index.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. // List rule
  20. $v_rule = escapeshellarg($_GET['rule']);
  21. exec (VESTA_CMD."v-list-firewall-rule ".$v_rule." 'json'", $output, $return_var);
  22. check_return_code($return_var,$output);
  23. $data = json_decode(implode('', $output), true);
  24. unset($output);
  25. // Parse rule
  26. $v_rule = $_GET['rule'];
  27. $v_action = $data[$v_rule]['ACTION'];
  28. $v_protocol = $data[$v_rule]['PROTOCOL'];
  29. $v_port = $data[$v_rule]['PORT'];
  30. $v_ip = $data[$v_rule]['IP'];
  31. $v_comment = $data[$v_rule]['COMMENT'];
  32. $v_date = $data[$v_rule]['DATE'];
  33. $v_time = $data[$v_rule]['TIME'];
  34. $v_suspended = $data[$v_rule]['SUSPENDED'];
  35. if ( $v_suspended == 'yes' ) {
  36. $v_status = 'suspended';
  37. } else {
  38. $v_status = 'active';
  39. }
  40. // Check POST request
  41. if (!empty($_POST['save'])) {
  42. // Check token
  43. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  44. header('location: /login/');
  45. exit();
  46. }
  47. $v_rule = escapeshellarg($_GET['rule']);
  48. $v_action = escapeshellarg($_POST['v_action']);
  49. $v_protocol = escapeshellarg($_POST['v_protocol']);
  50. $v_port = str_replace(" ",",", $_POST['v_port']);
  51. $v_port = preg_replace('/\,+/', ',', $v_port);
  52. $v_port = trim($v_port, ",");
  53. $v_port = escapeshellarg($v_port);
  54. $v_ip = escapeshellarg($_POST['v_ip']);
  55. $v_comment = escapeshellarg($_POST['v_comment']);
  56. // Change Status
  57. exec (VESTA_CMD."v-change-firewall-rule ".$v_rule." ".$v_action." ".$v_ip." ".$v_port." ".$v_protocol." ".$v_comment, $output, $return_var);
  58. check_return_code($return_var,$output);
  59. unset($output);
  60. $v_rule = $_GET['v_rule'];
  61. $v_action = $_POST['v_action'];
  62. $v_protocol = $_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_ip = $_POST['v_ip'];
  67. $v_comment = $_POST['v_comment'];
  68. // Set success message
  69. if (empty($_SESSION['error_msg'])) {
  70. $_SESSION['ok_msg'] = __('Changes has been saved.');
  71. }
  72. }
  73. // Header
  74. include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
  75. // Panel
  76. top_panel($user,$TAB);
  77. // Display body
  78. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_firewall.html');
  79. // Flush session messages
  80. unset($_SESSION['error_msg']);
  81. unset($_SESSION['ok_msg']);
  82. // Footer
  83. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');