* Show the correct nas type in nas_admin. Bug noted by Nick Bright
[freeradius.git] / dialup_admin / htdocs / user_finger.php3
1 <?php
2 require('../conf/config.php3');
3 require('../lib/attrshow.php3');
4 require('../lib/sql/nas_list.php3');
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>User Finger Facility</title>
12 <link rel="stylesheet" href="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.php3"))
19                 include_once("../lib/lang/$config[general_prefered_lang]/utf8.php3");
20         else
21                 include_once('../lib/lang/default/utf8.php3');
22         $k = init_decoder();
23         $decode_normal = 1;
24 }
25 require_once('../lib/functions.php3');
26 require("../lib/$config[general_lib_type]/functions.php3");
27
28 if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php3"))
29         include_once("../lib/sql/drivers/$config[sql_type]/functions.php3");
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
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                 $num = 0;
59
60                 if ($server != ''){
61                         if ($nas[name] == $server)
62                                 $servers_num++;
63                         else
64                                 continue;
65                 }
66                 else
67                         $servers_num++;
68                 if ($nas[ip] == '')
69                         continue;
70                 $name_data = $nas[ip];
71                 $community_data = $nas[community];
72                 $server_name[$servers_num] = $nas[name];
73                 $server_model[$servers_num] = $nas[model];
74                 $extra = "";
75                 $finger_type = $config[general_finger_type];
76                 if ($nas[finger_type] != '')
77                         $finger_type = $nas[finger_type];
78                 if ($finger_type == 'snmp'){
79                         $nas_type = ($nas[type] != '') ? $nas[type] : $config[general_nas_type];
80                         if ($nas_type == '')
81                                 $nas_type = 'cisco';
82
83                         $users=exec("$config[general_snmpfinger_bin] $name_data $community_data $nas_type");
84                         if (strlen($users)){
85                                 $extra = "AND username IN ($users)";
86                                 if ($config[general_strip_realms] == 'yes'){
87                                         if ($config[general_realm_format] == 'prefix')
88                                                 $match = "'[^']+" . $config[general_realm_delimiter];
89                                         else
90                                                 $match = $config[general_realm_delimiter] . "[^']+'";
91                                         $extra = preg_replace("/$match/","'",$extra);
92                                 }
93                         }
94                 }
95                 $search = @da_sql_query($link,$config,
96                 "SELECT DISTINCT username,acctstarttime,framedipaddress,callingstationid
97                 FROM $config[sql_accounting_table] WHERE
98                 acctstoptime IS NULL AND nasipaddress = '$name_data' $extra $sql_extra_query
99                 GROUP BY username,acctstarttime,framedipaddress,callingstationid
100                 ORDER BY acctstarttime;");
101                 if ($search){
102                         $now = time();
103                         while($row = @da_sql_fetch_array($search,$config)){
104                                 $num++;
105                                 $h += 21;
106                                 $user = $row['username'];
107                                 $finger_info[$servers_num][$num]['ip'] = $row['framedipaddress'];
108                                 if ($finger_info[$servers_num][$num]['ip'] == '')
109                                         $finger_info[$servers_num][$num]['ip'] = '-';
110                                 $session_time = $row['acctstarttime'];
111                                 $session_time = date2timediv($session_time,$now);
112                                 $finger_info[$servers_num][$num]['session_time'] = time2strclock($session_time);
113                                 $finger_info[$servers_num][$num]['user'] = $user;
114                                 $finger_info[$servers_num][$num]['callerid'] = $row['callingstationid'];
115                                 if ($finger_info[$servers_num][$num]['callerid'] == '')
116                                         $finger_info[$servers_num][$num]['callerid'] = '-';
117                                 if ($user_info["$user"] == ''){
118                                         $user_info["$user"] = get_user_info($link2,$user,$config,$decode_normal,$k);
119                                         if ($user_info["$user"] == '' || $user_info["$user"] == ' ')
120                                                 $user_info["$user"] = 'Unknown User';
121                                 }
122                         }
123                         $height[$servers_num] = $h;
124                 }
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 <center>
142 <table border=0 width=550 cellpadding=0 cellspacing=0>
143 <tr valign=top>
144 <td align=center><img src="images/title2.gif"></td>
145 </tr>
146 </table>
147 <br>
148 <table border=0 width=540 cellpadding=1 cellspacing=1>
149 <tr valign=top>
150 <td width=340></td>
151 <td bgcolor="black" width=200>
152         <table border=0 width=100% cellpadding=2 cellspacing=0>
153         <tr bgcolor="#907030" align=right valign=top><th>
154         <font color="white">Online Users</font>&nbsp;
155         </th></tr>
156         </table>
157 </td></tr>
158 <tr bgcolor="black" valign=top><td colspan=2>
159         <table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
160         <tr><td>
161 <?php
162 echo <<<EOM
163         <b>$date</b>
164 EOM;
165         for($j = 1; $j <= $servers_num; $j++){
166                 echo <<<EOM
167 <p>
168         <table width=100% cellpadding=0 height=30><tr>
169         <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>
170         </tr>
171         </table>
172         <div height="$height[$j]" style="height:$height[$j]">
173         <table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
174         <tr bgcolor="#d0ddb0">
175         <th>#</th><th>user</th>
176 EOM;
177         if ($acct_attrs['uf'][4] != '') echo "<th>" . $acct_attrs[uf][4] . "</th>\n";
178         if ($acct_attrs['uf'][9] != '') echo "<th>" . $acct_attrs[uf][9] . "</th>\n";
179 echo <<<EOM
180         <th>name</th><th>duration</th>
181         </tr>
182 EOM;
183         for( $k = 1; $k <= $server_loggedin[$j]; $k++){
184                 $user = $finger_info[$j][$k][user];
185                 if ($user == '')
186                         $user = '&nbsp;';
187                 $User = urlencode($user);
188                 $time = $finger_info[$j][$k][session_time];
189                 $ip = $finger_info[$j][$k][ip];
190                 $cid = $finger_info[$j][$k][callerid];
191                 $inf = $user_info[$user];
192                 echo <<<EOM
193         <tr align=center>
194         <td>$k</td><td><a href="user_admin.php3?login=$User" title="Edit User $user">$user</a></td>
195 EOM;
196 if ($acct_attrs['uf'][4] != '') echo "<td>$ip</td>\n";
197 if ($acct_attrs['uf'][9] != '') echo "<td>$cid</td>\n";
198 echo <<<EOM
199 <td>$inf</td><td>$time</td>
200         </tr>
201 EOM;
202         }
203
204         echo <<<EOM
205         </table>
206         </div>
207 EOM;
208 }
209 ?>
210         </td></tr>
211         </table>
212 </td></tr>
213 </table>
214 <p>
215 </html>