### # # 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 # ### # $1 = type # $2 = variable name # $3 = field name # $4 = options # $5 = value BEGIN { FS="|" output="" } { valid_type = 0 valid = 1 # if ( $0 ~ /\|@$|['`"$%&()]/ ) { if ( $0 ~ /\|@$|['`"$]/ ) { valid = 0 verr = "@TR<>" } else { # XXX: weird hack, but it works... n = split($0, param, "|") value = param[5] for (i = 6; i <= n; i++) value = value FS param[i] verr = "" } } $1 == "int" { valid_type = 1 if (value !~ /^[0-9]*$/) { valid = 0; verr = "@TR<>" } } $1 == "string" { valid_type = 1 } # FIXME: add proper netmask validation ($1 == "ip") || ($1 == "netmask") { valid_type = 1 if (value != "") { if (value !~ /^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/) valid = 0 else { split(value, ipaddr, "\\.") if ((ipaddr[1] == 0) && ($2 != "FORM_pptp_server")) valid = 0 counter = 0 for (i = 1; i <= 4; i++) { if ((ipaddr[i] < 0) || (ipaddr[i] > 255)) valid = 0 if ((ipaddr[i] == 255) && ($2 != "FORM_netmask")) counter++ } if (counter == 4) valid = 0 } if (valid == 0) verr = "@TR<>" } } $1 == "wep" { valid_type = 1 if (value !~ /^[0-9A-Fa-f]*$/) { valid = 0 verr = "@TR<>" } else if ((length(value) != 0) && (length(value) != 10) && (length(value) != 26)) { valid = 0 verr = "@TR<>" } } $1 == "hostname" { valid_type = 1 if (value !~ /^[a-zA-Z]+[0-9a-zA-Z\-_]*$/) { valid = 0 verr = "@TR<>" } } $1 == "essid" { valid_type = 1 if (value !~ /^[a-zA-Z]*$/) { valid = 0 verr = "@TR<>" } } $1 == "mac" { valid_type = 1 if ((value != "") && (value !~ /^[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]$/)) { valid = 0 verr = "@TR<>" } } $1 == "port" { valid_type = 1 if (value !~ /^[0-9]*$/) { valid = 0 verr = "@TR<>" } if (value > 65535) { valid = 0 verr = "@TR<>" } } $1 == "ports" { valid_type = 1 n = split(value ",", ports, ",") for (i = 1; i <= n; i++) { if ((ports[i] !~ /^[0-9]*$/) && (ports[i] !~ /^[0-9][0-9]*-[0-9][0-9]*$/)) { valid = 0 verr = "@TR<>" } } } $1 == "wpapsk" { valid_type = 1 if (length(value) > 64) { valid = 0 verr = "@TR<>" } if ((length(value) != 0) && (length(value) < 8)) { valid = 0 verr = "@TR<>" } if ((length(value) == 64) && (value ~ /[^0-9a-fA-F]/)) { valid = 0 verr = "@TR<>" } } $1 == "submit" { valid_type = 1 if (value !~ /[S|s]ubmit/) { valid = 0 verr = "@TR<>" } } $1 == "bool" { valid_type = 1 if (value !~ /^[01]$/) { valid = 0 verr = "@TR<>" } } $1 == "add_remove" { valid_type = 1 if (value !~ /^(add|remove)$/) { valid = 0 verr = "@TR<>" } } $1 == "tcp_udp" { valid_type = 1 if (value !~ /^(tcp|udp|both)$/) { valid = 0 verr = "@TR<>" } } $1 == "chk_bgmode" { valid_type = 1 if (value !~ /^(g|b|mixed)$/) { valid = 0 verr = "@TR<>" } } $1 == "chk_channel" { valid_type = 1 if (value !~ /^([01][0-9]|auto)$/) { valid = 0 verr = "@TR<>" } } $1 == "conn_type" { valid_type = 1 if (value !~ /^(dhcp|static|pppoe|pptp|wlan)$/) { valid = 0 verr = "@TR<>" } } $1 == "chk_auth" { valid_type = 1 if (value !~ /^(wpa|wpa2|mixed|wep|open)$/) { valid = 0 verr = "@TR<>" } } $1 == "chk_crypto" { valid_type = 1 if (value !~ /^(tkip\+aes|tkip|aes)$/) { valid = 0 verr = "@TR<>" } } $1 == "url" { valid_type = 1 if (value !~ /^(http):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}((:[0-9]{1,5})?\/.*)?$/i) { valid = 0 verr = "@TR<>" } } $1 == "dyndns" { valid_type = 1 if (value !~ /^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/i) { valid = 0 verr = "@TR<>" } } $1 == "mac_addr" { valid_type = 1 if (value !~ /^([0-9A-F]{2}:){5}[0-9A-F]{2}$/) { valid = 0 verr = "@TR<>" } } $1 == "mail" { valid_type = 1 if (value !~ /^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,5}$/) { valid = 0 verr = "@TR<>" } } valid_type != 1 { valid = 0 } valid == 1 { n = split($4, options, " ") for (i = 1; (valid == 1) && (i <= n); i++) { if (options[i] == "required") { if (value == "") { valid = 0; verr = "@TR<>" } } else if ((options[i] ~ /^min=/) && (value != "")) { min = options[i] sub(/^min=/, "", min) min = int(min) if ($1 == "int") { if (value < min) { valid = 0; verr = "@TR<>" min ")" } } else if ($1 == "string") { if (length(value) < min) { valid = 0; verr = "@TR<>" min ")"} } } else if ((options[i] ~ /^max=/) && (value != "")) { max = options[i] sub(/^max=/, "", max) max = int(max) if ($1 == "int") { if (value > max) { valid = 0; verr = "@TR<> (@TR<>: " max ")" } } else if ($1 == "string") { if (length(value) > max) { valid = 0; verr = "@TR<> (@TR<>: " max ")" } } } else if ((options[i] == "nodots") && ($1 == "hostname")) { if (value ~ /\./) { valid = 0 verr = "@TR<>" } } } } valid_type == 1 { if (valid == 1) output = output $2 "=\"" value "\";\n" else error = error "@TR<> " $3 ": " verr "
" } END { print output "ERROR=\"" error "\";\n" if (error == "") print "return 0" else print "return 255" }