Subversion Repositories ALCASAR

Rev

Rev 2853 | Rev 2888 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
2411 tom.houday 1
<?php
2265 richard 2
/********************
3
* READ CONF FILES   *
4
*********************/
2411 tom.houday 5
define("CONF_FILE", "/usr/local/etc/alcasar.conf");
6
define("ETHERS_INFO_FILE", "/usr/local/etc/alcasar-ethers-info");
2274 richard 7
$conf_files=array(CONF_FILE,ETHERS_INFO_FILE);
2411 tom.houday 8
foreach ($conf_files as $file) {
9
	if (!file_exists($file)) {
10
		exit("Requested file ".$file." isn't present");
11
	}
12
	if (!is_readable($file)) {
13
		exit("Can't read the file ".$file);
14
	}
2265 richard 15
}
2411 tom.houday 16
 
2299 tom.houday 17
$alcasar_conf_file = '/usr/local/etc/alcasar.conf';
18
$file_conf = fopen($alcasar_conf_file, 'r');
19
if (!$file_conf) {
20
	exit('Error opening the file '.$alcasar_conf_file);
21
}
22
while (!feof($file_conf)) {
23
	$buffer = fgets($file_conf, 4096);
24
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
2450 tom.houday 25
		$tmp = explode('=', $buffer, 2);
2299 tom.houday 26
		$conf[trim($tmp[0])] = trim($tmp[1]);
1667 richard 27
	}
28
}
2299 tom.houday 29
fclose($file_conf);
30
 
1667 richard 31
$tmp = explode("/",$conf["PRIVATE_IP"]);
32
$intif = $conf["INTIF"];
33
$private_ip=$tmp[0];
34
require('/etc/freeradius-web/config.php');
35
# Choice of language
36
$Language = 'en';
2411 tom.houday 37
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
38
	$Langue = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
39
	$Language = strtolower(substr(chop($Langue[0]), 0, 2));
1667 richard 40
}
2411 tom.houday 41
if ($Language === 'fr') {
42
	$l_activity = "Activité sur le réseau de consultation";
43
	$l_ip_adr = "Adresse IP";
44
	$l_mac_adr = "Adresse MAC";
45
	$l_user = "Usager";
46
	$l_mac_allowed = "@MAC autorisée";
47
	$l_mac_temporarily_allowed = "@MAC autorisée temporairement";
48
	$l_action = "Action";
49
	$l_dissociate = "Dissocier @IP";
50
	$l_disconnect = "Déconnecter";
2770 rexy 51
	$l_stop_capture_disconnect = "Arrêter la capture et se déconnecter";
2411 tom.houday 52
	$l_refresh = "Cette page est rafraichie toutes les 30 secondes";
2770 rexy 53
	$l_edit_user = "Editer l'utilisateur";
2411 tom.houday 54
	$l_connect = "Autoriser temporairement";
2770 rexy 55
	$l_captureon = "Autoriser et capturer";
56
	$l_captureoff = "Arrêter la capture";
57
	$l_captureonly_on = "Capturer";
2853 rexy 58
} else if ($Language === 'es') {
59
	$l_activity = "Actividad en la LAN";
60
	$l_ip_adr = "Dirección IP";
61
	$l_mac_adr = "MAC Adress";
62
	$l_user = "Usuario";
63
	$l_mac_allowed = "@MAC autorizada";
64
	$l_mac_temporarily_allowed = "@MAC temporalmente autorizada";
65
	$l_action = "Acción";
66
	$l_dissociate = "Liberar @IP";
67
	$l_disconnect = "Desconectar";
68
	$l_stop_capture_disconnect = "Deje de capturar y desconecte";
69
	$l_refresh = "Esta información es actualizada cada 30''";
70
	$l_edit_user = "usuario de edición"; 
71
	$l_connect = "Permitir temporalmente";
72
	$l_captureon = "Autorizar y capturar";
73
	$l_captureoff = "Detener la captura";
74
	$l_captureonly_on = "Captura";
2411 tom.houday 75
} else {
76
	$l_activity = "Activity on the consultation LAN";
77
	$l_ip_adr = "IP Adress";
78
	$l_mac_adr = "MAC Adress";
79
	$l_user = "User";
80
	$l_mac_allowed = "@MAC allowed";
81
	$l_mac_temporarily_allowed = "@MAC temporarily allowed";
82
	$l_action = "Action";
83
	$l_dissociate = "Dissociate @IP";
84
	$l_disconnect = "Disconnect";
2770 rexy 85
	$l_stop_capture_disconnect = "Stop capture and disconnect";
2411 tom.houday 86
	$l_refresh = "This frame is refreshed every 30'";
2770 rexy 87
	$l_edit_user = "Edit user";
2411 tom.houday 88
	$l_connect = "Temporarily authorize";
2770 rexy 89
	$l_captureon = "Authorize and capture";
90
	$l_captureoff = "Stop capture";
91
	$l_captureonly_on = "Capture";
1667 richard 92
}
2887 rexy 93
function taille_fichier($fichier)
94
{
95
	$taille_fichier = filesize($fichier);
96
	if ($taille_fichier >= 1073741824){
97
		$taille_fichier = round($taille_fichier / 1073741824 * 100) / 100 . " Go";}
98
	elseif ($taille_fichier >= 1048576){
99
		$taille_fichier = round($taille_fichier / 1048576 * 100) / 100 . " Mo";}
100
	elseif ($taille_fichier >= 1024){
101
		$taille_fichier = round($taille_fichier / 1024 * 100) / 100 . " Ko";}
102
	else {$taille_fichier = $taille_fichier . " o";}
103
	return $taille_fichier;
104
}
2411 tom.houday 105
 
1667 richard 106
if (isset($_POST['action'])){
2887 rexy 107
	$mac= str_replace ("'",'',escapeshellarg($_POST['mac_addr']));
108
	unset($_POST['mac_addr']);
1667 richard 109
	switch ($_POST['action']){
2065 raphael.pi 110
		case "$l_disconnect" :
2887 rexy 111
			exec("sudo /usr/sbin/chilli_query logout ".$mac);
1667 richard 112
		break;
2770 rexy 113
		case "$l_stop_capture_disconnect" :
114
			exec('sudo /usr/local/bin/alcasar-iot_capture.sh -k '.$mac.' &>/dev/null &');
2887 rexy 115
			exec("sudo /usr/sbin/chilli_query logout ".$mac);
2770 rexy 116
		break;
2065 raphael.pi 117
		case "$l_dissociate" :
2887 rexy 118
			exec("sudo /usr/sbin/chilli_query dhcp-release ".$mac);
1667 richard 119
		break;
2065 raphael.pi 120
		case "$l_connect" :
2887 rexy 121
			exec("sudo /usr/sbin/chilli_query authorize mac ".$mac);
2065 raphael.pi 122
		break;
2770 rexy 123
		case "$l_captureon" :
124
			exec('sudo /usr/local/bin/alcasar-iot_capture.sh -l '.$mac.' &>/dev/null &');
2887 rexy 125
			exec("sudo /usr/sbin/chilli_query authorize mac ".$mac);
2770 rexy 126
		break;
127
		case "$l_captureonly_on" :
128
			exec('sudo /usr/local/bin/alcasar-iot_capture.sh -l '.$mac.' &>/dev/null &');
129
		break;	
130
		case "$l_captureoff" :
131
			exec('sudo /usr/local/bin/alcasar-iot_capture.sh -k '.$mac.' &>/dev/null &');
132
		break;
1667 richard 133
	}
134
}
135
?>
2411 tom.houday 136
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2810 rexy 137
<html><!-- written by Rexy -->
2411 tom.houday 138
<head>
2810 rexy 139
<meta HTTP-EQUIV="Refresh" CONTENT="30">
2411 tom.houday 140
<meta http-equiv="Content-Type" content="text/html; charset=<?= $config['general_charset'] ?>">
141
<title>Activity</title>
2817 rexy 142
<link rel="stylesheet" type="text/css" href="/css/acc.css">
2411 tom.houday 143
</head>
144
<body>
145
<table width="100%" border="0" cellspacing="0" cellpadding="0">
146
<tr><th><?= $l_activity ?></th></tr>
147
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
148
</table>
2134 richard 149
<table width="100%" border=1 cellspacing=0 cellpadding=1>
2411 tom.houday 150
	<tr><td valign="middle" align="center"><?= $l_refresh ?><br>
151
	<table border=1 width="80%" cellpadding=2 cellspacing=0>
152
		<tr>
153
			<th>#</th>
154
			<th><?= $l_ip_adr ?></th>
155
			<th><?= $l_mac_adr ?></th>
156
			<th><?= $l_user ?></th>
157
			<th><?= $l_action ?></th>
158
		</tr>
159
		<?php
2770 rexy 160
		$IoT_capture = $conf["IOT_CAPTURE"];
1667 richard 161
		$output = array(); $detail = array(); $nb_ligne = 0;
2299 tom.houday 162
		exec("sudo /sbin/ip link show ".escapeshellarg($intif), $output); // retrieve ALCASAR MAC address
1667 richard 163
		$detail = explode (" " , $output[1]);
164
		$intif_mac_addr=strtoupper(str_replace(":","-",$detail[5]));
165
		unset ($output);unset ($detail);
2080 richard 166
		exec ('sudo /usr/sbin/chilli_query list|sort -k5 -r', $output); 
1667 richard 167
		while (list(,$ligne) = each($output)){
168
			$detail = explode (" ", $ligne);
169
			$nb_ligne ++;
2134 richard 170
			echo "<tr valign=\"middle\">";
171
			echo "<td>".$nb_ligne."</td>";
172
			echo "<td>".$detail[1]."</td>";
2080 richard 173
			if(file_exists('/usr/share/arp-scan/ieee-oui.txt')) // for each device on LAN, retrieve the MAC manufacturer
2065 raphael.pi 174
			{
175
				$oui_id = substr(str_replace("-","",$detail[0]),0,6);
176
				exec ("grep $oui_id /usr/share/arp-scan/ieee-oui.txt | cut -f2", $mac_manufacturer);
2095 raphael.pi 177
				if(empty($mac_manufacturer[0]))
2265 richard 178
				{
179
					$mac_manufacturer[0] = "Unknown";
180
				}
181
				echo "<td>$detail[0] <font size=\"1\">($mac_manufacturer[0])</font>";
2078 raphael.pi 182
				unset($mac_manufacturer);
2065 raphael.pi 183
			}
184
			else
185
			{
2265 richard 186
				echo "<td>$detail[0]";
2065 raphael.pi 187
			}
2274 richard 188
			exec ("grep $detail[0] /usr/local/etc/alcasar-ethers-info |cut -d' ' -f3", $mac_in_ether_file);
2265 richard 189
			if (!empty($mac_in_ether_file[0]))
190
			{
191
				echo " - <b>" . ltrim($mac_in_ether_file[0],'#') . "</b>";
192
			}
193
			echo "</td><td>";
2080 richard 194
			if ($detail[4] == "1"){ // authenticated equipment
195
				$login = $detail[5];
2128 richard 196
				unset ($found_users); unset ($cn);
197
				$search = $login; $search_IN = 'username'; // is user in database ?
2080 richard 198
				if (is_file("../lib/sql/find.php"))
2770 rexy 199
				include("../lib/sql/find.php");
2080 richard 200
				if (isset ($found_users)) // user is in database
201
				{
2128 richard 202
					if (is_file("../lib/sql/user_info.php")) //retrieve user info (especialy $cn)
2080 richard 203
						include("../lib/sql/user_info.php");
1667 richard 204
				}
2128 richard 205
				if (! isset ($cn)){ $cn='-';}
2080 richard 206
				# The user is an allowed MAC address
207
					if ($detail[5] == $detail[0]){
2128 richard 208
						if (isset ($found_users)) { #MAC is in database
2129 richard 209
							echo "<a href=\"/acc/manager/htdocs/user_admin.php?login=$detail[5]\" title=\"$l_edit_user\">$l_mac_allowed";if ($cn != '-'){ echo " ($cn)";};echo "</a>";
210
							echo "</td><td>";
2128 richard 211
						}
2129 richard 212
						else { #MAC is temporarily allowed
2265 richard 213
							echo "<b>$l_mac_temporarily_allowed</b>";
2129 richard 214
							echo "</td><td>";
2411 tom.houday 215
							echo "<FORM action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\">";
216
							echo "<INPUT type=\"hidden\" name=\"mac_addr\" value=\"$detail[0]\">";
2770 rexy 217
 
218
							if($IoT_capture == "on")
219
							{
220
								if(exec('sudo /usr/local/bin/alcasar-iot_capture.sh -i '.$detail[0]) == "CaptureON")
221
								{
222
									echo "<INPUT type=\"submit\" name=\"action\" value=\"$l_stop_capture_disconnect\">";
223
									echo "<INPUT type=\"submit\" name=\"action\" value=\"$l_captureoff\">";
224
								}
225
 								else
226
								{
227
									echo "<INPUT type=\"submit\" name=\"action\" value=\"$l_disconnect\">";
2887 rexy 228
									echo "<BR><INPUT type=\"submit\" name=\"action\" value=\"$l_captureonly_on\">";
229
									$file = '/var/Save/iot_captures/'.$mac.'.pcap';
230
									if (file_exists($file))
231
										{
232
										echo "<BR><a href=\"/save/iot_captures/$mac.pcap\">$mac.pcap</a> (";echo taille_fichier("/var/Save/iot_captures/".$mac.".pcap");echo ")";
233
										}
2770 rexy 234
								}
235
							}
236
							else
237
								echo "<INPUT type=\"submit\" name=\"action\" value=\"$l_disconnect\">";
238
 
2134 richard 239
							echo "</FORM></TD>";
2128 richard 240
						}
2080 richard 241
						# Disable temporarily @MAC access
2129 richard 242
					}
2080 richard 243
				# The user is a humanoide ;-)
244
					else {
245
						if ($cn != '-') { echo "<a href=\"/acc/manager/htdocs/user_admin.php?login=$detail[5]\" title=\"$l_edit_user $detail[5]\">$detail[5] ($cn)</a>";}
246
						else { echo "<a href=\"/acc/manager/htdocs/user_admin.php?login=$detail[5]\" title=\"$l_edit_user $detail[5]\">$detail[5]</a>";}
247
						echo "<TD>";
2411 tom.houday 248
						echo "<FORM action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\">";
249
						echo "<INPUT type=\"hidden\" name=\"mac_addr\" value=\"$detail[0]\">";
250
						echo "<INPUT type=\"submit\" name=\"action\" value=\"$l_disconnect\">";
2134 richard 251
						echo "</FORM></TD>";
2080 richard 252
						}
1667 richard 253
					}
254
			# equipment without authenticated user
255
			else if (($detail[0] == $intif_mac_addr) || ($detail[1] == $private_ip)){
256
				echo "ALCASAR system";
257
				echo "<TD>";
258
				echo "&nbsp;";
2134 richard 259
				echo "</TD>";
2080 richard 260
				}	
261
			else {  
1667 richard 262
				echo "&nbsp;";
2134 richard 263
				echo "<TD>";		
2411 tom.houday 264
				echo "<FORM action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\">";
2065 raphael.pi 265
				# Dissociate user (... or other) who is not connected yet
2411 tom.houday 266
				echo "<INPUT type=\"hidden\" name=\"mac_addr\" value=\"$detail[0]\">";
2276 richard 267
				exec ("grep $detail[0] /usr/local/etc/alcasar-ethers-info", $mac_in_ether_file);
268
				if (empty($mac_in_ether_file[1]))
2265 richard 269
				{
2411 tom.houday 270
					echo "<INPUT type=\"submit\" name=\"action\" value=\"$l_dissociate\">"; // Dissociate only MAC not in ether file (dhcp)
2265 richard 271
				}
2411 tom.houday 272
				echo "<INPUT type=\"submit\" name=\"action\" value=\"$l_connect\">"; // Enable temporarily @MAC access
2770 rexy 273
 
274
				if($IoT_capture == "on")
275
				{
276
					if(exec('sudo /usr/local/bin/alcasar-iot_capture.sh -i '.$detail[0]) == "CaptureON")
277
					{
2887 rexy 278
						echo "<BR><INPUT type=\"submit\" name=\"action\" value=\"$l_captureoff\">";
2770 rexy 279
					}
280
					else
281
					{
2887 rexy 282
						echo "<BR><INPUT type=\"submit\" name=\"action\" value=\"$l_captureon\">";
2770 rexy 283
						echo "<INPUT type=\"submit\" name=\"action\" value=\"$l_captureonly_on\">";
2887 rexy 284
						$file = '/var/Save/iot_captures/'.$mac.'.pcap';
285
						if (file_exists($file))
286
							{
287
							echo "<BR><a href=\"/save/iot_captures/$mac.pcap\">$mac.pcap</a> (";echo taille_fichier("/var/Save/iot_captures/".$mac.".pcap");echo ")";
288
							}
2770 rexy 289
					}
290
				}
2134 richard 291
				echo "</FORM></TD>";
1667 richard 292
			}
2265 richard 293
			unset ($mac_in_ether_file);
2134 richard 294
			echo "</tr>";
1667 richard 295
		}
296
		?>
297
	</table>
298
	</td></tr>
299
</table>
300
</html>
2065 raphael.pi 301