diff --git a/doc/SQL_tables_scheme.png b/doc/SQL_tables_scheme.png new file mode 100644 index 0000000..4f48a7c Binary files /dev/null and b/doc/SQL_tables_scheme.png differ diff --git a/src/SQLmanager.cpp b/src/SQLmanager.cpp index f61d1dc..3661818 100644 --- a/src/SQLmanager.cpp +++ b/src/SQLmanager.cpp @@ -9,24 +9,55 @@ #include #include #include +#include #include "Service.h" #include "SQLmanager.h" using namespace std; +//private methods +int callback(void * data, int argc, char **argv, char **azColName) { + int userID = stoi(argv[0]); + string serviceName = argv[1]; + string serveur=argv[2]; + string ip=argv[3]; + //extract the IPs as integers + stringstream ss(ip); + string nb; + while (getline(ss,nb,',')){ + stoi(nb); + } + + + cout << userID << serviceName << serveur << ip << endl; + //create a data structure to store servers + return 0; +} + //constructor SQLmanager::SQLmanager() { - sqlite3 *db; - char *zErrMsg = 0; + sqlite3 *db; int rc; - - rc = sqlite3_open("test.db", &db); - + int res; + char* errMess=0; + const char * data="Callback function called"; + rc=sqlite3_open("general.db", &db); + //CAREFUL: enable FK constraints? or not cause just reading? if(rc) { cerr << "Error. Database cannot be opened." << endl << sqlite3_errmsg(db) << endl; } else { cout << "Database opened" << endl; + //change this to get the info to create both the service and the server + string query="SELECT services.id,services.name,servers.name,GROUP_CONCAT(CASE WHEN IPs.value IS NOT NULL THEN IPs.value END) FROM services JOIN servers_services ON services.name = servers_services.name_service JOIN servers ON servers.name = servers_services.name_server CROSS JOIN json_each(servers.IPs) AS IPs GROUP BY services.id, services.name, servers.name;"; + res = sqlite3_exec(db, query.c_str(), callback, (void*)data, &errMess); + if( res != SQLITE_OK ) { + cout << errMess << endl; + sqlite3_free(errMess); + } else { + cout << "Data extracted from database." << endl; + } + } sqlite3_close(db); } @@ -55,6 +86,7 @@ int SQLmanager::isServiceOnServer(string serviceUsername) + //int isServiceOnServer(string serviceUsername) //this method tests if a certain service is on the current server //it looks into the /etc/hosts file thanks to a pipe to a separate bash process diff --git a/src/SQLmanager.h b/src/SQLmanager.h index 10602ff..5b9faf7 100644 --- a/src/SQLmanager.h +++ b/src/SQLmanager.h @@ -10,6 +10,7 @@ #include #include #include "Service.h" +#include "Server.h" using namespace std; @@ -26,5 +27,6 @@ class SQLmanager { private: vector services; + vector servers; }; #endif \ No newline at end of file diff --git a/src/Server.cpp b/src/Server.cpp new file mode 100644 index 0000000..1d0203d --- /dev/null +++ b/src/Server.cpp @@ -0,0 +1,5 @@ +//deployer Server implementation +// Copyright (C) 2024 Jean-Cloud +// GNU General Public License v3 + +#include "Server.h" diff --git a/src/Server.h b/src/Server.h new file mode 100644 index 0000000..d33145a --- /dev/null +++ b/src/Server.h @@ -0,0 +1,26 @@ +//deployer Server header +// Copyright (C) 2024 Jean-Cloud +// GNU General Public License v3 + +#if !defined(SERVER_H) +#define SERVER_H + +#include +#include +using namespace std; + +class Server{ + public: + Server(int anID,string aName,string aLocation,string anISP,string aNotes,string aWg_pubkey,list anIPs):ID(anID),name(aName),location(aLocation),ISP(anISP),notes(aNotes),wg_pubkey(aWg_pubkey),IPs(anIPs){}; + ~Server(){} + + private: + int ID; + string name; + string location; + string ISP; + string notes; + string wg_pubkey; + list IPs; +}; +#endif \ No newline at end of file diff --git a/src/general.db b/src/general.db index 115aba5..60bf608 100644 Binary files a/src/general.db and b/src/general.db differ diff --git a/src/testSQL.cpp b/src/testSQL.cpp new file mode 100644 index 0000000..3f93488 --- /dev/null +++ b/src/testSQL.cpp @@ -0,0 +1,8 @@ + +#include "SQLmanager.h" +#include "Service.h" + +int main(){ + SQLmanager manager = SQLmanager(); + +} \ No newline at end of file diff --git a/testenv/services/test.sh8s.sh/.env b/testenv/services/test.sh8s.sh/.env index 356f9a9..8b597ac 100644 --- a/testenv/services/test.sh8s.sh/.env +++ b/testenv/services/test.sh8s.sh/.env @@ -1 +1,9 @@ -GIT_SOURCE_REPO=https://git.jean-cloud.net/adrian/velov +http_dir=/srv/http/test.sh8s.sh +data_dir=/data/test.sh8s.sh +secret_dir=/data/secrets/test.sh8s.sh +docker_dir=/services/test.sh8s.sh +jc_service=test.sh8s.sh +home=/data/test.sh8s.sh +jc_id=2001 +net=172.29.2001 +jc_cert=/etc/letsencrypt/live/dummy diff --git a/testenv/services/test.sh8s.sh/nginx_server2.conf b/testenv/services/test.sh8s.sh/nginx_server2.conf new file mode 100644 index 0000000..34303bb --- /dev/null +++ b/testenv/services/test.sh8s.sh/nginx_server2.conf @@ -0,0 +1,25 @@ +server { + listen 443 ssl http2; + listen [::]:443 ssl http2; + ssl_certificate /fullchain.pem; + ssl_certificate_key /privkey.pem; + server_name velov.jean-cloud.net www.velov.jean-cloud.net; + root ; + + index index.php; + + location / { + try_files / =404; + } + + location ~ \.php$ { + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass .100:9000; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME /usr/src/app/; + #fastcgi_param SCRIPT_FILENAME /usr/src/app/index.php; + fastcgi_param PATH_INFO ; + } +} +