import from HEAD
[freeradius.git] / dialup_admin / htdocs / clear_opensessions.php3
1 <?php
2 require('../conf/config.php3');
3 if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php3"))
4         include_once("../lib/sql/drivers/$config[sql_type]/functions.php3");
5 else{
6         echo <<<EOM
7 <title>Clear Open User Sessions for $login</title>
8 <meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
9 <link rel="stylesheet" href="style.css">
10 </head>
11 <body bgcolor="#80a040" background="images/greenlines1.gif" link="black" alink="black">
12 <center>
13 <b>Could not include SQL library functions. Aborting</b>
14 </body>
15 </html>
16 EOM;
17         exit();
18 }
19
20 echo <<<EOM
21 <html>
22 <head>
23 <title>Clear Open User Sessions for $login</title>
24 <meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
25 <link rel="stylesheet" href="style.css">
26 </head>
27 <body bgcolor="#80a040" background="images/greenlines1.gif" link="black" alink="black">
28 <center>
29 <table border=0 width=550 cellpadding=0 cellspacing=0>
30 <tr valign=top>
31 <td align=center><img src="images/title2.gif"></td>
32 </tr>
33 </table>
34
35 <table border=0 width=400 cellpadding=0 cellspacing=2>
36 EOM;
37
38 include("../html/user_toolbar.html.php3");
39
40 $open_sessions = 0;
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 print <<<EOM
47 </table>
48
49 <br>
50 <table border=0 width=540 cellpadding=1 cellspacing=1>
51 <tr valign=top>
52 <td width=340></td>
53 <td bgcolor="black" width=200>
54         <table border=0 width=100% cellpadding=2 cellspacing=0>
55         <tr bgcolor="#907030" align=right valign=top><th>
56         <font color="white">Clear open sessions for $login</font>&nbsp;
57         </th></tr>
58         </table>
59 </td></tr>
60 <tr bgcolor="black" valign=top><td colspan=2>
61         <table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
62         <tr><td>
63 EOM;
64    
65 if ($clear_sessions == 1){
66         $link = @da_sql_pconnect($config);
67         if ($link){
68                 $res = @da_sql_query($link,$config,
69                 "DELETE FROM $config[sql_accounting_table]
70                 WHERE username='$login' AND acctstoptime = 0 $sql_extra_query;");
71                 if ($res)
72                         echo "<b>Deleted open sessions from accounting table</b><br>\n";
73                 else
74                         echo "<b>Error deleting open sessions for user" . da_sql_error($link,$config) . "</b><br>\n";
75         }
76         else
77                 echo "<b>Could not connect to SQL database</b><br>\n";
78         echo <<<EOM
79 </td></tr>
80 </table>
81 </tr>
82 </table>
83 </body>
84 </html>
85 EOM;
86         exit();
87 }
88 else{
89         $link = @da_sql_pconnect($config);
90         if ($link){
91                 $search = @da_sql_query($link,$config,
92                 "SELECT COUNT(*) AS counter FROM $config[sql_accounting_table]
93                 WHERE username = '$login' AND acctstoptime IS NULL $sql_extra_query;");
94                 if ($search){
95                         if ($row = @da_sql_fetch_array($search,$config))
96                                 $open_sessions = $row[counter];
97                 }
98                 else
99                         echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
100         }
101         else
102                 echo "<b>Could not connect to SQL database</b><br>\n";
103 }
104 ?>
105    <form method=post>
106       <input type=hidden name=login value=<?php print $login ?>>
107       <input type=hidden name=clear_sessions value="0">
108         <table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
109 <tr>
110 <td align=center>
111 User <?php echo $login; ?> has <i><?php echo $open_sessions; ?></i> open sessions<br><br>
112 Are you sure you want to clear all open user sessions?
113 </td>
114 </tr>
115         </table>
116 <br>
117 <input type=submit class=button value="Yes Clear" OnClick="this.form.clear_sessions.value=1">
118 </form>
119 </td></tr>
120 </table>
121 </tr>
122 </table>
123 </body>
124 </html>