index.php 4.9 KB

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