Commit 4c6c178b authored by jan.koester's avatar jan.koester
Browse files

gpo exists added to api

parent ecc15514
Loading
Loading
Loading
Loading
Loading
+38 −1
Changes for cli/authcli.cpp: 38 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -129,8 +129,42 @@ void editclient(int argc,char **argv){

}

void gpoexists(int argc,char **argv){
    cmdplus::CmdController &cmdc=cmdplus::CmdController::getInstance();

    cmdc.registerCmd("name",'n',true,nullptr,"Client Name");
    cmdc.registerCmd("secret",'s',true,nullptr,"Client Secret");
    cmdc.registerCmd("host-url",'h',true,nullptr,"Server Url");
    cmdc.registerCmd("gpoid",'g',true,nullptr,"GPO Id");

    cmdc.parseCmd(argc,argv);

    if(!cmdc.checkRequired()){
        cmdc.printHelp();
        return;
    }

    authdb::client::ClientConnection con;

    con.setUrl(cmdc.getCmdbyKey("host-url")->getValue());
    con.setClientName(cmdc.getCmdbyKey("name")->getValue());
    con.setClientSecret(cmdc.getCmdbyKey("secret")->getValue());

    authdb::client::Client clt(con);
    if(clt.ClientAuth()){
        if(clt.GPOexits(
            cmdc.getCmdbyKey("gpoid")->getValue()
        )){
            std::cout << "true" << std::endl;
        }else{
            std::cout << "false" << std::endl;
        }
    }

}

int main(int argc,char **argv){
    if(argc<1){
    if(argc<2){
        std::cerr << "Please Enter Command !" << std::endl;
    }

@@ -140,11 +174,14 @@ int main(int argc,char **argv){
        remclient(argc-1,argv+1);
    }else if(strcmp(argv[1],"editclient")==0){
        editclient(argc-1,argv+1);
    }else if(strcmp(argv[1],"gpoexists")==0){
        gpoexists(argc-1,argv+1);
    }else{
        std::cerr << "commands:" << std::endl;
        std::cerr << "addclient" << std::endl;
        std::cerr << "remclient" << std::endl;
        std::cerr << "editclient" << std::endl;
        std::cerr << "gpoexists" << std::endl;
    }


+58 −0
Changes for client/client.cpp: 58 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -537,3 +537,61 @@ void authdb::client::Client::editConnection(const uuid& clientid,const std::stri

    resp.push_back('\0');
}

bool authdb::client::Client::GPOexits(class uuid gpoid){
    json_object *jresponse = json_object_new_object();
    json_object *cmd=json_object_new_array();
    json_object *obj=json_object_new_object();

    json_object_object_add(obj,"clientsession", json_object_new_string(_Con.getClientId().c_str()));
    json_object_object_add(obj,"gpoexists",json_object_new_string(gpoid.c_str()));

    json_object_array_add(cmd,obj);

    json_object_object_add(jresponse,"commands",cmd);

    size_t outsize=0;

    std::vector<char> out;

    const char *tmp=json_object_to_json_string_length(jresponse,0,&outsize);

    std::copy(tmp,tmp+outsize,std::back_inserter(out));


    libhttppp::HttpRequest nreq;
    nreq.setHeaderData("accept")->push_back("text/json");
    nreq.setRequestURL(_Con._Url.getPath().c_str());
    std::vector<char> resp(_Con._Client->Post(nreq,out));

    resp.push_back('\0');

    json_object_put(jresponse);

    json_object *jrequest;
    json_tokener*jtok=json_tokener_new();

    jrequest=json_tokener_parse_ex(jtok,resp.data(),resp.size());

    if(!jrequest){
        throw authdb::AuthBackendError(json_tokener_error_desc(json_tokener_get_error(jtok)));
    }

    if(json_object_get_type(jrequest)!=json_type::json_type_array)
        throw(authdb::AuthBackendError("Invalid Api Commands"));

    bool ret=false;

    int fcount = json_object_array_length(jrequest);
    for(int i =0; i<fcount; ++i) {
        json_object_object_foreach(json_object_array_get_idx(jrequest,i), key, val) {
            if(strcmp(key,"gpoexists")==0){
                ret=json_object_get_boolean(json_object_object_get(val,gpoid.c_str()));
                break;
            }
        }
    }
    json_object_put(jrequest);
    json_tokener_free(jtok);
    return ret;
}
+1 −0
Changes for client/client.h: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ namespace authdb {
            bool remSession();

            bool GPOcheck(class uuid gpoid);
            bool GPOexits(class uuid gpoid);

            void UserInfo(class UserData &udat);
            void changeUserPw(const std::string& oldpw,const std::string& newpw);
+4 −2
Changes for src/api.cpp: 4 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -297,8 +297,6 @@ namespace authdb {
            if(!cmd || json_object_get_type(cmd)!=json_type::json_type_array)
                throw(AuthBackendError("Invalid Api Commands"));

            std::cout << "test" << std::endl;

            int fcount = json_object_array_length(cmd);
            for(int i =0; i<fcount; ++i) {
                json_object_object_foreach(json_object_array_get_idx(cmd,i), key, val) {
@@ -544,6 +542,10 @@ namespace authdb {
                    _SessionData=userLogin(jrequest,jresponse);
            }

            if(curcon){
                existsGPO(jrequest,jresponse);
            }

            if(_SessionData){
                Connection(jrequest,jresponse);
            }