#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 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 |
Defines | |
#define | ASTMAN_APPEND_BUF_INITSIZE 256 |
#define | MANAGER_EVENT_BUF_INITSIZE 256 |
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 (unsigned long ident, int perm) |
Verify a session's read permissions against a permission mask. | |
int | astman_verify_session_writepermissions (unsigned long 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 char * | complete_show_mancmd (const char *line, const char *word, int pos, int state) |
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 (unsigned long 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 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 |
static const char * | 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 2537 of file manager.c.
02537 { 02538 FORMAT_RAW, 02539 FORMAT_HTML, 02540 FORMAT_XML, 02541 };
int astman_verify_session_readpermissions | ( | unsigned long | ident, | |
int | perm | |||
) |
Verify a session's read permissions against a permission mask.
ident | session identity | |
perm | permission mask to verify |
Definition at line 2499 of file manager.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_mutex_lock(), ast_mutex_unlock(), result, s, and sessions.
02500 { 02501 int result = 0; 02502 struct mansession *s; 02503 02504 AST_LIST_LOCK(&sessions); 02505 AST_LIST_TRAVERSE(&sessions, s, list) { 02506 ast_mutex_lock(&s->__lock); 02507 if ((s->managerid == ident) && (s->readperm & perm)) { 02508 result = 1; 02509 ast_mutex_unlock(&s->__lock); 02510 break; 02511 } 02512 ast_mutex_unlock(&s->__lock); 02513 } 02514 AST_LIST_UNLOCK(&sessions); 02515 return result; 02516 }
int astman_verify_session_writepermissions | ( | unsigned long | ident, | |
int | perm | |||
) |
Verify a session's write permissions against a permission mask.
ident | session identity | |
perm | permission mask to verify |
Definition at line 2518 of file manager.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_mutex_lock(), ast_mutex_unlock(), result, s, and sessions.
02519 { 02520 int result = 0; 02521 struct mansession *s; 02522 02523 AST_LIST_LOCK(&sessions); 02524 AST_LIST_TRAVERSE(&sessions, s, list) { 02525 ast_mutex_lock(&s->__lock); 02526 if ((s->managerid == ident) && (s->writeperm & perm)) { 02527 result = 1; 02528 ast_mutex_unlock(&s->__lock); 02529 break; 02530 } 02531 ast_mutex_unlock(&s->__lock); 02532 } 02533 AST_LIST_UNLOCK(&sessions); 02534 return result; 02535 }
static struct mansession* find_session | ( | unsigned long | ident | ) | [static] |
END Doxygen group
Definition at line 2481 of file manager.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_mutex_lock(), ast_mutex_unlock(), s, and sessions.
02482 { 02483 struct mansession *s; 02484 02485 AST_LIST_LOCK(&sessions); 02486 AST_LIST_TRAVERSE(&sessions, s, list) { 02487 ast_mutex_lock(&s->__lock); 02488 if (s->sessiontimeout && (s->managerid == ident) && !s->needdestroy) { 02489 s->inuse++; 02490 break; 02491 } 02492 ast_mutex_unlock(&s->__lock); 02493 } 02494 AST_LIST_UNLOCK(&sessions); 02495 02496 return s; 02497 }
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 2544 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().
02545 { 02546 struct mansession *s = NULL; 02547 unsigned long ident = 0; 02548 char workspace[512]; 02549 char cookie[128]; 02550 size_t len = sizeof(workspace); 02551 int blastaway = 0; 02552 char *c = workspace; 02553 char *retval = NULL; 02554 struct ast_variable *v; 02555 02556 for (v = params; v; v = v->next) { 02557 if (!strcasecmp(v->name, "mansession_id")) { 02558 sscanf(v->value, "%lx", &ident); 02559 break; 02560 } 02561 } 02562 02563 if (!(s = find_session(ident))) { 02564 /* Create new session */ 02565 if (!(s = ast_calloc(1, sizeof(*s)))) { 02566 *status = 500; 02567 goto generic_callback_out; 02568 } 02569 memcpy(&s->sin, requestor, sizeof(s->sin)); 02570 s->fd = -1; 02571 s->waiting_thread = AST_PTHREADT_NULL; 02572 s->send_events = 0; 02573 ast_mutex_init(&s->__lock); 02574 ast_mutex_lock(&s->__lock); 02575 s->inuse = 1; 02576 s->managerid = rand() | (unsigned long)s; 02577 AST_LIST_LOCK(&sessions); 02578 AST_LIST_INSERT_HEAD(&sessions, s, list); 02579 /* Hook into the last spot in the event queue */ 02580 s->eventq = master_eventq; 02581 while (s->eventq->next) 02582 s->eventq = s->eventq->next; 02583 AST_LIST_UNLOCK(&sessions); 02584 ast_atomic_fetchadd_int(&s->eventq->usecount, 1); 02585 ast_atomic_fetchadd_int(&num_sessions, 1); 02586 } 02587 02588 /* Reset HTTP timeout. If we're not yet authenticated, keep it extremely short */ 02589 time(&s->sessiontimeout); 02590 if (!s->authenticated && (httptimeout > 5)) 02591 s->sessiontimeout += 5; 02592 else 02593 s->sessiontimeout += httptimeout; 02594 ast_mutex_unlock(&s->__lock); 02595 02596 if (s) { 02597 struct message m = { 0 }; 02598 char tmp[80]; 02599 unsigned int x; 02600 size_t hdrlen; 02601 02602 for (x = 0, v = params; v && (x < AST_MAX_MANHEADERS); x++, v = v->next) { 02603 hdrlen = strlen(v->name) + strlen(v->value) + 3; 02604 m.headers[m.hdrcount] = alloca(hdrlen); 02605 snprintf((char *) m.headers[m.hdrcount], hdrlen, "%s: %s", v->name, v->value); 02606 m.hdrcount = x + 1; 02607 } 02608 02609 if (process_message(s, &m)) { 02610 if (s->authenticated) { 02611 if (option_verbose > 1) { 02612 if (displayconnects) 02613 ast_verbose(VERBOSE_PREFIX_2 "HTTP Manager '%s' logged off from %s\n", s->username, ast_inet_ntoa(s->sin.sin_addr)); 02614 } 02615 ast_log(LOG_EVENT, "HTTP Manager '%s' logged off from %s\n", s->username, ast_inet_ntoa(s->sin.sin_addr)); 02616 } else { 02617 if (option_verbose > 1) { 02618 if (displayconnects) 02619 ast_verbose(VERBOSE_PREFIX_2 "HTTP Connect attempt from '%s' unable to authenticate\n", ast_inet_ntoa(s->sin.sin_addr)); 02620 } 02621 ast_log(LOG_EVENT, "HTTP Failed attempt from %s\n", ast_inet_ntoa(s->sin.sin_addr)); 02622 } 02623 s->needdestroy = 1; 02624 } 02625 ast_build_string(&c, &len, "Content-type: text/%s\r\n", contenttype[format]); 02626 sprintf(tmp, "%08lx", s->managerid); 02627 ast_build_string(&c, &len, "%s\r\n", ast_http_setcookie("mansession_id", tmp, httptimeout, cookie, sizeof(cookie))); 02628 if (format == FORMAT_HTML) 02629 ast_build_string(&c, &len, "<title>Asterisk™ Manager Interface</title>"); 02630 if (format == FORMAT_XML) { 02631 ast_build_string(&c, &len, "<ajax-response>\n"); 02632 } else if (format == FORMAT_HTML) { 02633 ast_build_string(&c, &len, "<body bgcolor=\"#ffffff\"><table align=center bgcolor=\"#f1f1f1\" width=\"500\">\r\n"); 02634 ast_build_string(&c, &len, "<tr><td colspan=\"2\" bgcolor=\"#f1f1ff\"><h1> Manager Tester</h1></td></tr>\r\n"); 02635 } 02636 ast_mutex_lock(&s->__lock); 02637 if (s->outputstr) { 02638 char *tmp; 02639 if (format == FORMAT_XML) 02640 tmp = xml_translate(s->outputstr->str, params); 02641 else if (format == FORMAT_HTML) 02642 tmp = html_translate(s->outputstr->str); 02643 else 02644 tmp = s->outputstr->str; 02645 if (tmp) { 02646 retval = malloc(strlen(workspace) + strlen(tmp) + 128); 02647 if (retval) { 02648 strcpy(retval, workspace); 02649 strcpy(retval + strlen(retval), tmp); 02650 c = retval + strlen(retval); 02651 len = 120; 02652 } 02653 } 02654 if (tmp != s->outputstr->str) 02655 free(tmp); 02656 free(s->outputstr); 02657 s->outputstr = NULL; 02658 } 02659 ast_mutex_unlock(&s->__lock); 02660 /* Still okay because c would safely be pointing to workspace even 02661 if retval failed to allocate above */ 02662 if (format == FORMAT_XML) { 02663 ast_build_string(&c, &len, "</ajax-response>\n"); 02664 } else if (format == FORMAT_HTML) 02665 ast_build_string(&c, &len, "</table></body>\r\n"); 02666 } else { 02667 *status = 500; 02668 *title = strdup("Server Error"); 02669 } 02670 ast_mutex_lock(&s->__lock); 02671 if (s->needdestroy) { 02672 if (s->inuse == 1) { 02673 ast_log(LOG_DEBUG, "Need destroy, doing it now!\n"); 02674 blastaway = 1; 02675 } else { 02676 ast_log(LOG_DEBUG, "Need destroy, but can't do it yet!\n"); 02677 if (s->waiting_thread != AST_PTHREADT_NULL) 02678 pthread_kill(s->waiting_thread, SIGURG); 02679 s->inuse--; 02680 } 02681 } else 02682 s->inuse--; 02683 ast_mutex_unlock(&s->__lock); 02684 02685 if (blastaway) 02686 destroy_session(s); 02687 generic_callback_out: 02688 if (*status != 200) 02689 return ast_http_error(500, "Server Error", NULL, "Internal Server Error (out of memory)\n"); 02690 return retval; 02691 }
int init_manager | ( | void | ) |
Called by Asterisk initialization
Definition at line 2732 of file manager.c.
References accept_thread(), 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_destroy(), ast_config_load(), ast_extension_state_add(), ast_get_manager_by_name_locked(), ast_http_uri_link(), ast_http_uri_unlink(), AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_log(), ast_manager_register, ast_manager_register2(), ast_pthread_create_background, ast_strdup, ast_true(), ast_variable_browse(), ast_variable_retrieve(), ast_verbose(), 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, httptimeout, ast_manager_user::keep, LOG_DEBUG, LOG_WARNING, manager_state_cb(), manageruri, managerxmluri, option_verbose, ast_manager_user::permit, portno, rawmanuri, ast_manager_user::read, ast_manager_user::secret, t, timestampevents, users, var, and ast_manager_user::write.
Referenced by main(), and reload_manager().
02733 { 02734 struct ast_config *cfg = NULL; 02735 const char *val; 02736 char *cat = NULL; 02737 int oldportno = portno; 02738 static struct sockaddr_in ba; 02739 int x = 1; 02740 int flags; 02741 int webenabled = 0; 02742 int newhttptimeout = 60; 02743 struct ast_manager_user *user = NULL; 02744 02745 if (!registered) { 02746 /* Register default actions */ 02747 ast_manager_register2("Ping", 0, action_ping, "Keepalive command", mandescr_ping); 02748 ast_manager_register2("Events", 0, action_events, "Control Event Flow", mandescr_events); 02749 ast_manager_register2("Logoff", 0, action_logoff, "Logoff Manager", mandescr_logoff); 02750 ast_manager_register2("Hangup", EVENT_FLAG_CALL, action_hangup, "Hangup Channel", mandescr_hangup); 02751 ast_manager_register("Status", EVENT_FLAG_CALL, action_status, "Lists channel status" ); 02752 ast_manager_register2("Setvar", EVENT_FLAG_CALL, action_setvar, "Set Channel Variable", mandescr_setvar ); 02753 ast_manager_register2("Getvar", EVENT_FLAG_CALL, action_getvar, "Gets a Channel Variable", mandescr_getvar ); 02754 ast_manager_register2("GetConfig", EVENT_FLAG_CONFIG, action_getconfig, "Retrieve configuration", mandescr_getconfig); 02755 ast_manager_register2("UpdateConfig", EVENT_FLAG_CONFIG, action_updateconfig, "Update basic configuration", mandescr_updateconfig); 02756 ast_manager_register2("Redirect", EVENT_FLAG_CALL, action_redirect, "Redirect (transfer) a call", mandescr_redirect ); 02757 ast_manager_register2("Originate", EVENT_FLAG_CALL, action_originate, "Originate Call", mandescr_originate); 02758 ast_manager_register2("Command", EVENT_FLAG_COMMAND, action_command, "Execute Asterisk CLI Command", mandescr_command ); 02759 ast_manager_register2("ExtensionState", EVENT_FLAG_CALL, action_extensionstate, "Check Extension Status", mandescr_extensionstate ); 02760 ast_manager_register2("AbsoluteTimeout", EVENT_FLAG_CALL, action_timeout, "Set Absolute Timeout", mandescr_timeout ); 02761 ast_manager_register2("MailboxStatus", EVENT_FLAG_CALL, action_mailboxstatus, "Check Mailbox", mandescr_mailboxstatus ); 02762 ast_manager_register2("MailboxCount", EVENT_FLAG_CALL, action_mailboxcount, "Check Mailbox Message Count", mandescr_mailboxcount ); 02763 ast_manager_register2("ListCommands", 0, action_listcommands, "List available manager commands", mandescr_listcommands); 02764 ast_manager_register2("UserEvent", EVENT_FLAG_USER, action_userevent, "Send an arbitrary event", mandescr_userevent); 02765 ast_manager_register2("WaitEvent", 0, action_waitevent, "Wait for an event to occur", mandescr_waitevent); 02766 02767 ast_cli_register_multiple(cli_manager, sizeof(cli_manager) / sizeof(struct ast_cli_entry)); 02768 ast_extension_state_add(NULL, NULL, manager_state_cb, NULL); 02769 registered = 1; 02770 /* Append placeholder event so master_eventq never runs dry */ 02771 append_event("Event: Placeholder\r\n\r\n", 0); 02772 } 02773 portno = DEFAULT_MANAGER_PORT; 02774 displayconnects = 1; 02775 cfg = ast_config_load("manager.conf"); 02776 if (!cfg) { 02777 ast_log(LOG_NOTICE, "Unable to open management configuration manager.conf. Call management disabled.\n"); 02778 return 0; 02779 } 02780 val = ast_variable_retrieve(cfg, "general", "enabled"); 02781 if (val) 02782 enabled = ast_true(val); 02783 02784 val = ast_variable_retrieve(cfg, "general", "block-sockets"); 02785 if (val) 02786 block_sockets = ast_true(val); 02787 02788 val = ast_variable_retrieve(cfg, "general", "webenabled"); 02789 if (val) 02790 webenabled = ast_true(val); 02791 02792 if ((val = ast_variable_retrieve(cfg, "general", "port"))) { 02793 if (sscanf(val, "%d", &portno) != 1) { 02794 ast_log(LOG_WARNING, "Invalid port number '%s'\n", val); 02795 portno = DEFAULT_MANAGER_PORT; 02796 } 02797 } 02798 02799 if ((val = ast_variable_retrieve(cfg, "general", "displayconnects"))) 02800 displayconnects = ast_true(val); 02801 02802 if ((val = ast_variable_retrieve(cfg, "general", "timestampevents"))) 02803 timestampevents = ast_true(val); 02804 02805 if ((val = ast_variable_retrieve(cfg, "general", "httptimeout"))) 02806 newhttptimeout = atoi(val); 02807 02808 memset(&ba, 0, sizeof(ba)); 02809 ba.sin_family = AF_INET; 02810 ba.sin_port = htons(portno); 02811 02812 if ((val = ast_variable_retrieve(cfg, "general", "bindaddr"))) { 02813 if (!inet_aton(val, &ba.sin_addr)) { 02814 ast_log(LOG_WARNING, "Invalid address '%s' specified, using 0.0.0.0\n", val); 02815 memset(&ba.sin_addr, 0, sizeof(ba.sin_addr)); 02816 } 02817 } 02818 02819 02820 if ((asock > -1) && ((portno != oldportno) || !enabled)) { 02821 #if 0 02822 /* Can't be done yet */ 02823 close(asock); 02824 asock = -1; 02825 #else 02826 ast_log(LOG_WARNING, "Unable to change management port / enabled\n"); 02827 #endif 02828 } 02829 02830 AST_LIST_LOCK(&users); 02831 02832 while ((cat = ast_category_browse(cfg, cat))) { 02833 struct ast_variable *var = NULL; 02834 02835 if (!strcasecmp(cat, "general")) 02836 continue; 02837 02838 /* Look for an existing entry, if none found - create one and add it to the list */ 02839 if (!(user = ast_get_manager_by_name_locked(cat))) { 02840 if (!(user = ast_calloc(1, sizeof(*user)))) 02841 break; 02842 /* Copy name over */ 02843 ast_copy_string(user->username, cat, sizeof(user->username)); 02844 /* Insert into list */ 02845 AST_LIST_INSERT_TAIL(&users, user, list); 02846 } 02847 02848 /* Make sure we keep this user and don't destroy it during cleanup */ 02849 user->keep = 1; 02850 02851 var = ast_variable_browse(cfg, cat); 02852 while (var) { 02853 if (!strcasecmp(var->name, "secret")) { 02854 if (user->secret) 02855 free(user->secret); 02856 user->secret = ast_strdup(var->value); 02857 } else if (!strcasecmp(var->name, "deny") ) { 02858 if (user->deny) 02859 free(user->deny); 02860 user->deny = ast_strdup(var->value); 02861 } else if (!strcasecmp(var->name, "permit") ) { 02862 if (user->permit) 02863 free(user->permit); 02864 user->permit = ast_strdup(var->value); 02865 } else if (!strcasecmp(var->name, "read") ) { 02866 if (user->read) 02867 free(user->read); 02868 user->read = ast_strdup(var->value); 02869 } else if (!strcasecmp(var->name, "write") ) { 02870 if (user->write) 02871 free(user->write); 02872 user->write = ast_strdup(var->value); 02873 } else if (!strcasecmp(var->name, "displayconnects") ) 02874 user->displayconnects = ast_true(var->value); 02875 else 02876 ast_log(LOG_DEBUG, "%s is an unknown option.\n", var->name); 02877 var = var->next; 02878 } 02879 } 02880 02881 /* Perform cleanup - essentially prune out old users that no longer exist */ 02882 AST_LIST_TRAVERSE_SAFE_BEGIN(&users, user, list) { 02883 if (user->keep) { 02884 user->keep = 0; 02885 continue; 02886 } 02887 /* We do not need to keep this user so take them out of the list */ 02888 AST_LIST_REMOVE_CURRENT(&users, list); 02889 /* Free their memory now */ 02890 if (user->secret) 02891 free(user->secret); 02892 if (user->deny) 02893 free(user->deny); 02894 if (user->permit) 02895 free(user->permit); 02896 if (user->read) 02897 free(user->read); 02898 if (user->write) 02899 free(user->write); 02900 free(user); 02901 } 02902 AST_LIST_TRAVERSE_SAFE_END 02903 02904 AST_LIST_UNLOCK(&users); 02905 02906 ast_config_destroy(cfg); 02907 02908 if (webenabled && enabled) { 02909 if (!webregged) { 02910 ast_http_uri_link(&rawmanuri); 02911 ast_http_uri_link(&manageruri); 02912 ast_http_uri_link(&managerxmluri); 02913 webregged = 1; 02914 } 02915 } else { 02916 if (webregged) { 02917 ast_http_uri_unlink(&rawmanuri); 02918 ast_http_uri_unlink(&manageruri); 02919 ast_http_uri_unlink(&managerxmluri); 02920 webregged = 0; 02921 } 02922 } 02923 02924 if (newhttptimeout > 0) 02925 httptimeout = newhttptimeout; 02926 02927 /* If not enabled, do nothing */ 02928 if (!enabled) 02929 return 0; 02930 02931 if (asock < 0) { 02932 asock = socket(AF_INET, SOCK_STREAM, 0); 02933 if (asock < 0) { 02934 ast_log(LOG_WARNING, "Unable to create socket: %s\n", strerror(errno)); 02935 return -1; 02936 } 02937 setsockopt(asock, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x)); 02938 if (bind(asock, (struct sockaddr *)&ba, sizeof(ba))) { 02939 ast_log(LOG_WARNING, "Unable to bind socket: %s\n", strerror(errno)); 02940 close(asock); 02941 asock = -1; 02942 return -1; 02943 } 02944 if (listen(asock, 2)) { 02945 ast_log(LOG_WARNING, "Unable to listen on socket: %s\n", strerror(errno)); 02946 close(asock); 02947 asock = -1; 02948 return -1; 02949 } 02950 flags = fcntl(asock, F_GETFL); 02951 fcntl(asock, F_SETFL, flags | O_NONBLOCK); 02952 if (option_verbose) 02953 ast_verbose("Asterisk Management interface listening on port %d\n", portno); 02954 ast_pthread_create_background(&t, NULL, accept_thread, NULL); 02955 } 02956 return 0; 02957 }
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 2693 of file manager.c.
References FORMAT_HTML, and generic_http_callback().
02694 { 02695 return generic_http_callback(FORMAT_HTML, requestor, uri, params, status, title, contentlength); 02696 }
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 2698 of file manager.c.
References FORMAT_XML, and generic_http_callback().
02699 { 02700 return generic_http_callback(FORMAT_XML, requestor, uri, params, status, title, contentlength); 02701 }
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 2703 of file manager.c.
References FORMAT_RAW, and generic_http_callback().
02704 { 02705 return generic_http_callback(FORMAT_RAW, requestor, uri, params, status, title, contentlength); 02706 }
int reload_manager | ( | void | ) |
Definition at line 2959 of file manager.c.
References EVENT_FLAG_SYSTEM, init_manager(), and manager_event().
02960 { 02961 manager_event(EVENT_FLAG_SYSTEM, "Reload", "Message: Reload Requested\r\n"); 02962 return init_manager(); 02963 }
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] |