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.
*******************************************************************************/
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
95
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;
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=="filename"){
stortype=BinaryStorage;
}
if(stortype==EmptyStorage){
bool numeric=true;
for(auto i : curformdat->Value){
if(!std::isdigit(i)){
numeric=false;
break;
}
}
if(!numeric)
stortype=TextStorage;
else
stortype=IntStorage;
}
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);
udat.Data->append(cudat);
delete[] cudat.data;
}else if(cudat.storage==TextStorage){
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';
curformdat->Value.push_back('\0');
cudat.datasize=curformdat->Value.size();
cudat.data=new char[cudat.datasize];
memcpy(cudat.data,curformdat->Value.data(),
curformdat->Value.size());
}else if(cudat.storage==IntStorage){
curformdat->Value.push_back('\0');
int val=atoi(curformdat->Value.data());
cudat.datasize=sizeof(int);
cudat.data=(char*)new int;
memcpy(cudat.data,&val,
curformdat->Value.size());
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;
if(curdispo->getKey())
key=curdispo->getKey();
else
continue;
std::transform(key.begin(), key.end(), key.begin(),
[](unsigned char c){ return std::tolower(c); });
if(key=="name"){
strcpy(curec.Data->fieldname,curdispo->getValue());
}
if(key=="filename"){
curec.Data->storage=BinaryStorage;
}
}
for(auto t : curformdat->Value){
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()+1;
curec.Data->data=new char[curec.Data->datasize];
std::copy(pwhash.begin(),pwhash.end(),curec.Data->data);
curec.Data->data[pwhash.length()]='\0';
std::copy(curformdat->Value.begin(),
curformdat->Value.end(),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()\">";
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
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){
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
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){
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
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);
}
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
void listGroups(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args,const char *url){
libhtmlpp::HtmlString grouplist,out,ddat;
libhtmlpp::HtmlElement root=_IndexElement;
libhtmlpp::HtmlElement *content=root.getElementbyID("content"),*domel=nullptr;
Group group;
domel=DomainChangeForm(curreq,url,_AdminBackend,ddat);
if(!domel){
throw AuthBackendError("listGroups: cannot load doamin's!");
}
char cdid[255];
uuid_t did;
if(sscanf(curreq->getRequestURL(),"/settings/%[^/]",cdid)<0){
throw AuthBackendError("listGroups: 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("listGroups: could not parse uuid!");
}
size_t rd=sizeof(authdb::AuthHeader),end=backend->end();
content->appendChild(domel);
grouplist << "<div><ul class=\"grouptoolbar\" ><li><a class=\"button\" href=\"/settings/"<< cdid << "/creategroup\">CreateGroup</a></li></ul></div>";
content->appendChild(grouplist.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 createGroup(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args,const char *url){
libhtmlpp::HtmlString form,out;
libhtmlpp::HtmlElement root=_IndexElement,*content=root.getElementbyID("content");
char cdid[255];
uuid_t did;
if(sscanf(curreq->getRequestURL(),"/settings/%[^/]",cdid)<0){
throw AuthBackendError("createGroups: wrong url!");
}
DomainBackend dbackend(_AdminBackend);