diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2013-02-11 02:12:12 +0200 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2013-02-11 02:12:12 +0200 |
commit | 5a81b0e272a6e456e8c29ce2e755ac4e1c8b5546 (patch) | |
tree | fe3f315cf3ebf102ca5d6b8529fc172ab55c9352 | |
parent | 94a11e7736df09143fd7cf1a75282dc9b408fbd9 (diff) |
started separated proto lib implementation
started modules support implementation
-rw-r--r-- | proto_lib/api_protocol.h | 62 | ||||
-rw-r--r-- | proto_lib/lib.project | 105 | ||||
-rw-r--r-- | proto_lib/packet.cpp | 98 | ||||
-rw-r--r-- | proto_lib/packet.h | 38 | ||||
-rw-r--r-- | proto_lib/proto_lib.workspace | 12 | ||||
-rw-r--r-- | proto_lib/protocol.cpp | 64 | ||||
-rw-r--r-- | restarter.workspace | 18 | ||||
-rw-r--r-- | server/api_service.h | 48 | ||||
-rw-r--r-- | server/config.cpp | 15 | ||||
-rw-r--r-- | server/config.h | 21 | ||||
-rw-r--r-- | server/get_function.cpp | 46 | ||||
-rw-r--r-- | server/get_function.h | 23 | ||||
-rw-r--r-- | server/headers.h | 26 | ||||
-rw-r--r-- | server/main.cpp | 239 | ||||
-rw-r--r-- | server/modules.cpp | 50 | ||||
-rw-r--r-- | server/modules.h | 6 | ||||
-rw-r--r-- | server/restarter_server.project | 29 | ||||
-rw-r--r-- | server/server.cpp | 129 | ||||
-rw-r--r-- | server/server.h | 118 | ||||
-rw-r--r-- | server/service.cpp | 16 | ||||
-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 |
23 files changed, 1171 insertions, 233 deletions
diff --git a/proto_lib/api_protocol.h b/proto_lib/api_protocol.h new file mode 100644 index 0000000..8206854 --- /dev/null +++ b/proto_lib/api_protocol.h @@ -0,0 +1,62 @@ +// 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. + +#ifndef API_PROTOCOL_H +#define API_PROTOCOL_H + + +struct service_s +{ + struct cmd + { + std::string command, description; + }; + std::string service; + std::list<cmd> cmds; +}; + +enum packet_type {AUTH_REPLY, AUTH_REQUEST, SERVICES_REPLY, SERVICES_REQUEST, COMMAND_REPLY, COMMAND_REQUEST, UNKNOWN}; + +class packet +{ +public: + packet(); + packet(std::vector<unsigned char>&); + const std::vector<unsigned char> &raw(); + packet_type get_type(); + bool is_good(); + bool is_server_packet(); + bool is_client_packet(); + bool assign(packet&); + bool assign(std::vector<unsigned char>&); +private: + std::vector<unsigned char> data; +}; + +//server functions +bool serv_validate_client_proto(packet&); + +//client functions + +packet cli_make_auth_packet(); //should be first packet to server +packet cli_make_command_packet(std::string &service, std::string &command); +packet cli_request_services(); +std::list<service_s> cli_extract_services(packet&); +bool cli_check_auth_reply(packet&); //false on fail +std::string cli_parse_command_reply(packet&); + + +#endif diff --git a/proto_lib/lib.project b/proto_lib/lib.project new file mode 100644 index 0000000..d8e56a4 --- /dev/null +++ b/proto_lib/lib.project @@ -0,0 +1,105 @@ +<?xml version="1.0" encoding="utf-8"?> +<CodeLite_Project Name="lib" InternalType="Console"> + <Plugins> + <Plugin Name="qmake"> + <![CDATA[00010001N0005Debug000000000000]]> + </Plugin> + </Plugins> + <Description/> + <Dependencies/> + <VirtualDirectory Name="src"> + <File Name="protocol.cpp"/> + <File Name="api_protocol.h"/> + <File Name="packet.cpp"/> + <File Name="packet.h"/> + </VirtualDirectory> + <Dependencies Name="Debug"/> + <Dependencies Name="Release"/> + <Settings Type="Static 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="Static Library" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append"> + <Compiler Options="-g;-O0;-Wall" C_Options="-g;-O0;-Wall" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" UseDifferentPCHFlags="no" PCHFlags=""> + <IncludePath Value="."/> + </Compiler> + <Linker Options="" Required="yes"/> + <ResourceCompiler Options="" Required="no"/> + <General OutputFile="$(IntermediateDirectory)/libproto.a" 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 g++" 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> diff --git a/proto_lib/packet.cpp b/proto_lib/packet.cpp new file mode 100644 index 0000000..3e0d676 --- /dev/null +++ b/proto_lib/packet.cpp @@ -0,0 +1,98 @@ +// 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 <string> +#include <list> +#include <vector> +#include <algorithm> +#include "api_protocol.h" +#include "packet.h" + + +packet::packet() +{ +} + +packet::packet(std::vector<unsigned char>& new_data) +{ + data = new_data; +} + +bool packet::assign(packet& p) +{ + data = p.data; + return is_good(); +} + +bool packet::assign(std::vector<unsigned char>& v) +{ + data = v; + return is_good(); +} + +bool packet::is_good() +{ + if(data.empty()) + return false; + if(std::search(data.begin(), data.end(), proto_header, proto_header + sizeof(proto_header)) == data.end()) + return false; + if(std::search(data.begin(), data.end(), proto_footer, proto_footer + sizeof(proto_footer)) == data.end()) + return false; + return true; +} + +bool packet::is_client_packet() +{ + std::vector<unsigned char>::iterator i = data.begin(); + i+= sizeof(proto_header); + std::vector<unsigned char> cli; + cli.push_back(*i); + i++; + cli.push_back(*i); + if(std::search(cli.begin(), cli.end(), cli_packet, cli_packet + sizeof(cli_packet)) != cli.end()) + return true; + return false; +} + +bool packet::is_server_packet() +{ + std::vector<unsigned char>::iterator i = data.begin(); + i+= sizeof(proto_header); + std::vector<unsigned char> srv; + srv.push_back(*i); + i++; + srv.push_back(*i); + if(std::search(srv.begin(), srv.end(), serv_packet, serv_packet + sizeof(serv_packet)) != srv.end()) + return true; + return false; +} + +packet_type packet::get_type() +{ + std::vector<unsigned char>::iterator i = data.begin(); + i+= (sizeof(proto_header) + 2); + std::vector<unsigned char> type; + type.push_back(*i); + i++; + type.push_back(*i); + bool cli = is_client_packet(); + if(std::search(type.begin(), type.end(), type_auth, type_auth + sizeof(type_auth)) != type.end()) + return cli?AUTH_REQUEST:AUTH_REPLY; + if(std::search(type.begin(), type.end(), type_services, type_services + sizeof(type_services)) != type.end()) + return cli?SERVICES_REQUEST:SERVICES_REPLY; + if(std::search(type.begin(), type.end(), type_command, type_command + sizeof(type_command)) != type.end()) + return cli?COMMAND_REQUEST:COMMAND_REPLY; + return UNKNOWN; +} diff --git a/proto_lib/packet.h b/proto_lib/packet.h new file mode 100644 index 0000000..6ef9094 --- /dev/null +++ b/proto_lib/packet.h @@ -0,0 +1,38 @@ +// 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. + + + + +const unsigned char proto_header [] = { 0x06, 0x06, 0x06, 0x13}; +const unsigned char proto_footer [] = { 0x13, 0x06, 0x06, 0x06}; + +const unsigned char cli_packet [] = {0xF0, 0X01}; +const unsigned char serv_packet [] = {0xF0, 0X00}; + +const unsigned char proto_version = 0x03; + +const unsigned char delimiter = 0x01; + + + + +//each data type should be specified at begin and end of data block +//data types follow: + +const unsigned char type_auth [] = {0x01, 0x01}; +const unsigned char type_services [] = {0xA, 0x01}; +const unsigned char type_command [] = {0xA, 0x02}; diff --git a/proto_lib/proto_lib.workspace b/proto_lib/proto_lib.workspace new file mode 100644 index 0000000..bde095f --- /dev/null +++ b/proto_lib/proto_lib.workspace @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<CodeLite_Workspace Name="proto_lib" Database="./proto_lib.tags"> + <Project Name="lib" Path="lib.project" Active="Yes"/> + <BuildMatrix> + <WorkspaceConfiguration Name="Debug" Selected="yes"> + <Project Name="lib" ConfigName="Debug"/> + </WorkspaceConfiguration> + <WorkspaceConfiguration Name="Release" Selected="yes"> + <Project Name="lib" ConfigName="Release"/> + </WorkspaceConfiguration> + </BuildMatrix> +</CodeLite_Workspace> diff --git a/proto_lib/protocol.cpp b/proto_lib/protocol.cpp new file mode 100644 index 0000000..e709415 --- /dev/null +++ b/proto_lib/protocol.cpp @@ -0,0 +1,64 @@ +// 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 <string> +#include <list> +#include <vector> +#include <algorithm> +#include "api_protocol.h" +#include "packet.h" + + + +bool serv_validate_client_proto(packet &p) +{ + const std::vector<unsigned char> &data = p.raw(); + if(data.empty()) + return false; + if(std::search(data.begin(), data.end(), proto_header, proto_header + sizeof(proto_header)) == data.end()) + return false; + if(std::search(data.begin(), data.end(), proto_footer, proto_footer + sizeof(proto_footer)) == data.end()) + return false; + std::vector<unsigned char>::const_iterator i = std::search(data.begin(), data.end(), cli_packet, cli_packet + sizeof(cli_packet)); + if(i == data.end()) + return false; + i += sizeof(cli_packet); + if(*i < proto_version) + return false; + return true; +} + +packet cli_make_auth_packet() +{ + std::vector<unsigned char> v; + int size = sizeof(proto_header); + for(int i = 0; i < size; i++) + v.push_back(proto_header[i]); + size = sizeof(cli_packet); + for(int i = 0; i < size; i++) + v.push_back(cli_packet[i]); + size = sizeof(type_auth); + for(int i = 0; i < size; i++) + v.push_back(type_auth[i]); + v.push_back(proto_version); + size = sizeof(proto_footer); + for(int i = 0; i < size; i++) + v.push_back(proto_footer[i]); + packet *p = new packet; + p->assign(v); + return *p; +} + diff --git a/restarter.workspace b/restarter.workspace new file mode 100644 index 0000000..1ee1e18 --- /dev/null +++ b/restarter.workspace @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="utf-8"?> +<CodeLite_Workspace Name="restarter" Database="./restarter.tags"> + <Project Name="restarter_server" Path="server/restarter_server.project" Active="No"/> + <Project Name="lib" Path="proto_lib/lib.project" Active="Yes"/> + <Project Name="unix_exec_service" Path="services/unix_exec_service/unix_exec_service.project" Active="No"/> + <BuildMatrix> + <WorkspaceConfiguration Name="Debug" Selected="yes"> + <Project Name="restarter_server" ConfigName="Debug"/> + <Project Name="lib" ConfigName="Debug"/> + <Project Name="unix_exec_service" ConfigName="Debug"/> + </WorkspaceConfiguration> + <WorkspaceConfiguration Name="Release" Selected="yes"> + <Project Name="restarter_server" ConfigName="Release"/> + <Project Name="lib" ConfigName="Release"/> + <Project Name="unix_exec_service" ConfigName="Release"/> + </WorkspaceConfiguration> + </BuildMatrix> +</CodeLite_Workspace> diff --git a/server/api_service.h b/server/api_service.h new file mode 100644 index 0000000..9d6a656 --- /dev/null +++ b/server/api_service.h @@ -0,0 +1,48 @@ +// 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. + +#ifndef API_SERVICES_H +#define API_SERVICES_H + +enum service_return {RET_NONE = 2, RET_VOID_PTR = 4, RET_CHAR_PTR = 8, RET_STD_STRING = 16, RET_INT, RET_FLOAT = 32}; +enum service_accept {ACC_NONE = 2, ACC_VOID_PTR = 4, ACC_CHAR_PTR = 8, ACC_STD_STRING = 16, ACC_INT, ACC_FLOAT = 32}; + +struct command +{ + std::string command, description; +}; + +//service may have predefined command set + +struct service_info +{ + std::string name, description; + service_return ret; + service_accept acc; + void * (*exec)(void *); + std::list<command> predefined; +}; + +#define services(x) extern "C" void __attribute__((__visibility__("default"))) x(std::list<service_info> &s) +//service should export "get_service" function which fill list of available services in this service library + +#define init_func(x) extern "C" void __attribute__((__visibility__("default"))) x() +//service may export "init" function which will be called on service loading + + + + +#endif diff --git a/server/config.cpp b/server/config.cpp new file mode 100644 index 0000000..265971b --- /dev/null +++ b/server/config.cpp @@ -0,0 +1,15 @@ +// 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. diff --git a/server/config.h b/server/config.h new file mode 100644 index 0000000..bdea2d1 --- /dev/null +++ b/server/config.h @@ -0,0 +1,21 @@ +// 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. + +#ifndef CONFIG_H +#define CONFIG_H + + +#endif diff --git a/server/get_function.cpp b/server/get_function.cpp new file mode 100644 index 0000000..00aa569 --- /dev/null +++ b/server/get_function.cpp @@ -0,0 +1,46 @@ +// 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. + + +#ifdef _WIN32 +#include <windows.h> +#else +#include <dlfcn.h> +#endif +#include <stdlib.h> + +void *load_lib(const char *path) +{ +#ifdef _WIN32 + return (void*)LoadLibraryA(path); +#else + return dlopen(path, RTLD_LAZY); +#endif +} + +void *get_function(const char *path, const char *func) +{ + void *lib = load_lib(path); + if(lib) + { +#ifdef _WIN32 + return GetProcAddressA((HANDLE)lib, func); +#else + return dlsym(lib, func); +#endif + } + return NULL; +} diff --git a/server/get_function.h b/server/get_function.h new file mode 100644 index 0000000..1156afe --- /dev/null +++ b/server/get_function.h @@ -0,0 +1,23 @@ +// 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. + +#ifndef GET_FUNCTION_H +#define GET_FUNCTION_H + + +void *get_function(const char *path, const char *func); + +#endif diff --git a/server/headers.h b/server/headers.h new file mode 100644 index 0000000..c7119b6 --- /dev/null +++ b/server/headers.h @@ -0,0 +1,26 @@ + +//c +#include <cstdlib> +#include <stdio.h> + +//os +#include <signal.h> +#include <unistd.h> + +//c++ +#include <iostream> +#include <fstream> + +//boost +#include <boost/bind.hpp> +#include <boost/asio.hpp> +#include <boost/asio/ssl.hpp> +#include <boost/filesystem.hpp> + +//our api + +#include "api_service.h" +#include "api_protocol.h" +#include "get_function.h" +#include "modules.h" +#include "server.h" diff --git a/server/main.cpp b/server/main.cpp index c92244f..eae3b1e 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -1,4 +1,4 @@ -// Copyright © 2010-2012 sss +// Copyright © 2010-2013 sss // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -16,232 +16,10 @@ //based on async_tcp_echo_server.cpp code by Christopher M. Kohlhoff (chris at kohlhoff dot com) -#include <cstdlib> +#include "headers.h" -#include <signal.h> -#include <unistd.h> -#include <stdio.h> -#include <iostream> -#include <fstream> -#include <boost/bind.hpp> -#include <boost/asio.hpp> -#include <boost/asio/ssl.hpp> -using boost::asio::ip::tcp; -typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> ssl_socket; - -class session -{ -public: - session(boost::asio::io_service& io_service, - boost::asio::ssl::context& context) - : socket_(io_service, context) { - } - - ssl_socket::lowest_layer_type& socket() - { - return socket_.lowest_layer(); - } - - void handle_handshake(const boost::system::error_code& error) - { - if (!error) - { - socket_.async_read_some(boost::asio::buffer(data_, max_length), - boost::bind(&session::handle_read, this, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred)); - } - else - { - delete this; - } - } - - void start() - { - socket_.async_handshake(boost::asio::ssl::stream_base::server, - boost::bind(&session::handle_handshake, this, - boost::asio::placeholders::error)); - } - -private: - void handle_read(const boost::system::error_code& error, - size_t bytes_transferred) - { - if (!error) - { -// std::cout<<"recieved: "<<data_<<"\n"; - if(strstr(data_, "restart vbox")) - { - FILE *f = popen("/sbin/runscript /etc/init.d/vbox_headles restart --nodeps","r"); - if(f != NULL) - { - char buf[128]; - while(fgets(buf, 128, f) != NULL) - ; //TODO: do something with output - int s = pclose(f); // TODO: handle exit status - } - else - ; //TODO: handle fail - } - else if(strstr(data_, "reboot now")) - { - FILE *f = popen("reboot","r"); - if(f != NULL) - { - char buf[128]; - while(fgets(buf, 128, f) != NULL) - ; //TODO: do something with output - int s = pclose(f); // TODO: handle exit status - } - else - ; //TODO: handle fail - } - else if(strstr(data_, "halt now")) - { - FILE *f = popen("halt","r"); - if(f != NULL) - { - char buf[128]; - while(fgets(buf, 128, f) != NULL) - ; //TODO: do something with output - int s = pclose(f); // TODO: handle exit status - } - else - ; //TODO: handle fail - } - else if(strstr(data_, "restart cups")) - { - FILE *f = popen("/sbin/runscript /etc/init.d/cupsd restart --nodeps","r"); - if(f != NULL) - { - char buf[128]; - while(fgets(buf, 128, f) != NULL) - ; //TODO: do something with output - int s = pclose(f); // TODO: handle exit status - } - else - ; //TODO: handle fail - } - else if(strstr(data_, "restart ppp")) - { - FILE *f = popen("/sbin/runscript /etc/init.d/net.ppp0 stop --nodeps","r"); - char buf[128]; - int s = 0; - if(f != NULL) - { - while(fgets(buf, 128, f) != NULL) - ; //TODO: do something with output - s = pclose(f); // TODO: handle exit status - } - else - ; //TODO: handle fail - sleep(3); - f = popen("killall pppd","r"); - if(f == NULL) - { - while(fgets(buf, 128, f) != NULL) - ; //TODO: do something with output - s = pclose(f); // TODO: handle exit status - } - else - ; //TODO: handle fail - sleep(1); - f = popen("/sbin/runscript /etc/init.d/net.ppp0 start --nodeps","r"); - if(f == NULL) - { - while(fgets(buf, 128, f) != NULL) - ; //TODO: do something with output - s = pclose(f); // TODO: handle exit status - } - else - ; //TODO: handle fail - } -/* boost::asio::async_write(socket_, - boost::asio::buffer(data_, bytes_transferred), - boost::bind(&session::handle_write, this, - boost::asio::placeholders::error)); */ - } - delete this; - } - -/* void handle_write(const boost::system::error_code& error) - { - if (!error) - { - socket_.async_read_some(boost::asio::buffer(data_, max_length), - boost::bind(&session::handle_read, this, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred)); - } - else - { - delete this; - } - }*/ - - ssl_socket socket_; - enum { max_length = 32 }; - char data_[max_length]; -}; - -class server -{ -public: -/* server(boost::asio::io_service& io_service, short port) - : io_service_(io_service), - acceptor_(io_service, tcp::endpoint(boost::asio::ip::address_v4::from_string("192.168.0.1"), port)), - context_(boost::asio::ssl::context::sslv23) */ - server(boost::asio::io_service& io_service, short port) - : io_service_(io_service), - acceptor_(io_service, tcp::endpoint(boost::asio::ip::address_v4(), port)), - context_(boost::asio::ssl::context::sslv23) - { - context_.set_options( - boost::asio::ssl::context::default_workarounds - | boost::asio::ssl::context::no_sslv2); - context_.set_password_callback(boost::bind(&server::get_password, this)); - context_.use_certificate_chain_file("/etc/restarter_server/serv.crt"); - context_.use_rsa_private_key_file("/etc/restarter_server/serv.key", boost::asio::ssl::context::pem); - context_.load_verify_file("/etc/restarter_server/ca.crt"); - context_.set_verify_mode(boost::asio::ssl::verify_peer | boost::asio::ssl::verify_client_once); - start_accept(); - } - -private: - void start_accept() - { - session* new_session = new session(io_service_, context_); - acceptor_.async_accept(new_session->socket(), - boost::bind(&server::handle_accept, this, new_session, - boost::asio::placeholders::error)); - } - std::string get_password() const - { - return ""; - } - - void handle_accept(session* new_session, - const boost::system::error_code& error) - { - if (!error) - { - new_session->start(); - } - else - { - delete new_session; - } - - start_accept(); - } - - boost::asio::io_service& io_service_; - boost::asio::ip::tcp::acceptor acceptor_; - boost::asio::ssl::context context_; -}; extern "C" void handle_term(int i) { @@ -249,13 +27,14 @@ extern "C" void handle_term(int i) exit(1); } + int main(int argc, char* argv[]) { - if(geteuid()) +/* if(geteuid()) //temporary disabled for debug { std::cout<<"Program must be runned with root privilegies\n"; exit(EXIT_FAILURE); - } + } */ { std::ifstream in_pid; in_pid.open("/var/run/restarter_server.pid"); @@ -275,7 +54,7 @@ int main(int argc, char* argv[]) } } } - pid_t pid; +/* pid_t pid; //temporary disabled for debug pid = fork(); if(pid < 0) { @@ -292,9 +71,11 @@ int main(int argc, char* argv[]) out<<pid<<"\n"; out.close(); exit(EXIT_SUCCESS); - } + } */ signal (SIGTERM, handle_term); + load_modules(); + try { @@ -310,4 +91,4 @@ int main(int argc, char* argv[]) } return 0; -}
\ No newline at end of file +} diff --git a/server/modules.cpp b/server/modules.cpp new file mode 100644 index 0000000..1f10b90 --- /dev/null +++ b/server/modules.cpp @@ -0,0 +1,50 @@ +// 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 "headers.h" + +std::list<service_info> installed_services; + +void load_modules(const char* path) +{ + boost::filesystem::path p (path); + typedef void (*svcs_ptr)(std::list<service_info>&); + typedef void (*init_ptr)(); + std::list<service_info> local_services; + for(boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator(p), end = boost::filesystem::directory_iterator(); i != end; ++i) + { + if(boost::filesystem::is_regular_file(i->path())) + { + init_ptr f = reinterpret_cast<init_ptr>(get_function(boost::filesystem::absolute(i->path()).generic_string().c_str(), "init")); + if(f) + f(); + local_services.clear(); + svcs_ptr svcs = reinterpret_cast<svcs_ptr>(get_function(boost::filesystem::absolute(i->path()).generic_string().c_str(), "get_services")); + if(svcs) + { + svcs(local_services); + if(!local_services.empty()) + installed_services.insert(installed_services.end(), local_services.begin(), local_services.end()); + } + } + } +} + +void load_modules() +{ + if(boost::filesystem::exists("./modules") && boost::filesystem::is_directory("./modules")) + load_modules("./modules"); +} diff --git a/server/modules.h b/server/modules.h new file mode 100644 index 0000000..e73415c --- /dev/null +++ b/server/modules.h @@ -0,0 +1,6 @@ +#ifndef MODULES_H +#define MODULES_H + +void load_modules(); + +#endif diff --git a/server/restarter_server.project b/server/restarter_server.project index f48e175..aa09d0c 100644 --- a/server/restarter_server.project +++ b/server/restarter_server.project @@ -9,7 +9,20 @@ <Dependencies/> <VirtualDirectory Name="src"> <File Name="main.cpp"/> + <File Name="api_service.h"/> + <File Name="service.cpp"/> + <File Name="headers.h"/> + <File Name="get_function.cpp"/> + <File Name="get_function.h"/> + <File Name="config.cpp"/> + <File Name="config.h"/> + <File Name="modules.cpp"/> + <File Name="modules.h"/> + <File Name="server.cpp"/> + <File Name="server.h"/> </VirtualDirectory> + <Dependencies Name="Debug"/> + <Dependencies Name="Release"/> <Settings Type="Executable"> <GlobalSettings> <Compiler Options="" C_Options=""> @@ -23,12 +36,16 @@ <Configuration Name="Debug" CompilerType="gnu g++" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append"> <Compiler Options="-g" C_Options="-g" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" UseDifferentPCHFlags="no" PCHFlags=""> <IncludePath Value="."/> + <IncludePath Value="../proto_lib"/> </Compiler> <Linker Options="" Required="yes"> + <LibraryPath Value="../proto_lib/Debug"/> <Library Value="boost_system"/> <Library Value="pthread"/> <Library Value="ssl"/> <Library Value="crypto"/> + <Library Value="boost_filesystem"/> + <Library Value="proto"/> </Linker> <ResourceCompiler Options="" Required="no"/> <General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes"/> @@ -55,10 +72,12 @@ <CustomPostBuild/> <CustomPreBuild/> </AdditionalRules> - <Completion> + <Completion EnableCpp11="yes"> + <ClangCmpFlagsC/> <ClangCmpFlags/> <ClangPP/> - <SearchPaths/> + <SearchPaths>/usr/include +/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include</SearchPaths> </Completion> </Configuration> <Configuration Name="Release" CompilerType="gnu g++" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append"> @@ -74,7 +93,8 @@ <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[]]> + <![CDATA[ + ]]> </Environment> <Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath=""> <PostConnectCommands/> @@ -96,7 +116,8 @@ <CustomPostBuild/> <CustomPreBuild/> </AdditionalRules> - <Completion> + <Completion EnableCpp11="no"> + <ClangCmpFlagsC/> <ClangCmpFlags/> <ClangPP/> <SearchPaths/> diff --git a/server/server.cpp b/server/server.cpp new file mode 100644 index 0000000..bdd2cfb --- /dev/null +++ b/server/server.cpp @@ -0,0 +1,129 @@ +// 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 "headers.h" + + +void session::handle_handshake(const boost::system::error_code& error) +{ + if (!error) + { + socket_.async_read_some(boost::asio::buffer(data_, max_length), boost::bind(&session::handle_read, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); + } + else + { + delete this; + } +} + +void session::handle_read(const boost::system::error_code& error, size_t bytes_transferred) +{ + if (!error) + { +// std::cout<<"recieved: "<<data_<<"\n"; + if(strstr(data_, "restart vbox")) + { + FILE *f = popen("/sbin/runscript /etc/init.d/vbox_headles restart --nodeps","r"); + if(f != NULL) + { + char buf[128]; + while(fgets(buf, 128, f) != NULL) + ; //TODO: do something with output + int s = pclose(f); // TODO: handle exit status + } + else + ; //TODO: handle fail + } + else if(strstr(data_, "reboot now")) + { + FILE *f = popen("reboot","r"); + if(f != NULL) + { + char buf[128]; + while(fgets(buf, 128, f) != NULL) + ; //TODO: do something with output + int s = pclose(f); // TODO: handle exit status + } + else + ; //TODO: handle fail + } + else if(strstr(data_, "halt now")) + { + FILE *f = popen("halt","r"); + if(f != NULL) + { + char buf[128]; + while(fgets(buf, 128, f) != NULL) + ; //TODO: do something with output + int s = pclose(f); // TODO: handle exit status + } + else + ; //TODO: handle fail + } + else if(strstr(data_, "restart cups")) + { + FILE *f = popen("/sbin/runscript /etc/init.d/cupsd restart --nodeps","r"); + if(f != NULL) + { + char buf[128]; + while(fgets(buf, 128, f) != NULL) + ; //TODO: do something with output + int s = pclose(f); // TODO: handle exit status + } + else + ; //TODO: handle fail + } + else if(strstr(data_, "restart ppp")) + { + FILE *f = popen("/sbin/runscript /etc/init.d/net.ppp0 stop --nodeps","r"); + char buf[128]; + int s = 0; + if(f != NULL) + { + while(fgets(buf, 128, f) != NULL) + ; //TODO: do something with output + s = pclose(f); // TODO: handle exit status + } + else + ; //TODO: handle fail + sleep(3); + f = popen("killall pppd","r"); + if(f == NULL) + { + while(fgets(buf, 128, f) != NULL) + ; //TODO: do something with output + s = pclose(f); // TODO: handle exit status + } + else + ; //TODO: handle fail + sleep(1); + f = popen("/sbin/runscript /etc/init.d/net.ppp0 start --nodeps","r"); + if(f == NULL) + { + while(fgets(buf, 128, f) != NULL) + ; //TODO: do something with output + s = pclose(f); // TODO: handle exit status + } + else + ; //TODO: handle fail + } +/* boost::asio::async_write(socket_, + boost::asio::buffer(data_, bytes_transferred), + boost::bind(&session::handle_write, this, + boost::asio::placeholders::error)); */ + } + delete this; +} diff --git a/server/server.h b/server/server.h new file mode 100644 index 0000000..c9028d3 --- /dev/null +++ b/server/server.h @@ -0,0 +1,118 @@ +// 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. + +#ifndef SERVER_H +#define SERVER_H + +#include "headers.h" + +using boost::asio::ip::tcp; +typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> ssl_socket; + + +class session +{ +public: + session(boost::asio::io_service& io_service, boost::asio::ssl::context& context) : socket_(io_service, context) + {} + + ssl_socket::lowest_layer_type& socket() + { + return socket_.lowest_layer(); + } + void handle_handshake(const boost::system::error_code& error); + + void start() + { + socket_.async_handshake(boost::asio::ssl::stream_base::server, boost::bind(&session::handle_handshake, this, boost::asio::placeholders::error)); + } + +private: + void handle_read(const boost::system::error_code& error, size_t bytes_transferred); + +/* void handle_write(const boost::system::error_code& error) + { + if (!error) + { + socket_.async_read_some(boost::asio::buffer(data_, max_length), + boost::bind(&session::handle_read, this, + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred)); + } + else + { + delete this; + } + }*/ + + ssl_socket socket_; + enum { max_length = 128 }; + char data_[max_length]; +}; + +class server +{ +public: + server(boost::asio::io_service& io_service, short port) + : io_service_(io_service), + acceptor_(io_service, tcp::endpoint(boost::asio::ip::address_v4(), port)), + context_(boost::asio::ssl::context::sslv23) + { + context_.set_options( + boost::asio::ssl::context::default_workarounds + | boost::asio::ssl::context::no_sslv2); + context_.set_password_callback(boost::bind(&server::get_password, this)); + context_.use_certificate_chain_file("/etc/restarter_server/serv.crt"); + context_.use_rsa_private_key_file("/etc/restarter_server/serv.key", boost::asio::ssl::context::pem); + context_.load_verify_file("/etc/restarter_server/ca.crt"); + context_.set_verify_mode(boost::asio::ssl::verify_peer | boost::asio::ssl::verify_client_once); + start_accept(); + } + +private: + void start_accept() + { + session* new_session = new session(io_service_, context_); + acceptor_.async_accept(new_session->socket(), + boost::bind(&server::handle_accept, this, new_session, + boost::asio::placeholders::error)); + } + std::string get_password() const + { + return ""; + } + + void handle_accept(session* new_session, + const boost::system::error_code& error) + { + if (!error) + { + new_session->start(); + } + else + { + delete new_session; + } + + start_accept(); + } + + boost::asio::io_service& io_service_; + boost::asio::ip::tcp::acceptor acceptor_; + boost::asio::ssl::context context_; +}; + +#endif diff --git a/server/service.cpp b/server/service.cpp new file mode 100644 index 0000000..ab9d7a1 --- /dev/null +++ b/server/service.cpp @@ -0,0 +1,16 @@ +// 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. + 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> |