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