Ticket #2086: manual-dns.patch
| File manual-dns.patch, 16.7 KB (added by blondak, 6 months ago) |
|---|
-
configs/common/database/database.sql
diff -NbBru 1/configs/common/database/database.sql 2/configs/common/database/database.sql
1 2 126 126 ('PREVENT_EXTERNAL_LOGIN_ADMIN', '1'), 127 127 ('PREVENT_EXTERNAL_LOGIN_RESELLER', '1'), 128 128 ('PREVENT_EXTERNAL_LOGIN_CLIENT', '1'), 129 ('DATABASE_REVISION', '4 5');129 ('DATABASE_REVISION', '46'); 130 130 131 131 -- -------------------------------------------------------- 132 132 … … 211 211 `domain_type` enum('A','AAAA','CERT','CNAME','DNAME','GPOS','KEY','KX','MX','NAPTR','NSAP','NS','NXT','PTR','PX','SIG','SRV','TXT') collate utf8_unicode_ci NOT NULL default 'A', 212 212 `domain_text` varchar(128) collate utf8_unicode_ci NOT NULL, 213 213 `protected` varchar(3) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no', 214 `domain_dns_status` VARCHAR(255) COLLATE utf8_unicode_ci, 214 215 PRIMARY KEY (`domain_dns_id`), 215 216 UNIQUE KEY `domain_id` (`domain_id`,`alias_id`,`domain_dns`,`domain_class`,`domain_type`,`domain_text`) 216 217 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -
engine/ispcp-als-mngr
diff -NbBru 1/engine/ispcp-als-mngr 2/engine/ispcp-als-mngr
1 2 58 58 push_el(\@main::el, 'als_mngr_start_up()', 'Starting...'); 59 59 60 60 # checking for master process; 61 $rs = check_master();62 return $rs if ($rs != 0);61 # $rs = check_master(); 62 # return $rs if ($rs != 0); 63 63 64 64 # Let's clear Execution Logs, if any. 65 65 if (-e $main::ispcp_als_mngr_el) { … … 533 533 $rs = getSerialNumber(\$alsName, \$tplDbEntries, \$wrkFile); 534 534 return $rs if ($rs != 0); 535 535 536 # Custom DNS support - Begin537 538 if($alsStatus eq 'dnschange' || $alsStatus eq 'change') {539 540 my $sql = "541 SELECT542 `domain_dns_id`, `domain_id`, `alias_id`, `domain_dns`,543 `domain_text`, `domain_class`, `domain_type`544 FROM545 `domain_dns`546 WHERE547 `domain_dns`.`alias_id` = @${data[0]}548 AND549 `domain_dns`.`domain_id` = @${data[1]}550 ORDER BY551 `domain_dns_id`552 ;553 ";554 555 my $rows;556 557 ($rs, $rows) = doSQL($sql);558 return $rs if ($rs != 0);559 560 if (@$rows > 0) {561 562 # Get needed templates for custom dns entries - Begin563 my ($tplDnsEntryB, $tplDnsEntry, $tplDnsEntryE);564 ($rs, $tplDnsEntryB, $tplDnsEntry, $tplDnsEntryE) = get_tpl(565 "$main::cfg{'CONF_DIR'}/bind/parts", 'db_dns_entry_b.tpl',566 'db_dns_entry.tpl', 'db_dns_entry_e.tpl'567 );568 return $rs if($rs != 0);569 570 my ($dnsEntryBv, $dnsEntryV, $dnsEntryEv, $dnsEntries);571 572 foreach (@$rows) {573 574 # Variables replacement575 ($rs, $dnsEntryBv, $dnsEntryV, $dnsEntryEv) = prep_tpl(576 {577 '{MANUAL_DNS_NAME}' => $_->[3],578 '{MANUAL_DNS_ID}' => $_->[0],579 '{MANUAL_DNS_DATA}' => $_->[4],580 '{MANUAL_DNS_CLASS}' => $_->[5],581 '{MANUAL_DNS_TYPE}' => $_->[6]582 },583 $tplDnsEntryB, $tplDnsEntry, $tplDnsEntryE584 );585 586 # Concatenates custom DNS entries587 $dnsEntries .= "$dnsEntryBv$dnsEntryV$dnsEntryEv\n";588 }589 590 # Put the custom DNS entries in db zone file591 ($rs, $tplDbEntries) = add_tag(592 $tplDnsEntryB, $tplDnsEntryE, $tplDbEntries, $dnsEntries593 );594 return $rs if($rs != 0);595 }596 }597 598 # Custom DNS support - End599 600 536 # Install new domain db file 601 537 foreach("$main::cfg{'CONF_DIR'}/bind/working", $main::cfg{'BIND_DB_DIR'}) { 602 538 $rs = store_file( … … 666 602 667 603 ################################################################################ 668 604 ## 605 ## Handle Manual DNS changes 606 ## 607 ## @param $data Ref to an array that contains domain data 608 ## @access private 609 ## 610 sub _als_dns_change_db_data { 611 612 push_el(\@main::el, '_als_dns_change_db_data()', 'Starting...'); 613 614 my ($data) = @_; 615 my ($alsName) = (@$data[2]); 616 617 if (!defined($data) || $data eq '') { 618 push_el( 619 \@main::el, '_als_dns_change_db_data()', 620 'ERROR: Undefined Input Data...' 621 ); 622 623 return -1; 624 } 625 626 my ($rs, $rows); 627 628 my $sql = " 629 SELECT 630 `domain_dns_id`, `domain_id`, `alias_id`, `domain_dns`, 631 `domain_text`, `domain_class`, `domain_type`, `domain_dns_status` 632 FROM 633 `domain_dns` 634 WHERE 635 `domain_dns`.`alias_id` = @${data[0]} 636 AND `domain_dns`.`domain_id` = @${data[1]} 637 AND `domain_dns`.`domain_dns_status` in ('delete','toadd','change') 638 ORDER BY 639 `domain_dns_id` 640 ; 641 "; 642 643 ($rs, $rows) = doSQL($sql); 644 return $rs if ($rs != 0); 645 646 my ($tplDnsEntryB, $tplDnsEntry, $tplDnsEntryE); 647 ($rs, $tplDnsEntryB, $tplDnsEntry, $tplDnsEntryE) = get_tpl( 648 "$main::cfg{'CONF_DIR'}/bind/parts", 'db_dns_entry_b.tpl', 649 'db_dns_entry.tpl', 'db_dns_entry_e.tpl' 650 ); 651 return $rs if($rs != 0); 652 653 654 if (@$rows > 0) { 655 my $bkp_dir = "$main::cfg{'CONF_DIR'}/bind/backup"; 656 657 my ($dnsEntryBv, $dnsEntryV, $dnsEntryEv, $dnsEntries, $wrkFile); 658 659 ($rs, $wrkFile) = get_file("$main::cfg{'CONF_DIR'}/bind/working/$alsName.db"); 660 return $rs if ($rs != 0); 661 662 foreach (@$rows) { 663 ($rs, $dnsEntryBv, $dnsEntryV, $dnsEntryEv) = prep_tpl( 664 { 665 '{MANUAL_DNS_NAME}' => $_->[3], 666 '{MANUAL_DNS_ID}' => $_->[0], 667 '{MANUAL_DNS_DATA}' => $_->[4], 668 '{MANUAL_DNS_CLASS}' => $_->[5], 669 '{MANUAL_DNS_TYPE}' => $_->[6] 670 }, 671 $tplDnsEntryB, $tplDnsEntry, $tplDnsEntryE 672 ); 673 674 if ($_->[7] eq 'delete'){ 675 push_el(\@main::el, '_als_dns_change_db_data()', 'Deleting ...'); 676 677 ($rs, $wrkFile) = del_tag($dnsEntryBv, "$dnsEntryEv\n", $wrkFile); 678 return $rs if ($rs != 0 && $rs != -5); 679 }elsif ($_->[7] eq 'toadd'){ 680 push_el(\@main::el, '_als_dns_change_db_data()', 'Adding ...'); 681 682 ($rs, $wrkFile) = add_tag( 683 $tplDnsEntryB, $tplDnsEntryE, $wrkFile, "$dnsEntryBv$dnsEntryV$dnsEntryEv\n" 684 ); 685 return $rs if ($rs != 0); 686 }elsif ($_->[7] eq 'change'){ 687 push_el(\@main::el, '_als_dns_change_db_data()', 'Changing ...'); 688 689 ($rs, $wrkFile) = repl_tag( 690 $dnsEntryBv, "$dnsEntryEv\n", $wrkFile, "$dnsEntryBv$dnsEntryV$dnsEntryEv\n" 691 ); 692 return $rs if ($rs != 0); 693 } 694 } 695 696 my $cmd = "$main::cfg{'CMD_CP'} -p $main::cfg{'CONF_DIR'}/bind/working/$alsName.db $bkp_dir/$alsName.db" . time; 697 $rs = sys_command_rs($cmd); 698 return $rs if ($rs != 0); 699 700 $rs = getSerialNumber(\$alsName, \$wrkFile, \$wrkFile); 701 return $rs if ($rs != 0); 702 703 foreach("$main::cfg{'CONF_DIR'}/bind/working", $main::cfg{'BIND_DB_DIR'}) { 704 $rs = store_file( 705 "$_/$alsName.db", $wrkFile, $main::cfg{'ROOT_USER'}, 706 $main::cfg{'ROOT_GROUP'}, 0644 707 ); 708 return $rs if($rs != 0); 709 } 710 711 $sql = " 712 DELETE FROM 713 `domain_dns` 714 WHERE 715 `domain_dns`.`alias_id` = @${data[0]} 716 AND `domain_dns`.`domain_id` = @${data[1]} 717 AND `domain_dns`.`domain_dns_status` = 'delete' 718 ; 719 "; 720 ($rs) = doSQL($sql); 721 722 $sql = " 723 UPDATE 724 `domain_dns` 725 SET 726 `domain_dns_status` = 'ok' 727 WHERE 728 `domain_dns`.`alias_id` = @${data[0]} 729 AND `domain_dns`.`domain_id` = @${data[1]} 730 AND `domain_dns`.`domain_dns_status` in ('toadd', 'change') 731 ; 732 "; 733 ($rs) = doSQL($sql); 734 735 } 736 737 push_el(\@main::el, '_als_dns_change_db_data()', 'Ending...'); 738 0; 739 } 740 ################################################################################ 741 ## 669 742 ## Adds all DNS configuration data related to a domain alias 670 743 ## See als_add_named_cfg_data() && _als_add_named_db_data() 671 744 ## … … 3810 3883 return $rs if ($rs != 0); 3811 3884 } elsif ($als_status eq 'dnschange'){ 3812 3885 # changing DNS 3813 $rs = _als_ add_named_db_data($entry);3886 $rs = _als_dns_change_db_data($entry); 3814 3887 3815 3888 $timestamp = time(); 3816 3889 if ($rs == 0) { … … 3840 3913 ($rs, $rdata) = doSQL($sql); 3841 3914 return $rs if ($rs != 0); 3842 3915 3916 $sql = " 3917 DELETE FROM 3918 domain_dns 3919 WHERE 3920 alias_id = $als_id 3921 ; 3922 "; 3923 3924 ($rs, $rdata) = doSQL($sql); 3925 return $rs if ($rs != 0); 3926 3843 3927 } else { 3844 3928 my ($sub_name, $msg) = split(/$main::el_sep/, pop_el(\@main::el)); 3845 3929 -
engine/ispcp-dmn-mngr
diff -NbBru 1/engine/ispcp-dmn-mngr 2/engine/ispcp-dmn-mngr
1 2 330 330 331 331 ################################################################################ 332 332 ## 333 ## Handle Manual DNS changes 334 ## 335 ## @param $data Ref to an array that contains domain data 336 ## @access private 337 ## 338 sub _dmn_dns_change_db_data { 339 340 push_el(\@main::el, '_dmn_dns_change_db_data()', 'Starting...'); 341 342 my ($data) = @_; 343 my ($dmnName) = (@$data[1]); 344 345 if (!defined($data) || $data eq '') { 346 push_el( 347 \@main::el, '_dmn_dns_change_db_data()', 348 'ERROR: Undefined Input Data...' 349 ); 350 351 return -1; 352 } 353 354 my ($rs, $rows); 355 356 my $sql = " 357 SELECT 358 `domain_dns_id`, `domain_id`, `alias_id`, `domain_dns`, 359 `domain_text`, `domain_class`, `domain_type`, `domain_dns_status` 360 FROM 361 `domain_dns` 362 WHERE 363 `domain_dns`.`alias_id` = 0 364 AND `domain_dns`.`domain_id` = @${data[0]} 365 AND `domain_dns`.`domain_dns_status` in ('delete','toadd','change') 366 ORDER BY 367 `domain_dns_id` 368 ; 369 "; 370 371 ($rs, $rows) = doSQL($sql); 372 return $rs if ($rs != 0); 373 374 my ($tplDnsEntryB, $tplDnsEntry, $tplDnsEntryE); 375 ($rs, $tplDnsEntryB, $tplDnsEntry, $tplDnsEntryE) = get_tpl( 376 "$main::cfg{'CONF_DIR'}/bind/parts", 'db_dns_entry_b.tpl', 377 'db_dns_entry.tpl', 'db_dns_entry_e.tpl' 378 ); 379 return $rs if($rs != 0); 380 381 382 if (@$rows > 0) { 383 my $bkp_dir = "$main::cfg{'CONF_DIR'}/bind/backup"; 384 385 my ($dnsEntryBv, $dnsEntryV, $dnsEntryEv, $dnsEntries, $wrkFile); 386 387 ($rs, $wrkFile) = get_file("$main::cfg{'CONF_DIR'}/bind/working/$dmnName.db"); 388 return $rs if ($rs != 0); 389 390 foreach (@$rows) { 391 ($rs, $dnsEntryBv, $dnsEntryV, $dnsEntryEv) = prep_tpl( 392 { 393 '{MANUAL_DNS_NAME}' => $_->[3], 394 '{MANUAL_DNS_ID}' => $_->[0], 395 '{MANUAL_DNS_DATA}' => $_->[4], 396 '{MANUAL_DNS_CLASS}' => $_->[5], 397 '{MANUAL_DNS_TYPE}' => $_->[6] 398 }, 399 $tplDnsEntryB, $tplDnsEntry, $tplDnsEntryE 400 ); 401 402 if ($_->[7] eq 'delete'){ 403 push_el(\@main::el, '_dmn_dns_change_db_data()', 'Deleting ...'); 404 405 ($rs, $wrkFile) = del_tag($dnsEntryBv, "$dnsEntryEv\n", $wrkFile); 406 return $rs if ($rs != 0 && $rs != -5); 407 }elsif ($_->[7] eq 'toadd'){ 408 push_el(\@main::el, '_dmn_dns_change_db_data()', 'Adding ...'); 409 410 ($rs, $wrkFile) = add_tag( 411 $tplDnsEntryB, $tplDnsEntryE, $wrkFile, "$dnsEntryBv$dnsEntryV$dnsEntryEv\n" 412 ); 413 return $rs if ($rs != 0); 414 }elsif ($_->[7] eq 'change'){ 415 push_el(\@main::el, '_dmn_dns_change_db_data()', 'Changing ...'); 416 417 ($rs, $wrkFile) = repl_tag( 418 $dnsEntryBv, "$dnsEntryEv\n", $wrkFile, "$dnsEntryBv$dnsEntryV$dnsEntryEv\n" 419 ); 420 return $rs if ($rs != 0); 421 } 422 } 423 424 my $cmd = "$main::cfg{'CMD_CP'} -p $main::cfg{'CONF_DIR'}/bind/working/$dmnName.db $bkp_dir/$dmnName.db" . time; 425 $rs = sys_command_rs($cmd); 426 return $rs if ($rs != 0); 427 428 $rs = getSerialNumber(\$dmnName, \$wrkFile, \$wrkFile); 429 return $rs if ($rs != 0); 430 431 foreach("$main::cfg{'CONF_DIR'}/bind/working", $main::cfg{'BIND_DB_DIR'}) { 432 $rs = store_file( 433 "$_/$dmnName.db", $wrkFile, $main::cfg{'ROOT_USER'}, 434 $main::cfg{'ROOT_GROUP'}, 0644 435 ); 436 return $rs if($rs != 0); 437 } 438 439 $sql = " 440 DELETE FROM 441 `domain_dns` 442 WHERE 443 `domain_dns`.`alias_id` = 0 444 AND `domain_dns`.`domain_id` = @${data[0]} 445 AND `domain_dns`.`domain_dns_status` = 'delete' 446 ; 447 "; 448 ($rs) = doSQL($sql); 449 450 $sql = " 451 UPDATE 452 `domain_dns` 453 SET 454 `domain_dns_status` = 'ok' 455 WHERE 456 `domain_dns`.`alias_id` = 0 457 AND `domain_dns`.`domain_id` = @${data[0]} 458 AND `domain_dns`.`domain_dns_status` in ('toadd', 'change') 459 ; 460 "; 461 ($rs) = doSQL($sql); 462 463 } 464 465 push_el(\@main::el, '_dmn_dns_change_db_data()', 'Ending...'); 466 0; 467 } 468 469 ################################################################################ 470 ## 333 471 ## Create domain DNS zone file in (eg. /var/cache/bind) 334 472 ## 335 473 ## @param arrayref $data Ref to an array that contains domain data … … 407 545 $rs = getSerialNumber(\$dmnName, \$tplDbEntries, \$wrkFile); 408 546 return $rs if ($rs != 0); 409 547 410 # Custom DNS support - Begin411 412 if($dmnStatus eq 'dnschange' || $dmnStatus eq 'change') {413 414 my $sql = "415 SELECT416 `domain_dns_id`, `domain_id`, `alias_id`, `domain_dns`,417 `domain_text`, `domain_class`, `domain_type`418 FROM419 `domain_dns`420 WHERE421 `domain_dns`.`alias_id` = 0422 AND423 `domain_dns`.`domain_id` = @${data[0]}424 ORDER BY425 `domain_dns_id`426 ;427 ";428 429 my $rows;430 431 ($rs, $rows) = doSQL($sql);432 return $rs if ($rs != 0);433 434 if (@$rows > 0) {435 436 # Get needed templates for custom dns entries - Begin437 my ($tplDnsEntryB, $tplDnsEntry, $tplDnsEntryE);438 ($rs, $tplDnsEntryB, $tplDnsEntry, $tplDnsEntryE) = get_tpl(439 "$main::cfg{'CONF_DIR'}/bind/parts", 'db_dns_entry_b.tpl',440 'db_dns_entry.tpl', 'db_dns_entry_e.tpl'441 );442 return $rs if($rs != 0);443 444 my ($dnsEntryBv, $dnsEntryV, $dnsEntryEv, $dnsEntries);445 446 foreach (@$rows) {447 448 # Variables replacement449 ($rs, $dnsEntryBv, $dnsEntryV, $dnsEntryEv) = prep_tpl(450 {451 '{MANUAL_DNS_NAME}' => $_->[3],452 '{MANUAL_DNS_ID}' => $_->[0],453 '{MANUAL_DNS_DATA}' => $_->[4],454 '{MANUAL_DNS_CLASS}' => $_->[5],455 '{MANUAL_DNS_TYPE}' => $_->[6]456 },457 $tplDnsEntryB, $tplDnsEntry, $tplDnsEntryE458 );459 460 # Concatenates custom DNS entries461 $dnsEntries .= "$dnsEntryBv$dnsEntryV$dnsEntryEv\n";462 }463 464 # Put the custom DNS entries in db zone file465 ($rs, $tplDbEntries) = add_tag(466 $tplDnsEntryB, $tplDnsEntryE, $tplDbEntries, $dnsEntries467 );468 return $rs if($rs != 0);469 }470 }471 472 # Custom DNS support - End473 474 548 # Install new domain db file 475 549 foreach("$main::cfg{'CONF_DIR'}/bind/working", $main::cfg{'BIND_DB_DIR'}) { 476 550 $rs = store_file( … … 4161 4235 } elsif ($dmn_status eq 'dnschange'){ 4162 4236 4163 4237 # Adds custom DNS entry 4164 $rs = _dmn_ add_named_db_data($entry);4238 $rs = _dmn_dns_change_db_data($entry); 4165 4239 4166 4240 if ($rs == 0) { 4167 4241 $sql = " 4168 4242 UPDATE 4169 4243 `domain` 4170 4244 SET 4171 `domain_status` = ' ok'4245 `domain_status` = '$main::after_change_status' 4172 4246 WHERE 4173 4247 `domain_id` = $dmn_id 4174 4248 ; … … 4207 4281 4208 4282 $sql = " 4209 4283 DELETE FROM 4284 `domain_dns` 4285 WHERE 4286 `domain_id` = $dmn_id 4287 ; 4288 "; 4289 4290 ($rs, undef) = doSQL($sql); 4291 return $rs if ($rs != 0); 4292 4293 $sql = " 4294 DELETE FROM 4210 4295 `admin` 4211 4296 WHERE 4212 4297 `admin_id` = $dmn_admin_id -
gui/client/dns_delete.php
diff -NbBru 1/gui/client/dns_delete.php 2/gui/client/dns_delete.php
1 2 73 73 74 74 // Delete DNS record from the database 75 75 $query = " 76 DELETE FROM76 UPDATE 77 77 `domain_dns` 78 SET 79 `domain_dns_status` 78 80 WHERE 79 81 `domain_dns_id` = ? 80 82 ; 81 83 "; 82 84 83 $rs = exec_query($sql, $query, $dns_id );85 $rs = exec_query($sql, $query, $dns_id, $cfg->ITEM_DELETE_STATUS); 84 86 85 87 if (empty($alias_id)) { 86 88 -
gui/client/dns_edit.php
diff -NbBru 1/gui/client/dns_edit.php 2/gui/client/dns_edit.php
1 2 572 572 INSERT INTO 573 573 `domain_dns` ( 574 574 `domain_id`, `alias_id`, `domain_dns`, `domain_class`, 575 `domain_type`, `domain_text` 575 `domain_type`, `domain_text`, `domain_dns_status` 576 576 ) VALUES ( 577 ?, ?, ?, ?, ?, ? 577 ?, ?, ?, ?, ?, ?, ? 578 578 ) 579 579 ; 580 580 "; 581 581 582 582 $rs = exec_query( 583 583 $sql, $query, 584 array($dmn_id, $alias_id, $_dns, $_class, $_type, $_text ),584 array($dmn_id, $alias_id, $_dns, $_class, $_type, $_text, $cfg->ITEM_ADD_STATUS), 585 585 false 586 586 ); 587 587 … … 608 608 `domain_dns` 609 609 SET 610 610 `domain_dns` = ?, `domain_class` = ?, `domain_type` = ?, 611 `domain_text` = ? 611 `domain_text` = ?, `domain_dns_status` = ? 612 612 WHERE 613 613 `domain_dns_id` = ? 614 614 ; 615 615 "; 616 616 617 617 exec_query( 618 $sql, $query, array($_dns, $_class, $_type, $_text, $ edit_id)618 $sql, $query, array($_dns, $_class, $_type, $_text, $cfg->ITEM_CHANGE_STATUS, $edit_id) 619 619 ); 620 620 } 621 621 -
gui/include/ispCP/Update/Database.php
diff -NbBru 1/gui/include/ispCP/Update/Database.php 2/gui/include/ispCP/Update/Database.php
1 2 1855 1855 return $sqlUpd; 1856 1856 } 1857 1857 1858 protected function _databaseUpdate_46(){ 1859 $sqlUpd = array(); 1860 $sqlUpd[] = "ALTER IGNORE TABLE `domain_dns` ADD `domain_dns_status` VARCHAR(255) COLLATE utf8_unicode_ci;"; 1861 $sqlUpd[] = "UPDATE `domain_dns` SET `domain_dns_status` = 'ok';" 1862 return $sqlUpd; 1863 } 1864 1858 1865 /* 1859 1866 * DO NOT CHANGE ANYTHING BELOW THIS LINE! 1860 1867 */
