1313# # Forked from https://github.com/jackyaz/uiDivStats ##
1414# # ##
1515# ##################################################################
16- # Last Modified: 2025-Jun-21
16+ # Last Modified: 2025-Nov-04
1717# ------------------------------------------------------------------
1818
1919# ################ Shellcheck directives ###############
3535
3636# ## Start of script variables ###
3737readonly SCRIPT_NAME=" uiDivStats"
38- readonly SCRIPT_VERSION=" v4.0.11 "
39- readonly SCRIPT_VERSTAG=" 25062121 "
40- SCRIPT_BRANCH=" master "
38+ readonly SCRIPT_VERSION=" v4.0.12 "
39+ readonly SCRIPT_VERSTAG=" 25110422 "
40+ SCRIPT_BRANCH=" develop "
4141SCRIPT_REPO=" https://raw.githubusercontent.com/AMTM-OSR/$SCRIPT_NAME /$SCRIPT_BRANCH "
4242readonly SCRIPT_DIR=" /jffs/addons/$SCRIPT_NAME .d"
4343readonly SCRIPT_CONF=" $SCRIPT_DIR /config"
@@ -68,7 +68,9 @@ readonly trimTMPOldsFile="${SCRIPT_USB_DIR}/uiDivStats_Olds.TMP"
6868readonly scriptVersRegExp=" v[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})"
6969readonly webPageFileRegExp=" user([1-9]|[1-2][0-9])[.]asp"
7070readonly webPageLineRegExp=" \{url: \" $webPageFileRegExp \" , tabName: \" $SCRIPT_NAME \" \}"
71- readonly scriptVERINFO=" [${SCRIPT_VERSION} _${SCRIPT_VERSTAG} , Branch: $SCRIPT_BRANCH ]"
71+ readonly branchxStr_TAG=" [Branch: $SCRIPT_BRANCH ]"
72+ readonly versionDev_TAG=" ${SCRIPT_VERSION} _${SCRIPT_VERSTAG} "
73+ readonly versionMod_TAG=" $SCRIPT_VERSION on $ROUTER_MODEL "
7274
7375readonly oneKByte=1024
7476readonly oneMByte=1048576
@@ -99,6 +101,7 @@ readonly CLEARFORMAT="\\e[0m"
99101readonly CLRct=" \033[0m"
100102readonly REDct=" \033[1;31m"
101103readonly GRNct=" \033[1;32m"
104+ readonly MGNTct=" \e[1;35m"
102105readonly CritIREDct=" \e[41m"
103106readonly CritBREDct=" \e[30;101m"
104107readonly PassBGRNct=" \e[30;102m"
@@ -129,7 +132,7 @@ Print_Output()
129132 " $PASS " ) prioNum=6 ;; # INFO#
130133 * ) prioNum=5 ;; # NOTICE#
131134 esac
132- logger -t " $SCRIPT_NAME " -p $prioNum " $2 "
135+ logger -t " ${ SCRIPT_NAME} _[ $$ ] " -p $prioNum " $2 "
133136 fi
134137 printf " ${BOLD}${3} %s${CLEARFORMAT} \n\n" " $2 "
135138}
@@ -956,7 +959,7 @@ Mount_WebUI()
956959 Get_WebUI_Page " $SCRIPT_DIR /uidivstats_www.asp"
957960 if [ " $MyWebPage " = " NONE" ]
958961 then
959- Print_Output true " **ERROR** Unable to mount $SCRIPT_NAME WebUI page, exiting " " $CRIT "
962+ Print_Output true " **ERROR** Unable to mount $SCRIPT_NAME WebUI page. " " $CRIT "
960963 Clear_Lock
961964 exit 1
962965 fi
@@ -2297,7 +2300,7 @@ _SQLGetDBLogTimeStamp_()
22972300{ printf " [$( date +" $sqlDBLogDateTime " ) ]" ; }
22982301
22992302# #----------------------------------------##
2300- # # Modified by Martinski W. [2025-Jun-21 ] ##
2303+ # # Modified by Martinski W. [2025-Jul-20 ] ##
23012304# #----------------------------------------##
23022305readonly errorMsgsRegExp=" Parse error|Runtime error|Error:"
23032306readonly corruptedBinExp=" Illegal instruction|SQLite header and source version mismatch"
@@ -2385,7 +2388,7 @@ _ApplyDatabaseSQLCmds_()
23852388 fi
23862389 if " $foundError " || " $foundLocked "
23872390 then
2388- Print_Output true " SQLite process ${resultStr} " " $ERR "
2391+ Print_Output true " SQLite process[ $callFlag ] ${resultStr} " " $ERR "
23892392 fi
23902393}
23912394
@@ -2752,26 +2755,55 @@ _WaitForYESorNO_()
27522755 fi
27532756}
27542757
2758+ # #-------------------------------------##
2759+ # # Added by Martinski W. [2025-Oct-25] ##
2760+ # #-------------------------------------##
2761+ _CenterTextStr_ ()
2762+ {
2763+ if [ $# -lt 2 ] || [ -z " $1 " ] || [ -z " $2 " ] || \
2764+ ! echo " $2 " | grep -qE " ^[1-9][0-9]+$"
2765+ then echo ; return 1
2766+ fi
2767+ local stringLen=" ${# 1} "
2768+ local space1Len=" $(( ($2 - stringLen)/ 2 )) "
2769+ local space2Len=" $space1Len "
2770+ local totalLen=" $(( space1 Len + stringLen + space2 Len)) "
2771+
2772+ if [ " $totalLen " -lt " $2 " ]
2773+ then space2Len=" $(( space2 Len + 1 )) "
2774+ elif [ " $totalLen " -gt " $2 " ]
2775+ then space1Len=" $(( space1 Len - 1 )) "
2776+ fi
2777+ if [ " $space1Len " -gt 0 ] && [ " $space2Len " -gt 0 ]
2778+ then printf " %*s%s%*s" " $space1Len " ' ' " $1 " " $space2Len " ' '
2779+ else printf " %s" " $1 "
2780+ fi
2781+ }
2782+
2783+ # #----------------------------------------##
2784+ # # Modified by Martinski W. [2025-Oct-25] ##
2785+ # #----------------------------------------##
27552786ScriptHeader ()
27562787{
27572788 clear
2758- printf " \\ n"
2759- printf " ${BOLD} ###################################################################${CLEARFORMAT} \\ n"
2760- printf " ${BOLD} ## ##${CLEARFORMAT} \\ n"
2761- printf " ${BOLD} ## _ _____ _ _____ _ _ ##${CLEARFORMAT} \\ n"
2762- printf " ${BOLD} ## (_)| __ \ (_) / ____|| | | | ##${CLEARFORMAT} \\ n"
2763- printf " ${BOLD} ## _ _ _ | | | | _ __ __| (___ | |_ __ _ | |_ ___ ##${CLEARFORMAT} \\ n"
2764- printf " ${BOLD} ## | | | || || | | || |\ \ / / \___ \ | __|/ _ || __|/ __| ##${CLEARFORMAT} \\ n"
2765- printf " ${BOLD} ## | |_| || || |__| || | \ V / ____) || |_| (_| || |_ \__ \ ##${CLEARFORMAT} \\ n"
2766- printf " ${BOLD} ## \__,_||_||_____/ |_| \_/ |_____/ \__|\__,_| \__||___/ ##${CLEARFORMAT} \\ n"
2767- printf " ${BOLD} ## ##${CLEARFORMAT} \\ n"
2768- printf " ${BOLD} ## %9s on %-18s ##${CLEARFORMAT} \n" " $SCRIPT_VERSION " " $ROUTER_MODEL "
2769- printf " ${BOLD} ## ##${CLEARFORMAT} \\ n"
2770- printf " ${BOLD} ## https://github.com/AMTM-OSR/uiDivStats ##${CLEARFORMAT} \\ n"
2771- printf " ${BOLD} ## Forked from https://github.com/jackyaz/uiDivStats ##${CLEARFORMAT} \\ n"
2772- printf " ${BOLD} ## ##${CLEARFORMAT} \\ n"
2773- printf " ${BOLD} ###################################################################${CLEARFORMAT} \\ n"
2774- printf " \\ n"
2789+ local spaceLen=61 colorCT
2790+ [ " $SCRIPT_BRANCH " = " master" ] && colorCT=" $GRNct " || colorCT=" $MGNTct "
2791+ echo
2792+ printf " ${BOLD} ###################################################################${CLRct} \n"
2793+ printf " ${BOLD} ## _ _____ _ _____ _ _ ##${CLRct} \n"
2794+ printf " ${BOLD} ## (_)| __ \ (_) / ____|| | | | ##${CLRct} \n"
2795+ printf " ${BOLD} ## _ _ _ | | | | _ __ __| (___ | |_ __ _ | |_ ___ ##${CLRct} \n"
2796+ printf " ${BOLD} ## | | | || || | | || |\ \ / / \___ \ | __|/ _ || __|/ __| ##${CLRct} \n"
2797+ printf " ${BOLD} ## | |_| || || |__| || | \ V / ____) || |_| (_| || |_ \__ \ ##${CLRct} \n"
2798+ printf " ${BOLD} ## \__,_||_||_____/ |_| \_/ |_____/ \__|\__,_| \__||___/ ##${CLRct} \n"
2799+ printf " ${BOLD} ## ##${CLRct} \n"
2800+ printf " ${BOLD} ## ${GRNct} %s${CLRct}${BOLD} ##${CLRct} \n" " $( _CenterTextStr_ " $versionMod_TAG " " $spaceLen " ) "
2801+ printf " ${BOLD} ## ${colorCT} %s${CLRct}${BOLD} ##${CLRct} \n" " $( _CenterTextStr_ " $branchxStr_TAG " " $spaceLen " ) "
2802+ printf " ${BOLD} ## ##${CLRct} \n"
2803+ printf " ${BOLD} ## https://github.com/AMTM-OSR/uiDivStats ##${CLRct} \n"
2804+ printf " ${BOLD} ## Forked from https://github.com/jackyaz/uiDivStats ##${CLRct} \n"
2805+ printf " ${BOLD} ## ##${CLRct} \n"
2806+ printf " ${BOLD} ###################################################################${CLRct} \n\n"
27752807}
27762808
27772809# #----------------------------------------##
@@ -3165,6 +3197,7 @@ Menu_Startup()
31653197 Auto_Cron delete 2> /dev/null
31663198 /opt/etc/init.d/S90taildns stop > /dev/null 2>&1
31673199 fi
3200+ Set_Version_Custom_Settings local " $SCRIPT_VERSION "
31683201 Auto_ServiceEvent create 2> /dev/null
31693202 Shortcut_Script create
31703203 Mount_WebUI
@@ -3373,25 +3406,36 @@ Menu_Uninstall()
33733406 Print_Output true " Uninstall completed" " $PASS "
33743407}
33753408
3409+ # #----------------------------------------##
3410+ # # Modified by Martinski W. [2025-Jul-27] ##
3411+ # #----------------------------------------##
33763412NTP_Ready ()
33773413{
3414+ local theSleepDelay=15 ntpMaxWaitSecs=600 ntpWaitSecs
3415+
33783416 if [ " $( nvram get ntp_ready) " -eq 0 ]
33793417 then
33803418 Check_Lock
3381- ntpwaitcount=0
3382- while [ " $( nvram get ntp_ready) " -eq 0 ] && [ " $ntpwaitcount " -lt 600 ]
3419+ ntpWaitSecs=0
3420+ Print_Output true " Waiting for NTP to sync..." " $WARN "
3421+
3422+ while [ " $( nvram get ntp_ready) " -eq 0 ] && [ " $ntpWaitSecs " -lt " $ntpMaxWaitSecs " ]
33833423 do
3384- ntpwaitcount=" $(( ntpwaitcount + 30 )) "
3385- Print_Output true " Waiting for NTP to sync..." " $WARN "
3386- sleep 30
3424+ if [ " $ntpWaitSecs " -gt 0 ] && [ " $(( ntpWaitSecs % 30 )) " -eq 0 ]
3425+ then
3426+ Print_Output true " Waiting for NTP to sync [$ntpWaitSecs secs]..." " $WARN "
3427+ fi
3428+ sleep " $theSleepDelay "
3429+ ntpWaitSecs=" $(( ntpWaitSecs + theSleepDelay)) "
33873430 done
3388- if [ " $ntpwaitcount " -ge 600 ]
3431+
3432+ if [ " $ntpWaitSecs " -ge " $ntpMaxWaitSecs " ]
33893433 then
33903434 Print_Output true " NTP failed to sync after 10 minutes. Please resolve!" " $CRIT "
33913435 Clear_Lock
33923436 exit 1
33933437 else
3394- Print_Output true " NTP synced, $ SCRIPT_NAME will now continue" " $PASS "
3438+ Print_Output true " NTP has synced [ $ntpWaitSecs secs]. $ SCRIPT_NAME will now continue. " " $PASS "
33953439 Clear_Lock
33963440 fi
33973441 fi
@@ -3403,7 +3447,7 @@ NTP_Ready()
34033447# #----------------------------------------##
34043448Entware_Ready ()
34053449{
3406- local theSleepDelay=5 maxSleepTimer=100 sleepTimerSecs
3450+ local theSleepDelay=5 maxSleepTimer=120 sleepTimerSecs
34073451 local doExitNotFound=true
34083452
34093453 if [ $# -eq 1 ] && [ " $1 " = " false" ]
@@ -3422,11 +3466,12 @@ Entware_Ready()
34223466 do
34233467 if [ " $(( sleepTimerSecs % 10 )) " -eq 0 ]
34243468 then
3425- Print_Output true " Entware NOT found, sleeping for $theSleepDelay secs [$sleepTimerSecs secs]..." " $WARN "
3469+ Print_Output true " Entware NOT found. Wait for Entware to be ready [$sleepTimerSecs secs]..." " $WARN "
34263470 fi
34273471 sleep " $theSleepDelay "
34283472 sleepTimerSecs=" $(( sleepTimerSecs + theSleepDelay)) "
34293473 done
3474+
34303475 if [ ! -f /opt/bin/opkg ]
34313476 then
34323477 if " $doExitNotFound "
@@ -3438,7 +3483,7 @@ Entware_Ready()
34383483 Clear_Lock ; return 1
34393484 fi
34403485 else
3441- Print_Output true " Entware found, $ SCRIPT_NAME will now continue" " $PASS "
3486+ Print_Output true " Entware found [ $sleepTimerSecs secs]. $ SCRIPT_NAME will now continue. " " $PASS "
34423487 Clear_Lock
34433488 fi
34443489 fi
@@ -3450,8 +3495,8 @@ Entware_Ready()
34503495# #----------------------------------------##
34513496Show_About ()
34523497{
3498+ printf " About ${MGNTct}${SCRIPT_VERS_INFO}${CLRct} \n"
34533499 cat << EOF
3454- About $SCRIPT_VERS_INFO
34553500 $SCRIPT_NAME provides a graphical representation of domain
34563501 blocking performed by Diversion.
34573502
@@ -3474,8 +3519,8 @@ EOF
34743519# #----------------------------------------##
34753520Show_Help ()
34763521{
3522+ printf " HELP ${MGNTct}${SCRIPT_VERS_INFO}${CLRct} \n"
34773523 cat << EOF
3478- HELP $SCRIPT_VERS_INFO
34793524Available commands:
34803525 $SCRIPT_NAME about explains functionality
34813526 $SCRIPT_NAME update checks for updates
@@ -3490,8 +3535,8 @@ Available commands:
34903535 $SCRIPT_NAME trimdb run maintenance on database (this runs automatically every night)
34913536 $SCRIPT_NAME enableprocs re-enable background processing of Diversion statistics
34923537 $SCRIPT_NAME disableprocs disable background processing of Diversion statistics
3493- $SCRIPT_NAME develop switch to development branch
3494- $SCRIPT_NAME stable switch to stable branch
3538+ $SCRIPT_NAME develop switch to development branch version
3539+ $SCRIPT_NAME stable switch to stable/production branch version
34953540EOF
34963541 printf " \n"
34973542}
@@ -3509,9 +3554,9 @@ else sqlDBLogFilePath="/tmp/var/tmp/$sqlDBLogFileName"
35093554fi
35103555_SQLCheckDBLogFileSize_
35113556
3512- if [ " $SCRIPT_BRANCH " ! = " develop " ]
3557+ if [ " $SCRIPT_BRANCH " = " master " ]
35133558then SCRIPT_VERS_INFO=" "
3514- else SCRIPT_VERS_INFO=" $scriptVERINFO "
3559+ else SCRIPT_VERS_INFO=" [ $versionDev_TAG ] "
35153560fi
35163561
35173562dbBackgProcsEnabled=" $( _ToggleBackgroundProcsEnabled_ check) "
@@ -3541,6 +3586,7 @@ then
35413586 Auto_Cron delete 2> /dev/null
35423587 /opt/etc/init.d/S90taildns stop > /dev/null 2>&1
35433588 fi
3589+ Set_Version_Custom_Settings local " $SCRIPT_VERSION "
35443590 Auto_ServiceEvent create 2> /dev/null
35453591 Shortcut_Script create
35463592 _CheckFor_WebGUI_Page_
@@ -3559,7 +3605,8 @@ case "$1" in
35593605 exit 0
35603606 ;;
35613607 startup)
3562- Menu_Startup " $2 "
3608+ shift
3609+ Menu_Startup " $@ "
35633610 exit 0
35643611 ;;
35653612 generate)
0 commit comments