1 |
c0b6fdde
|
jim-p
|
<?php
|
2 |
|
|
/*
|
3 |
|
|
easyrule.php
|
4 |
|
|
|
5 |
|
|
Copyright (C) 2009 Jim Pingle (jpingle@gmail.com)
|
6 |
|
|
Sponsored By Anathematic @ pfSense Forums
|
7 |
|
|
All rights reserved.
|
8 |
|
|
|
9 |
|
|
Redistribution and use in source and binary forms, with or without
|
10 |
|
|
modification, are permitted provided that the following conditions are met:
|
11 |
|
|
|
12 |
|
|
1. Redistributions of source code must retain the above copyright notice,
|
13 |
|
|
this list of conditions and the following disclaimer.
|
14 |
|
|
|
15 |
|
|
2. Redistributions in binary form must reproduce the above copyright
|
16 |
|
|
notice, this list of conditions and the following disclaimer in the
|
17 |
|
|
documentation and/or other materials provided with the distribution.
|
18 |
|
|
|
19 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
20 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
21 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
22 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
23 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
24 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
25 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
26 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
27 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
29 |
|
|
*/
|
30 |
7ac5a4cb
|
Scott Ullrich
|
/*
|
31 |
|
|
pfSense_MODULE: filter
|
32 |
|
|
*/
|
33 |
c0b6fdde
|
jim-p
|
|
34 |
|
|
$pgtitle = "Status : EasyRule";
|
35 |
|
|
require_once("guiconfig.inc");
|
36 |
|
|
require_once("easyrule.inc");
|
37 |
|
|
$retval = 0;
|
38 |
|
|
$message = "";
|
39 |
|
|
|
40 |
|
|
if ($_GET && isset($_GET['action'])) {
|
41 |
|
|
switch ($_GET['action']) {
|
42 |
|
|
case 'block':
|
43 |
|
|
/* Check that we have a valid host */
|
44 |
|
|
if (isset($_GET['src']) && isset($_GET['int'])) {
|
45 |
|
|
if (!is_ipaddr($_GET['src'])) {
|
46 |
|
|
$message .= "Tried to block invalid IP: " . htmlspecialchars($_GET['src']) . "<br/>";
|
47 |
|
|
break;
|
48 |
|
|
}
|
49 |
|
|
$_GET['int'] = easyrule_find_rule_interface($_GET['int']);
|
50 |
|
|
if ($_GET['int'] === false) {
|
51 |
|
|
$message .= "Invalid interface for block rule: " . htmlspecialchars($_GET['int']) . "<br/>";
|
52 |
|
|
break;
|
53 |
|
|
}
|
54 |
|
|
if (easyrule_block_host_add($_GET['src'], $_GET['int'])) {
|
55 |
|
|
/* shouldn't get here, the function will redirect */
|
56 |
|
|
$message .= "Host added successfully" . "<br/>";
|
57 |
|
|
} else {
|
58 |
|
|
$message .= "Failed to create block rule, alias, or add host." . "<br/>";
|
59 |
|
|
}
|
60 |
|
|
} else {
|
61 |
|
|
$message .= "Tried to block but had no host IP or interface<br/>";
|
62 |
|
|
}
|
63 |
|
|
break;
|
64 |
|
|
case 'pass':
|
65 |
|
|
/* Check for valid int, srchost, dsthost, dstport, and proto */
|
66 |
|
|
if (isset($_GET['int']) && isset($_GET['proto']) && isset($_GET['src']) && isset($_GET['dst'])) {
|
67 |
|
|
$_GET['int'] = easyrule_find_rule_interface($_GET['int']);
|
68 |
|
|
if ($_GET['int'] === false) {
|
69 |
|
|
$message .= "Invalid interface for pass rule: " . htmlspecialchars($_GET['int']) . "<br/>";
|
70 |
|
|
break;
|
71 |
|
|
}
|
72 |
|
|
if (getprotobyname($_GET['proto']) == -1) {
|
73 |
|
|
$message .= "Invalid protocol for pass rule: " . htmlspecialchars($_GET['proto']) . "<br/>";
|
74 |
|
|
break;
|
75 |
|
|
}
|
76 |
|
|
if (!is_ipaddr($_GET['src'])) {
|
77 |
|
|
$message .= "Tried to pass invalid source IP: " . htmlspecialchars($_GET['src']) . "<br/>";
|
78 |
|
|
break;
|
79 |
|
|
}
|
80 |
|
|
if (!is_ipaddr($_GET['dst'])) {
|
81 |
|
|
$message .= "Tried to pass invalid destination IP: " . htmlspecialchars($_GET['dst']) . "<br/>";
|
82 |
|
|
break;
|
83 |
|
|
}
|
84 |
|
|
if (($_GET['proto'] != 'icmp') && !isset($_GET['dstport'])) {
|
85 |
|
|
$message .= "Missing destination port: " . htmlspecialchars($_GET['dstport']) . "<br/>";
|
86 |
|
|
break;
|
87 |
|
|
}
|
88 |
|
|
if ($_GET['proto'] == 'icmp') {
|
89 |
|
|
$_GET['dstport'] = 0;
|
90 |
|
|
}
|
91 |
|
|
if (!is_numeric($_GET['dstport']) || ($_GET['dstport'] < 0) || ($_GET['dstport'] > 65536)) {
|
92 |
|
|
$message .= "Tried to pass invalid destination port: " . htmlspecialchars($_GET['dstport']) . "<br/>";
|
93 |
|
|
break;
|
94 |
|
|
}
|
95 |
|
|
/* Should have valid input... */
|
96 |
|
|
if (easyrule_pass_rule_add($_GET['int'], $_GET['proto'], $_GET['src'], $_GET['dst'], $_GET['dstport'])) {
|
97 |
|
|
/* Shouldn't get here, the function should redirect. */
|
98 |
|
|
$message .= "Successfully added pass rule!" . "<br/>";
|
99 |
|
|
} else {
|
100 |
|
|
$message .= "Failed to add pass rule." . "<br/>";
|
101 |
|
|
}
|
102 |
|
|
} else {
|
103 |
|
|
$message = "Missing parameters for pass rule";
|
104 |
|
|
break;
|
105 |
|
|
}
|
106 |
|
|
break;
|
107 |
|
|
}
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
if(stristr($retval, "error") == true)
|
111 |
|
|
$message = $retval;
|
112 |
|
|
|
113 |
|
|
include("head.inc"); ?>
|
114 |
|
|
<body link="#000000" vlink="#000000" alink="#000000">
|
115 |
|
|
<? include("fbegin.inc"); ?>
|
116 |
|
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
117 |
|
|
<tr>
|
118 |
|
|
<td>
|
119 |
|
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
120 |
|
|
|
121 |
|
|
<?php if ($message) { ?>
|
122 |
|
|
<br/>
|
123 |
|
|
Message: <?php echo $message; ?>
|
124 |
|
|
<br/>
|
125 |
|
|
<? } else { ?>
|
126 |
|
|
This is the Easy Rule status page, mainly used to display errors when adding rules.
|
127 |
|
|
If you are seeing this, there apparently was not an error, and you navigated to the
|
128 |
|
|
page directly without telling it what to do.<br/><br/>
|
129 |
1ae87edd
|
jim-p
|
This page is meant to be called from the block/pass buttons on the Firewall Logs page, <a href="diag_logs_filter.php">Status > System Logs,
|
130 |
c0b6fdde
|
jim-p
|
Firewall Tab</a>.
|
131 |
|
|
<br />
|
132 |
|
|
<? } ?>
|
133 |
|
|
</td></tr></table>
|
134 |
|
|
<?php include("fend.inc"); ?>
|