1 |
torben |
35 |
#include "ShellExecPlugin.h" |
2 |
|
|
#include "GsmModem.h" |
3 |
|
|
|
4 |
|
|
#include "util.h" |
5 |
|
|
|
6 |
torben |
56 |
ShellExecPlugin::ShellExecPlugin(std::string pluginCommand, std::string exeCommand, bool allowParameters) |
7 |
torben |
35 |
: Plugin(pluginCommand, std::string("ShellExec: ")+exeCommand ), |
8 |
torben |
56 |
_exeCommand(exeCommand), |
9 |
|
|
_allowParameters(allowParameters) |
10 |
torben |
35 |
{ |
11 |
|
|
} |
12 |
|
|
|
13 |
torben |
44 |
void ShellExecPlugin::Execute(IGsmModem& modem, SMS& sms) |
14 |
torben |
35 |
{ |
15 |
torben |
56 |
std::string command = _exeCommand; |
16 |
torben |
35 |
|
17 |
torben |
56 |
if (_allowParameters) |
18 |
|
|
{ |
19 |
|
|
std::string parameters = GetSmsData(sms); |
20 |
|
|
|
21 |
|
|
parameters = Util::str_replace(parameters, "||"); |
22 |
|
|
parameters = Util::str_replace(parameters, "&&"); |
23 |
|
|
parameters = Util::str_replace(parameters, ";"); |
24 |
|
|
parameters = Util::str_replace(parameters, "'"); |
25 |
|
|
parameters = Util::str_replace(parameters, "\""); |
26 |
|
|
|
27 |
|
|
command += " "; |
28 |
|
|
command += parameters; |
29 |
|
|
} |
30 |
torben |
86 |
int retval = Util::my_system( command.c_str() ); |
31 |
torben |
35 |
|
32 |
|
|
std::string message; |
33 |
|
|
if (retval == -1) |
34 |
|
|
message = "Error"; |
35 |
|
|
else |
36 |
|
|
message = "OK"; |
37 |
|
|
|
38 |
torben |
63 |
modem.SendSms(sms.sender, message, false ); |
39 |
torben |
35 |
} |