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