index.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. $v_rule = escapeshellarg($_GET['rule']);
  43. $v_action = escapeshellarg($_POST['v_action']);
  44. $v_protocol = escapeshellarg($_POST['v_protocol']);
  45. $v_port = str_replace(" ",",", $_POST['v_port']);
  46. $v_port = preg_replace('/\,+/', ',', $v_port);
  47. $v_port = trim($v_port, ",");
  48. $v_port = escapeshellarg($v_port);
  49. $v_ip = escapeshellarg($_POST['v_ip']);
  50. $v_comment = escapeshellarg($_POST['v_comment']);
  51. // Change Status
  52. exec (VESTA_CMD."v-change-firewall-rule ".$v_rule." ".$v_action." ".$v_ip." ".$v_port." ".$v_protocol." ".$v_comment, $output, $return_var);
  53. check_return_code($return_var,$output);
  54. unset($output);
  55. $v_rule = $_GET['v_rule'];
  56. $v_action = $_POST['v_action'];
  57. $v_protocol = $_POST['v_protocol'];
  58. $v_port = str_replace(" ",",", $_POST['v_port']);
  59. $v_port = preg_replace('/\,+/', ',', $v_port);
  60. $v_port = trim($v_port, ",");
  61. $v_ip = $_POST['v_ip'];
  62. $v_comment = $_POST['v_comment'];
  63. // Set success message
  64. if (empty($_SESSION['error_msg'])) {
  65. $_SESSION['ok_msg'] = __('Changes has been saved.');
  66. }
  67. }
  68. // Header
  69. include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
  70. // Panel
  71. top_panel($user,$TAB);
  72. // Display body
  73. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_firewall.html');
  74. // Flush session messages
  75. unset($_SESSION['error_msg']);
  76. unset($_SESSION['ok_msg']);
  77. // Footer
  78. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');