wipe_testusers.pl
Copying Source is Forbidden
67 lines of code
1
#!/usr/local/bin/perl
2
3
# must have's!
4
use strict;
5
use warnings;
6
use CGI::Carp qw(fatalsToBrowser);
7
use DBI;
8
use URI::Escape;
9
10
use lib "/var/www/html/Pm";
11
12
use Html qw(pre_html_header header);
13
use Bc_chef qw(cookie_get);
14
use Bc_misc qw(get_param referrer);
15
use Bc_sql qw(sql_execute
16
get_constant
17
user_exists
18
$QUERY_PAGE
19
$QUERY_UID
20
$LOGGEDIN
21
22
$DB
23
);
24
use Redir qw(notice_redir error_redir);
25
use User qw(isUserAdmin $USER_DATA);
26
use Security qw(banned);
27
28
my $DEBUG = 0;
29
30
my $output = pre_html_header();
31
32
############################################################
33
34
### YOUR CONTENT HERE
35
36
if (not user_exists($LOGGEDIN) or banned($LOGGEDIN) or not isUserAdmin($LOGGEDIN)) {
37
my $msg = "Access Denied";
38
if ($DEBUG) { $msg .= " (wipe_testusers.pl)"; }
39
$output = error_redir(referrer(), $msg);
40
} else {
41
my $sql = "delete from users where nickname like 'testuser-__________'";
42
my $result = sql_execute($sql, "wipe testusers.pl");
43
if ($result > 0) {
44
if ($DEBUG) {
45
$output .= "<b>success!</b> <i>yay! ($result)</i>\n";
46
} else {
47
$output = notice_redir(referrer(), "test users deleted");
48
}
49
} else {
50
if ($DEBUG) {
51
$output .= "<b>no joy! ($result)</b><br>\n";
52
$output .= "either the sql statement doesn't work as intended,<br>\n";
53
$output .= "or it does work and no such users match the given criteria\n";
54
} else {
55
$output = notice_redir(referrer(), "failure deleting test users (no test users, or bad sql)");
56
}
57
}
58
}
59
60
############################################################
61
if ($DEBUG) {
62
print $output;
63
} else {
64
print notice_redir(referrer(), "all test accounts destroyed");
65
}
66
67
exit 1;