#include <stdio.h>
#include <stdlib.h>
#include <string.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.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 dependency graph for manager.c:
Go to the source code of this file.
Data Structures | |
struct | fast_originate_helper |
struct | permalias |
Functions | |
static void * | accept_thread (void *ignore) |
static int | action_command (struct mansession *s, struct message *m) |
action_command: Manager command "command" - execute CLI command | |
static int | action_events (struct mansession *s, struct message *m) |
static int | action_extensionstate (struct mansession *s, struct message *m) |
static int | action_getvar (struct mansession *s, struct message *m) |
static int | action_hangup (struct mansession *s, struct message *m) |
static int | action_listcommands (struct mansession *s, struct message *m) |
static int | action_logoff (struct mansession *s, struct message *m) |
static int | action_mailboxcount (struct mansession *s, struct message *m) |
static int | action_mailboxstatus (struct mansession *s, struct message *m) |
static int | action_originate (struct mansession *s, struct message *m) |
static int | action_ping (struct mansession *s, struct message *m) |
static int | action_redirect (struct mansession *s, struct message *m) |
action_redirect: The redirect manager command | |
static int | action_setvar (struct mansession *s, struct message *m) |
static int | action_status (struct mansession *s, struct message *m) |
action_status: Manager "status" command to show channels | |
static int | action_timeout (struct mansession *s, struct message *m) |
static int | append_event (struct mansession *s, const char *str) |
int | ast_carefulwrite (int fd, char *s, int len, int timeoutms) |
static int | ast_instring (char *bigstr, char *smallstr, char delim) |
static int | ast_is_number (char *string) |
int | ast_manager_register2 (const char *action, int auth, int(*func)(struct mansession *s, 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_MUTEX_DEFINE_STATIC (actionlock) | |
AST_MUTEX_DEFINE_STATIC (sessionlock) | |
static int | ast_strings_to_mask (char *string) |
char * | astman_get_header (struct message *m, char *var) |
ast_variable * | astman_get_variables (struct message *m) |
void | astman_send_ack (struct mansession *s, struct message *m, char *msg) |
void | astman_send_error (struct mansession *s, struct message *m, char *error) |
void | astman_send_response (struct mansession *s, struct message *m, char *resp, char *msg) |
static int | authenticate (struct mansession *s, struct message *m) |
static char * | authority_to_str (int authority, char *res, int reslen) |
static char * | complete_show_mancmd (char *line, char *word, int pos, int state) |
static void | destroy_session (struct mansession *s) |
static void * | fast_originate (void *data) |
static void | free_session (struct mansession *s) |
static int | get_input (struct mansession *s, char *output) |
static int | get_perm (char *instr) |
static int | handle_showmancmd (int fd, int argc, char *argv[]) |
static int | handle_showmancmds (int fd, int argc, char *argv[]) |
handle_showmancmds: CLI command | |
static int | handle_showmanconn (int fd, int argc, char *argv[]) |
handle_showmanconn: CLI command show manager connected | |
int | init_manager (void) |
int | manager_event (int category, char *event, char *fmt,...) |
manager_event: Send AMI event to client | |
static int | manager_state_cb (char *context, char *exten, int state, void *data) |
static int | process_message (struct mansession *s, struct message *m) |
int | reload_manager (void) |
static void * | session_do (void *data) |
static int | set_eventmask (struct mansession *s, char *eventmask) |
Variables | |
static int | asock = -1 |
static int | block_sockets = 0 |
static int | displayconnects = 1 |
static int | enabled = 0 |
static struct manager_action * | first_action = NULL |
static char | mandescr_command [] |
static char | mandescr_events [] |
static char | mandescr_extensionstate [] |
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 [] |
PING: Manager PING. | |
static char | mandescr_redirect [] |
static char | mandescr_setvar [] |
static char | mandescr_timeout [] |
static struct permalias | perms [] |
static int | portno = DEFAULT_MANAGER_PORT |
static int | registered = 0 |
static struct mansession * | sessions = NULL |
static struct ast_cli_entry | show_mancmd_cli |
static struct ast_cli_entry | show_mancmds_cli |
static struct ast_cli_entry | show_manconn_cli |
static char | showmancmd_help [] |
static char | showmancmds_help [] |
static char | showmanconn_help [] |
static pthread_t | t |
Channel Management and more
Definition in file manager.c.
int init_manager | ( | void | ) |
Called by Asterisk initialization
Definition at line 1643 of file manager.c.
References accept_thread(), action_command(), action_events(), action_extensionstate(), action_getvar(), action_hangup(), action_listcommands(), action_logoff(), action_mailboxcount(), action_mailboxstatus(), action_originate(), action_ping(), action_redirect(), action_setvar(), action_status(), action_timeout(), asock, ast_cli_register(), ast_config_destroy(), ast_config_load(), ast_extension_state_add(), ast_log(), ast_manager_register, ast_manager_register2(), ast_pthread_create, ast_true(), ast_variable_retrieve(), ast_verbose(), block_sockets, cfg, DEFAULT_MANAGER_PORT, displayconnects, enabled, EVENT_FLAG_CALL, EVENT_FLAG_COMMAND, LOG_NOTICE, LOG_WARNING, manager_state_cb(), mandescr_command, mandescr_events, mandescr_extensionstate, mandescr_getvar, mandescr_hangup, mandescr_listcommands, mandescr_logoff, mandescr_mailboxcount, mandescr_mailboxstatus, mandescr_originate, mandescr_ping, mandescr_redirect, mandescr_setvar, mandescr_timeout, option_verbose, portno, show_mancmd_cli, show_mancmds_cli, show_manconn_cli, and t.
Referenced by main(), and reload_manager().
01644 { 01645 struct ast_config *cfg; 01646 char *val; 01647 int oldportno = portno; 01648 static struct sockaddr_in ba; 01649 int x = 1; 01650 if (!registered) { 01651 /* Register default actions */ 01652 ast_manager_register2("Ping", 0, action_ping, "Keepalive command", mandescr_ping); 01653 ast_manager_register2("Events", 0, action_events, "Control Event Flow", mandescr_events); 01654 ast_manager_register2("Logoff", 0, action_logoff, "Logoff Manager", mandescr_logoff); 01655 ast_manager_register2("Hangup", EVENT_FLAG_CALL, action_hangup, "Hangup Channel", mandescr_hangup); 01656 ast_manager_register("Status", EVENT_FLAG_CALL, action_status, "Lists channel status" ); 01657 ast_manager_register2("Setvar", EVENT_FLAG_CALL, action_setvar, "Set Channel Variable", mandescr_setvar ); 01658 ast_manager_register2("Getvar", EVENT_FLAG_CALL, action_getvar, "Gets a Channel Variable", mandescr_getvar ); 01659 ast_manager_register2("Redirect", EVENT_FLAG_CALL, action_redirect, "Redirect (transfer) a call", mandescr_redirect ); 01660 ast_manager_register2("Originate", EVENT_FLAG_CALL, action_originate, "Originate Call", mandescr_originate); 01661 ast_manager_register2("Command", EVENT_FLAG_COMMAND, action_command, "Execute Asterisk CLI Command", mandescr_command ); 01662 ast_manager_register2("ExtensionState", EVENT_FLAG_CALL, action_extensionstate, "Check Extension Status", mandescr_extensionstate ); 01663 ast_manager_register2("AbsoluteTimeout", EVENT_FLAG_CALL, action_timeout, "Set Absolute Timeout", mandescr_timeout ); 01664 ast_manager_register2("MailboxStatus", EVENT_FLAG_CALL, action_mailboxstatus, "Check Mailbox", mandescr_mailboxstatus ); 01665 ast_manager_register2("MailboxCount", EVENT_FLAG_CALL, action_mailboxcount, "Check Mailbox Message Count", mandescr_mailboxcount ); 01666 ast_manager_register2("ListCommands", 0, action_listcommands, "List available manager commands", mandescr_listcommands); 01667 01668 ast_cli_register(&show_mancmd_cli); 01669 ast_cli_register(&show_mancmds_cli); 01670 ast_cli_register(&show_manconn_cli); 01671 ast_extension_state_add(NULL, NULL, manager_state_cb, NULL); 01672 registered = 1; 01673 } 01674 portno = DEFAULT_MANAGER_PORT; 01675 displayconnects = 1; 01676 cfg = ast_config_load("manager.conf"); 01677 if (!cfg) { 01678 ast_log(LOG_NOTICE, "Unable to open management configuration manager.conf. Call management disabled.\n"); 01679 return 0; 01680 } 01681 memset(&ba, 0, sizeof(ba)); 01682 val = ast_variable_retrieve(cfg, "general", "enabled"); 01683 if (val) 01684 enabled = ast_true(val); 01685 01686 val = ast_variable_retrieve(cfg, "general", "block-sockets"); 01687 if(val) 01688 block_sockets = ast_true(val); 01689 01690 if ((val = ast_variable_retrieve(cfg, "general", "port"))) { 01691 if (sscanf(val, "%d", &portno) != 1) { 01692 ast_log(LOG_WARNING, "Invalid port number '%s'\n", val); 01693 portno = DEFAULT_MANAGER_PORT; 01694 } 01695 } else if ((val = ast_variable_retrieve(cfg, "general", "portno"))) { 01696 if (sscanf(val, "%d", &portno) != 1) { 01697 ast_log(LOG_WARNING, "Invalid port number '%s'\n", val); 01698 portno = DEFAULT_MANAGER_PORT; 01699 } 01700 ast_log(LOG_NOTICE, "Use of portno in manager.conf deprecated. Please use 'port=%s' instead.\n", val); 01701 } 01702 /* Parsing the displayconnects */ 01703 if ((val = ast_variable_retrieve(cfg, "general", "displayconnects"))) { 01704 displayconnects = ast_true(val);; 01705 } 01706 01707 01708 ba.sin_family = AF_INET; 01709 ba.sin_port = htons(portno); 01710 memset(&ba.sin_addr, 0, sizeof(ba.sin_addr)); 01711 01712 if ((val = ast_variable_retrieve(cfg, "general", "bindaddr"))) { 01713 if (!inet_aton(val, &ba.sin_addr)) { 01714 ast_log(LOG_WARNING, "Invalid address '%s' specified, using 0.0.0.0\n", val); 01715 memset(&ba.sin_addr, 0, sizeof(ba.sin_addr)); 01716 } 01717 } 01718 01719 if ((asock > -1) && ((portno != oldportno) || !enabled)) { 01720 #if 0 01721 /* Can't be done yet */ 01722 close(asock); 01723 asock = -1; 01724 #else 01725 ast_log(LOG_WARNING, "Unable to change management port / enabled\n"); 01726 #endif 01727 } 01728 ast_config_destroy(cfg); 01729 01730 /* If not enabled, do nothing */ 01731 if (!enabled) { 01732 return 0; 01733 } 01734 if (asock < 0) { 01735 asock = socket(AF_INET, SOCK_STREAM, 0); 01736 if (asock < 0) { 01737 ast_log(LOG_WARNING, "Unable to create socket: %s\n", strerror(errno)); 01738 return -1; 01739 } 01740 setsockopt(asock, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x)); 01741 if (bind(asock, (struct sockaddr *)&ba, sizeof(ba))) { 01742 ast_log(LOG_WARNING, "Unable to bind socket: %s\n", strerror(errno)); 01743 close(asock); 01744 asock = -1; 01745 return -1; 01746 } 01747 if (listen(asock, 2)) { 01748 ast_log(LOG_WARNING, "Unable to listen on socket: %s\n", strerror(errno)); 01749 close(asock); 01750 asock = -1; 01751 return -1; 01752 } 01753 if (option_verbose) 01754 ast_verbose("Asterisk Management interface listening on port %d\n", portno); 01755 ast_pthread_create(&t, NULL, accept_thread, NULL); 01756 } 01757 return 0; 01758 }
int reload_manager | ( | void | ) |
Called by Asterisk initialization
Definition at line 1760 of file manager.c.
References EVENT_FLAG_SYSTEM, init_manager(), and manager_event().
Referenced by ast_module_reload(), and main().
01761 { 01762 manager_event(EVENT_FLAG_SYSTEM, "Reload", "Message: Reload Requested\r\n"); 01763 return init_manager(); 01764 }
int registered = 0 [static] |