mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 20:20:07 +00:00
After discussing this with other people, we decided we'd like to try to do this a little differently.
Stay tuned. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@43290 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -106,12 +106,6 @@ int ast_manager_register2(
|
||||
*/
|
||||
int ast_manager_unregister( char *action );
|
||||
|
||||
/*! Add a manager_user to current list of manager */
|
||||
int *ast_manager_add(struct ast_manager_user *amu);
|
||||
|
||||
/*! Get an manager by his name */
|
||||
struct ast_manager_user *ast_get_manager_by_name_locked(const char *name);
|
||||
|
||||
/*! External routines may send asterisk manager events this way */
|
||||
/*! \param category Event category, matches manager authorization
|
||||
\param event Event name
|
||||
@@ -139,11 +133,5 @@ void astman_append(struct mansession *s, const char *fmt, ...)
|
||||
int init_manager(void);
|
||||
/*! Called by Asterisk initialization */
|
||||
int reload_manager(void);
|
||||
/*! Add a manager_user to current list of manager */
|
||||
int *ast_manager_add(struct ast_manager_user *amu);
|
||||
int *ast_manager_user_add(struct ast_manager_user *amu);
|
||||
/*! Get an manager by his name */
|
||||
struct ast_manager_user *ast_get_manager_by_name_locked(const char *name);
|
||||
|
||||
|
||||
#endif /* _ASTERISK_MANAGER_H */
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Asterisk -- An open source telephony toolkit.
|
||||
*
|
||||
* Copyright (C) 1999 - 2006, Digium, Inc.
|
||||
|
246
main/manager.c
246
main/manager.c
@@ -103,12 +103,9 @@ static pthread_t t;
|
||||
static int block_sockets = 0;
|
||||
static int num_sessions = 0;
|
||||
|
||||
static struct ast_manager_user *amus =NULL;
|
||||
|
||||
/* Protected by the sessions list lock */
|
||||
struct eventqent *master_eventq = NULL;
|
||||
|
||||
AST_MUTEX_DEFINE_STATIC(amulock);
|
||||
AST_THREADSTORAGE(manager_event_buf, manager_event_buf_init);
|
||||
#define MANAGER_EVENT_BUF_INITSIZE 256
|
||||
|
||||
@@ -178,17 +175,6 @@ struct mansession {
|
||||
AST_LIST_ENTRY(mansession) list;
|
||||
};
|
||||
|
||||
struct ast_manager_user {
|
||||
char username[80];
|
||||
char *secret;
|
||||
char *deny;
|
||||
char *permit;
|
||||
char *read;
|
||||
char *write;
|
||||
unsigned int displayconnects:1;
|
||||
struct ast_manager_user *next;
|
||||
};
|
||||
|
||||
static AST_LIST_HEAD_STATIC(sessions, mansession);
|
||||
|
||||
static struct manager_action *first_action = NULL;
|
||||
@@ -394,36 +380,6 @@ static char *html_translate(char *in)
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct ast_manager_user *ast_get_manager_by_name_locked(const char *name)
|
||||
{
|
||||
struct ast_manager_user *tmp = NULL;
|
||||
tmp=amus;
|
||||
while (tmp) {
|
||||
if (!strcasecmp(tmp->username, name))
|
||||
break;
|
||||
tmp = tmp->next;
|
||||
}
|
||||
if ( tmp)
|
||||
return tmp;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int *ast_manager_user_add(struct ast_manager_user *amu) {
|
||||
if (!amu) {
|
||||
ast_log(LOG_DEBUG, "You cant pass NULL to that function");
|
||||
return NULL;
|
||||
}
|
||||
ast_mutex_lock(&amulock);
|
||||
amu->next = amus;
|
||||
amus = amu;
|
||||
ast_mutex_unlock(&amulock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void astman_append(struct mansession *s, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
@@ -468,79 +424,6 @@ static int handle_showmancmd(int fd, int argc, char *argv[])
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static int handle_showmanager(int fd, int argc, char *argv[])
|
||||
{
|
||||
struct ast_manager_user *tmp;
|
||||
if (argc != 4 )
|
||||
return RESULT_SHOWUSAGE;
|
||||
|
||||
/* try to lock manager_user list ... */
|
||||
if (ast_mutex_lock(&amulock)) {
|
||||
ast_log(LOG_ERROR, "Unable to lock manager_user list\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
tmp = ast_get_manager_by_name_locked(argv[3]);
|
||||
|
||||
if (!tmp) {
|
||||
ast_cli(fd, "There are no manager called %s\n",argv[3]);
|
||||
ast_mutex_unlock(&amulock);
|
||||
return -1;
|
||||
}
|
||||
ast_cli(fd,"\n");
|
||||
ast_cli(fd,
|
||||
" username: %s\n"
|
||||
" secret: %s\n"
|
||||
" deny: %s\n"
|
||||
" permit: %s\n"
|
||||
" read: %s\n"
|
||||
" write: %s\n"
|
||||
"displayconnects: %s\n",
|
||||
(tmp->username ? tmp->username : "(N/A)"),
|
||||
(tmp->secret ? tmp->secret : "(N/A)"),
|
||||
(tmp->deny ? tmp->deny : "(N/A)"),
|
||||
(tmp->permit ? tmp->permit : "(N/A)"),
|
||||
(tmp->read ? tmp->read : "(N/A)"),
|
||||
(tmp->write ? tmp->write : "(N/A)"),
|
||||
(tmp->displayconnects ? "yes" : "no"));
|
||||
ast_mutex_unlock(&amulock);
|
||||
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int handle_showmanagers(int fd, int argc, char *argv[]) {
|
||||
struct ast_manager_user *tmp;
|
||||
int count_amu = 0;
|
||||
|
||||
if ( argc > 4 )
|
||||
return RESULT_SHOWUSAGE;
|
||||
|
||||
/* try to lock manager_user list ... */
|
||||
if (ast_mutex_lock(&amulock)) {
|
||||
ast_log(LOG_ERROR, "Unable to lock manager_user list\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
tmp=amus;
|
||||
if (!tmp) {
|
||||
ast_cli(fd, "There are no manager user.\n");
|
||||
ast_mutex_unlock(&amulock);
|
||||
return -1;
|
||||
}
|
||||
ast_cli(fd, "\nusername\n--------\n");
|
||||
while (tmp) {
|
||||
ast_cli(fd, "%s\n", tmp->username);
|
||||
tmp = tmp->next;
|
||||
count_amu++;
|
||||
}
|
||||
ast_mutex_unlock(&amulock);
|
||||
ast_cli(fd,"-------------------\n");
|
||||
ast_cli(fd,"%d manager users configured.\n", count_amu);
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/*! \brief CLI command
|
||||
Should change to "manager show commands" */
|
||||
static int handle_showmancmds(int fd, int argc, char *argv[])
|
||||
@@ -595,55 +478,60 @@ static int handle_showmaneventq(int fd, int argc, char *argv[])
|
||||
}
|
||||
|
||||
static char showmancmd_help[] =
|
||||
"Usage: show manager command <actionname>\n"
|
||||
"Usage: manager show command <actionname>\n"
|
||||
" Shows the detailed description for a specific Asterisk manager interface command.\n";
|
||||
|
||||
static char showmancmds_help[] =
|
||||
"Usage: show manager commands\n"
|
||||
"Usage: manager list commands\n"
|
||||
" Prints a listing of all the available Asterisk manager interface commands.\n";
|
||||
|
||||
static char showmanconn_help[] =
|
||||
"Usage: show manager connected\n"
|
||||
"Usage: manager list connected\n"
|
||||
" Prints a listing of the users that are currently connected to the\n"
|
||||
"Asterisk manager interface.\n";
|
||||
|
||||
static char showmaneventq_help[] =
|
||||
"Usage: show manager eventq\n"
|
||||
"Usage: manager list eventq\n"
|
||||
" Prints a listing of all events pending in the Asterisk manger\n"
|
||||
"event queue.\n";
|
||||
|
||||
static char showmanagers_help[] =
|
||||
"Usage: show managers\n"
|
||||
" Prints a listing of all managers that are currently configured on that\n"
|
||||
" system.\n";
|
||||
static struct ast_cli_entry cli_show_manager_command_deprecated = {
|
||||
{ "show", "manager", "command", NULL },
|
||||
handle_showmancmd, NULL,
|
||||
NULL, complete_show_mancmd };
|
||||
|
||||
static char showmanager_help[] =
|
||||
" Usage: show manager foobar\n"
|
||||
" Display all the infos related to the manager foobar.\n";
|
||||
static struct ast_cli_entry cli_show_manager_commands_deprecated = {
|
||||
{ "show", "manager", "commands", NULL },
|
||||
handle_showmancmds, NULL,
|
||||
NULL };
|
||||
|
||||
static struct ast_cli_entry show_managers_cli =
|
||||
{ { "manager", "show", "users" },
|
||||
handle_showmanagers, "Show all managers users (connected or not)", showmanagers_help };
|
||||
static struct ast_cli_entry cli_show_manager_connected_deprecated = {
|
||||
{ "show", "manager", "connected", NULL },
|
||||
handle_showmanconn, NULL,
|
||||
NULL };
|
||||
|
||||
static struct ast_cli_entry show_manager_cli =
|
||||
{ { "manager", "show", "user" }, handle_showmanager, "Display information on a specific manager", showmanager_help};
|
||||
static struct ast_cli_entry cli_show_manager_eventq_deprecated = {
|
||||
{ "show", "manager", "eventq", NULL },
|
||||
handle_showmaneventq, NULL,
|
||||
NULL };
|
||||
|
||||
static struct ast_cli_entry cli_manager[] = {
|
||||
{ { "manager", "show", "command", NULL },
|
||||
handle_showmancmd, "Show a manager interface command",
|
||||
showmancmd_help, complete_show_mancmd, &cli_show_manager_command_deprecated },
|
||||
|
||||
static struct ast_cli_entry show_mancmd_cli =
|
||||
{ { "show", "manager", "command", NULL },
|
||||
handle_showmancmd, "Show a manager interface command", showmancmd_help, complete_show_mancmd };
|
||||
{ { "manager", "list", "commands", NULL },
|
||||
handle_showmancmds, "List manager interface commands",
|
||||
showmancmds_help, NULL, &cli_show_manager_commands_deprecated },
|
||||
|
||||
static struct ast_cli_entry show_mancmds_cli =
|
||||
{ { "show", "manager", "commands", NULL },
|
||||
handle_showmancmds, "List manager interface commands", showmancmds_help };
|
||||
{ { "manager", "list", "connected", NULL },
|
||||
handle_showmanconn, "List connected manager interface users",
|
||||
showmanconn_help, NULL, &cli_show_manager_connected_deprecated },
|
||||
|
||||
static struct ast_cli_entry show_manconn_cli =
|
||||
{ { "show", "manager", "connected", NULL },
|
||||
handle_showmanconn, "Show connected manager interface users", showmanconn_help };
|
||||
|
||||
static struct ast_cli_entry show_maneventq_cli =
|
||||
{ { "show", "manager", "eventq", NULL },
|
||||
handle_showmaneventq, "Show manager interface queued events", showmaneventq_help };
|
||||
{ { "manager", "list", "eventq", NULL },
|
||||
handle_showmaneventq, "List manager interface queued events",
|
||||
showmaneventq_help, NULL, &cli_show_manager_eventq_deprecated },
|
||||
};
|
||||
|
||||
static void unuse_eventqent(struct eventqent *e)
|
||||
{
|
||||
@@ -2584,14 +2472,13 @@ static int webregged = 0;
|
||||
int init_manager(void)
|
||||
{
|
||||
struct ast_config *cfg;
|
||||
char *val,*cat;
|
||||
char *val;
|
||||
int oldportno = portno;
|
||||
static struct sockaddr_in ba;
|
||||
int x = 1;
|
||||
int flags;
|
||||
int webenabled = 0;
|
||||
int newhttptimeout = 60;
|
||||
amus = NULL;
|
||||
if (!registered) {
|
||||
/* Register default actions */
|
||||
ast_manager_register2("Ping", 0, action_ping, "Keepalive command", mandescr_ping);
|
||||
@@ -2614,13 +2501,7 @@ int init_manager(void)
|
||||
ast_manager_register2("UserEvent", EVENT_FLAG_USER, action_userevent, "Send an arbitrary event", mandescr_userevent);
|
||||
ast_manager_register2("WaitEvent", 0, action_waitevent, "Wait for an event to occur", mandescr_waitevent);
|
||||
|
||||
ast_cli_register(&show_mancmd_cli);
|
||||
ast_cli_register(&show_mancmds_cli);
|
||||
ast_cli_register(&show_manconn_cli);
|
||||
ast_cli_register(&show_maneventq_cli);
|
||||
ast_cli_register(&show_managers_cli);
|
||||
ast_cli_register(&show_manager_cli);
|
||||
|
||||
ast_cli_register_multiple(cli_manager, sizeof(cli_manager) / sizeof(struct ast_cli_entry));
|
||||
ast_extension_state_add(NULL, NULL, manager_state_cb, NULL);
|
||||
registered = 1;
|
||||
/* Append placeholder event so master_eventq never runs dry */
|
||||
@@ -2682,60 +2563,6 @@ int init_manager(void)
|
||||
ast_log(LOG_WARNING, "Unable to change management port / enabled\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
cat = ast_category_browse(cfg, NULL);
|
||||
amus=NULL; /* Resetting the boss */
|
||||
while(cat) {
|
||||
if (!strcasecmp(cat, "general")) {
|
||||
ast_log(LOG_NOTICE, "ignoring the cat general\n");
|
||||
cat = ast_category_browse(cfg, cat);
|
||||
continue;
|
||||
}
|
||||
|
||||
struct ast_manager_user *amu = malloc(sizeof(struct ast_manager_user));
|
||||
memset(amu, 0, sizeof(struct ast_manager_user));
|
||||
struct ast_variable *var;
|
||||
var = ast_variable_browse(cfg, cat);
|
||||
|
||||
while (var) {
|
||||
if (!strcasecmp(var->name, "secret")) {
|
||||
if (amu->secret)
|
||||
free(amu->secret);
|
||||
amu->secret=strdup(var->value);
|
||||
} else if (!strcasecmp(var->name, "deny") ) {
|
||||
if (amu->deny)
|
||||
free(amu->deny);
|
||||
amu->deny=strdup(var->value);
|
||||
} else if (!strcasecmp(var->name, "permit") ) {
|
||||
if (amu->permit)
|
||||
free(amu->permit);
|
||||
amu->permit=strdup(var->value);
|
||||
} else if (!strcasecmp(var->name, "read") ) {
|
||||
if (amu->read)
|
||||
free(amu->read);
|
||||
amu->read=strdup(var->value);
|
||||
} else if (!strcasecmp(var->name, "write") ) {
|
||||
if (amu->write)
|
||||
free(amu->write);
|
||||
amu->write=strdup(var->value);
|
||||
} else if (!strcasecmp(var->name, "displayconnects") ) {
|
||||
amu->displayconnects=ast_true(var->value);
|
||||
} else {
|
||||
ast_log(LOG_DEBUG, "%s is unknown.\n",var->name);
|
||||
}
|
||||
var = var->next;
|
||||
}
|
||||
|
||||
ast_copy_string(amu->username,cat,sizeof(amu->username));
|
||||
|
||||
ast_log(LOG_DEBUG, "Adding %s\n",amu->username);
|
||||
ast_manager_user_add(amu);
|
||||
amu=NULL;
|
||||
cat = ast_category_browse(cfg, cat);
|
||||
}
|
||||
|
||||
ast_config_destroy(cfg);
|
||||
|
||||
if (webenabled && enabled) {
|
||||
@@ -2794,4 +2621,3 @@ int reload_manager(void)
|
||||
manager_event(EVENT_FLAG_SYSTEM, "Reload", "Message: Reload Requested\r\n");
|
||||
return init_manager();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user