index.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. use function Hestiacp\quoteshellarg\quoteshellarg;
  3. ob_start();
  4. $TAB = "IP";
  5. // Main include
  6. include $_SERVER["DOCUMENT_ROOT"] . "/inc/main.php";
  7. // Check user
  8. if ($_SESSION["userContext"] != "admin") {
  9. header("Location: /list/user");
  10. exit();
  11. }
  12. // Check POST request
  13. if (!empty($_POST["ok"])) {
  14. /// Check token
  15. verify_csrf($_POST);
  16. // Check empty fields
  17. if (empty($_POST["v_ip"])) {
  18. $errors[] = _("IP Address");
  19. }
  20. if (empty($_POST["v_netmask"])) {
  21. $errors[] = _("Netmask");
  22. }
  23. if (empty($_POST["v_interface"])) {
  24. $errors[] = _("Interface");
  25. }
  26. if (empty($_POST["v_owner"])) {
  27. $errors[] = _("Assigned User");
  28. }
  29. if (!empty($errors[0])) {
  30. foreach ($errors as $i => $error) {
  31. if ($i == 0) {
  32. $error_msg = $error;
  33. } else {
  34. $error_msg = $error_msg . ", " . $error;
  35. }
  36. }
  37. $_SESSION["error_msg"] = sprintf(_('Field "%s" can not be blank.'), $error_msg);
  38. }
  39. // Protect input
  40. $v_ip = quoteshellarg($_POST["v_ip"]);
  41. $v_netmask = quoteshellarg($_POST["v_netmask"]);
  42. $v_name = quoteshellarg($_POST["v_name"]);
  43. $v_nat = quoteshellarg($_POST["v_nat"]);
  44. $v_interface = quoteshellarg($_POST["v_interface"]);
  45. $v_owner = quoteshellarg($_POST["v_owner"]);
  46. $v_shared = $_POST["v_shared"];
  47. // Check shared checkmark
  48. if ($v_shared == "on") {
  49. $ip_status = "shared";
  50. } else {
  51. $ip_status = "dedicated";
  52. $v_dedicated = "yes";
  53. }
  54. // Add IP
  55. if (empty($_SESSION["error_msg"])) {
  56. exec(
  57. HESTIA_CMD .
  58. "v-add-sys-ip " .
  59. $v_ip .
  60. " " .
  61. $v_netmask .
  62. " " .
  63. $v_interface .
  64. " " .
  65. $v_owner .
  66. " " .
  67. quoteshellarg($ip_status) .
  68. " " .
  69. $v_name .
  70. " " .
  71. $v_nat,
  72. $output,
  73. $return_var,
  74. );
  75. check_return_code($return_var, $output);
  76. unset($output);
  77. $v_owner = $_POST["v_owner"];
  78. $v_interface = $_POST["v_interface"];
  79. }
  80. // Flush field values on success
  81. if (empty($_SESSION["error_msg"])) {
  82. $_SESSION["ok_msg"] = htmlify_trans(
  83. sprintf(
  84. _("IP address {%s} has been created successfully."),
  85. htmlentities($_POST["v_ip"]),
  86. ),
  87. "</a>",
  88. '<a class="u-text-bold" href="/edit/ip/?ip=' . htmlentities($_POST["v_ip"]) . '">',
  89. );
  90. unset($v_ip);
  91. unset($v_netmask);
  92. unset($v_name);
  93. unset($v_nat);
  94. }
  95. }
  96. // List network interfaces
  97. exec(HESTIA_CMD . "v-list-sys-interfaces 'json'", $output, $return_var);
  98. $interfaces = json_decode(implode("", $output), true);
  99. unset($output);
  100. // List users
  101. exec(HESTIA_CMD . "v-list-sys-users 'json'", $output, $return_var);
  102. $users = json_decode(implode("", $output), true);
  103. unset($output);
  104. if (empty($v_ip)) {
  105. $v_ip = "";
  106. }
  107. if (empty($v_netmask)) {
  108. $v_netmask = "";
  109. }
  110. if (empty($v_name)) {
  111. $v_name = "";
  112. }
  113. if (empty($v_nat)) {
  114. $v_nat = "";
  115. }
  116. if (empty($v_interface)) {
  117. $v_interface = "";
  118. }
  119. if (empty($ip_status)) {
  120. $ip_status = "";
  121. }
  122. if (empty($v_owner)) {
  123. $v_owner = "";
  124. }
  125. // Render
  126. render_page($user, $TAB, "add_ip");
  127. // Flush session messages
  128. unset($_SESSION["error_msg"]);
  129. unset($_SESSION["ok_msg"]);