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