|
|
62b044 |
|
|
|
62b044 |
/***
|
|
|
62b044 |
* Convert Xoops + CBB (newbb) to phpBB
|
|
|
62b044 |
*
|
|
|
62b044 |
* --
|
|
|
62b044 |
* Alain Reguera Delgado <alain.reguera@gmail.com>
|
|
|
62b044 |
***/
|
|
|
62b044 |
|
|
|
62b044 |
|
|
|
62b044 |
class NEWBB_TO_PHPBB
|
|
|
62b044 |
{
|
|
|
62b044 |
|
|
|
62b044 |
/***
|
|
|
62b044 |
* Class Construct
|
|
|
62b044 |
* ----------------------------------------------------
|
|
|
62b044 |
*/
|
|
|
62b044 |
function __construct()
|
|
|
62b044 |
{
|
|
|
62b044 |
// Initialize session
|
|
|
62b044 |
session_start();
|
|
|
62b044 |
|
|
|
62b044 |
// Check action: usedefaults
|
|
|
62b044 |
if ( isset( $_GET['action'] ) && $_GET['action'] == 'restore' )
|
|
|
62b044 |
{
|
|
|
62b044 |
// Unset session values
|
|
|
62b044 |
session_unset();
|
|
|
62b044 |
|
|
|
62b044 |
// Reload page
|
|
|
62b044 |
header('Location: index.php');
|
|
|
62b044 |
}
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
/***
|
|
|
62b044 |
* Verify Configuration
|
|
|
62b044 |
*
|
|
|
62b044 |
* This verification is needed to be sure new information entered
|
|
|
62b044 |
* is valid.
|
|
|
62b044 |
*/
|
|
|
62b044 |
function config_verification( $next_step )
|
|
|
62b044 |
{
|
|
|
62b044 |
global $db;
|
|
|
62b044 |
global $ldap;
|
|
|
62b044 |
global $html;
|
|
|
62b044 |
|
|
|
62b044 |
$htmlblock = array();
|
|
|
62b044 |
$error = 0;
|
|
|
62b044 |
|
|
|
62b044 |
// Verify LDAP bind
|
|
|
62b044 |
if ( $ldap->do_bind() )
|
|
|
62b044 |
{
|
|
|
62b044 |
array_push($htmlblock, $html->format_message('LDAP Configuration is correct', 'green'));
|
|
|
62b044 |
}
|
|
|
62b044 |
else
|
|
|
62b044 |
{
|
|
|
62b044 |
array_push( $htmlblock, $html->format_message('LDAP Configuration is incorrect', 'orange'));
|
|
|
62b044 |
$error++;
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
// Verify Database
|
|
|
62b044 |
if ( $db->connect() === true )
|
|
|
62b044 |
{
|
|
|
62b044 |
array_push( $htmlblock, $html->format_message('Common DB Configuration is correct', 'green'));
|
|
|
62b044 |
|
|
|
62b044 |
// Verify XOOPS database and table
|
|
|
62b044 |
if ( $db->check_existance('xoops') === true )
|
|
|
62b044 |
{
|
|
|
62b044 |
array_push( $htmlblock, $html->format_message('Xoops configuration is correct', 'green'));
|
|
|
62b044 |
}
|
|
|
62b044 |
else
|
|
|
62b044 |
{
|
|
|
62b044 |
array_push( $htmlblock, $html->format_message('Xoops configuration is incorrect', 'orange'));
|
|
|
62b044 |
$error++;
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
// Verify PHPBB database and table
|
|
|
62b044 |
if ( $db->check_existance('phpbb') === true )
|
|
|
62b044 |
{
|
|
|
62b044 |
array_push( $htmlblock, $html->format_message('phpBB configuration is correct', 'green'));
|
|
|
62b044 |
}
|
|
|
62b044 |
else
|
|
|
62b044 |
{
|
|
|
62b044 |
array_push( $htmlblock, $html->format_message('phpBB configuration is incorrect', 'orange'));
|
|
|
62b044 |
$error++;
|
|
|
62b044 |
}
|
|
|
62b044 |
}
|
|
|
62b044 |
else
|
|
|
62b044 |
{
|
|
|
62b044 |
array_push( $htmlblock, $html->format_message('Common DB Configuration is incorrect', 'orange'));
|
|
|
62b044 |
$error++;
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
// Add action button
|
|
|
62b044 |
if ( $error == 0 )
|
|
|
62b044 |
{
|
|
|
62b044 |
$next_step++;
|
|
|
62b044 |
array_push( $htmlblock,
|
|
|
62b044 |
'
|
|
|
62b044 |
<input type="hidden" name="step" value="'.$next_step.'" />
|
|
|
62b044 |
<input type="submit" name="Next" value="Next" />
|
|
|
62b044 |
');
|
|
|
62b044 |
}
|
|
|
62b044 |
else
|
|
|
62b044 |
{
|
|
|
62b044 |
array_push($htmlblock, 'Check your configuration ');
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
return $html->format_htmlblock($htmlblock);
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
/***
|
|
|
62b044 |
* Groups
|
|
|
62b044 |
*
|
|
|
62b044 |
* All users in xoops.users will be inserted into phpBB.users
|
|
|
62b044 |
* using the REGISTERED group (group_id = 2). Forums administrators should
|
|
|
62b044 |
* be redifined after migration.
|
|
|
62b044 |
*/
|
|
|
62b044 |
|
|
|
62b044 |
/***
|
|
|
62b044 |
* Users
|
|
|
62b044 |
*
|
|
|
62b044 |
* Basic fields are copied from xoops.users to phpBB.users.
|
|
|
62b044 |
*
|
|
|
62b044 |
* Password field should be redifined by the user in order to get logged in
|
|
|
62b044 |
* after the migration.
|
|
|
62b044 |
*
|
|
|
62b044 |
* If LDAP authentication is used the directory structure should be design
|
|
|
62b044 |
* to receive uid and userPassword attributes. In this case the migration
|
|
|
62b044 |
* should be focused from xoops.users to LDAP directory not phpBB.users.
|
|
|
62b044 |
*
|
|
|
62b044 |
* The LDAP registration process is (as my understanding): 1. Add an entry
|
|
|
62b044 |
* for the user in the LDAP directory. 2. Add an entry for the user in the
|
|
|
62b044 |
* DB (this is automatically done by phpBB). This is needed to relate user
|
|
|
62b044 |
* against user specific information like topics, posts, etc.
|
|
|
62b044 |
*
|
|
|
62b044 |
* As we are using LDAP server for users. This function use php's ldap
|
|
|
62b044 |
* extension to add users into LDAP directory. If the user do no exist in
|
|
|
62b044 |
* the Database but in LDAP server, phpBB will automatically insert a
|
|
|
62b044 |
* record for that user in the phpBB.user table. It is needed to relate
|
|
|
62b044 |
* user identity to posts, topics, etc .
|
|
|
62b044 |
*
|
|
|
62b044 |
* User passwords need to be reseted and a notification could be send to each
|
|
|
62b044 |
* user telling the new password set. This is requiered because the
|
|
|
62b044 |
* password codification used in newbb, phpbb and LDAP is different.
|
|
|
62b044 |
*
|
|
|
62b044 |
* The structure of LDAP user entries was built with rfc2377 in mind.
|
|
|
62b044 |
*/
|
|
|
62b044 |
function copy_Users()
|
|
|
62b044 |
{
|
|
|
62b044 |
global $ldap;
|
|
|
62b044 |
global $db;
|
|
|
62b044 |
|
|
|
62b044 |
$htmlblock = array('Users','
|
|
|
62b044 |
|
|
|
62b044 |
// Remove phpBB.users. Number 52 seems to be the greatest user_id
|
|
|
62b044 |
// value when no user has been created.
|
|
|
62b044 |
|
|
|
62b044 |
array_push($htmlblock,'Cleanning up ... ');
|
|
|
62b044 |
|
|
|
62b044 |
$sql = sprintf('DELETE FROM %s.%susers WHERE user_id > 52;',
|
|
|
62b044 |
$db->db_phpbb_db,
|
|
|
62b044 |
$db->db_phpbb_tbl );
|
|
|
62b044 |
$db->query( $sql );
|
|
|
62b044 |
|
|
|
62b044 |
// Add users into LDAP directory
|
|
|
62b044 |
|
|
|
62b044 |
array_push($htmlblock,'Copying ... ');
|
|
|
62b044 |
|
|
|
62b044 |
$sql = sprintf("SELECT uname,
|
|
|
62b044 |
name,
|
|
|
62b044 |
email,
|
|
|
62b044 |
pass
|
|
|
62b044 |
FROM %s.%susers WHERE uid > 1",
|
|
|
62b044 |
$db->db_xoops_db,
|
|
|
62b044 |
$db->db_xoops_tbl );
|
|
|
62b044 |
|
|
|
62b044 |
$result = $db->query( $sql );
|
|
|
62b044 |
|
|
|
62b044 |
$counter = 0;
|
|
|
62b044 |
|
|
|
62b044 |
while ( $entry = mysql_fetch_array( $result ) )
|
|
|
62b044 |
{
|
|
|
62b044 |
// Add xoops.users into LDAP directory
|
|
|
62b044 |
if ( $ldap->add_User( $entry ) === true )
|
|
|
62b044 |
{
|
|
|
62b044 |
$counter++;
|
|
|
62b044 |
}
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
array_push($htmlblock,''. $counter .' user(s) copied successfully.','');
|
|
|
62b044 |
|
|
|
62b044 |
return $htmlblock;
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
/***
|
|
|
62b044 |
* Categories
|
|
|
62b044 |
*
|
|
|
62b044 |
* Not copied. In phpBB there is no category.
|
|
|
62b044 |
*/
|
|
|
62b044 |
|
|
|
62b044 |
/***
|
|
|
62b044 |
* Copy Forum
|
|
|
62b044 |
*/
|
|
|
62b044 |
function copy_Forums()
|
|
|
62b044 |
{
|
|
|
62b044 |
global $db;
|
|
|
62b044 |
|
|
|
62b044 |
$htmlblock = array('Forums', '
|
|
|
62b044 |
|
|
|
62b044 |
// Clean up Forums
|
|
|
62b044 |
|
|
|
62b044 |
array_push( $htmlblock, 'Cleanning up ... ' );
|
|
|
62b044 |
|
|
|
62b044 |
$sql = sprintf("TRUNCATE %s.%sforums;",
|
|
|
62b044 |
$db->db_phpbb_db,
|
|
|
62b044 |
$db->db_phpbb_tbl );
|
|
|
62b044 |
|
|
|
62b044 |
$db->query( $sql );
|
|
|
62b044 |
|
|
|
62b044 |
// Copy Forums
|
|
|
62b044 |
|
|
|
62b044 |
array_push($htmlblock,'Copying ... ');
|
|
|
62b044 |
|
|
|
62b044 |
$sql = sprintf("INSERT INTO %s.%sforums (forum_name,
|
|
|
62b044 |
forum_desc,
|
|
|
62b044 |
forum_topics,
|
|
|
62b044 |
forum_topics_real,
|
|
|
62b044 |
forum_type,
|
|
|
62b044 |
forum_posts) SELECT forum_name,
|
|
|
62b044 |
forum_desc,
|
|
|
62b044 |
forum_topics,
|
|
|
62b044 |
forum_topics,
|
|
|
62b044 |
(SELECT 1 AS forum_type),
|
|
|
62b044 |
forum_posts FROM %s.%sbb_forums;",
|
|
|
62b044 |
$db->db_phpbb_db, $db->db_phpbb_tbl,
|
|
|
62b044 |
$db->db_xoops_db, $db->db_xoops_tbl);
|
|
|
62b044 |
|
|
|
62b044 |
$db->query( $sql );
|
|
|
62b044 |
|
|
|
62b044 |
// Get forums recently added and update their order, ownership, and type.
|
|
|
62b044 |
|
|
|
62b044 |
$sql = sprintf('SELECT forum_id, left_id, right_id FROM %s.%sforums;',
|
|
|
62b044 |
$db->db_phpbb_db,
|
|
|
62b044 |
$db->db_phpbb_tbl );
|
|
|
62b044 |
|
|
|
62b044 |
$result = $db->query( $sql );
|
|
|
62b044 |
|
|
|
62b044 |
// Sanitize forum's order one by one
|
|
|
62b044 |
|
|
|
62b044 |
$left_id = 1;
|
|
|
62b044 |
$right_id = 2;
|
|
|
62b044 |
$counter = 0;
|
|
|
62b044 |
|
|
|
62b044 |
while ( $row = mysql_fetch_array( $result ) )
|
|
|
62b044 |
{
|
|
|
62b044 |
$sql = sprintf("UPDATE %s.%sforums SET left_id = %d, right_id = %d WHERE forum_id = %d;",
|
|
|
62b044 |
$db->db_phpbb_db,
|
|
|
62b044 |
$db->db_phpbb_tbl,
|
|
|
62b044 |
$left_id,
|
|
|
62b044 |
$right_id,
|
|
|
62b044 |
$row['forum_id']);
|
|
|
62b044 |
|
|
|
62b044 |
$db->query( $sql );
|
|
|
62b044 |
|
|
|
62b044 |
$left_id = $left_id + 2;
|
|
|
62b044 |
$right_id = $left_id + 1;
|
|
|
62b044 |
|
|
|
62b044 |
// Counter
|
|
|
62b044 |
|
|
|
62b044 |
$counter++;
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
// Get amount of forums copied.
|
|
|
62b044 |
array_push( $htmlblock, '' . $counter . ' forum(s) copied successfully.', '');
|
|
|
62b044 |
|
|
|
62b044 |
return $htmlblock;
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
/***
|
|
|
62b044 |
* Topics
|
|
|
62b044 |
*
|
|
|
62b044 |
* When doing Topic copying the user used will be administrator. This means
|
|
|
62b044 |
* that all topics and posts after migration will be own by the
|
|
|
62b044 |
* administrator user.
|
|
|
62b044 |
*/
|
|
|
62b044 |
function copy_Topics()
|
|
|
62b044 |
{
|
|
|
62b044 |
global $db;
|
|
|
62b044 |
|
|
|
62b044 |
$htmlblock = array('Topics','
|
|
|
62b044 |
|
|
|
62b044 |
// Claen up topics
|
|
|
62b044 |
|
|
|
62b044 |
array_push( $htmlblock, 'Cleanning up ... ' );
|
|
|
62b044 |
|
|
|
62b044 |
$sql = sprintf("TRUNCATE %s.%stopics;",
|
|
|
62b044 |
$db->db_phpbb_db,
|
|
|
62b044 |
$db->db_phpbb_tbl );
|
|
|
62b044 |
|
|
|
62b044 |
$db->query( $sql );
|
|
|
62b044 |
|
|
|
62b044 |
// Copy topics
|
|
|
62b044 |
|
|
|
62b044 |
array_push( $htmlblock, 'Copying ... ' );
|
|
|
62b044 |
|
|
|
62b044 |
$sql = sprintf("INSERT INTO %s.%stopics (forum_id,
|
|
|
62b044 |
topic_title,
|
|
|
62b044 |
topic_time,
|
|
|
62b044 |
topic_last_post_time,
|
|
|
62b044 |
topic_views,
|
|
|
62b044 |
topic_last_poster_id,
|
|
|
62b044 |
topic_poster,
|
|
|
62b044 |
topic_replies,
|
|
|
62b044 |
topic_replies_real) SELECT forum_id,
|
|
|
62b044 |
topic_title,
|
|
|
62b044 |
topic_time,
|
|
|
62b044 |
topic_time,
|
|
|
62b044 |
topic_views,
|
|
|
62b044 |
(SELECT 2 AS last_poster_id),
|
|
|
62b044 |
(SELECT 2 AS last_poster_id),
|
|
|
62b044 |
topic_replies,
|
|
|
62b044 |
topic_replies
|
|
|
62b044 |
FROM %s.%sbb_topics",
|
|
|
62b044 |
$db->db_phpbb_db, $db->db_phpbb_tbl,
|
|
|
62b044 |
$db->db_xoops_db, $db->db_xoops_tbl );
|
|
|
62b044 |
|
|
|
62b044 |
$db->query( $sql );
|
|
|
62b044 |
|
|
|
62b044 |
array_push( $htmlblock, '' . mysql_affected_rows() . ' topic(s) copied successfully.', '' );
|
|
|
62b044 |
|
|
|
62b044 |
return $htmlblock;
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
/***
|
|
|
62b044 |
* Posts
|
|
|
62b044 |
*/
|
|
|
62b044 |
function copy_Posts()
|
|
|
62b044 |
{
|
|
|
62b044 |
global $db;
|
|
|
62b044 |
|
|
|
62b044 |
$htmlblock = array('Posts','
|
|
|
62b044 |
|
|
|
62b044 |
// Clean Up posts
|
|
|
62b044 |
|
|
|
62b044 |
array_push($htmlblock,'Cleanning up ... ');
|
|
|
62b044 |
|
|
|
62b044 |
$sql = sprintf("TRUNCATE %s.%sposts;", $db->db_phpbb_db, $db->db_phpbb_tbl);
|
|
|
62b044 |
|
|
|
62b044 |
$db->query( $sql );
|
|
|
62b044 |
|
|
|
62b044 |
// Copy Posts
|
|
|
62b044 |
|
|
|
62b044 |
array_push( $htmlblock, 'Copying ... ');
|
|
|
62b044 |
|
|
|
62b044 |
$sql = sprintf("INSERT INTO %s.%sposts (topic_id,
|
|
|
62b044 |
forum_id,
|
|
|
62b044 |
poster_id,
|
|
|
62b044 |
post_time,
|
|
|
62b044 |
post_subject,
|
|
|
62b044 |
post_text) SELECT t1.topic_id,
|
|
|
62b044 |
t1.forum_id,
|
|
|
62b044 |
(SELECT 2 AS poster_id),
|
|
|
62b044 |
t1.post_time,
|
|
|
62b044 |
t1.subject,
|
|
|
62b044 |
t2.post_text
|
|
|
62b044 |
FROM %s.%sbb_posts t1
|
|
|
62b044 |
LEFT JOIN %s.%sbb_posts_text t2
|
|
|
62b044 |
ON t2.post_id = t1.post_id;",
|
|
|
62b044 |
$db->db_phpbb_db, $db->db_phpbb_tbl,
|
|
|
62b044 |
$db->db_xoops_db, $db->db_xoops_tbl,
|
|
|
62b044 |
$db->db_xoops_db, $db->db_xoops_tbl);
|
|
|
62b044 |
|
|
|
62b044 |
$db->query( $sql );
|
|
|
62b044 |
|
|
|
62b044 |
array_push( $htmlblock, '' . mysql_affected_rows() .' posts(s) copied successfully.', '');
|
|
|
62b044 |
|
|
|
62b044 |
return $htmlblock;
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
/***
|
|
|
62b044 |
* Generate random password
|
|
|
62b044 |
*/
|
|
|
62b044 |
function get_randomPass()
|
|
|
62b044 |
{
|
|
|
62b044 |
// Add lower case letters
|
|
|
62b044 |
$seed = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
|
|
|
62b044 |
'i', 'j', 'k', 'i', 'l', 'm', 'n', 'o',
|
|
|
62b044 |
'p', 'q', 'r', 's', 't', 'u', 'v', 'x',
|
|
|
62b044 |
'y', 'z');
|
|
|
62b044 |
|
|
|
62b044 |
// Add upper case letters
|
|
|
62b044 |
foreach ( $seed as $value )
|
|
|
62b044 |
{
|
|
|
62b044 |
array_push( $seed, strtoupper($value) );
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
// Add numbers
|
|
|
62b044 |
array_push( $seed, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' );
|
|
|
62b044 |
|
|
|
62b044 |
// Use some symbols chars
|
|
|
62b044 |
array_push( $seed, '!', '@', '#', '$', '%', '=', '/','+' );
|
|
|
62b044 |
|
|
|
62b044 |
// Build password based on seed
|
|
|
62b044 |
$userPassword = '';
|
|
|
62b044 |
$passwordLength = 20;
|
|
|
62b044 |
for ($i = 0; $i < $passwordLength; $i++)
|
|
|
62b044 |
{
|
|
|
62b044 |
$userPassword = $userPassword . $seed[array_rand($seed)];
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
return $userPassword;
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
/***
|
|
|
62b044 |
* Class Destruct
|
|
|
62b044 |
* ----------------------------------------------------
|
|
|
62b044 |
*/
|
|
|
62b044 |
|
|
|
62b044 |
function __destruct()
|
|
|
62b044 |
{
|
|
|
62b044 |
}
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
$newbb_to_phpbb = new NEWBB_TO_PHPBB;
|
|
|
62b044 |
?>
|