mm.pl
Copying Source is Forbidden
110 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);
13
use Bc_chef qw(cookie_get);
14
use Bc_misc qw(get_param referrer);
15
use Bc_sql qw(
16
get_constant
17
sql_execute
18
user_exists
19
$QUERY_PAGE
20
$QUERY_UID
21
$LOGGEDIN
22
in_maint
23
24
$DB
25
);
26
use Security qw(banned get_login);
27
use User qw(isUserSuperAdmin $USER_DATA);
28
use Redir qw(error_redir notice_redir);
29
30
my $DEBUG = 0;
31
my $CLI = 0;
32
33
my $silent = 0;
34
my $override = 0;
35
36
my $output = pre_html_header();
37
38
if ($ARGV[0] ne "cli") {
39
if (
40
not user_exists($LOGGEDIN)
41
or banned($LOGGEDIN)
42
or not isUserSuperAdmin($LOGGEDIN)
43
) {
44
my $msg = "Access Denied";
45
if ($DEBUG) { $msg .= " (mm.pl)"; }
46
print error_redir("/", $msg);
47
48
exit 1;
49
}
50
} else {
51
$output = "";
52
$CLI = 1;
53
54
if ($ARGV[1]) {
55
if ($ARGV[1] eq "s") { $silent = 1; }
56
elsif ($ARGV[1] eq "1") { $override = 1; }
57
elsif ($ARGV[1] eq "2") { $override = 2; }
58
}
59
60
if ($ARGV[2]) {
61
if ($ARGV[2] eq "s") { $silent = 1; }
62
elsif ($ARGV[2] eq "1") { $override = 1; }
63
elsif ($ARGV[2] eq "2") { $override = 2; }
64
}
65
}
66
67
############################################################
68
69
my $maint = in_maint();
70
my $sql = "update maint set value=";
71
if (not $override) {
72
if ($maint) { $sql .= "1"; } else { $sql .= "2"; }
73
} else {
74
if ($override ne 1 and $override ne 2) { $override = 1; }
75
$sql .= $override;
76
}
77
78
my $toggled = sql_execute($sql, "mm.pl");
79
80
if ($toggled) {
81
if ($DEBUG) {
82
$output .= "maintenace mode toggled\n";
83
} else {
84
if ($CLI) {
85
if (not $silent) {
86
$output .= "maintenace mode toggled: ";
87
if ($maint) { $output .= "off"; } else { $output .= "on"; }
88
$output .= "\n";
89
}
90
} else {
91
$output = notice_redir(referrer(), "maintenence mode updated");
92
}
93
}
94
} else {
95
if ($DEBUG) {
96
$output .= "maintenace mode toggle failed\n";
97
} else {
98
if ($CLI) {
99
if (not $silent) { $output .= "maintenace mode toggle failed\n"; }
100
} else {
101
$output = error_redir(referrer(), "maintenence mode NOT updated");
102
}
103
}
104
}
105
106
############################################################
107
108
print $output;
109
110
exit 1;