############################################################################### # ManageBoards.pl # ############################################################################### # YaBB: Yet another Bulletin Board # # Open-Source Community Software for Webmasters # # Version: YaBB 2.5.2 # # Packaged: October 21, 2012 # # Distributed by: http://www.yabbforum.nz # # =========================================================================== # # Copyright (c) 2000-2012 YaBB (www.yabbforum.nz) - All Rights Reserved. # # Software by: The YaBB Development Team # # with assistance from the YaBB community. # ############################################################################### $manageboardsplver = 'YaBB 2.5.2 $Revision: 1.0 $'; if ($action eq 'detailedversion') { return 1; } sub ManageBoards { &is_admin_or_gmod; &LoadBoardControl; unless ($mloaded == 1) { require "$boardsdir/forum.master"; } if ($INFO{'action'} eq 'managecats') { $colspan = qq~colspan="2"~; $add = $admin_txt{'47'}; $act = 'catscreen'; $manage = qq~$admin_txt{'829'}  $admin_txt{'49'}~; $managedescr = $admin_txt{'678'}; $act2 = 'addcat'; $action_area = 'managecats'; } else { $colspan = qq~colspan="4"~; $add = $admin_txt{'50'}; $act = 'boardscreen'; $manage = qq~  $admin_txt{'51'}~; $managedescr = $admin_txt{'677'}; $act2 = 'addboard'; $action_area = 'manageboards'; } $yymain .= qq~
~; foreach $catid (@categoryorder) { @bdlist = split(/,/, $cat{$catid}); ($curcatname, $catperms) = split(/\|/, $catinfo{"$catid"}); &ToChars($curcatname); if ($INFO{"action"} eq "managecats") { $tempcolspan = ""; $tempclass = "windowbg2"; $temphrefclass = ""; } else { $tempcolspan = qq~colspan="4"~; $tempclass = "catbg"; $temphrefclass = qq~class="catbg a"~; } $yymain .= qq~ ~; if ($INFO{"action"} eq "managecats") { $yymain .= qq~ ~; } $yymain .= qq~ ~; unless ($INFO{"action"} eq "managecats") { foreach $curboard (@bdlist) { ($boardname, $boardperms, $boardview) = split(/\|/, $board{$curboard}); $boardname =~ s/\"\;/"/g; &ToChars($boardname); $descr = ${$uid.$curboard}{'description'}; $descr =~ s~\
~\n~g; my $bicon = ""; if(${$uid.$curboard}{'pic'}) { $bicon = ${$uid.$curboard}{'pic'}; } if ($bicon =~ /\//i) { $bicon = qq~ ~; } elsif ($bicon) { $bicon = qq~ ~; } if (${$uid.$curboard}{'ann'} == 1) { $bicon = qq~ $admin_txt{'64g'}~; } if (${$uid.$curboard}{'rbin'} == 1) { $bicon = qq~ $admin_txt{'64i'}~; } $convertstr = $descr; unless($convertstr =~ /<.+?>/) { # Don't cut it if there's HTML in it. $convertcut = 60; &CountChars; } my $descr = $convertstr; &ToChars($descr); if ($cliped) { $descr .= "..."; } $yymain .= qq~ ~; } } } $yymain .= qq~
$manage

$managedescr

$admin_txt{'832'}  $curcatname
$boardname $descr $bicon
$admin_txt{'53'} $admin_txt{'54'}

~; $yytitle = "$admintxt{'a4_title'}"; &AdminTemplate; } sub BoardScreen { &is_admin_or_gmod; unless ($mloaded == 1) { require "$boardsdir/forum.master"; } $i = 0; while ($_ = each(%FORM)) { if ($FORM{$_} && $_ =~ /^yitem_(.+)$/) { $editboards[$i] = $1; $i++; } } $i = 1; foreach $thiscat (@categoryorder) { @theboards = split(/,/, $cat{$thiscat}); for (my $z = 0; $z < @theboards; $z++) { for (my $j = 0; $j < @editboards; $j++) { if ($editboards[$j] eq $theboards[$z]) { $editbrd[$i] = $theboards[$z]; $i++; splice(@editboards,$j,1); last; } } } } if ($FORM{'baction'} eq "edit") { &AddBoards(@editbrd); } elsif ($FORM{'baction'} eq "delme") { shift(@editbrd); if (!$mloaded) { require "$boardsdir/forum.master"; } foreach my $bd (@editbrd) { # Remove Board form category it belongs to $category = ${$uid.$bd}{'cat'}; @bdlist = split(/,/, $cat{$category}); my $c = 0; foreach (@bdlist) { if ($_ eq $bd) { splice(@bdlist, $c, 1); last; } $c++; } $cat{$category} = join(',', &undupe(@bdlist)); delete $board{$bd}; $yymain .= qq~$admin_txt{'55'}$bd
~; } # Actual deleting &DeleteBoards(@editbrd); &Write_ForumMaster; } else { &admin_fatal_error("no_action","$FORM{'baction'}"); } $action_area = "manageboards"; &AdminTemplate; } sub DeleteBoards { &is_admin_or_gmod; fopen(FORUMCONTROL, "+<$boardsdir/forum.control") || &fatal_error("cannot_open","$boardsdir/forum.control", 1); seek FORUMCONTROL, 0, 0; my @oldcontrols = ; foreach $board (@_) { fopen(BOARDDATA, "$boardsdir/$board.txt"); @messages = ; fclose(BOARDDATA); foreach $curmessage (@messages) { my ($id, undef) = split(/\|/, $curmessage, 2); unlink("$datadir/$id\.txt"); unlink("$datadir/$id\.mail"); unlink("$datadir/$id\.ctb"); unlink("$datadir/$id\.data"); unlink("$datadir/$id\.poll"); unlink("$datadir/$id\.polled"); } for (my $cnt = 0; $cnt < @oldcontrols; $cnt++) { my $oldboard; (undef, $oldboard, undef) = split(/\|/, $oldcontrols[$cnt], 3); $yydebug .= "$cnt $oldboard \n"; if ($oldboard eq $board) { $oldcontrols[$cnt] = ""; $yydebug .= "\$board{\"$oldboard\"}"; delete $board{"$board"}; last; } } unlink("$boardsdir/$board.txt"); unlink("$boardsdir/$board.ttl"); unlink("$boardsdir/$board.poster"); unlink("$boardsdir/$board.mail"); fopen(ATM, "+<$vardir/attachments.txt", 1); seek ATM, 0, 0; my @buffer = ; my ($amcurrentboard,$amfn); for (my $a = 0; $a < @buffer; $a++) { (undef, undef, undef, undef, $amcurrentboard, undef, undef, $amfn, undef) = split(/\|/, $buffer[$a]); if ($amcurrentboard eq $board) { $buffer[$a] = ''; unlink("$upload_dir/$amfn"); } } truncate ATM, 0; seek ATM, 0, 0; print ATM @buffer; fclose(ATM); &BoardTotals("delete", $board); } my @boardcontrol = grep { $_; } @oldcontrols; truncate FORUMCONTROL, 0; seek FORUMCONTROL, 0, 0; print FORUMCONTROL sort(@boardcontrol); fclose(FORUMCONTROL); fopen(FORUMCONTROL, "$boardsdir/forum.control"); @forum_control = ; fclose(FORUMCONTROL); } sub AddBoards { my @editboards = @_; &is_admin_or_gmod; $addtext = $admin_txt{'50'}; if ($INFO{'action'} eq 'boardscreen') { $FORM{'amount'} = $#editboards; $addtext = $admin_txt{'50a'}; } unless ($mloaded == 1) { require "$boardsdir/forum.master"; } $yymain .= qq~
$addtext

$admin_txt{'57'}


~; # Check if and which board are set for announcements or recycle bin # Start Looping through and repeating the board adding wherever needed $istart = 0; $annexist = ""; $rbinexist = ""; for ($i = 1; $i != $FORM{'amount'} + 1; $i++) { # differentiate between edit or add boards if ($editboards[$i] eq "" && $INFO{"action"} eq "boardscreen") { next; } if ($INFO{"action"} eq "boardscreen") { $id = $editboards[$i]; } else { $boardtext = "$admin_txt{'58'} $i:"; } foreach $catid (@categoryorder) { @bdlist = split(/,/, $cat{$catid}); ($curcatname, $catperms) = split(/\|/, $catinfo{"$catid"}); my $boardcat = ${$uid.$editboards[$i]}{'cat'}; if ($INFO{"action"} eq "boardscreen") { if ($catid eq $boardcat) { $selected = qq~selected="selected" ~; } else { $selected = ""; } } &ToChars($curcatname); $catsel{$i} .= qq~~; } if ($istart == 0) { $istart = $i; } ($boardname, $boardperms, $boardview) = split(/\|/, $board{"$id"}); &ToChars($boardname); if ($INFO{"action"} eq "boardscreen") { $boardtext = $boardname; } $boardpic = ${$uid.$editboards[$i]}{'pic'}; $description = ${$uid.$editboards[$i]}{'description'}; $description =~ s~
~\n~g; &ToChars($description); $moderators = ${$uid.$editboards[$i]}{'mods'}; $moderatorgroups = ${$uid.$editboards[$i]}{'modgroups'}; $boardminage = ${$uid.$editboards[$i]}{'minageperms'}; $boardmaxage = ${$uid.$editboards[$i]}{'maxageperms'}; $boardgender = ${$uid.$editboards[$i]}{'genderperms'}; $genselect = qq~~; # Retrieve Optional Details $ann = ""; $rbin = ""; $zeroch = ""; $attch = ""; $showpriv = ""; $brdpic = ""; if ($boardview == 1) { $showpriv = qq~ checked="checked"~; } if (${$uid.$id}{'zero'} == 1) { $zeroch = qq~ checked="checked"~; } if (${$uid.$id}{'attperms'} == 1) { $attch = qq~ checked="checked"~; } if (${$uid.$id}{'ann'} == 1) { $annch = qq~ checked="checked"~; $brdpic = qq~ disabled="disabled"~; } elsif ($annboard ne "") { $annch = qq~ disabled="disabled"~; $annexist = 1; } if (${$uid.$id}{'rbin'} == 1) { $rbinch = qq~ checked="checked"~; $brdpic = qq~ disabled="disabled"~; } elsif ($binboard ne "") { $rbinch = qq~ disabled="disabled"~; $rbinexist = 1; } #Get Board permissions here my $startperms = &DrawPerms(${$uid.$id}{'topicperms'}, 0); my $replyperms = &DrawPerms(${$uid.$id}{'replyperms'}, 1); my $viewperms = &DrawPerms($boardperms, 0); my $pollperms = &DrawPerms(${$uid.$id}{'pollperms'}, 0); $yymain .= qq~ ~; if ($id ne '') { $yymain .= qq~ ~; } else { $yymain .= qq~ ~; } $yymain .= qq~
$boardtext
$admin_txt{'59'}: $admin_txt{'60'}
$id
$admin_txt{'63'}:
$selector_txt{linklabel}
$admin_txt{'63a'}
$admin_txt{'63b'}
$admin_txt{'63c'}

$selector_txt{instructions}
~; # Allows admin to select entire membergroups to be a board moderator $k = 0; my $box = ""; foreach (@nopostorder) { @groupinfo = split(/\|/, $NoPost{$_}); $box .= qq~~; $k++; } if ($k > 5) { $k = 5; } if ($k > 0) { $yymain .= qq~ ~; } else { $yymain .= qq~$admin_txt{'15'}~; } $yymain .= qq~
$admin_txt{'64'} $admin_txt{'64a'}
$admin_txt{'100'}: $admin_txt{'100a'}
$genselect
$admin_txt{'65'}: $admin_txt{'65a'} $admin_txt{'14'}


~; } $yymain .= qq~
~; $yytitle = "$admin_txt{'50'}"; $action_area = "manageboards"; &AdminTemplate; } sub DrawPerms { my ($permissions,$permstype) = @_; my ($foundit, %found, $groupsel, $groupsel2, $name); my $count = 0; if ($permissions eq "") { $permissions = "xk8yj56ndkal"; } my @perms = split(/, /, $permissions); foreach $perm (@perms) { $foundit = 0; if ($permstype == 1) { $name = $admin_txt{'65f'}; if ($perm eq "Topic Starter") { $foundit = 1; $found{$name} = 1; $groupsel .= qq~\n~; } if ($count == $#perms && $found{$name} != 1) { $groupsel2 .= qq~\n~; } } ($name, undef) = split(/\|/, $Group{"Administrator"}, 2); if ($perm eq "Administrator") { $foundit = 1; $found{$name} = 1; $groupsel .= qq~\n~; } if ($count == $#perms && $found{$name} != 1) { $groupsel2 .= qq~\n~; } ($name, undef) = split(/\|/, $Group{"Global Moderator"}, 2); if ($perm eq "Global Moderator") { $foundit = 1; $found{$name} = 1; $groupsel .= qq~\n~; } if ($count == $#perms && $found{$name} != 1) { $groupsel2 .= qq~\n~; } if ($foundit != 1 || $count == $#perms) { foreach (@nopostorder) { ($name, undef) = split(/\|/, $NoPost{$_}, 2); if ($perm eq $_) { $foundit = 1; $found{$_} = 1; $groupsel .= qq~\n~; } if ($found{$_} != 1 && $count == $#perms) { $groupsel2 .= qq~\n~; } } if ($foundit != 1 || $count == $#perms) { foreach (sort { $b <=> $a } keys %Post) { ($name, undef) = split(/\|/, $Post{$_}, 2); if ($perm eq $name) { $foundit = 1; $found{$name} = 1; $groupsel .= qq~\n~; } if ($count == $#perms && ($found{$name} != 1 || $found{$name} eq "")) { $groupsel2 .= qq~\n~; } } } } $count++; } $groupsel . $groupsel2; } sub AddBoards2 { &is_admin_or_gmod; unless ($mloaded == 1) { require "$boardsdir/forum.master"; } $anncount = 0; $rbincount = 0; my (@boardcontrol,@changes); for (my $i = 1; $i != $FORM{'amount'} + 1; $i++) { if ($FORM{"pic$i"} ne '' && $FORM{"pic$i"} !~ m~^[0-9a-zA-Z_\.\#\%\-\:\+\?\$\&\~\.\,\@/]+\.(gif|png|bmp|jpg)$~) { &admin_fatal_error("invalid_picture"); } ##### Dealing with Required Info here ##### if ($FORM{"id$i"} eq '') { next; } $id = $FORM{"id$i"}; if ($FORM{"ann$i"}) { $anncount++; } if ($FORM{"rbin$i"}) { $rbincount++; } &admin_fatal_error('announcement_defined') if ($anncount > 1); &admin_fatal_error('recycle_bin_defined') if ($rbincount > 1); &admin_fatal_error('invalid_character',"$admin_txt{'61'} $admin_txt{'241'}") if ($id !~ /\A[0-9A-Za-z#%+-\.@^_]+\Z/); if ($FORM{'screenornot'} ne "boardscreen") { # adding a board # make sure no board already exists with that id &admin_fatal_error("board_defined","$id") if (exists $board{"$id"}); my @bdlist = split(/\,/, $cat{$FORM{"cat$i"}}); push(@bdlist, "$id"); $cat{$FORM{"cat$i"}} = join(',', @bdlist); fopen(BOARDINFO, ">$boardsdir/$id.txt"); print BOARDINFO ''; fclose(BOARDINFO); } if ($FORM{'screenornot'} eq "boardscreen") { # editing a board my $category = ${$uid.$id}{'cat'}; # move category of board if ($category ne $FORM{"cat$i"}) { ${$uid.$id}{'cat'} = qq~$FORM{"cat$i"}~; my @bdlist = split(/,/, $cat{$category}); # Remove Board from old Category my $k = 0; foreach $bd (@bdlist) { if ($id eq $bd) { splice(@bdlist, $k, 1); } $k++; } $cat{"$category"} = join(',', @bdlist); # Add Category to new Category my $ncat = $FORM{"cat$i"}; if ($cat{$ncat} ne "") { $cat{$ncat} .= ",$id"; } else { $cat{$ncat} = $id; } } if (-e "$boardsdir/$id.txt") { # fix a(nnboard) in the boardid.txt fopen(BOARDINFO, "$boardsdir/$id.txt") || &fatal_error('cannot_open', "$openboard/$id.txt", 1); my @boardtomodify = ; fclose(BOARDINFO); my $x; if ($FORM{"ann$i"} && (split /\|/, $boardtomodify[0])[8] !~ /a/i) { for ($x = 0; $x < @boardtomodify; $x++) { $boardtomodify[$x] =~ s/(.*\|)(0?)(.*)/ $1 . ($2 eq '0' ? "0a$3" : "a$3") /e; } } elsif (!$FORM{"ann$i"} && (split /\|/, $boardtomodify[0])[8] =~ /a/i) { for ($x = 0; $x < @boardtomodify; $x++) { $boardtomodify[$x] =~ s/(.*\|)(.*)/ $1 . &take_a_off($2) /e; } sub take_a_off { my $y = shift; $y =~ s/a//g; $y; } } if ($x) { fopen(BOARDINFO, ">$boardsdir/$id.txt") || &fatal_error('cannot_open', "$openboard/$id.txt", 1); print BOARDINFO @boardtomodify; fclose(BOARDINFO); } } } $bname = $FORM{"name$i"}; &FromChars($bname); &ToHTML($bname); # If someone has the bright idea of starting a membergroup with a $ # We need to escape it for them, to prevent us interpreting it as a var... $FORM{"viewperms$i"} =~ s~\$~\\\$~g; $board{"$id"} = "$bname|$FORM{\"viewperms$i\"}|$FORM{\"show$i\"}"; $bdescription = $FORM{"description$i"}; &FromChars($bdescription); $bdescription =~ s/\r//g; $bdescription =~ s~\n~
~g; if ($do_scramble_id) { my @mods; foreach (split(', ', $FORM{"moderators$i"})) { push(@mods, &decloak($_)); } $FORM{"moderators$i"} = join(', ', @mods); } if ($FORM{"zero$i"} eq '') { $FORM{"zero$i"} = 0; } $FORM{"minage$i"} =~ tr/[0-9]//cd; ## remove non numbers $FORM{"maxage$i"} =~ tr/[0-9]//cd; ## remove non numbers if ($FORM{"minage$i"} < 0) { $FORM{"minage$i"} = ""; } if ($FORM{"maxage$i"} < 0) { $FORM{"maxage$i"} = ""; } if ($FORM{"minage$i"} > 180) { $FORM{"minage$i"} = ""; } if ($FORM{"maxage$i"} > 180) { $FORM{"maxage$i"} = ""; } if ($FORM{"maxage$i"} && $FORM{"maxage$i"} < $FORM{"minage$i"}) { $FORM{"maxage$i"} = $FORM{"minage$i"}; } push(@boardcontrol, "$FORM{\"cat$i\"}|$id|$FORM{\"pic$i\"}|$bdescription|$FORM{\"moderators$i\"}|$FORM{\"moderatorgroups$i\"}|$FORM{\"topicperms$i\"}|$FORM{\"replyperms$i\"}|$FORM{\"pollperms$i\"}|$FORM{\"zero$i\"}|$FORM{\"membergroups$i\"}|$FORM{\"ann$i\"}|$FORM{\"rbin$i\"}|$FORM{\"att$i\"}|$FORM{\"minage$i\"}|$FORM{\"maxage$i\"}|$FORM{\"gender$i\"}\n"); push(@changes, $id); $yymain .= qq~'$FORM{"name$i"}' $admin_txt{'48'}
~; } # do the saving here, after all new boards passed the tests (admin_fatal_error) &BoardTotals("add", @changes); &Write_ForumMaster; fopen(FORUMCONTROL, "+<$boardsdir/forum.control"); seek FORUMCONTROL, 0, 0; my @oldcontrols = ; my $oldboard; for (my $cnt = 0; $cnt < @oldcontrols; $cnt++) { (undef, $oldboard, undef) = split(/\|/, $oldcontrols[$cnt], 3); foreach my $changedboard (@changes) { if ($changedboard eq $oldboard) { $oldcontrols[$cnt] = ""; } } } push(@oldcontrols, @boardcontrol); @boardcontrol = grep { $_; } @oldcontrols; truncate FORUMCONTROL, 0; seek FORUMCONTROL, 0, 0; print FORUMCONTROL sort(@boardcontrol); fclose(FORUMCONTROL); $action_area = "manageboards"; &AdminTemplate; } sub ReorderBoards { &is_admin_or_gmod; unless ($mloaded == 1) { require "$boardsdir/forum.master"; } if ($#categoryorder > 0) { foreach $category (@categoryorder) { chomp $category; ($categoryname, undef) = split(/\|/, $catinfo{$category}); &ToChars($categoryname); if ($category eq $INFO{"item"}) { $categorylistsel = qq~~; } else { $categorylist .= qq~~; } } } @bdlist = split(/,/, $cat{ $INFO{"item"} }); $bdcnt = @bdlist; $bdnum = $bdcnt; if ($bdcnt < 4) { $bdcnt = 4; } ($curcatname, $catperms) = split(/\|/, $catinfo{ $INFO{"item"} }); &ToChars($curcatname); # Prepare the list of current boards to be put in the select box $boardslist = qq~~; $yymain .= qq~

$admin_txt{'832'} ($curcatname)
~; if ($bdnum) { $yymain .= qq~
$boardslist
$admin_txt{'739d'}
~; if ($#categoryorder > 0) { $yymain .= qq~
~; } } else { $yymain .= qq~
$admin_txt{'739e'}
~; } $yymain .= qq~
~; $yytitle = "$admin_txt{'832'}"; $action_area = "manageboards"; &AdminTemplate; } sub ReorderBoards2 { &is_admin_or_gmod; unless ($mloaded == 1) { require "$boardsdir/forum.master"; } @itemorder = split(/,/, $cat{ $INFO{"item"} }); my $moveitem = $FORM{'selectboards'}; my $category = $INFO{"item"}; if ($moveitem) { if ($FORM{'moveup'} || $FORM{'movedown'}) { if ($FORM{'moveup'}) { for ($i = 0; $i < @itemorder; $i++) { if ($itemorder[$i] eq $moveitem && $i > 0) { $j = $i - 1; $itemorder[$i] = $itemorder[$j]; $itemorder[$j] = $moveitem; last; } } } elsif ($FORM{'movedown'}) { for ($i = 0; $i < @itemorder; $i++) { if ($itemorder[$i] eq $moveitem && $i < $#itemorder) { $j = $i + 1; $itemorder[$i] = $itemorder[$j]; $itemorder[$j] = $moveitem; last; } } } $cat{$category} = join(',', grep { $_; } @itemorder); } else { if ($category ne $FORM{"selectcategory"}) { ${$uid.$moveitem}{'cat'} = qq~$FORM{'selectcategory'}~; my @bdlist = split(/,/, $cat{$category}); my $k = 0; foreach $bd (@bdlist) { if ($moveitem eq $bd) { splice(@bdlist, $k, 1); } $k++; } $cat{"$category"} = join(',', @bdlist); my $ncat = $FORM{"selectcategory"}; if ($cat{$ncat} ne "") { $cat{$ncat} .= ",$moveitem"; } else { $cat{$ncat} = $moveitem; } $category = qq~$FORM{"selectcategory"}~; } } &Write_ForumMaster; fopen(FORUMCONTROL, "+<$boardsdir/forum.control"); seek FORUMCONTROL, 0, 0; my @oldcontrols = ; my $oldboard; for (my $cnt = 0; $cnt < @oldcontrols; $cnt++) { my (undef, $oldboard,$pic,$bdescription,$moderators,$moderatorgroups,$topicperms,$replyperms,$pollperms,$zero,$membergroups,$ann,$rbin,$att,$minage,$maxage,$gender) = split(/\|/, $oldcontrols[$cnt]); if ($moveitem eq $oldboard) { $oldcontrols[$cnt] = qq~$category|$moveitem|$pic|$bdescription|$moderators|$moderatorgroups|$topicperms|$replyperms|$pollperms|$zero|$membergroups|$ann|$rbin|$att|$minage|$maxage|$gender~; } } my @boardcontrol = grep { $_; } @oldcontrols; truncate FORUMCONTROL, 0; seek FORUMCONTROL, 0, 0; print FORUMCONTROL sort(@boardcontrol); fclose(FORUMCONTROL); } $yySetLocation = qq~$adminurl?action=reorderboards;item=$category;theboard=$moveitem~; &redirectexit; } sub ConfRemBoard { $yymain .= qq~
$admin_txt{'31'} - '$FORM{'boardname'}'?
$admin_txt{'617'}
$admin_txt{'163'} - $admin_txt{'164'}
~; $yytitle = "$admin_txt{'31'} - '$FORM{'boardname'}'?"; $action_area = "manageboards"; &AdminTemplate; } 1;