index.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. // Init
  3. error_reporting(NULL);
  4. ob_start();
  5. session_start();
  6. $TAB = 'DNS';
  7. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  8. // Header
  9. include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
  10. // Panel
  11. top_panel($user,$TAB);
  12. if (!empty($_POST['ok'])) {
  13. // Check input
  14. if (empty($_POST['v_domain'])) $errors[] = __('domain');
  15. if (empty($_POST['v_ip'])) $errors[] = __('ip');
  16. // Protect input
  17. $v_domain = preg_replace("/^www./i", "", $_POST['v_domain']);
  18. $v_domain = escapeshellarg($v_domain);
  19. $v_domain = strtolower($v_domain);
  20. $v_ip = escapeshellarg($_POST['v_ip']);
  21. if (!empty($_POST['v_ns1'])) $v_ns1 = escapeshellarg($_POST['v_ns1']);
  22. if (!empty($_POST['v_ns2'])) $v_ns2 = escapeshellarg($_POST['v_ns2']);
  23. if (!empty($_POST['v_ns3'])) $v_ns3 = escapeshellarg($_POST['v_ns3']);
  24. if (!empty($_POST['v_ns4'])) $v_ns4 = escapeshellarg($_POST['v_ns4']);
  25. // Check for errors
  26. if (!empty($errors[0])) {
  27. foreach ($errors as $i => $error) {
  28. if ( $i == 0 ) {
  29. $error_msg = $error;
  30. } else {
  31. $error_msg = $error_msg.", ".$error;
  32. }
  33. }
  34. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  35. } else {
  36. // Add DNS
  37. exec (VESTA_CMD."v-add-dns-domain ".$user." ".$v_domain." ".$v_ip." ".$v_ns1." ".$v_ns2." ".$v_ns3." ".$v_ns4." no", $output, $return_var);
  38. check_return_code($return_var,$output);
  39. unset($output);
  40. // Change Expiriation date
  41. if ((!empty($_POST['v_exp'])) && ($_POST['v_exp'] != date('Y-m-d', strtotime('+1 year')))) {
  42. $v_exp = escapeshellarg($_POST['v_exp']);
  43. exec (VESTA_CMD."v-change-dns-domain-exp ".$user." ".$v_domain." ".$v_exp." no", $output, $return_var);
  44. check_return_code($return_var,$output);
  45. unset($output);
  46. }
  47. // Change TTL
  48. if ((!empty($_POST['v_ttl'])) && ($_POST['v_ttl'] != '14400') && (empty($_SESSION['error_msg']))) {
  49. $v_ttl = escapeshellarg($_POST['v_ttl']);
  50. exec (VESTA_CMD."v-change-dns-domain-ttl ".$user." ".$v_domain." ".$v_ttl." no", $output, $return_var);
  51. check_return_code($return_var,$output);
  52. unset($output);
  53. }
  54. if (empty($_SESSION['error_msg'])) {
  55. $_SESSION['ok_msg'] = __('DNS_DOMAIN_CREATED_OK',$_POST[v_domain],$_POST[v_domain]);
  56. unset($v_domain);
  57. }
  58. if (empty($_SESSION['error_msg'])) {
  59. exec (VESTA_CMD."v-restart-dns", $output, $return_var);
  60. check_return_code($return_var,$output);
  61. unset($output);
  62. }
  63. }
  64. }
  65. // DNS Record
  66. if (!empty($_POST['ok_rec'])) {
  67. // Check input
  68. if (empty($_POST['v_domain'])) $errors[] = 'domain';
  69. if (empty($_POST['v_rec'])) $errors[] = 'record';
  70. if (empty($_POST['v_type'])) $errors[] = 'type';
  71. if (empty($_POST['v_val'])) $errors[] = 'value';
  72. // Protect input
  73. $v_domain = escapeshellarg($_POST['v_domain']);
  74. $v_rec = escapeshellarg($_POST['v_rec']);
  75. $v_type = escapeshellarg($_POST['v_type']);
  76. $v_val = escapeshellarg($_POST['v_val']);
  77. $v_priority = escapeshellarg($_POST['v_priority']);
  78. // Check for errors
  79. if (!empty($errors[0])) {
  80. foreach ($errors as $i => $error) {
  81. if ( $i == 0 ) {
  82. $error_msg = $error;
  83. } else {
  84. $error_msg = $error_msg.", ".$error;
  85. }
  86. }
  87. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  88. } else {
  89. // Add DNS Record
  90. exec (VESTA_CMD."v-add-dns-record ".$user." ".$v_domain." ".$v_rec." ".$v_type." ".$v_val." ".$v_priority, $output, $return_var);
  91. $v_type = $_POST['v_type'];
  92. check_return_code($return_var,$output);
  93. unset($output);
  94. if (empty($_SESSION['error_msg'])) {
  95. $_SESSION['ok_msg'] = __('DNS_RECORD_CREATED_OK',$_POST[v_rec],$_POST[v_domain]);
  96. unset($v_domain);
  97. unset($v_rec);
  98. unset($v_val);
  99. unset($v_priority);
  100. }
  101. }
  102. }
  103. if ((empty($_GET['domain'])) && (empty($_POST['domain']))) {
  104. if ((empty($v_ns1)) && (empty($v_ns2))) {
  105. exec (VESTA_CMD."v-list-user-ns ".$user." json", $output, $return_var);
  106. $nameservers = json_decode(implode('', $output), true);
  107. $v_ns1 = $nameservers[0];
  108. $v_ns2 = $nameservers[1];
  109. $v_ns3 = $nameservers[2];
  110. $v_ns4 = $nameservers[3];
  111. unset($output);
  112. }
  113. if (empty($v_ttl)) $v_ttl = 14400;
  114. if (empty($v_exp)) $v_exp = date('Y-m-d', strtotime('+1 year'));
  115. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns.html');
  116. unset($_SESSION['error_msg']);
  117. unset($_SESSION['ok_msg']);
  118. } else {
  119. $v_domain = $_GET['domain'];
  120. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns_rec.html');
  121. unset($_SESSION['error_msg']);
  122. unset($_SESSION['ok_msg']);
  123. }
  124. // Footer
  125. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');