Exemplo n.º 1
0
function plugin_dump_upload()
{
    global $vars, $_STORAGE, $script;
    $qm = get_qm();
    if (!PLUGIN_DUMP_ALLOW_RESTORE) {
        return array('code' => FALSE, 'msg' => $qm->m['plg_dump']['err_prohibit_restore']);
    }
    $filename = $_FILES['upload_file']['name'];
    $matches = array();
    $arc_kind = FALSE;
    if (!preg_match('/\\.zip$/', $filename, $matches)) {
        die_message($qm->m['plg_dump']['err_invalid_filetype']);
    }
    if ($_FILES['upload_file']['size'] > PLUGIN_DUMP_MAX_FILESIZE * 1024) {
        die_message($qm->replace('plg_dump.err_size_over', PLUGIN_DUMP_MAX_FILESIZE));
    }
    //require unzip
    require_once LIB_DIR . 'unzip.lib.php';
    // Create a temporary tar file
    $uploadfile = tempnam(realpath(CACHEQHM_DIR), 'zip_uploaded_');
    if (!move_uploaded_file($_FILES['upload_file']['tmp_name'], $uploadfile)) {
        @unlink($uploadfile);
        die_message($qm->m['plg_dump']['err_upload_failed']);
    }
    $unzip = new SimpleUnzip($uploadfile);
    $files = array();
    $len = $unzip->Count();
    for ($i = 0; $i < $len; $i++) {
        $name = $unzip->GetName($i);
        $path = $unzip->GetPath($i);
        //path をディレクトリにする: ./ で始まる場合、それを除去
        $dir = basename($path);
        //swfu/d
        if ($dir == 'd') {
            $dir = strpos($path, 'swfu/d') !== FALSE ? 'swfu/d' : '';
        }
        if ($dir == 'data') {
            //swfu/data
            if (strpos($path, 'swfu/data') !== FALSE) {
                $dir = 'swfu/data';
            } else {
                if (strpos($path, 'fwd3/sys/data') !== FALSE) {
                    $dir = 'fwd3/sys/data';
                }
            }
        }
        if (strpos($path, './.') !== FALSE) {
            $path = str_replace('./.', '.', $path);
        }
        switch ($dir) {
            case 'wiki':
                $stokey = 'DATA_DIR';
                break;
            case 'attach':
                $stokey = 'UPLOAD_DIR';
                break;
            case 'backup':
                $stokey = 'BACKUP_DIR';
                break;
            case 'swfu/d':
                $stokey = 'SWFU_DIR';
                break;
            case 'swfu/data':
                $stokey = 'SWFUDATA_DIR';
                break;
            case 'fwd3/sys/data':
                $stokey = 'FWD3DATA_DIR';
                break;
            case 'cache':
                $stokey = 'CACHE_DIR';
                break;
            default:
                $stokey = 'HOME_DIR';
        }
        $filter = isset($_STORAGE[$stokey]['extract_filter']) ? $_STORAGE[$stokey]['extract_filter'] : '';
        if ($filter && preg_match("/{$filter}/", $name)) {
            $uzfile = $path . '/' . $name;
            $files[] = $uzfile;
            $data = $unzip->GetData($i);
            $dlen = strlen($data);
            if ($fp = fopen($uzfile, "wb")) {
                fwrite($fp, $data, $dlen);
                fclose($fp);
                chmod($uzfile, 0666);
            } else {
                echo '<error>', $qm->replace('plg_dump.err_open_archive', $name), '</error>';
            }
        }
    }
    if (empty($files)) {
        @unlink($uploadfile);
        return array('code' => FALSE, 'msg' => $qm->m['plg_dump']['err_upload_empty']);
    }
    $msg = '<p><strong>' . $qm->m['plg_dump']['restore_header'] . '</strong><ul>';
    foreach ($files as $name) {
        $msg .= "<li>{$name}</li>\n";
    }
    $msg .= '</ul></p>';
    $msg .= '
<p>
	<a href="' . h($script) . '?cmd=qhmsetting">設定一覧へ戻る</a>
</p>
';
    @unlink($uploadfile);
    return array('code' => TRUE, 'msg' => $msg);
}