index.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. error_reporting(NULL);
  3. ob_start();
  4. $TAB = 'FIREWALL';
  5. // Main include
  6. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  7. // Check user
  8. if ($_SESSION['user'] != 'admin') {
  9. header("Location: /list/user");
  10. exit;
  11. }
  12. // Check ip argument
  13. if (empty($_GET['rule'])) {
  14. header("Location: /list/firewall/");
  15. exit;
  16. }
  17. // List rule
  18. $v_rule = escapeshellarg($_GET['rule']);
  19. exec (HESTIA_CMD."v-list-firewall-rule ".$v_rule." 'json'", $output, $return_var);
  20. check_return_code($return_var,$output);
  21. $data = json_decode(implode('', $output), true);
  22. unset($output);
  23. // Parse rule
  24. $v_rule = $_GET['rule'];
  25. $v_action = $data[$v_rule]['ACTION'];
  26. $v_protocol = $data[$v_rule]['PROTOCOL'];
  27. $v_port = $data[$v_rule]['PORT'];
  28. $v_ip = $data[$v_rule]['IP'];
  29. $v_comment = $data[$v_rule]['COMMENT'];
  30. $v_date = $data[$v_rule]['DATE'];
  31. $v_time = $data[$v_rule]['TIME'];
  32. $v_suspended = $data[$v_rule]['SUSPENDED'];
  33. if ( $v_suspended == 'yes' ) {
  34. $v_status = 'suspended';
  35. } else {
  36. $v_status = 'active';
  37. }
  38. // Get ipset lists
  39. exec (HESTIA_CMD."v-list-firewall-ipset 'json'", $output, $return_var);
  40. check_return_code($return_var,$output);
  41. $data = json_decode(implode('', $output), true);
  42. $ipset_lists=[];
  43. foreach($data as $key => $value) {
  44. if(isset($value['SUSPENDED']) && $value['SUSPENDED'] === 'yes') {
  45. continue;
  46. }
  47. if(isset($value['IP_VERSION']) && $value['IP_VERSION'] !== 'v4') {
  48. continue;
  49. }
  50. array_push($ipset_lists, ['name'=>$key]);
  51. }
  52. $ipset_lists_json=json_encode($ipset_lists);
  53. // Check POST request
  54. if (!empty($_POST['save'])) {
  55. // Check token
  56. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  57. header('location: /login/');
  58. exit();
  59. }
  60. $v_rule = escapeshellarg($_GET['rule']);
  61. $v_action = escapeshellarg($_POST['v_action']);
  62. $v_protocol = escapeshellarg($_POST['v_protocol']);
  63. $v_port = str_replace(" ",",", $_POST['v_port']);
  64. $v_port = preg_replace('/\,+/', ',', $v_port);
  65. $v_port = trim($v_port, ",");
  66. $v_port = escapeshellarg($v_port);
  67. $v_ip = escapeshellarg($_POST['v_ip']);
  68. $v_comment = escapeshellarg($_POST['v_comment']);
  69. // Change Status
  70. exec (HESTIA_CMD."v-change-firewall-rule ".$v_rule." ".$v_action." ".$v_ip." ".$v_port." ".$v_protocol." ".$v_comment, $output, $return_var);
  71. check_return_code($return_var,$output);
  72. unset($output);
  73. $v_rule = $_GET['v_rule'];
  74. $v_action = $_POST['v_action'];
  75. $v_protocol = $_POST['v_protocol'];
  76. $v_port = str_replace(" ",",", $_POST['v_port']);
  77. $v_port = preg_replace('/\,+/', ',', $v_port);
  78. $v_port = trim($v_port, ",");
  79. $v_ip = $_POST['v_ip'];
  80. $v_comment = $_POST['v_comment'];
  81. // Set success message
  82. if (empty($_SESSION['error_msg'])) {
  83. $_SESSION['ok_msg'] = _('Changes has been saved.');
  84. }
  85. }
  86. // Render page
  87. render_page($user, $TAB, 'edit_firewall');
  88. // Flush session messages
  89. unset($_SESSION['error_msg']);
  90. unset($_SESSION['ok_msg']);