index.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. // Init
  3. error_reporting(NULL);
  4. ob_start();
  5. session_start();
  6. $TAB = 'FIREWALL';
  7. // Main include
  8. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  9. // Check user
  10. if ($_SESSION['user'] != 'admin') {
  11. header("Location: /list/user");
  12. exit;
  13. }
  14. // Check ip argument
  15. if (empty($_GET['rule'])) {
  16. header("Location: /list/firewall/");
  17. exit;
  18. }
  19. $v_rule = $_GET['rule'];
  20. // List rule
  21. v_exec('v-list-firewall-rule', [$v_rule, 'json'], true, $output);
  22. $data = json_decode($output, true);
  23. // Parse rule
  24. $v_action = $data[$v_rule]['ACTION'];
  25. $v_protocol = $data[$v_rule]['PROTOCOL'];
  26. $v_port = $data[$v_rule]['PORT'];
  27. $v_ip = $data[$v_rule]['IP'];
  28. $v_comment = $data[$v_rule]['COMMENT'];
  29. $v_date = $data[$v_rule]['DATE'];
  30. $v_time = $data[$v_rule]['TIME'];
  31. $v_suspended = $data[$v_rule]['SUSPENDED'];
  32. $v_status = $v_suspended == 'yes' ? 'suspended' : 'active';
  33. // Check POST request
  34. if (!empty($_POST['save'])) {
  35. // Check token
  36. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  37. header('location: /login/');
  38. exit;
  39. }
  40. $v_rule = $_GET['rule'];
  41. $v_action = $_POST['v_action'];
  42. $v_protocol = $_POST['v_protocol'];
  43. $v_port = str_replace(" ",",", $_POST['v_port']);
  44. $v_port = preg_replace('/\,+/', ',', $v_port);
  45. $v_port = trim($v_port, ",");
  46. $v_ip = $_POST['v_ip'];
  47. $v_comment = $_POST['v_comment'];
  48. // Change Status
  49. v_exec('v-change-firewall-rule', [$v_rule, $v_action, $v_ip, $v_port, $v_protocol, $v_comment]);
  50. // Set success message
  51. if (empty($_SESSION['error_msg'])) {
  52. $_SESSION['ok_msg'] = __('Changes has been saved.');
  53. }
  54. }
  55. // Header
  56. include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
  57. // Panel
  58. top_panel($user,$TAB);
  59. // Display body
  60. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_firewall.html');
  61. // Flush session messages
  62. unset($_SESSION['error_msg']);
  63. unset($_SESSION['ok_msg']);
  64. // Footer
  65. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');