summaryrefslogtreecommitdiff
path: root/cgi-bin/maintain
blob: 007e1e37ae2b39871a6979362af512aca7a2f664 (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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/usr/bin/perl
#########################################
# maintain
#  - thread administration
#########################################

use localbucky;

our $id;
our $files;

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

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

$input->{id} ||= $input->{object_from_uri} if defined($input->{object_from_uri});
if (exists($input->{id}) && $input->{id} > 0)
	{ $id = $input->{id}; }
elsif (exists($input->{keyword}) )
	{ $keyword = $input->{keyword}; }
else
        { error("No post specified."); }

my $t = get_thread($id);
my $k = get_keyword($t->{keyword});

if ($t == -1)
	{ error("No such post."); }

$files = get_files($t->{id});
$comments = get_comments($t->{id});

#my ($participation) = check_participation($files, $comments);
my ($participation) = 0;

if (exists($input->{c}) && $input->{c} eq "zip")
	{
	if ($t->{zipped} == 0)
        {
		my $cleantitle = generate_zip_filename($t);
		update_thread_zipped($t->{id}, -1);
		$t->{zipped} = -1;
		system(qq!$NOHUP_PATH $ZIP_PATH -jr "$data_path/$t->{id}/$cleantitle" $data_path/$t->{id}/* >$temp_path/.zip.out -x "$cleantitle" 2>&1 &!);
		redirect("$BUCKY/".details_link($t)."/$t->{id}");
		}
	elsif ($t->{zipped} == 1)
		{
		my $cleantitle = generate_zip_filename($t);
		update_thread_zipped($t->{id}, -1);
		$t->{zipped} = -1;
		system(qq!$NOHUP_PATH $ZIP_PATH -jr "$data_path/$t->{id}/$cleantitle" $data_path/$t->{id}/* >$temp_path/.zip.out -x "$cleantitle" 2>&1 &!);
		redirect("$BUCKY/".details_link($t)."/$t->{id}");
        }
	}
elsif ($t->{username} eq $USER->{username} || check_op($k) || $participation == 2 || (check_key($t->{display}, "opset") && check_privacy($t, $k)) || $USER->{ulevel} == 3)
	{
	header( {
			title => "settings for \"$t->{title}\"",
			subtitle => qq!posted by <a href="$BUCKY/profile/$t->{username}">$t->{username}</a> on ! .
				(verbosedate($t->{createdate})) .
				qq! &middot; <span class="lite"><a href="$BUCKY/!.details_link($t).qq!/$t->{id}">view post</a></span>!,
			color => get_color($t, $k)
			} );
	menu();
	if (exists($input->{c}))
		{
		if ($input->{c} eq "display")
			{
			if ($t->{title} ne $input->{title})
				{
				update_thread_title($t->{id}, $input->{title});
				$t->{title} = $input->{title};
				print "Changed title to: <b>$t->{title}</b><br>\n";
				}

			if (($t->{color} ne $input->{color}) && is_color($input->{color}))
				{
				update_thread_color($t->{id}, $input->{color});
				$t->{color} = $input->{color};
				print "Set color to: <b>$t->{color}</b><br>\n";
				print qq(<link rel="stylesheet" href="/css/bogart/$t->{color}.css">);
				}

			my (@display) = qw[hoot ren "no-upload" shorturl editable opset "no-zip-button" hidekws];
			my $newdisplay = ' ';
			foreach my $key (@display)
				{
				if (exists($input->{$key}) && $input->{$key} == 1)
					{ $newdisplay = add_key($newdisplay, $key); }
				}
			if ($input->{filelist} == 2)
				{ $newdisplay = add_key($newdisplay, "ffl"); }
			if ($input->{filelist} == 0)
				{ $newdisplay = add_key($newdisplay, "nfl"); }

			if ($t->{display} ne $newdisplay)
				{
				update_thread_display($t->{id}, $newdisplay);
				$t->{display} = $newdisplay;
				print "New display settings: <b>$t->{display}</b><br>\n";
				}

			# touch_thread($t);
			admin_form($t->{id}, $t, $files, $k);
			}
		elsif ($input->{c} eq "p")
			{
			if ($input->{private} == 2)
				{
				print "Thread is now <b>" . $BUCKY_CONFIG->{PRIVACY_OWNER} . "</b>.<br>";
				switch_thread_privacy($t->{id}, 2);
				$t->{allowed} = update_whitelist();
				$t->{private} = 2;
				}
			elsif ($input->{private} == 1)
				{
				print "Thread is now viewable by <b>" . $BUCKY_CONFIG->{PRIVACY_BBS} || "other users" . "</b>.<br>";
				switch_thread_privacy($t->{id}, 1);
				$t->{allowed} = update_whitelist();
				$t->{private} = 1;
				}
			else
				{
				print "Thread is now viewable by <b>" . $BUCKY_CONFIG->{PRIVACY_WORLD} . "</b>.<br>";
				switch_thread_privacy($t->{id}, 0);
				$t->{private} = 0;
				}
			admin_form($t->{id}, $t, $files, $k);
			}
		# change tags
		elsif ($input->{c} eq "t")
			{
			my $new_tags = 0;
			if ($input->{tags} ne $input->{tags_saved})
				{
				print "Changed Tag to " . $input->{tags} . "<br>" if ($DEBUG);
				# First: add new tags
				my $tags = get_tags_from_string( $input->{tags} );
				foreach my $tag (@$tags)
					{
					print "Assigning tag $tag<br>\n" if ($DEBUG);
					print tag_assign_mechanism( $tag, $t ) || "";
					$new_tags++;
					}

				# Second: remove deleted tags
				my $old_tags = get_tags_from_string( $input->{tags_saved} );
				foreach my $old_tag (@$old_tags)
					{
					# If the new tags list does not contain this old tag, remove it
					if ( ! grep ( /^$old_tag$/, @$tags ) )
						{
						print tag_remove_mechanism( $old_tag, $t ) || "";
						$new_tags++;
						}
					}
				}
			# touch_thread($t);
			$t = get_thread( $t->{id} ) if $new_tags;
			admin_form($t->{id}, $t, $files, $k);
			}
		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($t->{id}, $flagged[0]);
				$t->{flagged} = $flagged[0];
				touch_thread($t);
				admin_form($t->{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 post 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="$t->{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$fid" value="$fid">\n};
						print $fh->{id}.": " if ($DEBUG);
						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++;

						next if -d qq!$data_path/$t->{id}/$$fh{filename}!;
						delete_file_record($fid);
						system($RM_PATH, "-f", qq!$data_path/$t->{id}/$$fh{filename}!);
						system($RM_PATH, "-f", qq!$data_path/$t->{id}/.thumb/s.$$fh{filename}!);
						system($RM_PATH, "-f", qq!$data_path/$t->{id}/.thumb/t.$$fh{filename}!);
						system($RM_PATH, "-f", qq!$data_path/$t->{id}/.thumb/b.$$fh{filename}!);
						print qq!deleted $$fh{filename}<br>\n!;

						$fid = shift(@flagged);
						}

					print "Recalculating post size...<br>\n";
					update_thread_size($t->{id});
					$files = get_files($t->{id});
					touch_thread($t);
					admin_form($t->{id}, $t, $files, $k);
					}
				}
			}
		elsif ($input->{c} eq "clobber")
			{
			if ($input->{okay})
				{
				delete_thread($t->{id});
				print qq!<br><br><center><table width=400 border=0 cellpadding=0 cellspacing=0><tr><td class="bluebox" style="padding: 20px;"><big><b>POST DELETED\!</b></big></td></tr></table></center>\n!;
				}
			else
				{
				my $fs = $t->{files} != 1 ? "s" : "";
				my $cs = $t->{comments} != 1 ? "s" : "";
				my $par = get_participation($t->{id});
				my $ps = $par != 1 ? "s" : "";
				print qq(<br><br><center><table width=350 border=0 cellpadding=0 cellspacing=0><tr><td class="bluebox" style="padding: 10px;">);
				print qq(<big>Are you <b>sure</b> you want to delete:<br>$t->{title}</big><br><br>);
				print qq(Doing so will delete <b>$t->{files} file$fs</b> and <b>$t->{comments} comment$cs</b>,<br>);
				print qq(<b>destroying</b> the hard work of $par duder$ps\!<br>);
				print qq(<br>);
				print qq(<form action="$BUCKY/maintain" method="post" enctype="multipart/form-data">\n);
				print qq(<input type=hidden name="debug" value="1">\n) if ($DEBUG);
				print qq(<input type=hidden name="id" value="$t->{id}">\n);
				print qq(<input type=hidden name="c" value="clobber">\n);
				print qq(<input type=hidden name="okay" value="1">\n);
				print qq(<center><table cellpadding=0 cellspacing=10 border=0><tr><td><input type="submit" value="OKAY" class="clicky"></form></td><td><input type="button" value="ABORT" class="clicky" onclick=")."javascript: history.go(-1)".qq("></td></tr></table></center>);

				print qq!</td></tr></table></center>!;
				}
			}
		}
	else
		{
		admin_form($t->{id}, $t, $files, $k);
		}
	footer();
	}
else
	{
	error("Unable to access $id!");
	}

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

print "Maintain: " . &report_time() . "\n" if $timer;