summaryrefslogtreecommitdiffstats
path: root/package/base-files/files/lib/config/validate_config.awk
blob: 053694efdadcdc543596eddf51e68fe5cda40fec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# AWK file for validating uci specification files
#
# Copyright (C) 2006 by Fokus Fraunhofer <carsten.tittel@fokus.fraunhofer.de>
#
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
function is_int(value) {
	valid = 1
	if (value !~ /^[0-9]*$/) { valid = 0 }
	return valid
}

function is_netmask(value) {
	return is_ip(value)
}

function is_ip(value) {
	valid = 1
	if ((value != "") && (value !~ /^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/)) valid = 0
	else {
		split(value, ipaddr, "\\.")
		for (i = 1; i <= 4; i++) {
			if ((ipaddr[i] < 0) || (ipaddr[i] > 255)) valid = 0
		}
	}
	return valid
}

function is_wep(value) {
	valid = 1
	if (value !~ /^[0-9A-Fa-f]*$/) {
		valid = 0
	} else if ((length(value) != 0) && (length(value) != 10) && (length(value) != 26)) {
		valid = 0
	} else if (value ~ /0$/) {
		valid = 0
	}
	return valid
}

function is_hostname(value) {
	valid = 1
	if (value !~ /^[0-9a-zA-z\.\-]*$/) {
		valid = 0
	}
	return valid;
}

function is_string(value) {
	return 1;
}

function is_mac(value) {
	valid = 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
	}
	return valid
}

function is_port(value) {
	valid = 1
	if (value !~ /^[0-9]*$/) {
		valid = 0
	}
	return valid
}

function is_ports(value) {
	valid = 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
		}
	}
	return valid
}

function is_wpapsk(value) {
	valid = 1
	if (length(value) > 64) {
		valid = 0
	}
	if ((length(value) != 0) && (length(value) < 8)) {
		valid = 0
	}
	if ((length(value) == 64) && (value ~ /[^0-9a-fA-F]/)) {
		valid = 0
	}
	return valid
}