index.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. // Header
  9. include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
  10. // Panel
  11. top_panel($user,$TAB);
  12. if (!empty($_POST['ok'])) {
  13. // Check input
  14. if (empty($_POST['v_domain'])) $errors[] = __('domain');
  15. if (empty($_POST['v_ip'])) $errors[] = __('ip');
  16. // Protect input
  17. $v_domain = preg_replace("/^www./i", "", $_POST['v_domain']);
  18. $v_domain = escapeshellarg($v_domain);
  19. $v_ip = escapeshellarg($_POST['v_ip']);
  20. if ($_SESSION['user'] == 'admin') {
  21. $v_template = escapeshellarg($_POST['v_template']);
  22. } else {
  23. $v_template = "''";
  24. }
  25. if (!empty($_POST['v_ns1'])) $v_ns1 = escapeshellarg($_POST['v_ns1']);
  26. if (!empty($_POST['v_ns2'])) $v_ns2 = escapeshellarg($_POST['v_ns2']);
  27. if (!empty($_POST['v_ns3'])) $v_ns3 = escapeshellarg($_POST['v_ns3']);
  28. if (!empty($_POST['v_ns4'])) $v_ns4 = escapeshellarg($_POST['v_ns4']);
  29. // Check for errors
  30. if (!empty($errors[0])) {
  31. foreach ($errors as $i => $error) {
  32. if ( $i == 0 ) {
  33. $error_msg = $error;
  34. } else {
  35. $error_msg = $error_msg.", ".$error;
  36. }
  37. }
  38. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  39. } else {
  40. // Add DNS
  41. exec (VESTA_CMD."v-add-dns-domain ".$user." ".$v_domain." ".$v_ip." ".$v_template." ".$v_ns1." ".$v_ns2." ".$v_ns3." ".$ns4, $output, $return_var);
  42. if ($return_var != 0) {
  43. $error = implode('<br>', $output);
  44. if (empty($error)) $error = __('Error code:',$return_var);
  45. $_SESSION['error_msg'] = $error;
  46. }
  47. unset($output);
  48. // Change Expiriation date
  49. if ((!empty($_POST['v_exp'])) && ($_POST['v_exp'] != date('Y-m-d', strtotime('+1 year')))) {
  50. $v_exp = escapeshellarg($_POST['v_exp']);
  51. exec (VESTA_CMD."v-change-dns-domain-exp ".$user." ".$v_domain." ".$v_exp, $output, $return_var);
  52. if ($return_var != 0) {
  53. $error = implode('<br>', $output);
  54. if (empty($error)) $error = __('Error code:',$return_var);
  55. $_SESSION['error_msg'] = $error;
  56. }
  57. unset($output);
  58. }
  59. // Change TTL
  60. if ((!empty($_POST['v_ttl'])) && ($_POST['v_ttl'] != '14400')) {
  61. $v_ttl = escapeshellarg($_POST['v_ttl']);
  62. exec (VESTA_CMD."v-change-dns-domain-ttl ".$user." ".$v_domain." ".$v_ttl, $output, $return_var);
  63. if ($return_var != 0) {
  64. $error = implode('<br>', $output);
  65. if (empty($error)) $error = __('Error code:',$return_var);
  66. $_SESSION['error_msg'] = $error;
  67. }
  68. unset($output);
  69. }
  70. if (empty($_SESSION['error_msg'])) {
  71. $_SESSION['ok_msg'] = __('DNS_DOMAIN_CREATED_OK',$_POST[v_domain],$_POST[v_domain]);
  72. unset($v_domain);
  73. }
  74. }
  75. }
  76. // DNS Record
  77. if (!empty($_POST['ok_rec'])) {
  78. // Check input
  79. if (empty($_POST['v_domain'])) $errors[] = 'domain';
  80. if (empty($_POST['v_rec'])) $errors[] = 'record';
  81. if (empty($_POST['v_type'])) $errors[] = 'type';
  82. if (empty($_POST['v_val'])) $errors[] = 'value';
  83. // Protect input
  84. $v_domain = escapeshellarg($_POST['v_domain']);
  85. $v_rec = escapeshellarg($_POST['v_rec']);
  86. $v_type = escapeshellarg($_POST['v_type']);
  87. $v_val = escapeshellarg($_POST['v_val']);
  88. $v_priority = escapeshellarg($_POST['v_priority']);
  89. // Check for errors
  90. if (!empty($errors[0])) {
  91. foreach ($errors as $i => $error) {
  92. if ( $i == 0 ) {
  93. $error_msg = $error;
  94. } else {
  95. $error_msg = $error_msg.", ".$error;
  96. }
  97. }
  98. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  99. } else {
  100. // Add DNS Record
  101. exec (VESTA_CMD."v-add-dns-domain-record ".$user." ".$v_domain." ".$v_rec." ".$v_type." ".$v_val." ".$v_priority, $output, $return_var);
  102. $v_type = $_POST['v_type'];
  103. if ($return_var != 0) {
  104. $error = implode('<br>', $output);
  105. if (empty($error)) $error = __('Error code:',$return_var);
  106. $_SESSION['error_msg'] = $error;
  107. }
  108. unset($output);
  109. if (empty($_SESSION['error_msg'])) {
  110. $_SESSION['ok_msg'] = __('DNS_RECORD_CREATED_OK',$_POST[v_rec],$_POST[v_domain]);
  111. unset($v_domain);
  112. unset($v_rec);
  113. unset($v_val);
  114. unset($v_priority);
  115. }
  116. }
  117. }
  118. if ((empty($_GET['domain'])) && (empty($_POST['domain']))) {
  119. exec (VESTA_CMD."v-get-user-value ".$user." 'TEMPLATE'", $output, $return_var);
  120. $template = $output[0] ;
  121. unset($output);
  122. exec (VESTA_CMD."v-list-dns-templates json", $output, $return_var);
  123. $templates = json_decode(implode('', $output), true);
  124. unset($output);
  125. if ((empty($v_ns1)) && (empty($v_ns2))) {
  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. if (empty($v_ttl)) $v_ttl = 14400;
  135. if (empty($v_exp)) $v_exp = date('Y-m-d', strtotime('+1 year'));
  136. if ($_SESSION['user'] == 'admin') {
  137. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns.html');
  138. } else {
  139. include($_SERVER['DOCUMENT_ROOT'].'/templates/user/add_dns.html');
  140. }
  141. unset($_SESSION['error_msg']);
  142. unset($_SESSION['ok_msg']);
  143. } else {
  144. $v_domain = $_GET['domain'];
  145. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns_rec.html');
  146. unset($_SESSION['error_msg']);
  147. unset($_SESSION['ok_msg']);
  148. }
  149. // Footer
  150. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');