#!/usr/bin/webif-page -p /bin/sh ### # # FreeWLAN Addons - http://www.freewlan.info # # This Script is based on the original La Fonera Firmware version 0.7.1r2 # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA # # http://www.gnu.org/copyleft/gpl.html # ### . /usr/lib/webif/webif.sh validate <>|max=10|$FORM_submit EOF if [ "$?" != "0" ] then FORM_submit="" fi sel_upgrade=1 . /usr/lib/webif/advanced.sh header "Upgrade_Title#Firmware upgrade and hotfix installation" display_form <>" ps | grep N50chillispot | awk '{ print $1 }' | xargs kill -KILL ps | grep -vE 'Command|init|\[[kbmj]|httpd|haserl|bstrip|bin/sh|awk|kill|ps|webif|watchdog' | awk '{ print $1 }' | xargs kill -KILL MEMFREE="$(awk 'BEGIN{ mem = 0 } ($1 == "MemFree:") || ($1 == "Cached:") {mem += int($2)} END{print mem}' /proc/meminfo)" echo "@TR<>$MEMFREE" CWD=$(pwd) cd /jffs echo "@TR<>" tar czf /tmp/config.tar.gz /etc/config/ mtd write /tmp/config.tar.gz config > /dev/null cd $CWD } do_upgrade() { # echo "$(date +%Y%M%d)upgrade" >> /tmp/upgrade_log.txt if [ -f /tmp/do_not_verify ]; then rm /tmp/do_not_verify fi bstrip "$BOUNDARY" | ( dd bs=4 count=1 > /tmp/upgrade.fon 2> /dev/null MAGIC_NUMBER=$(cat /tmp/upgrade.fon) if [ "$MAGIC_NUMBER" = "FON3" ]; then echo "

@TR<>" echo "@TR<>" echo "

"
			stop_services_and_save_configuration
			touch /tmp/restart_on_failure
			cat >> /tmp/upgrade.fon
		elif [ "$MAGIC_NUMBER" = "FON4" ]; then
			cat >> /tmp/upgrade.fon
		else
			echo "

@TR<>

" echo "

@TR<here to return to the index page>>

" footer touch /tmp/do_not_verify exit 1 fi ) if [ -f /tmp/do_not_verify ]; then rm /tmp/do_not_verify exit 1 fi /bin/fonverify /etc/public_fon_rsa_key.der /tmp/upgrade.fon RESULT=$? echo "
" if [ "$RESULT" -eq 0 ]; then echo -n "@TR<>" if [ "$MAGIC_NUMBER" = "FON1" ]; then echo "

...

" else echo "

@TR<here to return to the index page>>

" fi else echo -n "@TR<>" echo "

@TR<>

" if [ ! -f /tmp/restart_on_failure ]; then echo "

@TR<here to return to the index page>>

" else echo "
@TR<>
" for script in /etc/init.d/S[23456789]* /etc/init.d/N*; do $script start > /dev/null 2> /dev/null done echo "
@TR<>
" fi fi footer } read_var() { NAME="" while :; do read LINE LINE="${LINE%%[^0-9A-Za-z]}" equal "$LINE" "$BOUNDARY" && read LINE empty "$NAME$LINE" && exit case "${LINE%%:*}" in Content-Disposition) NAME="${LINE##*; name=\"}" NAME="${NAME%%\"*}" ;; esac empty "$LINE" && return done } cat < function statusupdate() { document.getElementById("form_submit").style.display = "none"; document.getElementById("status_text").style.display = "inline"; return true; } function printStatus() { document.write(''); } EOF display_form <> end_row add_row add_fileinput_cell|firmware end_row add_row call_js|printStatus add_input_submit_button|submit|@TR<>|statusupdate end_row end_table end_form EOF equal "$REQUEST_METHOD" "POST" && { equal "${CONTENT_TYPE%%;*}" "multipart/form-data" || ERR=1 BOUNDARY="${CONTENT_TYPE##*boundary=}" empty "$BOUNDARY" && ERR=1 empty "$ERR" || { echo "@TR<>" footer exit } cat <
EOF
	while :; do
		read_var
		empty "$NAME" && exit
		case "$NAME" in
			erase_fs)
				ERASE_FS=1
				bstrip "$BOUNDARY" > /dev/null
			;;
			firmware) do_upgrade;;
		esac
	done
cat <
EOF

}

footer