avancee sqlite
This commit is contained in:
parent
bc12dc6020
commit
a694abf874
BIN
doc/SQL_tables_scheme.png
Normal file
BIN
doc/SQL_tables_scheme.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 195 KiB |
@ -9,24 +9,55 @@
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <sqlite3.h>
|
||||
#include <sstream>
|
||||
#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
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include "Service.h"
|
||||
#include "Server.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -26,5 +27,6 @@ class SQLmanager {
|
||||
|
||||
private:
|
||||
vector <Service> services;
|
||||
vector <Server> servers;
|
||||
};
|
||||
#endif
|
5
src/Server.cpp
Normal file
5
src/Server.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
//deployer Server implementation
|
||||
// Copyright (C) 2024 Jean-Cloud
|
||||
// GNU General Public License v3
|
||||
|
||||
#include "Server.h"
|
26
src/Server.h
Normal file
26
src/Server.h
Normal file
@ -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 <string>
|
||||
#include <list>
|
||||
using namespace std;
|
||||
|
||||
class Server{
|
||||
public:
|
||||
Server(int anID,string aName,string aLocation,string anISP,string aNotes,string aWg_pubkey,list<int> 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 <int> IPs;
|
||||
};
|
||||
#endif
|
BIN
src/general.db
BIN
src/general.db
Binary file not shown.
8
src/testSQL.cpp
Normal file
8
src/testSQL.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
#include "SQLmanager.h"
|
||||
#include "Service.h"
|
||||
|
||||
int main(){
|
||||
SQLmanager manager = SQLmanager();
|
||||
|
||||
}
|
@ -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
|
||||
|
25
testenv/services/test.sh8s.sh/nginx_server2.conf
Normal file
25
testenv/services/test.sh8s.sh/nginx_server2.conf
Normal file
@ -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 ;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user