summaryrefslogtreecommitdiff
path: root/cgi-bin/adminz
blob: 4a71e389260e3e1a5bb33de5b52d81bd5f10f69f (plain)
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
#!/usr/bin/perl
#########################################
# administration of threads, keywords,
# privacy, etc.

use localbucky;

our $id;
our $files;

$dbh = DBI->connect ($dsn);

our ($USER, $lastlog) = checkin();
logout() unless ($USER != -1);

if ($USER->{ulevel} != 3)
	{ redirect("/"); }
else
	{
	header( { title => "bucky administrauma", color => "red" } );
	menu();
	if (exists($input->{c}))
		{
		if ($input->{c} eq "s")
			{
			update_thread_title($id, $input->{title});
			$t->{title} = $input->{title};
			print "Changed thread $id title to: <b>$t->{title}</b><br>\n";
			}
		elsif ($input->{c} eq "pass")
			{
			do_password_reset();
			}
		elsif ($input->{c} eq "p")
			{
			if ($input->{private} == 1)
				{
				print "Thread is now <b>private</b>.<br>";
				switch_thread_privacy($id, 1);
				$t->{allowed} = update_whitelist();
				$t->{private} = 1;
				}
			else
				{
				print "Thread is now <b>public</b>.<br>";
				switch_thread_privacy($id, 0);
				$t->{private} = 0;
				}
			}
		elsif ($input->{c} eq "f")
			{
			my @flagged = corral($input, "file");
			if ($DEBUG)
				{
				print "<br>\nfiles flagged: ";
				foreach (@flagged)
					 { print; print " "; }
				print "<br>\n";
				}
			if ($input->{verb} eq "flag")
				{
				print "Flagged file $flagged[0]<br>";
				update_flagged($id, $flagged[0]);
				$t->{flagged} = $flagged[0];
				admin_form($id, $t, $files, $k);
				}
			elsif ($input->{verb} eq "move")
				{
				print "When this works it will be like this:!<br>\n";
				print "Where do you want to move these files here<br>\n";
				print "Moving files...<br>\n";
				# system("mv", $data_path/$oldpid/$filenamea ..., "$data_path/$newpid/");
				print "Moving ids...<br>\n";
				print "Recalculating thread sizes...<br>\n";
				}
			elsif ($input->{verb} eq "rm")
				{
				if (!$input->{ok})
					{
					print qq!<center><p><div class="bluebox" style="width: 320px; padding: 10px;"><big><b>Are you sure you want to delete these files?</b></big><hr noshade color="$BUCKY_COLOR_HR"><p>\n!;
					print qq!<form action="$BUCKY/maintain" method="post" enctype="multipart/form-data">!;
					print qq{<input type=hidden name="c" value="f">\n};
					print qq{<input type=hidden name="id" value="$id">\n};
					print qq{<input type=hidden name="debug" value="1">\n} if ($DEBUG);
					print qq{<input type=hidden name="verb" value="rm">\n};
					print qq{<input type=hidden name="ok" value="1">\n};

					my $i = 0;
					my $fid = shift(@flagged);
					foreach my $fh (sort_by_id(@$files))
						{
						next if ($fid != $$fh{id});
						$i++;
						print qq{<input type=hidden name="file$i" value="$fid">\n};
						print $$fh{filename}."<br>\n";
						$fid = shift(@flagged);
						}

					print qq{<br><input type="submit" value="YES YES DELETE THE FILES" class="clicky"></form></div></center>};
					}
				else
					{
					my $i = 0;
					my $fid = shift(@flagged);
					foreach my $fh (sort_by_id(@$files))
						{
						next if ($fid != $$fh{id});
						$i++;
						delete_file_record($fid);
						system("rm", "-f", qq!$data_path/$id/$$fh{filename}!);
						print qq!deleted $$fh{filename}<br>\n!;
						$fid = shift(@flagged);
						}

					print "Recalculating thread size...<br>\n";
					update_thread_size($id);
					$files = get_files($id);
					}
				}
			}
		adminster_form();
		}
	else
		{
		adminster_form();
		}
	footer();
	}

sub sort_by_username { sort { lc($a->{username}) cmp lc($b->{username}) } @_; }
sub sort_by_id { sort { $a->{id} <=> $b->{id} } @_; }

sub adminster_form
	{
	print qq{<table width="100%" cellpadding=0 cellspacing=0 border=0><tr><td align=left valign=top>\n\n};

#	my $reqs = get_user_requests();
#	if ($reqs != -1)
#		{
#		my $s = (@$reqs != 1) ? "s" : "";
#		alert_box("$BUCKY/approve", @$reqs." account request$s pending!");
#		}

        print <<end;
<div class="message" style="float: right;">
<b>password reset form</b>
<hr color="$BUCKY_COLOR_HR">
end
	password_reset_form();
	print "</div>";

# "flush" zips button
# recalculcate thread sizes
# links to approval etc (alert!)
	print qq{</td></tr></table>\n\n};
	}

sub password_reset_form
	{
	my $users = get_all_users();

        print qq!<form action="$BUCKY/adminz" method="post" enctype="multipart/form-data">!;
        print qq{<input type=hidden name="c" value="pass">\n};
        print qq{<input type=hidden name="debug" value="1">\n} if ($DEBUG);
	print qq!<table cellpadding=2 cellspacing=0 border=0>!;
	print qq!<tr><td align="right">user:</td><td align="left">!;
        print qq!<select name="user">!;
        foreach $c (sort_by_username(@$users))
                {
                print qq!<option value="$c->{username}"!;
                print qq!>$c->{username}</option>!;
                }
        print qq!</select>\n!;
	print <<pws;
</td></tr>
<tr><td align="right">
password?<br>
</td><td align="left">
<input type="password" name="pw1" value="" size=13 maxlength=20><br>
</td></tr>
<tr><td align="right" valign="top">
<small>again!</small>
</td><td align="left">
<input type="password" name="pw2" value="" size=13 maxlength=20><br>
<input type="submit" value="RESET PASSWORD" class="clicky">
</td></tr>
</table>
pws
        print qq!</form>\n!;
	}

sub do_password_reset
	{
        if (exists($input->{pw1}) && exists($input->{pw2}) && $input->{pw1} && $input->{pw2})
                {
                if ($input->{pw1} eq $input->{pw2})
                        {
                        update_password($input->{user}, crypt($input->{pw1},lc($input->{user})));
                        print qq(password changed for $input->{user}<br>\n);
                        }
                else
                        {
                        print "passwords don't match!<br>\n";
                        }
                }
	}