From ce9d7576fa9d76c8bd3a4d8b996e3162e90f5c08 Mon Sep 17 00:00:00 2001 From: Brian West Date: Fri, 5 Sep 2008 04:09:50 +0000 Subject: [PATCH] MODAPP-138 with tweaks git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9459 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../applications/mod_commands/mod_commands.c | 18 ++++++++++++++++++ src/mod/applications/mod_dptools/mod_dptools.c | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index d0ef245200..04ad0e8d7b 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -2505,6 +2505,23 @@ SWITCH_STANDARD_API(global_getvar_function) return SWITCH_STATUS_SUCCESS; } +#define SYSTEM_SYNTAX "" +SWITCH_STANDARD_API(system_function) +{ + if (switch_strlen_zero(cmd)) { + stream->write_function(stream, "-USAGE: %s\n", SYSTEM_SYNTAX); + return SWITCH_STATUS_SUCCESS; + } + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Executing command: %s\n", cmd); + if (system(cmd) < 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Failed to execute command: %s\n", cmd); + } + stream->write_function(stream, "+OK\n"); + return SWITCH_STATUS_SUCCESS; +} + + SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load) { switch_api_interface_t *commands_api_interface; @@ -2589,6 +2606,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load) SWITCH_ADD_API(commands_api_interface, "module_exists", "check if module exists", module_exists_function, ""); SWITCH_ADD_API(commands_api_interface, "uuid_send_dtmf", "send dtmf digits", uuid_send_dtmf_function, UUID_SEND_DTMF_SYNTAX); SWITCH_ADD_API(commands_api_interface, "eval", "eval (noop)", eval_function, ""); + SWITCH_ADD_API(commands_api_interface, "system", "Execute a system command", system_function, SYSTEM_SYNTAX); /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_NOUNLOAD; diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 0d6578b6e6..51e6085566 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -1185,7 +1185,7 @@ SWITCH_STANDARD_APP(fax_detect_session_function) SWITCH_STANDARD_APP(system_session_function) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Executing command: %s\n", data); - if (!system(data)) { + if (system(data) < 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Failed to execute command: %s\n", data); } }