From 5a81b0e272a6e456e8c29ce2e755ac4e1c8b5546 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Mon, 11 Feb 2013 02:12:12 +0200 Subject: started separated proto lib implementation started modules support implementation --- .../unix_exec_service/docs/unix_exec_service.cmds | 7 ++ services/unix_exec_service/main.cpp | 132 +++++++++++++++++++++ .../unix_exec_service/unix_exec_service.project | 102 ++++++++++++++++ 3 files changed, 241 insertions(+) create mode 100644 services/unix_exec_service/docs/unix_exec_service.cmds create mode 100644 services/unix_exec_service/main.cpp create mode 100644 services/unix_exec_service/unix_exec_service.project (limited to 'services/unix_exec_service') diff --git a/services/unix_exec_service/docs/unix_exec_service.cmds b/services/unix_exec_service/docs/unix_exec_service.cmds new file mode 100644 index 0000000..4052970 --- /dev/null +++ b/services/unix_exec_service/docs/unix_exec_service.cmds @@ -0,0 +1,7 @@ +#list of commands with aliases and description +#string should look like "alias=command;description", any part except command can be omited, for example "=command;" +unix_exec_service=/sbin/runscript /etc/init.d/vbox_headles restart --nodeps;Restart Virtualbox VMs via my wrapper +reboot now=reboot;Reboot server +halt now=halt;Shutdown server +restart cups=/sbin/runscript /etc/init.d/cupsd restart --nodeps;Restart cups printing system +restart ppp=/sbin/runscript /etc/init.d/net.ppp0 stop --nodeps;Restart ppp internet interface diff --git a/services/unix_exec_service/main.cpp b/services/unix_exec_service/main.cpp new file mode 100644 index 0000000..ea7faef --- /dev/null +++ b/services/unix_exec_service/main.cpp @@ -0,0 +1,132 @@ +// Copyright © 2013 sss +//. +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +//. +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#include + +#include +#include +#include +#include + +#include "api_service.h" + +struct alias +{ + std::string _alias, cmd; + bool operator==(std::string a) + { + return this->_alias == a; + } +}; + +std::list aliases; +std::list cmds; + +std::string extract_aliased_cmd(std::string cmd) +{ + std::list::iterator i = std::find(aliases.begin(), aliases.end(), cmd); + if(i != aliases.end()) + return i->cmd; + else + return std::string(); +} + + +void * shell_exec(void * t) +{ + char *c = (char*)t; + std::string cmd; + if(c[0] != '/') + cmd = extract_aliased_cmd(c); + else + cmd = c; + if(!cmd.empty()) + { + } + return NULL; +} + +void load_cmds() +{ + std::fstream f("./unix_exec_service.cmds", std::fstream::in); + if(!f.is_open()) + f.open("./modules/unix_exec_service.cmds"); + if(!f.is_open()) + return; + char buf[2048]; + while(f.good() && !f.eof()) + { + std::string str, cmd, _alias, descr; + f.getline(buf, 2047); + if(buf[0] == '#') + continue; + str = buf; + if(buf[0] != '=') + { + std::string::size_type p2 = str.find("="); + if(p2 != std::string::npos) + { + _alias = str.substr(0, p2); + } + } + std::string::size_type p1 = str.find("="), p2 = 0; + if(p1 != std::string::npos) + { + p1++; + p2 = str.find(";", p1); + if(p2 != std::string::npos) + cmd = str.substr(p1, p2-p1); + } + p1 = str.find(";"); + if(p1 != std::string::npos && p1 < str.length()) + { + p1++; + descr = str.substr(p1); + } + if(!_alias.empty()) + { + alias a; + a._alias = _alias; + a.cmd = cmd; + aliases.push_back(a); + } + command c; + c.command = cmd; + c.description = descr; + cmds.push_back(c); +// printf("%s | %s | %s\n", _alias.c_str(), cmd.c_str(), descr.c_str()); + } +} + +init_func(init) +{ + load_cmds(); +} + +services(get_services) +{ + service_info shell_exec_service; + shell_exec_service.acc = ACC_CHAR_PTR; + shell_exec_service.ret = RET_STD_STRING; + shell_exec_service.name = "Shell exec"; + shell_exec_service.description = "Run shell command and return output"; + shell_exec_service.exec = &shell_exec; + shell_exec_service.predefined = cmds; + s.push_back(shell_exec_service); +} + + diff --git a/services/unix_exec_service/unix_exec_service.project b/services/unix_exec_service/unix_exec_service.project new file mode 100644 index 0000000..eb14914 --- /dev/null +++ b/services/unix_exec_service/unix_exec_service.project @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + None + + + + + + + + + + + /usr/include +/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include + + + + + + + + + + + + + + + + + + + + + + + + + + None + + + + + + + + + + + + + + + -- cgit v1.2.3