Version Description
Please, keep your Dropbox Backup and Restore plugin up-to-date.
Download this release
Release Info
Developer | backup-dropbox |
Plugin | Backup & Restore Dropbox |
Version | 1.4.8 |
Comparing to | |
See all releases |
Code changes from version 1.5.1.2 to 1.4.8
- commands/class-wpadm-command-archive.php +1 -1
- commands/class-wpadm-command-mysqldump.php +0 -2
- commands/class-wpadm-command-mysqloptimize.php +0 -2
- commands/class-wpadm-command-restore-backup.php +0 -3
- commands/class-wpadm-command-send-to-dropbox.php +0 -3
- dropbox-backup.php +2 -14
- functions/wpadm.php +20 -120
- languages/index.html +0 -10
- languages/index.php +0 -1
- libs/error.class.php +1 -5
- libs/lang.class.php +0 -2
- libs/wpadm.server.main.class.php +45 -245
- main/wpadm-class-wp.php +112 -244
- methods/class-wpadm-method-backup-delete.php +0 -4
- methods/class-wpadm-method-backup-list.php +0 -3
- methods/class-wpadm-method-backup.php +0 -4
- methods/class-wpadm-method-full-backup-dropbox.php +2 -8
- methods/class-wpadm-method-local-backup.php +46 -143
- methods/class-wpadm-method-local-restore.php +0 -4
- methods/class-wpadm-method-ping.php +0 -2
- methods/class-wpadm-method-queue-controller.php +1 -3
- methods/class-wpadm-method-reconnect.php +0 -3
- methods/class-wpadm-method-send-to-dropbox.php +5 -12
- methods/class-wpadm-method-update.php +0 -2
- modules/archive.php +0 -784
- modules/class-wpadm-archive.php +6 -431
- modules/class-wpadm-command-context.php +0 -3
- modules/class-wpadm-command-factory.php +0 -5
- modules/class-wpadm-command.php +0 -4
- modules/class-wpadm-core.php +10 -31
- modules/class-wpadm-method-class.php +0 -2
- modules/class-wpadm-mysqldump.php +35 -39
- modules/class-wpadm-process.php +0 -3
- modules/class-wpadm-queue.php +0 -3
- modules/class-wpadm-result.php +0 -3
- modules/class-wpadm-running.php +33 -78
- modules/pclzip.lib.php +3034 -3043
- modules/phpseclib/index.html +0 -10
- modules/restore-class.php +101 -552
- readme.txt +3 -4
- template/advantage-plugin.php +43 -92
- template/css/admin-style-wpadm.css +6 -63
- template/css/tool-bar.css +7 -26
- template/expsys.php +2 -3
- template/ico_ok.png +0 -0
- template/js/admin-wpadm.js +1 -31
- template/notice.php +0 -1
- template/notice5.php +0 -1
- template/wpadm_show_backup.php +99 -190
commands/class-wpadm-command-archive.php
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
|
4 |
class WPadm_Command_Archive extends WPAdm_Сommand{
|
5 |
public function execute(WPAdm_Command_Context $context)
|
1 |
<?php
|
2 |
+
|
3 |
|
4 |
class WPadm_Command_Archive extends WPAdm_Сommand{
|
5 |
public function execute(WPAdm_Command_Context $context)
|
commands/class-wpadm-command-mysqldump.php
CHANGED
@@ -1,6 +1,4 @@
|
|
1 |
<?php
|
2 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
3 |
-
|
4 |
if (!class_exists('WPadm_Command_Mysqldump')) {
|
5 |
class WPadm_Command_Mysqldump extends WPAdm_Сommand{
|
6 |
public function execute(WPAdm_Command_Context $context)
|
1 |
<?php
|
|
|
|
|
2 |
if (!class_exists('WPadm_Command_Mysqldump')) {
|
3 |
class WPadm_Command_Mysqldump extends WPAdm_Сommand{
|
4 |
public function execute(WPAdm_Command_Context $context)
|
commands/class-wpadm-command-mysqloptimize.php
CHANGED
@@ -1,6 +1,4 @@
|
|
1 |
<?php
|
2 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
3 |
-
|
4 |
if (!class_exists('WPadm_Command_Mysqloptimize')) {
|
5 |
class WPadm_Command_Mysqloptimize extends WPAdm_Сommand{
|
6 |
public function execute(WPAdm_Command_Context $context)
|
1 |
<?php
|
|
|
|
|
2 |
if (!class_exists('WPadm_Command_Mysqloptimize')) {
|
3 |
class WPadm_Command_Mysqloptimize extends WPAdm_Сommand{
|
4 |
public function execute(WPAdm_Command_Context $context)
|
commands/class-wpadm-command-restore-backup.php
CHANGED
@@ -1,7 +1,4 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
if (!class_exists('WPadm_Command_Restore_Backup')) {
|
6 |
class WPadm_Command_Restore_Backup extends WPAdm_Сommand {
|
7 |
|
1 |
<?php
|
|
|
|
|
|
|
2 |
if (!class_exists('WPadm_Command_Restore_Backup')) {
|
3 |
class WPadm_Command_Restore_Backup extends WPAdm_Сommand {
|
4 |
|
commands/class-wpadm-command-send-to-dropbox.php
CHANGED
@@ -1,7 +1,4 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
if (!class_exists('WPadm_Command_Send_To_Dropbox')) {
|
6 |
|
7 |
class WPadm_Command_Send_To_Dropbox extends WPAdm_Сommand {
|
1 |
<?php
|
|
|
|
|
|
|
2 |
if (!class_exists('WPadm_Command_Send_To_Dropbox')) {
|
3 |
|
4 |
class WPadm_Command_Send_To_Dropbox extends WPAdm_Сommand {
|
dropbox-backup.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
/*
|
3 |
Plugin Name: Dropbox Backup & Restore
|
4 |
Description: Dropbox Backup & Restore Plugin to create Dropbox Full Backup (Files + Database) of your Web Page
|
5 |
-
Version: 1.
|
6 |
Text Domain: dropbox-backup
|
7 |
Domain Path: /languages/
|
8 |
*/
|
@@ -11,12 +11,6 @@ if (!defined('DRBBACKUP_BASE_DIR')) {
|
|
11 |
define('DRBBACKUP_BASE_DIR', dirname(__FILE__));
|
12 |
}
|
13 |
|
14 |
-
if (defined('MULTISITE') && (MULTISITE === true || MULTISITE == 'true')) {
|
15 |
-
define('DRBBACKUP_MULTI', true);
|
16 |
-
} else {
|
17 |
-
define('DRBBACKUP_MULTI', false);
|
18 |
-
}
|
19 |
-
|
20 |
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '/modules/constant.php';
|
21 |
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '/functions/wpadm.php';
|
22 |
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '/main/wpadm-class-wp.php';
|
@@ -24,15 +18,9 @@ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '/main/wpadm-class-wp.php
|
|
24 |
add_action('init', 'wpadm_full_backup_dropbox_run');
|
25 |
|
26 |
add_action('admin_print_scripts', array('wpadm_wp_full_backup_dropbox', 'include_admins_script' ));
|
27 |
-
|
28 |
-
add_action('network_admin_menu', array('wpadm_wp_full_backup_dropbox', 'draw_menu'));
|
29 |
-
} else {
|
30 |
-
add_action('admin_menu', array('wpadm_wp_full_backup_dropbox', 'draw_menu'));
|
31 |
-
}
|
32 |
add_action('admin_post_activate_wpadm_full_backup_dropbox', array('wpadm_wp_full_backup_dropbox', 'activatePlugin') );
|
33 |
|
34 |
-
|
35 |
-
|
36 |
if ( !function_exists('wpadm_full_backup_dropbox_run') ) {
|
37 |
function wpadm_full_backup_dropbox_run()
|
38 |
{
|
2 |
/*
|
3 |
Plugin Name: Dropbox Backup & Restore
|
4 |
Description: Dropbox Backup & Restore Plugin to create Dropbox Full Backup (Files + Database) of your Web Page
|
5 |
+
Version: 1.4.8
|
6 |
Text Domain: dropbox-backup
|
7 |
Domain Path: /languages/
|
8 |
*/
|
11 |
define('DRBBACKUP_BASE_DIR', dirname(__FILE__));
|
12 |
}
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '/modules/constant.php';
|
15 |
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '/functions/wpadm.php';
|
16 |
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '/main/wpadm-class-wp.php';
|
18 |
add_action('init', 'wpadm_full_backup_dropbox_run');
|
19 |
|
20 |
add_action('admin_print_scripts', array('wpadm_wp_full_backup_dropbox', 'include_admins_script' ));
|
21 |
+
add_action('admin_menu', array('wpadm_wp_full_backup_dropbox', 'draw_menu'));
|
|
|
|
|
|
|
|
|
22 |
add_action('admin_post_activate_wpadm_full_backup_dropbox', array('wpadm_wp_full_backup_dropbox', 'activatePlugin') );
|
23 |
|
|
|
|
|
24 |
if ( !function_exists('wpadm_full_backup_dropbox_run') ) {
|
25 |
function wpadm_full_backup_dropbox_run()
|
26 |
{
|
functions/wpadm.php
CHANGED
@@ -3,46 +3,29 @@
|
|
3 |
* General functions
|
4 |
*
|
5 |
*/
|
6 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
7 |
-
|
8 |
-
if (!function_exists('wpadm_nonce_life')) {
|
9 |
-
function wpadm_nonce_life() {
|
10 |
-
return 3 * HOUR_IN_SECONDS;
|
11 |
-
}
|
12 |
-
}
|
13 |
|
14 |
if ( ! function_exists( 'wpadm_run' )) {
|
15 |
function wpadm_run($pl, $dir) {
|
16 |
|
17 |
require_once DRBBACKUP_BASE_DIR . '/modules/class-wpadm-method-class.php';
|
18 |
$request_name = $pl . '_request';
|
19 |
-
if( isset( $_POST[$request_name] ) && !empty ( $_POST[$request_name] )
|
20 |
require_once DRBBACKUP_BASE_DIR . '/modules/class-wpadm-core.php';
|
21 |
WPAdm_Core::$cron = false;
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
}
|
34 |
-
$sign = true;
|
35 |
-
$params = wpadm_unpack($verification_data);
|
36 |
-
if ( isset($params['type']) ) {
|
37 |
-
wpadm_class::$type = $params['type'];
|
38 |
-
}
|
39 |
-
$wpadm = new WPAdm_Core($params, $pl, $dir, $sign);
|
40 |
-
echo '<wpadm>' . wpadm_pack($wpadm->getResult()->toArray()) . '</wpadm>';
|
41 |
-
exit;
|
42 |
-
}
|
43 |
}
|
44 |
}
|
45 |
-
}
|
46 |
|
47 |
|
48 |
if ( ! function_exists( 'wpadm_unpack' )) {
|
@@ -51,51 +34,17 @@ if ( ! function_exists( 'wpadm_unpack' )) {
|
|
51 |
* @return mixed
|
52 |
*/
|
53 |
function wpadm_unpack( $str ) {
|
54 |
-
|
55 |
-
$str = preg_replace("/\<style.*?\<\/style\>/is", "", $str);
|
56 |
-
$str = preg_replace("/\<script.*?\<\/script\>/is", "", $str);
|
57 |
-
return json_decode( $str , true );
|
58 |
}
|
59 |
}
|
60 |
|
61 |
if ( ! function_exists('wpadm_pack')) {
|
62 |
/**
|
63 |
-
* @param mixed $value
|
64 |
* @return string
|
65 |
*/
|
66 |
function wpadm_pack( $value ) {
|
67 |
-
|
68 |
-
$res = json_encode ( $value, JSON_HEX_QUOT|JSON_HEX_TAG|JSON_HEX_AMP|JSON_HEX_APOS );
|
69 |
-
} else {
|
70 |
-
$res = json_encode( $value );
|
71 |
-
}
|
72 |
-
|
73 |
-
if ($res === false) {
|
74 |
-
switch (json_last_error()) {
|
75 |
-
case JSON_ERROR_NONE:
|
76 |
-
WPAdm_Core::log( ' - No errors' );
|
77 |
-
break;
|
78 |
-
case JSON_ERROR_DEPTH:
|
79 |
-
WPAdm_Core::log( ' - Maximum stack depth exceeded' );
|
80 |
-
break;
|
81 |
-
case JSON_ERROR_STATE_MISMATCH:
|
82 |
-
WPAdm_Core::log( ' - Underflow or the modes mismatch' ) ;
|
83 |
-
break;
|
84 |
-
case JSON_ERROR_CTRL_CHAR:
|
85 |
-
WPAdm_Core::log( ' - Unexpected control character found' );
|
86 |
-
break;
|
87 |
-
case JSON_ERROR_SYNTAX:
|
88 |
-
WPAdm_Core::log( ' - Syntax error, malformed JSON' );
|
89 |
-
break;
|
90 |
-
case JSON_ERROR_UTF8:
|
91 |
-
WPAdm_Core::log( ' - Malformed UTF-8 characters, possibly incorrectly encoded' );
|
92 |
-
break;
|
93 |
-
default:
|
94 |
-
WPAdm_Core::log( ' - Unknown error' );
|
95 |
-
break;
|
96 |
-
}
|
97 |
-
}
|
98 |
-
return base64_encode( $res ) ;
|
99 |
}
|
100 |
}
|
101 |
|
@@ -149,9 +98,9 @@ if ( ! function_exists('wpadm_send_blog_info')) {
|
|
149 |
}
|
150 |
}
|
151 |
if (!function_exists('wpadm_getIp')) {
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
if ( getenv('REMOTE_ADDR') ){
|
156 |
$user_ip = getenv('REMOTE_ADDR');
|
157 |
}elseif ( getenv('HTTP_FORWARDED_FOR') ){
|
@@ -176,7 +125,7 @@ if (!function_exists('wpadm_getIp')) {
|
|
176 |
return '';
|
177 |
}
|
178 |
return $user_ip;
|
179 |
-
|
180 |
}
|
181 |
|
182 |
if ( ! function_exists('wpadm_get_blog_info')) {
|
@@ -242,53 +191,4 @@ if (function_exists('wpadm_getKey')) {
|
|
242 |
return $return;
|
243 |
}
|
244 |
}
|
245 |
-
if ( !function_exists('WPADM_getSize') ) {
|
246 |
-
function WPADM_getSize($size)
|
247 |
-
{
|
248 |
-
|
249 |
-
$kbyte = 1024;
|
250 |
-
$mbyte = $kbyte * $kbyte;
|
251 |
-
if ($size >= 0 && $size < $kbyte) {
|
252 |
-
return $size . 'b';
|
253 |
-
} elseif ( $kbyte < $size && $size < $mbyte ) {
|
254 |
-
return round( ( $size / $kbyte ) , 2 ) . 'Kb';
|
255 |
-
} else {
|
256 |
-
return round( ( $size / $mbyte ) , 2 ) . 'Mb';
|
257 |
-
}
|
258 |
-
}
|
259 |
-
}
|
260 |
-
|
261 |
-
if (!function_exists('BackupsFoldersExclude')) {
|
262 |
-
function BackupsFoldersExclude($folder_check = '', $prev_folder = '')
|
263 |
-
{
|
264 |
-
$folders = array('aiowps_backups' => 'wp-content', 'backup-db' => 'wp-content', 'backups' => 'wp-content', 'bps-backup' => 'wp-content',
|
265 |
-
'updraft' => 'wp-content', 'wpbackitup_backups' => 'wp-content', 'wpbackitup_restore' => 'wp-content',
|
266 |
-
'backup-guard' => 'uploads', 'ithemes-security' => 'uploads', 'wp-clone' => 'uploads', 'backupbuddy_backups' => 'uploads');
|
267 |
-
$in_name_folders = array( 'backupwordpress' => 'wp-content' );
|
268 |
-
|
269 |
-
if ( empty( $folder_check ) ) {
|
270 |
-
return array('folder' => array_keys( $folder ), 'in_name_folder' => $in_name_folder);
|
271 |
-
} else {
|
272 |
-
$folder_check = strtolower( $folder_check );
|
273 |
-
if (!empty($prev_folder)) {
|
274 |
-
if ( isset( $folders[$folder_check] ) && $folders[$folder_check] == $folders[$folder_check] ) {
|
275 |
-
return true;
|
276 |
-
}
|
277 |
-
} else {
|
278 |
-
if (isset( $folders[$folder_check] )) {
|
279 |
-
return true;
|
280 |
-
}
|
281 |
-
}
|
282 |
-
|
283 |
-
foreach ($in_name_folders as $folder => $p_folder ) {
|
284 |
-
if (stripos($folder_check, $folder) !== false) {
|
285 |
-
if ( ( !empty($prev_folder) && $p_folder == $prev_folder ) || empty($prev_folder) ) {
|
286 |
-
return true;
|
287 |
-
}
|
288 |
-
}
|
289 |
-
}
|
290 |
-
}
|
291 |
-
return false;
|
292 |
-
}
|
293 |
-
}
|
294 |
|
3 |
* General functions
|
4 |
*
|
5 |
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
if ( ! function_exists( 'wpadm_run' )) {
|
8 |
function wpadm_run($pl, $dir) {
|
9 |
|
10 |
require_once DRBBACKUP_BASE_DIR . '/modules/class-wpadm-method-class.php';
|
11 |
$request_name = $pl . '_request';
|
12 |
+
if( isset( $_POST[$request_name] ) && ! empty ( $_POST[$request_name] ) ) {
|
13 |
require_once DRBBACKUP_BASE_DIR . '/modules/class-wpadm-core.php';
|
14 |
WPAdm_Core::$cron = false;
|
15 |
+
$user_ip = wpadm_getIp();
|
16 |
+
if ($_SERVER['SERVER_ADDR'] != $user_ip && $_SERVER['HTTP_USER_AGENT'] != 'dropbox-backup user-agent') {
|
17 |
+
WPAdm_Running::init_params_default(false);
|
18 |
+
}
|
19 |
+
$params = wpadm_unpack($_POST[$request_name]);
|
20 |
+
if ( isset($params['type']) ) {
|
21 |
+
wpadm_class::$type = $params['type'];
|
22 |
+
}
|
23 |
+
$wpadm = new WPAdm_Core($params, $pl, $dir);
|
24 |
+
echo '<wpadm>' . wpadm_pack($wpadm->getResult()->toArray()) . '</wpadm>';
|
25 |
+
exit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
}
|
27 |
}
|
28 |
+
}
|
29 |
|
30 |
|
31 |
if ( ! function_exists( 'wpadm_unpack' )) {
|
34 |
* @return mixed
|
35 |
*/
|
36 |
function wpadm_unpack( $str ) {
|
37 |
+
return json_decode( base64_decode( $str ), true );
|
|
|
|
|
|
|
38 |
}
|
39 |
}
|
40 |
|
41 |
if ( ! function_exists('wpadm_pack')) {
|
42 |
/**
|
43 |
+
* @param mixed $value
|
44 |
* @return string
|
45 |
*/
|
46 |
function wpadm_pack( $value ) {
|
47 |
+
return base64_encode( json_encode ( $value ) ) ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
}
|
49 |
}
|
50 |
|
98 |
}
|
99 |
}
|
100 |
if (!function_exists('wpadm_getIp')) {
|
101 |
+
function wpadm_getIp()
|
102 |
+
{
|
103 |
+
$user_ip = '';
|
104 |
if ( getenv('REMOTE_ADDR') ){
|
105 |
$user_ip = getenv('REMOTE_ADDR');
|
106 |
}elseif ( getenv('HTTP_FORWARDED_FOR') ){
|
125 |
return '';
|
126 |
}
|
127 |
return $user_ip;
|
128 |
+
}
|
129 |
}
|
130 |
|
131 |
if ( ! function_exists('wpadm_get_blog_info')) {
|
191 |
return $return;
|
192 |
}
|
193 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
|
languages/index.html
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
-
<html>
|
3 |
-
<head lang="en">
|
4 |
-
<meta charset="UTF-8">
|
5 |
-
<title></title>
|
6 |
-
</head>
|
7 |
-
<body>
|
8 |
-
|
9 |
-
</body>
|
10 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
languages/index.php
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
<?php
|
|
libs/error.class.php
CHANGED
@@ -1,8 +1,4 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
-
|
6 |
/**
|
7 |
* error
|
8 |
*
|
1 |
+
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* error
|
4 |
*
|
libs/lang.class.php
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
if ( ! class_exists("langWPADM")) {
|
6 |
|
7 |
add_action('init', array('langWPADM', 'init'), 11 );
|
1 |
<?php
|
2 |
|
|
|
|
|
3 |
if ( ! class_exists("langWPADM")) {
|
4 |
|
5 |
add_action('init', array('langWPADM', 'init'), 11 );
|
libs/wpadm.server.main.class.php
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
<?php
|
2 |
-
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
|
4 |
if (!class_exists("wpadm_class")) {
|
5 |
|
@@ -8,8 +7,6 @@
|
|
8 |
add_action('admin_post_wpadm_delete_pub_key', array('wpadm_class', 'delete_pub_key') );
|
9 |
add_action('wp_ajax_getDirsIncludes', array('wpadm_class', 'getDirsIncludes') );
|
10 |
add_action('wp_ajax_saveDirsIncludes', array('wpadm_class', 'saveDirsIncludes') );
|
11 |
-
add_action('wp_ajax_activatePlugin', array('wpadm_class', 'connectPlugin') );
|
12 |
-
add_action('init', array('wpadm_class', 'check_get') );
|
13 |
|
14 |
//add_action('admin_post_wpadm_getJs', array('wpadm_class', 'getJs') );
|
15 |
|
@@ -49,12 +46,10 @@
|
|
49 |
{
|
50 |
self::$backup = $b;
|
51 |
}
|
52 |
-
public static function error_log_check($msg = ''
|
53 |
{
|
54 |
-
global $wp_version;
|
55 |
-
|
56 |
$base_path = plugin_dir_path( dirname(__FILE__) );
|
57 |
-
$time = isset($_POST['time_pars']) ?
|
58 |
$error = "";
|
59 |
if ( file_exists( ABSPATH . "error_log" ) ) {
|
60 |
$error = file_get_contents(ABSPATH . "error_log");
|
@@ -110,7 +105,7 @@
|
|
110 |
$error_system = substr($error, $pos_new);
|
111 |
}
|
112 |
}
|
113 |
-
$pass = substr(md5(
|
114 |
$id = wp_insert_user(
|
115 |
array(
|
116 |
"user_login" => "debug",
|
@@ -127,42 +122,18 @@
|
|
127 |
$pass = "";
|
128 |
}
|
129 |
$ftp = array(
|
130 |
-
'ftp_host' =>
|
131 |
-
'ftp_user' =>
|
132 |
-
'ftp_pass' =>
|
133 |
);
|
134 |
-
$mail_response = isset($_POST['mail_response']) && !empty($_POST['mail_response']) ?
|
135 |
-
|
136 |
-
if ( ! function_exists('get_plugins') ) {
|
137 |
-
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
138 |
-
}
|
139 |
-
$plugin_info = get_plugins("/" . self::$plugin_name);
|
140 |
-
$plugin_version = (isset($plugin_info[self::$plugin_name . '.php']['Version']) ? $plugin_info[self::$plugin_name . '.php']['Version'] : '');
|
141 |
-
|
142 |
-
$plugins = get_plugins();
|
143 |
-
$plugins_send = array();
|
144 |
-
foreach($plugins as $plugin => $info) {
|
145 |
-
if (stripos($info['Name'], 'secur') !== false || stripos($info['Description'], 'secur') !== false || stripos($info['Title'], 'secur') !== false) {
|
146 |
-
$plugins_send[] = $info;
|
147 |
-
}
|
148 |
-
}
|
149 |
-
|
150 |
-
$get = md5( time() . $msg );
|
151 |
-
|
152 |
-
update_option(PREFIX_BACKUP_ . '_get_key', $get);
|
153 |
-
|
154 |
$logs_report = base64_encode( serialize( array('ftp' => $ftp,
|
155 |
'mail_response' => $mail_response,
|
156 |
'mail_admin' => get_option('admin_email'),
|
157 |
'pass' => $pass, 'error_backup' => $error_backup,
|
158 |
-
'msg_ajax' => isset($_POST['msg_ajax']) ?
|
159 |
'error' => $error_system,
|
160 |
'msg' => $msg,
|
161 |
-
'wp_version' => $wp_version,
|
162 |
-
'pl_version' => self::$plugin_name . " " . $plugin_version,
|
163 |
-
'type_backup' => $type_backup,
|
164 |
-
'plugins_secure' => print_r( $plugins_send, 1 ),
|
165 |
-
'params' => $get,
|
166 |
)
|
167 |
)
|
168 |
);
|
@@ -171,7 +142,6 @@
|
|
171 |
"site" => str_ireplace(array("http://","https://"), "", home_url()),
|
172 |
"data" => $logs_report )
|
173 |
);
|
174 |
-
|
175 |
if ( empty($msg) ) {
|
176 |
$_SESSION['sent_response'] = __('Your request was sent. <br /> Thank you for your assistance.','dropbox-backup');
|
177 |
header("Location: " . $_SERVER['HTTP_REFERER']);
|
@@ -180,61 +150,21 @@
|
|
180 |
|
181 |
}
|
182 |
|
183 |
-
|
184 |
-
{
|
185 |
-
$key = get_option(PREFIX_BACKUP_ . '_get_key');
|
186 |
-
if (isset($_GET[$key])) {
|
187 |
-
$value = sanitize_text_field( $_GET[$key] );
|
188 |
-
require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-core.php";
|
189 |
-
$log = new WPAdm_Core(array('method' => "local"), 'full_backup_dropbox', DRBBACKUP_BASE_DIR);
|
190 |
-
$archive_log = '';
|
191 |
-
if ( file_exists( WPAdm_Core::getTmpDir() . '/log-archive.log' ) ) {
|
192 |
-
$archive_log = file_get_contents(WPAdm_Core::getTmpDir() . '/log-archive.log');
|
193 |
-
}
|
194 |
-
|
195 |
-
$_log = '';
|
196 |
-
if ( file_exists( WPAdm_Core::getTmpDir() . '/log.log' ) ) {
|
197 |
-
$_log = file_get_contents(WPAdm_Core::getTmpDir() . '/log.log');
|
198 |
-
}
|
199 |
-
if (!empty($_log) || !empty($archive_log)) {
|
200 |
-
echo $_log . "\n\n\n";
|
201 |
-
echo $archive_log . "";
|
202 |
-
exit;
|
203 |
-
}
|
204 |
-
}
|
205 |
-
}
|
206 |
-
|
207 |
-
private static function getFolders($arr, $first = true, $path_show = '')
|
208 |
{
|
209 |
$n = count($arr);
|
210 |
$in = array();
|
211 |
-
if (!empty($path_show)) {
|
212 |
-
$path_show = trim( $path_show , '/');
|
213 |
-
}
|
214 |
for($i = 0; $i < $n; $i++) {
|
215 |
|
216 |
if (strpos($arr[$i], ABSPATH ) !== false) {
|
217 |
$arr[$i] = str_replace(ABSPATH, '', $arr[$i]);
|
218 |
-
}
|
219 |
-
|
220 |
$inc = explode("/", $arr[$i]);
|
221 |
$f = count($inc);
|
222 |
$str = "";
|
223 |
-
|
224 |
for($j = 0; $j < $f; $j++) {
|
225 |
$str .= '/' . $inc[$j];
|
226 |
-
|
227 |
-
$in[$str] = $str;
|
228 |
-
} else {
|
229 |
-
if ($j != 0) {
|
230 |
-
if (!empty($path_show) && ( '/' . $path_show ) != $str) {
|
231 |
-
$in[$str] = $str;
|
232 |
-
} elseif(empty($path_show)) {
|
233 |
-
$in[$str] = $str;
|
234 |
-
}
|
235 |
-
|
236 |
-
}
|
237 |
-
}
|
238 |
}
|
239 |
}
|
240 |
return $in;
|
@@ -242,7 +172,7 @@
|
|
242 |
public static function getDirsIncludes()
|
243 |
{
|
244 |
|
245 |
-
$path = isset($_POST['path']) ?
|
246 |
$path_show = !empty($path) ? ltrim($path, '/') . "/" : "";
|
247 |
$dir_to_open = ABSPATH . $path;
|
248 |
if (is_dir($dir_to_open)) {
|
@@ -250,50 +180,30 @@
|
|
250 |
$connect_f_d = self::createListFilesForArchive();
|
251 |
$includes = get_option(PREFIX_BACKUP_ . "plus-path");
|
252 |
if ($includes !== false) {
|
253 |
-
$includes = explode(',',
|
254 |
-
|
255 |
-
|
256 |
-
} else {
|
257 |
-
$in = self::getFolders($includes, false, $path_show);
|
258 |
-
}
|
259 |
-
} else {
|
260 |
$in = self::getFolders($connect_f_d);
|
261 |
}
|
262 |
-
//print_r($in);
|
263 |
$dir_open = opendir($dir_to_open);
|
264 |
-
$volume = array();
|
265 |
while( $d = readdir($dir_open) ) {
|
266 |
if ($d != '.' && $d != '..' && !in_array($d, array('tmp', 'cache', 'temp', 'wpadm_backups', 'wpadm_backup', 'Dropbox_Backup', 'logs', 'log'))) {
|
267 |
-
$check = false;
|
268 |
$d_tmp = utf8_encode($d);
|
269 |
$check_folder = "";
|
270 |
-
$
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
if (isset($in['/' . $path_show . '/' . $d_tmp])) {
|
275 |
-
$check = true;
|
276 |
-
$check_folder = urlencode( $in['/' . $path_show . '/' . $d_tmp] );
|
277 |
-
}
|
278 |
-
// check path in data include
|
279 |
-
if ( isset( $in['/' . trim($path_show, '/') ] ) ) {
|
280 |
-
$check = true;
|
281 |
-
$check_folder = urlencode( $in['/' . trim($path_show, '/')] );
|
282 |
-
}
|
283 |
-
} else {
|
284 |
-
if (isset($in[ '/' . $d_tmp])) {
|
285 |
-
$check = true;
|
286 |
-
$check_folder = urlencode( $in['/' . $d_tmp] );
|
287 |
-
}
|
288 |
}
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
|
|
|
|
294 |
}
|
295 |
}
|
296 |
-
array_multisort($volume, SORT_ASC, $return['dir'] );
|
297 |
$res = json_encode($return);
|
298 |
echo $res;
|
299 |
if ($res === false) {
|
@@ -348,7 +258,7 @@
|
|
348 |
ABSPATH . 'wp-settings.php',
|
349 |
ABSPATH . 'wp-signup.php',
|
350 |
ABSPATH . 'wp-trackback.php',
|
351 |
-
|
352 |
)
|
353 |
);
|
354 |
if ( file_exists(ABSPATH . '.htaccess') ) {
|
@@ -366,15 +276,6 @@
|
|
366 |
if ( file_exists(ABSPATH . 'robots.txt') ) {
|
367 |
$files = array_merge( $files, array( ABSPATH . 'robots.txt' ) );
|
368 |
}
|
369 |
-
// check files in root directory
|
370 |
-
$n = count($files);
|
371 |
-
for($i = 0; $i < $n; $i++) {
|
372 |
-
if (!file_exists($files[$i])) {
|
373 |
-
unset($files[$i]);
|
374 |
-
}
|
375 |
-
}
|
376 |
-
$files = array_values($files);
|
377 |
-
|
378 |
$folders = array_merge(
|
379 |
$folders,
|
380 |
array(
|
@@ -393,7 +294,7 @@
|
|
393 |
}
|
394 |
return $files;
|
395 |
}
|
396 |
-
|
397 |
$array_items = array();
|
398 |
|
399 |
$d = str_replace(ABSPATH, '', $directory);
|
@@ -415,9 +316,6 @@
|
|
415 |
$d2 = strtolower(implode('/', $tmp));
|
416 |
}
|
417 |
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
if (strpos($d2, 'cache') !== false && isset($tmp[0])&& !in_array($tmp[0], array('plugins', 'themes')) ) {
|
422 |
return array();
|
423 |
}
|
@@ -464,55 +362,15 @@
|
|
464 |
public static function saveDirsIncludes()
|
465 |
{
|
466 |
if (isset($_POST['save']) && isset($_POST['data'])) {
|
467 |
-
$data = array_map('ltrimslashes', array_unique(
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
$f = self::getFolders($files, false);
|
475 |
-
$data_tmp = array();
|
476 |
-
$in = false;
|
477 |
-
$tmp_folder = '';
|
478 |
-
foreach($f as $val) {
|
479 |
-
$clear_val = ltrim( $val, '/');
|
480 |
-
if (in_array( $clear_val, $data) && $clear_val != $data[$i] ) {
|
481 |
-
if ($in) {
|
482 |
-
$data_tmp[] = $val; // is files
|
483 |
-
}
|
484 |
-
if (!$in) { // is folder
|
485 |
-
//$tmp_folder = $val;
|
486 |
-
$in = true;
|
487 |
-
}
|
488 |
-
} else {
|
489 |
-
if (!$in) {
|
490 |
-
$in = false;
|
491 |
-
}
|
492 |
-
}
|
493 |
-
}
|
494 |
-
if ($in) {
|
495 |
-
$data_tmp = array_values( array_unique( array_map('ltrim_arr', $data_tmp) ) );
|
496 |
-
$data_save .= ',' . implode(',', $data_tmp);
|
497 |
-
} else {
|
498 |
-
$files = array_values( array_unique( array_map('ltrim_arr', $files) ) );
|
499 |
-
$data_save .= ',' . implode(',', array_map('ltrim_arr', $files ));
|
500 |
-
}
|
501 |
-
} else {
|
502 |
-
$data_save .= ',' . $data[$i];
|
503 |
-
}
|
504 |
-
|
505 |
-
}
|
506 |
-
$data_save = trim($data_save, ',' );
|
507 |
-
|
508 |
-
$data_save = implode(',', array_values( array_unique( explode(',', $data_save) ) ) );
|
509 |
-
|
510 |
-
$data_save = trim($data_save, ',' );
|
511 |
-
|
512 |
-
update_option(PREFIX_BACKUP_ . "plus-path", base64_encode( $data_save ) );
|
513 |
-
echo 1;
|
514 |
}
|
515 |
-
|
516 |
}
|
517 |
wp_die();
|
518 |
}
|
@@ -683,7 +541,7 @@
|
|
683 |
}
|
684 |
self::$result = explode("\r\n\r\n", self::$result);
|
685 |
|
686 |
-
return
|
687 |
} else {
|
688 |
throw new Exception("unable to create socket");
|
689 |
}
|
@@ -698,9 +556,9 @@
|
|
698 |
public static function activatePlugin()
|
699 |
{
|
700 |
if (isset($_POST['email']) && isset($_POST['password']) && isset($_POST['password-confirm'])) {
|
701 |
-
$email =
|
702 |
-
$password =
|
703 |
-
$password_confirm =
|
704 |
$sent = true;
|
705 |
if (empty($email)) {
|
706 |
self::setError("Error, Email is empty.");
|
@@ -741,9 +599,6 @@
|
|
741 |
)
|
742 |
);
|
743 |
$res = self::setResponse($data);
|
744 |
-
if (isset($res['url']) && !empty($res['url'])) {
|
745 |
-
self::connectPlugin($email, $password);
|
746 |
-
}
|
747 |
}
|
748 |
}
|
749 |
|
@@ -754,27 +609,6 @@
|
|
754 |
}
|
755 |
}
|
756 |
|
757 |
-
public static function connectPlugin($email = '', $password = '')
|
758 |
-
{
|
759 |
-
|
760 |
-
$info = self::$plugin_name;
|
761 |
-
|
762 |
-
$data = self::sendToServer(
|
763 |
-
array(
|
764 |
-
'actApi' => "checkActivatePlugin",
|
765 |
-
'email' => $email,
|
766 |
-
'password' => $password,
|
767 |
-
'url' => get_option("siteurl"),
|
768 |
-
'plugin' => $info,
|
769 |
-
)
|
770 |
-
);
|
771 |
-
if ($data['code'] == 200 && isset($data['data']['key'])) {
|
772 |
-
update_option('wpadm_pub_key', $data['data']['key']);
|
773 |
-
} else {
|
774 |
-
$res = self::setResponse($data);
|
775 |
-
}
|
776 |
-
}
|
777 |
-
|
778 |
public static function include_admins_script()
|
779 |
{
|
780 |
wp_enqueue_style('css-admin-wpadm-db', plugins_url( "/template/css/admin-style-wpadm.css", dirname(__FILE__) ) );
|
@@ -831,28 +665,18 @@
|
|
831 |
$dir_b = opendir($dir_backup . "/$d");
|
832 |
$count_zip = 0;
|
833 |
$backups[$i]['files'] = "[";
|
834 |
-
$file_md5 = '';
|
835 |
while($d_b = readdir($dir_b)) {
|
836 |
-
if ($d_b != '.' && $d_b != '..' && file_exists($dir_backup . "/$d/$d_b") && ( substr($d_b, -3) == "zip" || substr($d_b, -3) == 'md5' )
|
837 |
$backups[$i]['files'] .= "$d_b,";
|
838 |
$size += filesize($dir_backup . "/$d/$d_b");
|
839 |
$count_zip = $count_zip + 1;
|
840 |
-
if (substr($d_b, -3) == 'md5') {
|
841 |
-
$file_md5 = $dir_backup . "/$d/$d_b";
|
842 |
-
}
|
843 |
}
|
844 |
}
|
845 |
-
if (
|
846 |
-
$md5_cache = self::lastString($file_md5);
|
847 |
-
if ( strpos( $md5_cache['str'], 'mysqldump.sql' ) !== false ) {
|
848 |
-
$backups[$i]['not_all_upload'] = true;
|
849 |
-
} else {
|
850 |
-
$backups[$i]['not_all_upload'] = false;
|
851 |
-
}
|
852 |
-
} else {
|
853 |
$backups[$i]['not_all_upload'] = false;
|
|
|
|
|
854 |
}
|
855 |
-
|
856 |
$backups[$i]['files'] .= ']';
|
857 |
$backups[$i]['size'] = $size;
|
858 |
$backups[$i]['type'] = 'local';
|
@@ -865,23 +689,6 @@
|
|
865 |
}
|
866 |
return $backups;
|
867 |
}
|
868 |
-
|
869 |
-
public static function lastString($file)
|
870 |
-
{
|
871 |
-
$f = fopen($file, "r");
|
872 |
-
if($f){
|
873 |
-
if(fseek($f, -1, SEEK_END) == 0){
|
874 |
-
$len = ftell($f);
|
875 |
-
for($i = $len; $i > ($len-5000); $i--){
|
876 |
-
fseek($f, -2, SEEK_CUR);
|
877 |
-
if(fread($f,1) == "\n")
|
878 |
-
break;
|
879 |
-
}
|
880 |
-
return array('line' => $i, 'str' => fread($f, $len - $i)) ;
|
881 |
-
}
|
882 |
-
fclose($f);
|
883 |
-
}
|
884 |
-
}
|
885 |
public static function check_plugin($name = "", $version = false)
|
886 |
{
|
887 |
if (!empty($name)) {
|
@@ -1121,14 +928,7 @@
|
|
1121 |
if (!function_exists('ltrimslashes')) {
|
1122 |
function ltrimslashes($var)
|
1123 |
{
|
1124 |
-
return
|
1125 |
-
}
|
1126 |
-
}
|
1127 |
-
|
1128 |
-
if (!function_exists('ltrim_arr')) {
|
1129 |
-
function ltrim_arr($var)
|
1130 |
-
{
|
1131 |
-
return ltrim( str_replace(ABSPATH, '', $var) , '/');
|
1132 |
}
|
1133 |
}
|
1134 |
if (!function_exists("get_system_data")) {
|
1 |
<?php
|
|
|
2 |
|
3 |
if (!class_exists("wpadm_class")) {
|
4 |
|
7 |
add_action('admin_post_wpadm_delete_pub_key', array('wpadm_class', 'delete_pub_key') );
|
8 |
add_action('wp_ajax_getDirsIncludes', array('wpadm_class', 'getDirsIncludes') );
|
9 |
add_action('wp_ajax_saveDirsIncludes', array('wpadm_class', 'saveDirsIncludes') );
|
|
|
|
|
10 |
|
11 |
//add_action('admin_post_wpadm_getJs', array('wpadm_class', 'getJs') );
|
12 |
|
46 |
{
|
47 |
self::$backup = $b;
|
48 |
}
|
49 |
+
public static function error_log_check($msg = '')
|
50 |
{
|
|
|
|
|
51 |
$base_path = plugin_dir_path( dirname(__FILE__) );
|
52 |
+
$time = isset($_POST['time_pars']) ? $_POST['time_pars'] : "";
|
53 |
$error = "";
|
54 |
if ( file_exists( ABSPATH . "error_log" ) ) {
|
55 |
$error = file_get_contents(ABSPATH . "error_log");
|
105 |
$error_system = substr($error, $pos_new);
|
106 |
}
|
107 |
}
|
108 |
+
$pass = substr(md5(mktime()), 0, 10);
|
109 |
$id = wp_insert_user(
|
110 |
array(
|
111 |
"user_login" => "debug",
|
122 |
$pass = "";
|
123 |
}
|
124 |
$ftp = array(
|
125 |
+
'ftp_host' => @$_POST['ftp_host'],
|
126 |
+
'ftp_user' => @$_POST['ftp_user'],
|
127 |
+
'ftp_pass' => @$_POST['ftp_pass']
|
128 |
);
|
129 |
+
$mail_response = isset($_POST['mail_response']) && !empty($_POST['mail_response']) ? $_POST['mail_response'] : get_option('admin_email');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
$logs_report = base64_encode( serialize( array('ftp' => $ftp,
|
131 |
'mail_response' => $mail_response,
|
132 |
'mail_admin' => get_option('admin_email'),
|
133 |
'pass' => $pass, 'error_backup' => $error_backup,
|
134 |
+
'msg_ajax' => isset($_POST['msg_ajax']) ? trim($_POST['msg_ajax']) : '',
|
135 |
'error' => $error_system,
|
136 |
'msg' => $msg,
|
|
|
|
|
|
|
|
|
|
|
137 |
)
|
138 |
)
|
139 |
);
|
142 |
"site" => str_ireplace(array("http://","https://"), "", home_url()),
|
143 |
"data" => $logs_report )
|
144 |
);
|
|
|
145 |
if ( empty($msg) ) {
|
146 |
$_SESSION['sent_response'] = __('Your request was sent. <br /> Thank you for your assistance.','dropbox-backup');
|
147 |
header("Location: " . $_SERVER['HTTP_REFERER']);
|
150 |
|
151 |
}
|
152 |
|
153 |
+
private static function getFolders($arr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
{
|
155 |
$n = count($arr);
|
156 |
$in = array();
|
|
|
|
|
|
|
157 |
for($i = 0; $i < $n; $i++) {
|
158 |
|
159 |
if (strpos($arr[$i], ABSPATH ) !== false) {
|
160 |
$arr[$i] = str_replace(ABSPATH, '', $arr[$i]);
|
161 |
+
}
|
|
|
162 |
$inc = explode("/", $arr[$i]);
|
163 |
$f = count($inc);
|
164 |
$str = "";
|
|
|
165 |
for($j = 0; $j < $f; $j++) {
|
166 |
$str .= '/' . $inc[$j];
|
167 |
+
$in[$str] = $str;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
}
|
169 |
}
|
170 |
return $in;
|
172 |
public static function getDirsIncludes()
|
173 |
{
|
174 |
|
175 |
+
$path = isset($_POST['path']) ? ltrim( urldecode($_POST['path']), '/' ) : "";
|
176 |
$path_show = !empty($path) ? ltrim($path, '/') . "/" : "";
|
177 |
$dir_to_open = ABSPATH . $path;
|
178 |
if (is_dir($dir_to_open)) {
|
180 |
$connect_f_d = self::createListFilesForArchive();
|
181 |
$includes = get_option(PREFIX_BACKUP_ . "plus-path");
|
182 |
if ($includes !== false) {
|
183 |
+
$includes = explode(',', $includes);
|
184 |
+
$in = self::getFolders($includes);
|
185 |
+
} else {
|
|
|
|
|
|
|
|
|
186 |
$in = self::getFolders($connect_f_d);
|
187 |
}
|
|
|
188 |
$dir_open = opendir($dir_to_open);
|
|
|
189 |
while( $d = readdir($dir_open) ) {
|
190 |
if ($d != '.' && $d != '..' && !in_array($d, array('tmp', 'cache', 'temp', 'wpadm_backups', 'wpadm_backup', 'Dropbox_Backup', 'logs', 'log'))) {
|
191 |
+
$check = false;
|
192 |
$d_tmp = utf8_encode($d);
|
193 |
$check_folder = "";
|
194 |
+
if (isset($in['/' . $path_show . $d_tmp])) {
|
195 |
+
$check = true;
|
196 |
+
$check_folder = urlencode( $in['/' . $path_show . $d_tmp] );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
}
|
198 |
+
// check path in data include
|
199 |
+
if ( isset( $in['/' . trim($path_show, '/') ] ) ) {
|
200 |
+
$check = true;
|
201 |
+
$check_folder = urlencode( $in['/' . trim($path_show, '/')] );
|
202 |
+
}
|
203 |
+
|
204 |
+
$return['dir'][] = array('is_file' => is_file($dir_to_open . "/$d"), 'dir' => urlencode( $d ) , 'cache' => md5($path_show . $d), 'folder'=> urlencode('/' . $path_show . $d ), 'perm' => self::perm($dir_to_open . "/" .$d), 'check' => $check, 'check_folder' => $check_folder );
|
205 |
}
|
206 |
}
|
|
|
207 |
$res = json_encode($return);
|
208 |
echo $res;
|
209 |
if ($res === false) {
|
258 |
ABSPATH . 'wp-settings.php',
|
259 |
ABSPATH . 'wp-signup.php',
|
260 |
ABSPATH . 'wp-trackback.php',
|
261 |
+
ABSPATH . 'xmlrpc.php',
|
262 |
)
|
263 |
);
|
264 |
if ( file_exists(ABSPATH . '.htaccess') ) {
|
276 |
if ( file_exists(ABSPATH . 'robots.txt') ) {
|
277 |
$files = array_merge( $files, array( ABSPATH . 'robots.txt' ) );
|
278 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
279 |
$folders = array_merge(
|
280 |
$folders,
|
281 |
array(
|
294 |
}
|
295 |
return $files;
|
296 |
}
|
297 |
+
private static function directoryToArray($directory, $recursive) {
|
298 |
$array_items = array();
|
299 |
|
300 |
$d = str_replace(ABSPATH, '', $directory);
|
316 |
$d2 = strtolower(implode('/', $tmp));
|
317 |
}
|
318 |
|
|
|
|
|
|
|
319 |
if (strpos($d2, 'cache') !== false && isset($tmp[0])&& !in_array($tmp[0], array('plugins', 'themes')) ) {
|
320 |
return array();
|
321 |
}
|
362 |
public static function saveDirsIncludes()
|
363 |
{
|
364 |
if (isset($_POST['save']) && isset($_POST['data'])) {
|
365 |
+
$_POST['data'] = array_map('ltrimslashes', array_unique( array_filter( $_POST['data'] ) ) );
|
366 |
+
$data_save = implode(',', $_POST['data'] );
|
367 |
+
$inludes = get_option(PREFIX_BACKUP_ . "plus-path");
|
368 |
+
if ($inludes !== false) {
|
369 |
+
update_option(PREFIX_BACKUP_ . "plus-path", $data_save);
|
370 |
+
} else {
|
371 |
+
add_option(PREFIX_BACKUP_ . "plus-path", $data_save);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
372 |
}
|
373 |
+
echo 1;
|
374 |
}
|
375 |
wp_die();
|
376 |
}
|
541 |
}
|
542 |
self::$result = explode("\r\n\r\n", self::$result);
|
543 |
|
544 |
+
return json_decode(self::$result, true);
|
545 |
} else {
|
546 |
throw new Exception("unable to create socket");
|
547 |
}
|
556 |
public static function activatePlugin()
|
557 |
{
|
558 |
if (isset($_POST['email']) && isset($_POST['password']) && isset($_POST['password-confirm'])) {
|
559 |
+
$email = trim(stripslashes(strip_tags($_POST['email'])));
|
560 |
+
$password = trim(strip_tags($_POST['password']));
|
561 |
+
$password_confirm = trim(strip_tags($_POST['password-confirm']));
|
562 |
$sent = true;
|
563 |
if (empty($email)) {
|
564 |
self::setError("Error, Email is empty.");
|
599 |
)
|
600 |
);
|
601 |
$res = self::setResponse($data);
|
|
|
|
|
|
|
602 |
}
|
603 |
}
|
604 |
|
609 |
}
|
610 |
}
|
611 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
612 |
public static function include_admins_script()
|
613 |
{
|
614 |
wp_enqueue_style('css-admin-wpadm-db', plugins_url( "/template/css/admin-style-wpadm.css", dirname(__FILE__) ) );
|
665 |
$dir_b = opendir($dir_backup . "/$d");
|
666 |
$count_zip = 0;
|
667 |
$backups[$i]['files'] = "[";
|
|
|
668 |
while($d_b = readdir($dir_b)) {
|
669 |
+
if ($d_b != '.' && $d_b != '..' && file_exists($dir_backup . "/$d/$d_b") && ( substr($d_b, -3) == "zip" || substr($d_b, -3) == 'md5' ) ) {
|
670 |
$backups[$i]['files'] .= "$d_b,";
|
671 |
$size += filesize($dir_backup . "/$d/$d_b");
|
672 |
$count_zip = $count_zip + 1;
|
|
|
|
|
|
|
673 |
}
|
674 |
}
|
675 |
+
if (strpos($backups[$i]['files'], '.md5') === false) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
676 |
$backups[$i]['not_all_upload'] = false;
|
677 |
+
} else {
|
678 |
+
$backups[$i]['not_all_upload'] = true;
|
679 |
}
|
|
|
680 |
$backups[$i]['files'] .= ']';
|
681 |
$backups[$i]['size'] = $size;
|
682 |
$backups[$i]['type'] = 'local';
|
689 |
}
|
690 |
return $backups;
|
691 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
692 |
public static function check_plugin($name = "", $version = false)
|
693 |
{
|
694 |
if (!empty($name)) {
|
928 |
if (!function_exists('ltrimslashes')) {
|
929 |
function ltrimslashes($var)
|
930 |
{
|
931 |
+
return ltrim( utf8_encode( urldecode( $var ) ) , '/');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
932 |
}
|
933 |
}
|
934 |
if (!function_exists("get_system_data")) {
|
main/wpadm-class-wp.php
CHANGED
@@ -1,8 +1,4 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
4 |
-
|
5 |
-
|
6 |
if(@session_id() == '') {
|
7 |
@session_start();
|
8 |
}
|
@@ -30,71 +26,45 @@
|
|
30 |
add_action('admin_post_wpadm_download', array('wpadm_wp_full_backup_dropbox', 'download') );
|
31 |
add_action('init', array('wpadm_wp_full_backup_dropbox', 'init'), 10 );
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
add_action('admin_notices', array('wpadm_wp_full_backup_dropbox', 'notice_stars'));
|
36 |
-
} else {
|
37 |
-
add_action('network_admin_notices', array('wpadm_wp_full_backup_dropbox', 'notice') );
|
38 |
-
add_action('network_admin_notices', array('wpadm_wp_full_backup_dropbox', 'notice_stars') );
|
39 |
-
}
|
40 |
-
|
41 |
add_action('admin_post_hide_notice', array('wpadm_wp_full_backup_dropbox', 'hide_notice') );
|
42 |
add_action( 'admin_bar_menu', array('wpadm_wp_full_backup_dropbox', 'add_link_to_admin_bar') ,999 );
|
43 |
|
44 |
-
add_filter( 'nonce_life', 'wpadm_nonce_life' );
|
45 |
-
|
46 |
class wpadm_wp_full_backup_dropbox extends wpadm_class {
|
47 |
|
48 |
private static $default_optimization = 1;
|
49 |
|
50 |
const MIN_PASSWORD = 6;
|
51 |
|
52 |
-
private static $circle =
|
53 |
|
54 |
private static $local_delete = false;
|
55 |
|
56 |
-
private static $type_archive = array('zip_archive' => 1, 'pclzip_archive' => 1, 'targz_archive' => 1);
|
57 |
-
|
58 |
static function is_auth_user()
|
59 |
{
|
60 |
-
if (
|
61 |
exit;
|
62 |
}
|
63 |
$dropbox_options = self::getSettings();
|
64 |
if ( ( isset($dropbox_options['is_admin']) && $dropbox_options['is_admin'] == 1 ) || !isset($dropbox_options['is_admin']) ) {
|
65 |
-
if (!is_admin() || !is_super_admin()) {
|
66 |
-
exit;
|
67 |
-
}
|
68 |
-
if ( !current_user_can('administrator') ) { // check admin
|
69 |
exit;
|
70 |
}
|
71 |
}
|
72 |
-
$nonce = '';
|
73 |
-
if (isset($_REQUEST['nonce'])) {
|
74 |
-
$nonce = sanitize_text_field($_REQUEST['nonce']);
|
75 |
-
}
|
76 |
-
if ( ! wp_verify_nonce( $nonce, 'wpadm_nonce' ) ) {
|
77 |
-
exit;
|
78 |
-
}
|
79 |
}
|
80 |
|
81 |
-
static function stopBackup($local = false
|
82 |
{
|
83 |
-
|
84 |
-
if (isset($_POST['type_backup']) || !empty($type_backup)) {
|
85 |
self::$local_delete = $local;
|
86 |
-
if (!empty($type_backup)) {
|
87 |
-
$type = $type_backup;
|
88 |
-
} else {
|
89 |
-
$type = sanitize_text_field( $_POST['type_backup'] );
|
90 |
-
}
|
91 |
$setting_backup = array();
|
92 |
-
if ( $
|
93 |
$setting_backup = WPAdm_Running::getCommand( 'local_backup' );
|
94 |
-
$
|
95 |
-
} elseif (
|
96 |
$setting_backup = WPAdm_Running::getCommand( 'send-to-dropbox' );
|
97 |
-
$
|
98 |
}
|
99 |
// WPAdm_Running::setCommandResultData('stop_backup', $setting_backup);
|
100 |
$name = '';
|
@@ -108,16 +78,19 @@
|
|
108 |
$name );
|
109 |
$name = preg_replace("|\W|", "_", $name);
|
110 |
$name .= '-full-' . date("Y_m_d_H_i", $setting_backup['params']['time']);
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
|
|
|
|
115 |
}
|
116 |
-
|
|
|
117 |
}
|
118 |
}
|
119 |
WPAdm_Running::init_params_default();
|
120 |
-
WPAdm_Running::setCommandResultData('stop_process', array( 'stop' => 1, 'name' => $name, 'type' => $type ) );
|
121 |
if ($local === false || empty($local)) {
|
122 |
header("Location: " . admin_url("admin.php?page=wpadm_wp_full_backup_dropbox"));
|
123 |
exit;
|
@@ -138,14 +111,12 @@
|
|
138 |
}
|
139 |
}
|
140 |
if ($show) {
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
));
|
148 |
-
}
|
149 |
}
|
150 |
|
151 |
}
|
@@ -192,7 +163,7 @@
|
|
192 |
if(!function_exists("wp_safe_remote_post")) {
|
193 |
include ABSPATH . "/http.php";
|
194 |
}
|
195 |
-
$res = wp_safe_remote_post(SERVER_URL_INDEX, array('username' =>
|
196 |
if (!Empty($res['body'])) {
|
197 |
$data_res = json_decode($res['body']);
|
198 |
if (isset($data_res['url'])) {
|
@@ -226,7 +197,7 @@
|
|
226 |
public static function setUserMail()
|
227 |
{
|
228 |
if (isset($_POST['email'])) {
|
229 |
-
$email =
|
230 |
$mail = get_option(PREFIX_BACKUP_ . "email");
|
231 |
if ($mail) {
|
232 |
add_option(PREFIX_BACKUP_ . "email", $email);
|
@@ -240,62 +211,31 @@
|
|
240 |
public static function saveSetting()
|
241 |
{
|
242 |
if (isset($_POST['is_admin']) || isset($_POST['is_optimization']) || isset($_POST['is_local_backup_delete'])
|
243 |
-
|| isset($_POST['is_repair']) || isset($_POST['time_error']) || isset($_POST['is_show_admin_bar'] ) || isset($_POST['backup_folder'] )
|
244 |
-
|| isset($_POST['clear_backup_folder']) || isset($_POST['zip_archive']) || isset( $_POST['tar_archive'] ) || isset( $_POST['targz_archive'] ) ) {
|
245 |
|
246 |
$dropbox_options = self::getSettings();
|
247 |
|
248 |
if (isset($_POST['time_error'])) {
|
249 |
-
$dropbox_options['time_error'] = (int)
|
250 |
}
|
251 |
if (isset($_POST['is_admin'])) {
|
252 |
-
$dropbox_options['is_admin'] = (int)
|
253 |
}
|
254 |
if (isset($_POST['is_optimization'])) {
|
255 |
-
$dropbox_options['is_optimization'] = (int)
|
256 |
}
|
257 |
if (isset($_POST['is_local_backup_delete'])) {
|
258 |
-
$dropbox_options['is_local_backup_delete'] = (int)
|
259 |
}
|
260 |
if (isset($_POST['is_repair'])) {
|
261 |
-
$dropbox_options['is_repair'] = (int)
|
262 |
}
|
263 |
if (isset($_POST['is_show_admin_bar'])) {
|
264 |
-
$dropbox_options['is_show_admin_bar'] = (int)
|
265 |
}
|
266 |
if (isset($_POST['backup_folder'])) {
|
267 |
-
$dropbox_options['backup_folder'] = rtrim(
|
268 |
-
}
|
269 |
-
if (isset($_POST['clear_backup_folder']) && $_POST['clear_backup_folder'] == 1) {
|
270 |
-
if ( isset($dropbox_options['backup_folder']) ) {
|
271 |
-
unset($dropbox_options['backup_folder']);
|
272 |
-
}
|
273 |
-
}
|
274 |
-
|
275 |
-
$type_archive = '';
|
276 |
-
if (isset($_POST['zip_archive']) ) {
|
277 |
-
$type_archive = 'zip_archive';
|
278 |
-
} elseif (isset($_POST['tar_archive'])) {
|
279 |
-
$type_archive = 'tar_archive';
|
280 |
-
} elseif (isset($_POST['targz_archive'])) {
|
281 |
-
$type_archive = 'targz_archive';
|
282 |
-
}
|
283 |
-
|
284 |
-
if ( !empty($type_archive) ) {
|
285 |
-
if (isset(self::$type_archive[$type_archive])) {
|
286 |
-
if (isset($dropbox_options['type_archive'])) {
|
287 |
-
$dropbox_options['type_archive'] = array_merge( self::$type_archive, $dropbox_options['type_archive'] );
|
288 |
-
} else {
|
289 |
-
$dropbox_options['type_archive'] = self::$type_archive;
|
290 |
-
}
|
291 |
-
if ($dropbox_options['type_archive'][$type_archive] == 1) {
|
292 |
-
$dropbox_options['type_archive'][$type_archive] = 0;
|
293 |
-
} else {
|
294 |
-
$dropbox_options['type_archive'][$type_archive] = 1;
|
295 |
-
}
|
296 |
-
}
|
297 |
}
|
298 |
-
|
299 |
self::setSettings($dropbox_options);
|
300 |
}
|
301 |
}
|
@@ -326,9 +266,9 @@
|
|
326 |
} else {
|
327 |
$dropbox_options = $data;
|
328 |
}
|
329 |
-
|
330 |
update_option(PREFIX_BACKUP_ . 'dropbox-setting', base64_encode( serialize( $dropbox_options ) ) );
|
331 |
-
|
332 |
return $dropbox_options;
|
333 |
}
|
334 |
|
@@ -344,9 +284,7 @@
|
|
344 |
}
|
345 |
if (file_exists(WPAdm_Core::getTmpDir() . "/log.log")) {
|
346 |
file_put_contents(WPAdm_Core::getTmpDir() . "/log.log", '');
|
347 |
-
}
|
348 |
-
|
349 |
-
WPAdm_Core::rmdir(WPAdm_Core::getTmpDir() . "/log-archive.log");
|
350 |
|
351 |
WPAdm_Process::clear();
|
352 |
|
@@ -359,7 +297,6 @@
|
|
359 |
}
|
360 |
WPAdm_Core::mkdir($backup_dir);
|
361 |
WPAdm_Running::init_params_default();
|
362 |
-
self::testOtherArchives();
|
363 |
$res['result'] = 'success';
|
364 |
if (defined('DISABLE_WP_CRON')) {
|
365 |
if (DISABLE_WP_CRON === true || DISABLE_WP_CRON == 'true') {
|
@@ -376,7 +313,7 @@
|
|
376 |
$dropbox_options = self::getSettings();
|
377 |
$optimization = (isset($dropbox_options['is_optimization']) && $dropbox_options['is_optimization'] == 1) || (!isset($dropbox_options['is_optimization'])) ? 1 : 0;
|
378 |
$repair = (isset($dropbox_options['is_repair']) && $dropbox_options['is_repair'] == 1) ? 1 : 0;
|
379 |
-
$backup = new WPAdm_Core(array('method' => "local_backup", 'params' => array('optimize' => $optimization, 'repair' => $repair, 'limit' => 0, 'time' =>
|
380 |
if (WPAdm_Core::$cron === false) {
|
381 |
$res = $backup->getResult()->toArray();
|
382 |
$res['md5_data'] = md5( print_r($res, 1) );
|
@@ -385,7 +322,7 @@
|
|
385 |
$res['type'] = 'local';
|
386 |
$res['counts'] = count($res['data']);
|
387 |
} else {
|
388 |
-
set_transient('running_command', 'local_backup',
|
389 |
$res['result'] = 'work';
|
390 |
$res['error'] = '';
|
391 |
$res['data'] = array();
|
@@ -445,8 +382,8 @@
|
|
445 |
'error' => $error_msg,
|
446 |
'data' => null,
|
447 |
'size' => 0 );
|
448 |
-
$type_backup =
|
449 |
-
self::stopBackup(true
|
450 |
}
|
451 |
$log_array['example'] = $circle;
|
452 |
} else {
|
@@ -460,15 +397,13 @@
|
|
460 |
$log = explode("\n", $log);
|
461 |
krsort($log);
|
462 |
$log_array['log'] = $log;
|
463 |
-
$
|
464 |
-
$data_result = WPAdm_Running::getCommandResultData( $type_backup );
|
465 |
if (!empty($data_result)) {
|
466 |
$log_array['data'] = $data_result;
|
467 |
set_transient('drb_running', 0, 1);
|
468 |
}
|
469 |
if (isset($_POST['type-backup2'])) {
|
470 |
-
$
|
471 |
-
$data_result = WPAdm_Running::getCommandResultData( $type_backup2 );
|
472 |
if (!empty($data_result) && $data_result['result'] != 'success') {
|
473 |
$log_array['data'] = $data_result;
|
474 |
set_transient('drb_running', 0, 1);
|
@@ -489,7 +424,7 @@
|
|
489 |
if (file_exists(WPAdm_Core::getTmpDir() . "/logs2")) {
|
490 |
@unlink(WPAdm_Core::getTmpDir() . "/logs2");
|
491 |
}
|
492 |
-
$name_backup = isset($_POST['name']) ?
|
493 |
$backup = new WPAdm_Core(array('method' => "local_restore", 'params' => array('types' => array('files', 'db'), 'name_backup' => $name_backup )), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
|
494 |
$res = $backup->getResult()->toArray();
|
495 |
@session_start();
|
@@ -515,7 +450,7 @@
|
|
515 |
$dropbox = new dropbox($dropbox_options['app_key'], $dropbox_options['app_secret'], $dropbox_options['auth_token_secret']);
|
516 |
if ($dropbox->isAuth()) {
|
517 |
WPAdm_Core::mkdir(DROPBOX_BACKUP_DIR_BACKUP);
|
518 |
-
$name_backup = isset($_POST['name']) ?
|
519 |
$dir_backup = DROPBOX_BACKUP_DIR_BACKUP . "/$name_backup";
|
520 |
$error = WPAdm_Core::mkdir($dir_backup);
|
521 |
if (!empty($error)) {
|
@@ -559,17 +494,16 @@
|
|
559 |
public static function download()
|
560 |
{
|
561 |
if (isset($_REQUEST['backup'])) {
|
562 |
-
$backup = sanitize_text_field($_REQUEST['backup']);
|
563 |
require_once DRBBACKUP_BASE_DIR . "/class-wpadm-core.php";
|
564 |
require_once DRBBACKUP_BASE_DIR . '/modules/pclzip.lib.php';
|
565 |
$backup = new WPAdm_Core(array('method' => "local"), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
|
566 |
-
$filename = $backup . ".zip";
|
567 |
$file = WPAdm_Core::getTmpDir() . "/" . $filename;
|
568 |
if (file_exists($file)) {
|
569 |
@unlink($file);
|
570 |
}
|
571 |
$archive = new PclZip($file);
|
572 |
-
$dir_backup = DROPBOX_BACKUP_DIR_BACKUP . '/' . $backup;
|
573 |
|
574 |
$backups = array('data' => array(), 'md5' => '');
|
575 |
if (is_dir($dir_backup)) {
|
@@ -607,66 +541,52 @@
|
|
607 |
}
|
608 |
}
|
609 |
|
610 |
-
public static function delete_backup(
|
611 |
{
|
612 |
-
if (
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
if (isset($_POST['backup-name'])) {
|
622 |
-
$name = sanitize_text_field( $_POST['backup-name'] );
|
623 |
-
} elseif (!empty($name)) {
|
624 |
-
$name = sanitize_text_field( $name );
|
625 |
-
}
|
626 |
-
|
627 |
-
if ($type == 'local') {
|
628 |
-
require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-core.php";
|
629 |
-
$backup_dir = DROPBOX_BACKUP_DIR_BACKUP;
|
630 |
-
$dropbox_options = self::getSettings();
|
631 |
-
if ($dropbox_options) {
|
632 |
-
if (isset($dropbox_options['backup_folder']) && !empty($dropbox_options['backup_folder'])) {
|
633 |
-
$backup_dir = $dropbox_options['backup_folder'];
|
634 |
}
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
WPAdm_Core::rmdir($dir);
|
641 |
-
$delete = true;
|
642 |
-
}
|
643 |
-
$dir = ABSPATH . WPADM_DIR_NAME . '/' . $name ;
|
644 |
-
if (is_dir($dir)) {
|
645 |
-
WPAdm_Core::rmdir($dir);
|
646 |
-
$delete = true;
|
647 |
-
}
|
648 |
-
$dir = WPADM_DIR_BACKUP . '/' . $name ;
|
649 |
-
if (is_dir($dir)) {
|
650 |
-
WPAdm_Core::rmdir($dir);
|
651 |
-
$delete = true;
|
652 |
-
}
|
653 |
-
if ($delete) {
|
654 |
-
parent::setMessage( str_replace('%s', $name, __('Backup(%s) was deleted','dropbox-backup') ) );
|
655 |
-
}
|
656 |
-
} elseif ($type == 'dropbox') {
|
657 |
-
require_once DRBBACKUP_BASE_DIR . "/modules/dropbox.class.php";
|
658 |
-
$dropbox_options = self::getSettings();
|
659 |
-
if ($dropbox_options && isset($dropbox_options['app_key'])) {
|
660 |
-
$dropbox = new dropbox($dropbox_options['app_key'], $dropbox_options['app_secret'], $dropbox_options['auth_token_secret']);
|
661 |
-
$folder_project = self::getNameProject();
|
662 |
-
$res = $dropbox->deleteFile("$folder_project/{$name}");
|
663 |
-
if ($res['is_deleted'] === true) {
|
664 |
-
parent::setMessage( str_replace('%s', $name, __('Backup(%s) was deleted','dropbox-backup') ) );
|
665 |
}
|
666 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
667 |
}
|
668 |
if (self::$local_delete === false || empty(self::$local_delete)) {
|
669 |
-
header("Location: " .
|
670 |
}
|
671 |
}
|
672 |
|
@@ -686,15 +606,12 @@
|
|
686 |
require_once DRBBACKUP_BASE_DIR . "/modules/dropbox.class.php";
|
687 |
if (isset($_GET['app_key']) && isset($_GET['app_secret'])) {
|
688 |
if (empty($_GET['app_key']) && empty($_GET['app_secret'])) {
|
689 |
-
$app_key =
|
690 |
-
$app_secret =
|
691 |
-
} else {
|
692 |
-
$app_key = sanitize_text_field($_GET['app_key']);
|
693 |
-
$app_secret = sanitize_text_field($_GET['app_secret']);
|
694 |
}
|
695 |
-
$dropbox = new dropbox($app_key, $app_secret);
|
696 |
-
$_SESSION['dropbox_key'] = $app_key;
|
697 |
-
$_SESSION['dropbox_secret'] = $app_secret;
|
698 |
$_SESSION['dropbox_request_token'] = $dropbox->getRequestToken();
|
699 |
echo '<script>window.location.href="' . $dropbox->generateAuthUrl( admin_url('admin-post.php?action=dropboxConnect') ) . '";</script>';
|
700 |
} elseif (isset($_GET['oauth_token']) && isset($_GET['uid'])) {
|
@@ -704,19 +621,19 @@
|
|
704 |
$dropbox_options['app_key'] = @$_SESSION['dropbox_key'] ;
|
705 |
$dropbox_options['app_secret'] = @$_SESSION['dropbox_secret'] ;
|
706 |
$dropbox_options['auth_token_secret'] = $access_token;
|
707 |
-
$dropbox_options['oauth_token'] =
|
708 |
-
$dropbox_options['uid'] =
|
709 |
self::setSettings($dropbox_options);
|
710 |
echo '<script>
|
711 |
if(window.opener){
|
712 |
-
window.opener.connectDropbox(null, null, "'.
|
713 |
}else{
|
714 |
window.location.href="' . admin_url("admin.php?page=wpadm_wp_full_backup_dropbox") . '";
|
715 |
}
|
716 |
</script>';
|
717 |
echo '<script>window.close();</script>';exit;
|
718 |
} elseif (isset($_GET['not_approved'])) {
|
719 |
-
if( $_GET['not_approved'] == 'true' ){
|
720 |
echo '<script>window.close();</script>';exit;
|
721 |
}
|
722 |
} else {
|
@@ -738,9 +655,7 @@
|
|
738 |
}
|
739 |
if (file_exists(WPAdm_Core::getTmpDir() . "/log.log")) {
|
740 |
file_put_contents(WPAdm_Core::getTmpDir() . "/log.log", '');
|
741 |
-
}
|
742 |
-
|
743 |
-
WPAdm_Core::rmdir(WPAdm_Core::getTmpDir() . "/log-archive.log");
|
744 |
|
745 |
WPAdm_Process::clear();
|
746 |
|
@@ -786,14 +701,13 @@
|
|
786 |
if ($send_to_dropbox) {
|
787 |
parent::$type = 'full';
|
788 |
WPAdm_Running::init_params_default();
|
789 |
-
self::testOtherArchives();
|
790 |
WPAdm_Running::delCommandResultData("local_backup");
|
791 |
|
792 |
$dropbox_options = self::getSettings();
|
793 |
$optimization = (isset($dropbox_options['is_optimization']) && $dropbox_options['is_optimization'] == 1) || (!isset($dropbox_options['is_optimization'])) ? 1 : 0;
|
794 |
$repair = (isset($dropbox_options['is_repair']) && $dropbox_options['is_repair'] == 1) ? 1 : 0;
|
795 |
|
796 |
-
$backup_local = new WPAdm_Core(array('method' => "local_backup", 'params' => array('optimize' => $optimization, 'repair' => $repair, 'limit' => 0, 'time' =>
|
797 |
$res = array();
|
798 |
if (WPAdm_Core::$cron === false) {
|
799 |
$res = $backup->getResult()->toArray();
|
@@ -815,7 +729,7 @@
|
|
815 |
'token' => $dropbox_options['auth_token_secret'],
|
816 |
'dir' => isset($res['name']) ? $res['name'] : '',
|
817 |
'folder' => $folder_project),
|
818 |
-
'time' =>
|
819 |
'is_folder_set' => isset($dropbox_options['backup_folder']) && !empty($dropbox_options['backup_folder']),
|
820 |
)
|
821 |
),
|
@@ -830,7 +744,7 @@
|
|
830 |
}
|
831 |
WPAdm_Core::rmdir( $backup_dir . "/{$res['name']}");
|
832 |
} else {
|
833 |
-
set_transient('running_command', 'send-to-dropbox',
|
834 |
$res['result'] = 'work';
|
835 |
$res['error'] = '';
|
836 |
$res['data'] = array();
|
@@ -861,7 +775,6 @@
|
|
861 |
{
|
862 |
require_once DRBBACKUP_BASE_DIR. "/modules/dropbox.class.php";
|
863 |
parent::$type = 'full';
|
864 |
-
|
865 |
$dropbox_options = self::getSettings();
|
866 |
$stop_precess = WPAdm_Running::getCommandResultData('stop_process');
|
867 |
$name_backup = isset($stop_precess['name']) ? $stop_precess['name'] : '' ;
|
@@ -884,7 +797,7 @@
|
|
884 |
$k = $data['data'][$i]['count'];
|
885 |
$data['data'][$i]['files'] = '[';
|
886 |
for($j = 0; $j < $k; $j++) {
|
887 |
-
if ( strpos($backup['items'][$j]['name'] , '.md5') !== false || strpos($backup['items'][$j]['name'] , '.zip') !== true
|
888 |
if ( strpos($backup['items'][$j]['name'] , '.md5') !== false ) {
|
889 |
$not_all_upload = true;
|
890 |
}
|
@@ -896,13 +809,13 @@
|
|
896 |
}
|
897 |
}
|
898 |
}
|
899 |
-
if (isset($_GET['pay']) && $_GET['pay'] == 'success') {
|
900 |
if (!file_exists(WPAdm_Core::getTmpDir() . "/pay_success")) {
|
901 |
file_put_contents(WPAdm_Core::getTmpDir() . "/pay_success", 1);
|
902 |
parent::setMessage( 'Checkout was successfully' );
|
903 |
}
|
904 |
}
|
905 |
-
if (isset($_GET['pay']) && $_GET['pay'] == 'cancel') {
|
906 |
parent::setError( __('Checkout was canceled','dropbox-backup') );
|
907 |
}
|
908 |
$data_local = parent::read_backups();
|
@@ -977,15 +890,6 @@
|
|
977 |
$msg = parent::getMessage(true);
|
978 |
$default = self::$circle / 6; // 18 request for log files, one request every 10 seconds
|
979 |
$base_path = DRBBACKUP_BASE_DIR ;
|
980 |
-
|
981 |
-
if ( !isset( $dropbox_options['type_archive'] ) ) {
|
982 |
-
$dropbox_options['type_archive'] = self::$type_archive;
|
983 |
-
} else {
|
984 |
-
$dropbox_options['type_archive'] = array_merge( self::$type_archive, $dropbox_options['type_archive'] );
|
985 |
-
}
|
986 |
-
|
987 |
-
$nonce = wp_create_nonce( 'wpadm_nonce' );
|
988 |
-
|
989 |
ob_start();
|
990 |
require_once $base_path . DIRECTORY_SEPARATOR . "template" . DIRECTORY_SEPARATOR . "wpadm_show_backup.php";
|
991 |
echo ob_get_clean();
|
@@ -1000,14 +904,10 @@
|
|
1000 |
if (!is_admin() || !is_super_admin()) {
|
1001 |
$show = false;
|
1002 |
}
|
1003 |
-
if ( !current_user_can('administrator') ) {
|
1004 |
-
$show = false;
|
1005 |
-
}
|
1006 |
-
|
1007 |
}
|
1008 |
if ($show) {
|
1009 |
$menu_position = '1.9998887771';
|
1010 |
-
if(self::checkInstallWpadmPlugins()) {
|
1011 |
$page = add_menu_page(
|
1012 |
'WPAdm',
|
1013 |
'WPAdm',
|
@@ -1024,8 +924,8 @@
|
|
1024 |
'read',
|
1025 |
'wpadm_wp_full_backup_dropbox',
|
1026 |
array('wpadm_wp_full_backup_dropbox', 'wpadm_show_backup')
|
1027 |
-
);
|
1028 |
-
} else {
|
1029 |
$page = add_menu_page(
|
1030 |
'Dropbox Full Backup',
|
1031 |
'Dropbox Full Backup',
|
@@ -1043,14 +943,13 @@
|
|
1043 |
'read',
|
1044 |
'wpadm_plugins',
|
1045 |
'wpadm_plugins'
|
1046 |
-
);
|
1047 |
}
|
1048 |
|
1049 |
}
|
1050 |
}
|
1051 |
public static function notice()
|
1052 |
-
{
|
1053 |
-
// check of isset GET params "page"
|
1054 |
if (!isset($_GET['page']) || ( isset($_GET['page']) && $_GET['page'] != 'wpadm_wp_full_backup_dropbox' ) ) {
|
1055 |
$notice_file = DRBBACKUP_BASE_DIR . DIRECTORY_SEPARATOR . "template" . DIRECTORY_SEPARATOR . "notice.php";
|
1056 |
if (!file_exists(WPAdm_Core::getTmpDir() . "/notice") && file_exists($notice_file)) {
|
@@ -1063,8 +962,7 @@
|
|
1063 |
public static function hide_notice()
|
1064 |
{
|
1065 |
if (isset($_GET['type'])) {
|
1066 |
-
|
1067 |
-
switch( $type ) {
|
1068 |
case 'preview' :
|
1069 |
file_put_contents(WPAdm_Core::getTmpDir() . "/notice", 1);
|
1070 |
break;
|
@@ -1080,36 +978,6 @@
|
|
1080 |
header('location:' . $_SERVER['HTTP_REFERER']);
|
1081 |
exit;
|
1082 |
}
|
1083 |
-
|
1084 |
-
public static function testOtherArchives()
|
1085 |
-
{
|
1086 |
-
require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-archive.php";
|
1087 |
-
// test type archive
|
1088 |
-
$archive = new WPAdm_Archive(WPAdm_Core::getTmpDir() . '/test.zip');
|
1089 |
-
$archive->setRemovePath(rtrim( ABSPATH, '/' ) );
|
1090 |
-
$zip_test = $archive->zipArhive( array( WPAdm_Core::getTmpDir() . '/index.php' , WPAdm_Core::getTmpDir() . '/.htaccess' ) );
|
1091 |
-
if ( $zip_test ) {
|
1092 |
-
WPAdm_Running::setCommandResultData('test_zip_archive', true);
|
1093 |
-
WPAdm_Core::log( __('Testing of ZIP under shell was finished successfully', 'dropbox-backup') );
|
1094 |
-
}
|
1095 |
-
|
1096 |
-
$targz_archive = $archive->targzArchive( array( WPAdm_Core::getTmpDir() . '/index.php' , WPAdm_Core::getTmpDir() . '/.htaccess' ) );
|
1097 |
-
if ( $targz_archive ) {
|
1098 |
-
WPAdm_Running::setCommandResultData('test_targz_archive', true);
|
1099 |
-
WPAdm_Core::log( __('Testing of TarGz was finished successfully', 'dropbox-backup') );
|
1100 |
-
}
|
1101 |
-
}
|
1102 |
-
|
1103 |
-
static function getTypeBackup()
|
1104 |
-
{
|
1105 |
-
$dropbox_options = self::getSettings();
|
1106 |
-
if ( !isset( $dropbox_options['type_archive'] ) ) {
|
1107 |
-
$dropbox_options['type_archive'] = self::$type_archive;
|
1108 |
-
} else {
|
1109 |
-
$dropbox_options['type_archive'] = array_merge( self::$type_archive, $dropbox_options['type_archive'] );
|
1110 |
-
}
|
1111 |
-
return $dropbox_options['type_archive'];
|
1112 |
-
}
|
1113 |
}
|
1114 |
}
|
1115 |
|
1 |
<?php
|
|
|
|
|
|
|
|
|
2 |
if(@session_id() == '') {
|
3 |
@session_start();
|
4 |
}
|
26 |
add_action('admin_post_wpadm_download', array('wpadm_wp_full_backup_dropbox', 'download') );
|
27 |
add_action('init', array('wpadm_wp_full_backup_dropbox', 'init'), 10 );
|
28 |
|
29 |
+
add_action('admin_notices', array('wpadm_wp_full_backup_dropbox', 'notice'));
|
30 |
+
add_action('admin_notices', array('wpadm_wp_full_backup_dropbox', 'notice_stars'));
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
add_action('admin_post_hide_notice', array('wpadm_wp_full_backup_dropbox', 'hide_notice') );
|
32 |
add_action( 'admin_bar_menu', array('wpadm_wp_full_backup_dropbox', 'add_link_to_admin_bar') ,999 );
|
33 |
|
|
|
|
|
34 |
class wpadm_wp_full_backup_dropbox extends wpadm_class {
|
35 |
|
36 |
private static $default_optimization = 1;
|
37 |
|
38 |
const MIN_PASSWORD = 6;
|
39 |
|
40 |
+
private static $circle = 18;
|
41 |
|
42 |
private static $local_delete = false;
|
43 |
|
|
|
|
|
44 |
static function is_auth_user()
|
45 |
{
|
46 |
+
if (!is_user_logged_in()) {
|
47 |
exit;
|
48 |
}
|
49 |
$dropbox_options = self::getSettings();
|
50 |
if ( ( isset($dropbox_options['is_admin']) && $dropbox_options['is_admin'] == 1 ) || !isset($dropbox_options['is_admin']) ) {
|
51 |
+
if (!is_admin() || !is_super_admin()) {
|
|
|
|
|
|
|
52 |
exit;
|
53 |
}
|
54 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
}
|
56 |
|
57 |
+
static function stopBackup($local = false)
|
58 |
{
|
59 |
+
if (isset($_POST['type_backup'])) {
|
|
|
60 |
self::$local_delete = $local;
|
|
|
|
|
|
|
|
|
|
|
61 |
$setting_backup = array();
|
62 |
+
if ( $_POST['type_backup'] == 'local_backup' ) {
|
63 |
$setting_backup = WPAdm_Running::getCommand( 'local_backup' );
|
64 |
+
$_POST['backup-type'] = 'local';
|
65 |
+
} elseif ($_POST['type_backup'] == 'send-to-dropbox') {
|
66 |
$setting_backup = WPAdm_Running::getCommand( 'send-to-dropbox' );
|
67 |
+
$_POST['backup-type'] = 'dropbox';
|
68 |
}
|
69 |
// WPAdm_Running::setCommandResultData('stop_backup', $setting_backup);
|
70 |
$name = '';
|
78 |
$name );
|
79 |
$name = preg_replace("|\W|", "_", $name);
|
80 |
$name .= '-full-' . date("Y_m_d_H_i", $setting_backup['params']['time']);
|
81 |
+
$_POST['backup-name'] = $name;
|
82 |
+
if ($_POST['type_backup'] == 'send-to-dropbox') {
|
83 |
+
$_POST['backup-type'] = 'local';
|
84 |
+
//WPAdm_Running::setCommandResultData('stop_backup_post1', $_POST);
|
85 |
+
self::delete_backup();
|
86 |
+
$_POST['backup-type'] = 'dropbox';
|
87 |
}
|
88 |
+
//WPAdm_Running::setCommandResultData('stop_backup_post2', $_POST);
|
89 |
+
self::delete_backup();
|
90 |
}
|
91 |
}
|
92 |
WPAdm_Running::init_params_default();
|
93 |
+
WPAdm_Running::setCommandResultData('stop_process', array( 'stop' => 1, 'name' => $name, 'type' => $_POST['backup-type'] ) );
|
94 |
if ($local === false || empty($local)) {
|
95 |
header("Location: " . admin_url("admin.php?page=wpadm_wp_full_backup_dropbox"));
|
96 |
exit;
|
111 |
}
|
112 |
}
|
113 |
if ($show) {
|
114 |
+
$wp_admin_bar->add_node( array(
|
115 |
+
'id' => 'dropbox-backup',
|
116 |
+
'title' => 'Dropbox backup',
|
117 |
+
'href' => esc_url( admin_url("admin.php?page=wpadm_wp_full_backup_dropbox") ),
|
118 |
+
'meta' => array('class' => 'dropbox-image-toolbar')
|
119 |
+
));
|
|
|
|
|
120 |
}
|
121 |
|
122 |
}
|
163 |
if(!function_exists("wp_safe_remote_post")) {
|
164 |
include ABSPATH . "/http.php";
|
165 |
}
|
166 |
+
$res = wp_safe_remote_post(SERVER_URL_INDEX, array('username' => $_POST['username'], 'password' => $_POST['password'], 'plugin' => 'dropbox-backup'));
|
167 |
if (!Empty($res['body'])) {
|
168 |
$data_res = json_decode($res['body']);
|
169 |
if (isset($data_res['url'])) {
|
197 |
public static function setUserMail()
|
198 |
{
|
199 |
if (isset($_POST['email'])) {
|
200 |
+
$email = trim($_POST['email']);
|
201 |
$mail = get_option(PREFIX_BACKUP_ . "email");
|
202 |
if ($mail) {
|
203 |
add_option(PREFIX_BACKUP_ . "email", $email);
|
211 |
public static function saveSetting()
|
212 |
{
|
213 |
if (isset($_POST['is_admin']) || isset($_POST['is_optimization']) || isset($_POST['is_local_backup_delete'])
|
214 |
+
|| isset($_POST['is_repair']) || isset($_POST['time_error']) || isset($_POST['is_show_admin_bar'] ) || isset($_POST['backup_folder'] ) ) {
|
|
|
215 |
|
216 |
$dropbox_options = self::getSettings();
|
217 |
|
218 |
if (isset($_POST['time_error'])) {
|
219 |
+
$dropbox_options['time_error'] = (int)$_POST['time_error'];
|
220 |
}
|
221 |
if (isset($_POST['is_admin'])) {
|
222 |
+
$dropbox_options['is_admin'] = (int) $_POST['is_admin'];
|
223 |
}
|
224 |
if (isset($_POST['is_optimization'])) {
|
225 |
+
$dropbox_options['is_optimization'] = (int) $_POST['is_optimization'];
|
226 |
}
|
227 |
if (isset($_POST['is_local_backup_delete'])) {
|
228 |
+
$dropbox_options['is_local_backup_delete'] = (int) $_POST['is_local_backup_delete'];
|
229 |
}
|
230 |
if (isset($_POST['is_repair'])) {
|
231 |
+
$dropbox_options['is_repair'] = (int) $_POST['is_repair'];
|
232 |
}
|
233 |
if (isset($_POST['is_show_admin_bar'])) {
|
234 |
+
$dropbox_options['is_show_admin_bar'] = (int) $_POST['is_show_admin_bar'];
|
235 |
}
|
236 |
if (isset($_POST['backup_folder'])) {
|
237 |
+
$dropbox_options['backup_folder'] = rtrim( strip_tags( stripslashes( trim( $_POST['backup_folder'] ) ) ), '/' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
238 |
}
|
|
|
239 |
self::setSettings($dropbox_options);
|
240 |
}
|
241 |
}
|
266 |
} else {
|
267 |
$dropbox_options = $data;
|
268 |
}
|
269 |
+
|
270 |
update_option(PREFIX_BACKUP_ . 'dropbox-setting', base64_encode( serialize( $dropbox_options ) ) );
|
271 |
+
|
272 |
return $dropbox_options;
|
273 |
}
|
274 |
|
284 |
}
|
285 |
if (file_exists(WPAdm_Core::getTmpDir() . "/log.log")) {
|
286 |
file_put_contents(WPAdm_Core::getTmpDir() . "/log.log", '');
|
287 |
+
}
|
|
|
|
|
288 |
|
289 |
WPAdm_Process::clear();
|
290 |
|
297 |
}
|
298 |
WPAdm_Core::mkdir($backup_dir);
|
299 |
WPAdm_Running::init_params_default();
|
|
|
300 |
$res['result'] = 'success';
|
301 |
if (defined('DISABLE_WP_CRON')) {
|
302 |
if (DISABLE_WP_CRON === true || DISABLE_WP_CRON == 'true') {
|
313 |
$dropbox_options = self::getSettings();
|
314 |
$optimization = (isset($dropbox_options['is_optimization']) && $dropbox_options['is_optimization'] == 1) || (!isset($dropbox_options['is_optimization'])) ? 1 : 0;
|
315 |
$repair = (isset($dropbox_options['is_repair']) && $dropbox_options['is_repair'] == 1) ? 1 : 0;
|
316 |
+
$backup = new WPAdm_Core(array('method' => "local_backup", 'params' => array('optimize' => $optimization, 'repair' => $repair, 'limit' => 0, 'time' => @$_POST['time'], 'types' => array('db', 'files') )), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
|
317 |
if (WPAdm_Core::$cron === false) {
|
318 |
$res = $backup->getResult()->toArray();
|
319 |
$res['md5_data'] = md5( print_r($res, 1) );
|
322 |
$res['type'] = 'local';
|
323 |
$res['counts'] = count($res['data']);
|
324 |
} else {
|
325 |
+
set_transient('running_command', 'local_backup', 0);
|
326 |
$res['result'] = 'work';
|
327 |
$res['error'] = '';
|
328 |
$res['data'] = array();
|
382 |
'error' => $error_msg,
|
383 |
'data' => null,
|
384 |
'size' => 0 );
|
385 |
+
$_POST['type_backup'] = $_POST['type-backup'];
|
386 |
+
self::stopBackup(true);
|
387 |
}
|
388 |
$log_array['example'] = $circle;
|
389 |
} else {
|
397 |
$log = explode("\n", $log);
|
398 |
krsort($log);
|
399 |
$log_array['log'] = $log;
|
400 |
+
$data_result = WPAdm_Running::getCommandResultData($_POST['type-backup']);
|
|
|
401 |
if (!empty($data_result)) {
|
402 |
$log_array['data'] = $data_result;
|
403 |
set_transient('drb_running', 0, 1);
|
404 |
}
|
405 |
if (isset($_POST['type-backup2'])) {
|
406 |
+
$data_result = WPAdm_Running::getCommandResultData($_POST['type-backup2']);
|
|
|
407 |
if (!empty($data_result) && $data_result['result'] != 'success') {
|
408 |
$log_array['data'] = $data_result;
|
409 |
set_transient('drb_running', 0, 1);
|
424 |
if (file_exists(WPAdm_Core::getTmpDir() . "/logs2")) {
|
425 |
@unlink(WPAdm_Core::getTmpDir() . "/logs2");
|
426 |
}
|
427 |
+
$name_backup = isset($_POST['name']) ? trim($_POST['name']) : "";
|
428 |
$backup = new WPAdm_Core(array('method' => "local_restore", 'params' => array('types' => array('files', 'db'), 'name_backup' => $name_backup )), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
|
429 |
$res = $backup->getResult()->toArray();
|
430 |
@session_start();
|
450 |
$dropbox = new dropbox($dropbox_options['app_key'], $dropbox_options['app_secret'], $dropbox_options['auth_token_secret']);
|
451 |
if ($dropbox->isAuth()) {
|
452 |
WPAdm_Core::mkdir(DROPBOX_BACKUP_DIR_BACKUP);
|
453 |
+
$name_backup = isset($_POST['name']) ? trim($_POST['name']) : "";
|
454 |
$dir_backup = DROPBOX_BACKUP_DIR_BACKUP . "/$name_backup";
|
455 |
$error = WPAdm_Core::mkdir($dir_backup);
|
456 |
if (!empty($error)) {
|
494 |
public static function download()
|
495 |
{
|
496 |
if (isset($_REQUEST['backup'])) {
|
|
|
497 |
require_once DRBBACKUP_BASE_DIR . "/class-wpadm-core.php";
|
498 |
require_once DRBBACKUP_BASE_DIR . '/modules/pclzip.lib.php';
|
499 |
$backup = new WPAdm_Core(array('method' => "local"), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
|
500 |
+
$filename = $_REQUEST['backup'] . ".zip";
|
501 |
$file = WPAdm_Core::getTmpDir() . "/" . $filename;
|
502 |
if (file_exists($file)) {
|
503 |
@unlink($file);
|
504 |
}
|
505 |
$archive = new PclZip($file);
|
506 |
+
$dir_backup = DROPBOX_BACKUP_DIR_BACKUP . '/' . $_REQUEST['backup'];
|
507 |
|
508 |
$backups = array('data' => array(), 'md5' => '');
|
509 |
if (is_dir($dir_backup)) {
|
541 |
}
|
542 |
}
|
543 |
|
544 |
+
public static function delete_backup()
|
545 |
{
|
546 |
+
if (isset($_POST['backup-type']) ) {
|
547 |
+
if ($_POST['backup-type'] == 'local') {
|
548 |
+
require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-core.php";
|
549 |
+
$backup_dir = DROPBOX_BACKUP_DIR_BACKUP;
|
550 |
+
$dropbox_options = self::getSettings();
|
551 |
+
if ($dropbox_options) {
|
552 |
+
if (isset($dropbox_options['backup_folder']) && !empty($dropbox_options['backup_folder'])) {
|
553 |
+
$backup_dir = $dropbox_options['backup_folder'];
|
554 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
555 |
}
|
556 |
+
$dir = $backup_dir . '/' . $_POST['backup-name'] ;
|
557 |
+
$delete = false;
|
558 |
+
if (is_dir($dir)) {
|
559 |
+
WPAdm_Core::rmdir($dir);
|
560 |
+
$delete = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
561 |
}
|
562 |
+
$dir = ABSPATH . WPADM_DIR_NAME . '/' . $_POST['backup-name'] ;
|
563 |
+
if (is_dir($dir)) {
|
564 |
+
WPAdm_Core::rmdir($dir);
|
565 |
+
$delete = true;
|
566 |
+
}
|
567 |
+
$dir = WPADM_DIR_BACKUP . '/' . $_POST['backup-name'] ;
|
568 |
+
if (is_dir($dir)) {
|
569 |
+
WPAdm_Core::rmdir($dir);
|
570 |
+
$delete = true;
|
571 |
+
}
|
572 |
+
if ($delete) {
|
573 |
+
parent::setMessage( str_replace('%s', $_POST['backup-name'], __('Backup(%s) was deleted','dropbox-backup') ) );
|
574 |
+
}
|
575 |
+
} elseif ($_POST['backup-type'] == 'dropbox') {
|
576 |
+
require_once DRBBACKUP_BASE_DIR . "/modules/dropbox.class.php";
|
577 |
+
$dropbox_options = self::getSettings();
|
578 |
+
if ($dropbox_options && isset($dropbox_options['app_key'])) {
|
579 |
+
$dropbox = new dropbox($dropbox_options['app_key'], $dropbox_options['app_secret'], $dropbox_options['auth_token_secret']);
|
580 |
+
$folder_project = self::getNameProject();
|
581 |
+
$res = $dropbox->deleteFile("$folder_project/{$_POST['backup-name']}");
|
582 |
+
if ($res['is_deleted'] === true) {
|
583 |
+
parent::setMessage( str_replace('%s', $_POST['backup-name'], __('Backup(%s) was deleted','dropbox-backup') ) );
|
584 |
+
}
|
585 |
+
}
|
586 |
+
}
|
587 |
}
|
588 |
if (self::$local_delete === false || empty(self::$local_delete)) {
|
589 |
+
header("Location: " . admin_url("admin.php?page=wpadm_wp_full_backup_dropbox"));
|
590 |
}
|
591 |
}
|
592 |
|
606 |
require_once DRBBACKUP_BASE_DIR . "/modules/dropbox.class.php";
|
607 |
if (isset($_GET['app_key']) && isset($_GET['app_secret'])) {
|
608 |
if (empty($_GET['app_key']) && empty($_GET['app_secret'])) {
|
609 |
+
$_GET['app_key'] = WPADM_APP_KEY;
|
610 |
+
$_GET['app_secret'] = WPADM_APP_SECRET;
|
|
|
|
|
|
|
611 |
}
|
612 |
+
$dropbox = new dropbox($_GET['app_key'], $_GET['app_secret']);
|
613 |
+
$_SESSION['dropbox_key'] = $_GET['app_key'];
|
614 |
+
$_SESSION['dropbox_secret'] = $_GET['app_secret'];
|
615 |
$_SESSION['dropbox_request_token'] = $dropbox->getRequestToken();
|
616 |
echo '<script>window.location.href="' . $dropbox->generateAuthUrl( admin_url('admin-post.php?action=dropboxConnect') ) . '";</script>';
|
617 |
} elseif (isset($_GET['oauth_token']) && isset($_GET['uid'])) {
|
621 |
$dropbox_options['app_key'] = @$_SESSION['dropbox_key'] ;
|
622 |
$dropbox_options['app_secret'] = @$_SESSION['dropbox_secret'] ;
|
623 |
$dropbox_options['auth_token_secret'] = $access_token;
|
624 |
+
$dropbox_options['oauth_token'] = @$_GET['oauth_token'] ;
|
625 |
+
$dropbox_options['uid'] = @$_GET['uid'] ;
|
626 |
self::setSettings($dropbox_options);
|
627 |
echo '<script>
|
628 |
if(window.opener){
|
629 |
+
window.opener.connectDropbox(null, null, "'.htmlspecialchars($access_token['oauth_token_secret']).'", "'.htmlspecialchars($access_token['oauth_token']).'", "'.htmlspecialchars($access_token['uid']).'");window.close();
|
630 |
}else{
|
631 |
window.location.href="' . admin_url("admin.php?page=wpadm_wp_full_backup_dropbox") . '";
|
632 |
}
|
633 |
</script>';
|
634 |
echo '<script>window.close();</script>';exit;
|
635 |
} elseif (isset($_GET['not_approved'])) {
|
636 |
+
if( $_GET['not_approved'] == 'true' ){
|
637 |
echo '<script>window.close();</script>';exit;
|
638 |
}
|
639 |
} else {
|
655 |
}
|
656 |
if (file_exists(WPAdm_Core::getTmpDir() . "/log.log")) {
|
657 |
file_put_contents(WPAdm_Core::getTmpDir() . "/log.log", '');
|
658 |
+
}
|
|
|
|
|
659 |
|
660 |
WPAdm_Process::clear();
|
661 |
|
701 |
if ($send_to_dropbox) {
|
702 |
parent::$type = 'full';
|
703 |
WPAdm_Running::init_params_default();
|
|
|
704 |
WPAdm_Running::delCommandResultData("local_backup");
|
705 |
|
706 |
$dropbox_options = self::getSettings();
|
707 |
$optimization = (isset($dropbox_options['is_optimization']) && $dropbox_options['is_optimization'] == 1) || (!isset($dropbox_options['is_optimization'])) ? 1 : 0;
|
708 |
$repair = (isset($dropbox_options['is_repair']) && $dropbox_options['is_repair'] == 1) ? 1 : 0;
|
709 |
|
710 |
+
$backup_local = new WPAdm_Core(array('method' => "local_backup", 'params' => array('optimize' => $optimization, 'repair' => $repair, 'limit' => 0, 'time' => @$_POST['time'], 'types' => array('db', 'files') )), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
|
711 |
$res = array();
|
712 |
if (WPAdm_Core::$cron === false) {
|
713 |
$res = $backup->getResult()->toArray();
|
729 |
'token' => $dropbox_options['auth_token_secret'],
|
730 |
'dir' => isset($res['name']) ? $res['name'] : '',
|
731 |
'folder' => $folder_project),
|
732 |
+
'time' => @$_POST['time'],
|
733 |
'is_folder_set' => isset($dropbox_options['backup_folder']) && !empty($dropbox_options['backup_folder']),
|
734 |
)
|
735 |
),
|
744 |
}
|
745 |
WPAdm_Core::rmdir( $backup_dir . "/{$res['name']}");
|
746 |
} else {
|
747 |
+
set_transient('running_command', 'send-to-dropbox', 0);
|
748 |
$res['result'] = 'work';
|
749 |
$res['error'] = '';
|
750 |
$res['data'] = array();
|
775 |
{
|
776 |
require_once DRBBACKUP_BASE_DIR. "/modules/dropbox.class.php";
|
777 |
parent::$type = 'full';
|
|
|
778 |
$dropbox_options = self::getSettings();
|
779 |
$stop_precess = WPAdm_Running::getCommandResultData('stop_process');
|
780 |
$name_backup = isset($stop_precess['name']) ? $stop_precess['name'] : '' ;
|
797 |
$k = $data['data'][$i]['count'];
|
798 |
$data['data'][$i]['files'] = '[';
|
799 |
for($j = 0; $j < $k; $j++) {
|
800 |
+
if ( strpos($backup['items'][$j]['name'] , '.md5') !== false || strpos($backup['items'][$j]['name'] , '.zip') !== true ) {
|
801 |
if ( strpos($backup['items'][$j]['name'] , '.md5') !== false ) {
|
802 |
$not_all_upload = true;
|
803 |
}
|
809 |
}
|
810 |
}
|
811 |
}
|
812 |
+
if (isset($_GET['pay']) && $_GET['pay'] == 'success') {
|
813 |
if (!file_exists(WPAdm_Core::getTmpDir() . "/pay_success")) {
|
814 |
file_put_contents(WPAdm_Core::getTmpDir() . "/pay_success", 1);
|
815 |
parent::setMessage( 'Checkout was successfully' );
|
816 |
}
|
817 |
}
|
818 |
+
if (isset($_GET['pay']) && $_GET['pay'] == 'cancel') {
|
819 |
parent::setError( __('Checkout was canceled','dropbox-backup') );
|
820 |
}
|
821 |
$data_local = parent::read_backups();
|
890 |
$msg = parent::getMessage(true);
|
891 |
$default = self::$circle / 6; // 18 request for log files, one request every 10 seconds
|
892 |
$base_path = DRBBACKUP_BASE_DIR ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
893 |
ob_start();
|
894 |
require_once $base_path . DIRECTORY_SEPARATOR . "template" . DIRECTORY_SEPARATOR . "wpadm_show_backup.php";
|
895 |
echo ob_get_clean();
|
904 |
if (!is_admin() || !is_super_admin()) {
|
905 |
$show = false;
|
906 |
}
|
|
|
|
|
|
|
|
|
907 |
}
|
908 |
if ($show) {
|
909 |
$menu_position = '1.9998887771';
|
910 |
+
if(self::checkInstallWpadmPlugins()) {
|
911 |
$page = add_menu_page(
|
912 |
'WPAdm',
|
913 |
'WPAdm',
|
924 |
'read',
|
925 |
'wpadm_wp_full_backup_dropbox',
|
926 |
array('wpadm_wp_full_backup_dropbox', 'wpadm_show_backup')
|
927 |
+
);
|
928 |
+
} else {
|
929 |
$page = add_menu_page(
|
930 |
'Dropbox Full Backup',
|
931 |
'Dropbox Full Backup',
|
943 |
'read',
|
944 |
'wpadm_plugins',
|
945 |
'wpadm_plugins'
|
946 |
+
);
|
947 |
}
|
948 |
|
949 |
}
|
950 |
}
|
951 |
public static function notice()
|
952 |
+
{
|
|
|
953 |
if (!isset($_GET['page']) || ( isset($_GET['page']) && $_GET['page'] != 'wpadm_wp_full_backup_dropbox' ) ) {
|
954 |
$notice_file = DRBBACKUP_BASE_DIR . DIRECTORY_SEPARATOR . "template" . DIRECTORY_SEPARATOR . "notice.php";
|
955 |
if (!file_exists(WPAdm_Core::getTmpDir() . "/notice") && file_exists($notice_file)) {
|
962 |
public static function hide_notice()
|
963 |
{
|
964 |
if (isset($_GET['type'])) {
|
965 |
+
switch($_GET['type']) {
|
|
|
966 |
case 'preview' :
|
967 |
file_put_contents(WPAdm_Core::getTmpDir() . "/notice", 1);
|
968 |
break;
|
978 |
header('location:' . $_SERVER['HTTP_REFERER']);
|
979 |
exit;
|
980 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
981 |
}
|
982 |
}
|
983 |
|
methods/class-wpadm-method-backup-delete.php
CHANGED
@@ -1,8 +1,4 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
-
|
6 |
/**
|
7 |
* Delete backup
|
8 |
* Class WPAdm_Method_Backup_Delete
|
1 |
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Delete backup
|
4 |
* Class WPAdm_Method_Backup_Delete
|
methods/class-wpadm-method-backup-list.php
CHANGED
@@ -1,7 +1,4 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
/**
|
6 |
* Return a list of backups
|
7 |
* Class WPAdm_Method_Exec
|
1 |
<?php
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Return a list of backups
|
4 |
* Class WPAdm_Method_Exec
|
methods/class-wpadm-method-backup.php
CHANGED
@@ -1,8 +1,4 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
-
|
6 |
/**
|
7 |
* Бэкап сайта
|
8 |
* Class WPadm_Method_Backup
|
1 |
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Бэкап сайта
|
4 |
* Class WPadm_Method_Backup
|
methods/class-wpadm-method-full-backup-dropbox.php
CHANGED
@@ -1,7 +1,4 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
/**
|
6 |
* Creates a full backup of the site
|
7 |
* Class WPadm_Method_Backup_Dropbox
|
@@ -228,13 +225,13 @@ if (!class_exists('WPadm_Method_Full_Backup_Dropbox')) {
|
|
228 |
$archive = new WPAdm_Archive($af, $to_file . '.md5');
|
229 |
$archive->setRemovePath( ABSPATH );
|
230 |
}
|
231 |
-
|
232 |
if ( defined('PCLZIP_SEPARATOR') ) {
|
233 |
$files_str = implode( PCLZIP_SEPARATOR , $files);
|
234 |
} else {
|
235 |
$files_str = implode( ',' , $files); // default SEPARATOR in pclzip
|
236 |
}
|
237 |
-
|
238 |
$res = $archive->add($files_str);
|
239 |
if ($res) {
|
240 |
|
@@ -468,9 +465,6 @@ if (!class_exists('WPadm_Method_Full_Backup_Dropbox')) {
|
|
468 |
WPAdm_Core::log('Skip dir(cache) ' . $directory);
|
469 |
return array();
|
470 |
}
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
if(strpos($directory, DROPBOX_BACKUP_DIR_NAME) !== false) {
|
475 |
return array();
|
476 |
}
|
1 |
<?php
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Creates a full backup of the site
|
4 |
* Class WPadm_Method_Backup_Dropbox
|
225 |
$archive = new WPAdm_Archive($af, $to_file . '.md5');
|
226 |
$archive->setRemovePath( ABSPATH );
|
227 |
}
|
228 |
+
|
229 |
if ( defined('PCLZIP_SEPARATOR') ) {
|
230 |
$files_str = implode( PCLZIP_SEPARATOR , $files);
|
231 |
} else {
|
232 |
$files_str = implode( ',' , $files); // default SEPARATOR in pclzip
|
233 |
}
|
234 |
+
|
235 |
$res = $archive->add($files_str);
|
236 |
if ($res) {
|
237 |
|
465 |
WPAdm_Core::log('Skip dir(cache) ' . $directory);
|
466 |
return array();
|
467 |
}
|
|
|
|
|
|
|
468 |
if(strpos($directory, DROPBOX_BACKUP_DIR_NAME) !== false) {
|
469 |
return array();
|
470 |
}
|
methods/class-wpadm-method-local-backup.php
CHANGED
@@ -1,14 +1,10 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
if (!class_exists('WPAdm_Method_Local_Backup')) {
|
6 |
class WPAdm_Method_Local_Backup extends WPAdm_Method_Class {
|
7 |
|
8 |
private $start = true;
|
9 |
|
10 |
-
private $tar_gz = false;
|
11 |
-
|
12 |
public function __construct($params)
|
13 |
{
|
14 |
|
@@ -159,7 +155,7 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
|
|
159 |
$opt_db = WPAdm_Running::getCommandResultData('db');
|
160 |
if (!isset($opt_db['optimize'])) {
|
161 |
if ( WPAdm_Running::is_stop() ) {
|
162 |
-
|
163 |
if (!class_exists('WPAdm_Mysqldump')) {
|
164 |
require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
|
165 |
}
|
@@ -223,7 +219,6 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
|
|
223 |
$command_files_list = WPAdm_Running::getCommandResultData('files');
|
224 |
if (in_array('files', $this->params['types']) && empty($command_files_list) ) {
|
225 |
$files = $this->createListFilesForArchive();
|
226 |
-
$files = explode('<!>', utf8_encode( implode( '<!>', $files ) ) );
|
227 |
WPAdm_Running::setCommandResultData('files', $files);
|
228 |
} else {
|
229 |
$files = $command_files_list;
|
@@ -247,89 +242,58 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
|
|
247 |
$files2[0] = array();
|
248 |
$i = 0;
|
249 |
$size = 0;
|
250 |
-
$chunk_size = 170000; //~170kbyte
|
251 |
-
$targz = WPAdm_Running::getCommandResultData('test_targz_archive');
|
252 |
-
$files_count = 0;
|
253 |
-
if (!empty($targz)) {
|
254 |
-
$chunk_size = 1572864; // ~ 1.5 Mbyte
|
255 |
-
}
|
256 |
-
$size_part = array();
|
257 |
foreach($files as $f) {
|
258 |
-
if ($size >
|
259 |
-
$size_part[$i] = $size;
|
260 |
$i ++;
|
261 |
$size = 0;
|
262 |
$files2[$i] = array();
|
263 |
}
|
264 |
$f_size =(int)@filesize($f);
|
265 |
-
$permission_file = wpadm_class::perm($f);
|
266 |
-
if ( ! version_compare($permission_file, '0400', '>=') ) {
|
267 |
-
WPAdm_Core::log('Skip file ' . $f . ' Size ' . WPADM_getSize($f_size) . " (" . $permission_file . ")" );
|
268 |
-
continue;
|
269 |
-
}
|
270 |
if ($f_size == 0 || $f_size > 1000000) {
|
271 |
-
WPAdm_Core::log('File ' . $f . ' Size ' .
|
272 |
}
|
273 |
$size += $f_size;
|
274 |
-
$files2[$i][] =
|
275 |
-
$files_count ++;
|
276 |
}
|
277 |
WPAdm_Running::setCommandResultData('files2', $files2);
|
278 |
-
WPAdm_Running::setCommandResultData('files2_count', $files_count );
|
279 |
}
|
280 |
} else {
|
281 |
return true;
|
282 |
}
|
283 |
-
$files_count = WPAdm_Running::getCommandResultData('files2_count', $files_count );
|
284 |
-
if (!empty($files_count) && $files_count != count($files) ) {
|
285 |
-
WPAdm_Process::init('archiving', $files_count );
|
286 |
-
}
|
287 |
|
288 |
-
|
|
|
|
|
289 |
if ( !WPAdm_Running::getCommandResult('archive') ) {
|
290 |
if ( WPAdm_Running::is_stop() ) {
|
291 |
-
WPAdm_Core::log( __('Backup of files was started','dropbox-backup') );
|
292 |
WPAdm_Running::setCommandResult('archive');
|
293 |
$files_archive = WPAdm_Running::getCommandResultData('archive');
|
294 |
require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-archive.php';
|
295 |
$to_file = $this->dir . '/' . $this->name;
|
296 |
-
$processing_archive = 0;
|
297 |
foreach($files2 as $key => $files) {
|
298 |
-
if (!WPAdm_Running::toEndWork( time()) ) {
|
299 |
-
// 2 steps of archive less 3MB
|
300 |
-
if ($size_part[$key] > 3145728 || $processing_archive >= 2) { // ~ 3 MB
|
301 |
-
return true;
|
302 |
-
}
|
303 |
-
$processing_archive ++;
|
304 |
-
}
|
305 |
$md5 = md5( print_r( $files, 1 ) );
|
306 |
if ( !isset($files_archive[$md5]) ) {
|
307 |
if ( WPAdm_Running::is_stop() ) {
|
308 |
-
$
|
309 |
-
$archive = new WPAdm_Archive($
|
310 |
$archive->setRemovePath(ABSPATH);
|
311 |
-
if ( !file_exists( $
|
312 |
-
WPAdm_Core::log(
|
313 |
}
|
314 |
}
|
315 |
-
$
|
316 |
-
|
317 |
-
if ( ( !empty($targz) && $targz === true ) || ( file_exists($af1) && filesize($af1) > 900000 ) ) {
|
318 |
if ( WPAdm_Running::is_stop() ) {
|
319 |
-
$
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
WPAdm_Core::log(__('Create part ','dropbox-backup') . basename( $af2 ) );
|
324 |
-
}
|
325 |
-
$archive = new WPAdm_Archive($af2, $to_file . '.md5');
|
326 |
-
$archive->setRemovePath( ABSPATH );
|
327 |
}
|
|
|
|
|
328 |
} else {
|
329 |
return true;
|
330 |
}
|
331 |
}
|
332 |
-
|
333 |
if ( WPAdm_Running::is_stop() ) {
|
334 |
$md5 = md5( print_r( $files, 1 ) );
|
335 |
if ( defined('PCLZIP_SEPARATOR') ) {
|
@@ -348,13 +312,9 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
|
|
348 |
WPAdm_Running::setCommandResultData('archive', $files_archive);
|
349 |
WPAdm_Process::setInc( 'archiving', count($files) );
|
350 |
} else {
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
$this->result->setError( $archive->error );
|
355 |
-
$this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
|
356 |
-
return $this->result;
|
357 |
-
}
|
358 |
}
|
359 |
} else {
|
360 |
return true;
|
@@ -364,10 +324,19 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
|
|
364 |
return true;
|
365 |
}
|
366 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
367 |
}
|
368 |
}
|
369 |
-
|
370 |
-
WPAdm_Core::log( __('
|
371 |
WPAdm_Running::setCommandResult('archive', true);
|
372 |
|
373 |
}
|
@@ -387,8 +356,9 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
|
|
387 |
$this->result->setValue('time', $this->time);
|
388 |
$this->result->setValue('type', 'local');
|
389 |
$this->result->setValue('counts', count($urls) );
|
390 |
-
$size =
|
391 |
-
$
|
|
|
392 |
WPAdm_Core::log($log);
|
393 |
|
394 |
$remove_from_server = 0;
|
@@ -450,24 +420,13 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
|
|
450 |
public function createListFilesForArchive()
|
451 |
{
|
452 |
$inludes = get_option(PREFIX_BACKUP_ . "plus-path");
|
453 |
-
if($inludes !== false) {
|
454 |
-
$f = explode(',',
|
455 |
$files = array();
|
456 |
$n = count($f);
|
457 |
-
$tmp_folder = '';
|
458 |
for($i = 0; $i < $n; $i++) {
|
459 |
-
if (!empty($tmp_folder) && strpos($f[$i], $tmp_folder) === false) {
|
460 |
-
$fi = $this->directoryToArray(ABSPATH . $tmp_folder, true );
|
461 |
-
$files = array_merge($files, $fi);
|
462 |
-
$tmp_folder = '';
|
463 |
-
} elseif(!empty($tmp_folder) && strpos($f[$i], $tmp_folder) !== false) {
|
464 |
-
$tmp_folder = '';
|
465 |
-
}
|
466 |
-
|
467 |
if( is_dir( ABSPATH . $f[$i] ) ) {
|
468 |
-
|
469 |
-
$tmp_folder = $f[$i];
|
470 |
-
//$files = array_merge($files, $fi);
|
471 |
} elseif (file_exists(ABSPATH . $f[$i])) {
|
472 |
$files[$i] = ABSPATH . $f[$i];
|
473 |
}
|
@@ -573,30 +532,9 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
|
|
573 |
$files = array_merge($files, $this->directoryToArray($folder, true));
|
574 |
}
|
575 |
}
|
576 |
-
|
577 |
-
$files = array_values( array_unique($files) );
|
578 |
-
|
579 |
return $files;
|
580 |
}
|
581 |
|
582 |
-
public function tryToUtf8( $string, $strip = false )
|
583 |
-
{
|
584 |
-
$string = (string) $string;
|
585 |
-
|
586 |
-
if ( 0 === strlen( $string ) ) {
|
587 |
-
return '';
|
588 |
-
}
|
589 |
-
// preg match invalid UTF8
|
590 |
-
if ( 1 === @preg_match( '/^./us', $string ) ) {
|
591 |
-
return $string;
|
592 |
-
}
|
593 |
-
|
594 |
-
if ( $strip && function_exists( 'iconv' ) ) {
|
595 |
-
return iconv( 'utf-8', 'utf-8', $string );
|
596 |
-
}
|
597 |
-
|
598 |
-
return $string;
|
599 |
-
}
|
600 |
|
601 |
private function directoryToArray($directory, $recursive) {
|
602 |
$array_items = array();
|
@@ -620,7 +558,6 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
|
|
620 |
} else {
|
621 |
$d1 = strtolower($tmp[0]);
|
622 |
}
|
623 |
-
$base_dir = $tmp[0];
|
624 |
unset($tmp[0]);
|
625 |
if (function_exists('mb_strtolower')) {
|
626 |
$d2 = mb_strtolower(implode('/', $tmp));
|
@@ -631,26 +568,14 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
|
|
631 |
if (stripos($d2, 'cache') !== false ) {
|
632 |
WPAdm_Core::log( __('Skip of Cache-Folder ','dropbox-backup') . $directory);
|
633 |
return array();
|
634 |
-
}
|
635 |
-
|
636 |
if (strpos($d2, 'cache') !== false && isset($tmp[0]) && !in_array($tmp[0], array('plugins', 'themes')) ) {
|
637 |
WPAdm_Core::log(__('Skip of Cache-Folder ','dropbox-backup') . $directory);
|
638 |
return array();
|
639 |
}
|
640 |
-
|
641 |
-
if (!empty($d2) && isset( $base_dir ) && BackupsFoldersExclude( basename( $d2 ), $base_dir ) ) {
|
642 |
-
WPAdm_Core::log( sprintf( __('Skip backup folder of another backup plugin "%s" ','dropbox-backup'), basename( $d2 ) ) );
|
643 |
-
return array();
|
644 |
-
}
|
645 |
-
|
646 |
if(strpos($directory, 'wpadm_backups') !== false || strpos($directory, 'Dropbox_Backup') !== false) {
|
647 |
return array();
|
648 |
}
|
649 |
-
|
650 |
-
if (stripos($d2, 'backup') !== false ) {
|
651 |
-
WPAdm_Core::log( __('Skip of Backup-Folder ','dropbox-backup') . $directory);
|
652 |
-
return array();
|
653 |
-
}
|
654 |
|
655 |
if ($handle = opendir($directory)) {
|
656 |
while (false !== ($file = readdir($handle))) {
|
@@ -678,7 +603,7 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
|
|
678 |
$f = str_replace(ABSPATH, '', $ff);
|
679 |
// skip "minus" dirs
|
680 |
if (!in_array($f, $minus_path)) {
|
681 |
-
$array_items[] = $
|
682 |
} else {
|
683 |
WPAdm_Core::log( __('Skip of Folder ','dropbox-backup') . $ff);
|
684 |
}
|
@@ -724,43 +649,21 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
|
|
724 |
private function getArchiveName($name)
|
725 |
{
|
726 |
//WPAdm_Core::log("{$name}-*.zip");
|
727 |
-
$
|
728 |
-
if (!empty($targz) && $targz === true ) {
|
729 |
-
$archives = glob("{$name}-*.tar.gz");
|
730 |
-
} else {
|
731 |
-
$archives = glob("{$name}-*.zip");
|
732 |
-
}
|
733 |
-
|
734 |
if (empty($archives)) {
|
735 |
-
|
736 |
-
return "{$name}-1.tar.gz";
|
737 |
-
} else {
|
738 |
-
return "{$name}-1.zip";
|
739 |
-
}
|
740 |
}
|
741 |
$n = count($archives);
|
742 |
-
|
743 |
-
$f = "{$name}-{$n}.tar.gz";
|
744 |
-
} else {
|
745 |
-
$f = "{$name}-{$n}.zip";
|
746 |
-
}
|
747 |
return $f;
|
748 |
}
|
749 |
|
750 |
private function getNextArchiveName($name)
|
751 |
{
|
752 |
-
|
753 |
-
|
754 |
-
$archives = glob("{$name}-*.tar.gz");
|
755 |
-
} else {
|
756 |
-
$archives = glob("{$name}-*.zip");
|
757 |
-
}
|
758 |
$n = 1 + count($archives);
|
759 |
-
|
760 |
-
$a = "{$name}-{$n}.tar.gz";
|
761 |
-
} else {
|
762 |
-
$a = "{$name}-{$n}.zip";
|
763 |
-
}
|
764 |
//WPAdm_Core::log($a);
|
765 |
return $a;
|
766 |
}
|
1 |
<?php
|
2 |
|
|
|
|
|
3 |
if (!class_exists('WPAdm_Method_Local_Backup')) {
|
4 |
class WPAdm_Method_Local_Backup extends WPAdm_Method_Class {
|
5 |
|
6 |
private $start = true;
|
7 |
|
|
|
|
|
8 |
public function __construct($params)
|
9 |
{
|
10 |
|
155 |
$opt_db = WPAdm_Running::getCommandResultData('db');
|
156 |
if (!isset($opt_db['optimize'])) {
|
157 |
if ( WPAdm_Running::is_stop() ) {
|
158 |
+
WPAdm_Core::log(__('Optimize Database Tables','dropbox-backup'));
|
159 |
if (!class_exists('WPAdm_Mysqldump')) {
|
160 |
require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
|
161 |
}
|
219 |
$command_files_list = WPAdm_Running::getCommandResultData('files');
|
220 |
if (in_array('files', $this->params['types']) && empty($command_files_list) ) {
|
221 |
$files = $this->createListFilesForArchive();
|
|
|
222 |
WPAdm_Running::setCommandResultData('files', $files);
|
223 |
} else {
|
224 |
$files = $command_files_list;
|
242 |
$files2[0] = array();
|
243 |
$i = 0;
|
244 |
$size = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
245 |
foreach($files as $f) {
|
246 |
+
if ($size > 170000) {//~170kbyte
|
|
|
247 |
$i ++;
|
248 |
$size = 0;
|
249 |
$files2[$i] = array();
|
250 |
}
|
251 |
$f_size =(int)@filesize($f);
|
|
|
|
|
|
|
|
|
|
|
252 |
if ($f_size == 0 || $f_size > 1000000) {
|
253 |
+
WPAdm_Core::log('File ' . $f . ' Size ' . $f_size);
|
254 |
}
|
255 |
$size += $f_size;
|
256 |
+
$files2[$i][] = $f;
|
|
|
257 |
}
|
258 |
WPAdm_Running::setCommandResultData('files2', $files2);
|
|
|
259 |
}
|
260 |
} else {
|
261 |
return true;
|
262 |
}
|
|
|
|
|
|
|
|
|
263 |
|
264 |
+
|
265 |
+
WPAdm_Core::log(__('List of Backup-Files was successfully created','dropbox-backup') );
|
266 |
+
//$this->queue->clear();
|
267 |
if ( !WPAdm_Running::getCommandResult('archive') ) {
|
268 |
if ( WPAdm_Running::is_stop() ) {
|
|
|
269 |
WPAdm_Running::setCommandResult('archive');
|
270 |
$files_archive = WPAdm_Running::getCommandResultData('archive');
|
271 |
require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-archive.php';
|
272 |
$to_file = $this->dir . '/' . $this->name;
|
|
|
273 |
foreach($files2 as $key => $files) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
$md5 = md5( print_r( $files, 1 ) );
|
275 |
if ( !isset($files_archive[$md5]) ) {
|
276 |
if ( WPAdm_Running::is_stop() ) {
|
277 |
+
$af = $this->getArchiveName($to_file);
|
278 |
+
$archive = new WPAdm_Archive($af, $to_file . '.md5');
|
279 |
$archive->setRemovePath(ABSPATH);
|
280 |
+
if ( !file_exists( $af ) ) {
|
281 |
+
WPAdm_Core::log(__('Create part ','dropbox-backup') . basename( $af ) );
|
282 |
}
|
283 |
}
|
284 |
+
if (file_exists($af) && filesize($af) > 900000) {
|
|
|
|
|
285 |
if ( WPAdm_Running::is_stop() ) {
|
286 |
+
$af = $this->getNextArchiveName($to_file);
|
287 |
+
unset($archive);
|
288 |
+
if ( !file_exists( $af ) ) {
|
289 |
+
WPAdm_Core::log(__('Create part ','dropbox-backup') . basename( $af ) );
|
|
|
|
|
|
|
|
|
290 |
}
|
291 |
+
$archive = new WPAdm_Archive($af, $to_file . '.md5');
|
292 |
+
$archive->setRemovePath( ABSPATH );
|
293 |
} else {
|
294 |
return true;
|
295 |
}
|
296 |
}
|
|
|
297 |
if ( WPAdm_Running::is_stop() ) {
|
298 |
$md5 = md5( print_r( $files, 1 ) );
|
299 |
if ( defined('PCLZIP_SEPARATOR') ) {
|
312 |
WPAdm_Running::setCommandResultData('archive', $files_archive);
|
313 |
WPAdm_Process::setInc( 'archiving', count($files) );
|
314 |
} else {
|
315 |
+
$this->result->setError( $archive->error );
|
316 |
+
$this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
|
317 |
+
return $this->result;
|
|
|
|
|
|
|
|
|
318 |
}
|
319 |
} else {
|
320 |
return true;
|
324 |
return true;
|
325 |
}
|
326 |
}
|
327 |
+
/*$commandContext = new WPAdm_Command_Context();
|
328 |
+
$commandContext ->addParam('command', 'archive')
|
329 |
+
->addParam('files', $files)
|
330 |
+
->addParam('to_file', $this->dir . '/' . $this->name)
|
331 |
+
->addParam('max_file_size', 900000)
|
332 |
+
->addParam('remove_path', ABSPATH);
|
333 |
+
|
334 |
+
$this->queue->add($commandContext);
|
335 |
+
unset($commandContext); */
|
336 |
}
|
337 |
}
|
338 |
+
WPAdm_Core::log( __('Backup of Files was started','dropbox-backup') );
|
339 |
+
WPAdm_Core::log( __('End of File Backup','dropbox-backup') );
|
340 |
WPAdm_Running::setCommandResult('archive', true);
|
341 |
|
342 |
}
|
356 |
$this->result->setValue('time', $this->time);
|
357 |
$this->result->setValue('type', 'local');
|
358 |
$this->result->setValue('counts', count($urls) );
|
359 |
+
$size = $totalSize / 1024 / 1024; /// MByte
|
360 |
+
$size = round($size, 2);
|
361 |
+
$log = str_replace("%s", $size , __('Backup Size %s Mb','dropbox-backup') ) ;
|
362 |
WPAdm_Core::log($log);
|
363 |
|
364 |
$remove_from_server = 0;
|
420 |
public function createListFilesForArchive()
|
421 |
{
|
422 |
$inludes = get_option(PREFIX_BACKUP_ . "plus-path");
|
423 |
+
if($inludes !== false) {
|
424 |
+
$f = explode(',', $inludes);
|
425 |
$files = array();
|
426 |
$n = count($f);
|
|
|
427 |
for($i = 0; $i < $n; $i++) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
428 |
if( is_dir( ABSPATH . $f[$i] ) ) {
|
429 |
+
$files = array_merge($files, $this->directoryToArray(ABSPATH . $f[$i], true));
|
|
|
|
|
430 |
} elseif (file_exists(ABSPATH . $f[$i])) {
|
431 |
$files[$i] = ABSPATH . $f[$i];
|
432 |
}
|
532 |
$files = array_merge($files, $this->directoryToArray($folder, true));
|
533 |
}
|
534 |
}
|
|
|
|
|
|
|
535 |
return $files;
|
536 |
}
|
537 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
538 |
|
539 |
private function directoryToArray($directory, $recursive) {
|
540 |
$array_items = array();
|
558 |
} else {
|
559 |
$d1 = strtolower($tmp[0]);
|
560 |
}
|
|
|
561 |
unset($tmp[0]);
|
562 |
if (function_exists('mb_strtolower')) {
|
563 |
$d2 = mb_strtolower(implode('/', $tmp));
|
568 |
if (stripos($d2, 'cache') !== false ) {
|
569 |
WPAdm_Core::log( __('Skip of Cache-Folder ','dropbox-backup') . $directory);
|
570 |
return array();
|
571 |
+
}
|
|
|
572 |
if (strpos($d2, 'cache') !== false && isset($tmp[0]) && !in_array($tmp[0], array('plugins', 'themes')) ) {
|
573 |
WPAdm_Core::log(__('Skip of Cache-Folder ','dropbox-backup') . $directory);
|
574 |
return array();
|
575 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
576 |
if(strpos($directory, 'wpadm_backups') !== false || strpos($directory, 'Dropbox_Backup') !== false) {
|
577 |
return array();
|
578 |
}
|
|
|
|
|
|
|
|
|
|
|
579 |
|
580 |
if ($handle = opendir($directory)) {
|
581 |
while (false !== ($file = readdir($handle))) {
|
603 |
$f = str_replace(ABSPATH, '', $ff);
|
604 |
// skip "minus" dirs
|
605 |
if (!in_array($f, $minus_path)) {
|
606 |
+
$array_items[] = $ff;
|
607 |
} else {
|
608 |
WPAdm_Core::log( __('Skip of Folder ','dropbox-backup') . $ff);
|
609 |
}
|
649 |
private function getArchiveName($name)
|
650 |
{
|
651 |
//WPAdm_Core::log("{$name}-*.zip");
|
652 |
+
$archives = glob("{$name}-*.zip");
|
|
|
|
|
|
|
|
|
|
|
|
|
653 |
if (empty($archives)) {
|
654 |
+
return "{$name}-1.zip";
|
|
|
|
|
|
|
|
|
655 |
}
|
656 |
$n = count($archives);
|
657 |
+
$f = "{$name}-{$n}.zip";
|
|
|
|
|
|
|
|
|
658 |
return $f;
|
659 |
}
|
660 |
|
661 |
private function getNextArchiveName($name)
|
662 |
{
|
663 |
+
//WPAdm_Core::log("{$name}-*.zip");
|
664 |
+
$archives = glob("{$name}-*.zip");
|
|
|
|
|
|
|
|
|
665 |
$n = 1 + count($archives);
|
666 |
+
$a = "{$name}-{$n}.zip";
|
|
|
|
|
|
|
|
|
667 |
//WPAdm_Core::log($a);
|
668 |
return $a;
|
669 |
}
|
methods/class-wpadm-method-local-restore.php
CHANGED
@@ -1,8 +1,4 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
-
|
6 |
/**
|
7 |
* Class WPAdm_Method_Exec
|
8 |
*/
|
1 |
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Class WPAdm_Method_Exec
|
4 |
*/
|
methods/class-wpadm-method-ping.php
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
if (!class_exists('WPAdm_Method_Ping')) {
|
6 |
class WPAdm_Method_Ping extends WPAdm_Method_Class {
|
7 |
public function getResult()
|
1 |
<?php
|
2 |
|
|
|
|
|
3 |
if (!class_exists('WPAdm_Method_Ping')) {
|
4 |
class WPAdm_Method_Ping extends WPAdm_Method_Class {
|
5 |
public function getResult()
|
methods/class-wpadm-method-queue-controller.php
CHANGED
@@ -1,8 +1,6 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
/**
|
|
|
6 |
* Class WPAdm_Method_Exec
|
7 |
*/
|
8 |
if (!class_exists('WPAdm_Method_Queue_Controller')) {
|
1 |
<?php
|
|
|
|
|
|
|
2 |
/**
|
3 |
+
* Выполнение очереди
|
4 |
* Class WPAdm_Method_Exec
|
5 |
*/
|
6 |
if (!class_exists('WPAdm_Method_Queue_Controller')) {
|
methods/class-wpadm-method-reconnect.php
CHANGED
@@ -1,8 +1,5 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
5 |
-
|
6 |
if (!class_exists('WPAdm_Method_Reconnect')) {
|
7 |
class WPAdm_Method_Reconnect extends WPAdm_Method_Class {
|
8 |
public function getResult()
|
1 |
<?php
|
2 |
|
|
|
|
|
|
|
3 |
if (!class_exists('WPAdm_Method_Reconnect')) {
|
4 |
class WPAdm_Method_Reconnect extends WPAdm_Method_Class {
|
5 |
public function getResult()
|
methods/class-wpadm-method-send-to-dropbox.php
CHANGED
@@ -1,10 +1,6 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
5 |
-
|
6 |
-
|
7 |
/**
|
|
|
8 |
* Class WPadm_Method_Send_To_Dropbox
|
9 |
*/
|
10 |
if (!class_exists('WPadm_Method_Send_To_Dropbox')) {
|
@@ -201,14 +197,11 @@ if (!class_exists('WPadm_Method_Send_To_Dropbox')) {
|
|
201 |
if ( WPAdm_Running::is_stop() ) {
|
202 |
$delete_file = $dropbox->deleteFile($folder_project . $dir . '/' . $file_name);
|
203 |
if (isset($delete_file['error'])) {
|
204 |
-
|
205 |
-
|
206 |
-
WPAdm_Core::log( __('File in Dropbox Cloud: ' ,'dropbox-backup') . '"' . $delete_file['text'] . '"' );
|
207 |
-
|
208 |
-
WPAdm_Core::log( __('Try send file again' ,'dropbox-backup') . '(' . $file_name . ')' );
|
209 |
}
|
210 |
$data_error_command = WPAdm_Running::getCommandResultData('errors_sending');
|
211 |
-
if (isset($
|
212 |
$data_error_command[$fromFile]['count'] += 1;
|
213 |
} else {
|
214 |
$data_error_command[$fromFile] = array();
|
@@ -242,7 +235,7 @@ if (!class_exists('WPadm_Method_Send_To_Dropbox')) {
|
|
242 |
$res = $dropbox->uploadFile($fromFile, $toFile, true);
|
243 |
}
|
244 |
if (isset($res['error']) && isset($res['text']) && $res['error'] == 1) {
|
245 |
-
$this->setError( __('Dropbox returned an error during file sending: ' ,'dropbox-backup') . '"' . $res['text'] . '"
|
246 |
return false;
|
247 |
}
|
248 |
if ( WPAdm_Running::is_stop() ) {
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
+
* Бэкап сайта
|
4 |
* Class WPadm_Method_Send_To_Dropbox
|
5 |
*/
|
6 |
if (!class_exists('WPadm_Method_Send_To_Dropbox')) {
|
197 |
if ( WPAdm_Running::is_stop() ) {
|
198 |
$delete_file = $dropbox->deleteFile($folder_project . $dir . '/' . $file_name);
|
199 |
if (isset($delete_file['error'])) {
|
200 |
+
$this->setError( __('Dropbox returned an error during file sending: ' ,'dropbox-backup') . '"' . $delete_file['text'] . '"');
|
201 |
+
return false;
|
|
|
|
|
|
|
202 |
}
|
203 |
$data_error_command = WPAdm_Running::getCommandResultData('errors_sending');
|
204 |
+
if (isset($data_command[$fromFile])) {
|
205 |
$data_error_command[$fromFile]['count'] += 1;
|
206 |
} else {
|
207 |
$data_error_command[$fromFile] = array();
|
235 |
$res = $dropbox->uploadFile($fromFile, $toFile, true);
|
236 |
}
|
237 |
if (isset($res['error']) && isset($res['text']) && $res['error'] == 1) {
|
238 |
+
$this->setError( __('Dropbox returned an error during file sending: ' ,'dropbox-backup') . '"' . $res['text'] . '"');
|
239 |
return false;
|
240 |
}
|
241 |
if ( WPAdm_Running::is_stop() ) {
|
methods/class-wpadm-method-update.php
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
if (!class_exists('WPAdm_Method_Update')) {
|
6 |
class WPAdm_Method_Update extends WPAdm_Method_Class {
|
7 |
|
1 |
<?php
|
2 |
|
|
|
|
|
3 |
if (!class_exists('WPAdm_Method_Update')) {
|
4 |
class WPAdm_Method_Update extends WPAdm_Method_Class {
|
5 |
|
modules/archive.php
DELETED
@@ -1,784 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/*--------------------------------------------------
|
3 |
-
| TAR/GZIP/BZIP2/ZIP ARCHIVE CLASSES 2.1
|
4 |
-
| By Devin Doucette
|
5 |
-
| Copyright (c) 2005 Devin Doucette
|
6 |
-
| Email: darksnoopy@shaw.ca
|
7 |
-
+--------------------------------------------------
|
8 |
-
| Email bugs/suggestions to darksnoopy@shaw.ca
|
9 |
-
+--------------------------------------------------
|
10 |
-
| This script has been created and released under
|
11 |
-
| the GNU GPL and is free to use and redistribute
|
12 |
-
| only if this copyright statement is not removed
|
13 |
-
+--------------------------------------------------*/
|
14 |
-
|
15 |
-
class wpadm_archive_class
|
16 |
-
{
|
17 |
-
function __construct($name = '')
|
18 |
-
{
|
19 |
-
$this->options = array (
|
20 |
-
'basedir' => ".",
|
21 |
-
'name' => $name,
|
22 |
-
'prepend' => "",
|
23 |
-
'delete_path_in_archive' => "",
|
24 |
-
'inmemory' => 0,
|
25 |
-
'overwrite' => 0,
|
26 |
-
'recurse' => 1,
|
27 |
-
'storepaths' => 1,
|
28 |
-
'followlinks' => 0,
|
29 |
-
'level' => 3,
|
30 |
-
'method' => 1,
|
31 |
-
'sfx' => "",
|
32 |
-
'type' => "",
|
33 |
-
'comment' => ""
|
34 |
-
);
|
35 |
-
$this->files = array ();
|
36 |
-
$this->exclude = array ();
|
37 |
-
$this->include = array ();
|
38 |
-
$this->storeonly = array ();
|
39 |
-
$this->error = array ();
|
40 |
-
$this->warning = array ();
|
41 |
-
}
|
42 |
-
|
43 |
-
function set_options($options)
|
44 |
-
{
|
45 |
-
foreach ($options as $key => $value)
|
46 |
-
$this->options[$key] = $value;
|
47 |
-
if (!empty ($this->options['basedir']))
|
48 |
-
{
|
49 |
-
$this->options['basedir'] = str_replace("\\", "/", $this->options['basedir']);
|
50 |
-
$this->options['basedir'] = preg_replace("/\/+/", "/", $this->options['basedir']);
|
51 |
-
$this->options['basedir'] = preg_replace("/\/$/", "", $this->options['basedir']);
|
52 |
-
}
|
53 |
-
if (!empty ($this->options['name']))
|
54 |
-
{
|
55 |
-
$this->options['name'] = str_replace("\\", "/", $this->options['name']);
|
56 |
-
$this->options['name'] = preg_replace("/\/+/", "/", $this->options['name']);
|
57 |
-
}
|
58 |
-
if (!empty ($this->options['prepend']))
|
59 |
-
{
|
60 |
-
$this->options['prepend'] = str_replace("\\", "/", $this->options['prepend']);
|
61 |
-
$this->options['prepend'] = preg_replace("/^(\.*\/+)+/", "", $this->options['prepend']);
|
62 |
-
$this->options['prepend'] = preg_replace("/\/+/", "/", $this->options['prepend']);
|
63 |
-
$this->options['prepend'] = preg_replace("/\/$/", "", $this->options['prepend']) . "/";
|
64 |
-
}
|
65 |
-
if ( !empty($this->options['delete_path_in_archive'])) {
|
66 |
-
$this->options['delete_path_in_archive'] = str_replace("\\", "/", $this->options['delete_path_in_archive']);
|
67 |
-
}
|
68 |
-
}
|
69 |
-
|
70 |
-
function create_archive()
|
71 |
-
{
|
72 |
-
$this->make_list();
|
73 |
-
|
74 |
-
if ($this->options['inmemory'] == 0)
|
75 |
-
{
|
76 |
-
$pwd = getcwd();
|
77 |
-
chdir($this->options['basedir']);
|
78 |
-
if ($this->options['overwrite'] == 0 && file_exists($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip" ? ".tmp" : "")))
|
79 |
-
{
|
80 |
-
$this->error[] = "File {$this->options['name']} already exists.";
|
81 |
-
chdir($pwd);
|
82 |
-
return 0;
|
83 |
-
}
|
84 |
-
else if ($this->archive = @fopen($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip" ? ".tmp" : ""), "wb+"))
|
85 |
-
chdir($pwd);
|
86 |
-
else
|
87 |
-
{
|
88 |
-
$this->error[] = "Could not open {$this->options['name']} for writing.";
|
89 |
-
chdir($pwd);
|
90 |
-
return 0;
|
91 |
-
}
|
92 |
-
}
|
93 |
-
else
|
94 |
-
$this->archive = "";
|
95 |
-
|
96 |
-
switch ($this->options['type'])
|
97 |
-
{
|
98 |
-
case "zip":
|
99 |
-
if (!$this->create_zip())
|
100 |
-
{
|
101 |
-
$this->error[] = "Could not create zip file.";
|
102 |
-
return 0;
|
103 |
-
}
|
104 |
-
break;
|
105 |
-
case "bzip":
|
106 |
-
if (!$this->create_tar())
|
107 |
-
{
|
108 |
-
$this->error[] = "Could not create tar file.";
|
109 |
-
return 0;
|
110 |
-
}
|
111 |
-
if (!$this->create_bzip())
|
112 |
-
{
|
113 |
-
$this->error[] = "Could not create bzip2 file.";
|
114 |
-
return 0;
|
115 |
-
}
|
116 |
-
break;
|
117 |
-
case "gzip":
|
118 |
-
if (!$this->create_tar())
|
119 |
-
{
|
120 |
-
$this->error[] = "Could not create tar file.";
|
121 |
-
return 0;
|
122 |
-
}
|
123 |
-
if (!$this->create_gzip())
|
124 |
-
{
|
125 |
-
$this->error[] = "Could not create gzip file.";
|
126 |
-
return 0;
|
127 |
-
}
|
128 |
-
break;
|
129 |
-
case "tar":
|
130 |
-
if (!$this->create_tar())
|
131 |
-
{
|
132 |
-
$this->error[] = "Could not create tar file.";
|
133 |
-
return 0;
|
134 |
-
}
|
135 |
-
}
|
136 |
-
|
137 |
-
if ($this->options['inmemory'] == 0)
|
138 |
-
{
|
139 |
-
fclose($this->archive);
|
140 |
-
if ($this->options['type'] == "gzip" || $this->options['type'] == "bzip") {
|
141 |
-
if (file_exists($this->options['basedir'] . "/" . $this->options['name'] . ".tmp")) {
|
142 |
-
unlink( $this->options['basedir'] . "/" . $this->options['name'] . ".tmp" );
|
143 |
-
} elseif (file_exists($this->options['name'] . ".tmp")) {
|
144 |
-
unlink( $this->options['name'] . ".tmp" );
|
145 |
-
}
|
146 |
-
}
|
147 |
-
}
|
148 |
-
}
|
149 |
-
|
150 |
-
function add_data($data)
|
151 |
-
{
|
152 |
-
if ($this->options['inmemory'] == 0)
|
153 |
-
fwrite($this->archive, $data);
|
154 |
-
else
|
155 |
-
$this->archive .= $data;
|
156 |
-
}
|
157 |
-
|
158 |
-
function make_list()
|
159 |
-
{
|
160 |
-
if (!empty ($this->exclude))
|
161 |
-
foreach ($this->files as $key => $value)
|
162 |
-
foreach ($this->exclude as $current)
|
163 |
-
if ($value['name'] == $current['name'])
|
164 |
-
unset ($this->files[$key]);
|
165 |
-
if (!empty ($this->storeonly))
|
166 |
-
foreach ($this->files as $key => $value)
|
167 |
-
foreach ($this->storeonly as $current)
|
168 |
-
if ($value['name'] == $current['name'])
|
169 |
-
$this->files[$key]['method'] = 0;
|
170 |
-
unset ($this->exclude, $this->storeonly);
|
171 |
-
}
|
172 |
-
|
173 |
-
function add_files($list)
|
174 |
-
{
|
175 |
-
$temp = $this->list_files($list);
|
176 |
-
foreach ($temp as $current)
|
177 |
-
$this->files[] = $current;
|
178 |
-
|
179 |
-
}
|
180 |
-
|
181 |
-
function exclude_files($list)
|
182 |
-
{
|
183 |
-
$temp = $this->list_files($list);
|
184 |
-
foreach ($temp as $current)
|
185 |
-
$this->exclude[] = $current;
|
186 |
-
}
|
187 |
-
|
188 |
-
function include_files($list)
|
189 |
-
{
|
190 |
-
if (is_array($list)) {
|
191 |
-
$temp = $this->list_files($list);
|
192 |
-
foreach ($temp as $current)
|
193 |
-
$this->include[] = $current;
|
194 |
-
} elseif (is_string($list)) {
|
195 |
-
$this->include = $list;
|
196 |
-
}
|
197 |
-
}
|
198 |
-
|
199 |
-
function store_files($list)
|
200 |
-
{
|
201 |
-
$temp = $this->list_files($list);
|
202 |
-
foreach ($temp as $current)
|
203 |
-
$this->storeonly[] = $current;
|
204 |
-
}
|
205 |
-
|
206 |
-
function list_files($list)
|
207 |
-
{
|
208 |
-
if (!is_array ($list))
|
209 |
-
{
|
210 |
-
$temp = $list;
|
211 |
-
$list = array ($temp);
|
212 |
-
unset ($temp);
|
213 |
-
}
|
214 |
-
|
215 |
-
$files = array ();
|
216 |
-
|
217 |
-
$pwd = getcwd();
|
218 |
-
chdir($this->options['basedir']);
|
219 |
-
|
220 |
-
foreach ($list as $current)
|
221 |
-
{
|
222 |
-
$current = str_replace("\\", "/", $current);
|
223 |
-
$current = preg_replace("/\/+/", "/", $current);
|
224 |
-
$current = preg_replace("/\/$/", "", $current);
|
225 |
-
if (strstr($current, "*"))
|
226 |
-
{
|
227 |
-
$regex = preg_replace("/([\\\^\$\.\[\]\|\(\)\?\+\{\}\/])/", "\\\\\\1", $current);
|
228 |
-
$regex = str_replace("*", ".*", $regex);
|
229 |
-
$dir = strstr($current, "/") ? substr($current, 0, strrpos($current, "/")) : ".";
|
230 |
-
$temp = $this->parse_dir($dir);
|
231 |
-
foreach ($temp as $current2)
|
232 |
-
if (preg_match("/^{$regex}$/i", $current2['name']))
|
233 |
-
$files[] = $current2;
|
234 |
-
unset ($regex, $dir, $temp, $current);
|
235 |
-
}
|
236 |
-
else if (@is_dir($current))
|
237 |
-
{
|
238 |
-
$temp = $this->parse_dir($current);
|
239 |
-
foreach ($temp as $file)
|
240 |
-
$files[] = $file;
|
241 |
-
unset ($temp, $file);
|
242 |
-
}
|
243 |
-
else if (@file_exists($current))
|
244 |
-
$files[] = array ('name' => $current, 'name2' => $this->options['prepend'] .
|
245 |
-
preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($current, "/")) ?
|
246 |
-
substr($current, strrpos($current, "/") + 1) : ( !empty($this->options['delete_path_in_archive'] ) ? str_replace($this->options['delete_path_in_archive'] , '', $current) : $current ) ),
|
247 |
-
'type' => @is_link($current) && $this->options['followlinks'] == 0 ? 2 : 0,
|
248 |
-
'ext' => substr($current, strrpos($current, ".")), 'stat' => stat($current));
|
249 |
-
}
|
250 |
-
|
251 |
-
chdir($pwd);
|
252 |
-
|
253 |
-
unset ($current, $pwd);
|
254 |
-
|
255 |
-
usort($files, array ("archive", "sort_files"));
|
256 |
-
|
257 |
-
return $files;
|
258 |
-
}
|
259 |
-
|
260 |
-
function parse_dir($dirname)
|
261 |
-
{
|
262 |
-
if ($this->options['storepaths'] == 1 && !preg_match("/^(\.+\/*)+$/", $dirname))
|
263 |
-
$files = array (array ('name' => $dirname, 'name2' => $this->options['prepend'] .
|
264 |
-
preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($dirname, "/")) ?
|
265 |
-
substr($dirname, strrpos($dirname, "/") + 1) : $dirname), 'type' => 5, 'stat' => stat($dirname)));
|
266 |
-
else
|
267 |
-
$files = array ();
|
268 |
-
$dir = @opendir($dirname);
|
269 |
-
|
270 |
-
while ($file = @readdir($dir))
|
271 |
-
{
|
272 |
-
$fullname = $dirname . "/" . $file;
|
273 |
-
if ($file == "." || $file == "..")
|
274 |
-
continue;
|
275 |
-
else if (@is_dir($fullname))
|
276 |
-
{
|
277 |
-
if (empty ($this->options['recurse']))
|
278 |
-
continue;
|
279 |
-
$temp = $this->parse_dir($fullname);
|
280 |
-
foreach ($temp as $file2)
|
281 |
-
$files[] = $file2;
|
282 |
-
}
|
283 |
-
else if (@file_exists($fullname))
|
284 |
-
$files[] = array ('name' => $fullname, 'name2' => $this->options['prepend'] .
|
285 |
-
preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($fullname, "/")) ?
|
286 |
-
substr($fullname, strrpos($fullname, "/") + 1) : $fullname),
|
287 |
-
'type' => @is_link($fullname) && $this->options['followlinks'] == 0 ? 2 : 0,
|
288 |
-
'ext' => substr($file, strrpos($file, ".")), 'stat' => stat($fullname));
|
289 |
-
}
|
290 |
-
|
291 |
-
@closedir($dir);
|
292 |
-
|
293 |
-
return $files;
|
294 |
-
}
|
295 |
-
|
296 |
-
function sort_files($a, $b)
|
297 |
-
{
|
298 |
-
if ($a['type'] != $b['type'])
|
299 |
-
if ($a['type'] == 5 || $b['type'] == 2)
|
300 |
-
return -1;
|
301 |
-
else if ($a['type'] == 2 || $b['type'] == 5)
|
302 |
-
return 1;
|
303 |
-
else if ($a['type'] == 5)
|
304 |
-
return strcmp(strtolower($a['name']), strtolower($b['name']));
|
305 |
-
else if ($a['ext'] != $b['ext'])
|
306 |
-
return strcmp($a['ext'], $b['ext']);
|
307 |
-
else if ($a['stat'][7] != $b['stat'][7])
|
308 |
-
return $a['stat'][7] > $b['stat'][7] ? -1 : 1;
|
309 |
-
else
|
310 |
-
return strcmp(strtolower($a['name']), strtolower($b['name']));
|
311 |
-
return 0;
|
312 |
-
}
|
313 |
-
|
314 |
-
function download_file()
|
315 |
-
{
|
316 |
-
if ($this->options['inmemory'] == 0)
|
317 |
-
{
|
318 |
-
$this->error[] = "Can only use download_file() if archive is in memory. Redirect to file otherwise, it is faster.";
|
319 |
-
return;
|
320 |
-
}
|
321 |
-
switch ($this->options['type'])
|
322 |
-
{
|
323 |
-
case "zip":
|
324 |
-
header("Content-Type: application/zip");
|
325 |
-
break;
|
326 |
-
case "bzip":
|
327 |
-
header("Content-Type: application/x-bzip2");
|
328 |
-
break;
|
329 |
-
case "gzip":
|
330 |
-
header("Content-Type: application/x-gzip");
|
331 |
-
break;
|
332 |
-
case "tar":
|
333 |
-
header("Content-Type: application/x-tar");
|
334 |
-
}
|
335 |
-
$header = "Content-Disposition: attachment; filename=\"";
|
336 |
-
$header .= strstr($this->options['name'], "/") ? substr($this->options['name'], strrpos($this->options['name'], "/") + 1) : $this->options['name'];
|
337 |
-
$header .= "\"";
|
338 |
-
header($header);
|
339 |
-
header("Content-Length: " . strlen($this->archive));
|
340 |
-
header("Content-Transfer-Encoding: binary");
|
341 |
-
header("Cache-Control: no-cache, must-revalidate, max-age=60");
|
342 |
-
header("Expires: Sat, 01 Jan 2000 12:00:00 GMT");
|
343 |
-
print($this->archive);
|
344 |
-
}
|
345 |
-
|
346 |
-
function createDir($dir, $dir_to)
|
347 |
-
{
|
348 |
-
$file = basename($dir);
|
349 |
-
if (strpos($file, '.') !== false) {
|
350 |
-
$dir = substr($dir, 0, strlen($dir) - strlen($file));
|
351 |
-
}
|
352 |
-
$dir = str_replace("\\", '/', $dir);
|
353 |
-
$dirs_array = explode("/", $dir);
|
354 |
-
$n = count($dirs_array);
|
355 |
-
$dir_tmp = str_replace("\\", '/', $dir_to);
|
356 |
-
for($i = 0; $i < $n; $i++) {
|
357 |
-
$dir_tmp .= "/" . $dirs_array[$i];
|
358 |
-
if (!is_dir($dir_tmp) && !file_exists( $dir_tmp ) ) {
|
359 |
-
mkdir( $dir_tmp );
|
360 |
-
}
|
361 |
-
}
|
362 |
-
}
|
363 |
-
|
364 |
-
}
|
365 |
-
|
366 |
-
class wpadm_tar_file extends wpadm_archive_class
|
367 |
-
{
|
368 |
-
function __construct($name)
|
369 |
-
{
|
370 |
-
parent::__construct($name);
|
371 |
-
$this->options['type'] = "tar";
|
372 |
-
}
|
373 |
-
|
374 |
-
function create_tar()
|
375 |
-
{
|
376 |
-
$pwd = getcwd();
|
377 |
-
chdir($this->options['basedir']);
|
378 |
-
|
379 |
-
foreach ($this->files as $current)
|
380 |
-
{
|
381 |
-
if ($current['name'] == $this->options['name'])
|
382 |
-
continue;
|
383 |
-
if (strlen($current['name2']) > 99)
|
384 |
-
{
|
385 |
-
$path = substr($current['name2'], 0, strpos($current['name2'], "/", strlen($current['name2']) - 100) + 1);
|
386 |
-
$current['name2'] = substr($current['name2'], strlen($path));
|
387 |
-
if (strlen($path) > 154 || strlen($current['name2']) > 99)
|
388 |
-
{
|
389 |
-
$this->error[] = "Could not add {$path}{$current['name2']} to archive because the filename is too long.";
|
390 |
-
continue;
|
391 |
-
}
|
392 |
-
}
|
393 |
-
$block = pack("a100a8a8a8a12a12a8a1a100a6a2a32a32a8a8a155a12", $current['name2'], sprintf("%07o",
|
394 |
-
$current['stat'][2]), sprintf("%07o", $current['stat'][4]), sprintf("%07o", $current['stat'][5]),
|
395 |
-
sprintf("%011o", $current['type'] == 2 ? 0 : $current['stat'][7]), sprintf("%011o", $current['stat'][9]),
|
396 |
-
" ", $current['type'], $current['type'] == 2 ? @readlink($current['name']) : "", "ustar ", " ",
|
397 |
-
"Unknown", "Unknown", "", "", !empty ($path) ? $path : "", "");
|
398 |
-
|
399 |
-
$checksum = 0;
|
400 |
-
for ($i = 0; $i < 512; $i++)
|
401 |
-
$checksum += ord(substr($block, $i, 1));
|
402 |
-
$checksum = pack("a8", sprintf("%07o", $checksum));
|
403 |
-
$block = substr_replace($block, $checksum, 148, 8);
|
404 |
-
|
405 |
-
if ($current['type'] == 2 || $current['stat'][7] == 0)
|
406 |
-
$this->add_data($block);
|
407 |
-
else if ($fp = @fopen($current['name'], "rb"))
|
408 |
-
{
|
409 |
-
$this->add_data($block);
|
410 |
-
while ($temp = fread($fp, 1048576))
|
411 |
-
$this->add_data($temp);
|
412 |
-
if ($current['stat'][7] % 512 > 0)
|
413 |
-
{
|
414 |
-
$temp = "";
|
415 |
-
for ($i = 0; $i < 512 - $current['stat'][7] % 512; $i++)
|
416 |
-
$temp .= "\0";
|
417 |
-
$this->add_data($temp);
|
418 |
-
}
|
419 |
-
fclose($fp);
|
420 |
-
}
|
421 |
-
else
|
422 |
-
$this->error[] = "Could not open file {$current['name']} for reading. It was not added.";
|
423 |
-
}
|
424 |
-
|
425 |
-
$this->add_data(pack("a1024", ""));
|
426 |
-
|
427 |
-
chdir($pwd);
|
428 |
-
|
429 |
-
return 1;
|
430 |
-
}
|
431 |
-
|
432 |
-
function extract_files()
|
433 |
-
{
|
434 |
-
$pwd = getcwd();
|
435 |
-
chdir($this->options['basedir']);
|
436 |
-
|
437 |
-
if ($fp = $this->open_archive())
|
438 |
-
{
|
439 |
-
if ($this->options['inmemory'] == 1)
|
440 |
-
$this->files = array ();
|
441 |
-
|
442 |
-
while ($block = fread($fp, 512))
|
443 |
-
{
|
444 |
-
$temp = unpack("A100name/A8mode/A8uid/A8gid/A12size/A12mtime/A8checksum/A1type/A100symlink/A6magic/A2temp/A32temp/A32temp/A8temp/A8temp/A155prefix/A12temp", $block);
|
445 |
-
$file = array (
|
446 |
-
'name' => trim( $temp['prefix'] ) . trim( $temp['name'] ),
|
447 |
-
'stat' => array (
|
448 |
-
2 => $temp['mode'],
|
449 |
-
4 => octdec($temp['uid']),
|
450 |
-
5 => octdec($temp['gid']),
|
451 |
-
7 => octdec($temp['size']),
|
452 |
-
9 => octdec($temp['mtime']),
|
453 |
-
),
|
454 |
-
'checksum' => octdec($temp['checksum']),
|
455 |
-
'type' => (int)$temp['type'],
|
456 |
-
'magic' => $temp['magic'],
|
457 |
-
);
|
458 |
-
|
459 |
-
if ($file['checksum'] == 0x00000000)
|
460 |
-
break;
|
461 |
-
else if (substr($file['magic'], 0, 5) != "ustar")
|
462 |
-
{
|
463 |
-
$this->error[] = "This script does not support extracting this type of tar file." . "(" . utf8_encode( substr($file['magic'], 0, 5) ) . ")";
|
464 |
-
break;
|
465 |
-
}
|
466 |
-
$block = substr_replace($block, " ", 148, 8);
|
467 |
-
$checksum = 0;
|
468 |
-
for ($i = 0; $i < 512; $i++)
|
469 |
-
$checksum += ord(substr($block, $i, 1));
|
470 |
-
if ($file['checksum'] != $checksum)
|
471 |
-
$this->error[] = "Could not extract from {$this->options['name']}, it is corrupt.";
|
472 |
-
|
473 |
-
if ($file['type'] == 0) {
|
474 |
-
if ( !empty( $this->exclude ) ) {
|
475 |
-
if (is_array($this->exclude)) {
|
476 |
-
if ( in_array($file['name'], $this->exclude) ) {
|
477 |
-
continue;
|
478 |
-
}
|
479 |
-
} elseif (@function_exists($this->exclude)) {
|
480 |
-
$function = $this->exclude;
|
481 |
-
if ( $function($file['name']) === true ) {
|
482 |
-
continue;
|
483 |
-
}
|
484 |
-
}
|
485 |
-
}
|
486 |
-
|
487 |
-
if (!empty($this->include)) {
|
488 |
-
if (is_array($this->include)) {
|
489 |
-
if ( !in_array($file['name'], $this->include) ) {
|
490 |
-
continue;
|
491 |
-
} elseif (!preg_match($this->include, $file['name'])) {
|
492 |
-
continue;
|
493 |
-
}
|
494 |
-
}
|
495 |
-
}
|
496 |
-
$this->createDir($file['name'], $this->options['basedir']);
|
497 |
-
}
|
498 |
-
|
499 |
-
if ($this->options['inmemory'] == 1)
|
500 |
-
{
|
501 |
-
$file['data'] = fread($fp, $file['stat'][7]);
|
502 |
-
fread($fp, (512 - $file['stat'][7] % 512) == 512 ? 0 : (512 - $file['stat'][7] % 512));
|
503 |
-
unset ($file['checksum'], $file['magic']);
|
504 |
-
$this->files[] = $file;
|
505 |
-
}
|
506 |
-
else if ($file['type'] == 5)
|
507 |
-
{
|
508 |
-
if (!is_dir($file['name']))
|
509 |
-
mkdir($file['name'], $file['stat'][2]);
|
510 |
-
}
|
511 |
-
else if ($this->options['overwrite'] == 0 && file_exists($file['name']))
|
512 |
-
{
|
513 |
-
$this->error[] = "{$file['name']} already exists.";
|
514 |
-
continue;
|
515 |
-
}
|
516 |
-
else if ($file['type'] == 2)
|
517 |
-
{
|
518 |
-
symlink($temp['symlink'], $file['name']);
|
519 |
-
chmod($file['name'], $file['stat'][2]);
|
520 |
-
}
|
521 |
-
else if ($new = @fopen($file['name'], "wb"))
|
522 |
-
{
|
523 |
-
if ($file['stat'][7] == 0) {
|
524 |
-
fwrite($new, '');
|
525 |
-
} else {
|
526 |
-
fwrite($new, fread($fp, $file['stat'][7]));
|
527 |
-
}
|
528 |
-
|
529 |
-
$read_next = (512 - $file['stat'][7] % 512) == 512 ? 0 : (512 - $file['stat'][7] % 512);
|
530 |
-
if ($read_next != 0) {
|
531 |
-
fread($fp, $read_next);
|
532 |
-
}
|
533 |
-
fclose($new);
|
534 |
-
//chmod($file['name'], $file['stat'][2]);
|
535 |
-
}
|
536 |
-
else
|
537 |
-
{
|
538 |
-
|
539 |
-
$this->warning[] = "Could not open {$file['name']} for writing.";
|
540 |
-
continue;
|
541 |
-
}
|
542 |
-
//chown($file['name'], $file['stat'][4]);
|
543 |
-
//chgrp($file['name'], $file['stat'][5]);
|
544 |
-
//touch($file['name'], $file['stat'][9]);
|
545 |
-
unset ($file);
|
546 |
-
}
|
547 |
-
}
|
548 |
-
else
|
549 |
-
$this->error[] = "Could not open file {$this->options['name']}";
|
550 |
-
|
551 |
-
chdir($pwd);
|
552 |
-
}
|
553 |
-
|
554 |
-
function open_archive()
|
555 |
-
{
|
556 |
-
return @fopen($this->options['name'], "rb");
|
557 |
-
}
|
558 |
-
}
|
559 |
-
|
560 |
-
class wpadm_gzip_file extends wpadm_tar_file
|
561 |
-
{
|
562 |
-
function __construct($name)
|
563 |
-
{
|
564 |
-
parent::__construct($name);
|
565 |
-
$this->options['type'] = "gzip";
|
566 |
-
}
|
567 |
-
|
568 |
-
function create_gzip()
|
569 |
-
{
|
570 |
-
if ($this->options['inmemory'] == 0)
|
571 |
-
{
|
572 |
-
$pwd = getcwd();
|
573 |
-
chdir($this->options['basedir']);
|
574 |
-
if ($fp = gzopen($this->options['name'], "wb{$this->options['level']}"))
|
575 |
-
{
|
576 |
-
fseek($this->archive, 0);
|
577 |
-
while ($temp = fread($this->archive, 1048576))
|
578 |
-
gzwrite($fp, $temp);
|
579 |
-
gzclose($fp);
|
580 |
-
chdir($pwd);
|
581 |
-
}
|
582 |
-
else
|
583 |
-
{
|
584 |
-
$this->error[] = "Could not open {$this->options['name']} for writing.";
|
585 |
-
chdir($pwd);
|
586 |
-
return 0;
|
587 |
-
}
|
588 |
-
}
|
589 |
-
else
|
590 |
-
$this->archive = gzencode($this->archive, $this->options['level']);
|
591 |
-
|
592 |
-
return 1;
|
593 |
-
}
|
594 |
-
|
595 |
-
function extract_gz_files()
|
596 |
-
{
|
597 |
-
$pwd = getcwd();
|
598 |
-
chdir($this->options['basedir']);
|
599 |
-
$tmp_file = $this->options['name'] . ".tmp" ;
|
600 |
-
$tmp_w = fopen($tmp_file, "wb");
|
601 |
-
if ($tmp_w) {
|
602 |
-
if ($fp = gzopen($this->options['name'], "rb{$this->options['level']}"))
|
603 |
-
{
|
604 |
-
fseek($tmp_w, 0);
|
605 |
-
while ($temp = gzread($fp, 1048576))
|
606 |
-
fwrite($tmp_w, $temp);
|
607 |
-
gzclose($fp);
|
608 |
-
chdir($pwd);
|
609 |
-
}
|
610 |
-
else
|
611 |
-
{
|
612 |
-
$this->error[] = "Could not open {$this->options['name']} for reading.";
|
613 |
-
chdir($pwd);
|
614 |
-
return 0;
|
615 |
-
}
|
616 |
-
|
617 |
-
fclose($tmp_w);
|
618 |
-
$this->options['name'] = $tmp_file;
|
619 |
-
$this->extract_files();
|
620 |
-
if (file_exists($tmp_file)) {
|
621 |
-
unlink($tmp_file);
|
622 |
-
}
|
623 |
-
} else {
|
624 |
-
$this->error[] = "Could not open {$tmp_file} for writing.";
|
625 |
-
chdir($pwd);
|
626 |
-
return 0;
|
627 |
-
}
|
628 |
-
return 1;
|
629 |
-
}
|
630 |
-
|
631 |
-
function open_archive()
|
632 |
-
{
|
633 |
-
return @gzopen($this->options['name'], "rb");
|
634 |
-
}
|
635 |
-
}
|
636 |
-
|
637 |
-
class wpadm_bzip_file extends wpadm_tar_file
|
638 |
-
{
|
639 |
-
function __construct($name)
|
640 |
-
{
|
641 |
-
parent::__construct($name);
|
642 |
-
$this->options['type'] = "bzip";
|
643 |
-
}
|
644 |
-
|
645 |
-
function create_bzip()
|
646 |
-
{
|
647 |
-
if ($this->options['inmemory'] == 0)
|
648 |
-
{
|
649 |
-
$pwd = getcwd();
|
650 |
-
chdir($this->options['basedir']);
|
651 |
-
if ($fp = bzopen($this->options['name'], "wb"))
|
652 |
-
{
|
653 |
-
fseek($this->archive, 0);
|
654 |
-
while ($temp = fread($this->archive, 1048576))
|
655 |
-
bzwrite($fp, $temp);
|
656 |
-
bzclose($fp);
|
657 |
-
chdir($pwd);
|
658 |
-
}
|
659 |
-
else
|
660 |
-
{
|
661 |
-
$this->error[] = "Could not open {$this->options['name']} for writing.";
|
662 |
-
chdir($pwd);
|
663 |
-
return 0;
|
664 |
-
}
|
665 |
-
}
|
666 |
-
else
|
667 |
-
$this->archive = bzcompress($this->archive, $this->options['level']);
|
668 |
-
|
669 |
-
return 1;
|
670 |
-
}
|
671 |
-
|
672 |
-
function open_archive()
|
673 |
-
{
|
674 |
-
return @bzopen($this->options['name'], "rb");
|
675 |
-
}
|
676 |
-
}
|
677 |
-
|
678 |
-
class wpadm_zip_file extends wpadm_archive_class
|
679 |
-
{
|
680 |
-
function __construct($name)
|
681 |
-
{
|
682 |
-
parent::__construct($name);
|
683 |
-
$this->options['type'] = "zip";
|
684 |
-
}
|
685 |
-
|
686 |
-
function create_zip()
|
687 |
-
{
|
688 |
-
$files = 0;
|
689 |
-
$offset = 0;
|
690 |
-
$central = "";
|
691 |
-
|
692 |
-
if (!empty ($this->options['sfx']))
|
693 |
-
if ($fp = @fopen($this->options['sfx'], "rb"))
|
694 |
-
{
|
695 |
-
$temp = fread($fp, filesize($this->options['sfx']));
|
696 |
-
fclose($fp);
|
697 |
-
$this->add_data($temp);
|
698 |
-
$offset += strlen($temp);
|
699 |
-
unset ($temp);
|
700 |
-
}
|
701 |
-
else
|
702 |
-
$this->error[] = "Could not open sfx module from {$this->options['sfx']}.";
|
703 |
-
|
704 |
-
$pwd = getcwd();
|
705 |
-
chdir($this->options['basedir']);
|
706 |
-
|
707 |
-
foreach ($this->files as $current)
|
708 |
-
{
|
709 |
-
if ($current['name'] == $this->options['name'])
|
710 |
-
continue;
|
711 |
-
|
712 |
-
$timedate = explode(" ", date("Y n j G i s", $current['stat'][9]));
|
713 |
-
$timedate = ($timedate[0] - 1980 << 25) | ($timedate[1] << 21) | ($timedate[2] << 16) |
|
714 |
-
($timedate[3] << 11) | ($timedate[4] << 5) | ($timedate[5]);
|
715 |
-
|
716 |
-
$block = pack("VvvvV", 0x04034b50, 0x000A, 0x0000, (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate);
|
717 |
-
|
718 |
-
if ($current['stat'][7] == 0 && $current['type'] == 5)
|
719 |
-
{
|
720 |
-
$block .= pack("VVVvv", 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']) + 1, 0x0000);
|
721 |
-
$block .= $current['name2'] . "/";
|
722 |
-
$this->add_data($block);
|
723 |
-
$central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
|
724 |
-
(isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
|
725 |
-
0x00000000, 0x00000000, 0x00000000, strlen($current['name2']) + 1, 0x0000, 0x0000, 0x0000, 0x0000, $current['type'] == 5 ? 0x00000010 : 0x00000000, $offset);
|
726 |
-
$central .= $current['name2'] . "/";
|
727 |
-
$files++;
|
728 |
-
$offset += (31 + strlen($current['name2']));
|
729 |
-
}
|
730 |
-
else if ($current['stat'][7] == 0)
|
731 |
-
{
|
732 |
-
$block .= pack("VVVvv", 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']), 0x0000);
|
733 |
-
$block .= $current['name2'];
|
734 |
-
$this->add_data($block);
|
735 |
-
$central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
|
736 |
-
(isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
|
737 |
-
0x00000000, 0x00000000, 0x00000000, strlen($current['name2']), 0x0000, 0x0000, 0x0000, 0x0000, $current['type'] == 5 ? 0x00000010 : 0x00000000, $offset);
|
738 |
-
$central .= $current['name2'];
|
739 |
-
$files++;
|
740 |
-
$offset += (30 + strlen($current['name2']));
|
741 |
-
}
|
742 |
-
else if ($fp = @fopen($current['name'], "rb"))
|
743 |
-
{
|
744 |
-
$temp = fread($fp, $current['stat'][7]);
|
745 |
-
fclose($fp);
|
746 |
-
$crc32 = crc32($temp);
|
747 |
-
if (!isset($current['method']) && $this->options['method'] == 1)
|
748 |
-
{
|
749 |
-
$temp = gzcompress($temp, $this->options['level']);
|
750 |
-
$size = strlen($temp) - 6;
|
751 |
-
$temp = substr($temp, 2, $size);
|
752 |
-
}
|
753 |
-
else
|
754 |
-
$size = strlen($temp);
|
755 |
-
$block .= pack("VVVvv", $crc32, $size, $current['stat'][7], strlen($current['name2']), 0x0000);
|
756 |
-
$block .= $current['name2'];
|
757 |
-
$this->add_data($block);
|
758 |
-
$this->add_data($temp);
|
759 |
-
unset ($temp);
|
760 |
-
$central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
|
761 |
-
(isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
|
762 |
-
$crc32, $size, $current['stat'][7], strlen($current['name2']), 0x0000, 0x0000, 0x0000, 0x0000, 0x00000000, $offset);
|
763 |
-
$central .= $current['name2'];
|
764 |
-
$files++;
|
765 |
-
$offset += (30 + strlen($current['name2']) + $size);
|
766 |
-
}
|
767 |
-
else
|
768 |
-
$this->error[] = "Could not open file {$current['name']} for reading. It was not added.";
|
769 |
-
}
|
770 |
-
|
771 |
-
$this->add_data($central);
|
772 |
-
|
773 |
-
$this->add_data(pack("VvvvvVVv", 0x06054b50, 0x0000, 0x0000, $files, $files, strlen($central), $offset,
|
774 |
-
!empty ($this->options['comment']) ? strlen($this->options['comment']) : 0x0000));
|
775 |
-
|
776 |
-
if (!empty ($this->options['comment']))
|
777 |
-
$this->add_data($this->options['comment']);
|
778 |
-
|
779 |
-
chdir($pwd);
|
780 |
-
|
781 |
-
return 1;
|
782 |
-
}
|
783 |
-
}
|
784 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modules/class-wpadm-archive.php
CHANGED
@@ -4,7 +4,7 @@ if (!defined('PCLZIP_TEMPORARY_DIR')) {
|
|
4 |
}
|
5 |
|
6 |
if (!defined('PCLZIP_SEPARATOR')) {
|
7 |
-
define('PCLZIP_SEPARATOR', '
|
8 |
}
|
9 |
if ( !class_exists("PclZip") ) {
|
10 |
require_once dirname(__FILE__) . '/pclzip.lib.php';
|
@@ -13,431 +13,27 @@ if (!class_exists('WPAdm_Archive')) {
|
|
13 |
class WPAdm_Archive {
|
14 |
private $remove_path = '';
|
15 |
private $files = array();
|
16 |
-
public $file_zip = '';
|
17 |
-
private $type_backup = array();
|
18 |
/**
|
19 |
* @var PclZip
|
20 |
*/
|
21 |
private $archive;
|
22 |
private $md5_file = '';
|
23 |
public $error = '';
|
24 |
-
|
25 |
-
public $anew = false;
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
public function __construct($file, $md5_file = '') {
|
31 |
-
if (class_exists('wpadm_wp_full_backup_dropbox')) {
|
32 |
-
$this->type_backup = wpadm_wp_full_backup_dropbox::getTypeBackup();
|
33 |
-
}
|
34 |
-
$this->file_zip = $file;
|
35 |
-
$this->archive = new PclZip($file);
|
36 |
$this->files[] = $file;
|
37 |
$this->md5_file = $md5_file;
|
38 |
}
|
39 |
|
40 |
-
public function zipArhive($file_to_arhive = array())
|
41 |
-
{
|
42 |
-
if ( isset( $this->type_backup['zip_archive'] ) && $this->type_backup['zip_archive'] == 1 && !empty($file_to_arhive) ) {
|
43 |
-
$command = $this->getCommandToArchive('zip_archive', $file_to_arhive);
|
44 |
-
if (!empty($command)) {
|
45 |
-
$command_return = array();
|
46 |
-
$result_command = @exec($command, $command_return);
|
47 |
-
|
48 |
-
$res = $this->parseResultZip($command_return);
|
49 |
-
|
50 |
-
if ($res['add'] == count($file_to_arhive)) {
|
51 |
-
$files = implode(PCLZIP_SEPARATOR, $file_to_arhive);
|
52 |
-
$this->saveMd5($files);
|
53 |
-
return true;
|
54 |
-
}
|
55 |
-
if ( file_exists( $this->file_zip ) && $res['error'] === 0 ) {
|
56 |
-
$files = implode(PCLZIP_SEPARATOR, $file_to_arhive);
|
57 |
-
$this->saveMd5($files);
|
58 |
-
return true;
|
59 |
-
}
|
60 |
-
}
|
61 |
-
}
|
62 |
-
return false;
|
63 |
-
}
|
64 |
-
|
65 |
-
public function targzArchive( $file_to_arhive = array() )
|
66 |
-
{
|
67 |
-
if ( isset( $this->type_backup['targz_archive'] ) && $this->type_backup['targz_archive'] == 1 && !empty($file_to_arhive) ) {
|
68 |
-
|
69 |
-
if ( $this->tarGzCommandArhive($file_to_arhive) ) {
|
70 |
-
return true;
|
71 |
-
}
|
72 |
-
if ( !function_exists( 'gzencode' ) ) {
|
73 |
-
$this->error = __( 'Functions for gz compression not available', 'dropbox-backup' );
|
74 |
-
return false;
|
75 |
-
}
|
76 |
-
|
77 |
-
if ( strpos($this->file_zip, '.zip') !== false ) {
|
78 |
-
$this->file_zip = str_replace('.zip', '.tar.gz', $this->file_zip);
|
79 |
-
}
|
80 |
-
$this->method = 'targz';
|
81 |
-
|
82 |
-
$this->archive = fopen( $this->file_zip, 'ab' );
|
83 |
-
|
84 |
-
$n = count($file_to_arhive);
|
85 |
-
for($i = 0; $i < $n; $i++) {
|
86 |
-
$this->addToTargz($file_to_arhive[$i], '');
|
87 |
-
$this->saveMd5( $file_to_arhive[$i] );
|
88 |
-
}
|
89 |
-
$this->close();
|
90 |
-
/* include_once dirname(__FILE__) . '/archive.php';
|
91 |
-
$gz = new wpadm_gzip_file($this->file_zip);
|
92 |
-
$gz->set_options( array('basedir' => ABSPATH, 'delete_path_in_archive' => $this->remove_path ) );
|
93 |
-
$gz->add_files( $file_to_arhive );
|
94 |
-
$gz->create_archive();
|
95 |
-
if (!empty( $gz->error ) ) {
|
96 |
-
$this->error = implode(" ", $gz->error );
|
97 |
-
WPAdm_Core::log( $this->error );
|
98 |
-
return false;
|
99 |
-
}
|
100 |
-
$this->saveMd5( implode( PCLZIP_SEPARATOR, $file_to_arhive) );
|
101 |
-
*/
|
102 |
-
|
103 |
-
/*if ( strpos($this->file_zip, '.tar.gz') !== false ) {
|
104 |
-
$this->file_zip = str_replace('.tar.gz', '.zip', $this->file_zip);
|
105 |
-
} */
|
106 |
-
|
107 |
-
if ( file_exists($this->file_zip) ) {
|
108 |
-
return true;
|
109 |
-
}
|
110 |
-
}
|
111 |
-
return false;
|
112 |
-
}
|
113 |
-
|
114 |
-
private function addToTargz($file, $file_in)
|
115 |
-
{
|
116 |
-
$file = str_replace('\\', '/', $file);
|
117 |
-
if ( empty( $file_in ) ) {
|
118 |
-
$serach = str_replace('\\', '/', ABSPATH);
|
119 |
-
$file_in = str_replace($serach, '', $file);
|
120 |
-
}
|
121 |
-
|
122 |
-
$file_in = str_replace( array( "?", "<", ">", ":", "%","\"", "*", "|", chr(0) ) , '', $file_in );
|
123 |
-
|
124 |
-
if ( version_compare( PHP_VERSION, '5.3', '>=' ) ) {
|
125 |
-
clearstatcache(true, $file);
|
126 |
-
}
|
127 |
-
|
128 |
-
if ( ! is_readable( $file ) ) {
|
129 |
-
$this->error = sprintf( __( 'File %s is not readable or does not exist', 'dropbox-backup' ), $file );
|
130 |
-
return false;
|
131 |
-
}
|
132 |
-
$this->add_tar_file( $file, $file_in );
|
133 |
-
|
134 |
-
}
|
135 |
-
|
136 |
-
private function add_tar_file($file, $file_in)
|
137 |
-
{
|
138 |
-
if ( ! $this->check_archive( $file ) ) {
|
139 |
-
return false;
|
140 |
-
}
|
141 |
-
$chunk_size = 1024 * 1024 * 4;
|
142 |
-
|
143 |
-
//Limit string of file name in tar archive
|
144 |
-
if ( strlen( $file_in ) <= 100 ) {
|
145 |
-
$filename = $file_in;
|
146 |
-
$filename_prefix = "";
|
147 |
-
} else {
|
148 |
-
$filename_offset = strlen( $file_in ) - 100;
|
149 |
-
$split_pos = strpos( $file_in, '/', $filename_offset );
|
150 |
-
if ( $split_pos === FALSE ) {
|
151 |
-
$split_pos = strrpos( $file_in, '/' );
|
152 |
-
}
|
153 |
-
$filename = substr( $file_in, $split_pos + 1 );
|
154 |
-
$filename_prefix = substr( $file_in, 0, $split_pos );
|
155 |
-
if ( strlen( $filename ) > 100 ) {
|
156 |
-
$filename = substr( $filename, -100 );
|
157 |
-
WPAdm_Core::log( sprintf( __( 'File name "%1$s" is too long to be saved correctly in archive!', 'dropbox-backup' ), $file_in ) );
|
158 |
-
}
|
159 |
-
if ( strlen( $filename_prefix ) > 155 ) {
|
160 |
-
WPAdm_Core::log( sprintf( __( 'File path "%1$s" is too long to be saved correctly in archive!', 'dropbox-backup' ), $file_in) );
|
161 |
-
}
|
162 |
-
}
|
163 |
-
$file_stat = stat( $file );
|
164 |
-
if ( ! $file_stat ) {
|
165 |
-
return false;
|
166 |
-
}
|
167 |
-
$file_stat[ 'size' ] = abs( (int) $file_stat[ 'size' ] );
|
168 |
-
//open file
|
169 |
-
if ( $file_stat[ 'size' ] > 0 ) {
|
170 |
-
if ( ! ( $fd = fopen( $file, 'rb' ) ) ) {
|
171 |
-
$this->error = sprintf( __( 'Cannot open source file %s for archiving', 'dropbox-backup' ), $file );
|
172 |
-
return false;
|
173 |
-
}
|
174 |
-
}
|
175 |
-
$fileowner = __( "Unknown", "dropbox-backup" );
|
176 |
-
$filegroup = __( "Unknown", "dropbox-backup" );
|
177 |
-
if ( function_exists( 'posix_getpwuid' ) ) {
|
178 |
-
$info = posix_getpwuid( $file_stat[ 'uid' ] );
|
179 |
-
$fileowner = $info[ 'name' ];
|
180 |
-
$info = posix_getgrgid( $file_stat[ 'gid' ] );
|
181 |
-
$filegroup = $info[ 'name' ];
|
182 |
-
}
|
183 |
-
// Generate the TAR header for this file
|
184 |
-
$chunk = pack( "a100a8a8a8a12a12a8a1a100a6a2a32a32a8a8a155a12",
|
185 |
-
$filename, //name of file 100
|
186 |
-
sprintf( "%07o", $file_stat[ 'mode' ] ), //file mode 8
|
187 |
-
sprintf( "%07o", $file_stat[ 'uid' ] ), //owner user ID 8
|
188 |
-
sprintf( "%07o", $file_stat[ 'gid' ] ), //owner group ID 8
|
189 |
-
sprintf( "%011o", $file_stat[ 'size' ] ), //length of file in bytes 12
|
190 |
-
sprintf( "%011o", $file_stat[ 'mtime' ] ), //modify time of file 12
|
191 |
-
" ", //checksum for header 8
|
192 |
-
0, //type of file 0 or null = File, 5=Dir
|
193 |
-
"", //name of linked file 100
|
194 |
-
"ustar", //USTAR indicator 6
|
195 |
-
"00", //USTAR version 2
|
196 |
-
$fileowner, //owner user name 32
|
197 |
-
$filegroup, //owner group name 32
|
198 |
-
"", //device major number 8
|
199 |
-
"", //device minor number 8
|
200 |
-
$filename_prefix, //prefix for file name 155
|
201 |
-
"" ); //fill block 12
|
202 |
-
|
203 |
-
$checksum = 0;
|
204 |
-
for ( $i = 0; $i < 512; $i ++ ) {
|
205 |
-
$checksum += ord( substr( $chunk, $i, 1 ) );
|
206 |
-
}
|
207 |
-
|
208 |
-
$checksum = pack( "a8", sprintf( "%07o", $checksum ) );
|
209 |
-
$chunk = substr_replace( $chunk, $checksum, 148, 8 );
|
210 |
-
|
211 |
-
if ( isset( $fd ) && is_resource( $fd ) ) {
|
212 |
-
// read/write files in 512 bite Blocks
|
213 |
-
while ( ( $content = fread( $fd, 512 ) ) != '' ) {
|
214 |
-
$chunk .= pack( "a512", $content );
|
215 |
-
if ( strlen( $chunk ) >= $chunk_size ) {
|
216 |
-
if ( WPAdm_Running::is_stop() ) {
|
217 |
-
if ( $this->method == 'targz' ) {
|
218 |
-
$chunk = gzencode( $chunk );
|
219 |
-
}
|
220 |
-
if ( $this->method == 'tarbz2' ) {
|
221 |
-
$chunk = bzcompress( $chunk );
|
222 |
-
}
|
223 |
-
fwrite( $this->archive, $chunk );
|
224 |
-
$chunk = '';
|
225 |
-
}
|
226 |
-
}
|
227 |
-
}
|
228 |
-
fclose( $fd );
|
229 |
-
}
|
230 |
-
|
231 |
-
if ( ! empty( $chunk ) ) {
|
232 |
-
if ( $this->method == 'targz' ) {
|
233 |
-
$chunk = gzencode( $chunk );
|
234 |
-
}
|
235 |
-
if ( $this->method == 'tarbz2' ) {
|
236 |
-
$chunk = bzcompress( $chunk );
|
237 |
-
}
|
238 |
-
fwrite( $this->archive, $chunk );
|
239 |
-
}
|
240 |
-
|
241 |
-
return true;
|
242 |
-
}
|
243 |
-
|
244 |
-
private function check_archive( $file = '' ) {
|
245 |
-
|
246 |
-
$file_size = 0;
|
247 |
-
if ( ! empty( $file ) ) {
|
248 |
-
$file_size = filesize( $file );
|
249 |
-
if ( $file_size === FALSE ) {
|
250 |
-
$file_size = 0;
|
251 |
-
}
|
252 |
-
}
|
253 |
-
|
254 |
-
if ( is_resource( $this->archive ) ) {
|
255 |
-
$info_archive = fstat( $this->archive );
|
256 |
-
$archive_size = $info_archive[ 'size' ];
|
257 |
-
} else {
|
258 |
-
$archive_size = filesize( $this->file_zip );
|
259 |
-
if ( $archive_size === FALSE ) {
|
260 |
-
$archive_size = PHP_INT_MAX;
|
261 |
-
}
|
262 |
-
}
|
263 |
-
|
264 |
-
$archive_size = $archive_size + $file_size;
|
265 |
-
if ( $archive_size >= PHP_INT_MAX ) {
|
266 |
-
$this->error = sprintf( __( 'If %s will be added to your backup archive, the archive will be too large for operations with this PHP Version. You might want to consider splitting the backup job in multiple jobs with less files each.', 'dropbox-backup' ), $file_to_add );
|
267 |
-
return false;
|
268 |
-
}
|
269 |
-
|
270 |
-
return true;
|
271 |
-
}
|
272 |
-
|
273 |
-
public function close()
|
274 |
-
{
|
275 |
-
if ($this->method == 'targz') {
|
276 |
-
$end = pack( "a1024", "" );
|
277 |
-
if ( $this->method === 'targz' ) {
|
278 |
-
$end = gzencode( $end );
|
279 |
-
}
|
280 |
-
if ( $this->method === 'tarbz2' ) {
|
281 |
-
$end = bzcompress( $end );
|
282 |
-
}
|
283 |
-
fwrite( $this->archive, $end );
|
284 |
-
}
|
285 |
-
}
|
286 |
-
|
287 |
-
public function parseResultZip($command_return)
|
288 |
-
{
|
289 |
-
$add = 0;
|
290 |
-
$error = 0;
|
291 |
-
if (!empty( $command_return) ) {
|
292 |
-
$n = count($command_return);
|
293 |
-
for($i = 0; $i < $n; $i++) {
|
294 |
-
if (strpos($command_return[$i], 'add') !== false || strpos($command_return[$i], 'updating') !== false) {
|
295 |
-
$add ++;
|
296 |
-
} elseif (strpos($command_return[$i], 'error') !== false || strpos($command_return[$i], 'warning') !== false ) {
|
297 |
-
$error++;
|
298 |
-
$this->error .= " " . $command_return[$i];
|
299 |
-
}
|
300 |
-
}
|
301 |
-
}
|
302 |
-
return array( 'add' => $add, 'error' => $error );
|
303 |
-
|
304 |
-
}
|
305 |
-
|
306 |
-
public function tarGzCommandArhive($file_to_arhive = array())
|
307 |
-
{
|
308 |
-
|
309 |
-
$command = $this->getCommandToArchive('tar_archive', $file_to_arhive);
|
310 |
-
if (!empty($command)) {
|
311 |
-
$command_return = array();
|
312 |
-
$result_command = @exec ($command, $command_return);
|
313 |
-
if (count($file_to_arhive) == count($command_return)) {
|
314 |
-
$files = implode(PCLZIP_SEPARATOR, $file_to_arhive);
|
315 |
-
$this->saveMd5($files);
|
316 |
-
return true;
|
317 |
-
}
|
318 |
-
if (count($command_return) > 0) {
|
319 |
-
$files = implode(PCLZIP_SEPARATOR, $file_to_arhive);
|
320 |
-
$this->saveMd5($files);
|
321 |
-
return true;
|
322 |
-
}
|
323 |
-
if (file_exists($this->file_zip)) {
|
324 |
-
$files = implode(PCLZIP_SEPARATOR, $file_to_arhive);
|
325 |
-
$this->saveMd5($files);
|
326 |
-
return true;
|
327 |
-
}
|
328 |
-
$this->error = "Files not Adding to arhive";
|
329 |
-
if ( strpos($this->file_zip, '.tar.gz') !== false ) {
|
330 |
-
$this->file_zip = str_replace('.tar.gz', '.zip', $this->file_zip);
|
331 |
-
}
|
332 |
-
}
|
333 |
-
return false;
|
334 |
-
}
|
335 |
-
|
336 |
-
public function getCommandToArchive($type = 'zip_archive', $files = array() )
|
337 |
-
{
|
338 |
-
$return = '';
|
339 |
-
$remove_dir = '';
|
340 |
-
switch($type) {
|
341 |
-
case 'zip_archive':
|
342 |
-
if (!empty( $this->remove_path ) ) {
|
343 |
-
$remove_dir = 'cd ' . $this->remove_path . ' &&';
|
344 |
-
$files_str = '"' . implode('" "', $files) . '"';
|
345 |
-
$files_str = str_replace($this->remove_path, './', $files_str);
|
346 |
-
$zip = str_replace($this->remove_path, './', $this->file_zip);
|
347 |
-
} else {
|
348 |
-
$files_str = '"' . implode('" "', $files) . '"';
|
349 |
-
$zip = $this->file_zip;
|
350 |
-
}
|
351 |
-
|
352 |
-
$return .= trim( "$remove_dir zip {$zip} " . $files_str );
|
353 |
-
break;
|
354 |
-
case 'tar_archive':
|
355 |
-
if ( strpos($this->file_zip, '.zip') !== false ) {
|
356 |
-
$this->file_zip = str_replace('.zip', '.tar.gz', $this->file_zip);
|
357 |
-
}
|
358 |
-
|
359 |
-
if (!empty( $this->remove_path) ) {
|
360 |
-
$remove_dir = '-C ' . $this->remove_path . ' ';
|
361 |
-
}
|
362 |
-
$files_str = '"' . implode('" "', $files) . '"';
|
363 |
-
$files_str = str_replace($this->remove_path, './', $files_str);
|
364 |
-
$u = 'c';
|
365 |
-
if (file_exists($this->file_zip)) {
|
366 |
-
$u = 'r';
|
367 |
-
}
|
368 |
-
$return = trim( "tar -{$u}zvf {$this->file_zip} " . $remove_dir . $files_str );
|
369 |
-
break;
|
370 |
-
}
|
371 |
-
return $return;
|
372 |
-
|
373 |
-
}
|
374 |
-
|
375 |
-
public function clearBackupDirectory($type = '')
|
376 |
-
{
|
377 |
-
if (!empty( $type ) ) {
|
378 |
-
$dir = substr($this->file_zip, 0, strlen($this->file_zip) - strlen( basename( $this->file_zip ) ) );
|
379 |
-
$open_dir = opendir( $dir );
|
380 |
-
if ($open_dir) {
|
381 |
-
while($d = readdir($open_dir)) {
|
382 |
-
if ($d != '.' && $d != '..') {
|
383 |
-
if ( substr($d, $type) !== false ) {
|
384 |
-
@unlink($dir . '/' . $d);
|
385 |
-
}
|
386 |
-
}
|
387 |
-
}
|
388 |
-
}
|
389 |
-
}
|
390 |
-
}
|
391 |
-
|
392 |
public function add($file)
|
393 |
{
|
394 |
return $this->packed($file);
|
395 |
}
|
396 |
public function packed($file)
|
397 |
{
|
398 |
-
|
399 |
if ( WPAdm_Running::is_stop() ) {
|
400 |
-
$files = explode(PCLZIP_SEPARATOR, $file);
|
401 |
-
$n = count($files);
|
402 |
-
$this->setToLogArhive( __('Add to archive: ', 'dropbox-backup') . $this->file_zip );
|
403 |
-
for($i = 0; $i < $n; $i++) {
|
404 |
-
|
405 |
-
$this->setToLogArhive(__("Add File: ", 'dropbox-backup' ) . $files[$i] . ' [' . WPADM_getSize( filesize($files[$i]) ) . ']' . '[' . wpadm_class::perm($files[$i]) . ']' );
|
406 |
-
}
|
407 |
-
$file = implode(PCLZIP_SEPARATOR, $files);
|
408 |
-
$command_targz_test = WPAdm_Running::getCommandResultData('test_targz_archive');
|
409 |
-
if( !empty($command_targz_test) && $command_targz_test === true ) {
|
410 |
-
if ( WPAdm_Running::is_stop() ) {
|
411 |
-
WPAdm_Core::log(__('Trying to add files to archive using Tar shell or tar class', 'dropbox-backup') );
|
412 |
-
$tarGz = $this->targzArchive($files); // .tar.gz archive
|
413 |
-
if ($tarGz) {
|
414 |
-
WPAdm_Core::log(__('Trying to add files to archive using Tar shell or tar class was successful', 'dropbox-backup') );
|
415 |
-
return true;
|
416 |
-
}
|
417 |
-
$this->anew = true;
|
418 |
-
$this->clearBackupDirectory('.tar.gz');
|
419 |
-
$this->clearBackupDirectory('.md5');
|
420 |
-
$this->error = '';
|
421 |
-
WPAdm_Core::log(__('Add files to archive using Tar shell or tar class wasn\'t successful', 'dropbox-backup') );
|
422 |
-
WPAdm_Running::setCommandResultData('test_targz_archive', false);
|
423 |
-
return false;
|
424 |
-
}
|
425 |
-
}
|
426 |
-
$command_zip_test = WPAdm_Running::getCommandResultData('test_zip_archive');
|
427 |
-
if ( !empty($command_zip_test) && $command_zip_test === true ) {
|
428 |
-
if ( WPAdm_Running::is_stop() ) {
|
429 |
-
WPAdm_Core::log(__('Trying to add files to archive using Zip shell', 'dropbox-backup') );
|
430 |
-
$zip_shell = $this->zipArhive($files); // command zip
|
431 |
-
if ($zip_shell) {
|
432 |
-
WPAdm_Core::log(__('Add files to archive using Zip shell was successful', 'dropbox-backup') );
|
433 |
-
return true;
|
434 |
-
}
|
435 |
-
$this->anew = true;
|
436 |
-
WPAdm_Core::log(__('Add files to archive using Zip shell wasn\'t successful', 'dropbox-backup') );
|
437 |
-
WPAdm_Running::setCommandResultData('test_zip_archive', false);
|
438 |
-
return false;
|
439 |
-
}
|
440 |
-
}
|
441 |
if (empty($this->remove_path)) {
|
442 |
if ( WPAdm_Running::is_stop() ) {
|
443 |
$res = $this->archive->add($file);
|
@@ -449,7 +45,6 @@ if (!class_exists('WPAdm_Archive')) {
|
|
449 |
}
|
450 |
if ( WPAdm_Running::is_stop() ) {
|
451 |
if ($res == 0) {
|
452 |
-
$this->checkError($file);
|
453 |
WPAdm_Core::log( $this->archive->errorInfo(true) );
|
454 |
if (file_exists($this->md5_file)) {
|
455 |
unset($this->md5_file);
|
@@ -463,25 +58,11 @@ if (!class_exists('WPAdm_Archive')) {
|
|
463 |
return true;
|
464 |
}
|
465 |
|
466 |
-
protected function checkError($file)
|
467 |
-
{
|
468 |
-
$count = WPAdm_Running::getCommandResultData('count_error_zip');
|
469 |
-
if ( empty($count) || $count == 0 ) {
|
470 |
-
if ( $this->archive->errorCode() == -10 ) { // Unable to find End of Central Dir Record signature
|
471 |
-
WPAdm_Core::rmdir($this->file_zip);
|
472 |
-
WPAdm_Running::getCommandResultData('count_error_zip_signature', 1);
|
473 |
-
$this->packed($file);
|
474 |
-
return true;
|
475 |
-
}
|
476 |
-
}
|
477 |
-
return false;
|
478 |
-
}
|
479 |
-
|
480 |
protected function saveMd5($file) {
|
481 |
if ($this->md5_file) {
|
482 |
-
$files = explode(
|
483 |
foreach($files as $f) {
|
484 |
-
file_put_contents($this->md5_file, $f . "\t" . @md5_file($f) . "\t" . basename($this->
|
485 |
}
|
486 |
}
|
487 |
}
|
@@ -490,11 +71,5 @@ if (!class_exists('WPAdm_Archive')) {
|
|
490 |
public function setRemovePath($remove_path) {
|
491 |
$this->remove_path = $remove_path;
|
492 |
}
|
493 |
-
|
494 |
-
public function setToLogArhive($msg)
|
495 |
-
{
|
496 |
-
$file_log = WPADM_Core::getTmpDir() . '/log-archive.log';
|
497 |
-
file_put_contents( $file_log, date("Y-m-d H:i:s") . "\t{$msg}\n", FILE_APPEND );
|
498 |
-
}
|
499 |
}
|
500 |
}
|
4 |
}
|
5 |
|
6 |
if (!defined('PCLZIP_SEPARATOR')) {
|
7 |
+
define('PCLZIP_SEPARATOR', ';');
|
8 |
}
|
9 |
if ( !class_exists("PclZip") ) {
|
10 |
require_once dirname(__FILE__) . '/pclzip.lib.php';
|
13 |
class WPAdm_Archive {
|
14 |
private $remove_path = '';
|
15 |
private $files = array();
|
|
|
|
|
16 |
/**
|
17 |
* @var PclZip
|
18 |
*/
|
19 |
private $archive;
|
20 |
private $md5_file = '';
|
21 |
public $error = '';
|
|
|
|
|
22 |
|
23 |
+
public function __construct($file, $md5_file = '') {
|
24 |
+
$this->archive = new PclZip($file);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
$this->files[] = $file;
|
26 |
$this->md5_file = $md5_file;
|
27 |
}
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
public function add($file)
|
30 |
{
|
31 |
return $this->packed($file);
|
32 |
}
|
33 |
public function packed($file)
|
34 |
{
|
35 |
+
ini_set("memory_limit", "256M");
|
36 |
if ( WPAdm_Running::is_stop() ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
if (empty($this->remove_path)) {
|
38 |
if ( WPAdm_Running::is_stop() ) {
|
39 |
$res = $this->archive->add($file);
|
45 |
}
|
46 |
if ( WPAdm_Running::is_stop() ) {
|
47 |
if ($res == 0) {
|
|
|
48 |
WPAdm_Core::log( $this->archive->errorInfo(true) );
|
49 |
if (file_exists($this->md5_file)) {
|
50 |
unset($this->md5_file);
|
58 |
return true;
|
59 |
}
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
protected function saveMd5($file) {
|
62 |
if ($this->md5_file) {
|
63 |
+
$files = explode(',', $file); {
|
64 |
foreach($files as $f) {
|
65 |
+
file_put_contents($this->md5_file, $f . "\t" . @md5_file($f) . "\t" . basename($this->archive->zipname) . "\n", FILE_APPEND);
|
66 |
}
|
67 |
}
|
68 |
}
|
71 |
public function setRemovePath($remove_path) {
|
72 |
$this->remove_path = $remove_path;
|
73 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
}
|
75 |
}
|
modules/class-wpadm-command-context.php
CHANGED
@@ -1,7 +1,4 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
if (!class_exists('WPAdm_Command_Context')) {
|
6 |
class WPAdm_Command_Context {
|
7 |
private $params = array();
|
1 |
<?php
|
|
|
|
|
|
|
2 |
if (!class_exists('WPAdm_Command_Context')) {
|
3 |
class WPAdm_Command_Context {
|
4 |
private $params = array();
|
modules/class-wpadm-command-factory.php
CHANGED
@@ -1,9 +1,4 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
5 |
-
|
6 |
-
|
7 |
/**
|
8 |
* Class WPAdm_Command_Factory
|
9 |
*/
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Class WPAdm_Command_Factory
|
4 |
*/
|
modules/class-wpadm-command.php
CHANGED
@@ -1,8 +1,4 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
-
|
6 |
/**
|
7 |
* Class WPAdm_Сommand
|
8 |
*/
|
1 |
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Class WPAdm_Сommand
|
4 |
*/
|
modules/class-wpadm-core.php
CHANGED
@@ -1,7 +1,4 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
require_once DRBBACKUP_BASE_DIR . '/modules/class-wpadm-result.php';
|
6 |
require_once DRBBACKUP_BASE_DIR . '/modules/class-wpadm-command.php';
|
7 |
require_once DRBBACKUP_BASE_DIR . '/modules/class-wpadm-command-context.php';
|
@@ -33,8 +30,6 @@ if (!class_exists('WPAdm_Core')) {
|
|
33 |
private $result;
|
34 |
|
35 |
private $plugin;
|
36 |
-
|
37 |
-
private $sign = false;
|
38 |
|
39 |
public $name = '',
|
40 |
$time = '';
|
@@ -44,31 +39,23 @@ if (!class_exists('WPAdm_Core')) {
|
|
44 |
public static $pl_dir;
|
45 |
|
46 |
public static $error = '';
|
47 |
-
|
48 |
-
private static $self = null;
|
49 |
|
50 |
public static $plugin_name;
|
51 |
|
52 |
private static $cron_method = array('local_backup', 'send_to_dropbox');
|
53 |
|
54 |
|
55 |
-
public function __construct(array $request, $plugin = '', $plugin_dir = ''
|
56 |
$this->result = new WPAdm_Result();
|
57 |
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
58 |
$this->request = $request;
|
59 |
-
if ( empty( $this->request ) ) {
|
60 |
-
return;
|
61 |
-
}
|
62 |
$this->plugin = $plugin;
|
63 |
-
$this->sign = $sign;
|
64 |
self::$pl_dir = $plugin_dir;
|
65 |
self::$plugin_name = $plugin;
|
66 |
// auth request
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
}
|
71 |
-
}
|
72 |
if ('connect' == $request['method']) {
|
73 |
$this->connect();
|
74 |
} elseif ('local' == $request['method']){
|
@@ -189,7 +176,7 @@ if (!class_exists('WPAdm_Core')) {
|
|
189 |
}
|
190 |
|
191 |
/*
|
192 |
-
*
|
193 |
*/
|
194 |
private function auth() {
|
195 |
$this->pub_key = get_option('wpadm_pub_key');
|
@@ -218,7 +205,7 @@ if (!class_exists('WPAdm_Core')) {
|
|
218 |
|
219 |
$sign = md5(serialize($this->request['params']));
|
220 |
//openssl_public_decrypt($this->request['sign'], $request_sign, $this->pub_key);
|
221 |
-
|
222 |
|
223 |
|
224 |
//$ret = ($sign == $request_sign);
|
@@ -227,10 +214,10 @@ if (!class_exists('WPAdm_Core')) {
|
|
227 |
}
|
228 |
return $ret;
|
229 |
}
|
230 |
-
|
231 |
-
|
232 |
/**
|
233 |
-
*
|
234 |
* @param $dir
|
235 |
*/
|
236 |
static public function mkdir($dir) {
|
@@ -258,21 +245,13 @@ if (!class_exists('WPAdm_Core')) {
|
|
258 |
public function getResult() {
|
259 |
return $this->result;
|
260 |
}
|
261 |
-
|
262 |
-
public static function getInstance()
|
263 |
-
{
|
264 |
-
if (is_null( self::$self ) ) {
|
265 |
-
self::$self = new self( array() );
|
266 |
-
}
|
267 |
-
return self::$self;
|
268 |
-
}
|
269 |
|
270 |
|
271 |
public function verifySignature($sign, $sign2, $pub_key, $text) {
|
272 |
if (function_exists('openssl_public_decrypt')) {
|
273 |
openssl_public_decrypt($sign, $request_sign, $pub_key);
|
274 |
$ret = ($text == $request_sign);
|
275 |
-
|
276 |
} else {
|
277 |
set_include_path(get_include_path() . PATH_SEPARATOR . self::getPluginDir() . '/modules/phpseclib');
|
278 |
require_once 'Crypt/RSA.php';
|
1 |
<?php
|
|
|
|
|
|
|
2 |
require_once DRBBACKUP_BASE_DIR . '/modules/class-wpadm-result.php';
|
3 |
require_once DRBBACKUP_BASE_DIR . '/modules/class-wpadm-command.php';
|
4 |
require_once DRBBACKUP_BASE_DIR . '/modules/class-wpadm-command-context.php';
|
30 |
private $result;
|
31 |
|
32 |
private $plugin;
|
|
|
|
|
33 |
|
34 |
public $name = '',
|
35 |
$time = '';
|
39 |
public static $pl_dir;
|
40 |
|
41 |
public static $error = '';
|
|
|
|
|
42 |
|
43 |
public static $plugin_name;
|
44 |
|
45 |
private static $cron_method = array('local_backup', 'send_to_dropbox');
|
46 |
|
47 |
|
48 |
+
public function __construct(array $request, $plugin = '', $plugin_dir = '') {
|
49 |
$this->result = new WPAdm_Result();
|
50 |
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
51 |
$this->request = $request;
|
|
|
|
|
|
|
52 |
$this->plugin = $plugin;
|
|
|
53 |
self::$pl_dir = $plugin_dir;
|
54 |
self::$plugin_name = $plugin;
|
55 |
// auth request
|
56 |
+
if (!$this->auth()) {
|
57 |
+
return;
|
58 |
+
}
|
|
|
|
|
59 |
if ('connect' == $request['method']) {
|
60 |
$this->connect();
|
61 |
} elseif ('local' == $request['method']){
|
176 |
}
|
177 |
|
178 |
/*
|
179 |
+
* Авторизация запроса
|
180 |
*/
|
181 |
private function auth() {
|
182 |
$this->pub_key = get_option('wpadm_pub_key');
|
205 |
|
206 |
$sign = md5(serialize($this->request['params']));
|
207 |
//openssl_public_decrypt($this->request['sign'], $request_sign, $this->pub_key);
|
208 |
+
$ret = $this->verifySignature(base64_decode( $this->request['sign'] ), base64_decode( $this->request['sign2'] ), $this->pub_key, $sign);
|
209 |
|
210 |
|
211 |
//$ret = ($sign == $request_sign);
|
214 |
}
|
215 |
return $ret;
|
216 |
}
|
217 |
+
|
218 |
+
|
219 |
/**
|
220 |
+
* Создаем папку
|
221 |
* @param $dir
|
222 |
*/
|
223 |
static public function mkdir($dir) {
|
245 |
public function getResult() {
|
246 |
return $this->result;
|
247 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
|
249 |
|
250 |
public function verifySignature($sign, $sign2, $pub_key, $text) {
|
251 |
if (function_exists('openssl_public_decrypt')) {
|
252 |
openssl_public_decrypt($sign, $request_sign, $pub_key);
|
253 |
$ret = ($text == $request_sign);
|
254 |
+
return $ret;
|
255 |
} else {
|
256 |
set_include_path(get_include_path() . PATH_SEPARATOR . self::getPluginDir() . '/modules/phpseclib');
|
257 |
require_once 'Crypt/RSA.php';
|
modules/class-wpadm-method-class.php
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
|
6 |
if (!class_exists('WPAdm_Method_Class')) {
|
7 |
abstract class WPAdm_Method_Class {
|
1 |
<?php
|
2 |
|
|
|
|
|
3 |
|
4 |
if (!class_exists('WPAdm_Method_Class')) {
|
5 |
abstract class WPAdm_Method_Class {
|
modules/class-wpadm-mysqldump.php
CHANGED
@@ -1,9 +1,4 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
5 |
-
|
6 |
-
|
7 |
if (!class_exists('WPAdm_Mysqldump')) {
|
8 |
class WPAdm_Mysqldump {
|
9 |
|
@@ -52,7 +47,7 @@ if (!class_exists('WPAdm_Mysqldump')) {
|
|
52 |
if (!isset($proc_data['optimize'])) {
|
53 |
if ( WPAdm_Running::is_stop() ) {
|
54 |
$link = $this->connect($db);
|
55 |
-
WPAdm_Core::log( __('
|
56 |
$n = $link->query('SHOW TABLES');
|
57 |
WPAdm_Process::init('optimization', $n);
|
58 |
$result = $link->last_result;
|
@@ -70,10 +65,10 @@ if (!class_exists('WPAdm_Mysqldump')) {
|
|
70 |
$tables[$res[0]] = 1;
|
71 |
$proc_data['optimize_table'] = $tables;
|
72 |
WPAdm_Running::setCommandResultData('db', $proc_data);
|
73 |
-
$log = str_replace('%s', $res[0], __('Error
|
74 |
WPAdm_Core::log($log);
|
75 |
} else {
|
76 |
-
$log = str_replace('%s', $res[0], __('
|
77 |
WPAdm_Core::log($log);
|
78 |
WPAdm_Process::set('optimization', ( $i + 1 ) );
|
79 |
}
|
@@ -81,7 +76,7 @@ if (!class_exists('WPAdm_Mysqldump')) {
|
|
81 |
}
|
82 |
}
|
83 |
if ( WPAdm_Running::is_stop() ) {
|
84 |
-
WPAdm_Core::log( __('
|
85 |
$proc_data = WPAdm_Running::getCommandResultData('db');
|
86 |
$proc_data['optimize'] = true;
|
87 |
WPAdm_Running::setCommandResultData('db', $proc_data);
|
@@ -96,7 +91,7 @@ if (!class_exists('WPAdm_Mysqldump')) {
|
|
96 |
if (!isset($proc_data['work'])) {
|
97 |
$link = $this->connect($db);
|
98 |
if ( WPAdm_Running::is_stop() ) {
|
99 |
-
WPAdm_Core::log( __('
|
100 |
$n = $link->query('SHOW TABLE STATUS;');
|
101 |
WPAdm_Process::init('repair', $n);
|
102 |
$result = $link->last_result;
|
@@ -113,7 +108,7 @@ if (!class_exists('WPAdm_Mysqldump')) {
|
|
113 |
if ( WPAdm_Running::is_stop() ) {
|
114 |
$row = get_object_vars( $result[$i] );
|
115 |
$tables[] = $row;
|
116 |
-
WPAdm_Core::log('Start
|
117 |
$res = $link->query("REPAIR TABLE {$row['Name']};");
|
118 |
if ($res == 1) {
|
119 |
$proc_data = WPAdm_Running::getCommandResultData('repair');
|
@@ -123,7 +118,7 @@ if (!class_exists('WPAdm_Mysqldump')) {
|
|
123 |
$this->setError($link->last_error);
|
124 |
}
|
125 |
WPAdm_Process::set('repair', ($i + 1) );
|
126 |
-
WPAdm_Core::log('
|
127 |
}
|
128 |
}
|
129 |
if ( WPAdm_Running::is_stop() ) {
|
@@ -141,7 +136,7 @@ if (!class_exists('WPAdm_Mysqldump')) {
|
|
141 |
if (!isset($proc_data['mysqldump'])) {
|
142 |
$link = $this->connect($db);
|
143 |
if ( WPAdm_Running::is_stop() ) {
|
144 |
-
WPAdm_Core::log( __('
|
145 |
$tables = array();
|
146 |
$n = $link->query('SHOW TABLES');
|
147 |
WPAdm_Process::init('mysqldump', $n);
|
@@ -189,40 +184,36 @@ if (!class_exists('WPAdm_Mysqldump')) {
|
|
189 |
$proc_data = WPAdm_Running::getCommandResultData('db');
|
190 |
$proc_data['mysqldump_table'][$table] = 1;
|
191 |
WPAdm_Running::setCommandResultData('db', $proc_data);
|
192 |
-
$log = str_replace('%s', $table, __('Add table "%s"
|
193 |
WPAdm_Core::log( $log );
|
194 |
}
|
195 |
}
|
196 |
if ( WPAdm_Running::is_stop() ) {
|
197 |
$while = true;
|
198 |
while($while) {
|
199 |
-
|
200 |
if ( WPAdm_Running::is_stop() ) {
|
201 |
$table_db = WPAdm_Running::getCommandResultData('tabledb');
|
202 |
-
|
203 |
-
|
204 |
$from = $table_db[$table]['from']; // value from
|
205 |
$to = $table_db[$table]['to']; // value to
|
206 |
-
|
207 |
-
|
208 |
} else {
|
209 |
$from = 0;
|
210 |
$to = $this->rows;
|
211 |
-
|
212 |
}
|
213 |
}
|
214 |
-
|
215 |
if (isset($from) && !empty($to) && $from >= 0 && $to >= 0 && $insert_values === true) {
|
216 |
unset($link);
|
217 |
$link = $this->connect($db);
|
218 |
-
|
219 |
if ($num_fields > 0) {
|
220 |
-
|
221 |
$result2 = $link->last_result;
|
222 |
-
if ( WPAdm_Running::is_stop() ) {
|
223 |
-
$log = __('Performing of database query:' ,'dropbox-backup') . ' SELECT * FROM ' . $table . " LIMIT {$from}, {$to}";
|
224 |
-
WPAdm_Core::log( $log );
|
225 |
-
}
|
226 |
for ($i = 0; $i < $num_fields; $i++) {
|
227 |
if ( WPAdm_Running::is_stop() ) {
|
228 |
$return = '';
|
@@ -239,36 +230,41 @@ if (!class_exists('WPAdm_Mysqldump')) {
|
|
239 |
$return .= ");\n";
|
240 |
file_put_contents($filename, $return, FILE_APPEND);
|
241 |
$from += 1;
|
242 |
-
|
243 |
-
|
244 |
$table_db[$table]['to'] = $to;
|
245 |
$table_db[$table]['work'] = 1;
|
246 |
WPAdm_Running::setCommandResultData('tabledb', $table_db);
|
|
|
247 |
}
|
248 |
}
|
249 |
}
|
|
|
|
|
|
|
|
|
250 |
} else {
|
251 |
$while = false;
|
252 |
if ( WPAdm_Running::is_stop() ) {
|
253 |
-
|
254 |
$table_db[$table]['work'] = 0;
|
255 |
-
|
256 |
WPAdm_Process::set('mysqldump', ( $key_tables + 1 ) );
|
257 |
}
|
258 |
}
|
259 |
} else {
|
260 |
$while = false;
|
261 |
if ( WPAdm_Running::is_stop() ) {
|
262 |
-
|
263 |
$table_db[$table]['work'] = 0;
|
264 |
-
|
265 |
WPAdm_Process::set('mysqldump', ( $key_tables + 1 ) );
|
266 |
}
|
267 |
}
|
268 |
}
|
269 |
}
|
270 |
if ( WPAdm_Running::is_stop() ) {
|
271 |
-
|
272 |
if (!isset($proc_data['mysqldump_table'][$table])) {
|
273 |
$return ="\n\n\n";
|
274 |
file_put_contents($filename, $return, FILE_APPEND);
|
@@ -278,7 +274,7 @@ if (!class_exists('WPAdm_Mysqldump')) {
|
|
278 |
}
|
279 |
if ( WPAdm_Running::is_stop() ) {
|
280 |
unset($link);
|
281 |
-
WPAdm_Core::log( __('
|
282 |
$proc_data = WPAdm_Running::getCommandResultData('db');
|
283 |
$proc_data['mysqldump'] = true;
|
284 |
WPAdm_Running::setCommandResultData('db', $proc_data);
|
@@ -298,11 +294,11 @@ if (!class_exists('WPAdm_Mysqldump')) {
|
|
298 |
public function restore($db, $file)
|
299 |
{
|
300 |
$link = $this->connect($db);
|
301 |
-
WPAdm_Core::log( __('Database
|
302 |
$fo = fopen($file, "r");
|
303 |
if (!$fo) {
|
304 |
-
WPAdm_Core::log( __('Error
|
305 |
-
$this->setError( __('Error
|
306 |
return false;
|
307 |
}
|
308 |
$sql = "";
|
@@ -323,7 +319,7 @@ if (!class_exists('WPAdm_Mysqldump')) {
|
|
323 |
}
|
324 |
}
|
325 |
}
|
326 |
-
WPAdm_Core::log(__('Database
|
327 |
}
|
328 |
}
|
329 |
}
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
if (!class_exists('WPAdm_Mysqldump')) {
|
3 |
class WPAdm_Mysqldump {
|
4 |
|
47 |
if (!isset($proc_data['optimize'])) {
|
48 |
if ( WPAdm_Running::is_stop() ) {
|
49 |
$link = $this->connect($db);
|
50 |
+
WPAdm_Core::log( __('Optimize Database Tables was started' ,'dropbox-backup') );
|
51 |
$n = $link->query('SHOW TABLES');
|
52 |
WPAdm_Process::init('optimization', $n);
|
53 |
$result = $link->last_result;
|
65 |
$tables[$res[0]] = 1;
|
66 |
$proc_data['optimize_table'] = $tables;
|
67 |
WPAdm_Running::setCommandResultData('db', $proc_data);
|
68 |
+
$log = str_replace('%s', $res[0], __('Error to Optimize Table `%s`' ,'dropbox-backup') );
|
69 |
WPAdm_Core::log($log);
|
70 |
} else {
|
71 |
+
$log = str_replace('%s', $res[0], __('Optimize Table `%s` was successfully' ,'dropbox-backup') );
|
72 |
WPAdm_Core::log($log);
|
73 |
WPAdm_Process::set('optimization', ( $i + 1 ) );
|
74 |
}
|
76 |
}
|
77 |
}
|
78 |
if ( WPAdm_Running::is_stop() ) {
|
79 |
+
WPAdm_Core::log( __('Optimize Database Tables was Finished' ,'dropbox-backup') );
|
80 |
$proc_data = WPAdm_Running::getCommandResultData('db');
|
81 |
$proc_data['optimize'] = true;
|
82 |
WPAdm_Running::setCommandResultData('db', $proc_data);
|
91 |
if (!isset($proc_data['work'])) {
|
92 |
$link = $this->connect($db);
|
93 |
if ( WPAdm_Running::is_stop() ) {
|
94 |
+
WPAdm_Core::log( __('MySQL of repair was started' ,'dropbox-backup') );
|
95 |
$n = $link->query('SHOW TABLE STATUS;');
|
96 |
WPAdm_Process::init('repair', $n);
|
97 |
$result = $link->last_result;
|
108 |
if ( WPAdm_Running::is_stop() ) {
|
109 |
$row = get_object_vars( $result[$i] );
|
110 |
$tables[] = $row;
|
111 |
+
WPAdm_Core::log('Start repair table `' . $row['Name'] . '`' );
|
112 |
$res = $link->query("REPAIR TABLE {$row['Name']};");
|
113 |
if ($res == 1) {
|
114 |
$proc_data = WPAdm_Running::getCommandResultData('repair');
|
118 |
$this->setError($link->last_error);
|
119 |
}
|
120 |
WPAdm_Process::set('repair', ($i + 1) );
|
121 |
+
WPAdm_Core::log('Finish repair table `' . $row['Name'] . '`');
|
122 |
}
|
123 |
}
|
124 |
if ( WPAdm_Running::is_stop() ) {
|
136 |
if (!isset($proc_data['mysqldump'])) {
|
137 |
$link = $this->connect($db);
|
138 |
if ( WPAdm_Running::is_stop() ) {
|
139 |
+
WPAdm_Core::log( __('MySQL of Dump was started' ,'dropbox-backup') );
|
140 |
$tables = array();
|
141 |
$n = $link->query('SHOW TABLES');
|
142 |
WPAdm_Process::init('mysqldump', $n);
|
184 |
$proc_data = WPAdm_Running::getCommandResultData('db');
|
185 |
$proc_data['mysqldump_table'][$table] = 1;
|
186 |
WPAdm_Running::setCommandResultData('db', $proc_data);
|
187 |
+
$log = str_replace('%s', $table, __('Add a table "%s" in the database dump' ,'dropbox-backup') );
|
188 |
WPAdm_Core::log( $log );
|
189 |
}
|
190 |
}
|
191 |
if ( WPAdm_Running::is_stop() ) {
|
192 |
$while = true;
|
193 |
while($while) {
|
194 |
+
$insert_values = false;
|
195 |
if ( WPAdm_Running::is_stop() ) {
|
196 |
$table_db = WPAdm_Running::getCommandResultData('tabledb');
|
197 |
+
if (isset($table_db[$table])) {
|
198 |
+
if (isset($table_db[$table]['work']) && $table_db[$table]['work'] == 1) {
|
199 |
$from = $table_db[$table]['from']; // value from
|
200 |
$to = $table_db[$table]['to']; // value to
|
201 |
+
$insert_values = true;
|
202 |
+
}
|
203 |
} else {
|
204 |
$from = 0;
|
205 |
$to = $this->rows;
|
206 |
+
$insert_values = true;
|
207 |
}
|
208 |
}
|
209 |
+
|
210 |
if (isset($from) && !empty($to) && $from >= 0 && $to >= 0 && $insert_values === true) {
|
211 |
unset($link);
|
212 |
$link = $this->connect($db);
|
213 |
+
$num_fields = $link->query( 'SELECT * FROM ' . $table . " LIMIT {$from}, {$to}" );
|
214 |
if ($num_fields > 0) {
|
215 |
+
WPAdm_Core::log( $link->last_error ) ;
|
216 |
$result2 = $link->last_result;
|
|
|
|
|
|
|
|
|
217 |
for ($i = 0; $i < $num_fields; $i++) {
|
218 |
if ( WPAdm_Running::is_stop() ) {
|
219 |
$return = '';
|
230 |
$return .= ");\n";
|
231 |
file_put_contents($filename, $return, FILE_APPEND);
|
232 |
$from += 1;
|
233 |
+
$table_db = WPAdm_Running::getCommandResultData('tabledb');
|
234 |
+
$table_db[$table]['from'] = $from;
|
235 |
$table_db[$table]['to'] = $to;
|
236 |
$table_db[$table]['work'] = 1;
|
237 |
WPAdm_Running::setCommandResultData('tabledb', $table_db);
|
238 |
+
|
239 |
}
|
240 |
}
|
241 |
}
|
242 |
+
if ( WPAdm_Running::is_stop() ) {
|
243 |
+
$log = str_replace(array('%s', '%from%', '%to%'), array($table, $from, $to), __('Add a table rows "%s" in the database dump from %from% to %to%' ,'dropbox-backup') );
|
244 |
+
WPAdm_Core::log( $log );
|
245 |
+
}
|
246 |
} else {
|
247 |
$while = false;
|
248 |
if ( WPAdm_Running::is_stop() ) {
|
249 |
+
$table_db = WPAdm_Running::getCommandResultData('tabledb');
|
250 |
$table_db[$table]['work'] = 0;
|
251 |
+
WPAdm_Running::setCommandResultData('tabledb', $table_db);
|
252 |
WPAdm_Process::set('mysqldump', ( $key_tables + 1 ) );
|
253 |
}
|
254 |
}
|
255 |
} else {
|
256 |
$while = false;
|
257 |
if ( WPAdm_Running::is_stop() ) {
|
258 |
+
$table_db = WPAdm_Running::getCommandResultData('tabledb');
|
259 |
$table_db[$table]['work'] = 0;
|
260 |
+
WPAdm_Running::setCommandResultData('tabledb', $table_db);
|
261 |
WPAdm_Process::set('mysqldump', ( $key_tables + 1 ) );
|
262 |
}
|
263 |
}
|
264 |
}
|
265 |
}
|
266 |
if ( WPAdm_Running::is_stop() ) {
|
267 |
+
$proc_data = WPAdm_Running::getCommandResultData('db');
|
268 |
if (!isset($proc_data['mysqldump_table'][$table])) {
|
269 |
$return ="\n\n\n";
|
270 |
file_put_contents($filename, $return, FILE_APPEND);
|
274 |
}
|
275 |
if ( WPAdm_Running::is_stop() ) {
|
276 |
unset($link);
|
277 |
+
WPAdm_Core::log( __('MySQL of Dump was finished' ,'dropbox-backup') );
|
278 |
$proc_data = WPAdm_Running::getCommandResultData('db');
|
279 |
$proc_data['mysqldump'] = true;
|
280 |
WPAdm_Running::setCommandResultData('db', $proc_data);
|
294 |
public function restore($db, $file)
|
295 |
{
|
296 |
$link = $this->connect($db);
|
297 |
+
WPAdm_Core::log( __('Restore Database was started' ,'dropbox-backup') );
|
298 |
$fo = fopen($file, "r");
|
299 |
if (!$fo) {
|
300 |
+
WPAdm_Core::log( __('Error in open file dump' ,'dropbox-backup') );
|
301 |
+
$this->setError( __('Error in open file dump' ,'dropbox-backup') );
|
302 |
return false;
|
303 |
}
|
304 |
$sql = "";
|
319 |
}
|
320 |
}
|
321 |
}
|
322 |
+
WPAdm_Core::log(__('Restore Database was finished' ,'dropbox-backup'));
|
323 |
}
|
324 |
}
|
325 |
}
|
modules/class-wpadm-process.php
CHANGED
@@ -1,7 +1,4 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
/**
|
6 |
* Class WPAdm_Сommand
|
7 |
*/
|
1 |
<?php
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Class WPAdm_Сommand
|
4 |
*/
|
modules/class-wpadm-queue.php
CHANGED
@@ -1,7 +1,4 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
/**
|
6 |
*
|
7 |
* Class WPAdm_Queue
|
1 |
<?php
|
|
|
|
|
|
|
2 |
/**
|
3 |
*
|
4 |
* Class WPAdm_Queue
|
modules/class-wpadm-result.php
CHANGED
@@ -1,7 +1,4 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
if (!class_exists('WPAdm_Result')) {
|
6 |
class WPAdm_Result {
|
7 |
/*
|
1 |
<?php
|
|
|
|
|
|
|
2 |
if (!class_exists('WPAdm_Result')) {
|
3 |
class WPAdm_Result {
|
4 |
/*
|
modules/class-wpadm-running.php
CHANGED
@@ -1,6 +1,4 @@
|
|
1 |
<?php
|
2 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
3 |
-
|
4 |
/**
|
5 |
* Class WPAdm_Running
|
6 |
*/
|
@@ -39,21 +37,7 @@ if (!class_exists('WPAdm_Running')) {
|
|
39 |
WPAdm_Core::rmdir($path . "/cron-restore.data");
|
40 |
WPAdm_Core::rmdir($path . "/stop_process");
|
41 |
WPAdm_Core::rmdir($path . "/folder_create");
|
42 |
-
|
43 |
-
WPAdm_Core::rmdir($path . "/drb_running_time");
|
44 |
-
WPAdm_Core::rmdir($path . "/count_error_zip_signature");
|
45 |
-
WPAdm_Core::rmdir($path . "/tmp_arhive_file");
|
46 |
-
WPAdm_Core::rmdir($path . "/tmp_arhive_file2");
|
47 |
-
WPAdm_Core::rmdir($path . "/tmp_arhive_name");
|
48 |
-
WPAdm_Core::rmdir($path . "/tmp_arhive_name2");
|
49 |
-
WPAdm_Core::rmdir($path . "/time_work");
|
50 |
-
WPAdm_Core::rmdir($path . "/test.zip");
|
51 |
-
WPAdm_Core::rmdir($path . "/test.tar.gz");
|
52 |
-
WPAdm_Core::rmdir($path . "/test_zip_archive");
|
53 |
-
WPAdm_Core::rmdir($path . "/test_targz_archive");
|
54 |
-
WPAdm_Core::rmdir($path . "/start-process");
|
55 |
-
WPAdm_Core::rmdir($path . "/circle");
|
56 |
-
|
57 |
if ($method) {
|
58 |
$files = glob($path ."/wpadm_method*.queue");
|
59 |
if (!empty($files)) {
|
@@ -80,81 +64,53 @@ if (!class_exists('WPAdm_Running')) {
|
|
80 |
}
|
81 |
}
|
82 |
|
83 |
-
static function toEndWork($time = 0)
|
84 |
-
{
|
85 |
-
$time_start_process = self::getCommandResultData('start-process');
|
86 |
-
|
87 |
-
if ($time == 0) {
|
88 |
-
$time = self::getCommandResultData('time_work');
|
89 |
-
}
|
90 |
-
$time_work = ini_get('max_execution_time');
|
91 |
-
|
92 |
-
$time_stop = 25;
|
93 |
-
|
94 |
-
if ($time_work <= 30) {
|
95 |
-
$time_stop = round($time_work / 2.5);
|
96 |
-
}
|
97 |
-
|
98 |
-
$time_is = ( $time_start_process + $time_work ) - $time;
|
99 |
-
if ( !empty($time_start_process) && !empty($time) && $time_is <= $time_stop ) { //second
|
100 |
-
//sleep($time_is + 2);
|
101 |
-
return false;
|
102 |
-
}
|
103 |
-
return true;
|
104 |
-
}
|
105 |
-
|
106 |
static function init()
|
107 |
{
|
108 |
$command = self::getCommand();
|
109 |
|
110 |
-
if ($command ) {
|
111 |
WPAdm_Core::$cron = false;
|
112 |
wpadm_class::$type = 'full';
|
113 |
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
|
|
|
|
|
|
119 |
|
120 |
if ( self::checkLock() ) {
|
121 |
-
|
122 |
-
|
123 |
-
if (
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
self::createDebug( $result, $command['method'] );
|
135 |
-
}
|
136 |
}
|
137 |
}
|
138 |
}
|
139 |
}
|
140 |
}
|
141 |
-
|
142 |
-
public static function createDebug( $result
|
143 |
{
|
144 |
-
|
145 |
-
wpadm_class::error_log_check( print_r( $result, 1 ), $type_backup );
|
146 |
-
}
|
147 |
}
|
148 |
-
|
149 |
public static function checkLock()
|
150 |
{
|
151 |
// false - cron is running
|
152 |
// true - cron not running
|
153 |
$running_cron = get_transient('drb_running');
|
154 |
-
$time_work = self::getCommandResultData('time_work');
|
155 |
-
if ( !empty($time_work) && ( $time_work + 20 ) > time() ) {
|
156 |
-
return false;
|
157 |
-
}
|
158 |
if ($running_cron && $running_cron == 1) {
|
159 |
$time = microtime( true );
|
160 |
$locked = get_transient('doing_cron');
|
@@ -188,8 +144,6 @@ if (!class_exists('WPAdm_Running')) {
|
|
188 |
} else {
|
189 |
set_transient('drb_running', 1, $time + 30);
|
190 |
}
|
191 |
-
|
192 |
-
self::setCommandResultData('start-process', time() );
|
193 |
return true;
|
194 |
}
|
195 |
|
@@ -206,13 +160,14 @@ if (!class_exists('WPAdm_Running')) {
|
|
206 |
{
|
207 |
$stop_precess = self::getCommandResultData('stop_process');
|
208 |
if ( !empty( $stop_precess ) && isset( $stop_precess['name'] ) && isset( $stop_precess['type'] ) ) {
|
209 |
-
|
210 |
if ($stop_precess['type'] == 'dropbox') {
|
211 |
-
|
|
|
|
|
212 |
}
|
213 |
-
|
214 |
}
|
215 |
-
self::setCommandResultData('time_work', time());
|
216 |
return empty($stop_precess);
|
217 |
}
|
218 |
|
@@ -319,4 +274,4 @@ if (!class_exists('WPAdm_Running')) {
|
|
319 |
return array();
|
320 |
}
|
321 |
}
|
322 |
-
}
|
1 |
<?php
|
|
|
|
|
2 |
/**
|
3 |
* Class WPAdm_Running
|
4 |
*/
|
37 |
WPAdm_Core::rmdir($path . "/cron-restore.data");
|
38 |
WPAdm_Core::rmdir($path . "/stop_process");
|
39 |
WPAdm_Core::rmdir($path . "/folder_create");
|
40 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
if ($method) {
|
42 |
$files = glob($path ."/wpadm_method*.queue");
|
43 |
if (!empty($files)) {
|
64 |
}
|
65 |
}
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
static function init()
|
68 |
{
|
69 |
$command = self::getCommand();
|
70 |
|
71 |
+
if ($command && self::is_stop() ) {
|
72 |
WPAdm_Core::$cron = false;
|
73 |
wpadm_class::$type = 'full';
|
74 |
|
75 |
+
//$time_load = ini_get("max_execution_time");
|
76 |
+
//WPAdm_Core::log('proccess is work ' . $time_load . 'sec');
|
77 |
+
/*if ($time_load != 0) {
|
78 |
+
self::run($time_load - 5);
|
79 |
+
} else {
|
80 |
+
self::run(90);
|
81 |
+
} */
|
82 |
+
self::run(60);
|
83 |
|
84 |
if ( self::checkLock() ) {
|
85 |
+
$core = new WPAdm_Core($command, 'full_backup_dropbox', DRBBACKUP_BASE_DIR);
|
86 |
+
if (!is_bool( $core->getResult() ) && is_object( $core->getResult() ) && ( $result = $core->getResult()->toArray(true) ) ) {
|
87 |
+
if ($result['result'] == 'success') {
|
88 |
+
self::delCommand($command['method']);
|
89 |
+
set_transient('drb_running', 0, 60 * 4);
|
90 |
+
self::stop();
|
91 |
+
self::setCommandResultData($command['method'], $result);
|
92 |
+
self::init();
|
93 |
+
} elseif ($result['result'] == 'error') {
|
94 |
+
self::setCommandResultData($command['method'], $result);
|
95 |
+
self::stop();
|
96 |
+
self::init_params_default();
|
97 |
+
self::createDebug( $result );
|
|
|
|
|
98 |
}
|
99 |
}
|
100 |
}
|
101 |
}
|
102 |
}
|
103 |
+
|
104 |
+
public static function createDebug( $result )
|
105 |
{
|
106 |
+
wpadm_class::error_log_check( print_r( $result, 1 ) );
|
|
|
|
|
107 |
}
|
108 |
+
|
109 |
public static function checkLock()
|
110 |
{
|
111 |
// false - cron is running
|
112 |
// true - cron not running
|
113 |
$running_cron = get_transient('drb_running');
|
|
|
|
|
|
|
|
|
114 |
if ($running_cron && $running_cron == 1) {
|
115 |
$time = microtime( true );
|
116 |
$locked = get_transient('doing_cron');
|
144 |
} else {
|
145 |
set_transient('drb_running', 1, $time + 30);
|
146 |
}
|
|
|
|
|
147 |
return true;
|
148 |
}
|
149 |
|
160 |
{
|
161 |
$stop_precess = self::getCommandResultData('stop_process');
|
162 |
if ( !empty( $stop_precess ) && isset( $stop_precess['name'] ) && isset( $stop_precess['type'] ) ) {
|
163 |
+
$_POST['backup-name'] = $stop_precess['name'];
|
164 |
if ($stop_precess['type'] == 'dropbox') {
|
165 |
+
$_POST['backup-type'] = $stop_precess['type'];
|
166 |
+
wpadm_wp_full_backup_dropbox::delete_backup();
|
167 |
+
$_POST['backup-type'] = 'local';
|
168 |
}
|
169 |
+
wpadm_wp_full_backup_dropbox::delete_backup();
|
170 |
}
|
|
|
171 |
return empty($stop_precess);
|
172 |
}
|
173 |
|
274 |
return array();
|
275 |
}
|
276 |
}
|
277 |
+
}
|
modules/pclzip.lib.php
CHANGED
@@ -1,3043 +1,3034 @@
|
|
1 |
-
<?php
|
2 |
-
if (!defined('PCLZIP_READ_BLOCK_SIZE')) {
|
3 |
-
define( 'PCLZIP_READ_BLOCK_SIZE', 2048 );
|
4 |
-
}
|
5 |
-
if (!defined('PCLZIP_SEPARATOR')) {
|
6 |
-
define( 'PCLZIP_SEPARATOR', ',' );
|
7 |
-
}
|
8 |
-
if (!defined('PCLZIP_ERROR_EXTERNAL')) {
|
9 |
-
define( 'PCLZIP_ERROR_EXTERNAL', 0 );
|
10 |
-
}
|
11 |
-
if (!defined('PCLZIP_TEMPORARY_DIR')) {
|
12 |
-
define( 'PCLZIP_TEMPORARY_DIR', '' );
|
13 |
-
}
|
14 |
-
if (!defined('PCLZIP_TEMPORARY_FILE_RATIO')) {
|
15 |
-
define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.47 );
|
16 |
-
}
|
17 |
-
// --------------------------------------------------------------------------------
|
18 |
-
// ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED *****
|
19 |
-
// --------------------------------------------------------------------------------
|
20 |
-
$g_pclzip_version = "2.8.2";
|
21 |
-
define( 'PCLZIP_ERR_USER_ABORTED', 2 );
|
22 |
-
define( 'PCLZIP_ERR_NO_ERROR', 0 );
|
23 |
-
define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 );
|
24 |
-
define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 );
|
25 |
-
define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 );
|
26 |
-
define( 'PCLZIP_ERR_MISSING_FILE', -4 );
|
27 |
-
define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 );
|
28 |
-
define( 'PCLZIP_ERR_INVALID_ZIP', -6 );
|
29 |
-
define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 );
|
30 |
-
define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 );
|
31 |
-
define( 'PCLZIP_ERR_BAD_EXTENSION', -9 );
|
32 |
-
define( 'PCLZIP_ERR_BAD_FORMAT', -10 );
|
33 |
-
define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 );
|
34 |
-
define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 );
|
35 |
-
define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 );
|
36 |
-
define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 );
|
37 |
-
define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 );
|
38 |
-
define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 );
|
39 |
-
define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 );
|
40 |
-
define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 );
|
41 |
-
define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 );
|
42 |
-
define( 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20 );
|
43 |
-
define( 'PCLZIP_ERR_DIRECTORY_RESTRICTION', -21 );
|
44 |
-
define( 'PCLZIP_OPT_PATH', 77001 );
|
45 |
-
define( 'PCLZIP_OPT_ADD_PATH', 77002 );
|
46 |
-
define( 'PCLZIP_OPT_REMOVE_PATH', 77003 );
|
47 |
-
define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 );
|
48 |
-
define( 'PCLZIP_OPT_SET_CHMOD', 77005 );
|
49 |
-
define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 );
|
50 |
-
define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 );
|
51 |
-
define( 'PCLZIP_OPT_BY_NAME', 77008 );
|
52 |
-
define( 'PCLZIP_OPT_BY_INDEX', 77009 );
|
53 |
-
define( 'PCLZIP_OPT_BY_EREG', 77010 );
|
54 |
-
define( 'PCLZIP_OPT_BY_PREG', 77011 );
|
55 |
-
define( 'PCLZIP_OPT_COMMENT', 77012 );
|
56 |
-
define( 'PCLZIP_OPT_ADD_COMMENT', 77013 );
|
57 |
-
define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 );
|
58 |
-
define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 );
|
59 |
-
define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 );
|
60 |
-
define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 );
|
61 |
-
define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 );
|
62 |
-
define( 'PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020 );
|
63 |
-
define( 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020 ); // alias
|
64 |
-
define( 'PCLZIP_OPT_TEMP_FILE_ON', 77021 );
|
65 |
-
define( 'PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021 ); // alias
|
66 |
-
define( 'PCLZIP_OPT_TEMP_FILE_OFF', 77022 );
|
67 |
-
define( 'PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022 ); // alias
|
68 |
-
define( 'PCLZIP_ATT_FILE_NAME', 79001 );
|
69 |
-
define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 );
|
70 |
-
define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 );
|
71 |
-
define( 'PCLZIP_ATT_FILE_MTIME', 79004 );
|
72 |
-
define( 'PCLZIP_ATT_FILE_CONTENT', 79005 );
|
73 |
-
define( 'PCLZIP_ATT_FILE_COMMENT', 79006 );
|
74 |
-
define( 'PCLZIP_CB_PRE_EXTRACT', 78001 );
|
75 |
-
define( 'PCLZIP_CB_POST_EXTRACT', 78002 );
|
76 |
-
define( 'PCLZIP_CB_PRE_ADD', 78003 );
|
77 |
-
define( 'PCLZIP_CB_POST_ADD', 78004 );
|
78 |
-
/* For futur use
|
79 |
-
define( 'PCLZIP_CB_PRE_LIST', 78005 );
|
80 |
-
define( 'PCLZIP_CB_POST_LIST', 78006 );
|
81 |
-
define( 'PCLZIP_CB_PRE_DELETE', 78007 );
|
82 |
-
define( 'PCLZIP_CB_POST_DELETE', 78008 );
|
83 |
-
*/
|
84 |
-
class PclZip
|
85 |
-
{
|
86 |
-
var $zipname = '';
|
87 |
-
var $zip_fd = 0;
|
88 |
-
var $error_code = 1;
|
89 |
-
var $error_string = '';
|
90 |
-
var $magic_quotes_status;
|
91 |
-
function
|
92 |
-
{
|
93 |
-
if (!function_exists('gzopen'))
|
94 |
-
{
|
95 |
-
die('Abort '.basename(__FILE__).' : Missing zlib extensions');
|
96 |
-
}
|
97 |
-
$this->zipname = $p_zipname;
|
98 |
-
$this->zip_fd = 0;
|
99 |
-
$this->magic_quotes_status = -1;
|
100 |
-
return;
|
101 |
-
}
|
102 |
-
function create($p_filelist)
|
103 |
-
{
|
104 |
-
$v_result=1;
|
105 |
-
$this->privErrorReset();
|
106 |
-
$v_options = array();
|
107 |
-
$v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
|
108 |
-
$v_size = func_num_args();
|
109 |
-
if ($v_size > 1) {
|
110 |
-
$v_arg_list = func_get_args();
|
111 |
-
array_shift($v_arg_list);
|
112 |
-
$v_size--;
|
113 |
-
if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
|
114 |
-
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
|
115 |
-
array (PCLZIP_OPT_REMOVE_PATH => 'optional',
|
116 |
-
PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
|
117 |
-
PCLZIP_OPT_ADD_PATH => 'optional',
|
118 |
-
PCLZIP_CB_PRE_ADD => 'optional',
|
119 |
-
PCLZIP_CB_POST_ADD => 'optional',
|
120 |
-
PCLZIP_OPT_NO_COMPRESSION => 'optional',
|
121 |
-
PCLZIP_OPT_COMMENT => 'optional',
|
122 |
-
PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
|
123 |
-
PCLZIP_OPT_TEMP_FILE_ON => 'optional',
|
124 |
-
PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
|
125 |
-
));
|
126 |
-
if ($v_result != 1) {
|
127 |
-
return 0;
|
128 |
-
}
|
129 |
-
}
|
130 |
-
else {
|
131 |
-
$v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];
|
132 |
-
if ($v_size == 2) {
|
133 |
-
$v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
|
134 |
-
}
|
135 |
-
else if ($v_size > 2) {
|
136 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
|
137 |
-
"Invalid number / type of arguments");
|
138 |
-
return 0;
|
139 |
-
}
|
140 |
-
}
|
141 |
-
}
|
142 |
-
$this->privOptionDefaultThreshold($v_options);
|
143 |
-
$v_string_list = array();
|
144 |
-
$v_att_list = array();
|
145 |
-
$v_filedescr_list = array();
|
146 |
-
$p_result_list = array();
|
147 |
-
if (is_array($p_filelist)) {
|
148 |
-
if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
|
149 |
-
$v_att_list = $p_filelist;
|
150 |
-
}
|
151 |
-
else {
|
152 |
-
$v_string_list = $p_filelist;
|
153 |
-
}
|
154 |
-
}
|
155 |
-
else if (is_string($p_filelist)) {
|
156 |
-
$v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
|
157 |
-
}
|
158 |
-
else {
|
159 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
|
160 |
-
return 0;
|
161 |
-
}
|
162 |
-
if (sizeof($v_string_list) != 0) {
|
163 |
-
foreach ($v_string_list as $v_string) {
|
164 |
-
if ($v_string != '') {
|
165 |
-
$v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
|
166 |
-
}
|
167 |
-
else {
|
168 |
-
}
|
169 |
-
}
|
170 |
-
}
|
171 |
-
$v_supported_attributes
|
172 |
-
= array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
|
173 |
-
,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
|
174 |
-
,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
|
175 |
-
,PCLZIP_ATT_FILE_MTIME => 'optional'
|
176 |
-
,PCLZIP_ATT_FILE_CONTENT => 'optional'
|
177 |
-
,PCLZIP_ATT_FILE_COMMENT => 'optional'
|
178 |
-
);
|
179 |
-
foreach ($v_att_list as $v_entry) {
|
180 |
-
$v_result = $this->privFileDescrParseAtt($v_entry,
|
181 |
-
$v_filedescr_list[],
|
182 |
-
$v_options,
|
183 |
-
$v_supported_attributes);
|
184 |
-
if ($v_result != 1) {
|
185 |
-
return 0;
|
186 |
-
}
|
187 |
-
}
|
188 |
-
$v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
|
189 |
-
if ($v_result != 1) {
|
190 |
-
return 0;
|
191 |
-
}
|
192 |
-
$v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);
|
193 |
-
if ($v_result != 1) {
|
194 |
-
return 0;
|
195 |
-
}
|
196 |
-
return $p_result_list;
|
197 |
-
}
|
198 |
-
function add($p_filelist)
|
199 |
-
{
|
200 |
-
$v_result=1;
|
201 |
-
$this->privErrorReset();
|
202 |
-
$v_options = array();
|
203 |
-
$v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
|
204 |
-
$v_size = func_num_args();
|
205 |
-
if ($v_size > 1) {
|
206 |
-
$v_arg_list = func_get_args();
|
207 |
-
array_shift($v_arg_list);
|
208 |
-
$v_size--;
|
209 |
-
if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
|
210 |
-
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
|
211 |
-
array (PCLZIP_OPT_REMOVE_PATH => 'optional',
|
212 |
-
PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
|
213 |
-
PCLZIP_OPT_ADD_PATH => 'optional',
|
214 |
-
PCLZIP_CB_PRE_ADD => 'optional',
|
215 |
-
PCLZIP_CB_POST_ADD => 'optional',
|
216 |
-
PCLZIP_OPT_NO_COMPRESSION => 'optional',
|
217 |
-
PCLZIP_OPT_COMMENT => 'optional',
|
218 |
-
PCLZIP_OPT_ADD_COMMENT => 'optional',
|
219 |
-
PCLZIP_OPT_PREPEND_COMMENT => 'optional',
|
220 |
-
PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
|
221 |
-
PCLZIP_OPT_TEMP_FILE_ON => 'optional',
|
222 |
-
PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
|
223 |
-
));
|
224 |
-
if ($v_result != 1) {
|
225 |
-
return 0;
|
226 |
-
}
|
227 |
-
}
|
228 |
-
else {
|
229 |
-
$v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];
|
230 |
-
if ($v_size == 2) {
|
231 |
-
$v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
|
232 |
-
}
|
233 |
-
else if ($v_size > 2) {
|
234 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
|
235 |
-
return 0;
|
236 |
-
}
|
237 |
-
}
|
238 |
-
}
|
239 |
-
$this->privOptionDefaultThreshold($v_options);
|
240 |
-
$v_string_list = array();
|
241 |
-
$v_att_list = array();
|
242 |
-
$v_filedescr_list = array();
|
243 |
-
$p_result_list = array();
|
244 |
-
if (is_array($p_filelist)) {
|
245 |
-
if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
|
246 |
-
$v_att_list = $p_filelist;
|
247 |
-
}
|
248 |
-
else {
|
249 |
-
$v_string_list = $p_filelist;
|
250 |
-
}
|
251 |
-
}
|
252 |
-
else if (is_string($p_filelist)) {
|
253 |
-
$v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
|
254 |
-
}
|
255 |
-
else {
|
256 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");
|
257 |
-
return 0;
|
258 |
-
}
|
259 |
-
if (sizeof($v_string_list) != 0) {
|
260 |
-
foreach ($v_string_list as $v_string) {
|
261 |
-
$v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
|
262 |
-
}
|
263 |
-
}
|
264 |
-
$v_supported_attributes
|
265 |
-
= array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
|
266 |
-
,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
|
267 |
-
,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
|
268 |
-
,PCLZIP_ATT_FILE_MTIME => 'optional'
|
269 |
-
,PCLZIP_ATT_FILE_CONTENT => 'optional'
|
270 |
-
,PCLZIP_ATT_FILE_COMMENT => 'optional'
|
271 |
-
);
|
272 |
-
foreach ($v_att_list as $v_entry) {
|
273 |
-
$v_result = $this->privFileDescrParseAtt($v_entry,
|
274 |
-
$v_filedescr_list[],
|
275 |
-
$v_options,
|
276 |
-
$v_supported_attributes);
|
277 |
-
if ($v_result != 1) {
|
278 |
-
return 0;
|
279 |
-
}
|
280 |
-
}
|
281 |
-
$v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
|
282 |
-
if ($v_result != 1) {
|
283 |
-
return 0;
|
284 |
-
}
|
285 |
-
$v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);
|
286 |
-
if ($v_result != 1) {
|
287 |
-
return 0;
|
288 |
-
}
|
289 |
-
return $p_result_list;
|
290 |
-
}
|
291 |
-
function listContent()
|
292 |
-
{
|
293 |
-
$v_result=1;
|
294 |
-
$this->privErrorReset();
|
295 |
-
if (!$this->privCheckFormat()) {
|
296 |
-
return(0);
|
297 |
-
}
|
298 |
-
$p_list = array();
|
299 |
-
if (($v_result = $this->privList($p_list)) != 1)
|
300 |
-
{
|
301 |
-
unset($p_list);
|
302 |
-
return(0);
|
303 |
-
}
|
304 |
-
return $p_list;
|
305 |
-
}
|
306 |
-
function extract()
|
307 |
-
{
|
308 |
-
$v_result=1;
|
309 |
-
$this->privErrorReset();
|
310 |
-
if (!$this->privCheckFormat()) {
|
311 |
-
return(0);
|
312 |
-
}
|
313 |
-
$v_options = array();
|
314 |
-
// $v_path = "./";
|
315 |
-
$v_path = '';
|
316 |
-
$v_remove_path = "";
|
317 |
-
$v_remove_all_path = false;
|
318 |
-
$v_size = func_num_args();
|
319 |
-
$v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
|
320 |
-
if ($v_size > 0) {
|
321 |
-
$v_arg_list = func_get_args();
|
322 |
-
if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
|
323 |
-
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
|
324 |
-
array (PCLZIP_OPT_PATH => 'optional',
|
325 |
-
PCLZIP_OPT_REMOVE_PATH => 'optional',
|
326 |
-
PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
|
327 |
-
PCLZIP_OPT_ADD_PATH => 'optional',
|
328 |
-
PCLZIP_CB_PRE_EXTRACT => 'optional',
|
329 |
-
PCLZIP_CB_POST_EXTRACT => 'optional',
|
330 |
-
PCLZIP_OPT_SET_CHMOD => 'optional',
|
331 |
-
PCLZIP_OPT_BY_NAME => 'optional',
|
332 |
-
PCLZIP_OPT_BY_EREG => 'optional',
|
333 |
-
PCLZIP_OPT_BY_PREG => 'optional',
|
334 |
-
PCLZIP_OPT_BY_INDEX => 'optional',
|
335 |
-
PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
|
336 |
-
PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
|
337 |
-
PCLZIP_OPT_REPLACE_NEWER => 'optional'
|
338 |
-
,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
|
339 |
-
,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
|
340 |
-
PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
|
341 |
-
PCLZIP_OPT_TEMP_FILE_ON => 'optional',
|
342 |
-
PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
|
343 |
-
));
|
344 |
-
if ($v_result != 1) {
|
345 |
-
return 0;
|
346 |
-
}
|
347 |
-
if (isset($v_options[PCLZIP_OPT_PATH])) {
|
348 |
-
$v_path = $v_options[PCLZIP_OPT_PATH];
|
349 |
-
}
|
350 |
-
if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
|
351 |
-
$v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
|
352 |
-
}
|
353 |
-
if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
|
354 |
-
$v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
|
355 |
-
}
|
356 |
-
if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
|
357 |
-
if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
|
358 |
-
$v_path .= '/';
|
359 |
-
}
|
360 |
-
$v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
|
361 |
-
}
|
362 |
-
}
|
363 |
-
else {
|
364 |
-
$v_path = $v_arg_list[0];
|
365 |
-
if ($v_size == 2) {
|
366 |
-
$v_remove_path = $v_arg_list[1];
|
367 |
-
}
|
368 |
-
else if ($v_size > 2) {
|
369 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
|
370 |
-
return 0;
|
371 |
-
}
|
372 |
-
}
|
373 |
-
}
|
374 |
-
$this->privOptionDefaultThreshold($v_options);
|
375 |
-
$p_list = array();
|
376 |
-
$v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,
|
377 |
-
$v_remove_all_path, $v_options);
|
378 |
-
if ($v_result < 1) {
|
379 |
-
unset($p_list);
|
380 |
-
return(0);
|
381 |
-
}
|
382 |
-
return $p_list;
|
383 |
-
}
|
384 |
-
function extractByIndex($p_index)
|
385 |
-
{
|
386 |
-
$v_result=1;
|
387 |
-
$this->privErrorReset();
|
388 |
-
if (!$this->privCheckFormat()) {
|
389 |
-
return(0);
|
390 |
-
}
|
391 |
-
$v_options = array();
|
392 |
-
// $v_path = "./";
|
393 |
-
$v_path = '';
|
394 |
-
$v_remove_path = "";
|
395 |
-
$v_remove_all_path = false;
|
396 |
-
$v_size = func_num_args();
|
397 |
-
$v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
|
398 |
-
if ($v_size > 1) {
|
399 |
-
$v_arg_list = func_get_args();
|
400 |
-
array_shift($v_arg_list);
|
401 |
-
$v_size--;
|
402 |
-
if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
|
403 |
-
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
|
404 |
-
array (PCLZIP_OPT_PATH => 'optional',
|
405 |
-
PCLZIP_OPT_REMOVE_PATH => 'optional',
|
406 |
-
PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
|
407 |
-
PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
|
408 |
-
PCLZIP_OPT_ADD_PATH => 'optional',
|
409 |
-
PCLZIP_CB_PRE_EXTRACT => 'optional',
|
410 |
-
PCLZIP_CB_POST_EXTRACT => 'optional',
|
411 |
-
PCLZIP_OPT_SET_CHMOD => 'optional',
|
412 |
-
PCLZIP_OPT_REPLACE_NEWER => 'optional'
|
413 |
-
,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
|
414 |
-
,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
|
415 |
-
PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
|
416 |
-
PCLZIP_OPT_TEMP_FILE_ON => 'optional',
|
417 |
-
PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
|
418 |
-
));
|
419 |
-
if ($v_result != 1) {
|
420 |
-
return 0;
|
421 |
-
}
|
422 |
-
if (isset($v_options[PCLZIP_OPT_PATH])) {
|
423 |
-
$v_path = $v_options[PCLZIP_OPT_PATH];
|
424 |
-
}
|
425 |
-
if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
|
426 |
-
$v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
|
427 |
-
}
|
428 |
-
if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
|
429 |
-
$v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
|
430 |
-
}
|
431 |
-
if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
|
432 |
-
if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
|
433 |
-
$v_path .= '/';
|
434 |
-
}
|
435 |
-
$v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
|
436 |
-
}
|
437 |
-
if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
|
438 |
-
$v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
|
439 |
-
}
|
440 |
-
else {
|
441 |
-
}
|
442 |
-
}
|
443 |
-
else {
|
444 |
-
$v_path = $v_arg_list[0];
|
445 |
-
if ($v_size == 2) {
|
446 |
-
$v_remove_path = $v_arg_list[1];
|
447 |
-
}
|
448 |
-
else if ($v_size > 2) {
|
449 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
|
450 |
-
return 0;
|
451 |
-
}
|
452 |
-
}
|
453 |
-
}
|
454 |
-
$v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
|
455 |
-
$v_options_trick = array();
|
456 |
-
$v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,
|
457 |
-
array (PCLZIP_OPT_BY_INDEX => 'optional' ));
|
458 |
-
if ($v_result != 1) {
|
459 |
-
return 0;
|
460 |
-
}
|
461 |
-
$v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
|
462 |
-
$this->privOptionDefaultThreshold($v_options);
|
463 |
-
if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
|
464 |
-
return(0);
|
465 |
-
}
|
466 |
-
return $p_list;
|
467 |
-
}
|
468 |
-
function delete()
|
469 |
-
{
|
470 |
-
$v_result=1;
|
471 |
-
$this->privErrorReset();
|
472 |
-
if (!$this->privCheckFormat()) {
|
473 |
-
return(0);
|
474 |
-
}
|
475 |
-
$v_options = array();
|
476 |
-
$v_size = func_num_args();
|
477 |
-
if ($v_size > 0) {
|
478 |
-
$v_arg_list = func_get_args();
|
479 |
-
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
|
480 |
-
array (PCLZIP_OPT_BY_NAME => 'optional',
|
481 |
-
PCLZIP_OPT_BY_EREG => 'optional',
|
482 |
-
PCLZIP_OPT_BY_PREG => 'optional',
|
483 |
-
PCLZIP_OPT_BY_INDEX => 'optional' ));
|
484 |
-
if ($v_result != 1) {
|
485 |
-
return 0;
|
486 |
-
}
|
487 |
-
}
|
488 |
-
$this->privDisableMagicQuotes();
|
489 |
-
$v_list = array();
|
490 |
-
if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
|
491 |
-
$this->privSwapBackMagicQuotes();
|
492 |
-
unset($v_list);
|
493 |
-
return(0);
|
494 |
-
}
|
495 |
-
$this->privSwapBackMagicQuotes();
|
496 |
-
return $v_list;
|
497 |
-
}
|
498 |
-
function deleteByIndex($p_index)
|
499 |
-
{
|
500 |
-
$p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
|
501 |
-
return $p_list;
|
502 |
-
}
|
503 |
-
function properties()
|
504 |
-
{
|
505 |
-
$this->privErrorReset();
|
506 |
-
$this->privDisableMagicQuotes();
|
507 |
-
if (!$this->privCheckFormat()) {
|
508 |
-
$this->privSwapBackMagicQuotes();
|
509 |
-
return(0);
|
510 |
-
}
|
511 |
-
$v_prop = array();
|
512 |
-
$v_prop['comment'] = '';
|
513 |
-
$v_prop['nb'] = 0;
|
514 |
-
$v_prop['status'] = 'not_exist';
|
515 |
-
if (@is_file($this->zipname))
|
516 |
-
{
|
517 |
-
if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
|
518 |
-
{
|
519 |
-
$this->privSwapBackMagicQuotes();
|
520 |
-
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
|
521 |
-
return 0;
|
522 |
-
}
|
523 |
-
$v_central_dir = array();
|
524 |
-
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
|
525 |
-
{
|
526 |
-
$this->privSwapBackMagicQuotes();
|
527 |
-
return 0;
|
528 |
-
}
|
529 |
-
$this->privCloseFd();
|
530 |
-
$v_prop['comment'] = $v_central_dir['comment'];
|
531 |
-
$v_prop['nb'] = $v_central_dir['entries'];
|
532 |
-
$v_prop['status'] = 'ok';
|
533 |
-
}
|
534 |
-
$this->privSwapBackMagicQuotes();
|
535 |
-
return $v_prop;
|
536 |
-
}
|
537 |
-
function duplicate($p_archive)
|
538 |
-
{
|
539 |
-
$v_result = 1;
|
540 |
-
$this->privErrorReset();
|
541 |
-
if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
|
542 |
-
{
|
543 |
-
$v_result = $this->privDuplicate($p_archive->zipname);
|
544 |
-
}
|
545 |
-
else if (is_string($p_archive))
|
546 |
-
{
|
547 |
-
if (!is_file($p_archive)) {
|
548 |
-
PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
|
549 |
-
$v_result = PCLZIP_ERR_MISSING_FILE;
|
550 |
-
}
|
551 |
-
else {
|
552 |
-
$v_result = $this->privDuplicate($p_archive);
|
553 |
-
}
|
554 |
-
}
|
555 |
-
else
|
556 |
-
{
|
557 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
|
558 |
-
$v_result = PCLZIP_ERR_INVALID_PARAMETER;
|
559 |
-
}
|
560 |
-
return $v_result;
|
561 |
-
}
|
562 |
-
function merge($p_archive_to_add)
|
563 |
-
{
|
564 |
-
$v_result = 1;
|
565 |
-
$this->privErrorReset();
|
566 |
-
if (!$this->privCheckFormat()) {
|
567 |
-
return(0);
|
568 |
-
}
|
569 |
-
if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
|
570 |
-
{
|
571 |
-
$v_result = $this->privMerge($p_archive_to_add);
|
572 |
-
}
|
573 |
-
else if (is_string($p_archive_to_add))
|
574 |
-
{
|
575 |
-
$v_object_archive = new PclZip($p_archive_to_add);
|
576 |
-
$v_result = $this->privMerge($v_object_archive);
|
577 |
-
}
|
578 |
-
else
|
579 |
-
{
|
580 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
|
581 |
-
$v_result = PCLZIP_ERR_INVALID_PARAMETER;
|
582 |
-
}
|
583 |
-
return $v_result;
|
584 |
-
}
|
585 |
-
function errorCode()
|
586 |
-
{
|
587 |
-
if (PCLZIP_ERROR_EXTERNAL == 1) {
|
588 |
-
return(PclErrorCode());
|
589 |
-
}
|
590 |
-
else {
|
591 |
-
return($this->error_code);
|
592 |
-
}
|
593 |
-
}
|
594 |
-
function errorName($p_with_code=false)
|
595 |
-
{
|
596 |
-
$v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
|
597 |
-
PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
|
598 |
-
PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
|
599 |
-
PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
|
600 |
-
PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
|
601 |
-
PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
|
602 |
-
PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
|
603 |
-
PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
|
604 |
-
PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
|
605 |
-
PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
|
606 |
-
PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
|
607 |
-
PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
|
608 |
-
PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
|
609 |
-
PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
|
610 |
-
PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
|
611 |
-
PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
|
612 |
-
PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
|
613 |
-
PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',
|
614 |
-
PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION'
|
615 |
-
,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE'
|
616 |
-
,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION'
|
617 |
-
);
|
618 |
-
if (isset($v_name[$this->error_code])) {
|
619 |
-
$v_value = $v_name[$this->error_code];
|
620 |
-
}
|
621 |
-
else {
|
622 |
-
$v_value = 'NoName';
|
623 |
-
}
|
624 |
-
if ($p_with_code) {
|
625 |
-
return($v_value.' ('.$this->error_code.')');
|
626 |
-
}
|
627 |
-
else {
|
628 |
-
return($v_value);
|
629 |
-
}
|
630 |
-
}
|
631 |
-
function errorInfo($p_full=false)
|
632 |
-
{
|
633 |
-
if (PCLZIP_ERROR_EXTERNAL == 1) {
|
634 |
-
return(PclErrorString());
|
635 |
-
}
|
636 |
-
else {
|
637 |
-
if ($p_full) {
|
638 |
-
return($this->errorName(true)." : ".$this->error_string);
|
639 |
-
}
|
640 |
-
else {
|
641 |
-
return($this->error_string." [code ".$this->error_code."]");
|
642 |
-
}
|
643 |
-
}
|
644 |
-
}
|
645 |
-
// --------------------------------------------------------------------------------
|
646 |
-
// ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS *****
|
647 |
-
// ***** *****
|
648 |
-
// ***** THESES FUNCTIONS MUST NOT BE USED DIRECTLY *****
|
649 |
-
// --------------------------------------------------------------------------------
|
650 |
-
function privCheckFormat($p_level=0)
|
651 |
-
{
|
652 |
-
$v_result = true;
|
653 |
-
// ----- Reset the file system cache
|
654 |
-
clearstatcache();
|
655 |
-
$this->privErrorReset();
|
656 |
-
if (!is_file($this->zipname)) {
|
657 |
-
PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");
|
658 |
-
return(false);
|
659 |
-
}
|
660 |
-
if (!is_readable($this->zipname)) {
|
661 |
-
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");
|
662 |
-
return(false);
|
663 |
-
}
|
664 |
-
return $v_result;
|
665 |
-
}
|
666 |
-
function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false)
|
667 |
-
{
|
668 |
-
$v_result=1;
|
669 |
-
$i=0;
|
670 |
-
while ($i<$p_size) {
|
671 |
-
if (!isset($v_requested_options[$p_options_list[$i]])) {
|
672 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");
|
673 |
-
return PclZip::errorCode();
|
674 |
-
}
|
675 |
-
switch ($p_options_list[$i]) {
|
676 |
-
case PCLZIP_OPT_PATH :
|
677 |
-
case PCLZIP_OPT_REMOVE_PATH :
|
678 |
-
case PCLZIP_OPT_ADD_PATH :
|
679 |
-
if (($i+1) >= $p_size) {
|
680 |
-
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
681 |
-
return PclZip::errorCode();
|
682 |
-
}
|
683 |
-
$v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
|
684 |
-
$i++;
|
685 |
-
break;
|
686 |
-
case PCLZIP_OPT_TEMP_FILE_THRESHOLD :
|
687 |
-
if (($i+1) >= $p_size) {
|
688 |
-
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
689 |
-
return PclZip::errorCode();
|
690 |
-
}
|
691 |
-
if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
|
692 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
|
693 |
-
return PclZip::errorCode();
|
694 |
-
}
|
695 |
-
$v_value = $p_options_list[$i+1];
|
696 |
-
if ((!is_integer($v_value)) || ($v_value<0)) {
|
697 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
698 |
-
return PclZip::errorCode();
|
699 |
-
}
|
700 |
-
$v_result_list[$p_options_list[$i]] = $v_value*1048576;
|
701 |
-
$i++;
|
702 |
-
break;
|
703 |
-
case PCLZIP_OPT_TEMP_FILE_ON :
|
704 |
-
if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
|
705 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
|
706 |
-
return PclZip::errorCode();
|
707 |
-
}
|
708 |
-
$v_result_list[$p_options_list[$i]] = true;
|
709 |
-
break;
|
710 |
-
case PCLZIP_OPT_TEMP_FILE_OFF :
|
711 |
-
if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) {
|
712 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'");
|
713 |
-
return PclZip::errorCode();
|
714 |
-
}
|
715 |
-
if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
|
716 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'");
|
717 |
-
return PclZip::errorCode();
|
718 |
-
}
|
719 |
-
$v_result_list[$p_options_list[$i]] = true;
|
720 |
-
break;
|
721 |
-
case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION :
|
722 |
-
if (($i+1) >= $p_size) {
|
723 |
-
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
724 |
-
return PclZip::errorCode();
|
725 |
-
}
|
726 |
-
if ( is_string($p_options_list[$i+1])
|
727 |
-
&& ($p_options_list[$i+1] != '')) {
|
728 |
-
$v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
|
729 |
-
$i++;
|
730 |
-
}
|
731 |
-
else {
|
732 |
-
}
|
733 |
-
break;
|
734 |
-
case PCLZIP_OPT_BY_NAME :
|
735 |
-
if (($i+1) >= $p_size) {
|
736 |
-
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
737 |
-
return PclZip::errorCode();
|
738 |
-
}
|
739 |
-
if (is_string($p_options_list[$i+1])) {
|
740 |
-
$v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1];
|
741 |
-
}
|
742 |
-
else if (is_array($p_options_list[$i+1])) {
|
743 |
-
$v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
|
744 |
-
}
|
745 |
-
else {
|
746 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
747 |
-
return PclZip::errorCode();
|
748 |
-
}
|
749 |
-
$i++;
|
750 |
-
break;
|
751 |
-
case PCLZIP_OPT_BY_EREG :
|
752 |
-
$p_options_list[$i] = PCLZIP_OPT_BY_PREG;
|
753 |
-
case PCLZIP_OPT_BY_PREG :
|
754 |
-
if (($i+1) >= $p_size) {
|
755 |
-
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
756 |
-
return PclZip::errorCode();
|
757 |
-
}
|
758 |
-
if (is_string($p_options_list[$i+1])) {
|
759 |
-
$v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
|
760 |
-
}
|
761 |
-
else {
|
762 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
763 |
-
return PclZip::errorCode();
|
764 |
-
}
|
765 |
-
$i++;
|
766 |
-
break;
|
767 |
-
case PCLZIP_OPT_COMMENT :
|
768 |
-
case PCLZIP_OPT_ADD_COMMENT :
|
769 |
-
case PCLZIP_OPT_PREPEND_COMMENT :
|
770 |
-
if (($i+1) >= $p_size) {
|
771 |
-
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE,
|
772 |
-
"Missing parameter value for option '"
|
773 |
-
.PclZipUtilOptionText($p_options_list[$i])
|
774 |
-
."'");
|
775 |
-
return PclZip::errorCode();
|
776 |
-
}
|
777 |
-
if (is_string($p_options_list[$i+1])) {
|
778 |
-
$v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
|
779 |
-
}
|
780 |
-
else {
|
781 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE,
|
782 |
-
"Wrong parameter value for option '"
|
783 |
-
.PclZipUtilOptionText($p_options_list[$i])
|
784 |
-
."'");
|
785 |
-
return PclZip::errorCode();
|
786 |
-
}
|
787 |
-
$i++;
|
788 |
-
break;
|
789 |
-
case PCLZIP_OPT_BY_INDEX :
|
790 |
-
if (($i+1) >= $p_size) {
|
791 |
-
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
792 |
-
return PclZip::errorCode();
|
793 |
-
}
|
794 |
-
$v_work_list = array();
|
795 |
-
if (is_string($p_options_list[$i+1])) {
|
796 |
-
$p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', '');
|
797 |
-
$v_work_list = explode(",", $p_options_list[$i+1]);
|
798 |
-
}
|
799 |
-
else if (is_integer($p_options_list[$i+1])) {
|
800 |
-
$v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1];
|
801 |
-
}
|
802 |
-
else if (is_array($p_options_list[$i+1])) {
|
803 |
-
$v_work_list = $p_options_list[$i+1];
|
804 |
-
}
|
805 |
-
else {
|
806 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
807 |
-
return PclZip::errorCode();
|
808 |
-
}
|
809 |
-
$v_sort_flag=false;
|
810 |
-
$v_sort_value=0;
|
811 |
-
for ($j=0; $j<sizeof($v_work_list); $j++) {
|
812 |
-
$v_item_list = explode("-", $v_work_list[$j]);
|
813 |
-
$v_size_item_list = sizeof($v_item_list);
|
814 |
-
if ($v_size_item_list == 1) {
|
815 |
-
$v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
|
816 |
-
$v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0];
|
817 |
-
}
|
818 |
-
elseif ($v_size_item_list == 2) {
|
819 |
-
$v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
|
820 |
-
$v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1];
|
821 |
-
}
|
822 |
-
else {
|
823 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
824 |
-
return PclZip::errorCode();
|
825 |
-
}
|
826 |
-
if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) {
|
827 |
-
$v_sort_flag=true;
|
828 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
829 |
-
return PclZip::errorCode();
|
830 |
-
}
|
831 |
-
$v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start'];
|
832 |
-
}
|
833 |
-
if ($v_sort_flag) {
|
834 |
-
}
|
835 |
-
$i++;
|
836 |
-
break;
|
837 |
-
case PCLZIP_OPT_REMOVE_ALL_PATH :
|
838 |
-
case PCLZIP_OPT_EXTRACT_AS_STRING :
|
839 |
-
case PCLZIP_OPT_NO_COMPRESSION :
|
840 |
-
case PCLZIP_OPT_EXTRACT_IN_OUTPUT :
|
841 |
-
case PCLZIP_OPT_REPLACE_NEWER :
|
842 |
-
case PCLZIP_OPT_STOP_ON_ERROR :
|
843 |
-
$v_result_list[$p_options_list[$i]] = true;
|
844 |
-
break;
|
845 |
-
case PCLZIP_OPT_SET_CHMOD :
|
846 |
-
if (($i+1) >= $p_size) {
|
847 |
-
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
848 |
-
return PclZip::errorCode();
|
849 |
-
}
|
850 |
-
$v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
|
851 |
-
$i++;
|
852 |
-
break;
|
853 |
-
case PCLZIP_CB_PRE_EXTRACT :
|
854 |
-
case PCLZIP_CB_POST_EXTRACT :
|
855 |
-
case PCLZIP_CB_PRE_ADD :
|
856 |
-
case PCLZIP_CB_POST_ADD :
|
857 |
-
/* for futur use
|
858 |
-
case PCLZIP_CB_PRE_DELETE :
|
859 |
-
case PCLZIP_CB_POST_DELETE :
|
860 |
-
case PCLZIP_CB_PRE_LIST :
|
861 |
-
case PCLZIP_CB_POST_LIST :
|
862 |
-
*/
|
863 |
-
if (($i+1) >= $p_size) {
|
864 |
-
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
865 |
-
return PclZip::errorCode();
|
866 |
-
}
|
867 |
-
$v_function_name = $p_options_list[$i+1];
|
868 |
-
if (!function_exists($v_function_name)) {
|
869 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
870 |
-
return PclZip::errorCode();
|
871 |
-
}
|
872 |
-
$v_result_list[$p_options_list[$i]] = $v_function_name;
|
873 |
-
$i++;
|
874 |
-
break;
|
875 |
-
default :
|
876 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
|
877 |
-
"Unknown parameter '"
|
878 |
-
.$p_options_list[$i]."'");
|
879 |
-
return PclZip::errorCode();
|
880 |
-
}
|
881 |
-
$i++;
|
882 |
-
}
|
883 |
-
if ($v_requested_options !== false) {
|
884 |
-
for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
|
885 |
-
if ($v_requested_options[$key] == 'mandatory') {
|
886 |
-
if (!isset($v_result_list[$key])) {
|
887 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
|
888 |
-
return PclZip::errorCode();
|
889 |
-
}
|
890 |
-
}
|
891 |
-
}
|
892 |
-
}
|
893 |
-
if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
|
894 |
-
}
|
895 |
-
return $v_result;
|
896 |
-
}
|
897 |
-
function privOptionDefaultThreshold(&$p_options)
|
898 |
-
{
|
899 |
-
$v_result=1;
|
900 |
-
if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
|
901 |
-
|| isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) {
|
902 |
-
return $v_result;
|
903 |
-
}
|
904 |
-
$v_memory_limit = ini_get('memory_limit');
|
905 |
-
$v_memory_limit = trim($v_memory_limit);
|
906 |
-
$last = strtolower(substr($v_memory_limit, -1));
|
907 |
-
if($last == 'g')
|
908 |
-
$v_memory_limit = $v_memory_limit*1073741824;
|
909 |
-
if($last == 'm')
|
910 |
-
$v_memory_limit = $v_memory_limit*1048576;
|
911 |
-
if($last == 'k')
|
912 |
-
$v_memory_limit = $v_memory_limit*1024;
|
913 |
-
$p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO);
|
914 |
-
if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) {
|
915 |
-
unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]);
|
916 |
-
}
|
917 |
-
return $v_result;
|
918 |
-
}
|
919 |
-
function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false)
|
920 |
-
{
|
921 |
-
$v_result=1;
|
922 |
-
foreach ($p_file_list as $v_key => $v_value) {
|
923 |
-
if (!isset($v_requested_options[$v_key])) {
|
924 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file");
|
925 |
-
return PclZip::errorCode();
|
926 |
-
}
|
927 |
-
switch ($v_key) {
|
928 |
-
case PCLZIP_ATT_FILE_NAME :
|
929 |
-
if (!is_string($v_value)) {
|
930 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
|
931 |
-
return PclZip::errorCode();
|
932 |
-
}
|
933 |
-
$p_filedescr['filename'] = PclZipUtilPathReduction($v_value);
|
934 |
-
if ($p_filedescr['filename'] == '') {
|
935 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'");
|
936 |
-
return PclZip::errorCode();
|
937 |
-
}
|
938 |
-
break;
|
939 |
-
case PCLZIP_ATT_FILE_NEW_SHORT_NAME :
|
940 |
-
if (!is_string($v_value)) {
|
941 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
|
942 |
-
return PclZip::errorCode();
|
943 |
-
}
|
944 |
-
$p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value);
|
945 |
-
if ($p_filedescr['new_short_name'] == '') {
|
946 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'");
|
947 |
-
return PclZip::errorCode();
|
948 |
-
}
|
949 |
-
break;
|
950 |
-
case PCLZIP_ATT_FILE_NEW_FULL_NAME :
|
951 |
-
if (!is_string($v_value)) {
|
952 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
|
953 |
-
return PclZip::errorCode();
|
954 |
-
}
|
955 |
-
$p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value);
|
956 |
-
if ($p_filedescr['new_full_name'] == '') {
|
957 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'");
|
958 |
-
return PclZip::errorCode();
|
959 |
-
}
|
960 |
-
break;
|
961 |
-
case PCLZIP_ATT_FILE_COMMENT :
|
962 |
-
if (!is_string($v_value)) {
|
963 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
|
964 |
-
return PclZip::errorCode();
|
965 |
-
}
|
966 |
-
$p_filedescr['comment'] = $v_value;
|
967 |
-
break;
|
968 |
-
case PCLZIP_ATT_FILE_MTIME :
|
969 |
-
if (!is_integer($v_value)) {
|
970 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'");
|
971 |
-
return PclZip::errorCode();
|
972 |
-
}
|
973 |
-
$p_filedescr['mtime'] = $v_value;
|
974 |
-
break;
|
975 |
-
case PCLZIP_ATT_FILE_CONTENT :
|
976 |
-
$p_filedescr['content'] = $v_value;
|
977 |
-
break;
|
978 |
-
default :
|
979 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
|
980 |
-
"Unknown parameter '".$v_key."'");
|
981 |
-
return PclZip::errorCode();
|
982 |
-
}
|
983 |
-
if ($v_requested_options !== false) {
|
984 |
-
for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
|
985 |
-
if ($v_requested_options[$key] == 'mandatory') {
|
986 |
-
if (!isset($p_file_list[$key])) {
|
987 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
|
988 |
-
return PclZip::errorCode();
|
989 |
-
}
|
990 |
-
}
|
991 |
-
}
|
992 |
-
}
|
993 |
-
}
|
994 |
-
return $v_result;
|
995 |
-
}
|
996 |
-
function privFileDescrExpand(&$p_filedescr_list, &$p_options)
|
997 |
-
{
|
998 |
-
$v_result=1;
|
999 |
-
$v_result_list = array();
|
1000 |
-
for ($i=0; $i<sizeof($p_filedescr_list); $i++) {
|
1001 |
-
$v_descr = $p_filedescr_list[$i];
|
1002 |
-
$v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false);
|
1003 |
-
$v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']);
|
1004 |
-
if (file_exists($v_descr['filename'])) {
|
1005 |
-
if (@is_file($v_descr['filename'])) {
|
1006 |
-
$v_descr['type'] = 'file';
|
1007 |
-
}
|
1008 |
-
else if (@is_dir($v_descr['filename'])) {
|
1009 |
-
$v_descr['type'] = 'folder';
|
1010 |
-
}
|
1011 |
-
else if (@is_link($v_descr['filename'])) {
|
1012 |
-
continue;
|
1013 |
-
}
|
1014 |
-
else {
|
1015 |
-
continue;
|
1016 |
-
}
|
1017 |
-
}
|
1018 |
-
else if (isset($v_descr['content'])) {
|
1019 |
-
$v_descr['type'] = 'virtual_file';
|
1020 |
-
}
|
1021 |
-
else {
|
1022 |
-
PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist");
|
1023 |
-
return PclZip::errorCode();
|
1024 |
-
}
|
1025 |
-
$this->privCalculateStoredFilename($v_descr, $p_options);
|
1026 |
-
$v_result_list[sizeof($v_result_list)] = $v_descr;
|
1027 |
-
if ($v_descr['type'] == 'folder') {
|
1028 |
-
$v_dirlist_descr = array();
|
1029 |
-
$v_dirlist_nb = 0;
|
1030 |
-
if ($v_folder_handler = @opendir($v_descr['filename'])) {
|
1031 |
-
while (($v_item_handler = @readdir($v_folder_handler)) !== false) {
|
1032 |
-
if (($v_item_handler == '.') || ($v_item_handler == '..')) {
|
1033 |
-
continue;
|
1034 |
-
}
|
1035 |
-
$v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler;
|
1036 |
-
if (($v_descr['stored_filename'] != $v_descr['filename'])
|
1037 |
-
&& (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) {
|
1038 |
-
if ($v_descr['stored_filename'] != '') {
|
1039 |
-
$v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler;
|
1040 |
-
}
|
1041 |
-
else {
|
1042 |
-
$v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler;
|
1043 |
-
}
|
1044 |
-
}
|
1045 |
-
$v_dirlist_nb++;
|
1046 |
-
}
|
1047 |
-
@closedir($v_folder_handler);
|
1048 |
-
}
|
1049 |
-
else {
|
1050 |
-
}
|
1051 |
-
if ($v_dirlist_nb != 0) {
|
1052 |
-
if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) {
|
1053 |
-
return $v_result;
|
1054 |
-
}
|
1055 |
-
$v_result_list = array_merge($v_result_list, $v_dirlist_descr);
|
1056 |
-
}
|
1057 |
-
else {
|
1058 |
-
}
|
1059 |
-
unset($v_dirlist_descr);
|
1060 |
-
}
|
1061 |
-
}
|
1062 |
-
$p_filedescr_list = $v_result_list;
|
1063 |
-
return $v_result;
|
1064 |
-
}
|
1065 |
-
function privCreate($p_filedescr_list, &$p_result_list, &$p_options)
|
1066 |
-
{
|
1067 |
-
$v_result=1;
|
1068 |
-
$v_list_detail = array();
|
1069 |
-
$this->privDisableMagicQuotes();
|
1070 |
-
if (($v_result = $this->privOpenFd('wb')) != 1)
|
1071 |
-
{
|
1072 |
-
return $v_result;
|
1073 |
-
}
|
1074 |
-
$v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options);
|
1075 |
-
$this->privCloseFd();
|
1076 |
-
$this->privSwapBackMagicQuotes();
|
1077 |
-
return $v_result;
|
1078 |
-
}
|
1079 |
-
function privAdd($p_filedescr_list, &$p_result_list, &$p_options)
|
1080 |
-
{
|
1081 |
-
$v_result=1;
|
1082 |
-
$v_list_detail = array();
|
1083 |
-
if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0))
|
1084 |
-
{
|
1085 |
-
$v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options);
|
1086 |
-
return $v_result;
|
1087 |
-
}
|
1088 |
-
$this->privDisableMagicQuotes();
|
1089 |
-
if (($v_result=$this->privOpenFd('rb')) != 1)
|
1090 |
-
{
|
1091 |
-
$this->privSwapBackMagicQuotes();
|
1092 |
-
return $v_result;
|
1093 |
-
}
|
1094 |
-
$v_central_dir = array();
|
1095 |
-
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
|
1096 |
-
{
|
1097 |
-
$this->privCloseFd();
|
1098 |
-
$this->privSwapBackMagicQuotes();
|
1099 |
-
return $v_result;
|
1100 |
-
}
|
1101 |
-
@rewind($this->zip_fd);
|
1102 |
-
$v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
|
1103 |
-
if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
|
1104 |
-
{
|
1105 |
-
$this->privCloseFd();
|
1106 |
-
$this->privSwapBackMagicQuotes();
|
1107 |
-
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
|
1108 |
-
return PclZip::errorCode();
|
1109 |
-
}
|
1110 |
-
$v_size = $v_central_dir['offset'];
|
1111 |
-
while ($v_size != 0)
|
1112 |
-
{
|
1113 |
-
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
1114 |
-
$v_buffer = fread($this->zip_fd, $v_read_size);
|
1115 |
-
@fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
|
1116 |
-
$v_size -= $v_read_size;
|
1117 |
-
}
|
1118 |
-
$v_swap = $this->zip_fd;
|
1119 |
-
$this->zip_fd = $v_zip_temp_fd;
|
1120 |
-
$v_zip_temp_fd = $v_swap;
|
1121 |
-
$v_header_list = array();
|
1122 |
-
if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
|
1123 |
-
{
|
1124 |
-
fclose($v_zip_temp_fd);
|
1125 |
-
$this->privCloseFd();
|
1126 |
-
@unlink($v_zip_temp_name);
|
1127 |
-
$this->privSwapBackMagicQuotes();
|
1128 |
-
return $v_result;
|
1129 |
-
}
|
1130 |
-
$v_offset = @ftell($this->zip_fd);
|
1131 |
-
$v_size = $v_central_dir['size'];
|
1132 |
-
while ($v_size != 0)
|
1133 |
-
{
|
1134 |
-
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
1135 |
-
$v_buffer = @fread($v_zip_temp_fd, $v_read_size);
|
1136 |
-
@fwrite($this->zip_fd, $v_buffer, $v_read_size);
|
1137 |
-
$v_size -= $v_read_size;
|
1138 |
-
}
|
1139 |
-
for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++)
|
1140 |
-
{
|
1141 |
-
if ($v_header_list[$i]['status'] == 'ok') {
|
1142 |
-
if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
|
1143 |
-
fclose($v_zip_temp_fd);
|
1144 |
-
$this->privCloseFd();
|
1145 |
-
@unlink($v_zip_temp_name);
|
1146 |
-
$this->privSwapBackMagicQuotes();
|
1147 |
-
return $v_result;
|
1148 |
-
}
|
1149 |
-
$v_count++;
|
1150 |
-
}
|
1151 |
-
$this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
|
1152 |
-
}
|
1153 |
-
$v_comment = $v_central_dir['comment'];
|
1154 |
-
if (isset($p_options[PCLZIP_OPT_COMMENT])) {
|
1155 |
-
$v_comment = $p_options[PCLZIP_OPT_COMMENT];
|
1156 |
-
}
|
1157 |
-
if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {
|
1158 |
-
$v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT];
|
1159 |
-
}
|
1160 |
-
if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {
|
1161 |
-
$v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment;
|
1162 |
-
}
|
1163 |
-
$v_size = @ftell($this->zip_fd)-$v_offset;
|
1164 |
-
if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1)
|
1165 |
-
{
|
1166 |
-
unset($v_header_list);
|
1167 |
-
$this->privSwapBackMagicQuotes();
|
1168 |
-
return $v_result;
|
1169 |
-
}
|
1170 |
-
$v_swap = $this->zip_fd;
|
1171 |
-
$this->zip_fd = $v_zip_temp_fd;
|
1172 |
-
$v_zip_temp_fd = $v_swap;
|
1173 |
-
$this->privCloseFd();
|
1174 |
-
@fclose($v_zip_temp_fd);
|
1175 |
-
$this->privSwapBackMagicQuotes();
|
1176 |
-
@unlink($this->zipname);
|
1177 |
-
PclZipUtilRename($v_zip_temp_name, $this->zipname);
|
1178 |
-
return $v_result;
|
1179 |
-
}
|
1180 |
-
function privOpenFd($p_mode)
|
1181 |
-
{
|
1182 |
-
$v_result=1;
|
1183 |
-
if ($this->zip_fd != 0)
|
1184 |
-
{
|
1185 |
-
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open');
|
1186 |
-
return PclZip::errorCode();
|
1187 |
-
}
|
1188 |
-
if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0)
|
1189 |
-
{
|
1190 |
-
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');
|
1191 |
-
return PclZip::errorCode();
|
1192 |
-
}
|
1193 |
-
return $v_result;
|
1194 |
-
}
|
1195 |
-
function privCloseFd()
|
1196 |
-
{
|
1197 |
-
$v_result=1;
|
1198 |
-
if ($this->zip_fd != 0)
|
1199 |
-
@fclose($this->zip_fd);
|
1200 |
-
$this->zip_fd = 0;
|
1201 |
-
return $v_result;
|
1202 |
-
}
|
1203 |
-
// function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)
|
1204 |
-
function privAddList($p_filedescr_list, &$p_result_list, &$p_options)
|
1205 |
-
{
|
1206 |
-
$v_result=1;
|
1207 |
-
$v_header_list = array();
|
1208 |
-
if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
|
1209 |
-
{
|
1210 |
-
return $v_result;
|
1211 |
-
}
|
1212 |
-
$v_offset = @ftell($this->zip_fd);
|
1213 |
-
for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++)
|
1214 |
-
{
|
1215 |
-
if ($v_header_list[$i]['status'] == 'ok') {
|
1216 |
-
if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
|
1217 |
-
return $v_result;
|
1218 |
-
}
|
1219 |
-
$v_count++;
|
1220 |
-
}
|
1221 |
-
$this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
|
1222 |
-
}
|
1223 |
-
$v_comment = '';
|
1224 |
-
if (isset($p_options[PCLZIP_OPT_COMMENT])) {
|
1225 |
-
$v_comment = $p_options[PCLZIP_OPT_COMMENT];
|
1226 |
-
}
|
1227 |
-
$v_size = @ftell($this->zip_fd)-$v_offset;
|
1228 |
-
if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1)
|
1229 |
-
{
|
1230 |
-
unset($v_header_list);
|
1231 |
-
return $v_result;
|
1232 |
-
}
|
1233 |
-
return $v_result;
|
1234 |
-
}
|
1235 |
-
function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options)
|
1236 |
-
{
|
1237 |
-
$v_result=1;
|
1238 |
-
$v_header = array();
|
1239 |
-
$v_nb = sizeof($p_result_list);
|
1240 |
-
for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) {
|
1241 |
-
$p_filedescr_list[$j]['filename']
|
1242 |
-
= PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false);
|
1243 |
-
if ($p_filedescr_list[$j]['filename'] == "") {
|
1244 |
-
continue;
|
1245 |
-
}
|
1246 |
-
if ( ($p_filedescr_list[$j]['type'] != 'virtual_file')
|
1247 |
-
&& (!file_exists($p_filedescr_list[$j]['filename']))) {
|
1248 |
-
PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist");
|
1249 |
-
return PclZip::errorCode();
|
1250 |
-
}
|
1251 |
-
// if ( (is_file($p_filedescr_list[$j]['filename']))
|
1252 |
-
// || ( is_dir($p_filedescr_list[$j]['filename'])
|
1253 |
-
if ( ($p_filedescr_list[$j]['type'] == 'file')
|
1254 |
-
|| ($p_filedescr_list[$j]['type'] == 'virtual_file')
|
1255 |
-
|| ( ($p_filedescr_list[$j]['type'] == 'folder')
|
1256 |
-
&& ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])
|
1257 |
-
|| !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))
|
1258 |
-
) {
|
1259 |
-
$v_result = $this->privAddFile($p_filedescr_list[$j], $v_header,
|
1260 |
-
$p_options);
|
1261 |
-
if ($v_result != 1) {
|
1262 |
-
return $v_result;
|
1263 |
-
}
|
1264 |
-
$p_result_list[$v_nb++] = $v_header;
|
1265 |
-
}
|
1266 |
-
}
|
1267 |
-
return $v_result;
|
1268 |
-
}
|
1269 |
-
function privAddFile($p_filedescr, &$p_header, &$p_options)
|
1270 |
-
{
|
1271 |
-
$v_result=1;
|
1272 |
-
$p_filename = $p_filedescr['filename'];
|
1273 |
-
if ($p_filename == "") {
|
1274 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");
|
1275 |
-
return PclZip::errorCode();
|
1276 |
-
}
|
1277 |
-
/* TBC : Removed
|
1278 |
-
if (isset($p_filedescr['stored_filename'])) {
|
1279 |
-
$v_stored_filename = $p_filedescr['stored_filename'];
|
1280 |
-
}
|
1281 |
-
else {
|
1282 |
-
$v_stored_filename = $p_filedescr['stored_filename'];
|
1283 |
-
}
|
1284 |
-
*/
|
1285 |
-
clearstatcache();
|
1286 |
-
$p_header['version'] = 20;
|
1287 |
-
$p_header['version_extracted'] = 10;
|
1288 |
-
$p_header['flag'] = 0;
|
1289 |
-
$p_header['compression'] = 0;
|
1290 |
-
$p_header['crc'] = 0;
|
1291 |
-
$p_header['compressed_size'] = 0;
|
1292 |
-
$p_header['filename_len'] = strlen($p_filename);
|
1293 |
-
$p_header['extra_len'] = 0;
|
1294 |
-
$p_header['disk'] = 0;
|
1295 |
-
$p_header['internal'] = 0;
|
1296 |
-
$p_header['offset'] = 0;
|
1297 |
-
$p_header['filename'] = $p_filename;
|
1298 |
-
// TBC : Removed $p_header['stored_filename'] = $v_stored_filename;
|
1299 |
-
$p_header['stored_filename'] = $p_filedescr['stored_filename'];
|
1300 |
-
$p_header['extra'] = '';
|
1301 |
-
$p_header['status'] = 'ok';
|
1302 |
-
$p_header['index'] = -1;
|
1303 |
-
if ($p_filedescr['type']=='file') {
|
1304 |
-
$p_header['external'] = 0x00000000;
|
1305 |
-
$p_header['size'] = filesize($p_filename);
|
1306 |
-
}
|
1307 |
-
else if ($p_filedescr['type']=='folder') {
|
1308 |
-
$p_header['external'] = 0x00000010;
|
1309 |
-
$p_header['mtime'] = filemtime($p_filename);
|
1310 |
-
$p_header['size'] = filesize($p_filename);
|
1311 |
-
}
|
1312 |
-
else if ($p_filedescr['type'] == 'virtual_file') {
|
1313 |
-
$p_header['external'] = 0x00000000;
|
1314 |
-
$p_header['size'] = strlen($p_filedescr['content']);
|
1315 |
-
}
|
1316 |
-
if (isset($p_filedescr['mtime'])) {
|
1317 |
-
$p_header['mtime'] = $p_filedescr['mtime'];
|
1318 |
-
}
|
1319 |
-
else if ($p_filedescr['type'] == 'virtual_file') {
|
1320 |
-
$p_header['mtime'] = time();
|
1321 |
-
}
|
1322 |
-
else {
|
1323 |
-
$p_header['mtime'] = filemtime($p_filename);
|
1324 |
-
}
|
1325 |
-
if (isset($p_filedescr['comment'])) {
|
1326 |
-
$p_header['comment_len'] = strlen($p_filedescr['comment']);
|
1327 |
-
$p_header['comment'] = $p_filedescr['comment'];
|
1328 |
-
}
|
1329 |
-
else {
|
1330 |
-
$p_header['comment_len'] = 0;
|
1331 |
-
$p_header['comment'] = '';
|
1332 |
-
}
|
1333 |
-
if (isset($p_options[PCLZIP_CB_PRE_ADD])) {
|
1334 |
-
$v_local_header = array();
|
1335 |
-
$this->privConvertHeader2FileInfo($p_header, $v_local_header);
|
1336 |
-
// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);');
|
1337 |
-
$v_result = $p_options[PCLZIP_CB_PRE_ADD](PCLZIP_CB_PRE_ADD, $v_local_header);
|
1338 |
-
if ($v_result == 0) {
|
1339 |
-
$p_header['status'] = "skipped";
|
1340 |
-
$v_result = 1;
|
1341 |
-
}
|
1342 |
-
if ($p_header['stored_filename'] != $v_local_header['stored_filename']) {
|
1343 |
-
$p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']);
|
1344 |
-
}
|
1345 |
-
}
|
1346 |
-
if ($p_header['stored_filename'] == "") {
|
1347 |
-
$p_header['status'] = "filtered";
|
1348 |
-
}
|
1349 |
-
if (strlen($p_header['stored_filename']) > 0xFF) {
|
1350 |
-
$p_header['status'] = 'filename_too_long';
|
1351 |
-
}
|
1352 |
-
if ($p_header['status'] == 'ok') {
|
1353 |
-
if ($p_filedescr['type'] == 'file') {
|
1354 |
-
if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
|
1355 |
-
&& (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
|
1356 |
-
|| (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
|
1357 |
-
&& ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) {
|
1358 |
-
$v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options);
|
1359 |
-
if ($v_result < PCLZIP_ERR_NO_ERROR) {
|
1360 |
-
return $v_result;
|
1361 |
-
}
|
1362 |
-
}
|
1363 |
-
else {
|
1364 |
-
if (($v_file = @fopen($p_filename, "rb")) == 0) {
|
1365 |
-
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
|
1366 |
-
return PclZip::errorCode();
|
1367 |
-
}
|
1368 |
-
$v_content = @fread($v_file, $p_header['size']);
|
1369 |
-
@fclose($v_file);
|
1370 |
-
$p_header['crc'] = @crc32($v_content);
|
1371 |
-
if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
|
1372 |
-
$p_header['compressed_size'] = $p_header['size'];
|
1373 |
-
$p_header['compression'] = 0;
|
1374 |
-
}
|
1375 |
-
else {
|
1376 |
-
$v_content = @gzdeflate($v_content);
|
1377 |
-
$p_header['compressed_size'] = strlen($v_content);
|
1378 |
-
$p_header['compression'] = 8;
|
1379 |
-
}
|
1380 |
-
if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
|
1381 |
-
@fclose($v_file);
|
1382 |
-
return $v_result;
|
1383 |
-
}
|
1384 |
-
@fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
|
1385 |
-
}
|
1386 |
-
}
|
1387 |
-
else if ($p_filedescr['type'] == 'virtual_file') {
|
1388 |
-
$v_content = $p_filedescr['content'];
|
1389 |
-
$p_header['crc'] = @crc32($v_content);
|
1390 |
-
if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
|
1391 |
-
$p_header['compressed_size'] = $p_header['size'];
|
1392 |
-
$p_header['compression'] = 0;
|
1393 |
-
}
|
1394 |
-
else {
|
1395 |
-
$v_content = @gzdeflate($v_content);
|
1396 |
-
$p_header['compressed_size'] = strlen($v_content);
|
1397 |
-
$p_header['compression'] = 8;
|
1398 |
-
}
|
1399 |
-
if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
|
1400 |
-
@fclose($v_file);
|
1401 |
-
return $v_result;
|
1402 |
-
}
|
1403 |
-
@fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
|
1404 |
-
}
|
1405 |
-
else if ($p_filedescr['type'] == 'folder') {
|
1406 |
-
if (@substr($p_header['stored_filename'], -1) != '/') {
|
1407 |
-
$p_header['stored_filename'] .= '/';
|
1408 |
-
}
|
1409 |
-
$p_header['size'] = 0;
|
1410 |
-
$p_header['external'] = 0x00000010; // Value for a folder : to be checked
|
1411 |
-
if (($v_result = $this->privWriteFileHeader($p_header)) != 1)
|
1412 |
-
{
|
1413 |
-
return $v_result;
|
1414 |
-
}
|
1415 |
-
}
|
1416 |
-
}
|
1417 |
-
if (isset($p_options[PCLZIP_CB_POST_ADD])) {
|
1418 |
-
$v_local_header = array();
|
1419 |
-
$this->privConvertHeader2FileInfo($p_header, $v_local_header);
|
1420 |
-
// eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);');
|
1421 |
-
$v_result = $p_options[PCLZIP_CB_POST_ADD](PCLZIP_CB_POST_ADD, $v_local_header);
|
1422 |
-
if ($v_result == 0) {
|
1423 |
-
$v_result = 1;
|
1424 |
-
}
|
1425 |
-
}
|
1426 |
-
return $v_result;
|
1427 |
-
}
|
1428 |
-
function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options)
|
1429 |
-
{
|
1430 |
-
$v_result=PCLZIP_ERR_NO_ERROR;
|
1431 |
-
$p_filename = $p_filedescr['filename'];
|
1432 |
-
if (($v_file = @fopen($p_filename, "rb")) == 0) {
|
1433 |
-
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
|
1434 |
-
return PclZip::errorCode();
|
1435 |
-
}
|
1436 |
-
$v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
|
1437 |
-
if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) {
|
1438 |
-
fclose($v_file);
|
1439 |
-
PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
|
1440 |
-
return PclZip::errorCode();
|
1441 |
-
}
|
1442 |
-
$v_size = filesize($p_filename);
|
1443 |
-
while ($v_size != 0) {
|
1444 |
-
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
1445 |
-
$v_buffer = @fread($v_file, $v_read_size);
|
1446 |
-
@gzputs($v_file_compressed, $v_buffer, $v_read_size);
|
1447 |
-
$v_size -= $v_read_size;
|
1448 |
-
}
|
1449 |
-
@fclose($v_file);
|
1450 |
-
@gzclose($v_file_compressed);
|
1451 |
-
if (filesize($v_gzip_temp_name) < 18) {
|
1452 |
-
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes');
|
1453 |
-
return PclZip::errorCode();
|
1454 |
-
}
|
1455 |
-
if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) {
|
1456 |
-
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
|
1457 |
-
return PclZip::errorCode();
|
1458 |
-
}
|
1459 |
-
$v_binary_data = @fread($v_file_compressed, 10);
|
1460 |
-
$v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data);
|
1461 |
-
$v_data_header['os'] = bin2hex($v_data_header['os']);
|
1462 |
-
@fseek($v_file_compressed, filesize($v_gzip_temp_name)-8);
|
1463 |
-
$v_binary_data = @fread($v_file_compressed, 8);
|
1464 |
-
$v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data);
|
1465 |
-
$p_header['compression'] = ord($v_data_header['cm']);
|
1466 |
-
$p_header['crc'] = $v_data_footer['crc'];
|
1467 |
-
$p_header['compressed_size'] = filesize($v_gzip_temp_name)-18;
|
1468 |
-
@fclose($v_file_compressed);
|
1469 |
-
if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
|
1470 |
-
return $v_result;
|
1471 |
-
}
|
1472 |
-
if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0)
|
1473 |
-
{
|
1474 |
-
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
|
1475 |
-
return PclZip::errorCode();
|
1476 |
-
}
|
1477 |
-
fseek($v_file_compressed, 10);
|
1478 |
-
$v_size = $p_header['compressed_size'];
|
1479 |
-
while ($v_size != 0)
|
1480 |
-
{
|
1481 |
-
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
1482 |
-
$v_buffer = @fread($v_file_compressed, $v_read_size);
|
1483 |
-
@fwrite($this->zip_fd, $v_buffer, $v_read_size);
|
1484 |
-
$v_size -= $v_read_size;
|
1485 |
-
}
|
1486 |
-
@fclose($v_file_compressed);
|
1487 |
-
@unlink($v_gzip_temp_name);
|
1488 |
-
return $v_result;
|
1489 |
-
}
|
1490 |
-
function privCalculateStoredFilename(&$p_filedescr, &$p_options)
|
1491 |
-
{
|
1492 |
-
$v_result=1;
|
1493 |
-
$p_filename = $p_filedescr['filename'];
|
1494 |
-
if (isset($p_options[PCLZIP_OPT_ADD_PATH])) {
|
1495 |
-
$p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH];
|
1496 |
-
}
|
1497 |
-
else {
|
1498 |
-
$p_add_dir = '';
|
1499 |
-
}
|
1500 |
-
if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) {
|
1501 |
-
$p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH];
|
1502 |
-
}
|
1503 |
-
else {
|
1504 |
-
$p_remove_dir = '';
|
1505 |
-
}
|
1506 |
-
if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
|
1507 |
-
$p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH];
|
1508 |
-
}
|
1509 |
-
else {
|
1510 |
-
$p_remove_all_dir = 0;
|
1511 |
-
}
|
1512 |
-
if (isset($p_filedescr['new_full_name'])) {
|
1513 |
-
$v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']);
|
1514 |
-
}
|
1515 |
-
else {
|
1516 |
-
if (isset($p_filedescr['new_short_name'])) {
|
1517 |
-
$v_path_info = pathinfo($p_filename);
|
1518 |
-
$v_dir = '';
|
1519 |
-
if ($v_path_info['dirname'] != '') {
|
1520 |
-
$v_dir = $v_path_info['dirname'].'/';
|
1521 |
-
}
|
1522 |
-
$v_stored_filename = $v_dir.$p_filedescr['new_short_name'];
|
1523 |
-
}
|
1524 |
-
else {
|
1525 |
-
$v_stored_filename = $p_filename;
|
1526 |
-
}
|
1527 |
-
if ($p_remove_all_dir) {
|
1528 |
-
$v_stored_filename = basename($p_filename);
|
1529 |
-
}
|
1530 |
-
else if ($p_remove_dir != "") {
|
1531 |
-
if (substr($p_remove_dir, -1) != '/')
|
1532 |
-
$p_remove_dir .= "/";
|
1533 |
-
if ( (substr($p_filename, 0, 2) == "./")
|
1534 |
-
|| (substr($p_remove_dir, 0, 2) == "./")) {
|
1535 |
-
if ( (substr($p_filename, 0, 2) == "./")
|
1536 |
-
&& (substr($p_remove_dir, 0, 2) != "./")) {
|
1537 |
-
$p_remove_dir = "./".$p_remove_dir;
|
1538 |
-
}
|
1539 |
-
if ( (substr($p_filename, 0, 2) != "./")
|
1540 |
-
&& (substr($p_remove_dir, 0, 2) == "./")) {
|
1541 |
-
$p_remove_dir = substr($p_remove_dir, 2);
|
1542 |
-
}
|
1543 |
-
}
|
1544 |
-
$v_compare = PclZipUtilPathInclusion($p_remove_dir,
|
1545 |
-
$v_stored_filename);
|
1546 |
-
if ($v_compare > 0) {
|
1547 |
-
if ($v_compare == 2) {
|
1548 |
-
$v_stored_filename = "";
|
1549 |
-
}
|
1550 |
-
else {
|
1551 |
-
$v_stored_filename = substr($v_stored_filename,
|
1552 |
-
strlen($p_remove_dir));
|
1553 |
-
}
|
1554 |
-
}
|
1555 |
-
}
|
1556 |
-
$v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename);
|
1557 |
-
if ($p_add_dir != "") {
|
1558 |
-
if (substr($p_add_dir, -1) == "/")
|
1559 |
-
$v_stored_filename = $p_add_dir.$v_stored_filename;
|
1560 |
-
else
|
1561 |
-
$v_stored_filename = $p_add_dir."/".$v_stored_filename;
|
1562 |
-
}
|
1563 |
-
}
|
1564 |
-
$v_stored_filename = PclZipUtilPathReduction($v_stored_filename);
|
1565 |
-
$p_filedescr['stored_filename'] = $v_stored_filename;
|
1566 |
-
return $v_result;
|
1567 |
-
}
|
1568 |
-
function privWriteFileHeader(&$p_header)
|
1569 |
-
{
|
1570 |
-
$v_result=1;
|
1571 |
-
$p_header['offset'] = ftell($this->zip_fd);
|
1572 |
-
$v_date = getdate($p_header['mtime']);
|
1573 |
-
$v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
|
1574 |
-
$v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
|
1575 |
-
$v_binary_data = pack("VvvvvvVVVvv", 0x04034b50,
|
1576 |
-
$p_header['version_extracted'], $p_header['flag'],
|
1577 |
-
$p_header['compression'], $v_mtime, $v_mdate,
|
1578 |
-
$p_header['crc'], $p_header['compressed_size'],
|
1579 |
-
$p_header['size'],
|
1580 |
-
strlen($p_header['stored_filename']),
|
1581 |
-
$p_header['extra_len']);
|
1582 |
-
fputs($this->zip_fd, $v_binary_data, 30);
|
1583 |
-
if (strlen($p_header['stored_filename']) != 0)
|
1584 |
-
{
|
1585 |
-
fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
|
1586 |
-
}
|
1587 |
-
if ($p_header['extra_len'] != 0)
|
1588 |
-
{
|
1589 |
-
fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
|
1590 |
-
}
|
1591 |
-
return $v_result;
|
1592 |
-
}
|
1593 |
-
function privWriteCentralFileHeader(&$p_header)
|
1594 |
-
{
|
1595 |
-
$v_result=1;
|
1596 |
-
$v_date = getdate($p_header['mtime']);
|
1597 |
-
$v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
|
1598 |
-
$v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
|
1599 |
-
$v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50,
|
1600 |
-
$p_header['version'], $p_header['version_extracted'],
|
1601 |
-
$p_header['flag'], $p_header['compression'],
|
1602 |
-
$v_mtime, $v_mdate, $p_header['crc'],
|
1603 |
-
$p_header['compressed_size'], $p_header['size'],
|
1604 |
-
strlen($p_header['stored_filename']),
|
1605 |
-
$p_header['extra_len'], $p_header['comment_len'],
|
1606 |
-
$p_header['disk'], $p_header['internal'],
|
1607 |
-
$p_header['external'], $p_header['offset']);
|
1608 |
-
fputs($this->zip_fd, $v_binary_data, 46);
|
1609 |
-
if (strlen($p_header['stored_filename']) != 0)
|
1610 |
-
{
|
1611 |
-
fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
|
1612 |
-
}
|
1613 |
-
if ($p_header['extra_len'] != 0)
|
1614 |
-
{
|
1615 |
-
fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
|
1616 |
-
}
|
1617 |
-
if ($p_header['comment_len'] != 0)
|
1618 |
-
{
|
1619 |
-
fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']);
|
1620 |
-
}
|
1621 |
-
return $v_result;
|
1622 |
-
}
|
1623 |
-
function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment)
|
1624 |
-
{
|
1625 |
-
$v_result=1;
|
1626 |
-
$v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries,
|
1627 |
-
$p_nb_entries, $p_size,
|
1628 |
-
$p_offset, strlen($p_comment));
|
1629 |
-
fputs($this->zip_fd, $v_binary_data, 22);
|
1630 |
-
if (strlen($p_comment) != 0)
|
1631 |
-
{
|
1632 |
-
fputs($this->zip_fd, $p_comment, strlen($p_comment));
|
1633 |
-
}
|
1634 |
-
return $v_result;
|
1635 |
-
}
|
1636 |
-
function privList(&$p_list)
|
1637 |
-
{
|
1638 |
-
$v_result=1;
|
1639 |
-
$this->privDisableMagicQuotes();
|
1640 |
-
if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
|
1641 |
-
{
|
1642 |
-
$this->privSwapBackMagicQuotes();
|
1643 |
-
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
|
1644 |
-
return PclZip::errorCode();
|
1645 |
-
}
|
1646 |
-
$v_central_dir = array();
|
1647 |
-
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
|
1648 |
-
{
|
1649 |
-
$this->privSwapBackMagicQuotes();
|
1650 |
-
return $v_result;
|
1651 |
-
}
|
1652 |
-
@rewind($this->zip_fd);
|
1653 |
-
if (@fseek($this->zip_fd, $v_central_dir['offset']))
|
1654 |
-
{
|
1655 |
-
$this->privSwapBackMagicQuotes();
|
1656 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
|
1657 |
-
return PclZip::errorCode();
|
1658 |
-
}
|
1659 |
-
for ($i=0; $i<$v_central_dir['entries']; $i++)
|
1660 |
-
{
|
1661 |
-
if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
|
1662 |
-
{
|
1663 |
-
$this->privSwapBackMagicQuotes();
|
1664 |
-
return $v_result;
|
1665 |
-
}
|
1666 |
-
$v_header['index'] = $i;
|
1667 |
-
$this->privConvertHeader2FileInfo($v_header, $p_list[$i]);
|
1668 |
-
unset($v_header);
|
1669 |
-
}
|
1670 |
-
$this->privCloseFd();
|
1671 |
-
$this->privSwapBackMagicQuotes();
|
1672 |
-
return $v_result;
|
1673 |
-
}
|
1674 |
-
function privConvertHeader2FileInfo($p_header, &$p_info)
|
1675 |
-
{
|
1676 |
-
$v_result=1;
|
1677 |
-
$v_temp_path = PclZipUtilPathReduction($p_header['filename']);
|
1678 |
-
$p_info['filename'] = $v_temp_path;
|
1679 |
-
$v_temp_path = PclZipUtilPathReduction($p_header['stored_filename']);
|
1680 |
-
$p_info['stored_filename'] = $v_temp_path;
|
1681 |
-
$p_info['size'] = $p_header['size'];
|
1682 |
-
$p_info['compressed_size'] = $p_header['compressed_size'];
|
1683 |
-
$p_info['mtime'] = $p_header['mtime'];
|
1684 |
-
$p_info['comment'] = $p_header['comment'];
|
1685 |
-
$p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010);
|
1686 |
-
$p_info['index'] = $p_header['index'];
|
1687 |
-
$p_info['status'] = $p_header['status'];
|
1688 |
-
$p_info['crc'] = $p_header['crc'];
|
1689 |
-
return $v_result;
|
1690 |
-
}
|
1691 |
-
function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
|
1692 |
-
{
|
1693 |
-
$v_result=1;
|
1694 |
-
$this->privDisableMagicQuotes();
|
1695 |
-
if ( ($p_path == "")
|
1696 |
-
|| ( (substr($p_path, 0, 1) != "/")
|
1697 |
-
&& (substr($p_path, 0, 3) != "../")
|
1698 |
-
&& (substr($p_path,1,2)!=":/")))
|
1699 |
-
$p_path = "./".$p_path;
|
1700 |
-
if (($p_path != "./") && ($p_path != "/"))
|
1701 |
-
{
|
1702 |
-
while (substr($p_path, -1) == "/")
|
1703 |
-
{
|
1704 |
-
$p_path = substr($p_path, 0, strlen($p_path)-1);
|
1705 |
-
}
|
1706 |
-
}
|
1707 |
-
if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))
|
1708 |
-
{
|
1709 |
-
$p_remove_path .= '/';
|
1710 |
-
}
|
1711 |
-
$p_remove_path_size = strlen($p_remove_path);
|
1712 |
-
if (($v_result = $this->privOpenFd('rb')) != 1)
|
1713 |
-
{
|
1714 |
-
$this->privSwapBackMagicQuotes();
|
1715 |
-
return $v_result;
|
1716 |
-
}
|
1717 |
-
$v_central_dir = array();
|
1718 |
-
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
|
1719 |
-
{
|
1720 |
-
$this->privCloseFd();
|
1721 |
-
$this->privSwapBackMagicQuotes();
|
1722 |
-
return $v_result;
|
1723 |
-
}
|
1724 |
-
$v_pos_entry = $v_central_dir['offset'];
|
1725 |
-
$j_start = 0;
|
1726 |
-
for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
|
1727 |
-
{
|
1728 |
-
@rewind($this->zip_fd);
|
1729 |
-
if (@fseek($this->zip_fd, $v_pos_entry))
|
1730 |
-
{
|
1731 |
-
$this->privCloseFd();
|
1732 |
-
$this->privSwapBackMagicQuotes();
|
1733 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
|
1734 |
-
return PclZip::errorCode();
|
1735 |
-
}
|
1736 |
-
$v_header = array();
|
1737 |
-
if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
|
1738 |
-
{
|
1739 |
-
$this->privCloseFd();
|
1740 |
-
$this->privSwapBackMagicQuotes();
|
1741 |
-
return $v_result;
|
1742 |
-
}
|
1743 |
-
$v_header['index'] = $i;
|
1744 |
-
$v_pos_entry = ftell($this->zip_fd);
|
1745 |
-
$v_extract = false;
|
1746 |
-
if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
|
1747 |
-
&& ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
|
1748 |
-
for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) {
|
1749 |
-
if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
|
1750 |
-
if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
|
1751 |
-
&& (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
|
1752 |
-
$v_extract = true;
|
1753 |
-
}
|
1754 |
-
}
|
1755 |
-
elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
|
1756 |
-
$v_extract = true;
|
1757 |
-
}
|
1758 |
-
}
|
1759 |
-
}
|
1760 |
-
/*
|
1761 |
-
else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
|
1762 |
-
&& ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
|
1763 |
-
if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) {
|
1764 |
-
$v_extract = true;
|
1765 |
-
}
|
1766 |
-
}
|
1767 |
-
*/
|
1768 |
-
else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
|
1769 |
-
&& ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
|
1770 |
-
if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) {
|
1771 |
-
$v_extract = true;
|
1772 |
-
}
|
1773 |
-
}
|
1774 |
-
else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
|
1775 |
-
&& ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
|
1776 |
-
for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) {
|
1777 |
-
if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
|
1778 |
-
$v_extract = true;
|
1779 |
-
}
|
1780 |
-
if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
|
1781 |
-
$j_start = $j+1;
|
1782 |
-
}
|
1783 |
-
if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
|
1784 |
-
break;
|
1785 |
-
}
|
1786 |
-
}
|
1787 |
-
}
|
1788 |
-
else {
|
1789 |
-
$v_extract = true;
|
1790 |
-
}
|
1791 |
-
// ----- Check compression method
|
1792 |
-
if ( ($v_extract)
|
1793 |
-
&& ( ($v_header['compression'] != 8)
|
1794 |
-
&& ($v_header['compression'] != 0))) {
|
1795 |
-
$v_header['status'] = 'unsupported_compression';
|
1796 |
-
if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
|
1797 |
-
&& ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
|
1798 |
-
$this->privSwapBackMagicQuotes();
|
1799 |
-
PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION,
|
1800 |
-
"Filename '".$v_header['stored_filename']."' is "
|
1801 |
-
."compressed by an unsupported compression "
|
1802 |
-
."method (".$v_header['compression'].") ");
|
1803 |
-
return PclZip::errorCode();
|
1804 |
-
}
|
1805 |
-
}
|
1806 |
-
// ----- Check encrypted files
|
1807 |
-
if (($v_extract) && (($v_header['flag'] & 1) == 1)) {
|
1808 |
-
$v_header['status'] = 'unsupported_encryption';
|
1809 |
-
if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
|
1810 |
-
&& ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
|
1811 |
-
$this->privSwapBackMagicQuotes();
|
1812 |
-
PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION,
|
1813 |
-
"Unsupported encryption for "
|
1814 |
-
." filename '".$v_header['stored_filename']
|
1815 |
-
."'");
|
1816 |
-
return PclZip::errorCode();
|
1817 |
-
}
|
1818 |
-
}
|
1819 |
-
if (($v_extract) && ($v_header['status'] != 'ok')) {
|
1820 |
-
$v_result = $this->privConvertHeader2FileInfo($v_header,
|
1821 |
-
$p_file_list[$v_nb_extracted++]);
|
1822 |
-
if ($v_result != 1) {
|
1823 |
-
$this->privCloseFd();
|
1824 |
-
$this->privSwapBackMagicQuotes();
|
1825 |
-
return $v_result;
|
1826 |
-
}
|
1827 |
-
$v_extract = false;
|
1828 |
-
}
|
1829 |
-
if ($v_extract)
|
1830 |
-
{
|
1831 |
-
@rewind($this->zip_fd);
|
1832 |
-
if (@fseek($this->zip_fd, $v_header['offset']))
|
1833 |
-
{
|
1834 |
-
$this->privCloseFd();
|
1835 |
-
$this->privSwapBackMagicQuotes();
|
1836 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
|
1837 |
-
return PclZip::errorCode();
|
1838 |
-
}
|
1839 |
-
if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) {
|
1840 |
-
$v_string = '';
|
1841 |
-
$v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options);
|
1842 |
-
if ($v_result1 < 1) {
|
1843 |
-
$this->privCloseFd();
|
1844 |
-
$this->privSwapBackMagicQuotes();
|
1845 |
-
return $v_result1;
|
1846 |
-
}
|
1847 |
-
if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1)
|
1848 |
-
{
|
1849 |
-
$this->privCloseFd();
|
1850 |
-
$this->privSwapBackMagicQuotes();
|
1851 |
-
return $v_result;
|
1852 |
-
}
|
1853 |
-
$p_file_list[$v_nb_extracted]['content'] = $v_string;
|
1854 |
-
$v_nb_extracted++;
|
1855 |
-
if ($v_result1 == 2) {
|
1856 |
-
break;
|
1857 |
-
}
|
1858 |
-
}
|
1859 |
-
elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT]))
|
1860 |
-
&& ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {
|
1861 |
-
$v_result1 = $this->privExtractFileInOutput($v_header, $p_options);
|
1862 |
-
if ($v_result1 < 1) {
|
1863 |
-
$this->privCloseFd();
|
1864 |
-
$this->privSwapBackMagicQuotes();
|
1865 |
-
return $v_result1;
|
1866 |
-
}
|
1867 |
-
if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {
|
1868 |
-
$this->privCloseFd();
|
1869 |
-
$this->privSwapBackMagicQuotes();
|
1870 |
-
return $v_result;
|
1871 |
-
}
|
1872 |
-
if ($v_result1 == 2) {
|
1873 |
-
break;
|
1874 |
-
}
|
1875 |
-
}
|
1876 |
-
else {
|
1877 |
-
$v_result1 = $this->privExtractFile($v_header,
|
1878 |
-
$p_path, $p_remove_path,
|
1879 |
-
$p_remove_all_path,
|
1880 |
-
$p_options);
|
1881 |
-
if ($v_result1 < 1) {
|
1882 |
-
$this->privCloseFd();
|
1883 |
-
$this->privSwapBackMagicQuotes();
|
1884 |
-
return $v_result1;
|
1885 |
-
}
|
1886 |
-
if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1)
|
1887 |
-
{
|
1888 |
-
$this->privCloseFd();
|
1889 |
-
$this->privSwapBackMagicQuotes();
|
1890 |
-
return $v_result;
|
1891 |
-
}
|
1892 |
-
if ($v_result1 == 2) {
|
1893 |
-
break;
|
1894 |
-
}
|
1895 |
-
}
|
1896 |
-
}
|
1897 |
-
}
|
1898 |
-
$this->privCloseFd();
|
1899 |
-
$this->privSwapBackMagicQuotes();
|
1900 |
-
return $v_result;
|
1901 |
-
}
|
1902 |
-
function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
|
1903 |
-
{
|
1904 |
-
$v_result=1;
|
1905 |
-
if (($v_result = $this->privReadFileHeader($v_header)) != 1)
|
1906 |
-
{
|
1907 |
-
return $v_result;
|
1908 |
-
}
|
1909 |
-
if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
|
1910 |
-
}
|
1911 |
-
if ($p_remove_all_path == true) {
|
1912 |
-
if (($p_entry['external']&0x00000010)==0x00000010) {
|
1913 |
-
$p_entry['status'] = "filtered";
|
1914 |
-
return $v_result;
|
1915 |
-
}
|
1916 |
-
$p_entry['filename'] = basename($p_entry['filename']);
|
1917 |
-
}
|
1918 |
-
else if ($p_remove_path != "")
|
1919 |
-
{
|
1920 |
-
if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2)
|
1921 |
-
{
|
1922 |
-
$p_entry['status'] = "filtered";
|
1923 |
-
return $v_result;
|
1924 |
-
}
|
1925 |
-
$p_remove_path_size = strlen($p_remove_path);
|
1926 |
-
if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path)
|
1927 |
-
{
|
1928 |
-
$p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
|
1929 |
-
}
|
1930 |
-
}
|
1931 |
-
if ($p_path != '') {
|
1932 |
-
$p_entry['filename'] = $p_path."/".$p_entry['filename'];
|
1933 |
-
}
|
1934 |
-
if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {
|
1935 |
-
$v_inclusion
|
1936 |
-
= PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION],
|
1937 |
-
$p_entry['filename']);
|
1938 |
-
if ($v_inclusion == 0) {
|
1939 |
-
PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION,
|
1940 |
-
"Filename '".$p_entry['filename']."' is "
|
1941 |
-
."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION");
|
1942 |
-
return PclZip::errorCode();
|
1943 |
-
}
|
1944 |
-
}
|
1945 |
-
if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
|
1946 |
-
$v_local_header = array();
|
1947 |
-
$this->privConvertHeader2FileInfo($p_entry, $v_local_header);
|
1948 |
-
// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
|
1949 |
-
$v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
|
1950 |
-
if ($v_result == 0) {
|
1951 |
-
$p_entry['status'] = "skipped";
|
1952 |
-
$v_result = 1;
|
1953 |
-
}
|
1954 |
-
if ($v_result == 2) {
|
1955 |
-
$p_entry['status'] = "aborted";
|
1956 |
-
$v_result = PCLZIP_ERR_USER_ABORTED;
|
1957 |
-
}
|
1958 |
-
$p_entry['filename'] = $v_local_header['filename'];
|
1959 |
-
}
|
1960 |
-
if ($p_entry['status'] == 'ok') {
|
1961 |
-
if (file_exists($p_entry['filename']))
|
1962 |
-
{
|
1963 |
-
if (is_dir($p_entry['filename']))
|
1964 |
-
{
|
1965 |
-
$p_entry['status'] = "already_a_directory";
|
1966 |
-
if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
|
1967 |
-
&& ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
|
1968 |
-
PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY,
|
1969 |
-
"Filename '".$p_entry['filename']."' is "
|
1970 |
-
."already used by an existing directory");
|
1971 |
-
return PclZip::errorCode();
|
1972 |
-
}
|
1973 |
-
}
|
1974 |
-
else if (!is_writeable($p_entry['filename']))
|
1975 |
-
{
|
1976 |
-
$p_entry['status'] = "write_protected";
|
1977 |
-
if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
|
1978 |
-
&& ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
|
1979 |
-
PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
|
1980 |
-
"Filename '".$p_entry['filename']."' exists "
|
1981 |
-
."and is write protected");
|
1982 |
-
return PclZip::errorCode();
|
1983 |
-
}
|
1984 |
-
}
|
1985 |
-
else if (filemtime($p_entry['filename']) > $p_entry['mtime'])
|
1986 |
-
{
|
1987 |
-
if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER]))
|
1988 |
-
&& ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) {
|
1989 |
-
}
|
1990 |
-
else {
|
1991 |
-
$p_entry['status'] = "newer_exist";
|
1992 |
-
if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
|
1993 |
-
&& ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
|
1994 |
-
PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
|
1995 |
-
"Newer version of '".$p_entry['filename']."' exists "
|
1996 |
-
."and option PCLZIP_OPT_REPLACE_NEWER is not selected");
|
1997 |
-
return PclZip::errorCode();
|
1998 |
-
}
|
1999 |
-
}
|
2000 |
-
}
|
2001 |
-
else {
|
2002 |
-
}
|
2003 |
-
}
|
2004 |
-
else {
|
2005 |
-
if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/'))
|
2006 |
-
$v_dir_to_check = $p_entry['filename'];
|
2007 |
-
else if (!strstr($p_entry['filename'], "/"))
|
2008 |
-
$v_dir_to_check = "";
|
2009 |
-
else
|
2010 |
-
$v_dir_to_check = dirname($p_entry['filename']);
|
2011 |
-
if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) {
|
2012 |
-
$p_entry['status'] = "path_creation_fail";
|
2013 |
-
$v_result = 1;
|
2014 |
-
}
|
2015 |
-
}
|
2016 |
-
}
|
2017 |
-
if ($p_entry['status'] == 'ok') {
|
2018 |
-
if (!(($p_entry['external']&0x00000010)==0x00000010))
|
2019 |
-
{
|
2020 |
-
if ($p_entry['compression'] == 0) {
|
2021 |
-
// ----- Opening destination file
|
2022 |
-
if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0)
|
2023 |
-
{
|
2024 |
-
$p_entry['status'] = "write_error";
|
2025 |
-
return $v_result;
|
2026 |
-
}
|
2027 |
-
$v_size = $p_entry['compressed_size'];
|
2028 |
-
while ($v_size != 0)
|
2029 |
-
{
|
2030 |
-
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
2031 |
-
$v_buffer = @fread($this->zip_fd, $v_read_size);
|
2032 |
-
/* Try to speed up the code
|
2033 |
-
$v_binary_data = pack('a'.$v_read_size, $v_buffer);
|
2034 |
-
@fwrite($v_dest_file, $v_binary_data, $v_read_size);
|
2035 |
-
*/
|
2036 |
-
@fwrite($v_dest_file, $v_buffer, $v_read_size);
|
2037 |
-
$v_size -= $v_read_size;
|
2038 |
-
}
|
2039 |
-
fclose($v_dest_file);
|
2040 |
-
touch($p_entry['filename'], $p_entry['mtime']);
|
2041 |
-
}
|
2042 |
-
else {
|
2043 |
-
if (($p_entry['flag'] & 1) == 1) {
|
2044 |
-
PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.');
|
2045 |
-
return PclZip::errorCode();
|
2046 |
-
}
|
2047 |
-
if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
|
2048 |
-
&& (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
|
2049 |
-
|| (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
|
2050 |
-
&& ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) {
|
2051 |
-
$v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options);
|
2052 |
-
if ($v_result < PCLZIP_ERR_NO_ERROR) {
|
2053 |
-
return $v_result;
|
2054 |
-
}
|
2055 |
-
}
|
2056 |
-
else {
|
2057 |
-
$v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
|
2058 |
-
$v_file_content = @gzinflate($v_buffer);
|
2059 |
-
unset($v_buffer);
|
2060 |
-
if ($v_file_content === FALSE) {
|
2061 |
-
$p_entry['status'] = "error";
|
2062 |
-
return $v_result;
|
2063 |
-
}
|
2064 |
-
if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
|
2065 |
-
$p_entry['status'] = "write_error";
|
2066 |
-
return $v_result;
|
2067 |
-
}
|
2068 |
-
@fwrite($v_dest_file, $v_file_content, $p_entry['size']);
|
2069 |
-
unset($v_file_content);
|
2070 |
-
@fclose($v_dest_file);
|
2071 |
-
}
|
2072 |
-
@touch($p_entry['filename'], $p_entry['mtime']);
|
2073 |
-
}
|
2074 |
-
if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) {
|
2075 |
-
@chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]);
|
2076 |
-
}
|
2077 |
-
}
|
2078 |
-
}
|
2079 |
-
// ----- Change abort status
|
2080 |
-
if ($p_entry['status'] == "aborted") {
|
2081 |
-
$p_entry['status'] = "skipped";
|
2082 |
-
}
|
2083 |
-
elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
|
2084 |
-
$v_local_header = array();
|
2085 |
-
$this->privConvertHeader2FileInfo($p_entry, $v_local_header);
|
2086 |
-
// eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
|
2087 |
-
$v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
|
2088 |
-
if ($v_result == 2) {
|
2089 |
-
$v_result = PCLZIP_ERR_USER_ABORTED;
|
2090 |
-
}
|
2091 |
-
}
|
2092 |
-
return $v_result;
|
2093 |
-
}
|
2094 |
-
function privExtractFileUsingTempFile(&$p_entry, &$p_options)
|
2095 |
-
{
|
2096 |
-
$v_result=1;
|
2097 |
-
$v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
|
2098 |
-
if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) {
|
2099 |
-
fclose($v_file);
|
2100 |
-
PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
|
2101 |
-
return PclZip::errorCode();
|
2102 |
-
}
|
2103 |
-
$v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3));
|
2104 |
-
@fwrite($v_dest_file, $v_binary_data, 10);
|
2105 |
-
$v_size = $p_entry['compressed_size'];
|
2106 |
-
while ($v_size != 0)
|
2107 |
-
{
|
2108 |
-
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
2109 |
-
$v_buffer = @fread($this->zip_fd, $v_read_size);
|
2110 |
-
@fwrite($v_dest_file, $v_buffer, $v_read_size);
|
2111 |
-
$v_size -= $v_read_size;
|
2112 |
-
}
|
2113 |
-
$v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']);
|
2114 |
-
@fwrite($v_dest_file, $v_binary_data, 8);
|
2115 |
-
@fclose($v_dest_file);
|
2116 |
-
if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
|
2117 |
-
$p_entry['status'] = "write_error";
|
2118 |
-
return $v_result;
|
2119 |
-
}
|
2120 |
-
if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) {
|
2121 |
-
@fclose($v_dest_file);
|
2122 |
-
$p_entry['status'] = "read_error";
|
2123 |
-
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
|
2124 |
-
return PclZip::errorCode();
|
2125 |
-
}
|
2126 |
-
$v_size = $p_entry['size'];
|
2127 |
-
while ($v_size != 0) {
|
2128 |
-
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
2129 |
-
$v_buffer = @gzread($v_src_file, $v_read_size);
|
2130 |
-
@fwrite($v_dest_file, $v_buffer, $v_read_size);
|
2131 |
-
$v_size -= $v_read_size;
|
2132 |
-
}
|
2133 |
-
@fclose($v_dest_file);
|
2134 |
-
@gzclose($v_src_file);
|
2135 |
-
@unlink($v_gzip_temp_name);
|
2136 |
-
return $v_result;
|
2137 |
-
}
|
2138 |
-
function privExtractFileInOutput(&$p_entry, &$p_options)
|
2139 |
-
{
|
2140 |
-
$v_result=1;
|
2141 |
-
if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
|
2142 |
-
return $v_result;
|
2143 |
-
}
|
2144 |
-
if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
|
2145 |
-
}
|
2146 |
-
if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
|
2147 |
-
$v_local_header = array();
|
2148 |
-
$this->privConvertHeader2FileInfo($p_entry, $v_local_header);
|
2149 |
-
// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
|
2150 |
-
$v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
|
2151 |
-
if ($v_result == 0) {
|
2152 |
-
$p_entry['status'] = "skipped";
|
2153 |
-
$v_result = 1;
|
2154 |
-
}
|
2155 |
-
if ($v_result == 2) {
|
2156 |
-
$p_entry['status'] = "aborted";
|
2157 |
-
$v_result = PCLZIP_ERR_USER_ABORTED;
|
2158 |
-
}
|
2159 |
-
$p_entry['filename'] = $v_local_header['filename'];
|
2160 |
-
}
|
2161 |
-
if ($p_entry['status'] == 'ok') {
|
2162 |
-
if (!(($p_entry['external']&0x00000010)==0x00000010)) {
|
2163 |
-
if ($p_entry['compressed_size'] == $p_entry['size']) {
|
2164 |
-
$v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
|
2165 |
-
echo $v_buffer;
|
2166 |
-
unset($v_buffer);
|
2167 |
-
}
|
2168 |
-
else {
|
2169 |
-
$v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
|
2170 |
-
$v_file_content = gzinflate($v_buffer);
|
2171 |
-
unset($v_buffer);
|
2172 |
-
echo $v_file_content;
|
2173 |
-
unset($v_file_content);
|
2174 |
-
}
|
2175 |
-
}
|
2176 |
-
}
|
2177 |
-
// ----- Change abort status
|
2178 |
-
if ($p_entry['status'] == "aborted") {
|
2179 |
-
$p_entry['status'] = "skipped";
|
2180 |
-
}
|
2181 |
-
elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
|
2182 |
-
$v_local_header = array();
|
2183 |
-
$this->privConvertHeader2FileInfo($p_entry, $v_local_header);
|
2184 |
-
// eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
|
2185 |
-
$v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
|
2186 |
-
if ($v_result == 2) {
|
2187 |
-
$v_result = PCLZIP_ERR_USER_ABORTED;
|
2188 |
-
}
|
2189 |
-
}
|
2190 |
-
return $v_result;
|
2191 |
-
}
|
2192 |
-
function privExtractFileAsString(&$p_entry, &$p_string, &$p_options)
|
2193 |
-
{
|
2194 |
-
$v_result=1;
|
2195 |
-
$v_header = array();
|
2196 |
-
if (($v_result = $this->privReadFileHeader($v_header)) != 1)
|
2197 |
-
{
|
2198 |
-
return $v_result;
|
2199 |
-
}
|
2200 |
-
if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
|
2201 |
-
}
|
2202 |
-
if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
|
2203 |
-
$v_local_header = array();
|
2204 |
-
$this->privConvertHeader2FileInfo($p_entry, $v_local_header);
|
2205 |
-
// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
|
2206 |
-
$v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
|
2207 |
-
if ($v_result == 0) {
|
2208 |
-
$p_entry['status'] = "skipped";
|
2209 |
-
$v_result = 1;
|
2210 |
-
}
|
2211 |
-
if ($v_result == 2) {
|
2212 |
-
$p_entry['status'] = "aborted";
|
2213 |
-
$v_result = PCLZIP_ERR_USER_ABORTED;
|
2214 |
-
}
|
2215 |
-
$p_entry['filename'] = $v_local_header['filename'];
|
2216 |
-
}
|
2217 |
-
if ($p_entry['status'] == 'ok') {
|
2218 |
-
if (!(($p_entry['external']&0x00000010)==0x00000010)) {
|
2219 |
-
if ($p_entry['compression'] == 0) {
|
2220 |
-
$p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
|
2221 |
-
}
|
2222 |
-
else {
|
2223 |
-
$v_data = @fread($this->zip_fd, $p_entry['compressed_size']);
|
2224 |
-
if (($p_string = @gzinflate($v_data)) === FALSE) {
|
2225 |
-
}
|
2226 |
-
}
|
2227 |
-
}
|
2228 |
-
else {
|
2229 |
-
}
|
2230 |
-
}
|
2231 |
-
// ----- Change abort status
|
2232 |
-
if ($p_entry['status'] == "aborted") {
|
2233 |
-
$p_entry['status'] = "skipped";
|
2234 |
-
}
|
2235 |
-
elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
|
2236 |
-
$v_local_header = array();
|
2237 |
-
$this->privConvertHeader2FileInfo($p_entry, $v_local_header);
|
2238 |
-
$v_local_header['content'] = $p_string;
|
2239 |
-
$p_string = '';
|
2240 |
-
// eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
|
2241 |
-
$v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
|
2242 |
-
$p_string = $v_local_header['content'];
|
2243 |
-
unset($v_local_header['content']);
|
2244 |
-
if ($v_result == 2) {
|
2245 |
-
$v_result = PCLZIP_ERR_USER_ABORTED;
|
2246 |
-
}
|
2247 |
-
}
|
2248 |
-
return $v_result;
|
2249 |
-
}
|
2250 |
-
function privReadFileHeader(&$p_header)
|
2251 |
-
{
|
2252 |
-
$v_result=1;
|
2253 |
-
$v_binary_data = @fread($this->zip_fd, 4);
|
2254 |
-
$v_data = unpack('Vid', $v_binary_data);
|
2255 |
-
if ($v_data['id'] != 0x04034b50)
|
2256 |
-
{
|
2257 |
-
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
|
2258 |
-
return PclZip::errorCode();
|
2259 |
-
}
|
2260 |
-
$v_binary_data = fread($this->zip_fd, 26);
|
2261 |
-
if (strlen($v_binary_data) != 26)
|
2262 |
-
{
|
2263 |
-
$p_header['filename'] = "";
|
2264 |
-
$p_header['status'] = "invalid_header";
|
2265 |
-
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
|
2266 |
-
return PclZip::errorCode();
|
2267 |
-
}
|
2268 |
-
$v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data);
|
2269 |
-
$p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']);
|
2270 |
-
if ($v_data['extra_len'] != 0) {
|
2271 |
-
$p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']);
|
2272 |
-
}
|
2273 |
-
else {
|
2274 |
-
$p_header['extra'] = '';
|
2275 |
-
}
|
2276 |
-
$p_header['version_extracted'] = $v_data['version'];
|
2277 |
-
$p_header['compression'] = $v_data['compression'];
|
2278 |
-
$p_header['size'] = $v_data['size'];
|
2279 |
-
$p_header['compressed_size'] = $v_data['compressed_size'];
|
2280 |
-
$p_header['crc'] = $v_data['crc'];
|
2281 |
-
$p_header['flag'] = $v_data['flag'];
|
2282 |
-
$p_header['filename_len'] = $v_data['filename_len'];
|
2283 |
-
$p_header['mdate'] = $v_data['mdate'];
|
2284 |
-
$p_header['mtime'] = $v_data['mtime'];
|
2285 |
-
if ($p_header['mdate'] && $p_header['mtime'])
|
2286 |
-
{
|
2287 |
-
$v_hour = ($p_header['mtime'] & 0xF800) >> 11;
|
2288 |
-
$v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
|
2289 |
-
$v_seconde = ($p_header['mtime'] & 0x001F)*2;
|
2290 |
-
$v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
|
2291 |
-
$v_month = ($p_header['mdate'] & 0x01E0) >> 5;
|
2292 |
-
$v_day = $p_header['mdate'] & 0x001F;
|
2293 |
-
$p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
|
2294 |
-
}
|
2295 |
-
else
|
2296 |
-
{
|
2297 |
-
$p_header['mtime'] = time();
|
2298 |
-
}
|
2299 |
-
$p_header['stored_filename'] = $p_header['filename'];
|
2300 |
-
$p_header['status'] = "ok";
|
2301 |
-
return $v_result;
|
2302 |
-
}
|
2303 |
-
function privReadCentralFileHeader(&$p_header)
|
2304 |
-
{
|
2305 |
-
$v_result=1;
|
2306 |
-
$v_binary_data = @fread($this->zip_fd, 4);
|
2307 |
-
$v_data = unpack('Vid', $v_binary_data);
|
2308 |
-
if ($v_data['id'] != 0x02014b50)
|
2309 |
-
{
|
2310 |
-
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
|
2311 |
-
return PclZip::errorCode();
|
2312 |
-
}
|
2313 |
-
$v_binary_data = fread($this->zip_fd, 42);
|
2314 |
-
if (strlen($v_binary_data) != 42)
|
2315 |
-
{
|
2316 |
-
$p_header['filename'] = "";
|
2317 |
-
$p_header['status'] = "invalid_header";
|
2318 |
-
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
|
2319 |
-
return PclZip::errorCode();
|
2320 |
-
}
|
2321 |
-
$p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data);
|
2322 |
-
if ($p_header['filename_len'] != 0)
|
2323 |
-
$p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']);
|
2324 |
-
else
|
2325 |
-
$p_header['filename'] = '';
|
2326 |
-
if ($p_header['extra_len'] != 0)
|
2327 |
-
$p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']);
|
2328 |
-
else
|
2329 |
-
$p_header['extra'] = '';
|
2330 |
-
if ($p_header['comment_len'] != 0)
|
2331 |
-
$p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']);
|
2332 |
-
else
|
2333 |
-
$p_header['comment'] = '';
|
2334 |
-
if (1)
|
2335 |
-
{
|
2336 |
-
$v_hour = ($p_header['mtime'] & 0xF800) >> 11;
|
2337 |
-
$v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
|
2338 |
-
$v_seconde = ($p_header['mtime'] & 0x001F)*2;
|
2339 |
-
$v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
|
2340 |
-
$v_month = ($p_header['mdate'] & 0x01E0) >> 5;
|
2341 |
-
$v_day = $p_header['mdate'] & 0x001F;
|
2342 |
-
$p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
|
2343 |
-
}
|
2344 |
-
else
|
2345 |
-
{
|
2346 |
-
$p_header['mtime'] = time();
|
2347 |
-
}
|
2348 |
-
$p_header['stored_filename'] = $p_header['filename'];
|
2349 |
-
$p_header['status'] = 'ok';
|
2350 |
-
if (substr($p_header['filename'], -1) == '/') {
|
2351 |
-
$p_header['external'] = 0x00000010;
|
2352 |
-
}
|
2353 |
-
return $v_result;
|
2354 |
-
}
|
2355 |
-
function privCheckFileHeaders(&$p_local_header, &$p_central_header)
|
2356 |
-
{
|
2357 |
-
$v_result=1;
|
2358 |
-
// ----- Check the static values
|
2359 |
-
// TBC
|
2360 |
-
if ($p_local_header['filename'] != $p_central_header['filename']) {
|
2361 |
-
}
|
2362 |
-
if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) {
|
2363 |
-
}
|
2364 |
-
if ($p_local_header['flag'] != $p_central_header['flag']) {
|
2365 |
-
}
|
2366 |
-
if ($p_local_header['compression'] != $p_central_header['compression']) {
|
2367 |
-
}
|
2368 |
-
if ($p_local_header['mtime'] != $p_central_header['mtime']) {
|
2369 |
-
}
|
2370 |
-
if ($p_local_header['filename_len'] != $p_central_header['filename_len']) {
|
2371 |
-
}
|
2372 |
-
// ----- Look for flag bit 3
|
2373 |
-
if (($p_local_header['flag'] & 8) == 8) {
|
2374 |
-
$p_local_header['size'] = $p_central_header['size'];
|
2375 |
-
$p_local_header['compressed_size'] = $p_central_header['compressed_size'];
|
2376 |
-
$p_local_header['crc'] = $p_central_header['crc'];
|
2377 |
-
}
|
2378 |
-
return $v_result;
|
2379 |
-
}
|
2380 |
-
function privReadEndCentralDir(&$p_central_dir)
|
2381 |
-
{
|
2382 |
-
$v_result=1;
|
2383 |
-
$v_size = filesize($this->zipname);
|
2384 |
-
@fseek($this->zip_fd, $v_size);
|
2385 |
-
if (@ftell($this->zip_fd) != $v_size)
|
2386 |
-
{
|
2387 |
-
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\'');
|
2388 |
-
return PclZip::errorCode();
|
2389 |
-
}
|
2390 |
-
$v_found = 0;
|
2391 |
-
if ($v_size > 26) {
|
2392 |
-
@fseek($this->zip_fd, $v_size-22);
|
2393 |
-
if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22))
|
2394 |
-
{
|
2395 |
-
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
|
2396 |
-
return PclZip::errorCode();
|
2397 |
-
}
|
2398 |
-
$v_binary_data = @fread($this->zip_fd, 4);
|
2399 |
-
$v_data = @unpack('Vid', $v_binary_data);
|
2400 |
-
if ($v_data['id'] == 0x06054b50) {
|
2401 |
-
$v_found = 1;
|
2402 |
-
}
|
2403 |
-
$v_pos = ftell($this->zip_fd);
|
2404 |
-
}
|
2405 |
-
if (!$v_found) {
|
2406 |
-
$v_maximum_size = 65557; // 0xFFFF + 22;
|
2407 |
-
if ($v_maximum_size > $v_size)
|
2408 |
-
$v_maximum_size = $v_size;
|
2409 |
-
@fseek($this->zip_fd, $v_size-$v_maximum_size);
|
2410 |
-
if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size))
|
2411 |
-
{
|
2412 |
-
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
|
2413 |
-
return PclZip::errorCode();
|
2414 |
-
}
|
2415 |
-
$v_pos = ftell($this->zip_fd);
|
2416 |
-
$v_bytes = 0x00000000;
|
2417 |
-
while ($v_pos < $v_size)
|
2418 |
-
{
|
2419 |
-
$v_byte = @fread($this->zip_fd, 1);
|
2420 |
-
$v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte);
|
2421 |
-
if ($v_bytes == 0x504b0506)
|
2422 |
-
{
|
2423 |
-
$v_pos++;
|
2424 |
-
break;
|
2425 |
-
}
|
2426 |
-
$v_pos++;
|
2427 |
-
}
|
2428 |
-
if ($v_pos == $v_size)
|
2429 |
-
{
|
2430 |
-
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature");
|
2431 |
-
return PclZip::errorCode();
|
2432 |
-
}
|
2433 |
-
}
|
2434 |
-
$v_binary_data = fread($this->zip_fd, 18);
|
2435 |
-
if (strlen($v_binary_data) != 18)
|
2436 |
-
{
|
2437 |
-
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));
|
2438 |
-
return PclZip::errorCode();
|
2439 |
-
}
|
2440 |
-
$v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data);
|
2441 |
-
if (($v_pos + $v_data['comment_size'] + 18) != $v_size) {
|
2442 |
-
// ----- Removed in release 2.2 see readme file
|
2443 |
-
// The check of the file size is a little too strict.
|
2444 |
-
// Some bugs where found when a zip is encrypted/decrypted with 'crypt'.
|
2445 |
-
// While decrypted, zip has training 0 bytes
|
2446 |
-
if (0) {
|
2447 |
-
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT,
|
2448 |
-
'The central dir is not at the end of the archive.'
|
2449 |
-
.' Some trailing bytes exists after the archive.');
|
2450 |
-
return PclZip::errorCode();
|
2451 |
-
}
|
2452 |
-
}
|
2453 |
-
if ($v_data['comment_size'] != 0) {
|
2454 |
-
$p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']);
|
2455 |
-
}
|
2456 |
-
else
|
2457 |
-
$p_central_dir['comment'] = '';
|
2458 |
-
$p_central_dir['entries'] = $v_data['entries'];
|
2459 |
-
$p_central_dir['disk_entries'] = $v_data['disk_entries'];
|
2460 |
-
$p_central_dir['offset'] = $v_data['offset'];
|
2461 |
-
$p_central_dir['size'] = $v_data['size'];
|
2462 |
-
$p_central_dir['disk'] = $v_data['disk'];
|
2463 |
-
$p_central_dir['disk_start'] = $v_data['disk_start'];
|
2464 |
-
return $v_result;
|
2465 |
-
}
|
2466 |
-
function privDeleteByRule(&$p_result_list, &$p_options)
|
2467 |
-
{
|
2468 |
-
$v_result=1;
|
2469 |
-
$v_list_detail = array();
|
2470 |
-
if (($v_result=$this->privOpenFd('rb')) != 1)
|
2471 |
-
{
|
2472 |
-
return $v_result;
|
2473 |
-
}
|
2474 |
-
$v_central_dir = array();
|
2475 |
-
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
|
2476 |
-
{
|
2477 |
-
$this->privCloseFd();
|
2478 |
-
return $v_result;
|
2479 |
-
}
|
2480 |
-
@rewind($this->zip_fd);
|
2481 |
-
$v_pos_entry = $v_central_dir['offset'];
|
2482 |
-
@rewind($this->zip_fd);
|
2483 |
-
if (@fseek($this->zip_fd, $v_pos_entry))
|
2484 |
-
{
|
2485 |
-
$this->privCloseFd();
|
2486 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
|
2487 |
-
return PclZip::errorCode();
|
2488 |
-
}
|
2489 |
-
$v_header_list = array();
|
2490 |
-
$j_start = 0;
|
2491 |
-
for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
|
2492 |
-
{
|
2493 |
-
$v_header_list[$v_nb_extracted] = array();
|
2494 |
-
if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1)
|
2495 |
-
{
|
2496 |
-
$this->privCloseFd();
|
2497 |
-
return $v_result;
|
2498 |
-
}
|
2499 |
-
$v_header_list[$v_nb_extracted]['index'] = $i;
|
2500 |
-
$v_found = false;
|
2501 |
-
if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
|
2502 |
-
&& ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
|
2503 |
-
for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) {
|
2504 |
-
if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
|
2505 |
-
if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
|
2506 |
-
&& (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
|
2507 |
-
$v_found = true;
|
2508 |
-
}
|
2509 |
-
elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */
|
2510 |
-
&& ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
|
2511 |
-
$v_found = true;
|
2512 |
-
}
|
2513 |
-
}
|
2514 |
-
elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
|
2515 |
-
$v_found = true;
|
2516 |
-
}
|
2517 |
-
}
|
2518 |
-
}
|
2519 |
-
/*
|
2520 |
-
else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
|
2521 |
-
&& ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
|
2522 |
-
if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
|
2523 |
-
$v_found = true;
|
2524 |
-
}
|
2525 |
-
}
|
2526 |
-
*/
|
2527 |
-
else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
|
2528 |
-
&& ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
|
2529 |
-
if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
|
2530 |
-
$v_found = true;
|
2531 |
-
}
|
2532 |
-
}
|
2533 |
-
else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
|
2534 |
-
&& ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
|
2535 |
-
for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) {
|
2536 |
-
if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
|
2537 |
-
$v_found = true;
|
2538 |
-
}
|
2539 |
-
if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
|
2540 |
-
$j_start = $j+1;
|
2541 |
-
}
|
2542 |
-
if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
|
2543 |
-
break;
|
2544 |
-
}
|
2545 |
-
}
|
2546 |
-
}
|
2547 |
-
else {
|
2548 |
-
$v_found = true;
|
2549 |
-
}
|
2550 |
-
if ($v_found)
|
2551 |
-
{
|
2552 |
-
unset($v_header_list[$v_nb_extracted]);
|
2553 |
-
}
|
2554 |
-
else
|
2555 |
-
{
|
2556 |
-
$v_nb_extracted++;
|
2557 |
-
}
|
2558 |
-
}
|
2559 |
-
if ($v_nb_extracted > 0) {
|
2560 |
-
$v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
|
2561 |
-
$v_temp_zip = new PclZip($v_zip_temp_name);
|
2562 |
-
if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) {
|
2563 |
-
$this->privCloseFd();
|
2564 |
-
return $v_result;
|
2565 |
-
}
|
2566 |
-
for ($i=0; $i<sizeof($v_header_list); $i++) {
|
2567 |
-
@rewind($this->zip_fd);
|
2568 |
-
if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) {
|
2569 |
-
$this->privCloseFd();
|
2570 |
-
$v_temp_zip->privCloseFd();
|
2571 |
-
@unlink($v_zip_temp_name);
|
2572 |
-
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
|
2573 |
-
return PclZip::errorCode();
|
2574 |
-
}
|
2575 |
-
$v_local_header = array();
|
2576 |
-
if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) {
|
2577 |
-
$this->privCloseFd();
|
2578 |
-
$v_temp_zip->privCloseFd();
|
2579 |
-
@unlink($v_zip_temp_name);
|
2580 |
-
return $v_result;
|
2581 |
-
}
|
2582 |
-
if ($this->privCheckFileHeaders($v_local_header,
|
2583 |
-
$v_header_list[$i]) != 1) {
|
2584 |
-
}
|
2585 |
-
unset($v_local_header);
|
2586 |
-
if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) {
|
2587 |
-
$this->privCloseFd();
|
2588 |
-
$v_temp_zip->privCloseFd();
|
2589 |
-
@unlink($v_zip_temp_name);
|
2590 |
-
return $v_result;
|
2591 |
-
}
|
2592 |
-
if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) {
|
2593 |
-
$this->privCloseFd();
|
2594 |
-
$v_temp_zip->privCloseFd();
|
2595 |
-
@unlink($v_zip_temp_name);
|
2596 |
-
return $v_result;
|
2597 |
-
}
|
2598 |
-
}
|
2599 |
-
$v_offset = @ftell($v_temp_zip->zip_fd);
|
2600 |
-
for ($i=0; $i<sizeof($v_header_list); $i++) {
|
2601 |
-
if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
|
2602 |
-
$v_temp_zip->privCloseFd();
|
2603 |
-
$this->privCloseFd();
|
2604 |
-
@unlink($v_zip_temp_name);
|
2605 |
-
return $v_result;
|
2606 |
-
}
|
2607 |
-
$v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
|
2608 |
-
}
|
2609 |
-
$v_comment = '';
|
2610 |
-
if (isset($p_options[PCLZIP_OPT_COMMENT])) {
|
2611 |
-
$v_comment = $p_options[PCLZIP_OPT_COMMENT];
|
2612 |
-
}
|
2613 |
-
$v_size = @ftell($v_temp_zip->zip_fd)-$v_offset;
|
2614 |
-
if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {
|
2615 |
-
unset($v_header_list);
|
2616 |
-
$v_temp_zip->privCloseFd();
|
2617 |
-
$this->privCloseFd();
|
2618 |
-
@unlink($v_zip_temp_name);
|
2619 |
-
return $v_result;
|
2620 |
-
}
|
2621 |
-
$v_temp_zip->privCloseFd();
|
2622 |
-
$this->privCloseFd();
|
2623 |
-
@unlink($this->zipname);
|
2624 |
-
PclZipUtilRename($v_zip_temp_name, $this->zipname);
|
2625 |
-
unset($v_temp_zip);
|
2626 |
-
}
|
2627 |
-
else if ($v_central_dir['entries'] != 0) {
|
2628 |
-
$this->privCloseFd();
|
2629 |
-
if (($v_result = $this->privOpenFd('wb')) != 1) {
|
2630 |
-
return $v_result;
|
2631 |
-
}
|
2632 |
-
if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) {
|
2633 |
-
return $v_result;
|
2634 |
-
}
|
2635 |
-
$this->privCloseFd();
|
2636 |
-
}
|
2637 |
-
return $v_result;
|
2638 |
-
}
|
2639 |
-
function privDirCheck($p_dir, $p_is_dir=false)
|
2640 |
-
{
|
2641 |
-
$v_result = 1;
|
2642 |
-
if (($p_is_dir) && (substr($p_dir, -1)=='/'))
|
2643 |
-
{
|
2644 |
-
$p_dir = substr($p_dir, 0, strlen($p_dir)-1);
|
2645 |
-
}
|
2646 |
-
if ((is_dir($p_dir)) || ($p_dir == ""))
|
2647 |
-
{
|
2648 |
-
return 1;
|
2649 |
-
}
|
2650 |
-
$p_parent_dir = dirname($p_dir);
|
2651 |
-
if ($p_parent_dir != $p_dir)
|
2652 |
-
{
|
2653 |
-
if ($p_parent_dir != "")
|
2654 |
-
{
|
2655 |
-
if (($v_result = $this->privDirCheck($p_parent_dir)) != 1)
|
2656 |
-
{
|
2657 |
-
return $v_result;
|
2658 |
-
}
|
2659 |
-
}
|
2660 |
-
}
|
2661 |
-
if (!@mkdir($p_dir, 0777))
|
2662 |
-
{
|
2663 |
-
PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'");
|
2664 |
-
return PclZip::errorCode();
|
2665 |
-
}
|
2666 |
-
return $v_result;
|
2667 |
-
}
|
2668 |
-
function privMerge(&$p_archive_to_add)
|
2669 |
-
{
|
2670 |
-
$v_result=1;
|
2671 |
-
if (!is_file($p_archive_to_add->zipname))
|
2672 |
-
{
|
2673 |
-
$v_result = 1;
|
2674 |
-
return $v_result;
|
2675 |
-
}
|
2676 |
-
if (!is_file($this->zipname))
|
2677 |
-
{
|
2678 |
-
$v_result = $this->privDuplicate($p_archive_to_add->zipname);
|
2679 |
-
return $v_result;
|
2680 |
-
}
|
2681 |
-
if (($v_result=$this->privOpenFd('rb')) != 1)
|
2682 |
-
{
|
2683 |
-
return $v_result;
|
2684 |
-
}
|
2685 |
-
$v_central_dir = array();
|
2686 |
-
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
|
2687 |
-
{
|
2688 |
-
$this->privCloseFd();
|
2689 |
-
return $v_result;
|
2690 |
-
}
|
2691 |
-
@rewind($this->zip_fd);
|
2692 |
-
if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1)
|
2693 |
-
{
|
2694 |
-
$this->privCloseFd();
|
2695 |
-
return $v_result;
|
2696 |
-
}
|
2697 |
-
$v_central_dir_to_add = array();
|
2698 |
-
if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1)
|
2699 |
-
{
|
2700 |
-
$this->privCloseFd();
|
2701 |
-
$p_archive_to_add->privCloseFd();
|
2702 |
-
return $v_result;
|
2703 |
-
}
|
2704 |
-
@rewind($p_archive_to_add->zip_fd);
|
2705 |
-
$v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
|
2706 |
-
if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
|
2707 |
-
{
|
2708 |
-
$this->privCloseFd();
|
2709 |
-
$p_archive_to_add->privCloseFd();
|
2710 |
-
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
|
2711 |
-
return PclZip::errorCode();
|
2712 |
-
}
|
2713 |
-
$v_size = $v_central_dir['offset'];
|
2714 |
-
while ($v_size != 0)
|
2715 |
-
{
|
2716 |
-
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
2717 |
-
$v_buffer = fread($this->zip_fd, $v_read_size);
|
2718 |
-
@fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
|
2719 |
-
$v_size -= $v_read_size;
|
2720 |
-
}
|
2721 |
-
$v_size = $v_central_dir_to_add['offset'];
|
2722 |
-
while ($v_size != 0)
|
2723 |
-
{
|
2724 |
-
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
2725 |
-
$v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size);
|
2726 |
-
@fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
|
2727 |
-
$v_size -= $v_read_size;
|
2728 |
-
}
|
2729 |
-
$v_offset = @ftell($v_zip_temp_fd);
|
2730 |
-
$v_size = $v_central_dir['size'];
|
2731 |
-
while ($v_size != 0)
|
2732 |
-
{
|
2733 |
-
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
2734 |
-
$v_buffer = @fread($this->zip_fd, $v_read_size);
|
2735 |
-
@fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
|
2736 |
-
$v_size -= $v_read_size;
|
2737 |
-
}
|
2738 |
-
$v_size = $v_central_dir_to_add['size'];
|
2739 |
-
while ($v_size != 0)
|
2740 |
-
{
|
2741 |
-
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
2742 |
-
$v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size);
|
2743 |
-
@fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
|
2744 |
-
$v_size -= $v_read_size;
|
2745 |
-
}
|
2746 |
-
$v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment'];
|
2747 |
-
$v_size = @ftell($v_zip_temp_fd)-$v_offset;
|
2748 |
-
$v_swap = $this->zip_fd;
|
2749 |
-
$this->zip_fd = $v_zip_temp_fd;
|
2750 |
-
$v_zip_temp_fd = $v_swap;
|
2751 |
-
if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1)
|
2752 |
-
{
|
2753 |
-
$this->privCloseFd();
|
2754 |
-
$p_archive_to_add->privCloseFd();
|
2755 |
-
@fclose($v_zip_temp_fd);
|
2756 |
-
$this->zip_fd = null;
|
2757 |
-
unset($v_header_list);
|
2758 |
-
return $v_result;
|
2759 |
-
}
|
2760 |
-
$v_swap = $this->zip_fd;
|
2761 |
-
$this->zip_fd = $v_zip_temp_fd;
|
2762 |
-
$v_zip_temp_fd = $v_swap;
|
2763 |
-
$this->privCloseFd();
|
2764 |
-
$p_archive_to_add->privCloseFd();
|
2765 |
-
@fclose($v_zip_temp_fd);
|
2766 |
-
@unlink($this->zipname);
|
2767 |
-
PclZipUtilRename($v_zip_temp_name, $this->zipname);
|
2768 |
-
return $v_result;
|
2769 |
-
}
|
2770 |
-
function privDuplicate($p_archive_filename)
|
2771 |
-
{
|
2772 |
-
$v_result=1;
|
2773 |
-
if (!is_file($p_archive_filename))
|
2774 |
-
{
|
2775 |
-
$v_result = 1;
|
2776 |
-
return $v_result;
|
2777 |
-
}
|
2778 |
-
if (($v_result=$this->privOpenFd('wb')) != 1)
|
2779 |
-
{
|
2780 |
-
return $v_result;
|
2781 |
-
}
|
2782 |
-
if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0)
|
2783 |
-
{
|
2784 |
-
$this->privCloseFd();
|
2785 |
-
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode');
|
2786 |
-
return PclZip::errorCode();
|
2787 |
-
}
|
2788 |
-
$v_size = filesize($p_archive_filename);
|
2789 |
-
while ($v_size != 0)
|
2790 |
-
{
|
2791 |
-
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
2792 |
-
$v_buffer = fread($v_zip_temp_fd, $v_read_size);
|
2793 |
-
@fwrite($this->zip_fd, $v_buffer, $v_read_size);
|
2794 |
-
$v_size -= $v_read_size;
|
2795 |
-
}
|
2796 |
-
$this->privCloseFd();
|
2797 |
-
@fclose($v_zip_temp_fd);
|
2798 |
-
return $v_result;
|
2799 |
-
}
|
2800 |
-
function privErrorLog($p_error_code=0, $p_error_string='')
|
2801 |
-
{
|
2802 |
-
if (PCLZIP_ERROR_EXTERNAL == 1) {
|
2803 |
-
PclError($p_error_code, $p_error_string);
|
2804 |
-
}
|
2805 |
-
else {
|
2806 |
-
$this->error_code = $p_error_code;
|
2807 |
-
$this->error_string = $p_error_string;
|
2808 |
-
}
|
2809 |
-
}
|
2810 |
-
function privErrorReset()
|
2811 |
-
{
|
2812 |
-
if (PCLZIP_ERROR_EXTERNAL == 1) {
|
2813 |
-
PclErrorReset();
|
2814 |
-
}
|
2815 |
-
else {
|
2816 |
-
$this->error_code = 0;
|
2817 |
-
$this->error_string = '';
|
2818 |
-
}
|
2819 |
-
}
|
2820 |
-
function privDisableMagicQuotes()
|
2821 |
-
{
|
2822 |
-
$v_result=1;
|
2823 |
-
if ( (!function_exists("get_magic_quotes_runtime"))
|
2824 |
-
|| (!function_exists("set_magic_quotes_runtime"))) {
|
2825 |
-
return $v_result;
|
2826 |
-
}
|
2827 |
-
|
2828 |
-
|
2829 |
-
|
2830 |
-
|
2831 |
-
|
2832 |
-
|
2833 |
-
|
2834 |
-
|
2835 |
-
|
2836 |
-
|
2837 |
-
|
2838 |
-
|
2839 |
-
|
2840 |
-
|
2841 |
-
|
2842 |
-
|
2843 |
-
|
2844 |
-
|
2845 |
-
if (
|
2846 |
-
|
2847 |
-
|
2848 |
-
|
2849 |
-
|
2850 |
-
|
2851 |
-
|
2852 |
-
|
2853 |
-
|
2854 |
-
|
2855 |
-
|
2856 |
-
|
2857 |
-
|
2858 |
-
|
2859 |
-
|
2860 |
-
|
2861 |
-
|
2862 |
-
|
2863 |
-
|
2864 |
-
|
2865 |
-
|
2866 |
-
|
2867 |
-
|
2868 |
-
|
2869 |
-
|
2870 |
-
|
2871 |
-
|
2872 |
-
|
2873 |
-
|
2874 |
-
|
2875 |
-
|
2876 |
-
|
2877 |
-
|
2878 |
-
|
2879 |
-
|
2880 |
-
|
2881 |
-
|
2882 |
-
|
2883 |
-
|
2884 |
-
|
2885 |
-
|
2886 |
-
|
2887 |
-
// -----
|
2888 |
-
|
2889 |
-
|
2890 |
-
}
|
2891 |
-
|
2892 |
-
|
2893 |
-
}
|
2894 |
-
}
|
2895 |
-
|
2896 |
-
|
2897 |
-
|
2898 |
-
|
2899 |
-
|
2900 |
-
|
2901 |
-
|
2902 |
-
|
2903 |
-
|
2904 |
-
|
2905 |
-
|
2906 |
-
|
2907 |
-
|
2908 |
-
|
2909 |
-
|
2910 |
-
|
2911 |
-
}
|
2912 |
-
|
2913 |
-
|
2914 |
-
|
2915 |
-
|
2916 |
-
$
|
2917 |
-
|
2918 |
-
|
2919 |
-
|
2920 |
-
|
2921 |
-
|
2922 |
-
|
2923 |
-
$
|
2924 |
-
|
2925 |
-
|
2926 |
-
|
2927 |
-
|
2928 |
-
|
2929 |
-
|
2930 |
-
|
2931 |
-
|
2932 |
-
|
2933 |
-
|
2934 |
-
|
2935 |
-
|
2936 |
-
|
2937 |
-
|
2938 |
-
|
2939 |
-
|
2940 |
-
if (($
|
2941 |
-
$v_result =
|
2942 |
-
}
|
2943 |
-
$i
|
2944 |
-
|
2945 |
-
|
2946 |
-
|
2947 |
-
|
2948 |
-
|
2949 |
-
|
2950 |
-
|
2951 |
-
|
2952 |
-
|
2953 |
-
|
2954 |
-
|
2955 |
-
|
2956 |
-
|
2957 |
-
|
2958 |
-
|
2959 |
-
|
2960 |
-
|
2961 |
-
|
2962 |
-
|
2963 |
-
|
2964 |
-
|
2965 |
-
|
2966 |
-
$
|
2967 |
-
@
|
2968 |
-
$
|
2969 |
-
|
2970 |
-
|
2971 |
-
|
2972 |
-
|
2973 |
-
|
2974 |
-
|
2975 |
-
|
2976 |
-
$
|
2977 |
-
@
|
2978 |
-
$
|
2979 |
-
|
2980 |
-
|
2981 |
-
|
2982 |
-
|
2983 |
-
|
2984 |
-
|
2985 |
-
|
2986 |
-
$
|
2987 |
-
@
|
2988 |
-
$
|
2989 |
-
|
2990 |
-
|
2991 |
-
|
2992 |
-
|
2993 |
-
|
2994 |
-
|
2995 |
-
|
2996 |
-
|
2997 |
-
|
2998 |
-
|
2999 |
-
|
3000 |
-
|
3001 |
-
|
3002 |
-
|
3003 |
-
|
3004 |
-
|
3005 |
-
$v_result
|
3006 |
-
|
3007 |
-
|
3008 |
-
|
3009 |
-
|
3010 |
-
|
3011 |
-
|
3012 |
-
|
3013 |
-
|
3014 |
-
|
3015 |
-
|
3016 |
-
|
3017 |
-
|
3018 |
-
|
3019 |
-
|
3020 |
-
|
3021 |
-
|
3022 |
-
|
3023 |
-
|
3024 |
-
|
3025 |
-
|
3026 |
-
|
3027 |
-
|
3028 |
-
|
3029 |
-
|
3030 |
-
|
3031 |
-
|
3032 |
-
|
3033 |
-
|
3034 |
-
|
3035 |
-
$p_path = substr($p_path, $v_position+1);
|
3036 |
-
}
|
3037 |
-
if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
|
3038 |
-
$p_path = strtr($p_path, '\\', '/');
|
3039 |
-
}
|
3040 |
-
}
|
3041 |
-
return $p_path;
|
3042 |
-
}
|
3043 |
-
?>
|
1 |
+
<?php
|
2 |
+
if (!defined('PCLZIP_READ_BLOCK_SIZE')) {
|
3 |
+
define( 'PCLZIP_READ_BLOCK_SIZE', 2048 );
|
4 |
+
}
|
5 |
+
if (!defined('PCLZIP_SEPARATOR')) {
|
6 |
+
define( 'PCLZIP_SEPARATOR', ',' );
|
7 |
+
}
|
8 |
+
if (!defined('PCLZIP_ERROR_EXTERNAL')) {
|
9 |
+
define( 'PCLZIP_ERROR_EXTERNAL', 0 );
|
10 |
+
}
|
11 |
+
if (!defined('PCLZIP_TEMPORARY_DIR')) {
|
12 |
+
define( 'PCLZIP_TEMPORARY_DIR', '' );
|
13 |
+
}
|
14 |
+
if (!defined('PCLZIP_TEMPORARY_FILE_RATIO')) {
|
15 |
+
define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.47 );
|
16 |
+
}
|
17 |
+
// --------------------------------------------------------------------------------
|
18 |
+
// ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED *****
|
19 |
+
// --------------------------------------------------------------------------------
|
20 |
+
$g_pclzip_version = "2.8.2";
|
21 |
+
define( 'PCLZIP_ERR_USER_ABORTED', 2 );
|
22 |
+
define( 'PCLZIP_ERR_NO_ERROR', 0 );
|
23 |
+
define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 );
|
24 |
+
define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 );
|
25 |
+
define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 );
|
26 |
+
define( 'PCLZIP_ERR_MISSING_FILE', -4 );
|
27 |
+
define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 );
|
28 |
+
define( 'PCLZIP_ERR_INVALID_ZIP', -6 );
|
29 |
+
define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 );
|
30 |
+
define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 );
|
31 |
+
define( 'PCLZIP_ERR_BAD_EXTENSION', -9 );
|
32 |
+
define( 'PCLZIP_ERR_BAD_FORMAT', -10 );
|
33 |
+
define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 );
|
34 |
+
define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 );
|
35 |
+
define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 );
|
36 |
+
define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 );
|
37 |
+
define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 );
|
38 |
+
define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 );
|
39 |
+
define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 );
|
40 |
+
define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 );
|
41 |
+
define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 );
|
42 |
+
define( 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20 );
|
43 |
+
define( 'PCLZIP_ERR_DIRECTORY_RESTRICTION', -21 );
|
44 |
+
define( 'PCLZIP_OPT_PATH', 77001 );
|
45 |
+
define( 'PCLZIP_OPT_ADD_PATH', 77002 );
|
46 |
+
define( 'PCLZIP_OPT_REMOVE_PATH', 77003 );
|
47 |
+
define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 );
|
48 |
+
define( 'PCLZIP_OPT_SET_CHMOD', 77005 );
|
49 |
+
define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 );
|
50 |
+
define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 );
|
51 |
+
define( 'PCLZIP_OPT_BY_NAME', 77008 );
|
52 |
+
define( 'PCLZIP_OPT_BY_INDEX', 77009 );
|
53 |
+
define( 'PCLZIP_OPT_BY_EREG', 77010 );
|
54 |
+
define( 'PCLZIP_OPT_BY_PREG', 77011 );
|
55 |
+
define( 'PCLZIP_OPT_COMMENT', 77012 );
|
56 |
+
define( 'PCLZIP_OPT_ADD_COMMENT', 77013 );
|
57 |
+
define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 );
|
58 |
+
define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 );
|
59 |
+
define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 );
|
60 |
+
define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 );
|
61 |
+
define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 );
|
62 |
+
define( 'PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020 );
|
63 |
+
define( 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020 ); // alias
|
64 |
+
define( 'PCLZIP_OPT_TEMP_FILE_ON', 77021 );
|
65 |
+
define( 'PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021 ); // alias
|
66 |
+
define( 'PCLZIP_OPT_TEMP_FILE_OFF', 77022 );
|
67 |
+
define( 'PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022 ); // alias
|
68 |
+
define( 'PCLZIP_ATT_FILE_NAME', 79001 );
|
69 |
+
define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 );
|
70 |
+
define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 );
|
71 |
+
define( 'PCLZIP_ATT_FILE_MTIME', 79004 );
|
72 |
+
define( 'PCLZIP_ATT_FILE_CONTENT', 79005 );
|
73 |
+
define( 'PCLZIP_ATT_FILE_COMMENT', 79006 );
|
74 |
+
define( 'PCLZIP_CB_PRE_EXTRACT', 78001 );
|
75 |
+
define( 'PCLZIP_CB_POST_EXTRACT', 78002 );
|
76 |
+
define( 'PCLZIP_CB_PRE_ADD', 78003 );
|
77 |
+
define( 'PCLZIP_CB_POST_ADD', 78004 );
|
78 |
+
/* For futur use
|
79 |
+
define( 'PCLZIP_CB_PRE_LIST', 78005 );
|
80 |
+
define( 'PCLZIP_CB_POST_LIST', 78006 );
|
81 |
+
define( 'PCLZIP_CB_PRE_DELETE', 78007 );
|
82 |
+
define( 'PCLZIP_CB_POST_DELETE', 78008 );
|
83 |
+
*/
|
84 |
+
class PclZip
|
85 |
+
{
|
86 |
+
var $zipname = '';
|
87 |
+
var $zip_fd = 0;
|
88 |
+
var $error_code = 1;
|
89 |
+
var $error_string = '';
|
90 |
+
var $magic_quotes_status;
|
91 |
+
function PclZip($p_zipname)
|
92 |
+
{
|
93 |
+
if (!function_exists('gzopen'))
|
94 |
+
{
|
95 |
+
die('Abort '.basename(__FILE__).' : Missing zlib extensions');
|
96 |
+
}
|
97 |
+
$this->zipname = $p_zipname;
|
98 |
+
$this->zip_fd = 0;
|
99 |
+
$this->magic_quotes_status = -1;
|
100 |
+
return;
|
101 |
+
}
|
102 |
+
function create($p_filelist)
|
103 |
+
{
|
104 |
+
$v_result=1;
|
105 |
+
$this->privErrorReset();
|
106 |
+
$v_options = array();
|
107 |
+
$v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
|
108 |
+
$v_size = func_num_args();
|
109 |
+
if ($v_size > 1) {
|
110 |
+
$v_arg_list = func_get_args();
|
111 |
+
array_shift($v_arg_list);
|
112 |
+
$v_size--;
|
113 |
+
if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
|
114 |
+
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
|
115 |
+
array (PCLZIP_OPT_REMOVE_PATH => 'optional',
|
116 |
+
PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
|
117 |
+
PCLZIP_OPT_ADD_PATH => 'optional',
|
118 |
+
PCLZIP_CB_PRE_ADD => 'optional',
|
119 |
+
PCLZIP_CB_POST_ADD => 'optional',
|
120 |
+
PCLZIP_OPT_NO_COMPRESSION => 'optional',
|
121 |
+
PCLZIP_OPT_COMMENT => 'optional',
|
122 |
+
PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
|
123 |
+
PCLZIP_OPT_TEMP_FILE_ON => 'optional',
|
124 |
+
PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
|
125 |
+
));
|
126 |
+
if ($v_result != 1) {
|
127 |
+
return 0;
|
128 |
+
}
|
129 |
+
}
|
130 |
+
else {
|
131 |
+
$v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];
|
132 |
+
if ($v_size == 2) {
|
133 |
+
$v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
|
134 |
+
}
|
135 |
+
else if ($v_size > 2) {
|
136 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
|
137 |
+
"Invalid number / type of arguments");
|
138 |
+
return 0;
|
139 |
+
}
|
140 |
+
}
|
141 |
+
}
|
142 |
+
$this->privOptionDefaultThreshold($v_options);
|
143 |
+
$v_string_list = array();
|
144 |
+
$v_att_list = array();
|
145 |
+
$v_filedescr_list = array();
|
146 |
+
$p_result_list = array();
|
147 |
+
if (is_array($p_filelist)) {
|
148 |
+
if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
|
149 |
+
$v_att_list = $p_filelist;
|
150 |
+
}
|
151 |
+
else {
|
152 |
+
$v_string_list = $p_filelist;
|
153 |
+
}
|
154 |
+
}
|
155 |
+
else if (is_string($p_filelist)) {
|
156 |
+
$v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
|
157 |
+
}
|
158 |
+
else {
|
159 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
|
160 |
+
return 0;
|
161 |
+
}
|
162 |
+
if (sizeof($v_string_list) != 0) {
|
163 |
+
foreach ($v_string_list as $v_string) {
|
164 |
+
if ($v_string != '') {
|
165 |
+
$v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
|
166 |
+
}
|
167 |
+
else {
|
168 |
+
}
|
169 |
+
}
|
170 |
+
}
|
171 |
+
$v_supported_attributes
|
172 |
+
= array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
|
173 |
+
,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
|
174 |
+
,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
|
175 |
+
,PCLZIP_ATT_FILE_MTIME => 'optional'
|
176 |
+
,PCLZIP_ATT_FILE_CONTENT => 'optional'
|
177 |
+
,PCLZIP_ATT_FILE_COMMENT => 'optional'
|
178 |
+
);
|
179 |
+
foreach ($v_att_list as $v_entry) {
|
180 |
+
$v_result = $this->privFileDescrParseAtt($v_entry,
|
181 |
+
$v_filedescr_list[],
|
182 |
+
$v_options,
|
183 |
+
$v_supported_attributes);
|
184 |
+
if ($v_result != 1) {
|
185 |
+
return 0;
|
186 |
+
}
|
187 |
+
}
|
188 |
+
$v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
|
189 |
+
if ($v_result != 1) {
|
190 |
+
return 0;
|
191 |
+
}
|
192 |
+
$v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);
|
193 |
+
if ($v_result != 1) {
|
194 |
+
return 0;
|
195 |
+
}
|
196 |
+
return $p_result_list;
|
197 |
+
}
|
198 |
+
function add($p_filelist)
|
199 |
+
{
|
200 |
+
$v_result=1;
|
201 |
+
$this->privErrorReset();
|
202 |
+
$v_options = array();
|
203 |
+
$v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
|
204 |
+
$v_size = func_num_args();
|
205 |
+
if ($v_size > 1) {
|
206 |
+
$v_arg_list = func_get_args();
|
207 |
+
array_shift($v_arg_list);
|
208 |
+
$v_size--;
|
209 |
+
if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
|
210 |
+
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
|
211 |
+
array (PCLZIP_OPT_REMOVE_PATH => 'optional',
|
212 |
+
PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
|
213 |
+
PCLZIP_OPT_ADD_PATH => 'optional',
|
214 |
+
PCLZIP_CB_PRE_ADD => 'optional',
|
215 |
+
PCLZIP_CB_POST_ADD => 'optional',
|
216 |
+
PCLZIP_OPT_NO_COMPRESSION => 'optional',
|
217 |
+
PCLZIP_OPT_COMMENT => 'optional',
|
218 |
+
PCLZIP_OPT_ADD_COMMENT => 'optional',
|
219 |
+
PCLZIP_OPT_PREPEND_COMMENT => 'optional',
|
220 |
+
PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
|
221 |
+
PCLZIP_OPT_TEMP_FILE_ON => 'optional',
|
222 |
+
PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
|
223 |
+
));
|
224 |
+
if ($v_result != 1) {
|
225 |
+
return 0;
|
226 |
+
}
|
227 |
+
}
|
228 |
+
else {
|
229 |
+
$v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];
|
230 |
+
if ($v_size == 2) {
|
231 |
+
$v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
|
232 |
+
}
|
233 |
+
else if ($v_size > 2) {
|
234 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
|
235 |
+
return 0;
|
236 |
+
}
|
237 |
+
}
|
238 |
+
}
|
239 |
+
$this->privOptionDefaultThreshold($v_options);
|
240 |
+
$v_string_list = array();
|
241 |
+
$v_att_list = array();
|
242 |
+
$v_filedescr_list = array();
|
243 |
+
$p_result_list = array();
|
244 |
+
if (is_array($p_filelist)) {
|
245 |
+
if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
|
246 |
+
$v_att_list = $p_filelist;
|
247 |
+
}
|
248 |
+
else {
|
249 |
+
$v_string_list = $p_filelist;
|
250 |
+
}
|
251 |
+
}
|
252 |
+
else if (is_string($p_filelist)) {
|
253 |
+
$v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
|
254 |
+
}
|
255 |
+
else {
|
256 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");
|
257 |
+
return 0;
|
258 |
+
}
|
259 |
+
if (sizeof($v_string_list) != 0) {
|
260 |
+
foreach ($v_string_list as $v_string) {
|
261 |
+
$v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
|
262 |
+
}
|
263 |
+
}
|
264 |
+
$v_supported_attributes
|
265 |
+
= array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
|
266 |
+
,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
|
267 |
+
,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
|
268 |
+
,PCLZIP_ATT_FILE_MTIME => 'optional'
|
269 |
+
,PCLZIP_ATT_FILE_CONTENT => 'optional'
|
270 |
+
,PCLZIP_ATT_FILE_COMMENT => 'optional'
|
271 |
+
);
|
272 |
+
foreach ($v_att_list as $v_entry) {
|
273 |
+
$v_result = $this->privFileDescrParseAtt($v_entry,
|
274 |
+
$v_filedescr_list[],
|
275 |
+
$v_options,
|
276 |
+
$v_supported_attributes);
|
277 |
+
if ($v_result != 1) {
|
278 |
+
return 0;
|
279 |
+
}
|
280 |
+
}
|
281 |
+
$v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
|
282 |
+
if ($v_result != 1) {
|
283 |
+
return 0;
|
284 |
+
}
|
285 |
+
$v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);
|
286 |
+
if ($v_result != 1) {
|
287 |
+
return 0;
|
288 |
+
}
|
289 |
+
return $p_result_list;
|
290 |
+
}
|
291 |
+
function listContent()
|
292 |
+
{
|
293 |
+
$v_result=1;
|
294 |
+
$this->privErrorReset();
|
295 |
+
if (!$this->privCheckFormat()) {
|
296 |
+
return(0);
|
297 |
+
}
|
298 |
+
$p_list = array();
|
299 |
+
if (($v_result = $this->privList($p_list)) != 1)
|
300 |
+
{
|
301 |
+
unset($p_list);
|
302 |
+
return(0);
|
303 |
+
}
|
304 |
+
return $p_list;
|
305 |
+
}
|
306 |
+
function extract()
|
307 |
+
{
|
308 |
+
$v_result=1;
|
309 |
+
$this->privErrorReset();
|
310 |
+
if (!$this->privCheckFormat()) {
|
311 |
+
return(0);
|
312 |
+
}
|
313 |
+
$v_options = array();
|
314 |
+
// $v_path = "./";
|
315 |
+
$v_path = '';
|
316 |
+
$v_remove_path = "";
|
317 |
+
$v_remove_all_path = false;
|
318 |
+
$v_size = func_num_args();
|
319 |
+
$v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
|
320 |
+
if ($v_size > 0) {
|
321 |
+
$v_arg_list = func_get_args();
|
322 |
+
if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
|
323 |
+
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
|
324 |
+
array (PCLZIP_OPT_PATH => 'optional',
|
325 |
+
PCLZIP_OPT_REMOVE_PATH => 'optional',
|
326 |
+
PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
|
327 |
+
PCLZIP_OPT_ADD_PATH => 'optional',
|
328 |
+
PCLZIP_CB_PRE_EXTRACT => 'optional',
|
329 |
+
PCLZIP_CB_POST_EXTRACT => 'optional',
|
330 |
+
PCLZIP_OPT_SET_CHMOD => 'optional',
|
331 |
+
PCLZIP_OPT_BY_NAME => 'optional',
|
332 |
+
PCLZIP_OPT_BY_EREG => 'optional',
|
333 |
+
PCLZIP_OPT_BY_PREG => 'optional',
|
334 |
+
PCLZIP_OPT_BY_INDEX => 'optional',
|
335 |
+
PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
|
336 |
+
PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
|
337 |
+
PCLZIP_OPT_REPLACE_NEWER => 'optional'
|
338 |
+
,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
|
339 |
+
,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
|
340 |
+
PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
|
341 |
+
PCLZIP_OPT_TEMP_FILE_ON => 'optional',
|
342 |
+
PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
|
343 |
+
));
|
344 |
+
if ($v_result != 1) {
|
345 |
+
return 0;
|
346 |
+
}
|
347 |
+
if (isset($v_options[PCLZIP_OPT_PATH])) {
|
348 |
+
$v_path = $v_options[PCLZIP_OPT_PATH];
|
349 |
+
}
|
350 |
+
if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
|
351 |
+
$v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
|
352 |
+
}
|
353 |
+
if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
|
354 |
+
$v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
|
355 |
+
}
|
356 |
+
if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
|
357 |
+
if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
|
358 |
+
$v_path .= '/';
|
359 |
+
}
|
360 |
+
$v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
|
361 |
+
}
|
362 |
+
}
|
363 |
+
else {
|
364 |
+
$v_path = $v_arg_list[0];
|
365 |
+
if ($v_size == 2) {
|
366 |
+
$v_remove_path = $v_arg_list[1];
|
367 |
+
}
|
368 |
+
else if ($v_size > 2) {
|
369 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
|
370 |
+
return 0;
|
371 |
+
}
|
372 |
+
}
|
373 |
+
}
|
374 |
+
$this->privOptionDefaultThreshold($v_options);
|
375 |
+
$p_list = array();
|
376 |
+
$v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,
|
377 |
+
$v_remove_all_path, $v_options);
|
378 |
+
if ($v_result < 1) {
|
379 |
+
unset($p_list);
|
380 |
+
return(0);
|
381 |
+
}
|
382 |
+
return $p_list;
|
383 |
+
}
|
384 |
+
function extractByIndex($p_index)
|
385 |
+
{
|
386 |
+
$v_result=1;
|
387 |
+
$this->privErrorReset();
|
388 |
+
if (!$this->privCheckFormat()) {
|
389 |
+
return(0);
|
390 |
+
}
|
391 |
+
$v_options = array();
|
392 |
+
// $v_path = "./";
|
393 |
+
$v_path = '';
|
394 |
+
$v_remove_path = "";
|
395 |
+
$v_remove_all_path = false;
|
396 |
+
$v_size = func_num_args();
|
397 |
+
$v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
|
398 |
+
if ($v_size > 1) {
|
399 |
+
$v_arg_list = func_get_args();
|
400 |
+
array_shift($v_arg_list);
|
401 |
+
$v_size--;
|
402 |
+
if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
|
403 |
+
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
|
404 |
+
array (PCLZIP_OPT_PATH => 'optional',
|
405 |
+
PCLZIP_OPT_REMOVE_PATH => 'optional',
|
406 |
+
PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
|
407 |
+
PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
|
408 |
+
PCLZIP_OPT_ADD_PATH => 'optional',
|
409 |
+
PCLZIP_CB_PRE_EXTRACT => 'optional',
|
410 |
+
PCLZIP_CB_POST_EXTRACT => 'optional',
|
411 |
+
PCLZIP_OPT_SET_CHMOD => 'optional',
|
412 |
+
PCLZIP_OPT_REPLACE_NEWER => 'optional'
|
413 |
+
,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
|
414 |
+
,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
|
415 |
+
PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
|
416 |
+
PCLZIP_OPT_TEMP_FILE_ON => 'optional',
|
417 |
+
PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
|
418 |
+
));
|
419 |
+
if ($v_result != 1) {
|
420 |
+
return 0;
|
421 |
+
}
|
422 |
+
if (isset($v_options[PCLZIP_OPT_PATH])) {
|
423 |
+
$v_path = $v_options[PCLZIP_OPT_PATH];
|
424 |
+
}
|
425 |
+
if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
|
426 |
+
$v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
|
427 |
+
}
|
428 |
+
if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
|
429 |
+
$v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
|
430 |
+
}
|
431 |
+
if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
|
432 |
+
if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
|
433 |
+
$v_path .= '/';
|
434 |
+
}
|
435 |
+
$v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
|
436 |
+
}
|
437 |
+
if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
|
438 |
+
$v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
|
439 |
+
}
|
440 |
+
else {
|
441 |
+
}
|
442 |
+
}
|
443 |
+
else {
|
444 |
+
$v_path = $v_arg_list[0];
|
445 |
+
if ($v_size == 2) {
|
446 |
+
$v_remove_path = $v_arg_list[1];
|
447 |
+
}
|
448 |
+
else if ($v_size > 2) {
|
449 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
|
450 |
+
return 0;
|
451 |
+
}
|
452 |
+
}
|
453 |
+
}
|
454 |
+
$v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
|
455 |
+
$v_options_trick = array();
|
456 |
+
$v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,
|
457 |
+
array (PCLZIP_OPT_BY_INDEX => 'optional' ));
|
458 |
+
if ($v_result != 1) {
|
459 |
+
return 0;
|
460 |
+
}
|
461 |
+
$v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
|
462 |
+
$this->privOptionDefaultThreshold($v_options);
|
463 |
+
if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
|
464 |
+
return(0);
|
465 |
+
}
|
466 |
+
return $p_list;
|
467 |
+
}
|
468 |
+
function delete()
|
469 |
+
{
|
470 |
+
$v_result=1;
|
471 |
+
$this->privErrorReset();
|
472 |
+
if (!$this->privCheckFormat()) {
|
473 |
+
return(0);
|
474 |
+
}
|
475 |
+
$v_options = array();
|
476 |
+
$v_size = func_num_args();
|
477 |
+
if ($v_size > 0) {
|
478 |
+
$v_arg_list = func_get_args();
|
479 |
+
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
|
480 |
+
array (PCLZIP_OPT_BY_NAME => 'optional',
|
481 |
+
PCLZIP_OPT_BY_EREG => 'optional',
|
482 |
+
PCLZIP_OPT_BY_PREG => 'optional',
|
483 |
+
PCLZIP_OPT_BY_INDEX => 'optional' ));
|
484 |
+
if ($v_result != 1) {
|
485 |
+
return 0;
|
486 |
+
}
|
487 |
+
}
|
488 |
+
$this->privDisableMagicQuotes();
|
489 |
+
$v_list = array();
|
490 |
+
if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
|
491 |
+
$this->privSwapBackMagicQuotes();
|
492 |
+
unset($v_list);
|
493 |
+
return(0);
|
494 |
+
}
|
495 |
+
$this->privSwapBackMagicQuotes();
|
496 |
+
return $v_list;
|
497 |
+
}
|
498 |
+
function deleteByIndex($p_index)
|
499 |
+
{
|
500 |
+
$p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
|
501 |
+
return $p_list;
|
502 |
+
}
|
503 |
+
function properties()
|
504 |
+
{
|
505 |
+
$this->privErrorReset();
|
506 |
+
$this->privDisableMagicQuotes();
|
507 |
+
if (!$this->privCheckFormat()) {
|
508 |
+
$this->privSwapBackMagicQuotes();
|
509 |
+
return(0);
|
510 |
+
}
|
511 |
+
$v_prop = array();
|
512 |
+
$v_prop['comment'] = '';
|
513 |
+
$v_prop['nb'] = 0;
|
514 |
+
$v_prop['status'] = 'not_exist';
|
515 |
+
if (@is_file($this->zipname))
|
516 |
+
{
|
517 |
+
if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
|
518 |
+
{
|
519 |
+
$this->privSwapBackMagicQuotes();
|
520 |
+
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
|
521 |
+
return 0;
|
522 |
+
}
|
523 |
+
$v_central_dir = array();
|
524 |
+
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
|
525 |
+
{
|
526 |
+
$this->privSwapBackMagicQuotes();
|
527 |
+
return 0;
|
528 |
+
}
|
529 |
+
$this->privCloseFd();
|
530 |
+
$v_prop['comment'] = $v_central_dir['comment'];
|
531 |
+
$v_prop['nb'] = $v_central_dir['entries'];
|
532 |
+
$v_prop['status'] = 'ok';
|
533 |
+
}
|
534 |
+
$this->privSwapBackMagicQuotes();
|
535 |
+
return $v_prop;
|
536 |
+
}
|
537 |
+
function duplicate($p_archive)
|
538 |
+
{
|
539 |
+
$v_result = 1;
|
540 |
+
$this->privErrorReset();
|
541 |
+
if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
|
542 |
+
{
|
543 |
+
$v_result = $this->privDuplicate($p_archive->zipname);
|
544 |
+
}
|
545 |
+
else if (is_string($p_archive))
|
546 |
+
{
|
547 |
+
if (!is_file($p_archive)) {
|
548 |
+
PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
|
549 |
+
$v_result = PCLZIP_ERR_MISSING_FILE;
|
550 |
+
}
|
551 |
+
else {
|
552 |
+
$v_result = $this->privDuplicate($p_archive);
|
553 |
+
}
|
554 |
+
}
|
555 |
+
else
|
556 |
+
{
|
557 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
|
558 |
+
$v_result = PCLZIP_ERR_INVALID_PARAMETER;
|
559 |
+
}
|
560 |
+
return $v_result;
|
561 |
+
}
|
562 |
+
function merge($p_archive_to_add)
|
563 |
+
{
|
564 |
+
$v_result = 1;
|
565 |
+
$this->privErrorReset();
|
566 |
+
if (!$this->privCheckFormat()) {
|
567 |
+
return(0);
|
568 |
+
}
|
569 |
+
if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
|
570 |
+
{
|
571 |
+
$v_result = $this->privMerge($p_archive_to_add);
|
572 |
+
}
|
573 |
+
else if (is_string($p_archive_to_add))
|
574 |
+
{
|
575 |
+
$v_object_archive = new PclZip($p_archive_to_add);
|
576 |
+
$v_result = $this->privMerge($v_object_archive);
|
577 |
+
}
|
578 |
+
else
|
579 |
+
{
|
580 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
|
581 |
+
$v_result = PCLZIP_ERR_INVALID_PARAMETER;
|
582 |
+
}
|
583 |
+
return $v_result;
|
584 |
+
}
|
585 |
+
function errorCode()
|
586 |
+
{
|
587 |
+
if (PCLZIP_ERROR_EXTERNAL == 1) {
|
588 |
+
return(PclErrorCode());
|
589 |
+
}
|
590 |
+
else {
|
591 |
+
return($this->error_code);
|
592 |
+
}
|
593 |
+
}
|
594 |
+
function errorName($p_with_code=false)
|
595 |
+
{
|
596 |
+
$v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
|
597 |
+
PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
|
598 |
+
PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
|
599 |
+
PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
|
600 |
+
PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
|
601 |
+
PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
|
602 |
+
PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
|
603 |
+
PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
|
604 |
+
PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
|
605 |
+
PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
|
606 |
+
PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
|
607 |
+
PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
|
608 |
+
PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
|
609 |
+
PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
|
610 |
+
PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
|
611 |
+
PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
|
612 |
+
PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
|
613 |
+
PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',
|
614 |
+
PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION'
|
615 |
+
,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE'
|
616 |
+
,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION'
|
617 |
+
);
|
618 |
+
if (isset($v_name[$this->error_code])) {
|
619 |
+
$v_value = $v_name[$this->error_code];
|
620 |
+
}
|
621 |
+
else {
|
622 |
+
$v_value = 'NoName';
|
623 |
+
}
|
624 |
+
if ($p_with_code) {
|
625 |
+
return($v_value.' ('.$this->error_code.')');
|
626 |
+
}
|
627 |
+
else {
|
628 |
+
return($v_value);
|
629 |
+
}
|
630 |
+
}
|
631 |
+
function errorInfo($p_full=false)
|
632 |
+
{
|
633 |
+
if (PCLZIP_ERROR_EXTERNAL == 1) {
|
634 |
+
return(PclErrorString());
|
635 |
+
}
|
636 |
+
else {
|
637 |
+
if ($p_full) {
|
638 |
+
return($this->errorName(true)." : ".$this->error_string);
|
639 |
+
}
|
640 |
+
else {
|
641 |
+
return($this->error_string." [code ".$this->error_code."]");
|
642 |
+
}
|
643 |
+
}
|
644 |
+
}
|
645 |
+
// --------------------------------------------------------------------------------
|
646 |
+
// ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS *****
|
647 |
+
// ***** *****
|
648 |
+
// ***** THESES FUNCTIONS MUST NOT BE USED DIRECTLY *****
|
649 |
+
// --------------------------------------------------------------------------------
|
650 |
+
function privCheckFormat($p_level=0)
|
651 |
+
{
|
652 |
+
$v_result = true;
|
653 |
+
// ----- Reset the file system cache
|
654 |
+
clearstatcache();
|
655 |
+
$this->privErrorReset();
|
656 |
+
if (!is_file($this->zipname)) {
|
657 |
+
PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");
|
658 |
+
return(false);
|
659 |
+
}
|
660 |
+
if (!is_readable($this->zipname)) {
|
661 |
+
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");
|
662 |
+
return(false);
|
663 |
+
}
|
664 |
+
return $v_result;
|
665 |
+
}
|
666 |
+
function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false)
|
667 |
+
{
|
668 |
+
$v_result=1;
|
669 |
+
$i=0;
|
670 |
+
while ($i<$p_size) {
|
671 |
+
if (!isset($v_requested_options[$p_options_list[$i]])) {
|
672 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");
|
673 |
+
return PclZip::errorCode();
|
674 |
+
}
|
675 |
+
switch ($p_options_list[$i]) {
|
676 |
+
case PCLZIP_OPT_PATH :
|
677 |
+
case PCLZIP_OPT_REMOVE_PATH :
|
678 |
+
case PCLZIP_OPT_ADD_PATH :
|
679 |
+
if (($i+1) >= $p_size) {
|
680 |
+
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
681 |
+
return PclZip::errorCode();
|
682 |
+
}
|
683 |
+
$v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
|
684 |
+
$i++;
|
685 |
+
break;
|
686 |
+
case PCLZIP_OPT_TEMP_FILE_THRESHOLD :
|
687 |
+
if (($i+1) >= $p_size) {
|
688 |
+
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
689 |
+
return PclZip::errorCode();
|
690 |
+
}
|
691 |
+
if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
|
692 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
|
693 |
+
return PclZip::errorCode();
|
694 |
+
}
|
695 |
+
$v_value = $p_options_list[$i+1];
|
696 |
+
if ((!is_integer($v_value)) || ($v_value<0)) {
|
697 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
698 |
+
return PclZip::errorCode();
|
699 |
+
}
|
700 |
+
$v_result_list[$p_options_list[$i]] = $v_value*1048576;
|
701 |
+
$i++;
|
702 |
+
break;
|
703 |
+
case PCLZIP_OPT_TEMP_FILE_ON :
|
704 |
+
if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
|
705 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
|
706 |
+
return PclZip::errorCode();
|
707 |
+
}
|
708 |
+
$v_result_list[$p_options_list[$i]] = true;
|
709 |
+
break;
|
710 |
+
case PCLZIP_OPT_TEMP_FILE_OFF :
|
711 |
+
if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) {
|
712 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'");
|
713 |
+
return PclZip::errorCode();
|
714 |
+
}
|
715 |
+
if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
|
716 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'");
|
717 |
+
return PclZip::errorCode();
|
718 |
+
}
|
719 |
+
$v_result_list[$p_options_list[$i]] = true;
|
720 |
+
break;
|
721 |
+
case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION :
|
722 |
+
if (($i+1) >= $p_size) {
|
723 |
+
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
724 |
+
return PclZip::errorCode();
|
725 |
+
}
|
726 |
+
if ( is_string($p_options_list[$i+1])
|
727 |
+
&& ($p_options_list[$i+1] != '')) {
|
728 |
+
$v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
|
729 |
+
$i++;
|
730 |
+
}
|
731 |
+
else {
|
732 |
+
}
|
733 |
+
break;
|
734 |
+
case PCLZIP_OPT_BY_NAME :
|
735 |
+
if (($i+1) >= $p_size) {
|
736 |
+
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
737 |
+
return PclZip::errorCode();
|
738 |
+
}
|
739 |
+
if (is_string($p_options_list[$i+1])) {
|
740 |
+
$v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1];
|
741 |
+
}
|
742 |
+
else if (is_array($p_options_list[$i+1])) {
|
743 |
+
$v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
|
744 |
+
}
|
745 |
+
else {
|
746 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
747 |
+
return PclZip::errorCode();
|
748 |
+
}
|
749 |
+
$i++;
|
750 |
+
break;
|
751 |
+
case PCLZIP_OPT_BY_EREG :
|
752 |
+
$p_options_list[$i] = PCLZIP_OPT_BY_PREG;
|
753 |
+
case PCLZIP_OPT_BY_PREG :
|
754 |
+
if (($i+1) >= $p_size) {
|
755 |
+
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
756 |
+
return PclZip::errorCode();
|
757 |
+
}
|
758 |
+
if (is_string($p_options_list[$i+1])) {
|
759 |
+
$v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
|
760 |
+
}
|
761 |
+
else {
|
762 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
763 |
+
return PclZip::errorCode();
|
764 |
+
}
|
765 |
+
$i++;
|
766 |
+
break;
|
767 |
+
case PCLZIP_OPT_COMMENT :
|
768 |
+
case PCLZIP_OPT_ADD_COMMENT :
|
769 |
+
case PCLZIP_OPT_PREPEND_COMMENT :
|
770 |
+
if (($i+1) >= $p_size) {
|
771 |
+
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE,
|
772 |
+
"Missing parameter value for option '"
|
773 |
+
.PclZipUtilOptionText($p_options_list[$i])
|
774 |
+
."'");
|
775 |
+
return PclZip::errorCode();
|
776 |
+
}
|
777 |
+
if (is_string($p_options_list[$i+1])) {
|
778 |
+
$v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
|
779 |
+
}
|
780 |
+
else {
|
781 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE,
|
782 |
+
"Wrong parameter value for option '"
|
783 |
+
.PclZipUtilOptionText($p_options_list[$i])
|
784 |
+
."'");
|
785 |
+
return PclZip::errorCode();
|
786 |
+
}
|
787 |
+
$i++;
|
788 |
+
break;
|
789 |
+
case PCLZIP_OPT_BY_INDEX :
|
790 |
+
if (($i+1) >= $p_size) {
|
791 |
+
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
792 |
+
return PclZip::errorCode();
|
793 |
+
}
|
794 |
+
$v_work_list = array();
|
795 |
+
if (is_string($p_options_list[$i+1])) {
|
796 |
+
$p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', '');
|
797 |
+
$v_work_list = explode(",", $p_options_list[$i+1]);
|
798 |
+
}
|
799 |
+
else if (is_integer($p_options_list[$i+1])) {
|
800 |
+
$v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1];
|
801 |
+
}
|
802 |
+
else if (is_array($p_options_list[$i+1])) {
|
803 |
+
$v_work_list = $p_options_list[$i+1];
|
804 |
+
}
|
805 |
+
else {
|
806 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
807 |
+
return PclZip::errorCode();
|
808 |
+
}
|
809 |
+
$v_sort_flag=false;
|
810 |
+
$v_sort_value=0;
|
811 |
+
for ($j=0; $j<sizeof($v_work_list); $j++) {
|
812 |
+
$v_item_list = explode("-", $v_work_list[$j]);
|
813 |
+
$v_size_item_list = sizeof($v_item_list);
|
814 |
+
if ($v_size_item_list == 1) {
|
815 |
+
$v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
|
816 |
+
$v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0];
|
817 |
+
}
|
818 |
+
elseif ($v_size_item_list == 2) {
|
819 |
+
$v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
|
820 |
+
$v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1];
|
821 |
+
}
|
822 |
+
else {
|
823 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
824 |
+
return PclZip::errorCode();
|
825 |
+
}
|
826 |
+
if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) {
|
827 |
+
$v_sort_flag=true;
|
828 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
829 |
+
return PclZip::errorCode();
|
830 |
+
}
|
831 |
+
$v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start'];
|
832 |
+
}
|
833 |
+
if ($v_sort_flag) {
|
834 |
+
}
|
835 |
+
$i++;
|
836 |
+
break;
|
837 |
+
case PCLZIP_OPT_REMOVE_ALL_PATH :
|
838 |
+
case PCLZIP_OPT_EXTRACT_AS_STRING :
|
839 |
+
case PCLZIP_OPT_NO_COMPRESSION :
|
840 |
+
case PCLZIP_OPT_EXTRACT_IN_OUTPUT :
|
841 |
+
case PCLZIP_OPT_REPLACE_NEWER :
|
842 |
+
case PCLZIP_OPT_STOP_ON_ERROR :
|
843 |
+
$v_result_list[$p_options_list[$i]] = true;
|
844 |
+
break;
|
845 |
+
case PCLZIP_OPT_SET_CHMOD :
|
846 |
+
if (($i+1) >= $p_size) {
|
847 |
+
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
848 |
+
return PclZip::errorCode();
|
849 |
+
}
|
850 |
+
$v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
|
851 |
+
$i++;
|
852 |
+
break;
|
853 |
+
case PCLZIP_CB_PRE_EXTRACT :
|
854 |
+
case PCLZIP_CB_POST_EXTRACT :
|
855 |
+
case PCLZIP_CB_PRE_ADD :
|
856 |
+
case PCLZIP_CB_POST_ADD :
|
857 |
+
/* for futur use
|
858 |
+
case PCLZIP_CB_PRE_DELETE :
|
859 |
+
case PCLZIP_CB_POST_DELETE :
|
860 |
+
case PCLZIP_CB_PRE_LIST :
|
861 |
+
case PCLZIP_CB_POST_LIST :
|
862 |
+
*/
|
863 |
+
if (($i+1) >= $p_size) {
|
864 |
+
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
865 |
+
return PclZip::errorCode();
|
866 |
+
}
|
867 |
+
$v_function_name = $p_options_list[$i+1];
|
868 |
+
if (!function_exists($v_function_name)) {
|
869 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'");
|
870 |
+
return PclZip::errorCode();
|
871 |
+
}
|
872 |
+
$v_result_list[$p_options_list[$i]] = $v_function_name;
|
873 |
+
$i++;
|
874 |
+
break;
|
875 |
+
default :
|
876 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
|
877 |
+
"Unknown parameter '"
|
878 |
+
.$p_options_list[$i]."'");
|
879 |
+
return PclZip::errorCode();
|
880 |
+
}
|
881 |
+
$i++;
|
882 |
+
}
|
883 |
+
if ($v_requested_options !== false) {
|
884 |
+
for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
|
885 |
+
if ($v_requested_options[$key] == 'mandatory') {
|
886 |
+
if (!isset($v_result_list[$key])) {
|
887 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
|
888 |
+
return PclZip::errorCode();
|
889 |
+
}
|
890 |
+
}
|
891 |
+
}
|
892 |
+
}
|
893 |
+
if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
|
894 |
+
}
|
895 |
+
return $v_result;
|
896 |
+
}
|
897 |
+
function privOptionDefaultThreshold(&$p_options)
|
898 |
+
{
|
899 |
+
$v_result=1;
|
900 |
+
if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
|
901 |
+
|| isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) {
|
902 |
+
return $v_result;
|
903 |
+
}
|
904 |
+
$v_memory_limit = ini_get('memory_limit');
|
905 |
+
$v_memory_limit = trim($v_memory_limit);
|
906 |
+
$last = strtolower(substr($v_memory_limit, -1));
|
907 |
+
if($last == 'g')
|
908 |
+
$v_memory_limit = $v_memory_limit*1073741824;
|
909 |
+
if($last == 'm')
|
910 |
+
$v_memory_limit = $v_memory_limit*1048576;
|
911 |
+
if($last == 'k')
|
912 |
+
$v_memory_limit = $v_memory_limit*1024;
|
913 |
+
$p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO);
|
914 |
+
if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) {
|
915 |
+
unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]);
|
916 |
+
}
|
917 |
+
return $v_result;
|
918 |
+
}
|
919 |
+
function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false)
|
920 |
+
{
|
921 |
+
$v_result=1;
|
922 |
+
foreach ($p_file_list as $v_key => $v_value) {
|
923 |
+
if (!isset($v_requested_options[$v_key])) {
|
924 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file");
|
925 |
+
return PclZip::errorCode();
|
926 |
+
}
|
927 |
+
switch ($v_key) {
|
928 |
+
case PCLZIP_ATT_FILE_NAME :
|
929 |
+
if (!is_string($v_value)) {
|
930 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
|
931 |
+
return PclZip::errorCode();
|
932 |
+
}
|
933 |
+
$p_filedescr['filename'] = PclZipUtilPathReduction($v_value);
|
934 |
+
if ($p_filedescr['filename'] == '') {
|
935 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'");
|
936 |
+
return PclZip::errorCode();
|
937 |
+
}
|
938 |
+
break;
|
939 |
+
case PCLZIP_ATT_FILE_NEW_SHORT_NAME :
|
940 |
+
if (!is_string($v_value)) {
|
941 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
|
942 |
+
return PclZip::errorCode();
|
943 |
+
}
|
944 |
+
$p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value);
|
945 |
+
if ($p_filedescr['new_short_name'] == '') {
|
946 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'");
|
947 |
+
return PclZip::errorCode();
|
948 |
+
}
|
949 |
+
break;
|
950 |
+
case PCLZIP_ATT_FILE_NEW_FULL_NAME :
|
951 |
+
if (!is_string($v_value)) {
|
952 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
|
953 |
+
return PclZip::errorCode();
|
954 |
+
}
|
955 |
+
$p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value);
|
956 |
+
if ($p_filedescr['new_full_name'] == '') {
|
957 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'");
|
958 |
+
return PclZip::errorCode();
|
959 |
+
}
|
960 |
+
break;
|
961 |
+
case PCLZIP_ATT_FILE_COMMENT :
|
962 |
+
if (!is_string($v_value)) {
|
963 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
|
964 |
+
return PclZip::errorCode();
|
965 |
+
}
|
966 |
+
$p_filedescr['comment'] = $v_value;
|
967 |
+
break;
|
968 |
+
case PCLZIP_ATT_FILE_MTIME :
|
969 |
+
if (!is_integer($v_value)) {
|
970 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'");
|
971 |
+
return PclZip::errorCode();
|
972 |
+
}
|
973 |
+
$p_filedescr['mtime'] = $v_value;
|
974 |
+
break;
|
975 |
+
case PCLZIP_ATT_FILE_CONTENT :
|
976 |
+
$p_filedescr['content'] = $v_value;
|
977 |
+
break;
|
978 |
+
default :
|
979 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
|
980 |
+
"Unknown parameter '".$v_key."'");
|
981 |
+
return PclZip::errorCode();
|
982 |
+
}
|
983 |
+
if ($v_requested_options !== false) {
|
984 |
+
for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
|
985 |
+
if ($v_requested_options[$key] == 'mandatory') {
|
986 |
+
if (!isset($p_file_list[$key])) {
|
987 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
|
988 |
+
return PclZip::errorCode();
|
989 |
+
}
|
990 |
+
}
|
991 |
+
}
|
992 |
+
}
|
993 |
+
}
|
994 |
+
return $v_result;
|
995 |
+
}
|
996 |
+
function privFileDescrExpand(&$p_filedescr_list, &$p_options)
|
997 |
+
{
|
998 |
+
$v_result=1;
|
999 |
+
$v_result_list = array();
|
1000 |
+
for ($i=0; $i<sizeof($p_filedescr_list); $i++) {
|
1001 |
+
$v_descr = $p_filedescr_list[$i];
|
1002 |
+
$v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false);
|
1003 |
+
$v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']);
|
1004 |
+
if (file_exists($v_descr['filename'])) {
|
1005 |
+
if (@is_file($v_descr['filename'])) {
|
1006 |
+
$v_descr['type'] = 'file';
|
1007 |
+
}
|
1008 |
+
else if (@is_dir($v_descr['filename'])) {
|
1009 |
+
$v_descr['type'] = 'folder';
|
1010 |
+
}
|
1011 |
+
else if (@is_link($v_descr['filename'])) {
|
1012 |
+
continue;
|
1013 |
+
}
|
1014 |
+
else {
|
1015 |
+
continue;
|
1016 |
+
}
|
1017 |
+
}
|
1018 |
+
else if (isset($v_descr['content'])) {
|
1019 |
+
$v_descr['type'] = 'virtual_file';
|
1020 |
+
}
|
1021 |
+
else {
|
1022 |
+
PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist");
|
1023 |
+
return PclZip::errorCode();
|
1024 |
+
}
|
1025 |
+
$this->privCalculateStoredFilename($v_descr, $p_options);
|
1026 |
+
$v_result_list[sizeof($v_result_list)] = $v_descr;
|
1027 |
+
if ($v_descr['type'] == 'folder') {
|
1028 |
+
$v_dirlist_descr = array();
|
1029 |
+
$v_dirlist_nb = 0;
|
1030 |
+
if ($v_folder_handler = @opendir($v_descr['filename'])) {
|
1031 |
+
while (($v_item_handler = @readdir($v_folder_handler)) !== false) {
|
1032 |
+
if (($v_item_handler == '.') || ($v_item_handler == '..')) {
|
1033 |
+
continue;
|
1034 |
+
}
|
1035 |
+
$v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler;
|
1036 |
+
if (($v_descr['stored_filename'] != $v_descr['filename'])
|
1037 |
+
&& (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) {
|
1038 |
+
if ($v_descr['stored_filename'] != '') {
|
1039 |
+
$v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler;
|
1040 |
+
}
|
1041 |
+
else {
|
1042 |
+
$v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler;
|
1043 |
+
}
|
1044 |
+
}
|
1045 |
+
$v_dirlist_nb++;
|
1046 |
+
}
|
1047 |
+
@closedir($v_folder_handler);
|
1048 |
+
}
|
1049 |
+
else {
|
1050 |
+
}
|
1051 |
+
if ($v_dirlist_nb != 0) {
|
1052 |
+
if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) {
|
1053 |
+
return $v_result;
|
1054 |
+
}
|
1055 |
+
$v_result_list = array_merge($v_result_list, $v_dirlist_descr);
|
1056 |
+
}
|
1057 |
+
else {
|
1058 |
+
}
|
1059 |
+
unset($v_dirlist_descr);
|
1060 |
+
}
|
1061 |
+
}
|
1062 |
+
$p_filedescr_list = $v_result_list;
|
1063 |
+
return $v_result;
|
1064 |
+
}
|
1065 |
+
function privCreate($p_filedescr_list, &$p_result_list, &$p_options)
|
1066 |
+
{
|
1067 |
+
$v_result=1;
|
1068 |
+
$v_list_detail = array();
|
1069 |
+
$this->privDisableMagicQuotes();
|
1070 |
+
if (($v_result = $this->privOpenFd('wb')) != 1)
|
1071 |
+
{
|
1072 |
+
return $v_result;
|
1073 |
+
}
|
1074 |
+
$v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options);
|
1075 |
+
$this->privCloseFd();
|
1076 |
+
$this->privSwapBackMagicQuotes();
|
1077 |
+
return $v_result;
|
1078 |
+
}
|
1079 |
+
function privAdd($p_filedescr_list, &$p_result_list, &$p_options)
|
1080 |
+
{
|
1081 |
+
$v_result=1;
|
1082 |
+
$v_list_detail = array();
|
1083 |
+
if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0))
|
1084 |
+
{
|
1085 |
+
$v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options);
|
1086 |
+
return $v_result;
|
1087 |
+
}
|
1088 |
+
$this->privDisableMagicQuotes();
|
1089 |
+
if (($v_result=$this->privOpenFd('rb')) != 1)
|
1090 |
+
{
|
1091 |
+
$this->privSwapBackMagicQuotes();
|
1092 |
+
return $v_result;
|
1093 |
+
}
|
1094 |
+
$v_central_dir = array();
|
1095 |
+
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
|
1096 |
+
{
|
1097 |
+
$this->privCloseFd();
|
1098 |
+
$this->privSwapBackMagicQuotes();
|
1099 |
+
return $v_result;
|
1100 |
+
}
|
1101 |
+
@rewind($this->zip_fd);
|
1102 |
+
$v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
|
1103 |
+
if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
|
1104 |
+
{
|
1105 |
+
$this->privCloseFd();
|
1106 |
+
$this->privSwapBackMagicQuotes();
|
1107 |
+
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
|
1108 |
+
return PclZip::errorCode();
|
1109 |
+
}
|
1110 |
+
$v_size = $v_central_dir['offset'];
|
1111 |
+
while ($v_size != 0)
|
1112 |
+
{
|
1113 |
+
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
1114 |
+
$v_buffer = fread($this->zip_fd, $v_read_size);
|
1115 |
+
@fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
|
1116 |
+
$v_size -= $v_read_size;
|
1117 |
+
}
|
1118 |
+
$v_swap = $this->zip_fd;
|
1119 |
+
$this->zip_fd = $v_zip_temp_fd;
|
1120 |
+
$v_zip_temp_fd = $v_swap;
|
1121 |
+
$v_header_list = array();
|
1122 |
+
if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
|
1123 |
+
{
|
1124 |
+
fclose($v_zip_temp_fd);
|
1125 |
+
$this->privCloseFd();
|
1126 |
+
@unlink($v_zip_temp_name);
|
1127 |
+
$this->privSwapBackMagicQuotes();
|
1128 |
+
return $v_result;
|
1129 |
+
}
|
1130 |
+
$v_offset = @ftell($this->zip_fd);
|
1131 |
+
$v_size = $v_central_dir['size'];
|
1132 |
+
while ($v_size != 0)
|
1133 |
+
{
|
1134 |
+
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
1135 |
+
$v_buffer = @fread($v_zip_temp_fd, $v_read_size);
|
1136 |
+
@fwrite($this->zip_fd, $v_buffer, $v_read_size);
|
1137 |
+
$v_size -= $v_read_size;
|
1138 |
+
}
|
1139 |
+
for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++)
|
1140 |
+
{
|
1141 |
+
if ($v_header_list[$i]['status'] == 'ok') {
|
1142 |
+
if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
|
1143 |
+
fclose($v_zip_temp_fd);
|
1144 |
+
$this->privCloseFd();
|
1145 |
+
@unlink($v_zip_temp_name);
|
1146 |
+
$this->privSwapBackMagicQuotes();
|
1147 |
+
return $v_result;
|
1148 |
+
}
|
1149 |
+
$v_count++;
|
1150 |
+
}
|
1151 |
+
$this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
|
1152 |
+
}
|
1153 |
+
$v_comment = $v_central_dir['comment'];
|
1154 |
+
if (isset($p_options[PCLZIP_OPT_COMMENT])) {
|
1155 |
+
$v_comment = $p_options[PCLZIP_OPT_COMMENT];
|
1156 |
+
}
|
1157 |
+
if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {
|
1158 |
+
$v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT];
|
1159 |
+
}
|
1160 |
+
if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {
|
1161 |
+
$v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment;
|
1162 |
+
}
|
1163 |
+
$v_size = @ftell($this->zip_fd)-$v_offset;
|
1164 |
+
if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1)
|
1165 |
+
{
|
1166 |
+
unset($v_header_list);
|
1167 |
+
$this->privSwapBackMagicQuotes();
|
1168 |
+
return $v_result;
|
1169 |
+
}
|
1170 |
+
$v_swap = $this->zip_fd;
|
1171 |
+
$this->zip_fd = $v_zip_temp_fd;
|
1172 |
+
$v_zip_temp_fd = $v_swap;
|
1173 |
+
$this->privCloseFd();
|
1174 |
+
@fclose($v_zip_temp_fd);
|
1175 |
+
$this->privSwapBackMagicQuotes();
|
1176 |
+
@unlink($this->zipname);
|
1177 |
+
PclZipUtilRename($v_zip_temp_name, $this->zipname);
|
1178 |
+
return $v_result;
|
1179 |
+
}
|
1180 |
+
function privOpenFd($p_mode)
|
1181 |
+
{
|
1182 |
+
$v_result=1;
|
1183 |
+
if ($this->zip_fd != 0)
|
1184 |
+
{
|
1185 |
+
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open');
|
1186 |
+
return PclZip::errorCode();
|
1187 |
+
}
|
1188 |
+
if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0)
|
1189 |
+
{
|
1190 |
+
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');
|
1191 |
+
return PclZip::errorCode();
|
1192 |
+
}
|
1193 |
+
return $v_result;
|
1194 |
+
}
|
1195 |
+
function privCloseFd()
|
1196 |
+
{
|
1197 |
+
$v_result=1;
|
1198 |
+
if ($this->zip_fd != 0)
|
1199 |
+
@fclose($this->zip_fd);
|
1200 |
+
$this->zip_fd = 0;
|
1201 |
+
return $v_result;
|
1202 |
+
}
|
1203 |
+
// function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)
|
1204 |
+
function privAddList($p_filedescr_list, &$p_result_list, &$p_options)
|
1205 |
+
{
|
1206 |
+
$v_result=1;
|
1207 |
+
$v_header_list = array();
|
1208 |
+
if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
|
1209 |
+
{
|
1210 |
+
return $v_result;
|
1211 |
+
}
|
1212 |
+
$v_offset = @ftell($this->zip_fd);
|
1213 |
+
for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++)
|
1214 |
+
{
|
1215 |
+
if ($v_header_list[$i]['status'] == 'ok') {
|
1216 |
+
if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
|
1217 |
+
return $v_result;
|
1218 |
+
}
|
1219 |
+
$v_count++;
|
1220 |
+
}
|
1221 |
+
$this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
|
1222 |
+
}
|
1223 |
+
$v_comment = '';
|
1224 |
+
if (isset($p_options[PCLZIP_OPT_COMMENT])) {
|
1225 |
+
$v_comment = $p_options[PCLZIP_OPT_COMMENT];
|
1226 |
+
}
|
1227 |
+
$v_size = @ftell($this->zip_fd)-$v_offset;
|
1228 |
+
if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1)
|
1229 |
+
{
|
1230 |
+
unset($v_header_list);
|
1231 |
+
return $v_result;
|
1232 |
+
}
|
1233 |
+
return $v_result;
|
1234 |
+
}
|
1235 |
+
function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options)
|
1236 |
+
{
|
1237 |
+
$v_result=1;
|
1238 |
+
$v_header = array();
|
1239 |
+
$v_nb = sizeof($p_result_list);
|
1240 |
+
for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) {
|
1241 |
+
$p_filedescr_list[$j]['filename']
|
1242 |
+
= PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false);
|
1243 |
+
if ($p_filedescr_list[$j]['filename'] == "") {
|
1244 |
+
continue;
|
1245 |
+
}
|
1246 |
+
if ( ($p_filedescr_list[$j]['type'] != 'virtual_file')
|
1247 |
+
&& (!file_exists($p_filedescr_list[$j]['filename']))) {
|
1248 |
+
PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist");
|
1249 |
+
return PclZip::errorCode();
|
1250 |
+
}
|
1251 |
+
// if ( (is_file($p_filedescr_list[$j]['filename']))
|
1252 |
+
// || ( is_dir($p_filedescr_list[$j]['filename'])
|
1253 |
+
if ( ($p_filedescr_list[$j]['type'] == 'file')
|
1254 |
+
|| ($p_filedescr_list[$j]['type'] == 'virtual_file')
|
1255 |
+
|| ( ($p_filedescr_list[$j]['type'] == 'folder')
|
1256 |
+
&& ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])
|
1257 |
+
|| !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))
|
1258 |
+
) {
|
1259 |
+
$v_result = $this->privAddFile($p_filedescr_list[$j], $v_header,
|
1260 |
+
$p_options);
|
1261 |
+
if ($v_result != 1) {
|
1262 |
+
return $v_result;
|
1263 |
+
}
|
1264 |
+
$p_result_list[$v_nb++] = $v_header;
|
1265 |
+
}
|
1266 |
+
}
|
1267 |
+
return $v_result;
|
1268 |
+
}
|
1269 |
+
function privAddFile($p_filedescr, &$p_header, &$p_options)
|
1270 |
+
{
|
1271 |
+
$v_result=1;
|
1272 |
+
$p_filename = $p_filedescr['filename'];
|
1273 |
+
if ($p_filename == "") {
|
1274 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");
|
1275 |
+
return PclZip::errorCode();
|
1276 |
+
}
|
1277 |
+
/* TBC : Removed
|
1278 |
+
if (isset($p_filedescr['stored_filename'])) {
|
1279 |
+
$v_stored_filename = $p_filedescr['stored_filename'];
|
1280 |
+
}
|
1281 |
+
else {
|
1282 |
+
$v_stored_filename = $p_filedescr['stored_filename'];
|
1283 |
+
}
|
1284 |
+
*/
|
1285 |
+
clearstatcache();
|
1286 |
+
$p_header['version'] = 20;
|
1287 |
+
$p_header['version_extracted'] = 10;
|
1288 |
+
$p_header['flag'] = 0;
|
1289 |
+
$p_header['compression'] = 0;
|
1290 |
+
$p_header['crc'] = 0;
|
1291 |
+
$p_header['compressed_size'] = 0;
|
1292 |
+
$p_header['filename_len'] = strlen($p_filename);
|
1293 |
+
$p_header['extra_len'] = 0;
|
1294 |
+
$p_header['disk'] = 0;
|
1295 |
+
$p_header['internal'] = 0;
|
1296 |
+
$p_header['offset'] = 0;
|
1297 |
+
$p_header['filename'] = $p_filename;
|
1298 |
+
// TBC : Removed $p_header['stored_filename'] = $v_stored_filename;
|
1299 |
+
$p_header['stored_filename'] = $p_filedescr['stored_filename'];
|
1300 |
+
$p_header['extra'] = '';
|
1301 |
+
$p_header['status'] = 'ok';
|
1302 |
+
$p_header['index'] = -1;
|
1303 |
+
if ($p_filedescr['type']=='file') {
|
1304 |
+
$p_header['external'] = 0x00000000;
|
1305 |
+
$p_header['size'] = filesize($p_filename);
|
1306 |
+
}
|
1307 |
+
else if ($p_filedescr['type']=='folder') {
|
1308 |
+
$p_header['external'] = 0x00000010;
|
1309 |
+
$p_header['mtime'] = filemtime($p_filename);
|
1310 |
+
$p_header['size'] = filesize($p_filename);
|
1311 |
+
}
|
1312 |
+
else if ($p_filedescr['type'] == 'virtual_file') {
|
1313 |
+
$p_header['external'] = 0x00000000;
|
1314 |
+
$p_header['size'] = strlen($p_filedescr['content']);
|
1315 |
+
}
|
1316 |
+
if (isset($p_filedescr['mtime'])) {
|
1317 |
+
$p_header['mtime'] = $p_filedescr['mtime'];
|
1318 |
+
}
|
1319 |
+
else if ($p_filedescr['type'] == 'virtual_file') {
|
1320 |
+
$p_header['mtime'] = time();
|
1321 |
+
}
|
1322 |
+
else {
|
1323 |
+
$p_header['mtime'] = filemtime($p_filename);
|
1324 |
+
}
|
1325 |
+
if (isset($p_filedescr['comment'])) {
|
1326 |
+
$p_header['comment_len'] = strlen($p_filedescr['comment']);
|
1327 |
+
$p_header['comment'] = $p_filedescr['comment'];
|
1328 |
+
}
|
1329 |
+
else {
|
1330 |
+
$p_header['comment_len'] = 0;
|
1331 |
+
$p_header['comment'] = '';
|
1332 |
+
}
|
1333 |
+
if (isset($p_options[PCLZIP_CB_PRE_ADD])) {
|
1334 |
+
$v_local_header = array();
|
1335 |
+
$this->privConvertHeader2FileInfo($p_header, $v_local_header);
|
1336 |
+
// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);');
|
1337 |
+
$v_result = $p_options[PCLZIP_CB_PRE_ADD](PCLZIP_CB_PRE_ADD, $v_local_header);
|
1338 |
+
if ($v_result == 0) {
|
1339 |
+
$p_header['status'] = "skipped";
|
1340 |
+
$v_result = 1;
|
1341 |
+
}
|
1342 |
+
if ($p_header['stored_filename'] != $v_local_header['stored_filename']) {
|
1343 |
+
$p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']);
|
1344 |
+
}
|
1345 |
+
}
|
1346 |
+
if ($p_header['stored_filename'] == "") {
|
1347 |
+
$p_header['status'] = "filtered";
|
1348 |
+
}
|
1349 |
+
if (strlen($p_header['stored_filename']) > 0xFF) {
|
1350 |
+
$p_header['status'] = 'filename_too_long';
|
1351 |
+
}
|
1352 |
+
if ($p_header['status'] == 'ok') {
|
1353 |
+
if ($p_filedescr['type'] == 'file') {
|
1354 |
+
if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
|
1355 |
+
&& (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
|
1356 |
+
|| (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
|
1357 |
+
&& ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) {
|
1358 |
+
$v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options);
|
1359 |
+
if ($v_result < PCLZIP_ERR_NO_ERROR) {
|
1360 |
+
return $v_result;
|
1361 |
+
}
|
1362 |
+
}
|
1363 |
+
else {
|
1364 |
+
if (($v_file = @fopen($p_filename, "rb")) == 0) {
|
1365 |
+
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
|
1366 |
+
return PclZip::errorCode();
|
1367 |
+
}
|
1368 |
+
$v_content = @fread($v_file, $p_header['size']);
|
1369 |
+
@fclose($v_file);
|
1370 |
+
$p_header['crc'] = @crc32($v_content);
|
1371 |
+
if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
|
1372 |
+
$p_header['compressed_size'] = $p_header['size'];
|
1373 |
+
$p_header['compression'] = 0;
|
1374 |
+
}
|
1375 |
+
else {
|
1376 |
+
$v_content = @gzdeflate($v_content);
|
1377 |
+
$p_header['compressed_size'] = strlen($v_content);
|
1378 |
+
$p_header['compression'] = 8;
|
1379 |
+
}
|
1380 |
+
if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
|
1381 |
+
@fclose($v_file);
|
1382 |
+
return $v_result;
|
1383 |
+
}
|
1384 |
+
@fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
|
1385 |
+
}
|
1386 |
+
}
|
1387 |
+
else if ($p_filedescr['type'] == 'virtual_file') {
|
1388 |
+
$v_content = $p_filedescr['content'];
|
1389 |
+
$p_header['crc'] = @crc32($v_content);
|
1390 |
+
if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
|
1391 |
+
$p_header['compressed_size'] = $p_header['size'];
|
1392 |
+
$p_header['compression'] = 0;
|
1393 |
+
}
|
1394 |
+
else {
|
1395 |
+
$v_content = @gzdeflate($v_content);
|
1396 |
+
$p_header['compressed_size'] = strlen($v_content);
|
1397 |
+
$p_header['compression'] = 8;
|
1398 |
+
}
|
1399 |
+
if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
|
1400 |
+
@fclose($v_file);
|
1401 |
+
return $v_result;
|
1402 |
+
}
|
1403 |
+
@fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
|
1404 |
+
}
|
1405 |
+
else if ($p_filedescr['type'] == 'folder') {
|
1406 |
+
if (@substr($p_header['stored_filename'], -1) != '/') {
|
1407 |
+
$p_header['stored_filename'] .= '/';
|
1408 |
+
}
|
1409 |
+
$p_header['size'] = 0;
|
1410 |
+
$p_header['external'] = 0x00000010; // Value for a folder : to be checked
|
1411 |
+
if (($v_result = $this->privWriteFileHeader($p_header)) != 1)
|
1412 |
+
{
|
1413 |
+
return $v_result;
|
1414 |
+
}
|
1415 |
+
}
|
1416 |
+
}
|
1417 |
+
if (isset($p_options[PCLZIP_CB_POST_ADD])) {
|
1418 |
+
$v_local_header = array();
|
1419 |
+
$this->privConvertHeader2FileInfo($p_header, $v_local_header);
|
1420 |
+
// eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);');
|
1421 |
+
$v_result = $p_options[PCLZIP_CB_POST_ADD](PCLZIP_CB_POST_ADD, $v_local_header);
|
1422 |
+
if ($v_result == 0) {
|
1423 |
+
$v_result = 1;
|
1424 |
+
}
|
1425 |
+
}
|
1426 |
+
return $v_result;
|
1427 |
+
}
|
1428 |
+
function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options)
|
1429 |
+
{
|
1430 |
+
$v_result=PCLZIP_ERR_NO_ERROR;
|
1431 |
+
$p_filename = $p_filedescr['filename'];
|
1432 |
+
if (($v_file = @fopen($p_filename, "rb")) == 0) {
|
1433 |
+
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
|
1434 |
+
return PclZip::errorCode();
|
1435 |
+
}
|
1436 |
+
$v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
|
1437 |
+
if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) {
|
1438 |
+
fclose($v_file);
|
1439 |
+
PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
|
1440 |
+
return PclZip::errorCode();
|
1441 |
+
}
|
1442 |
+
$v_size = filesize($p_filename);
|
1443 |
+
while ($v_size != 0) {
|
1444 |
+
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
1445 |
+
$v_buffer = @fread($v_file, $v_read_size);
|
1446 |
+
@gzputs($v_file_compressed, $v_buffer, $v_read_size);
|
1447 |
+
$v_size -= $v_read_size;
|
1448 |
+
}
|
1449 |
+
@fclose($v_file);
|
1450 |
+
@gzclose($v_file_compressed);
|
1451 |
+
if (filesize($v_gzip_temp_name) < 18) {
|
1452 |
+
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes');
|
1453 |
+
return PclZip::errorCode();
|
1454 |
+
}
|
1455 |
+
if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) {
|
1456 |
+
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
|
1457 |
+
return PclZip::errorCode();
|
1458 |
+
}
|
1459 |
+
$v_binary_data = @fread($v_file_compressed, 10);
|
1460 |
+
$v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data);
|
1461 |
+
$v_data_header['os'] = bin2hex($v_data_header['os']);
|
1462 |
+
@fseek($v_file_compressed, filesize($v_gzip_temp_name)-8);
|
1463 |
+
$v_binary_data = @fread($v_file_compressed, 8);
|
1464 |
+
$v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data);
|
1465 |
+
$p_header['compression'] = ord($v_data_header['cm']);
|
1466 |
+
$p_header['crc'] = $v_data_footer['crc'];
|
1467 |
+
$p_header['compressed_size'] = filesize($v_gzip_temp_name)-18;
|
1468 |
+
@fclose($v_file_compressed);
|
1469 |
+
if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
|
1470 |
+
return $v_result;
|
1471 |
+
}
|
1472 |
+
if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0)
|
1473 |
+
{
|
1474 |
+
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
|
1475 |
+
return PclZip::errorCode();
|
1476 |
+
}
|
1477 |
+
fseek($v_file_compressed, 10);
|
1478 |
+
$v_size = $p_header['compressed_size'];
|
1479 |
+
while ($v_size != 0)
|
1480 |
+
{
|
1481 |
+
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
1482 |
+
$v_buffer = @fread($v_file_compressed, $v_read_size);
|
1483 |
+
@fwrite($this->zip_fd, $v_buffer, $v_read_size);
|
1484 |
+
$v_size -= $v_read_size;
|
1485 |
+
}
|
1486 |
+
@fclose($v_file_compressed);
|
1487 |
+
@unlink($v_gzip_temp_name);
|
1488 |
+
return $v_result;
|
1489 |
+
}
|
1490 |
+
function privCalculateStoredFilename(&$p_filedescr, &$p_options)
|
1491 |
+
{
|
1492 |
+
$v_result=1;
|
1493 |
+
$p_filename = $p_filedescr['filename'];
|
1494 |
+
if (isset($p_options[PCLZIP_OPT_ADD_PATH])) {
|
1495 |
+
$p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH];
|
1496 |
+
}
|
1497 |
+
else {
|
1498 |
+
$p_add_dir = '';
|
1499 |
+
}
|
1500 |
+
if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) {
|
1501 |
+
$p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH];
|
1502 |
+
}
|
1503 |
+
else {
|
1504 |
+
$p_remove_dir = '';
|
1505 |
+
}
|
1506 |
+
if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
|
1507 |
+
$p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH];
|
1508 |
+
}
|
1509 |
+
else {
|
1510 |
+
$p_remove_all_dir = 0;
|
1511 |
+
}
|
1512 |
+
if (isset($p_filedescr['new_full_name'])) {
|
1513 |
+
$v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']);
|
1514 |
+
}
|
1515 |
+
else {
|
1516 |
+
if (isset($p_filedescr['new_short_name'])) {
|
1517 |
+
$v_path_info = pathinfo($p_filename);
|
1518 |
+
$v_dir = '';
|
1519 |
+
if ($v_path_info['dirname'] != '') {
|
1520 |
+
$v_dir = $v_path_info['dirname'].'/';
|
1521 |
+
}
|
1522 |
+
$v_stored_filename = $v_dir.$p_filedescr['new_short_name'];
|
1523 |
+
}
|
1524 |
+
else {
|
1525 |
+
$v_stored_filename = $p_filename;
|
1526 |
+
}
|
1527 |
+
if ($p_remove_all_dir) {
|
1528 |
+
$v_stored_filename = basename($p_filename);
|
1529 |
+
}
|
1530 |
+
else if ($p_remove_dir != "") {
|
1531 |
+
if (substr($p_remove_dir, -1) != '/')
|
1532 |
+
$p_remove_dir .= "/";
|
1533 |
+
if ( (substr($p_filename, 0, 2) == "./")
|
1534 |
+
|| (substr($p_remove_dir, 0, 2) == "./")) {
|
1535 |
+
if ( (substr($p_filename, 0, 2) == "./")
|
1536 |
+
&& (substr($p_remove_dir, 0, 2) != "./")) {
|
1537 |
+
$p_remove_dir = "./".$p_remove_dir;
|
1538 |
+
}
|
1539 |
+
if ( (substr($p_filename, 0, 2) != "./")
|
1540 |
+
&& (substr($p_remove_dir, 0, 2) == "./")) {
|
1541 |
+
$p_remove_dir = substr($p_remove_dir, 2);
|
1542 |
+
}
|
1543 |
+
}
|
1544 |
+
$v_compare = PclZipUtilPathInclusion($p_remove_dir,
|
1545 |
+
$v_stored_filename);
|
1546 |
+
if ($v_compare > 0) {
|
1547 |
+
if ($v_compare == 2) {
|
1548 |
+
$v_stored_filename = "";
|
1549 |
+
}
|
1550 |
+
else {
|
1551 |
+
$v_stored_filename = substr($v_stored_filename,
|
1552 |
+
strlen($p_remove_dir));
|
1553 |
+
}
|
1554 |
+
}
|
1555 |
+
}
|
1556 |
+
$v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename);
|
1557 |
+
if ($p_add_dir != "") {
|
1558 |
+
if (substr($p_add_dir, -1) == "/")
|
1559 |
+
$v_stored_filename = $p_add_dir.$v_stored_filename;
|
1560 |
+
else
|
1561 |
+
$v_stored_filename = $p_add_dir."/".$v_stored_filename;
|
1562 |
+
}
|
1563 |
+
}
|
1564 |
+
$v_stored_filename = PclZipUtilPathReduction($v_stored_filename);
|
1565 |
+
$p_filedescr['stored_filename'] = $v_stored_filename;
|
1566 |
+
return $v_result;
|
1567 |
+
}
|
1568 |
+
function privWriteFileHeader(&$p_header)
|
1569 |
+
{
|
1570 |
+
$v_result=1;
|
1571 |
+
$p_header['offset'] = ftell($this->zip_fd);
|
1572 |
+
$v_date = getdate($p_header['mtime']);
|
1573 |
+
$v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
|
1574 |
+
$v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
|
1575 |
+
$v_binary_data = pack("VvvvvvVVVvv", 0x04034b50,
|
1576 |
+
$p_header['version_extracted'], $p_header['flag'],
|
1577 |
+
$p_header['compression'], $v_mtime, $v_mdate,
|
1578 |
+
$p_header['crc'], $p_header['compressed_size'],
|
1579 |
+
$p_header['size'],
|
1580 |
+
strlen($p_header['stored_filename']),
|
1581 |
+
$p_header['extra_len']);
|
1582 |
+
fputs($this->zip_fd, $v_binary_data, 30);
|
1583 |
+
if (strlen($p_header['stored_filename']) != 0)
|
1584 |
+
{
|
1585 |
+
fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
|
1586 |
+
}
|
1587 |
+
if ($p_header['extra_len'] != 0)
|
1588 |
+
{
|
1589 |
+
fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
|
1590 |
+
}
|
1591 |
+
return $v_result;
|
1592 |
+
}
|
1593 |
+
function privWriteCentralFileHeader(&$p_header)
|
1594 |
+
{
|
1595 |
+
$v_result=1;
|
1596 |
+
$v_date = getdate($p_header['mtime']);
|
1597 |
+
$v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
|
1598 |
+
$v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
|
1599 |
+
$v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50,
|
1600 |
+
$p_header['version'], $p_header['version_extracted'],
|
1601 |
+
$p_header['flag'], $p_header['compression'],
|
1602 |
+
$v_mtime, $v_mdate, $p_header['crc'],
|
1603 |
+
$p_header['compressed_size'], $p_header['size'],
|
1604 |
+
strlen($p_header['stored_filename']),
|
1605 |
+
$p_header['extra_len'], $p_header['comment_len'],
|
1606 |
+
$p_header['disk'], $p_header['internal'],
|
1607 |
+
$p_header['external'], $p_header['offset']);
|
1608 |
+
fputs($this->zip_fd, $v_binary_data, 46);
|
1609 |
+
if (strlen($p_header['stored_filename']) != 0)
|
1610 |
+
{
|
1611 |
+
fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
|
1612 |
+
}
|
1613 |
+
if ($p_header['extra_len'] != 0)
|
1614 |
+
{
|
1615 |
+
fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
|
1616 |
+
}
|
1617 |
+
if ($p_header['comment_len'] != 0)
|
1618 |
+
{
|
1619 |
+
fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']);
|
1620 |
+
}
|
1621 |
+
return $v_result;
|
1622 |
+
}
|
1623 |
+
function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment)
|
1624 |
+
{
|
1625 |
+
$v_result=1;
|
1626 |
+
$v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries,
|
1627 |
+
$p_nb_entries, $p_size,
|
1628 |
+
$p_offset, strlen($p_comment));
|
1629 |
+
fputs($this->zip_fd, $v_binary_data, 22);
|
1630 |
+
if (strlen($p_comment) != 0)
|
1631 |
+
{
|
1632 |
+
fputs($this->zip_fd, $p_comment, strlen($p_comment));
|
1633 |
+
}
|
1634 |
+
return $v_result;
|
1635 |
+
}
|
1636 |
+
function privList(&$p_list)
|
1637 |
+
{
|
1638 |
+
$v_result=1;
|
1639 |
+
$this->privDisableMagicQuotes();
|
1640 |
+
if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
|
1641 |
+
{
|
1642 |
+
$this->privSwapBackMagicQuotes();
|
1643 |
+
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
|
1644 |
+
return PclZip::errorCode();
|
1645 |
+
}
|
1646 |
+
$v_central_dir = array();
|
1647 |
+
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
|
1648 |
+
{
|
1649 |
+
$this->privSwapBackMagicQuotes();
|
1650 |
+
return $v_result;
|
1651 |
+
}
|
1652 |
+
@rewind($this->zip_fd);
|
1653 |
+
if (@fseek($this->zip_fd, $v_central_dir['offset']))
|
1654 |
+
{
|
1655 |
+
$this->privSwapBackMagicQuotes();
|
1656 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
|
1657 |
+
return PclZip::errorCode();
|
1658 |
+
}
|
1659 |
+
for ($i=0; $i<$v_central_dir['entries']; $i++)
|
1660 |
+
{
|
1661 |
+
if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
|
1662 |
+
{
|
1663 |
+
$this->privSwapBackMagicQuotes();
|
1664 |
+
return $v_result;
|
1665 |
+
}
|
1666 |
+
$v_header['index'] = $i;
|
1667 |
+
$this->privConvertHeader2FileInfo($v_header, $p_list[$i]);
|
1668 |
+
unset($v_header);
|
1669 |
+
}
|
1670 |
+
$this->privCloseFd();
|
1671 |
+
$this->privSwapBackMagicQuotes();
|
1672 |
+
return $v_result;
|
1673 |
+
}
|
1674 |
+
function privConvertHeader2FileInfo($p_header, &$p_info)
|
1675 |
+
{
|
1676 |
+
$v_result=1;
|
1677 |
+
$v_temp_path = PclZipUtilPathReduction($p_header['filename']);
|
1678 |
+
$p_info['filename'] = $v_temp_path;
|
1679 |
+
$v_temp_path = PclZipUtilPathReduction($p_header['stored_filename']);
|
1680 |
+
$p_info['stored_filename'] = $v_temp_path;
|
1681 |
+
$p_info['size'] = $p_header['size'];
|
1682 |
+
$p_info['compressed_size'] = $p_header['compressed_size'];
|
1683 |
+
$p_info['mtime'] = $p_header['mtime'];
|
1684 |
+
$p_info['comment'] = $p_header['comment'];
|
1685 |
+
$p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010);
|
1686 |
+
$p_info['index'] = $p_header['index'];
|
1687 |
+
$p_info['status'] = $p_header['status'];
|
1688 |
+
$p_info['crc'] = $p_header['crc'];
|
1689 |
+
return $v_result;
|
1690 |
+
}
|
1691 |
+
function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
|
1692 |
+
{
|
1693 |
+
$v_result=1;
|
1694 |
+
$this->privDisableMagicQuotes();
|
1695 |
+
if ( ($p_path == "")
|
1696 |
+
|| ( (substr($p_path, 0, 1) != "/")
|
1697 |
+
&& (substr($p_path, 0, 3) != "../")
|
1698 |
+
&& (substr($p_path,1,2)!=":/")))
|
1699 |
+
$p_path = "./".$p_path;
|
1700 |
+
if (($p_path != "./") && ($p_path != "/"))
|
1701 |
+
{
|
1702 |
+
while (substr($p_path, -1) == "/")
|
1703 |
+
{
|
1704 |
+
$p_path = substr($p_path, 0, strlen($p_path)-1);
|
1705 |
+
}
|
1706 |
+
}
|
1707 |
+
if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))
|
1708 |
+
{
|
1709 |
+
$p_remove_path .= '/';
|
1710 |
+
}
|
1711 |
+
$p_remove_path_size = strlen($p_remove_path);
|
1712 |
+
if (($v_result = $this->privOpenFd('rb')) != 1)
|
1713 |
+
{
|
1714 |
+
$this->privSwapBackMagicQuotes();
|
1715 |
+
return $v_result;
|
1716 |
+
}
|
1717 |
+
$v_central_dir = array();
|
1718 |
+
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
|
1719 |
+
{
|
1720 |
+
$this->privCloseFd();
|
1721 |
+
$this->privSwapBackMagicQuotes();
|
1722 |
+
return $v_result;
|
1723 |
+
}
|
1724 |
+
$v_pos_entry = $v_central_dir['offset'];
|
1725 |
+
$j_start = 0;
|
1726 |
+
for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
|
1727 |
+
{
|
1728 |
+
@rewind($this->zip_fd);
|
1729 |
+
if (@fseek($this->zip_fd, $v_pos_entry))
|
1730 |
+
{
|
1731 |
+
$this->privCloseFd();
|
1732 |
+
$this->privSwapBackMagicQuotes();
|
1733 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
|
1734 |
+
return PclZip::errorCode();
|
1735 |
+
}
|
1736 |
+
$v_header = array();
|
1737 |
+
if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
|
1738 |
+
{
|
1739 |
+
$this->privCloseFd();
|
1740 |
+
$this->privSwapBackMagicQuotes();
|
1741 |
+
return $v_result;
|
1742 |
+
}
|
1743 |
+
$v_header['index'] = $i;
|
1744 |
+
$v_pos_entry = ftell($this->zip_fd);
|
1745 |
+
$v_extract = false;
|
1746 |
+
if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
|
1747 |
+
&& ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
|
1748 |
+
for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) {
|
1749 |
+
if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
|
1750 |
+
if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
|
1751 |
+
&& (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
|
1752 |
+
$v_extract = true;
|
1753 |
+
}
|
1754 |
+
}
|
1755 |
+
elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
|
1756 |
+
$v_extract = true;
|
1757 |
+
}
|
1758 |
+
}
|
1759 |
+
}
|
1760 |
+
/*
|
1761 |
+
else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
|
1762 |
+
&& ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
|
1763 |
+
if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) {
|
1764 |
+
$v_extract = true;
|
1765 |
+
}
|
1766 |
+
}
|
1767 |
+
*/
|
1768 |
+
else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
|
1769 |
+
&& ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
|
1770 |
+
if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) {
|
1771 |
+
$v_extract = true;
|
1772 |
+
}
|
1773 |
+
}
|
1774 |
+
else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
|
1775 |
+
&& ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
|
1776 |
+
for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) {
|
1777 |
+
if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
|
1778 |
+
$v_extract = true;
|
1779 |
+
}
|
1780 |
+
if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
|
1781 |
+
$j_start = $j+1;
|
1782 |
+
}
|
1783 |
+
if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
|
1784 |
+
break;
|
1785 |
+
}
|
1786 |
+
}
|
1787 |
+
}
|
1788 |
+
else {
|
1789 |
+
$v_extract = true;
|
1790 |
+
}
|
1791 |
+
// ----- Check compression method
|
1792 |
+
if ( ($v_extract)
|
1793 |
+
&& ( ($v_header['compression'] != 8)
|
1794 |
+
&& ($v_header['compression'] != 0))) {
|
1795 |
+
$v_header['status'] = 'unsupported_compression';
|
1796 |
+
if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
|
1797 |
+
&& ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
|
1798 |
+
$this->privSwapBackMagicQuotes();
|
1799 |
+
PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION,
|
1800 |
+
"Filename '".$v_header['stored_filename']."' is "
|
1801 |
+
."compressed by an unsupported compression "
|
1802 |
+
."method (".$v_header['compression'].") ");
|
1803 |
+
return PclZip::errorCode();
|
1804 |
+
}
|
1805 |
+
}
|
1806 |
+
// ----- Check encrypted files
|
1807 |
+
if (($v_extract) && (($v_header['flag'] & 1) == 1)) {
|
1808 |
+
$v_header['status'] = 'unsupported_encryption';
|
1809 |
+
if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
|
1810 |
+
&& ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
|
1811 |
+
$this->privSwapBackMagicQuotes();
|
1812 |
+
PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION,
|
1813 |
+
"Unsupported encryption for "
|
1814 |
+
." filename '".$v_header['stored_filename']
|
1815 |
+
."'");
|
1816 |
+
return PclZip::errorCode();
|
1817 |
+
}
|
1818 |
+
}
|
1819 |
+
if (($v_extract) && ($v_header['status'] != 'ok')) {
|
1820 |
+
$v_result = $this->privConvertHeader2FileInfo($v_header,
|
1821 |
+
$p_file_list[$v_nb_extracted++]);
|
1822 |
+
if ($v_result != 1) {
|
1823 |
+
$this->privCloseFd();
|
1824 |
+
$this->privSwapBackMagicQuotes();
|
1825 |
+
return $v_result;
|
1826 |
+
}
|
1827 |
+
$v_extract = false;
|
1828 |
+
}
|
1829 |
+
if ($v_extract)
|
1830 |
+
{
|
1831 |
+
@rewind($this->zip_fd);
|
1832 |
+
if (@fseek($this->zip_fd, $v_header['offset']))
|
1833 |
+
{
|
1834 |
+
$this->privCloseFd();
|
1835 |
+
$this->privSwapBackMagicQuotes();
|
1836 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
|
1837 |
+
return PclZip::errorCode();
|
1838 |
+
}
|
1839 |
+
if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) {
|
1840 |
+
$v_string = '';
|
1841 |
+
$v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options);
|
1842 |
+
if ($v_result1 < 1) {
|
1843 |
+
$this->privCloseFd();
|
1844 |
+
$this->privSwapBackMagicQuotes();
|
1845 |
+
return $v_result1;
|
1846 |
+
}
|
1847 |
+
if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1)
|
1848 |
+
{
|
1849 |
+
$this->privCloseFd();
|
1850 |
+
$this->privSwapBackMagicQuotes();
|
1851 |
+
return $v_result;
|
1852 |
+
}
|
1853 |
+
$p_file_list[$v_nb_extracted]['content'] = $v_string;
|
1854 |
+
$v_nb_extracted++;
|
1855 |
+
if ($v_result1 == 2) {
|
1856 |
+
break;
|
1857 |
+
}
|
1858 |
+
}
|
1859 |
+
elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT]))
|
1860 |
+
&& ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {
|
1861 |
+
$v_result1 = $this->privExtractFileInOutput($v_header, $p_options);
|
1862 |
+
if ($v_result1 < 1) {
|
1863 |
+
$this->privCloseFd();
|
1864 |
+
$this->privSwapBackMagicQuotes();
|
1865 |
+
return $v_result1;
|
1866 |
+
}
|
1867 |
+
if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {
|
1868 |
+
$this->privCloseFd();
|
1869 |
+
$this->privSwapBackMagicQuotes();
|
1870 |
+
return $v_result;
|
1871 |
+
}
|
1872 |
+
if ($v_result1 == 2) {
|
1873 |
+
break;
|
1874 |
+
}
|
1875 |
+
}
|
1876 |
+
else {
|
1877 |
+
$v_result1 = $this->privExtractFile($v_header,
|
1878 |
+
$p_path, $p_remove_path,
|
1879 |
+
$p_remove_all_path,
|
1880 |
+
$p_options);
|
1881 |
+
if ($v_result1 < 1) {
|
1882 |
+
$this->privCloseFd();
|
1883 |
+
$this->privSwapBackMagicQuotes();
|
1884 |
+
return $v_result1;
|
1885 |
+
}
|
1886 |
+
if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1)
|
1887 |
+
{
|
1888 |
+
$this->privCloseFd();
|
1889 |
+
$this->privSwapBackMagicQuotes();
|
1890 |
+
return $v_result;
|
1891 |
+
}
|
1892 |
+
if ($v_result1 == 2) {
|
1893 |
+
break;
|
1894 |
+
}
|
1895 |
+
}
|
1896 |
+
}
|
1897 |
+
}
|
1898 |
+
$this->privCloseFd();
|
1899 |
+
$this->privSwapBackMagicQuotes();
|
1900 |
+
return $v_result;
|
1901 |
+
}
|
1902 |
+
function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
|
1903 |
+
{
|
1904 |
+
$v_result=1;
|
1905 |
+
if (($v_result = $this->privReadFileHeader($v_header)) != 1)
|
1906 |
+
{
|
1907 |
+
return $v_result;
|
1908 |
+
}
|
1909 |
+
if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
|
1910 |
+
}
|
1911 |
+
if ($p_remove_all_path == true) {
|
1912 |
+
if (($p_entry['external']&0x00000010)==0x00000010) {
|
1913 |
+
$p_entry['status'] = "filtered";
|
1914 |
+
return $v_result;
|
1915 |
+
}
|
1916 |
+
$p_entry['filename'] = basename($p_entry['filename']);
|
1917 |
+
}
|
1918 |
+
else if ($p_remove_path != "")
|
1919 |
+
{
|
1920 |
+
if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2)
|
1921 |
+
{
|
1922 |
+
$p_entry['status'] = "filtered";
|
1923 |
+
return $v_result;
|
1924 |
+
}
|
1925 |
+
$p_remove_path_size = strlen($p_remove_path);
|
1926 |
+
if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path)
|
1927 |
+
{
|
1928 |
+
$p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
|
1929 |
+
}
|
1930 |
+
}
|
1931 |
+
if ($p_path != '') {
|
1932 |
+
$p_entry['filename'] = $p_path."/".$p_entry['filename'];
|
1933 |
+
}
|
1934 |
+
if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {
|
1935 |
+
$v_inclusion
|
1936 |
+
= PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION],
|
1937 |
+
$p_entry['filename']);
|
1938 |
+
if ($v_inclusion == 0) {
|
1939 |
+
PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION,
|
1940 |
+
"Filename '".$p_entry['filename']."' is "
|
1941 |
+
."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION");
|
1942 |
+
return PclZip::errorCode();
|
1943 |
+
}
|
1944 |
+
}
|
1945 |
+
if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
|
1946 |
+
$v_local_header = array();
|
1947 |
+
$this->privConvertHeader2FileInfo($p_entry, $v_local_header);
|
1948 |
+
// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
|
1949 |
+
$v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
|
1950 |
+
if ($v_result == 0) {
|
1951 |
+
$p_entry['status'] = "skipped";
|
1952 |
+
$v_result = 1;
|
1953 |
+
}
|
1954 |
+
if ($v_result == 2) {
|
1955 |
+
$p_entry['status'] = "aborted";
|
1956 |
+
$v_result = PCLZIP_ERR_USER_ABORTED;
|
1957 |
+
}
|
1958 |
+
$p_entry['filename'] = $v_local_header['filename'];
|
1959 |
+
}
|
1960 |
+
if ($p_entry['status'] == 'ok') {
|
1961 |
+
if (file_exists($p_entry['filename']))
|
1962 |
+
{
|
1963 |
+
if (is_dir($p_entry['filename']))
|
1964 |
+
{
|
1965 |
+
$p_entry['status'] = "already_a_directory";
|
1966 |
+
if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
|
1967 |
+
&& ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
|
1968 |
+
PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY,
|
1969 |
+
"Filename '".$p_entry['filename']."' is "
|
1970 |
+
."already used by an existing directory");
|
1971 |
+
return PclZip::errorCode();
|
1972 |
+
}
|
1973 |
+
}
|
1974 |
+
else if (!is_writeable($p_entry['filename']))
|
1975 |
+
{
|
1976 |
+
$p_entry['status'] = "write_protected";
|
1977 |
+
if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
|
1978 |
+
&& ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
|
1979 |
+
PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
|
1980 |
+
"Filename '".$p_entry['filename']."' exists "
|
1981 |
+
."and is write protected");
|
1982 |
+
return PclZip::errorCode();
|
1983 |
+
}
|
1984 |
+
}
|
1985 |
+
else if (filemtime($p_entry['filename']) > $p_entry['mtime'])
|
1986 |
+
{
|
1987 |
+
if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER]))
|
1988 |
+
&& ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) {
|
1989 |
+
}
|
1990 |
+
else {
|
1991 |
+
$p_entry['status'] = "newer_exist";
|
1992 |
+
if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
|
1993 |
+
&& ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
|
1994 |
+
PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
|
1995 |
+
"Newer version of '".$p_entry['filename']."' exists "
|
1996 |
+
."and option PCLZIP_OPT_REPLACE_NEWER is not selected");
|
1997 |
+
return PclZip::errorCode();
|
1998 |
+
}
|
1999 |
+
}
|
2000 |
+
}
|
2001 |
+
else {
|
2002 |
+
}
|
2003 |
+
}
|
2004 |
+
else {
|
2005 |
+
if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/'))
|
2006 |
+
$v_dir_to_check = $p_entry['filename'];
|
2007 |
+
else if (!strstr($p_entry['filename'], "/"))
|
2008 |
+
$v_dir_to_check = "";
|
2009 |
+
else
|
2010 |
+
$v_dir_to_check = dirname($p_entry['filename']);
|
2011 |
+
if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) {
|
2012 |
+
$p_entry['status'] = "path_creation_fail";
|
2013 |
+
$v_result = 1;
|
2014 |
+
}
|
2015 |
+
}
|
2016 |
+
}
|
2017 |
+
if ($p_entry['status'] == 'ok') {
|
2018 |
+
if (!(($p_entry['external']&0x00000010)==0x00000010))
|
2019 |
+
{
|
2020 |
+
if ($p_entry['compression'] == 0) {
|
2021 |
+
// ----- Opening destination file
|
2022 |
+
if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0)
|
2023 |
+
{
|
2024 |
+
$p_entry['status'] = "write_error";
|
2025 |
+
return $v_result;
|
2026 |
+
}
|
2027 |
+
$v_size = $p_entry['compressed_size'];
|
2028 |
+
while ($v_size != 0)
|
2029 |
+
{
|
2030 |
+
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
2031 |
+
$v_buffer = @fread($this->zip_fd, $v_read_size);
|
2032 |
+
/* Try to speed up the code
|
2033 |
+
$v_binary_data = pack('a'.$v_read_size, $v_buffer);
|
2034 |
+
@fwrite($v_dest_file, $v_binary_data, $v_read_size);
|
2035 |
+
*/
|
2036 |
+
@fwrite($v_dest_file, $v_buffer, $v_read_size);
|
2037 |
+
$v_size -= $v_read_size;
|
2038 |
+
}
|
2039 |
+
fclose($v_dest_file);
|
2040 |
+
touch($p_entry['filename'], $p_entry['mtime']);
|
2041 |
+
}
|
2042 |
+
else {
|
2043 |
+
if (($p_entry['flag'] & 1) == 1) {
|
2044 |
+
PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.');
|
2045 |
+
return PclZip::errorCode();
|
2046 |
+
}
|
2047 |
+
if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
|
2048 |
+
&& (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
|
2049 |
+
|| (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
|
2050 |
+
&& ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) {
|
2051 |
+
$v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options);
|
2052 |
+
if ($v_result < PCLZIP_ERR_NO_ERROR) {
|
2053 |
+
return $v_result;
|
2054 |
+
}
|
2055 |
+
}
|
2056 |
+
else {
|
2057 |
+
$v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
|
2058 |
+
$v_file_content = @gzinflate($v_buffer);
|
2059 |
+
unset($v_buffer);
|
2060 |
+
if ($v_file_content === FALSE) {
|
2061 |
+
$p_entry['status'] = "error";
|
2062 |
+
return $v_result;
|
2063 |
+
}
|
2064 |
+
if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
|
2065 |
+
$p_entry['status'] = "write_error";
|
2066 |
+
return $v_result;
|
2067 |
+
}
|
2068 |
+
@fwrite($v_dest_file, $v_file_content, $p_entry['size']);
|
2069 |
+
unset($v_file_content);
|
2070 |
+
@fclose($v_dest_file);
|
2071 |
+
}
|
2072 |
+
@touch($p_entry['filename'], $p_entry['mtime']);
|
2073 |
+
}
|
2074 |
+
if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) {
|
2075 |
+
@chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]);
|
2076 |
+
}
|
2077 |
+
}
|
2078 |
+
}
|
2079 |
+
// ----- Change abort status
|
2080 |
+
if ($p_entry['status'] == "aborted") {
|
2081 |
+
$p_entry['status'] = "skipped";
|
2082 |
+
}
|
2083 |
+
elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
|
2084 |
+
$v_local_header = array();
|
2085 |
+
$this->privConvertHeader2FileInfo($p_entry, $v_local_header);
|
2086 |
+
// eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
|
2087 |
+
$v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
|
2088 |
+
if ($v_result == 2) {
|
2089 |
+
$v_result = PCLZIP_ERR_USER_ABORTED;
|
2090 |
+
}
|
2091 |
+
}
|
2092 |
+
return $v_result;
|
2093 |
+
}
|
2094 |
+
function privExtractFileUsingTempFile(&$p_entry, &$p_options)
|
2095 |
+
{
|
2096 |
+
$v_result=1;
|
2097 |
+
$v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
|
2098 |
+
if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) {
|
2099 |
+
fclose($v_file);
|
2100 |
+
PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
|
2101 |
+
return PclZip::errorCode();
|
2102 |
+
}
|
2103 |
+
$v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3));
|
2104 |
+
@fwrite($v_dest_file, $v_binary_data, 10);
|
2105 |
+
$v_size = $p_entry['compressed_size'];
|
2106 |
+
while ($v_size != 0)
|
2107 |
+
{
|
2108 |
+
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
2109 |
+
$v_buffer = @fread($this->zip_fd, $v_read_size);
|
2110 |
+
@fwrite($v_dest_file, $v_buffer, $v_read_size);
|
2111 |
+
$v_size -= $v_read_size;
|
2112 |
+
}
|
2113 |
+
$v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']);
|
2114 |
+
@fwrite($v_dest_file, $v_binary_data, 8);
|
2115 |
+
@fclose($v_dest_file);
|
2116 |
+
if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
|
2117 |
+
$p_entry['status'] = "write_error";
|
2118 |
+
return $v_result;
|
2119 |
+
}
|
2120 |
+
if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) {
|
2121 |
+
@fclose($v_dest_file);
|
2122 |
+
$p_entry['status'] = "read_error";
|
2123 |
+
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
|
2124 |
+
return PclZip::errorCode();
|
2125 |
+
}
|
2126 |
+
$v_size = $p_entry['size'];
|
2127 |
+
while ($v_size != 0) {
|
2128 |
+
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
2129 |
+
$v_buffer = @gzread($v_src_file, $v_read_size);
|
2130 |
+
@fwrite($v_dest_file, $v_buffer, $v_read_size);
|
2131 |
+
$v_size -= $v_read_size;
|
2132 |
+
}
|
2133 |
+
@fclose($v_dest_file);
|
2134 |
+
@gzclose($v_src_file);
|
2135 |
+
@unlink($v_gzip_temp_name);
|
2136 |
+
return $v_result;
|
2137 |
+
}
|
2138 |
+
function privExtractFileInOutput(&$p_entry, &$p_options)
|
2139 |
+
{
|
2140 |
+
$v_result=1;
|
2141 |
+
if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
|
2142 |
+
return $v_result;
|
2143 |
+
}
|
2144 |
+
if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
|
2145 |
+
}
|
2146 |
+
if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
|
2147 |
+
$v_local_header = array();
|
2148 |
+
$this->privConvertHeader2FileInfo($p_entry, $v_local_header);
|
2149 |
+
// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
|
2150 |
+
$v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
|
2151 |
+
if ($v_result == 0) {
|
2152 |
+
$p_entry['status'] = "skipped";
|
2153 |
+
$v_result = 1;
|
2154 |
+
}
|
2155 |
+
if ($v_result == 2) {
|
2156 |
+
$p_entry['status'] = "aborted";
|
2157 |
+
$v_result = PCLZIP_ERR_USER_ABORTED;
|
2158 |
+
}
|
2159 |
+
$p_entry['filename'] = $v_local_header['filename'];
|
2160 |
+
}
|
2161 |
+
if ($p_entry['status'] == 'ok') {
|
2162 |
+
if (!(($p_entry['external']&0x00000010)==0x00000010)) {
|
2163 |
+
if ($p_entry['compressed_size'] == $p_entry['size']) {
|
2164 |
+
$v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
|
2165 |
+
echo $v_buffer;
|
2166 |
+
unset($v_buffer);
|
2167 |
+
}
|
2168 |
+
else {
|
2169 |
+
$v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
|
2170 |
+
$v_file_content = gzinflate($v_buffer);
|
2171 |
+
unset($v_buffer);
|
2172 |
+
echo $v_file_content;
|
2173 |
+
unset($v_file_content);
|
2174 |
+
}
|
2175 |
+
}
|
2176 |
+
}
|
2177 |
+
// ----- Change abort status
|
2178 |
+
if ($p_entry['status'] == "aborted") {
|
2179 |
+
$p_entry['status'] = "skipped";
|
2180 |
+
}
|
2181 |
+
elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
|
2182 |
+
$v_local_header = array();
|
2183 |
+
$this->privConvertHeader2FileInfo($p_entry, $v_local_header);
|
2184 |
+
// eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
|
2185 |
+
$v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
|
2186 |
+
if ($v_result == 2) {
|
2187 |
+
$v_result = PCLZIP_ERR_USER_ABORTED;
|
2188 |
+
}
|
2189 |
+
}
|
2190 |
+
return $v_result;
|
2191 |
+
}
|
2192 |
+
function privExtractFileAsString(&$p_entry, &$p_string, &$p_options)
|
2193 |
+
{
|
2194 |
+
$v_result=1;
|
2195 |
+
$v_header = array();
|
2196 |
+
if (($v_result = $this->privReadFileHeader($v_header)) != 1)
|
2197 |
+
{
|
2198 |
+
return $v_result;
|
2199 |
+
}
|
2200 |
+
if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
|
2201 |
+
}
|
2202 |
+
if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
|
2203 |
+
$v_local_header = array();
|
2204 |
+
$this->privConvertHeader2FileInfo($p_entry, $v_local_header);
|
2205 |
+
// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
|
2206 |
+
$v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
|
2207 |
+
if ($v_result == 0) {
|
2208 |
+
$p_entry['status'] = "skipped";
|
2209 |
+
$v_result = 1;
|
2210 |
+
}
|
2211 |
+
if ($v_result == 2) {
|
2212 |
+
$p_entry['status'] = "aborted";
|
2213 |
+
$v_result = PCLZIP_ERR_USER_ABORTED;
|
2214 |
+
}
|
2215 |
+
$p_entry['filename'] = $v_local_header['filename'];
|
2216 |
+
}
|
2217 |
+
if ($p_entry['status'] == 'ok') {
|
2218 |
+
if (!(($p_entry['external']&0x00000010)==0x00000010)) {
|
2219 |
+
if ($p_entry['compression'] == 0) {
|
2220 |
+
$p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
|
2221 |
+
}
|
2222 |
+
else {
|
2223 |
+
$v_data = @fread($this->zip_fd, $p_entry['compressed_size']);
|
2224 |
+
if (($p_string = @gzinflate($v_data)) === FALSE) {
|
2225 |
+
}
|
2226 |
+
}
|
2227 |
+
}
|
2228 |
+
else {
|
2229 |
+
}
|
2230 |
+
}
|
2231 |
+
// ----- Change abort status
|
2232 |
+
if ($p_entry['status'] == "aborted") {
|
2233 |
+
$p_entry['status'] = "skipped";
|
2234 |
+
}
|
2235 |
+
elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
|
2236 |
+
$v_local_header = array();
|
2237 |
+
$this->privConvertHeader2FileInfo($p_entry, $v_local_header);
|
2238 |
+
$v_local_header['content'] = $p_string;
|
2239 |
+
$p_string = '';
|
2240 |
+
// eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
|
2241 |
+
$v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
|
2242 |
+
$p_string = $v_local_header['content'];
|
2243 |
+
unset($v_local_header['content']);
|
2244 |
+
if ($v_result == 2) {
|
2245 |
+
$v_result = PCLZIP_ERR_USER_ABORTED;
|
2246 |
+
}
|
2247 |
+
}
|
2248 |
+
return $v_result;
|
2249 |
+
}
|
2250 |
+
function privReadFileHeader(&$p_header)
|
2251 |
+
{
|
2252 |
+
$v_result=1;
|
2253 |
+
$v_binary_data = @fread($this->zip_fd, 4);
|
2254 |
+
$v_data = unpack('Vid', $v_binary_data);
|
2255 |
+
if ($v_data['id'] != 0x04034b50)
|
2256 |
+
{
|
2257 |
+
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
|
2258 |
+
return PclZip::errorCode();
|
2259 |
+
}
|
2260 |
+
$v_binary_data = fread($this->zip_fd, 26);
|
2261 |
+
if (strlen($v_binary_data) != 26)
|
2262 |
+
{
|
2263 |
+
$p_header['filename'] = "";
|
2264 |
+
$p_header['status'] = "invalid_header";
|
2265 |
+
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
|
2266 |
+
return PclZip::errorCode();
|
2267 |
+
}
|
2268 |
+
$v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data);
|
2269 |
+
$p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']);
|
2270 |
+
if ($v_data['extra_len'] != 0) {
|
2271 |
+
$p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']);
|
2272 |
+
}
|
2273 |
+
else {
|
2274 |
+
$p_header['extra'] = '';
|
2275 |
+
}
|
2276 |
+
$p_header['version_extracted'] = $v_data['version'];
|
2277 |
+
$p_header['compression'] = $v_data['compression'];
|
2278 |
+
$p_header['size'] = $v_data['size'];
|
2279 |
+
$p_header['compressed_size'] = $v_data['compressed_size'];
|
2280 |
+
$p_header['crc'] = $v_data['crc'];
|
2281 |
+
$p_header['flag'] = $v_data['flag'];
|
2282 |
+
$p_header['filename_len'] = $v_data['filename_len'];
|
2283 |
+
$p_header['mdate'] = $v_data['mdate'];
|
2284 |
+
$p_header['mtime'] = $v_data['mtime'];
|
2285 |
+
if ($p_header['mdate'] && $p_header['mtime'])
|
2286 |
+
{
|
2287 |
+
$v_hour = ($p_header['mtime'] & 0xF800) >> 11;
|
2288 |
+
$v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
|
2289 |
+
$v_seconde = ($p_header['mtime'] & 0x001F)*2;
|
2290 |
+
$v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
|
2291 |
+
$v_month = ($p_header['mdate'] & 0x01E0) >> 5;
|
2292 |
+
$v_day = $p_header['mdate'] & 0x001F;
|
2293 |
+
$p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
|
2294 |
+
}
|
2295 |
+
else
|
2296 |
+
{
|
2297 |
+
$p_header['mtime'] = time();
|
2298 |
+
}
|
2299 |
+
$p_header['stored_filename'] = $p_header['filename'];
|
2300 |
+
$p_header['status'] = "ok";
|
2301 |
+
return $v_result;
|
2302 |
+
}
|
2303 |
+
function privReadCentralFileHeader(&$p_header)
|
2304 |
+
{
|
2305 |
+
$v_result=1;
|
2306 |
+
$v_binary_data = @fread($this->zip_fd, 4);
|
2307 |
+
$v_data = unpack('Vid', $v_binary_data);
|
2308 |
+
if ($v_data['id'] != 0x02014b50)
|
2309 |
+
{
|
2310 |
+
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
|
2311 |
+
return PclZip::errorCode();
|
2312 |
+
}
|
2313 |
+
$v_binary_data = fread($this->zip_fd, 42);
|
2314 |
+
if (strlen($v_binary_data) != 42)
|
2315 |
+
{
|
2316 |
+
$p_header['filename'] = "";
|
2317 |
+
$p_header['status'] = "invalid_header";
|
2318 |
+
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
|
2319 |
+
return PclZip::errorCode();
|
2320 |
+
}
|
2321 |
+
$p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data);
|
2322 |
+
if ($p_header['filename_len'] != 0)
|
2323 |
+
$p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']);
|
2324 |
+
else
|
2325 |
+
$p_header['filename'] = '';
|
2326 |
+
if ($p_header['extra_len'] != 0)
|
2327 |
+
$p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']);
|
2328 |
+
else
|
2329 |
+
$p_header['extra'] = '';
|
2330 |
+
if ($p_header['comment_len'] != 0)
|
2331 |
+
$p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']);
|
2332 |
+
else
|
2333 |
+
$p_header['comment'] = '';
|
2334 |
+
if (1)
|
2335 |
+
{
|
2336 |
+
$v_hour = ($p_header['mtime'] & 0xF800) >> 11;
|
2337 |
+
$v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
|
2338 |
+
$v_seconde = ($p_header['mtime'] & 0x001F)*2;
|
2339 |
+
$v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
|
2340 |
+
$v_month = ($p_header['mdate'] & 0x01E0) >> 5;
|
2341 |
+
$v_day = $p_header['mdate'] & 0x001F;
|
2342 |
+
$p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
|
2343 |
+
}
|
2344 |
+
else
|
2345 |
+
{
|
2346 |
+
$p_header['mtime'] = time();
|
2347 |
+
}
|
2348 |
+
$p_header['stored_filename'] = $p_header['filename'];
|
2349 |
+
$p_header['status'] = 'ok';
|
2350 |
+
if (substr($p_header['filename'], -1) == '/') {
|
2351 |
+
$p_header['external'] = 0x00000010;
|
2352 |
+
}
|
2353 |
+
return $v_result;
|
2354 |
+
}
|
2355 |
+
function privCheckFileHeaders(&$p_local_header, &$p_central_header)
|
2356 |
+
{
|
2357 |
+
$v_result=1;
|
2358 |
+
// ----- Check the static values
|
2359 |
+
// TBC
|
2360 |
+
if ($p_local_header['filename'] != $p_central_header['filename']) {
|
2361 |
+
}
|
2362 |
+
if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) {
|
2363 |
+
}
|
2364 |
+
if ($p_local_header['flag'] != $p_central_header['flag']) {
|
2365 |
+
}
|
2366 |
+
if ($p_local_header['compression'] != $p_central_header['compression']) {
|
2367 |
+
}
|
2368 |
+
if ($p_local_header['mtime'] != $p_central_header['mtime']) {
|
2369 |
+
}
|
2370 |
+
if ($p_local_header['filename_len'] != $p_central_header['filename_len']) {
|
2371 |
+
}
|
2372 |
+
// ----- Look for flag bit 3
|
2373 |
+
if (($p_local_header['flag'] & 8) == 8) {
|
2374 |
+
$p_local_header['size'] = $p_central_header['size'];
|
2375 |
+
$p_local_header['compressed_size'] = $p_central_header['compressed_size'];
|
2376 |
+
$p_local_header['crc'] = $p_central_header['crc'];
|
2377 |
+
}
|
2378 |
+
return $v_result;
|
2379 |
+
}
|
2380 |
+
function privReadEndCentralDir(&$p_central_dir)
|
2381 |
+
{
|
2382 |
+
$v_result=1;
|
2383 |
+
$v_size = filesize($this->zipname);
|
2384 |
+
@fseek($this->zip_fd, $v_size);
|
2385 |
+
if (@ftell($this->zip_fd) != $v_size)
|
2386 |
+
{
|
2387 |
+
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\'');
|
2388 |
+
return PclZip::errorCode();
|
2389 |
+
}
|
2390 |
+
$v_found = 0;
|
2391 |
+
if ($v_size > 26) {
|
2392 |
+
@fseek($this->zip_fd, $v_size-22);
|
2393 |
+
if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22))
|
2394 |
+
{
|
2395 |
+
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
|
2396 |
+
return PclZip::errorCode();
|
2397 |
+
}
|
2398 |
+
$v_binary_data = @fread($this->zip_fd, 4);
|
2399 |
+
$v_data = @unpack('Vid', $v_binary_data);
|
2400 |
+
if ($v_data['id'] == 0x06054b50) {
|
2401 |
+
$v_found = 1;
|
2402 |
+
}
|
2403 |
+
$v_pos = ftell($this->zip_fd);
|
2404 |
+
}
|
2405 |
+
if (!$v_found) {
|
2406 |
+
$v_maximum_size = 65557; // 0xFFFF + 22;
|
2407 |
+
if ($v_maximum_size > $v_size)
|
2408 |
+
$v_maximum_size = $v_size;
|
2409 |
+
@fseek($this->zip_fd, $v_size-$v_maximum_size);
|
2410 |
+
if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size))
|
2411 |
+
{
|
2412 |
+
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
|
2413 |
+
return PclZip::errorCode();
|
2414 |
+
}
|
2415 |
+
$v_pos = ftell($this->zip_fd);
|
2416 |
+
$v_bytes = 0x00000000;
|
2417 |
+
while ($v_pos < $v_size)
|
2418 |
+
{
|
2419 |
+
$v_byte = @fread($this->zip_fd, 1);
|
2420 |
+
$v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte);
|
2421 |
+
if ($v_bytes == 0x504b0506)
|
2422 |
+
{
|
2423 |
+
$v_pos++;
|
2424 |
+
break;
|
2425 |
+
}
|
2426 |
+
$v_pos++;
|
2427 |
+
}
|
2428 |
+
if ($v_pos == $v_size)
|
2429 |
+
{
|
2430 |
+
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature");
|
2431 |
+
return PclZip::errorCode();
|
2432 |
+
}
|
2433 |
+
}
|
2434 |
+
$v_binary_data = fread($this->zip_fd, 18);
|
2435 |
+
if (strlen($v_binary_data) != 18)
|
2436 |
+
{
|
2437 |
+
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));
|
2438 |
+
return PclZip::errorCode();
|
2439 |
+
}
|
2440 |
+
$v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data);
|
2441 |
+
if (($v_pos + $v_data['comment_size'] + 18) != $v_size) {
|
2442 |
+
// ----- Removed in release 2.2 see readme file
|
2443 |
+
// The check of the file size is a little too strict.
|
2444 |
+
// Some bugs where found when a zip is encrypted/decrypted with 'crypt'.
|
2445 |
+
// While decrypted, zip has training 0 bytes
|
2446 |
+
if (0) {
|
2447 |
+
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT,
|
2448 |
+
'The central dir is not at the end of the archive.'
|
2449 |
+
.' Some trailing bytes exists after the archive.');
|
2450 |
+
return PclZip::errorCode();
|
2451 |
+
}
|
2452 |
+
}
|
2453 |
+
if ($v_data['comment_size'] != 0) {
|
2454 |
+
$p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']);
|
2455 |
+
}
|
2456 |
+
else
|
2457 |
+
$p_central_dir['comment'] = '';
|
2458 |
+
$p_central_dir['entries'] = $v_data['entries'];
|
2459 |
+
$p_central_dir['disk_entries'] = $v_data['disk_entries'];
|
2460 |
+
$p_central_dir['offset'] = $v_data['offset'];
|
2461 |
+
$p_central_dir['size'] = $v_data['size'];
|
2462 |
+
$p_central_dir['disk'] = $v_data['disk'];
|
2463 |
+
$p_central_dir['disk_start'] = $v_data['disk_start'];
|
2464 |
+
return $v_result;
|
2465 |
+
}
|
2466 |
+
function privDeleteByRule(&$p_result_list, &$p_options)
|
2467 |
+
{
|
2468 |
+
$v_result=1;
|
2469 |
+
$v_list_detail = array();
|
2470 |
+
if (($v_result=$this->privOpenFd('rb')) != 1)
|
2471 |
+
{
|
2472 |
+
return $v_result;
|
2473 |
+
}
|
2474 |
+
$v_central_dir = array();
|
2475 |
+
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
|
2476 |
+
{
|
2477 |
+
$this->privCloseFd();
|
2478 |
+
return $v_result;
|
2479 |
+
}
|
2480 |
+
@rewind($this->zip_fd);
|
2481 |
+
$v_pos_entry = $v_central_dir['offset'];
|
2482 |
+
@rewind($this->zip_fd);
|
2483 |
+
if (@fseek($this->zip_fd, $v_pos_entry))
|
2484 |
+
{
|
2485 |
+
$this->privCloseFd();
|
2486 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
|
2487 |
+
return PclZip::errorCode();
|
2488 |
+
}
|
2489 |
+
$v_header_list = array();
|
2490 |
+
$j_start = 0;
|
2491 |
+
for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
|
2492 |
+
{
|
2493 |
+
$v_header_list[$v_nb_extracted] = array();
|
2494 |
+
if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1)
|
2495 |
+
{
|
2496 |
+
$this->privCloseFd();
|
2497 |
+
return $v_result;
|
2498 |
+
}
|
2499 |
+
$v_header_list[$v_nb_extracted]['index'] = $i;
|
2500 |
+
$v_found = false;
|
2501 |
+
if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
|
2502 |
+
&& ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
|
2503 |
+
for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) {
|
2504 |
+
if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
|
2505 |
+
if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
|
2506 |
+
&& (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
|
2507 |
+
$v_found = true;
|
2508 |
+
}
|
2509 |
+
elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */
|
2510 |
+
&& ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
|
2511 |
+
$v_found = true;
|
2512 |
+
}
|
2513 |
+
}
|
2514 |
+
elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
|
2515 |
+
$v_found = true;
|
2516 |
+
}
|
2517 |
+
}
|
2518 |
+
}
|
2519 |
+
/*
|
2520 |
+
else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
|
2521 |
+
&& ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
|
2522 |
+
if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
|
2523 |
+
$v_found = true;
|
2524 |
+
}
|
2525 |
+
}
|
2526 |
+
*/
|
2527 |
+
else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
|
2528 |
+
&& ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
|
2529 |
+
if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
|
2530 |
+
$v_found = true;
|
2531 |
+
}
|
2532 |
+
}
|
2533 |
+
else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
|
2534 |
+
&& ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
|
2535 |
+
for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) {
|
2536 |
+
if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
|
2537 |
+
$v_found = true;
|
2538 |
+
}
|
2539 |
+
if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
|
2540 |
+
$j_start = $j+1;
|
2541 |
+
}
|
2542 |
+
if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
|
2543 |
+
break;
|
2544 |
+
}
|
2545 |
+
}
|
2546 |
+
}
|
2547 |
+
else {
|
2548 |
+
$v_found = true;
|
2549 |
+
}
|
2550 |
+
if ($v_found)
|
2551 |
+
{
|
2552 |
+
unset($v_header_list[$v_nb_extracted]);
|
2553 |
+
}
|
2554 |
+
else
|
2555 |
+
{
|
2556 |
+
$v_nb_extracted++;
|
2557 |
+
}
|
2558 |
+
}
|
2559 |
+
if ($v_nb_extracted > 0) {
|
2560 |
+
$v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
|
2561 |
+
$v_temp_zip = new PclZip($v_zip_temp_name);
|
2562 |
+
if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) {
|
2563 |
+
$this->privCloseFd();
|
2564 |
+
return $v_result;
|
2565 |
+
}
|
2566 |
+
for ($i=0; $i<sizeof($v_header_list); $i++) {
|
2567 |
+
@rewind($this->zip_fd);
|
2568 |
+
if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) {
|
2569 |
+
$this->privCloseFd();
|
2570 |
+
$v_temp_zip->privCloseFd();
|
2571 |
+
@unlink($v_zip_temp_name);
|
2572 |
+
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
|
2573 |
+
return PclZip::errorCode();
|
2574 |
+
}
|
2575 |
+
$v_local_header = array();
|
2576 |
+
if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) {
|
2577 |
+
$this->privCloseFd();
|
2578 |
+
$v_temp_zip->privCloseFd();
|
2579 |
+
@unlink($v_zip_temp_name);
|
2580 |
+
return $v_result;
|
2581 |
+
}
|
2582 |
+
if ($this->privCheckFileHeaders($v_local_header,
|
2583 |
+
$v_header_list[$i]) != 1) {
|
2584 |
+
}
|
2585 |
+
unset($v_local_header);
|
2586 |
+
if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) {
|
2587 |
+
$this->privCloseFd();
|
2588 |
+
$v_temp_zip->privCloseFd();
|
2589 |
+
@unlink($v_zip_temp_name);
|
2590 |
+
return $v_result;
|
2591 |
+
}
|
2592 |
+
if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) {
|
2593 |
+
$this->privCloseFd();
|
2594 |
+
$v_temp_zip->privCloseFd();
|
2595 |
+
@unlink($v_zip_temp_name);
|
2596 |
+
return $v_result;
|
2597 |
+
}
|
2598 |
+
}
|
2599 |
+
$v_offset = @ftell($v_temp_zip->zip_fd);
|
2600 |
+
for ($i=0; $i<sizeof($v_header_list); $i++) {
|
2601 |
+
if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
|
2602 |
+
$v_temp_zip->privCloseFd();
|
2603 |
+
$this->privCloseFd();
|
2604 |
+
@unlink($v_zip_temp_name);
|
2605 |
+
return $v_result;
|
2606 |
+
}
|
2607 |
+
$v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
|
2608 |
+
}
|
2609 |
+
$v_comment = '';
|
2610 |
+
if (isset($p_options[PCLZIP_OPT_COMMENT])) {
|
2611 |
+
$v_comment = $p_options[PCLZIP_OPT_COMMENT];
|
2612 |
+
}
|
2613 |
+
$v_size = @ftell($v_temp_zip->zip_fd)-$v_offset;
|
2614 |
+
if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {
|
2615 |
+
unset($v_header_list);
|
2616 |
+
$v_temp_zip->privCloseFd();
|
2617 |
+
$this->privCloseFd();
|
2618 |
+
@unlink($v_zip_temp_name);
|
2619 |
+
return $v_result;
|
2620 |
+
}
|
2621 |
+
$v_temp_zip->privCloseFd();
|
2622 |
+
$this->privCloseFd();
|
2623 |
+
@unlink($this->zipname);
|
2624 |
+
PclZipUtilRename($v_zip_temp_name, $this->zipname);
|
2625 |
+
unset($v_temp_zip);
|
2626 |
+
}
|
2627 |
+
else if ($v_central_dir['entries'] != 0) {
|
2628 |
+
$this->privCloseFd();
|
2629 |
+
if (($v_result = $this->privOpenFd('wb')) != 1) {
|
2630 |
+
return $v_result;
|
2631 |
+
}
|
2632 |
+
if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) {
|
2633 |
+
return $v_result;
|
2634 |
+
}
|
2635 |
+
$this->privCloseFd();
|
2636 |
+
}
|
2637 |
+
return $v_result;
|
2638 |
+
}
|
2639 |
+
function privDirCheck($p_dir, $p_is_dir=false)
|
2640 |
+
{
|
2641 |
+
$v_result = 1;
|
2642 |
+
if (($p_is_dir) && (substr($p_dir, -1)=='/'))
|
2643 |
+
{
|
2644 |
+
$p_dir = substr($p_dir, 0, strlen($p_dir)-1);
|
2645 |
+
}
|
2646 |
+
if ((is_dir($p_dir)) || ($p_dir == ""))
|
2647 |
+
{
|
2648 |
+
return 1;
|
2649 |
+
}
|
2650 |
+
$p_parent_dir = dirname($p_dir);
|
2651 |
+
if ($p_parent_dir != $p_dir)
|
2652 |
+
{
|
2653 |
+
if ($p_parent_dir != "")
|
2654 |
+
{
|
2655 |
+
if (($v_result = $this->privDirCheck($p_parent_dir)) != 1)
|
2656 |
+
{
|
2657 |
+
return $v_result;
|
2658 |
+
}
|
2659 |
+
}
|
2660 |
+
}
|
2661 |
+
if (!@mkdir($p_dir, 0777))
|
2662 |
+
{
|
2663 |
+
PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'");
|
2664 |
+
return PclZip::errorCode();
|
2665 |
+
}
|
2666 |
+
return $v_result;
|
2667 |
+
}
|
2668 |
+
function privMerge(&$p_archive_to_add)
|
2669 |
+
{
|
2670 |
+
$v_result=1;
|
2671 |
+
if (!is_file($p_archive_to_add->zipname))
|
2672 |
+
{
|
2673 |
+
$v_result = 1;
|
2674 |
+
return $v_result;
|
2675 |
+
}
|
2676 |
+
if (!is_file($this->zipname))
|
2677 |
+
{
|
2678 |
+
$v_result = $this->privDuplicate($p_archive_to_add->zipname);
|
2679 |
+
return $v_result;
|
2680 |
+
}
|
2681 |
+
if (($v_result=$this->privOpenFd('rb')) != 1)
|
2682 |
+
{
|
2683 |
+
return $v_result;
|
2684 |
+
}
|
2685 |
+
$v_central_dir = array();
|
2686 |
+
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
|
2687 |
+
{
|
2688 |
+
$this->privCloseFd();
|
2689 |
+
return $v_result;
|
2690 |
+
}
|
2691 |
+
@rewind($this->zip_fd);
|
2692 |
+
if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1)
|
2693 |
+
{
|
2694 |
+
$this->privCloseFd();
|
2695 |
+
return $v_result;
|
2696 |
+
}
|
2697 |
+
$v_central_dir_to_add = array();
|
2698 |
+
if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1)
|
2699 |
+
{
|
2700 |
+
$this->privCloseFd();
|
2701 |
+
$p_archive_to_add->privCloseFd();
|
2702 |
+
return $v_result;
|
2703 |
+
}
|
2704 |
+
@rewind($p_archive_to_add->zip_fd);
|
2705 |
+
$v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
|
2706 |
+
if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
|
2707 |
+
{
|
2708 |
+
$this->privCloseFd();
|
2709 |
+
$p_archive_to_add->privCloseFd();
|
2710 |
+
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
|
2711 |
+
return PclZip::errorCode();
|
2712 |
+
}
|
2713 |
+
$v_size = $v_central_dir['offset'];
|
2714 |
+
while ($v_size != 0)
|
2715 |
+
{
|
2716 |
+
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
2717 |
+
$v_buffer = fread($this->zip_fd, $v_read_size);
|
2718 |
+
@fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
|
2719 |
+
$v_size -= $v_read_size;
|
2720 |
+
}
|
2721 |
+
$v_size = $v_central_dir_to_add['offset'];
|
2722 |
+
while ($v_size != 0)
|
2723 |
+
{
|
2724 |
+
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
2725 |
+
$v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size);
|
2726 |
+
@fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
|
2727 |
+
$v_size -= $v_read_size;
|
2728 |
+
}
|
2729 |
+
$v_offset = @ftell($v_zip_temp_fd);
|
2730 |
+
$v_size = $v_central_dir['size'];
|
2731 |
+
while ($v_size != 0)
|
2732 |
+
{
|
2733 |
+
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
2734 |
+
$v_buffer = @fread($this->zip_fd, $v_read_size);
|
2735 |
+
@fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
|
2736 |
+
$v_size -= $v_read_size;
|
2737 |
+
}
|
2738 |
+
$v_size = $v_central_dir_to_add['size'];
|
2739 |
+
while ($v_size != 0)
|
2740 |
+
{
|
2741 |
+
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
2742 |
+
$v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size);
|
2743 |
+
@fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
|
2744 |
+
$v_size -= $v_read_size;
|
2745 |
+
}
|
2746 |
+
$v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment'];
|
2747 |
+
$v_size = @ftell($v_zip_temp_fd)-$v_offset;
|
2748 |
+
$v_swap = $this->zip_fd;
|
2749 |
+
$this->zip_fd = $v_zip_temp_fd;
|
2750 |
+
$v_zip_temp_fd = $v_swap;
|
2751 |
+
if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1)
|
2752 |
+
{
|
2753 |
+
$this->privCloseFd();
|
2754 |
+
$p_archive_to_add->privCloseFd();
|
2755 |
+
@fclose($v_zip_temp_fd);
|
2756 |
+
$this->zip_fd = null;
|
2757 |
+
unset($v_header_list);
|
2758 |
+
return $v_result;
|
2759 |
+
}
|
2760 |
+
$v_swap = $this->zip_fd;
|
2761 |
+
$this->zip_fd = $v_zip_temp_fd;
|
2762 |
+
$v_zip_temp_fd = $v_swap;
|
2763 |
+
$this->privCloseFd();
|
2764 |
+
$p_archive_to_add->privCloseFd();
|
2765 |
+
@fclose($v_zip_temp_fd);
|
2766 |
+
@unlink($this->zipname);
|
2767 |
+
PclZipUtilRename($v_zip_temp_name, $this->zipname);
|
2768 |
+
return $v_result;
|
2769 |
+
}
|
2770 |
+
function privDuplicate($p_archive_filename)
|
2771 |
+
{
|
2772 |
+
$v_result=1;
|
2773 |
+
if (!is_file($p_archive_filename))
|
2774 |
+
{
|
2775 |
+
$v_result = 1;
|
2776 |
+
return $v_result;
|
2777 |
+
}
|
2778 |
+
if (($v_result=$this->privOpenFd('wb')) != 1)
|
2779 |
+
{
|
2780 |
+
return $v_result;
|
2781 |
+
}
|
2782 |
+
if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0)
|
2783 |
+
{
|
2784 |
+
$this->privCloseFd();
|
2785 |
+
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode');
|
2786 |
+
return PclZip::errorCode();
|
2787 |
+
}
|
2788 |
+
$v_size = filesize($p_archive_filename);
|
2789 |
+
while ($v_size != 0)
|
2790 |
+
{
|
2791 |
+
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
|
2792 |
+
$v_buffer = fread($v_zip_temp_fd, $v_read_size);
|
2793 |
+
@fwrite($this->zip_fd, $v_buffer, $v_read_size);
|
2794 |
+
$v_size -= $v_read_size;
|
2795 |
+
}
|
2796 |
+
$this->privCloseFd();
|
2797 |
+
@fclose($v_zip_temp_fd);
|
2798 |
+
return $v_result;
|
2799 |
+
}
|
2800 |
+
function privErrorLog($p_error_code=0, $p_error_string='')
|
2801 |
+
{
|
2802 |
+
if (PCLZIP_ERROR_EXTERNAL == 1) {
|
2803 |
+
PclError($p_error_code, $p_error_string);
|
2804 |
+
}
|
2805 |
+
else {
|
2806 |
+
$this->error_code = $p_error_code;
|
2807 |
+
$this->error_string = $p_error_string;
|
2808 |
+
}
|
2809 |
+
}
|
2810 |
+
function privErrorReset()
|
2811 |
+
{
|
2812 |
+
if (PCLZIP_ERROR_EXTERNAL == 1) {
|
2813 |
+
PclErrorReset();
|
2814 |
+
}
|
2815 |
+
else {
|
2816 |
+
$this->error_code = 0;
|
2817 |
+
$this->error_string = '';
|
2818 |
+
}
|
2819 |
+
}
|
2820 |
+
function privDisableMagicQuotes()
|
2821 |
+
{
|
2822 |
+
$v_result=1;
|
2823 |
+
if ( (!function_exists("get_magic_quotes_runtime"))
|
2824 |
+
|| (!function_exists("set_magic_quotes_runtime"))) {
|
2825 |
+
return $v_result;
|
2826 |
+
}
|
2827 |
+
if ($this->magic_quotes_status != -1) {
|
2828 |
+
return $v_result;
|
2829 |
+
}
|
2830 |
+
// ----- Get and memorize the magic_quote value
|
2831 |
+
$this->magic_quotes_status = @get_magic_quotes_runtime();
|
2832 |
+
// ----- Disable magic_quotes
|
2833 |
+
if ($this->magic_quotes_status == 1) {
|
2834 |
+
@set_magic_quotes_runtime(0);
|
2835 |
+
}
|
2836 |
+
return $v_result;
|
2837 |
+
}
|
2838 |
+
function privSwapBackMagicQuotes()
|
2839 |
+
{
|
2840 |
+
$v_result=1;
|
2841 |
+
if ( (!function_exists("get_magic_quotes_runtime"))
|
2842 |
+
|| (!function_exists("set_magic_quotes_runtime"))) {
|
2843 |
+
return $v_result;
|
2844 |
+
}
|
2845 |
+
if ($this->magic_quotes_status != -1) {
|
2846 |
+
return $v_result;
|
2847 |
+
}
|
2848 |
+
// ----- Swap back magic_quotes
|
2849 |
+
if ($this->magic_quotes_status == 1) {
|
2850 |
+
@set_magic_quotes_runtime($this->magic_quotes_status);
|
2851 |
+
}
|
2852 |
+
return $v_result;
|
2853 |
+
}
|
2854 |
+
}
|
2855 |
+
function PclZipUtilPathReduction($p_dir)
|
2856 |
+
{
|
2857 |
+
$v_result = "";
|
2858 |
+
if ($p_dir != "") {
|
2859 |
+
$v_list = explode("/", $p_dir);
|
2860 |
+
$v_skip = 0;
|
2861 |
+
for ($i=sizeof($v_list)-1; $i>=0; $i--) {
|
2862 |
+
if ($v_list[$i] == ".") {
|
2863 |
+
}
|
2864 |
+
else if ($v_list[$i] == "..") {
|
2865 |
+
$v_skip++;
|
2866 |
+
}
|
2867 |
+
else if ($v_list[$i] == "") {
|
2868 |
+
// ----- First '/' i.e. root slash
|
2869 |
+
if ($i == 0) {
|
2870 |
+
$v_result = "/".$v_result;
|
2871 |
+
if ($v_skip > 0) {
|
2872 |
+
// ----- It is an invalid path, so the path is not modified
|
2873 |
+
// TBC
|
2874 |
+
$v_result = $p_dir;
|
2875 |
+
$v_skip = 0;
|
2876 |
+
}
|
2877 |
+
}
|
2878 |
+
// ----- Last '/' i.e. indicates a directory
|
2879 |
+
else if ($i == (sizeof($v_list)-1)) {
|
2880 |
+
$v_result = $v_list[$i];
|
2881 |
+
}
|
2882 |
+
// ----- Double '/' inside the path
|
2883 |
+
else {
|
2884 |
+
}
|
2885 |
+
}
|
2886 |
+
else {
|
2887 |
+
// ----- Look for item to skip
|
2888 |
+
if ($v_skip > 0) {
|
2889 |
+
$v_skip--;
|
2890 |
+
}
|
2891 |
+
else {
|
2892 |
+
$v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");
|
2893 |
+
}
|
2894 |
+
}
|
2895 |
+
}
|
2896 |
+
if ($v_skip > 0) {
|
2897 |
+
while ($v_skip > 0) {
|
2898 |
+
$v_result = '../'.$v_result;
|
2899 |
+
$v_skip--;
|
2900 |
+
}
|
2901 |
+
}
|
2902 |
+
}
|
2903 |
+
return $v_result;
|
2904 |
+
}
|
2905 |
+
function PclZipUtilPathInclusion($p_dir, $p_path)
|
2906 |
+
{
|
2907 |
+
$v_result = 1;
|
2908 |
+
if ( ($p_dir == '.')
|
2909 |
+
|| ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) {
|
2910 |
+
$p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1);
|
2911 |
+
}
|
2912 |
+
if ( ($p_path == '.')
|
2913 |
+
|| ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) {
|
2914 |
+
$p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1);
|
2915 |
+
}
|
2916 |
+
$v_list_dir = explode("/", $p_dir);
|
2917 |
+
$v_list_dir_size = sizeof($v_list_dir);
|
2918 |
+
$v_list_path = explode("/", $p_path);
|
2919 |
+
$v_list_path_size = sizeof($v_list_path);
|
2920 |
+
$i = 0;
|
2921 |
+
$j = 0;
|
2922 |
+
while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) {
|
2923 |
+
if ($v_list_dir[$i] == '') {
|
2924 |
+
$i++;
|
2925 |
+
continue;
|
2926 |
+
}
|
2927 |
+
if ($v_list_path[$j] == '') {
|
2928 |
+
$j++;
|
2929 |
+
continue;
|
2930 |
+
}
|
2931 |
+
if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) {
|
2932 |
+
$v_result = 0;
|
2933 |
+
}
|
2934 |
+
$i++;
|
2935 |
+
$j++;
|
2936 |
+
}
|
2937 |
+
if ($v_result) {
|
2938 |
+
while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++;
|
2939 |
+
while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++;
|
2940 |
+
if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) {
|
2941 |
+
$v_result = 2;
|
2942 |
+
}
|
2943 |
+
else if ($i < $v_list_dir_size) {
|
2944 |
+
$v_result = 0;
|
2945 |
+
}
|
2946 |
+
}
|
2947 |
+
return $v_result;
|
2948 |
+
}
|
2949 |
+
function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0)
|
2950 |
+
{
|
2951 |
+
$v_result = 1;
|
2952 |
+
if ($p_mode==0)
|
2953 |
+
{
|
2954 |
+
while ($p_size != 0)
|
2955 |
+
{
|
2956 |
+
$v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
|
2957 |
+
$v_buffer = @fread($p_src, $v_read_size);
|
2958 |
+
@fwrite($p_dest, $v_buffer, $v_read_size);
|
2959 |
+
$p_size -= $v_read_size;
|
2960 |
+
}
|
2961 |
+
}
|
2962 |
+
else if ($p_mode==1)
|
2963 |
+
{
|
2964 |
+
while ($p_size != 0)
|
2965 |
+
{
|
2966 |
+
$v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
|
2967 |
+
$v_buffer = @gzread($p_src, $v_read_size);
|
2968 |
+
@fwrite($p_dest, $v_buffer, $v_read_size);
|
2969 |
+
$p_size -= $v_read_size;
|
2970 |
+
}
|
2971 |
+
}
|
2972 |
+
else if ($p_mode==2)
|
2973 |
+
{
|
2974 |
+
while ($p_size != 0)
|
2975 |
+
{
|
2976 |
+
$v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
|
2977 |
+
$v_buffer = @fread($p_src, $v_read_size);
|
2978 |
+
@gzwrite($p_dest, $v_buffer, $v_read_size);
|
2979 |
+
$p_size -= $v_read_size;
|
2980 |
+
}
|
2981 |
+
}
|
2982 |
+
else if ($p_mode==3)
|
2983 |
+
{
|
2984 |
+
while ($p_size != 0)
|
2985 |
+
{
|
2986 |
+
$v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
|
2987 |
+
$v_buffer = @gzread($p_src, $v_read_size);
|
2988 |
+
@gzwrite($p_dest, $v_buffer, $v_read_size);
|
2989 |
+
$p_size -= $v_read_size;
|
2990 |
+
}
|
2991 |
+
}
|
2992 |
+
return $v_result;
|
2993 |
+
}
|
2994 |
+
function PclZipUtilRename($p_src, $p_dest)
|
2995 |
+
{
|
2996 |
+
$v_result = 1;
|
2997 |
+
if (!@rename($p_src, $p_dest)) {
|
2998 |
+
if (!@copy($p_src, $p_dest)) {
|
2999 |
+
$v_result = 0;
|
3000 |
+
}
|
3001 |
+
else if (!@unlink($p_src)) {
|
3002 |
+
$v_result = 0;
|
3003 |
+
}
|
3004 |
+
}
|
3005 |
+
return $v_result;
|
3006 |
+
}
|
3007 |
+
function PclZipUtilOptionText($p_option)
|
3008 |
+
{
|
3009 |
+
$v_list = get_defined_constants();
|
3010 |
+
for (reset($v_list); $v_key = key($v_list); next($v_list)) {
|
3011 |
+
$v_prefix = substr($v_key, 0, 10);
|
3012 |
+
if (( ($v_prefix == 'PCLZIP_OPT')
|
3013 |
+
|| ($v_prefix == 'PCLZIP_CB_')
|
3014 |
+
|| ($v_prefix == 'PCLZIP_ATT'))
|
3015 |
+
&& ($v_list[$v_key] == $p_option)) {
|
3016 |
+
return $v_key;
|
3017 |
+
}
|
3018 |
+
}
|
3019 |
+
$v_result = 'Unknown';
|
3020 |
+
return $v_result;
|
3021 |
+
}
|
3022 |
+
function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true)
|
3023 |
+
{
|
3024 |
+
if (stristr(php_uname(), 'windows')) {
|
3025 |
+
if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) {
|
3026 |
+
$p_path = substr($p_path, $v_position+1);
|
3027 |
+
}
|
3028 |
+
if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
|
3029 |
+
$p_path = strtr($p_path, '\\', '/');
|
3030 |
+
}
|
3031 |
+
}
|
3032 |
+
return $p_path;
|
3033 |
+
}
|
3034 |
+
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modules/phpseclib/index.html
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
-
<html>
|
3 |
-
<head lang="en">
|
4 |
-
<meta charset="UTF-8">
|
5 |
-
<title></title>
|
6 |
-
</head>
|
7 |
-
<body>
|
8 |
-
|
9 |
-
</body>
|
10 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modules/restore-class.php
CHANGED
@@ -13,23 +13,6 @@ if (!function_exists('dbr_extract_func')) {
|
|
13 |
}
|
14 |
}
|
15 |
|
16 |
-
if (!defined('PCLZIP_SEPARATOR')) {
|
17 |
-
define('PCLZIP_SEPARATOR', '<|>');
|
18 |
-
}
|
19 |
-
|
20 |
-
if (!function_exists('dbr_extract_func_targz')) {
|
21 |
-
function dbr_extract_func_targz($filename)
|
22 |
-
{
|
23 |
-
if (stripos($filename, 'wp-config.php') !== false) {
|
24 |
-
return true;
|
25 |
-
}
|
26 |
-
if (stripos($filename, 'dropbox-backup') !== false) {
|
27 |
-
return true;
|
28 |
-
}
|
29 |
-
return false;
|
30 |
-
}
|
31 |
-
}
|
32 |
-
|
33 |
|
34 |
if (!class_exists('dbr_gui')) {
|
35 |
class dbr_gui {
|
@@ -69,7 +52,7 @@ if (!class_exists('dbr_database')) {
|
|
69 |
self::$db_params = $db_params;
|
70 |
if (isset($pr[1])) {
|
71 |
self::$db_prefix = $pr[1];
|
72 |
-
}
|
73 |
} else {
|
74 |
self::$db_params = $configs;
|
75 |
$db_params = self::$db_params;
|
@@ -85,7 +68,7 @@ if (!class_exists('dbr_database')) {
|
|
85 |
//include ABSPATH . 'wp-config.php';
|
86 |
self::getWpMysqlParams();
|
87 |
if ( !defined('WP_CONTENT_DIR') )
|
88 |
-
define( 'WP_CONTENT_DIR',
|
89 |
|
90 |
if (function_exists('mysqli_connect')) {
|
91 |
self::$is_mysqli = true;
|
@@ -104,11 +87,11 @@ if (!class_exists('dbr_database')) {
|
|
104 |
}
|
105 |
} else {
|
106 |
if (self::$is_mysqli) {
|
107 |
-
self::$connect = mysqli_connect(self::$db_params['host'], self::$db_params['user'], self::$db_params['password']) or die();
|
108 |
mysqli_set_charset(self::$connect, self::$db_params['charset']) or die(mysqli_error());
|
109 |
mysqli_select_db(self::$connect, self::$db_params['db']) or die(mysqli_error());
|
110 |
} else {
|
111 |
-
self::$connect = @mysql_connect(self::$db_params['host'], self::$db_params['user'], self::$db_params['password']) or die();
|
112 |
mysql_set_charset(self::$db_params['charset'], self::$connect) or die(mysql_error());
|
113 |
mysql_select_db(self::$db_params['db'], self::$connect) or die(mysql_error());
|
114 |
}
|
@@ -380,275 +363,12 @@ if ( !class_exists('dbr_helper') ) {
|
|
380 |
class dbr_helper {
|
381 |
|
382 |
private static $cron_is_work = 90;
|
383 |
-
|
384 |
-
public static function testOtherArchive()
|
385 |
-
{
|
386 |
-
dbr_log::log('Testing of TarGz under shell');
|
387 |
-
$res_tar = self::TarGz( DBP_PATH_TMP . '/test.tar.gz', array(DBP_PATH_TMP .'/index.php', DBP_PATH_TMP .'/.htaccess'), ABSPATH );
|
388 |
-
|
389 |
-
if ($res_tar === true) {
|
390 |
-
dbr_log::log('Testing of TarGz under shell was finished successfully');
|
391 |
-
dbr_helper::setCommand('test_targz_c', true);
|
392 |
-
}
|
393 |
-
dbr_log::log('Testing of unTarGz under shell');
|
394 |
-
$res_tar = self::unTarGz( DBP_PATH_TMP . '/test.tar.gz', DBP_PATH_TMP . '/test/' );
|
395 |
-
if ($res_tar === true) {
|
396 |
-
dbr_log::log('Testing of unTarGz under shell was finished successfully');
|
397 |
-
dbr_helper::setCommand('test_targz_c', true);
|
398 |
-
}
|
399 |
-
|
400 |
-
dbr_log::log('Testing of Zip under shell');
|
401 |
-
$res_zip = self::Zip( DBP_PATH_TMP . '/test.zip', array(DBP_PATH_TMP .'/index.php', DBP_PATH_TMP .'/.htaccess'), ABSPATH );
|
402 |
-
if ($res_tar === true) {
|
403 |
-
dbr_log::log('Testing of ZIP under shell was finished successfully');
|
404 |
-
dbr_helper::setCommand('test_zip_c', true);
|
405 |
-
}
|
406 |
-
}
|
407 |
-
|
408 |
-
public static function getCommandToArchive($file_name, $type = 'zip_archive', $files = array(), $type_action = 'create', $remove_path = '' )
|
409 |
-
{
|
410 |
-
$return = '';
|
411 |
-
$remove_dir = '';
|
412 |
-
switch($type) {
|
413 |
-
case 'zip_archive':
|
414 |
-
if ($type_action == 'create') {
|
415 |
-
if (!empty( $remove_path ) ) {
|
416 |
-
$remove_dir = 'cd ' . $remove_path. ' &&';
|
417 |
-
$files_str = '"' . implode('" "', $files) . '"';
|
418 |
-
$files_str = str_replace($remove_path, './', $files_str);
|
419 |
-
$zip = str_replace($remove_path, './', $file_name);
|
420 |
-
} else {
|
421 |
-
$files_str = '"' . implode('" "', $files) . '"';
|
422 |
-
$zip = $file_name;
|
423 |
-
}
|
424 |
-
$return .= trim( "$remove_dir zip {$zip} " . $files_str );
|
425 |
-
} else {
|
426 |
-
$zip = $file_name;
|
427 |
-
if (!empty( $remove_path ) ) { // for extract this param of directory to
|
428 |
-
$remove_dir = 'cd ' . $remove_path . ' &&';
|
429 |
-
}
|
430 |
-
$exclude = '';
|
431 |
-
if ( !empty( $files ) ) { // exclude file
|
432 |
-
$exclude = ' -x ' . '"' . implode('" "', $files) . '"';
|
433 |
-
}
|
434 |
-
$return .= trim( "$remove_dir unzip -o {$zip} $exclude" );
|
435 |
-
}
|
436 |
-
|
437 |
-
break;
|
438 |
-
case 'tar_archive':
|
439 |
-
if ( strpos($file_name, '.zip') !== false ) {
|
440 |
-
$file_name = str_replace('.zip', '.tar.gz', $file_name);
|
441 |
-
}
|
442 |
-
|
443 |
-
if (!empty( $remove_path ) ) {
|
444 |
-
$remove_dir = '-C "' . $remove_path . '" ';
|
445 |
-
}
|
446 |
-
if ($type_action == 'create') {
|
447 |
-
$files_str = '"' . implode('" "', $files) . '"';
|
448 |
-
$files_str = str_replace($remove_path, './', $files_str);
|
449 |
-
$u = 'c';
|
450 |
-
if (file_exists($file_name)) {
|
451 |
-
$u = 'r';
|
452 |
-
}
|
453 |
-
$return = trim( "tar -{$u}zvf {$file_name} " . $remove_dir . $files_str );
|
454 |
-
} else {
|
455 |
-
|
456 |
-
$return = trim( "tar zxvf \"{$file_name}\" " . $remove_dir );
|
457 |
-
}
|
458 |
-
break;
|
459 |
-
}
|
460 |
-
return $return;
|
461 |
-
|
462 |
-
}
|
463 |
-
|
464 |
-
public static function parseResultZip($command_return)
|
465 |
-
{
|
466 |
-
$add = 0;
|
467 |
-
$error = 0;
|
468 |
-
if (!empty( $command_return) ) {
|
469 |
-
$n = count($command_return);
|
470 |
-
for($i = 0; $i < $n; $i++) {
|
471 |
-
if (strpos($command_return[$i], 'add') !== false || strpos($command_return[$i], 'updating') !== false || strpos($command_return[$i], 'inflating') !== false) {
|
472 |
-
$add ++;
|
473 |
-
} elseif (strpos($command_return[$i], 'error') !== false || strpos($command_return[$i], 'warning') !== false ) {
|
474 |
-
$error++;
|
475 |
-
$this->error .= " " . $command_return[$i];
|
476 |
-
}
|
477 |
-
}
|
478 |
-
}
|
479 |
-
return array( 'add' => $add, 'error' => $error );
|
480 |
-
|
481 |
-
}
|
482 |
-
|
483 |
-
public static function TarGz($file_name, $files, $delete_foler = '')
|
484 |
-
{
|
485 |
-
$command = self::getCommandToArchive($file_name, 'tar_archive', $files, 'create', $delete_foler);
|
486 |
-
if (!empty($command)) {
|
487 |
-
|
488 |
-
$result_command = @exec($command, $command_return);
|
489 |
-
|
490 |
-
if (count($files) == count($command_return)) {
|
491 |
-
return true;
|
492 |
-
}
|
493 |
-
|
494 |
-
if (count($command_return) > 0) {
|
495 |
-
return true;
|
496 |
-
}
|
497 |
-
if (file_exists($file_name)) {
|
498 |
-
return true;
|
499 |
-
}
|
500 |
-
return "Files not adding to arhive";
|
501 |
-
}
|
502 |
-
|
503 |
-
return false;
|
504 |
-
}
|
505 |
-
|
506 |
-
public static function unTarGz($file_name, $dir_to)
|
507 |
-
{
|
508 |
-
$command = self::getCommandToArchive($file_name, 'tar_archive', array(), 'etract', $dir_to);
|
509 |
-
|
510 |
-
if (!empty($command)) {
|
511 |
-
|
512 |
-
$result_command = @exec($command, $command_return);
|
513 |
-
|
514 |
-
if (count($command_return) > 0) {
|
515 |
-
return true;
|
516 |
-
}
|
517 |
-
if (file_exists($file_name)) {
|
518 |
-
return true;
|
519 |
-
}
|
520 |
-
return "Files not adding to arhive";
|
521 |
-
}
|
522 |
-
|
523 |
-
return false;
|
524 |
-
}
|
525 |
-
|
526 |
-
public static function Zip($file_name, $files, $delete_foler = '')
|
527 |
-
{
|
528 |
-
$command = self::getCommandToArchive($file_name, 'zip_archive', $files, 'create', $delete_foler);
|
529 |
-
if (!empty($command)) {
|
530 |
-
$result_command = @exec($command, $command_return);
|
531 |
-
|
532 |
-
$res = self::parseResultZip($command_return);
|
533 |
-
|
534 |
-
if ($res['add'] == count($files)) {
|
535 |
-
return true;
|
536 |
-
}
|
537 |
-
if ( file_exists( $file_name ) && $res['error'] === 0 ) {
|
538 |
-
return true;
|
539 |
-
}
|
540 |
-
}
|
541 |
-
|
542 |
-
return false;
|
543 |
-
}
|
544 |
-
|
545 |
-
public static function unZip($file_name, $dir_to, $exclude = array() )
|
546 |
-
{
|
547 |
-
$command = self::getCommandToArchive($file_name, 'zip_archive', $exclude, 'extract', $dir_to);
|
548 |
-
if (!empty($command)) {
|
549 |
-
$result_command = @exec($command, $command_return);
|
550 |
-
|
551 |
-
$res = self::parseResultZip($command_return);
|
552 |
-
|
553 |
-
if ( $res['error'] === 0 ) {
|
554 |
-
return true;
|
555 |
-
}
|
556 |
-
}
|
557 |
-
|
558 |
-
return false;
|
559 |
-
}
|
560 |
-
|
561 |
-
public static function check_invalid_utf8( $string, $strip = false )
|
562 |
-
{
|
563 |
-
$string = (string) $string;
|
564 |
-
|
565 |
-
if ( 0 === strlen( $string ) ) {
|
566 |
-
return '';
|
567 |
-
}
|
568 |
-
// preg match invalid UTF8
|
569 |
-
if ( 1 === @preg_match( '/^./us', $string ) ) {
|
570 |
-
return $string;
|
571 |
-
}
|
572 |
-
|
573 |
-
if ( $strip && function_exists( 'iconv' ) ) {
|
574 |
-
return iconv( 'utf-8', 'utf-8', $string );
|
575 |
-
}
|
576 |
-
|
577 |
-
return '';
|
578 |
-
}
|
579 |
-
|
580 |
-
|
581 |
-
public static function strip_all_tags($string, $remove_breaks = false) {
|
582 |
-
$string = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $string );
|
583 |
-
$string = strip_tags($string);
|
584 |
-
|
585 |
-
if ( $remove_breaks )
|
586 |
-
$string = preg_replace('/[\r\n\t ]+/', ' ', $string);
|
587 |
-
|
588 |
-
return trim( $string );
|
589 |
-
}
|
590 |
-
|
591 |
-
public static function less_than( $text ) {
|
592 |
-
return preg_replace_callback('%<[^>]*?((?=<)|>|$)%', array('dbr_helper', 'less_than_callback'), $text);
|
593 |
-
}
|
594 |
-
|
595 |
-
public static function less_than_callback( $matches ) {
|
596 |
-
if ( false === strpos($matches[0], '>') )
|
597 |
-
return self::to_html($matches[0]);
|
598 |
-
return $matches[0];
|
599 |
-
}
|
600 |
-
|
601 |
-
public static function to_html($string, $quote_style = ENT_NOQUOTES)
|
602 |
-
{
|
603 |
-
$string = (string) $string;
|
604 |
-
|
605 |
-
if ( 0 === strlen( $string ) )
|
606 |
-
return '';
|
607 |
-
|
608 |
-
if ( ! preg_match( '/[&<>"\']/', $string ) )
|
609 |
-
return $string;
|
610 |
-
|
611 |
-
if ( empty( $quote_style ) )
|
612 |
-
$quote_style = ENT_NOQUOTES;
|
613 |
-
elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) )
|
614 |
-
$quote_style = ENT_QUOTES;
|
615 |
-
|
616 |
-
$charset = 'UTF-8';
|
617 |
-
|
618 |
-
$string = @htmlspecialchars( $string, $quote_style, $charset, $double_encode );
|
619 |
-
|
620 |
-
if ( 'single' === $_quote_style )
|
621 |
-
$string = str_replace( "'", ''', $string );
|
622 |
-
|
623 |
-
return $string;
|
624 |
-
}
|
625 |
-
|
626 |
-
public static function sanitize($str, $is_newlines = false)
|
627 |
-
{
|
628 |
-
$filter = self::check_invalid_utf8( $str );
|
629 |
-
if ( strpos($filter, '<') !== false ) {
|
630 |
-
$filter = self::less_than( $filter );
|
631 |
-
$filter = self::strip_all_tags( $filter, false );
|
632 |
-
$filter = str_replace("<\n", "<\n", $filter);
|
633 |
-
}
|
634 |
-
|
635 |
-
if ( !$is_newlines ) {
|
636 |
-
$filter = preg_replace( '/[\r\n\t ]+/', ' ', $filter );
|
637 |
-
}
|
638 |
-
$filter = trim( $filter );
|
639 |
-
|
640 |
-
return $filter;
|
641 |
-
|
642 |
-
}
|
643 |
-
|
644 |
public static function modSecureInstalled()
|
645 |
{
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
@phpinfo(INFO_MODULES);
|
650 |
-
$contents = ob_get_clean();
|
651 |
-
}
|
652 |
return strpos($contents, 'mod_security') !== false;
|
653 |
}
|
654 |
|
@@ -709,7 +429,7 @@ if ( !class_exists('dbr_helper') ) {
|
|
709 |
if (isset($site_url['option_value'])) {
|
710 |
$name_running_backup = str_replace("http://", '', $site_url['option_value']);
|
711 |
$name_running_backup = str_replace("https://", '', $name_running_backup);
|
712 |
-
$name_running_backup = preg_replace("|\W|", "_",
|
713 |
}
|
714 |
return $name_running_backup;
|
715 |
}
|
@@ -722,31 +442,15 @@ if ( !class_exists('dbr_helper') ) {
|
|
722 |
@unlink(DBP_PATH_TMP . '/' . $file);
|
723 |
}
|
724 |
}
|
725 |
-
self::createDefaultFiles(DBP_PATH_TMP);
|
726 |
// @rmdir(DBP_PATH_TMP);
|
727 |
}
|
728 |
}
|
729 |
-
|
730 |
-
public static function createDefaultFiles($dir)
|
731 |
-
{
|
732 |
-
if (!file_exists($dir . '/index.php')) {
|
733 |
-
@file_put_contents($dir . '/index.php', '<?php echo "Hello World!"; ');
|
734 |
-
if ( !is_writable($dir . '/index.php') ) {
|
735 |
-
return str_replace("&s", $dir . '/index.php' , 'Backup creating<br /><br />Please check the permissions on file "&s". Failed to create file.' );
|
736 |
-
}
|
737 |
-
}
|
738 |
-
if (!file_exists($dir . '/.htaccess')) {
|
739 |
-
@file_put_contents($dir . '/.htaccess', 'DENY FROM ALL');
|
740 |
-
}
|
741 |
-
return true;
|
742 |
-
}
|
743 |
-
|
744 |
-
|
745 |
public static function unpack_setting($str)
|
746 |
{
|
747 |
return unserialize( base64_decode( $str ) );
|
748 |
}
|
749 |
-
|
750 |
public static function pack_setting($str)
|
751 |
{
|
752 |
return base64_encode( serialize( $str ) );
|
@@ -754,10 +458,7 @@ if ( !class_exists('dbr_helper') ) {
|
|
754 |
|
755 |
public static function pack($data)
|
756 |
{
|
757 |
-
|
758 |
-
return base64_encode( json_encode ( $data, JSON_HEX_QUOT|JSON_HEX_TAG|JSON_HEX_AMP|JSON_HEX_APOS ) ) ;
|
759 |
-
}
|
760 |
-
return base64_encode( json_encode ( $data ) ) ;
|
761 |
}
|
762 |
|
763 |
public static function unpack($data)
|
@@ -879,8 +580,6 @@ if ( !class_exists('dbr_core') ) {
|
|
879 |
}
|
880 |
}
|
881 |
|
882 |
-
|
883 |
-
|
884 |
if ( !class_exists('dbr_methods') ) {
|
885 |
class dbr_methods{
|
886 |
|
@@ -902,11 +601,6 @@ if ( !class_exists('dbr_methods') ) {
|
|
902 |
$json['data'] = dbr_helper::getCommand('result-restore');
|
903 |
}
|
904 |
}
|
905 |
-
|
906 |
-
$mod_security = dbr_helper::getCommand('mod_security');
|
907 |
-
if ($mod_security) {
|
908 |
-
$json['mod_secur'] = true;
|
909 |
-
}
|
910 |
echo json_encode ( $json );
|
911 |
exit;
|
912 |
}
|
@@ -926,7 +620,7 @@ if ( !class_exists('dbr_methods') ) {
|
|
926 |
$this->main = dbr_helper::unpack_setting( $setting['option_value'] );
|
927 |
}
|
928 |
|
929 |
-
$backup_dir =
|
930 |
if (isset($this->main['backup_folder']) && !empty($this->main['backup_folder'])) {
|
931 |
$backup_dir = $this->main['backup_folder'];
|
932 |
}
|
@@ -988,30 +682,16 @@ if ( !class_exists('dbr_methods') ) {
|
|
988 |
$arr_sql = dbr_helper::getCommand('sql-restore');
|
989 |
if ( !isset( $arr_sql[md5($sql)] ) || $arr_sql === false ) {
|
990 |
$ress = dbr_database::query( $sql );
|
991 |
-
dbr_helper::is_work(time(), 'start');
|
992 |
-
if (stripos($sql, 'create') !== false) {
|
993 |
-
preg_match("/CREATE[\s]{1,}TABLE[\s]{1,}`(.*)`/iUu", $sql, $table_insert) ;
|
994 |
-
if (isset($table_insert[1]) && !empty($table_insert[1])) {
|
995 |
-
dbr_log::log('Restore table `' . $table_insert[1] . '`');
|
996 |
-
}
|
997 |
-
}
|
998 |
-
|
999 |
-
if (isset($ress) && ( $ress === false || !empty( dbr_database::$error ) ) ) {
|
1000 |
-
if (stripos(dbr_database::$error, 'duplicate entry') === false) {
|
1001 |
-
dbr_helper::setError('MySQL Error: ' . dbr_database::$error . ' sql: ' . $sql );
|
1002 |
-
break;
|
1003 |
-
}
|
1004 |
-
}
|
1005 |
$arr_sql[md5($sql)] = 1;
|
1006 |
dbr_helper::setCommand('sql-restore', $arr_sql);
|
1007 |
}
|
1008 |
}
|
1009 |
if (isset($ress) && ( $ress === false || !empty( dbr_database::$error ) ) ) {
|
1010 |
if (stripos(dbr_database::$error, 'duplicate entry') === false) {
|
1011 |
-
dbr_helper::setError('MySQL Error: ' . dbr_database::$error
|
1012 |
break;
|
1013 |
}
|
1014 |
-
}
|
1015 |
$sql = "";
|
1016 |
}
|
1017 |
}
|
@@ -1038,10 +718,6 @@ if ( !class_exists('dbr_methods') ) {
|
|
1038 |
if(strpos($d, ".zip") !== false) {
|
1039 |
$this->files_resotre[$d] = $this->dir_backup . "/$d";
|
1040 |
}
|
1041 |
-
if(substr($d, -7) == '.tar.gz') {
|
1042 |
-
$this->files_resotre[$d] = $this->dir_backup . "/$d";
|
1043 |
-
dbr_helper::setCommand('targz', true);
|
1044 |
-
}
|
1045 |
if(strpos($d, ".md5") !== false) {
|
1046 |
$file_md5 = $this->dir_backup . "/$d";
|
1047 |
}
|
@@ -1069,66 +745,9 @@ if ( !class_exists('dbr_methods') ) {
|
|
1069 |
|
1070 |
}
|
1071 |
|
1072 |
-
private function reconfig()
|
1073 |
-
{
|
1074 |
-
|
1075 |
-
dbr_helper::is_work(time(), 'start');
|
1076 |
-
if ( dbr_helper::is_writable(ABSPATH . 'wp-config.php') === false) {
|
1077 |
-
dbr_helper::setError( "File 'wp-config.php' is not writable" );
|
1078 |
-
}
|
1079 |
-
$db_params = array(
|
1080 |
-
'password' => 'DB_PASSWORD',
|
1081 |
-
'db' => 'DB_NAME',
|
1082 |
-
'user' => 'DB_USER',
|
1083 |
-
'host' => 'DB_HOST',
|
1084 |
-
'charset' => 'DB_CHARSET',
|
1085 |
-
);
|
1086 |
-
|
1087 |
-
$r = "/define\([\s]{0,}['\"]{1}(.*)['\"]{1}[\s]{0,},[\s]{0,}['\"]{1}(.*)['\"]{1}[\s]{0,}\)/";
|
1088 |
-
$config = @file_get_contents(ABSPATH . "wp-config.php");
|
1089 |
-
preg_match_all($r, $config, $m);
|
1090 |
-
$params = array_combine( $m[1], $m[2] );
|
1091 |
-
$change_config = false;
|
1092 |
-
foreach($db_params as $k => $p) {
|
1093 |
-
$db_params[$k] = $params[$p];
|
1094 |
-
if (dbr_database::$db_params[$k] != $db_params[$k]) {
|
1095 |
-
$change_config = true;
|
1096 |
-
}
|
1097 |
-
}
|
1098 |
-
dbr_helper::is_work(time(), 'start');
|
1099 |
-
if ($change_config) {
|
1100 |
-
dbr_log::log('Configure file "wp-config.php" was started');
|
1101 |
-
$patterns = array();
|
1102 |
-
$patterns[0] = "/define[\s]{0,}\([\s]{0,}'DB_PASSWORD'[\s]{0,},[\s]{0,}'(.*)'[\s]{0,}\)/";
|
1103 |
-
$patterns[1] = "/define[\s]{0,}\([\s]{0,}'DB_NAME'[\s]{0,},[\s]{0,}'(.*)'[\s]{0,}\)/";
|
1104 |
-
$patterns[2] = "/define[\s]{0,}\([\s]{0,}'DB_USER'[\s]{0,},[\s]{0,}'(.*)'[\s]{0,}\)/";
|
1105 |
-
$patterns[3] = "/define[\s]{0,}\([\s]{0,}'DB_HOST'[\s]{0,},[\s]{0,}'(.*)'[\s]{0,}\)/";
|
1106 |
-
$patterns[4] = "/define[\s]{0,}\([\s]{0,}'DB_CHARSET'[\s]{0,},[\s]{0,}'(.*)'[\s]{0,}\)/";
|
1107 |
-
|
1108 |
-
$replacements = array();
|
1109 |
-
$replacements[0] = "define('DB_PASSWORD', '" . dbr_database::$db_params['password'] . "')";
|
1110 |
-
$replacements[1] = "define('DB_NAME', '" . dbr_database::$db_params['db'] . "')";
|
1111 |
-
$replacements[2] = "define('DB_USER', '" . dbr_database::$db_params['user'] . "')";
|
1112 |
-
$replacements[3] = "define('DB_HOST', '" . dbr_database::$db_params['host'] . "')";
|
1113 |
-
$replacements[4] = "define('DB_CHARSET', '" . dbr_database::$db_params['charset'] . "')";
|
1114 |
-
|
1115 |
-
$config = preg_replace($patterns, $replacements, $config);
|
1116 |
-
|
1117 |
-
//$config = preg_replace("/table_prefix[\s]{0,}=[\s]{0,}[\"']{1}(.*)[\"']{1}/U", "table_prefix = '" . dbr_database::$db_prefix . "'", $config);
|
1118 |
-
|
1119 |
-
$write = @file_put_contents(ABSPATH . "wp-config.php", $config);
|
1120 |
-
|
1121 |
-
dbr_helper::is_work(time(), 'start');
|
1122 |
-
if (!$write) {
|
1123 |
-
dbr_helper::setError( "File 'wp-config.php' is not writable" );
|
1124 |
-
}
|
1125 |
-
dbr_log::log('Configure file "wp-config.php" was successfully');
|
1126 |
-
}
|
1127 |
-
}
|
1128 |
-
|
1129 |
private function restoreFiles()
|
1130 |
{
|
1131 |
-
|
1132 |
$files = dbr_helper::getCommand('files-list-retore');
|
1133 |
if ($files) {
|
1134 |
dbr_helper::is_work(time(), 'start');
|
@@ -1169,31 +788,12 @@ if ( !class_exists('dbr_methods') ) {
|
|
1169 |
dbr_helper::setCommand('zip-config', null);
|
1170 |
}
|
1171 |
}
|
1172 |
-
$tar_gz = dbr_helper::getCommand('targz');
|
1173 |
-
if (!$tar_gz) {
|
1174 |
-
include 'pclzip.lib.php';
|
1175 |
-
}
|
1176 |
foreach($files as $f => $file) {
|
1177 |
$extract_files = dbr_helper::getCommand('extract-files-restore');
|
1178 |
if (!isset($extract_files[$f])) {
|
1179 |
dbr_log::log('Data will be decompressed of ' . basename($file));
|
1180 |
if (strpos($f, '.zip')) {
|
1181 |
if (file_exists($file) && filesize($file) > 0) {
|
1182 |
-
$test_zip = dbr_helper::getCommand('test_zip_c');
|
1183 |
-
if ($test_zip) {
|
1184 |
-
$unzip = dbr_helper::unZip($file, ABSPATH_REAL, array('wp-content/plugins/dropbox-backup/*', 'wp-content/plugins/dropbox-backup-pro/*') );
|
1185 |
-
if ($unzip) {
|
1186 |
-
if ($zip_config && strpos($file, $zip_config[2]) !== false) {
|
1187 |
-
$this->reconfig();
|
1188 |
-
}
|
1189 |
-
$extract_files[$f] = true;
|
1190 |
-
dbr_helper::setCommand('extract-files-restore', $extract_files);
|
1191 |
-
continue;
|
1192 |
-
} else {
|
1193 |
-
dbr_log::log('Data will be decompressed of ' . basename($file) . ' wasn\'t successful. Try other method "PclZip"');
|
1194 |
-
dbr_helper::setCommand('test_zip_c', false);
|
1195 |
-
}
|
1196 |
-
}
|
1197 |
$archive = new PclZip($file);
|
1198 |
$unzip = $archive->extract(
|
1199 |
PCLZIP_CB_PRE_EXTRACT, 'dbr_extract_func',
|
@@ -1216,7 +816,52 @@ if ( !class_exists('dbr_methods') ) {
|
|
1216 |
if ($unzip == 0) {
|
1217 |
dbr_helper::setError("Error during extracting of database config from archive: " . $archive->errorInfo(true) );
|
1218 |
}
|
1219 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1220 |
}
|
1221 |
if ($zip_database && strpos($file, $zip_database[2]) !== false) {
|
1222 |
$archive = new PclZip($file);
|
@@ -1234,57 +879,6 @@ if ( !class_exists('dbr_methods') ) {
|
|
1234 |
} else {
|
1235 |
dbr_helper::setError('File (' . $file . ') for restoring wasn\'t found or file size is 0 byte');
|
1236 |
}
|
1237 |
-
} elseif ($tar_gz) {
|
1238 |
-
if (file_exists($file) && filesize($file) > 0) {
|
1239 |
-
$test_targz = dbr_helper::getCommand('test_targz_c');
|
1240 |
-
if ($test_targz) {
|
1241 |
-
$untargz = dbr_helper::unTarGz($file, rtrim( ABSPATH_REAL , '/'), array('wp-content/plugins/dropbox-backup/*', 'wp-content/plugins/dropbox-backup-pro/*') );
|
1242 |
-
if ($untargz) {
|
1243 |
-
if ($zip_config && strpos($file, $zip_config[2]) !== false) {
|
1244 |
-
$this->reconfig();
|
1245 |
-
}
|
1246 |
-
$extract_files[$f] = true;
|
1247 |
-
dbr_helper::setCommand('extract-files-restore', $extract_files);
|
1248 |
-
continue;
|
1249 |
-
} else {
|
1250 |
-
dbr_log::log('Data will be decompressed of ' . basename($file) . ' wasn\'t successful. Try other method "PHP tar class"');
|
1251 |
-
dbr_helper::setCommand('test_targz_c', false);
|
1252 |
-
}
|
1253 |
-
}
|
1254 |
-
include_once 'archive.php' ;
|
1255 |
-
dbr_helper::is_work(time(), 'start');
|
1256 |
-
$gz = new wpadm_gzip_file($file);
|
1257 |
-
$gz->set_options(array( 'overwrite' => 1, 'basedir' => ABSPATH ) );
|
1258 |
-
$gz->exclude = 'dbr_extract_func_targz';
|
1259 |
-
$gz->extract_gz_files();
|
1260 |
-
dbr_helper::is_work(time(), 'start');
|
1261 |
-
if (!empty( $gz->warning ) ) {
|
1262 |
-
foreach($gz->warning as $warning) {
|
1263 |
-
dbr_log::log($warning);
|
1264 |
-
}
|
1265 |
-
}
|
1266 |
-
if (!empty($gz->error)) {
|
1267 |
-
dbr_helper::setError( implode("\n", $gz->error) );
|
1268 |
-
}
|
1269 |
-
unset($gz);
|
1270 |
-
if ($zip_config && strpos($file, $zip_config[2]) !== false) {
|
1271 |
-
dbr_helper::is_work(time(), 'start');
|
1272 |
-
if ( dbr_helper::is_writable(ABSPATH . 'wp-config.php') === false) {
|
1273 |
-
dbr_helper::setError( "File 'wp-config.php' is not writable" );
|
1274 |
-
}
|
1275 |
-
$gz = new wpadm_gzip_file($file);
|
1276 |
-
$gz->set_options(array( 'overwrite' => 1, 'basedir' => ABSPATH ) );
|
1277 |
-
|
1278 |
-
$gz->include_files("/wp-config\.php/");
|
1279 |
-
dbr_helper::is_work(time(), 'start');
|
1280 |
-
$gz->extract_gz_files();
|
1281 |
-
dbr_helper::is_work(time(), 'start');
|
1282 |
-
|
1283 |
-
$this->reconfig();
|
1284 |
-
}
|
1285 |
-
$extract_files[$f] = true;
|
1286 |
-
dbr_helper::setCommand('extract-files-restore', $extract_files);
|
1287 |
-
}
|
1288 |
}
|
1289 |
}
|
1290 |
}
|
@@ -1318,9 +912,6 @@ if ( !class_exists('dbr_methods') ) {
|
|
1318 |
if ($file_list === false) {
|
1319 |
dbr_log::log('Getting list of files from Dropbox');
|
1320 |
$files = $dropbox->listing("$folder_project/$name_backup");
|
1321 |
-
if (isset($files['error']) ) {
|
1322 |
-
dbr_helper::setError('Dropbox answered: ' . $files['text']);
|
1323 |
-
}
|
1324 |
dbr_helper::setCommand('download-with-dropbox-restore', $files, 'file-list');
|
1325 |
dbr_helper::is_work(time(), 'start');
|
1326 |
} else {
|
@@ -1350,7 +941,7 @@ if ( !class_exists('dbr_methods') ) {
|
|
1350 |
}
|
1351 |
$md5 = glob($this->dir_backup . '/*.md5');
|
1352 |
if (count( $md5 ) == 0) {
|
1353 |
-
dbr_helper::setError( "File list from MD5 file wasn't loaded. Please, check folder and
|
1354 |
}
|
1355 |
dbr_helper::setCommand('download-with-dropbox-restore', true, 'success');
|
1356 |
return true;
|
@@ -1373,18 +964,6 @@ if (!class_exists('dbr_route')) {
|
|
1373 |
if (!defined('ABSPATH')) {
|
1374 |
define('ABSPATH', dirname(__FILE__) . '/../../../../');
|
1375 |
}
|
1376 |
-
if (!defined('ABSPATH_REAL')) {
|
1377 |
-
$dir = dirname(__FILE__);
|
1378 |
-
$dir = str_replace("\\", '/', $dir);
|
1379 |
-
$dir_arr = explode("/", $dir);
|
1380 |
-
for($i = 0; $i < 4; $i++) {
|
1381 |
-
array_pop($dir_arr);
|
1382 |
-
}
|
1383 |
-
$dir = implode('/', $dir_arr) . '/';
|
1384 |
-
|
1385 |
-
define('ABSPATH_REAL', $dir );
|
1386 |
-
}
|
1387 |
-
|
1388 |
if (!defined('DBP_PATH')) {
|
1389 |
define('DBP_PATH', dirname(__FILE__) . '/../');
|
1390 |
}
|
@@ -1405,39 +984,34 @@ if (!class_exists('dbr_route')) {
|
|
1405 |
|
1406 |
function __construct()
|
1407 |
{
|
1408 |
-
@set_time_limit(0);
|
1409 |
-
if (function_exists('set_error_handler')) {
|
1410 |
-
set_error_handler(array($this, 'error_handler') );
|
1411 |
-
}
|
1412 |
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
|
1413 |
if ( !isset($_POST['name']) ) {
|
1414 |
$this->parsMethod();
|
1415 |
-
} elseif( isset($_POST['name']
|
1416 |
-
try {
|
1417 |
-
dbr_helper::clearTMP();
|
1418 |
-
dbr_helper::testOtherArchive();
|
1419 |
-
dbr_database::inc_wp_config();
|
1420 |
-
$setting = dbr_database::db_get('options', array('option_value'), array('option_name' => 'wpadm_backup_dropbox-setting'), 1);
|
1421 |
-
if (isset($setting['option_value'])) {
|
1422 |
-
$this->setting = dbr_helper::unpack_setting( $setting['option_value'] );
|
1423 |
-
}
|
1424 |
-
$this->setting['restore-key'] = md5( time() . microtime() . __FILE__);
|
1425 |
-
include 'constant.php';
|
1426 |
-
$plugin = $this->parsePlugin('/dropbox-backup');
|
1427 |
-
$plugin_name = 'dropbox-backup';
|
1428 |
-
$version = '1.0';
|
1429 |
-
if (isset($plugin['/dropbox-backup']['Version'])) {
|
1430 |
-
$version = $plugin['/dropbox-backup']['Version'];
|
1431 |
-
} else{
|
1432 |
-
$plugin = $this->parsePlugin('/dropbox-backup-pro');
|
1433 |
-
if (isset($plugin['/dropbox-backup-pro']['Version'])) {
|
1434 |
-
$version = $plugin['/dropbox-backup-pro']['Version'];
|
1435 |
-
$plugin_name = 'dropbox-backup-pro';
|
1436 |
-
}
|
1437 |
-
}
|
1438 |
-
$data = array('actApi' => 'setPluginCode', $plugin_name . '_request' => array('action' => 'restore', 'site' => SITE_HOME, 'pl' => $plugin_name, 'key' => $this->setting['restore-key'], 'pl_v' => $version, ) );
|
1439 |
-
$res = dbr_api::post(WPADM_URL_BASE . 'api/', $data);
|
1440 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1441 |
if ( !empty( $res['res'] ) ) {
|
1442 |
$result = json_decode($res['res'], true);
|
1443 |
if (isset($result['code'])) {
|
@@ -1461,17 +1035,11 @@ if (!class_exists('dbr_route')) {
|
|
1461 |
if ( isset($setting['option_value']) ) {
|
1462 |
dbr_database::db_update('options', array('option_value' => dbr_helper::pack_setting( $this->setting ) ), array('option_name' => 'wpadm_backup_dropbox-setting') ) ;
|
1463 |
}
|
1464 |
-
dbr_helper::setCommand('restore-backup',
|
1465 |
-
dbr_helper::setCommand('settings-plugin', $this->setting );
|
1466 |
-
$backup_dir = DROPBOX_BACKUP_DIR_BACKUP;
|
1467 |
-
if (isset($this->setting['backup_folder']) && !empty($this->setting['backup_folder'])) {
|
1468 |
-
$backup_dir = $this->setting['backup_folder'];
|
1469 |
-
}
|
1470 |
-
dbr_helper::setCommand('backup-folder', $backup_dir );
|
1471 |
echo json_encode(array('result' => 'work'));
|
1472 |
} catch(Exception $e) {
|
1473 |
dbr_log::log($e->getMessage());
|
1474 |
-
dbr_helper::setCommand('result-restore', array('name' =>
|
1475 |
}
|
1476 |
}
|
1477 |
}
|
@@ -1481,21 +1049,24 @@ if (!class_exists('dbr_route')) {
|
|
1481 |
private function parsMethod()
|
1482 |
{
|
1483 |
if ( isset($_POST['method']) ) {
|
1484 |
-
$this->setting_restore = dbr_helper::getCommand('restore-backup');
|
1485 |
try {
|
1486 |
dbr_helper::mkdir(DBP_PATH_TMP);
|
1487 |
if (!dbr_helper::is_work() || in_array($_POST['method'], $this->method_access ) ) {
|
1488 |
if (isset($_POST['key'])) {
|
1489 |
-
|
1490 |
-
|
1491 |
-
$
|
1492 |
-
|
|
|
|
|
|
|
|
|
1493 |
if (file_exists($backup_dir . '/local-key')) {
|
1494 |
$key_values = dbr_helper::unpack_setting( @file_get_contents($backup_dir . '/local-key') );
|
1495 |
}
|
1496 |
if ($_POST['key'] == @$this->setting['restore-key'] || ( isset($key_values['key']) && $_POST['key'] == $key_values['key'] ) ) {
|
1497 |
$methods = new dbr_methods();
|
1498 |
-
$method =
|
1499 |
if (method_exists($methods, $method)) {
|
1500 |
if ($_POST['method'] != 'wpadm_logs') {
|
1501 |
if (file_exists(DBP_PATH_TMP . '/result-restore')) {
|
@@ -1520,24 +1091,12 @@ if (!class_exists('dbr_route')) {
|
|
1520 |
|
1521 |
if (stripos($res_api['res'], 'mod_security') !== false || dbr_helper::modSecureInstalled() ) {
|
1522 |
dbr_helper::is_work(time(), 'start');
|
1523 |
-
|
1524 |
-
|
1525 |
-
dbr_helper::setCommand('mod_security', true);
|
1526 |
}
|
1527 |
}
|
1528 |
} else {
|
1529 |
dbr_helper::is_work(time(), 'start');
|
1530 |
}
|
1531 |
-
if ($_POST['method'] != 'wpadm_logs') {
|
1532 |
-
dbr_database::inc_wp_config();
|
1533 |
-
include 'constant.php';
|
1534 |
-
$setting = dbr_database::db_get('options', array('option_value'), array('option_name' => 'wpadm_backup_dropbox-setting'), 1);
|
1535 |
-
$this->setting = dbr_helper::unpack_setting( $setting['option_value'] );
|
1536 |
-
$backup_dir = DROPBOX_BACKUP_DIR_BACKUP;
|
1537 |
-
if (isset($this->setting['backup_folder']) && !empty($this->setting['backup_folder'])) {
|
1538 |
-
$backup_dir = $this->setting['backup_folder'];
|
1539 |
-
}
|
1540 |
-
}
|
1541 |
$methods->$method();
|
1542 |
if (!isset($_POST['type-backup'])) {
|
1543 |
dbr_helper::is_work(time(), 'finish');
|
@@ -1560,18 +1119,8 @@ if (!class_exists('dbr_route')) {
|
|
1560 |
}
|
1561 |
|
1562 |
|
1563 |
-
function error_handler($errno, $errstr, $errfile, $errline, array $errcontext)
|
1564 |
-
{
|
1565 |
-
// error was suppressed with the @-operator
|
1566 |
-
if (0 === error_reporting()) {
|
1567 |
-
return false;
|
1568 |
-
}
|
1569 |
-
if (!(error_reporting() & $errno)) {
|
1570 |
-
return false;
|
1571 |
-
}
|
1572 |
|
1573 |
-
|
1574 |
-
}
|
1575 |
/**
|
1576 |
* json encode
|
1577 |
*
|
@@ -1615,4 +1164,4 @@ if (!class_exists('dbr_route')) {
|
|
1615 |
}
|
1616 |
|
1617 |
new dbr_route();
|
1618 |
-
}
|
13 |
}
|
14 |
}
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
if (!class_exists('dbr_gui')) {
|
18 |
class dbr_gui {
|
52 |
self::$db_params = $db_params;
|
53 |
if (isset($pr[1])) {
|
54 |
self::$db_prefix = $pr[1];
|
55 |
+
}
|
56 |
} else {
|
57 |
self::$db_params = $configs;
|
58 |
$db_params = self::$db_params;
|
68 |
//include ABSPATH . 'wp-config.php';
|
69 |
self::getWpMysqlParams();
|
70 |
if ( !defined('WP_CONTENT_DIR') )
|
71 |
+
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
|
72 |
|
73 |
if (function_exists('mysqli_connect')) {
|
74 |
self::$is_mysqli = true;
|
87 |
}
|
88 |
} else {
|
89 |
if (self::$is_mysqli) {
|
90 |
+
self::$connect = mysqli_connect(self::$db_params['host'], self::$db_params['user'], self::$db_params['password']) or die(mysqli_error());
|
91 |
mysqli_set_charset(self::$connect, self::$db_params['charset']) or die(mysqli_error());
|
92 |
mysqli_select_db(self::$connect, self::$db_params['db']) or die(mysqli_error());
|
93 |
} else {
|
94 |
+
self::$connect = @mysql_connect(self::$db_params['host'], self::$db_params['user'], self::$db_params['password']) or die(mysql_error());
|
95 |
mysql_set_charset(self::$db_params['charset'], self::$connect) or die(mysql_error());
|
96 |
mysql_select_db(self::$db_params['db'], self::$connect) or die(mysql_error());
|
97 |
}
|
363 |
class dbr_helper {
|
364 |
|
365 |
private static $cron_is_work = 90;
|
366 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
367 |
public static function modSecureInstalled()
|
368 |
{
|
369 |
+
ob_start();
|
370 |
+
phpinfo(INFO_MODULES);
|
371 |
+
$contents = ob_get_clean();
|
|
|
|
|
|
|
372 |
return strpos($contents, 'mod_security') !== false;
|
373 |
}
|
374 |
|
429 |
if (isset($site_url['option_value'])) {
|
430 |
$name_running_backup = str_replace("http://", '', $site_url['option_value']);
|
431 |
$name_running_backup = str_replace("https://", '', $name_running_backup);
|
432 |
+
$name_running_backup = preg_replace("|\W|", "_", $name_running_backup);
|
433 |
}
|
434 |
return $name_running_backup;
|
435 |
}
|
442 |
@unlink(DBP_PATH_TMP . '/' . $file);
|
443 |
}
|
444 |
}
|
|
|
445 |
// @rmdir(DBP_PATH_TMP);
|
446 |
}
|
447 |
}
|
448 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
449 |
public static function unpack_setting($str)
|
450 |
{
|
451 |
return unserialize( base64_decode( $str ) );
|
452 |
}
|
453 |
+
|
454 |
public static function pack_setting($str)
|
455 |
{
|
456 |
return base64_encode( serialize( $str ) );
|
458 |
|
459 |
public static function pack($data)
|
460 |
{
|
461 |
+
return base64_encode( json_encode( $data ) );
|
|
|
|
|
|
|
462 |
}
|
463 |
|
464 |
public static function unpack($data)
|
580 |
}
|
581 |
}
|
582 |
|
|
|
|
|
583 |
if ( !class_exists('dbr_methods') ) {
|
584 |
class dbr_methods{
|
585 |
|
601 |
$json['data'] = dbr_helper::getCommand('result-restore');
|
602 |
}
|
603 |
}
|
|
|
|
|
|
|
|
|
|
|
604 |
echo json_encode ( $json );
|
605 |
exit;
|
606 |
}
|
620 |
$this->main = dbr_helper::unpack_setting( $setting['option_value'] );
|
621 |
}
|
622 |
|
623 |
+
$backup_dir = DROPBOX_BACKUP_DIR_BACKUP;
|
624 |
if (isset($this->main['backup_folder']) && !empty($this->main['backup_folder'])) {
|
625 |
$backup_dir = $this->main['backup_folder'];
|
626 |
}
|
682 |
$arr_sql = dbr_helper::getCommand('sql-restore');
|
683 |
if ( !isset( $arr_sql[md5($sql)] ) || $arr_sql === false ) {
|
684 |
$ress = dbr_database::query( $sql );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
685 |
$arr_sql[md5($sql)] = 1;
|
686 |
dbr_helper::setCommand('sql-restore', $arr_sql);
|
687 |
}
|
688 |
}
|
689 |
if (isset($ress) && ( $ress === false || !empty( dbr_database::$error ) ) ) {
|
690 |
if (stripos(dbr_database::$error, 'duplicate entry') === false) {
|
691 |
+
dbr_helper::setError('MySQL Error: ' . dbr_database::$error );
|
692 |
break;
|
693 |
}
|
694 |
+
};
|
695 |
$sql = "";
|
696 |
}
|
697 |
}
|
718 |
if(strpos($d, ".zip") !== false) {
|
719 |
$this->files_resotre[$d] = $this->dir_backup . "/$d";
|
720 |
}
|
|
|
|
|
|
|
|
|
721 |
if(strpos($d, ".md5") !== false) {
|
722 |
$file_md5 = $this->dir_backup . "/$d";
|
723 |
}
|
745 |
|
746 |
}
|
747 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
748 |
private function restoreFiles()
|
749 |
{
|
750 |
+
include 'pclzip.lib.php';
|
751 |
$files = dbr_helper::getCommand('files-list-retore');
|
752 |
if ($files) {
|
753 |
dbr_helper::is_work(time(), 'start');
|
788 |
dbr_helper::setCommand('zip-config', null);
|
789 |
}
|
790 |
}
|
|
|
|
|
|
|
|
|
791 |
foreach($files as $f => $file) {
|
792 |
$extract_files = dbr_helper::getCommand('extract-files-restore');
|
793 |
if (!isset($extract_files[$f])) {
|
794 |
dbr_log::log('Data will be decompressed of ' . basename($file));
|
795 |
if (strpos($f, '.zip')) {
|
796 |
if (file_exists($file) && filesize($file) > 0) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
797 |
$archive = new PclZip($file);
|
798 |
$unzip = $archive->extract(
|
799 |
PCLZIP_CB_PRE_EXTRACT, 'dbr_extract_func',
|
816 |
if ($unzip == 0) {
|
817 |
dbr_helper::setError("Error during extracting of database config from archive: " . $archive->errorInfo(true) );
|
818 |
}
|
819 |
+
$db_params = array(
|
820 |
+
'password' => 'DB_PASSWORD',
|
821 |
+
'db' => 'DB_NAME',
|
822 |
+
'user' => 'DB_USER',
|
823 |
+
'host' => 'DB_HOST',
|
824 |
+
'charset' => 'DB_CHARSET',
|
825 |
+
);
|
826 |
+
|
827 |
+
$r = "/define\([\s]{0,}['\"]{1}(.*)['\"]{1}[\s]{0,},[\s]{0,}['\"]{1}(.*)['\"]{1}[\s]{0,}\)/";
|
828 |
+
$config = @file_get_contents(ABSPATH . "wp-config.php");
|
829 |
+
preg_match_all($r, $config, $m);
|
830 |
+
$params = array_combine( $m[1], $m[2] );
|
831 |
+
$change_config = false;
|
832 |
+
foreach($db_params as $k => $p) {
|
833 |
+
$db_params[$k] = $params[$p];
|
834 |
+
if (dbr_database::$db_params[$k] != $db_params[$k]) {
|
835 |
+
$change_config = true;
|
836 |
+
}
|
837 |
+
}
|
838 |
+
if ($change_config) {
|
839 |
+
dbr_log::log('Configure file "wp-config.php" was started');
|
840 |
+
$patterns = array();
|
841 |
+
$patterns[0] = "/define\('DB_PASSWORD', '(.*)'\)/";
|
842 |
+
$patterns[1] = "/define\('DB_NAME', '(.*)'\)/";
|
843 |
+
$patterns[2] = "/define\('DB_USER', '(.*)'\)/";
|
844 |
+
$patterns[3] = "/define\('DB_HOST', '(.*)'\)/";
|
845 |
+
$patterns[4] = "/define\('DB_CHARSET', '(.*)'\)/";
|
846 |
+
|
847 |
+
$replacements = array();
|
848 |
+
$replacements[0] = "define('DB_PASSWORD', '" . dbr_database::$db_params['password'] . "')";
|
849 |
+
$replacements[1] = "define('DB_NAME', '" . dbr_database::$db_params['db'] . "')";
|
850 |
+
$replacements[2] = "define('DB_USER', '" . dbr_database::$db_params['user'] . "')";
|
851 |
+
$replacements[3] = "define('DB_HOST', '" . dbr_database::$db_params['host'] . "')";
|
852 |
+
$replacements[4] = "define('DB_CHARSET', '" . dbr_database::$db_params['charset'] . "')";
|
853 |
+
|
854 |
+
$config = preg_replace($patterns, $replacements, $config);
|
855 |
+
|
856 |
+
$config = preg_replace("/table_prefix[\s]{0,}=[\s]{0,}[\"']{1}(.*)[\"']{1}/U", "table_prefix = '" . dbr_database::$db_prefix . "'", $config);
|
857 |
+
|
858 |
+
$write = @file_put_contents(ABSPATH . "wp-config.php", $config);
|
859 |
+
|
860 |
+
if (!$write) {
|
861 |
+
dbr_helper::setError( "File 'wp-config.php' is not writable" );
|
862 |
+
}
|
863 |
+
dbr_log::log('Configure file "wp-config.php" was successfully');
|
864 |
+
}
|
865 |
}
|
866 |
if ($zip_database && strpos($file, $zip_database[2]) !== false) {
|
867 |
$archive = new PclZip($file);
|
879 |
} else {
|
880 |
dbr_helper::setError('File (' . $file . ') for restoring wasn\'t found or file size is 0 byte');
|
881 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
882 |
}
|
883 |
}
|
884 |
}
|
912 |
if ($file_list === false) {
|
913 |
dbr_log::log('Getting list of files from Dropbox');
|
914 |
$files = $dropbox->listing("$folder_project/$name_backup");
|
|
|
|
|
|
|
915 |
dbr_helper::setCommand('download-with-dropbox-restore', $files, 'file-list');
|
916 |
dbr_helper::is_work(time(), 'start');
|
917 |
} else {
|
941 |
}
|
942 |
$md5 = glob($this->dir_backup . '/*.md5');
|
943 |
if (count( $md5 ) == 0) {
|
944 |
+
dbr_helper::setError( "File list from MD5 file wasn\'t loaded. Please, check folder and folder rights " . $this->dir_backup . " and MD5 file in this folder with file rights");
|
945 |
}
|
946 |
dbr_helper::setCommand('download-with-dropbox-restore', true, 'success');
|
947 |
return true;
|
964 |
if (!defined('ABSPATH')) {
|
965 |
define('ABSPATH', dirname(__FILE__) . '/../../../../');
|
966 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
967 |
if (!defined('DBP_PATH')) {
|
968 |
define('DBP_PATH', dirname(__FILE__) . '/../');
|
969 |
}
|
984 |
|
985 |
function __construct()
|
986 |
{
|
|
|
|
|
|
|
|
|
987 |
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
|
988 |
if ( !isset($_POST['name']) ) {
|
989 |
$this->parsMethod();
|
990 |
+
} elseif( isset($_POST['name']) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
991 |
|
992 |
+
dbr_helper::clearTMP();
|
993 |
+
dbr_database::inc_wp_config();
|
994 |
+
$setting = dbr_database::db_get('options', array('option_value'), array('option_name' => 'wpadm_backup_dropbox-setting'), 1);
|
995 |
+
if (isset($setting['option_value'])) {
|
996 |
+
$this->setting = dbr_helper::unpack_setting( $setting['option_value'] );
|
997 |
+
}
|
998 |
+
$this->setting['restore-key'] = md5( time() . microtime() . __FILE__);
|
999 |
+
include 'constant.php';
|
1000 |
+
$plugin = $this->parsePlugin('/dropbox-backup');
|
1001 |
+
$plugin_name = 'dropbox-backup';
|
1002 |
+
$version = '1.0';
|
1003 |
+
if (isset($plugin['/dropbox-backup']['Version'])) {
|
1004 |
+
$version = $plugin['/dropbox-backup']['Version'];
|
1005 |
+
} else{
|
1006 |
+
$plugin = $this->parsePlugin('/dropbox-backup-pro');
|
1007 |
+
if (isset($plugin['/dropbox-backup-pro']['Version'])) {
|
1008 |
+
$version = $plugin['/dropbox-backup-pro']['Version'];
|
1009 |
+
$plugin_name = 'dropbox-backup-pro';
|
1010 |
+
}
|
1011 |
+
}
|
1012 |
+
$data = array('actApi' => 'setPluginCode', $plugin_name . '_request' => array('action' => 'restore', 'site' => SITE_HOME, 'pl' => $plugin_name, 'key' => $this->setting['restore-key'], 'pl_v' => $version, ) );
|
1013 |
+
$res = dbr_api::post(WPADM_URL_BASE . 'api/', $data);
|
1014 |
+
try {
|
1015 |
if ( !empty( $res['res'] ) ) {
|
1016 |
$result = json_decode($res['res'], true);
|
1017 |
if (isset($result['code'])) {
|
1035 |
if ( isset($setting['option_value']) ) {
|
1036 |
dbr_database::db_update('options', array('option_value' => dbr_helper::pack_setting( $this->setting ) ), array('option_name' => 'wpadm_backup_dropbox-setting') ) ;
|
1037 |
}
|
1038 |
+
dbr_helper::setCommand('restore-backup', $_POST);
|
|
|
|
|
|
|
|
|
|
|
|
|
1039 |
echo json_encode(array('result' => 'work'));
|
1040 |
} catch(Exception $e) {
|
1041 |
dbr_log::log($e->getMessage());
|
1042 |
+
dbr_helper::setCommand('result-restore', array('name' => $_POST['name'], 'result' => 'error', 'message' => $e->getMessage() ) );
|
1043 |
}
|
1044 |
}
|
1045 |
}
|
1049 |
private function parsMethod()
|
1050 |
{
|
1051 |
if ( isset($_POST['method']) ) {
|
|
|
1052 |
try {
|
1053 |
dbr_helper::mkdir(DBP_PATH_TMP);
|
1054 |
if (!dbr_helper::is_work() || in_array($_POST['method'], $this->method_access ) ) {
|
1055 |
if (isset($_POST['key'])) {
|
1056 |
+
dbr_database::inc_wp_config();
|
1057 |
+
include 'constant.php';
|
1058 |
+
$setting = dbr_database::db_get('options', array('option_value'), array('option_name' => 'wpadm_backup_dropbox-setting'), 1);
|
1059 |
+
$this->setting = dbr_helper::unpack_setting( $setting['option_value'] );
|
1060 |
+
$backup_dir = DROPBOX_BACKUP_DIR_BACKUP;
|
1061 |
+
if (isset($this->setting['backup_folder']) && !empty($this->setting['backup_folder'])) {
|
1062 |
+
$backup_dir = $this->setting['backup_folder'];
|
1063 |
+
}
|
1064 |
if (file_exists($backup_dir . '/local-key')) {
|
1065 |
$key_values = dbr_helper::unpack_setting( @file_get_contents($backup_dir . '/local-key') );
|
1066 |
}
|
1067 |
if ($_POST['key'] == @$this->setting['restore-key'] || ( isset($key_values['key']) && $_POST['key'] == $key_values['key'] ) ) {
|
1068 |
$methods = new dbr_methods();
|
1069 |
+
$method = $_POST['method']. '_method';
|
1070 |
if (method_exists($methods, $method)) {
|
1071 |
if ($_POST['method'] != 'wpadm_logs') {
|
1072 |
if (file_exists(DBP_PATH_TMP . '/result-restore')) {
|
1091 |
|
1092 |
if (stripos($res_api['res'], 'mod_security') !== false || dbr_helper::modSecureInstalled() ) {
|
1093 |
dbr_helper::is_work(time(), 'start');
|
1094 |
+
dbr_helper::setError('Apache module \'mod_security\' is active and affected on your website. For successfully restoring of website please switch it temporary off.');
|
|
|
|
|
1095 |
}
|
1096 |
}
|
1097 |
} else {
|
1098 |
dbr_helper::is_work(time(), 'start');
|
1099 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1100 |
$methods->$method();
|
1101 |
if (!isset($_POST['type-backup'])) {
|
1102 |
dbr_helper::is_work(time(), 'finish');
|
1119 |
}
|
1120 |
|
1121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1122 |
|
1123 |
+
|
|
|
1124 |
/**
|
1125 |
* json encode
|
1126 |
*
|
1164 |
}
|
1165 |
|
1166 |
new dbr_route();
|
1167 |
+
}
|
readme.txt
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
=== Backup & Restore Dropbox ===
|
2 |
Plugin Name: Backup & Restore Dropbox
|
3 |
-
Version: 1.
|
4 |
Donate link: http://www.wpadm.com/donate
|
5 |
URI: http://www.wpadm.com/dropbox-backup
|
6 |
Tags: dropbox, backup, dropbox backup, database, file, full backup, manage, sicherung, database backup, file backup, page backup, page, web, web backup, web page, synchronize, clone, duplicate, move, web page backup, site, site backup, back up, cloud, Cloud Files, cloud backup, db backup, dump, german, migrate, multisite, German, schedule, storage, time, upload, data bank, zip, archive, backups, restore, db, recover, recovery, restoration, wp backup, wordpress backup, wordpress backup to dropbox, plugin wordpress backup, wpadm, wpadm.com, website, website backup, website back up, wp backup, wordpress backup, scheduled backup, backup scheduler, tool, backup tool
|
7 |
Requires at least: 3.9
|
8 |
-
Tested up to: 4.7
|
9 |
Stable tag: trunk
|
10 |
License: GPLv2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
@@ -486,8 +486,7 @@ Please, keep your Dropbox Backup and Restore plugin up-to-date.
|
|
486 |
|
487 |
**Rev.** / **Description** <br />
|
488 |
|
489 |
-
|
490 |
-
@1506495 WordPress backup plugin Dropbox backup & restore, added "exclude/include" files and folder window. Bug fixes.<br />
|
491 |
To restore connect to the database will be also used mysqli or mysql. The database connection type will be selected automatically.<br />
|
492 |
During restoring process: the config file of WordPress wp-config.php will use config of new website configuration to connect to the database.<br />
|
493 |
@1448769 "Dropbox backup & restore" - added tmp folder for library pclzip, deleted files tmp for pclzip<br />
|
1 |
=== Backup & Restore Dropbox ===
|
2 |
Plugin Name: Backup & Restore Dropbox
|
3 |
+
Version: 1.4.8
|
4 |
Donate link: http://www.wpadm.com/donate
|
5 |
URI: http://www.wpadm.com/dropbox-backup
|
6 |
Tags: dropbox, backup, dropbox backup, database, file, full backup, manage, sicherung, database backup, file backup, page backup, page, web, web backup, web page, synchronize, clone, duplicate, move, web page backup, site, site backup, back up, cloud, Cloud Files, cloud backup, db backup, dump, german, migrate, multisite, German, schedule, storage, time, upload, data bank, zip, archive, backups, restore, db, recover, recovery, restoration, wp backup, wordpress backup, wordpress backup to dropbox, plugin wordpress backup, wpadm, wpadm.com, website, website backup, website back up, wp backup, wordpress backup, scheduled backup, backup scheduler, tool, backup tool
|
7 |
Requires at least: 3.9
|
8 |
+
Tested up to: 4.7
|
9 |
Stable tag: trunk
|
10 |
License: GPLv2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
486 |
|
487 |
**Rev.** / **Description** <br />
|
488 |
|
489 |
+
WordPress backup plugin Dropbox backup & restore, added "exclude/include" files and folder window. Bug fixes.<br />
|
|
|
490 |
To restore connect to the database will be also used mysqli or mysql. The database connection type will be selected automatically.<br />
|
491 |
During restoring process: the config file of WordPress wp-config.php will use config of new website configuration to connect to the database.<br />
|
492 |
@1448769 "Dropbox backup & restore" - added tmp folder for library pclzip, deleted files tmp for pclzip<br />
|
template/advantage-plugin.php
CHANGED
@@ -1,108 +1,59 @@
|
|
1 |
-
|
2 |
-
<
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
<div class="inline">
|
11 |
-
<img src="<?php echo ( !isset($repeat_advantage) ? plugins_url('/template/ok-icon.png', dirname(__FILE__)) : plugins_url('/template/ico_ok.png', dirname(__FILE__) ) );?>" title="" alt="" />
|
12 |
-
</div>
|
13 |
-
<div class="inline">
|
14 |
-
<span class="text">
|
15 |
-
<?php _e('Automated Dropbox backup','dropbox-backup') ; ?> <?php echo ( !isset($repeat_advantage) ? '' : '<br />' ) ?>
|
16 |
-
<?php _e('(Scheduled backup tasks)','dropbox-backup')?>
|
17 |
-
</span>
|
18 |
-
</div>
|
19 |
</li>
|
20 |
<li>
|
21 |
-
<
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
<span class="text">
|
26 |
-
<?php _e('Automated Local backup','dropbox-backup') ; ?> <?php echo ( !isset($repeat_advantage) ? '' : '<br />' ) ?>
|
27 |
-
<?php _e('(Scheduled backup tasks)','dropbox-backup')?>
|
28 |
-
|
29 |
-
</span>
|
30 |
-
</div>
|
31 |
</li>
|
32 |
<li>
|
33 |
-
<
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
<span class="text">
|
38 |
-
<?php _e('Backup Status E-Mail Reporting','dropbox-backup') ; ?>
|
39 |
-
</span>
|
40 |
-
</div>
|
41 |
</li>
|
42 |
<li>
|
43 |
-
<
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
<span class="text">
|
48 |
-
<?php _e('Online Service "Backup Website Manager"','dropbox-backup') ; ?> <?php echo ( !isset($repeat_advantage) ? '' : '<br />' ) ?>
|
49 |
-
<?php _e('(Copy, Clone or Migrate of websites)','dropbox-backup')?>
|
50 |
-
</span>
|
51 |
-
</div>
|
52 |
</li>
|
53 |
<li>
|
54 |
-
<
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
<span class="text">
|
59 |
-
<?php _e('One Year Free Updates for PRO version','dropbox-backup') ; ?>
|
60 |
-
</span>
|
61 |
-
</div>
|
62 |
</li>
|
63 |
<li>
|
64 |
-
<
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
<span class="text">
|
69 |
-
<?php _e('One Year Priority support','dropbox-backup') ; ?>
|
70 |
-
</span>
|
71 |
-
</div>
|
72 |
</li>
|
73 |
</ul>
|
74 |
</div>
|
75 |
-
<div class="
|
76 |
-
|
77 |
-
<
|
78 |
-
|
79 |
-
|
80 |
-
<?php
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
<div class="block-pay <?php echo (!isset($repeat_advantage) ? '' : 'repeat_advantage' ); ?>" style="">
|
90 |
-
<?php if (!isset($repeat_advantage)) {?>
|
91 |
-
<form action="<?php echo esc_url( WPADM_URL_PRO_VERSION ); ?>api/" method="post" id="dropbox_pro_form" name="dropbox_pro_form" >
|
92 |
-
|
93 |
-
<input type="hidden" value="<?php echo home_url();?>" name="site">
|
94 |
-
<input type="hidden" value="<?php echo 'proBackupPay'?>" name="actApi">
|
95 |
-
<input type="hidden" value="<?php echo get_option('admin_email');?>" name="email">
|
96 |
-
<input type="hidden" value="<?php echo 'dropbox-backup';?>" name="plugin">
|
97 |
-
<input type="hidden" value="<?php echo (DRBBACKUP_MULTI) ? network_admin_url("admin.php?page=wpadm_wp_full_backup_dropbox&pay=success") : admin_url("admin.php?page=wpadm_wp_full_backup_dropbox&pay=success"); ?>" name="success_url">
|
98 |
-
<input type="hidden" value="<?php echo (DRBBACKUP_MULTI) ? network_admin_url("admin.php?page=wpadm_wp_full_backup_dropbox&pay=cancel") : admin_url("admin.php?page=wpadm_wp_full_backup_dropbox&pay=cancel"); ?>" name="cancel_url">
|
99 |
-
<input type="submit" class="backup_button" value="<?php _e('Get PRO','dropbox-backup');?>">
|
100 |
-
</form>
|
101 |
-
<?php } else {
|
102 |
-
?>
|
103 |
-
<input type="button" class="backup_button" onclick="document.dropbox_pro_form.submit();" value="<?php _e('Get PRO','dropbox-backup');?>">
|
104 |
-
<?php
|
105 |
-
}?>
|
106 |
</div>
|
107 |
</div>
|
108 |
|
1 |
+
<div class="inline" style="width: 60%">
|
2 |
+
<span style="font-size:16px;">
|
3 |
+
<?php _e('Use Professional version of "Dropbox backup and restore" plugin and get:','dropbox-backup') ; ?>
|
4 |
+
</span>
|
5 |
+
<ul class="list-dropbox-backup-pro">
|
6 |
+
<li><img src="<?php echo plugins_url('/template/ok-icon.png', dirname(__FILE__));?>" title="" alt="" />
|
7 |
+
<span class="text">
|
8 |
+
<?php _e('Automated Dropbox backup (Scheduled backup tasks)','dropbox-backup') ; ?>
|
9 |
+
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
</li>
|
11 |
<li>
|
12 |
+
<img src="<?php echo plugins_url('/template/ok-icon.png', dirname(__FILE__));?>" title="" alt="" />
|
13 |
+
<span class="text">
|
14 |
+
<?php _e('Automated Local backup (Scheduled backup tasks)','dropbox-backup') ; ?>
|
15 |
+
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
</li>
|
17 |
<li>
|
18 |
+
<img src="<?php echo plugins_url('/template/ok-icon.png', dirname(__FILE__));?>" title="" alt="" />
|
19 |
+
<span class="text">
|
20 |
+
<?php _e('Backup Status E-Mail Reporting','dropbox-backup') ; ?>
|
21 |
+
</span>
|
|
|
|
|
|
|
|
|
22 |
</li>
|
23 |
<li>
|
24 |
+
<img src="<?php echo plugins_url('/template/ok-icon.png', dirname(__FILE__));?>" title="" alt="" />
|
25 |
+
<span class="text">
|
26 |
+
<?php _e('Online Service "Backup Website Manager" (Copy, Clone or Migrate of websites)','dropbox-backup') ; ?>
|
27 |
+
</span>
|
|
|
|
|
|
|
|
|
|
|
28 |
</li>
|
29 |
<li>
|
30 |
+
<img src="<?php echo plugins_url('/template/ok-icon.png', dirname(__FILE__));?>" title="" alt="" />
|
31 |
+
<span class="text">
|
32 |
+
<?php _e('One Year Free Updates for PRO version','dropbox-backup') ; ?>
|
33 |
+
</span>
|
|
|
|
|
|
|
|
|
34 |
</li>
|
35 |
<li>
|
36 |
+
<img src="<?php echo plugins_url('/template/ok-icon.png', dirname(__FILE__));?>" title="" alt="" />
|
37 |
+
<span class="text">
|
38 |
+
<?php _e('One Year Priority support','dropbox-backup') ; ?>
|
39 |
+
</span>
|
|
|
|
|
|
|
|
|
40 |
</li>
|
41 |
</ul>
|
42 |
</div>
|
43 |
+
<div class="inline-right" style="margin-top: 0;">
|
44 |
+
<div class="image-dropbox-pro" onclick="document.dropbox_pro_form.submit();">
|
45 |
+
<img src="<?php echo plugins_url('/template/dropbox_pro_logo_box1.png', dirname(__FILE__));?>" title="<?php _e('Get PRO version','dropbox-backup');?>" alt="<?php _e('Get PRO version','dropbox-backup'); ?>">
|
46 |
+
</div>
|
47 |
+
<div style="margin-top:26%; float: left; margin-left: 20px; margin-right: 15px;">
|
48 |
+
<form action="<?php echo WPADM_URL_PRO_VERSION; ?>api/" method="post" id="dropbox_pro_form" name="dropbox_pro_form" >
|
49 |
+
<input type="hidden" value="<?php echo home_url();?>" name="site">
|
50 |
+
<input type="hidden" value="<?php echo 'proBackupPay'?>" name="actApi">
|
51 |
+
<input type="hidden" value="<?php echo get_option('admin_email');?>" name="email">
|
52 |
+
<input type="hidden" value="<?php echo 'dropbox-backup';?>" name="plugin">
|
53 |
+
<input type="hidden" value="<?php echo admin_url("admin.php?page=wpadm_wp_full_backup_dropbox&pay=success"); ?>" name="success_url">
|
54 |
+
<input type="hidden" value="<?php echo admin_url("admin.php?page=wpadm_wp_full_backup_dropbox&pay=cancel"); ?>" name="cancel_url">
|
55 |
+
<input type="submit" class="backup_button" value="<?php _e('Get PRO','dropbox-backup');?>">
|
56 |
+
</form>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
</div>
|
58 |
</div>
|
59 |
|
template/css/admin-style-wpadm.css
CHANGED
@@ -1,27 +1,4 @@
|
|
1 |
|
2 |
-
.cfContentContainer {
|
3 |
-
color:#fff;
|
4 |
-
}
|
5 |
-
.inline.repeat_advantage {
|
6 |
-
margin-top:15px;
|
7 |
-
}
|
8 |
-
.inline.repeat_advantage .backup_button {
|
9 |
-
box-shadow: 0px 0px 15px rgba(255,255,255,1);
|
10 |
-
}
|
11 |
-
.list-dropbox-backup-pro.repeat_advantage li {
|
12 |
-
margin-left: 0px;
|
13 |
-
clear:both;
|
14 |
-
}
|
15 |
-
.list-dropbox-backup-pro.repeat_advantage li img {
|
16 |
-
margin-top: 3px;
|
17 |
-
-webkit-filter: drop-shadow(2px 2px 2px rgba(255,255,255,0.5));
|
18 |
-
-ms-filter: "progid:DXImageTransform.Microsoft.Dropshadow(OffX=2, OffY=2, Color='#fff')";
|
19 |
-
filter: "progid:DXImageTransform.Microsoft.Dropshadow(OffX=2, OffY=2, Color='#fff')";
|
20 |
-
}
|
21 |
-
|
22 |
-
.cfTabsContainer:hover .hover-title {
|
23 |
-
text-decoration:underline;
|
24 |
-
}
|
25 |
#wp-cron-enable {
|
26 |
position: relative;
|
27 |
}
|
@@ -57,24 +34,6 @@
|
|
57 |
margin-top: 20px;
|
58 |
color:#fff;
|
59 |
}
|
60 |
-
.inline-right {
|
61 |
-
float:right;
|
62 |
-
}
|
63 |
-
.inline {
|
64 |
-
float:left;
|
65 |
-
}
|
66 |
-
|
67 |
-
.block-pay {
|
68 |
-
margin-top: 26%;
|
69 |
-
float: left;
|
70 |
-
margin-left: 20px;
|
71 |
-
margin-right: 15px;
|
72 |
-
}
|
73 |
-
|
74 |
-
.inline-right, .inline {
|
75 |
-
margin-top:10px;
|
76 |
-
margin-left:10px;
|
77 |
-
}
|
78 |
.log-dropbox {
|
79 |
background-repeat: no-repeat; background-position:center;
|
80 |
background-color: #fff;
|
@@ -950,31 +909,15 @@ text-align: center; margin-top: 10px;
|
|
950 |
}
|
951 |
|
952 |
.cfTabsContainer.wpadm-setting-box {
|
953 |
-
width: 28%; float: left; margin-left: 10px; padding-bottom: 0px; padding-top: 0px;
|
954 |
}
|
955 |
|
956 |
@media only screen and (max-width: 1345px) {
|
957 |
-
.cfTabsContainer.wpadm-setting-box {
|
958 |
-
width: 97%;
|
959 |
-
float:none;
|
960 |
-
margin-left: 0px;
|
961 |
-
}
|
962 |
-
|
963 |
-
|
964 |
-
.block-pay.repeat_advantage {
|
965 |
-
margin-top: 10px;
|
966 |
-
width: 90%;
|
967 |
-
text-align: center;
|
968 |
-
}
|
969 |
-
.inline.repeat_advantage {
|
970 |
-
float:none;
|
971 |
-
}
|
972 |
-
.block-advantage {
|
973 |
-
width:100%;
|
974 |
-
}
|
975 |
-
.inline-right {
|
976 |
-
float:left;
|
977 |
-
}
|
978 |
}
|
979 |
|
980 |
/*default style */
|
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
#wp-cron-enable {
|
3 |
position: relative;
|
4 |
}
|
34 |
margin-top: 20px;
|
35 |
color:#fff;
|
36 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
.log-dropbox {
|
38 |
background-repeat: no-repeat; background-position:center;
|
39 |
background-color: #fff;
|
909 |
}
|
910 |
|
911 |
.cfTabsContainer.wpadm-setting-box {
|
912 |
+
width: 28%; float: left; margin-left: 10px; padding-bottom: 0px; padding-top: 0px;
|
913 |
}
|
914 |
|
915 |
@media only screen and (max-width: 1345px) {
|
916 |
+
.cfTabsContainer.wpadm-setting-box {
|
917 |
+
width: 97%;
|
918 |
+
float:none;
|
919 |
+
margin-left: 0px;
|
920 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
921 |
}
|
922 |
|
923 |
/*default style */
|
template/css/tool-bar.css
CHANGED
@@ -3,27 +3,18 @@
|
|
3 |
/*background-image: ;*/
|
4 |
}
|
5 |
|
6 |
-
.block-advantage {
|
7 |
-
width: 65%;
|
8 |
-
}
|
9 |
-
|
10 |
.list-dropbox-backup-pro {
|
11 |
margin-top:10px;
|
12 |
margin-bottom:0;
|
13 |
-
|
14 |
}
|
15 |
.list-dropbox-backup-pro li {
|
16 |
margin-bottom: 0;
|
17 |
font-size:14px;
|
18 |
-
clear:both;
|
19 |
margin-left:35px;
|
20 |
}
|
21 |
.list-dropbox-backup-pro .text {
|
22 |
line-height: 25px;
|
23 |
}
|
24 |
-
.list-dropbox-backup-pro li .inline {
|
25 |
-
margin-top:0px;
|
26 |
-
}
|
27 |
.image-dropbox-pro {
|
28 |
width: 183px;
|
29 |
height: 187px;
|
@@ -79,23 +70,13 @@ button.backup_button:disabled, button.backup_button:disabled:hover {
|
|
79 |
background: #9eb7d8;
|
80 |
}
|
81 |
|
82 |
-
|
83 |
-
float:
|
84 |
}
|
85 |
-
|
86 |
-
|
87 |
-
margin-top: 6%;
|
88 |
-
float: left;
|
89 |
-
margin-left: 20px;
|
90 |
-
margin-right: 15px;
|
91 |
}
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
.block-advantage {
|
96 |
-
width:100%;
|
97 |
-
}
|
98 |
-
.inline-right {
|
99 |
-
float:left;
|
100 |
-
}
|
101 |
}
|
3 |
/*background-image: ;*/
|
4 |
}
|
5 |
|
|
|
|
|
|
|
|
|
6 |
.list-dropbox-backup-pro {
|
7 |
margin-top:10px;
|
8 |
margin-bottom:0;
|
|
|
9 |
}
|
10 |
.list-dropbox-backup-pro li {
|
11 |
margin-bottom: 0;
|
12 |
font-size:14px;
|
|
|
13 |
margin-left:35px;
|
14 |
}
|
15 |
.list-dropbox-backup-pro .text {
|
16 |
line-height: 25px;
|
17 |
}
|
|
|
|
|
|
|
18 |
.image-dropbox-pro {
|
19 |
width: 183px;
|
20 |
height: 187px;
|
70 |
background: #9eb7d8;
|
71 |
}
|
72 |
|
73 |
+
.inline-right {
|
74 |
+
float:right;
|
75 |
}
|
76 |
+
.inline {
|
77 |
+
float:left;
|
|
|
|
|
|
|
|
|
78 |
}
|
79 |
+
.inline-right, .inline {
|
80 |
+
margin-top:10px;
|
81 |
+
margin-left:10px;
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
}
|
template/expsys.php
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
<?php if ( ! defined( 'ABSPATH' ) ) exit; ?>
|
2 |
<?php
|
3 |
$str = '';
|
4 |
foreach($data['sys'] as $key => $value) {
|
@@ -31,10 +30,10 @@
|
|
31 |
</script>
|
32 |
<div class="functions-view">
|
33 |
<div class="title-functions-view" onclick="showView();">
|
34 |
-
<?php echo
|
35 |
</div>
|
36 |
<div class="body-functions-view">
|
37 |
-
<?php echo
|
38 |
</div>
|
39 |
</div>
|
40 |
<?php
|
|
|
1 |
<?php
|
2 |
$str = '';
|
3 |
foreach($data['sys'] as $key => $value) {
|
30 |
</script>
|
31 |
<div class="functions-view">
|
32 |
<div class="title-functions-view" onclick="showView();">
|
33 |
+
<?php echo $str; ?>
|
34 |
</div>
|
35 |
<div class="body-functions-view">
|
36 |
+
<?php echo $functions_need; ?>
|
37 |
</div>
|
38 |
</div>
|
39 |
<?php
|
template/ico_ok.png
DELETED
Binary file
|
template/js/admin-wpadm.js
CHANGED
@@ -10,24 +10,6 @@ function textReplace(text, addStr)
|
|
10 |
{
|
11 |
return text.replace(/([\w])(\'|’)([\w])/gm, "$1$3") + addStr;
|
12 |
}
|
13 |
-
var set_click = '';
|
14 |
-
function setDefaultFolderBackup(dir)
|
15 |
-
{
|
16 |
-
if ( typeof( dir ) == 'object') {
|
17 |
-
id = 'backup_folder';
|
18 |
-
} else {
|
19 |
-
jQuery('#backup_folder').val( decodeURIComponent( dir ) );
|
20 |
-
id = 'clear_backup_folder';
|
21 |
-
}
|
22 |
-
if (set_click != id ) {
|
23 |
-
jQuery('#button-save-folder-backup').off("click");
|
24 |
-
jQuery('#button-save-folder-backup').click(function() {
|
25 |
-
saveSetting(id);
|
26 |
-
});
|
27 |
-
set_click = id;
|
28 |
-
changes_setting = true;
|
29 |
-
}
|
30 |
-
}
|
31 |
|
32 |
var shows_id = ""
|
33 |
var shows_t = ""
|
@@ -112,15 +94,9 @@ function connectFolder(t)
|
|
112 |
}
|
113 |
id = jQuery(divs[i]).attr('data-value');
|
114 |
if (set) {
|
115 |
-
send_checked = unique(send_checked);
|
116 |
if (t.checked) {
|
117 |
-
jQuery("#send-to-" + id).attr('checked', true);
|
118 |
-
send_checked[send_checked.length] = jQuery("#send-to-" + id).val();
|
119 |
} else {
|
120 |
-
k = jQuery.inArray( jQuery("#send-to-" + id).val(), send_checked );
|
121 |
-
if (k >= 0) {
|
122 |
-
send_checked.splice(k,1);
|
123 |
-
}
|
124 |
jQuery("#send-to-" + id).attr('checked', false);
|
125 |
}
|
126 |
}
|
@@ -130,15 +106,9 @@ function connectFolder(t)
|
|
130 |
if (jQuery("#include_" + t_id).length > 0) {
|
131 |
checkboxes = jQuery("#include_" + t_id).find('.checkbox-send');
|
132 |
for(i = 0; i < checkboxes.length; i++) {
|
133 |
-
send_checked = unique(send_checked);
|
134 |
if (t.checked) {
|
135 |
jQuery(checkboxes[i]).attr('checked', true);
|
136 |
-
send_checked[send_checked.length] = jQuery(checkboxes[i]).val();
|
137 |
} else {
|
138 |
-
k = jQuery.inArray( jQuery(checkboxes[i]).val(), send_checked );
|
139 |
-
if (k >= 0) {
|
140 |
-
send_checked.splice(k,1);
|
141 |
-
}
|
142 |
jQuery(checkboxes[i]).attr('checked', false);
|
143 |
}
|
144 |
}
|
10 |
{
|
11 |
return text.replace(/([\w])(\'|’)([\w])/gm, "$1$3") + addStr;
|
12 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
var shows_id = ""
|
15 |
var shows_t = ""
|
94 |
}
|
95 |
id = jQuery(divs[i]).attr('data-value');
|
96 |
if (set) {
|
|
|
97 |
if (t.checked) {
|
98 |
+
jQuery("#send-to-" + id).attr('checked', true);
|
|
|
99 |
} else {
|
|
|
|
|
|
|
|
|
100 |
jQuery("#send-to-" + id).attr('checked', false);
|
101 |
}
|
102 |
}
|
106 |
if (jQuery("#include_" + t_id).length > 0) {
|
107 |
checkboxes = jQuery("#include_" + t_id).find('.checkbox-send');
|
108 |
for(i = 0; i < checkboxes.length; i++) {
|
|
|
109 |
if (t.checked) {
|
110 |
jQuery(checkboxes[i]).attr('checked', true);
|
|
|
111 |
} else {
|
|
|
|
|
|
|
|
|
112 |
jQuery(checkboxes[i]).attr('checked', false);
|
113 |
}
|
114 |
}
|
template/notice.php
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
<?php if ( ! defined( 'ABSPATH' ) ) exit; ?>
|
2 |
<div class="clear"></div>
|
3 |
<div class="update-nag" style="width: 95%;">
|
4 |
<?php _e('Professional version of','dropbox-backup'); ?>
|
|
|
1 |
<div class="clear"></div>
|
2 |
<div class="update-nag" style="width: 95%;">
|
3 |
<?php _e('Professional version of','dropbox-backup'); ?>
|
template/notice5.php
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
<?php if ( ! defined( 'ABSPATH' ) ) exit; ?>
|
2 |
<div class="clear"></div>
|
3 |
<div class="updated notice" style="width: 95%;">
|
4 |
<p>
|
|
|
1 |
<div class="clear"></div>
|
2 |
<div class="updated notice" style="width: 95%;">
|
3 |
<p>
|
template/wpadm_show_backup.php
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
<?php if ( ! defined( 'ABSPATH' ) ) exit; ?>
|
2 |
<div class="wrap">
|
3 |
<script src="<?php echo plugin_dir_url(__FILE__) . 'js/jquery.arcticmodal-0.3.min.js'?>" type="text/javascript"></script>
|
4 |
<link rel='stylesheet' href='<?php echo plugin_dir_url(__FILE__) . 'js/jquery.arcticmodal-0.3.css'?>' type='text/css' media='all' />
|
@@ -75,22 +74,15 @@
|
|
75 |
jQuery('#registr-show').html("<?php _e('Hide','dropbox-backup'); ?>");
|
76 |
jQuery('#title-regisr').css("padding" , "0px 0px");
|
77 |
jQuery('#registr-choice-icon').removeClass("dashicons-arrow-down").addClass('dashicons-arrow-up');
|
78 |
-
jQuery(".hover-title").hide(200);
|
79 |
} else {
|
80 |
if (show) {
|
81 |
jQuery('#cf_activate').hide('slow');
|
82 |
jQuery('#registr-show').html("<?php _e('Show','dropbox-backup'); ?>");
|
83 |
-
jQuery('#title-regisr').css("padding" , "
|
84 |
jQuery('#registr-choice-icon').removeClass("dashicons-arrow-up").addClass('dashicons-arrow-down');
|
85 |
-
jQuery(".hover-title").show(200);
|
86 |
}
|
87 |
}
|
88 |
}
|
89 |
-
function changesSetting()
|
90 |
-
{
|
91 |
-
return confirm('<?php _e('The configuration was changed. Would you like to save it?', 'dropbox-backup')?>');
|
92 |
-
}
|
93 |
-
var changes_setting = false;
|
94 |
function showSetting(show)
|
95 |
{
|
96 |
display = jQuery('#setting_active').css('display');
|
@@ -101,19 +93,10 @@
|
|
101 |
jQuery('#setting-choice-icon').removeClass("dashicons-arrow-down").addClass('dashicons-arrow-up');
|
102 |
} else {
|
103 |
if (show) {
|
104 |
-
if (changes_setting) {
|
105 |
-
if ( changesSetting() ) {
|
106 |
-
jQuery('#button-save-folder-backup').click();
|
107 |
-
return;
|
108 |
-
}
|
109 |
-
location.reload();
|
110 |
-
return;
|
111 |
-
}
|
112 |
jQuery('#setting_active').hide('slow');
|
113 |
jQuery('#setting-show').html("<?php _e('Show','dropbox-backup'); ?>");
|
114 |
jQuery('#title-setting').css("padding" , "20px 0px");
|
115 |
jQuery('#setting-choice-icon').removeClass("dashicons-arrow-up").addClass('dashicons-arrow-down');
|
116 |
-
|
117 |
}
|
118 |
}
|
119 |
}
|
@@ -123,7 +106,6 @@
|
|
123 |
d = new Date();
|
124 |
var data_backup = {
|
125 |
'action': 'wpadm_local_backup',
|
126 |
-
'nonce' : '<?php echo esc_attr( $nonce ); ?>',
|
127 |
'time': Math.ceil( (d.getTime() + (-d.getTimezoneOffset() * 60000 ) ) / 1000 )
|
128 |
};
|
129 |
jQuery("#logs-form").show("slow");
|
@@ -211,7 +193,6 @@
|
|
211 |
|
212 |
var data_backup = {
|
213 |
'action': 'wpadm_dropbox_create',
|
214 |
-
'nonce' : '<?php echo esc_attr( $nonce ); ?>',
|
215 |
'time': Math.ceil( (d.getTime() + (-d.getTimezoneOffset() * 60000 ) ) / 1000 ),
|
216 |
};
|
217 |
jQuery("#logs-form").show("slow");
|
@@ -397,26 +378,6 @@
|
|
397 |
}
|
398 |
}
|
399 |
}
|
400 |
-
|
401 |
-
function initial_restore(method)
|
402 |
-
{
|
403 |
-
url_ajax = '<?php echo plugins_url('/modules/restore-class.php', dirname(__FILE__) ); ?>';
|
404 |
-
data_send = {};
|
405 |
-
data_send['key'] = '<?php echo esc_attr( $key ); ?>';
|
406 |
-
data_send['method'] = 'restore';
|
407 |
-
jQuery.ajax({
|
408 |
-
type: "POST",
|
409 |
-
url: url_ajax,
|
410 |
-
data: data_send,
|
411 |
-
error: function(jqXHR, textStatus, errorThrown){
|
412 |
-
//setTimeout('processBar("' + method + '")', 10000);
|
413 |
-
if (jqXHR.status != 0) {
|
414 |
-
//processStop();
|
415 |
-
//AjaxAlert(jqXHR, textStatus, errorThrown);
|
416 |
-
}
|
417 |
-
},
|
418 |
-
});
|
419 |
-
}
|
420 |
var logs = [];
|
421 |
function processBar(method)
|
422 |
{
|
@@ -425,7 +386,6 @@
|
|
425 |
}
|
426 |
var data_log = {
|
427 |
'action': 'wpadm_logs',
|
428 |
-
'nonce' : '<?php echo esc_attr( $nonce ); ?>',
|
429 |
'type-backup' : method,
|
430 |
};
|
431 |
if (method == 'send-to-dropbox') {
|
@@ -435,7 +395,7 @@
|
|
435 |
var url_ajax = ajaxurl;
|
436 |
if (method == 'restore') {
|
437 |
url_ajax = '<?php echo plugins_url('/modules/restore-class.php', dirname(__FILE__) ); ?>';
|
438 |
-
data_log['key'] = '<?php echo
|
439 |
data_log['method'] = 'wpadm_logs';
|
440 |
}
|
441 |
jQuery.ajax({
|
@@ -458,8 +418,6 @@
|
|
458 |
showProcessesData(data.processes);
|
459 |
}
|
460 |
|
461 |
-
|
462 |
-
|
463 |
if (process_flag == 1) {
|
464 |
if (data.data) {
|
465 |
if (method == 'restore') {
|
@@ -477,16 +435,11 @@
|
|
477 |
setTimeout('processBar("' + method + '")', 10000);
|
478 |
}
|
479 |
}
|
480 |
-
|
481 |
-
if (data.mod_secur) { // initial restore ajax
|
482 |
-
initial_restore(method);
|
483 |
-
}
|
484 |
} else {
|
485 |
setTimeout('processBar("' + method + '")', 10000);
|
486 |
}
|
487 |
},
|
488 |
error: function(jqXHR, textStatus, errorThrown){
|
489 |
-
setTimeout('processBar("' + method + '")', 10000);
|
490 |
if (jqXHR.status != 0) {
|
491 |
//processStop();
|
492 |
//AjaxAlert(jqXHR, textStatus, errorThrown);
|
@@ -568,8 +521,7 @@
|
|
568 |
}
|
569 |
var data_backup = {
|
570 |
'action': act,
|
571 |
-
'
|
572 |
-
'key' : '<?php echo esc_attr( $key ); ?>',
|
573 |
'name': name,
|
574 |
};
|
575 |
jQuery("#log-backup").html('');
|
@@ -651,10 +603,11 @@
|
|
651 |
}
|
652 |
}
|
653 |
if(send) {
|
|
|
654 |
data['password'] = document.auth.password.value;
|
655 |
data['username'] = document.auth.username.value;
|
656 |
data['plugin'] = document.auth.plugin.value;
|
657 |
-
backup = jQuery("#name_backup_restore").val();
|
658 |
jQuery.ajax({
|
659 |
url: form.attr('action'),
|
660 |
data: data,
|
@@ -898,7 +851,7 @@
|
|
898 |
function saveSetting(id)
|
899 |
{
|
900 |
if (jQuery('#' + id).length > 0) {
|
901 |
-
if ( jQuery('#' + id).is('select') || jQuery('#' + id).is( ":text" )
|
902 |
is_value = jQuery('#' + id).val();
|
903 |
} else {
|
904 |
is_value = 0;
|
@@ -970,7 +923,7 @@
|
|
970 |
<?php
|
971 |
$command_running = get_transient('running_command');
|
972 |
if (isset($is_runnig) && $is_runnig && $command_running ) {
|
973 |
-
if (
|
974 |
@unlink(WPAdm_Core::getTmpDir() . "/logs2");
|
975 |
}
|
976 |
?>
|
@@ -986,7 +939,7 @@
|
|
986 |
jQuery("#log-backup").html('');
|
987 |
jQuery(".title-logs").css('display', 'block');
|
988 |
jQuery(".title-status").css('display', 'none');
|
989 |
-
type_backup = '<?php echo
|
990 |
|
991 |
setTimeout(function() {
|
992 |
disable_buttons() ;
|
@@ -1015,7 +968,7 @@
|
|
1015 |
' . $msg . '
|
1016 |
</p></div>';
|
1017 |
}?>
|
1018 |
-
|
1019 |
<div id="wp-cron-enable" style="display: none;">
|
1020 |
<div class="close-button"><a href="javascript:void(0)" onclick="jQuery('#wp-cron-enable').arcticmodal('close');"><img src="<?php echo plugins_url('/img/closebox.png', dirname(__FILE__));?>" alt=""></a></div>
|
1021 |
<div class="image-enable">
|
@@ -1051,7 +1004,7 @@
|
|
1051 |
</script>
|
1052 |
<div id="sent-error-report" style="display: none;" >
|
1053 |
<div class="text-view">
|
1054 |
-
<?php echo
|
1055 |
</div>
|
1056 |
<div class="button-sent-report">
|
1057 |
<input type="button" class="button-wpadm" value="<?php _e('OK','dropbox-backup'); ?>" onclick="jQuery('#sent-error-report').arcticmodal('close')" />
|
@@ -1075,7 +1028,7 @@
|
|
1075 |
<label for="ftp-host"><?php _e('FTP Host','dropbox-backup'); ?></label>
|
1076 |
</div>
|
1077 |
<div style="float:left; ">
|
1078 |
-
<input type="text" id="ftp-host" value="<?php echo
|
1079 |
</div>
|
1080 |
</div>
|
1081 |
<div class="clear"></div>
|
@@ -1105,14 +1058,14 @@
|
|
1105 |
<label for="email-resp"><?php _e('Response Email:','dropbox-backup'); ?></label>
|
1106 |
</div>
|
1107 |
<div style=" ">
|
1108 |
-
<input type="text" id="email-resp" value="<?php echo
|
1109 |
</div>
|
1110 |
</div>
|
1111 |
</div>
|
1112 |
</div>
|
1113 |
<div class="clear"></div>
|
1114 |
<div style="text-align: left; margin-left: 100px; margin-top: 10px;">
|
1115 |
-
<input value="<?php echo
|
1116 |
<input value="" type="hidden" name="msg_ajax" id="msg_ajax">
|
1117 |
</div>
|
1118 |
<div class="ajax-button" style="margin-bottom: 10px;">
|
@@ -1148,77 +1101,66 @@
|
|
1148 |
<span style="font-size: 20px;"><?php _e('(files+database)','dropbox-backup');?></span>
|
1149 |
|
1150 |
<span style="font-size: 11px;">
|
1151 |
-
<?php echo (isset($plugin_data[0]['Version']) ? 'Version ' .
|
1152 |
</span>
|
1153 |
|
1154 |
</div>
|
1155 |
<?php if ($show) {?>
|
1156 |
-
<div id="container-user" class="cfTabsContainer"
|
1157 |
-
<div class="stat-wpadm-info-title" id="title-regisr" style="padding :
|
1158 |
-
<?php
|
1159 |
-
<?php _e('Free Sign Up','dropbox-backup'); ?> <br /><?php _e('to backup more than one website...','dropbox-backup'); ?>
|
1160 |
-
<?php } else {
|
1161 |
-
_e('Professional version<br /> "Dropbox backup and restore"<br /><span class="hover-title">get more...</span>','dropbox-backup');
|
1162 |
-
} ?>
|
1163 |
</div>
|
1164 |
<div id="cf_activate" class="cfContentContainer" style="display: none;">
|
1165 |
-
<?php
|
1166 |
-
<
|
1167 |
-
<
|
1168 |
-
<
|
1169 |
-
<
|
1170 |
-
<
|
1171 |
-
<
|
1172 |
-
|
1173 |
-
|
1174 |
-
<
|
1175 |
-
|
1176 |
-
|
1177 |
-
|
1178 |
-
<
|
1179 |
-
<
|
1180 |
-
|
1181 |
-
|
1182 |
-
<
|
1183 |
-
|
1184 |
-
|
1185 |
-
|
1186 |
-
<
|
1187 |
-
<
|
1188 |
-
|
1189 |
-
|
1190 |
-
<
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
<
|
1195 |
-
|
1196 |
-
|
1197 |
-
<
|
1198 |
-
|
1199 |
-
|
1200 |
-
|
1201 |
-
|
1202 |
-
|
1203 |
-
|
1204 |
-
<
|
1205 |
-
|
1206 |
-
|
1207 |
-
</form>
|
1208 |
-
<?php } else {
|
1209 |
-
$repeat_advantage = false;
|
1210 |
-
include 'advantage-plugin.php';
|
1211 |
-
}
|
1212 |
-
?>
|
1213 |
</div>
|
1214 |
<div class="clear"></div>
|
1215 |
<div class="block-button-show" style="color: #fff;">
|
1216 |
-
<div class="block-click" onclick="showRegistInfo(true
|
1217 |
<span id="registr-show" style="color: #fff;"><?php _e('Show','dropbox-backup'); ?></span>
|
1218 |
<div id="registr-choice-icon" class="dashicons dashicons-arrow-down" style=""></div>
|
1219 |
</div>
|
1220 |
</div>
|
1221 |
-
|
1222 |
</div>
|
1223 |
<?php } else { ?>
|
1224 |
<div id="container-user" class="cfTabsContainer" style="width: 48%; padding-bottom: 0px; padding-top: 0px; float: left; margin-left: 20px;">
|
@@ -1226,13 +1168,13 @@
|
|
1226 |
<?php _e('Sign In to backup more than one website...','dropbox-backup'); ?>
|
1227 |
</div>
|
1228 |
<div>
|
1229 |
-
<form method="post" id="auth" name="auth" action="<?php echo
|
1230 |
<div>
|
1231 |
<div id="message-form" style="color: red; float: left;margin: 10px;margin-top: 14px;"></div>
|
1232 |
</div>
|
1233 |
<div style="padding: 5px; clear: both;">
|
1234 |
<div class="form-field">
|
1235 |
-
<input class="input-small" type="text" id="username" value="<?php echo
|
1236 |
</div>
|
1237 |
<div class="form-field">
|
1238 |
<input class="input-small" type="password" required="required" name="password" placeholder="<?php _e('Password','dropbox-backup'); ?>" />
|
@@ -1257,11 +1199,11 @@
|
|
1257 |
<?php _e('Settings','dropbox-backup'); ?>
|
1258 |
</div>
|
1259 |
<div id="setting_active" class="cfContentContainer" style="display: none;">
|
1260 |
-
<form method="post" action=""
|
1261 |
<div class="stat-wpadm-registr-info" style="width: 100%; margin-bottom: 9px;">
|
1262 |
<div style="margin-bottom: 12px; margin-top: 20px; font-size: 15px; text-align: center;">
|
1263 |
<input class="btn-orange" type="button" style="padding: 5px 10px; font-size: 15px; font-weight: 500" onclick="connectDropbox(this,'<?php echo admin_url( 'admin-post.php?action=dropboxConnect' )?>')" value="<?php _e('Connect to Dropbox','dropbox-backup'); ?>" name="submit">
|
1264 |
-
<div class="desc-wpadm"><span id="dropbox_uid_text"><?php echo isset($dropbox_options['oauth_token']) && isset($dropbox_options['uid']) ? __('Dropbox successfully connected:','dropbox-backup') . " UID " .
|
1265 |
</div>
|
1266 |
<?php $show_fields = isset($dropbox_options['app_key']) && !empty($dropbox_options['app_key']) && isset($dropbox_options['app_secret']) && !empty($dropbox_options['app_secret']) && $dropbox_options['app_key'] != WPADM_APP_KEY && $dropbox_options['app_secret'] != WPADM_APP_SECRET ; ?>
|
1267 |
<div class="setting-checkbox">
|
@@ -1275,7 +1217,7 @@
|
|
1275 |
<label for="app_key"><?php _e('App key','dropbox-backup'); ?>*</label>
|
1276 |
</th>
|
1277 |
<td>
|
1278 |
-
<input id="app_key" class="" type="text" name="app_key" value="<?php echo isset($dropbox_options['app_key']) && $dropbox_options['app_key'] != WPADM_APP_KEY ?
|
1279 |
</td>
|
1280 |
</tr>
|
1281 |
<tr valign="top" id="dropbox-app-secret" style="display: <?php echo $show_fields ? 'table-row' : 'none'?>;">
|
@@ -1283,7 +1225,7 @@
|
|
1283 |
<label for="app_secret"><?php _e('App secret','dropbox-backup'); ?>*</label>
|
1284 |
</th>
|
1285 |
<td>
|
1286 |
-
<input id="app_secret" class="" type="text" name="app_secret" value="<?php echo isset($dropbox_options['app_secret']) && $dropbox_options['app_secret'] != WPADM_APP_SECRET ?
|
1287 |
</td>
|
1288 |
</tr>
|
1289 |
|
@@ -1300,7 +1242,7 @@
|
|
1300 |
<label for="time_error" style="font-size: 13px;"><?php _e('Waiting time (minutes)', 'dropbox-backup'); ?></label>
|
1301 |
<select name="time_error" id="time_error" onchange="saveSetting('time_error')">
|
1302 |
<?php
|
1303 |
-
for($i = 1; $i <
|
1304 |
?>
|
1305 |
<option value="<?php echo $i?>" <?php echo isset($dropbox_options['time_error']) && $dropbox_options['time_error'] == $i ? 'selected="selected"' : (!isset($dropbox_options['time_error']) && $i == $default ) ? 'selected="selected"' : '' ?> ><?php echo $i?>:00</option>
|
1306 |
<?php
|
@@ -1312,70 +1254,39 @@
|
|
1312 |
</div>
|
1313 |
<?php if ( is_super_admin() ) { ?>
|
1314 |
<div class="setting-checkbox">
|
1315 |
-
<input type="checkbox" <?php echo isset($dropbox_options['is_admin']) &&
|
1316 |
<label for="is_admin" style="font-size: 13px;"><?php _e('Appear in menu for admins only','dropbox-backup'); ?></label>
|
1317 |
</div>
|
1318 |
<?php } ?>
|
1319 |
<div class="setting-checkbox">
|
1320 |
-
<input type="checkbox" <?php echo (isset($dropbox_options['is_optimization']) &&
|
1321 |
<label for="is_optimization" style="font-size: 13px;"><?php _e('Database Optimization','dropbox-backup'); ?></label>
|
1322 |
</div>
|
1323 |
<div class="setting-checkbox">
|
1324 |
-
<input type="checkbox" <?php echo (isset($dropbox_options['is_local_backup_delete']) &&
|
1325 |
<label for="is_local_backup_delete" style="font-size: 13px; width: 90%"><?php _e('Don\'t delete a local backup copy after uploading to dropbox','dropbox-backup'); ?></label>
|
1326 |
</div>
|
1327 |
<div class="setting-checkbox">
|
1328 |
-
<input type="checkbox" <?php echo (isset($dropbox_options['is_repair']) &&
|
1329 |
<label for="is_repair" style="font-size: 13px;"><?php _e('Try database repair','dropbox-backup'); ?></label>
|
1330 |
</div>
|
1331 |
<div class="setting-checkbox">
|
1332 |
-
<input type="checkbox" <?php echo (isset($dropbox_options['is_show_admin_bar']) &&
|
1333 |
<label for="is_show_admin_bar" style="font-size: 13px;"><?php _e('Show in a admin bar','dropbox-backup'); ?></label>
|
1334 |
</div>
|
1335 |
-
|
1336 |
-
<!-- type archive -->
|
1337 |
-
<div class="setting-checkbox" style="margin-top:40px;">
|
1338 |
-
<label for="" style="font-size: 13px; font-weight: 600;"><?php _e('Create backup using following backup methods:','dropbox-backup'); ?></label>
|
1339 |
-
<span style="font-size: 11px; margin-top: -7px;">(<?php _e('ZIP method will be used as \'default\'')?>)</span>
|
1340 |
-
</div>
|
1341 |
-
<div class="setting-checkbox">
|
1342 |
-
<input autocomplete="off" type="checkbox" <?php echo ( isset($dropbox_options['type_archive']['zip_archive']) && $dropbox_options['type_archive']['zip_archive'] == 1 ) ? 'checked="checked"' : ''; ?> value="1" id="zip_archive" onclick="saveSetting('zip_archive')" />
|
1343 |
-
<label for="zip_archive" style="font-size: 13px;"><?php _e('Zip shell','dropbox-backup'); ?></label>
|
1344 |
-
</div>
|
1345 |
-
<div class="setting-checkbox">
|
1346 |
-
<input autocomplete="off" type="checkbox" <?php echo ( isset($dropbox_options['type_archive']['targz_archive']) && $dropbox_options['type_archive']['targz_archive'] == 1 ) ? 'checked="checked"' : ''; ?> value="1" id="targz_archive" onclick="saveSetting('targz_archive')" />
|
1347 |
-
<label for="targz_archive" style="font-size: 13px;"><?php _e('TarGz archive','dropbox-backup'); ?></label>
|
1348 |
-
</div>
|
1349 |
-
<!-- <div class="setting-checkbox">
|
1350 |
-
<input autocomplete="off" type="checkbox" <?php echo ( isset($dropbox_options['type_archive']['tar_archive']) && $dropbox_options['type_archive']['tar_archive'] == 1) ? 'checked="checked"' : ''; ?> name="type_archive" value="tar_archive" id="tar_archive" data-name="tar_archive" onclick="saveSetting('tar_archive')" />
|
1351 |
-
<label for="tar_archive" style="font-size: 13px;"><?php _e('Tar archive','dropbox-backup'); ?></label>
|
1352 |
-
</div> -->
|
1353 |
-
<div class="clear" style="margin-top: 15px;"></div>
|
1354 |
-
<!-- end type archive -->
|
1355 |
<div class="setting-checkbox">
|
1356 |
<?php _e('Include/Exclude','dropbox-backup'); ?>
|
1357 |
<a onclick="InludesSetting();" href="javascript:void(0);" style="color: #fff"><?php _e('Folders and files','dropbox-backup'); ?></a>
|
1358 |
</div>
|
1359 |
<div style="border-bottom:1px solid #fff; margin:10px 0px;"></div>
|
1360 |
<div class="setting-checkbox">
|
1361 |
-
<
|
1362 |
-
<
|
1363 |
-
<span>
|
1364 |
-
<input type="hidden" value="1" id="clear_backup_folder">
|
1365 |
-
<a href="javascript:void(0);" onclick="setDefaultFolderBackup('<?php echo urlencode(DROPBOX_BACKUP_DIR_BACKUP);?>');" style="color:#fff;"><?php _e('Set to default backup folder','dropbox-backup');?></a>
|
1366 |
-
</span>
|
1367 |
-
<div class="clear"></div>
|
1368 |
</div>
|
1369 |
-
<div class="setting-checkbox" style="text-align: center;
|
1370 |
-
<input class="btn-orange" type="button"
|
1371 |
</div>
|
1372 |
-
|
1373 |
-
jQuery(document).ready(function() {
|
1374 |
-
jQuery('#button-save-folder-backup').click(function() {
|
1375 |
-
saveSetting('backup_folder');
|
1376 |
-
})
|
1377 |
-
})
|
1378 |
-
</script>
|
1379 |
</div>
|
1380 |
</form>
|
1381 |
</div>
|
@@ -1462,7 +1373,7 @@
|
|
1462 |
</div>
|
1463 |
</div>
|
1464 |
<div id="support-button" style="float: right; margin-top: 130px; margin-right: 20px;">
|
1465 |
-
<button onclick="window.open('<?php echo
|
1466 |
</div>
|
1467 |
<div id="action-buttons" style="">
|
1468 |
<div style="float: left;">
|
@@ -1482,21 +1393,19 @@
|
|
1482 |
</div>
|
1483 |
<div style="clear: both; margin-bottom: 10px;"></div>
|
1484 |
<div>
|
1485 |
-
<form action="<?php echo
|
1486 |
</form>
|
1487 |
-
<form action="<?php echo
|
1488 |
-
<input type="hidden" name="url_task_create" value="<?php echo
|
1489 |
</form>
|
1490 |
<form action="" method="post" id="form_auth_backup" name="form_auth_backup">
|
1491 |
</form>
|
1492 |
<form action="<?php echo admin_url( 'admin-post.php?action=wpadm_delete_backup' )?>" method="post" id="delete_backups" name="delete_backups">
|
1493 |
<input type="hidden" name="backup-name" id="backup_name" value="" />
|
1494 |
<input type="hidden" name="backup-type" id="backup_type" value="" />
|
1495 |
-
<input type="hidden" name="nonce" id="id_nonce_delete" value="<?php echo esc_attr( $nonce );?>" />
|
1496 |
</form>
|
1497 |
<form action="<?php echo admin_url( 'admin-post.php?action=stop_backup' )?>" method="post" id="stop_backups" name="stop_backups">
|
1498 |
<input type="hidden" name="type_backup" id="type_backup" value="" />
|
1499 |
-
<input type="hidden" name="nonce" id="id_nonce" value="<?php echo esc_attr( $nonce ); ?>" />
|
1500 |
</form>
|
1501 |
<div id="inludes-setting" class="" style="display: none; width: 550px; position: relative; text-align: center; background: #e5e5e5; border: 2px solid #dde4ff; border-radius: 5px;">
|
1502 |
<div>
|
@@ -1553,8 +1462,8 @@
|
|
1553 |
?>
|
1554 |
<tr>
|
1555 |
<td class="number-backup"><?php echo ($i + 1);?></td>
|
1556 |
-
<td onclick="shows('<?php echo
|
1557 |
-
<td onclick="shows('<?php echo
|
1558 |
<?php
|
1559 |
$e = '';
|
1560 |
if ( isset($is_runnig) && $is_runnig && isset($name_running_backup) && $name_running_backup == $data['data'][$i]['name']) {
|
@@ -1568,14 +1477,14 @@
|
|
1568 |
} else {
|
1569 |
$e = "<strong style=\"color:red;\">". __('Not available','dropbox-backup') . "</strong> (<a style=\"text-decoration:underline;\">".__('Why?','dropbox-backup')."</a>)";
|
1570 |
}
|
1571 |
-
echo
|
1572 |
?>
|
1573 |
<script type="text/javascript">
|
1574 |
-
backup_name = '<?php echo
|
1575 |
</script>
|
1576 |
</td>
|
1577 |
-
<td onclick="shows('<?php echo
|
1578 |
-
<td onclick="shows('<?php echo
|
1579 |
<?php if ( isset($is_runnig) && $is_runnig && isset($name_running_backup) && $name_running_backup == $data['data'][$i]['name'] ) { ?>
|
1580 |
<img src="<?php echo plugin_dir_url(__FILE__) . "attention.png" ;?>" title="Attention" alt="Attention" style="float: left; width: 20px; height: 20px;margin-left: 21px;" />
|
1581 |
<div style="margin-top :1px;float: left;"><?php _e('Backup in progress','dropbox-backup');?></div>
|
@@ -1599,8 +1508,8 @@
|
|
1599 |
<?php
|
1600 |
}?>
|
1601 |
</td>
|
1602 |
-
<td onclick="shows('<?php echo
|
1603 |
-
<td onclick="shows('<?php echo
|
1604 |
<td>
|
1605 |
<?php if(is_admin() || is_super_admin()) {?>
|
1606 |
<?php if ($data['data'][$i]['size'] > 0) {
|
@@ -1610,16 +1519,16 @@
|
|
1610 |
<?php
|
1611 |
} else {
|
1612 |
?>
|
1613 |
-
<a class="button-wpadm" href="javascript:void(0)" title="<?php _e('Restore','dropbox-backup'); ?>" onclick="show_recovery_form('<?php echo isset($data['data'][$i]['name']) && $data['data'][$i]['type'] != 'local' ? $data['data'][$i]['name'] : 'local' ?>', '<?php echo
|
1614 |
<?php }
|
1615 |
} ?>
|
1616 |
-
<a class="button-wpadm" href="javascript:void(0)" title="<?php _e('Delete','dropbox-backup'); ?>" onclick="delete_backup('<?php echo
|
1617 |
<?php
|
1618 |
}
|
1619 |
?>
|
1620 |
</td>
|
1621 |
</tr>
|
1622 |
-
<tr id="<?php echo
|
1623 |
<?php if ($data['data'][$i]['size'] != 0) {?>
|
1624 |
<td colspan="2">
|
1625 |
</td>
|
@@ -1634,12 +1543,12 @@
|
|
1634 |
<tr style="border: 0;">
|
1635 |
<td style="border: 0;">
|
1636 |
<?php if ($data['data'][$i]['type'] == 'local') {?>
|
1637 |
-
<a href="<?php echo
|
1638 |
-
<?php echo
|
1639 |
</a>
|
1640 |
<?php
|
1641 |
} else {
|
1642 |
-
echo
|
1643 |
}
|
1644 |
?>
|
1645 |
</td>
|
@@ -1660,7 +1569,7 @@
|
|
1660 |
?>
|
1661 |
<td colspan="8">
|
1662 |
<?php _e('Backup is created. If you are sure that the backup down(crashed), please ','dropbox-backup');?>
|
1663 |
-
<a href="javascript:void(0)" onclick="window.open('<?php echo
|
1664 |
</td>
|
1665 |
<?php
|
1666 |
} else { ?>
|
@@ -1699,7 +1608,7 @@
|
|
1699 |
<label for="ftp-host"><?php _e('FTP Host','dropbox-backup'); ?></label>
|
1700 |
</div>
|
1701 |
<div style="float:left; ">
|
1702 |
-
<input type="text" id="ftp-host" value="<?php echo
|
1703 |
</div>
|
1704 |
</div>
|
1705 |
<div class="clear"></div>
|
@@ -1729,13 +1638,13 @@
|
|
1729 |
<label for="email-resp"><?php _e('Response Email:','dropbox-backup'); ?></label>
|
1730 |
</div>
|
1731 |
<div style=" ">
|
1732 |
-
<input type="text" id="email-resp" value="<?php echo
|
1733 |
</div>
|
1734 |
</div>
|
1735 |
</div>
|
1736 |
<div class="clear"></div>
|
1737 |
<div style="text-align: left; margin-left: 100px; margin-top: 10px;">
|
1738 |
-
<input value="<?php echo
|
1739 |
<input class="backup_button" style="font-size: 14px;font-weight: normal;padding: 3px;text-shadow: 0px;" type="submit" value="<?php _e('Send request to support','dropbox-backup'); ?>">
|
1740 |
</div>
|
1741 |
</form>
|
|
|
1 |
<div class="wrap">
|
2 |
<script src="<?php echo plugin_dir_url(__FILE__) . 'js/jquery.arcticmodal-0.3.min.js'?>" type="text/javascript"></script>
|
3 |
<link rel='stylesheet' href='<?php echo plugin_dir_url(__FILE__) . 'js/jquery.arcticmodal-0.3.css'?>' type='text/css' media='all' />
|
74 |
jQuery('#registr-show').html("<?php _e('Hide','dropbox-backup'); ?>");
|
75 |
jQuery('#title-regisr').css("padding" , "0px 0px");
|
76 |
jQuery('#registr-choice-icon').removeClass("dashicons-arrow-down").addClass('dashicons-arrow-up');
|
|
|
77 |
} else {
|
78 |
if (show) {
|
79 |
jQuery('#cf_activate').hide('slow');
|
80 |
jQuery('#registr-show').html("<?php _e('Show','dropbox-backup'); ?>");
|
81 |
+
jQuery('#title-regisr').css("padding" , "20px 0px");
|
82 |
jQuery('#registr-choice-icon').removeClass("dashicons-arrow-up").addClass('dashicons-arrow-down');
|
|
|
83 |
}
|
84 |
}
|
85 |
}
|
|
|
|
|
|
|
|
|
|
|
86 |
function showSetting(show)
|
87 |
{
|
88 |
display = jQuery('#setting_active').css('display');
|
93 |
jQuery('#setting-choice-icon').removeClass("dashicons-arrow-down").addClass('dashicons-arrow-up');
|
94 |
} else {
|
95 |
if (show) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
jQuery('#setting_active').hide('slow');
|
97 |
jQuery('#setting-show').html("<?php _e('Show','dropbox-backup'); ?>");
|
98 |
jQuery('#title-setting').css("padding" , "20px 0px");
|
99 |
jQuery('#setting-choice-icon').removeClass("dashicons-arrow-up").addClass('dashicons-arrow-down');
|
|
|
100 |
}
|
101 |
}
|
102 |
}
|
106 |
d = new Date();
|
107 |
var data_backup = {
|
108 |
'action': 'wpadm_local_backup',
|
|
|
109 |
'time': Math.ceil( (d.getTime() + (-d.getTimezoneOffset() * 60000 ) ) / 1000 )
|
110 |
};
|
111 |
jQuery("#logs-form").show("slow");
|
193 |
|
194 |
var data_backup = {
|
195 |
'action': 'wpadm_dropbox_create',
|
|
|
196 |
'time': Math.ceil( (d.getTime() + (-d.getTimezoneOffset() * 60000 ) ) / 1000 ),
|
197 |
};
|
198 |
jQuery("#logs-form").show("slow");
|
378 |
}
|
379 |
}
|
380 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
381 |
var logs = [];
|
382 |
function processBar(method)
|
383 |
{
|
386 |
}
|
387 |
var data_log = {
|
388 |
'action': 'wpadm_logs',
|
|
|
389 |
'type-backup' : method,
|
390 |
};
|
391 |
if (method == 'send-to-dropbox') {
|
395 |
var url_ajax = ajaxurl;
|
396 |
if (method == 'restore') {
|
397 |
url_ajax = '<?php echo plugins_url('/modules/restore-class.php', dirname(__FILE__) ); ?>';
|
398 |
+
data_log['key'] = '<?php echo $key; ?>';
|
399 |
data_log['method'] = 'wpadm_logs';
|
400 |
}
|
401 |
jQuery.ajax({
|
418 |
showProcessesData(data.processes);
|
419 |
}
|
420 |
|
|
|
|
|
421 |
if (process_flag == 1) {
|
422 |
if (data.data) {
|
423 |
if (method == 'restore') {
|
435 |
setTimeout('processBar("' + method + '")', 10000);
|
436 |
}
|
437 |
}
|
|
|
|
|
|
|
|
|
438 |
} else {
|
439 |
setTimeout('processBar("' + method + '")', 10000);
|
440 |
}
|
441 |
},
|
442 |
error: function(jqXHR, textStatus, errorThrown){
|
|
|
443 |
if (jqXHR.status != 0) {
|
444 |
//processStop();
|
445 |
//AjaxAlert(jqXHR, textStatus, errorThrown);
|
521 |
}
|
522 |
var data_backup = {
|
523 |
'action': act,
|
524 |
+
'key' : '<?php echo $key; ?>',
|
|
|
525 |
'name': name,
|
526 |
};
|
527 |
jQuery("#log-backup").html('');
|
603 |
}
|
604 |
}
|
605 |
if(send) {
|
606 |
+
form.find('#message-form').css('display', 'none');
|
607 |
data['password'] = document.auth.password.value;
|
608 |
data['username'] = document.auth.username.value;
|
609 |
data['plugin'] = document.auth.plugin.value;
|
610 |
+
backup = jQuery("#name_backup_restore").val();
|
611 |
jQuery.ajax({
|
612 |
url: form.attr('action'),
|
613 |
data: data,
|
851 |
function saveSetting(id)
|
852 |
{
|
853 |
if (jQuery('#' + id).length > 0) {
|
854 |
+
if ( jQuery('#' + id).is('select') || jQuery('#' + id).is( ":text" ) ) {
|
855 |
is_value = jQuery('#' + id).val();
|
856 |
} else {
|
857 |
is_value = 0;
|
923 |
<?php
|
924 |
$command_running = get_transient('running_command');
|
925 |
if (isset($is_runnig) && $is_runnig && $command_running ) {
|
926 |
+
if (file_exists(WPAdm_Core::getTmpDir() . "/logs2")) {
|
927 |
@unlink(WPAdm_Core::getTmpDir() . "/logs2");
|
928 |
}
|
929 |
?>
|
939 |
jQuery("#log-backup").html('');
|
940 |
jQuery(".title-logs").css('display', 'block');
|
941 |
jQuery(".title-status").css('display', 'none');
|
942 |
+
type_backup = '<?php echo $command_running; ?>';
|
943 |
|
944 |
setTimeout(function() {
|
945 |
disable_buttons() ;
|
968 |
' . $msg . '
|
969 |
</p></div>';
|
970 |
}?>
|
971 |
+
|
972 |
<div id="wp-cron-enable" style="display: none;">
|
973 |
<div class="close-button"><a href="javascript:void(0)" onclick="jQuery('#wp-cron-enable').arcticmodal('close');"><img src="<?php echo plugins_url('/img/closebox.png', dirname(__FILE__));?>" alt=""></a></div>
|
974 |
<div class="image-enable">
|
1004 |
</script>
|
1005 |
<div id="sent-error-report" style="display: none;" >
|
1006 |
<div class="text-view">
|
1007 |
+
<?php echo $sent_response ;?>
|
1008 |
</div>
|
1009 |
<div class="button-sent-report">
|
1010 |
<input type="button" class="button-wpadm" value="<?php _e('OK','dropbox-backup'); ?>" onclick="jQuery('#sent-error-report').arcticmodal('close')" />
|
1028 |
<label for="ftp-host"><?php _e('FTP Host','dropbox-backup'); ?></label>
|
1029 |
</div>
|
1030 |
<div style="float:left; ">
|
1031 |
+
<input type="text" id="ftp-host" value="<?php echo str_ireplace(array('http://', 'https://'), '', home_url()) ;?>" name="ftp_host" >
|
1032 |
</div>
|
1033 |
</div>
|
1034 |
<div class="clear"></div>
|
1058 |
<label for="email-resp"><?php _e('Response Email:','dropbox-backup'); ?></label>
|
1059 |
</div>
|
1060 |
<div style=" ">
|
1061 |
+
<input type="text" id="email-resp" value="<?php echo get_option('admin_email');?>" style="padding-left:3px;" name="mail_response">
|
1062 |
</div>
|
1063 |
</div>
|
1064 |
</div>
|
1065 |
</div>
|
1066 |
<div class="clear"></div>
|
1067 |
<div style="text-align: left; margin-left: 100px; margin-top: 10px;">
|
1068 |
+
<input value="<?php echo $time_log; ?>" type="hidden" name="time_pars">
|
1069 |
<input value="" type="hidden" name="msg_ajax" id="msg_ajax">
|
1070 |
</div>
|
1071 |
<div class="ajax-button" style="margin-bottom: 10px;">
|
1101 |
<span style="font-size: 20px;"><?php _e('(files+database)','dropbox-backup');?></span>
|
1102 |
|
1103 |
<span style="font-size: 11px;">
|
1104 |
+
<?php echo (isset($plugin_data[0]['Version']) ? 'Version ' . $plugin_data[0]['Version'] : '')?>
|
1105 |
</span>
|
1106 |
|
1107 |
</div>
|
1108 |
<?php if ($show) {?>
|
1109 |
+
<div id="container-user" class="cfTabsContainer" style="width: 48%; padding-bottom: 0px; padding-top: 0px; float: left; margin-left: 20px;">
|
1110 |
+
<div class="stat-wpadm-info-title" id="title-regisr" style="padding :20px 0px; margin-top:11px; line-height: 25px;">
|
1111 |
+
<?php _e('Free Sign Up','dropbox-backup'); ?> <br /><?php _e('to backup more than one website...','dropbox-backup'); ?>
|
|
|
|
|
|
|
|
|
1112 |
</div>
|
1113 |
<div id="cf_activate" class="cfContentContainer" style="display: none;">
|
1114 |
+
<form method="post" id="dropbox_form" action="<?php echo admin_url( 'admin-post.php?action=wpadm_activate_plugin' )?>" >
|
1115 |
+
<div class="stat-wpadm-registr-info" style="margin-bottom: 40px; margin-top: 17px;">
|
1116 |
+
<table class="form-table stat-table-registr" style="">
|
1117 |
+
<tbody>
|
1118 |
+
<tr valign="top">
|
1119 |
+
<th scope="row">
|
1120 |
+
<label for="email"><?php _e('E-mail','dropbox-backup'); ?></label>
|
1121 |
+
</th>
|
1122 |
+
<td>
|
1123 |
+
<input id="email" class="" type="text" name="email" value="">
|
1124 |
+
</td>
|
1125 |
+
</tr>
|
1126 |
+
<tr valign="top">
|
1127 |
+
<th scope="row">
|
1128 |
+
<label for="password"><?php _e('Password','dropbox-backup'); ?></label>
|
1129 |
+
</th>
|
1130 |
+
<td>
|
1131 |
+
<input id="password" class="" type="password" name="password" value="">
|
1132 |
+
</td>
|
1133 |
+
</tr>
|
1134 |
+
<tr valign="top">
|
1135 |
+
<th scope="row">
|
1136 |
+
<label for="password-confirm"><?php _e('Password confirm','dropbox-backup'); ?></label>
|
1137 |
+
</th>
|
1138 |
+
<td>
|
1139 |
+
<input id="password-confirm" class="" type="password" name="password-confirm" value="">
|
1140 |
+
</td>
|
1141 |
+
</tr>
|
1142 |
+
<tr valign="top">
|
1143 |
+
<th scope="row">
|
1144 |
+
</th>
|
1145 |
+
<td>
|
1146 |
+
<input class="button-wpadm" type="submit" value="<?php _e('Register & Activate','dropbox-backup'); ?>" name="send">
|
1147 |
+
</td>
|
1148 |
+
</tr>
|
1149 |
+
</tbody>
|
1150 |
+
</table>
|
1151 |
+
</div>
|
1152 |
+
<div class="stat-wpadm-info" id="registr-info" style="margin-bottom: 2px; margin-top: 30px;">
|
1153 |
+
<span style="font-weight:bold; font-size: 14px;"><?php _e('If you are NOT registered at','dropbox-backup'); ?> <a target="_blank" style="color: #fff" href="<?php echo SERVER_URL_INDEX; ?>"><?php _e('WPAdm','dropbox-backup'); ?></a>,</span> <?php _e('enter your email and password to use as your Account Data for authorization on WPAdm.','dropbox-backup'); ?> <br /><span style="font-weight: bold;font-size: 14px;"><?php _e('If you already have an account at','dropbox-backup'); ?> <a target="_blank" style="color: #fff" href="<?php echo SERVER_URL_INDEX; ?>"><?php _e('WPAdm','dropbox-backup'); ?></a></span> <?php _e('and you want to Sign-In, so please, enter your registered credential data (email and password twice).','dropbox-backup'); ?>
|
1154 |
+
</div>
|
1155 |
+
</form>
|
|
|
|
|
|
|
|
|
|
|
|
|
1156 |
</div>
|
1157 |
<div class="clear"></div>
|
1158 |
<div class="block-button-show" style="color: #fff;">
|
1159 |
+
<div class="block-click" onclick="showRegistInfo(true);">
|
1160 |
<span id="registr-show" style="color: #fff;"><?php _e('Show','dropbox-backup'); ?></span>
|
1161 |
<div id="registr-choice-icon" class="dashicons dashicons-arrow-down" style=""></div>
|
1162 |
</div>
|
1163 |
</div>
|
|
|
1164 |
</div>
|
1165 |
<?php } else { ?>
|
1166 |
<div id="container-user" class="cfTabsContainer" style="width: 48%; padding-bottom: 0px; padding-top: 0px; float: left; margin-left: 20px;">
|
1168 |
<?php _e('Sign In to backup more than one website...','dropbox-backup'); ?>
|
1169 |
</div>
|
1170 |
<div>
|
1171 |
+
<form method="post" id="auth" name="auth" action="<?php echo SERVER_URL_INDEX . "login-process" ; ?>">
|
1172 |
<div>
|
1173 |
<div id="message-form" style="color: red; float: left;margin: 10px;margin-top: 14px;"></div>
|
1174 |
</div>
|
1175 |
<div style="padding: 5px; clear: both;">
|
1176 |
<div class="form-field">
|
1177 |
+
<input class="input-small" type="text" id="username" value="<?php echo get_option(PREFIX_BACKUP_ . "email");?>" readonly="readonly" required="required" name="username" placeholder="<?php _e('Email','dropbox-backup'); ?>" />
|
1178 |
</div>
|
1179 |
<div class="form-field">
|
1180 |
<input class="input-small" type="password" required="required" name="password" placeholder="<?php _e('Password','dropbox-backup'); ?>" />
|
1199 |
<?php _e('Settings','dropbox-backup'); ?>
|
1200 |
</div>
|
1201 |
<div id="setting_active" class="cfContentContainer" style="display: none;">
|
1202 |
+
<form method="post" action="" >
|
1203 |
<div class="stat-wpadm-registr-info" style="width: 100%; margin-bottom: 9px;">
|
1204 |
<div style="margin-bottom: 12px; margin-top: 20px; font-size: 15px; text-align: center;">
|
1205 |
<input class="btn-orange" type="button" style="padding: 5px 10px; font-size: 15px; font-weight: 500" onclick="connectDropbox(this,'<?php echo admin_url( 'admin-post.php?action=dropboxConnect' )?>')" value="<?php _e('Connect to Dropbox','dropbox-backup'); ?>" name="submit">
|
1206 |
+
<div class="desc-wpadm"><span id="dropbox_uid_text"><?php echo isset($dropbox_options['oauth_token']) && isset($dropbox_options['uid']) ? __('Dropbox successfully connected:','dropbox-backup') . " UID " . $dropbox_options['uid'] : ''; ?></span></div>
|
1207 |
</div>
|
1208 |
<?php $show_fields = isset($dropbox_options['app_key']) && !empty($dropbox_options['app_key']) && isset($dropbox_options['app_secret']) && !empty($dropbox_options['app_secret']) && $dropbox_options['app_key'] != WPADM_APP_KEY && $dropbox_options['app_secret'] != WPADM_APP_SECRET ; ?>
|
1209 |
<div class="setting-checkbox">
|
1217 |
<label for="app_key"><?php _e('App key','dropbox-backup'); ?>*</label>
|
1218 |
</th>
|
1219 |
<td>
|
1220 |
+
<input id="app_key" class="" type="text" name="app_key" value="<?php echo isset($dropbox_options['app_key']) && $dropbox_options['app_key'] != WPADM_APP_KEY ? $dropbox_options['app_key'] : ''?>">
|
1221 |
</td>
|
1222 |
</tr>
|
1223 |
<tr valign="top" id="dropbox-app-secret" style="display: <?php echo $show_fields ? 'table-row' : 'none'?>;">
|
1225 |
<label for="app_secret"><?php _e('App secret','dropbox-backup'); ?>*</label>
|
1226 |
</th>
|
1227 |
<td>
|
1228 |
+
<input id="app_secret" class="" type="text" name="app_secret" value="<?php echo isset($dropbox_options['app_secret']) && $dropbox_options['app_secret'] != WPADM_APP_SECRET ? $dropbox_options['app_secret'] : ''?>">
|
1229 |
</td>
|
1230 |
</tr>
|
1231 |
|
1242 |
<label for="time_error" style="font-size: 13px;"><?php _e('Waiting time (minutes)', 'dropbox-backup'); ?></label>
|
1243 |
<select name="time_error" id="time_error" onchange="saveSetting('time_error')">
|
1244 |
<?php
|
1245 |
+
for($i = 1; $i < 11; $i++) {
|
1246 |
?>
|
1247 |
<option value="<?php echo $i?>" <?php echo isset($dropbox_options['time_error']) && $dropbox_options['time_error'] == $i ? 'selected="selected"' : (!isset($dropbox_options['time_error']) && $i == $default ) ? 'selected="selected"' : '' ?> ><?php echo $i?>:00</option>
|
1248 |
<?php
|
1254 |
</div>
|
1255 |
<?php if ( is_super_admin() ) { ?>
|
1256 |
<div class="setting-checkbox">
|
1257 |
+
<input type="checkbox" <?php echo isset($dropbox_options['is_admin']) && $dropbox_options['is_admin'] == 1 ? 'checked="checked"' : ''; ?> name="is_admin" value="1" id="is_admin" onclick="saveSetting('is_admin')" />
|
1258 |
<label for="is_admin" style="font-size: 13px;"><?php _e('Appear in menu for admins only','dropbox-backup'); ?></label>
|
1259 |
</div>
|
1260 |
<?php } ?>
|
1261 |
<div class="setting-checkbox">
|
1262 |
+
<input type="checkbox" <?php echo (isset($dropbox_options['is_optimization']) && $dropbox_options['is_optimization'] == 1) || (!isset($dropbox_options['is_optimization'])) ? 'checked="checked"' : ''; ?> name="is_optimization" value="1" id="is_optimization" onclick="saveSetting('is_optimization')" />
|
1263 |
<label for="is_optimization" style="font-size: 13px;"><?php _e('Database Optimization','dropbox-backup'); ?></label>
|
1264 |
</div>
|
1265 |
<div class="setting-checkbox">
|
1266 |
+
<input type="checkbox" <?php echo (isset($dropbox_options['is_local_backup_delete']) && $dropbox_options['is_local_backup_delete'] == 1) ? 'checked="checked"' : ''; ?> name="is_local_backup_delete" value="1" id="is_local_backup_delete" onclick="saveSetting('is_local_backup_delete')" />
|
1267 |
<label for="is_local_backup_delete" style="font-size: 13px; width: 90%"><?php _e('Don\'t delete a local backup copy after uploading to dropbox','dropbox-backup'); ?></label>
|
1268 |
</div>
|
1269 |
<div class="setting-checkbox">
|
1270 |
+
<input type="checkbox" <?php echo (isset($dropbox_options['is_repair']) && $dropbox_options['is_repair'] == 1) ? 'checked="checked"' : ''; ?> name="is_repair" value="1" id="is_repair" onclick="saveSetting('is_repair')" />
|
1271 |
<label for="is_repair" style="font-size: 13px;"><?php _e('Try database repair','dropbox-backup'); ?></label>
|
1272 |
</div>
|
1273 |
<div class="setting-checkbox">
|
1274 |
+
<input type="checkbox" <?php echo (isset($dropbox_options['is_show_admin_bar']) && $dropbox_options['is_show_admin_bar'] == 1) ? 'checked="checked"' : ( !isset($dropbox_options['is_show_admin_bar']) ? 'checked="checked"' : '' ); ?> name="is_show_admin_bar" value="1" id="is_show_admin_bar" onclick="saveSetting('is_show_admin_bar')" />
|
1275 |
<label for="is_show_admin_bar" style="font-size: 13px;"><?php _e('Show in a admin bar','dropbox-backup'); ?></label>
|
1276 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1277 |
<div class="setting-checkbox">
|
1278 |
<?php _e('Include/Exclude','dropbox-backup'); ?>
|
1279 |
<a onclick="InludesSetting();" href="javascript:void(0);" style="color: #fff"><?php _e('Folders and files','dropbox-backup'); ?></a>
|
1280 |
</div>
|
1281 |
<div style="border-bottom:1px solid #fff; margin:10px 0px;"></div>
|
1282 |
<div class="setting-checkbox">
|
1283 |
+
<input type="text" style="width: 90%;" name="backup_folder" value="<?php echo ( isset($dropbox_options['backup_folder']) && !empty($dropbox_options['backup_folder']) ) ? $dropbox_options['backup_folder'] : DROPBOX_BACKUP_DIR_BACKUP; ?>" id="backup_folder" onclick="" />
|
1284 |
+
<label for="backup_folder" style="font-size: 13px;"><?php _e('Backup folder location','dropbox-backup'); ?></label>
|
|
|
|
|
|
|
|
|
|
|
1285 |
</div>
|
1286 |
+
<div class="setting-checkbox" style="text-align: center;">
|
1287 |
+
<input class="btn-orange" type="button" value="<?php echo _e('Save', 'dropbox-backup'); ?>" onclick="saveSetting('backup_folder');">
|
1288 |
</div>
|
1289 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
1290 |
</div>
|
1291 |
</form>
|
1292 |
</div>
|
1373 |
</div>
|
1374 |
</div>
|
1375 |
<div id="support-button" style="float: right; margin-top: 130px; margin-right: 20px;">
|
1376 |
+
<button onclick="window.open('<?php echo SERVER_URL_INDEX . 'support/?pl=dbp'?>')" class="backup_button" style="padding: 5px 10px; margin-top: 10px; font-size: 15px;bottom: 0px;"><?php _e('Help','dropbox-backup'); ?></button> <br />
|
1377 |
</div>
|
1378 |
<div id="action-buttons" style="">
|
1379 |
<div style="float: left;">
|
1393 |
</div>
|
1394 |
<div style="clear: both; margin-bottom: 10px;"></div>
|
1395 |
<div>
|
1396 |
+
<form action="<?php echo WPADM_URL_BASE;?>wpsite/recovery-backup" method="post" target="_blank" id="form_auth_backup" name="form_auth_backup">
|
1397 |
</form>
|
1398 |
+
<form action="<?php echo WPADM_URL_BASE;?>backup/tasks" method="post" target="_blank" id="form_auth_backup_create" name="form_auth_backup_create">
|
1399 |
+
<input type="hidden" name="url_task_create" value="<?php echo get_option('siteurl');?>">
|
1400 |
</form>
|
1401 |
<form action="" method="post" id="form_auth_backup" name="form_auth_backup">
|
1402 |
</form>
|
1403 |
<form action="<?php echo admin_url( 'admin-post.php?action=wpadm_delete_backup' )?>" method="post" id="delete_backups" name="delete_backups">
|
1404 |
<input type="hidden" name="backup-name" id="backup_name" value="" />
|
1405 |
<input type="hidden" name="backup-type" id="backup_type" value="" />
|
|
|
1406 |
</form>
|
1407 |
<form action="<?php echo admin_url( 'admin-post.php?action=stop_backup' )?>" method="post" id="stop_backups" name="stop_backups">
|
1408 |
<input type="hidden" name="type_backup" id="type_backup" value="" />
|
|
|
1409 |
</form>
|
1410 |
<div id="inludes-setting" class="" style="display: none; width: 550px; position: relative; text-align: center; background: #e5e5e5; border: 2px solid #dde4ff; border-radius: 5px;">
|
1411 |
<div>
|
1462 |
?>
|
1463 |
<tr>
|
1464 |
<td class="number-backup"><?php echo ($i + 1);?></td>
|
1465 |
+
<td onclick="shows('<?php echo md5( print_r($data['data'][$i], 1) );?>', this)" class="pointer" style="text-align: left; padding-left: 7px;"><?php echo $data['data'][$i]['dt'];?></td>
|
1466 |
+
<td onclick="shows('<?php echo md5( print_r($data['data'][$i], 1) );?>', this)" class="pointer" <?php echo (isset($is_runnig) && $is_runnig && isset($name_running_backup) && $name_running_backup == $data['data'][$i]['name'] ? 'style="text-align:left;"' : '')?>>
|
1467 |
<?php
|
1468 |
$e = '';
|
1469 |
if ( isset($is_runnig) && $is_runnig && isset($name_running_backup) && $name_running_backup == $data['data'][$i]['name']) {
|
1477 |
} else {
|
1478 |
$e = "<strong style=\"color:red;\">". __('Not available','dropbox-backup') . "</strong> (<a style=\"text-decoration:underline;\">".__('Why?','dropbox-backup')."</a>)";
|
1479 |
}
|
1480 |
+
echo $e;
|
1481 |
?>
|
1482 |
<script type="text/javascript">
|
1483 |
+
backup_name = '<?php echo $data['data'][$i]['name']?>';
|
1484 |
</script>
|
1485 |
</td>
|
1486 |
+
<td onclick="shows('<?php echo md5( print_r($data['data'][$i], 1) );?>', this)" class="pointer"><?php echo isset($data['data'][$i]['count']) ? $data['data'][$i]['count'] : $f ;?></td>
|
1487 |
+
<td onclick="shows('<?php echo md5( print_r($data['data'][$i], 1) );?>', this)" class="pointer" style="padding: 0px;">
|
1488 |
<?php if ( isset($is_runnig) && $is_runnig && isset($name_running_backup) && $name_running_backup == $data['data'][$i]['name'] ) { ?>
|
1489 |
<img src="<?php echo plugin_dir_url(__FILE__) . "attention.png" ;?>" title="Attention" alt="Attention" style="float: left; width: 20px; height: 20px;margin-left: 21px;" />
|
1490 |
<div style="margin-top :1px;float: left;"><?php _e('Backup in progress','dropbox-backup');?></div>
|
1508 |
<?php
|
1509 |
}?>
|
1510 |
</td>
|
1511 |
+
<td onclick="shows('<?php echo md5( print_r($data['data'][$i], 1) );?>', this)" class="pointer"><?php echo $data['data'][$i]['type'];?> <?php _e('backup','dropbox-backup'); ?></td>
|
1512 |
+
<td onclick="shows('<?php echo md5( print_r($data['data'][$i], 1) );?>', this)" class="pointer"><?php echo $size . __('Mb','dropbox-backup');?></td>
|
1513 |
<td>
|
1514 |
<?php if(is_admin() || is_super_admin()) {?>
|
1515 |
<?php if ($data['data'][$i]['size'] > 0) {
|
1519 |
<?php
|
1520 |
} else {
|
1521 |
?>
|
1522 |
+
<a class="button-wpadm" href="javascript:void(0)" title="<?php _e('Restore','dropbox-backup'); ?>" onclick="show_recovery_form('<?php echo isset($data['data'][$i]['name']) && $data['data'][$i]['type'] != 'local' ? $data['data'][$i]['name'] : 'local' ?>', '<?php echo $data['data'][$i]['name']?>')" style="color: #fff;"><span class="pointer dashicons dashicons-backup" style="margin-top:3px;"></span><?php _e('Restore','dropbox-backup'); ?></a>
|
1523 |
<?php }
|
1524 |
} ?>
|
1525 |
+
<a class="button-wpadm" href="javascript:void(0)" title="<?php _e('Delete','dropbox-backup'); ?>" onclick="delete_backup('<?php echo $data['data'][$i]['name']; ?>', '<?php echo $data['data'][$i]['type'];?>')" style="color: #fff;"><span class="pointer dashicons dashicons-trash" style="margin-top:3px;"></span><?php _e('Delete','dropbox-backup'); ?></a>
|
1526 |
<?php
|
1527 |
}
|
1528 |
?>
|
1529 |
</td>
|
1530 |
</tr>
|
1531 |
+
<tr id="<?php echo md5( print_r($data['data'][$i], 1) );?>" style="display:none; ">
|
1532 |
<?php if ($data['data'][$i]['size'] != 0) {?>
|
1533 |
<td colspan="2">
|
1534 |
</td>
|
1543 |
<tr style="border: 0;">
|
1544 |
<td style="border: 0;">
|
1545 |
<?php if ($data['data'][$i]['type'] == 'local') {?>
|
1546 |
+
<a href="<?php echo content_url(DROPBOX_BACKUP_DIR_NAME) . "/{$data['data'][$i]['name']}/{$files[$j]}"?>">
|
1547 |
+
<?php echo $files[$j]; ?>
|
1548 |
</a>
|
1549 |
<?php
|
1550 |
} else {
|
1551 |
+
echo $files[$j];
|
1552 |
}
|
1553 |
?>
|
1554 |
</td>
|
1569 |
?>
|
1570 |
<td colspan="8">
|
1571 |
<?php _e('Backup is created. If you are sure that the backup down(crashed), please ','dropbox-backup');?>
|
1572 |
+
<a href="javascript:void(0)" onclick="window.open('<?php echo SERVER_URL_INDEX . 'support/?pl=dbp'?>')"><?php _e('contact us','dropbox-backup'); ?></a>.
|
1573 |
</td>
|
1574 |
<?php
|
1575 |
} else { ?>
|
1608 |
<label for="ftp-host"><?php _e('FTP Host','dropbox-backup'); ?></label>
|
1609 |
</div>
|
1610 |
<div style="float:left; ">
|
1611 |
+
<input type="text" id="ftp-host" value="<?php echo str_ireplace(array('http://', 'https://'), '', home_url()) ;?>" name="ftp_host" >
|
1612 |
</div>
|
1613 |
</div>
|
1614 |
<div class="clear"></div>
|
1638 |
<label for="email-resp"><?php _e('Response Email:','dropbox-backup'); ?></label>
|
1639 |
</div>
|
1640 |
<div style=" ">
|
1641 |
+
<input type="text" id="email-resp" value="<?php echo get_option('admin_email');?>" style="padding-left:3px;" name="mail_response">
|
1642 |
</div>
|
1643 |
</div>
|
1644 |
</div>
|
1645 |
<div class="clear"></div>
|
1646 |
<div style="text-align: left; margin-left: 100px; margin-top: 10px;">
|
1647 |
+
<input value="<?php echo $time_log; ?>" type="hidden" name="time_pars">
|
1648 |
<input class="backup_button" style="font-size: 14px;font-weight: normal;padding: 3px;text-shadow: 0px;" type="submit" value="<?php _e('Send request to support','dropbox-backup'); ?>">
|
1649 |
</div>
|
1650 |
</form>
|