Exemple #1
0
 public function database()
 {
     requireadmin();
     $file = isset($_FILES["file"]) ? $_FILES["file"] : false;
     if ($file) {
         $name = $file['name'];
         $extArr = explode(".", $name);
         $ext = end($extArr);
         if (strtolower($ext) == 'tsdbak') {
             $tmpFile = 'static/temp/' . strtotime('now') . '.zip';
             move_uploaded_file($file["tmp_name"], $tmpFile);
             $tempFolder = 'static/temp/' . random_string('alnum', 32);
             $zip = new ZipArchive();
             if ($zip->open($tmpFile) === TRUE) {
                 $zip->extractTo($tempFolder);
                 $zip->close();
                 unlink($tmpFile);
                 $sqlFile = $tempFolder . '/backup.sql';
                 if (is_file($sqlFile)) {
                     $this->load->helper("sql_import");
                     sql_import($sqlFile);
                     generate_json(array('status' => 1));
                 } else {
                     generate_json(array('status' => 0, 'message' => 'Cannot read database info from file.'));
                 }
             } else {
                 generate_json(array('status' => 0, 'message' => 'Failed to extract file, maybe its corrupted.'));
             }
         } else {
             generate_json(array('status' => 0, 'message' => 'Invalid backup file.'));
         }
     } else {
         generate_json(array('status' => 0, 'message' => 'No file to upload.'));
     }
 }
Exemple #2
0
    if (empty($_GET['mysql_ver_confirm'])) {
        if (empty($sql_info['mysql_ver'])) {
            sys_msg($_LANG['unrecognize_mysql_version']);
        } else {
            $mysql_ver_arr = $db->version();
            if ($sql_info['mysql_ver'] != $mysql_ver_arr) {
                $lnk = array();
                $lnk[] = array('text' => $_LANG['confirm_ver'], 'href' => 'database.php?act=upload_sql&mysql_ver_confirm=1');
                $lnk[] = array('text' => $_LANG['unconfirm_ver'], 'href' => 'database.php?act=restore');
                sys_msg(sprintf($_LANG['mysql_version_error'], $mysql_ver_arr, $sql_info['mysql_ver']), 0, $lnk, false);
            }
        }
    }
    /* 设置最长执行时间为5分钟 */
    @set_time_limit(300);
    if (sql_import($sql_file)) {
        clear_all_files();
        @unlink($sql_file);
        sys_msg($_LANG['restore_success'], 0, array());
    } else {
        @unlink($sql_file);
        sys_msg($_LANG['sqlfile_error'], 1);
    }
}
/*------------------------------------------------------ */
//-- 优化页面
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'optimize') {
    /* 初始化数据 */
    admin_priv('db_backup');
    $db_ver_arr = $db->version();
Exemple #3
0
     /* 创建数据表 */
     if (mysql_get_server_info() > '4.1') {
         mysql_query("CREATE DATABASE `{$_POST['dbname']}` DEFAULT CHARACTER SET utf8");
     } else {
         mysql_query("CREATE DATABASE `{$_POST['dbname']}`");
     }
     if ($errno = mysql_errno()) {
         $tpl['errors']['error'] = $_DBD['dberror_' . $errno] ? sprintf($_DBD['dberror_' . $errno], $_POST['dbname']) : $_DBD['dberror_cret'];
     } else {
         mysql_select_db($_POST['dbname']);
     }
 }
 /* 数据库创建成功 */
 if (empty($tpl['errors']['error'])) {
     /* 数据库导入成功 */
     if (sql_import()) {
         /* 构建系统配置文件 */
         file_systemconfig_build();
         /* 更新管理员 */
         update_administrator();
         /* 设置成功标识 */
         $_SESSION[SN_INSTALL][$step] = 'ok';
         /* 下一步 */
         header('location:index.php?step=' . ($step + 1));
         exit;
     } else {
         /* 错误信息 */
         $tpl['errors']['error'] = mysql_errno() . ': ' . mysql_error();
         /* 移除数据库 */
         mysql_query("DROP DATABASE `{$_POST['dbname']}`");
     }
Exemple #4
0
 function connect()
 {
     $domain = $_SERVER['HTTP_HOST'];
     if ($domain == 'localhost') {
         $kapcsolat = mysql_connect("localhost", LOCALHOST_DB_USER, LOCALHOST_DB_PASSWORD);
         $adatbazis = mysql_select_db(LOCALHOST_DB_NAME);
     } else {
         $kapcsolat = mysql_connect("localhost", DOMAIN_DB_USER, DOMAIN_DB_PASSWORD);
         $adatbazis = mysql_select_db(DOMAIN_DB_NAME);
     }
     if (!$kapcsolat) {
         die('Hiba a MySQL szerverhez kapcsolódás közben: ' . mysql_error());
     }
     $ekezet = mysql_set_charset("utf8", $kapcsolat);
     if ($_REQUEST[db_save]) {
         if (!$_REQUEST[table]) {
             $tables = '*';
         } else {
             $tables = $_REQUEST[table];
         }
         backup_tables($tables);
     }
     if ($_REQUEST[db_load]) {
         sql_import("db-backup.sql");
     }
 }
Exemple #5
0
					
				</td>
				<td width=80% valign=top class="cwContentDisplay" align=left>
				<!-- Right side tabs -->
					<table border=0 cellspacing=0 cellpadding=10 width=100%>
					<tr><td class=small align=left><img src="include/install/images/confWizFinish.gif" alt="安装完成" title="安装完成"><br>
					  <hr noshade size=1></td></tr>

					<tr>
					<td align=center class="small" style="height:250px;"> 

<?php 
require 'include/init.php';
global $adb;
$filepath = 'storage/c3crm.sql';
$init = sql_import($filepath);
//populating forums data
//this is to rename the installation file and folder so that no one destroys the setup
$renamefile = uniqid(rand(), true);
//@rename("install.php", $renamefile."install.php.txt");
if (!rename("install.php", $renamefile . "install.php.txt")) {
    if (copy("install.php", $renamefile . "install.php.txt")) {
        unlink($renamefile . "install.php.txt");
    }
}
//@rename("install/", $renamefile."install/");
if (!rename("install/", $renamefile . "install/")) {
    if (copy("install/", $renamefile . "install/")) {
        unlink($renamefile . "install/");
    }
}
Exemple #6
0
 public function import($file_name)
 {
     /* 权限判断 */
     $result = array('error' => 1, 'content' => '');
     $is_confirm = empty($_GET['confirm']) ? false : true;
     $path = ROOT_PATH . '/Temp/sqldata/';
     if ($file_name == '') {
         die;
     }
     /* 设置最长执行时间为5分钟 */
     @set_time_limit(300);
     if (preg_match('/_[0-9]+\\.sql$/', $file_name)) {
         /* 多卷处理 */
         if ($is_confirm == false) {
             /* 提示用户要求确认 */
             //sys_msg($_LANG['confirm_import'], 1, array(array('text'=>$_LANG['also_continue'], 'href'=>'database.php?act=import&confirm=1&file_name=' . $file_name)), false);
             exit;
         }
         $short_name = substr($file_name, 0, strrpos($file_name, '_'));
         /* 获取文件列表 */
         $real_file = array();
         $folder = opendir($path);
         while ($file = readdir($folder)) {
             if (is_file($path . $file) && preg_match('/_[0-9]+\\.sql$/', $file)) {
                 $real_file[] = $file;
             }
         }
         /* 所有相同分卷数据列表 */
         $post_list = array();
         foreach ($real_file as $file) {
             $tmp_name = substr($file, 0, strrpos($file, '_'));
             if ($tmp_name == $short_name) {
                 $post_list[] = $file;
             }
         }
         natsort($post_list);
         /* 开始恢复数据 */
         foreach ($post_list as $file) {
             $info = sql_dumpDB::get_head($path . $file);
             if ($info['ecs_ver'] != VERSION) {
                 //sys_msg(sprintf($_LANG['version_error'], VERSION, $sql_info['ecs_ver']));
             }
             if (!sql_import($path . $file)) {
                 //sys_msg($_LANG['sqlfile_error'], 1);
                 $result['content'] = Lang('sql_error');
                 return $result;
             }
         }
         //sys_msg($_LANG['restore_success'], 0, array(array('text'=>$_LANG['restore'], 'href'=>'database.php?act=restore')));
         $result['error'] = 0;
         $result['content'] = Lang('restore_success');
         return $result;
     } else {
         /* 单卷 */
         $info = sql_dumpDB::get_head($path . $file_name);
         if ($info['ecs_ver'] != VERSION) {
             //sys_msg(sprintf($_LANG['version_error'], VERSION, $sql_info['ecs_ver']));
         }
         if ($this->sql_import($path . $file_name)) {
             //sys_msg($_LANG['restore_success'], 0, array(array('text'=>$_LANG['restore'], 'href'=>'database.php?act=restore')));
             $result['error'] = 0;
             $result['content'] = Lang('restore_success');
         } else {
             //sys_msg($_LANG['sqlfile_error'], 1);
             $result['content'] = Lang('sql_error');
         }
         return $result;
     }
 }
Exemple #7
0
        $url = parse_url($ret['data']['result']);
        $path = $url['path'];
        $path_parts = pathinfo($path);
        $down_file = AROOT . $path_parts["basename"];
        $down = download_file($ret['data']['result'], $down_file);
        if (file_exists($down_file)) {
            include_once 'dUnzip2.inc.php';
            $zip = new dUnzip2($down_file);
            @mkdir(AROOT . 'apps' . DS . $folder);
            $zip->debug = false;
            $zip->unzipAll(AROOT);
            $root_directory = dirname(__FILE__) . "/";
            require $root_directory . 'include/init.php';
            global $adb;
            $filepath = (require $root_directory . 'storage/upgrade.sql');
            sql_import($filepath);
            echo 'done';
        } else {
            echo 'failed';
        }
    }
} else {
    echo 'api error';
}
function download_file($file_url, $save_to)
{
    $in = fopen($file_url, "rb");
    $out = fopen($save_to, "wb");
    while ($chunk = fread($in, 8192)) {
        $c = fwrite($out, $chunk, 8192);
    }