index.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. ob_start();
  3. $TAB = 'DNS';
  4. // Main include
  5. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  6. // Check domain name
  7. if (empty($_GET['domain'])) {
  8. header("Location: /list/dns/");
  9. exit;
  10. }
  11. // Edit as someone else?
  12. if (($_SESSION['userContext'] === 'admin') && (!empty($_GET['user']))) {
  13. $user=escapeshellarg($_GET['user']);
  14. }
  15. // List ip addresses
  16. exec(HESTIA_CMD."v-list-user-ips ".$user." json", $output, $return_var);
  17. $v_ips = json_decode(implode('', $output), true);
  18. unset($output);
  19. // List dns domain
  20. if ((!empty($_GET['domain'])) && (empty($_GET['record_id']))) {
  21. $v_domain = escapeshellarg($_GET['domain']);
  22. exec(HESTIA_CMD."v-list-dns-domain ".$user." ".$v_domain." json", $output, $return_var);
  23. check_return_code($return_var, $output);
  24. $data = json_decode(implode('', $output), true);
  25. unset($output);
  26. // Parse dns domain
  27. $v_username = $user;
  28. $v_domain = $_GET['domain'];
  29. $v_ip = $data[$v_domain]['IP'];
  30. $v_template = $data[$v_domain]['TPL'];
  31. $v_ttl = $data[$v_domain]['TTL'];
  32. $v_exp = $data[$v_domain]['EXP'];
  33. $v_soa = $data[$v_domain]['SOA'];
  34. $v_date = $data[$v_domain]['DATE'];
  35. $v_time = $data[$v_domain]['TIME'];
  36. $v_suspended = $data[$v_domain]['SUSPENDED'];
  37. if ($v_suspended == 'yes') {
  38. $v_status = 'suspended';
  39. } else {
  40. $v_status = 'active';
  41. }
  42. // List dns templates
  43. exec(HESTIA_CMD."v-list-dns-templates json", $output, $return_var);
  44. $templates = json_decode(implode('', $output), true);
  45. unset($output);
  46. }
  47. // List dns record
  48. if ((!empty($_GET['domain'])) && (!empty($_GET['record_id']))) {
  49. $v_domain = escapeshellarg($_GET['domain']);
  50. $v_record_id = escapeshellarg($_GET['record_id']);
  51. exec(HESTIA_CMD."v-list-dns-records ".$user." ".$v_domain." 'json'", $output, $return_var);
  52. check_return_code($return_var, $output);
  53. $data = json_decode(implode('', $output), true);
  54. unset($output);
  55. // Parse dns record
  56. $v_username = $user;
  57. $v_domain = $_GET['domain'];
  58. $v_record_id = $_GET['record_id'];
  59. $v_rec = $data[$v_record_id]['RECORD'];
  60. $v_type = $data[$v_record_id]['TYPE'];
  61. $v_val = $data[$v_record_id]['VALUE'];
  62. $v_priority = $data[$v_record_id]['PRIORITY'];
  63. $v_suspended = $data[$v_record_id]['SUSPENDED'];
  64. if ($v_suspended == 'yes') {
  65. $v_status = 'suspended';
  66. } else {
  67. $v_status = 'active';
  68. }
  69. $v_date = $data[$v_record_id]['DATE'];
  70. $v_time = $data[$v_record_id]['TIME'];
  71. $v_ttl = $data[$v_record_id]['TTL'];
  72. }
  73. // Check POST request for dns domain
  74. if ((!empty($_POST['save'])) && (!empty($_GET['domain'])) && (empty($_GET['record_id']))) {
  75. $v_domain = escapeshellarg($_POST['v_domain']);
  76. // Check token
  77. verify_csrf($_POST);
  78. // Change domain IP
  79. if (($v_ip != $_POST['v_ip']) && (empty($_SESSION['error_msg']))) {
  80. $v_ip = escapeshellarg($_POST['v_ip']);
  81. exec(HESTIA_CMD."v-change-dns-domain-ip ".$v_username." ".$v_domain." ".$v_ip." 'no'", $output, $return_var);
  82. check_return_code($return_var, $output);
  83. $restart_dns = 'yes';
  84. unset($output);
  85. }
  86. // Change domain template
  87. if (($v_template != $_POST['v_template']) && (empty($_SESSION['error_msg']))) {
  88. $v_template = escapeshellarg($_POST['v_template']);
  89. exec(HESTIA_CMD."v-change-dns-domain-tpl ".$v_username." ".$v_domain." ".$v_template." 'no'", $output, $return_var);
  90. check_return_code($return_var, $output);
  91. unset($output);
  92. $restart_dns = 'yes';
  93. }
  94. // Change SOA record
  95. if (($v_soa != $_POST['v_soa']) && (empty($_SESSION['error_msg']))) {
  96. $v_soa = escapeshellarg($_POST['v_soa']);
  97. exec(HESTIA_CMD."v-change-dns-domain-soa ".$v_username." ".$v_domain." ".$v_soa." 'no'", $output, $return_var);
  98. check_return_code($return_var, $output);
  99. unset($output);
  100. $restart_dns = 'yes';
  101. }
  102. // Change expiriation date
  103. if (($v_exp != $_POST['v_exp']) && (empty($_SESSION['error_msg']))) {
  104. $v_exp = escapeshellarg($_POST['v_exp']);
  105. exec(HESTIA_CMD."v-change-dns-domain-exp ".$v_username." ".$v_domain." ".$v_exp." 'no'", $output, $return_var);
  106. check_return_code($return_var, $output);
  107. unset($output);
  108. }
  109. // Change domain ttl
  110. if (($v_ttl != $_POST['v_ttl']) && (empty($_SESSION['error_msg']))) {
  111. $v_ttl = escapeshellarg($_POST['v_ttl']);
  112. exec(HESTIA_CMD."v-change-dns-domain-ttl ".$v_username." ".$v_domain." ".$v_ttl." 'no'", $output, $return_var);
  113. check_return_code($return_var, $output);
  114. unset($output);
  115. $restart_dns = 'yes';
  116. }
  117. // Restart dns server
  118. if (!empty($restart_dns) && (empty($_SESSION['error_msg']))) {
  119. exec(HESTIA_CMD."v-restart-dns", $output, $return_var);
  120. check_return_code($return_var, $output);
  121. unset($output);
  122. }
  123. // Set success message
  124. if (empty($_SESSION['error_msg'])) {
  125. $_SESSION['ok_msg'] = _('Changes has been saved.');
  126. }
  127. }
  128. // Check POST request for dns record
  129. if ((!empty($_POST['save'])) && (!empty($_GET['domain'])) && (!empty($_GET['record_id']))) {
  130. // Check token
  131. verify_csrf($_POST);
  132. // Protect input
  133. $v_domain = escapeshellarg($_POST['v_domain']);
  134. $v_record_id = escapeshellarg($_POST['v_record_id']);
  135. // Change dns record
  136. if (($v_rec != $_POST['v_rec']) || ($v_type != $_POST['v_type']) || ($v_val != $_POST['v_val']) || ($v_priority != $_POST['v_priority']) || ($v_ttl != $_POST['v_ttl']) && (empty($_SESSION['error_msg']))) {
  137. $v_rec = escapeshellarg($_POST['v_rec']);
  138. $v_type = escapeshellarg($_POST['v_type']);
  139. $v_val = escapeshellarg($_POST['v_val']);
  140. $v_priority = escapeshellarg($_POST['v_priority']);
  141. $v_ttl = escapeshellarg($_POST['v_ttl']);
  142. exec(HESTIA_CMD."v-change-dns-record ".$v_username." ".$v_domain." ".$v_record_id." ".$v_rec." ".$v_type." ".$v_val." ".$v_priority." false ".$v_ttl, $output, $return_var);
  143. check_return_code($return_var, $output);
  144. $v_rec = $_POST['v_rec'];
  145. $v_type = $_POST['v_type'];
  146. $v_val = $_POST['v_val'];
  147. unset($output);
  148. $restart_dns = 'yes';
  149. }
  150. // Change dns record id
  151. if (($_GET['record_id'] != $_POST['v_record_id']) && (empty($_SESSION['error_msg']))) {
  152. $v_old_record_id = escapeshellarg($_GET['record_id']);
  153. exec(HESTIA_CMD."v-change-dns-record-id ".$v_username." ".$v_domain." ".$v_old_record_id." ".$v_record_id, $output, $return_var);
  154. check_return_code($return_var, $output);
  155. unset($output);
  156. $restart_dns = 'yes';
  157. }
  158. // Restart dns server
  159. if (!empty($restart_dns) && (empty($_SESSION['error_msg']))) {
  160. exec(HESTIA_CMD."v-restart-dns", $output, $return_var);
  161. check_return_code($return_var, $output);
  162. unset($output);
  163. }
  164. // Set success message
  165. if (empty($_SESSION['error_msg'])) {
  166. $_SESSION['ok_msg'] = _('Changes has been saved.');
  167. }
  168. // Change url if record id was changed
  169. if ((empty($_SESSION['error_msg'])) && ($_GET['record_id'] != $_POST['v_record_id'])) {
  170. header("Location: /edit/dns/?domain=".$_GET['domain']."&record_id=".$_POST['v_record_id']);
  171. exit;
  172. }
  173. }
  174. // Render page
  175. if (empty($_GET['record_id'])) {
  176. // Display body for dns domain
  177. render_page($user, $TAB, 'edit_dns');
  178. } else {
  179. // Display body for dns record
  180. render_page($user, $TAB, 'edit_dns_rec');
  181. }
  182. // Flush session messages
  183. unset($_SESSION['error_msg']);
  184. unset($_SESSION['ok_msg']);