Commit 5669edee authored by mr-ti's avatar mr-ti
Browse files

No commit message

No commit message
parent 775fe66b
//
// C++ Implementation: cunireqanalisor
//
// Description:
//
//
// Author: Emeric Verschuur <contact@mr-ti.com>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "cunireqanalyzer.h"
#include "csvnmanagercl.h"
/**
* @brief Global CUniReqAnalyzer objet.
*/
CUniReqAnalyzer *CUniReqAnalyzer::reqAnalyzer;
/**
* @brief CUniReqAnalyzer constructor
*/
CUniReqAnalyzer::CUniReqAnalyzer()
: CUniReqToolKit()
{
}
/**
* @brief CUniReqAnalyzer destructor.
*/
CUniReqAnalyzer::~CUniReqAnalyzer()
{
}
/**
* @brief Execute a request.
* @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)){
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"
" * 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.");
}
}else if(equ(elts.at(0),"VERSION")){ // KW
if(checkNb("VERSION",1)){
returnMessage(_UNI_VERSION);
}
}else if(equ(elts.at(0),"BUILD")){ // KW
if(checkNb("BUILD",1)){
returnMessage(__DATE__ " " __TIME__);
}
}else if(equ(elts.at(0),"REVISION")){ // KW
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);
}
}
}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.");
}
}
CUniSvnManager::svn->unlock();
}
/**
* @brief The name of the class.
* @return "CUniReqAnalyzer"
*/
string CUniReqAnalyzer::className() {
return "CUniReqAnalyzer";
}
//
// C++ Interface: cunireqanalisor
//
// Description:
//
//
// Author: Emeric Verschuur <contact@mr-ti.com>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
/**
* @brief Request management.
* @file cunireqanalyzer.h
* @author Emeric VERSCHUUR <contact@mr-ti.com>, (C) 2007
*/
#ifndef CUNIREQANALYZER_H
#define CUNIREQANALYZER_H
#include <unicomctrl/cunireqtoolkit.h>
#include "cunisvnmanager.h"
/**
* This class can manage a generic object.
* @brief Request analyze and execution.
*/
class CUniReqAnalyzer : public CUniReqToolKit
{
public:
CUniReqAnalyzer();
~CUniReqAnalyzer();
void exec(const string& request);
static CUniReqAnalyzer *reqAnalyzer;
virtual string className();
};
#endif
#include <iostream>
#include <unicomctrl/cuniconffile.h>
#include <unicomctrl/cuniconfreg.h>
#include <unicomctrl/ddnssreqanalyzer.h>
#include <string>
#include <list>
#include "../ddnssbase/ddnsshttpcl.h"
#include <signal.h>
CUniReqAnalyzer analyzer;
class DDnsSManager : public CUniComCl
{
public:
CUniAuthManager(const string& server): CUniComCl(server){}
~CUniAuthManager(){}
void onDataIn(CUniData::Type type){
switch(type){
case CUniData::REQUEST:
analyzer.lock();
analyzer.init(this,"URA");
analyzer.exec(getMessage());
analyzer.unlock();
break;
default:
break;
}
}
virtual string className(){
return "CUniAuthManager";
}
};
CUniThreadManager thList;
void quit(int sig){
//Arrêt des clients.
thList.breakWait();
}
int main(int argc, char **argv) {
// CRegex reg((const string)string(argv[1]));
// if(reg.getState()==CRegex::ERROR){
// cout << reg.getErrorMsg() << endl;
// return 1;
// }
// string buf(argv[2]);
// reg.setBuffer(&buf);
// // cout << reg.getFirstMatch() << endl;
// list<string> lst=reg.getMatchs(atoi(argv[3]));
// for(list<string>::iterator it=lst.begin();it!=lst.end();it++){
// cout << "\"" << *it << "\"" << endl;
//Initialisation.
CUniSocket::init();
CUniConfFile config("/etc/ddnssync/ddnssync.conf");
// Niveau bavard
string value=config.getValue("verbose_level");
if(value=="verbose")
CUniIO::globalIO.setLevel(CUniIO::LONG);
else if(value=="short")
CUniIO::globalIO.setLevel(CUniIO::SHORT);
else if(value=="quiet")
CUniIO::globalIO.setLevel(CUniIO::QUIET);
else
CUniObj::printc("AuthManager","Configuration file >> Bade value for the parameter \"verbose_level\"\n"
"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);
// }
//
// }
DdnssHttpCl cl;
cout << cl.getPublicIp() << endl;
//Paramétrage de l'interruption.
signal(SIGTERM,quit);
signal(SIGINT,quit);
thList.waitJoin();
thList.killall();
return 0;
}
#include <unicomctrl/cuniconffile.h>
#include <unicomctrl/cuniconfreg.h>
#include <unicomctrl/cunithreadmanager.h>
#include <string>
#include <signal.h>
#include "csvnmanagercl.h"
CUniThreadManager thList;
void quit(int sig){
//Arrêt des clients.
thList.breakWait();
}
int main(int argc, char **argv) {
//Initialisation.
CUniSocket::init();
#ifdef WIN32
CUniConfReg config("Software\\UniComPl\\svnmanager",CUniConfReg::REG_LM);
#else
CUniConfFile config("/etc/unicomctrl/svnmanager.conf");
#endif
// Niveau bavard
string value=config.getValue("verbose_level");
if(value=="verbose")
CUniIO::globalIO.setLevel(CUniIO::LONG);
else if(value=="short")
CUniIO::globalIO.setLevel(CUniIO::SHORT);
else if(value=="quiet")
CUniIO::globalIO.setLevel(CUniIO::QUIET);
else
CUniObj::printc("AuthManager","Configuration file >> Bade value for the parameter \"verbose_level\"\n"
"Possible values are :\n\t* verbose\n\t* short\n\t* quiet\n"
"You must correct this error in the configuration file.\n");
CUniSvnManager::svn=new CUniSvnManager(&config);
//Lancement des clients
CUniDB *db=CUniSvnManager::svn->getDB();
db->setSQL("SELECT id_svn_parent,ref,path FROM svn_parent");
if(!db->execAndOpen()){
CUniObj::printc("AuthManager","Fatal DB error !\n");
exit(EXIT_FAILURE);
}
CSVNManagerCl *thread;
string server=config.getValue("server");
string user=config.getValue("user");
string passwd=config.getValue("passwd");
string name=config.getValue("name");
thList.addTypeToManage("CSVNManagerCl");
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);
}
}
db->close();
//Paramétrage de l'interruption.
signal(SIGTERM,quit);
signal(SIGINT,quit);
thList.waitJoin();
thList.killall();
delete CUniSvnManager::svn;
return 0;
}
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