Added support for 2.6.27 kernel
[openwrt.git] / package / base-files / files / lib / config / validate_config.awk
1 # AWK file for validating uci specification files
2 #
3 # Copyright (C) 2006 by Fokus Fraunhofer <carsten.tittel@fokus.fraunhofer.de>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #
19 function is_int(value) {
20 valid = 1
21 if (value !~ /^[0-9]*$/) { valid = 0 }
22 return valid
23 }
24
25 function is_netmask(value) {
26 return is_ip(value)
27 }
28
29 function is_ip(value) {
30 valid = 1
31 if ((value != "") && (value !~ /^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/)) valid = 0
32 else {
33 split(value, ipaddr, "\\.")
34 for (i = 1; i <= 4; i++) {
35 if ((ipaddr[i] < 0) || (ipaddr[i] > 255)) valid = 0
36 }
37 }
38 return valid
39 }
40
41 function is_wep(value) {
42 valid = 1
43 if (value !~ /^[0-9A-Fa-f]*$/) {
44 valid = 0
45 } else if ((length(value) != 0) && (length(value) != 10) && (length(value) != 26)) {
46 valid = 0
47 } else if (value ~ /0$/) {
48 valid = 0
49 }
50 return valid
51 }
52
53 function is_hostname(value) {
54 valid = 1
55 if (value !~ /^[0-9a-zA-z\.\-]*$/) {
56 valid = 0
57 }
58 return valid;
59 }
60
61 function is_string(value) {
62 return 1;
63 }
64
65 function is_mac(value) {
66 valid = 1
67 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]$/)) {
68 valid = 0
69 }
70 return valid
71 }
72
73 function is_port(value) {
74 valid = 1
75 if (value !~ /^[0-9]*$/) {
76 valid = 0
77 }
78 return valid
79 }
80
81 function is_ports(value) {
82 valid = 1
83 n = split(value ",", ports, ",")
84 for (i = 1; i <= n; i++) {
85 if ((ports[i] !~ /^[0-9]*$/) && (ports[i] !~ /^[0-9][0-9]*-[0-9][0-9]*$/)) {
86 valid = 0
87 }
88 }
89 return valid
90 }
91
92 function is_wpapsk(value) {
93 valid = 1
94 if (length(value) > 64) {
95 valid = 0
96 }
97 if ((length(value) != 0) && (length(value) < 8)) {
98 valid = 0
99 }
100 if ((length(value) == 64) && (value ~ /[^0-9a-fA-F]/)) {
101 valid = 0
102 }
103 return valid
104 }
105
This page took 0.058822 seconds and 5 git commands to generate.