index.php 5.1 KB

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