From 252537b516ca92ccb80e0e87dd87ec342a5f7499 Mon Sep 17 00:00:00 2001 From: Sven Ullmann Date: Tue, 4 Jul 2023 21:06:57 +0200 Subject: [PATCH] refactoring --- .gitignore | 2 + README.md | 2 + plugins/db/etc/config.json | 64 ++++---- plugins/db/etc/live.my.cnf | 22 --- plugins/db/etc/stage.my.cnf | 22 --- plugins/db/src/commands/backup | 39 +++-- plugins/db/src/commands/create-config | 140 ----------------- plugins/db/src/includes/bash_header | 17 ++ plugins/db/src/includes/db | 85 ++++++++++ plugins/db/src/includes/db_my | 64 ++++++++ plugins/db/src/includes/includes | 73 +-------- plugins/db/src/includes/includes.sh | 77 +++++++++ plugins/git/etc/config | 12 -- plugins/git/etc/config.json | 9 ++ plugins/plesk/etc/config | 10 -- plugins/plesk/etc/config.json | 11 ++ plugins/shopware5/etc/config | 70 --------- plugins/shopware5/etc/config.json | 56 +++++++ plugins/shopware6/etc/config | 86 ----------- plugins/shopware6/etc/config.json | 67 ++++++++ plugins/ssh/{ => bin}/commands/add-key | 0 plugins/ssh/bin/includes/bash_header | 9 ++ plugins/ssh/bin/includes/includes | 5 + .../includes => bin/includes/includes.sh} | 0 plugins/ssh/bin/includes/ssh | 108 +++++++++++++ plugins/ssh/etc/config | 15 -- plugins/ssh/etc/config.json | 20 +++ src/commands/create-project | 3 + src/commands/install-plugin | 4 +- src/commands/install-project-manager | 8 +- src/includes/config.php | 2 +- src/includes/json | 35 +++++ src/includes/json.php | 78 ++++++++++ src/includes/main_functions | 146 ++++++++++++++++-- src/includes/project_manager | 15 ++ var/.keep | 0 var/tmp/.keep | 0 37 files changed, 862 insertions(+), 514 deletions(-) delete mode 100644 plugins/db/etc/live.my.cnf delete mode 100644 plugins/db/etc/stage.my.cnf delete mode 100644 plugins/db/src/commands/create-config create mode 100644 plugins/db/src/includes/bash_header create mode 100644 plugins/db/src/includes/db create mode 100644 plugins/db/src/includes/db_my create mode 100644 plugins/db/src/includes/includes.sh delete mode 100644 plugins/git/etc/config create mode 100644 plugins/git/etc/config.json delete mode 100644 plugins/plesk/etc/config create mode 100644 plugins/plesk/etc/config.json delete mode 100644 plugins/shopware5/etc/config create mode 100644 plugins/shopware5/etc/config.json delete mode 100644 plugins/shopware6/etc/config create mode 100644 plugins/shopware6/etc/config.json rename plugins/ssh/{ => bin}/commands/add-key (100%) create mode 100644 plugins/ssh/bin/includes/bash_header create mode 100644 plugins/ssh/bin/includes/includes rename plugins/ssh/{includes/includes => bin/includes/includes.sh} (100%) create mode 100644 plugins/ssh/bin/includes/ssh delete mode 100644 plugins/ssh/etc/config create mode 100644 plugins/ssh/etc/config.json create mode 100644 src/includes/json create mode 100755 src/includes/json.php create mode 100644 var/.keep create mode 100644 var/tmp/.keep diff --git a/.gitignore b/.gitignore index 3e5d6a7..9e001fe 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,7 @@ /src/postscripts/plugins/* /data/* /etc/* +/var/* +/var/tmp/* !/**/.keep \ No newline at end of file diff --git a/README.md b/README.md index b5770ac..920527c 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ Hope you will enjoy. Free to use. ### Prerequisites - PHP +- OpenSSL +- scp ### Install Project Manager diff --git a/plugins/db/etc/config.json b/plugins/db/etc/config.json index d9e3da6..1790d4e 100644 --- a/plugins/db/etc/config.json +++ b/plugins/db/etc/config.json @@ -1,44 +1,44 @@ { "db": { "stage": { - "socket": "", - "host": "", - "port": "", - "database": "", - "user": "", - "password": "", - "admin_user": "", - "admin_password": "" + "socket": null, + "host": null, + "port": null, + "database": null, + "user": null, + "password": null, + "admin_user": null, + "admin_password": null }, "live": { - "socket": "", - "host": "", - "port": "", - "database": "", - "user": "", - "password": "", - "admin_user": "", - "admin_password": "" + "socket": null, + "host": null, + "port": null, + "database": null, + "user": null, + "password": null, + "admin_user": null, + "admin_password": null }, "local_stage": { - "socket": "", - "host": "", - "port": "", - "database": "", - "user": "", - "password": "", - "admin_user": "", - "admin_password": "" + "socket": null, + "host": null, + "port": null, + "database": null, + "user": null, + "password": null, + "admin_user": null, + "admin_password": null }, "local_live": { - "socket": "", - "host": "", - "port": "", - "database": "", - "user": "", - "password": "", - "admin_user": "", - "admin_password": "" + "socket": null, + "host": null, + "port": null, + "database": null, + "user": null, + "password": null, + "admin_user": null, + "admin_password": null } } } diff --git a/plugins/db/etc/live.my.cnf b/plugins/db/etc/live.my.cnf deleted file mode 100644 index add3038..0000000 --- a/plugins/db/etc/live.my.cnf +++ /dev/null @@ -1,22 +0,0 @@ - -### DO NOT EDIT THIS FILE - -[mysqldump] -max_allowed_packet=500M -socket= -host= -port= - -[mysql] -max_allowed_packet=500M -socket= -host= -port= - -[client] -user= -password= - -[clientadmin] -user= -password= \ No newline at end of file diff --git a/plugins/db/etc/stage.my.cnf b/plugins/db/etc/stage.my.cnf deleted file mode 100644 index add3038..0000000 --- a/plugins/db/etc/stage.my.cnf +++ /dev/null @@ -1,22 +0,0 @@ - -### DO NOT EDIT THIS FILE - -[mysqldump] -max_allowed_packet=500M -socket= -host= -port= - -[mysql] -max_allowed_packet=500M -socket= -host= -port= - -[client] -user= -password= - -[clientadmin] -user= -password= \ No newline at end of file diff --git a/plugins/db/src/commands/backup b/plugins/db/src/commands/backup index e9e5408..c75067f 100644 --- a/plugins/db/src/commands/backup +++ b/plugins/db/src/commands/backup @@ -8,37 +8,46 @@ function usage { echo echoSubTitle "Usage:" echo - echo "project-manager db:backup [project-shortname] [env]" + echo "project-manager db:backup [shortname] [env]" echo - echo " [env] can be live, stage, local_live or local_stage" + echo "[env]: can be live, stage, local_live or local_stage" echo - echo "--help Prints this message" + echo "--ignored-data-tables space seperated list of ignored tables" + echo "--mysqldump-parameters space separated mysqldump parameters" + echo + echo "--help Prints this message" echo } -help="$(getParameter "--help" false "$*")" -if [ "$help" == true ] || [ "$1" == "" ] -then - usage - exit -fi +source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header" + +shortname="$(getArgument "$1" "$(usageError "shortname required")" true)" +env="$(getArgument "$2" "$(usageError "env required")" true)" +ignoredDataTables="$(getParameter "--ignored-data-tables" "$*")" +mysqldumpParameters="$(getParameter "--mysqldump-parameters" "$*")" + +initMy "$shortname" "$env" -source "$project_manager_dir/bin/includes/project_header" -env="$(getArgument "$2" "$(usage)" "live stage local_live local_stage")" -dbValidate +customer="$(getConfig false "project_manager.projects.$shortname.customer")" +project="$(getConfig false "project_manager.projects.$shortname.project")" -database=$(dbGetConfig "$env" "database") +dbBackupDir="$project_manager_dir/data/$customer/$project/backup/database"; +if [ ! -d "$dbBackupDir" ]; then mkdir -p "$dbBackupDir"; fi echo echoMainTitle "Backup database $env" echo echo "Backup structure ..." -db="$(dbDump "$env" "structure" "--no-data" "$database")" +dbdumpStructureTempFile="$(dbDump "$shortname" "$env" "structure" "$ignoredDataTables" "$mysqldumpParameters")" +cp "$dbdumpStructureTempFile" "$project_manager_dir/data/$customer/$project/backup/." +rm "$dbdumpStructureTempFile" echo "Database structure backed up to: $db" echo "Backup data ..." -db="$(dbDump "$env" "data" "--no-create-info --skip-triggers" "$database")" +dbdumpDataTempFile="$(dbDump "$shortname" "$env" "data" "$ignoredDataTables" "$mysqldumpParameters")" +cp "$dbdumpDataTempFile" "$project_manager_dir/data/$customer/$project/backup/." +rm "$dbdumpDataTempFile" echo "Database data backed up to: $db" echo diff --git a/plugins/db/src/commands/create-config b/plugins/db/src/commands/create-config deleted file mode 100644 index 736fdd2..0000000 --- a/plugins/db/src/commands/create-config +++ /dev/null @@ -1,140 +0,0 @@ -#!/bin/bash - -### DO NOT EDIT THIS FILE - -function usage { - echo - echoMainTitle "Create configuration files" - echo - echoSubTitle "Usage:" - echo - echo "project-manager db:create-config [project-shortname]" - echo - echo "--help Prints this message" - echo -} - -help="$(getParameter "--help" false "$*")" -if [ "$help" == true ] || [ "$1" == "" ] -then - usage - exit -fi - -source "$project_manager_dir/bin/includes/project_header" -dbValidate - -echo -echoMainTitle "Creating db configuration" -echo -echoSubTitle "Please verify data" -echo -echo "Stage Socket: $db_stage_socket" -echo "Stage Host: $db_stage_host" -echo "Stage Port: $db_stage_port" -echo "Stage Database: $db_stage_database" -echo "Stage Admin User: $db_stage_admin_user" -echo -echo "Live Socket: $db_live_socket" -echo "Live Host: $db_live_host" -echo "Live Port: $db_live_port" -echo "Live Database: $db_live_database" -echo "Live Admin User: $db_live_admin_user" -echo -echo "Local Stage Socket: $db_local_stage_socket" -echo "Local Stage Host: $db_local_stage_host" -echo "Local Stage Port: $db_local_stage_port" -echo "Local Stage Database: $db_local_stage_database" -echo "Local Stage Admin User: $db_local_stage_admin_user" -echo -echo "Local Live Socket: $db_local_live_socket" -echo "Local Live Host: $db_local_live_host" -echo "Local Live Port: $db_local_live_port" -echo "Local Live Database: $db_local_live_database" -echo "Local Live Admin User: $db_local_live_admin_user" -echo -confirm - -template_file="$project_manager_dir/plugins/db/etc/.my.cnf_template" -path="$project_manager_dir/data/$customer/$project" - -quoted_socket="$(sedEscape "$db_stage_socket")" -quoted_password="$(sedEscape "$db_stage_password")" -quoted_admin_password="$(sedEscape "$db_stage_admin_password")" -if [ "$quoted_socket" == "" ] -then - file_string="$(cat "$template_file" | sed "s/socket=//")" -else - file_string="$(cat "$template_file")" -fi -echo "$file_string" | \ - sed "s/socket=/socket=$quoted_socket/" | \ - sed "s/host=/host=$db_stage_host/" | \ - sed "s/port=/port=$db_stage_port/" | \ - sed "s/database=/database=$db_stage_database/" | \ - sed "s/\[client\]/\[client\]\nuser=$db_stage_user\npassword=$quoted_password/" | \ - sed "s/\[clientadmin\]/\[clientadmin\]\nuser=$db_stage_admin_user\npassword=$quoted_admin_password/" \ - > "$path/etc/stage.my.cnf" - -quoted_socket="$(sedEscape "$db_live_socket")" -quoted_password="$(sedEscape "$db_live_password")" -quoted_admin_password="$(sedEscape "$db_live_admin_password")" -if [ "$quoted_socket" == "" ] -then - file_string="$(cat "$template_file" | sed "s/socket=//")" -else - file_string="$(cat "$template_file")" -fi -echo "$file_string" | \ - sed "s/socket=/socket=$quoted_socket/" | \ - sed "s/host=/host=$db_live_host/" | \ - sed "s/port=/port=$db_live_port/" | \ - sed "s/database=/database=$db_live_database/" | \ - sed "s/\[client\]/\[client\]\nuser=$db_live_user\npassword=$quoted_password/" | \ - sed "s/\[clientadmin\]/\[clientadmin\]\nuser=$db_live_admin_user\npassword=$quoted_admin_password/" \ - > "$path/etc/live.my.cnf" - -quoted_socket="$(sedEscape "$db_local_stage_socket")" -quoted_password="$(sedEscape "$db_local_stage_password")" -quoted_admin_password="$(sedEscape "$db_local_stage_admin_password")" -if [ "$quoted_socket" == "" ] -then - file_string="$(cat "$template_file" | sed "s/socket=//")" -else - file_string="$(cat "$template_file")" -fi -echo "$file_string" | \ - sed "s/socket=/socket=$quoted_socket/" | \ - sed "s/host=/host=$db_local_stage_host/" | \ - sed "s/port=/port=$db_local_stage_port/" | \ - sed "s/database=/database=$db_local_stage_database/" | \ - sed "s/\[client\]/\[client\]\nuser=$db_local_stage_user\npassword=$quoted_password/" | \ - sed "s/\[clientadmin\]/\[clientadmin\]\nuser=$db_local_stage_admin_user\npassword=$quoted_admin_password/" \ - > "$path/etc/local_stage.my.cnf" - -quoted_socket="$(sedEscape "$db_local_live_socket")" -quoted_password="$(sedEscape "$db_local_live_password")" -quoted_admin_password="$(sedEscape "$db_local_live_admin_password")" -if [ "$quoted_socket" == "" ] -then - file_string="$(cat "$template_file" | sed "s/socket=//")" -else - file_string="$(cat "$template_file")" -fi -echo "$file_string" | \ - sed "s/socket=/socket=$quoted_socket/" | \ - sed "s/host=/host=$db_local_live_host/" | \ - sed "s/port=/port=$db_local_live_port/" | \ - sed "s/database=/database=$db_local_live_database/" | \ - sed "s/\[client\]/\[client\]\nuser=$db_local_live_user\npassword=$quoted_password/" | \ - sed "s/\[clientadmin\]/\[clientadmin\]\nuser=$db_local_live_admin_user\npassword=$quoted_admin_password/" \ - > "$path/etc/local_live.my.cnf" - -echo -echoSubTitle "Running postscripts ..." -postScript "$path/bin/postscripts/plugins/db/commands/create-config" -postScript "$workspaces_dir/$customer/$project/bin/postscripts/plugins/db/commands/create-config" - -echo -echoSuccess "Database configuration files created" -echo \ No newline at end of file diff --git a/plugins/db/src/includes/bash_header b/plugins/db/src/includes/bash_header new file mode 100644 index 0000000..cd8c66b --- /dev/null +++ b/plugins/db/src/includes/bash_header @@ -0,0 +1,17 @@ +#!/bin/bash + +### DO NOT EDIT THIS FILE + +source "$project_manager_dir/src/includes/bash_header" + +shortname="$(getArgument "$1" "shortname required" true)" + +if [ "$(isPluginEnabled "$shortname" "ssh")" == false ] +then + echo + echoError "Plugin 'db' depends on plugin 'ssh'" + echo + exit +fi + +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/includes" \ No newline at end of file diff --git a/plugins/db/src/includes/db b/plugins/db/src/includes/db new file mode 100644 index 0000000..9954f07 --- /dev/null +++ b/plugins/db/src/includes/db @@ -0,0 +1,85 @@ +#!/bin/bash + +### DO NOT EDIT THIS FILE + +if [ true != ${includes_db:-false} ] +then + includes_db=true + + function dbDump { + shortname="$(getArgument "$1" "shortname required" true)" + env="$(getArgument "$2" "env required" true)" + mode="$(getArgument "$3" "mode [structure|data|all]" "structure data all")" + skippedTables="$(getArgument "$4")" + mysqldumpParameters="$(getArgument "$5")" + + customer="$(getConfig false "project_manager.projects.$shortname.customer")" + project="$(getConfig false "project_manager.projects.$shortname.project")" + + if [ "$mode" == "all" ]; then mode=""; fi + if [ "$mode" == "data" ]; then mode="--no-create-info"; fi + if [ "$mode" == "structure" ]; then mode="--no-data"; fi + + if [[ "$env" == *"local_"* ]] + then + local=true + else + local=false + prepareSSHConnection "$shortname" "$env" + fi + + if [ "$local" == false ] + then + sshUser="$(getConfig "$shortname" "ssh.$env.user")" + sshDomain="$(getConfig "$shortname" "ssh.$env.domain")" + sshPort="$(getConfig "$shortname" "ssh.$env.port")" + fi + + socket="$(getConfig "$shortname" "db.$env.socket")" + host="$(getConfig "$shortname" "db.$env.host")" + database="$(getConfig "$shortname" "db.$env.database")" + user="$(getConfig "$shortname" "db.$env.user")" + port="$(getConfig "$shortname" "db.$env.port")" + password="$(getCryptedConfig "$shortname" "db.$env.password")" + admin_user="$(getConfig "$shortname" "db.$env.admin_user")" + admin_password="$(getConfig "$shortname" "db.$env.admin_password")" + + date="$(date +"%Y.%m.%d-%H:%M:%S")" + filenamePrefix="$shortname-$env.$date." + + local ignoreTables=""; + for table in "${skippedTables[@]}" + do + ignoredTables="$ignoredTables --ignore-table=\"$database.$table\"" + done + + local tempdir="$project_manager_dir/var/tmp/$customer/$project/dbdump" + if [ ! -d "$tempdir" ] + then + mkdir -p "$tempdir" + fi + + if [ "$local" == false ] + then + + + ssh -p "$sshPort" "$sshUser"@"$sshDomain" "cat \"$(generateMy "$shortname" "$env")\" > ~/$env.my.cnf" + ssh "$sshUser"@"$sshDomain" "mysqldump --defaults-extra-file=~/$env.my.cnf --no-tablespaces \ + $ignoredTables ${mysqldumpParameters[*]} $mode $database | \ + LANG=C LC_CTYPE=C LC_ALL=C sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | \ + sed -e 's/,NO_AUTO_CREATE_USER//' | gzip -9 > ~/$filenamePrefix.sql.gz" + scp -P "$sshPort" "$sshUser"@"$sshDomain":"~/$filenamePrefix.sql.gz" "$tempdir/$filenamePrefix.sql.gz" + ssh -p "$sshPort" "$sshUser"@"$sshDomain" "unlink ~/$filenamePrefix.sql.gz" + else + cat "$(generateMy "$shortname" "$env")" > "$tempdir/$env.my.cnf" + mysqldump --defaults-extra-file="$tempdir/$env.my.cnf" --no-tablespaces \ + $ignoredTables ${mysqldumpParameters[*]} $mode $database | \ + LANG=C LC_CTYPE=C LC_ALL=C sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | \ + sed -e 's/,NO_AUTO_CREATE_USER//' | gzip -9 > "$tempdir/$filenamePrefix.sql.gz" + rm "$tempdir/$env.my.cnf" + fi + + echo "$tempdir/$filenamePrefix.sql.gz" + } + +fi \ No newline at end of file diff --git a/plugins/db/src/includes/db_my b/plugins/db/src/includes/db_my new file mode 100644 index 0000000..38b7608 --- /dev/null +++ b/plugins/db/src/includes/db_my @@ -0,0 +1,64 @@ +#!/bin/bash + +### DO NOT EDIT THIS FILE + +if [ true != ${includes_db_my:-false} ] +then + includes_db_my=true + + myContainer=null + + function initMy { + if [ "$myContainer" != null ] + then + exit + fi + + local shortname="$(getArgument "$1" "shortname required" true)" + local env="$(getArgument "$2" "env required" true)" + + local socket="$(getConfig "$shortname" "db.$env.socket")" + local host="$(getConfig "$shortname" "db.$env.host")" + local database="$(getConfig "$shortname" "db.$env.database")" + local user="$(getConfig "$shortname" "db.$env.user")" + local port="$(getConfig "$shortname" "db.$env.port")" + local password="$(getCryptedConfig "$shortname" "db.$env.password")" + local admin_user="$(getConfig "$shortname" "db.$env.admin_user")" + local admin_password="$(getConfig "$shortname" "db.$env.admin_password")" + + jsonSet "$myContainer" "$shortname.$env.mysqldump.max_allowed_packet" "500M" + jsonSet "$myContainer" "$shortname.$env.mysqldump.socket" "$socket" + jsonSet "$myContainer" "$shortname.$env.mysqldump.host" "$host" + jsonSet "$myContainer" "$shortname.$env.mysqldump.port" "$port" + jsonSet "$myContainer" "$shortname.$env.mysql.max_allowed_packet" "500M" + jsonSet "$myContainer" "$shortname.$env.mysql.socket" "$socket" + jsonSet "$myContainer" "$shortname.$env.mysql.host" "$host" + jsonSet "$myContainer" "$shortname.$env.mysql.port" "$port" + jsonSet "$myContainer" "$shortname.$env.client.user" "$user" + jsonSet "$myContainer" "$shortname.$env.client.password" "$password" + jsonSet "$myContainer" "$shortname.$env.clientadmin.user" "$admin_user" + jsonSet "$myContainer" "$shortname.$env.clientadmin.password" "$admin_password" + } + + function generateMy { + local shortname="$(getArgument "$1" "shortname required" true)" + local env="$(getArgument "$2" "env required" true)" + local my="" + + local segments="$(jsonGet "$myContainer" "$shortname.$env")"; + for segmentName in "${segments[@]}" + do + my="\n$my"; + local parameters="$(jsonGet "$myContainer" "$shortname.$env.$segmentName")" + for parameterName in "$(parameters[@])" + do + local parameterValue="$(jsonGet "$myContainer" "$shortname.$env.$segmentName.$parameterName")" + my="$my\n$parameterName = $parameterValue" + done + my "$my\n" + done + + echo "$my" + } + +fi \ No newline at end of file diff --git a/plugins/db/src/includes/includes b/plugins/db/src/includes/includes index 8a48101..4c9076e 100644 --- a/plugins/db/src/includes/includes +++ b/plugins/db/src/includes/includes @@ -2,74 +2,5 @@ ### DO NOT EDIT THIS FILE -db_included=true - -function dbValidate { - if ([ "$db_local_stage_user" == "" ] && [ "$db_local_live_user" == "" ]) - then - echo >&2 - echoError "Please configure $project_manager_dir/data/$customer/$project/etc/plugins/db/config" >&2 - echo >&2 - exit - fi - - if [ "$ssh_included" == "" ] - then - echo >&2 - echoError "Plugin \"ssh\" has to be included" >&2 - echo >&2 - exit - fi -} - -function dbGetConfig { - local env=$(getArgument "$1" "Usage dbGetConfig [live|stage|local_live|local_stage] var" "live stage local_live local_stage") - local suffix=$(getArgument "$2" "Usage dbGetConfig [live|stage|local_live|local_stage] var" true) - - echo "$(eval "echo \"\$db_${env}_$suffix\"")" -} - -function dbDump { - local env=$(getArgument "$1" "Usage: dbDump [env] [filename] [mysqldump-parameters] [database] [tables]" true) - local name=$(getArgument "$2" "Usage: dbDump [env] [filename] [mysqldump-parameters] [database] [tables]" true) - local parameters=$(getArgument "$3" "Usage: dbDump [env] [filename] [mysqldump-parameters] [database] [tables]") - local database=$(getArgument "$4" "Usage: dbDump [env] [filename] [mysqldump-parameters] [database] [tables]" true) - local tables=$(getArgument "$5" "Usage: dbDump [env] [filename] [mysqldump-parameters] [database] [tables]") - - local currentDate=$(date '+%Y-%m-%d_%H:%M:%S') - local is_remote="$(if [ "$env" == "live" ] || [ "$env" == "stage" ]; then echo 1; else echo 0; fi)" - - if [ "$is_remote" == 1 ] - then - local ssh_user="$(sshGetConfig "$env" "user")" - local ssh_domain="$(sshGetConfig "$env" "domain")" - sshAddKey "$env" - - scp "$app_dir/etc/plugins/db/$env.my.cnf" "$ssh_user"@"$ssh_domain":"~/$env.my.cnf" - ssh "$ssh_user"@"$ssh_domain" "mysqldump --defaults-extra-file=~/$env.my.cnf --no-tablespaces ${parameters[*]} $database $tables | \ - LANG=C LC_CTYPE=C LC_ALL=C sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | \ - sed -e 's/,NO_AUTO_CREATE_USER//' | gzip -9 > ~/${env}_$name.sql.gz" - scp "$ssh_user"@"$ssh_domain":"~/${env}_$name.sql.gz" "$app_dir/var/tmp/$currentDate-${env}_$name.sql.gz" - ssh "$ssh_user"@"$ssh_domain" "unlink ~/${env}_$name.sql.gz" - - gunzip "$app_dir/var/tmp/$currentDate-${env}_$name.sql.gz" - else - mysqldump --defaults-extra-file="$app_dir/plugins/db/etc/${env}.my.cnf" --no-tablespaces ${parameters[*]} $database $tables | \ - LANG=C LC_CTYPE=C LC_ALL=C sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | sed -e 's/,NO_AUTO_CREATE_USER//' \ - > "$app_dir/var/tmp/${currentDate}-${env}_$name.sql" - fi - - if [[ "$(tail -n 2 "$app_dir/var/tmp/$currentDate-${env}_$name.sql" )" != *"-- Dump completed"* ]] - then - rm "$app_dir/var/tmp/$currentDate-${env}_$name.sql" - echo - echoError "File was corrupted, deleting" - echo - exit - fi - - gzip -c "$app_dir/var/tmp/${currentDate}-${env}_$name.sql.gz" > "$app_dir/backup/database/${currentDate}-${env}_$name.sql.gz" - rm "$app_dir/var/tmp/$currentDate-${env}_$name.sql" - - echo "$app_dir/backup/database/$currentDate-${env}_$name.sql.gz" -} \ No newline at end of file +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/db" +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/db_my" diff --git a/plugins/db/src/includes/includes.sh b/plugins/db/src/includes/includes.sh new file mode 100644 index 0000000..87fe39b --- /dev/null +++ b/plugins/db/src/includes/includes.sh @@ -0,0 +1,77 @@ +#!/bin/bash + +### DO NOT EDIT THIS FILE + +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/db" + +db_included=true + +function dbValidate { + if ([ "$db_local_stage_user" == "" ] && [ "$db_local_live_user" == "" ]) + then + echo >&2 + echoError "Please configure $project_manager_dir/data/$customer/$project/etc/plugins/db/config" >&2 + echo >&2 + exit + fi + + if [ "$ssh_included" == "" ] + then + echo >&2 + echoError "Plugin \"ssh\" has to be included" >&2 + echo >&2 + exit + fi +} + +function dbGetConfig { + local env=$(getArgument "$1" "Usage dbGetConfig [live|stage|local_live|local_stage] var" "live stage local_live local_stage") + local suffix=$(getArgument "$2" "Usage dbGetConfig [live|stage|local_live|local_stage] var" true) + + echo "$(eval "echo \"\$db_${env}_$suffix\"")" +} + +function dbDump { + local env=$(getArgument "$1" "Usage: dbDump [env] [filename] [mysqldump-parameters] [database] [tables]" true) + local name=$(getArgument "$2" "Usage: dbDump [env] [filename] [mysqldump-parameters] [database] [tables]" true) + local parameters=$(getArgument "$3" "Usage: dbDump [env] [filename] [mysqldump-parameters] [database] [tables]") + local database=$(getArgument "$4" "Usage: dbDump [env] [filename] [mysqldump-parameters] [database] [tables]" true) + local tables=$(getArgument "$5" "Usage: dbDump [env] [filename] [mysqldump-parameters] [database] [tables]") + + local currentDate=$(date '+%Y-%m-%d_%H:%M:%S') + local is_remote="$(if [ "$env" == "live" ] || [ "$env" == "stage" ]; then echo 1; else echo 0; fi)" + + if [ "$is_remote" == 1 ] + then + local ssh_user="$(sshGetConfig "$env" "user")" + local ssh_domain="$(sshGetConfig "$env" "domain")" + sshAddKey "$env" + + scp "$app_dir/etc/plugins/db/$env.my.cnf" "$ssh_user"@"$ssh_domain":"~/$env.my.cnf" + ssh "$ssh_user"@"$ssh_domain" "mysqldump --defaults-extra-file=~/$env.my.cnf --no-tablespaces ${parameters[*]} $database $tables | \ + LANG=C LC_CTYPE=C LC_ALL=C sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | \ + sed -e 's/,NO_AUTO_CREATE_USER//' | gzip -9 > ~/${env}_$name.sql.gz" + scp "$ssh_user"@"$ssh_domain":"~/${env}_$name.sql.gz" "$app_dir/var/tmp/$currentDate-${env}_$name.sql.gz" + ssh "$ssh_user"@"$ssh_domain" "unlink ~/${env}_$name.sql.gz" + + gunzip "$app_dir/var/tmp/$currentDate-${env}_$name.sql.gz" + else + mysqldump --defaults-extra-file="$app_dir/plugins/db/etc/${env}.my.cnf" --no-tablespaces ${parameters[*]} $database $tables | \ + LANG=C LC_CTYPE=C LC_ALL=C sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | sed -e 's/,NO_AUTO_CREATE_USER//' \ + > "$app_dir/var/tmp/${currentDate}-${env}_$name.sql" + fi + + if [[ "$(tail -n 2 "$app_dir/var/tmp/$currentDate-${env}_$name.sql" )" != *"-- Dump completed"* ]] + then + rm "$app_dir/var/tmp/$currentDate-${env}_$name.sql" + echo + echoError "File was corrupted, deleting" + echo + exit + fi + + gzip -c "$app_dir/var/tmp/${currentDate}-${env}_$name.sql.gz" > "$app_dir/backup/database/${currentDate}-${env}_$name.sql.gz" + rm "$app_dir/var/tmp/$currentDate-${env}_$name.sql" + + echo "$app_dir/backup/database/$currentDate-${env}_$name.sql.gz" +} \ No newline at end of file diff --git a/plugins/git/etc/config b/plugins/git/etc/config deleted file mode 100644 index 64c8f01..0000000 --- a/plugins/git/etc/config +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -### GIT - -# where is your project located in git -git_url='' - -# optionaly you can let empty and use https with password -git_ssh_user='' -git_ssh_domain='' -git_ssh_private_key='' -git_ssh_public_key='' \ No newline at end of file diff --git a/plugins/git/etc/config.json b/plugins/git/etc/config.json new file mode 100644 index 0000000..380b00f --- /dev/null +++ b/plugins/git/etc/config.json @@ -0,0 +1,9 @@ +{ + "git": { + "git_url": null, + "git_ssh_user": null, + "git_ssh_domain": null, + "git_ssh_private_key": null, + "git_ssh_public_key": null + } +} \ No newline at end of file diff --git a/plugins/plesk/etc/config b/plugins/plesk/etc/config deleted file mode 100644 index e317145..0000000 --- a/plugins/plesk/etc/config +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -plesk_host='' -plesk_user='' -plesk_private_key='' -plesk_public_key='' - -plesk_db_type='mysql' - -plesk_binary='plesk' \ No newline at end of file diff --git a/plugins/plesk/etc/config.json b/plugins/plesk/etc/config.json new file mode 100644 index 0000000..2933f34 --- /dev/null +++ b/plugins/plesk/etc/config.json @@ -0,0 +1,11 @@ +{ + "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" + } +} diff --git a/plugins/shopware5/etc/config b/plugins/shopware5/etc/config deleted file mode 100644 index 38fb994..0000000 --- a/plugins/shopware5/etc/config +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/bash - -### GENERAL - -shopware5_httpdocs_subpath='' - -shopware5_local_user='' -shopware5_local_email='' -shopware5_local_firstname='' -shopware5_local_lastname='' - -shopware5_install_name='' -shopware5_install_email='' -shopware5_install_locale='' -shopware5_install_currency='' -shopware5_install_storefront_name='' -shopware5_install_storefront_url='' - -### URL MAPPING - -shopware5_live_urls=() -shopware5_stage_urls=() -shopware5_local_urls=() - -### GDPR SHOPWARE 6 TABLES - -shopware5_gdpr_tables=( - s_user - s_user_addresses - s_user_addresses_attributes - s_user_attributes - s_user_billingaddress - s_user_billingaddress_attributes - s_user_shippingaddress - s_user_shippingaddress_attributes - s_customer_search_index - s_customer_streams - s_customer_streams_attributes - s_customer_streams_mapping - s_mail_log - s_mail_log_contact - s_mail_log_document - s_mail_log_recipient - s_order_attributes - s_order_basket - s_order_basket_attributes - s_order_billingaddress - s_order_billingaddress_attributes - s_order_comparisons - s_order_details - s_order_details_attributes - s_order_documents - s_order_documents_attributes - s_order_esd - s_order_history - s_order_notes - s_order_shippingaddress - s_order_shippingaddress_attributes -) - -### Media Files - -shopware5_shared_files=( - '/files' - '/media' -) - -### MAILER - -shopware5_local_mailer_url='' \ No newline at end of file diff --git a/plugins/shopware5/etc/config.json b/plugins/shopware5/etc/config.json new file mode 100644 index 0000000..511b69f --- /dev/null +++ b/plugins/shopware5/etc/config.json @@ -0,0 +1,56 @@ +{ + "shopware5": { + "shopware5_httpdocs_subpath": null, + "shopware5_local_user": null, + "shopware5_local_email": null, + "shopware5_local_firstname": null, + "shopware5_local_lastname": null, + "shopware5_install_name": null, + "shopware5_install_email": null, + "shopware5_install_locale": null, + "shopware5_install_currency": null, + "shopware5_install_storefront_name": null, + "shopware5_install_storefront_url": null, + "shopware5_live_urls": [], + "shopware5_stage_urls": [], + "shopware5_local_urls": [], + "shopware5_gdpr_tables": [ + "s_user", + "s_user_addresses", + "s_user_addresses_attributes", + "s_user_attributes", + "s_user_billingaddress", + "s_user_billingaddress_attributes", + "s_user_shippingaddress", + "s_user_shippingaddress_attributes", + "s_customer_search_index", + "s_customer_streams", + "s_customer_streams_attributes", + "s_customer_streams_mapping", + "s_mail_log", + "s_mail_log_contact", + "s_mail_log_document", + "s_mail_log_recipient", + "s_order_attributes", + "s_order_basket", + "s_order_basket_attributes", + "s_order_billingaddress", + "s_order_billingaddress_attributes", + "s_order_comparisons", + "s_order_details", + "s_order_details_attributes", + "s_order_documents", + "s_order_documents_attributes", + "s_order_esd", + "s_order_history", + "s_order_notes", + "s_order_shippingaddress", + "s_order_shippingaddress_attributes" + ], + "shopware5_shared_files": [ + "/files", + "/media" + ], + "shopware5_local_mailer_url": null + } +} diff --git a/plugins/shopware6/etc/config b/plugins/shopware6/etc/config deleted file mode 100644 index e22f439..0000000 --- a/plugins/shopware6/etc/config +++ /dev/null @@ -1,86 +0,0 @@ -#!/bin/bash - -### GENERAL - -shopware6_httpdocs_subpath='' - -shopware6_local_user='' -shopware6_local_email='' -shopware6_local_firstname='' -shopware6_local_lastname='' - -shopware6_install_name='' -shopware6_install_email='' -shopware6_install_locale='' -shopware6_install_currency='' -shopware6_install_storefront_name='' -shopware6_install_storefront_url='' - -### URL MAPPING - -shopware6_live_urls=() -shopware6_stage_urls=() -shopware6_local_urls=() - -### GDPR SHOPWARE 6 TABLES - -shopware6_gdpr_tables=( - acl_user_role - cart - customer - customer_address - customer_recovery - customer_tag - customer_wishlist - customer_wishlist_product - elasticsearch_index_task - import_export_log - integration - integration_role - log_entry - message_queue_stats - newsletter_recipient - newsletter_recipient_tag - order - order_address - order_customer - order_delivery - order_delivery_position - order_line_item - order_tag - order_transaction - product_export - product_review - promotion_persona_customer - refresh_token - sales_channel_api_context - state_machine_history - user - user_access_key - user_config - user_recovery - version - version_commit - version_commit_data - klarna_payment_request_log - payone_payment_card - payone_payment_mandate - payone_payment_redirect - unzer_payment_payment_device - unzer_payment_transfer_info - enqeueue - product_keyword_dictionary - product_search_keyword -) - -### Media Files - -shopware6_shared_files=( - '/files' - '/public/media' - '/public/thumbnails' -) - -### MAILER - -shopware6_local_mailer_url='' \ No newline at end of file diff --git a/plugins/shopware6/etc/config.json b/plugins/shopware6/etc/config.json new file mode 100644 index 0000000..446874d --- /dev/null +++ b/plugins/shopware6/etc/config.json @@ -0,0 +1,67 @@ +{ + "shopware6": { + "shopware6_httpdocs_subpath": null, + "shopware6_local_user": null, + "shopware6_local_email": null, + "shopware6_local_firstname": null, + "shopware6_local_lastname": null, + "shopware6_install_name": null, + "shopware6_install_email": null, + "shopware6_install_locale": null, + "shopware6_install_currency": null, + "shopware6_install_storefront_name": null, + "shopware6_install_storefront_url": null, + "shopware6_live_urls": [], + "shopware6_stage_urls": [], + "shopware6_local_urls": [], + "shopware6_gdpr_tables": [ + "acl_user_role", + "cart", + "customer", + "customer_address", + "customer_recovery", + "customer_tag", + "customer_wishlist", + "customer_wishlist_product", + "elasticsearch_index_task", + "import_export_log", + "integration", + "integration_role", + "log_entry", + "message_queue_stats", + "newsletter_recipient", + "newsletter_recipient_tag", + "order", + "order_address", + "order_customer", + "order_delivery", + "order_delivery_position", + "order_line_item", + "order_tag", + "order_transaction", + "product_export", + "product_review", + "promotion_persona_customer", + "refresh_token", + "sales_channel_api_context" + "state_machine_history", + "user", + "user_access_key", + "user_config", + "user_recovery", + "klarna_payment_request_log", + "payone_payment_card", + "payone_payment_mandate", + "payone_payment_redirect", + "enqeueue", + "product_keyword_dictionary", + "product_search_keyword" + ], + "shopware6_shared_files": [ + "/files", + "/public/media", + "/public/thumbnails" + ], + "shopware6_local_mailer_url": null + } +} diff --git a/plugins/ssh/commands/add-key b/plugins/ssh/bin/commands/add-key similarity index 100% rename from plugins/ssh/commands/add-key rename to plugins/ssh/bin/commands/add-key diff --git a/plugins/ssh/bin/includes/bash_header b/plugins/ssh/bin/includes/bash_header new file mode 100644 index 0000000..7211e35 --- /dev/null +++ b/plugins/ssh/bin/includes/bash_header @@ -0,0 +1,9 @@ +#!/bin/bash + +### DO NOT EDIT THIS FILE + +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 diff --git a/plugins/ssh/bin/includes/includes b/plugins/ssh/bin/includes/includes new file mode 100644 index 0000000..2608788 --- /dev/null +++ b/plugins/ssh/bin/includes/includes @@ -0,0 +1,5 @@ +#!/bin/bash + +### DO NOT EDIT THIS FILE + +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/ssh" diff --git a/plugins/ssh/includes/includes b/plugins/ssh/bin/includes/includes.sh similarity index 100% rename from plugins/ssh/includes/includes rename to plugins/ssh/bin/includes/includes.sh diff --git a/plugins/ssh/bin/includes/ssh b/plugins/ssh/bin/includes/ssh new file mode 100644 index 0000000..ff9543f --- /dev/null +++ b/plugins/ssh/bin/includes/ssh @@ -0,0 +1,108 @@ +#!/bin/bash + +### DO NOT EDIT THIS FILE + +if [ true != ${includes_ssh:-false} ] +then + includes_ssh=true + + function prepareSSHConnection { + local shortname="$(getArgument "$1" "shortname required" true)" + local env="$(getArgument "$2" "env required" true)" + local overwrite="$(getArgument "$3")" + + 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" + } + + function copyProjectKeys + { + 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 + } + + function installRemoteKey + { + 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" + } + + function addKey { + 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 + } + + 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 diff --git a/plugins/ssh/etc/config b/plugins/ssh/etc/config deleted file mode 100644 index 7877cd0..0000000 --- a/plugins/ssh/etc/config +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -### STAGE - -ssh_stage_user='' -ssh_stage_domain='' -ssh_stage_private_key='' -ssh_stage_public_key='' - -### LIVE - -ssh_live_user='' -ssh_live_domain='' -ssh_live_private_key='' -ssh_live_public_key='' diff --git a/plugins/ssh/etc/config.json b/plugins/ssh/etc/config.json new file mode 100644 index 0000000..240a366 --- /dev/null +++ b/plugins/ssh/etc/config.json @@ -0,0 +1,20 @@ +{ + "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 + } + } +} diff --git a/src/commands/create-project b/src/commands/create-project index 75954c6..b768c82 100644 --- a/src/commands/create-project +++ b/src/commands/create-project @@ -58,8 +58,11 @@ echo "Shortname: $shortname" echo confirm +cryptkey="$(randkey)" + setConfig false "project_manager.projects.$shortname.customer" "$customer" setConfig false "project_manager.projects.$shortname.project" "$project" +setConfig "$shortname" "project.cryptkey" "$cryptkey" runPostscripts "create-project" "$shortname" diff --git a/src/commands/install-plugin b/src/commands/install-plugin index 7c075d4..712ad88 100644 --- a/src/commands/install-plugin +++ b/src/commands/install-plugin @@ -16,8 +16,8 @@ function usage { source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header" -shortname=$(getArgument "$1" "$(usage)" true) -plugin=$(getArgument "$2" "$(usage)" true) +shortname=$(getArgument "$1" "shortname required" true) +plugin=$(getArgument "$2" "plugin required" true) customer=$(getConfig false "project_manager.projects.$shortname.customer") project=$(getConfig false "project_manager.projects.$shortname.project") project_dir="$project_manager_dir/data/$customer/$project" diff --git a/src/commands/install-project-manager b/src/commands/install-project-manager index 921769e..c68eb26 100644 --- a/src/commands/install-project-manager +++ b/src/commands/install-project-manager @@ -23,11 +23,12 @@ echo echoSubTitle "Please configure Sumedia Project Manager" echo +cryptkey="$(randkey)" workspaces_dir="$(readConsole "Workspaces dir" "Invalid selection" true "$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." &> /dev/null && pwd)")" apache_httpdocs="$(readConsole "Local Apache httpdocs dir (optional)")" -config_source="$project_manager/etc/template/project_manager.json" -config_target="$project_manager/etc/config.json" +config_source="$project_manager_dir/etc/template/project_manager.json" +config_target="$project_manager_dir/etc/config.json" if [ ! -d "$(dirname "$config_target")" ] then @@ -36,11 +37,12 @@ fi if [ ! -f "$config_target" ] then - cp "$source" "$target" + cp "$config_source" "$config_target" fi setConfig false "project_manager.workspaces_dir" "$workspaces_dir" setConfig false "project_manager.apache_httpdocs" "$apache_httpdocs" +setConfig false "project_manager.cryptkey" "$cryptkey" runPostscripts "install-project-manager" diff --git a/src/includes/config.php b/src/includes/config.php index 14f9b04..59196d6 100755 --- a/src/includes/config.php +++ b/src/includes/config.php @@ -2,7 +2,7 @@ ### DO NOT EDIT THIS FILE -global $project_manager_dir, $shortname, $configPath, $configuration; +global $project_manager_dir, $shortname, $configPath, $configuration, $value; $configuration = []; $project_manager_dir = dirname(dirname(__DIR__)); $command = $_SERVER['argv'][1]; diff --git a/src/includes/json b/src/includes/json new file mode 100644 index 0000000..1662d63 --- /dev/null +++ b/src/includes/json @@ -0,0 +1,35 @@ +#!/bin/bash + +### DO NOT EDIT THIS FILE + +function usage { + echo + echoMainTitle "Sumedia Project Manager Json Container Helper" + echo + echoSubTitle "Usage:" + echo + echo "json get [container] [configPath]" + echo "json has [container] [configPath]" + echo + echo "This methods return complete container as string:" + echo "json set [container] [configPath] [value]" + echo "json remove [container] [configPath]" + echo + echo "--help Prints this message" + echo " " + exit +} + +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/bash_header" + +command="$(getArgument "$1" "Invalid command given" "get set has remove")" +container="$(getArgument "$2" "Invalid command given" "get set has remove")" +configPath="$(getArgument "$3")" +if [ "$command" == "set" ] +then + value="$(getArgument "$4" "Parameter value not given" true)" +fi + +PHP=`which php` +script="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/json.php" +$PHP "$script" "$@" \ No newline at end of file diff --git a/src/includes/json.php b/src/includes/json.php new file mode 100755 index 0000000..245c29b --- /dev/null +++ b/src/includes/json.php @@ -0,0 +1,78 @@ +&2 - echoError "$errmsg" >&2 - usage >&2 - exit_program + usageError "$errmsg" fi echo "$var" } + function usageError { + error="$(getArgument "$1")" + echo >&2 + echoError "$error" >&2 + usage >&2 + exit_program + } + function isAllowed { local var="$1" local allow="$2" @@ -108,7 +113,7 @@ then function readConsole { local message="$1" - local errmsg="$2" + local errmsg=${2:-"Invalid"} local allow=${3:-false} local default="${4:-null}" @@ -155,14 +160,6 @@ then fi } - function usageError { - error="$(getArgument "$1")" - echo - echoError "$error" - usage - exit - } - function postScript { local script=$(getArgument "$1") if [ -f "$script" ] @@ -189,13 +186,55 @@ then fi } + function getCryptKey + { + local shortname="$(getArgument "$1" "shortname required" true)" + if [ "$shortname" != false] + then + echo "$(getConfig "$shortname" "project_manager.cryptkey")" + else + echo "$(getConfig "$shortname" "project_manager.projects.$shortname.cryptkey")" + fi + } + + function getCryptedConfig + { + local shortname="$(getArgument "$1" "shortname required" true)" + local configPath="$(getArgument "$2" "configPath required" true)" + local cryptkey="$(getCryptKey "$shortname")" + + if [ "$(hasConfig "$shortname" "$configPath")" == null ] + then + readCryptedConfig "$shortname" "$configPath" + fi + + echo "$(decrypt "$(getConfig "$shortname" "$configPath")" "$cryptkey")" + } + function getConfig { local shortname="$(getArgument "$1" "shortname required" true)" local configPath="$(getArgument "$2" "configPath required" true)" + + if [ "$(hasConfig "$shortname" "$configPath")" == null ] + then + readConfig "$shortname" "$configPath" + fi + local configScript="$project_manager_dir/src/includes/config" echo "$(source "$configScript" get "$shortname" "$configPath")" } + function setCryptedConfig + { + local shortname="$(getArgument "$1" "shortname required" true)" + local configPath="$(getArgument "$2" "configPath required" true)" + local value="$(getArgument "$3" "value required" true)" + local cryptkey="$(getCryptKey "$shortname")" + + local configScript="$project_manager_dir/src/includes/config" + source "$configScript" set "$shortname" "$configPath" "$(encrypt "$value" "$cryptkey")" + } + function setConfig { local shortname="$(getArgument "$1" "shortname required" true)" local configPath="$(getArgument "$2" "configPath required" true)" @@ -219,4 +258,85 @@ then echo "$(source "$configScript" has "$shortname" "$configPath")" } + function readyCryptedConfig + { + local shortname="$(getArgument "$1" "shortname required" true)" + local configPath="$(getArgument "$2" "configPath required" true)" + local cryptkey="$(getCryptKey "$shortname")" + local value="$(encrypt "$(readConsole "Input config for: $configPath:")" "$cryptkey")" + setConfig "$shortname" "$configPath" "$value" + } + + function readConfig { + local shortname="$(getArgument "$1" "shortname required" true)" + local configPath="$(getArgument "$2" "configPath required" true)" + local value="$(readConsole "Input config for: $configPath:")" + setConfig "$shortname" "$configPath" "$value" + } + + function encrypt + { + 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" + } + + 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" + } + + function randkey + { + echo "$(openssl rand -base64 32)" + } + + function rmEmptyDir { + local path="$(getArgument "$1" "path required" true)" + local length="$(getArgument "$2" "length required" true)" + + if [ "$length" > 0 ] + then + if [ "$(ls -A $path)" == "" ] + then + rmdir "$path"; + rmEmptyDir "$(dirname "$path")" $length-1 + fi + fi + } + + function jsonSet { + local container="$(getArgument "$1" "container required" true)" + local configPath="$(getArgument "$2" "configPath required" true)" + local value="$(getArgument "$3" "value required" true)" + + local configScript="$project_manager_dir/src/includes/json" + echo "$(source "$configScript" set "$container" "$configPath" "$value")" + } + + function jsonRemove { + local container="$(getArgument "$1" "container required" true)" + local configPath="$(getArgument "$2" "configPath required" true)" + + local configScript="$project_manager_dir/src/includes/json" + echo "$(source "$configScript" remove "$container" "$configPath")" + } + + function jsonGet { + local container="$(getArgument "$1" "container required" true)" + local configPath="$(getArgument "$2" "configPath required" true)" + + local configScript="$project_manager_dir/src/includes/json" + echo "$(source "$configScript" get "$container" "$configPath")" + } + + function jsonHas { + local container="$(getArgument "$1" "container required" true)" + local configPath="$(getArgument "$2" "configPath required" true)" + + local configScript="$project_manager_dir/src/includes/json" + echo "$(source "$configScript" has "$container" "$configPath")" + } fi \ No newline at end of file diff --git a/src/includes/project_manager b/src/includes/project_manager index e6e5b5e..545fb35 100644 --- a/src/includes/project_manager +++ b/src/includes/project_manager @@ -25,4 +25,19 @@ then cp "$source_config_file" "$target_config_source_config_file" fi } + + function isPluginEnabled { + local shortname="$(getArgument "$1")" + local customer="$(getConfig false "project_manager.projects.$shortname.customer")" + local project="$(getConfig false "project_manager.projects.$shortname.project")" + local plugin="$(getArgument "$2")" + local plugin_enabled_dir="$project_manager_dir/data/$customer/$project/etc/$plugin" + + if [ -d "$plugin_enabled_dir" ] + then + echo true + else + echo false + fi + } fi \ No newline at end of file diff --git a/var/.keep b/var/.keep new file mode 100644 index 0000000..e69de29 diff --git a/var/tmp/.keep b/var/tmp/.keep new file mode 100644 index 0000000..e69de29