diff --git a/check_process b/check_process index 44c97a8..26f0c64 100644 --- a/check_process +++ b/check_process @@ -1,13 +1,9 @@ -# See here for more information -# https://github.com/YunoHost/package_check#syntax-check_process-file - ;; Test complet ; Manifest - domain="domain.tld" (DOMAIN) - path="/path" (PATH) + domain="domain.tld" + path="/path" root_access=0 - is_public=1 (PUBLIC|public=1|private=0) - + is_public=1 ; Checks pkg_linter=1 setup_sub_dir=1 @@ -18,7 +14,6 @@ upgrade=1 backup_restore=1 multi_instance=1 - port_already_use=0 change_url=1 ;;; Options Email= anmol@datamol.org diff --git a/manifest.json b/manifest.json index 9e8a926..a72a78c 100644 --- a/manifest.json +++ b/manifest.json @@ -21,7 +21,7 @@ "url": "https://github.com/jesuisfol/adminer_ynh" }, "requirements": { - "yunohost": ">= 4.1.7" + "yunohost": ">= 4.2.4" }, "multi_instance": true, "services": [ diff --git a/scripts/install b/scripts/install index 0c7f432..667f176 100644 --- a/scripts/install +++ b/scripts/install @@ -45,6 +45,14 @@ ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url ynh_app_setting_set --app=$app --key=root_access --value=$root_access +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." --weight=2 + +# Create a system user +ynh_system_user_create --username=$app --home_dir="$final_path" + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -63,23 +71,10 @@ if [[ $root_access -eq 1 ]]; then cp -a ../sources/root_access_disabled/. $final_path fi -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." --weight=2 - -# Create a system user -ynh_system_user_create --username=$app - -#================================================= -# GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - -# Set permissions to app files -chown -R www-data:www-data $final_path -chmod 755 -R $final_path/adminer.php +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" +chmod 755 $final_path/adminer.php #================================================= # NGINX CONFIGURATION diff --git a/scripts/restore b/scripts/restore index 579cde3..16ba223 100644 --- a/scripts/restore +++ b/scripts/restore @@ -46,6 +46,14 @@ test ! -d $final_path \ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# RECREATE THE DEDICATED USER +#================================================= +ynh_script_progression --message="Recreating the dedicated system user..." --weight=2 + +# Create the dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir="$final_path" + #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -53,21 +61,10 @@ ynh_script_progression --message="Restoring Adminer main directory..." --weight= ynh_restore_file --origin_path="$final_path" -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --weight=2 - -# Create the dedicated user (if not existing) -ynh_system_user_create --username=$app - -#================================================= -# STANDARD RESTORATION STEPS -#================================================= - -# Restore permissions to app files -chown -R www-data:www-data $final_path -chmod 755 -R $final_path/adminer.php +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" +chmod 755 $final_path/adminer.php #================================================= # RESTORE THE PHP-FPM CONFIGURATION diff --git a/scripts/upgrade b/scripts/upgrade index 53faa4c..c3adec7 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -22,6 +22,26 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) root_access=$(ynh_app_setting_get --app=$app --key=root_access) phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) +#================================================= +# CHECK VERSION +#================================================= + +upgrade_type=$(ynh_check_app_version_changed) + +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_script_progression --message="Backing up Adminer before upgrading (may take a while)..." --weight=3 + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -40,48 +60,38 @@ if ynh_legacy_permissions_exists; then ynh_app_setting_delete --app=$app --key=is_public fi -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up Adminer before upgrading (may take a while)..." --weight=3 - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 # Create a dedicated user (if not existing) -ynh_system_user_create --username=$app +ynh_system_user_create --username=$app --home_dir="$final_path" -# Copy source files -ynh_secure_remove $final_path +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= -mkdir -p $final_path +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + # Copy source files + ynh_secure_remove $final_path -if [[ $root_access -eq 1 ]]; then -#copy files from with_root_access folder to the final_path - cp -a ../sources/with_root_access/. $final_path - else - #copy files from root_access_disabled folder to the final_path - cp -a ../sources/root_access_disabled/. $final_path + mkdir -p $final_path + + if [[ $root_access -eq 1 ]]; then + #copy files from with_root_access folder to the final_path + cp -a ../sources/with_root_access/. $final_path + else + #copy files from root_access_disabled folder to the final_path + cp -a ../sources/root_access_disabled/. $final_path + fi fi -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - -# Set permissions to app files -chmod 755 -R $final_path/adminer.php -chown -R www-data:www-data $final_path +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" +chmod 755 $final_path/adminer.php #================================================= # NGINX CONFIGURATION diff --git a/sources/with_root_access/index.php b/sources/with_root_access/index.php index b9ce4d0..762aaaf 100644 --- a/sources/with_root_access/index.php +++ b/sources/with_root_access/index.php @@ -5,56 +5,56 @@ * @copyright 2007 Jakub Vrana * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 * @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other) -* @version 4.8.0 +* @version 4.8.1 */function -adminer_errors($Ac,$Cc){return!!preg_match('~^(Trying to access array offset on value of type null|Undefined array key)~',$Cc);}error_reporting(6135);set_error_handler('adminer_errors',2);$Yc=!preg_match('~^(unsafe_raw)?$~',ini_get("filter.default"));if($Yc||ini_get("filter.default_flags")){foreach(array('_GET','_POST','_COOKIE','_SERVER')as$X){$Hi=filter_input_array(constant("INPUT$X"),FILTER_UNSAFE_RAW);if($Hi)$$X=$Hi;}}if(function_exists("mb_internal_encoding"))mb_internal_encoding("8bit");function +adminer_errors($Cc,$Ec){return!!preg_match('~^(Trying to access array offset on value of type null|Undefined array key)~',$Ec);}error_reporting(6135);set_error_handler('adminer_errors',E_WARNING);$ad=!preg_match('~^(unsafe_raw)?$~',ini_get("filter.default"));if($ad||ini_get("filter.default_flags")){foreach(array('_GET','_POST','_COOKIE','_SERVER')as$X){$Ii=filter_input_array(constant("INPUT$X"),FILTER_UNSAFE_RAW);if($Ii)$$X=$Ii;}}if(function_exists("mb_internal_encoding"))mb_internal_encoding("8bit");function connection(){global$g;return$g;}function adminer(){global$b;return$b;}function version(){global$ia;return$ia;}function -idf_unescape($v){$pe=substr($v,-1);return -str_replace($pe.$pe,$pe,substr($v,1,-1));}function +idf_unescape($v){if(!preg_match('~^[`\'"]~',$v))return$v;$qe=substr($v,-1);return +str_replace($qe.$qe,$qe,substr($v,1,-1));}function escape_string($X){return substr(q($X),1,-1);}function number($X){return preg_replace('~[^0-9]+~','',$X);}function number_type(){return'((?$W){unset($sg[$z][$ge]);if(is_array($W)){$sg[$z][stripslashes($ge)]=$W;$sg[]=&$sg[$z][stripslashes($ge)];}else$sg[$z][stripslashes($ge)]=($Yc?$W:stripslashes($W));}}}}function -bracket_escape($v,$Na=false){static$ti=array(':'=>':1',']'=>':2','['=>':3','"'=>':4');return -strtr($v,($Na?array_flip($ti):$ti));}function -min_version($Yi,$Ce="",$h=null){global$g;if(!$h)$h=$g;$mh=$h->server_info;if($Ce&&preg_match('~([\d.]+)-MariaDB~',$mh,$C)){$mh=$C[1];$Yi=$Ce;}return(version_compare($mh,$Yi)>=0);}function +remove_slashes($tg,$ad=false){if(function_exists("get_magic_quotes_gpc")&&get_magic_quotes_gpc()){while(list($z,$X)=each($tg)){foreach($X +as$he=>$W){unset($tg[$z][$he]);if(is_array($W)){$tg[$z][stripslashes($he)]=$W;$tg[]=&$tg[$z][stripslashes($he)];}else$tg[$z][stripslashes($he)]=($ad?$W:stripslashes($W));}}}}function +bracket_escape($v,$Na=false){static$ui=array(':'=>':1',']'=>':2','['=>':3','"'=>':4');return +strtr($v,($Na?array_flip($ui):$ui));}function +min_version($Zi,$De="",$h=null){global$g;if(!$h)$h=$g;$nh=$h->server_info;if($De&&preg_match('~([\d.]+)-MariaDB~',$nh,$C)){$nh=$C[1];$Zi=$De;}return(version_compare($nh,$Zi)>=0);}function charset($g){return(min_version("5.5.3",0,$g)?"utf8mb4":"utf8");}function -script($xh,$si="\n"){return"$xh$si";}function -script_src($Mi){return"\n";}function +script($yh,$ti="\n"){return"$yh$ti";}function +script_src($Ni){return"\n";}function nonce(){return' nonce="'.get_nonce().'"';}function target_blank(){return' target="_blank" rel="noreferrer noopener"';}function h($P){return str_replace("\0","�",htmlspecialchars($P,ENT_QUOTES,'utf-8'));}function nl_br($P){return str_replace("\n","
",$P);}function -checkbox($D,$Y,$db,$le="",$tf="",$hb="",$me=""){$I="".($tf?script("qsl('input').onclick = function () { $tf };",""):"");return($le!=""||$hb?"$I".h($le)."":$I);}function -optionlist($zf,$fh=null,$Qi=false){$I="";foreach($zf -as$ge=>$W){$_f=array($ge=>$W);if(is_array($W)){$I.='';$_f=$W;}foreach($_f -as$z=>$X)$I.=''.h($X);if(is_array($W))$I.='';}return$I;}function -html_select($D,$zf,$Y="",$sf=true,$me=""){if($sf)return"".(is_string($sf)?script("qsl('select').onchange = function () { $sf };",""):"");$I="";foreach($zf +checkbox($D,$Y,$db,$me="",$uf="",$hb="",$ne=""){$I="".($uf?script("qsl('input').onclick = function () { $uf };",""):"");return($me!=""||$hb?"$I".h($me)."":$I);}function +optionlist($_f,$gh=null,$Ri=false){$I="";foreach($_f +as$he=>$W){$Af=array($he=>$W);if(is_array($W)){$I.='';$Af=$W;}foreach($Af +as$z=>$X)$I.=''.h($X);if(is_array($W))$I.='';}return$I;}function +html_select($D,$_f,$Y="",$tf=true,$ne=""){if($tf)return"".(is_string($tf)?script("qsl('select').onchange = function () { $tf };",""):"");$I="";foreach($_f as$z=>$X)$I.="";return$I;}function -select_input($Ia,$zf,$Y="",$sf="",$eg=""){$Xh=($zf?"select":"input");return"<$Xh$Ia".($zf?">