--- smsdaemon/plugins/ShellExecPlugin.cpp 2008/06/11 08:25:34 44 +++ smsdaemon/plugins/ShellExecPlugin.cpp 2008/12/19 22:29:25 205 @@ -1,27 +1,64 @@ #include "ShellExecPlugin.h" -#include "GsmModem.h" +#include "ISmsTransceiver.h" +#include "Sms.h" -#include "util.h" +#include "Util.h" +#include "ConfigFile.h" -ShellExecPlugin::ShellExecPlugin(std::string pluginCommand, std::string exeCommand) - : Plugin(pluginCommand, std::string("ShellExec: ")+exeCommand ), - _exeCommand(exeCommand) +#include + +ShellExecPlugin::ShellExecPlugin(std::map args) + : Plugin("", "") { + _command = args["trigger"]; + _exeCommand = args["cmd"]; + _description = std::string("ShellExec: ")+_exeCommand; + std::string allowParms = args["allowparms"]; + std::string returnOutput = args["returnoutput"]; + + if (_command == "" || _exeCommand == "" || allowParms == "" || returnOutput == "") + throw std::runtime_error("Usage: plugin = shellexec trigger=; cmd=; allowparms=<0|1>; returnoutput=<0|1>"); + + + _allowParameters = ( ConfigHelper::StringToInt(allowParms) == 1); + _returnOutput = ( ConfigHelper::StringToInt(returnOutput) == 1); } -void ShellExecPlugin::Execute(IGsmModem& modem, SMS& sms) +void ShellExecPlugin::Execute(ISmsTransceiver& modem, SMS& sms) { - std::string parameters = GetSmsData(sms); - parameters = Util::str_replace(parameters,";"); + std::string command = _exeCommand; + + if (_allowParameters) + { + std::string parameters = sms.ExtractParameters(); - std::string command = _exeCommand + " " + parameters; - int retval = ::system( command.c_str() ); + parameters = Util::str_replace(parameters, "||"); + parameters = Util::str_replace(parameters, "&&"); + parameters = Util::str_replace(parameters, ";"); + parameters = Util::str_replace(parameters, "'"); + parameters = Util::str_replace(parameters, "\""); + + command += " "; + command += parameters; + } + std::string output; + std::string* out_p = 0; + + if (_returnOutput) + out_p = &output; + + int retval = Util::my_system( command.c_str(), out_p ); std::string message; if (retval == -1) message = "Error"; else - message = "OK"; - - modem.SendSms(sms.sender, message ); + { + if (_returnOutput) + message = output; + else + message = "OK"; + } + + modem.SendSms(sms.GetSender(), message, false ); }