diff options
Diffstat (limited to 'cgi-bin/maintain')
| -rwxr-xr-x | cgi-bin/maintain | 289 |
1 files changed, 289 insertions, 0 deletions
diff --git a/cgi-bin/maintain b/cgi-bin/maintain new file mode 100755 index 0000000..007e1e3 --- /dev/null +++ b/cgi-bin/maintain @@ -0,0 +1,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! · <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; |
