From: Banana Date: Thu, 25 Jul 2024 20:09:35 +0000 (+0200) Subject: changed endpoint file name X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=39e47617f16919e0246e66ba795611ba5eb00b6d;p=scientia.git changed endpoint file name changed client config Signed-off-by: Banana --- 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/add.php b/webroot/add.php new file mode 100644 index 0000000..763ecd7 --- /dev/null +++ b/webroot/add.php @@ -0,0 +1,119 @@ + '', + '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 index 062e51c..0000000 --- a/webroot/api.php +++ /dev/null @@ -1,116 +0,0 @@ - '', - '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();