index.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. // Check POST request for dns domain
  9. if (!empty($_POST['ok'])) {
  10. // Check token
  11. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  12. header('location: /login/');
  13. exit();
  14. }
  15. // Check empty fields
  16. if (empty($_POST['v_domain'])) $errors[] = __('domain');
  17. if (empty($_POST['v_ip'])) $errors[] = __('ip');
  18. if (!empty($errors[0])) {
  19. foreach ($errors as $i => $error) {
  20. if ( $i == 0 ) {
  21. $error_msg = $error;
  22. } else {
  23. $error_msg = $error_msg.", ".$error;
  24. }
  25. }
  26. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  27. }
  28. // Protect input
  29. $v_domain = preg_replace("/^www./i", "", $_POST['v_domain']);
  30. $v_domain = escapeshellarg($v_domain);
  31. $v_domain = strtolower($v_domain);
  32. $v_ip = escapeshellarg($_POST['v_ip']);
  33. $v_ns1 = escapeshellarg($_POST['v_ns1']);
  34. $v_ns2 = escapeshellarg($_POST['v_ns2']);
  35. $v_ns3 = escapeshellarg($_POST['v_ns3']);
  36. $v_ns4 = escapeshellarg($_POST['v_ns4']);
  37. $v_ns5 = escapeshellarg($_POST['v_ns5']);
  38. $v_ns6 = escapeshellarg($_POST['v_ns6']);
  39. $v_ns7 = escapeshellarg($_POST['v_ns7']);
  40. $v_ns8 = escapeshellarg($_POST['v_ns8']);
  41. // Add dns domain
  42. if (empty($_SESSION['error_msg'])) {
  43. exec (VESTA_CMD."v-add-dns-domain ".$user." ".$v_domain." ".$v_ip." ".$v_ns1." ".$v_ns2." ".$v_ns3." ".$v_ns4." ".$v_ns5." ".$v_ns6." ".$v_ns7." ".$v_ns8." no", $output, $return_var);
  44. check_return_code($return_var,$output);
  45. unset($output);
  46. }
  47. // Set expiriation date
  48. if (empty($_SESSION['error_msg'])) {
  49. if ((!empty($_POST['v_exp'])) && ($_POST['v_exp'] != date('Y-m-d', strtotime('+1 year')))) {
  50. $v_exp = escapeshellarg($_POST['v_exp']);
  51. exec (VESTA_CMD."v-change-dns-domain-exp ".$user." ".$v_domain." ".$v_exp." no", $output, $return_var);
  52. check_return_code($return_var,$output);
  53. unset($output);
  54. }
  55. }
  56. // Set ttl
  57. if (empty($_SESSION['error_msg'])) {
  58. if ((!empty($_POST['v_ttl'])) && ($_POST['v_ttl'] != '14400') && (empty($_SESSION['error_msg']))) {
  59. $v_ttl = escapeshellarg($_POST['v_ttl']);
  60. exec (VESTA_CMD."v-change-dns-domain-ttl ".$user." ".$v_domain." ".$v_ttl." no", $output, $return_var);
  61. check_return_code($return_var,$output);
  62. unset($output);
  63. }
  64. }
  65. // Restart dns server
  66. if (empty($_SESSION['error_msg'])) {
  67. exec (VESTA_CMD."v-restart-dns", $output, $return_var);
  68. check_return_code($return_var,$output);
  69. unset($output);
  70. }
  71. // Flush field values on success
  72. if (empty($_SESSION['error_msg'])) {
  73. $_SESSION['ok_msg'] = __('DNS_DOMAIN_CREATED_OK',htmlentities($_POST[v_domain]),htmlentities($_POST[v_domain]));
  74. unset($v_domain);
  75. }
  76. }
  77. // Check POST request for dns record
  78. if (!empty($_POST['ok_rec'])) {
  79. // Check token
  80. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  81. header('location: /login/');
  82. exit();
  83. }
  84. // Check empty fields
  85. if (empty($_POST['v_domain'])) $errors[] = 'domain';
  86. if (empty($_POST['v_rec'])) $errors[] = 'record';
  87. if (empty($_POST['v_type'])) $errors[] = 'type';
  88. if (empty($_POST['v_val'])) $errors[] = 'value';
  89. if (!empty($errors[0])) {
  90. foreach ($errors as $i => $error) {
  91. if ( $i == 0 ) {
  92. $error_msg = $error;
  93. } else {
  94. $error_msg = $error_msg.", ".$error;
  95. }
  96. }
  97. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  98. }
  99. // Protect input
  100. $v_domain = escapeshellarg($_POST['v_domain']);
  101. $v_rec = escapeshellarg($_POST['v_rec']);
  102. $v_type = escapeshellarg($_POST['v_type']);
  103. $v_val = escapeshellarg($_POST['v_val']);
  104. $v_priority = escapeshellarg($_POST['v_priority']);
  105. // Add dns record
  106. if (empty($_SESSION['error_msg'])) {
  107. exec (VESTA_CMD."v-add-dns-record ".$user." ".$v_domain." ".$v_rec." ".$v_type." ".$v_val." ".$v_priority, $output, $return_var);
  108. check_return_code($return_var,$output);
  109. unset($output);
  110. $v_type = $_POST['v_type'];
  111. }
  112. // Flush field values on success
  113. if (empty($_SESSION['error_msg'])) {
  114. $_SESSION['ok_msg'] = __('DNS_RECORD_CREATED_OK',htmlentities($_POST[v_rec]),htmlentities($_POST[v_domain]));
  115. unset($v_domain);
  116. unset($v_rec);
  117. unset($v_val);
  118. unset($v_priority);
  119. }
  120. }
  121. // Header
  122. include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
  123. // Panel
  124. top_panel($user,$TAB);
  125. $v_ns1 = str_replace("'", "", $v_ns1);
  126. $v_ns2 = str_replace("'", "", $v_ns2);
  127. $v_ns3 = str_replace("'", "", $v_ns3);
  128. $v_ns4 = str_replace("'", "", $v_ns4);
  129. $v_ns5 = str_replace("'", "", $v_ns5);
  130. $v_ns6 = str_replace("'", "", $v_ns6);
  131. $v_ns7 = str_replace("'", "", $v_ns7);
  132. $v_ns8 = str_replace("'", "", $v_ns8);
  133. // Display body for dns domain
  134. if (empty($_GET['domain'])) {
  135. if (empty($v_ttl)) $v_ttl = 14400;
  136. if (empty($v_exp)) $v_exp = date('Y-m-d', strtotime('+1 year'));
  137. if (empty($v_ns1)) {
  138. exec (VESTA_CMD."v-list-user-ns ".$user." json", $output, $return_var);
  139. $nameservers = json_decode(implode('', $output), true);
  140. $v_ns1 = str_replace("'", "", $nameservers[0]);
  141. $v_ns2 = str_replace("'", "", $nameservers[1]);
  142. $v_ns3 = str_replace("'", "", $nameservers[2]);
  143. $v_ns4 = str_replace("'", "", $nameservers[3]);
  144. $v_ns5 = str_replace("'", "", $nameservers[4]);
  145. $v_ns6 = str_replace("'", "", $nameservers[5]);
  146. $v_ns7 = str_replace("'", "", $nameservers[6]);
  147. $v_ns8 = str_replace("'", "", $nameservers[7]);
  148. unset($output);
  149. }
  150. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns.html');
  151. }
  152. // Display body for dns record
  153. if (!empty($_GET['domain'])) {
  154. $v_domain = $_GET['domain'];
  155. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns_rec.html');
  156. }
  157. // Flush session messages
  158. unset($_SESSION['error_msg']);
  159. unset($_SESSION['ok_msg']);
  160. // Footer
  161. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');