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