index.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 (VESTA_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. // Check POST request
  39. if (!empty($_POST['save'])) {
  40. // Check token
  41. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  42. header('location: /login/');
  43. exit();
  44. }
  45. $v_rule = escapeshellarg($_GET['rule']);
  46. $v_action = escapeshellarg($_POST['v_action']);
  47. $v_protocol = escapeshellarg($_POST['v_protocol']);
  48. $v_port = str_replace(" ",",", $_POST['v_port']);
  49. $v_port = preg_replace('/\,+/', ',', $v_port);
  50. $v_port = trim($v_port, ",");
  51. $v_port = escapeshellarg($v_port);
  52. $v_ip = escapeshellarg($_POST['v_ip']);
  53. $v_comment = escapeshellarg($_POST['v_comment']);
  54. // Change Status
  55. exec (VESTA_CMD."v-change-firewall-rule ".$v_rule." ".$v_action." ".$v_ip." ".$v_port." ".$v_protocol." ".$v_comment, $output, $return_var);
  56. check_return_code($return_var,$output);
  57. unset($output);
  58. $v_rule = $_GET['v_rule'];
  59. $v_action = $_POST['v_action'];
  60. $v_protocol = $_POST['v_protocol'];
  61. $v_port = str_replace(" ",",", $_POST['v_port']);
  62. $v_port = preg_replace('/\,+/', ',', $v_port);
  63. $v_port = trim($v_port, ",");
  64. $v_ip = $_POST['v_ip'];
  65. $v_comment = $_POST['v_comment'];
  66. // Set success message
  67. if (empty($_SESSION['error_msg'])) {
  68. $_SESSION['ok_msg'] = __('Changes has been saved.');
  69. }
  70. }
  71. // Render page
  72. render_page($user, $TAB, 'edit_firewall');
  73. // Flush session messages
  74. unset($_SESSION['error_msg']);
  75. unset($_SESSION['ok_msg']);