Index: main/manager.c =================================================================== --- main/manager.c (revision 77884) +++ main/manager.c (working copy) @@ -406,6 +406,45 @@ return get_perm(string); } + +static char mandescr_shell[] = +"Description: Run a shell command from manager.\n" +"Variables: (Names marked with * are required)\n" +" *Command: Command to execute\n" +" ActionID: Option Action id for message matching.\n" +" GetVar: Anything sent within this field indicates you want the output of the shell command. Eg) GetVar: true\n"; + + +/*! \brief action:shell: Manager command "shell" - executes a command as if you were at the shell environment */ +static int action_shell(struct mansession *s, const struct message *m) +{ + /* Things to do: Thread this function, so it does not slow down the GUI */ + FILE *ptr; + char buf[4096] = ""; /* Return Buffer */ + const char *cmd = astman_get_header(m, "Command"); + const char *id = astman_get_header(m, "ActionID"); /* Optional action ID, good for use in javascript...... */ + const char *getvar = astman_get_header(m, "getvar"); /* Option to get return value */ + + if (ast_strlen_zero(cmd)) { + astman_append(s, "No command specified!\n"); + return 0; + } + + if (!ast_strlen_zero(id)) + astman_append(s, "ActionID: %s\r\n", id); /* we are going to send an action id, if they want it. */ + + ptr = popen(cmd, "r"); + + if (!ast_strlen_zero(getvar)) { + while (fgets(buf, sizeof(buf), ptr)) + astman_append(s, buf); + } + + pclose(ptr); + + return 0; +} + static char *complete_show_mancmd(const char *line, const char *word, int pos, int state) { struct manager_action *cur; @@ -3274,6 +3313,7 @@ ast_manager_register2("Redirect", EVENT_FLAG_CALL, action_redirect, "Redirect (transfer) a call", mandescr_redirect ); ast_manager_register2("Originate", EVENT_FLAG_CALL, action_originate, "Originate Call", mandescr_originate); ast_manager_register2("Command", EVENT_FLAG_COMMAND, action_command, "Execute Asterisk CLI Command", mandescr_command ); + ast_manager_register2("Shell", EVENT_FLAG_COMMAND, action_shell, "Executes a Shell Command", mandescr_shell ); ast_manager_register2("ExtensionState", EVENT_FLAG_CALL, action_extensionstate, "Check Extension Status", mandescr_extensionstate ); ast_manager_register2("AbsoluteTimeout", EVENT_FLAG_CALL, action_timeout, "Set Absolute Timeout", mandescr_timeout ); ast_manager_register2("MailboxStatus", EVENT_FLAG_CALL, action_mailboxstatus, "Check Mailbox", mandescr_mailboxstatus );