index.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. use function Hestiacp\quoteshellarg\quoteshellarg;
  3. ob_start();
  4. $TAB = "FIREWALL";
  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_ipname"])) {
  18. $errors[] = _("Name");
  19. }
  20. if (empty($_POST["v_datasource"])) {
  21. $errors[] = _("Data Source");
  22. }
  23. if (empty($_POST["v_ipver"])) {
  24. $errors[] = _("Ip Version");
  25. }
  26. if (empty($_POST["v_autoupdate"])) {
  27. $errors[] = _("Autoupdate");
  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. $v_ipname = $_POST["v_ipname"];
  40. $v_datasource = $_POST["v_datasource"];
  41. $v_ipver = $_POST["v_ipver"];
  42. $v_autoupdate = $_POST["v_autoupdate"];
  43. // Add firewall ipset list
  44. if (empty($_SESSION["error_msg"])) {
  45. exec(
  46. HESTIA_CMD .
  47. "v-add-firewall-ipset " .
  48. quoteshellarg($v_ipname) .
  49. " " .
  50. quoteshellarg($v_datasource) .
  51. " " .
  52. quoteshellarg($v_ipver) .
  53. " " .
  54. quoteshellarg($v_autoupdate),
  55. $output,
  56. $return_var,
  57. );
  58. check_return_code($return_var, $output);
  59. unset($output);
  60. }
  61. // Flush field values on success
  62. if (empty($_SESSION["error_msg"])) {
  63. $_SESSION["ok_msg"] = _("IPSET_CREATED_OK");
  64. }
  65. }
  66. if (empty($v_ipname)) {
  67. $v_ipname = "";
  68. }
  69. if (empty($v_datasource)) {
  70. $v_datasource = "";
  71. }
  72. if (empty($v_ipver)) {
  73. $v_ipver = "";
  74. }
  75. // Render
  76. render_page($user, $TAB, "add_firewall_ipset");
  77. // Flush session messages
  78. unset($_SESSION["error_msg"]);
  79. unset($_SESSION["ok_msg"]);