1
+ − 1
<?
+ − 2
+ − 3
+ − 4
// Filename: record.inc.php
+ − 5
// Startdate: 26-10-2002
+ − 6
// This file is ought to edit the records in the database.
+ − 7
// Records are domains aswell, they also belong here.
+ − 8
// All database functions are associative.
+ − 9
// use nextID first to get a new id. Then insert it into the database.
+ − 10
// do not rely on auto_increment (see above).
+ − 11
// use dns.inc.php for validation functions.
+ − 12
//
+ − 13
// $Id: record.inc.php,v 1.21 2003/05/10 20:21:01 azurazu Exp $
+ − 14
//
+ − 15
+ − 16
+ − 17
function update_soa_serial ( $domain_id )
+ − 18
{
+ − 19
global $db ;
+ − 20
/*
+ − 21
* THIS CODE ISNT TESTED THROUGH MUCH YET!
+ − 22
* !!!!!!! BETACODE !!!!!!!!!!
+ − 23
* Code committed by DeViCeD, Thanks a lot!
+ − 24
* Heavily hax0red by Trancer/azurazu
+ − 25
*
+ − 26
* First we have to check, wheather current searial number
+ − 27
* was already updated on the other nameservers.
+ − 28
* If field 'notified_serial' is NULL, then I guess domain is
+ − 29
* NATIVE and we don't have any secondary nameservers for this domain.
+ − 30
* NOTICE: Serial number *will* be RFC1912 compilant after update
+ − 31
* NOTICE: This function will allow only 100 DNS zone transfers ;-)
+ − 32
* YYYYMMDDnn
+ − 33
*/
+ − 34
+ − 35
$sqlq = "SELECT `notified_serial` FROM `domains` WHERE `id` = '" . $domain_id . "'" ;
8
+ − 36
$notified_serial = $db -> queryOne ( $sqlq );
1
+ − 37
+ − 38
$sqlq = "SELECT `content` FROM `records` WHERE `type` = 'SOA' AND `domain_id` = '" . $domain_id . "'" ;
8
+ − 39
$content = $db -> queryOne ( $sqlq );
1
+ − 40
$need_to_update = false ;
+ − 41
+ − 42
// Getting the serial field.
+ − 43
$soa = explode ( " " , $content );
+ − 44
+ − 45
if ( empty ( $notified_serial ))
+ − 46
{
+ − 47
// Ok native replication, so we have to update.
+ − 48
$need_to_update = true ;
+ − 49
}
+ − 50
elseif ( $notified_serial >= $soa [ 2 ])
+ − 51
{
+ − 52
$need_to_update = true ;
+ − 53
}
+ − 54
elseif ( strlen ( $soa [ 2 ]) != 10 )
+ − 55
{
+ − 56
$need_to_update = true ;
+ − 57
}
+ − 58
else
+ − 59
{
+ − 60
$need_to_update = false ;
+ − 61
}
+ − 62
if ( $need_to_update )
+ − 63
{
+ − 64
// Ok so we have to update it seems.
+ − 65
$current_serial = $soa [ 2 ];
+ − 66
+ − 67
/*
+ − 68
* What we need here (for RFC1912) is YEAR, MONTH and DAY
+ − 69
* so let's get it ...
+ − 70
*/
+ − 71
$new_serial = date ( 'Ymd' ); // we will add revision number later
+ − 72
+ − 73
if ( strncmp ( $new_serial , $current_serial , 8 ) === 0 )
+ − 74
{
+ − 75
/*
+ − 76
* Ok, so we already made updates tonight
+ − 77
* let's just increase the revision number
+ − 78
*/
+ − 79
$revision_number = ( int ) substr ( $current_serial , - 2 );
+ − 80
if ( $revision_number == 99 ) return false ; // ok, we cannot update anymore tonight
+ − 81
++ $revision_number ;
+ − 82
// here it is ... same date, new revision
+ − 83
$new_serial .= str_pad ( $revision_number , 2 , "0" , STR_PAD_LEFT );
+ − 84
}
+ − 85
else
+ − 86
{
+ − 87
/*
+ − 88
* Current serial is not RFC1912 compilant, so let's make a new one
+ − 89
*/
+ − 90
$new_serial .= '00' ;
+ − 91
}
+ − 92
$soa [ 2 ] = $new_serial ; // change serial in SOA array
+ − 93
$new_soa = "" ;
+ − 94
// build new soa and update SQL after that
+ − 95
for ( $i = 0 ; $i < count ( $soa ); $i ++ )
+ − 96
{
+ − 97
$new_soa .= $soa [ $i ] . " " ;
+ − 98
}
+ − 99
$sqlq = "UPDATE `records` SET `content` = '" . $new_soa . "' WHERE `domain_id` = '" . $domain_id . "' AND `type` = 'SOA' LIMIT 1" ;
+ − 100
$db -> Query ( $sqlq );
+ − 101
return true ;
+ − 102
}
+ − 103
}
+ − 104
+ − 105
/*
+ − 106
* Edit a record.
+ − 107
* This function validates it if correct it inserts it into the database.
+ − 108
* return values: true if succesful.
+ − 109
*/
+ − 110
function edit_record ( $recordid , $zoneid , $name , $type , $content , $ttl , $prio )
+ − 111
{
+ − 112
global $db ;
+ − 113
if ( $content == "" )
+ − 114
{
+ − 115
error ( ERR_RECORD_EMPTY_CONTENT );
+ − 116
}
+ − 117
// Edits the given record (validates specific stuff first)
+ − 118
if ( ! xs ( recid_to_domid ( $recordid )))
+ − 119
{
+ − 120
error ( ERR_RECORD_ACCESS_DENIED );
+ − 121
}
+ − 122
if ( is_numeric ( $zoneid ))
+ − 123
{
19
+ − 124
validate_input ( $zoneid , $type , $content , $name , $prio , $ttl );
1
+ − 125
$change = time ();
+ − 126
$db -> query ( "UPDATE records set name=' $name ', type=' $type ', content=' $content ', ttl=' $ttl ', prio=' $prio ', change_date=' $change ' WHERE id= $recordid " );
+ − 127
+ − 128
/*
+ − 129
* Added by DeViCeD - Update SOA Serial number
+ − 130
* There should be more checks
+ − 131
*/
+ − 132
if ( $type != 'SOA' )
+ − 133
{
+ − 134
update_soa_serial ( $zoneid );
+ − 135
}
+ − 136
return true ;
+ − 137
}
+ − 138
else
+ − 139
{
+ − 140
error ( sprintf ( ERR_INV_ARGC , "edit_record" , "no zoneid given" ));
+ − 141
}
+ − 142
+ − 143
}
+ − 144
+ − 145
+ − 146
/*
+ − 147
* Adds a record.
+ − 148
* This function validates it if correct it inserts it into the database.
+ − 149
* return values: true if succesful.
+ − 150
*/
+ − 151
function add_record ( $zoneid , $name , $type , $content , $ttl , $prio )
+ − 152
{
+ − 153
+ − 154
global $db ;
+ − 155
if ( ! xs ( $zoneid ))
+ − 156
{
+ − 157
error ( ERR_RECORD_ACCESS_DENIED );
+ − 158
}
+ − 159
if ( is_numeric ( $zoneid ))
+ − 160
{
8
+ − 161
// Check the user input.
+ − 162
validate_input ( $zoneid , $type , $content , $name , $prio , $ttl );
1
+ − 163
8
+ − 164
// Generate new timestamp for the daemon
1
+ − 165
$change = time ();
8
+ − 166
1
+ − 167
// Execute query.
8
+ − 168
$db -> query ( "INSERT INTO records (domain_id, name, type, content, ttl, prio, change_date) VALUES ( $zoneid , ' $name ', ' $type ', ' $content ', $ttl , ' $prio ', $change )" );
1
+ − 169
if ( $type != 'SOA' )
+ − 170
{
+ − 171
update_soa_serial ( $zoneid );
+ − 172
}
+ − 173
return true ;
+ − 174
}
+ − 175
else
+ − 176
{
+ − 177
error ( sprintf ( ERR_INV_ARG , "add_record" ));
+ − 178
}
+ − 179
}
+ − 180
+ − 181
13
+ − 182
function add_supermaster ( $master_ip , $ns_name , $account )
+ − 183
{
+ − 184
global $db ;
+ − 185
if ( ! is_valid_ip ( $master_ip ) && ! is_valid_ip6 ( $master_ip ))
+ − 186
{
+ − 187
error ( sprintf ( ERR_INV_ARGC , "add_supermaster" , "No or no valid ipv4 or ipv6 address given." ));
+ − 188
}
+ − 189
if ( ! is_valid_hostname ( $ns_name ))
+ − 190
{
+ − 191
error ( ERR_DNS_HOSTNAME );
+ − 192
}
+ − 193
if ( ! validate_account ( $account ))
+ − 194
{
+ − 195
error ( sprintf ( ERR_INV_ARGC , "add_supermaster" , "given account name is invalid (alpha chars only)" ));
+ − 196
}
+ − 197
if ( supermaster_exists ( $master_ip ))
+ − 198
{
+ − 199
error ( sprintf ( ERR_INV_ARGC , "add_supermaster" , "supermaster already exists" ));
+ − 200
}
+ − 201
else
+ − 202
{
+ − 203
$db -> query ( "INSERT INTO supermasters VALUES (' $master_ip ', ' $ns_name ', ' $account ')" );
+ − 204
return true ;
+ − 205
}
+ − 206
}
+ − 207
+ − 208
function delete_supermaster ( $master_ip )
+ − 209
{
+ − 210
global $db ;
+ − 211
if ( ! level ( 5 ))
+ − 212
{
+ − 213
error ( ERR_LEVEL_5 );
+ − 214
}
+ − 215
if ( is_valid_ip ( $master_ip ) || is_valid_ip6 ( $master_ip ))
+ − 216
{
+ − 217
$db -> query ( "DELETE FROM supermasters WHERE ip = ' $master_ip '" );
+ − 218
return true ;
+ − 219
}
+ − 220
else
+ − 221
{
+ − 222
error ( sprintf ( ERR_INV_ARGC , "delete_supermaster" , "No or no valid ipv4 or ipv6 address given." ));
+ − 223
}
+ − 224
}
+ − 225
+ − 226
function get_supermaster_info_from_ip ( $master_ip )
+ − 227
{
+ − 228
global $db ;
+ − 229
if ( ! level ( 5 ))
+ − 230
{
+ − 231
error ( ERR_LEVEL_5 );
+ − 232
}
+ − 233
if ( is_valid_ip ( $master_ip ) || is_valid_ip6 ( $master_ip ))
+ − 234
{
+ − 235
$result = $db -> queryRow ( "SELECT ip,nameserver,account FROM supermasters WHERE ip = ' $master_ip '" );
+ − 236
+ − 237
$ret = array (
+ − 238
"master_ip" => $result [ "ip" ],
+ − 239
"ns_name" => $result [ "nameserver" ],
+ − 240
"account" => $result [ "account" ]
+ − 241
);
+ − 242
+ − 243
return $ret ;
+ − 244
}
+ − 245
else
+ − 246
{
+ − 247
error ( sprintf ( ERR_INV_ARGC , "get_supermaster_info_from_ip" , "No or no valid ipv4 or ipv6 address given." ));
+ − 248
}
+ − 249
}
+ − 250
+ − 251
1
+ − 252
/*
+ − 253
* Delete a record by a given id.
+ − 254
* return values: true, this function is always succesful.
+ − 255
*/
+ − 256
function delete_record ( $id )
+ − 257
{
+ − 258
global $db ;
+ − 259
+ − 260
// Check if the user has access.
+ − 261
if ( ! xs ( recid_to_domid ( $id )))
+ − 262
{
+ − 263
error ( ERR_RECORD_ACCESS_DENIED );
+ − 264
}
+ − 265
+ − 266
// Retrieve the type of record to see if we can actually remove it.
+ − 267
$recordtype = get_recordtype_from_id ( $id );
+ − 268
+ − 269
// If the record type is NS and the user tries to delete it while ALLOW_NS_EDIT is set to 0
+ − 270
// OR
+ − 271
// check if the name of the record isnt the domain name (if so it should delete all records)
+ − 272
// OR
+ − 273
// check if we are dealing with a SOA field (same story as NS)
+ − 274
if (( $recordtype == "NS" && $GLOBALS [ "ALLOW_NS_EDIT" ] != 1 && ( get_name_from_record_id ( $id ) == get_domain_name_from_id ( recid_to_domid ( $id )))) || ( $recordtype == "SOA" && $GLOBALS [ "ALLOW_SOA_EDIT" ] != 1 ))
+ − 275
{
+ − 276
error ( sprintf ( ERR_RECORD_DELETE_TYPE_DENIED , $recordtype ));
+ − 277
+ − 278
}
+ − 279
if ( is_numeric ( $id ))
+ − 280
{
+ − 281
$did = recid_to_domid ( $id );
+ − 282
$db -> query ( 'DELETE FROM records WHERE id=' . $id . ' LIMIT 1' );
+ − 283
if ( $type != 'SOA' )
+ − 284
{
+ − 285
update_soa_serial ( $did );
+ − 286
}
+ − 287
// $id doesnt exist in database anymore so its deleted or just not there which means "true"
+ − 288
return true ;
+ − 289
}
+ − 290
else
+ − 291
{
+ − 292
error ( sprintf ( ERR_INV_ARG , "delete_record" ));
+ − 293
}
+ − 294
}
+ − 295
+ − 296
+ − 297
/*
+ − 298
* Add a domain to the database.
+ − 299
* A domain is name obligatory, so is an owner.
+ − 300
* return values: true when succesful.
+ − 301
* Empty means templates dont have to be applied.
+ − 302
* --------------------------------------------------------------------------
+ − 303
* This functions eats a template and by that it inserts various records.
+ − 304
* first we start checking if something in an arpa record
+ − 305
* remember to request nextID's from the database to be able to insert record.
+ − 306
* if anything is invalid the function will error
+ − 307
*/
13
+ − 308
function add_domain ( $domain , $owner , $webip , $mailip , $empty , $type , $slave_master )
1
+ − 309
{
+ − 310
+ − 311
global $db ;
+ − 312
+ − 313
if ( ! level ( 5 ))
+ − 314
{
+ − 315
error ( ERR_LEVEL_5 );
+ − 316
}
+ − 317
+ − 318
// If domain, owner and mailip are given
+ − 319
// OR
+ − 320
// empty is given and owner and domain
+ − 321
// OR
+ − 322
// the domain is an arpa record and owner is given
13
+ − 323
// OR
+ − 324
// the type is slave, domain, owner and slave_master are given
1
+ − 325
// THAN
+ − 326
// Continue this function
13
+ − 327
if (( $domain && $owner && $webip && $mailip ) || ( $empty && $owner && $domain ) || ( eregi ( 'in-addr.arpa' , $domain ) && $owner ) || $type == "SLAVE" && $domain && $owner && $slave_master )
1
+ − 328
{
8
+ − 329
// First insert zone into domain table
+ − 330
$db -> query ( "INSERT INTO domains (name, type) VALUES (' $domain ', ' $type ')" );
1
+ − 331
8
+ − 332
// Determine id of insert zone (in other words, find domain_id)
+ − 333
$iddomain = $db -> lastInsertId ( 'domains' , 'id' );
+ − 334
if ( PEAR :: isError ( $iddomain )) {
+ − 335
die ( $id -> getMessage ());
+ − 336
}
1
+ − 337
8
+ − 338
// Second, insert into zones tables
+ − 339
$db -> query ( "INSERT INTO zones (domain_id, owner) VALUES (' $iddomain ', $owner )" );
1
+ − 340
13
+ − 341
if ( $type == "SLAVE" )
1
+ − 342
{
13
+ − 343
$db -> query ( "UPDATE domains SET master = ' $slave_master ' WHERE id = ' $iddomain ';" );
+ − 344
+ − 345
// Done
+ − 346
return true ;
+ − 347
}
+ − 348
else
+ − 349
{
+ − 350
// Generate new timestamp. We need this one anyhow.
+ − 351
$now = time ();
1
+ − 352
13
+ − 353
if ( $empty && $iddomain )
+ − 354
{
+ − 355
// If we come into this if statement we dont want to apply templates.
+ − 356
// Retrieve configuration settings.
+ − 357
$ns1 = $GLOBALS [ "NS1" ];
+ − 358
$hm = $GLOBALS [ "HOSTMASTER" ];
+ − 359
$ttl = $GLOBALS [ "DEFAULT_TTL" ];
1
+ − 360
13
+ − 361
// Build and execute query
+ − 362
$sql = "INSERT INTO records (domain_id, name, content, type, ttl, prio, change_date) VALUES (' $iddomain ', ' $domain ', ' $ns1 $hm 1', 'SOA', $ttl , '', ' $now ')" ;
+ − 363
$db -> query ( $sql );
1
+ − 364
13
+ − 365
// Done
+ − 366
return true ;
+ − 367
}
+ − 368
elseif ( $iddomain )
1
+ − 369
{
13
+ − 370
// If we are here we want to apply templates.
+ − 371
global $template ;
+ − 372
+ − 373
// Iterate over the template and apply it for each field.
+ − 374
foreach ( $template as $r )
1
+ − 375
{
13
+ − 376
// Same type of if statement as previous.
+ − 377
if (( eregi ( 'in-addr.arpa' , $domain ) && ( $r [ "type" ] == "NS" || $r [ "type" ] == "SOA" )) || ( ! eregi ( 'in-addr.arpa' , $domain )))
1
+ − 378
{
13
+ − 379
// Parse the template.
+ − 380
$name = parse_template_value ( $r [ "name" ], $domain , $webip , $mailip );
+ − 381
$type = $r [ "type" ];
+ − 382
$content = parse_template_value ( $r [ "content" ], $domain , $webip , $mailip );
+ − 383
$ttl = $r [ "ttl" ];
+ − 384
$prio = $r [ "prio" ];
1
+ − 385
13
+ − 386
// If no ttl is given, use the default.
+ − 387
if ( ! $ttl )
+ − 388
{
+ − 389
$ttl = $GLOBALS [ "DEFAULT_TTL" ];
+ − 390
}
+ − 391
+ − 392
$sql = "INSERT INTO records (domain_id, name, content, type, ttl, prio, change_date) VALUES (' $iddomain ', ' $name ',' $content ',' $type ',' $ttl ',' $prio ',' $now ')" ;
+ − 393
$db -> query ( $sql );
+ − 394
}
1
+ − 395
}
13
+ − 396
// All done.
+ − 397
return true ;
+ − 398
}
+ − 399
else
+ − 400
{
+ − 401
error ( sprintf ( ERR_INV_ARGC , "add_domain" , "could not create zone" ));
+ − 402
}
+ − 403
}
1
+ − 404
}
+ − 405
else
+ − 406
{
+ − 407
error ( sprintf ( ERR_INV_ARG , "add_domain" ));
+ − 408
}
+ − 409
}
+ − 410
+ − 411
+ − 412
/*
+ − 413
* Deletes a domain by a given id.
+ − 414
* Function always succeeds. If the field is not found in the database, thats what we want anyway.
+ − 415
*/
+ − 416
function delete_domain ( $id )
+ − 417
{
+ − 418
global $db ;
+ − 419
+ − 420
if ( ! level ( 5 ))
+ − 421
{
+ − 422
error ( ERR_LEVEL_5 );
+ − 423
}
+ − 424
+ − 425
// See if the ID is numeric.
+ − 426
if ( is_numeric ( $id ))
+ − 427
{
+ − 428
$db -> query ( "DELETE FROM zones WHERE domain_id= $id " );
+ − 429
$db -> query ( "DELETE FROM domains WHERE id= $id " );
+ − 430
$db -> query ( "DELETE FROM records WHERE domain_id= $id " );
+ − 431
// Nothing in the database. If the delete deleted 0 records it means the id is just not there.
+ − 432
// therefore the is no need to check the affectedRows values.
+ − 433
return true ;
+ − 434
}
+ − 435
else
+ − 436
{
+ − 437
error ( sprintf ( ERR_INV_ARGC , "delete_domain" , "id must be a number" ));
+ − 438
}
+ − 439
}
+ − 440
+ − 441
+ − 442
/*
+ − 443
* Gets the id of the domain by a given record id.
+ − 444
* return values: the domain id that was requested.
+ − 445
*/
+ − 446
function recid_to_domid ( $id )
+ − 447
{
+ − 448
global $db ;
+ − 449
if ( is_numeric ( $id ))
+ − 450
{
+ − 451
$result = $db -> query ( "SELECT domain_id FROM records WHERE id= $id " );
+ − 452
$r = $result -> fetchRow ();
+ − 453
return $r [ "domain_id" ];
+ − 454
}
+ − 455
else
+ − 456
{
+ − 457
error ( sprintf ( ERR_INV_ARGC , "recid_to_domid" , "id must be a number" ));
+ − 458
}
+ − 459
}
+ − 460
+ − 461
+ − 462
/*
+ − 463
* Sorts a zone by records.
+ − 464
* return values: the sorted zone.
+ − 465
*/
+ − 466
function sort_zone ( $records )
+ − 467
{
+ − 468
$ar_so = array ();
+ − 469
$ar_ns = array ();
+ − 470
$ar_mx = array ();
+ − 471
$ar_mb = array ();
+ − 472
$ar_ur = array ();
+ − 473
$ar_ov = array ();
+ − 474
foreach ( $records as $c )
+ − 475
{
+ − 476
switch ( strtoupper ( $c [ 'type' ]))
+ − 477
{
+ − 478
case "SOA" :
+ − 479
$ar_so [] = $c ;
+ − 480
break ;
+ − 481
case "NS" :
+ − 482
$ar_ns [] = $c ;
+ − 483
break ;
+ − 484
case "MX" :
+ − 485
$ar_mx [] = $c ;
+ − 486
break ;
+ − 487
case "MBOXFW" :
+ − 488
$ar_mb [] = $c ;
+ − 489
break ;
+ − 490
case "URL" :
+ − 491
$ar_ur [] = $c ;
+ − 492
break ;
+ − 493
default :
+ − 494
$ar_ov [] = $c ;
+ − 495
break ;
+ − 496
}
+ − 497
}
+ − 498
+ − 499
$res = array_merge ( $ar_so , $ar_ns , $ar_mx , $ar_mb , $ar_ur , $ar_ov );
+ − 500
+ − 501
if ( count ( $records ) == count ( $res ))
+ − 502
{
+ − 503
$records = $res ;
+ − 504
}
+ − 505
else
+ − 506
{
+ − 507
error ( sprintf ( ERR_INV_ARGC , "sort_zone" , "records sorting failed!" ));
+ − 508
}
+ − 509
return $records ;
+ − 510
}
+ − 511
+ − 512
+ − 513
/*
+ − 514
* Change owner of a domain.
+ − 515
* Function should actually be in users.inc.php. But its more of a record modification than a user modification
+ − 516
* return values: true when succesful.
+ − 517
*/
+ − 518
function add_owner ( $domain , $newowner )
+ − 519
{
+ − 520
global $db ;
+ − 521
+ − 522
if ( ! level ( 5 ))
+ − 523
{
+ − 524
error ( ERR_LEVEL_5 );
+ − 525
}
+ − 526
+ − 527
if ( is_numeric ( $domain ) && is_numeric ( $newowner ) && is_valid_user ( $newowner ))
+ − 528
{
8
+ − 529
if ( $db -> queryOne ( "SELECT COUNT(id) FROM zones WHERE owner= $newowner AND domain_id= $domain " ) == 0 )
1
+ − 530
{
8
+ − 531
$db -> query ( "INSERT INTO zones (domain_id, owner) VALUES( $domain , $newowner )" );
1
+ − 532
}
+ − 533
return true ;
+ − 534
}
+ − 535
else
+ − 536
{
+ − 537
error ( sprintf ( ERR_INV_ARGC , "change_owner" , " $domain / $newowner " ));
+ − 538
}
+ − 539
}
+ − 540
+ − 541
+ − 542
function delete_owner ( $domain , $owner )
+ − 543
{
+ − 544
global $db ;
8
+ − 545
if ( $db -> queryOne ( "SELECT COUNT(id) FROM zones WHERE owner= $owner AND domain_id= $domain " ) != 0 )
1
+ − 546
{
+ − 547
$db -> query ( "DELETE FROM zones WHERE owner= $owner AND domain_id= $domain " );
+ − 548
}
+ − 549
return true ;
+ − 550
}
+ − 551
+ − 552
/*
+ − 553
* Retrieves all supported dns record types
+ − 554
* This function might be deprecated.
+ − 555
* return values: array of types in string form.
+ − 556
*/
+ − 557
function get_record_types ()
+ − 558
{
+ − 559
global $rtypes ;
+ − 560
return $rtypes ;
+ − 561
}
+ − 562
+ − 563
+ − 564
/*
+ − 565
* Retrieve all records by a given type and domain id.
+ − 566
* Example: get all records that are of type A from domain id 1
+ − 567
* return values: a DB class result object
+ − 568
*/
+ − 569
function get_records_by_type_from_domid ( $type , $recid )
+ − 570
{
+ − 571
global $rtypes ;
+ − 572
global $db ;
+ − 573
+ − 574
// Does this type exist?
+ − 575
if ( ! in_array ( strtoupper ( $type ), $rtypes ))
+ − 576
{
+ − 577
error ( sprintf ( ERR_INV_ARGC , "get_records_from_type" , "this is not a supported record" ));
+ − 578
}
+ − 579
+ − 580
// Get the domain id.
+ − 581
$domid = recid_to_domid ( $recid );
+ − 582
+ − 583
$result = $db -> query ( "select id, type from records where domain_id= $recid and type=' $type '" );
+ − 584
return $result ;
+ − 585
}
+ − 586
+ − 587
+ − 588
/*
+ − 589
* Retrieves the type of a record from a given id.
+ − 590
* return values: the type of the record (one of the records types in $rtypes assumable).
+ − 591
*/
+ − 592
function get_recordtype_from_id ( $id )
+ − 593
{
+ − 594
global $db ;
+ − 595
if ( is_numeric ( $id ))
+ − 596
{
+ − 597
$result = $db -> query ( "SELECT type FROM records WHERE id= $id " );
+ − 598
$r = $result -> fetchRow ();
+ − 599
return $r [ "type" ];
+ − 600
}
+ − 601
else
+ − 602
{
+ − 603
error ( sprintf ( ERR_INV_ARG , "get_recordtype_from_id" ));
+ − 604
}
+ − 605
}
+ − 606
+ − 607
+ − 608
/*
+ − 609
* Retrieves the name (e.g. bla.test.com) of a record by a given id.
+ − 610
* return values: the name associated with the id.
+ − 611
*/
+ − 612
function get_name_from_record_id ( $id )
+ − 613
{
+ − 614
global $db ;
+ − 615
if ( is_numeric ( $id ))
+ − 616
{
+ − 617
$result = $db -> query ( "SELECT name FROM records WHERE id= $id " );
+ − 618
$r = $result -> fetchRow ();
+ − 619
return $r [ "name" ];
+ − 620
}
+ − 621
else
+ − 622
{
+ − 623
error ( sprintf ( ERR_INV_ARG , "get_name_from_record_id" ));
+ − 624
}
+ − 625
}
+ − 626
+ − 627
+ − 628
/*
+ − 629
* Get all the domains from a database of which the user is the owner.
+ − 630
* return values: an array with the id of the domain and its name.
+ − 631
*/
+ − 632
function get_domains_from_userid ( $id )
+ − 633
{
+ − 634
global $db ;
+ − 635
if ( is_numeric ( $id ))
+ − 636
{
+ − 637
$result = $db -> query ( "SELECT domains.id AS domain_id, domains.name AS name FROM domains LEFT JOIN zones ON domains.id=zones.domain_id WHERE owner= $id " );
+ − 638
+ − 639
$ret = array ();
+ − 640
+ − 641
// Put all the information in a big array.
+ − 642
while ( $r = $result -> fetchRow ())
+ − 643
{
+ − 644
$ret [] = array (
+ − 645
"id" => $r [ "domain_id" ],
+ − 646
"name" => $r [ "name" ]
+ − 647
);
+ − 648
}
+ − 649
return $ret ;
+ − 650
}
+ − 651
else
+ − 652
{
+ − 653
error ( sprintf ( ERR_INV_ARGC , "get_domains_from_userid" , "This is not a valid userid: $id " ));
+ − 654
}
+ − 655
}
+ − 656
+ − 657
+ − 658
/*
+ − 659
* Get domain name from a given id
+ − 660
* return values: the name of the domain associated with the id.
+ − 661
*/
+ − 662
function get_domain_name_from_id ( $id )
+ − 663
{
+ − 664
global $db ;
+ − 665
if ( ! xs ( $id ))
+ − 666
{
+ − 667
error ( ERR_RECORD_ACCESS_DENIED );
+ − 668
}
+ − 669
if ( is_numeric ( $id ))
+ − 670
{
+ − 671
$result = $db -> query ( "SELECT name FROM domains WHERE id= $id " );
+ − 672
if ( $result -> numRows () == 1 )
+ − 673
{
+ − 674
$r = $result -> fetchRow ();
+ − 675
return $r [ "name" ];
+ − 676
}
+ − 677
else
+ − 678
{
+ − 679
error ( sprintf ( ERR_INV_ARGC , "get_domain_name_from_id" , "more than one domain found?! whaaa! BAD! BAD! Contact admin!" ));
+ − 680
}
+ − 681
}
+ − 682
else
+ − 683
{
+ − 684
error ( sprintf ( ERR_INV_ARGC , "get_domain_name_from_id" , "Not a valid domainid: $id " ));
+ − 685
}
+ − 686
}
+ − 687
+ − 688
+ − 689
/*
+ − 690
* Get information about a domain name from a given domain id.
+ − 691
* the function looks up the domainname, the owner of the domain and the number of records in it.
+ − 692
* return values: an array containing the information.
+ − 693
*/
+ − 694
function get_domain_info_from_id ( $id )
+ − 695
{
+ − 696
global $db ;
+ − 697
if ( ! xs ( $id ))
+ − 698
{
+ − 699
error ( ERR_RECORD_ACCESS_DENIED );
+ − 700
}
+ − 701
if ( is_numeric ( $id ))
+ − 702
{
+ − 703
+ − 704
if ( $_SESSION [ $id . "_ispartial" ] == 1 ) {
+ − 705
13
+ − 706
$sqlq = "SELECT
+ − 707
domains.type AS type,
+ − 708
domains.name AS name,
1
+ − 709
users.fullname AS owner,
+ − 710
count(record_owners.id) AS aantal
+ − 711
FROM domains, users, record_owners, records
+ − 712
+ − 713
WHERE record_owners.user_id = " . $_SESSION [ "userid" ] . "
+ − 714
AND record_owners.record_id = records.id
+ − 715
AND records.domain_id = " . $id . "
+ − 716
+ − 717
GROUP BY name, owner, users.fullname
+ − 718
ORDER BY name" ;
+ − 719
8
+ − 720
$result = $db -> queryRow ( $sqlq );
1
+ − 721
+ − 722
$ret = array (
+ − 723
"name" => $result [ "name" ],
+ − 724
"ownerid" => $_SESSION [ "userid" ],
+ − 725
"owner" => $result [ "owner" ],
13
+ − 726
"type" => $result [ "type" ],
1
+ − 727
"numrec" => $result [ "aantal" ]
+ − 728
);
+ − 729
+ − 730
return $ret ;
+ − 731
+ − 732
} else {
+ − 733
+ − 734
// Query that retrieves the information we need.
13
+ − 735
$sqlq = "SELECT
+ − 736
domains.type AS type,
+ − 737
domains.name AS name,
1
+ − 738
min(zones.owner) AS ownerid,
+ − 739
users.fullname AS owner,
+ − 740
count(records.domain_id) AS aantal
+ − 741
FROM domains
+ − 742
LEFT JOIN records ON domains.id=records.domain_id
+ − 743
LEFT JOIN zones ON domains.id=zones.domain_id
+ − 744
LEFT JOIN users ON zones.owner=users.id
+ − 745
WHERE domains.id= $id
+ − 746
GROUP BY name, owner, users.fullname
+ − 747
ORDER BY zones.id" ;
+ − 748
+ − 749
// Put the first occurence in an array and return it.
8
+ − 750
$result = $db -> queryRow ( $sqlq );
1
+ − 751
8
+ − 752
//$result["ownerid"] = ($result["ownerid"] == NULL) ? $db->queryOne("select min(id) from users where users.level=10") : $result["ownerid"];
1
+ − 753
+ − 754
$ret = array (
+ − 755
"name" => $result [ "name" ],
+ − 756
"ownerid" => $result [ "ownerid" ],
+ − 757
"owner" => $result [ "owner" ],
13
+ − 758
"type" => $result [ "type" ],
1
+ − 759
"numrec" => $result [ "aantal" ]
+ − 760
);
+ − 761
return $ret ;
+ − 762
}
+ − 763
+ − 764
}
+ − 765
else
+ − 766
{
+ − 767
error ( sprintf ( ERR_INV_ARGC , "get_domain_num_records_from_id" , "This is not a valid domainid: $id " ));
+ − 768
}
+ − 769
}
+ − 770
+ − 771
+ − 772
/*
+ − 773
* Check if a domain is already existing.
+ − 774
* return values: true if existing, false if it doesnt exist.
+ − 775
*/
+ − 776
function domain_exists ( $domain )
+ − 777
{
+ − 778
global $db ;
+ − 779
+ − 780
if ( ! level ( 5 ))
+ − 781
{
+ − 782
error ( ERR_LEVEL_5 );
+ − 783
}
+ − 784
if ( is_valid_domain ( $domain ))
+ − 785
{
+ − 786
$result = $db -> query ( "SELECT id FROM domains WHERE name=' $domain '" );
+ − 787
if ( $result -> numRows () == 0 )
+ − 788
{
+ − 789
return false ;
+ − 790
}
+ − 791
elseif ( $result -> numRows () >= 1 )
+ − 792
{
+ − 793
return true ;
+ − 794
}
+ − 795
}
+ − 796
else
+ − 797
{
+ − 798
error ( ERR_DOMAIN_INVALID );
+ − 799
}
+ − 800
}
+ − 801
13
+ − 802
function get_supermasters ()
+ − 803
{
+ − 804
global $db ;
+ − 805
$result = $db -> query ( "SELECT ip, nameserver, account FROM supermasters" );
+ − 806
$ret = array ();
+ − 807
+ − 808
if ( $result -> numRows () == 0 )
+ − 809
{
+ − 810
return - 1 ;
+ − 811
}
+ − 812
else
+ − 813
{
+ − 814
while ( $r = $result -> fetchRow ())
+ − 815
{
+ − 816
$ret [] = array (
+ − 817
"master_ip" => $r [ "ip" ],
+ − 818
"ns_name" => $r [ "nameserver" ],
+ − 819
"account" => $r [ "account" ],
+ − 820
);
+ − 821
}
36
+ − 822
return $ret ;
13
+ − 823
}
+ − 824
}
+ − 825
+ − 826
function supermaster_exists ( $master_ip )
+ − 827
{
+ − 828
global $db ;
+ − 829
if ( ! level ( 5 ))
+ − 830
{
+ − 831
error ( ERR_LEVEL_5 );
+ − 832
}
+ − 833
if ( is_valid_ip ( $master_ip ) || is_valid_ip6 ( $master_ip ))
+ − 834
{
+ − 835
$result = $db -> query ( "SELECT ip FROM supermasters WHERE ip = ' $master_ip '" );
+ − 836
if ( $result -> numRows () == 0 )
+ − 837
{
+ − 838
return false ;
+ − 839
}
+ − 840
elseif ( $result -> numRows () >= 1 )
+ − 841
{
+ − 842
return true ;
+ − 843
}
+ − 844
}
+ − 845
else
+ − 846
{
+ − 847
error ( sprintf ( ERR_INV_ARGC , "supermaster_exists" , "No or no valid IPv4 or IPv6 address given." ));
+ − 848
}
+ − 849
}
+ − 850
1
+ − 851
+ − 852
/*
13
+ − 853
* Get all domains from the database
1
+ − 854
* This function gets all the domains from the database unless a user id is below 5.
+ − 855
* if a user id is below 5 this function will only retrieve records for that user.
+ − 856
* return values: the array of domains or -1 if nothing is found.
+ − 857
*/
+ − 858
function get_domains ( $userid = true , $letterstart = all , $rowstart = 0 , $rowamount = 999999 )
+ − 859
{
+ − 860
global $db ;
+ − 861
if (( ! level ( 5 ) || ! $userid ) && ! level ( 10 ) && ! level ( 5 ))
+ − 862
{
+ − 863
$add = " AND zones.owner=" . $_SESSION [ "userid" ];
+ − 864
}
+ − 865
else
+ − 866
{
+ − 867
$add = "" ;
+ − 868
}
+ − 869
+ − 870
$sqlq = "SELECT domains.id AS domain_id,
+ − 871
min(zones.owner) AS owner,
+ − 872
count(DISTINCT records.id) AS aantal,
+ − 873
domains.name AS domainname
+ − 874
FROM domains
+ − 875
LEFT JOIN zones ON domains.id=zones.domain_id
+ − 876
LEFT JOIN records ON records.domain_id=domains.id
+ − 877
WHERE 1 $add " ;
+ − 878
if ( $letterstart != all && $letterstart != 1 ) {
21
+ − 879
$sqlq .= " AND substring(domains.name,1,1) REGEXP '^" . $letterstart . "' " ;
1
+ − 880
} elseif ( $letterstart == 1 ) {
21
+ − 881
$sqlq .= " AND substring(domains.name,1,1) REGEXP '^[[:digit:]]'" ;
1
+ − 882
}
+ − 883
$sqlq .= " GROUP BY domainname, domain_id
+ − 884
ORDER BY domainname
+ − 885
LIMIT $rowstart , $rowamount " ;
+ − 886
+ − 887
$result = $db -> query ( $sqlq );
21
+ − 888
$result2 = $db -> query ( $sqlq );
+ − 889
+ − 890
$numrows = $result2 -> numRows ();
+ − 891
$i = 1 ;
+ − 892
if ( $numrows > 0 ) {
+ − 893
$andnot = " AND NOT domains.id IN (" ;
+ − 894
while ( $r = $result2 -> fetchRow ()) {
+ − 895
$andnot .= $r [ "domain_id" ];
+ − 896
if ( $i < $numrows ) {
+ − 897
$andnot .= "," ;
+ − 898
$i ++ ;
+ − 899
}
+ − 900
}
+ − 901
$andnot .= ")" ;
+ − 902
}
+ − 903
else
+ − 904
{
+ − 905
$andnot = "" ;
1
+ − 906
}
+ − 907
21
+ − 908
if ( $letterstart != all && $letterstart != 1 ) {
1
+ − 909
21
+ − 910
$sqlq = "SELECT domains.id AS domain_id,
+ − 911
count(DISTINCT record_owners.record_id) AS aantal,
+ − 912
domains.name AS domainname
+ − 913
FROM domains, record_owners,records, zones
+ − 914
WHERE record_owners.user_id = '" . $_SESSION [ "userid" ] . "'
+ − 915
AND (records.id = record_owners.record_id
+ − 916
AND domains.id = records.domain_id)
+ − 917
$andnot
+ − 918
AND domains.name LIKE '" . $letterstart . "%'
+ − 919
AND (zones.domain_id != records.domain_id AND zones.owner!='" . $_SESSION [ "userid" ] . "')
+ − 920
GROUP BY domainname, domain_id
+ − 921
ORDER BY domainname" ;
1
+ − 922
21
+ − 923
$result_extra = $db -> query ( $sqlq );
1
+ − 924
21
+ − 925
} else {
1
+ − 926
21
+ − 927
$sqlq = "SELECT domains.id AS domain_id,
+ − 928
count(DISTINCT record_owners.record_id) AS aantal,
+ − 929
domains.name AS domainname
+ − 930
FROM domains, record_owners,records, zones
+ − 931
WHERE record_owners.user_id = '" . $_SESSION [ "userid" ] . "'
+ − 932
AND (records.id = record_owners.record_id
+ − 933
AND domains.id = records.domain_id)
+ − 934
$andnot
+ − 935
AND substring(domains.name,1,1) REGEXP '^[[:digit:]]'
+ − 936
AND (zones.domain_id != records.domain_id AND zones.owner!='" . $_SESSION [ "userid" ] . "')
+ − 937
GROUP BY domainname, domain_id
+ − 938
ORDER BY domainname" ;
1
+ − 939
21
+ − 940
$result_extra [ $i ] = $db -> query ( $sqlq );
+ − 941
1
+ − 942
}
+ − 943
+ − 944
while ( $r = $result -> fetchRow ())
+ − 945
{
8
+ − 946
$r [ "owner" ] = ( $r [ "owner" ] == NULL ) ? $db -> queryOne ( "select min(id) from users where users.level=10" ) : $r [ "owner" ];
1
+ − 947
$ret [ $r [ "domainname" ]] = array (
+ − 948
"name" => $r [ "domainname" ],
+ − 949
"id" => $r [ "domain_id" ],
+ − 950
"owner" => $r [ "owner" ],
+ − 951
"numrec" => $r [ "aantal" ]
+ − 952
);
+ − 953
}
+ − 954
+ − 955
21
+ − 956
if ( $letterstart != all && $letterstart != 1 ) {
1
+ − 957
21
+ − 958
while ( $r = $result_extra -> fetchRow ())
+ − 959
{
+ − 960
$ret [ $r [ "domainname" ]] = array (
+ − 961
"name" => $r [ "domainname" ] . "*" ,
+ − 962
"id" => $r [ "domain_id" ],
+ − 963
"owner" => $_SESSION [ "userid" ],
+ − 964
"numrec" => $r [ "aantal" ]
+ − 965
);
+ − 966
$_SESSION [ "partial_" . $r [ "domainname" ]] = 1 ;
+ − 967
}
1
+ − 968
21
+ − 969
} else {
1
+ − 970
21
+ − 971
foreach ( $result_extra as $result_e ) {
+ − 972
while ( $r = $result_e -> fetchRow ())
+ − 973
{
+ − 974
$ret [ $r [ "domainname" ]] = array (
+ − 975
"name" => $r [ "domainname" ] . "*" ,
+ − 976
"id" => $r [ "domain_id" ],
+ − 977
"owner" => $_SESSION [ "userid" ],
+ − 978
"numrec" => $r [ "aantal" ]
+ − 979
);
+ − 980
$_SESSION [ "partial_" . $r [ "domainname" ]] = 1 ;
+ − 981
}
+ − 982
}
+ − 983
1
+ − 984
}
+ − 985
21
+ − 986
if ( empty ( $ret )) {
+ − 987
return - 1 ;
+ − 988
} else {
+ − 989
sort ( $ret );
+ − 990
return $ret ;
+ − 991
}
1
+ − 992
+ − 993
}
+ − 994
+ − 995
+ − 996
/*
30
+ − 997
* zone_count
+ − 998
* Does a select query to count how many zones we have in the database
+ − 999
*
+ − 1000
* @todo: see whether or not it is possible to add the records
+ − 1001
* @param $userid integer The userid of the current user
+ − 1002
* @return integer the number of zones
+ − 1003
*/
+ − 1004
+ − 1005
function zone_count ( $userid = true , $letterstart = all ) {
+ − 1006
global $db ;
+ − 1007
if (( ! level ( 5 ) || ! $userid ) && ! level ( 10 ) && ! level ( 5 ))
+ − 1008
{
37
+ − 1009
// First select the zones for which we have ownership on one or more records.
+ − 1010
$query = 'SELECT records.domain_id FROM records, record_owners WHERE user_id = ' . $_SESSION [ 'userid' ] . ' AND records.id = record_owners.record_id' ;
+ − 1011
$result = $db -> query ( $query );
+ − 1012
$zones = array ();
+ − 1013
if ( ! PEAR :: isError ( $result )) {
+ − 1014
$zones = $result -> fetchCol ();
+ − 1015
}
+ − 1016
+ − 1017
$add = " AND (zones.owner=" . $_SESSION [ "userid" ];
+ − 1018
if ( count ( $zones ) > 0 ) {
+ − 1019
$add .= ' OR zones.domain_id IN (' . implode ( ',' , $zones ) . ') ' ;
+ − 1020
+ − 1021
}
+ − 1022
$add .= ')' ;
30
+ − 1023
}
+ − 1024
else
+ − 1025
{
+ − 1026
$add = "" ;
+ − 1027
}
+ − 1028
+ − 1029
if ( $letterstart != all && $letterstart != 1 ) {
+ − 1030
$add .= " AND domains.name LIKE '" . $letterstart . "%' " ;
+ − 1031
} elseif ( $letterstart == 1 ) {
+ − 1032
$add .= " AND substring(domains.name,1,1) REGEXP '^[[:digit:]]'" ;
+ − 1033
}
+ − 1034
+ − 1035
$query = 'SELECT count(distinct zones.domain_id) as zone_count FROM zones, domains WHERE zones.domain_id = domains.id ' . $add ;
+ − 1036
$numRows = $db -> queryOne ( $query );
+ − 1037
return $numRows ;
+ − 1038
}
+ − 1039
+ − 1040
/*
1
+ − 1041
* Get a record from an id.
+ − 1042
* Retrieve all fields of the record and send it back to the function caller.
+ − 1043
* return values: the array with information, or -1 is nothing is found.
+ − 1044
*/
+ − 1045
function get_record_from_id ( $id )
+ − 1046
{
+ − 1047
global $db ;
+ − 1048
if ( is_numeric ( $id ))
+ − 1049
{
+ − 1050
$result = $db -> query ( "SELECT id, domain_id, name, type, content, ttl, prio, change_date FROM records WHERE id= $id " );
+ − 1051
if ( $result -> numRows () == 0 )
+ − 1052
{
+ − 1053
return - 1 ;
+ − 1054
}
+ − 1055
elseif ( $result -> numRows () == 1 )
+ − 1056
{
+ − 1057
$r = $result -> fetchRow ();
+ − 1058
$ret = array (
+ − 1059
"id" => $r [ "id" ],
+ − 1060
"domain_id" => $r [ "domain_id" ],
+ − 1061
"name" => $r [ "name" ],
+ − 1062
"type" => $r [ "type" ],
+ − 1063
"content" => $r [ "content" ],
+ − 1064
"ttl" => $r [ "ttl" ],
+ − 1065
"prio" => $r [ "prio" ],
+ − 1066
"change_date" => $r [ "change_date" ]
+ − 1067
);
+ − 1068
return $ret ;
+ − 1069
}
+ − 1070
else
+ − 1071
{
+ − 1072
error ( sprintf ( ERR_INV_ARGC , "get_record_from_id" , "More than one row returned! This is bad!" ));
+ − 1073
}
+ − 1074
}
+ − 1075
else
+ − 1076
{
+ − 1077
error ( sprintf ( ERR_INV_ARG , "get_record_from_id" ));
+ − 1078
}
+ − 1079
}
+ − 1080
+ − 1081
+ − 1082
/*
+ − 1083
* Get all records from a domain id.
+ − 1084
* Retrieve all fields of the records and send it back to the function caller.
+ − 1085
* return values: the array with information, or -1 is nothing is found.
+ − 1086
*/
+ − 1087
function get_records_from_domain_id ( $id , $rowstart = 0 , $rowamount = 999999 )
+ − 1088
{
+ − 1089
global $db ;
+ − 1090
if ( is_numeric ( $id ))
+ − 1091
{
+ − 1092
if ( $_SESSION [ $id . "_ispartial" ] == 1 ) {
+ − 1093
+ − 1094
$result = $db -> query ( "SELECT record_owners.record_id as id
+ − 1095
FROM record_owners,domains,records
+ − 1096
WHERE record_owners.user_id = " . $_SESSION [ "userid" ] . "
+ − 1097
AND record_owners.record_id = records.id
+ − 1098
AND records.domain_id = " . $id . "
+ − 1099
GROUP bY record_owners.record_id
+ − 1100
LIMIT $rowstart , $rowamount " );
+ − 1101
+ − 1102
$ret = array ();
+ − 1103
if ( $result -> numRows () == 0 )
+ − 1104
{
+ − 1105
return - 1 ;
+ − 1106
}
+ − 1107
else
+ − 1108
{
+ − 1109
$ret [] = array ();
+ − 1110
$retcount = 0 ;
+ − 1111
while ( $r = $result -> fetchRow ())
+ − 1112
{
+ − 1113
// Call get_record_from_id for each row.
+ − 1114
$ret [ $retcount ] = get_record_from_id ( $r [ "id" ]);
+ − 1115
$retcount ++ ;
+ − 1116
}
+ − 1117
return $ret ;
+ − 1118
}
+ − 1119
+ − 1120
} else {
+ − 1121
+ − 1122
$result = $db -> query ( "SELECT id FROM records WHERE domain_id= $id LIMIT $rowstart , $rowamount " );
+ − 1123
$ret = array ();
+ − 1124
if ( $result -> numRows () == 0 )
+ − 1125
{
+ − 1126
return - 1 ;
+ − 1127
}
+ − 1128
else
+ − 1129
{
+ − 1130
$ret [] = array ();
+ − 1131
$retcount = 0 ;
+ − 1132
while ( $r = $result -> fetchRow ())
+ − 1133
{
+ − 1134
// Call get_record_from_id for each row.
+ − 1135
$ret [ $retcount ] = get_record_from_id ( $r [ "id" ]);
+ − 1136
$retcount ++ ;
+ − 1137
}
+ − 1138
return $ret ;
+ − 1139
}
+ − 1140
+ − 1141
}
+ − 1142
}
+ − 1143
else
+ − 1144
{
+ − 1145
error ( sprintf ( ERR_INV_ARG , "get_records_from_domain_id" ));
+ − 1146
}
+ − 1147
}
+ − 1148
+ − 1149
+ − 1150
function get_users_from_domain_id ( $id )
+ − 1151
{
+ − 1152
global $db ;
8
+ − 1153
$result = $db -> queryCol ( "SELECT owner FROM zones WHERE domain_id= $id " );
1
+ − 1154
$ret = array ();
+ − 1155
foreach ( $result as $uid )
+ − 1156
{
8
+ − 1157
$fullname = $db -> queryOne ( "SELECT fullname FROM users WHERE id= $uid " );
1
+ − 1158
$ret [] = array (
+ − 1159
"id" => $uid ,
+ − 1160
"fullname" => $fullname
+ − 1161
);
+ − 1162
}
+ − 1163
return $ret ;
+ − 1164
}
+ − 1165
+ − 1166
function search_record ( $question )
+ − 1167
{
+ − 1168
global $db ;
+ − 1169
$question = trim ( $question );
+ − 1170
if ( empty ( $question ))
+ − 1171
{
+ − 1172
$S_INPUT_TYPE = - 1 ;
+ − 1173
}
+ − 1174
+ − 1175
/* now for some input-type searching */
+ − 1176
if ( is_valid_ip ( $question ) || is_valid_ip6 ( $question ))
+ − 1177
{
+ − 1178
$S_INPUT_TYPE = 0 ;
+ − 1179
}
+ − 1180
elseif ( is_valid_domain ( $question ) ||
+ − 1181
is_valid_hostname ( $question ) ||
+ − 1182
is_valid_mboxfw ( $question )) // I guess this one can appear in records table too (content?!)
+ − 1183
{
+ − 1184
$S_INPUT_TYPE = 1 ;
+ − 1185
}
+ − 1186
else
+ − 1187
{
+ − 1188
$S_INPUT_TYPE = - 1 ;
+ − 1189
}
+ − 1190
switch ( $S_INPUT_TYPE )
+ − 1191
{
+ − 1192
case '0' :
+ − 1193
$sqlq = "SELECT * FROM `records` WHERE `content` = '" . $question . "' ORDER BY `type` DESC" ;
+ − 1194
$result = $db -> query ( $sqlq );
+ − 1195
$ret_r = array ();
+ − 1196
while ( $r = $result -> fetchRow ())
+ − 1197
{
+ − 1198
if ( xs ( $r [ 'domain_id' ]))
+ − 1199
{
+ − 1200
$ret_r [] = array (
+ − 1201
'id' => $r [ 'id' ],
+ − 1202
'domain_id' => $r [ 'domain_id' ],
+ − 1203
'name' => $r [ 'name' ],
+ − 1204
'type' => $r [ 'type' ],
+ − 1205
'content' => $r [ 'content' ],
+ − 1206
'ttl' => $r [ 'ttl' ],
+ − 1207
'prio' => $r [ 'prio' ],
+ − 1208
'change_date' => $r [ 'change_date' ]
+ − 1209
);
+ − 1210
}
+ − 1211
}
+ − 1212
break ;
+ − 1213
+ − 1214
case '1' :
5
+ − 1215
$sqlq = "SELECT `domains`.*, count(`records`.`id`) AS `numrec`, `zones`.`owner`, `records`.`domain_id`
1
+ − 1216
FROM `domains`, `records`, `zones`
+ − 1217
WHERE `domains`.`id` = `records`.`domain_id`
+ − 1218
AND `zones`.`domain_id` = `domains`.`id`
+ − 1219
AND `domains`.`name` = '" . $question . "'
+ − 1220
GROUP BY (`domains`.`id`)" ;
+ − 1221
+ − 1222
$result = $db -> query ( $sqlq );
+ − 1223
$ret_d = array ();
+ − 1224
while ( $r = $result -> fetchRow ())
+ − 1225
{
+ − 1226
if ( xs ( $r [ 'domain_id' ]))
+ − 1227
{
+ − 1228
$ret_d [] = array (
+ − 1229
'id' => $r [ 'id' ],
+ − 1230
'name' => $r [ 'name' ],
+ − 1231
'numrec' => $r [ 'numrec' ],
+ − 1232
'owner' => $r [ 'owner' ]
+ − 1233
);
+ − 1234
}
+ − 1235
}
+ − 1236
+ − 1237
$sqlq = "SELECT * FROM `records` WHERE `name` = '" . $question . "' OR `content` = '" . $question . "' ORDER BY `type` DESC" ;
+ − 1238
$result = $db -> query ( $sqlq );
+ − 1239
while ( $r = $result -> fetchRow ())
+ − 1240
{
+ − 1241
if ( xs ( $r [ 'domain_id' ]))
+ − 1242
{
+ − 1243
$ret_r [] = array (
+ − 1244
'id' => $r [ 'id' ],
+ − 1245
'domain_id' => $r [ 'domain_id' ],
+ − 1246
'name' => $r [ 'name' ],
+ − 1247
'type' => $r [ 'type' ],
+ − 1248
'content' => $r [ 'content' ],
+ − 1249
'ttl' => $r [ 'ttl' ],
+ − 1250
'prio' => $r [ 'prio' ],
+ − 1251
);
+ − 1252
}
+ − 1253
}
+ − 1254
break ;
+ − 1255
}
+ − 1256
if ( $S_INPUT_TYPE == 1 )
+ − 1257
{
+ − 1258
return array ( 'domains' => $ret_d , 'records' => $ret_r );
+ − 1259
}
+ − 1260
return array ( 'records' => $ret_r );
+ − 1261
}
+ − 1262
+ − 1263
function get_domain_type ( $id )
+ − 1264
{
+ − 1265
global $db ;
13
+ − 1266
if ( is_numeric ( $id ))
1
+ − 1267
{
13
+ − 1268
$type = $db -> queryOne ( "SELECT `type` FROM `domains` WHERE `id` = '" . $id . "'" );
+ − 1269
if ( $type == "" )
+ − 1270
{
+ − 1271
$type = "NATIVE" ;
+ − 1272
}
+ − 1273
return $type ;
+ − 1274
}
+ − 1275
else
+ − 1276
{
+ − 1277
error ( sprintf ( ERR_INV_ARG , "get_record_from_id" , "no or no valid zoneid given" ));
+ − 1278
}
+ − 1279
}
+ − 1280
+ − 1281
function get_domain_slave_master ( $id )
+ − 1282
{
+ − 1283
global $db ;
+ − 1284
if ( is_numeric ( $id ))
+ − 1285
{
+ − 1286
$slave_master = $db -> queryOne ( "SELECT `master` FROM `domains` WHERE `type` = 'SLAVE' and `id` = '" . $id . "'" );
+ − 1287
return $slave_master ;
+ − 1288
}
+ − 1289
else
+ − 1290
{
+ − 1291
error ( sprintf ( ERR_INV_ARG , "get_domain_slave_master" , "no or no valid zoneid given" ));
+ − 1292
}
1
+ − 1293
}
+ − 1294
+ − 1295
function change_domain_type ( $type , $id )
+ − 1296
{
13
+ − 1297
global $db ;
+ − 1298
unset ( $add );
+ − 1299
if ( is_numeric ( $id ))
+ − 1300
{
+ − 1301
// It is not really neccesary to clear the master field if a
+ − 1302
// zone is not of the type "slave" as powerdns will ignore that
+ − 1303
// fiedl, but it is cleaner anyway.
+ − 1304
if ( $type != "SLAVE" )
+ − 1305
{
+ − 1306
$add = ", master=''" ;
+ − 1307
}
+ − 1308
$result = $db -> query ( "UPDATE `domains` SET `type` = '" . $type . "'" . $add . " WHERE `id` = '" . $id . "'" );
+ − 1309
}
+ − 1310
else
+ − 1311
{
+ − 1312
error ( sprintf ( ERR_INV_ARG , "change_domain_type" , "no or no valid zoneid given" ));
+ − 1313
}
+ − 1314
}
+ − 1315
+ − 1316
function change_domain_slave_master ( $id , $slave_master )
+ − 1317
{
+ − 1318
global $db ;
+ − 1319
if ( is_numeric ( $id ))
+ − 1320
{
+ − 1321
if ( is_valid_ip ( $slave_master ) || is_valid_ip6 ( $slave_master ))
+ − 1322
{
+ − 1323
$result = $db -> query ( "UPDATE `domains` SET `master` = '" . $slave_master . "' WHERE `id` = '" . $id . "'" );
+ − 1324
}
+ − 1325
else
+ − 1326
{
+ − 1327
error ( sprintf ( ERR_INV_ARGC , "change_domain_slave_master" , "This is not a valid IPv4 or IPv6 address: $slave_master " ));
+ − 1328
}
+ − 1329
}
+ − 1330
else
+ − 1331
{
+ − 1332
error ( sprintf ( ERR_INV_ARG , "change_domain_type" , "no or no valid zoneid given" ));
+ − 1333
}
+ − 1334
}
+ − 1335
+ − 1336
+ − 1337
function validate_account ( $account )
+ − 1338
{
+ − 1339
+ − 1340
if ( preg_match ( "/^[A-Z0-9._-]+$/i" , $account ))
+ − 1341
{
+ − 1342
return true ;
+ − 1343
}
+ − 1344
else
+ − 1345
{
+ − 1346
return false ;
+ − 1347
}
1
+ − 1348
}
+ − 1349
?>