1
+ − 1
<?
+ − 2
+ − 3
// +--------------------------------------------------------------------+
+ − 4
// | PowerAdmin |
+ − 5
// +--------------------------------------------------------------------+
+ − 6
// | Copyright (c) 1997-2002 The PowerAdmin Team |
+ − 7
// +--------------------------------------------------------------------+
+ − 8
// | This source file is subject to the license carried by the overal |
+ − 9
// | program PowerAdmin as found on http://poweradmin.sf.net |
+ − 10
// | The PowerAdmin program falls under the QPL License: |
+ − 11
// | http://www.trolltech.com/developer/licensing/qpl.html |
+ − 12
// +--------------------------------------------------------------------+
+ − 13
// | Authors: Roeland Nieuwenhuis <trancer <AT> trancer <DOT> nl> |
+ − 14
// | Sjeemz <sjeemz <AT> sjeemz <DOT> nl> |
+ − 15
// +--------------------------------------------------------------------+
+ − 16
+ − 17
// Filename: record.inc.php
+ − 18
// Startdate: 26-10-2002
+ − 19
// This file is ought to edit the records in the database.
+ − 20
// Records are domains aswell, they also belong here.
+ − 21
// All database functions are associative.
+ − 22
// use nextID first to get a new id. Then insert it into the database.
+ − 23
// do not rely on auto_increment (see above).
+ − 24
// use dns.inc.php for validation functions.
+ − 25
//
+ − 26
// $Id: record.inc.php,v 1.21 2003/05/10 20:21:01 azurazu Exp $
+ − 27
//
+ − 28
+ − 29
+ − 30
function update_soa_serial ( $domain_id )
+ − 31
{
+ − 32
global $db ;
+ − 33
/*
+ − 34
* THIS CODE ISNT TESTED THROUGH MUCH YET!
+ − 35
* !!!!!!! BETACODE !!!!!!!!!!
+ − 36
* Code committed by DeViCeD, Thanks a lot!
+ − 37
* Heavily hax0red by Trancer/azurazu
+ − 38
*
+ − 39
* First we have to check, wheather current searial number
+ − 40
* was already updated on the other nameservers.
+ − 41
* If field 'notified_serial' is NULL, then I guess domain is
+ − 42
* NATIVE and we don't have any secondary nameservers for this domain.
+ − 43
* NOTICE: Serial number *will* be RFC1912 compilant after update
+ − 44
* NOTICE: This function will allow only 100 DNS zone transfers ;-)
+ − 45
* YYYYMMDDnn
+ − 46
*/
+ − 47
+ − 48
$sqlq = "SELECT `notified_serial` FROM `domains` WHERE `id` = '" . $domain_id . "'" ;
8
+ − 49
$notified_serial = $db -> queryOne ( $sqlq );
1
+ − 50
+ − 51
$sqlq = "SELECT `content` FROM `records` WHERE `type` = 'SOA' AND `domain_id` = '" . $domain_id . "'" ;
8
+ − 52
$content = $db -> queryOne ( $sqlq );
1
+ − 53
$need_to_update = false ;
+ − 54
+ − 55
// Getting the serial field.
+ − 56
$soa = explode ( " " , $content );
+ − 57
+ − 58
if ( empty ( $notified_serial ))
+ − 59
{
+ − 60
// Ok native replication, so we have to update.
+ − 61
$need_to_update = true ;
+ − 62
}
+ − 63
elseif ( $notified_serial >= $soa [ 2 ])
+ − 64
{
+ − 65
$need_to_update = true ;
+ − 66
}
+ − 67
elseif ( strlen ( $soa [ 2 ]) != 10 )
+ − 68
{
+ − 69
$need_to_update = true ;
+ − 70
}
+ − 71
else
+ − 72
{
+ − 73
$need_to_update = false ;
+ − 74
}
+ − 75
if ( $need_to_update )
+ − 76
{
+ − 77
// Ok so we have to update it seems.
+ − 78
$current_serial = $soa [ 2 ];
+ − 79
+ − 80
/*
+ − 81
* What we need here (for RFC1912) is YEAR, MONTH and DAY
+ − 82
* so let's get it ...
+ − 83
*/
+ − 84
$new_serial = date ( 'Ymd' ); // we will add revision number later
+ − 85
+ − 86
if ( strncmp ( $new_serial , $current_serial , 8 ) === 0 )
+ − 87
{
+ − 88
/*
+ − 89
* Ok, so we already made updates tonight
+ − 90
* let's just increase the revision number
+ − 91
*/
+ − 92
$revision_number = ( int ) substr ( $current_serial , - 2 );
+ − 93
if ( $revision_number == 99 ) return false ; // ok, we cannot update anymore tonight
+ − 94
++ $revision_number ;
+ − 95
// here it is ... same date, new revision
+ − 96
$new_serial .= str_pad ( $revision_number , 2 , "0" , STR_PAD_LEFT );
+ − 97
}
+ − 98
else
+ − 99
{
+ − 100
/*
+ − 101
* Current serial is not RFC1912 compilant, so let's make a new one
+ − 102
*/
+ − 103
$new_serial .= '00' ;
+ − 104
}
+ − 105
$soa [ 2 ] = $new_serial ; // change serial in SOA array
+ − 106
$new_soa = "" ;
+ − 107
// build new soa and update SQL after that
+ − 108
for ( $i = 0 ; $i < count ( $soa ); $i ++ )
+ − 109
{
+ − 110
$new_soa .= $soa [ $i ] . " " ;
+ − 111
}
+ − 112
$sqlq = "UPDATE `records` SET `content` = '" . $new_soa . "' WHERE `domain_id` = '" . $domain_id . "' AND `type` = 'SOA' LIMIT 1" ;
+ − 113
$db -> Query ( $sqlq );
+ − 114
return true ;
+ − 115
}
+ − 116
}
+ − 117
+ − 118
/*
+ − 119
* Edit a record.
+ − 120
* This function validates it if correct it inserts it into the database.
+ − 121
* return values: true if succesful.
+ − 122
*/
+ − 123
function edit_record ( $recordid , $zoneid , $name , $type , $content , $ttl , $prio )
+ − 124
{
+ − 125
global $db ;
+ − 126
if ( $content == "" )
+ − 127
{
+ − 128
error ( ERR_RECORD_EMPTY_CONTENT );
+ − 129
}
+ − 130
// Edits the given record (validates specific stuff first)
+ − 131
if ( ! xs ( recid_to_domid ( $recordid )))
+ − 132
{
+ − 133
error ( ERR_RECORD_ACCESS_DENIED );
+ − 134
}
+ − 135
if ( is_numeric ( $zoneid ))
+ − 136
{
19
+ − 137
validate_input ( $zoneid , $type , $content , $name , $prio , $ttl );
1
+ − 138
$change = time ();
+ − 139
$db -> query ( "UPDATE records set name=' $name ', type=' $type ', content=' $content ', ttl=' $ttl ', prio=' $prio ', change_date=' $change ' WHERE id= $recordid " );
+ − 140
+ − 141
/*
+ − 142
* Added by DeViCeD - Update SOA Serial number
+ − 143
* There should be more checks
+ − 144
*/
+ − 145
if ( $type != 'SOA' )
+ − 146
{
+ − 147
update_soa_serial ( $zoneid );
+ − 148
}
+ − 149
return true ;
+ − 150
}
+ − 151
else
+ − 152
{
+ − 153
error ( sprintf ( ERR_INV_ARGC , "edit_record" , "no zoneid given" ));
+ − 154
}
+ − 155
+ − 156
}
+ − 157
+ − 158
+ − 159
/*
+ − 160
* Adds a record.
+ − 161
* This function validates it if correct it inserts it into the database.
+ − 162
* return values: true if succesful.
+ − 163
*/
+ − 164
function add_record ( $zoneid , $name , $type , $content , $ttl , $prio )
+ − 165
{
+ − 166
+ − 167
global $db ;
+ − 168
if ( ! xs ( $zoneid ))
+ − 169
{
+ − 170
error ( ERR_RECORD_ACCESS_DENIED );
+ − 171
}
+ − 172
if ( is_numeric ( $zoneid ))
+ − 173
{
8
+ − 174
// Check the user input.
+ − 175
validate_input ( $zoneid , $type , $content , $name , $prio , $ttl );
1
+ − 176
8
+ − 177
// Generate new timestamp for the daemon
1
+ − 178
$change = time ();
8
+ − 179
1
+ − 180
// Execute query.
8
+ − 181
$db -> query ( "INSERT INTO records (domain_id, name, type, content, ttl, prio, change_date) VALUES ( $zoneid , ' $name ', ' $type ', ' $content ', $ttl , ' $prio ', $change )" );
1
+ − 182
if ( $type != 'SOA' )
+ − 183
{
+ − 184
update_soa_serial ( $zoneid );
+ − 185
}
+ − 186
return true ;
+ − 187
}
+ − 188
else
+ − 189
{
+ − 190
error ( sprintf ( ERR_INV_ARG , "add_record" ));
+ − 191
}
+ − 192
}
+ − 193
+ − 194
13
+ − 195
function add_supermaster ( $master_ip , $ns_name , $account )
+ − 196
{
+ − 197
global $db ;
+ − 198
if ( ! is_valid_ip ( $master_ip ) && ! is_valid_ip6 ( $master_ip ))
+ − 199
{
+ − 200
error ( sprintf ( ERR_INV_ARGC , "add_supermaster" , "No or no valid ipv4 or ipv6 address given." ));
+ − 201
}
+ − 202
if ( ! is_valid_hostname ( $ns_name ))
+ − 203
{
+ − 204
error ( ERR_DNS_HOSTNAME );
+ − 205
}
+ − 206
if ( ! validate_account ( $account ))
+ − 207
{
+ − 208
error ( sprintf ( ERR_INV_ARGC , "add_supermaster" , "given account name is invalid (alpha chars only)" ));
+ − 209
}
+ − 210
if ( supermaster_exists ( $master_ip ))
+ − 211
{
+ − 212
error ( sprintf ( ERR_INV_ARGC , "add_supermaster" , "supermaster already exists" ));
+ − 213
}
+ − 214
else
+ − 215
{
+ − 216
$db -> query ( "INSERT INTO supermasters VALUES (' $master_ip ', ' $ns_name ', ' $account ')" );
+ − 217
return true ;
+ − 218
}
+ − 219
}
+ − 220
+ − 221
function delete_supermaster ( $master_ip )
+ − 222
{
+ − 223
global $db ;
+ − 224
if ( ! level ( 5 ))
+ − 225
{
+ − 226
error ( ERR_LEVEL_5 );
+ − 227
}
+ − 228
if ( is_valid_ip ( $master_ip ) || is_valid_ip6 ( $master_ip ))
+ − 229
{
+ − 230
$db -> query ( "DELETE FROM supermasters WHERE ip = ' $master_ip '" );
+ − 231
return true ;
+ − 232
}
+ − 233
else
+ − 234
{
+ − 235
error ( sprintf ( ERR_INV_ARGC , "delete_supermaster" , "No or no valid ipv4 or ipv6 address given." ));
+ − 236
}
+ − 237
}
+ − 238
+ − 239
function get_supermaster_info_from_ip ( $master_ip )
+ − 240
{
+ − 241
global $db ;
+ − 242
if ( ! level ( 5 ))
+ − 243
{
+ − 244
error ( ERR_LEVEL_5 );
+ − 245
}
+ − 246
if ( is_valid_ip ( $master_ip ) || is_valid_ip6 ( $master_ip ))
+ − 247
{
+ − 248
$result = $db -> queryRow ( "SELECT ip,nameserver,account FROM supermasters WHERE ip = ' $master_ip '" );
+ − 249
+ − 250
$ret = array (
+ − 251
"master_ip" => $result [ "ip" ],
+ − 252
"ns_name" => $result [ "nameserver" ],
+ − 253
"account" => $result [ "account" ]
+ − 254
);
+ − 255
+ − 256
return $ret ;
+ − 257
}
+ − 258
else
+ − 259
{
+ − 260
error ( sprintf ( ERR_INV_ARGC , "get_supermaster_info_from_ip" , "No or no valid ipv4 or ipv6 address given." ));
+ − 261
}
+ − 262
}
+ − 263
+ − 264
1
+ − 265
/*
+ − 266
* Delete a record by a given id.
+ − 267
* return values: true, this function is always succesful.
+ − 268
*/
+ − 269
function delete_record ( $id )
+ − 270
{
+ − 271
global $db ;
+ − 272
+ − 273
// Check if the user has access.
+ − 274
if ( ! xs ( recid_to_domid ( $id )))
+ − 275
{
+ − 276
error ( ERR_RECORD_ACCESS_DENIED );
+ − 277
}
+ − 278
+ − 279
// Retrieve the type of record to see if we can actually remove it.
+ − 280
$recordtype = get_recordtype_from_id ( $id );
+ − 281
+ − 282
// If the record type is NS and the user tries to delete it while ALLOW_NS_EDIT is set to 0
+ − 283
// OR
+ − 284
// check if the name of the record isnt the domain name (if so it should delete all records)
+ − 285
// OR
+ − 286
// check if we are dealing with a SOA field (same story as NS)
+ − 287
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 ))
+ − 288
{
+ − 289
error ( sprintf ( ERR_RECORD_DELETE_TYPE_DENIED , $recordtype ));
+ − 290
+ − 291
}
+ − 292
if ( is_numeric ( $id ))
+ − 293
{
+ − 294
$did = recid_to_domid ( $id );
+ − 295
$db -> query ( 'DELETE FROM records WHERE id=' . $id . ' LIMIT 1' );
+ − 296
if ( $type != 'SOA' )
+ − 297
{
+ − 298
update_soa_serial ( $did );
+ − 299
}
+ − 300
// $id doesnt exist in database anymore so its deleted or just not there which means "true"
+ − 301
return true ;
+ − 302
}
+ − 303
else
+ − 304
{
+ − 305
error ( sprintf ( ERR_INV_ARG , "delete_record" ));
+ − 306
}
+ − 307
}
+ − 308
+ − 309
+ − 310
/*
+ − 311
* Add a domain to the database.
+ − 312
* A domain is name obligatory, so is an owner.
+ − 313
* return values: true when succesful.
+ − 314
* Empty means templates dont have to be applied.
+ − 315
* --------------------------------------------------------------------------
+ − 316
* This functions eats a template and by that it inserts various records.
+ − 317
* first we start checking if something in an arpa record
+ − 318
* remember to request nextID's from the database to be able to insert record.
+ − 319
* if anything is invalid the function will error
+ − 320
*/
13
+ − 321
function add_domain ( $domain , $owner , $webip , $mailip , $empty , $type , $slave_master )
1
+ − 322
{
+ − 323
+ − 324
global $db ;
+ − 325
+ − 326
if ( ! level ( 5 ))
+ − 327
{
+ − 328
error ( ERR_LEVEL_5 );
+ − 329
}
+ − 330
+ − 331
// If domain, owner and mailip are given
+ − 332
// OR
+ − 333
// empty is given and owner and domain
+ − 334
// OR
+ − 335
// the domain is an arpa record and owner is given
13
+ − 336
// OR
+ − 337
// the type is slave, domain, owner and slave_master are given
1
+ − 338
// THAN
+ − 339
// Continue this function
13
+ − 340
if (( $domain && $owner && $webip && $mailip ) || ( $empty && $owner && $domain ) || ( eregi ( 'in-addr.arpa' , $domain ) && $owner ) || $type == "SLAVE" && $domain && $owner && $slave_master )
1
+ − 341
{
8
+ − 342
// First insert zone into domain table
+ − 343
$db -> query ( "INSERT INTO domains (name, type) VALUES (' $domain ', ' $type ')" );
1
+ − 344
8
+ − 345
// Determine id of insert zone (in other words, find domain_id)
+ − 346
$iddomain = $db -> lastInsertId ( 'domains' , 'id' );
+ − 347
if ( PEAR :: isError ( $iddomain )) {
+ − 348
die ( $id -> getMessage ());
+ − 349
}
1
+ − 350
8
+ − 351
// Second, insert into zones tables
+ − 352
$db -> query ( "INSERT INTO zones (domain_id, owner) VALUES (' $iddomain ', $owner )" );
1
+ − 353
13
+ − 354
if ( $type == "SLAVE" )
1
+ − 355
{
13
+ − 356
$db -> query ( "UPDATE domains SET master = ' $slave_master ' WHERE id = ' $iddomain ';" );
+ − 357
+ − 358
// Done
+ − 359
return true ;
+ − 360
}
+ − 361
else
+ − 362
{
+ − 363
// Generate new timestamp. We need this one anyhow.
+ − 364
$now = time ();
1
+ − 365
13
+ − 366
if ( $empty && $iddomain )
+ − 367
{
+ − 368
// If we come into this if statement we dont want to apply templates.
+ − 369
// Retrieve configuration settings.
+ − 370
$ns1 = $GLOBALS [ "NS1" ];
+ − 371
$hm = $GLOBALS [ "HOSTMASTER" ];
+ − 372
$ttl = $GLOBALS [ "DEFAULT_TTL" ];
1
+ − 373
13
+ − 374
// Build and execute query
+ − 375
$sql = "INSERT INTO records (domain_id, name, content, type, ttl, prio, change_date) VALUES (' $iddomain ', ' $domain ', ' $ns1 $hm 1', 'SOA', $ttl , '', ' $now ')" ;
+ − 376
$db -> query ( $sql );
1
+ − 377
13
+ − 378
// Done
+ − 379
return true ;
+ − 380
}
+ − 381
elseif ( $iddomain )
1
+ − 382
{
13
+ − 383
// If we are here we want to apply templates.
+ − 384
global $template ;
+ − 385
+ − 386
// Iterate over the template and apply it for each field.
+ − 387
foreach ( $template as $r )
1
+ − 388
{
13
+ − 389
// Same type of if statement as previous.
+ − 390
if (( eregi ( 'in-addr.arpa' , $domain ) && ( $r [ "type" ] == "NS" || $r [ "type" ] == "SOA" )) || ( ! eregi ( 'in-addr.arpa' , $domain )))
1
+ − 391
{
13
+ − 392
// Parse the template.
+ − 393
$name = parse_template_value ( $r [ "name" ], $domain , $webip , $mailip );
+ − 394
$type = $r [ "type" ];
+ − 395
$content = parse_template_value ( $r [ "content" ], $domain , $webip , $mailip );
+ − 396
$ttl = $r [ "ttl" ];
+ − 397
$prio = $r [ "prio" ];
1
+ − 398
13
+ − 399
// If no ttl is given, use the default.
+ − 400
if ( ! $ttl )
+ − 401
{
+ − 402
$ttl = $GLOBALS [ "DEFAULT_TTL" ];
+ − 403
}
+ − 404
+ − 405
$sql = "INSERT INTO records (domain_id, name, content, type, ttl, prio, change_date) VALUES (' $iddomain ', ' $name ',' $content ',' $type ',' $ttl ',' $prio ',' $now ')" ;
+ − 406
$db -> query ( $sql );
+ − 407
}
1
+ − 408
}
13
+ − 409
// All done.
+ − 410
return true ;
+ − 411
}
+ − 412
else
+ − 413
{
+ − 414
error ( sprintf ( ERR_INV_ARGC , "add_domain" , "could not create zone" ));
+ − 415
}
+ − 416
}
1
+ − 417
}
+ − 418
else
+ − 419
{
+ − 420
error ( sprintf ( ERR_INV_ARG , "add_domain" ));
+ − 421
}
+ − 422
}
+ − 423
+ − 424
+ − 425
/*
+ − 426
* Deletes a domain by a given id.
+ − 427
* Function always succeeds. If the field is not found in the database, thats what we want anyway.
+ − 428
*/
+ − 429
function delete_domain ( $id )
+ − 430
{
+ − 431
global $db ;
+ − 432
+ − 433
if ( ! level ( 5 ))
+ − 434
{
+ − 435
error ( ERR_LEVEL_5 );
+ − 436
}
+ − 437
+ − 438
// See if the ID is numeric.
+ − 439
if ( is_numeric ( $id ))
+ − 440
{
+ − 441
$db -> query ( "DELETE FROM zones WHERE domain_id= $id " );
+ − 442
$db -> query ( "DELETE FROM domains WHERE id= $id " );
+ − 443
$db -> query ( "DELETE FROM records WHERE domain_id= $id " );
+ − 444
// Nothing in the database. If the delete deleted 0 records it means the id is just not there.
+ − 445
// therefore the is no need to check the affectedRows values.
+ − 446
return true ;
+ − 447
}
+ − 448
else
+ − 449
{
+ − 450
error ( sprintf ( ERR_INV_ARGC , "delete_domain" , "id must be a number" ));
+ − 451
}
+ − 452
}
+ − 453
+ − 454
+ − 455
/*
+ − 456
* Gets the id of the domain by a given record id.
+ − 457
* return values: the domain id that was requested.
+ − 458
*/
+ − 459
function recid_to_domid ( $id )
+ − 460
{
+ − 461
global $db ;
+ − 462
if ( is_numeric ( $id ))
+ − 463
{
+ − 464
$result = $db -> query ( "SELECT domain_id FROM records WHERE id= $id " );
+ − 465
$r = $result -> fetchRow ();
+ − 466
return $r [ "domain_id" ];
+ − 467
}
+ − 468
else
+ − 469
{
+ − 470
error ( sprintf ( ERR_INV_ARGC , "recid_to_domid" , "id must be a number" ));
+ − 471
}
+ − 472
}
+ − 473
+ − 474
+ − 475
/*
+ − 476
* Sorts a zone by records.
+ − 477
* return values: the sorted zone.
+ − 478
*/
+ − 479
function sort_zone ( $records )
+ − 480
{
+ − 481
$ar_so = array ();
+ − 482
$ar_ns = array ();
+ − 483
$ar_mx = array ();
+ − 484
$ar_mb = array ();
+ − 485
$ar_ur = array ();
+ − 486
$ar_ov = array ();
+ − 487
foreach ( $records as $c )
+ − 488
{
+ − 489
switch ( strtoupper ( $c [ 'type' ]))
+ − 490
{
+ − 491
case "SOA" :
+ − 492
$ar_so [] = $c ;
+ − 493
break ;
+ − 494
case "NS" :
+ − 495
$ar_ns [] = $c ;
+ − 496
break ;
+ − 497
case "MX" :
+ − 498
$ar_mx [] = $c ;
+ − 499
break ;
+ − 500
case "MBOXFW" :
+ − 501
$ar_mb [] = $c ;
+ − 502
break ;
+ − 503
case "URL" :
+ − 504
$ar_ur [] = $c ;
+ − 505
break ;
+ − 506
default :
+ − 507
$ar_ov [] = $c ;
+ − 508
break ;
+ − 509
}
+ − 510
}
+ − 511
+ − 512
$res = array_merge ( $ar_so , $ar_ns , $ar_mx , $ar_mb , $ar_ur , $ar_ov );
+ − 513
+ − 514
if ( count ( $records ) == count ( $res ))
+ − 515
{
+ − 516
$records = $res ;
+ − 517
}
+ − 518
else
+ − 519
{
+ − 520
error ( sprintf ( ERR_INV_ARGC , "sort_zone" , "records sorting failed!" ));
+ − 521
}
+ − 522
return $records ;
+ − 523
}
+ − 524
+ − 525
+ − 526
/*
+ − 527
* Change owner of a domain.
+ − 528
* Function should actually be in users.inc.php. But its more of a record modification than a user modification
+ − 529
* return values: true when succesful.
+ − 530
*/
+ − 531
function add_owner ( $domain , $newowner )
+ − 532
{
+ − 533
global $db ;
+ − 534
+ − 535
if ( ! level ( 5 ))
+ − 536
{
+ − 537
error ( ERR_LEVEL_5 );
+ − 538
}
+ − 539
+ − 540
if ( is_numeric ( $domain ) && is_numeric ( $newowner ) && is_valid_user ( $newowner ))
+ − 541
{
8
+ − 542
if ( $db -> queryOne ( "SELECT COUNT(id) FROM zones WHERE owner= $newowner AND domain_id= $domain " ) == 0 )
1
+ − 543
{
8
+ − 544
$db -> query ( "INSERT INTO zones (domain_id, owner) VALUES( $domain , $newowner )" );
1
+ − 545
}
+ − 546
return true ;
+ − 547
}
+ − 548
else
+ − 549
{
+ − 550
error ( sprintf ( ERR_INV_ARGC , "change_owner" , " $domain / $newowner " ));
+ − 551
}
+ − 552
}
+ − 553
+ − 554
+ − 555
function delete_owner ( $domain , $owner )
+ − 556
{
+ − 557
global $db ;
8
+ − 558
if ( $db -> queryOne ( "SELECT COUNT(id) FROM zones WHERE owner= $owner AND domain_id= $domain " ) != 0 )
1
+ − 559
{
+ − 560
$db -> query ( "DELETE FROM zones WHERE owner= $owner AND domain_id= $domain " );
+ − 561
}
+ − 562
return true ;
+ − 563
}
+ − 564
+ − 565
/*
+ − 566
* Retrieves all supported dns record types
+ − 567
* This function might be deprecated.
+ − 568
* return values: array of types in string form.
+ − 569
*/
+ − 570
function get_record_types ()
+ − 571
{
+ − 572
global $rtypes ;
+ − 573
return $rtypes ;
+ − 574
}
+ − 575
+ − 576
+ − 577
/*
+ − 578
* Retrieve all records by a given type and domain id.
+ − 579
* Example: get all records that are of type A from domain id 1
+ − 580
* return values: a DB class result object
+ − 581
*/
+ − 582
function get_records_by_type_from_domid ( $type , $recid )
+ − 583
{
+ − 584
global $rtypes ;
+ − 585
global $db ;
+ − 586
+ − 587
// Does this type exist?
+ − 588
if ( ! in_array ( strtoupper ( $type ), $rtypes ))
+ − 589
{
+ − 590
error ( sprintf ( ERR_INV_ARGC , "get_records_from_type" , "this is not a supported record" ));
+ − 591
}
+ − 592
+ − 593
// Get the domain id.
+ − 594
$domid = recid_to_domid ( $recid );
+ − 595
+ − 596
$result = $db -> query ( "select id, type from records where domain_id= $recid and type=' $type '" );
+ − 597
return $result ;
+ − 598
}
+ − 599
+ − 600
+ − 601
/*
+ − 602
* Retrieves the type of a record from a given id.
+ − 603
* return values: the type of the record (one of the records types in $rtypes assumable).
+ − 604
*/
+ − 605
function get_recordtype_from_id ( $id )
+ − 606
{
+ − 607
global $db ;
+ − 608
if ( is_numeric ( $id ))
+ − 609
{
+ − 610
$result = $db -> query ( "SELECT type FROM records WHERE id= $id " );
+ − 611
$r = $result -> fetchRow ();
+ − 612
return $r [ "type" ];
+ − 613
}
+ − 614
else
+ − 615
{
+ − 616
error ( sprintf ( ERR_INV_ARG , "get_recordtype_from_id" ));
+ − 617
}
+ − 618
}
+ − 619
+ − 620
+ − 621
/*
+ − 622
* Retrieves the name (e.g. bla.test.com) of a record by a given id.
+ − 623
* return values: the name associated with the id.
+ − 624
*/
+ − 625
function get_name_from_record_id ( $id )
+ − 626
{
+ − 627
global $db ;
+ − 628
if ( is_numeric ( $id ))
+ − 629
{
+ − 630
$result = $db -> query ( "SELECT name FROM records WHERE id= $id " );
+ − 631
$r = $result -> fetchRow ();
+ − 632
return $r [ "name" ];
+ − 633
}
+ − 634
else
+ − 635
{
+ − 636
error ( sprintf ( ERR_INV_ARG , "get_name_from_record_id" ));
+ − 637
}
+ − 638
}
+ − 639
+ − 640
+ − 641
/*
+ − 642
* Get all the domains from a database of which the user is the owner.
+ − 643
* return values: an array with the id of the domain and its name.
+ − 644
*/
+ − 645
function get_domains_from_userid ( $id )
+ − 646
{
+ − 647
global $db ;
+ − 648
if ( is_numeric ( $id ))
+ − 649
{
+ − 650
$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 " );
+ − 651
+ − 652
$ret = array ();
+ − 653
+ − 654
// Put all the information in a big array.
+ − 655
while ( $r = $result -> fetchRow ())
+ − 656
{
+ − 657
$ret [] = array (
+ − 658
"id" => $r [ "domain_id" ],
+ − 659
"name" => $r [ "name" ]
+ − 660
);
+ − 661
}
+ − 662
return $ret ;
+ − 663
}
+ − 664
else
+ − 665
{
+ − 666
error ( sprintf ( ERR_INV_ARGC , "get_domains_from_userid" , "This is not a valid userid: $id " ));
+ − 667
}
+ − 668
}
+ − 669
+ − 670
+ − 671
/*
+ − 672
* Get domain name from a given id
+ − 673
* return values: the name of the domain associated with the id.
+ − 674
*/
+ − 675
function get_domain_name_from_id ( $id )
+ − 676
{
+ − 677
global $db ;
+ − 678
if ( ! xs ( $id ))
+ − 679
{
+ − 680
error ( ERR_RECORD_ACCESS_DENIED );
+ − 681
}
+ − 682
if ( is_numeric ( $id ))
+ − 683
{
+ − 684
$result = $db -> query ( "SELECT name FROM domains WHERE id= $id " );
+ − 685
if ( $result -> numRows () == 1 )
+ − 686
{
+ − 687
$r = $result -> fetchRow ();
+ − 688
return $r [ "name" ];
+ − 689
}
+ − 690
else
+ − 691
{
+ − 692
error ( sprintf ( ERR_INV_ARGC , "get_domain_name_from_id" , "more than one domain found?! whaaa! BAD! BAD! Contact admin!" ));
+ − 693
}
+ − 694
}
+ − 695
else
+ − 696
{
+ − 697
error ( sprintf ( ERR_INV_ARGC , "get_domain_name_from_id" , "Not a valid domainid: $id " ));
+ − 698
}
+ − 699
}
+ − 700
+ − 701
+ − 702
/*
+ − 703
* Get information about a domain name from a given domain id.
+ − 704
* the function looks up the domainname, the owner of the domain and the number of records in it.
+ − 705
* return values: an array containing the information.
+ − 706
*/
+ − 707
function get_domain_info_from_id ( $id )
+ − 708
{
+ − 709
global $db ;
+ − 710
if ( ! xs ( $id ))
+ − 711
{
+ − 712
error ( ERR_RECORD_ACCESS_DENIED );
+ − 713
}
+ − 714
if ( is_numeric ( $id ))
+ − 715
{
+ − 716
+ − 717
if ( $_SESSION [ $id . "_ispartial" ] == 1 ) {
+ − 718
13
+ − 719
$sqlq = "SELECT
+ − 720
domains.type AS type,
+ − 721
domains.name AS name,
1
+ − 722
users.fullname AS owner,
+ − 723
count(record_owners.id) AS aantal
+ − 724
FROM domains, users, record_owners, records
+ − 725
+ − 726
WHERE record_owners.user_id = " . $_SESSION [ "userid" ] . "
+ − 727
AND record_owners.record_id = records.id
+ − 728
AND records.domain_id = " . $id . "
+ − 729
+ − 730
GROUP BY name, owner, users.fullname
+ − 731
ORDER BY name" ;
+ − 732
8
+ − 733
$result = $db -> queryRow ( $sqlq );
1
+ − 734
+ − 735
$ret = array (
+ − 736
"name" => $result [ "name" ],
+ − 737
"ownerid" => $_SESSION [ "userid" ],
+ − 738
"owner" => $result [ "owner" ],
13
+ − 739
"type" => $result [ "type" ],
1
+ − 740
"numrec" => $result [ "aantal" ]
+ − 741
);
+ − 742
+ − 743
return $ret ;
+ − 744
+ − 745
} else {
+ − 746
+ − 747
// Query that retrieves the information we need.
13
+ − 748
$sqlq = "SELECT
+ − 749
domains.type AS type,
+ − 750
domains.name AS name,
1
+ − 751
min(zones.owner) AS ownerid,
+ − 752
users.fullname AS owner,
+ − 753
count(records.domain_id) AS aantal
+ − 754
FROM domains
+ − 755
LEFT JOIN records ON domains.id=records.domain_id
+ − 756
LEFT JOIN zones ON domains.id=zones.domain_id
+ − 757
LEFT JOIN users ON zones.owner=users.id
+ − 758
WHERE domains.id= $id
+ − 759
GROUP BY name, owner, users.fullname
+ − 760
ORDER BY zones.id" ;
+ − 761
+ − 762
// Put the first occurence in an array and return it.
8
+ − 763
$result = $db -> queryRow ( $sqlq );
1
+ − 764
8
+ − 765
//$result["ownerid"] = ($result["ownerid"] == NULL) ? $db->queryOne("select min(id) from users where users.level=10") : $result["ownerid"];
1
+ − 766
+ − 767
$ret = array (
+ − 768
"name" => $result [ "name" ],
+ − 769
"ownerid" => $result [ "ownerid" ],
+ − 770
"owner" => $result [ "owner" ],
13
+ − 771
"type" => $result [ "type" ],
1
+ − 772
"numrec" => $result [ "aantal" ]
+ − 773
);
+ − 774
return $ret ;
+ − 775
}
+ − 776
+ − 777
}
+ − 778
else
+ − 779
{
+ − 780
error ( sprintf ( ERR_INV_ARGC , "get_domain_num_records_from_id" , "This is not a valid domainid: $id " ));
+ − 781
}
+ − 782
}
+ − 783
+ − 784
+ − 785
/*
+ − 786
* Check if a domain is already existing.
+ − 787
* return values: true if existing, false if it doesnt exist.
+ − 788
*/
+ − 789
function domain_exists ( $domain )
+ − 790
{
+ − 791
global $db ;
+ − 792
+ − 793
if ( ! level ( 5 ))
+ − 794
{
+ − 795
error ( ERR_LEVEL_5 );
+ − 796
}
+ − 797
if ( is_valid_domain ( $domain ))
+ − 798
{
+ − 799
$result = $db -> query ( "SELECT id FROM domains WHERE name=' $domain '" );
+ − 800
if ( $result -> numRows () == 0 )
+ − 801
{
+ − 802
return false ;
+ − 803
}
+ − 804
elseif ( $result -> numRows () >= 1 )
+ − 805
{
+ − 806
return true ;
+ − 807
}
+ − 808
}
+ − 809
else
+ − 810
{
+ − 811
error ( ERR_DOMAIN_INVALID );
+ − 812
}
+ − 813
}
+ − 814
13
+ − 815
function get_supermasters ()
+ − 816
{
+ − 817
global $db ;
+ − 818
$result = $db -> query ( "SELECT ip, nameserver, account FROM supermasters" );
+ − 819
$ret = array ();
+ − 820
+ − 821
if ( $result -> numRows () == 0 )
+ − 822
{
+ − 823
return - 1 ;
+ − 824
}
+ − 825
else
+ − 826
{
+ − 827
while ( $r = $result -> fetchRow ())
+ − 828
{
+ − 829
$ret [] = array (
+ − 830
"master_ip" => $r [ "ip" ],
+ − 831
"ns_name" => $r [ "nameserver" ],
+ − 832
"account" => $r [ "account" ],
+ − 833
);
+ − 834
return $ret ;
+ − 835
}
+ − 836
}
+ − 837
}
+ − 838
+ − 839
function supermaster_exists ( $master_ip )
+ − 840
{
+ − 841
global $db ;
+ − 842
if ( ! level ( 5 ))
+ − 843
{
+ − 844
error ( ERR_LEVEL_5 );
+ − 845
}
+ − 846
if ( is_valid_ip ( $master_ip ) || is_valid_ip6 ( $master_ip ))
+ − 847
{
+ − 848
$result = $db -> query ( "SELECT ip FROM supermasters WHERE ip = ' $master_ip '" );
+ − 849
if ( $result -> numRows () == 0 )
+ − 850
{
+ − 851
return false ;
+ − 852
}
+ − 853
elseif ( $result -> numRows () >= 1 )
+ − 854
{
+ − 855
return true ;
+ − 856
}
+ − 857
}
+ − 858
else
+ − 859
{
+ − 860
error ( sprintf ( ERR_INV_ARGC , "supermaster_exists" , "No or no valid IPv4 or IPv6 address given." ));
+ − 861
}
+ − 862
}
+ − 863
1
+ − 864
+ − 865
/*
13
+ − 866
* Get all domains from the database
1
+ − 867
* This function gets all the domains from the database unless a user id is below 5.
+ − 868
* if a user id is below 5 this function will only retrieve records for that user.
+ − 869
* return values: the array of domains or -1 if nothing is found.
+ − 870
*/
+ − 871
function get_domains ( $userid = true , $letterstart = all , $rowstart = 0 , $rowamount = 999999 )
+ − 872
{
+ − 873
global $db ;
+ − 874
if (( ! level ( 5 ) || ! $userid ) && ! level ( 10 ) && ! level ( 5 ))
+ − 875
{
+ − 876
$add = " AND zones.owner=" . $_SESSION [ "userid" ];
+ − 877
}
+ − 878
else
+ − 879
{
+ − 880
$add = "" ;
+ − 881
}
+ − 882
+ − 883
$sqlq = "SELECT domains.id AS domain_id,
+ − 884
min(zones.owner) AS owner,
+ − 885
count(DISTINCT records.id) AS aantal,
+ − 886
domains.name AS domainname
+ − 887
FROM domains
+ − 888
LEFT JOIN zones ON domains.id=zones.domain_id
+ − 889
LEFT JOIN records ON records.domain_id=domains.id
+ − 890
WHERE 1 $add " ;
+ − 891
if ( $letterstart != all && $letterstart != 1 ) {
21
+ − 892
$sqlq .= " AND substring(domains.name,1,1) REGEXP '^" . $letterstart . "' " ;
1
+ − 893
} elseif ( $letterstart == 1 ) {
21
+ − 894
$sqlq .= " AND substring(domains.name,1,1) REGEXP '^[[:digit:]]'" ;
1
+ − 895
}
+ − 896
$sqlq .= " GROUP BY domainname, domain_id
+ − 897
ORDER BY domainname
+ − 898
LIMIT $rowstart , $rowamount " ;
+ − 899
+ − 900
$result = $db -> query ( $sqlq );
21
+ − 901
$result2 = $db -> query ( $sqlq );
+ − 902
+ − 903
$numrows = $result2 -> numRows ();
+ − 904
$i = 1 ;
+ − 905
if ( $numrows > 0 ) {
+ − 906
$andnot = " AND NOT domains.id IN (" ;
+ − 907
while ( $r = $result2 -> fetchRow ()) {
+ − 908
$andnot .= $r [ "domain_id" ];
+ − 909
if ( $i < $numrows ) {
+ − 910
$andnot .= "," ;
+ − 911
$i ++ ;
+ − 912
}
+ − 913
}
+ − 914
$andnot .= ")" ;
+ − 915
}
+ − 916
else
+ − 917
{
+ − 918
$andnot = "" ;
1
+ − 919
}
+ − 920
21
+ − 921
if ( $letterstart != all && $letterstart != 1 ) {
1
+ − 922
21
+ − 923
$sqlq = "SELECT domains.id AS domain_id,
+ − 924
count(DISTINCT record_owners.record_id) AS aantal,
+ − 925
domains.name AS domainname
+ − 926
FROM domains, record_owners,records, zones
+ − 927
WHERE record_owners.user_id = '" . $_SESSION [ "userid" ] . "'
+ − 928
AND (records.id = record_owners.record_id
+ − 929
AND domains.id = records.domain_id)
+ − 930
$andnot
+ − 931
AND domains.name LIKE '" . $letterstart . "%'
+ − 932
AND (zones.domain_id != records.domain_id AND zones.owner!='" . $_SESSION [ "userid" ] . "')
+ − 933
GROUP BY domainname, domain_id
+ − 934
ORDER BY domainname" ;
1
+ − 935
21
+ − 936
$result_extra = $db -> query ( $sqlq );
1
+ − 937
21
+ − 938
} else {
1
+ − 939
21
+ − 940
$sqlq = "SELECT domains.id AS domain_id,
+ − 941
count(DISTINCT record_owners.record_id) AS aantal,
+ − 942
domains.name AS domainname
+ − 943
FROM domains, record_owners,records, zones
+ − 944
WHERE record_owners.user_id = '" . $_SESSION [ "userid" ] . "'
+ − 945
AND (records.id = record_owners.record_id
+ − 946
AND domains.id = records.domain_id)
+ − 947
$andnot
+ − 948
AND substring(domains.name,1,1) REGEXP '^[[:digit:]]'
+ − 949
AND (zones.domain_id != records.domain_id AND zones.owner!='" . $_SESSION [ "userid" ] . "')
+ − 950
GROUP BY domainname, domain_id
+ − 951
ORDER BY domainname" ;
1
+ − 952
21
+ − 953
$result_extra [ $i ] = $db -> query ( $sqlq );
+ − 954
1
+ − 955
}
+ − 956
+ − 957
while ( $r = $result -> fetchRow ())
+ − 958
{
8
+ − 959
$r [ "owner" ] = ( $r [ "owner" ] == NULL ) ? $db -> queryOne ( "select min(id) from users where users.level=10" ) : $r [ "owner" ];
1
+ − 960
$ret [ $r [ "domainname" ]] = array (
+ − 961
"name" => $r [ "domainname" ],
+ − 962
"id" => $r [ "domain_id" ],
+ − 963
"owner" => $r [ "owner" ],
+ − 964
"numrec" => $r [ "aantal" ]
+ − 965
);
+ − 966
}
+ − 967
+ − 968
21
+ − 969
if ( $letterstart != all && $letterstart != 1 ) {
1
+ − 970
21
+ − 971
while ( $r = $result_extra -> fetchRow ())
+ − 972
{
+ − 973
$ret [ $r [ "domainname" ]] = array (
+ − 974
"name" => $r [ "domainname" ] . "*" ,
+ − 975
"id" => $r [ "domain_id" ],
+ − 976
"owner" => $_SESSION [ "userid" ],
+ − 977
"numrec" => $r [ "aantal" ]
+ − 978
);
+ − 979
$_SESSION [ "partial_" . $r [ "domainname" ]] = 1 ;
+ − 980
}
1
+ − 981
21
+ − 982
} else {
1
+ − 983
21
+ − 984
foreach ( $result_extra as $result_e ) {
+ − 985
while ( $r = $result_e -> fetchRow ())
+ − 986
{
+ − 987
$ret [ $r [ "domainname" ]] = array (
+ − 988
"name" => $r [ "domainname" ] . "*" ,
+ − 989
"id" => $r [ "domain_id" ],
+ − 990
"owner" => $_SESSION [ "userid" ],
+ − 991
"numrec" => $r [ "aantal" ]
+ − 992
);
+ − 993
$_SESSION [ "partial_" . $r [ "domainname" ]] = 1 ;
+ − 994
}
+ − 995
}
+ − 996
1
+ − 997
}
+ − 998
21
+ − 999
if ( empty ( $ret )) {
+ − 1000
return - 1 ;
+ − 1001
} else {
+ − 1002
sort ( $ret );
+ − 1003
return $ret ;
+ − 1004
}
1
+ − 1005
+ − 1006
}
+ − 1007
+ − 1008
+ − 1009
/*
30
+ − 1010
* zone_count
+ − 1011
* Does a select query to count how many zones we have in the database
+ − 1012
*
+ − 1013
* @todo: see whether or not it is possible to add the records
+ − 1014
* @param $userid integer The userid of the current user
+ − 1015
* @return integer the number of zones
+ − 1016
*/
+ − 1017
+ − 1018
function zone_count ( $userid = true , $letterstart = all ) {
+ − 1019
global $db ;
+ − 1020
if (( ! level ( 5 ) || ! $userid ) && ! level ( 10 ) && ! level ( 5 ))
+ − 1021
{
+ − 1022
$add = " AND zones.owner=" . $_SESSION [ "userid" ];
+ − 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
?>