File: user_finger.php3

package info (click to toggle)
freeradius 1.0.2-4sarge3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 9,792 kB
  • ctags: 6,980
  • sloc: ansic: 52,618; sh: 9,731; php: 5,764; perl: 2,309; makefile: 1,056; sql: 730; python: 159; tcl: 33; sed: 23
file content (200 lines) | stat: -rw-r--r-- 6,196 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
require('../conf/config.php3');
require('../lib/attrshow.php3');
if (!isset($usage_summary)){
	echo <<<EOM
<html>
<head>
<META HTTP-EQUIV="Refresh" CONTENT="50">
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
<title>User Finger Facility</title>
<link rel="stylesheet" href="style.css">
</head>
EOM;
}

if ($config[general_decode_normal_attributes] == 'yes'){
	if (is_file("../lib/lang/$config[general_prefered_lang]/utf8.php3"))
		include_once("../lib/lang/$config[general_prefered_lang]/utf8.php3");
	else
		include_once('../lib/lang/default/utf8.php3');
	$k = init_decoder();
	$decode_normal = 1;
}
require('../lib/functions.php3');
require("../lib/$config[general_lib_type]/functions.php3");

if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php3"))
	include_once("../lib/sql/drivers/$config[sql_type]/functions.php3");
else{
	echo <<<EOM
<body bgcolor="#80a040" background="images/greenlines1.gif" link="black" alink="black">
<center>
<b>Could not include SQL library functions. Aborting</b>
</body>
</html>
EOM;
	exit();
}

$date = strftime('%A, %e %B %Y, %T %Z');

$sql_extra_query = '';
if ($config[sql_accounting_extra_query] != '')
	$sql_extra_query = sql_xlat($config[sql_accounting_extra_query],$login,$config);

$link = @da_sql_pconnect($config);
$link2 = connect2db($config);
$tot_in = $tot_rem = 0;
if ($link){
	$h = 21;
	$servers_num = 0;
	foreach($nas_list as $nas){
		$num = 0;

		if ($server != ''){
			if ($nas[name] == $server)
				$servers_num++;
			else
				continue;
		}
		else
			$servers_num++;
		$name_data = $nas[ip];
		$community_data = $nas[community];
		$server_name[$servers_num] = $nas[name];
		$server_model[$servers_num] = $nas[model];
		if ($config[general_ld_library_path] != '')
			putenv("LD_LIBRARY_PATH=$config[general_ld_library_path]");
		$extra = "";
		if ($config[$finger_type] != 'database' && $config[general_finger_type] == 'snmp'){
			if ($config[$nas_type] == '')
				$nas_type = $config[general_nas_type];
			else
				$nas_type = $nas[type];
			if ($nas_type == '')
				$nas_type = 'cisco';

			$users=exec("$config[general_snmpfinger_bin] $name_data $community_data $nas_type");
			if (strlen($users))
				$extra = "AND username IN ($users)";
		}
		$search = @da_sql_query($link,$config,
		"SELECT DISTINCT username,acctstarttime,framedipaddress,callingstationid
		FROM $config[sql_accounting_table] WHERE
		acctstoptime IS NULL AND nasipaddress = '$name_data' $extra $sql_extra_query
		GROUP BY username ORDER BY acctstarttime;");
		if ($search){
			$now = time();
			while($row = @da_sql_fetch_array($search,$config)){
				$num++;
				$h += 21;
				$user = $row['username'];
				$finger_info[$servers_num][$num]['ip'] = $row['framedipaddress'];
				if ($finger_info[$servers_num][$num]['ip'] == '')
					$finger_info[$servers_num][$num]['ip'] = '-';
				$session_time = $row['acctstarttime'];
				$session_time = date2timediv($session_time,$now);
				$finger_info[$servers_num][$num]['session_time'] = time2strclock($session_time);
				$finger_info[$servers_num][$num]['user'] = $user;
				$finger_info[$servers_num][$num]['callerid'] = $row['callingstationid'];
				if ($finger_info[$servers_num][$num]['callerid'] == '')
					$finger_info[$servers_num][$num]['callerid'] = '-';
				if ($user_info["$user"] == ''){
					$user_info["$user"] = get_user_info($link2,$user,$config,$decode_normal,$k);
					if ($user_info["$user"] == '' || $user_info["$user"] == ' ')
						$user_info["$user"] = 'Unknown User';
				}
			}
			$height[$servers_num] = $h;
		}
		$server_loggedin[$servers_num] = $num;
		$server_rem[$servers_num] = ($config[$portnum]) ? ($config[$portnum] - $num) : 'unknown';
		$tot_in += $num;
		if (is_numeric($server_rem[$servers_num]))
			$tot_rem += $server_rem[$servers_num];
	}
}
else
	echo "<b>Could not connect to SQL database</b><br>\n";
if (isset($usage_summary)){
	echo "Online: $tot_in Free: $tot_rem\n";
	exit();
}
?>

<body bgcolor="#80a040" background="images/greenlines1.gif" link="black" alink="black">
<center>
<table border=0 width=550 cellpadding=0 cellspacing=0>
<tr valign=top>
<td align=center><img src="images/title2.gif"></td>
</tr>
</table>
<br>
<table border=0 width=540 cellpadding=1 cellspacing=1>
<tr valign=top>
<td width=340></td>
<td bgcolor="black" width=200>
	<table border=0 width=100% cellpadding=2 cellspacing=0>
	<tr bgcolor="#907030" align=right valign=top><th>
	<font color="white">Online Users</font>&nbsp;
	</th></tr>
	</table>
</td></tr>
<tr bgcolor="black" valign=top><td colspan=2>
	<table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
	<tr><td>
<?php
echo <<<EOM
	<b>$date</b>
EOM;
	for($j = 1; $j <= $servers_num; $j++){
		echo <<<EOM
<p>
	<table width=100% cellpadding=0 height=30><tr>
	<th align=left>$server_name[$j]<br><font color="green">$server_model[$j]</font></th><th align=right><font color="red">$server_loggedin[$j] users connected</font></th><th><font color="green">$server_rem[$j] $config[general_caption_finger_free_lines]</font></th>
	</tr>
	</table>
	<div height="$height[$j]" style="height:$height[$j]">
	<table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
	<tr bgcolor="#d0ddb0">
	<th>#</th><th>user</th>
EOM;
	if ($acct_attrs['uf'][4] != '')	echo "<th>" . $acct_attrs[uf][4] . "</th>\n";
	if ($acct_attrs['uf'][9] != '') echo "<th>" . $acct_attrs[uf][9] . "</th>\n";
echo <<<EOM
	<th>name</th><th>duration</th>
	</tr>
EOM;
	for( $k = 1; $k <= $server_loggedin[$j]; $k++){
		$user = $finger_info[$j][$k][user];
		if ($user == '')
			$user = '&nbsp;';
		$time = $finger_info[$j][$k][session_time];
		$ip = $finger_info[$j][$k][ip];
		$cid = $finger_info[$j][$k][callerid];
		$inf = $user_info[$user];
		echo <<<EOM
	<tr align=center>
	<td>$k</td><td><a href="user_admin.php3?login=$user" title="Edit User $user">$user</a></td>
EOM;
if ($acct_attrs['uf'][4] != '') echo "<td>$ip</td>\n";
if ($acct_attrs['uf'][9] != '') echo "<td>$cid</td>\n";
echo <<<EOM
<td>$inf</td><td>$time</td>
	</tr>
EOM;
	}

	echo <<<EOM
	</table>
	</div>
EOM;
}
?>
	</td></tr>
	</table>
</td></tr>
</table>
<p>
</html>