Repository navigation
Expand file tree
/
Copy pathmodify-webui.sh
More file actions
254 lines (211 loc) · 11.9 KB
/
Copy pathmodify-webui.sh
File metadata and controls
254 lines (211 loc) · 11.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/bin/sh
# Made by Jack'lul <jacklul.github.io>
#
# Apply custom tweaks to the WebUI
#
#jas-update=modify-webui.sh
#shellcheck shell=ash
#shellcheck disable=SC2155
#shellcheck source=./common.sh
readonly common_script="$(dirname "$0")/common.sh"
if [ -f "$common_script" ]; then . "$common_script"; else { echo "$common_script not found" >&2; exit 1; } fi
# List of all tweaks: cpu_temperature guest_wifi_qr_code notrendmicro_support https_lanport_allow_443 no_https_redirect
TWEAKS="cpu_temperature guest_wifi_qr_code" # list of tweaks to apply
TMP_WWW_DIR="$state_file-www" # directory to store modified files in
load_script_config
sed_and_check() {
local _md5sum="$(md5sum "$4" | awk '{print $1}')"
sed_helper "$1" "$2" "$3" "$4"
if [ "$_md5sum" != "$(md5sum "$4" | awk '{print $1}')" ]; then
return 0
fi
logecho "Failed to apply modification to '$(basename "$4")': '$1' '$2' '$3'" error
return 1
}
#shellcheck disable=SC2016
cpu_temperature() {
local _applied
case "$1" in
"set")
if ! mount | grep -Fq /www/cpu_ram_status.asp; then
[ ! -f "$TMP_WWW_DIR/cpu_ram_status.asp" ] && cp -f /www/cpu_ram_status.asp "$TMP_WWW_DIR/cpu_ram_status.asp"
echo "cpuTemp = '<%get_cpu_temperature();%>';" >> "$TMP_WWW_DIR/cpu_ram_status.asp"
_applied=1
mount --bind "$TMP_WWW_DIR/cpu_ram_status.asp" /www/cpu_ram_status.asp
fi
if ! mount | grep -Fq /www/device-map/router_status.asp; then
mkdir -p "$TMP_WWW_DIR/device-map"
[ ! -f "$TMP_WWW_DIR/device-map/router_status.asp" ] && cp -f /www/device-map/router_status.asp "$TMP_WWW_DIR/device-map/router_status.asp"
sed_and_check replace 'render_CPU(cpuInfo);' 'render_CPU(cpuInfo, cpuTemp);' "$TMP_WWW_DIR/device-map/router_status.asp" && \
sed_and_check replace 'function(cpu_info_new)' 'function(cpu_info_new, cpu_temp_new)' "$TMP_WWW_DIR/device-map/router_status.asp" && \
sed_and_check append 'Object.keys(cpu_info_new).length;' '$("#cpu_temp").html(parseFloat(cpu_temp_new).toFixed(1));' "$TMP_WWW_DIR/device-map/router_status.asp" && \
sed_and_check prepend "('#cpu_field').html(code);" "code += '<div class=\"info-block\">Temperature: <span id=\"cpu_temp\"></span> °C</div>';" "$TMP_WWW_DIR/device-map/router_status.asp" && \
_applied=1
mount --bind "$TMP_WWW_DIR/device-map/router_status.asp" /www/device-map/router_status.asp
fi
;;
"unset")
if mount | grep -Fq /www/cpu_ram_status.asp; then
umount /www/cpu_ram_status.asp
rm -f "$TMP_WWW_DIR/cpu_ram_status.asp"
fi
if mount | grep -Fq /www/device-map/router_status.asp; then
umount /www/device-map/router_status.asp
rm -f "$TMP_WWW_DIR/device-map/router_status.asp"
fi
;;
esac
[ -n "$_applied" ] && return 0 || return 1
}
guest_wifi_qr_code() {
local _applied
case "$1" in
"set")
if ! mount | grep -Fq /www/Guest_network.asp; then
[ ! -f "$TMP_WWW_DIR/Guest_network.asp" ] && cp -f /www/Guest_network.asp "$TMP_WWW_DIR/Guest_network.asp"
sed_and_check append '<script type="text/javascript" src="js/httpApi.js"></script>' '<script src="https://cdn.rawgit.com/davidshimjs/qrcodejs/gh-pages/qrcode.min.js"></script>' "$TMP_WWW_DIR/Guest_network.asp" && \
sed_and_check append 'onclick="applyRule();">' '<br><span id="qr_code" style="display:inline-block;margin:25px 0 25px 0;"></span>' "$TMP_WWW_DIR/Guest_network.asp" && \
sed_and_check replace 'gn_array[i][4];' "'Hidden'" "$TMP_WWW_DIR/Guest_network.asp" && \
sed_and_check replace 'gn_array[i][key_index];' "'Hidden'" "$TMP_WWW_DIR/Guest_network.asp" && \
sed_and_check append 'updateMacModeOption()' 'var qrstring="WIFI:S:"+document.form.wl_ssid.value+";";document.form.wl_wpa_psk.value&&0<document.form.wl_wpa_psk.value.length?qrstring+="T:WPA;P:"+document.form.wl_wpa_psk.value+";":qrstring+="T:nopass;",1==document.form.wl_closed[0].checked&&(qrstring+="H:true;"),document.getElementById("qr_code").innerHTML="",new QRCode(document.getElementById("qr_code"),{text:qrstring+";",width:500,height:500});' "$TMP_WWW_DIR/Guest_network.asp" && \
_applied=1
mount --bind "$TMP_WWW_DIR/Guest_network.asp" /www/Guest_network.asp
fi
;;
"unset")
if mount | grep -Fq /www/Guest_network.asp; then
umount /www/Guest_network.asp
rm -f "$TMP_WWW_DIR/Guest_network.asp"
fi
;;
esac
[ -n "$_applied" ] && return 0 || return 1
}
notrendmicro_support() {
local _applied
case "$1" in
"set")
if ! mount | grep -Fq /www/state.js; then
[ ! -f "$TMP_WWW_DIR/state.js" ] && cp -f /www/state.js "$TMP_WWW_DIR/state.js"
sed_and_check append 'var lyra_hide_support = isSupport("lyra_hide")' 'var notrendmicro_support = isSupport("notrendmicro");' "$TMP_WWW_DIR/state.js" && \
_applied=1
mount --bind "$TMP_WWW_DIR/state.js" /www/state.js
fi
# Doesn't matter if this is Merlin firmware and menuTree.js was already modified, we can still reference it by orignal path since it will be mounted
if ! mount | grep -Fq /www/require/modules/menuTree.js || ! grep -Fq 'notrendmicro_support' /www/require/modules/menuTree.js; then
mkdir -p "$TMP_WWW_DIR/require/modules"
[ ! -f "$TMP_WWW_DIR/require/modules/menuTree.js" ] && cp -f /www/require/modules/menuTree.js "$TMP_WWW_DIR/require/modules/menuTree.js"
local inetspeed_tab="$(grep -F 'url: "AdaptiveQoS_InternetSpeed.asp' /www/require/modules/menuTree.js | tail -n 1)"
if [ -n "$inetspeed_tab" ]; then
sed_and_check replace '{url: "AdaptiveQoS_InternetSpeed.asp"' '//{url: "AdaptiveQoS_InternetSpeed.asp"' "$TMP_WWW_DIR/require/modules/menuTree.js" && \
sed_and_check append '{url: "Advanced_Smart_Connect.asp' "$inetspeed_tab" "$TMP_WWW_DIR/require/modules/menuTree.js"
else
logecho "There was a problem performing modification on file '$TMP_WWW_DIR/require/modules/menuTree.js': unable to find line containing 'AdaptiveQoS_InternetSpeed'!" error
fi
sed_and_check prepend 'return menuTree;' 'menuTree.exclude.menus=function(){var t=menuTree.exclude.menus;return function(){var e=t.apply(this,arguments);return!ParentalCtrl2_support&¬rendmicro_support&&e.push("menu_ParentalControl"),notrendmicro_support&&(e.push("menu_AiProtection"),e.push("menu_BandwidthMonitor")),e}}(),menuTree.exclude.tabs=function(){var t=menuTree.exclude.tabs;return function(){var e=t.apply(this,arguments);return notrendmicro_support&&(e.push("AiProtection_HomeProtection.asp"),e.push("AiProtection_MaliciousSitesBlocking.asp"),e.push("AiProtection_IntrusionPreventionSystem.asp"),e.push("AiProtection_InfectedDevicePreventBlock.asp"),e.push("AiProtection_AdBlock.asp"),e.push("AiProtection_Key_Guard.asp"),e.push("AdaptiveQoS_ROG.asp"),e.push("AiProtection_WebProtector.asp"),e.push("AdaptiveQoS_Bandwidth_Monitor.asp"),e.push("QoS_EZQoS.asp"),e.push("AdaptiveQoS_WebHistory.asp"),e.push("AdaptiveQoS_ROG.asp"),e.push("Advanced_QOSUserPrio_Content.asp"),e.push("Advanced_QOSUserRules_Content.asp"),e.push("AdaptiveQoS_Adaptive.asp"),e.push("TrafficAnalyzer_Statistic.asp"),e.push("AdaptiveQoS_TrafficLimiter.asp")),e}}();' "$TMP_WWW_DIR/require/modules/menuTree.js" && \
_applied=1
if is_merlin_firmware; then # but copy our modification to /tmp/menuTree.js and remount it
cp -f "$TMP_WWW_DIR/require/modules/menuTree.js" /tmp/menuTree.js
umount /www/require/modules/menuTree.js 2> /dev/null
mount --bind /tmp/menuTree.js /www/require/modules/menuTree.js
else
mount --bind "$TMP_WWW_DIR/require/modules/menuTree.js" /www/require/modules/menuTree.js
fi
fi
;;
"unset")
if is_merlin_firmware || [ -f /tmp/menuTree.js ]; then
logecho "Unable to revert 'notrendmicro_support' tweak on Asuswrt-Merlin firmware - reboot is required!" error
return
fi
if mount | grep -Fq /www/state.js; then
umount /www/state.js
rm -f "$TMP_WWW_DIR/state.js"
fi
if mount | grep -Fq /www/require/modules/menuTree.js; then
umount /www/require/modules/menuTree.js
rm -f "$TMP_WWW_DIR/require/modules/menuTree.js"
fi
;;
esac
[ -n "$_applied" ] && return 0 || return 1
}
https_lanport_allow_443() {
local _applied
case "$1" in
"set")
if ! mount | grep -Fq /www/Advanced_System_Content.asp; then
[ ! -f "$TMP_WWW_DIR/Advanced_System_Content.asp" ] && cp -f /www/Advanced_System_Content.asp "$TMP_WWW_DIR/Advanced_System_Content.asp"
sed_and_check replace '&& !validator.range(document.form.https_lanport, 1024, 65535) &&' "&& (document.form.https_lanport.value != 443 && !validator.range(document.form.https_lanport, 1024, 65535)) &&" "$TMP_WWW_DIR/Advanced_System_Content.asp" && \
_applied=1
mount --bind "$TMP_WWW_DIR/Advanced_System_Content.asp" /www/Advanced_System_Content.asp
fi
;;
"unset")
if mount | grep -Fq /www/Advanced_System_Content.asp; then
umount /www/Advanced_System_Content.asp
rm -f "$TMP_WWW_DIR/Advanced_System_Content.asp"
fi
;;
esac
[ -n "$_applied" ] && return 0 || return 1
}
no_https_redirect() {
local _applied
case "$1" in
"set")
if ! mount | grep -Fq /www/js/https_redirect/https_redirect.js; then
mkdir -p "$TMP_WWW_DIR/js/https_redirect"
[ ! -f "$TMP_WWW_DIR/js/https_redirect/https_redirect.js" ] && cp -f /www/js/https_redirect/https_redirect.js "$TMP_WWW_DIR/js/https_redirect/https_redirect.js"
sed_and_check replace 'Initial_Https_Redirect();' '//Initial_Https_Redirect();' "$TMP_WWW_DIR/js/https_redirect/https_redirect.js" && \
_applied=1
mount --bind "$TMP_WWW_DIR/js/https_redirect/https_redirect.js" /www/js/https_redirect/https_redirect.js
fi
;;
"unset")
if mount | grep -Fq /www/js/https_redirect/https_redirect.js; then
umount /www/js/https_redirect/https_redirect.js
rm -f "$TMP_WWW_DIR/js/https_redirect/https_redirect.js"
fi
;;
esac
[ -n "$_applied" ] && return 0 || return 1
}
www_override() {
case "$1" in
"set")
[ -z "$TWEAKS" ] && { logecho "Error: No tweaks to apply" error; exit 1; }
mkdir -p "$TMP_WWW_DIR"
local _tweak _applied
for _tweak in $TWEAKS; do
$_tweak set && _applied="$_applied $_tweak"
done
[ -n "$_applied" ] && logecho "Applied WebUI tweaks: $(echo "$_applied" | awk '{$1=$1};1')" alert
;;
"unset")
logecho "Removing WebUI tweaks..." alert
cpu_temperature unset
guest_wifi_qr_code unset
notrendmicro_support unset
https_lanport_allow_443 unset
no_https_redirect unset
rm -fr "$TMP_WWW_DIR"
;;
esac
}
case "$1" in
"start")
www_override set
;;
"stop")
www_override unset
;;
"restart")
sh "$script_path" stop
sh "$script_path" start
;;
*)
echo "Usage: $0 start|stop|restart"
exit 1
;;
esac