Asterisk - The Open Source Telephony Project GIT-master-5467495
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions | Variables
manager.c File Reference

The Asterisk Management Interface - AMI. More...

#include "asterisk.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/core_local.h"
#include "asterisk/lock.h"
#include "asterisk/cli.h"
#include "asterisk/app.h"
#include "asterisk/mwi.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/strings.h"
#include "asterisk/stringfields.h"
#include "asterisk/presencestate.h"
#include "asterisk/stasis_message_router.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/stasis_bridges.h"
#include "asterisk/test.h"
#include "asterisk/json.h"
#include "asterisk/bridge.h"
#include "asterisk/bridge_after.h"
#include "asterisk/features_config.h"
#include "asterisk/rtp_engine.h"
#include "asterisk/format_cache.h"
#include "asterisk/translate.h"
#include "asterisk/taskprocessor.h"
#include "asterisk/message.h"
Include dependency graph for manager.c:

Go to the source code of this file.

Data Structures

struct  actions
 list of actions registered More...
 
struct  ast_manager_user
 user descriptor, as read from the config file. More...
 
struct  event_filter_entry
 
struct  eventqent
 An AMI event message. More...
 
struct  fast_originate_helper
 helper function for originate More...
 
struct  manager_hooks
 list of hooks registered More...
 
struct  mansession
 In case you didn't read that giant block of text above the mansession_session struct, the mansession is named this solely to keep the API the same in Asterisk. This structure really represents data that is different from Manager action to Manager action. The mansession_session pointer contained within points to session-specific data. More...
 
struct  mansession_session::mansession_datastores
 
struct  mansession_session
 
struct  originate_permissions_entry
 
struct  permalias
 
struct  users
 list of users found in the config file More...
 
struct  variable_count
 

Macros

#define any_manager_listeners(sessions)    ((sessions && ao2_container_count(sessions)) || !AST_RWLIST_EMPTY(&manager_hooks))
 
#define ASTMAN_APPEND_BUF_INITSIZE   256
 initial allocated size for the astman_append_buf and astman_send_*_va
 
#define DEFAULT_REALM   "asterisk"
 
#define EVENT_FLAG_SHUTDOWN   -1
 Fake event class used to end sessions at shutdown.
 
#define FORMAT   " %-25.25s %-15.55s\n"
 
#define FORMAT2   " %-25.25s %-15d\n"
 
#define FORMAT3   " %-25.25s %s\n"
 
#define GET_HEADER_FIRST_MATCH   0
 
#define GET_HEADER_LAST_MATCH   1
 
#define GET_HEADER_SKIP_EMPTY   2
 
#define HSMC_FORMAT   " %-*.*s %-.*s\n"
 
#define HSMCONN_FORMAT1   " %-15.15s %-55.55s %-10.10s %-10.10s %-8.8s %-8.8s %-10.10s %-10.10s\n"
 
#define HSMCONN_FORMAT2   " %-15.15s %-55.55s %-10d %-10d %-8d %-8d %-10.10d %-10.10d\n"
 
#define MANAGER_EVENT_BUF_INITSIZE   256
 Initial size of the manager event message buffer.
 
#define manager_event_sessions(sessions, category, event, contents, ...)    __manager_event_sessions(sessions, category, event, 0, NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__, contents , ## __VA_ARGS__)
 
#define MAX_AUTH_PERM_STRING   150
 
#define MAX_BLACKLIST_CMD_LEN   2
 Descriptor for a manager session, either on the AMI socket or over HTTP.
 
#define MAX_VARS   128
 
#define MGR_SHOW_TERMINAL_WIDTH   80
 
#define MSG_MOREDATA   ((char *)astman_send_response)
 
#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=\"\">-----&gt;</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  add_filter_result { FILTER_SUCCESS = 0 , FILTER_ALLOC_FAILED , FILTER_COMPILE_FAIL , FILTER_FORMAT_ERROR }
 
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 , FAILURE_TEMPLATE
}
 
enum  event_filter_match_type {
  FILTER_MATCH_REGEX = 0 , FILTER_MATCH_EXACT , FILTER_MATCH_STARTS_WITH , FILTER_MATCH_ENDS_WITH ,
  FILTER_MATCH_CONTAINS , FILTER_MATCH_NONE
}
 
enum  mansession_message_parsing { MESSAGE_OKAY , MESSAGE_LINE_TOO_LONG }
 
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 int __init_manager (int reload, int by_external_config)
 
static int __manager_event_sessions (struct ao2_container *sessions, int category, const char *event, int chancount, struct ast_channel **chans, const char *file, int line, const char *func, const char *fmt,...)
 
static int __manager_event_sessions_va (struct ao2_container *sessions, int category, const char *event_name, int chancount, struct ast_channel **chans, const char *file, int line, const char *func, const char *fmt, va_list ap)
 
static void __reg_module (void)
 
static void __unreg_module (void)
 
static void acl_change_stasis_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static void acl_change_stasis_subscribe (void)
 
static void acl_change_stasis_unsubscribe (void)
 
static struct ast_aoc_decodedaction_aoc_de_message (struct mansession *s, const struct message *m)
 
static struct ast_aoc_decodedaction_aoc_s_message (struct mansession *s, const struct message *m)
 
static int action_aoc_s_submessage (struct mansession *s, const struct message *m, struct ast_aoc_decoded *decoded)
 
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_blind_transfer (struct mansession *s, const struct message *m)
 
static int action_cancel_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_coreshowchannelmap (struct mansession *s, const struct message *m)
 Manager command "CoreShowChannelMap" - Lists all channels connected to the specified channel.
 
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 int action_filter (struct mansession *s, const struct message *m)
 Manager command to add an event filter to a manager session.
 
static struct manager_actionaction_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_loggerrotate (struct mansession *s, const struct message *m)
 Manager command "LoggerRotate" - reloads and rotates the logger in the same manner as the CLI command 'logger rotate'.
 
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_presencestate (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 int action_waitevent_http (struct mansession *s, const struct message *m, const char *id, int timeout)
 
static int action_waitevent_tcp (struct mansession *s, const struct message *m, const char *id, int timeout)
 
static AO2_GLOBAL_OBJ_STATIC (event_docs)
 A container of event documentation nodes.
 
static AO2_GLOBAL_OBJ_STATIC (mgr_sessions)
 
 AO2_STRING_FIELD_SORT_FN (ast_xml_doc_item, name)
 
static int aocmessage_get_unit_entry (const struct message *m, struct ast_aoc_unit_entry *entry, unsigned int entry_num)
 
static int app_match (const char *app, const char *data, const char *search)
 
static int appdata_match (const char *app, const char *data, const char *search)
 
static void append_channel_vars (struct ast_str **pbuf, struct ast_channel *chan)
 
int ast_hook_send_action (struct manager_custom_hook *hook, const char *msg)
 access for hooks to send action messages to ami
 
static int ast_instring (const char *bigstr, const char *smallstr, const char delim)
 
int ast_manager_check_enabled (void)
 Check if AMI is enabled.
 
struct ast_manager_event_blobast_manager_event_blob_create (int event_flags, const char *manager_event, const char *extra_fields_fmt,...)
 Construct a ast_manager_event_blob.
 
struct stasis_message_routerast_manager_get_message_router (void)
 Get the stasis_message_router for AMI.
 
struct stasis_topicast_manager_get_topic (void)
 Get the Stasis Message Bus API topic for AMI.
 
int ast_manager_hangup_helper (struct mansession *s, const struct message *m, manager_hangup_handler_t hangup_handler, manager_hangup_cause_validator_t cause_validator)
 A manager helper function that hangs up a channel using a supplied channel type specific hangup function and cause code validator.
 
void ast_manager_publish_event (const char *type, int class_type, struct ast_json *obj)
 Publish an event to AMI.
 
int ast_manager_register2 (const char *action, int auth, int(*func)(struct mansession *s, const struct message *m), struct ast_module *module, 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)
 
struct ast_strast_manager_str_from_json_object (struct ast_json *blob, key_exclusion_cb exclusion_cb)
 Convert a JSON object into an AMI compatible string.
 
int ast_manager_unregister (const char *action)
 support functions to register/unregister AMI action handlers,
 
void ast_manager_unregister_hook (struct manager_custom_hook *hook)
 Delete a custom hook to be called when an event is fired.
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
int ast_str_append_event_header (struct ast_str **fields_string, const char *header, const char *value)
 append an event header to an ast string
 
 AST_THREADSTORAGE_CUSTOM_SCOPE (astman_append_buf, NULL, ast_free_ptr, static)
 thread local buffer for astman_append
 
 AST_THREADSTORAGE_CUSTOM_SCOPE (userevent_buf, NULL, ast_free_ptr, static)
 
int ast_webmanager_check_enabled (void)
 Check if AMI/HTTP is enabled.
 
void astman_append (struct mansession *s, const char *fmt,...)
 
static void astman_append_headers (struct message *m, const struct ast_variable *params)
 Append additional headers into the message structure from params.
 
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_datastoreastman_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.
 
static void astman_flush (struct mansession *s, struct ast_str *buf)
 
static void astman_free_headers (struct message *m)
 Free headers inside message structure, but not the message structure itself.
 
const char * astman_get_header (const struct message *m, char *var)
 Return the first matching variable from an array.
 
struct ast_variableastman_get_variables (const struct message *m)
 Get a linked list of the Variable: headers.
 
struct ast_variableastman_get_variables_order (const struct message *m, enum variable_orders order)
 Get a linked list of the Variable: headers with order specified.
 
int astman_is_authed (uint32_t ident)
 Determine if a manager session ident is authenticated.
 
void astman_live_dangerously (int new_live_dangerously)
 Enable/disable the inclusion of 'dangerous' configurations outside of the ast_config_AST_CONFIG_DIR.
 
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_error_va (struct mansession *s, const struct message *m, const char *fmt,...)
 Send error in manager transaction (with va_args support)
 
static void astman_send_list_complete (struct mansession *s, const struct message *m, const char *event_name, int count)
 
void astman_send_list_complete_end (struct mansession *s)
 End the list complete event.
 
void astman_send_list_complete_start (struct mansession *s, const struct message *m, const char *event_name, int count)
 Start the list complete event.
 
static struct ast_strastman_send_list_complete_start_common (struct mansession *s, const struct message *m, const char *event_name, int count)
 
void astman_send_listack (struct mansession *s, const struct message *m, char *msg, char *listflag)
 Send ack in manager transaction to begin a list.
 
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)
 send a response with an optional message, and terminate it with an empty line. m is used only to grab the 'ActionID' field.
 
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 async_goto_with_discard_bridge_after (struct ast_channel *chan, const char *context, const char *exten, int priority)
 
static int auth_http_callback (struct ast_tcptls_session_instance *ser, enum ast_http_method method, enum output_format format, const struct ast_sockaddr *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. Note that the EVENT_FLAG_ALL authority will always be returned.
 
static struct mansession_sessionbuild_mansession (const struct ast_sockaddr *addr, unsigned int needs_alert_pipe)
 Allocate manager session structure and add it to the list of sessions.
 
static int check_blacklist (const char *cmd)
 
static int check_manager_session_inuse (const char *name)
 
static void close_mansession_file (struct mansession *s)
 
static int coreshowchannelmap_add_connected_channels (struct ao2_container *channel_map, struct ast_channel_snapshot *channel_snapshot, struct ast_bridge_snapshot *bridge_snapshot)
 Recursive function to get all channels in a bridge. Follow local channels as well.
 
static int coreshowchannelmap_add_to_map (struct ao2_container *c, const char *s)
 Helper function to add a channel name to the vector.
 
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 int event_max_name_len_cb (void *obj, void *arg, void *data, int flags)
 
static struct eventqenteventqent_alloc (const char *event_name, int category)
 Allocate a manager event.
 
static void eventqent_destructor (void *obj)
 Destructor for manager event message.
 
static void * fast_originate (void *data)
 
static int file_in_modules_dir (const char *filename)
 Check if the given file path is in the modules dir or not.
 
static int filter_cmp_fn (void *obj, void *arg, void *data, int flags)
 
static struct mansession_sessionfind_session (uint32_t ident, int incinuse)
 
static struct mansession_sessionfind_session_by_nonce (const char *username, unsigned long nonce, int *stale)
 
static int function_amiclient (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 ${AMI_CLIENT()} Dialplan function - reads manager client data
 
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 void generate_status (struct mansession *s, struct ast_channel *chan, char **vars, int varc, int all_variables, char *id_text, int *count)
 
static int generic_http_callback (struct ast_tcptls_session_instance *ser, enum ast_http_method method, enum output_format format, const struct ast_sockaddr *remote_address, const char *uri, struct ast_variable *get_params, struct ast_variable *headers)
 
static int get_input (struct mansession *s, struct pollfd *pfds, char *output)
 
static struct ast_manager_userget_manager_by_name_locked (const char *name)
 
static int get_manager_sessions_cb (void *obj, void *arg, void *data, int flags)
 Get number of logged in sessions for a login name.
 
static int get_perm (const char *instr)
 
static char * handle_kickmanconn (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI command manager kick session.
 
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_event (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_manager_show_events (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
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 void handle_parse_error (struct mansession *s, struct message *m, char *error)
 
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 enum error_type handle_updates (struct mansession *s, const struct message *m, struct ast_config *cfg, const char *dfn)
 helper function for action_updateconfig
 
static int is_originate_app_permitted (const char *app, const char *data, int permission)
 
static int is_restricted_file (const char *filename)
 Check if a file is restricted or not.
 
static void json_escape (char *out, const char *in)
 
static void load_channelvars (struct ast_variable *var)
 
static void load_disabledevents (struct ast_variable *var)
 
static int load_module (void)
 
static void log_action (const struct message *m, const char *action)
 
static struct ast_variableman_do_variable_value (struct ast_variable *head, const char *hdr_val)
 
static enum add_filter_result manager_add_filter (const char *criteria, const char *filter_pattern, struct ao2_container *includefilters, struct ao2_container *excludefilters)
 Add an event filter to a manager session.
 
static void manager_default_msg_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static int manager_displayconnects (struct mansession_session *session)
 Get displayconnects config option.
 
static void manager_event_blob_dtor (void *obj)
 
static void manager_free_user (struct ast_manager_user *user)
 
static void manager_generic_msg_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
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 void manager_json_array_with_key (struct ast_json *obj, const char *key, size_t index, struct ast_str **res, key_exclusion_cb exclusion_cb)
 
static void manager_json_obj_with_key (struct ast_json *obj, const char *key, const char *parent_key, struct ast_str **res, key_exclusion_cb exclusion_cb)
 
static void manager_json_to_ast_str (struct ast_json *obj, const char *key, struct ast_str **res, key_exclusion_cb exclusion_cb)
 
static void manager_json_value_str_append (struct ast_json *value, const char *key, struct ast_str **res)
 
static int manager_modulecheck (struct mansession *s, const struct message *m)
 Manager function to check if module is loaded.
 
static int manager_moduleload (struct mansession *s, const struct message *m)
 
static void manager_set_defaults (void)
 
static void manager_shutdown (void)
 
static int manager_state_cb (const char *context, const char *exten, struct ast_state_cb_info *info, void *data)
 
static void manager_subscription_change_msg_cb (void *userdata, struct stasis_subscription *sub, struct stasis_message *message)
 Callback for subscription change messages.
 
static int manager_subscriptions_init (void)
 Initialize all Stasis Message Bus API topics and routers used by the various sub-components of AMI.
 
static int mansession_cmp_fn (void *obj, void *arg, int flags)
 
static enum ast_transport 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_eventdata (struct event_filter_entry *entry, const char *eventdata)
 Test eventdata against a filter entry.
 
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 void print_event_instance (struct ast_cli_args *a, struct ast_xml_doc_item *instance)
 
static int process_events (struct mansession *s)
 Send any pending events to the client listening on this socket.
 
static int process_message (struct mansession *s, const struct message *m)
 Process an AMI message, performing desired action. Return 0 on success, -1 on error that require the session to be destroyed.
 
static void process_output (struct mansession *s, struct ast_str **out, struct ast_variable *params, enum output_format format)
 
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 int purge_sessions (int n_max)
 remove at most n_max stale session from the list.
 
static int queue_match (const char *app, const char *data, const char *search)
 
static int queue_read_action_payload (struct ast_channel *chan, const unsigned char *payload, size_t payload_size, enum ast_frame_read_action action)
 Queue a given read action containing a payload onto a channel.
 
static int queue_sendtext (struct ast_channel *chan, const char *body)
 Queue a read action to send a text message.
 
static int queue_sendtext_data (struct ast_channel *chan, const char *body, const char *content_type)
 Queue a read action to send a text data message.
 
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 int reload_module (void)
 
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 void session_notify (struct mansession_session *session)
 
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 should_send_event (struct ao2_container *includefilters, struct ao2_container *excludefilters, struct eventqent *eqe)
 
static int strings_to_mask (const char *string)
 
static int subscribe_all (void)
 
static int unload_module (void)
 
static struct mansession_sessionunref_mansession (struct mansession_session *s)
 Unreference manager session object. If no more references, then go ahead and delete it.
 
static const char * user_authority_to_str (int authority, struct ast_str **res)
 Convert authority code to a list of options for a user. This will only display those authority codes that have an explicit match on authority.
 
static int variable_count_cmp_fn (void *obj, void *vstr, int flags)
 
static int variable_count_hash_fn (const void *vvc, const int flags)
 
static void xml_copy_escape (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'.
 
 STASIS_MESSAGE_TYPE_DEFN (ast_manager_get_generic_type)
 Define AMI message types.
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Asterisk Manager Interface" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload_module, .load_pri = AST_MODPRI_CORE, .requires = "extconfig,acl,http", }
 
static struct stasis_subscriptionacl_change_sub
 
static struct actions actions = AST_RWLIST_HEAD_INIT_VALUE
 
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 const struct ast_module_infoast_module_info = &__mod_info
 
static int authlimit
 
static int authtimeout
 
static int broken_events_action = 0
 
static struct ast_cli_entry cli_manager []
 
struct { 
 
   const char *   words [AST_MAX_CMD_LEN
 
command_blacklist [] 
 
static const char *const contenttype []
 
static int displayconnects = 1
 
static char global_realm [MAXHOSTNAMELEN]
 
static int httptimeout = 60
 
static int live_dangerously
 Set to true (non-zero) to globally allow all dangerous AMI actions to run.
 
static char * manager_channelvars
 
static int manager_debug = 0
 
static char * manager_disabledevents
 
static int manager_enabled = 0
 
static struct manager_hooks manager_hooks = AST_RWLIST_HEAD_INIT_VALUE
 
static struct stasis_topicmanager_topic
 A stasis_topic that all topics AMI cares about will be forwarded to.
 
static struct ast_custom_function managerclient_function
 description of AMI_CLIENT dialplan function
 
static struct ast_http_uri manageruri
 
static struct ast_http_uri managerxmluri
 
static char * match_type_names []
 
static struct originate_permissions_entry originate_app_permissions []
 
static const struct permalias perms []
 
static struct ast_http_uri rawmanuri
 
static struct stasis_forwardrtp_topic_forwarder
 The stasis_subscription for forwarding the RTP topic to the AMI topic.
 
static struct stasis_forwardsecurity_topic_forwarder
 The stasis_subscription for forwarding the Security topic to the AMI topic.
 
static struct stasis_message_routerstasis_router
 The stasis_message_router for all Stasis Message Bus API messages.
 
static int subscribed = 0
 
static int timestampevents
 
static int unauth_sessions = 0
 
static struct users users = AST_RWLIST_HEAD_INIT_VALUE
 
static int webmanager_enabled = 0
 
static int webregged = 0
 

Detailed Description

The Asterisk Management Interface - AMI.

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

OpenSSL http://www.openssl.org - for AMI/SSL

At the moment this file contains a number of functions, namely:

manager.conf

Definition in file manager.c.

Macro Definition Documentation

◆ FORMAT

#define FORMAT   " %-25.25s %-15.55s\n"

◆ FORMAT2

#define FORMAT2   " %-25.25s %-15d\n"

◆ FORMAT3

#define FORMAT3   " %-25.25s %s\n"

◆ HSMC_FORMAT

#define HSMC_FORMAT   " %-*.*s %-.*s\n"

◆ HSMCONN_FORMAT1

#define HSMCONN_FORMAT1   " %-15.15s %-55.55s %-10.10s %-10.10s %-8.8s %-8.8s %-10.10s %-10.10s\n"

◆ HSMCONN_FORMAT2

#define HSMCONN_FORMAT2   " %-15.15s %-55.55s %-10d %-10d %-8d %-8d %-10.10d %-10.10d\n"

◆ ROW_FMT

#define ROW_FMT   "<tr><td colspan=\"2\" bgcolor=\"#f1f1ff\">%s</td></tr>\r\n"

◆ TEST_STRING

#define TEST_STRING    "<form action=\"manager\" method=\"post\">\n\ Action: <select name=\"action\">\n\ <option value=\"\">-----&gt;</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"

Enumeration Type Documentation

◆ output_format

Enumerator
FORMAT_RAW 
FORMAT_HTML 
FORMAT_XML 

Definition at line 8003 of file manager.c.

8003 {
8004 FORMAT_RAW,
8006 FORMAT_XML,
8007};
@ FORMAT_RAW
Definition manager.c:8004
@ FORMAT_HTML
Definition manager.c:8005
@ FORMAT_XML
Definition manager.c:8006

Function Documentation

◆ __init_manager()

static int __init_manager ( int  reload,
int  by_external_config 
)
static

Definition at line 9758 of file manager.c.

9759{
9760 struct ast_config *cfg = NULL;
9761 const char *val;
9762 char *cat = NULL;
9763 int newhttptimeout = 60;
9764 struct ast_manager_user *user = NULL;
9765 struct ast_variable *var;
9766 struct ast_flags config_flags = { (reload && !by_external_config) ? CONFIG_FLAG_FILEUNCHANGED : 0 };
9767 char a1[337];
9768 char a1_hash[256];
9769 struct ast_sockaddr ami_desc_local_address_tmp;
9770 struct ast_sockaddr amis_desc_local_address_tmp;
9771 int tls_was_enabled = 0;
9772 int acl_subscription_flag = 0;
9773
9774 if (!reload) {
9775 struct ao2_container *sessions;
9776#ifdef AST_XML_DOCS
9777 struct ao2_container *temp_event_docs;
9778#endif
9779 int res;
9780
9782 if (res != 0) {
9783 return -1;
9784 }
9785 manager_topic = stasis_topic_create("manager:core");
9786 if (!manager_topic) {
9787 return -1;
9788 }
9789
9790 /* Register default actions */
9830
9831#ifdef TEST_FRAMEWORK
9832 test_suite_forwarder = stasis_forward_all(ast_test_suite_topic(), manager_topic);
9833#endif
9834
9838
9839#ifdef AST_XML_DOCS
9840 temp_event_docs = ast_xmldoc_build_documentation("managerEvent");
9841 if (temp_event_docs) {
9842 ao2_t_global_obj_replace_unref(event_docs, temp_event_docs, "Toss old event docs");
9843 ao2_t_ref(temp_event_docs, -1, "Remove creation ref - container holds only ref now");
9844 }
9845#endif
9846
9847 /* If you have a NULL hash fn, you only need a single bucket */
9849 if (!sessions) {
9850 return -1;
9851 }
9853 ao2_ref(sessions, -1);
9854
9855 /* Initialize all settings before first configuration load. */
9857 }
9858
9859 cfg = ast_config_load2("manager.conf", "manager", config_flags);
9860 if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
9861 return 0;
9862 } else if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) {
9863 ast_log(LOG_NOTICE, "Unable to open AMI configuration manager.conf, or configuration is invalid.\n");
9864 return 0;
9865 }
9866
9867 /* If this wasn't performed due to a forced reload (because those can be created by ACL change events, we need to unsubscribe to ACL change events. */
9868 if (!by_external_config) {
9870 }
9871
9872 if (reload) {
9873 /* Reset all settings before reloading configuration */
9874 tls_was_enabled = ami_tls_cfg.enabled;
9876 }
9877
9878 ast_sockaddr_parse(&ami_desc_local_address_tmp, "[::]", 0);
9879 ast_sockaddr_set_port(&ami_desc_local_address_tmp, DEFAULT_MANAGER_PORT);
9880
9881 for (var = ast_variable_browse(cfg, "general"); var; var = var->next) {
9882 val = var->value;
9883
9884 /* read tls config options while preventing unsupported options from being set */
9885 if (strcasecmp(var->name, "tlscafile")
9886 && strcasecmp(var->name, "tlscapath")
9887 && strcasecmp(var->name, "tlscadir")
9888 && strcasecmp(var->name, "tlsverifyclient")
9889 && strcasecmp(var->name, "tlsdontverifyserver")
9890 && strcasecmp(var->name, "tlsclientmethod")
9891 && strcasecmp(var->name, "sslclientmethod")
9893 continue;
9894 }
9895
9896 if (!strcasecmp(var->name, "enabled")) {
9898 } else if (!strcasecmp(var->name, "webenabled")) {
9900 } else if (!strcasecmp(var->name, "port")) {
9901 int bindport;
9902 if (ast_parse_arg(val, PARSE_UINT32|PARSE_IN_RANGE, &bindport, 1024, 65535)) {
9903 ast_log(LOG_WARNING, "Invalid port number '%s'\n", val);
9904 }
9905 ast_sockaddr_set_port(&ami_desc_local_address_tmp, bindport);
9906 } else if (!strcasecmp(var->name, "bindaddr")) {
9907 /* remember port if it has already been set */
9908 int setport = ast_sockaddr_port(&ami_desc_local_address_tmp);
9909
9911 ast_log(LOG_WARNING, "Invalid address '%s' specified, default '%s' will be used\n", val,
9912 ast_sockaddr_stringify_addr(&ami_desc_local_address_tmp));
9913 } else {
9914 ast_sockaddr_parse(&ami_desc_local_address_tmp, val, PARSE_PORT_IGNORE);
9915 }
9916
9917 if (setport) {
9918 ast_sockaddr_set_port(&ami_desc_local_address_tmp, setport);
9919 }
9920
9921 } else if (!strcasecmp(var->name, "brokeneventsaction")) {
9923 } else if (!strcasecmp(var->name, "allowmultiplelogin")) {
9925 } else if (!strcasecmp(var->name, "displayconnects")) {
9927 } else if (!strcasecmp(var->name, "timestampevents")) {
9929 } else if (!strcasecmp(var->name, "debug")) {
9931 } else if (!strcasecmp(var->name, "httptimeout")) {
9932 newhttptimeout = atoi(val);
9933 } else if (!strcasecmp(var->name, "authtimeout")) {
9934 int timeout = atoi(var->value);
9935
9936 if (timeout < 1) {
9937 ast_log(LOG_WARNING, "Invalid authtimeout value '%s', using default value\n", var->value);
9938 } else {
9939 authtimeout = timeout;
9940 }
9941 } else if (!strcasecmp(var->name, "authlimit")) {
9942 int limit = atoi(var->value);
9943
9944 if (limit < 1) {
9945 ast_log(LOG_WARNING, "Invalid authlimit value '%s', using default value\n", var->value);
9946 } else {
9947 authlimit = limit;
9948 }
9949 } else if (!strcasecmp(var->name, "channelvars")) {
9951 } else if (!strcasecmp(var->name, "disabledevents")) {
9953 } else {
9954 ast_log(LOG_NOTICE, "Invalid keyword <%s> = <%s> in manager.conf [general]\n",
9955 var->name, val);
9956 }
9957 }
9958
9959 if (manager_enabled && !subscribed) {
9960 if (subscribe_all() != 0) {
9961 ast_log(LOG_ERROR, "Manager subscription error\n");
9962 return -1;
9963 }
9964 }
9965
9966 ast_sockaddr_copy(&amis_desc_local_address_tmp, &amis_desc.local_address);
9967
9968 /* if the amis address has not been set, default is the same as non secure ami */
9969 if (ast_sockaddr_isnull(&amis_desc_local_address_tmp)) {
9970 ast_sockaddr_copy(&amis_desc_local_address_tmp, &ami_desc_local_address_tmp);
9971 }
9972
9973 /* if the amis address was not set, it will have non-secure ami port set; if
9974 amis address was set, we need to check that a port was set or not, if not
9975 use the default tls port */
9976 if (ast_sockaddr_port(&amis_desc_local_address_tmp) == 0 ||
9977 (ast_sockaddr_port(&ami_desc_local_address_tmp) == ast_sockaddr_port(&amis_desc_local_address_tmp))) {
9978
9979 ast_sockaddr_set_port(&amis_desc_local_address_tmp, DEFAULT_MANAGER_TLS_PORT);
9980 }
9981
9982 if (manager_enabled) {
9983 ast_sockaddr_copy(&ami_desc.local_address, &ami_desc_local_address_tmp);
9984 ast_sockaddr_copy(&amis_desc.local_address, &amis_desc_local_address_tmp);
9985 }
9986
9988
9989 while ((cat = ast_category_browse(cfg, cat))) {
9990 struct ast_acl_list *oldacl;
9991
9992 if (!strcasecmp(cat, "general")) {
9993 continue;
9994 }
9995
9996 /* Look for an existing entry, if none found - create one and add it to the list */
9997 if (!(user = get_manager_by_name_locked(cat))) {
9998 if (!(user = ast_calloc(1, sizeof(*user)))) {
9999 break;
10000 }
10001 /* Copy name over */
10002 ast_copy_string(user->username, cat, sizeof(user->username));
10003
10004 user->acl = NULL;
10005 user->readperm = 0;
10006 user->writeperm = 0;
10007 /* Default displayconnect from [general] */
10008 user->displayconnects = displayconnects;
10009 /* Default allowmultiplelogin from [general] */
10010 user->allowmultiplelogin = allowmultiplelogin;
10011 user->writetimeout = 100;
10014 if (!user->includefilters || !user->excludefilters) {
10016 break;
10017 }
10018
10019 /* Insert into list */
10021 } else {
10022 ao2_t_callback(user->includefilters, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL, "unlink all include filters");
10023 ao2_t_callback(user->excludefilters, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL, "unlink all exclude filters");
10024 }
10025
10026 /* Make sure we keep this user and don't destroy it during cleanup */
10027 user->keep = 1;
10028 oldacl = user->acl;
10029 user->acl = NULL;
10030 ast_variables_destroy(user->chanvars);
10031
10032 var = ast_variable_browse(cfg, cat);
10033 for (; var; var = var->next) {
10034 if (!strcasecmp(var->name, "secret")) {
10035 ast_free(user->secret);
10036 user->secret = ast_strdup(var->value);
10037 } else if (!strcasecmp(var->name, "deny") ||
10038 !strcasecmp(var->name, "permit") ||
10039 !strcasecmp(var->name, "acl")) {
10040 int acl_error = 0;
10041
10042 ast_append_acl(var->name, var->value, &user->acl, &acl_error, &acl_subscription_flag);
10043 if (acl_error) {
10044 ast_log(LOG_ERROR, "Invalid ACL '%s' for manager user '%s' on line %d. Deleting user\n",
10045 var->value, user->username, var->lineno);
10046 user->keep = 0;
10047 }
10048 } else if (!strcasecmp(var->name, "read") ) {
10049 user->readperm = get_perm(var->value);
10050 } else if (!strcasecmp(var->name, "write") ) {
10051 user->writeperm = get_perm(var->value);
10052 } else if (!strcasecmp(var->name, "displayconnects") ) {
10053 user->displayconnects = ast_true(var->value);
10054 } else if (!strcasecmp(var->name, "allowmultiplelogin") ) {
10055 user->allowmultiplelogin = ast_true(var->value);
10056 } else if (!strcasecmp(var->name, "writetimeout")) {
10057 int value = atoi(var->value);
10058 if (value < 100) {
10059 ast_log(LOG_WARNING, "Invalid writetimeout value '%s' at line %d\n", var->value, var->lineno);
10060 } else {
10061 user->writetimeout = value;
10062 }
10063 } else if (!strcasecmp(var->name, "setvar")) {
10064 struct ast_variable *tmpvar;
10065 char varbuf[256];
10066 char *varval;
10067 char *varname;
10068
10069 ast_copy_string(varbuf, var->value, sizeof(varbuf));
10070 varname = varbuf;
10071
10072 if ((varval = strchr(varname,'='))) {
10073 *varval++ = '\0';
10074 if ((tmpvar = ast_variable_new(varname, varval, ""))) {
10075 tmpvar->next = user->chanvars;
10076 user->chanvars = tmpvar;
10077 }
10078 }
10079 } else if (ast_begins_with(var->name, "eventfilter")) {
10080 const char *value = var->value;
10081 manager_add_filter(var->name, value, user->includefilters, user->excludefilters);
10082 } else {
10083 ast_debug(1, "%s is an unknown option.\n", var->name);
10084 }
10085 }
10086
10087 oldacl = ast_free_acl_list(oldacl);
10088 }
10089 ast_config_destroy(cfg);
10090
10091 /* Check the flag for named ACL event subscription and if we need to, register a subscription. */
10092 if (acl_subscription_flag && !by_external_config) {
10094 }
10095
10096 /* Perform cleanup - essentially prune out old users that no longer exist */
10098 if (user->keep) { /* valid record. clear flag for the next round */
10099 user->keep = 0;
10100
10101 /* Calculate A1 for Digest auth */
10102 snprintf(a1, sizeof(a1), "%s:%s:%s", user->username, global_realm, user->secret);
10103 ast_md5_hash(a1_hash,a1);
10104 ast_free(user->a1_hash);
10105 user->a1_hash = ast_strdup(a1_hash);
10106 continue;
10107 }
10108 /* We do not need to keep this user so take them out of the list */
10110 ast_debug(4, "Pruning user '%s'\n", user->username);
10112 }
10114
10116
10118 if (!webregged) {
10122
10126 webregged = 1;
10127 }
10128 } else {
10129 if (webregged) {
10133
10137 webregged = 0;
10138 }
10139 }
10140
10141 if (newhttptimeout > 0) {
10142 httptimeout = newhttptimeout;
10143 }
10144
10146 if (tls_was_enabled && !ami_tls_cfg.enabled) {
10148 } else if (ast_ssl_setup(amis_desc.tls_cfg)) {
10150 }
10151
10152 return 0;
10153}
void ast_append_acl(const char *sense, const char *stuff, struct ast_acl_list **path, int *error, int *named_acl_flag)
Add a rule to an ACL struct.
Definition acl.c:429
struct ast_acl_list * ast_free_acl_list(struct ast_acl_list *acl)
Free a list of ACLs.
Definition acl.c:233
#define var
Definition ast_expr2f.c:605
#define ast_free(a)
Definition astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
#define ast_calloc(num, len)
A wrapper for calloc()
Definition astmm.h:202
#define ast_log
Definition astobj2.c:42
#define ao2_t_ref(o, delta, tag)
Definition astobj2.h:460
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition astobj2.h:363
#define ao2_global_obj_replace_unref(holder, obj)
Replace an ao2 object in the global holder, throwing away any old object.
Definition astobj2.h:901
#define ao2_t_global_obj_replace_unref(holder, obj, tag)
Definition astobj2.h:904
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459
@ OBJ_NODATA
Definition astobj2.h:1044
@ OBJ_MULTIPLE
Definition astobj2.h:1049
@ OBJ_UNLINK
Definition astobj2.h:1039
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
Definition astobj2.h:1327
#define ao2_t_callback(c, flags, cb_fn, arg, tag)
Definition astobj2.h:1696
static struct unistimsession * sessions
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition cli.h:265
static int action_setvar(struct mansession *s, const struct message *m)
Definition manager.c:3596
static int action_createconfig(struct mansession *s, const struct message *m)
Definition manager.c:3044
static int manager_state_cb(const char *context, const char *exten, struct ast_state_cb_info *info, void *data)
Definition manager.c:7812
static int action_loggerrotate(struct mansession *s, const struct message *m)
Manager command "LoggerRotate" - reloads and rotates the logger in the same manner as the CLI command...
Definition manager.c:6892
static struct ast_manager_user * get_manager_by_name_locked(const char *name)
Definition manager.c:1019
static void acl_change_stasis_subscribe(void)
Definition manager.c:221
static int manager_enabled
Definition manager.c:154
static int action_sendtext(struct mansession *s, const struct message *m)
Definition manager.c:3952
static int action_mailboxcount(struct mansession *s, const struct message *m)
Definition manager.c:5487
static int action_getconfigjson(struct mansession *s, const struct message *m)
Definition manager.c:2596
static int action_listcategories(struct mansession *s, const struct message *m)
Definition manager.c:2520
static int action_hangup(struct mansession *s, const struct message *m)
Definition manager.c:3590
static int action_listcommands(struct mansession *s, const struct message *m)
Definition manager.c:3334
static int action_atxfer(struct mansession *s, const struct message *m)
Definition manager.c:4192
static int action_timeout(struct mansession *s, const struct message *m)
Definition manager.c:5581
static int action_coresettings(struct mansession *s, const struct message *m)
Show PBX core settings information.
Definition manager.c:6525
static int mansession_cmp_fn(void *obj, void *arg, int flags)
Definition manager.c:976
static int displayconnects
Definition manager.c:149
static int action_filter(struct mansession *s, const struct message *m)
Manager command to add an event filter to a manager session.
Definition manager.c:5733
static int manager_debug
Definition manager.c:157
static int action_mailboxstatus(struct mansession *s, const struct message *m)
Definition manager.c:5470
static int action_login(struct mansession *s, const struct message *m)
Definition manager.c:3403
static int action_getvar(struct mansession *s, const struct message *m)
Definition manager.c:3629
static int action_blind_transfer(struct mansession *s, const struct message *m)
Definition manager.c:4146
static int action_extensionstate(struct mansession *s, const struct message *m)
Definition manager.c:5508
static int action_getconfig(struct mansession *s, const struct message *m)
Definition manager.c:2448
static enum add_filter_result manager_add_filter(const char *criteria, const char *filter_pattern, struct ao2_container *includefilters, struct ao2_container *excludefilters)
Add an event filter to a manager session.
Definition manager.c:5800
static int action_logoff(struct mansession *s, const struct message *m)
Definition manager.c:3397
static int action_updateconfig(struct mansession *s, const struct message *m)
Definition manager.c:2953
static int manager_moduleload(struct mansession *s, const struct message *m)
Definition manager.c:6969
static void acl_change_stasis_unsubscribe(void)
Definition manager.c:231
static int action_reload(struct mansession *s, const struct message *m)
Send a reload event.
Definition manager.c:6611
static int authlimit
Definition manager.c:159
static int action_aocmessage(struct mansession *s, const struct message *m)
Definition manager.c:4982
static int action_events(struct mansession *s, const struct message *m)
Definition manager.c:3353
static int action_redirect(struct mansession *s, const struct message *m)
action_redirect: The redirect manager command
Definition manager.c:4001
static int action_presencestate(struct mansession *s, const struct message *m)
Definition manager.c:5538
static int allowmultiplelogin
Definition manager.c:150
static int action_cancel_atxfer(struct mansession *s, const struct message *m)
Definition manager.c:4246
static char global_realm[MAXHOSTNAMELEN]
Definition manager.c:164
static int action_originate(struct mansession *s, const struct message *m)
Definition manager.c:5275
static int action_userevent(struct mansession *s, const struct message *m)
Definition manager.c:6504
static int action_command(struct mansession *s, const struct message *m)
Manager command "command" - execute CLI command.
Definition manager.c:4323
static int broken_events_action
Definition manager.c:153
static int timestampevents
Definition manager.c:151
static int subscribed
Definition manager.c:155
static int authtimeout
Definition manager.c:158
static int manager_modulecheck(struct mansession *s, const struct message *m)
Manager function to check if module is loaded.
Definition manager.c:6904
static int webmanager_enabled
Definition manager.c:156
static int action_status(struct mansession *s, const struct message *m)
Manager "status" command to show channels.
Definition manager.c:3796
static int get_perm(const char *instr)
Definition manager.c:813
static int action_coreshowchannels(struct mansession *s, const struct message *m)
Manager command "CoreShowChannels" - List currently defined channels and some information about them.
Definition manager.c:6643
static int action_corestatus(struct mansession *s, const struct message *m)
Show PBX core status information.
Definition manager.c:6569
static int action_challenge(struct mansession *s, const struct message *m)
Definition manager.c:3451
static struct stasis_topic * manager_topic
A stasis_topic that all topics AMI cares about will be forwarded to.
Definition manager.c:170
static int action_waitevent(struct mansession *s, const struct message *m)
Definition manager.c:3306
static int action_coreshowchannelmap(struct mansession *s, const struct message *m)
Manager command "CoreShowChannelMap" - Lists all channels connected to the specified channel.
Definition manager.c:6811
static int action_ping(struct mansession *s, const struct message *m)
Definition manager.c:2376
static int httptimeout
Definition manager.c:152
void ast_http_uri_unlink(struct ast_http_uri *urihandler)
Unregister a URI handler.
Definition http.c:779
int ast_http_uri_link(struct ast_http_uri *urihandler)
Register a URI handler.
Definition http.c:747
@ CONFIG_FLAG_FILEUNCHANGED
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
Definition extconf.c:3324
#define ast_variable_new(name, value, filename)
#define CONFIG_STATUS_FILEUNCHANGED
#define CONFIG_STATUS_FILEINVALID
int ast_parse_arg(const char *arg, enum ast_parse_flags flags, void *p_result,...)
The argument parsing routine.
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition extconf.c:1287
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition extconf.c:1260
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Definition extconf.c:1213
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
#define LOG_NOTICE
#define LOG_WARNING
#define AST_RWLIST_REMOVE_CURRENT
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition linkedlists.h:52
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
#define AST_RWLIST_TRAVERSE_SAFE_END
#define AST_RWLIST_INSERT_TAIL
static struct ast_tls_config ami_tls_cfg
Definition manager.c:9196
static struct ast_tcptls_session_args ami_desc
Definition manager.c:9197
static struct ast_http_uri managerxmluri
Definition manager.c:9037
static struct ast_tcptls_session_args amis_desc
Definition manager.c:9208
static struct ast_custom_function managerclient_function
description of AMI_CLIENT dialplan function
Definition manager.c:9170
static void load_channelvars(struct ast_variable *var)
Definition manager.c:9494
static struct ast_http_uri manageruri
Definition manager.c:9029
static void manager_set_defaults(void)
Definition manager.c:9730
static struct ast_http_uri arawmanuri
Definition manager.c:9080
static struct ast_http_uri rawmanuri
Definition manager.c:9021
static struct ast_cli_entry cli_manager[]
Definition manager.c:9472
static void manager_free_user(struct ast_manager_user *user)
Definition manager.c:9527
static struct ast_http_uri amanageruri
Definition manager.c:9089
static int webregged
Definition manager.c:9176
static int subscribe_all(void)
Definition manager.c:9700
static struct ast_http_uri amanagerxmluri
Definition manager.c:9098
static void load_disabledevents(struct ast_variable *var)
Definition manager.c:9517
#define EVENT_FLAG_REPORTING
Definition manager.h:84
#define ast_manager_register_xml_core(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
Definition manager.h:204
#define EVENT_FLAG_CONFIG
Definition manager.h:82
#define EVENT_FLAG_SYSTEM
Definition manager.h:75
struct stasis_message_type * ast_manager_get_generic_type(void)
Get the stasis_message_type for generic messages.
#define DEFAULT_MANAGER_PORT
Definition manager.h:58
#define DEFAULT_MANAGER_TLS_PORT
Definition manager.h:59
#define EVENT_FLAG_CALL
Definition manager.h:76
#define EVENT_FLAG_COMMAND
Definition manager.h:79
#define EVENT_FLAG_USER
Definition manager.h:81
#define EVENT_FLAG_AOC
Definition manager.h:91
#define EVENT_FLAG_ORIGINATE
Definition manager.h:87
#define ast_sockaddr_port(addr)
Get the port number of a socket address.
Definition netsock2.h:517
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
Definition netsock2.h:167
int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
Parse an IPv4 or IPv6 address string.
Definition netsock2.c:230
static int ast_sockaddr_isnull(const struct ast_sockaddr *addr)
Checks if the ast_sockaddr is null. "null" in this sense essentially means uninitialized,...
Definition netsock2.h:127
#define ast_sockaddr_set_port(addr, port)
Sets the port number of a socket address.
Definition netsock2.h:532
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
Definition netsock2.h:286
int __ast_custom_function_register(struct ast_custom_function *acf, struct ast_module *mod)
Register a custom function.
int ast_extension_state_add(const char *context, const char *exten, ast_state_cb_type change_cb, void *data)
Add watcher for extension states.
static int reload(void)
#define NULL
Definition resample.c:96
struct stasis_topic * stasis_topic_create(const char *name)
Create a new topic.
Definition stasis.c:684
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
Definition stasis.h:1524
struct stasis_forward * stasis_forward_all(struct stasis_topic *from_topic, struct stasis_topic *to_topic)
Create a subscription which forwards all messages from one topic to another.
Definition stasis.c:1656
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition utils.c:2233
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition strings.h:425
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
Checks whether a string begins with another.
Definition strings.h:97
Generic container type.
Wrapper for an ast_acl linked list.
Definition acl.h:76
Structure used to handle boolean flags.
Definition utils.h:220
user descriptor, as read from the config file.
Definition manager.c:333
Socket address structure.
Definition netsock2.h:97
struct ast_sockaddr local_address
Definition tcptls.h:131
const char * name
Definition tcptls.h:143
struct ast_tls_config * tls_cfg
Definition tcptls.h:135
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
structure to hold users read from phoneprov_users.conf
list of users found in the config file
int value
Definition syslog.c:37
void ast_tcptls_server_stop(struct ast_tcptls_session_args *desc)
Shutdown a running server if there is one.
Definition tcptls.c:948
int ast_ssl_setup(struct ast_tls_config *cfg)
Set up an SSL server.
Definition tcptls.c:587
void ast_tcptls_server_start(struct ast_tcptls_session_args *desc)
This is a generic (re)start routine for a TCP server, which does the socket/bind/listen and starts a ...
Definition tcptls.c:783
int ast_tls_read_conf(struct ast_tls_config *tls_cfg, struct ast_tcptls_session_args *tls_desc, const char *varname, const char *value)
Used to parse conf files containing tls/ssl options.
Definition tcptls.c:974
#define ARRAY_LEN(a)
Definition utils.h:706
void ast_md5_hash(char *output, const char *input)
Produces MD5 hash based on input string.
Definition utils.c:250
struct ao2_container * ast_xmldoc_build_documentation(const char *type)
Build the documentation for a particular source type.
Definition xmldoc.c:2851

References __ast_custom_function_register(), acl_change_stasis_subscribe(), acl_change_stasis_unsubscribe(), action_aocmessage(), action_atxfer(), action_blind_transfer(), action_cancel_atxfer(), action_challenge(), action_command(), action_coresettings(), action_coreshowchannelmap(), action_coreshowchannels(), action_corestatus(), action_createconfig(), action_events(), action_extensionstate(), action_filter(), action_getconfig(), action_getconfigjson(), action_getvar(), action_hangup(), action_listcategories(), action_listcommands(), action_loggerrotate(), action_login(), action_logoff(), action_mailboxcount(), action_mailboxstatus(), action_originate(), action_ping(), action_presencestate(), action_redirect(), action_reload(), action_sendtext(), action_setvar(), action_status(), action_timeout(), action_updateconfig(), action_userevent(), action_waitevent(), allowmultiplelogin, amanageruri, amanagerxmluri, ami_desc, ami_tls_cfg, amis_desc, AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_list, ao2_global_obj_replace_unref, ao2_ref, ao2_t_callback, ao2_t_global_obj_replace_unref, ao2_t_ref, arawmanuri, ARRAY_LEN, ast_append_acl(), ast_begins_with(), ast_calloc, ast_category_browse(), ast_cli_register_multiple, ast_config_destroy(), ast_config_load2(), ast_copy_string(), ast_debug, ast_extension_state_add(), ast_free, ast_free_acl_list(), ast_http_uri_link(), ast_http_uri_unlink(), ast_log, ast_manager_get_generic_type(), ast_manager_register_xml_core, ast_md5_hash(), ast_parse_arg(), 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_copy(), ast_sockaddr_isnull(), ast_sockaddr_parse(), ast_sockaddr_port, ast_sockaddr_set_port, ast_sockaddr_stringify_addr(), ast_ssl_setup(), ast_strdup, ast_tcptls_server_start(), ast_tcptls_server_stop(), ast_tls_read_conf(), ast_true(), ast_variable_browse(), ast_variable_new, ast_variables_destroy(), ast_xmldoc_build_documentation(), authlimit, authtimeout, broken_events_action, cli_manager, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, DEFAULT_MANAGER_PORT, DEFAULT_MANAGER_TLS_PORT, displayconnects, ast_tls_config::enabled, EVENT_FLAG_AOC, EVENT_FLAG_CALL, EVENT_FLAG_COMMAND, EVENT_FLAG_CONFIG, EVENT_FLAG_ORIGINATE, EVENT_FLAG_REPORTING, EVENT_FLAG_SYSTEM, EVENT_FLAG_USER, get_manager_by_name_locked(), get_perm(), global_realm, httptimeout, load_channelvars(), load_disabledevents(), ast_tcptls_session_args::local_address, LOG_ERROR, LOG_NOTICE, LOG_WARNING, manager_add_filter(), manager_debug, manager_enabled, manager_free_user(), manager_modulecheck(), manager_moduleload(), manager_set_defaults(), manager_state_cb(), manager_topic, managerclient_function, manageruri, managerxmluri, mansession_cmp_fn(), ast_tcptls_session_args::name, ast_variable::next, NULL, OBJ_MULTIPLE, OBJ_NODATA, OBJ_UNLINK, PARSE_ADDR, PARSE_IN_RANGE, PARSE_PORT_IGNORE, PARSE_UINT32, rawmanuri, reload(), sessions, stasis_forward_all(), STASIS_MESSAGE_TYPE_INIT, stasis_topic_create(), subscribe_all(), subscribed, timestampevents, ast_tcptls_session_args::tls_cfg, ast_variable::value, value, var, webmanager_enabled, and webregged.

Referenced by acl_change_stasis_cb(), load_module(), and reload_module().

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 10290 of file manager.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 10290 of file manager.c.

◆ AO2_STRING_FIELD_SORT_FN()

AO2_STRING_FIELD_SORT_FN ( ast_xml_doc_item  ,
name   
)

◆ ast_manager_event_blob_create()

struct ast_manager_event_blob * ast_manager_event_blob_create ( int  event_flags,
const char *  manager_event,
const char *  extra_fields_fmt,
  ... 
)

Construct a ast_manager_event_blob.

Since
12

The returned object is AO2 managed, so clean up with ao2_cleanup().

Parameters
event_flagsFlags the event should be raised with.
manager_eventThe event to be raised, should be a string literal.
extra_fields_fmtFormat string for extra fields to include. Or NO_EXTRA_FIELDS for no extra fields.
Returns
New ast_manager_event_blob object.
Return values
NULLon error.

Definition at line 10251 of file manager.c.

10256{
10257 struct ast_manager_event_blob *ev;
10258 va_list argp;
10259
10260 ast_assert(extra_fields_fmt != NULL);
10262
10264 if (!ev) {
10265 return NULL;
10266 }
10267
10268 if (ast_string_field_init(ev, 20)) {
10269 ao2_ref(ev, -1);
10270 return NULL;
10271 }
10272
10275
10276 va_start(argp, extra_fields_fmt);
10277 ast_string_field_ptr_build_va(ev, &ev->extra_fields, extra_fields_fmt, argp);
10278 va_end(argp);
10279
10280 return ev;
10281}
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition astobj2.h:367
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition astobj2.h:404
static void manager_event_blob_dtor(void *obj)
Definition manager.c:10242
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition manager.h:255
#define ast_string_field_ptr_build_va(x, ptr, fmt, args)
Set a field to a complex (built) value with prebuilt va_lists.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Struct containing info for an AMI event to send out.
Definition manager.h:504
const ast_string_field extra_fields
Definition manager.h:509
const char * manager_event
Definition manager.h:506
#define ast_assert(a)
Definition utils.h:779

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_ref, ast_assert, ast_string_field_init, ast_string_field_ptr_build_va, ast_manager_event_blob::event_flags, ast_manager_event_blob::extra_fields, manager_event, ast_manager_event_blob::manager_event, manager_event_blob_dtor(), and NULL.

Referenced by agent_login_to_ami(), agent_logoff_to_ami(), agi_channel_to_ami(), aoc_to_ami(), attended_transfer_to_ami(), blind_transfer_to_ami(), bridge_create(), bridge_destroy(), bridge_video_update(), call_pickup_to_ami(), cc_available_to_ami(), cc_callerrecalling_to_ami(), cc_callerstartmonitoring_to_ami(), cc_callerstopmonitoring_to_ami(), cc_failure_to_ami(), cc_monitorfailed_to_ami(), cc_offertimerstart_to_ami(), cc_recallcomplete_to_ami(), cc_requestacknowledged_to_ami(), cc_requested_to_ami(), channel_new_accountcode(), channel_new_callerid(), channel_new_connected_line(), channel_newexten(), channel_state_change(), contactstatus_to_ami(), dahdichannel_to_ami(), devstate_to_ami(), fake_ami(), local_message_to_ami(), multi_user_event_to_ami(), peerstatus_to_ami(), presence_state_to_ami(), queue_channel_to_ami(), queue_member_to_ami(), queue_multi_channel_to_ami(), rtcp_report_to_ami(), security_event_to_ami_blob(), system_registry_to_ami(), talking_start_to_ami(), talking_stop_to_ami(), and varset_to_ami().

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 10290 of file manager.c.

◆ ast_str_append_event_header()

int ast_str_append_event_header ( struct ast_str **  fields_string,
const char *  header,
const char *  value 
)

append an event header to an ast string

Since
12
Parameters
fields_stringpointer to an ast_string pointer. It may be a pointer to a NULL ast_str pointer, in which case the ast_str will be initialized.
headerThe header being applied
valuethe value of the header
Return values
0if successful
non-zeroon failure

Definition at line 10229 of file manager.c.

10231{
10232 if (!*fields_string) {
10233 *fields_string = ast_str_create(128);
10234 if (!*fields_string) {
10235 return -1;
10236 }
10237 }
10238
10239 return (ast_str_append(fields_string, 0, "%s: %s\r\n", header, value) < 0) ? -1 : 0;
10240}
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition strings.h:1139
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition strings.h:659

References ast_str_append(), ast_str_create, and value.

Referenced by confbridge_talking_cb(), get_bool_header(), and meetme_stasis_cb().

◆ astman_datastore_add()

int astman_datastore_add ( struct mansession s,
struct ast_datastore datastore 
)

Add a datastore to a session.

Return values
0success
non-zerofailure
Since
1.6.1

Definition at line 10190 of file manager.c.

10191{
10192 AST_LIST_INSERT_HEAD(&s->session->datastores, datastore, entry);
10193
10194 return 0;
10195}
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
struct mansession_session::mansession_datastores datastores
struct mansession_session * session
Definition manager.c:315

References AST_LIST_INSERT_HEAD, mansession_session::datastores, and mansession::session.

◆ astman_datastore_find()

struct ast_datastore * astman_datastore_find ( struct mansession s,
const struct ast_datastore_info info,
const char *  uid 
)

Find a datastore on a session.

Returns
pointer to the datastore if found
Return values
NULLif not found
Since
1.6.1

Definition at line 10202 of file manager.c.

10203{
10204 struct ast_datastore *datastore = NULL;
10205
10206 if (info == NULL)
10207 return NULL;
10208
10210 if (datastore->info != info) {
10211 continue;
10212 }
10213
10214 if (uid == NULL) {
10215 /* matched by type only */
10216 break;
10217 }
10218
10219 if ((datastore->uid != NULL) && !strcasecmp(uid, datastore->uid)) {
10220 /* Matched by type AND uid */
10221 break;
10222 }
10223 }
10225
10226 return datastore;
10227}
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Structure for a data store object.
Definition datastore.h:64
const struct ast_datastore_info * info
Definition datastore.h:67
const char * uid
Definition datastore.h:65
struct ast_datastore::@224 entry

References AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, mansession_session::datastores, ast_datastore::entry, ast_datastore::info, NULL, mansession::session, and ast_datastore::uid.

◆ astman_datastore_remove()

int astman_datastore_remove ( struct mansession s,
struct ast_datastore datastore 
)

Remove a datastore from a session.

Return values
0success
non-zerofailure
Since
1.6.1

Definition at line 10197 of file manager.c.

10198{
10199 return AST_LIST_REMOVE(&s->session->datastores, datastore, entry) ? 0 : -1;
10200}
#define AST_LIST_REMOVE(head, elm, field)
Removes a specific entry from a list.

References AST_LIST_REMOVE, mansession_session::datastores, and mansession::session.

◆ astman_is_authed()

int astman_is_authed ( uint32_t  ident)

Determine if a manager session ident is authenticated.

Definition at line 8092 of file manager.c.

8093{
8094 int authed;
8096
8097 if (!(session = find_session(ident, 0)))
8098 return 0;
8099
8100 authed = (session->authenticated != 0);
8101
8104
8105 return authed;
8106}
static struct ast_mansession session
#define ao2_unlock(a)
Definition astobj2.h:729
static struct mansession_session * unref_mansession(struct mansession_session *s)
Unreference manager session object. If no more references, then go ahead and delete it.
Definition manager.c:865
static struct mansession_session * find_session(uint32_t ident, int incinuse)
Definition manager.c:8020

References ao2_unlock, find_session(), session, and unref_mansession().

Referenced by http_post_callback(), and static_callback().

◆ astman_verify_session_readpermissions()

int astman_verify_session_readpermissions ( uint32_t  ident,
int  perm 
)

Verify a session's read permissions against a permission mask.

Parameters
identsession identity
permpermission mask to verify
Return values
1if the session has the permission mask capabilities
0otherwise

Definition at line 8108 of file manager.c.

8109{
8110 int result = 0;
8112 struct ao2_container *sessions;
8113 struct ao2_iterator i;
8114
8115 if (ident == 0) {
8116 return 0;
8117 }
8118
8119 sessions = ao2_global_obj_ref(mgr_sessions);
8120 if (!sessions) {
8121 return 0;
8122 }
8124 ao2_ref(sessions, -1);
8125 while ((session = ao2_iterator_next(&i))) {
8127 if ((session->managerid == ident) && (session->readperm & perm)) {
8128 result = 1;
8131 break;
8132 }
8135 }
8137
8138 return result;
8139}
#define ao2_iterator_next(iter)
Definition astobj2.h:1911
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
Definition astobj2.h:918
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define ao2_lock(a)
Definition astobj2.h:717
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
static PGresult * result
Definition cel_pgsql.c:84
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition astobj2.h:1821

References ao2_global_obj_ref, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_unlock, result, session, sessions, and unref_mansession().

◆ astman_verify_session_writepermissions()

int astman_verify_session_writepermissions ( uint32_t  ident,
int  perm 
)

Verify a session's write permissions against a permission mask.

Parameters
identsession identity
permpermission mask to verify
Return values
1if the session has the permission mask capabilities, otherwise 0
0otherwise

Definition at line 8141 of file manager.c.

8142{
8143 int result = 0;
8145 struct ao2_container *sessions;
8146 struct ao2_iterator i;
8147
8148 if (ident == 0) {
8149 return 0;
8150 }
8151
8152 sessions = ao2_global_obj_ref(mgr_sessions);
8153 if (!sessions) {
8154 return 0;
8155 }
8157 ao2_ref(sessions, -1);
8158 while ((session = ao2_iterator_next(&i))) {
8160 if ((session->managerid == ident) && (session->writeperm & perm)) {
8161 result = 1;
8164 break;
8165 }
8168 }
8170
8171 return result;
8172}

References ao2_global_obj_ref, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_unlock, result, session, sessions, and unref_mansession().

Referenced by http_post_callback().

◆ auth_http_callback()

static int auth_http_callback ( struct ast_tcptls_session_instance ser,
enum ast_http_method  method,
enum output_format  format,
const struct ast_sockaddr remote_address,
const char *  uri,
struct ast_variable get_params,
struct ast_variable headers 
)
static

Definition at line 8667 of file manager.c.

8673{
8675 struct mansession s = { .session = NULL, .tcptls_session = ser };
8676 struct ast_variable *v, *params = get_params;
8677 char template[] = "/tmp/ast-http-XXXXXX"; /* template for temporary file */
8678 struct ast_str *http_header = NULL, *out = NULL;
8679 size_t result_size;
8680 struct message m = { 0 };
8681 int fd;
8682
8683 time_t time_now = time(NULL);
8684 unsigned long nonce = 0, nc;
8685 struct ast_http_digest d = { NULL, };
8686 struct ast_manager_user *user = NULL;
8687 int stale = 0;
8688 char resp_hash[256]="";
8689 /* Cache for user data */
8690 char u_username[80];
8691 int u_readperm;
8692 int u_writeperm;
8693 int u_writetimeout;
8694 int u_displayconnects;
8695
8697 ast_http_error(ser, 501, "Not Implemented", "Attempt to use unimplemented / unsupported method");
8698 return 0;
8699 }
8700
8701 /* Find "Authorization: " header */
8702 for (v = headers; v; v = v->next) {
8703 if (!strcasecmp(v->name, "Authorization")) {
8704 break;
8705 }
8706 }
8707
8708 if (!v || ast_strlen_zero(v->value)) {
8709 goto out_401; /* Authorization Header not present - send auth request */
8710 }
8711
8712 /* Digest found - parse */
8713 if (ast_string_field_init(&d, 128)) {
8715 ast_http_error(ser, 500, "Server Error", "Internal Server Error (out of memory)");
8716 return 0;
8717 }
8718
8719 if (ast_parse_digest(v->value, &d, 0, 1)) {
8720 /* Error in Digest - send new one */
8721 nonce = 0;
8722 goto out_401;
8723 }
8724 if (sscanf(d.nonce, "%30lx", &nonce) != 1) {
8725 ast_log(LOG_WARNING, "Received incorrect nonce in Digest <%s>\n", d.nonce);
8726 nonce = 0;
8727 goto out_401;
8728 }
8729
8731 user = get_manager_by_name_locked(d.username);
8732 if(!user) {
8734 ast_log(LOG_NOTICE, "%s tried to authenticate with nonexistent user '%s'\n", ast_sockaddr_stringify_addr(remote_address), d.username);
8735 nonce = 0;
8736 goto out_401;
8737 }
8738
8739 /* --- We have User for this auth, now check ACL */
8740 if (user->acl && !ast_apply_acl(user->acl, remote_address, "Manager User ACL:")) {
8742 ast_log(LOG_NOTICE, "%s failed to pass IP ACL as '%s'\n", ast_sockaddr_stringify_addr(remote_address), d.username);
8744 ast_http_error(ser, 403, "Permission denied", "Permission denied");
8745 return 0;
8746 }
8747
8748 /* --- We have auth, so check it */
8749
8750 /* compute the expected response to compare with what we received */
8751 {
8752 char *a2;
8753 /* ast_md5_hash outputs 32 characters plus NULL terminator. */
8754 char a2_hash[33];
8755 char resp[256];
8756
8757 /* XXX Now request method are hardcoded in A2 */
8758 if (ast_asprintf(&a2, "%s:%s", ast_get_http_method(method), d.uri) < 0) {
8761 ast_http_error(ser, 500, "Server Error", "Internal Server Error (out of memory)");
8762 return 0;
8763 }
8764
8765 ast_md5_hash(a2_hash, a2);
8766 ast_free(a2);
8767
8768 if (d.qop) {
8769 /* RFC 2617 */
8770 snprintf(resp, sizeof(resp), "%s:%08lx:%s:%s:auth:%s", user->a1_hash, nonce, d.nc, d.cnonce, a2_hash);
8771 } else {
8772 /* RFC 2069 */
8773 snprintf(resp, sizeof(resp), "%s:%08lx:%s", user->a1_hash, nonce, a2_hash);
8774 }
8775 ast_md5_hash(resp_hash, resp);
8776 }
8777
8778 if (strncasecmp(d.response, resp_hash, strlen(resp_hash))) {
8779 /* Something was wrong, so give the client to try with a new challenge */
8781 nonce = 0;
8782 goto out_401;
8783 }
8784
8785 /*
8786 * User are pass Digest authentication.
8787 * Now, cache the user data and unlock user list.
8788 */
8789 ast_copy_string(u_username, user->username, sizeof(u_username));
8790 u_readperm = user->readperm;
8791 u_writeperm = user->writeperm;
8792 u_displayconnects = user->displayconnects;
8793 u_writetimeout = user->writetimeout;
8795
8796 if (!(session = find_session_by_nonce(d.username, nonce, &stale))) {
8797 /*
8798 * Create new session.
8799 * While it is not in the list we don't need any locking
8800 */
8801 if (!(session = build_mansession(remote_address, 0))) {
8803 ast_http_error(ser, 500, "Server Error", "Internal Server Error (out of memory)");
8804 return 0;
8805 }
8807
8808 ast_copy_string(session->username, u_username, sizeof(session->username));
8809 session->managerid = nonce;
8810
8811 session->readperm = u_readperm;
8812 session->writeperm = u_writeperm;
8813 session->writetimeout = u_writetimeout;
8814
8815 if (u_displayconnects) {
8816 ast_verb(2, "HTTP Manager '%s' logged in from %s\n", session->username, ast_sockaddr_stringify_addr(&session->addr));
8817 }
8818 session->noncetime = session->sessionstart = time_now;
8819 session->authenticated = 1;
8820 } else if (stale) {
8821 /*
8822 * Session found, but nonce is stale.
8823 *
8824 * This could be because an old request (w/old nonce) arrived.
8825 *
8826 * This may be as the result of http proxy usage (separate delay or
8827 * multipath) or in a situation where a page was refreshed too quickly
8828 * (seen in Firefox).
8829 *
8830 * In this situation, we repeat the 401 auth with the current nonce
8831 * value.
8832 */
8833 nonce = session->managerid;
8835 stale = 1;
8836 goto out_401;
8837 } else {
8838 sscanf(d.nc, "%30lx", &nc);
8839 if (session->nc >= nc || ((time_now - session->noncetime) > 62) ) {
8840 /*
8841 * Nonce time expired (> 2 minutes) or something wrong with nonce
8842 * counter.
8843 *
8844 * Create new nonce key and resend Digest auth request. Old nonce
8845 * is saved for stale checking...
8846 */
8847 session->nc = 0; /* Reset nonce counter */
8848 session->oldnonce = session->managerid;
8849 nonce = session->managerid = ast_random();
8850 session->noncetime = time_now;
8852 stale = 1;
8853 goto out_401;
8854 } else {
8855 session->nc = nc; /* All OK, save nonce counter */
8856 }
8857 }
8858
8859
8860 /* Reset session timeout. */
8861 session->sessiontimeout = time(NULL) + (httptimeout > 5 ? httptimeout : 5);
8863
8864 ast_mutex_init(&s.lock);
8865 s.session = session;
8866 fd = mkstemp(template); /* create a temporary file for command output */
8867 unlink(template);
8868 if (fd <= -1) {
8869 ast_http_error(ser, 500, "Server Error", "Internal Server Error (mkstemp failed)");
8870 goto auth_callback_out;
8871 }
8873 if (!s.stream) {
8874 ast_log(LOG_WARNING, "HTTP Manager, fdopen failed: %s!\n", strerror(errno));
8875 ast_http_error(ser, 500, "Server Error", "Internal Server Error (fdopen failed)");
8876 close(fd);
8877 goto auth_callback_out;
8878 }
8879
8880 if (method == AST_HTTP_POST) {
8881 params = ast_http_get_post_vars(ser, headers);
8882 if (!params) {
8883 switch (errno) {
8884 case EFBIG:
8885 ast_http_error(ser, 413, "Request Entity Too Large", "Body too large");
8887 goto auth_callback_out;
8888 case ENOMEM:
8890 ast_http_error(ser, 500, "Server Error", "Out of memory");
8892 goto auth_callback_out;
8893 case EIO:
8894 ast_http_error(ser, 400, "Bad Request", "Error parsing request body");
8896 goto auth_callback_out;
8897 }
8898 }
8899 }
8900
8901 astman_append_headers(&m, params);
8902
8903 if (process_message(&s, &m)) {
8904 if (u_displayconnects) {
8905 ast_verb(2, "HTTP Manager '%s' logged off from %s\n", session->username, ast_sockaddr_stringify_addr(&session->addr));
8906 }
8907
8908 session->needdestroy = 1;
8909 }
8910
8912
8913 result_size = lseek(ast_iostream_get_fd(s.stream), 0, SEEK_CUR); /* Calculate approx. size of result */
8914
8915 http_header = ast_str_create(80);
8916 out = ast_str_create(result_size * 2 + 512);
8917 if (http_header == NULL || out == NULL) {
8919 ast_http_error(ser, 500, "Server Error", "Internal Server Error (ast_str_create() out of memory)");
8921 goto auth_callback_out;
8922 }
8923
8924 ast_str_append(&http_header, 0, "Content-type: text/%s\r\n", contenttype[format]);
8925
8926 if (format == FORMAT_XML) {
8927 ast_str_append(&out, 0, "<ajax-response>\n");
8928 } else if (format == FORMAT_HTML) {
8929 ast_str_append(&out, 0,
8930 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
8931 "<html><head>\r\n"
8932 "<title>Asterisk&trade; Manager Interface</title>\r\n"
8933 "</head><body style=\"background-color: #ffffff;\">\r\n"
8934 "<form method=\"POST\">\r\n"
8935 "<table align=\"center\" style=\"background-color: #f1f1f1;\" width=\"500\">\r\n"
8936 "<tr><th colspan=\"2\" style=\"background-color: #f1f1ff;\"><h1>Manager Tester</h1></th></tr>\r\n"
8937 "<tr><th colspan=\"2\" style=\"background-color: #f1f1ff;\">Action: <input name=\"action\" /> Cmd: <input name=\"command\" /><br>"
8938 "<input type=\"submit\" value=\"Send request\" /></th></tr>\r\n");
8939 }
8940
8941 process_output(&s, &out, params, format);
8942
8943 if (format == FORMAT_XML) {
8944 ast_str_append(&out, 0, "</ajax-response>\n");
8945 } else if (format == FORMAT_HTML) {
8946 ast_str_append(&out, 0, "</table></form></body></html>\r\n");
8947 }
8948
8949 ast_http_send(ser, method, 200, NULL, http_header, out, 0, 0);
8950 http_header = NULL;
8951 out = NULL;
8952
8953auth_callback_out:
8955
8956 /* Clear resources and unlock manager session */
8957 if (method == AST_HTTP_POST && params) {
8958 ast_variables_destroy(params);
8959 }
8960
8961 ast_free(http_header);
8962 ast_free(out);
8963
8965 if (session->stream) {
8966 ast_iostream_close(session->stream);
8967 session->stream = NULL;
8968 }
8970
8971 if (session->needdestroy) {
8972 ast_debug(1, "Need destroy, doing it now!\n");
8974 }
8976 return 0;
8977
8978out_401:
8979 if (!nonce) {
8980 nonce = ast_random();
8981 }
8982
8983 ast_http_auth(ser, global_realm, nonce, nonce, stale, NULL);
8985 return 0;
8986}
enum ast_acl_sense ast_apply_acl(struct ast_acl_list *acl_list, const struct ast_sockaddr *addr, const char *purpose)
Apply a set of rules to a given IP address.
Definition acl.c:799
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition astmm.h:267
static int process_message(struct mansession *s, const struct message *m)
Process an AMI message, performing desired action. Return 0 on success, -1 on error that require the ...
Definition manager.c:7089
static void astman_free_headers(struct message *m)
Free headers inside message structure, but not the message structure itself.
Definition manager.c:1606
static void session_destroy(struct mansession_session *s)
Definition manager.c:983
static void astman_append_headers(struct message *m, const struct ast_variable *params)
Append additional headers into the message structure from params.
Definition manager.c:1592
static struct mansession_session * build_mansession(const struct ast_sockaddr *addr, unsigned int needs_alert_pipe)
Allocate manager session structure and add it to the list of sessions.
Definition manager.c:934
void ast_http_send(struct ast_tcptls_session_instance *ser, enum ast_http_method method, int status_code, const char *status_title, struct ast_str *http_header, struct ast_str *out, int fd, unsigned int static_content)
Generic function for sending HTTP/1.1 response.
Definition http.c:522
struct ast_variable * ast_http_get_post_vars(struct ast_tcptls_session_instance *ser, struct ast_variable *headers)
Get post variables from client Request Entity-Body, if content type is application/x-www-form-urlenco...
Definition http.c:1463
@ AST_HTTP_POST
Definition http.h:61
@ AST_HTTP_GET
Definition http.h:60
@ AST_HTTP_HEAD
Definition http.h:62
const char * ast_get_http_method(enum ast_http_method method) attribute_pure
Return http method name string.
Definition http.c:207
void ast_http_request_close_on_completion(struct ast_tcptls_session_instance *ser)
Request the HTTP connection be closed after this HTTP request.
Definition http.c:911
void ast_http_error(struct ast_tcptls_session_instance *ser, int status, const char *title, const char *text)
Send HTTP error message and close socket.
Definition http.c:722
#define ast_verb(level,...)
struct ast_iostream * ast_iostream_from_fd(int *fd)
Create an iostream from a file descriptor.
Definition iostream.c:616
int ast_iostream_get_fd(struct ast_iostream *stream)
Get an iostream's file descriptor.
Definition iostream.c:85
int ast_iostream_close(struct ast_iostream *stream)
Close an iostream.
Definition iostream.c:544
#define ast_mutex_init(pmutex)
Definition lock.h:193
#define ast_mutex_destroy(a)
Definition lock.h:195
int errno
static void close_mansession_file(struct mansession *s)
Definition manager.c:8415
static struct mansession_session * find_session_by_nonce(const char *username, unsigned long nonce, int *stale)
Definition manager.c:8059
static void process_output(struct mansession *s, struct ast_str **out, struct ast_variable *params, enum output_format format)
Definition manager.c:8425
static const char *const contenttype[]
Definition manager.c:8009
const char * method
Definition res_pjsip.c:1277
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
HTTP authentication information.
Definition http.h:125
Support for dynamic strings.
Definition strings.h:623
In case you didn't read that giant block of text above the mansession_session struct,...
Definition manager.c:314
struct ast_iostream * stream
Definition manager.c:316
ast_mutex_t lock
Definition manager.c:321
static struct test_val d
FILE * out
Definition utils/frame.c:33
int ast_parse_digest(const char *digest, struct ast_http_digest *d, int request, int pedantic)
Parse digest authorization header.
Definition utils.c:2672
long int ast_random(void)
Definition utils.c:2346

References ao2_lock, ao2_unlock, ast_apply_acl(), ast_asprintf, ast_copy_string(), ast_debug, ast_free, ast_get_http_method(), ast_http_error(), AST_HTTP_GET, ast_http_get_post_vars(), AST_HTTP_HEAD, AST_HTTP_POST, ast_http_request_close_on_completion(), ast_http_send(), ast_iostream_close(), ast_iostream_from_fd(), ast_iostream_get_fd(), ast_log, ast_md5_hash(), ast_mutex_destroy, ast_mutex_init, ast_parse_digest(), ast_random(), AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_sockaddr_stringify_addr(), ast_str_append(), ast_str_create, ast_string_field_free_memory, ast_string_field_init, ast_strlen_zero(), ast_variables_destroy(), ast_verb, astman_append_headers(), astman_free_headers(), build_mansession(), close_mansession_file(), contenttype, d, errno, find_session_by_nonce(), FORMAT_HTML, FORMAT_XML, get_manager_by_name_locked(), global_realm, httptimeout, mansession::lock, LOG_NOTICE, LOG_WARNING, method, ast_variable::name, ast_variable::next, NULL, out, process_message(), process_output(), mansession::session, session, session_destroy(), mansession::stream, and ast_variable::value.

Referenced by auth_manager_http_callback(), auth_mxml_http_callback(), and auth_rawman_http_callback().

◆ auth_manager_http_callback()

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 9047 of file manager.c.

9048{
9049 int retval;
9050 struct ast_sockaddr ser_remote_address_tmp;
9051
9052 ast_sockaddr_copy(&ser_remote_address_tmp, &ser->remote_address);
9053 retval = auth_http_callback(ser, method, FORMAT_HTML, &ser_remote_address_tmp, uri, get_params, headers);
9054 ast_sockaddr_copy(&ser->remote_address, &ser_remote_address_tmp);
9055 return retval;
9056}
static int auth_http_callback(struct ast_tcptls_session_instance *ser, enum ast_http_method method, enum output_format format, const struct ast_sockaddr *remote_address, const char *uri, struct ast_variable *get_params, struct ast_variable *headers)
Definition manager.c:8667
struct ast_sockaddr remote_address
Definition tcptls.h:153

References ast_sockaddr_copy(), auth_http_callback(), FORMAT_HTML, method, and ast_tcptls_session_instance::remote_address.

◆ auth_mxml_http_callback()

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 9058 of file manager.c.

9059{
9060 int retval;
9061 struct ast_sockaddr ser_remote_address_tmp;
9062
9063 ast_sockaddr_copy(&ser_remote_address_tmp, &ser->remote_address);
9064 retval = auth_http_callback(ser, method, FORMAT_XML, &ser_remote_address_tmp, uri, get_params, headers);
9065 ast_sockaddr_copy(&ser->remote_address, &ser_remote_address_tmp);
9066 return retval;
9067}

References ast_sockaddr_copy(), auth_http_callback(), FORMAT_XML, method, and ast_tcptls_session_instance::remote_address.

◆ auth_rawman_http_callback()

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 9069 of file manager.c.

9070{
9071 int retval;
9072 struct ast_sockaddr ser_remote_address_tmp;
9073
9074 ast_sockaddr_copy(&ser_remote_address_tmp, &ser->remote_address);
9075 retval = auth_http_callback(ser, method, FORMAT_RAW, &ser_remote_address_tmp, uri, get_params, headers);
9076 ast_sockaddr_copy(&ser->remote_address, &ser_remote_address_tmp);
9077 return retval;
9078}

References ast_sockaddr_copy(), auth_http_callback(), FORMAT_RAW, method, and ast_tcptls_session_instance::remote_address.

◆ close_mansession_file()

static void close_mansession_file ( struct mansession s)
static

Definition at line 8415 of file manager.c.

8416{
8417 if (s->stream) {
8419 s->stream = NULL;
8420 } else {
8421 ast_log(LOG_ERROR, "Attempted to close file/file descriptor on mansession without a valid file or file descriptor.\n");
8422 }
8423}

References ast_iostream_close(), ast_log, LOG_ERROR, NULL, and mansession::stream.

Referenced by auth_http_callback(), generic_http_callback(), and process_output().

◆ event_max_name_len_cb()

static int event_max_name_len_cb ( void *  obj,
void *  arg,
void *  data,
int  flags 
)
static

Definition at line 9266 of file manager.c.

9267{
9268 struct ast_xml_doc_item *item = obj;
9269 int *max_len = data;
9270 int len = strlen(item->name);
9271
9272 if (len > *max_len) {
9273 *max_len = len;
9274 }
9275
9276 return 0;
9277}
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
const char * name
Struct that contains the XML documentation for a particular item. Note that this is an ao2 ref counte...
Definition xmldoc.h:56
static struct aco_type item

References item, len(), and aco_type::name.

Referenced by handle_manager_show_events().

◆ find_session()

static struct mansession_session * find_session ( uint32_t  ident,
int  incinuse 
)
static

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 8020 of file manager.c.

8021{
8022 struct ao2_container *sessions;
8024 struct ao2_iterator i;
8025
8026 if (ident == 0) {
8027 return NULL;
8028 }
8029
8030 sessions = ao2_global_obj_ref(mgr_sessions);
8031 if (!sessions) {
8032 return NULL;
8033 }
8035 ao2_ref(sessions, -1);
8036 while ((session = ao2_iterator_next(&i))) {
8038 if (session->managerid == ident && !session->needdestroy) {
8039 ast_atomic_fetchadd_int(&session->inuse, incinuse ? 1 : 0);
8040 break;
8041 }
8044 }
8046
8047 return session;
8048}
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition lock.h:764

References ao2_global_obj_ref, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_unlock, ast_atomic_fetchadd_int(), NULL, session, sessions, and unref_mansession().

Referenced by astman_is_authed(), generic_http_callback(), and manager_fax_session().

◆ find_session_by_nonce()

static struct mansession_session * find_session_by_nonce ( const char *  username,
unsigned long  nonce,
int *  stale 
)
static

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 8059 of file manager.c.

8060{
8062 struct ao2_container *sessions;
8063 struct ao2_iterator i;
8064
8065 if (nonce == 0 || username == NULL || stale == NULL) {
8066 return NULL;
8067 }
8068
8069 sessions = ao2_global_obj_ref(mgr_sessions);
8070 if (!sessions) {
8071 return NULL;
8072 }
8074 ao2_ref(sessions, -1);
8075 while ((session = ao2_iterator_next(&i))) {
8077 if (!strcasecmp(session->username, username) && session->managerid == nonce) {
8078 *stale = 0;
8079 break;
8080 } else if (!strcasecmp(session->username, username) && session->oldnonce == nonce) {
8081 *stale = 1;
8082 break;
8083 }
8086 }
8088
8089 return session;
8090}

References ao2_global_obj_ref, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_unlock, NULL, session, sessions, and unref_mansession().

Referenced by auth_http_callback().

◆ function_amiclient()

static int function_amiclient ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

${AMI_CLIENT()} Dialplan function - reads manager client data

Definition at line 9123 of file manager.c.

9124{
9125 struct ast_manager_user *user = NULL;
9126
9129 AST_APP_ARG(param);
9130 );
9131
9132
9133 if (ast_strlen_zero(data) ) {
9134 ast_log(LOG_WARNING, "AMI_CLIENT() requires two arguments: AMI_CLIENT(<name>[,<arg>])\n");
9135 return -1;
9136 }
9138 args.name = ast_strip(args.name);
9139 args.param = ast_strip(args.param);
9140
9142 if (!(user = get_manager_by_name_locked(args.name))) {
9144 ast_log(LOG_ERROR, "There's no manager user called : \"%s\"\n", args.name);
9145 return -1;
9146 }
9148
9149 if (!strcasecmp(args.param, "sessions")) {
9150 int no_sessions = 0;
9151 struct ao2_container *sessions;
9152
9153 sessions = ao2_global_obj_ref(mgr_sessions);
9154 if (sessions) {
9155 ao2_callback_data(sessions, 0, get_manager_sessions_cb, /*login name*/ data, &no_sessions);
9156 ao2_ref(sessions, -1);
9157 }
9158 snprintf(buf, len, "%d", no_sessions);
9159 } else {
9160 ast_log(LOG_ERROR, "Invalid arguments provided to function AMI_CLIENT: %s\n", args.param);
9161 return -1;
9162
9163 }
9164
9165 return 0;
9166}
#define ao2_callback_data(container, flags, cb_fn, arg, data)
Definition astobj2.h:1723
char buf[BUFSIZE]
Definition eagi_proxy.c:66
static const char name[]
Definition format_mp3.c:68
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition linkedlists.h:78
static int get_manager_sessions_cb(void *obj, void *arg, void *data, int flags)
Get number of logged in sessions for a login name.
Definition manager.c:9108
static struct @522 args
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition strings.h:223

References ao2_callback_data, ao2_global_obj_ref, ao2_ref, args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, AST_STANDARD_APP_ARGS, ast_strip(), ast_strlen_zero(), buf, get_manager_by_name_locked(), get_manager_sessions_cb(), len(), LOG_ERROR, LOG_WARNING, name, NULL, and sessions.

◆ generic_http_callback()

static int generic_http_callback ( struct ast_tcptls_session_instance ser,
enum ast_http_method  method,
enum output_format  format,
const struct ast_sockaddr remote_address,
const char *  uri,
struct ast_variable get_params,
struct ast_variable headers 
)
static
Note
There is approximately a 1 in 1.8E19 chance that the following calculation will produce 0, which is an invalid ID, but due to the properties of the rand() function (and the constancy of s), that won't happen twice in a row.

Definition at line 8458 of file manager.c.

8464{
8465 struct mansession s = { .session = NULL, .tcptls_session = ser };
8467 uint32_t ident;
8468 int fd;
8469 int blastaway = 0;
8470 struct ast_variable *params = get_params;
8471 char template[] = "/tmp/ast-http-XXXXXX"; /* template for temporary file */
8472 struct ast_str *http_header = NULL, *out = NULL;
8473 struct message m = { 0 };
8474
8476 ast_http_error(ser, 501, "Not Implemented", "Attempt to use unimplemented / unsupported method");
8477 return 0;
8478 }
8479
8480 ident = ast_http_manid_from_vars(headers);
8481
8482 if (!(session = find_session(ident, 1))) {
8483
8484 /**/
8485 /* Create new session.
8486 * While it is not in the list we don't need any locking
8487 */
8488 if (!(session = build_mansession(remote_address, 0))) {
8490 ast_http_error(ser, 500, "Server Error", "Internal Server Error (out of memory)");
8491 return 0;
8492 }
8494 session->inuse = 1;
8495 /*!
8496 * \note There is approximately a 1 in 1.8E19 chance that the following
8497 * calculation will produce 0, which is an invalid ID, but due to the
8498 * properties of the rand() function (and the constancy of s), that
8499 * won't happen twice in a row.
8500 */
8501 while ((session->managerid = ast_random() ^ (unsigned long) session) == 0) {
8502 }
8503 }
8505
8506 http_header = ast_str_create(128);
8507 out = ast_str_create(2048);
8508
8509 ast_mutex_init(&s.lock);
8510
8511 if (http_header == NULL || out == NULL) {
8513 ast_http_error(ser, 500, "Server Error", "Internal Server Error (ast_str_create() out of memory)");
8514 goto generic_callback_out;
8515 }
8516
8517 s.session = session;
8518 fd = mkstemp(template); /* create a temporary file for command output */
8519 unlink(template);
8520 if (fd <= -1) {
8521 ast_http_error(ser, 500, "Server Error", "Internal Server Error (mkstemp failed)");
8522 goto generic_callback_out;
8523 }
8525 if (!s.stream) {
8526 ast_log(LOG_WARNING, "HTTP Manager, fdopen failed: %s!\n", strerror(errno));
8527 ast_http_error(ser, 500, "Server Error", "Internal Server Error (fdopen failed)");
8528 close(fd);
8529 goto generic_callback_out;
8530 }
8531
8532 if (method == AST_HTTP_POST) {
8533 params = ast_http_get_post_vars(ser, headers);
8534 if (!params) {
8535 switch (errno) {
8536 case EFBIG:
8537 ast_http_error(ser, 413, "Request Entity Too Large", "Body too large");
8539 goto generic_callback_out;
8540 case ENOMEM:
8542 ast_http_error(ser, 500, "Server Error", "Out of memory");
8544 goto generic_callback_out;
8545 case EIO:
8546 ast_http_error(ser, 400, "Bad Request", "Error parsing request body");
8548 goto generic_callback_out;
8549 }
8550 }
8551 }
8552
8553 astman_append_headers(&m, params);
8554
8555 if (process_message(&s, &m)) {
8556 if (session->authenticated) {
8558 ast_verb(2, "HTTP Manager '%s' logged off from %s\n", session->username, ast_sockaddr_stringify_addr(&session->addr));
8559 }
8560 } else {
8561 if (displayconnects) {
8562 ast_verb(2, "HTTP Connect attempt from '%s' unable to authenticate\n", ast_sockaddr_stringify_addr(&session->addr));
8563 }
8564 }
8565 session->needdestroy = 1;
8566 }
8567
8569
8570 ast_str_append(&http_header, 0,
8571 "Content-type: text/%s\r\n"
8572 "Set-Cookie: mansession_id=\"%08x\"; Version=1; Max-Age=%d\r\n"
8573 "Pragma: SuppressEvents\r\n",
8574 contenttype[format],
8575 session->managerid, httptimeout);
8576
8577 if (format == FORMAT_XML) {
8578 ast_str_append(&out, 0, "<ajax-response>\n");
8579 } else if (format == FORMAT_HTML) {
8580 /*
8581 * When handling AMI-over-HTTP in HTML format, we provide a simple form for
8582 * debugging purposes. This HTML code should not be here, we
8583 * should read from some config file...
8584 */
8585
8586#define ROW_FMT "<tr><td colspan=\"2\" bgcolor=\"#f1f1ff\">%s</td></tr>\r\n"
8587#define TEST_STRING \
8588 "<form action=\"manager\" method=\"post\">\n\
8589 Action: <select name=\"action\">\n\
8590 <option value=\"\">-----&gt;</option>\n\
8591 <option value=\"login\">login</option>\n\
8592 <option value=\"command\">Command</option>\n\
8593 <option value=\"waitevent\">waitevent</option>\n\
8594 <option value=\"listcommands\">listcommands</option>\n\
8595 </select>\n\
8596 or <input name=\"action\"><br/>\n\
8597 CLI Command <input name=\"command\"><br>\n\
8598 user <input name=\"username\"> pass <input type=\"password\" name=\"secret\"><br>\n\
8599 <input type=\"submit\">\n</form>\n"
8600
8601 ast_str_append(&out, 0, "<title>Asterisk&trade; Manager Interface</title>");
8602 ast_str_append(&out, 0, "<body bgcolor=\"#ffffff\"><table align=center bgcolor=\"#f1f1f1\" width=\"500\">\r\n");
8603 ast_str_append(&out, 0, ROW_FMT, "<h1>Manager Tester</h1>");
8605 }
8606
8607 process_output(&s, &out, params, format);
8608
8609 if (format == FORMAT_XML) {
8610 ast_str_append(&out, 0, "</ajax-response>\n");
8611 } else if (format == FORMAT_HTML) {
8612 ast_str_append(&out, 0, "</table></body>\r\n");
8613 }
8614
8616 /* Reset HTTP timeout. If we're not authenticated, keep it extremely short */
8617 session->sessiontimeout = time(NULL) + ((session->authenticated || httptimeout < 5) ? httptimeout : 5);
8618
8619 if (session->needdestroy) {
8620 if (session->inuse == 1) {
8621 ast_debug(1, "Need destroy, doing it now!\n");
8622 blastaway = 1;
8623 } else {
8624 ast_debug(1, "Need destroy, but can't do it yet!\n");
8625 ast_mutex_lock(&session->http_thread_lock);
8626 if (session->http_thread != AST_PTHREADT_NULL) {
8627 pthread_kill(session->http_thread, SIGURG);
8628 }
8629 ast_mutex_unlock(&session->http_thread_lock);
8630 session->inuse--;
8631 }
8632 } else {
8633 session->inuse--;
8634 }
8636
8637 ast_http_send(ser, method, 200, NULL, http_header, out, 0, 0);
8638 http_header = NULL;
8639 out = NULL;
8640
8641generic_callback_out:
8643
8644 /* Clear resource */
8645
8646 if (method == AST_HTTP_POST && params) {
8647 ast_variables_destroy(params);
8648 }
8649 ast_free(http_header);
8650 ast_free(out);
8651
8652 if (session) {
8653 if (blastaway) {
8655 } else {
8656 if (session->stream) {
8657 ast_iostream_close(session->stream);
8658 session->stream = NULL;
8659 }
8661 }
8662 }
8663
8664 return 0;
8665}
static int manager_displayconnects(struct mansession_session *session)
Get displayconnects config option.
Definition manager.c:1036
uint32_t ast_http_manid_from_vars(struct ast_variable *headers) attribute_pure
Return manager id, if exist, from request headers.
Definition http.c:247
#define AST_PTHREADT_NULL
Definition lock.h:73
#define ast_mutex_unlock(a)
Definition lock.h:197
#define ast_mutex_lock(a)
Definition lock.h:196
#define ROW_FMT
#define TEST_STRING

References ao2_lock, ao2_unlock, ast_debug, ast_free, ast_http_error(), AST_HTTP_GET, ast_http_get_post_vars(), AST_HTTP_HEAD, ast_http_manid_from_vars(), AST_HTTP_POST, ast_http_request_close_on_completion(), ast_http_send(), ast_iostream_close(), ast_iostream_from_fd(), ast_log, ast_mutex_destroy, ast_mutex_init, ast_mutex_lock, ast_mutex_unlock, AST_PTHREADT_NULL, ast_random(), ast_sockaddr_stringify_addr(), ast_str_append(), ast_str_create, ast_variables_destroy(), ast_verb, astman_append_headers(), astman_free_headers(), build_mansession(), close_mansession_file(), contenttype, displayconnects, errno, find_session(), FORMAT_HTML, FORMAT_XML, httptimeout, mansession::lock, LOG_WARNING, manager_displayconnects(), method, NULL, out, process_message(), process_output(), ROW_FMT, mansession::session, session, session_destroy(), mansession::stream, TEST_STRING, and unref_mansession().

Referenced by manager_http_callback(), mxml_http_callback(), and rawman_http_callback().

◆ get_manager_sessions_cb()

static int get_manager_sessions_cb ( void *  obj,
void *  arg,
void *  data,
int  flags 
)
static

Get number of logged in sessions for a login name.

Definition at line 9108 of file manager.c.

9109{
9110 struct mansession_session *session = obj;
9111 const char *login = (char *)arg;
9112 int *no_sessions = data;
9113
9114 if (strcasecmp(session->username, login) == 0) {
9115 (*no_sessions)++;
9116 }
9117
9118 return 0;
9119}

References session.

Referenced by function_amiclient().

◆ handle_manager_show_event()

static char * handle_manager_show_event ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 9410 of file manager.c.

9411{
9413 struct ao2_iterator it_events;
9414 struct ast_xml_doc_item *item, *temp;
9415 int length;
9416
9417 if (cmd == CLI_INIT) {
9418 e->command = "manager show event";
9419 e->usage =
9420 "Usage: manager show event <eventname>\n"
9421 " Provides a detailed description a Manager interface event.\n";
9422 return NULL;
9423 }
9424
9425 events = ao2_global_obj_ref(event_docs);
9426 if (!events) {
9427 ast_cli(a->fd, "No manager event documentation loaded\n");
9428 return CLI_SUCCESS;
9429 }
9430
9431 if (cmd == CLI_GENERATE) {
9432 if (a->pos != 3) {
9433 return NULL;
9434 }
9435
9436 length = strlen(a->word);
9437 it_events = ao2_iterator_init(events, 0);
9438 while ((item = ao2_iterator_next(&it_events))) {
9439 if (!strncasecmp(a->word, item->name, length)) {
9441 ao2_ref(item, -1);
9442 break;
9443 }
9444 }
9445 ao2_ref(item, -1);
9446 }
9447 ao2_iterator_destroy(&it_events);
9448
9449 return NULL;
9450 }
9451
9452 if (a->argc != 4) {
9453 return CLI_SHOWUSAGE;
9454 }
9455
9456 if (!(item = ao2_find(events, a->argv[3], OBJ_KEY))) {
9457 ast_cli(a->fd, "Could not find event '%s'\n", a->argv[3]);
9458 return CLI_SUCCESS;
9459 }
9460
9461 ast_cli(a->fd, "Event: %s\n", a->argv[3]);
9462 for (temp = item; temp; temp = AST_LIST_NEXT(temp, next)) {
9463 print_event_instance(a, temp);
9464 }
9465
9466 ao2_ref(item, -1);
9467 return CLI_SUCCESS;
9468}
static const struct adsi_event events[]
#define OBJ_KEY
Definition astobj2.h:1151
#define ao2_cleanup(obj)
Definition astobj2.h:1934
#define ao2_find(container, arg, flags)
Definition astobj2.h:1736
#define CLI_SHOWUSAGE
Definition cli.h:45
#define CLI_SUCCESS
Definition cli.h:44
int ast_cli_completion_add(char *value)
Add a result to a request for completion options.
Definition main/cli.c:2845
void ast_cli(int fd, const char *fmt,...)
Definition clicompat.c:6
@ CLI_INIT
Definition cli.h:152
@ CLI_GENERATE
Definition cli.h:153
static void print_event_instance(struct ast_cli_args *a, struct ast_xml_doc_item *instance)
Definition manager.c:9358
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
char * command
Definition cli.h:186
const char * usage
Definition cli.h:177
struct ast_xml_doc_item * next
Definition xmldoc.h:80
static struct test_val a
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition utils.h:981

References a, ao2_cleanup, ao2_find, ao2_global_obj_ref, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_cli(), ast_cli_completion_add(), AST_LIST_NEXT, ast_strdup, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, events, item, aco_type::name, ast_xml_doc_item::next, NULL, OBJ_KEY, print_event_instance(), RAII_VAR, and ast_cli_entry::usage.

◆ handle_manager_show_events()

static char * handle_manager_show_events ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 9279 of file manager.c.

9280{
9281 struct ao2_container *events;
9282 struct ao2_container *sorted_events;
9283 struct ao2_iterator it_events;
9284 struct ast_xml_doc_item *item;
9285 struct ast_str *buffer;
9286 int col = 0;
9287 int maxlen = 0;
9288 const char *dashes = "--------------------------------------------------------------------------------";
9289
9290 switch (cmd) {
9291 case CLI_INIT:
9292 e->command = "manager show events";
9293 e->usage =
9294 "Usage: manager show events\n"
9295 " Prints a listing of the available Asterisk manager interface events.\n";
9296 return NULL;
9297 case CLI_GENERATE:
9298 return NULL;
9299 }
9300 if (a->argc != 3) {
9301 return CLI_SHOWUSAGE;
9302 }
9303
9304 buffer = ast_str_create(128);
9305 if (!buffer) {
9306 return CLI_SUCCESS;
9307 }
9308
9309 events = ao2_global_obj_ref(event_docs);
9310 if (!events) {
9311 ast_cli(a->fd, "No manager event documentation loaded\n");
9312 ast_free(buffer);
9313 return CLI_SUCCESS;
9314 }
9315
9319 ast_xml_doc_item_sort_fn, NULL);
9320 if (!sorted_events) {
9322 ast_log(AST_LOG_ERROR, "Unable to create sorted container for events\n");
9323 ast_free(buffer);
9324 ao2_ref(events, -1);
9325 return CLI_SUCCESS;
9326 }
9327 ao2_container_dup(sorted_events, events, 0);
9329 ao2_ref(events, -1);
9330
9331 ao2_callback_data(sorted_events, OBJ_NODATA, event_max_name_len_cb, NULL, &maxlen);
9332 it_events = ao2_iterator_init(sorted_events, AO2_ITERATOR_DONTLOCK);
9333
9334 ast_cli(a->fd, "Events:\n");
9335 ast_cli(a->fd, " %.*s %.*s %.*s \n", maxlen, dashes, maxlen, dashes, maxlen, dashes);
9336
9337 while ((item = ao2_iterator_next(&it_events))) {
9338 ast_str_append(&buffer, 0, " %-*s", maxlen, item->name);
9339 if (++col % 3 == 0) {
9340 ast_cli(a->fd, "%s\n", ast_str_buffer(buffer));
9341 ast_str_set(&buffer, 0, "%s", "");
9342 }
9343 ao2_ref(item, -1);
9344 }
9345 ao2_iterator_destroy(&it_events);
9346
9347 if (col % 3 != 0) {
9348 ast_cli(a->fd, "%s\n", ast_str_buffer(buffer));
9349 }
9350 ast_cli(a->fd, "\n%d events registered.\n", col);
9351
9352 ao2_ref(sorted_events, -1);
9353 ast_free(buffer);
9354
9355 return CLI_SUCCESS;
9356}
int ao2_container_dup(struct ao2_container *dest, struct ao2_container *src, enum search_flags flags)
Copy all object references in the src container into the dest container.
@ AO2_ITERATOR_DONTLOCK
Assume that the ao2_container is already locked.
Definition astobj2.h:1852
#define ao2_container_alloc_rbtree(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a red-black tree container.
Definition astobj2.h:1349
@ AO2_CONTAINER_ALLOC_OPT_DUPS_REPLACE
Replace objects with duplicate keys in container.
Definition astobj2.h:1211
#define AST_LOG_ERROR
static int event_max_name_len_cb(void *obj, void *arg, void *data, int flags)
Definition manager.c:9266
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition strings.h:1113
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761

References a, AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_callback_data, AO2_CONTAINER_ALLOC_OPT_DUPS_REPLACE, ao2_container_alloc_rbtree, ao2_container_dup(), ao2_global_obj_ref, ao2_iterator_destroy(), AO2_ITERATOR_DONTLOCK, ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_unlock, ast_cli(), ast_free, ast_log, AST_LOG_ERROR, ast_str_append(), ast_str_buffer(), ast_str_create, ast_str_set(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, event_max_name_len_cb(), events, item, aco_type::name, NULL, OBJ_NODATA, and ast_cli_entry::usage.

◆ handle_manager_show_settings()

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 9219 of file manager.c.

9220{
9221 switch (cmd) {
9222 case CLI_INIT:
9223 e->command = "manager show settings";
9224 e->usage =
9225 "Usage: manager show settings\n"
9226 " Provides detailed list of the configuration of the Manager.\n";
9227 return NULL;
9228 case CLI_GENERATE:
9229 return NULL;
9230 }
9231#define FORMAT " %-25.25s %-15.55s\n"
9232#define FORMAT2 " %-25.25s %-15d\n"
9233#define FORMAT3 " %-25.25s %s\n"
9234 if (a->argc != 3) {
9235 return CLI_SHOWUSAGE;
9236 }
9237 ast_cli(a->fd, "\nGlobal Settings:\n");
9238 ast_cli(a->fd, "----------------\n");
9239 ast_cli(a->fd, FORMAT, "Manager (AMI):", AST_CLI_YESNO(manager_enabled));
9240 ast_cli(a->fd, FORMAT, "Web Manager (AMI/HTTP):", AST_CLI_YESNO(webmanager_enabled));
9241 ast_cli(a->fd, FORMAT, "TCP Bindaddress:", manager_enabled != 0 ? ast_sockaddr_stringify(&ami_desc.local_address) : "Disabled");
9242 ast_cli(a->fd, FORMAT2, "HTTP Timeout (seconds):", httptimeout);
9243 ast_cli(a->fd, FORMAT, "TLS Enable:", AST_CLI_YESNO(ami_tls_cfg.enabled));
9244 ast_cli(a->fd, FORMAT, "TLS Bindaddress:", ami_tls_cfg.enabled != 0 ? ast_sockaddr_stringify(&amis_desc.local_address) : "Disabled");
9245 ast_cli(a->fd, FORMAT, "TLS Certfile:", ami_tls_cfg.certfile);
9246 ast_cli(a->fd, FORMAT, "TLS Privatekey:", ami_tls_cfg.pvtfile);
9247 ast_cli(a->fd, FORMAT, "TLS Cipher:", ami_tls_cfg.cipher);
9248 ast_cli(a->fd, FORMAT, "Allow multiple login:", AST_CLI_YESNO(allowmultiplelogin));
9249 ast_cli(a->fd, FORMAT, "Display connects:", AST_CLI_YESNO(displayconnects));
9250 ast_cli(a->fd, FORMAT, "Timestamp events:", AST_CLI_YESNO(timestampevents));
9251 ast_cli(a->fd, FORMAT3, "Channel vars:", S_OR(manager_channelvars, ""));
9252 ast_cli(a->fd, FORMAT3, "Disabled events:", S_OR(manager_disabledevents, ""));
9253 ast_cli(a->fd, FORMAT, "Debug:", AST_CLI_YESNO(manager_debug));
9254#undef FORMAT
9255#undef FORMAT2
9256#undef FORMAT3
9257
9258 return CLI_SUCCESS;
9259}
#define AST_CLI_YESNO(x)
Return Yes or No depending on the argument.
Definition cli.h:71
static char * manager_channelvars
Definition manager.c:160
static char * manager_disabledevents
Definition manager.c:161
#define FORMAT3
#define FORMAT
#define FORMAT2
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition netsock2.h:256
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition strings.h:80
char * certfile
Definition tcptls.h:90
char * cipher
Definition tcptls.h:92
char * pvtfile
Definition tcptls.h:91

References a, allowmultiplelogin, ami_desc, ami_tls_cfg, amis_desc, ast_cli(), AST_CLI_YESNO, ast_sockaddr_stringify(), ast_tls_config::certfile, ast_tls_config::cipher, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, displayconnects, ast_tls_config::enabled, FORMAT, FORMAT2, FORMAT3, httptimeout, ast_tcptls_session_args::local_address, manager_channelvars, manager_debug, manager_disabledevents, manager_enabled, NULL, ast_tls_config::pvtfile, S_OR, timestampevents, ast_cli_entry::usage, and webmanager_enabled.

◆ load_channelvars()

static void load_channelvars ( struct ast_variable var)
static

Definition at line 9494 of file manager.c.

9495{
9496 char *parse = NULL;
9498 AST_APP_ARG(vars)[MAX_VARS];
9499 );
9500
9503
9504 /* parse the setting */
9507
9509}
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition astmm.h:298
void ast_channel_set_manager_vars(size_t varc, char **vars)
Sets the variables to be stored in the manager_vars field of all snapshots.
Definition channel.c:7896
#define MAX_VARS
Definition manager.c:193

References args, AST_APP_ARG, ast_channel_set_manager_vars(), AST_DECLARE_APP_ARGS, ast_free, AST_STANDARD_APP_ARGS, ast_strdup, ast_strdupa, manager_channelvars, MAX_VARS, NULL, and var.

Referenced by __init_manager().

◆ load_disabledevents()

static void load_disabledevents ( struct ast_variable var)
static

Definition at line 9517 of file manager.c.

References ast_free, ast_strdup, manager_disabledevents, and var.

Referenced by __init_manager().

◆ load_module()

static int load_module ( void  )
static

Definition at line 10172 of file manager.c.

10173{
10174 int rc = 0;
10177#ifdef TEST_FRAMEWORK
10178 AST_TEST_REGISTER(eventfilter_test_creation);
10179 AST_TEST_REGISTER(eventfilter_test_matching);
10180 AST_TEST_REGISTER(originate_permissions_test);
10181#endif
10182 return rc;
10183}
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition clicompat.c:19
static int __init_manager(int reload, int by_external_config)
Definition manager.c:9758
static void manager_shutdown(void)
Definition manager.c:9546
@ AST_MODULE_LOAD_FAILURE
Module could not be loaded properly.
Definition module.h:102
@ AST_MODULE_LOAD_SUCCESS
Definition module.h:70
#define AST_TEST_REGISTER(cb)
Definition test.h:127

References __init_manager(), AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_register_cleanup(), AST_TEST_REGISTER, and manager_shutdown().

◆ manager_event_blob_dtor()

static void manager_event_blob_dtor ( void *  obj)
static

Definition at line 10242 of file manager.c.

10243{
10244 struct ast_manager_event_blob *ev = obj;
10245
10247}

References ast_string_field_free_memory.

Referenced by ast_manager_event_blob_create().

◆ manager_free_user()

static void manager_free_user ( struct ast_manager_user user)
static

Definition at line 9527 of file manager.c.

9528{
9529 ast_free(user->a1_hash);
9530 ast_free(user->secret);
9531 if (user->includefilters) {
9532 ao2_t_ref(user->includefilters, -1, "decrement ref for include container, should be last one");
9533 }
9534 if (user->excludefilters) {
9535 ao2_t_ref(user->excludefilters, -1, "decrement ref for exclude container, should be last one");
9536 }
9537 user->acl = ast_free_acl_list(user->acl);
9538 ast_variables_destroy(user->chanvars);
9539 ast_free(user);
9540}

References ao2_t_ref, ast_free, ast_free_acl_list(), and ast_variables_destroy().

Referenced by __init_manager(), and manager_shutdown().

◆ manager_http_callback()

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 8988 of file manager.c.

8989{
8990 int retval;
8991 struct ast_sockaddr ser_remote_address_tmp;
8992
8993 ast_sockaddr_copy(&ser_remote_address_tmp, &ser->remote_address);
8994 retval = generic_http_callback(ser, method, FORMAT_HTML, &ser_remote_address_tmp, uri, get_params, headers);
8995 ast_sockaddr_copy(&ser->remote_address, &ser_remote_address_tmp);
8996 return retval;
8997}
static int generic_http_callback(struct ast_tcptls_session_instance *ser, enum ast_http_method method, enum output_format format, const struct ast_sockaddr *remote_address, const char *uri, struct ast_variable *get_params, struct ast_variable *headers)
Definition manager.c:8458

References ast_sockaddr_copy(), FORMAT_HTML, generic_http_callback(), method, and ast_tcptls_session_instance::remote_address.

◆ manager_set_defaults()

static void manager_set_defaults ( void  )
static

Definition at line 9730 of file manager.c.

9731{
9732 manager_enabled = 0;
9733 displayconnects = 1;
9735 authtimeout = 30;
9736 authlimit = 50;
9737 manager_debug = 0; /* Debug disabled by default */
9738
9739 /* default values */
9741 sizeof(global_realm));
9744
9745 ami_tls_cfg.enabled = 0;
9756}
#define DEFAULT_REALM
Definition manager.c:163
static void ast_sockaddr_setnull(struct ast_sockaddr *addr)
Sets address addr to null.
Definition netsock2.h:138
const char * ast_config_AST_SYSTEM_NAME
Definition options.c:171
char * capath
Definition tcptls.h:94
char * cafile
Definition tcptls.h:93
#define AST_CERTFILE
Definition tcptls.h:63

References ami_desc, ami_tls_cfg, amis_desc, AST_CERTFILE, ast_config_AST_SYSTEM_NAME, ast_copy_string(), ast_free, ast_sockaddr_setnull(), ast_strdup, authlimit, authtimeout, broken_events_action, ast_tls_config::cafile, ast_tls_config::capath, ast_tls_config::certfile, ast_tls_config::cipher, DEFAULT_REALM, displayconnects, ast_tls_config::enabled, global_realm, ast_tcptls_session_args::local_address, manager_debug, manager_enabled, ast_tls_config::pvtfile, and S_OR.

Referenced by __init_manager().

◆ manager_shutdown()

static void manager_shutdown ( void  )
static

Definition at line 9546 of file manager.c.

9547{
9548 struct ast_manager_user *user;
9549
9550#ifdef TEST_FRAMEWORK
9551 AST_TEST_UNREGISTER(eventfilter_test_creation);
9552 AST_TEST_UNREGISTER(eventfilter_test_matching);
9553 AST_TEST_UNREGISTER(originate_permissions_test);
9554#endif
9555
9556 /* This event is not actually transmitted, but causes all TCP sessions to be closed */
9557 manager_event(EVENT_FLAG_SHUTDOWN, "CloseSession", "CloseSession: true\r\n");
9558
9559 ast_manager_unregister("Ping");
9560 ast_manager_unregister("Events");
9561 ast_manager_unregister("Logoff");
9562 ast_manager_unregister("Login");
9563 ast_manager_unregister("Challenge");
9564 ast_manager_unregister("Hangup");
9565 ast_manager_unregister("Status");
9566 ast_manager_unregister("Setvar");
9567 ast_manager_unregister("Getvar");
9568 ast_manager_unregister("GetConfig");
9569 ast_manager_unregister("GetConfigJSON");
9570 ast_manager_unregister("UpdateConfig");
9571 ast_manager_unregister("CreateConfig");
9572 ast_manager_unregister("ListCategories");
9573 ast_manager_unregister("Redirect");
9574 ast_manager_unregister("Atxfer");
9575 ast_manager_unregister("CancelAtxfer");
9576 ast_manager_unregister("Originate");
9577 ast_manager_unregister("Command");
9578 ast_manager_unregister("ExtensionState");
9579 ast_manager_unregister("PresenceState");
9580 ast_manager_unregister("AbsoluteTimeout");
9581 ast_manager_unregister("MailboxStatus");
9582 ast_manager_unregister("MailboxCount");
9583 ast_manager_unregister("ListCommands");
9584 ast_manager_unregister("SendText");
9585 ast_manager_unregister("UserEvent");
9586 ast_manager_unregister("WaitEvent");
9587 ast_manager_unregister("CoreSettings");
9588 ast_manager_unregister("CoreStatus");
9589 ast_manager_unregister("Reload");
9590 ast_manager_unregister("LoggerRotate");
9591 ast_manager_unregister("CoreShowChannels");
9592 ast_manager_unregister("CoreShowChannelMap");
9593 ast_manager_unregister("ModuleLoad");
9594 ast_manager_unregister("ModuleCheck");
9595 ast_manager_unregister("AOCMessage");
9596 ast_manager_unregister("Filter");
9597 ast_manager_unregister("BlindTransfer");
9600
9601#ifdef AST_XML_DOCS
9602 ao2_t_global_obj_release(event_docs, "Dispose of event_docs");
9603#endif
9604
9605#ifdef TEST_FRAMEWORK
9606 stasis_forward_cancel(test_suite_forwarder);
9607 test_suite_forwarder = NULL;
9608#endif
9609
9610 if (stasis_router) {
9613 }
9621
9624
9635
9636 ao2_global_obj_release(mgr_sessions);
9637
9638 while ((user = AST_LIST_REMOVE_HEAD(&users, list))) {
9640 }
9642
9645}
void ast_cli_unregister_multiple(void)
Definition ael_main.c:408
#define ao2_global_obj_release(holder)
Release the ao2 object held in the global holder.
Definition astobj2.h:859
#define ao2_t_global_obj_release(holder, tag)
Definition astobj2.h:861
static struct stasis_message_router * stasis_router
The stasis_message_router for all Stasis Message Bus API messages.
Definition manager.c:173
static struct stasis_forward * rtp_topic_forwarder
The stasis_subscription for forwarding the RTP topic to the AMI topic.
Definition manager.c:176
static struct stasis_forward * security_topic_forwarder
The stasis_subscription for forwarding the Security topic to the AMI topic.
Definition manager.c:179
#define EVENT_FLAG_SHUTDOWN
Fake event class used to end sessions at shutdown.
Definition manager.c:196
int ast_manager_unregister(const char *action)
support functions to register/unregister AMI action handlers,
Definition manager.c:7782
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
#define STASIS_MESSAGE_TYPE_CLEANUP(name)
Boiler-plate messaging macro for cleaning up message types.
Definition stasis.h:1546
struct stasis_forward * stasis_forward_cancel(struct stasis_forward *forward)
Definition stasis.c:1626
void stasis_message_router_unsubscribe_and_join(struct stasis_message_router *router)
Unsubscribe the router from the upstream topic, blocking until the final message has been processed.
struct ast_manager_user::@403 list
#define AST_TEST_UNREGISTER(cb)
Definition test.h:128

References acl_change_stasis_unsubscribe(), ami_desc, ami_tls_cfg, amis_desc, ao2_cleanup, ao2_global_obj_release, ao2_t_global_obj_release, ARRAY_LEN, ast_cli_unregister_multiple(), ast_custom_function_unregister(), ast_free, AST_LIST_REMOVE_HEAD, ast_manager_get_generic_type(), ast_manager_unregister(), ast_tcptls_server_stop(), AST_TEST_UNREGISTER, ast_tls_config::cafile, ast_tls_config::capath, ast_tls_config::certfile, ast_tls_config::cipher, cli_manager, EVENT_FLAG_SHUTDOWN, ast_manager_user::list, manager_channelvars, manager_disabledevents, manager_event, manager_free_user(), manager_topic, managerclient_function, NULL, ast_tls_config::pvtfile, rtp_topic_forwarder, security_topic_forwarder, stasis_forward_cancel(), stasis_message_router_unsubscribe_and_join(), STASIS_MESSAGE_TYPE_CLEANUP, and stasis_router.

Referenced by load_module().

◆ manager_subscriptions_init()

static int manager_subscriptions_init ( void  )
static

Initialize all Stasis Message Bus API topics and routers used by the various sub-components of AMI.

Definition at line 9651 of file manager.c.

9652{
9653 struct ao2_container *sessions;
9654 int res = 0;
9655
9657 if (!rtp_topic_forwarder) {
9658 return -1;
9659 }
9660
9663 return -1;
9664 }
9665
9667 if (!stasis_router) {
9668 return -1;
9669 }
9672
9673 /*
9674 * The reference to sessions passes to the stasis router subscription so
9675 * no need to unref here at all. This is also invoked after creating the
9676 * sessions container so it has to exist.
9677 */
9678 sessions = ao2_global_obj_ref(mgr_sessions);
9679
9682
9685
9686 /*
9687 * This specific callback is solely for lifetime management of the sessions
9688 * reference. Once the subscription is finalized the reference is dropped in
9689 * the callback.
9690 */
9693
9694 if (res != 0) {
9695 return -1;
9696 }
9697 return 0;
9698}
static void manager_default_msg_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Definition manager.c:559
static void manager_subscription_change_msg_cb(void *userdata, struct stasis_subscription *sub, struct stasis_message *message)
Callback for subscription change messages.
Definition manager.c:622
static void manager_generic_msg_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Definition manager.c:585
struct stasis_message_type * stasis_subscription_change_type(void)
Gets the message type for subscription change notices.
struct stasis_topic * ast_rtp_topic(void)
Stasis Message Bus API topic for RTP and RTCP related messages
struct stasis_topic * ast_security_topic(void)
A stasis_topic which publishes messages for security related issues.
@ STASIS_SUBSCRIPTION_FORMATTER_AMI
Definition stasis.h:311
int stasis_message_router_set_congestion_limits(struct stasis_message_router *router, long low_water, long high_water)
Set the high and low alert water marks of the stasis message router.
#define stasis_message_router_create(topic)
Create a new message router object.
int stasis_message_router_add(struct stasis_message_router *router, struct stasis_message_type *message_type, stasis_subscription_cb callback, void *data)
Add a route to a message router.
void stasis_message_router_set_formatters_default(struct stasis_message_router *router, stasis_subscription_cb callback, void *data, enum stasis_subscription_message_formatters formatters)
Sets the default route of a router with formatters.
#define AST_TASKPROCESSOR_HIGH_WATER_LEVEL

References ao2_global_obj_ref, ast_manager_get_generic_type(), ast_rtp_topic(), ast_security_topic(), AST_TASKPROCESSOR_HIGH_WATER_LEVEL, manager_default_msg_cb(), manager_generic_msg_cb(), manager_subscription_change_msg_cb(), manager_topic, rtp_topic_forwarder, security_topic_forwarder, sessions, stasis_forward_all(), stasis_message_router_add(), stasis_message_router_create, stasis_message_router_set_congestion_limits(), stasis_message_router_set_formatters_default(), stasis_router, stasis_subscription_change_type(), and STASIS_SUBSCRIPTION_FORMATTER_AMI.

Referenced by subscribe_all().

◆ mxml_http_callback()

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 8999 of file manager.c.

9000{
9001 int retval;
9002 struct ast_sockaddr ser_remote_address_tmp;
9003
9004 ast_sockaddr_copy(&ser_remote_address_tmp, &ser->remote_address);
9005 retval = generic_http_callback(ser, method, FORMAT_XML, &ser_remote_address_tmp, uri, get_params, headers);
9006 ast_sockaddr_copy(&ser->remote_address, &ser_remote_address_tmp);
9007 return retval;
9008}

References ast_sockaddr_copy(), FORMAT_XML, generic_http_callback(), method, and ast_tcptls_session_instance::remote_address.

◆ process_output()

static void process_output ( struct mansession s,
struct ast_str **  out,
struct ast_variable params,
enum output_format  format 
)
static

Definition at line 8425 of file manager.c.

8426{
8427 char *buf;
8428 off_t l;
8429 int fd;
8430
8431 if (!s->stream)
8432 return;
8433
8434 /* Ensure buffer is NULL-terminated */
8435 ast_iostream_write(s->stream, "", 1);
8436
8437 fd = ast_iostream_get_fd(s->stream);
8438
8439 l = lseek(fd, 0, SEEK_CUR);
8440 if (l > 0) {
8441 if (MAP_FAILED == (buf = mmap(NULL, l, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0))) {
8442 ast_log(LOG_WARNING, "mmap failed. Manager output was not processed\n");
8443 } else {
8444 if (format == FORMAT_XML || format == FORMAT_HTML) {
8445 xml_translate(out, buf, params, format);
8446 } else {
8447 ast_str_append(out, 0, "%s", buf);
8448 }
8449 munmap(buf, l);
8450 }
8451 } else if (format == FORMAT_XML || format == FORMAT_HTML) {
8452 xml_translate(out, "", params, format);
8453 }
8454
8456}
ssize_t ast_iostream_write(struct ast_iostream *stream, const void *buffer, size_t count)
Write data to an iostream.
Definition iostream.c:390
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:...
Definition manager.c:8297

References ast_iostream_get_fd(), ast_iostream_write(), ast_log, ast_str_append(), buf, close_mansession_file(), FORMAT_HTML, FORMAT_XML, LOG_WARNING, NULL, out, mansession::stream, and xml_translate().

Referenced by auth_http_callback(), and generic_http_callback().

◆ purge_old_stuff()

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 9181 of file manager.c.

9182{
9183 struct ast_tcptls_session_args *ser = data;
9184 /* purge_sessions will return the number of sessions actually purged,
9185 * up to a maximum of it's arguments, purge one at a time, keeping a
9186 * purge interval of 1ms as long as we purged a session, otherwise
9187 * revert to a purge check every 5s
9188 */
9189 if (purge_sessions(1) == 1) {
9190 ser->poll_timeout = 1;
9191 } else {
9192 ser->poll_timeout = 5000;
9193 }
9194}
static int purge_sessions(int n_max)
remove at most n_max stale session from the list.
Definition manager.c:7518
arguments for the accepting thread
Definition tcptls.h:130

References ast_tcptls_session_args::poll_timeout, and purge_sessions().

◆ rawman_http_callback()

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 9010 of file manager.c.

9011{
9012 int retval;
9013 struct ast_sockaddr ser_remote_address_tmp;
9014
9015 ast_sockaddr_copy(&ser_remote_address_tmp, &ser->remote_address);
9016 retval = generic_http_callback(ser, method, FORMAT_RAW, &ser_remote_address_tmp, uri, get_params, headers);
9017 ast_sockaddr_copy(&ser->remote_address, &ser_remote_address_tmp);
9018 return retval;
9019}

References ast_sockaddr_copy(), FORMAT_RAW, generic_http_callback(), method, and ast_tcptls_session_instance::remote_address.

◆ subscribe_all()

static int subscribe_all ( void  )
static

Definition at line 9700 of file manager.c.

9701{
9703 ast_log(AST_LOG_ERROR, "Failed to initialize manager subscriptions\n");
9704 return -1;
9705 }
9706 if (manager_system_init()) {
9707 ast_log(AST_LOG_ERROR, "Failed to initialize manager system handling\n");
9708 return -1;
9709 }
9710 if (manager_channels_init()) {
9711 ast_log(AST_LOG_ERROR, "Failed to initialize manager channel handling\n");
9712 return -1;
9713 }
9714 if (manager_mwi_init()) {
9715 ast_log(AST_LOG_ERROR, "Failed to initialize manager MWI handling\n");
9716 return -1;
9717 }
9718 if (manager_bridging_init()) {
9719 return -1;
9720 }
9721 if (manager_endpoints_init()) {
9722 ast_log(AST_LOG_ERROR, "Failed to initialize manager endpoints handling\n");
9723 return -1;
9724 }
9725
9726 subscribed = 1;
9727 return 0;
9728}
static int manager_subscriptions_init(void)
Initialize all Stasis Message Bus API topics and routers used by the various sub-components of AMI.
Definition manager.c:9651
int manager_mwi_init(void)
Initialize support for AMI MWI events.
int manager_bridging_init(void)
Initialize support for AMI channel events.
int manager_endpoints_init(void)
Initialize support for AMI endpoint events.
int manager_system_init(void)
Initialize support for AMI system events.
int manager_channels_init(void)
Initialize support for AMI channel events.

References ast_log, AST_LOG_ERROR, manager_bridging_init(), manager_channels_init(), manager_endpoints_init(), manager_mwi_init(), manager_subscriptions_init(), manager_system_init(), and subscribed.

Referenced by __init_manager(), ari_conf_init(), session_create(), session_register_apps(), and websocket_attempted_cb().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 10167 of file manager.c.

10168{
10169 return 0;
10170}

◆ variable_count_cmp_fn()

static int variable_count_cmp_fn ( void *  obj,
void *  vstr,
int  flags 
)
static

Definition at line 8258 of file manager.c.

8259{
8260 /* Due to the simplicity of struct variable_count, it makes no difference
8261 * if you pass in objects or strings, the same operation applies. This is
8262 * due to the fact that the hash occurs on the first element, which means
8263 * the address of both the struct and the string are exactly the same. */
8264 struct variable_count *vc = obj;
8265 char *str = vstr;
8266 return !strcmp(vc->varname, str) ? CMP_MATCH | CMP_STOP : 0;
8267}
const char * str
Definition app_jack.c:150
@ CMP_MATCH
Definition astobj2.h:1027
@ CMP_STOP
Definition astobj2.h:1028
char * varname
Definition manager.c:8247

References CMP_MATCH, CMP_STOP, str, and variable_count::varname.

Referenced by xml_translate().

◆ variable_count_hash_fn()

static int variable_count_hash_fn ( const void *  vvc,
const int  flags 
)
static

Definition at line 8251 of file manager.c.

8252{
8253 const struct variable_count *vc = vvc;
8254
8255 return ast_str_hash(vc->varname);
8256}
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
Definition strings.h:1259

References ast_str_hash(), and variable_count::varname.

Referenced by xml_translate().

◆ xml_copy_escape()

static void xml_copy_escape ( struct ast_str **  out,
const char *  src,
int  mode 
)
static

Definition at line 8179 of file manager.c.

8180{
8181 /* store in a local buffer to avoid calling ast_str_append too often */
8182 char buf[256];
8183 char *dst = buf;
8184 const char *save = src;
8185 int space = sizeof(buf);
8186 /* repeat until done and nothing to flush */
8187 for ( ; *src || dst != buf ; src++) {
8188 if (*src == '\0' || space < 10) { /* flush */
8189 *dst++ = '\0';
8190 ast_str_append(out, 0, "%s", buf);
8191 dst = buf;
8192 space = sizeof(buf);
8193 if (*src == '\0') {
8194 break;
8195 }
8196 }
8197
8198 if (mode & 2) {
8199 if (save == src && isdigit(*src)) {
8200 /* The first character of an XML attribute cannot be a digit */
8201 *dst++ = '_';
8202 *dst++ = *src;
8203 space -= 2;
8204 continue;
8205 } else if (!isalnum(*src)) {
8206 /* Replace non-alphanumeric with an underscore */
8207 *dst++ = '_';
8208 space--;
8209 continue;
8210 }
8211 }
8212 switch (*src) {
8213 case '<':
8214 strcpy(dst, "&lt;");
8215 dst += 4;
8216 space -= 4;
8217 break;
8218 case '>':
8219 strcpy(dst, "&gt;");
8220 dst += 4;
8221 space -= 4;
8222 break;
8223 case '\"':
8224 strcpy(dst, "&quot;");
8225 dst += 6;
8226 space -= 6;
8227 break;
8228 case '\'':
8229 strcpy(dst, "&apos;");
8230 dst += 6;
8231 space -= 6;
8232 break;
8233 case '&':
8234 strcpy(dst, "&amp;");
8235 dst += 5;
8236 space -= 5;
8237 break;
8238
8239 default:
8240 *dst++ = mode ? tolower(*src) : *src;
8241 space--;
8242 }
8243 }
8244}

References ast_str_append(), buf, and out.

Referenced by xml_translate().

◆ xml_translate()

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 8297 of file manager.c.

8298{
8299 struct ast_variable *v;
8300 const char *dest = NULL;
8301 char *var, *val;
8302 const char *objtype = NULL;
8303 int in_data = 0; /* parsing data */
8304 int inobj = 0;
8305 int xml = (format == FORMAT_XML);
8306 struct variable_count *vc = NULL;
8307 struct ao2_container *vco = NULL;
8308
8309 if (xml) {
8310 /* dest and objtype need only for XML format */
8311 for (v = get_vars; v; v = v->next) {
8312 if (!strcasecmp(v->name, "ajaxdest")) {
8313 dest = v->value;
8314 } else if (!strcasecmp(v->name, "ajaxobjtype")) {
8315 objtype = v->value;
8316 }
8317 }
8318 if (ast_strlen_zero(dest)) {
8319 dest = "unknown";
8320 }
8321 if (ast_strlen_zero(objtype)) {
8322 objtype = "generic";
8323 }
8324 }
8325
8326 /* we want to stop when we find an empty line */
8327 while (in && *in) {
8328 val = strsep(&in, "\r\n"); /* mark start and end of line */
8329 if (in && *in == '\n') { /* remove trailing \n if any */
8330 in++;
8331 }
8333 ast_debug(5, "inobj %d in_data %d line <%s>\n", inobj, in_data, val);
8334 if (ast_strlen_zero(val)) {
8335 /* empty line */
8336 if (in_data) {
8337 /* close data in Opaque mode */
8338 ast_str_append(out, 0, xml ? "'" : "</td></tr>\n");
8339 in_data = 0;
8340 }
8341
8342 if (inobj) {
8343 /* close block */
8344 ast_str_append(out, 0, xml ? " /></response>\n" :
8345 "<tr><td colspan=\"2\"><hr></td></tr>\r\n");
8346 inobj = 0;
8347 ao2_ref(vco, -1);
8348 vco = NULL;
8349 }
8350 continue;
8351 }
8352
8353 if (!inobj) {
8354 /* start new block */
8355 if (xml) {
8356 ast_str_append(out, 0, "<response type='object' id='%s'><%s", dest, objtype);
8357 }
8360 inobj = 1;
8361 }
8362
8363 if (in_data) {
8364 /* Process data field in Opaque mode. This is a
8365 * followup, so we re-add line feeds. */
8366 ast_str_append(out, 0, xml ? "\n" : "<br>\n");
8367 xml_copy_escape(out, val, 0); /* data field */
8368 continue;
8369 }
8370
8371 /* We expect "Name: value" line here */
8372 var = strsep(&val, ":");
8373 if (val) {
8374 /* found the field name */
8377 } else {
8378 /* field name not found, switch to opaque mode */
8379 val = var;
8380 var = "Opaque-data";
8381 in_data = 1;
8382 }
8383
8384
8385 ast_str_append(out, 0, xml ? " " : "<tr><td>");
8386 if ((vc = ao2_find(vco, var, 0))) {
8387 vc->count++;
8388 } else {
8389 /* Create a new entry for this one */
8390 vc = ao2_alloc(sizeof(*vc), NULL);
8391 vc->varname = var;
8392 vc->count = 1;
8393 ao2_link(vco, vc);
8394 }
8395
8396 xml_copy_escape(out, var, xml ? 1 | 2 : 0); /* data name */
8397 if (vc->count > 1) {
8398 ast_str_append(out, 0, "-%d", vc->count);
8399 }
8400 ao2_ref(vc, -1);
8401 ast_str_append(out, 0, xml ? "='" : "</td><td>");
8402 xml_copy_escape(out, val, 0); /* data field */
8403 if (!in_data || !*in) {
8404 ast_str_append(out, 0, xml ? "'" : "</td></tr>\n");
8405 }
8406 }
8407
8408 if (inobj) {
8409 ast_str_append(out, 0, xml ? " /></response>\n" :
8410 "<tr><td colspan=\"2\"><hr></td></tr>\r\n");
8411 ao2_ref(vco, -1);
8412 }
8413}
char * strsep(char **str, const char *delims)
#define ao2_link(container, obj)
Add an object to a container.
Definition astobj2.h:1532
#define ao2_alloc(data_size, destructor_fn)
Definition astobj2.h:409
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Definition astobj2.h:1303
static void xml_copy_escape(struct ast_str **out, const char *src, int mode)
Definition manager.c:8179
static int variable_count_cmp_fn(void *obj, void *vstr, int flags)
Definition manager.c:8258
static int variable_count_hash_fn(const void *vvc, const int flags)
Definition manager.c:8251
char * ast_trim_blanks(char *str)
Trims trailing whitespace characters from a string.
Definition strings.h:186
char *attribute_pure ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
Definition strings.h:161
FILE * in
Definition utils/frame.c:33

References ao2_alloc, AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, 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, in, ast_variable::name, ast_variable::next, NULL, out, strsep(), ast_variable::value, var, variable_count_cmp_fn(), variable_count_hash_fn(), variable_count::varname, and xml_copy_escape().

Referenced by process_output().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Asterisk Manager Interface" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload_module, .load_pri = AST_MODPRI_CORE, .requires = "extconfig,acl,http", }
static

Definition at line 10290 of file manager.c.

◆ amanageruri

struct ast_http_uri amanageruri
static

Definition at line 9089 of file manager.c.

9089 {
9090 .description = "HTML Manager Event Interface w/Digest authentication",
9091 .uri = "amanager",
9092 .has_subtree = 0,
9093 .callback = auth_manager_http_callback,
9094 .data = NULL,
9095 .key = __FILE__,
9096};
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)
Definition manager.c:9047

Referenced by __init_manager().

◆ amanagerxmluri

struct ast_http_uri amanagerxmluri
static

Definition at line 9098 of file manager.c.

9098 {
9099 .description = "XML Manager Event Interface w/Digest authentication",
9100 .uri = "amxml",
9101 .has_subtree = 0,
9102 .callback = auth_mxml_http_callback,
9103 .data = NULL,
9104 .key = __FILE__,
9105};
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)
Definition manager.c:9058

Referenced by __init_manager().

◆ ami_desc

struct ast_tcptls_session_args ami_desc
static

Definition at line 9197 of file manager.c.

9197 {
9198 .accept_fd = -1,
9199 .master = AST_PTHREADT_NULL,
9200 .tls_cfg = NULL,
9201 .poll_timeout = 5000, /* wake up every 5 seconds */
9202 .periodic_fn = purge_old_stuff,
9203 .name = "AMI server",
9204 .accept_fn = ast_tcptls_server_root, /* thread doing the accept() */
9205 .worker_fn = session_do, /* thread handling the session */
9206};
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 ...
Definition manager.c:7430
static void purge_old_stuff(void *data)
cleanup code called at each iteration of server_root, guaranteed to happen every 5 seconds at most
Definition manager.c:9181
void * ast_tcptls_server_root(void *)
Definition tcptls.c:290

Referenced by __init_manager(), handle_manager_show_settings(), manager_set_defaults(), and manager_shutdown().

◆ ami_tls_cfg

struct ast_tls_config ami_tls_cfg
static

◆ amis_desc

struct ast_tcptls_session_args amis_desc
static

Definition at line 9208 of file manager.c.

9208 {
9209 .accept_fd = -1,
9210 .master = AST_PTHREADT_NULL,
9211 .tls_cfg = &ami_tls_cfg,
9212 .poll_timeout = -1, /* the other does the periodic cleanup */
9213 .name = "AMI TLS server",
9214 .accept_fn = ast_tcptls_server_root, /* thread doing the accept() */
9215 .worker_fn = session_do, /* thread handling the session */
9216};

Referenced by __init_manager(), handle_manager_show_settings(), manager_set_defaults(), and manager_shutdown().

◆ arawmanuri

struct ast_http_uri arawmanuri
static

Definition at line 9080 of file manager.c.

9080 {
9081 .description = "Raw HTTP Manager Event Interface w/Digest authentication",
9082 .uri = "arawman",
9083 .has_subtree = 0,
9084 .callback = auth_rawman_http_callback,
9085 .data = NULL,
9086 .key = __FILE__,
9087};
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)
Definition manager.c:9069

Referenced by __init_manager().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 10290 of file manager.c.

◆ cli_manager

struct ast_cli_entry cli_manager[]
static

Definition at line 9472 of file manager.c.

9472 {
9473 AST_CLI_DEFINE(handle_showmancmd, "Show a manager interface command"),
9474 AST_CLI_DEFINE(handle_showmancmds, "List manager interface commands"),
9475 AST_CLI_DEFINE(handle_showmanconn, "List connected manager interface users"),
9476 AST_CLI_DEFINE(handle_kickmanconn, "Kick a connected manager interface connection"),
9477 AST_CLI_DEFINE(handle_showmanagers, "List configured manager users"),
9478 AST_CLI_DEFINE(handle_showmanager, "Display information on a specific manager user"),
9479 AST_CLI_DEFINE(handle_mandebug, "Show, enable, disable debugging of the manager code"),
9480 AST_CLI_DEFINE(handle_manager_reload, "Reload manager configurations"),
9481 AST_CLI_DEFINE(handle_manager_show_settings, "Show manager global settings"),
9482#ifdef AST_XML_DOCS
9483 AST_CLI_DEFINE(handle_manager_show_events, "List manager interface events"),
9484 AST_CLI_DEFINE(handle_manager_show_event, "Show a manager interface event"),
9485#endif
9486};
#define AST_CLI_DEFINE(fn, txt,...)
Definition cli.h:197
static char * handle_showmancmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition manager.c:1054
static char * handle_showmanconn(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
CLI command manager list connected.
Definition manager.c:1457
static char * handle_kickmanconn(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
CLI command manager kick session.
Definition manager.c:1391
static char * handle_showmanagers(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition manager.c:1306
static char * handle_showmanager(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition manager.c:1233
static char * handle_manager_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
CLI command manager reload.
Definition manager.c:1509
static char * handle_showmancmds(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
CLI command manager list commands.
Definition manager.c:1349
static char * handle_mandebug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition manager.c:1208
static char * handle_manager_show_events(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition manager.c:9279
static char * handle_manager_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
CLI command manager show settings.
Definition manager.c:9219
static char * handle_manager_show_event(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition manager.c:9410

Referenced by __init_manager(), and manager_shutdown().

◆ contenttype

const char* const contenttype[]
static
Initial value:
= {
[FORMAT_RAW] = "plain",
[FORMAT_HTML] = "html",
[FORMAT_XML] = "xml",
}

Definition at line 8009 of file manager.c.

8009 {
8010 [FORMAT_RAW] = "plain",
8011 [FORMAT_HTML] = "html",
8012 [FORMAT_XML] = "xml",
8013};

Referenced by auth_http_callback(), and generic_http_callback().

◆ managerclient_function

struct ast_custom_function managerclient_function
static
Initial value:
= {
.name = "AMI_CLIENT",
.read_max = 12,
}
static int function_amiclient(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
${AMI_CLIENT()} Dialplan function - reads manager client data
Definition manager.c:9123

description of AMI_CLIENT dialplan function

Definition at line 9170 of file manager.c.

9170 {
9171 .name = "AMI_CLIENT",
9172 .read = function_amiclient,
9173 .read_max = 12,
9174};

Referenced by __init_manager(), and manager_shutdown().

◆ manageruri

struct ast_http_uri manageruri
static

Definition at line 9029 of file manager.c.

9029 {
9030 .description = "HTML Manager Event Interface",
9031 .uri = "manager",
9032 .callback = manager_http_callback,
9033 .data = NULL,
9034 .key = __FILE__,
9035};
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)
Definition manager.c:8988

Referenced by __init_manager().

◆ managerxmluri

struct ast_http_uri managerxmluri
static

Definition at line 9037 of file manager.c.

9037 {
9038 .description = "XML Manager Event Interface",
9039 .uri = "mxml",
9040 .callback = mxml_http_callback,
9041 .data = NULL,
9042 .key = __FILE__,
9043};
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)
Definition manager.c:8999

Referenced by __init_manager().

◆ rawmanuri

struct ast_http_uri rawmanuri
static

Definition at line 9021 of file manager.c.

9021 {
9022 .description = "Raw HTTP Manager Event Interface",
9023 .uri = "rawman",
9024 .callback = rawman_http_callback,
9025 .data = NULL,
9026 .key = __FILE__,
9027};
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)
Definition manager.c:9010

Referenced by __init_manager().

◆ webregged

int webregged = 0
static

Definition at line 9176 of file manager.c.

Referenced by __init_manager().

◆ words

const char* words[AST_MAX_CMD_LEN]

Definition at line 210 of file manager.c.

Referenced by check_blacklist().