index.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. if (empty($_POST['v_exp'])) $errors[] = 'expiriation date';
  19. if (empty($_POST['v_soa'])) $errors[] = 'SOA';
  20. if (empty($_POST['v_ttl'])) $errors[] = 'TTL';
  21. // Protect input
  22. $v_domain = preg_replace("/^www./i", "", $_POST['v_domain']);
  23. $v_domain = escapeshellarg($v_domain);
  24. $v_ip = escapeshellarg($_POST['v_ip']);
  25. if ($_SESSION['user'] == 'admin') {
  26. $v_template = escapeshellarg($_POST['v_template']);
  27. } else {
  28. $v_template = "''";
  29. }
  30. $v_exp = escapeshellarg($_POST['v_exp']);
  31. $v_soa = escapeshellarg($_POST['v_soa']);
  32. $v_ttl = escapeshellarg($_POST['v_ttl']);
  33. // Check for errors
  34. if (!empty($errors[0])) {
  35. foreach ($errors as $i => $error) {
  36. if ( $i == 0 ) {
  37. $error_msg = $error;
  38. } else {
  39. $error_msg = $error_msg.", ".$error;
  40. }
  41. }
  42. $_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank.";
  43. } else {
  44. // Add DNS
  45. exec (VESTA_CMD."v_add_dns_domain ".$user." ".$v_domain." ".$v_ip." ".$v_template." ".$v_exp." ".$v_soa." ".$v_ttl, $output, $return_var);
  46. if ($return_var != 0) {
  47. $error = implode('<br>', $output);
  48. if (empty($error)) $error = 'Error: vesta did not return any output.';
  49. $_SESSION['error_msg'] = $error;
  50. }
  51. unset($output);
  52. if (empty($_SESSION['error_msg'])) {
  53. $_SESSION['ok_msg'] = "OK: domain <b>".$_POST[v_domain]."</b> has been created successfully.";
  54. unset($v_domain);
  55. }
  56. }
  57. }
  58. // DNS Record
  59. if (!empty($_POST['ok_rec'])) {
  60. // Check input
  61. if (empty($_POST['v_domain'])) $errors[] = 'domain';
  62. if (empty($_POST['v_rec'])) $errors[] = 'record';
  63. if (empty($_POST['v_type'])) $errors[] = 'type';
  64. if (empty($_POST['v_val'])) $errors[] = 'value';
  65. // Protect input
  66. $v_domain = escapeshellarg($_POST['v_domain']);
  67. $v_rec = escapeshellarg($_POST['v_rec']);
  68. $v_type = escapeshellarg($_POST['v_type']);
  69. $v_val = escapeshellarg($_POST['v_val']);
  70. $v_priority = escapeshellarg($_POST['v_priority']);
  71. // Check for errors
  72. if (!empty($errors[0])) {
  73. foreach ($errors as $i => $error) {
  74. if ( $i == 0 ) {
  75. $error_msg = $error;
  76. } else {
  77. $error_msg = $error_msg.", ".$error;
  78. }
  79. }
  80. $_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank.";
  81. } else {
  82. // Add DNS Record
  83. exec (VESTA_CMD."v_add_dns_domain_record ".$user." ".$v_domain." ".$v_rec." ".$v_type." ".$v_val." ".$v_priority, $output, $return_var);
  84. $v_type = $_POST['v_type'];
  85. if ($return_var != 0) {
  86. $error = implode('<br>', $output);
  87. if (empty($error)) $error = 'Error: vesta did not return any output.';
  88. $_SESSION['error_msg'] = $error;
  89. }
  90. unset($output);
  91. if (empty($_SESSION['error_msg'])) {
  92. $_SESSION['ok_msg'] = "OK: record <b>".$_POST[v_rec]."</b> has been created successfully.";
  93. unset($v_domain);
  94. unset($v_rec);
  95. unset($v_val);
  96. unset($v_priority);
  97. }
  98. }
  99. }
  100. if ((empty($_GET['domain'])) && (empty($_POST['domain']))) {
  101. exec (VESTA_CMD."v_list_dns_templates json", $output, $return_var);
  102. $templates = json_decode(implode('', $output), true);
  103. unset($output);
  104. exec (VESTA_CMD."v_list_user_ns ".$user." json", $output, $return_var);
  105. $soa = json_decode(implode('', $output), true);
  106. $v_soa = $soa[0];
  107. unset($output);
  108. $v_ttl = 14400;
  109. $v_exp = date('Y-m-d', strtotime('+1 year'));
  110. if ($_SESSION['user'] == 'admin') {
  111. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_dns.html');
  112. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns.html');
  113. } else {
  114. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_dns.html');
  115. include($_SERVER['DOCUMENT_ROOT'].'/templates/user/add_dns.html');
  116. }
  117. unset($_SESSION['error_msg']);
  118. unset($_SESSION['ok_msg']);
  119. } else {
  120. $v_domain = $_GET['domain'];
  121. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_dns_rec.html');
  122. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns_rec.html');
  123. unset($_SESSION['error_msg']);
  124. unset($_SESSION['ok_msg']);
  125. }
  126. //}
  127. // Footer
  128. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');