File: badusers.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 (229 lines) | stat: -rw-r--r-- 6,885 bytes parent folder | download
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
require('../conf/config.php3');
require('../lib/functions.php3');
?>
<html>
<?php

if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php3"))
	include_once("../lib/sql/drivers/$config[sql_type]/functions.php3");
else{
	echo <<<EOM
<title>Unauthorized Service Usage History for $login</title>
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
<link rel="stylesheet" href="style.css">
</head>
<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();
}

$now = time();
$now_str = ($now_str != '') ? "$now_str" : date($config[sql_date_format],$now + 86400);
$prev_str = ($prev_str != '') ? "$prev_str" : "0001-01-01 00:00:00";

$now_str = da_sql_escape_string($now_str);
$prev_str = da_sql_escape_string($prev_str);

$num = 0;
$pagesize = ($pagesize) ? $pagesize : 10;
if (!is_int($pagesize))
	$pagesize = 10;
$limit = ($pagesize == 'all') ? '' : "LIMIT $pagesize";
$selected[$pagesize] = 'selected';
$login = ($login != '') ? $login : 'anyone';
$usercheck = ($login == 'anyone') ? "LIKE '%'" : "= '$login'";
$order = ($order != '') ? $order : $config[general_accounting_info_order];
if ($order != 'desc' && $order != 'asc')
	$order = 'desc';
$selected[$order] = 'selected';

echo <<<EOM
<head>
<title>Unauthorized Service Usage History for $login</title>
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
<link rel="stylesheet" href="style.css">
</head>
<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>
EOM;

if ($login != 'anyone'){
	echo <<<EOM
<table border=0 width=400 cellpadding=0 cellspacing=2>
EOM;

include("../html/user_toolbar.html.php3");

print <<<EOM
</table>
EOM;
}

if ($do_delete == 1 && ($row_id != 0 && is_numeric($row_id))){
$link = @da_sql_connect($config);
if ($link){
	$search = @da_sql_query($link,$config,
	"SELECT id,Admin FROM $config[sql_badusers_table]
	WHERE id = '$row_id';");
	if ($search){
		$row = @da_sql_fetch_array($search,$config);
		if ($row[id] == $row_id){
			$admin = "$row[Admin]";
			if (($admin != '-' && $HTTP_SERVER_VARS["PHP_AUTH_USER"] == $admin) || $admin == '-'){
				$sql_servers = array();
				if ($config[sql_extra_servers] != '')
					$sql_servers = explode(' ',$config[sql_extra_servers]);
				$sql_servers[] = $config[sql_server];
				foreach ($sql_servers as $server){
					$link2 = @da_sql_host_connect($server,$config);
					if ($link2){
						$r = da_sql_query($link2,$config,
						"DELETE FROM $config[sql_badusers_table]
						WHERE id = '$row_id';");
						if (!$r)
							echo "<b>SQL Error:" . da_sql_error($link2,$config) . "</b><br>\n";
						@da_sql_close($link2,$config);
					}
					else
						echo "<b>SQL Error: Could not connect to SQL database: $server</b><br>\n";
				}
			}
		}
	}
	else
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
	@da_sql_close($link,$config);
}
else
	echo "<b>Could not connect to SQL database</b><br>\n";
}

echo <<<EOM
<br><br>
<table border=0 width=740 cellpadding=1 cellspacing=1>
<tr valign=top>
<td width=55%></td>
<td bgcolor="black" width=45%>
	<table border=0 width=100% cellpadding=2 cellspacing=0>
	<tr bgcolor="#907030" align=right valign=top><th>
	<font color="white">Unauthorized Service Usage History for $login</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>
<b>$prev_str</b> up to <b>$now_str</b>
<form action="badusers.php3" method="get" name="master">
<input type=hidden name=do_delete value=0>
<input type=hidden name=row_id value=0>
EOM;
?>

<p>
	<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><th>date</th><th>admin</th><th>reason</th><th>administrator action</th>
	</tr>

<?php
$auth_user = $HTTP_SERVER_VARS["PHP_AUTH_USER"];
if ($config[general_restrict_badusers_access] == 'yes'){
	$auth_user = da_sql_escape_string($auth_user);
	$extra_query = "AND Admin == '$auth_user'";
}
$link = @da_sql_pconnect($config);
if ($link){
	$search = @da_sql_query($link,$config,
	"SELECT * FROM $config[sql_badusers_table]
	WHERE UserName $usercheck $extra_query AND Date <= '$now_str'
	AND Date >= '$prev_str' ORDER BY Date $order $limit;");
	if ($search){
		while( $row = @da_sql_fetch_array($search,$config) ){
			$num++;
			$id = $row[id];
			$user = "$row[UserName]";
			$date = "$row[Date]";
			$reason = "$row[Reason]";
			$admin = "$row[Admin]";
			if ($admin == $auth_user || $admin == '-')
	$action = "<td><input type=submit class=button value=\"Delete\" OnClick=\"this.form.do_delete.value=1;this.form.row_id.value=$id\"></td>";
			else
				$action = "<td>-</td>";
			if ($admin == '')
				$admin = '-';
			if ($reason == '')
				$reason = '-';
			echo <<<EOM
			<tr align=center>
				<td>$num</td>
				<td><a href="user_admin.php3?login=$user" title="Edit user $user">$user</a></td>
				<td>$date</td>
				<td>$admin</td>
				<td>$reason</td>
				$action
			</tr>
EOM;
		}
	}
	else
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
}
else
	echo "<b>Could not connect to SQL database</b><br>\n";
echo <<<EOM
	</table>
<tr><td>
<hr>
<tr><td align="center">
	<table border=0>
		<tr><td colspan=6></td>
			<td rowspan=3 valign="bottom">
				<small>
				the <b>from</b> date matches any login after the 00:00 that day,
				and the <b>to</b> date any login before the 23:59 that day.
				the default values shown are the <b>current week</b>.
			</td>
		</tr>
		<tr valign="bottom">
			<td><small><b>user</td><td><small><b>from date</td><td><small><b>to date</td><td><small><b>pagesize</td><td><b>order</td>
&nbsp;</td>
	<tr valign="middle"><td>
<input type="text" name="login" size="11" value="$login"></td>
<td><input type="text" name="prev_str" size="11" value="$prev_str"></td>
<td><input type="text" name="now_str" size="11" value="$now_str"></td>
<td><select name="pagesize">
<option $selected[5] value="5" >05
<option $selected[10] value="10">10
<option $selected[15] value="15">15
<option $selected[20] value="20">20
<option $selected[40] value="40">40
<option $selected[80] value="80">80
<option $selected[all] value="all">all
</select>
</td>
<td><select name="order">
<option $selected[asc] value="asc">older first
<option $selected[desc] value="desc">recent first
</select>
</td>
EOM;
?>

<td><input type="submit" class=button value="show"></td></tr>
</table></td></tr></form>
</table>
</tr>
</table>
</body>
</html>