]> 91.132.146.200 Git - scientia.git/commitdiff
changed endpoint file name
authorBanana <mail@bananas-playground.net>
Thu, 25 Jul 2024 20:09:35 +0000 (22:09 +0200)
committerBanana <mail@bananas-playground.net>
Thu, 25 Jul 2024 20:09:35 +0000 (22:09 +0200)
changed client config

Signed-off-by: Banana <mail@bananas-playground.net>
client/go-cli/scientia/cmd/add.go
client/go-cli/scientia/cmd/config.go
client/go-cli/scientia/cmd/config_init.go
client/go-cli/scientia/cmd/config_read.go
client/go-cli/scientia/cmd/root.go
webroot/add.php [new file with mode: 0644]
webroot/api.php [deleted file]

index abea4f5798fde4e4e7e9b3d9fbfbe15f63f7a31a..139cee3b77b1cb5280394ae10e988d434e59f009 100644 (file)
@@ -12,13 +12,30 @@ import (
        Helper "scientia/lib"
 )
 
+
+/**
+ * scientia
+ *
+ * Copyright 2023 - 2024 Johannes Keßler
+ *
+ * https://www.bananas-playground.net/projekt/scientia/
+ *
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
+ *
+ * You should have received a copy of the
+ * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+ * along with this program.  If not, see http://www.sun.com/cddl/cddl.html
+ */
+
 func init() {
        rootCmd.AddCommand(addCmd)
 }
 
 var addCmd = &cobra.Command {
        Use: "add file.ext",
-       Short: "Add a new entry and return the URL",
+       Short: "Add a new entry and get the URL returned",
        Long: "Add a new entry based on a file or piped cat file | scientia add. Returns the url to the new entry.",
        Run: func(cmd *cobra.Command, args []string) {
                // check if there is a file or piped content
index 3a3231415f679190a7261fd8d9542ad7a1db3995..30acec0324cde10a88da34b733ae93fc10395f86 100644 (file)
@@ -5,6 +5,22 @@ import (
        "os"
 )
 
+/**
+ * scientia
+ *
+ * Copyright 2023 - 2024 Johannes Keßler
+ *
+ * https://www.bananas-playground.net/projekt/scientia/
+ *
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
+ *
+ * You should have received a copy of the
+ * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+ * along with this program.  If not, see http://www.sun.com/cddl/cddl.html
+ */
+
 var configCmd = &cobra.Command {
        Use: "config",
        Short: "Modify config",
index f538e4aa31e45ec4ba96c243ed9131addeed33f1..632746ad7bfa101ac672680e2a8e981af613e377 100644 (file)
@@ -24,6 +24,8 @@ import (
  * along with this program.  If not, see http://www.sun.com/cddl/cddl.html
  */
 
+// Subcommand of config
+// to init the config with default values.
 
 func init() {
        configCmd.AddCommand(configInitCmd)
@@ -65,7 +67,8 @@ func initConfig() {
                fmt.Fprintf(newConfig, "# See %s for more details.\n", Helper.Website)
                fmt.Fprintf(newConfig, "# Version: %s\n", Helper.Version)
                fmt.Fprintf(newConfig, "endpoint:\n")
-               fmt.Fprintf(newConfig, "  url: \"http://your-scientia-endpoi.nt/api.php\"\n")
+               fmt.Fprintf(newConfig, "  add: \"http://your-scientia-endpoi.nt/add.php\"\n")
+               fmt.Fprintf(newConfig, "  get: \"http://your-scientia-endpoi.nt/get.php\"\n")
                fmt.Fprintf(newConfig, "  secret: \"%s\"\n", Helper.RandStringBytes(50))
 
                fmt.Println("Created a new default config file. Please use the edit command to update it with your settings.")
index f4c701cd35f4ca1bb18bcaa71ed48b1593e75618..f96b060dc58b62bfb53b191c80f2a326cc296dce 100644 (file)
@@ -25,13 +25,13 @@ import (
  * along with this program.  If not, see http://www.sun.com/cddl/cddl.html
  */
 
+// Subcommand of config
+// to read the config file
+
 func init() {
        configCmd.AddCommand(configReadCmd)
 }
 
-// Subcommand of config
-// to read the config file
-
 var configReadCmd = &cobra.Command {
        Use:   "read",
        Short: "Read config file",
index b2b6260e4487580cf8aefe1a019648b20b607882..37d3bcbaef2f63907d1fd03d03ebdbe05b26336f 100644 (file)
@@ -20,7 +20,8 @@ var FlagDebug bool
 // ConfigStruct file struct
 type ConfigStruct struct {
        Endpoint struct {
-               Url   string `yaml:"url"`
+               Add   string `yaml:"add"`
+               Get   string `yaml:"get"`
                Secret string `yaml:"secret"`
        } `yaml:"endpoint"`
 }
@@ -82,12 +83,13 @@ func loadConfig() {
        err = decoder.Decode(&ScientiaConfig)
        Helper.ErrorCheck(err, "Can not decode config file")
 
-       if ScientiaConfig.Endpoint.Url == "" || ScientiaConfig.Endpoint.Secret == "" {
+       if ScientiaConfig.Endpoint.Add == "" || ScientiaConfig.Endpoint.Secret == "" {
                log.Fatal("Empty config?")
        }
 
        if FlagDebug {
-               fmt.Println("DEBUG Endpoint: " + ScientiaConfig.Endpoint.Url)
+               fmt.Println("DEBUG Add endpoint: " + ScientiaConfig.Endpoint.Add)
+               fmt.Println("DEBUG Get endpoint: " + ScientiaConfig.Endpoint.Get)
                fmt.Println("DEBUG Secret: " + ScientiaConfig.Endpoint.Secret)
        }
 }
diff --git a/webroot/add.php b/webroot/add.php
new file mode 100644 (file)
index 0000000..763ecd7
--- /dev/null
@@ -0,0 +1,119 @@
+<?php
+/**
+ * scientia
+ *
+ * Copyright 2023 - 2024 Johannes Keßler
+ *
+ * https://www.bananas-playground.net/projekt/scientia/
+ *
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
+ *
+ * You should have received a copy of the
+ * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+ * along with this program.  If not, see http://www.sun.com/cddl/cddl.html
+ */
+
+/**
+ * add endpoint. Accepts only POST and valid post body as json
+ */
+
+mb_http_output('UTF-8');
+mb_internal_encoding('UTF-8');
+ini_set('error_reporting',-1); // E_ALL & E_STRICT
+
+## check request
+$_urlToParse = filter_var($_SERVER['QUERY_STRING'],FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW);
+if(!empty($_urlToParse)) {
+    # see http://de2.php.net/manual/en/regexp.reference.unicode.php
+    if(preg_match('/[\p{C}\p{M}\p{Sc}\p{Sk}\p{So}\p{Zl}\p{Zp}]/u',$_urlToParse) === 1) {
+        die('Malformed request. Make sure you know what you are doing.');
+    }
+}
+
+## config
+require_once('config/config.php');
+
+## set the error reporting
+ini_set('log_errors',true);
+ini_set('error_log',PATH_SYSTEMOUT.'/error.log');
+if(DEBUG === true) {
+    ini_set('display_errors',true);
+}
+else {
+    ini_set('display_errors',false);
+}
+
+# time settings
+date_default_timezone_set(TIMEZONE);
+
+# required libs
+require_once('lib/summoner.class.php');
+
+if(DEBUG) error_log("Dump SERVER ".var_export($_SERVER,true));
+## check if request is valid
+$_create = false;
+$filteredData = '';
+if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/json; charset=UTF-8') {
+    $payload = json_decode(file_get_contents('php://input'), true);
+    if(DEBUG) error_log("[DEBUG] Dump payload ".var_export($payload,true));
+    if(!empty($payload)) {
+        if(isset($payload['asl']) && !empty($payload['asl'])
+            && isset($payload['data']) && !empty($payload['data'])
+            && isset(UPLOAD_SECRET[$payload['asl']])
+        ) {
+            if(DEBUG) error_log("[DEBUG] Valid payload so far");
+            $filteredData = filter_var($payload['data'],FILTER_SANITIZE_FULL_SPECIAL_CHARS);
+            if(!empty($filteredData)) {
+                if(DEBUG) error_log("[DEBUG] Validated payload");
+                $_create = true;
+            }
+        }
+    }
+}
+
+## default response
+$contentType = 'Content-Type: application/json; charset=utf-8';
+$httpResponseCode = 200;
+$contentBody = array(
+    'message' => '',
+    'status' => $httpResponseCode
+);
+
+## break here secret empty or false
+if($_create === false) {
+    header('X-PROVIDED-BY: scientia');
+    header($contentType);
+    http_response_code($httpResponseCode);
+    echo json_encode($contentBody);
+    exit();
+}
+
+## DB connection
+$DB = new mysqli(DB_HOST, DB_USERNAME,DB_PASSWORD, DB_NAME);
+if ($DB->connect_errno) exit('Can not connect to MySQL Server');
+$DB->set_charset("utf8mb4");
+$DB->query("SET collation_connection = 'utf8mb4_bin'");
+$driver = new mysqli_driver();
+$driver->report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT;
+
+require_once 'lib/entry.class.php';
+$Entry = new Entry($DB);
+$do = $Entry->create($filteredData);
+if(!empty($do)) {
+    $contentBody['message'] = INSTALL_URL . PATH_WEBROOT . date('/Y/m/d/').$do;
+}
+else {
+    $hash = md5($do.time());
+    error_log("[ERROR] $hash Can not create. ". var_export($do,true));
+    $contentBody['message'] = "Something went wrong. $hash";
+    $contentBody['status'] = 500;
+}
+
+# return
+header('X-PROVIDED-BY: scientia');
+header($contentType);
+http_response_code($httpResponseCode);
+echo json_encode($contentBody);
+$DB->close();
diff --git a/webroot/api.php b/webroot/api.php
deleted file mode 100644 (file)
index 062e51c..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-<?php
-/**
- * scientia
- *
- * Copyright 2023 - 2024 Johannes Keßler
- *
- * https://www.bananas-playground.net/projekt/scientia/
- *
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
- *
- * You should have received a copy of the
- * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
- * along with this program.  If not, see http://www.sun.com/cddl/cddl.html
- */
-
-mb_http_output('UTF-8');
-mb_internal_encoding('UTF-8');
-ini_set('error_reporting',-1); // E_ALL & E_STRICT
-
-## check request
-$_urlToParse = filter_var($_SERVER['QUERY_STRING'],FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW);
-if(!empty($_urlToParse)) {
-    # see http://de2.php.net/manual/en/regexp.reference.unicode.php
-    if(preg_match('/[\p{C}\p{M}\p{Sc}\p{Sk}\p{So}\p{Zl}\p{Zp}]/u',$_urlToParse) === 1) {
-        die('Malformed request. Make sure you know what you are doing.');
-    }
-}
-
-## config
-require_once('config/config.php');
-
-## set the error reporting
-ini_set('log_errors',true);
-ini_set('error_log',PATH_SYSTEMOUT.'/error.log');
-if(DEBUG === true) {
-    ini_set('display_errors',true);
-}
-else {
-    ini_set('display_errors',false);
-}
-
-# time settings
-date_default_timezone_set(TIMEZONE);
-
-# required libs
-require_once('lib/summoner.class.php');
-
-
-if(DEBUG) error_log("Dump SERVER ".var_export($_SERVER,true));
-## check if request is valid
-$_create = false;
-$filteredData = '';
-if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/json; charset=UTF-8') {
-    $payload = json_decode(file_get_contents('php://input'), true);
-    if(DEBUG) error_log("[DEBUG] Dump payload ".var_export($payload,true));
-    if(!empty($payload)) {
-        if(isset($payload['asl']) && !empty($payload['asl'])
-            && isset($payload['data']) && !empty($payload['data'])
-            && isset(UPLOAD_SECRET[$payload['asl']])
-        ) {
-            if(DEBUG) error_log("[DEBUG] Valid payload so far");
-            $filteredData = filter_var($payload['data'],FILTER_SANITIZE_FULL_SPECIAL_CHARS);
-            if(!empty($filteredData)) {
-                if(DEBUG) error_log("[DEBUG] Validated payload");
-                $_create = true;
-            }
-        }
-    }
-}
-
-## default response
-$contentType = 'Content-Type: application/json; charset=utf-8';
-$httpResponseCode = 200;
-$contentBody = array(
-    'message' => '',
-    'status' => $httpResponseCode
-);
-
-## break here secret empty or false
-if($_create === false) {
-    header('X-PROVIDED-BY: scientia');
-    header($contentType);
-    http_response_code($httpResponseCode);
-    echo json_encode($contentBody);
-    exit();
-}
-
-## DB connection
-$DB = new mysqli(DB_HOST, DB_USERNAME,DB_PASSWORD, DB_NAME);
-if ($DB->connect_errno) exit('Can not connect to MySQL Server');
-$DB->set_charset("utf8mb4");
-$DB->query("SET collation_connection = 'utf8mb4_bin'");
-$driver = new mysqli_driver();
-$driver->report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT;
-
-require_once 'lib/entry.class.php';
-$Entry = new Entry($DB);
-$do = $Entry->create($filteredData);
-if(!empty($do)) {
-    $contentBody['message'] = INSTALL_URL . PATH_WEBROOT . date('/Y/m/d/').$do;
-}
-else {
-    $hash = md5($do.time());
-    error_log("[ERROR] $hash Can not create. ". var_export($do,true));
-    $contentBody['message'] = "Something went wrong. $hash";
-    $contentBody['status'] = 500;
-}
-
-# return
-header('X-PROVIDED-BY: scientia');
-header($contentType);
-http_response_code($httpResponseCode);
-echo json_encode($contentBody);
-$DB->close();