* Add the style sheet in the content.html
[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('../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         foreach($nas_list as $nas){
56                 $num = 0;
57
58                 if ($server != ''){
59                         if ($nas[name] == $server)
60                                 $servers_num++;
61                         else
62                                 continue;
63                 }
64                 else
65                         $servers_num++;
66                 if ($nas[ip] == '')
67                         continue;
68                 $name_data = $nas[ip];
69                 $community_data = $nas[community];
70                 $server_name[$servers_num] = $nas[name];
71                 $server_model[$servers_num] = $nas[model];
72                 if ($config[general_ld_library_path] != '')
73                         putenv("LD_LIBRARY_PATH=$config[general_ld_library_path]");
74                 $extra = "";
75                 if ($config[$finger_type] != 'database' && $config[general_finger_type] == 'snmp'){
76                         if ($config[$nas_type] == '')
77                                 $nas_type = $config[general_nas_type];
78                         else
79                                 $nas_type = $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                 }
87                 $search = @da_sql_query($link,$config,
88                 "SELECT DISTINCT username,acctstarttime,framedipaddress,callingstationid
89                 FROM $config[sql_accounting_table] WHERE
90                 acctstoptime IS NULL AND nasipaddress = '$name_data' $extra $sql_extra_query
91                 GROUP BY username,acctstarttime,framedipaddress,callingstationid
92                 ORDER BY acctstarttime;");
93                 if ($search){
94                         $now = time();
95                         while($row = @da_sql_fetch_array($search,$config)){
96                                 $num++;
97                                 $h += 21;
98                                 $user = $row['username'];
99                                 $finger_info[$servers_num][$num]['ip'] = $row['framedipaddress'];
100                                 if ($finger_info[$servers_num][$num]['ip'] == '')
101                                         $finger_info[$servers_num][$num]['ip'] = '-';
102                                 $session_time = $row['acctstarttime'];
103                                 $session_time = date2timediv($session_time,$now);
104                                 $finger_info[$servers_num][$num]['session_time'] = time2strclock($session_time);
105                                 $finger_info[$servers_num][$num]['user'] = $user;
106                                 $finger_info[$servers_num][$num]['callerid'] = $row['callingstationid'];
107                                 if ($finger_info[$servers_num][$num]['callerid'] == '')
108                                         $finger_info[$servers_num][$num]['callerid'] = '-';
109                                 if ($user_info["$user"] == ''){
110                                         $user_info["$user"] = get_user_info($link2,$user,$config,$decode_normal,$k);
111                                         if ($user_info["$user"] == '' || $user_info["$user"] == ' ')
112                                                 $user_info["$user"] = 'Unknown User';
113                                 }
114                         }
115                         $height[$servers_num] = $h;
116                 }
117                 $server_loggedin[$servers_num] = $num;
118                 $server_rem[$servers_num] = ($config[$portnum]) ? ($config[$portnum] - $num) : 'unknown';
119                 $tot_in += $num;
120                 if (is_numeric($server_rem[$servers_num]))
121                         $tot_rem += $server_rem[$servers_num];
122         }
123 }
124 else
125         echo "<b>Could not connect to SQL database</b><br>\n";
126 if (isset($usage_summary)){
127         echo "Online: $tot_in Free: $tot_rem\n";
128         exit();
129 }
130 ?>
131
132 <body>
133 <center>
134 <table border=0 width=550 cellpadding=0 cellspacing=0>
135 <tr valign=top>
136 <td align=center><img src="images/title2.gif"></td>
137 </tr>
138 </table>
139 <br>
140 <table border=0 width=540 cellpadding=1 cellspacing=1>
141 <tr valign=top>
142 <td width=340></td>
143 <td bgcolor="black" width=200>
144         <table border=0 width=100% cellpadding=2 cellspacing=0>
145         <tr bgcolor="#907030" align=right valign=top><th>
146         <font color="white">Online Users</font>&nbsp;
147         </th></tr>
148         </table>
149 </td></tr>
150 <tr bgcolor="black" valign=top><td colspan=2>
151         <table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
152         <tr><td>
153 <?php
154 echo <<<EOM
155         <b>$date</b>
156 EOM;
157         for($j = 1; $j <= $servers_num; $j++){
158                 echo <<<EOM
159 <p>
160         <table width=100% cellpadding=0 height=30><tr>
161         <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>
162         </tr>
163         </table>
164         <div height="$height[$j]" style="height:$height[$j]">
165         <table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
166         <tr bgcolor="#d0ddb0">
167         <th>#</th><th>user</th>
168 EOM;
169         if ($acct_attrs['uf'][4] != '') echo "<th>" . $acct_attrs[uf][4] . "</th>\n";
170         if ($acct_attrs['uf'][9] != '') echo "<th>" . $acct_attrs[uf][9] . "</th>\n";
171 echo <<<EOM
172         <th>name</th><th>duration</th>
173         </tr>
174 EOM;
175         for( $k = 1; $k <= $server_loggedin[$j]; $k++){
176                 $user = $finger_info[$j][$k][user];
177                 if ($user == '')
178                         $user = '&nbsp;';
179                 $time = $finger_info[$j][$k][session_time];
180                 $ip = $finger_info[$j][$k][ip];
181                 $cid = $finger_info[$j][$k][callerid];
182                 $inf = $user_info[$user];
183                 echo <<<EOM
184         <tr align=center>
185         <td>$k</td><td><a href="user_admin.php3?login=$user" title="Edit User $user">$user</a></td>
186 EOM;
187 if ($acct_attrs['uf'][4] != '') echo "<td>$ip</td>\n";
188 if ($acct_attrs['uf'][9] != '') echo "<td>$cid</td>\n";
189 echo <<<EOM
190 <td>$inf</td><td>$time</td>
191         </tr>
192 EOM;
193         }
194
195         echo <<<EOM
196         </table>
197         </div>
198 EOM;
199 }
200 ?>
201         </td></tr>
202         </table>
203 </td></tr>
204 </table>
205 <p>
206 </html>