index.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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_domain = strtolower($v_domain);
  20. $v_ip = escapeshellarg($_POST['v_ip']);
  21. if (!empty($_POST['v_ns1'])) $v_ns1 = escapeshellarg($_POST['v_ns1']);
  22. if (!empty($_POST['v_ns2'])) $v_ns2 = escapeshellarg($_POST['v_ns2']);
  23. if (!empty($_POST['v_ns3'])) $v_ns3 = escapeshellarg($_POST['v_ns3']);
  24. if (!empty($_POST['v_ns4'])) $v_ns4 = escapeshellarg($_POST['v_ns4']);
  25. // Check for errors
  26. if (!empty($errors[0])) {
  27. foreach ($errors as $i => $error) {
  28. if ( $i == 0 ) {
  29. $error_msg = $error;
  30. } else {
  31. $error_msg = $error_msg.", ".$error;
  32. }
  33. }
  34. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  35. } else {
  36. // Add DNS
  37. exec (VESTA_CMD."v-add-dns-domain ".$user." ".$v_domain." ".$v_ip." ".$v_ns1." ".$v_ns2." ".$v_ns3." ".$v_ns4, $output, $return_var);
  38. if ($return_var != 0) {
  39. $error = implode('<br>', $output);
  40. if (empty($error)) $error = __('Error code:',$return_var);
  41. $_SESSION['error_msg'] = $error;
  42. }
  43. unset($output);
  44. // Change Expiriation date
  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, $output, $return_var);
  48. if ($return_var != 0) {
  49. $error = implode('<br>', $output);
  50. if (empty($error)) $error = __('Error code:',$return_var);
  51. $_SESSION['error_msg'] = $error;
  52. }
  53. unset($output);
  54. }
  55. // Change TTL
  56. if ((!empty($_POST['v_ttl'])) && ($_POST['v_ttl'] != '14400')) {
  57. $v_ttl = escapeshellarg($_POST['v_ttl']);
  58. exec (VESTA_CMD."v-change-dns-domain-ttl ".$user." ".$v_domain." ".$v_ttl, $output, $return_var);
  59. if ($return_var != 0) {
  60. $error = implode('<br>', $output);
  61. if (empty($error)) $error = __('Error code:',$return_var);
  62. $_SESSION['error_msg'] = $error;
  63. }
  64. unset($output);
  65. }
  66. if (empty($_SESSION['error_msg'])) {
  67. $_SESSION['ok_msg'] = __('DNS_DOMAIN_CREATED_OK',$_POST[v_domain],$_POST[v_domain]);
  68. unset($v_domain);
  69. }
  70. }
  71. }
  72. // DNS Record
  73. if (!empty($_POST['ok_rec'])) {
  74. // Check input
  75. if (empty($_POST['v_domain'])) $errors[] = 'domain';
  76. if (empty($_POST['v_rec'])) $errors[] = 'record';
  77. if (empty($_POST['v_type'])) $errors[] = 'type';
  78. if (empty($_POST['v_val'])) $errors[] = 'value';
  79. // Protect input
  80. $v_domain = escapeshellarg($_POST['v_domain']);
  81. $v_rec = escapeshellarg($_POST['v_rec']);
  82. $v_type = escapeshellarg($_POST['v_type']);
  83. $v_val = escapeshellarg($_POST['v_val']);
  84. $v_priority = escapeshellarg($_POST['v_priority']);
  85. // Check for errors
  86. if (!empty($errors[0])) {
  87. foreach ($errors as $i => $error) {
  88. if ( $i == 0 ) {
  89. $error_msg = $error;
  90. } else {
  91. $error_msg = $error_msg.", ".$error;
  92. }
  93. }
  94. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  95. } else {
  96. // Add DNS Record
  97. exec (VESTA_CMD."v-add-dns-record ".$user." ".$v_domain." ".$v_rec." ".$v_type." ".$v_val." ".$v_priority, $output, $return_var);
  98. $v_type = $_POST['v_type'];
  99. if ($return_var != 0) {
  100. $error = implode('<br>', $output);
  101. if (empty($error)) $error = __('Error code:',$return_var);
  102. $_SESSION['error_msg'] = $error;
  103. }
  104. unset($output);
  105. if (empty($_SESSION['error_msg'])) {
  106. $_SESSION['ok_msg'] = __('DNS_RECORD_CREATED_OK',$_POST[v_rec],$_POST[v_domain]);
  107. unset($v_domain);
  108. unset($v_rec);
  109. unset($v_val);
  110. unset($v_priority);
  111. }
  112. }
  113. }
  114. if ((empty($_GET['domain'])) && (empty($_POST['domain']))) {
  115. if ((empty($v_ns1)) && (empty($v_ns2))) {
  116. exec (VESTA_CMD."v-list-user-ns ".$user." json", $output, $return_var);
  117. $nameservers = json_decode(implode('', $output), true);
  118. $v_ns1 = $nameservers[0];
  119. $v_ns2 = $nameservers[1];
  120. $v_ns3 = $nameservers[2];
  121. $v_ns4 = $nameservers[3];
  122. unset($output);
  123. }
  124. if (empty($v_ttl)) $v_ttl = 14400;
  125. if (empty($v_exp)) $v_exp = date('Y-m-d', strtotime('+1 year'));
  126. if ($_SESSION['user'] == 'admin') {
  127. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns.html');
  128. } else {
  129. include($_SERVER['DOCUMENT_ROOT'].'/templates/user/add_dns.html');
  130. }
  131. unset($_SESSION['error_msg']);
  132. unset($_SESSION['ok_msg']);
  133. } else {
  134. $v_domain = $_GET['domain'];
  135. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns_rec.html');
  136. unset($_SESSION['error_msg']);
  137. unset($_SESSION['ok_msg']);
  138. }
  139. // Footer
  140. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');