index.php 6.0 KB

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