2 Commits

  1. 12
      plugins/git/etc/config.json
  2. 7
      plugins/git/src/includes/bash_header
  3. 9
      plugins/plesk/etc/config.json
  4. 26
      plugins/plesk/src/commands/configure-ssh
  5. 62
      plugins/plesk/src/commands/create-domain
  6. 10
      plugins/plesk/src/includes/bash_header
  7. 181
      plugins/ssh/bak/includes.sh
  8. 17
      plugins/ssh/etc/config.json
  9. 67
      plugins/ssh/src/commands/add-key
  10. 58
      plugins/ssh/src/commands/configure-ssh
  11. 48
      plugins/ssh/src/commands/install-keys
  12. 4
      plugins/ssh/src/includes/bash_header
  13. 140
      plugins/ssh/src/includes/ssh
  14. 9
      src/commands/install-plugin
  15. 16
      src/includes/configure-json-file.php
  16. 38
      src/includes/main_functions
  17. 10
      src/includes/plugin_header

12
plugins/git/etc/config.json

@ -1,10 +1,12 @@
{
"git": {
"url": null,
"ssh_user": null,
"ssh_domain": null,
"ssh_private_key": null,
"ssh_public_key": null,
"ssh_private_key_passphrase": null
"ssh": {
"user": null,
"domain": null,
"private_key": null,
"public_key": null,
"private_key_passphrase": null
}
}
}

7
plugins/git/src/includes/bash_header

@ -2,9 +2,4 @@
### 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")"
source "$project_manager_dir/src/includes/plugin_header"

9
plugins/plesk/etc/config.json

@ -1,11 +1,6 @@
{
"plesk": {
"plesk_host": null,
"plesk_user": null,
"plesk_private_key": null,
"plesk_private_key_passphrase": null,
"plesk_public_key": null,
"plesk_db_type": null,
"plesk_binary": "plesk"
"servers": {
}
}
}

26
plugins/plesk/src/commands/configure-ssh

@ -0,0 +1,26 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
function usage {
echo
echoMainTitle "Configures Plesk Server Connection"
echo
echoSubTitle "Usage:"
echo
echo "project-manager plesk:configure-ssh [shortname] [plesk-name] [ssh-connection-name]"
echo
echo "--help Prints this message"
echo
}
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header"
pleskName="$(getArgument "$2" "Plesk name required" true)"
sshConnectionName="$(getArgument "$3" "SSH connection name required" true)"
escapedPleskName=${pleskName//./\\.}
setConfig "$shortname" "plesk.servers.$escapedPleskName.ssh" "$sshConnectionName"
echo
echoSuccess "SSH Connection ($sshConnectionName) setted for Plesk: $pleskName"
echo

62
plugins/plesk/src/commands/create-domain

@ -0,0 +1,62 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
function usage {
echo
echoMainTitle "Creates a domain on plesk server"
echo
echoSubTitle "Usage:"
echo
echo "project-manager plesk:create-domain [shortname] [domain]"
echo
echo "--help Prints this message"
echo
}
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header"
domain="$(getArgument "$2" "domain required" true)"
escapedDomain=${domain//./\\.}
host="$(getConfig "$shortname" "ssh.servers.$escapedDomain.host")"
user="$(getConfig "$shortname" "ssh.servers.$escapedDomain.user")"
port="$(getConfig "$shortname" "ssh.servers.$escapedDomain.port")"
split=($(echo $domain | tr "." "\n"))
count="${#split[@]}"
((length=$count-2))
sub=''
for i in "${!split[@]}"
do
((j=$i+1))
if [ "$j" -lt "$length" ]
then
sub+="${split[$i]}."
fi
if [ "$j" -eq "$length" ]
then
sub+="${split[$i]}"
fi
done
domain="$(echo "$domain" | sed "s/$(sedEscape "$sub")\.//")"
echo
echoMainTitle "Adding domain on plesk server"
echo
echoSubTitle "Please verify data"
echo
echo "-- $env"
echo "Domain: $domain"
echo "Sub: $sub"
echo
echo "Plesk host: $host"
echo "Plesk user: $user"
echo
confirm
pleskAddSSHKey
ssh "$user@$host" "plesk bin subdomain --create '$sub' -domain '$domain' -www-root '/$sub.$domain'"
echo
echoSuccess "Subdomain has been created on plesk"
echo

10
plugins/plesk/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")"

181
plugins/ssh/bak/includes.sh

@ -1,181 +0,0 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
ssh_included=true
function sshValidate {
if [ "$ssh_stage_user" == "" ] || [ "$ssh_stage_domain" == "" ] || [ "$ssh_live_user" == "" ] || [ "$ssh_live_domain" == "" ]
then
echo >&2
echoError "Please configure $project_manager_dir/data/$customer/$project/etc/plugins/ssh/config" >&2
echo >&2
exit
fi
if [ "$git_included" == "" ]
then
echo >&2
echoError "Plugin \"git\" has to be included" >&2
echo >&2
exit
fi
if [ "$git_ssh_user" == "" ] || [ "$git_ssh_domain" == "" ]
then
echo >&2
echoError "Please configure $project_manager_dir/data/$customer/$project/etc/plugins/git/config" >&2
echo >&2
exit
fi
}
function sshGetConfig {
local env=$(getArgument "$1" "Usage getEnvVar [live|stage|git] var" "live stage git")
local suffix=$(getArgument "$2" "Usage getEnvVar [live|stage|git] var" true)
if [ "$env" == "live" ] || [ "$env" == "stage" ]
then
echo "$(eval "echo \"\$ssh_${env}_$suffix\"")"
else
echo "$(eval "echo \"\$${env}_ssh_$suffix\"")"
fi
}
function sshGetPrivateKey
{
local env=$(getArgument "$1" "Usage: sshGetPrivateKey [live|stage|git]" "live stage git")
if [ "$env" == "live" ] || [ "$env" == "stage" ]
then
echo "$(sshGetConfig "$env" "private_key")"
else
echo "$ssh_private_key"
fi
}
function sshGetPublicKey
{
local env=$(getArgument "$1" "Usage: addSSHPublic [live|stage|git]" "live stage git")
if [ "$env" == "live" ] || [ "$env" == "stage" ]
then
echo "$(sshGetConfig "$env" "private_key")"
else
echo "$ssh_private_key"
fi
}
function sshAddKey {
local env="$(getArgument "$1" "Usage: sshAddKey [live|stage|git]" "live stage git")"
local ssh_private_key="$(sshGetPrivateKey "$env")"
local ssh_public_key="$(sshGetPublicKey "$env")"
if [ "$ssh_private_key" != "" ] && [ "$ssh_public_key" != "" ]
then
if [ ! -f "$app_dir/.ssh/$env" ] && [ ! -f "$app_dir/.ssh/$env.pub" ]
then
sshCopyKeys "$env"
fi
else
if [ ! -f "$app_dir/.ssh/$env" ] && [ ! -f "$app_dir/.ssh/$env.pub" ]
then
sshInstallKeys "$env"
fi
fi
ssh-add "$app_dir/.ssh/$env"
}
function sshCopyKeys {
local env=$(getArgument "$1" "Usage: sshCopyKeys [live|stage|git]" "live stage git")
local ssh_private_key="$(sshGetPrivateKey "$env")"
local ssh_public_key="$(sshGetPublicKey "$env")"
if [ ! -f "$ssh_private_key" ] && [ ! -f "$ssh_public_key" ]
then
echo
echoError "Configureg $env key files don't exists" >&2
echo
exit
fi
if [ -f "$app_dir/.ssh/$env" ]
then
echo
echoError "SSH $env private key already exists" >&2
echo
exit
fi
if [ -f "$app_dir/.ssh/$env.pub" ]
then
echo
echoError "SSH $env public key already exists" >&2
echo
exit
fi
sshCopyKey "$env" "$ssh_private_key"
sshCopyKey "$env.pub" "$ssh_public_key"
}
function sshCopyKey {
local name="$(getArgument "$1" "Usage: sshCopyKey [name] [key_path]" true)"
local file="$(getArgument "$2" "Usage: sshCopyKey [name] [key_path]" true)"
cp "$file" "$app_dir/.ssh/$name"
chmod 0600 "$app_dir/.ssh/$name"
}
function sshInstallKeys {
local env=$(getArgument "$1" "Usage: sshInstallKeys [live|stage|git]" "live stage git")
local ssh_private_key="$(sshGetPrivateKey "$env")"
local ssh_public_key="$(sshGetPublicKey "$env")"
local user="$(sshGetConfig "$env" "user")"
local domain="$(sshGetConfig "$env" "domain")"
if [ -f "$ssh_private_key" ] && [ -f "$ssh_public_key" ]
then
echo
echoError "Can't create $env key files, there are already some configured" >&2
echo
exit
fi
if [ -f "$app_dir/.ssh/$env" ]
then
echo
echoError "SSH $env private key already exists" >&2
echo
exit
fi
if [ -f "$app_dir/.ssh/$env.pub" ]
then
echo
echoError "SSH $env public key already exists" >&2
echo
exit
fi
sshGenerateKey "$env"
sshCopyIdKey "$env" "$user@$domain" "$app_dir/.ssh/$env.pub"
}
function sshGenerateKey {
local name="$(getArgument "$1" "Usage: sshGenerateKey [name]" true)"
ssh-keygen -b 4096 -t rsa -f "$app_dir/.ssh/$name" -q -N ""
chmod 0600 "$app_dir/.ssh/$name"
chmod 0600 "$app_dir/.ssh/$name.pub"
}
function sshCopyIdKey {
local name="$(getArgument "$1" "Usage: sshCopyKey [name] [user@host] [file]" true)"
local ssh="$(getArgument "$2" "Usage: sshCopyKey [name] [user@host] [file]" true)"
local file="$(getArgument "$3" "Usage: sshCopyKey [name] [user@host] [file]" true)"
echo "Please enter SSH $name system password:"
ssh-copy-id -i "$file" "$ssh"
}

17
plugins/ssh/etc/config.json

@ -1,20 +1,5 @@
{
"ssh": {
"stage": {
"user": null,
"domain": null,
"port": null,
"private_key": null,
"public_key": null,
"key_passphrase": null
},
"live": {
"user": null,
"domain": null,
"port": null,
"private_key": null,
"public_key": null,
"key_passphrase": null
}
"servers": {}
}
}

67
plugins/ssh/src/commands/add-key

@ -1,67 +0,0 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
function usage {
echo
echoMainTitle "Create, move the ssh keys and install them to server"
echo
echoSubTitle "Usage:"
echo
echo "project-manager ssh:add-key [project-shortname] [env]"
echo
echo " [env] could be live, stage or git"
echo
echo "--help Prints this message"
echo
}
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header"
env="$(getArgument "$2" "$(usage)" "live stage git")"
sshValidate
ssh_private_key="$(sshGetConfig "$env" "private_key")"
ssh_public_key="$(sshGetConfig "$env" "public_key")"
ssh_user="$(sshGetConfig "$env" "user")"
ssh_domain="$(sshGetConfig "$env" "domain")"
echo
echoMainTitle "Adding SSH Keys"
echo
echoSubTitle "Please verify data"
echo
echo "-- $env"
echo "Private key: $ssh_private_key"
echo "Public key: $ssh_public_key"
echo
confirm
if [ "$ssh_private_key" != "" ]
then
target="$app_dir/.ssh/$env"
if [ -f "$source" ] && [ ! -f "$target" ]
then
cp "$ssh_private_key" "target"
chmod 0600 "$target"
fi
fi
if [ "$ssh_public_key" != "" ]
then
target="$app_dir/.ssh/$env.pub"
if [ -f "$source" ] && [ ! -f "$target" ]
then
cp "$ssh_public_key" "target"
chmod 0600 "$target"
fi
fi
if [ "$ssh_private_key" == "" ] && [ "$ssh_public_key" == "" ] && [ ! -f "$app_dir/.ssh/$env" ] && [ ! -f "$app_dir/.ssh/$env.pub" ]
then
ssh-keygen -b 4096 -t rsa -f "$app_dir/.ssh/$env" -q -N ""
chmod 0600 "$app_dir/.ssh/$env"
chmod 0600 "$app_dir/.ssh/$env.pub"
ssh-copy-id -i "$app_dir/.ssh/$env.pub" "$ssh_user"@"$ssh_domain"
fi
ssh-add "$app_dir/.ssh/$env"

58
plugins/ssh/src/commands/configure-ssh

@ -0,0 +1,58 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
function usage {
echo
echoMainTitle "Configure Plugin SSH Domain"
echo
echoSubTitle "Usage:"
echo
echo "project-manager ssh:configure-ssh [shortname] [ssh-connection-name]"
echo
echo "--help Prints this message"
echo
}
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header"
sshConnectionName="$(getArgument "$2" "SSH connection name required" true)"
escapedSSHConnectionName=${sshConnectionName//./\\.}
user="$(getConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.user")"
host="$(getConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.host")"
port="$(getConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.port")"
privateKey="$(getConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.private_key")"
publicKey="$(getConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.public_key")"
echo
echoMainTitle "Configure SSH Connection"
echo
echoSubTitle "Please configure ssh connection: $sshConnectionName"
echo
user=$(readConsole "User" false false "$user");
host="$(readConsole "Host" false false "$host")"
port="$(readConsole "Port" false false "$port")"
privateKey="$(readConsole "Private Key File" false false "$privateKey")"
publicKey="$(readConsole "Public Key File" false false "$publicKey")"
echo
echoSmall "Validate Data:"
echo
echo "User: $user"
echo "Host: $host"
echo "Port: $port"
echo "Private Key File: $privateKey"
echo "Public Key File: $publicKey"
echo
confirm
setConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.user" "$user"
setConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.host" "$host"
setConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.port" "$port"
setConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.private_key" "$privateKey"
setConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.public_key" "$publicKey"
echo
echoSuccess "Configuration written"
echo

48
plugins/ssh/src/commands/install-keys

@ -0,0 +1,48 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
function usage {
echo
echoMainTitle "Generate ssh keys"
echo
echoSubTitle "Usage:"
echo
echo "project-manager ssh:install-keys [shortname] [ssh-connection-name] [key-name]"
echo
echo "--help Prints this message"
echo
}
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header"
sshConnectionName="$(getArgument "$2" "SSH connection name required" true)"
escapedSSHConnectionName=${domain//./\\.}
user="$(getConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.user")"
host="$(getConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.host")"
port="$(getConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.port")"
privateKey="$(getConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.private_key")"
publicKey="$(getConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.public_key")"
name="$user@$host"
echo
echoMainTitle "Install ssh keys"
echo
echoSubTitle "SSH keys for connection: $sshConnectionName"
echo
if [ -f "$privateKey" ] && [ -f "$publicKey" ]
then
sshCopyKeyPair "$shortname" "$name" "$privateKey" "$publicKey"
fi
if [ false == "$(sshHasKeys "$shortname" "$name")" ]
then
sshGenerateKeys "$shortname" "$name"
fi
sshInstallRemoteKey "$shortname" "$name" "$user" "$host" "$port"
echo
echoSuccess "SSH keys installed"
echo

4
plugins/ssh/src/includes/bash_header

@ -2,8 +2,6 @@
### DO NOT EDIT THIS FILE
source "$project_manager_dir/src/includes/bash_header"
shortname="$(getArgument "$1" "shortname required" true)"
source "$project_manager_dir/src/includes/plugin_header"
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/includes"

140
plugins/ssh/src/includes/ssh

@ -6,103 +6,71 @@ if [ true != ${includes_ssh:-false} ]
then
includes_ssh=true
function prepareSSHConnection {
function sshHasKeys {
local shortname="$(getArgument "$1" "shortname required" true)"
local env="$(getArgument "$2" "env required" true)"
local overwrite="$(getArgument "$3")"
local name="$(getArgument "$2" "name required" true)"
local escapedShortname=${shortname//./\\.}
local customer="$(getConfig false "project_manager.projects.$escapedShortname.customer")"
local project="$(getConfig false "project_manager.projects.$escapedShortname.project")"
local sshDir="$project_manager_dir/data/$customer/$project/.ssh"
local privateKey="$(getConfig "$shortname" "ssh.$env.private_key")"
local publicKey="$(getConfig "$shortname" "ssh.$env.public_key")"
copyProjectKeys "$shortname" "$env" "$overwrite"
installRemoteKey "$shortname" "$env"
addKey "$shortname" "$env"
echo [ -f "$sshDir/$name" ] && [ -f "$sshDir/$name.pub" ]
}
function copyProjectKeys
{
function sshGenerateKeys {
local shortname="$(getArgument "$1" "shortname required" true)"
local env="$(getArgument "$2" "env required" true)"
local overwrite="$(getArgument "$3")"
local customer="$(getConfig "$shortname" "project_manager.projects.$shortname.customer")"
local project="$(getConfig "$shortname" "project_manager.projects.$shortname.project")"
local privateKey="$(getConfig "$shortname" "ssh.$env.private_key")"
local publicKey="$(getConfig "$shortname" "ssh.$env.public_key")"
if [ "$privateKey" == "" ] || [ "$publicKey" == "" ]
then
generateKeys "$shortname" "$env"
else
local privateKeyTarget="$project_manager_dir/data/$customer/$project/.ssh/$env.private.key"
local publicKeyTarget="$project_manager_dir/data/$customer/$project/.ssh/$env.public.key"
if [ ! -f "$privateKeyTarget" ] || [ "$overwrite" == true ]
then
cp "$privateKey" "$privateKeyTarget"
chmod 0600 "$privateKeyTarget"
fi
if [ ! -f "$publicKeyTarget" ] || [ "$overwrite" == true ]
then
cp "$publicKey" "$publicKeyTarget"
chmod 0600 "$publicKeyTarget"
fi
fi
local name="$(getArgument "$2" "name required" true)"
local escapedShortname=${shortname//./\\.}
local customer="$(getConfig false "project_manager.projects.$escapedShortname.customer")"
local project="$(getConfig false "project_manager.projects.$escapedShortname.project")"
local tempDir="$project_manager_dir/var/tmp/$customer/$project/ssh-keys"
local sshDir="$project_manager_dir/data/$customer/$project/.ssh"
local date="$(date 'Y.m.d_H:i:s')"
local rand="$shortname-$(cat /proc/sys/kernel/random/uuid)"
local backupDir="$project_manager_dir/.trash/$customer/$project/$rand/.ssh"
if [ ! -d "$sshDir" ]; then mkdir -p "$sshDir"; fi
if [ -f "$sshDir/$name" ] || [ -f "$sshDir/$name.pub" ]; then mkdir -p "$backupDir"; fi
if [ -f "$sshDir/$name" ]; then mv "$sshDir/$name" "$backupDir/$name" && chmod 0600 "$backupDir/$name"; fi
if [ -f "$sshDir/$name.pub" ]; then mv "$sshDir/$name" "$backupDir/$name.pub" && chmod 0600 "$backupDir/$name.pub"; fi
ssh-keygen -b 4096 -t rsa -f "$sshDir/$name" -q -N ""
chmod 0600 "$sshDir/$name"
chmod 0600 "$sshDir/$name.pub"
}
function installRemoteKey
{
function sshCopyKeyPair {
local shortname="$(getArgument "$1" "shortname required" true)"
local env="$(getArgument "$2" "env required" true)"
local customer="$(getConfig "$shortname" "project_manager.projects.$shortname.customer")"
local project="$(getConfig "$shortname" "project_manager.projects.$shortname.project")"
local user="$(getConfig "$shortname" "ssh.$env.user")"
local domain="$(getConfig "$shortname" "ssh.$env.domain")"
local port="$(getConfig "$shortname" "ssh.$env.port")"
local publicKey="$project_manager_dir/data/$customer/$project/.ssh/$env.public.key"
echo "Please enter SSH $name system password:"
ssh-copy-id -p "$port" -i "$publicKey" "$user@$domain"
local name="$(getArgument "$2" "name required" true)"
local privateKeyFile="$(getArgument "$3" "private key file required" true)"
local publicKeyFile="$(getArgument "$4" "public key file required" true)"
local customer="$(getConfig false "project_manager.projects.$escapedShortname.customer")"
local project="$(getConfig false "project_manager.projects.$escapedShortname.project")"
local sshDir="$project_manager_dir/data/$customer/$project/.ssh"
if [ ! -d "$sshDir" ]; then mkdir -p "$sshDir"; fi
if [ -f "$sshDir/$name" ] || [ -f "$sshDir/$name.pub" ]; then mkdir -p "$backupDir"; fi
if [ -f "$sshDir/$name" ]; then mv "$sshDir/$name" "$backupDir/$name" && chmod 0600 "$backupDir/$name"; fi
if [ -f "$sshDir/$name.pub" ]; then mv "$sshDir/$name" "$backupDir/$name.pub" && chmod 0600 "$backupDir/$name.pub"; fi
cp "$privateKeyFile" "$sshDir/$name"
chmod 0600 "$sshDir/$name"
cp "$publicKeyFile" "$sshDir/$name.pub"
chmod 0600 "$sshDir/$name.pub"
}
function addKey {
function sshInstallRemoteKey {
local shortname="$(getArgument "$1" "shortname required" true)"
local env="$(getArgument "$2" "env required" true)"
local customer="$(getConfig "$shortname" "project_manager.projects.$shortname.customer")"
local project="$(getConfig "$shortname" "project_manager.projects.$shortname.project")"
local publicKey="$project_manager_dir/data/$customer/$project/.ssh/$env.public.key"
if [ ! -f "$publicKey" ]
then
copyProjectKeys "$shortname" "$env"
fi
local name="$(getArgument "$2" "name required" true)"
local user="$(getArgument "$3" "user required" true)"
local host="$(getArgument "$4" "host required" true)"
local port="${$(getArgument "$2"):-22}"
local customer="$(getConfig false "project_manager.projects.$escapedShortname.customer")"
local project="$(getConfig false "project_manager.projects.$escapedShortname.project")"
local sshDir="$project_manager_dir/data/$customer/$project/.ssh"
echo "Please enter SSH $user@$host system password:"
ssh-copy-id -p "$port" -i "$sshDir/$name.pub" "$user@$host"
}
function generateKeys {
local shortname="$(getArgument "$1" "shortname required" true)"
local env="$(getArgument "$2" "env required" true)"
local overwrite="$(getArgument "$3")"
local customer="$(getConfig "$shortname" "project_manager.projects.$shortname.customer")"
local project="$(getConfig "$shortname" "project_manager.projects.$shortname.project")"
local privateKey="$project_manager_dir/data/$customer/$project/.ssh/$env.private.key"
local publicKey="$project_manager_dir/data/$customer/$project/.ssh/$env.public.key"
local tempDir="$project_manager_dir/var/tmp/$customer/$project/ssh-keys"
if [[ (! -f "$privateKey" && ! -f "$publicKey") || "$overwrite" == true ]]
then
if [ ! -d "$tempDir" ]; then mkdir -p "$tempDir"; fi
ssh-keygen -b 4096 -t rsa -f "$tempDir/$env" -q -N ""
mv "$tempDir/$env" "$privateKey"
chmod 0600 "$privateKey"
mv "$tempDir/$env.pub" "$publicKey"
chmod 0600 "$publicKey"
rmEmptyDir "$tempDir" 3
fi
}
fi

9
src/commands/install-plugin

@ -21,6 +21,15 @@ plugin=$(getArgument "$2" "plugin required" true)
escapedShortname=${shortname//./\\.}
customer=$(getConfig false "project_manager.projects.$escapedShortname.customer")
project=$(getConfig false "project_manager.projects.$escapedShortname.project")
if [ "" == "$customer" ] || [ "" == "$project" ]
then
echo
echoError "Could not fetch project by shortname: $shortname"
echo
exit
fi
project_dir="$project_manager_dir/data/$customer/$project"
plugin_dir="$project_manager_dir/plugins/$plugin"
source="$project_manager_dir/plugins/$plugin/etc/config.json"

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

@ -20,7 +20,7 @@ function readNext($config, &$current, $keyPath = '') {
if (null === $value) {
$default = null;
}
$prompt = "$keyPath.$key: " . ($default !== null ? "[$default]": "");
$prompt = "$keyPath.$key " . ($default !== null ? "[$default]" : "") . ": ";
$ret = readline($prompt);
$ret = trim($ret);
if ($ret === "null") {
@ -40,21 +40,17 @@ function readNext($config, &$current, $keyPath = '') {
}
}
if (!empty($ret)) {
$ret = filterValue("$keyPath.$key", $ret);
$fullKey = "$keyPath.$key";
if (preg_match('#pass#', $fullKey) && $ret !== $value) {
$ret = encryptValue($value);
}
}
$current[$key] = $ret;
}
}
}
function filterValue($fullKey, $value) {
if (preg_match('#pass#', $fullKey)) {
return cryptValue($value);
}
return $value;
}
function cryptValue($value) {
function encryptValue($value) {
global $cryptKey;
$value = escapeshellcmd($value);
$cryptKeyEscaped = escapeshellcmd($cryptKey);

38
src/includes/main_functions

@ -89,23 +89,23 @@ then
local valid=true
if [ "$allow" == true ] && [ "$var" == "" ]
then
valid=false
elif [ "$allow" != false ] && [ "$allow" != true ]
then
allow=($allow)
local found=false
for i in "${!allow[@]}"
do
if [ "${allow[$i]}" == "$var" ]
then
found=true
fi
done
if [ "$found" != true ]
then
valid=false
fi
then
valid=false
elif [ "$allow" != false ] && [ "$allow" != true ]
then
allow=($allow)
local found=false
for i in "${!allow[@]}"
do
if [ "${allow[$i]}" == "$var" ]
then
found=true
fi
done
if [ "$found" != true ]
then
valid=false
fi
fi
echo $valid
@ -119,7 +119,7 @@ then
if [ "$default" != "" ] && [ "$default" != null ]
then
read -p "$message [default:$default]: " var
read -p "$message [$default]: " var
else
read -p "$message: " var
fi
@ -131,7 +131,7 @@ then
if [ "$(isAllowed "$var" "$allow")" == false ]
then
echo "$errmsg" >&2
echoError "$errmsg" >&2
var=$(readConsole "$message" "$errmsg" "$allow" "$default")
fi

10
src/includes/plugin_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")"
Loading…
Cancel
Save