From 39e47617f16919e0246e66ba795611ba5eb00b6d Mon Sep 17 00:00:00 2001 From: Banana Date: Thu, 25 Jul 2024 22:09:35 +0200 Subject: [PATCH] changed endpoint file name changed client config Signed-off-by: Banana --- client/go-cli/scientia/cmd/add.go | 19 ++++++++++++++++++- client/go-cli/scientia/cmd/config.go | 16 ++++++++++++++++ client/go-cli/scientia/cmd/config_init.go | 5 ++++- client/go-cli/scientia/cmd/config_read.go | 6 +++--- client/go-cli/scientia/cmd/root.go | 8 +++++--- webroot/{api.php => add.php} | 5 ++++- 6 files changed, 50 insertions(+), 9 deletions(-) rename webroot/{api.php => add.php} (98%) diff --git a/client/go-cli/scientia/cmd/add.go b/client/go-cli/scientia/cmd/add.go index abea4f5..139cee3 100644 --- a/client/go-cli/scientia/cmd/add.go +++ b/client/go-cli/scientia/cmd/add.go @@ -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 diff --git a/client/go-cli/scientia/cmd/config.go b/client/go-cli/scientia/cmd/config.go index 3a32314..30acec0 100644 --- a/client/go-cli/scientia/cmd/config.go +++ b/client/go-cli/scientia/cmd/config.go @@ -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", diff --git a/client/go-cli/scientia/cmd/config_init.go b/client/go-cli/scientia/cmd/config_init.go index f538e4a..632746a 100644 --- a/client/go-cli/scientia/cmd/config_init.go +++ b/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 */ +// 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.") diff --git a/client/go-cli/scientia/cmd/config_read.go b/client/go-cli/scientia/cmd/config_read.go index f4c701c..f96b060 100644 --- a/client/go-cli/scientia/cmd/config_read.go +++ b/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 */ +// 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", diff --git a/client/go-cli/scientia/cmd/root.go b/client/go-cli/scientia/cmd/root.go index b2b6260..37d3bcb 100644 --- a/client/go-cli/scientia/cmd/root.go +++ b/client/go-cli/scientia/cmd/root.go @@ -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/api.php b/webroot/add.php similarity index 98% rename from webroot/api.php rename to webroot/add.php index 062e51c..763ecd7 100644 --- a/webroot/api.php +++ b/webroot/add.php @@ -15,6 +15,10 @@ * 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 @@ -47,7 +51,6 @@ 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; -- 2.39.5