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