Commit 5d2298b7 authored by jan.koester's avatar jan.koester
Browse files

work work

parent 12f2d7aa
Loading
Loading
Loading
Loading
+134 −0
Changes for src/authdb.cpp: 134 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -985,8 +985,142 @@ namespace authdb {
        }

        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);

            AuthBackend *backend=nullptr;

            if(strcmp(cdid,"admin")!=0){
                if(uuid_parse(cdid,did)<0)
                    throw AuthBackendError("createGroups: wrong domain id !");
                backend=dbackend.data(did);
            }else{
                backend=&_AdminBackend;
            }

            if(!backend)
                throw AuthBackendError("createGroups: no backend seleted!");

            libhttppp::HttpForm curform;
            curform.parse(curreq);

            if (curform.getBoundary()) {
                size_t gcount=0;
                std::string gname;

                uuid_t gid;
                uuid_generate(gid);

                class GroupData grp(gid);

                for (libhttppp::HttpForm::MultipartForm::Data* curformdat = curform.MultipartFormData.getFormData();
                     curformdat; curformdat = curformdat->nextData()) {

                    if(curformdat->Value.empty())
                        continue;


                    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" && strcmp(curdispo->getValue(),"members")==0){
                            ++gcount;
                        }

                        if(tmp=="name" && strcmp(curdispo->getValue(),"groupname")==0){
                            std::copy(curformdat->Value.begin(),curformdat->Value.end(),std::back_inserter(gname));
                        }

                    }
                }

                if(gname.empty())
                    throw AuthBackendError("createGroups: no doamin name given");

                grp.Members->count=gcount;
                grp.Members->uid = new uuid_t[gcount];

                size_t git=0;

                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()
                    ){
                        std::string tmp=curdispo->getKey();

                        std::transform(tmp.begin(), tmp.end(), tmp.begin(),
                                       [](unsigned char c){ return std::tolower(c); });

                        if(tmp=="name" && strcmp(curdispo->getValue(),"members")==0){
                            uuid_parse(curformdat->Value.data(),grp.Members->uid[git]);
                            ++git;
                        }
                    }

                }

                delete[] grp.Members->uid;
            }

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

            form  << "<form method=\"post\" enctype=\"multipart/form-data\">"
                  << "<table>"
                  << "<tr><th>Create Group:</th></tr>"
                  << "<tr><td><label for=\"groupname\">groupname:</label></td>"
                  << "<td><input type=\"text\" name=\"groupname\"></td></tr>"
                  << "<tr><td>Members:</td>"
                  << "<td><select name=\"members\" multiple>";
            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 == UserData && strcmp(cur.fieldname,"username")==0){
                    cur.data=new char[cur.datasize];
                    backend->read((unsigned char*)cur.data,cur.datasize);
                    char cuid[255];
                    uuid_unparse(cur.uuid,cuid);
                    form << "<option value=\"" << cuid << "\">" << cur.data << "</option>";
                    delete[] cur.data;
                }

            }
            form  << "</select></td></tr>"
                  << "<tr><td></td><td><input type=\"submit\" value=\"Create group\"></td></tr>"
                  << "</table>"
                  << "</form";

            content->appendChild(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 SettingsController(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){
+8 −0
Changes for src/group.cpp: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -26,3 +26,11 @@
 *******************************************************************************/

#include "group.h"

authdb::GroupData::GroupData(uuid_t gid){
    Members=new GroupData::MemberUids;
}

authdb::GroupData::~GroupData(){
    delete Members;
}