Commit f43a4b53 authored by jan.koester's avatar jan.koester
Browse files

test

parent c7275e73
Loading
Loading
Loading
Loading
Loading
+45 −28
Changes for src/admin.cpp: 45 added lines, 28 removed lines.
Original line number Diff line number Diff line
@@ -2082,53 +2082,64 @@ namespace authdb {
            libhtmlpp::HtmlElement* domel = DomainChangeForm(curreq, curreq.getRequestURL(), _AdminBackend, ddat);

            if (!domel) {
                throw AuthBackendError("listUsers: cannot load doamin's!");
                throw AuthBackendError("listUsers: cannot load domains!");
            }

            char cdid[255];
            const std::string requestURL = curreq.getRequestURL();
            std::string cdid;
            uuid::uuid did;

            if(sscanf(curreq.getRequestURL().c_str(),"/settings/%[^/]",cdid)<0){
                throw AuthBackendError("listUsers: wrong url!");
            static const std::string SETTINGS_PREFIX = "/settings/";
            const size_t prefixLength = SETTINGS_PREFIX.length();

            if (requestURL.find(SETTINGS_PREFIX) != 0) {
                throw AuthBackendError("listUsers: wrong url! (Missing prefix)");
            }

            DomainBackend dbackend(_AdminBackend);
            size_t nextSlash = requestURL.find('/', prefixLength);

            if (nextSlash == std::string::npos) {
                cdid = requestURL.substr(prefixLength);
            } else {
                cdid = requestURL.substr(prefixLength, nextSlash - prefixLength);
            }

            if (cdid.empty()) {
                throw AuthBackendError("listUsers: wrong url! (Empty domain ID)");
            }

            DomainBackend dbackend(_AdminBackend);
            AuthBackend* backend = nullptr;

            if(strcmp(cdid,"admin") == 0 ){
            if (cdid == "admin") {
                backend = &_AdminBackend;
            } else if (did.parse(cdid) == 0) {
                backend = dbackend.data(did);
            } else {
                throw AuthBackendError("listUsers: could not parse uuid!");
                throw AuthBackendError("listUsers: could not parse domain uuid!");
            }


            libhtmlpp::HtmlElement index = *_IndexElement;

            libhtmlpp::HtmlElement headline("span"),table("table"),toolbar("ul");

            libhtmlpp::HtmlElement headline("span"), toolbar("ul");
            headline.insertChild(libhtmlpp::TextElement("Clients"));

            toolbar.setAttribute("id", "clienttoolbar");

            libhtmlpp::HtmlElement create("a"),list("li");

            std::string crurl="/settings/"; crurl+=cdid; crurl+="/createclient";
            const std::string createUrl = "/settings/" + cdid + "/createclient";

            create.setAttribute("href",crurl.c_str());
            libhtmlpp::HtmlElement create("a"), list("li");
            create.setAttribute("href", createUrl.c_str());
            create.setAttribute("class", "button");
            create.insertChild(libhtmlpp::TextElement("Create client"));

            list.appendChild(create);

            toolbar.insertChild(list);

            libhtmlpp::HtmlElement clist("ul");

            size_t rd=sizeof(authdb::AuthHeader),end=backend->end();

            size_t rd = sizeof(authdb::AuthHeader);
            const size_t end = backend->end();
            Client clt;

            while (rd < end) {
@@ -2137,29 +2148,34 @@ namespace authdb {
                cur->type = EmptyData;

                backend->setPos(rd);
                backend->read((unsigned char*)cur.get(),sizeof(AuthData::Record));
                backend->read(reinterpret_cast<unsigned char*>(cur.get()), sizeof(authdb::AuthData::Record));

                rd = backend->getPos() + cur->datasize;

                if(cur->type == ClientData && strcmp(cur->fieldname,"clientname")==0){
                    class ClientData cdat(cur->ruid);
                if (cur->type == ClientData && std::string(cur->fieldname) == "clientname") {
                    try {
                        class ClientData cdat(cur->ruid);

                        size_t ccpos = sizeof(authdb::AuthHeader);
                        clt.info(*backend, cdat, ccpos);

                        libhtmlpp::HtmlString clistdata;
                        const std::string clientUuidStr = uuid::uuid(cur->ruid).c_str();

                        const std::string editUrl = "/settings/" + cdid + "/editclient/" + clientUuidStr;
                        const std::string removeUrl = "/settings/" + cdid + "/removeclient/" + clientUuidStr;

                        clistdata << "<li>" << uuid::uuid(cur->ruid).c_str() << ": " << cdat.getName()
                                  << "<a class=\"button\" href=\"/settings/" << cdid << "/"
                                  << "editclient/" << uuid::uuid(cur->ruid).c_str() << "\">Edit</a>"
                                  << "<a class=\"button\" href=\"/settings/" << cdid << "/"
                                  << "removeclient/" << uuid::uuid(cur->ruid).c_str() << "\">Delete</a>"
                        clistdata << "<li>" << clientUuidStr << ": " << cdat.getName()
                        << "<a class=\"button\" href=\"" << editUrl << "\">Edit</a>"
                        << "<a class=\"button\" href=\"" << removeUrl << "\">Delete</a>"
                        << "</li>";

                        clist.appendChild(clistdata.parse());

                    }catch(AuthBackendError &e){
                        std::cerr << e.what() << std::endl;
                    } catch (const AuthBackendError& e) {
                        std::cerr << "AuthBackendError: " << e.what() << std::endl;
                    } catch (const std::exception& e) {
                        std::cerr << "Standard Exception: " << e.what() << std::endl;
                    }
                }
            }
@@ -2169,8 +2185,8 @@ namespace authdb {
            if (content) {
                content->appendChild(domel);
                content->appendChild(headline);
                content->appendChild(toolbar); // Moved up
                content->appendChild(clist);
                content->appendChild(toolbar);
            }

            std::shared_ptr<libhtmlpp::HtmlString> sendat = std::make_shared<libhtmlpp::HtmlString>();
@@ -2181,6 +2197,7 @@ namespace authdb {
            rep.setState(HTTP200);
            rep.setVersion(HTTPVERSION(1.1));
            rep.setContentType("text/html");
            // Use the HtmlString's data and length for the response body
            rep.send(curreq, sendat->data(), sendat->length());
        }