From 7ec58246d998794ea0b78db7c8f5194acc627600 Mon Sep 17 00:00:00 2001 From: Yunohost-Bot <> Date: Sat, 31 Aug 2024 01:03:24 +0200 Subject: [PATCH] [autopatch] Automatic patch attempt for helpers 2.1 --- .gitignore | 1 + conf/extra_php-fpm.conf | 4 - conf/nginx.conf | 2 +- manifest.toml | 4 +- scripts/_common.sh | 14 +- scripts/backup | 25 +- scripts/change_url | 14 +- scripts/config | 102 ------ scripts/install | 25 +- scripts/remove | 16 +- scripts/restore | 39 +-- scripts/upgrade | 40 +-- sources/patches/how-to-generate-patch.md | 6 - sources/patches/main-replace_data_dir.patch | 335 -------------------- 14 files changed, 59 insertions(+), 568 deletions(-) delete mode 100644 conf/extra_php-fpm.conf delete mode 100644 scripts/config delete mode 100644 sources/patches/how-to-generate-patch.md delete mode 100644 sources/patches/main-replace_data_dir.patch diff --git a/.gitignore b/.gitignore index 783a4ae..8f144f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *~ *.sw[op] +.DS_Store diff --git a/conf/extra_php-fpm.conf b/conf/extra_php-fpm.conf deleted file mode 100644 index 700c37c..0000000 --- a/conf/extra_php-fpm.conf +++ /dev/null @@ -1,4 +0,0 @@ -; Additional php.ini defines, specific to this pool of workers. - -php_admin_value[upload_max_filesize] = 50M -php_admin_value[post_max_size] = 50M diff --git a/conf/nginx.conf b/conf/nginx.conf index 6f4a542..e38d116 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -12,7 +12,7 @@ location __PATH__/ { try_files $uri $uri/ index.php; location ~ [^/]\.php(/|$) { fastcgi_split_path_info ^(.+?\.php)(/.*)$; - fastcgi_pass unix:/var/run/php/php__PHPVERSION__-fpm-__NAME__.sock; + fastcgi_pass unix:/var/run/php/php__PHP_VERSION__-fpm-__APP__.sock; fastcgi_index index.php; include fastcgi_params; diff --git a/manifest.toml b/manifest.toml index 61351c7..d6ac488 100644 --- a/manifest.toml +++ b/manifest.toml @@ -15,7 +15,8 @@ website = "https://lxdware.com" code = "https://github.com/lxdware/lxd-dashboard" [integration] -yunohost = ">= 11.2" +yunohost = ">= 11.2.18" +helpers_version = "2.1" architectures = "all" multi_instance = true @@ -54,6 +55,7 @@ ram.runtime = "50M" [resources.system_user] [resources.install_dir] + group = "www-data:r-x" [resources.data_dir] subdirs = ["backups", "data/lxd"] diff --git a/scripts/_common.sh b/scripts/_common.sh index 944a65e..3d7f008 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,17 +1,5 @@ #!/bin/bash #================================================= -# COMMON VARIABLES -#================================================= - -#================================================= -# PERSONAL HELPERS -#================================================= - -#================================================= -# EXPERIMENTAL HELPERS -#================================================= - -#================================================= -# FUTURE OFFICIAL HELPERS +# COMMON VARIABLES AND CUSTOM HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index 1eb5941..ca218e9 100755 --- a/scripts/backup +++ b/scripts/backup @@ -1,55 +1,46 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# DECLARE DATA AND CONF FILES TO BACKUP -#================================================= -ynh_print_info --message="Declaring files to be backed up..." +ynh_print_info "Declaring files to be backed up..." #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$install_dir" +ynh_backup "$install_dir" #================================================= # BACKUP THE DATA DIR #================================================= -ynh_backup --src_path="$data_dir" +ynh_backup "$data_dir" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP THE PHP-FPM CONFIGURATION #================================================= -ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" +ynh_backup "/etc/php/$php_version/fpm/pool.d/$app.conf" #================================================= # SPECIFIC BACKUP #================================================= # BACKUP THE MYSQL DATABASE #================================================= -ynh_print_info --message="Backing up the MySQL database..." +ynh_print_info "Backing up the MySQL database..." -ynh_mysql_dump_db --database="$db_name" > db.sql +ynh_mysql_dump_db > db.sql #================================================= # END OF SCRIPT #================================================= -ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/change_url b/scripts/change_url index 690b1ba..39d37fc 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -1,25 +1,17 @@ #!/bin/bash -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers -#================================================= -# STANDARD MODIFICATIONS #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating NGINX web server configuration..." +ynh_script_progression "Updating NGINX web server configuration..." -ynh_change_url_nginx_config +ynh_config_change_url_nginx #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" +ynh_script_progression "Change of URL completed for $app" diff --git a/scripts/config b/scripts/config deleted file mode 100644 index b9e79f8..0000000 --- a/scripts/config +++ /dev/null @@ -1,102 +0,0 @@ -#!/bin/bash -# In simple cases, you don't need a config script. - -# With a simple config_panel.toml, you can write in the app settings, in the -# upstream config file or replace complete files (logo ...) and restart services. - -# The config scripts allows you to go further, to handle specific cases -# (validation of several interdependent fields, specific getter/setter for a value, -# display dynamic informations or choices, pre-loading of config type .cube... ). - -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -source /usr/share/yunohost/helpers - -ynh_abort_if_errors - -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -final_path=$(ynh_app_setting_get $app final_path) - -#================================================= -# SPECIFIC GETTERS FOR TOML SHORT KEY -#================================================= - -get__amount() { - # Here we can imagine to have an API call to stripe to know the amount of donation during a month - local amount = 200 - - # It's possible to change some properties of the question by overriding it: - if [ $amount -gt 100 ] - then - cat << EOF -style: success -value: $amount -ask: - en: A lot of donation this month: **$amount €** -EOF - else - cat << EOF -style: danger -value: $amount -ask: - en: Not so much donation this month: $amount € -EOF - fi -} - -get__prices() { - local prices = "$(grep "DONATION\['" "$final_path/settings.py" | sed -r "s@^DONATION\['([^']*)'\]\['([^']*)'\] = '([^']*)'@\1/\2/\3@g" | sed -z 's/\n/,/g;s/,$/\n/')" - if [ "$prices" == "," ]; - then - # Return YNH_NULL if you prefer to not return a value at all. - echo YNH_NULL - else - echo $prices - fi -} - - -#================================================= -# SPECIFIC VALIDATORS FOR TOML SHORT KEYS -#================================================= -validate__publishable_key() { - - # We can imagine here we test if the key is really a publisheable key - (is_secret_key $publishable_key) && - echo 'This key seems to be a secret key' -} - -#================================================= -# SPECIFIC SETTERS FOR TOML SHORT KEYS -#================================================= -set__prices() { - - #--------------------------------------------- - # IMPORTANT: setter are trigger only if a change is detected - #--------------------------------------------- - for price in $(echo $prices | sed "s/,/ /"); do - frequency=$(echo $price | cut -d/ -f1) - currency=$(echo $price | cut -d/ -f2) - price_id=$(echo $price | cut -d/ -f3) - sed "d/DONATION\['$frequency'\]\['$currency'\]" "$final_path/settings.py" - - echo "DONATION['$frequency']['$currency'] = '$price_id'" >> "$final_path/settings.py" - done - - #--------------------------------------------- - # IMPORTANT: to be able to upgrade properly, you have to saved the value in settings too - #--------------------------------------------- - ynh_app_setting_set $app prices $prices -} - -#================================================= -# GENERIC FINALIZATION -#================================================= -ynh_app_config_run $1 diff --git a/scripts/install b/scripts/install index 7fcacc6..8e5f7b8 100755 --- a/scripts/install +++ b/scripts/install @@ -1,43 +1,36 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." +ynh_script_progression "Setting up source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir" -chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" - +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "$install_dir" #================================================= # PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Configuring PHP-FPM..." +ynh_script_progression "Configuring PHP-FPM..." # Create a dedicated PHP-FPM config -ynh_add_fpm_config +ynh_config_add_phpfpm # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx #================================================= # SETUP APPLICATION WITH CURL #================================================= -ynh_script_progression --message="Setuping application with CURL..." +ynh_script_progression "Setuping application with CURL..." # Installation with curl -ynh_script_progression --message="Finalizing installation..." +ynh_script_progression "Finalizing installation..." ynh_local_curl "/backend/config/login.php?database_type=mysql&database_host=localhost&database_name=$db_name&database_user=$db_user&action=writeDatabaseConfig" "database_password=$db_pwd" ynh_local_curl "/backend/admin/settings.php?action=createUser" "username=$admin" "password=$password" ynh_local_curl "/backend/admin/settings.php?action=createUser" "email=$(ynh_user_get_info --username=$admin --key=mail)" "first_name=$(ynh_user_get_info --username=$admin --key=firstname)" "last_name=$(ynh_user_get_info --username=$admin --key=lastname)" "password=$password" "username=$admin" @@ -49,4 +42,4 @@ chown -R $app: "$data_dir" # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" +ynh_script_progression "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index af5f63a..19e0623 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,29 +1,23 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." +ynh_script_progression "Removing NGINX web server configuration..." # Remove the dedicated NGINX config -ynh_remove_nginx_config +ynh_config_remove_nginx # Remove the dedicated PHP-FPM config -ynh_remove_fpm_config +ynh_config_remove_phpfpm -ynh_secure_remove --file="$data_dir" +ynh_safe_rm "$data_dir" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" +ynh_script_progression "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 2460e2d..27eb9df 100755 --- a/scripts/restore +++ b/scripts/restore @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -13,19 +7,18 @@ source /usr/share/yunohost/helpers #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." +ynh_script_progression "Restoring the app main directory..." -ynh_restore_file --origin_path="$install_dir" - -chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" +ynh_restore "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "$install_dir" #================================================= # RESTORE THE DATA DIRECTORY #================================================= -ynh_script_progression --message="Restoring the data directory..." +ynh_script_progression "Restoring the data directory..." -ynh_restore_file --origin_path="$data_dir" +ynh_restore "$data_dir" chmod -R o-rwx "$data_dir" chown -R $app: "$data_dir" @@ -33,31 +26,29 @@ chown -R $app: "$data_dir" #================================================= # RESTORE THE MYSQL DATABASE #================================================= -ynh_script_progression --message="Restoring the MySQL database..." +ynh_script_progression "Restoring the MySQL database..." -ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql +ynh_mysql_db_shell < ./db.sql #================================================= # RESTORE THE PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Restoring the PHP-FPM configuration..." +ynh_script_progression "Restoring the PHP-FPM configuration..." -ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" +ynh_restore "/etc/php/$php_version/fpm/pool.d/$app.conf" -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# GENERIC FINALIZATION #================================================= # RELOAD NGINX AND PHP-FPM #================================================= -ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." +ynh_script_progression "Reloading NGINX web server and PHP-FPM..." -ynh_systemd_action --service_name=php$phpversion-fpm --action=reload -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemctl --service=php$php_version-fpm --action=reload +ynh_systemctl --service=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" +ynh_script_progression "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index 68d05e1..48da2ae 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,57 +1,43 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers -#================================================= -# CHECK VERSION -#================================================= - -upgrade_type=$(ynh_check_app_version_changed) - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -if [ "$upgrade_type" == "UPGRADE_APP" ] +# FIXME: this is still supported but the recommendation is now to *always* re-setup the app sources wether or not the upstream sources changed +if ynh_app_upstream_version_changed then - ynh_script_progression --message="Upgrading source files..." + ynh_script_progression "Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir" fi -chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" - +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "$install_dir" #================================================= # PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading PHP-FPM configuration..." +ynh_script_progression "Upgrading PHP-FPM configuration..." # Create a dedicated PHP-FPM config -ynh_add_fpm_config +ynh_config_add_phpfpm # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx -#================================================= -# SPECIFIC UPGRADE #================================================= # UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Updating a configuration file..." +ynh_script_progression "Updating configuration..." -ynh_add_config --template="db_config.php" --destination="$data_dir/data/db_config.php" +ynh_config_add --template="db_config.php" --destination="$data_dir/data/db_config.php" -chmod 400 "$data_dir/data/db_config.php" -chown $app:$app "$data_dir/data/db_config.php" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$data_dir/data/db_config.php" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$data_dir/data/db_config.php" chmod -R o-rwx "$data_dir" chown -R $app: "$data_dir" @@ -60,4 +46,4 @@ chown -R $app: "$data_dir" # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" +ynh_script_progression "Upgrade of $app completed" diff --git a/sources/patches/how-to-generate-patch.md b/sources/patches/how-to-generate-patch.md deleted file mode 100644 index 9c9f673..0000000 --- a/sources/patches/how-to-generate-patch.md +++ /dev/null @@ -1,6 +0,0 @@ - -- download and extract sources, navigate to the dir then: -- `git init` -- `git add *` -- `find ./ \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i 's/\/var\/lxdware/\/home\/yunohost.app\/lxd-dashboard/g'` -- `git diff > main-replace_data_dir.patch` \ No newline at end of file diff --git a/sources/patches/main-replace_data_dir.patch b/sources/patches/main-replace_data_dir.patch deleted file mode 100644 index f1475ea..0000000 --- a/sources/patches/main-replace_data_dir.patch +++ /dev/null @@ -1,335 +0,0 @@ -diff --git a/lxd-dashboard/backend/config/about.php b/lxd-dashboard/backend/config/about.php -index 268ac7b..6476c11 100644 ---- a/lxd-dashboard/backend/config/about.php -+++ b/lxd-dashboard/backend/config/about.php -@@ -26,7 +26,7 @@ if (!isset($_SESSION)) { - if (isset($_SESSION['username'])) { - - //Include db_config.php file -- include_once('/var/lxdware/data/db_config.php'); -+ include_once('/home/yunohost.app/lxd-dashboard/data/db_config.php'); - - switch (DB_TYPE) { - case "sqlite": -diff --git a/lxd-dashboard/backend/config/cert.php b/lxd-dashboard/backend/config/cert.php -index e2b3799..3c234f3 100644 ---- a/lxd-dashboard/backend/config/cert.php -+++ b/lxd-dashboard/backend/config/cert.php -@@ -24,7 +24,7 @@ if (!isset($_SESSION)) { - - function createCertificate($certificateFilename, $numberofDays = 3650){ - //Only create the certificate if it does not already exist -- if (!file_exists('/var/lxdware/data/lxd/'.$certificateFilename.'.crt')){ -+ if (!file_exists('/home/yunohost.app/lxd-dashboard/data/lxd/'.$certificateFilename.'.crt')){ - $subject = array( - "commonName" => "LXDWARE", - ); -@@ -40,11 +40,11 @@ function createCertificate($certificateFilename, $numberofDays = 3650){ - - //Generate self-signed EC cert - $x509 = openssl_csr_sign($csr, null, $private_key, $numberofDays); -- openssl_x509_export_to_file($x509, '/var/lxdware/data/lxd/'.$certificateFilename.'.crt'); -- openssl_pkey_export_to_file($private_key, '/var/lxdware/data/lxd/'.$certificateFilename.'.key'); -+ openssl_x509_export_to_file($x509, '/home/yunohost.app/lxd-dashboard/data/lxd/'.$certificateFilename.'.crt'); -+ openssl_pkey_export_to_file($private_key, '/home/yunohost.app/lxd-dashboard/data/lxd/'.$certificateFilename.'.key'); - - //Change permissions to lock down private key -- chmod('/var/lxdware/data/lxd/'.$certificateFilename.'.key',0600); -+ chmod('/home/yunohost.app/lxd-dashboard/data/lxd/'.$certificateFilename.'.key',0600); - } - } - -@@ -65,9 +65,9 @@ if (isset($_SESSION['username'])) { - case "createCertificateFiles": - if (validateAuthorization($action)) { - if (!empty($name)){ -- if (!file_exists('/var/lxdware/data/lxd/'.$name.'.crt')){ -+ if (!file_exists('/home/yunohost.app/lxd-dashboard/data/lxd/'.$name.'.crt')){ - createCertificate($name, $days); -- if (file_exists('/var/lxdware/data/lxd/'.$name.'.crt') && file_exists('/var/lxdware/data/lxd/'.$name.'.key')) -+ if (file_exists('/home/yunohost.app/lxd-dashboard/data/lxd/'.$name.'.crt') && file_exists('/home/yunohost.app/lxd-dashboard/data/lxd/'.$name.'.key')) - echo '{"status": "Ok", "status_code": 200, "metadata": {"status": "Certificate files created"}}'; - else - echo '{"status": "Bad Request", "status_code": 400, "metadata": {"error": "Unable to create all certificate files"}}'; -@@ -85,11 +85,11 @@ if (isset($_SESSION['username'])) { - case "deleteCertificateFiles": - if (validateAuthorization($action)) { - if (!empty($name)){ -- unlink('/var/lxdware/data/lxd/'.$name.'.crt'); -- unlink('/var/lxdware/data/lxd/'.$name.'.key'); -+ unlink('/home/yunohost.app/lxd-dashboard/data/lxd/'.$name.'.crt'); -+ unlink('/home/yunohost.app/lxd-dashboard/data/lxd/'.$name.'.key'); - } - -- if (file_exists('/var/lxdware/data/lxd/'.$name.'.crt') || file_exists('/var/lxdware/data/lxd/'.$name.'.key')) -+ if (file_exists('/home/yunohost.app/lxd-dashboard/data/lxd/'.$name.'.crt') || file_exists('/home/yunohost.app/lxd-dashboard/data/lxd/'.$name.'.key')) - echo '{"status": "Bad Request", "status_code": 400, "metadata": {"error": "Unable to remove all certificate files"}}'; - else - echo '{"status": "Ok", "status_code": 200, "metadata": {"status": "Certificate files removed"}}'; -@@ -105,7 +105,7 @@ if (isset($_SESSION['username'])) { - $i = 0; - echo '{ "data": ['; - -- foreach (glob("/var/lxdware/data/lxd/*.crt") as $filename) { -+ foreach (glob("/home/yunohost.app/lxd-dashboard/data/lxd/*.crt") as $filename) { - - $data = openssl_x509_parse(file_get_contents($filename)); - $validFrom = date('Y-m-d H:i:s', $data['validFrom_time_t']); -@@ -138,7 +138,7 @@ if (isset($_SESSION['username'])) { - - case "viewCertificate": - if (validateAuthorization($action)) { -- $results = shell_exec("cat /var/lxdware/data/lxd/client.crt"); -+ $results = shell_exec("cat /home/yunohost.app/lxd-dashboard/data/lxd/client.crt"); - echo htmlentities($results); - } - else { -diff --git a/lxd-dashboard/backend/config/curl.php b/lxd-dashboard/backend/config/curl.php -index 7753f63..9642189 100644 ---- a/lxd-dashboard/backend/config/curl.php -+++ b/lxd-dashboard/backend/config/curl.php -@@ -31,8 +31,8 @@ require_once('../config/db.php'); - - - function sendCurlRequest($request_action, $request_type, $request_url, $request_data = "{}"){ -- $cert = "/var/lxdware/data/lxd/client.crt"; -- $key = "/var/lxdware/data/lxd/client.key"; -+ $cert = "/home/yunohost.app/lxd-dashboard/data/lxd/client.crt"; -+ $key = "/home/yunohost.app/lxd-dashboard/data/lxd/client.key"; - - //Set required variables - $get_connection_timeout = (isset($_SESSION['get_connection_timeout'])) ? $_SESSION['get_connection_timeout'] : 3; -diff --git a/lxd-dashboard/backend/config/db.php b/lxd-dashboard/backend/config/db.php -index e911499..68802eb 100644 ---- a/lxd-dashboard/backend/config/db.php -+++ b/lxd-dashboard/backend/config/db.php -@@ -34,12 +34,12 @@ function in_array_r($needle, $haystacks){ - function establishDatabaseConnection(){ - - //Require db_config.php file -- require_once('/var/lxdware/data/db_config.php'); -+ require_once('/home/yunohost.app/lxd-dashboard/data/db_config.php'); - - switch (DB_TYPE) { - case "sqlite": - $_SESSION['db_type'] = "SQLite"; -- $conn = new PDO('sqlite:/var/lxdware/data/sqlite/lxdware.sqlite'); -+ $conn = new PDO('sqlite:/home/yunohost.app/lxd-dashboard/data/sqlite/lxdware.sqlite'); - $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //needed for catch backward compatability with PHP 7 - break; - case "mysql": -diff --git a/lxd-dashboard/backend/config/login.php b/lxd-dashboard/backend/config/login.php -index bb30ef6..4b283b1 100644 ---- a/lxd-dashboard/backend/config/login.php -+++ b/lxd-dashboard/backend/config/login.php -@@ -34,7 +34,7 @@ switch ($action) { - case "loadLoginForm": - $showRegistrationForm = false; - -- if (!file_exists('/var/lxdware/data/db_config.php')){ -+ if (!file_exists('/home/yunohost.app/lxd-dashboard/data/db_config.php')){ - $showRegistrationForm = true; - } - else { -@@ -127,10 +127,10 @@ switch ($action) { - - case "writeDatabaseConfig": - -- if (!file_exists('/var/lxdware/data/db_config.php')){ -+ if (!file_exists('/home/yunohost.app/lxd-dashboard/data/db_config.php')){ - if ($database_type == 'sqlite'){ - try { -- $conn = new PDO('sqlite:/var/lxdware/data/sqlite/lxdware.sqlite'); -+ $conn = new PDO('sqlite:/home/yunohost.app/lxd-dashboard/data/sqlite/lxdware.sqlite'); - $db = null; - } - catch (PDOException $e){ -@@ -138,7 +138,7 @@ switch ($action) { - break; - } - -- $file = fopen("/var/lxdware/data/db_config.php", "w") or die('{"status": "Bad Request", "status_code": 400, "metadata": {"error": "Unable to write database configuration file"}}'); -+ $file = fopen("/home/yunohost.app/lxd-dashboard/data/db_config.php", "w") or die('{"status": "Bad Request", "status_code": 400, "metadata": {"error": "Unable to write database configuration file"}}'); - $txt = ""; - fwrite($file, $txt); - fclose($file); -- chmod('/var/lxdware/data/db_config.php',0600); -+ chmod('/home/yunohost.app/lxd-dashboard/data/db_config.php',0600); - } - - if ($database_type == 'mysql'){ -@@ -162,7 +162,7 @@ switch ($action) { - break; - } - -- $file = fopen("/var/lxdware/data/db_config.php", "w") or die('{"status": "Bad Request", "status_code": 400, "metadata": {"error": "Unable to write database configuration file"}}'); -+ $file = fopen("/home/yunohost.app/lxd-dashboard/data/db_config.php", "w") or die('{"status": "Bad Request", "status_code": 400, "metadata": {"error": "Unable to write database configuration file"}}'); - $txt = ""; - fwrite($file, $txt); - fclose($file); -- chmod('/var/lxdware/data/db_config.php',0600); -+ chmod('/home/yunohost.app/lxd-dashboard/data/db_config.php',0600); - } - - echo '{"status": "Ok", "status_code": 200, "metadata": "{}"}'; - } - else { -- echo '{"status": "Bad Request", "status_code": 400, "metadata": {"error": "Database config file \'/var/lxdware/data/db_config.php\' already exists"}}'; -+ echo '{"status": "Bad Request", "status_code": 400, "metadata": {"error": "Database config file \'/home/yunohost.app/lxd-dashboard/data/db_config.php\' already exists"}}'; - } - - break; -diff --git a/lxd-dashboard/backend/lxd/containers-single.php b/lxd-dashboard/backend/lxd/containers-single.php -index 7cbcc4c..13656b2 100644 ---- a/lxd-dashboard/backend/lxd/containers-single.php -+++ b/lxd-dashboard/backend/lxd/containers-single.php -@@ -704,7 +704,7 @@ if (isset($_SESSION['username'])) { - $instance_only = ($instance_backup['instance_only'])?"true":"false"; - $optimized_storage = ($instance_backup['optimized_storage'])?"true":"false"; - $hostname = retrieveHostName($remote); -- $file = '/var/lxdware/backups/' . $hostname . '/' . $project . '/' . $instance . '/' . $instance_backup['name']; -+ $file = '/home/yunohost.app/lxd-dashboard/backups/' . $hostname . '/' . $project . '/' . $instance . '/' . $instance_backup['name']; - $file_exists = false; - $file_size = ""; - $unit_size = ""; -diff --git a/lxd-dashboard/backend/lxd/containers.php b/lxd-dashboard/backend/lxd/containers.php -index 0ccf4b8..d3ca545 100644 ---- a/lxd-dashboard/backend/lxd/containers.php -+++ b/lxd-dashboard/backend/lxd/containers.php -@@ -398,7 +398,7 @@ if (isset($_SESSION['username'])) { - - case "deleteInstanceBackup": - $hostname = retrieveHostName($remote); -- $file = '/var/lxdware/backups/' . $hostname . '/' . $project . '/' . $instance . '/' . $name; -+ $file = '/home/yunohost.app/lxd-dashboard/backups/' . $hostname . '/' . $project . '/' . $instance . '/' . $name; - unlink($file); - $url = $base_url . "/1.0/containers/" . $instance . "/backups/" . $name . "?project=" . $project; - $results = sendCurlRequest($action, "DELETE", $url); -@@ -477,7 +477,7 @@ if (isset($_SESSION['username'])) { - - case "downloadInstanceExportFile": - $hostname = retrieveHostName($remote); -- $file = '/var/lxdware/backups/' . $hostname . '/' . $project . '/' . $instance . '/' . $name; -+ $file = '/home/yunohost.app/lxd-dashboard/backups/' . $hostname . '/' . $project . '/' . $instance . '/' . $name; - $file_name = basename($file); - $file_size = filesize($file); - -@@ -513,14 +513,14 @@ if (isset($_SESSION['username'])) { - - case "exportInstanceBackup": - if (validateAuthorization($action)) { -- $cert = "/var/lxdware/data/lxd/client.crt"; -- $key = "/var/lxdware/data/lxd/client.key"; -+ $cert = "/home/yunohost.app/lxd-dashboard/data/lxd/client.crt"; -+ $key = "/home/yunohost.app/lxd-dashboard/data/lxd/client.key"; - $hostname = retrieveHostName($remote); -- $file = '/var/lxdware/backups/' . $hostname . '/' . $project . '/' . $instance . '/' . $name; -+ $file = '/home/yunohost.app/lxd-dashboard/backups/' . $hostname . '/' . $project . '/' . $instance . '/' . $name; - if (!file_exists($file)){ - //If there is no directory yet for the host to store backups, create it -- if (!file_exists('/var/lxdware/backups/' . $hostname . '/' . $project . '/' . $instance)){ -- mkdir('/var/lxdware/backups/'.$hostname . '/' . $project . '/' . $instance, 0777, true); -+ if (!file_exists('/home/yunohost.app/lxd-dashboard/backups/' . $hostname . '/' . $project . '/' . $instance)){ -+ mkdir('/home/yunohost.app/lxd-dashboard/backups/'.$hostname . '/' . $project . '/' . $instance, 0777, true); - } - - $url = $base_url . "/1.0/containers/" . $instance . "/backups/" . $name . "/export?project=" . $project; -diff --git a/lxd-dashboard/backend/lxd/virtual-machines-single.php b/lxd-dashboard/backend/lxd/virtual-machines-single.php -index 17d573b..0673d87 100644 ---- a/lxd-dashboard/backend/lxd/virtual-machines-single.php -+++ b/lxd-dashboard/backend/lxd/virtual-machines-single.php -@@ -653,7 +653,7 @@ if (isset($_SESSION['username'])) { - $instance_only = ($instance_backup['instance_only'])?"true":"false"; - $optimized_storage = ($instance_backup['optimized_storage'])?"true":"false"; - $hostname = retrieveHostName($remote); -- $file = '/var/lxdware/backups/' . $hostname . '/' . $project . '/' . $instance . '/' . $instance_backup['name']; -+ $file = '/home/yunohost.app/lxd-dashboard/backups/' . $hostname . '/' . $project . '/' . $instance . '/' . $instance_backup['name']; - $file_exists = false; - $file_size = ""; - $unit_size = ""; -diff --git a/lxd-dashboard/backend/lxd/virtual-machines.php b/lxd-dashboard/backend/lxd/virtual-machines.php -index a01ce7d..df11017 100644 ---- a/lxd-dashboard/backend/lxd/virtual-machines.php -+++ b/lxd-dashboard/backend/lxd/virtual-machines.php -@@ -318,7 +318,7 @@ if (isset($_SESSION['username'])) { - - case "deleteInstanceBackup": - $hostname = retrieveHostName($remote); -- $file = '/var/lxdware/backups/' . $hostname . '/' . $project . '/' . $instance . '/' . $name; -+ $file = '/home/yunohost.app/lxd-dashboard/backups/' . $hostname . '/' . $project . '/' . $instance . '/' . $name; - unlink($file); - $url = $base_url . "/1.0/instances/" . $instance . "/backups/" . $name . "?project=" . $project; - $results = sendCurlRequest($action, "DELETE", $url); -@@ -397,7 +397,7 @@ if (isset($_SESSION['username'])) { - - case "downloadInstanceExportFile": - $hostname = retrieveHostName($remote); -- $file = '/var/lxdware/backups/' . $hostname . '/' . $project . '/' . $instance . '/' . $name; -+ $file = '/home/yunohost.app/lxd-dashboard/backups/' . $hostname . '/' . $project . '/' . $instance . '/' . $name; - $file_name = basename($file); - $file_size = filesize($file); - -@@ -433,14 +433,14 @@ if (isset($_SESSION['username'])) { - - case "exportInstanceBackup": - if (validateAuthorization($action)) { -- $cert = "/var/lxdware/data/lxd/client.crt"; -- $key = "/var/lxdware/data/lxd/client.key"; -+ $cert = "/home/yunohost.app/lxd-dashboard/data/lxd/client.crt"; -+ $key = "/home/yunohost.app/lxd-dashboard/data/lxd/client.key"; - $hostname = retrieveHostName($remote); -- $file = '/var/lxdware/backups/' . $hostname . '/' . $project . '/' . $instance . '/' . $name; -+ $file = '/home/yunohost.app/lxd-dashboard/backups/' . $hostname . '/' . $project . '/' . $instance . '/' . $name; - if (!file_exists($file)){ - //If there is no directory yet for the host to store backups, create it -- if (!file_exists('/var/lxdware/backups/' . $hostname . '/' . $project . '/' . $instance)){ -- mkdir('/var/lxdware/backups/'.$hostname . '/' . $project . '/' . $instance, 0777, true); -+ if (!file_exists('/home/yunohost.app/lxd-dashboard/backups/' . $hostname . '/' . $project . '/' . $instance)){ -+ mkdir('/home/yunohost.app/lxd-dashboard/backups/'.$hostname . '/' . $project . '/' . $instance, 0777, true); - } - - $url = $base_url . "/1.0/instances/" . $instance . "/backups/" . $name . "/export?project=" . $project; -diff --git a/startup.sh b/startup.sh -index 48aa2fe..90f6179 100644 ---- a/startup.sh -+++ b/startup.sh -@@ -1,24 +1,24 @@ - #!/bin/bash - - #Setup LXD data directory --if [ ! -d /var/lxdware/data/lxd ] -+if [ ! -d /home/yunohost.app/lxd-dashboard/data/lxd ] - then -- mkdir -p /var/lxdware/data/lxd -+ mkdir -p /home/yunohost.app/lxd-dashboard/data/lxd - fi - - #Create backups directory if needed --if [ ! -d /var/lxdware/backups ] -+if [ ! -d /home/yunohost.app/lxd-dashboard/backups ] - then -- mkdir -p /var/lxdware/backups -+ mkdir -p /home/yunohost.app/lxd-dashboard/backups - fi - - #Create SQLite database directory if needed --if [ ! -d /var/lxdware/data/sqlite ] -+if [ ! -d /home/yunohost.app/lxd-dashboard/data/sqlite ] - then -- mkdir -p /var/lxdware/data/sqlite -+ mkdir -p /home/yunohost.app/lxd-dashboard/data/sqlite - fi - --chown -R www-data:www-data /var/lxdware/ -+chown -R www-data:www-data /home/yunohost.app/lxd-dashboard/ - - #Start PHP for NGINX - service php7.4-fpm start \ No newline at end of file