The Asterisk Management Interface - AMI. More...
#include "asterisk.h"#include "asterisk/_private.h"#include "asterisk/paths.h"#include <ctype.h>#include <sys/time.h>#include <signal.h>#include <sys/mman.h>#include <sys/types.h>#include <regex.h>#include "asterisk/channel.h"#include "asterisk/file.h"#include "asterisk/manager.h"#include "asterisk/module.h"#include "asterisk/config.h"#include "asterisk/callerid.h"#include "asterisk/lock.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/tcptls.h"#include "asterisk/http.h"#include "asterisk/ast_version.h"#include "asterisk/threadstorage.h"#include "asterisk/linkedlists.h"#include "asterisk/term.h"#include "asterisk/astobj2.h"#include "asterisk/features.h"#include "asterisk/security_events.h"#include "asterisk/aoc.h"#include "asterisk/stringfields.h"
Go to the source code of this file.
Data Structures | |
| struct | actions |
| list of actions registered More... | |
| struct | all_events |
| struct | ast_manager_user |
| user descriptor, as read from the config file. More... | |
| struct | channelvars |
| struct | eventqent |
| struct | fast_originate_helper |
| helper function for originate More... | |
| struct | manager_channel_variable |
| struct | manager_hooks |
| list of hooks registered More... | |
| struct | mansession |
| struct | mansession_datastores |
| struct | mansession_session |
| struct | permalias |
| struct | users |
| list of users found in the config file More... | |
| struct | variable_count |
Defines | |
| #define | ASTMAN_APPEND_BUF_INITSIZE 256 |
| initial allocated size for the astman_append_buf | |
| #define | DEFAULT_REALM "asterisk" |
| #define | FORMAT " %-25.25s %-15.15s\n" |
| #define | FORMAT2 " %-25.25s %-15d\n" |
| #define | GET_HEADER_FIRST_MATCH 0 |
| #define | GET_HEADER_LAST_MATCH 1 |
| #define | GET_HEADER_SKIP_EMPTY 2 |
| #define | HSMC_FORMAT " %-15.15s %-15.15s %-55.55s\n" |
| #define | HSMCONN_FORMAT1 " %-15.15s %-15.15s %-10.10s %-10.10s %-8.8s %-8.8s %-5.5s %-5.5s\n" |
| #define | HSMCONN_FORMAT2 " %-15.15s %-15.15s %-10d %-10d %-8d %-8d %-5.5d %-5.5d\n" |
| #define | MANAGER_EVENT_BUF_INITSIZE 256 |
| #define | MAX_BLACKLIST_CMD_LEN 2 |
| Descriptor for a manager session, either on the AMI socket or over HTTP. | |
| #define | MSG_MOREDATA ((char *)astman_send_response) |
| send a response with an optional message, and terminate it with an empty line. m is used only to grab the 'ActionID' field. | |
| #define | ROW_FMT "<tr><td colspan=\"2\" bgcolor=\"#f1f1ff\">%s</td></tr>\r\n" |
| #define | TEST_STRING "<form action=\"manager\" method=\"post\">\n\ Action: <select name=\"action\">\n\ <option value=\"\">-----></option>\n\ <option value=\"login\">login</option>\n\ <option value=\"command\">Command</option>\n\ <option value=\"waitevent\">waitevent</option>\n\ <option value=\"listcommands\">listcommands</option>\n\ </select>\n\ or <input name=\"action\"><br/>\n\ CLI Command <input name=\"command\"><br>\n\ user <input name=\"username\"> pass <input type=\"password\" name=\"secret\"><br>\n\ <input type=\"submit\">\n</form>\n" |
Enumerations | |
| enum | error_type { UNKNOWN_ACTION = 1, UNKNOWN_CATEGORY, UNSPECIFIED_CATEGORY, UNSPECIFIED_ARGUMENT, FAILURE_ALLOCATION, FAILURE_NEWCAT, FAILURE_DELCAT, FAILURE_EMPTYCAT, FAILURE_UPDATE, FAILURE_DELETE, FAILURE_APPEND } |
| enum | output_format { FORMAT_RAW, FORMAT_HTML, FORMAT_XML } |
Functions | |
| int | __ast_manager_event_multichan (int category, const char *event, int chancount, struct ast_channel **chans, const char *file, int line, const char *func, const char *fmt,...) |
| static const char * | __astman_get_header (const struct message *m, char *var, int mode) |
| Return a matching header value. | |
| static void | __init_astman_append_buf (void) |
| thread local buffer for astman_append | |
| static int | __init_manager (int reload) |
| static void | __init_manager_event_buf (void) |
| static void | __init_manager_event_funcbuf (void) |
| static void | __init_userevent_buf (void) |
| static int | action_aocmessage (struct mansession *s, const struct message *m) |
| static int | action_atxfer (struct mansession *s, const struct message *m) |
| static int | action_challenge (struct mansession *s, const struct message *m) |
| static int | action_command (struct mansession *s, const struct message *m) |
| 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_coreshowchannels (struct mansession *s, const struct message *m) |
| Manager command "CoreShowChannels" - List currently defined channels and some information about them. | |
| static int | action_corestatus (struct mansession *s, const struct message *m) |
| Show PBX core status information. | |
| static int | action_createconfig (struct mansession *s, const struct message *m) |
| static void | action_destroy (void *obj) |
| static int | action_events (struct mansession *s, const struct message *m) |
| static int | action_extensionstate (struct mansession *s, const struct message *m) |
| static struct manager_action * | action_find (const char *name) |
| static int | action_getconfig (struct mansession *s, const struct message *m) |
| static int | action_getconfigjson (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_listcategories (struct mansession *s, const struct message *m) |
| static int | action_listcommands (struct mansession *s, const struct message *m) |
| static int | action_login (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_reload (struct mansession *s, const struct message *m) |
| Send a reload event. | |
| static int | action_sendtext (struct mansession *s, const struct message *m) |
| 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 struct eventqent * | advance_event (struct eventqent *e) |
| static int | aocmessage_get_unit_entry (const struct message *m, struct ast_aoc_unit_entry *entry, unsigned int entry_num) |
| static void | append_channel_vars (struct ast_str **pbuf, struct ast_channel *chan) |
| static int | append_event (const char *str, int category) |
| int | ast_hook_send_action (struct manager_custom_hook *hook, const char *msg) |
| Registered hooks can call this function to invoke actions and they will receive responses through registered callback. | |
| static int | ast_instring (const char *bigstr, const char *smallstr, const char delim) |
| 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 | |
| void | ast_manager_register_hook (struct manager_custom_hook *hook) |
| Add a custom hook to be called when an event is fired. | |
| static int | ast_manager_register_struct (struct manager_action *act) |
| int | ast_manager_unregister (char *action) |
| Unregister a registered manager command. | |
| void | ast_manager_unregister_hook (struct manager_custom_hook *hook) |
| Delete a custom hook to be called when an event is fired. | |
| void | astman_append (struct mansession *s, const char *fmt,...) |
| static void | astman_append_json (struct mansession *s, const char *str) |
| int | astman_datastore_add (struct mansession *s, struct ast_datastore *datastore) |
| Add a datastore to a session. | |
| struct ast_datastore * | astman_datastore_find (struct mansession *s, const struct ast_datastore_info *info, const char *uid) |
| Find a datastore on a session. | |
| int | astman_datastore_remove (struct mansession *s, struct ast_datastore *datastore) |
| Remove a datastore from a session. | |
| const char * | astman_get_header (const struct message *m, char *var) |
| Return the first matching variable from an array. | |
| struct ast_variable * | astman_get_variables (const struct message *m) |
| Get a linked list of the Variable: headers. | |
| int | astman_is_authed (uint32_t ident) |
| Determinie if a manager session ident is authenticated. | |
| void | astman_send_ack (struct mansession *s, const struct message *m, char *msg) |
| Send ack in manager transaction. | |
| void | astman_send_error (struct mansession *s, const struct message *m, char *error) |
| Send error in manager transaction. | |
| void | astman_send_listack (struct mansession *s, const struct message *m, char *msg, char *listflag) |
| Send ack in manager list transaction. | |
| void | astman_send_response (struct mansession *s, const struct message *m, char *resp, char *msg) |
| Send response in manager transaction. | |
| static void | astman_send_response_full (struct mansession *s, const struct message *m, char *resp, char *msg, char *listflag) |
| static void | astman_start_ack (struct mansession *s, const struct message *m) |
| 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 | auth_http_callback (struct ast_tcptls_session_instance *ser, enum ast_http_method method, enum output_format format, struct sockaddr_in *remote_address, const char *uri, struct ast_variable *get_params, struct ast_variable *headers) |
| static int | auth_manager_http_callback (struct ast_tcptls_session_instance *ser, const struct ast_http_uri *urih, const char *uri, enum ast_http_method method, struct ast_variable *get_params, struct ast_variable *headers) |
| static int | auth_mxml_http_callback (struct ast_tcptls_session_instance *ser, const struct ast_http_uri *urih, const char *uri, enum ast_http_method method, struct ast_variable *get_params, struct ast_variable *headers) |
| static int | auth_rawman_http_callback (struct ast_tcptls_session_instance *ser, const struct ast_http_uri *urih, const char *uri, enum ast_http_method method, struct ast_variable *get_params, struct ast_variable *headers) |
| static int | authenticate (struct mansession *s, const struct message *m) |
| static const char * | authority_to_str (int authority, struct ast_str **res) |
| Convert authority code to a list of options. | |
| static int | blackfilter_cmp_fn (void *obj, void *arg, void *data, int flags) |
| static struct mansession_session * | build_mansession (struct sockaddr_in sin) |
| Allocate manager session structure and add it to the list of sessions. | |
| static int | check_blacklist (const char *cmd) |
| int | check_manager_enabled (void) |
| Check if AMI is enabled. | |
| static int | check_manager_session_inuse (const char *name) |
| int | check_webmanager_enabled (void) |
| Check if AMI/HTTP is enabled. | |
| static void | destroy_fast_originate_helper (struct fast_originate_helper *doomed) |
| static int | do_message (struct mansession *s) |
| static void | event_filter_destructor (void *obj) |
| static void * | fast_originate (void *data) |
| static struct mansession_session * | find_session (uint32_t ident, int incinuse) |
| static struct mansession_session * | find_session_by_nonce (const char *username, unsigned long nonce, int *stale) |
| static void | free_channelvars (void) |
| static int | function_capable_string_allowed_with_auths (const char *evaluating, int writepermlist) |
| Checks to see if a string which can be used to evaluate functions should be rejected. | |
| static int | generic_http_callback (struct ast_tcptls_session_instance *ser, enum ast_http_method method, enum output_format format, struct sockaddr_in *remote_address, const char *uri, struct ast_variable *get_params, struct ast_variable *headers) |
| static int | get_input (struct mansession *s, char *output) |
| static struct ast_manager_user * | get_manager_by_name_locked (const char *name) |
| static int | get_perm (const char *instr) |
| static struct eventqent * | grab_last (void) |
| static char * | handle_manager_reload (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| CLI command manager reload. | |
| static char * | handle_manager_show_settings (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| CLI command manager show settings. | |
| static char * | handle_mandebug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_showmanager (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_showmanagers (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_showmancmd (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_showmancmds (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| CLI command manager list commands. | |
| static char * | handle_showmanconn (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| CLI command manager list connected. | |
| static char * | handle_showmaneventq (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| CLI command manager list eventq. | |
| static enum error_type | handle_updates (struct mansession *s, const struct message *m, struct ast_config *cfg, const char *dfn) |
| int | init_manager (void) |
| Called by Asterisk initialization. | |
| static void | json_escape (char *out, const char *in) |
| static void | load_channelvars (struct ast_variable *var) |
| static struct ast_variable * | man_do_variable_value (struct ast_variable *head, const char *hdr_val) |
| static int | manager_displayconnects (struct mansession_session *session) |
| Get displayconnects config option. | |
| static int | manager_http_callback (struct ast_tcptls_session_instance *ser, const struct ast_http_uri *urih, const char *uri, enum ast_http_method method, struct ast_variable *get_params, struct ast_variable *headers) |
| static int | manager_modulecheck (struct mansession *s, const struct message *m) |
| static int | manager_moduleload (struct mansession *s, const struct message *m) |
| static int | manager_state_cb (char *context, char *exten, int state, void *data) |
| static int | mansession_cmp_fn (void *obj, void *arg, int flags) |
| static struct sockaddr_in * | mansession_encode_sin_local (const struct mansession *s, struct sockaddr_in *sin_local) |
| static enum ast_security_event_transport_type | mansession_get_transport (const struct mansession *s) |
| static void | mansession_lock (struct mansession *s) |
| Lock the 'mansession' structure. | |
| static void | mansession_unlock (struct mansession *s) |
| Unlock the 'mansession' structure. | |
| static int | match_filter (struct mansession *s, char *eventdata) |
| static int | mxml_http_callback (struct ast_tcptls_session_instance *ser, const struct ast_http_uri *urih, const char *uri, enum ast_http_method method, struct ast_variable *get_params, struct ast_variable *headers) |
| static int | process_events (struct mansession *s) |
| static int | process_message (struct mansession *s, const struct message *m) |
| static void | process_output (struct mansession *s, struct ast_str **out, struct ast_variable *params, enum output_format format) |
| static void | purge_events (void) |
| static void | purge_old_stuff (void *data) |
| cleanup code called at each iteration of server_root, guaranteed to happen every 5 seconds at most | |
| static void | purge_sessions (int n_max) |
| remove at most n_max stale session from the list. | |
| static int | rawman_http_callback (struct ast_tcptls_session_instance *ser, const struct ast_http_uri *urih, const char *uri, enum ast_http_method method, struct ast_variable *get_params, struct ast_variable *headers) |
| int | reload_manager (void) |
| Called by Asterisk module functions and the CLI command. | |
| static void | report_auth_success (const struct mansession *s) |
| static void | report_failed_acl (const struct mansession *s, const char *username) |
| static void | report_failed_challenge_response (const struct mansession *s, const char *response, const char *expected_response) |
| static void | report_inval_password (const struct mansession *s, const char *username) |
| static void | report_invalid_user (const struct mansession *s, const char *username) |
| static void | report_req_bad_format (const struct mansession *s, const char *action) |
| static void | report_req_not_allowed (const struct mansession *s, const char *action) |
| static void | report_session_limit (const struct mansession *s) |
| static int | send_string (struct mansession *s, char *string) |
| static void | session_destroy (struct mansession_session *s) |
| static void | session_destructor (void *obj) |
| static void * | session_do (void *data) |
| The body of the individual manager session. Call get_input() to read one line at a time (or be woken up on new events), collect the lines in a message until found an empty line, and execute the request. In any case, deliver events asynchronously through process_events() (called from here if no line is available, or at the end of process_message(). ). | |
| 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 struct mansession_session * | unref_mansession (struct mansession_session *s) |
| Unreference manager session object. If no more references, then go ahead and delete it. | |
| 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 int | whitefilter_cmp_fn (void *obj, void *arg, void *data, int flags) |
| static void | xml_copy_escape (struct ast_str **out, const char *src, int mode) |
| static void | xml_translate (struct ast_str **out, char *in, struct ast_variable *get_vars, enum output_format format) |
| Convert the input into XML or HTML. The input is supposed to be a sequence of lines of the form Name: value optionally followed by a blob of unformatted text. A blank line is a section separator. Basically, this is a mixture of the format of Manager Interface and CLI commands. The unformatted text is considered as a single value of a field named 'Opaque-data'. | |
Variables | |
| static int | allowmultiplelogin = 1 |
| static struct ast_http_uri | amanageruri |
| static struct ast_http_uri | amanagerxmluri |
| static struct ast_tcptls_session_args | ami_desc |
| static struct ast_tls_config | ami_tls_cfg |
| static struct ast_tcptls_session_args | amis_desc |
| static struct ast_http_uri | arawmanuri |
| static struct ast_threadstorage | astman_append_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_astman_append_buf , .custom_init = NULL , } |
| static int | authlimit |
| static int | authtimeout |
| static int | block_sockets |
| static int | broken_events_action |
| static struct ast_cli_entry | cli_manager [] |
| struct { | |
| const char * words [AST_MAX_CMD_LEN] | |
| } | command_blacklist [] |
| static const char *const | contenttype [] |
| static const int | DEFAULT_AUTHLIMIT = 50 |
| static const int | DEFAULT_AUTHTIMEOUT = 30 |
| static const int | DEFAULT_BLOCKSOCKETS = 0 |
| static const int | DEFAULT_BROKENEVENTSACTION = 0 |
| static const int | DEFAULT_DISPLAYCONNECTS = 1 |
| static const int | DEFAULT_ENABLED = 0 |
| static const int | DEFAULT_HTTPTIMEOUT = 60 |
| static const int | DEFAULT_MANAGERDEBUG = 0 |
| static const int | DEFAULT_TIMESTAMPEVENTS = 0 |
| static const int | DEFAULT_WEBENABLED = 0 |
| static int | displayconnects |
| static char | global_realm [MAXHOSTNAMELEN] |
| static int | httptimeout |
| static char * | manager_channelvars |
| static int | manager_debug = 0 |
| static int | manager_enabled = 0 |
| static struct ast_threadstorage | manager_event_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_manager_event_buf , .custom_init = NULL , } |
| static struct ast_threadstorage | manager_event_funcbuf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_manager_event_funcbuf , .custom_init = NULL , } |
| static struct ast_http_uri | manageruri |
| static struct ast_http_uri | managerxmluri |
| static struct permalias | perms [] |
| static struct ast_http_uri | rawmanuri |
| static int | registered = 0 |
| static struct ao2_container * | sessions = NULL |
| static int | timestampevents |
| static int | unauth_sessions = 0 |
| static struct ast_threadstorage | userevent_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_userevent_buf , .custom_init = NULL , } |
| static int | webmanager_enabled = 0 |
| static int | webregged = 0 |
The Asterisk Management Interface - AMI.
At the moment this file contains a number of functions, namely:
Definition in file manager.c.
| #define FORMAT " %-25.25s %-15.15s\n" |
| #define FORMAT2 " %-25.25s %-15d\n" |
| #define HSMC_FORMAT " %-15.15s %-15.15s %-55.55s\n" |
Referenced by handle_showmancmds().
| #define HSMCONN_FORMAT1 " %-15.15s %-15.15s %-10.10s %-10.10s %-8.8s %-8.8s %-5.5s %-5.5s\n" |
Referenced by handle_showmanconn().
| #define HSMCONN_FORMAT2 " %-15.15s %-15.15s %-10d %-10d %-8d %-8d %-5.5d %-5.5d\n" |
Referenced by handle_showmanconn().
| #define ROW_FMT "<tr><td colspan=\"2\" bgcolor=\"#f1f1ff\">%s</td></tr>\r\n" |
Referenced by generic_http_callback().
| #define TEST_STRING "<form action=\"manager\" method=\"post\">\n\ Action: <select name=\"action\">\n\ <option value=\"\">-----></option>\n\ <option value=\"login\">login</option>\n\ <option value=\"command\">Command</option>\n\ <option value=\"waitevent\">waitevent</option>\n\ <option value=\"listcommands\">listcommands</option>\n\ </select>\n\ or <input name=\"action\"><br/>\n\ CLI Command <input name=\"command\"><br>\n\ user <input name=\"username\"> pass <input type=\"password\" name=\"secret\"><br>\n\ <input type=\"submit\">\n</form>\n" |
Referenced by generic_http_callback().
| enum output_format |
END Doxygen group
Definition at line 5386 of file manager.c.
05386 { 05387 FORMAT_RAW, 05388 FORMAT_HTML, 05389 FORMAT_XML, 05390 };
| static int __init_manager | ( | int | reload | ) | [static] |
Definition at line 6574 of file manager.c.
References ast_manager_user::a1_hash, action_aocmessage(), action_atxfer(), action_challenge(), action_command(), action_coresettings(), action_coreshowchannels(), action_corestatus(), action_createconfig(), action_events(), action_extensionstate(), action_getconfig(), action_getconfigjson(), action_getvar(), action_hangup(), action_listcategories(), action_listcommands(), action_login(), action_logoff(), action_mailboxcount(), action_mailboxstatus(), action_originate(), action_ping(), action_redirect(), action_reload(), action_sendtext(), action_setvar(), action_status(), action_timeout(), action_updateconfig(), action_userevent(), action_waitevent(), ami_tls_cfg, ao2_container_alloc, ao2_t_alloc, ao2_t_callback, ao2_t_link, ao2_t_ref, append_event(), ARRAY_LEN, ast_append_ha(), ast_calloc, ast_category_browse(), AST_CERTFILE, ast_cli_register_multiple(), ast_config_AST_SYSTEM_NAME, ast_config_destroy(), ast_config_load2(), ast_copy_string(), ast_debug, ast_extension_state_add(), ast_free, ast_free_ha(), ast_http_uri_link(), ast_http_uri_unlink(), AST_LIST_INSERT_TAIL, ast_log(), ast_manager_register_xml, ast_md5_hash(), AST_RWLIST_INSERT_TAIL, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_sockaddr_from_sin, ast_sockaddr_setnull(), ast_sockaddr_to_sin, ast_ssl_setup(), ast_strdup, ast_strlen_zero(), ast_tcptls_server_start(), ast_tcptls_server_stop(), ast_tls_read_conf(), ast_true(), ast_variable_browse(), ast_variable_retrieve(), ast_manager_user::blackfilters, block_sockets, ast_tls_config::certfile, ast_tls_config::cipher, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, DEFAULT_MANAGER_PORT, DEFAULT_MANAGER_TLS_PORT, DEFAULT_REALM, ast_manager_user::displayconnects, ast_tls_config::enabled, event_filter_destructor(), EVENT_FLAG_AOC, EVENT_FLAG_CALL, EVENT_FLAG_COMMAND, EVENT_FLAG_CONFIG, EVENT_FLAG_ORIGINATE, EVENT_FLAG_REPORTING, EVENT_FLAG_SYSTEM, EVENT_FLAG_USER, free_channelvars(), get_manager_by_name_locked(), get_perm(), global_realm, ast_manager_user::ha, ast_manager_user::keep, ast_variable::lineno, load_channelvars(), ast_tcptls_session_args::local_address, LOG_NOTICE, LOG_WARNING, manager_event, manager_modulecheck(), manager_moduleload(), manager_state_cb(), mansession_cmp_fn(), ast_variable::name, ast_variable::next, OBJ_MULTIPLE, OBJ_NODATA, OBJ_UNLINK, ast_tls_config::pvtfile, ast_manager_user::readperm, S_OR, ast_manager_user::secret, sessions, ast_tcptls_session_args::tls_cfg, ast_manager_user::username, value, ast_variable::value, var, ast_manager_user::whitefilters, ast_manager_user::writeperm, and ast_manager_user::writetimeout.
Referenced by init_manager(), and reload_manager().
06575 { 06576 struct ast_config *ucfg = NULL, *cfg = NULL; 06577 const char *val; 06578 char *cat = NULL; 06579 int newhttptimeout = DEFAULT_HTTPTIMEOUT; 06580 struct ast_manager_user *user = NULL; 06581 struct ast_variable *var; 06582 struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; 06583 char a1[256]; 06584 char a1_hash[256]; 06585 struct sockaddr_in ami_desc_local_address_tmp = { 0, }; 06586 struct sockaddr_in amis_desc_local_address_tmp = { 0, }; 06587 int tls_was_enabled = 0; 06588 06589 if (!registered) { 06590 /* Register default actions */ 06591 ast_manager_register_xml("Ping", 0, action_ping); 06592 ast_manager_register_xml("Events", 0, action_events); 06593 ast_manager_register_xml("Logoff", 0, action_logoff); 06594 ast_manager_register_xml("Login", 0, action_login); 06595 ast_manager_register_xml("Challenge", 0, action_challenge); 06596 ast_manager_register_xml("Hangup", EVENT_FLAG_SYSTEM | EVENT_FLAG_CALL, action_hangup); 06597 ast_manager_register_xml("Status", EVENT_FLAG_SYSTEM | EVENT_FLAG_CALL | EVENT_FLAG_REPORTING, action_status); 06598 ast_manager_register_xml("Setvar", EVENT_FLAG_CALL, action_setvar); 06599 ast_manager_register_xml("Getvar", EVENT_FLAG_CALL | EVENT_FLAG_REPORTING, action_getvar); 06600 ast_manager_register_xml("GetConfig", EVENT_FLAG_SYSTEM | EVENT_FLAG_CONFIG, action_getconfig); 06601 ast_manager_register_xml("GetConfigJSON", EVENT_FLAG_SYSTEM | EVENT_FLAG_CONFIG, action_getconfigjson); 06602 ast_manager_register_xml("UpdateConfig", EVENT_FLAG_CONFIG, action_updateconfig); 06603 ast_manager_register_xml("CreateConfig", EVENT_FLAG_CONFIG, action_createconfig); 06604 ast_manager_register_xml("ListCategories", EVENT_FLAG_CONFIG, action_listcategories); 06605 ast_manager_register_xml("Redirect", EVENT_FLAG_CALL, action_redirect); 06606 ast_manager_register_xml("Atxfer", EVENT_FLAG_CALL, action_atxfer); 06607 ast_manager_register_xml("Originate", EVENT_FLAG_ORIGINATE, action_originate); 06608 ast_manager_register_xml("Command", EVENT_FLAG_COMMAND, action_command); 06609 ast_manager_register_xml("ExtensionState", EVENT_FLAG_CALL | EVENT_FLAG_REPORTING, action_extensionstate); 06610 ast_manager_register_xml("AbsoluteTimeout", EVENT_FLAG_SYSTEM | EVENT_FLAG_CALL, action_timeout); 06611 ast_manager_register_xml("MailboxStatus", EVENT_FLAG_CALL | EVENT_FLAG_REPORTING, action_mailboxstatus); 06612 ast_manager_register_xml("MailboxCount", EVENT_FLAG_CALL | EVENT_FLAG_REPORTING, action_mailboxcount); 06613 ast_manager_register_xml("ListCommands", 0, action_listcommands); 06614 ast_manager_register_xml("SendText", EVENT_FLAG_CALL, action_sendtext); 06615 ast_manager_register_xml("UserEvent", EVENT_FLAG_USER, action_userevent); 06616 ast_manager_register_xml("WaitEvent", 0, action_waitevent); 06617 ast_manager_register_xml("CoreSettings", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, action_coresettings); 06618 ast_manager_register_xml("CoreStatus", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, action_corestatus); 06619 ast_manager_register_xml("Reload", EVENT_FLAG_CONFIG | EVENT_FLAG_SYSTEM, action_reload); 06620 ast_manager_register_xml("CoreShowChannels", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, action_coreshowchannels); 06621 ast_manager_register_xml("ModuleLoad", EVENT_FLAG_SYSTEM, manager_moduleload); 06622 ast_manager_register_xml("ModuleCheck", EVENT_FLAG_SYSTEM, manager_modulecheck); 06623 ast_manager_register_xml("AOCMessage", EVENT_FLAG_AOC, action_aocmessage); 06624 06625 ast_cli_register_multiple(cli_manager, ARRAY_LEN(cli_manager)); 06626 ast_extension_state_add(NULL, NULL, manager_state_cb, NULL); 06627 registered = 1; 06628 /* Append placeholder event so master_eventq never runs dry */ 06629 append_event("Event: Placeholder\r\n\r\n", 0); 06630 } 06631 if ((cfg = ast_config_load2("manager.conf", "manager", config_flags)) == CONFIG_STATUS_FILEUNCHANGED) { 06632 return 0; 06633 } 06634 06635 manager_enabled = DEFAULT_ENABLED; 06636 webmanager_enabled = DEFAULT_WEBENABLED; 06637 manager_debug = DEFAULT_MANAGERDEBUG; 06638 displayconnects = DEFAULT_DISPLAYCONNECTS; 06639 broken_events_action = DEFAULT_BROKENEVENTSACTION; 06640 block_sockets = DEFAULT_BLOCKSOCKETS; 06641 timestampevents = DEFAULT_TIMESTAMPEVENTS; 06642 httptimeout = DEFAULT_HTTPTIMEOUT; 06643 authtimeout = DEFAULT_AUTHTIMEOUT; 06644 authlimit = DEFAULT_AUTHLIMIT; 06645 06646 if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) { 06647 ast_log(LOG_NOTICE, "Unable to open AMI configuration manager.conf, or configuration is invalid. Asterisk management interface (AMI) disabled.\n"); 06648 return 0; 06649 } 06650 06651 /* default values */ 06652 ast_copy_string(global_realm, S_OR(ast_config_AST_SYSTEM_NAME, DEFAULT_REALM), sizeof(global_realm)); 06653 ast_sockaddr_setnull(&ami_desc.local_address); 06654 ast_sockaddr_setnull(&amis_desc.local_address); 06655 06656 ami_desc_local_address_tmp.sin_family = AF_INET; 06657 amis_desc_local_address_tmp.sin_family = AF_INET; 06658 06659 ami_desc_local_address_tmp.sin_port = htons(DEFAULT_MANAGER_PORT); 06660 06661 tls_was_enabled = (reload && ami_tls_cfg.enabled); 06662 06663 ami_tls_cfg.enabled = 0; 06664 if (ami_tls_cfg.certfile) { 06665 ast_free(ami_tls_cfg.certfile); 06666 } 06667 ami_tls_cfg.certfile = ast_strdup(AST_CERTFILE); 06668 if (ami_tls_cfg.pvtfile) { 06669 ast_free(ami_tls_cfg.pvtfile); 06670 } 06671 ami_tls_cfg.pvtfile = ast_strdup(""); 06672 if (ami_tls_cfg.cipher) { 06673 ast_free(ami_tls_cfg.cipher); 06674 } 06675 ami_tls_cfg.cipher = ast_strdup(""); 06676 06677 free_channelvars(); 06678 06679 for (var = ast_variable_browse(cfg, "general"); var; var = var->next) { 06680 val = var->value; 06681 06682 if (!ast_tls_read_conf(&ami_tls_cfg, &amis_desc, var->name, val)) { 06683 continue; 06684 } 06685 06686 if (!strcasecmp(var->name, "enabled")) { 06687 manager_enabled = ast_true(val); 06688 } else if (!strcasecmp(var->name, "block-sockets")) { 06689 block_sockets = ast_true(val); 06690 } else if (!strcasecmp(var->name, "webenabled")) { 06691 webmanager_enabled = ast_true(val); 06692 } else if (!strcasecmp(var->name, "port")) { 06693 ami_desc_local_address_tmp.sin_port = htons(atoi(val)); 06694 } else if (!strcasecmp(var->name, "bindaddr")) { 06695 if (!inet_aton(val, &ami_desc_local_address_tmp.sin_addr)) { 06696 ast_log(LOG_WARNING, "Invalid address '%s' specified, using 0.0.0.0\n", val); 06697 memset(&ami_desc_local_address_tmp.sin_addr, 0, 06698 sizeof(ami_desc_local_address_tmp.sin_addr)); 06699 } 06700 } else if (!strcasecmp(var->name, "brokeneventsaction")) { 06701 broken_events_action = ast_true(val); 06702 } else if (!strcasecmp(var->name, "allowmultiplelogin")) { 06703 allowmultiplelogin = ast_true(val); 06704 } else if (!strcasecmp(var->name, "displayconnects")) { 06705 displayconnects = ast_true(val); 06706 } else if (!strcasecmp(var->name, "timestampevents")) { 06707 timestampevents = ast_true(val); 06708 } else if (!strcasecmp(var->name, "debug")) { 06709 manager_debug = ast_true(val); 06710 } else if (!strcasecmp(var->name, "httptimeout")) { 06711 newhttptimeout = atoi(val); 06712 } else if (!strcasecmp(var->name, "authtimeout")) { 06713 int timeout = atoi(var->value); 06714 06715 if (timeout < 1) { 06716 ast_log(LOG_WARNING, "Invalid authtimeout value '%s', using default value\n", var->value); 06717 } else { 06718 authtimeout = timeout; 06719 } 06720 } else if (!strcasecmp(var->name, "authlimit")) { 06721 int limit = atoi(var->value); 06722 06723 if (limit < 1) { 06724 ast_log(LOG_WARNING, "Invalid authlimit value '%s', using default value\n", var->value); 06725 } else { 06726 authlimit = limit; 06727 } 06728 } else if (!strcasecmp(var->name, "channelvars")) { 06729 load_channelvars(var); 06730 } else { 06731 ast_log(LOG_NOTICE, "Invalid keyword <%s> = <%s> in manager.conf [general]\n", 06732 var->name, val); 06733 } 06734 } 06735 06736 ast_sockaddr_to_sin(&amis_desc.local_address, &amis_desc_local_address_tmp); 06737 06738 /* if the amis address has not been set, default is the same as non secure ami */ 06739 if (!amis_desc_local_address_tmp.sin_addr.s_addr) { 06740 amis_desc_local_address_tmp.sin_addr = 06741 ami_desc_local_address_tmp.sin_addr; 06742 } 06743 06744 if (!amis_desc_local_address_tmp.sin_port) { 06745 amis_desc_local_address_tmp.sin_port = htons(DEFAULT_MANAGER_TLS_PORT); 06746 } 06747 06748 if (manager_enabled) { 06749 ast_sockaddr_from_sin(&ami_desc.local_address, &ami_desc_local_address_tmp); 06750 ast_sockaddr_from_sin(&amis_desc.local_address, &amis_desc_local_address_tmp); 06751 } 06752 06753 AST_RWLIST_WRLOCK(&users); 06754 06755 /* First, get users from users.conf */ 06756 ucfg = ast_config_load2("users.conf", "manager", config_flags); 06757 if (ucfg && (ucfg != CONFIG_STATUS_FILEUNCHANGED) && ucfg != CONFIG_STATUS_FILEINVALID) { 06758 const char *hasmanager; 06759 int genhasmanager = ast_true(ast_variable_retrieve(ucfg, "general", "hasmanager")); 06760 06761 while ((cat = ast_category_browse(ucfg, cat))) { 06762 if (!strcasecmp(cat, "general")) { 06763 continue; 06764 } 06765 06766 hasmanager = ast_variable_retrieve(ucfg, cat, "hasmanager"); 06767 if ((!hasmanager && genhasmanager) || ast_true(hasmanager)) { 06768 const char *user_secret = ast_variable_retrieve(ucfg, cat, "secret"); 06769 const char *user_read = ast_variable_retrieve(ucfg, cat, "read"); 06770 const char *user_write = ast_variable_retrieve(ucfg, cat, "write"); 06771 const char *user_displayconnects = ast_variable_retrieve(ucfg, cat, "displayconnects"); 06772 const char *user_writetimeout = ast_variable_retrieve(ucfg, cat, "writetimeout"); 06773 06774 /* Look for an existing entry, 06775 * if none found - create one and add it to the list 06776 */ 06777 if (!(user = get_manager_by_name_locked(cat))) { 06778 if (!(user = ast_calloc(1, sizeof(*user)))) { 06779 break; 06780 } 06781 06782 /* Copy name over */ 06783 ast_copy_string(user->username, cat, sizeof(user->username)); 06784 /* Insert into list */ 06785 AST_LIST_INSERT_TAIL(&users, user, list); 06786 user->ha = NULL; 06787 user->keep = 1; 06788 user->readperm = -1; 06789 user->writeperm = -1; 06790 /* Default displayconnect from [general] */ 06791 user->displayconnects = displayconnects; 06792 user->writetimeout = 100; 06793 } 06794 06795 if (!user_secret) { 06796 user_secret = ast_variable_retrieve(ucfg, "general", "secret"); 06797 } 06798 if (!user_read) { 06799 user_read = ast_variable_retrieve(ucfg, "general", "read"); 06800 } 06801 if (!user_write) { 06802 user_write = ast_variable_retrieve(ucfg, "general", "write"); 06803 } 06804 if (!user_displayconnects) { 06805 user_displayconnects = ast_variable_retrieve(ucfg, "general", "displayconnects"); 06806 } 06807 if (!user_writetimeout) { 06808 user_writetimeout = ast_variable_retrieve(ucfg, "general", "writetimeout"); 06809 } 06810 06811 if (!ast_strlen_zero(user_secret)) { 06812 if (user->secret) { 06813 ast_free(user->secret); 06814 } 06815 user->secret = ast_strdup(user_secret); 06816 } 06817 06818 if (user_read) { 06819 user->readperm = get_perm(user_read); 06820 } 06821 if (user_write) { 06822 user->writeperm = get_perm(user_write); 06823 } 06824 if (user_displayconnects) { 06825 user->displayconnects = ast_true(user_displayconnects); 06826 } 06827 if (user_writetimeout) { 06828 int value = atoi(user_writetimeout); 06829 if (value < 100) { 06830 ast_log(LOG_WARNING, "Invalid writetimeout value '%d' in users.conf\n", value); 06831 } else { 06832 user->writetimeout = value; 06833 } 06834 } 06835 } 06836 } 06837 ast_config_destroy(ucfg); 06838 } 06839 06840 /* cat is NULL here in any case */ 06841 06842 while ((cat = ast_category_browse(cfg, cat))) { 06843 struct ast_ha *oldha; 06844 06845 if (!strcasecmp(cat, "general")) { 06846 continue; 06847 } 06848 06849 /* Look for an existing entry, if none found - create one and add it to the list */ 06850 if (!(user = get_manager_by_name_locked(cat))) { 06851 if (!(user = ast_calloc(1, sizeof(*user)))) { 06852 break; 06853 } 06854 /* Copy name over */ 06855 ast_copy_string(user->username, cat, sizeof(user->username)); 06856 06857 user->ha = NULL; 06858 user->readperm = 0; 06859 user->writeperm = 0; 06860 /* Default displayconnect from [general] */ 06861 user->displayconnects = displayconnects; 06862 user->writetimeout = 100; 06863 user->whitefilters = ao2_container_alloc(1, NULL, NULL); 06864 user->blackfilters = ao2_container_alloc(1, NULL, NULL); 06865 06866 /* Insert into list */ 06867 AST_RWLIST_INSERT_TAIL(&users, user, list); 06868 } else { 06869 ao2_t_callback(user->whitefilters, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL, "unlink all white filters"); 06870 ao2_t_callback(user->blackfilters, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL, "unlink all black filters"); 06871 } 06872 06873 /* Make sure we keep this user and don't destroy it during cleanup */ 06874 user->keep = 1; 06875 oldha = user->ha; 06876 user->ha = NULL; 06877 06878 var = ast_variable_browse(cfg, cat); 06879 for (; var; var = var->next) { 06880 if (!strcasecmp(var->name, "secret")) { 06881 if (user->secret) { 06882 ast_free(user->secret); 06883 } 06884 user->secret = ast_strdup(var->value); 06885 } else if (!strcasecmp(var->name, "deny") || 06886 !strcasecmp(var->name, "permit")) { 06887 user->ha = ast_append_ha(var->name, var->value, user->ha, NULL); 06888 } else if (!strcasecmp(var->name, "read") ) { 06889 user->readperm = get_perm(var->value); 06890 } else if (!strcasecmp(var->name, "write") ) { 06891 user->writeperm = get_perm(var->value); 06892 } else if (!strcasecmp(var->name, "displayconnects") ) { 06893 user->displayconnects = ast_true(var->value); 06894 } else if (!strcasecmp(var->name, "writetimeout")) { 06895 int value = atoi(var->value); 06896 if (value < 100) { 06897 ast_log(LOG_WARNING, "Invalid writetimeout value '%s' at line %d\n", var->value, var->lineno); 06898 } else { 06899 user->writetimeout = value; 06900 } 06901 } else if (!strcasecmp(var->name, "eventfilter")) { 06902 const char *value = var->value; 06903 regex_t *new_filter = ao2_t_alloc(sizeof(*new_filter), event_filter_destructor, "event_filter allocation"); 06904 if (new_filter) { 06905 int is_blackfilter; 06906 if (value[0] == '!') { 06907 is_blackfilter = 1; 06908 value++; 06909 } else { 06910 is_blackfilter = 0; 06911 } 06912 if (regcomp(new_filter, value, 0)) { 06913 ao2_t_ref(new_filter, -1, "failed to make regx"); 06914 } else { 06915 if (is_blackfilter) { 06916 ao2_t_link(user->blackfilters, new_filter, "link new filter into black user container"); 06917 } else { 06918 ao2_t_link(user->whitefilters, new_filter, "link new filter into white user container"); 06919 } 06920 } 06921 } 06922 } else { 06923 ast_debug(1, "%s is an unknown option.\n", var->name); 06924 } 06925 } 06926 ast_free_ha(oldha); 06927 } 06928 ast_config_destroy(cfg); 06929 06930 /* Perform cleanup - essentially prune out old users that no longer exist */ 06931 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&users, user, list) { 06932 if (user->keep) { /* valid record. clear flag for the next round */ 06933 user->keep = 0; 06934 06935 /* Calculate A1 for Digest auth */ 06936 snprintf(a1, sizeof(a1), "%s:%s:%s", user->username, global_realm, user->secret); 06937 ast_md5_hash(a1_hash,a1); 06938 if (user->a1_hash) { 06939 ast_free(user->a1_hash); 06940 } 06941 user->a1_hash = ast_strdup(a1_hash); 06942 continue; 06943 } 06944 /* We do not need to keep this user so take them out of the list */ 06945 AST_RWLIST_REMOVE_CURRENT(list); 06946 ast_debug(4, "Pruning user '%s'\n", user->username); 06947 /* Free their memory now */ 06948 if (user->a1_hash) { 06949 ast_free(user->a1_hash); 06950 } 06951 if (user->secret) { 06952 ast_free(user->secret); 06953 } 06954 ao2_t_callback(user->whitefilters, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL, "unlink all white filters"); 06955 ao2_t_callback(user->blackfilters, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL, "unlink all black filters"); 06956 ao2_t_ref(user->whitefilters, -1, "decrement ref for white container, should be last one"); 06957 ao2_t_ref(user->blackfilters, -1, "decrement ref for black container, should be last one"); 06958 ast_free_ha(user->ha); 06959 ast_free(user); 06960 } 06961 AST_RWLIST_TRAVERSE_SAFE_END; 06962 06963 AST_RWLIST_UNLOCK(&users); 06964 06965 if (!reload) { 06966 /* If you have a NULL hash fn, you only need a single bucket */ 06967 sessions = ao2_container_alloc(1, NULL, mansession_cmp_fn); 06968 } 06969 06970 if (webmanager_enabled && manager_enabled) { 06971 if (!webregged) { 06972 06973 ast_http_uri_link(&rawmanuri); 06974 ast_http_uri_link(&manageruri); 06975 ast_http_uri_link(&managerxmluri); 06976 06977 ast_http_uri_link(&arawmanuri); 06978 ast_http_uri_link(&amanageruri); 06979 ast_http_uri_link(&amanagerxmluri); 06980 webregged = 1; 06981 } 06982 } else { 06983 if (webregged) { 06984 ast_http_uri_unlink(&rawmanuri); 06985 ast_http_uri_unlink(&manageruri); 06986 ast_http_uri_unlink(&managerxmluri); 06987 06988 ast_http_uri_unlink(&arawmanuri); 06989 ast_http_uri_unlink(&amanageruri); 06990 ast_http_uri_unlink(&amanagerxmluri); 06991 webregged = 0; 06992 } 06993 } 06994 06995 if (newhttptimeout > 0) { 06996 httptimeout = newhttptimeout; 06997 } 06998 06999 manager_event(EVENT_FLAG_SYSTEM, "Reload", "Module: Manager\r\nStatus: %s\r\nMessage: Manager reload Requested\r\n", manager_enabled ? "Enabled" : "Disabled"); 07000 07001 ast_tcptls_server_start(&ami_desc); 07002 if (tls_was_enabled && !ami_tls_cfg.enabled) { 07003 ast_tcptls_server_stop(&amis_desc); 07004 } else if (ast_ssl_setup(amis_desc.tls_cfg)) { 07005 ast_tcptls_server_start(&amis_desc); 07006 } 07007 return 0; 07008 }
| int astman_datastore_add | ( | struct mansession * | s, | |
| struct ast_datastore * | datastore | |||
| ) |
Add a datastore to a session.
| 0 | success | |
| non-zero | failure |
Definition at line 7031 of file manager.c.
References AST_LIST_INSERT_HEAD, mansession_session::datastores, and mansession::session.
07032 { 07033 AST_LIST_INSERT_HEAD(&s->session->datastores, datastore, entry); 07034 07035 return 0; 07036 }
| struct ast_datastore* astman_datastore_find | ( | struct mansession * | s, | |
| const struct ast_datastore_info * | info, | |||
| const char * | uid | |||
| ) | [read] |
Find a datastore on a session.
| pointer | to the datastore if found | |
| NULL | if not found |
Definition at line 7043 of file manager.c.
References AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, mansession_session::datastores, ast_datastore::info, mansession::session, and ast_datastore::uid.
07044 { 07045 struct ast_datastore *datastore = NULL; 07046 07047 if (info == NULL) 07048 return NULL; 07049 07050 AST_LIST_TRAVERSE_SAFE_BEGIN(&s->session->datastores, datastore, entry) { 07051 if (datastore->info != info) { 07052 continue; 07053 } 07054 07055 if (uid == NULL) { 07056 /* matched by type only */ 07057 break; 07058 } 07059 07060 if ((datastore->uid != NULL) && !strcasecmp(uid, datastore->uid)) { 07061 /* Matched by type AND uid */ 07062 break; 07063 } 07064 } 07065 AST_LIST_TRAVERSE_SAFE_END; 07066 07067 return datastore; 07068 }
| int astman_datastore_remove | ( | struct mansession * | s, | |
| struct ast_datastore * | datastore | |||
| ) |
Remove a datastore from a session.
| 0 | success | |
| non-zero | failure |
Definition at line 7038 of file manager.c.
References AST_LIST_REMOVE, mansession_session::datastores, and mansession::session.
07039 { 07040 return AST_LIST_REMOVE(&s->session->datastores, datastore, entry) ? 0 : -1; 07041 }
| int astman_is_authed | ( | uint32_t | ident | ) |
Determinie if a manager session ident is authenticated.
Definition at line 5462 of file manager.c.
References ao2_unlock, mansession_session::authenticated, find_session(), and unref_mansession().
Referenced by http_post_callback(), and static_callback().
05463 { 05464 int authed; 05465 struct mansession_session *session; 05466 05467 if (!(session = find_session(ident, 0))) 05468 return 0; 05469 05470 authed = (session->authenticated != 0); 05471 05472 ao2_unlock(session); 05473 unref_mansession(session); 05474 05475 return authed; 05476 }
| 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 |
| 1 | if the session has the permission mask capabilities | |
| 0 | otherwise |
Definition at line 5478 of file manager.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_unlock, mansession_session::managerid, mansession_session::readperm, sessions, and unref_mansession().
05479 { 05480 int result = 0; 05481 struct mansession_session *session; 05482 struct ao2_iterator i; 05483 05484 if (ident == 0) { 05485 return 0; 05486 } 05487 05488 i = ao2_iterator_init(sessions, 0); 05489 while ((session = ao2_iterator_next(&i))) { 05490 ao2_lock(session); 05491 if ((session->managerid == ident) && (session->readperm & perm)) { 05492 result = 1; 05493 ao2_unlock(session); 05494 unref_mansession(session); 05495 break; 05496 } 05497 ao2_unlock(session); 05498 unref_mansession(session); 05499 } 05500 ao2_iterator_destroy(&i); 05501 return result; 05502 }
| 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 |
| 1 | if the session has the permission mask capabilities, otherwise 0 | |
| 0 | otherwise |
Definition at line 5504 of file manager.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_unlock, mansession_session::managerid, sessions, unref_mansession(), and mansession_session::writeperm.
Referenced by http_post_callback().
05505 { 05506 int result = 0; 05507 struct mansession_session *session; 05508 struct ao2_iterator i; 05509 05510 if (ident == 0) { 05511 return 0; 05512 } 05513 05514 i = ao2_iterator_init(sessions, 0); 05515 while ((session = ao2_iterator_next(&i))) { 05516 ao2_lock(session); 05517 if ((session->managerid == ident) && (session->writeperm & perm)) { 05518 result = 1; 05519 ao2_unlock(session); 05520 unref_mansession(session); 05521 break; 05522 } 05523 ao2_unlock(session); 05524 unref_mansession(session); 05525 } 05526 ao2_iterator_destroy(&i); 05527 return result; 05528 }
| static int auth_http_callback | ( | struct ast_tcptls_session_instance * | ser, | |
| enum ast_http_method | method, | |||
| enum output_format | format, | |||
| struct sockaddr_in * | remote_address, | |||
| const char * | uri, | |||
| struct ast_variable * | get_params, | |||
| struct ast_variable * | headers | |||
| ) | [static] |
Definition at line 6018 of file manager.c.
References ast_manager_user::a1_hash, ao2_lock, ao2_unlock, ARRAY_LEN, ast_apply_ha(), ast_copy_string(), ast_debug, ast_free, ast_get_http_method(), ast_http_auth(), ast_http_error(), AST_HTTP_GET, ast_http_get_post_vars(), AST_HTTP_HEAD, AST_HTTP_POST, ast_http_send(), ast_inet_ntoa(), AST_LIST_HEAD_INIT_NOLOCK, ast_log(), ast_malloc, ast_md5_hash(), ast_mutex_destroy, ast_mutex_init, ast_parse_digest(), ast_random(), AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_sockaddr_from_sin, ast_str_append(), ast_str_create(), ast_string_field_free_memory, ast_string_field_init, ast_strlen_zero(), ast_variables_destroy(), ast_verb, mansession_session::authenticated, build_mansession(), ast_http_digest::cnonce, mansession_session::datastores, ast_manager_user::displayconnects, errno, mansession_session::f, mansession::f, mansession_session::fd, mansession::fd, find_session_by_nonce(), FORMAT_HTML, FORMAT_XML, get_manager_by_name_locked(), global_realm, grab_last(), ast_manager_user::ha, message::hdrcount, message::headers, mansession_session::last_ev, mansession::lock, LOG_NOTICE, LOG_WARNING, mansession_session::managerid, ast_variable::name, mansession_session::nc, ast_http_digest::nc, mansession_session::needdestroy, ast_variable::next, ast_http_digest::nonce, mansession_session::noncetime, mansession_session::oldnonce, process_message(), process_output(), ast_http_digest::qop, mansession_session::readperm, ast_manager_user::readperm, ast_http_digest::response, mansession::session, session_destroy(), mansession_session::sessionstart, mansession_session::sessiontimeout, mansession_session::sin, ast_http_digest::uri, mansession_session::username, ast_manager_user::username, ast_http_digest::username, ast_variable::value, mansession_session::writeperm, ast_manager_user::writeperm, mansession_session::writetimeout, and ast_manager_user::writetimeout.
Referenced by auth_manager_http_callback(), auth_mxml_http_callback(), and auth_rawman_http_callback().
06024 { 06025 struct mansession_session *session = NULL; 06026 struct mansession s = { .session = NULL, .tcptls_session = ser }; 06027 struct ast_variable *v, *params = get_params; 06028 char template[] = "/tmp/ast-http-XXXXXX"; /* template for temporary file */ 06029 struct ast_str *http_header = NULL, *out = NULL; 06030 size_t result_size = 512; 06031 struct message m = { 0 }; 06032 unsigned int idx; 06033 size_t hdrlen; 06034 06035 time_t time_now = time(NULL); 06036 unsigned long nonce = 0, nc; 06037 struct ast_http_digest d = { NULL, }; 06038 struct ast_manager_user *user = NULL; 06039 int stale = 0; 06040 char resp_hash[256]=""; 06041 /* Cache for user data */ 06042 char u_username[80]; 06043 int u_readperm; 06044 int u_writeperm; 06045 int u_writetimeout; 06046 int u_displayconnects; 06047 struct ast_sockaddr addr; 06048 06049 if (method != AST_HTTP_GET && method != AST_HTTP_HEAD && method != AST_HTTP_POST) { 06050 ast_http_error(ser, 501, "Not Implemented", "Attempt to use unimplemented / unsupported method"); 06051 return -1; 06052 } 06053 06054 /* Find "Authorization: " header */ 06055 for (v = headers; v; v = v->next) { 06056 if (!strcasecmp(v->name, "Authorization")) { 06057 break; 06058 } 06059 } 06060 06061 if (!v || ast_strlen_zero(v->value)) { 06062 goto out_401; /* Authorization Header not present - send auth request */ 06063 } 06064 06065 /* Digest found - parse */ 06066 if (ast_string_field_init(&d, 128)) { 06067 ast_http_error(ser, 500, "Server Error", "Internal Server Error (out of memory)\n"); 06068 return -1; 06069 } 06070 06071 if (ast_parse_digest(v->value, &d, 0, 1)) { 06072 /* Error in Digest - send new one */ 06073 nonce = 0; 06074 goto out_401; 06075 } 06076 if (sscanf(d.nonce, "%30lx", &nonce) != 1) { 06077 ast_log(LOG_WARNING, "Received incorrect nonce in Digest <%s>\n", d.nonce); 06078 nonce = 0; 06079 goto out_401; 06080 } 06081 06082 AST_RWLIST_WRLOCK(&users); 06083 user = get_manager_by_name_locked(d.username); 06084 if(!user) { 06085 AST_RWLIST_UNLOCK(&users); 06086 ast_log(LOG_NOTICE, "%s tried to authenticate with nonexistent user '%s'\n", ast_inet_ntoa(remote_address->sin_addr), d.username); 06087 nonce = 0; 06088 goto out_401; 06089 } 06090 06091 ast_sockaddr_from_sin(&addr, remote_address); 06092 /* --- We have User for this auth, now check ACL */ 06093 if (user->ha && !ast_apply_ha(user->ha, &addr)) { 06094 AST_RWLIST_UNLOCK(&users); 06095 ast_log(LOG_NOTICE, "%s failed to pass IP ACL as '%s'\n", ast_inet_ntoa(remote_address->sin_addr), d.username); 06096 ast_http_error(ser, 403, "Permission denied", "Permission denied\n"); 06097 return -1; 06098 } 06099 06100 /* --- We have auth, so check it */ 06101 06102 /* compute the expected response to compare with what we received */ 06103 { 06104 char a2[256]; 06105 char a2_hash[256]; 06106 char resp[256]; 06107 06108 /* XXX Now request method are hardcoded in A2 */ 06109 snprintf(a2, sizeof(a2), "%s:%s", ast_get_http_method(method), d.uri); 06110 ast_md5_hash(a2_hash, a2); 06111 06112 if (d.qop) { 06113 /* RFC 2617 */ 06114 snprintf(resp, sizeof(resp), "%s:%08lx:%s:%s:auth:%s", user->a1_hash, nonce, d.nc, d.cnonce, a2_hash); 06115 } else { 06116 /* RFC 2069 */ 06117 snprintf(resp, sizeof(resp), "%s:%08lx:%s", user->a1_hash, nonce, a2_hash); 06118 } 06119 ast_md5_hash(resp_hash, resp); 06120 } 06121 06122 if (strncasecmp(d.response, resp_hash, strlen(resp_hash))) { 06123 /* Something was wrong, so give the client to try with a new challenge */ 06124 AST_RWLIST_UNLOCK(&users); 06125 nonce = 0; 06126 goto out_401; 06127 } 06128 06129 /* 06130 * User are pass Digest authentication. 06131 * Now, cache the user data and unlock user list. 06132 */ 06133 ast_copy_string(u_username, user->username, sizeof(u_username)); 06134 u_readperm = user->readperm; 06135 u_writeperm = user->writeperm; 06136 u_displayconnects = user->displayconnects; 06137 u_writetimeout = user->writetimeout; 06138 AST_RWLIST_UNLOCK(&users); 06139 06140 if (!(session = find_session_by_nonce(d.username, nonce, &stale))) { 06141 /* 06142 * Create new session. 06143 * While it is not in the list we don't need any locking 06144 */ 06145 if (!(session = build_mansession(*remote_address))) { 06146 ast_http_error(ser, 500, "Server Error", "Internal Server Error (out of memory)\n"); 06147 return -1; 06148 } 06149 ao2_lock(session); 06150 06151 ast_copy_string(session->username, u_username, sizeof(session->username)); 06152 session->managerid = nonce; 06153 session->last_ev = grab_last(); 06154 AST_LIST_HEAD_INIT_NOLOCK(&session->datastores); 06155 06156 session->readperm = u_readperm; 06157 session->writeperm = u_writeperm; 06158 session->writetimeout = u_writetimeout; 06159 06160 if (u_displayconnects) { 06161 ast_verb(2, "HTTP Manager '%s' logged in from %s\n", session->username, ast_inet_ntoa(session->sin.sin_addr)); 06162 } 06163 session->noncetime = session->sessionstart = time_now; 06164 session->authenticated = 1; 06165 } else if (stale) { 06166 /* 06167 * Session found, but nonce is stale. 06168 * 06169 * This could be because an old request (w/old nonce) arrived. 06170 * 06171 * This may be as the result of http proxy usage (separate delay or 06172 * multipath) or in a situation where a page was refreshed too quickly 06173 * (seen in Firefox). 06174 * 06175 * In this situation, we repeat the 401 auth with the current nonce 06176 * value. 06177 */ 06178 nonce = session->managerid; 06179 ao2_unlock(session); 06180 stale = 1; 06181 goto out_401; 06182 } else { 06183 sscanf(d.nc, "%30lx", &nc); 06184 if (session->nc >= nc || ((time_now - session->noncetime) > 62) ) { 06185 /* 06186 * Nonce time expired (> 2 minutes) or something wrong with nonce 06187 * counter. 06188 * 06189 * Create new nonce key and resend Digest auth request. Old nonce 06190 * is saved for stale checking... 06191 */ 06192 session->nc = 0; /* Reset nonce counter */ 06193 session->oldnonce = session->managerid; 06194 nonce = session->managerid = ast_random(); 06195 session->noncetime = time_now; 06196 ao2_unlock(session); 06197 stale = 1; 06198 goto out_401; 06199 } else { 06200 session->nc = nc; /* All OK, save nonce counter */ 06201 } 06202 } 06203 06204 06205 /* Reset session timeout. */ 06206 session->sessiontimeout = time(NULL) + (httptimeout > 5 ? httptimeout : 5); 06207 ao2_unlock(session); 06208 06209 ast_mutex_init(&s.lock); 06210 s.session = session; 06211 s.fd = mkstemp(template); /* create a temporary file for command output */ 06212 unlink(template); 06213 if (s.fd <= -1) { 06214 ast_http_error(ser, 500, "Server Error", "Internal Server Error (mkstemp failed)\n"); 06215 goto auth_callback_out; 06216 } 06217 s.f = fdopen(s.fd, "w+"); 06218 if (!s.f) { 06219 ast_log(LOG_WARNING, "HTTP Manager, fdopen failed: %s!\n", strerror(errno)); 06220 ast_http_error(ser, 500, "Server Error", "Internal Server Error (fdopen failed)\n"); 06221 close(s.fd); 06222 goto auth_callback_out; 06223 } 06224 06225 if (method == AST_HTTP_POST) { 06226 params = ast_http_get_post_vars(ser, headers); 06227 } 06228 06229 for (v = params; v && m.hdrcount < ARRAY_LEN(m.headers); v = v->next) { 06230 hdrlen = strlen(v->name) + strlen(v->value) + 3; 06231 m.headers[m.hdrcount] = ast_malloc(hdrlen); 06232 if (!m.headers[m.hdrcount]) { 06233 /* Allocation failure */ 06234 continue; 06235 } 06236 snprintf((char *) m.headers[m.hdrcount], hdrlen, "%s: %s", v->name, v->value); 06237 ast_verb(4, "HTTP Manager add header %s\n", m.headers[m.hdrcount]); 06238 ++m.hdrcount; 06239 } 06240 06241 if (process_message(&s, &m)) { 06242 if (u_displayconnects) { 06243 ast_verb(2, "HTTP Manager '%s' logged off from %s\n", session->username, ast_inet_ntoa(session->sin.sin_addr)); 06244 } 06245 06246 session->needdestroy = 1; 06247 } 06248 06249 /* Free request headers. */ 06250 for (idx = 0; idx < m.hdrcount; ++idx) { 06251 ast_free((void *) m.headers[idx]); 06252 m.headers[idx] = NULL; 06253 } 06254 06255 if (s.f) { 06256 result_size = ftell(s.f); /* Calculate approx. size of result */ 06257 } 06258 06259 http_header = ast_str_create(80); 06260 out = ast_str_create(result_size * 2 + 512); 06261 06262 if (http_header == NULL || out == NULL) { 06263 ast_http_error(ser, 500, "Server Error", "Internal Server Error (ast_str_create() out of memory)\n"); 06264 goto auth_callback_out; 06265 } 06266 06267 ast_str_append(&http_header, 0, "Content-type: text/%s\r\n", contenttype[format]); 06268 06269 if (format == FORMAT_XML) { 06270 ast_str_append(&out, 0, "<ajax-response>\n"); 06271 } else if (format == FORMAT_HTML) { 06272 ast_str_append(&out, 0, 06273 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n" 06274 "<html><head>\r\n" 06275 "<title>Asterisk™ Manager Interface</title>\r\n" 06276 "</head><body style=\"background-color: #ffffff;\">\r\n" 06277 "<form method=\"POST\">\r\n" 06278 "<table align=\"center\" style=\"background-color: #f1f1f1;\" width=\"500\">\r\n" 06279 "<tr><th colspan=\"2\" style=\"background-color: #f1f1ff;\"><h1>Manager Tester</h1></th></tr>\r\n" 06280 "<tr><th colspan=\"2\" style=\"background-color: #f1f1ff;\">Action: <input name=\"action\" /> Cmd: <input name=\"command\" /><br>" 06281 "<input type=\"submit\" value=\"Send request\" /></th></tr>\r\n"); 06282 } 06283 06284 process_output(&s, &out, params, format); 06285 06286 if (format == FORMAT_XML) { 06287 ast_str_append(&out, 0, "</ajax-response>\n"); 06288 } else if (format == FORMAT_HTML) { 06289 ast_str_append(&out, 0, "</table></form></body></html>\r\n"); 06290 } 06291 06292 ast_http_send(ser, method, 200, NULL, http_header, out, 0, 0); 06293 http_header = out = NULL; 06294 06295 auth_callback_out: 06296 ast_mutex_destroy(&s.lock); 06297 06298 /* Clear resources and unlock manager session */ 06299 if (method == AST_HTTP_POST && params) { 06300 ast_variables_destroy(params); 06301 } 06302 06303 ast_free(http_header); 06304 ast_free(out); 06305 06306 ao2_lock(session); 06307 if (session->f) { 06308 fclose(session->f); 06309 } 06310 session->f = NULL; 06311 session->fd = -1; 06312 ao2_unlock(session); 06313 06314 if (session->needdestroy) { 06315 ast_debug(1, "Need destroy, doing it now!\n"); 06316 session_destroy(session); 06317 } 06318 ast_string_field_free_memory(&d); 06319 return 0; 06320 06321 out_401: 06322 if (!nonce) { 06323 nonce = ast_random(); 06324 } 06325 06326 ast_http_auth(ser, global_realm, nonce, nonce, stale, NULL); 06327 ast_string_field_free_memory(&d); 06328 return 0; 06329 }
| static int auth_manager_http_callback | ( | struct ast_tcptls_session_instance * | ser, | |
| const struct ast_http_uri * | urih, | |||
| const char * | uri, | |||
| enum ast_http_method | method, | |||
| struct ast_variable * | get_params, | |||
| struct ast_variable * | headers | |||
| ) | [static] |
Definition at line 6390 of file manager.c.
References ast_sockaddr_from_sin, ast_sockaddr_to_sin, auth_http_callback(), FORMAT_HTML, and ast_tcptls_session_instance::remote_address.
06391 { 06392 int retval; 06393 struct sockaddr_in ser_remote_address_tmp; 06394 06395 ast_sockaddr_to_sin(&ser->remote_address, &ser_remote_address_tmp); 06396 retval = auth_http_callback(ser, method, FORMAT_HTML, &ser_remote_address_tmp, uri, get_params, headers); 06397 ast_sockaddr_from_sin(&ser->remote_address, &ser_remote_address_tmp); 06398 return retval; 06399 }
| static int auth_mxml_http_callback | ( | struct ast_tcptls_session_instance * | ser, | |
| const struct ast_http_uri * | urih, | |||
| const char * | uri, | |||
| enum ast_http_method | method, | |||
| struct ast_variable * | get_params, | |||
| struct ast_variable * | headers | |||
| ) | [static] |
Definition at line 6401 of file manager.c.
References ast_sockaddr_from_sin, ast_sockaddr_to_sin, auth_http_callback(), FORMAT_XML, and ast_tcptls_session_instance::remote_address.
06402 { 06403 int retval; 06404 struct sockaddr_in ser_remote_address_tmp; 06405 06406 ast_sockaddr_to_sin(&ser->remote_address, &ser_remote_address_tmp); 06407 retval = auth_http_callback(ser, method, FORMAT_XML, &ser_remote_address_tmp, uri, get_params, headers); 06408 ast_sockaddr_from_sin(&ser->remote_address, &ser_remote_address_tmp); 06409 return retval; 06410 }
| static int auth_rawman_http_callback | ( | struct ast_tcptls_session_instance * | ser, | |
| const struct ast_http_uri * | urih, | |||
| const char * | uri, | |||
| enum ast_http_method | method, | |||
| struct ast_variable * | get_params, | |||
| struct ast_variable * | headers | |||
| ) | [static] |
Definition at line 6412 of file manager.c.
References ast_sockaddr_from_sin, ast_sockaddr_to_sin, auth_http_callback(), FORMAT_RAW, and ast_tcptls_session_instance::remote_address.
06413 { 06414 int retval; 06415 struct sockaddr_in ser_remote_address_tmp; 06416 06417 ast_sockaddr_to_sin(&ser->remote_address, &ser_remote_address_tmp); 06418 retval = auth_http_callback(ser, method, FORMAT_RAW, &ser_remote_address_tmp, uri, get_params, headers); 06419 ast_sockaddr_from_sin(&ser->remote_address, &ser_remote_address_tmp); 06420 return retval; 06421 }
| static struct mansession_session* find_session | ( | uint32_t | ident, | |
| int | incinuse | |||
| ) | [static, read] |
locate an http session in the list. The search key (ident) is the value of the mansession_id cookie (0 is not valid and means a session on the AMI socket).
Definition at line 5403 of file manager.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_unlock, ast_atomic_fetchadd_int(), mansession_session::inuse, mansession_session::managerid, mansession_session::needdestroy, sessions, and unref_mansession().
Referenced by astman_is_authed(), and generic_http_callback().
05404 { 05405 struct mansession_session *session; 05406 struct ao2_iterator i; 05407 05408 if (ident == 0) { 05409 return NULL; 05410 } 05411 05412 i = ao2_iterator_init(sessions, 0); 05413 while ((session = ao2_iterator_next(&i))) { 05414 ao2_lock(session); 05415 if (session->managerid == ident && !session->needdestroy) { 05416 ast_atomic_fetchadd_int(&session->inuse, incinuse ? 1 : 0); 05417 break; 05418 } 05419 ao2_unlock(session); 05420 unref_mansession(session); 05421 } 05422 ao2_iterator_destroy(&i); 05423 05424 return session; 05425 }
| static struct mansession_session* find_session_by_nonce | ( | const char * | username, | |
| unsigned long | nonce, | |||
| int * | stale | |||
| ) | [static, read] |
locate an http session in the list. The search keys (nonce) and (username) is value from received "Authorization" http header. As well as in find_session() function, the value of the nonce can't be zero. (0 meansi, that the session used for AMI socket connection). Flag (stale) is set, if client used valid, but old, nonce value.
Definition at line 5436 of file manager.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_unlock, mansession_session::managerid, mansession_session::oldnonce, sessions, unref_mansession(), and mansession_session::username.
Referenced by auth_http_callback().
05437 { 05438 struct mansession_session *session; 05439 struct ao2_iterator i; 05440 05441 if (nonce == 0 || username == NULL || stale == NULL) { 05442 return NULL; 05443 } 05444 05445 i = ao2_iterator_init(sessions, 0); 05446 while ((session = ao2_iterator_next(&i))) { 05447 ao2_lock(session); 05448 if (!strcasecmp(session->username, username) && session->managerid == nonce) { 05449 *stale = 0; 05450 break; 05451 } else if (!strcasecmp(session->username, username) && session->oldnonce == nonce) { 05452 *stale = 1; 05453 break; 05454 } 05455 ao2_unlock(session); 05456 unref_mansession(session); 05457 } 05458 ao2_iterator_destroy(&i); 05459 return session; 05460 }
| static int generic_http_callback | ( | struct ast_tcptls_session_instance * | ser, | |
| enum ast_http_method | method, | |||
| enum output_format | format, | |||
| struct sockaddr_in * | remote_address, | |||
| const char * | uri, | |||
| struct ast_variable * | get_params, | |||
| struct ast_variable * | headers | |||
| ) | [static] |
Definition at line 5803 of file manager.c.
References ao2_lock, ao2_unlock, ARRAY_LEN, ast_debug, ast_free, ast_http_error(), AST_HTTP_GET, ast_http_get_cookies(), ast_http_get_post_vars(), AST_HTTP_HEAD, AST_HTTP_POST, ast_http_send(), ast_inet_ntoa(), AST_LIST_HEAD_INIT_NOLOCK, ast_log(), ast_malloc, ast_mutex_destroy, ast_mutex_init, AST_PTHREADT_NULL, ast_random(), ast_str_append(), ast_str_create(), ast_variables_destroy(), ast_verb, mansession_session::authenticated, build_mansession(), errno, mansession_session::f, mansession::f, mansession::fd, mansession_session::fd, find_session(), FORMAT_HTML, FORMAT_XML, grab_last(), message::hdrcount, message::headers, mansession_session::inuse, mansession::lock, LOG_WARNING, manager_displayconnects(), mansession_session::managerid, ast_variable::name, mansession_session::needdestroy, ast_variable::next, process_message(), process_output(), ROW_FMT, mansession_session::send_events, mansession::session, session_destroy(), mansession_session::sessiontimeout, mansession_session::sin, TEST_STRING, mansession_session::username, ast_variable::value, and mansession_session::waiting_thread.
Referenced by manager_http_callback(), mxml_http_callback(), and rawman_http_callback().
05809 { 05810 struct mansession s = { .session = NULL, .tcptls_session = ser }; 05811 struct mansession_session *session = NULL; 05812 uint32_t ident = 0; 05813 int blastaway = 0; 05814 struct ast_variable *v, *cookies, *params = get_params; 05815 char template[] = "/tmp/ast-http-XXXXXX"; /* template for temporary file */ 05816 struct ast_str *http_header = NULL, *out = NULL; 05817 struct message m = { 0 }; 05818 unsigned int idx; 05819 size_t hdrlen; 05820 05821 if (method != AST_HTTP_GET && method != AST_HTTP_HEAD && method != AST_HTTP_POST) { 05822 ast_http_error(ser, 501, "Not Implemented", "Attempt to use unimplemented / unsupported method"); 05823 return -1; 05824 } 05825 05826 cookies = ast_http_get_cookies(headers); 05827 for (v = cookies; v; v = v->next) { 05828 if (!strcasecmp(v->name, "mansession_id")) { 05829 sscanf(v->value, "%30x", &ident); 05830 break; 05831 } 05832 } 05833 if (cookies) { 05834 ast_variables_destroy(cookies); 05835 } 05836 05837 if (!(session = find_session(ident, 1))) { 05838 05839 /**/ 05840 /* Create new session. 05841 * While it is not in the list we don't need any locking 05842 */ 05843 if (!(session = build_mansession(*remote_address))) { 05844 ast_http_error(ser, 500, "Server Error", "Internal Server Error (out of memory)\n"); 05845 return -1; 05846 } 05847 ao2_lock(session); 05848 session->sin = *remote_address; 05849 session->fd = -1; 05850 session->waiting_thread = AST_PTHREADT_NULL; 05851 session->send_events = 0; 05852 session->inuse = 1; 05853 /*!\note There is approximately a 1 in 1.8E19 chance that the following 05854 * calculation will produce 0, which is an invalid ID, but due to the 05855 * properties of the rand() function (and the constantcy of s), that 05856 * won't happen twice in a row. 05857 */ 05858 while ((session->managerid = ast_random() ^ (unsigned long) session) == 0); 05859 session->last_ev = grab_last(); 05860 AST_LIST_HEAD_INIT_NOLOCK(&session->datastores); 05861 } 05862 ao2_unlock(session); 05863 05864 http_header = ast_str_create(128); 05865 out = ast_str_create(2048); 05866 05867 ast_mutex_init(&s.lock); 05868 05869 if (http_header == NULL || out == NULL) { 05870 ast_http_error(ser, 500, "Server Error", "Internal Server Error (ast_str_create() out of memory)\n"); 05871 goto generic_callback_out; 05872 } 05873 05874 s.session = session; 05875 s.fd = mkstemp(template); /* create a temporary file for command output */ 05876 unlink(template); 05877 if (s.fd <= -1) { 05878 ast_http_error(ser, 500, "Server Error", "Internal Server Error (mkstemp failed)\n"); 05879 goto generic_callback_out; 05880 } 05881 s.f = fdopen(s.fd, "w+"); 05882 if (!s.f) { 05883 ast_log(LOG_WARNING, "HTTP Manager, fdopen failed: %s!\n", strerror(errno)); 05884 ast_http_error(ser, 500, "Server Error", "Internal Server Error (fdopen failed)\n"); 05885 close(s.fd); 05886 goto generic_callback_out; 05887 } 05888 05889 if (method == AST_HTTP_POST) { 05890 params = ast_http_get_post_vars(ser, headers); 05891 } 05892 05893 for (v = params; v && m.hdrcount < ARRAY_LEN(m.headers); v = v->next) { 05894 hdrlen = strlen(v->name) + strlen(v->value) + 3; 05895 m.headers[m.hdrcount] = ast_malloc(hdrlen); 05896 if (!m.headers[m.hdrcount]) { 05897 /* Allocation failure */ 05898 continue; 05899 } 05900 snprintf((char *) m.headers[m.hdrcount], hdrlen, "%s: %s", v->name, v->value); 05901 ast_debug(1, "HTTP Manager add header %s\n", m.headers[m.hdrcount]); 05902 ++m.hdrcount; 05903 } 05904 05905 if (process_message(&s, &m)) { 05906 if (session->authenticated) { 05907 if (manager_displayconnects(session)) { 05908 ast_verb(2, "HTTP Manager '%s' logged off from %s\n", session->username, ast_inet_ntoa(session->sin.sin_addr)); 05909 } 05910 } else { 05911 if (displayconnects) { 05912 ast_verb(2, "HTTP Connect attempt from '%s' unable to authenticate\n", ast_inet_ntoa(session->sin.sin_addr)); 05913 } 05914 } 05915 session->needdestroy = 1; 05916 } 05917 05918 /* Free request headers. */ 05919 for (idx = 0; idx < m.hdrcount; ++idx) { 05920 ast_free((void *) m.headers[idx]); 05921 m.headers[idx] = NULL; 05922 } 05923 05924 ast_str_append(&http_header, 0, 05925 "Content-type: text/%s\r\n" 05926 "Cache-Control: no-cache;\r\n" 05927 "Set-Cookie: mansession_id=\"%08x\"; Version=1; Max-Age=%d\r\n" 05928 "Pragma: SuppressEvents\r\n", 05929 contenttype[format], 05930 session->managerid, httptimeout); 05931 05932 if (format == FORMAT_XML) { 05933 ast_str_append(&out, 0, "<ajax-response>\n"); 05934 } else if (format == FORMAT_HTML) { 05935 /* 05936 * When handling AMI-over-HTTP in HTML format, we provide a simple form for 05937 * debugging purposes. This HTML code should not be here, we 05938 * should read from some config file... 05939 */ 05940 05941 #define ROW_FMT "<tr><td colspan=\"2\" bgcolor=\"#f1f1ff\">%s</td></tr>\r\n" 05942 #define TEST_STRING \ 05943 "<form action=\"manager\" method=\"post\">\n\ 05944 Action: <select name=\"action\">\n\ 05945 <option value=\"\">-----></option>\n\ 05946 <option value=\"login\">login</option>\n\ 05947 <option value=\"command\">Command</option>\n\ 05948 <option value=\"waitevent\">waitevent</option>\n\ 05949 <option value=\"listcommands\">listcommands</option>\n\ 05950 </select>\n\ 05951 or <input name=\"action\"><br/>\n\ 05952 CLI Command <input name=\"command\"><br>\n\ 05953 user <input name=\"username\"> pass <input type=\"password\" name=\"secret\"><br>\n\ 05954 <input type=\"submit\">\n</form>\n" 05955 05956 ast_str_append(&out, 0, "<title>Asterisk™ Manager Interface</title>"); 05957 ast_str_append(&out, 0, "<body bgcolor=\"#ffffff\"><table align=center bgcolor=\"#f1f1f1\" width=\"500\">\r\n"); 05958 ast_str_append(&out, 0, ROW_FMT, "<h1>Manager Tester</h1>"); 05959 ast_str_append(&out, 0, ROW_FMT, TEST_STRING); 05960 } 05961 05962 process_output(&s, &out, params, format); 05963 05964 if (format == FORMAT_XML) { 05965 ast_str_append(&out, 0, "</ajax-response>\n"); 05966 } else if (format == FORMAT_HTML) { 05967 ast_str_append(&out, 0, "</table></body>\r\n"); 05968 } 05969 05970 ao2_lock(session); 05971 /* Reset HTTP timeout. If we're not authenticated, keep it extremely short */ 05972 session->sessiontimeout = time(NULL) + ((session->authenticated || httptimeout < 5) ? httptimeout : 5); 05973 05974 if (session->needdestroy) { 05975 if (session->inuse == 1) { 05976 ast_debug(1, "Need destroy, doing it now!\n"); 05977 blastaway = 1; 05978 } else { 05979 ast_debug(1, "Need destroy, but can't do it yet!\n"); 05980 if (session->waiting_thread != AST_PTHREADT_NULL) { 05981 pthread_kill(session->waiting_thread, SIGURG); 05982 } 05983 session->inuse--; 05984 } 05985 } else { 05986 session->inuse--; 05987 } 05988 ao2_unlock(session); 05989 05990 ast_http_send(ser, method, 200, NULL, http_header, out, 0, 0); 05991 http_header = out = NULL; 05992 05993 generic_callback_out: 05994 ast_mutex_destroy(&s.lock); 05995 05996 /* Clear resource */ 05997 05998 if (method == AST_HTTP_POST && params) { 05999 ast_variables_destroy(params); 06000 } 06001 if (http_header) { 06002 ast_free(http_header); 06003 } 06004 if (out) { 06005 ast_free(out); 06006 } 06007 06008 if (session && blastaway) { 06009 session_destroy(session); 06010 } else if (session && session->f) { 06011 fclose(session->f); 06012 session->f = NULL; 06013 } 06014 06015 return 0; 06016 }
| static char* handle_manager_show_settings | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
CLI command manager show settings.
Definition at line 6485 of file manager.c.
References ami_tls_cfg, ast_cli_args::argc, ast_cli(), AST_CLI_YESNO, ast_sockaddr_stringify(), block_sockets, ast_tls_config::certfile, ast_tls_config::cipher, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_tls_config::enabled, ast_cli_args::fd, FORMAT, FORMAT2, ast_tcptls_session_args::local_address, ast_tls_config::pvtfile, S_OR, and ast_cli_entry::usage.
06486 { 06487 switch (cmd) { 06488 case CLI_INIT: 06489 e->command = "manager show settings"; 06490 e->usage = 06491 "Usage: manager show settings\n" 06492 " Provides detailed list of the configuration of the Manager.\n"; 06493 return NULL; 06494 case CLI_GENERATE: 06495 return NULL; 06496 } 06497 #define FORMAT " %-25.25s %-15.15s\n" 06498 #define FORMAT2 " %-25.25s %-15d\n" 06499 if (a->argc != 3) { 06500 return CLI_SHOWUSAGE; 06501 } 06502 ast_cli(a->fd, "\nGlobal Settings:\n"); 06503 ast_cli(a->fd, "----------------\n"); 06504 ast_cli(a->fd, FORMAT, "Manager (AMI):", AST_CLI_YESNO(manager_enabled)); 06505 ast_cli(a->fd, FORMAT, "Web Manager (AMI/HTTP):", AST_CLI_YESNO(webmanager_enabled)); 06506 ast_cli(a->fd, FORMAT, "TCP Bindaddress:", manager_enabled != 0 ? ast_sockaddr_stringify(&ami_desc.local_address) : "Disabled"); 06507 ast_cli(a->fd, FORMAT2, "HTTP Timeout (minutes):", httptimeout); 06508 ast_cli(a->fd, FORMAT, "TLS Enable:", AST_CLI_YESNO(ami_tls_cfg.enabled)); 06509 ast_cli(a->fd, FORMAT, "TLS Bindaddress:", ami_tls_cfg.enabled != 0 ? ast_sockaddr_stringify(&amis_desc.local_address) : "Disabled"); 06510 ast_cli(a->fd, FORMAT, "TLS Certfile:", ami_tls_cfg.certfile); 06511 ast_cli(a->fd, FORMAT, "TLS Privatekey:", ami_tls_cfg.pvtfile); 06512 ast_cli(a->fd, FORMAT, "TLS Cipher:", ami_tls_cfg.cipher); 06513 ast_cli(a->fd, FORMAT, "Allow multiple login:", AST_CLI_YESNO(allowmultiplelogin)); 06514 ast_cli(a->fd, FORMAT, "Display connects:", AST_CLI_YESNO(displayconnects)); 06515 ast_cli(a->fd, FORMAT, "Timestamp events:", AST_CLI_YESNO(timestampevents)); 06516 ast_cli(a->fd, FORMAT, "Channel vars:", S_OR(manager_channelvars, "")); 06517 ast_cli(a->fd, FORMAT, "Debug:", AST_CLI_YESNO(manager_debug)); 06518 ast_cli(a->fd, FORMAT, "Block sockets:", AST_CLI_YESNO(block_sockets)); 06519 #undef FORMAT 06520 #undef FORMAT2 06521 06522 return CLI_SUCCESS; 06523 }
| int init_manager | ( | void | ) |
Called by Asterisk initialization.
Definition at line 7021 of file manager.c.
References __init_manager().
Referenced by main().
07022 { 07023 return __init_manager(0); 07024 }
| static void load_channelvars | ( | struct ast_variable * | var | ) | [static] |
Definition at line 6545 of file manager.c.
References ast_calloc, ast_free, AST_RWLIST_INSERT_TAIL, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strdup, ast_strdupa, free_channelvars(), manager_channel_variable::isfunc, manager_channel_variable::name, eventqent::next, and ast_variable::value.
Referenced by __init_manager().
06546 { 06547 struct manager_channel_variable *mcv; 06548 char *remaining = ast_strdupa(var->value); 06549 char *next; 06550 06551 ast_free(manager_channelvars); 06552 manager_channelvars = ast_strdup(var->value); 06553 06554 /* 06555 * XXX TODO: To allow dialplan functions to have more than one 06556 * parameter requires eliminating the '|' as a separator so we 06557 * could use AST_STANDARD_APP_ARGS() to separate items. 06558 */ 06559 free_channelvars(); 06560 AST_RWLIST_WRLOCK(&channelvars); 06561 while ((next = strsep(&remaining, ",|"))) { 06562 if (!(mcv = ast_calloc(1, sizeof(*mcv) + strlen(next) + 1))) { 06563 break; 06564 } 06565 strcpy(mcv->name, next); /* SAFE */ 06566 if (strchr(next, '(')) { 06567 mcv->isfunc = 1; 06568 } 06569 AST_RWLIST_INSERT_TAIL(&channelvars, mcv, entry); 06570 } 06571 AST_RWLIST_UNLOCK(&channelvars); 06572 }
| static int manager_http_callback | ( | struct ast_tcptls_session_instance * | ser, | |
| const struct ast_http_uri * | urih, | |||
| const char * | uri, | |||
| enum ast_http_method | method, | |||
| struct ast_variable * | get_params, | |||
| struct ast_variable * | headers | |||
| ) | [static] |
Definition at line 6331 of file manager.c.
References ast_sockaddr_from_sin, ast_sockaddr_to_sin, FORMAT_HTML, generic_http_callback(), and ast_tcptls_session_instance::remote_address.
06332 { 06333 int retval; 06334 struct sockaddr_in ser_remote_address_tmp; 06335 06336 ast_sockaddr_to_sin(&ser->remote_address, &ser_remote_address_tmp); 06337 retval = generic_http_callback(ser, method, FORMAT_HTML, &ser_remote_address_tmp, uri, get_params, headers); 06338 ast_sockaddr_from_sin(&ser->remote_address, &ser_remote_address_tmp); 06339 return retval; 06340 }
| static int mxml_http_callback | ( | struct ast_tcptls_session_instance * | ser, | |
| const struct ast_http_uri * | urih, | |||
| const char * | uri, | |||
| enum ast_http_method | method, | |||
| struct ast_variable * | get_params, | |||
| struct ast_variable * | headers | |||
| ) | [static] |
Definition at line 6342 of file manager.c.
References ast_sockaddr_from_sin, ast_sockaddr_to_sin, FORMAT_XML, generic_http_callback(), and ast_tcptls_session_instance::remote_address.
06343 { 06344 int retval; 06345 struct sockaddr_in ser_remote_address_tmp; 06346 06347 ast_sockaddr_to_sin(&ser->remote_address, &ser_remote_address_tmp); 06348 retval = generic_http_callback(ser, method, FORMAT_XML, &ser_remote_address_tmp, uri, get_params, headers); 06349 ast_sockaddr_from_sin(&ser->remote_address, &ser_remote_address_tmp); 06350 return retval; 06351 }
| static void process_output | ( | struct mansession * | s, | |
| struct ast_str ** | out, | |||
| struct ast_variable * | params, | |||
| enum output_format | format | |||
| ) | [static] |
Definition at line 5760 of file manager.c.
References ast_log(), ast_str_append(), errno, mansession::f, mansession::fd, FORMAT_HTML, FORMAT_XML, LOG_ERROR, LOG_WARNING, and xml_translate().
Referenced by auth_http_callback(), and generic_http_callback().
05761 { 05762 char *buf; 05763 size_t l; 05764 05765 if (!s->f) 05766 return; 05767 05768 /* Ensure buffer is NULL-terminated */ 05769 fprintf(s->f, "%c", 0); 05770 fflush(s->f); 05771 05772 if ((l = ftell(s->f)) > 0) { 05773 if (MAP_FAILED == (buf = mmap(NULL, l, PROT_READ | PROT_WRITE, MAP_PRIVATE, s->fd, 0))) { 05774 ast_log(LOG_WARNING, "mmap failed. Manager output was not processed\n"); 05775 } else { 05776 if (format == FORMAT_XML || format == FORMAT_HTML) { 05777 xml_translate(out, buf, params, format); 05778 } else { 05779 ast_str_append(out, 0, "%s", buf); 05780 } 05781 munmap(buf, l); 05782 } 05783 } else if (format == FORMAT_XML || format == FORMAT_HTML) { 05784 xml_translate(out, "", params, format); 05785 } 05786 05787 if (s->f) { 05788 if (fclose(s->f)) { 05789 ast_log(LOG_ERROR, "fclose() failed: %s\n", strerror(errno)); 05790 } 05791 s->f = NULL; 05792 s->fd = -1; 05793 } else if (s->fd != -1) { 05794 if (close(s->fd)) { 05795 ast_log(LOG_ERROR, "close() failed: %s\n", strerror(errno)); 05796 } 05797 s->fd = -1; 05798 } else { 05799 ast_log(LOG_ERROR, "process output attempted to close file/file descriptor on mansession without a valid file or file descriptor.\n"); 05800 } 05801 }
| static void purge_old_stuff | ( | void * | data | ) | [static] |
cleanup code called at each iteration of server_root, guaranteed to happen every 5 seconds at most
Definition at line 6456 of file manager.c.
References purge_events(), and purge_sessions().
06457 { 06458 purge_sessions(1); 06459 purge_events(); 06460 }
| static int rawman_http_callback | ( | struct ast_tcptls_session_instance * | ser, | |
| const struct ast_http_uri * | urih, | |||
| const char * | uri, | |||
| enum ast_http_method | method, | |||
| struct ast_variable * | get_params, | |||
| struct ast_variable * | headers | |||
| ) | [static] |
Definition at line 6353 of file manager.c.
References ast_sockaddr_from_sin, ast_sockaddr_to_sin, FORMAT_RAW, generic_http_callback(), and ast_tcptls_session_instance::remote_address.
06354 { 06355 int retval; 06356 struct sockaddr_in ser_remote_address_tmp; 06357 06358 ast_sockaddr_to_sin(&ser->remote_address, &ser_remote_address_tmp); 06359 retval = generic_http_callback(ser, method, FORMAT_RAW, &ser_remote_address_tmp, uri, get_params, headers); 06360 ast_sockaddr_from_sin(&ser->remote_address, &ser_remote_address_tmp); 06361 return retval; 06362 }
| int reload_manager | ( | void | ) |
Called by Asterisk module functions and the CLI command.
Definition at line 7026 of file manager.c.
References __init_manager().
Referenced by handle_manager_reload().
07027 { 07028 return __init_manager(1); 07029 }
| static int variable_count_cmp_fn | ( | void * | obj, | |
| void * | vstr, | |||
| int | flags | |||
| ) | [static] |
Definition at line 5604 of file manager.c.
References CMP_MATCH, CMP_STOP, str, and variable_count::varname.
Referenced by xml_translate().
05605 { 05606 /* Due to the simplicity of struct variable_count, it makes no difference 05607 * if you pass in objects or strings, the same operation applies. This is 05608 * due to the fact that the hash occurs on the first element, which means 05609 * the address of both the struct and the string are exactly the same. */ 05610 struct variable_count *vc = obj; 05611 char *str = vstr; 05612 return !strcmp(vc->varname, str) ? CMP_MATCH | CMP_STOP : 0; 05613 }
| static int variable_count_hash_fn | ( | const void * | vvc, | |
| const int | flags | |||
| ) | [static] |
Definition at line 5597 of file manager.c.
References ast_str_hash(), and variable_count::varname.
Referenced by xml_translate().
05598 { 05599 const struct variable_count *vc = vvc; 05600 05601 return ast_str_hash(vc->varname); 05602 }
| static void xml_copy_escape | ( | struct ast_str ** | out, | |
| const char * | src, | |||
| int | mode | |||
| ) | [static] |
Definition at line 5535 of file manager.c.
References ast_str_append().
Referenced by xml_translate().
05536 { 05537 /* store in a local buffer to avoid calling ast_str_append too often */ 05538 char buf[256]; 05539 char *dst = buf; 05540 int space = sizeof(buf); 05541 /* repeat until done and nothing to flush */ 05542 for ( ; *src || dst != buf ; src++) { 05543 if (*src == '\0' || space < 10) { /* flush */ 05544 *dst++ = '\0'; 05545 ast_str_append(out, 0, "%s", buf); 05546 dst = buf; 05547 space = sizeof(buf); 05548 if (*src == '\0') { 05549 break; 05550 } 05551 } 05552 05553 if ( (mode & 2) && !isalnum(*src)) { 05554 *dst++ = '_'; 05555 space--; 05556 continue; 05557 } 05558 switch (*src) { 05559 case '<': 05560 strcpy(dst, "<"); 05561 dst += 4; 05562 space -= 4; 05563 break; 05564 case '>': 05565 strcpy(dst, ">"); 05566 dst += 4; 05567 space -= 4; 05568 break; 05569 case '\"': 05570 strcpy(dst, """); 05571 dst += 6; 05572 space -= 6; 05573 break; 05574 case '\'': 05575 strcpy(dst, "'"); 05576 dst += 6; 05577 space -= 6; 05578 break; 05579 case '&': 05580 strcpy(dst, "&"); 05581 dst += 5; 05582 space -= 5; 05583 break; 05584 05585 default: 05586 *dst++ = mode ? tolower(*src) : *src; 05587 space--; 05588 } 05589 } 05590 }
| static void xml_translate | ( | struct ast_str ** | out, | |
| char * | in, | |||
| struct ast_variable * | get_vars, | |||
| enum output_format | format | |||
| ) | [static] |
Convert the input into XML or HTML. The input is supposed to be a sequence of lines of the form Name: value optionally followed by a blob of unformatted text. A blank line is a section separator. Basically, this is a mixture of the format of Manager Interface and CLI commands. The unformatted text is considered as a single value of a field named 'Opaque-data'.
At the moment the output format is the following (but it may change depending on future requirements so don't count too much on it when writing applications):
General: the unformatted text is used as a value of XML output: to be completed
* Each section is within <response type="object" id="xxx"> * where xxx is taken from ajaxdest variable or defaults to unknown * Each row is reported as an attribute Name="value" of an XML * entity named from the variable ajaxobjtype, default to "generic" *
HTML output: each Name-value pair is output as a single row of a two-column table. Sections (blank lines in the input) are separated by a
Definition at line 5643 of file manager.c.
References ao2_alloc, ao2_container_alloc, ao2_find, ao2_link, ao2_ref, ast_debug, ast_skip_blanks(), ast_str_append(), ast_strlen_zero(), ast_trim_blanks(), variable_count::count, FORMAT_XML, ast_variable::name, ast_variable::next, ast_variable::value, var, variable_count_cmp_fn(), variable_count_hash_fn(), variable_count::varname, and xml_copy_escape().
Referenced by process_output().
05644 { 05645 struct ast_variable *v; 05646 const char *dest = NULL; 05647 char *var, *val; 05648 const char *objtype = NULL; 05649 int in_data = 0; /* parsing data */ 05650 int inobj = 0; 05651 int xml = (format == FORMAT_XML); 05652 struct variable_count *vc = NULL; 05653 struct ao2_container *vco = NULL; 05654 05655 if (xml) { 05656 /* dest and objtype need only for XML format */ 05657 for (v = get_vars; v; v = v->next) { 05658 if (!strcasecmp(v->name, "ajaxdest")) { 05659 dest = v->value; 05660 } else if (!strcasecmp(v->name, "ajaxobjtype")) { 05661 objtype = v->value; 05662 } 05663 } 05664 if (ast_strlen_zero(dest)) { 05665 dest = "unknown"; 05666 } 05667 if (ast_strlen_zero(objtype)) { 05668 objtype = "generic"; 05669 } 05670 } 05671 05672 /* we want to stop when we find an empty line */ 05673 while (in && *in) { 05674 val = strsep(&in, "\r\n"); /* mark start and end of line */ 05675 if (in && *in == '\n') { /* remove trailing \n if any */ 05676 in++; 05677 } 05678 ast_trim_blanks(val); 05679 ast_debug(5, "inobj %d in_data %d line <%s>\n", inobj, in_data, val); 05680 if (ast_strlen_zero(val)) { 05681 /* empty line */ 05682 if (in_data) { 05683 /* close data in Opaque mode */ 05684 ast_str_append(out, 0, xml ? "'" : "</td></tr>\n"); 05685 in_data = 0; 05686 } 05687 05688 if (inobj) { 05689 /* close block */ 05690 ast_str_append(out, 0, xml ? " /></response>\n" : 05691 "<tr><td colspan=\"2\"><hr></td></tr>\r\n"); 05692 inobj = 0; 05693 ao2_ref(vco, -1); 05694 vco = NULL; 05695 } 05696 continue; 05697 } 05698 05699 if (!inobj) { 05700 /* start new block */ 05701 if (xml) { 05702 ast_str_append(out, 0, "<response type='object' id='%s'><%s", dest, objtype); 05703 } 05704 vco = ao2_container_alloc(37, variable_count_hash_fn, variable_count_cmp_fn); 05705 inobj = 1; 05706 } 05707 05708 if (in_data) { 05709 /* Process data field in Opaque mode. This is a 05710 * followup, so we re-add line feeds. */ 05711 ast_str_append(out, 0, xml ? "\n" : "<br>\n"); 05712 xml_copy_escape(out, val, 0); /* data field */ 05713 continue; 05714 } 05715 05716 /* We expect "Name: value" line here */ 05717 var = strsep(&val, ":"); 05718 if (val) { 05719 /* found the field name */ 05720 val = ast_skip_blanks(val); 05721 ast_trim_blanks(var); 05722 } else { 05723 /* field name not found, switch to opaque mode */ 05724 val = var; 05725 var = "Opaque-data"; 05726 in_data = 1; 05727 } 05728 05729 05730 ast_str_append(out, 0, xml ? " " : "<tr><td>"); 05731 if ((vc = ao2_find(vco, var, 0))) { 05732 vc->count++; 05733 } else { 05734 /* Create a new entry for this one */ 05735 vc = ao2_alloc(sizeof(*vc), NULL); 05736 vc->varname = var; 05737 vc->count = 1; 05738 ao2_link(vco, vc); 05739 } 05740 05741 xml_copy_escape(out, var, xml ? 1 | 2 : 0); /* data name */ 05742 if (vc->count > 1) { 05743 ast_str_append(out, 0, "-%d", vc->count); 05744 } 05745 ao2_ref(vc, -1); 05746 ast_str_append(out, 0, xml ? "='" : "</td><td>"); 05747 xml_copy_escape(out, val, 0); /* data field */ 05748 if (!in_data || !*in) { 05749 ast_str_append(out, 0, xml ? "'" : "</td></tr>\n"); 05750 } 05751 } 05752 05753 if (inobj) { 05754 ast_str_append(out, 0, xml ? " /></response>\n" : 05755 "<tr><td colspan=\"2\"><hr></td></tr>\r\n"); 05756 ao2_ref(vco, -1); 05757 } 05758 }
struct ast_http_uri amanageruri [static] |
struct ast_http_uri amanagerxmluri [static] |
struct ast_tcptls_session_args ami_desc [static] |
struct ast_tls_config ami_tls_cfg [static] |
Definition at line 6462 of file manager.c.
Referenced by __init_manager(), and handle_manager_show_settings().
struct ast_tcptls_session_args amis_desc [static] |
struct ast_http_uri arawmanuri [static] |
struct ast_cli_entry cli_manager[] [static] |
const char* const contenttype[] [static] |
{
[FORMAT_RAW] = "plain",
[FORMAT_HTML] = "html",
[FORMAT_XML] = "xml",
}
struct ast_http_uri manageruri [static] |
struct ast_http_uri managerxmluri [static] |
struct ast_http_uri rawmanuri [static] |
int registered = 0 [static] |
| const char* words[AST_MAX_CMD_LEN] |
Definition at line 921 of file manager.c.
Referenced by check_blacklist().
1.6.1