Commit 98c0c81c authored by jan.koester's avatar jan.koester
Browse files

teswt

parent 935175ee
Loading
Loading
Loading
Loading
+0 −3
Changes for src/auth.cpp: 0 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@
#include "conf.h"
#include "theme.h"
#include "session.h"
#include "plugin.h"

namespace blogi {
  const uuid::uuid emptyuuid;
@@ -95,8 +94,6 @@ void blogi::Auth::_doLogin(const AuthSource &src, const char *username, const ch
        ret = clt.GPOcheck("e7d3b8b3-4825-11f0-ae2b-3cecefce9cb6");

        if(ret){
            PluginApi::registerPendingGPOs(clt);

            if(ssid){
                Session sess(*_dbconn[tid]);
                sess.addSessionData(*ssid,"authid",authcon.getSessionID().c_str());
+26 −5
Changes for src/edit.cpp: 26 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -61,11 +61,32 @@ blogi::webedit::WebEditor::WebEditor(PluginArgs &plgargs) : Args (plgargs){
#define GPO_EDITOR_IMPORTEXPORT "f46a4fd3-a69a-4fb4-a908-c5890a244386"

void blogi::webedit::WebEditor::registerEditorGPOs(){
    auto &list = PluginApi::getPendingGPOs();
    list.push_back({GPO_EDITOR_PUBLISH,      "Blogi: Publish Content",   "Controls access to publishing content from the editor", false});
    list.push_back({GPO_EDITOR_SHARE,        "Blogi: Share Posts",        "Controls access to sharing posts to social networks", false});
    list.push_back({GPO_EDITOR_TEMPLATES,    "Blogi: Manage Templates",   "Controls access to saving and loading editor templates", false});
    list.push_back({GPO_EDITOR_IMPORTEXPORT, "Blogi: Import/Export",      "Controls access to importing and exporting editor content", false});
    auto reg = [&](const char *gpoid, const char *name, const char *desc){
        try {
            if(Args.config->getAuthSourceCount() < 1)
                return;
            const AuthSource &src = Args.config->getAuthSource(0);
            authdb::client::ClientConnection authcon;
            authcon.setUrl(src.url);
            authcon.setClientName(src.clientName);
            authcon.setClientSecret(src.clientSecret);
            authdb::client::Client clt(authcon);
            if(clt.ClientAuth()){
                uuid::uuid gid(gpoid);
                if(!clt.GPOexits(gid)){
                    clt.GPOadd(gid, name, desc, false, {});
                }
            }
        } catch(const std::exception &e) {
            std::cerr << "Editor GPO registration failed for " << name << ": " << e.what() << std::endl;
        } catch(...) {
            std::cerr << "Editor GPO registration failed for " << name << std::endl;
        }
    };
    reg(GPO_EDITOR_PUBLISH,      "Blogi: Publish Content",   "Controls access to publishing content from the editor");
    reg(GPO_EDITOR_SHARE,        "Blogi: Share Posts",        "Controls access to sharing posts to social networks");
    reg(GPO_EDITOR_TEMPLATES,    "Blogi: Manage Templates",   "Controls access to saving and loading editor templates");
    reg(GPO_EDITOR_IMPORTEXPORT, "Blogi: Import/Export",      "Controls access to importing and exporting editor content");
}

bool blogi::webedit::WebEditor::checkEditorGPO(json_object *request, const char *gpoid){
+17 −27
Changes for src/plugin.cpp: 17 added lines, 27 removed lines.
Original line number Diff line number Diff line
@@ -28,10 +28,10 @@
#include <iostream>
#include <cstring>
#include <filesystem>
#include <mutex>
#include <atomic>

#include <httppp/exception.h>
#include <authdb/client.h>
#include <uuidp.h>

#ifdef Windows
#define WIN32_LEAN_AND_MEAN
@@ -40,6 +40,7 @@
#include <dlfcn.h>
#endif
#include "plugin.h"
#include "conf.h"

blogi::SearchRet::SearchRet(){
    _firstData=nullptr;
@@ -96,37 +97,26 @@ void blogi::PluginApi::initPlugin(){
    return;
}

static std::vector<blogi::PluginApi::PendingGPO> &pendingGPOs(){
    static std::vector<blogi::PluginApi::PendingGPO> list;
    return list;
}

std::vector<blogi::PluginApi::PendingGPO> &blogi::PluginApi::getPendingGPOs(){
    return pendingGPOs();
}

void blogi::PluginApi::registerGPO(const char *gpoid, const char *name, const char *desc, bool gpodefault){
    static std::mutex mtx;
    std::lock_guard<std::mutex> lock(mtx);
    pendingGPOs().push_back({gpoid, name, desc, gpodefault});
}

void blogi::PluginApi::registerPendingGPOs(authdb::client::Client &clt){
    static std::atomic<bool> done{false};
    if(done.exchange(true))
        return;
    auto &list = pendingGPOs();
    for(const auto &gpo : list){
    try {
            uuid::uuid gid(gpo.gpoid.c_str());
        if(Args->config->getAuthSourceCount() < 1)
            return;
        const AuthSource &src = Args->config->getAuthSource(0);
        authdb::client::ClientConnection authcon;
        authcon.setUrl(src.url);
        authcon.setClientName(src.clientName);
        authcon.setClientSecret(src.clientSecret);
        authdb::client::Client clt(authcon);
        if(clt.ClientAuth()){
            uuid::uuid gid(gpoid);
            if(!clt.GPOexits(gid)){
                clt.GPOadd(gid, gpo.name, gpo.desc, gpo.gpodefault, {});
                clt.GPOadd(gid, name, desc, gpodefault, {});
            }
        }
    } catch(const std::exception &e) {
            std::cerr << "GPO registration failed for " << gpo.name << ": " << e.what() << std::endl;
        std::cerr << "GPO registration failed for " << name << ": " << e.what() << std::endl;
    } catch(...) {
            std::cerr << "GPO registration failed for " << gpo.name << std::endl;
        }
        std::cerr << "GPO registration failed for " << name << std::endl;
    }
}

+0 −10
Changes for src/plugin.h: 0 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -163,16 +163,6 @@ namespace blogi {
        /// Share a post to social networks; url is the public link, title/description for text
        virtual void sharePost(const int tid, SharePostType type, const std::string &url,
                               const std::string &title, const std::string &description);

        struct PendingGPO {
            std::string gpoid;
            std::string name;
            std::string desc;
            bool gpodefault;
        };

        static void registerPendingGPOs(authdb::client::Client &clt);
        static std::vector<PendingGPO> &getPendingGPOs();
    protected:
        void registerGPO(const char *gpoid, const char *name, const char *desc, bool gpodefault);
        PluginArgs *Args;