Loading src/admin.cpp +63 −3 Changes for src/admin.cpp: 63 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ #include "hash/sha512.h" #include "session.h" #include "gpo.h" #include "client.h" namespace authdb { class AdminController { Loading Loading @@ -2133,11 +2134,30 @@ namespace authdb { form.parse(curreq); if(form.UrlFormData.getFormData()){ uuid_t clid; uuid_generate(clid); class ClientData cdat(clid); std::string key,keyhash; for(libhttppp::HttpForm::UrlcodedForm::Data *curdat=form.UrlFormData.getFormData(); curdat; curdat=curdat->nextData() ){ if( strcmp(curdat->getKey(),"clientname")==0 ) cdat.setName(curdat->getValue()); else if (strcmp(curdat->getKey(),"clientkey")==0) key=curdat->getValue(); } sha512 hash; hash.hash(key,keyhash); cdat.setKey(keyhash.c_str()); Client clt; clt.create(*backend,&cdat); libhttppp::HttpResponse rep; rep.setState(HTTP303); rep.setVersion(HTTPVERSION(1.1)); Loading Loading @@ -2165,12 +2185,14 @@ namespace authdb { submitl.insertChild(submit); lname.insertChild(libhtmlpp::TextElement("Client name:")); lname.setAttribute("for","clientname"); name.setAttribute("type","text"); name.setAttribute("name","clientname"); lsecret.insertChild(libhtmlpp::TextElement("Client secret:")); secret.setAttribute("type","text"); secret.setAttribute("name","secret"); lsecret.setAttribute("for","clientkey"); secret.setAttribute("type","password"); secret.setAttribute("name","clientkey"); namel.appendChild(lname); namel.appendChild(name); Loading Loading @@ -2248,11 +2270,49 @@ namespace authdb { toolbar.insertChild(list); libhtmlpp::HtmlElement clist("ul"); size_t rd=sizeof(authdb::AuthHeader),end=backend->end(); Client clt; while(rd<end){ authdb::AuthData::Record cur; cur.type=EmptyData; backend->setPos(rd); backend->read((unsigned char*)&cur,sizeof(AuthData::Record)); rd=backend->getPos()+cur.datasize; if(cur.type == ClientData && strcmp(cur.fieldname,"clientname")==0){ class ClientData cdat(cur.uuid); try { size_t ccpos=sizeof(authdb::AuthHeader); clt.info(*backend,cdat,ccpos); char cruid[255]; uuid_unparse(cur.uuid,cruid); libhtmlpp::HtmlString clistdata; clistdata << "<li>" << cruid << ": " << cdat.getName() << "</li>"; clist.appendChild(clistdata.parse()); }catch(AuthBackendError &e){ std::cerr << e.what() << std::endl; } } } libhtmlpp::HtmlElement *content=index.getElementbyID("content"); if(content){ content->appendChild(domel); content->appendChild(headline); content->appendChild(clist); content->appendChild(toolbar); } Loading src/client.cpp +13 −4 Changes for src/client.cpp: 13 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -27,6 +27,15 @@ #include "client.h" authdb::ClientData::ClientData(uuid_t clid) : AuthData(clid){ ClientKey=nullptr; ClientName=nullptr; } authdb::ClientData::~ClientData() { } void authdb::ClientData::setKey(const char *key){ setAuthData<char,char>(DataType::ClientData,StorageType::TextStorage, this,&ClientKey,"clientkey",key,strlen(key)+1); Loading Loading @@ -54,16 +63,16 @@ void authdb::Client::create(AuthBackend& backend, class ClientData* data){ if(exits(backend,&data->Data->uuid,data->getName(),exi)){ switch(exi){ case 1: throw authdb::AuthBackendError("Create User: Username already Exists aborting!"); throw authdb::AuthBackendError("Create Client: Username already Exists aborting!"); default: throw authdb::AuthBackendError("Create User: UUID already Exists aborting!"); throw authdb::AuthBackendError("Create Client: UUID already Exists aborting!"); } } size_t wd=backend.end(); for(AuthData *curec=data; curec; curec=curec->next()){ curec->Data->type=UserData; curec->Data->type=ClientData; backend.setPos(wd); backend.write((unsigned char*)curec->Data,sizeof(struct AuthData::Record)); backend.write((unsigned char*)curec->Data->data,curec->Data->datasize); Loading Loading @@ -115,7 +124,7 @@ void authdb::Client::info(AuthBackend& backend, class ClientData& dat, size_t& p && strcmp(cur->fieldname,"clientname")==0 ){ if(!getRecord(backend,dat,DataType::UserData)) if(!getRecord(backend,dat,DataType::ClientData)) continue; if(strcmp(dat.Data->fieldname,"clientname")==0){ Loading src/client.h +3 −0 Changes for src/client.h: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -33,6 +33,9 @@ namespace authdb { class ClientData : public AuthData { public: ClientData(uuid_t clid); ~ClientData(); void setName(const char* name); const char *getName(); Loading Loading
src/admin.cpp +63 −3 Changes for src/admin.cpp: 63 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ #include "hash/sha512.h" #include "session.h" #include "gpo.h" #include "client.h" namespace authdb { class AdminController { Loading Loading @@ -2133,11 +2134,30 @@ namespace authdb { form.parse(curreq); if(form.UrlFormData.getFormData()){ uuid_t clid; uuid_generate(clid); class ClientData cdat(clid); std::string key,keyhash; for(libhttppp::HttpForm::UrlcodedForm::Data *curdat=form.UrlFormData.getFormData(); curdat; curdat=curdat->nextData() ){ if( strcmp(curdat->getKey(),"clientname")==0 ) cdat.setName(curdat->getValue()); else if (strcmp(curdat->getKey(),"clientkey")==0) key=curdat->getValue(); } sha512 hash; hash.hash(key,keyhash); cdat.setKey(keyhash.c_str()); Client clt; clt.create(*backend,&cdat); libhttppp::HttpResponse rep; rep.setState(HTTP303); rep.setVersion(HTTPVERSION(1.1)); Loading Loading @@ -2165,12 +2185,14 @@ namespace authdb { submitl.insertChild(submit); lname.insertChild(libhtmlpp::TextElement("Client name:")); lname.setAttribute("for","clientname"); name.setAttribute("type","text"); name.setAttribute("name","clientname"); lsecret.insertChild(libhtmlpp::TextElement("Client secret:")); secret.setAttribute("type","text"); secret.setAttribute("name","secret"); lsecret.setAttribute("for","clientkey"); secret.setAttribute("type","password"); secret.setAttribute("name","clientkey"); namel.appendChild(lname); namel.appendChild(name); Loading Loading @@ -2248,11 +2270,49 @@ namespace authdb { toolbar.insertChild(list); libhtmlpp::HtmlElement clist("ul"); size_t rd=sizeof(authdb::AuthHeader),end=backend->end(); Client clt; while(rd<end){ authdb::AuthData::Record cur; cur.type=EmptyData; backend->setPos(rd); backend->read((unsigned char*)&cur,sizeof(AuthData::Record)); rd=backend->getPos()+cur.datasize; if(cur.type == ClientData && strcmp(cur.fieldname,"clientname")==0){ class ClientData cdat(cur.uuid); try { size_t ccpos=sizeof(authdb::AuthHeader); clt.info(*backend,cdat,ccpos); char cruid[255]; uuid_unparse(cur.uuid,cruid); libhtmlpp::HtmlString clistdata; clistdata << "<li>" << cruid << ": " << cdat.getName() << "</li>"; clist.appendChild(clistdata.parse()); }catch(AuthBackendError &e){ std::cerr << e.what() << std::endl; } } } libhtmlpp::HtmlElement *content=index.getElementbyID("content"); if(content){ content->appendChild(domel); content->appendChild(headline); content->appendChild(clist); content->appendChild(toolbar); } Loading
src/client.cpp +13 −4 Changes for src/client.cpp: 13 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -27,6 +27,15 @@ #include "client.h" authdb::ClientData::ClientData(uuid_t clid) : AuthData(clid){ ClientKey=nullptr; ClientName=nullptr; } authdb::ClientData::~ClientData() { } void authdb::ClientData::setKey(const char *key){ setAuthData<char,char>(DataType::ClientData,StorageType::TextStorage, this,&ClientKey,"clientkey",key,strlen(key)+1); Loading Loading @@ -54,16 +63,16 @@ void authdb::Client::create(AuthBackend& backend, class ClientData* data){ if(exits(backend,&data->Data->uuid,data->getName(),exi)){ switch(exi){ case 1: throw authdb::AuthBackendError("Create User: Username already Exists aborting!"); throw authdb::AuthBackendError("Create Client: Username already Exists aborting!"); default: throw authdb::AuthBackendError("Create User: UUID already Exists aborting!"); throw authdb::AuthBackendError("Create Client: UUID already Exists aborting!"); } } size_t wd=backend.end(); for(AuthData *curec=data; curec; curec=curec->next()){ curec->Data->type=UserData; curec->Data->type=ClientData; backend.setPos(wd); backend.write((unsigned char*)curec->Data,sizeof(struct AuthData::Record)); backend.write((unsigned char*)curec->Data->data,curec->Data->datasize); Loading Loading @@ -115,7 +124,7 @@ void authdb::Client::info(AuthBackend& backend, class ClientData& dat, size_t& p && strcmp(cur->fieldname,"clientname")==0 ){ if(!getRecord(backend,dat,DataType::UserData)) if(!getRecord(backend,dat,DataType::ClientData)) continue; if(strcmp(dat.Data->fieldname,"clientname")==0){ Loading
src/client.h +3 −0 Changes for src/client.h: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -33,6 +33,9 @@ namespace authdb { class ClientData : public AuthData { public: ClientData(uuid_t clid); ~ClientData(); void setName(const char* name); const char *getName(); Loading