Loading CMakeLists.txt +1 −0 Changes for CMakeLists.txt: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -6,5 +6,6 @@ find_package(libconfplus REQUIRED) find_package(libcmdplus REQUIRED) find_package(libnetplus REQUIRED) find_package(libhttppp REQUIRED) find_package(libhtmlpp REQUIRED) add_subdirectory(src) data/admin.htmldeleted 100644 → 0 +0 −1 Changes for data/admin.html: 0 added lines, 1 removed line. Original line number Diff line number Diff line src/CMakeLists.txt +1 −1 Changes for src/CMakeLists.txt: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -10,4 +10,4 @@ add_executable( authdb ${authdbSrcs} ) target_link_libraries(authdb PUBLIC fback httppp::httppp netplus::netplus confplus::confplus cmdplus::cmdplus uuid) target_link_libraries(authdb PUBLIC fback httppp::httppp netplus::netplus confplus::confplus cmdplus::cmdplus htmlpp::htmlpp uuid) src/authdb.cpp +83 −1 Changes for src/authdb.cpp: 83 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -34,9 +34,11 @@ #include <confplus/conf.h> #include <httppp/httpd.h> #include <htmlpp/html.h> #include "backend.h" #include "authdb.h" #include "user.h" namespace authdb { class AuthDB : public libhttppp::HttpEvent{ Loading @@ -45,7 +47,7 @@ namespace authdb { }; void RequestEvent(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){ void listUsers(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){ _Backend.lock(); authdb::AuthData cur; Loading Loading @@ -89,6 +91,86 @@ namespace authdb { rep.setContentType("text/txt"); rep.setContentLength(userlist.length()); rep.send(curreq,userlist.c_str(),userlist.length()); } void createUser(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){ libhttppp::HttpResponse rep; libhttppp::HttpForm curform; curform.parse(curreq); if (curform.getBoundary()) { uuid_t uid; uuid_generate(uid); UserData udat(uid); for (libhttppp::HttpForm::MultipartForm::Data* curformdat = curform.MultipartFormData.getFormData(); curformdat; curformdat = curformdat->nextData()) { for(libhttppp::HttpForm::MultipartForm::Data::ContentDisposition *curdispo=curformdat->getDisposition(); curdispo; curdispo=curdispo->nextContentDisposition() ){ if(strcmp(curdispo->getValue(),"username")==0){ udat.setUserName(curformdat->Value.data()); }else if(strcmp(curdispo->getValue(),"firstname")==0){ udat.setFirstName(curformdat->Value.data()); }else if(strcmp(curdispo->getValue(),"lastname")==0){ udat.setLastName(curformdat->Value.data()); }else if(strcmp(curdispo->getValue(),"mail")==0){ udat.setMail(curformdat->Value.data()); }else if(strcmp(curdispo->getValue(),"avatar")==0){ udat.setAvatar(curformdat->Value); } } } User user; user.create(_Backend,&udat); std::cout << "user created!" << std::endl; } libhtmlpp::HtmlElement *root; libhtmlpp::HtmlPage page; libhtmlpp::HtmlString content,out; content << "<!DOCTYPE HTML>\r\n" << "<html>" << "<body>" << "<form method=\"post\" enctype=\"multipart/form-data\"><ul>" << "<li><label for=\"username\">username:</label>" << "<input type=\"text\" name=\"username\"></li>" << "<li><label for=\"firstname\">firstname:</label>" << "<input type=\"text\" name=\"firstname\"></li>" << "<li><label for=\"lastname\">lastname:</label>" << "<input type=\"text\" name=\"lastname\"></li>" << "<li><label for=\"mail\">mail:</label>" << "<input type=\"text\" name=\"mail\"></li>" << "<li><label for=\"avatar\">ProfilBild:</label>" << "<input type=\"file\" name=\"avatar\"></li>" << "<li><input type=\"submit\"></li>" << "<ul></form>" << "</body>"; root=(libhtmlpp::HtmlElement*)content.parse(); libhtmlpp::print(root,out,true); rep.setContentType("text/html"); rep.setContentLength(out.size()); rep.send(curreq,out.c_str(),out.size()); } void AdminController(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){ if(strncmp(curreq->getRequestURL(),"/admin/listusers",16)==0){ listUsers(curreq,tid,args); }else if(strncmp(curreq->getRequestURL(),"/admin/createuser",17)==0){ createUser(curreq,tid,args); } } void RequestEvent(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){ if(strncmp(curreq->getRequestURL(),"/admin",6)==0){ AdminController(curreq,tid,args); } }; private: authdb::AuthBackend &_Backend; Loading src/user.cpp +15 −8 Changes for src/user.cpp: 15 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -36,6 +36,12 @@ authdb::UserData::UserData(uuid_t id){ Data->Data.type=-1; username=nullptr; firstname=nullptr; lastname=nullptr; mail=nullptr; pwhash=nullptr; avatar=nullptr; } authdb::UserData::~UserData(){ Loading @@ -59,8 +65,8 @@ void authdb::UserData::setFirstName(const char* src){ while(!target){ target=target->next(); }; target=new AuthDataRecord; } target=new AuthDataRecord; } } target->Data.type=1; Loading Loading @@ -90,8 +96,8 @@ void authdb::UserData::setLastName(const char* src){ while(!target){ target=target->next(); }; target=new AuthDataRecord; } target=new AuthDataRecord; } } target->Data.type=1; Loading Loading @@ -121,8 +127,8 @@ void authdb::UserData::setMail(const char* src){ while(!target){ target=target->next(); }; target=new AuthDataRecord; } target=new AuthDataRecord; } } target->Data.type=1; Loading Loading @@ -152,8 +158,8 @@ void authdb::UserData::setPwHash(const char* src){ while(!target){ target=target->next(); }; target=new AuthDataRecord; } target=new AuthDataRecord; } } target->Data.type=1; Loading Loading @@ -183,12 +189,12 @@ void authdb::UserData::setUserName(const char* src){ while(!target){ target=target->next(); }; target=new AuthDataRecord; } target=new AuthDataRecord; } } target->Data.type=1; target->Data.type=1; memcpy(target->Data.uuid,Data->Data.uuid,strlen(Data->Data.uuid)+1); snprintf(target->Data.fieldname,255,"%s","username"); target->Data.datasize=strlen(src); Loading @@ -214,10 +220,11 @@ void authdb::UserData::setAvatar(const std::vector<char>& src){ while(!target){ target=target->next(); }; target=new AuthDataRecord; } target=new AuthDataRecord; } } target->Data.type=1; memcpy(target->Data.uuid,Data->Data.uuid,strlen(Data->Data.uuid)+1); Loading @@ -230,7 +237,7 @@ void authdb::UserData::setAvatar(const std::vector<char>& src){ } void authdb::User::create(AuthBackend &backend, class UserData* dat){ void authdb::User::create(AuthBackend &backend,UserData* dat){ authdb::AuthData cur; size_t rd=sizeof(authdb::AuthHeader),end=backend.end(); Loading Loading
CMakeLists.txt +1 −0 Changes for CMakeLists.txt: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -6,5 +6,6 @@ find_package(libconfplus REQUIRED) find_package(libcmdplus REQUIRED) find_package(libnetplus REQUIRED) find_package(libhttppp REQUIRED) find_package(libhtmlpp REQUIRED) add_subdirectory(src)
data/admin.htmldeleted 100644 → 0 +0 −1 Changes for data/admin.html: 0 added lines, 1 removed line. Original line number Diff line number Diff line
src/CMakeLists.txt +1 −1 Changes for src/CMakeLists.txt: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -10,4 +10,4 @@ add_executable( authdb ${authdbSrcs} ) target_link_libraries(authdb PUBLIC fback httppp::httppp netplus::netplus confplus::confplus cmdplus::cmdplus uuid) target_link_libraries(authdb PUBLIC fback httppp::httppp netplus::netplus confplus::confplus cmdplus::cmdplus htmlpp::htmlpp uuid)
src/authdb.cpp +83 −1 Changes for src/authdb.cpp: 83 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -34,9 +34,11 @@ #include <confplus/conf.h> #include <httppp/httpd.h> #include <htmlpp/html.h> #include "backend.h" #include "authdb.h" #include "user.h" namespace authdb { class AuthDB : public libhttppp::HttpEvent{ Loading @@ -45,7 +47,7 @@ namespace authdb { }; void RequestEvent(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){ void listUsers(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){ _Backend.lock(); authdb::AuthData cur; Loading Loading @@ -89,6 +91,86 @@ namespace authdb { rep.setContentType("text/txt"); rep.setContentLength(userlist.length()); rep.send(curreq,userlist.c_str(),userlist.length()); } void createUser(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){ libhttppp::HttpResponse rep; libhttppp::HttpForm curform; curform.parse(curreq); if (curform.getBoundary()) { uuid_t uid; uuid_generate(uid); UserData udat(uid); for (libhttppp::HttpForm::MultipartForm::Data* curformdat = curform.MultipartFormData.getFormData(); curformdat; curformdat = curformdat->nextData()) { for(libhttppp::HttpForm::MultipartForm::Data::ContentDisposition *curdispo=curformdat->getDisposition(); curdispo; curdispo=curdispo->nextContentDisposition() ){ if(strcmp(curdispo->getValue(),"username")==0){ udat.setUserName(curformdat->Value.data()); }else if(strcmp(curdispo->getValue(),"firstname")==0){ udat.setFirstName(curformdat->Value.data()); }else if(strcmp(curdispo->getValue(),"lastname")==0){ udat.setLastName(curformdat->Value.data()); }else if(strcmp(curdispo->getValue(),"mail")==0){ udat.setMail(curformdat->Value.data()); }else if(strcmp(curdispo->getValue(),"avatar")==0){ udat.setAvatar(curformdat->Value); } } } User user; user.create(_Backend,&udat); std::cout << "user created!" << std::endl; } libhtmlpp::HtmlElement *root; libhtmlpp::HtmlPage page; libhtmlpp::HtmlString content,out; content << "<!DOCTYPE HTML>\r\n" << "<html>" << "<body>" << "<form method=\"post\" enctype=\"multipart/form-data\"><ul>" << "<li><label for=\"username\">username:</label>" << "<input type=\"text\" name=\"username\"></li>" << "<li><label for=\"firstname\">firstname:</label>" << "<input type=\"text\" name=\"firstname\"></li>" << "<li><label for=\"lastname\">lastname:</label>" << "<input type=\"text\" name=\"lastname\"></li>" << "<li><label for=\"mail\">mail:</label>" << "<input type=\"text\" name=\"mail\"></li>" << "<li><label for=\"avatar\">ProfilBild:</label>" << "<input type=\"file\" name=\"avatar\"></li>" << "<li><input type=\"submit\"></li>" << "<ul></form>" << "</body>"; root=(libhtmlpp::HtmlElement*)content.parse(); libhtmlpp::print(root,out,true); rep.setContentType("text/html"); rep.setContentLength(out.size()); rep.send(curreq,out.c_str(),out.size()); } void AdminController(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){ if(strncmp(curreq->getRequestURL(),"/admin/listusers",16)==0){ listUsers(curreq,tid,args); }else if(strncmp(curreq->getRequestURL(),"/admin/createuser",17)==0){ createUser(curreq,tid,args); } } void RequestEvent(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){ if(strncmp(curreq->getRequestURL(),"/admin",6)==0){ AdminController(curreq,tid,args); } }; private: authdb::AuthBackend &_Backend; Loading
src/user.cpp +15 −8 Changes for src/user.cpp: 15 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -36,6 +36,12 @@ authdb::UserData::UserData(uuid_t id){ Data->Data.type=-1; username=nullptr; firstname=nullptr; lastname=nullptr; mail=nullptr; pwhash=nullptr; avatar=nullptr; } authdb::UserData::~UserData(){ Loading @@ -59,8 +65,8 @@ void authdb::UserData::setFirstName(const char* src){ while(!target){ target=target->next(); }; target=new AuthDataRecord; } target=new AuthDataRecord; } } target->Data.type=1; Loading Loading @@ -90,8 +96,8 @@ void authdb::UserData::setLastName(const char* src){ while(!target){ target=target->next(); }; target=new AuthDataRecord; } target=new AuthDataRecord; } } target->Data.type=1; Loading Loading @@ -121,8 +127,8 @@ void authdb::UserData::setMail(const char* src){ while(!target){ target=target->next(); }; target=new AuthDataRecord; } target=new AuthDataRecord; } } target->Data.type=1; Loading Loading @@ -152,8 +158,8 @@ void authdb::UserData::setPwHash(const char* src){ while(!target){ target=target->next(); }; target=new AuthDataRecord; } target=new AuthDataRecord; } } target->Data.type=1; Loading Loading @@ -183,12 +189,12 @@ void authdb::UserData::setUserName(const char* src){ while(!target){ target=target->next(); }; target=new AuthDataRecord; } target=new AuthDataRecord; } } target->Data.type=1; target->Data.type=1; memcpy(target->Data.uuid,Data->Data.uuid,strlen(Data->Data.uuid)+1); snprintf(target->Data.fieldname,255,"%s","username"); target->Data.datasize=strlen(src); Loading @@ -214,10 +220,11 @@ void authdb::UserData::setAvatar(const std::vector<char>& src){ while(!target){ target=target->next(); }; target=new AuthDataRecord; } target=new AuthDataRecord; } } target->Data.type=1; memcpy(target->Data.uuid,Data->Data.uuid,strlen(Data->Data.uuid)+1); Loading @@ -230,7 +237,7 @@ void authdb::UserData::setAvatar(const std::vector<char>& src){ } void authdb::User::create(AuthBackend &backend, class UserData* dat){ void authdb::User::create(AuthBackend &backend,UserData* dat){ authdb::AuthData cur; size_t rd=sizeof(authdb::AuthHeader),end=backend.end(); Loading