#!/usr/bin/perl -- # $Id: YaBB FixFile Utility $ # $HeadURL: YaBB $ # $Source: /FixFile.pl $ ############################################################################### # FixFile.pl # # $Date: 01.14.13 $ # ############################################################################### # YaBB: Yet another Bulletin Board # # Open-Source Community Software for Webmasters # # Version: YaBB 2.5.4 # # Packaged: January 1, 2013 # # Distributed by: http://www.yabbforum.com # # =========================================================================== # # Copyright (c) 2000-2013 YaBB (www.yabbforum.com) - All Rights Reserved. # # Software by: The YaBB Development Team # # with assistance from the YaBB community. # ############################################################################### # use strict; # use warnings; no warnings qw(uninitialized once redefine); use CGI::Carp qw(fatalsToBrowser); use English qw(-no_match_vars); our $VERSION = '2.5.4'; $fixfileplver = 'YaBB 2.5.4 $Revision$'; if ( $ENV{'SERVER_SOFTWARE'} =~ /IIS/sm ) { $yyIIS = 1; if ( $PROGRAM_NAME =~ m{(.*)(\\|/)}xsm ) { $yypath = $1; } $yypath =~ s/\\/\//gxsm; chdir $yypath; push @INC, $yypath; } ### Requirements and Errors ### $script_root = $ENV{'SCRIPT_FILENAME'}; if ( !$script_root ) { $script_root = $ENV{'PATH_TRANSLATED'}; $script_root =~ s/\\/\//gxsm; } $script_root =~ s/\/FixFile\.(pl|cgi)//igxsm; if ( -e './Paths.pm' ) { require Paths; } elsif ( -e './Variables/Paths.pm' ) { require './Variables/Paths.pm'; } else { $boardsdir = './Boards'; $sourcedir = './Sources'; $memberdir = './Members'; $vardir = './Variables'; } $thisscript = "$ENV{'SCRIPT_NAME'}"; if ( -e ('YaBB.cgi') ) { $yyext = 'cgi'; } else { $yyext = 'pl'; } if ($boardurl) { $set_cgi = "$boardurl/FixFile.$yyext"; } else { $set_cgi = "FixFile.$yyext"; } $scripturl = "$boardurl/YaBB.$yyext"; # Make sure the module path is present push @INC, './Modules'; require Sources::Subs; require Sources::System; require Sources::Load; require Sources::DateTime; require Admin::Admin; ############################################# # Conversion starts here # ############################################# $px = 'px'; if ( -e "$vardir/Setup.lock" ) { if ( -e "$vardir/FixFile.lock" ) { FoundFixFileLock(); } tempstarter(); tabmenushow(); if ( !$action ) { $yytabmenu = $NavLink1 . $NavLink2 . $NavLink3 . $NavLink5 . $NavLink6; $yymain = qq~
YaBB 2.5.4 Converter
Make sure your YaBB 2.5.4 installation is running and that it has all the correct folder paths and URLs.
Proceed through the following steps to convert your YaBB 2x forum to YaBB 2.5.4!

If your YaBB 2x forum is located on the same server as your YaBB 2.5.4 installation:
  1. Insert the path to your YaBB 2x forum in the input field below
  2. Click on the 'Continue' button
Else if your YaBB 2x forum is located on a different server than your YaBB 2.5.4 installation or if you do not know the path to your YaBB 2x forum:
  1. Copy all files in the /Boards, /Members, /Messages, and /Variables folders from your YaBB 2x installation, to the corresponding Convert/Boards, Convert/Members, Convert/Messages, and Convert/Variables folders of your YaBB 2.5.4 installation, and chmod them 755.
  2. Click on the 'Continue' button
Path to your YaBB 2xfiles:

~; } if ( $action eq 'prepare' ) { UpdateCookie('delete'); $username = 'Guest'; $iamguest = '1'; $iamadmin = q{}; $iamgmod = q{}; $password = q{}; $yyim = q{}; local $ENV{'HTTP_COOKIE'} = q{}; $yyuname = q{}; $convertdir = $FORM{'convertdir'}; if ( !-d "$convertdir/Boards" ) { setup_fatal_error( "Directory: $convertdir/Boards", 1 ); } else { $convboardsdir = "$convertdir/Boards"; } if ( !-e "$convertdir/Members/memberlist.txt" ) { setup_fatal_error( "Directory: $convertdir/Members", 1 ); } else { $convmemberdir = "$convertdir/Members"; } if ( !-d "$convertdir/Messages" ) { setup_fatal_error( "Directory: $convertdir/Messages", 1 ); } else { $convdatadir = "$convertdir/Messages";} if ( !-d "$convertdir/Variables" ) { setup_fatal_error( "Directory: $convertdir/Variables", 1 ); } else {$convvardir = "$convertdir/Variables";} my $setfile = << "EOF"; \$convertdir = qq~$convertdir~; \$convboardsdir = qq~$convertdir/Boards~; \$convmemberdir = qq~$convertdir/Members~; \$convdatadir = qq~$convertdir/Messages~; \$convvardir = qq~$convertdir/Variables~; 1; EOF fopen( SETTING, ">$vardir/ConvSettings.txt" ) || setup_fatal_error( "$maintext_23 $vardir/ConvSettings.txt: ", 1 ); print {SETTING} nicely_aligned_file($setfile) or croak 'cannot print SETTING'; fclose(SETTING); $yytabmenu = $NavLink1a . $NavLink2 . $NavLink3 . $NavLink5 . $NavLink6; $yymain = qq~
YaBB 2.5.4 Converter
  • Members info found in: $convmemberdir
  • Board and Category info found in: $convboardsdir
  • Messages info found in: $convdatadir
- Conversion can take a long time depending on the size of your forum (30 seconds to a couple hours).
- Your browser will be refreshed automatically every $max_process_time seconds and you will see the ongoing process in the status bar.
- Some internet connections refresh their IP-Address automatically every 24 hours.
  Make sure that your IP-Address will not change during conversion, or you must restart the conversion after that!
- Your forum will be set to maintenance while converting.

Click on 'Members' in the menu to start.
 

~; } elsif ( $action eq 'members' ) { PrepareConv(); MyUpdateUser($convmemberdir); $yytabmenu = $NavLink1 . $NavLink2a . $NavLink3 . $NavLink5 . $NavLink6; $yymain = qq~
YaBB 2.5.4 Converter
Member Import.
$ConvDone
Board and Category Import.
$ConvNotDone
Message Import.
$ConvNotDone
Clean Up
$ConvNotDone
User data files have been imported.

You are importing ~ . int( ( $INFO{'st'} + 60 ) / 60 ) . qq~ minutes.

Click on 'Boards & Categories' in the menu to continue.
If you do not do that the script will continue itself in 5 minutes.

~; } elsif ( $action eq 'cats' ) { MoveBoards($convboardsdir); $yytabmenu = $NavLink1 . $NavLink2 . $NavLink3a . $NavLink5 . $NavLink6; $yymain = qq~
YaBB 2.5.4 Converter
Member Import.
$ConvDone
Board & Category Import.
$ConvDone
Message Import.
$ConvNotDone
Clean Up.
$ConvNotDone
All Boards threads imported.

You are converting ~ . int( ( $INFO{'st'} + 60 ) / 60 ) . qq~ minutes.

Click on 'Messages' in the menu to continue.
If you do not do that the script will continue by itself in 5 minutes.

~; } elsif ( $action eq 'messages' ) { MoveMessages($convdatadir);; $yytabmenu = $NavLink1 . $NavLink2 . $NavLink3 . $NavLink5a . $NavLink6; $yymain = qq~
YaBB 2.5.4 Converter
Member Import.
$ConvDone
Board and Category Import.
$ConvDone
Message Import.
$ConvDone
Clean Up.
$ConvNotDone
$INFO{'total_threads'} Threads have been converted.
$INFO{'total_mess'} Messages have been converted.

You are converting ~ . int( ( $INFO{'st'} + 60 ) / 60 ) . qq~ minutes.

Click on 'Clean Up' in the menu to continue.
If you do not do that the script will continue by itself in 5 minutes.

~; } elsif ( $action eq 'cleanup' ) { MoveVariables($convvardir); FixNopost(); $yytabmenu = $NavLink1 . $NavLink2 . $NavLink3 . $NavLink5 . $NavLink6a; $formsession = cloak("$mbname$username"); $convtext .= q~

After you have tested your forum and made sure everything was converted correctly you can go to your Admin Center and delete /Convert/Boards, /Convert/Members, /Convert/Messages and /Convert/Variables folders and their contents.~; $yymain = qq~
YaBB 2.5.4 Converter
Member Import.
$ConvDone
Board and Category Import.
$ConvDone
Message Import.
$ConvDone
Clean Up.
$ConvDone
$forumstarttext $convtext

The conversion took ~ . int( ( $INFO{'st'} + 60 ) / 60 ) . qq~ minutes.


We recommend you delete the file "$ENV{'SCRIPT_NAME'}". This is to prevent someone else running the converter and damaging your files.

Further more, we strongly recommend to run the following "Maintenance Controls" in the "Admin Center" before you start doing other things:
- Rebuild Message Index
- Recount Board Totals
- Rebuild Members List
- Recount Membership
- Rebuild Members History
- Rebuild Notifications Files
- Clean Users Online Log
- Attachment Functions => Rebuild Attachments


You may now login to your forum. Enjoy using YaBB 2.5.4!
~; CreateFixLock(); } $yyim = 'You are running the YaBB 2.5.4 Converter.'; $yytitle = 'YaBB 2.5.4 Converter'; SetupTemplate(); } # Prepare Conversion ## sub PrepareConv { fopen( FILE, ">$boardsdir/dummy.testfile" ) || setup_fatal_error( "The CHMOD of the $boardsdir is not set correctly! Cannot write this directory!", 1 ); print {FILE} "dummy testfile\n" or croak 'cannot print FILE'; fclose(FILE); opendir( BDIR, $boardsdir ) || setup_fatal_error( "The CHMOD of the $boardsdir is not set correctly! Cannot read this directory! ", 1 ); @boardlist = readdir BDIR; closedir BDIR; fopen( FILE, ">$memberdir/dummy.testfile" ) || setup_fatal_error( "The CHMOD of the $memberdir is not set correctly! Cannot write this directory!", 1 ); print {FILE} "dummy testfile\n" or croak 'cannot print FILE'; fclose(FILE); opendir( MBDIR, $memberdir ) || setup_fatal_error( "The CHMOD of the $memberdir is not set correctly! Cannot read this directory! ", 1 ); @memblist = readdir MBDIR; closedir MBDIR; fopen( FILE, ">$datadir/dummy.testfile" ) || setup_fatal_error( "The CHMOD of the $datadir is not set correctly! Cannot write this directory!", 1 ); print {FILE} "dummy testfile\n" or croak 'cannot print FILE'; fclose(FILE); opendir( MSDIR, $datadir ) || setup_fatal_error( "The CHMOD of the $datadir is not set correctly! Cannot read this directory! ", 1 ); @msglist = readdir MSDIR; closedir MSDIR; automaintenance('on'); unlink "$vardir/fixusers.txt"; foreach my $file (@boardlist) { if ( $file ne '.htaccess' && $file ne 'index.html' && $file ne 'forum.control' && $file ne q{.} && $file ne q{..} ) { unlink "$boardsdir/$file"; } } foreach my $file (@memblist) { if ( $file ne '.htaccess' && $file ne 'index.html' && $file ne 'admin.vars' && $file ne q{.} && $file ne q{..} ) { unlink "$memberdir/$file"; } } foreach my $file (@msglist) { if ( $file ne '.htaccess' && $file ne 'index.html' && $file ne q{.} && $file ne q{..} ) { unlink "$datadir/$file"; } } return; } # / Prepare Conversion ## # Member Conversion ## sub MyUpdateUser { my ( $convmemberdir ) = @_; fopen( MEMDIR, "$convmemberdir/memberlist.txt" ) || setup_fatal_error( "$maintext_23 $convmemberdir/memberlist.txt: ", 1 ); my @memlist = ; fclose(MEMDIR); fopen( MEMDIRLST, ">$memberdir/memberlist.txt" ) || setup_fatal_error( "$maintext_23 $memberdir/memberlist.txt: ", 1 ); print {MEMDIRLST} @memlist or croak 'cannot print NBMEMDIR'; fclose(MEMDIRLST); for my $i ( @memlist ) { ( $user, undef ) = split /\t/xsm, $i; my $newuser = $user; my @xtn = qw(vars msg ims imstore log outbox rlog imdraft); for my $cnt ( @xtn ) { if ( -e "$convmemberdir/$user.$cnt" ) { fopen( FILEUSER, "$convmemberdir/$user.$cnt" ) || setup_fatal_error( "$maintext_23 $convmemberdir/$user.$cnt: ", 1 ); my @divfiles = ; fclose(FILEUSER); fopen( FILEUSER, ">$memberdir/$newuser.$cnt" ) || setup_fatal_error( "$maintext_23 $memberdir/$newuser.$cnt: ", 1 ); print {FILEUSER} @divfiles or croak 'cannot print FILEUSER'; fclose(FILEUSER); } } } fopen( MEMINFO, "$convmemberdir/memberinfo.txt" ) || setup_fatal_error( "$maintext_23 $convmemberdir/memberinfo.txt: ", 1 ); my @meminfo = ; fclose(MEMINFO); fopen( NMEMINFO, ">$memberdir/memberinfo.txt" ) || setup_fatal_error( "$maintext_23 $memberdir/memberinfo.txt: ", 1 ); print {NMEMINFO} @meminfo or croak 'cannot print NBMEMINFO'; fclose(NMEMINFO); fopen( BMEMDIR, "$convmemberdir/broadcast.messages" ) || setup_fatal_error( "$maintext_23 $convmemberdir/broadcast.messages: ", 1 ); my @bmessages = ; fclose(BMEMDIR); fopen( NBMEMDIR, ">$memberdir/broadcast.messages" ) || setup_fatal_error( "$maintext_23 $convmemberdir/broadcast.messages: ", 1 ); print {NBMEMDIR} @bmessages or croak 'cannot print NBMEMDIR'; fclose(NBMEMDIR); return; } sub FixNopost { if ( $NoPost{'1'} ) { fopen( FORUMCONTROL, "$boardsdir/forum.control" ) || setup_fatal_error( "$maintext_23 $boardsdir/forum.control: ", 1 ); @boardcontrols = ; fclose(FORUMCONTROL); chomp @boardcontrols; my $totalnoposts = keys %NoPost; for my $i ( ( $INFO{'fix_nopost'} || 1 ) .. ( $totalnoposts - 1 ) ) { ( $grptitle, undef ) = split /\|/xsm, $NoPost{$i}, 2; foreach my $key ( keys %catinfo ) { ( $catname, $catperms, $catcol ) = split /\|/xsm, $catinfo{$key}, 3; $newperm = q{}; foreach my $theperm ( split /, /sm, $catperms ) { if ( $theperm eq $grptitle ) { $theperm = $i; } $newperm .= qq~$theperm, ~; } $newperm =~ s/, $//sm; $catinfo{$key} = qq~$catname|$newperm|$catcol~; } foreach my $key ( keys %board ) { ( $boardname, $boardperms, $boardshow ) = split /\|/xsm, $board{$key}, 3; $newperm = q{}; foreach my $theperm ( split /, /sm, $boardperms ) { if ( $theperm eq $grptitle ) { $theperm = $i; } $newperm .= qq~$theperm, ~; } $newperm =~ s/, $//sm; $board{$key} = qq~$boardname|$newperm|$boardshow~; } for my $j ( 0 .. ( @boardcontrols - 1 ) ) { ( $cntcat, $cntboard, $cntpic, $cntdescription, $cntmods, $cntmodgroups, $cnttopicperms, $cntreplyperms, $cntpollperms, $cntzero, $cntmembergroups, $cntann, $cntrbin, $cntattperms, $cntminageperms, $cntmaxageperms, $cntgenderperms ) = split /\|/xsm, $boardcontrols[$j]; $newmodgroups = q{}; foreach my $theperm ( split /, /sm, $cntmodgroups ) { if ( $theperm eq $grptitle ) { $theperm = $i; } $newmodgroups .= qq~$theperm, ~; } $newmodgroups =~ s/, $//sm; $newtopicperms = q{}; foreach my $theperm ( split /, /sm, $cnttopicperms ) { if ( $theperm eq $grptitle ) { $theperm = $i; } $newtopicperms .= qq~$theperm, ~; } $newtopicperms =~ s/, $//sm; $newreplyperms = q{}; foreach my $theperm ( split /, /sm, $cntreplyperms ) { if ( $theperm eq $grptitle ) { $theperm = $i; } $newreplyperms .= qq~$theperm, ~; } $newreplyperms =~ s/, $//sm; $newpollperms = q{}; foreach my $theperm ( split /, /sm, $cntpollperms ) { if ( $theperm eq $grptitle ) { $theperm = $i; } $newpollperms .= qq~$theperm, ~; } $newpollperms =~ s/, $//sm; $boardcontrols[$j] = qq~$cntcat|$cntboard|$cntpic|$cntdescription|$cntmods|$newmodgroups|$newtopicperms|$newreplyperms|$newpollperms|$cntzero|$cntmembergroups|$cntann|$cntrbin|$cntattperms|$cntminageperms|$cntmaxageperms|$cntgenderperms\n~; } } fopen( FORUMCONTROL, ">$boardsdir/forum.control" ) || setup_fatal_error( "$maintext_23 $boardsdir/forum.control: ", 1 ); print {FORUMCONTROL} @boardcontrols or croak 'cannot print FORUMCONTROL'; fclose(FORUMCONTROL); } return; } sub tempstarter { return if !-e "$vardir/Settings.pm"; $YaBBversion = 'YaBB 2.5.4'; # Make sure the module path is present push @INC, './Modules'; if ( $ENV{'SERVER_SOFTWARE'} =~ /IIS/sm ) { $yyIIS = 1; if ( $PROGRAM_NAME =~ m{(.*)(\\|/)}xsm ) { $yypath = $1; } $yypath =~ s/\\/\//gxsm; chdir $yypath; push @INC, $yypath; } # Requirements and Errors require Variables::Settings; if ( -e "$vardir/convSettings.txt" ) { require "$vardir/convSettings.txt"; } else { $convertdir = './Convert'; } LoadCookie(); # Load the user's cookie (or set to guest) LoadUserSettings(); WhatTemplate(); WhatLanguage(); require Sources::Security; WriteLog(); return; } sub CreateFixLock { fopen( 'LOCKFILE', ">$vardir/FixFile.lock" ) || setup_fatal_error( "$maintext_23 $vardir/FixFile.lock: ", 1 ); print {LOCKFILE} qq~This is a lockfile for the FixFile Utility.\n~ or croak 'cannot print to FixFile.lock'; print {LOCKFILE} qq~It prevents it being run again after it has been run once.\n~ or croak 'cannot print to FixFile.lock'; print {LOCKFILE} q~Delete this file if you want to run the FixFile Utility again.~ or croak 'cannot print to FixFile.lock'; fclose('LOCKFILE'); return; } sub FoundFixFileLock { tempstarter(); require Sources::TabMenu; # $formsession = cloak("$mbname$username"); if ( -e "$vardir/FixFile.lock" ) { $fixa = q{}; $fixa2 = qq~The 2.0-2.4 to 2.5.4 FixFile Utility has already been run.
To run Utility again, remove the file "$vardir/FixFile.lock," then re-visit this page.~; } else { $fixa = q~           
~; } $yymain = qq~
YaBB 2.5.4 Setup
$fixa2
$fixa
~; $yyim = 'YaBB 2.5.4 FixFile Utility has already been run.'; $yytitle = 'YaBB 2.5.4 FixFile Utility'; template(); return; } sub SetupImgLoc { if ( !-e "$htmldir/Templates/Forum/$useimages/$_[0]" ) { $thisimgloc = qq~img src="$yyhtml_root/Templates/Forum/default/$_[0]"~; } else { $thisimgloc = qq~img src="$imagesdir/$_[0]"~; } return $thisimgloc; } sub tabmenushow { # used by the converter $tabsep = qq~~; $tabfill = qq~~; $NavLink1 = qq~$tabfill Members $tabfill~; $NavLink2 = qq~$tabsep$tabfill Boards & Categories $tabfill~; $NavLink3 = qq~$tabsep$tabfill Messages $tabfill~; $NavLink5 = qq~$tabsep$tabfill Clean Up $tabfill~; $NavLink6 = qq~$tabsep$tabfill Login $tabfill$tabsep ~; $NavLink1a = qq~$tabfill Members $tabfill~; $NavLink2a = qq~$tabsep$tabfill Boards & Categories $tabfill~; $NavLink3a = qq~$tabsep$tabfill Messages $tabfill~; $NavLink5a = qq~$tabsep$tabfill Clean Up $tabfill~; $NavLink6a = qq~$tabsep$tabfill Login $tabfill$tabsep ~; $ConvDone = q~
 
100 %

~; $ConvNotDone = q~
 
0 %

~; return; } sub setup_fatal_error { my ( $e, $v ) = @_; $e .= "\n"; if ($v) { $e .= $! . "\n"; } $yymenu = q~Boards & Categories | ~; $yymenu .= q~Members | ~; $yymenu .= q~Messages | ~; $yymenu .= q~Date & Time | ~; $yymenu .= q~Clean Up | ~; $yymenu .= q~Login~; $yymain .= qq~
An Error Has Occurred!

$e

Back

~; $yyim = 'YaBB 2.5.4 Convertor Error.'; $yytitle = 'YaBB 2.5.4 Convertor Error.'; if ( !-e "$vardir/Settings.pm" ) { SimpleOutput(); } tempstarter(); SetupTemplate(); return; } sub SimpleOutput { $gzcomp = 0; print_output_header(); print qq~ YaBB 2.5.4 Setup
 
$yymain
~ or croak 'cannot print output screen'; exit; } sub SetupTemplate { $gzcomp = fileno $GZIP ? 1 : 0; print_output_header(); $yyposition = $yytitle; $yytitle = "$mbname - $yytitle"; $yyimages = $imagesdir; $yydefaultimages = $defaultimagesdir; $yystyle = qq~\n\n ~; $yystyle =~ s/$usestyle\///gxsm; $yytemplate = "$templatesdir/$usehead/$usehead.html"; fopen( TEMPLATE, "$yytemplate" ) || setup_fatal_error( "$maintext_23 $yytemplate: ", 1 ); @yytemplate =