status_captiveportal.php 8.88 KB
Newer Older
1
<?php
Ad Schellevis's avatar
Ad Schellevis committed
2
/*
3
	Copyright (C) 2014-2015 Deciso B.V.
Ad Schellevis's avatar
Ad Schellevis committed
4 5
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
	All rights reserved.
6

Ad Schellevis's avatar
Ad Schellevis committed
7 8
	Redistribution and use in source and binary forms, with or without
	modification, are permitted provided that the following conditions are met:
9

Ad Schellevis's avatar
Ad Schellevis committed
10 11
	1. Redistributions of source code must retain the above copyright notice,
	   this list of conditions and the following disclaimer.
12

Ad Schellevis's avatar
Ad Schellevis committed
13 14 15
	2. Redistributions in binary form must reproduce the above copyright
	   notice, this list of conditions and the following disclaimer in the
	   documentation and/or other materials provided with the distribution.
16

Ad Schellevis's avatar
Ad Schellevis committed
17 18 19 20 21 22 23 24 25 26 27 28
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
	POSSIBILITY OF SUCH DAMAGE.
*/

29 30
require_once("guiconfig.inc");
require_once("captiveportal.inc");
31
require_once("services.inc");
32
require_once("pfsense-utils.inc");
33
require_once("interfaces.inc");
Ad Schellevis's avatar
Ad Schellevis committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

$cpzone = $_GET['zone'];
if (isset($_POST['zone']))
	$cpzone = $_POST['zone'];

if ($_GET['act'] == "del" && !empty($cpzone)) {
	captiveportal_disconnect_client($_GET['id']);
	header("Location: status_captiveportal.php?zone={$cpzone}");
	exit;
}

$pgtitle = array(gettext("Status: Captive portal"));
$shortcut_section = "captiveportal";

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

if (count($a_cp) == 1)
 $cpzone = current(array_keys($a_cp));

include("head.inc");

?>

59

Ad Schellevis's avatar
Ad Schellevis committed
60 61 62 63 64 65 66 67 68 69
<?php

flush();

function clientcmp($a, $b) {
	global $order;
	return strcmp($a[$order], $b[$order]);
}

if (!empty($cpzone)) {
70
        $cpdb_handle = new OPNsense\CaptivePortal\DB($cpzone);
71
        $cpclient_handle = new OPNsense\CaptivePortal\CPClient();
72

73
        $order = "";
Ad Schellevis's avatar
Ad Schellevis committed
74
	if ($_GET['order']) {
75 76 77
		if ($_GET['order'] == "ip") $order = "ip";
		else if ($_GET['order'] == "mac") $order = "mac";
		else if ($_GET['order'] == "user") $order = "username";
Ad Schellevis's avatar
Ad Schellevis committed
78
	}
79

80
        $cpdb = $cpdb_handle->listClients(array(),"and",array($order) ) ;
81
        if ($_GET['showact']) {
82
            $accounting_info =  $cpclient_handle->listAccounting();
83 84 85 86
        }
        else {
            $accounting_info = array() ;
        }
87 88 89
}
else {
    $cpdb = array() ;
Ad Schellevis's avatar
Ad Schellevis committed
90
}
91

Ad Schellevis's avatar
Ad Schellevis committed
92 93 94 95 96 97

// Load MAC-Manufacturer table
$mac_man = load_mac_manufacturer_table();

?>

Ad Schellevis's avatar
Ad Schellevis committed
98 99 100 101 102 103 104


<body>
<?php include("fbegin.inc"); ?>


	<section class="page-content-main">
105
		<div class="container-fluid">
Ad Schellevis's avatar
Ad Schellevis committed
106
			<div class="row">
107 108 109



Ad Schellevis's avatar
Ad Schellevis committed
110
			    <section class="col-xs-12">
111

Ad Schellevis's avatar
Ad Schellevis committed
112
					<?php if (!empty($cpzone) && isset($config['voucher'][$cpzone]['enable'])): ?>
113
					<?php
Ad Schellevis's avatar
Ad Schellevis committed
114 115 116 117 118 119 120
							$tab_array = array();
					        $tab_array[] = array(gettext("Active Users"), true, "status_captiveportal.php?zone={$cpzone}");
					        $tab_array[] = array(gettext("Active Vouchers"), false, "status_captiveportal_vouchers.php?zone={$cpzone}");
					        $tab_array[] = array(gettext("Voucher Rolls"), false, "status_captiveportal_voucher_rolls.php?zone={$cpzone}");
					        $tab_array[] = array(gettext("Test Vouchers"), false, "status_captiveportal_test.php?zone={$cpzone}");
							$tab_array[] = array(gettext("Expire Vouchers"), false, "status_captiveportal_expire.php?zone={$cpzone}");
					        display_top_tabs($tab_array);
121
					?>
Ad Schellevis's avatar
Ad Schellevis committed
122
					<?php endif; ?>
123 124 125 126

					<div class="tab-content content-box col-xs-12">

				    <div class="container-fluid">
Ad Schellevis's avatar
Ad Schellevis committed
127 128

	                        <form action="<?=$_SERVER['REQUEST_URI'];?>" method="post" name="iform" id="iform">
129

Ad Schellevis's avatar
Ad Schellevis committed
130 131 132
	                        <div class="table-responsive">
		                        <table class="table table-striped table-sort">
								  <tr>
133
									<td width="20%" class="vncell" valign="top">
Ad Schellevis's avatar
Ad Schellevis committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
								               <br /><?=gettext("Captive Portal Zone"); ?><br/><br />
									</td>
									<td class="vncell" width="30%" align="center">
									<?php if (count($a_cp) >  1) { ?>
									<form action="status_captiveportal.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
										<select name="zone" class="formselect" onchange="document.form1.submit()">
										<option value="">none</option>
										<?php foreach ($a_cp as $cpkey => $cp) {
										       echo "<option value=\"{$cpkey}\" ";
										       if ($cpzone == $cpkey)
											       echo "selected=\"selected\"";
										       echo ">" . htmlspecialchars($cp['zone']) . "</option>\n";
										       }
								               ?>
								               </select>
										<br />
									</form>
									<?php } else echo $a_cp[$cpzone]['zone']; ?>
									</td>
153
									<td colspan="6" width="50%"></td>
Ad Schellevis's avatar
Ad Schellevis committed
154
								  </tr>
155
								  <tr><td colspan="6"><br /></td></tr>
Ad Schellevis's avatar
Ad Schellevis committed
156 157
								<?php if (!empty($cpzone)): ?>
								  <tr>
158
									<td colspan="7" valign="top" class="listtopic"><?=gettext("Captiveportal status");?></td>
Ad Schellevis's avatar
Ad Schellevis committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
								  </tr>
								  <tr>
								    <td class="listhdrr"><a href="?zone=<?=$cpzone?>&amp;order=ip&amp;showact=<?=htmlspecialchars($_GET['showact']);?>"><?=gettext("IP address");?></a></td>
								    <td class="listhdrr"><a href="?zone=<?=$cpzone?>&amp;order=mac&amp;showact=<?=htmlspecialchars($_GET['showact']);?>"><?=gettext("MAC address");?></a></td>
								    <td class="listhdrr"><a href="?zone=<?=$cpzone?>&amp;order=user&amp;showact=<?=htmlspecialchars($_GET['showact']);?>"><?=gettext("Username");?></a></td>
									<?php if ($_GET['showact']): ?>
								    <td class="listhdrr"><a href="?zone=<?=$cpzone?>&amp;order=start&amp;showact=<?=htmlspecialchars($_GET['showact']);?>"><?=gettext("Session start");?></a></td>
								    <td class="listhdr"><a href="?zone=<?=$cpzone?>&amp;order=lastact&amp;showact=<?=htmlspecialchars($_GET['showact']);?>"><?=gettext("Last activity");?></a></td>
									<?php else: ?>
								    <td class="listhdr" colspan="2"><a href="?zone=<?=$cpzone?>&amp;order=start&amp;showact=<?=htmlspecialchars($_GET['showact']);?>"><?=gettext("Session start");?></a></td>
									<?php endif; ?>
								    <td class="list sort_ignore"></td>
								  </tr>
								<?php foreach ($cpdb as $cpent): ?>
								  <tr>
174
								    <td class="listlr"><?=$cpent->ip;?></td>
Ad Schellevis's avatar
Ad Schellevis committed
175 176
									<td class="listr">
										<?php
177
										$mac=trim($cpent->mac);
Ad Schellevis's avatar
Ad Schellevis committed
178 179 180 181 182 183 184
										if (!empty($mac)) {
											$mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]);
											print htmlentities($mac);
											if(isset($mac_man[$mac_hi])){ print "<br /><font size=\"-2\"><i>{$mac_man[$mac_hi]}</i></font>"; }
										}
										?>&nbsp;
									</td>
185 186
								    <td class="listr"><?=htmlspecialchars($cpent->username);?>&nbsp;</td>
								    <td class="listr"><?=htmlspecialchars(date("m/d/Y H:i:s", $cpent->allow_time));?></td>
Ad Schellevis's avatar
Ad Schellevis committed
187
									<?php if ($_GET['showact']):
188
									if ( array_key_exists($cpent->ip,$accounting_info) ) $last_act = $accounting_info[$cpent->ip]['last_accessed'] ;
189
									else $last_act=0;
190
									?>
Ad Schellevis's avatar
Ad Schellevis committed
191 192
								    <td class="listr"><?php if ($last_act != 0) echo htmlspecialchars(date("m/d/Y H:i:s", $last_act));?></td>
									<?php else: ?>
193
								    <td class="listr" colspan="2"></td>
Ad Schellevis's avatar
Ad Schellevis committed
194 195
									<?php endif; ?>
								    <td valign="middle" class="list nowrap">
196
								      <a class="btn btn-default btn-xs" href="?zone=<?=$cpzone;?>&amp;order=<?=$_GET['order'];?>&amp;showact=<?=htmlspecialchars($_GET['showact']);?>&amp;act=del&amp;id=<?=$cpent->sessionid;?>" onclick="return confirm('<?=gettext("Do you really want to disconnect this client?");?>')" title="<?=gettext("Disconnect");?>"><span class="glyphicon glyphicon-remove"></span></a>
Ad Schellevis's avatar
Ad Schellevis committed
197 198 199 200
								    </td>
								  </tr>
								<?php endforeach; endif; ?>
								</table>
201

Ad Schellevis's avatar
Ad Schellevis committed
202
	                        </div>
203 204

	                        </form>
Ad Schellevis's avatar
Ad Schellevis committed
205 206 207 208 209 210 211 212 213 214 215 216 217 218
							<form action="status_captiveportal.php" method="get" style="margin: 14px;">
							<input type="hidden" name="order" value="<?=htmlspecialchars($_GET['order']);?>" />
							<?php if (!empty($cpzone)): ?>
							<?php if ($_GET['showact']): ?>
							<input type="hidden" name="showact" value="0" />
							<input type="submit" class="btn btn-primary" value="<?=gettext("Don't show last activity");?>" />
							<?php else: ?>
							<input type="hidden" name="showact" value="1" />
							<input type="submit" class="btn btn-primary" value="<?=gettext("Show last activity");?>" />
							<?php endif; ?>
							<input type="hidden" name="zone" value="<?=htmlspecialchars($cpzone);?>" />
							<?php endif; ?>
							</form>

219
				    </div>
Ad Schellevis's avatar
Ad Schellevis committed
220 221 222 223 224 225
					</div>
			    </section>
			</div>
		</div>
	</section>

226 227

<?php include("foot.inc"); ?>