index.php 6.6 KB

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