swap MODS Sample Simple and Advanced for DSM 7.x

This commit is contained in:
vletroye
2021-02-18 18:15:37 +01:00
parent 6290dd2663
commit d19a0cc978
21 changed files with 255 additions and 250 deletions

View File

@ -2,8 +2,8 @@ arch="noarch"
beta="yes" beta="yes"
ctl_stop="yes" ctl_stop="yes"
ctl_uninstall="yes" ctl_uninstall="yes"
description="This is a package created with MODS to illustrate the use of a fake CGI. It's a version of the package 'MODS Sample - Simple CGI 7.x' which requires to a sudoer account 'ModsPackager' in order to be able to deploy it's nginx config." description="This is a package created with MODS to illustrate the use of a fake CGI that runs a simple php website, displayed in a DSM iFrame. It requires dependency neither on the well known package Init_3rdparty not on the Synology WebStation. it reuses the 'Simple php Website' of Banago for illustration purpose. Navigation between pages can be tested as well asAjax calls, Ajax callbacks, Post and Get. This version is targeting DSM 7.x. Due to security restriction during installation, it requires an access onto the NAS via SSH. Credentials of an administrator must be entered (at your own risk) to autorize the execution of commands as sudoer. This is indeed required to configure nginx and run php pages deployed outside the root folder of the WebStation."
description_enu="This is a package created with MODS to illustrate the use of a fake CGI. It's a version of the package 'MODS Sample - Simple CGI 7.x' which requires to a sudoer account 'ModsPackager' in order to be able to deploy it's nginx config." description_enu="This is a package created with MODS to illustrate the use of a fake CGI that runs a simple php website, displayed in a DSM iFrame. It requires dependency neither on the well known package Init_3rdparty not on the Synology WebStation. it reuses the 'Simple php Website' of Banago for illustration purpose. Navigation between pages can be tested as well asAjax calls, Ajax callbacks, Post and Get. This version is targeting DSM 7.x. Due to security restriction during installation, it requires an access onto the NAS via SSH. Credentials of an administrator must be entered (at your own risk) to autorize the execution of commands as sudoer. This is indeed required to configure nginx and run php pages deployed outside the root folder of the WebStation."
displayname="MODS Sample - Advanced CGI 7.x" displayname="MODS Sample - Advanced CGI 7.x"
displayname_enu="MODS Sample - Advanced CGI 7.x" displayname_enu="MODS Sample - Advanced CGI 7.x"
distributor="vletroye" distributor="vletroye"
@ -32,5 +32,4 @@ startstop_restart_services="nginx.service"
support_center="no" support_center="no"
support_url="https://github.com/vletroye/SynoPackages/wiki/MODS-Sample-Advanced-Cgi-7.x" support_url="https://github.com/vletroye/SynoPackages/wiki/MODS-Sample-Advanced-Cgi-7.x"
thirdparty="yes" thirdparty="yes"
version="1.0-0126" version="1.0-0127"
checksum="3a087249c749130025b1e18165a5dc45"

View File

@ -1,32 +1,58 @@
[ [
{ {
"step_title": "Installation Guide", "step_title": "Install parameters",
"invalid_next_disabled": true, "invalid_next_disabled": true,
"items": [ "items": [
{ {
"type": "textfield", "type": "textfield",
"desc": "Before installing this package, you must define a sudoer account 'ModsPackager' on your NAS, with rights to run /bin/ln and /bin/unlink without password:", "desc": "Enter an administrator account and his password to install this package:",
"subitems": [] "subitems": [
{
"blankText": "You must type an account",
"key": "MODS_ADMIN",
"defaultValue": "admin",
"desc": "Account"
}
]
},
{
"type": "password",
"desc": "",
"subitems": [
{
"blankText": "You must type a password",
"key": "MODS_PASSWORD",
"desc": "Password"
}
]
},
{
"type": "multiselect",
"subitems": [
{
"key": "MODS_SAVE",
"defaultValue": "false",
"desc": "Save password"
}
]
}, },
{ {
"type": "textfield", "type": "textfield",
"desc": "1. Connect onto your NAS via SSH (using e.g. the Putty console) as administrator", "desc": "Enter the port used to connect via SSH:",
"subitems": [] "subitems": [
}, {
{ "validator": {
"type": "textfield", "allowBlank": false,
"desc": "2. Create a sudo file (the name does not matter): sudo vi /etc/sudoers.d/ModsPackager", "regex": {
"subitems": [] "errorText": "You must enter a valid port",
}, "expr": "/^(102[0-3]|10[0-1]\\d|[1-9][0-9]{0,2}|0)$/"
{ }
"type": "textfield", },
"desc": "3. Type in this file: ModsPackager ALL=(ALL) NOPASSWD:/bin/ln,/bin/unlink", "key": "MODS_PORT",
"subitems": [] "defaultValue": "22",
}, "desc": "SSH Port"
{ }
"type": "textfield", ]
"desc": "4. Save the file (with :x!)",
"subitems": []
} }
] ]
} }

View File

@ -1,7 +1,5 @@
{ {
"defaults": { "defaults": {
"run-as": "package" "run-as": "package"
}, }
"username": "ModsPackager",
"groupname": "ModsPackager"
} }

View File

@ -37,15 +37,6 @@ if [ -z $SYNOPKG_PKGNAME ]; then
fi fi
LOG="/tmp/$SYNOPKG_PKGNAME.log" LOG="/tmp/$SYNOPKG_PKGNAME.log"
ERR="/tmp/$SYNOPKG_PKGNAME.err" ERR="/tmp/$SYNOPKG_PKGNAME.err"
if [ ! -f $ERR ]; then
touch $ERR
chmod og+w $ERR
fi
if [ ! -f $LOG ]; then
touch $LOG
chmod og+w $LOG
fi
SEP="################################################################################################################################################################################" SEP="################################################################################################################################################################################"
WIZARD=0 WIZARD=0
@ -83,9 +74,63 @@ function ShowLog() {
fi fi
} }
# Execute a command via SSH on the local host, using a php script
function ExecSSH() {
user=$1 # Admin account
pass=$2 # Admin password
port=$3 # SSH port
cmd=$4 # Command to execute
# Find the php version to be used
version=`php -v | grep "PHP " | cut -f2 -d " "`
major=`echo $version | cut -d. -f1`
minor=`echo $version | cut -d. -f2`
if [ $0 == "-sh" ]; then
# If run from a -sh, assume that the php script os local
path="."
else
path="/var/packages/$SYNOPKG_PKGNAME/scripts"
fi
script="$path/exec.php"
# Call PHP with ssh2 modules
output="$(php -dextension=/var/packages/PHP$major.$minor/target/usr/local/lib/php$major$minor/modules/ssh2.so "$script" -u "$user" -p "$pass" -s "127.0.0.1" -o "$port" -c "$cmd")"
ExitCode=$? #Do not add any line or comment between the command and this line retrieving its exit code!!
LogInfo "$output"
return $ExitCode
}
# Validate credentials to connect via SSH on the local host, using a php script
function CheckSSH() {
user=$1 # Admin account
pass=$2 # Admin password
port=$3 # SSH port
# Find the php version to be used
version=`php -v | grep "PHP " | cut -f2 -d " "`
major=`echo $version | cut -d. -f1`
minor=`echo $version | cut -d. -f2`
if [ $0 == "-sh" ]; then
# If run from a -sh, assume that the php script os local
path="."
else
path="/var/packages/$SYNOPKG_PKGNAME/scripts"
fi
script="$path/check.php"
# Call PHP with ssh2 modules
output="$(php -dextension=/var/packages/PHP$major.$minor/target/usr/local/lib/php$major$minor/modules/ssh2.so "$script" -u "$user" -p "$pass" -s "127.0.0.1" -o "$port")"
ExitCode=$? #Do not add any line of comment between the command and this line retrieving its exit code!!
LogInfo "$output"
return $ExitCode
}
# Link nginx to the package's config file defined to be able to run php scripts outside to web root folder # Link nginx to the package's config file defined to be able to run php scripts outside to web root folder
function LinkNginx() { function LinkNginx() {
LogInfo "I am : `whoami`"
if [ -f $SYNOPKG_PKGDEST/ui/router.cgi ]; then if [ -f $SYNOPKG_PKGDEST/ui/router.cgi ]; then
# Set the name of the package in the router cgi # Set the name of the package in the router cgi
sed -i -e "s|@SYNOPKG_PKGNAME@|$SYNOPKG_PKGNAME|g" "$SYNOPKG_PKGDEST/ui/router.cgi" sed -i -e "s|@SYNOPKG_PKGNAME@|$SYNOPKG_PKGNAME|g" "$SYNOPKG_PKGDEST/ui/router.cgi"
@ -101,29 +146,83 @@ function LinkNginx() {
if [ -f $LINK ]; then if [ -f $LINK ]; then
LogInfo "Link to nginx config already exists." LogInfo "Link to nginx config already exists."
else else
sudo /bin/ln -s "$SYNOPKG_PKGDEST/ui/dsm.cgi.conf" "$LINK" # Check if SSH connection is working
LogInfo "Checking SSH credentials"
CheckSSH "$MODS_ADMIN" "$MODS_PASSWORD" "$MODS_PORT"
ExitCode=$? #Do not add any line of comment between the command and this line retrieving its exit code!!
if [ $ExitCode == 0 ]; then
# Store Admin account and SSH port
if [ ! -z $MODS_ADMIN ]; then
echo "MODS_ADMIN=$MODS_ADMIN" > "/var/packages/$SYNOPKG_PKGNAME/etc/parameters"
echo "MODS_PORT=$MODS_PORT" >> "/var/packages/$SYNOPKG_PKGNAME/etc/parameters"
chmod og-r "/var/packages/$SYNOPKG_PKGNAME/etc/parameters"
fi
# Store Admin password if requested
if [ $MODS_SAVE == "true" ]; then
# Create a Private Key to encrypt the password
if [ ! -f "/var/packages/$SYNOPKG_PKGNAME/etc/image" ]; then
LogInfo "Creating Encryption Key"
openssl genrsa -out /var/packages/$SYNOPKG_PKGNAME/etc/image 2048 2> /dev/null
fi
# Encrypt and store the password
if [ ! -z $MODS_PASSWORD ]; then
LogInfo "Encrypting Password"
echo "$MODS_PASSWORD" | openssl rsautl -inkey /var/packages/$SYNOPKG_PKGNAME/etc/image -encrypt > /var/packages/$SYNOPKG_PKGNAME/etc/backup
chmod og-r /var/packages/$SYNOPKG_PKGNAME/etc/backup
fi
else
LogInfo "Don't store Password"
fi
# Create the Symbolic link
LogInfo "Creating nginx Link"
ExecSSH "$MODS_ADMIN" "$MODS_PASSWORD" "$MODS_PORT" "ln -s $SYNOPKG_PKGDEST/ui/dsm.cgi.conf $LINK"
ExitCode=$?
# Check that the link has been created # Check that the link has been created
if [ ! -f $LINK ]; then if [ ! -f $LINK ]; then
PublishInfo ""
PublishInfo "Link Creation failed..."
PublishInfo "Investigate the reason in the Logs"
exit 150
fi
else
PublishInfo "" PublishInfo ""
PublishInfo "Link Creation failed..." PublishInfo "Cannot connect via SSH onto the NAS with provided Login/Password."
PublishInfo "Investigate the reason in the Logs" PublishInfo "Go back into the Installation Wizard to change your Login/Password."
return 1 exit 150
fi fi
fi fi
fi fi
return 0
} }
# Unlink nginx config # Unlink nginx config
function UnlinkNginx() { function UnlinkNginx() {
LogInfo "I am : `whoami`"
if [ $SYNOPKG_PKG_STATUS == "UNINSTALL" ]; then if [ $SYNOPKG_PKG_STATUS == "UNINSTALL" ]; then
LINK="/usr/syno/share/nginx/conf.d/dsm.$SYNOPKG_PKGNAME.conf" LINK="/usr/syno/share/nginx/conf.d/dsm.$SYNOPKG_PKGNAME.conf"
if [ -f $LINK ]; then if [ -f $LINK ]; then
sudo /bin/unlink "$LINK" # Retrieve previous credentials if no account received from Wizard
if [ -z $MODS_ADMIN ] && [ -f /var/packages/$SYNOPKG_PKGNAME/etc/backup ]; then
if [ -f /var/packages/$SYNOPKG_PKGNAME/etc/parameters ]; then
. /var/packages/$SYNOPKG_PKGNAME/etc/parameters
fi
if [ -z $MODS_PASSWORD ]; then
LogInfo "Retrieving previous SSH credentials"
MODS_PASSWORD=$(openssl rsautl -inkey /var/packages/$SYNOPKG_PKGNAME/etc/image -decrypt < /var/packages/$SYNOPKG_PKGNAME/etc/backup)
fi
fi
# Unlink nginx configuration
LogInfo "Removing nginx Link"
ExecSSH "$MODS_ADMIN" "$MODS_PASSWORD" "$MODS_PORT" "unlink $LINK"
ExitCode=$?
if [ -f $LINK ]; then if [ -f $LINK ]; then
PublishInfo PublishInfo

View File

@ -3,18 +3,13 @@
. `dirname $0`/common `basename $0` $* . `dirname $0`/common `basename $0` $*
StartScript StartScript
if [ $? != 0 ]; then
LinkNginx exit 150
ExitCode=$?
if [ $ExitCode == "0" ]; then
EnableRouterLog
fi fi
EndScript LinkNginx
if [ $ExitCode == "0" ]; then EnableRouterLog
exit 0
else EndScript
exit 150 exit 0
fi

View File

@ -2,12 +2,12 @@ arch="noarch"
beta="yes" beta="yes"
ctl_stop="yes" ctl_stop="yes"
ctl_uninstall="yes" ctl_uninstall="yes"
description="This is a package created with MODS to illustrate the use of a fake CGI that runs a simple php website, displayed in a DSM iFrame. It requires dependency neither on the well known package Init_3rdparty not on the Synology WebStation. it reuses the 'Simple php Website' of Banago for illustration purpose. Navigation between pages can be tested as well asAjax calls, Ajax callbacks, Post and Get. This version is targeting DSM 7.x. Due to security restriction during installation, it requires an access onto the NAS via SSH. Credentials of an administrator must be entered (at your own risk) to autorize the execution of commands as sudoer. This is indeed required to configure nginx and run php pages deployed outside the root folder of the WebStation." description="This is a package created with MODS to illustrate the use of a fake CGI. It's a version of the package 'MODS Sample - Simple CGI 7.x' which requires to a sudoer account 'ModsPackager' in order to be able to deploy it's nginx config."
description_enu="This is a package created with MODS to illustrate the use of a fake CGI that runs a simple php website, displayed in a DSM iFrame. It requires dependency neither on the well known package Init_3rdparty not on the Synology WebStation. it reuses the 'Simple php Website' of Banago for illustration purpose. Navigation between pages can be tested as well asAjax calls, Ajax callbacks, Post and Get. This version is targeting DSM 7.x. Due to security restriction during installation, it requires an access onto the NAS via SSH. Credentials of an administrator must be entered (at your own risk) to autorize the execution of commands as sudoer. This is indeed required to configure nginx and run php pages deployed outside the root folder of the WebStation." description_enu="This is a package created with MODS to illustrate the use of a fake CGI. It's a version of the package 'MODS Sample - Simple CGI 7.x' which requires to a sudoer account 'ModsPackager' in order to be able to deploy it's nginx config."
displayname="MODS Sample - Simple CGI 7.x" displayname="MODS Sample - Simple CGI 7.x"
displayname_enu="MODS Sample - Simple CGI 7.x" displayname_enu="MODS Sample - Simple CGI 7.x"
distributor="vletroye" distributor="vletroye"
distributor_url="https://www.beatificabytes.be/sspks" distributor_url="https://olympe.letroye.be/sspks"
dsmappname="SYNO.SDS.ThirdParty.App.MODS_Sample_Simple_CGI_7.x" dsmappname="SYNO.SDS.ThirdParty.App.MODS_Sample_Simple_CGI_7.x"
dsmuidir="ui" dsmuidir="ui"
firmware="7.0-40000" firmware="7.0-40000"
@ -22,7 +22,7 @@ os_min_ver="7.0-40000"
package="MODS_Sample_Simple_CGI_7.x" package="MODS_Sample_Simple_CGI_7.x"
precheckstartstop="no" precheckstartstop="no"
reloadui="yes" reloadui="yes"
report_url="https://github.com/vletroye/SynoPackages/wiki" report_url="https://github.com/vletroye/SynoPackages/issues"
silent_install="no" silent_install="no"
silent_uninstall="no" silent_uninstall="no"
silent_upgrade="no" silent_upgrade="no"
@ -32,5 +32,5 @@ startstop_restart_services="nginx.service"
support_center="no" support_center="no"
support_url="https://github.com/vletroye/SynoPackages/wiki/MODS-Sample-Simple-Cgi-7.x" support_url="https://github.com/vletroye/SynoPackages/wiki/MODS-Sample-Simple-Cgi-7.x"
thirdparty="yes" thirdparty="yes"
version="1.0-0110" version="1.0-0111"
checksum="0f5f87f61166787c95a86c0bdb63d962" checksum="d1dfe3d090fd8c3145a8672ee234f374"

View File

@ -1,58 +1,32 @@
[ [
{ {
"step_title": "Install parameters", "step_title": "Installation Guide",
"invalid_next_disabled": true, "invalid_next_disabled": true,
"items": [ "items": [
{ {
"type": "textfield", "type": "textfield",
"desc": "Enter an administrator account and his password to install this package:", "desc": "Before installing this package, you must define a sudoer account 'ModsPackager' on your NAS, with rights to run /bin/ln and /bin/unlink without password:",
"subitems": [ "subitems": []
{
"blankText": "You must type an account",
"key": "MODS_ADMIN",
"defaultValue": "admin",
"desc": "Account"
}
]
},
{
"type": "password",
"desc": "",
"subitems": [
{
"blankText": "You must type a password",
"key": "MODS_PASSWORD",
"desc": "Password"
}
]
},
{
"type": "multiselect",
"subitems": [
{
"key": "MODS_SAVE",
"defaultValue": "false",
"desc": "Save password"
}
]
}, },
{ {
"type": "textfield", "type": "textfield",
"desc": "Enter the port used to connect via SSH:", "desc": "1. Connect onto your NAS via SSH (using e.g. the Putty console) as administrator",
"subitems": [ "subitems": []
{ },
"validator": { {
"allowBlank": false, "type": "textfield",
"regex": { "desc": "2. Create a sudo file (the name does not matter): sudo vi /etc/sudoers.d/ModsPackager",
"errorText": "You must enter a valid port", "subitems": []
"expr": "/^(102[0-3]|10[0-1]\\d|[1-9][0-9]{0,2}|0)$/" },
} {
}, "type": "textfield",
"key": "MODS_PORT", "desc": "3. Type in this file: ModsPackager ALL=(ALL) NOPASSWD:/bin/ln,/bin/unlink",
"defaultValue": "22", "subitems": []
"desc": "SSH Port" },
} {
] "type": "textfield",
"desc": "4. Save the file (with :x!)",
"subitems": []
} }
] ]
} }

View File

@ -1,5 +1,7 @@
{ {
"defaults": { "defaults": {
"run-as": "package" "run-as": "package"
} },
"username": "ModsPackager",
"groupname": "ModsPackager"
} }

View File

@ -1,13 +1,13 @@
{ {
".url": { ".url": {
"SYNO.SDS.ThirdParty.App.MODS_Sample_Simple_CGI_7.x": { "SYNO.SDS._ThirdParty.App.MODS_Sample_Simple_CGI_7.x": {
"itemType": 2, "itemType": 2,
"type": "legacy", "type": "legacy",
"allUsers": true, "allUsers": true,
"title": "Mods Simple CGI", "title": "Mods Advanced CGI",
"desc": "Simple php website running on DSM 7.x without the need for the Init_3rdparty package and WebStation.", "desc": "Simple php website running on DSM 7.x without the need for the Init_3rdparty package and WebStation.",
"icon": "images/Mods_Simple_CGI_{0}.png", "icon": "images/Mods_Simple_CGI_{0}.png",
"appWindow": "SYNO.SDS.ThirdParty.App.MODS_Sample_Simple_CGI_7.x", "appWindow": "SYNO.SDS._ThirdParty.App.MODS_Sample_Simple_CGI_7.x",
"url": "/webman/3rdparty/MODS_Sample_Simple_CGI_7.x/index.php", "url": "/webman/3rdparty/MODS_Sample_Simple_CGI_7.x/index.php",
"allowMultiInstance": false, "allowMultiInstance": false,
"configablePrivilege": true, "configablePrivilege": true,

View File

@ -26,14 +26,26 @@
# Define temporary Log and Err files # Define temporary Log and Err files
if [ -z $SYNOPKG_PKGNAME ]; then if [ -z $SYNOPKG_PKGNAME ]; then
# Define variables to be able to run from a -sh instead of being run from Synology installer # Define variables to be able to run from a -sh instead of being run from Synology installer
SYNOPKG_PKGNAME="MODS_DUMMY" SYNOPKG_PKGNAME="$(pwd | cut -d '/' -f4)"
SYNOPKG_PKGDEST="." if [ -z $SYNOPKG_PKGNAME ]; then
LOG="/tmp/$SYNOPKG_PKGNAME.log" SYNOPKG_PKGNAME="Dummy"
ERR="/tmp/$SYNOPKG_PKGNAME.err" SYNOPKG_PKGDEST="."
else SYNOPKG_TEMP_LOGFILE="/tmp/$SYNOPKG_PKGNAME.log"
LOG="/tmp/$SYNOPKG_PKGNAME.log" else
ERR="/tmp/$SYNOPKG_PKGNAME.err" SYNOPKG_PKGDEST="/var/packages/$SYNOPKG_PKGNAME/target"
fi
fi fi
LOG="/tmp/$SYNOPKG_PKGNAME.log"
ERR="/tmp/$SYNOPKG_PKGNAME.err"
if [ ! -f $ERR ]; then
touch $ERR
chmod og+w $ERR
fi
if [ ! -f $LOG ]; then
touch $LOG
chmod og+w $LOG
fi
SEP="################################################################################################################################################################################" SEP="################################################################################################################################################################################"
WIZARD=0 WIZARD=0
@ -55,15 +67,15 @@ function ShowLog() {
LogInfo " -f: full display" LogInfo " -f: full display"
LogInfo " -l: keep logs after display" LogInfo " -l: keep logs after display"
else else
if [ -f /var/log/packages/MODS_Sample_Simple_CGI_7.x.log ]; then if [ -f /var/log/packages/$SYNOPKG_PKGNAME.log ]; then
if [ $full == 1 ]; then if [ $full == 1 ]; then
sudo cat /tmp/MODS* /var/log/packages/MODS_Sample_Simple_CGI_7.x.log sudo cat /tmp/MODS* /var/log/packages/$SYNOPKG_PKGNAME.log
else else
sudo cat /tmp/MODS* /var/log/packages/MODS_Sample_Simple_CGI_7.x.log | grep -v "Begin /bin/" | grep -v "End /bin/" sudo cat /tmp/MODS* /var/log/packages/$SYNOPKG_PKGNAME.log | grep -v "Begin /bin/" | grep -v "End /bin/"
fi fi
if [ $keep == 0 ]; then if [ $keep == 0 ]; then
sudo rm -f /var/log/packages/MODS_Sample_Simple_CGI_7.x.log sudo rm -f /var/log/packages/$SYNOPKG_PKGNAME.log
fi fi
#rm -f /tmp/MODS* #rm -f /tmp/MODS*
@ -71,63 +83,9 @@ function ShowLog() {
fi fi
} }
# Execute a command via SSH on the local host, using a php script
function ExecSSH() {
user=$1 # Admin account
pass=$2 # Admin password
port=$3 # SSH port
cmd=$4 # Command to execute
# Find the php version to be used
version=`php -v | grep "PHP " | cut -f2 -d " "`
major=`echo $version | cut -d. -f1`
minor=`echo $version | cut -d. -f2`
if [ $0 == "-sh" ]; then
# If run from a -sh, assume that the php script os local
path="."
else
path="/var/packages/$SYNOPKG_PKGNAME/scripts"
fi
script="$path/exec.php"
# Call PHP with ssh2 modules
output="$(php -dextension=/var/packages/PHP$major.$minor/target/usr/local/lib/php$major$minor/modules/ssh2.so "$script" -u "$user" -p "$pass" -s "127.0.0.1" -o "$port" -c "$cmd")"
ExitCode=$? #Do not add any line or comment between the command and this line retrieving its exit code!!
LogInfo "$output"
return $ExitCode
}
# Validate credentials to connect via SSH on the local host, using a php script
function CheckSSH() {
user=$1 # Admin account
pass=$2 # Admin password
port=$3 # SSH port
# Find the php version to be used
version=`php -v | grep "PHP " | cut -f2 -d " "`
major=`echo $version | cut -d. -f1`
minor=`echo $version | cut -d. -f2`
if [ $0 == "-sh" ]; then
# If run from a -sh, assume that the php script os local
path="."
else
path="/var/packages/$SYNOPKG_PKGNAME/scripts"
fi
script="$path/check.php"
# Call PHP with ssh2 modules
output="$(php -dextension=/var/packages/PHP$major.$minor/target/usr/local/lib/php$major$minor/modules/ssh2.so "$script" -u "$user" -p "$pass" -s "127.0.0.1" -o "$port")"
ExitCode=$? #Do not add any line of comment between the command and this line retrieving its exit code!!
LogInfo "$output"
return $ExitCode
}
# Link nginx to the package's config file defined to be able to run php scripts outside to web root folder # Link nginx to the package's config file defined to be able to run php scripts outside to web root folder
function LinkNginx() { function LinkNginx() {
LogInfo "I am : `whoami`"
if [ -f $SYNOPKG_PKGDEST/ui/router.cgi ]; then if [ -f $SYNOPKG_PKGDEST/ui/router.cgi ]; then
# Set the name of the package in the router cgi # Set the name of the package in the router cgi
sed -i -e "s|@SYNOPKG_PKGNAME@|$SYNOPKG_PKGNAME|g" "$SYNOPKG_PKGDEST/ui/router.cgi" sed -i -e "s|@SYNOPKG_PKGNAME@|$SYNOPKG_PKGNAME|g" "$SYNOPKG_PKGDEST/ui/router.cgi"
@ -143,85 +101,31 @@ function LinkNginx() {
if [ -f $LINK ]; then if [ -f $LINK ]; then
LogInfo "Link to nginx config already exists." LogInfo "Link to nginx config already exists."
else else
# Check if SSH connection is working sudo /bin/ln -s "$SYNOPKG_PKGDEST/ui/dsm.cgi.conf" "$LINK"
LogInfo "Checking SSH credentials"
CheckSSH "$MODS_ADMIN" "$MODS_PASSWORD" "$MODS_PORT"
ExitCode=$? #Do not add any line of comment between the command and this line retrieving its exit code!!
if [ $ExitCode == 0 ]; then
# Store Admin account and SSH port
if [ ! -z $MODS_ADMIN ]; then
echo "MODS_ADMIN=$MODS_ADMIN" > "/var/packages/$SYNOPKG_PKGNAME/etc/parameters"
echo "MODS_PORT=$MODS_PORT" >> "/var/packages/$SYNOPKG_PKGNAME/etc/parameters"
chmod og-r "/var/packages/$SYNOPKG_PKGNAME/etc/parameters"
fi
# Store Admin password if requested
if [ $MODS_SAVE == "true" ]; then
# Create a Private Key to encrypt the password
if [ ! -f "/var/packages/$SYNOPKG_PKGNAME/etc/image" ]; then
LogInfo "Creating Encryption Key"
openssl genrsa -out /var/packages/$SYNOPKG_PKGNAME/etc/image 2048 2> /dev/null
fi
# Encrypt and store the password
if [ ! -z $MODS_PASSWORD ]; then
LogInfo "Encrypting Password"
echo "$MODS_PASSWORD" | openssl rsautl -inkey /var/packages/$SYNOPKG_PKGNAME/etc/image -encrypt > /var/packages/$SYNOPKG_PKGNAME/etc/backup
chmod og-r /var/packages/$SYNOPKG_PKGNAME/etc/backup
fi
else
LogInfo "Don't store Password"
fi
# Create the Symbolic link
LogInfo "Creating nginx Link"
ExecSSH "$MODS_ADMIN" "$MODS_PASSWORD" "$MODS_PORT" "ln -s $SYNOPKG_PKGDEST/ui/dsm.cgi.conf $LINK"
ExitCode=$?
# Check that the link has been created # Check that the link has been created
if [ ! -f $LINK ]; then if [ ! -f $LINK ]; then
PublishInfo ""
PublishInfo "Link Creation failed..."
PublishInfo "Investigate the reason in the Logs"
exit 150
fi
else
PublishInfo "" PublishInfo ""
PublishInfo "Cannot connect via SSH onto the NAS with provided Login/Password." PublishInfo "Link Creation failed..."
PublishInfo "Go back into the Installation Wizard to change your Login/Password." PublishInfo "Investigate the reason in the Logs"
exit 150 return 1
fi fi
fi fi
fi fi
return 0
} }
# Unlink nginx config # Unlink nginx config
function UnlinkNginx() { function UnlinkNginx() {
LogInfo "I am : `whoami`"
if [ $SYNOPKG_PKG_STATUS == "UNINSTALL" ]; then if [ $SYNOPKG_PKG_STATUS == "UNINSTALL" ]; then
LINK="/usr/syno/share/nginx/conf.d/dsm.$SYNOPKG_PKGNAME.conf" LINK="/usr/syno/share/nginx/conf.d/dsm.$SYNOPKG_PKGNAME.conf"
if [ -f $LINK ]; then if [ -f $LINK ]; then
# Retrieve previous credentials if no account received from Wizard sudo /bin/unlink "$LINK"
if [ -z $MODS_ADMIN ] && [ -f /var/packages/$SYNOPKG_PKGNAME/etc/backup ]; then
if [ -f /var/packages/$SYNOPKG_PKGNAME/etc/parameters ]; then
. /var/packages/$SYNOPKG_PKGNAME/etc/parameters
fi
if [ -z $MODS_PASSWORD ]; then
LogInfo "Retrieving previous SSH credentials"
MODS_PASSWORD=$(openssl rsautl -inkey /var/packages/$SYNOPKG_PKGNAME/etc/image -decrypt < /var/packages/$SYNOPKG_PKGNAME/etc/backup)
fi
fi
# Unlink nginx configuration if [ -f $LINK ]; then
LogInfo "Removing nginx Link"
ExecSSH "$MODS_ADMIN" "$MODS_PASSWORD" "$MODS_PORT" "unlink $LINK"
ExitCode=$?
if [ $ExitCode != 0 ]; then
PublishInfo PublishInfo
PublishInfo "Couldn't remove the link '$Link'." PublishInfo "Couldn't remove the link '$Link'."
PublishInfo "This is not a blocking issue but uninstallation is not clean." PublishInfo "This is not a blocking issue but uninstallation is not clean."

View File

@ -5,8 +5,16 @@
StartScript StartScript
LinkNginx LinkNginx
ExitCode=$?
EnableRouterLog if [ $ExitCode == "0" ]; then
EnableRouterLog
fi
EndScript EndScript
exit 0
if [ $ExitCode == "0" ]; then
exit 0
else
exit 150
fi