Révision b1a27b8a
Ajouté par Thomas Noël il y a plus de 9 ans
usr/local/univnautes/sp/cp_get_sessions | ||
---|---|---|
1 |
#!/usr/local/bin/php -f |
|
2 |
<?php |
|
3 |
|
|
4 |
/* |
|
5 |
* cp_get_session [cpzone=....] [ip=... [mac=...]] [username=...] |
|
6 |
* output on stdout: list of sessionid (one by line) |
|
7 |
*/ |
|
8 |
|
|
9 |
global $cpzone, $config; |
|
10 |
|
|
11 |
$ip = $mac = $username = $cpzone = null; |
|
12 |
|
|
13 |
array_shift($argv); |
|
14 |
foreach ($argv as $arg) { |
|
15 |
list($name, $value) = explode('=', $arg, 2); |
|
16 |
switch($name) { |
|
17 |
case 'ip': |
|
18 |
$ip=$value; |
|
19 |
break; |
|
20 |
case 'mac': |
|
21 |
$mac=$value; |
|
22 |
break; |
|
23 |
case 'username': |
|
24 |
$username=$value; |
|
25 |
break; |
|
26 |
case 'cpzone': |
|
27 |
$cpzone=$value; |
|
28 |
break; |
|
29 |
} |
|
30 |
} |
|
31 |
|
|
32 |
if ( $ip != null ) { |
|
33 |
// check IP format (ipv4 only) |
|
34 |
if (! preg_match( '/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/', $ip)) { |
|
35 |
exit(2); |
|
36 |
} |
|
37 |
|
|
38 |
if ( $mac == null ) { |
|
39 |
// search MAC in ARP cache |
|
40 |
require("util.inc"); |
|
41 |
$mac=arp_get_mac_by_ip($ip); |
|
42 |
} |
|
43 |
|
|
44 |
// check MAC format |
|
45 |
if (! preg_match( '/^([0-9A-F]{2}:){5}[0-9A-F]{2}$/i', $mac)) { |
|
46 |
exit(3); |
|
47 |
} |
|
48 |
} |
|
49 |
|
|
50 |
require("captiveportal.inc"); |
|
51 |
|
|
52 |
function show_sessions($zone) { |
|
53 |
global $cpzone; |
|
54 |
$cpzone = $zone; |
|
55 |
$cpdb = captiveportal_read_db(); |
|
56 |
foreach ($cpdb as $cpentry) { |
|
57 |
print $cpentry[5] . "\n"; |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
61 |
// check if cpzone is defined |
|
62 |
if ( $cpzone == null ) { |
|
63 |
foreach ($config['captiveportal'] as $cpkey => $cp) { |
|
64 |
if ($cp['auth_method'] == 'saml') { |
|
65 |
show_sessions($cpkey); |
|
66 |
} |
|
67 |
} |
|
68 |
} else { |
|
69 |
show_sessions($cpzone); |
|
70 |
} |
|
71 |
|
|
72 |
?> |
Formats disponibles : Unified diff
add cp_get_sessions script (php)