Projet

Général

Profil

Télécharger (8,27 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / services_captiveportal_mac.php @ 2d1e985d

1
<?php
2
/*
3
	services_captiveportal_mac.php
4
	part of m0n0wall (http://m0n0.ch/wall)
5
	
6
	Copyright (C) 2004 Dinesh Nair <dinesh@alphaque.com>
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:	captiveportal
32
*/
33

    
34
##|+PRIV
35
##|*IDENT=page-services-captiveportal-macaddresses
36
##|*NAME=Services: Captive portal: Mac Addresses page
37
##|*DESCR=Allow access to the 'Services: Captive portal: Mac Addresses' page.
38
##|*MATCH=services_captiveportal_mac.php*
39
##|-PRIV
40

    
41
require("guiconfig.inc");
42
require("functions.inc");
43
require_once("filter.inc");
44
require("shaper.inc");
45
require("captiveportal.inc");
46

    
47
$cpzone = $_GET['zone'];
48
if (isset($_POST['zone']))
49
        $cpzone = $_POST['zone'];
50

    
51
if (empty($cpzone) || empty($config['captiveportal'][$cpzone])) {
52
        header("Location: services_captiveportal_zones.php");
53
        exit;
54
}
55

    
56
if (!is_array($config['captiveportal']))
57
        $config['captiveportal'] = array();
58
$a_cp =& $config['captiveportal'];
59

    
60
$pgtitle = array(gettext("Services"),gettext("Captive portal"), $a_cp[$cpzone]['zone']);
61
$shortcut_section = "captiveportal";
62

    
63
if ($_POST) {
64

    
65
	$pconfig = $_POST;
66

    
67
	if ($_POST['apply']) {
68
		$retval = 0;
69

    
70
		$rules = captiveportal_passthrumac_configure();
71
		$savemsg = get_std_save_message($retval);
72
		if ($retval == 0)
73
			clear_subsystem_dirty('passthrumac');
74
	}
75

    
76
	if ($_POST['postafterlogin']) {
77
		if (!is_array($a_passthrumacs)) {
78
			echo gettext("No entry exists yet!") ."\n";
79
			exit;
80
		}
81
		if (empty($_POST['zone'])) {
82
			echo gettext("Please set the zone on which the operation should be allowed");
83
			exit;
84
		}
85
		if (!is_array($a_cp[$cpzone]['passthrumac']))
86
			$a_cp[$cpzone]['passthrumac'] = array();
87
		$a_passthrumacs =& $a_cp[$cpzone]['passthrumac'];
88

    
89
		if ($_POST['username']) {
90
			$mac = captiveportal_passthrumac_findbyname($_POST['username']);
91
			if (!empty($mac))
92
				$_POST['delmac'] = $mac['mac'];	
93
			else
94
				echo gettext("No entry exists for this username:") . " " . $_POST['username'] . "\n";
95
		}
96
		if ($_POST['delmac']) {
97
			$found = false;
98
			foreach ($a_passthrumacs as $idx => $macent) {
99
				if ($macent['mac'] == $_POST['delmac']) {
100
					$found = true;
101
					break;
102
				}
103
			}
104
			if ($found == true) {
105
				$ruleno = captiveportal_get_ipfw_passthru_ruleno($_POST['delmac']);
106
				if ($ruleno) {
107
					captiveportal_free_ipfw_ruleno($ruleno);
108
					$pipeno = captiveportal_get_dn_passthru_ruleno($_POST['delmac']);
109
					if ($pipeno)
110
						captiveportal_free_dn_ruleno($pipeno);
111
					if (!empty($pipeno))
112
						mwexec("/sbin/ipfw -x {$cpzone} -q delete {$ruleno}; /sbin/ipfw -x {$cpzone} -q delete " . ++$ruleno . "; /sbin/ipfw -q pipe delete {$pipeno}; /sbin/ipfw -q pipe delete " . (++$pipeno));
113
					else
114
						mwexec("/sbin/ipfw -x {$cpzone} -q delete {$ruleno}; /sbin/ipfw -x {$cpzone} -q delete " . ++$ruleno);
115
				}
116
				unset($a_passthrumacs[$idx]);
117
				write_config();
118
				echo gettext("The entry was sucessfully deleted") . "\n";
119
			} else
120
				echo gettext("No entry exists for this mac address:") . " " .  $_POST['delmac'] . "\n";
121
		}
122
		exit;
123
	}
124
}
125

    
126
if ($_GET['act'] == "del") {
127
	$a_passthrumacs =& $a_cp[$cpzone]['passthrumac'];
128
	if ($a_passthrumacs[$_GET['id']]) {
129
		$ruleno = captiveportal_get_ipfw_passthru_ruleno($a_passthrumacs[$_GET['id']]['mac']);
130
		if ($ruleno) {
131
			captiveportal_free_ipfw_ruleno($ruleno);
132
			$pipeno = captiveportal_get_dn_passthru_ruleno($a_passthrumacs[$_GET['id']]['mac']);
133
			if ($pipeno)
134
				captiveportal_free_dn_ruleno($pipeno);
135
			if (!empty($pipeno))
136
				mwexec("/sbin/ipfw -x {$cpzone} -q delete {$ruleno}; /sbin/ipfw -x {$cpzone} -q delete " . ++$ruleno . "; /sbin/ipfw -q pipe delete {$pipeno}; /sbin/ipfw -q pipe delete " . (++$pipeno));
137
			else
138
				mwexec("/sbin/ipfw -x {$cpzone} -q delete {$ruleno}; /sbin/ipfw -x {$cpzone} -q delete " . ++$ruleno);
139
		}
140
		unset($a_passthrumacs[$_GET['id']]);
141
		write_config();
142
		header("Location: services_captiveportal_mac.php?zone={$cpzone}");
143
		exit;
144
	}
145
}
146

    
147
include("head.inc");
148

    
149
?>
150
<?php include("fbegin.inc"); ?>
151
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
152
<form action="services_captiveportal_mac.php" method="post">
153
<input type="hidden" name="zone" id="zone" value="<?=htmlspecialchars($cpzone);?>"/>
154
<?php if ($savemsg) print_info_box($savemsg); ?>
155
<?php if (is_subsystem_dirty('passthrumac')): ?><p>
156
<?php print_info_box_np(gettext("The captive portal MAC address configuration has been changed.<br>You must apply the changes in order for them to take effect."));?><br>
157
<?php endif; ?>
158
<table width="100%" border="0" cellpadding="0" cellspacing="0">
159
  <tr><td class="tabnavtbl">
160
<?php
161
	$tab_array = array();
162
	$tab_array[] = array(gettext("Captive portal"), false, "services_captiveportal.php?zone={$cpzone}");
163
	$tab_array[] = array(gettext("Pass-through MAC"), true, "services_captiveportal_mac.php?zone={$cpzone}");
164
	$tab_array[] = array(gettext("Allowed IP addresses"), false, "services_captiveportal_ip.php?zone={$cpzone}");
165
	$tab_array[] = array(gettext("Allowed Hostnames"), false, "services_captiveportal_hostname.php?zone={$cpzone}");
166
	$tab_array[] = array(gettext("Vouchers"), false, "services_captiveportal_vouchers.php?zone={$cpzone}");
167
	$tab_array[] = array(gettext("File Manager"), false, "services_captiveportal_filemanager.php?zone={$cpzone}");
168
	display_top_tabs($tab_array, true);
169
?>
170
  </td></tr>
171
  <tr>
172
  <td class="tabcont">
173
  <table width="100%" border="0" cellpadding="0" cellspacing="0">
174
	<tr>
175
	  <td width="40%" class="listhdrr"><?=gettext("MAC address"); ?></td>
176
	  <td width="50%" class="listhdr"><?=gettext("Description"); ?></td>
177
	  <td width="10%" class="list"></td>
178
	</tr>
179
<?php	if (is_array($a_cp[$cpzone]['passthrumac'])):
180
		$i = 0; foreach ($a_cp[$cpzone]['passthrumac'] as $mac): ?>
181
	<tr ondblclick="document.location='services_captiveportal_mac_edit.php?zone=<?=$cpzone;?>&id=<?=$i;?>'">
182
	  <td class="listlr">
183
		<?=$mac['mac'];?>
184
	  </td>
185
	  <td class="listbg">
186
		<?=htmlspecialchars($mac['descr']);?>&nbsp;
187
	  </td>
188
	  <td valign="middle" nowrap class="list"> <a href="services_captiveportal_mac_edit.php?zone=<?=$cpzone;?>&id=<?=$i;?>"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit host"); ?>" width="17" height="17" border="0"></a>
189
		 &nbsp;<a href="services_captiveportal_mac.php?zone=<?=$cpzone;?>&act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this host?"); ?>')"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete host"); ?>" width="17" height="17" border="0"></a></td>
190
	</tr>
191
  <?php $i++; endforeach; endif; ?>
192
	<tr> 
193
	  <td class="list" colspan="2">&nbsp;</td>
194
	  <td class="list"> <a href="services_captiveportal_mac_edit.php?zone=<?=$cpzone;?>"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add host"); ?>" width="17" height="17" border="0"></a></td>
195
	</tr>
196
	<tr>
197
	<td colspan="2" class="list"><span class="vexpl"><span class="red"><strong>
198
	<?=gettext("Note:"); ?><br>
199
	</strong></span>
200
	<?=gettext("Adding MAC addresses as pass-through MACs allows them access through the captive portal automatically without being taken to the portal page."); ?> </span></td>
201
	<td class="list">&nbsp;</td>
202
	</tr>
203
  </table>
204
  </td>
205
  </tr>
206
  </table>
207
</form>
208
<?php include("fend.inc"); ?>
209
</body>
210
</html>
(142-142/246)