diff --git a/plugins/git/etc/config.json b/plugins/git/etc/config.json index 380b00f..b823f79 100644 --- a/plugins/git/etc/config.json +++ b/plugins/git/etc/config.json @@ -1,9 +1,10 @@ { "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 } } \ No newline at end of file diff --git a/plugins/git/src/commands/clone b/plugins/git/src/commands/clone index 5c3ef6c..74151ba 100644 --- a/plugins/git/src/commands/clone +++ b/plugins/git/src/commands/clone @@ -14,10 +14,16 @@ function usage { 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 echo echoError "There is no git url configured" @@ -31,17 +37,17 @@ echoMainTitle "Cloning Repository" echo echoSubTitle "Please confirm following data" echo -if [ "$git_ssh_private_key" != "" ] +if [ "$ssh_private_key" != "" ] then echo "SSH Private Key File: $git_ssh_public_key" fi -if [ "$git_ssh_public_key" != "" ] +if [ "$ssh_public_key" != "" ] then echo "SSH Public Key File: $git_ssh_public_key" 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 confirm @@ -55,8 +61,4 @@ then fi sshAddKey "git" -git clone "$git_url" "$workspaces_dir/$customer/$project" - -echo -echoSuccess "GIT cloned" -echo \ No newline at end of file +git clone "$url" "$workspaces_dir/$customer/$project" \ No newline at end of file diff --git a/plugins/git/src/includes/bash_header b/plugins/git/src/includes/bash_header new file mode 100644 index 0000000..e98c337 --- /dev/null +++ b/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")" \ No newline at end of file diff --git a/plugins/git/src/includes/includes b/plugins/git/src/includes/includes deleted file mode 100644 index 415dc7f..0000000 --- a/plugins/git/src/includes/includes +++ /dev/null @@ -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 -} diff --git a/plugins/plesk/commands/create-database b/plugins/plesk/bak/commands/create-database similarity index 100% rename from plugins/plesk/commands/create-database rename to plugins/plesk/bak/commands/create-database diff --git a/plugins/plesk/commands/create-subdomain b/plugins/plesk/bak/commands/create-subdomain similarity index 100% rename from plugins/plesk/commands/create-subdomain rename to plugins/plesk/bak/commands/create-subdomain diff --git a/plugins/plesk/includes/includes b/plugins/plesk/bak/includes/includes similarity index 100% rename from plugins/plesk/includes/includes rename to plugins/plesk/bak/includes/includes diff --git a/plugins/shopware5/includes/includes b/plugins/shopware5/bak/includes similarity index 100% rename from plugins/shopware5/includes/includes rename to plugins/shopware5/bak/includes diff --git a/plugins/shopware6/bin/includes/includes b/plugins/shopware6/bak/includes similarity index 100% rename from plugins/shopware6/bin/includes/includes rename to plugins/shopware6/bak/includes diff --git a/plugins/ssh/bin/includes/includes.sh b/plugins/ssh/bak/includes.sh similarity index 100% rename from plugins/ssh/bin/includes/includes.sh rename to plugins/ssh/bak/includes.sh diff --git a/plugins/ssh/bin/commands/add-key b/plugins/ssh/src/commands/add-key similarity index 92% rename from plugins/ssh/bin/commands/add-key rename to plugins/ssh/src/commands/add-key index 46d4de0..28e784f 100644 --- a/plugins/ssh/bin/commands/add-key +++ b/plugins/ssh/src/commands/add-key @@ -16,7 +16,7 @@ function usage { 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")" sshValidate diff --git a/plugins/ssh/bin/includes/bash_header b/plugins/ssh/src/includes/bash_header similarity index 94% rename from plugins/ssh/bin/includes/bash_header rename to plugins/ssh/src/includes/bash_header index 7211e35..4bc0fdf 100644 --- a/plugins/ssh/bin/includes/bash_header +++ b/plugins/ssh/src/includes/bash_header @@ -6,4 +6,4 @@ source "$project_manager_dir/src/includes/bash_header" shortname="$(getArgument "$1" "shortname required" true)" -source "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/ssh" \ No newline at end of file +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/includes" \ No newline at end of file diff --git a/plugins/ssh/bin/includes/includes b/plugins/ssh/src/includes/includes similarity index 100% rename from plugins/ssh/bin/includes/includes rename to plugins/ssh/src/includes/includes diff --git a/plugins/ssh/bin/includes/ssh b/plugins/ssh/src/includes/ssh similarity index 100% rename from plugins/ssh/bin/includes/ssh rename to plugins/ssh/src/includes/ssh diff --git a/src/commands/configure-plugin b/src/commands/configure-plugin index 9e9a49c..af7170b 100644 --- a/src/commands/configure-plugin +++ b/src/commands/configure-plugin @@ -36,4 +36,4 @@ echo echoMainTitle "Configure Plugin: $plugin" echo -configureJsonFile "$config_path" \ No newline at end of file +configureJsonFile "$shortname" "$config_path" \ No newline at end of file diff --git a/src/includes/configure-json-file b/src/includes/configure-json-file index f1deaac..e37e981 100644 --- a/src/includes/configure-json-file +++ b/src/includes/configure-json-file @@ -8,7 +8,7 @@ function usage { echo echoSubTitle "Usage:" echo - echo "configure-json-file filePath" + echo "configure-json-file shortname filePath" echo echo "--help Prints this message" echo " " @@ -17,7 +17,10 @@ function usage { 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" ] then echo @@ -28,4 +31,4 @@ fi PHP=`which php` script="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/configure-json-file.php" -$PHP "$script" "$@" \ No newline at end of file +$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 index e6b846f..7ea5915 100644 --- a/src/includes/configure-json-file.php +++ b/src/includes/configure-json-file.php @@ -5,6 +5,7 @@ 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 = '') { @@ -21,11 +22,45 @@ function readNext($config, &$current, $keyPath = '') { } $prompt = "$keyPath.$key: " . ($default !== null ? "[$default]": ""); $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) { readNext($config, $configuration[$key], $key); } diff --git a/src/includes/main_functions b/src/includes/main_functions index 4a33da7..b753b4a 100644 --- a/src/includes/main_functions +++ b/src/includes/main_functions @@ -174,8 +174,9 @@ then if [ "$shortname" != false ] 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" fi @@ -189,11 +190,12 @@ then function getCryptKey { local shortname="$(getArgument "$1" "shortname required" true)" - if [ "$shortname" != false] + if [ "$shortname" != false ] then echo "$(getConfig "$shortname" "project_manager.cryptkey")" else - echo "$(getConfig "$shortname" "project_manager.projects.$shortname.cryptkey")" + escapedShortname=${shortname//./\\.} + echo "$(getConfig "$shortname" "project_manager.projects.$escapedShortname.cryptkey")" fi } @@ -258,7 +260,7 @@ then echo "$(source "$configScript" has "$shortname" "$configPath")" } - function readyCryptedConfig + function readCryptedConfig { local shortname="$(getArgument "$1" "shortname required" true)" local configPath="$(getArgument "$2" "configPath required" true)" @@ -278,14 +280,14 @@ then { local password="$(getArgument "$1" "password 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 { local password="$(getArgument "$1" "password 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 @@ -341,8 +343,9 @@ then } 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" - source "$configScript" "$jsonPath" + source "$configScript" "$shortname" "$jsonPath" } fi \ No newline at end of file