index.php 5.5 KB

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