forked from fbelavenuto/arpl-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b95dbc9
commit aff3c6d
Showing
3 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env ash | ||
|
||
SCRIPT_NAME=$(basename "$0") | ||
TARGET_DIR="/usr/syno/share/nginx" | ||
TARGET_FILE="${TARGET_DIR}/*.mustache" | ||
CURRENT_HTTP_PORT_FILE="${TARGET_DIR}/current_http_port" | ||
CURRENT_HTTPS_PORT_FILE="${TARGET_DIR}/current_https_port" | ||
|
||
usage() { | ||
echo "${script_name} usage:" | ||
echo " ${script_name} HTTP_PORT HTTPS_PORT" | ||
echo " requires two parameters or none" | ||
echo " with no parameter default HTTP_PORT 80 and HTTPS_PORT 443" | ||
echo " The port number must be between 1 and 65535" | ||
exit 0 | ||
} | ||
|
||
is_number() { | ||
[ -n "$1" ] && [ "$1" -eq "$1" ] 2>/dev/null | ||
if [ $? -ne 0 ]; then | ||
return 0 | ||
fi | ||
return 1 | ||
} | ||
|
||
outrange() { | ||
if is_number $1; then | ||
echo "Port number \"$1\" not accepted. The port must be a number" | ||
usage | ||
fi | ||
|
||
if [ $1 -ge 1 ] && [ $1 -le 65535 ]; then | ||
return | ||
else | ||
echo "Port number \"$1\" not accepted. The port number must be between 1 and 65535" | ||
usage | ||
fi | ||
} | ||
|
||
CURRENT_HTTP_PORT=80 | ||
CURRENT_HTTPS_PORT=443 | ||
|
||
if [ -f "${CURRENT_HTTP_PORT_FILE}" ]; then | ||
CURRENT_HTTP_PORT=$(cat "${CURRENT_HTTP_PORT_FILE}") | ||
fi | ||
|
||
if [ -f "${CURRENT_HTTPS_PORT_FILE}" ]; then | ||
CURRENT_HTTPS_PORT=$(cat "${CURRENT_HTTPS_PORT_FILE}") | ||
fi | ||
|
||
if [ "$#" != "0" ] && [ "$#" != "2" ]; then usage; fi | ||
|
||
if [ "$#" -eq "0" ]; then | ||
NEW_HTTP_PORT=${CURRENT_HTTP_PORT} | ||
NEW_HTTPS_PORT=${CURRENT_HTTPS_PORT} | ||
fi | ||
|
||
if [ "$#" -eq "2" ]; then | ||
NEW_HTTP_PORT=$1 | ||
NEW_HTTPS_PORT=$2 | ||
fi | ||
|
||
outrange "${NEW_HTTP_PORT}" | ||
outrange "${NEW_HTTPS_PORT}" | ||
|
||
if [ "${CURRENT_HTTP_PORT}" != "${NEW_HTTP_PORT}" ]; then | ||
sed -i "s/^\([ \t]\+listen[ \t]\+[]:[]*\)${CURRENT_HTTP_PORT}\([^0-9]\)/\1${NEW_HTTP_PORT}\2/" ${TARGET_FILE} | ||
echo ${NEW_HTTP_PORT} >"${CURRENT_HTTP_PORT_FILE}" | ||
echo "Switch port http ${CURRENT_HTTP_PORT} to ${NEW_HTTP_PORT}" | ||
fi | ||
|
||
if [ "${CURRENT_HTTPS_PORT}" != "${NEW_HTTPS_PORT}" ]; then | ||
sed -i "s/^\([ \t]\+listen[ \t]\+[]:[]*\)${CURRENT_HTTPS_PORT}\([^0-9]\)/\1${NEW_HTTPS_PORT}\2/" ${TARGET_FILE} | ||
echo ${NEW_HTTPS_PORT} >"${CURRENT_HTTPS_PORT_FILE}" | ||
echo "Switch port https ${CURRENT_HTTPS_PORT} to ${NEW_HTTPS_PORT}" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env ash | ||
|
||
if [ "${1}" = "late" ]; then | ||
echo "Installing daemon for switchport" | ||
cp -vf /usr/sbin/switchport.sh /tmpRoot/usr/sbin/switchport.sh | ||
shift | ||
|
||
DEST="/tmpRoot/lib/systemd/system/switchport.service" | ||
echo "[Unit]" >${DEST} | ||
echo "Description=Desallocates ports http(s)" >>${DEST} | ||
echo "Before=nginx.service" >>${DEST} | ||
echo >>${DEST} | ||
echo "[Service]" >>${DEST} | ||
echo "Type=oneshot" >>${DEST} | ||
echo "RemainAfterExit=true" >>${DEST} | ||
echo "ExecStart=/usr/sbin/switchport.sh $1 $2" >>${DEST} | ||
echo "ExecStartPost=/bin/systemctl try-restart nginx" >>${DEST} | ||
echo >>${DEST} | ||
echo "[Install]" >>${DEST} | ||
echo "WantedBy=nginx.service" >>${DEST} | ||
|
||
mkdir -vp /tmpRoot/lib/systemd/system/multi-user.target.wants | ||
ln -vsf /lib/systemd/system/switchport.service /tmpRoot/lib/systemd/system/multi-user.target.wants/switchport.service | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
version: 1 | ||
name: switch port | ||
description: "Desallocates ports 80 and 443 and assigns another ports (2580 and 25443 by default)" | ||
all: | ||
install-script: "install.sh" | ||
copy: "all" | ||
available-for: | ||
apollolake-4.4.59: | ||
apollolake-4.4.180: | ||
apollolake-4.4.302: | ||
bromolow-3.10.105: | ||
bromolow-3.10.108: | ||
broadwell-4.4.105: | ||
broadwell-4.4.180: | ||
broadwell-4.4.302: | ||
broadwellnk-4.4.59: | ||
broadwellnk-4.4.180: | ||
broadwellnk-4.4.302: | ||
epyc7002-5.10.55: | ||
denverton-4.4.59: | ||
denverton-4.4.180: | ||
denverton-4.4.302: | ||
geminilake-4.4.59: | ||
geminilake-4.4.180: | ||
geminilake-4.4.302: | ||
purley-4.4.59: | ||
purley-4.4.180: | ||
purley-4.4.302: | ||
r1000-4.4.180: | ||
r1000-4.4.302: | ||
v1000-4.4.59: | ||
v1000-4.4.180: | ||
v1000-4.4.302: |