Subversion Repositories ALCASAR

Rev

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