From 0e07a65d8c7f0cfcd831f3fd44623a8ae3fc5597 Mon Sep 17 00:00:00 2001 From: TolaMironcenko Date: Wed, 3 Jul 2024 10:06:58 +0700 Subject: [PATCH] syslog added --- src/auth_service.cpp | 6 ++++-- src/users/add_user.cpp | 5 ++++- src/users/change_password.cpp | 4 ++++ src/users/change_user.cpp | 4 ++++ src/users/delete_user.cpp | 4 ++++ src/web/js/routes.js | 2 +- 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/auth_service.cpp b/src/auth_service.cpp index a64d27a..a630c8c 100644 --- a/src/auth_service.cpp +++ b/src/auth_service.cpp @@ -4,6 +4,7 @@ #include "auth/auth.hpp" #include "users/users.hpp" #include "colors.h" +#include #define CORS_ENABLE @@ -28,7 +29,8 @@ int main() { srv.set_mount_point("/auth/css", "../src/web/css"); std::cout << GREEN << "Starting" << RESET << " server on [ " << YELLOW - << "localhost" << RESET << ":" << CYAN << "43243" << RESET << " ]" << std::endl; - srv.listen("localhost", 43243); + << "0.0.0.0" << RESET << ":" << CYAN << "43243" << RESET << " ]" << std::endl; + syslog(LOG_INFO, "Authorization service started"); + srv.listen("0.0.0.0", 43243); return 0; } diff --git a/src/users/add_user.cpp b/src/users/add_user.cpp index 5fe818c..e24feed 100644 --- a/src/users/add_user.cpp +++ b/src/users/add_user.cpp @@ -3,6 +3,7 @@ #include "../includes.hpp" #include "../auth/auth.hpp" #include +#include #define ALPHABET "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" @@ -96,6 +97,8 @@ void add_user(const httplib::Request &request, httplib::Response &response) { std::ofstream usersfilew("users.json"); usersfilew << all_users.dump(4); usersfilew.close(); - + std::stringstream syslogstring; + syslogstring << "user added [" << username << "]"; + syslog(LOG_INFO, syslogstring.str().c_str()); response.set_content(R"({"status":"ok"})", JSON_TYPE); } diff --git a/src/users/change_password.cpp b/src/users/change_password.cpp index b14ca72..40ee6ee 100644 --- a/src/users/change_password.cpp +++ b/src/users/change_password.cpp @@ -3,6 +3,7 @@ #include "../includes.hpp" #include "../auth/auth.hpp" #include +#include // functtion for change password for user void change_password(const httplib::Request &request, httplib::Response &response) { @@ -81,6 +82,9 @@ void change_password(const httplib::Request &request, httplib::Response &respons if ((all_user["id"] == changepassuserid)) { all_user["password"] = new_password; found = true; + std::stringstream syslogstring; + syslogstring << "password changed for user [" << all_user["username"] << "]"; + syslog(LOG_INFO, syslogstring.str().c_str()); break; } } diff --git a/src/users/change_user.cpp b/src/users/change_user.cpp index 3b80e85..bd47d51 100644 --- a/src/users/change_user.cpp +++ b/src/users/change_user.cpp @@ -3,6 +3,7 @@ #include "../includes.hpp" #include "../auth/auth.hpp" #include +#include // function for change user data void change_user(const httplib::Request &request, httplib::Response &response) { @@ -73,6 +74,9 @@ void change_user(const httplib::Request &request, httplib::Response &response) { if (json_body["group"] != nullptr) { all_user["group"] = json_body["group"]; } if (json_body["is_superuser"] != nullptr) { all_user["is_superuser"] = json_body["is_superuser"]; } found = true; + std::stringstream syslogstring; + syslogstring << "userdata changed for user [" << all_user["username"] << "]"; + syslog(LOG_INFO, syslogstring.str().c_str()); break; } } diff --git a/src/users/delete_user.cpp b/src/users/delete_user.cpp index 35bfe7b..b46d741 100644 --- a/src/users/delete_user.cpp +++ b/src/users/delete_user.cpp @@ -3,6 +3,7 @@ #include "../includes.hpp" #include "../auth/auth.hpp" #include +#include // function for delete user void delete_user(const httplib::Request &request, httplib::Response &response) { @@ -62,6 +63,9 @@ void delete_user(const httplib::Request &request, httplib::Response &response) { if (all_users[i]["id"] == deluserid) { all_users.erase(i); found = true; + std::stringstream syslogstring; + syslogstring << "user deleted [" << all_users[i]["username"] << "]"; + syslog(LOG_INFO, syslogstring.str().c_str()); break; } } diff --git a/src/web/js/routes.js b/src/web/js/routes.js index 2e42d5b..ed4c779 100644 --- a/src/web/js/routes.js +++ b/src/web/js/routes.js @@ -1,4 +1,4 @@ -const host = 'http://localhost:43243' +const host = 'http://192.168.122.76:43243' const prefix = 'api' const routes = {