Subversion Repositories ALCASAR

Rev

Rev 2299 | Rev 2450 | 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) !== '#')) {
25
		$tmp = explode('=', $buffer);
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";
51
	$l_refresh = "Cette page est rafraichie toutes les 30 secondes";
52
	$l_edit_user = "Editer l'utilisateur"; 
53
	$l_connect = "Autoriser temporairement";
54
} else {
55
	$l_activity = "Activity on the consultation LAN";
56
	$l_ip_adr = "IP Adress";
57
	$l_mac_adr = "MAC Adress";
58
	$l_user = "User";
59
	$l_mac_allowed = "@MAC allowed";
60
	$l_mac_temporarily_allowed = "@MAC temporarily allowed";
61
	$l_action = "Action";
62
	$l_dissociate = "Dissociate @IP";
63
	$l_disconnect = "Disconnect";
64
	$l_refresh = "This frame is refreshed every 30'";
65
	$l_edit_user = "Edit user"; 
66
	$l_connect = "Temporarily authorize";
1667 richard 67
}
2411 tom.houday 68
 
1667 richard 69
if (isset($_POST['action'])){
70
	switch ($_POST['action']){
2065 raphael.pi 71
		case "$l_disconnect" :
2299 tom.houday 72
			exec("sudo /usr/sbin/chilli_query logout ".escapeshellarg($_POST['mac_addr']));
73
			unset($_POST['mac_addr']);
1667 richard 74
		break;
2065 raphael.pi 75
		case "$l_dissociate" :
2299 tom.houday 76
			exec("sudo /usr/sbin/chilli_query dhcp-release ".escapeshellarg($_POST['mac_addr']));
77
			unset($_POST['mac_addr']);
1667 richard 78
		break;
2065 raphael.pi 79
		case "$l_connect" :
2299 tom.houday 80
			exec("sudo /usr/sbin/chilli_query authorize mac ".escapeshellarg($_POST['mac_addr']));
81
			unset($_POST['mac_addr']);
2065 raphael.pi 82
		break;
1667 richard 83
	}
84
}
85
?>
2411 tom.houday 86
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
87
<HTML><!-- written by Rexy -->
88
<head>
89
<META HTTP-EQUIV="Refresh" CONTENT="30">
90
<meta http-equiv="Content-Type" content="text/html; charset=<?= $config['general_charset'] ?>">
91
<title>Activity</title>
92
<link rel="stylesheet" type="text/css" href="/css/style.css">
93
</head>
94
<body>
95
<table width="100%" border="0" cellspacing="0" cellpadding="0">
96
<tr><th><?= $l_activity ?></th></tr>
97
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
98
</table>
2134 richard 99
<table width="100%" border=1 cellspacing=0 cellpadding=1>
2411 tom.houday 100
	<tr><td valign="middle" align="center"><?= $l_refresh ?><br>
101
	<table border=1 width="80%" cellpadding=2 cellspacing=0>
102
		<tr>
103
			<th>#</th>
104
			<th><?= $l_ip_adr ?></th>
105
			<th><?= $l_mac_adr ?></th>
106
			<th><?= $l_user ?></th>
107
			<th><?= $l_action ?></th>
108
		</tr>
109
		<?php
1667 richard 110
		$output = array(); $detail = array(); $nb_ligne = 0;
2299 tom.houday 111
		exec("sudo /sbin/ip link show ".escapeshellarg($intif), $output); // retrieve ALCASAR MAC address
1667 richard 112
		$detail = explode (" " , $output[1]);
113
		$intif_mac_addr=strtoupper(str_replace(":","-",$detail[5]));
114
		unset ($output);unset ($detail);
2080 richard 115
		exec ('sudo /usr/sbin/chilli_query list|sort -k5 -r', $output); 
1667 richard 116
		while (list(,$ligne) = each($output)){
117
			$detail = explode (" ", $ligne);
118
			$nb_ligne ++;
2134 richard 119
			echo "<tr valign=\"middle\">";
120
			echo "<td>".$nb_ligne."</td>";
121
			echo "<td>".$detail[1]."</td>";
2080 richard 122
			if(file_exists('/usr/share/arp-scan/ieee-oui.txt')) // for each device on LAN, retrieve the MAC manufacturer
2065 raphael.pi 123
			{
124
				$oui_id = substr(str_replace("-","",$detail[0]),0,6);
125
				exec ("grep $oui_id /usr/share/arp-scan/ieee-oui.txt | cut -f2", $mac_manufacturer);
2095 raphael.pi 126
				if(empty($mac_manufacturer[0]))
2265 richard 127
				{
128
					$mac_manufacturer[0] = "Unknown";
129
				}
130
				echo "<td>$detail[0] <font size=\"1\">($mac_manufacturer[0])</font>";
2078 raphael.pi 131
				unset($mac_manufacturer);
2065 raphael.pi 132
			}
133
			else
134
			{
2265 richard 135
				echo "<td>$detail[0]";
2065 raphael.pi 136
			}
2274 richard 137
			exec ("grep $detail[0] /usr/local/etc/alcasar-ethers-info |cut -d' ' -f3", $mac_in_ether_file);
2265 richard 138
			if (!empty($mac_in_ether_file[0]))
139
			{
140
				echo " - <b>" . ltrim($mac_in_ether_file[0],'#') . "</b>";
141
			}
142
			echo "</td><td>";
2080 richard 143
			if ($detail[4] == "1"){ // authenticated equipment
144
				$login = $detail[5];
2128 richard 145
				unset ($found_users); unset ($cn);
146
				$search = $login; $search_IN = 'username'; // is user in database ?
2080 richard 147
				if (is_file("../lib/sql/find.php"))
148
					include("../lib/sql/find.php");
149
				if (isset ($found_users)) // user is in database
150
				{
2128 richard 151
					if (is_file("../lib/sql/user_info.php")) //retrieve user info (especialy $cn)
2080 richard 152
						include("../lib/sql/user_info.php");
1667 richard 153
				}
2128 richard 154
				if (! isset ($cn)){ $cn='-';}
2080 richard 155
				# The user is an allowed MAC address
156
					if ($detail[5] == $detail[0]){
2128 richard 157
						if (isset ($found_users)) { #MAC is in database
2129 richard 158
							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>";
159
							echo "</td><td>";
2128 richard 160
						}
2129 richard 161
						else { #MAC is temporarily allowed
2265 richard 162
							echo "<b>$l_mac_temporarily_allowed</b>";
2129 richard 163
							echo "</td><td>";
2411 tom.houday 164
							echo "<FORM action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\">";
165
							echo "<INPUT type=\"hidden\" name=\"mac_addr\" value=\"$detail[0]\">";
166
							echo "<INPUT type=\"submit\" name=\"action\" value=\"$l_disconnect\">";
2134 richard 167
							echo "</FORM></TD>";
2128 richard 168
						}
2080 richard 169
						# Disable temporarily @MAC access
2129 richard 170
					}
2080 richard 171
				# The user is a humanoide ;-)
172
					else {
173
						if ($cn != '-') { echo "<a href=\"/acc/manager/htdocs/user_admin.php?login=$detail[5]\" title=\"$l_edit_user $detail[5]\">$detail[5] ($cn)</a>";}
174
						else { echo "<a href=\"/acc/manager/htdocs/user_admin.php?login=$detail[5]\" title=\"$l_edit_user $detail[5]\">$detail[5]</a>";}
175
						echo "<TD>";
2411 tom.houday 176
						echo "<FORM action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\">";
177
						echo "<INPUT type=\"hidden\" name=\"mac_addr\" value=\"$detail[0]\">";
178
						echo "<INPUT type=\"submit\" name=\"action\" value=\"$l_disconnect\">";
2134 richard 179
						echo "</FORM></TD>";
2080 richard 180
						}
1667 richard 181
					}
182
			# equipment without authenticated user
183
			else if (($detail[0] == $intif_mac_addr) || ($detail[1] == $private_ip)){
184
				echo "ALCASAR system";
185
				echo "<TD>";
186
				echo "&nbsp;";
2134 richard 187
				echo "</TD>";
2080 richard 188
				}	
189
			else {  
1667 richard 190
				echo "&nbsp;";
2134 richard 191
				echo "<TD>";		
2411 tom.houday 192
				echo "<FORM action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\">";
2065 raphael.pi 193
				# Dissociate user (... or other) who is not connected yet
2411 tom.houday 194
				echo "<INPUT type=\"hidden\" name=\"mac_addr\" value=\"$detail[0]\">";
2276 richard 195
				exec ("grep $detail[0] /usr/local/etc/alcasar-ethers-info", $mac_in_ether_file);
196
				if (empty($mac_in_ether_file[1]))
2265 richard 197
				{
2411 tom.houday 198
					echo "<INPUT type=\"submit\" name=\"action\" value=\"$l_dissociate\">"; // Dissociate only MAC not in ether file (dhcp)
2265 richard 199
				}
2411 tom.houday 200
				echo "<INPUT type=\"submit\" name=\"action\" value=\"$l_connect\">"; // Enable temporarily @MAC access
2134 richard 201
				echo "</FORM></TD>";
1667 richard 202
			}
2265 richard 203
			unset ($mac_in_ether_file);
2134 richard 204
			echo "</tr>";
1667 richard 205
		}
206
		?>
207
	</table>
208
	</td></tr>
209
</table>
210
</html>
2065 raphael.pi 211