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