Exemple #1
0
function SQLFromFile($file)
{
    global $db, $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DB_NAME, $MYSQL_CHARSET;
    // try to upload dump via exec("mysql")
    $err_code = 127;
    @exec("mysql --host={$MYSQL_HOST} --user={$MYSQL_USER}" . ($MYSQL_PASSWORD ? " --password={$MYSQL_PASSWORD} " : "") . ((double) mysql_get_server_info() > 4 ? " --default-character-set={$MYSQL_CHARSET} " : "") . "  {$MYSQL_DB_NAME} < {$file} 2>&1", $output, $err_code);
    // exec failed
    if ($err_code) {
        $mysql_dump = new MYSQL_DUMP($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_CHARSET);
        // $sql = $mysql_dump->dumpDB($MYSQL_DB_NAME);
        if ($mysql_dump->restoreDB($file) == false) {
            echo $mysql_dump->error();
            return false;
        }
    }
    return true;
}
Exemple #2
0
 $dir = $type == 'all' ? HOME : USERS_DIR . 'files/';
 // increase memory limit
 ini_set('memory_limit', '64M');
 $backup_dir = USERS_DIR . 'backup/';
 if (!is_dir($backup_dir)) {
     mkdir($backup_dir);
 }
 // json encode settings
 global $DB, $SETTINGS, $PLUGINS;
 $settings = array('SETTINGS' => $SETTINGS);
 if ($type == 'all') {
     $settings['PLUGINS'] = $PLUGINS;
 }
 $settings = json_encode($settings);
 // backup database
 $dump = new MYSQL_DUMP($DB['host'], $DB['user'], $DB['pass']);
 $sql = $dump->dumpDB($DB['name']);
 // backup files
 $zip = new zipfile();
 $files = scandir($dir);
 function zip_files($files, $dir = '', $zdir = '', $zip)
 {
     foreach ($files as $file) {
         if ($file == '.' || $file == '..' || $file == 'backup') {
             continue;
         }
         if (is_dir($dir . $file)) {
             $zip->addDir($zdir . $file);
             zip_files(scandir($dir . $file), $dir . $file . '/', $zdir . $file . '/', $zip);
         } else {
             $zip->addFile(file_get_contents($dir . $file), $zdir . $file);
if (!empty($submitId) && isset($submitId)) {
    $backupType['hidden'] = secureVar(trim($_POST['hiddenField']), 'html');
    $backupType['backupType'] = secureVar(trim($_POST['backupType']), 'html');
    if ($backupType['hidden'] != '') {
        $error = new Error("Humans only ! Go away WALL&#183;E");
        die($error->showError());
    }
    if ($backupType['backupType'] == 'restore') {
        if (base64_decode($_SESSION['privilege']) == 1) {
            $errorField = '';
            $uploadedFilePost = @$HTTP_POST_FILES['uploadField']['name'];
            if (isset($uploadedFilePost) && !empty($uploadedFilePost)) {
                $uploadedFile = $config['backupFolder'] . '/' . basename($_FILES['uploadField']['name']);
                if (@move_uploaded_file($_FILES['uploadField']['tmp_name'], $uploadedFile)) {
                    include_once '../classes/database/mysql_dump.inc.php';
                    $mysql_dump = new MYSQL_DUMP($data['dbHost'], $data['dbUsername'], $data['dbPassword']);
                    $con->connect();
                    if ($mysql_dump->restoreDB($uploadedFile)) {
                        @unlink($uploadedFile);
                        $queryMsg = "insert into " . $dbTables['backupLog'] . " (id, date, operation) values (NULL, '" . secureVar(time(), 'sql') . "', '" . secureVar('r', 'sql') . "');";
                        $con->modify($queryMsg);
                        echo "<div class=\"msgSuccess\">" . $lang['changeSuccess'] . "</div>";
                    } else {
                        echo "<div class=\"msgError\">" . $lang['dataError'] . "</div>";
                    }
                    $con->close();
                } else {
                    $errorField .= $lang['permissionsError'] . '<br />';
                }
            } else {
                $errorField .= $lang['sqlFile'] . ' ' . $lang['isEmpty'] . '<br />';
<?php

/**
 * Database Backup, Furasta.Org
 *
 * Dumps the content of the current database to /backup/db-backup.sql
 *
 * @author     Conor Mac Aoidh <*****@*****.**>
 * @license    http://furasta.org/licence.txt The BSD License
 * @version    1.0
 * @package    admin_settings
 */
if (!defined('AJAX_LOADED') || !defined('AJAX_VERIFIED')) {
    exit;
}
if (!is_dir(USERS_DIR . 'backup')) {
    mkdir(USERS_DIR . 'backup');
}
$dump = new MYSQL_DUMP($DB['host'], $DB['user'], $DB['pass']);
$sql = $dump->dumpDB($DB['name']);
$dump->save_sql($sql, USERS_DIR . 'backup/db-backup.sql');
die('ok');
Exemple #5
0
function restore_dump($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DB_NAME, $MYSQL_CHARSET)
{
    // Try via command-line mysql first
    $err_code = 127;
    $path = dirname(__FILE__) . DIRECTORY_SEPARATOR;
    $exec_str = "mysql --host=" . escapeshellarg($MYSQL_HOST) . " --user="******" --password="******" --default-character-set={$MYSQL_CHARSET} " : "") . "  " . escapeshellarg($MYSQL_DB_NAME) . " < {$path}netcat.sql 2>&1";
    exec($exec_str, $output, $err_code);
    if ($err_code) {
        $mysql_dump = new MYSQL_DUMP($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_CHARSET);
        $mysql_dump->dumpDB($MYSQL_DB_NAME);
        if ($mysql_dump->restoreDB("{$path}netcat.sql") == false) {
            echo "Failed to import MySQL dump:<br />\n";
            echo $mysql_dump->error();
            echo "Cmdline output: \n<br />\n";
            foreach ($output as $l) {
                echo $l . "\n<br />";
            }
            echo "\n<br />\n";
            return false;
        }
    }
    return true;
}
require_once '../../../configuration.php';
if (@is_dir("../../../setup")) {
    $error = new Error("Setup directory exists. You either haven't installed your guestbook, or forgot to delete the setup folder.");
    die($error->showError());
}
if (!file_exists("../../../data.php")) {
    $error = new Error("Data file doesn't exist. Have you installed your guestbook yet?");
    die($error->showError());
}
require_once '../iden.php';
if (@$magicBackup != "0xNOWALLEALLOWED") {
    die("This file cannot be executed directly");
}
unset($magicBackup);
include_once '../../../classes/database/mysql_dump.inc.php';
$mysql_dump = new MYSQL_DUMP(base64_decode($data['dbHost']), base64_decode($data['dbUsername']), base64_decode($data['dbPassword']));
$data['dbDatabaseDecoded'] = base64_decode($data['dbDatabase']);
$sql1 = $mysql_dump->dumpDB($data['dbDatabaseDecoded'], $dbTables['config'], HAR_ALL_OPTIONS);
$sql2 = $mysql_dump->dumpDB($data['dbDatabaseDecoded'], $dbTables['admin'], HAR_ALL_OPTIONS);
$sql3 = $mysql_dump->dumpDB($data['dbDatabaseDecoded'], $dbTables['posts'], HAR_ALL_OPTIONS);
$sql4 = $mysql_dump->dumpDB($data['dbDatabaseDecoded'], $dbTables['ip'], HAR_ALL_OPTIONS);
$sql5 = $mysql_dump->dumpDB($data['dbDatabaseDecoded'], $dbTables['censored'], HAR_ALL_OPTIONS);
$sql6 = $mysql_dump->dumpDB($data['dbDatabaseDecoded'], $dbTables['smilies'], HAR_ALL_OPTIONS);
$sql7 = $mysql_dump->dumpDB($data['dbDatabaseDecoded'], $dbTables['trash'], HAR_ALL_OPTIONS);
$sql8 = $mysql_dump->dumpDB($data['dbDatabaseDecoded'], $dbTables['reply'], HAR_ALL_OPTIONS);
$sql9 = $mysql_dump->dumpDB($data['dbDatabaseDecoded'], $dbTables['backupLog'], HAR_ALL_OPTIONS);
unset($data['dbDatabaseDecoded']);
$sql = $sql1 . $sql2 . $sql3 . $sql4 . $sql5 . $sql6 . $sql7 . $sql8 . $sql9;
$sql_file = "angora_" . time() . ".sql";
$mysql_dump->download_sql($sql, $sql_file);
include_once '../../../classes/functions.php';