index.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. $user_plain=htmlentities($_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_redirect($return_var, $output,'/list/dns/');
  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_redirect($return_var, $output,'/list/dns/');
  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 ".$user." ".$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 ".$user." ".$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 ".$user." ".$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 ".$user." ".$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 ".$user." ".$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. // Restart dns server
  129. if (empty($_SESSION['error_msg'])) {
  130. exec(HESTIA_CMD."v-restart-dns", $output, $return_var);
  131. check_return_code($return_var, $output);
  132. unset($output);
  133. }
  134. }
  135. // Check POST request for dns record
  136. if ((!empty($_POST['save'])) && (!empty($_GET['domain'])) && (!empty($_GET['record_id']))) {
  137. // Check token
  138. verify_csrf($_POST);
  139. // Protect input
  140. $v_domain = escapeshellarg($_POST['v_domain']);
  141. $v_record_id = escapeshellarg($_POST['v_record_id']);
  142. // Change dns record
  143. 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']))) {
  144. $v_rec = escapeshellarg($_POST['v_rec']);
  145. $v_type = escapeshellarg($_POST['v_type']);
  146. $v_val = escapeshellarg($_POST['v_val']);
  147. $v_priority = escapeshellarg($_POST['v_priority']);
  148. $v_ttl = escapeshellarg($_POST['v_ttl']);
  149. exec(HESTIA_CMD."v-change-dns-record ".$user." ".$v_domain." ".$v_record_id." ".$v_rec." ".$v_type." ".$v_val." ".$v_priority." yes ".$v_ttl, $output, $return_var);
  150. check_return_code($return_var, $output);
  151. $v_rec = $_POST['v_rec'];
  152. $v_type = $_POST['v_type'];
  153. $v_val = $_POST['v_val'];
  154. unset($output);
  155. $restart_dns = 'yes';
  156. }
  157. // Change dns record id
  158. if (($_GET['record_id'] != $_POST['v_record_id']) && (empty($_SESSION['error_msg']))) {
  159. $v_old_record_id = escapeshellarg($_GET['record_id']);
  160. exec(HESTIA_CMD."v-change-dns-record-id ".$user." ".$v_domain." ".$v_old_record_id." ".$v_record_id, $output, $return_var);
  161. check_return_code($return_var, $output);
  162. unset($output);
  163. $restart_dns = 'yes';
  164. }
  165. // Restart dns server
  166. if (!empty($restart_dns) && (empty($_SESSION['error_msg']))) {
  167. exec(HESTIA_CMD."v-restart-dns", $output, $return_var);
  168. check_return_code($return_var, $output);
  169. unset($output);
  170. }
  171. // Set success message
  172. if (empty($_SESSION['error_msg'])) {
  173. $_SESSION['ok_msg'] = _('Changes has been saved.');
  174. }
  175. // Change url if record id was changed
  176. if ((empty($_SESSION['error_msg'])) && ($_GET['record_id'] != $_POST['v_record_id'])) {
  177. header("Location: /edit/dns/?domain=".$_GET['domain']."&record_id=".$_POST['v_record_id']);
  178. exit;
  179. }
  180. }
  181. // Render page
  182. if (empty($_GET['record_id'])) {
  183. // Display body for dns domain
  184. render_page($user, $TAB, 'edit_dns');
  185. } else {
  186. if(empty($data[$_GET['record_id']])){
  187. header("Location: /list/dns/");
  188. $_SESSION['error_msg'] = _("Unknown record ID");
  189. }
  190. // Display body for dns record
  191. render_page($user, $TAB, 'edit_dns_rec');
  192. }
  193. // Flush session messages
  194. unset($_SESSION['error_msg']);
  195. unset($_SESSION['ok_msg']);