1 |
#include "ShellExecPlugin.h" |
#include "ShellExecPlugin.h" |
2 |
#include "GsmModem.h" |
#include "ISmsTransceiver.h" |
3 |
|
#include "Sms.h" |
4 |
|
|
5 |
#include "util.h" |
#include "Util.h" |
6 |
|
|
7 |
ShellExecPlugin::ShellExecPlugin(std::string pluginCommand, std::string exeCommand) |
ShellExecPlugin::ShellExecPlugin(std::string pluginCommand, std::string exeCommand, bool allowParameters, bool returnOutput) |
8 |
: Plugin(pluginCommand, std::string("ShellExec: ")+exeCommand ), |
: Plugin(pluginCommand, std::string("ShellExec: ")+exeCommand ), |
9 |
_exeCommand(exeCommand) |
_exeCommand(exeCommand), |
10 |
|
_allowParameters(allowParameters), |
11 |
|
_returnOutput(returnOutput) |
12 |
{ |
{ |
13 |
} |
} |
14 |
|
|
15 |
void ShellExecPlugin::Execute(GsmModem& modem, SMS& sms) |
void ShellExecPlugin::Execute(ISmsTransceiver& modem, SMS& sms) |
16 |
{ |
{ |
17 |
std::string parameters = GetSmsData(sms); |
std::string command = _exeCommand; |
|
parameters = Util::str_replace(parameters,";"); |
|
18 |
|
|
19 |
std::string command = _exeCommand + " " + parameters; |
if (_allowParameters) |
20 |
int retval = ::system( command.c_str() ); |
{ |
21 |
|
std::string parameters = sms.ExtractParameters(); |
22 |
|
|
23 |
|
parameters = Util::str_replace(parameters, "||"); |
24 |
|
parameters = Util::str_replace(parameters, "&&"); |
25 |
|
parameters = Util::str_replace(parameters, ";"); |
26 |
|
parameters = Util::str_replace(parameters, "'"); |
27 |
|
parameters = Util::str_replace(parameters, "\""); |
28 |
|
|
29 |
|
command += " "; |
30 |
|
command += parameters; |
31 |
|
} |
32 |
|
std::string output; |
33 |
|
std::string* out_p = 0; |
34 |
|
|
35 |
|
if (_returnOutput) |
36 |
|
out_p = &output; |
37 |
|
|
38 |
|
int retval = Util::my_system( command.c_str(), out_p ); |
39 |
|
|
40 |
std::string message; |
std::string message; |
41 |
if (retval == -1) |
if (retval == -1) |
42 |
message = "Error"; |
message = "Error"; |
43 |
else |
else |
44 |
message = "OK"; |
{ |
45 |
|
if (_returnOutput) |
46 |
|
message = output; |
47 |
|
else |
48 |
|
message = "OK"; |
49 |
|
} |
50 |
|
|
51 |
modem.SendSms(sms.sender, message ); |
modem.SendSms(sms.GetSender(), message, false ); |
52 |
} |
} |