Dabombber
Senior Member
Most people are probably like me where they don't check random settings like Remote WebUI Access ever again once they've disabled it. And given that it's possibly been enabled without them knowing (like me >.<), I figured it'd be useful to show a warning for it.
It might be necessary to run 'service restart_httpd' after running the script.
If you leave the created file in the jffs directory it should survive a reboot but the bind won't, so you can either link to, or just put the whole thing in jffs/scripts/init-start.
To undo the changes it makes, you can run the command 'umount /www/notification.js', and delete the file/directories it made (/jffs/www/notification.js).
Code:
#!/bin/sh
NOTIFILE="/jffs/www/notification.js"
MAGICNUMBER=20
_quote() {
printf "%s\n" "$1" | sed 's/[]\/$*.^&[]/\\&/g'
}
str_append() {
PATTERN="$(_quote "$1")"
CONTENT="$(_quote "$2")"
sed -i "s/$PATTERN/&$CONTENT/" "$3"
}
line_append() {
PATTERN="$(_quote "$1")"
CONTENT="$(_quote "$2")"
sed -i -e "/$PATTERN/a\\" -e "$CONTENT" "$3"
}
line_prepend() {
PATTERN="$(_quote "$1")"
CONTENT="$(_quote "$2")"
sed -i -e "/$PATTERN/i\\" -e "$CONTENT" "$3"
}
file_append() {
printf "%s\n" "$1" >> "$2"
}
# Remove any stale file
TIMESTAMP="$(date -r "/www/notification.css")"
if [ -e "$NOTIFILE" ]; then
if ! grep -Fq "$TIMESTAMP" "$NOTIFILE"; then
mount | grep -Fq "/www/notification.js" && umount "/www/notification.js"
rm "$NOTIFILE"
else
# Up to date, nothing to do here
unset TIMESTAMP
fi
fi
# Make new file
if [ -n "$TIMESTAMP" ]; then
mkdir -p "$(dirname "$NOTIFILE")"
cp "/www/notification.js" "$NOTIFILE"
# Add WebUI stuff where samba stuff is
line_append "var enable_samba" "var misc_http_x = '<% nvram_get(\"misc_http_x\"); %>';" "$NOTIFILE"
line_append "samba: 0," "webuiwan: 0," "$NOTIFILE"
str_append "notification.ftp ,notification.samba" " ,notification.webuiwan" "$NOTIFILE"
str_append "&& !notification.samba" " && !notification.webuiwan" "$NOTIFILE"
line_prepend "st_samba_force_mode == ''" "if(misc_http_x != 0){notification.array[${MAGICNUMBER}] = 'noti_webuiwan'; notification.webuiwan = 1; notification.desc[${MAGICNUMBER}] = 'Your WebUI is currently accessable from the internet. We strongly recommend that you disable [ Enable Web Access from WAN ] to avoid security risk.'; notification.action_desc[${MAGICNUMBER}] = 'Change now'; notification.clickCallBack[${MAGICNUMBER}] = \"location.href = 'Advanced_System_Content.asp';\";}else{notification.webuiwan = 0;}" "$NOTIFILE"
str_append "|| notification.samba" " || notification.webuiwan" "$NOTIFILE"
line_append "this.samba = 0;" "this.webuiwan = 0;" "$NOTIFILE"
file_append "// Source timestamp: $TIMESTAMP" "$NOTIFILE"
fi
# Mount over stock file
if ! mount | grep -Fq "/www/notification.js"; then
mount -o bind "$NOTIFILE" "/www/notification.js"
fi
If you leave the created file in the jffs directory it should survive a reboot but the bind won't, so you can either link to, or just put the whole thing in jffs/scripts/init-start.
To undo the changes it makes, you can run the command 'umount /www/notification.js', and delete the file/directories it made (/jffs/www/notification.js).
Attachments
Last edited: