From 50fc292b13b328124cd9ba97cb9d4ad2d03c3df3 Mon Sep 17 00:00:00 2001 From: Sven Ullmann Date: Wed, 5 Jul 2023 23:43:15 +0200 Subject: [PATCH] refactoring --- src/commands/configure-plugin | 39 ----------------- src/includes/configure-json-file | 34 --------------- src/includes/configure-json-file.php | 65 ---------------------------- 3 files changed, 138 deletions(-) delete mode 100644 src/commands/configure-plugin delete mode 100644 src/includes/configure-json-file delete mode 100644 src/includes/configure-json-file.php diff --git a/src/commands/configure-plugin b/src/commands/configure-plugin deleted file mode 100644 index af7170b..0000000 --- a/src/commands/configure-plugin +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -### DO NOT EDIT THIS FILE - -function usage { - echo - echoMainTitle "Configures a plugin" - echo - echoSubTitle "Usage:" - echo - echo "configure-plugin [shortname] [plugin]" - echo - echo "--help Prints this message" - echo " " -} - -source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header" - -shortname=$(getArgument "$1" "shortname required" true) -plugin=$(getArgument "$2" "plugin required" true) -escapedShortname=${shortname//./\\.} -customer=$(getConfig false "project_manager.projects.$escapedShortname.customer") -project=$(getConfig false "project_manager.projects.$escapedShortname.project") -project_dir="$project_manager_dir/data/$customer/$project" -config_path="$project_dir/etc/$plugin/config.json" - -if [ ! -f "$config_path" ] -then - echo - echoError "Could not load configuration file: $config_path" - echo - exit -fi - -echo -echoMainTitle "Configure Plugin: $plugin" -echo - -configureJsonFile "$shortname" "$config_path" \ No newline at end of file diff --git a/src/includes/configure-json-file b/src/includes/configure-json-file deleted file mode 100644 index e37e981..0000000 --- a/src/includes/configure-json-file +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -### DO NOT EDIT THIS FILE - -function usage { - echo - echoMainTitle "Sumedia Project Manager Configure Configuration File" - echo - echoSubTitle "Usage:" - echo - echo "configure-json-file shortname filePath" - echo - echo "--help Prints this message" - echo " " - exit -} - -source "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/bash_header" - -shortname="$(getArgument "$1" "Parameter shortname not given" true)" -filePath="$(getArgument "$2" "Parameter filePath not given" true)" -cryptKey="$(getCryptKey "$shortname")" - -if [ ! -f "$filePath" ] -then - echo - echoError "Could not find configuration file: $filePath" - echo - exit; -fi - -PHP=`which php` -script="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/configure-json-file.php" -$PHP "$script" "$filePath" "$cryptKey" \ No newline at end of file diff --git a/src/includes/configure-json-file.php b/src/includes/configure-json-file.php deleted file mode 100644 index 8a0e83b..0000000 --- a/src/includes/configure-json-file.php +++ /dev/null @@ -1,65 +0,0 @@ - $value) { - if (is_array($value) && !isset($value[0])) { - readNext($value, $current[$key], "$keyPath.$key"); - } else { - $default = $value; - if (is_bool($value)) { - $default = true === $value ? 'true' : 'false'; - } - if (null === $value) { - $default = null; - } - $prompt = "$keyPath.$key " . ($default !== null ? "[$default]" : "") . ": "; - $ret = readline($prompt); - $ret = trim($ret); - if ($ret === "null") { - $ret = null; - } - if ($ret === "false") { - $ret = false; - } - if ($ret === "true") { - $ret = true; - } - if ("" === $ret) { - if ($value === null) { - $ret = null; - } else { - $ret = $default; - } - } - if (!empty($ret)) { - $fullKey = "$keyPath.$key"; - if (preg_match('#pass#', $fullKey) && $ret !== $value) { - $ret = encryptValue($value); - } - } - $current[$key] = $ret; - } - } -} - -function encryptValue($value) { - global $cryptKey; - $value = escapeshellcmd($value); - $cryptKeyEscaped = escapeshellcmd($cryptKey); - return trim(shell_exec("echo '$value' | openssl enc -base64 -nosalt -nopad -pbkdf2 -k '$cryptKeyEscaped'")); -} - -foreach ($configuration as $key => $config) { - readNext($config, $configuration[$key], $key); -} - -file_put_contents($jsonFile, json_encode($configuration, - JSON_PRETTY_PRINT | JSON_ERROR_NONE | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT)); \ No newline at end of file