index.php 7.6 KB

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