Commit a51fe742 authored by mr-ti's avatar mr-ti
Browse files

No commit message

No commit message
parent 5669edee
......@@ -16,6 +16,9 @@
#include <regex.h>
#include <unicomctrl/cuniobj.h>
using namespace unicomctrl;
using namespace std;
class CRegex : public CUniObj{
public:
typedef enum State{
......
......@@ -15,6 +15,9 @@
#include <curl/curl.h>
#include <unicomctrl/cuniobj.h>
using namespace unicomctrl;
using namespace std;
class DdnssHttpCl : public CUniObj{
public:
DdnssHttpCl();
......
......@@ -2,7 +2,7 @@
PROJECT(ddnssync)
# ### COMMUN ###
SET(ddnssync_SRCS main.cpp ddnssslist.cpp ddnsspluginlist.cpp)
SET(ddnssync_SRCS ddnssslist.cpp ddnsspluginlist.cpp ddnssreqanalyzer.cpp main.cpp)
SET(ddnssync_LIBS ddnssbase unicomdb)
SET(ddnssync_DEFS ${global_unicomctrl_DEFS})
SET(ddnssync_LDFS )
......
......@@ -13,19 +13,21 @@
#include "../ddnssbase/cregex.h"
#include <dlfcn.h>
DDnsSPlList *DDnsSPlList::pList=0;
/**
* @brief DDnsSPluginList constructor.
*/
DDnsSPlList::DDnsSPlList(CUniConf &config):CUniObj() {
string dirPath=config.getValue("plugin_dir_path");
if(!dirPath.empty()){
CUniStringList list=config.getListValue("plugin_list");
StringList list=config.getListValue("plugin_list");
Plugin *plugin;
string plugPath;
void *handle;
ExecFct exec;
char *tmp;
for(CUniStringList::iterator it=list.begin();it!=list.end();it++){
for(StringList::iterator it=list.begin();it!=list.end();it++){
plugPath=dirPath+"lib"+*it+".so";
handle = dlopen (plugPath.c_str(), RTLD_LAZY|RTLD_GLOBAL);
if (!handle) {
......
......@@ -24,6 +24,9 @@
#include <unicomctrl/unilib.h>
#include <map>
using namespace unicomctrl;
using namespace std;
/**
* This class can manage a plugin list.
* @brief Plugin list.
......@@ -34,6 +37,7 @@ public:
~DDnsSPlList();
void exec(const string &request);
virtual string className();
static DDnsSPlList *pList;
private:
typedef void (*ExecFct)(const string&);
typedef struct Plugin{
......
......@@ -9,26 +9,26 @@
// Copyright: See COPYING file that comes with this distribution
//
//
#include "cunireqanalyzer.h"
#include "csvnmanagercl.h"
#include "ddnssreqanalyzer.h"
#include "ddnsspluginlist.h"
/**
* @brief Global CUniReqAnalyzer objet.
* @brief Global DDnsSReqAnalyzer objet.
*/
CUniReqAnalyzer *CUniReqAnalyzer::reqAnalyzer;
DDnsSReqAnalyzer *DDnsSReqAnalyzer::reqAnalyzer;
/**
* @brief CUniReqAnalyzer constructor
* @brief DDnsSReqAnalyzer constructor
*/
CUniReqAnalyzer::CUniReqAnalyzer()
DDnsSReqAnalyzer::DDnsSReqAnalyzer()
: CUniReqToolKit()
{
}
/**
* @brief CUniReqAnalyzer destructor.
* @brief DDnsSReqAnalyzer destructor.
*/
CUniReqAnalyzer::~CUniReqAnalyzer()
DDnsSReqAnalyzer::~DDnsSReqAnalyzer()
{
}
......@@ -37,59 +37,18 @@ CUniReqAnalyzer::~CUniReqAnalyzer()
* @param thread Thread sender.
* @param request The request.
*/
void CUniReqAnalyzer::exec(const string& request){
CSVNManagerCl *thread=(CSVNManagerCl*)(this->thread);
CUniSvnManager::svn->lock();
CUniSvnManager::svn->setParams(thread->getIdParent(),thread->getPathParent());
if(request.size()>4 && equ(request.substr(0,4),"SQL:")){
CUniDB *db=CUniSvnManager::svn->getDB();
if(checkIsFlagAdmin()){
string::size_type begin=request.find_first_not_of(" \t\n\r';",4);
if(begin!=string::npos){
string sql=request.substr(begin);
if(sql.size()>5 && equ(sql.substr(0,6),"SELECT")){
db->setSQL(sql);
if(db->execAndOpen()){
CUniString2DList list2D;
db->extractAll(list2D);
db->close();
if(list2D.size()==0)
returnMessage("AM >> Empty result.");
else
return2DList(list2D);
}else{
returnError("AM >> "+db->className().substr(6)+" error : "+db->getError());
}
}else{
db->setSQL(sql);
if(db->exec()){
returnMessage("AM >> SQL OK.");
}else{
returnError("AM >> "+db->className().substr(6)+" error : "+db->getError());
}
}
}else{
returnError("AM >> Empty SQL request.");
}
}
}else if(cut(request)){
void DDnsSReqAnalyzer::exec(const string& request){
if(cut(request)){
if(elts.size()>0 && checkIsKeyword(0,true)){
if(equ(elts.at(0),"HELP")){ // Help
if(elts.size()==1){
returnMessage("AM >> Command list :\n"
" * CREATE {REPOSITORY|REPO} '<repository>'; Create a repository.\n"
" * DELETE {REPOSITORY|REPO} '<repository>'; Create a repository.\n"
" * COMMIT; Write the authz file in the repositories parent dir.\n"
" * LIST {REPOSITORY|REPO}; Get the list of repositories.\n"
" * LIST {PRIVILEGES|PRIV} ['<user>']; Get the list of privileges associed to the user '<user>', otherwise all privileges.\n"
" * GRANT {READ|WRITE} TO '<user or role>' ON '<repository>' ['<location>']; Grant an user to read or read and write on all or specified repository at a location (default : \"/\").\n"
" * REVOKE ALL FROM '<user or role>' ON {ALL|'<repository>'} [{ALL|'<location>'}]; Revoke an user from all privileges on all or specified repository at a location (default : \"/\").\n"
returnMessage("Command list :\n"
" * VERSION; Get the version.\n"
" * REVISION; Get the revision (SVN).\n"
" * BUILD; Get the build date.\n"
" NB:\n{choice|other choice} => choice or other choice.\n[Option] => this is an option.\n");
}else{
returnError("AM >> HELP request error.");
returnError("HELP request error.");
}
}else if(equ(elts.at(0),"VERSION")){ // KW
if(checkNb("VERSION",1)){
......@@ -103,146 +62,23 @@ void CUniReqAnalyzer::exec(const string& request){
if(checkNb("REVISION",1)){
returnMessage(_UNI_REVISION);
}
}else if(equ(elts.at(0),"COMMIT")){ // KW
if(checkNb("COMMIT",1) && checkIsFlagAdmin()){
if(CUniSvnManager::svn->commitAuthz()){
returnMessage("commited.");
}else{
returnError("fatal error");
}
}
}else if(equ(elts.at(0),"LIST")){ // KW KW
if(elts.size()<2){
returnError("AM >> The command \"LIST\" require 2 arguments at least.");
}else if(checkIsKeyword(1,true) && checkIsFlagAdmin()){
CUniString2DList list2D;
CUniStringList list;
if(equ(elts.at(1),"PRIVILEGE") || equ(elts.at(1),"PRIV")){
if(elts.size()==2){
if(CUniSvnManager::svn->mkListPriv("",list2D,false)){
return2DList(list2D);
}else
returnError(CUniSvnManager::svn->getLastError());
}else if(elts.size()==3){
if(CUniSvnManager::svn->mkListPriv(elts.at(2),list2D,true)){
return2DList(list2D);
}else
returnError(CUniSvnManager::svn->getLastError());
}else if(elts.size()==4){
if(!equ(elts.at(3),"SINGLE"))
unreconizedKeyWord(3);
else if(CUniSvnManager::svn->mkListPriv(elts.at(2),list2D,false)){
return2DList(list2D);
}else
returnError(CUniSvnManager::svn->getLastError());
}else{
returnError("URA >> The command \"LIST PRIVILEGE\" (or \"LIST PRIV\") require 0,1 or 2 arguments.");
}
}else if(equ(elts.at(1),"REPOSITORY") || equ(elts.at(1),"REPO")){
if(checkIsKeyword(1,true) && checkNb("LIST REPOSITORY",2,2)){
if(CUniSvnManager::svn->mkListRepo(list)){
returnList(list);
}else
returnError(CUniSvnManager::svn->getLastError());
}
}else{
returnError("AM >> Syntax error at character "+charno.at(1)+" : unreconized arguments \""+elts.at(1)+"\".");
}
}
}else if(equ(elts.at(0),"CREATE")){ // KW KW ...
if(elts.size()>1){
if(checkIsKeyword(1,true) && checkIsFlagAdmin()){
if(equ(elts.at(1),"REPOSITORY") || equ(elts.at(1),"REPO")){ // KW KW STR
if(checkNb("CREATE REPOSITORY",3,2)){
if(CUniSvnManager::svn->createRepo(elts.at(2)))
returnMessage("AM >> 1 repository created.");
else
returnError(CUniSvnManager::svn->getLastError());
}
}else{
unreconizedKeyWord(1);
}
try{
DDnsSPlList::pList->exec(request);
}catch(string err){
returnError(err);
}
}else{
returnError("AM >> The command \"CREATE\" require an instruction complement.");
}
}else if(equ(elts.at(0),"DELETE")){ // KW KW ...
if(elts.size()>1){
if(checkIsKeyword(1,true) && checkIsFlagAdmin()){
if(equ(elts.at(1),"REPOSITORY") || equ(elts.at(1),"REPO")){ // KW KW STR
if(checkNb("CREATE REPOSITORY",3,2)){
if(CUniSvnManager::svn->deleteRepo(elts.at(2)))
returnMessage("AM >> 1 repository deleted.");
else
returnError(CUniSvnManager::svn->getLastError());
}
}else{
unreconizedKeyWord(1);
}
}
}else{
returnError("AM >> The command \"DELETE\" require an instruction complement.");
}
}else if(equ(elts.at(0),"GRANT")){ // KW KW KW STR KW STR [STR]
if(elts.size()==6 || elts.size()==7){
if(checkIsKeyword(1,true) && checkIsKeyword(2,true) && checkIsKeyword(4,true) && checkIsFlagAdmin()){
bool write=(equ(elts.at(1),"WRITE")?true:false);
string path=(elts.size()==7?elts.at(6):"/");
if(path.length()>0 && path[0]!='/')
path.insert(path.begin(),'/');
if(!equ(elts.at(1),"READ") && !equ(elts.at(1),"WRITE")){
unreconizedKeyWord(1);
}else if(!equ(elts.at(2),"TO")){
unreconizedKeyWord(2);
}else if(!equ(elts.at(4),"ON")){
unreconizedKeyWord(4);
}else{
if(CUniSvnManager::svn->grant(elts.at(3),elts.at(5),path,write))
returnMessage("URA >> granted.");
else
returnError(CUniSvnManager::svn->getLastError());
}
}
}else{
returnError("URA >> The command \"GRANT\" require 6 or 7 arguments.");
}
}else if(equ(elts.at(0),"REVOKE")){ // KW KW KW STR KW STR [STR]
if(elts.size()==6 || elts.size()==7){
if(checkIsKeyword(1,true) && checkIsKeyword(2,true) && checkIsKeyword(4,true) && checkIsFlagAdmin()){
string path=(elts.size()==7?(keyword.at(6) && equ(elts.at(6),"ALL")?"":elts.at(6)):"/");
if(path.length()>0 && path[0]!='/')
path.insert(path.begin(),'/');
if(!equ(elts.at(1),"ALL")){
unreconizedKeyWord(1);
}else if(!equ(elts.at(2),"FROM")){
unreconizedKeyWord(2);
}else if(!equ(elts.at(4),"ON")){
unreconizedKeyWord(4);
}else{
if(CUniSvnManager::svn->revoke(elts.at(3),
(keyword.at(5) && equ(elts.at(5),"ALL")?"":elts.at(5)),path))
returnMessage("URA >> revoked.");
else
returnError(CUniSvnManager::svn->getLastError());
}
}
}else{
returnError("URA >> The command \"REVOKE\" require 6 or 7 arguments.");
}
}else{
unreconizedKeyWord(0);
}
}else if(elts.size()==0){
returnError("AM >> Empty request.");
returnError("Empty request.");
}
}
CUniSvnManager::svn->unlock();
}
/**
* @brief The name of the class.
* @return "CUniReqAnalyzer"
* @return "DDnsSReqAnalyzer"
*/
string CUniReqAnalyzer::className() {
return "CUniReqAnalyzer";
string DDnsSReqAnalyzer::className() {
return "DDnsSReqAnalyzer";
}
......@@ -20,19 +20,21 @@
#define CUNIREQANALYZER_H
#include <unicomctrl/cunireqtoolkit.h>
#include "cunisvnmanager.h"
using namespace unicomctrl;
using namespace std;
/**
* This class can manage a generic object.
* @brief Request analyze and execution.
*/
class CUniReqAnalyzer : public CUniReqToolKit
class DDnsSReqAnalyzer : public CUniReqToolKit
{
public:
CUniReqAnalyzer();
~CUniReqAnalyzer();
DDnsSReqAnalyzer();
~DDnsSReqAnalyzer();
void exec(const string& request);
static CUniReqAnalyzer *reqAnalyzer;
static DDnsSReqAnalyzer *reqAnalyzer;
virtual string className();
};
......
......@@ -14,8 +14,8 @@
DDnsSSList::DDnsSSList(CUniConf &cf)
: CUniObj()
{
CUniStringList cmdList=cf.getListValue("dn_list");
for(CUniStringList::iterator it=cmdList.begin();it!=cmdList.begin();it++){
StringList cmdList=cf.getListValue("dn_list");
for(StringList::iterator it=cmdList.begin();it!=cmdList.begin();it++){
dnList.push_back(new DName(cf,*it));
}
}
......
......@@ -16,6 +16,9 @@
#include <unicomctrl/cuniconf.h>
#include <unicomctrl/unilib.h>
using namespace unicomctrl;
using namespace std;
/**
@author Emeric VERSCHUUR <contact@mr-ti.com>
*/
......@@ -32,7 +35,7 @@ public:
virtual void onExit();
private:
string dname;
CUniStringList cmdList;
StringList cmdList;
};
DDnsSSList(CUniConf &cf);
~DDnsSSList();
......
#include <unicomctrl/cuniconffile.h>
#include <unicomctrl/cuniconfreg.h>
#include <unicomctrl/ddnssreqanalyzer.h>
#include <unicomctrl/cunicomcl.h>
#include <unicomctrl/cunithreadmanager.h>
#include "ddnssreqanalyzer.h"
#include <string>
#include <signal.h>
CUniReqAnalyzer analyzer;
using namespace unicomctrl;
using namespace std;
DDnsSReqAnalyzer analyzer;
class DDnsSManager : public CUniComCl
{
public:
CUniAuthManager(const string& server): CUniComCl(server){}
~CUniAuthManager(){}
DDnsSManager(const string& server): CUniComCl(server){}
~DDnsSManager(){}
void onDataIn(CUniData::Type type){
switch(type){
case CUniData::REQUEST:
......@@ -24,7 +29,7 @@ public:
}
}
virtual string className(){
return "CUniAuthManager";
return "DDnsSManager";
}
};
......@@ -53,30 +58,25 @@ int main(int argc, char **argv) {
"Possible values are :\n\t* verbose\n\t* short\n\t* quiet\n"
"You must correct this error in the configuration file.\n");
CSVNManagerCl *thread;
string server=config.getValue("server");
string user=config.getValue("user");
string passwd=config.getValue("passwd");
string name=config.getValue("name");
thList.addTypeToManage("???");
// while(db->next()){
// thread=new CSVNManagerCl(server,db->extractRow(0),db->extractRow(2));
// if(!thread->isConnected()){
// thread->printc("Connection failed !\n");
// exit(EXIT_FAILURE);
// }
//
// //Démarrage du client.
// thread->start();
//
// //Identification et insertion du plugin auprès du serveur.
// if(!thread->query(NULL,"connect '"+user+"' '"+passwd+"'")
// || !thread->query(NULL,"insert '"+name+" "+db->extractRow(1)+"'")){
// thread->printc("Failed to record : "+thread->getLastError()+"\n");
// exit(EXIT_FAILURE);
// }
//
// }
thList.addTypeToManage("DDnsSManager");
DDnsSManager *thread=new DDnsSManager(server);
if(!thread->isConnected()){
thread->printc("Connection failed !\n");
}else{
//Démarrage du client.
thread->start();
//Identification et insertion du plugin auprès du serveur.
if(!thread->query(NULL,"connect '"+user+"' '"+passwd+"'")
|| !thread->query(NULL,"insert '"+name+"'")){
thread->printc("Failed to record : "+thread->getLastError()+"\n");
}
}
//Paramétrage de l'interruption.
signal(SIGTERM,quit);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment