Loading Dockerfile +1 −0 Changes for Dockerfile: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -46,5 +46,6 @@ COPY --from=build /usr/local/lib /usr/local/lib COPY data/docker-config.yaml /etc/authdb/config.yaml USER authdb CMD ["authdb","-c","yaml://etc/authdb/config.yaml"] src/authdb.cpp +87 −106 Changes for src/authdb.cpp: 87 added lines, 106 removed lines. Original line number Diff line number Diff line Loading @@ -75,7 +75,94 @@ namespace authdb { cssfs.read(_AuthCss.data(),csssize); }; void WizzardEvent(libhttppp::HttpRequest * curreq, const int tid, ULONG_PTR args){ std::lock_guard<std::mutex> wlock(g_wizzard); libhttppp::HttpForm form; form.parse(curreq); 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(); } if(!password.empty() && !username.empty()){ sha512 hash; hash.hash(password,pwhash); authdb::User user; uuid_t adminid,admingid; uuid_generate(adminid); uuid_generate(admingid); class authdb::UserData udat(adminid); udat.setUserName(username.c_str()); authdb::sha512 sha; sha.hash(password,pwhash); udat.setPwHash(pwhash.c_str()); user.create(_AdminBackend,&udat); authdb::Group group; class authdb::GroupData gdat(admingid); gdat.setName("SuperAdmin"); authdb::GroupData::MemberUids muid; muid.count=1; muid.uid=&adminid; gdat.addMember(muid); group.create(_AdminBackend,&gdat); libhttppp::HTTPException exp; exp[999] << "wizzard finished"; throw exp; } libhtmlpp::HtmlElement index; libhtmlpp::HtmlPage page; page.loadFile(index,GETDATA(wizzard.html)); 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()); } void RequestEvent(libhttppp::HttpRequest * curreq, const int tid, ULONG_PTR args){ if(_AdminBackend.end()<=sizeof(authdb::AuthHeader)){ try{ WizzardEvent(curreq,tid,args); return; }catch(libhttppp::HTTPException &e){ if(e.getErrorType()!=999) throw e; } } if(strncmp("/settings",curreq->getRequestURL(),9)==0){ _AdminBackend.lock(); try{ Loading Loading @@ -446,99 +533,6 @@ VALUEFOUND: DomainBackend::~DomainBackend(){ delete _domainbck; } class AuthWizzard : public libhttppp::HttpEvent { public: AuthWizzard(netplus::socket *ssock) : HttpEvent(ssock){ _Page.loadFile(_Index,GETDATA(wizzard.html)); } void RequestEvent(libhttppp::HttpRequest * curreq, const int tid, ULONG_PTR args){ std::lock_guard<std::mutex> wlock(g_wizzard); AuthBackend *backend=(AuthBackend*)args; if(backend->end()>sizeof(authdb::AuthHeader)){ libhttppp::HTTPException exp; exp[999] << "wizzard already done!"; throw exp; } libhttppp::HttpForm form; form.parse(curreq); 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(); } if(!password.empty() && !username.empty()){ sha512 hash; hash.hash(password,pwhash); authdb::User user; uuid_t adminid,admingid; uuid_generate(adminid); uuid_generate(admingid); class authdb::UserData udat(adminid); udat.setUserName(username.c_str()); authdb::sha512 sha; sha.hash(password,pwhash); udat.setPwHash(pwhash.c_str()); user.create(*backend,&udat); authdb::Group group; class authdb::GroupData gdat(admingid); gdat.setName("SuperAdmin"); authdb::GroupData::MemberUids muid; muid.count=1; muid.uid=&adminid; gdat.addMember(muid); 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[]){ Loading Loading @@ -569,19 +563,6 @@ 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
Dockerfile +1 −0 Changes for Dockerfile: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -46,5 +46,6 @@ COPY --from=build /usr/local/lib /usr/local/lib COPY data/docker-config.yaml /etc/authdb/config.yaml USER authdb CMD ["authdb","-c","yaml://etc/authdb/config.yaml"]
src/authdb.cpp +87 −106 Changes for src/authdb.cpp: 87 added lines, 106 removed lines. Original line number Diff line number Diff line Loading @@ -75,7 +75,94 @@ namespace authdb { cssfs.read(_AuthCss.data(),csssize); }; void WizzardEvent(libhttppp::HttpRequest * curreq, const int tid, ULONG_PTR args){ std::lock_guard<std::mutex> wlock(g_wizzard); libhttppp::HttpForm form; form.parse(curreq); 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(); } if(!password.empty() && !username.empty()){ sha512 hash; hash.hash(password,pwhash); authdb::User user; uuid_t adminid,admingid; uuid_generate(adminid); uuid_generate(admingid); class authdb::UserData udat(adminid); udat.setUserName(username.c_str()); authdb::sha512 sha; sha.hash(password,pwhash); udat.setPwHash(pwhash.c_str()); user.create(_AdminBackend,&udat); authdb::Group group; class authdb::GroupData gdat(admingid); gdat.setName("SuperAdmin"); authdb::GroupData::MemberUids muid; muid.count=1; muid.uid=&adminid; gdat.addMember(muid); group.create(_AdminBackend,&gdat); libhttppp::HTTPException exp; exp[999] << "wizzard finished"; throw exp; } libhtmlpp::HtmlElement index; libhtmlpp::HtmlPage page; page.loadFile(index,GETDATA(wizzard.html)); 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()); } void RequestEvent(libhttppp::HttpRequest * curreq, const int tid, ULONG_PTR args){ if(_AdminBackend.end()<=sizeof(authdb::AuthHeader)){ try{ WizzardEvent(curreq,tid,args); return; }catch(libhttppp::HTTPException &e){ if(e.getErrorType()!=999) throw e; } } if(strncmp("/settings",curreq->getRequestURL(),9)==0){ _AdminBackend.lock(); try{ Loading Loading @@ -446,99 +533,6 @@ VALUEFOUND: DomainBackend::~DomainBackend(){ delete _domainbck; } class AuthWizzard : public libhttppp::HttpEvent { public: AuthWizzard(netplus::socket *ssock) : HttpEvent(ssock){ _Page.loadFile(_Index,GETDATA(wizzard.html)); } void RequestEvent(libhttppp::HttpRequest * curreq, const int tid, ULONG_PTR args){ std::lock_guard<std::mutex> wlock(g_wizzard); AuthBackend *backend=(AuthBackend*)args; if(backend->end()>sizeof(authdb::AuthHeader)){ libhttppp::HTTPException exp; exp[999] << "wizzard already done!"; throw exp; } libhttppp::HttpForm form; form.parse(curreq); 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(); } if(!password.empty() && !username.empty()){ sha512 hash; hash.hash(password,pwhash); authdb::User user; uuid_t adminid,admingid; uuid_generate(adminid); uuid_generate(admingid); class authdb::UserData udat(adminid); udat.setUserName(username.c_str()); authdb::sha512 sha; sha.hash(password,pwhash); udat.setPwHash(pwhash.c_str()); user.create(*backend,&udat); authdb::Group group; class authdb::GroupData gdat(admingid); gdat.setName("SuperAdmin"); authdb::GroupData::MemberUids muid; muid.count=1; muid.uid=&adminid; gdat.addMember(muid); 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[]){ Loading Loading @@ -569,19 +563,6 @@ 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