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