Vergleich admin/dbtools.php - 1.2.0 - 1.2.14

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 3Zeile 3
 * MyBB 1.2
* Copyright © 2006 MyBB Group, All Rights Reserved
*

 * MyBB 1.2
* Copyright © 2006 MyBB Group, All Rights Reserved
*

 * Website: http://www.mybboard.com
* License: http://www.mybboard.com/eula.html

 * Website: http://www.mybboard.net
* License: http://www.mybboard.net/eula.html

 *

 *

 * $Id$

 * $Id: dbtools.php 3530 2007-12-01 19:29:47Z Tikitiki $

 */

define("IN_MYBB", 1);

 */

define("IN_MYBB", 1);

Zeile 32Zeile 32
	case 'optimize':
addacpnav($lang->optimize_tables);
break;

	case 'optimize':
addacpnav($lang->optimize_tables);
break;

 
	case 'utf8_conversion':
addacpnav($lang->convert_to_utf8);
break;
}

if($mybb->input['action'] == "utf8_conversion")
{
cpheader();

// The last step where we do the actual conversion process.
if($mybb->request_method == "post" || ($mybb->input['table'] == "all" && isset($mybb->input['table2'])))
{
@set_time_limit(0);

if($mybb->input['table'] == "all")
{
$all = true;
$mybb->input['table'] = $mybb->input['table2'];
}

if(!$db->table_exists($db->escape_string($mybb->input['table'])))
{
cperror($lang->error_invalid_table);
}

starttable();

$table1 = $db->show_create_table($db->escape_string($mybb->input['table']));
preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table1, $matches);
$charset = $matches[1];

tableheader($converting_table." {$mybb->input['table']}", 'tablename', 1);

echo "<tr>\n";
echo "<td class=\"subheader\"><strong>".sprintf($lang->converting_to_utf8, $mybb->input['table'], $charset)."</strong></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class=\"altbg1\" align=\"center\">{$lang->please_wait}</td>\n";
echo "</tr>\n";

flush();

$types = array(
'text' => 'blob',
'mediumtext' => 'mediumblob',
'longtext' => 'longblob',
'char' => 'varbinary',
'varchar' => 'varbinary',
'tinytext' => 'tinyblob'
);

// Get next table in list
$convert_to_binary = '';
$convert_to_utf8 = '';
$comma = '';

// Set table default charset
$db->query("ALTER TABLE {$mybb->input['table']} DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci");

// Fetch any fulltext keys
if($db->supports_fulltext($mybb->input['table']))
{
$table_structure = $db->show_create_table($mybb->input['table']);
preg_match_all("#FULLTEXT KEY `?([a-zA-Z0-9_]+)`? \(([a-zA-Z0-9_`,']+)\)#i", $table_structure, $matches);
if(is_array($matches))
{
foreach($matches[0] as $key => $matched)
{
$db->query("ALTER TABLE {$mybb->input['table']} DROP INDEX {$matches[1][$key]}");
$fulltext_to_create[$matches[1][$key]] = $matches[2][$key];
}
}
}

// Find out which columns need converting and build SQL statements
$query = $db->query("SHOW FULL COLUMNS FROM {$mybb->input['table']}");
while($column = $db->fetch_array($query))
{
list($type) = explode('(', $column['Type']);
if(array_key_exists($type, $types))
{
// Build the actual strings for converting the columns
$names = "CHANGE `{$column['Field']}` `{$column['Field']}` ";

$attributes = " DEFAULT ";
if($column['Default'] == 'NULL')
{
$attributes .= "NULL ";
}
else
{
$attributes .= "'".$db->escape_string($column['Default'])."' ";

if($column['Null'] == 'YES')
{
$attributes .= 'NULL';
}
else
{
$attributes .= 'NOT NULL';
}
}

$convert_to_binary .= $comma.$names.preg_replace('/'.$type.'/i', $types[$type], $column['Type']).$attributes;
$convert_to_utf8 .= "{$comma}{$names}{$column['Type']} CHARACTER SET utf8 COLLATE utf8_general_ci{$attributes}";

$comma = ', ';
}
}

if(!empty($convert_to_binary))
{
// This converts the columns to UTF-8 while also doing the same for data
$db->query("ALTER TABLE {$mybb->input['table']} {$convert_to_binary}");
$db->query("ALTER TABLE {$mybb->input['table']} {$convert_to_utf8}");
}

// Any fulltext indexes to recreate?
if(is_array($fulltext_to_create))
{
foreach($fulltext_to_create as $name => $fields)
{
$db->create_fulltext_index($mybb->input['table'], $fields, $name);
}
}

if($all == true)
{
$tables = $db->list_tables($config['database']);
foreach($tables as $key => $tablename)
{
if(substr($tablename, 0, strlen(TABLE_PREFIX)) == TABLE_PREFIX)
{
$table = $db->show_create_table($tablename);
preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table, $matches);
if(fetch_iconv_encoding($matches[1]) == 'utf-8' && $mybb->input['table'] != $tablename)
{
continue;
}

$mybb_tables[$key] = $tablename;
}
}

asort($mybb_tables);
reset($mybb_tables);

$is_next = false;
$nexttable = "";

foreach($mybb_tables as $key => $tablename)
{
if($is_next == true)
{
$nexttable = $tablename;
break;
}
else if($mybb->input['table'] == $tablename)
{
$is_next = true;
}
}

if($nexttable)
{
$nexttable = $db->escape_string($nexttable);
echo "<tr>\n";
echo "<td class=\"altbg2\" align=\"center\">".sprintf($lang->success_table_converted, $mybb->input['table'])."</td>\n";
echo "</tr>\n";
endtable();
echo "<meta http-equiv=\"Refresh\" content=\"5; url=dbtools.php?".SID."&amp;action=utf8_conversion&amp;table=all&amp;table2={$nexttable}\" />";
}
else
{
echo "<tr>\n";
echo "<td class=\"altbg2\" align=\"center\">".sprintf($lang->success_table_converted, $mybb->input['table'])."</td>\n";
echo "</tr>\n";
endtable();
echo "<meta http-equiv=\"Refresh\" content=\"5; url=dbtools.php?".SID."&amp;action=utf8_conversion\" />";
}
}
else
{
echo "<tr>\n";
echo "<td class=\"altbg2\" align=\"center\">".sprintf($lang->success_table_converted, $mybb->input['table'])."</td>\n";
echo "</tr>\n";
endtable();
echo "<meta http-equiv=\"Refresh\" content=\"5; url=dbtools.php?".SID."&amp;action=utf8_conversion\" />";
}

cpfooter();

exit;
}

// This is the second step where we confirm the table we're about to convert.
if($mybb->input['table'])
{
if($mybb->input['table'] != "all" && !$db->table_exists($db->escape_string($mybb->input['table'])))
{
cperror($lang->error_invalid_table);
}

if($mybb->input['table'] == "all")
{
$tables = $db->list_tables($config['database']);
foreach($tables as $key => $tablename)
{
if(substr($tablename, 0, strlen(TABLE_PREFIX)) == TABLE_PREFIX)
{
$table = $db->show_create_table($tablename);
preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table, $matches);
if(fetch_iconv_encoding($matches[1]) == 'utf-8')
{
continue;
}
$mybb_tables[$key] = $tablename;
}
}

if(is_array($mybb_tables))
{
asort($mybb_tables);
reset($mybb_tables);
$nexttable = current($mybb_tables);
$table = $db->show_create_table($db->escape_string($nexttable));
}
else
{
cperror($lang->error_all_tables_already_converted);
}
}
else
{
$table = $db->show_create_table($db->escape_string($mybb->input['table']));
}

preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table, $matches);
$charset = $matches[1];

startform('dbtools.php', '', "utf8_conversion");
makehiddencode('table', $mybb->input['table']);


if($mybb->input['table'] == "all")
{
makehiddencode('table2', $nexttable);
starttable();
tableheader($lang->convert_tables, 'converttable', 1);
echo "<tr>\n";
echo "<td class=\"subheader\"><strong>".sprintf($lang->convert_all_to_utf, $charset)."</strong></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class=\"altbg1\" align=\"center\">{$lang->notice_proccess_long_time}</td>\n";
echo "</tr>\n";

$submit_button = makebuttoncode('submit', $lang->convert_database_tables);
}
else
{
starttable();
tableheader($lang->convert_table." {$mybb->input['table']}", 'converttable', 1);
echo "<tr>\n";
echo "<td class=\"subheader\"><strong>".sprintf($lang->convert_to_utf, $mybb->input['table'], $charset)."</strong></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class=\"altbg1\" align=\"center\">{$lang->notice_proccess_long_time}</td>\n";
echo "</tr>\n";

$submit_button = makebuttoncode('submit', $lang->convert_database_table);
}

makelabelcode('<div align="center">'.$submit_button.'</div>');

endtable();
endform();
cpfooter();

exit;
}

$tables = $db->list_tables($config['database']);

$not_okey_count = 0;
$not_okey = array();
$okay_count = 0;

foreach($tables as $key => $tablename)
{
if(substr($tablename, 0, strlen(TABLE_PREFIX)) == TABLE_PREFIX)
{
$table = $db->show_create_table($tablename);
preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table, $matches);
if(fetch_iconv_encoding($matches[1]) != 'utf-8')
{
$not_okey[$key] = $tablename;
++$not_okey_count;
}
else
{
++$okay_count;
}

$mybb_tables[$key] = $tablename;
}
}

asort($mybb_tables);

if($okay_count == count($mybb_tables))
{
cperror($lang->error_all_tables_already_converted);
}

// From here we display a list of tables to convert. This is the first step
if(!$config['db_encoding'])
{
cperror($lang->error_db_encoding_not_set);
}


$hopto[] = "<input type=\"button\" value=\"{$lang->convert_all}\" onclick=\"hopto('dbtools.php?".SID."&amp;action=utf8_conversion&amp;table=all');\" class=\"hoptobutton\" />";
makehoptolinks($hopto);

starttable();
tableheader($lang->utf8_conversion, 'utf8_conversion', 2);
echo "<tr>\n";
echo "<td class=\"subheader\">".$lang->table."</td>\n";
echo "<td class=\"subheader\" align=\"center\">".$lang->status."</td>\n";
echo "</tr>\n";

foreach($mybb_tables as $key => $tablename)
{
if(array_key_exists($key, $not_okey))
{
$status = "<a href=\"dbtools.php?".SID."&amp;action=utf8_conversion&amp;table={$tablename}\">{$lang->convert_now}</a>";
}
else
{
$status = "OK";
}
$bgcolor = getaltbg();
echo "<tr>\n";
echo "<td class=\"$bgcolor\"><strong>{$tablename}</strong></td>\n";
echo "<td class=\"$bgcolor\" align=\"center\" width=\"15%\">{$status}</td>\n";
echo "</tr>\n";
}

endtable();
cpfooter();

}

if($mybb->input['action'] == 'do_delete')

}

if($mybb->input['action'] == 'do_delete')

Zeile 39Zeile 389
	if($mybb->input['deletesubmit'])
{
$file = basename($mybb->input['file']);

	if($mybb->input['deletesubmit'])
{
$file = basename($mybb->input['file']);

		

		

		if(file_exists(MYBB_ADMIN_DIR.'backups/'.$file))
{
$delete = @unlink(MYBB_ADMIN_DIR.'backups/'.$file);

		if(file_exists(MYBB_ADMIN_DIR.'backups/'.$file))
{
$delete = @unlink(MYBB_ADMIN_DIR.'backups/'.$file);

Zeile 51Zeile 401
			else
{
cperror($lang->error_delete_fail);

			else
{
cperror($lang->error_delete_fail);

			}
}
}

			}
}
}

	else
{
$mybb->input['action'] = 'existing';

	else
{
$mybb->input['action'] = 'existing';

Zeile 66Zeile 416
	{
cperror($lang->error_no_tables_selected);
}

	{
cperror($lang->error_no_tables_selected);
}

 
	
@set_time_limit(0);

	
if($mybb->input['write'] == 'disk')

	
if($mybb->input['write'] == 'disk')

	{

	{

		$file = MYBB_ADMIN_DIR.'backups/backup_'.substr(md5($mybb->user['uid'].time().random_str()), 0, 10);

if($mybb->input['type'] == 'gzip')

		$file = MYBB_ADMIN_DIR.'backups/backup_'.substr(md5($mybb->user['uid'].time().random_str()), 0, 10);

if($mybb->input['type'] == 'gzip')

Zeile 88Zeile 440
	else
{
$file = 'backup_'.substr(md5($mybb->user['uid'].time().random_str()), 0, 10);

	else
{
$file = 'backup_'.substr(md5($mybb->user['uid'].time().random_str()), 0, 10);

		if($mybb->input['type'] == 'gzip')
{

		if($mybb->input['type'] == 'gzip')
{

			// Send headers for gzip file (do ob_start too)
header('Content-Encoding: x-gzip');
header('Content-Type: application/x-gzip');
header('Content-Disposition: attachment; filename="'.$file.'.gz"');

			// Send headers for gzip file (do ob_start too)
header('Content-Encoding: x-gzip');
header('Content-Type: application/x-gzip');
header('Content-Disposition: attachment; filename="'.$file.'.gz"');

		}

		}

		else
{
// Send standard headers for .sql
header('Content-Type: text/x-sql');
header('Content-Disposition: attachment; filename="'.$file.'.sql"');

		else
{
// Send standard headers for .sql
header('Content-Type: text/x-sql');
header('Content-Disposition: attachment; filename="'.$file.'.sql"');

		}
}

$time = date('dS F Y \a\t H:i', time());
$header = "-- MyBB Database Backup\n-- Generated: ".$time."\n---------------------------------------\n\n";

if($mybb->input['write'] == 'disk')
{
if($mybb->input['type'] == 'gzip')
{
gzwrite($fp, $header, strlen($header));
}
else
{
fputs($fp, $header, strlen($header));
}
}
else
{
if($mybb->input['type'] == 'gzip')
{
echo gzencode($header);
}
else
{
echo $header;
}

		}



























	}


	}


 
	$time = date('dS F Y \a\t H:i', time());
$header = "-- MyBB Database Backup\n-- Generated: ".$time."\n-- -------------------------------------\n\n";
$contents = $header;

	foreach($mybb->input['tables'] as $table)
{
$field_list = array();
$query = $db->query("SHOW FIELDS FROM ".$table);
while($row = $db->fetch_array($query))

	foreach($mybb->input['tables'] as $table)
{
$field_list = array();
$query = $db->query("SHOW FIELDS FROM ".$table);
while($row = $db->fetch_array($query))

		{

		{

			$field_list[] = $row['Field'];
}
$fields = implode(",", $field_list);

			$field_list[] = $row['Field'];
}
$fields = implode(",", $field_list);

		if($mybb->input['contents'] != 'data')
{
$structure = $db->show_create_table($table)."\n";
if($mybb->input['write'] == 'disk')
{
if($type == 'gzip')
{
gzwrite($fp, $structure, strlen($structure));
}
else
{
fputs($fp, $structure, strlen($structure));
}
}
else
{
if($mybb->input['type'] == 'gzip')
{
echo gzencode($structure);
}
else
{
echo $structure;
}
}

		if($mybb->input['contents'] != 'data')
{
$structure = $db->show_create_table($table).";\n";
$contents .= $structure;
seq_backup($fp, $contents);





















		}
if($mybb->input['contents'] != 'structure')

		}
if($mybb->input['contents'] != 'structure')

		{

		{

			$query = $db->simple_select($table);
while($row = $db->fetch_array($query))
{

			$query = $db->simple_select($table);
while($row = $db->fetch_array($query))
{

Zeile 173Zeile 482
				$comma = '';
foreach($field_list as $field)
{

				$comma = '';
foreach($field_list as $field)
{

					if(!isset($row[$field]))

					if(!isset($row[$field]) || trim($row[$field]) == "")

					{

					{

						$insert .= $comma.'NULL';
}
else
{
$insert .= $comma."'".$db->escape_string($row[$field])."'";
}
$comma = ',';
}
$insert .= ")\n";
if($mybb->input['write'] == 'disk')
{
if($type == 'gzip')
{
gzwrite($fp, $insert, strlen($insert));
}
else
{
fputs($fp, $insert, strlen($insert));
}
}
else
{
if($mybb->input['type'] == 'gzip')
{
echo gzencode($insert);

						$insert .= $comma."''";

























					}
else
{

					}
else
{

						echo $insert;

						$insert .= $comma."'".$db->escape_string($row[$field])."'";

					}

					}

 
					$comma = ',';

				}

				}

 
				$insert .= ");\n";
$contents .= $insert;
seq_backup($fp, $contents);

			}
}
}

			}
}
}

Zeile 214Zeile 503
	{
if($mybb->input['type'] == 'gzip')
{

	{
if($mybb->input['type'] == 'gzip')
{

 
			gzwrite($fp, $contents);

			gzclose($fp);
}
else
{

			gzclose($fp);
}
else
{

 
			fwrite($fp, $contents);

			fclose($fp);
}


			fclose($fp);
}


		if($mybb->input['type'] == 'gzip')
{
$ext = '.gz';
}
else
{
$ext = '.sql';
}


		if($mybb->input['type'] == 'gzip')
{
$ext = '.gz';
}
else
{
$ext = '.sql';
}


		$file_from_admindir = 'dbtools.php?'.SID.'&amp;action=dlbackup&amp;file='.basename($file).$ext;
$lang->backup_complete = sprintf($lang->backup_complete, $file.$ext, $file_from_admindir);
cpmessage($lang->backup_complete);

		$file_from_admindir = 'dbtools.php?'.SID.'&amp;action=dlbackup&amp;file='.basename($file).$ext;
$lang->backup_complete = sprintf($lang->backup_complete, $file.$ext, $file_from_admindir);
cpmessage($lang->backup_complete);

	}
}












	}
else
{
if($mybb->input['type'] == "gzip")
{
echo gzencode($contents);
}
else
{
echo $contents;
}
}
}


if($mybb->input['action'] == "dlbackup")
{
if(empty($mybb->input['file']))


if($mybb->input['action'] == "dlbackup")
{
if(empty($mybb->input['file']))

	{

	{

		cperror($lang->error_download_no_file);
}

		cperror($lang->error_download_no_file);
}

 
	
@set_time_limit(0);

	
$file = basename($mybb->input['file']);
$ext = get_extension($file);

	
$file = basename($mybb->input['file']);
$ext = get_extension($file);

Zeile 267Zeile 571
	{
cperror($lang->error_no_tables_selected);
}

	{
cperror($lang->error_no_tables_selected);
}

 
	
@set_time_limit(0);

	
foreach($mybb->input['tables'] as $table)
{

	
foreach($mybb->input['tables'] as $table)
{

Zeile 343Zeile 649
	else
{
makelabelcode($lang->no_existing_backups);

	else
{
makelabelcode($lang->no_existing_backups);

	}

	}

	
endtable();
cpfooter();

	
endtable();
cpfooter();

Zeile 512Zeile 818
	echo "</td>\n";
echo "</tr>\n";
makeyesnocode($lang->analyse_optimise, 'analyse');

	echo "</td>\n";
echo "</tr>\n";
makeyesnocode($lang->analyse_optimise, 'analyse');

 
	makeyesnocode($lang->sequential_backup, 'sequential_backup');

	endtable();
endform($lang->perform_backup);
cpfooter();

	endtable();
endform($lang->perform_backup);
cpfooter();

 
}

function seq_backup($fp, &$contents)
{
global $mybb;

if($mybb->input['sequential_backup'] == 'yes')
{
if($mybb->input['write'] == 'disk')
{
if($mybb->input['type'] == 'gzip')
{
gzwrite($fp, $contents);
}
else
{
fwrite($fp, $contents);
}
}
else
{
if($mybb->input['type'] == "gzip")
{
echo gzencode($contents);
}
else
{
echo $contents;
}
}

$contents = '';
}

}
?>

}
?>