#include "asterisk.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/time.h>
#include <sys/types.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include "asterisk/channel.h"
#include "asterisk/file.h"
#include "asterisk/manager.h"
#include "asterisk/config.h"
#include "asterisk/callerid.h"
#include "asterisk/lock.h"
#include "asterisk/logger.h"
#include "asterisk/options.h"
#include "asterisk/cli.h"
#include "asterisk/app.h"
#include "asterisk/pbx.h"
#include "asterisk/md5.h"
#include "asterisk/acl.h"
#include "asterisk/utils.h"
#include "asterisk/http.h"
#include "asterisk/threadstorage.h"
#include "asterisk/linkedlists.h"
#include "asterisk/term.h"
#include "asterisk/astobj2.h"
Include dependency graph for manager.c:

Go to the source code of this file.
Data Structures | |
| struct | ast_manager_user |
| struct | eventqent |
| struct | fast_originate_helper |
| struct | mansession |
| struct | permalias |
| struct | variable_count |
Defines | |
| #define | ASTMAN_APPEND_BUF_INITSIZE 256 |
| #define | MANAGER_EVENT_BUF_INITSIZE 256 |
| #define | MAX_BLACKLIST_CMD_LEN 2 |
Enumerations | |
| enum | { FORMAT_RAW, FORMAT_HTML, FORMAT_XML } |
Functions | |
| static void * | accept_thread (void *ignore) |
| static int | action_command (struct mansession *s, const struct message *m) |
| action_command: Manager command "command" - execute CLI command | |
| static int | action_events (struct mansession *s, const struct message *m) |
| static int | action_extensionstate (struct mansession *s, const struct message *m) |
| static int | action_getconfig (struct mansession *s, const struct message *m) |
| static int | action_getvar (struct mansession *s, const struct message *m) |
| static int | action_hangup (struct mansession *s, const struct message *m) |
| static int | action_listcommands (struct mansession *s, const struct message *m) |
| static int | action_logoff (struct mansession *s, const struct message *m) |
| static int | action_mailboxcount (struct mansession *s, const struct message *m) |
| static int | action_mailboxstatus (struct mansession *s, const struct message *m) |
| static int | action_originate (struct mansession *s, const struct message *m) |
| static int | action_ping (struct mansession *s, const struct message *m) |
| static int | action_redirect (struct mansession *s, const struct message *m) |
| action_redirect: The redirect manager command | |
| static int | action_setvar (struct mansession *s, const struct message *m) |
| static int | action_status (struct mansession *s, const struct message *m) |
| Manager "status" command to show channels. | |
| static int | action_timeout (struct mansession *s, const struct message *m) |
| static int | action_updateconfig (struct mansession *s, const struct message *m) |
| static int | action_userevent (struct mansession *s, const struct message *m) |
| static int | action_waitevent (struct mansession *s, const struct message *m) |
| static int | append_event (const char *str, int category) |
| static struct ast_manager_user * | ast_get_manager_by_name_locked (const char *name) |
| static int | ast_instring (const char *bigstr, const char *smallstr, char delim) |
| static int | ast_is_number (const char *string) |
| static | AST_LIST_HEAD_STATIC (users, ast_manager_user) |
| static | AST_LIST_HEAD_STATIC (sessions, mansession) |
| int | ast_manager_register2 (const char *action, int auth, int(*func)(struct mansession *s, const struct message *m), const char *synopsis, const char *description) |
| register a new command with manager, including online help. This is the preferred way to register a manager command | |
| static int | ast_manager_register_struct (struct manager_action *act) |
| int | ast_manager_unregister (char *action) |
| AST_RWLOCK_DEFINE_STATIC (actionlock) | |
| AST_THREADSTORAGE (astman_append_buf, astman_append_buf_init) | |
| AST_THREADSTORAGE (manager_event_buf, manager_event_buf_init) | |
| void | astman_append (struct mansession *s, const char *fmt,...) |
| const char * | astman_get_header (const struct message *m, char *var) |
| ast_variable * | astman_get_variables (const struct message *m) |
| void | astman_send_ack (struct mansession *s, const struct message *m, char *msg) |
| void | astman_send_error (struct mansession *s, const struct message *m, char *error) |
| void | astman_send_response (struct mansession *s, const struct message *m, char *resp, char *msg) |
| int | astman_verify_session_readpermissions (uint32_t ident, int perm) |
| Verify a session's read permissions against a permission mask. | |
| int | astman_verify_session_writepermissions (uint32_t ident, int perm) |
| Verify a session's write permissions against a permission mask. | |
| static int | authenticate (struct mansession *s, const struct message *m) |
| static char * | authority_to_str (int authority, char *res, int reslen) |
| Convert authority code to string with serveral options. | |
| static int | check_blacklist (const char *cmd) |
| static char * | complete_show_mancmd (const char *line, const char *word, int pos, int state) |
| static int | compress_char (char c) |
| static void | destroy_session (struct mansession *s) |
| static int | do_message (struct mansession *s) |
| static void * | fast_originate (void *data) |
| static struct mansession * | find_session (uint32_t ident) |
| static void | free_session (struct mansession *s) |
| static char * | generic_http_callback (int format, struct sockaddr_in *requestor, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength) |
| static int | get_input (struct mansession *s, char *output) |
| static int | get_perm (const char *instr) |
| static int | handle_showmanager (int fd, int argc, char *argv[]) |
| static int | handle_showmanagers (int fd, int argc, char *argv[]) |
| static int | handle_showmancmd (int fd, int argc, char *argv[]) |
| static int | handle_showmancmds (int fd, int argc, char *argv[]) |
| CLI command Should change to "manager show commands". | |
| static int | handle_showmanconn (int fd, int argc, char *argv[]) |
| CLI command show manager connected. | |
| static int | handle_showmaneventq (int fd, int argc, char *argv[]) |
| CLI command show manager connected. | |
| static void | handle_updates (struct mansession *s, const struct message *m, struct ast_config *cfg) |
| static char * | html_translate (char *in) |
| int | init_manager (void) |
| int | manager_event (int category, const char *event, const char *fmt,...) |
| manager_event: Send AMI event to client | |
| static char * | manager_http_callback (struct sockaddr_in *requestor, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength) |
| static int | manager_state_cb (char *context, char *exten, int state, void *data) |
| static char * | mxml_http_callback (struct sockaddr_in *requestor, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength) |
| static int | process_events (struct mansession *s) |
| static int | process_message (struct mansession *s, const struct message *m) |
| static char * | rawman_http_callback (struct sockaddr_in *requestor, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength) |
| int | reload_manager (void) |
| static void * | session_do (void *data) |
| static int | set_eventmask (struct mansession *s, const char *eventmask) |
| Rather than braindead on,off this now can also accept a specific int mask value or a ',' delim list of mask strings (the same as manager.conf) -anthm. | |
| static int | strings_to_mask (const char *string) |
| static void | unuse_eventqent (struct eventqent *e) |
| static int | variable_count_cmp_fn (void *obj, void *vstr, int flags) |
| static int | variable_count_hash_fn (const void *vvc, const int flags) |
| static void | xml_copy_escape (char **dst, size_t *maxlen, const char *src, int lower) |
| static char * | xml_translate (char *in, struct ast_variable *vars) |
Variables | |
| static int | asock = -1 |
| static int | block_sockets |
| static struct ast_cli_entry | cli_manager [] |
| static struct ast_cli_entry | cli_show_manager_command_deprecated |
| static struct ast_cli_entry | cli_show_manager_commands_deprecated |
| static struct ast_cli_entry | cli_show_manager_connected_deprecated |
| static struct ast_cli_entry | cli_show_manager_eventq_deprecated |
| struct { | |
| char * words [AST_MAX_CMD_LEN] | |
| } | command_blacklist [] |
| static char * | contenttype [] = { "plain", "html", "xml" } |
| static int | displayconnects = 1 |
| static int | enabled |
| static struct manager_action * | first_action |
| static int | httptimeout = 60 |
| ast_http_uri | manageruri |
| ast_http_uri | managerxmluri |
| static char | mandescr_command [] |
| static char | mandescr_events [] |
| static char | mandescr_extensionstate [] |
| static char | mandescr_getconfig [] |
| static char | mandescr_getvar [] |
| static char | mandescr_hangup [] |
| static char | mandescr_listcommands [] |
| static char | mandescr_logoff [] |
| static char | mandescr_mailboxcount [] |
| static char | mandescr_mailboxstatus [] |
| Help text for manager command mailboxstatus. | |
| static char | mandescr_originate [] |
| static char | mandescr_ping [] |
| Manager PING. | |
| static char | mandescr_redirect [] |
| static char | mandescr_setvar [] |
| static char | mandescr_timeout [] |
| static char | mandescr_updateconfig [] |
| static char | mandescr_userevent [] |
| static char | mandescr_waitevent [] |
| Manager WAITEVENT. | |
| eventqent * | master_eventq = NULL |
| static int | num_sessions |
| static struct permalias | perms [] |
| static int | portno = DEFAULT_MANAGER_PORT |
| ast_http_uri | rawmanuri |
| static int | registered = 0 |
| static char | showmanager_help [] |
| static char | showmanagers_help [] |
| static char | showmancmd_help [] |
| static char | showmancmds_help [] |
| static char | showmanconn_help [] |
| static char | showmaneventq_help [] |
| static pthread_t | t |
| static int | timestampevents |
| static int | webregged = 0 |
Channel Management and more
Definition in file manager.c.
| anonymous enum |
Definition at line 2694 of file manager.c.
02694 { 02695 FORMAT_RAW, 02696 FORMAT_HTML, 02697 FORMAT_XML, 02698 };
| int astman_verify_session_readpermissions | ( | uint32_t | ident, | |
| int | perm | |||
| ) |
Verify a session's read permissions against a permission mask.
| ident | session identity | |
| perm | permission mask to verify |
Definition at line 2656 of file manager.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_mutex_lock(), ast_mutex_unlock(), s, and sessions.
02657 { 02658 int result = 0; 02659 struct mansession *s; 02660 02661 AST_LIST_LOCK(&sessions); 02662 AST_LIST_TRAVERSE(&sessions, s, list) { 02663 ast_mutex_lock(&s->__lock); 02664 if ((s->managerid == ident) && (s->readperm & perm)) { 02665 result = 1; 02666 ast_mutex_unlock(&s->__lock); 02667 break; 02668 } 02669 ast_mutex_unlock(&s->__lock); 02670 } 02671 AST_LIST_UNLOCK(&sessions); 02672 return result; 02673 }
| int astman_verify_session_writepermissions | ( | uint32_t | ident, | |
| int | perm | |||
| ) |
Verify a session's write permissions against a permission mask.
| ident | session identity | |
| perm | permission mask to verify |
Definition at line 2675 of file manager.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_mutex_lock(), ast_mutex_unlock(), s, and sessions.
02676 { 02677 int result = 0; 02678 struct mansession *s; 02679 02680 AST_LIST_LOCK(&sessions); 02681 AST_LIST_TRAVERSE(&sessions, s, list) { 02682 ast_mutex_lock(&s->__lock); 02683 if ((s->managerid == ident) && (s->writeperm & perm)) { 02684 result = 1; 02685 ast_mutex_unlock(&s->__lock); 02686 break; 02687 } 02688 ast_mutex_unlock(&s->__lock); 02689 } 02690 AST_LIST_UNLOCK(&sessions); 02691 return result; 02692 }
| static struct mansession* find_session | ( | uint32_t | ident | ) | [static] |
END Doxygen group
Definition at line 2638 of file manager.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_mutex_lock(), ast_mutex_unlock(), s, and sessions.
02639 { 02640 struct mansession *s; 02641 02642 AST_LIST_LOCK(&sessions); 02643 AST_LIST_TRAVERSE(&sessions, s, list) { 02644 ast_mutex_lock(&s->__lock); 02645 if (s->sessiontimeout && (s->managerid == ident) && !s->needdestroy) { 02646 s->inuse++; 02647 break; 02648 } 02649 ast_mutex_unlock(&s->__lock); 02650 } 02651 AST_LIST_UNLOCK(&sessions); 02652 02653 return s; 02654 }
| static char* generic_http_callback | ( | int | format, | |
| struct sockaddr_in * | requestor, | |||
| const char * | uri, | |||
| struct ast_variable * | params, | |||
| int * | status, | |||
| char ** | title, | |||
| int * | contentlength | |||
| ) | [static] |
Definition at line 2701 of file manager.c.
References len, ast_variable::name, ast_variable::next, s, and ast_variable::value.
Referenced by manager_http_callback(), mxml_http_callback(), and rawman_http_callback().
02702 { 02703 struct mansession *s = NULL; 02704 uint32_t ident = 0; 02705 char workspace[512]; 02706 char cookie[128]; 02707 size_t len = sizeof(workspace); 02708 int blastaway = 0; 02709 char *c = workspace; 02710 char *retval = NULL; 02711 struct ast_variable *v; 02712 02713 for (v = params; v; v = v->next) { 02714 if (!strcasecmp(v->name, "mansession_id")) { 02715 sscanf(v->value, "%x", &ident); 02716 break; 02717 } 02718 } 02719 02720 if (!(s = find_session(ident))) { 02721 /* Create new session */ 02722 if (!(s = ast_calloc(1, sizeof(*s)))) { 02723 *status = 500; 02724 goto generic_callback_out; 02725 } 02726 memcpy(&s->sin, requestor, sizeof(s->sin)); 02727 s->fd = -1; 02728 s->waiting_thread = AST_PTHREADT_NULL; 02729 s->send_events = 0; 02730 ast_mutex_init(&s->__lock); 02731 ast_mutex_lock(&s->__lock); 02732 s->inuse = 1; 02733 /*!\note There is approximately a 1 in 1.8E19 chance that the following 02734 * calculation will produce 0, which is an invalid ID, but due to the 02735 * properties of the rand() function (and the constantcy of s), that 02736 * won't happen twice in a row. 02737 */ 02738 while ((s->managerid = rand() ^ (unsigned long) s) == 0); 02739 AST_LIST_LOCK(&sessions); 02740 AST_LIST_INSERT_HEAD(&sessions, s, list); 02741 /* Hook into the last spot in the event queue */ 02742 s->eventq = master_eventq; 02743 while (s->eventq->next) 02744 s->eventq = s->eventq->next; 02745 ast_atomic_fetchadd_int(&s->eventq->usecount, 1); 02746 ast_atomic_fetchadd_int(&num_sessions, 1); 02747 AST_LIST_UNLOCK(&sessions); 02748 } 02749 02750 /* Reset HTTP timeout. If we're not yet authenticated, keep it extremely short */ 02751 time(&s->sessiontimeout); 02752 if (!s->authenticated && (httptimeout > 5)) 02753 s->sessiontimeout += 5; 02754 else 02755 s->sessiontimeout += httptimeout; 02756 ast_mutex_unlock(&s->__lock); 02757 02758 if (s) { 02759 struct message m = { 0 }; 02760 char tmp[80]; 02761 unsigned int x; 02762 size_t hdrlen; 02763 02764 for (x = 0, v = params; v && (x < AST_MAX_MANHEADERS); x++, v = v->next) { 02765 hdrlen = strlen(v->name) + strlen(v->value) + 3; 02766 m.headers[m.hdrcount] = alloca(hdrlen); 02767 snprintf((char *) m.headers[m.hdrcount], hdrlen, "%s: %s", v->name, v->value); 02768 m.hdrcount = x + 1; 02769 } 02770 02771 if (process_message(s, &m)) { 02772 if (s->authenticated) { 02773 if (option_verbose > 1) { 02774 if (displayconnects) 02775 ast_verbose(VERBOSE_PREFIX_2 "HTTP Manager '%s' logged off from %s\n", s->username, ast_inet_ntoa(s->sin.sin_addr)); 02776 } 02777 ast_log(LOG_EVENT, "HTTP Manager '%s' logged off from %s\n", s->username, ast_inet_ntoa(s->sin.sin_addr)); 02778 } else { 02779 if (option_verbose > 1) { 02780 if (displayconnects) 02781 ast_verbose(VERBOSE_PREFIX_2 "HTTP Connect attempt from '%s' unable to authenticate\n", ast_inet_ntoa(s->sin.sin_addr)); 02782 } 02783 ast_log(LOG_EVENT, "HTTP Failed attempt from %s\n", ast_inet_ntoa(s->sin.sin_addr)); 02784 } 02785 s->needdestroy = 1; 02786 } 02787 ast_build_string(&c, &len, "Content-type: text/%s\r\n", contenttype[format]); 02788 sprintf(tmp, "%08x", s->managerid); 02789 ast_build_string(&c, &len, "%s\r\n", ast_http_setcookie("mansession_id", tmp, httptimeout, cookie, sizeof(cookie))); 02790 if (format == FORMAT_HTML) 02791 ast_build_string(&c, &len, "<title>Asterisk™ Manager Interface</title>"); 02792 if (format == FORMAT_XML) { 02793 ast_build_string(&c, &len, "<ajax-response>\n"); 02794 } else if (format == FORMAT_HTML) { 02795 ast_build_string(&c, &len, "<body bgcolor=\"#ffffff\"><table align=center bgcolor=\"#f1f1f1\" width=\"500\">\r\n"); 02796 ast_build_string(&c, &len, "<tr><td colspan=\"2\" bgcolor=\"#f1f1ff\"><h1> Manager Tester</h1></td></tr>\r\n"); 02797 } 02798 ast_mutex_lock(&s->__lock); 02799 if (s->outputstr) { 02800 char *tmp; 02801 if (format == FORMAT_XML) 02802 tmp = xml_translate(s->outputstr->str, params); 02803 else if (format == FORMAT_HTML) 02804 tmp = html_translate(s->outputstr->str); 02805 else 02806 tmp = s->outputstr->str; 02807 if (tmp) { 02808 retval = malloc(strlen(workspace) + strlen(tmp) + 128); 02809 if (retval) { 02810 strcpy(retval, workspace); 02811 strcpy(retval + strlen(retval), tmp); 02812 c = retval + strlen(retval); 02813 len = 120; 02814 } 02815 } 02816 if (tmp != s->outputstr->str) 02817 free(tmp); 02818 free(s->outputstr); 02819 s->outputstr = NULL; 02820 } 02821 ast_mutex_unlock(&s->__lock); 02822 /* Still okay because c would safely be pointing to workspace even 02823 if retval failed to allocate above */ 02824 if (format == FORMAT_XML) { 02825 ast_build_string(&c, &len, "</ajax-response>\n"); 02826 } else if (format == FORMAT_HTML) 02827 ast_build_string(&c, &len, "</table></body>\r\n"); 02828 } else { 02829 *status = 500; 02830 *title = strdup("Server Error"); 02831 } 02832 ast_mutex_lock(&s->__lock); 02833 if (s->needdestroy) { 02834 if (s->inuse == 1) { 02835 ast_log(LOG_DEBUG, "Need destroy, doing it now!\n"); 02836 blastaway = 1; 02837 } else { 02838 ast_log(LOG_DEBUG, "Need destroy, but can't do it yet!\n"); 02839 if (s->waiting_thread != AST_PTHREADT_NULL) 02840 pthread_kill(s->waiting_thread, SIGURG); 02841 s->inuse--; 02842 } 02843 } else 02844 s->inuse--; 02845 ast_mutex_unlock(&s->__lock); 02846 02847 if (blastaway) 02848 destroy_session(s); 02849 generic_callback_out: 02850 if (*status != 200) 02851 return ast_http_error(500, "Server Error", NULL, "Internal Server Error (out of memory)\n"); 02852 return retval; 02853 }
| int init_manager | ( | void | ) |
Called by Asterisk initialization
Definition at line 2894 of file manager.c.
References action_command(), action_events(), action_extensionstate(), action_getconfig(), action_getvar(), action_hangup(), action_listcommands(), action_logoff(), action_mailboxcount(), action_mailboxstatus(), action_originate(), action_ping(), action_redirect(), action_setvar(), action_status(), action_timeout(), action_updateconfig(), action_userevent(), action_waitevent(), append_event(), asock, ast_calloc, ast_category_browse(), ast_cli_register_multiple(), ast_config_load(), ast_extension_state_add(), ast_get_manager_by_name_locked(), AST_LIST_INSERT_TAIL, AST_LIST_LOCK, ast_log(), ast_manager_register, ast_manager_register2(), ast_strdup, ast_true(), ast_variable_browse(), ast_variable_retrieve(), block_sockets, cli_manager, DEFAULT_MANAGER_PORT, ast_manager_user::deny, displayconnects, ast_manager_user::displayconnects, enabled, EVENT_FLAG_CALL, EVENT_FLAG_COMMAND, EVENT_FLAG_CONFIG, EVENT_FLAG_USER, ast_channel::flags, free, ast_manager_user::keep, LOG_DEBUG, LOG_WARNING, manager_state_cb(), ast_manager_user::permit, portno, ast_manager_user::read, ast_manager_user::secret, timestampevents, users, var, and ast_manager_user::write.
Referenced by main(), and reload_manager().
02895 { 02896 struct ast_config *cfg = NULL, *ucfg = NULL; 02897 const char *val; 02898 char *cat = NULL; 02899 int oldportno = portno; 02900 static struct sockaddr_in ba; 02901 int x = 1; 02902 int flags; 02903 int webenabled = 0; 02904 int newhttptimeout = 60; 02905 struct ast_manager_user *user = NULL; 02906 02907 if (!registered) { 02908 /* Register default actions */ 02909 ast_manager_register2("Ping", 0, action_ping, "Keepalive command", mandescr_ping); 02910 ast_manager_register2("Events", 0, action_events, "Control Event Flow", mandescr_events); 02911 ast_manager_register2("Logoff", 0, action_logoff, "Logoff Manager", mandescr_logoff); 02912 ast_manager_register2("Hangup", EVENT_FLAG_CALL, action_hangup, "Hangup Channel", mandescr_hangup); 02913 ast_manager_register("Status", EVENT_FLAG_CALL, action_status, "Lists channel status" ); 02914 ast_manager_register2("Setvar", EVENT_FLAG_CALL, action_setvar, "Set Channel Variable", mandescr_setvar ); 02915 ast_manager_register2("Getvar", EVENT_FLAG_CALL, action_getvar, "Gets a Channel Variable", mandescr_getvar ); 02916 ast_manager_register2("GetConfig", EVENT_FLAG_CONFIG, action_getconfig, "Retrieve configuration", mandescr_getconfig); 02917 ast_manager_register2("UpdateConfig", EVENT_FLAG_CONFIG, action_updateconfig, "Update basic configuration", mandescr_updateconfig); 02918 ast_manager_register2("Redirect", EVENT_FLAG_CALL, action_redirect, "Redirect (transfer) a call", mandescr_redirect ); 02919 ast_manager_register2("Originate", EVENT_FLAG_CALL, action_originate, "Originate Call", mandescr_originate); 02920 ast_manager_register2("Command", EVENT_FLAG_COMMAND, action_command, "Execute Asterisk CLI Command", mandescr_command ); 02921 ast_manager_register2("ExtensionState", EVENT_FLAG_CALL, action_extensionstate, "Check Extension Status", mandescr_extensionstate ); 02922 ast_manager_register2("AbsoluteTimeout", EVENT_FLAG_CALL, action_timeout, "Set Absolute Timeout", mandescr_timeout ); 02923 ast_manager_register2("MailboxStatus", EVENT_FLAG_CALL, action_mailboxstatus, "Check Mailbox", mandescr_mailboxstatus ); 02924 ast_manager_register2("MailboxCount", EVENT_FLAG_CALL, action_mailboxcount, "Check Mailbox Message Count", mandescr_mailboxcount ); 02925 ast_manager_register2("ListCommands", 0, action_listcommands, "List available manager commands", mandescr_listcommands); 02926 ast_manager_register2("UserEvent", EVENT_FLAG_USER, action_userevent, "Send an arbitrary event", mandescr_userevent); 02927 ast_manager_register2("WaitEvent", 0, action_waitevent, "Wait for an event to occur", mandescr_waitevent); 02928 02929 ast_cli_register_multiple(cli_manager, sizeof(cli_manager) / sizeof(struct ast_cli_entry)); 02930 ast_extension_state_add(NULL, NULL, manager_state_cb, NULL); 02931 registered = 1; 02932 /* Append placeholder event so master_eventq never runs dry */ 02933 append_event("Event: Placeholder\r\n\r\n", 0); 02934 } 02935 portno = DEFAULT_MANAGER_PORT; 02936 displayconnects = 1; 02937 cfg = ast_config_load("manager.conf"); 02938 if (!cfg) { 02939 ast_log(LOG_NOTICE, "Unable to open management configuration manager.conf. Call management disabled.\n"); 02940 return 0; 02941 } 02942 val = ast_variable_retrieve(cfg, "general", "enabled"); 02943 if (val) 02944 enabled = ast_true(val); 02945 02946 val = ast_variable_retrieve(cfg, "general", "block-sockets"); 02947 if (val) 02948 block_sockets = ast_true(val); 02949 02950 val = ast_variable_retrieve(cfg, "general", "webenabled"); 02951 if (val) 02952 webenabled = ast_true(val); 02953 02954 if ((val = ast_variable_retrieve(cfg, "general", "port"))) { 02955 if (sscanf(val, "%d", &portno) != 1) { 02956 ast_log(LOG_WARNING, "Invalid port number '%s'\n", val); 02957 portno = DEFAULT_MANAGER_PORT; 02958 } 02959 } 02960 02961 if ((val = ast_variable_retrieve(cfg, "general", "displayconnects"))) 02962 displayconnects = ast_true(val); 02963 02964 if ((val = ast_variable_retrieve(cfg, "general", "timestampevents"))) 02965 timestampevents = ast_true(val); 02966 02967 if ((val = ast_variable_retrieve(cfg, "general", "httptimeout"))) 02968 newhttptimeout = atoi(val); 02969 02970 memset(&ba, 0, sizeof(ba)); 02971 ba.sin_family = AF_INET; 02972 ba.sin_port = htons(portno); 02973 02974 if ((val = ast_variable_retrieve(cfg, "general", "bindaddr"))) { 02975 if (!inet_aton(val, &ba.sin_addr)) { 02976 ast_log(LOG_WARNING, "Invalid address '%s' specified, using 0.0.0.0\n", val); 02977 memset(&ba.sin_addr, 0, sizeof(ba.sin_addr)); 02978 } 02979 } 02980 02981 02982 if ((asock > -1) && ((portno != oldportno) || !enabled)) { 02983 #if 0 02984 /* Can't be done yet */ 02985 close(asock); 02986 asock = -1; 02987 #else 02988 ast_log(LOG_WARNING, "Unable to change management port / enabled\n"); 02989 #endif 02990 } 02991 02992 AST_LIST_LOCK(&users); 02993 02994 if ((ucfg = ast_config_load("users.conf"))) { 02995 while ((cat = ast_category_browse(ucfg, cat))) { 02996 int hasmanager = 0; 02997 struct ast_variable *var = NULL; 02998 02999 if (!strcasecmp(cat, "general")) { 03000 continue; 03001 } 03002 03003 if (!(hasmanager = ast_true(ast_variable_retrieve(ucfg, cat, "hasmanager")))) { 03004 continue; 03005 } 03006 03007 /* Look for an existing entry, if none found - create one and add it to the list */ 03008 if (!(user = ast_get_manager_by_name_locked(cat))) { 03009 if (!(user = ast_calloc(1, sizeof(*user)))) { 03010 break; 03011 } 03012 /* Copy name over */ 03013 ast_copy_string(user->username, cat, sizeof(user->username)); 03014 /* Insert into list */ 03015 AST_LIST_INSERT_TAIL(&users, user, list); 03016 } 03017 03018 /* Make sure we keep this user and don't destroy it during cleanup */ 03019 user->keep = 1; 03020 03021 for (var = ast_variable_browse(ucfg, cat); var; var = var->next) { 03022 if (!strcasecmp(var->name, "secret")) { 03023 if (user->secret) { 03024 free(user->secret); 03025 } 03026 user->secret = ast_strdup(var->value); 03027 } else if (!strcasecmp(var->name, "deny") ) { 03028 if (user->deny) { 03029 free(user->deny); 03030 } 03031 user->deny = ast_strdup(var->value); 03032 } else if (!strcasecmp(var->name, "permit") ) { 03033 if (user->permit) { 03034 free(user->permit); 03035 } 03036 user->permit = ast_strdup(var->value); 03037 } else if (!strcasecmp(var->name, "read") ) { 03038 if (user->read) { 03039 free(user->read); 03040 } 03041 user->read = ast_strdup(var->value); 03042 } else if (!strcasecmp(var->name, "write") ) { 03043 if (user->write) { 03044 free(user->write); 03045 } 03046 user->write = ast_strdup(var->value); 03047 } else if (!strcasecmp(var->name, "displayconnects") ) { 03048 user->displayconnects = ast_true(var->value); 03049 } else if (!strcasecmp(var->name, "hasmanager")) { 03050 /* already handled */ 03051 } else { 03052 ast_log(LOG_DEBUG, "%s is an unknown option (to the manager module).\n", var->name); 03053 } 03054 } 03055 } 03056 ast_config_destroy(ucfg); 03057 } 03058 03059 while ((cat = ast_category_browse(cfg, cat))) { 03060 struct ast_variable *var = NULL; 03061 03062 if (!strcasecmp(cat, "general")) 03063 continue; 03064 03065 /* Look for an existing entry, if none found - create one and add it to the list */ 03066 if (!(user = ast_get_manager_by_name_locked(cat))) { 03067 if (!(user = ast_calloc(1, sizeof(*user)))) 03068 break; 03069 /* Copy name over */ 03070 ast_copy_string(user->username, cat, sizeof(user->username)); 03071 /* Insert into list */ 03072 AST_LIST_INSERT_TAIL(&users, user, list); 03073 } 03074 03075 /* Make sure we keep this user and don't destroy it during cleanup */ 03076 user->keep = 1; 03077 03078 var = ast_variable_browse(cfg, cat); 03079 while (var) { 03080 if (!strcasecmp(var->name, "secret")) { 03081 if (user->secret) 03082 free(user->secret); 03083 user->secret = ast_strdup(var->value); 03084 } else if (!strcasecmp(var->name, "deny") ) { 03085 if (user->deny) 03086 free(user->deny); 03087 user->deny = ast_strdup(var->value); 03088 } else if (!strcasecmp(var->name, "permit") ) { 03089 if (user->permit) 03090 free(user->permit); 03091 user->