Skip to content
Snippets Groups Projects
Commit f3d20271 authored by jan.koester's avatar jan.koester
Browse files

fninished

parent 07eba8b5
No related branches found
No related tags found
No related merge requests found
Pipeline #108 failed
...@@ -46,5 +46,6 @@ COPY --from=build /usr/local/lib /usr/local/lib ...@@ -46,5 +46,6 @@ COPY --from=build /usr/local/lib /usr/local/lib
COPY data/docker-config.yaml /etc/authdb/config.yaml COPY data/docker-config.yaml /etc/authdb/config.yaml
USER authdb
CMD ["authdb","-c","yaml://etc/authdb/config.yaml"] CMD ["authdb","-c","yaml://etc/authdb/config.yaml"]
...@@ -75,7 +75,94 @@ namespace authdb { ...@@ -75,7 +75,94 @@ namespace authdb {
cssfs.read(_AuthCss.data(),csssize); 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){ 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){ if(strncmp("/settings",curreq->getRequestURL(),9)==0){
_AdminBackend.lock(); _AdminBackend.lock();
try{ try{
...@@ -446,99 +533,6 @@ VALUEFOUND: ...@@ -446,99 +533,6 @@ VALUEFOUND:
DomainBackend::~DomainBackend(){ DomainBackend::~DomainBackend(){
delete _domainbck; 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[]){ int main(int argc, char *argv[]){
...@@ -569,19 +563,6 @@ int main(int argc, char *argv[]){ ...@@ -569,19 +563,6 @@ int main(int argc, char *argv[]){
nullptr 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::AuthDB authdb(backend,httpd.getServerSocket());
// authdb.threads=2; // authdb.threads=2;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment