From 26945657da6a532216f928d17bc80f089ce37560 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 13 Dec 2024 18:13:00 +0100 Subject: [PATCH] user command --- httpdocs/.gitignore | 2 +- httpdocs/1deployImaq.sh | 184 ++++++++++++++++++ httpdocs/public/.htaccess | 87 +++++++++ httpdocs/public/.htpasswd | 1 + .../src/Command/Import/CreateUserCommand.php | 73 +++++++ 5 files changed, 346 insertions(+), 1 deletion(-) create mode 100644 httpdocs/1deployImaq.sh create mode 100644 httpdocs/public/.htaccess create mode 100644 httpdocs/public/.htpasswd create mode 100644 httpdocs/src/Command/Import/CreateUserCommand.php diff --git a/httpdocs/.gitignore b/httpdocs/.gitignore index 94a2aab..e40b801 100644 --- a/httpdocs/.gitignore +++ b/httpdocs/.gitignore @@ -10,5 +10,5 @@ ###< symfony/framework-bundle ### ###> lexik/jwt-authentication-bundle ### -/config/jwt/*.pem +/jwt/*.pem ###< lexik/jwt-authentication-bundle ### diff --git a/httpdocs/1deployImaq.sh b/httpdocs/1deployImaq.sh new file mode 100644 index 0000000..bad9ad9 --- /dev/null +++ b/httpdocs/1deployImaq.sh @@ -0,0 +1,184 @@ +#!/bin/bash + +# Default-Werte für Parameter +SKIP_CLIENT=false +SKIP_MIGRATION=false +INIT_MODE=false + +# Projekt-Name +PROJECT_NAME="Imaq" + +# Konfigurierbare Pfade +BASE_DIR="/var/www/vhosts/app-imaq-pilot.de" +GIT_REPO_PATH="${BASE_DIR}/git_repo/imaq" +ANGULAR_PATH="${BASE_DIR}/angular" +HTTPDOCS_PATH="${BASE_DIR}/httpdocs" +PUBLIC_PATH="${HTTPDOCS_PATH}/public" +CLIENT_PATH="${PUBLIC_PATH}/client" +PHP_PATH="/opt/plesk/php/8.3/bin" +ANGULAR_ENVIRONMENT="production" + +# Funktion zum Überprüfen der Pfade +check_paths() { + local error=false + + # Prüfe ob alle erforderlichen Pfade existieren + if [ ! -d "$GIT_REPO_PATH" ]; then + echo "$(tput setab 1)ERROR: Git repository path does not exist: ${GIT_REPO_PATH}$(tput sgr 0)" + error=true + fi + + if [ ! -d "$BASE_DIR" ]; then + echo "$(tput setab 1)ERROR: Base directory does not exist: ${BASE_DIR}$(tput sgr 0)" + error=true + fi + + # Im Init-Mode müssen nicht alle Verzeichnisse existieren + if [ "$INIT_MODE" = false ]; then + if [ ! -d "$ANGULAR_PATH" ]; then + echo "$(tput setab 1)ERROR: Angular path does not exist: ${ANGULAR_PATH}$(tput sgr 0)" + error=true + fi + + if [ ! -d "$HTTPDOCS_PATH" ]; then + echo "$(tput setab 1)ERROR: Httpdocs path does not exist: ${HTTPDOCS_PATH}$(tput sgr 0)" + error=true + fi + + if [ ! -d "$PUBLIC_PATH" ]; then + echo "$(tput setab 1)ERROR: Public path does not exist: ${PUBLIC_PATH}$(tput sgr 0)" + error=true + fi + fi + + # Prüfe ob PHP im angegebenen Pfad existiert + if [ ! -d "$PHP_PATH" ]; then + echo "$(tput setab 1)ERROR: PHP path does not exist: ${PHP_PATH}$(tput sgr 0)" + error=true + fi + + # Wenn Fehler gefunden wurden, beende das Skript + if [ "$error" = true ]; then + echo "$(tput setab 1)Critical errors found. Please check your path configuration at the top of the script.$(tput sgr 0)" + exit 1 + fi +} + +# Parameter verarbeiten +while getopts ":cmi" opt; do + case $opt in + c) SKIP_CLIENT=true ;; + m) SKIP_MIGRATION=true ;; + i) INIT_MODE=true ;; + \?) echo "Unknown option: -$OPTARG" >&2; exit 1 ;; + esac +done + +# Pfade überprüfen bevor irgendwelche Operationen durchgeführt werden +check_paths + +export PATH=${PHP_PATH}:$PATH + +# Git Pull durchführen +cd "${GIT_REPO_PATH}" || { echo "$(tput setab 1)Failed to change to repository directory$(tput sgr 0)"; exit 1; } +sudo git pull +echo "$(tput setab 2)${PROJECT_NAME} has been PULLED$(tput sgr 0)" + +# Client Update nur wenn nicht übersprungen +if [ "$SKIP_CLIENT" = false ]; then + echo "$(tput setab 2)Client update$(tput sgr 0)" + + # Im Init-Mode keine Dateien löschen + if [ "$INIT_MODE" = false ]; then + echo "$(tput setab 2)delete angular files$(tput sgr 0)" + cd "${ANGULAR_PATH}" || { echo "$(tput setab 1)Failed to change to angular directory$(tput sgr 0)"; exit 1; } + find . -maxdepth 1 ! -name 'node_modules' ! -name '.' -exec rm -rf {} + + fi + + # Kopiere normale Dateien + cp -r "${GIT_REPO_PATH}/angular/"* "${ANGULAR_PATH}" 2>/dev/null || true + + # Kopiere versteckte Dateien nur wenn sie existieren + HIDDEN_FILES=$(find "${GIT_REPO_PATH}/angular" -maxdepth 1 -name ".*" -not -name "." -not -name "..") + if [ ! -z "$HIDDEN_FILES" ]; then + cp -r ${HIDDEN_FILES} "${ANGULAR_PATH}" + fi + + cd "${ANGULAR_PATH}" || { echo "$(tput setab 1)Failed to change to angular directory$(tput sgr 0)"; exit 1; } + npm install + npx ng analytics off + npx ng build --configuration ${ANGULAR_ENVIRONMENT} + + if [ -d "${CLIENT_PATH}/browser" ]; then + mv "${CLIENT_PATH}/browser/"* "${CLIENT_PATH}/" + rm -rf "${CLIENT_PATH}/browser" + fi + echo "$(tput setab 2)Client files have been updated$(tput sgr 0)" +else + echo "$(tput setab 3)Skip client update$(tput sgr 0)" +fi + +# Arrays mit Dateien und Verzeichnissen die kopiert werden sollen +COPY_ITEMS="composer.lock composer.json config migrations src templates" +PUBLIC_FILES="index.php .htaccess .htpasswd" + +# Dateien und Verzeichnisse kopieren +for item in $COPY_ITEMS; do + if [ -e "${GIT_REPO_PATH}/httpdocs/${item}" ]; then + # Im Init-Mode keine Dateien löschen + if [ "$INIT_MODE" = false ]; then + rm -rf "${HTTPDOCS_PATH}/${item}" + fi + cp -rf "${GIT_REPO_PATH}/httpdocs/${item}" "${HTTPDOCS_PATH}" + else + echo "$(tput setab 3)Warning: Source item does not exist: ${GIT_REPO_PATH}/httpdocs/${item}$(tput sgr 0)" + fi +done + +# Spezielle Dateien im public Verzeichnis kopieren +for file in $PUBLIC_FILES; do + if [ -e "${GIT_REPO_PATH}/httpdocs/public/${file}" ]; then + # Im Init-Mode keine Dateien löschen + if [ "$INIT_MODE" = false ]; then + rm -rf "${PUBLIC_PATH}/${file}" + fi + cp -rf "${GIT_REPO_PATH}/httpdocs/public/${file}" "${PUBLIC_PATH}" + else + echo "$(tput setab 3)Warning: Source file does not exist: ${GIT_REPO_PATH}/httpdocs/public/${file}$(tput sgr 0)" + fi +done + +echo "$(tput setab 2)Files have been copied$(tput sgr 0)" + +cd "${HTTPDOCS_PATH}" || { echo "$(tput setab 1)Failed to change to httpdocs directory$(tput sgr 0)"; exit 1; } +export COMPOSER_ALLOW_SUPERUSER=1 +composer update --no-interaction + +echo "$(tput setab 2)COMPOSER UPDATED updated$(tput sgr 0)" + +# Migration nur wenn nicht übersprungen +if [ "$SKIP_MIGRATION" = false ]; then + php "${HTTPDOCS_PATH}/bin/console" doctrine:migration:migrate --no-interaction + echo "$(tput setab 2)DATABASE SCHEMA updated$(tput sgr 0)" +else + echo "$(tput setab 3)Skip migrations$(tput sgr 0)" +fi + +# Cache leeren +if [ -d "${HTTPDOCS_PATH}/var/cache" ]; then + cd "${HTTPDOCS_PATH}/var/cache/" || { echo "$(tput setab 1)Failed to change to cache directory$(tput sgr 0)"; exit 1; } + rm -R * + + php "${HTTPDOCS_PATH}/bin/console" cache:clear + php "${HTTPDOCS_PATH}/bin/console" cache:warmup + + echo "$(tput setab 2)CACHE HAS BEEN CLEARED$(tput sgr 0)" +else + echo "$(tput setab 3)Warning: Cache directory does not exist$(tput sgr 0)" +fi + +cd "${HTTPDOCS_PATH}" || { echo "$(tput setab 1)Failed to change to httpdocs directory$(tput sgr 0)"; exit 1; } +chmod 777 -R var/ + +echo "$(tput setab 7)$(tput setaf 1)THINK ABOUT POSSIBLE PATCHES!" +echo "You have updated ${PROJECT_NAME}!$(tput sgr 0)" \ No newline at end of file diff --git a/httpdocs/public/.htaccess b/httpdocs/public/.htaccess new file mode 100644 index 0000000..a5ee474 --- /dev/null +++ b/httpdocs/public/.htaccess @@ -0,0 +1,87 @@ +# Enable rewrite engine +RewriteEngine On + +# Set a rewrite condition for non-API requests +RewriteCond %{REQUEST_URI} !^/api/ [NC] +RewriteRule .* - [E=NEED_AUTH:1] + +# Basic Authentication +AuthType Basic +AuthName "Passwortgeschützter Bereich" +AuthUserFile /var/www/vhosts/futbase.digital/httpdocs/public/.htpasswd +Require valid-user + +# Skip auth for API routes +Satisfy any +Order Allow,Deny +Allow from all +Deny from env=NEED_AUTH + +# Use the front controller as index file. It serves as a fallback solution when +# every other rewrite/redirect fails (e.g. in an aliased environment without +# mod_rewrite). Additionally, this reduces the matching process for the +# start page (path "/") because otherwise Apache will apply the rewriting rules +# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl). +DirectoryIndex index.php + +# By default, Apache does not evaluate symbolic links if you did not enable this +# feature in your server configuration. Uncomment the following line if you +# install assets as symlinks or if you experience problems related to symlinks +# when compiling LESS/Sass/CoffeScript assets. +# Options FollowSymlinks + +# Disabling MultiViews prevents unwanted negotiation, e.g. "/index" should not resolve +# to the front controller "/index.php" but be rewritten to "/index.php/index". + + Options -MultiViews + + + + RewriteEngine On + + # Determine the RewriteBase automatically and set it as environment variable. + # If you are using Apache aliases to do mass virtual hosting or installed the + # project in a subdirectory, the base path will be prepended to allow proper + # resolution of the index.php file and to redirect to the correct URI. It will + # work in environments without path prefix as well, providing a safe, one-size + # fits all solution. But as you do not need it in this case, you can comment + # the following 2 lines to eliminate the overhead. + RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ + RewriteRule ^(.*) - [E=BASE:%1] + + # Sets the HTTP_AUTHORIZATION header removed by Apache + RewriteCond %{HTTP:Authorization} . + RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + + # Redirect to URI without front controller to prevent duplicate content + # (with and without `/index.php`). Only do this redirect on the initial + # rewrite by Apache and not on subsequent cycles. Otherwise we would get an + # endless redirect loop (request -> rewrite to front controller -> + # redirect -> request -> ...). + # So in case you get a "too many redirects" error or you always get redirected + # to the start page because your Apache does not expose the REDIRECT_STATUS + # environment variable, you have 2 choices: + # - disable this feature by commenting the following 2 lines or + # - use Apache >= 2.3.9 and replace all L flags by END flags and remove the + # following RewriteCond (best solution) + RewriteCond %{ENV:REDIRECT_STATUS} ^$ + RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L] + + # If the requested filename exists, simply serve it. + # We only want to let Apache serve files and not directories. + RewriteCond %{REQUEST_FILENAME} -f + RewriteRule ^ - [L] + + # Rewrite all other queries to the front controller. + RewriteRule ^ %{ENV:BASE}/index.php [L] + + + + + # When mod_rewrite is not available, we instruct a temporary redirect of + # the start page to the front controller explicitly so that the website + # and the generated links can still be used. + RedirectMatch 307 ^/$ /index.php/ + # RedirectTemp cannot be used instead + + diff --git a/httpdocs/public/.htpasswd b/httpdocs/public/.htpasswd new file mode 100644 index 0000000..accd9b3 --- /dev/null +++ b/httpdocs/public/.htpasswd @@ -0,0 +1 @@ +futcoinbase2023:$apr1$ko0m8f57$mf3gQsnDcHdpQU7OCuL6E0 \ No newline at end of file diff --git a/httpdocs/src/Command/Import/CreateUserCommand.php b/httpdocs/src/Command/Import/CreateUserCommand.php new file mode 100644 index 0000000..6b769d9 --- /dev/null +++ b/httpdocs/src/Command/Import/CreateUserCommand.php @@ -0,0 +1,73 @@ + 'jakob@spawntree.de', + 'firstName' => 'Jakob', + 'lastName' => 'Nordstrøm', + 'password' => '12spawntree345', + 'roles' => ['ROLE_ADMIN'] + ] + ); + $system->_set('image', MediaObjectFactory::createOne()->_real()); + $system->_save(); + + $adminD = UserFactory::createOne( + [ + 'email' => 'd.knudsen@spawntree.de', + 'firstName' => 'Daniel', + 'lastName' => 'Knudsen', + 'password' => '12spawntree345', + 'roles' => ['ROLE_ADMIN'] + ] + ); + $system->_set('image', MediaObjectFactory::createOne()->_real()); + $adminD->_save(); + + UserFactory::createOne( + [ + 'email' => 'f.eisenmenger@spawntree.de', + 'firstName' => 'Florian', + 'lastName' => 'Eisenmenger', + 'password' => '12spawntree345', + 'image' => MediaObjectFactory::createOne(), + 'roles' => ['ROLE_ADMIN'] + ] + ); + $system->_set('image', MediaObjectFactory::createOne()->_real()); + $adminD->_save(); + + + return Command::SUCCESS; + } +} \ No newline at end of file