index.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 empty fields
  11. if (empty($_POST['v_domain'])) $errors[] = __('domain');
  12. if (empty($_POST['v_ip'])) $errors[] = __('ip');
  13. if (!empty($errors[0])) {
  14. foreach ($errors as $i => $error) {
  15. if ( $i == 0 ) {
  16. $error_msg = $error;
  17. } else {
  18. $error_msg = $error_msg.", ".$error;
  19. }
  20. }
  21. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  22. }
  23. // Protect input
  24. $v_domain = preg_replace("/^www./i", "", $_POST['v_domain']);
  25. $v_domain = escapeshellarg($v_domain);
  26. $v_domain = strtolower($v_domain);
  27. $v_ip = escapeshellarg($_POST['v_ip']);
  28. if (!empty($_POST['v_ns1'])) $v_ns1 = escapeshellarg($_POST['v_ns1']);
  29. if (!empty($_POST['v_ns2'])) $v_ns2 = escapeshellarg($_POST['v_ns2']);
  30. if (!empty($_POST['v_ns3'])) $v_ns3 = escapeshellarg($_POST['v_ns3']);
  31. if (!empty($_POST['v_ns4'])) $v_ns4 = escapeshellarg($_POST['v_ns4']);
  32. // Add dns domain
  33. if (empty($_SESSION['error_msg'])) {
  34. exec (VESTA_CMD."v-add-dns-domain ".$user." ".$v_domain." ".$v_ip." ".$v_ns1." ".$v_ns2." ".$v_ns3." ".$v_ns4." no", $output, $return_var);
  35. check_return_code($return_var,$output);
  36. unset($output);
  37. }
  38. // Set expiriation date
  39. if (empty($_SESSION['error_msg'])) {
  40. if ((!empty($_POST['v_exp'])) && ($_POST['v_exp'] != date('Y-m-d', strtotime('+1 year')))) {
  41. $v_exp = escapeshellarg($_POST['v_exp']);
  42. exec (VESTA_CMD."v-change-dns-domain-exp ".$user." ".$v_domain." ".$v_exp." no", $output, $return_var);
  43. check_return_code($return_var,$output);
  44. unset($output);
  45. }
  46. }
  47. // Set ttl
  48. if (empty($_SESSION['error_msg'])) {
  49. if ((!empty($_POST['v_ttl'])) && ($_POST['v_ttl'] != '14400') && (empty($_SESSION['error_msg']))) {
  50. $v_ttl = escapeshellarg($_POST['v_ttl']);
  51. exec (VESTA_CMD."v-change-dns-domain-ttl ".$user." ".$v_domain." ".$v_ttl." no", $output, $return_var);
  52. check_return_code($return_var,$output);
  53. unset($output);
  54. }
  55. }
  56. // Restart dns server
  57. if (empty($_SESSION['error_msg'])) {
  58. exec (VESTA_CMD."v-restart-dns", $output, $return_var);
  59. check_return_code($return_var,$output);
  60. unset($output);
  61. }
  62. // Flush field values on success
  63. if (empty($_SESSION['error_msg'])) {
  64. $_SESSION['ok_msg'] = __('DNS_DOMAIN_CREATED_OK',$_POST[v_domain],$_POST[v_domain]);
  65. unset($v_domain);
  66. }
  67. }
  68. // Check POST request for dns record
  69. if (!empty($_POST['ok_rec'])) {
  70. // Check empty fields
  71. if (empty($_POST['v_domain'])) $errors[] = 'domain';
  72. if (empty($_POST['v_rec'])) $errors[] = 'record';
  73. if (empty($_POST['v_type'])) $errors[] = 'type';
  74. if (empty($_POST['v_val'])) $errors[] = 'value';
  75. if (!empty($errors[0])) {
  76. foreach ($errors as $i => $error) {
  77. if ( $i == 0 ) {
  78. $error_msg = $error;
  79. } else {
  80. $error_msg = $error_msg.", ".$error;
  81. }
  82. }
  83. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  84. }
  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. // Add dns record
  92. if (empty($_SESSION['error_msg'])) {
  93. exec (VESTA_CMD."v-add-dns-record ".$user." ".$v_domain." ".$v_rec." ".$v_type." ".$v_val." ".$v_priority, $output, $return_var);
  94. check_return_code($return_var,$output);
  95. unset($output);
  96. $v_type = $_POST['v_type'];
  97. }
  98. // Flush field values on success
  99. if (empty($_SESSION['error_msg'])) {
  100. $_SESSION['ok_msg'] = __('DNS_RECORD_CREATED_OK',$_POST[v_rec],$_POST[v_domain]);
  101. unset($v_domain);
  102. unset($v_rec);
  103. unset($v_val);
  104. unset($v_priority);
  105. }
  106. }
  107. // Header
  108. include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
  109. // Panel
  110. top_panel($user,$TAB);
  111. // Display body for dns domain
  112. if (empty($_GET['domain'])) {
  113. if (empty($v_ttl)) $v_ttl = 14400;
  114. if (empty($v_exp)) $v_exp = date('Y-m-d', strtotime('+1 year'));
  115. if (empty($v_ns1)) {
  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. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns.html');
  125. }
  126. // Display body for dns record
  127. if (!empty($_GET['domain'])) {
  128. $v_domain = $_GET['domain'];
  129. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns_rec.html');
  130. }
  131. // Flush session messages
  132. unset($_SESSION['error_msg']);
  133. unset($_SESSION['ok_msg']);
  134. // Footer
  135. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');