index.php 6.3 KB

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