#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/version.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"
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 | sessions |
struct | users |
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_atxfer (struct mansession *s, const struct message *m) |
static int | action_command (struct mansession *s, const struct message *m) |
action_command: Manager command "command" - execute CLI command | |
static int | action_coresettings (struct mansession *s, const struct message *m) |
Show PBX core settings information. | |
static int | action_corestatus (struct mansession *s, const struct message *m) |
Show PBX core status information. | |
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) |
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) |
void | astman_append (struct mansession *s, const char *fmt,...) |
static void | astman_append_buf_init (void) |
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) |
int | check_manager_enabled () |
Check if AMI is enabled. | |
int | check_webmanager_enabled () |
Check if AMI/HTTP is enabled. | |
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 eventq. | |
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 void | manager_event_buf_init (void) |
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 ast_rwlock_t | actionlock = PTHREAD_RWLOCK_INITIALIZER |
static int | asock = -1 |
static struct ast_threadstorage | astman_append_buf = { .once = PTHREAD_ONCE_INIT, .key_init = astman_append_buf_init , } |
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 struct manager_action * | first_action |
static int | httptimeout = 60 |
static int | manager_enabled = 0 |
static struct ast_threadstorage | manager_event_buf = { .once = PTHREAD_ONCE_INIT, .key_init = manager_event_buf_init , } |
ast_http_uri | manageruri |
ast_http_uri | managerxmluri |
static char | mandescr_atxfer [] |
static char | mandescr_command [] |
static char | mandescr_coresettings [] |
static char | mandescr_corestatus [] |
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 | webmanager_enabled = 0 |
static int | webregged = 0 |
Definition in file manager.c.
anonymous enum |
Definition at line 2853 of file manager.c.
02853 { 02854 FORMAT_RAW, 02855 FORMAT_HTML, 02856 FORMAT_XML, 02857 };
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 2815 of file manager.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_mutex_lock(), ast_mutex_unlock(), and s.
02816 { 02817 int result = 0; 02818 struct mansession *s; 02819 02820 AST_LIST_LOCK(&sessions); 02821 AST_LIST_TRAVERSE(&sessions, s, list) { 02822 ast_mutex_lock(&s->__lock); 02823 if ((s->managerid == ident) && (s->readperm & perm)) { 02824 result = 1; 02825 ast_mutex_unlock(&s->__lock); 02826 break; 02827 } 02828 ast_mutex_unlock(&s->__lock); 02829 } 02830 AST_LIST_UNLOCK(&sessions); 02831 return result; 02832 }
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 2834 of file manager.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_mutex_lock(), ast_mutex_unlock(), and s.
02835 { 02836 int result = 0; 02837 struct mansession *s; 02838 02839 AST_LIST_LOCK(&sessions); 02840 AST_LIST_TRAVERSE(&sessions, s, list) { 02841 ast_mutex_lock(&s->__lock); 02842 if ((s->managerid == ident) && (s->writeperm & perm)) { 02843 result = 1; 02844 ast_mutex_unlock(&s->__lock); 02845 break; 02846 } 02847 ast_mutex_unlock(&s->__lock); 02848 } 02849 AST_LIST_UNLOCK(&sessions); 02850 return result; 02851 }
static struct mansession* find_session | ( | uint32_t | ident | ) | [static] |
END Doxygen group
Definition at line 2797 of file manager.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_mutex_lock(), ast_mutex_unlock(), and s.
02798 { 02799 struct mansession *s; 02800 02801 AST_LIST_LOCK(&sessions); 02802 AST_LIST_TRAVERSE(&sessions, s, list) { 02803 ast_mutex_lock(&s->__lock); 02804 if (s->sessiontimeout && (s->managerid == ident) && !s->needdestroy) { 02805 s->inuse++; 02806 break; 02807 } 02808 ast_mutex_unlock(&s->__lock); 02809 } 02810 AST_LIST_UNLOCK(&sessions); 02811 02812 return s; 02813 }
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 2860 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().
02861 { 02862 struct mansession *s = NULL; 02863 uint32_t ident = 0; 02864 char workspace[512]; 02865 char cookie[128]; 02866 size_t len = sizeof(workspace); 02867 int blastaway = 0; 02868 char *c = workspace; 02869 char *retval = NULL; 02870 struct ast_variable *v; 02871 02872 for (v = params; v; v = v->next) { 02873 if (!strcasecmp(v->name, "mansession_id")) { 02874 sscanf(v->value, "%x", &ident); 02875 break; 02876 } 02877 } 02878 02879 if (!(s = find_session(ident))) { 02880 /* Create new session */ 02881 if (!(s = ast_calloc(1, sizeof(*s)))) { 02882 *status = 500; 02883 goto generic_callback_out; 02884 } 02885 memcpy(&s->sin, requestor, sizeof(s->sin)); 02886 s->fd = -1; 02887 s->waiting_thread = AST_PTHREADT_NULL; 02888 s->send_events = 0; 02889 ast_mutex_init(&s->__lock); 02890 ast_mutex_lock(&s->__lock); 02891 s->inuse = 1; 02892 /*!\note There is approximately a 1 in 1.8E19 chance that the following 02893 * calculation will produce 0, which is an invalid ID, but due to the 02894 * properties of the rand() function (and the constantcy of s), that 02895 * won't happen twice in a row. 02896 */ 02897 while ((s->managerid = rand() ^ (unsigned long) s) == 0); 02898 AST_LIST_LOCK(&sessions); 02899 AST_LIST_INSERT_HEAD(&sessions, s, list); 02900 /* Hook into the last spot in the event queue */ 02901 s->eventq = master_eventq; 02902 while (s->eventq->next) 02903 s->eventq = s->eventq->next; 02904 ast_atomic_fetchadd_int(&s->eventq->usecount, 1); 02905 ast_atomic_fetchadd_int(&num_sessions, 1); 02906 AST_LIST_UNLOCK(&sessions); 02907 } 02908 02909 /* Reset HTTP timeout. If we're not yet authenticated, keep it extremely short */ 02910 time(&s->sessiontimeout); 02911 if (!s->authenticated && (httptimeout > 5)) 02912 s->sessiontimeout += 5; 02913 else 02914 s->sessiontimeout += httptimeout; 02915 ast_mutex_unlock(&s->__lock); 02916 02917 if (s) { 02918 struct message m = { 0 }; 02919 char tmp[80]; 02920 unsigned int x; 02921 size_t hdrlen; 02922 02923 for (x = 0, v = params; v && (x < AST_MAX_MANHEADERS); x++, v = v->next) { 02924 hdrlen = strlen(v->name) + strlen(v->value) + 3; 02925 m.headers[m.hdrcount] = alloca(hdrlen); 02926 snprintf((char *) m.headers[m.hdrcount], hdrlen, "%s: %s", v->name, v->value); 02927 m.hdrcount = x + 1; 02928 } 02929 02930 if (process_message(s, &m)) { 02931 if (s->authenticated) { 02932 if (option_verbose > 1) { 02933 if (displayconnects) 02934 ast_verbose(VERBOSE_PREFIX_2 "HTTP Manager '%s' logged off from %s\n", s->username, ast_inet_ntoa(s->sin.sin_addr)); 02935 } 02936 ast_log(LOG_EVENT, "HTTP Manager '%s' logged off from %s\n", s->username, ast_inet_ntoa(s->sin.sin_addr)); 02937 } else { 02938 if (option_verbose > 1) { 02939 if (displayconnects) 02940 ast_verbose(VERBOSE_PREFIX_2 "HTTP Connect attempt from '%s' unable to authenticate\n", ast_inet_ntoa(s->sin.sin_addr)); 02941 } 02942 ast_log(LOG_EVENT, "HTTP Failed attempt from %s\n", ast_inet_ntoa(s->sin.sin_addr)); 02943 } 02944 s->needdestroy = 1; 02945 } 02946 ast_build_string(&c, &len, "Content-type: text/%s\r\n", contenttype[format]); 02947 sprintf(tmp, "%08x", s->managerid); 02948 ast_build_string(&c, &len, "%s\r\n", ast_http_setcookie("mansession_id", tmp, httptimeout, cookie, sizeof(cookie))); 02949 if (format == FORMAT_HTML) 02950 ast_build_string(&c, &len, "<title>Asterisk™ Manager Interface</title>"); 02951 if (format == FORMAT_XML) { 02952 ast_build_string(&c, &len, "<ajax-response>\n"); 02953 } else if (format == FORMAT_HTML) { 02954 ast_build_string(&c, &len, "<body bgcolor=\"#ffffff\"><table align=center bgcolor=\"#f1f1f1\" width=\"500\">\r\n"); 02955 ast_build_string(&c, &len, "<tr><td colspan=\"2\" bgcolor=\"#f1f1ff\"><h1> Manager Tester</h1></td></tr>\r\n"); 02956 } 02957 ast_mutex_lock(&s->__lock); 02958 if (s->outputstr) { 02959 char *tmp; 02960 if (format == FORMAT_XML) 02961 tmp = xml_translate(s->outputstr->str, params); 02962 else if (format == FORMAT_HTML) 02963 tmp = html_translate(s->outputstr->str); 02964 else 02965 tmp = s->outputstr->str; 02966 if (tmp) { 02967 retval = malloc(strlen(workspace) + strlen(tmp) + 128); 02968 if (retval) { 02969 strcpy(retval, workspace); 02970 strcpy(retval + strlen(retval), tmp); 02971 c = retval + strlen(retval); 02972 len = 120; 02973 } 02974 } 02975 if (tmp != s->outputstr->str) 02976 free(tmp); 02977 free(s->outputstr); 02978 s->outputstr = NULL; 02979 } 02980 ast_mutex_unlock(&s->__lock); 02981 /* Still okay because c would safely be pointing to workspace even 02982 if retval failed to allocate above */ 02983 if (format == FORMAT_XML) { 02984 ast_build_string(&c, &len, "</ajax-response>\n"); 02985 } else if (format == FORMAT_HTML) 02986 ast_build_string(&c, &len, "</table></body>\r\n"); 02987 } else { 02988 *status = 500; 02989 *title = strdup("Server Error"); 02990 } 02991 ast_mutex_lock(&s->__lock); 02992 if (s->needdestroy) { 02993 if (s->inuse == 1) { 02994 ast_log(LOG_DEBUG, "Need destroy, doing it now!\n"); 02995 blastaway = 1; 02996 } else { 02997 ast_log(LOG_DEBUG, "Need destroy, but can't do it yet!\n"); 02998 if (s->waiting_thread != AST_PTHREADT_NULL) 02999 pthread_kill(s->waiting_thread, SIGURG); 03000 s->inuse--; 03001 } 03002 } else 03003 s->inuse--; 03004 ast_mutex_unlock(&s->__lock); 03005 03006 if (blastaway) 03007 destroy_session(s); 03008 generic_callback_out: 03009 if (*status != 200) 03010 return ast_http_error(500, "Server Error", NULL, "Internal Server Error (out of memory)\n"); 03011 return retval; 03012 }
int init_manager | ( | void | ) |
Called by Asterisk initialization
Definition at line 3053 of file manager.c.
References action_atxfer(), action_command(), action_coresettings(), action_corestatus(), 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_copy_string(), 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, EVENT_FLAG_CALL, EVENT_FLAG_COMMAND, EVENT_FLAG_CONFIG, EVENT_FLAG_SYSTEM, EVENT_FLAG_USER, ast_channel::flags, free, ast_manager_user::keep, LOG_DEBUG, LOG_WARNING, manager_enabled, manager_state_cb(), mandescr_atxfer, mandescr_command, mandescr_events, mandescr_extensionstate, mandescr_getconfig, mandescr_getvar, mandescr_hangup, mandescr_listcommands, mandescr_logoff, mandescr_mailboxcount, mandescr_mailboxstatus, mandescr_originate, mandescr_ping, mandescr_redirect, mandescr_setvar, mandescr_timeout, mandescr_updateconfig, mandescr_userevent, mandescr_waitevent, ast_manager_user::permit, portno, ast_manager_user::read, ast_manager_user::secret, timestampevents, var, webmanager_enabled, and ast_manager_user::write.
Referenced by main(), and reload_manager().
03054 { 03055 struct ast_config *cfg = NULL, *ucfg = NULL; 03056 const char *val; 03057 char *cat = NULL; 03058 int oldportno = portno; 03059 static struct sockaddr_in ba; 03060 int x = 1; 03061 int flags; 03062 int newhttptimeout = 60; 03063 struct ast_manager_user *user = NULL; 03064 03065 if (!registered) { 03066 /* Register default actions */ 03067 ast_manager_register2("Ping", 0, action_ping, "Keepalive command", mandescr_ping); 03068 ast_manager_register2("Events", 0, action_events, "Control Event Flow", mandescr_events); 03069 ast_manager_register2("Logoff", 0, action_logoff, "Logoff Manager", mandescr_logoff); 03070 ast_manager_register2("Hangup", EVENT_FLAG_CALL, action_hangup, "Hangup Channel", mandescr_hangup); 03071 ast_manager_register("Status", EVENT_FLAG_CALL, action_status, "Lists channel status" ); 03072 ast_manager_register2("Setvar", EVENT_FLAG_CALL, action_setvar, "Set Channel Variable", mandescr_setvar ); 03073 ast_manager_register2("Getvar", EVENT_FLAG_CALL, action_getvar, "Gets a Channel Variable", mandescr_getvar ); 03074 ast_manager_register2("GetConfig", EVENT_FLAG_CONFIG, action_getconfig, "Retrieve configuration", mandescr_getconfig); 03075 ast_manager_register2("UpdateConfig", EVENT_FLAG_CONFIG, action_updateconfig, "Update basic configuration", mandescr_updateconfig); 03076 ast_manager_register2("Redirect", EVENT_FLAG_CALL, action_redirect, "Redirect (transfer) a call", mandescr_redirect ); 03077 ast_manager_register2("Atxfer", EVENT_FLAG_CALL, action_atxfer, "Attended transfer", mandescr_atxfer ); 03078 ast_manager_register2("Originate", EVENT_FLAG_CALL, action_originate, "Originate Call", mandescr_originate); 03079 ast_manager_register2("Command", EVENT_FLAG_COMMAND, action_command, "Execute Asterisk CLI Command", mandescr_command ); 03080 ast_manager_register2("ExtensionState", EVENT_FLAG_CALL, action_extensionstate, "Check Extension Status", mandescr_extensionstate ); 03081 ast_manager_register2("AbsoluteTimeout", EVENT_FLAG_CALL, action_timeout, "Set Absolute Timeout", mandescr_timeout ); 03082 ast_manager_register2("MailboxStatus", EVENT_FLAG_CALL, action_mailboxstatus, "Check Mailbox", mandescr_mailboxstatus ); 03083 ast_manager_register2("MailboxCount", EVENT_FLAG_CALL, action_mailboxcount, "Check Mailbox Message Count", mandescr_mailboxcount ); 03084 ast_manager_register2("ListCommands", 0, action_listcommands, "List available manager commands", mandescr_listcommands); 03085 ast_manager_register2("UserEvent", EVENT_FLAG_USER, action_userevent, "Send an arbitrary event", mandescr_userevent); 03086 ast_manager_register2("CoreSettings", EVENT_FLAG_SYSTEM, action_coresettings, "Show PBX core settings (version etc)", mandescr_coresettings); 03087 ast_manager_register2("CoreStatus", EVENT_FLAG_SYSTEM, action_corestatus, "Show PBX core status variables", mandescr_corestatus); 03088 ast_manager_register2("WaitEvent", 0, action_waitevent, "Wait for an event to occur", mandescr_waitevent); 03089 03090 ast_cli_register_multiple(cli_manager, sizeof(cli_manager) / sizeof(struct ast_cli_entry)); 03091 ast_extension_state_add(NULL, NULL, manager_state_cb, NULL); 03092 registered = 1; 03093 /* Append placeholder event so master_eventq never runs dry */ 03094 append_event("Event: Placeholder\r\n\r\n", 0); 03095 } 03096 portno = DEFAULT_MANAGER_PORT; 03097 displayconnects = 1; 03098 cfg = ast_config_load("manager.conf"); 03099 if (!cfg) { 03100 ast_log(LOG_NOTICE, "Unable to open management configuration manager.conf. Call management disabled.\n"); 03101 return 0; 03102 } 03103 if ((val = ast_variable_retrieve(cfg, "general", "enabled"))) { 03104 manager_enabled = ast_true(val); 03105 } 03106 if ((val = ast_variable_retrieve(cfg, "general", "block-sockets"))) { 03107 block_sockets = ast_true(val); 03108 } 03109 if((val = ast_variable_retrieve(cfg, "general", "webenabled"))) { 03110 webmanager_enabled = ast_true(val); 03111 } 03112 if ((val = ast_variable_retrieve(cfg, "general", "port"))) { 03113 if (sscanf(val, "%d", &portno) != 1) { 03114 ast_log(LOG_WARNING, "Invalid port number '%s'\n", val); 03115 portno = DEFAULT_MANAGER_PORT; 03116 } 03117 } 03118 if ((val = ast_variable_retrieve(cfg, "general", "displayconnects"))) { 03119 displayconnects = ast_true(val); 03120 } 03121 if ((val = ast_variable_retrieve(cfg, "general", "timestampevents"))) { 03122 timestampevents = ast_true(val); 03123 } 03124 if ((val = ast_variable_retrieve(cfg, "general", "httptimeout"))) { 03125 newhttptimeout = atoi(val); 03126 } 03127 03128 memset(&ba, 0, sizeof(ba)); 03129 ba.sin_family = AF_INET; 03130 ba.sin_port = htons(portno); 03131 03132 if ((val = ast_variable_retrieve(cfg, "general", "bindaddr"))) { 03133 if (!inet_aton(val, &ba.sin_addr)) { 03134 ast_log(LOG_WARNING, "Invalid address '%s' specified, using 0.0.0.0\n", val); 03135 memset(&ba.sin_addr, 0, sizeof(ba.sin_addr)); 03136 } 03137 } 03138 03139 03140 if ((asock > -1) && ((portno != oldportno) || !manager_enabled)) { 03141 #if 0 03142 /* Can't be done yet */ 03143 close(asock); 03144 asock = -1; 03145 #else 03146 ast_log(LOG_WARNING, "Unable to change management port / enabled\n"); 03147 #endif 03148 } 03149 03150 AST_LIST_LOCK(&users); 03151 03152 if ((ucfg = ast_config_load("users.conf"))) { 03153 while ((cat = ast_category_browse(ucfg, cat))) { 03154 int hasmanager = 0; 03155 struct ast_variable *var = NULL; 03156 03157 if (!strcasecmp(cat, "general")) { 03158 continue; 03159 } 03160 03161 if (!(hasmanager = ast_true(ast_variable_retrieve(ucfg, cat, "hasmanager")))) { 03162 continue; 03163 } 03164 03165 /* Look for an existing entry, if none found - create one and add it to the list */ 03166 if (!(user = ast_get_manager_by_name_locked(cat))) { 03167 if (!(user = ast_calloc(1, sizeof(*user)))) { 03168 break; 03169 } 03170 /* Copy name over */ 03171 ast_copy_string(user->username, cat, sizeof(user->username)); 03172 /* Insert into list */ 03173 AST_LIST_INSERT_TAIL(&users, user, list); 03174 } 03175 03176 /* Make sure we keep this user and don't destroy it during cleanup */ 03177 user->keep = 1; 03178 03179 for (var = ast_variable_browse(ucfg, cat); var; var = var->next) { 03180 if (!strcasecmp(var->name, "secret")) { 03181 if (user->secret) { 03182 free(user->secret); 03183 } 03184 user->secret = ast_strdup(var->value); 03185 } else if (!strcasecmp(var->name, "deny") ) { 03186 if (user->deny) { 03187 free(user->deny); 03188 } 03189 user->deny = ast_strdup(var->value); 03190 } else if (!strcasecmp(var->name, "permit") ) { 03191 if (user->permit) { 03192 free(user->permit); 03193 } 03194 user->permit = ast_strdup(var->value); 03195 } else if (!strcasecmp(var->name, "read") ) { 03196 if (user->read) { 03197 free(user->read); 03198 } 03199 user->read = ast_strdup(var->value); 03200 } else if (!strcasecmp(var->name, "write") ) { 03201 if (user->write) { 03202 free(user->write); 03203 } 03204 user->write = ast_strdup(var->value); 03205 } else if (!strcasecmp(var->name, "displayconnects") ) { 03206 user->displayconnects = ast_true(var->value); 03207 } else if (!strcasecmp(var->name, "hasmanager")) { 03208 /* already handled */ 03209 } else { 03210 ast_log(LOG_DEBUG, "%s is an unknown option (to the manager module).\n", var->name); 03211 } 03212 } 03213 } 03214 ast_config_destroy(ucfg); 03215 } 03216 03217 while ((cat = ast_category_browse(cfg, cat))) { 03218 struct ast_variable *var = NULL; 03219 03220 if (!strcasecmp(cat, "general")) 03221 continue; 03222 03223 /* Look for an existing entry, if none found - create one and add it to the list */ 03224 if (!(user = ast_get_manager_by_name_locked(cat))) { 03225 if (!(user = ast_calloc(1, sizeof(*user)))) 03226 break; 03227 /* Copy name over */ 03228 ast_copy_string(user->username, cat, sizeof(user->username)); 03229 /* Insert into list */ 03230 AST_LIST_INSERT_TAIL(&users, user, list); 03231 } 03232 03233 /* Make sure we keep this user and don't destroy it during cleanup */ 03234 user->keep = 1; 03235 03236 var = ast_variable_browse(cfg, cat); 03237 while (var) { 03238 if (!strcasecmp(var->name, "secret")) { 03239 if (user->secret) 03240 free(user->secret); 03241 user->secret = ast_strdup(var->value); 03242 } else if (!strcasecmp(var->name, "deny") ) { 03243 if (user->deny) 03244 free(user->deny); 03245 user->deny = ast_strdup(var->value); 03246 } else if (!strcasecmp(var->name, "permit") ) { 03247 if (user->permit) 03248 free(user->permit); 03249 user->permit = ast_strdup(var->value); 03250 } else if (!strcasecmp(var->name, "read") ) { 03251 if (user->read) 03252 free(user->read); 03253 user->read = ast_strdup(var->value); 03254 } else if (!strcasecmp(var->name, "write") ) { 03255 if (user->write) 03256 free(user->write); 03257 user->write = ast_strdup(var->value); 03258 } else if (!strcasecmp(var->name, "displayconnects") ) 03259 user->displayconnects = ast_true(var->value); 03260 else 03261 ast_log(LOG_DEBUG, "%s is an unknown option.\n", var->name); 03262 var = var->next; 03263 } 03264 } 03265 03266 /* Perform cleanup - essentially prune out old users that no longer exist */ 03267 AST_LIST_TRAVERSE_SAFE_BEGIN(&users, user, list) { 03268 if (user->keep) { 03269 user->keep = 0; 03270 continue; 03271 } 03272 /* We do not need to keep this user so take them out of the list */ 03273 AST_LIST_REMOVE_CURRENT(&users, list); 03274 /* Free their memory now */ 03275 if (user->secret) 03276 free(user->secret); 03277 if (user->deny) 03278 free(user->deny); 03279 if (user->permit) 03280 free(user->permit); 03281 if (user->read) 03282 free(user->read); 03283 if (user->write) 03284 free(user->write); 03285 free(user); 03286 } 03287 AST_LIST_TRAVERSE_SAFE_END 03288 03289 AST_LIST_UNLOCK(&users); 03290 03291 ast_config_destroy(cfg); 03292 03293 if (webmanager_enabled && manager_enabled) { 03294 if (!webregged) { 03295 ast_http_uri_link(&rawmanuri); 03296 ast_http_uri_link(&manageruri); 03297 ast_http_uri_link(&managerxmluri); 03298 webregged = 1; 03299 } 03300 } else { 03301 if (webregged) { 03302 ast_http_uri_unlink(&rawmanuri); 03303 ast_http_uri_unlink(&manageruri); 03304 ast_http_uri_unlink(&managerxmluri); 03305 webregged = 0; 03306 } 03307 } 03308 03309 if (newhttptimeout > 0) 03310 httptimeout = newhttptimeout; 03311 03312 /* If not enabled, do nothing */ 03313 if (!manager_enabled) 03314 return 0; 03315 03316 if (asock < 0) { 03317 asock = socket(AF_INET, SOCK_STREAM, 0); 03318 if (asock < 0) { 03319 ast_log(LOG_WARNING, "Unable to create socket: %s\n", strerror(errno)); 03320 return -1; 03321 } 03322 setsockopt(asock, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x)); 03323 if (bind(asock, (struct sockaddr *)&ba, sizeof(ba))) { 03324 ast_log(LOG_WARNING, "Unable to bind socket: %s\n", strerror(errno)); 03325 close(asock); 03326 asock = -1; 03327 return -1; 03328 } 03329 if (listen(asock, 2)) { 03330 ast_log(LOG_WARNING, "Unable to listen on socket: %s\n", strerror(errno)); 03331 close(asock); 03332 asock = -1; 03333 return -1; 03334 } 03335 flags = fcntl(asock, F_GETFL); 03336 fcntl(asock, F_SETFL, flags | O_NONBLOCK); 03337 if (option_verbose) 03338 ast_verbose("Asterisk Management interface listening on port %d\n", portno); 03339 ast_pthread_create_background(&t, NULL, accept_thread, NULL); 03340 } 03341 return 0; 03342 }
static char* manager_http_callback | ( | struct sockaddr_in * | requestor, | |
const char * | uri, | |||
struct ast_variable * | params, | |||
int * | status, | |||
char ** | title, | |||
int * | contentlength | |||
) | [static] |
Definition at line 3014 of file manager.c.
References FORMAT_HTML, and generic_http_callback().
03015 { 03016 return generic_http_callback(FORMAT_HTML, requestor, uri, params, status, title, contentlength); 03017 }
static char* mxml_http_callback | ( | struct sockaddr_in * | requestor, | |
const char * | uri, | |||
struct ast_variable * | params, | |||
int * | status, | |||
char ** | title, | |||
int * | contentlength | |||
) | [static] |
Definition at line 3019 of file manager.c.
References FORMAT_XML, and generic_http_callback().
03020 { 03021 return generic_http_callback(FORMAT_XML, requestor, uri, params, status, title, contentlength); 03022 }
static char* rawman_http_callback | ( | struct sockaddr_in * | requestor, | |
const char * | uri, | |||
struct ast_variable * | params, | |||
int * | status, | |||
char ** | title, | |||
int * | contentlength | |||
) | [static] |
Definition at line 3024 of file manager.c.
References FORMAT_RAW, and generic_http_callback().
03025 { 03026 return generic_http_callback(FORMAT_RAW, requestor, uri, params, status, title, contentlength); 03027 }
int reload_manager | ( | void | ) |
Definition at line 3344 of file manager.c.
References EVENT_FLAG_SYSTEM, init_manager(), and manager_event().
03345 { 03346 manager_event(EVENT_FLAG_SYSTEM, "Reload", "Message: Reload Requested\r\n"); 03347 return init_manager(); 03348 }
char* contenttype[] = { "plain", "html", "xml" } [static] |
struct ast_http_uri manageruri |
struct ast_http_uri managerxmluri |
struct ast_http_uri rawmanuri |
int registered = 0 [static] |
char* words[AST_MAX_CMD_LEN] |