Commit 3384b822 authored by jan.koester's avatar jan.koester
Browse files

settings settings

parent 45263d30
Loading
Loading
Loading
Loading
+4 −8
Changes for config.yaml: 4 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -16,14 +16,10 @@ BLOGI:
    DRIVER: "sqlite"
    CONNECTION: "/var/lib/blogi/blog.db"
  AUTHDB:
    URL:
      - "https://auth.example.com"
    CLIENTNAME:
      - "blogiclient"
    CLIENTSECRET:
      - "clientsecret"
    DOMAIN:
      - "example.com"
    - URL: "https://auth.example.com"
      CLIENTNAME: "blogiclient"
      CLIENTSECRET: "clientsecret"
      DOMAIN: "example.com"
  REDIS:
    HOST: "127.0.0.1"
    PORT: 6379
+4 −8
Changes for docker-config.yaml: 4 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -20,11 +20,7 @@ BLOGI:
  DOMAIN:
    NAME: "%COOKIE%"
  AUTHDB:
    URL:
      - "%CLIENTURL%"
    CLIENTNAME:
      - "%CLIENTNAME%"
    CLIENTSECRET:
      - "%CLIENTSECRET%"
    DOMAIN:
      - "%AUTHDOMAIN%"
    - URL: "%CLIENTURL%"
      CLIENTNAME: "%CLIENTNAME%"
      CLIENTSECRET: "%CLIENTSECRET%"
      DOMAIN: "%AUTHDOMAIN%"
+3 −2
Changes for plugins/gameinfo/CMakeLists.txt: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
find_package(gameinfoplus)
find_package(json-c REQUIRED)

if(${gameinfoplus_FOUND})
    add_library(gamestatus SHARED gameinfo.cpp)
@@ -9,9 +10,9 @@ if(${gameinfoplus_FOUND})
    

    if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
	    target_link_libraries(gamestatus PUBLIC kernel32.lib uuidp::uuidp blogidev gameinfoplus::gameinfoplus)
	    target_link_libraries(gamestatus PUBLIC kernel32.lib uuidp::uuidp blogidev gameinfoplus::gameinfoplus json-c::json-c)
    else()
	    target_link_libraries(gamestatus PUBLIC dl blogidev uuidp::uuidp gameinfoplus::gameinfoplus)
	    target_link_libraries(gamestatus PUBLIC dl blogidev uuidp::uuidp gameinfoplus::gameinfoplus json-c::json-c)
    endif()

    install (TARGETS gamestatus  DESTINATION lib/blogi/plugins)
+125 −0
Changes for plugins/gameinfo/gameinfo.cpp: 125 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@

#include <dbpp/database.h>

#include <json-c/json.h>

#include <plugin.h>
#include <theme.h>
#include <conf.h>
@@ -98,6 +100,129 @@ namespace blogi {
            }
        }

        bool haveSettings(){
            return true;
        }

        json_object* Settings(const int tid,libhttppp::HttpRequest &req,const std::string &sessionid){
            std::string _lang = getLang(*Args->database[tid]);
            bool saved = false;

            libhttppp::HttpForm form;
            form.parse(req);

            std::string formAddr, formPort, formProtocol;
            bool hasForm = false;
            std::string delId;

            for(const auto &cur : form.urlData()){
                if(cur.key=="server_addr"){
                    formAddr = cur.value;
                    hasForm = true;
                }else if(cur.key=="server_port"){
                    formPort = cur.value;
                    hasForm = true;
                }else if(cur.key=="server_protocol"){
                    formProtocol = cur.value;
                    hasForm = true;
                }else if(cur.key=="delete_id"){
                    delId = cur.value;
                }
            }

            if(!delId.empty()){
                dbpp::SQL sql;
                dbpp::DBResult res;
                std::vector<char> buf;
                sql << "DELETE FROM gameserver WHERE id='" << sql.escaped(buf, delId.c_str()) << "'";
                Args->database[tid]->exec(sql,res);
                saved = true;
            }

            if(hasForm && !formAddr.empty() && !formPort.empty()){
                dbpp::SQL sql;
                dbpp::DBResult res;
                std::vector<char> buf;
                sql << "INSERT INTO gameserver (protocol,addr,port) VALUES ('"
                    << sql.escaped(buf, formProtocol.c_str()) << "','"
                    << sql.escaped(buf, formAddr.c_str()) << "','"
                    << sql.escaped(buf, formPort.c_str()) << "')";
                Args->database[tid]->exec(sql,res);
                saved = true;
            }

            json_object *jroot = json_object_new_object();
            json_object_object_add(jroot, "title", json_object_new_string(tr(_lang,"Game Server Settings").c_str()));

            if(saved){
                json_object_object_add(jroot, "message", json_object_new_string(tr(_lang,"Saved!").c_str()));
                json_object_object_add(jroot, "message_type", json_object_new_string("success"));
            }

            // Existing servers list
            json_object *jservers = json_object_new_array();
            {
                dbpp::SQL sql;
                dbpp::DBResult res;
                sql << "SELECT id,protocol,addr,port FROM gameserver";
                int count = Args->database[tid]->exec(sql,res);
                for(int i = 0; i < count; ++i){
                    json_object *js = json_object_new_object();
                    json_object_object_add(js, "id", json_object_new_string(res[i][0]));
                    json_object_object_add(js, "protocol", json_object_new_string(res[i][1]));
                    json_object_object_add(js, "addr", json_object_new_string(res[i][2]));
                    json_object_object_add(js, "port", json_object_new_string(res[i][3]));
                    json_object_array_add(jservers, js);
                }
            }
            json_object_object_add(jroot, "items", jservers);

            // Add server form
            json_object *jform = json_object_new_object();
            json_object_object_add(jform, "method", json_object_new_string("POST"));
            json_object_object_add(jform, "action", json_object_new_string(
                Args->config->buildurl("settings/gamestatus").c_str()));

            json_object *jfields = json_object_new_array();

            auto addField = [&](const char *name, const char *label, const char *type, const std::string &value){
                json_object *jf = json_object_new_object();
                json_object_object_add(jf, "name", json_object_new_string(name));
                json_object_object_add(jf, "label", json_object_new_string(label));
                json_object_object_add(jf, "type", json_object_new_string(type));
                json_object_object_add(jf, "value", json_object_new_string(value.c_str()));
                json_object_array_add(jfields, jf);
            };

            addField("server_addr", "Server Address", "text", "");
            addField("server_port", "Server Port", "text", "");
            addField("server_protocol", "Protocol (0=HLDS)", "text", "0");

            json_object_object_add(jform, "fields", jfields);
            json_object_object_add(jform, "submit", json_object_new_string(tr(_lang,"Add Server").c_str()));
            json_object_object_add(jroot, "form", jform);

            // Delete form
            json_object *jdelform = json_object_new_object();
            json_object_object_add(jdelform, "method", json_object_new_string("POST"));
            json_object_object_add(jdelform, "action", json_object_new_string(
                Args->config->buildurl("settings/gamestatus").c_str()));
            json_object *jdelfields = json_object_new_array();
            {
                json_object *jf = json_object_new_object();
                json_object_object_add(jf, "name", json_object_new_string("delete_id"));
                json_object_object_add(jf, "label", json_object_new_string("Server ID to delete"));
                json_object_object_add(jf, "type", json_object_new_string("text"));
                json_object_object_add(jf, "value", json_object_new_string(""));
                json_object_array_add(jdelfields, jf);
            }
            json_object_object_add(jdelform, "fields", jdelfields);
            json_object_object_add(jdelform, "submit", json_object_new_string(tr(_lang,"Delete Server").c_str()));
            json_object_object_add(jroot, "delete_form", jdelform);

            return jroot;
        }

        bool Controller(const int tid,libhttppp::HttpRequest &req,libhtmlpp::HtmlElement *page,const std::string &sessionid){
            if(req.getRequestURL().compare(0,Args->config->buildurl("gamestatus").length(),Args->config->buildurl("gamestatus"))!=0){
                return false;
+77 −4
Changes for plugins/nginxfiler/filer.cpp: 77 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
#include "plugin.h"
#include "theme.h"
#include "conf.h"
#include <i18n.h>

#include <json-c/json.h>
#include <json-c/json_object.h>
@@ -79,13 +80,85 @@ namespace blogi {
                getConfig(*Args->database[0],"NGINXFILERPREFIX",_NPrefix);
                getConfig(*Args->database[0],"NGINXFILERSSL",_NSSL);
                getConfig(*Args->database[0],"NGINXFILERTIMEOUT",_Timeout);
            }catch(confplus::ConfException &e){
                libhttppp::HTTPException err;
                err[libhttppp::HTTPException::Error] << "NginxFiler init failed: " << e.what();
                throw err;
            }catch(...){
            }
        }

        bool haveSettings(){
            return true;
        }

        json_object* Settings(const int tid,libhttppp::HttpRequest &req,const std::string &sessionid){
            std::string _lang = getLang(*Args->database[tid]);
            bool saved = false;

            libhttppp::HttpForm form;
            form.parse(req);

            for(const auto &cur : form.urlData()){
                if(cur.key=="nginxfilerhost"){
                    setConfig(*Args->database[tid],"NGINXFILERHOST",cur.value);
                    saved = true;
                }else if(cur.key=="nginxfilerport"){
                    setConfig(*Args->database[tid],"NGINXFILERPORT",cur.value);
                    saved = true;
                }else if(cur.key=="nginxfilerprefix"){
                    setConfig(*Args->database[tid],"NGINXFILERPREFIX",cur.value);
                    saved = true;
                }else if(cur.key=="nginxfilerssl"){
                    setConfig(*Args->database[tid],"NGINXFILERSSL",cur.value);
                    saved = true;
                }else if(cur.key=="nginxfilertimeout"){
                    setConfig(*Args->database[tid],"NGINXFILERTIMEOUT",cur.value);
                    saved = true;
                }
            }

            if(saved){
                try{ getConfig(*Args->database[tid],"NGINXFILERHOST",_NHost); }catch(...){}
                try{ getConfig(*Args->database[tid],"NGINXFILERPORT",_NPort); }catch(...){}
                try{ getConfig(*Args->database[tid],"NGINXFILERPREFIX",_NPrefix); }catch(...){}
                try{ getConfig(*Args->database[tid],"NGINXFILERSSL",_NSSL); }catch(...){}
                try{ getConfig(*Args->database[tid],"NGINXFILERTIMEOUT",_Timeout); }catch(...){}
            }

            json_object *jroot = json_object_new_object();
            json_object_object_add(jroot, "title", json_object_new_string("Nginx Filer"));

            if(saved){
                json_object_object_add(jroot, "message", json_object_new_string(tr(_lang,"Saved!").c_str()));
                json_object_object_add(jroot, "message_type", json_object_new_string("success"));
            }

            json_object *jform = json_object_new_object();
            json_object_object_add(jform, "method", json_object_new_string("POST"));
            json_object_object_add(jform, "action", json_object_new_string(
                Args->config->buildurl("settings/nginxfiler").c_str()));

            json_object *jfields = json_object_new_array();

            auto addField = [&](const char *name, const char *label, const char *type, const std::string &value){
                json_object *jf = json_object_new_object();
                json_object_object_add(jf, "name", json_object_new_string(name));
                json_object_object_add(jf, "label", json_object_new_string(label));
                json_object_object_add(jf, "type", json_object_new_string(type));
                json_object_object_add(jf, "value", json_object_new_string(value.c_str()));
                json_object_array_add(jfields, jf);
            };

            addField("nginxfilerhost", "Host", "text", _NHost);
            addField("nginxfilerport", "Port", "text", std::to_string(_NPort));
            addField("nginxfilerprefix", "Prefix", "text", _NPrefix);
            addField("nginxfilerssl", "SSL (true/false)", "text", _NSSL ? "true" : "false");
            addField("nginxfilertimeout", "Timeout (s)", "text", std::to_string(_Timeout));

            json_object_object_add(jform, "fields", jfields);
            json_object_object_add(jform, "submit", json_object_new_string(tr(_lang,"save").c_str()));
            json_object_object_add(jroot, "form", jform);

            return jroot;
        }

        void RenderUI(std::string path,struct json_object *jobj,libhtmlpp::HtmlString &out){
            if (json_object_get_type(jobj) != json_type_array) {
                    libhttppp::HTTPException he;
Loading