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