Commit 9caca7f0 authored by jan.koester's avatar jan.koester
Browse files

test

parent 15d25eff
Loading
Loading
Loading
Loading
Loading
+1 −1
Changes for data/index.html: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
                    <li><a href="/settings/admin/listusers" >Users</a></li>
                    <li><a href="/settings/admin/listgroups" >Groups</a></li>
                    <li><a href="#" >Clients</a></li>
                    <li><a href="#" >Policies</a></li>
                    <li><a href="/settings/admin/listgpos" >Policies</a></li>
                    <li><a href="/settings/admin/listsessions" >Sessions</a></li>
                    <li><a href="/settings/logout" >Logout</a></li>
                </ul>
+102 −0
Changes for src/admin.cpp: 102 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -1496,6 +1496,104 @@ namespace authdb {
            rep.send(curreq,nullptr,0);
        }

        void createGpo(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){
            char cgpid[255],cdid[255];
            uuid_t gpid,did;

            uuid_clear(gpid);

            if(sscanf(curreq->getRequestURL(),"/settings/%[^/]/creategpo/%s",cdid,cgpid)<0){
                throw AuthBackendError("removeSession: wrong url!");
            }

            uuid_parse(cgpid,gpid);
            uuid_parse(cdid,did);

            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("login: could not parse uuid!");
            }

            libhtmlpp::HtmlPage page;

            libhtmlpp::HtmlString form,out;

            uuid_generate(gpid);

            uuid_unparse(gpid,cgpid);

            form  << "<form method=\"post\" enctype=\"multipart/form-data\">"
                  << "<table>"
                  << "<tr><td><label for=\"gpoid\">Policy ID:</label></td>"
                  << "<td><input type=\"text\" name=\"gpoid\" value=\"" << cgpid << "\"></td></tr>"
                  << "<tr><td><label for=\"gponame\">Policy Name:</label></td>"
                  << "<td><input type=\"text\" name=\"gponame\"></td></tr>"
                  << "<tr><td><label for=\"gpodesc\">Policy Description:</label></td>"
                  << "<td><input type=\"text\" name=\"gpodesc\"></td></tr>"
                  << "<tr><td></td><td><input type=\"submit\" value=\"Save\"></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());


            // char rurl[255];
            // snprintf(rurl,255,"/settings/%s/listgpos",cdid);
            //
            // libhttppp::HttpResponse rep;
            // rep.setState(HTTP303);
            // rep.setVersion(HTTPVERSION(1.1));
            // rep.setHeaderData("Location")->push_back(rurl);
            // rep.setContentType("text/html");
            // rep.send(curreq,nullptr,0);
        }

        void listGpos(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){
            char cdid[255];
            uuid_t did;

            uuid_clear(did);

            if(sscanf(curreq->getRequestURL(),"/settings/%[^/]/listgpos",cdid)<0){
                throw AuthBackendError("removeSession: wrong url!");
            }

            uuid_parse(cdid,did);

            libhtmlpp::HtmlElement root=_IndexElement;
            libhtmlpp::HtmlElement *content=root.getElementbyID("content");

            libhtmlpp::HtmlString list,out;

            list << "<div><ul class=\"gpotoolbar\" ><li><a class=\"button\" href=\"/settings/"<< cdid << "/creategpo\">Create Group Policy</a></li></ul></div>";

            content->insertChild(list.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 login(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){
            libhttppp::HttpForm form;

@@ -1701,6 +1799,10 @@ namespace authdb {
                removeSession(curreq,tid,args);
            }else if(strncmp("reloadsession",url,13)==0){
                reloadSession(curreq,tid,args);
            }else if(strncmp("creategpo",url,8)==0){
                createGpo(curreq,tid,args);
            }else if(strncmp("listgpos",url,8)==0){
                listGpos(curreq,tid,args);
            }else{
URLNOTFOUND:
                uuid_t did;
+54 −4
Changes for src/gpo.cpp: 54 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -174,12 +174,62 @@ const char * authdb::GpoData::getDesc(){
    return getGpoData(this,&_Desc,"gpodesc");
}

void authdb::GpoData::setAllowed(bool src){
    setGpoData(this,&_Allowed,"gpoallowed",src);
void authdb::GpoData::setGpoValue(bool dest){
    setGpoData(this,&_GpoDefault,"gpodefault",dest);
}

bool authdb::GpoData::getAlowed(){
    return getBoolGpoData(this,&_Allowed,"gpoallowed");
bool authdb::GpoData::getGpoValue(){
    return getBoolGpoData(this,&_GpoDefault,"gpodefault");
}



void authdb::GpoData::setAllowed(Allow *allowed, bool dest){
        AuthData *curec=this;

        uuid_t gid;
        uuid_copy(gid,Data->uuid);

        if(!_Allowed){
            while(curec){
                if(curec->Data->type == authdb::GroupData &&
                    uuid_compare(curec->Data->uuid,Data->uuid)==0 &&
                    strcmp(curec->Data->fieldname,"gpoallowed")==0
                ){
                    _Allowed=curec->Data;
                    _Allowed->datasize=0;
                    delete[] _Allowed->data;
                    _Allowed->data=nullptr;
                    break;
                }
                curec=curec->next();
            }
        }

        if(!_Allowed){
            AuthData::Record rec;
            _Allowed=append(rec)->Data;
        }

        memset(_Allowed,0,sizeof(AuthData::Record));

        _Allowed->start=0xFE;
        uuid_copy(_Allowed->uuid,gid);
        _Allowed->type=DataType::PolicyData;
        _Allowed->storage=StorageType::BinaryStorage;

        snprintf(_Allowed->fieldname,255,"%s","groupmembers");
        _Allowed->datasize = sizeof(GpoData::Allow)+(sizeof(Allow::Data)*allowed->count);
        _Allowed->data=new char [_Allowed->datasize];
        memset(_Allowed->data,0,_Allowed->datasize);
        char *start =_Allowed->data+sizeof(GpoData::Allow::AllowData);
        for(int i=0; i< allowed->count; ++i){
            memcpy(start+(i*sizeof(Allow::Data)),&allowed->AllowData[i],sizeof(Allow::Data));
        }
}

void authdb::GpoData::getAlowed(Allow *allowed){

}


+14 −3
Changes for src/gpo.h: 14 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -45,13 +45,24 @@ namespace authdb {
        void setDesc(const char *src);
        const char *getDesc();

        void setGpoValue(bool dest);
        bool getGpoValue();

        void setAllowed(bool src);
        bool getAlowed();

    protected:
        struct Allow {
            size_t count;
            struct Data {
                uuid_t uid;
                bool   allowed;
            } *AllowData;
        };
    public:
        void setAllowed(Allow *allowed, bool dest);
        void getAlowed(Allow *allowed);
    private:
        AuthData::Record *_Name;
        AuthData::Record *_Desc;
        AuthData::Record *_GpoDefault;
        AuthData::Record *_Allowed;
        friend class Gpo;
    };