Project

General

Profile

Download (5.01 KB) Statistics
| Branch: | Tag: | Revision:
1
<?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
/*
31
	pfSense_MODULE:	filter
32
*/
33

    
34
$pgtitle = "Status : EasyRule";
35
require_once("guiconfig.inc");
36
require_once("easyrule.inc");
37
require_once("filter.inc");
38
require_once("shaper.inc");
39

    
40
$retval = 0;
41
$message = "";
42
$specialsrcdst = explode(" ", "any pptp pppoe l2tp openvpn");
43

    
44
if ($_GET && isset($_GET['action'])) {
45
	switch ($_GET['action']) {
46
		case 'block':
47
			/* Check that we have a valid host */
48
			if (isset($_GET['src']) && isset($_GET['int'])) {
49
				if (!is_ipaddr($_GET['src'])) {
50
					$message .= "Tried to block invalid IP: " . htmlspecialchars($_GET['src']) . "<br/>";
51
					break;
52
				}
53
				$_GET['int'] = easyrule_find_rule_interface($_GET['int']);
54
				if ($_GET['int'] === false) {
55
					$message .= "Invalid interface for block rule: " . htmlspecialchars($_GET['int']) . "<br/>";
56
					break;
57
				}
58
				if (easyrule_block_host_add($_GET['src'], $_GET['int'])) {
59
					/* shouldn't get here, the function will redirect */
60
					$message .= "Host added successfully" . "<br/>";
61
				} else {
62
					$message .= "Failed to create block rule, alias, or add host." . "<br/>";
63
				}
64
			} else {
65
				$message .= "Tried to block but had no host IP or interface<br/>";
66
			}
67
			break;
68
		case 'pass':
69
			/* Check for valid int, srchost, dsthost, dstport, and proto */
70
			if (isset($_GET['int']) && isset($_GET['proto']) && isset($_GET['src']) && isset($_GET['dst'])) {
71
				$_GET['int'] = easyrule_find_rule_interface($_GET['int']);
72
				if ($_GET['int'] === false) {
73
					$message .= "Invalid interface for pass rule: " . htmlspecialchars($_GET['int']) . "<br/>";
74
					break;
75
				}
76
				if (getprotobyname($_GET['proto']) == -1) {
77
					$message .= "Invalid protocol for pass rule: " . htmlspecialchars($_GET['proto']) . "<br/>";
78
					break;
79
				}
80
				if (!is_ipaddr($_GET['src'])) {
81
					$message .= "Tried to pass invalid source IP: " . htmlspecialchars($_GET['src']) . "<br/>";
82
					break;
83
				}
84
				if (!is_ipaddr($_GET['dst'])) {
85
					$message .= "Tried to pass invalid destination IP: " . htmlspecialchars($_GET['dst']) . "<br/>";
86
					break;
87
				}
88
				if (($_GET['proto'] != 'icmp') && !isset($_GET['dstport'])) {
89
					$message .= "Missing destination port: " . htmlspecialchars($_GET['dstport']) . "<br/>";
90
					break;
91
				}
92
				if ($_GET['proto'] == 'icmp') {
93
					$_GET['dstport'] = 0;
94
				}
95
				if (!is_numeric($_GET['dstport']) || ($_GET['dstport'] < 0) || ($_GET['dstport'] > 65536)) {
96
					$message .= "Tried to pass invalid destination port: " . htmlspecialchars($_GET['dstport']) . "<br/>";
97
					break;
98
				}
99
				/* Should have valid input... */
100
				if (easyrule_pass_rule_add($_GET['int'], $_GET['proto'], $_GET['src'], $_GET['dst'], $_GET['dstport'])) {
101
					/* Shouldn't get here, the function should redirect. */
102
					$message .= "Successfully added pass rule!" . "<br/>";
103
				} else {
104
					$message .= "Failed to add pass rule." . "<br/>";
105
				}
106
			} else {
107
				$message = "Missing parameters for pass rule";
108
				break;
109
			}
110
			break;
111
	}
112
}
113

    
114
if(stristr($retval, "error") == true)
115
    $message = $retval;
116

    
117
include("head.inc"); ?>
118
<body link="#000000" vlink="#000000" alink="#000000">
119
<? include("fbegin.inc"); ?>
120
<table width="100%" border="0" cellpadding="0" cellspacing="0">
121
	<tr>
122
		<td>
123
<?php if ($input_errors) print_input_errors($input_errors); ?>
124

    
125
<?php if ($message) { ?>
126
<br/>
127
Message: <?php echo $message; ?>
128
<br/>
129
<? } else { ?>
130
This is the Easy Rule status page, mainly used to display errors when adding rules. 
131
If you are seeing this, there apparently was not an error, and you navigated to the
132
page directly without telling it what to do.<br/><br/>
133
This page is meant to be called from the block/pass buttons on the Firewall Logs page, <a href="diag_logs_filter.php">Status &gt; System Logs,
134
Firewall Tab</a>.
135
<br />      
136
<? } ?>
137
</td></tr></table>
138
<?php include("fend.inc"); ?>
(40-40/215)