index.php 7.5 KB

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