From b24d12009bfac614346d1070bfe53e220bda59e1 Mon Sep 17 00:00:00 2001 From: Martinski <119833648+Martinski4GitHub@users.noreply.github.com> Date: Mon, 1 Jul 2024 17:21:58 -0700 Subject: [PATCH 1/4] Update README.md Corrected next version string. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 712cd59..12a16e0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/91af8db9cd354643a8ef6a7117be90fb)](https://www.codacy.com/app/jackyaz/connmon?utm_source=github.com&utm_medium=referral&utm_content=jackyaz/connmon&utm_campaign=Badge_Grade) ![Shellcheck](https://github.com/jackyaz/connmon/actions/workflows/shellcheck.yml/badge.svg) -## v3.0.4 +## v3.0.3 ### Updated on 2024-July-01 ## About connmon is an internet connection monitoring tool for AsusWRT Merlin with charts for daily, weekly and monthly summaries. From d98af7ef2f08276d3d80d9c49bd5995b6b0fdbd4 Mon Sep 17 00:00:00 2001 From: Martinski <119833648+Martinski4GitHub@users.noreply.github.com> Date: Mon, 1 Jul 2024 17:22:16 -0700 Subject: [PATCH 2/4] Update connmon.sh Corrected next version string. --- connmon.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connmon.sh b/connmon.sh index ae92ed9..3d1302b 100644 --- a/connmon.sh +++ b/connmon.sh @@ -30,7 +30,7 @@ ### Start of script variables ### readonly SCRIPT_NAME="connmon" -readonly SCRIPT_VERSION="v3.0.4" +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" From 2d35b6181bd7fc2158fcece46653ffec687bda96 Mon Sep 17 00:00:00 2001 From: Martinski <119833648+Martinski4GitHub@users.noreply.github.com> Date: Mon, 15 Jul 2024 00:23:42 -0700 Subject: [PATCH 3/4] Fixed "Reset Database" functionality Fixed the "Reset Database" functionality on the CLI menu where the database file was correctly reset but the result was not reflected on the webGUI page where "old" entries were still shown as if the database had not been reset. --- README.md | 2 +- connmon.sh | 61 ++++++++++++++++++++++++++++++++++++-------- connmonstats_www.asp | 10 +++++--- connmonstats_www.js | 21 ++++++++++++--- 4 files changed, 74 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 12a16e0..92c0375 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ![Shellcheck](https://github.com/jackyaz/connmon/actions/workflows/shellcheck.yml/badge.svg) ## v3.0.3 -### Updated on 2024-July-01 +### Updated on 2024-July-14 ## 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 3d1302b..716ed73 100644 --- a/connmon.sh +++ b/connmon.sh @@ -10,7 +10,7 @@ ## https://github.com/jackyaz/connmon ## ## ## ############################################################## -# Last Modified: 2024-Jul-01 +# Last Modified: 2024-Jul-14 #------------------------------------------------------------- ############## Shellcheck directives ############# @@ -1023,14 +1023,25 @@ OutputTimeMode(){ esac } -WriteStats_ToJS(){ +##----------------------------------------## +## Modified by Martinski W. [2024-Jul-14] ## +##----------------------------------------## +WriteStats_ToJS() +{ + if [ $# -lt 4 ] ; then return 1 ; fi + echo "function $3(){" > "$2" html='document.getElementById("'"$4"'").innerHTML="' - while IFS='' read -r line || [ -n "$line" ]; do - html="${html}${line}\\r\\n" + + while IFS='' read -r line || [ -n "$line" ] + do html="${html}${line}\r\n" done < "$1" html="$html"'"' - printf "%s\\r\\n}\\r\\n" "$html" >> "$2" + + if [ $# -lt 5 ] || [ -z "$5" ] + then printf "%s\r\n}\r\n" "$html" >> "$2" + else printf "%s;\r\n%s\r\n}\r\n" "$html" "$5" >> "$2" + fi } #$1 fieldname $2 tablename $3 frequency (hours) $4 length (days) $5 outputfile $6 outputfrequency $7 sqlfile $8 timestamp @@ -1327,12 +1338,18 @@ Generate_LastXResults(){ mv /tmp/conn-lastx.csv "$SCRIPT_STORAGE_DIR/lastx.csv" } -Reset_DB(){ + +##----------------------------------------## +## Modified by Martinski W. [2024-Jul-14] ## +##----------------------------------------## +Reset_DB() +{ SIZEAVAIL="$(df -P -k "$SCRIPT_STORAGE_DIR" | awk '{print $4}' | tail -n 1)" SIZEDB="$(ls -l "$SCRIPT_STORAGE_DIR/connstats.db" | awk '{print $5}')" - SIZEAVAIL="$(echo "$SIZEAVAIL" | awk '{printf("%s", $1*1024);}')" + SIZEAVAIL="$(echo "$SIZEAVAIL" | awk '{printf("%s", $1 * 1024);}')" - if [ "$(echo "$SIZEAVAIL $SIZEDB" | awk '{print ($1 < $2)}')" -eq 1 ]; then + if [ "$(echo "$SIZEAVAIL $SIZEDB" | awk '{print ($1 < $2)}')" -eq 1 ] + then Print_Output true "Database size exceeds available space. $(ls -lh "$SCRIPT_STORAGE_DIR/connstats.db" | awk '{print $5}')B is required to create backup." "$ERR" return 1 else @@ -1341,11 +1358,30 @@ Reset_DB(){ Print_Output true "Database backup failed, please check storage device" "$WARN" fi + Print_Output false "Please wait..." "$PASS" echo "DELETE FROM [connstats];" > /tmp/connmon-stats.sql "$SQLITE3_PATH" "$SCRIPT_STORAGE_DIR/connstats.db" < /tmp/connmon-stats.sql rm -f /tmp/connmon-stats.sql + ## Clear/Reset all CSV files ## + Generate_CSVs + + ## Show "reset" messages on webGUI ## + timeDateNow="$(/bin/date +"%c")" + extraJScode='databaseResetDone += 1;' + echo "Resetting stats: $timeDateNow" > /tmp/connstatstitle.txt + WriteStats_ToJS /tmp/connstatstitle.txt "$SCRIPT_STORAGE_DIR/connstatstext.js" setConnmonStatsTitle statstitle "$extraJScode" + rm -f /tmp/connstatstitle.txt + sleep 2 Print_Output true "Database reset complete" "$WARN" + { + sleep 4 + timeDateNow="$(/bin/date +"%c")" + extraJScode='databaseResetDone = 0;' + echo "Stats were reset: $timeDateNow" > /tmp/connstatstitle.txt + WriteStats_ToJS /tmp/connstatstitle.txt "$SCRIPT_STORAGE_DIR/connstatstext.js" setConnmonStatsTitle statstitle "$extraJScode" + rm -f /tmp/connstatstitle.txt + } & fi } @@ -3221,8 +3257,10 @@ Menu_Install(){ MainMenu } -Menu_Startup(){ - if [ -z "$1" ]; then +Menu_Startup() +{ + if [ $# -eq 0 ] || [ -z "$1" ] + then Print_Output true "Missing argument for startup, not starting $SCRIPT_NAME" "$WARN" exit 1 elif [ "$1" != "force" ]; then @@ -3747,7 +3785,8 @@ fi CSV_OUTPUT_DIR="$SCRIPT_STORAGE_DIR/csv" USER_SCRIPT_DIR="$SCRIPT_STORAGE_DIR/userscripts.d" -if [ -z "$1" ]; then +if [ $# -eq 0 ] || [ -z "$1" ] +then NTP_Ready Entware_Ready if [ ! -f /opt/bin/sqlite3 ]; then diff --git a/connmonstats_www.asp b/connmonstats_www.asp index 666d7f5..cac756f 100644 --- a/connmonstats_www.asp +++ b/connmonstats_www.asp @@ -1,5 +1,4 @@ - + @@ -35,8 +34,9 @@ diff --git a/connmonstats_www.js b/connmonstats_www.js index fd2ccec..a7af6b7 100644 --- a/connmonstats_www.js +++ b/connmonstats_www.js @@ -868,7 +868,6 @@ function redrawAllCharts() { } } - function sortTable(sorttext) { sortname = sorttext.replace('↑', '').replace('↓', '').trim(); var sorttype = 'number'; @@ -1369,15 +1368,29 @@ function getConfFile() { }); } -function getStatstitleFile() { +/**----------------------------------------**/ +/** Modified by Martinski W. [2024-Jul-14] **/ +/**----------------------------------------**/ +let databaseResetDone = 0; +function getStatstitleFile() +{ $j.ajax({ url: '/ext/connmon/connstatstext.js', dataType: 'script', error: function (xhr) { - setTimeout(getStatstitleFile, 1000); + setTimeout(getStatstitleFile, 2000); }, - success: function () { + success: function() + { setConnmonStatsTitle(); + if (databaseResetDone == 1) + { + currentNoCharts = 0; + $j('#Time_Format').val(getCookie('Time_Format', 'number')); + redrawAllCharts(); + databaseResetDone += 1; + } + setTimeout(getStatstitleFile, 4000); } }); } From c272dd5d3f031547f4457427ed0641984630746f Mon Sep 17 00:00:00 2001 From: Martinski <119833648+Martinski4GitHub@users.noreply.github.com> Date: Mon, 15 Jul 2024 00:42:43 -0700 Subject: [PATCH 4/4] Numerical comparison operator. Updated numerical comparison operator. --- connmonstats_www.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connmonstats_www.js b/connmonstats_www.js index a7af6b7..141a9c8 100644 --- a/connmonstats_www.js +++ b/connmonstats_www.js @@ -1383,7 +1383,7 @@ function getStatstitleFile() success: function() { setConnmonStatsTitle(); - if (databaseResetDone == 1) + if (databaseResetDone === 1) { currentNoCharts = 0; $j('#Time_Format').val(getCookie('Time_Format', 'number'));