inc/record.inc.php
author rejo
Sun, 18 May 2008 11:51:59 +0000
changeset 170 391e744a1def
parent 169 41353c2e0c9f
child 171 2a10febd6af9
permissions -rw-r--r--
[feladat @ 277] Changed legacy function name for hostname validation to new code. Bug reported by Adhisimon. Closes: #55.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
71
e1b918eaf69a [feladat @ 118]
peter
parents: 65
diff changeset
     1
<?php
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
     2
119
f74e4f88b680 [feladat @ 222]
rejo
parents: 115
diff changeset
     3
/*  Poweradmin, a friendly web-based admin tool for PowerDNS.
47
ae140472d97c [feladat @ 94]
rejo
parents: 40
diff changeset
     4
 *  See <https://rejo.zenger.nl/poweradmin> for more details.
ae140472d97c [feladat @ 94]
rejo
parents: 40
diff changeset
     5
 *
ae140472d97c [feladat @ 94]
rejo
parents: 40
diff changeset
     6
 *  Copyright 2007, 2008  Rejo Zenger <rejo@zenger.nl>
ae140472d97c [feladat @ 94]
rejo
parents: 40
diff changeset
     7
 *
ae140472d97c [feladat @ 94]
rejo
parents: 40
diff changeset
     8
 *  This program is free software: you can redistribute it and/or modify
ae140472d97c [feladat @ 94]
rejo
parents: 40
diff changeset
     9
 *  it under the terms of the GNU General Public License as published by
ae140472d97c [feladat @ 94]
rejo
parents: 40
diff changeset
    10
 *  the Free Software Foundation, either version 3 of the License, or
ae140472d97c [feladat @ 94]
rejo
parents: 40
diff changeset
    11
 *  (at your option) any later version.
ae140472d97c [feladat @ 94]
rejo
parents: 40
diff changeset
    12
 *
ae140472d97c [feladat @ 94]
rejo
parents: 40
diff changeset
    13
 *  This program is distributed in the hope that it will be useful,
ae140472d97c [feladat @ 94]
rejo
parents: 40
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ae140472d97c [feladat @ 94]
rejo
parents: 40
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ae140472d97c [feladat @ 94]
rejo
parents: 40
diff changeset
    16
 *  GNU General Public License for more details.
ae140472d97c [feladat @ 94]
rejo
parents: 40
diff changeset
    17
 *
ae140472d97c [feladat @ 94]
rejo
parents: 40
diff changeset
    18
 *  You should have received a copy of the GNU General Public License
ae140472d97c [feladat @ 94]
rejo
parents: 40
diff changeset
    19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
ae140472d97c [feladat @ 94]
rejo
parents: 40
diff changeset
    20
 */
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    21
141
1ede5203910d [feladat @ 247]
rejo
parents: 140
diff changeset
    22
function zone_id_exists($zid) {
1ede5203910d [feladat @ 247]
rejo
parents: 140
diff changeset
    23
	global $db;
1ede5203910d [feladat @ 247]
rejo
parents: 140
diff changeset
    24
	$query = "SELECT COUNT(id) FROM domains WHERE id = " . $db->quote($zid);
1ede5203910d [feladat @ 247]
rejo
parents: 140
diff changeset
    25
	$count = $db->queryOne($query);
1ede5203910d [feladat @ 247]
rejo
parents: 140
diff changeset
    26
	if (PEAR::isError($result)) { error($result->getMessage()); return false; }
1ede5203910d [feladat @ 247]
rejo
parents: 140
diff changeset
    27
	return $count;
1ede5203910d [feladat @ 247]
rejo
parents: 140
diff changeset
    28
}
1ede5203910d [feladat @ 247]
rejo
parents: 140
diff changeset
    29
1ede5203910d [feladat @ 247]
rejo
parents: 140
diff changeset
    30
120
982f722376b4 [feladat @ 223]
rejo
parents: 119
diff changeset
    31
function get_zone_id_from_record_id($rid) {
982f722376b4 [feladat @ 223]
rejo
parents: 119
diff changeset
    32
	global $db;
982f722376b4 [feladat @ 223]
rejo
parents: 119
diff changeset
    33
	$query = "SELECT domain_id FROM records WHERE id = " . $db->quote($rid);
982f722376b4 [feladat @ 223]
rejo
parents: 119
diff changeset
    34
	$zid = $db->queryOne($query);
982f722376b4 [feladat @ 223]
rejo
parents: 119
diff changeset
    35
	return $zid;
982f722376b4 [feladat @ 223]
rejo
parents: 119
diff changeset
    36
}
982f722376b4 [feladat @ 223]
rejo
parents: 119
diff changeset
    37
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    38
function count_zone_records($zone_id) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    39
	global $db;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    40
	$sqlq = "SELECT COUNT(id) FROM records WHERE domain_id = ".$db->quote($zone_id);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    41
	$record_count = $db->queryOne($sqlq);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    42
	return $record_count;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    43
}
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    44
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    45
function update_soa_serial($domain_id)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    46
{
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    47
	global $db;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    48
65
ce1c4d5e1576 [feladat @ 112]
peter
parents: 63
diff changeset
    49
	$sqlq = "SELECT notified_serial FROM domains WHERE id = ".$db->quote($domain_id);
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
    50
	$notified_serial = $db->queryOne($sqlq);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    51
65
ce1c4d5e1576 [feladat @ 112]
peter
parents: 63
diff changeset
    52
	$sqlq = "SELECT content FROM records WHERE type = 'SOA' AND domain_id = ".$db->quote($domain_id);
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 5
diff changeset
    53
	$content = $db->queryOne($sqlq);
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    54
	$need_to_update = false;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    55
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    56
	// Getting the serial field.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    57
	$soa = explode(" ", $content);
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    58
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    59
	if(empty($notified_serial)) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    60
		// Ok native replication, so we have to update.
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    61
		$need_to_update = true;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    62
	} elseif($notified_serial >= $soa[2]) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    63
		$need_to_update = true;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    64
	} elseif(strlen($soa[2]) != 10) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    65
		$need_to_update = true;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    66
	} else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    67
		$need_to_update = false;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    68
	}
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    69
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    70
	if($need_to_update) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    71
		// Ok so we have to update it seems.
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    72
		$current_serial = $soa[2];
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    73
		$new_serial = date('Ymd'); // we will add revision number later
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    74
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    75
		if(strncmp($new_serial, $current_serial, 8) === 0) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    76
			$revision_number = (int) substr($current_serial, -2);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    77
			if ($revision_number == 99) return false; // ok, we cannot update anymore tonight
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    78
			++$revision_number;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    79
			// here it is ... same date, new revision
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    80
			$new_serial .= str_pad($revision_number, 2, "0", STR_PAD_LEFT);	
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    81
		} else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    82
			/*
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    83
			 * Current serial is not RFC1912 compilant, so let's make a new one
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    84
			 */
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    85
			$new_serial .= '00';
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    86
		}
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    87
		$soa[2] = $new_serial; // change serial in SOA array
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    88
		$new_soa = "";		
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    89
		// build new soa and update SQL after that
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
    90
		for ($i = 0; $i < count($soa); $i++) {	
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    91
			$new_soa .= $soa[$i] . " "; 
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    92
		}
65
ce1c4d5e1576 [feladat @ 112]
peter
parents: 63
diff changeset
    93
		$sqlq = "UPDATE records SET content = ".$db->quote($new_soa)." WHERE domain_id = ".$db->quote($domain_id)." AND type = 'SOA'";
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    94
		$db->Query($sqlq);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    95
		return true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    96
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    97
}  
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    98
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    99
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   100
 * Edit a record.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   101
 * This function validates it if correct it inserts it into the database.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   102
 * return values: true if succesful.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   103
 */
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   104
function edit_record($record) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   105
126
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   106
	if (verify_permission('zone_content_edit_others')) { $perm_content_edit = "all" ; }
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   107
	elseif (verify_permission('zone_content_edit_own')) { $perm_content_edit = "own" ; }
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   108
	else { $perm_content_edit = "none" ; }
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   109
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   110
	$user_is_zone_owner = verify_user_is_owner_zoneid($record['zid']);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   111
	$zone_type = get_domain_type($record['zid']);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   112
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   113
	if ( $zone_type == "SLAVE" || $perm_content_edit == "none" || $perm_content_edit == "own" && $user_is_zone_owner == "0" ) {
111
0a2342a64b83 [feladat @ 211]
rejo
parents: 106
diff changeset
   114
		error(ERR_PERM_EDIT_RECORD);
0a2342a64b83 [feladat @ 211]
rejo
parents: 106
diff changeset
   115
		return false;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   116
	} else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   117
		if($record['content'] == "") {
111
0a2342a64b83 [feladat @ 211]
rejo
parents: 106
diff changeset
   118
			error(ERR_DNS_CONTENT);
0a2342a64b83 [feladat @ 211]
rejo
parents: 106
diff changeset
   119
			return false;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   120
		}
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   121
		global $db;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   122
		// TODO: no need to check for numeric-ness of zone id if we check with validate_input as well?
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   123
		if (is_numeric($record['zid'])) {
135
3673b1c9246c [feladat @ 241]
peter
parents: 134
diff changeset
   124
			if (validate_input($record['zid'], $record['type'], $record['content'], $record['name'], $record['prio'], $record['ttl'])) {
3673b1c9246c [feladat @ 241]
peter
parents: 134
diff changeset
   125
				$query = "UPDATE records 
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   126
					SET name=".$db->quote($record['name']).", 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   127
					type=".$db->quote($record['type']).", 
138
3e36ebbfe048 [feladat @ 244]
rejo
parents: 136
diff changeset
   128
					content='" . $record['content'] . "', 
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   129
					ttl=".$db->quote($record['ttl']).", 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   130
					prio=".$db->quote($record['prio']).", 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   131
					change_date=".$db->quote(time())." 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   132
					WHERE id=".$db->quote($record['rid']);
135
3673b1c9246c [feladat @ 241]
peter
parents: 134
diff changeset
   133
				$result = $db->Query($query);
3673b1c9246c [feladat @ 241]
peter
parents: 134
diff changeset
   134
				if (PEAR::isError($result)) {
3673b1c9246c [feladat @ 241]
peter
parents: 134
diff changeset
   135
					error($result->getMessage());
3673b1c9246c [feladat @ 241]
peter
parents: 134
diff changeset
   136
					return false;
3673b1c9246c [feladat @ 241]
peter
parents: 134
diff changeset
   137
				} elseif ($record['type'] != 'SOA') {
3673b1c9246c [feladat @ 241]
peter
parents: 134
diff changeset
   138
					update_soa_serial($record['zid']);
3673b1c9246c [feladat @ 241]
peter
parents: 134
diff changeset
   139
				}
3673b1c9246c [feladat @ 241]
peter
parents: 134
diff changeset
   140
				return true;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   141
			}
135
3673b1c9246c [feladat @ 241]
peter
parents: 134
diff changeset
   142
			return false;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   143
		}
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   144
		else
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   145
		{
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   146
			// TODO change to error style as above (returning directly)
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   147
			error(sprintf(ERR_INV_ARGC, "edit_record", "no zoneid given"));
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   148
		}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   149
	}
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   150
	return true;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   151
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   152
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   153
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   154
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   155
 * Adds a record.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   156
 * This function validates it if correct it inserts it into the database.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   157
 * return values: true if succesful.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   158
 */
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   159
function add_record($zoneid, $name, $type, $content, $ttl, $prio) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   160
	global $db;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   161
126
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   162
	if (verify_permission('zone_content_edit_others')) { $perm_content_edit = "all" ; }
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   163
	elseif (verify_permission('zone_content_edit_own')) { $perm_content_edit = "own" ; }
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   164
	else { $perm_content_edit = "none" ; }
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   165
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   166
	$user_is_zone_owner = verify_user_is_owner_zoneid($zoneid);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   167
	$zone_type = get_domain_type($zoneid);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   168
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   169
        if ( $zone_type == "SLAVE" || $perm_content_edit == "none" || $perm_content_edit == "own" && $user_is_zone_owner == "0" ) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   170
		error(ERR_PERM_ADD_RECORD);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   171
		return false;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   172
	} else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   173
		if (validate_input($zoneid, $type, $content, $name, $prio, $ttl) ) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   174
			$change = time();
106
41d05ff53708 [feladat @ 206]
peter
parents: 98
diff changeset
   175
			$query = "INSERT INTO records (domain_id, name, type, content, ttl, prio, change_date) VALUES ("
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   176
						. $db->quote($zoneid) . ","
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   177
						. $db->quote($name) . "," 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   178
						. $db->quote($type) . "," 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   179
						. $db->quote($content) . ","
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   180
						. $db->quote($ttl) . ","
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   181
						. $db->quote($prio) . ","
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   182
						. $db->quote($change) . ")";
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   183
			$response = $db->query($query);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   184
			if (PEAR::isError($response)) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   185
				error($response->getMessage());
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   186
				return false;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   187
			} else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   188
				if ($type != 'SOA') { update_soa_serial($zoneid); }
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   189
				return true;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   190
			}
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   191
		} else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   192
			return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   193
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   194
		return true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   195
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   196
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   197
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   198
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   199
function add_supermaster($master_ip, $ns_name, $account)
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   200
{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   201
        global $db;
161
0832d846bf8e [feladat @ 267]
rejo
parents: 160
diff changeset
   202
        if (!is_valid_ipv4($master_ip) && !is_valid_ipv6($master_ip)) {
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   203
                error(ERR_DNS_IP);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   204
		return false;
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   205
        }
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   206
        if (!is_valid_hostname($ns_name)) {
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   207
                error(ERR_DNS_HOSTNAME);
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   208
		return false;
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   209
        }
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   210
	if (!validate_account($account)) {
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   211
		error(sprintf(ERR_INV_ARGC, "add_supermaster", "given account name is invalid (alpha chars only)"));
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   212
		return false;
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   213
	}
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   214
        if (supermaster_exists($master_ip)) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   215
                error(ERR_SM_EXISTS);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   216
		return false;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   217
        } else {
65
ce1c4d5e1576 [feladat @ 112]
peter
parents: 63
diff changeset
   218
                $db->query("INSERT INTO supermasters VALUES (".$db->quote($master_ip).", ".$db->quote($ns_name).", ".$db->quote($account).")");
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   219
                return true;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   220
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   221
}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   222
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   223
function delete_supermaster($master_ip) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   224
	global $db;
161
0832d846bf8e [feladat @ 267]
rejo
parents: 160
diff changeset
   225
        if (is_valid_ipv4($master_ip) || is_valid_ipv6($master_ip))
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   226
        {
65
ce1c4d5e1576 [feladat @ 112]
peter
parents: 63
diff changeset
   227
                $db->query("DELETE FROM supermasters WHERE ip = ".$db->quote($master_ip));
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   228
                return true;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   229
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   230
        else
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   231
        {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   232
                error(sprintf(ERR_INV_ARGC, "delete_supermaster", "No or no valid ipv4 or ipv6 address given."));
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   233
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   234
}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   235
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   236
function get_supermaster_info_from_ip($master_ip)
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   237
{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   238
	global $db;
161
0832d846bf8e [feladat @ 267]
rejo
parents: 160
diff changeset
   239
        if (is_valid_ipv4($master_ip) || is_valid_ipv6($master_ip))
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   240
	{
65
ce1c4d5e1576 [feladat @ 112]
peter
parents: 63
diff changeset
   241
	        $result = $db->queryRow("SELECT ip,nameserver,account FROM supermasters WHERE ip = ".$db->quote($master_ip));
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   242
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   243
		$ret = array(
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   244
		"master_ip"	=>              $result["ip"],
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   245
		"ns_name"	=>              $result["nameserver"],
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   246
		"account"	=>              $result["account"]
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   247
		);
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   248
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   249
		return $ret;	
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   250
	}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   251
        else
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   252
	{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   253
                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
   254
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   255
}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   256
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   257
function get_record_details_from_record_id($rid) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   258
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   259
	global $db;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   260
98
9c10fd623368 [feladat @ 198]
rejo
parents: 93
diff changeset
   261
	$query = "SELECT id AS rid, domain_id AS zid, name, type, content, ttl, prio, change_date FROM records WHERE id = " . $db->quote($rid) ;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   262
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   263
	$response = $db->query($query);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   264
	if (PEAR::isError($response)) { error($response->getMessage()); return false; }
98
9c10fd623368 [feladat @ 198]
rejo
parents: 93
diff changeset
   265
	
9c10fd623368 [feladat @ 198]
rejo
parents: 93
diff changeset
   266
	$return = $response->fetchRow();
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   267
	return $return;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   268
}
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   269
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   270
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   271
 * Delete a record by a given id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   272
 * return values: true, this function is always succesful.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   273
 */
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   274
function delete_record($rid)
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   275
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   276
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   277
126
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   278
	if (verify_permission('zone_content_edit_others')) { $perm_content_edit = "all" ; } 
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   279
	elseif (verify_permission('zone_content_edit_own')) { $perm_content_edit = "own" ; } 
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   280
	else { $perm_content_edit = "none" ; }
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   281
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   282
	// Determine ID of zone first.
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   283
	$record = get_record_details_from_record_id($rid);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   284
	$user_is_zone_owner = verify_user_is_owner_zoneid($record['zid']);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   285
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   286
	if ( $perm_content_edit == "all" || ($perm_content_edit == "own" && $user_is_zone_owner == "0" )) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   287
		if ($record['type'] == "SOA") {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   288
			error(_('You are trying to delete the SOA record. If are not allowed to remove it, unless you remove the entire zone.'));
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   289
		} else {
98
9c10fd623368 [feladat @ 198]
rejo
parents: 93
diff changeset
   290
			$query = "DELETE FROM records WHERE id = " . $db->quote($rid);
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   291
			$response = $db->query($query);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   292
			if (PEAR::isError($response)) { error($response->getMessage()); return false; }
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   293
			return true;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   294
		}
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   295
	} else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   296
		error(ERR_PERM_DEL_RECORD);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   297
		return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   298
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   299
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   300
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   301
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   302
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   303
 * Add a domain to the database.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   304
 * A domain is name obligatory, so is an owner.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   305
 * return values: true when succesful.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   306
 * Empty means templates dont have to be applied.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   307
 * --------------------------------------------------------------------------
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   308
 * This functions eats a template and by that it inserts various records.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   309
 * first we start checking if something in an arpa record
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   310
 * remember to request nextID's from the database to be able to insert record.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   311
 * if anything is invalid the function will error
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   312
 */
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   313
function add_domain($domain, $owner, $webip, $mailip, $empty, $type, $slave_master)
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   314
{
126
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   315
	if(verify_permission('zone_master_add')) { $zone_master_add = "1" ; } ;
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   316
	if(verify_permission('zone_slave_add')) { $zone_slave_add = "1" ; } ;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   317
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   318
	// TODO: make sure only one is possible if only one is enabled
86
0205771bf84c [feladat @ 186]
rejo
parents: 82
diff changeset
   319
	if($zone_master_add == "1" || $zone_slave_add == "1") {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   320
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   321
		global $db;
136
c795dd75a77e [feladat @ 242]
rejo
parents: 135
diff changeset
   322
		global $dns_ns1;
c795dd75a77e [feladat @ 242]
rejo
parents: 135
diff changeset
   323
		global $dns_hostmaster;
c795dd75a77e [feladat @ 242]
rejo
parents: 135
diff changeset
   324
		global $dns_ttl;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   325
		if (($domain && $owner && $webip && $mailip) || 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   326
				($empty && $owner && $domain) || 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   327
				(eregi('in-addr.arpa', $domain) && $owner) || 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   328
				$type=="SLAVE" && $domain && $owner && $slave_master) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   329
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   330
			$response = $db->query("INSERT INTO domains (name, type) VALUES (".$db->quote($domain).", ".$db->quote($type).")");
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   331
			if (PEAR::isError($response)) { error($response->getMessage()); return false; }
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   332
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   333
			$domain_id = $db->lastInsertId('domains', 'id');
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   334
			if (PEAR::isError($domain_id)) { error($id->getMessage()); return false; }
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   335
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   336
			$response = $db->query("INSERT INTO zones (domain_id, owner) VALUES (".$db->quote($domain_id).", ".$db->quote($owner).")");
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   337
			if (PEAR::isError($response)) { error($response->getMessage()); return false; }
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   338
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   339
			if ($type == "SLAVE") {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   340
				$response = $db->query("UPDATE domains SET master = ".$db->quote($slave_master)." WHERE id = ".$db->quote($domain_id));
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   341
				if (PEAR::isError($response)) { error($response->getMessage()); return false; }
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   342
				return true;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   343
			} else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   344
				$now = time();
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   345
				if ($empty && $domain_id) {
136
c795dd75a77e [feladat @ 242]
rejo
parents: 135
diff changeset
   346
					$ns1 = $dns_ns1;
c795dd75a77e [feladat @ 242]
rejo
parents: 135
diff changeset
   347
					$hm  = $dns_hostmaster;
c795dd75a77e [feladat @ 242]
rejo
parents: 135
diff changeset
   348
					$ttl = $dns_ttl;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   349
106
41d05ff53708 [feladat @ 206]
peter
parents: 98
diff changeset
   350
					$query = "INSERT INTO records (domain_id, name, content, type, ttl, prio, change_date) VALUES (" 
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   351
							. $db->quote($domain_id) . "," 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   352
							. $db->quote($domain) . "," 
133
7863d881b8a5 [feladat @ 239]
rejo
parents: 128
diff changeset
   353
							. $db->quote($ns1.' '.$hm.' 1') . ","
106
41d05ff53708 [feladat @ 206]
peter
parents: 98
diff changeset
   354
							. $db->quote('SOA').","
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   355
							. $db->quote($ttl) 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   356
							. ", 0, "
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   357
							. $db->quote($now).")";
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   358
					$response = $db->query($query);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   359
					if (PEAR::isError($response)) { error($response->getMessage()); return false; }
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   360
				} elseif ($domain_id) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   361
					global $template;
136
c795dd75a77e [feladat @ 242]
rejo
parents: 135
diff changeset
   362
					global $dns_ttl;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   363
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   364
					foreach ($template as $r) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   365
						if ((eregi('in-addr.arpa', $domain) && ($r["type"] == "NS" || $r["type"] == "SOA")) || (!eregi('in-addr.arpa', $domain)))
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   366
						{
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   367
							$name     = parse_template_value($r["name"], $domain, $webip, $mailip);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   368
							$type     = $r["type"];
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   369
							$content  = parse_template_value($r["content"], $domain, $webip, $mailip);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   370
							$ttl      = $r["ttl"];
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   371
							$prio     = intval($r["prio"]);
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   372
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   373
							if (!$ttl) {
136
c795dd75a77e [feladat @ 242]
rejo
parents: 135
diff changeset
   374
								$ttl = $dns_ttl;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   375
							}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   376
106
41d05ff53708 [feladat @ 206]
peter
parents: 98
diff changeset
   377
							$query = "INSERT INTO records (domain_id, name, type, content, ttl, prio, change_date) VALUES (" 
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   378
									. $db->quote($domain_id) . ","
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   379
									. $db->quote($name) . ","
87
654262e698e2 [feladat @ 187]
rejo
parents: 86
diff changeset
   380
									. $db->quote($type) . ","
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   381
									. $db->quote($content) . ","
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   382
									. $db->quote($ttl) . ","
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   383
									. $db->quote($prio) . ","
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   384
									. $db->quote($now) . ")";
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   385
							$response = $db->query($query);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   386
							if (PEAR::isError($response)) { error($response->getMessage()); return false; }
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   387
						}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   388
					}
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   389
					return true;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   390
				 } else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   391
					error(sprintf(ERR_INV_ARGC, "add_domain", "could not create zone"));
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   392
				 }
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   393
			}
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   394
		} else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   395
			error(sprintf(ERR_INV_ARG, "add_domain"));
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   396
		}
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   397
	} else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   398
		error(ERR_PERM_ADD_ZONE_MASTER);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   399
		return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   400
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   401
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   402
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   403
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   404
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   405
 * Deletes a domain by a given id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   406
 * Function always succeeds. If the field is not found in the database, thats what we want anyway.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   407
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   408
function delete_domain($id)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   409
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   410
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   411
126
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   412
	if (verify_permission('zone_content_edit_others')) { $perm_edit = "all" ; }
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   413
	elseif (verify_permission('zone_content_edit_own')) { $perm_edit = "own" ; }
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   414
	else { $perm_edit = "none" ; }
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   415
	$user_is_zone_owner = verify_user_is_owner_zoneid($id);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   416
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   417
        if ( $perm_edit == "all" || ( $perm_edit == "own" && $user_is_zone_owner == "1") ) {    
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   418
		if (is_numeric($id)) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   419
			$db->query("DELETE FROM zones WHERE domain_id=".$db->quote($id));
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   420
			$db->query("DELETE FROM domains WHERE id=".$db->quote($id));
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   421
			$db->query("DELETE FROM records WHERE domain_id=".$db->quote($id));
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   422
			return true;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   423
		} else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   424
			error(sprintf(ERR_INV_ARGC, "delete_domain", "id must be a number"));
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   425
			return false;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   426
		}
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   427
	} else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   428
		error(ERR_PERM_DEL_ZONE);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   429
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   430
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   431
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   432
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   433
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   434
 * Gets the id of the domain by a given record id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   435
 * return values: the domain id that was requested.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   436
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   437
function recid_to_domid($id)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   438
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   439
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   440
	if (is_numeric($id))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   441
	{
65
ce1c4d5e1576 [feladat @ 112]
peter
parents: 63
diff changeset
   442
		$result = $db->query("SELECT domain_id FROM records WHERE id=".$db->quote($id));
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   443
		$r = $result->fetchRow();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   444
		return $r["domain_id"];
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   445
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   446
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   447
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   448
		error(sprintf(ERR_INV_ARGC, "recid_to_domid", "id must be a number"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   449
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   450
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   451
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   452
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   453
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   454
 * Change owner of a domain.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   455
 * return values: true when succesful.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   456
 */
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   457
function add_owner_to_zone($zone_id, $user_id)
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   458
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   459
	global $db;
126
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   460
	if ( (verify_permission('zone_meta_edit_others')) || (verify_permission('zone_meta_edit_own')) && verify_user_is_owner_zoneid($_GET["id"])) {
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   461
		// User is allowed to make change to meta data of this zone.
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   462
		if (is_numeric($zone_id) && is_numeric($user_id) && is_valid_user($user_id))
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   463
		{
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   464
			if($db->queryOne("SELECT COUNT(id) FROM zones WHERE owner=".$db->quote($user_id)." AND domain_id=".$db->quote($zone_id)) == 0)
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   465
			{
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   466
				$db->query("INSERT INTO zones (domain_id, owner) VALUES(".$db->quote($zone_id).", ".$db->quote($user_id).")");
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   467
			}
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   468
			return true;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   469
		} else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   470
			error(sprintf(ERR_INV_ARGC, "add_owner_to_zone", "$zone_id / $user_id"));
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   471
		}
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   472
	} else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   473
		return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   474
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   475
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   476
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   477
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   478
function delete_owner_from_zone($zone_id, $user_id)
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   479
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   480
	global $db;
126
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   481
	if ( (verify_permission('zone_meta_edit_others')) || (verify_permission('zone_meta_edit_own')) && verify_user_is_owner_zoneid($_GET["id"])) {
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   482
		// User is allowed to make change to meta data of this zone.
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   483
		if (is_numeric($zone_id) && is_numeric($user_id) && is_valid_user($user_id))
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   484
		{
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   485
			// TODO: Next if() required, why not just execute DELETE query?
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   486
			if($db->queryOne("SELECT COUNT(id) FROM zones WHERE owner=".$db->quote($user_id)." AND domain_id=".$db->quote($zone_id)) != 0)
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   487
			{
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   488
				$db->query("DELETE FROM zones WHERE owner=".$db->quote($user_id)." AND domain_id=".$db->quote($zone_id));
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   489
			}
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   490
			return true;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   491
		} else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   492
			error(sprintf(ERR_INV_ARGC, "delete_owner_from_zone", "$zone_id / $user_id"));
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   493
		}
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   494
	} else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   495
		return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   496
	}
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   497
	
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   498
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   499
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   500
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   501
 * Retrieves all supported dns record types
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   502
 * This function might be deprecated.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   503
 * return values: array of types in string form.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   504
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   505
function get_record_types()
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   506
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   507
	global $rtypes;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   508
	return $rtypes;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   509
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   510
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   511
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   512
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   513
 * Retrieve all records by a given type and domain id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   514
 * Example: get all records that are of type A from domain id 1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   515
 * return values: a DB class result object
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   516
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   517
function get_records_by_type_from_domid($type, $recid)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   518
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   519
	global $rtypes;
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
	// Does this type exist?
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   523
	if(!in_array(strtoupper($type), $rtypes))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   524
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   525
		error(sprintf(ERR_INV_ARGC, "get_records_from_type", "this is not a supported record"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   526
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   527
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   528
	// Get the domain id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   529
	$domid = recid_to_domid($recid);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   530
65
ce1c4d5e1576 [feladat @ 112]
peter
parents: 63
diff changeset
   531
	$result = $db->query("select id, type from records where domain_id=".$db->quote($recid)." and type=".$db->quote($type));
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   532
	return $result;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   533
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   534
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   535
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   536
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   537
 * Retrieves the type of a record from a given id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   538
 * return values: the type of the record (one of the records types in $rtypes assumable).
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   539
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   540
function get_recordtype_from_id($id)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   541
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   542
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   543
	if (is_numeric($id))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   544
	{
65
ce1c4d5e1576 [feladat @ 112]
peter
parents: 63
diff changeset
   545
		$result = $db->query("SELECT type FROM records WHERE id=".$db->quote($id));
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   546
		$r = $result->fetchRow();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   547
		return $r["type"];
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   548
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   549
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   550
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   551
		error(sprintf(ERR_INV_ARG, "get_recordtype_from_id"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   552
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   553
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   554
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   555
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   556
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   557
 * Retrieves the name (e.g. bla.test.com) of a record by a given id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   558
 * return values: the name associated with the id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   559
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   560
function get_name_from_record_id($id)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   561
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   562
	global $db;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   563
	if (is_numeric($id)) {
65
ce1c4d5e1576 [feladat @ 112]
peter
parents: 63
diff changeset
   564
		$result = $db->query("SELECT name FROM records WHERE id=".$db->quote($id));
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   565
		$r = $result->fetchRow();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   566
		return $r["name"];
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   567
	} else {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   568
		error(sprintf(ERR_INV_ARG, "get_name_from_record_id"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   569
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   570
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   571
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   572
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   573
function get_zone_name_from_id($zid)
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   574
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   575
	global $db;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   576
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   577
	if (is_numeric($zid))
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   578
	{
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   579
		$result = $db->query("SELECT name FROM domains WHERE id=".$db->quote($zid));
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   580
		$rows = $result->numRows() ;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   581
		if ($rows == 1) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   582
 			$r = $result->fetchRow();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   583
 			return $r["name"];
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   584
		} elseif ($rows == "0") {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   585
			error(sprintf("Zone does not exist."));
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   586
			return false;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   587
		} else {
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   588
	 		error(sprintf(ERR_INV_ARGC, "get_zone_name_from_id", "more than one domain found?! whaaa! BAD! BAD! Contact admin!"));
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   589
			return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   590
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   591
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   592
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   593
	{
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   594
		error(sprintf(ERR_INV_ARGC, "get_zone_name_from_id", "Not a valid domainid: $id"));
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   595
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   596
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   597
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   598
function get_zone_info_from_id($zid) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   599
126
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   600
	if (verify_permission('zone_content_view_others')) { $perm_view = "all" ; } 
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   601
	elseif (verify_permission('zone_content_view_own')) { $perm_view = "own" ; }
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   602
	else { $perm_view = "none" ;}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   603
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   604
	if ($perm_view == "none") { 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   605
		error(ERR_PERM_VIEW_ZONE);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   606
	} else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   607
		global $db;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   608
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   609
		$query = "SELECT 	domains.type AS type, 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   610
					domains.name AS name, 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   611
					domains.master AS master_ip,
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   612
					count(records.domain_id) AS record_count
134
a8228f676bf7 [feladat @ 240]
peter
parents: 133
diff changeset
   613
					FROM domains LEFT OUTER JOIN records ON domains.id = records.domain_id 
140
e68c3d6094d1 [feladat @ 246]
rejo
parents: 138
diff changeset
   614
					WHERE domains.id = " . $db->quote($zid) . "
134
a8228f676bf7 [feladat @ 240]
peter
parents: 133
diff changeset
   615
					GROUP BY domains.id, domains.type, domains.name, domains.master";
88
fa948cc3727e [feladat @ 188]
rejo
parents: 87
diff changeset
   616
		$result = $db->query($query);
fa948cc3727e [feladat @ 188]
rejo
parents: 87
diff changeset
   617
		if (PEAR::isError($result)) { error($result->getMessage()); return false; }
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   618
88
fa948cc3727e [feladat @ 188]
rejo
parents: 87
diff changeset
   619
		if($result->numRows() != 1) {
fa948cc3727e [feladat @ 188]
rejo
parents: 87
diff changeset
   620
			error(_('Function returned an error (multiple zones matching this zone ID).'));
fa948cc3727e [feladat @ 188]
rejo
parents: 87
diff changeset
   621
			return false;
fa948cc3727e [feladat @ 188]
rejo
parents: 87
diff changeset
   622
		} else {
fa948cc3727e [feladat @ 188]
rejo
parents: 87
diff changeset
   623
			$r = $result->fetchRow();
fa948cc3727e [feladat @ 188]
rejo
parents: 87
diff changeset
   624
			$return = array(
fa948cc3727e [feladat @ 188]
rejo
parents: 87
diff changeset
   625
				"name"		=>	$r['name'],
fa948cc3727e [feladat @ 188]
rejo
parents: 87
diff changeset
   626
				"type"		=>	$r['type'],
fa948cc3727e [feladat @ 188]
rejo
parents: 87
diff changeset
   627
				"master_ip"	=>	$r['master_ip'],
fa948cc3727e [feladat @ 188]
rejo
parents: 87
diff changeset
   628
				"record_count"	=>	$r['record_count']
fa948cc3727e [feladat @ 188]
rejo
parents: 87
diff changeset
   629
				);
fa948cc3727e [feladat @ 188]
rejo
parents: 87
diff changeset
   630
		}
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   631
		return $return;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   632
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   633
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   634
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   635
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   636
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   637
 * Check if a domain is already existing.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   638
 * return values: true if existing, false if it doesnt exist.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   639
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   640
function domain_exists($domain)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   641
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   642
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   643
170
391e744a1def [feladat @ 277]
rejo
parents: 169
diff changeset
   644
	if (is_valid_hostname_fqdn($domain)) {
65
ce1c4d5e1576 [feladat @ 112]
peter
parents: 63
diff changeset
   645
		$result = $db->query("SELECT id FROM domains WHERE name=".$db->quote($domain));
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   646
		if ($result->numRows() == 0) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   647
			return false;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   648
		} elseif ($result->numRows() >= 1) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   649
			return true;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   650
		}
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   651
	} else {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   652
		error(ERR_DOMAIN_INVALID);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   653
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   654
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   655
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   656
function get_supermasters()
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   657
{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   658
        global $db;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   659
        
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   660
	$result = $db->query("SELECT ip, nameserver, account FROM supermasters");
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   661
	if (PEAR::isError($response)) { error($response->getMessage()); return false; }
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   662
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   663
        $ret = array();
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   664
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   665
        if($result->numRows() == 0) {
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   666
                return -1;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   667
        } else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   668
                while ($r = $result->fetchRow()) {
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   669
                        $ret[] = array(
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   670
                        "master_ip"     => $r["ip"],
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   671
                        "ns_name"       => $r["nameserver"],
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   672
                        "account"       => $r["account"],
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   673
                        );
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   674
                }
36
4ec5ab29f634 [feladat @ 83]
rejo
parents: 30
diff changeset
   675
		return $ret;
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   676
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   677
}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   678
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   679
function supermaster_exists($master_ip)
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   680
{
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   681
        global $db;
161
0832d846bf8e [feladat @ 267]
rejo
parents: 160
diff changeset
   682
        if (is_valid_ipv4($master_ip) || is_valid_ipv6($master_ip))
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   683
        {
65
ce1c4d5e1576 [feladat @ 112]
peter
parents: 63
diff changeset
   684
                $result = $db->query("SELECT ip FROM supermasters WHERE ip = ".$db->quote($master_ip));
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   685
                if ($result->numRows() == 0)
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   686
                {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   687
                        return false;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   688
                }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   689
                elseif ($result->numRows() >= 1)
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   690
                {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   691
                        return true;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   692
                }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   693
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   694
        else
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   695
        {
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   696
                error(sprintf(ERR_INV_ARGC, "supermaster_exists", "No or no valid IPv4 or IPv6 address given."));
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   697
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   698
}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
   699
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   700
126
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   701
function get_zones($perm,$userid=0,$letterstart='all',$rowstart=0,$rowamount=999999) 
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   702
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   703
	global $db;
55
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
   704
	global $sql_regexp;
126
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   705
	$sql_add = '';
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   706
	if ($perm != "own" && $perm != "all") {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   707
		error(ERR_PERM_VIEW_ZONE);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   708
		return false;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   709
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   710
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   711
	{
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   712
		if ($perm == "own") {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   713
			$sql_add = " AND zones.domain_id = domains.id
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   714
				AND zones.owner = ".$db->quote($userid);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   715
		}
126
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   716
		if ($letterstart!='all' && $letterstart!=1) {
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   717
			$sql_add .=" AND domains.name LIKE ".$db->quote($letterstart."%")." ";
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   718
		} elseif ($letterstart==1) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   719
			$sql_add .=" AND substring(domains.name,1,1) ".$sql_regexp." '^[[:digit:]]'";
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   720
		}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   721
	}
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   722
	
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   723
	$sqlq = "SELECT domains.id, 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   724
			domains.name,
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   725
			domains.type,
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   726
			COUNT(DISTINCT records.id) AS count_records
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   727
			FROM domains
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   728
			LEFT JOIN zones ON domains.id=zones.domain_id 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   729
			LEFT JOIN records ON records.domain_id=domains.id
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   730
			WHERE 1=1".$sql_add." 
106
41d05ff53708 [feladat @ 206]
peter
parents: 98
diff changeset
   731
			GROUP BY domains.name, domains.id, domains.type
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   732
			ORDER BY domains.name";
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   733
	
74
43c31dc98305 [feladat @ 121]
peter
parents: 71
diff changeset
   734
	$db->setLimit($rowamount, $rowstart);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   735
	$result = $db->query($sqlq);
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   736
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   737
	while($r = $result->fetchRow())
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   738
	{
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   739
		$ret[$r["name"]] = array(
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   740
		"id"		=>	$r["id"],
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   741
		"name"		=>	$r["name"],
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   742
		"type"		=>	$r["type"],
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   743
		"count_records"	=>	$r["count_records"]
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   744
		);	
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   745
	}
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   746
	return $ret;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   747
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   748
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   749
// TODO: letterstart limitation and userid permission limitiation should be applied at the same time?
126
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   750
function zone_count_ng($perm, $letterstart='all') {
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   751
	global $db;
55
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
   752
	global $sql_regexp;
115
b1d7998a903e [feladat @ 218]
peter
parents: 111
diff changeset
   753
b1d7998a903e [feladat @ 218]
peter
parents: 111
diff changeset
   754
	$fromTable = 'domains';
126
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   755
	$sql_add = '';
115
b1d7998a903e [feladat @ 218]
peter
parents: 111
diff changeset
   756
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   757
	if ($perm != "own" && $perm != "all") {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   758
		$zone_count = "0";
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   759
	} 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   760
	else 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   761
	{
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   762
		if ($perm == "own") {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   763
			$sql_add = " AND zones.domain_id = domains.id
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   764
					AND zones.owner = ".$db->quote($_SESSION['userid']);
115
b1d7998a903e [feladat @ 218]
peter
parents: 111
diff changeset
   765
			$fromTable .= ',zones';
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   766
		}
126
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   767
		if ($letterstart!='all' && $letterstart!=1) {
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   768
			$sql_add .=" AND domains.name LIKE ".$db->quote($letterstart."%")." ";
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   769
		} elseif ($letterstart==1) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   770
			$sql_add .=" AND substring(domains.name,1,1) ".$sql_regexp." '^[[:digit:]]'";
37
b785e54690ce [feladat @ 84]
rejo
parents: 36
diff changeset
   771
		}
b785e54690ce [feladat @ 84]
rejo
parents: 36
diff changeset
   772
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   773
		$sqlq = "SELECT COUNT(distinct domains.id) AS count_zones 
115
b1d7998a903e [feladat @ 218]
peter
parents: 111
diff changeset
   774
			FROM ".$fromTable."	WHERE 1=1
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   775
			".$sql_add.";";
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   776
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   777
		$zone_count = $db->queryOne($sqlq);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   778
	}
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   779
	return $zone_count;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   780
}
30
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
   781
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   782
function zone_count_for_uid($uid) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   783
	global $db;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   784
	$query = "SELECT COUNT(domain_id) 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   785
			FROM zones 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   786
			WHERE owner = " . $db->quote($uid) . " 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   787
			ORDER BY domain_id";
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   788
	$zone_count = $db->queryOne($query);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   789
	return $zone_count;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   790
}
30
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
   791
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
   792
380197766e7e [feladat @ 77]
rejo
parents: 21
diff changeset
   793
/*
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   794
 * Get a record from an id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   795
 * Retrieve all fields of the record and send it back to the function caller.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   796
 * return values: the array with information, or -1 is nothing is found.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   797
 */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   798
function get_record_from_id($id)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   799
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   800
	global $db;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   801
	if (is_numeric($id))
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   802
	{
65
ce1c4d5e1576 [feladat @ 112]
peter
parents: 63
diff changeset
   803
		$result = $db->query("SELECT id, domain_id, name, type, content, ttl, prio, change_date FROM records WHERE id=".$db->quote($id));
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   804
		if($result->numRows() == 0)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   805
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   806
			return -1;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   807
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   808
		elseif ($result->numRows() == 1)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   809
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   810
			$r = $result->fetchRow();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   811
			$ret = array(
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   812
				"id"            =>      $r["id"],
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   813
				"domain_id"     =>      $r["domain_id"],
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   814
				"name"          =>      $r["name"],
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   815
				"type"          =>      $r["type"],
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   816
				"content"       =>      $r["content"],
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   817
				"ttl"           =>      $r["ttl"],
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   818
				"prio"          =>      $r["prio"],
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   819
				"change_date"   =>      $r["change_date"]
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   820
				);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   821
			return $ret;
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   822
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   823
		else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   824
		{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   825
			error(sprintf(ERR_INV_ARGC, "get_record_from_id", "More than one row returned! This is bad!"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   826
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   827
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   828
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   829
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   830
		error(sprintf(ERR_INV_ARG, "get_record_from_id"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   831
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   832
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   833
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   834
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   835
/*
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   836
 * Get all records from a domain id.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   837
 * Retrieve all fields of the records and send it back to the function caller.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   838
 * return values: the array with information, or -1 is nothing is found.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   839
 */
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   840
function get_records_from_domain_id($id,$rowstart=0,$rowamount=999999) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   841
	global $db;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   842
	if (is_numeric($id)) {
126
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   843
		if ((isset($_SESSION[$id."_ispartial"])) && ($_SESSION[$id."_ispartial"] == 1)) {
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   844
			$db->setLimit($rowamount, $rowstart);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   845
			$result = $db->query("SELECT record_owners.record_id as id
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   846
					FROM record_owners,domains,records
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   847
					WHERE record_owners.user_id = " . $db->quote($_SESSION["userid"]) . "
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   848
					AND record_owners.record_id = records.id
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   849
					AND records.domain_id = " . $db->quote($id) . "
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   850
					GROUP BY record_owners.record_id");
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   851
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   852
			$ret = array();
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   853
			if($result->numRows() == 0) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   854
				return -1;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   855
			} else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   856
				$ret[] = array();
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   857
				$retcount = 0;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   858
				while($r = $result->fetchRow())
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   859
				{
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   860
					// Call get_record_from_id for each row.
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   861
					$ret[$retcount] = get_record_from_id($r["id"]);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   862
					$retcount++;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   863
				}
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   864
				return $ret;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   865
			}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   866
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   867
		} else {
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   868
			$db->setLimit($rowamount, $rowstart);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   869
			$result = $db->query("SELECT id FROM records WHERE domain_id=".$db->quote($id));
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   870
			$ret = array();
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   871
			if($result->numRows() == 0)
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   872
			{
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   873
				return -1;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   874
			}
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   875
			else
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   876
			{
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   877
				$ret[] = array();
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   878
				$retcount = 0;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   879
				while($r = $result->fetchRow())
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   880
				{
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   881
					// Call get_record_from_id for each row.
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   882
					$ret[$retcount] = get_record_from_id($r["id"]);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   883
					$retcount++;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   884
				}
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   885
				return $ret;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   886
			}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   887
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   888
		}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   889
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   890
	else
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   891
	{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   892
		error(sprintf(ERR_INV_ARG, "get_records_from_domain_id"));
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   893
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   894
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   895
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   896
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   897
function get_users_from_domain_id($id) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   898
	global $db;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   899
	$sqlq = "SELECT owner FROM zones WHERE domain_id =" .$db->quote($id);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   900
	$id_owners = $db->query($sqlq);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   901
	if ($id_owners->numRows() == 0) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   902
		return -1;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   903
	} else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   904
		while ($r = $id_owners->fetchRow()) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   905
			$fullname = $db->queryOne("SELECT fullname FROM users WHERE id=".$r['owner']);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   906
			$owners[] = array(
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   907
				"id" 		=> 	$r['owner'],
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   908
				"fullname"	=>	$fullname		
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   909
			);		
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   910
		}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   911
	}
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   912
	return $owners;	
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   913
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   914
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   915
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   916
function search_zone_and_record($holy_grail,$perm) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   917
	
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   918
	global $db;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   919
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   920
	$holy_grail = trim($holy_grail);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   921
126
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   922
	$sql_add_from = '';
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   923
	$sql_add_where = '';
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   924
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   925
	$return_zones = array();
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   926
	$return_records = array();
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   927
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   928
	if (verify_permission('zone_content_view_others')) { $perm_view = "all" ; }
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   929
	elseif (verify_permission('zone_content_view_own')) { $perm_view = "own" ; }
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   930
	else { $perm_view = "none" ; }
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   931
126
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   932
	if (verify_permission('zone_content_edit_others')) { $perm_content_edit = "all" ; }
cb06e3e29ed8 [feladat @ 230]
peter
parents: 120
diff changeset
   933
	elseif (verify_permission('zone_content_edit_own')) { $perm_content_edit = "own" ; }
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   934
	else { $perm_content_edit = "none" ; }
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   935
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   936
	// Search for matching domains
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   937
	if ($perm == "own") {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   938
		$sql_add_from = ", zones ";
169
41353c2e0c9f [feladat @ 276]
peter
parents: 161
diff changeset
   939
		$sql_add_where = " AND zones.domain_id = domains.id AND zones.owner = " . $db->quote($_SESSION['userid']);
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   940
	}
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   941
	
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   942
	$query = "SELECT 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   943
			domains.id AS zid,
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   944
			domains.name AS name,
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   945
			domains.type AS type,
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   946
			domains.master AS master
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   947
			FROM domains" . $sql_add_from . "
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   948
			WHERE domains.name LIKE " . $db->quote($holy_grail)
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   949
			. $sql_add_where ;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   950
	
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   951
	$response = $db->query($query);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   952
	if (PEAR::isError($response)) { error($response->getMessage()); return false; }
62
ce4919f37489 [feladat @ 109]
rejo
parents: 60
diff changeset
   953
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   954
	while ($r = $response->fetchRow()) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   955
		$return_zones[] = array(
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   956
			"zid"		=>	$r['zid'],
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   957
			"name"		=>	$r['name'],
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   958
			"type"		=>	$r['type'],
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   959
			"master"	=>	$r['master']);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   960
	}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   961
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   962
	// Search for matching records
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   963
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   964
	if ($perm == "own") {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   965
		$sql_add_from = ", zones ";
169
41353c2e0c9f [feladat @ 276]
peter
parents: 161
diff changeset
   966
		$sql_add_where = " AND zones.domain_id = record.id AND zones.owner = " . $db->quote($_SESSION['userid']);
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   967
	}
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   968
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   969
	$query = "SELECT
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   970
			records.id AS rid,
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   971
			records.name AS name,
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   972
			records.type AS type,
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   973
			records.content AS content,
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   974
			records.ttl AS ttl,
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   975
			records.prio AS prio,
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   976
			records.domain_id AS zid
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   977
			FROM records" . $sql_add_from . "
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   978
			WHERE (records.name LIKE " . $db->quote($holy_grail) . " OR records.content LIKE " . $db->quote($holy_grail) . ")"
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   979
			. $sql_add_where ;
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   980
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   981
	$response = $db->query($query);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   982
	if (PEAR::isError($response)) { error($response->getMessage()); return false; }
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   983
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   984
	while ($r = $response->fetchRow()) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   985
		$return_records[] = array(
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   986
			"rid"		=>	$r['rid'],
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   987
			"name"		=>	$r['name'],
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   988
			"type"		=>	$r['type'],
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   989
			"content"	=>	$r['content'],
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   990
			"ttl"		=>	$r['ttl'],
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   991
			"zid"		=>	$r['zid'],
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   992
			"prio"		=>	$r['prio']);
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   993
	}
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   994
	return array('zones' => $return_zones, 'records' => $return_records);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   995
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   996
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   997
function get_domain_type($id) {
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   998
	global $db;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
   999
        if (is_numeric($id)) {
65
ce1c4d5e1576 [feladat @ 112]
peter
parents: 63
diff changeset
  1000
		$type = $db->queryOne("SELECT type FROM domains WHERE id = ".$db->quote($id));
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1001
		if ($type == "") {
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1002
			$type = "NATIVE";
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1003
		}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1004
		return $type;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1005
        } else {
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1006
                error(sprintf(ERR_INV_ARG, "get_record_from_id", "no or no valid zoneid given"));
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1007
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1008
}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1009
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1010
function get_domain_slave_master($id){
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1011
	global $db;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1012
        if (is_numeric($id)) {
65
ce1c4d5e1576 [feladat @ 112]
peter
parents: 63
diff changeset
  1013
		$slave_master = $db->queryOne("SELECT master FROM domains WHERE type = 'SLAVE' and id = ".$db->quote($id));
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1014
		return $slave_master;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1015
        } else {
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1016
                error(sprintf(ERR_INV_ARG, "get_domain_slave_master", "no or no valid zoneid given"));
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1017
        }
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1018
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1019
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1020
function change_zone_type($type, $id)
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1021
{
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1022
	global $db;
79
0c0aa144356a [feladat @ 156]
peter
parents: 78
diff changeset
  1023
	$add = '';
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1024
        if (is_numeric($id))
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1025
	{
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1026
		// It is not really neccesary to clear the field that contains the IP address 
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1027
		// of the master if the type changes from slave to something else. PowerDNS will
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1028
		// ignore the field if the type isn't something else then slave. But then again,
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1029
		// it's much clearer this way.
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1030
		if ($type != "SLAVE") {
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1031
			$add = ", master=''";
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1032
		}
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1033
		$result = $db->query("UPDATE domains SET type = " . $db->quote($type) . $add . " WHERE id = ".$db->quote($id));
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1034
	} else {
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1035
                error(sprintf(ERR_INV_ARG, "change_domain_type", "no or no valid zoneid given"));
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1036
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1037
}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1038
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1039
function change_zone_slave_master($zone_id, $ip_slave_master) {
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1040
	global $db;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1041
        if (is_numeric($zone_id)) {
161
0832d846bf8e [feladat @ 267]
rejo
parents: 160
diff changeset
  1042
       		if (is_valid_ipv4($ip_slave_master) || is_valid_ipv6($ip_slave_master)) {
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1043
			$result = $db->query("UPDATE domains SET master = " .$db->quote($ip_slave_master). " WHERE id = ".$db->quote($zone_id));
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1044
		} else {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1045
			error(sprintf(ERR_INV_ARGC, "change_domain_ip_slave_master", "This is not a valid IPv4 or IPv6 address: $ip_slave_master"));
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1046
		}
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1047
	} else {
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1048
                error(sprintf(ERR_INV_ARG, "change_domain_type", "no or no valid zoneid given"));
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1049
        }
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1050
}
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1051
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1052
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1053
function validate_account($account) {
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1054
  	if(preg_match("/^[A-Z0-9._-]+$/i",$account)) {
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1055
		return true;
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1056
	} else {
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1057
		return false;
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
  1058
	}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1059
}
82
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1060
c255196bc447 [feladat @ 182]
rejo
parents: 81
diff changeset
  1061
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
  1062
?>