diff --git a/README.md b/README.md index 89e7d35..7627dc2 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/bfd397624cdf4803a465d4ae1530e7fe)](https://www.codacy.com/app/jackyaz/scMerlin?utm_source=github.com&utm_medium=referral&utm_content=jackyaz/scMerlin&utm_campaign=Badge_Grade) [![Build Status](https://travis-ci.com/jackyaz/scMerlin.svg?branch=master)](https://travis-ci.com/jackyaz/scMerlin) -## v2.0.0 -### Updated on 2020-11-06 +## v2.1.0 +### Updated on 2021-01-04 ## About scMerlin allows you to easily control the most common services/scripts on your router. @@ -23,6 +23,9 @@ Using your preferred SSH client/terminal, copy and paste the following command, /usr/sbin/curl --retry 3 "https://raw.githubusercontent.com/jackyaz/scmerlin/master/scmerlin.sh" -o "/jffs/scripts/scmerlin" && chmod 0755 /jffs/scripts/scmerlin && /jffs/scripts/scmerlin install ``` +## Supported firmware versions +You must be running firmware Merlin 384.15/384.13_4 or Fork 43E5 (or later) [Asuswrt-Merlin](https://asuswrt.lostrealm.ca/) + ## Usage ### WebUI scMerlin can be used via the WebUI, in the Addons section. diff --git a/scmerlin.sh b/scmerlin.sh index cb8280d..820b27b 100644 --- a/scmerlin.sh +++ b/scmerlin.sh @@ -18,16 +18,17 @@ readonly SCRIPT_NAME="scMerlin" #shellcheck disable=SC2018 readonly SCRIPT_NAME_LOWER=$(echo $SCRIPT_NAME | tr 'A-Z' 'a-z' | sed 's/d//') #shellcheck disable=SC2034 -readonly SCM_VERSION="v2.0.0" -readonly SCRIPT_VERSION="v2.0.0" +readonly SCM_VERSION="v2.1.0" +readonly SCRIPT_VERSION="v2.1.0" readonly SCRIPT_BRANCH="master" -readonly SCRIPT_REPO="https://raw.githubusercontent.com/jackyaz/""$SCRIPT_NAME""/""$SCRIPT_BRANCH" +readonly SCRIPT_REPO="https://raw.githubusercontent.com/jackyaz/$SCRIPT_NAME/$SCRIPT_BRANCH" readonly SCRIPT_DIR="/jffs/addons/$SCRIPT_NAME_LOWER.d" readonly SCRIPT_WEBPAGE_DIR="$(readlink /www/user)" readonly SCRIPT_WEB_DIR="$SCRIPT_WEBPAGE_DIR/$SCRIPT_NAME_LOWER" readonly SHARED_DIR="/jffs/addons/shared-jy" readonly SHARED_REPO="https://raw.githubusercontent.com/jackyaz/shared-jy/master" readonly SHARED_WEB_DIR="$SCRIPT_WEBPAGE_DIR/shared-jy" +readonly DISABLE_USB_FEATURES_FILE="$SCRIPT_DIR/.usbdisabled" [ -z "$(nvram get odmpid)" ] && ROUTER_MODEL=$(nvram get productid) || ROUTER_MODEL=$(nvram get odmpid) ### End of script variables ### @@ -49,18 +50,26 @@ Print_Output(){ fi } +Firmware_Version_Check(){ + if nvram get rc_support | grep -qF "am_addons"; then + return 0 + else + return 1 + fi +} + ### Code for these functions inspired by https://github.com/Adamm00 - credit to @Adamm ### Check_Lock(){ if [ -f "/tmp/$SCRIPT_NAME_LOWER.lock" ]; then ageoflock=$(($(date +%s) - $(date +%s -r "/tmp/$SCRIPT_NAME_LOWER.lock"))) if [ "$ageoflock" -gt 60 ]; then - Print_Output "true" "Stale lock file found (>60 seconds old) - purging lock" "$ERR" + Print_Output true "Stale lock file found (>60 seconds old) - purging lock" "$ERR" kill "$(sed -n '1p' "/tmp/$SCRIPT_NAME_LOWER.lock")" >/dev/null 2>&1 Clear_Lock echo "$$" > "/tmp/$SCRIPT_NAME_LOWER.lock" return 0 else - Print_Output "true" "Lock file found (age: $ageoflock seconds)" "$ERR" + Print_Output true "Lock file found (age: $ageoflock seconds)" "$ERR" if [ -z "$1" ]; then exit 1 else @@ -81,7 +90,7 @@ Clear_Lock(){ ############################################## Set_Version_Custom_Settings(){ - SETTINGSFILE="/jffs/addons/custom_settings.txt" + SETTINGSFILE=/jffs/addons/custom_settings.txt case "$1" in local) if [ -f "$SETTINGSFILE" ]; then @@ -116,11 +125,11 @@ Update_Check(){ echo 'var updatestatus = "InProgress";' > "$SCRIPT_WEB_DIR/detect_update.js" doupdate="false" localver=$(grep "SCRIPT_VERSION=" /jffs/scripts/"$SCRIPT_NAME_LOWER" | grep -m1 -oE 'v[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})') - /usr/sbin/curl -fsL --retry 3 "$SCRIPT_REPO/$SCRIPT_NAME_LOWER.sh" | grep -qF "jackyaz" || { Print_Output "true" "404 error detected - stopping update" "$ERR"; return 1; } + /usr/sbin/curl -fsL --retry 3 "$SCRIPT_REPO/$SCRIPT_NAME_LOWER.sh" | grep -qF "jackyaz" || { Print_Output true "404 error detected - stopping update" "$ERR"; return 1; } serverver=$(/usr/sbin/curl -fsL --retry 3 "$SCRIPT_REPO/$SCRIPT_NAME_LOWER.sh" | grep "SCRIPT_VERSION=" | grep -m1 -oE 'v[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})') if [ "$localver" != "$serverver" ]; then doupdate="version" - Set_Version_Custom_Settings "server" "$serverver" + Set_Version_Custom_Settings server "$serverver" echo 'var updatestatus = "'"$serverver"'";' > "$SCRIPT_WEB_DIR/detect_update.js" else localmd5="$(md5sum "/jffs/scripts/$SCRIPT_NAME_LOWER" | awk '{print $1}')" @@ -132,7 +141,7 @@ Update_Check(){ fi fi if [ "$doupdate" = "false" ]; then - echo 'var updatestatus = "None";' > "$SCRIPT_WEB_DIR/detect_update.js" + echo 'var updatestatus = "None";' > "$SCRIPT_WEB_DIR/detect_update.js" fi echo "$doupdate,$localver,$serverver" } @@ -145,48 +154,53 @@ Update_Version(){ serverver="$(echo "$updatecheckresult" | cut -f3 -d',')" if [ "$isupdate" = "version" ]; then - Print_Output "true" "New version of $SCRIPT_NAME available - updating to $serverver" "$PASS" + Print_Output true "New version of $SCRIPT_NAME available - updating to $serverver" "$PASS" elif [ "$isupdate" = "md5" ]; then - Print_Output "true" "MD5 hash of $SCRIPT_NAME does not match - downloading updated $serverver" "$PASS" + Print_Output true "MD5 hash of $SCRIPT_NAME does not match - downloading updated $serverver" "$PASS" fi - Update_File "scmerlin_www.asp" - Update_File "shared-jy.tar.gz" - Update_File "tailtop" - Update_File "tailtopd" - Update_File "S99tailtop" + Update_File scmerlin_www.asp + Update_File shared-jy.tar.gz + + if [ ! -f "$DISABLE_USB_FEATURES_FILE" ]; then + Update_File tailtop + Update_File tailtopd + Update_File S99tailtop + fi if [ "$isupdate" != "false" ]; then - /usr/sbin/curl -fsL --retry 3 "$SCRIPT_REPO/$SCRIPT_NAME_LOWER.sh" -o "/jffs/scripts/$SCRIPT_NAME_LOWER" && Print_Output "true" "$SCRIPT_NAME successfully updated" + /usr/sbin/curl -fsL --retry 3 "$SCRIPT_REPO/$SCRIPT_NAME_LOWER.sh" -o "/jffs/scripts/$SCRIPT_NAME_LOWER" && Print_Output true "$SCRIPT_NAME successfully updated" chmod 0755 /jffs/scripts/"$SCRIPT_NAME_LOWER" Clear_Lock if [ -z "$1" ]; then - exec "$0" "setversion" + exec "$0" setversion elif [ "$1" = "unattended" ]; then - exec "$0" "setversion" "unattended" + exec "$0" setversion unattended fi exit 0 else - Print_Output "true" "No new version - latest is $localver" "$WARN" + Print_Output true "No new version - latest is $localver" "$WARN" Clear_Lock fi fi if [ "$1" = "force" ]; then serverver=$(/usr/sbin/curl -fsL --retry 3 "$SCRIPT_REPO/$SCRIPT_NAME_LOWER.sh" | grep "SCRIPT_VERSION=" | grep -m1 -oE 'v[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})') - Print_Output "true" "Downloading latest version ($serverver) of $SCRIPT_NAME" "$PASS" - Update_File "scmerlin_www.asp" - Update_File "shared-jy.tar.gz" - Update_File "tailtop" - Update_File "tailtopd" - Update_File "S99tailtop" - /usr/sbin/curl -fsL --retry 3 "$SCRIPT_REPO/$SCRIPT_NAME_LOWER.sh" -o "/jffs/scripts/$SCRIPT_NAME_LOWER" && Print_Output "true" "$SCRIPT_NAME successfully updated" + Print_Output true "Downloading latest version ($serverver) of $SCRIPT_NAME" "$PASS" + Update_File scmerlin_www.asp + Update_File shared-jy.tar.gz + if [ ! -f "$DISABLE_USB_FEATURES_FILE" ]; then + Update_File tailtop + Update_File tailtopd + Update_File S99tailtop + fi + /usr/sbin/curl -fsL --retry 3 "$SCRIPT_REPO/$SCRIPT_NAME_LOWER.sh" -o "/jffs/scripts/$SCRIPT_NAME_LOWER" && Print_Output true "$SCRIPT_NAME successfully updated" chmod 0755 /jffs/scripts/"$SCRIPT_NAME_LOWER" Clear_Lock if [ -z "$2" ]; then - exec "$0" "setversion" + exec "$0" setversion elif [ "$2" = "unattended" ]; then - exec "$0" "setversion" "unattended" + exec "$0" setversion unattended fi exit 0 fi @@ -203,7 +217,7 @@ Update_File(){ rm -f "$SCRIPT_WEBPAGE_DIR/$MyPage" 2>/dev/null fi Download_File "$SCRIPT_REPO/$1" "$SCRIPT_DIR/$1" - Print_Output "true" "New version of $1 downloaded" "$PASS" + Print_Output true "New version of $1 downloaded" "$PASS" Mount_WebUI fi rm -f "$tmpfile" @@ -213,7 +227,7 @@ Update_File(){ Download_File "$SHARED_REPO/$1.md5" "$SHARED_DIR/$1.md5" tar -xzf "$SHARED_DIR/$1" -C "$SHARED_DIR" rm -f "$SHARED_DIR/$1" - Print_Output "true" "New version of $1 downloaded" "$PASS" + Print_Output true "New version of $1 downloaded" "$PASS" else localmd5="$(cat "$SHARED_DIR/$1.md5")" remotemd5="$(curl -fsL --retry 3 "$SHARED_REPO/$1.md5")" @@ -222,7 +236,7 @@ Update_File(){ Download_File "$SHARED_REPO/$1.md5" "$SHARED_DIR/$1.md5" tar -xzf "$SHARED_DIR/$1" -C "$SHARED_DIR" rm -f "$SHARED_DIR/$1" - Print_Output "true" "New version of $1 downloaded" "$PASS" + Print_Output true "New version of $1 downloaded" "$PASS" fi fi elif [ "$1" = "S99tailtop" ]; then @@ -236,7 +250,7 @@ Update_File(){ Download_File "$SCRIPT_REPO/$1" "/opt/etc/init.d/$1" chmod 0755 "/opt/etc/init.d/$1" /opt/etc/init.d/S99tailtop start >/dev/null 2>&1 - Print_Output "true" "New version of $1 downloaded" "$PASS" + Print_Output true "New version of $1 downloaded" "$PASS" fi rm -f "$tmpfile" elif [ "$1" = "tailtop" ] || [ "$1" = "tailtopd" ]; then @@ -249,7 +263,7 @@ Update_File(){ fi Download_File "$SCRIPT_REPO/$1" "$SCRIPT_DIR/$1" chmod 0755 "$SCRIPT_DIR/$1" - Print_Output "true" "New version of $1 downloaded" "$PASS" + Print_Output true "New version of $1 downloaded" "$PASS" /opt/etc/init.d/S99tailtop start >/dev/null 2>&1 fi rm -f "$tmpfile" @@ -264,7 +278,7 @@ Validate_Number(){ else formatted="$(echo "$1" | sed -e 's/|/ /g')" if [ -z "$3" ]; then - Print_Output "false" "$formatted - $2 is not a number" "$ERR" + Print_Output false "$formatted - $2 is not a number" "$ERR" fi return 1 fi @@ -292,6 +306,7 @@ Create_Symlinks(){ rm -rf "${SCRIPT_WEB_DIR:?}/"* 2>/dev/null ln -s /tmp/scmerlin-top "$SCRIPT_WEB_DIR/top.htm" 2>/dev/null + ln -s "$DISABLE_USB_FEATURES_FILE" "$SCRIPT_WEB_DIR/usbdisabled.htm" 2>/dev/null if [ ! -d "$SHARED_WEB_DIR" ]; then ln -s "$SHARED_DIR" "$SHARED_WEB_DIR" 2>/dev/null @@ -304,7 +319,7 @@ Auto_ServiceEvent(){ if [ -f /jffs/scripts/service-event ]; then STARTUPLINECOUNT=$(grep -i -c '# '"$SCRIPT_NAME" /jffs/scripts/service-event) # shellcheck disable=SC2016 - STARTUPLINECOUNTEX=$(grep -i -cx "/jffs/scripts/$SCRIPT_NAME_LOWER service_event"' "$1" "$2" &'' # '"$SCRIPT_NAME" /jffs/scripts/service-event) + STARTUPLINECOUNTEX=$(grep -i -cx "/jffs/scripts/$SCRIPT_NAME_LOWER service_event"' "$@" & # '"$SCRIPT_NAME" /jffs/scripts/service-event) if [ "$STARTUPLINECOUNT" -gt 1 ] || { [ "$STARTUPLINECOUNTEX" -eq 0 ] && [ "$STARTUPLINECOUNT" -gt 0 ]; }; then sed -i -e '/# '"$SCRIPT_NAME"'/d' /jffs/scripts/service-event @@ -312,13 +327,13 @@ Auto_ServiceEvent(){ if [ "$STARTUPLINECOUNTEX" -eq 0 ]; then # shellcheck disable=SC2016 - echo "/jffs/scripts/$SCRIPT_NAME_LOWER service_event"' "$1" "$2" &'' # '"$SCRIPT_NAME" >> /jffs/scripts/service-event + echo "/jffs/scripts/$SCRIPT_NAME_LOWER service_event"' "$@" & # '"$SCRIPT_NAME" >> /jffs/scripts/service-event fi else echo "#!/bin/sh" > /jffs/scripts/service-event echo "" >> /jffs/scripts/service-event # shellcheck disable=SC2016 - echo "/jffs/scripts/$SCRIPT_NAME_LOWER service_event"' "$1" "$2" &'' # '"$SCRIPT_NAME" >> /jffs/scripts/service-event + echo "/jffs/scripts/$SCRIPT_NAME_LOWER service_event"' "$@" & # '"$SCRIPT_NAME" >> /jffs/scripts/service-event chmod 0755 /jffs/scripts/service-event fi ;; @@ -339,23 +354,84 @@ Auto_Startup(){ create) if [ -f /jffs/scripts/services-start ]; then STARTUPLINECOUNT=$(grep -i -c '# '"$SCRIPT_NAME" /jffs/scripts/services-start) - STARTUPLINECOUNTEX=$(grep -i -cx "/jffs/scripts/$SCRIPT_NAME_LOWER startup &"' # '"$SCRIPT_NAME" /jffs/scripts/services-start) + + if [ "$STARTUPLINECOUNT" -gt 0 ]; then + sed -i -e '/# '"$SCRIPT_NAME"'/d' /jffs/scripts/services-start + fi + fi + if [ -f /jffs/scripts/post-mount ]; then + STARTUPLINECOUNT=$(grep -i -c '# '"$SCRIPT_NAME" /jffs/scripts/post-mount) + STARTUPLINECOUNTEX=$(grep -i -cx "/jffs/scripts/$SCRIPT_NAME_LOWER startup"' "$@" & # '"$SCRIPT_NAME" /jffs/scripts/post-mount) + + if [ "$STARTUPLINECOUNT" -gt 1 ] || { [ "$STARTUPLINECOUNTEX" -eq 0 ] && [ "$STARTUPLINECOUNT" -gt 0 ]; }; then + sed -i -e '/# '"$SCRIPT_NAME"'/d' /jffs/scripts/post-mount + fi + + if [ "$STARTUPLINECOUNTEX" -eq 0 ]; then + echo "/jffs/scripts/$SCRIPT_NAME_LOWER startup"' "$@" & # '"$SCRIPT_NAME" >> /jffs/scripts/post-mount + fi + else + echo "#!/bin/sh" > /jffs/scripts/post-mount + echo "" >> /jffs/scripts/post-mount + echo "/jffs/scripts/$SCRIPT_NAME_LOWER startup"' "$@" & # '"$SCRIPT_NAME" >> /jffs/scripts/post-mount + chmod 0755 /jffs/scripts/post-mount + fi + ;; + delete) + if [ -f /jffs/scripts/services-start ]; then + STARTUPLINECOUNT=$(grep -i -c '# '"$SCRIPT_NAME" /jffs/scripts/services-start) + + if [ "$STARTUPLINECOUNT" -gt 0 ]; then + sed -i -e '/# '"$SCRIPT_NAME"'/d' /jffs/scripts/services-start + fi + fi + if [ -f /jffs/scripts/post-mount ]; then + STARTUPLINECOUNT=$(grep -i -c '# '"$SCRIPT_NAME" /jffs/scripts/post-mount) + + if [ "$STARTUPLINECOUNT" -gt 0 ]; then + sed -i -e '/# '"$SCRIPT_NAME"'/d' /jffs/scripts/post-mount + fi + fi + ;; + esac +} + +Auto_Startup_NoUSB(){ + case $1 in + create) + if [ -f /jffs/scripts/post-mount ]; then + STARTUPLINECOUNT=$(grep -i -c '# '"$SCRIPT_NAME" /jffs/scripts/post-mount) + + if [ "$STARTUPLINECOUNT" -gt 0 ]; then + sed -i -e '/# '"$SCRIPT_NAME"'/d' /jffs/scripts/post-mount + fi + fi + if [ -f /jffs/scripts/services-start ]; then + STARTUPLINECOUNT=$(grep -i -c '# '"$SCRIPT_NAME" /jffs/scripts/services-start) + STARTUPLINECOUNTEX=$(grep -i -cx "/jffs/scripts/$SCRIPT_NAME_LOWER startup"' & # '"$SCRIPT_NAME" /jffs/scripts/services-start) if [ "$STARTUPLINECOUNT" -gt 1 ] || { [ "$STARTUPLINECOUNTEX" -eq 0 ] && [ "$STARTUPLINECOUNT" -gt 0 ]; }; then sed -i -e '/# '"$SCRIPT_NAME"'/d' /jffs/scripts/services-start fi if [ "$STARTUPLINECOUNTEX" -eq 0 ]; then - echo "/jffs/scripts/$SCRIPT_NAME_LOWER startup &"' # '"$SCRIPT_NAME" >> /jffs/scripts/services-start + echo "/jffs/scripts/$SCRIPT_NAME_LOWER startup"' & # '"$SCRIPT_NAME" >> /jffs/scripts/services-start fi else echo "#!/bin/sh" > /jffs/scripts/services-start echo "" >> /jffs/scripts/services-start - echo "/jffs/scripts/$SCRIPT_NAME_LOWER startup &"' # '"$SCRIPT_NAME" >> /jffs/scripts/services-start + echo "/jffs/scripts/$SCRIPT_NAME_LOWER startup"' & # '"$SCRIPT_NAME" >> /jffs/scripts/services-start chmod 0755 /jffs/scripts/services-start fi ;; delete) + if [ -f /jffs/scripts/post-mount ]; then + STARTUPLINECOUNT=$(grep -i -c '# '"$SCRIPT_NAME" /jffs/scripts/post-mount) + + if [ "$STARTUPLINECOUNT" -gt 0 ]; then + sed -i -e '/# '"$SCRIPT_NAME"'/d' /jffs/scripts/post-mount + fi + fi if [ -f /jffs/scripts/services-start ]; then STARTUPLINECOUNT=$(grep -i -c '# '"$SCRIPT_NAME" /jffs/scripts/services-start) @@ -367,7 +443,6 @@ Auto_Startup(){ esac } - Download_File(){ /usr/sbin/curl -fsL --retry 3 "$1" -o "$2" } @@ -388,17 +463,17 @@ Get_WebUI_Page(){ Mount_WebUI(){ Get_WebUI_Page "$SCRIPT_DIR/scmerlin_www.asp" if [ "$MyPage" = "none" ]; then - Print_Output "true" "Unable to mount $SCRIPT_NAME WebUI page, exiting" "$CRIT" + Print_Output true "Unable to mount $SCRIPT_NAME WebUI page, exiting" "$CRIT" Clear_Lock exit 1 fi - Print_Output "true" "Mounting $SCRIPT_NAME WebUI page as $MyPage" "$PASS" + Print_Output true "Mounting $SCRIPT_NAME WebUI page as $MyPage" "$PASS" cp -f "$SCRIPT_DIR/scmerlin_www.asp" "$SCRIPT_WEBPAGE_DIR/$MyPage" echo "scMerlin" > "$SCRIPT_WEBPAGE_DIR/$(echo $MyPage | cut -f1 -d'.').title" if [ "$(uname -o)" = "ASUSWRT-Merlin" ]; then - if [ ! -f "/tmp/index_style.css" ]; then - cp -f "/www/index_style.css" "/tmp/" + if [ ! -f /tmp/index_style.css ]; then + cp -f /www/index_style.css /tmp/ fi if ! grep -q '.menu_Addons' /tmp/index_style.css ; then @@ -408,8 +483,8 @@ Mount_WebUI(){ umount /www/index_style.css 2>/dev/null mount -o bind /tmp/index_style.css /www/index_style.css - if [ ! -f "/tmp/menuTree.js" ]; then - cp -f "/www/require/modules/menuTree.js" "/tmp/" + if [ ! -f /tmp/menuTree.js ]; then + cp -f /www/require/modules/menuTree.js /tmp/ fi sed -i "\\~$MyPage~d" /tmp/menuTree.js @@ -429,10 +504,39 @@ Mount_WebUI(){ fi } -Shortcut_SCM(){ +ToggleUSBFeatures(){ + case "$1" in + enable) + rm -f "$DISABLE_USB_FEATURES_FILE" + Auto_Startup_NoUSB delete 2>/dev/null + Auto_Startup create 2>/dev/null + Update_File tailtop + Update_File tailtopd + Update_File S99tailtop + ;; + disable) + touch "$DISABLE_USB_FEATURES_FILE" + Auto_Startup delete 2>/dev/null + Auto_Startup_NoUSB create 2>/dev/null + /opt/etc/init.d/S99tailtop stop + rm -f "$SCRIPT_DIR/tailtop" + rm -f "$SCRIPT_DIR/tailtopd" + rm -f /opt/etc/init.d/S99tailtop + ;; + check) + if [ ! -f "$DISABLE_USB_FEATURES_FILE" ]; then + echo "ENABLED" + else + echo "DISABLED" + fi + ;; + esac +} + +Shortcut_Script(){ case $1 in create) - if [ -d "/opt/bin" ] && [ ! -f "/opt/bin/$SCRIPT_NAME_LOWER" ] && [ -f "/jffs/scripts/$SCRIPT_NAME_LOWER" ]; then + if [ -d /opt/bin ] && [ ! -f "/opt/bin/$SCRIPT_NAME_LOWER" ] && [ -f "/jffs/scripts/$SCRIPT_NAME_LOWER" ]; then ln -s /jffs/scripts/"$SCRIPT_NAME_LOWER" /opt/bin chmod 0755 /opt/bin/"$SCRIPT_NAME_LOWER" fi @@ -448,7 +552,7 @@ Shortcut_SCM(){ PressEnter(){ while true; do printf "Press enter to continue..." - read -r "key" + read -r key case "$key" in *) break @@ -500,7 +604,7 @@ MainMenu(){ printf "\\e[1m(selecting an option will restart the VPN Client)\\e[0m\\n\\n" vpnclientnum=1 while [ "$vpnclientnum" -lt 6 ]; do - printf "vc%s. VPN Client %s (%s)\\n" "$vpnclientnum" "$vpnclientnum" "$(nvram get vpn_client"$vpnclientnum"_desc)" + printf "vc%s. VPN Client %s (%s)\\n" "$vpnclientnum" "$vpnclientnum" "$(nvram get vpn_client"$vpnclientnum"_desc)" vpnclientnum=$((vpnclientnum + 1)) done fi @@ -513,18 +617,18 @@ MainMenu(){ printf "\\n\\e[1mVPN Servers\\e[0m\\n" printf "\\e[1m(selecting an option will restart the VPN Server)\\e[0m\\n\\n" vpnservernum=1 - while [ "$vpnservernum" -lt "3" ]; do + while [ "$vpnservernum" -lt 3 ]; do vpnsdesc="" if ! nvram get vpn_serverx_start | grep -q "$vpnservernum"; then vpnsdesc="(Not configured)" fi - printf "vs%s. VPN Server %s %s\\n" "$vpnservernum" "$vpnservernum" "$vpnsdesc" + printf "vs%s. VPN Server %s %s\\n" "$vpnservernum" "$vpnservernum" "$vpnsdesc" vpnservernum=$((vpnservernum + 1)) done fi if [ -f /opt/bin/opkg ]; then printf "\\n\\e[1mEntware\\e[0m\\n\\n" - printf "et. Restart all Entware scripts\\n" + printf "et. Restart all Entware scripts\\n" fi printf "\\n\\e[1mRouter\\e[0m\\n\\n" printf "c. View running processes\\n" @@ -532,6 +636,7 @@ MainMenu(){ printf "t. View router temperatures\n" printf "r. Reboot router\\n\\n" printf "\\e[1mOther\\e[0m\\n\\n" + printf "usb. Toggle USB features (list of running processes in WebUI)\\n Currently: \\e[1m%s\\e[0m\\n\\n" "$(ToggleUSBFeatures check)" printf "u. Check for updates\\n" printf "uf. Update %s with latest version (force update)\\n\\n" "$SCRIPT_NAME" printf "e. Exit %s\\n\\n" "$SCRIPT_NAME" @@ -541,7 +646,7 @@ MainMenu(){ printf "\\n" while true; do printf "Choose an option: " - read -r "menu" + read -r menu case "$menu" in 1) printf "\\n" @@ -553,7 +658,7 @@ MainMenu(){ printf "\\n" while true; do printf "\\n\\e[1mInternet connection will take 30s-60s to reconnect. Continue? (y/n)\\e[0m\\n" - read -r "confirm" + read -r confirm case "$confirm" in y|Y) service restart_wan >/dev/null 2>&1 @@ -581,7 +686,7 @@ MainMenu(){ ;; 5) ENABLED_FTP="$(nvram get enable_ftp)" - if ! Validate_Number "" "$ENABLED_FTP" "silent"; then ENABLED_FTP=0; fi + if ! Validate_Number "" "$ENABLED_FTP" silent; then ENABLED_FTP=0; fi if [ "$ENABLED_FTP" -eq 1 ]; then printf "\\n" service restart_ftpd >/dev/null 2>&1 @@ -593,7 +698,7 @@ MainMenu(){ ;; 6) ENABLED_SAMBA="$(nvram get enable_samba)" - if ! Validate_Number "" "$ENABLED_SAMBA" "silent"; then ENABLED_SAMBA=0; fi + if ! Validate_Number "" "$ENABLED_SAMBA" silent; then ENABLED_SAMBA=0; fi if [ "$ENABLED_SAMBA" -eq 1 ]; then printf "\\n" service restart_samba >/dev/null 2>&1 @@ -605,7 +710,7 @@ MainMenu(){ ;; 7) ENABLED_DDNS="$(nvram get ddns_enable_x)" - if ! Validate_Number "" "$ENABLED_DDNS" "silent"; then ENABLED_DDNS=0; fi + if ! Validate_Number "" "$ENABLED_DDNS" silent; then ENABLED_DDNS=0; fi if [ "$ENABLED_DDNS" -eq 1 ]; then printf "\\n" service restart_ddns >/dev/null 2>&1 @@ -617,14 +722,14 @@ MainMenu(){ ;; 8) ENABLED_NTPD="$(nvram get ntpd_enable)" - if ! Validate_Number "" "$ENABLED_NTPD" "silent"; then ENABLED_NTPD=0; fi + if ! Validate_Number "" "$ENABLED_NTPD" silent; then ENABLED_NTPD=0; fi if [ "$ENABLED_NTPD" -eq 1 ]; then printf "\\n" service restart_time >/dev/null 2>&1 - elif [ -f "/opt/etc/init.d/S77ntpd" ]; then + elif [ -f /opt/etc/init.d/S77ntpd ]; then printf "\\n" /opt/etc/init.d/S77ntpd restart - elif [ -f "/opt/etc/init.d/S77chronyd" ]; then + elif [ -f /opt/etc/init.d/S77chronyd ]; then printf "\\n" /opt/etc/init.d/S77chronyd restart else @@ -706,10 +811,10 @@ MainMenu(){ et) printf "\\n" if [ -f /opt/bin/opkg ]; then - if Check_Lock "menu"; then + if Check_Lock menu; then while true; do printf "\\n\\e[1mAre you sure you want to restart all Entware scripts? (y/n)\\e[0m\\n" - read -r "confirm" + read -r confirm case "$confirm" in y|Y) /opt/etc/init.d/rc.unslung restart @@ -738,7 +843,7 @@ MainMenu(){ program="" while true; do printf "\\n\\e[1mWould you like to install htop (enhanced version of top)? (y/n)\\e[0m\\n" - read -r "confirm" + read -r confirm case "$confirm" in y|Y) program="htop" @@ -795,14 +900,14 @@ MainMenu(){ ;; r) printf "\\n" - if Check_Lock "menu"; then + if Check_Lock menu; then while true; do if [ "$ROUTER_MODEL" = "RT-AC86U" ]; then printf "\\n\\e[1m\\e[33mRemote reboots are not recommend for %s\\e[0m" "$ROUTER_MODEL" printf "\\n\\e[1m\\e[33mSome %s fail to reboot correctly and require a manual power cycle\\e[0m\\n" "$ROUTER_MODEL" fi printf "\\n\\e[1mAre you sure you want to reboot? (y/n)\\e[0m\\n" - read -r "confirm" + read -r confirm case "$confirm" in y|Y) service reboot >/dev/null 2>&1 @@ -818,9 +923,14 @@ MainMenu(){ PressEnter break ;; + usb) + printf "\\n" + Menu_ToggleUSBFeatures + break + ;; u) printf "\\n" - if Check_Lock "menu"; then + if Check_Lock menu; then Menu_Update fi PressEnter @@ -828,7 +938,7 @@ MainMenu(){ ;; uf) printf "\\n" - if Check_Lock "menu"; then + if Check_Lock menu; then Menu_ForceUpdate fi PressEnter @@ -840,19 +950,17 @@ MainMenu(){ exit 0 ;; z) - while true; do - printf "\\n\\e[1mAre you sure you want to uninstall %s? (y/n)\\e[0m\\n" "$SCRIPT_NAME" - read -r "confirm" - case "$confirm" in - y|Y) - Menu_Uninstall - exit 0 - ;; - *) - break - ;; - esac - done + printf "\\n\\e[1mAre you sure you want to uninstall %s? (y/n)\\e[0m\\n" "$SCRIPT_NAME" + read -r confirm + case "$confirm" in + y|Y) + Menu_Uninstall + exit 0 + ;; + *) + : + ;; + esac ;; *) printf "\\nPlease choose a valid option\\n\\n" @@ -870,9 +978,30 @@ Check_Requirements(){ if [ "$(nvram get jffs2_scripts)" -ne 1 ]; then nvram set jffs2_scripts=1 nvram commit - Print_Output "true" "Custom JFFS Scripts enabled" "$WARN" + Print_Output true "Custom JFFS Scripts enabled" "$WARN" + fi + + if ! Firmware_Version_Check; then + Print_Output true "Unsupported firmware version detected" "$ERR" + Print_Output true "$SCRIPT_NAME requires Merlin 384.15/384.13_4 or Fork 43E5 (or later)" "$ERR" + CHECKSFAILED="true" fi + printf "\\n\\e[1mWould you like to enable USB Features (list of running processes in WebUI) (y/n)?\\nThis requires a USB device plugged into router for Entware\\e[0m\\n" + read -r confirm + case "$confirm" in + y|Y) + if [ ! -f /opt/bin/opkg ]; then + touch "$DISABLE_USB_FEATURES_FILE" + Print_Output true "Entware not detected, USB features disabled" "$WARN" + fi + ;; + *) + touch "$DISABLE_USB_FEATURES_FILE" + Print_Output true "USB features can be enabled later via the WebUI or command line" "$WARN" + ;; + esac + if [ "$CHECKSFAILED" = "false" ]; then return 0 else @@ -881,31 +1010,38 @@ Check_Requirements(){ } Menu_Install(){ - Print_Output "true" "Welcome to $SCRIPT_NAME $SCRIPT_VERSION, a script by JackYaz" + Print_Output true "Welcome to $SCRIPT_NAME $SCRIPT_VERSION, a script by JackYaz" sleep 1 - Print_Output "true" "Checking your router meets the requirements for $SCRIPT_NAME" + Print_Output true "Checking your router meets the requirements for $SCRIPT_NAME" if ! Check_Requirements; then - Print_Output "true" "Requirements for $SCRIPT_NAME not met, please see above for the reason(s)" "$CRIT" + Print_Output true "Requirements for $SCRIPT_NAME not met, please see above for the reason(s)" "$CRIT" PressEnter Clear_Lock rm -f "/jffs/scripts/$SCRIPT_NAME_LOWER" 2>/dev/null + rm -rf "$SCRIPT_DIR" 2>/dev/null exit 1 fi Create_Dirs - Shortcut_SCM create - Set_Version_Custom_Settings "local" + Shortcut_Script create + Set_Version_Custom_Settings local Create_Symlinks - Auto_Startup create 2>/dev/null + if [ ! -f "$DISABLE_USB_FEATURES_FILE" ]; then + Auto_Startup create 2>/dev/null + else + Auto_Startup_NoUSB create 2>/dev/null + fi Auto_ServiceEvent create 2>/dev/null - Update_File "scmerlin_www.asp" - Update_File "shared-jy.tar.gz" - Update_File "tailtop" - Update_File "tailtopd" - Update_File "S99tailtop" + Update_File scmerlin_www.asp + Update_File shared-jy.tar.gz + if [ ! -f "$DISABLE_USB_FEATURES_FILE" ]; then + Update_File tailtop + Update_File tailtopd + Update_File S99tailtop + fi Clear_Lock ScriptHeader @@ -914,15 +1050,31 @@ Menu_Install(){ Menu_Startup(){ Create_Dirs - Set_Version_Custom_Settings "local" + Set_Version_Custom_Settings local Create_Symlinks - Auto_Startup create 2>/dev/null + if [ ! -f "$DISABLE_USB_FEATURES_FILE" ]; then + Auto_Startup create 2>/dev/null + else + Auto_Startup_NoUSB create 2>/dev/null + fi Auto_ServiceEvent create 2>/dev/null - Shortcut_SCM create + Shortcut_Script create Mount_WebUI Clear_Lock } +Menu_ToggleUSBFeatures(){ + if [ -z "$1" ]; then + if [ "$(ToggleUSBFeatures check)" = "ENABLED" ]; then + ToggleUSBFeatures disable + elif [ "$(ToggleUSBFeatures check)" = "DISABLED" ]; then + ToggleUSBFeatures enable + fi + else + ToggleUSBFeatures "$1" + fi +} + Menu_Update(){ Update_Version Clear_Lock @@ -934,13 +1086,17 @@ Menu_ForceUpdate(){ } Menu_Uninstall(){ - Print_Output "true" "Removing $SCRIPT_NAME..." "$PASS" - Shortcut_SCM delete - Auto_Startup delete 2>/dev/null + Print_Output true "Removing $SCRIPT_NAME..." "$PASS" + Shortcut_Script delete + if [ ! -f "$DISABLE_USB_FEATURES_FILE" ]; then + Auto_Startup delete 2>/dev/null + else + Auto_Startup_NoUSB delete 2>/dev/null + fi Auto_ServiceEvent delete 2>/dev/null Get_WebUI_Page "$SCRIPT_DIR/scmerlin_www.asp" - if [ -n "$MyPage" ] && [ "$MyPage" != "none" ] && [ -f "/tmp/menuTree.js" ]; then + if [ -n "$MyPage" ] && [ "$MyPage" != "none" ] && [ -f /tmp/menuTree.js ]; then sed -i "\\~$MyPage~d" /tmp/menuTree.js umount /www/require/modules/menuTree.js mount -o bind /tmp/menuTree.js /www/require/modules/menuTree.js @@ -951,38 +1107,33 @@ Menu_Uninstall(){ /opt/etc/init.d/S99tailtop stop >/dev/null 2>&1 sleep 5 - rm -f "/opt/etc/init.d/S99tailtop" 2>/dev/null + rm -f /opt/etc/init.d/S99tailtop 2>/dev/null rm -f "$SCRIPT_DIR/tailtop"* 2>/dev/null rm -rf "$SCRIPT_DIR" rm -f "/jffs/scripts/$SCRIPT_NAME_LOWER" 2>/dev/null Clear_Lock - Print_Output "true" "Uninstall completed" "$PASS" + Print_Output true "Uninstall completed" "$PASS" } NTP_Ready(){ - if [ "$1" = "service_event" ]; then - if [ -n "$2" ] && [ "$(echo "$3" | grep -c "$SCRIPT_NAME_LOWER")" -eq 0 ]; then - exit 0 - fi - fi - if [ "$(nvram get ntp_ready)" = "0" ]; then - ntpwaitcount="0" + if [ "$(nvram get ntp_ready)" -eq 0 ]; then Check_Lock - while [ "$(nvram get ntp_ready)" = "0" ] && [ "$ntpwaitcount" -lt "300" ]; do + ntpwaitcount="0" + while [ "$(nvram get ntp_ready)" -eq 0 ] && [ "$ntpwaitcount" -lt 300 ]; do ntpwaitcount="$((ntpwaitcount + 1))" - if [ "$ntpwaitcount" = "60" ]; then - Print_Output "true" "Waiting for NTP to sync..." "$WARN" + if [ "$ntpwaitcount" -eq 60 ]; then + Print_Output true "Waiting for NTP to sync..." "$WARN" fi sleep 1 done - if [ "$ntpwaitcount" -ge "300" ]; then - Print_Output "true" "NTP failed to sync after 5 minutes. Please resolve!" "$CRIT" + if [ "$ntpwaitcount" -ge 300 ]; then + Print_Output true "NTP failed to sync after 5 minutes. Please resolve!" "$CRIT" Clear_Lock exit 1 else - Print_Output "true" "NTP synced, $SCRIPT_NAME will now continue" "$PASS" + Print_Output true "NTP synced, $SCRIPT_NAME will now continue" "$PASS" Clear_Lock fi fi @@ -990,41 +1141,41 @@ NTP_Ready(){ ### function based on @Adamm00's Skynet USB wait function ### Entware_Ready(){ - if [ "$1" = "service_event" ]; then - if [ -n "$2" ] && [ "$(echo "$3" | grep -c "$SCRIPT_NAME_LOWER")" -eq 0 ]; then - exit 0 - fi - fi - - if [ ! -f "/opt/bin/opkg" ] && ! echo "$@" | grep -wqE "(install|uninstall|update|forceupdate)"; then + if [ ! -f /opt/bin/opkg ]; then Check_Lock sleepcount=1 - while [ ! -f "/opt/bin/opkg" ] && [ "$sleepcount" -le 10 ]; do - Print_Output "true" "Entware not found, sleeping for 10s (attempt $sleepcount of 10)" "$ERR" + while [ ! -f /opt/bin/opkg ] && [ "$sleepcount" -le 10 ]; do + Print_Output true "Entware not found, sleeping for 10s (attempt $sleepcount of 10)" "$ERR" sleepcount="$((sleepcount + 1))" sleep 10 done - if [ ! -f "/opt/bin/opkg" ]; then - Print_Output "true" "Entware not found and is required for $SCRIPT_NAME to run, please resolve" "$CRIT" + if [ ! -f /opt/bin/opkg ]; then + Print_Output true "Entware not found and is required for $SCRIPT_NAME to run, please resolve" "$CRIT" Clear_Lock exit 1 else - Print_Output "true" "Entware found, $SCRIPT_NAME will now continue" "$PASS" + Print_Output true "Entware found, $SCRIPT_NAME will now continue" "$PASS" Clear_Lock fi fi } ### ### -NTP_Ready "$@" -Entware_Ready "$@" - if [ -z "$1" ]; then + NTP_Ready + if [ ! -f "$DISABLE_USB_FEATURES_FILE" ]; then + Entware_Ready + fi Create_Dirs - Shortcut_SCM create - Set_Version_Custom_Settings "local" + Shortcut_Script create + Set_Version_Custom_Settings local Create_Symlinks - Auto_Startup create 2>/dev/null + if [ ! -f "$DISABLE_USB_FEATURES_FILE" ]; then + Auto_Startup create 2>/dev/null + else + Auto_Startup_NoUSB create 2>/dev/null + fi + Auto_ServiceEvent create 2>/dev/null ScriptHeader MainMenu @@ -1038,21 +1189,20 @@ case "$1" in exit 0 ;; startup) - Check_Lock - sleep 20 - Menu_Startup + Menu_Startup "$2" exit 0 ;; service_event) - if [ "$2" = "start" ] && [ "$3" = "$SCRIPT_NAME_LOWER""config" ]; then - Conf_FromSettings + if [ "$2" = "start" ] && echo "$3" | grep "${SCRIPT_NAME_LOWER}config"; then + settingstate="$(echo "$3" | sed "s/${SCRIPT_NAME_LOWER}config//")"; + Menu_ToggleUSBFeatures "$settingstate" exit 0 - elif [ "$2" = "start" ] && echo "$3" | grep "$SCRIPT_NAME_LOWER""servicerestart"; then + elif [ "$2" = "start" ] && echo "$3" | grep "${SCRIPT_NAME_LOWER}servicerestart"; then echo 'var servicestatus = "InProgress";' > "$SCRIPT_WEB_DIR/detect_service.js" - srvname="$(echo "$3" | sed "s/$SCRIPT_NAME_LOWER""servicerestart//")"; + srvname="$(echo "$3" | sed "s/${SCRIPT_NAME_LOWER}servicerestart//")"; if [ "$srvname" = "vsftpd" ]; then ENABLED_FTP="$(nvram get enable_ftp)" - if ! Validate_Number "" "$ENABLED_FTP" "silent"; then ENABLED_FTP=0; fi + if ! Validate_Number "" "$ENABLED_FTP" silent; then ENABLED_FTP=0; fi if [ "$ENABLED_FTP" -eq 1 ]; then service restart_"$srvname" >/dev/null 2>&1 echo 'var servicestatus = "Done";' > "$SCRIPT_WEB_DIR/detect_service.js" @@ -1061,7 +1211,7 @@ case "$1" in fi elif [ "$srvname" = "samba" ]; then ENABLED_SAMBA="$(nvram get enable_samba)" - if ! Validate_Number "" "$ENABLED_SAMBA" "silent"; then ENABLED_SAMBA=0; fi + if ! Validate_Number "" "$ENABLED_SAMBA" silent; then ENABLED_SAMBA=0; fi if [ "$ENABLED_SAMBA" -eq 1 ]; then service restart_"$srvname" >/dev/null 2>&1 echo 'var servicestatus = "Done";' > "$SCRIPT_WEB_DIR/detect_service.js" @@ -1070,14 +1220,14 @@ case "$1" in fi elif [ "$srvname" = "ntpdchronyd" ]; then ENABLED_NTPD="$(nvram get ntpd_enable)" - if ! Validate_Number "" "$ENABLED_NTPD" "silent"; then ENABLED_NTPD=0; fi + if ! Validate_Number "" "$ENABLED_NTPD" silent; then ENABLED_NTPD=0; fi if [ "$ENABLED_NTPD" -eq 1 ]; then service restart_time >/dev/null 2>&1 echo 'var servicestatus = "Done";' > "$SCRIPT_WEB_DIR/detect_service.js" - elif [ -f "/opt/etc/init.d/S77ntpd" ]; then + elif [ -f /opt/etc/init.d/S77ntpd ]; then /opt/etc/init.d/S77ntpd restart echo 'var servicestatus = "Done";' > "$SCRIPT_WEB_DIR/detect_service.js" - elif [ -f "/opt/etc/init.d/S77chronyd" ]; then + elif [ -f /opt/etc/init.d/S77chronyd ]; then /opt/etc/init.d/S77chronyd restart echo 'var servicestatus = "Done";' > "$SCRIPT_WEB_DIR/detect_service.js" else @@ -1085,7 +1235,7 @@ case "$1" in fi elif echo "$srvname" | grep -q "vpnclient"; then vpnno="$(echo "$srvname" | sed "s/vpnclient//")"; - if [ -n "$(nvram get "vpn_client$vpnno""_addr")" ]; then + if [ -n "$(nvram get "vpn_client${vpnno}_addr")" ]; then service restart_"$srvname" >/dev/null 2>&1 echo 'var servicestatus = "Done";' > "$SCRIPT_WEB_DIR/detect_service.js" else @@ -1107,34 +1257,33 @@ case "$1" in echo 'var servicestatus = "Done";' > "$SCRIPT_WEB_DIR/detect_service.js" fi exit 0 - elif [ "$2" = "start" ] && [ "$3" = "$SCRIPT_NAME_LOWER""checkupdate" ]; then - updatecheckresult="$(Update_Check)" + elif [ "$2" = "start" ] && [ "$3" = "${SCRIPT_NAME_LOWER}checkupdate" ]; then + Update_Check exit 0 - elif [ "$2" = "start" ] && [ "$3" = "$SCRIPT_NAME_LOWER""doupdate" ]; then - Update_Version "force" "unattended" + elif [ "$2" = "start" ] && [ "$3" = "${SCRIPT_NAME_LOWER}doupdate" ]; then + Update_Version force unattended exit 0 fi exit 0 ;; update) - Update_Version "unattended" + Update_Version unattended exit 0 ;; forceupdate) - Update_Version "force" "unattended" + Update_Version force unattended exit 0 ;; setversion) - Set_Version_Custom_Settings "local" - Set_Version_Custom_Settings "server" "$SCRIPT_VERSION" + Set_Version_Custom_Settings local + Set_Version_Custom_Settings server "$SCRIPT_VERSION" if [ -z "$2" ]; then exec "$0" fi exit 0 ;; checkupdate) - #shellcheck disable=SC2034 - updatecheckresult="$(Update_Check)" + Update_Check exit 0 ;; uninstall) @@ -1144,12 +1293,12 @@ case "$1" in ;; develop) sed -i 's/^readonly SCRIPT_BRANCH.*$/readonly SCRIPT_BRANCH="develop"/' "/jffs/scripts/$SCRIPT_NAME_LOWER" - exec "$0" "update" + Update_Version force exit 0 ;; stable) sed -i 's/^readonly SCRIPT_BRANCH.*$/readonly SCRIPT_BRANCH="master"/' "/jffs/scripts/$SCRIPT_NAME_LOWER" - exec "$0" "update" + Update_Version force exit 0 ;; *) diff --git a/scmerlin_www.asp b/scmerlin_www.asp index 7a1798f..1f386f7 100644 --- a/scmerlin_www.asp +++ b/scmerlin_www.asp @@ -15,6 +15,11 @@ p { font-weight: bolder; } +label.settingvalue { + margin-right: 10px !important; + vertical-align: top !important; +} + thead.collapsible-jquery { color: white; padding: 0px; @@ -126,7 +131,7 @@ function update_sysinfo(e){ url: '/ajax_sysinfo.asp', dataType: 'script', error: function(xhr) { - setTimeout("update_sysinfo();", 1000); + setTimeout(update_sysinfo, 1000); }, success: function(response){ show_memcpu(); @@ -140,7 +145,7 @@ function update_sysinfo(e){ } Draw_Chart("nvramUsage"); Draw_Chart("jffsUsage"); - setTimeout("update_sysinfo();", 3000); + setTimeout(update_sysinfo, 3000); } }); } @@ -170,17 +175,15 @@ function update_temperatures(){ }, success: function(response){ code = "2.4 GHz: " + curr_coreTmp_2_raw + ""; - if(typeof wl_info.band5g_2_support == 'undefined' || wl_info.band5g_2_support == null){ - code += "  -  5 GHz: " + curr_coreTmp_5_raw + ""; - } - else{ - if(wl_info.band5g_2_support){ - code += "  -  5 GHz-1: " + curr_coreTmp_5_raw + ""; - code += "  -  5 GHz-2: " + curr_coreTmp_52_raw + ""; - } - else if (band5g_support){ - code += "  -  5 GHz: " + curr_coreTmp_5_raw + ""; + if(wl_info.band5g_2_support){ + code += "  -  5 GHz-1: " + curr_coreTmp_5_raw + ""; + if(typeof curr_coreTmp_52_raw == 'undefined' || curr_coreTmp_52_raw == null){ + curr_coreTmp_52_raw = "N/A" } + code += "  -  5 GHz-2: " + curr_coreTmp_52_raw + ""; + } + else if (band5g_support){ + code += "  -  5 GHz: " + curr_coreTmp_5_raw + ""; } var CPUTemp = ""; @@ -195,15 +198,14 @@ function update_temperatures(){ code +="  -  CPU: " + parseInt(CPUTemp) +"°C"; } document.getElementById("temp_td").innerHTML = code; - setTimeout("update_temperatures();", 3000); + setTimeout(update_temperatures, 3000); } }); } /* End firmware functions */ var nvramtotal = <% sysinfo("nvram.total"); %> / 1024; - -var tout,arrayproclistlines=[],originalarrayproclistlines=[],sortfield="CPU%",sortname="CPU%",sortdir="desc";Chart.defaults.global.defaultFontColor="#CCC",Chart.Tooltip.positioners.cursor=function(a,b){return b};var $j=jQuery.noConflict();function SetCurrentPage(){document.form.next_page.value=window.location.pathname.substring(1),document.form.current_page.value=window.location.pathname.substring(1)}var srvnamelist=["dnsmasq","wan","httpd","wireless","vsftpd","samba","ddns","ntpd/chronyd"],srvdesclist=["DNS/DHCP Server","Internet Connection","Web Interface","WiFi","FTP Server","Samba","DDNS client","Timeserver"],srvnamevisiblelist=[!0,!1,!0,!1,!0,!1,!1,!0];function initial(){SetCurrentPage(),LoadCustomSettings(),show_menu();var a="";for(i=1;3>i;i++)a+=BuildVPNServerTable(i);$j("#table_buttons").after(a);var b="";for(i=1;6>i;i++)b+=BuildVPNClientTable(i);$j("#table_buttons").after(b);var c="";for(i=0;i";a+="",a+="",a+="",a+="",a+="",a+="",a+="",a+="",a+="",a+="",a+="",a+="PID",a+="PPID",a+="USER",a+="STAT",a+="VSZ",a+="VSZ%",a+="CPU",a+="CPU%",a+="COMMAND",a+="",a+="",a+="";for(var b=0;b",a+=""+arrayproclistlines[b].PID+"",a+=""+arrayproclistlines[b].PPID+"",a+=""+arrayproclistlines[b].USER+"",a+=""+arrayproclistlines[b].STAT+"",a+=""+arrayproclistlines[b].VSZ+"",a+=""+arrayproclistlines[b].VSZP+"",a+=""+arrayproclistlines[b].CPU+"",a+=""+arrayproclistlines[b].CPUP+"",a+=""+arrayproclistlines[b].COMMAND+"",a+="";return a+="",a+="",a}function get_proclist_file(){$j.ajax({url:"/ext/scmerlin/top.htm",dataType:"text",error:function(){tout=setTimeout(get_proclist_file,1e3)},success:function(a){ParseProcList(a),document.getElementById("auto_refresh").checked&&(tout=setTimeout("get_proclist_file();",3e3))}})}function ParseProcList(a){var b=a.split("\n");b=b.filter(Boolean),arrayproclistlines=[];for(var c=0;c (a."+sortfield+" > b."+sortfield+") ? 1 : ((b."+sortfield+" > a."+sortfield+") ? -1 : 0)); "),sortdir="asc"):-1==sorttext.indexOf("\u2193")?(eval("arrayproclistlines = arrayproclistlines.sort((a,b) => (a."+sortfield+" < b."+sortfield+") ? 1 : ((b."+sortfield+" < a."+sortfield+") ? -1 : 0)); "),sortdir="desc"):(eval("arrayproclistlines = arrayproclistlines.sort((a,b) => (a."+sortfield+" > b."+sortfield+") ? 1 : ((b."+sortfield+" > a."+sortfield+") ? -1 : 0)); "),sortdir="asc"):"number"==sorttype&&(-1==sorttext.indexOf("\u2193")&&-1==sorttext.indexOf("\u2191")?(eval("arrayproclistlines = arrayproclistlines.sort((a, b) => parseFloat(a."+sortfield+".replace('m','000')) - parseFloat(b."+sortfield+".replace('m','000'))); "),sortdir="asc"):-1==sorttext.indexOf("\u2193")?(eval("arrayproclistlines = arrayproclistlines.sort((a, b) => parseFloat(b."+sortfield+".replace('m','000')) - parseFloat(a."+sortfield+".replace('m','000'))); "),sortdir="desc"):(eval("arrayproclistlines = arrayproclistlines.sort((a, b) => parseFloat(a."+sortfield+".replace('m','000')) - parseFloat(b."+sortfield+".replace('m','000'))); "),sortdir="asc")),$j("#procTableContainer").empty(),$j("#procTableContainer").append(BuildProcListTableHtml()),stripedTable(),$j(".sortable").each(function(a,b){b.innerHTML==sortname&&("asc"==sortdir?b.innerHTML=sortname+" \u2191":b.innerHTML=sortname+" \u2193")})}function ToggleRefresh(){$j("#auto_refresh").prop("checked",function(a,b){b?get_proclist_file():clearTimeout(tout)})}function BuildServiceTable(a,b,c,d){var e="";return 0==d&&(e+="
 
",e+="",e+="",e+="",e+=""),e+="",e+=c?"":"",a=a.replace("/",""),e+="",e+="",d==srvnamelist.length-1&&(e+="
Services (click to expand/collapse)
"+b+" ("+a+")"+b+"",e+="",e+="      Done",e+="Invalid - service not enabled",e+="",e+="   ",e+="
"),e}function BuildVPNClientTable(loopindex){var vpnclientshtml="",vpnclientname="vpnclient"+loopindex,vpnclientdesc=eval("document.form.vpnc"+loopindex+"_desc").value;return 1==loopindex&&(vpnclientshtml+="
 
",vpnclientshtml+="",vpnclientshtml+="",vpnclientshtml+="",vpnclientshtml+=""),vpnclientshtml+="",vpnclientshtml+="",vpnclientshtml+="",vpnclientshtml+="",5==loopindex&&(vpnclientshtml+="
VPN Clients (click to expand/collapse)
VPN Client "+loopindex,vpnclientshtml+="
("+vpnclientdesc+")
",vpnclientshtml+="",vpnclientshtml+="      Done",vpnclientshtml+="Invalid - VPN Client not enabled",vpnclientshtml+="",vpnclientshtml+="   ",vpnclientshtml+="
"),vpnclientshtml}function BuildVPNServerTable(a){var b="",c="vpnserver"+a;return 1==a&&(b+="
 
",b+="",b+="",b+="",b+=""),b+="",b+="",b+="",b+="",2==a&&(b+="
VPN Servers (click to expand/collapse)
VPN Server "+a+"",b+="",b+="      Done",b+="Invalid - VPN Server not enabled",b+="",b+="   ",b+="
"),b}function round(a,b){return+(Math.round(a+"e"+b)+"e-"+b)}function Draw_Chart_NoData(a){document.getElementById("canvasChart"+a).width="270",document.getElementById("canvasChart"+a).height="250",document.getElementById("canvasChart"+a).style.width="270px",document.getElementById("canvasChart"+a).style.height="250px";var b=document.getElementById("canvasChart"+a).getContext("2d");b.save(),b.textAlign="center",b.textBaseline="middle",b.font="normal normal bolder 22px Arial",b.fillStyle="white",b.fillText("No swap file configured",135,125),b.restore()}function Draw_Chart(a){var b=[],c=[],d=[],e="",f="";if("MemoryUsage"==a)b=[1*mem_stats_arr[0]-1*mem_stats_arr[1]-1*mem_stats_arr[2]-1*mem_stats_arr[3],mem_stats_arr[1],mem_stats_arr[2],mem_stats_arr[3]],c=["Used","Free","Buffers","Cache"],d=["#5eaec0","#12cf80","#ceca09","#9d12c4"],e="Memory Usage",f="MB";else if("SwapUsage"==a)b=[mem_stats_arr[4],1*mem_stats_arr[5]-1*mem_stats_arr[4]],c=["Used","Free"],d=["#135fee","#1aa658"],e="Swap Usage",f="MB";else if("nvramUsage"==a)b=[round(mem_stats_arr[6]/1024,2).toFixed(2),round(1*nvramtotal-1*mem_stats_arr[6]/1024,2).toFixed(2)],c=["Used","Free"],d=["#5eaec0","#12cf80"],e="NVRAM Usage",f="KB";else if("jffsUsage"==a){var g=mem_stats_arr[7].split(" ");b=[1*g[0],1*g[2]-1*g[0]],c=["Used","Free"],d=["#135fee","#1aa658"],e="JFFS Usage",f="MB"}var h=window["Chart"+a];h!=null&&h.destroy();var j=document.getElementById("canvasChart"+a).getContext("2d"),k={segmentShowStroke:!1,segmentStrokeColor:"#000",maintainAspectRatio:!1,animation:{duration:0},hover:{animationDuration:0},responsiveAnimationDuration:0,legend:{onClick:null,display:!0,position:"left",labels:{fontColor:"#ffffff"}},title:{display:!0,text:e,position:"top"},tooltips:{callbacks:{title:function(a,b){return b.labels[a[0].index]},label:function(a,b){return round(b.datasets[a.datasetIndex].data[a.index],2).toFixed(2)+" "+f}},mode:"point",position:"cursor",intersect:!0},scales:{xAxes:[{display:!1,gridLines:{display:!1},scaleLabel:{display:!1},ticks:{display:!1}}],yAxes:[{display:!1,gridLines:{display:!1},scaleLabel:{display:!1},ticks:{display:!1}}]}},l={labels:c,datasets:[{data:b,borderWidth:1,backgroundColor:d,borderColor:"#000000"}]};h=new Chart(j,{type:"pie",options:k,data:l}),window["Chart"+a]=h} +var tout,arrayproclistlines=[],originalarrayproclistlines=[],sortfield="CPU%",sortname="CPU%",sortdir="desc";Chart.defaults.global.defaultFontColor="#CCC",Chart.Tooltip.positioners.cursor=function(a,b){return b};var $j=jQuery.noConflict();function SetCurrentPage(){document.form.next_page.value=window.location.pathname.substring(1),document.form.current_page.value=window.location.pathname.substring(1)}var srvnamelist=["dnsmasq","wan","httpd","wireless","vsftpd","samba","ddns","ntpd/chronyd"],srvdesclist=["DNS/DHCP Server","Internet Connection","Web Interface","WiFi","FTP Server","Samba","DDNS client","Timeserver"],srvnamevisiblelist=[!0,!1,!0,!1,!0,!1,!1,!0];function initial(){SetCurrentPage(),LoadCustomSettings(),show_menu();var a="";for(i=1;3>i;i++)a+=BuildVPNServerTable(i);$j("#table_config").after(a);var b="";for(i=1;6>i;i++)b+=BuildVPNClientTable(i);$j("#table_config").after(b);var c="";for(i=0;i";a+="",a+="",a+="",a+="",a+="",a+="",a+="",a+="",a+="",a+="",a+="",a+="PID",a+="PPID",a+="USER",a+="STAT",a+="VSZ",a+="VSZ%",a+="CPU",a+="CPU%",a+="COMMAND",a+="",a+="",a+="";for(var b=0;b",a+=""+arrayproclistlines[b].PID+"",a+=""+arrayproclistlines[b].PPID+"",a+=""+arrayproclistlines[b].USER+"",a+=""+arrayproclistlines[b].STAT+"",a+=""+arrayproclistlines[b].VSZ+"",a+=""+arrayproclistlines[b].VSZP+"",a+=""+arrayproclistlines[b].CPU+"",a+=""+arrayproclistlines[b].CPUP+"",a+=""+arrayproclistlines[b].COMMAND+"",a+="";return a+="",a+="",a}function get_usbdisabled_file(){$j.ajax({url:"/ext/scmerlin/usbdisabled.htm",dataType:"text",timeout:1e4,error:function(){document.form.scmerlin_usbenabled.value="enable",get_proclist_file()},success:function(){document.form.scmerlin_usbenabled.value="disable",document.getElementById("procTableContainer").innerHTML="Process list disabled, this feature requires the \"USB features\" option to be enabled and a USB device plugged into router for Entware"}})}function get_proclist_file(){$j.ajax({url:"/ext/scmerlin/top.htm",dataType:"text",error:function(){tout=setTimeout(get_proclist_file,1e3)},success:function(a){ParseProcList(a),document.getElementById("auto_refresh").checked&&(tout=setTimeout(get_proclist_file,3e3))}})}function ParseProcList(a){var b=a.split("\n");b=b.filter(Boolean),arrayproclistlines=[];for(var c=0;c (a."+sortfield+" > b."+sortfield+") ? 1 : ((b."+sortfield+" > a."+sortfield+") ? -1 : 0)); "),sortdir="asc"):-1==sorttext.indexOf("\u2193")?(eval("arrayproclistlines = arrayproclistlines.sort((a,b) => (a."+sortfield+" < b."+sortfield+") ? 1 : ((b."+sortfield+" < a."+sortfield+") ? -1 : 0)); "),sortdir="desc"):(eval("arrayproclistlines = arrayproclistlines.sort((a,b) => (a."+sortfield+" > b."+sortfield+") ? 1 : ((b."+sortfield+" > a."+sortfield+") ? -1 : 0)); "),sortdir="asc"):"number"==sorttype&&(-1==sorttext.indexOf("\u2193")&&-1==sorttext.indexOf("\u2191")?(eval("arrayproclistlines = arrayproclistlines.sort((a, b) => parseFloat(a."+sortfield+".replace('m','000')) - parseFloat(b."+sortfield+".replace('m','000'))); "),sortdir="asc"):-1==sorttext.indexOf("\u2193")?(eval("arrayproclistlines = arrayproclistlines.sort((a, b) => parseFloat(b."+sortfield+".replace('m','000')) - parseFloat(a."+sortfield+".replace('m','000'))); "),sortdir="desc"):(eval("arrayproclistlines = arrayproclistlines.sort((a, b) => parseFloat(a."+sortfield+".replace('m','000')) - parseFloat(b."+sortfield+".replace('m','000'))); "),sortdir="asc")),$j("#procTableContainer").empty(),$j("#procTableContainer").append(BuildProcListTableHtml()),stripedTable(),$j(".sortable").each(function(a,b){b.innerHTML==sortname&&("asc"==sortdir?b.innerHTML=sortname+" \u2191":b.innerHTML=sortname+" \u2193")})}function ToggleRefresh(){$j("#auto_refresh").prop("checked",function(a,b){b?get_proclist_file():clearTimeout(tout)})}function BuildServiceTable(a,b,c,d){var e="";return 0==d&&(e+="
 
",e+="",e+="",e+="",e+=""),e+="",e+=c?"":"",a=a.replace("/",""),e+="",e+="",d==srvnamelist.length-1&&(e+="
Services (click to expand/collapse)
"+b+" ("+a+")"+b+"",e+="",e+="      Done",e+="Invalid - service not enabled",e+="",e+="   ",e+="
"),e}function BuildVPNClientTable(loopindex){var vpnclientshtml="",vpnclientname="vpnclient"+loopindex,vpnclientdesc=eval("document.form.vpnc"+loopindex+"_desc").value;return 1==loopindex&&(vpnclientshtml+="
 
",vpnclientshtml+="",vpnclientshtml+="",vpnclientshtml+="",vpnclientshtml+=""),vpnclientshtml+="",vpnclientshtml+="",vpnclientshtml+="",vpnclientshtml+="",5==loopindex&&(vpnclientshtml+="
VPN Clients (click to expand/collapse)
VPN Client "+loopindex,vpnclientshtml+="
("+vpnclientdesc+")
",vpnclientshtml+="",vpnclientshtml+="      Done",vpnclientshtml+="Invalid - VPN Client not enabled",vpnclientshtml+="",vpnclientshtml+="   ",vpnclientshtml+="
"),vpnclientshtml}function BuildVPNServerTable(a){var b="",c="vpnserver"+a;return 1==a&&(b+="
 
",b+="",b+="",b+="",b+=""),b+="",b+="",b+="",b+="",2==a&&(b+="
VPN Servers (click to expand/collapse)
VPN Server "+a+"",b+="",b+="      Done",b+="Invalid - VPN Server not enabled",b+="",b+="   ",b+="
"),b}function round(a,b){return+(Math.round(a+"e"+b)+"e-"+b)}function Draw_Chart_NoData(a){document.getElementById("canvasChart"+a).width="270",document.getElementById("canvasChart"+a).height="250",document.getElementById("canvasChart"+a).style.width="270px",document.getElementById("canvasChart"+a).style.height="250px";var b=document.getElementById("canvasChart"+a).getContext("2d");b.save(),b.textAlign="center",b.textBaseline="middle",b.font="normal normal bolder 22px Arial",b.fillStyle="white",b.fillText("No swap file configured",135,125),b.restore()}function Draw_Chart(a){var b=[],c=[],d=[],e="",f="";if("MemoryUsage"==a)b=[1*mem_stats_arr[0]-1*mem_stats_arr[1]-1*mem_stats_arr[2]-1*mem_stats_arr[3],mem_stats_arr[1],mem_stats_arr[2],mem_stats_arr[3]],c=["Used","Free","Buffers","Cache"],d=["#5eaec0","#12cf80","#ceca09","#9d12c4"],e="Memory Usage",f="MB";else if("SwapUsage"==a)b=[mem_stats_arr[4],1*mem_stats_arr[5]-1*mem_stats_arr[4]],c=["Used","Free"],d=["#135fee","#1aa658"],e="Swap Usage",f="MB";else if("nvramUsage"==a)b=[round(mem_stats_arr[6]/1024,2).toFixed(2),round(1*nvramtotal-1*mem_stats_arr[6]/1024,2).toFixed(2)],c=["Used","Free"],d=["#5eaec0","#12cf80"],e="NVRAM Usage",f="KB";else if("jffsUsage"==a){var g=mem_stats_arr[7].split(" ");b=[1*g[0],1*g[2]-1*g[0]],c=["Used","Free"],d=["#135fee","#1aa658"],e="JFFS Usage",f="MB"}var h=window["Chart"+a];h!=null&&h.destroy();var j=document.getElementById("canvasChart"+a).getContext("2d"),k={segmentShowStroke:!1,segmentStrokeColor:"#000",maintainAspectRatio:!1,animation:{duration:0},hover:{animationDuration:0},responsiveAnimationDuration:0,legend:{onClick:null,display:!0,position:"left",labels:{fontColor:"#ffffff"}},title:{display:!0,text:e,position:"top"},tooltips:{callbacks:{title:function(a,b){return b.labels[a[0].index]},label:function(a,b){return round(b.datasets[a.datasetIndex].data[a.index],2).toFixed(2)+" "+f}},mode:"point",position:"cursor",intersect:!0},scales:{xAxes:[{display:!1,gridLines:{display:!1},scaleLabel:{display:!1},ticks:{display:!1}}],yAxes:[{display:!1,gridLines:{display:!1},scaleLabel:{display:!1},ticks:{display:!1}}]}},l={labels:c,datasets:[{data:b,borderWidth:1,backgroundColor:d,borderColor:"#000000"}]};h=new Chart(j,{type:"pie",options:k,data:l}),window["Chart"+a]=h}function SaveConfig(){var a="start_scmerlinconfig"+document.form.scmerlin_usbenabled.value;document.form.action_script.value=a;document.form.action_wait.value=10,showLoading(),document.form.submit()} @@ -265,6 +267,26 @@ var tout,arrayproclistlines=[],originalarrayproclistlines=[],sortfield="CPU%",so +
 
+ + + + + + + + + + + +
Configuration (click to expand/collapse)
Enable USB Features
(running processes in WebUI)
+ + + + +
+ +
diff --git a/scmerlin_www.js b/scmerlin_www.js index 4c5ea22..4f297f6 100644 --- a/scmerlin_www.js +++ b/scmerlin_www.js @@ -30,21 +30,21 @@ function initial(){ for (i = 1; i < 3; i++){ vpnserverstablehtml += BuildVPNServerTable(i); } - $j("#table_buttons").after(vpnserverstablehtml); + $j("#table_config").after(vpnserverstablehtml); var vpnclientstablehtml=""; for (i = 1; i < 6; i++){ vpnclientstablehtml += BuildVPNClientTable(i); } - $j("#table_buttons").after(vpnclientstablehtml); + $j("#table_config").after(vpnclientstablehtml); var servicectablehtml=""; for (i = 0; i < srvnamelist.length; i++){ servicectablehtml += BuildServiceTable(srvnamelist[i],srvdesclist[i],srvnamevisiblelist[i],i); } - $j("#table_buttons").after(servicectablehtml); + $j("#table_config").after(servicectablehtml); - get_proclist_file(); + get_usbdisabled_file(); update_temperatures(); update_sysinfo(); ScriptUpdateLayout(); @@ -75,11 +75,11 @@ function update_status(){ dataType: 'script', timeout: 3000, error: function(xhr){ - setTimeout('update_status();', 1000); + setTimeout(update_status, 1000); }, success: function(){ if(updatestatus == "InProgress"){ - setTimeout('update_status();', 1000); + setTimeout(update_status, 1000); } else{ document.getElementById("imgChkUpdate").style.display = "none"; @@ -104,7 +104,7 @@ function CheckUpdate(){ document.formScriptActions.action_script.value="start_scmerlincheckupdate"; document.formScriptActions.submit(); document.getElementById("imgChkUpdate").style.display = ""; - setTimeout("update_status();", 2000); + setTimeout(update_status, 2000); } function DoUpdate(){ @@ -122,7 +122,7 @@ function RestartService(servicename){ document.formScriptActions.action_script.value="start_scmerlinservicerestart"+servicename; document.formScriptActions.submit(); document.getElementById("imgRestartSrv_"+servicename).style.display = ""; - setTimeout("service_status('"+servicename+"');", 1000); + setTimeout(service_status, 1000, servicename); } function service_status(servicename){ @@ -131,18 +131,18 @@ function service_status(servicename){ dataType: 'script', timeout: 3000, error: function(xhr){ - setTimeout("service_status('"+servicename+"');", 1000); + setTimeout(service_status, 1000, servicename); }, success: function(){ if(servicestatus == "InProgress"){ - setTimeout("service_status('"+servicename+"');", 1000); + setTimeout(service_status, 1000, servicename); } else{ document.getElementById("imgRestartSrv_"+servicename).style.display = "none"; if(servicestatus == "Done"){ showhide("btnRestartSrv_"+servicename, true); showhide("txtRestartSrv_"+servicename, true); - setTimeout("showhide('txtRestartSrv_"+servicename+"',false);", 3000); + setTimeout(showhide, 3000,'txtRestartSrv_'+servicename,false); } else{ showhide("txtRestartSrvError_"+servicename, true); @@ -215,6 +215,22 @@ function BuildProcListTableHtml() { return tablehtml; } +function get_usbdisabled_file(){ + $j.ajax({ + url: '/ext/scmerlin/usbdisabled.htm', + dataType: 'text', + timeout: 10000, + error: function(xhr){ + document.form.scmerlin_usbenabled.value = "enable"; + get_proclist_file(); + }, + success: function(data){ + document.form.scmerlin_usbenabled.value = "disable"; + document.getElementById("procTableContainer").innerHTML = "Process list disabled, this feature requires the \"USB features\" option to be enabled and a USB device plugged into router for Entware"; + } + }); +} + function get_proclist_file(){ $j.ajax({ url: '/ext/scmerlin/top.htm', @@ -225,7 +241,7 @@ function get_proclist_file(){ success: function(data){ ParseProcList(data); if(document.getElementById("auto_refresh").checked){ - tout = setTimeout("get_proclist_file();",3000); + tout = setTimeout(get_proclist_file,3000); } } }); @@ -642,3 +658,12 @@ function Draw_Chart(txtchartname){ }); window["Chart" + txtchartname] = objchartname; } + +function SaveConfig(){ + var action_script_tmp = "start_scmerlinconfig" + document.form.scmerlin_usbenabled.value; + document.form.action_script.value = action_script_tmp; + var restart_time = 10; + document.form.action_wait.value = restart_time; + showLoading(); + document.form.submit(); +}