index.php 5.4 KB

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