From: HelenMamontova <44774239+HelenMamontova@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:53:46 +0000 (+0200) Subject: Stargazer (#6) X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/ebd170a764ab9660adee464588cda1801c7986b4?ds=sidebyside Stargazer (#6) * Radius. Block if (BUILD_MOD_RADIUS) added. * Radius. Catalog radius with radius.h and radius.cpp files added. * Declaration of methods GetVersion, SendMessage, SetUsers, Start added. * Definition of method SendMessage added. * The option for BUILD_MOD_RADIUS added. * Header files , , added. Virtual methods Start, Stop declaration added. Private methods AddUser, DelUser, GetUser, UpdateUserAuthorization added. Class member variable errorStr, users, userList, isRunning, m_conns, m_onAddUserConn, m_onDelUserConn added. * Header files , "stg/user.h" added. Overriding virtual methods Start, Stop added. * Private methods SetUserNotifiers, UnSetUserNotifiers declaration added. * Header file added. Definition methods GetUser, AddUser, DelUser, UpdateUserAuthorization added. * Unnecessary block private removed. Unnecessary header files removed. * Unnecessary methods removed. Unnecessary header files removed. * Overriding virtual methods Start, Stop, Reload, IsRunning, ParseSettings, GetStrErroor, GetStartPosition, GetStopPosition, SendMessage added. Class member variable errorStr, isRunning added. * Definition of methods Start, Stop, SendMessage removed. * Header file added. The functions PrintHelp, PrintVersion added. Parsing command line parameters added. The parameter of function settings when it call changed. * Radius. Variable bool noDaemon added. Parameter -f/--f added to parsing command line. The call of function ForkAndWait changed - it is called if the variable noDaemon is false. * Radius. Command line parameter 'path' value fixed in the function PrintHelp. Parsing command line parameters fixed. The key -f/--foreground added to parsing command line parameters. * Radius. Return value in the function GetVersion changed. * Radius. Unnecessary check 'argc = i + 2' removed from parsing command line parameters. * The macro NO_DAEMON removed. The logic driven by the macro changed to command line argument f analysis. * Radius. The check variable noDaemon added when create function call. * Radius. The variable startFile definition moved to block if(!noDaemon) in main function. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index e887fc58..1b039a00 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ option ( BUILD_SGAUTH "Build SGAuth client." OFF ) # General modules option ( BUILD_MOD_AO "Build AlwaysOnline STG module." ON ) +option ( BUILD_MOD_RADIUS "Build Radius STG module." ON ) option ( BUILD_MOD_IA "Buils InetAccess STG module." ON ) option ( BUILD_MOD_SGCONFIG "Build SGConfig STG module." ON ) option ( BUILD_MOD_PING "Build Ping STG module." ON ) diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index ee14c3a8..acc826f7 100644 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@ -41,6 +41,7 @@ #include #include +#include #include #include #include @@ -55,10 +56,6 @@ #include // S_IRUSR #include // create -#ifdef DEBUG - #define NO_DAEMON (1) -#endif - #define START_FILE "/._ST_ART_ED_" using STG::SettingsImpl; @@ -155,13 +152,8 @@ int StartScriptExecuter(char*, int msgKey, int* msgID) return 0; } //----------------------------------------------------------------------------- -#ifndef NO_DAEMON int ForkAndWait(const std::string& confDir) -#else -int ForkAndWait(const std::string&) -#endif { -#ifndef NO_DAEMON const auto pid = fork(); const auto startFile = confDir + START_FILE; unlink(startFile.c_str()); @@ -194,9 +186,9 @@ int ForkAndWait(const std::string&) exit(1); break; } -#endif return 0; } + //----------------------------------------------------------------------------- void KillExecuters() { @@ -208,6 +200,21 @@ void KillExecuters() ++pid; } } + +void PrintHelp(const std::string& programName) +{ + std::cout << "Usage: " << programName << "[-h/--help] [-v/--version] [-f/--foreground] []\n" + << "\t --help, -h - print this help;\n" + << "\t --version, -v - print version;\n" + << "\t --foreground, -f - do not go into background;\n" + << "\t - path to the directory where the configuration file is located.\n"; +} + +void PrintVersion(const std::string& programName) +{ + std::cout << programName << "\n" + << "Stargazer version" << " " << SERVER_VERSION << "\n"; +} //----------------------------------------------------------------------------- } // namespace anonymous //----------------------------------------------------------------------------- @@ -223,7 +230,34 @@ int main(int argc, char* argv[]) return 1; } - SettingsImpl settings(argc == 2 ? argv[1] : ""); + std::string path; + bool noDaemon(false); + + if (argc == 1) + path = ""; + else + { + for (int i = 1; i < argc; ++i) + { + const std::string arg(argv[i]); + if (arg == "--help" || arg == "-h") + { + PrintHelp(argv[0]); + return 0; + } + if (arg == "--version" || arg == "-v") + { + PrintVersion(argv[0]); + return 0; + } + if (arg == "--foreground" || arg == "-f") + noDaemon = true; + else + path = arg; + } + } + + SettingsImpl settings(path); if (settings.ReadSettings()) { @@ -236,14 +270,13 @@ int main(int argc, char* argv[]) return -1; } -#ifndef NO_DAEMON - const auto startFile = settings.GetConfDir() + START_FILE; -#endif - - if (ForkAndWait(settings.GetConfDir()) < 0) + if (!noDaemon) { - STG::Logger::get()("Fork error!"); - return -1; + if (ForkAndWait(settings.GetConfDir()) < 0) + { + STG::Logger::get()("Fork error!"); + return -1; + } } auto& WriteServLog = STG::Logger::get(); @@ -321,9 +354,11 @@ int main(int argc, char* argv[]) WriteServLog("Stg started successfully."); WriteServLog("+++++++++++++++++++++++++++++++++++++++++++++"); -#ifndef NO_DAEMON - creat(startFile.c_str(), S_IRUSR); -#endif + if (!noDaemon) + { + const auto startFile = settings.GetConfDir() + START_FILE; + creat(startFile.c_str(), S_IRUSR); + } bool running = true; while (running) diff --git a/projects/stargazer/plugins/CMakeLists.txt b/projects/stargazer/plugins/CMakeLists.txt index fc378ba6..40e18dec 100644 --- a/projects/stargazer/plugins/CMakeLists.txt +++ b/projects/stargazer/plugins/CMakeLists.txt @@ -11,6 +11,19 @@ if ( BUILD_MOD_AO ) endif () endif ( BUILD_MOD_AO ) +if ( BUILD_MOD_RADIUS ) + add_library ( mod_radius MODULE other/radius/radius.cpp ) + target_link_libraries ( mod_radius scriptexecuter logger common ) + set_target_properties ( mod_radius PROPERTIES PREFIX "" ) + + if ( CLANG_TIDY_EXE ) + set_target_properties ( mod_radius PROPERTIES CXX_CLANG_TIDY "${DO_CLANG_TIDY}" ) + endif () + if ( INCLUDE_WHAT_YOU_USE_EXE ) + set_target_properties ( mod_radius PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "${DO_INCLUDE_WHAT_YOU_USE}" ) + endif () +endif ( BUILD_MOD_RADIUS ) + if ( BUILD_MOD_IA ) add_library ( mod_auth_ia MODULE authorization/inetaccess/inetaccess.cpp ) target_link_libraries ( mod_auth_ia scriptexecuter crypto logger common ) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp new file mode 100644 index 00000000..3ec0f705 --- /dev/null +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -0,0 +1,19 @@ +#include "radius.h" + +using STG::RADIUS; + +extern "C" STG::Plugin* GetPlugin() +{ + static RADIUS plugin; + return &plugin; +} + +std::string RADIUS::GetVersion() const +{ + return "Radius v.1.0"; +} + +RADIUS::RADIUS() +{ +} + diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h new file mode 100644 index 00000000..4cc84e26 --- /dev/null +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -0,0 +1,30 @@ +#pragma once + +#include "stg/auth.h" +#include + +namespace STG +{ + class RADIUS : public Auth + { + public: + RADIUS(); + + int Start() override { return 0; } + int Stop() override { return 0; } + int Reload(const ModuleSettings & /*ms*/) override { return 0; } + bool IsRunning() override { return isRunning; } + int ParseSettings() override { return 0; } + const std::string & GetStrError() const override { return errorStr; } + std::string GetVersion() const override; + uint16_t GetStartPosition() const override { return 0; } + uint16_t GetStopPosition() const override { return 0; } + + int SendMessage(const Message & msg, uint32_t ip) const override { return 0; } + + private: + mutable std::string errorStr; + bool isRunning; + + }; +}