inc/record.inc.php
author rejo
Mon, 02 Jul 2007 23:01:18 +0000
changeset 36 4ec5ab29f634
parent 30 380197766e7e
child 37 b785e54690ce
permissions -rwxr-xr-x
[feladat @ 83] Bugfix: the list_zones.php wasn't listing zones correctly if a zone didn't have an owner. Bugfix: the list_supermasters.php never listed more then one supermaster, even if there were more. Both bugs were reported by Jasper van Erven Dorens.
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
// Filename: record.inc.php
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
     5
// Startdate: 26-10-2002
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
     6
// This file is ought to edit the records in the database.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
     7
// Records are domains aswell, they also belong here.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
     8
// All database functions are associative.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
     9
// use nextID first to get a new id. Then insert it into the database.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    10
// do not rely on auto_increment (see above).
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    11
// use dns.inc.php for validation functions.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    12
//
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    13
// $Id: record.inc.php,v 1.21 2003/05/10 20:21:01 azurazu Exp $
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    14
//
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    15
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    16
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    17
function update_soa_serial($domain_id)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    18
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    19
    global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    20
	/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    21
	 * THIS CODE ISNT TESTED THROUGH MUCH YET!
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    22
	 * !!!!!!! BETACODE !!!!!!!!!!
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    23
	 * Code committed by DeViCeD, Thanks a lot!
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    24
	 * Heavily hax0red by Trancer/azurazu
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    25
	 *
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    26
	 * First we have to check, wheather current searial number 
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    27
	 * was already updated on the other nameservers.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    28
	 * If field 'notified_serial' is NULL, then I guess domain is
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    29
	 * NATIVE and we don't have any secondary nameservers for this domain.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    30
	 * NOTICE: Serial number *will* be RFC1912 compilant after update 
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    31
	 * NOTICE: This function will allow only 100 DNS zone transfers ;-)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    32
	 * YYYYMMDDnn
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    33
	 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    34
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    35
	$sqlq = "SELECT `notified_serial` FROM `domains` WHERE `id` = '".$domain_id."'";
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
    36
	$notified_serial = $db->queryOne($sqlq);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    37
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    38
	$sqlq = "SELECT `content` FROM `records` WHERE `type` = 'SOA' AND `domain_id` = '".$domain_id."'";
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
    39
	$content = $db->queryOne($sqlq);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    40
    $need_to_update = false;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    41
	
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    42
	// Getting the serial field.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    43
	$soa = explode(" ", $content);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    44
	
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    45
	if(empty($notified_serial))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    46
    {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    47
        // Ok native replication, so we have to update.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    48
        $need_to_update = true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    49
    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    50
    elseif($notified_serial >= $soa[2])
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    51
    {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    52
        $need_to_update = true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    53
    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    54
    elseif(strlen($soa[2]) != 10)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    55
    {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    56
        $need_to_update = true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    57
    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    58
    else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    59
    {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    60
        $need_to_update = false;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    61
    }
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    62
    if($need_to_update)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    63
    {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    64
        // Ok so we have to update it seems.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    65
        $current_serial = $soa[2];
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    66
        
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    67
		/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    68
		 * What we need here (for RFC1912) is YEAR, MONTH and DAY
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    69
		 * so let's get it ...
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    70
		 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    71
		$new_serial = date('Ymd'); // we will add revision number later
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    72
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    73
		if(strncmp($new_serial, $current_serial, 8) === 0)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    74
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    75
            /*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    76
             * Ok, so we already made updates tonight
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    77
             * let's just increase the revision number
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    78
             */				
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    79
            $revision_number = (int) substr($current_serial, -2);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    80
            if ($revision_number == 99) return false; // ok, we cannot update anymore tonight
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    81
            ++$revision_number;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    82
            // here it is ... same date, new revision
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    83
            $new_serial .= str_pad($revision_number, 2, "0", STR_PAD_LEFT);	
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    84
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    85
 		else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    86
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    87
            /*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    88
			 * Current serial is not RFC1912 compilant, so let's make a new one
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    89
			 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    90
 			$new_serial .= '00';
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    91
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    92
        $soa[2] = $new_serial; // change serial in SOA array
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    93
		$new_soa = "";		
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    94
		// build new soa and update SQL after that
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    95
		for ($i = 0; $i < count($soa); $i++) 
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    96
		{	
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    97
			$new_soa .= $soa[$i] . " "; 
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    98
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    99
		$sqlq = "UPDATE `records` SET `content` = '".$new_soa."' WHERE `domain_id` = '".$domain_id."' AND `type` = 'SOA' LIMIT 1";
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   100
		$db->Query($sqlq);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   101
		return true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   102
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   103
}  
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   104
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   105
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   106
 * Edit a record.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   107
 * This function validates it if correct it inserts it into the database.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   108
 * return values: true if succesful.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   109
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   110
function edit_record($recordid, $zoneid, $name, $type, $content, $ttl, $prio)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   111
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   112
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   113
  	if($content == "")
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   114
  	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   115
  		error(ERR_RECORD_EMPTY_CONTENT);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   116
  	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   117
  	// Edits the given record (validates specific stuff first)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   118
	if (!xs(recid_to_domid($recordid)))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   119
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   120
		error(ERR_RECORD_ACCESS_DENIED);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   121
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   122
	if (is_numeric($zoneid))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   123
	{
19
f9ea2a05149b [feladat @ 66]
rejo
parents: 13
diff changeset
   124
		validate_input($zoneid, $type, $content, $name, $prio, $ttl);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   125
                $change = time();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   126
                $db->query("UPDATE records set name='$name', type='$type', content='$content', ttl='$ttl', prio='$prio', change_date='$change' WHERE id=$recordid");
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   127
		
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   128
		/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   129
		 * Added by DeViCeD - Update SOA Serial number
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   130
		 * There should be more checks
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   131
		 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   132
		if ($type != 'SOA')
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   133
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   134
			update_soa_serial($zoneid);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   135
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   136
		return true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   137
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   138
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   139
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   140
		error(sprintf(ERR_INV_ARGC, "edit_record", "no zoneid given"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   141
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   142
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   143
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   144
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   145
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   146
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   147
 * Adds a record.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   148
 * This function validates it if correct it inserts it into the database.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   149
 * return values: true if succesful.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   150
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   151
function add_record($zoneid, $name, $type, $content, $ttl, $prio)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   152
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   153
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   154
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   155
	if (!xs($zoneid))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   156
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   157
		error(ERR_RECORD_ACCESS_DENIED);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   158
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   159
	if (is_numeric($zoneid))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   160
	{
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
   161
		// Check the user input.
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
   162
		validate_input($zoneid, $type, $content, $name, $prio, $ttl);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   163
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
   164
		// Generate new timestamp for the daemon
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   165
		$change = time();
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
   166
		
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   167
		// Execute query.
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
   168
		$db->query("INSERT INTO records (domain_id, name, type, content, ttl, prio, change_date) VALUES ($zoneid, '$name', '$type', '$content', $ttl, '$prio', $change)");
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   169
		if ($type != 'SOA')
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   170
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   171
			update_soa_serial($zoneid);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   172
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   173
		return true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   174
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   175
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   176
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   177
		error(sprintf(ERR_INV_ARG, "add_record"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   178
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   179
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   180
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   181
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   182
function add_supermaster($master_ip, $ns_name, $account)
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   183
{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   184
        global $db;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   185
        if (!is_valid_ip($master_ip) && !is_valid_ip6($master_ip))
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   186
        {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   187
                error(sprintf(ERR_INV_ARGC, "add_supermaster", "No or no valid ipv4 or ipv6 address given."));
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   188
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   189
        if (!is_valid_hostname($ns_name))
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   190
        {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   191
                error(ERR_DNS_HOSTNAME);
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   192
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   193
	if (!validate_account($account))
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   194
	{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   195
		error(sprintf(ERR_INV_ARGC, "add_supermaster", "given account name is invalid (alpha chars only)"));
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   196
	}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   197
        if (supermaster_exists($master_ip))
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   198
        {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   199
                error(sprintf(ERR_INV_ARGC, "add_supermaster", "supermaster already exists"));
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   200
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   201
        else
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   202
        {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   203
                $db->query("INSERT INTO supermasters VALUES ('$master_ip', '$ns_name', '$account')");
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   204
                return true;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   205
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   206
}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   207
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   208
function delete_supermaster($master_ip)
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   209
{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   210
        global $db;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   211
        if (!level(5))
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   212
        {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   213
                error(ERR_LEVEL_5);
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   214
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   215
        if (is_valid_ip($master_ip) || is_valid_ip6($master_ip))
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   216
        {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   217
                $db->query("DELETE FROM supermasters WHERE ip = '$master_ip'");
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   218
                return true;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   219
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   220
        else
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   221
        {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   222
                error(sprintf(ERR_INV_ARGC, "delete_supermaster", "No or no valid ipv4 or ipv6 address given."));
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   223
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   224
}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   225
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   226
function get_supermaster_info_from_ip($master_ip)
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   227
{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   228
	global $db;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   229
        if (!level(5))
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   230
        {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   231
                error(ERR_LEVEL_5);
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   232
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   233
        if (is_valid_ip($master_ip) || is_valid_ip6($master_ip))
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   234
	{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   235
	        $result = $db->queryRow("SELECT ip,nameserver,account FROM supermasters WHERE ip = '$master_ip'");
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   236
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   237
		$ret = array(
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   238
		"master_ip"	=>              $result["ip"],
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   239
		"ns_name"	=>              $result["nameserver"],
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   240
		"account"	=>              $result["account"]
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   241
		);
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   242
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   243
		return $ret;	
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   244
	}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   245
        else
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   246
	{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   247
                error(sprintf(ERR_INV_ARGC, "get_supermaster_info_from_ip", "No or no valid ipv4 or ipv6 address given."));
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   248
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   249
}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   250
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   251
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   252
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   253
 * Delete a record by a given id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   254
 * return values: true, this function is always succesful.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   255
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   256
function delete_record($id)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   257
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   258
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   259
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   260
	// Check if the user has access.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   261
	if (!xs(recid_to_domid($id)))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   262
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   263
		error(ERR_RECORD_ACCESS_DENIED);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   264
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   265
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   266
	// Retrieve the type of record to see if we can actually remove it.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   267
	$recordtype = get_recordtype_from_id($id);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   268
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   269
	// If the record type is NS and the user tries to delete it while ALLOW_NS_EDIT is set to 0
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   270
	// OR
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   271
	// check if the name of the record isnt the domain name (if so it should delete all records)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   272
	// OR
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   273
	// check if we are dealing with a SOA field (same story as NS)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   274
	if (($recordtype == "NS" && $GLOBALS["ALLOW_NS_EDIT"] != 1 && (get_name_from_record_id($id) == get_domain_name_from_id(recid_to_domid($id)))) || ($recordtype == "SOA" && $GLOBALS["ALLOW_SOA_EDIT"] != 1))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   275
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   276
		error(sprintf(ERR_RECORD_DELETE_TYPE_DENIED, $recordtype));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   277
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   278
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   279
	if (is_numeric($id))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   280
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   281
	    $did = recid_to_domid($id);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   282
		$db->query('DELETE FROM records WHERE id=' . $id . ' LIMIT 1');
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   283
		if ($type != 'SOA')
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   284
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   285
			update_soa_serial($did);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   286
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   287
        // $id doesnt exist in database anymore so its deleted or just not there which means "true"	
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   288
		return true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   289
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   290
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   291
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   292
		error(sprintf(ERR_INV_ARG, "delete_record"));
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
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   298
 * Add a domain to the database.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   299
 * A domain is name obligatory, so is an owner.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   300
 * return values: true when succesful.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   301
 * Empty means templates dont have to be applied.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   302
 * --------------------------------------------------------------------------
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   303
 * This functions eats a template and by that it inserts various records.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   304
 * first we start checking if something in an arpa record
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   305
 * remember to request nextID's from the database to be able to insert record.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   306
 * if anything is invalid the function will error
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   307
 */
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   308
function add_domain($domain, $owner, $webip, $mailip, $empty, $type, $slave_master)
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   309
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   310
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   311
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   312
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   313
	if (!level(5))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   314
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   315
		error(ERR_LEVEL_5);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   316
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   317
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   318
	// If domain, owner and mailip are given
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   319
	// OR
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   320
	// empty is given and owner and domain
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   321
	// OR
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   322
	// the domain is an arpa record and owner is given
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   323
	// OR
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   324
	// the type is slave, domain, owner and slave_master are given
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   325
	// THAN
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   326
	// Continue this function
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   327
	if (($domain && $owner && $webip && $mailip) || ($empty && $owner && $domain) || (eregi('in-addr.arpa', $domain) && $owner) || $type=="SLAVE" && $domain && $owner && $slave_master)
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   328
	{
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
   329
                // First insert zone into domain table
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
   330
                $db->query("INSERT INTO domains (name, type) VALUES ('$domain', '$type')");
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   331
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
   332
                // Determine id of insert zone (in other words, find domain_id)
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
   333
                $iddomain = $db->lastInsertId('domains', 'id');
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
   334
                if (PEAR::isError($iddomain)) {
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
   335
                        die($id->getMessage());
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
   336
                }
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   337
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
   338
                // Second, insert into zones tables
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
   339
                $db->query("INSERT INTO zones (domain_id, owner) VALUES ('$iddomain', $owner)");
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   340
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   341
		if ($type == "SLAVE")
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   342
		{
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   343
			$db->query("UPDATE domains SET master = '$slave_master' WHERE id = '$iddomain';");
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   344
			
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   345
			// Done
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   346
			return true;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   347
		}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   348
		else
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   349
		{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   350
			// Generate new timestamp. We need this one anyhow.
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   351
			$now = time();
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   352
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   353
			if ($empty && $iddomain)
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   354
			{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   355
				// If we come into this if statement we dont want to apply templates.
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   356
				// Retrieve configuration settings.
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   357
				$ns1 = $GLOBALS["NS1"];
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   358
				$hm  = $GLOBALS["HOSTMASTER"];
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   359
				$ttl = $GLOBALS["DEFAULT_TTL"];
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   360
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   361
				// Build and execute query
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   362
				$sql = "INSERT INTO records (domain_id, name, content, type, ttl, prio, change_date) VALUES ('$iddomain', '$domain', '$ns1 $hm 1', 'SOA', $ttl, '', '$now')";
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   363
				$db->query($sql);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   364
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   365
				// Done
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   366
				return true;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   367
			}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   368
			elseif ($iddomain)
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   369
			{
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   370
				// If we are here we want to apply templates.
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   371
				global $template;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   372
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   373
				// Iterate over the template and apply it for each field.
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   374
				foreach ($template as $r)
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   375
				{
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   376
					// Same type of if statement as previous.
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   377
					if ((eregi('in-addr.arpa', $domain) && ($r["type"] == "NS" || $r["type"] == "SOA")) || (!eregi('in-addr.arpa', $domain)))
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   378
					{
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   379
						// Parse the template.
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   380
						$name     = parse_template_value($r["name"], $domain, $webip, $mailip);
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   381
						$type     = $r["type"];
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   382
						$content  = parse_template_value($r["content"], $domain, $webip, $mailip);
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   383
						$ttl      = $r["ttl"];
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   384
						$prio     = $r["prio"];
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   385
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   386
						// If no ttl is given, use the default.
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   387
						if (!$ttl)
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   388
						{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   389
							$ttl = $GLOBALS["DEFAULT_TTL"];
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   390
						}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   391
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   392
						$sql = "INSERT INTO records (domain_id, name, content, type, ttl, prio, change_date) VALUES ('$iddomain', '$name','$content','$type','$ttl','$prio','$now')";
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   393
						$db->query($sql);
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   394
					}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   395
				}
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   396
				// All done.
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   397
				return true;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   398
			 }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   399
			 else
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   400
			 {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   401
				error(sprintf(ERR_INV_ARGC, "add_domain", "could not create zone"));
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   402
			 }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   403
		}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   404
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   405
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   406
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   407
		error(sprintf(ERR_INV_ARG, "add_domain"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   408
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   409
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   410
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   411
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   412
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   413
 * Deletes a domain by a given id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   414
 * Function always succeeds. If the field is not found in the database, thats what we want anyway.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   415
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   416
function delete_domain($id)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   417
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   418
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   419
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   420
	if (!level(5))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   421
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   422
		error(ERR_LEVEL_5);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   423
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   424
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   425
	// See if the ID is numeric.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   426
	if (is_numeric($id))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   427
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   428
		$db->query("DELETE FROM zones WHERE domain_id=$id");
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   429
		$db->query("DELETE FROM domains WHERE id=$id");
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   430
		$db->query("DELETE FROM records WHERE domain_id=$id");
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   431
		// Nothing in the database. If the delete deleted 0 records it means the id is just not there.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   432
		// therefore the is no need to check the affectedRows values.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   433
		return true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   434
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   435
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   436
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   437
		error(sprintf(ERR_INV_ARGC, "delete_domain", "id must be a number"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   438
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   439
}
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
 * Gets the id of the domain by a given record id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   444
 * return values: the domain id that was requested.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   445
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   446
function recid_to_domid($id)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   447
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   448
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   449
	if (is_numeric($id))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   450
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   451
		$result = $db->query("SELECT domain_id FROM records WHERE id=$id");
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   452
		$r = $result->fetchRow();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   453
		return $r["domain_id"];
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   454
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   455
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   456
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   457
		error(sprintf(ERR_INV_ARGC, "recid_to_domid", "id must be a number"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   458
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   459
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   460
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   461
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   462
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   463
 * Sorts a zone by records.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   464
 * return values: the sorted zone.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   465
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   466
function sort_zone($records)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   467
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   468
	$ar_so = array();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   469
	$ar_ns = array();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   470
	$ar_mx = array();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   471
	$ar_mb = array();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   472
	$ar_ur = array();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   473
	$ar_ov = array();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   474
	foreach ($records as $c)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   475
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   476
		switch(strtoupper($c['type']))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   477
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   478
			case "SOA":
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   479
				$ar_so[] = $c;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   480
				break;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   481
			case "NS":
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   482
				$ar_ns[] = $c;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   483
				break;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   484
			case "MX":
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   485
				$ar_mx[] = $c;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   486
				break;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   487
			case "MBOXFW":
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   488
				$ar_mb[] = $c;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   489
				break;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   490
			case "URL":
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   491
				$ar_ur[] = $c;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   492
				break;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   493
			default:
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   494
				$ar_ov[] = $c;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   495
				break;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   496
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   497
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   498
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   499
	$res = array_merge($ar_so, $ar_ns, $ar_mx, $ar_mb, $ar_ur, $ar_ov);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   500
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   501
	if (count($records) == count($res))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   502
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   503
		$records = $res;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   504
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   505
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   506
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   507
		error(sprintf(ERR_INV_ARGC, "sort_zone", "records sorting failed!"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   508
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   509
	return $records;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   510
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   511
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   512
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   513
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   514
 * Change owner of a domain.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   515
 * Function should actually be in users.inc.php. But its more of a record modification than a user modification
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   516
 * return values: true when succesful.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   517
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   518
function add_owner($domain, $newowner)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   519
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   520
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   521
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   522
	if (!level(5))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   523
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   524
		error(ERR_LEVEL_5);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   525
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   526
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   527
	if (is_numeric($domain) && is_numeric($newowner) && is_valid_user($newowner))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   528
	{
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
   529
		if($db->queryOne("SELECT COUNT(id) FROM zones WHERE owner=$newowner AND domain_id=$domain") == 0)
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   530
		{
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
   531
			$db->query("INSERT INTO zones (domain_id, owner) VALUES($domain, $newowner)");
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   532
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   533
		return true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   534
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   535
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   536
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   537
		error(sprintf(ERR_INV_ARGC, "change_owner", "$domain / $newowner"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   538
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   539
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   540
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   541
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   542
function delete_owner($domain, $owner)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   543
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   544
	global $db;
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
   545
	if($db->queryOne("SELECT COUNT(id) FROM zones WHERE owner=$owner AND domain_id=$domain") != 0)
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   546
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   547
		$db->query("DELETE FROM zones WHERE owner=$owner AND domain_id=$domain");
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   548
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   549
	return true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   550
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   551
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   552
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   553
 * Retrieves all supported dns record types
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   554
 * This function might be deprecated.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   555
 * return values: array of types in string form.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   556
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   557
function get_record_types()
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   558
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   559
	global $rtypes;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   560
	return $rtypes;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   561
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   562
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   563
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   564
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   565
 * Retrieve all records by a given type and domain id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   566
 * Example: get all records that are of type A from domain id 1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   567
 * return values: a DB class result object
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   568
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   569
function get_records_by_type_from_domid($type, $recid)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   570
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   571
	global $rtypes;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   572
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   573
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   574
	// Does this type exist?
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   575
	if(!in_array(strtoupper($type), $rtypes))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   576
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   577
		error(sprintf(ERR_INV_ARGC, "get_records_from_type", "this is not a supported record"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   578
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   579
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   580
	// Get the domain id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   581
	$domid = recid_to_domid($recid);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   582
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   583
	$result = $db->query("select id, type from records where domain_id=$recid and type='$type'");
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   584
	return $result;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   585
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   586
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   587
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   588
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   589
 * Retrieves the type of a record from a given id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   590
 * return values: the type of the record (one of the records types in $rtypes assumable).
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   591
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   592
function get_recordtype_from_id($id)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   593
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   594
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   595
	if (is_numeric($id))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   596
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   597
		$result = $db->query("SELECT type FROM records WHERE id=$id");
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   598
		$r = $result->fetchRow();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   599
		return $r["type"];
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   600
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   601
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   602
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   603
		error(sprintf(ERR_INV_ARG, "get_recordtype_from_id"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   604
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   605
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   606
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   607
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   608
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   609
 * Retrieves the name (e.g. bla.test.com) of a record by a given id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   610
 * return values: the name associated with the id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   611
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   612
function get_name_from_record_id($id)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   613
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   614
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   615
	if (is_numeric($id))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   616
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   617
		$result = $db->query("SELECT name FROM records WHERE id=$id");
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   618
		$r = $result->fetchRow();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   619
		return $r["name"];
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   620
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   621
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   622
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   623
		error(sprintf(ERR_INV_ARG, "get_name_from_record_id"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   624
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   625
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   626
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   627
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   628
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   629
 * Get all the domains from a database of which the user is the owner.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   630
 * return values: an array with the id of the domain and its name.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   631
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   632
function get_domains_from_userid($id)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   633
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   634
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   635
	if (is_numeric($id))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   636
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   637
		$result = $db->query("SELECT domains.id AS domain_id, domains.name AS name FROM domains LEFT JOIN zones ON domains.id=zones.domain_id WHERE owner=$id");
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   638
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   639
		$ret = array();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   640
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   641
		// Put all the information in a big array.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   642
		while ($r = $result->fetchRow())
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   643
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   644
			$ret[] = array(
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   645
			"id"            =>              $r["domain_id"],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   646
			"name"          =>              $r["name"]
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   647
			);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   648
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   649
		return $ret;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   650
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   651
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   652
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   653
		error(sprintf(ERR_INV_ARGC, "get_domains_from_userid", "This is not a valid userid: $id"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   654
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   655
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   656
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   657
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   658
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   659
 * Get domain name from a given id
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   660
 * return values: the name of the domain associated with the id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   661
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   662
function get_domain_name_from_id($id)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   663
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   664
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   665
	if (!xs($id))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   666
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   667
		error(ERR_RECORD_ACCESS_DENIED);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   668
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   669
	if (is_numeric($id))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   670
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   671
		$result = $db->query("SELECT name FROM domains WHERE id=$id");
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   672
		if ($result->numRows() == 1)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   673
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   674
 			$r = $result->fetchRow();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   675
 			return $r["name"];
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   676
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   677
		else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   678
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   679
	 		error(sprintf(ERR_INV_ARGC, "get_domain_name_from_id", "more than one domain found?! whaaa! BAD! BAD! Contact admin!"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   680
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   681
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   682
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   683
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   684
		error(sprintf(ERR_INV_ARGC, "get_domain_name_from_id", "Not a valid domainid: $id"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   685
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   686
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   687
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   688
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   689
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   690
 * Get information about a domain name from a given domain id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   691
 * the function looks up the domainname, the owner of the domain and the number of records in it.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   692
 * return values: an array containing the information.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   693
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   694
function get_domain_info_from_id($id)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   695
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   696
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   697
	if (!xs($id))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   698
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   699
		error(ERR_RECORD_ACCESS_DENIED);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   700
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   701
	if (is_numeric($id))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   702
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   703
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   704
	if ($_SESSION[$id."_ispartial"] == 1) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   705
	
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   706
	$sqlq = "SELECT 
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   707
	domains.type AS type,
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   708
	domains.name AS name,
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   709
	users.fullname AS owner,
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   710
	count(record_owners.id) AS aantal
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   711
	FROM domains, users, record_owners, records
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   712
	
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   713
        WHERE record_owners.user_id = ".$_SESSION["userid"]."
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   714
        AND record_owners.record_id = records.id
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   715
	AND records.domain_id = ".$id."
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   716
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   717
	GROUP BY name, owner, users.fullname
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   718
	ORDER BY name";
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   719
	
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
   720
	$result = $db->queryRow($sqlq);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   721
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   722
	$ret = array(
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   723
	"name"          =>              $result["name"],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   724
	"ownerid"       =>              $_SESSION["userid"],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   725
	"owner"         =>              $result["owner"],
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   726
	"type"		=>		$result["type"],
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   727
	"numrec"        =>              $result["aantal"]
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   728
	);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   729
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   730
	return $ret;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   731
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   732
	} else{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   733
	
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   734
		// Query that retrieves the information we need.
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   735
		$sqlq = "SELECT 
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   736
			domains.type AS type,
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   737
			domains.name AS name,
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   738
			min(zones.owner) AS ownerid,
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   739
			users.fullname AS owner,
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   740
			count(records.domain_id) AS aantal
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   741
			FROM domains
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   742
			LEFT JOIN records ON domains.id=records.domain_id
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   743
			LEFT JOIN zones ON domains.id=zones.domain_id
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   744
			LEFT JOIN users ON zones.owner=users.id
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   745
			WHERE domains.id=$id
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   746
			GROUP BY name, owner, users.fullname
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   747
			ORDER BY zones.id";
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   748
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   749
		// Put the first occurence in an array and return it.
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
   750
		$result = $db->queryRow($sqlq);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   751
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
   752
		//$result["ownerid"] = ($result["ownerid"] == NULL) ? $db->queryOne("select min(id) from users where users.level=10") : $result["ownerid"];
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   753
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   754
		$ret = array(
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   755
		"name"          =>              $result["name"],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   756
		"ownerid"       =>              $result["ownerid"],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   757
		"owner"         =>              $result["owner"],
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   758
		"type"          =>              $result["type"],
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   759
		"numrec"        =>              $result["aantal"]
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   760
		);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   761
		return $ret;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   762
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   763
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   764
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   765
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   766
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   767
		error(sprintf(ERR_INV_ARGC, "get_domain_num_records_from_id", "This is not a valid domainid: $id"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   768
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   769
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   770
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   771
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   772
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   773
 * Check if a domain is already existing.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   774
 * return values: true if existing, false if it doesnt exist.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   775
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   776
function domain_exists($domain)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   777
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   778
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   779
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   780
	if (!level(5))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   781
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   782
		error(ERR_LEVEL_5);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   783
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   784
	if (is_valid_domain($domain))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   785
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   786
		$result = $db->query("SELECT id FROM domains WHERE name='$domain'");
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   787
		if ($result->numRows() == 0)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   788
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   789
			return false;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   790
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   791
		elseif ($result->numRows() >= 1)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   792
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   793
			return true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   794
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   795
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   796
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   797
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   798
		error(ERR_DOMAIN_INVALID);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   799
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   800
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   801
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   802
function get_supermasters()
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   803
{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   804
        global $db;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   805
        $result = $db->query("SELECT ip, nameserver, account FROM supermasters");
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   806
        $ret = array();
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   807
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   808
        if($result->numRows() == 0)
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   809
        {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   810
                return -1;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   811
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   812
        else
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   813
        {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   814
                while ($r = $result->fetchRow())
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   815
                {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   816
                        $ret[] = array(
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   817
                        "master_ip"     => $r["ip"],
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   818
                        "ns_name"       => $r["nameserver"],
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   819
                        "account"       => $r["account"],
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   820
                        );
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   821
                }
36
4ec5ab29f634 [feladat @ 83]
rejo
parents: 30
diff changeset
   822
		return $ret;
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   823
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   824
}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   825
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   826
function supermaster_exists($master_ip)
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   827
{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   828
        global $db;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   829
        if (!level(5))
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   830
        {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   831
                error(ERR_LEVEL_5);
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   832
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   833
        if (is_valid_ip($master_ip) || is_valid_ip6($master_ip))
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   834
        {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   835
                $result = $db->query("SELECT ip FROM supermasters WHERE ip = '$master_ip'");
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   836
                if ($result->numRows() == 0)
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   837
                {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   838
                        return false;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   839
                }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   840
                elseif ($result->numRows() >= 1)
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   841
                {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   842
                        return true;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   843
                }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   844
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   845
        else
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   846
        {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   847
                error(sprintf(ERR_INV_ARGC, "supermaster_exists", "No or no valid IPv4 or IPv6 address given."));
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   848
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   849
}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   850
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   851
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   852
/*
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   853
 * Get all domains from the database 
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   854
 * This function gets all the domains from the database unless a user id is below 5.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   855
 * if a user id is below 5 this function will only retrieve records for that user.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   856
 * return values: the array of domains or -1 if nothing is found.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   857
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   858
function get_domains($userid=true,$letterstart=all,$rowstart=0,$rowamount=999999)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   859
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   860
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   861
	if((!level(5) || !$userid) && !level(10) && !level(5))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   862
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   863
		$add = " AND zones.owner=".$_SESSION["userid"];
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   864
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   865
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   866
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   867
		$add = "";
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   868
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   869
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   870
	$sqlq = "SELECT domains.id AS domain_id,
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   871
	min(zones.owner) AS owner,
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   872
	count(DISTINCT records.id) AS aantal,
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   873
	domains.name AS domainname
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   874
	FROM domains
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   875
	LEFT JOIN zones ON domains.id=zones.domain_id 
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   876
	LEFT JOIN records ON records.domain_id=domains.id
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   877
	WHERE 1 $add ";
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   878
	if ($letterstart!=all && $letterstart!=1) {
21
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   879
	   $sqlq.=" AND substring(domains.name,1,1) REGEXP '^".$letterstart."' ";
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   880
	} elseif ($letterstart==1) {
21
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   881
	   $sqlq.=" AND substring(domains.name,1,1) REGEXP '^[[:digit:]]'";
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   882
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   883
	$sqlq.=" GROUP BY domainname, domain_id
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   884
	ORDER BY domainname
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   885
	LIMIT $rowstart,$rowamount";
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   886
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   887
	$result = $db->query($sqlq);
21
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   888
	$result2 = $db->query($sqlq); 
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   889
	
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   890
	$numrows = $result2->numRows();
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   891
	$i=1;
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   892
	if ($numrows > 0) {
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   893
		$andnot=" AND NOT domains.id IN (";
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   894
		while($r = $result2->fetchRow()) {
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   895
			$andnot.=$r["domain_id"];
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   896
			if ($i < $numrows) {
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   897
				$andnot.=",";
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   898
				$i++;
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   899
			}
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   900
		}
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   901
		$andnot.=")";
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   902
	}
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   903
	else
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   904
	{
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   905
		$andnot="";
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   906
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   907
21
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   908
	if ($letterstart!=all && $letterstart!=1) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   909
21
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   910
		$sqlq = "SELECT domains.id AS domain_id,
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   911
		count(DISTINCT record_owners.record_id) AS aantal,
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   912
		domains.name AS domainname
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   913
		FROM domains, record_owners,records, zones
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   914
		WHERE record_owners.user_id = '".$_SESSION["userid"]."'
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   915
		AND (records.id = record_owners.record_id
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   916
		AND domains.id = records.domain_id)
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   917
		$andnot 
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   918
		AND domains.name LIKE '".$letterstart."%' 
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   919
		AND (zones.domain_id != records.domain_id AND zones.owner!='".$_SESSION["userid"]."')
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   920
		GROUP BY domainname, domain_id
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   921
		ORDER BY domainname";
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   922
21
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   923
		$result_extra = $db->query($sqlq);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   924
21
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   925
	} else {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   926
21
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   927
		$sqlq = "SELECT domains.id AS domain_id,
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   928
		count(DISTINCT record_owners.record_id) AS aantal,
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   929
		domains.name AS domainname
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   930
		FROM domains, record_owners,records, zones
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   931
		WHERE record_owners.user_id = '".$_SESSION["userid"]."'
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   932
		AND (records.id = record_owners.record_id
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   933
		AND domains.id = records.domain_id)
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   934
		$andnot 
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   935
		AND substring(domains.name,1,1) REGEXP '^[[:digit:]]'
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   936
		AND (zones.domain_id != records.domain_id AND zones.owner!='".$_SESSION["userid"]."')
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   937
		GROUP BY domainname, domain_id
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   938
		ORDER BY domainname";
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   939
21
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   940
		$result_extra[$i] = $db->query($sqlq);
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   941
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   942
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   943
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   944
	while($r = $result->fetchRow())
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   945
	{
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
   946
		$r["owner"] = ($r["owner"] == NULL) ? $db->queryOne("select min(id) from users where users.level=10") : $r["owner"];
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   947
	     	$ret[$r["domainname"]] = array(
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   948
		"name"          =>              $r["domainname"],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   949
		"id"            =>              $r["domain_id"],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   950
		"owner"         =>              $r["owner"],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   951
		"numrec"        =>              $r["aantal"]
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   952
		);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   953
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   954
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   955
21
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   956
	if ($letterstart!=all && $letterstart!=1) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   957
21
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   958
		while($r = $result_extra->fetchRow())
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   959
		{
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   960
		       $ret[$r["domainname"]] = array(
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   961
		       "name"          =>              $r["domainname"]."*",
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   962
		       "id"            =>              $r["domain_id"],
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   963
		       "owner"         =>              $_SESSION["userid"],
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   964
		       "numrec"        =>              $r["aantal"]
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   965
		       );
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   966
		       $_SESSION["partial_".$r["domainname"]] = 1;
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   967
		}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   968
21
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   969
	} else {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   970
21
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   971
		foreach ($result_extra as $result_e) {
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   972
		while($r = $result_e->fetchRow())
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   973
		{
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   974
		       $ret[$r["domainname"]] = array(
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   975
		       "name"          =>              $r["domainname"]."*",
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   976
		       "id"            =>              $r["domain_id"],
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   977
		       "owner"         =>              $_SESSION["userid"],
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   978
		       "numrec"        =>              $r["aantal"]
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   979
		       );
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   980
		       $_SESSION["partial_".$r["domainname"]] = 1;
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   981
		}
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   982
		}
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   983
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   984
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   985
21
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   986
	if (empty($ret)) {
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   987
	   return -1;
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   988
	} else {
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   989
	   sort($ret);
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   990
	   return $ret;
31e17a9406eb [feladat @ 68]
rejo
parents: 19
diff changeset
   991
	}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   992
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   993
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   994
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   995
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   996
/*
30
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
   997
 * zone_count
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
   998
 * Does a select query to count how many zones we have in the database
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
   999
 *
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1000
 * @todo: see whether or not it is possible to add the records
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1001
 * @param $userid integer The userid of the current user
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1002
 * @return integer the number of zones
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1003
 */
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1004
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1005
function zone_count($userid=true, $letterstart=all) {
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1006
        global $db;
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1007
        if((!level(5) || !$userid) && !level(10) && !level(5))
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1008
        {
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1009
                $add = " AND zones.owner=".$_SESSION["userid"];
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1010
        }
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1011
        else
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1012
        {
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1013
                $add = "";
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1014
        }
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1015
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1016
        if ($letterstart!=all && $letterstart!=1) {
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1017
           $add .=" AND domains.name LIKE '".$letterstart."%' ";
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1018
        } elseif ($letterstart==1) {
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1019
           $add .=" AND substring(domains.name,1,1) REGEXP '^[[:digit:]]'";
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1020
        }
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1021
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1022
        $query = 'SELECT count(distinct zones.domain_id) as zone_count FROM zones, domains WHERE zones.domain_id = domains.id '.$add;
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1023
        $numRows = $db->queryOne($query);
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1024
        return $numRows;
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1025
}
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1026
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
  1027
/*
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1028
 * Get a record from an id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1029
 * Retrieve all fields of the record and send it back to the function caller.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1030
 * return values: the array with information, or -1 is nothing is found.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1031
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1032
function get_record_from_id($id)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1033
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1034
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1035
	if (is_numeric($id))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1036
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1037
		$result = $db->query("SELECT id, domain_id, name, type, content, ttl, prio, change_date FROM records WHERE id=$id");
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1038
		if($result->numRows() == 0)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1039
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1040
			return -1;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1041
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1042
		elseif ($result->numRows() == 1)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1043
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1044
			$r = $result->fetchRow();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1045
			$ret = array(
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1046
			"id"            =>      $r["id"],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1047
			"domain_id"     =>      $r["domain_id"],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1048
			"name"          =>      $r["name"],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1049
			"type"          =>      $r["type"],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1050
			"content"       =>      $r["content"],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1051
			"ttl"           =>      $r["ttl"],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1052
			"prio"          =>      $r["prio"],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1053
			"change_date"   =>      $r["change_date"]
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1054
			);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1055
			return $ret;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1056
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1057
		else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1058
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1059
			error(sprintf(ERR_INV_ARGC, "get_record_from_id", "More than one row returned! This is bad!"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1060
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1061
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1062
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1063
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1064
		error(sprintf(ERR_INV_ARG, "get_record_from_id"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1065
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1066
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1067
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1068
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1069
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1070
 * Get all records from a domain id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1071
 * Retrieve all fields of the records and send it back to the function caller.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1072
 * return values: the array with information, or -1 is nothing is found.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1073
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1074
function get_records_from_domain_id($id,$rowstart=0,$rowamount=999999)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1075
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1076
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1077
	if (is_numeric($id))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1078
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1079
		if ($_SESSION[$id."_ispartial"] == 1) {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1080
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1081
		$result = $db->query("SELECT record_owners.record_id as id
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1082
		FROM record_owners,domains,records
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1083
		WHERE record_owners.user_id = ".$_SESSION["userid"]."
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1084
		AND record_owners.record_id = records.id
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1085
		AND records.domain_id = ".$id."
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1086
		GROUP bY record_owners.record_id
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1087
		LIMIT $rowstart,$rowamount");
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1088
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1089
		$ret = array();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1090
		if($result->numRows() == 0)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1091
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1092
		return -1;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1093
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1094
		else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1095
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1096
		$ret[] = array();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1097
		$retcount = 0;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1098
		while($r = $result->fetchRow())
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1099
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1100
		// Call get_record_from_id for each row.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1101
		$ret[$retcount] = get_record_from_id($r["id"]);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1102
		$retcount++;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1103
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1104
		return $ret;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1105
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1106
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1107
		} else {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1108
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1109
		$result = $db->query("SELECT id FROM records WHERE domain_id=$id LIMIT $rowstart,$rowamount");
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1110
		$ret = array();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1111
		if($result->numRows() == 0)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1112
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1113
			return -1;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1114
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1115
		else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1116
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1117
			$ret[] = array();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1118
			$retcount = 0;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1119
			while($r = $result->fetchRow())
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1120
			{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1121
				// Call get_record_from_id for each row.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1122
				$ret[$retcount] = get_record_from_id($r["id"]);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1123
				$retcount++;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1124
			}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1125
			return $ret;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1126
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1127
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1128
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1129
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1130
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1131
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1132
		error(sprintf(ERR_INV_ARG, "get_records_from_domain_id"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1133
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1134
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1135
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1136
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1137
function get_users_from_domain_id($id)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1138
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1139
	global $db;
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
  1140
	$result = $db->queryCol("SELECT owner FROM zones WHERE domain_id=$id");
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1141
	$ret = array();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1142
	foreach($result as $uid)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1143
	{
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
  1144
		$fullname = $db->queryOne("SELECT fullname FROM users WHERE id=$uid");
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1145
		$ret[] = array(
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1146
		"id" 		=> 	$uid,
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1147
		"fullname"	=>	$fullname		
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1148
		);		
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1149
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1150
	return $ret;	
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1151
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1152
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1153
function search_record($question)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1154
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1155
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1156
	$question = trim($question);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1157
	if (empty($question)) 
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1158
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1159
		$S_INPUT_TYPE = -1;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1160
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1161
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1162
	/* now for some input-type searching */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1163
	if (is_valid_ip($question) || is_valid_ip6($question))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1164
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1165
		$S_INPUT_TYPE = 0;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1166
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1167
	elseif(is_valid_domain($question) || 
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1168
		is_valid_hostname($question) ||
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1169
		is_valid_mboxfw($question)) // I guess this one can appear in records table too (content?!)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1170
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1171
		$S_INPUT_TYPE = 1;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1172
	}	  
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1173
	else 
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1174
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1175
		$S_INPUT_TYPE = -1;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1176
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1177
	switch($S_INPUT_TYPE)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1178
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1179
		case '0': 
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1180
			$sqlq = "SELECT * FROM `records` WHERE `content` = '".$question."' ORDER BY `type` DESC";
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1181
			$result = $db->query($sqlq);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1182
			$ret_r = array();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1183
			while ($r = $result->fetchRow())
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1184
			{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1185
			    if(xs($r['domain_id']))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1186
			    {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1187
    				$ret_r[] = array(
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1188
    				  'id'			=>	$r['id'],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1189
    				  'domain_id'		=>	$r['domain_id'],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1190
    				  'name'		=>	$r['name'],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1191
    				  'type'		=>	$r['type'],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1192
    				  'content'		=>	$r['content'],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1193
    				  'ttl'			=>	$r['ttl'],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1194
    				  'prio'		=>	$r['prio'],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1195
    				  'change_date'		=>	$r['change_date']
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1196
    				);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1197
				}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1198
			}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1199
			break;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1200
	    
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1201
		case '1' :
5
ebf8868e99f5 [feladat @ 6]
rejo
parents: 1
diff changeset
  1202
			$sqlq = "SELECT `domains`.*, count(`records`.`id`) AS `numrec`, `zones`.`owner`, `records`.`domain_id`
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1203
					FROM `domains`, `records`, `zones`  
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1204
					WHERE `domains`.`id` = `records`.`domain_id` 
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1205
					AND `zones`.`domain_id` = `domains`.`id` 
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1206
					AND `domains`.`name` = '".$question."' 
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1207
					GROUP BY (`domains`.`id`)";
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1208
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1209
			$result = $db->query($sqlq);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1210
			$ret_d = array();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1211
			while ($r = $result->fetchRow())
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1212
			{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1213
			    if(xs($r['domain_id']))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1214
			    {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1215
				    $ret_d[] = array(
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1216
    					'id'			=>	$r['id'],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1217
    					'name'		=>	$r['name'],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1218
    					'numrec'		=>	$r['numrec'],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1219
    					'owner'		=>	$r['owner']
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1220
    				);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1221
				}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1222
			}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1223
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1224
			$sqlq = "SELECT * FROM `records` WHERE `name` = '".$question."' OR `content` = '".$question."' ORDER BY `type` DESC";
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1225
			$result = $db->query($sqlq);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1226
			while ($r = $result->fetchRow())
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1227
			{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1228
			    if(xs($r['domain_id']))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1229
			    {
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1230
    				$ret_r[] = array(
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1231
    					'id'			=>	$r['id'],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1232
    					'domain_id'		=>	$r['domain_id'],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1233
    					'name'		=>	$r['name'],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1234
    					'type'		=>	$r['type'],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1235
    					'content'		=>	$r['content'],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1236
    					'ttl'			=>	$r['ttl'],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1237
    					'prio'		=>	$r['prio'],
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1238
    				);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1239
    			}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1240
			}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1241
			break;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1242
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1243
	if($S_INPUT_TYPE == 1)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1244
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1245
		return array('domains' => $ret_d, 'records' => $ret_r);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1246
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1247
	return array('records' => $ret_r);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1248
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1249
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1250
function get_domain_type($id)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1251
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1252
	global $db;
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1253
        if (is_numeric($id))
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1254
	{
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1255
		$type = $db->queryOne("SELECT `type` FROM `domains` WHERE `id` = '".$id."'");
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1256
		if($type == "")
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1257
		{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1258
			$type = "NATIVE";
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1259
		}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1260
		return $type;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1261
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1262
        else
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1263
        {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1264
                error(sprintf(ERR_INV_ARG, "get_record_from_id", "no or no valid zoneid given"));
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1265
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1266
}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1267
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1268
function get_domain_slave_master($id)
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1269
{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1270
	global $db;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1271
        if (is_numeric($id))
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1272
	{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1273
		$slave_master = $db->queryOne("SELECT `master` FROM `domains` WHERE `type` = 'SLAVE' and `id` = '".$id."'");
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1274
		return $slave_master;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1275
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1276
        else
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1277
        {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1278
                error(sprintf(ERR_INV_ARG, "get_domain_slave_master", "no or no valid zoneid given"));
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1279
        }
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1280
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1281
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1282
function change_domain_type($type, $id)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1283
{
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1284
	global $db;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1285
	unset($add);
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1286
        if (is_numeric($id))
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1287
	{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1288
		// It is not really neccesary to clear the master field if a 
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1289
		// zone is not of the type "slave" as powerdns will ignore that
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1290
		// fiedl, but it is cleaner anyway.
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1291
		if ($type != "SLAVE")
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1292
		{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1293
			$add = ", master=''";
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1294
		}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1295
		$result = $db->query("UPDATE `domains` SET `type` = '" .$type. "'".$add." WHERE `id` = '".$id."'");
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1296
	}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1297
        else
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1298
        {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1299
                error(sprintf(ERR_INV_ARG, "change_domain_type", "no or no valid zoneid given"));
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1300
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1301
}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1302
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1303
function change_domain_slave_master($id, $slave_master)
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1304
{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1305
	global $db;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1306
        if (is_numeric($id))
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1307
	{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1308
       		if (is_valid_ip($slave_master) || is_valid_ip6($slave_master))
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1309
		{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1310
			$result = $db->query("UPDATE `domains` SET `master` = '" .$slave_master. "' WHERE `id` = '".$id."'");
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1311
		}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1312
		else
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1313
		{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1314
			error(sprintf(ERR_INV_ARGC, "change_domain_slave_master", "This is not a valid IPv4 or IPv6 address: $slave_master"));
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1315
		}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1316
	}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1317
        else
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1318
        {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1319
                error(sprintf(ERR_INV_ARG, "change_domain_type", "no or no valid zoneid given"));
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1320
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1321
}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1322
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1323
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1324
function validate_account($account)
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1325
{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1326
	
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1327
  	if(preg_match("/^[A-Z0-9._-]+$/i",$account))
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1328
	{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1329
		return true;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1330
	}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1331
	else
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1332
	{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1333
		return false;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1334
	}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1335
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1336
?>