Subversion Repositories ALCASAR

Rev

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

Rev Author Line No. Line
324 richard 1
<?php
2
require('/etc/freeradius-web/config.php');
3
require('../lib/attrshow.php');
4
require('../lib/sql/nas_list.php');
5
if (!isset($usage_summary)){
6
	echo <<<EOM
7
<html>
8
<head>
9
<META HTTP-EQUIV="Refresh" CONTENT="50">
10
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
11
<title>Usagers connect&eacute;es</title>
2817 rexy 12
<link rel="stylesheet" href="/css/acc.css">
324 richard 13
</head>
14
EOM;
15
}
16
require_once('../lib/functions.php');
17
require("../lib/$config[general_lib_type]/functions.php");
18
 
19
if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
20
	include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
21
else{
22
	echo <<<EOM
23
<body>
24
<center>
25
<b>Could not include SQL library functions. Aborting</b>
26
</body>
27
</html>
28
EOM;
29
	exit();
30
}
31
setlocale (LC_ALL, 'fr_FR');
32
$date = strftime('%A, %e %B %Y, %T %Z');
33
 
34
$sql_extra_query = '';
35
if ($config[sql_accounting_extra_query] != ''){
36
	$sql_extra_query = xlat($config[sql_accounting_extra_query],$login,$config);
1831 raphael.pi 37
	$sql_extra_query = da_sql_escape_string($link,$sql_extra_query);
324 richard 38
}
39
 
40
$link = @da_sql_pconnect($config);
41
$link2 = connect2db($config);
42
$tot_in = $tot_rem = 0;
43
if ($link){
44
	$h = 21;
45
	$servers_num = 0;
46
	if ($config[general_ld_library_path] != '')
47
		putenv("LD_LIBRARY_PATH=$config[general_ld_library_path]");
48
	foreach($nas_list as $nas){
49
		$j = 0;
50
		$num = 0;
51
 
52
		if ($server != ''){
53
			if ($nas[name] == $server)
54
				$servers_num++;
55
			else
56
				continue;
57
		}
58
		else
59
			$servers_num++;
60
		if ($nas[ip] == '')
61
			continue;
62
		$name_data = $nas[ip];
63
		$community_data = $nas[community];
64
		$server_name[$servers_num] = $nas[name];
65
		$server_model[$servers_num] = $nas[model];
66
		$extra = "";
67
		$finger_type = $config[general_finger_type];
68
		if ($nas[finger_type] != '')
69
			$finger_type = $nas[finger_type];
70
		if ($finger_type == 'snmp'){
71
			$nas_type = ($nas[type] != '') ? $nas[type] : $config[general_nas_type];
72
			if ($nas_type == '')
73
				$nas_type = 'cisco';
74
 
75
			$users=exec("$config[general_snmpfinger_bin] $name_data $community_data $nas_type");
76
			if (strlen($users)){
77
				$extra = "AND username IN ($users)";
78
				if ($config[general_strip_realms] == 'yes'){
79
					if ($config[general_realm_format] == 'prefix')
80
						$match = "'[^']+" . $config[general_realm_delimiter];
81
					else
82
						$match = $config[general_realm_delimiter] . "[^']+'";
83
					$extra = preg_replace("/$match/","'",$extra);
84
				}
85
			}
86
		}
87
		$search = @da_sql_query($link,$config,
88
		"SELECT COUNT(*) AS onlineusers FROM $config[sql_accounting_table] WHERE
89
		acctstoptime IS NULL AND nasipaddress = '$name_data' $extra $sql_extra_query;");
90
		if ($search){
91
			if (($row = @da_sql_fetch_array($search,$config)))
92
				$num = $row[onlineusers];
93
		}
94
		$search = @da_sql_query($link,$config,
95
		"SELECT DISTINCT username,acctstarttime,framedipaddress,callingstationid
96
		FROM $config[sql_accounting_table] WHERE
97
		acctstoptime IS NULL AND nasipaddress = '$name_data' $extra $sql_extra_query
98
		GROUP BY username,acctstarttime,framedipaddress,callingstationid
99
		ORDER BY acctstarttime;");
100
		if ($search){
101
			$now = time();
102
			while($row = @da_sql_fetch_array($search,$config)){
103
				$j++;
104
				$h += 21;
105
				$user = $row['username'];
106
				$finger_info[$servers_num][$j]['ip'] = $row['framedipaddress'];
107
				if ($finger_info[$servers_num][$j]['ip'] == '')
108
					$finger_info[$servers_num][$j]['ip'] = '-';
109
				$session_time = $row['acctstarttime'];
110
				$session_time = date2timediv($session_time,$now);
111
				$finger_info[$servers_num][$j]['session_time'] = time2strclock($session_time);
112
				$finger_info[$servers_num][$j]['user'] = $user;
113
				$finger_info[$servers_num][$j]['callerid'] = $row['callingstationid'];
114
				if ($finger_info[$servers_num][$j]['callerid'] == '')
115
					$finger_info[$servers_num][$j]['callerid'] = '-';
116
				if ($user_info["$user"] == ''){
117
					$user_info["$user"] = get_user_info($link2,$user,$config,$decode_normal,$k);
118
					if ($user_info["$user"] == '' || $user_info["$user"] == ' ')
119
						$user_info["$user"] = 'Unknown User';
120
				}
121
			}
122
			$height[$servers_num] = $h;
123
		}
124
		$server_counting[$servers_num] = $j;
125
		$server_loggedin[$servers_num] = $num;
126
		$server_rem[$servers_num] = ($config[$portnum]) ? ($config[$portnum] - $num) : 'unknown';
127
		$tot_in += $num;
128
		if (is_numeric($server_rem[$servers_num]))
129
			$tot_rem += $server_rem[$servers_num];
130
	}
131
}
132
else
133
	echo "<b>Could not connect to SQL database</b><br>\n";
134
if (isset($usage_summary)){
135
	echo "Online: $tot_in Free: $tot_rem\n";
136
	exit();
137
}
138
?>
139
 
140
<body>
141
<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
142
	<tr><th>Gestion des usagers</th></tr>
143
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" 
144
height="2"></td></tr>
145
</TABLE>
146
<TABLE width="100%" border=0 cellspacing=0 cellpadding=1>
147
	<tr bgcolor="#666666"><td>
148
	<TABLE width="100%" border=0 cellspacing=0 cellpadding=2>
149
		<tr><td valign="middle" align="left">
150
<center>
151
<table border=0 width=550 cellpadding=0 cellspacing=0>
152
<tr valign=top>
153
<!--<td align=center><img src="images/title2.gif"></td>-->
154
</tr>
155
</table>
156
<br>
157
<table border=0 width=540 cellpadding=1 cellspacing=1>
158
<tr valign=top>
159
<td width=340></td>
160
<td bgcolor="black" width=200>
161
	<table border=0 width=100% cellpadding=2 cellspacing=0>
162
	<tr bgcolor="#907030" align=right valign=top><th>
163
	<font color="white">Usagers en ligne</font>&nbsp;
164
	</th></tr>
165
	</table>
166
</td></tr>
167
<tr bgcolor="black" valign=top><td colspan=2>
168
	<table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
169
	<tr><td>
170
<?php
171
echo <<<EOM
172
	<center><b>$date</b></center>
173
EOM;
174
	for($j = 1; $j <= $servers_num; $j++){
175
		echo <<<EOM
176
<p>
177
	<table width=100% cellpadding=0 height=30><tr>
178
	<th align=left>$server_name[$j]</th><th align=right><font color="red">$server_loggedin[$j] usager(s) connect&eacute;(s)</font></th><th>$server_model[$j]</th>
179
	</tr>
180
	</table>
181
	<div height="$height[$j]" style="height:$height[$j]">
182
	<table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
183
	<tr bgcolor="#d0ddb0">
184
	<th>#</th><th>usager</th>
185
EOM;
186
	if ($acct_attrs['uf'][4] != '')	echo "<th>" . $acct_attrs[uf][4] . "</th>\n";
187
	if ($acct_attrs['uf'][9] != '') echo "<th>" . $acct_attrs[uf][9] . "</th>\n";
188
echo <<<EOM
189
	<th>nom</th><th>dur&eacute;e</th>
190
	</tr>
191
EOM;
192
	for( $k = 1; $k <= $server_counting[$j]; $k++){
193
		$user = $finger_info[$j][$k][user];
194
		if ($user == '')
195
			$user = '&nbsp;';
196
		$User = urlencode($user);
197
		$time = $finger_info[$j][$k][session_time];
198
		$ip = $finger_info[$j][$k][ip];
199
		$cid = $finger_info[$j][$k][callerid];
200
		$inf = $user_info[$user];
201
		echo <<<EOM
202
	<tr align=center>
203
	<td>$k</td><td><a href="user_admin.php?login=$User" title="Editer l'utilisateur $user">$user</a></td>
204
EOM;
205
if ($acct_attrs['uf'][4] != '') echo "<td>$ip</td>\n";
206
if ($acct_attrs['uf'][9] != '') echo "<td>$cid</td>\n";
207
echo <<<EOM
208
<td>$inf</td><td>$time</td>
209
	</tr>
210
EOM;
211
	}
212
 
213
	echo <<<EOM
214
	</table>
215
	</div>
216
EOM;
217
}
218
?>
219
	</td></tr>
220
	</table>
221
</td></tr>
222
</table>
223
</TD></TR>
224
</TABLE>
225
</td></tr>
226
</TABLE><p>
227
</html>