Browse Source

changed endpoint file name
changed client config

Signed-off-by: Banana <mail@bananas-playground.net>

Banana 1 month ago
parent
commit
39e47617f1

+ 18 - 1
client/go-cli/scientia/cmd/add.go

@@ -12,13 +12,30 @@ import (
 	Helper "scientia/lib"
 	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() {
 func init() {
 	rootCmd.AddCommand(addCmd)
 	rootCmd.AddCommand(addCmd)
 }
 }
 
 
 var addCmd = &cobra.Command {
 var addCmd = &cobra.Command {
 	Use: "add file.ext",
 	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.",
 	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) {
 	Run: func(cmd *cobra.Command, args []string) {
 		// check if there is a file or piped content
 		// check if there is a file or piped content

+ 16 - 0
client/go-cli/scientia/cmd/config.go

@@ -5,6 +5,22 @@ import (
 	"os"
 	"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 {
 var configCmd = &cobra.Command {
 	Use: "config",
 	Use: "config",
 	Short: "Modify config",
 	Short: "Modify config",

+ 4 - 1
client/go-cli/scientia/cmd/config_init.go

@@ -24,6 +24,8 @@ import (
  * along with this program.  If not, see http://www.sun.com/cddl/cddl.html
  * 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() {
 func init() {
 	configCmd.AddCommand(configInitCmd)
 	configCmd.AddCommand(configInitCmd)
@@ -65,7 +67,8 @@ func initConfig() {
 		fmt.Fprintf(newConfig, "# See %s for more details.\n", Helper.Website)
 		fmt.Fprintf(newConfig, "# See %s for more details.\n", Helper.Website)
 		fmt.Fprintf(newConfig, "# Version: %s\n", Helper.Version)
 		fmt.Fprintf(newConfig, "# Version: %s\n", Helper.Version)
 		fmt.Fprintf(newConfig, "endpoint:\n")
 		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.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.")
 		fmt.Println("Created a new default config file. Please use the edit command to update it with your settings.")

+ 3 - 3
client/go-cli/scientia/cmd/config_read.go

@@ -25,13 +25,13 @@ import (
  * along with this program.  If not, see http://www.sun.com/cddl/cddl.html
  * along with this program.  If not, see http://www.sun.com/cddl/cddl.html
  */
  */
 
 
+// Subcommand of config
+// to read the config file
+
 func init() {
 func init() {
 	configCmd.AddCommand(configReadCmd)
 	configCmd.AddCommand(configReadCmd)
 }
 }
 
 
-// Subcommand of config
-// to read the config file
-
 var configReadCmd = &cobra.Command {
 var configReadCmd = &cobra.Command {
 	Use:   "read",
 	Use:   "read",
 	Short: "Read config file",
 	Short: "Read config file",

+ 5 - 3
client/go-cli/scientia/cmd/root.go

@@ -20,7 +20,8 @@ var FlagDebug bool
 // ConfigStruct file struct
 // ConfigStruct file struct
 type ConfigStruct struct {
 type ConfigStruct struct {
 	Endpoint struct {
 	Endpoint struct {
-		Url   string `yaml:"url"`
+		Add   string `yaml:"add"`
+		Get   string `yaml:"get"`
 		Secret string `yaml:"secret"`
 		Secret string `yaml:"secret"`
 	} `yaml:"endpoint"`
 	} `yaml:"endpoint"`
 }
 }
@@ -82,12 +83,13 @@ func loadConfig() {
 	err = decoder.Decode(&ScientiaConfig)
 	err = decoder.Decode(&ScientiaConfig)
 	Helper.ErrorCheck(err, "Can not decode config file")
 	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?")
 		log.Fatal("Empty config?")
 	}
 	}
 
 
 	if FlagDebug {
 	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)
 		fmt.Println("DEBUG Secret: " + ScientiaConfig.Endpoint.Secret)
 	}
 	}
 }
 }

+ 4 - 1
webroot/api.php → webroot/add.php

@@ -15,6 +15,10 @@
  * along with this program.  If not, see http://www.sun.com/cddl/cddl.html
  * 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_http_output('UTF-8');
 mb_internal_encoding('UTF-8');
 mb_internal_encoding('UTF-8');
 ini_set('error_reporting',-1); // E_ALL & E_STRICT
 ini_set('error_reporting',-1); // E_ALL & E_STRICT
@@ -47,7 +51,6 @@ date_default_timezone_set(TIMEZONE);
 # required libs
 # required libs
 require_once('lib/summoner.class.php');
 require_once('lib/summoner.class.php');
 
 
-
 if(DEBUG) error_log("Dump SERVER ".var_export($_SERVER,true));
 if(DEBUG) error_log("Dump SERVER ".var_export($_SERVER,true));
 ## check if request is valid
 ## check if request is valid
 $_create = false;
 $_create = false;