Browse Source

refactoring

master
Sven Ullmann 2 years ago
parent
commit
583947dd62
  1. 11
      plugins/git/etc/config.json
  2. 28
      plugins/git/src/commands/clone
  3. 10
      plugins/git/src/includes/bash_header
  4. 15
      plugins/git/src/includes/includes
  5. 0
      plugins/plesk/bak/commands/create-database
  6. 0
      plugins/plesk/bak/commands/create-subdomain
  7. 0
      plugins/plesk/bak/includes/includes
  8. 0
      plugins/shopware5/bak/includes
  9. 0
      plugins/shopware6/bak/includes
  10. 0
      plugins/ssh/bak/includes.sh
  11. 2
      plugins/ssh/src/commands/add-key
  12. 2
      plugins/ssh/src/includes/bash_header
  13. 0
      plugins/ssh/src/includes/includes
  14. 0
      plugins/ssh/src/includes/ssh
  15. 2
      src/commands/configure-plugin
  16. 9
      src/includes/configure-json-file
  17. 37
      src/includes/configure-json-file.php
  18. 21
      src/includes/main_functions

11
plugins/git/etc/config.json

@ -1,9 +1,10 @@
{ {
"git": { "git": {
"git_url": null,
"git_ssh_user": null,
"git_ssh_domain": null,
"git_ssh_private_key": null,
"git_ssh_public_key": null
"url": null,
"ssh_user": null,
"ssh_domain": null,
"ssh_private_key": null,
"ssh_public_key": null,
"ssh_private_key_passphrase": null
} }
} }

28
plugins/git/src/commands/clone

@ -14,10 +14,16 @@ function usage {
echo echo
} }
source "$project_manager_dir/bin/includes/project_header"
gitValidate
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header"
if [ "$git_url" == "" ]
url="$(getConfig $shortname "git.url")"
sshUser="$(getConfig $shortname "git.ssh_user")"
sshDomain="$(getConfig $shortname "git.ssh_domain")"
sshPrivateKey="$(getConfig $shortname "git.ssh_private_key")"
sshPublicKey="$(getConfig $shortname "git.ssh_public_key")"
sshPrivateKeyPassphrase="$(getCryptedConfig $shortname "git.ssh_private_key_passphrase")"
if [ "$url" == "" ]
then then
echo echo
echoError "There is no git url configured" echoError "There is no git url configured"
@ -31,17 +37,17 @@ echoMainTitle "Cloning Repository"
echo echo
echoSubTitle "Please confirm following data" echoSubTitle "Please confirm following data"
echo echo
if [ "$git_ssh_private_key" != "" ]
if [ "$ssh_private_key" != "" ]
then then
echo "SSH Private Key File: $git_ssh_public_key" echo "SSH Private Key File: $git_ssh_public_key"
fi fi
if [ "$git_ssh_public_key" != "" ]
if [ "$ssh_public_key" != "" ]
then then
echo "SSH Public Key File: $git_ssh_public_key" echo "SSH Public Key File: $git_ssh_public_key"
fi fi
echo "GIT Url: $git_url"
echo "GIT User: $git_ssh_user"
echo "GIT Domain: $git_ssh_domain"
echo "GIT Url: $url"
echo "GIT User: $ssh_user"
echo "GIT Domain: $ssh_domain"
echo "Install Location: $workspaces_dir/$customer/$project" echo "Install Location: $workspaces_dir/$customer/$project"
echo echo
confirm confirm
@ -55,8 +61,4 @@ then
fi fi
sshAddKey "git" sshAddKey "git"
git clone "$git_url" "$workspaces_dir/$customer/$project"
echo
echoSuccess "GIT cloned"
echo
git clone "$url" "$workspaces_dir/$customer/$project"

10
plugins/git/src/includes/bash_header

@ -0,0 +1,10 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
source "$project_manager_dir/src/includes/bash_header"
shortname="$(getArgument "$1" "shortname required" true)"
escapedShortname=${shortname//./\\.}
customer="$(getConfig false "project_manager.projects.$escapedShortname.customer")"
project="$(getConfig false "project_manager.projects.$escapedShortname.project")"

15
plugins/git/src/includes/includes

@ -1,15 +0,0 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
git_included=true
function gitValidate {
if [ "$git_url" == "" ]
then
echo >&2
echoError "Please configure $project_manager_dir/data/$customer/$project/etc/plugins/git/config" >&2
echo >&2
exit
fi
}

0
plugins/plesk/commands/create-database → plugins/plesk/bak/commands/create-database

0
plugins/plesk/commands/create-subdomain → plugins/plesk/bak/commands/create-subdomain

0
plugins/plesk/includes/includes → plugins/plesk/bak/includes/includes

0
plugins/shopware5/includes/includes → plugins/shopware5/bak/includes

0
plugins/shopware6/bin/includes/includes → plugins/shopware6/bak/includes

0
plugins/ssh/bin/includes/includes.sh → plugins/ssh/bak/includes.sh

2
plugins/ssh/bin/commands/add-key → plugins/ssh/src/commands/add-key

@ -16,7 +16,7 @@ function usage {
echo echo
} }
source "$project_manager_dir/bin/includes/project_header"
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header"
env="$(getArgument "$2" "$(usage)" "live stage git")" env="$(getArgument "$2" "$(usage)" "live stage git")"
sshValidate sshValidate

2
plugins/ssh/bin/includes/bash_header → plugins/ssh/src/includes/bash_header

@ -6,4 +6,4 @@ source "$project_manager_dir/src/includes/bash_header"
shortname="$(getArgument "$1" "shortname required" true)" shortname="$(getArgument "$1" "shortname required" true)"
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/ssh"
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/includes"

0
plugins/ssh/bin/includes/includes → plugins/ssh/src/includes/includes

0
plugins/ssh/bin/includes/ssh → plugins/ssh/src/includes/ssh

2
src/commands/configure-plugin

@ -36,4 +36,4 @@ echo
echoMainTitle "Configure Plugin: $plugin" echoMainTitle "Configure Plugin: $plugin"
echo echo
configureJsonFile "$config_path"
configureJsonFile "$shortname" "$config_path"

9
src/includes/configure-json-file

@ -8,7 +8,7 @@ function usage {
echo echo
echoSubTitle "Usage:" echoSubTitle "Usage:"
echo echo
echo "configure-json-file filePath"
echo "configure-json-file shortname filePath"
echo echo
echo "--help Prints this message" echo "--help Prints this message"
echo " " echo " "
@ -17,7 +17,10 @@ function usage {
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/bash_header" source "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/bash_header"
filePath="$(getArgument "$1" "Parameter filePath not given" true)"
shortname="$(getArgument "$1" "Parameter shortname not given" true)"
filePath="$(getArgument "$2" "Parameter filePath not given" true)"
cryptKey="$(getCryptKey "$shortname")"
if [ ! -f "$filePath" ] if [ ! -f "$filePath" ]
then then
echo echo
@ -28,4 +31,4 @@ fi
PHP=`which php` PHP=`which php`
script="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/configure-json-file.php" script="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/configure-json-file.php"
$PHP "$script" "$@"
$PHP "$script" "$filePath" "$cryptKey"

37
src/includes/configure-json-file.php

@ -5,6 +5,7 @@
global $project_manager_dir, $shortname, $configPath, $configuration, $value; global $project_manager_dir, $shortname, $configPath, $configuration, $value;
$configuration = []; $configuration = [];
$jsonFile = $_SERVER['argv'][1]; $jsonFile = $_SERVER['argv'][1];
$cryptKey = $_SERVER['argv'][2];
$configuration = json_decode(file_get_contents($jsonFile), true); $configuration = json_decode(file_get_contents($jsonFile), true);
function readNext($config, &$current, $keyPath = '') { function readNext($config, &$current, $keyPath = '') {
@ -21,11 +22,45 @@ function readNext($config, &$current, $keyPath = '') {
} }
$prompt = "$keyPath.$key: " . ($default !== null ? "[$default]": ""); $prompt = "$keyPath.$key: " . ($default !== null ? "[$default]": "");
$ret = readline($prompt); $ret = readline($prompt);
$current[$key] = "" === $ret ? ($value === null ? null : $default) : $ret;
$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)) {
$ret = filterValue("$keyPath.$key", $ret);
}
$current[$key] = $ret;
} }
} }
} }
function filterValue($fullKey, $value) {
if (preg_match('#pass#', $fullKey)) {
return cryptValue($value);
}
return $value;
}
function cryptValue($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) { foreach ($configuration as $key => $config) {
readNext($config, $configuration[$key], $key); readNext($config, $configuration[$key], $key);
} }

21
src/includes/main_functions

@ -174,8 +174,9 @@ then
if [ "$shortname" != false ] if [ "$shortname" != false ]
then then
local project="$(getConfig false "project_manager.projects.$shortname.project")"
local customer="$(getConfig false "project_manager.projects.$shortname.customer")"
escapedShortname=${shortname//./\\.}
local project="$(getConfig false "project_manager.projects.$escapedShortname.project")"
local customer="$(getConfig false "project_manager.projects.$escapedShortname.customer")"
local project_dir="$project_manager_dir/data/$customer/$project" local project_dir="$project_manager_dir/data/$customer/$project"
fi fi
@ -189,11 +190,12 @@ then
function getCryptKey function getCryptKey
{ {
local shortname="$(getArgument "$1" "shortname required" true)" local shortname="$(getArgument "$1" "shortname required" true)"
if [ "$shortname" != false]
if [ "$shortname" != false ]
then then
echo "$(getConfig "$shortname" "project_manager.cryptkey")" echo "$(getConfig "$shortname" "project_manager.cryptkey")"
else else
echo "$(getConfig "$shortname" "project_manager.projects.$shortname.cryptkey")"
escapedShortname=${shortname//./\\.}
echo "$(getConfig "$shortname" "project_manager.projects.$escapedShortname.cryptkey")"
fi fi
} }
@ -258,7 +260,7 @@ then
echo "$(source "$configScript" has "$shortname" "$configPath")" echo "$(source "$configScript" has "$shortname" "$configPath")"
} }
function readyCryptedConfig
function readCryptedConfig
{ {
local shortname="$(getArgument "$1" "shortname required" true)" local shortname="$(getArgument "$1" "shortname required" true)"
local configPath="$(getArgument "$2" "configPath required" true)" local configPath="$(getArgument "$2" "configPath required" true)"
@ -278,14 +280,14 @@ then
{ {
local password="$(getArgument "$1" "password required" true)" local password="$(getArgument "$1" "password required" true)"
local cryptkey="$(getArgument "$2" "crypt key required" true)" local cryptkey="$(getArgument "$2" "crypt key required" true)"
echo "$password" | openssl enc -base64 -aes-256-cbc -nosalt -nopad -pbkdf2 -k "$cryptkey"
echo "$password" | openssl enc -base64 -nosalt -nopad -pbkdf2 -k "$cryptkey"
} }
function decrypt function decrypt
{ {
local password="$(getArgument "$1" "password required" true)" local password="$(getArgument "$1" "password required" true)"
local cryptkey="$(getArgument "$2" "crypt key required" true)" local cryptkey="$(getArgument "$2" "crypt key required" true)"
echo "$password" | openssl enc -da -aes-256-cbc -nosalt -nopad -pbkdf2 -k "$cryptkey"
echo "$password" | openssl enc -da -nosalt -nopad -pbkdf2 -k "$cryptkey"
} }
function randkey function randkey
@ -341,8 +343,9 @@ then
} }
function configureJsonFile { function configureJsonFile {
local jsonPath="$(getArgument "$1" "json file path required" true)"
local shortname="$(getArgument "$1" "shortname is required" true)"
local jsonPath="$(getArgument "$2" "json file path required" true)"
local configScript="$project_manager_dir/src/includes/configure-json-file" local configScript="$project_manager_dir/src/includes/configure-json-file"
source "$configScript" "$jsonPath"
source "$configScript" "$shortname" "$jsonPath"
} }
fi fi
Loading…
Cancel
Save