inc/dns.inc.php
author peter
Fri, 26 Sep 2008 10:02:33 +0000
changeset 194 df674d004508
parent 193 6a87ca695244
child 200 6bdfaba077cb
permissions -rw-r--r--
[feladat @ 307] Minor bug fix: bg.shiny@gmail.com reported that cyrillic characters where not supported. Applied the patch which was supplied. This closes #93.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
71
e1b918eaf69a [feladat @ 118]
peter
parents: 65
diff changeset
     1
<?php
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
     2
119
f74e4f88b680 [feladat @ 222]
rejo
parents: 97
diff changeset
     3
/*  Poweradmin, a friendly web-based admin tool for PowerDNS.
47
ae140472d97c [feladat @ 94]
rejo
parents: 16
diff changeset
     4
 *  See <https://rejo.zenger.nl/poweradmin> for more details.
ae140472d97c [feladat @ 94]
rejo
parents: 16
diff changeset
     5
 *
ae140472d97c [feladat @ 94]
rejo
parents: 16
diff changeset
     6
 *  Copyright 2007, 2008  Rejo Zenger <rejo@zenger.nl>
ae140472d97c [feladat @ 94]
rejo
parents: 16
diff changeset
     7
 *
ae140472d97c [feladat @ 94]
rejo
parents: 16
diff changeset
     8
 *  This program is free software: you can redistribute it and/or modify
ae140472d97c [feladat @ 94]
rejo
parents: 16
diff changeset
     9
 *  it under the terms of the GNU General Public License as published by
ae140472d97c [feladat @ 94]
rejo
parents: 16
diff changeset
    10
 *  the Free Software Foundation, either version 3 of the License, or
ae140472d97c [feladat @ 94]
rejo
parents: 16
diff changeset
    11
 *  (at your option) any later version.
ae140472d97c [feladat @ 94]
rejo
parents: 16
diff changeset
    12
 *
ae140472d97c [feladat @ 94]
rejo
parents: 16
diff changeset
    13
 *  This program is distributed in the hope that it will be useful,
ae140472d97c [feladat @ 94]
rejo
parents: 16
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ae140472d97c [feladat @ 94]
rejo
parents: 16
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ae140472d97c [feladat @ 94]
rejo
parents: 16
diff changeset
    16
 *  GNU General Public License for more details.
ae140472d97c [feladat @ 94]
rejo
parents: 16
diff changeset
    17
 *
ae140472d97c [feladat @ 94]
rejo
parents: 16
diff changeset
    18
 *  You should have received a copy of the GNU General Public License
ae140472d97c [feladat @ 94]
rejo
parents: 16
diff changeset
    19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
ae140472d97c [feladat @ 94]
rejo
parents: 16
diff changeset
    20
 */
ae140472d97c [feladat @ 94]
rejo
parents: 16
diff changeset
    21
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    22
function validate_input($zid, $type, &$content, &$name, &$prio, &$ttl) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    23
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    24
	$zone = get_zone_name_from_id($zid);				// TODO check for return
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    25
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    26
	if (!(preg_match("/$zone$/i", $name))) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    27
		if (isset($name) && $name != "") {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    28
			$name = $name . "." . $zone;
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    29
		} else {
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    30
			$name = $zone;
97
090be08858db [feladat @ 197]
rejo
parents: 96
diff changeset
    31
		}
96
35cd9e082b90 [feladat @ 196]
rejo
parents: 95
diff changeset
    32
	}
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    33
	
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    34
	switch ($type) {
96
35cd9e082b90 [feladat @ 196]
rejo
parents: 95
diff changeset
    35
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    36
		case "A":
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    37
			if (!is_valid_ipv4($content)) return false;
164
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
    38
			if (!is_valid_hostname_fqdn($name,1)) return false;
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    39
			break;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    40
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    41
		case "AAAA":
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    42
			if (!is_valid_ipv6($content)) return false;
164
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
    43
			if (!is_valid_hostname_fqdn($name,1)) return false;
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    44
			break;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    45
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    46
		case "CNAME":
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    47
			if (!is_valid_rr_cname_name($name)) return false;
164
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
    48
			if (!is_valid_hostname_fqdn($name,1)) return false;
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    49
			if (!is_valid_hostname_fqdn($content,0)) return false;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    50
			break;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    51
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    52
		case "HINFO":
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    53
			if (!is_valid_rr_hinfo_content($content)) return false;
164
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
    54
			if (!is_valid_hostname_fqdn($name,1)) return false;
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    55
			break;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    56
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    57
		case "MX":
158
30a7f897aaf0 [feladat @ 264]
rejo
parents: 148
diff changeset
    58
			if (!is_valid_hostname_fqdn($content,0)) return false;
164
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
    59
			if (!is_valid_hostname_fqdn($name,1)) return false;
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
    60
			if (!is_valid_non_alias_target($content)) return false;
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    61
			break;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    62
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    63
		case "NS":
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    64
			if (!is_valid_hostname_fqdn($content,0)) return false;
164
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
    65
			if (!is_valid_hostname_fqdn($name,1)) return false;
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
    66
			if (!is_valid_non_alias_target($content)) return false;
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    67
			break;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    68
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    69
		case "PTR":
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    70
			if (!is_valid_hostname_fqdn($content,0)) return false;
164
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
    71
			if (!is_valid_hostname_fqdn($name,1)) return false;
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    72
			break;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    73
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    74
		case "SOA":
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    75
			if (!is_valid_rr_soa_name($name,$zone)) return false;
164
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
    76
			if (!is_valid_hostname_fqdn($name,1)) return false;
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    77
			if (!is_valid_rr_soa_content($content)) return false;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    78
			break;
164
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
    79
		
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
    80
		case "SRV":
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
    81
			if (!is_valid_rr_srv_name($name)) return false;
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
    82
			if (!is_valid_rr_srv_content($content)) return false;
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
    83
			break;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    84
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    85
		case "TXT":
164
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
    86
			if (!is_valid_printable($name)) return false;
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
    87
			if (!is_valid_printable($content)) return false;
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    88
			break;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    89
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    90
		case "MBOXFW":
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    91
		case "NAPTR":
193
6a87ca695244 [feladat @ 303]
rejo
parents: 192
diff changeset
    92
		case "SPF":
6a87ca695244 [feladat @ 303]
rejo
parents: 192
diff changeset
    93
		case "SSHFP":
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    94
		case "URL":
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    95
			// These types are supported by PowerDNS, but there is not
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    96
			// yet code for validation. Validation needs to be added 
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    97
			// for these types. One Day Real Soon Now. [tm]
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    98
			break;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
    99
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   100
		default:
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   101
			error(ERR_DNS_RR_TYPE);
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   102
			return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   103
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   104
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   105
	if (!is_valid_rr_prio($prio,$type)) return false;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   106
	if (!is_valid_rr_ttl($ttl)) return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   107
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   108
	return true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   109
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   110
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   111
function is_valid_hostname_fqdn($hostname, $wildcard) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   112
138
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   113
	global $dns_strict_tld_check;
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   114
	global $valid_tlds;
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   115
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   116
	$hostname = ereg_replace("\.$","",$hostname);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   117
138
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   118
	if (strlen($hostname) > 255) {
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   119
		error(ERR_DNS_HN_TOO_LONG);
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   120
		return false;
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   121
	}
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   122
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   123
        $hostname_labels = explode ('.', $hostname);
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   124
        $label_count = count($hostname_labels);
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   125
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   126
	foreach ($hostname_labels as $hostname_label) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   127
		if ($wildcard == 1 && !isset($first)) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   128
			if (!preg_match('/^(\*|[\w-\/]+)$/',$hostname_label)) { error(ERR_DNS_HN_INV_CHARS); return false; }
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   129
			$first = 1;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   130
		} else {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   131
			if (!preg_match('/^[\w-\/]+$/',$hostname_label)) { error(ERR_DNS_HN_INV_CHARS); return false; }
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   132
		}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   133
		if (substr($hostname_label, 0, 1) == "-") { error(ERR_DNS_HN_DASH); return false; }
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   134
		if (substr($hostname_label, -1, 1) == "-") { error(ERR_DNS_HN_DASH); return false; }
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   135
		if (strlen($hostname_label) < 1 || strlen($hostname_label) > 63) { error(ERR_DNS_HN_LENGTH); return false; }
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   136
	}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   137
	
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   138
	if ($hostname_labels[$label_count-1] == "arpa" && (substr_count($hostname_labels[0], "/") == 1 XOR substr_count($hostname_labels[1], "/") == 1)) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   139
		if (substr_count($hostname_labels[0], "/") == 1) { 
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   140
			$array = explode ("/", $hostname_labels[0]);
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   141
		} else {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   142
			$array = explode ("/", $hostname_labels[1]);
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   143
		}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   144
		if (count($array) != 2) { error(ERR_DNS_HOSTNAME) ; return false; }
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   145
		if (!is_numeric($array[0]) || $array[0] < 0 || $array[0] > 255) { error(ERR_DNS_HOSTNAME) ; return false; }
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   146
		if (!is_numeric($array[1]) || $array[1] < 25 || $array[1] > 31) { error(ERR_DNS_HOSTNAME) ; return false; }
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   147
	} else {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   148
		if (substr_count($hostname, "/") > 0) { error(ERR_DNS_HN_SLASH) ; return false; }
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   149
	}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   150
	
138
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   151
	if ($dns_strict_tld_check == "1" && !in_array($hostname_labels[$label_count-1], $valid_tlds)) {
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   152
		error(ERR_DNS_INV_TLD); return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   153
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   154
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   155
	return true;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   156
}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   157
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   158
function is_valid_ipv4($ipv4) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   159
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   160
// 20080424/RZ: The current code may be replaced by the following if() 
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   161
// statement, but it will raise the required PHP version to ">= 5.2.0". 
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   162
// Not sure if we want that now.
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   163
//
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   164
//	if(filter_var($ipv4, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === FALSE) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   165
//		error(ERR_DNS_IPV4); return false;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   166
//	}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   167
162
e109f389316c [feladat @ 268]
rejo
parents: 158
diff changeset
   168
	if (!preg_match("/^[0-9\.]{7,15}$/", $ipv4)) {
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   169
		error(ERR_DNS_IPV4); return false;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   170
	}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   171
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   172
	$quads = explode('.', $ipv4);
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   173
	$numquads = count($quads);
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   174
	
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   175
	if ($numquads != 4) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   176
		error(ERR_DNS_IPV4); return false;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   177
	}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   178
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   179
	for ($i = 0; $i < 4; $i++) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   180
		if ($quads[$i] > 255) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   181
			error(ERR_DNS_IPV4); return false;
138
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   182
		}
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   183
	}
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   184
138
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   185
	return true;
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   186
}
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   187
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   188
function is_valid_ipv6($ipv6) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   189
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   190
// 20080424/RZ: The current code may be replaced by the following if() 
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   191
// statement, but it will raise the required PHP version to ">= 5.2.0". 
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   192
// Not sure if we want that now.
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   193
//
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   194
//	if(filter_var($ipv6, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === FALSE) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   195
//		error(ERR_DNS_IPV6); return false;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   196
//	}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   197
162
e109f389316c [feladat @ 268]
rejo
parents: 158
diff changeset
   198
	if (!preg_match("/^[0-9a-f]{0,4}:([0-9a-f]{0,4}:){0,6}[0-9a-f]{0,4}$/i", $ipv6)) {
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   199
		error(ERR_DNS_IPV6); return false;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   200
	}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   201
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   202
	$quads = explode(':', $ipv6);
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   203
	$numquads = count ($quads);
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   204
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   205
	if ($numquads > 8 || $numquads < 3) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   206
		error(ERR_DNS_IPV6); return false;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   207
	}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   208
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   209
	$emptyquads = 0;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   210
	for ($i = 1; $i < $numquads-1; $i++) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   211
		if ($quads[$i] == "") $emptyquads++;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   212
	}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   213
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   214
	if ($emptyquads > 1) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   215
		error(ERR_DNS_IPV6); return false;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   216
	}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   217
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   218
	if ($emptyquads == 0 && $numquads != 8) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   219
		error(ERR_DNS_IPV6); return false;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   220
	}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   221
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   222
	return true;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   223
}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   224
164
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   225
function is_valid_printable($string) {
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   226
	if (!ereg('^[[:print:]]+$', trim($string))) { error(ERR_DNS_PRINTABLE); return false; }
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   227
	return true;
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   228
}
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   229
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   230
function is_valid_rr_cname_name($name) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   231
	global $db;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   232
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   233
	$query = "SELECT type, content 
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   234
			FROM records 
192
3d18290ac993 [feladat @ 302]
peter
parents: 186
diff changeset
   235
			WHERE content = " . $db->quote($name, 'text') . "
3d18290ac993 [feladat @ 302]
peter
parents: 186
diff changeset
   236
			AND (type = ".$db->quote('MX', 'text')." OR type = ".$db->quote('NS', 'text').")";
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   237
	
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   238
	$response = $db->query($query);
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   239
	if (PEAR::isError($response)) { error($response->getMessage()); return false; };
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   240
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   241
	if ($response->numRows() > 0) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   242
		error(ERR_DNS_CNAME); return false;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   243
	}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   244
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   245
	return true;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   246
}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   247
164
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   248
function is_valid_non_alias_target($target) {
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   249
	global $db;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   250
	
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   251
	$query = "SELECT type, name
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   252
			FROM records
192
3d18290ac993 [feladat @ 302]
peter
parents: 186
diff changeset
   253
			WHERE name = " . $db->quote($target, 'text') . "
3d18290ac993 [feladat @ 302]
peter
parents: 186
diff changeset
   254
			AND TYPE = ".$db->quote('CNAME', 'text');
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   255
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   256
	$response = $db->query($query);
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   257
	if (PEAR::isError($response)) { error($response->getMessage()); return false; };
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   258
	if ($response->numRows() > 0) {
167
0b992665ac4d [feladat @ 273]
rejo
parents: 164
diff changeset
   259
		error(ERR_DNS_NON_ALIAS_TARGET); return false;
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   260
	}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   261
	return true;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   262
}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   263
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   264
function is_valid_rr_hinfo_content($content) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   265
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   266
	if ($content[0] == "\"") {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   267
		$fields = preg_split('/(?<=") /', $content, 2);
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   268
	} else {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   269
		$fields = preg_split('/ /', $content, 2);
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   270
	}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   271
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   272
	for ($i = 0; ($i < 2); $i++) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   273
		if (!preg_match("/^([^\s]{1,1000}|\"([^\"]{1,998}\")$/i", $fields[$i])) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   274
			error(ERR_DNS_HINFO_INV_CONTENT); return false;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   275
		}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   276
	}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   277
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   278
	return true;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   279
}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   280
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   281
function is_valid_rr_soa_content(&$content) {
138
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   282
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   283
	$fields = preg_split("/\s+/", trim($content));
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   284
        $field_count = count($fields);
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   285
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   286
	if ($field_count == 0 || $field_count > 7) {
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   287
		return false;
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   288
	} else {
173
6d0e4e6bedad [feladat @ 280]
rejo
parents: 167
diff changeset
   289
		if (!is_valid_hostname_fqdn($fields[0],0) || preg_match('/\.arpa\.?$/',$fields[0])) {
138
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   290
			return false;
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   291
		}
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   292
		$final_soa = $fields[0];
121
90cab8725693 [feladat @ 224]
rejo
parents: 119
diff changeset
   293
138
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   294
		if (isset($fields[1])) {
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   295
			$addr_input = $fields[1];
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   296
		} else {
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   297
			global $dns_hostmaster;
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   298
			$addr_input = $dns_hostmaster;
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   299
		}
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   300
		if (!preg_match("/@/", $addr_input)) {
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   301
			$addr_input = preg_split('/(?<!\\\)\./', $addr_input, 2);
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   302
			$addr_to_check = str_replace("\\", "", $addr_input[0]) . "@" . $addr_input[1];
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   303
		} else {
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   304
			$addr_to_check = $addr_input;
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   305
		}
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   306
		
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   307
		if (!is_valid_email($addr_to_check)) {
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   308
			return false;
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   309
		} else {
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   310
			$addr_final = explode('@', $addr_to_check, 2);
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   311
			$final_soa .= " " . str_replace(".", "\\.", $addr_final[0]) . "." . $addr_final[1];
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   312
		}
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   313
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   314
		if (isset($fields[2])) {
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   315
			if (!is_numeric($fields[2])) {
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   316
				return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   317
			}
138
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   318
			$final_soa .= " " . $fields[2];
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   319
		} else {
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   320
			$final_soa .= " 0";
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   321
		}
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   322
		
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   323
		if ($field_count == 7) {
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   324
			for ($i = 3; ($i < 7); $i++) {
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   325
				if (!is_numeric($fields[$i])) {
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   326
					return false;
121
90cab8725693 [feladat @ 224]
rejo
parents: 119
diff changeset
   327
				} else {
138
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   328
					$final_soa .= " " . $fields[$i];
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   329
				}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   330
			}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   331
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   332
	}
138
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   333
	$content = $final_soa;
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   334
	return true;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   335
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   336
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   337
function is_valid_rr_soa_name($name, $zone) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   338
	if ($name != $zone) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   339
		error(ERR_DNS_SOA_NAME); return false;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   340
	}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   341
	return true;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   342
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   343
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   344
function is_valid_rr_prio(&$prio, $type) {
164
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   345
	if ($type == "MX" || $type == "SRV" ) {
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   346
		if (!is_numeric($prio) || $prio < 0 || $prio > 65535 ) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   347
			error(ERR_DNS_INV_PRIO); return false;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   348
		}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   349
	} else {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   350
		$prio = "";
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   351
	}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   352
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   353
	return true;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   354
}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   355
164
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   356
function is_valid_rr_srv_name($name){
186
a3e83a34f267 [feladat @ 294]
rejo
parents: 182
diff changeset
   357
a3e83a34f267 [feladat @ 294]
rejo
parents: 182
diff changeset
   358
	if (strlen($name) > 255) {
a3e83a34f267 [feladat @ 294]
rejo
parents: 182
diff changeset
   359
		error(ERR_DNS_HN_TOO_LONG);
a3e83a34f267 [feladat @ 294]
rejo
parents: 182
diff changeset
   360
		return false;
a3e83a34f267 [feladat @ 294]
rejo
parents: 182
diff changeset
   361
	}
a3e83a34f267 [feladat @ 294]
rejo
parents: 182
diff changeset
   362
164
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   363
	$fields = explode('.', $name, 3);
186
a3e83a34f267 [feladat @ 294]
rejo
parents: 182
diff changeset
   364
	if (!preg_match('/^_[\w-]+$/i', $fields[0])) { error(ERR_DNS_SRV_NAME) ; return false; }
a3e83a34f267 [feladat @ 294]
rejo
parents: 182
diff changeset
   365
	if (!preg_match('/^_[\w]+$/i', $fields[1])) { error(ERR_DNS_SRV_NAME) ; return false; }
164
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   366
	if (!is_valid_hostname_fqdn($fields[2],0)) { error(ERR_DNS_SRV_NAME) ; return false ; }
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   367
	return true ;
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   368
}
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   369
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   370
function is_valid_rr_srv_content($content) {
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   371
	$fields = preg_split("/\s+/", trim($content), 3);
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   372
	if (!is_numeric($fields[0]) || $fields[0] < 0 || $fields[0] > 65535) { error(ERR_DNS_SRV_WGHT) ; return false; } 
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   373
	if (!is_numeric($fields[1]) || $fields[1] < 0 || $fields[1] > 65535) { error(ERR_DNS_SRV_PORT) ; return false; } 
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   374
	if ($fields[2] == "" || ($fields[2] != "." && !is_valid_hostname_fqdn($fields[2],0))) {
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   375
		error(ERR_DNS_SRV_TRGT) ; return false; 
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   376
	} 
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   377
	return true;
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   378
}
4c6adb48dcfd [feladat @ 270]
rejo
parents: 162
diff changeset
   379
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   380
function is_valid_rr_ttl(&$ttl) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   381
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   382
	if (!isset($ttl) || $ttl == "" ) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   383
		global $dns_ttl;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   384
		$ttl = $dns_ttl;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   385
	}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   386
	
182
049347a649e0 [feladat @ 290]
rejo
parents: 173
diff changeset
   387
	if (!is_numeric($ttl) ||  $ttl < 0 || $ttl > 2147483647 ) {
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   388
		error(ERR_DNS_INV_TTL);	return false;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   389
	}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   390
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   391
	return true;
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   392
}
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   393
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   394
function is_valid_search($holygrail) {
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   395
62
ce4919f37489 [feladat @ 109]
rejo
parents: 55
diff changeset
   396
	// Only allow for alphanumeric, numeric, dot, dash, underscore and 
ce4919f37489 [feladat @ 109]
rejo
parents: 55
diff changeset
   397
	// percent in search string. The last two are wildcards for SQL.
ce4919f37489 [feladat @ 109]
rejo
parents: 55
diff changeset
   398
	// Needs extension probably for more usual record types.
ce4919f37489 [feladat @ 109]
rejo
parents: 55
diff changeset
   399
ce4919f37489 [feladat @ 109]
rejo
parents: 55
diff changeset
   400
	return preg_match('/^[a-z0-9.\-%_]+$/i', $holygrail);
ce4919f37489 [feladat @ 109]
rejo
parents: 55
diff changeset
   401
}
ce4919f37489 [feladat @ 109]
rejo
parents: 55
diff changeset
   402
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   403
?>