Skip to content

Commit 7cb9c34

Browse files
Merge pull request #436 from Martinski4GitHub/dev
Code Improvements
2 parents eb39050 + db12664 commit 7cb9c34

File tree

4 files changed

+92
-50
lines changed

4 files changed

+92
-50
lines changed

MerlinAU.asp

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<script language="JavaScript" type="text/javascript">
3030
3131
/**----------------------------**/
32-
/** Last Modified: 2025-Mar-29 **/
32+
/** Last Modified: 2025-Mar-30 **/
3333
/** Intended for 1.4.x Release **/
3434
/**----------------------------**/
3535
@@ -154,6 +154,7 @@ function FormatNumericSetting (formInput)
154154
/** Added by Martinski W. [2025-Jan-24] **/
155155
/**-------------------------------------**/
156156
const numberRegExp = '^[0-9]+$';
157+
const daysOfWeekNumbr = ['0', '1', '2', '3', '4', '5', '6'];
157158
const daysOfWeekNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
158159
const daysOfWeekRexpN = '([S|s]un|[M|m]on|[T|t]ue|[W|w]ed|[T|t]hu|[F|f]ri|[S|s]at)';
159160
const daysOfWeekRexp1 = `${daysOfWeekRexpN}|[0-6]`;
@@ -357,15 +358,24 @@ function ValidateScheduleDAYofWEEK (cronDAYofWEEK)
357358
{ return false; }
358359
}
359360
360-
/**-------------------------------------**/
361-
/** Added by Martinski W. [2025-Jan-25] **/
362-
/**-------------------------------------**/
361+
/**----------------------------------------**/
362+
/** Modified by Martinski W. [2025-Mar-30] **/
363+
/**----------------------------------------**/
363364
function GetListFromRangeDAYofWEEK (cronRangeDAYofWEEK)
364365
{
365-
let theDaysArray = [];
366+
let indexMin = 0, indexMax = 0, theDaysArray = [];
366367
let theDaysRange = cronRangeDAYofWEEK.split ('-');
367-
let indexMin = daysOfWeekNames.indexOf (theDaysRange[0]);
368-
let indexMax = daysOfWeekNames.indexOf (theDaysRange[1]);
368+
369+
if (theDaysRange[0].match ('[0-6]'))
370+
{ indexMin = daysOfWeekNumbr.indexOf (theDaysRange[0]); }
371+
else
372+
{ indexMin = daysOfWeekNames.indexOf (theDaysRange[0]); }
373+
374+
if (theDaysRange[1].match ('[0-6]'))
375+
{ indexMax = daysOfWeekNumbr.indexOf (theDaysRange[1]); }
376+
else
377+
{ indexMax = daysOfWeekNames.indexOf (theDaysRange[1]); }
378+
369379
for (var indx = indexMin; indx <= indexMax; indx++)
370380
{ theDaysArray.push (daysOfWeekNames[indx]) ; }
371381
return (theDaysArray.toString());
@@ -397,9 +407,9 @@ function GetCronDAYofWEEK (daysOfWeekIndex, daysOfWeekArray)
397407
return (theDaysOfWeek);
398408
}
399409
400-
/**-------------------------------------**/
401-
/** Added by Martinski W. [2025-Jan-25] **/
402-
/**-------------------------------------**/
410+
/**----------------------------------------**/
411+
/** Modified by Martinski W. [2025-Mar-30] **/
412+
/**----------------------------------------**/
403413
function SetScheduleDAYofWEEK (cronDAYofWEEK)
404414
{
405415
let fwScheduleDAYS1, fwSchedBoxDAYSX, fwScheduleXDAYS;
@@ -430,47 +440,47 @@ function SetScheduleDAYofWEEK (cronDAYofWEEK)
430440
ToggleDaysOfWeek (false, 'X');
431441
let theDAYofWEEK = cronDAYofWEEK;
432442
433-
if (cronDAYofWEEK.match (`${daysOfWeekRexpN}[-]${daysOfWeekRexpN}`) !== null)
443+
if (cronDAYofWEEK.match (`${daysOfWeekRexp2}`) !== null)
434444
{
435445
theDAYofWEEK = GetListFromRangeDAYofWEEK (cronDAYofWEEK);
436446
}
437-
if (theDAYofWEEK.match ('[,]?[M|m]on[,]?') !== null)
447+
if (theDAYofWEEK.match ('[,]?(1|[M|m]on)[,]?') !== null)
438448
{
439449
fwScheduleMON = document.getElementById('fwSched_MON');
440450
fwScheduleMON.checked = true;
441451
fwScheduleMON.disabled = false;
442452
}
443-
if (theDAYofWEEK.match ('[,]?[T|t]ue[,]?') !== null)
453+
if (theDAYofWEEK.match ('[,]?(2|[T|t]ue)[,]?') !== null)
444454
{
445455
fwScheduleTUE = document.getElementById('fwSched_TUE');
446456
fwScheduleTUE.checked = true;
447457
fwScheduleTUE.disabled = false;
448458
}
449-
if (theDAYofWEEK.match ('[,]?[W|w]ed[,]?') !== null)
459+
if (theDAYofWEEK.match ('[,]?(3|[W|w]ed)[,]?') !== null)
450460
{
451461
fwScheduleWED = document.getElementById('fwSched_WED');
452462
fwScheduleWED.checked = true;
453463
fwScheduleWED.disabled = false;
454464
}
455-
if (theDAYofWEEK.match ('[,]?[T|t]hu[,]?') !== null)
465+
if (theDAYofWEEK.match ('[,]?(4|[T|t]hu)[,]?') !== null)
456466
{
457467
fwScheduleTHU = document.getElementById('fwSched_THU');
458468
fwScheduleTHU.checked = true;
459469
fwScheduleTHU.disabled = false;
460470
}
461-
if (theDAYofWEEK.match ('[,]?[F|f]ri[,]?') !== null)
471+
if (theDAYofWEEK.match ('[,]?(5|[F|f]ri)[,]?') !== null)
462472
{
463473
fwScheduleFRI = document.getElementById('fwSched_FRI');
464474
fwScheduleFRI.checked = true;
465475
fwScheduleFRI.disabled = false;
466476
}
467-
if (theDAYofWEEK.match ('[,]?[S|s]at[,]?') !== null)
477+
if (theDAYofWEEK.match ('[,]?(6|[S|s]at)[,]?') !== null)
468478
{
469479
fwScheduleSAT = document.getElementById('fwSched_SAT');
470480
fwScheduleSAT.checked = true;
471481
fwScheduleSAT.disabled = false;
472482
}
473-
if (theDAYofWEEK.match ('[,]?[S|s]un[,]?') !== null)
483+
if (theDAYofWEEK.match ('[,]?(0|[S|s]un)[,]?') !== null)
474484
{
475485
fwScheduleSUN = document.getElementById('fwSched_SUN');
476486
fwScheduleSUN.checked = true;

MerlinAU.sh

Lines changed: 62 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Original Creation Date: 2023-Oct-01 by @ExtremeFiretop.
66
# Official Co-Author: @Martinski W. - Date: 2023-Nov-01
7-
# Last Modified: 2025-Mar-28
7+
# Last Modified: 2025-Mar-30
88
###################################################################
99
set -u
1010

@@ -6060,7 +6060,7 @@ _Set_FW_UpdatePostponementDays_()
60606060
}
60616061

60626062
##----------------------------------------##
6063-
## Modified by Martinski W. [2025-Jan-22] ##
6063+
## Modified by Martinski W. [2025-Mar-29] ##
60646064
##----------------------------------------##
60656065
_TranslateCronSchedHR_()
60666066
{
@@ -6105,6 +6105,7 @@ _TranslateCronSchedHR_()
61056105
theCronHOUR="$(echo "$1" | awk -F ' ' '{print $2}')"
61066106
theCronDAYM="$(echo "$1" | awk -F ' ' '{print $3}')"
61076107
theCronDAYW="$(echo "$1" | awk -F ' ' '{print $5}')"
6108+
theCronDAYW="$(_ConvertDayOfWeekToHR_ "$theCronDAYW")"
61086109

61096110
if [ "$theCronDAYW" = "*" ] && [ "$theCronDAYM" = "*" ]
61106111
then
@@ -6269,26 +6270,62 @@ _ValidateCronScheduleHOUR_()
62696270
}
62706271

62716272
##-------------------------------------##
6272-
## Added by Martinski W. [2024-Nov-23] ##
6273+
## Added by Martinski W. [2025-Mar-29] ##
6274+
##-------------------------------------##
6275+
_ConvertDAYW_NumberToName_()
6276+
{ echo "$1" | sed 's/0/Sun/g;s/1/Mon/g;s/2/Tue/g;s/3/Wed/g;s/4/Thu/g;s/5/Fri/g;s/6/Sat/g' ; }
6277+
6278+
##-------------------------------------##
6279+
## Added by Martinski W. [2024-Nov-24] ##
62736280
##-------------------------------------##
6281+
_ConvertDAYW_NameToNumber_()
6282+
{
6283+
if [ $# -eq 0 ] && [ -z "$1" ] ; then echo ; return 1; fi
6284+
echo "$1" | sed 's/[Ss]un/0/g;s/[Mm]on/1/g;s/[Tt]ue/2/g;s/[Ww]ed/3/g;s/[Tt]hu/4/g;s/[Ff]ri/5/g;s/[Ss]at/6/g'
6285+
}
6286+
6287+
##----------------------------------------##
6288+
## Modified by Martinski W. [2025-Mar-29] ##
6289+
##----------------------------------------##
62746290
_ConvertDAYW_NumToName_()
62756291
{
62766292
if [ $# -eq 0 ] && [ -z "$1" ] ; then echo ; return 1; fi
6277-
local rangeDays rangeFreq
6293+
local daysOfWeek rangeDays rangeFreq
6294+
6295+
if ! echo "$1" | grep -q "/" && \
6296+
echo "$1" | grep -q "[0-6]"
6297+
then
6298+
daysOfWeek="$(_ConvertDAYW_NumberToName_ "$1")"
6299+
echo "$daysOfWeek"
6300+
return 0
6301+
fi
6302+
62786303
rangeDays="$(echo "$1" | awk -F '/' '{print $1}')"
62796304
rangeFreq="$(echo "$1" | awk -F '/' '{print $2}')"
6280-
rangeDays="$(echo "$rangeDays" | sed 's/0/Sun/g;s/1/Mon/g;s/2/Tue/g;s/3/Wed/g;s/4/Thu/g;s/5/Fri/g;s/6/Sat/g')"
6305+
rangeDays="$(_ConvertDAYW_NumberToName_ "$rangeDays")"
62816306
if [ -z "$rangeFreq" ]
62826307
then echo "$rangeDays"
62836308
else echo "${rangeDays}/$rangeFreq"
62846309
fi
62856310
return 0
62866311
}
62876312

6288-
_ConvertDAYW_NameToNum_()
6313+
##-------------------------------------##
6314+
## Added by Martinski W. [2025-Mar-29] ##
6315+
##-------------------------------------##
6316+
_ConvertDayOfWeekToHR_()
62896317
{
62906318
if [ $# -eq 0 ] && [ -z "$1" ] ; then echo ; return 1; fi
6291-
echo "$1" | sed 's/[Ss]un/0/g;s/[Mm]on/1/g;s/[Tt]ue/2/g;s/[Ww]ed/3/g;s/[Tt]hu/4/g;s/[Ff]ri/5/g;s/[Ss]at/6/g'
6319+
local daysOfWeek="$1"
6320+
if echo "$1" | grep -qE "^[fmstw]"
6321+
then
6322+
daysOfWeek="$(_CapitalizeFirstChar_ "$1")"
6323+
elif ! echo "$1" | grep -q '[*/]' && \
6324+
echo "$1" | grep -q "[0-6]"
6325+
then
6326+
daysOfWeek="$(_ConvertDAYW_NumToName_ "$1")"
6327+
fi
6328+
echo "$daysOfWeek"
62926329
return 0
62936330
}
62946331

@@ -6301,7 +6338,7 @@ _ValidateCronNumOrderDAYW_()
63016338
local numDAYS numDays1 numDays2
63026339
if ! echo "$1" | grep -qE "[a-zA-Z]"
63036340
then numDAYS="$1"
6304-
else numDAYS="$(_ConvertDAYW_NameToNum_ "$1")"
6341+
else numDAYS="$(_ConvertDAYW_NameToNumber_ "$1")"
63056342
fi
63066343
numDays1="$(echo "$numDAYS" | awk -F '[-/]' '{print $1}')"
63076344
numDays2="$(echo "$numDAYS" | awk -F '[-/]' '{print $2}')"
@@ -6341,19 +6378,19 @@ _ValidateCronScheduleDAYofWEEK_()
63416378
return 1
63426379
}
63436380

6344-
##-------------------------------------##
6345-
## Added by Martinski W. [2024-Nov-24] ##
6346-
##-------------------------------------##
6381+
##----------------------------------------##
6382+
## Modified by Martinski W. [2025-Mar-30] ##
6383+
##----------------------------------------##
63476384
#----------------------------------------------------------#
63486385
# Allow ONLY full numbers within the range [1-31]
6349-
# some intervals [ * */[2-9] */10 */12 */15 ],
6386+
# some intervals [ * */[2-9] */10 */12 */14 */15 ],
63506387
# lists and ranges for the purposes of doing F/W Updates.
63516388
#----------------------------------------------------------#
63526389
_ValidateCronScheduleDAYofMONTH_()
63536390
{
63546391
if [ $# -eq 0 ] || [ -z "$1" ] ; then return 1 ; fi
63556392
if [ "$1" = "*" ] || \
6356-
echo "$1" | grep -qE "^[*]/([2-9]|10|12|15)$"
6393+
echo "$1" | grep -qE "^[*]/([2-9]|10|12|14|15)$"
63576394
then return 0 ; fi
63586395
if echo "$1" | grep -qE "^${CRON_DAYofMONTH_RegEx}$"
63596396
then
@@ -6369,8 +6406,8 @@ _ValidateCronScheduleDAYofMONTH_()
63696406
fi
63706407
fi
63716408
printf "\n${REDct}INVALID cron value for 'DAY of MONTH' [$1]${NOct}\n"
6372-
printf "${REDct}NOTE${NOct}: Only numbers within the range [1-31],\n"
6373-
printf "specific intervals (* */[2-9] */10 */12 */15),\n"
6409+
printf "${REDct}NOTE${NOct}: Only numbers within the range [1-31], some\n"
6410+
printf "specific intervals (* */[2-9] */10 */12 */14 */15),\n"
63746411
printf "lists of numbers, and single ranges are valid.\n"
63756412
return 1
63766413
}
@@ -6530,14 +6567,14 @@ _ShowCronMenuHeader_()
65306567
}
65316568

65326569
##----------------------------------------##
6533-
## Modified by Martinski W. [2024-Dec-20] ##
6570+
## Modified by Martinski W. [2025-Mar-29] ##
65346571
##----------------------------------------##
65356572
_GetCronScheduleInputDAYofMONTH_()
65366573
{
65376574
if [ $# -eq 0 ] || [ -z "$1" ] ; then return 1 ; fi
65386575
local oldSchedDAYM newSchedDAYM oldSchedDAYHR
65396576

6540-
_GetSchedDaysHR_()
6577+
_GetSchedDayOfMonthHR_()
65416578
{
65426579
local cruDAYS="$1"
65436580
[ "$1" = "*" ] && cruDAYS="Every day"
@@ -6546,7 +6583,7 @@ _GetCronScheduleInputDAYofMONTH_()
65466583

65476584
newSchedDAYM=""
65486585
oldSchedDAYM="$1"
6549-
oldSchedDAYHR="$(_GetSchedDaysHR_ "$1")"
6586+
oldSchedDAYHR="$(_GetSchedDayOfMonthHR_ "$1")"
65506587

65516588
while true
65526589
do
@@ -6578,7 +6615,7 @@ _GetCronScheduleInputDAYofMONTH_()
65786615
}
65796616

65806617
##----------------------------------------##
6581-
## Modified by Martinski W. [2024-Dec-20] ##
6618+
## Modified by Martinski W. [2025-Mar-29] ##
65826619
##----------------------------------------##
65836620
_GetCronScheduleInputDAYofWEEK_()
65846621
{
@@ -6588,7 +6625,7 @@ _GetCronScheduleInputDAYofWEEK_()
65886625
_DayOfWeekNumToDayName_()
65896626
{ echo "$1" | sed 's/0/Sun/;s/1/Mon/;s/2/Tue/;s/3/Wed/;s/4/Thu/;s/5/Fri/;s/6/Sat/;' ; }
65906627

6591-
_GetSchedDaysHR_()
6628+
_GetSchedDayOfWeekHR_()
65926629
{
65936630
local cruDAYS="$1"
65946631
if [ "$1" = "*" ]
@@ -6601,7 +6638,7 @@ _GetCronScheduleInputDAYofWEEK_()
66016638

66026639
newSchedDAYW=""
66036640
oldSchedDAYW="$1"
6604-
oldSchedDAYHR="$(_GetSchedDaysHR_ "$1")"
6641+
oldSchedDAYHR="$(_GetSchedDayOfWeekHR_ "$1")"
66056642

66066643
while true
66076644
do
@@ -6622,22 +6659,17 @@ _GetCronScheduleInputDAYofWEEK_()
66226659
then
66236660
newSchedDAYW="$oldSchedDAYW"
66246661
if _ValidateCronScheduleDAYofWEEK_ "$oldSchedDAYW"
6625-
then break #Keep Current Value#
6662+
then #Keep Current Value#
6663+
newSchedDAYW="$(_ConvertDayOfWeekToHR_ "$oldSchedDAYW")"
6664+
break
66266665
fi
66276666
elif _CheckForCancelAndExitMenu_ "$newSchedDAYW" || \
66286667
_CheckForReturnToBeginMenu_ "$newSchedDAYW" || \
66296668
_CheckForSavedThenExitMenu_ "$newSchedDAYW"
66306669
then break
66316670
elif _ValidateCronScheduleDAYofWEEK_ "$newSchedDAYW"
66326671
then
6633-
if echo "$newSchedDAYW" | grep -qE "[fmstw]"
6634-
then
6635-
newSchedDAYW="$(_CapitalizeFirstChar_ "$newSchedDAYW")"
6636-
elif ! echo "$newSchedDAYW" | grep -q '[*/]' && \
6637-
echo "$newSchedDAYW" | grep -q "[0-6]"
6638-
then
6639-
newSchedDAYW="$(_ConvertDAYW_NumToName_ "$newSchedDAYW")"
6640-
fi
6672+
newSchedDAYW="$(_ConvertDayOfWeekToHR_ "$newSchedDAYW")"
66416673
break
66426674
fi
66436675
_WaitForEnterKey_

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MerlinAU - AsusWRT-Merlin Firmware Auto Updater
22
## v1.4.0
3-
## 2025-Mar-29
3+
## 2025-Mar-30
44

55
## WebUI:
66
![image](https://github.com/user-attachments/assets/10d0971c-b3c6-477a-8904-d4bf013f72df)

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
1.4.0
2-
25032921
2+
25033001

0 commit comments

Comments
 (0)