inc/dns.inc.php
author rejo
Wed, 26 Mar 2008 14:48:25 +0000
changeset 90 d7bee09d98fe
parent 82 c255196bc447
child 94 6b4d19ef3de4
permissions -rwxr-xr-x
[feladat @ 190] Changed 'print debug' function a tiny bit.
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
47
ae140472d97c [feladat @ 94]
rejo
parents: 16
diff changeset
     3
/*  PowerAdmin, a friendly web-based admin tool for PowerDNS.
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
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    22
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    23
 * Validates an IPv4 IP.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    24
 * returns true if valid.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    25
 */
16
79b09e1e2985 [feladat @ 63]
rejo
parents: 12
diff changeset
    26
function validate_input($zoneid, $type, &$content, &$name, &$prio, &$ttl)
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    27
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    28
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    29
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    30
	// Has to validate content first then it can do the rest
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    31
	// Since if content is invalid already it can aswell be just removed
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    32
	// Check first if content is IPv4, IPv6 or Hostname
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    33
	// We accomplish this by just running all tests over it
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    34
	// We start with IPv6 since its not able to have these ip's in domains.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    35
	//
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    36
	// <TODO>
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    37
	// The nocheck has to move to the configuration file
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    38
	// </TODO>
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    39
	//
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    40
	$domain = get_domain_name_from_id($zoneid);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    41
	$nocheck = array('SOA', 'HINFO', 'NAPTR', 'URL', 'MBOXFW', 'TXT');
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    42
	$hostname = false;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    43
	$ip4 = false;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    44
	$ip6 = false;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    45
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    46
	if(!in_array(strtoupper($type), $nocheck)) {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    47
		if(!is_valid_ip6($content)) {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    48
			if(!is_valid_ip($content)) {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    49
				if(!is_valid_hostname($content)) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    50
					error(ERR_DNS_CONTENT);
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    51
					return false;
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    52
				} else {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    53
					$hostname = true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    54
				}
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    55
			} else {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    56
				$ip4 = true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    57
			}
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    58
		} else {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    59
			$ip6 = true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    60
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    61
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    62
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    63
	// Prepare total hostname.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    64
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    65
	if ($name == '*') {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    66
		$wildcard = true;
79
0c0aa144356a [feladat @ 156]
peter
parents: 71
diff changeset
    67
	} else {
0c0aa144356a [feladat @ 156]
peter
parents: 71
diff changeset
    68
		$wildcard = false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    69
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    70
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    71
// TODO:	Needs to be checked what this is good for. Since we started insert an array
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    72
//		in functions like edit_record, "name"'s like "sub-fqdn.example.net" became 
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    73
//		"sub-fqdn.example.net.example.net". 
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    74
//	if ($name=="0") {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    75
//		$name=$name.".".$domain;
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    76
//	} else {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    77
//		$name = ($name) ? $name.".".$domain : $domain;
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    78
//	}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    79
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    80
	if (preg_match('!@\.!i', $name))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    81
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    82
		$name = str_replace('@.', '@', $name);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    83
	}
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    84
	if(!$wildcard) {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    85
		if(!is_valid_hostname($name)) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    86
			error(ERR_DNS_HOSTNAME);
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    87
			return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    88
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    89
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    90
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    91
	// Check record type (if it exists in our allowed list.
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    92
	if (!in_array(strtoupper($type), get_record_types())) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    93
		error(ERR_DNS_RECORDTYPE);
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    94
		return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    95
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    96
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    97
	// Start handling the demands for the functions.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    98
	// Validation for IN A records. Can only have an IP. Nothing else.
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
    99
	if ($type == 'A' && !$ip4) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   100
		error(ERR_DNS_IPV4);
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   101
		return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   102
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   103
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   104
	if ($type == 'AAAA' && !$ip6) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   105
		error(ERR_DNS_IPV6);
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   106
		return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   107
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   108
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   109
	if ($type == 'CNAME' && $hostname) {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   110
		if(!is_valid_cname($name)) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   111
			error(ERR_DNS_CNAME);
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   112
			return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   113
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   114
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   115
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   116
	if ($type == 'NS') {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   117
		$status = is_valid_ns($content, $hostname);
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   118
		if($status == -1) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   119
			error(ERR_DNS_NS_HNAME);
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   120
			return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   121
		}
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   122
		elseif($status == -2) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   123
			error(ERR_DNS_NS_CNAME);
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   124
			return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   125
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   126
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   127
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   128
	if ($type == 'SOA') {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   129
		$status = is_valid_soa($content, $zoneid);
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   130
		if($status == -1) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   131
			error(ERR_DNS_SOA_UNIQUE);
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   132
		} elseif($status == -2) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   133
			error(ERR_DNS_SOA_NUMERIC);
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   134
			return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   135
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   136
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   137
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   138
	// HINFO and TXT require no validation.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   139
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   140
	if ($type == 'URL') {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   141
		if(!is_valid_url($content)) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   142
			error(ERR_INV_URL);
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   143
			return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   144
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   145
	}
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   146
	if ($type == 'MBOXFW') 	{
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   147
		if(!is_valid_mboxfw($content)) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   148
			error(ERR_INV_EMAIL);
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   149
			return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   150
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   151
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   152
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   153
	// NAPTR has to be done.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   154
	// Do we want that?
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   155
	// http://www.ietf.org/rfc/rfc2915.txt
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   156
	// http://www.zvon.org/tmRFC/RFC2915/Output/chapter2.html
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   157
	// http://www.zvon.org/tmRFC/RFC3403/Output/chapter4.html
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   158
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   159
	// See if the prio field is valid and if we have one.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   160
	// If we dont have one and the type is MX record, give it value '10'
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   161
	if($type == 'NAPTR') {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   162
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   163
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   164
	
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   165
	if($type == 'MX') {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   166
		if($hostname) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   167
			$status = is_valid_mx($content, $prio);
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   168
			if($status == -1) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   169
				error(ERR_DNS_MX_CNAME);
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   170
				return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   171
			}
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   172
			elseif($status == -2) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   173
				error(ERR_DNS_MX_PRIO);
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   174
				return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   175
			}
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   176
		} else {
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   177
			error( _('If you specify an MX record it must be a hostname.') ); // TODO make error
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   178
			return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   179
		}
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   180
	} else {
55
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
   181
		$prio=0;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   182
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   183
	// Validate the TTL, it has to be numeric.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   184
	$ttl = (!isset($ttl) || !is_numeric($ttl)) ? $DEFAULT_TTL : $ttl;
82
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   185
	
c255196bc447 [feladat @ 182]
rejo
parents: 79
diff changeset
   186
	return true;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   187
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   188
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   189
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   190
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   191
		/****************************************
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   192
		 *					*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   193
		 * RECORD VALIDATING PART.		*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   194
		 * CHANGES HERE SHOULD BE CONSIDERED	*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   195
		 * THEY REQUIRE KNOWLEDGE ABOUT THE 	*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   196
		 * DNS SPECIFICATIONS			*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   197
		 *					*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   198
		 ***************************************/
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   199
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   200
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   201
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   202
 * Validatis a CNAME record by the name it will have and its destination
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   203
 *
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   204
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   205
function is_valid_cname($dest)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   206
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   207
	/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   208
	 * This is really EVIL.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   209
	 * If the new record (a CNAME) record is being pointed to by a MX record or NS record we have to bork.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   210
	 * this is the idea.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   211
	 *
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   212
	 * MX record: blaat.nl MX mail.blaat.nl
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   213
	 * Now we look what mail.blaat.nl is
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   214
	 * We discover the following:
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   215
	 * mail.blaat.nl CNAME bork.blaat.nl
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   216
	 * This is NOT allowed! mail.onthanet.nl can not be a CNAME!
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   217
	 * The same goes for NS. mail.blaat.nl must have a normal IN A record.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   218
	 * It MAY point to a CNAME record but its not wished. Lets not support it.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   219
	 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   220
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   221
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   222
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   223
	// Check if there are other records with this information of the following types.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   224
	// P.S. we might add CNAME to block CNAME recursion and chains.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   225
	$blockedtypes = " AND (type='MX' OR type='NS')";
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   226
65
ce1c4d5e1576 [feladat @ 112]
peter
parents: 62
diff changeset
   227
	$cnamec = "SELECT type, content FROM records WHERE content=".$db->quote($dest) . $blockedtypes;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   228
	$result = $db->query($cnamec);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   229
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   230
	if($result->numRows() > 0)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   231
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   232
		return false;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   233
		// Lets inform the user he is doing something EVIL.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   234
		// Ok we found a record that has our content field in their content field.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   235
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   236
	return true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   237
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   238
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   239
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   240
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   241
 * Checks if something is a valid domain.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   242
 * Checks for domainname with the allowed characters <a,b,...z,A,B,...Z> and - and _.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   243
 * This part must be followed by a 2 to 4 character TLD.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   244
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   245
function is_valid_domain($domain)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   246
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   247
	if ((eregi("^[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$", $domain)) && (strlen($domain) <= 128))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   248
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   249
		return true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   250
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   251
	return false;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   252
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   253
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   254
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   255
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   256
 * Validates if given hostname is allowed.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   257
 * returns true if allowed.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   258
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   259
function is_valid_hostname($host)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   260
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   261
	if(count(explode(".", $host)) == 1)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   262
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   263
		return false;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   264
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   265
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   266
	// Its not perfect (in_addr.int is allowed) but works for now.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   267
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   268
	if(preg_match('!(ip6|in-addr).(arpa|int)$!i', $host))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   269
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   270
		if(preg_match('!^(([A-Z\d]|[A-Z\d][A-Z\d-]*[A-Z\d])\.)*[A-Z\d]+$!i', $host))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   271
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   272
			return true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   273
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   274
		return false;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   275
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   276
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   277
	// Validate further.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   278
	return (preg_match('!^(([A-Z\d]|[A-Z\d][A-Z\d-]*[A-Z\d])\.)*[A-Z\d]+$!i', $host)) ? true : false;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   279
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   280
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   281
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   282
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   283
 * Validates an IPv4 IP.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   284
 * returns true if valid.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   285
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   286
function is_valid_ip($ip)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   287
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   288
	// Stop reading at this point. Scroll down to the next function...
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   289
	// Ok... you didn't stop reading... now you have to rewrite the whole function! enjoy ;-)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   290
	// Trance unborked it. Twice even!
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   291
	return ($ip == long2ip(ip2long($ip))) ? true : false;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   292
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   293
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   294
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   295
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   296
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   297
 * Validates an IPv6 IP.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   298
 * returns true if valid.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   299
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   300
function is_valid_ip6($ip)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   301
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   302
	// Validates if the given IP is truly an IPv6 address.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   303
	// Precondition: have a string
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   304
	// Postcondition: false: Error in IP
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   305
	//                true: IP is correct
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   306
	// Requires: String
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   307
	// Date: 10-sep-2002
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   308
	if(preg_match('!^[A-F0-9:]{1,39}$!i', $ip) == true)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   309
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   310
		// Not 3 ":" or more.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   311
		$p = explode(':::', $ip);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   312
		if(sizeof($p) > 1)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   313
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   314
			return false;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   315
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   316
		// Find if there is only one occurence of "::".
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   317
		$p = explode('::', $ip);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   318
		if(sizeof($p) > 2)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   319
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   320
			return false;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   321
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   322
		// Not more than 8 octects
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   323
		$p = explode(':', $ip);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   324
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   325
		if(sizeof($p) > 8)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   326
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   327
			return false;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   328
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   329
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   330
		// Check octet length
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   331
		foreach($p as $checkPart)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   332
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   333
			if(strlen($checkPart) > 4)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   334
			{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   335
				return false;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   336
			}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   337
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   338
		return true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   339
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   340
	return false;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   341
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   342
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   343
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   344
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   345
 * FANCY RECORD.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   346
 * Validates if the fancy record mboxfw is an actual email address.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   347
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   348
function is_valid_mboxfw($email)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   349
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   350
	return is_valid_email($email);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   351
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   352
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   353
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   354
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   355
 * Validates MX records.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   356
 * an MX record cant point to a CNAME record. This has to be checked.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   357
 * this function also sets a proper priority.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   358
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   359
function is_valid_mx($content, &$prio)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   360
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   361
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   362
	// See if the destination to which this MX is pointing is NOT a CNAME record.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   363
	// Check inside our dns server.
65
ce1c4d5e1576 [feladat @ 112]
peter
parents: 62
diff changeset
   364
	if($db->queryOne("SELECT count(id) FROM records WHERE name=".$db->quote($content)." AND type='CNAME'") > 0)
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   365
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   366
		return -1;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   367
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   368
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   369
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   370
		// Fix the proper priority for the record.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   371
		// Bugfix, thanks Oscar :)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   372
		if(!isset($prio))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   373
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   374
			$prio = 10;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   375
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   376
		if(!is_numeric($prio))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   377
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   378
			if($prio == '')
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   379
			{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   380
				$prio = 10;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   381
			}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   382
			else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   383
			{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   384
				return -2;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   385
			}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   386
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   387
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   388
	return 1;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   389
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   390
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   391
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   392
 * Validates NS records.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   393
 * an NS record cant point to a CNAME record. This has to be checked.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   394
 * $hostname directive means if its a hostname or not (this to avoid that NS records get ip fields)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   395
 * NS must have a hostname, it is not allowed to have an IP.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   396
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   397
function is_valid_ns($content, $hostname)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   398
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   399
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   400
	// Check if the field is a hostname, it MUST be a hostname.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   401
	if(!$hostname)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   402
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   403
		return -1;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   404
		// "an IN NS field must be a hostname."
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   405
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   406
65
ce1c4d5e1576 [feladat @ 112]
peter
parents: 62
diff changeset
   407
	if($db->queryOne("SELECT count(id) FROM records WHERE name=".$db->quote($content)." AND type='CNAME'") > 0)
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   408
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   409
		return -2;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   410
		// "You can not point a NS record to a CNAME record. Remove/rename the CNAME record first or take another name."
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   411
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   412
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   413
	return 1;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   414
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   415
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   416
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   417
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   418
 * Function to check the validity of SOA records.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   419
 * return values: true if succesful
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   420
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   421
function is_valid_soa(&$content, $zoneid)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   422
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   423
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   424
	/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   425
	 * SOA (start of authority)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   426
	 * there is only _ONE_ SOA record allowed in every zone.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   427
	 * Validate SOA record
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   428
	 * The Start of Authority record is one of the most complex available. It specifies a lot
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   429
	 * about a domain: the name of the master nameserver ('the primary'), the hostmaster and
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   430
	 * a set of numbers indicating how the data in this domain expires and how often it needs
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   431
	 * to be checked. Further more, it contains a serial number which should rise on each change
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   432
	 * of the domain.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   433
	 					    2002120902 28800 7200 604800 10800
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   434
	 * The stored format is: primary hostmaster serial refresh retry expire default_ttl
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   435
	 * From the powerdns documentation.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   436
	 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   437
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   438
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   439
	// Check if there already is an occurence of a SOA, if so see if its not the one we are currently changing
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   440
	$return = get_records_by_type_from_domid("SOA", $zoneid);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   441
	if($return->numRows() > 1)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   442
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   443
		return -1;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   444
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   445
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   446
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   447
	$soacontent = explode(" ", $content);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   448
	// Field is at least one otherwise it wouldnt even get here.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   449
	if(is_valid_hostname($soacontent[0]))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   450
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   451
		$totalsoa = $soacontent[0];
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   452
		// It doesnt matter what field 2 contains, but lets check if its there
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   453
		// We assume the 2nd field wont have numbers, otherwise its a TTL field
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   454
		if(count($soacontent) > 1)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   455
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   456
			if(is_numeric($soacontent[1]))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   457
			{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   458
				// its a TTL field, or at least not hostmaster or alike
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   459
				// Set final string to the default hostmaster addy
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   460
				global $HOSTMASTER;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   461
				$totalsoa .= " ". $HOSTMASTER;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   462
			}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   463
			else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   464
			{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   465
				$totalsoa .= " ".$soacontent[1];
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   466
			}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   467
			// For loop to iterate over the numbers
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   468
			$imax = count($soacontent);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   469
			for($i = 2; ($i < $imax) && ($i < 7); $i++)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   470
			{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   471
				if(!is_numeric($soacontent[$i]))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   472
				{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   473
					return -2;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   474
				}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   475
				else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   476
				{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   477
					$totalsoa .= " ".$soacontent[$i];
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   478
				}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   479
			}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   480
			if($i > 7)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   481
			{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   482
				error(ERR_DNS_SOA_NUMERIC_FIELDS);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   483
			}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   484
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   485
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   486
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   487
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   488
		error(ERR_DNS_SOA_HOSTNAME);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   489
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   490
	$content = $totalsoa;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   491
	return 1;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   492
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   493
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   494
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   495
function is_valid_url($url)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   496
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   497
	return preg_match('!^(http://)(([A-Z\d]|[A-Z\d][A-Z\d-]*[A-Z\d])\.)*[A-Z\d]+([//]([0-9a-z//~#%&\'_\-+=:?.]*))?$!i',  $url);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   498
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   499
62
ce4919f37489 [feladat @ 109]
rejo
parents: 55
diff changeset
   500
function is_valid_search($holygrail)
ce4919f37489 [feladat @ 109]
rejo
parents: 55
diff changeset
   501
{
ce4919f37489 [feladat @ 109]
rejo
parents: 55
diff changeset
   502
	// Only allow for alphanumeric, numeric, dot, dash, underscore and 
ce4919f37489 [feladat @ 109]
rejo
parents: 55
diff changeset
   503
	// percent in search string. The last two are wildcards for SQL.
ce4919f37489 [feladat @ 109]
rejo
parents: 55
diff changeset
   504
	// Needs extension probably for more usual record types.
ce4919f37489 [feladat @ 109]
rejo
parents: 55
diff changeset
   505
ce4919f37489 [feladat @ 109]
rejo
parents: 55
diff changeset
   506
	return preg_match('/^[a-z0-9.\-%_]+$/i', $holygrail);
ce4919f37489 [feladat @ 109]
rejo
parents: 55
diff changeset
   507
}
ce4919f37489 [feladat @ 109]
rejo
parents: 55
diff changeset
   508
ce4919f37489 [feladat @ 109]
rejo
parents: 55
diff changeset
   509
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   510
?>