import from HEAD:
[freeradius.git] / dialup_admin / htdocs / user_finger.php3
1 <?php
2 require('../conf/config.php3');
3 require('../lib/attrshow.php3');
4 if (!isset($usage_summary)){
5         echo <<<EOM
6 <html>
7 <head>
8 <META HTTP-EQUIV="Refresh" CONTENT="50">
9 <meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
10 <title>User Finger Facility</title>
11 <link rel="stylesheet" href="style.css">
12 </head>
13 EOM;
14 }
15
16 if ($config[general_decode_normal_attributes] == 'yes'){
17         if (is_file("../lib/lang/$config[general_prefered_lang]/utf8.php3"))
18                 include_once("../lib/lang/$config[general_prefered_lang]/utf8.php3");
19         else
20                 include_once('../lib/lang/default/utf8.php3');
21         $k = init_decoder();
22         $decode_normal = 1;
23 }
24 require('../lib/functions.php3');
25 require("../lib/$config[general_lib_type]/functions.php3");
26
27 if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php3"))
28         include_once("../lib/sql/drivers/$config[sql_type]/functions.php3");
29 else{
30         echo <<<EOM
31 <body bgcolor="#80a040" background="images/greenlines1.gif" link="black" alink="black">
32 <center>
33 <b>Could not include SQL library functions. Aborting</b>
34 </body>
35 </html>
36 EOM;
37         exit();
38 }
39
40 $date = strftime('%A, %e %B %Y, %T %Z');
41
42 $sql_extra_query = '';
43 if ($config[sql_accounting_extra_query] != '')
44         $sql_extra_query = sql_xlat($config[sql_accounting_extra_query],$login,$config);
45
46 $link = @da_sql_pconnect($config);
47 $link2 = connect2db($config);
48 $tot_in = $tot_rem = 0;
49 if ($link){
50         $h = 21;
51         $servers_num = 0;
52         foreach($nas_list as $nas){
53                 $num = 0;
54
55                 if ($server != ''){
56                         if ($nas[name] == $server)
57                                 $servers_num++;
58                         else
59                                 continue;
60                 }
61                 else
62                         $servers_num++;
63                 $name_data = $nas[ip];
64                 $community_data = $nas[community];
65                 $server_name[$servers_num] = $nas[name];
66                 $server_model[$servers_num] = $nas[model];
67                 if ($config[general_ld_library_path] != '')
68                         putenv("LD_LIBRARY_PATH=$config[general_ld_library_path]");
69                 $extra = "";
70                 if ($config[$finger_type] != 'database' && $config[general_finger_type] == 'snmp'){
71                         if ($config[$nas_type] == '')
72                                 $nas_type = $config[general_nas_type];
73                         else
74                                 $nas_type = $nas[type];
75                         if ($nas_type == '')
76                                 $nas_type = 'cisco';
77
78                         $users=exec("$config[general_snmpfinger_bin] $name_data $community_data $nas_type");
79                         if (strlen($users))
80                                 $extra = "AND username IN ($users)";
81                 }
82                 $search = @da_sql_query($link,$config,
83                 "SELECT DISTINCT username,acctstarttime,framedipaddress,callingstationid
84                 FROM $config[sql_accounting_table] WHERE
85                 acctstoptime IS NULL AND nasipaddress = '$name_data' $extra $sql_extra_query
86                 GROUP BY username ORDER BY acctstarttime;");
87                 if ($search){
88                         $now = time();
89                         while($row = @da_sql_fetch_array($search,$config)){
90                                 $num++;
91                                 $h += 21;
92                                 $user = $row['username'];
93                                 $finger_info[$servers_num][$num]['ip'] = $row['framedipaddress'];
94                                 if ($finger_info[$servers_num][$num]['ip'] == '')
95                                         $finger_info[$servers_num][$num]['ip'] = '-';
96                                 $session_time = $row['acctstarttime'];
97                                 $session_time = date2timediv($session_time,$now);
98                                 $finger_info[$servers_num][$num]['session_time'] = time2strclock($session_time);
99                                 $finger_info[$servers_num][$num]['user'] = $user;
100                                 $finger_info[$servers_num][$num]['callerid'] = $row['callingstationid'];
101                                 if ($finger_info[$servers_num][$num]['callerid'] == '')
102                                         $finger_info[$servers_num][$num]['callerid'] = '-';
103                                 if ($user_info["$user"] == ''){
104                                         $user_info["$user"] = get_user_info($link2,$user,$config,$decode_normal,$k);
105                                         if ($user_info["$user"] == '' || $user_info["$user"] == ' ')
106                                                 $user_info["$user"] = 'Unknown User';
107                                 }
108                         }
109                         $height[$servers_num] = $h;
110                 }
111                 $server_loggedin[$servers_num] = $num;
112                 $server_rem[$servers_num] = ($config[$portnum]) ? ($config[$portnum] - $num) : 'unknown';
113                 $tot_in += $num;
114                 if (is_numeric($server_rem[$servers_num]))
115                         $tot_rem += $server_rem[$servers_num];
116         }
117 }
118 else
119         echo "<b>Could not connect to SQL database</b><br>\n";
120 if (isset($usage_summary)){
121         echo "Online: $tot_in Free: $tot_rem\n";
122         exit();
123 }
124 ?>
125
126 <body bgcolor="#80a040" background="images/greenlines1.gif" link="black" alink="black">
127 <center>
128 <table border=0 width=550 cellpadding=0 cellspacing=0>
129 <tr valign=top>
130 <td align=center><img src="images/title2.gif"></td>
131 </tr>
132 </table>
133 <br>
134 <table border=0 width=540 cellpadding=1 cellspacing=1>
135 <tr valign=top>
136 <td width=340></td>
137 <td bgcolor="black" width=200>
138         <table border=0 width=100% cellpadding=2 cellspacing=0>
139         <tr bgcolor="#907030" align=right valign=top><th>
140         <font color="white">Online Users</font>&nbsp;
141         </th></tr>
142         </table>
143 </td></tr>
144 <tr bgcolor="black" valign=top><td colspan=2>
145         <table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
146         <tr><td>
147 <?php
148 echo <<<EOM
149         <b>$date</b>
150 EOM;
151         for($j = 1; $j <= $servers_num; $j++){
152                 echo <<<EOM
153 <p>
154         <table width=100% cellpadding=0 height=30><tr>
155         <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>
156         </tr>
157         </table>
158         <div height="$height[$j]" style="height:$height[$j]">
159         <table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
160         <tr bgcolor="#d0ddb0">
161         <th>#</th><th>user</th>
162 EOM;
163         if ($acct_attrs['uf'][4] != '') echo "<th>" . $acct_attrs[uf][4] . "</th>\n";
164         if ($acct_attrs['uf'][9] != '') echo "<th>" . $acct_attrs[uf][9] . "</th>\n";
165 echo <<<EOM
166         <th>name</th><th>duration</th>
167         </tr>
168 EOM;
169         for( $k = 1; $k <= $server_loggedin[$j]; $k++){
170                 $user = $finger_info[$j][$k][user];
171                 if ($user == '')
172                         $user = '&nbsp;';
173                 $time = $finger_info[$j][$k][session_time];
174                 $ip = $finger_info[$j][$k][ip];
175                 $cid = $finger_info[$j][$k][callerid];
176                 $inf = $user_info[$user];
177                 echo <<<EOM
178         <tr align=center>
179         <td>$k</td><td><a href="user_admin.php3?login=$user" title="Edit User $user">$user</a></td>
180 EOM;
181 if ($acct_attrs['uf'][4] != '') echo "<td>$ip</td>\n";
182 if ($acct_attrs['uf'][9] != '') echo "<td>$cid</td>\n";
183 echo <<<EOM
184 <td>$inf</td><td>$time</td>
185         </tr>
186 EOM;
187         }
188
189         echo <<<EOM
190         </table>
191         </div>
192 EOM;
193 }
194 ?>
195         </td></tr>
196         </table>
197 </td></tr>
198 </table>
199 <p>
200 </html>