function start_form(title, field_opts) {
- print "<div class=\"settings\">"
+ print "<div class=\"settings\"" field_opts ">"
if (title != "") print "<div class=\"settings-title\"><h3><strong>" title "</strong></h3></div>"
print "<div class=\"settings-content\">"
}
gsub(/^[ \t]+/,"",$1)
}
-($1 != "") && ($1 !~ /^option/) {
+($1 != "") && ($1 !~ /^option/) && (select_open == 1) {
select_open = 0
print "</select>"
}
rootdir=/cgi-bin/webif
indexpage=index.sh
-# workarounds for stupid busybox fork/exec on [ ]
+# workarounds for stupid busybox slowness on [ ]
empty() {
case "$1" in
"") return 0 ;;
*) return 255 ;;
esac
}
+# very crazy, but also very fast :-)
+exists() {
+ ( < $1 ) 2>&-
+}
categories() {
grep '##WEBIF:' $cgidir/.categories $cgidir/*.sh 2>/dev/null | \
_uptime="${_uptime#*up }"
_uptime="${_uptime%%,*}"
_hostname=$(cat /proc/sys/kernel/hostname)
- _version=$(cat /etc/banner | grep "(")
+ _version=$( grep "(" /etc/banner )
_version="${_version%% ---*}"
_head="${3:+<div class=\"settings-block-title\"><h2>$3$_saved_title</h2></div>}"
_form="${5:+<form enctype=\"multipart/form-data\" action=\"$5\" method=\"post\"><input type="hidden" name="submit" value="1" />}"
case ${SERVER_SOFTWARE%% *} in
busybox)
echo -n '/cgi-bin/webif:' > /etc/httpd.conf
- cat /etc/passwd | grep root | cut -d: -f1,2 >> /etc/httpd.conf
+ grep root /etc/passwd | cut -d: -f1,2 >> /etc/httpd.conf
killall -HUP httpd
;;
esac
}
display_form() {
- echo "$1" | awk -F'|' -f /usr/lib/webif/common.awk -f /usr/lib/webif/form.awk
+ if empty "$1"; then
+ awk -F'|' -f /usr/lib/webif/common.awk -f /usr/lib/webif/form.awk
+ else
+ echo "$1" | awk -F'|' -f /usr/lib/webif/common.awk -f /usr/lib/webif/form.awk
+ fi
}
list_remove() {
}
load_settings() {
- [ \! "$1" = "nvram" -a -f /etc/config/$1 ] && . /etc/config/$1
- [ -f /tmp/.webif/config-$1 ] && . /tmp/.webif/config-$1
+ equal "$1" "nvram" || {
+ exists /etc/config/$1 && . /etc/config/$1
+ }
+ exists /tmp/.webif/config-$1 && . /tmp/.webif/config-$1
}
validate() {
- eval "$(echo "$1" | awk -f /usr/lib/webif/validate.awk)"
+ if empty "$1"; then
+ eval "$(awk -f /usr/lib/webif/validate.awk)"
+ else
+ eval "$(echo "$1" | awk -f /usr/lib/webif/validate.awk)"
+ fi
}
save_setting() {
- mkdir -p /tmp/.webif
+ exists /tmp/.webif/* || mkdir -p /tmp/.webif
oldval=$(eval "echo \${$2}")
oldval=${oldval:-$(nvram get "$2")}
grep "^$2=" /tmp/.webif/config-$1 >&- 2>&- && {
- mv /tmp/.webif/config-$1 /tmp/.webif/config-$1-old 2>&- >&-
- grep -v "^$2=" /tmp/.webif/config-$1-old > /tmp/.webif/config-$1 2>&-
+ grep -v "^$2=" /tmp/.webif/config-$1 > /tmp/.webif/config-$1-new 2>&-
+ mv /tmp/.webif/config-$1-new /tmp/.webif/config-$1 2>&- >&-
oldval=""
}
equal "$oldval" "$3" || echo "$2=\"$3\"" >> /tmp/.webif/config-$1
- rm -f /tmp/.webif/config-$1-old
}
+is_bcm947xx() {
+ read _systype < /proc/cpuinfo
+ equal "${_systype##* }" "BCM947XX"
+}
}
done
CONFIGFILES=""
- for configname in $(ls file-* 2>&-); do
- CONFIGFILES="$CONFIGFILES ${configname#file-}"
+ for configname in file-*; do
+ exists "$configname" && CONFIGFILES="$CONFIGFILES ${configname#file-}"
done
CONFIGFILES="${CONFIGFILES:+<h3 style="display:inline">Config files: </h3>$CONFIGFILES<br />}"
echo $CONFIGFILES
<?
. /usr/lib/webif/webif.sh
-[ -f /tmp/.webif/file-hosts ] && HOSTS_FILE=/tmp/.webif/file-hosts || HOSTS_FILE=/etc/hosts
-[ -f /tmp/.webif/file-ethers ] && ETHERS_FILE=/tmp/.webif/file-ethers || ETHERS_FILE=/etc/ethers
-touch $HOSTS_FILE $ETHERS_FILE >&- 2>&-
+exists /tmp/.webif/file-hosts && HOSTS_FILE=/tmp/.webif/file-hosts || HOSTS_FILE=/etc/hosts
+exists /tmp/.webif/file-ethers && ETHERS_FILE=/tmp/.webif/file-ethers || ETHERS_FILE=/etc/ethers
+exists $HOSTS_FILE || touch $HOSTS_FILE >&- 2>&-
+exists $ETHERS_FILE || touch $ETHERS_FILE >&- 2>&-
update_hosts() {
- mkdir -p /tmp/.webif
+ exists /tmp/.webif/* || mkdir -p /tmp/.webif
awk -v "mode=$1" -v "ip=$2" -v "name=$3" '
BEGIN {
FS="[ \t]"
}
END {
if ((mode == "add") && (host_added == 0)) print ip " " name
-}' - < "$HOSTS_FILE" > /tmp/.webif/file-hosts-new
+}' "$HOSTS_FILE" > /tmp/.webif/file-hosts-new
mv "/tmp/.webif/file-hosts-new" "/tmp/.webif/file-hosts"
HOSTS_FILE=/tmp/.webif/file-hosts
}
update_ethers() {
- mkdir -p /tmp/.webif
+ exists /tmp/.webif/* || mkdir -p /tmp/.webif
case "$1" in
add)
grep -E -v "^[ \t]*$2" $ETHERS_FILE > /tmp/.webif/file-ethers-new
empty "$FORM_add_host" || {
# add a host to /etc/hosts
- validate "ip|FORM_host_ip|IP Address|required|$FORM_host_ip
-hostname|FORM_host_name|Hostname|required|$FORM_host_name" && update_hosts add "$FORM_host_ip" "$FORM_host_name"
+ validate <<EOF
+ip|FORM_host_ip|IP Address|required|$FORM_host_ip
+hostname|FORM_host_name|Hostname|required|$FORM_host_name
+EOF
+ equal "$?" 0 && update_hosts add "$FORM_host_ip" "$FORM_host_name"
}
empty "$FORM_add_dhcp" || {
# add a host to /etc/ethers
- validate "mac|FORM_dhcp_mac|MAC Address|required|$FORM_dhcp_mac
-ip|FORM_dhcp_ip|IP|required|$FORM_dhcp_ip" && update_ethers add "$FORM_dhcp_mac" "$FORM_dhcp_ip"
+ validate <<EOF
+mac|FORM_dhcp_mac|MAC Address|required|$FORM_dhcp_mac
+ip|FORM_dhcp_ip|IP|required|$FORM_dhcp_ip
+EOF
+ equal "$?" 0 && update_ethers add "$FORM_dhcp_mac" "$FORM_dhcp_ip"
}
+
empty "$FORM_remove_host" || update_hosts del "$FORM_remove_ip" "$FORM_remove_name"
empty "$FORM_remove_dhcp" || update_ethers del "$FORM_remove_mac"
<tbody>
<tr>
<td>Firmware Version</td>
- <td><? cat /etc/banner | grep "(" | cut -b-20 | cut -b2- ?></td>
+ <td><? grep "(" /etc/banner | cut -b-20 | cut -b2- ?></td>
</tr>
<tr>
<td>Kernel Version</td>
FORM_lan_gateway=${lan_gateway:-$(nvram get lan_gateway)}
else
SAVED=1
- validate "
+ validate <<EOF
ip|FORM_lan_ipaddr|LAN IP|required|$FORM_lan_ipaddr
netmask|FORM_lan_netmask|LAN network mask|required|$FORM_lan_netmask
-ip|FORM_lan_gateway|LAN gateway||$FORM_lan_gateway" && {
+ip|FORM_lan_gateway|LAN gateway||$FORM_lan_gateway
+EOF
+ equal "$?" 0 && {
save_setting network lan_ipaddr $FORM_lan_ipaddr
save_setting network lan_netmask $FORM_lan_netmask
save_setting network lan_gateway $FORM_lan_gateway
header "Network" "LAN" "LAN settings" '' "$SCRIPT_NAME"
-display_form "start_form|LAN Configuration
+display_form <<EOF
+start_form|LAN Configuration
field|IP Address
text|lan_ipaddr|$FORM_lan_ipaddr
field|Netmask
listedit|dns|$SCRIPT_NAME?|$FORM_dns|$FORM_dnsadd
helpitem|Note
helptext|You should save your settings on this page before adding/removing DNS servers
-end_form"
+end_form
+EOF
footer ?>
<!--
if empty "$FORM_submit"; then
FORM_hostname=${wan_hostname:-$(nvram get wan_hostname)}
FORM_hostname=${FORM_hostname:-OpenWrt}
- grep BCM947 /proc/cpuinfo 2>&- >&- && {
+ is_bcm947xx && {
FORM_boot_wait=${boot_wait:-$(nvram get boot_wait)}
FORM_boot_wait=${FORM_boot_wait:-off}
}
else
SAVED=1
- validate "hostname|FORM_hostname|Hostname|nodots required|$FORM_hostname" && {
+ validate <<EOF
+hostname|FORM_hostname|Hostname|nodots required|$FORM_hostname
+EOF
+ equal "$?" 0 && {
save_setting system wan_hostname $FORM_hostname
- grep BCM947 /proc/cpuinfo 2>&- >&- && {
+ is_bcm947xx && {
case "$FORM_boot_wait" in
on|off) save_setting nvram boot_wait $FORM_boot_wait;;
esac
header "System" "Settings" "System settings" '' "$SCRIPT_NAME"
-grep BCM947 /proc/cpuinfo 2>&- >&- && bootwait_form="field|boot_wait
+is_bcm947xx && bootwait_form="field|boot_wait
radio|boot_wait|$FORM_boot_wait|on|On<br />
radio|boot_wait|$FORM_boot_wait|off|Off"
-display_form "start_form|System settings
+display_form <<EOF
+start_form|System settings
field|Hostname
text|hostname|$FORM_hostname
$bootwait_form
field
-end_form"
+end_form
+EOF
footer ?>
;;
esac
- # FIXME: add validation for DNS server list
- validate "
+validate <<EOF
ip|FORM_wan_ipaddr|IP address|$V_IP|$FORM_wan_ipaddr
netmask|FORM_wan_netmask|network mask|$V_NM|$FORM_wan_netmask
ip|FORM_wan_gateway|gateway address||$FORM_wan_gateway
-ip|FORM_pptp_server_ip|PPTP server IP|$V_PPTP|$FORM_pptp_server_ip" && {
+ip|FORM_pptp_server_ip|PPTP server IP|$V_PPTP|$FORM_pptp_server_ip
+EOF
+ equal "$?" 0 && {
save_setting network wan_proto $FORM_wan_proto
# Settings specific to one protocol type
fi
header "Network" "WAN" "WAN settings" ' onLoad="modechange()" ' "$SCRIPT_NAME"
-?>
+
+cat <<EOF
<script type="text/javascript" src="/webif.js "></script>
<script type="text/javascript">
<!--
}
-->
</script>
-<? display_form "start_form|WAN Configuration
+EOF
+
+display_form <<EOF
+start_form|WAN Configuration
field|Internet Connection Type
-radio|wan_proto|$FORM_wan_proto|none|None<br />|onchange=\"modechange()\"
-radio|wan_proto|$FORM_wan_proto|dhcp|DHCP<br />|onchange=\"modechange()\"
-radio|wan_proto|$FORM_wan_proto|static|Static IP<br />|onchange=\"modechange()\"
+radio|wan_proto|$FORM_wan_proto|none|None<br />|onchange="modechange()"
+radio|wan_proto|$FORM_wan_proto|dhcp|DHCP<br />|onchange="modechange()"
+radio|wan_proto|$FORM_wan_proto|static|Static IP<br />|onchange="modechange()"
$PPPOE_OPTION
$PPTP_OPTION
end_form
start_form|PPP Settings|ppp_settings|hidden
field|PPP Redial Policy|ppp_redial|hidden
-radio|ppp_redial|$FORM_ppp_redial|demand|Connect on Demand<br />|onChange=\"modechange()\"
-radio|ppp_redial|$FORM_ppp_redial|persist|Keep Alive|onChange=\"modechange()\"
+radio|ppp_redial|$FORM_ppp_redial|demand|Connect on Demand<br />|onChange="modechange()"
+radio|ppp_redial|$FORM_ppp_redial|persist|Keep Alive|onChange="modechange()"
field|Maximum Idle Time|ppp_demand_idletime|hidden
text|ppp_idletime|$FORM_ppp_idletime
field|Redial Timeout|ppp_persist_redialperiod|hidden
text|ppp_passwd|$FORM_ppp_passwd
field|PPP MTU|ppp_mtu|hidden
text|ppp_mtu|$FORM_ppp_mtu
-end_form"
+end_form
+EOF
footer ?>
<!--
psk) V_PSK="required";;
esac
- validate "
+ validate <<EOF
ip|FORM_radius_ipaddr|RADIUS IP address|$V_RADIUS|$FORM_radius_ipaddr
wep|FORM_key1|WEP key 1||$FORM_key1
wep|FORM_key2|WEP key 2||$FORM_key2
string|FORM_wpa_psk|WPA pre-shared key|min=8 max=63 $V_PSK|$FORM_wpa_psk
string|FORM_radius_key|RADIUS server key|min=4 max=63 $V_RADIUS|$FORM_radius_key
string|FORM_ssid|ESSID|required|$FORM_ssid
-int|FORM_channel|Channel|required min=1 max=$CHANNEL_MAX|$FORM_channel" && {
+int|FORM_channel|Channel|required min=1 max=$CHANNEL_MAX|$FORM_channel
+EOF
+ equal "$?" 0 && {
if equal "$FORM_mode" adhoc; then
FORM_mode=sta
EOF
-display_form "start_form|Wireless Configuration
+display_form <<EOF
+start_form|Wireless Configuration
field|ESSID
text|ssid|$FORM_ssid
helpitem|ESSID
select|channel|$FORM_channel
$F_CHANNELS
field|Mode
-radio|mode|$FORM_mode|ap|Access Point<br />|onChange=\"modechange()\"
-radio|mode|$FORM_mode|sta|Client <br />|onChange=\"modechange()\"
-radio|mode|$FORM_mode|wet|Bridge <br />|onChange=\"modechange()\"
-radio|mode|$FORM_mode|adhoc|Ad-Hoc|onChange=\"modechange()\"
+radio|mode|$FORM_mode|ap|Access Point<br />|onChange="modechange()"
+radio|mode|$FORM_mode|sta|Client <br />|onChange="modechange()"
+radio|mode|$FORM_mode|wet|Bridge <br />|onChange="modechange()"
+radio|mode|$FORM_mode|adhoc|Ad-Hoc|onChange="modechange()"
helpitem|Mode
helptext|Operation mode
helplink|http://wiki.openwrt.org/OpenWrtDocs/Configuration#head-7126c5958e237d603674b3a9739c9d23bdfdb293
end_form
start_form|Encryption settings
field|Encryption type
-radio|encryption|$FORM_encryption|off|Disabled <br />|onChange=\"modechange()\"
-radio|encryption|$FORM_encryption|wep|WEP <br />|onChange=\"modechange()\"
-radio|encryption|$FORM_encryption|psk|WPA (preshared key) <br />|onChange=\"modechange()\"
-radio|encryption|$FORM_encryption|wpa|WPA (RADIUS)|onChange=\"modechange()\"
+radio|encryption|$FORM_encryption|off|Disabled <br />|onChange="modechange()"
+radio|encryption|$FORM_encryption|wep|WEP <br />|onChange="modechange()"
+radio|encryption|$FORM_encryption|psk|WPA (preshared key) <br />|onChange="modechange()"
+radio|encryption|$FORM_encryption|wpa|WPA (RADIUS)|onChange="modechange()"
field|WPA support|wpa_support|hidden
checkbox|wpa1|$FORM_wpa1|wpa1|WPA1
checkbox|wpa2|$FORM_wpa2|wpa2|WPA2
listedit|wds|$SCRIPT_NAME?|$FORM_wds|$FORM_wdsadd
helpitem|Note
helptext|You should save your settings on this page before adding/removing WDS links
-end_form"
+end_form
+EOF
footer ?>
<!--