index.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 token
  11. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  12. header('location: /login/');
  13. exit;
  14. }
  15. // Check empty fields
  16. if (empty($_POST['v_domain'])) $errors[] = __('domain');
  17. if (empty($_POST['v_ip'])) $errors[] = __('ip');
  18. if (!empty($errors[0])) {
  19. foreach ($errors as $i => $error) {
  20. if ( $i == 0 ) {
  21. $error_msg = $error;
  22. } else {
  23. $error_msg = $error_msg.", ".$error;
  24. }
  25. }
  26. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  27. }
  28. // Protect input
  29. $v_domain = preg_replace("/^www./i", "", $_POST['v_domain']);
  30. $v_domain = strtolower($v_domain);
  31. $v_ip = $_POST['v_ip'];
  32. if (!empty($_POST['v_ns1'])) $v_ns1 = $_POST['v_ns1'];
  33. if (!empty($_POST['v_ns2'])) $v_ns2 = $_POST['v_ns2'];
  34. if (!empty($_POST['v_ns3'])) $v_ns3 = $_POST['v_ns3'];
  35. if (!empty($_POST['v_ns4'])) $v_ns4 = $_POST['v_ns4'];
  36. if (!empty($_POST['v_ns5'])) $v_ns5 = $_POST['v_ns5'];
  37. if (!empty($_POST['v_ns6'])) $v_ns6 = $_POST['v_ns6'];
  38. if (!empty($_POST['v_ns7'])) $v_ns7 = $_POST['v_ns7'];
  39. if (!empty($_POST['v_ns8'])) $v_ns8 = $_POST['v_ns8'];
  40. // Add dns domain
  41. if (empty($_SESSION['error_msg'])) {
  42. v_exec('v-add-dns-domain', [$user, $v_domain, $v_ip, $v_ns1, $v_ns2, $v_ns3, $v_ns4, $v_ns5, $v_ns6, $v_ns7, $v_ns8, 'no']);
  43. }
  44. // Set expiriation date
  45. if (empty($_SESSION['error_msg'])) {
  46. if ((!empty($_POST['v_exp'])) && ($_POST['v_exp'] != date('Y-m-d', strtotime('+1 year')))) {
  47. $v_exp = $_POST['v_exp'];
  48. v_exec('v-change-dns-domain-exp', [$user, $v_domain, $v_exp, 'no']);
  49. }
  50. }
  51. // Set ttl
  52. if (empty($_SESSION['error_msg'])) {
  53. if ((!empty($_POST['v_ttl'])) && ($_POST['v_ttl'] != '14400') && (empty($_SESSION['error_msg']))) {
  54. $v_ttl = $_POST['v_ttl'];
  55. v_exec('v-change-dns-domain-ttl', [$user, $v_domain, $v_ttl, 'no']);
  56. }
  57. }
  58. // Restart dns server
  59. if (empty($_SESSION['error_msg'])) {
  60. v_exec('v-restart-dns');
  61. }
  62. // Flush field values on success
  63. if (empty($_SESSION['error_msg'])) {
  64. $_SESSION['ok_msg'] = __('DNS_DOMAIN_CREATED_OK', htmlentities($_POST[v_domain]), htmlentities($_POST[v_domain]));
  65. unset($v_domain);
  66. }
  67. }
  68. // Check POST request for dns record
  69. if (!empty($_POST['ok_rec'])) {
  70. // Check token
  71. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  72. header('location: /login/');
  73. exit;
  74. }
  75. // Check empty fields
  76. if (empty($_POST['v_domain'])) $errors[] = 'domain';
  77. if (empty($_POST['v_rec'])) $errors[] = 'record';
  78. if (empty($_POST['v_type'])) $errors[] = 'type';
  79. if (empty($_POST['v_val'])) $errors[] = 'value';
  80. if (!empty($errors[0])) {
  81. foreach ($errors as $i => $error) {
  82. if ( $i == 0 ) {
  83. $error_msg = $error;
  84. } else {
  85. $error_msg = $error_msg.", ".$error;
  86. }
  87. }
  88. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  89. }
  90. // Protect input
  91. $v_domain = $_POST['v_domain'];
  92. $v_rec = $_POST['v_rec'];
  93. $v_type = $_POST['v_type'];
  94. $v_val = $_POST['v_val'];
  95. $v_priority = $_POST['v_priority'];
  96. // Add dns record
  97. if (empty($_SESSION['error_msg'])) {
  98. v_exec('v-add-dns-record', [$user, $v_domain, $v_rec, $v_type, $v_val, $v_priority]);
  99. }
  100. // Flush field values on success
  101. if (empty($_SESSION['error_msg'])) {
  102. $_SESSION['ok_msg'] = __('DNS_RECORD_CREATED_OK',htmlentities($_POST[v_rec]),htmlentities($_POST[v_domain]));
  103. unset($v_domain);
  104. unset($v_rec);
  105. unset($v_val);
  106. unset($v_priority);
  107. }
  108. }
  109. // Header
  110. include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
  111. // Panel
  112. top_panel($user,$TAB);
  113. $v_ns1 = str_replace("'", "", $v_ns1);
  114. $v_ns2 = str_replace("'", "", $v_ns2);
  115. $v_ns3 = str_replace("'", "", $v_ns3);
  116. $v_ns4 = str_replace("'", "", $v_ns4);
  117. $v_ns5 = str_replace("'", "", $v_ns5);
  118. $v_ns6 = str_replace("'", "", $v_ns6);
  119. $v_ns7 = str_replace("'", "", $v_ns7);
  120. $v_ns8 = str_replace("'", "", $v_ns8);
  121. // Display body for dns domain
  122. if (empty($_GET['domain'])) {
  123. if (empty($v_ttl)) $v_ttl = 14400;
  124. if (empty($v_exp)) $v_exp = date('Y-m-d', strtotime('+1 year'));
  125. if (empty($v_ns1)) {
  126. v_exec('v-list-user-ns', [$user, 'json'], false, $output);
  127. $nameservers = json_decode($output, true);
  128. $v_ns1 = str_replace("'", "", $nameservers[0]);
  129. $v_ns2 = str_replace("'", "", $nameservers[1]);
  130. $v_ns3 = str_replace("'", "", $nameservers[2]);
  131. $v_ns4 = str_replace("'", "", $nameservers[3]);
  132. $v_ns5 = str_replace("'", "", $nameservers[4]);
  133. $v_ns6 = str_replace("'", "", $nameservers[5]);
  134. $v_ns7 = str_replace("'", "", $nameservers[6]);
  135. $v_ns8 = str_replace("'", "", $nameservers[7]);
  136. }
  137. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns.html');
  138. }
  139. // Display body for dns record
  140. if (!empty($_GET['domain'])) {
  141. $v_domain = $_GET['domain'];
  142. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns_rec.html');
  143. }
  144. // Flush session messages
  145. unset($_SESSION['error_msg']);
  146. unset($_SESSION['ok_msg']);
  147. // Footer
  148. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');