diff --git a/CHANGELOG.md b/CHANGELOG.md index 150400a..8d57893 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## v3.0.3 +04 January 2025 +* FIXED: Errors when loading the webGUI page on the 3006.102.1 F/W version. +* FIXED: Bug giving incorrect results when computing the free space available of a large-capacity USB-attached drive. This was preventing the user from resetting the database using the CLI menu. +* FIXED: "Reset Database" functionality on the CLI menu was correctly resetting the database file but the result was not reflected on the webGUI page where "old" entries were still shown as if the database had not been reset. +* IMPROVED: Modified all SQLite3 calls to capture and log errors in the system log. +* IMPROVED: Modified SQLite3 configuration parameters to improve the trimming of records from the database and then perform "garbage collection" of deleted entries to reclaim unused space & avoid excessive fragmentation. +* IMPROVED: Modified SQLite3 configuration parameters to improve the processing of database records. +* IMPROVED: Modified code to set the corresponding priority level of log entries when calling the built-in logger utility. +* IMPROVED: Modified the startup call made in the post-mount script to check if the USB-attached disk partition passed as argument has Entware installed. +* IMPROVED: Added code to show the current database file size information on the CLI menu and the webGUI page. +* IMPROVED: Added code to show the "JFFS Available" space information for the "Data Storage Location" option on the CLI menu and the webGUI page. +* CHANGED: Modified code related to "var $j = jQuery.noConflict();" which is now considered obsolete. +* IMPROVED: Various code improvements & fine-tuning. + ## v3.0.2 06 January 2022 * FIXED: Only download CHANGELOG on upgrade if it doesn't exist diff --git a/README.md b/README.md index f368b7b..21645b7 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ [](https://www.codacy.com/app/jackyaz/connmon?utm_source=github.com&utm_medium=referral&utm_content=jackyaz/connmon&utm_campaign=Badge_Grade)  -## v3.0.2 -### Updated on 2022-01-06 +## v3.0.3 +### Updated on 2025-Feb-03 ## About connmon is an internet connection monitoring tool for AsusWRT Merlin with charts for daily, weekly and monthly summaries. diff --git a/connmon.sh b/connmon.sh index f2db048..872415e 100644 --- a/connmon.sh +++ b/connmon.sh @@ -10,6 +10,8 @@ ## https://github.com/jackyaz/connmon ## ## ## ############################################################## +# Last Modified: 2025-Feb-03 +#------------------------------------------------------------- ############## Shellcheck directives ############# # shellcheck disable=SC1090 @@ -22,14 +24,18 @@ # shellcheck disable=SC2059 # shellcheck disable=SC2086 # shellcheck disable=SC2155 +# shellcheck disable=SC2174 # shellcheck disable=SC2181 # shellcheck disable=SC3003 +# shellcheck disable=SC3018 +# shellcheck disable=SC3043 +# shellcheck disable=SC3045 ############################################################## ### Start of script variables ### readonly SCRIPT_NAME="connmon" -readonly SCRIPT_VERSION="v3.0.2" -SCRIPT_BRANCH="master" +readonly SCRIPT_VERSION="v3.0.3" +SCRIPT_BRANCH="develop" SCRIPT_REPO="https://jackyaz.io/$SCRIPT_NAME/$SCRIPT_BRANCH" readonly SCRIPT_DIR="/jffs/addons/$SCRIPT_NAME.d" readonly SCRIPT_WEBPAGE_DIR="$(readlink /www/user)" @@ -40,8 +46,24 @@ readonly SHARED_WEB_DIR="$SCRIPT_WEBPAGE_DIR/shared-jy" readonly EMAIL_DIR="/jffs/addons/amtm/mail" readonly EMAIL_CONF="$EMAIL_DIR/email.conf" readonly EMAIL_REGEX="^(([A-Za-z0-9]+((\.|\-|\_|\+)?[A-Za-z0-9]?)*[A-Za-z0-9]+)|[A-Za-z0-9]+)@(([A-Za-z0-9]+)+((\.|\-|\_)?([A-Za-z0-9]+)+)*)+\.([A-Za-z]{2,})+$" + [ -z "$(nvram get odmpid)" ] && ROUTER_MODEL="$(nvram get productid)" || ROUTER_MODEL="$(nvram get odmpid)" [ -f /opt/bin/sqlite3 ] && SQLITE3_PATH=/opt/bin/sqlite3 || SQLITE3_PATH=/usr/sbin/sqlite3 + +##----------------------------------------## +## Modified by Martinski W. [2025-Jan-04] ## +##----------------------------------------## +readonly scriptVersRegExp="v[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})" + +# For daily CRON job to trim database # +readonly defTrimDB_Hour=3 +readonly defTrimDB_Mins=1 + +readonly oneKByte=1024 +readonly oneMByte=1048576 +readonly oneGByte=1073741824 +readonly SHARE_TEMP_DIR="/opt/share/tmp" + ### End of script variables ### ### Start of output format variables ### @@ -53,17 +75,46 @@ readonly BOLD="\\e[1m" readonly SETTING="${BOLD}\\e[36m" readonly UNDERLINE="\\e[4m" readonly CLEARFORMAT="\\e[0m" + +##-------------------------------------## +## Added by Martinski W. [2024-Dec-21] ## +##-------------------------------------## +readonly REDct="\033[1;31m\033[1m" +readonly GRNct="\033[1;32m\033[1m" +readonly CLEARct="\033[0m" + ### End of output format variables ### +# Give priority to built-in binaries # +export PATH="/bin:/usr/bin:/sbin:/usr/sbin:$PATH" + +##----------------------------------------## +## Modified by Martinski W. [2024-Dec-21] ## +##----------------------------------------## # $1 = print to syslog, $2 = message to print, $3 = log level -Print_Output(){ - if [ "$1" = "true" ]; then - logger -t "$SCRIPT_NAME" "$2" +Print_Output() +{ + local prioStr prioNum + if [ $# -gt 2 ] && [ -n "$3" ] + then prioStr="$3" + else prioStr="NOTICE" + fi + if [ "$1" = "true" ] + then + case "$prioStr" in + "$CRIT") prioNum=2 ;; + "$ERR") prioNum=3 ;; + "$WARN") prioNum=4 ;; + "$PASS") prioNum=6 ;; #INFO# + *) prioNum=5 ;; #NOTICE# + esac + logger -t "$SCRIPT_NAME" -p $prioNum "$2" fi - printf "${BOLD}${3}%s${CLEARFORMAT}\\n\\n" "$2" + printf "${BOLD}${3}%s${CLEARFORMAT}\n\n" "$2" } -Firmware_Version_Check(){ +Firmware_Version_Check() +{ if nvram get rc_support | grep -qF "am_addons"; then return 0 else @@ -72,10 +123,13 @@ Firmware_Version_Check(){ } ### Code for these functions inspired by https://github.com/Adamm00 - credit to @Adamm ### -Check_Lock(){ - if [ -f "/tmp/$SCRIPT_NAME.lock" ]; then +Check_Lock() +{ + if [ -f "/tmp/$SCRIPT_NAME.lock" ] + then ageoflock="$(($(/bin/date "+%s") - $(/bin/date "+%s" -r "/tmp/$SCRIPT_NAME.lock")))" - if [ "$ageoflock" -gt 600 ]; then + if [ "$ageoflock" -gt 600 ] #10 minutes# + then Print_Output true "Stale lock file found (>600 seconds old) - purging lock" "$ERR" kill "$(sed -n '1p' "/tmp/$SCRIPT_NAME.lock")" >/dev/null 2>&1 Clear_Lock @@ -83,7 +137,8 @@ Check_Lock(){ return 0 else Print_Output true "Lock file found (age: $ageoflock seconds) - ping test likely currently running" "$ERR" - if [ -z "$1" ]; then + if [ $# -eq 0 ] || [ -z "$1" ] + then exit 1 else if [ "$1" = "webui" ]; then @@ -99,21 +154,27 @@ Check_Lock(){ fi } -Clear_Lock(){ +Clear_Lock() +{ rm -f "/tmp/$SCRIPT_NAME.lock" 2>/dev/null return 0 } -############################################################################ - -Set_Version_Custom_Settings(){ +##----------------------------------------## +## Modified by Martinski W. [2025-Feb-02] ## +##----------------------------------------## +Set_Version_Custom_Settings() +{ SETTINGSFILE="/jffs/addons/custom_settings.txt" case "$1" in local) - if [ -f "$SETTINGSFILE" ]; then - if [ "$(grep -c "connmon_version_local" $SETTINGSFILE)" -gt 0 ]; then - if [ "$2" != "$(grep "connmon_version_local" /jffs/addons/custom_settings.txt | cut -f2 -d' ')" ]; then - sed -i "s/connmon_version_local.*/connmon_version_local $2/" "$SETTINGSFILE" + if [ -f "$SETTINGSFILE" ] + then + if [ "$(grep -c "^connmon_version_local" "$SETTINGSFILE")" -gt 0 ] + then + if [ "$2" != "$(grep "^connmon_version_local" "$SETTINGSFILE" | cut -f2 -d' ')" ] + then + sed -i "s/^connmon_version_local.*/connmon_version_local $2/" "$SETTINGSFILE" fi else echo "connmon_version_local $2" >> "$SETTINGSFILE" @@ -123,10 +184,13 @@ Set_Version_Custom_Settings(){ fi ;; server) - if [ -f "$SETTINGSFILE" ]; then - if [ "$(grep -c "connmon_version_server" $SETTINGSFILE)" -gt 0 ]; then - if [ "$2" != "$(grep "connmon_version_server" /jffs/addons/custom_settings.txt | cut -f2 -d' ')" ]; then - sed -i "s/connmon_version_server.*/connmon_version_server $2/" "$SETTINGSFILE" + if [ -f "$SETTINGSFILE" ] + then + if [ "$(grep -c "^connmon_version_server" "$SETTINGSFILE")" -gt 0 ] + then + if [ "$2" != "$(grep "^connmon_version_server" "$SETTINGSFILE" | cut -f2 -d' ')" ] + then + sed -i "s/^connmon_version_server.*/connmon_version_server $2/" "$SETTINGSFILE" fi else echo "connmon_version_server $2" >> "$SETTINGSFILE" @@ -138,23 +202,30 @@ Set_Version_Custom_Settings(){ esac } -Update_Check(){ +##----------------------------------------## +## Modified by Martinski W. [2025-Jan-04] ## +##----------------------------------------## +Update_Check() +{ echo 'var updatestatus = "InProgress";' > "$SCRIPT_WEB_DIR/detect_update.js" doupdate="false" - localver="$(grep "SCRIPT_VERSION=" "/jffs/scripts/$SCRIPT_NAME" | grep -m1 -oE 'v[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})')" - Set_Version_Custom_Settings local "$localver" - /usr/sbin/curl -fsL --retry 3 --connect-timeout 15 "$SCRIPT_REPO/404/$SCRIPT_NAME.sh" | grep -qF "jackyaz" || { Print_Output true "404 error detected - stopping update" "$ERR"; return 1; } - serverver="$(/usr/sbin/curl -fsL --retry 3 --connect-timeout 15 "$SCRIPT_REPO/version/$SCRIPT_NAME.sh" | grep "SCRIPT_VERSION=" | grep -m1 -oE 'v[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})')" - if [ "$localver" != "$serverver" ]; then + localver="$(grep "SCRIPT_VERSION=" "/jffs/scripts/$SCRIPT_NAME" | grep -m1 -oE "$scriptVersRegExp")" + [ -n "$localver" ] && Set_Version_Custom_Settings local "$localver" + curl -fsL --retry 4 --retry-delay 5 "$SCRIPT_REPO/404/$SCRIPT_NAME.sh" | grep -qF "jackyaz" || \ + { Print_Output true "404 error detected - stopping update" "$ERR"; return 1; } + serverver="$(curl -fsL --retry 4 --retry-delay 5 "$SCRIPT_REPO/version/$SCRIPT_NAME.sh" | grep "SCRIPT_VERSION=" | grep -m1 -oE "$scriptVersRegExp")" + if [ "$localver" != "$serverver" ] + then doupdate="version" Set_Version_Custom_Settings server "$serverver" - changelog="$(/usr/sbin/curl -fsL --retry 3 --connect-timeout 15 "$SCRIPT_REPO/files/CHANGELOG.md" | sed -n "/$serverver"'/,/##/p' | head -n -1 | sed 's/## //')" + changelog="$(curl -fsL --retry 4 --retry-delay 5 "$SCRIPT_REPO/files/CHANGELOG.md" | sed -n "/$serverver"'/,/##/p' | head -n -1 | sed 's/## //')" echo 'var changelog = "
Ping: $PING
Jitter: $JITTER
Line Quality: $LINEQUAL
| Data loading... |