debut SQLmanager
This commit is contained in:
parent
180561618b
commit
f6dbdc9fc3
@ -22,6 +22,7 @@ BashModule::BashModule()
|
|||||||
//private methods
|
//private methods
|
||||||
int BashModule::executeScript(string serviceUsername, string script)
|
int BashModule::executeScript(string serviceUsername, string script)
|
||||||
{
|
{
|
||||||
|
cout << "debut execute script" <<endl;
|
||||||
//this method is called in deploy() and remove(), it executes the script if it exists
|
//this method is called in deploy() and remove(), it executes the script if it exists
|
||||||
if(!filesystem::exists(script)){
|
if(!filesystem::exists(script)){
|
||||||
cout << "No deploy.sh script for this service.";
|
cout << "No deploy.sh script for this service.";
|
||||||
@ -64,6 +65,7 @@ int BashModule::executeScriptAs(string serviceUsername, string script)
|
|||||||
{
|
{
|
||||||
//this method is called in deploy(), it executes the script if it exists, as the user associated with the service
|
//this method is called in deploy(), it executes the script if it exists, as the user associated with the service
|
||||||
//check that the file exists
|
//check that the file exists
|
||||||
|
cout << "debut ex script as"<<endl;
|
||||||
if(!filesystem::exists(script)){
|
if(!filesystem::exists(script)){
|
||||||
cout << "No deploy_user.sh script for this service.";
|
cout << "No deploy_user.sh script for this service.";
|
||||||
return 0;
|
return 0;
|
||||||
@ -87,6 +89,7 @@ int BashModule::executeScriptAs(string serviceUsername, string script)
|
|||||||
return -1;
|
return -1;
|
||||||
}else{
|
}else{
|
||||||
//executing the script in a separate process
|
//executing the script in a separate process
|
||||||
|
cout << "avant le fork "<<endl;
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid == -1) {
|
if (pid == -1) {
|
||||||
cerr << "Error when forking." << endl;
|
cerr << "Error when forking." << endl;
|
||||||
|
@ -13,7 +13,7 @@ $(EXE) : $(OBJECTS)
|
|||||||
$(ECHO) "-Linking $(EXE)-"
|
$(ECHO) "-Linking $(EXE)-"
|
||||||
$(GCC) -o $@ $^ $(LIBRARIES)
|
$(GCC) -o $@ $^ $(LIBRARIES)
|
||||||
$(CP) $(EXE) ../testenv
|
$(CP) $(EXE) ../testenv
|
||||||
|
$(CP) $(EXE) ../bin
|
||||||
$(BIN)/%.o:%.cpp
|
$(BIN)/%.o:%.cpp
|
||||||
$(ECHO) "-Compilation $<- "
|
$(ECHO) "-Compilation $<- "
|
||||||
$(GCC) $(CCFLAGS) -o $@ $<
|
$(GCC) $(CCFLAGS) -o $@ $<
|
||||||
|
@ -13,4 +13,4 @@ NginxModule nginxModule=NginxModule();
|
|||||||
WireguardModule wireguardModule=WireguardModule();
|
WireguardModule wireguardModule=WireguardModule();
|
||||||
EncryptionModule encryptionModule=EncryptionModule();
|
EncryptionModule encryptionModule=EncryptionModule();
|
||||||
|
|
||||||
vector <Module *> modules={&bashModule,&nginxModule,&wireguardModule, &encryptionModule}; //&dockerModule
|
vector <Module *> modules={&bashModule,&wireguardModule, &encryptionModule}; //&dockerModule,&nginxModule
|
39
src/SQLmanager.cpp
Normal file
39
src/SQLmanager.cpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
//deployer SLmanager implementation
|
||||||
|
// Copyright (C) 2024 Jean-Cloud
|
||||||
|
// GNU General Public License v3
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <cstring>
|
||||||
|
#include <vector>
|
||||||
|
#include <list>
|
||||||
|
#include "Service.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
//constructor and destructor inlin
|
||||||
|
|
||||||
|
//services
|
||||||
|
vector<Service> GetServices() const;
|
||||||
|
const Service * FindServiceByUsername(string aUsername) const;
|
||||||
|
const Service * FindServiceByID(int aUserID) const;
|
||||||
|
//list<const Service*> FindServicesByServer(string aServer) const;
|
||||||
|
int isServiceOnServer(string serviceUsername);
|
||||||
|
|
||||||
|
vector <Service> services;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//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
|
||||||
|
// {
|
||||||
|
// string cmd ="getent hosts " +serviceUsername;
|
||||||
|
// string result = BashManager::ExecuteAndReadResult(cmd);
|
||||||
|
// if(result.find("::1")!=string::npos){ //if result contains "::1" which is the notation for loopback in IpV6
|
||||||
|
// cout << "service " << serviceUsername << " on server" << endl;
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
// cout << "service" << serviceUsername << " not on server" << endl;
|
||||||
|
// return 1;
|
||||||
|
// return 0;
|
||||||
|
// }
|
30
src/SQLmanager.h
Normal file
30
src/SQLmanager.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
//deployer SLmanager header
|
||||||
|
// Copyright (C) 2024 Jean-Cloud
|
||||||
|
// GNU General Public License v3
|
||||||
|
|
||||||
|
#if !defined(SQLMANAGER_H)
|
||||||
|
#define SQLMANAGER_H
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <cstring>
|
||||||
|
#include <vector>
|
||||||
|
#include <list>
|
||||||
|
#include "Service.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class SQLmanager {
|
||||||
|
public:
|
||||||
|
SQLmanager(){}
|
||||||
|
~SQLmanager(){}
|
||||||
|
//services
|
||||||
|
vector<Service> GetServices() const;
|
||||||
|
const Service * FindServiceByUsername(string aUsername) const;
|
||||||
|
const Service * FindServiceByID(int aUserID) const;
|
||||||
|
//list<const Service*> FindServicesByServer(string aServer) const;
|
||||||
|
int isServiceOnServer(string serviceUsername);
|
||||||
|
|
||||||
|
private:
|
||||||
|
vector <Service> services;
|
||||||
|
};
|
||||||
|
#endif
|
BIN
src/deployer
Executable file
BIN
src/deployer
Executable file
Binary file not shown.
BIN
src/general.db
Normal file
BIN
src/general.db
Normal file
Binary file not shown.
21
src/main.cpp
21
src/main.cpp
@ -21,20 +21,7 @@ void help(char * argv0)
|
|||||||
cout << "usage: ./" << argv0 <<"action file \n with action=deploy or remove and file=path to a file or all. \n" << endl;
|
cout << "usage: ./" << argv0 <<"action file \n with action=deploy or remove and file=path to a file or all. \n" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
|
||||||
{
|
|
||||||
string cmd ="getent hosts " +serviceUsername;
|
|
||||||
string result = BashManager::ExecuteAndReadResult(cmd);
|
|
||||||
if(result.find("::1")!=string::npos){ //if result contains "::1" which is the notation for loopback in IpV6
|
|
||||||
cout << "service " << serviceUsername << " on server" << endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
cout << "service" << serviceUsername << " not on server" << endl;
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int createUser(string serviceUsername)
|
int createUser(string serviceUsername)
|
||||||
{
|
{
|
||||||
@ -44,6 +31,7 @@ int createUser(string serviceUsername)
|
|||||||
Services services = Services();
|
Services services = Services();
|
||||||
const Service * service = services.FindByUsername(serviceUsername);
|
const Service * service = services.FindByUsername(serviceUsername);
|
||||||
int uid = (*service).GetUserID()+uidStart;
|
int uid = (*service).GetUserID()+uidStart;
|
||||||
|
cout << "uid vaut" << uid << endl;
|
||||||
//test if user already exists
|
//test if user already exists
|
||||||
string cmd = "id -u "+serviceUsername;
|
string cmd = "id -u "+serviceUsername;
|
||||||
string res = BashManager::ExecuteAndReadResult (cmd);
|
string res = BashManager::ExecuteAndReadResult (cmd);
|
||||||
@ -60,6 +48,7 @@ int createUser(string serviceUsername)
|
|||||||
cerr << res2 << endl;
|
cerr << res2 << endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
cout << "user created " << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,14 +244,13 @@ int deployService(string serviceUsername){
|
|||||||
|
|
||||||
for(Module * mod_ptr : modules){
|
for(Module * mod_ptr : modules){
|
||||||
int modResult = (*mod_ptr).Deploy(serviceUsername);
|
int modResult = (*mod_ptr).Deploy(serviceUsername);
|
||||||
|
|
||||||
if (modResult!=0){
|
if (modResult!=0){
|
||||||
//cerr << "Error in " << (*mod_ptr) << " when deploying " << serviceUsername << endl;
|
//cerr << "Error in " << (*mod_ptr) << " when deploying " << serviceUsername << endl;
|
||||||
cerr << "Error in module " << endl;
|
cerr << "Error in module " << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
cerr << "Error creating user and environment of "<<serviceUsername << endl;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -274,6 +262,7 @@ int deployAll()
|
|||||||
createEnv();
|
createEnv();
|
||||||
//initializing modules
|
//initializing modules
|
||||||
for(Module * mod_ptr : modules){
|
for(Module * mod_ptr : modules){
|
||||||
|
cout << *mod_ptr << endl;
|
||||||
int modPrep = (*mod_ptr).Prepare();
|
int modPrep = (*mod_ptr).Prepare();
|
||||||
int modClean = (*mod_ptr).Clean();
|
int modClean = (*mod_ptr).Clean();
|
||||||
if ((modPrep && modClean) !=0){
|
if ((modPrep && modClean) !=0){
|
||||||
|
Loading…
Reference in New Issue
Block a user