Sven Ullmann
2 years ago
3 changed files with 0 additions and 138 deletions
-
39src/commands/configure-plugin
-
34src/includes/configure-json-file
-
65src/includes/configure-json-file.php
@ -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" |
|
@ -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" |
|
@ -1,65 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
### DO NOT EDIT THIS FILE
|
|
||||
|
|
||||
global $project_manager_dir, $shortname, $configPath, $configuration, $value; |
|
||||
$configuration = []; |
|
||||
$jsonFile = $_SERVER['argv'][1]; |
|
||||
$cryptKey = $_SERVER['argv'][2]; |
|
||||
$configuration = json_decode(file_get_contents($jsonFile), true); |
|
||||
|
|
||||
function readNext($config, &$current, $keyPath = '') { |
|
||||
foreach ($config as $key => $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)); |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue