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){
Loading
Loading full blame...