Esempio n. 1
0
	public function extract($archive="", $outputDir = "")
	{
		$gzh = gzopen($archive, 'r') or die("Could not open $archive");
		if(!is_dir($outputDir))
		{
			mkdir($outputDir, 0700, true) or die("Could not create a $outputDir directory");
		}
		$_archive = str_ireplace('.tgz', '.gz', $archive);
		$tar_path = basename($_archive, '.gz');
		$lchar = substr($outputDir, -1);
		if('/' == $lchar OR '\\' == $lchar)
		{
			$tar_path = $outputDir.$tar_path;
		} else {
			$tar_path = $outputDir."/".$tar_path;
		}
		$fh = fopen($tar_path, "w");
		while(!feof($gzh))
		{
			$cstr = gzread($gzh, 4096);
			fwrite($fh, $cstr);
		}
		bzclose($gzh);
		fclose($fh);
		$this->tarHandler->extract($tar_path, $outputDir);
		echo "<font color=\"green\">Sucessfull!</font>";
	}
Esempio n. 2
0
 protected function getLines()
 {
     $handle = bzopen($this->file, "r");
     if ($handle) {
         $decompressedData = '';
         while (true) {
             do {
                 if (feof($handle)) {
                     bzclose($handle);
                     return;
                 }
                 $decompressedData .= bzread($handle, 8192);
                 $key = strpos($decompressedData, "\n");
             } while ($key === false);
             do {
                 $line = substr($decompressedData, 0, $key + 1);
                 $decompressedData = substr_replace($decompressedData, '', 0, $key + 1);
                 (yield $line);
                 $key = strpos($decompressedData, "\n");
             } while ($key !== false);
         }
     } else {
         throw new \Exception("не удалось открыть файл");
     }
 }
Esempio n. 3
0
 /**
  * Static method to decompress data
  *
  * @param  string $data
  * @return mixed
  */
 public static function decompress($data)
 {
     // Decompress the file
     if (@file_exists($data)) {
         $bz = bzopen($data, 'r');
         $uncompressed = '';
         // Read the uncompressed data.
         while (!feof($bz)) {
             $uncompressed .= bzread($bz, 4096);
         }
         // Close the Bzip2 compressed file and write
         // the data to the uncompressed file.
         bzclose($bz);
         if (stripos($data, '.tbz2') !== false) {
             $newFile = str_replace('.tbz2', '.tar', $data);
         } else {
             if (stripos($data, '.tbz') !== false) {
                 $newFile = str_replace('.tbz', '.tar', $data);
             } else {
                 $newFile = str_replace('.bz2', '', $data);
             }
         }
         file_put_contents($newFile, $uncompressed);
         return $newFile;
         // Else, decompress the string
     } else {
         return bzdecompress($data);
     }
 }
Esempio n. 4
0
 public function read($file)
 {
     $open = bzopen($file, 'r');
     if (empty($open)) {
         throw new FileNotFoundException('Error', 'fileNotFound', $file);
     }
     $return = bzread($open, 8096);
     bzclose($open);
     return $return;
 }
Esempio n. 5
0
function bzfile($file)
{
    $bz = bzopen($file, "r");
    $str = "";
    while (!feof($bz)) {
        $str = $str . bzread($bz, 8192);
        bzclose($bz);
    }
    return $str;
}
Esempio n. 6
0
 function _bz2($string, $state)
 {
     bzwrite($this->fp, $string);
     if ($state & PHP_OUTPUT_HANDLER_END) {
         bzclose($this->fp);
         $return = file_get_contents($this->filename);
         unlink($this->filename);
         return $return;
     }
     return "";
 }
Esempio n. 7
0
 function bunzip($infile, $outfile)
 {
     $string = null;
     $zp = bzopen($infile, "r");
     while (!feof($zp)) {
         $string .= bzread($zp, 4096);
     }
     bzclose($zp);
     $fp = fopen($outfile, "w");
     fwrite($fp, $string, strlen($string));
     fclose($fp);
 }
Esempio n. 8
0
 public function compress($fileName)
 {
     $this->tarHandler->compress($fileName);
     $bzh = bzopen($fileName . '.tar.bz2', 'wb');
     $th = fopen($fileName . ".tar", 'rb');
     while (!feof($th)) {
         $ustr = fread($th, 1048576);
         bzwrite($bzh, $ustr);
     }
     bzclose($bzh);
     fclose($th);
 }
Esempio n. 9
0
function test_bzerror()
{
    global $tmpfile;
    $f = fopen($tmpfile, "w");
    fwrite($f, "this is a test");
    fclose($f);
    $f = bzopen($tmpfile, "r");
    bzread($f);
    $ret = bzerror($f);
    bzclose($f);
    unlink($tmpfile);
    VS($ret, array("errno" => -5, "errstr" => "DATA_ERROR_MAGIC"));
}
Esempio n. 10
0
 /**
  * {@inheritdoc}
  */
 public function extract($file, $target, Format\FormatInterface $format)
 {
     $this->checkSupport($format);
     $basename = pathinfo($file, PATHINFO_FILENAME);
     if (false === $this->isValid($file)) {
         throw new Exception\IO\Input\FileCorruptedException($file, Exception\IO\Input\FileCorruptedException::SEVERITY_HIGH);
     }
     $source = bzopen($file, 'r');
     $this->getFilesystem()->mkdir($target);
     $destination = fopen($target . DIRECTORY_SEPARATOR . $basename, 'w');
     $bytes = stream_copy_to_stream($source, $destination);
     bzclose($source);
     fclose($destination);
     return $bytes > 0;
 }
Esempio n. 11
0
 function extractBzip2($src, $dest = false)
 {
     $bz = bzopen($src, "r");
     $data = '';
     while (!feof($bz)) {
         $data .= bzread($bz, 1024 * 1024);
     }
     bzclose($bz);
     if (empty($dest)) {
         return $data;
     } elseif (file_put_contents($dest, $data)) {
         return $dest;
     }
     return false;
 }
 public function peekLine()
 {
     $line = false;
     if ($this->tResource !== false) {
         if ($this->tLine === false) {
             $this->tLine = gzgets($this->tResource, FileDecoder::BUFLEN);
         }
         if ($this->tLine !== false) {
             $line = $this->tLine;
         } else {
             bzclose($this->tResource);
             $this->tResource = false;
         }
     }
     return $line;
 }
Esempio n. 13
0
 public function read($file = '', $length = 1024, $type = NULL)
 {
     if (!is_string($file) || empty($file)) {
         return Error::set('Error', 'stringParameter', '1.(file)');
     }
     if (!is_numeric($length)) {
         return Error::set('Error', 'numericParameter', '2.(length)');
     }
     $open = bzopen($file, 'r');
     if (empty($open)) {
         return Error::set('Error', 'fileNotFound', $file);
     }
     $return = bzread($open, $length);
     bzclose($open);
     return $return;
 }
Esempio n. 14
0
function x()
{
    $uncheckedDir = opendir('.');
    readdir($uncheckedDir);
    $uncheckedDir2 = bzopen('.');
    bzclose($uncheckedDir2);
    $uncheckedDir3 = fopen('.', 'r+');
    fclose($uncheckedDir3);
    readdir(opendir('uncheckedDir4'));
    readdir2(opendir('uncheckedDir5'));
    readdir(opendir2('uncheckedDir6'));
    $pspell_new = pspell_new('asdfasdf');
    while ($f = pspell_suggest($pspell_new)) {
        print "{$f}\n";
    }
}
Esempio n. 15
0
 function bzip2($in, $out)
 {
     if (!file_exists($in) || !is_readable($in)) {
         return false;
     }
     if (!file_exists($out) && !is_writeable(dirname($out)) || file_exists($out) && !is_writable($out)) {
         return false;
     }
     $in_file = fopen($in, "r");
     $out_file = bzopen($out, "w");
     while (!feof($in_file)) {
         $buffer = fgets($in_file, 4096);
         bzwrite($out_file, $buffer, 4096);
     }
     fclose($in_file);
     bzclose($out_file);
     return true;
 }
Esempio n. 16
0
 static function load_bz($file_name)
 {
     global $wgOfflineWikiPath;
     $path = "{$wgOfflineWikiPath}/{$file_name}";
     if (strlen($file_name) < 1) {
         return null;
     }
     #strange that bzopen doesn't choke on dir.
     $bz = bzopen($path, "r");
     if (!$bz) {
         return null;
     }
     $out = "";
     while ($bz && !feof($bz)) {
         $out .= bzread($bz, 8192);
     }
     bzclose($bz);
     return $out;
 }
Esempio n. 17
0
 /**
  * Unpack file by BZIP2 compressor.
  *
  * @param string $source
  * @param string $destination
  * @return string
  */
 public function unpack($source, $destination)
 {
     $data = '';
     $bzPointer = bzopen($source, 'r');
     if (empty($bzPointer)) {
         throw new Exception('Can\'t open BZ archive : ' . $source);
     }
     while (!feof($bzPointer)) {
         $data .= bzread($bzPointer, 131072);
     }
     bzclose($bzPointer);
     if (is_dir($destination)) {
         $file = $this->getFilename($source);
         $destination = $destination . $file;
     }
     echo $destination;
     $this->_writeFile($destination, $data);
     return $destination;
 }
 /**
  * Décompression du contenu. Si path est donné les fichiers sont décompressés dans le répertoire en question,
  * sinon, ils sont retournés "en mémoire".
  *
  * @param filename, path where uncompress
  * @return buffer uncompressed or boolean for save success if path given
  */
 public function uncompress($filename, $path = null)
 {
     if (!($bz = bzopen($filename, "r"))) {
         return null;
     }
     $decompressed_file = '';
     while (!feof($bz)) {
         $decompressed_file .= bzread($bz, 4096);
     }
     bzclose($bz);
     if ($path) {
         if ($fp = fopen($path, 'w')) {
             fwrite($fp, $decompressed_file, strlen($decompressed_file));
             fclose($fp);
             return true;
         }
         return false;
     }
     return $decompressed_file;
 }
Esempio n. 19
0
function getFile($full_filename)
{
	$extension = pathinfo($full_filename, PATHINFO_EXTENSION);
	if ($extension == "bz2")
	{
		$bz = bzopen($full_filename, "r");
		while (!feof($bz))
			$data .= bzread($bz, 4096);
		bzclose($bz);
	}
	else
	{
		$bz = fopen($full_filename, "r");
		while (!feof($bz))
			$data .= fread($bz, 4096);
		fclose($bz);
	}
	
	return $data;
}
Esempio n. 20
0
function bzip2_compress($src_file, $dest_file = null)
{
    if ($dest_file == null) {
        $dest_file = $src_file;
    }
    $content = file_get_contents($src_file);
    if (empty($content)) {
        return 1;
    }
    $bz = bzopen($dest_file, "w");
    if (!$bz) {
        return 2;
    }
    $ret = bzwrite($bz, $content);
    if (!$ret) {
        bzclose($bz);
        return 3;
    }
    bzclose($bz);
    return 0;
}
Esempio n. 21
0
function download($url, $file)
{
    $tmp = $file . '.bz2';
    $fp = fopen($tmp, "w");
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_FILE, $fp);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    $result = curl_exec($curl);
    curl_close($curl);
    fclose($fp);
    if ($result == false) {
        return false;
    }
    $bz = bzopen($tmp, "r");
    $fp = fopen($file, "w");
    while (!feof($bz)) {
        fwrite($fp, bzread($bz, 4096));
    }
    bzclose($bz);
    fclose($fp);
    return $result;
}
Esempio n. 22
0
 public static function read($f3, $md5, $filename)
 {
     $path_temp = PFH_MD5::get_tmp_file_path($f3, $md5, $filename);
     // 移除多餘的快取資料
     PFH_Archive_cache::clean($f3, $path_temp);
     if (is_file($path_temp) === FALSE) {
         $path = PFH_MD5::get_file_path($f3, $md5, $filename);
         $tmp_dir = PFH_MD5::get_tmp_dir_path($f3, $md5);
         //$tmp_file = PFH_MD5::get_tmp_file_path($f3, $md5);
         if (is_file($path)) {
             // 沒有壓縮的情況
             return $path;
         }
         //if (is_file($path)) {
         if (is_file($path . ".zip")) {
             $archive = new ZipArchive();
             //echo $path;
             $res = $archive->open($path . ".zip");
             //$zip->extractTo($tmp_file);
             $archive->extractTo($tmp_dir);
             $archive->close();
         } else {
             if (is_file($path . ".bz2")) {
                 $in_file = bzopen($path . ".bz2", "r");
                 $out_file = fopen($path_temp, "w");
                 while ($buffer = bzread($in_file, 4096)) {
                     fwrite($out_file, $buffer, 4096);
                 }
                 bzclose($in_file);
                 fclose($out_file);
             }
         }
     }
     // 加入快取資料
     PFH_Archive_cache::add($f3, $path_temp);
     return $path_temp;
 }
Esempio n. 23
0
 private function restore_backup_db($working_dir, $working_dir_localpath, &$import_table_prefix)
 {
     do_action('updraftplus_restore_db_pre');
     # This is now a legacy option (at least on the front end), so we should not see it much
     $this->prior_upload_path = get_option('upload_path');
     // There is a file backup.db(.gz) inside the working directory
     # The 'off' check is for badly configured setups - http://wordpress.org/support/topic/plugin-wp-super-cache-warning-php-safe-mode-enabled-but-safe-mode-is-off
     if (@ini_get('safe_mode') && 'off' != strtolower(@ini_get('safe_mode'))) {
         echo "<p>" . __('Warning: PHP safe_mode is active on your server. Timeouts are much more likely. If these happen, then you will need to manually restore the file via phpMyAdmin or another method.', 'updraftplus') . "</p><br/>";
     }
     $db_basename = 'backup.db.gz';
     if (!empty($this->ud_foreign)) {
         $plugins = apply_filters('updraftplus_accept_archivename', array());
         if (empty($plugins[$this->ud_foreign])) {
             return new WP_Error('unknown', sprintf(__('Backup created by unknown source (%s) - cannot be restored.', 'updraftplus'), $this->ud_foreign));
         }
         if (!file_exists($working_dir_localpath . '/' . $db_basename) && file_exists($working_dir_localpath . '/backup.db')) {
             $db_basename = 'backup.db';
         } elseif (!file_exists($working_dir_localpath . '/' . $db_basename) && file_exists($working_dir_localpath . '/backup.db.bz2')) {
             $db_basename = 'backup.db.bz2';
         }
         if (!file_exists($working_dir_localpath . '/' . $db_basename)) {
             $separatedb = empty($plugins[$this->ud_foreign]['separatedb']) ? false : true;
             $filtered_db_name = apply_filters('updraftplus_foreign_dbfilename', false, $this->ud_foreign, $this->ud_backup_info, $working_dir_localpath, $separatedb);
             if (is_string($filtered_db_name)) {
                 $db_basename = $filtered_db_name;
             }
         }
     }
     // wp_filesystem has no gzopen method, so we switch to using the local filesystem (which is harmless, since we are performing read-only operations)
     if (false === $db_basename || !is_readable($working_dir_localpath . '/' . $db_basename)) {
         return new WP_Error('dbopen_failed', __('Failed to find database file', 'updraftplus') . " ({$working_dir}/" . $db_basename . ")");
     }
     global $wpdb, $updraftplus;
     $this->skin->feedback('restore_database');
     $is_plain = substr($db_basename, -3, 3) == '.db';
     $is_bz2 = substr($db_basename, -7, 7) == '.db.bz2';
     // Read-only access: don't need to go through WP_Filesystem
     if ($is_plain) {
         $dbhandle = fopen($working_dir_localpath . '/' . $db_basename, 'r');
     } elseif ($is_bz2) {
         if (!function_exists('bzopen')) {
             $updraftplus->log_e("Your web server's PHP installation has these functions disabled: %s.", 'bzopen');
             $updraftplus->log_e('Your hosting company must enable these functions before %s can work.', __('restoration', 'updraftplus'));
         }
         $dbhandle = bzopen($working_dir_localpath . '/' . $db_basename, 'r');
     } else {
         $dbhandle = gzopen($working_dir_localpath . '/' . $db_basename, 'r');
     }
     if (!$dbhandle) {
         return new WP_Error('dbopen_failed', __('Failed to open database file', 'updraftplus'));
     }
     $this->line = 0;
     if (true == $this->use_wpdb) {
         $updraftplus->log_e('Database access: Direct MySQL access is not available, so we are falling back to wpdb (this will be considerably slower)');
     } else {
         $updraftplus->log("Using direct MySQL access; value of use_mysqli is: " . ($this->use_mysqli ? '1' : '0'));
         if ($this->use_mysqli) {
             @mysqli_query($this->mysql_dbh, 'SET SESSION query_cache_type = OFF;');
         } else {
             @mysql_query('SET SESSION query_cache_type = OFF;', $this->mysql_dbh);
         }
     }
     // Find the supported engines - in case the dump had something else (case seen: saved from MariaDB with engine Aria; imported into plain MySQL without)
     $supported_engines = $wpdb->get_results("SHOW ENGINES", OBJECT_K);
     $this->errors = 0;
     $this->statements_run = 0;
     $this->insert_statements_run = 0;
     $this->tables_created = 0;
     $sql_line = "";
     $sql_type = -1;
     $this->start_time = microtime(true);
     $old_wpversion = '';
     $this->old_siteurl = '';
     $this->old_home = '';
     $this->old_content = '';
     $old_table_prefix = defined('UPDRAFTPLUS_OVERRIDE_IMPORT_PREFIX') && UPDRAFTPLUS_OVERRIDE_IMPORT_PREFIX ? UPDRAFTPLUS_OVERRIDE_IMPORT_PREFIX : '';
     $old_siteinfo = array();
     $gathering_siteinfo = true;
     $this->create_forbidden = false;
     $this->drop_forbidden = false;
     $this->last_error = '';
     $random_table_name = 'updraft_tmp_' . rand(0, 9999999) . md5(microtime(true));
     # The only purpose in funnelling queries directly here is to be able to get the error number
     if ($this->use_wpdb) {
         $req = $wpdb->query("CREATE TABLE {$random_table_name}");
         if (!$req) {
             $this->last_error = $wpdb->last_error;
         }
         $this->last_error_no = false;
     } else {
         if ($this->use_mysqli) {
             $req = mysqli_query($this->mysql_dbh, "CREATE TABLE {$random_table_name}");
         } else {
             $req = mysql_unbuffered_query("CREATE TABLE {$random_table_name}", $this->mysql_dbh);
         }
         if (!$req) {
             $this->last_error = $this->use_mysqli ? mysqli_error($this->mysql_dbh) : mysql_error($this->mysql_dbh);
             $this->last_error_no = $this->use_mysqli ? mysqli_errno($this->mysql_dbh) : mysql_errno($this->mysql_dbh);
         }
     }
     if (!$req && ($this->use_wpdb || 1142 === $this->last_error_no)) {
         $this->create_forbidden = true;
         # If we can't create, then there's no point dropping
         $this->drop_forbidden = true;
         echo '<strong>' . __('Warning:', 'updraftplus') . '</strong> ';
         $updraftplus->log_e('Your database user does not have permission to create tables. We will attempt to restore by simply emptying the tables; this should work as long as a) you are restoring from a WordPress version with the same database structure, and b) Your imported database does not contain any tables which are not already present on the importing site.', ' (' . $this->last_error . ')');
     } else {
         if ($this->use_wpdb) {
             $req = $wpdb->query("DROP TABLE {$random_table_name}");
             if (!$req) {
                 $this->last_error = $wpdb->last_error;
             }
             $this->last_error_no = false;
         } else {
             if ($this->use_mysqli) {
                 $req = mysqli_query($this->mysql_dbh, "DROP TABLE {$random_table_name}");
             } else {
                 $req = mysql_unbuffered_query("DROP TABLE {$random_table_name}", $this->mysql_dbh);
             }
             if (!$req) {
                 $this->last_error = $this->use_mysqli ? mysqli_error($this->mysql_dbh) : mysql_error($this->mysql_dbh);
                 $this->last_error_no = $this->use_mysqli ? mysqli_errno($this->mysql_dbh) : mysql_errno($this->mysql_dbh);
             }
         }
         if (!$req && ($this->use_wpdb || $this->last_error_no === 1142)) {
             $this->drop_forbidden = true;
             echo '<strong>' . __('Warning:', 'updraftplus') . '</strong> ';
             $updraftplus->log_e('Your database user does not have permission to drop tables. We will attempt to restore by simply emptying the tables; this should work as long as you are restoring from a WordPress version with the same database structure (%s)', ' (' . $this->last_error . ')');
         }
     }
     $restoring_table = '';
     $this->max_allowed_packet = $updraftplus->get_max_packet_size();
     $updraftplus->log("Entering maintenance mode");
     $this->maintenance_mode(true);
     // N.B. There is no such function as bzeof() - we have to detect that another way
     while ($is_plain && !feof($dbhandle) || !$is_plain && ($is_bz2 || !$is_bz2 && !gzeof($dbhandle))) {
         // Up to 1Mb
         if ($is_plain) {
             $buffer = rtrim(fgets($dbhandle, 1048576));
         } elseif ($is_bz2) {
             if (!isset($bz2_buffer)) {
                 $bz2_buffer = '';
             }
             $buffer = '';
             if (strlen($bz2_buffer) < 524288) {
                 $bz2_buffer .= bzread($dbhandle, 1048576);
             }
             if (bzerrno($dbhandle) !== 0) {
                 $updraftplus->log("bz2 error: " . bzerrstr($dbhandle) . " (code: " . bzerrno($bzhandle) . ")");
                 break;
             }
             if (false !== $bz2_buffer && '' !== $bz2_buffer) {
                 if (false !== ($p = strpos($bz2_buffer, "\n"))) {
                     $buffer .= substr($bz2_buffer, 0, $p + 1);
                     $bz2_buffer = substr($bz2_buffer, $p + 1);
                 } else {
                     $buffer .= $bz2_buffer;
                     $bz2_buffer = '';
                 }
             } else {
                 break;
             }
             $buffer = rtrim($buffer);
         } else {
             $buffer = rtrim(gzgets($dbhandle, 1048576));
         }
         // Discard comments
         if (empty($buffer) || substr($buffer, 0, 1) == '#' || preg_match('/^--(\\s|$)/', substr($buffer, 0, 3))) {
             if ('' == $this->old_siteurl && preg_match('/^\\# Backup of: (http(.*))$/', $buffer, $matches)) {
                 $this->old_siteurl = untrailingslashit($matches[1]);
                 $updraftplus->log_e('<strong>Backup of:</strong> %s', htmlspecialchars($this->old_siteurl));
                 do_action('updraftplus_restore_db_record_old_siteurl', $this->old_siteurl);
                 $this->save_configuration_bundle();
             } elseif (false === $this->created_by_version && preg_match('/^\\# Created by UpdraftPlus version ([\\d\\.]+)/', $buffer, $matches)) {
                 $this->created_by_version = trim($matches[1]);
                 echo '<strong>' . __('Backup created by:', 'updraftplus') . '</strong> ' . htmlspecialchars($this->created_by_version) . '<br>';
                 $updraftplus->log('Backup created by: ' . $this->created_by_version);
             } elseif ('' == $this->old_home && preg_match('/^\\# Home URL: (http(.*))$/', $buffer, $matches)) {
                 $this->old_home = untrailingslashit($matches[1]);
                 if ($this->old_siteurl && $this->old_home != $this->old_siteurl) {
                     echo '<strong>' . __('Site home:', 'updraftplus') . '</strong> ' . htmlspecialchars($this->old_home) . '<br>';
                     $updraftplus->log('Site home: ' . $this->old_home);
                 }
                 do_action('updraftplus_restore_db_record_old_home', $this->old_home);
             } elseif ('' == $this->old_content && preg_match('/^\\# Content URL: (http(.*))$/', $buffer, $matches)) {
                 $this->old_content = untrailingslashit($matches[1]);
                 echo '<strong>' . __('Content URL:', 'updraftplus') . '</strong> ' . htmlspecialchars($this->old_content) . '<br>';
                 $updraftplus->log('Content URL: ' . $this->old_content);
                 do_action('updraftplus_restore_db_record_old_content', $this->old_content);
             } elseif ('' == $old_table_prefix && (preg_match('/^\\# Table prefix: (\\S+)$/', $buffer, $matches) || preg_match('/^-- Table Prefix: (\\S+)$/i', $buffer, $matches))) {
                 # We also support backwpup style:
                 # -- Table Prefix: wp_
                 $old_table_prefix = $matches[1];
                 echo '<strong>' . __('Old table prefix:', 'updraftplus') . '</strong> ' . htmlspecialchars($old_table_prefix) . '<br>';
                 $updraftplus->log("Old table prefix: " . $old_table_prefix);
             } elseif ($gathering_siteinfo && preg_match('/^\\# Site info: (\\S+)$/', $buffer, $matches)) {
                 if ('end' == $matches[1]) {
                     $gathering_siteinfo = false;
                     // Sanity checks
                     if (isset($old_siteinfo['multisite']) && !$old_siteinfo['multisite'] && is_multisite()) {
                         // Just need to check that you're crazy
                         if (!defined('UPDRAFTPLUS_EXPERIMENTAL_IMPORTINTOMULTISITE') || UPDRAFTPLUS_EXPERIMENTAL_IMPORTINTOMULTISITE != true) {
                             return new WP_Error('multisite_error', $this->strings['multisite_error']);
                         }
                         // Got the needed code?
                         if (!class_exists('UpdraftPlusAddOn_MultiSite') || !class_exists('UpdraftPlus_Addons_Migrator')) {
                             return new WP_Error('missing_addons', __('To import an ordinary WordPress site into a multisite installation requires both the multisite and migrator add-ons.', 'updraftplus'));
                         }
                     }
                 } elseif (preg_match('/^([^=]+)=(.*)$/', $matches[1], $kvmatches)) {
                     $key = $kvmatches[1];
                     $val = $kvmatches[2];
                     echo '<strong>' . __('Site information:', 'updraftplus') . '</strong>' . ' ' . htmlspecialchars($key) . ' = ' . htmlspecialchars($val) . '<br>';
                     $updraftplus->log("Site information: " . $key . "=" . $val);
                     $old_siteinfo[$key] = $val;
                     if ('multisite' == $key) {
                         if ($val) {
                             $this->ud_backup_is_multisite = 1;
                         } else {
                             $this->ud_backup_is_multisite = 0;
                         }
                     }
                 }
             }
             continue;
         }
         // Detect INSERT commands early, so that we can split them if necessary
         if (preg_match('/^\\s*(insert into \\`?([^\\`]*)\\`?\\s+(values|\\())/i', $sql_line . $buffer, $matches)) {
             $sql_type = 3;
             $insert_prefix = $matches[1];
         }
         # Deal with case where adding this line will take us over the MySQL max_allowed_packet limit - must split, if we can (if it looks like consecutive rows)
         # ALlow a 100-byte margin for error (including searching/replacing table prefix)
         if (3 == $sql_type && $sql_line && strlen($sql_line . $buffer) > $this->max_allowed_packet - 100 && preg_match('/,\\s*$/', $sql_line) && preg_match('/^\\s*\\(/', $buffer)) {
             // Remove the final comma; replace with semi-colon
             $sql_line = substr(rtrim($sql_line), 0, strlen($sql_line) - 1) . ';';
             if ('' != $old_table_prefix && $import_table_prefix != $old_table_prefix) {
                 $sql_line = $updraftplus->str_replace_once($old_table_prefix, $import_table_prefix, $sql_line);
             }
             # Run the SQL command; then set up for the next one.
             $this->line++;
             echo __("Split line to avoid exceeding maximum packet size", 'updraftplus') . " (" . strlen($sql_line) . " + " . strlen($buffer) . " : " . $this->max_allowed_packet . ")<br>";
             $updraftplus->log("Split line to avoid exceeding maximum packet size (" . strlen($sql_line) . " + " . strlen($buffer) . " : " . $this->max_allowed_packet . ")");
             $do_exec = $this->sql_exec($sql_line, $sql_type, $import_table_prefix);
             if (is_wp_error($do_exec)) {
                 return $do_exec;
             }
             # Reset, then carry on
             $sql_line = $insert_prefix . " ";
         }
         $sql_line .= $buffer;
         # Do we have a complete line yet? We used to just test the final character for ';' here (up to 1.8.12), but that was too unsophisticated
         if (3 == $sql_type && !preg_match('/\\)\\s*;$/', substr($sql_line, -3, 3)) || 3 != $sql_type && ';' != substr($sql_line, -1, 1)) {
             continue;
         }
         $this->line++;
         # We now have a complete line - process it
         if (3 == $sql_type && $sql_line && strlen($sql_line) > $this->max_allowed_packet) {
             $this->log_oversized_packet($sql_line);
             # Reset
             $sql_line = '';
             $sql_type = -1;
             # If this is the very first SQL line of the options table, we need to bail; it's essential
             if (0 == $this->insert_statements_run && $restoring_table && $restoring_table == $import_table_prefix . 'options') {
                 $updraftplus->log("Leaving maintenance mode");
                 $this->maintenance_mode(false);
                 return new WP_Error('initial_db_error', sprintf(__('An error occurred on the first %s command - aborting run', 'updraftplus'), 'INSERT (options)'));
             }
             continue;
         }
         # The timed overhead of this is negligible
         if (preg_match('/^\\s*drop table if exists \\`?([^\\`]*)\\`?\\s*;/i', $sql_line, $matches)) {
             $sql_type = 1;
             if (!isset($printed_new_table_prefix)) {
                 $import_table_prefix = $this->pre_sql_actions($import_table_prefix);
                 if (false === $import_table_prefix || is_wp_error($import_table_prefix)) {
                     return $import_table_prefix;
                 }
                 $printed_new_table_prefix = true;
             }
             $this->table_name = $matches[1];
             // Legacy, less reliable - in case it was not caught before
             if ('' == $old_table_prefix && preg_match('/^([a-z0-9]+)_.*$/i', $this->table_name, $tmatches)) {
                 $old_table_prefix = $tmatches[1] . '_';
                 echo '<strong>' . __('Old table prefix:', 'updraftplus') . '</strong> ' . htmlspecialchars($old_table_prefix) . '<br>';
                 $updraftplus->log("Old table prefix (detected from first table): {$old_table_prefix}");
             }
             $this->new_table_name = $old_table_prefix ? $updraftplus->str_replace_once($old_table_prefix, $import_table_prefix, $this->table_name) : $this->table_name;
             if ('' != $old_table_prefix && $import_table_prefix != $old_table_prefix) {
                 $sql_line = $updraftplus->str_replace_once($old_table_prefix, $import_table_prefix, $sql_line);
             }
             $this->tables_been_dropped[] = $this->new_table_name;
         } elseif (preg_match('/^\\s*create table \\`?([^\\`\\(]*)\\`?\\s*\\(/i', $sql_line, $matches)) {
             $sql_type = 2;
             $this->insert_statements_run = 0;
             $this->table_name = $matches[1];
             // Legacy, less reliable - in case it was not caught before. We added it in here (CREATE) as well as in DROP because of SQL dumps which lack DROP statements.
             if ('' == $old_table_prefix && preg_match('/^([a-z0-9]+)_.*$/i', $this->table_name, $tmatches)) {
                 $old_table_prefix = $tmatches[1] . '_';
                 echo '<strong>' . __('Old table prefix:', 'updraftplus') . '</strong> ' . htmlspecialchars($old_table_prefix) . '<br>';
                 $updraftplus->log("Old table prefix (detected from creating first table): {$old_table_prefix}");
             }
             // MySQL 4.1 outputs TYPE=, but accepts ENGINE=; 5.1 onwards accept *only* ENGINE=
             $sql_line = $updraftplus->str_lreplace('TYPE=', 'ENGINE=', $sql_line);
             if (empty($printed_new_table_prefix)) {
                 $import_table_prefix = $this->pre_sql_actions($import_table_prefix);
                 if (false === $import_table_prefix || is_wp_error($import_table_prefix)) {
                     return $import_table_prefix;
                 }
                 $printed_new_table_prefix = true;
             }
             $this->new_table_name = $old_table_prefix ? $updraftplus->str_replace_once($old_table_prefix, $import_table_prefix, $this->table_name) : $this->table_name;
             // This CREATE TABLE command may be the de-facto mark for the end of processing a previous table (which is so if this is not the first table in the SQL dump)
             if ($restoring_table) {
                 # Attempt to reconnect if the DB connection dropped (may not succeed, of course - but that will soon become evident)
                 $updraftplus->check_db_connection($this->wpdb_obj);
                 // After restoring the options table, we can set old_siteurl if on legacy (i.e. not already set)
                 if ($restoring_table == $import_table_prefix . 'options') {
                     if ('' == $this->old_siteurl || '' == $this->old_home || '' == $this->old_content) {
                         global $updraftplus_addons_migrator;
                         if (isset($updraftplus_addons_migrator->new_blogid)) {
                             switch_to_blog($updraftplus_addons_migrator->new_blogid);
                         }
                         if ('' == $this->old_siteurl) {
                             $this->old_siteurl = untrailingslashit($wpdb->get_row("SELECT option_value FROM {$wpdb->options} WHERE option_name='siteurl'")->option_value);
                             do_action('updraftplus_restore_db_record_old_siteurl', $this->old_siteurl);
                         }
                         if ('' == $this->old_home) {
                             $this->old_home = untrailingslashit($wpdb->get_row("SELECT option_value FROM {$wpdb->options} WHERE option_name='home'")->option_value);
                             do_action('updraftplus_restore_db_record_old_home', $this->old_home);
                         }
                         if ('' == $this->old_content) {
                             $this->old_content = $this->old_siteurl . '/wp-content';
                             do_action('updraftplus_restore_db_record_old_content', $this->old_content);
                         }
                         if (isset($updraftplus_addons_migrator->new_blogid)) {
                             restore_current_blog();
                         }
                     }
                 }
                 if ($restoring_table != $this->new_table_name) {
                     $this->restored_table($restoring_table, $import_table_prefix, $old_table_prefix);
                 }
             }
             $engine = "(?)";
             $engine_change_message = '';
             if (preg_match('/ENGINE=([^\\s;]+)/', $sql_line, $eng_match)) {
                 $engine = $eng_match[1];
                 if (isset($supported_engines[$engine])) {
                     #echo sprintf(__('Requested table engine (%s) is present.', 'updraftplus'), $engine);
                     if ('myisam' == strtolower($engine)) {
                         $sql_line = preg_replace('/PAGE_CHECKSUM=\\d\\s?/', '', $sql_line, 1);
                     }
                 } else {
                     $engine_change_message = sprintf(__('Requested table engine (%s) is not present - changing to MyISAM.', 'updraftplus'), $engine) . "<br>";
                     $sql_line = $updraftplus->str_lreplace("ENGINE={$eng_match}", "ENGINE=MyISAM", $sql_line);
                     // Remove (M)aria options
                     if ('maria' == strtolower($engine) || 'aria' == strtolower($engine)) {
                         $sql_line = preg_replace('/PAGE_CHECKSUM=\\d\\s?/', '', $sql_line, 1);
                         $sql_line = preg_replace('/TRANSACTIONAL=\\d\\s?/', '', $sql_line, 1);
                     }
                 }
             }
             $this->table_name = $matches[1];
             echo '<strong>' . sprintf(__('Restoring table (%s)', 'updraftplus'), $engine) . ":</strong> " . htmlspecialchars($this->table_name);
             $logline = "Restoring table ({$engine}): " . $this->table_name;
             if ('' != $old_table_prefix && $import_table_prefix != $old_table_prefix) {
                 echo ' - ' . __('will restore as:', 'updraftplus') . ' ' . htmlspecialchars($this->new_table_name);
                 $logline .= " - will restore as: " . $this->new_table_name;
                 $sql_line = $updraftplus->str_replace_once($old_table_prefix, $import_table_prefix, $sql_line);
             }
             $updraftplus->log($logline);
             $restoring_table = $this->new_table_name;
             echo '<br>';
             if ($engine_change_message) {
                 echo $engine_change_message;
             }
         } elseif (preg_match('/^\\s*(insert into \\`?([^\\`]*)\\`?\\s+(values|\\())/i', $sql_line, $matches)) {
             $sql_type = 3;
             if ('' != $old_table_prefix && $import_table_prefix != $old_table_prefix) {
                 $sql_line = $updraftplus->str_replace_once($old_table_prefix, $import_table_prefix, $sql_line);
             }
         } elseif (preg_match('/^\\s*(\\/\\*\\!40000 )?(alter|lock) tables? \\`?([^\\`\\(]*)\\`?\\s+(write|disable|enable)/i', $sql_line, $matches)) {
             # Only binary mysqldump produces this pattern (LOCK TABLES `table` WRITE, ALTER TABLE `table` (DISABLE|ENABLE) KEYS)
             $sql_type = 4;
             if ('' != $old_table_prefix && $import_table_prefix != $old_table_prefix) {
                 $sql_line = $updraftplus->str_replace_once($old_table_prefix, $import_table_prefix, $sql_line);
             }
         } elseif (preg_match('/^(un)?lock tables/i', $sql_line)) {
             # BackWPup produces these
             $sql_type = 5;
         } elseif (preg_match('/^(create|drop) database /i', $sql_line)) {
             # WPB2D produces these, as do some phpMyAdmin dumps
             $sql_type = 6;
         } elseif (preg_match('/^use /i', $sql_line)) {
             # WPB2D produces these, as do some phpMyAdmin dumps
             $sql_type = 7;
         } elseif (preg_match('#/\\*\\!40\\d+ SET NAMES (\\S+)#', $sql_line, $smatches)) {
             $sql_type = 8;
             $this->set_names = $smatches[1];
         } else {
             # Prevent the previous value of $sql_type being retained for an unknown type
             $sql_type = 0;
         }
         // 			if (5 !== $sql_type) {
         if ($sql_type != 6 && $sql_type != 7) {
             $do_exec = $this->sql_exec($sql_line, $sql_type);
             if (is_wp_error($do_exec)) {
                 return $do_exec;
             }
         } else {
             $updraftplus->log("Skipped SQL statement (unwanted type={$sql_type}): {$sql_line}");
         }
         # Reset
         $sql_line = '';
         $sql_type = -1;
     }
     $updraftplus->log("Leaving maintenance mode");
     $this->maintenance_mode(false);
     if ($restoring_table) {
         $this->restored_table($restoring_table, $import_table_prefix, $old_table_prefix);
     }
     $time_taken = microtime(true) - $this->start_time;
     $updraftplus->log_e('Finished: lines processed: %d in %.2f seconds', $this->line, $time_taken);
     if ($is_plain) {
         fclose($dbhandle);
     } elseif ($is_bz2) {
         bzclose($dbhandle);
     } else {
         gzclose($dbhandle);
     }
     global $wp_filesystem;
     $wp_filesystem->delete($working_dir . '/' . $db_basename, false, 'f');
     return true;
 }
Esempio n. 24
0
 function create_bzip()
 {
     if ($this->options['inmemory'] == 0) {
         $Pwd = getcwd();
         chdir($this->options['basedir']);
         if ($fp = bzopen($this->options['name'], "wb")) {
             fseek($this->archive, 0);
             while ($temp = fread($this->archive, 1048576)) {
                 bzwrite($fp, $temp);
             }
             bzclose($fp);
             chdir($Pwd);
         } else {
             $this->error[] = "Could not open {$this->options['name']} for writing.";
             chdir($Pwd);
             return 0;
         }
     } else {
         $this->archive = bzcompress($this->archive, $this->options['level']);
     }
     return 1;
 }
Esempio n. 25
0
 /**
  * Actually write the tmp file to the inner writer
  * Close and delete temporary file
  *
  * @see File_Archive_Writer::close()
  */
 function close()
 {
     bzclose($this->bzfile);
     if ($this->filename === null) {
         //Assume innerWriter is already opened on a file...
         $this->innerWriter->writeFile($this->tmpName);
         unlink($this->tmpName);
     } else {
         $this->innerWriter->newFromTempFile($this->tmpName, $this->filename, $this->stat, 'application/x-compressed');
     }
     if ($this->autoClose) {
         return $this->innerWriter->close();
     }
 }
Esempio n. 26
0
 public function close()
 {
     return bzclose($this->fileHandler);
 }
Esempio n. 27
0
 function fn_close($fp)
 {
     if ($this->SET['comp_method'] == 2) {
         bzclose($fp);
     } elseif ($this->SET['comp_method'] == 1) {
         gzclose($fp);
     } else {
         fclose($fp);
     }
     @chmod(PATH . $this->filename, 0666);
     $this->fn_index();
 }
             if ($objval != "") {
                 $finalfile .= "{$objid}: {$objval}\n";
             }
             if ($y == $numberofkeys) {
                 // last
                 $finalfile .= "\n\n";
             }
         }
     }
 }
 file_put_contents("Packages", $finalfile);
 chmod("Packages", 0777);
 $fileconent = file_get_contents("Packages");
 $bz = bzopen("Packages.bz2", "w");
 bzwrite($bz, $fileconent);
 bzclose($bz);
 chmod("Packages.bz2", 0777);
 //////
 $request = $_GET["request"];
 $extension = pathinfo($request, PATHINFO_EXTENSION);
 if ($extension) {
     $mimemap = array("bz2" => "application/bzip2", "gz" => "application/x-gzip", "xz" => "application/x-xz", "lzma" => "application/x-lzma", "lz" => "application/x-lzip");
     header(sprintf("Content-Type: %s", $mimemap[$extension]));
     header(sprintf("Content-Disposition: attachment; filename=\"%s\"", $request));
 }
 $docroot = $_SERVER['DOCUMENT_ROOT'] . $CurrentDirectoryFolder;
 if ($request == $docroot . "Packages" || $request == $docroot . "Release" || $request == $docroot . "Packages.bz2" || $request == $docroot . "Packages.gz" || $request == $docroot . "en_US.bz2" || $request == $docroot . "en_US.gz") {
     echo readfile($request);
 } else {
     header("HTTP/1.0 403 Forbidden: Someone's sneaky.");
 }
Esempio n. 29
0
                } else {
                    fwrite($fp, $thistableinserts . LINE_TERMINATOR . LINE_TERMINATOR, strlen($thistableinserts) + strlen(LINE_TERMINATOR) + strlen(LINE_TERMINATOR));
                }
            }
        }
    }
    $activateForeignKeys = 'SET FOREIGN_KEY_CHECKS=1;' . LINE_TERMINATOR . LINE_TERMINATOR;
    if (OUTPUT_COMPRESSION_TYPE == 'bzip2') {
        bzwrite($bp, $activateForeignKeys, strlen($activateForeignKeys));
    } elseif (OUTPUT_COMPRESSION_TYPE == 'gzip') {
        gzwrite($zp, $activateForeignKeys, strlen($activateForeignKeys));
    } else {
        fwrite($fp, $activateForeignKeys, strlen($activateForeignKeys));
    }
    if (OUTPUT_COMPRESSION_TYPE == 'bzip2') {
        bzclose($bp);
    } elseif (OUTPUT_COMPRESSION_TYPE == 'gzip') {
        gzclose($zp);
    } else {
        fclose($fp);
    }
    if (file_exists($newfullfilename)) {
        unlink($newfullfilename);
        // Windows won't allow overwriting via rename
    }
    rename($backupabsolutepath . $tempbackupfilename, $newfullfilename);
} else {
    echo '<b>Warning:</b> failed to open ' . $backupabsolutepath . $tempbackupfilename . ' for writing!<br><br>';
    if (is_dir($backupabsolutepath)) {
        echo '<i>CHMOD 777</i> on the directory (' . htmlentities($backupabsolutepath) . ') should fix that.';
    } else {
Esempio n. 30
0
             sql1();
             break;
     }
     if ($_POST['save'] == 1) {
         switch ($_POST['compr']) {
             case 0:
                 $n = '.txt';
                 fclose($fp);
                 break;
             case 1:
                 $n = '.gz';
                 gzclose($fp);
                 break;
             case 2:
                 $n = '.bz2';
                 bzclose($fp);
                 break;
         }
         head($tmpfname, $_POST['table_sel'] . $n);
     }
     break;
 case 1:
     $res = mysql_query("SELECT * FROM `" . $_POST['table_sel'] . "`", $connect);
     if (mysql_num_rows($res) > 0) {
         while ($row = mysql_fetch_assoc($res)) {
             $values = array_values($row);
             foreach ($values as $k => $v) {
                 $values[$k] = addslashes($v);
             }
             $values = implode($_POST['cvs_term'], $values);
             write($values);