Newer
Older
/*******************************************************************************
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
class DomainBackend {
public:
DomainBackend(authdb::AuthBackend &adminbck) : _adminbck(adminbck) {
_domainbck=nullptr;
}
authdb::AuthBackend *data(uuid_t did){
size_t rd=sizeof(authdb::AuthHeader),end=_adminbck.end();
while(rd<end){
authdb::AuthData::Record cur;
_adminbck.setPos(rd);
_adminbck.read((unsigned char*)&cur,sizeof(AuthData::Record));
rd=_adminbck.getPos()+cur.datasize;
if(uuid_compare(cur.uuid,did) == 0 && cur.type == DataType::DomainData &&
strcmp(cur.fieldname,"domainName")==0){
class DomainData ddat(cur.uuid);
size_t dpos=sizeof(authdb::AuthHeader);
Domain domain;
domain.info(_adminbck,ddat,dpos);
_domainbck = new AuthBackend(ddat.getStorageType(),ddat.getStorageOptions(),ddat.getDomainName());
}
}
return _domainbck;
}
~DomainBackend(){
delete _domainbck;
}
private:
authdb::AuthBackend &_adminbck;
authdb::AuthBackend *_domainbck;
};
class AuthDB : public libhttppp::HttpEvent{
public:
AuthDB(authdb::AuthBackend &backend,netplus::socket *ssock) : HttpEvent(ssock), _AdminBackend(backend){
_Indexpage.loadFile(_IndexElement,"../data/index.html");
std::ifstream authfs("../data/authdb.js", std::ios::ate);
size_t asize = authfs.tellg();
_AuthJs.resize(asize);
authfs.seekg(0);
authfs.read(_AuthJs.data(),asize);
void listUsers(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args,const char *url){
libhtmlpp::HtmlElement *content=root.getElementbyID("content"),*domel=nullptr;
if(!domel){
throw AuthBackendError("listUsers: cannot load doamin's!");
}
char cdid[255];
uuid_t did;
if(sscanf(curreq->getRequestURL(),"/settings/%[^/]",cdid)<0){
throw AuthBackendError("listUsers: wrong url!");
}
DomainBackend dbackend(_AdminBackend);
AuthBackend *backend=nullptr;
if(strcmp(cdid,"admin") == 0 ){
backend=&_AdminBackend;
}else if(uuid_parse(cdid,did) == 0 ){
backend=dbackend.data(did);
}else{
throw AuthBackendError("listUsers: could not parse uuid!");
}
size_t rd=sizeof(authdb::AuthHeader),end=backend->end();
userlist <<"<div><p>UserList:</p><table class=\"userlist\">";
backend->setPos(rd);
backend->read((unsigned char*)&cur,sizeof(AuthData::Record));
if(cur.type == UserData && strcmp(cur.fieldname,"username")==0){
class UserData udat(cur.uuid);
char cruid[20];
uuid_unparse(cur.uuid,cruid);
userlist << "<tr><td class=\"list_username\">"
<< udat.getUsername()
<< "</td></tr>"
<< "<tr><td><img class=\"list_picture\" style=\"height:100px;\" src=\"" <<"/getavatar/" << cdid << "/" << cruid << ".jpg\" alt=\"avatar\">"
<< "</li>"
<< "<li><span>Firstname:</span><span>" << udat.getFirstname() << "</span></li>"
<< "<li><span>Lastname:</span><span>" << udat.getLastname() << "</span></li>"
<< "<li><span>Email:</span><span>" << udat.getMail() << "</span></li>"
<< "</ul></td><td><ul class=\"usertoolbar\" >"
<< "<li><a class=\"button\" href=\"/settings/"<< cdid << "/edituser/" << cruid << "\">EditUser</a></li>"
<< "<li><a class=\"button\" href=\"/settings/" << cdid << "/removeuser/" << cruid << "\">RemoveUser</a></li>"
<< "</ul></td></tr>";
}catch(AuthBackendError &e){
std::cerr << e.what() << std::endl;
userlist << "</table></div><div><ul class=\"usertoolbar\" ><li><a class=\"button\" href=\"/settings/"<< cdid << "/createuser\">CreateUser</a></li></ul></div>";
rep.setContentType("text/html");
rep.send(curreq,out.c_str(),out.size());
void createUser(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args,const char *baseurl){
libhttppp::HttpResponse rep;
libhttppp::HttpForm curform;
curform.parse(curreq);
uuid_t did;
if(sscanf(curreq->getRequestURL(),"/settings/%[^/]/*",cdid)<0){
throw AuthBackendError("createUser: wrong url!");
}
DomainBackend dbackend(_AdminBackend);
AuthBackend *backend=nullptr;
if(strcmp(cdid,"admin") == 0 ){
backend=&_AdminBackend;
}else if(uuid_parse(cdid,did) == 0 ){
backend=dbackend.data(did);
}else{
throw AuthBackendError("createUser: could not parse uuid!");
}
if (curform.getBoundary()) {
uuid_t uid;
uuid_generate(uid);
for (libhttppp::HttpForm::MultipartForm::Data* curformdat = curform.MultipartFormData.getFormData();
curformdat; curformdat = curformdat->nextData()) {
if(curformdat->Value.empty())
continue;
std::string name;
int stortype=TextStorage;
for(libhttppp::HttpForm::MultipartForm::Data::ContentDisposition *curdispo=curformdat->getDisposition();
curdispo; curdispo=curdispo->nextContentDisposition()
){
std::string tmp=curdispo->getKey();
std::transform(tmp.begin(), tmp.end(), tmp.begin(),
[](unsigned char c){ return std::tolower(c); });
if(tmp=="name")
name=curdispo->getValue();
if(tmp=="filename"){
stortype=BinaryStorage;
}
if(name.empty() || stortype == EmptyStorage)
continue;
struct AuthData::Record cudat;
memset(&cudat,0,sizeof(AuthData::Record));
cudat.start=0xFE;
uuid_copy(cudat.uuid,uid);
cudat.type=UserData;
cudat.storage=stortype;
strcpy(cudat.fieldname,name.c_str());
if(cudat.storage==BinaryStorage){
cudat.datasize=curformdat->Value.size();
cudat.data=new char[cudat.datasize];
memcpy(cudat.data,curformdat->Value.data(),
cudat.datasize);
}else{
if(strcmp(cudat.fieldname,"pwhash")==0){
Hash hash;
std::string pwhash,inpw;
std::copy(curformdat->Value.begin(),curformdat->Value.end(),
std::back_inserter(inpw));
hash.hash(inpw,pwhash);
cudat.datasize=pwhash.length()+1;
cudat.data=new char[cudat.datasize];
memcpy(cudat.data,pwhash.c_str(),pwhash.length());
cudat.data[pwhash.length()]='\0';
}else{
cudat.datasize=curformdat->Value.size()+1;
cudat.data=new char[cudat.datasize];
memcpy(cudat.data,curformdat->Value.data(),
curformdat->Value.size());
cudat.data[curformdat->Value.size()]='\0';
}
}
udat.Data->append(cudat);
delete[] cudat.data;
}
libhtmlpp::HtmlString form,out;
form << "<form method=\"post\" enctype=\"multipart/form-data\">"
<< "<table>"
<< "<tr><td><label for=\"username\">username:</label></td>"
<< "<td><input type=\"text\" name=\"username\"></td></tr>"
<< "<tr><td><label for=\"firstname\">firstname:</label></td>"
<< "<td><input type=\"text\" name=\"firstname\"></td></tr>"
<< "<tr><td><label for=\"lastname\">lastname:</label></td>"
<< "<td><input type=\"text\" name=\"lastname\"></td></tr>"
<< "<tr><td><label for=\"mail\">mail:</label></td>"
<< "<td><input type=\"text\" name=\"mail\"></td></tr>"
<< "<tr><td><label for=\"pwhash\">password:</label></td>"
<< "<td><input type=\"text\" name=\"pwhash\"></td></tr>"
<< "<tr><td><label for=\"avatar\">ProfilBild:</label></td>"
<< "<td><input type=\"file\" name=\"avatar\"></td></tr>"
<< "<tr><td></td><td><input type=\"submit\"></td></tr>"
<< "</table>"
<< "</form";
libhtmlpp::HtmlElement *content=root.getElementbyID("content");
content->insertChild(form.parse());
libhtmlpp::print(&root,out,true);
rep.setContentType("text/html");
rep.setContentLength(out.size());
rep.send(curreq,out.c_str(),out.size());
}
void removeuser(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){
char cdid[255],uid[255];
uuid_t did;
if(sscanf(curreq->getRequestURL(),"/settings/%[^/]/removeuser/%s",cdid,uid)<0){
throw AuthBackendError("listUsers: wrong url!");
}
DomainBackend dbackend(_AdminBackend);
AuthBackend *backend=nullptr;
if(strcmp(cdid,"admin") == 0 ){
backend=&_AdminBackend;
}else if(uuid_parse(cdid,did) == 0 ){
backend=dbackend.data(did);
}else{
throw AuthBackendError("listUsers: could not parse uuid!");
}
User user;
uuid_t uuid;
uuid_parse(uid,uuid);
libhttppp::HttpResponse rep;
rep.setState(HTTP307);
rep.setVersion(HTTPVERSION(1.1));
char rurl[255];
snprintf(rurl,255,"/settings/%s/listusers",cdid);
rep.setHeaderData("Location")->push_back(rurl);
rep.setContentType("text/html");
rep.send(curreq,nullptr,0);
void getAvatar(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){
libhttppp::HttpResponse rep;
DomainBackend dbackend(_AdminBackend);
AuthBackend *backend=nullptr;
if(sscanf(curreq->getRequestURL(),"/getavatar/%[^/]/%[^.].%s",domain,cuid,ext)<0)
}else if(uuid_parse(domain,did) == 0 ){
backend=dbackend.data(did);
size_t rd=sizeof(authdb::AuthHeader),end=backend->end();
backend->setPos(rd);
backend->read((unsigned char*)&cur,sizeof(AuthData::Record));
rd=backend->getPos()+cur.datasize;
if(uuid_compare(cur.uuid,uid)==0 && strcmp(cur.fieldname,"avatar")==0){
cur.data = new char[cur.datasize];
backend->read((unsigned char*)cur.data,cur.datasize);
char ctype[255];
snprintf(ctype,255,"image/%s",ext);
rep.setContentType(ctype);
}
}
if(end!=0){
rep.setState(HTTP404);
rep.send(curreq,nullptr,0);
}
};
void editUser(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){
char cdid[255],cuid[255];
uuid_t did;
if(sscanf(curreq->getRequestURL(),"/settings/%[^/]/edituser/%s",cdid,cuid)<0){
throw AuthBackendError("listUsers: wrong url!");
}
AuthBackend *backend=nullptr;
if(strcmp(cdid,"admin") == 0 ){
backend=&_AdminBackend;
}else if(uuid_parse(cdid,did) == 0 ){
backend=dbackend.data(did);
}else{
throw AuthBackendError("listUsers: could not parse uuid!");
}
size_t rd=sizeof(authdb::AuthHeader),end=backend->end();
uuid_t uid;
uuid_parse(cuid,uid);
AuthData editrec(uid);
bool data = false;
libhttppp::HttpForm curform;
curform.parse(curreq);
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(curformdat->Value.empty() || !curdispo->getValue())
continue;
data = true;
for(libhttppp::HttpForm::MultipartForm::Data::ContentDisposition *curdispo=curformdat->getDisposition();
curdispo; curdispo=curdispo->nextContentDisposition()
){
std::string key;
if(curdispo->getKey())
key=curdispo->getKey();
std::transform(key.begin(), key.end(), key.begin(),
[](unsigned char c){ return std::tolower(c); });
if(key=="name"){
if(curec.Data->storage==EmptyStorage){
bool numeric=true;
for(auto t=curformdat->Value.begin(); t!=curformdat->Value.end();
++t){
if(!std::isdigit(*t)){
numeric=false;
break;
}
}
if(numeric)
curec.Data->storage=IntStorage;
else
curec.Data->storage=TextStorage;
}
if(curec.Data->storage==TextStorage) {
curformdat->Value.push_back('\0');
if(strcmp(curec.Data->fieldname,"pwhash")==0){
Hash hash;
std::string pwhash,inpw;
std::copy(curformdat->Value.begin(),curformdat->Value.end(),
std::back_inserter(inpw));
hash.hash(inpw,pwhash);
curec.Data->datasize=pwhash.length();
curec.Data->data=new char[curec.Data->datasize];
memcpy(curec.Data->data,pwhash.c_str(),pwhash.length());
}else{
curec.Data->datasize=curformdat->Value.size();
curec.Data->data=new char[curec.Data->datasize];
memcpy(curec.Data->data,curformdat->Value.data(),
curformdat->Value.size());
}
editrec.append(curec);
delete[] curec.Data->data;
}else if(curec.Data->storage==BinaryStorage){
curec.Data->datasize=curformdat->Value.size();
curec.Data->data=new char[curec.Data->datasize];
memcpy(curec.Data->data,curformdat->Value.data(),
curformdat->Value.size());
editrec.append(curec);
delete[] curec.Data->data;
}else if(curec.Data->storage==IntStorage){
curformdat->Value.push_back('\0');
curec.Data->datasize=sizeof(int);
curec.Data->data=(char*)new int;
int val=atoi(curformdat->Value.data());
memcpy(curec.Data->data,&val,
curec.Data->datasize);
editrec.append(curec);
delete[] (int*)curec.Data->data;
}
libhttppp::HttpResponse rep;
rep.setState(HTTP307);
rep.setVersion(HTTPVERSION(1.1));
char rurl[255];
snprintf(rurl,255,"/settings/%s/listusers",cdid);
rep.setHeaderData("Location")->push_back(rurl);
rep.setContentType("text/html");
rep.send(curreq,nullptr,0);
return;
}
libhtmlpp::HtmlPage page;
libhtmlpp::HtmlString form,out;
form << "<form method=\"post\" enctype=\"multipart/form-data\">"
<< "<table>";
while(rd<end){
backend->setPos(rd);
backend->read((unsigned char*)&cur,sizeof(AuthData::Record));
rd=backend->getPos()+cur.datasize;
if(uuid_compare(cur.uuid,uid)==0 && cur.type==UserData && cur.storage==TextStorage){
cur.data = new char[cur.datasize];
form << "<tr><td><label for=\"username\">" << cur.fieldname << "</label></td>"
<< "<td><input type=\"text\" name=\"" << cur.fieldname << "\" value=\""
<< cur.data <<"\"></td></tr>";
}catch(AuthBackendError &e){
std::cerr << e.what() << std::endl;
}
}
}
form << "<tr><td><label for=\"avatar\">ProfilBild:</label></td>"
<< "<td><input type=\"file\" name=\"avatar\"></td></tr>"
<< "<tr><td></td><td><input type=\"submit\"></td></tr>"
<< "</table>"
<< "</form";
libhtmlpp::HtmlElement root=_IndexElement;
libhtmlpp::HtmlElement *content=root.getElementbyID("content");
content->insertChild(form.parse());
libhtmlpp::print(&root,out,true);
libhttppp::HttpResponse rep;
rep.setContentType("text/html");
rep.setContentLength(out.size());
rep.send(curreq,out.c_str(),out.size());
}
libhtmlpp::HtmlElement *DomainChangeForm(libhttppp::HttpRequest *curreq,const char *url,AuthBackend &backend,libhtmlpp::HtmlString &dest){
libhttppp::HttpForm form;
form.parse(curreq);
char cdid[255];
cdid[0]='\0';
for (libhttppp::HttpForm::UrlcodedForm::Data* cururlform = form.UrlFormData.getFormData(); cururlform;
cururlform = cururlform->nextData()) {
if( strcmp(cururlform->getKey(),"domaindid")==0){
if(strcmp(cdid,cururlform->getValue())!=0){
char rurl[255];
libhttppp::HttpResponse rep;
rep.setState(HTTP307);
rep.setVersion(HTTPVERSION(1.1));
rep.setHeaderData("Location")->push_back(rurl);
rep.setContentType("text/html");
rep.send(curreq,nullptr,0);
return nullptr;
}
}
}
size_t rd=sizeof(authdb::AuthHeader),end=backend.end();
Domain domain;
dest.clear();
dest << "<form method=\"post\" ><select name=\"domaindid\" onchange=\"this.form.submit()\">";
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
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 == DataType::DomainData && strcmp(cur.fieldname,"domainName")==0){
size_t dpos=sizeof(authdb::AuthHeader);
cur.data = new char[cur.datasize];
backend.read((unsigned char*)cur.data,cur.datasize);
char did[255];
uuid_unparse(cur.uuid,did);
dest << "<option value=\"" << did << "\" ";
if ( strcmp(cdid,did)==0 ){
dest << "selected";
}
dest << ">"
<< cur.data << "</option>";
delete [] cur.data;
}
}
dest << "</select></form>";
return (libhtmlpp::HtmlElement*)dest.parse();
}
void listDomains(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){
size_t rd=sizeof(authdb::AuthHeader),end=_AdminBackend.end();
libhtmlpp::HtmlString list,out;
libhtmlpp::HtmlElement root=_IndexElement;
libhtmlpp::HtmlElement *content=root.getElementbyID("content");
Domain domain;
list <<"<div><p>DomainList:</p><table class=\"domainlist\">";
while(rd<end){
authdb::AuthData::Record cur;
cur.type=EmptyData;
_AdminBackend.setPos(rd);
_AdminBackend.read((unsigned char*)&cur,sizeof(AuthData::Record));
if(cur.type == DataType::DomainData && strcmp(cur.fieldname,"domainName")==0){
class DomainData ddat(cur.uuid);
try {
size_t dpos=sizeof(authdb::AuthHeader);
char crdid[20];
uuid_unparse(cur.uuid,crdid);
list << "<tr><td>"
<< ddat.getDomainName()
<< "</td><td><ul><li>"
<< "Domainid: " << crdid
<< "</li>"
<< "<li><span>Storagetype: </span><span>" << ddat.getStorageType() << "</span></li>"
<< "<li><span>Storageoptions: </span><span>" << ddat.getStorageOptions() << "</span></li>"
<< "</ul></td><td><ul class=\"usertoolbar\" >"
<< "<li><a class=\"button\" href=\"/settings/" << crdid << "/removedomain\">RemoveDomain</a></li>"
<< "</ul></td></tr>";
}catch(AuthBackendError &e){
std::cerr << e.what() << std::endl;
}
}
}
<< "<li><a class=\"button\" href=\"/settings/admin/createdomain\">CreateDomain</a>"
libhtmlpp::print(&root,out,true);
libhttppp::HttpResponse rep;
rep.setContentType("text/html");
rep.setContentLength(out.size());
rep.send(curreq,out.c_str(),out.size());
}
void createDomain(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
libhttppp::HttpForm curform;
curform.parse(curreq);
if (curform.getBoundary()) {
uuid_t uid;
uuid_generate(uid);
class DomainData ddat(uid);
for (libhttppp::HttpForm::MultipartForm::Data* curformdat = curform.MultipartFormData.getFormData();
curformdat; curformdat = curformdat->nextData()) {
if(curformdat->Value.empty())
continue;
std::string name;
int stortype=TextStorage;
for(libhttppp::HttpForm::MultipartForm::Data::ContentDisposition *curdispo=curformdat->getDisposition();
curdispo; curdispo=curdispo->nextContentDisposition()
){
std::string tmp=curdispo->getKey();
std::transform(tmp.begin(), tmp.end(), tmp.begin(),
[](unsigned char c){ return std::tolower(c); });
if(tmp=="name")
name=curdispo->getValue();
if(tmp=="filename"){
stortype=BinaryStorage;
for(auto t=curformdat->Value.begin(); t!=curformdat->Value.end();
++t){
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
if(!std::isdigit(*t)){
numeric=false;
break;
}
}
if(numeric){
stortype=StorageType::IntStorage;
}
}
if(name.empty() || stortype == EmptyStorage)
continue;
struct AuthData::Record dodat;
memset(&dodat,0,sizeof(AuthData::Record));
dodat.start=0xFE;
uuid_copy(dodat.uuid,uid);
dodat.type=UserData;
dodat.storage=stortype;
strcpy(dodat.fieldname,name.c_str());
if(dodat.storage==TextStorage){
dodat.data=new char[dodat.datasize];
memcpy(dodat.data,curformdat->Value.data(),
curformdat->Value.size());
}else {
dodat.datasize=curformdat->Value.size();
dodat.data=new char[dodat.datasize];
memcpy(dodat.data,curformdat->Value.data(),
dodat.datasize);
libhtmlpp::HtmlString form,out;
libhtmlpp::HtmlElement root=_IndexElement;
libhtmlpp::HtmlElement *content=root.getElementbyID("content");
form << "<form method=\"post\" enctype=\"multipart/form-data\">"
<< "<table>"
<< "<tr><td><label for=\"domainName\">Domain Name:</label></td>"
<< "<td><input class=\"domaintext\" type=\"text\" name=\"domainName\" value=\"tuxist.de\"></td></tr>"
<< "<tr><td><label for=\"domainStorage\">Domain Storage:</label></td>"
<< "<td><select name=\"domainStorage\">"
<< "<option value=\""<< AuthBackendType::File << "\">File</option>"
<< "<tr><td><label for=\"domainOptions\">Domain Options:</label></td>"
<< "<td><input class=\"domaintext\" type=\"text\" name=\"domainOptions\" value=\"tuxist.de.db\"></td></tr>"
<< "<tr><td></td><td><input type=\"submit\" value=\"save\" ></td></tr>"
<< "</table>";
content->insertChild(form.parse());
libhtmlpp::print(&root,out,true);
libhttppp::HttpResponse rep;
rep.setContentType("text/html");
rep.setContentLength(out.size());
rep.send(curreq,out.c_str(),out.size());
}
void removeDomain(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){
char did[255];
sscanf(curreq->getRequestURL(),"/settings/%[^/]/removedomain",did);
libhttppp::HttpResponse rep;
rep.setState(HTTP307);
rep.setVersion(HTTPVERSION(1.1));
rep.setContentType("text/html");
rep.send(curreq,nullptr,0);
}
void SettingsController(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){
_AdminBackend.lock();
char domain[255],url[255];
if(sscanf(curreq->getRequestURL(),"/settings/%[^/]/%s",domain,url)<0)
libhttppp::HttpResponse rep;
rep.setContentType("text/javascript");
rep.send(curreq,_AuthJs.data(),_AuthJs.size());
}else{
libhtmlpp::HtmlElement root=_IndexElement;
libhtmlpp::HtmlString out;
libhtmlpp::print(&root,out,true);
libhttppp::HttpResponse rep;
rep.setContentType("text/html");
rep.setContentLength(out.size());
rep.send(curreq,out.c_str(),out.size());
}
}catch(AuthBackendError &e){
libhttppp::HttpResponse rep;
rep.setState(HTTP500);
rep.setContentType("text/html");
rep.send(curreq,e.what(),strlen(e.what()));
}
void RequestEvent(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){
if(strncmp(curreq->getRequestURL(),"/settings",9)==0){
SettingsController(curreq,tid,args);
}if(strncmp(curreq->getRequestURL(),"/getavatar/",11)==0){
getAvatar(curreq,tid,args);
}else if(strncmp(curreq->getRequestURL(),"/api",4)==0){
}else{
libhttppp::HttpResponse rep;
rep.setState(HTTP307);
rep.setVersion(HTTPVERSION(1.1));
rep.setHeaderData("Location")->push_back("/settings/admin/index");
libhtmlpp::HtmlElement _IndexElement;
libhtmlpp::HtmlPage _Indexpage;
};
int searchValue(authdb::AuthBackend &backend,const char*fieldname,const char *value){
int rd=sizeof(authdb::AuthHeader),brd=rd;
while(rd>backend.end()){
backend.setPos(rd);
backend.read((unsigned char*)user,sizeof(AuthData::Record));
user->data = new char[user->datasize];
backend.read((unsigned char*)user->data,user->datasize);
Data->type=DataType::EmptyData;
Data->fieldname[0]='\0';
Data->data=nullptr;
Data->datasize=0;
AuthData::AuthData(const AuthData &src) : AuthData(src.Data->uuid){