diff options
Diffstat (limited to 'services')
-rw-r--r-- | services/unix_exec_service/docs/unix_exec_service.cmds | 7 | ||||
-rw-r--r-- | services/unix_exec_service/main.cpp | 132 | ||||
-rw-r--r-- | services/unix_exec_service/unix_exec_service.project | 102 |
3 files changed, 241 insertions, 0 deletions
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 <stdio.h> + +#include <string> +#include <list> +#include <algorithm> +#include <fstream> + +#include "api_service.h" + +struct alias +{ + std::string _alias, cmd; + bool operator==(std::string a) + { + return this->_alias == a; + } +}; + +std::list<alias> aliases; +std::list<command> cmds; + +std::string extract_aliased_cmd(std::string cmd) +{ + std::list<alias>::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 @@ +<?xml version="1.0" encoding="utf-8"?> +<CodeLite_Project Name="unix_exec_service" InternalType="Console"> + <Plugins> + <Plugin Name="qmake"> + <![CDATA[00010001N0005Debug000000000000]]> + </Plugin> + </Plugins> + <Description/> + <Dependencies/> + <VirtualDirectory Name="src"> + <File Name="main.cpp"/> + </VirtualDirectory> + <Settings Type="Dynamic Library"> + <GlobalSettings> + <Compiler Options="" C_Options=""> + <IncludePath Value="."/> + </Compiler> + <Linker Options=""> + <LibraryPath Value="."/> + </Linker> + <ResourceCompiler Options=""/> + </GlobalSettings> + <Configuration Name="Debug" CompilerType="gnu g++" DebuggerType="GNU gdb debugger" Type="Dynamic Library" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append"> + <Compiler Options="-g;-O0;-Wall -fPIC" C_Options="-g;-O0;-Wall -fPIC" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" UseDifferentPCHFlags="no" PCHFlags=""> + <IncludePath Value="."/> + <IncludePath Value="../../server"/> + <IncludePath Value="../../proto_lib"/> + </Compiler> + <Linker Options="" Required="yes"/> + <ResourceCompiler Options="" Required="no"/> + <General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes"/> + <Environment EnvVarSetName="<Use Defaults>" DbgSetName="<Use Defaults>"> + <![CDATA[]]> + </Environment> + <Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath=""> + <PostConnectCommands/> + <StartupCommands/> + </Debugger> + <PreBuild/> + <PostBuild/> + <CustomBuild Enabled="no"> + <RebuildCommand/> + <CleanCommand/> + <BuildCommand/> + <PreprocessFileCommand/> + <SingleFileCommand/> + <MakefileGenerationCommand/> + <ThirdPartyToolName>None</ThirdPartyToolName> + <WorkingDirectory/> + </CustomBuild> + <AdditionalRules> + <CustomPostBuild/> + <CustomPreBuild/> + </AdditionalRules> + <Completion EnableCpp11="yes"> + <ClangCmpFlagsC/> + <ClangCmpFlags/> + <ClangPP/> + <SearchPaths>/usr/include +/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include</SearchPaths> + </Completion> + </Configuration> + <Configuration Name="Release" CompilerType="gnu gcc" DebuggerType="GNU gdb debugger" Type="" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append"> + <Compiler Options="-O2;-Wall" C_Options="-O2;-Wall" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" UseDifferentPCHFlags="no" PCHFlags=""> + <IncludePath Value="."/> + </Compiler> + <Linker Options="" Required="yes"/> + <ResourceCompiler Options="" Required="no"/> + <General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Release" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes"/> + <Environment EnvVarSetName="<Use Defaults>" DbgSetName="<Use Defaults>"> + <![CDATA[ + ]]> + </Environment> + <Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath=""> + <PostConnectCommands/> + <StartupCommands/> + </Debugger> + <PreBuild/> + <PostBuild/> + <CustomBuild Enabled="no"> + <RebuildCommand/> + <CleanCommand/> + <BuildCommand/> + <PreprocessFileCommand/> + <SingleFileCommand/> + <MakefileGenerationCommand/> + <ThirdPartyToolName>None</ThirdPartyToolName> + <WorkingDirectory/> + </CustomBuild> + <AdditionalRules> + <CustomPostBuild/> + <CustomPreBuild/> + </AdditionalRules> + <Completion EnableCpp11="no"> + <ClangCmpFlagsC/> + <ClangCmpFlags/> + <ClangPP/> + <SearchPaths/> + </Completion> + </Configuration> + </Settings> +</CodeLite_Project> |