Loading data/wizzard.html 0 → 100644 +30 −0 Changes for data/wizzard.html: 30 added lines, 0 removed lines. Original line number Diff line number Diff line <!DOCTYPE html> <html lang="en"> <head> <title>AuthDB Wizzard</title> </head> <body> <div id="wizzard" > <p><span style="font-size:4em;">AuthDB Initial Wizzard</span></p> <form method="post" id="createform"> <table> <tr> <td><label for="username">Username:</label></td> <td><input type="text" name="username" id="username"></td> </tr> <tr> <td><label for="password">Password:</label></td> <td><input type="password" name="password" id="password"></td> </tr> <tr> </tr> <tr> <td></td> <td><input type="submit" value="Create"></td> </tr> </table> </form> </div> </body> </html> src/authdb.cpp +80 −32 Changes for src/authdb.cpp: 80 added lines, 32 removed lines. Original line number Diff line number Diff line Loading @@ -442,61 +442,52 @@ VALUEFOUND: DomainBackend::~DomainBackend(){ delete _domainbck; } }; void runWizzard(){ class AuthWizzard : public libhttppp::HttpEvent { public: AuthWizzard(netplus::socket *ssock) : HttpEvent(ssock){ _Page.loadFile(_Index,GETDATA(wizzard.html)); } int main(int argc, char *argv[]){ cmdplus::CmdController &cmd=cmdplus::CmdController::getInstance(); void RequestEvent(libhttppp::HttpRequest * curreq, const int tid, ULONG_PTR args){ libhttppp::HttpForm form; cmd.registerCmd("config",'c',true,nullptr,"Config Path"); AuthBackend *backend=(AuthBackend*)args; cmd.parseCmd(argc,argv); form.parse(curreq); if(!cmd.checkRequired()){ std::cerr << "Config Path required !" << std::endl; cmd.printHelp(); return -1; std::string username,password,pwhash; for(libhttppp::HttpForm::UrlcodedForm::Data *curformdat=form.UrlFormData.getFormData(); curformdat; curformdat=curformdat->nextData()){ if(strcmp(curformdat->getKey(),"username")==0) username=curformdat->getValue(); else if(strcmp(curformdat->getKey(),"password")==0) password=curformdat->getValue(); } confplus::Config config(cmd.getCmdbyKey("config")->getValue()); if(!password.empty() && !username.empty()){ sha512 hash; hash.hash(password,pwhash); authdb::AuthBackend backend(authdb::AuthBackendType::File, config.getValue(config.getKey("/AUTHDB/ADMINDB/PATH"),0), "admin.local" ); try { if(backend.end()<=sizeof(authdb::AuthHeader)){ authdb::User user; uuid_t adminid,admingid; uuid_generate(adminid); uuid_generate(admingid); class authdb::UserData udat(adminid); std::string username,password,pwhash; uuid_generate(adminid); std::cout << "Please enter Admin name: "; std::cin >> username; std::cout << std::endl; uuid_generate(admingid); udat.setUserName(username.c_str()); std::cout << "Please enter Admin Password: "; std::cin >> password; std::cout << std::endl; authdb::sha512 sha; sha.hash(password,pwhash); udat.setPwHash(pwhash.c_str()); user.create(backend,&udat); user.create(*backend,&udat); authdb::Group group; Loading @@ -511,9 +502,53 @@ int main(int argc, char *argv[]){ gdat.addMember(muid); group.create(backend,&gdat); group.create(*backend,&gdat); libhttppp::HTTPException exp; exp[999] << "wizzard finished"; throw exp; } libhtmlpp::HtmlElement index=_Index; libhttppp::HttpResponse rep; libhtmlpp::HtmlString sendat; libhtmlpp::print((libhtmlpp::Element*)&index,sendat,false); rep.setState(HTTP200); rep.setVersion(HTTPVERSION(1.1)); rep.setContentType("text/html"); rep.send(curreq,sendat.c_str(),sendat.size()); } private: libhtmlpp::HtmlPage _Page; libhtmlpp::HtmlElement _Index;; }; }; int main(int argc, char *argv[]){ cmdplus::CmdController &cmd=cmdplus::CmdController::getInstance(); cmd.registerCmd("config",'c',true,nullptr,"Config Path"); cmd.parseCmd(argc,argv); if(!cmd.checkRequired()){ std::cerr << "Config Path required !" << std::endl; cmd.printHelp(); return -1; } confplus::Config config(cmd.getCmdbyKey("config")->getValue()); authdb::AuthBackend backend(authdb::AuthBackendType::File, config.getValue(config.getKey("/AUTHDB/ADMINDB/PATH"),0), "admin.local" ); try { libhttppp::HttpD httpd( config.getValue(config.getKey("/AUTHDB/BIND"),0), config.getIntValue(config.getKey("/AUTHDB/PORT"),0), Loading @@ -522,6 +557,19 @@ int main(int argc, char *argv[]){ nullptr ); if(backend.end()<=sizeof(authdb::AuthHeader)){ try{ authdb::AuthWizzard wizzard(httpd.getServerSocket()); wizzard.threads=1; wizzard.runEventloop((ULONG_PTR)&backend); }catch(libhttppp::HTTPException &e){ if(e.getErrorType()==999) std::cout<< e.what() << std::endl; else throw e; } } authdb::AuthDB authdb(backend,httpd.getServerSocket()); // authdb.threads=2; Loading Loading
data/wizzard.html 0 → 100644 +30 −0 Changes for data/wizzard.html: 30 added lines, 0 removed lines. Original line number Diff line number Diff line <!DOCTYPE html> <html lang="en"> <head> <title>AuthDB Wizzard</title> </head> <body> <div id="wizzard" > <p><span style="font-size:4em;">AuthDB Initial Wizzard</span></p> <form method="post" id="createform"> <table> <tr> <td><label for="username">Username:</label></td> <td><input type="text" name="username" id="username"></td> </tr> <tr> <td><label for="password">Password:</label></td> <td><input type="password" name="password" id="password"></td> </tr> <tr> </tr> <tr> <td></td> <td><input type="submit" value="Create"></td> </tr> </table> </form> </div> </body> </html>
src/authdb.cpp +80 −32 Changes for src/authdb.cpp: 80 added lines, 32 removed lines. Original line number Diff line number Diff line Loading @@ -442,61 +442,52 @@ VALUEFOUND: DomainBackend::~DomainBackend(){ delete _domainbck; } }; void runWizzard(){ class AuthWizzard : public libhttppp::HttpEvent { public: AuthWizzard(netplus::socket *ssock) : HttpEvent(ssock){ _Page.loadFile(_Index,GETDATA(wizzard.html)); } int main(int argc, char *argv[]){ cmdplus::CmdController &cmd=cmdplus::CmdController::getInstance(); void RequestEvent(libhttppp::HttpRequest * curreq, const int tid, ULONG_PTR args){ libhttppp::HttpForm form; cmd.registerCmd("config",'c',true,nullptr,"Config Path"); AuthBackend *backend=(AuthBackend*)args; cmd.parseCmd(argc,argv); form.parse(curreq); if(!cmd.checkRequired()){ std::cerr << "Config Path required !" << std::endl; cmd.printHelp(); return -1; std::string username,password,pwhash; for(libhttppp::HttpForm::UrlcodedForm::Data *curformdat=form.UrlFormData.getFormData(); curformdat; curformdat=curformdat->nextData()){ if(strcmp(curformdat->getKey(),"username")==0) username=curformdat->getValue(); else if(strcmp(curformdat->getKey(),"password")==0) password=curformdat->getValue(); } confplus::Config config(cmd.getCmdbyKey("config")->getValue()); if(!password.empty() && !username.empty()){ sha512 hash; hash.hash(password,pwhash); authdb::AuthBackend backend(authdb::AuthBackendType::File, config.getValue(config.getKey("/AUTHDB/ADMINDB/PATH"),0), "admin.local" ); try { if(backend.end()<=sizeof(authdb::AuthHeader)){ authdb::User user; uuid_t adminid,admingid; uuid_generate(adminid); uuid_generate(admingid); class authdb::UserData udat(adminid); std::string username,password,pwhash; uuid_generate(adminid); std::cout << "Please enter Admin name: "; std::cin >> username; std::cout << std::endl; uuid_generate(admingid); udat.setUserName(username.c_str()); std::cout << "Please enter Admin Password: "; std::cin >> password; std::cout << std::endl; authdb::sha512 sha; sha.hash(password,pwhash); udat.setPwHash(pwhash.c_str()); user.create(backend,&udat); user.create(*backend,&udat); authdb::Group group; Loading @@ -511,9 +502,53 @@ int main(int argc, char *argv[]){ gdat.addMember(muid); group.create(backend,&gdat); group.create(*backend,&gdat); libhttppp::HTTPException exp; exp[999] << "wizzard finished"; throw exp; } libhtmlpp::HtmlElement index=_Index; libhttppp::HttpResponse rep; libhtmlpp::HtmlString sendat; libhtmlpp::print((libhtmlpp::Element*)&index,sendat,false); rep.setState(HTTP200); rep.setVersion(HTTPVERSION(1.1)); rep.setContentType("text/html"); rep.send(curreq,sendat.c_str(),sendat.size()); } private: libhtmlpp::HtmlPage _Page; libhtmlpp::HtmlElement _Index;; }; }; int main(int argc, char *argv[]){ cmdplus::CmdController &cmd=cmdplus::CmdController::getInstance(); cmd.registerCmd("config",'c',true,nullptr,"Config Path"); cmd.parseCmd(argc,argv); if(!cmd.checkRequired()){ std::cerr << "Config Path required !" << std::endl; cmd.printHelp(); return -1; } confplus::Config config(cmd.getCmdbyKey("config")->getValue()); authdb::AuthBackend backend(authdb::AuthBackendType::File, config.getValue(config.getKey("/AUTHDB/ADMINDB/PATH"),0), "admin.local" ); try { libhttppp::HttpD httpd( config.getValue(config.getKey("/AUTHDB/BIND"),0), config.getIntValue(config.getKey("/AUTHDB/PORT"),0), Loading @@ -522,6 +557,19 @@ int main(int argc, char *argv[]){ nullptr ); if(backend.end()<=sizeof(authdb::AuthHeader)){ try{ authdb::AuthWizzard wizzard(httpd.getServerSocket()); wizzard.threads=1; wizzard.runEventloop((ULONG_PTR)&backend); }catch(libhttppp::HTTPException &e){ if(e.getErrorType()==999) std::cout<< e.what() << std::endl; else throw e; } } authdb::AuthDB authdb(backend,httpd.getServerSocket()); // authdb.threads=2; Loading