Version Description
Upgrade Notice
Download this release
Release Info
Developer | backup-dropbox |
Plugin | Backup & Restore Dropbox |
Version | 1.2.9.2 |
Comparing to | |
See all releases |
Code changes from version 1.5.1.4 to 1.2.9.2
- modules/class-wpadm-command.php → class-wpadm-command.php +13 -17
- modules/class-wpadm-core.php → class-wpadm-core.php +55 -134
- class-wpadm-method-class.php +26 -0
- modules/class-wpadm-result.php → class-wpadm-result.php +116 -129
- commands/class-wpadm-command-archive.php +44 -88
- commands/class-wpadm-command-mysqldump.php +21 -25
- commands/class-wpadm-command-mysqloptimize.php +22 -24
- commands/class-wpadm-command-restore-backup.php +5 -7
- commands/class-wpadm-command-send-to-dropbox.php +32 -88
- dropbox-backup.php +8 -25
- modules/errorHandler.php → errorHandler.php +0 -0
- functions/index.php +0 -1
- functions/wpadm.php +0 -294
- img/closebox.png +0 -0
- img/folder-loader.gif +0 -0
- img/how-to-enable-cron.png +0 -0
- languages/dropbox-backup.pot +0 -945
- languages/index.html +0 -10
- languages/index.php +0 -1
- libs/error.class.php +1 -5
- libs/index.php +0 -1
- libs/lang.class.php +37 -32
- libs/lang/index.php +0 -1
- libs/wpadm.server.main.class.php +132 -405
- main/index.php +0 -1
- main/wpadm-class-wp.php +0 -1116
- methods/class-wpadm-method-backup-delete.php +27 -38
- methods/class-wpadm-method-backup-list.php +44 -54
- methods/class-wpadm-method-backup.php +450 -505
- methods/class-wpadm-method-full-backup-dropbox.php +206 -253
- methods/class-wpadm-method-local-backup.php +261 -631
- methods/class-wpadm-method-local-restore.php +24 -45
- methods/class-wpadm-method-ping.php +1 -5
- methods/class-wpadm-method-queue-controller.php +15 -8
- methods/class-wpadm-method-reconnect.php +14 -17
- methods/class-wpadm-method-send-to-dropbox.php +50 -270
- methods/class-wpadm-method-update.php +3 -4
- modules/HttpFsockopen.php +0 -178
- modules/OAuthSimple.php +255 -256
- modules/archive.php +0 -784
- modules/class-wpadm-archive.php +41 -499
- modules/class-wpadm-command-context.php +0 -3
- modules/class-wpadm-command-factory.php +33 -41
- modules/class-wpadm-method-class.php +0 -40
- modules/class-wpadm-mysqldump.php +84 -263
- modules/class-wpadm-process.php +0 -100
- modules/class-wpadm-queue.php +36 -25
- modules/class-wpadm-running.php +0 -322
- modules/constant.php +0 -65
- modules/dropbox.class.php +176 -287
- modules/index.html +0 -10
- modules/pclzip.lib.php +3034 -3051
- modules/phpseclib/Crypt/AES.php +540 -540
- modules/phpseclib/Crypt/Blowfish.php +1468 -1468
- modules/phpseclib/Crypt/DES.php +646 -2536
modules/class-wpadm-command.php → class-wpadm-command.php
RENAMED
@@ -1,18 +1,14 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
*/
|
15 |
-
abstract function execute(WPAdm_Command_Context $context);
|
16 |
-
|
17 |
-
}
|
18 |
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class WPAdm_Сommand
|
4 |
+
*/
|
5 |
+
if (!class_exists('WPAdm_Сommand')) {
|
6 |
+
abstract class WPAdm_Сommand {
|
7 |
+
/**
|
8 |
+
* @param WPAdm_Command_Context $context
|
9 |
+
* @return boolean
|
10 |
+
*/
|
11 |
+
abstract function execute(WPAdm_Command_Context $context);
|
12 |
+
|
13 |
+
}
|
|
|
|
|
|
|
|
|
14 |
}
|
modules/class-wpadm-core.php → class-wpadm-core.php
RENAMED
@@ -1,112 +1,85 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
require_once
|
6 |
-
require_once
|
7 |
-
require_once DRBBACKUP_BASE_DIR . '/modules/class-wpadm-command-context.php';
|
8 |
-
require_once DRBBACKUP_BASE_DIR . '/modules/class-wpadm-queue.php';
|
9 |
-
require_once DRBBACKUP_BASE_DIR . '/modules/class-wpadm-running.php';
|
10 |
-
require_once DRBBACKUP_BASE_DIR . '/modules/class-wpadm-command-factory.php';
|
11 |
|
12 |
|
13 |
if (!class_exists('WPAdm_Core')) {
|
14 |
-
|
15 |
class WPAdm_Core {
|
16 |
|
17 |
/*
|
18 |
-
*
|
19 |
* @var array
|
20 |
*/
|
21 |
private $request = array();
|
22 |
|
23 |
/*
|
24 |
-
*
|
25 |
* @var string
|
26 |
*/
|
27 |
private $pub_key;
|
28 |
|
29 |
/*
|
30 |
-
*
|
31 |
* @var WPAdm_Result
|
32 |
*/
|
33 |
private $result;
|
34 |
|
35 |
private $plugin;
|
36 |
-
|
37 |
-
private $sign = false;
|
38 |
-
|
39 |
-
public $name = '',
|
40 |
-
$time = '';
|
41 |
-
|
42 |
-
public static $cron = true;
|
43 |
|
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 |
-
//
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
}
|
71 |
-
}
|
72 |
if ('connect' == $request['method']) {
|
73 |
$this->connect();
|
74 |
} elseif ('local' == $request['method']){
|
75 |
|
76 |
} elseif($obj = $this->getObject($request['method'], $request['params'])) {
|
77 |
-
if (
|
78 |
-
$this->
|
79 |
-
}
|
80 |
-
|
81 |
-
|
82 |
-
}
|
83 |
-
if (isset($obj->time)) {
|
84 |
-
$this->time = $obj->time;
|
85 |
-
}
|
86 |
-
$this->result = $obj->getResult();
|
87 |
}
|
|
|
88 |
} else {
|
89 |
-
$this->result->setError(
|
90 |
}
|
91 |
}
|
92 |
|
93 |
|
94 |
/**
|
95 |
-
*
|
96 |
* @return string
|
97 |
*/
|
98 |
static public function getTmpDir() {
|
99 |
$tmp_dir = self::$pl_dir . '/tmp';
|
100 |
self::mkdir($tmp_dir);
|
101 |
if (!file_exists($tmp_dir . '/index.php')) {
|
102 |
-
|
103 |
-
if (!file_exists($tmp_dir . '/index.php')) {
|
104 |
-
self::$error = ( sprintf( __('Backup creating<br /><br />Please check the permissions on folder "%s".<br />Failed to create folder.', 'dropbxo-backup'), $tmp_dir ) );
|
105 |
-
}
|
106 |
}
|
107 |
return $tmp_dir;
|
108 |
}
|
109 |
-
|
|
|
|
|
|
|
|
|
110 |
static public function getPluginDir() {
|
111 |
return self::$pl_dir;
|
112 |
}
|
@@ -117,15 +90,13 @@ if (!class_exists('WPAdm_Core')) {
|
|
117 |
* @return null|WPAdm_Method_Class
|
118 |
*/
|
119 |
private function getObject($method, $params) {
|
120 |
-
if (!preg_match("|[a-zA-Z0-9_
|
121 |
return null;
|
122 |
}
|
123 |
-
|
124 |
-
|
125 |
-
} else {
|
126 |
-
$method = strtolower($method);
|
127 |
-
}
|
128 |
$class_file = self::$pl_dir . "/methods/class-wpadm-method-" . str_replace('_', '-', $method) . ".php";
|
|
|
129 |
if (file_exists($class_file)) {
|
130 |
require_once $class_file;
|
131 |
$tmp = explode('_', str_replace('-', '_', $method));
|
@@ -136,25 +107,16 @@ if (!class_exists('WPAdm_Core')) {
|
|
136 |
|
137 |
$class_name = "WPAdm_Method_{$method}";
|
138 |
if (!class_exists($class_name)) {
|
139 |
-
$this->getResult()->setError(
|
140 |
$this->getResult()->setResult(WPAdm_result::WPADM_RESULT_ERROR);
|
141 |
return null;
|
142 |
}
|
143 |
-
|
144 |
-
WPAdm_Running::setCommand( strtolower($this->request['method']), $params );
|
145 |
-
WPAdm_Running::run();
|
146 |
-
self::$cron = true;
|
147 |
-
return true;
|
148 |
-
} else {
|
149 |
-
return new $class_name($params);
|
150 |
-
}
|
151 |
-
|
152 |
}
|
153 |
return null;
|
154 |
|
155 |
}
|
156 |
|
157 |
-
|
158 |
public static function getLog()
|
159 |
{
|
160 |
$file_log = self::getTmpDir() . '/log.log';
|
@@ -189,7 +151,7 @@ if (!class_exists('WPAdm_Core')) {
|
|
189 |
}
|
190 |
|
191 |
/*
|
192 |
-
*
|
193 |
*/
|
194 |
private function auth() {
|
195 |
$this->pub_key = get_option('wpadm_pub_key');
|
@@ -197,59 +159,47 @@ if (!class_exists('WPAdm_Core')) {
|
|
197 |
if ( in_array($this->request['method'], $methods_local) ) {
|
198 |
return true;
|
199 |
}
|
200 |
-
self::log($this->request['method']);
|
201 |
if (empty($this->pub_key)) {
|
202 |
if ('connect' == $this->request['method']) {
|
203 |
$this->pub_key = $this->request['params']['pub_key'];
|
204 |
} else {
|
205 |
-
$this->getResult()->setError(
|
206 |
return false;
|
207 |
}
|
208 |
} elseif ('connect' == $this->request['method']) {
|
209 |
if( $this->pub_key != $this->request['params']['pub_key'] ){
|
210 |
-
$this->getResult()->setError(
|
211 |
return false;
|
212 |
}
|
213 |
} elseif('queue_controller' == $this->request['method']) {
|
214 |
-
//todo:
|
215 |
return true;
|
216 |
|
217 |
}
|
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);
|
225 |
if (!$ret) {
|
226 |
-
$this->getResult()->setError(
|
227 |
}
|
228 |
return $ret;
|
229 |
}
|
230 |
-
|
231 |
-
|
232 |
/**
|
233 |
-
*
|
234 |
* @param $dir
|
235 |
*/
|
236 |
static public function mkdir($dir) {
|
237 |
if(!file_exists($dir)) {
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
} else {
|
242 |
-
//todo: права доступа
|
243 |
-
@file_put_contents($dir . '/index.php', '<?php echo "Hello World!"; ');
|
244 |
-
if ( !is_writable($dir . '/index.php') ) {
|
245 |
-
self::$error = str_replace("&s", $dir . '/index.php' , __('Backup creating<br /><br />Please check the permissions on file "&s". Failed to create file.','dropbox-backup') );
|
246 |
-
}
|
247 |
-
}
|
248 |
-
}
|
249 |
-
if (!file_exists($dir . '/.htaccess')) {
|
250 |
-
@file_put_contents($dir . '/.htaccess', 'DENY FROM ALL');
|
251 |
}
|
252 |
-
return self::$error;
|
253 |
}
|
254 |
|
255 |
/**
|
@@ -258,21 +208,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 |
-
|
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';
|
@@ -295,10 +237,8 @@ if (!class_exists('WPAdm_Core')) {
|
|
295 |
|
296 |
|
297 |
static public function log($txt, $class='') {
|
298 |
-
|
299 |
-
|
300 |
-
file_put_contents($log_file, date("Y-m-d H:i:s") ."\t{$class}\t{$txt}\n", FILE_APPEND);
|
301 |
-
}
|
302 |
}
|
303 |
|
304 |
/**
|
@@ -307,39 +247,20 @@ if (!class_exists('WPAdm_Core')) {
|
|
307 |
*/
|
308 |
static function rmdir($dir) {
|
309 |
if (is_dir($dir)) {
|
310 |
-
$
|
311 |
-
|
312 |
if ($f == '..' or $f == '.') {
|
313 |
continue;
|
314 |
}
|
315 |
-
if (is_dir($
|
316 |
-
self::rmdir($
|
317 |
}
|
318 |
-
if (file_exists($
|
319 |
-
@unlink($
|
320 |
}
|
321 |
}
|
322 |
@rmdir($dir);
|
323 |
-
} elseif (is_file($dir)) {
|
324 |
-
@unlink($dir);
|
325 |
}
|
326 |
}
|
327 |
-
static function dir_writeble($dir)
|
328 |
-
{
|
329 |
-
$error = self::mkdir($dir);
|
330 |
-
$ret = true;
|
331 |
-
if (!empty($dir)) {
|
332 |
-
@file_put_contents($dir . "/test", "Hello World!!!");
|
333 |
-
if (file_exists($dir . "/test")) {
|
334 |
-
if (!@is_writable($dir . "/test") && @filesize($dir . "/test") == 0) {
|
335 |
-
$ret = false;
|
336 |
-
}
|
337 |
-
} else {
|
338 |
-
$ret = false;
|
339 |
-
}
|
340 |
-
@unlink($dir . "/test");
|
341 |
-
}
|
342 |
-
return $ret;
|
343 |
-
}
|
344 |
}
|
345 |
}
|
1 |
<?php
|
2 |
+
require_once dirname(__FILE__) . '/class-wpadm-result.php';
|
3 |
+
require_once dirname(__FILE__) . '/class-wpadm-command.php';
|
4 |
+
require_once dirname(__FILE__) . '/modules/class-wpadm-command-context.php';
|
5 |
+
require_once dirname(__FILE__) . '/modules/class-wpadm-queue.php';
|
6 |
+
require_once dirname(__FILE__) . '/modules/class-wpadm-command-factory.php';
|
|
|
|
|
|
|
|
|
7 |
|
8 |
|
9 |
if (!class_exists('WPAdm_Core')) {
|
|
|
10 |
class WPAdm_Core {
|
11 |
|
12 |
/*
|
13 |
+
* "прилетевший" POST-запрос от админки($_POST)
|
14 |
* @var array
|
15 |
*/
|
16 |
private $request = array();
|
17 |
|
18 |
/*
|
19 |
+
* публичный ключ для проверки подписи
|
20 |
* @var string
|
21 |
*/
|
22 |
private $pub_key;
|
23 |
|
24 |
/*
|
25 |
+
* Результат выполнения запроса
|
26 |
* @var WPAdm_Result
|
27 |
*/
|
28 |
private $result;
|
29 |
|
30 |
private $plugin;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
public static $pl_dir;
|
33 |
|
|
|
|
|
|
|
|
|
34 |
public static $plugin_name;
|
35 |
|
|
|
|
|
36 |
|
37 |
+
public function __construct(array $request, $plugin = '', $plugin_dir = '') {
|
38 |
$this->result = new WPAdm_Result();
|
39 |
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
40 |
$this->request = $request;
|
|
|
|
|
|
|
41 |
$this->plugin = $plugin;
|
|
|
42 |
self::$pl_dir = $plugin_dir;
|
43 |
self::$plugin_name = $plugin;
|
44 |
+
// авторизация запроса
|
45 |
+
if (!$this->auth()) {
|
46 |
+
return;
|
47 |
+
};
|
|
|
|
|
48 |
if ('connect' == $request['method']) {
|
49 |
$this->connect();
|
50 |
} elseif ('local' == $request['method']){
|
51 |
|
52 |
} elseif($obj = $this->getObject($request['method'], $request['params'])) {
|
53 |
+
if (isset($obj->name)) {
|
54 |
+
$this->name = $obj->name;
|
55 |
+
}
|
56 |
+
if (isset($obj->time)) {
|
57 |
+
$this->time = $obj->time;
|
|
|
|
|
|
|
|
|
|
|
58 |
}
|
59 |
+
$this->result = $obj->getResult();
|
60 |
} else {
|
61 |
+
$this->result->setError('Unknown method "' . $request['method'] . '"');
|
62 |
}
|
63 |
}
|
64 |
|
65 |
|
66 |
/**
|
67 |
+
* Возвращает путь до папки временных файлов
|
68 |
* @return string
|
69 |
*/
|
70 |
static public function getTmpDir() {
|
71 |
$tmp_dir = self::$pl_dir . '/tmp';
|
72 |
self::mkdir($tmp_dir);
|
73 |
if (!file_exists($tmp_dir . '/index.php')) {
|
74 |
+
file_put_contents($tmp_dir . '/index.php', '');
|
|
|
|
|
|
|
75 |
}
|
76 |
return $tmp_dir;
|
77 |
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Возвращает путь до папки временных файлов
|
81 |
+
* @return string
|
82 |
+
*/
|
83 |
static public function getPluginDir() {
|
84 |
return self::$pl_dir;
|
85 |
}
|
90 |
* @return null|WPAdm_Method_Class
|
91 |
*/
|
92 |
private function getObject($method, $params) {
|
93 |
+
if (!preg_match("|[a-zA-Z0-9_]|", $method)) {
|
94 |
return null;
|
95 |
}
|
96 |
+
$method = mb_strtolower($method);
|
97 |
+
|
|
|
|
|
|
|
98 |
$class_file = self::$pl_dir . "/methods/class-wpadm-method-" . str_replace('_', '-', $method) . ".php";
|
99 |
+
|
100 |
if (file_exists($class_file)) {
|
101 |
require_once $class_file;
|
102 |
$tmp = explode('_', str_replace('-', '_', $method));
|
107 |
|
108 |
$class_name = "WPAdm_Method_{$method}";
|
109 |
if (!class_exists($class_name)) {
|
110 |
+
$this->getResult()->setError("Class '$class_name' not found");
|
111 |
$this->getResult()->setResult(WPAdm_result::WPADM_RESULT_ERROR);
|
112 |
return null;
|
113 |
}
|
114 |
+
return new $class_name($params);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
}
|
116 |
return null;
|
117 |
|
118 |
}
|
119 |
|
|
|
120 |
public static function getLog()
|
121 |
{
|
122 |
$file_log = self::getTmpDir() . '/log.log';
|
151 |
}
|
152 |
|
153 |
/*
|
154 |
+
* Авторизация запроса
|
155 |
*/
|
156 |
private function auth() {
|
157 |
$this->pub_key = get_option('wpadm_pub_key');
|
159 |
if ( in_array($this->request['method'], $methods_local) ) {
|
160 |
return true;
|
161 |
}
|
|
|
162 |
if (empty($this->pub_key)) {
|
163 |
if ('connect' == $this->request['method']) {
|
164 |
$this->pub_key = $this->request['params']['pub_key'];
|
165 |
} else {
|
166 |
+
$this->getResult()->setError('Activate site in WPAdm.com for work to plugins.');
|
167 |
return false;
|
168 |
}
|
169 |
} elseif ('connect' == $this->request['method']) {
|
170 |
if( $this->pub_key != $this->request['params']['pub_key'] ){
|
171 |
+
$this->getResult()->setError('Ошибка. Воспользуйтесь переподключением плагина.');
|
172 |
return false;
|
173 |
}
|
174 |
} elseif('queue_controller' == $this->request['method']) {
|
175 |
+
//todo: проверить, что запустили сами себя
|
176 |
return true;
|
177 |
|
178 |
}
|
179 |
|
180 |
$sign = md5(serialize($this->request['params']));
|
181 |
//openssl_public_decrypt($this->request['sign'], $request_sign, $this->pub_key);
|
182 |
+
$ret = $this->verifySignature($this->request['sign'], $this->request['sign2'], $this->pub_key, $sign);
|
183 |
|
184 |
|
185 |
//$ret = ($sign == $request_sign);
|
186 |
if (!$ret) {
|
187 |
+
$this->getResult()->setError("Неверная подпись");
|
188 |
}
|
189 |
return $ret;
|
190 |
}
|
191 |
+
|
192 |
+
|
193 |
/**
|
194 |
+
* Создаем папку
|
195 |
* @param $dir
|
196 |
*/
|
197 |
static public function mkdir($dir) {
|
198 |
if(!file_exists($dir)) {
|
199 |
+
mkdir($dir, 0755);
|
200 |
+
//todo: права доступа
|
201 |
+
file_put_contents($dir . '/index.php', '');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
}
|
|
|
203 |
}
|
204 |
|
205 |
/**
|
208 |
public function getResult() {
|
209 |
return $this->result;
|
210 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
|
212 |
|
213 |
public function verifySignature($sign, $sign2, $pub_key, $text) {
|
214 |
+
if (function_exists('openssl_public_decrypt')) {
|
215 |
openssl_public_decrypt($sign, $request_sign, $pub_key);
|
216 |
$ret = ($text == $request_sign);
|
217 |
+
return $ret;
|
218 |
} else {
|
219 |
set_include_path(get_include_path() . PATH_SEPARATOR . self::getPluginDir() . '/modules/phpseclib');
|
220 |
require_once 'Crypt/RSA.php';
|
237 |
|
238 |
|
239 |
static public function log($txt, $class='') {
|
240 |
+
$log_file = self::getTmpDir() . '/log.log';
|
241 |
+
file_put_contents($log_file, date("Y-m-d H:i:s") ."\t{$class}\t{$txt}\n", FILE_APPEND);
|
|
|
|
|
242 |
}
|
243 |
|
244 |
/**
|
247 |
*/
|
248 |
static function rmdir($dir) {
|
249 |
if (is_dir($dir)) {
|
250 |
+
$files = glob($dir. '/*');
|
251 |
+
foreach($files as $f) {
|
252 |
if ($f == '..' or $f == '.') {
|
253 |
continue;
|
254 |
}
|
255 |
+
if (is_dir($f)) {
|
256 |
+
self::rmdir($f);
|
257 |
}
|
258 |
+
if (file_exists($f)) {
|
259 |
+
@unlink($f);
|
260 |
}
|
261 |
}
|
262 |
@rmdir($dir);
|
|
|
|
|
263 |
}
|
264 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
}
|
266 |
}
|
class-wpadm-method-class.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
if (!class_exists('WPAdm_Method_Class')) {
|
5 |
+
abstract class WPAdm_Method_Class {
|
6 |
+
/**
|
7 |
+
* @var mixed
|
8 |
+
*/
|
9 |
+
protected $params;
|
10 |
+
|
11 |
+
/**
|
12 |
+
* @var WPAdm_result
|
13 |
+
*/
|
14 |
+
protected $result;
|
15 |
+
|
16 |
+
/**
|
17 |
+
* @param mixed $params
|
18 |
+
*/
|
19 |
+
public function __construct($params) {
|
20 |
+
$this->params = $params;
|
21 |
+
$this->result = new WPAdm_Result();
|
22 |
+
}
|
23 |
+
|
24 |
+
abstract function getResult();
|
25 |
+
}
|
26 |
+
}
|
modules/class-wpadm-result.php → class-wpadm-result.php
RENAMED
@@ -1,130 +1,117 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
public function
|
48 |
-
{
|
49 |
-
$this
|
50 |
-
}
|
51 |
-
|
52 |
-
/**
|
53 |
-
|
54 |
-
|
55 |
-
public function
|
56 |
-
{
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
$this->error
|
67 |
-
}
|
68 |
-
|
69 |
-
/**
|
70 |
-
|
71 |
-
|
72 |
-
public function
|
73 |
-
{
|
74 |
-
|
75 |
-
}
|
76 |
-
|
77 |
-
/**
|
78 |
-
|
79 |
-
|
80 |
-
public function
|
81 |
-
{
|
82 |
-
$this->size
|
83 |
-
}
|
84 |
-
|
85 |
-
/**
|
86 |
-
|
87 |
-
|
88 |
-
public function
|
89 |
-
{
|
90 |
-
|
91 |
-
}
|
92 |
-
|
93 |
-
/**
|
94 |
-
|
95 |
-
|
96 |
-
public function
|
97 |
-
{
|
98 |
-
$this->result
|
99 |
-
}
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
if ($all) {
|
119 |
-
return get_object_vars( $this );
|
120 |
-
} else {
|
121 |
-
return array(
|
122 |
-
'result' => $this->getResult(),
|
123 |
-
'error' => $this->getError(),
|
124 |
-
'data' => $this->getData(),
|
125 |
-
'size' => $this->getSize()
|
126 |
-
);
|
127 |
-
}
|
128 |
-
}
|
129 |
-
}
|
130 |
}
|
1 |
+
<?php
|
2 |
+
if (!class_exists('WPAdm_Result')) {
|
3 |
+
class WPAdm_Result {
|
4 |
+
/*
|
5 |
+
* Status of the request.
|
6 |
+
* Can be either a "success" - the request is successful,
|
7 |
+
* or "error" - in an error was encountered
|
8 |
+
* @var string
|
9 |
+
*/
|
10 |
+
private $result;
|
11 |
+
|
12 |
+
/*
|
13 |
+
* Text of the error that occurred during query execution
|
14 |
+
* @var string
|
15 |
+
*/
|
16 |
+
private $error = '';
|
17 |
+
|
18 |
+
/*
|
19 |
+
* Data obtained during query execution
|
20 |
+
* @var mixed
|
21 |
+
*/
|
22 |
+
private $data;
|
23 |
+
|
24 |
+
/*
|
25 |
+
* Total size of backup
|
26 |
+
*/
|
27 |
+
private $size;
|
28 |
+
|
29 |
+
const WPADM_RESULT_SUCCESS = 'success';
|
30 |
+
const WPADM_RESULT_ERROR = 'error';
|
31 |
+
|
32 |
+
public function __construct() {
|
33 |
+
$this->result = WPAdm_Result::WPADM_RESULT_ERROR;
|
34 |
+
}
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @param mixed $data
|
38 |
+
*/
|
39 |
+
public function setData($data)
|
40 |
+
{
|
41 |
+
$this->data = $data;
|
42 |
+
}
|
43 |
+
|
44 |
+
/**
|
45 |
+
* @return mixed
|
46 |
+
*/
|
47 |
+
public function getData()
|
48 |
+
{
|
49 |
+
return $this->data;
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* @param string $error
|
54 |
+
*/
|
55 |
+
public function setError($error)
|
56 |
+
{
|
57 |
+
WPAdm_Core::log($error);
|
58 |
+
$this->error = $error;
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* @return string
|
63 |
+
*/
|
64 |
+
public function getError()
|
65 |
+
{
|
66 |
+
return $this->error;
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* @param int $size
|
71 |
+
*/
|
72 |
+
public function setSize($size)
|
73 |
+
{
|
74 |
+
$this->size = $size;
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* @return int
|
79 |
+
*/
|
80 |
+
public function getSize()
|
81 |
+
{
|
82 |
+
return $this->size;
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* @param string $result
|
87 |
+
*/
|
88 |
+
public function setResult($result)
|
89 |
+
{
|
90 |
+
$this->result = $result;
|
91 |
+
}
|
92 |
+
|
93 |
+
/**
|
94 |
+
* @return string
|
95 |
+
*/
|
96 |
+
public function getResult()
|
97 |
+
{
|
98 |
+
return $this->result;
|
99 |
+
}
|
100 |
+
|
101 |
+
public function exchangeArray(array $a) {
|
102 |
+
$this->result = (isset($a['result'])) ? $a['result'] : '';
|
103 |
+
$this->data = (isset($a['data'])) ? $a['data'] : '';
|
104 |
+
$this->error = (isset($a['error'])) ? $a['error'] : '';
|
105 |
+
$this->size = (isset($a['size'])) ? $a['size'] : '';
|
106 |
+
}
|
107 |
+
|
108 |
+
public function toArray() {
|
109 |
+
return array(
|
110 |
+
'result' => $this->getResult(),
|
111 |
+
'error' => $this->getError(),
|
112 |
+
'data' => $this->getData(),
|
113 |
+
'size' => $this->getSize()
|
114 |
+
);
|
115 |
+
}
|
116 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
}
|
commands/class-wpadm-command-archive.php
CHANGED
@@ -1,89 +1,45 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
class WPadm_Command_Archive extends WPAdm_Сommand{
|
5 |
-
public function execute(WPAdm_Command_Context $context)
|
6 |
-
{
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
WPAdm_Running::setCommandResultData('archive', $files_archive);
|
46 |
-
WPAdm_Process::setInc( 'archiving', count($files) );
|
47 |
-
}
|
48 |
-
} else {
|
49 |
-
$context->setError( $archive->error );
|
50 |
-
return false;
|
51 |
-
}
|
52 |
-
} else {
|
53 |
-
return true;
|
54 |
-
}
|
55 |
-
}
|
56 |
-
} else {
|
57 |
-
return true;
|
58 |
-
}
|
59 |
-
} else {
|
60 |
-
return true;
|
61 |
-
}
|
62 |
-
}
|
63 |
-
return true;
|
64 |
-
|
65 |
-
}
|
66 |
-
|
67 |
-
private function getArchiveName($name)
|
68 |
-
{
|
69 |
-
//WPAdm_Core::log("{$name}-*.zip");
|
70 |
-
$archives = glob("{$name}-*.zip");
|
71 |
-
//WPAdm_Core::log( print_r($archives, 1) );
|
72 |
-
if (empty($archives)) {
|
73 |
-
return "{$name}-1.zip";
|
74 |
-
}
|
75 |
-
$n = count($archives);
|
76 |
-
$f = "{$name}-{$n}.zip";
|
77 |
-
return $f;
|
78 |
-
}
|
79 |
-
|
80 |
-
private function getNextArchiveName($name)
|
81 |
-
{
|
82 |
-
//WPAdm_Core::log("{$name}-*.zip");
|
83 |
-
$archives = glob("{$name}-*.zip");
|
84 |
-
$n = 1 + count($archives);
|
85 |
-
$a = "{$name}-{$n}.zip";
|
86 |
-
//WPAdm_Core::log($a);
|
87 |
-
return $a;
|
88 |
-
}
|
89 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
class WPadm_Command_Archive extends WPAdm_Сommand{
|
5 |
+
public function execute(WPAdm_Command_Context $context)
|
6 |
+
{
|
7 |
+
require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-archive.php';
|
8 |
+
$af = $this->getArchiveName($context->get('to_file'));
|
9 |
+
$archive = new WPAdm_Archive($af, $context->get('to_file') . '.md5');
|
10 |
+
$archive->setRemovePath($context->get('remove_path'));
|
11 |
+
$files = $context->get('files');
|
12 |
+
|
13 |
+
// если привышен максимальный размер архива, создадим новый
|
14 |
+
if (file_exists($af) && filesize($af) > $context->get('max_file_size')) {
|
15 |
+
//WPAdm_Core::log(filesize($af) . ', max=' . $context->get('max_file_size'));
|
16 |
+
$af = $this->getNextArchiveName($context->get('to_file'));
|
17 |
+
unset($archive);
|
18 |
+
$archive = new WPAdm_Archive($af, $context->get('to_file') . '.md5');
|
19 |
+
$archive->setRemovePath($context->get('remove_path'));
|
20 |
+
}
|
21 |
+
//WPAdm_Core::log('Add to archive ' . $af);
|
22 |
+
$archive->add(implode(',', $files));
|
23 |
+
return true;
|
24 |
+
}
|
25 |
+
|
26 |
+
private function getArchiveName($name)
|
27 |
+
{
|
28 |
+
$archives = glob("{$name}-*.zip");
|
29 |
+
if (empty($archives)) {
|
30 |
+
return "{$name}-1.zip";
|
31 |
+
}
|
32 |
+
$n = count($archives);
|
33 |
+
$f = "{$name}-{$n}.zip";
|
34 |
+
//$f = array_pop($archives);
|
35 |
+
return $f;
|
36 |
+
}
|
37 |
+
|
38 |
+
private function getNextArchiveName($name)
|
39 |
+
{
|
40 |
+
$arhives = glob("{$name}-*.zip");
|
41 |
+
$n = 1 + count($arhives);
|
42 |
+
$a = "{$name}-{$n}.zip";
|
43 |
+
return $a;
|
44 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
}
|
commands/class-wpadm-command-mysqldump.php
CHANGED
@@ -1,26 +1,22 @@
|
|
1 |
-
<?php
|
2 |
-
if (
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
$mysqldump->
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
}
|
23 |
-
return true;
|
24 |
-
}
|
25 |
-
}
|
26 |
}
|
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)
|
5 |
+
{
|
6 |
+
//WPAdm_Core::log(print_r($context, true));
|
7 |
+
require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
|
8 |
+
$mysqldump = new WPAdm_Mysqldump();
|
9 |
+
$mysqldump->host = $context->get('host');
|
10 |
+
$mysqldump->user = $context->get('user');
|
11 |
+
$mysqldump->password = $context->get('password');
|
12 |
+
|
13 |
+
try {
|
14 |
+
$mysqldump->mysqldump($context->get('db'), $context->get('to_file'));
|
15 |
+
} catch (Exception $e) {
|
16 |
+
$context->setError($e->getMessage());
|
17 |
+
return false;
|
18 |
+
}
|
19 |
+
return true;
|
20 |
+
}
|
21 |
+
}
|
|
|
|
|
|
|
|
|
22 |
}
|
commands/class-wpadm-command-mysqloptimize.php
CHANGED
@@ -1,24 +1,22 @@
|
|
1 |
-
<?php
|
2 |
-
if (
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
$mysqldump =
|
11 |
-
$mysqldump->
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
$
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
}
|
24 |
-
}
|
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)
|
5 |
+
{
|
6 |
+
//WPAdm_Core::log(print_r($context, true));
|
7 |
+
require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
|
8 |
+
$mysqldump = new WPAdm_Mysqldump();
|
9 |
+
$mysqldump->host = $context->get('host');
|
10 |
+
$mysqldump->user = $context->get('user');
|
11 |
+
$mysqldump->password = $context->get('password');
|
12 |
+
|
13 |
+
try {
|
14 |
+
$mysqldump->optimize($context->get('db'));
|
15 |
+
} catch (Exception $e) {
|
16 |
+
$context->setError($e->getMessage());
|
17 |
+
return false;
|
18 |
+
}
|
19 |
+
return true;
|
20 |
+
}
|
21 |
+
}
|
22 |
+
}
|
|
|
|
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 |
|
@@ -22,8 +19,8 @@ if (!class_exists('WPadm_Command_Restore_Backup')) {
|
|
22 |
}
|
23 |
|
24 |
if ($file_in_zip == 0) {
|
25 |
-
WPAdm_Core::log(
|
26 |
-
$context->setError(
|
27 |
return false;
|
28 |
}
|
29 |
//WPAdm_Core::log(print_r($file_in_zip, 1));
|
@@ -43,9 +40,10 @@ if (!class_exists('WPadm_Command_Restore_Backup')) {
|
|
43 |
}
|
44 |
}
|
45 |
}
|
|
|
46 |
} else {
|
47 |
-
$context->setError(
|
48 |
-
WPAdm_Core::log(
|
49 |
return false;
|
50 |
}
|
51 |
return true;
|
1 |
<?php
|
|
|
|
|
|
|
2 |
if (!class_exists('WPadm_Command_Restore_Backup')) {
|
3 |
class WPadm_Command_Restore_Backup extends WPAdm_Сommand {
|
4 |
|
19 |
}
|
20 |
|
21 |
if ($file_in_zip == 0) {
|
22 |
+
WPAdm_Core::log( "ERROR Archived: " . $this->archive->errorInfo(true) );
|
23 |
+
$context->setError( "ERROR Archived: " . $this->archive->errorInfo(true));
|
24 |
return false;
|
25 |
}
|
26 |
//WPAdm_Core::log(print_r($file_in_zip, 1));
|
40 |
}
|
41 |
}
|
42 |
}
|
43 |
+
|
44 |
} else {
|
45 |
+
$context->setError("File Archive Not Exist " . $context->get('zip_file'));
|
46 |
+
WPAdm_Core::log( "File Archive Not Exist " . $context->get('zip_file') );
|
47 |
return false;
|
48 |
}
|
49 |
return true;
|
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 {
|
@@ -9,96 +6,43 @@ if (!class_exists('WPadm_Command_Send_To_Dropbox')) {
|
|
9 |
public function execute(WPAdm_Command_Context $context)
|
10 |
{
|
11 |
@session_start();
|
12 |
-
|
13 |
-
require_once WPAdm_Core::getPluginDir() . '/modules/dropbox.class.php';
|
14 |
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
}
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
$
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
if (isset($delete_file['error'])) {
|
50 |
-
$context->setError( __('Dropbox returned an error during file sending: ' ,'dropbox-backup') . '"' . $delete_file['text'] . '"');
|
51 |
-
return false;
|
52 |
-
}
|
53 |
-
$data_error_command = WPAdm_Running::getCommandResultData('errors_sending');
|
54 |
-
if (isset($data_command[$fromFile])) {
|
55 |
-
$data_error_command[$fromFile]['count'] += 1;
|
56 |
-
} else {
|
57 |
-
$data_error_command[$fromFile] = array();
|
58 |
-
$data_error_command[$fromFile]['count'] = 1;
|
59 |
-
}
|
60 |
-
WPAdm_Running::setCommandResultData('errors_sending', $data_error_command);
|
61 |
-
}
|
62 |
-
} else {
|
63 |
-
$send = false;
|
64 |
-
}
|
65 |
-
}
|
66 |
-
if ( $local ) {
|
67 |
-
if ( WPAdm_Running::is_stop() ) {
|
68 |
-
$data_command = WPAdm_Running::getCommandResultData('command_dropbox');
|
69 |
-
$md5 = md5($fromFile);
|
70 |
-
if (empty($data_command) || !in_array($md5 ,$data_command) ) {
|
71 |
-
if ($send) {
|
72 |
-
$res = $dropbox->uploadFile($fromFile, $toFile, true);
|
73 |
-
} else {
|
74 |
-
$this->saveDataCommand($md5);
|
75 |
-
WPAdm_Process::setInc('dropbox', 1);
|
76 |
-
}
|
77 |
-
}
|
78 |
-
}
|
79 |
-
} else {
|
80 |
-
$md5 = md5($fromFile);
|
81 |
-
$res = $dropbox->uploadFile($fromFile, $toFile, true);
|
82 |
-
}
|
83 |
-
if (isset($res['error']) && isset($res['text']) && $res['error'] == 1) {
|
84 |
-
$context->setError( __('Dropbox returned an error during file sending: ' ,'dropbox-backup') . '"' . $res['text'] . '"');
|
85 |
-
return false;
|
86 |
-
}
|
87 |
-
if ( WPAdm_Running::is_stop() ) {
|
88 |
-
if (isset($res['size']) && isset($res['client_mtime'])) {
|
89 |
-
WPAdm_Core::log( __('File upload: ' ,'dropbox-backup') . basename( $files ) . __(' size: ' ,'dropbox-backup') . $res['size']);
|
90 |
-
$this->saveDataCommand($md5);
|
91 |
-
WPAdm_Process::setInc('dropbox', 1);
|
92 |
-
}
|
93 |
-
}
|
94 |
}
|
95 |
return true;
|
96 |
}
|
97 |
-
private function saveDataCommand($file)
|
98 |
-
{
|
99 |
-
$data_command = WPAdm_Running::getCommandResultData('command_dropbox');
|
100 |
-
$data_command[] = $file;
|
101 |
-
WPAdm_Running::setCommandResultData('command_dropbox', $data_command);
|
102 |
-
}
|
103 |
}
|
104 |
}
|
1 |
<?php
|
|
|
|
|
|
|
2 |
if (!class_exists('WPadm_Command_Send_To_Dropbox')) {
|
3 |
|
4 |
class WPadm_Command_Send_To_Dropbox extends WPAdm_Сommand {
|
6 |
public function execute(WPAdm_Command_Context $context)
|
7 |
{
|
8 |
@session_start();
|
9 |
+
require_once WPAdm_Core::getPluginDir() . '/modules/dropbox.class.php';
|
|
|
10 |
|
11 |
+
WPAdm_Core::log( langWPADM::get('Send to drop box files' , false) );
|
12 |
+
$dropbox = new dropbox($context->get('key'), $context->get('secret'), $context->get('token'));
|
13 |
|
14 |
+
//$token = $dropbox->getAccessToken($_SESSION['request_token']);
|
15 |
+
//WPAdm_Core::log('Token: ' . print_r($context->get('token'), true));
|
16 |
+
|
17 |
+
if (!$dropbox->isAuth()) {
|
18 |
+
$context->setError( langWPADM::get('Error auth in Dropbox' , false) );
|
19 |
+
return false;
|
20 |
+
}
|
21 |
+
$files = $context->get('files');
|
22 |
+
|
23 |
+
$file = explode("/", $files);
|
24 |
+
$file_name = array_pop($file);
|
25 |
+
$folder_project_temp = $context->get('folder_project');
|
26 |
+
$folder_project = "";
|
27 |
+
if (!empty($folder_project_temp)) {
|
28 |
+
$folder_project = $folder_project_temp . "/";
|
29 |
+
$dropbox->createDir($folder_project_temp );
|
30 |
+
$dropbox->createDir($folder_project . $context->get('folder') );
|
31 |
+
} else {
|
32 |
+
$dropbox->createDir($context->get('folder') );
|
33 |
+
}
|
|
|
34 |
|
35 |
+
$fromFile = str_replace('//', '/', $files);
|
36 |
+
$toFile = str_replace('//', '/', $folder_project . $context->get('folder') . '/' . $file_name);
|
37 |
+
$res = $dropbox->uploadFile($fromFile, $toFile);
|
38 |
+
if (isset($res['error']) && isset($res['text']) && $res['error'] == 1) {
|
39 |
+
$context->setError( langWPADM::get('Error: ' , false) . '"' . $res['text'] . '"');
|
40 |
+
return false;
|
41 |
+
}
|
42 |
+
if (isset($res['size']) && isset($res['client_mtime'])) {
|
43 |
+
WPAdm_Core::log( langWPADM::get('File upload: ' , false) . $files . langWPADM::get(' size: ' , false) . $res['size']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
}
|
45 |
return true;
|
46 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
}
|
48 |
}
|
dropbox-backup.php
CHANGED
@@ -2,43 +2,26 @@
|
|
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 |
*/
|
9 |
|
10 |
-
|
11 |
-
|
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';
|
23 |
|
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 |
{
|
39 |
wpadm_run('dropbox-backup', dirname(__FILE__));
|
40 |
}
|
41 |
}
|
42 |
|
43 |
-
|
44 |
-
|
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.2.9.2
|
|
|
|
|
6 |
*/
|
7 |
|
8 |
+
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'wpadm.php';
|
9 |
+
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'wpadm-class-wp.php';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
add_action('init', 'wpadm_full_backup_dropbox_run');
|
12 |
|
13 |
add_action('admin_print_scripts', array('wpadm_wp_full_backup_dropbox', 'include_admins_script' ));
|
14 |
+
add_action('admin_menu', array('wpadm_wp_full_backup_dropbox', 'draw_menu'));
|
|
|
|
|
|
|
|
|
15 |
add_action('admin_post_activate_wpadm_full_backup_dropbox', array('wpadm_wp_full_backup_dropbox', 'activatePlugin') );
|
16 |
|
17 |
+
if ( !get_option('wpadm_pub_key')/* && (is_admin())*/) {
|
18 |
+
add_action('admin_notices', 'wpadm_admin_notice');
|
19 |
+
}
|
20 |
|
21 |
+
if (!function_exists('wpadm_full_backup_dropbox_run')) {
|
|
|
22 |
function wpadm_full_backup_dropbox_run()
|
23 |
{
|
24 |
wpadm_run('dropbox-backup', dirname(__FILE__));
|
25 |
}
|
26 |
}
|
27 |
|
|
|
|
modules/errorHandler.php → errorHandler.php
RENAMED
File without changes
|
functions/index.php
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
<?php
|
|
functions/wpadm.php
DELETED
@@ -1,294 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
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] ) && isset( $_POST['sign'] ) && isset( $_POST['sign2'] ) ) {
|
20 |
-
require_once DRBBACKUP_BASE_DIR . '/modules/class-wpadm-core.php';
|
21 |
-
WPAdm_Core::$cron = false;
|
22 |
-
|
23 |
-
$user_ip = wpadm_getIp();
|
24 |
-
$core_sign = WPAdm_Core::getInstance();
|
25 |
-
$public_key = get_option('wpadm_pub_key', false);
|
26 |
-
$sign = false;
|
27 |
-
$sign_key = sanitize_text_field( $_POST['sign'] );
|
28 |
-
$sign2_key = sanitize_text_field( $_POST['sign2'] );
|
29 |
-
$verification_data = sanitize_text_field( $_POST[$request_name] );
|
30 |
-
if ($public_key && $core_sign->verifySignature( base64_decode( $sign_key ), base64_decode( $sign2_key ), $public_key, md5( $verification_data ) ) ) { // Signature verification check
|
31 |
-
if ($_SERVER['SERVER_ADDR'] != $user_ip && $_SERVER['HTTP_USER_AGENT'] != 'dropbox-backup user-agent') {
|
32 |
-
WPAdm_Running::init_params_default(false);
|
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' )) {
|
49 |
-
/**
|
50 |
-
* @param str $str
|
51 |
-
* @return mixed
|
52 |
-
*/
|
53 |
-
function wpadm_unpack( $str ) {
|
54 |
-
$str = base64_decode( $str );
|
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 |
-
if (defined('JSON_HEX_TAG') && defined('JSON_HEX_QUOT') && defined('JSON_HEX_AMP') && defined('JSON_HEX_APOS') ) {
|
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 |
-
|
102 |
-
if ( ! function_exists('wpadm_admin_notice')) {
|
103 |
-
function wpadm_admin_notice() {
|
104 |
-
|
105 |
-
}
|
106 |
-
}
|
107 |
-
|
108 |
-
|
109 |
-
if ( ! function_exists('wpadm_deactivation')) {
|
110 |
-
function wpadm_deactivation() {
|
111 |
-
wpadm_send_blog_info('deactivation');
|
112 |
-
}
|
113 |
-
}
|
114 |
-
|
115 |
-
|
116 |
-
if ( ! function_exists('wpadm_uninstall')) {
|
117 |
-
function wpadm_uninstall() {
|
118 |
-
wpadm_send_blog_info('uninstall');
|
119 |
-
}
|
120 |
-
}
|
121 |
-
|
122 |
-
|
123 |
-
if ( ! function_exists('wpadm_activation')) {
|
124 |
-
function wpadm_activation() {
|
125 |
-
wpadm_send_blog_info('activation');
|
126 |
-
}
|
127 |
-
}
|
128 |
-
|
129 |
-
if ( ! function_exists('wpadm_send_blog_info')) {
|
130 |
-
function wpadm_send_blog_info($status) {
|
131 |
-
$info = wpadm_get_blog_info();
|
132 |
-
$info['status'] = $status;
|
133 |
-
|
134 |
-
$data = wpadm_pack($info);
|
135 |
-
$host = WPADM_URL_BASE;
|
136 |
-
$host = str_replace(array('http://','https://'), '', trim($host,'/'));
|
137 |
-
$socket = fsockopen($host, 80, $errno, $errstr, 30);
|
138 |
-
fwrite($socket, "GET /wpsite/pluginHook?data={$data} HTTP/1.1\r\n");
|
139 |
-
fwrite($socket, "Host: {$host}\r\n");
|
140 |
-
|
141 |
-
fwrite($socket,"Content-type: application/x-www-form-urlencoded\r\n");
|
142 |
-
fwrite($socket,"Content-length:".strlen($data)."\r\n");
|
143 |
-
fwrite($socket,"Accept:*/*\r\n");
|
144 |
-
fwrite($socket,"User-agent:Opera 10.00\r\n");
|
145 |
-
fwrite($socket,"Connection:Close\r\n");
|
146 |
-
fwrite($socket,"\r\n");
|
147 |
-
sleep(1);
|
148 |
-
fclose($socket);
|
149 |
-
}
|
150 |
-
}
|
151 |
-
if (!function_exists('wpadm_getIp')) {
|
152 |
-
function wpadm_getIp()
|
153 |
-
{
|
154 |
-
$user_ip = '';
|
155 |
-
if ( getenv('REMOTE_ADDR') ){
|
156 |
-
$user_ip = getenv('REMOTE_ADDR');
|
157 |
-
}elseif ( getenv('HTTP_FORWARDED_FOR') ){
|
158 |
-
$user_ip = getenv('HTTP_FORWARDED_FOR');
|
159 |
-
}elseif ( getenv('HTTP_X_FORWARDED_FOR') ){
|
160 |
-
$user_ip = getenv('HTTP_X_FORWARDED_FOR');
|
161 |
-
}elseif ( getenv('HTTP_X_COMING_FROM') ){
|
162 |
-
$user_ip = getenv('HTTP_X_COMING_FROM');
|
163 |
-
}elseif ( getenv('HTTP_VIA') ){
|
164 |
-
$user_ip = getenv('HTTP_VIA');
|
165 |
-
}elseif ( getenv('HTTP_XROXY_CONNECTION') ){
|
166 |
-
$user_ip = getenv('HTTP_XROXY_CONNECTION');
|
167 |
-
}elseif ( getenv('HTTP_CLIENT_IP') ){
|
168 |
-
$user_ip = getenv('HTTP_CLIENT_IP');
|
169 |
-
}
|
170 |
-
|
171 |
-
$user_ip = trim($user_ip);
|
172 |
-
if ( empty($user_ip) ){
|
173 |
-
return '';
|
174 |
-
}
|
175 |
-
if ( !preg_match("/^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/", $user_ip) ){
|
176 |
-
return '';
|
177 |
-
}
|
178 |
-
return $user_ip;
|
179 |
-
}
|
180 |
-
}
|
181 |
-
|
182 |
-
if ( ! function_exists('wpadm_get_blog_info')) {
|
183 |
-
function wpadm_get_blog_info() {
|
184 |
-
$info = array(
|
185 |
-
'url' => get_site_url(),
|
186 |
-
'email' => get_option('admin_email')
|
187 |
-
);
|
188 |
-
$debug = debug_backtrace();
|
189 |
-
$info['debug'] = $debug;
|
190 |
-
$file = (is_array($debug[count($debug)-1]['args'][0]))?$debug[count($debug)-1]['args'][0][0] : $debug[count($debug)-1]['args'][0];
|
191 |
-
preg_match("|wpadm_.*wpadm_(.*)\.php|", $file, $m);
|
192 |
-
$info['plugin'] = '';
|
193 |
-
if (isset($m[1])) {
|
194 |
-
$info['plugin'] = $m[1];
|
195 |
-
}
|
196 |
-
|
197 |
-
return $info;
|
198 |
-
}
|
199 |
-
}
|
200 |
-
if ( ! function_exists( "wpadm_set_plugin" )) {
|
201 |
-
function wpadm_set_plugin($plugin_name = '')
|
202 |
-
{
|
203 |
-
if (!empty($plugin_name) && function_exists("wpadm_run")) {
|
204 |
-
$GLOBALS['wpadm_plugin'][] = $plugin_name;
|
205 |
-
}
|
206 |
-
}
|
207 |
-
}
|
208 |
-
if (!function_exists('wpadm_in_array')) {
|
209 |
-
function wpadm_in_array($value, $key, $array, $ids = false)
|
210 |
-
{
|
211 |
-
if (is_array($array)) {
|
212 |
-
foreach($array as $k => $v) {
|
213 |
-
if (!is_array($v) && $k == $key && $v == $value) {
|
214 |
-
if ($ids) {
|
215 |
-
return $k;
|
216 |
-
}
|
217 |
-
return true;
|
218 |
-
} elseif (is_array($v) && isset($v[$key]) && $v[$key] == $value ) {
|
219 |
-
if ($ids) {
|
220 |
-
return $k;
|
221 |
-
}
|
222 |
-
return true;
|
223 |
-
}
|
224 |
-
}
|
225 |
-
}
|
226 |
-
return false;
|
227 |
-
}
|
228 |
-
}
|
229 |
-
if (function_exists('wpadm_getKey')) {
|
230 |
-
function wpadm_getKey($array, $key)
|
231 |
-
{
|
232 |
-
$return = array();
|
233 |
-
if (empty($array) && ($n = count($array)) > 0) {
|
234 |
-
for($i = 0; $i < $n; $i++) {
|
235 |
-
if (isset($array[$i]['key']) && is_array($key) && in_array($array[$i]['key'], $key) ) {
|
236 |
-
$return[] = $i;
|
237 |
-
} elseif(isset($array[$i]['key']) && is_string($key) ) {
|
238 |
-
$return[] = $i;
|
239 |
-
}
|
240 |
-
}
|
241 |
-
}
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
img/closebox.png
DELETED
Binary file
|
img/folder-loader.gif
DELETED
Binary file
|
img/how-to-enable-cron.png
DELETED
Binary file
|
languages/dropbox-backup.pot
DELETED
@@ -1,945 +0,0 @@
|
|
1 |
-
#, fuzzy
|
2 |
-
msgid ""
|
3 |
-
msgstr ""
|
4 |
-
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
|
5 |
-
"Project-Id-Version: Dropbox Backup & Restore\n"
|
6 |
-
"POT-Creation-Date: 2016-02-01 11:31+0300\n"
|
7 |
-
"PO-Revision-Date: 2016-02-01 11:31+0300\n"
|
8 |
-
"Last-Translator: \n"
|
9 |
-
"Language-Team: \n"
|
10 |
-
"MIME-Version: 1.0\n"
|
11 |
-
"Content-Type: text/plain; charset=UTF-8\n"
|
12 |
-
"Content-Transfer-Encoding: 8bit\n"
|
13 |
-
"X-Generator: Poedit 1.8.6\n"
|
14 |
-
"X-Poedit-Basepath: ..\n"
|
15 |
-
"X-Poedit-WPHeader: dropbox-backup.php\n"
|
16 |
-
"X-Poedit-SourceCharset: UTF-8\n"
|
17 |
-
"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;"
|
18 |
-
"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;"
|
19 |
-
"_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
|
20 |
-
"X-Poedit-SearchPath-0: .\n"
|
21 |
-
"X-Poedit-SearchPathExcluded-0: *.js\n"
|
22 |
-
|
23 |
-
#: commands/class-wpadm-command-archive.php:15
|
24 |
-
#: commands/class-wpadm-command-archive.php:21
|
25 |
-
msgid "Create part "
|
26 |
-
msgstr ""
|
27 |
-
|
28 |
-
#: commands/class-wpadm-command-restore-backup.php:22
|
29 |
-
#: commands/class-wpadm-command-restore-backup.php:23
|
30 |
-
#, php-format
|
31 |
-
msgid "Website \"%d\" returned an error during archive extracting: "
|
32 |
-
msgstr ""
|
33 |
-
|
34 |
-
#: commands/class-wpadm-command-restore-backup.php:44
|
35 |
-
#: commands/class-wpadm-command-restore-backup.php:45
|
36 |
-
#, php-format
|
37 |
-
msgid ""
|
38 |
-
"Website \"%d\" returned an error: The necessary file of archive \"%f\" "
|
39 |
-
"wasn't found "
|
40 |
-
msgstr ""
|
41 |
-
|
42 |
-
#: commands/class-wpadm-command-send-to-dropbox.php:11
|
43 |
-
msgid "Send to dropbox files"
|
44 |
-
msgstr ""
|
45 |
-
|
46 |
-
#: commands/class-wpadm-command-send-to-dropbox.php:15
|
47 |
-
#: main/wpadm-class-wp.php:319
|
48 |
-
msgid ""
|
49 |
-
"Website \"%d\" can't authorize on Dropbox with using of \"app key: %k\" and "
|
50 |
-
"\"app secret: %s\""
|
51 |
-
msgstr ""
|
52 |
-
|
53 |
-
#: commands/class-wpadm-command-send-to-dropbox.php:42
|
54 |
-
#: commands/class-wpadm-command-send-to-dropbox.php:70
|
55 |
-
msgid "Dropbox returned an error during file sending: "
|
56 |
-
msgstr ""
|
57 |
-
|
58 |
-
#: commands/class-wpadm-command-send-to-dropbox.php:74
|
59 |
-
msgid "File upload: "
|
60 |
-
msgstr ""
|
61 |
-
|
62 |
-
#: commands/class-wpadm-command-send-to-dropbox.php:74
|
63 |
-
msgid " size: "
|
64 |
-
msgstr ""
|
65 |
-
|
66 |
-
#: libs/wpadm.server.main.class.php:144
|
67 |
-
msgid "Your request was sent. <br /> Thank you for your assistance."
|
68 |
-
msgstr ""
|
69 |
-
|
70 |
-
#: main/wpadm-class-wp.php:78
|
71 |
-
msgid "1 day"
|
72 |
-
msgstr ""
|
73 |
-
|
74 |
-
#: main/wpadm-class-wp.php:81
|
75 |
-
msgid "1 week"
|
76 |
-
msgstr ""
|
77 |
-
|
78 |
-
#: main/wpadm-class-wp.php:218 main/wpadm-class-wp.php:567
|
79 |
-
#, php-format
|
80 |
-
msgid ""
|
81 |
-
"Website \"%domain\" returned an error during file creation: Failed to create "
|
82 |
-
"file, please check the permissions on the folder \"%dir-backup\"."
|
83 |
-
msgstr ""
|
84 |
-
|
85 |
-
#: main/wpadm-class-wp.php:280
|
86 |
-
msgid "Start Restore from Dropbox cloud"
|
87 |
-
msgstr ""
|
88 |
-
|
89 |
-
#: main/wpadm-class-wp.php:306
|
90 |
-
msgid "Error: "
|
91 |
-
msgstr ""
|
92 |
-
|
93 |
-
#: main/wpadm-class-wp.php:308
|
94 |
-
#, php-format
|
95 |
-
msgid "Download file (%s) with Dropbox"
|
96 |
-
msgstr ""
|
97 |
-
|
98 |
-
#: main/wpadm-class-wp.php:324 main/wpadm-class-wp.php:474
|
99 |
-
#: main/wpadm-class-wp.php:510
|
100 |
-
#, php-format
|
101 |
-
msgid ""
|
102 |
-
"Website \"%d\" returned an error during connection to Dropbox: \"app key\" "
|
103 |
-
"and \"app secret\" wasn't found. Please, check your Dropbox settings."
|
104 |
-
msgstr ""
|
105 |
-
|
106 |
-
#: main/wpadm-class-wp.php:402 main/wpadm-class-wp.php:413
|
107 |
-
#, php-format
|
108 |
-
msgid "Backup(%s) was deleted"
|
109 |
-
msgstr ""
|
110 |
-
|
111 |
-
#: main/wpadm-class-wp.php:498
|
112 |
-
#, php-format
|
113 |
-
msgid ""
|
114 |
-
"Website \"%d\" returned an error during connection to Dropbox: \"App Key\" "
|
115 |
-
"wasn't found. Please, check your Dropbox settings."
|
116 |
-
msgstr ""
|
117 |
-
|
118 |
-
#: main/wpadm-class-wp.php:502
|
119 |
-
#, php-format
|
120 |
-
msgid ""
|
121 |
-
"Website \"%d\" returned an error during connection to Dropbox: \"App Secret"
|
122 |
-
"\" wasn't found. Please, check your Dropbox settings."
|
123 |
-
msgstr ""
|
124 |
-
|
125 |
-
#: main/wpadm-class-wp.php:506
|
126 |
-
#, php-format
|
127 |
-
msgid ""
|
128 |
-
"Website \"%d\" returned an error during file sending to Dropbox: \"Auth "
|
129 |
-
"Token not exist. Files cannot be sent to Dropbox cloud. Please, check your "
|
130 |
-
"Dropbox settings.\""
|
131 |
-
msgstr ""
|
132 |
-
|
133 |
-
#: main/wpadm-class-wp.php:619
|
134 |
-
msgid "Checkout was canceled"
|
135 |
-
msgstr ""
|
136 |
-
|
137 |
-
#: main/wpadm-class-wp.php:644
|
138 |
-
msgid ""
|
139 |
-
"The \"Dropbox backup & restore PRO\" version can be downloaded here <a href="
|
140 |
-
"\"&s\">download</a>"
|
141 |
-
msgstr ""
|
142 |
-
|
143 |
-
#: methods/class-wpadm-method-backup.php:119
|
144 |
-
#: methods/class-wpadm-method-local-backup.php:118
|
145 |
-
#, php-format
|
146 |
-
msgid ""
|
147 |
-
"Website \"%domain\" returned an error during database dump creation: 'Dump "
|
148 |
-
"of Database wasn't created: \"%s\"'. To solve this problem, please check "
|
149 |
-
"your database system logs or send to us your FTP access data. You can send "
|
150 |
-
"to us support request using \"Help\" button on plugin page."
|
151 |
-
msgstr ""
|
152 |
-
|
153 |
-
#: methods/class-wpadm-method-backup.php:123
|
154 |
-
#: methods/class-wpadm-method-local-backup.php:122
|
155 |
-
#, php-format
|
156 |
-
msgid ""
|
157 |
-
"Website \"%domain\" returned an error during database dump creation: "
|
158 |
-
"Database-Dump file is emplty. To solve this problem, please check "
|
159 |
-
"permissions to folder: \"%dir\"."
|
160 |
-
msgstr ""
|
161 |
-
|
162 |
-
#: methods/class-wpadm-method-backup.php:128
|
163 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:131
|
164 |
-
#, php-format
|
165 |
-
msgid "Database Dump was successfully created ( %s Mb) : "
|
166 |
-
msgstr ""
|
167 |
-
|
168 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:82
|
169 |
-
msgid "Start backup"
|
170 |
-
msgstr ""
|
171 |
-
|
172 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:85
|
173 |
-
msgid "Start create db dump"
|
174 |
-
msgstr ""
|
175 |
-
|
176 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:99
|
177 |
-
msgid "Table optimization"
|
178 |
-
msgstr ""
|
179 |
-
|
180 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:123
|
181 |
-
#, php-format
|
182 |
-
msgid "Error: Dump of Database wasn't created (%s)"
|
183 |
-
msgstr ""
|
184 |
-
|
185 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:127
|
186 |
-
msgid "MySQL Error: Database-Dump File is empty"
|
187 |
-
msgstr ""
|
188 |
-
|
189 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:128
|
190 |
-
msgid "Dump of Database wasn't created (File of Database-Dump is empty!)"
|
191 |
-
msgstr ""
|
192 |
-
|
193 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:138
|
194 |
-
msgid "Create a list of files for Backup"
|
195 |
-
msgstr ""
|
196 |
-
|
197 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:145
|
198 |
-
msgid "Error: the list of Backup files is empty"
|
199 |
-
msgstr ""
|
200 |
-
|
201 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:167
|
202 |
-
#: methods/class-wpadm-method-local-backup.php:175
|
203 |
-
msgid "List of Backup-Files was successfully created"
|
204 |
-
msgstr ""
|
205 |
-
|
206 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:182
|
207 |
-
#: methods/class-wpadm-method-local-backup.php:194
|
208 |
-
msgid "Backup of Files was started"
|
209 |
-
msgstr ""
|
210 |
-
|
211 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:185
|
212 |
-
#: methods/class-wpadm-method-local-backup.php:196
|
213 |
-
msgid "End of File Backup"
|
214 |
-
msgstr ""
|
215 |
-
|
216 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:202
|
217 |
-
msgid "Begin copying files to FTP"
|
218 |
-
msgstr ""
|
219 |
-
|
220 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:225
|
221 |
-
msgid "FTP: "
|
222 |
-
msgstr ""
|
223 |
-
|
224 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:229
|
225 |
-
msgid "Finished copying files to FTP"
|
226 |
-
msgstr ""
|
227 |
-
|
228 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:234
|
229 |
-
msgid "Begin coping files to S3"
|
230 |
-
msgstr ""
|
231 |
-
|
232 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:258
|
233 |
-
msgid "Finished copying files to S3"
|
234 |
-
msgstr ""
|
235 |
-
|
236 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:266
|
237 |
-
msgid "Remove the backup server"
|
238 |
-
msgstr ""
|
239 |
-
|
240 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:275
|
241 |
-
msgid "files to google: "
|
242 |
-
msgstr ""
|
243 |
-
|
244 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:292
|
245 |
-
msgid "Google drive: "
|
246 |
-
msgstr ""
|
247 |
-
|
248 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:300
|
249 |
-
msgid "files to dropbox: "
|
250 |
-
msgstr ""
|
251 |
-
|
252 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:317
|
253 |
-
msgid "Dropbox: "
|
254 |
-
msgstr ""
|
255 |
-
|
256 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:325
|
257 |
-
msgid "Start removing old backups"
|
258 |
-
msgstr ""
|
259 |
-
|
260 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:346
|
261 |
-
msgid "Finished removing old backups"
|
262 |
-
msgstr ""
|
263 |
-
|
264 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:348
|
265 |
-
msgid "Creating a backup is completed"
|
266 |
-
msgstr ""
|
267 |
-
|
268 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:397
|
269 |
-
msgid "Skip file "
|
270 |
-
msgstr ""
|
271 |
-
|
272 |
-
#: methods/class-wpadm-method-full-backup-dropbox.php:492
|
273 |
-
msgid "Skip dir "
|
274 |
-
msgstr ""
|
275 |
-
|
276 |
-
#: methods/class-wpadm-method-local-backup.php:18
|
277 |
-
#: methods/class-wpadm-method-local-restore.php:28
|
278 |
-
msgid "Create Unique Id "
|
279 |
-
msgstr ""
|
280 |
-
|
281 |
-
#: methods/class-wpadm-method-local-backup.php:71
|
282 |
-
msgid "Start Backup process..."
|
283 |
-
msgstr ""
|
284 |
-
|
285 |
-
#: methods/class-wpadm-method-local-backup.php:78
|
286 |
-
msgid "Creating Database Dump"
|
287 |
-
msgstr ""
|
288 |
-
|
289 |
-
#: methods/class-wpadm-method-local-backup.php:93
|
290 |
-
msgid "Optimize Database Tables"
|
291 |
-
msgstr ""
|
292 |
-
|
293 |
-
#: methods/class-wpadm-method-local-backup.php:127
|
294 |
-
#, php-format
|
295 |
-
msgid "Database Dump was successfully created ( %size Mb) : "
|
296 |
-
msgstr ""
|
297 |
-
|
298 |
-
#: methods/class-wpadm-method-local-backup.php:148
|
299 |
-
#, php-format
|
300 |
-
msgid ""
|
301 |
-
"Website \"%d\" returned an error during creation of the list of files for a "
|
302 |
-
"backup: list of files for a backup is empty. To solve this problem, please "
|
303 |
-
"check files and folders permissions for website \"%d\"."
|
304 |
-
msgstr ""
|
305 |
-
|
306 |
-
#: methods/class-wpadm-method-local-backup.php:215
|
307 |
-
#, php-format
|
308 |
-
msgid "Backup Size %s Mb"
|
309 |
-
msgstr ""
|
310 |
-
|
311 |
-
#: methods/class-wpadm-method-local-backup.php:224
|
312 |
-
msgid "Limits of Backups "
|
313 |
-
msgstr ""
|
314 |
-
|
315 |
-
#: methods/class-wpadm-method-local-backup.php:225
|
316 |
-
msgid "Removing of old Backups was started"
|
317 |
-
msgstr ""
|
318 |
-
|
319 |
-
#: methods/class-wpadm-method-local-backup.php:244
|
320 |
-
msgid "Removing of old Backups was Finished"
|
321 |
-
msgstr ""
|
322 |
-
|
323 |
-
#: methods/class-wpadm-method-local-backup.php:256
|
324 |
-
msgid "Backup creation was complete successfully!"
|
325 |
-
msgstr ""
|
326 |
-
|
327 |
-
#: methods/class-wpadm-method-local-backup.php:298
|
328 |
-
#: methods/class-wpadm-method-local-backup.php:385
|
329 |
-
msgid "Skip of File "
|
330 |
-
msgstr ""
|
331 |
-
|
332 |
-
#: methods/class-wpadm-method-local-backup.php:349
|
333 |
-
#: methods/class-wpadm-method-local-backup.php:397
|
334 |
-
msgid "Skip of Folder "
|
335 |
-
msgstr ""
|
336 |
-
|
337 |
-
#: methods/class-wpadm-method-local-backup.php:362
|
338 |
-
msgid "Skip of Cache-Folder "
|
339 |
-
msgstr ""
|
340 |
-
|
341 |
-
#: methods/class-wpadm-method-local-restore.php:47
|
342 |
-
#, php-format
|
343 |
-
msgid ""
|
344 |
-
"Website \"%d\" returned an error during backup restoration: Archive of "
|
345 |
-
"Backup wasn't found \"%s\""
|
346 |
-
msgstr ""
|
347 |
-
|
348 |
-
#: methods/class-wpadm-method-local-restore.php:90
|
349 |
-
msgid "Start Restore process"
|
350 |
-
msgstr ""
|
351 |
-
|
352 |
-
#: methods/class-wpadm-method-local-restore.php:128
|
353 |
-
#, php-format
|
354 |
-
msgid ""
|
355 |
-
"Website \"%d\" returned an error during backup restoration: Part Backup is "
|
356 |
-
"not exist \"%s\" "
|
357 |
-
msgstr ""
|
358 |
-
|
359 |
-
#: methods/class-wpadm-method-local-restore.php:138
|
360 |
-
#, php-format
|
361 |
-
msgid ""
|
362 |
-
"Website \"%d\" returned an error during restore backup: Files for restore is "
|
363 |
-
"not exist, check permission your backup data or You can send to us support "
|
364 |
-
"request using \"Help\" button on plugin page."
|
365 |
-
msgstr ""
|
366 |
-
|
367 |
-
#: methods/class-wpadm-method-queue-controller.php:69
|
368 |
-
#, php-format
|
369 |
-
msgid ""
|
370 |
-
"Website \"%d\" returned an error: Command \"%com\" not found. To solve this "
|
371 |
-
"problem, we need to access the system logs of your hosting/server and/or "
|
372 |
-
"from your backup, that you tried to create or simply send to us your FTP "
|
373 |
-
"access data. You can send to us support request using \"Help\" button on "
|
374 |
-
"plugin page."
|
375 |
-
msgstr ""
|
376 |
-
|
377 |
-
#: methods/class-wpadm-method-queue-controller.php:75
|
378 |
-
#, php-format
|
379 |
-
msgid ""
|
380 |
-
"Website \"%d\" returned some unknown error during command \"%com\" was "
|
381 |
-
"running. To solve this problem, we need to access the system logs of your "
|
382 |
-
"hosting/server and/or from your backup, that you tried to create or simply "
|
383 |
-
"send to us your FTP access data. You can send to us support request using "
|
384 |
-
"\"Help\" button on plugin page."
|
385 |
-
msgstr ""
|
386 |
-
|
387 |
-
#: methods/class-wpadm-method-send-to-dropbox.php:49
|
388 |
-
msgid ""
|
389 |
-
"Not perhaps sending file: \"%file%\". If you wish make upload file, increase "
|
390 |
-
"execution time code or speed internet provider is small for upload file."
|
391 |
-
msgstr ""
|
392 |
-
|
393 |
-
#: methods/class-wpadm-method-send-to-dropbox.php:75
|
394 |
-
msgid "Start copy to Dropbox Cloud"
|
395 |
-
msgstr ""
|
396 |
-
|
397 |
-
#: methods/class-wpadm-method-send-to-dropbox.php:77
|
398 |
-
msgid "End Copy Files to Dropbox"
|
399 |
-
msgstr ""
|
400 |
-
|
401 |
-
#: methods/class-wpadm-method-send-to-dropbox.php:80
|
402 |
-
#: methods/class-wpadm-method-send-to-dropbox.php:81
|
403 |
-
msgid "Answer from Dropbox "
|
404 |
-
msgstr ""
|
405 |
-
|
406 |
-
#: methods/class-wpadm-method-update.php:16
|
407 |
-
msgid "Error to copy file "
|
408 |
-
msgstr ""
|
409 |
-
|
410 |
-
#: methods/class-wpadm-method-update.php:19
|
411 |
-
msgid "Error to extract file "
|
412 |
-
msgstr ""
|
413 |
-
|
414 |
-
#: modules/class-wpadm-core.php:223 modules/class-wpadm-core.php:228
|
415 |
-
msgid ""
|
416 |
-
"Failed to create a file, please check the permissions on the folders \"&s\"."
|
417 |
-
msgstr ""
|
418 |
-
|
419 |
-
#: modules/class-wpadm-mysqldump.php:28
|
420 |
-
msgid "MySQL Connect failed: "
|
421 |
-
msgstr ""
|
422 |
-
|
423 |
-
#: modules/class-wpadm-mysqldump.php:49
|
424 |
-
msgid "Optimize Database Tables was started"
|
425 |
-
msgstr ""
|
426 |
-
|
427 |
-
#: modules/class-wpadm-mysqldump.php:65
|
428 |
-
#, php-format
|
429 |
-
msgid "Error to Optimize Table `%s`"
|
430 |
-
msgstr ""
|
431 |
-
|
432 |
-
#: modules/class-wpadm-mysqldump.php:68
|
433 |
-
#, php-format
|
434 |
-
msgid "Optimize Table `%s` was successfully"
|
435 |
-
msgstr ""
|
436 |
-
|
437 |
-
#: modules/class-wpadm-mysqldump.php:73
|
438 |
-
msgid "Optimize Database Tables was Finished"
|
439 |
-
msgstr ""
|
440 |
-
|
441 |
-
#: modules/class-wpadm-mysqldump.php:86
|
442 |
-
msgid "MySQL of Dump was started"
|
443 |
-
msgstr ""
|
444 |
-
|
445 |
-
#: modules/class-wpadm-mysqldump.php:130
|
446 |
-
#, php-format
|
447 |
-
msgid "Add a table \"%s\" in the database dump"
|
448 |
-
msgstr ""
|
449 |
-
|
450 |
-
#: modules/class-wpadm-mysqldump.php:176
|
451 |
-
msgid "Add a table rows \"%s\" in the database dump from %from% to %to%"
|
452 |
-
msgstr ""
|
453 |
-
|
454 |
-
#: modules/class-wpadm-mysqldump.php:195
|
455 |
-
msgid "MySQL of Dump was finished"
|
456 |
-
msgstr ""
|
457 |
-
|
458 |
-
#: modules/class-wpadm-mysqldump.php:213
|
459 |
-
msgid "Restore Database was started"
|
460 |
-
msgstr ""
|
461 |
-
|
462 |
-
#: modules/class-wpadm-mysqldump.php:216 modules/class-wpadm-mysqldump.php:217
|
463 |
-
msgid "Error in open file dump"
|
464 |
-
msgstr ""
|
465 |
-
|
466 |
-
#: modules/class-wpadm-mysqldump.php:231
|
467 |
-
msgid "MySQL Error: "
|
468 |
-
msgstr ""
|
469 |
-
|
470 |
-
#: modules/class-wpadm-mysqldump.php:238
|
471 |
-
msgid "Restore Database was finished"
|
472 |
-
msgstr ""
|
473 |
-
|
474 |
-
#: template/notice.php:3
|
475 |
-
msgid "Professional version of"
|
476 |
-
msgstr ""
|
477 |
-
|
478 |
-
#: template/notice.php:4
|
479 |
-
msgid "Dropbox backup and restore\""
|
480 |
-
msgstr ""
|
481 |
-
|
482 |
-
#: template/notice.php:4
|
483 |
-
msgid "Dropbox backup and restore"
|
484 |
-
msgstr ""
|
485 |
-
|
486 |
-
#: template/notice.php:5
|
487 |
-
msgid " plugin is now available!"
|
488 |
-
msgstr ""
|
489 |
-
|
490 |
-
#: template/notice.php:6
|
491 |
-
msgid "Read more..."
|
492 |
-
msgstr ""
|
493 |
-
|
494 |
-
#: template/notice.php:7
|
495 |
-
msgid "hide this message"
|
496 |
-
msgstr ""
|
497 |
-
|
498 |
-
#: template/notice5.php:4
|
499 |
-
#, php-format
|
500 |
-
msgid ""
|
501 |
-
"You use Dropbox backup and restore plugin successfully for more than %s. "
|
502 |
-
"Please, leave a 5 star review for our development team, because it inspires "
|
503 |
-
"us to develop this plugin for you."
|
504 |
-
msgstr ""
|
505 |
-
|
506 |
-
#: template/notice5.php:5
|
507 |
-
msgid "Thank you!"
|
508 |
-
msgstr ""
|
509 |
-
|
510 |
-
#: template/notice5.php:7
|
511 |
-
msgid "Leave review"
|
512 |
-
msgstr ""
|
513 |
-
|
514 |
-
#: template/notice5.php:8
|
515 |
-
msgid "I already left a review"
|
516 |
-
msgstr ""
|
517 |
-
|
518 |
-
#: template/notice5.php:9
|
519 |
-
msgid "Hide this message"
|
520 |
-
msgstr ""
|
521 |
-
|
522 |
-
#: template/wpadm_show_backup.php:28 template/wpadm_show_backup.php:45
|
523 |
-
msgid "Hide"
|
524 |
-
msgstr ""
|
525 |
-
|
526 |
-
#: template/wpadm_show_backup.php:34 template/wpadm_show_backup.php:51
|
527 |
-
#: template/wpadm_show_backup.php:1025 template/wpadm_show_backup.php:1121
|
528 |
-
msgid "Show"
|
529 |
-
msgstr ""
|
530 |
-
|
531 |
-
#: template/wpadm_show_backup.php:177 template/wpadm_show_backup.php:237
|
532 |
-
msgid "Dropbox Backup was created successfully"
|
533 |
-
msgstr ""
|
534 |
-
|
535 |
-
#: template/wpadm_show_backup.php:181 template/wpadm_show_backup.php:241
|
536 |
-
msgid "Dropbox Backup wasn't created. "
|
537 |
-
msgstr ""
|
538 |
-
|
539 |
-
#: template/wpadm_show_backup.php:227
|
540 |
-
msgid "Local Backup was created successfully"
|
541 |
-
msgstr ""
|
542 |
-
|
543 |
-
#: template/wpadm_show_backup.php:231
|
544 |
-
msgid "Local Backup wasn't created"
|
545 |
-
msgstr ""
|
546 |
-
|
547 |
-
#: template/wpadm_show_backup.php:249 template/wpadm_show_backup.php:1248
|
548 |
-
msgid "Successful"
|
549 |
-
msgstr ""
|
550 |
-
|
551 |
-
#: template/wpadm_show_backup.php:254 template/wpadm_show_backup.php:1255
|
552 |
-
msgid "Fail"
|
553 |
-
msgstr ""
|
554 |
-
|
555 |
-
#: template/wpadm_show_backup.php:254 template/wpadm_show_backup.php:1255
|
556 |
-
msgid "Show Details"
|
557 |
-
msgstr ""
|
558 |
-
|
559 |
-
#: template/wpadm_show_backup.php:255 template/wpadm_show_backup.php:1236
|
560 |
-
msgid "Not available"
|
561 |
-
msgstr ""
|
562 |
-
|
563 |
-
#: template/wpadm_show_backup.php:285 template/wpadm_show_backup.php:1259
|
564 |
-
msgid "backup"
|
565 |
-
msgstr ""
|
566 |
-
|
567 |
-
#: template/wpadm_show_backup.php:288 template/wpadm_show_backup.php:1260
|
568 |
-
msgid "Mb"
|
569 |
-
msgstr ""
|
570 |
-
|
571 |
-
#: template/wpadm_show_backup.php:291 template/wpadm_show_backup.php:1264
|
572 |
-
msgid "Restore"
|
573 |
-
msgstr ""
|
574 |
-
|
575 |
-
#: template/wpadm_show_backup.php:292 template/wpadm_show_backup.php:1266
|
576 |
-
msgid "Delete"
|
577 |
-
msgstr ""
|
578 |
-
|
579 |
-
#: template/wpadm_show_backup.php:358 template/wpadm_show_backup.php:1132
|
580 |
-
msgid "sec."
|
581 |
-
msgstr ""
|
582 |
-
|
583 |
-
#: template/wpadm_show_backup.php:381
|
584 |
-
msgid "Are you sure you want to start the recovery process?"
|
585 |
-
msgstr ""
|
586 |
-
|
587 |
-
#: template/wpadm_show_backup.php:418
|
588 |
-
#, php-format
|
589 |
-
msgid "Local Backup (%s) was restored successfully"
|
590 |
-
msgstr ""
|
591 |
-
|
592 |
-
#: template/wpadm_show_backup.php:422
|
593 |
-
#, php-format
|
594 |
-
msgid "Dropbox Backup (%s) was restored successfully"
|
595 |
-
msgstr ""
|
596 |
-
|
597 |
-
#: template/wpadm_show_backup.php:430
|
598 |
-
#, php-format
|
599 |
-
msgid "Local Backup (%s) wasn't restored"
|
600 |
-
msgstr ""
|
601 |
-
|
602 |
-
#: template/wpadm_show_backup.php:434
|
603 |
-
#, php-format
|
604 |
-
msgid "Dropbox Backup (%s) wasn't restored"
|
605 |
-
msgstr ""
|
606 |
-
|
607 |
-
#: template/wpadm_show_backup.php:541
|
608 |
-
msgid "Please, permit the pop-up windows."
|
609 |
-
msgstr ""
|
610 |
-
|
611 |
-
#: template/wpadm_show_backup.php:552 template/wpadm_show_backup.php:1071
|
612 |
-
msgid "Dropbox successfully connected:"
|
613 |
-
msgstr ""
|
614 |
-
|
615 |
-
#: template/wpadm_show_backup.php:787
|
616 |
-
msgid "Please, add your Dropbox credentials:"
|
617 |
-
msgstr ""
|
618 |
-
|
619 |
-
#: template/wpadm_show_backup.php:788
|
620 |
-
msgid "\"App key\""
|
621 |
-
msgstr ""
|
622 |
-
|
623 |
-
#: template/wpadm_show_backup.php:788
|
624 |
-
msgid "\"App secret\""
|
625 |
-
msgstr ""
|
626 |
-
|
627 |
-
#: template/wpadm_show_backup.php:789
|
628 |
-
msgid "in the Setting Form"
|
629 |
-
msgstr ""
|
630 |
-
|
631 |
-
#: template/wpadm_show_backup.php:792 template/wpadm_show_backup.php:815
|
632 |
-
#: template/wpadm_show_backup.php:894 template/wpadm_show_backup.php:1193
|
633 |
-
msgid "OK"
|
634 |
-
msgstr ""
|
635 |
-
|
636 |
-
#: template/wpadm_show_backup.php:823
|
637 |
-
msgid ""
|
638 |
-
"To solve this problem, we need to access the system logs of your hosting/"
|
639 |
-
"server and/or from your backup, <br />that you tried to create or simply "
|
640 |
-
"send to us your FTP access data."
|
641 |
-
msgstr ""
|
642 |
-
|
643 |
-
#: template/wpadm_show_backup.php:827
|
644 |
-
msgid "I want to provide your FTP access to resolve this issue quickly:"
|
645 |
-
msgstr ""
|
646 |
-
|
647 |
-
#: template/wpadm_show_backup.php:833 template/wpadm_show_backup.php:1349
|
648 |
-
msgid "FTP Host"
|
649 |
-
msgstr ""
|
650 |
-
|
651 |
-
#: template/wpadm_show_backup.php:842 template/wpadm_show_backup.php:1358
|
652 |
-
msgid "FTP User"
|
653 |
-
msgstr ""
|
654 |
-
|
655 |
-
#: template/wpadm_show_backup.php:851 template/wpadm_show_backup.php:1367
|
656 |
-
msgid "FTP Password"
|
657 |
-
msgstr ""
|
658 |
-
|
659 |
-
#: template/wpadm_show_backup.php:863 template/wpadm_show_backup.php:1379
|
660 |
-
msgid "Response Email:"
|
661 |
-
msgstr ""
|
662 |
-
|
663 |
-
#: template/wpadm_show_backup.php:877
|
664 |
-
msgid "SEND TO SUPPORT and close this window"
|
665 |
-
msgstr ""
|
666 |
-
|
667 |
-
#: template/wpadm_show_backup.php:878
|
668 |
-
msgid "Close this window WITHOUT SENDING TO SUPPORT"
|
669 |
-
msgstr ""
|
670 |
-
|
671 |
-
#: template/wpadm_show_backup.php:884
|
672 |
-
msgid "Where can I find my app key and secret?"
|
673 |
-
msgstr ""
|
674 |
-
|
675 |
-
#: template/wpadm_show_backup.php:887
|
676 |
-
msgid "You can get an API app key and secret by creating an app on the"
|
677 |
-
msgstr ""
|
678 |
-
|
679 |
-
#: template/wpadm_show_backup.php:888
|
680 |
-
msgid "app creation page"
|
681 |
-
msgstr ""
|
682 |
-
|
683 |
-
#: template/wpadm_show_backup.php:889
|
684 |
-
msgid ""
|
685 |
-
"Once you have an app created, the app key and secret will be available on "
|
686 |
-
"the app's page on the"
|
687 |
-
msgstr ""
|
688 |
-
|
689 |
-
#: template/wpadm_show_backup.php:890
|
690 |
-
msgid "App Console"
|
691 |
-
msgstr ""
|
692 |
-
|
693 |
-
#: template/wpadm_show_backup.php:891
|
694 |
-
msgid "Note that Drop-ins have app keys but no app secrets."
|
695 |
-
msgstr ""
|
696 |
-
|
697 |
-
#: template/wpadm_show_backup.php:901
|
698 |
-
msgid ""
|
699 |
-
"Use Professional version of \"Dropbox backup and restore\" plugin and get:"
|
700 |
-
msgstr ""
|
701 |
-
|
702 |
-
#: template/wpadm_show_backup.php:906
|
703 |
-
msgid "Automated Dropbox backup (Scheduled backup tasks)"
|
704 |
-
msgstr ""
|
705 |
-
|
706 |
-
#: template/wpadm_show_backup.php:912
|
707 |
-
msgid "Automated Local backup (Scheduled backup tasks)"
|
708 |
-
msgstr ""
|
709 |
-
|
710 |
-
#: template/wpadm_show_backup.php:918
|
711 |
-
msgid "Backup Status E-Mail Reporting"
|
712 |
-
msgstr ""
|
713 |
-
|
714 |
-
#: template/wpadm_show_backup.php:924
|
715 |
-
msgid ""
|
716 |
-
"Online Service \"Backup Website Manager\" (Copy, Clone or Migrate of "
|
717 |
-
"websites)"
|
718 |
-
msgstr ""
|
719 |
-
|
720 |
-
#: template/wpadm_show_backup.php:930
|
721 |
-
msgid "One Year Free Updates for PRO version"
|
722 |
-
msgstr ""
|
723 |
-
|
724 |
-
#: template/wpadm_show_backup.php:936
|
725 |
-
msgid "One Year Priority support"
|
726 |
-
msgstr ""
|
727 |
-
|
728 |
-
#: template/wpadm_show_backup.php:943
|
729 |
-
msgid "Get PRO version"
|
730 |
-
msgstr ""
|
731 |
-
|
732 |
-
#: template/wpadm_show_backup.php:953
|
733 |
-
msgid "Get PRO"
|
734 |
-
msgstr ""
|
735 |
-
|
736 |
-
#: template/wpadm_show_backup.php:965
|
737 |
-
msgid "Dropbox Full Backup"
|
738 |
-
msgstr ""
|
739 |
-
|
740 |
-
#: template/wpadm_show_backup.php:966
|
741 |
-
msgid "(files+database)"
|
742 |
-
msgstr ""
|
743 |
-
|
744 |
-
#: template/wpadm_show_backup.php:976
|
745 |
-
msgid "Free Sign Up"
|
746 |
-
msgstr ""
|
747 |
-
|
748 |
-
#: template/wpadm_show_backup.php:976
|
749 |
-
msgid "to backup more than one website..."
|
750 |
-
msgstr ""
|
751 |
-
|
752 |
-
#: template/wpadm_show_backup.php:985
|
753 |
-
msgid "E-mail"
|
754 |
-
msgstr ""
|
755 |
-
|
756 |
-
#: template/wpadm_show_backup.php:993 template/wpadm_show_backup.php:1045
|
757 |
-
msgid "Password"
|
758 |
-
msgstr ""
|
759 |
-
|
760 |
-
#: template/wpadm_show_backup.php:1001
|
761 |
-
msgid "Password confirm"
|
762 |
-
msgstr ""
|
763 |
-
|
764 |
-
#: template/wpadm_show_backup.php:1011
|
765 |
-
msgid "Register & Activate"
|
766 |
-
msgstr ""
|
767 |
-
|
768 |
-
#: template/wpadm_show_backup.php:1018
|
769 |
-
msgid "If you are NOT registered at"
|
770 |
-
msgstr ""
|
771 |
-
|
772 |
-
#: template/wpadm_show_backup.php:1018
|
773 |
-
msgid "WPAdm"
|
774 |
-
msgstr ""
|
775 |
-
|
776 |
-
#: template/wpadm_show_backup.php:1018
|
777 |
-
msgid ""
|
778 |
-
"enter your email and password to use as your Account Data for authorization "
|
779 |
-
"on WPAdm."
|
780 |
-
msgstr ""
|
781 |
-
|
782 |
-
#: template/wpadm_show_backup.php:1018
|
783 |
-
msgid "If you already have an account at"
|
784 |
-
msgstr ""
|
785 |
-
|
786 |
-
#: template/wpadm_show_backup.php:1018
|
787 |
-
msgid ""
|
788 |
-
"and you want to Sign-In, so please, enter your registered credential data "
|
789 |
-
"(email and password twice)."
|
790 |
-
msgstr ""
|
791 |
-
|
792 |
-
#: template/wpadm_show_backup.php:1033
|
793 |
-
msgid "Sign In to backup more than one website..."
|
794 |
-
msgstr ""
|
795 |
-
|
796 |
-
#: template/wpadm_show_backup.php:1042
|
797 |
-
msgid "Email"
|
798 |
-
msgstr ""
|
799 |
-
|
800 |
-
#: template/wpadm_show_backup.php:1054
|
801 |
-
msgid "set new mail"
|
802 |
-
msgstr ""
|
803 |
-
|
804 |
-
#: template/wpadm_show_backup.php:1064
|
805 |
-
msgid "Settings"
|
806 |
-
msgstr ""
|
807 |
-
|
808 |
-
#: template/wpadm_show_backup.php:1070
|
809 |
-
msgid "Connect to Dropbox"
|
810 |
-
msgstr ""
|
811 |
-
|
812 |
-
#: template/wpadm_show_backup.php:1075
|
813 |
-
msgid "Connect using my Dropbox App"
|
814 |
-
msgstr ""
|
815 |
-
|
816 |
-
#: template/wpadm_show_backup.php:1082
|
817 |
-
msgid "App key"
|
818 |
-
msgstr ""
|
819 |
-
|
820 |
-
#: template/wpadm_show_backup.php:1090
|
821 |
-
msgid "App secret"
|
822 |
-
msgstr ""
|
823 |
-
|
824 |
-
#: template/wpadm_show_backup.php:1099
|
825 |
-
msgid "Where to get App key & App secret?"
|
826 |
-
msgstr ""
|
827 |
-
|
828 |
-
#: template/wpadm_show_backup.php:1108
|
829 |
-
msgid "Appear in menu for admins only"
|
830 |
-
msgstr ""
|
831 |
-
|
832 |
-
#: template/wpadm_show_backup.php:1113
|
833 |
-
msgid "Database Optimization"
|
834 |
-
msgstr ""
|
835 |
-
|
836 |
-
#: template/wpadm_show_backup.php:1132
|
837 |
-
msgid "Please wait..."
|
838 |
-
msgstr ""
|
839 |
-
|
840 |
-
#: template/wpadm_show_backup.php:1140
|
841 |
-
msgid "++ Review ++"
|
842 |
-
msgstr ""
|
843 |
-
|
844 |
-
#: template/wpadm_show_backup.php:1141
|
845 |
-
msgid "Your review is important for us"
|
846 |
-
msgstr ""
|
847 |
-
|
848 |
-
#: template/wpadm_show_backup.php:1146
|
849 |
-
msgid "Help"
|
850 |
-
msgstr ""
|
851 |
-
|
852 |
-
#: template/wpadm_show_backup.php:1150
|
853 |
-
msgid "Create Dropbox Backup"
|
854 |
-
msgstr ""
|
855 |
-
|
856 |
-
#: template/wpadm_show_backup.php:1153
|
857 |
-
msgid "Create Local Backup"
|
858 |
-
msgstr ""
|
859 |
-
|
860 |
-
#: template/wpadm_show_backup.php:1156
|
861 |
-
msgid "Folders & files"
|
862 |
-
msgstr ""
|
863 |
-
|
864 |
-
#: template/wpadm_show_backup.php:1177
|
865 |
-
msgid "Include/Exclude of Files & Folders to backup"
|
866 |
-
msgstr ""
|
867 |
-
|
868 |
-
#: template/wpadm_show_backup.php:1179
|
869 |
-
msgid "Database of web page will be included automatically"
|
870 |
-
msgstr ""
|
871 |
-
|
872 |
-
#: template/wpadm_show_backup.php:1194
|
873 |
-
msgid "Cancel"
|
874 |
-
msgstr ""
|
875 |
-
|
876 |
-
#: template/wpadm_show_backup.php:1204
|
877 |
-
msgid "Create, Date/Time"
|
878 |
-
msgstr ""
|
879 |
-
|
880 |
-
#: template/wpadm_show_backup.php:1205
|
881 |
-
msgid "Name of Backup"
|
882 |
-
msgstr ""
|
883 |
-
|
884 |
-
#: template/wpadm_show_backup.php:1206
|
885 |
-
msgid "Archive Parts"
|
886 |
-
msgstr ""
|
887 |
-
|
888 |
-
#: template/wpadm_show_backup.php:1207
|
889 |
-
msgid "Status"
|
890 |
-
msgstr ""
|
891 |
-
|
892 |
-
#: template/wpadm_show_backup.php:1208
|
893 |
-
msgid "Type of Backup"
|
894 |
-
msgstr ""
|
895 |
-
|
896 |
-
#: template/wpadm_show_backup.php:1209
|
897 |
-
msgid "Size"
|
898 |
-
msgstr ""
|
899 |
-
|
900 |
-
#: template/wpadm_show_backup.php:1211
|
901 |
-
msgid "Action"
|
902 |
-
msgstr ""
|
903 |
-
|
904 |
-
#: template/wpadm_show_backup.php:1234
|
905 |
-
msgid "Backup in process create"
|
906 |
-
msgstr ""
|
907 |
-
|
908 |
-
#: template/wpadm_show_backup.php:1236
|
909 |
-
msgid "Why?"
|
910 |
-
msgstr ""
|
911 |
-
|
912 |
-
#: template/wpadm_show_backup.php:1251
|
913 |
-
msgid "Attention, backup creates"
|
914 |
-
msgstr ""
|
915 |
-
|
916 |
-
#: template/wpadm_show_backup.php:1312
|
917 |
-
msgid ""
|
918 |
-
"Backup is created. If you are sure that the backup down(crashed), please "
|
919 |
-
msgstr ""
|
920 |
-
|
921 |
-
#: template/wpadm_show_backup.php:1313
|
922 |
-
msgid "contact us"
|
923 |
-
msgstr ""
|
924 |
-
|
925 |
-
#: template/wpadm_show_backup.php:1338
|
926 |
-
msgid "Error log wasn't Found"
|
927 |
-
msgstr ""
|
928 |
-
|
929 |
-
#: template/wpadm_show_backup.php:1344
|
930 |
-
msgid "Please, provide your FTP access to resolve this issue quickly:"
|
931 |
-
msgstr ""
|
932 |
-
|
933 |
-
#: template/wpadm_show_backup.php:1389
|
934 |
-
msgid "Send request to support"
|
935 |
-
msgstr ""
|
936 |
-
|
937 |
-
#. Plugin Name of the plugin/theme
|
938 |
-
msgid "Dropbox Backup & Restore"
|
939 |
-
msgstr ""
|
940 |
-
|
941 |
-
#. Description of the plugin/theme
|
942 |
-
msgid ""
|
943 |
-
"Dropbox Backup & Restore Plugin to create Dropbox Full Backup (Files + "
|
944 |
-
"Database) of your Web Page"
|
945 |
-
msgstr ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/index.php
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
<?php
|
|
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 );
|
@@ -39,25 +37,27 @@ if ( ! class_exists("langWPADM")) {
|
|
39 |
}
|
40 |
return false;
|
41 |
}
|
42 |
-
public static function get($key, $echo = true
|
43 |
{
|
44 |
-
$result = '';
|
45 |
if(!empty($key)) {
|
46 |
if ( isset(self::$lang[self::$lang_name][$key]) ) {
|
47 |
-
$
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
50 |
}
|
51 |
}
|
52 |
-
if
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
if ($echo) {
|
57 |
-
echo $
|
58 |
return true;
|
59 |
} else {
|
60 |
-
return $
|
61 |
}
|
62 |
}
|
63 |
public static function getLanguageSystem()
|
@@ -73,26 +73,31 @@ if ( ! class_exists("langWPADM")) {
|
|
73 |
}
|
74 |
public static function downloadLang()
|
75 |
{
|
76 |
-
if (!empty(self::$lang_load)) {
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
95 |
}
|
|
|
|
|
96 |
}
|
97 |
private static function updateDate($date_update)
|
98 |
{
|
1 |
<?php
|
2 |
|
|
|
|
|
3 |
if ( ! class_exists("langWPADM")) {
|
4 |
|
5 |
add_action('init', array('langWPADM', 'init'), 11 );
|
37 |
}
|
38 |
return false;
|
39 |
}
|
40 |
+
public static function get($key, $echo = true)
|
41 |
{
|
|
|
42 |
if(!empty($key)) {
|
43 |
if ( isset(self::$lang[self::$lang_name][$key]) ) {
|
44 |
+
if ($echo) {
|
45 |
+
echo self::$lang[self::$lang_name][$key];
|
46 |
+
return true;
|
47 |
+
} else {
|
48 |
+
return self::$lang[self::$lang_name][$key];
|
49 |
+
}
|
50 |
}
|
51 |
}
|
52 |
+
/*if(!isset(self::$debug[$key])) {
|
53 |
+
self::$debug[$key] = $key;
|
54 |
+
file_put_contents( dirname(__FILE__) . "/debug.lang", print_r(self::$debug, 1) );
|
55 |
+
} */
|
56 |
if ($echo) {
|
57 |
+
echo $key;
|
58 |
return true;
|
59 |
} else {
|
60 |
+
return $key;
|
61 |
}
|
62 |
}
|
63 |
public static function getLanguageSystem()
|
73 |
}
|
74 |
public static function downloadLang()
|
75 |
{
|
76 |
+
/*if (!empty(self::$lang_load)) {
|
77 |
+
$time = get_option(WPADM_LANG_ . 'time-update');
|
78 |
+
if ( (isset($time['check_time']) && $time['check_time'] <= time()) || !isset($time['check_time']) || !file_exists(self::$lang_dir . self::$lang_load . '.php') ) {
|
79 |
+
if (!function_exists('wp_safe_remote_get')) {
|
80 |
+
include_once ABSPATH . WPINC . '/http.php';
|
81 |
+
}
|
82 |
+
if (function_exists('wp_safe_remote_get')) {
|
83 |
+
$load = wp_safe_remote_get( self::$url . self::$lang_load . '.php' );
|
84 |
+
if ( is_wp_error( $load ) ) {
|
85 |
+
return false;
|
86 |
+
}
|
87 |
+
if (isset($load['response']['code']) && $load['response']['code'] == '200') {
|
88 |
+
@preg_match("/Date create - ([0-9\.]+)/", $load['body'], $date);
|
89 |
+
if (!isset($time['date']) || $time['date'] != $date[1] || !file_exists(self::$lang_dir . self::$lang_load . '.php')) {
|
90 |
+
if (isset($date[1])) {
|
91 |
+
self::updateDate($date[1]);
|
92 |
+
} else {
|
93 |
+
self::updateDate(date('d.m.Y'));
|
94 |
+
}
|
95 |
+
file_put_contents(self::$lang_dir . self::$lang_load . '.php', $load['body']);
|
96 |
+
}
|
97 |
+
}
|
98 |
}
|
99 |
+
}
|
100 |
+
} */
|
101 |
}
|
102 |
private static function updateDate($date_update)
|
103 |
{
|
libs/lang/index.php
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
<?php
|
|
libs/wpadm.server.main.class.php
CHANGED
@@ -1,5 +1,27 @@
|
|
1 |
<?php
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
if (!class_exists("wpadm_class")) {
|
5 |
|
@@ -8,8 +30,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 |
|
@@ -21,12 +41,12 @@
|
|
21 |
protected static $class = "";
|
22 |
protected static $title = "";
|
23 |
public static $type = "";
|
24 |
-
public static $plugin_name = "
|
25 |
protected static $plugins = array('stats-counter' => '1.1',
|
26 |
'wpadm_full_backup_storage' => '1.0',
|
27 |
'wpadm_full_backup_s3' => '1.0',
|
28 |
'ftp-backup' => '1.0',
|
29 |
-
'dropbox-backup' => '1.
|
30 |
'wpadm_db_backup_storage' => '1.0',
|
31 |
'database-backup-amazon-s3' => '1.0',
|
32 |
'wpadm_file_backup_s3' => '1.0',
|
@@ -49,12 +69,10 @@
|
|
49 |
{
|
50 |
self::$backup = $b;
|
51 |
}
|
52 |
-
public static function error_log_check(
|
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 +128,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,200 +145,66 @@
|
|
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 |
-
'
|
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 |
);
|
169 |
-
|
170 |
$res = self::sendToServer(array('actApi' => "errorLog",
|
171 |
"site" => str_ireplace(array("http://","https://"), "", home_url()),
|
172 |
"data" => $logs_report )
|
173 |
-
);
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
header("Location: " . $_SERVER['HTTP_REFERER']);
|
178 |
-
exit;
|
179 |
-
}
|
180 |
-
|
181 |
-
}
|
182 |
-
|
183 |
-
public static function check_get()
|
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 |
-
if ($first) {
|
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;
|
241 |
}
|
242 |
public static function getDirsIncludes()
|
243 |
{
|
244 |
-
|
245 |
-
$path = isset($_POST['path']) ? sanitize_text_field( urldecode( $_POST['path'] ) ) : "";
|
246 |
$path_show = !empty($path) ? ltrim($path, '/') . "/" : "";
|
247 |
$dir_to_open = ABSPATH . $path;
|
248 |
-
if (is_dir($dir_to_open)) {
|
|
|
249 |
$return = array();
|
250 |
$connect_f_d = self::createListFilesForArchive();
|
251 |
$includes = get_option(PREFIX_BACKUP_ . "plus-path");
|
252 |
if ($includes !== false) {
|
253 |
-
$includes = explode(',',
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
258 |
}
|
259 |
-
} else {
|
260 |
-
$in = self::getFolders($connect_f_d);
|
261 |
}
|
262 |
-
|
263 |
-
|
264 |
-
$volume = array();
|
265 |
while( $d = readdir($dir_open) ) {
|
266 |
-
if ($d != '.' && $d != '..' && !in_array($d, array('tmp', 'cache', 'temp', 'wpadm_backups', 'wpadm_backup', '
|
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 |
-
$return['dir'][] = array('is_file' => is_file($dir_to_open . "/$d"), 'dir' => urlencode( $d ) , 'cache' => md5($path_show . $d),
|
291 |
-
'folder'=> urlencode('/' . ( empty($path_show ) ? '' : $path_show . '/' ) . $d ),
|
292 |
-
'perm' => self::perm($dir_to_open . "/" .$d),
|
293 |
-
'check' => $check, 'check_folder' => $check_folder );
|
294 |
-
}
|
295 |
-
}
|
296 |
-
array_multisort($volume, SORT_ASC, $return['dir'] );
|
297 |
-
$res = json_encode($return);
|
298 |
-
echo $res;
|
299 |
-
if ($res === false) {
|
300 |
-
switch (json_last_error()) {
|
301 |
-
case JSON_ERROR_NONE:
|
302 |
-
echo ' - No errors';
|
303 |
-
break;
|
304 |
-
case JSON_ERROR_DEPTH:
|
305 |
-
echo ' - Maximum stack depth exceeded';
|
306 |
-
break;
|
307 |
-
case JSON_ERROR_STATE_MISMATCH:
|
308 |
-
echo ' - Underflow or the modes mismatch';
|
309 |
-
break;
|
310 |
-
case JSON_ERROR_CTRL_CHAR:
|
311 |
-
echo ' - Unexpected control character found';
|
312 |
-
break;
|
313 |
-
case JSON_ERROR_SYNTAX:
|
314 |
-
echo ' - Syntax error, malformed JSON';
|
315 |
-
break;
|
316 |
-
case JSON_ERROR_UTF8:
|
317 |
-
echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
|
318 |
-
break;
|
319 |
-
default:
|
320 |
-
echo ' - Unknown error';
|
321 |
-
break;
|
322 |
}
|
323 |
}
|
|
|
324 |
}
|
325 |
wp_die();
|
326 |
}
|
@@ -331,15 +215,15 @@
|
|
331 |
$files = array_merge(
|
332 |
$files,
|
333 |
array(
|
334 |
-
|
335 |
ABSPATH . 'index.php',
|
336 |
-
|
337 |
-
|
338 |
ABSPATH . 'wp-activate.php',
|
339 |
ABSPATH . 'wp-blog-header.php',
|
340 |
ABSPATH . 'wp-comments-post.php',
|
341 |
ABSPATH . 'wp-config.php',
|
342 |
-
|
343 |
ABSPATH . 'wp-cron.php',
|
344 |
ABSPATH . 'wp-links-opml.php',
|
345 |
ABSPATH . 'wp-load.php',
|
@@ -348,33 +232,9 @@
|
|
348 |
ABSPATH . 'wp-settings.php',
|
349 |
ABSPATH . 'wp-signup.php',
|
350 |
ABSPATH . 'wp-trackback.php',
|
351 |
-
|
352 |
)
|
353 |
);
|
354 |
-
if ( file_exists(ABSPATH . '.htaccess') ) {
|
355 |
-
$files = array_merge( $files, array( ABSPATH . '.htaccess' ) );
|
356 |
-
}
|
357 |
-
if ( file_exists( ABSPATH . 'license.txt' ) ) {
|
358 |
-
$files = array_merge( $files, array( ABSPATH . 'license.txt' ) );
|
359 |
-
}
|
360 |
-
if ( file_exists( ABSPATH . 'readme.html' ) ) {
|
361 |
-
$files = array_merge( $files, array( ABSPATH . 'readme.html') );
|
362 |
-
}
|
363 |
-
if ( file_exists(ABSPATH . 'wp-config-sample.php') ) {
|
364 |
-
$files = array_merge( $files, array( ABSPATH . 'wp-config-sample.php' ) );
|
365 |
-
}
|
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 +253,7 @@
|
|
393 |
}
|
394 |
return $files;
|
395 |
}
|
396 |
-
|
397 |
$array_items = array();
|
398 |
|
399 |
$d = str_replace(ABSPATH, '', $directory);
|
@@ -403,21 +263,9 @@
|
|
403 |
|
404 |
$d = str_replace('\\', '/', $d);
|
405 |
$tmp = explode('/', $d);
|
406 |
-
|
407 |
-
$d1 = mb_strtolower($tmp[0]);
|
408 |
-
} else {
|
409 |
-
$d1 = strtolower($tmp[0]);
|
410 |
-
}
|
411 |
unset($tmp[0]);
|
412 |
-
|
413 |
-
$d2 = mb_strtolower(implode('/', $tmp));
|
414 |
-
} else {
|
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 +312,14 @@
|
|
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 |
}
|
@@ -571,7 +378,7 @@
|
|
571 |
|
572 |
static function setResponse($data)
|
573 |
{
|
574 |
-
$msg =
|
575 |
if(isset($data['data'])) {
|
576 |
if (isset($data['data']['replace'])) {
|
577 |
foreach($data['data']['replace'] as $key => $value) {
|
@@ -593,16 +400,16 @@
|
|
593 |
protected static function setError($msg = "")
|
594 |
{
|
595 |
if (!empty($msg)) {
|
596 |
-
$_SESSION['
|
597 |
}
|
598 |
}
|
599 |
protected static function getError($del = false)
|
600 |
{
|
601 |
$error = "";
|
602 |
-
if (isset($_SESSION['
|
603 |
-
$error = $_SESSION['
|
604 |
if($del) {
|
605 |
-
unset($_SESSION['
|
606 |
}
|
607 |
}
|
608 |
return $error;
|
@@ -611,16 +418,16 @@
|
|
611 |
protected static function setMessage($msg)
|
612 |
{
|
613 |
if (!empty($msg)) {
|
614 |
-
$_SESSION['
|
615 |
}
|
616 |
}
|
617 |
protected static function getMessage($del = false)
|
618 |
{
|
619 |
$msg = "";
|
620 |
-
if (isset($_SESSION['
|
621 |
-
$msg = $_SESSION['
|
622 |
if($del) {
|
623 |
-
unset($_SESSION['
|
624 |
}
|
625 |
}
|
626 |
return $msg;
|
@@ -654,7 +461,11 @@
|
|
654 |
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
|
655 |
self::$result = curl_exec($curl);
|
656 |
curl_close($curl);
|
657 |
-
|
|
|
|
|
|
|
|
|
658 |
} elseif (function_exists("fsockopen")) {
|
659 |
if ($stat) {
|
660 |
$url = SERVER_URL_STAT;
|
@@ -682,8 +493,12 @@
|
|
682 |
}
|
683 |
}
|
684 |
self::$result = explode("\r\n\r\n", self::$result);
|
685 |
-
|
686 |
-
|
|
|
|
|
|
|
|
|
687 |
} else {
|
688 |
throw new Exception("unable to create socket");
|
689 |
}
|
@@ -698,29 +513,29 @@
|
|
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 |
-
|
707 |
$sent = false;
|
708 |
}
|
709 |
if (!preg_match("/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i", $email)) {
|
710 |
-
|
711 |
$sent = false;
|
712 |
}
|
713 |
if (empty($password)) {
|
714 |
-
|
715 |
$sent = false;
|
716 |
}
|
717 |
if (strlen($password) < self::MIN_PASSWORD) {
|
718 |
-
|
719 |
$sent = false;
|
720 |
}
|
721 |
|
722 |
if ($password != $password_confirm) {
|
723 |
-
|
724 |
$sent = false;
|
725 |
}
|
726 |
if ($sent) {
|
@@ -741,37 +556,12 @@
|
|
741 |
)
|
742 |
);
|
743 |
$res = self::setResponse($data);
|
744 |
-
if (isset($res['url']) && !empty($res['url'])) {
|
745 |
-
self::connectPlugin($email, $password);
|
746 |
-
}
|
747 |
}
|
748 |
}
|
749 |
-
|
750 |
if (isset($res['url']) && !empty($res['url'])) {
|
751 |
header("Location: " . $res['url']);
|
752 |
} else {
|
753 |
-
header("Location: " .
|
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 |
|
@@ -792,95 +582,39 @@
|
|
792 |
$name = preg_replace("|\W|", "_", $name);
|
793 |
$name .= '-' . self::$type . '-' . date("Y_m_d_H_i");
|
794 |
|
795 |
-
$
|
796 |
-
|
797 |
-
$dir_backup = DROPBOX_BACKUP_DIR_BACKUP;
|
798 |
-
if ($dropbox_options) {
|
799 |
-
if (isset($dropbox_options['backup_folder']) && !empty($dropbox_options['backup_folder'])) {
|
800 |
-
$dir_backup = $dropbox_options['backup_folder'];
|
801 |
-
}
|
802 |
-
}
|
803 |
-
|
804 |
|
805 |
$backups = array('data' => array(), 'md5' => '');
|
806 |
-
|
807 |
-
$backups['data'] = self::getBackups($dir_backup, $dirs_read);
|
808 |
-
|
809 |
-
$backups['data'] = array_merge($backups['data'], self::getBackups(ABSPATH . WPADM_DIR_NAME, $dirs_read) );
|
810 |
-
$backups['data'] = array_merge($backups['data'], self::getBackups(WPADM_DIR_BACKUP, $dirs_read) );
|
811 |
-
|
812 |
-
$backups['md5'] = md5( print_r($backups['data'] , 1) );
|
813 |
-
return $backups;
|
814 |
-
}
|
815 |
-
|
816 |
-
protected static function getBackups($dir_backup, $dirs_read)
|
817 |
-
{
|
818 |
-
$backups = array();
|
819 |
if (is_dir($dir_backup)) {
|
820 |
$i = 0;
|
821 |
$dir_open = opendir($dir_backup);
|
822 |
-
$stop_precess = WPAdm_Running::getCommandResultData('stop_process');
|
823 |
-
$name_backup = isset($stop_precess['name']) ? $stop_precess['name'] : '' ;
|
824 |
while($d = readdir($dir_open)) {
|
825 |
if ($d != '.' && $d != '..' && is_dir($dir_backup . "/$d") && strpos($d, self::$type) !== false) {
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
$
|
835 |
-
|
836 |
-
|
837 |
-
|
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 (!empty($file_md5)) {
|
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';
|
859 |
-
$backups[$i]['count'] = $count_zip;
|
860 |
}
|
861 |
-
$i
|
|
|
|
|
|
|
862 |
}
|
|
|
863 |
}
|
864 |
}
|
865 |
}
|
866 |
-
|
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 |
{
|
@@ -940,7 +674,7 @@
|
|
940 |
//try get mysql version
|
941 |
$mysqlVersion = $c['mysqlVersion'];
|
942 |
|
943 |
-
$show = !get_option('wpadm_pub_key') || (!is_super_admin() || !is_admin()) ||
|
944 |
?>
|
945 |
|
946 |
|
@@ -1121,14 +855,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")) {
|
@@ -1152,18 +879,18 @@
|
|
1152 |
$mysqlVersion = $mysqli->db_version();
|
1153 |
}
|
1154 |
$upMaxExecutionTime = 0;
|
1155 |
-
$newMaxExecutionTime = intval($maxExecutionTime) +
|
1156 |
-
|
1157 |
@set_time_limit( $newMaxExecutionTime );
|
1158 |
if( ini_get('max_execution_time') == $newMaxExecutionTime ){
|
1159 |
$upMaxExecutionTime = 1;
|
1160 |
-
|
1161 |
}
|
1162 |
$upMemoryLimit = 0;
|
1163 |
$newMemoryLimit = intval($maxMemoryLimit) + 60;
|
1164 |
ini_set('memory_limit', $newMemoryLimit.'M');
|
1165 |
if( ini_get('memory_limit') == $newMemoryLimit ){
|
1166 |
$upMemoryLimit = 1;
|
|
|
1167 |
}
|
1168 |
$extensions_search = array('curl', 'json', 'mysqli', 'sockets', 'zip', 'ftp');
|
1169 |
$disabledFunctions_search = array('set_time_limit', 'curl_init', 'fsockopen', 'ftp_connect');
|
@@ -1172,11 +899,11 @@
|
|
1172 |
$func = check_function($disabledFunctions, $disabledFunctions_search, true);
|
1173 |
|
1174 |
return array('wp_version' => $wp_version, 'php_verion' => phpversion(),
|
1175 |
-
'maxExecutionTime' => $maxExecutionTime,
|
1176 |
'extensions' => $extensions, 'disabledFunctions' => $disabledFunctions,
|
1177 |
'mysqlVersion' => $mysqlVersion, 'upMaxExecutionTime' => $upMaxExecutionTime,
|
1178 |
'newMaxExecutionTime' => $newMaxExecutionTime, 'upMemoryLimit' => $upMemoryLimit,
|
1179 |
-
'newMemoryLimit' => $
|
1180 |
'ex' => $ex, 'func' => $func, 'wp_lang' => get_option('WPLANG'),
|
1181 |
);
|
1182 |
|
1 |
<?php
|
2 |
+
|
3 |
+
if (!defined("SERVER_URL_INDEX")) {
|
4 |
+
define("SERVER_URL_INDEX", "http://www.webpage-backup.com/");
|
5 |
+
}
|
6 |
+
if (!defined("PHP_VERSION_DEFAULT")) {
|
7 |
+
define("PHP_VERSION_DEFAULT", '5.2.4' );
|
8 |
+
}
|
9 |
+
if (!defined("MYSQL_VERSION_DEFAULT")) {
|
10 |
+
define("MYSQL_VERSION_DEFAULT", '5.0' );
|
11 |
+
}
|
12 |
+
|
13 |
+
if (!defined("_PREFIX_STAT")) {
|
14 |
+
define("_PREFIX_STAT", "counter_free_wpadm_");
|
15 |
+
}
|
16 |
+
|
17 |
+
if (!defined("PREFIX_BACKUP_")) {
|
18 |
+
define("PREFIX_BACKUP_", "wpadm_backup_");
|
19 |
+
}
|
20 |
+
if (!defined("PAGES_NEXT_PREV_COUNT_STAT")) {
|
21 |
+
define("PAGES_NEXT_PREV_COUNT_STAT", 3);
|
22 |
+
}
|
23 |
+
|
24 |
+
require_once dirname(__FILE__) . "/lang.class.php";
|
25 |
|
26 |
if (!class_exists("wpadm_class")) {
|
27 |
|
30 |
add_action('admin_post_wpadm_delete_pub_key', array('wpadm_class', 'delete_pub_key') );
|
31 |
add_action('wp_ajax_getDirsIncludes', array('wpadm_class', 'getDirsIncludes') );
|
32 |
add_action('wp_ajax_saveDirsIncludes', array('wpadm_class', 'saveDirsIncludes') );
|
|
|
|
|
33 |
|
34 |
//add_action('admin_post_wpadm_getJs', array('wpadm_class', 'getJs') );
|
35 |
|
41 |
protected static $class = "";
|
42 |
protected static $title = "";
|
43 |
public static $type = "";
|
44 |
+
public static $plugin_name = "";
|
45 |
protected static $plugins = array('stats-counter' => '1.1',
|
46 |
'wpadm_full_backup_storage' => '1.0',
|
47 |
'wpadm_full_backup_s3' => '1.0',
|
48 |
'ftp-backup' => '1.0',
|
49 |
+
'dropbox-backup' => '1.0',
|
50 |
'wpadm_db_backup_storage' => '1.0',
|
51 |
'database-backup-amazon-s3' => '1.0',
|
52 |
'wpadm_file_backup_s3' => '1.0',
|
69 |
{
|
70 |
self::$backup = $b;
|
71 |
}
|
72 |
+
public static function error_log_check()
|
73 |
{
|
|
|
|
|
74 |
$base_path = plugin_dir_path( dirname(__FILE__) );
|
75 |
+
$time = isset($_POST['time_pars']) ? $_POST['time_pars'] : "";
|
76 |
$error = "";
|
77 |
if ( file_exists( ABSPATH . "error_log" ) ) {
|
78 |
$error = file_get_contents(ABSPATH . "error_log");
|
128 |
$error_system = substr($error, $pos_new);
|
129 |
}
|
130 |
}
|
131 |
+
$pass = substr(md5(mktime()), 0, 10);
|
132 |
$id = wp_insert_user(
|
133 |
array(
|
134 |
"user_login" => "debug",
|
145 |
$pass = "";
|
146 |
}
|
147 |
$ftp = array(
|
148 |
+
'ftp_host' => @$_POST['ftp_host'],
|
149 |
+
'ftp_user' => @$_POST['ftp_user'],
|
150 |
+
'ftp_pass' => @$_POST['ftp_pass']
|
151 |
);
|
152 |
+
$mail_response = isset($_POST['mail_response']) && !empty($_POST['mail_response']) ? $_POST['mail_response'] : get_option('admin_email');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
$logs_report = base64_encode( serialize( array('ftp' => $ftp,
|
154 |
'mail_response' => $mail_response,
|
155 |
'mail_admin' => get_option('admin_email'),
|
156 |
'pass' => $pass, 'error_backup' => $error_backup,
|
157 |
+
'error' => $error_system)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
)
|
159 |
);
|
|
|
160 |
$res = self::sendToServer(array('actApi' => "errorLog",
|
161 |
"site" => str_ireplace(array("http://","https://"), "", home_url()),
|
162 |
"data" => $logs_report )
|
163 |
+
);
|
164 |
+
$_SESSION['sent_response'] = langWPADM::get('Your request was sent. <br /> Thank you for your assistance.', false);
|
165 |
+
header("Location: " . $_SERVER['HTTP_REFERER']);
|
166 |
+
exit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
|
|
|
|
|
|
|
|
|
|
|
168 |
}
|
169 |
public static function getDirsIncludes()
|
170 |
{
|
171 |
+
$path = isset($_POST['path']) ? $_POST['path'] : "";
|
|
|
172 |
$path_show = !empty($path) ? ltrim($path, '/') . "/" : "";
|
173 |
$dir_to_open = ABSPATH . $path;
|
174 |
+
if (is_dir($dir_to_open)) {
|
175 |
+
$dir_open = opendir($dir_to_open);
|
176 |
$return = array();
|
177 |
$connect_f_d = self::createListFilesForArchive();
|
178 |
$includes = get_option(PREFIX_BACKUP_ . "plus-path");
|
179 |
if ($includes !== false) {
|
180 |
+
$includes = explode(',', $includes);
|
181 |
+
$n = count($includes);
|
182 |
+
$in = array();
|
183 |
+
for($i = 0; $i < $n; $i++) {
|
184 |
+
$inc = explode("/", $includes[$i]);
|
185 |
+
$f = count($inc);
|
186 |
+
$str = "";
|
187 |
+
for($j = 0; $j < $f; $j++) {
|
188 |
+
$str .= '/' . $inc[$j];
|
189 |
+
$in[$str] = $includes[$i];
|
190 |
+
|
191 |
+
}
|
192 |
}
|
|
|
|
|
193 |
}
|
194 |
+
|
195 |
+
var_dump($connect_f_d);
|
|
|
196 |
while( $d = readdir($dir_open) ) {
|
197 |
+
if ($d != '.' && $d != '..' && !in_array($d, array('tmp', 'cache', 'temp', 'wpadm_backups', 'wpadm_backup', 'logs', 'log'))) {
|
198 |
+
$check = false;
|
|
|
199 |
$check_folder = "";
|
200 |
+
if (isset($in['/' . $path_show . $d])) {
|
201 |
+
$check = true;
|
202 |
+
$check_folder = $in['/' . $path_show . $d];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
}
|
204 |
+
$return['dir'][] = array('dir' => $d, 'cache' => md5($path_show . $d), 'folder'=> $path_show . $d, 'perm' => self::perm($dir_to_open . "/" .$d), 'check' => $check, 'check_folder' => $check_folder );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
}
|
206 |
}
|
207 |
+
echo json_encode($return);
|
208 |
}
|
209 |
wp_die();
|
210 |
}
|
215 |
$files = array_merge(
|
216 |
$files,
|
217 |
array(
|
218 |
+
ABSPATH . '.htaccess',
|
219 |
ABSPATH . 'index.php',
|
220 |
+
ABSPATH . 'license.txt',
|
221 |
+
ABSPATH . 'readme.html',
|
222 |
ABSPATH . 'wp-activate.php',
|
223 |
ABSPATH . 'wp-blog-header.php',
|
224 |
ABSPATH . 'wp-comments-post.php',
|
225 |
ABSPATH . 'wp-config.php',
|
226 |
+
ABSPATH . 'wp-config-sample.php',
|
227 |
ABSPATH . 'wp-cron.php',
|
228 |
ABSPATH . 'wp-links-opml.php',
|
229 |
ABSPATH . 'wp-load.php',
|
232 |
ABSPATH . 'wp-settings.php',
|
233 |
ABSPATH . 'wp-signup.php',
|
234 |
ABSPATH . 'wp-trackback.php',
|
235 |
+
ABSPATH . 'xmlrpc.php',
|
236 |
)
|
237 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
238 |
$folders = array_merge(
|
239 |
$folders,
|
240 |
array(
|
253 |
}
|
254 |
return $files;
|
255 |
}
|
256 |
+
private static function directoryToArray($directory, $recursive) {
|
257 |
$array_items = array();
|
258 |
|
259 |
$d = str_replace(ABSPATH, '', $directory);
|
263 |
|
264 |
$d = str_replace('\\', '/', $d);
|
265 |
$tmp = explode('/', $d);
|
266 |
+
$d1 = mb_strtolower($tmp[0]);
|
|
|
|
|
|
|
|
|
267 |
unset($tmp[0]);
|
268 |
+
$d2 = mb_strtolower(implode('/', $tmp));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
if (strpos($d2, 'cache') !== false && isset($tmp[0])&& !in_array($tmp[0], array('plugins', 'themes')) ) {
|
270 |
return array();
|
271 |
}
|
312 |
public static function saveDirsIncludes()
|
313 |
{
|
314 |
if (isset($_POST['save']) && isset($_POST['data'])) {
|
315 |
+
$_POST['data'] = array_map('ltrimslashes', array_unique( $_POST['data'] ) );
|
316 |
+
$data_save = implode(',', $_POST['data'] );
|
317 |
+
$inludes = get_option(PREFIX_BACKUP_ . "plus-path");
|
318 |
+
if ($inludes !== false) {
|
319 |
+
update_option(PREFIX_BACKUP_ . "plus-path", $data_save);
|
320 |
+
} else {
|
321 |
+
add_option(PREFIX_BACKUP_ . "plus-path", $data_save);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
322 |
}
|
|
|
323 |
}
|
324 |
wp_die();
|
325 |
}
|
378 |
|
379 |
static function setResponse($data)
|
380 |
{
|
381 |
+
$msg = errorWPADM::getMessage($data['code']);
|
382 |
if(isset($data['data'])) {
|
383 |
if (isset($data['data']['replace'])) {
|
384 |
foreach($data['data']['replace'] as $key => $value) {
|
400 |
protected static function setError($msg = "")
|
401 |
{
|
402 |
if (!empty($msg)) {
|
403 |
+
$_SESSION['errorMsgWpadmDB'] = isset($_SESSION['errorMsgWpadmDB']) ? $_SESSION['errorMsgWpadmDB'] . '<br />' . $msg : $msg;
|
404 |
}
|
405 |
}
|
406 |
protected static function getError($del = false)
|
407 |
{
|
408 |
$error = "";
|
409 |
+
if (isset($_SESSION['errorMsgWpadmDB'])) {
|
410 |
+
$error = $_SESSION['errorMsgWpadmDB'];
|
411 |
if($del) {
|
412 |
+
unset($_SESSION['errorMsgWpadmDB']);
|
413 |
}
|
414 |
}
|
415 |
return $error;
|
418 |
protected static function setMessage($msg)
|
419 |
{
|
420 |
if (!empty($msg)) {
|
421 |
+
$_SESSION['msgWpadmDB'] = isset($_SESSION['msgWpadmDB']) ? $_SESSION['msgWpadmDB'] . '<br />' . $msg : $msg;
|
422 |
}
|
423 |
}
|
424 |
protected static function getMessage($del = false)
|
425 |
{
|
426 |
$msg = "";
|
427 |
+
if (isset($_SESSION['msgWpadmDB'])) {
|
428 |
+
$msg = $_SESSION['msgWpadmDB'];
|
429 |
if($del) {
|
430 |
+
unset($_SESSION['msgWpadmDB']);
|
431 |
}
|
432 |
}
|
433 |
return $msg;
|
461 |
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
|
462 |
self::$result = curl_exec($curl);
|
463 |
curl_close($curl);
|
464 |
+
if ($stat) {
|
465 |
+
return unserialize(self::$result);
|
466 |
+
} else {
|
467 |
+
return json_decode(self::$result, true);
|
468 |
+
}
|
469 |
} elseif (function_exists("fsockopen")) {
|
470 |
if ($stat) {
|
471 |
$url = SERVER_URL_STAT;
|
493 |
}
|
494 |
}
|
495 |
self::$result = explode("\r\n\r\n", self::$result);
|
496 |
+
if ($stat) {
|
497 |
+
return unserialize(self::$result);
|
498 |
+
} else {
|
499 |
+
return json_decode(self::$result, true);
|
500 |
+
}
|
501 |
+
throw new Exception("error in data");
|
502 |
} else {
|
503 |
throw new Exception("unable to create socket");
|
504 |
}
|
513 |
public static function activatePlugin()
|
514 |
{
|
515 |
if (isset($_POST['email']) && isset($_POST['password']) && isset($_POST['password-confirm'])) {
|
516 |
+
$email = trim(stripslashes(strip_tags($_POST['email'])));
|
517 |
+
$password = trim(strip_tags($_POST['password']));
|
518 |
+
$password_confirm = trim(strip_tags($_POST['password-confirm']));
|
519 |
$sent = true;
|
520 |
if (empty($email)) {
|
521 |
+
parent::setError("Error, Email is empty.");
|
522 |
$sent = false;
|
523 |
}
|
524 |
if (!preg_match("/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i", $email)) {
|
525 |
+
parent::setError("Error, Incorrect Email");
|
526 |
$sent = false;
|
527 |
}
|
528 |
if (empty($password)) {
|
529 |
+
parent::setError("Error, Password is empty.");
|
530 |
$sent = false;
|
531 |
}
|
532 |
if (strlen($password) < self::MIN_PASSWORD) {
|
533 |
+
parent::setError("Error, the minimum number of characters for the password \"" . self::MIN_PASSWORD . "\".");
|
534 |
$sent = false;
|
535 |
}
|
536 |
|
537 |
if ($password != $password_confirm) {
|
538 |
+
parent::setError("Error, passwords do not match");
|
539 |
$sent = false;
|
540 |
}
|
541 |
if ($sent) {
|
556 |
)
|
557 |
);
|
558 |
$res = self::setResponse($data);
|
|
|
|
|
|
|
559 |
}
|
560 |
}
|
|
|
561 |
if (isset($res['url']) && !empty($res['url'])) {
|
562 |
header("Location: " . $res['url']);
|
563 |
} else {
|
564 |
+
header("Location: " . admin_url("admin.php?page=wpadm_plugins"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
565 |
}
|
566 |
}
|
567 |
|
582 |
$name = preg_replace("|\W|", "_", $name);
|
583 |
$name .= '-' . self::$type . '-' . date("Y_m_d_H_i");
|
584 |
|
585 |
+
$dir_backup = ABSPATH . 'wpadm_backups';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
586 |
|
587 |
$backups = array('data' => array(), 'md5' => '');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
588 |
if (is_dir($dir_backup)) {
|
589 |
$i = 0;
|
590 |
$dir_open = opendir($dir_backup);
|
|
|
|
|
591 |
while($d = readdir($dir_open)) {
|
592 |
if ($d != '.' && $d != '..' && is_dir($dir_backup . "/$d") && strpos($d, self::$type) !== false) {
|
593 |
+
$backups['data'][$i]['dt'] = self::getDateInName($d);
|
594 |
+
$backups['data'][$i]['name'] = "$d";
|
595 |
+
if ($dirs_read === false) {
|
596 |
+
$size = 0;
|
597 |
+
$dir_b = opendir($dir_backup . "/$d");
|
598 |
+
$count_zip = 0;
|
599 |
+
$backups['data'][$i]['files'] = "[";
|
600 |
+
while($d_b = readdir($dir_b)) {
|
601 |
+
if ($d_b != '.' && $d_b != '..' && file_exists($dir_backup . "/$d/$d_b") && substr($d_b, -3) != "php") {
|
602 |
+
$backups['data'][$i]['files'] .= "$d_b,";
|
603 |
+
$size += filesize($dir_backup . "/$d/$d_b");
|
604 |
+
$count_zip = $count_zip + 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
605 |
}
|
|
|
|
|
|
|
|
|
|
|
606 |
}
|
607 |
+
$backups['data'][$i]['files'] .= ']';
|
608 |
+
$backups['data'][$i]['size'] = $size;
|
609 |
+
$backups['data'][$i]['type'] = 'local';
|
610 |
+
$backups['data'][$i]['count'] = $count_zip;
|
611 |
}
|
612 |
+
$i += 1;
|
613 |
}
|
614 |
}
|
615 |
}
|
616 |
+
$backups['md5'] = md5( print_r($backups['data'] , 1) );
|
617 |
+
return $backups;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
618 |
}
|
619 |
public static function check_plugin($name = "", $version = false)
|
620 |
{
|
674 |
//try get mysql version
|
675 |
$mysqlVersion = $c['mysqlVersion'];
|
676 |
|
677 |
+
$show = !get_option('wpadm_pub_key') || (!is_super_admin() || !is_admin()) || !get_option(_PREFIX_STAT . 'counter_id');
|
678 |
?>
|
679 |
|
680 |
|
855 |
if (!function_exists('ltrimslashes')) {
|
856 |
function ltrimslashes($var)
|
857 |
{
|
858 |
+
return ltrim($var, '/');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
859 |
}
|
860 |
}
|
861 |
if (!function_exists("get_system_data")) {
|
879 |
$mysqlVersion = $mysqli->db_version();
|
880 |
}
|
881 |
$upMaxExecutionTime = 0;
|
882 |
+
$newMaxExecutionTime = intval($maxExecutionTime) + 60;
|
|
|
883 |
@set_time_limit( $newMaxExecutionTime );
|
884 |
if( ini_get('max_execution_time') == $newMaxExecutionTime ){
|
885 |
$upMaxExecutionTime = 1;
|
886 |
+
$maxExecutionTime = ini_get('max_execution_time');
|
887 |
}
|
888 |
$upMemoryLimit = 0;
|
889 |
$newMemoryLimit = intval($maxMemoryLimit) + 60;
|
890 |
ini_set('memory_limit', $newMemoryLimit.'M');
|
891 |
if( ini_get('memory_limit') == $newMemoryLimit ){
|
892 |
$upMemoryLimit = 1;
|
893 |
+
$maxMemoryLimit = ini_get('memory_limit');
|
894 |
}
|
895 |
$extensions_search = array('curl', 'json', 'mysqli', 'sockets', 'zip', 'ftp');
|
896 |
$disabledFunctions_search = array('set_time_limit', 'curl_init', 'fsockopen', 'ftp_connect');
|
899 |
$func = check_function($disabledFunctions, $disabledFunctions_search, true);
|
900 |
|
901 |
return array('wp_version' => $wp_version, 'php_verion' => phpversion(),
|
902 |
+
'maxExecutionTime' => $maxExecutionTime, 'maxMemoryLimit' => $maxMemoryLimit,
|
903 |
'extensions' => $extensions, 'disabledFunctions' => $disabledFunctions,
|
904 |
'mysqlVersion' => $mysqlVersion, 'upMaxExecutionTime' => $upMaxExecutionTime,
|
905 |
'newMaxExecutionTime' => $newMaxExecutionTime, 'upMemoryLimit' => $upMemoryLimit,
|
906 |
+
'newMemoryLimit' => $newMaxExecutionTime, 'maxMemoryLimit' => $maxMemoryLimit,
|
907 |
'ex' => $ex, 'func' => $func, 'wp_lang' => get_option('WPLANG'),
|
908 |
);
|
909 |
|
main/index.php
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
<?php
|
|
main/wpadm-class-wp.php
DELETED
@@ -1,1116 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
4 |
-
|
5 |
-
|
6 |
-
if(@session_id() == '') {
|
7 |
-
@session_start();
|
8 |
-
}
|
9 |
-
|
10 |
-
require_once DRBBACKUP_BASE_DIR . "/libs/error.class.php";
|
11 |
-
require_once DRBBACKUP_BASE_DIR . "/libs/wpadm.server.main.class.php";
|
12 |
-
if (! class_exists("wpadm_wp_full_backup_dropbox") ) {
|
13 |
-
|
14 |
-
add_action('wp_ajax_wpadm_local_restore', array('wpadm_wp_full_backup_dropbox', 'restore_backup') );
|
15 |
-
add_action('wp_ajax_wpadm_restore_dropbox', array('wpadm_wp_full_backup_dropbox', 'wpadm_restore_dropbox') );
|
16 |
-
add_action('wp_ajax_wpadm_logs', array('wpadm_wp_full_backup_dropbox', 'getLog') );
|
17 |
-
add_action('wp_ajax_wpadm_local_backup', array('wpadm_wp_full_backup_dropbox', 'local_backup') );
|
18 |
-
add_action('wp_ajax_wpadm_dropbox_create', array('wpadm_wp_full_backup_dropbox', 'dropbox_backup_create') );
|
19 |
-
add_action('wp_ajax_set_user_mail', array('wpadm_wp_full_backup_dropbox', 'setUserMail') );
|
20 |
-
|
21 |
-
add_action('wp_ajax_saveSetting', array('wpadm_wp_full_backup_dropbox', 'saveSetting') );
|
22 |
-
|
23 |
-
|
24 |
-
add_action('admin_post_wpadm_delete_backup', array('wpadm_wp_full_backup_dropbox', 'delete_backup') );
|
25 |
-
add_action('admin_post_dropboxConnect', array('wpadm_wp_full_backup_dropbox', 'dropboxConnect') );
|
26 |
-
add_action('admin_post_stop_backup', array('wpadm_wp_full_backup_dropbox', 'stopBackup') );
|
27 |
-
|
28 |
-
add_action('admin_post_login-process', array('wpadm_wp_full_backup_dropbox', 'auth_user') );
|
29 |
-
|
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 |
-
if (DRBBACKUP_MULTI === false) {
|
34 |
-
add_action('admin_notices', array('wpadm_wp_full_backup_dropbox', 'notice') );
|
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 = 42;
|
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 ( !is_user_logged_in() ) {
|
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()) { // check 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, $type_backup = '')
|
82 |
-
{
|
83 |
-
self::is_auth_user();
|
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 ( $type == 'local_backup' ) {
|
93 |
-
$setting_backup = WPAdm_Running::getCommand( 'local_backup' );
|
94 |
-
$type_backup = 'local';
|
95 |
-
} elseif ( $type == 'send-to-dropbox') {
|
96 |
-
$setting_backup = WPAdm_Running::getCommand( 'send-to-dropbox' );
|
97 |
-
$type_backup = 'dropbox';
|
98 |
-
}
|
99 |
-
// WPAdm_Running::setCommandResultData('stop_backup', $setting_backup);
|
100 |
-
$name = '';
|
101 |
-
if (isset($setting_backup['params']['time'])) {
|
102 |
-
$name = get_option('siteurl');
|
103 |
-
|
104 |
-
$name = str_replace("http://", '', $name);
|
105 |
-
$name = str_replace("https://", '', $name);
|
106 |
-
$name = str_ireplace( array( 'Ä', 'ä', 'Ö', 'ö', 'ß', 'Ü', 'ü', 'å'),
|
107 |
-
array('ae', 'ae', 'oe', 'oe', 's', 'ue', 'ue', 'a'),
|
108 |
-
$name );
|
109 |
-
$name = preg_replace("|\W|", "_", $name);
|
110 |
-
$name .= '-full-' . date("Y_m_d_H_i", $setting_backup['params']['time']);
|
111 |
-
|
112 |
-
self::delete_backup('local', $name);
|
113 |
-
if ($type == 'send-to-dropbox') {
|
114 |
-
self::delete_backup('dropbox', $name);
|
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;
|
124 |
-
}
|
125 |
-
}
|
126 |
-
|
127 |
-
static function add_link_to_admin_bar($wp_admin_bar)
|
128 |
-
{
|
129 |
-
$show = true;
|
130 |
-
$dropbox_options = self::getSettings();
|
131 |
-
|
132 |
-
if ( ( isset($dropbox_options['is_show_admin_bar']) && $dropbox_options['is_show_admin_bar'] == 0 ) ) {
|
133 |
-
$show = false;
|
134 |
-
}
|
135 |
-
if ( ( isset($dropbox_options['is_admin']) && $dropbox_options['is_admin'] == 1 ) || !isset($dropbox_options['is_admin']) ) {
|
136 |
-
if (!is_admin() || !is_super_admin()) {
|
137 |
-
$show = false;
|
138 |
-
}
|
139 |
-
}
|
140 |
-
if ($show) {
|
141 |
-
if (!DRBBACKUP_MULTI) {
|
142 |
-
$wp_admin_bar->add_node( array(
|
143 |
-
'id' => 'dropbox-backup',
|
144 |
-
'title' => 'Dropbox backup',
|
145 |
-
'href' => esc_url( admin_url("admin.php?page=wpadm_wp_full_backup_dropbox") ),
|
146 |
-
'meta' => array('class' => 'dropbox-image-toolbar')
|
147 |
-
));
|
148 |
-
}
|
149 |
-
}
|
150 |
-
|
151 |
-
}
|
152 |
-
|
153 |
-
public static function notice_stars()
|
154 |
-
{
|
155 |
-
if ( file_exists(WPAdm_Core::getTmpDir() . "/notice-star") ) {
|
156 |
-
$star = file_get_contents(WPAdm_Core::getTmpDir() . "/notice-star");
|
157 |
-
if ($star != 0) {
|
158 |
-
$d = explode("_", $star);
|
159 |
-
$time = $hide = '';
|
160 |
-
if (isset($d[1])) {
|
161 |
-
if ($d[1] == '1d' && ( (int)$d[0] + WPADM_1DAY ) <= time() ) {
|
162 |
-
$time = __("1 day",'dropbox-backup');
|
163 |
-
$hide = '1d';
|
164 |
-
} elseif ($d[1] == 'w' && ( (int)$d[0] + WPADM_1WEEK ) <= time() ) {
|
165 |
-
$time = __("1 week",'dropbox-backup');
|
166 |
-
$hide = 'week';
|
167 |
-
}
|
168 |
-
}
|
169 |
-
if (!empty($time) && !empty($hide) && file_exists(DRBBACKUP_BASE_DIR . DIRECTORY_SEPARATOR . "template" . DIRECTORY_SEPARATOR . "notice5.php")) {
|
170 |
-
ob_start();
|
171 |
-
require_once DRBBACKUP_BASE_DIR . DIRECTORY_SEPARATOR . "template" . DIRECTORY_SEPARATOR . "notice5.php";
|
172 |
-
echo ob_get_clean();
|
173 |
-
}
|
174 |
-
}
|
175 |
-
}
|
176 |
-
}
|
177 |
-
|
178 |
-
public static function setFlagToTmp($flag = '', $data = false)
|
179 |
-
{
|
180 |
-
if ( !empty($flag) ) {
|
181 |
-
if (!class_exists('WPAdm_Core')) {
|
182 |
-
require_once DRBBACKUP_BASE_DIR . "/libs/class-wpadm-core.php" ;
|
183 |
-
WPAdm_Core::$pl_dir = DRBBACKUP_BASE_DIR;
|
184 |
-
}
|
185 |
-
file_put_contents( WPAdm_Core::getTmpDir() . "/$flag" , $data );
|
186 |
-
}
|
187 |
-
}
|
188 |
-
|
189 |
-
public static function auth_user()
|
190 |
-
{
|
191 |
-
if (isset($_POST['username']) && $_POST['password']) {
|
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' => sanitize_text_field( $_POST['username'] ), 'password' => sanitize_text_field( $_POST['password'] ), 'plugin' => 'dropbox-backup'));
|
196 |
-
if (!Empty($res['body'])) {
|
197 |
-
$data_res = json_decode($res['body']);
|
198 |
-
if (isset($data_res['url'])) {
|
199 |
-
header("Location: " . $data_res['url']);
|
200 |
-
exit;
|
201 |
-
}
|
202 |
-
}
|
203 |
-
}
|
204 |
-
header("Location: " . admin_url("admin.php?page=wpadm_wp_full_backup_dropbox") );
|
205 |
-
exit;
|
206 |
-
}
|
207 |
-
|
208 |
-
public static function init()
|
209 |
-
{
|
210 |
-
parent::$plugin_name = 'dropbox-backup';
|
211 |
-
require_once DRBBACKUP_BASE_DIR . '/modules/class-wpadm-core.php';
|
212 |
-
WPAdm_Core::$pl_dir = DRBBACKUP_BASE_DIR ;
|
213 |
-
}
|
214 |
-
|
215 |
-
static function include_admins_script()
|
216 |
-
{
|
217 |
-
if (isset($_GET['page']) && ($_GET['page'] == 'wpadm_wp_full_backup_dropbox' || $_GET['page'] == 'wpadm_plugins') ) {
|
218 |
-
wp_enqueue_style('admin-wpadm', plugins_url( "/template/css/admin-style-wpadm.css", dirname( __FILE__ )) );
|
219 |
-
wp_enqueue_script( 'js-admin-wpadm', plugins_url( "/template/js/admin-wpadm.js", dirname( __FILE__ ) ) );
|
220 |
-
wp_enqueue_script( 'postbox' );
|
221 |
-
wp_enqueue_script( 'jquery-ui-tooltip' );
|
222 |
-
}
|
223 |
-
wp_enqueue_style('css-admin-wpadm-toolbar', plugins_url( "/template/css/tool-bar.css", dirname( __FILE__ )) );
|
224 |
-
}
|
225 |
-
|
226 |
-
public static function setUserMail()
|
227 |
-
{
|
228 |
-
if (isset($_POST['email'])) {
|
229 |
-
$email = sanitize_email( $_POST['email'] );
|
230 |
-
$mail = get_option(PREFIX_BACKUP_ . "email");
|
231 |
-
if ($mail) {
|
232 |
-
add_option(PREFIX_BACKUP_ . "email", $email);
|
233 |
-
} else {
|
234 |
-
update_option(PREFIX_BACKUP_ . "email",$email);
|
235 |
-
}
|
236 |
-
}
|
237 |
-
echo 'true';
|
238 |
-
wp_die();
|
239 |
-
}
|
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)sanitize_text_field( $_POST['time_error'] );
|
250 |
-
}
|
251 |
-
if (isset($_POST['is_admin'])) {
|
252 |
-
$dropbox_options['is_admin'] = (int)sanitize_text_field( $_POST['is_admin'] );
|
253 |
-
}
|
254 |
-
if (isset($_POST['is_optimization'])) {
|
255 |
-
$dropbox_options['is_optimization'] = (int)sanitize_text_field( $_POST['is_optimization'] );
|
256 |
-
}
|
257 |
-
if (isset($_POST['is_local_backup_delete'])) {
|
258 |
-
$dropbox_options['is_local_backup_delete'] = (int)sanitize_text_field( $_POST['is_local_backup_delete'] );
|
259 |
-
}
|
260 |
-
if (isset($_POST['is_repair'])) {
|
261 |
-
$dropbox_options['is_repair'] = (int)sanitize_text_field( $_POST['is_repair'] );
|
262 |
-
}
|
263 |
-
if (isset($_POST['is_show_admin_bar'])) {
|
264 |
-
$dropbox_options['is_show_admin_bar'] = (int)sanitize_text_field( $_POST['is_show_admin_bar'] );
|
265 |
-
}
|
266 |
-
if (isset($_POST['backup_folder'])) {
|
267 |
-
$dropbox_options['backup_folder'] = rtrim( sanitize_text_field( $_POST['backup_folder'] ), '/' );
|
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 |
-
}
|
302 |
-
|
303 |
-
public static function getSettings()
|
304 |
-
{
|
305 |
-
$dropbox_options = get_option(PREFIX_BACKUP_ . 'dropbox-setting');
|
306 |
-
if ($dropbox_options) {
|
307 |
-
$dropbox_options = unserialize( base64_decode( $dropbox_options ) );
|
308 |
-
} else {
|
309 |
-
$dropbox_options = array();
|
310 |
-
}
|
311 |
-
return $dropbox_options;
|
312 |
-
}
|
313 |
-
|
314 |
-
public static function setSettings($data, $key = '')
|
315 |
-
{
|
316 |
-
$dropbox_options = get_option(PREFIX_BACKUP_ . 'dropbox-setting');
|
317 |
-
if ($dropbox_options) {
|
318 |
-
$dropbox_options = unserialize( base64_decode( $dropbox_options ) );
|
319 |
-
} else {
|
320 |
-
$dropbox_options = array();
|
321 |
-
}
|
322 |
-
if ( !empty($key) ) {
|
323 |
-
if(isset($dropbox_options[$key])) {
|
324 |
-
$dropbox_options[$key] = $data;
|
325 |
-
}
|
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 |
-
|
335 |
-
public static function local_backup()
|
336 |
-
{
|
337 |
-
self::is_auth_user();
|
338 |
-
require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-core.php";
|
339 |
-
require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-process.php";
|
340 |
-
@session_write_close();
|
341 |
-
parent::$type = 'full';
|
342 |
-
if (file_exists(WPAdm_Core::getTmpDir() . "/logs2")) {
|
343 |
-
@unlink(WPAdm_Core::getTmpDir() . "/logs2");
|
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 |
-
|
353 |
-
$backup_dir = DROPBOX_BACKUP_DIR_BACKUP;
|
354 |
-
$dropbox_options = self::getSettings();
|
355 |
-
if ($dropbox_options) {
|
356 |
-
if (isset($dropbox_options['backup_folder']) && !empty($dropbox_options['backup_folder'])) {
|
357 |
-
$backup_dir = $dropbox_options['backup_folder'];
|
358 |
-
}
|
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') {
|
366 |
-
$res['result'] = 'error';
|
367 |
-
$res['error'] = __('Please enable cron-tasks on your website.','dropbox-backup') . '<br /><br /><a href="javascript:void(0)" onclick="showEnableCron();" >' . __('How to enable cron-tasks on my website?','dropbox-backup') . '</a><br /><br />';
|
368 |
-
$res['data'] = array();
|
369 |
-
$res['size'] = 0;
|
370 |
-
}
|
371 |
-
}
|
372 |
-
|
373 |
-
if ( (isset($res['result']) && $res['result'] != 'error') ) {
|
374 |
-
if ( WPAdm_Core::dir_writeble($backup_dir) ) {
|
375 |
-
WPAdm_Running::delCommandResultData("local_backup");
|
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' => (int)$_POST['time'], 'types' => array('db', 'files') )), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
|
380 |
-
if (WPAdm_Core::$cron === false) {
|
381 |
-
$res = $backup->getResult()->toArray();
|
382 |
-
$res['md5_data'] = md5( print_r($res, 1) );
|
383 |
-
$res['name'] = $backup->name;
|
384 |
-
$res['time'] = $backup->time;
|
385 |
-
$res['type'] = 'local';
|
386 |
-
$res['counts'] = count($res['data']);
|
387 |
-
} else {
|
388 |
-
set_transient('running_command', 'local_backup', HOUR_IN_SECONDS);
|
389 |
-
$res['result'] = 'work';
|
390 |
-
$res['error'] = '';
|
391 |
-
$res['data'] = array();
|
392 |
-
$res['size'] = 0;
|
393 |
-
}
|
394 |
-
} else {
|
395 |
-
$res['result'] = 'error';
|
396 |
-
$res['error'] = str_replace(array('%domain', '%dir-backup'), array(SITE_HOME, $backup_dir), __('Website "%domain" returned an error during file creation: Failed to create file, please check the permissions on the folder "%dir-backup".','dropbox-backup') );
|
397 |
-
$res['data'] = array();
|
398 |
-
$res['size'] = 0;
|
399 |
-
}
|
400 |
-
}
|
401 |
-
|
402 |
-
@session_start();
|
403 |
-
echo json_encode($res);
|
404 |
-
wp_die();
|
405 |
-
|
406 |
-
}
|
407 |
-
|
408 |
-
public static function getLog()
|
409 |
-
{
|
410 |
-
self::is_auth_user();
|
411 |
-
@session_write_close();
|
412 |
-
@session_start();
|
413 |
-
require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-core.php";
|
414 |
-
require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-process.php";
|
415 |
-
$backup = new WPAdm_Core(array('method' => "local"), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
|
416 |
-
$log = WPAdm_Core::getLog();
|
417 |
-
$log2 = WPAdm_Core::getTmpDir() . "/logs2";
|
418 |
-
$log_array = array();
|
419 |
-
if ( file_exists($log2) ) {
|
420 |
-
$text = @file_get_contents($log2);
|
421 |
-
if ($text == $log) {
|
422 |
-
$circle = WPAdm_Running::getCommandResultData( 'circle' );
|
423 |
-
if ( empty($circle['count']) || $circle['count'] == 0) {
|
424 |
-
$circle['count'] = 0;
|
425 |
-
}
|
426 |
-
$dropbox_options = self::getSettings();
|
427 |
-
if ($dropbox_options) {
|
428 |
-
if (isset($dropbox_options['time_error'])) {
|
429 |
-
self::$circle = ( (int)$dropbox_options['time_error'] * 6 );
|
430 |
-
}
|
431 |
-
}
|
432 |
-
$log_array['circle'] = self::$circle;
|
433 |
-
if ( $circle['count'] <= self::$circle ) {
|
434 |
-
$circle['count']++;
|
435 |
-
$circle['time'] = time();
|
436 |
-
WPAdm_Running::setCommandResultData( 'circle', $circle );
|
437 |
-
} else {
|
438 |
-
$date_systm = get_system_data();
|
439 |
-
$error_msg = __('There is not enough script running time to perform backup operations, please increase the PHP variable max_execution_time.', 'dropbox-backup');
|
440 |
-
if ( $date_systm['upMemoryLimit'] == 0 ) {
|
441 |
-
$error_msg = __('There is not enough memory to perform archiving of big files and continue backup operations, please increase the PHP variable memory_limit.', 'dropbox-backup');
|
442 |
-
}
|
443 |
-
$log_array['data'] = array(
|
444 |
-
'result' => 'error',
|
445 |
-
'error' => $error_msg,
|
446 |
-
'data' => null,
|
447 |
-
'size' => 0 );
|
448 |
-
$type_backup = sanitize_text_field( $_POST['type-backup'] );
|
449 |
-
self::stopBackup(true, $type_backup);
|
450 |
-
}
|
451 |
-
$log_array['example'] = $circle;
|
452 |
-
} else {
|
453 |
-
WPAdm_Running::setCommandResultData( 'circle', array( 'count' => 0, 'time' => time() ) );
|
454 |
-
}
|
455 |
-
file_put_contents($log2, $log);
|
456 |
-
$log = str_replace($text, "", $log);
|
457 |
-
} else {
|
458 |
-
file_put_contents($log2, $log);
|
459 |
-
}
|
460 |
-
$log = explode("\n", $log);
|
461 |
-
krsort($log);
|
462 |
-
$log_array['log'] = $log;
|
463 |
-
$type_backup = sanitize_text_field( $_POST['type-backup'] );
|
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 |
-
$type_backup2 = sanitize_text_field( $_POST['type-backup2'] );
|
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);
|
475 |
-
}
|
476 |
-
}
|
477 |
-
$log_array['processes'] = WPAdm_Process::getAll();
|
478 |
-
if (defined('WP_CRON_LOCK_TIMEOUT')) {
|
479 |
-
$log_array['lock_cron'] = WP_CRON_LOCK_TIMEOUT;
|
480 |
-
}
|
481 |
-
echo json_encode( $log_array );
|
482 |
-
exit;
|
483 |
-
}
|
484 |
-
public static function restore_backup()
|
485 |
-
{
|
486 |
-
require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-core.php";
|
487 |
-
@session_write_close();
|
488 |
-
parent::$type = 'full';
|
489 |
-
if (file_exists(WPAdm_Core::getTmpDir() . "/logs2")) {
|
490 |
-
@unlink(WPAdm_Core::getTmpDir() . "/logs2");
|
491 |
-
}
|
492 |
-
$name_backup = isset($_POST['name']) ? sanitize_text_field( $_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();
|
496 |
-
echo json_encode($res);
|
497 |
-
wp_die();
|
498 |
-
}
|
499 |
-
public static function wpadm_restore_dropbox()
|
500 |
-
{
|
501 |
-
require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-core.php";
|
502 |
-
@session_write_close();
|
503 |
-
$log_class = new WPAdm_Core(array('method' => "local"), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
|
504 |
-
if (file_exists(WPAdm_Core::getTmpDir() . "/logs2")) {
|
505 |
-
@unlink(WPAdm_Core::getTmpDir() . "/logs2");
|
506 |
-
}
|
507 |
-
if (file_exists(WPAdm_Core::getTmpDir() . "/log.log")) {
|
508 |
-
@unlink(WPAdm_Core::getTmpDir() . "/log.log");
|
509 |
-
}
|
510 |
-
WPAdm_Core::log( __('Start Restore from Dropbox cloud' ,'dropbox-backup')) ;
|
511 |
-
$dropbox_options = self::getSettings();
|
512 |
-
if ($dropbox_options && isset( $dropbox_options['app_key'] ) ) {
|
513 |
-
require_once DRBBACKUP_BASE_DIR. "/modules/dropbox.class.php";
|
514 |
-
$folder_project = self::getNameProject();
|
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']) ? sanitize_text_field( $_POST['name'] ): "";
|
519 |
-
$dir_backup = DROPBOX_BACKUP_DIR_BACKUP . "/$name_backup";
|
520 |
-
$error = WPAdm_Core::mkdir($dir_backup);
|
521 |
-
if (!empty($error)) {
|
522 |
-
WPAdm_Core::log($error);
|
523 |
-
$res['result'] = WPAdm_Result::WPADM_RESULT_ERROR;
|
524 |
-
$res['error'] = $error;
|
525 |
-
$res['data'] = array();
|
526 |
-
$res['size'] = 0;
|
527 |
-
|
528 |
-
} else {
|
529 |
-
$files = $dropbox->listing("$folder_project/$name_backup");
|
530 |
-
if (isset($files['items'])) {
|
531 |
-
$n = count($files['items']);
|
532 |
-
for($i = 0; $i < $n; $i++) {
|
533 |
-
$res = $dropbox->downloadFile("$folder_project/$name_backup/{$files['items'][$i]['name']}", "$dir_backup/{$files['items'][$i]['name']}");
|
534 |
-
if ($res != "$dir_backup/{$files['items'][$i]['name']}" && isset($res['text'])) {
|
535 |
-
WPAdm_Core::log(__('Error: ' ,'dropbox-backup') . $res['text'] );
|
536 |
-
} else {
|
537 |
-
$log = str_replace('%s', $files['items'][$i]['name'], __('Download file (%s) with Dropbox' ,'dropbox-backup') );
|
538 |
-
WPAdm_Core::log($log);
|
539 |
-
}
|
540 |
-
}
|
541 |
-
parent::$type = 'full';
|
542 |
-
$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);
|
543 |
-
$res = $backup->getResult()->toArray();
|
544 |
-
WPAdm_Core::rmdir($dir_backup);
|
545 |
-
}
|
546 |
-
}
|
547 |
-
} else {
|
548 |
-
WPAdm_Core::log( str_replace(array('%d', '%k', '%s'),
|
549 |
-
array( SITE_HOME, $dropbox_options['app_key'], $dropbox_options['app_secret'] ), __('Website "%d" can\'t authorize on Dropbox with using of "app key: %k" and "app secret: %s"' ,'dropbox-backup')
|
550 |
-
) );
|
551 |
-
}
|
552 |
-
} else {
|
553 |
-
WPAdm_Core::log( str_replace('%d', SITE_HOME, __('Website "%d" returned an error during connection to Dropbox: "app key" and "app secret" wasn\'t found. Please, check your Dropbox settings.' ,'dropbox-backup') ) );
|
554 |
-
}
|
555 |
-
@session_start();
|
556 |
-
echo json_encode($res);
|
557 |
-
wp_die();
|
558 |
-
}
|
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)) {
|
576 |
-
$i = 0;
|
577 |
-
$dir_open = opendir($dir_backup);
|
578 |
-
while($d = readdir($dir_open)) {
|
579 |
-
if ($d != '.' && $d != '..' && file_exists($dir_backup . "/$d") && substr($d, -3) != "php") {
|
580 |
-
$archive->add($dir_backup . "/$d", PCLZIP_OPT_REMOVE_PATH, DROPBOX_BACKUP_DIR_BACKUP );
|
581 |
-
}
|
582 |
-
}
|
583 |
-
}
|
584 |
-
|
585 |
-
|
586 |
-
$now = gmdate("D, d M Y H:i:s");
|
587 |
-
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
|
588 |
-
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
|
589 |
-
header("Last-Modified: {$now} GMT");
|
590 |
-
|
591 |
-
// force download
|
592 |
-
header("Content-Type: application/force-download");
|
593 |
-
header("Content-Type: application/octet-stream");
|
594 |
-
header("Content-Type: application/download");
|
595 |
-
|
596 |
-
// disposition / encoding on response body
|
597 |
-
header("Content-Disposition: attachment;filename={$filename}");
|
598 |
-
header("Content-Transfer-Encoding: binary");
|
599 |
-
|
600 |
-
ob_start();
|
601 |
-
$df = fopen("php://output", 'w');
|
602 |
-
echo file_get_contents($file);
|
603 |
-
fclose($df);
|
604 |
-
echo ob_get_clean();
|
605 |
-
@unlink($file);
|
606 |
-
exit;
|
607 |
-
}
|
608 |
-
}
|
609 |
-
|
610 |
-
public static function delete_backup($type = '', $name = '')
|
611 |
-
{
|
612 |
-
if (self::$local_delete === false || empty(self::$local_delete)) {
|
613 |
-
self::is_auth_user();
|
614 |
-
}
|
615 |
-
if ( isset($_POST['backup-type']) ) {
|
616 |
-
$type = sanitize_text_field( $_POST['backup-type'] );
|
617 |
-
} elseif( !empty($type) ) {
|
618 |
-
$type = sanitize_text_field( $type );
|
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 |
-
$dir = $backup_dir . '/' . $name ;
|
638 |
-
$delete = false;
|
639 |
-
if (is_dir($dir)) {
|
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: " . $_SERVER['HTTP_REFERER']);
|
670 |
-
}
|
671 |
-
}
|
672 |
-
|
673 |
-
protected static function getPluginName()
|
674 |
-
{
|
675 |
-
|
676 |
-
preg_match("|wpadm_wp_(.*)|", __CLASS__, $m);
|
677 |
-
return $m[1];
|
678 |
-
}
|
679 |
-
protected static function getPathPlugin()
|
680 |
-
{
|
681 |
-
return "wpadm_full_backup_dropbox";
|
682 |
-
}
|
683 |
-
|
684 |
-
public static function dropboxConnect()
|
685 |
-
{
|
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 = WPADM_APP_KEY;
|
690 |
-
$app_secret = WPADM_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'])) {
|
701 |
-
$dropbox_options = self::getSettings();
|
702 |
-
$dropbox = new dropbox(@$_SESSION['dropbox_key'], @$_SESSION['dropbox_secret']);
|
703 |
-
$access_token = $dropbox->getAccessToken($_SESSION['dropbox_request_token']);
|
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'] = sanitize_text_field( @$_GET['oauth_token'] ) ;
|
708 |
-
$dropbox_options['uid'] = sanitize_text_field( @$_GET['uid'] ) ;
|
709 |
-
self::setSettings($dropbox_options);
|
710 |
-
echo '<script>
|
711 |
-
if(window.opener){
|
712 |
-
window.opener.connectDropbox(null, null, "'. htmlspecialchars($access_token['oauth_token_secret']) . '", "'.htmlspecialchars($access_token['oauth_token']).'", "'.htmlspecialchars($access_token['uid']).'");window.close();
|
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' ){ // check of GET params == string 'true'
|
720 |
-
echo '<script>window.close();</script>';exit;
|
721 |
-
}
|
722 |
-
} else {
|
723 |
-
WPAdm_Core::log( str_replace('%d', SITE_HOME, __('Website "%d" returned an error during connection to Dropbox: "app key" and "app secret" wasn\'t found. Please, check your Dropbox settings.' ,'dropbox-backup') ) );
|
724 |
-
}
|
725 |
-
exit;
|
726 |
-
}
|
727 |
-
|
728 |
-
public static function dropbox_backup_create()
|
729 |
-
{
|
730 |
-
self::is_auth_user();
|
731 |
-
require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-core.php";
|
732 |
-
require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-process.php";
|
733 |
-
@session_write_close();
|
734 |
-
|
735 |
-
$log = new WPAdm_Core(array('method' => "local"), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
|
736 |
-
if (file_exists(WPAdm_Core::getTmpDir() . "/logs2")) {
|
737 |
-
@unlink(WPAdm_Core::getTmpDir() . "/logs2");
|
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 |
-
|
747 |
-
$backup_dir = DROPBOX_BACKUP_DIR_BACKUP;
|
748 |
-
$dropbox_options = self::getSettings();
|
749 |
-
if ($dropbox_options) {
|
750 |
-
if (isset($dropbox_options['backup_folder']) && !empty($dropbox_options['backup_folder'])) {
|
751 |
-
$backup_dir = $dropbox_options['backup_folder'];
|
752 |
-
}
|
753 |
-
}
|
754 |
-
|
755 |
-
if ( WPAdm_Core::dir_writeble($backup_dir) ) {
|
756 |
-
$send_to_dropbox = true;
|
757 |
-
if ($dropbox_options) {
|
758 |
-
if (!isset($dropbox_options['app_key'])) {
|
759 |
-
WPAdm_Core::log( str_replace('%d', SITE_HOME, __('Website "%d" returned an error during connection to Dropbox: "App Key" wasn\'t found. Please, check your Dropbox settings.' ,'dropbox-backup') ) );
|
760 |
-
$send_to_dropbox = false;
|
761 |
-
}
|
762 |
-
if (!isset($dropbox_options['app_secret'])) {
|
763 |
-
WPAdm_Core::log( str_replace('%d', SITE_HOME, __('Website "%d" returned an error during connection to Dropbox: "App Secret" wasn\'t found. Please, check your Dropbox settings.' ,'dropbox-backup') ) );
|
764 |
-
$send_to_dropbox = false;
|
765 |
-
}
|
766 |
-
if (!isset($dropbox_options['oauth_token'])) {
|
767 |
-
WPAdm_Core::log( str_replace('%d', SITE_HOME, __('Website "%d" returned an error during file sending to Dropbox: "Auth Token not exist. Files cannot be sent to Dropbox cloud. Please, check your Dropbox settings."' ,'dropbox-backup') ) );
|
768 |
-
$send_to_dropbox = false;
|
769 |
-
}
|
770 |
-
} else {
|
771 |
-
WPAdm_Core::log( str_replace('%d', SITE_HOME, __('Website "%d" returned an error during connection to Dropbox: "app key" and "app secret" wasn\'t found. Please, check your Dropbox settings.' ,'dropbox-backup') ) );
|
772 |
-
$res['type'] = 'local';
|
773 |
-
$send_to_dropbox = false;
|
774 |
-
}
|
775 |
-
|
776 |
-
if (defined('DISABLE_WP_CRON')) {
|
777 |
-
if (DISABLE_WP_CRON === true || DISABLE_WP_CRON == 'true') {
|
778 |
-
$res['result'] = 'error';
|
779 |
-
$res['error'] = __('Please enable cron-tasks on your website.','dropbox-backup') . '<br /><br /><a href="javascript:void(0)" onclick="showEnableCron();" >' . __('How to enable cron-tasks on my website?','dropbox-backup') . '</a><br /><br />';
|
780 |
-
$res['data'] = array();
|
781 |
-
$res['size'] = 0;
|
782 |
-
$send_to_dropbox = false;
|
783 |
-
}
|
784 |
-
}
|
785 |
-
|
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' => (int)$_POST['time'], 'types' => array('db', 'files') )), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
|
797 |
-
$res = array();
|
798 |
-
if (WPAdm_Core::$cron === false) {
|
799 |
-
$res = $backup->getResult()->toArray();
|
800 |
-
$res['md5_data'] = md5( print_r($res, 1) );
|
801 |
-
$res['name'] = $backup->name;
|
802 |
-
$res['time'] = $backup->time;
|
803 |
-
$res['type'] = 'dropbox';
|
804 |
-
$res['counts'] = count($res['data']);
|
805 |
-
}
|
806 |
-
unset($backup_local);
|
807 |
-
$folder_project = self::getNameProject();
|
808 |
-
WPAdm_Running::delCommandResultData("send-to-dropbox");
|
809 |
-
$backup = new WPAdm_Core(array('method' => "send-to-dropbox",
|
810 |
-
'params' => array('files' => isset($res['data']) ? $res['data'] : '',
|
811 |
-
'local' => true,
|
812 |
-
'is_local_backup' => ( isset($dropbox_options['is_local_backup_delete']) && $dropbox_options['is_local_backup_delete'] == 1 ? $dropbox_options['is_local_backup_delete'] : 0 ),
|
813 |
-
'access_details' => array('key' => $dropbox_options['app_key'],
|
814 |
-
'secret' => $dropbox_options['app_secret'],
|
815 |
-
'token' => $dropbox_options['auth_token_secret'],
|
816 |
-
'dir' => isset($res['name']) ? $res['name'] : '',
|
817 |
-
'folder' => $folder_project),
|
818 |
-
'time' => (int)$_POST['time'],
|
819 |
-
'is_folder_set' => isset($dropbox_options['backup_folder']) && !empty($dropbox_options['backup_folder']),
|
820 |
-
)
|
821 |
-
),
|
822 |
-
'full_backup_dropbox', WPAdm_Core::$pl_dir) ;
|
823 |
-
if (WPAdm_Core::$cron === false) {
|
824 |
-
$result_send = $backup->getResult()->toArray();
|
825 |
-
if ($result_send['result'] == 'error') {
|
826 |
-
$res = array();
|
827 |
-
$res['error'] = $result_send['error'];
|
828 |
-
$res['result'] = 'error';
|
829 |
-
@rename(WPAdm_Core::getTmpDir() . "/logs2", WPAdm_Core::getTmpDir() . "/logs_error_" . $backup_local->time);
|
830 |
-
}
|
831 |
-
WPAdm_Core::rmdir( $backup_dir . "/{$res['name']}");
|
832 |
-
} else {
|
833 |
-
set_transient('running_command', 'send-to-dropbox', HOUR_IN_SECONDS);
|
834 |
-
$res['result'] = 'work';
|
835 |
-
$res['error'] = '';
|
836 |
-
$res['data'] = array();
|
837 |
-
$res['size'] = 0;
|
838 |
-
}
|
839 |
-
}
|
840 |
-
} else {
|
841 |
-
$res['result'] = 'error';
|
842 |
-
$res['error'] = str_replace(array('%domain', '%dir-backup'), array(SITE_HOME, $backup_dir), __('Website "%domain" returned an error during file creation: Failed to create file, please check the permissions on the folder "%dir-backup".','dropbox-backup') );
|
843 |
-
$res['data'] = array();
|
844 |
-
$res['size'] = 0;
|
845 |
-
}
|
846 |
-
@session_start();
|
847 |
-
echo json_encode($res);
|
848 |
-
wp_die();
|
849 |
-
}
|
850 |
-
public static function getNameProject()
|
851 |
-
{
|
852 |
-
$folder_project = str_ireplace( array("http://", "https://"), '', home_url() );
|
853 |
-
$folder_project = str_ireplace( array( "-", '/', '.'), '_', $folder_project );
|
854 |
-
$folder_project = str_ireplace( array( 'Ä', 'ä', 'Ö', 'ö', 'ß', 'Ü', 'ü', 'å'),
|
855 |
-
array('ae', 'ae', 'oe', 'oe', 's', 'ue', 'ue', 'a'),
|
856 |
-
$folder_project );
|
857 |
-
return $folder_project;
|
858 |
-
}
|
859 |
-
|
860 |
-
public static function wpadm_show_backup()
|
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'] : '' ;
|
868 |
-
if ($dropbox_options) {
|
869 |
-
if (isset($dropbox_options['app_key']) && isset($dropbox_options['app_secret']) && isset($dropbox_options['auth_token_secret'])) {
|
870 |
-
$dropbox = new dropbox($dropbox_options['app_key'], $dropbox_options['app_secret'], $dropbox_options['auth_token_secret']);
|
871 |
-
$folder_project = self::getNameProject();
|
872 |
-
$backups = $dropbox->listing($folder_project);
|
873 |
-
$n = count($backups['items']);
|
874 |
-
$data['data'] = array();
|
875 |
-
$not_all_upload = false;
|
876 |
-
for($i = 0; $i < $n; $i++) {
|
877 |
-
if ($name_backup != $backups['items'][$i]['name']) {
|
878 |
-
$backup = $dropbox->listing($folder_project . "/" . $backups['items'][$i]['name']);
|
879 |
-
$data['data'][$i]['name'] = $backups['items'][$i]['name'];
|
880 |
-
$data['data'][$i]['size'] = (float)$backup['size'] * 1024 * 1024;
|
881 |
-
$data['data'][$i]['dt'] = parent::getDateInName($backups['items'][$i]['name']);
|
882 |
-
$data['data'][$i]['count'] = count($backup['items']);
|
883 |
-
$data['data'][$i]['type'] = 'dropbox';
|
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 || strpos($backup['items'][$j]['name'] , '.tar.gz' ) !== false ) {
|
888 |
-
if ( strpos($backup['items'][$j]['name'] , '.md5') !== false ) {
|
889 |
-
$not_all_upload = true;
|
890 |
-
}
|
891 |
-
$data['data'][$i]['files'] .= $backup['items'][$j]['name'] . ',';
|
892 |
-
}
|
893 |
-
}
|
894 |
-
$data['data'][$i]['not_all_upload'] = $not_all_upload;
|
895 |
-
}
|
896 |
-
}
|
897 |
-
}
|
898 |
-
}
|
899 |
-
if (isset($_GET['pay']) && $_GET['pay'] == 'success') { // check of GET params == string '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') { // check of GET params == string 'cancel'
|
906 |
-
parent::setError( __('Checkout was canceled','dropbox-backup') );
|
907 |
-
}
|
908 |
-
$data_local = parent::read_backups();
|
909 |
-
if (isset($data['data'])) {
|
910 |
-
$data['data'] = array_merge($data_local['data'], $data['data']);
|
911 |
-
$data['md5'] = md5( print_r( $data['data'] , 1 ) );
|
912 |
-
} else {
|
913 |
-
$data = $data_local;
|
914 |
-
}
|
915 |
-
if (file_exists(WPAdm_Core::getTmpDir() . "/pay_success")) {
|
916 |
-
$plugin_info = get_plugins("/" . parent::$plugin_name);
|
917 |
-
$plugin_version = (isset($plugin_info[parent::$plugin_name . '.php']['Version']) ? $plugin_info[parent::$plugin_name . '.php']['Version'] : '');
|
918 |
-
$data_server = parent::sendToServer(
|
919 |
-
array(
|
920 |
-
'actApi' => "proBackupCheck",
|
921 |
-
'site' => home_url(),
|
922 |
-
'email' => get_option('admin_email'),
|
923 |
-
'plugin' => parent::$plugin_name,
|
924 |
-
'key' => '',
|
925 |
-
'plugin_version' => $plugin_version
|
926 |
-
)
|
927 |
-
);
|
928 |
-
if (isset($data_server['status']) && $data_server['status'] == 'success' && isset($data_server['key'])) {
|
929 |
-
update_option(PREFIX_BACKUP_ . 'pro-key', $data_server['key']);
|
930 |
-
if (isset($data_server['url']) && !empty($data_server['url'])) {
|
931 |
-
parent::setMessage( str_replace('&s', $data_server['url'], __('The "Dropbox backup & restore PRO" version can be downloaded here <a href="&s">download</a>','dropbox-backup') ) );
|
932 |
-
}
|
933 |
-
}
|
934 |
-
}
|
935 |
-
if ( ! function_exists( 'get_plugins' ) ) {
|
936 |
-
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
937 |
-
}
|
938 |
-
$stars5 = file_exists( WPAdm_Core::getTmpDir() . "/notice-star");
|
939 |
-
$plugin_data = array_values( get_plugins('/dropbox-backup') );
|
940 |
-
$is_runnig = WPAdm_Running::is_running();
|
941 |
-
$running_backup = WPAdm_Running::getCommand( 'local_backup' );
|
942 |
-
if($running_backup === false) {
|
943 |
-
$running_backup = WPAdm_Running::getCommand( 'send-to-dropbox' );
|
944 |
-
}
|
945 |
-
if ( isset($running_backup['params']['time']) ) {
|
946 |
-
$name = get_option('siteurl');
|
947 |
-
|
948 |
-
$name_running_backup = str_replace("http://", '', $name);
|
949 |
-
$name_running_backup = str_replace("https://", '', $name_running_backup);
|
950 |
-
$name_running_backup = preg_replace("|\W|", "_", $name_running_backup);
|
951 |
-
$name_running_backup .= '-' . wpadm_class::$type . '-' . date("Y_m_d_H_i", $running_backup['params']['time']);
|
952 |
-
}
|
953 |
-
|
954 |
-
$backu_dir = DROPBOX_BACKUP_DIR_BACKUP;
|
955 |
-
if (isset($dropbox_options['backup_folder']) && !empty($dropbox_options['backup_folder'])) {
|
956 |
-
$backu_dir = $dropbox_options['backup_folder'];
|
957 |
-
}
|
958 |
-
if ( !file_exists( $backu_dir . '/local-key') ) {
|
959 |
-
WPAdm_Core::mkdir($backu_dir);
|
960 |
-
$key = md5(time() . 'wpadm-key');
|
961 |
-
file_put_contents($backu_dir . '/local-key', base64_encode( serialize( array('key' => $key, 'time-update' => time() + 3600) ) ) );
|
962 |
-
} else {
|
963 |
-
$key_values = unserialize( base64_decode( file_get_contents($backu_dir . '/local-key') ) );
|
964 |
-
if (isset($key_values['time-update']) && $key_values['time-update'] <= time() ) {
|
965 |
-
$key = md5( time() . 'wpadm-key' );
|
966 |
-
file_put_contents($backu_dir . '/local-key', base64_encode( serialize ( array( 'key' => $key, 'time-update' => time() + 3600 ) ) ) );
|
967 |
-
} else {
|
968 |
-
$key = $key_values['key'];
|
969 |
-
}
|
970 |
-
}
|
971 |
-
|
972 |
-
$show = !get_option('wpadm_pub_key') && is_super_admin();
|
973 |
-
$error = parent::getError(true);
|
974 |
-
if ( !empty( WPAdm_Core::$error ) ) {
|
975 |
-
$error .= '<br />' . WPAdm_Core::$error;
|
976 |
-
}
|
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();
|
992 |
-
}
|
993 |
-
|
994 |
-
public static function draw_menu()
|
995 |
-
{
|
996 |
-
$show = true;
|
997 |
-
$dropbox_options = self::getSettings();
|
998 |
-
|
999 |
-
if ( ( isset($dropbox_options['is_admin']) && $dropbox_options['is_admin'] == 1 ) || !isset($dropbox_options['is_admin']) ) {
|
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',
|
1014 |
-
"read",
|
1015 |
-
'wpadm_plugins',
|
1016 |
-
'wpadm_plugins',
|
1017 |
-
plugins_url('/img/wpadm-logo.png', dirname( __FILE__ )),
|
1018 |
-
$menu_position
|
1019 |
-
);
|
1020 |
-
add_submenu_page(
|
1021 |
-
'wpadm_plugins',
|
1022 |
-
"Dropbox Full Backup",
|
1023 |
-
"Dropbox Full Backup",
|
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',
|
1032 |
-
"read",
|
1033 |
-
'wpadm_wp_full_backup_dropbox',
|
1034 |
-
array('wpadm_wp_full_backup_dropbox', 'wpadm_show_backup'),
|
1035 |
-
plugins_url('/img/wpadm-logo.png', dirname( __FILE__ ) ),
|
1036 |
-
$menu_position
|
1037 |
-
);
|
1038 |
-
|
1039 |
-
add_submenu_page(
|
1040 |
-
'wpadm_wp_full_backup_dropbox',
|
1041 |
-
"WPAdm",
|
1042 |
-
"WPAdm",
|
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)) {
|
1057 |
-
ob_start();
|
1058 |
-
include_once $notice_file;
|
1059 |
-
echo ob_get_clean();
|
1060 |
-
}
|
1061 |
-
}
|
1062 |
-
}
|
1063 |
-
public static function hide_notice()
|
1064 |
-
{
|
1065 |
-
if (isset($_GET['type'])) {
|
1066 |
-
$type = sanitize_text_field( $_GET['type'] );
|
1067 |
-
switch( $type ) {
|
1068 |
-
case 'preview' :
|
1069 |
-
file_put_contents(WPAdm_Core::getTmpDir() . "/notice", 1);
|
1070 |
-
break;
|
1071 |
-
case 'star' :
|
1072 |
-
if (isset($_GET['hide']) && $_GET['hide'] == '1d') {
|
1073 |
-
file_put_contents(WPAdm_Core::getTmpDir() . "/notice-star", time() . '_w');
|
1074 |
-
} elseif ( ( isset($_GET['hide']) && $_GET['hide'] == 'week' ) || !isset($_GET['hide']) ) {
|
1075 |
-
file_put_contents(WPAdm_Core::getTmpDir() . "/notice-star", 0);
|
1076 |
-
}
|
1077 |
-
break;
|
1078 |
-
}
|
1079 |
-
}
|
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 |
-
|
1116 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
methods/class-wpadm-method-backup-delete.php
CHANGED
@@ -1,39 +1,28 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
if (!is_dir($backups_dir)) {
|
29 |
-
$this->result->setResult = WPAdm_result::WPADM_RESULT_SUCCESS;
|
30 |
-
} else {
|
31 |
-
$this->result->setResult = WPAdm_result::WPADM_RESULT_ERROR;
|
32 |
-
$this->result->setError('Failed to remove backup');
|
33 |
-
}
|
34 |
-
}
|
35 |
-
}
|
36 |
-
return $this->result;
|
37 |
-
}
|
38 |
-
}
|
39 |
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Delete backup
|
4 |
+
* Class WPAdm_Method_Backup_Delete
|
5 |
+
*/
|
6 |
+
if (!class_exists('WPAdm_Method_Backup_Delete')) {
|
7 |
+
class WPAdm_Method_Backup_Delete extends WPAdm_Method_Class {
|
8 |
+
public function getResult()
|
9 |
+
{
|
10 |
+
$backups_dir = realpath(ABSPATH . '/wpadm_backups/' . $this->params['name']);
|
11 |
+
if(strpos($backups_dir, DIRECTORY_SEPARATOR . 'wpadm_backups' . DIRECTORY_SEPARATOR) === false || !is_dir($backups_dir)) {
|
12 |
+
$this->result->setResult = WPAdm_result::WPADM_RESULT_ERROR;
|
13 |
+
$this->result->setError('Wrong name backup');
|
14 |
+
} else {
|
15 |
+
if (is_dir($backups_dir)) {
|
16 |
+
WPAdm_Core::rmdir($backups_dir);
|
17 |
+
if (!is_dir($backups_dir)) {
|
18 |
+
$this->result->setResult = WPAdm_result::WPADM_RESULT_SUCCESS;
|
19 |
+
} else {
|
20 |
+
$this->result->setResult = WPAdm_result::WPADM_RESULT_ERROR;
|
21 |
+
$this->result->setError('Failed to remove backup');
|
22 |
+
}
|
23 |
+
}
|
24 |
+
}
|
25 |
+
return $this->result;
|
26 |
+
}
|
27 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
}
|
methods/class-wpadm-method-backup-list.php
CHANGED
@@ -1,55 +1,45 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
$
|
14 |
-
$
|
15 |
-
|
16 |
-
|
17 |
-
$
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
$
|
27 |
-
$
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
'
|
32 |
-
'
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
}
|
46 |
-
|
47 |
-
}
|
48 |
-
}
|
49 |
-
$this->result->setData($backups);
|
50 |
-
$this->result->setResult(WPAdm_result::WPADM_RESULT_SUCCESS);
|
51 |
-
return $this->result;
|
52 |
-
}
|
53 |
-
|
54 |
-
}
|
55 |
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Return a list of backups
|
4 |
+
* Class WPAdm_Method_Exec
|
5 |
+
*/
|
6 |
+
if (!class_exists('WPAdm_Method_Backup_List')) {
|
7 |
+
class WPAdm_Method_Backup_List extends WPAdm_Method_Class {
|
8 |
+
public function getResult()
|
9 |
+
{
|
10 |
+
$backups_dir = ABSPATH . '/wpadm_backups/';
|
11 |
+
$dirs = glob($backups_dir . '*');
|
12 |
+
|
13 |
+
$backups = array();
|
14 |
+
foreach($dirs as $dir) {
|
15 |
+
if (preg_match("|(.*)\-(.*)\-(.*)|", $dir, $mm)) {
|
16 |
+
$tmp = explode('/', $dir);
|
17 |
+
$name = array_pop($tmp);
|
18 |
+
list($y,$m,$d, $h,$i) = explode('_', $mm[3]);
|
19 |
+
$dt = "$y-$m-$d $h:$i";
|
20 |
+
$backup = array(
|
21 |
+
'name' => $name,
|
22 |
+
'type' => $mm[2],
|
23 |
+
'dt' => $dt,
|
24 |
+
);
|
25 |
+
$files = glob($dir . '/*.zip');
|
26 |
+
$size = 0;
|
27 |
+
foreach($files as $k=>$v) {
|
28 |
+
$size += (int)filesize($v);
|
29 |
+
$files[$k] = str_replace(ABSPATH, '', $v);
|
30 |
+
}
|
31 |
+
$backup['files'] = $files;
|
32 |
+
$backup['size'] = $size;
|
33 |
+
if ($size > 0) {
|
34 |
+
$backups[] = $backup;
|
35 |
+
}
|
36 |
+
|
37 |
+
}
|
38 |
+
}
|
39 |
+
$this->result->setData($backups);
|
40 |
+
$this->result->setResult(WPAdm_result::WPADM_RESULT_SUCCESS);
|
41 |
+
return $this->result;
|
42 |
+
}
|
43 |
+
|
44 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
}
|
methods/class-wpadm-method-backup.php
CHANGED
@@ -1,506 +1,451 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
$name = str_replace("
|
61 |
-
$name =
|
62 |
-
$name =
|
63 |
-
|
64 |
-
$name
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
$this->dir
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
if (
|
123 |
-
WPAdm_Core::log(
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
}
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
$
|
163 |
-
$
|
164 |
-
|
165 |
-
|
166 |
-
$
|
167 |
-
$
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
$
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
$
|
184 |
-
}
|
185 |
-
|
186 |
-
|
187 |
-
$
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
$
|
226 |
-
}
|
227 |
-
|
228 |
-
$
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
WPAdm_Core::
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
$
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
}
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
}
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
);
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
WPAdm_Core::log('Skip of File ' . $ff);
|
452 |
-
}
|
453 |
-
}
|
454 |
-
} else {
|
455 |
-
$file = $directory . "/" . $file;
|
456 |
-
if (!is_dir($file)) {
|
457 |
-
$ff = preg_replace("/\/\//si", "/", $file);
|
458 |
-
$f = str_replace(ABSPATH . '/', '', $ff);
|
459 |
-
// skip folders
|
460 |
-
if (!in_array($f, $this->params['minus-path'])) {
|
461 |
-
$array_items[] = $ff;
|
462 |
-
} else {
|
463 |
-
WPAdm_Core::log('Skip of Folder ' . $ff);
|
464 |
-
}
|
465 |
-
}
|
466 |
-
}
|
467 |
-
}
|
468 |
-
}
|
469 |
-
closedir($handle);
|
470 |
-
}
|
471 |
-
return $array_items;
|
472 |
-
}
|
473 |
-
|
474 |
-
|
475 |
-
/*
|
476 |
-
* get access to mysql from params WP
|
477 |
-
* return Array()
|
478 |
-
*/
|
479 |
-
private function getWpMysqlParams()
|
480 |
-
{
|
481 |
-
$db_params = array(
|
482 |
-
'password' => 'DB_PASSWORD',
|
483 |
-
'db' => 'DB_NAME',
|
484 |
-
'user' => 'DB_USER',
|
485 |
-
'host' => 'DB_HOST',
|
486 |
-
);
|
487 |
-
|
488 |
-
$r = "/define\('(.*)', '(.*)'\)/";
|
489 |
-
preg_match_all($r, file_get_contents(ABSPATH . "wp-config.php"), $m);
|
490 |
-
$params = array_combine($m[1], $m[2]);
|
491 |
-
foreach($db_params as $k=>$p) {
|
492 |
-
$db_params[$k] = $params[$p];
|
493 |
-
}
|
494 |
-
return $db_params;
|
495 |
-
}
|
496 |
-
|
497 |
-
|
498 |
-
private function init(array $conf) {
|
499 |
-
//todo: norm
|
500 |
-
$this->id = $conf['id'];
|
501 |
-
$this->stime = $conf['stime'];
|
502 |
-
//$this->queue = new WPAdm_Queue($this->id);
|
503 |
-
$this->type = $conf['type'];
|
504 |
-
}
|
505 |
-
}
|
506 |
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Бэкап сайта
|
4 |
+
* Class WPadm_Method_Backup
|
5 |
+
*/
|
6 |
+
if (!class_exists('WPadm_Method_Backup')) {
|
7 |
+
class WPadm_Method_Backup extends WPAdm_Method_Class {
|
8 |
+
/**
|
9 |
+
* Уникальный идентификатор текущего объекта
|
10 |
+
* @var String
|
11 |
+
*/
|
12 |
+
private $id;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Unixtimestamp, когда был запущен метод
|
16 |
+
* @var Int
|
17 |
+
*/
|
18 |
+
private $stime;
|
19 |
+
|
20 |
+
/**
|
21 |
+
* @var WPAdm_Queue
|
22 |
+
*/
|
23 |
+
private $queue;
|
24 |
+
|
25 |
+
/**
|
26 |
+
* @var string
|
27 |
+
*/
|
28 |
+
private $dir;
|
29 |
+
|
30 |
+
/**
|
31 |
+
* @var string
|
32 |
+
*/
|
33 |
+
private $tmp_dir;
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Тип бэкапа
|
37 |
+
* @var string [full|db]
|
38 |
+
*/
|
39 |
+
private $type = 'full';
|
40 |
+
|
41 |
+
private $name = '';
|
42 |
+
|
43 |
+
public function __construct($params) {
|
44 |
+
parent::__construct($params);
|
45 |
+
$this->init(
|
46 |
+
array(
|
47 |
+
'id' => uniqid('wpadm_method_backup__'),
|
48 |
+
'stime' => time(),
|
49 |
+
'type' => $params['type'],
|
50 |
+
)
|
51 |
+
);
|
52 |
+
|
53 |
+
|
54 |
+
//папка для временных файлов
|
55 |
+
// $this->tmp_dir = WPAdm_Core::getTmpDir() . '/' . $this->id;
|
56 |
+
// WPAdm_Core::mkdir($this->tmp_dir);
|
57 |
+
|
58 |
+
$name = get_option('siteurl');
|
59 |
+
|
60 |
+
$name = str_replace("http://", '', $name);
|
61 |
+
$name = str_replace("https://", '', $name);
|
62 |
+
$name = preg_replace("|\W|", "_", $name);
|
63 |
+
$name .= '-' . $this->type . '-' . date("Y_m_d_H_i");
|
64 |
+
$this->name = $name;
|
65 |
+
|
66 |
+
// папка для бэкапа
|
67 |
+
$this->dir = ABSPATH . '/wpadm_backups/' . $this->name;
|
68 |
+
WPAdm_Core::mkdir(ABSPATH . '/wpadm_backups/');
|
69 |
+
WPAdm_Core::mkdir($this->dir);
|
70 |
+
}
|
71 |
+
|
72 |
+
public function getResult()
|
73 |
+
{
|
74 |
+
$errors = array();
|
75 |
+
|
76 |
+
$this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
|
77 |
+
$this->result->setError('');
|
78 |
+
|
79 |
+
|
80 |
+
#ОТЛАДКА, нужно удалить
|
81 |
+
//todo: удалить
|
82 |
+
unlink(dirname(__FILE__) . '/../tmp/log.log');
|
83 |
+
#конец отладки
|
84 |
+
|
85 |
+
WPAdm_Core::log('Начинаем бэкап');
|
86 |
+
|
87 |
+
# СОЗДАДИМ ДАМП БД
|
88 |
+
WPAdm_Core::log('Начинаем создание дампа БД');
|
89 |
+
// добавим в очередь создание бэкапа БД и выполним
|
90 |
+
WPAdm_Core::mkdir(ABSPATH . '/wpadm_backup');
|
91 |
+
$mysql_dump_file = ABSPATH . '/wpadm_backup/mysqldump.sql';
|
92 |
+
if (file_exists($mysql_dump_file)) {
|
93 |
+
unlink($mysql_dump_file);
|
94 |
+
}
|
95 |
+
$wp_mysql_params = $this->getWpMysqlParams();
|
96 |
+
|
97 |
+
if (isset($this->params['optimize']) && ($this->params['optimize']==1)) {
|
98 |
+
WPAdm_Core::log('Оптимизцация таблиц БД');
|
99 |
+
$commandContext = new WPAdm_Command_Context();
|
100 |
+
$commandContext ->addParam('command','mysqloptimize')
|
101 |
+
->addParam('host', $wp_mysql_params['host'])
|
102 |
+
->addParam('db', $wp_mysql_params['db'])
|
103 |
+
->addParam('user', $wp_mysql_params['user'])
|
104 |
+
->addParam('password', $wp_mysql_params['password']);
|
105 |
+
$this->queue->clear()
|
106 |
+
->add($commandContext);
|
107 |
+
unset($commandContext);
|
108 |
+
}
|
109 |
+
|
110 |
+
$commandContext = new WPAdm_Command_Context();
|
111 |
+
$commandContext ->addParam('command','mysqldump')
|
112 |
+
->addParam('host', $wp_mysql_params['host'])
|
113 |
+
->addParam('db', $wp_mysql_params['db'])
|
114 |
+
->addParam('user', $wp_mysql_params['user'])
|
115 |
+
->addParam('password', $wp_mysql_params['password'])
|
116 |
+
->addParam('tables', '')
|
117 |
+
->addParam('to_file', $mysql_dump_file);
|
118 |
+
$res = $this->queue->add($commandContext)
|
119 |
+
->save()
|
120 |
+
->execute();
|
121 |
+
|
122 |
+
if (!$res) {
|
123 |
+
WPAdm_Core::log('Дамп БД не создан('.$this->queue->getError().')');
|
124 |
+
$errors[] = 'MySQL error: '.$this->queue->getError();
|
125 |
+
} elseif (0 == (int)filesize($mysql_dump_file)) {
|
126 |
+
$errors[] = 'MySQL error: empty dump-file';
|
127 |
+
WPAdm_Core::log('Дамп БД не создан(пустой файл)');
|
128 |
+
} else {
|
129 |
+
WPAdm_Core::log('Дамп БД создан('.filesize($mysql_dump_file).'b):' . $mysql_dump_file);
|
130 |
+
}
|
131 |
+
unset($commandContext);
|
132 |
+
|
133 |
+
|
134 |
+
#ЗАРХИВИРУЕМ ФАЙЛЫ
|
135 |
+
WPAdm_Core::log('Начинаем подготовку списка файлов');
|
136 |
+
// список файлов для архивации
|
137 |
+
if ($this->type == 'full') {
|
138 |
+
$files = $this->createListFilesForArchive();
|
139 |
+
} else {
|
140 |
+
$files = array();
|
141 |
+
}
|
142 |
+
if (file_exists($mysql_dump_file) && filesize($mysql_dump_file) > 0) {
|
143 |
+
$files[] = $mysql_dump_file;
|
144 |
+
}
|
145 |
+
|
146 |
+
if (empty($files)) {
|
147 |
+
$errors[] = 'Empty list files';
|
148 |
+
}
|
149 |
+
|
150 |
+
// разабьем список файлов на списки по 170кбайт,
|
151 |
+
// чтобы разбить одну большую задачу на маленькие
|
152 |
+
$files2 = array();
|
153 |
+
$files2[0] = array();
|
154 |
+
$i = 0;
|
155 |
+
$size = 0;
|
156 |
+
foreach($files as $f) {
|
157 |
+
if ($size > 170000) {//~170kbyte
|
158 |
+
$i ++;
|
159 |
+
$size = 0;
|
160 |
+
$files2[$i] = array();
|
161 |
+
}
|
162 |
+
$f_size =(int)filesize($f);
|
163 |
+
if ($f_size == 0 || $f_size > 1000000) {
|
164 |
+
WPAdm_Core::log('file '. $f .' size ' . $f_size);
|
165 |
+
}
|
166 |
+
$size += $f_size;
|
167 |
+
$files2[$i][] = $f;
|
168 |
+
}
|
169 |
+
|
170 |
+
WPAdm_Core::log('Список файлов подготовлен');
|
171 |
+
// подготовим очередь к выполнению
|
172 |
+
$this->queue->clear();
|
173 |
+
|
174 |
+
foreach($files2 as $files) {
|
175 |
+
$commandContext = new WPAdm_Command_Context();
|
176 |
+
$commandContext ->addParam('command','archive')
|
177 |
+
->addParam('files', $files)
|
178 |
+
->addParam('to_file', $this->dir . '/'.$this->name)
|
179 |
+
->addParam('max_file_size', 900000)
|
180 |
+
->addParam('remove_path', ABSPATH);
|
181 |
+
|
182 |
+
$this->queue->add($commandContext);
|
183 |
+
unset($commandContext);
|
184 |
+
}
|
185 |
+
WPAdm_Core::log('Начинаем архивацию файлов');
|
186 |
+
// сохраним и выполним
|
187 |
+
$this->queue->save()
|
188 |
+
->execute();
|
189 |
+
WPAdm_Core::log('Закочили архивацию файлов');
|
190 |
+
|
191 |
+
$files = glob($this->dir . '/'.$this->name . '*');
|
192 |
+
$urls = array();
|
193 |
+
foreach($files as $file) {
|
194 |
+
$urls[] = str_replace(ABSPATH, '', $file);
|
195 |
+
}
|
196 |
+
$this->result->setData($urls);
|
197 |
+
|
198 |
+
|
199 |
+
# КОПИРОВАНИЕ ФАЙЛОВ НА FTP
|
200 |
+
if (isset($this->params['storage']) && $this->params['storage']['type'] == 'ftp') {
|
201 |
+
WPAdm_Core::log('Начинаем копирование файлов на FTP');
|
202 |
+
$this->queue->clear();
|
203 |
+
$files = glob($this->dir . '/'.$this->name . '*');
|
204 |
+
//$this->getResult()->setData($files);
|
205 |
+
$ad = $this->params['storage']['access_details'];
|
206 |
+
$dir = (isset($ad['dir'])) ? $ad['dir'] : '/';
|
207 |
+
$dir = trim($dir, '/') . '/' . $this->name;
|
208 |
+
foreach($files as $file) {
|
209 |
+
$commandContext = new WPAdm_Command_Context();
|
210 |
+
$commandContext ->addParam('command','send_to_ftp')
|
211 |
+
->addParam('file', $file)
|
212 |
+
->addParam('host', $ad['host'])
|
213 |
+
->addParam('port', (isset($ad['port']))? $ad['port'] : 21)
|
214 |
+
->addParam('user', $ad['user'])
|
215 |
+
->addParam('password', $ad['password'])
|
216 |
+
->addParam('dir', $dir)
|
217 |
+
->addParam('http_host', isset($ad['http_host']) ? $ad['http_host'] : '');
|
218 |
+
$this->queue->add($commandContext);
|
219 |
+
unset($commandContext);
|
220 |
+
}
|
221 |
+
$res = $this->queue->save()
|
222 |
+
->execute();
|
223 |
+
if (!$res) {
|
224 |
+
WPAdm_Core::log('FTP: ' . $this->queue->getError());
|
225 |
+
$errors[] = 'FTP: '.$this->queue->getError();
|
226 |
+
}
|
227 |
+
WPAdm_Core::log('Закончили копирование файлов на FTP');
|
228 |
+
if (isset($this->params['storage']['remove_from_server']) && $this->params['storage']['remove_from_server'] == 1 ) {
|
229 |
+
// удаляем файлы на сервере
|
230 |
+
WPAdm_Core::log('Удаляем бэкап на сервере');
|
231 |
+
WPAdm_Core::rmdir($this->dir);
|
232 |
+
}
|
233 |
+
}
|
234 |
+
|
235 |
+
#УДАЛЕНИЕ TMP-ФАЙЛОВ
|
236 |
+
//todo: УДАЛЕНИЕ TMP-ФАЙЛОВ
|
237 |
+
WPAdm_Core::rmdir(ABSPATH.'/wpadm_backup');
|
238 |
+
|
239 |
+
#УДАЛЕНИЕ СТАРЫХ АРХИВОВ(те что не влазят в лимит)
|
240 |
+
//todo: не правмльно удаляет, если есть ооба типа бэкапа
|
241 |
+
WPAdm_Core::log('Начинаем удалять старые архивы');
|
242 |
+
if ($this->params['limit'] != 0) {
|
243 |
+
$files = glob(ABSPATH . '/wpadm_backups/*');
|
244 |
+
if (count($files) > $this->params['limit']) {
|
245 |
+
$files2 = array();
|
246 |
+
foreach($files as $f) {
|
247 |
+
$fa = explode('-', $f);
|
248 |
+
if (count($fa) != 3) {
|
249 |
+
continue;
|
250 |
+
}
|
251 |
+
$files2[$fa[2]] = $f;
|
252 |
+
|
253 |
+
}
|
254 |
+
ksort($files2);
|
255 |
+
$d = count($files2) - $this->params['limit'];
|
256 |
+
$del = array_slice($files2, 0, $d);
|
257 |
+
foreach($del as $d) {
|
258 |
+
WPAdm_Core::rmdir($d);
|
259 |
+
}
|
260 |
+
}
|
261 |
+
}
|
262 |
+
WPAdm_Core::log('Закончили удалять старые архивы');
|
263 |
+
|
264 |
+
WPAdm_Core::log('Бэкап завершен');
|
265 |
+
|
266 |
+
if (!empty($errors)) {
|
267 |
+
$this->result->setError(implode("\n", $errors));
|
268 |
+
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
269 |
+
}
|
270 |
+
|
271 |
+
return $this->result;
|
272 |
+
|
273 |
+
|
274 |
+
}
|
275 |
+
|
276 |
+
|
277 |
+
|
278 |
+
public function createListFilesForArchive() {
|
279 |
+
$folders = array();
|
280 |
+
$files = array();
|
281 |
+
|
282 |
+
$files = array_merge(
|
283 |
+
$files,
|
284 |
+
array(
|
285 |
+
ABSPATH .'/.htaccess',
|
286 |
+
ABSPATH .'/index.php',
|
287 |
+
ABSPATH .'/license.txt',
|
288 |
+
ABSPATH .'/readme.html',
|
289 |
+
ABSPATH .'/wp-activate.php',
|
290 |
+
ABSPATH .'/wp-blog-header.php',
|
291 |
+
ABSPATH .'/wp-comments-post.php',
|
292 |
+
ABSPATH .'/wp-config.php',
|
293 |
+
ABSPATH .'/wp-config-sample.php',
|
294 |
+
ABSPATH .'/wp-cron.php',
|
295 |
+
ABSPATH .'/wp-links-opml.php',
|
296 |
+
ABSPATH .'/wp-load.php',
|
297 |
+
ABSPATH .'/wp-login.php',
|
298 |
+
ABSPATH .'/wp-mail.php',
|
299 |
+
ABSPATH .'/wp-settings.php',
|
300 |
+
ABSPATH .'/wp-signup.php',
|
301 |
+
ABSPATH .'/wp-trackback.php',
|
302 |
+
ABSPATH .'/xmlrpc.php',
|
303 |
+
)
|
304 |
+
);
|
305 |
+
|
306 |
+
if (!empty($this->params['minus-path'])) {
|
307 |
+
foreach($files as $k=>$v) {
|
308 |
+
$v = str_replace(ABSPATH .'/' , '', $v);
|
309 |
+
if (in_array($v, $this->params['minus-path'])) {
|
310 |
+
unset($files[$k]);
|
311 |
+
WPAdm_Core::log('Пропускаем файл ' . $v);
|
312 |
+
}
|
313 |
+
}
|
314 |
+
}
|
315 |
+
|
316 |
+
$folders = array_merge(
|
317 |
+
$folders,
|
318 |
+
array(
|
319 |
+
ABSPATH .'/wp-admin',
|
320 |
+
ABSPATH .'/wp-content',
|
321 |
+
ABSPATH .'/wp-includes',
|
322 |
+
)
|
323 |
+
);
|
324 |
+
|
325 |
+
foreach($this->params['plus-path'] as $p) {
|
326 |
+
if (empty($p)) {
|
327 |
+
continue;
|
328 |
+
}
|
329 |
+
$p = ABSPATH .'/' . $p;
|
330 |
+
if (file_exists($p)) {
|
331 |
+
if (is_dir($p)) {
|
332 |
+
$folders[] = $p;
|
333 |
+
} else{
|
334 |
+
$files[] = $p;
|
335 |
+
}
|
336 |
+
}
|
337 |
+
}
|
338 |
+
|
339 |
+
$folders = array_unique($folders);
|
340 |
+
$files = array_unique($files);
|
341 |
+
|
342 |
+
foreach($folders as $folder) {
|
343 |
+
if (!is_dir($folder)) {
|
344 |
+
continue;
|
345 |
+
}
|
346 |
+
$files = array_merge($files, $this->directoryToArray($folder, true));
|
347 |
+
}
|
348 |
+
return $files;
|
349 |
+
}
|
350 |
+
|
351 |
+
|
352 |
+
private function directoryToArray($directory, $recursive) {
|
353 |
+
$array_items = array();
|
354 |
+
|
355 |
+
$d = str_replace(ABSPATH . '/', '', $directory);
|
356 |
+
// пропускаем ненужные директории
|
357 |
+
|
358 |
+
if (
|
359 |
+
in_array($d, $this->params['minus-path'])
|
360 |
+
) {
|
361 |
+
WPAdm_Core::log('Пропускаем папку ' . $directory);
|
362 |
+
return array();
|
363 |
+
}
|
364 |
+
|
365 |
+
$d = str_replace('\\', '/', $d);
|
366 |
+
$tmp = explode('/', $d);
|
367 |
+
$d1 = mb_strtolower($tmp[0]);
|
368 |
+
unset($tmp[0]);
|
369 |
+
$d2 = mb_strtolower(implode('/', $tmp));
|
370 |
+
// if (strpos($d1, 'cache') !== false || ($d1 == 'wp-includes' && strpos($d2, 'cache') !== false)) {
|
371 |
+
// if (($d1 == 'wp-includes' && strpos($d2, 'cache') !== false)
|
372 |
+
// || ($d1 == 'wp-content' || !in_array($tmp[0], array('plugins', 'themes')))
|
373 |
+
if (strpos($d2, 'cache') !== false
|
374 |
+
&& !in_array($tmp[0], array('plugins', 'themes'))
|
375 |
+
) {
|
376 |
+
WPAdm_Core::log('Пропускаем папку(cache) ' . $directory);
|
377 |
+
return array();
|
378 |
+
}
|
379 |
+
|
380 |
+
if ($handle = opendir($directory)) {
|
381 |
+
while (false !== ($file = readdir($handle))) {
|
382 |
+
if ($file != "." && $file != "..") {
|
383 |
+
if (is_dir($directory. "/" . $file)) {
|
384 |
+
if($recursive) {
|
385 |
+
$array_items = array_merge($array_items, $this->directoryToArray($directory. "/" . $file, $recursive));
|
386 |
+
}
|
387 |
+
|
388 |
+
$file = $directory . "/" . $file;
|
389 |
+
if (!is_dir($file)) {
|
390 |
+
$ff = preg_replace("/\/\//si", "/", $file);
|
391 |
+
$f = str_replace(ABSPATH . '/', '', $ff);
|
392 |
+
// пропускаем ненужные директории
|
393 |
+
if (!in_array($f, $this->params['minus-path'])) {
|
394 |
+
$array_items[] = $ff;
|
395 |
+
} else {
|
396 |
+
WPAdm_Core::log('Пропускаем файл ' . $ff);
|
397 |
+
}
|
398 |
+
}
|
399 |
+
} else {
|
400 |
+
$file = $directory . "/" . $file;
|
401 |
+
if (!is_dir($file)) {
|
402 |
+
$ff = preg_replace("/\/\//si", "/", $file);
|
403 |
+
$f = str_replace(ABSPATH . '/', '', $ff);
|
404 |
+
// пропускаем ненужные директории
|
405 |
+
if (!in_array($f, $this->params['minus-path'])) {
|
406 |
+
$array_items[] = $ff;
|
407 |
+
} else {
|
408 |
+
WPAdm_Core::log('Пропускаем файл ' . $ff);
|
409 |
+
}
|
410 |
+
}
|
411 |
+
}
|
412 |
+
}
|
413 |
+
}
|
414 |
+
closedir($handle);
|
415 |
+
}
|
416 |
+
return $array_items;
|
417 |
+
}
|
418 |
+
|
419 |
+
|
420 |
+
/*
|
421 |
+
* Берем реквизиты доступа к MySQL из параметров WP
|
422 |
+
* return Array()
|
423 |
+
*/
|
424 |
+
private function getWpMysqlParams()
|
425 |
+
{
|
426 |
+
$db_params = array(
|
427 |
+
'password' => 'DB_PASSWORD',
|
428 |
+
'db' => 'DB_NAME',
|
429 |
+
'user' => 'DB_USER',
|
430 |
+
'host' => 'DB_HOST',
|
431 |
+
);
|
432 |
+
|
433 |
+
$r = "/define\('(.*)', '(.*)'\)/";
|
434 |
+
preg_match_all($r, file_get_contents(ABSPATH . "wp-config.php"), $m);
|
435 |
+
$params = array_combine($m[1], $m[2]);
|
436 |
+
foreach($db_params as $k=>$p) {
|
437 |
+
$db_params[$k] = $params[$p];
|
438 |
+
}
|
439 |
+
return $db_params;
|
440 |
+
}
|
441 |
+
|
442 |
+
|
443 |
+
private function init(array $conf) {
|
444 |
+
//todo: нормализация
|
445 |
+
$this->id = $conf['id'];
|
446 |
+
$this->stime = $conf['stime'];
|
447 |
+
$this->queue = new WPAdm_Queue($this->id);
|
448 |
+
$this->type = $conf['type'];
|
449 |
+
}
|
450 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
451 |
}
|
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
|
@@ -51,34 +48,20 @@ if (!class_exists('WPadm_Method_Full_Backup_Dropbox')) {
|
|
51 |
'stime' => time(),
|
52 |
)
|
53 |
);
|
54 |
-
set_time_limit(0);
|
55 |
|
56 |
-
|
57 |
-
require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-process.php';
|
58 |
-
}
|
59 |
$name = get_option('siteurl');
|
60 |
|
61 |
$name = str_replace("http://", '', $name);
|
62 |
$name = str_replace("https://", '', $name);
|
63 |
-
$name = str_ireplace( array( 'Ä', 'ä', 'Ö', 'ö', 'ß', 'Ü', 'ü', 'å'),
|
64 |
-
array('ae', 'ae', 'oe', 'oe', 's', 'ue', 'ue', 'a'),
|
65 |
-
$name );
|
66 |
$name = preg_replace("|\W|", "_", $name);
|
67 |
$name .= '-' . $this->type . '-' . date("Y_m_d_H_i");
|
68 |
$this->name = $name;
|
69 |
|
70 |
// folder for backup
|
71 |
-
$this->dir =
|
72 |
-
|
73 |
-
|
74 |
-
$this->result->setError($error);
|
75 |
-
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
76 |
-
}
|
77 |
-
$error = WPAdm_Core::mkdir($this->dir);
|
78 |
-
if (!empty($error)) {
|
79 |
-
$this->result->setError($error);
|
80 |
-
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
81 |
-
}
|
82 |
}
|
83 |
|
84 |
public function getResult()
|
@@ -88,101 +71,65 @@ if (!class_exists('WPadm_Method_Full_Backup_Dropbox')) {
|
|
88 |
$this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
|
89 |
$this->result->setError('');
|
90 |
|
91 |
-
WPAdm_Core::log(
|
92 |
|
93 |
# create db dump
|
94 |
-
WPAdm_Core::log(
|
95 |
-
|
96 |
-
|
97 |
-
$this->result->setError($error);
|
98 |
-
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
99 |
-
return $this->result;
|
100 |
-
}
|
101 |
-
$mysql_dump_file = DROPBOX_BACKUP_DIR_BACKUP . '/mysqldump.sql';
|
102 |
if (file_exists($mysql_dump_file)) {
|
103 |
unlink($mysql_dump_file);
|
104 |
}
|
105 |
$wp_mysql_params = $this->getWpMysqlParams();
|
106 |
|
107 |
-
if ( isset($this->params['repair']) && ( $this->params['repair'] == 1 ) ) {
|
108 |
-
if ( WPAdm_Running::is_stop() ) {
|
109 |
-
if (!class_exists('WPAdm_Mysqldump')) {
|
110 |
-
require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
|
111 |
-
}
|
112 |
-
|
113 |
-
$mysql = new WPAdm_Mysqldump();
|
114 |
-
$mysql->host = $wp_mysql_params['host'];
|
115 |
-
$mysql->user = $wp_mysql_params['user'];
|
116 |
-
$mysql->password = $wp_mysql_params['password'];
|
117 |
-
try {
|
118 |
-
$mysql->repair($wp_mysql_params['db']);
|
119 |
-
unset($mysql);
|
120 |
-
} catch (Exception $e) {
|
121 |
-
$this->result->setError( $e->getMessage() );
|
122 |
-
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
123 |
-
return $this->result;
|
124 |
-
}
|
125 |
-
unset($mysql);
|
126 |
-
}
|
127 |
-
}
|
128 |
-
|
129 |
if (isset($this->params['optimize']) && ($this->params['optimize']==1)) {
|
130 |
-
WPAdm_Core::log(
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
$
|
135 |
-
|
136 |
-
|
137 |
-
$
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
try {
|
157 |
-
$mysql->mysqldump($wp_mysql_params['db'], $mysql_dump_file);
|
158 |
-
} catch (Exception $e) {
|
159 |
-
$this->result->setError( $e->getMessage() );
|
160 |
-
$this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
|
161 |
-
return $this->result;
|
162 |
-
}
|
163 |
-
unset($mysql);
|
164 |
-
|
165 |
-
if (0 == (int)filesize($mysql_dump_file)) {
|
166 |
-
$log = str_replace(array('%domain', '%dir'), array(SITE_HOME, DROPBOX_BACKUP_DIR_BACKUP), __('Website "%domain" returned an error during database dump creation: Database-Dump file is emplty. To solve this problem, please check permissions to folder: "%dir".','dropbox-backup') );
|
167 |
-
$errors[] = $log;
|
168 |
WPAdm_Core::log($log);
|
169 |
-
$
|
170 |
-
|
171 |
-
|
|
|
172 |
} else {
|
173 |
$size_dump = round( (filesize($mysql_dump_file) / 1024 / 1024) , 2);
|
174 |
-
$log = str_replace("%
|
175 |
WPAdm_Core::log($log . $mysql_dump_file);
|
176 |
}
|
|
|
|
|
177 |
|
178 |
-
|
|
|
179 |
$files = $this->createListFilesForArchive();
|
180 |
if (file_exists($mysql_dump_file) && filesize($mysql_dump_file) > 0) {
|
181 |
$files[] = $mysql_dump_file;
|
182 |
}
|
183 |
|
184 |
if (empty($files)) {
|
185 |
-
$errors[] =
|
186 |
}
|
187 |
|
188 |
// split the file list by 170kbayt lists, To break one big task into smaller
|
@@ -204,47 +151,25 @@ if (!class_exists('WPadm_Method_Full_Backup_Dropbox')) {
|
|
204 |
$files2[$i][] = $f;
|
205 |
}
|
206 |
|
207 |
-
WPAdm_Core::log(
|
208 |
-
WPAdm_Core::log( __('Backup of Files was started','dropbox-backup') );
|
209 |
-
//$this->queue->clear();
|
210 |
-
if (!class_exists('WPAdm_Archive')) {
|
211 |
-
require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-archive.php';
|
212 |
-
}
|
213 |
-
$to_file = $this->dir . '/' . $this->name;
|
214 |
-
foreach($files2 as $files) {
|
215 |
-
$af = $this->getArchiveName($to_file);
|
216 |
-
$archive = new WPAdm_Archive($af, $to_file . '.md5');
|
217 |
-
$archive->setRemovePath(ABSPATH);
|
218 |
-
if ( !file_exists( $af ) ) {
|
219 |
-
WPAdm_Core::log(__('Create part ','dropbox-backup') . basename( $af ) );
|
220 |
-
}
|
221 |
|
222 |
-
|
223 |
-
$af = $this->getNextArchiveName($to_file);
|
224 |
-
unset($archive);
|
225 |
-
if ( !file_exists( $af ) ) {
|
226 |
-
WPAdm_Core::log(__('Create part ','dropbox-backup') . basename( $af ) );
|
227 |
-
}
|
228 |
-
$archive = new WPAdm_Archive($af, $to_file . '.md5');
|
229 |
-
$archive->setRemovePath( ABSPATH );
|
230 |
-
}
|
231 |
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
if ($res) {
|
240 |
|
241 |
-
|
242 |
-
|
243 |
-
$this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
|
244 |
-
return $this->result;
|
245 |
-
}
|
246 |
}
|
247 |
-
WPAdm_Core::log(
|
|
|
|
|
|
|
248 |
|
249 |
$files = glob($this->dir . '/'.$this->name . '*');
|
250 |
$urls = array();
|
@@ -258,72 +183,156 @@ if (!class_exists('WPadm_Method_Full_Backup_Dropbox')) {
|
|
258 |
|
259 |
|
260 |
$remove_from_server = 0;
|
261 |
-
if (isset($this->params['
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
$files = glob($this->dir . '/' . $this->name . '*');
|
263 |
-
require_once WPAdm_Core::getPluginDir() . '/modules/dropbox.class.php';
|
264 |
$files = array_merge_recursive(array($mysql_dump_file), $files);
|
265 |
-
WPAdm_Core::log(
|
266 |
-
$n = count($files);
|
267 |
-
$
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
276 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
277 |
for($i = 0; $i <$n; $i++) {
|
278 |
-
$
|
279 |
-
$
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
}
|
294 |
}
|
295 |
|
296 |
#Removing TMP-files
|
297 |
-
WPAdm_Core::rmdir(
|
298 |
|
299 |
#Removind old backups(if limit the number of stored backups)
|
300 |
-
WPAdm_Core::log(
|
301 |
if ($this->params['limit'] != 0) {
|
302 |
-
|
303 |
-
|
304 |
-
$files2 = array();
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
continue;
|
310 |
-
}
|
311 |
-
$files2[$fa[2]] = $f;
|
312 |
}
|
|
|
|
|
313 |
}
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
WPAdm_Core::rmdir($d);
|
320 |
-
}
|
321 |
}
|
322 |
}
|
323 |
}
|
324 |
-
WPAdm_Core::log(
|
325 |
|
326 |
-
WPAdm_Core::log(
|
327 |
|
328 |
wpadm_class::setBackup(2);
|
329 |
if (!empty($errors)) {
|
@@ -336,8 +345,12 @@ if (!class_exists('WPadm_Method_Full_Backup_Dropbox')) {
|
|
336 |
}
|
337 |
wpadm_class::backupSend();
|
338 |
return $this->result;
|
|
|
|
|
339 |
}
|
340 |
|
|
|
|
|
341 |
public function createListFilesForArchive() {
|
342 |
$folders = array();
|
343 |
$files = array();
|
@@ -345,15 +358,15 @@ if (!class_exists('WPadm_Method_Full_Backup_Dropbox')) {
|
|
345 |
$files = array_merge(
|
346 |
$files,
|
347 |
array(
|
348 |
-
|
349 |
ABSPATH . 'index.php',
|
350 |
-
|
351 |
-
|
352 |
ABSPATH . 'wp-activate.php',
|
353 |
ABSPATH . 'wp-blog-header.php',
|
354 |
ABSPATH . 'wp-comments-post.php',
|
355 |
ABSPATH . 'wp-config.php',
|
356 |
-
|
357 |
ABSPATH . 'wp-cron.php',
|
358 |
ABSPATH . 'wp-links-opml.php',
|
359 |
ABSPATH . 'wp-load.php',
|
@@ -365,30 +378,6 @@ if (!class_exists('WPadm_Method_Full_Backup_Dropbox')) {
|
|
365 |
ABSPATH . 'xmlrpc.php',
|
366 |
)
|
367 |
);
|
368 |
-
if ( file_exists(ABSPATH . '.htaccess') ) {
|
369 |
-
$files = array_merge( $files, array( ABSPATH . '.htaccess' ) );
|
370 |
-
}
|
371 |
-
if ( file_exists( ABSPATH . 'license.txt' ) ) {
|
372 |
-
$files = array_merge( $files, array( ABSPATH . 'license.txt' ) );
|
373 |
-
}
|
374 |
-
if ( file_exists( ABSPATH . 'readme.html' ) ) {
|
375 |
-
$files = array_merge( $files, array( ABSPATH . 'readme.html') );
|
376 |
-
}
|
377 |
-
if ( file_exists(ABSPATH . 'wp-config-sample.php') ) {
|
378 |
-
$files = array_merge( $files, array( ABSPATH . 'wp-config-sample.php' ) );
|
379 |
-
}
|
380 |
-
if ( file_exists(ABSPATH . 'robots.txt') ) {
|
381 |
-
$files = array_merge( $files, array( ABSPATH . 'robots.txt' ) );
|
382 |
-
}
|
383 |
-
|
384 |
-
// check files in root directory
|
385 |
-
$n = count($files);
|
386 |
-
for($i = 0; $i < $n; $i++) {
|
387 |
-
if (!file_exists($files[$i])) {
|
388 |
-
unset($files[$i]);
|
389 |
-
}
|
390 |
-
}
|
391 |
-
$files = array_values($files);
|
392 |
|
393 |
if (!empty($this->params['minus-path'])) {
|
394 |
$minus_path = explode(",", $this->params['minus-path']);
|
@@ -396,7 +385,7 @@ if (!class_exists('WPadm_Method_Full_Backup_Dropbox')) {
|
|
396 |
$v = str_replace(ABSPATH , '', $v);
|
397 |
if (in_array($v, $minus_path)) {
|
398 |
unset($files[$k]);
|
399 |
-
WPAdm_Core::log(
|
400 |
}
|
401 |
}
|
402 |
}
|
@@ -452,29 +441,16 @@ if (!class_exists('WPadm_Method_Full_Backup_Dropbox')) {
|
|
452 |
|
453 |
$d = str_replace('\\', '/', $d);
|
454 |
$tmp = explode('/', $d);
|
455 |
-
|
456 |
-
if (function_exists('mb_strtolower')) {
|
457 |
-
$d1 = mb_strtolower($tmp[0]);
|
458 |
-
} else {
|
459 |
-
$d1 = strtolower($tmp[0]);
|
460 |
-
}
|
461 |
unset($tmp[0]);
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
}
|
467 |
-
if (strpos($d2, 'cache') !== false && isset($tmp[0]) && !in_array($tmp[0], array('plugins', 'themes')) ) {
|
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 |
-
}
|
477 |
-
|
478 |
if ($handle = opendir($directory)) {
|
479 |
while (false !== ($file = readdir($handle))) {
|
480 |
if ($file != "." && $file != "..") {
|
@@ -503,7 +479,7 @@ if (!class_exists('WPadm_Method_Full_Backup_Dropbox')) {
|
|
503 |
if (!in_array($f, $minus_path)) {
|
504 |
$array_items[] = $ff;
|
505 |
} else {
|
506 |
-
WPAdm_Core::log(
|
507 |
}
|
508 |
}
|
509 |
}
|
@@ -543,28 +519,5 @@ if (!class_exists('WPadm_Method_Full_Backup_Dropbox')) {
|
|
543 |
$this->stime = $conf['stime'];
|
544 |
$this->queue = new WPAdm_Queue($this->id);
|
545 |
}
|
546 |
-
|
547 |
-
private function getArchiveName($name)
|
548 |
-
{
|
549 |
-
//WPAdm_Core::log("{$name}-*.zip");
|
550 |
-
$archives = glob("{$name}-*.zip");
|
551 |
-
//WPAdm_Core::log( print_r($archives, 1) );
|
552 |
-
if (empty($archives)) {
|
553 |
-
return "{$name}-1.zip";
|
554 |
-
}
|
555 |
-
$n = count($archives);
|
556 |
-
$f = "{$name}-{$n}.zip";
|
557 |
-
return $f;
|
558 |
-
}
|
559 |
-
|
560 |
-
private function getNextArchiveName($name)
|
561 |
-
{
|
562 |
-
//WPAdm_Core::log("{$name}-*.zip");
|
563 |
-
$archives = glob("{$name}-*.zip");
|
564 |
-
$n = 1 + count($archives);
|
565 |
-
$a = "{$name}-{$n}.zip";
|
566 |
-
//WPAdm_Core::log($a);
|
567 |
-
return $a;
|
568 |
-
}
|
569 |
}
|
570 |
}
|
1 |
<?php
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Creates a full backup of the site
|
4 |
* Class WPadm_Method_Backup_Dropbox
|
48 |
'stime' => time(),
|
49 |
)
|
50 |
);
|
|
|
51 |
|
52 |
+
|
|
|
|
|
53 |
$name = get_option('siteurl');
|
54 |
|
55 |
$name = str_replace("http://", '', $name);
|
56 |
$name = str_replace("https://", '', $name);
|
|
|
|
|
|
|
57 |
$name = preg_replace("|\W|", "_", $name);
|
58 |
$name .= '-' . $this->type . '-' . date("Y_m_d_H_i");
|
59 |
$this->name = $name;
|
60 |
|
61 |
// folder for backup
|
62 |
+
$this->dir = ABSPATH . 'wpadm_backups/' . $this->name;
|
63 |
+
WPAdm_Core::mkdir(ABSPATH . 'wpadm_backups/');
|
64 |
+
WPAdm_Core::mkdir($this->dir);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
}
|
66 |
|
67 |
public function getResult()
|
71 |
$this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
|
72 |
$this->result->setError('');
|
73 |
|
74 |
+
WPAdm_Core::log( langWPADM::get('Start backup', false) );
|
75 |
|
76 |
# create db dump
|
77 |
+
WPAdm_Core::log( langWPADM::get('Start create db dump', false) );
|
78 |
+
WPAdm_Core::mkdir(ABSPATH . 'wpadm_backup');
|
79 |
+
$mysql_dump_file = ABSPATH . 'wpadm_backup/mysqldump.sql';
|
|
|
|
|
|
|
|
|
|
|
80 |
if (file_exists($mysql_dump_file)) {
|
81 |
unlink($mysql_dump_file);
|
82 |
}
|
83 |
$wp_mysql_params = $this->getWpMysqlParams();
|
84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
if (isset($this->params['optimize']) && ($this->params['optimize']==1)) {
|
86 |
+
WPAdm_Core::log( langWPADM::get('Table optimization', false) );
|
87 |
+
$commandContext = new WPAdm_Command_Context();
|
88 |
+
$commandContext ->addParam('command','mysqloptimize')
|
89 |
+
->addParam('host', $wp_mysql_params['host'])
|
90 |
+
->addParam('db', $wp_mysql_params['db'])
|
91 |
+
->addParam('user', $wp_mysql_params['user'])
|
92 |
+
->addParam('password', $wp_mysql_params['password']);
|
93 |
+
$this->queue->clear()
|
94 |
+
->add($commandContext);
|
95 |
+
unset($commandContext);
|
96 |
+
}
|
97 |
+
|
98 |
+
$commandContext = new WPAdm_Command_Context();
|
99 |
+
$commandContext ->addParam('command','mysqldump')
|
100 |
+
->addParam('host', $wp_mysql_params['host'])
|
101 |
+
->addParam('db', $wp_mysql_params['db'])
|
102 |
+
->addParam('user', $wp_mysql_params['user'])
|
103 |
+
->addParam('password', $wp_mysql_params['password'])
|
104 |
+
->addParam('tables', '')
|
105 |
+
->addParam('to_file', $mysql_dump_file);
|
106 |
+
$res = $this->queue->add($commandContext)
|
107 |
+
->save()
|
108 |
+
->execute();
|
109 |
+
if (!$res) {
|
110 |
+
$log = str_replace('%s', $this->queue->getError(), langWPADM::get('Error: Dump of Database wasn\'t created (%s)', false) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
WPAdm_Core::log($log);
|
112 |
+
$errors[] = $log;
|
113 |
+
} elseif (0 == (int)filesize($mysql_dump_file)) {
|
114 |
+
$errors[] = langWPADM::get('MySQL Error: Database-Dump File is empty', false);
|
115 |
+
WPAdm_Core::log(langWPADM::get('Dump of Database wasn\'t created (File of Database-Dump is empty!)', false));
|
116 |
} else {
|
117 |
$size_dump = round( (filesize($mysql_dump_file) / 1024 / 1024) , 2);
|
118 |
+
$log = str_replace("%s", $size_dump , langWPADM::get('Database Dump was successfully created ( %s Mb) : ', false) ) ;
|
119 |
WPAdm_Core::log($log . $mysql_dump_file);
|
120 |
}
|
121 |
+
unset($commandContext);
|
122 |
+
|
123 |
|
124 |
+
#ЗАРХИВИРУЕМ ФАЙЛЫ
|
125 |
+
WPAdm_Core::log( langWPADM::get('Create a list of files for Backup', false) );
|
126 |
$files = $this->createListFilesForArchive();
|
127 |
if (file_exists($mysql_dump_file) && filesize($mysql_dump_file) > 0) {
|
128 |
$files[] = $mysql_dump_file;
|
129 |
}
|
130 |
|
131 |
if (empty($files)) {
|
132 |
+
$errors[] = langWPADM::get('Error: the list of Backup files is empty', false);
|
133 |
}
|
134 |
|
135 |
// split the file list by 170kbayt lists, To break one big task into smaller
|
151 |
$files2[$i][] = $f;
|
152 |
}
|
153 |
|
154 |
+
WPAdm_Core::log( langWPADM::get('List of Backup-Files was successfully created', false) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
|
156 |
+
$this->queue->clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
|
158 |
+
foreach($files2 as $files) {
|
159 |
+
$commandContext = new WPAdm_Command_Context();
|
160 |
+
$commandContext ->addParam('command','archive')
|
161 |
+
->addParam('files', $files)
|
162 |
+
->addParam('to_file', $this->dir . '/'.$this->name)
|
163 |
+
->addParam('max_file_size', 900000)
|
164 |
+
->addParam('remove_path', ABSPATH);
|
|
|
165 |
|
166 |
+
$this->queue->add($commandContext);
|
167 |
+
unset($commandContext);
|
|
|
|
|
|
|
168 |
}
|
169 |
+
WPAdm_Core::log( langWPADM::get('Backup of Files was started', false) );
|
170 |
+
$this->queue->save()
|
171 |
+
->execute();
|
172 |
+
WPAdm_Core::log( langWPADM::get('End of File Backup', false) );
|
173 |
|
174 |
$files = glob($this->dir . '/'.$this->name . '*');
|
175 |
$urls = array();
|
183 |
|
184 |
|
185 |
$remove_from_server = 0;
|
186 |
+
if (isset($this->params['storage'])) {
|
187 |
+
foreach($this->params['storage'] as $storage) {
|
188 |
+
if ($storage['type'] == 'ftp') {
|
189 |
+
WPAdm_Core::log( langWPADM::get('Begin copying files to FTP', false) );
|
190 |
+
$this->queue->clear();
|
191 |
+
$files = glob($this->dir . '/'.$this->name . '*');
|
192 |
+
//$this->getResult()->setData($files);
|
193 |
+
$ad = $storage['access_details'];
|
194 |
+
$dir = (isset($ad['dir'])) ? $ad['dir'] : '/';
|
195 |
+
$dir = trim($dir, '/') . '/' . $this->name;
|
196 |
+
foreach($files as $file) {
|
197 |
+
$commandContext = new WPAdm_Command_Context();
|
198 |
+
$commandContext ->addParam('command','send_to_ftp')
|
199 |
+
->addParam('file', $file)
|
200 |
+
->addParam('host', $ad['host'])
|
201 |
+
->addParam('port', (isset($ad['port']))? $ad['port'] : 21)
|
202 |
+
->addParam('user', $ad['user'])
|
203 |
+
->addParam('password', $ad['password'])
|
204 |
+
->addParam('dir', $dir)
|
205 |
+
->addParam('http_host', isset($ad['http_host']) ? $ad['http_host'] : '');
|
206 |
+
$this->queue->add($commandContext);
|
207 |
+
unset($commandContext);
|
208 |
+
}
|
209 |
+
$res = $this->queue->save()
|
210 |
+
->execute();
|
211 |
+
if (!$res) {
|
212 |
+
$log = langWPADM::get('FTP: ' , false);
|
213 |
+
WPAdm_Core::log($log . $this->queue->getError());
|
214 |
+
$errors[] = $log . $this->queue->getError();
|
215 |
+
}
|
216 |
+
WPAdm_Core::log( langWPADM::get('Finished copying files to FTP' , false) );
|
217 |
+
if (isset($storage['remove_from_server']) && $storage['remove_from_server'] == 1 ) {
|
218 |
+
$remove_from_server = $storage['remove_from_server'];
|
219 |
+
}
|
220 |
+
} elseif ($storage['type'] == 's3') {
|
221 |
+
WPAdm_Core::log( langWPADM::get('Begin coping files to S3' , false) );
|
222 |
+
$this->queue->clear();
|
223 |
+
$files = glob($this->dir . '/'.$this->name . '*');
|
224 |
+
//$this->getResult()->setData($files);
|
225 |
+
$ad = $storage['access_details'];
|
226 |
+
$dir = (isset($ad['dir'])) ? $ad['dir'] : '/';
|
227 |
+
$dir = trim($dir, '/') . '/' . $this->name;
|
228 |
+
foreach($files as $file) {
|
229 |
+
$commandContext = new WPAdm_Command_Context();
|
230 |
+
$commandContext ->addParam('command','send_to_s3')
|
231 |
+
->addParam('file', $file)
|
232 |
+
->addParam('bucket', $ad['bucket'])
|
233 |
+
->addParam('AccessKeyId', $ad['AccessKeyId'])
|
234 |
+
->addParam('SecretAccessKey', $ad['SecretAccessKey'])
|
235 |
+
->addParam('SessionToken', $ad['SessionToken']);
|
236 |
+
$this->queue->add($commandContext);
|
237 |
+
unset($commandContext);
|
238 |
+
}
|
239 |
+
$res = $this->queue->save()
|
240 |
+
->execute();
|
241 |
+
if (!$res) {
|
242 |
+
WPAdm_Core::log('S3: ' . $this->queue->getError());
|
243 |
+
$errors[] = 'S3: '.$this->queue->getError();
|
244 |
+
}
|
245 |
+
WPAdm_Core::log( langWPADM::get('Finished copying files to S3' , false) );
|
246 |
+
if (isset($storage['remove_from_server']) && $storage['remove_from_server'] == 1 ) {
|
247 |
+
$remove_from_server = $storage['remove_from_server'];
|
248 |
+
}
|
249 |
+
}
|
250 |
+
}
|
251 |
+
if ($remove_from_server) {
|
252 |
+
// удаляем файлы на сервере
|
253 |
+
WPAdm_Core::log( langWPADM::get('Remove the backup server' , false) );
|
254 |
+
WPAdm_Core::rmdir($this->dir);
|
255 |
+
}
|
256 |
+
|
257 |
+
}
|
258 |
+
if (isset($this->params['gd']) && isset($this->params['gd']['key']) && isset($this->params['gd']['secret'])) {
|
259 |
+
$this->queue->clear();
|
260 |
$files = glob($this->dir . '/' . $this->name . '*');
|
|
|
261 |
$files = array_merge_recursive(array($mysql_dump_file), $files);
|
262 |
+
WPAdm_Core::log( langWPADM::get('files to google: ' , false) . print_r($files, true));
|
263 |
+
$n = count($files);
|
264 |
+
for($i = 0; $i <$n; $i++) {
|
265 |
+
$commandContext = new WPAdm_Command_Context();
|
266 |
+
$commandContext->addParam('command', 'send_to_google_drive')
|
267 |
+
->addParam('key', $this->params['gd']['key'])
|
268 |
+
->addParam('secret', $this->params['gd']['secret'])
|
269 |
+
->addParam('token', $this->params['gd']['token'])
|
270 |
+
->addParam('folder_project', $this->params['gd']['folder'])
|
271 |
+
->addParam('folder', $this->name )
|
272 |
+
->addParam('files', $files[$i]);
|
273 |
+
$this->queue->add($commandContext);
|
274 |
+
unset($commandContext);
|
275 |
+
}
|
276 |
+
$res = $this->queue->save()
|
277 |
+
->execute();
|
278 |
+
if (!$res) {
|
279 |
+
WPAdm_Core::log( langWPADM::get('Google drive: ' , false) . $this->queue->getError());
|
280 |
}
|
281 |
+
//WPAdm_Core::log('google drive' . print_r($this->params, true));
|
282 |
+
}
|
283 |
+
if (isset($this->params['dropbox']) && isset($this->params['dropbox']['key']) && isset($this->params['dropbox']['secret'])) {
|
284 |
+
$this->queue->clear();
|
285 |
+
$files = glob($this->dir . '/' . $this->name . '*');
|
286 |
+
$files = array_merge_recursive(array($mysql_dump_file), $files);
|
287 |
+
WPAdm_Core::log( langWPADM::get('files to dropbox: ' , false) . print_r($files, true));
|
288 |
+
$n = count($files);
|
289 |
for($i = 0; $i <$n; $i++) {
|
290 |
+
$commandContext = new WPAdm_Command_Context();
|
291 |
+
$commandContext->addParam('command', 'send_to_dropbox')
|
292 |
+
->addParam('key', $this->params['dropbox']['key'])
|
293 |
+
->addParam('secret', $this->params['dropbox']['secret'])
|
294 |
+
->addParam('token', $this->params['dropbox']['token'])
|
295 |
+
->addParam('folder_project', $this->params['dropbox']['folder'])
|
296 |
+
->addParam('folder', $this->name)
|
297 |
+
->addParam('files', $files[$i]);
|
298 |
+
$this->queue->add($commandContext);
|
299 |
+
unset($commandContext);
|
300 |
+
}
|
301 |
+
$this->queue->save()
|
302 |
+
->execute();
|
303 |
+
if (!$res) {
|
304 |
+
WPAdm_Core::log(langWPADM::get('Dropbox: ' , false) . $this->queue->getError());
|
305 |
}
|
306 |
}
|
307 |
|
308 |
#Removing TMP-files
|
309 |
+
WPAdm_Core::rmdir(ABSPATH . 'wpadm_backup');
|
310 |
|
311 |
#Removind old backups(if limit the number of stored backups)
|
312 |
+
WPAdm_Core::log( langWPADM::get('Start removing old backups' , false) );
|
313 |
if ($this->params['limit'] != 0) {
|
314 |
+
$files = glob(ABSPATH . 'wpadm_backups/*');
|
315 |
+
if (count($files) > $this->params['limit']) {
|
316 |
+
$files2 = array();
|
317 |
+
foreach($files as $f) {
|
318 |
+
$fa = explode('-', $f);
|
319 |
+
if (count($fa) != 3) {
|
320 |
+
continue;
|
|
|
|
|
|
|
321 |
}
|
322 |
+
$files2[$fa[2]] = $f;
|
323 |
+
|
324 |
}
|
325 |
+
ksort($files2);
|
326 |
+
$d = count($files2) - $this->params['limit'];
|
327 |
+
$del = array_slice($files2, 0, $d);
|
328 |
+
foreach($del as $d) {
|
329 |
+
WPAdm_Core::rmdir($d);
|
|
|
|
|
330 |
}
|
331 |
}
|
332 |
}
|
333 |
+
WPAdm_Core::log( langWPADM::get('Finished removing old backups' , false) );
|
334 |
|
335 |
+
WPAdm_Core::log( langWPADM::get('Creating a backup is completed' , false) );
|
336 |
|
337 |
wpadm_class::setBackup(2);
|
338 |
if (!empty($errors)) {
|
345 |
}
|
346 |
wpadm_class::backupSend();
|
347 |
return $this->result;
|
348 |
+
|
349 |
+
|
350 |
}
|
351 |
|
352 |
+
|
353 |
+
|
354 |
public function createListFilesForArchive() {
|
355 |
$folders = array();
|
356 |
$files = array();
|
358 |
$files = array_merge(
|
359 |
$files,
|
360 |
array(
|
361 |
+
ABSPATH . '.htaccess',
|
362 |
ABSPATH . 'index.php',
|
363 |
+
ABSPATH . 'license.txt',
|
364 |
+
ABSPATH . 'readme.html',
|
365 |
ABSPATH . 'wp-activate.php',
|
366 |
ABSPATH . 'wp-blog-header.php',
|
367 |
ABSPATH . 'wp-comments-post.php',
|
368 |
ABSPATH . 'wp-config.php',
|
369 |
+
ABSPATH . 'wp-config-sample.php',
|
370 |
ABSPATH . 'wp-cron.php',
|
371 |
ABSPATH . 'wp-links-opml.php',
|
372 |
ABSPATH . 'wp-load.php',
|
378 |
ABSPATH . 'xmlrpc.php',
|
379 |
)
|
380 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
381 |
|
382 |
if (!empty($this->params['minus-path'])) {
|
383 |
$minus_path = explode(",", $this->params['minus-path']);
|
385 |
$v = str_replace(ABSPATH , '', $v);
|
386 |
if (in_array($v, $minus_path)) {
|
387 |
unset($files[$k]);
|
388 |
+
WPAdm_Core::log( langWPADM::get('Skip file ' , false) . $v);
|
389 |
}
|
390 |
}
|
391 |
}
|
441 |
|
442 |
$d = str_replace('\\', '/', $d);
|
443 |
$tmp = explode('/', $d);
|
444 |
+
$d1 = mb_strtolower($tmp[0]);
|
|
|
|
|
|
|
|
|
|
|
445 |
unset($tmp[0]);
|
446 |
+
$d2 = mb_strtolower(implode('/', $tmp));
|
447 |
+
if (strpos($d2, 'cache') !== false
|
448 |
+
&& !in_array($tmp[0], array('plugins', 'themes'))
|
449 |
+
) {
|
|
|
|
|
450 |
WPAdm_Core::log('Skip dir(cache) ' . $directory);
|
451 |
return array();
|
452 |
}
|
453 |
|
|
|
|
|
|
|
|
|
|
|
|
|
454 |
if ($handle = opendir($directory)) {
|
455 |
while (false !== ($file = readdir($handle))) {
|
456 |
if ($file != "." && $file != "..") {
|
479 |
if (!in_array($f, $minus_path)) {
|
480 |
$array_items[] = $ff;
|
481 |
} else {
|
482 |
+
WPAdm_Core::log( langWPADM::get('Skip dir ' , false) . $ff);
|
483 |
}
|
484 |
}
|
485 |
}
|
519 |
$this->stime = $conf['stime'];
|
520 |
$this->queue = new WPAdm_Queue($this->id);
|
521 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
522 |
}
|
523 |
}
|
methods/class-wpadm-method-local-backup.php
CHANGED
@@ -1,606 +1,308 @@
|
|
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 |
|
15 |
-
if ( WPAdm_Running::is_stop() ) {
|
16 |
-
parent::__construct($params);
|
17 |
-
$this->init(
|
18 |
-
array(
|
19 |
-
'id' => uniqid('wpadm_method__local_backup__'),
|
20 |
-
'stime' => time(),
|
21 |
-
)
|
22 |
-
);
|
23 |
-
|
24 |
-
WPAdm_Core::log(__('Create Unique Id ','dropbox-backup') . $this->id);
|
25 |
-
|
26 |
-
|
27 |
-
$name = get_option('siteurl');
|
28 |
-
|
29 |
-
if (!class_exists('WPAdm_Process')) {
|
30 |
-
require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-process.php';
|
31 |
-
}
|
32 |
-
|
33 |
-
$name = str_replace("http://", '', $name);
|
34 |
-
$name = str_replace("https://", '', $name);
|
35 |
-
$name = str_ireplace( array( 'Ä', 'ä', 'Ö', 'ö', 'ß', 'Ü', 'ü', 'å'),
|
36 |
-
array('ae', 'ae', 'oe', 'oe', 's', 'ue', 'ue', 'a'),
|
37 |
-
$name );
|
38 |
-
$name = preg_replace("|\W|", "_", $name);
|
39 |
-
if (isset($params['time']) && !empty($params['time'])) { // time 1432751372
|
40 |
-
$this->time = date("Y-m-d H:i", $params['time']);
|
41 |
-
$name .= '-' . wpadm_class::$type . '-' . date("Y_m_d_H_i", $params['time']);
|
42 |
-
} else {
|
43 |
-
$this->time = date("Y-m-d H:i"); //23.04.2015 13:45
|
44 |
-
$name .= '-' . wpadm_class::$type . '-' . date("Y_m_d_H_i");
|
45 |
-
}
|
46 |
-
$this->name = $name;
|
47 |
-
|
48 |
-
// folder for backup
|
49 |
-
|
50 |
-
|
51 |
-
$dropbox_options = wpadm_wp_full_backup_dropbox::getSettings();
|
52 |
|
53 |
-
|
54 |
-
$this->dir = DROPBOX_BACKUP_DIR_BACKUP . '/' . $name;
|
55 |
-
if ($dropbox_options) {
|
56 |
-
if (isset($dropbox_options['backup_folder']) && !empty($dropbox_options['backup_folder']) ) {
|
57 |
-
$this->dir = $dropbox_options['backup_folder'] . '/' . $name;
|
58 |
-
$this->base_dir = $dropbox_options['backup_folder'];
|
59 |
-
}
|
60 |
-
}
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
if (isset($dropbox_options['backup_folder']) && !empty($dropbox_options['backup_folder'])) {
|
69 |
-
$this->dir = $dropbox_options['backup_folder'] . '/' . $f;
|
70 |
-
}
|
71 |
-
}
|
72 |
-
if (isset($dropbox_options['backup_folder']) && !empty($dropbox_options['backup_folder'])) {
|
73 |
-
$error = WPAdm_Core::mkdir($dropbox_options['backup_folder']);
|
74 |
-
if (!empty($error)) {
|
75 |
-
$this->result->setError($error);
|
76 |
-
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
77 |
-
}
|
78 |
-
} else {
|
79 |
-
$error = WPAdm_Core::mkdir(DROPBOX_BACKUP_DIR_BACKUP);
|
80 |
-
if (!empty($error)) {
|
81 |
-
$this->result->setError($error);
|
82 |
-
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
83 |
-
}
|
84 |
-
}
|
85 |
-
$error = WPAdm_Core::mkdir($this->dir);
|
86 |
-
if (!empty($error)) {
|
87 |
-
$this->result->setError($error);
|
88 |
-
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
89 |
-
}
|
90 |
-
$opt_folder = WPAdm_Running::getCommandResultData('folder_create');
|
91 |
-
$opt_folder[$name] = true;
|
92 |
-
WPAdm_Running::setCommandResultData('folder_create', $opt_folder);
|
93 |
-
}
|
94 |
}
|
|
|
|
|
95 |
}
|
96 |
public function checkBackup()
|
97 |
{
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
return false;
|
102 |
-
}
|
103 |
-
$n = count($archives);
|
104 |
-
$f = "{$this->name}({$n})";
|
105 |
-
return $f;
|
106 |
}
|
107 |
-
|
|
|
|
|
108 |
}
|
109 |
public function getResult()
|
110 |
{
|
111 |
-
|
|
|
|
|
|
|
|
|
112 |
$errors = array();
|
113 |
-
if ( WPAdm_Running::is_stop() ) {
|
114 |
-
$this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
|
115 |
-
$this->result->setError('');
|
116 |
-
WPAdm_Core::log(__('Start Backup process...', 'dropbox-backup'));
|
117 |
-
|
118 |
-
# create db dump
|
119 |
-
if (in_array('db', $this->params['types']) ) {
|
120 |
-
|
121 |
-
$mysql_dump_file = DROPBOX_BACKUP_DIR_BACKUP . '/mysqldump.sql';
|
122 |
-
if ( !WPAdm_Running::getCommandResult('db') ) {
|
123 |
-
WPAdm_Running::setCommandResult('db');
|
124 |
-
WPAdm_Core::log(__('Creating Database Dump','dropbox-backup'));
|
125 |
-
$error = WPAdm_Core::mkdir(DROPBOX_BACKUP_DIR_BACKUP);
|
126 |
-
if (!empty($error)) {
|
127 |
-
$this->result->setError($error);
|
128 |
-
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
129 |
-
return $this->result;
|
130 |
-
}
|
131 |
-
if (file_exists($mysql_dump_file) && !file_exists(WPAdm_Core::getTmpDir() . "/db")) {
|
132 |
-
unlink($mysql_dump_file);
|
133 |
-
}
|
134 |
-
$wp_mysql_params = $this->getWpMysqlParams();
|
135 |
|
136 |
-
|
137 |
-
|
138 |
-
if (!class_exists('WPAdm_Mysqldump')) {
|
139 |
-
require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
|
140 |
-
}
|
141 |
|
142 |
-
|
143 |
-
$mysql->host = $wp_mysql_params['host'];
|
144 |
-
$mysql->user = $wp_mysql_params['user'];
|
145 |
-
$mysql->password = $wp_mysql_params['password'];
|
146 |
-
try {
|
147 |
-
$mysql->repair($wp_mysql_params['db']);
|
148 |
-
unset($mysql);
|
149 |
-
} catch (Exception $e) {
|
150 |
-
$this->result->setError( $e->getMessage() );
|
151 |
-
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
152 |
-
return $this->result;
|
153 |
-
}
|
154 |
-
unset($mysql);
|
155 |
-
}
|
156 |
-
}
|
157 |
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
|
182 |
|
183 |
-
|
184 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
$mysql = new WPAdm_Mysqldump();
|
190 |
-
$mysql->host = $wp_mysql_params['host'];
|
191 |
-
$mysql->user = $wp_mysql_params['user'];
|
192 |
-
$mysql->password = $wp_mysql_params['password'];
|
193 |
-
|
194 |
-
try {
|
195 |
-
$mysql->mysqldump($wp_mysql_params['db'], $mysql_dump_file);
|
196 |
-
} catch (Exception $e) {
|
197 |
-
$this->result->setError( $e->getMessage() );
|
198 |
-
$this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
|
199 |
-
return $this->result;
|
200 |
-
}
|
201 |
-
unset($mysql);
|
202 |
-
|
203 |
-
if (0 == (int)filesize($mysql_dump_file)) {
|
204 |
-
$log = str_replace(array('%domain', '%dir'), array(SITE_HOME, DROPBOX_BACKUP_DIR_BACKUP), __('Website "%domain" returned an error during database dump creation: Database-Dump file is emplty. To solve this problem, please check permissions to folder: "%dir".','dropbox-backup') );
|
205 |
-
$errors[] = $log;
|
206 |
-
WPAdm_Core::log($log);
|
207 |
-
$this->result->setError( $log );
|
208 |
-
$this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
|
209 |
-
return $this->result;
|
210 |
-
} else {
|
211 |
-
$size_dump = round( (filesize($mysql_dump_file) / 1024 / 1024) , 2);
|
212 |
-
$log = str_replace("%size", $size_dump , __('Database Dump was successfully created ( %size Mb) : ','dropbox-backup') ) ;
|
213 |
-
WPAdm_Core::log($log . $mysql_dump_file);
|
214 |
-
}
|
215 |
-
WPAdm_Running::setCommandResult('db', true);
|
216 |
-
}
|
217 |
-
}
|
218 |
-
}
|
219 |
-
}
|
220 |
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
return true;
|
240 |
-
}
|
241 |
|
242 |
-
|
243 |
-
if ( WPAdm_Running::is_stop() ) {
|
244 |
-
$files2 = WPAdm_Running::getCommandResultData('files2');
|
245 |
-
if (empty($files2)) {
|
246 |
-
$files2 = array();
|
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 > $chunk_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 ' . WPADM_getSize($f_size) . " (" . $permission_file . ")" );
|
272 |
-
}
|
273 |
-
$size += $f_size;
|
274 |
-
$files2[$i][] = utf8_decode( $f );
|
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 |
-
$af1 = $this->getArchiveName($to_file);
|
309 |
-
$archive = new WPAdm_Archive($af1, $to_file . '.md5');
|
310 |
-
$archive->setRemovePath(ABSPATH);
|
311 |
-
if ( !file_exists( $af1 ) ) {
|
312 |
-
WPAdm_Core::log( __('Create part ','dropbox-backup') . basename( $af1 ) );
|
313 |
-
}
|
314 |
-
}
|
315 |
-
$targz = WPAdm_Running::getCommandResultData('test_targz_archive');
|
316 |
-
|
317 |
-
if ( ( !empty($targz) && $targz === true ) || ( file_exists($af1) && filesize($af1) > 900000 ) ) {
|
318 |
-
if ( WPAdm_Running::is_stop() ) {
|
319 |
-
$af2 = $this->getNextArchiveName($to_file);
|
320 |
-
if ($af1 != $af2) {
|
321 |
-
unset($archive);
|
322 |
-
if ( !file_exists( $af2 ) ) {
|
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') ) {
|
336 |
-
$files_str = implode( PCLZIP_SEPARATOR , $files);
|
337 |
-
} else {
|
338 |
-
$files_str = implode( ',' , $files);
|
339 |
-
}
|
340 |
-
$files_archive = WPAdm_Running::getCommandResultData('archive');
|
341 |
-
if ( WPAdm_Running::is_stop() ) {
|
342 |
-
if ( !isset($files_archive[$md5]) ) {
|
343 |
-
if ( WPAdm_Running::is_stop() ) {
|
344 |
-
$res = $archive->add($files_str);
|
345 |
-
if ($res) {
|
346 |
-
$files_archive = WPAdm_Running::getCommandResultData('archive');
|
347 |
-
$files_archive[$md5] = 1;
|
348 |
-
WPAdm_Running::setCommandResultData('archive', $files_archive);
|
349 |
-
WPAdm_Process::setInc( 'archiving', count($files) );
|
350 |
-
} else {
|
351 |
-
if ($archive->anew) {
|
352 |
-
return true;
|
353 |
-
} else {
|
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;
|
361 |
-
}
|
362 |
-
}
|
363 |
-
} else {
|
364 |
-
return true;
|
365 |
-
}
|
366 |
-
}
|
367 |
-
}
|
368 |
-
}
|
369 |
|
370 |
-
|
371 |
-
|
|
|
|
|
|
|
|
|
|
|
372 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
373 |
}
|
374 |
-
|
375 |
-
|
376 |
-
$files = glob($this->dir . '/'.$this->name . '*');
|
377 |
-
$urls = array();
|
378 |
-
$totalSize = 0;
|
379 |
-
foreach($files as $file) {
|
380 |
-
$urls[] = str_replace(ABSPATH, '', $file);
|
381 |
-
$totalSize += @intval( filesize($file) );
|
382 |
-
}
|
383 |
-
$this->result->setData($urls);
|
384 |
-
$this->result->setSize($totalSize);
|
385 |
-
$this->result->setValue('md5_data', md5 ( print_r($this->result->toArray(), 1 ) ) );
|
386 |
-
$this->result->setValue('name', $this->name );
|
387 |
-
$this->result->setValue('time', $this->time);
|
388 |
-
$this->result->setValue('type', 'local');
|
389 |
-
$this->result->setValue('counts', count($urls) );
|
390 |
-
$size = WPADM_getSize( $totalSize ); /// MByte
|
391 |
-
$log = str_replace("%s", $size , __('Backup size %s','dropbox-backup') ) ;
|
392 |
-
WPAdm_Core::log($log);
|
393 |
-
|
394 |
-
$remove_from_server = 0;
|
395 |
-
#Removing TMP-files
|
396 |
-
WPAdm_Core::rmdir($mysql_dump_file);
|
397 |
-
|
398 |
-
#Removind old backups(if limit the number of stored backups)
|
399 |
-
if ($this->params['limit'] != 0) {
|
400 |
-
WPAdm_Core::log( __('Limits of Backups ','dropbox-backup') . $this->params['limit'] );
|
401 |
-
WPAdm_Core::log( __('Removing of old Backups was started','dropbox-backup') );
|
402 |
-
$files = glob(DROPBOX_BACKUP_DIR_BACKUP . '/*');
|
403 |
-
if (count($files) > $this->params['limit']) {
|
404 |
-
$files2 = array();
|
405 |
-
foreach($files as $f) {
|
406 |
-
$fa = explode('-', $f);
|
407 |
-
if (count($fa) != 3) {
|
408 |
-
continue;
|
409 |
-
}
|
410 |
-
$files2[$fa[2]] = $f;
|
411 |
-
|
412 |
-
}
|
413 |
-
ksort($files2);
|
414 |
-
$d = count($files2) - $this->params['limit'];
|
415 |
-
$del = array_slice($files2, 0, $d);
|
416 |
-
foreach($del as $d) {
|
417 |
-
WPAdm_Core::rmdir($d);
|
418 |
-
}
|
419 |
-
}
|
420 |
-
WPAdm_Core::log( __('Removing of old Backups was Finished','dropbox-backup') );
|
421 |
-
}
|
422 |
-
} else {
|
423 |
-
return true;
|
424 |
-
}
|
425 |
-
}
|
426 |
-
} else {
|
427 |
-
return true;
|
428 |
}
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
435 |
-
WPAdm_Core::rmdir($this->dir);
|
436 |
-
wpadm_class::setStatus(0);
|
437 |
-
wpadm_class::setErrors( implode(", ", $errors) );
|
438 |
-
} else {
|
439 |
-
wpadm_class::setStatus(1);
|
440 |
-
WPAdm_Core::log( __('Backup creation was complete successfully!','dropbox-backup') );
|
441 |
}
|
442 |
-
wpadm_class::backupSend();
|
443 |
-
} else {
|
444 |
-
return true;
|
445 |
}
|
446 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
447 |
}
|
|
|
|
|
|
|
448 |
|
449 |
}
|
450 |
-
public function createListFilesForArchive()
|
451 |
-
|
452 |
-
$
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
}
|
479 |
-
} else {
|
480 |
-
$folders = array();
|
481 |
-
$files = array();
|
482 |
-
|
483 |
-
$files = array_merge(
|
484 |
-
$files,
|
485 |
-
array(
|
486 |
-
//ABSPATH . '.htaccess',
|
487 |
-
ABSPATH . 'index.php',
|
488 |
-
// ABSPATH . 'license.txt',
|
489 |
-
// ABSPATH . 'readme.html',
|
490 |
-
ABSPATH . 'wp-activate.php',
|
491 |
-
ABSPATH . 'wp-blog-header.php',
|
492 |
-
ABSPATH . 'wp-comments-post.php',
|
493 |
-
ABSPATH . 'wp-config.php',
|
494 |
-
// ABSPATH . 'wp-config-sample.php',
|
495 |
-
ABSPATH . 'wp-cron.php',
|
496 |
-
ABSPATH . 'wp-links-opml.php',
|
497 |
-
ABSPATH . 'wp-load.php',
|
498 |
-
ABSPATH . 'wp-login.php',
|
499 |
-
ABSPATH . 'wp-mail.php',
|
500 |
-
ABSPATH . 'wp-settings.php',
|
501 |
-
//ABSPATH . 'wp-signup.php',
|
502 |
-
ABSPATH . 'wp-trackback.php',
|
503 |
-
ABSPATH . 'xmlrpc.php',
|
504 |
-
)
|
505 |
-
);
|
506 |
-
if ( file_exists(ABSPATH . '.htaccess') ) {
|
507 |
-
$files = array_merge( $files, array( ABSPATH . '.htaccess' ) );
|
508 |
-
}
|
509 |
-
if ( file_exists( ABSPATH . 'license.txt' ) ) {
|
510 |
-
$files = array_merge( $files, array( ABSPATH . 'license.txt' ) );
|
511 |
-
}
|
512 |
-
if ( file_exists( ABSPATH . 'readme.html' ) ) {
|
513 |
-
$files = array_merge( $files, array( ABSPATH . 'readme.html') );
|
514 |
-
}
|
515 |
-
if ( file_exists(ABSPATH . 'wp-config-sample.php') ) {
|
516 |
-
$files = array_merge( $files, array( ABSPATH . 'wp-config-sample.php' ) );
|
517 |
-
}
|
518 |
-
if ( file_exists(ABSPATH . 'robots.txt') ) {
|
519 |
-
$files = array_merge( $files, array( ABSPATH . 'robots.txt' ) );
|
520 |
-
}
|
521 |
-
if ( file_exists(ABSPATH . 'wp-signup.php') ) {
|
522 |
-
$files = array_merge( $files, array( ABSPATH . 'wp-signup.php' ) );
|
523 |
-
}
|
524 |
|
525 |
-
|
526 |
-
$
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
$files = array_values($files);
|
533 |
-
|
534 |
-
if (!empty($this->params['minus-path'])) {
|
535 |
-
$minus_path = explode(",", $this->params['minus-path']);
|
536 |
-
foreach($files as $k => $v) {
|
537 |
-
$v = str_replace(ABSPATH , '', $v);
|
538 |
-
if (in_array($v, $minus_path)) {
|
539 |
-
unset($files[$k]);
|
540 |
-
WPAdm_Core::log( __('Skip of File ','dropbox-backup') . $v);
|
541 |
-
}
|
542 |
}
|
543 |
}
|
|
|
544 |
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
}
|
566 |
}
|
567 |
}
|
568 |
}
|
|
|
569 |
|
570 |
-
|
571 |
-
|
572 |
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
}
|
577 |
-
$files = array_merge($files, $this->directoryToArray($folder, true));
|
578 |
}
|
|
|
579 |
}
|
580 |
-
|
581 |
-
$files = array_values( array_unique($files) );
|
582 |
-
|
583 |
return $files;
|
584 |
}
|
585 |
|
586 |
-
public function tryToUtf8( $string, $strip = false )
|
587 |
-
{
|
588 |
-
$string = (string) $string;
|
589 |
-
|
590 |
-
if ( 0 === strlen( $string ) ) {
|
591 |
-
return '';
|
592 |
-
}
|
593 |
-
// preg match invalid UTF8
|
594 |
-
if ( 1 === @preg_match( '/^./us', $string ) ) {
|
595 |
-
return $string;
|
596 |
-
}
|
597 |
-
|
598 |
-
if ( $strip && function_exists( 'iconv' ) ) {
|
599 |
-
return iconv( 'utf-8', 'utf-8', $string );
|
600 |
-
}
|
601 |
-
|
602 |
-
return $string;
|
603 |
-
}
|
604 |
|
605 |
private function directoryToArray($directory, $recursive) {
|
606 |
$array_items = array();
|
@@ -610,7 +312,7 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
|
|
610 |
if (isset($this->params['minus-path'])) {
|
611 |
$minus_path = explode(",", $this->params['minus-path']);
|
612 |
if (in_array($d, $minus_path) ) {
|
613 |
-
WPAdm_Core::log(
|
614 |
return array();
|
615 |
}
|
616 |
} else {
|
@@ -619,46 +321,18 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
|
|
619 |
|
620 |
$d = str_replace('\\', '/', $d);
|
621 |
$tmp = explode('/', $d);
|
622 |
-
|
623 |
-
$d1 = mb_strtolower($tmp[0]);
|
624 |
-
} else {
|
625 |
-
$d1 = strtolower($tmp[0]);
|
626 |
-
}
|
627 |
-
$base_dir = $tmp[0];
|
628 |
unset($tmp[0]);
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
$d2 = strtolower(implode('/', $tmp));
|
633 |
-
}
|
634 |
-
|
635 |
-
if (stripos($d2, 'cache') !== false ) {
|
636 |
-
WPAdm_Core::log( __('Skip of Cache-Folder ','dropbox-backup') . $directory);
|
637 |
-
return array();
|
638 |
-
}
|
639 |
-
|
640 |
-
if (strpos($d2, 'cache') !== false && isset($tmp[0]) && !in_array($tmp[0], array('plugins', 'themes')) ) {
|
641 |
-
WPAdm_Core::log(__('Skip of Cache-Folder ','dropbox-backup') . $directory);
|
642 |
-
return array();
|
643 |
-
}
|
644 |
-
|
645 |
-
if (!empty($d2) && isset( $base_dir ) && BackupsFoldersExclude( basename( $d2 ), $base_dir ) ) {
|
646 |
-
WPAdm_Core::log( sprintf( __('Skip backup folder of another backup plugin "%s" ','dropbox-backup'), basename( $d2 ) ) );
|
647 |
-
return array();
|
648 |
-
}
|
649 |
-
if(stripos($directory, 'wpadm_backups') !== false || stripos($directory, 'Dropbox_Backup') !== false) {
|
650 |
-
return array();
|
651 |
-
}
|
652 |
-
|
653 |
-
if (stripos($d2, 'backup') !== false ) {
|
654 |
-
WPAdm_Core::log( __('Skip of Backup-Folder ','dropbox-backup') . $directory);
|
655 |
return array();
|
656 |
}
|
657 |
|
658 |
if ($handle = opendir($directory)) {
|
659 |
while (false !== ($file = readdir($handle))) {
|
660 |
-
if ($file != "." && $file != ".."
|
661 |
-
if (is_dir($directory. "/" . $file)
|
662 |
if($recursive) {
|
663 |
$array_items = array_merge($array_items, $this->directoryToArray($directory. "/" . $file, $recursive));
|
664 |
}
|
@@ -671,7 +345,7 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
|
|
671 |
if (!in_array($f, $minus_path)) {
|
672 |
$array_items[] = $ff;
|
673 |
} else {
|
674 |
-
WPAdm_Core::log(
|
675 |
}
|
676 |
}
|
677 |
} else {
|
@@ -681,9 +355,9 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
|
|
681 |
$f = str_replace(ABSPATH, '', $ff);
|
682 |
// skip "minus" dirs
|
683 |
if (!in_array($f, $minus_path)) {
|
684 |
-
$array_items[] = $
|
685 |
} else {
|
686 |
-
WPAdm_Core::log(
|
687 |
}
|
688 |
}
|
689 |
}
|
@@ -721,51 +395,7 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
|
|
721 |
private function init(array $conf) {
|
722 |
$this->id = $conf['id'];
|
723 |
$this->stime = $conf['stime'];
|
724 |
-
|
725 |
-
}
|
726 |
-
|
727 |
-
private function getArchiveName($name)
|
728 |
-
{
|
729 |
-
//WPAdm_Core::log("{$name}-*.zip");
|
730 |
-
$targz = WPAdm_Running::getCommandResultData('test_targz_archive');
|
731 |
-
if (!empty($targz) && $targz === true ) {
|
732 |
-
$archives = glob("{$name}-*.tar.gz");
|
733 |
-
} else {
|
734 |
-
$archives = glob("{$name}-*.zip");
|
735 |
-
}
|
736 |
-
|
737 |
-
if (empty($archives)) {
|
738 |
-
if (!empty($targz) && $targz === true ) {
|
739 |
-
return "{$name}-1.tar.gz";
|
740 |
-
} else {
|
741 |
-
return "{$name}-1.zip";
|
742 |
-
}
|
743 |
-
}
|
744 |
-
$n = count($archives);
|
745 |
-
if (!empty($targz) && $targz === true ) {
|
746 |
-
$f = "{$name}-{$n}.tar.gz";
|
747 |
-
} else {
|
748 |
-
$f = "{$name}-{$n}.zip";
|
749 |
-
}
|
750 |
-
return $f;
|
751 |
-
}
|
752 |
-
|
753 |
-
private function getNextArchiveName($name)
|
754 |
-
{
|
755 |
-
$targz = WPAdm_Running::getCommandResultData('test_targz_archive');
|
756 |
-
if (!empty($targz) && $targz === true ) {
|
757 |
-
$archives = glob("{$name}-*.tar.gz");
|
758 |
-
} else {
|
759 |
-
$archives = glob("{$name}-*.zip");
|
760 |
-
}
|
761 |
-
$n = 1 + count($archives);
|
762 |
-
if (!empty($targz) && $targz === true ) {
|
763 |
-
$a = "{$name}-{$n}.tar.gz";
|
764 |
-
} else {
|
765 |
-
$a = "{$name}-{$n}.zip";
|
766 |
-
}
|
767 |
-
//WPAdm_Core::log($a);
|
768 |
-
return $a;
|
769 |
}
|
770 |
}
|
771 |
}
|
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 |
+
parent::__construct($params);
|
11 |
+
$this->init(
|
12 |
+
array(
|
13 |
+
'id' => uniqid('wpadm_method_backup__'),
|
14 |
+
'stime' => time(),
|
15 |
+
)
|
16 |
+
);
|
17 |
+
$file_log = WPAdm_Core::getTmpDir() . "/log.log";
|
18 |
+
if (file_exists($file_log)) {
|
19 |
+
unlink($file_log);
|
20 |
+
}
|
21 |
+
WPAdm_Core::log(langWPADM::get('Create Unique Id ', false) . $this->id);
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
+
$name = get_option('siteurl');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
$name = str_replace("http://", '', $name);
|
27 |
+
$name = str_replace("https://", '', $name);
|
28 |
+
$name = preg_replace("|\W|", "_", $name);
|
29 |
+
if (isset($params['time']) && !empty($params['time'])) { // time 1432751372
|
30 |
+
$this->time = date("Y-m-d H:i", $params['time']);
|
31 |
+
$name .= '-' . wpadm_class::$type . '-' . date("Y_m_d_H_i", $params['time']);
|
32 |
+
} else {
|
33 |
+
$this->time = date("Y-m-d H:i"); //23.04.2015 13:45
|
34 |
+
$name .= '-' . wpadm_class::$type . '-' . date("Y_m_d_H_i");
|
35 |
+
}
|
36 |
+
$this->name = $name;
|
37 |
|
38 |
|
39 |
+
// folder for backup
|
40 |
+
$this->dir = ABSPATH . 'wpadm_backups/' . $this->name;
|
41 |
+
if (($f = $this->checkBackup()) !== false) {
|
42 |
+
$this->dir = ABSPATH . 'wpadm_backups/' . $f;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
}
|
44 |
+
WPAdm_Core::mkdir(ABSPATH . 'wpadm_backups/');
|
45 |
+
WPAdm_Core::mkdir($this->dir);
|
46 |
}
|
47 |
public function checkBackup()
|
48 |
{
|
49 |
+
$archives = glob("{$this->dir}");
|
50 |
+
if (empty($archives) && count($archives) <= 1) {
|
51 |
+
return false;
|
|
|
|
|
|
|
|
|
|
|
52 |
}
|
53 |
+
$n = count($archives);
|
54 |
+
$f = "{$this->name}({$n})";
|
55 |
+
return $f;
|
56 |
}
|
57 |
public function getResult()
|
58 |
{
|
59 |
+
if ($this->start === false) {
|
60 |
+
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
61 |
+
$this->result->setError(langWPADM::get('Backup process was started, please, wait a few minutes...', false));
|
62 |
+
return $this->result;
|
63 |
+
}
|
64 |
$errors = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
+
$this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
|
67 |
+
$this->result->setError('');
|
|
|
|
|
|
|
68 |
|
69 |
+
WPAdm_Core::log(langWPADM::get('Start Backup process...', false));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
+
# create db dump
|
72 |
+
if (in_array('db', $this->params['types']) ) {
|
73 |
+
WPAdm_Core::log(langWPADM::get('Creating Database Dump', false));
|
74 |
+
WPAdm_Core::mkdir(ABSPATH . 'wpadm_backup');
|
75 |
+
$mysql_dump_file = ABSPATH . 'wpadm_backup/mysqldump.sql';
|
76 |
+
if (file_exists($mysql_dump_file)) {
|
77 |
+
unlink($mysql_dump_file);
|
78 |
+
}
|
79 |
+
$wp_mysql_params = $this->getWpMysqlParams();
|
80 |
+
|
81 |
+
if (isset($this->params['optimize']) && ($this->params['optimize']==1)) {
|
82 |
+
WPAdm_Core::log(langWPADM::get('Optimize Database Tables', false));
|
83 |
+
$commandContext = new WPAdm_Command_Context();
|
84 |
+
$commandContext ->addParam('command','mysqloptimize')
|
85 |
+
->addParam('host', $wp_mysql_params['host'])
|
86 |
+
->addParam('db', $wp_mysql_params['db'])
|
87 |
+
->addParam('user', $wp_mysql_params['user'])
|
88 |
+
->addParam('password', $wp_mysql_params['password']);
|
89 |
+
$this->queue->clear()
|
90 |
+
->add($commandContext);
|
91 |
+
unset($commandContext);
|
92 |
+
}
|
93 |
+
|
94 |
+
$commandContext = new WPAdm_Command_Context();
|
95 |
+
$commandContext ->addParam('command','mysqldump')
|
96 |
+
->addParam('host', $wp_mysql_params['host'])
|
97 |
+
->addParam('db', $wp_mysql_params['db'])
|
98 |
+
->addParam('user', $wp_mysql_params['user'])
|
99 |
+
->addParam('password', $wp_mysql_params['password'])
|
100 |
+
->addParam('tables', '')
|
101 |
+
->addParam('to_file', $mysql_dump_file);
|
102 |
+
$res = $this->queue->add($commandContext)
|
103 |
+
->save()
|
104 |
+
->execute();
|
105 |
+
if (!$res) {
|
106 |
+
$log = str_replace('%s', $this->queue->getError(), langWPADM::get('Error: Dump of Database wasn\'t created (%s)', false) );
|
107 |
+
WPAdm_Core::log($log);
|
108 |
+
$errors[] = $log;
|
109 |
+
} elseif (0 == (int)filesize($mysql_dump_file)) {
|
110 |
+
$errors[] = langWPADM::get('MySQL Error: Database-Dump File is empty', false);
|
111 |
+
WPAdm_Core::log(langWPADM::get('Dump of Database wasn\'t created (File of Database-Dump is empty!)', false));
|
112 |
+
} else {
|
113 |
+
$size_dump = round( (filesize($mysql_dump_file) / 1024 / 1024) , 2);
|
114 |
+
$log = str_replace("%s", $size_dump , langWPADM::get('Database Dump was successfully created ( %s Mb) : ', false) ) ;
|
115 |
+
WPAdm_Core::log($log . $mysql_dump_file);
|
116 |
+
}
|
117 |
+
unset($commandContext);
|
118 |
+
}
|
119 |
|
120 |
|
121 |
+
if (in_array('files', $this->params['types']) ) {
|
122 |
+
#ЗАРХИВИРУЕМ ФАЙЛЫ
|
123 |
+
WPAdm_Core::log( langWPADM::get('Create a list of files for Backup', false) );
|
124 |
+
$files = $this->createListFilesForArchive();
|
125 |
+
}
|
126 |
+
if (isset($mysql_dump_file) && file_exists($mysql_dump_file) && filesize($mysql_dump_file) > 0) {
|
127 |
+
$files[] = $mysql_dump_file;
|
128 |
+
}
|
129 |
|
130 |
+
if (empty($files)) {
|
131 |
+
$errors[] = langWPADM::get('Error: the list of Backup files is empty', false);
|
132 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
+
// split the file list by 170kbayt lists, To break one big task into smaller
|
135 |
+
$files2 = array();
|
136 |
+
$files2[0] = array();
|
137 |
+
$i = 0;
|
138 |
+
$size = 0;
|
139 |
+
foreach($files as $f) {
|
140 |
+
if ($size > 170000) {//~170kbyte
|
141 |
+
$i ++;
|
142 |
+
$size = 0;
|
143 |
+
$files2[$i] = array();
|
144 |
+
}
|
145 |
+
$f_size =(int)@filesize($f);
|
146 |
+
if ($f_size == 0 || $f_size > 1000000) {
|
147 |
+
WPAdm_Core::log('File '. $f .' Size ' . $f_size);
|
148 |
+
}
|
149 |
+
$size += $f_size;
|
150 |
+
$files2[$i][] = $f;
|
151 |
+
}
|
|
|
|
|
152 |
|
153 |
+
WPAdm_Core::log( langWPADM::get('List of Backup-Files was successfully created', false) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
+
$this->queue->clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
|
157 |
+
foreach($files2 as $files) {
|
158 |
+
$commandContext = new WPAdm_Command_Context();
|
159 |
+
$commandContext ->addParam('command', 'archive')
|
160 |
+
->addParam('files', $files)
|
161 |
+
->addParam('to_file', $this->dir . '/'.$this->name)
|
162 |
+
->addParam('max_file_size', 900000)
|
163 |
+
->addParam('remove_path', ABSPATH);
|
164 |
|
165 |
+
$this->queue->add($commandContext);
|
166 |
+
unset($commandContext);
|
167 |
+
}
|
168 |
+
WPAdm_Core::log( langWPADM::get('Backup of Files was started', false) );
|
169 |
+
$this->queue->save()
|
170 |
+
->execute();
|
171 |
+
WPAdm_Core::log( langWPADM::get('End of File Backup', false) );
|
172 |
+
|
173 |
+
$files = glob($this->dir . '/'.$this->name . '*');
|
174 |
+
$urls = array();
|
175 |
+
$totalSize = 0;
|
176 |
+
foreach($files as $file) {
|
177 |
+
$urls[] = str_replace(ABSPATH, '', $file);
|
178 |
+
$totalSize += @intval( filesize($file) );
|
179 |
+
}
|
180 |
+
$this->result->setData($urls);
|
181 |
+
$this->result->setSize($totalSize);
|
182 |
+
$size = $totalSize / 1024 / 1024; /// MByte
|
183 |
+
$size = round($size, 2);
|
184 |
+
$log = str_replace("%s", $size , langWPADM::get('Backup Size %s Mb', false) ) ;
|
185 |
+
WPAdm_Core::log($log);
|
186 |
+
|
187 |
+
$remove_from_server = 0;
|
188 |
+
#Removing TMP-files
|
189 |
+
WPAdm_Core::rmdir(ABSPATH . 'wpadm_backup');
|
190 |
+
|
191 |
+
#Removind old backups(if limit the number of stored backups)
|
192 |
+
if ($this->params['limit'] != 0) {
|
193 |
+
WPAdm_Core::log( langWPADM::get('Limits of Backups ', false) . $this->params['limit'] );
|
194 |
+
WPAdm_Core::log( langWPADM::get('Removing of old Backups was started', false) );
|
195 |
+
$files = glob(ABSPATH . 'wpadm_backups/*');
|
196 |
+
if (count($files) > $this->params['limit']) {
|
197 |
+
$files2 = array();
|
198 |
+
foreach($files as $f) {
|
199 |
+
$fa = explode('-', $f);
|
200 |
+
if (count($fa) != 3) {
|
201 |
+
continue;
|
202 |
}
|
203 |
+
$files2[$fa[2]] = $f;
|
204 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
}
|
206 |
+
ksort($files2);
|
207 |
+
$d = count($files2) - $this->params['limit'];
|
208 |
+
$del = array_slice($files2, 0, $d);
|
209 |
+
foreach($del as $d) {
|
210 |
+
WPAdm_Core::rmdir($d);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
}
|
|
|
|
|
|
|
212 |
}
|
213 |
+
WPAdm_Core::log( langWPADM::get('Removing of old Backups was Finished', false) );
|
214 |
+
}
|
215 |
+
wpadm_class::setBackup(1);
|
216 |
+
if (!empty($errors)) {
|
217 |
+
$this->result->setError(implode("\n", $errors));
|
218 |
+
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
219 |
+
wpadm_class::setStatus(0);
|
220 |
+
wpadm_class::setErrors( implode(", ", $errors) );
|
221 |
+
} else {
|
222 |
+
wpadm_class::setStatus(1);
|
223 |
+
WPAdm_Core::log( langWPADM::get('Backup creating is completed successfully!', false) );
|
224 |
}
|
225 |
+
wpadm_class::backupSend();
|
226 |
+
|
227 |
+
return $this->result;
|
228 |
|
229 |
}
|
230 |
+
public function createListFilesForArchive() {
|
231 |
+
$folders = array();
|
232 |
+
$files = array();
|
233 |
+
|
234 |
+
$files = array_merge(
|
235 |
+
$files,
|
236 |
+
array(
|
237 |
+
ABSPATH . '.htaccess',
|
238 |
+
ABSPATH . 'index.php',
|
239 |
+
ABSPATH . 'license.txt',
|
240 |
+
ABSPATH . 'readme.html',
|
241 |
+
ABSPATH . 'wp-activate.php',
|
242 |
+
ABSPATH . 'wp-blog-header.php',
|
243 |
+
ABSPATH . 'wp-comments-post.php',
|
244 |
+
ABSPATH . 'wp-config.php',
|
245 |
+
ABSPATH . 'wp-config-sample.php',
|
246 |
+
ABSPATH . 'wp-cron.php',
|
247 |
+
ABSPATH . 'wp-links-opml.php',
|
248 |
+
ABSPATH . 'wp-load.php',
|
249 |
+
ABSPATH . 'wp-login.php',
|
250 |
+
ABSPATH . 'wp-mail.php',
|
251 |
+
ABSPATH . 'wp-settings.php',
|
252 |
+
ABSPATH . 'wp-signup.php',
|
253 |
+
ABSPATH . 'wp-trackback.php',
|
254 |
+
ABSPATH . 'xmlrpc.php',
|
255 |
+
)
|
256 |
+
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
|
258 |
+
if (!empty($this->params['minus-path'])) {
|
259 |
+
$minus_path = explode(",", $this->params['minus-path']);
|
260 |
+
foreach($files as $k => $v) {
|
261 |
+
$v = str_replace(ABSPATH , '', $v);
|
262 |
+
if (in_array($v, $minus_path)) {
|
263 |
+
unset($files[$k]);
|
264 |
+
WPAdm_Core::log( langWPADM::get('Skip of File ', false) . $v);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
}
|
266 |
}
|
267 |
+
}
|
268 |
|
269 |
+
$folders = array_merge(
|
270 |
+
$folders,
|
271 |
+
array(
|
272 |
+
ABSPATH . 'wp-admin',
|
273 |
+
ABSPATH . 'wp-content',
|
274 |
+
ABSPATH . 'wp-includes',
|
275 |
+
)
|
276 |
+
);
|
277 |
+
if (!empty($this->params['plus-path'])) {
|
278 |
+
$plus_path = explode(",", $this->params['plus-path']);
|
279 |
+
foreach($plus_path as $p) {
|
280 |
+
if (empty($p)) {
|
281 |
+
continue;
|
282 |
+
}
|
283 |
+
$p = ABSPATH . $p;
|
284 |
+
if (file_exists($p)) {
|
285 |
+
if (is_dir($p)) {
|
286 |
+
$folders[] = $p;
|
287 |
+
} else{
|
288 |
+
$files[] = $p;
|
|
|
289 |
}
|
290 |
}
|
291 |
}
|
292 |
+
}
|
293 |
|
294 |
+
$folders = array_unique($folders);
|
295 |
+
$files = array_unique($files);
|
296 |
|
297 |
+
foreach($folders as $folder) {
|
298 |
+
if (!is_dir($folder)) {
|
299 |
+
continue;
|
|
|
|
|
300 |
}
|
301 |
+
$files = array_merge($files, $this->directoryToArray($folder, true));
|
302 |
}
|
|
|
|
|
|
|
303 |
return $files;
|
304 |
}
|
305 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
306 |
|
307 |
private function directoryToArray($directory, $recursive) {
|
308 |
$array_items = array();
|
312 |
if (isset($this->params['minus-path'])) {
|
313 |
$minus_path = explode(",", $this->params['minus-path']);
|
314 |
if (in_array($d, $minus_path) ) {
|
315 |
+
WPAdm_Core::log(langWPADM::get('Skip of Folder ', false) . $directory);
|
316 |
return array();
|
317 |
}
|
318 |
} else {
|
321 |
|
322 |
$d = str_replace('\\', '/', $d);
|
323 |
$tmp = explode('/', $d);
|
324 |
+
$d1 = mb_strtolower($tmp[0]);
|
|
|
|
|
|
|
|
|
|
|
325 |
unset($tmp[0]);
|
326 |
+
$d2 = mb_strtolower(implode('/', $tmp));
|
327 |
+
if (strpos($d2, 'cache') !== false && isset($tmp[0])&& !in_array($tmp[0], array('plugins', 'themes')) ) {
|
328 |
+
WPAdm_Core::log(langWPADM::get('Skip of Cache-Folder ', false) . $directory);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
329 |
return array();
|
330 |
}
|
331 |
|
332 |
if ($handle = opendir($directory)) {
|
333 |
while (false !== ($file = readdir($handle))) {
|
334 |
+
if ($file != "." && $file != "..") {
|
335 |
+
if (is_dir($directory. "/" . $file)) {
|
336 |
if($recursive) {
|
337 |
$array_items = array_merge($array_items, $this->directoryToArray($directory. "/" . $file, $recursive));
|
338 |
}
|
345 |
if (!in_array($f, $minus_path)) {
|
346 |
$array_items[] = $ff;
|
347 |
} else {
|
348 |
+
WPAdm_Core::log(langWPADM::get('Skip of File ', false) . $ff);
|
349 |
}
|
350 |
}
|
351 |
} else {
|
355 |
$f = str_replace(ABSPATH, '', $ff);
|
356 |
// skip "minus" dirs
|
357 |
if (!in_array($f, $minus_path)) {
|
358 |
+
$array_items[] = $ff;
|
359 |
} else {
|
360 |
+
WPAdm_Core::log( langWPADM::get('Skip of Folder ', false) . $ff);
|
361 |
}
|
362 |
}
|
363 |
}
|
395 |
private function init(array $conf) {
|
396 |
$this->id = $conf['id'];
|
397 |
$this->stime = $conf['stime'];
|
398 |
+
$this->queue = new WPAdm_Queue($this->id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
399 |
}
|
400 |
}
|
401 |
}
|
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 |
*/
|
@@ -29,7 +25,7 @@ if (!class_exists('WPAdm_Method_Local_Restore')) {
|
|
29 |
if (file_exists($file_log)) {
|
30 |
unlink($file_log);
|
31 |
}
|
32 |
-
WPAdm_Core::log(
|
33 |
if (count($this->files_resotre) > 0) {
|
34 |
$this->restore = true;
|
35 |
}
|
@@ -37,42 +33,28 @@ if (!class_exists('WPAdm_Method_Local_Restore')) {
|
|
37 |
}
|
38 |
private function getFiles()
|
39 |
{
|
40 |
-
$res = false;
|
41 |
if (isset($this->params['name_backup']) && !empty($this->params['name_backup'])) {
|
42 |
-
$
|
43 |
-
if ($
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
$this->setError($str);
|
54 |
-
}
|
55 |
-
return $res;
|
56 |
-
|
57 |
-
}
|
58 |
-
|
59 |
-
private function readFiles($dir_backup)
|
60 |
-
{
|
61 |
-
if (is_dir($dir_backup)) {
|
62 |
-
WPAdm_Core::log('Read of Backup Files for Restore (' . $this->params['name_backup'] . ')');
|
63 |
-
$dir_open = opendir($dir_backup);
|
64 |
-
while($d = readdir($dir_open)) {
|
65 |
-
if ($d != "." && $d != '..') {
|
66 |
-
if(strpos($d, ".md5") !== false) {
|
67 |
-
$this->md5_info = explode ("\n", file_get_contents( $dir_backup . "/$d" ) );
|
68 |
-
} elseif(strpos($d, ".zip") !== false) {
|
69 |
-
$this->files_resotre[$d] = $dir_backup . "/$d";
|
70 |
}
|
71 |
}
|
|
|
72 |
}
|
73 |
-
|
74 |
-
|
|
|
|
|
75 |
return false;
|
|
|
76 |
}
|
77 |
private function setError($errors)
|
78 |
{
|
@@ -91,9 +73,11 @@ if (!class_exists('WPAdm_Method_Local_Restore')) {
|
|
91 |
$this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
|
92 |
$this->result->setError('');
|
93 |
|
94 |
-
WPAdm_Core::log(
|
95 |
$n = count($this->md5_info);
|
96 |
-
|
|
|
|
|
97 |
if (in_array('files', $this->params['types']) ) {
|
98 |
foreach($this->files_resotre as $key => $file) {
|
99 |
if (file_exists($file)) {
|
@@ -125,11 +109,8 @@ if (!class_exists('WPAdm_Method_Local_Restore')) {
|
|
125 |
->add($commandContext)->save()
|
126 |
->execute();
|
127 |
unset($commandContext);
|
128 |
-
if (file_exists(DROPBOX_BACKUP_DIR_BACKUP . "/mysqldump.sql")) {
|
129 |
-
@unlink(DROPBOX_BACKUP_DIR_BACKUP . "/mysqldump.sql");
|
130 |
-
}
|
131 |
} else {
|
132 |
-
$log = str_replace(
|
133 |
$this->setError($log);
|
134 |
WPAdm_Core::log($log);
|
135 |
break;
|
@@ -138,9 +119,7 @@ if (!class_exists('WPAdm_Method_Local_Restore')) {
|
|
138 |
}
|
139 |
}
|
140 |
} else {
|
141 |
-
WPAdm_Core::log(
|
142 |
-
str_replace( array('%d'), array(SITE_HOME), __('Website "%d" returned an error during restore backup: Files for restore is not exist, check permission your backup data or You can send to us support request using "Help" button on plugin page.','dropbox-backup') )
|
143 |
-
);
|
144 |
}
|
145 |
return $this->result;
|
146 |
}
|
1 |
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Class WPAdm_Method_Exec
|
4 |
*/
|
25 |
if (file_exists($file_log)) {
|
26 |
unlink($file_log);
|
27 |
}
|
28 |
+
WPAdm_Core::log(langWPADM::get('Create Unique Id ', false) . $this->id);
|
29 |
if (count($this->files_resotre) > 0) {
|
30 |
$this->restore = true;
|
31 |
}
|
33 |
}
|
34 |
private function getFiles()
|
35 |
{
|
|
|
36 |
if (isset($this->params['name_backup']) && !empty($this->params['name_backup'])) {
|
37 |
+
$dir_backup = ABSPATH . 'wpadm_backups/' . $this->params['name_backup'];
|
38 |
+
if (is_dir($dir_backup)) {
|
39 |
+
WPAdm_Core::log('Read of Backup Files for Restore (' . $this->params['name_backup'] . ')');
|
40 |
+
$dir_open = opendir($dir_backup);
|
41 |
+
while($d = readdir($dir_open)) {
|
42 |
+
if ($d != "." && $d != '..') {
|
43 |
+
if(strpos($d, ".md5") !== false) {
|
44 |
+
$this->md5_info = explode ("\n", file_get_contents( $dir_backup . "/$d" ) );
|
45 |
+
} elseif(strpos($d, ".zip") !== false) {
|
46 |
+
$this->files_resotre[$d] = $dir_backup . "/$d";
|
47 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
}
|
49 |
}
|
50 |
+
return true;
|
51 |
}
|
52 |
+
}
|
53 |
+
$str = str_replace('%s', $this->params['name_backup'], langWPADM::get('Error: folder is not exist (%s)', false));
|
54 |
+
WPAdm_Core::log($str);
|
55 |
+
$this->setError($str);
|
56 |
return false;
|
57 |
+
|
58 |
}
|
59 |
private function setError($errors)
|
60 |
{
|
73 |
$this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
|
74 |
$this->result->setError('');
|
75 |
|
76 |
+
WPAdm_Core::log(langWPADM::get('Start Restore process', false));
|
77 |
$n = count($this->md5_info);
|
78 |
+
if (in_array('db', $this->params['types'])) {
|
79 |
+
|
80 |
+
}
|
81 |
if (in_array('files', $this->params['types']) ) {
|
82 |
foreach($this->files_resotre as $key => $file) {
|
83 |
if (file_exists($file)) {
|
109 |
->add($commandContext)->save()
|
110 |
->execute();
|
111 |
unset($commandContext);
|
|
|
|
|
|
|
112 |
} else {
|
113 |
+
$log = str_replace("%s", $data[2], langWPADM::get('File (%s) not Exist', false) );
|
114 |
$this->setError($log);
|
115 |
WPAdm_Core::log($log);
|
116 |
break;
|
119 |
}
|
120 |
}
|
121 |
} else {
|
122 |
+
WPAdm_Core::log(langWPADM::get('Files to restore is empty', false));
|
|
|
|
|
123 |
}
|
124 |
return $this->result;
|
125 |
}
|
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()
|
@@ -11,9 +9,7 @@ if (!class_exists('WPAdm_Method_Ping')) {
|
|
11 |
if ( ! function_exists( 'get_plugins' ) ) {
|
12 |
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
13 |
}
|
14 |
-
|
15 |
-
$plugin_dir_array = explode("/", $plugin_dir );
|
16 |
-
$plugin_name = array_pop( $plugin_dir_array );
|
17 |
$plugin_name2 = str_replace("-", "_", $plugin_name);
|
18 |
$plugin = get_plugins("/$plugin_name");
|
19 |
$pl_version = "";
|
1 |
<?php
|
2 |
|
|
|
|
|
3 |
if (!class_exists('WPAdm_Method_Ping')) {
|
4 |
class WPAdm_Method_Ping extends WPAdm_Method_Class {
|
5 |
public function getResult()
|
9 |
if ( ! function_exists( 'get_plugins' ) ) {
|
10 |
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
11 |
}
|
12 |
+
$plugin_name = array_pop( explode("/", WPAdm_Core::getPluginDir()) );
|
|
|
|
|
13 |
$plugin_name2 = str_replace("-", "_", $plugin_name);
|
14 |
$plugin = get_plugins("/$plugin_name");
|
15 |
$pl_version = "";
|
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')) {
|
@@ -48,6 +46,7 @@ if (!class_exists('WPAdm_Method_Queue_Controller')) {
|
|
48 |
private $id = '';
|
49 |
|
50 |
public function __construct($params) {
|
|
|
51 |
$this->stime = time();
|
52 |
parent::__construct($params);
|
53 |
$this->queue_file = WPAdm_Core::getTmpDir() . '/' . $this->params['id'] . '.queue';
|
@@ -55,7 +54,9 @@ if (!class_exists('WPAdm_Method_Queue_Controller')) {
|
|
55 |
$this->log("queue-file not exists: {$this->queue_file}");
|
56 |
exit;
|
57 |
}
|
|
|
58 |
$queue = unserialize(file_get_contents($this->queue_file));
|
|
|
59 |
$this->id = $queue['id'];
|
60 |
$this->step = (isset($queue['step']) && (int)$queue['step'] > 1) ? (int)$queue['step']+1 : 1;
|
61 |
$this->contexts = $queue['contexts'];
|
@@ -64,24 +65,28 @@ if (!class_exists('WPAdm_Method_Queue_Controller')) {
|
|
64 |
|
65 |
public function getResult()
|
66 |
{
|
|
|
67 |
while(!$this->timeIsOver() && $context = $this->getNextContext()) {
|
68 |
$com = $context->get('command');
|
69 |
$cmd = WPAdm_Command_Factory::getCommand($com);
|
70 |
if ($cmd === null) {
|
71 |
-
$this->result->setError(
|
72 |
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
73 |
array_unshift($this->contexts, $context);
|
74 |
$this->done();
|
75 |
return $this->result;
|
76 |
} elseif (!$cmd->execute($context)) {
|
77 |
-
|
|
|
78 |
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
79 |
array_unshift($this->contexts, $context);
|
80 |
$this->done();
|
81 |
return $this->result;
|
82 |
} else {
|
83 |
-
|
|
|
84 |
}
|
|
|
85 |
}
|
86 |
|
87 |
if ($this->step >= self::MAX_COUNT_STEPS) {
|
@@ -90,7 +95,7 @@ if (!class_exists('WPAdm_Method_Queue_Controller')) {
|
|
90 |
}
|
91 |
//если еще есть невыполненые задачи - рестаратуем
|
92 |
if (!empty($this->contexts)) {
|
93 |
-
|
94 |
}
|
95 |
|
96 |
// если все задачи выполнили, то пометим файл
|
@@ -120,6 +125,7 @@ if (!class_exists('WPAdm_Method_Queue_Controller')) {
|
|
120 |
}
|
121 |
|
122 |
private function restart() {
|
|
|
123 |
$this->step ++;
|
124 |
$url = get_option('siteurl');
|
125 |
$pu = parse_url($url);
|
@@ -139,7 +145,8 @@ if (!class_exists('WPAdm_Method_Queue_Controller')) {
|
|
139 |
// $pl = (defined('WPADM_PLUGIN')) ? WPADM_PLUGIN . '_' : '';
|
140 |
$dp = explode(DIRECTORY_SEPARATOR,dirname(dirname(__FILE__)));
|
141 |
$pl = array_pop($dp) . '_';
|
142 |
-
$data =
|
|
|
143 |
fwrite($socket, "POST / HTTP/1.1\r\n");
|
144 |
fwrite($socket, "Host: {$host}\r\n");
|
145 |
|
1 |
<?php
|
|
|
|
|
|
|
2 |
/**
|
3 |
+
* Выполнение очереди
|
4 |
* Class WPAdm_Method_Exec
|
5 |
*/
|
6 |
if (!class_exists('WPAdm_Method_Queue_Controller')) {
|
46 |
private $id = '';
|
47 |
|
48 |
public function __construct($params) {
|
49 |
+
//WPAdm_Core::log("Запуск очереди. Параметры: " . print_r($params, true));
|
50 |
$this->stime = time();
|
51 |
parent::__construct($params);
|
52 |
$this->queue_file = WPAdm_Core::getTmpDir() . '/' . $this->params['id'] . '.queue';
|
54 |
$this->log("queue-file not exists: {$this->queue_file}");
|
55 |
exit;
|
56 |
}
|
57 |
+
//WPAdm_Core::log('Открываем файл очереди ' . $this->queue_file);
|
58 |
$queue = unserialize(file_get_contents($this->queue_file));
|
59 |
+
//WPAdm_Core::log(print_r($queue, true));
|
60 |
$this->id = $queue['id'];
|
61 |
$this->step = (isset($queue['step']) && (int)$queue['step'] > 1) ? (int)$queue['step']+1 : 1;
|
62 |
$this->contexts = $queue['contexts'];
|
65 |
|
66 |
public function getResult()
|
67 |
{
|
68 |
+
// пока время не закончилось и есть задачи - выполняем
|
69 |
while(!$this->timeIsOver() && $context = $this->getNextContext()) {
|
70 |
$com = $context->get('command');
|
71 |
$cmd = WPAdm_Command_Factory::getCommand($com);
|
72 |
if ($cmd === null) {
|
73 |
+
$this->result->setError('Command error: ' . $com . ' : '. 'Command not found: ' . $com);
|
74 |
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
75 |
array_unshift($this->contexts, $context);
|
76 |
$this->done();
|
77 |
return $this->result;
|
78 |
} elseif (!$cmd->execute($context)) {
|
79 |
+
//произошла какая то ошибка
|
80 |
+
$this->result->setError('Command error: ' . $com . ' : '. $context->getError());
|
81 |
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
82 |
array_unshift($this->contexts, $context);
|
83 |
$this->done();
|
84 |
return $this->result;
|
85 |
} else {
|
86 |
+
//команда выполнена успешно
|
87 |
+
//WPAdm_Core::log("Команда выполнена: {$com}");
|
88 |
}
|
89 |
+
//продолжаем работу
|
90 |
}
|
91 |
|
92 |
if ($this->step >= self::MAX_COUNT_STEPS) {
|
95 |
}
|
96 |
//если еще есть невыполненые задачи - рестаратуем
|
97 |
if (!empty($this->contexts)) {
|
98 |
+
$this->restart();
|
99 |
}
|
100 |
|
101 |
// если все задачи выполнили, то пометим файл
|
125 |
}
|
126 |
|
127 |
private function restart() {
|
128 |
+
$this->log('restart(' . $this->step .'): ' . $this->id);
|
129 |
$this->step ++;
|
130 |
$url = get_option('siteurl');
|
131 |
$pu = parse_url($url);
|
145 |
// $pl = (defined('WPADM_PLUGIN')) ? WPADM_PLUGIN . '_' : '';
|
146 |
$dp = explode(DIRECTORY_SEPARATOR,dirname(dirname(__FILE__)));
|
147 |
$pl = array_pop($dp) . '_';
|
148 |
+
// $data = 'wpadm_'.$pl.'request='.base64_encode(serialize($data));
|
149 |
+
$data = $pl.'request='.base64_encode(serialize($data));
|
150 |
fwrite($socket, "POST / HTTP/1.1\r\n");
|
151 |
fwrite($socket, "Host: {$host}\r\n");
|
152 |
|
methods/class-wpadm-method-reconnect.php
CHANGED
@@ -1,18 +1,15 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
return $this->result;
|
16 |
-
}
|
17 |
-
}
|
18 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if (!class_exists('WPAdm_Method_Reconnect')) {
|
4 |
+
class WPAdm_Method_Reconnect extends WPAdm_Method_Class {
|
5 |
+
public function getResult()
|
6 |
+
{
|
7 |
+
// обновить публичный ключ
|
8 |
+
update_option('wpadm_pub_key', $this->params['pub_key']);
|
9 |
+
|
10 |
+
$this->result->setResult(WPAdm_result::WPADM_RESULT_SUCCESS);
|
11 |
+
$this->result->setData('');
|
12 |
+
return $this->result;
|
13 |
+
}
|
14 |
+
}
|
|
|
|
|
|
|
15 |
}
|
methods/class-wpadm-method-send-to-dropbox.php
CHANGED
@@ -1,292 +1,72 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
5 |
-
|
6 |
-
|
7 |
/**
|
8 |
-
*
|
9 |
-
|
|
|
10 |
if (!class_exists('WPadm_Method_Send_To_Dropbox')) {
|
11 |
class WPadm_Method_Send_To_Dropbox extends WPAdm_Method_Class {
|
12 |
/**
|
13 |
-
|
14 |
-
|
15 |
private $queue;
|
16 |
|
17 |
private $id;
|
18 |
|
19 |
-
private $time_send = 120; // seconds for send to dropbox
|
20 |
//private $name = '';
|
21 |
|
22 |
public function getResult()
|
23 |
{
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
-
|
29 |
-
$this->result->setError('');
|
30 |
-
if ( WPAdm_Running::is_stop() ) {
|
31 |
-
if (isset($this->params['local']) && $this->params['local']) {
|
32 |
-
$params_data_cron = WPAdm_Running::getCommandResultData('local_backup');
|
33 |
-
if ( isset($res['result']) && $res['result'] == 'error' ) {
|
34 |
-
$errors[] = $res['error'];
|
35 |
-
} else {
|
36 |
-
$this->params['files'] = $params_data_cron['data'];
|
37 |
-
$this->params['access_details']['dir'] = $params_data_cron['name'];
|
38 |
-
}
|
39 |
-
}
|
40 |
-
} else {
|
41 |
-
return true;
|
42 |
-
}
|
43 |
-
if ( WPAdm_Running::is_stop() ) {
|
44 |
-
if (empty($errors)) {
|
45 |
|
46 |
-
$ad = $this->params['access_details'];
|
47 |
-
$files = $this->params['files'];
|
48 |
-
//$this->getResult()->setData($files);
|
49 |
-
//$dir = trim($dir, '/') . '/' . $this->name;
|
50 |
-
if (is_array($files)) {
|
51 |
-
$send = false;
|
52 |
-
if (!class_exists('WPAdm_Process')) {
|
53 |
-
require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-process.php';
|
54 |
-
}
|
55 |
-
WPAdm_Process::init( 'dropbox', count($files) );
|
56 |
-
WPAdm_Core::log( __('Start copy to Dropbox Cloud', 'dropbox-backup') );
|
57 |
-
foreach($files as $file) {
|
58 |
-
try {
|
59 |
-
if (isset($this->params['is_folder_set'])) {
|
60 |
-
$this->sendFileToDropbox( $file, $ad );
|
61 |
-
} else {
|
62 |
-
$this->sendFileToDropbox( ABSPATH . $file, $ad );
|
63 |
-
}
|
64 |
-
|
65 |
-
} catch (Exception $e) {
|
66 |
-
$this->result->setError( $e->getMessage() );
|
67 |
-
$this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
|
68 |
-
return $this->deleteBackup();
|
69 |
-
}
|
70 |
-
if (isset($this->params['local']) && $this->params['local']) {
|
71 |
-
$data_command = WPAdm_Running::getCommandResultData('command_dropbox');
|
72 |
-
$data_error_command = WPAdm_Running::getCommandResultData('errors_sending');
|
73 |
-
if (isset($data_error_command[ABSPATH . $file]) && $data_error_command[ABSPATH . $file]['count'] > WPADM_COUNT_LIMIT_SEND_TO_DROPBOX) {
|
74 |
-
$msg = str_replace('%file%', $file, __('Not perhaps sending file: "%file%". If you wish make upload file, increase execution time code or speed internet provider is small for upload file.' ,'dropbox-backup'));
|
75 |
-
WPAdm_Core::log( $msg );
|
76 |
-
$errors[] = $msg;
|
77 |
-
break;
|
78 |
-
}
|
79 |
-
$md5 = md5(ABSPATH . $file);
|
80 |
-
if ( !empty($data_command) && in_array($md5, $data_command) ) {
|
81 |
-
continue;
|
82 |
-
}
|
83 |
-
}
|
84 |
-
/* $commandContext = new WPAdm_Command_Context();
|
85 |
-
$commandContext->addParam('command', 'send_to_dropbox')
|
86 |
-
->addParam('key', $ad['key'])
|
87 |
-
->addParam('secret', $ad['secret'])
|
88 |
-
->addParam('token', $ad['token'])
|
89 |
-
->addParam('folder_project', $ad['folder'])
|
90 |
-
->addParam('folder', $dir)
|
91 |
-
->addParam('files', ABSPATH . $file);
|
92 |
-
if (isset($this->params['local']) && $this->params['local']) {
|
93 |
-
$commandContext->addParam('local', true);
|
94 |
-
}
|
95 |
-
$this->queue->add($commandContext);
|
96 |
-
unset($commandContext);
|
97 |
-
$send = true;
|
98 |
-
} */
|
99 |
-
}
|
100 |
-
WPAdm_Core::log( __('End Copy Files to Dropbox' ,'dropbox-backup') );
|
101 |
-
/*if (isset($res) && !$res) {
|
102 |
-
WPAdm_Core::log(__('Answer from Dropbox ' ,'dropbox-backup') . $this->queue->getError());
|
103 |
-
$errors[] = __('Answer from Dropbox ' ,'dropbox-backup') . $this->queue->getError();
|
104 |
-
} */
|
105 |
-
}
|
106 |
-
}
|
107 |
-
} else {
|
108 |
-
return true;
|
109 |
-
}
|
110 |
-
if (count($errors) > 0) {
|
111 |
-
$this->result->setError(implode("\n", $errors));
|
112 |
-
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
113 |
-
return $this->deleteBackup();
|
114 |
-
} else {
|
115 |
-
if ( WPAdm_Running::is_stop() ) {
|
116 |
-
if (class_exists('wpadm_wp_full_backup_dropbox') && !file_exists( WPAdm_Core::getTmpDir() . "/notice-star") ) {
|
117 |
-
wpadm_wp_full_backup_dropbox::setFlagToTmp( 'notice-star', time() . "_1d" );
|
118 |
-
}
|
119 |
-
if (isset($this->params['local']) && $this->params['local'] && isset($params_data_cron)) {
|
120 |
-
if ( WPAdm_Running::is_stop() ) {
|
121 |
-
$this->result->setData($this->params['files']);
|
122 |
-
$this->result->setSize($params_data_cron['size']);
|
123 |
-
$this->result->setValue('md5_data', md5 ( print_r($this->result->toArray(), 1 ) ) );
|
124 |
-
$this->result->setValue('name', $params_data_cron['name']);
|
125 |
-
$this->result->setValue('time', $params_data_cron['time']);
|
126 |
-
$this->result->setValue('type', 'dropbox');
|
127 |
-
$this->result->setValue('counts', $params_data_cron['counts'] );
|
128 |
-
if( (isset($this->params['is_local_backup']) && $this->params['is_local_backup'] == 0 ) || ( !isset($this->params['is_local_backup']) ) ) {
|
129 |
-
$backup_dir = DROPBOX_BACKUP_DIR_BACKUP;
|
130 |
-
$dropbox_options = wpadm_wp_full_backup_dropbox::getSettings();
|
131 |
-
if ($dropbox_options) {
|
132 |
-
if (isset($dropbox_options['backup_folder']) && !empty($dropbox_options['backup_folder'])) {
|
133 |
-
$backup_dir = $dropbox_options['backup_folder'];
|
134 |
-
}
|
135 |
-
}
|
136 |
-
WPAdm_Core::rmdir( $backup_dir . "/{$params_data_cron['name']}");
|
137 |
-
}
|
138 |
-
return $this->result;
|
139 |
-
} else {
|
140 |
-
return $this->result;
|
141 |
-
}
|
142 |
-
}
|
143 |
-
} else {
|
144 |
-
return $this->result;
|
145 |
-
}
|
146 |
-
}
|
147 |
-
return $this->result;
|
148 |
-
}
|
149 |
-
return true;
|
150 |
-
}
|
151 |
|
152 |
-
|
153 |
-
|
|
|
|
|
154 |
$this->id = $conf['id'];
|
155 |
$this->stime = $conf['stime'];
|
|
|
156 |
$this->type = $conf['type'];
|
157 |
}
|
158 |
-
|
159 |
-
private function sendFileToDropbox($file, $ad)
|
160 |
-
{
|
161 |
-
if ( WPAdm_Running::is_stop() ) {
|
162 |
-
require_once WPAdm_Core::getPluginDir() . '/modules/dropbox.class.php';
|
163 |
-
$command_dropbox = WPAdm_Running::getCommandResultData('command_dropbox');
|
164 |
-
$fromFile = str_replace('//', '/', $file);
|
165 |
-
$md5 = md5($fromFile);
|
166 |
-
if (in_array($md5, $command_dropbox)) {
|
167 |
-
return true;
|
168 |
-
}
|
169 |
-
WPAdm_Core::log(__('Send to dropbox files' ,'dropbox-backup') );
|
170 |
-
$dropbox = new dropbox($ad['key'], $ad['secret'], $ad['token'] );
|
171 |
-
|
172 |
-
if (!$dropbox->isAuth()) {
|
173 |
-
$this->setError( str_replace(array('%d', '%k', '%s'),
|
174 |
-
array( SITE_HOME, $ad['key'], $ad['secret'] ),__('Website "%d" can\'t authorize on Dropbox with using of "app key: %k" and "app secret: %s"' ,'dropbox-backup') ) );
|
175 |
-
return false;
|
176 |
-
}
|
177 |
-
$dir = (isset($ad['dir'])) ? $ad['dir'] : '/';
|
178 |
-
if ( WPAdm_Running::is_stop() ) {
|
179 |
-
$file_ = explode("/", $file);
|
180 |
-
$file_name = array_pop($file_);
|
181 |
-
$folder_project_temp = $ad['folder'];
|
182 |
-
$folder_project = "";
|
183 |
-
if (!empty($folder_project_temp)) {
|
184 |
-
$folder_project = $folder_project_temp . "/";
|
185 |
-
$dropbox->createDir($folder_project_temp );
|
186 |
-
$dropbox->createDir($folder_project . $dir );
|
187 |
-
} else {
|
188 |
-
$dropbox->createDir( $dir );
|
189 |
-
}
|
190 |
-
} else {
|
191 |
-
return true;
|
192 |
-
}
|
193 |
-
//$files = ''; // to comment
|
194 |
-
$fromFile = str_replace('//', '/', $file);
|
195 |
-
$toFile = str_replace('//', '/', $folder_project . $dir . '/' . $file_name);
|
196 |
-
$local = isset( $this->params['local'] ) ? $this->params['local'] : false ;
|
197 |
-
$file_dropbox = $dropbox->listing($folder_project . $dir. '/' . $file_name);
|
198 |
-
$send = true;
|
199 |
-
if ( !isset($file_dropbox['error']) ) {
|
200 |
-
if ($file_dropbox['bytes'] != filesize($fromFile)) {
|
201 |
-
if ( WPAdm_Running::is_stop() ) {
|
202 |
-
$delete_file = $dropbox->deleteFile($folder_project . $dir . '/' . $file_name);
|
203 |
-
if (isset($delete_file['error'])) {
|
204 |
-
//$this->setError( __('Dropbox returned an error during file sending: ' ,'dropbox-backup') . '"' . $delete_file['text'] . '"(d)');
|
205 |
-
//return false;
|
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($data_error_command[$fromFile])) {
|
212 |
-
$data_error_command[$fromFile]['count'] += 1;
|
213 |
-
} else {
|
214 |
-
$data_error_command[$fromFile] = array();
|
215 |
-
$data_error_command[$fromFile]['count'] = 1;
|
216 |
-
}
|
217 |
-
WPAdm_Running::setCommandResultData('errors_sending', $data_error_command);
|
218 |
-
}
|
219 |
-
} else {
|
220 |
-
$send = false;
|
221 |
-
}
|
222 |
-
}
|
223 |
-
if ( $local ) {
|
224 |
-
if ( WPAdm_Running::is_stop() ) {
|
225 |
-
$data_command = WPAdm_Running::getCommandResultData('command_dropbox');
|
226 |
-
$md5 = md5($fromFile);
|
227 |
-
if (empty($data_command) || !in_array($md5 ,$data_command) ) {
|
228 |
-
if ($send) {
|
229 |
-
$res = $dropbox->uploadFile($fromFile, $toFile, true);
|
230 |
-
} else {
|
231 |
-
$data_command = WPAdm_Running::getCommandResultData('command_dropbox');
|
232 |
-
if (!in_array($md5, $data_command)) {
|
233 |
-
$this->saveDataCommand($md5);
|
234 |
-
WPAdm_Process::setInc('dropbox', 1);
|
235 |
-
}
|
236 |
-
|
237 |
-
}
|
238 |
-
}
|
239 |
-
}
|
240 |
-
} else {
|
241 |
-
$md5 = md5($fromFile);
|
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'] . '"(u)');
|
246 |
-
return false;
|
247 |
-
}
|
248 |
-
if ( WPAdm_Running::is_stop() ) {
|
249 |
-
if (isset($res['size']) && isset($res['client_mtime'])) {
|
250 |
-
$data_command = WPAdm_Running::getCommandResultData('command_dropbox');
|
251 |
-
if (!in_array($md5, $data_command)) {
|
252 |
-
WPAdm_Core::log( __('File upload: ' ,'dropbox-backup') . basename( $file ) . __(' size: ' ,'dropbox-backup') . $res['size']);
|
253 |
-
$this->saveDataCommand($md5);
|
254 |
-
WPAdm_Process::setInc('dropbox', 1);
|
255 |
-
}
|
256 |
-
}
|
257 |
-
}
|
258 |
-
|
259 |
-
}
|
260 |
-
return true;
|
261 |
-
}
|
262 |
-
|
263 |
-
private function saveDataCommand($file)
|
264 |
-
{
|
265 |
-
$data_command = WPAdm_Running::getCommandResultData('command_dropbox');
|
266 |
-
$data_command[] = $file;
|
267 |
-
WPAdm_Running::setCommandResultData('command_dropbox', $data_command);
|
268 |
-
}
|
269 |
-
|
270 |
-
private function setError($txt = '')
|
271 |
-
{
|
272 |
-
throw new Exception($txt);
|
273 |
-
}
|
274 |
-
|
275 |
-
private function deleteBackup()
|
276 |
-
{
|
277 |
-
if( (isset($this->params['is_local_backup']) && $this->params['is_local_backup'] == 0 ) || ( !isset($this->params['is_local_backup']) ) ) {
|
278 |
-
if (isset($this->params['access_details']['dir'])) {
|
279 |
-
$backup_dir = DROPBOX_BACKUP_DIR_BACKUP;
|
280 |
-
$dropbox_options = wpadm_wp_full_backup_dropbox::getSettings();
|
281 |
-
if ($dropbox_options) {
|
282 |
-
if (isset($dropbox_options['backup_folder']) && !empty($dropbox_options['backup_folder'])) {
|
283 |
-
$backup_dir = $dropbox_options['backup_folder'];
|
284 |
-
}
|
285 |
-
}
|
286 |
-
WPAdm_Core::rmdir( $backup_dir . "/{$this->params['access_details']['dir']}");
|
287 |
-
}
|
288 |
-
}
|
289 |
-
return $this->result;
|
290 |
-
}
|
291 |
}
|
292 |
}
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
+
* Бэкап сайта
|
4 |
+
* Class WPadm_Method_Send_To_Dropbox
|
5 |
+
*/
|
6 |
if (!class_exists('WPadm_Method_Send_To_Dropbox')) {
|
7 |
class WPadm_Method_Send_To_Dropbox extends WPAdm_Method_Class {
|
8 |
/**
|
9 |
+
* @var WPAdm_Queue
|
10 |
+
*/
|
11 |
private $queue;
|
12 |
|
13 |
private $id;
|
14 |
|
|
|
15 |
//private $name = '';
|
16 |
|
17 |
public function getResult()
|
18 |
{
|
19 |
+
$errors = array();
|
20 |
+
$this->id = uniqid('wpadm_method_send_to_dropbox_');
|
21 |
+
|
22 |
+
$this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
|
23 |
+
$this->result->setError('');
|
24 |
+
|
25 |
+
$this->queue = new WPAdm_Queue($this->id);
|
26 |
+
|
27 |
+
$ad = $this->params['access_details'];
|
28 |
+
WPAdm_Core::log( langWPADM::get('Start copy to Dropbox Cloud' , false) );
|
29 |
+
$this->queue->clear();
|
30 |
+
$files = $this->params['files'];
|
31 |
+
//$this->getResult()->setData($files);
|
32 |
+
|
33 |
+
$dir = (isset($ad['dir'])) ? $ad['dir'] : '/';
|
34 |
+
//$dir = trim($dir, '/') . '/' . $this->name;
|
35 |
+
foreach($files as $file) {
|
36 |
+
$commandContext = new WPAdm_Command_Context();
|
37 |
+
$commandContext->addParam('command', 'send_to_dropbox')
|
38 |
+
->addParam('key', $ad['key'])
|
39 |
+
->addParam('secret', $ad['secret'])
|
40 |
+
->addParam('token', $ad['token'])
|
41 |
+
->addParam('folder_project',$ad['folder'])
|
42 |
+
->addParam('folder', $dir)
|
43 |
+
->addParam('files', ABSPATH . $file);
|
44 |
+
$this->queue->add($commandContext);
|
45 |
+
unset($commandContext);
|
46 |
+
}
|
47 |
+
$res = $this->queue->save()
|
48 |
+
->execute();
|
49 |
+
if (!$res) {
|
50 |
+
WPAdm_Core::log(langWPADM::get('Answer from Dropbox ' , false) . $this->queue->getError());
|
51 |
+
$errors[] = langWPADM::get('Answer from Dropbox ' , false) . $this->queue->getError();
|
52 |
+
}
|
53 |
+
WPAdm_Core::log( langWPADM::get('End Copy Files to Dropbox' , false) );
|
54 |
+
if (count($errors) > 0) {
|
55 |
+
$this->result->setError(implode("\n", $errors));
|
56 |
+
$this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
|
57 |
+
}
|
58 |
|
59 |
+
return $this->result;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
+
}
|
63 |
+
|
64 |
+
private function init(array $conf) {
|
65 |
+
//todo: нормализация
|
66 |
$this->id = $conf['id'];
|
67 |
$this->stime = $conf['stime'];
|
68 |
+
$this->queue = new WPAdm_Queue($this->id);
|
69 |
$this->type = $conf['type'];
|
70 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
}
|
72 |
}
|
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 |
|
@@ -15,10 +13,10 @@ if (!class_exists('WPAdm_Method_Update')) {
|
|
15 |
$n = count($this->params['files']);
|
16 |
for($i = 0; $i < $n; $i++) {
|
17 |
if ( ( $f = $this->dl($this->params['files'][$i]) ) === false ) {
|
18 |
-
$error[] =
|
19 |
} else {
|
20 |
if ( is_string($f) && $this->unpack($f, $this->params['files'][$i]['to']) === false ) {
|
21 |
-
$error[] =
|
22 |
}
|
23 |
if (file_exists($f)) {
|
24 |
unlink($f);
|
@@ -60,6 +58,7 @@ if (!class_exists('WPAdm_Method_Update')) {
|
|
60 |
if (!empty($d_)) {
|
61 |
//$headers = array( 'Authorization' => 'Basic ' . base64_encode( "admin24:admin24" ) );
|
62 |
$f = wp_remote_get($file['file'], array('headers' => $headers));
|
|
|
63 |
if (isset($f['body']) && !empty($f['body'])) {
|
64 |
file_put_contents($d_ . "/" . $b, $f['body']);
|
65 |
if (file_exists($d_ . "/" . $b)) {
|
1 |
<?php
|
2 |
|
|
|
|
|
3 |
if (!class_exists('WPAdm_Method_Update')) {
|
4 |
class WPAdm_Method_Update extends WPAdm_Method_Class {
|
5 |
|
13 |
$n = count($this->params['files']);
|
14 |
for($i = 0; $i < $n; $i++) {
|
15 |
if ( ( $f = $this->dl($this->params['files'][$i]) ) === false ) {
|
16 |
+
$error[] = langWPADM::get('Error to copy file ' , false) . $this->params['files'][$i]['file'];
|
17 |
} else {
|
18 |
if ( is_string($f) && $this->unpack($f, $this->params['files'][$i]['to']) === false ) {
|
19 |
+
$error[] = langWPADM::get('Error to extract file ' , false) . $f;
|
20 |
}
|
21 |
if (file_exists($f)) {
|
22 |
unlink($f);
|
58 |
if (!empty($d_)) {
|
59 |
//$headers = array( 'Authorization' => 'Basic ' . base64_encode( "admin24:admin24" ) );
|
60 |
$f = wp_remote_get($file['file'], array('headers' => $headers));
|
61 |
+
WPAdm_Core::log(serialize($f));
|
62 |
if (isset($f['body']) && !empty($f['body'])) {
|
63 |
file_put_contents($d_ . "/" . $b, $f['body']);
|
64 |
if (file_exists($d_ . "/" . $b)) {
|
modules/HttpFsockopen.php
DELETED
@@ -1,178 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
justin was here :D
|
5 |
-
*/
|
6 |
-
|
7 |
-
class HttpFsockopen {
|
8 |
-
|
9 |
-
protected $url;
|
10 |
-
protected $path;
|
11 |
-
protected $host;
|
12 |
-
protected $query;
|
13 |
-
protected $post;
|
14 |
-
protected $port;
|
15 |
-
protected $headers;
|
16 |
-
protected $ssl;
|
17 |
-
protected $method;
|
18 |
-
protected $timeout;
|
19 |
-
protected $str_headers = '';
|
20 |
-
protected $is_post = false;
|
21 |
-
|
22 |
-
protected static $autoload;
|
23 |
-
|
24 |
-
public function __construct($url, $use_autoload = true){
|
25 |
-
if(is_null(HttpFsockopen::$autoload) && $use_autoload){
|
26 |
-
HttpFsockopen::$autoload = true;
|
27 |
-
spl_autoload_register(array("HttpFsockopen", "load"));
|
28 |
-
}
|
29 |
-
$url_array = parse_url($url);
|
30 |
-
|
31 |
-
if(!empty($url_array["scheme"]) && preg_match("#^https|ssl$#i", $url_array["scheme"])){
|
32 |
-
$this -> ssl = true;
|
33 |
-
} else {
|
34 |
-
$this -> ssl = false;
|
35 |
-
}
|
36 |
-
|
37 |
-
if(empty($url_array["port"])){
|
38 |
-
if($this -> ssl){
|
39 |
-
$this -> port = 443;
|
40 |
-
} else {
|
41 |
-
$this -> port = 80;
|
42 |
-
}
|
43 |
-
}
|
44 |
-
|
45 |
-
if(array_key_exists("path", $url_array)){
|
46 |
-
$this -> path = $url_array["path"];
|
47 |
-
} else {
|
48 |
-
$this -> path = false;
|
49 |
-
}
|
50 |
-
|
51 |
-
if(array_key_exists("query", $url_array)){
|
52 |
-
$this -> query = $url_array["query"];
|
53 |
-
} else {
|
54 |
-
$this -> query = false;
|
55 |
-
}
|
56 |
-
|
57 |
-
$this -> host = $url_array["host"];
|
58 |
-
$this -> method = "GET";
|
59 |
-
$this -> timeout = 15;
|
60 |
-
$this -> is_post = false;
|
61 |
-
}
|
62 |
-
|
63 |
-
public static function load($class){
|
64 |
-
$file = dirname( __FILE__ ) . DIRECTORY_SEPARATOR .
|
65 |
-
preg_replace("#[_]+#", DIRECTORY_SEPARATOR , $class) . ".php";
|
66 |
-
if(file_exists($file))
|
67 |
-
include_once $file ;
|
68 |
-
}
|
69 |
-
|
70 |
-
public function setQueryData($data){
|
71 |
-
if(is_array($data)){
|
72 |
-
$data = http_build_query($data);
|
73 |
-
}
|
74 |
-
$this -> query = $data;
|
75 |
-
return $this;
|
76 |
-
}
|
77 |
-
|
78 |
-
public function setPostData($data){
|
79 |
-
if(is_array($data)){
|
80 |
-
$data = http_build_query($data);
|
81 |
-
}
|
82 |
-
$this -> post = $data;
|
83 |
-
$this -> method = "POST";
|
84 |
-
$this -> is_post = true;
|
85 |
-
$this -> setHeaders("Content-Type", "application/x-www-form-urlencoded");
|
86 |
-
return $this;
|
87 |
-
}
|
88 |
-
|
89 |
-
public function setMethod($method){
|
90 |
-
$previous_method = $this -> method;
|
91 |
-
if(preg_match("#^[a-z]+$#i", $method)){
|
92 |
-
$this -> method = strtoupper($method);
|
93 |
-
}
|
94 |
-
if($this -> method == "POST" && $previous_method != "POST"){
|
95 |
-
//$this -> setHeaders("Content-Type", "application/x-www-form-urlencoded");
|
96 |
-
}
|
97 |
-
if($this -> method != "POST" && $previous_method == "POST"){
|
98 |
-
$this -> setHeaders("Content-Type", null);
|
99 |
-
}
|
100 |
-
return $this;
|
101 |
-
}
|
102 |
-
|
103 |
-
public function setTimeout($timeout){
|
104 |
-
$this -> timeout = $timeout;
|
105 |
-
return $this;
|
106 |
-
}
|
107 |
-
|
108 |
-
public function setPort($port){
|
109 |
-
$this -> port = $port;
|
110 |
-
return $this;
|
111 |
-
}
|
112 |
-
|
113 |
-
public function setHeaders($key, $value = null){
|
114 |
-
if(is_array($key)){
|
115 |
-
foreach($key as $key => $value){
|
116 |
-
if(is_null($value)){
|
117 |
-
unset($this -> headers[$key]);
|
118 |
-
} else {
|
119 |
-
$this -> headers[$key] = $value;
|
120 |
-
}
|
121 |
-
}
|
122 |
-
} else {
|
123 |
-
if(is_null($value)){
|
124 |
-
unset($this -> headers[$key]);
|
125 |
-
} else {
|
126 |
-
$this -> headers[$key] = $value;
|
127 |
-
}
|
128 |
-
}
|
129 |
-
return $this;
|
130 |
-
}
|
131 |
-
|
132 |
-
public function setStrHeaders($str)
|
133 |
-
{
|
134 |
-
$this->str_headers = $str;
|
135 |
-
}
|
136 |
-
|
137 |
-
public function setUserAgent($user_agent){
|
138 |
-
return $this -> setHeaders("User-Agent", $user_agent);
|
139 |
-
}
|
140 |
-
|
141 |
-
public function exec(){
|
142 |
-
$socket = fsockopen(($this -> ssl ? "ssl://" : "") . $this -> host, $this -> port, $errno, $errstr,
|
143 |
-
$this -> timeout);
|
144 |
-
$contents = "";
|
145 |
-
|
146 |
-
if($socket){
|
147 |
-
$http = $this -> method . " ". (strlen($this -> path) ? $this -> path : "/") .
|
148 |
-
(strlen($this -> query)>0 ? "?" . $this -> query : "")
|
149 |
-
." HTTP/1.1\r\n";
|
150 |
-
$http .= "Host: ".$this -> host."\r\n";
|
151 |
-
foreach($this -> headers as $key => $value){
|
152 |
-
$http .= $key. ": ".$value."\r\n";
|
153 |
-
}
|
154 |
-
|
155 |
-
if ( $this -> is_post || $this -> method == 'GET' ) {
|
156 |
-
$http .= "Content-length: " . strlen($this -> post) . "\r\n";
|
157 |
-
$http .= "Connection: close\r\n\r\n";
|
158 |
-
}
|
159 |
-
|
160 |
-
if (!empty($this->str_headers)) {
|
161 |
-
$http .= $this->str_headers;
|
162 |
-
}
|
163 |
-
|
164 |
-
if(!is_null($this -> post)) {
|
165 |
-
$http .= $this -> post . "\r\n\r\n";
|
166 |
-
}
|
167 |
-
|
168 |
-
fwrite($socket, $http);
|
169 |
-
while (!feof($socket)) {
|
170 |
-
$contents .= fgetc($socket);
|
171 |
-
}
|
172 |
-
fclose($socket);
|
173 |
-
}
|
174 |
-
|
175 |
-
return $contents;
|
176 |
-
}
|
177 |
-
|
178 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modules/OAuthSimple.php
CHANGED
@@ -1,15 +1,15 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
* OAuthSimple - A simpler version of OAuth
|
4 |
-
*
|
5 |
-
* https://github.com/jrconlin/oauthsimple
|
6 |
-
*
|
7 |
-
* @author jr conlin <src@jrconlin.com>
|
8 |
-
* @copyright unitedHeroes.net 2011
|
9 |
-
* @version 1.3
|
10 |
-
* @license See OAuthSimple_license.txt
|
11 |
-
*
|
12 |
-
*/
|
13 |
|
14 |
class OAuthSimple {
|
15 |
private $_secrets;
|
@@ -18,168 +18,168 @@ class OAuthSimple {
|
|
18 |
private $_nonce_chars;
|
19 |
|
20 |
/**
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
function __construct ($APIKey = "", $sharedSecret=""){
|
29 |
-
|
30 |
if (!empty($APIKey))
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
if (!empty($sharedSecret))
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
$this->_default_signature_method = "HMAC-SHA1";
|
41 |
$this->_action = "GET";
|
42 |
$this->_nonce_chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
43 |
-
|
44 |
return $this;
|
45 |
}
|
46 |
-
|
47 |
/**
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
public function reset() {
|
54 |
$this->_parameters = Array();
|
55 |
$this->path = NULL;
|
56 |
$this->sbs = NULL;
|
57 |
-
|
58 |
return $this;
|
59 |
}
|
60 |
|
61 |
/**
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
public function setParameters ($parameters=Array()) {
|
69 |
-
|
70 |
if (is_string($parameters))
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
if (empty($this->_parameters))
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
else if (!empty($parameters))
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
if (empty($this->_parameters['oauth_timestamp']))
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
if (empty($this->_parameters['oauth_consumer_key']))
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
if (empty($this->_parameters['oauth_token']))
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
if (empty($this->_parameters['oauth_signature_method']))
|
99 |
-
|
100 |
$this->setSignatureMethod();
|
101 |
-
|
102 |
if (empty($this->_parameters['oauth_version']))
|
103 |
-
|
104 |
$this->_parameters['oauth_version']="1.0";
|
105 |
-
|
106 |
-
|
107 |
return $this;
|
108 |
}
|
109 |
|
110 |
/**
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
public function setQueryString ($parameters)
|
117 |
{
|
118 |
return $this->setParameters($parameters);
|
119 |
}
|
120 |
|
121 |
/**
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
public function setURL ($path)
|
128 |
-
|
129 |
if (empty($path))
|
130 |
-
|
131 |
throw new OAuthSimpleException('No path specified for OAuthSimple.setURL');
|
132 |
-
|
133 |
$this->_path=$path;
|
134 |
-
|
135 |
return $this;
|
136 |
}
|
137 |
|
138 |
/**
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
public function setPath ($path)
|
145 |
{
|
146 |
return $this->_path=$path;
|
147 |
}
|
148 |
|
149 |
/**
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
public function setAction ($action)
|
156 |
{
|
157 |
if (empty($action))
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
$action = strtoupper($action);
|
162 |
if (preg_match('/[^A-Z]/',$action))
|
163 |
-
|
164 |
throw new OAuthSimpleException('Invalid action specified for OAuthSimple.setAction');
|
165 |
-
|
166 |
$this->_action = $action;
|
167 |
-
|
168 |
return $this;
|
169 |
}
|
170 |
|
171 |
/**
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
public function signatures ($signatures)
|
178 |
{
|
179 |
if (!empty($signatures) && !is_array($signatures))
|
180 |
-
|
181 |
throw new OAuthSimpleException('Must pass dictionary array to OAuthSimple.signatures');
|
182 |
-
|
183 |
if (!empty($signatures))
|
184 |
{
|
185 |
if (empty($this->_secrets))
|
@@ -189,34 +189,34 @@ class OAuthSimple {
|
|
189 |
$this->_secrets=array_merge($this->_secrets,$signatures);
|
190 |
}
|
191 |
if (isset($this->_secrets['api_key']))
|
192 |
-
|
193 |
$this->_secrets['consumer_key'] = $this->_secrets['api_key'];
|
194 |
-
|
195 |
if (isset($this->_secrets['access_token']))
|
196 |
-
|
197 |
$this->_secrets['oauth_token'] = $this->_secrets['access_token'];
|
198 |
-
|
199 |
if (isset($this->_secrets['access_secret']))
|
200 |
-
|
201 |
$this->_secrets['oauth_secret'] = $this->_secrets['access_secret'];
|
202 |
}
|
203 |
if (isset($this->_secrets['access_token_secret']))
|
204 |
-
|
205 |
$this->_secrets['oauth_secret'] = $this->_secrets['access_token_secret'];
|
206 |
-
|
207 |
if (empty($this->_secrets['consumer_key']))
|
208 |
-
|
209 |
throw new OAuthSimpleException('Missing required consumer_key in OAuthSimple.signatures');
|
210 |
}
|
211 |
if (empty($this->_secrets['shared_secret']))
|
212 |
-
|
213 |
throw new OAuthSimpleException('Missing requires shared_secret in OAuthSimple.signatures');
|
214 |
-
|
215 |
if (!empty($this->_secrets['oauth_token']) && empty($this->_secrets['oauth_secret']))
|
216 |
-
|
217 |
throw new OAuthSimpleException('Missing oauth_secret for supplied oauth_token in OAuthSimple.signatures');
|
218 |
-
|
219 |
-
|
220 |
return $this;
|
221 |
}
|
222 |
|
@@ -226,99 +226,99 @@ class OAuthSimple {
|
|
226 |
}
|
227 |
|
228 |
/**
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
*/
|
234 |
public function setSignatureMethod ($method="")
|
235 |
-
|
236 |
if (empty($method))
|
237 |
-
|
238 |
$method = $this->_default_signature_method;
|
239 |
-
|
240 |
$method = strtoupper($method);
|
241 |
switch($method)
|
242 |
{
|
243 |
case 'PLAINTEXT':
|
244 |
case 'HMAC-SHA1':
|
245 |
$this->_parameters['oauth_signature_method']=$method;
|
246 |
-
|
247 |
default:
|
248 |
throw new OAuthSimpleException ("Unknown signing method $method specified for OAuthSimple.setSignatureMethod");
|
249 |
-
|
250 |
}
|
251 |
-
|
252 |
-
|
253 |
}
|
254 |
|
255 |
/** sign the request
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
public function sign($args=array())
|
264 |
{
|
265 |
if (!empty($args['action']))
|
266 |
-
|
267 |
$this->setAction($args['action']);
|
268 |
-
|
269 |
if (!empty($args['path']))
|
270 |
-
|
271 |
$this->setPath($args['path']);
|
272 |
}
|
273 |
if (!empty($args['method']))
|
274 |
-
|
275 |
$this->setSignatureMethod($args['method']);
|
276 |
-
|
277 |
if (!empty($args['signatures']))
|
278 |
-
|
279 |
$this->signatures($args['signatures']);
|
280 |
-
|
281 |
if (empty($args['parameters']))
|
282 |
-
|
283 |
$args['parameters']=array();
|
284 |
-
|
285 |
$this->setParameters($args['parameters']);
|
286 |
$normParams = $this->_normalizedParameters();
|
287 |
$this->_parameters['oauth_signature'] = $this->_generateSignature($normParams);
|
288 |
-
|
289 |
return Array (
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
}
|
297 |
|
298 |
/**
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
*/
|
308 |
public function getHeaderString ($args=array())
|
309 |
{
|
310 |
if (empty($this->_parameters['oauth_signature']))
|
311 |
-
|
312 |
$this->sign($args);
|
313 |
-
|
314 |
$result = 'OAuth ';
|
315 |
|
316 |
foreach ($this->_parameters as $pName => $pValue)
|
317 |
{
|
318 |
if (strpos($pName,'oauth_') !== 0 || $pName == 'oauth_token_secret2')
|
319 |
-
|
320 |
continue;
|
321 |
-
|
322 |
if (is_array($pValue))
|
323 |
{
|
324 |
foreach ($pValue as $val)
|
@@ -343,19 +343,19 @@ class OAuthSimple {
|
|
343 |
{
|
344 |
list ($key,$token) = explode('=',$element);
|
345 |
if ($token)
|
346 |
-
|
347 |
$token = urldecode($token);
|
348 |
-
|
349 |
if (!empty($result[$key]))
|
350 |
{
|
351 |
if (!is_array($result[$key]))
|
352 |
-
|
353 |
$result[$key] = array($result[$key],$token);
|
354 |
-
|
355 |
else
|
356 |
-
|
357 |
array_push($result[$key],$token);
|
358 |
-
|
359 |
}
|
360 |
else
|
361 |
$result[$key]=$token;
|
@@ -367,14 +367,14 @@ class OAuthSimple {
|
|
367 |
private static function _oauthEscape($string)
|
368 |
{
|
369 |
if ($string === 0) { return 0; }
|
370 |
-
|
371 |
if (strlen($string) == 0) { return ''; }
|
372 |
if (is_array($string)) {
|
373 |
throw new OAuthSimpleException('Array passed to _oauthEscape');
|
374 |
-
|
375 |
$string = rawurlencode($string);
|
376 |
-
|
377 |
-
|
378 |
$string = str_replace('!','%21',$string);
|
379 |
$string = str_replace('*','%2A',$string);
|
380 |
$string = str_replace('\'','%27',$string);
|
@@ -393,9 +393,9 @@ class OAuthSimple {
|
|
393 |
$rnum = rand(0,$cLength);
|
394 |
$result .= substr($this->_nonce_chars,$rnum,1);
|
395 |
}
|
396 |
-
|
397 |
$this->_parameters['oauth_nonce'] = $result;
|
398 |
-
|
399 |
return $result;
|
400 |
}
|
401 |
|
@@ -406,22 +406,22 @@ class OAuthSimple {
|
|
406 |
throw new OAuthSimpleException('No consumer_key set for OAuthSimple');
|
407 |
}
|
408 |
$this->_parameters['oauth_consumer_key']=$this->_secrets['consumer_key'];
|
409 |
-
|
410 |
return $this->_parameters['oauth_consumer_key'];
|
411 |
}
|
412 |
|
413 |
private function _getAccessToken()
|
414 |
{
|
415 |
if (!isset($this->_secrets['oauth_secret']))
|
416 |
-
|
417 |
return '';
|
418 |
-
|
419 |
if (!isset($this->_secrets['oauth_token']))
|
420 |
-
|
421 |
throw new OAuthSimpleException('No access token (oauth_token) set for OAuthSimple.');
|
422 |
-
|
423 |
$this->_parameters['oauth_token'] = $this->_secrets['oauth_token'];
|
424 |
-
|
425 |
return $this->_parameters['oauth_token'];
|
426 |
}
|
427 |
|
@@ -432,63 +432,63 @@ class OAuthSimple {
|
|
432 |
|
433 |
private function _normalizedParameters()
|
434 |
{
|
435 |
-
|
436 |
-
|
437 |
|
438 |
-
|
439 |
if (!preg_match('/\w+_secret/',$paramName) OR (strpos($paramValue, '@') !== 0 && !file_exists(substr($paramValue, 1))) )
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
}
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
}
|
477 |
|
478 |
|
479 |
private function _generateSignature ()
|
480 |
{
|
481 |
$secretKey = '';
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
$secretKey .= self::_oauthEscape($this->_secrets['oauth_secret']);
|
491 |
-
|
492 |
|
493 |
switch($this->_parameters['oauth_signature_method'])
|
494 |
{
|
@@ -500,34 +500,33 @@ class OAuthSimple {
|
|
500 |
return base64_encode(hash_hmac('sha1',$this->sbs,$secretKey,TRUE));
|
501 |
default:
|
502 |
throw new OAuthSimpleException('Unknown signature method for OAuthSimple');
|
503 |
-
|
504 |
}
|
505 |
}
|
506 |
}
|
507 |
-
if (!class_exists('OAuthSimpleException')) {
|
508 |
-
class OAuthSimpleException extends Exception {
|
509 |
-
|
510 |
-
public function __construct($err, $isDebug = FALSE)
|
511 |
-
{
|
512 |
-
self::log_error($err);
|
513 |
-
if ($isDebug)
|
514 |
-
{
|
515 |
-
self::display_error($err, TRUE);
|
516 |
-
}
|
517 |
-
}
|
518 |
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
533 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
+
* OAuthSimple - A simpler version of OAuth
|
4 |
+
*
|
5 |
+
* https://github.com/jrconlin/oauthsimple
|
6 |
+
*
|
7 |
+
* @author jr conlin <src@jrconlin.com>
|
8 |
+
* @copyright unitedHeroes.net 2011
|
9 |
+
* @version 1.3
|
10 |
+
* @license See OAuthSimple_license.txt
|
11 |
+
*
|
12 |
+
*/
|
13 |
|
14 |
class OAuthSimple {
|
15 |
private $_secrets;
|
18 |
private $_nonce_chars;
|
19 |
|
20 |
/**
|
21 |
+
* Constructor
|
22 |
+
*
|
23 |
+
* @access public
|
24 |
+
* @param api_key (String) The API Key (sometimes referred to as the consumer key) This value is usually supplied by the site you wish to use.
|
25 |
+
* @param shared_secret (String) The shared secret. This value is also usually provided by the site you wish to use.
|
26 |
+
* @return OAuthSimple (Object)
|
27 |
+
*/
|
28 |
function __construct ($APIKey = "", $sharedSecret=""){
|
29 |
+
|
30 |
if (!empty($APIKey))
|
31 |
+
{
|
32 |
+
$this->_secrets['consumer_key'] = $APIKey;
|
33 |
+
}
|
34 |
+
|
35 |
if (!empty($sharedSecret))
|
36 |
+
{
|
37 |
+
$this->_secrets['shared_secret'] = $sharedSecret;
|
38 |
+
}
|
39 |
+
|
40 |
$this->_default_signature_method = "HMAC-SHA1";
|
41 |
$this->_action = "GET";
|
42 |
$this->_nonce_chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
43 |
+
|
44 |
return $this;
|
45 |
}
|
46 |
+
|
47 |
/**
|
48 |
+
* Reset the parameters and URL
|
49 |
+
*
|
50 |
+
* @access public
|
51 |
+
* @return OAuthSimple (Object)
|
52 |
+
*/
|
53 |
public function reset() {
|
54 |
$this->_parameters = Array();
|
55 |
$this->path = NULL;
|
56 |
$this->sbs = NULL;
|
57 |
+
|
58 |
return $this;
|
59 |
}
|
60 |
|
61 |
/**
|
62 |
+
* Set the parameters either from a hash or a string
|
63 |
+
*
|
64 |
+
* @access public
|
65 |
+
* @param(string, object) List of parameters for the call, this can either be a URI string (e.g. "foo=bar&gorp=banana" or an object/hash)
|
66 |
+
* @return OAuthSimple (Object)
|
67 |
+
*/
|
68 |
public function setParameters ($parameters=Array()) {
|
69 |
+
|
70 |
if (is_string($parameters))
|
71 |
+
{
|
72 |
+
$parameters = $this->_parseParameterString($parameters);
|
73 |
+
}
|
74 |
if (empty($this->_parameters))
|
75 |
+
{
|
76 |
+
$this->_parameters = $parameters;
|
77 |
+
}
|
78 |
else if (!empty($parameters))
|
79 |
+
{
|
80 |
+
$this->_parameters = array_merge($this->_parameters,$parameters);
|
81 |
+
}
|
82 |
+
if (empty($this->_parameters['oauth_nonce']))
|
83 |
+
{
|
84 |
+
$this->_getNonce();
|
85 |
+
}
|
86 |
if (empty($this->_parameters['oauth_timestamp']))
|
87 |
+
{
|
88 |
+
$this->_getTimeStamp();
|
89 |
+
}
|
90 |
if (empty($this->_parameters['oauth_consumer_key']))
|
91 |
+
{
|
92 |
+
$this->_getApiKey();
|
93 |
+
}
|
94 |
if (empty($this->_parameters['oauth_token']))
|
95 |
+
{
|
96 |
+
$this->_getAccessToken();
|
97 |
+
}
|
98 |
if (empty($this->_parameters['oauth_signature_method']))
|
99 |
+
{
|
100 |
$this->setSignatureMethod();
|
101 |
+
}
|
102 |
if (empty($this->_parameters['oauth_version']))
|
103 |
+
{
|
104 |
$this->_parameters['oauth_version']="1.0";
|
105 |
+
}
|
106 |
+
|
107 |
return $this;
|
108 |
}
|
109 |
|
110 |
/**
|
111 |
+
* Convenience method for setParameters
|
112 |
+
*
|
113 |
+
* @access public
|
114 |
+
* @see setParameters
|
115 |
+
*/
|
116 |
public function setQueryString ($parameters)
|
117 |
{
|
118 |
return $this->setParameters($parameters);
|
119 |
}
|
120 |
|
121 |
/**
|
122 |
+
* Set the target URL (does not include the parameters)
|
123 |
+
*
|
124 |
+
* @param path (String) the fully qualified URI (excluding query arguments) (e.g "http://example.org/foo")
|
125 |
+
* @return OAuthSimple (Object)
|
126 |
+
*/
|
127 |
public function setURL ($path)
|
128 |
+
{
|
129 |
if (empty($path))
|
130 |
+
{
|
131 |
throw new OAuthSimpleException('No path specified for OAuthSimple.setURL');
|
132 |
+
}
|
133 |
$this->_path=$path;
|
134 |
+
|
135 |
return $this;
|
136 |
}
|
137 |
|
138 |
/**
|
139 |
+
* Convenience method for setURL
|
140 |
+
*
|
141 |
+
* @param path (String)
|
142 |
+
* @see setURL
|
143 |
+
*/
|
144 |
public function setPath ($path)
|
145 |
{
|
146 |
return $this->_path=$path;
|
147 |
}
|
148 |
|
149 |
/**
|
150 |
+
* Set the "action" for the url, (e.g. GET,POST, DELETE, etc.)
|
151 |
+
*
|
152 |
+
* @param action (String) HTTP Action word.
|
153 |
+
* @return OAuthSimple (Object)
|
154 |
+
*/
|
155 |
public function setAction ($action)
|
156 |
{
|
157 |
if (empty($action))
|
158 |
+
{
|
159 |
+
$action = 'GET';
|
160 |
+
}
|
161 |
$action = strtoupper($action);
|
162 |
if (preg_match('/[^A-Z]/',$action))
|
163 |
+
{
|
164 |
throw new OAuthSimpleException('Invalid action specified for OAuthSimple.setAction');
|
165 |
+
}
|
166 |
$this->_action = $action;
|
167 |
+
|
168 |
return $this;
|
169 |
}
|
170 |
|
171 |
/**
|
172 |
+
* Set the signatures (as well as validate the ones you have)
|
173 |
+
*
|
174 |
+
* @param signatures (object) object/hash of the token/signature pairs {api_key:, shared_secret:, oauth_token: oauth_secret:}
|
175 |
+
* @return OAuthSimple (Object)
|
176 |
+
*/
|
177 |
public function signatures ($signatures)
|
178 |
{
|
179 |
if (!empty($signatures) && !is_array($signatures))
|
180 |
+
{
|
181 |
throw new OAuthSimpleException('Must pass dictionary array to OAuthSimple.signatures');
|
182 |
+
}
|
183 |
if (!empty($signatures))
|
184 |
{
|
185 |
if (empty($this->_secrets))
|
189 |
$this->_secrets=array_merge($this->_secrets,$signatures);
|
190 |
}
|
191 |
if (isset($this->_secrets['api_key']))
|
192 |
+
{
|
193 |
$this->_secrets['consumer_key'] = $this->_secrets['api_key'];
|
194 |
+
}
|
195 |
if (isset($this->_secrets['access_token']))
|
196 |
+
{
|
197 |
$this->_secrets['oauth_token'] = $this->_secrets['access_token'];
|
198 |
+
}
|
199 |
if (isset($this->_secrets['access_secret']))
|
200 |
+
{
|
201 |
$this->_secrets['oauth_secret'] = $this->_secrets['access_secret'];
|
202 |
}
|
203 |
if (isset($this->_secrets['access_token_secret']))
|
204 |
+
{
|
205 |
$this->_secrets['oauth_secret'] = $this->_secrets['access_token_secret'];
|
206 |
+
}
|
207 |
if (empty($this->_secrets['consumer_key']))
|
208 |
+
{
|
209 |
throw new OAuthSimpleException('Missing required consumer_key in OAuthSimple.signatures');
|
210 |
}
|
211 |
if (empty($this->_secrets['shared_secret']))
|
212 |
+
{
|
213 |
throw new OAuthSimpleException('Missing requires shared_secret in OAuthSimple.signatures');
|
214 |
+
}
|
215 |
if (!empty($this->_secrets['oauth_token']) && empty($this->_secrets['oauth_secret']))
|
216 |
+
{
|
217 |
throw new OAuthSimpleException('Missing oauth_secret for supplied oauth_token in OAuthSimple.signatures');
|
218 |
+
}
|
219 |
+
|
220 |
return $this;
|
221 |
}
|
222 |
|
226 |
}
|
227 |
|
228 |
/**
|
229 |
+
* Set the signature method (currently only Plaintext or SHA-MAC1)
|
230 |
+
*
|
231 |
+
* @param method (String) Method of signing the transaction (only PLAINTEXT and SHA-MAC1 allowed for now)
|
232 |
+
* @return OAuthSimple (Object)
|
233 |
*/
|
234 |
public function setSignatureMethod ($method="")
|
235 |
+
{
|
236 |
if (empty($method))
|
237 |
+
{
|
238 |
$method = $this->_default_signature_method;
|
239 |
+
}
|
240 |
$method = strtoupper($method);
|
241 |
switch($method)
|
242 |
{
|
243 |
case 'PLAINTEXT':
|
244 |
case 'HMAC-SHA1':
|
245 |
$this->_parameters['oauth_signature_method']=$method;
|
246 |
+
break;
|
247 |
default:
|
248 |
throw new OAuthSimpleException ("Unknown signing method $method specified for OAuthSimple.setSignatureMethod");
|
249 |
+
break;
|
250 |
}
|
251 |
+
|
252 |
+
return $this;
|
253 |
}
|
254 |
|
255 |
/** sign the request
|
256 |
+
*
|
257 |
+
* note: all arguments are optional, provided you've set them using the
|
258 |
+
* other helper functions.
|
259 |
+
*
|
260 |
+
* @param args (Array) hash of arguments for the call {action, path, parameters (array), method, signatures (array)} all arguments are optional.
|
261 |
+
* @return (Array) signed values
|
262 |
+
*/
|
263 |
public function sign($args=array())
|
264 |
{
|
265 |
if (!empty($args['action']))
|
266 |
+
{
|
267 |
$this->setAction($args['action']);
|
268 |
+
}
|
269 |
if (!empty($args['path']))
|
270 |
+
{
|
271 |
$this->setPath($args['path']);
|
272 |
}
|
273 |
if (!empty($args['method']))
|
274 |
+
{
|
275 |
$this->setSignatureMethod($args['method']);
|
276 |
+
}
|
277 |
if (!empty($args['signatures']))
|
278 |
+
{
|
279 |
$this->signatures($args['signatures']);
|
280 |
+
}
|
281 |
if (empty($args['parameters']))
|
282 |
+
{
|
283 |
$args['parameters']=array();
|
284 |
+
}
|
285 |
$this->setParameters($args['parameters']);
|
286 |
$normParams = $this->_normalizedParameters();
|
287 |
$this->_parameters['oauth_signature'] = $this->_generateSignature($normParams);
|
288 |
+
|
289 |
return Array (
|
290 |
+
'parameters' => $this->_parameters,
|
291 |
+
'signature' => self::_oauthEscape($this->_parameters['oauth_signature']),
|
292 |
+
'signed_url' => $this->_path . '?' . $this->_normalizedParameters(),
|
293 |
+
'header' => $this->getHeaderString(),
|
294 |
+
'sbs'=> $this->sbs
|
295 |
+
);
|
296 |
}
|
297 |
|
298 |
/**
|
299 |
+
* Return a formatted "header" string
|
300 |
+
*
|
301 |
+
* NOTE: This doesn't set the "Authorization: " prefix, which is required.
|
302 |
+
* It's not set because various set header functions prefer different
|
303 |
+
* ways to do that.
|
304 |
+
*
|
305 |
+
* @param args (Array)
|
306 |
+
* @return $result (String)
|
307 |
*/
|
308 |
public function getHeaderString ($args=array())
|
309 |
{
|
310 |
if (empty($this->_parameters['oauth_signature']))
|
311 |
+
{
|
312 |
$this->sign($args);
|
313 |
+
}
|
314 |
$result = 'OAuth ';
|
315 |
|
316 |
foreach ($this->_parameters as $pName => $pValue)
|
317 |
{
|
318 |
if (strpos($pName,'oauth_') !== 0 || $pName == 'oauth_token_secret2')
|
319 |
+
{
|
320 |
continue;
|
321 |
+
}
|
322 |
if (is_array($pValue))
|
323 |
{
|
324 |
foreach ($pValue as $val)
|
343 |
{
|
344 |
list ($key,$token) = explode('=',$element);
|
345 |
if ($token)
|
346 |
+
{
|
347 |
$token = urldecode($token);
|
348 |
+
}
|
349 |
if (!empty($result[$key]))
|
350 |
{
|
351 |
if (!is_array($result[$key]))
|
352 |
+
{
|
353 |
$result[$key] = array($result[$key],$token);
|
354 |
+
}
|
355 |
else
|
356 |
+
{
|
357 |
array_push($result[$key],$token);
|
358 |
+
}
|
359 |
}
|
360 |
else
|
361 |
$result[$key]=$token;
|
367 |
private static function _oauthEscape($string)
|
368 |
{
|
369 |
if ($string === 0) { return 0; }
|
370 |
+
if ($string == '0') { return '0'; }
|
371 |
if (strlen($string) == 0) { return ''; }
|
372 |
if (is_array($string)) {
|
373 |
throw new OAuthSimpleException('Array passed to _oauthEscape');
|
374 |
+
}
|
375 |
$string = rawurlencode($string);
|
376 |
+
|
377 |
+
$string = str_replace('+','%20',$string);
|
378 |
$string = str_replace('!','%21',$string);
|
379 |
$string = str_replace('*','%2A',$string);
|
380 |
$string = str_replace('\'','%27',$string);
|
393 |
$rnum = rand(0,$cLength);
|
394 |
$result .= substr($this->_nonce_chars,$rnum,1);
|
395 |
}
|
396 |
+
$result = md5($result);
|
397 |
$this->_parameters['oauth_nonce'] = $result;
|
398 |
+
|
399 |
return $result;
|
400 |
}
|
401 |
|
406 |
throw new OAuthSimpleException('No consumer_key set for OAuthSimple');
|
407 |
}
|
408 |
$this->_parameters['oauth_consumer_key']=$this->_secrets['consumer_key'];
|
409 |
+
|
410 |
return $this->_parameters['oauth_consumer_key'];
|
411 |
}
|
412 |
|
413 |
private function _getAccessToken()
|
414 |
{
|
415 |
if (!isset($this->_secrets['oauth_secret']))
|
416 |
+
{
|
417 |
return '';
|
418 |
+
}
|
419 |
if (!isset($this->_secrets['oauth_token']))
|
420 |
+
{
|
421 |
throw new OAuthSimpleException('No access token (oauth_token) set for OAuthSimple.');
|
422 |
+
}
|
423 |
$this->_parameters['oauth_token'] = $this->_secrets['oauth_token'];
|
424 |
+
|
425 |
return $this->_parameters['oauth_token'];
|
426 |
}
|
427 |
|
432 |
|
433 |
private function _normalizedParameters()
|
434 |
{
|
435 |
+
$normalized_keys = array();
|
436 |
+
$return_array = array();
|
437 |
|
438 |
+
foreach ( $this->_parameters as $paramName=>$paramValue) {
|
439 |
if (!preg_match('/\w+_secret/',$paramName) OR (strpos($paramValue, '@') !== 0 && !file_exists(substr($paramValue, 1))) )
|
440 |
+
{
|
441 |
+
if (is_array($paramValue))
|
442 |
+
{
|
443 |
+
$normalized_keys[self::_oauthEscape($paramName)] = array();
|
444 |
+
foreach($paramValue as $item)
|
445 |
+
{
|
446 |
+
array_push($normalized_keys[self::_oauthEscape($paramName)], self::_oauthEscape($item));
|
447 |
+
}
|
448 |
+
}
|
449 |
+
else
|
450 |
+
{
|
451 |
+
$normalized_keys[self::_oauthEscape($paramName)] = self::_oauthEscape($paramValue);
|
452 |
+
}
|
453 |
+
}
|
454 |
+
}
|
455 |
+
|
456 |
+
ksort($normalized_keys);
|
457 |
+
|
458 |
+
foreach($normalized_keys as $key=>$val)
|
459 |
+
{
|
460 |
+
if (is_array($val))
|
461 |
+
{
|
462 |
+
sort($val);
|
463 |
+
foreach($val as $element)
|
464 |
+
{
|
465 |
+
array_push($return_array, $key . "=" . $element);
|
466 |
+
}
|
467 |
+
}
|
468 |
+
else
|
469 |
+
{
|
470 |
+
array_push($return_array, $key .'='. $val);
|
471 |
+
}
|
472 |
+
|
473 |
+
}
|
474 |
+
|
475 |
+
return join("&", $return_array);
|
476 |
}
|
477 |
|
478 |
|
479 |
private function _generateSignature ()
|
480 |
{
|
481 |
$secretKey = '';
|
482 |
+
if(isset($this->_secrets['shared_secret']))
|
483 |
+
{
|
484 |
+
$secretKey = self::_oauthEscape($this->_secrets['shared_secret']);
|
485 |
+
}
|
486 |
+
|
487 |
+
$secretKey .= '&';
|
488 |
+
if(isset($this->_secrets['oauth_secret']))
|
489 |
+
{
|
490 |
$secretKey .= self::_oauthEscape($this->_secrets['oauth_secret']);
|
491 |
+
}
|
492 |
|
493 |
switch($this->_parameters['oauth_signature_method'])
|
494 |
{
|
500 |
return base64_encode(hash_hmac('sha1',$this->sbs,$secretKey,TRUE));
|
501 |
default:
|
502 |
throw new OAuthSimpleException('Unknown signature method for OAuthSimple');
|
503 |
+
break;
|
504 |
}
|
505 |
}
|
506 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
507 |
|
508 |
+
class OAuthSimpleException extends Exception {
|
509 |
+
|
510 |
+
public function __construct($err, $isDebug = FALSE)
|
511 |
+
{
|
512 |
+
self::log_error($err);
|
513 |
+
if ($isDebug)
|
514 |
+
{
|
515 |
+
self::display_error($err, TRUE);
|
516 |
+
}
|
517 |
+
}
|
518 |
+
|
519 |
+
public static function log_error($err)
|
520 |
+
{
|
521 |
+
error_log($err, 0);
|
522 |
+
}
|
523 |
+
|
524 |
+
public static function display_error($err, $kill = FALSE)
|
525 |
+
{
|
526 |
+
print_r($err);
|
527 |
+
if ($kill === FALSE)
|
528 |
+
{
|
529 |
+
die();
|
530 |
+
}
|
531 |
+
}
|
532 |
}
|
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
@@ -1,500 +1,42 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
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 |
-
@ini_set("memory_limit", "256M");
|
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);
|
444 |
-
}
|
445 |
-
} else {
|
446 |
-
if ( WPAdm_Running::is_stop() ) {
|
447 |
-
$res = $this->archive->add($file, PCLZIP_OPT_REMOVE_PATH, $this->remove_path);
|
448 |
-
}
|
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);
|
456 |
-
}
|
457 |
-
$this->error = $this->archive->errorInfo(true);
|
458 |
-
return false;
|
459 |
-
}
|
460 |
-
$this->saveMd5($file);
|
461 |
-
}
|
462 |
-
}
|
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(PCLZIP_SEPARATOR, $file); {
|
483 |
-
foreach($files as $f) {
|
484 |
-
file_put_contents($this->md5_file, $f . "\t" . @md5_file($f) . "\t" . basename($this->file_zip) . "\n", FILE_APPEND);
|
485 |
-
}
|
486 |
-
}
|
487 |
-
}
|
488 |
-
}
|
489 |
-
|
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 |
}
|
1 |
+
<?php
|
2 |
+
require_once dirname(__FILE__) . '/pclzip.lib.php';
|
3 |
+
if (!class_exists('WPAdm_Archive')) {
|
4 |
+
class WPAdm_Archive {
|
5 |
+
private $remove_path = '';
|
6 |
+
private $files = array();
|
7 |
+
/**
|
8 |
+
* @var PclZip
|
9 |
+
*/
|
10 |
+
private $archive;
|
11 |
+
private $md5_file = '';
|
12 |
+
|
13 |
+
public function __construct($file, $md5_file = '') {
|
14 |
+
$this->archive = new PclZip($file);
|
15 |
+
$this->files[] = $file;
|
16 |
+
$this->md5_file = $md5_file;
|
17 |
+
}
|
18 |
+
|
19 |
+
public function add($file) {
|
20 |
+
if (empty($this->remove_path)) {
|
21 |
+
$this->archive->add($file);
|
22 |
+
} else {
|
23 |
+
$this->archive->add($file, PCLZIP_OPT_REMOVE_PATH, $this->remove_path);
|
24 |
+
}
|
25 |
+
$this->saveMd5($file);
|
26 |
+
}
|
27 |
+
|
28 |
+
protected function saveMd5($file) {
|
29 |
+
if ($this->md5_file) {
|
30 |
+
$files = explode(',', $file); {
|
31 |
+
foreach($files as $f) {
|
32 |
+
file_put_contents($this->md5_file, $f . "\t" . md5_file($f) . "\t" . basename($this->archive->zipname) . "\n", FILE_APPEND);
|
33 |
+
}
|
34 |
+
}
|
35 |
+
}
|
36 |
+
}
|
37 |
+
|
38 |
+
public function setRemovePath($remove_path) {
|
39 |
+
$this->remove_path = $remove_path;
|
40 |
+
}
|
41 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
}
|
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,42 +1,34 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
/**
|
8 |
-
*
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
if (
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
$class_name = "WPAdm_Command_{$com}";
|
36 |
-
return new $class_name();
|
37 |
-
}
|
38 |
-
|
39 |
-
return null;
|
40 |
-
}
|
41 |
-
}
|
42 |
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class WPAdm_Command_Factory
|
4 |
+
*/
|
5 |
+
if (!class_exists('WPAdm_Command_Factory')) {
|
6 |
+
class WPAdm_Command_Factory {
|
7 |
+
/**
|
8 |
+
* @param string $com
|
9 |
+
* @return command
|
10 |
+
*/
|
11 |
+
static function getCommand($com = '') {
|
12 |
+
if (!preg_match("|[a-zA-Z0-9_]|", $com)) {
|
13 |
+
return null;
|
14 |
+
}
|
15 |
+
|
16 |
+
$com = mb_strtolower($com);
|
17 |
+
$tmp = explode('_', $com);
|
18 |
+
$class_file = WPAdm_Core::getPluginDir() . "/commands/class-wpadm-command-" . str_replace('_', '-', $com) . ".php";
|
19 |
+
|
20 |
+
if (file_exists($class_file)) {
|
21 |
+
require_once $class_file;
|
22 |
+
foreach($tmp as $k=>$v) {
|
23 |
+
$tmp[$k] = ucfirst($v);
|
24 |
+
}
|
25 |
+
$com = implode('_', $tmp);
|
26 |
+
|
27 |
+
$class_name = "WPAdm_Command_{$com}";
|
28 |
+
return new $class_name();
|
29 |
+
}
|
30 |
+
|
31 |
+
return null;
|
32 |
+
}
|
33 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
}
|
modules/class-wpadm-method-class.php
DELETED
@@ -1,40 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
-
|
6 |
-
if (!class_exists('WPAdm_Method_Class')) {
|
7 |
-
abstract class WPAdm_Method_Class {
|
8 |
-
/**
|
9 |
-
* @var mixed
|
10 |
-
*/
|
11 |
-
protected $params;
|
12 |
-
|
13 |
-
/**
|
14 |
-
* @var WPAdm_result
|
15 |
-
*/
|
16 |
-
protected $result;
|
17 |
-
|
18 |
-
/**
|
19 |
-
* @param mixed $params
|
20 |
-
*/
|
21 |
-
public function __construct($params) {
|
22 |
-
$this->params = $params;
|
23 |
-
$this->result = new WPAdm_Result();
|
24 |
-
$this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
|
25 |
-
$this->result->setError('');
|
26 |
-
}
|
27 |
-
|
28 |
-
abstract function getResult();
|
29 |
-
|
30 |
-
public function isError()
|
31 |
-
{
|
32 |
-
$error = $this->result->getError();
|
33 |
-
return isset($this->result) && !empty( $error );
|
34 |
-
}
|
35 |
-
public function get_results()
|
36 |
-
{
|
37 |
-
return $this->result;
|
38 |
-
}
|
39 |
-
}
|
40 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
@@ -13,281 +8,107 @@ if (!class_exists('WPAdm_Mysqldump')) {
|
|
13 |
public $host = '';
|
14 |
public $user = '';
|
15 |
public $password = '';
|
16 |
-
public $dbh
|
17 |
-
public $rows = 1000;
|
18 |
|
19 |
private function connect($db = '') {
|
20 |
-
|
21 |
-
|
22 |
if (! class_exists('wpdb')) {
|
23 |
require_once ABSPATH . '/' . WPINC . '/wp-db.php';
|
24 |
}
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
} else {
|
30 |
-
$this->dbh = new wpdb( $this->user, $this->password, $db, $this->host );
|
31 |
-
$errors = $this->dbh->last_error;
|
32 |
-
if ($errors) {
|
33 |
-
$this->setError( __('MySQL Connect failed: ' ,'dropbox-backup') . $errors);
|
34 |
-
}
|
35 |
-
if (isset($this->dbh->error->errors) && count($this->dbh->error->errors) > 0 ) {
|
36 |
-
$error = '';
|
37 |
-
foreach($this->dbh->error->errors as $key => $err) {
|
38 |
-
if ($key === 'db_connect_fail') {
|
39 |
-
$error .= "Connect fail: Check the number of connections to the database or \n";
|
40 |
-
}
|
41 |
-
$error .= strip_tags( implode("\n", ($err) ) );
|
42 |
-
}
|
43 |
-
$this->setError( $error );
|
44 |
-
}
|
45 |
-
}
|
46 |
}
|
47 |
-
return $this->dbh;
|
48 |
}
|
49 |
|
50 |
public function optimize($db) {
|
51 |
-
$
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
61 |
} else {
|
62 |
-
|
63 |
-
|
64 |
-
$proc_data = WPAdm_Running::getCommandResultData('db');
|
65 |
-
if ( WPAdm_Running::is_stop() ) {
|
66 |
-
if (!isset($proc_data['optimize_table'][$res[0]])) {
|
67 |
-
$link->query('OPTIMIZE TABLE '. $res[0]);
|
68 |
-
if (!empty( $link->last_error ) ) {
|
69 |
-
$tables = isset($proc_data['optimize_table']) ? $proc_data['optimize_table'] : array();
|
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 during database table optimization: `%s`' ,'dropbox-backup') );
|
74 |
-
WPAdm_Core::log($log);
|
75 |
-
} else {
|
76 |
-
$log = str_replace('%s', $res[0], __('Database table optimization of `%s` was successfully' ,'dropbox-backup') );
|
77 |
-
WPAdm_Core::log($log);
|
78 |
-
WPAdm_Process::set('optimization', ( $i + 1 ) );
|
79 |
-
}
|
80 |
-
}
|
81 |
-
}
|
82 |
-
}
|
83 |
-
if ( WPAdm_Running::is_stop() ) {
|
84 |
-
WPAdm_Core::log( __('Optimization of database tables was Finished' ,'dropbox-backup') );
|
85 |
-
$proc_data = WPAdm_Running::getCommandResultData('db');
|
86 |
-
$proc_data['optimize'] = true;
|
87 |
-
WPAdm_Running::setCommandResultData('db', $proc_data);
|
88 |
-
}
|
89 |
-
}
|
90 |
-
}
|
91 |
-
}
|
92 |
-
}
|
93 |
-
public function repair($db)
|
94 |
-
{
|
95 |
-
$proc_data = WPAdm_Running::getCommandResultData('repair');
|
96 |
-
if (!isset($proc_data['work'])) {
|
97 |
-
$link = $this->connect($db);
|
98 |
-
if ( WPAdm_Running::is_stop() ) {
|
99 |
-
WPAdm_Core::log( __('Repairing of MySQL database was started' ,'dropbox-backup') );
|
100 |
-
$n = $link->query('SHOW TABLE STATUS;');
|
101 |
-
WPAdm_Process::init('repair', $n);
|
102 |
-
$result = $link->last_result;
|
103 |
-
if (!empty( $link->last_error )) {
|
104 |
-
$this->setError($link->last_error);
|
105 |
-
return false;
|
106 |
-
}
|
107 |
-
if ($link->last_result === null) {
|
108 |
-
$this->setError(print_r(implode("\n", $link->error->errors), 1));
|
109 |
-
return false;
|
110 |
-
}
|
111 |
-
$tables = array();
|
112 |
-
for($i = 0; $i < $n; $i++ ) {
|
113 |
-
if ( WPAdm_Running::is_stop() ) {
|
114 |
-
$row = get_object_vars( $result[$i] );
|
115 |
-
$tables[] = $row;
|
116 |
-
WPAdm_Core::log('Start repairing of table `' . $row['Name'] . '`' );
|
117 |
-
$res = $link->query("REPAIR TABLE {$row['Name']};");
|
118 |
-
if ($res == 1) {
|
119 |
-
$proc_data = WPAdm_Running::getCommandResultData('repair');
|
120 |
-
$proc_data['repair'][$row['Name']] = 1;
|
121 |
-
WPAdm_Running::setCommandResultData('repair', $proc_data);
|
122 |
-
} else {
|
123 |
-
$this->setError($link->last_error);
|
124 |
-
}
|
125 |
-
WPAdm_Process::set('repair', ($i + 1) );
|
126 |
-
WPAdm_Core::log('Table repairing of `' . $row['Name'] . '` was finished');
|
127 |
-
}
|
128 |
-
}
|
129 |
-
if ( WPAdm_Running::is_stop() ) {
|
130 |
-
$proc_data = WPAdm_Running::getCommandResultData('repair');
|
131 |
-
$proc_data['work'] = 1;
|
132 |
-
WPAdm_Running::setCommandResultData('repair', $proc_data);
|
133 |
}
|
134 |
}
|
|
|
135 |
}
|
136 |
-
}
|
137 |
|
138 |
-
|
139 |
-
{
|
140 |
-
$proc_data = WPAdm_Running::getCommandResultData('db');
|
141 |
-
if (!isset($proc_data['mysqldump'])) {
|
142 |
-
$link = $this->connect($db);
|
143 |
-
if ( WPAdm_Running::is_stop() ) {
|
144 |
-
WPAdm_Core::log( __('Creating of MySQL dump was started' ,'dropbox-backup') );
|
145 |
-
$tables = array();
|
146 |
-
$n = $link->query('SHOW TABLES');
|
147 |
-
WPAdm_Process::init('mysqldump', $n);
|
148 |
-
$result = $link->last_result;
|
149 |
-
if (!empty( $link->last_error )) {
|
150 |
-
$this->setError($link->last_error);
|
151 |
-
return false;
|
152 |
-
}
|
153 |
-
if ($link->last_result === null) {
|
154 |
-
/* foreach($link->error->errors as $key => $errors) {
|
155 |
-
if ($key == db_connect_fail)
|
156 |
-
}*/
|
157 |
-
$this->setError(print_r(implode("\n", $link->error->errors), 1));
|
158 |
-
return false;
|
159 |
-
}
|
160 |
-
if ( WPAdm_Running::is_stop() ) {
|
161 |
-
for($i = 0; $i < $n; $i++ ) {
|
162 |
-
$row = array_values( get_object_vars( $result[$i] ) );
|
163 |
-
$tables[] = $row[0];
|
164 |
-
}
|
165 |
-
}
|
166 |
-
if ( WPAdm_Running::is_stop() ) {
|
167 |
-
foreach($tables as $key_tables => $table) {
|
168 |
-
$return = '';
|
169 |
-
$proc_data = WPAdm_Running::getCommandResultData('db');
|
170 |
-
if ( !isset($proc_data['mysqldump_table'][$table]) ) {
|
171 |
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
$proc_data['mysqldump_table'][$table] = 1;
|
191 |
-
WPAdm_Running::setCommandResultData('db', $proc_data);
|
192 |
-
$log = str_replace('%s', $table, __('Add table "%s" to the database dump' ,'dropbox-backup') );
|
193 |
-
WPAdm_Core::log( $log );
|
194 |
-
}
|
195 |
-
}
|
196 |
-
if ( WPAdm_Running::is_stop() ) {
|
197 |
-
$while = true;
|
198 |
-
while($while) {
|
199 |
-
$insert_values = false;
|
200 |
-
if ( WPAdm_Running::is_stop() ) {
|
201 |
-
$table_db = WPAdm_Running::getCommandResultData('tabledb');
|
202 |
-
if (isset($table_db[$table])) {
|
203 |
-
if (isset($table_db[$table]['work']) && $table_db[$table]['work'] == 1) {
|
204 |
-
$from = $table_db[$table]['from']; // value from
|
205 |
-
$to = $table_db[$table]['to']; // value to
|
206 |
-
$insert_values = true;
|
207 |
-
}
|
208 |
-
} else {
|
209 |
-
$from = 0;
|
210 |
-
$to = $this->rows;
|
211 |
-
$insert_values = true;
|
212 |
-
}
|
213 |
-
}
|
214 |
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
|
237 |
-
if ($j<($rows_num-1)) { $return.= ','; }
|
238 |
-
}
|
239 |
-
$return .= ");\n";
|
240 |
-
file_put_contents($filename, $return, FILE_APPEND);
|
241 |
-
$from += 1;
|
242 |
-
$table_db = WPAdm_Running::getCommandResultData('tabledb');
|
243 |
-
$table_db[$table]['from'] = $from;
|
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 |
-
$table_db = WPAdm_Running::getCommandResultData('tabledb');
|
254 |
-
$table_db[$table]['work'] = 0;
|
255 |
-
WPAdm_Running::setCommandResultData('tabledb', $table_db);
|
256 |
-
WPAdm_Process::set('mysqldump', ( $key_tables + 1 ) );
|
257 |
-
}
|
258 |
-
}
|
259 |
-
} else {
|
260 |
-
$while = false;
|
261 |
-
if ( WPAdm_Running::is_stop() ) {
|
262 |
-
$table_db = WPAdm_Running::getCommandResultData('tabledb');
|
263 |
-
$table_db[$table]['work'] = 0;
|
264 |
-
WPAdm_Running::setCommandResultData('tabledb', $table_db);
|
265 |
-
WPAdm_Process::set('mysqldump', ( $key_tables + 1 ) );
|
266 |
-
}
|
267 |
-
}
|
268 |
-
}
|
269 |
-
}
|
270 |
-
if ( WPAdm_Running::is_stop() ) {
|
271 |
-
$proc_data = WPAdm_Running::getCommandResultData('db');
|
272 |
-
if (!isset($proc_data['mysqldump_table'][$table])) {
|
273 |
-
$return ="\n\n\n";
|
274 |
-
file_put_contents($filename, $return, FILE_APPEND);
|
275 |
-
}
|
276 |
}
|
|
|
277 |
}
|
278 |
-
|
279 |
-
if ( WPAdm_Running::is_stop() ) {
|
280 |
-
unset($link);
|
281 |
-
WPAdm_Core::log( __('Creating of MySQL database dump was finished' ,'dropbox-backup') );
|
282 |
-
$proc_data = WPAdm_Running::getCommandResultData('db');
|
283 |
-
$proc_data['mysqldump'] = true;
|
284 |
-
WPAdm_Running::setCommandResultData('db', $proc_data);
|
285 |
}
|
286 |
}
|
287 |
-
return
|
288 |
-
} else {
|
289 |
-
return false;
|
290 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
}
|
292 |
|
293 |
private function setError($txt)
|
@@ -298,11 +119,11 @@ if (!class_exists('WPAdm_Mysqldump')) {
|
|
298 |
public function restore($db, $file)
|
299 |
{
|
300 |
$link = $this->connect($db);
|
301 |
-
WPAdm_Core::log(
|
302 |
$fo = fopen($file, "r");
|
303 |
if (!$fo) {
|
304 |
-
WPAdm_Core::log(
|
305 |
-
$this->setError(
|
306 |
return false;
|
307 |
}
|
308 |
$sql = "";
|
@@ -316,14 +137,14 @@ if (!class_exists('WPAdm_Mysqldump')) {
|
|
316 |
$ress = $link->query($sql);
|
317 |
if (!empty( $link->last_error ) && $n > 0) {
|
318 |
$this->setError($link->last_error);
|
319 |
-
WPAdm_Core::log(
|
320 |
break;
|
321 |
};
|
322 |
$sql = "";
|
323 |
}
|
324 |
}
|
325 |
}
|
326 |
-
WPAdm_Core::log(
|
327 |
}
|
328 |
}
|
329 |
}
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
if (!class_exists('WPAdm_Mysqldump')) {
|
3 |
class WPAdm_Mysqldump {
|
4 |
|
8 |
public $host = '';
|
9 |
public $user = '';
|
10 |
public $password = '';
|
11 |
+
public $dbh ;
|
|
|
12 |
|
13 |
private function connect($db = '') {
|
14 |
+
WPAdm_Core::log("----------------------------------------------------");
|
15 |
+
WPAdm_Core::log( langWPADM::get('Connecting to MySQL...' , false) );
|
16 |
if (! class_exists('wpdb')) {
|
17 |
require_once ABSPATH . '/' . WPINC . '/wp-db.php';
|
18 |
}
|
19 |
+
$this->dbh = new wpdb( $this->user, $this->password, $db, $this->host );
|
20 |
+
$errors = $this->dbh->last_error;
|
21 |
+
if ($errors) {
|
22 |
+
$this->setError( langWPADM::get('MySQL Connect failed: ' , false) . $errors);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
}
|
24 |
+
return $this->dbh;
|
25 |
}
|
26 |
|
27 |
public function optimize($db) {
|
28 |
+
$link = $this->connect($db);
|
29 |
+
WPAdm_Core::log( langWPADM::get('Optimize Database Tables was started' , false) );
|
30 |
+
$n = $link->query('SHOW TABLES');
|
31 |
+
$result = $link->last_result;
|
32 |
+
if (!empty( $link->last_error ) && $n > 0) {
|
33 |
+
$this->setError($link->last_error);
|
34 |
+
} else {
|
35 |
+
for($i = 0; $i < $n; $i++ ) {
|
36 |
+
$res = array_values( get_object_vars( $result[$i] ) );
|
37 |
+
$link->query('OPTIMIZE TABLE '. $res[0]);
|
38 |
+
if (!empty( $link->last_error ) ) {
|
39 |
+
$log = str_replace('%s', $res[0], langWPADM::get('Error to Optimize Table `%s`' , false) );
|
40 |
+
WPAdm_Core::log($log);
|
41 |
} else {
|
42 |
+
$log = str_replace('%s', $res[0], langWPADM::get('Optimize Table `%s` was successfully' , false) );
|
43 |
+
WPAdm_Core::log($log);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
}
|
45 |
}
|
46 |
+
WPAdm_Core::log( langWPADM::get('Optimize Database Tables was Finished' , false) );
|
47 |
}
|
|
|
48 |
|
49 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
+
public function mysqldump($db, $filename) {
|
52 |
+
$link = $this->connect($db);
|
53 |
+
WPAdm_Core::log( langWPADM::get('MySQL of Dump was started' , false) );
|
54 |
+
$tables = array();
|
55 |
+
$n = $link->query('SHOW TABLES');
|
56 |
+
$result = $link->last_result;
|
57 |
+
if (!empty( $link->last_error ) && $n > 0) {
|
58 |
+
$this->setError($link->last_error);
|
59 |
+
}
|
60 |
+
for($i = 0; $i < $n; $i++ ) {
|
61 |
+
$row = array_values( get_object_vars( $result[$i] ) );
|
62 |
+
$tables[] = $row[0];
|
63 |
+
}
|
64 |
|
65 |
+
$return = '';
|
66 |
+
foreach($tables as $table)
|
67 |
+
{
|
68 |
+
$log = str_replace('%s', $table, langWPADM::get('Add a table "%s" in the database dump' , false) );
|
69 |
+
WPAdm_Core::log( $log );
|
70 |
+
$num_fields = $link->query('SELECT * FROM ' . $table);
|
71 |
+
$result = $link->last_result;
|
72 |
+
if (!empty( $link->last_error ) && $n > 0) {
|
73 |
+
$this->setError($link->last_error);
|
74 |
+
}
|
75 |
+
$return.= 'DROP TABLE ' . $table.';';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
+
$ress = $link->query('SHOW CREATE TABLE ' . $table);
|
78 |
+
$result2 = $link->last_result;
|
79 |
+
if (!empty( $link->last_error ) && $n > 0) {
|
80 |
+
$this->setError($link->last_error);
|
81 |
+
}
|
82 |
+
$row2 = array_values( get_object_vars( $result2[0] ) );
|
83 |
+
$return.= "\n\n".$row2[1].";\n\n";
|
84 |
+
if ($num_fields > 0) {
|
85 |
+
for ($i = 0; $i < $num_fields; $i++)
|
86 |
+
{
|
87 |
+
$row = array_values( get_object_vars( $result[$i] ) );
|
88 |
+
//WPAdm_Core::log('row' . print_r($row, 1));
|
89 |
+
$rows_num = count($row);
|
90 |
+
if ($rows_num > 0) {
|
91 |
+
$return.= 'INSERT INTO '.$table.' VALUES(';
|
92 |
+
for($j=0; $j < $rows_num; $j++)
|
93 |
+
{
|
94 |
+
$row[$j] = addslashes($row[$j]);
|
95 |
+
$row[$j] = str_replace("\n","\\n",$row[$j]);
|
96 |
+
if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
|
97 |
+
if ($j<($rows_num-1)) { $return.= ','; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
}
|
99 |
+
$return.= ");\n";
|
100 |
}
|
101 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
}
|
103 |
}
|
104 |
+
$return.="\n\n\n";
|
|
|
|
|
105 |
}
|
106 |
+
unset($link);
|
107 |
+
$handle = fopen($filename,'w+');
|
108 |
+
fwrite($handle,$return);
|
109 |
+
fclose($handle);
|
110 |
+
WPAdm_Core::log( langWPADM::get('MySQL of Dump was finished' , false) );
|
111 |
+
return true;
|
112 |
}
|
113 |
|
114 |
private function setError($txt)
|
119 |
public function restore($db, $file)
|
120 |
{
|
121 |
$link = $this->connect($db);
|
122 |
+
WPAdm_Core::log( langWPADM::get('Restore Database was started' , false) );
|
123 |
$fo = fopen($file, "r");
|
124 |
if (!$fo) {
|
125 |
+
WPAdm_Core::log( langWPADM::get('Error in open file dump' , false) );
|
126 |
+
$this->setError( langWPADM::get('Error in open file dump' , false) );
|
127 |
return false;
|
128 |
}
|
129 |
$sql = "";
|
137 |
$ress = $link->query($sql);
|
138 |
if (!empty( $link->last_error ) && $n > 0) {
|
139 |
$this->setError($link->last_error);
|
140 |
+
WPAdm_Core::log(langWPADM::get('MySQL Error: ' , false) . $link->last_error);
|
141 |
break;
|
142 |
};
|
143 |
$sql = "";
|
144 |
}
|
145 |
}
|
146 |
}
|
147 |
+
WPAdm_Core::log(langWPADM::get('Restore Database was finished' , false));
|
148 |
}
|
149 |
}
|
150 |
}
|
modules/class-wpadm-process.php
DELETED
@@ -1,100 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
-
|
5 |
-
/**
|
6 |
-
* Class WPAdm_Сommand
|
7 |
-
*/
|
8 |
-
if (!class_exists('WPAdm_Process')) {
|
9 |
-
|
10 |
-
class WPAdm_Process {
|
11 |
-
|
12 |
-
public static $processes = array('repair', 'optimization', 'mysqldump', 'archiving', 'dropbox');
|
13 |
-
|
14 |
-
private static $file_name = 'processes.data';
|
15 |
-
|
16 |
-
private static $file = '';
|
17 |
-
|
18 |
-
private static $data = array();
|
19 |
-
|
20 |
-
public static function includeCore()
|
21 |
-
{
|
22 |
-
if (!class_exists('WPAdm_Core')) {
|
23 |
-
include_once 'class-wpadm-core.php';
|
24 |
-
WPAdm_Core::$pl_dir = DRBBACKUP_BASE_DIR;
|
25 |
-
}
|
26 |
-
self::$file = WPAdm_Core::getTmpDir() . '/' . self::$file_name;
|
27 |
-
}
|
28 |
-
|
29 |
-
public static function init($process, $all)
|
30 |
-
{
|
31 |
-
self::includeCore();
|
32 |
-
|
33 |
-
if (file_exists(self::$file)) {
|
34 |
-
self::$data = wpadm_unpack( file_get_contents( self::$file ) );
|
35 |
-
}
|
36 |
-
self::$data[$process]['all'] = $all;
|
37 |
-
file_put_contents(self::$file, wpadm_pack( self::$data ) );
|
38 |
-
}
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
public static function clear()
|
43 |
-
{
|
44 |
-
self::includeCore();
|
45 |
-
if ( file_exists( self::$file ) ) {
|
46 |
-
unlink(self::$file);
|
47 |
-
}
|
48 |
-
}
|
49 |
-
|
50 |
-
public static function set($process, $count = 0)
|
51 |
-
{
|
52 |
-
self::includeCore();
|
53 |
-
if (file_exists(self::$file)) {
|
54 |
-
self::$data = wpadm_unpack( file_get_contents( self::$file ) );
|
55 |
-
}
|
56 |
-
self::$data[$process]['count'] = $count;
|
57 |
-
file_put_contents(self::$file, wpadm_pack( self::$data ) );
|
58 |
-
}
|
59 |
-
|
60 |
-
public static function setInc($process, $count = 0)
|
61 |
-
{
|
62 |
-
self::includeCore();
|
63 |
-
if (file_exists(self::$file)) {
|
64 |
-
self::$data = wpadm_unpack( file_get_contents( self::$file ) );
|
65 |
-
}
|
66 |
-
if (isset(self::$data[$process]['count'])) {
|
67 |
-
self::set($process, self::$data[$process]['count'] + $count);
|
68 |
-
} else {
|
69 |
-
self::set($process, $count);
|
70 |
-
}
|
71 |
-
}
|
72 |
-
|
73 |
-
public static function get($process)
|
74 |
-
{
|
75 |
-
self::includeCore();
|
76 |
-
if (file_exists(self::$file)) {
|
77 |
-
self::$data = wpadm_unpack( file_get_contents( self::$file ) );
|
78 |
-
}
|
79 |
-
$count = $procent = $all = 0;
|
80 |
-
if ( isset( self::$data[$process]['all'] ) && self::$data[$process]['all'] > 0 ) {
|
81 |
-
$all = self::$data[$process]['all'];
|
82 |
-
$count = isset(self::$data[$process]['count']) ? self::$data[$process]['count'] : 0;
|
83 |
-
$procent = round( ( ( $count / self::$data[$process]['all'] ) * 100 ) ) ;
|
84 |
-
}
|
85 |
-
return array('all' => $all, 'count' => $count, 'procent' => $procent);
|
86 |
-
}
|
87 |
-
|
88 |
-
public static function getAll()
|
89 |
-
{
|
90 |
-
$result = array();
|
91 |
-
$n = count(self::$processes);
|
92 |
-
for($i = 0; $i < $n; $i++) {
|
93 |
-
$result[self::$processes[$i]] = self::get( self::$processes[$i] );
|
94 |
-
}
|
95 |
-
return $result;
|
96 |
-
}
|
97 |
-
|
98 |
-
}
|
99 |
-
|
100 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
@@ -37,14 +34,11 @@ if (!class_exists('WPAdm_Queue')) {
|
|
37 |
|
38 |
private $error;
|
39 |
|
40 |
-
private $user_agent = 'dropbox-backup user-agent';
|
41 |
-
|
42 |
public function __construct($id) {
|
43 |
$this->id = $id;
|
44 |
}
|
45 |
|
46 |
public function add(WPAdm_Command_Context $context) {
|
47 |
-
|
48 |
$this->contexts[] = $context;
|
49 |
return $this;
|
50 |
}
|
@@ -70,6 +64,7 @@ if (!class_exists('WPAdm_Queue')) {
|
|
70 |
$host = $pu['host'];
|
71 |
$path = isset($pu['path']) ? $pu['path'] . "/" : "/" ;
|
72 |
|
|
|
73 |
$data = array(
|
74 |
'method' => 'queue_controller',
|
75 |
'params' => array(
|
@@ -79,11 +74,39 @@ if (!class_exists('WPAdm_Queue')) {
|
|
79 |
|
80 |
);
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
}
|
88 |
|
89 |
private function wait_result() {
|
@@ -95,33 +118,21 @@ if (!class_exists('WPAdm_Queue')) {
|
|
95 |
}
|
96 |
if (!file_exists($done_file)) {
|
97 |
$this->error = 'No result of the command';
|
|
|
98 |
} else {
|
99 |
$queue = unserialize(file_get_contents($done_file));
|
100 |
if (isset($queue['contexts'][0])) {
|
101 |
$this->error = $queue['contexts'][0]->getError();
|
|
|
102 |
}
|
103 |
}
|
104 |
if (file_exists($done_file)) {
|
105 |
unlink($done_file);
|
106 |
}
|
107 |
-
if (!empty($this->error) ) {
|
108 |
-
return false;
|
109 |
-
}
|
110 |
return true;
|
111 |
}
|
112 |
-
private function deleteCommands()
|
113 |
-
{
|
114 |
-
$files = glob(WPAdm_Core::getTmpDir() . "/wpadm_method_*");
|
115 |
-
if (!empty($files)) {
|
116 |
-
for($i = 0; $i < $n; $i++) {
|
117 |
-
WPAdm_Core::rmdir($files[$i]);
|
118 |
-
}
|
119 |
-
}
|
120 |
-
}
|
121 |
|
122 |
public function save() {
|
123 |
-
|
124 |
-
$this->deleteCommands();
|
125 |
$file = WPAdm_Core::getTmpDir() . '/' . $this->id. '.queue';
|
126 |
$txt = serialize(
|
127 |
array(
|
1 |
<?php
|
|
|
|
|
|
|
2 |
/**
|
3 |
*
|
4 |
* Class WPAdm_Queue
|
34 |
|
35 |
private $error;
|
36 |
|
|
|
|
|
37 |
public function __construct($id) {
|
38 |
$this->id = $id;
|
39 |
}
|
40 |
|
41 |
public function add(WPAdm_Command_Context $context) {
|
|
|
42 |
$this->contexts[] = $context;
|
43 |
return $this;
|
44 |
}
|
64 |
$host = $pu['host'];
|
65 |
$path = isset($pu['path']) ? $pu['path'] . "/" : "/" ;
|
66 |
|
67 |
+
//WPAdm_Core::log('execute on host ' . $host);
|
68 |
$data = array(
|
69 |
'method' => 'queue_controller',
|
70 |
'params' => array(
|
74 |
|
75 |
);
|
76 |
|
77 |
+
if (function_exists('fsockopen')) {
|
78 |
+
$socket = @fsockopen($host, 80, $errno, $errstr, 30);
|
79 |
+
$dp = explode(DIRECTORY_SEPARATOR, WPAdm_Core::$pl_dir );
|
80 |
+
$pl = array_pop($dp) . '_';
|
81 |
+
$data = $pl . 'request='.base64_encode(serialize($data));
|
82 |
+
if (!$socket) {
|
83 |
+
//WPAdm_Core::log( "$errstr ($errno) " , "socket");
|
84 |
+
$curl = curl_init($url . "/");
|
85 |
+
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
86 |
+
curl_setopt($curl, CURLOPT_POST, true);
|
87 |
+
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
88 |
+
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
|
89 |
+
$res = curl_exec($curl);
|
90 |
+
curl_close($curl);
|
91 |
+
return $this->wait_result();
|
92 |
+
}
|
93 |
+
|
94 |
+
fwrite($socket, "POST {$path} HTTP/1.1\r\n");
|
95 |
+
fwrite($socket, "Host: {$host}\r\n");
|
96 |
+
|
97 |
+
fwrite($socket,"Content-type: application/x-www-form-urlencoded\r\n");
|
98 |
+
fwrite($socket,"Content-length:".strlen($data)."\r\n");
|
99 |
+
fwrite($socket,"Accept:*/*\r\n");
|
100 |
+
fwrite($socket,"User-agent:Opera 10.00\r\n");
|
101 |
+
fwrite($socket,"Connection:Close\r\n");
|
102 |
+
fwrite($socket,"\r\n");
|
103 |
+
fwrite($socket,"$data\r\n");
|
104 |
+
fwrite($socket,"\r\n");
|
105 |
+
|
106 |
+
@sleep(1);
|
107 |
+
fclose($socket);
|
108 |
+
}
|
109 |
+
return $this->wait_result();
|
110 |
}
|
111 |
|
112 |
private function wait_result() {
|
118 |
}
|
119 |
if (!file_exists($done_file)) {
|
120 |
$this->error = 'No result of the command';
|
121 |
+
return false;
|
122 |
} else {
|
123 |
$queue = unserialize(file_get_contents($done_file));
|
124 |
if (isset($queue['contexts'][0])) {
|
125 |
$this->error = $queue['contexts'][0]->getError();
|
126 |
+
return false;
|
127 |
}
|
128 |
}
|
129 |
if (file_exists($done_file)) {
|
130 |
unlink($done_file);
|
131 |
}
|
|
|
|
|
|
|
132 |
return true;
|
133 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
public function save() {
|
|
|
|
|
136 |
$file = WPAdm_Core::getTmpDir() . '/' . $this->id. '.queue';
|
137 |
$txt = serialize(
|
138 |
array(
|
modules/class-wpadm-running.php
DELETED
@@ -1,322 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
3 |
-
|
4 |
-
/**
|
5 |
-
* Class WPAdm_Running
|
6 |
-
*/
|
7 |
-
if (!class_exists('WPAdm_Running')) {
|
8 |
-
|
9 |
-
add_action('drb_run_backup', array('wpadm_running', 'init') );
|
10 |
-
|
11 |
-
class WPAdm_Running {
|
12 |
-
|
13 |
-
private static $command_result_data = array();
|
14 |
-
private static $command_result = '';
|
15 |
-
private static $command_result_id = false;
|
16 |
-
|
17 |
-
static function init_params_default($method = true)
|
18 |
-
{
|
19 |
-
update_option(PREFIX_BACKUP_ . "_commands", array());
|
20 |
-
update_option(PREFIX_BACKUP_ . "proccess-command", array());
|
21 |
-
set_transient('drb_running', 0, 60 * 5);
|
22 |
-
$path = WPAdm_Core::getTmpDir();
|
23 |
-
if (!empty($path)) {
|
24 |
-
WPAdm_Core::rmdir($path . "/db");
|
25 |
-
WPAdm_Core::rmdir($path . "/files");
|
26 |
-
WPAdm_Core::rmdir($path . "/files2");
|
27 |
-
WPAdm_Core::rmdir($path . "/archive");
|
28 |
-
WPAdm_Core::rmdir($path . "/command_dropbox");
|
29 |
-
WPAdm_Core::rmdir($path . "/errors_sending");
|
30 |
-
WPAdm_Core::rmdir($path . "/tabledb");
|
31 |
-
WPAdm_Core::rmdir($path . "/repair");
|
32 |
-
WPAdm_Core::rmdir($path . "/restore-backup");
|
33 |
-
WPAdm_Core::rmdir($path . "/log-restore.log");
|
34 |
-
WPAdm_Core::rmdir($path . "/log-restore2");
|
35 |
-
WPAdm_Core::rmdir($path . "/md5_info-restore");
|
36 |
-
WPAdm_Core::rmdir($path . "/restore-backup");
|
37 |
-
WPAdm_Core::rmdir($path . "/files-list-retore");
|
38 |
-
WPAdm_Core::rmdir($path . "/extract-files-restore");
|
39 |
-
WPAdm_Core::rmdir($path . "/cron-restore.data");
|
40 |
-
WPAdm_Core::rmdir($path . "/stop_process");
|
41 |
-
WPAdm_Core::rmdir($path . "/folder_create");
|
42 |
-
WPAdm_Core::rmdir($path . "/drb_running");
|
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)) {
|
60 |
-
$n = count($files);
|
61 |
-
for($i = 0; $i < $n; $i++) {
|
62 |
-
WPAdm_Core::rmdir($files[$i]);
|
63 |
-
}
|
64 |
-
}
|
65 |
-
$files = glob($path ."/pclzip*.tmp");
|
66 |
-
if (!empty($files)) {
|
67 |
-
$n = count($files);
|
68 |
-
for($i = 0; $i < $n; $i++) {
|
69 |
-
WPAdm_Core::rmdir($files[$i]);
|
70 |
-
}
|
71 |
-
}
|
72 |
-
$files = glob($path ."/wpadm_method*.done");
|
73 |
-
if (!empty($files)) {
|
74 |
-
$n = count($files);
|
75 |
-
for($i = 0; $i < $n; $i++) {
|
76 |
-
WPAdm_Core::rmdir($files[$i]);
|
77 |
-
}
|
78 |
-
}
|
79 |
-
}
|
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 |
-
if (function_exists('set_time_limit')) {
|
115 |
-
//@set_time_limit(0);
|
116 |
-
}
|
117 |
-
|
118 |
-
self::run(35);
|
119 |
-
|
120 |
-
if ( self::checkLock() ) {
|
121 |
-
if ( self::is_stop() ) {
|
122 |
-
$core = new WPAdm_Core($command, 'full_backup_dropbox', DRBBACKUP_BASE_DIR);
|
123 |
-
if (!is_bool( $core->getResult() ) && is_object( $core->getResult() ) && ( $result = $core->getResult()->toArray(true) ) ) {
|
124 |
-
if ($result['result'] == 'success') {
|
125 |
-
self::delCommand($command['method']);
|
126 |
-
set_transient('drb_running', 0, 60 * 4);
|
127 |
-
self::stop();
|
128 |
-
self::setCommandResultData($command['method'], $result);
|
129 |
-
self::init();
|
130 |
-
} elseif ($result['result'] == 'error') {
|
131 |
-
self::setCommandResultData($command['method'], $result);
|
132 |
-
self::stop();
|
133 |
-
self::init_params_default();
|
134 |
-
self::createDebug( $result, $command['method'] );
|
135 |
-
}
|
136 |
-
}
|
137 |
-
}
|
138 |
-
}
|
139 |
-
}
|
140 |
-
}
|
141 |
-
|
142 |
-
public static function createDebug( $result, $type_backup = '' )
|
143 |
-
{
|
144 |
-
if (isset($result['error']) && !empty( $result['error'] ) ) {
|
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');
|
161 |
-
|
162 |
-
if ( $locked > $time + 10 * 60 ) { // 10 minutes
|
163 |
-
$locked = 0;
|
164 |
-
}
|
165 |
-
if ((defined('WP_CRON_LOCK_TIMEOUT') && $locked + WP_CRON_LOCK_TIMEOUT > $time) || (!defined('WP_CRON_LOCK_TIMEOUT') && $locked + 60 > $time)) {
|
166 |
-
return false;
|
167 |
-
}
|
168 |
-
if (function_exists('_get_cron_array')) {
|
169 |
-
$crons = _get_cron_array();
|
170 |
-
} else {
|
171 |
-
$crons = get_option('cron');
|
172 |
-
}
|
173 |
-
if (!is_array($crons)) {
|
174 |
-
return false;
|
175 |
-
}
|
176 |
-
|
177 |
-
$values = array_values( $crons );
|
178 |
-
if (isset($values['drb_run_backup'])) {
|
179 |
-
$keys = array_keys( $crons );
|
180 |
-
if ( isset($keys[0]) && $keys[0] > $time ) {
|
181 |
-
return false;
|
182 |
-
}
|
183 |
-
}
|
184 |
-
}
|
185 |
-
$time = ini_get('max_execution_time');
|
186 |
-
if ($time == 0) {
|
187 |
-
set_transient('drb_running', 1, 60 * 60 * 24); // 24 hour
|
188 |
-
} else {
|
189 |
-
set_transient('drb_running', 1, $time + 30);
|
190 |
-
}
|
191 |
-
|
192 |
-
self::setCommandResultData('start-process', time() );
|
193 |
-
return true;
|
194 |
-
}
|
195 |
-
|
196 |
-
static function is_running()
|
197 |
-
{
|
198 |
-
$running = get_transient('drb_running');
|
199 |
-
if ($running && $running == 1) {
|
200 |
-
return true;
|
201 |
-
}
|
202 |
-
return false;
|
203 |
-
}
|
204 |
-
|
205 |
-
static function is_stop()
|
206 |
-
{
|
207 |
-
$stop_precess = self::getCommandResultData('stop_process');
|
208 |
-
if ( !empty( $stop_precess ) && isset( $stop_precess['name'] ) && isset( $stop_precess['type'] ) ) {
|
209 |
-
wpadm_wp_full_backup_dropbox::delete_backup('local', $stop_precess['name']);
|
210 |
-
if ($stop_precess['type'] == 'dropbox') {
|
211 |
-
wpadm_wp_full_backup_dropbox::delete_backup('dropbox', $stop_precess['name']);
|
212 |
-
}
|
213 |
-
|
214 |
-
}
|
215 |
-
self::setCommandResultData('time_work', time());
|
216 |
-
return empty($stop_precess);
|
217 |
-
}
|
218 |
-
|
219 |
-
static function getCommand($command = '')
|
220 |
-
{
|
221 |
-
$commands = get_option(PREFIX_BACKUP_ . "_commands");
|
222 |
-
if ($commands !== false && is_array($commands) && isset($commands[0]) && empty($command) ) {
|
223 |
-
return $commands[0];
|
224 |
-
} elseif (!empty($command) && $commands !== false && is_array($commands)) {
|
225 |
-
$id = wpadm_in_array($command, 'method', $commands, true );
|
226 |
-
if (isset($commands[$id])) {
|
227 |
-
return $commands[$id];
|
228 |
-
}
|
229 |
-
}
|
230 |
-
return false;
|
231 |
-
}
|
232 |
-
static function setCommand($method, $params = array() )
|
233 |
-
{
|
234 |
-
$commands = get_option(PREFIX_BACKUP_ . "_commands");
|
235 |
-
if ( ( $commands === false ) || !wpadm_in_array($method, 'method', $commands ) ) {
|
236 |
-
$commands[] = array('method' => $method, 'params' => $params, 'work' => 0 );
|
237 |
-
update_option(PREFIX_BACKUP_ . "_commands", $commands);
|
238 |
-
}
|
239 |
-
}
|
240 |
-
static function delCommand($method)
|
241 |
-
{
|
242 |
-
$commands = get_option(PREFIX_BACKUP_ . "_commands");
|
243 |
-
if ($commands !== false && is_array($commands)) {
|
244 |
-
$id = wpadm_in_array($method, 'method', $commands, true);
|
245 |
-
unset($commands[$id]);
|
246 |
-
if (!empty($commands)) {
|
247 |
-
$commands = array_values($commands);
|
248 |
-
} else {
|
249 |
-
$commands = array();
|
250 |
-
}
|
251 |
-
update_option(PREFIX_BACKUP_ . "_commands", $commands);
|
252 |
-
}
|
253 |
-
}
|
254 |
-
|
255 |
-
static function run($time = false)
|
256 |
-
{
|
257 |
-
if ($time) {
|
258 |
-
$time = $time + time();
|
259 |
-
} else {
|
260 |
-
$time = time();
|
261 |
-
}
|
262 |
-
wp_schedule_single_event($time, 'drb_run_backup', array() );
|
263 |
-
}
|
264 |
-
|
265 |
-
static function stop()
|
266 |
-
{
|
267 |
-
wp_clear_scheduled_hook( 'drb_run_backup', array() );
|
268 |
-
}
|
269 |
-
|
270 |
-
static function setCommandResult($command, $work = false )
|
271 |
-
{
|
272 |
-
$options = get_option( PREFIX_BACKUP_ . "proccess-command" );
|
273 |
-
$id = wpadm_in_array($command, 'command', $options, true );
|
274 |
-
if ($options === false || $id === false ) {
|
275 |
-
$options[] = array('command' => $command, 'work' => 0);
|
276 |
-
self::$command_result_id = wpadm_in_array($command, 'command', $options, true );
|
277 |
-
self::$command_result_data = array();
|
278 |
-
update_option(PREFIX_BACKUP_ . "proccess-command", $options);
|
279 |
-
} else {
|
280 |
-
if ($work) {
|
281 |
-
$options[$id]['work'] = 1;
|
282 |
-
update_option(PREFIX_BACKUP_ . "proccess-command", $options);
|
283 |
-
}
|
284 |
-
}
|
285 |
-
}
|
286 |
-
|
287 |
-
static function setCommandResultData($command, $data = array())
|
288 |
-
{
|
289 |
-
$path = WPAdm_Core::getTmpDir();
|
290 |
-
file_put_contents($path ."/$command", wpadm_pack( $data ) );
|
291 |
-
}
|
292 |
-
static function delCommandResultData($command)
|
293 |
-
{
|
294 |
-
$path = WPAdm_Core::getTmpDir();
|
295 |
-
if (!empty($path)) {
|
296 |
-
WPAdm_Core::rmdir($path . "/$command");
|
297 |
-
}
|
298 |
-
}
|
299 |
-
|
300 |
-
static function getCommandResult($command)
|
301 |
-
{
|
302 |
-
$options = get_option( PREFIX_BACKUP_ . "proccess-command" );
|
303 |
-
if ($options !== false) {
|
304 |
-
$id = wpadm_in_array($command, 'command', $options, true );
|
305 |
-
if ($id !== false && $options[$id]['work'] == 1) {
|
306 |
-
return true;
|
307 |
-
}
|
308 |
-
}
|
309 |
-
return false;
|
310 |
-
}
|
311 |
-
static function getCommandResultData($command)
|
312 |
-
{
|
313 |
-
$path = WPAdm_Core::getTmpDir();
|
314 |
-
if (file_exists($path . "/$command")) {
|
315 |
-
$data = wpadm_unpack( file_get_contents( $path . "/$command" ) );
|
316 |
-
return $data;
|
317 |
-
}
|
318 |
-
|
319 |
-
return array();
|
320 |
-
}
|
321 |
-
}
|
322 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modules/constant.php
DELETED
@@ -1,65 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
if( !defined('WPADM_DIR_NAME') ) {
|
3 |
-
define('WPADM_DIR_NAME', 'wpadm_backups');
|
4 |
-
}
|
5 |
-
|
6 |
-
if( !defined('DROPBOX_BACKUP_DIR_NAME') ) {
|
7 |
-
define('DROPBOX_BACKUP_DIR_NAME', 'Dropbox_Backup');
|
8 |
-
}
|
9 |
-
|
10 |
-
if( !defined('DROPBOX_BACKUP_DIR_BACKUP') ) {
|
11 |
-
define('DROPBOX_BACKUP_DIR_BACKUP', WP_CONTENT_DIR . '/' . DROPBOX_BACKUP_DIR_NAME);
|
12 |
-
}
|
13 |
-
|
14 |
-
if (!defined('WPADM_DIR_BACKUP')) {
|
15 |
-
define('WPADM_DIR_BACKUP', WP_CONTENT_DIR . '/' . WPADM_DIR_NAME );
|
16 |
-
}
|
17 |
-
|
18 |
-
if (! defined("WPADM_URL_BASE")) {
|
19 |
-
define("WPADM_URL_BASE", 'http://secure.webpage-backup.com/');
|
20 |
-
}
|
21 |
-
if (! defined("WPADM_URL_PRO_VERSION")) {
|
22 |
-
define("WPADM_URL_PRO_VERSION", 'https://secure.wpadm.com/');
|
23 |
-
}
|
24 |
-
|
25 |
-
if (! defined("WPADM_APP_KEY")) {
|
26 |
-
define("WPADM_APP_KEY", 'nv751n84w2nif6j');
|
27 |
-
}
|
28 |
-
|
29 |
-
if (! defined("WPADM_APP_SECRET")) {
|
30 |
-
define("WPADM_APP_SECRET", 'qllasd4tbnqh4oi');
|
31 |
-
}
|
32 |
-
|
33 |
-
if (!defined("SERVER_URL_INDEX")) {
|
34 |
-
define("SERVER_URL_INDEX", "http://www.webpage-backup.com/");
|
35 |
-
}
|
36 |
-
if (!defined("PHP_VERSION_DEFAULT")) {
|
37 |
-
define("PHP_VERSION_DEFAULT", '5.2.4' );
|
38 |
-
}
|
39 |
-
if (!defined("MYSQL_VERSION_DEFAULT")) {
|
40 |
-
define("MYSQL_VERSION_DEFAULT", '5.0' );
|
41 |
-
}
|
42 |
-
|
43 |
-
if (!defined("PREFIX_BACKUP_")) {
|
44 |
-
define("PREFIX_BACKUP_", "wpadm_backup_");
|
45 |
-
}
|
46 |
-
if (!defined("WPADM_1DAY")) {
|
47 |
-
define("WPADM_1DAY", 86400); // 86400 sec = 1 day = 24 hours
|
48 |
-
}
|
49 |
-
if (!defined("WPADM_1WEEK")) {
|
50 |
-
define("WPADM_1WEEK", WPADM_1DAY * 7);
|
51 |
-
}
|
52 |
-
if (!defined("WPADM_COUNT_LIMIT_SEND_TO_DROPBOX")) {
|
53 |
-
define("WPADM_COUNT_LIMIT_SEND_TO_DROPBOX", 5);
|
54 |
-
}
|
55 |
-
|
56 |
-
if (!defined("SITE_HOME") && function_exists( 'home_url' ) ) {
|
57 |
-
define("SITE_HOME", str_ireplace( array( 'http://', 'https://' ), '', home_url() ) );
|
58 |
-
} else {
|
59 |
-
if (class_exists('dbr_database')) {
|
60 |
-
$data = dbr_database::db_get('options', array('option_value'), array('option_name' => 'home'), 1);
|
61 |
-
if (isset($data['option_value'])) {
|
62 |
-
define("SITE_HOME", str_ireplace( array( 'http://', 'https://' ), '', $data['option_value'] ) );
|
63 |
-
}
|
64 |
-
}
|
65 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modules/dropbox.class.php
CHANGED
@@ -13,15 +13,15 @@ class dropbox
|
|
13 |
private $chunk_size_mb = 50;
|
14 |
private $request_token;
|
15 |
|
16 |
-
private $api_url = "https://api.dropbox.com/1/";
|
17 |
private $api_url_content = "https://api-content.dropbox.com/1/";
|
18 |
|
19 |
|
20 |
/**
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
public function __construct ($app_key, $app_secret, $token = "")
|
26 |
{
|
27 |
$this->app_key = $app_key;
|
@@ -30,20 +30,20 @@ class dropbox
|
|
30 |
}
|
31 |
|
32 |
/**
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
public function isAuth()
|
38 |
{
|
39 |
return !empty($this->token);
|
40 |
}
|
41 |
|
42 |
/**
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
public function getRequestToken()
|
48 |
{
|
49 |
if (!$this->request_token) {
|
@@ -56,11 +56,11 @@ class dropbox
|
|
56 |
}
|
57 |
|
58 |
/**
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
public function generateAuthUrl($callback)
|
65 |
{
|
66 |
$request_token = $this->getRequestToken();
|
@@ -70,11 +70,11 @@ class dropbox
|
|
70 |
|
71 |
|
72 |
/**
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
public function getAccessToken($request_token)
|
79 |
{
|
80 |
if (!empty($this->token)) {
|
@@ -89,25 +89,25 @@ class dropbox
|
|
89 |
}
|
90 |
|
91 |
/**
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
public function deleteFile($file)
|
98 |
{
|
99 |
return $this->doApi("fileops/delete", "POST", array(
|
100 |
-
|
101 |
-
|
102 |
));
|
103 |
}
|
104 |
|
105 |
/**
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
public function deleteFiles($files = array())
|
112 |
{
|
113 |
$result = array();
|
@@ -115,8 +115,8 @@ class dropbox
|
|
115 |
foreach ($files as $file) {
|
116 |
$do = $this->deleteFile($file);
|
117 |
$result[] = array (
|
118 |
-
|
119 |
-
|
120 |
);
|
121 |
}
|
122 |
|
@@ -124,42 +124,42 @@ class dropbox
|
|
124 |
}
|
125 |
|
126 |
/**
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
public function moveFile ($from, $to)
|
134 |
{
|
135 |
return $this->doApi("fileops/move", "POST", array(
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
));
|
140 |
}
|
141 |
|
142 |
public function listing($path)
|
143 |
{
|
144 |
$dir = $this->doApi("metadata/auto/".ltrim($path, "/"), "GET", array(
|
145 |
-
|
146 |
));
|
147 |
|
148 |
if ($dir['error']) {
|
149 |
return $dir;
|
150 |
}
|
151 |
-
|
152 |
elseif (!$dir['is_dir']) {
|
153 |
return array (
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
"name" => $dir['path']
|
158 |
);
|
159 |
}
|
160 |
|
161 |
$all_size = 0;
|
162 |
$items = array();
|
|
|
163 |
foreach ($dir['contents'] as $item) {
|
164 |
if (!$item['is_dir']) {
|
165 |
switch (substr($item['size'], -2)) {
|
@@ -183,18 +183,18 @@ class dropbox
|
|
183 |
}
|
184 |
|
185 |
$items[] = array (
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
);
|
191 |
}
|
192 |
|
193 |
$dir_result = array (
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
);
|
199 |
|
200 |
return $dir_result;
|
@@ -210,23 +210,23 @@ class dropbox
|
|
210 |
if ($size < $kb) {
|
211 |
return $size.' B';
|
212 |
} else if ($size < $mb) {
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
}
|
221 |
}
|
222 |
|
223 |
/**
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
public function downloadFile($file, $server_path = "")
|
231 |
{
|
232 |
$isset = $this->listing($file);
|
@@ -244,9 +244,8 @@ class dropbox
|
|
244 |
header("Content-Transfer-Encoding: binary");
|
245 |
|
246 |
$this->doApi("files/auto/".ltrim($file, "/"), "GET", array(), array(
|
247 |
-
|
248 |
-
|
249 |
-
CURLOPT_RETURNTRANSFER => 0,
|
250 |
), TRUE);
|
251 |
exit;
|
252 |
}
|
@@ -255,16 +254,15 @@ class dropbox
|
|
255 |
//Файл недоступен для записи
|
256 |
if (!$fd = fopen($server_path, "wb")) {
|
257 |
return array (
|
258 |
-
|
259 |
-
|
260 |
);
|
261 |
}
|
262 |
|
263 |
$this->doApi("files/auto/".ltrim($file, "/"), "GET", array(), array(
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
CURLOPT_FILE => $fd
|
268 |
), TRUE);
|
269 |
|
270 |
fclose($fd);
|
@@ -279,12 +277,12 @@ class dropbox
|
|
279 |
}
|
280 |
|
281 |
/**
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
public function shareFile($file, $short_url = TRUE)
|
289 |
{
|
290 |
$result = $this->doApi("shares/auto/".ltrim($file, "/"), "POST", compact("short_url"));
|
@@ -292,12 +290,12 @@ class dropbox
|
|
292 |
}
|
293 |
|
294 |
/**
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
public function uploadFiles($files = array())
|
302 |
{
|
303 |
$result = array();
|
@@ -305,8 +303,8 @@ class dropbox
|
|
305 |
foreach ($files as $file => $dbx) {
|
306 |
$do = $this->uploadFile($file, $dbx);
|
307 |
$result[] = array (
|
308 |
-
|
309 |
-
|
310 |
);
|
311 |
}
|
312 |
|
@@ -314,13 +312,13 @@ class dropbox
|
|
314 |
}
|
315 |
|
316 |
/**
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
public function uploadFile($file_path, $dropbox_path = "", $overwrite = FALSE)
|
325 |
{
|
326 |
if (empty($dropbox_path)) {
|
@@ -329,8 +327,8 @@ class dropbox
|
|
329 |
|
330 |
if (!is_file($file_path)) {
|
331 |
return array(
|
332 |
-
|
333 |
-
|
334 |
);
|
335 |
}
|
336 |
|
@@ -340,16 +338,15 @@ class dropbox
|
|
340 |
if ($fsize/1024/1024 < $this->max_filesize_mb)
|
341 |
{
|
342 |
$result = $this->doApi("files_put/auto/".ltrim($dropbox_path, "/"),
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
TRUE);
|
353 |
|
354 |
}
|
355 |
//Файл слишком велик
|
@@ -363,17 +360,15 @@ class dropbox
|
|
363 |
$offset += $chunk;
|
364 |
|
365 |
$result = $this->doApi("chunked_upload",
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
),
|
376 |
-
TRUE);
|
377 |
|
378 |
fseek($file, $offset);
|
379 |
if($offset >= $fsize) {
|
@@ -386,10 +381,10 @@ class dropbox
|
|
386 |
}
|
387 |
|
388 |
$result = $this->doApi("commit_chunked_upload/auto/".ltrim($dropbox_path, "/"),
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
}
|
394 |
|
395 |
@fclose($file);
|
@@ -398,61 +393,73 @@ class dropbox
|
|
398 |
}
|
399 |
|
400 |
/**
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
public function createDir($path)
|
407 |
{
|
408 |
return $this->doApi("fileops/create_folder", "POST", array(
|
409 |
-
|
410 |
-
|
411 |
));
|
412 |
}
|
413 |
|
414 |
/**
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
public function accInfo()
|
420 |
{
|
421 |
return $this->doApi("account/info", "GET");
|
422 |
}
|
423 |
|
424 |
/** Запрос к API
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
private function doApi ($op, $method, $data = array(), $opts = array(), $api_content = FALSE)
|
434 |
{
|
435 |
if (($method == "GET" || $method == "PUT") && count($data)) {
|
436 |
$op .= "?".http_build_query($data);
|
437 |
}
|
438 |
-
|
439 |
$result = $this->doCurl((!$api_content ? $this->api_url : $this->api_url_content).$op, $method, $data, $opts);
|
440 |
$return = json_decode($result, TRUE);
|
441 |
return self::checkError($return);
|
442 |
}
|
443 |
|
444 |
/**
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
public function doCurl($url, $method = "POST", $data = array(), $opts = array())
|
454 |
{
|
455 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
456 |
$oauth = new OAuthSimple($this->app_key, $this->app_secret);
|
457 |
|
458 |
if (!$this->request_token && $this->token) {
|
@@ -476,141 +483,23 @@ class dropbox
|
|
476 |
}
|
477 |
|
478 |
$signed = $oauth->sign(array(
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
);
|
|
|
483 |
|
484 |
-
if (
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
CURLOPT_RETURNTRANSFER => 1,
|
491 |
-
CURLOPT_HEADER => 0,
|
492 |
-
CURLOPT_SSL_VERIFYPEER => 0,
|
493 |
-
CURLOPT_SSL_VERIFYHOST => 0,
|
494 |
-
);
|
495 |
-
|
496 |
-
if ($method == "POST") {
|
497 |
-
$opts[CURLOPT_POST] = TRUE;
|
498 |
-
$opts[CURLOPT_POSTFIELDS] = http_build_query($data);
|
499 |
-
}
|
500 |
-
|
501 |
-
//$oauth = new OAuthSimple($this->app_key, $this->app_secret);
|
502 |
-
|
503 |
-
/*if (!$this->request_token && $this->token) {
|
504 |
-
$this->request_token = $this->token;
|
505 |
-
}
|
506 |
-
|
507 |
-
if ($this->request_token) {
|
508 |
-
$oauth->setParameters(array('oauth_token' => $this->request_token['oauth_token']));
|
509 |
-
$oauth->signatures(array('oauth_secret'=> $this->request_token['oauth_token_secret']));
|
510 |
-
}
|
511 |
-
|
512 |
-
if ($method == "POST" && count($data)) {
|
513 |
-
$oauth->setParameters(http_build_query($data));
|
514 |
-
}
|
515 |
-
|
516 |
-
$path = $url;
|
517 |
-
$query = strrchr($url,'?');
|
518 |
-
if(!empty($query)) {
|
519 |
-
$oauth->setParameters(substr($query,1));
|
520 |
-
$path = substr($url, 0, -strlen($query));
|
521 |
-
}
|
522 |
|
523 |
-
$signed = $oauth->sign(array(
|
524 |
-
'action' => $method,
|
525 |
-
'path' => $path
|
526 |
-
)
|
527 |
-
); */
|
528 |
-
$opts[CURLOPT_HTTPHEADER][] = "Authorization: ".$signed['header'];
|
529 |
|
530 |
-
if ($method == "PUT") {
|
531 |
-
$opts[CURLOPT_CUSTOMREQUEST] = "PUT";
|
532 |
-
}
|
533 |
-
curl_setopt_array($ch, $opts);
|
534 |
-
$result = curl_exec($ch);
|
535 |
-
|
536 |
-
} elseif (function_exists('fsockopen')) {
|
537 |
-
include_once dirname(__FILE__) . '/HttpFsockopen.php';
|
538 |
-
$socket = new HttpFsockopen($url, false);
|
539 |
-
if ($method == 'POST') {
|
540 |
-
$socket->setPostData($data);
|
541 |
-
}
|
542 |
-
if ($method == 'PUT') {
|
543 |
-
if (isset($opts['socket']['file'])) {
|
544 |
-
$data = '';
|
545 |
-
srand( (double)microtime() * 1000000);
|
546 |
-
$file_data = join('', file( $opts['socket']['file'] ) ) ;
|
547 |
-
$rand = substr( md5( rand( 0, 32000 ) ), 0, 10);
|
548 |
-
$boundary = $rand;
|
549 |
-
$data = "";
|
550 |
-
$data .= "Content-Disposition: form-data; name=\"" . basename($opts['socket']['file']) ."\"; filename=\"" . basename( $opts['socket']['file'] ) . "\"\r\n";
|
551 |
-
$data .= "Content-Type: application/x-www-form-urlencoded;\r\n"; //multipart/form-data;
|
552 |
-
$data .= "Content-length: " . strlen($file_data) . "\r\n";
|
553 |
-
$data .= "Connection: close\r\n\r\n";
|
554 |
-
$data .= $file_data ;
|
555 |
-
$socket->setStrHeaders($data);
|
556 |
-
$socket->setMethod("PUT");
|
557 |
-
}
|
558 |
-
}
|
559 |
-
$socket->setHeaders('Authorization', $signed['header']);
|
560 |
-
$res = $socket->exec();
|
561 |
-
if ($method == 'GET') {
|
562 |
-
if (isset($opts['socket']['file_download'])) {
|
563 |
-
$r = $this->getResult($res);
|
564 |
-
if (isset($r[1])) {
|
565 |
-
file_put_contents($opts['socket']['file_download'], $r[1]);
|
566 |
-
}
|
567 |
-
}
|
568 |
-
}
|
569 |
-
if ( empty($result) ) {
|
570 |
-
$res = $this->getResult($res);
|
571 |
-
if (isset($res[1])) {
|
572 |
-
$res1 = $this->getResult($res[1], "\r", true);
|
573 |
-
preg_match("/{.*}/is", trim($res1), $r);
|
574 |
-
if(isset($r[0])) {
|
575 |
-
$result = $r[0];
|
576 |
-
} else {
|
577 |
-
$res1 = $this->getResult($res[1], "\n", true);
|
578 |
-
preg_match("/{.*}/is", trim($res1), $r);
|
579 |
-
if(isset($r[0])) {
|
580 |
-
$result = $r[0];
|
581 |
-
} else {
|
582 |
-
$res1 = $this->getResult($res[1], "\r\n", true);
|
583 |
-
preg_match("/{.*}/is", trim($res1), $r);
|
584 |
-
if(isset($r[0])) {
|
585 |
-
$result = $r[0];
|
586 |
-
}
|
587 |
-
|
588 |
-
}
|
589 |
-
}
|
590 |
-
|
591 |
-
}
|
592 |
-
}
|
593 |
-
}
|
594 |
return $result;
|
595 |
}
|
596 |
|
597 |
-
private function getResult($str, $patern = "\r\n\r\n", $is_json = false)
|
598 |
-
{
|
599 |
-
if ($is_json === false) {
|
600 |
-
return explode($patern, $str);
|
601 |
-
} else {
|
602 |
-
$res = explode($patern, $str);
|
603 |
-
$n = count($res);
|
604 |
-
$result = '';
|
605 |
-
for($i = 0; $i < $n; $i++) {
|
606 |
-
if ( preg_match_all("/[\{\"\:\,\}\s]+/is", trim($res[$i]), $r ) ) {
|
607 |
-
$result .= str_replace(array("\r", "\n"), '', $res[$i]);
|
608 |
-
}
|
609 |
-
}
|
610 |
-
return $result;
|
611 |
-
}
|
612 |
-
}
|
613 |
-
|
614 |
|
615 |
private static function checkError($return)
|
616 |
{
|
13 |
private $chunk_size_mb = 50;
|
14 |
private $request_token;
|
15 |
|
16 |
+
private $api_url = "https://api.dropbox.com/1/";
|
17 |
private $api_url_content = "https://api-content.dropbox.com/1/";
|
18 |
|
19 |
|
20 |
/**
|
21 |
+
* @param $app_key
|
22 |
+
* @param $app_secret
|
23 |
+
* @param string $token - постоянный токен
|
24 |
+
*/
|
25 |
public function __construct ($app_key, $app_secret, $token = "")
|
26 |
{
|
27 |
$this->app_key = $app_key;
|
30 |
}
|
31 |
|
32 |
/**
|
33 |
+
* Проверка на то, был ли получен постоянный токен
|
34 |
+
*
|
35 |
+
* @return bool
|
36 |
+
*/
|
37 |
public function isAuth()
|
38 |
{
|
39 |
return !empty($this->token);
|
40 |
}
|
41 |
|
42 |
/**
|
43 |
+
* Получение временного токена, необходимого для авторизации и получения токена постоянного
|
44 |
+
*
|
45 |
+
* @return mixed
|
46 |
+
*/
|
47 |
public function getRequestToken()
|
48 |
{
|
49 |
if (!$this->request_token) {
|
56 |
}
|
57 |
|
58 |
/**
|
59 |
+
* Авторизация, шаг1: Генерация ссылки для авторизации приложения
|
60 |
+
*
|
61 |
+
* @param $callback - URL для возвращения токена после авторизации
|
62 |
+
* @return string
|
63 |
+
*/
|
64 |
public function generateAuthUrl($callback)
|
65 |
{
|
66 |
$request_token = $this->getRequestToken();
|
70 |
|
71 |
|
72 |
/**
|
73 |
+
* Получение токена, необходимого для запросов к API
|
74 |
+
*
|
75 |
+
* @param $request_token - временный токен, полученный функцией getRequestToken
|
76 |
+
* @return string токен
|
77 |
+
*/
|
78 |
public function getAccessToken($request_token)
|
79 |
{
|
80 |
if (!empty($this->token)) {
|
89 |
}
|
90 |
|
91 |
/**
|
92 |
+
* Удаление файла
|
93 |
+
*
|
94 |
+
* @param $file
|
95 |
+
* @return mixed
|
96 |
+
*/
|
97 |
public function deleteFile($file)
|
98 |
{
|
99 |
return $this->doApi("fileops/delete", "POST", array(
|
100 |
+
"path" => $file,
|
101 |
+
"root" => "auto"
|
102 |
));
|
103 |
}
|
104 |
|
105 |
/**
|
106 |
+
* Удаление нескольких файлов
|
107 |
+
*
|
108 |
+
* @param array $files
|
109 |
+
* @return array
|
110 |
+
*/
|
111 |
public function deleteFiles($files = array())
|
112 |
{
|
113 |
$result = array();
|
115 |
foreach ($files as $file) {
|
116 |
$do = $this->deleteFile($file);
|
117 |
$result[] = array (
|
118 |
+
"name" => $file,
|
119 |
+
"result" => $do['error'] ? 0 : 1
|
120 |
);
|
121 |
}
|
122 |
|
124 |
}
|
125 |
|
126 |
/**
|
127 |
+
* Перемещение файлов
|
128 |
+
*
|
129 |
+
* @param $from - откуда
|
130 |
+
* @param $to - куда
|
131 |
+
* @return mixed
|
132 |
+
*/
|
133 |
public function moveFile ($from, $to)
|
134 |
{
|
135 |
return $this->doApi("fileops/move", "POST", array(
|
136 |
+
"root" => "auto",
|
137 |
+
"from_path" => $from,
|
138 |
+
"to_path" => $to
|
139 |
));
|
140 |
}
|
141 |
|
142 |
public function listing($path)
|
143 |
{
|
144 |
$dir = $this->doApi("metadata/auto/".ltrim($path, "/"), "GET", array(
|
145 |
+
"list" => TRUE
|
146 |
));
|
147 |
|
148 |
if ($dir['error']) {
|
149 |
return $dir;
|
150 |
}
|
151 |
+
//Это не папка
|
152 |
elseif (!$dir['is_dir']) {
|
153 |
return array (
|
154 |
+
"size" => $dir['size'],
|
155 |
+
"date" => $dir['modified'],
|
156 |
+
"name" => $dir['path']
|
|
|
157 |
);
|
158 |
}
|
159 |
|
160 |
$all_size = 0;
|
161 |
$items = array();
|
162 |
+
|
163 |
foreach ($dir['contents'] as $item) {
|
164 |
if (!$item['is_dir']) {
|
165 |
switch (substr($item['size'], -2)) {
|
183 |
}
|
184 |
|
185 |
$items[] = array (
|
186 |
+
"type" => $item['is_dir'] ? "dir" : "file",
|
187 |
+
"date" => $item['modified'],
|
188 |
+
"name" => basename($item['path']),
|
189 |
+
"size" => $item['size']
|
190 |
);
|
191 |
}
|
192 |
|
193 |
$dir_result = array (
|
194 |
+
"size" => $this->bite2other($all_size),
|
195 |
+
"date" => $dir['modified'],
|
196 |
+
"name" => $dir['path'],
|
197 |
+
"items" => $items
|
198 |
);
|
199 |
|
200 |
return $dir_result;
|
210 |
if ($size < $kb) {
|
211 |
return $size.' B';
|
212 |
} else if ($size < $mb) {
|
213 |
+
return round($size / $kb, 2).' KB';
|
214 |
+
} else if ($size < $gb) {
|
215 |
+
return round($size / $mb, 2).' MB';
|
216 |
+
} else if ($size < $tb) {
|
217 |
+
return round($size / $gb, 2).' GB';
|
218 |
+
} else {
|
219 |
+
return round($size / $tb, 2).' TB';
|
220 |
}
|
221 |
}
|
222 |
|
223 |
/**
|
224 |
+
* Скачивание файла
|
225 |
+
*
|
226 |
+
* @param $file
|
227 |
+
* @param $server_path - путь, куда скачать на сервер. Если задан -- вернет путь к файлу в случае успешной загрузки.
|
228 |
+
* @return array
|
229 |
+
*/
|
230 |
public function downloadFile($file, $server_path = "")
|
231 |
{
|
232 |
$isset = $this->listing($file);
|
244 |
header("Content-Transfer-Encoding: binary");
|
245 |
|
246 |
$this->doApi("files/auto/".ltrim($file, "/"), "GET", array(), array(
|
247 |
+
CURLOPT_BINARYTRANSFER => 1,
|
248 |
+
CURLOPT_RETURNTRANSFER => 0,
|
|
|
249 |
), TRUE);
|
250 |
exit;
|
251 |
}
|
254 |
//Файл недоступен для записи
|
255 |
if (!$fd = fopen($server_path, "wb")) {
|
256 |
return array (
|
257 |
+
"error" => 1,
|
258 |
+
"text" => "File '".$server_path."' not writable"
|
259 |
);
|
260 |
}
|
261 |
|
262 |
$this->doApi("files/auto/".ltrim($file, "/"), "GET", array(), array(
|
263 |
+
CURLOPT_BINARYTRANSFER => 1,
|
264 |
+
CURLOPT_RETURNTRANSFER => 1,
|
265 |
+
CURLOPT_FILE => $fd
|
|
|
266 |
), TRUE);
|
267 |
|
268 |
fclose($fd);
|
277 |
}
|
278 |
|
279 |
/**
|
280 |
+
* Поделиться файлом
|
281 |
+
*
|
282 |
+
* @param $file
|
283 |
+
* @param bool $short_url - короткая ссылка
|
284 |
+
* @return mixed
|
285 |
+
*/
|
286 |
public function shareFile($file, $short_url = TRUE)
|
287 |
{
|
288 |
$result = $this->doApi("shares/auto/".ltrim($file, "/"), "POST", compact("short_url"));
|
290 |
}
|
291 |
|
292 |
/**
|
293 |
+
* Загрузка нескольких файлов
|
294 |
+
*
|
295 |
+
* @param $files - массив формата файл_на_сервере => файл_в_дропбоксе
|
296 |
+
*
|
297 |
+
* @return array - информация о списке файлов
|
298 |
+
*/
|
299 |
public function uploadFiles($files = array())
|
300 |
{
|
301 |
$result = array();
|
303 |
foreach ($files as $file => $dbx) {
|
304 |
$do = $this->uploadFile($file, $dbx);
|
305 |
$result[] = array (
|
306 |
+
"name" => $file,
|
307 |
+
"result" => $do['error'] ? 0 : 1
|
308 |
);
|
309 |
}
|
310 |
|
312 |
}
|
313 |
|
314 |
/**
|
315 |
+
* Загрузка файла
|
316 |
+
*
|
317 |
+
* @param $file_path - путь к файлу на сервере
|
318 |
+
* @param $dropbox_path - куда загружать, если не задан, будет загружен в корень дропбокса с таким же именем
|
319 |
+
* @param bool $overwrite - заменять ли файлы со схожими именами
|
320 |
+
* @return mixed
|
321 |
+
*/
|
322 |
public function uploadFile($file_path, $dropbox_path = "", $overwrite = FALSE)
|
323 |
{
|
324 |
if (empty($dropbox_path)) {
|
327 |
|
328 |
if (!is_file($file_path)) {
|
329 |
return array(
|
330 |
+
"error" => 1,
|
331 |
+
"text" => "File '".$file_path."' not found."
|
332 |
);
|
333 |
}
|
334 |
|
338 |
if ($fsize/1024/1024 < $this->max_filesize_mb)
|
339 |
{
|
340 |
$result = $this->doApi("files_put/auto/".ltrim($dropbox_path, "/"),
|
341 |
+
"PUT",
|
342 |
+
compact ("overwrite"),
|
343 |
+
array(
|
344 |
+
CURLOPT_INFILE => $file,
|
345 |
+
CURLOPT_INFILESIZE => filesize($file_path),
|
346 |
+
CURLOPT_BINARYTRANSFER => 1,
|
347 |
+
CURLOPT_PUT => 1
|
348 |
+
),
|
349 |
+
TRUE);
|
|
|
350 |
|
351 |
}
|
352 |
//Файл слишком велик
|
360 |
$offset += $chunk;
|
361 |
|
362 |
$result = $this->doApi("chunked_upload",
|
363 |
+
"PUT",
|
364 |
+
compact("upload_id", "offset"),
|
365 |
+
array(
|
366 |
+
CURLOPT_INFILE => $file,
|
367 |
+
CURLOPT_INFILESIZE => $chunk,
|
368 |
+
CURLOPT_BINARYTRANSFER => 1,
|
369 |
+
CURLOPT_PUT => 1
|
370 |
+
),
|
371 |
+
TRUE);
|
|
|
|
|
372 |
|
373 |
fseek($file, $offset);
|
374 |
if($offset >= $fsize) {
|
381 |
}
|
382 |
|
383 |
$result = $this->doApi("commit_chunked_upload/auto/".ltrim($dropbox_path, "/"),
|
384 |
+
"POST",
|
385 |
+
compact("upload_id", "overwrite"),
|
386 |
+
array(),
|
387 |
+
TRUE);
|
388 |
}
|
389 |
|
390 |
@fclose($file);
|
393 |
}
|
394 |
|
395 |
/**
|
396 |
+
* Создание директории
|
397 |
+
*
|
398 |
+
* @param $path
|
399 |
+
* @return mixed
|
400 |
+
*/
|
401 |
public function createDir($path)
|
402 |
{
|
403 |
return $this->doApi("fileops/create_folder", "POST", array(
|
404 |
+
"root" => "auto",
|
405 |
+
"path" => $path
|
406 |
));
|
407 |
}
|
408 |
|
409 |
/**
|
410 |
+
* Информация об аккаунте
|
411 |
+
*
|
412 |
+
* @return mixed
|
413 |
+
*/
|
414 |
public function accInfo()
|
415 |
{
|
416 |
return $this->doApi("account/info", "GET");
|
417 |
}
|
418 |
|
419 |
/** Запрос к API
|
420 |
+
*
|
421 |
+
* @param $op - операция (url)
|
422 |
+
* @param $method - post/get
|
423 |
+
* @param array $data - доп. данные, url запрос
|
424 |
+
* @param array $opts - доп. параметры для curl
|
425 |
+
* @param $api_content - использовать url для загрузки файлов
|
426 |
+
* @return mixed
|
427 |
+
*/
|
428 |
private function doApi ($op, $method, $data = array(), $opts = array(), $api_content = FALSE)
|
429 |
{
|
430 |
if (($method == "GET" || $method == "PUT") && count($data)) {
|
431 |
$op .= "?".http_build_query($data);
|
432 |
}
|
|
|
433 |
$result = $this->doCurl((!$api_content ? $this->api_url : $this->api_url_content).$op, $method, $data, $opts);
|
434 |
$return = json_decode($result, TRUE);
|
435 |
return self::checkError($return);
|
436 |
}
|
437 |
|
438 |
/**
|
439 |
+
* Обертка для отправки подписанного запроса через curl
|
440 |
+
*
|
441 |
+
* @param $url
|
442 |
+
* @param string $method
|
443 |
+
* @param array $data - POST данные
|
444 |
+
* @param $opts - доп. параметры для curl
|
445 |
+
* @return mixed
|
446 |
+
*/
|
447 |
public function doCurl($url, $method = "POST", $data = array(), $opts = array())
|
448 |
{
|
449 |
+
$ch = curl_init($url);
|
450 |
+
$opts += array(
|
451 |
+
CURLOPT_RETURNTRANSFER => 1,
|
452 |
+
CURLOPT_HEADER => 0,
|
453 |
+
CURLOPT_SSL_VERIFYPEER => 0,
|
454 |
+
CURLOPT_SSL_VERIFYHOST => 0,
|
455 |
+
);
|
456 |
+
|
457 |
+
|
458 |
+
if ($method == "POST") {
|
459 |
+
$opts[CURLOPT_POST] = TRUE;
|
460 |
+
$opts[CURLOPT_POSTFIELDS] = http_build_query($data);
|
461 |
+
}
|
462 |
+
|
463 |
$oauth = new OAuthSimple($this->app_key, $this->app_secret);
|
464 |
|
465 |
if (!$this->request_token && $this->token) {
|
483 |
}
|
484 |
|
485 |
$signed = $oauth->sign(array(
|
486 |
+
'action' => $method,
|
487 |
+
'path' => $path
|
488 |
+
)
|
489 |
);
|
490 |
+
$opts[CURLOPT_HTTPHEADER][] = "Authorization: ".$signed['header'];
|
491 |
|
492 |
+
if ($method == "PUT")
|
493 |
+
{
|
494 |
+
$opts[CURLOPT_CUSTOMREQUEST] = "PUT";
|
495 |
+
}
|
496 |
+
curl_setopt_array($ch, $opts);
|
497 |
+
$result = curl_exec($ch);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
498 |
|
|
|
|
|
|
|
|
|
|
|
|
|
499 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
500 |
return $result;
|
501 |
}
|
502 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
503 |
|
504 |
private static function checkError($return)
|
505 |
{
|
modules/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/pclzip.lib.php
CHANGED
@@ -1,3051 +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 |
-
|
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 |
-
$
|
2942 |
-
|
2943 |
-
|
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 |
-
$p_size
|
2977 |
-
|
2978 |
-
|
2979 |
-
|
2980 |
-
|
2981 |
-
|
2982 |
-
|
2983 |
-
|
2984 |
-
|
2985 |
-
|
2986 |
-
$p_size
|
2987 |
-
|
2988 |
-
|
2989 |
-
|
2990 |
-
|
2991 |
-
|
2992 |
-
|
2993 |
-
|
2994 |
-
|
2995 |
-
|
2996 |
-
|
2997 |
-
|
2998 |
-
|
2999 |
-
|
3000 |
-
|
3001 |
-
|
3002 |
-
|
3003 |
-
|
3004 |
-
|
3005 |
-
|
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 |
-
}
|
3036 |
-
$v_result = 'Unknown';
|
3037 |
-
return $v_result;
|
3038 |
-
}
|
3039 |
-
function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true)
|
3040 |
-
{
|
3041 |
-
if (stristr(php_uname(), 'windows')) {
|
3042 |
-
if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) {
|
3043 |
-
$p_path = substr($p_path, $v_position+1);
|
3044 |
-
}
|
3045 |
-
if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
|
3046 |
-
$p_path = strtr($p_path, '\\', '/');
|
3047 |
-
}
|
3048 |
-
}
|
3049 |
-
return $p_path;
|
3050 |
-
}
|
3051 |
-
?>
|
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/Crypt/AES.php
CHANGED
@@ -1,540 +1,540 @@
|
|
1 |
-
<?php
|
2 |
-
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
3 |
-
|
4 |
-
/**
|
5 |
-
* Pure-PHP implementation of AES.
|
6 |
-
*
|
7 |
-
* Uses mcrypt, if available, and an internal implementation, otherwise.
|
8 |
-
*
|
9 |
-
* PHP versions 4 and 5
|
10 |
-
*
|
11 |
-
* If {@link Crypt_AES::setKeyLength() setKeyLength()} isn't called, it'll be calculated from
|
12 |
-
* {@link Crypt_AES::setKey() setKey()}. ie. if the key is 128-bits, the key length will be 128-bits. If it's 136-bits
|
13 |
-
* it'll be null-padded to 160-bits and 160 bits will be the key length until {@link Crypt_Rijndael::setKey() setKey()}
|
14 |
-
* is called, again, at which point, it'll be recalculated.
|
15 |
-
*
|
16 |
-
* Since Crypt_AES extends Crypt_Rijndael, some functions are available to be called that, in the context of AES, don't
|
17 |
-
* make a whole lot of sense. {@link Crypt_AES::setBlockLength() setBlockLength()}, for instance. Calling that function,
|
18 |
-
* however possible, won't do anything (AES has a fixed block length whereas Rijndael has a variable one).
|
19 |
-
*
|
20 |
-
* Here's a short example of how to use this library:
|
21 |
-
* <code>
|
22 |
-
* <?php
|
23 |
-
* include('Crypt/AES.php');
|
24 |
-
*
|
25 |
-
* $aes = new Crypt_AES();
|
26 |
-
*
|
27 |
-
* $aes->setKey('abcdefghijklmnop');
|
28 |
-
*
|
29 |
-
* $size = 10 * 1024;
|
30 |
-
* $plaintext = '';
|
31 |
-
* for ($i = 0; $i < $size; $i++) {
|
32 |
-
* $plaintext.= 'a';
|
33 |
-
* }
|
34 |
-
*
|
35 |
-
* echo $aes->decrypt($aes->encrypt($plaintext));
|
36 |
-
* ?>
|
37 |
-
* </code>
|
38 |
-
*
|
39 |
-
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
40 |
-
* of this software and associated documentation files (the "Software"), to deal
|
41 |
-
* in the Software without restriction, including without limitation the rights
|
42 |
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
43 |
-
* copies of the Software, and to permit persons to whom the Software is
|
44 |
-
* furnished to do so, subject to the following conditions:
|
45 |
-
*
|
46 |
-
* The above copyright notice and this permission notice shall be included in
|
47 |
-
* all copies or substantial portions of the Software.
|
48 |
-
*
|
49 |
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
50 |
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
51 |
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
52 |
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
53 |
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
54 |
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
55 |
-
* THE SOFTWARE.
|
56 |
-
*
|
57 |
-
* @category Crypt
|
58 |
-
* @package Crypt_AES
|
59 |
-
* @author Jim Wigginton <terrafrost@php.net>
|
60 |
-
* @copyright MMVIII Jim Wigginton
|
61 |
-
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
62 |
-
* @link http://phpseclib.sourceforge.net
|
63 |
-
*/
|
64 |
-
|
65 |
-
/**
|
66 |
-
* Include Crypt_Rijndael
|
67 |
-
*/
|
68 |
-
if (!class_exists('Crypt_Rijndael')) {
|
69 |
-
require_once 'Rijndael.php';
|
70 |
-
}
|
71 |
-
|
72 |
-
/**#@+
|
73 |
-
* @access public
|
74 |
-
* @see Crypt_AES::encrypt()
|
75 |
-
* @see Crypt_AES::decrypt()
|
76 |
-
*/
|
77 |
-
/**
|
78 |
-
* Encrypt / decrypt using the Counter mode.
|
79 |
-
*
|
80 |
-
* Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
|
81 |
-
*
|
82 |
-
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
|
83 |
-
*/
|
84 |
-
define('CRYPT_AES_MODE_CTR', -1);
|
85 |
-
/**
|
86 |
-
* Encrypt / decrypt using the Electronic Code Book mode.
|
87 |
-
*
|
88 |
-
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
|
89 |
-
*/
|
90 |
-
define('CRYPT_AES_MODE_ECB', 1);
|
91 |
-
/**
|
92 |
-
* Encrypt / decrypt using the Code Book Chaining mode.
|
93 |
-
*
|
94 |
-
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
|
95 |
-
*/
|
96 |
-
define('CRYPT_AES_MODE_CBC', 2);
|
97 |
-
/**
|
98 |
-
* Encrypt / decrypt using the Cipher Feedback mode.
|
99 |
-
*
|
100 |
-
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
|
101 |
-
*/
|
102 |
-
define('CRYPT_AES_MODE_CFB', 3);
|
103 |
-
/**
|
104 |
-
* Encrypt / decrypt using the Cipher Feedback mode.
|
105 |
-
*
|
106 |
-
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
|
107 |
-
*/
|
108 |
-
define('CRYPT_AES_MODE_OFB', 4);
|
109 |
-
/**#@-*/
|
110 |
-
|
111 |
-
/**#@+
|
112 |
-
* @access private
|
113 |
-
* @see Crypt_AES::Crypt_AES()
|
114 |
-
*/
|
115 |
-
/**
|
116 |
-
* Toggles the internal implementation
|
117 |
-
*/
|
118 |
-
define('CRYPT_AES_MODE_INTERNAL', 1);
|
119 |
-
/**
|
120 |
-
* Toggles the mcrypt implementation
|
121 |
-
*/
|
122 |
-
define('CRYPT_AES_MODE_MCRYPT', 2);
|
123 |
-
/**#@-*/
|
124 |
-
|
125 |
-
/**
|
126 |
-
* Pure-PHP implementation of AES.
|
127 |
-
*
|
128 |
-
* @author Jim Wigginton <terrafrost@php.net>
|
129 |
-
* @version 0.1.0
|
130 |
-
* @access public
|
131 |
-
* @package Crypt_AES
|
132 |
-
*/
|
133 |
-
class Crypt_AES extends Crypt_Rijndael {
|
134 |
-
/**
|
135 |
-
* mcrypt resource for encryption
|
136 |
-
*
|
137 |
-
* The mcrypt resource can be recreated every time something needs to be created or it can be created just once.
|
138 |
-
* Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.
|
139 |
-
*
|
140 |
-
* @see Crypt_AES::encrypt()
|
141 |
-
* @var String
|
142 |
-
* @access private
|
143 |
-
*/
|
144 |
-
var $enmcrypt;
|
145 |
-
|
146 |
-
/**
|
147 |
-
* mcrypt resource for decryption
|
148 |
-
*
|
149 |
-
* The mcrypt resource can be recreated every time something needs to be created or it can be created just once.
|
150 |
-
* Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.
|
151 |
-
*
|
152 |
-
* @see Crypt_AES::decrypt()
|
153 |
-
* @var String
|
154 |
-
* @access private
|
155 |
-
*/
|
156 |
-
var $demcrypt;
|
157 |
-
|
158 |
-
/**
|
159 |
-
* mcrypt resource for CFB mode
|
160 |
-
*
|
161 |
-
* @see Crypt_AES::encrypt()
|
162 |
-
* @see Crypt_AES::decrypt()
|
163 |
-
* @var String
|
164 |
-
* @access private
|
165 |
-
*/
|
166 |
-
var $ecb;
|
167 |
-
|
168 |
-
/**
|
169 |
-
* Default Constructor.
|
170 |
-
*
|
171 |
-
* Determines whether or not the mcrypt extension should be used. $mode should only, at present, be
|
172 |
-
* CRYPT_AES_MODE_ECB or CRYPT_AES_MODE_CBC. If not explictly set, CRYPT_AES_MODE_CBC will be used.
|
173 |
-
*
|
174 |
-
* @param optional Integer $mode
|
175 |
-
* @return Crypt_AES
|
176 |
-
* @access public
|
177 |
-
*/
|
178 |
-
function
|
179 |
-
{
|
180 |
-
if ( !defined('CRYPT_AES_MODE') ) {
|
181 |
-
switch (true) {
|
182 |
-
case extension_loaded('mcrypt') && in_array('rijndael-128', mcrypt_list_algorithms()):
|
183 |
-
define('CRYPT_AES_MODE', CRYPT_AES_MODE_MCRYPT);
|
184 |
-
break;
|
185 |
-
default:
|
186 |
-
define('CRYPT_AES_MODE', CRYPT_AES_MODE_INTERNAL);
|
187 |
-
}
|
188 |
-
}
|
189 |
-
|
190 |
-
switch ( CRYPT_AES_MODE ) {
|
191 |
-
case CRYPT_AES_MODE_MCRYPT:
|
192 |
-
switch ($mode) {
|
193 |
-
case CRYPT_AES_MODE_ECB:
|
194 |
-
$this->paddable = true;
|
195 |
-
$this->mode = MCRYPT_MODE_ECB;
|
196 |
-
break;
|
197 |
-
case CRYPT_AES_MODE_CTR:
|
198 |
-
// ctr doesn't have a constant associated with it even though it appears to be fairly widely
|
199 |
-
// supported. in lieu of knowing just how widely supported it is, i've, for now, opted not to
|
200 |
-
// include a compatibility layer. the layer has been implemented but, for now, is commented out.
|
201 |
-
$this->mode = 'ctr';
|
202 |
-
//$this->mode = in_array('ctr', mcrypt_list_modes()) ? 'ctr' : CRYPT_AES_MODE_CTR;
|
203 |
-
break;
|
204 |
-
case CRYPT_AES_MODE_CFB:
|
205 |
-
$this->mode = 'ncfb';
|
206 |
-
break;
|
207 |
-
case CRYPT_AES_MODE_OFB:
|
208 |
-
$this->mode = MCRYPT_MODE_NOFB;
|
209 |
-
break;
|
210 |
-
case CRYPT_AES_MODE_CBC:
|
211 |
-
default:
|
212 |
-
$this->paddable = true;
|
213 |
-
$this->mode = MCRYPT_MODE_CBC;
|
214 |
-
}
|
215 |
-
|
216 |
-
break;
|
217 |
-
default:
|
218 |
-
switch ($mode) {
|
219 |
-
case CRYPT_AES_MODE_ECB:
|
220 |
-
$this->paddable = true;
|
221 |
-
$this->mode = CRYPT_RIJNDAEL_MODE_ECB;
|
222 |
-
break;
|
223 |
-
case CRYPT_AES_MODE_CTR:
|
224 |
-
$this->mode = CRYPT_RIJNDAEL_MODE_CTR;
|
225 |
-
break;
|
226 |
-
case CRYPT_AES_MODE_CFB:
|
227 |
-
$this->mode = CRYPT_RIJNDAEL_MODE_CFB;
|
228 |
-
break;
|
229 |
-
case CRYPT_AES_MODE_OFB:
|
230 |
-
$this->mode = CRYPT_RIJNDAEL_MODE_OFB;
|
231 |
-
break;
|
232 |
-
case CRYPT_AES_MODE_CBC:
|
233 |
-
default:
|
234 |
-
$this->paddable = true;
|
235 |
-
$this->mode = CRYPT_RIJNDAEL_MODE_CBC;
|
236 |
-
}
|
237 |
-
}
|
238 |
-
|
239 |
-
if (CRYPT_AES_MODE == CRYPT_AES_MODE_INTERNAL) {
|
240 |
-
parent::Crypt_Rijndael($this->mode);
|
241 |
-
}
|
242 |
-
|
243 |
-
}
|
244 |
-
|
245 |
-
/**
|
246 |
-
* Dummy function
|
247 |
-
*
|
248 |
-
* Since Crypt_AES extends Crypt_Rijndael, this function is, technically, available, but it doesn't do anything.
|
249 |
-
*
|
250 |
-
* @access public
|
251 |
-
* @param Integer $length
|
252 |
-
*/
|
253 |
-
function setBlockLength($length)
|
254 |
-
{
|
255 |
-
return;
|
256 |
-
}
|
257 |
-
|
258 |
-
/**
|
259 |
-
* Sets the initialization vector. (optional)
|
260 |
-
*
|
261 |
-
* SetIV is not required when CRYPT_RIJNDAEL_MODE_ECB is being used. If not explictly set, it'll be assumed
|
262 |
-
* to be all zero's.
|
263 |
-
*
|
264 |
-
* @access public
|
265 |
-
* @param String $iv
|
266 |
-
*/
|
267 |
-
function setIV($iv)
|
268 |
-
{
|
269 |
-
parent::setIV($iv);
|
270 |
-
if ( CRYPT_AES_MODE == CRYPT_AES_MODE_MCRYPT ) {
|
271 |
-
$this->changed = true;
|
272 |
-
}
|
273 |
-
}
|
274 |
-
|
275 |
-
/**
|
276 |
-
* Encrypts a message.
|
277 |
-
*
|
278 |
-
* $plaintext will be padded with up to 16 additional bytes. Other AES implementations may or may not pad in the
|
279 |
-
* same manner. Other common approaches to padding and the reasons why it's necessary are discussed in the following
|
280 |
-
* URL:
|
281 |
-
*
|
282 |
-
* {@link http://www.di-mgt.com.au/cryptopad.html http://www.di-mgt.com.au/cryptopad.html}
|
283 |
-
*
|
284 |
-
* An alternative to padding is to, separately, send the length of the file. This is what SSH, in fact, does.
|
285 |
-
* strlen($plaintext) will still need to be a multiple of 16, however, arbitrary values can be added to make it that
|
286 |
-
* length.
|
287 |
-
*
|
288 |
-
* @see Crypt_AES::decrypt()
|
289 |
-
* @access public
|
290 |
-
* @param String $plaintext
|
291 |
-
*/
|
292 |
-
function encrypt($plaintext)
|
293 |
-
{
|
294 |
-
if ( CRYPT_AES_MODE == CRYPT_AES_MODE_MCRYPT ) {
|
295 |
-
$this->_mcryptSetup();
|
296 |
-
|
297 |
-
// re: http://phpseclib.sourceforge.net/cfb-demo.phps
|
298 |
-
// using mcrypt's default handing of CFB the above would output two different things. using phpseclib's
|
299 |
-
// rewritten CFB implementation the above outputs the same thing twice.
|
300 |
-
if ($this->mode == 'ncfb' && $this->continuousBuffer) {
|
301 |
-
$iv = &$this->encryptIV;
|
302 |
-
$pos = &$this->enbuffer['pos'];
|
303 |
-
$len = strlen($plaintext);
|
304 |
-
$ciphertext = '';
|
305 |
-
$i = 0;
|
306 |
-
if ($pos) {
|
307 |
-
$orig_pos = $pos;
|
308 |
-
$max = 16 - $pos;
|
309 |
-
if ($len >= $max) {
|
310 |
-
$i = $max;
|
311 |
-
$len-= $max;
|
312 |
-
$pos = 0;
|
313 |
-
} else {
|
314 |
-
$i = $len;
|
315 |
-
$pos+= $len;
|
316 |
-
$len = 0;
|
317 |
-
}
|
318 |
-
$ciphertext = substr($iv, $orig_pos) ^ $plaintext;
|
319 |
-
$iv = substr_replace($iv, $ciphertext, $orig_pos, $i);
|
320 |
-
$this->enbuffer['enmcrypt_init'] = true;
|
321 |
-
}
|
322 |
-
if ($len >= 16) {
|
323 |
-
if ($this->enbuffer['enmcrypt_init'] === false || $len > 280) {
|
324 |
-
if ($this->enbuffer['enmcrypt_init'] === true) {
|
325 |
-
mcrypt_generic_init($this->enmcrypt, $this->key, $iv);
|
326 |
-
$this->enbuffer['enmcrypt_init'] = false;
|
327 |
-
}
|
328 |
-
$ciphertext.= mcrypt_generic($this->enmcrypt, substr($plaintext, $i, $len - $len % 16));
|
329 |
-
$iv = substr($ciphertext, -16);
|
330 |
-
$len%= 16;
|
331 |
-
} else {
|
332 |
-
while ($len >= 16) {
|
333 |
-
$iv = mcrypt_generic($this->ecb, $iv) ^ substr($plaintext, $i, 16);
|
334 |
-
$ciphertext.= $iv;
|
335 |
-
$len-= 16;
|
336 |
-
$i+= 16;
|
337 |
-
}
|
338 |
-
}
|
339 |
-
}
|
340 |
-
|
341 |
-
if ($len) {
|
342 |
-
$iv = mcrypt_generic($this->ecb, $iv);
|
343 |
-
$block = $iv ^ substr($plaintext, -$len);
|
344 |
-
$iv = substr_replace($iv, $block, 0, $len);
|
345 |
-
$ciphertext.= $block;
|
346 |
-
$pos = $len;
|
347 |
-
}
|
348 |
-
|
349 |
-
return $ciphertext;
|
350 |
-
}
|
351 |
-
|
352 |
-
if ($this->paddable) {
|
353 |
-
$plaintext = $this->_pad($plaintext);
|
354 |
-
}
|
355 |
-
|
356 |
-
$ciphertext = mcrypt_generic($this->enmcrypt, $plaintext);
|
357 |
-
|
358 |
-
if (!$this->continuousBuffer) {
|
359 |
-
mcrypt_generic_init($this->enmcrypt, $this->key, $this->iv);
|
360 |
-
}
|
361 |
-
|
362 |
-
return $ciphertext;
|
363 |
-
}
|
364 |
-
|
365 |
-
return parent::encrypt($plaintext);
|
366 |
-
}
|
367 |
-
|
368 |
-
/**
|
369 |
-
* Decrypts a message.
|
370 |
-
*
|
371 |
-
* If strlen($ciphertext) is not a multiple of 16, null bytes will be added to the end of the string until it is.
|
372 |
-
*
|
373 |
-
* @see Crypt_AES::encrypt()
|
374 |
-
* @access public
|
375 |
-
* @param String $ciphertext
|
376 |
-
*/
|
377 |
-
function decrypt($ciphertext)
|
378 |
-
{
|
379 |
-
if ( CRYPT_AES_MODE == CRYPT_AES_MODE_MCRYPT ) {
|
380 |
-
$this->_mcryptSetup();
|
381 |
-
|
382 |
-
if ($this->mode == 'ncfb' && $this->continuousBuffer) {
|
383 |
-
$iv = &$this->decryptIV;
|
384 |
-
$pos = &$this->debuffer['pos'];
|
385 |
-
$len = strlen($ciphertext);
|
386 |
-
$plaintext = '';
|
387 |
-
$i = 0;
|
388 |
-
if ($pos) {
|
389 |
-
$orig_pos = $pos;
|
390 |
-
$max = 16 - $pos;
|
391 |
-
if ($len >= $max) {
|
392 |
-
$i = $max;
|
393 |
-
$len-= $max;
|
394 |
-
$pos = 0;
|
395 |
-
} else {
|
396 |
-
$i = $len;
|
397 |
-
$pos+= $len;
|
398 |
-
$len = 0;
|
399 |
-
}
|
400 |
-
// ie. $i = min($max, $len), $len-= $i, $pos+= $i, $pos%= $blocksize
|
401 |
-
$plaintext = substr($iv, $orig_pos) ^ $ciphertext;
|
402 |
-
$iv = substr_replace($iv, substr($ciphertext, 0, $i), $orig_pos, $i);
|
403 |
-
}
|
404 |
-
if ($len >= 16) {
|
405 |
-
$cb = substr($ciphertext, $i, $len - $len % 16);
|
406 |
-
$plaintext.= mcrypt_generic($this->ecb, $iv . $cb) ^ $cb;
|
407 |
-
$iv = substr($cb, -16);
|
408 |
-
$len%= 16;
|
409 |
-
}
|
410 |
-
if ($len) {
|
411 |
-
$iv = mcrypt_generic($this->ecb, $iv);
|
412 |
-
$plaintext.= $iv ^ substr($ciphertext, -$len);
|
413 |
-
$iv = substr_replace($iv, substr($ciphertext, -$len), 0, $len);
|
414 |
-
$pos = $len;
|
415 |
-
}
|
416 |
-
|
417 |
-
return $plaintext;
|
418 |
-
}
|
419 |
-
|
420 |
-
if ($this->paddable) {
|
421 |
-
// we pad with chr(0) since that's what mcrypt_generic does. to quote from http://php.net/function.mcrypt-generic :
|
422 |
-
// "The data is padded with "\0" to make sure the length of the data is n * blocksize."
|
423 |
-
$ciphertext = str_pad($ciphertext, (strlen($ciphertext) + 15) & 0xFFFFFFF0, chr(0));
|
424 |
-
}
|
425 |
-
|
426 |
-
$plaintext = mdecrypt_generic($this->demcrypt, $ciphertext);
|
427 |
-
|
428 |
-
if (!$this->continuousBuffer) {
|
429 |
-
mcrypt_generic_init($this->demcrypt, $this->key, $this->iv);
|
430 |
-
}
|
431 |
-
|
432 |
-
return $this->paddable ? $this->_unpad($plaintext) : $plaintext;
|
433 |
-
}
|
434 |
-
|
435 |
-
return parent::decrypt($ciphertext);
|
436 |
-
}
|
437 |
-
|
438 |
-
/**
|
439 |
-
* Setup mcrypt
|
440 |
-
*
|
441 |
-
* Validates all the variables.
|
442 |
-
*
|
443 |
-
* @access private
|
444 |
-
*/
|
445 |
-
function _mcryptSetup()
|
446 |
-
{
|
447 |
-
if (!$this->changed) {
|
448 |
-
return;
|
449 |
-
}
|
450 |
-
|
451 |
-
if (!$this->explicit_key_length) {
|
452 |
-
// this just copied from Crypt_Rijndael::_setup()
|
453 |
-
$length = strlen($this->key) >> 2;
|
454 |
-
if ($length > 8) {
|
455 |
-
$length = 8;
|
456 |
-
} else if ($length < 4) {
|
457 |
-
$length = 4;
|
458 |
-
}
|
459 |
-
$this->Nk = $length;
|
460 |
-
$this->key_size = $length << 2;
|
461 |
-
}
|
462 |
-
|
463 |
-
switch ($this->Nk) {
|
464 |
-
case 4: // 128
|
465 |
-
$this->key_size = 16;
|
466 |
-
break;
|
467 |
-
case 5: // 160
|
468 |
-
case 6: // 192
|
469 |
-
$this->key_size = 24;
|
470 |
-
break;
|
471 |
-
case 7: // 224
|
472 |
-
case 8: // 256
|
473 |
-
$this->key_size = 32;
|
474 |
-
}
|
475 |
-
|
476 |
-
$this->key = str_pad(substr($this->key, 0, $this->key_size), $this->key_size, chr(0));
|
477 |
-
$this->encryptIV = $this->decryptIV = $this->iv = str_pad(substr($this->iv, 0, 16), 16, chr(0));
|
478 |
-
|
479 |
-
if (!isset($this->enmcrypt)) {
|
480 |
-
$mode = $this->mode;
|
481 |
-
//$mode = $this->mode == CRYPT_AES_MODE_CTR ? MCRYPT_MODE_ECB : $this->mode;
|
482 |
-
|
483 |
-
$this->demcrypt = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', $mode, '');
|
484 |
-
$this->enmcrypt = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', $mode, '');
|
485 |
-
|
486 |
-
if ($mode == 'ncfb') {
|
487 |
-
$this->ecb = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, '');
|
488 |
-
}
|
489 |
-
|
490 |
-
} // else should mcrypt_generic_deinit be called?
|
491 |
-
|
492 |
-
mcrypt_generic_init($this->demcrypt, $this->key, $this->iv);
|
493 |
-
mcrypt_generic_init($this->enmcrypt, $this->key, $this->iv);
|
494 |
-
|
495 |
-
if ($this->mode == 'ncfb') {
|
496 |
-
mcrypt_generic_init($this->ecb, $this->key, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
|
497 |
-
}
|
498 |
-
|
499 |
-
$this->changed = false;
|
500 |
-
}
|
501 |
-
|
502 |
-
/**
|
503 |
-
* Treat consecutive "packets" as if they are a continuous buffer.
|
504 |
-
*
|
505 |
-
* The default behavior.
|
506 |
-
*
|
507 |
-
* @see Crypt_Rijndael::disableContinuousBuffer()
|
508 |
-
* @access public
|
509 |
-
*/
|
510 |
-
function enableContinuousBuffer()
|
511 |
-
{
|
512 |
-
parent::enableContinuousBuffer();
|
513 |
-
|
514 |
-
if (CRYPT_AES_MODE == CRYPT_AES_MODE_MCRYPT) {
|
515 |
-
$this->enbuffer['enmcrypt_init'] = true;
|
516 |
-
$this->debuffer['demcrypt_init'] = true;
|
517 |
-
}
|
518 |
-
}
|
519 |
-
|
520 |
-
/**
|
521 |
-
* Treat consecutive packets as if they are a discontinuous buffer.
|
522 |
-
*
|
523 |
-
* The default behavior.
|
524 |
-
*
|
525 |
-
* @see Crypt_Rijndael::enableContinuousBuffer()
|
526 |
-
* @access public
|
527 |
-
*/
|
528 |
-
function disableContinuousBuffer()
|
529 |
-
{
|
530 |
-
parent::disableContinuousBuffer();
|
531 |
-
|
532 |
-
if (CRYPT_AES_MODE == CRYPT_AES_MODE_MCRYPT) {
|
533 |
-
mcrypt_generic_init($this->enmcrypt, $this->key, $this->iv);
|
534 |
-
mcrypt_generic_init($this->demcrypt, $this->key, $this->iv);
|
535 |
-
}
|
536 |
-
}
|
537 |
-
}
|
538 |
-
|
539 |
-
// vim: ts=4:sw=4:et:
|
540 |
-
// vim6: fdl=1:
|
1 |
+
<?php
|
2 |
+
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Pure-PHP implementation of AES.
|
6 |
+
*
|
7 |
+
* Uses mcrypt, if available, and an internal implementation, otherwise.
|
8 |
+
*
|
9 |
+
* PHP versions 4 and 5
|
10 |
+
*
|
11 |
+
* If {@link Crypt_AES::setKeyLength() setKeyLength()} isn't called, it'll be calculated from
|
12 |
+
* {@link Crypt_AES::setKey() setKey()}. ie. if the key is 128-bits, the key length will be 128-bits. If it's 136-bits
|
13 |
+
* it'll be null-padded to 160-bits and 160 bits will be the key length until {@link Crypt_Rijndael::setKey() setKey()}
|
14 |
+
* is called, again, at which point, it'll be recalculated.
|
15 |
+
*
|
16 |
+
* Since Crypt_AES extends Crypt_Rijndael, some functions are available to be called that, in the context of AES, don't
|
17 |
+
* make a whole lot of sense. {@link Crypt_AES::setBlockLength() setBlockLength()}, for instance. Calling that function,
|
18 |
+
* however possible, won't do anything (AES has a fixed block length whereas Rijndael has a variable one).
|
19 |
+
*
|
20 |
+
* Here's a short example of how to use this library:
|
21 |
+
* <code>
|
22 |
+
* <?php
|
23 |
+
* include('Crypt/AES.php');
|
24 |
+
*
|
25 |
+
* $aes = new Crypt_AES();
|
26 |
+
*
|
27 |
+
* $aes->setKey('abcdefghijklmnop');
|
28 |
+
*
|
29 |
+
* $size = 10 * 1024;
|
30 |
+
* $plaintext = '';
|
31 |
+
* for ($i = 0; $i < $size; $i++) {
|
32 |
+
* $plaintext.= 'a';
|
33 |
+
* }
|
34 |
+
*
|
35 |
+
* echo $aes->decrypt($aes->encrypt($plaintext));
|
36 |
+
* ?>
|
37 |
+
* </code>
|
38 |
+
*
|
39 |
+
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
40 |
+
* of this software and associated documentation files (the "Software"), to deal
|
41 |
+
* in the Software without restriction, including without limitation the rights
|
42 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
43 |
+
* copies of the Software, and to permit persons to whom the Software is
|
44 |
+
* furnished to do so, subject to the following conditions:
|
45 |
+
*
|
46 |
+
* The above copyright notice and this permission notice shall be included in
|
47 |
+
* all copies or substantial portions of the Software.
|
48 |
+
*
|
49 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
50 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
51 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
52 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
53 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
54 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
55 |
+
* THE SOFTWARE.
|
56 |
+
*
|
57 |
+
* @category Crypt
|
58 |
+
* @package Crypt_AES
|
59 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
60 |
+
* @copyright MMVIII Jim Wigginton
|
61 |
+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
62 |
+
* @link http://phpseclib.sourceforge.net
|
63 |
+
*/
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Include Crypt_Rijndael
|
67 |
+
*/
|
68 |
+
if (!class_exists('Crypt_Rijndael')) {
|
69 |
+
require_once 'Rijndael.php';
|
70 |
+
}
|
71 |
+
|
72 |
+
/**#@+
|
73 |
+
* @access public
|
74 |
+
* @see Crypt_AES::encrypt()
|
75 |
+
* @see Crypt_AES::decrypt()
|
76 |
+
*/
|
77 |
+
/**
|
78 |
+
* Encrypt / decrypt using the Counter mode.
|
79 |
+
*
|
80 |
+
* Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
|
81 |
+
*
|
82 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
|
83 |
+
*/
|
84 |
+
define('CRYPT_AES_MODE_CTR', -1);
|
85 |
+
/**
|
86 |
+
* Encrypt / decrypt using the Electronic Code Book mode.
|
87 |
+
*
|
88 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
|
89 |
+
*/
|
90 |
+
define('CRYPT_AES_MODE_ECB', 1);
|
91 |
+
/**
|
92 |
+
* Encrypt / decrypt using the Code Book Chaining mode.
|
93 |
+
*
|
94 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
|
95 |
+
*/
|
96 |
+
define('CRYPT_AES_MODE_CBC', 2);
|
97 |
+
/**
|
98 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
99 |
+
*
|
100 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
|
101 |
+
*/
|
102 |
+
define('CRYPT_AES_MODE_CFB', 3);
|
103 |
+
/**
|
104 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
105 |
+
*
|
106 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
|
107 |
+
*/
|
108 |
+
define('CRYPT_AES_MODE_OFB', 4);
|
109 |
+
/**#@-*/
|
110 |
+
|
111 |
+
/**#@+
|
112 |
+
* @access private
|
113 |
+
* @see Crypt_AES::Crypt_AES()
|
114 |
+
*/
|
115 |
+
/**
|
116 |
+
* Toggles the internal implementation
|
117 |
+
*/
|
118 |
+
define('CRYPT_AES_MODE_INTERNAL', 1);
|
119 |
+
/**
|
120 |
+
* Toggles the mcrypt implementation
|
121 |
+
*/
|
122 |
+
define('CRYPT_AES_MODE_MCRYPT', 2);
|
123 |
+
/**#@-*/
|
124 |
+
|
125 |
+
/**
|
126 |
+
* Pure-PHP implementation of AES.
|
127 |
+
*
|
128 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
129 |
+
* @version 0.1.0
|
130 |
+
* @access public
|
131 |
+
* @package Crypt_AES
|
132 |
+
*/
|
133 |
+
class Crypt_AES extends Crypt_Rijndael {
|
134 |
+
/**
|
135 |
+
* mcrypt resource for encryption
|
136 |
+
*
|
137 |
+
* The mcrypt resource can be recreated every time something needs to be created or it can be created just once.
|
138 |
+
* Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.
|
139 |
+
*
|
140 |
+
* @see Crypt_AES::encrypt()
|
141 |
+
* @var String
|
142 |
+
* @access private
|
143 |
+
*/
|
144 |
+
var $enmcrypt;
|
145 |
+
|
146 |
+
/**
|
147 |
+
* mcrypt resource for decryption
|
148 |
+
*
|
149 |
+
* The mcrypt resource can be recreated every time something needs to be created or it can be created just once.
|
150 |
+
* Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.
|
151 |
+
*
|
152 |
+
* @see Crypt_AES::decrypt()
|
153 |
+
* @var String
|
154 |
+
* @access private
|
155 |
+
*/
|
156 |
+
var $demcrypt;
|
157 |
+
|
158 |
+
/**
|
159 |
+
* mcrypt resource for CFB mode
|
160 |
+
*
|
161 |
+
* @see Crypt_AES::encrypt()
|
162 |
+
* @see Crypt_AES::decrypt()
|
163 |
+
* @var String
|
164 |
+
* @access private
|
165 |
+
*/
|
166 |
+
var $ecb;
|
167 |
+
|
168 |
+
/**
|
169 |
+
* Default Constructor.
|
170 |
+
*
|
171 |
+
* Determines whether or not the mcrypt extension should be used. $mode should only, at present, be
|
172 |
+
* CRYPT_AES_MODE_ECB or CRYPT_AES_MODE_CBC. If not explictly set, CRYPT_AES_MODE_CBC will be used.
|
173 |
+
*
|
174 |
+
* @param optional Integer $mode
|
175 |
+
* @return Crypt_AES
|
176 |
+
* @access public
|
177 |
+
*/
|
178 |
+
function Crypt_AES($mode = CRYPT_AES_MODE_CBC)
|
179 |
+
{
|
180 |
+
if ( !defined('CRYPT_AES_MODE') ) {
|
181 |
+
switch (true) {
|
182 |
+
case extension_loaded('mcrypt') && in_array('rijndael-128', mcrypt_list_algorithms()):
|
183 |
+
define('CRYPT_AES_MODE', CRYPT_AES_MODE_MCRYPT);
|
184 |
+
break;
|
185 |
+
default:
|
186 |
+
define('CRYPT_AES_MODE', CRYPT_AES_MODE_INTERNAL);
|
187 |
+
}
|
188 |
+
}
|
189 |
+
|
190 |
+
switch ( CRYPT_AES_MODE ) {
|
191 |
+
case CRYPT_AES_MODE_MCRYPT:
|
192 |
+
switch ($mode) {
|
193 |
+
case CRYPT_AES_MODE_ECB:
|
194 |
+
$this->paddable = true;
|
195 |
+
$this->mode = MCRYPT_MODE_ECB;
|
196 |
+
break;
|
197 |
+
case CRYPT_AES_MODE_CTR:
|
198 |
+
// ctr doesn't have a constant associated with it even though it appears to be fairly widely
|
199 |
+
// supported. in lieu of knowing just how widely supported it is, i've, for now, opted not to
|
200 |
+
// include a compatibility layer. the layer has been implemented but, for now, is commented out.
|
201 |
+
$this->mode = 'ctr';
|
202 |
+
//$this->mode = in_array('ctr', mcrypt_list_modes()) ? 'ctr' : CRYPT_AES_MODE_CTR;
|
203 |
+
break;
|
204 |
+
case CRYPT_AES_MODE_CFB:
|
205 |
+
$this->mode = 'ncfb';
|
206 |
+
break;
|
207 |
+
case CRYPT_AES_MODE_OFB:
|
208 |
+
$this->mode = MCRYPT_MODE_NOFB;
|
209 |
+
break;
|
210 |
+
case CRYPT_AES_MODE_CBC:
|
211 |
+
default:
|
212 |
+
$this->paddable = true;
|
213 |
+
$this->mode = MCRYPT_MODE_CBC;
|
214 |
+
}
|
215 |
+
|
216 |
+
break;
|
217 |
+
default:
|
218 |
+
switch ($mode) {
|
219 |
+
case CRYPT_AES_MODE_ECB:
|
220 |
+
$this->paddable = true;
|
221 |
+
$this->mode = CRYPT_RIJNDAEL_MODE_ECB;
|
222 |
+
break;
|
223 |
+
case CRYPT_AES_MODE_CTR:
|
224 |
+
$this->mode = CRYPT_RIJNDAEL_MODE_CTR;
|
225 |
+
break;
|
226 |
+
case CRYPT_AES_MODE_CFB:
|
227 |
+
$this->mode = CRYPT_RIJNDAEL_MODE_CFB;
|
228 |
+
break;
|
229 |
+
case CRYPT_AES_MODE_OFB:
|
230 |
+
$this->mode = CRYPT_RIJNDAEL_MODE_OFB;
|
231 |
+
break;
|
232 |
+
case CRYPT_AES_MODE_CBC:
|
233 |
+
default:
|
234 |
+
$this->paddable = true;
|
235 |
+
$this->mode = CRYPT_RIJNDAEL_MODE_CBC;
|
236 |
+
}
|
237 |
+
}
|
238 |
+
|
239 |
+
if (CRYPT_AES_MODE == CRYPT_AES_MODE_INTERNAL) {
|
240 |
+
parent::Crypt_Rijndael($this->mode);
|
241 |
+
}
|
242 |
+
|
243 |
+
}
|
244 |
+
|
245 |
+
/**
|
246 |
+
* Dummy function
|
247 |
+
*
|
248 |
+
* Since Crypt_AES extends Crypt_Rijndael, this function is, technically, available, but it doesn't do anything.
|
249 |
+
*
|
250 |
+
* @access public
|
251 |
+
* @param Integer $length
|
252 |
+
*/
|
253 |
+
function setBlockLength($length)
|
254 |
+
{
|
255 |
+
return;
|
256 |
+
}
|
257 |
+
|
258 |
+
/**
|
259 |
+
* Sets the initialization vector. (optional)
|
260 |
+
*
|
261 |
+
* SetIV is not required when CRYPT_RIJNDAEL_MODE_ECB is being used. If not explictly set, it'll be assumed
|
262 |
+
* to be all zero's.
|
263 |
+
*
|
264 |
+
* @access public
|
265 |
+
* @param String $iv
|
266 |
+
*/
|
267 |
+
function setIV($iv)
|
268 |
+
{
|
269 |
+
parent::setIV($iv);
|
270 |
+
if ( CRYPT_AES_MODE == CRYPT_AES_MODE_MCRYPT ) {
|
271 |
+
$this->changed = true;
|
272 |
+
}
|
273 |
+
}
|
274 |
+
|
275 |
+
/**
|
276 |
+
* Encrypts a message.
|
277 |
+
*
|
278 |
+
* $plaintext will be padded with up to 16 additional bytes. Other AES implementations may or may not pad in the
|
279 |
+
* same manner. Other common approaches to padding and the reasons why it's necessary are discussed in the following
|
280 |
+
* URL:
|
281 |
+
*
|
282 |
+
* {@link http://www.di-mgt.com.au/cryptopad.html http://www.di-mgt.com.au/cryptopad.html}
|
283 |
+
*
|
284 |
+
* An alternative to padding is to, separately, send the length of the file. This is what SSH, in fact, does.
|
285 |
+
* strlen($plaintext) will still need to be a multiple of 16, however, arbitrary values can be added to make it that
|
286 |
+
* length.
|
287 |
+
*
|
288 |
+
* @see Crypt_AES::decrypt()
|
289 |
+
* @access public
|
290 |
+
* @param String $plaintext
|
291 |
+
*/
|
292 |
+
function encrypt($plaintext)
|
293 |
+
{
|
294 |
+
if ( CRYPT_AES_MODE == CRYPT_AES_MODE_MCRYPT ) {
|
295 |
+
$this->_mcryptSetup();
|
296 |
+
|
297 |
+
// re: http://phpseclib.sourceforge.net/cfb-demo.phps
|
298 |
+
// using mcrypt's default handing of CFB the above would output two different things. using phpseclib's
|
299 |
+
// rewritten CFB implementation the above outputs the same thing twice.
|
300 |
+
if ($this->mode == 'ncfb' && $this->continuousBuffer) {
|
301 |
+
$iv = &$this->encryptIV;
|
302 |
+
$pos = &$this->enbuffer['pos'];
|
303 |
+
$len = strlen($plaintext);
|
304 |
+
$ciphertext = '';
|
305 |
+
$i = 0;
|
306 |
+
if ($pos) {
|
307 |
+
$orig_pos = $pos;
|
308 |
+
$max = 16 - $pos;
|
309 |
+
if ($len >= $max) {
|
310 |
+
$i = $max;
|
311 |
+
$len-= $max;
|
312 |
+
$pos = 0;
|
313 |
+
} else {
|
314 |
+
$i = $len;
|
315 |
+
$pos+= $len;
|
316 |
+
$len = 0;
|
317 |
+
}
|
318 |
+
$ciphertext = substr($iv, $orig_pos) ^ $plaintext;
|
319 |
+
$iv = substr_replace($iv, $ciphertext, $orig_pos, $i);
|
320 |
+
$this->enbuffer['enmcrypt_init'] = true;
|
321 |
+
}
|
322 |
+
if ($len >= 16) {
|
323 |
+
if ($this->enbuffer['enmcrypt_init'] === false || $len > 280) {
|
324 |
+
if ($this->enbuffer['enmcrypt_init'] === true) {
|
325 |
+
mcrypt_generic_init($this->enmcrypt, $this->key, $iv);
|
326 |
+
$this->enbuffer['enmcrypt_init'] = false;
|
327 |
+
}
|
328 |
+
$ciphertext.= mcrypt_generic($this->enmcrypt, substr($plaintext, $i, $len - $len % 16));
|
329 |
+
$iv = substr($ciphertext, -16);
|
330 |
+
$len%= 16;
|
331 |
+
} else {
|
332 |
+
while ($len >= 16) {
|
333 |
+
$iv = mcrypt_generic($this->ecb, $iv) ^ substr($plaintext, $i, 16);
|
334 |
+
$ciphertext.= $iv;
|
335 |
+
$len-= 16;
|
336 |
+
$i+= 16;
|
337 |
+
}
|
338 |
+
}
|
339 |
+
}
|
340 |
+
|
341 |
+
if ($len) {
|
342 |
+
$iv = mcrypt_generic($this->ecb, $iv);
|
343 |
+
$block = $iv ^ substr($plaintext, -$len);
|
344 |
+
$iv = substr_replace($iv, $block, 0, $len);
|
345 |
+
$ciphertext.= $block;
|
346 |
+
$pos = $len;
|
347 |
+
}
|
348 |
+
|
349 |
+
return $ciphertext;
|
350 |
+
}
|
351 |
+
|
352 |
+
if ($this->paddable) {
|
353 |
+
$plaintext = $this->_pad($plaintext);
|
354 |
+
}
|
355 |
+
|
356 |
+
$ciphertext = mcrypt_generic($this->enmcrypt, $plaintext);
|
357 |
+
|
358 |
+
if (!$this->continuousBuffer) {
|
359 |
+
mcrypt_generic_init($this->enmcrypt, $this->key, $this->iv);
|
360 |
+
}
|
361 |
+
|
362 |
+
return $ciphertext;
|
363 |
+
}
|
364 |
+
|
365 |
+
return parent::encrypt($plaintext);
|
366 |
+
}
|
367 |
+
|
368 |
+
/**
|
369 |
+
* Decrypts a message.
|
370 |
+
*
|
371 |
+
* If strlen($ciphertext) is not a multiple of 16, null bytes will be added to the end of the string until it is.
|
372 |
+
*
|
373 |
+
* @see Crypt_AES::encrypt()
|
374 |
+
* @access public
|
375 |
+
* @param String $ciphertext
|
376 |
+
*/
|
377 |
+
function decrypt($ciphertext)
|
378 |
+
{
|
379 |
+
if ( CRYPT_AES_MODE == CRYPT_AES_MODE_MCRYPT ) {
|
380 |
+
$this->_mcryptSetup();
|
381 |
+
|
382 |
+
if ($this->mode == 'ncfb' && $this->continuousBuffer) {
|
383 |
+
$iv = &$this->decryptIV;
|
384 |
+
$pos = &$this->debuffer['pos'];
|
385 |
+
$len = strlen($ciphertext);
|
386 |
+
$plaintext = '';
|
387 |
+
$i = 0;
|
388 |
+
if ($pos) {
|
389 |
+
$orig_pos = $pos;
|
390 |
+
$max = 16 - $pos;
|
391 |
+
if ($len >= $max) {
|
392 |
+
$i = $max;
|
393 |
+
$len-= $max;
|
394 |
+
$pos = 0;
|
395 |
+
} else {
|
396 |
+
$i = $len;
|
397 |
+
$pos+= $len;
|
398 |
+
$len = 0;
|
399 |
+
}
|
400 |
+
// ie. $i = min($max, $len), $len-= $i, $pos+= $i, $pos%= $blocksize
|
401 |
+
$plaintext = substr($iv, $orig_pos) ^ $ciphertext;
|
402 |
+
$iv = substr_replace($iv, substr($ciphertext, 0, $i), $orig_pos, $i);
|
403 |
+
}
|
404 |
+
if ($len >= 16) {
|
405 |
+
$cb = substr($ciphertext, $i, $len - $len % 16);
|
406 |
+
$plaintext.= mcrypt_generic($this->ecb, $iv . $cb) ^ $cb;
|
407 |
+
$iv = substr($cb, -16);
|
408 |
+
$len%= 16;
|
409 |
+
}
|
410 |
+
if ($len) {
|
411 |
+
$iv = mcrypt_generic($this->ecb, $iv);
|
412 |
+
$plaintext.= $iv ^ substr($ciphertext, -$len);
|
413 |
+
$iv = substr_replace($iv, substr($ciphertext, -$len), 0, $len);
|
414 |
+
$pos = $len;
|
415 |
+
}
|
416 |
+
|
417 |
+
return $plaintext;
|
418 |
+
}
|
419 |
+
|
420 |
+
if ($this->paddable) {
|
421 |
+
// we pad with chr(0) since that's what mcrypt_generic does. to quote from http://php.net/function.mcrypt-generic :
|
422 |
+
// "The data is padded with "\0" to make sure the length of the data is n * blocksize."
|
423 |
+
$ciphertext = str_pad($ciphertext, (strlen($ciphertext) + 15) & 0xFFFFFFF0, chr(0));
|
424 |
+
}
|
425 |
+
|
426 |
+
$plaintext = mdecrypt_generic($this->demcrypt, $ciphertext);
|
427 |
+
|
428 |
+
if (!$this->continuousBuffer) {
|
429 |
+
mcrypt_generic_init($this->demcrypt, $this->key, $this->iv);
|
430 |
+
}
|
431 |
+
|
432 |
+
return $this->paddable ? $this->_unpad($plaintext) : $plaintext;
|
433 |
+
}
|
434 |
+
|
435 |
+
return parent::decrypt($ciphertext);
|
436 |
+
}
|
437 |
+
|
438 |
+
/**
|
439 |
+
* Setup mcrypt
|
440 |
+
*
|
441 |
+
* Validates all the variables.
|
442 |
+
*
|
443 |
+
* @access private
|
444 |
+
*/
|
445 |
+
function _mcryptSetup()
|
446 |
+
{
|
447 |
+
if (!$this->changed) {
|
448 |
+
return;
|
449 |
+
}
|
450 |
+
|
451 |
+
if (!$this->explicit_key_length) {
|
452 |
+
// this just copied from Crypt_Rijndael::_setup()
|
453 |
+
$length = strlen($this->key) >> 2;
|
454 |
+
if ($length > 8) {
|
455 |
+
$length = 8;
|
456 |
+
} else if ($length < 4) {
|
457 |
+
$length = 4;
|
458 |
+
}
|
459 |
+
$this->Nk = $length;
|
460 |
+
$this->key_size = $length << 2;
|
461 |
+
}
|
462 |
+
|
463 |
+
switch ($this->Nk) {
|
464 |
+
case 4: // 128
|
465 |
+
$this->key_size = 16;
|
466 |
+
break;
|
467 |
+
case 5: // 160
|
468 |
+
case 6: // 192
|
469 |
+
$this->key_size = 24;
|
470 |
+
break;
|
471 |
+
case 7: // 224
|
472 |
+
case 8: // 256
|
473 |
+
$this->key_size = 32;
|
474 |
+
}
|
475 |
+
|
476 |
+
$this->key = str_pad(substr($this->key, 0, $this->key_size), $this->key_size, chr(0));
|
477 |
+
$this->encryptIV = $this->decryptIV = $this->iv = str_pad(substr($this->iv, 0, 16), 16, chr(0));
|
478 |
+
|
479 |
+
if (!isset($this->enmcrypt)) {
|
480 |
+
$mode = $this->mode;
|
481 |
+
//$mode = $this->mode == CRYPT_AES_MODE_CTR ? MCRYPT_MODE_ECB : $this->mode;
|
482 |
+
|
483 |
+
$this->demcrypt = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', $mode, '');
|
484 |
+
$this->enmcrypt = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', $mode, '');
|
485 |
+
|
486 |
+
if ($mode == 'ncfb') {
|
487 |
+
$this->ecb = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, '');
|
488 |
+
}
|
489 |
+
|
490 |
+
} // else should mcrypt_generic_deinit be called?
|
491 |
+
|
492 |
+
mcrypt_generic_init($this->demcrypt, $this->key, $this->iv);
|
493 |
+
mcrypt_generic_init($this->enmcrypt, $this->key, $this->iv);
|
494 |
+
|
495 |
+
if ($this->mode == 'ncfb') {
|
496 |
+
mcrypt_generic_init($this->ecb, $this->key, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
|
497 |
+
}
|
498 |
+
|
499 |
+
$this->changed = false;
|
500 |
+
}
|
501 |
+
|
502 |
+
/**
|
503 |
+
* Treat consecutive "packets" as if they are a continuous buffer.
|
504 |
+
*
|
505 |
+
* The default behavior.
|
506 |
+
*
|
507 |
+
* @see Crypt_Rijndael::disableContinuousBuffer()
|
508 |
+
* @access public
|
509 |
+
*/
|
510 |
+
function enableContinuousBuffer()
|
511 |
+
{
|
512 |
+
parent::enableContinuousBuffer();
|
513 |
+
|
514 |
+
if (CRYPT_AES_MODE == CRYPT_AES_MODE_MCRYPT) {
|
515 |
+
$this->enbuffer['enmcrypt_init'] = true;
|
516 |
+
$this->debuffer['demcrypt_init'] = true;
|
517 |
+
}
|
518 |
+
}
|
519 |
+
|
520 |
+
/**
|
521 |
+
* Treat consecutive packets as if they are a discontinuous buffer.
|
522 |
+
*
|
523 |
+
* The default behavior.
|
524 |
+
*
|
525 |
+
* @see Crypt_Rijndael::enableContinuousBuffer()
|
526 |
+
* @access public
|
527 |
+
*/
|
528 |
+
function disableContinuousBuffer()
|
529 |
+
{
|
530 |
+
parent::disableContinuousBuffer();
|
531 |
+
|
532 |
+
if (CRYPT_AES_MODE == CRYPT_AES_MODE_MCRYPT) {
|
533 |
+
mcrypt_generic_init($this->enmcrypt, $this->key, $this->iv);
|
534 |
+
mcrypt_generic_init($this->demcrypt, $this->key, $this->iv);
|
535 |
+
}
|
536 |
+
}
|
537 |
+
}
|
538 |
+
|
539 |
+
// vim: ts=4:sw=4:et:
|
540 |
+
// vim6: fdl=1:
|
modules/phpseclib/Crypt/Blowfish.php
CHANGED
@@ -1,1468 +1,1468 @@
|
|
1 |
-
<?php
|
2 |
-
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
3 |
-
|
4 |
-
/**
|
5 |
-
* Pure-PHP implementation of Blowfish.
|
6 |
-
*
|
7 |
-
* Uses mcrypt, if available, and an internal implementation, otherwise.
|
8 |
-
*
|
9 |
-
* PHP versions 4 and 5
|
10 |
-
*
|
11 |
-
* Useful resources are as follows:
|
12 |
-
*
|
13 |
-
* - {@link http://en.wikipedia.org/wiki/Blowfish Wikipedia description of Blowfish}
|
14 |
-
*
|
15 |
-
* Here's a short example of how to use this library:
|
16 |
-
* <code>
|
17 |
-
* <?php
|
18 |
-
* include('Crypt/Blowfish.php');
|
19 |
-
*
|
20 |
-
* $blowfish = new Crypt_Blowfish();
|
21 |
-
*
|
22 |
-
* $blowfish->setKey('12345678901234567890123456789012');
|
23 |
-
*
|
24 |
-
* $plaintext = str_repeat('a', 1024);
|
25 |
-
*
|
26 |
-
* echo $blowfish->decrypt($blowfish->encrypt($plaintext));
|
27 |
-
* ?>
|
28 |
-
* </code>
|
29 |
-
*
|
30 |
-
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
31 |
-
* of this software and associated documentation files (the "Software"), to deal
|
32 |
-
* in the Software without restriction, including without limitation the rights
|
33 |
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
34 |
-
* copies of the Software, and to permit persons to whom the Software is
|
35 |
-
* furnished to do so, subject to the following conditions:
|
36 |
-
*
|
37 |
-
* The above copyright notice and this permission notice shall be included in
|
38 |
-
* all copies or substantial portions of the Software.
|
39 |
-
*
|
40 |
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
41 |
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
42 |
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
43 |
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
44 |
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
45 |
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
46 |
-
* THE SOFTWARE.
|
47 |
-
*
|
48 |
-
* @category Crypt
|
49 |
-
* @package Crypt_Blowfish
|
50 |
-
* @author Jim Wigginton <terrafrost@php.net>
|
51 |
-
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
52 |
-
* @copyright MMVII Jim Wigginton
|
53 |
-
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
54 |
-
* @version 1.0
|
55 |
-
* @link http://phpseclib.sourceforge.net
|
56 |
-
*/
|
57 |
-
|
58 |
-
/**#@+
|
59 |
-
* @access public
|
60 |
-
* @see Crypt_Blowfish::encrypt()
|
61 |
-
* @see Crypt_Blowfish::decrypt()
|
62 |
-
*/
|
63 |
-
/**
|
64 |
-
* Encrypt / decrypt using the Counter mode.
|
65 |
-
*
|
66 |
-
* Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
|
67 |
-
*
|
68 |
-
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
|
69 |
-
*/
|
70 |
-
define('CRYPT_BLOWFISH_MODE_CTR', -1);
|
71 |
-
/**
|
72 |
-
* Encrypt / decrypt using the Electronic Code Book mode.
|
73 |
-
*
|
74 |
-
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
|
75 |
-
*/
|
76 |
-
define('CRYPT_BLOWFISH_MODE_ECB', 1);
|
77 |
-
/**
|
78 |
-
* Encrypt / decrypt using the Code Book Chaining mode.
|
79 |
-
*
|
80 |
-
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
|
81 |
-
*/
|
82 |
-
define('CRYPT_BLOWFISH_MODE_CBC', 2);
|
83 |
-
/**
|
84 |
-
* Encrypt / decrypt using the Cipher Feedback mode.
|
85 |
-
*
|
86 |
-
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
|
87 |
-
*/
|
88 |
-
define('CRYPT_BLOWFISH_MODE_CFB', 3);
|
89 |
-
/**
|
90 |
-
* Encrypt / decrypt using the Cipher Feedback mode.
|
91 |
-
*
|
92 |
-
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
|
93 |
-
*/
|
94 |
-
define('CRYPT_BLOWFISH_MODE_OFB', 4);
|
95 |
-
/**#@-*/
|
96 |
-
|
97 |
-
/**#@+
|
98 |
-
* @access private
|
99 |
-
* @see Crypt_Blowfish::Crypt_Blowfish()
|
100 |
-
*/
|
101 |
-
/**
|
102 |
-
* Toggles the internal implementation
|
103 |
-
*/
|
104 |
-
define('CRYPT_BLOWFISH_MODE_INTERNAL', 1);
|
105 |
-
/**
|
106 |
-
* Toggles the mcrypt implementation
|
107 |
-
*/
|
108 |
-
define('CRYPT_BLOWFISH_MODE_MCRYPT', 2);
|
109 |
-
/**#@-*/
|
110 |
-
|
111 |
-
/**
|
112 |
-
* Pure-PHP implementation of Blowfish.
|
113 |
-
*
|
114 |
-
* @author Jim Wigginton <terrafrost@php.net>
|
115 |
-
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
116 |
-
* @version 1.0
|
117 |
-
* @access public
|
118 |
-
* @package Crypt_Blowfish
|
119 |
-
*/
|
120 |
-
class Crypt_Blowfish {
|
121 |
-
/**
|
122 |
-
* The Key as String
|
123 |
-
*
|
124 |
-
* @see Crypt_Blowfish::setKey()
|
125 |
-
* @var Array
|
126 |
-
* @access private
|
127 |
-
*/
|
128 |
-
var $key = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
|
129 |
-
|
130 |
-
/**
|
131 |
-
* The Encryption Mode
|
132 |
-
*
|
133 |
-
* @see Crypt_Blowfish::Crypt_Blowfish()
|
134 |
-
* @var Integer
|
135 |
-
* @access private
|
136 |
-
*/
|
137 |
-
var $mode;
|
138 |
-
|
139 |
-
/**
|
140 |
-
* Continuous Buffer status
|
141 |
-
*
|
142 |
-
* @see Crypt_Blowfish::enableContinuousBuffer()
|
143 |
-
* @var Boolean
|
144 |
-
* @access private
|
145 |
-
*/
|
146 |
-
var $continuousBuffer = false;
|
147 |
-
|
148 |
-
/**
|
149 |
-
* Padding status
|
150 |
-
*
|
151 |
-
* @see Crypt_Blowfish::enablePadding()
|
152 |
-
* @var Boolean
|
153 |
-
* @access private
|
154 |
-
*/
|
155 |
-
var $padding = true;
|
156 |
-
|
157 |
-
/**
|
158 |
-
* The Initialization Vector
|
159 |
-
*
|
160 |
-
* @see Crypt_Blowfish::setIV()
|
161 |
-
* @var String
|
162 |
-
* @access private
|
163 |
-
*/
|
164 |
-
var $iv = "\0\0\0\0\0\0\0\0";
|
165 |
-
|
166 |
-
/**
|
167 |
-
* A "sliding" Initialization Vector
|
168 |
-
*
|
169 |
-
* @see Crypt_Blowfish::enableContinuousBuffer()
|
170 |
-
* @var String
|
171 |
-
* @access private
|
172 |
-
*/
|
173 |
-
var $encryptIV = "\0\0\0\0\0\0\0\0";
|
174 |
-
|
175 |
-
/**
|
176 |
-
* A "sliding" Initialization Vector
|
177 |
-
*
|
178 |
-
* @see Crypt_Blowfish::enableContinuousBuffer()
|
179 |
-
* @var String
|
180 |
-
* @access private
|
181 |
-
*/
|
182 |
-
var $decryptIV = "\0\0\0\0\0\0\0\0";
|
183 |
-
|
184 |
-
/**
|
185 |
-
* mcrypt resource for encryption
|
186 |
-
*
|
187 |
-
* The mcrypt resource can be recreated every time something needs to be created or it can be created just once.
|
188 |
-
* Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.
|
189 |
-
*
|
190 |
-
* @see Crypt_Blowfish::encrypt()
|
191 |
-
* @var String
|
192 |
-
* @access private
|
193 |
-
*/
|
194 |
-
var $enmcrypt;
|
195 |
-
|
196 |
-
/**
|
197 |
-
* mcrypt resource for decryption
|
198 |
-
*
|
199 |
-
* The mcrypt resource can be recreated every time something needs to be created or it can be created just once.
|
200 |
-
* Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.
|
201 |
-
*
|
202 |
-
* @see Crypt_Blowfish::decrypt()
|
203 |
-
* @var String
|
204 |
-
* @access private
|
205 |
-
*/
|
206 |
-
var $demcrypt;
|
207 |
-
|
208 |
-
/**
|
209 |
-
* Does the enmcrypt resource need to be (re)initialized?
|
210 |
-
*
|
211 |
-
* @see Crypt_Blowfish::setKey()
|
212 |
-
* @see Crypt_Blowfish::setIV()
|
213 |
-
* @var Boolean
|
214 |
-
* @access private
|
215 |
-
*/
|
216 |
-
var $enchanged = true;
|
217 |
-
|
218 |
-
/**
|
219 |
-
* Does the demcrypt resource need to be (re)initialized?
|
220 |
-
*
|
221 |
-
* @see Crypt_Blowfish::setKey()
|
222 |
-
* @see Crypt_Blowfish::setIV()
|
223 |
-
* @var Boolean
|
224 |
-
* @access private
|
225 |
-
*/
|
226 |
-
var $dechanged = true;
|
227 |
-
|
228 |
-
/**
|
229 |
-
* Is the mode one that is paddable?
|
230 |
-
*
|
231 |
-
* @see Crypt_Blowfish::Crypt_Blowfish()
|
232 |
-
* @var Boolean
|
233 |
-
* @access private
|
234 |
-
*/
|
235 |
-
var $paddable = false;
|
236 |
-
|
237 |
-
/**
|
238 |
-
* Encryption buffer for CTR, OFB and CFB modes
|
239 |
-
*
|
240 |
-
* @see Crypt_Blowfish::encrypt()
|
241 |
-
* @var Array
|
242 |
-
* @access private
|
243 |
-
*/
|
244 |
-
var $enbuffer = array('encrypted' => '', 'xor' => '', 'pos' => 0, 'enmcrypt_init' => true);
|
245 |
-
|
246 |
-
/**
|
247 |
-
* Decryption buffer for CTR, OFB and CFB modes
|
248 |
-
*
|
249 |
-
* @see Crypt_Blowfish::decrypt()
|
250 |
-
* @var Array
|
251 |
-
* @access private
|
252 |
-
*/
|
253 |
-
var $debuffer = array('ciphertext' => '', 'xor' => '', 'pos' => 0, 'demcrypt_init' => true);
|
254 |
-
|
255 |
-
/**
|
256 |
-
* mcrypt resource for CFB mode
|
257 |
-
*
|
258 |
-
* @see Crypt_Blowfish::encrypt()
|
259 |
-
* @see Crypt_Blowfish::decrypt()
|
260 |
-
* @var String
|
261 |
-
* @access private
|
262 |
-
*/
|
263 |
-
var $ecb;
|
264 |
-
|
265 |
-
/**
|
266 |
-
* Performance-optimized callback function for en/decrypt()
|
267 |
-
*
|
268 |
-
* @var Callback
|
269 |
-
* @access private
|
270 |
-
*/
|
271 |
-
var $inline_crypt;
|
272 |
-
|
273 |
-
/**
|
274 |
-
* The fixed subkeys boxes ($sbox0 - $sbox3) with 256 entries each
|
275 |
-
*
|
276 |
-
* S-Box 1
|
277 |
-
*
|
278 |
-
* @access private
|
279 |
-
* @var array
|
280 |
-
*/
|
281 |
-
var $sbox0 = array (
|
282 |
-
0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
|
283 |
-
0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
|
284 |
-
0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
|
285 |
-
0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
|
286 |
-
0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
|
287 |
-
0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
|
288 |
-
0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
|
289 |
-
0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
|
290 |
-
0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
|
291 |
-
0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
|
292 |
-
0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
|
293 |
-
0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
|
294 |
-
0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
|
295 |
-
0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
|
296 |
-
0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
|
297 |
-
0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
|
298 |
-
0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
|
299 |
-
0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
|
300 |
-
0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
|
301 |
-
0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
|
302 |
-
0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
|
303 |
-
0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
|
304 |
-
0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
|
305 |
-
0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
|
306 |
-
0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
|
307 |
-
0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
|
308 |
-
0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
|
309 |
-
0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
|
310 |
-
0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
|
311 |
-
0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
|
312 |
-
0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
|
313 |
-
0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a
|
314 |
-
);
|
315 |
-
|
316 |
-
/**
|
317 |
-
* S-Box 1
|
318 |
-
*
|
319 |
-
* @access private
|
320 |
-
* @var array
|
321 |
-
*/
|
322 |
-
var $sbox1 = array(
|
323 |
-
0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
|
324 |
-
0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
|
325 |
-
0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
|
326 |
-
0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
|
327 |
-
0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
|
328 |
-
0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
|
329 |
-
0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
|
330 |
-
0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
|
331 |
-
0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
|
332 |
-
0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
|
333 |
-
0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
|
334 |
-
0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
|
335 |
-
0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
|
336 |
-
0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
|
337 |
-
0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
|
338 |
-
0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
|
339 |
-
0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
|
340 |
-
0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
|
341 |
-
0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
|
342 |
-
0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
|
343 |
-
0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
|
344 |
-
0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
|
345 |
-
0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
|
346 |
-
0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
|
347 |
-
0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
|
348 |
-
0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
|
349 |
-
0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
|
350 |
-
0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
|
351 |
-
0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
|
352 |
-
0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
|
353 |
-
0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
|
354 |
-
0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7
|
355 |
-
);
|
356 |
-
|
357 |
-
/**
|
358 |
-
* S-Box 2
|
359 |
-
*
|
360 |
-
* @access private
|
361 |
-
* @var array
|
362 |
-
*/
|
363 |
-
var $sbox2 = array(
|
364 |
-
0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
|
365 |
-
0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
|
366 |
-
0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
|
367 |
-
0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
|
368 |
-
0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
|
369 |
-
0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
|
370 |
-
0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
|
371 |
-
0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
|
372 |
-
0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
|
373 |
-
0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
|
374 |
-
0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
|
375 |
-
0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
|
376 |
-
0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
|
377 |
-
0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
|
378 |
-
0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
|
379 |
-
0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
|
380 |
-
0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
|
381 |
-
0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
|
382 |
-
0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
|
383 |
-
0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
|
384 |
-
0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
|
385 |
-
0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
|
386 |
-
0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
|
387 |
-
0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
|
388 |
-
0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
|
389 |
-
0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
|
390 |
-
0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
|
391 |
-
0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
|
392 |
-
0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
|
393 |
-
0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
|
394 |
-
0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
|
395 |
-
0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0
|
396 |
-
);
|
397 |
-
|
398 |
-
/**
|
399 |
-
* S-Box 3
|
400 |
-
*
|
401 |
-
* @access private
|
402 |
-
* @var array
|
403 |
-
*/
|
404 |
-
var $sbox3 = array(
|
405 |
-
0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
|
406 |
-
0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
|
407 |
-
0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
|
408 |
-
0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
|
409 |
-
0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
|
410 |
-
0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
|
411 |
-
0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
|
412 |
-
0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
|
413 |
-
0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
|
414 |
-
0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
|
415 |
-
0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
|
416 |
-
0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
|
417 |
-
0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
|
418 |
-
0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
|
419 |
-
0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
|
420 |
-
0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
|
421 |
-
0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
|
422 |
-
0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
|
423 |
-
0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
|
424 |
-
0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
|
425 |
-
0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
|
426 |
-
0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
|
427 |
-
0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
|
428 |
-
0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
|
429 |
-
0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
|
430 |
-
0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
|
431 |
-
0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
|
432 |
-
0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
|
433 |
-
0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
|
434 |
-
0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
|
435 |
-
0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
|
436 |
-
0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
|
437 |
-
);
|
438 |
-
|
439 |
-
/**
|
440 |
-
* P-Array consists of 18 32-bit subkeys
|
441 |
-
*
|
442 |
-
* @var array $parray
|
443 |
-
* @access private
|
444 |
-
*/
|
445 |
-
var $parray = array(
|
446 |
-
0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0,
|
447 |
-
0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
|
448 |
-
0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b
|
449 |
-
);
|
450 |
-
|
451 |
-
/**
|
452 |
-
* The BCTX-working Array
|
453 |
-
*
|
454 |
-
* Holds the expanded key [p] and the key-depended s-boxes [sb]
|
455 |
-
*
|
456 |
-
* @var array $bctx
|
457 |
-
* @access private
|
458 |
-
*/
|
459 |
-
var $bctx = array();
|
460 |
-
|
461 |
-
/**
|
462 |
-
* Default Constructor.
|
463 |
-
*
|
464 |
-
* Determines whether or not the mcrypt extension should be used.
|
465 |
-
* If not explictly set, CRYPT_BLOWFISH_MODE_CBC will be used.
|
466 |
-
*
|
467 |
-
* @param optional Integer $mode
|
468 |
-
* @access public
|
469 |
-
*/
|
470 |
-
function
|
471 |
-
{
|
472 |
-
if ( !defined('CRYPT_BLOWFISH_MODE') ) {
|
473 |
-
switch (true) {
|
474 |
-
case extension_loaded('mcrypt') && in_array('blowfish', mcrypt_list_algorithms()):
|
475 |
-
define('CRYPT_BLOWFISH_MODE', CRYPT_BLOWFISH_MODE_MCRYPT);
|
476 |
-
break;
|
477 |
-
default:
|
478 |
-
define('CRYPT_BLOWFISH_MODE', CRYPT_BLOWFISH_MODE_INTERNAL);
|
479 |
-
}
|
480 |
-
}
|
481 |
-
|
482 |
-
switch ( CRYPT_BLOWFISH_MODE ) {
|
483 |
-
case CRYPT_BLOWFISH_MODE_MCRYPT:
|
484 |
-
switch ($mode) {
|
485 |
-
case CRYPT_BLOWFISH_MODE_ECB:
|
486 |
-
$this->paddable = true;
|
487 |
-
$this->mode = MCRYPT_MODE_ECB;
|
488 |
-
break;
|
489 |
-
case CRYPT_BLOWFISH_MODE_CTR:
|
490 |
-
$this->mode = 'ctr';
|
491 |
-
break;
|
492 |
-
case CRYPT_BLOWFISH_MODE_CFB:
|
493 |
-
$this->mode = 'ncfb';
|
494 |
-
$this->ecb = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_ECB, '');
|
495 |
-
break;
|
496 |
-
case CRYPT_BLOWFISH_MODE_OFB:
|
497 |
-
$this->mode = MCRYPT_MODE_NOFB;
|
498 |
-
break;
|
499 |
-
case CRYPT_BLOWFISH_MODE_CBC:
|
500 |
-
default:
|
501 |
-
$this->paddable = true;
|
502 |
-
$this->mode = MCRYPT_MODE_CBC;
|
503 |
-
}
|
504 |
-
$this->enmcrypt = mcrypt_module_open(MCRYPT_BLOWFISH, '', $this->mode, '');
|
505 |
-
$this->demcrypt = mcrypt_module_open(MCRYPT_BLOWFISH, '', $this->mode, '');
|
506 |
-
|
507 |
-
break;
|
508 |
-
default:
|
509 |
-
switch ($mode) {
|
510 |
-
case CRYPT_BLOWFISH_MODE_ECB:
|
511 |
-
case CRYPT_BLOWFISH_MODE_CBC:
|
512 |
-
$this->paddable = true;
|
513 |
-
$this->mode = $mode;
|
514 |
-
break;
|
515 |
-
case CRYPT_BLOWFISH_MODE_CTR:
|
516 |
-
case CRYPT_BLOWFISH_MODE_CFB:
|
517 |
-
case CRYPT_BLOWFISH_MODE_OFB:
|
518 |
-
$this->mode = $mode;
|
519 |
-
break;
|
520 |
-
default:
|
521 |
-
$this->paddable = true;
|
522 |
-
$this->mode = CRYPT_BLOWFISH_MODE_CBC;
|
523 |
-
}
|
524 |
-
$this->inline_crypt_setup();
|
525 |
-
}
|
526 |
-
}
|
527 |
-
|
528 |
-
/**
|
529 |
-
* Sets the key.
|
530 |
-
*
|
531 |
-
* Keys can be of any length. Blowfish, itself, requires the use of a key between 32 and max. 448-bits long.
|
532 |
-
* If the key is less than 32-bits we NOT fill the key to 32bit but let the key as it is to be compatible
|
533 |
-
* with mcrypt because mcrypt act this way with blowfish key's < 32 bits.
|
534 |
-
*
|
535 |
-
* If the key is more than 448-bits, we trim the excess bits.
|
536 |
-
*
|
537 |
-
* If the key is not explicitly set, or empty, it'll be assumed a 128 bits key to be all null bytes.
|
538 |
-
*
|
539 |
-
* @access public
|
540 |
-
* @param String $key
|
541 |
-
*/
|
542 |
-
function setKey($key)
|
543 |
-
{
|
544 |
-
$keylength = strlen($key);
|
545 |
-
|
546 |
-
if (!$keylength) {
|
547 |
-
$key = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
|
548 |
-
}
|
549 |
-
elseif ($keylength > 56) {
|
550 |
-
$key = substr($key, 0, 56);
|
551 |
-
}
|
552 |
-
|
553 |
-
$this->key = $key;
|
554 |
-
|
555 |
-
$this->enchanged = true;
|
556 |
-
$this->dechanged = true;
|
557 |
-
|
558 |
-
if (CRYPT_BLOWFISH_MODE == CRYPT_BLOWFISH_MODE_MCRYPT) {
|
559 |
-
return;
|
560 |
-
}
|
561 |
-
|
562 |
-
/* key-expanding p[] and S-Box building sb[] */
|
563 |
-
$this->bctx = array(
|
564 |
-
'p' => array(),
|
565 |
-
'sb' => array(
|
566 |
-
$this->sbox0,
|
567 |
-
$this->sbox1,
|
568 |
-
$this->sbox2,
|
569 |
-
$this->sbox3
|
570 |
-
)
|
571 |
-
);
|
572 |
-
|
573 |
-
// unpack binary string in unsigned chars
|
574 |
-
$key = array_values(unpack('C*', $key));
|
575 |
-
$keyl = count($key);
|
576 |
-
for ($j = 0, $i = 0; $i < 18; ++$i) {
|
577 |
-
// xor P1 with the first 32-bits of the key, xor P2 with the second 32-bits ...
|
578 |
-
for ($data = 0, $k = 0; $k < 4; ++$k) {
|
579 |
-
$data = ($data << 8) | $key[$j];
|
580 |
-
if (++$j >= $keyl) {
|
581 |
-
$j = 0;
|
582 |
-
}
|
583 |
-
}
|
584 |
-
$this->bctx['p'][] = $this->parray[$i] ^ $data;
|
585 |
-
}
|
586 |
-
|
587 |
-
// encrypt the zero-string, replace P1 and P2 with the encrypted data,
|
588 |
-
// encrypt P3 and P4 with the new P1 and P2, do it with all P-array and subkeys
|
589 |
-
$datal = 0;
|
590 |
-
$datar = 0;
|
591 |
-
for ($i = 0; $i < 18; $i += 2) {
|
592 |
-
$this->_encryptBlock($datal, $datar);
|
593 |
-
$this->bctx['p'][$i ] = $datal;
|
594 |
-
$this->bctx['p'][$i + 1] = $datar;
|
595 |
-
}
|
596 |
-
for ($i = 0; $i < 4; ++$i) {
|
597 |
-
for ($j = 0; $j < 256; $j += 2) {
|
598 |
-
$this->_encryptBlock($datal, $datar);
|
599 |
-
$this->bctx['sb'][$i][$j ] = $datal;
|
600 |
-
$this->bctx['sb'][$i][$j + 1] = $datar;
|
601 |
-
}
|
602 |
-
}
|
603 |
-
}
|
604 |
-
|
605 |
-
/**
|
606 |
-
* Encrypt the block.
|
607 |
-
*
|
608 |
-
* @access private
|
609 |
-
* @param int $Xl left uInt32 part of the block
|
610 |
-
* @param int $Xr right uInt32 part of the block
|
611 |
-
* @return void
|
612 |
-
*/
|
613 |
-
function _encryptBlock(&$Xl, &$Xr)
|
614 |
-
{
|
615 |
-
$p = $this->bctx['p'];
|
616 |
-
$sb_0 = $this->bctx['sb'][0];
|
617 |
-
$sb_1 = $this->bctx['sb'][1];
|
618 |
-
$sb_2 = $this->bctx['sb'][2];
|
619 |
-
$sb_3 = $this->bctx['sb'][3];
|
620 |
-
$l = $Xl;
|
621 |
-
$r = $Xr;
|
622 |
-
|
623 |
-
$i = -1;
|
624 |
-
while ($i < 15) {
|
625 |
-
$l^= $p[++$i];
|
626 |
-
$r^= ($sb_0[$l >> 24 & 0xff] +
|
627 |
-
$sb_1[$l >> 16 & 0xff] ^
|
628 |
-
$sb_2[$l >> 8 & 0xff]) +
|
629 |
-
$sb_3[$l & 0xff];
|
630 |
-
|
631 |
-
$r^= $p[++$i];
|
632 |
-
$l^= ($sb_0[$r >> 24 & 0xff] +
|
633 |
-
$sb_1[$r >> 16 & 0xff] ^
|
634 |
-
$sb_2[$r >> 8 & 0xff]) +
|
635 |
-
$sb_3[$r & 0xff];
|
636 |
-
|
637 |
-
}
|
638 |
-
$Xr = $l ^ $p[16];
|
639 |
-
$Xl = $r ^ $p[17];
|
640 |
-
}
|
641 |
-
|
642 |
-
/**
|
643 |
-
* Sets the password.
|
644 |
-
*
|
645 |
-
* Depending on what $method is set to, setPassword()'s (optional) parameters are as follows:
|
646 |
-
* {@link http://en.wikipedia.org/wiki/PBKDF2 pbkdf2}:
|
647 |
-
* $hash, $salt, $count
|
648 |
-
*
|
649 |
-
* @param String $password
|
650 |
-
* @param optional String $method
|
651 |
-
* @access public
|
652 |
-
*/
|
653 |
-
function setPassword($password, $method = 'pbkdf2')
|
654 |
-
{
|
655 |
-
$key = '';
|
656 |
-
|
657 |
-
switch ($method) {
|
658 |
-
default: // 'pbkdf2'
|
659 |
-
list(, , $hash, $salt, $count) = func_get_args();
|
660 |
-
if (!isset($hash)) {
|
661 |
-
$hash = 'sha1';
|
662 |
-
}
|
663 |
-
// WPA and WPA2 use the SSID as the salt
|
664 |
-
if (!isset($salt)) {
|
665 |
-
$salt = 'phpseclib/salt';
|
666 |
-
}
|
667 |
-
// RFC2898#section-4.2 uses 1,000 iterations by default
|
668 |
-
// WPA and WPA2 use 4,096.
|
669 |
-
if (!isset($count)) {
|
670 |
-
$count = 1000;
|
671 |
-
}
|
672 |
-
|
673 |
-
if (!class_exists('Crypt_Hash')) {
|
674 |
-
require_once('Crypt/Hash.php');
|
675 |
-
}
|
676 |
-
|
677 |
-
$i = 1;
|
678 |
-
while (strlen($key) < 56) {
|
679 |
-
//$dk.= $this->_pbkdf($password, $salt, $count, $i++);
|
680 |
-
$hmac = new Crypt_Hash();
|
681 |
-
$hmac->setHash($hash);
|
682 |
-
$hmac->setKey($password);
|
683 |
-
$f = $u = $hmac->hash($salt . pack('N', $i++));
|
684 |
-
for ($j = 2; $j <= $count; $j++) {
|
685 |
-
$u = $hmac->hash($u);
|
686 |
-
$f^= $u;
|
687 |
-
}
|
688 |
-
$key.= $f;
|
689 |
-
}
|
690 |
-
}
|
691 |
-
|
692 |
-
$this->setKey($key);
|
693 |
-
}
|
694 |
-
|
695 |
-
/**
|
696 |
-
* Sets the initialization vector. (optional)
|
697 |
-
*
|
698 |
-
* SetIV is not required when CRYPT_BLOWFISH_MODE_ECB is being used. If not explictly set, it'll be assumed
|
699 |
-
* to be all null bytes.
|
700 |
-
*
|
701 |
-
* @access public
|
702 |
-
* @param String $iv
|
703 |
-
*/
|
704 |
-
function setIV($iv)
|
705 |
-
{
|
706 |
-
$this->encryptIV = $this->decryptIV = $this->iv = str_pad(substr($iv, 0, 8), 8, chr(0));
|
707 |
-
$this->enchanged = true;
|
708 |
-
$this->dechanged = true;
|
709 |
-
}
|
710 |
-
|
711 |
-
/**
|
712 |
-
* Encrypts a message.
|
713 |
-
*
|
714 |
-
* $plaintext will be padded with up to 8 additional bytes. Other Blowfish implementations may or may not pad in the
|
715 |
-
* same manner. Other common approaches to padding and the reasons why it's necessary are discussed in the following
|
716 |
-
* URL:
|
717 |
-
*
|
718 |
-
* {@link http://www.di-mgt.com.au/cryptopad.html http://www.di-mgt.com.au/cryptopad.html}
|
719 |
-
*
|
720 |
-
* An alternative to padding is to, separately, send the length of the file. This is what SSH, in fact, does.
|
721 |
-
* strlen($plaintext) will still need to be a multiple of 8, however, arbitrary values can be added to make it that
|
722 |
-
* length.
|
723 |
-
*
|
724 |
-
* @see Crypt_Blowfish::decrypt()
|
725 |
-
* @access public
|
726 |
-
* @param String $plaintext
|
727 |
-
*/
|
728 |
-
function encrypt($plaintext)
|
729 |
-
{
|
730 |
-
if ( CRYPT_BLOWFISH_MODE == CRYPT_BLOWFISH_MODE_MCRYPT ) {
|
731 |
-
if ($this->paddable) {
|
732 |
-
$plaintext = $this->_pad($plaintext);
|
733 |
-
}
|
734 |
-
|
735 |
-
if ($this->enchanged) {
|
736 |
-
mcrypt_generic_init($this->enmcrypt, $this->key, $this->encryptIV);
|
737 |
-
if ($this->mode == 'ncfb') {
|
738 |
-
mcrypt_generic_init($this->ecb, $this->key, "\0\0\0\0\0\0\0\0");
|
739 |
-
}
|
740 |
-
$this->enchanged = false;
|
741 |
-
}
|
742 |
-
|
743 |
-
if ($this->mode != 'ncfb' || !$this->continuousBuffer) {
|
744 |
-
$ciphertext = mcrypt_generic($this->enmcrypt, $plaintext);
|
745 |
-
} else {
|
746 |
-
$iv = &$this->encryptIV;
|
747 |
-
$pos = &$this->enbuffer['pos'];
|
748 |
-
$len = strlen($plaintext);
|
749 |
-
$ciphertext = '';
|
750 |
-
$i = 0;
|
751 |
-
if ($pos) {
|
752 |
-
$orig_pos = $pos;
|
753 |
-
$max = 8 - $pos;
|
754 |
-
if ($len >= $max) {
|
755 |
-
$i = $max;
|
756 |
-
$len-= $max;
|
757 |
-
$pos = 0;
|
758 |
-
} else {
|
759 |
-
$i = $len;
|
760 |
-
$pos+= $len;
|
761 |
-
$len = 0;
|
762 |
-
}
|
763 |
-
$ciphertext = substr($iv, $orig_pos) ^ $plaintext;
|
764 |
-
$iv = substr_replace($iv, $ciphertext, $orig_pos, $i);
|
765 |
-
$this->enbuffer['enmcrypt_init'] = true;
|
766 |
-
}
|
767 |
-
if ($len >= 8) {
|
768 |
-
if ($this->enbuffer['enmcrypt_init'] === false || $len > 600) {
|
769 |
-
if ($this->enbuffer['enmcrypt_init'] === true) {
|
770 |
-
mcrypt_generic_init($this->enmcrypt, $this->key, $iv);
|
771 |
-
$this->enbuffer['enmcrypt_init'] = false;
|
772 |
-
}
|
773 |
-
$ciphertext.= mcrypt_generic($this->enmcrypt, substr($plaintext, $i, $len - $len % 8));
|
774 |
-
$iv = substr($ciphertext, -8);
|
775 |
-
$len%= 8;
|
776 |
-
} else {
|
777 |
-
while ($len >= 8) {
|
778 |
-
$iv = mcrypt_generic($this->ecb, $iv) ^ substr($plaintext, $i, 8);
|
779 |
-
$ciphertext.= $iv;
|
780 |
-
$len-= 8;
|
781 |
-
$i+= 8;
|
782 |
-
}
|
783 |
-
}
|
784 |
-
}
|
785 |
-
if ($len) {
|
786 |
-
$iv = mcrypt_generic($this->ecb, $iv);
|
787 |
-
$block = $iv ^ substr($plaintext, -$len);
|
788 |
-
$iv = substr_replace($iv, $block, 0, $len);
|
789 |
-
$ciphertext.= $block;
|
790 |
-
$pos = $len;
|
791 |
-
}
|
792 |
-
return $ciphertext;
|
793 |
-
}
|
794 |
-
|
795 |
-
if (!$this->continuousBuffer) {
|
796 |
-
mcrypt_generic_init($this->enmcrypt, $this->key, $this->encryptIV);
|
797 |
-
}
|
798 |
-
|
799 |
-
return $ciphertext;
|
800 |
-
}
|
801 |
-
|
802 |
-
if (empty($this->bctx)) {
|
803 |
-
$this->setKey($this->key);
|
804 |
-
}
|
805 |
-
|
806 |
-
$inline = $this->inline_crypt;
|
807 |
-
return $inline('encrypt', $this, $plaintext);
|
808 |
-
}
|
809 |
-
|
810 |
-
/**
|
811 |
-
* Decrypts a message.
|
812 |
-
*
|
813 |
-
* If strlen($ciphertext) is not a multiple of 8, null bytes will be added to the end of the string until it is.
|
814 |
-
*
|
815 |
-
* @see Crypt_Blowfish::encrypt()
|
816 |
-
* @access public
|
817 |
-
* @param String $ciphertext
|
818 |
-
*/
|
819 |
-
function decrypt($ciphertext)
|
820 |
-
{
|
821 |
-
if ( CRYPT_BLOWFISH_MODE == CRYPT_BLOWFISH_MODE_MCRYPT ) {
|
822 |
-
if ($this->paddable) {
|
823 |
-
// we pad with chr(0) since that's what mcrypt_generic does. to quote from http://php.net/function.mcrypt-generic :
|
824 |
-
// "The data is padded with "\0" to make sure the length of the data is n * blocksize."
|
825 |
-
$ciphertext = str_pad($ciphertext, strlen($ciphertext) + (8 - strlen($ciphertext) % 8) % 8, chr(0));
|
826 |
-
}
|
827 |
-
|
828 |
-
if ($this->dechanged) {
|
829 |
-
mcrypt_generic_init($this->demcrypt, $this->key, $this->decryptIV);
|
830 |
-
if ($this->mode == 'ncfb') {
|
831 |
-
mcrypt_generic_init($this->ecb, $this->key, "\0\0\0\0\0\0\0\0");
|
832 |
-
}
|
833 |
-
$this->dechanged = false;
|
834 |
-
}
|
835 |
-
|
836 |
-
if ($this->mode != 'ncfb' || !$this->continuousBuffer) {
|
837 |
-
$plaintext = mdecrypt_generic($this->demcrypt, $ciphertext);
|
838 |
-
} else {
|
839 |
-
$iv = &$this->decryptIV;
|
840 |
-
$pos = &$this->debuffer['pos'];
|
841 |
-
$len = strlen($ciphertext);
|
842 |
-
$plaintext = '';
|
843 |
-
$i = 0;
|
844 |
-
if ($pos) {
|
845 |
-
$orig_pos = $pos;
|
846 |
-
$max = 8 - $pos;
|
847 |
-
if ($len >= $max) {
|
848 |
-
$i = $max;
|
849 |
-
$len-= $max;
|
850 |
-
$pos = 0;
|
851 |
-
} else {
|
852 |
-
$i = $len;
|
853 |
-
$pos+= $len;
|
854 |
-
$len = 0;
|
855 |
-
}
|
856 |
-
$plaintext = substr($iv, $orig_pos) ^ $ciphertext;
|
857 |
-
$iv = substr_replace($iv, substr($ciphertext, 0, $i), $orig_pos, $i);
|
858 |
-
}
|
859 |
-
if ($len >= 8) {
|
860 |
-
$cb = substr($ciphertext, $i, $len - $len % 8);
|
861 |
-
$plaintext.= mcrypt_generic($this->ecb, $iv . $cb) ^ $cb;
|
862 |
-
$iv = substr($cb, -8);
|
863 |
-
$len%= 8;
|
864 |
-
}
|
865 |
-
if ($len) {
|
866 |
-
$iv = mcrypt_generic($this->ecb, $iv);
|
867 |
-
$plaintext.= $iv ^ substr($ciphertext, -$len);
|
868 |
-
$iv = substr_replace($iv, substr($ciphertext, -$len), 0, $len);
|
869 |
-
$pos = $len;
|
870 |
-
}
|
871 |
-
return $plaintext;
|
872 |
-
}
|
873 |
-
|
874 |
-
if (!$this->continuousBuffer) {
|
875 |
-
mcrypt_generic_init($this->demcrypt, $this->key, $this->decryptIV);
|
876 |
-
}
|
877 |
-
|
878 |
-
return $this->paddable ? $this->_unpad($plaintext) : $plaintext;
|
879 |
-
}
|
880 |
-
|
881 |
-
if (empty($this->bctx)) {
|
882 |
-
$this->setKey($this->key);
|
883 |
-
}
|
884 |
-
|
885 |
-
$inline = $this->inline_crypt;
|
886 |
-
return $inline('decrypt', $this, $ciphertext);
|
887 |
-
}
|
888 |
-
|
889 |
-
/**
|
890 |
-
* Treat consecutive "packets" as if they are a continuous buffer.
|
891 |
-
*
|
892 |
-
* @see Crypt_Blowfish::disableContinuousBuffer()
|
893 |
-
* @access public
|
894 |
-
*/
|
895 |
-
function enableContinuousBuffer()
|
896 |
-
{
|
897 |
-
$this->continuousBuffer = true;
|
898 |
-
}
|
899 |
-
|
900 |
-
/**
|
901 |
-
* Treat consecutive packets as if they are a discontinuous buffer.
|
902 |
-
*
|
903 |
-
* The default behavior.
|
904 |
-
*
|
905 |
-
* @see Crypt_Blowfish::enableContinuousBuffer()
|
906 |
-
* @access public
|
907 |
-
*/
|
908 |
-
function disableContinuousBuffer()
|
909 |
-
{
|
910 |
-
$this->continuousBuffer = false;
|
911 |
-
$this->encryptIV = $this->iv;
|
912 |
-
$this->decryptIV = $this->iv;
|
913 |
-
$this->enbuffer = array('encrypted' => '', 'xor' => '', 'pos' => 0, 'enmcrypt_init' => true);
|
914 |
-
$this->debuffer = array('ciphertext' => '', 'xor' => '', 'pos' => 0, 'demcrypt_init' => true);
|
915 |
-
|
916 |
-
if (CRYPT_BLOWFISH_MODE == CRYPT_BLOWFISH_MODE_MCRYPT) {
|
917 |
-
mcrypt_generic_init($this->enmcrypt, $this->key, $this->iv);
|
918 |
-
mcrypt_generic_init($this->demcrypt, $this->key, $this->iv);
|
919 |
-
}
|
920 |
-
}
|
921 |
-
|
922 |
-
/**
|
923 |
-
* Pad "packets".
|
924 |
-
*
|
925 |
-
* Blowfish works by encrypting 8 bytes at a time. If you ever need to encrypt or decrypt something that's not
|
926 |
-
* a multiple of 8, it becomes necessary to pad the input so that it's length is a multiple of eight.
|
927 |
-
*
|
928 |
-
* Padding is enabled by default. Sometimes, however, it is undesirable to pad strings. Such is the case in SSH1,
|
929 |
-
* where "packets" are padded with random bytes before being encrypted. Unpad these packets and you risk stripping
|
930 |
-
* away characters that shouldn't be stripped away. (SSH knows how many bytes are added because the length is
|
931 |
-
* transmitted separately)
|
932 |
-
*
|
933 |
-
* @see Crypt_Blowfish::disablePadding()
|
934 |
-
* @access public
|
935 |
-
*/
|
936 |
-
function enablePadding()
|
937 |
-
{
|
938 |
-
$this->padding = true;
|
939 |
-
}
|
940 |
-
|
941 |
-
/**
|
942 |
-
* Do not pad packets.
|
943 |
-
*
|
944 |
-
* @see Crypt_Blowfish::enablePadding()
|
945 |
-
* @access public
|
946 |
-
*/
|
947 |
-
function disablePadding()
|
948 |
-
{
|
949 |
-
$this->padding = false;
|
950 |
-
}
|
951 |
-
|
952 |
-
/**
|
953 |
-
* Pads a string
|
954 |
-
*
|
955 |
-
* Pads a string using the RSA PKCS padding standards so that its length is a multiple of the blocksize (8).
|
956 |
-
*
|
957 |
-
* If padding is disabled and $text is not a multiple of the blocksize, the string will be padded regardless
|
958 |
-
* and padding will, hence forth, be enabled.
|
959 |
-
*
|
960 |
-
* @see Crypt_Blowfish::_unpad()
|
961 |
-
* @access private
|
962 |
-
*/
|
963 |
-
function _pad($text)
|
964 |
-
{
|
965 |
-
$length = strlen($text);
|
966 |
-
|
967 |
-
if (!$this->padding) {
|
968 |
-
if ($length % 8 == 0) {
|
969 |
-
return $text;
|
970 |
-
} else {
|
971 |
-
user_error("The plaintext's length ($length) is not a multiple of the block size (8)");
|
972 |
-
$this->padding = true;
|
973 |
-
}
|
974 |
-
}
|
975 |
-
|
976 |
-
$pad = 8 - ($length % 8);
|
977 |
-
|
978 |
-
return str_pad($text, $length + $pad, chr($pad));
|
979 |
-
}
|
980 |
-
|
981 |
-
/**
|
982 |
-
* Unpads a string
|
983 |
-
*
|
984 |
-
* If padding is enabled and the reported padding length is invalid the encryption key will be assumed to be wrong
|
985 |
-
* and false will be returned.
|
986 |
-
*
|
987 |
-
* @see Crypt_Blowfish::_pad()
|
988 |
-
* @access private
|
989 |
-
*/
|
990 |
-
function _unpad($text)
|
991 |
-
{
|
992 |
-
if (!$this->padding) {
|
993 |
-
return $text;
|
994 |
-
}
|
995 |
-
|
996 |
-
$length = ord($text[strlen($text) - 1]);
|
997 |
-
|
998 |
-
if (!$length || $length > 8) {
|
999 |
-
return false;
|
1000 |
-
}
|
1001 |
-
|
1002 |
-
return substr($text, 0, -$length);
|
1003 |
-
}
|
1004 |
-
|
1005 |
-
/**
|
1006 |
-
* String Shift
|
1007 |
-
*
|
1008 |
-
* Inspired by array_shift
|
1009 |
-
*
|
1010 |
-
* @param String $string
|
1011 |
-
* @return String
|
1012 |
-
* @access private
|
1013 |
-
*/
|
1014 |
-
function _string_shift(&$string)
|
1015 |
-
{
|
1016 |
-
$substr = substr($string, 0, 8);
|
1017 |
-
$string = substr($string, 8);
|
1018 |
-
return $substr;
|
1019 |
-
}
|
1020 |
-
|
1021 |
-
/**
|
1022 |
-
* Generate CTR XOR encryption key
|
1023 |
-
*
|
1024 |
-
* Encrypt the output of this and XOR it against the ciphertext / plaintext to get the
|
1025 |
-
* plaintext / ciphertext in CTR mode.
|
1026 |
-
*
|
1027 |
-
* @see Crypt_Blowfish::decrypt()
|
1028 |
-
* @see Crypt_Blowfish::encrypt()
|
1029 |
-
* @access public
|
1030 |
-
* @param String $iv
|
1031 |
-
*/
|
1032 |
-
function _generate_xor(&$iv)
|
1033 |
-
{
|
1034 |
-
$xor = $iv;
|
1035 |
-
for ($j = 4; $j <= 8; $j+=4) {
|
1036 |
-
$temp = substr($iv, -$j, 4);
|
1037 |
-
switch ($temp) {
|
1038 |
-
case "\xFF\xFF\xFF\xFF":
|
1039 |
-
$iv = substr_replace($iv, "\x00\x00\x00\x00", -$j, 4);
|
1040 |
-
break;
|
1041 |
-
case "\x7F\xFF\xFF\xFF":
|
1042 |
-
$iv = substr_replace($iv, "\x80\x00\x00\x00", -$j, 4);
|
1043 |
-
break 2;
|
1044 |
-
default:
|
1045 |
-
extract(unpack('Ncount', $temp));
|
1046 |
-
$iv = substr_replace($iv, pack('N', $count + 1), -$j, 4);
|
1047 |
-
break 2;
|
1048 |
-
}
|
1049 |
-
}
|
1050 |
-
|
1051 |
-
return $xor;
|
1052 |
-
}
|
1053 |
-
|
1054 |
-
/**
|
1055 |
-
* Creates performance-optimized function for de/encrypt(), storing it in $this->inline_crypt
|
1056 |
-
*
|
1057 |
-
* @access private
|
1058 |
-
*/
|
1059 |
-
function inline_crypt_setup()
|
1060 |
-
{/*{{{*/
|
1061 |
-
$lambda_functions =& Crypt_Blowfish::get_lambda_functions();
|
1062 |
-
$block_size = 8;
|
1063 |
-
$mode = $this->mode;
|
1064 |
-
$code_hash = "$mode";
|
1065 |
-
|
1066 |
-
if (!isset($lambda_functions[$code_hash])) {
|
1067 |
-
$init_cryptBlock = '
|
1068 |
-
extract($self->bctx["p"], EXTR_PREFIX_ALL, "p");
|
1069 |
-
extract($self->bctx["sb"], EXTR_PREFIX_ALL, "sb");
|
1070 |
-
';
|
1071 |
-
|
1072 |
-
// Generating encrypt code:
|
1073 |
-
$_encryptBlock = '
|
1074 |
-
$in = unpack("N*", $in);
|
1075 |
-
$l = $in[1];
|
1076 |
-
$r = $in[2];
|
1077 |
-
';
|
1078 |
-
for ($i = 0; $i < 16; $i+= 2) {
|
1079 |
-
$_encryptBlock.= '
|
1080 |
-
$l^= $p_'.($i).';
|
1081 |
-
$r^= ($sb_0[$l >> 24 & 0xff] +
|
1082 |
-
$sb_1[$l >> 16 & 0xff] ^
|
1083 |
-
$sb_2[$l >> 8 & 0xff]) +
|
1084 |
-
$sb_3[$l & 0xff];
|
1085 |
-
|
1086 |
-
$r^= $p_'.($i + 1).';
|
1087 |
-
$l^= ($sb_0[$r >> 24 & 0xff] +
|
1088 |
-
$sb_1[$r >> 16 & 0xff] ^
|
1089 |
-
$sb_2[$r >> 8 & 0xff]) +
|
1090 |
-
$sb_3[$r & 0xff];
|
1091 |
-
';
|
1092 |
-
}
|
1093 |
-
$_encryptBlock.= '
|
1094 |
-
$in = pack("N*", $r ^ $p_17, $l ^ $p_16);
|
1095 |
-
';
|
1096 |
-
|
1097 |
-
// Generating decrypt code:
|
1098 |
-
$_decryptBlock = '
|
1099 |
-
$in = unpack("N*", $in);
|
1100 |
-
$l = $in[1];
|
1101 |
-
$r = $in[2];
|
1102 |
-
';
|
1103 |
-
|
1104 |
-
for ($i = 17; $i > 2; $i-= 2) {
|
1105 |
-
$_decryptBlock.= '
|
1106 |
-
$l^= $p_'.($i).';
|
1107 |
-
$r^= ($sb_0[$l >> 24 & 0xff] +
|
1108 |
-
$sb_1[$l >> 16 & 0xff] ^
|
1109 |
-
$sb_2[$l >> 8 & 0xff]) +
|
1110 |
-
$sb_3[$l & 0xff];
|
1111 |
-
|
1112 |
-
$r^= $p_'.($i - 1).';
|
1113 |
-
$l^= ($sb_0[$r >> 24 & 0xff] +
|
1114 |
-
$sb_1[$r >> 16 & 0xff] ^
|
1115 |
-
$sb_2[$r >> 8 & 0xff]) +
|
1116 |
-
$sb_3[$r & 0xff];
|
1117 |
-
';
|
1118 |
-
}
|
1119 |
-
|
1120 |
-
$_decryptBlock.= '
|
1121 |
-
$in = pack("N*", $r ^ $p_0, $l ^ $p_1);
|
1122 |
-
';
|
1123 |
-
|
1124 |
-
// Generating mode of operation code:
|
1125 |
-
switch ($mode) {
|
1126 |
-
case CRYPT_BLOWFISH_MODE_ECB:
|
1127 |
-
$encrypt = '
|
1128 |
-
$ciphertext = "";
|
1129 |
-
$text = $self->_pad($text);
|
1130 |
-
$plaintext_len = strlen($text);
|
1131 |
-
|
1132 |
-
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
|
1133 |
-
$in = substr($text, $i, '.$block_size.');
|
1134 |
-
'.$_encryptBlock.'
|
1135 |
-
$ciphertext.= $in;
|
1136 |
-
}
|
1137 |
-
return $ciphertext;
|
1138 |
-
';
|
1139 |
-
|
1140 |
-
$decrypt = '
|
1141 |
-
$plaintext = "";
|
1142 |
-
$text = str_pad($text, strlen($text) + ('.$block_size.' - strlen($text) % '.$block_size.') % '.$block_size.', chr(0));
|
1143 |
-
$ciphertext_len = strlen($text);
|
1144 |
-
|
1145 |
-
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') {
|
1146 |
-
$in = substr($text, $i, '.$block_size.');
|
1147 |
-
'.$_decryptBlock.'
|
1148 |
-
$plaintext.= $in;
|
1149 |
-
}
|
1150 |
-
|
1151 |
-
return $self->_unpad($plaintext);
|
1152 |
-
';
|
1153 |
-
break;
|
1154 |
-
case CRYPT_BLOWFISH_MODE_CBC:
|
1155 |
-
$encrypt = '
|
1156 |
-
$ciphertext = "";
|
1157 |
-
$text = $self->_pad($text);
|
1158 |
-
$plaintext_len = strlen($text);
|
1159 |
-
|
1160 |
-
$in = $self->encryptIV;
|
1161 |
-
|
1162 |
-
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
|
1163 |
-
$in = substr($text, $i, '.$block_size.') ^ $in;
|
1164 |
-
'.$_encryptBlock.'
|
1165 |
-
$ciphertext.= $in;
|
1166 |
-
}
|
1167 |
-
|
1168 |
-
if ($self->continuousBuffer) {
|
1169 |
-
$self->encryptIV = $in;
|
1170 |
-
}
|
1171 |
-
|
1172 |
-
return $ciphertext;
|
1173 |
-
';
|
1174 |
-
|
1175 |
-
$decrypt = '
|
1176 |
-
$plaintext = "";
|
1177 |
-
$text = str_pad($text, strlen($text) + ('.$block_size.' - strlen($text) % '.$block_size.') % '.$block_size.', chr(0));
|
1178 |
-
$ciphertext_len = strlen($text);
|
1179 |
-
|
1180 |
-
$iv = $self->decryptIV;
|
1181 |
-
|
1182 |
-
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') {
|
1183 |
-
$in = $block = substr($text, $i, '.$block_size.');
|
1184 |
-
'.$_decryptBlock.'
|
1185 |
-
$plaintext.= $in ^ $iv;
|
1186 |
-
$iv = $block;
|
1187 |
-
}
|
1188 |
-
|
1189 |
-
if ($self->continuousBuffer) {
|
1190 |
-
$self->decryptIV = $iv;
|
1191 |
-
}
|
1192 |
-
|
1193 |
-
return $self->_unpad($plaintext);
|
1194 |
-
';
|
1195 |
-
break;
|
1196 |
-
case CRYPT_BLOWFISH_MODE_CTR:
|
1197 |
-
$encrypt = '
|
1198 |
-
$ciphertext = "";
|
1199 |
-
$plaintext_len = strlen($text);
|
1200 |
-
$xor = $self->encryptIV;
|
1201 |
-
$buffer = &$self->enbuffer;
|
1202 |
-
|
1203 |
-
if (strlen($buffer["encrypted"])) {
|
1204 |
-
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
|
1205 |
-
$block = substr($text, $i, '.$block_size.');
|
1206 |
-
if (strlen($block) > strlen($buffer["encrypted"])) {
|
1207 |
-
$in = $self->_generate_xor($xor);
|
1208 |
-
'.$_encryptBlock.'
|
1209 |
-
$buffer["encrypted"].= $in;
|
1210 |
-
}
|
1211 |
-
$key = $self->_string_shift($buffer["encrypted"]);
|
1212 |
-
$ciphertext.= $block ^ $key;
|
1213 |
-
}
|
1214 |
-
} else {
|
1215 |
-
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
|
1216 |
-
$block = substr($text, $i, '.$block_size.');
|
1217 |
-
$in = $self->_generate_xor($xor);
|
1218 |
-
'.$_encryptBlock.'
|
1219 |
-
$key = $in;
|
1220 |
-
$ciphertext.= $block ^ $key;
|
1221 |
-
}
|
1222 |
-
}
|
1223 |
-
if ($self->continuousBuffer) {
|
1224 |
-
$self->encryptIV = $xor;
|
1225 |
-
if ($start = $plaintext_len % '.$block_size.') {
|
1226 |
-
$buffer["encrypted"] = substr($key, $start) . $buffer["encrypted"];
|
1227 |
-
}
|
1228 |
-
}
|
1229 |
-
|
1230 |
-
return $ciphertext;
|
1231 |
-
';
|
1232 |
-
|
1233 |
-
$decrypt = '
|
1234 |
-
$plaintext = "";
|
1235 |
-
$ciphertext_len = strlen($text);
|
1236 |
-
$xor = $self->decryptIV;
|
1237 |
-
$buffer = &$self->debuffer;
|
1238 |
-
|
1239 |
-
if (strlen($buffer["ciphertext"])) {
|
1240 |
-
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') {
|
1241 |
-
$block = substr($text, $i, '.$block_size.');
|
1242 |
-
if (strlen($block) > strlen($buffer["ciphertext"])) {
|
1243 |
-
$in = $self->_generate_xor($xor);
|
1244 |
-
'.$_encryptBlock.'
|
1245 |
-
$buffer["ciphertext"].= $in;
|
1246 |
-
}
|
1247 |
-
$key = $self->_string_shift($buffer["ciphertext"]);
|
1248 |
-
$plaintext.= $block ^ $key;
|
1249 |
-
}
|
1250 |
-
} else {
|
1251 |
-
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') {
|
1252 |
-
$block = substr($text, $i, '.$block_size.');
|
1253 |
-
$in = $self->_generate_xor($xor);
|
1254 |
-
'.$_encryptBlock.'
|
1255 |
-
$key = $in;
|
1256 |
-
$plaintext.= $block ^ $key;
|
1257 |
-
}
|
1258 |
-
}
|
1259 |
-
if ($self->continuousBuffer) {
|
1260 |
-
$self->decryptIV = $xor;
|
1261 |
-
if ($start = $ciphertext_len % '.$block_size.') {
|
1262 |
-
$buffer["ciphertext"] = substr($key, $start) . $buffer["ciphertext"];
|
1263 |
-
}
|
1264 |
-
}
|
1265 |
-
return $plaintext;
|
1266 |
-
';
|
1267 |
-
break;
|
1268 |
-
case CRYPT_BLOWFISH_MODE_CFB:
|
1269 |
-
$encrypt = '
|
1270 |
-
$ciphertext = "";
|
1271 |
-
$buffer = &$self->enbuffer;
|
1272 |
-
|
1273 |
-
if ($self->continuousBuffer) {
|
1274 |
-
$iv = &$self->encryptIV;
|
1275 |
-
$pos = &$buffer["pos"];
|
1276 |
-
} else {
|
1277 |
-
$iv = $self->encryptIV;
|
1278 |
-
$pos = 0;
|
1279 |
-
}
|
1280 |
-
$len = strlen($text);
|
1281 |
-
$i = 0;
|
1282 |
-
if ($pos) {
|
1283 |
-
$orig_pos = $pos;
|
1284 |
-
$max = '.$block_size.' - $pos;
|
1285 |
-
if ($len >= $max) {
|
1286 |
-
$i = $max;
|
1287 |
-
$len-= $max;
|
1288 |
-
$pos = 0;
|
1289 |
-
} else {
|
1290 |
-
$i = $len;
|
1291 |
-
$pos+= $len;
|
1292 |
-
$len = 0;
|
1293 |
-
}
|
1294 |
-
$ciphertext = substr($iv, $orig_pos) ^ $text;
|
1295 |
-
$iv = substr_replace($iv, $ciphertext, $orig_pos, $i);
|
1296 |
-
}
|
1297 |
-
while ($len >= '.$block_size.') {
|
1298 |
-
$in = $iv;
|
1299 |
-
'.$_encryptBlock.';
|
1300 |
-
$iv = $in ^ substr($text, $i, '.$block_size.');
|
1301 |
-
$ciphertext.= $iv;
|
1302 |
-
$len-= '.$block_size.';
|
1303 |
-
$i+= '.$block_size.';
|
1304 |
-
}
|
1305 |
-
if ($len) {
|
1306 |
-
$in = $iv;
|
1307 |
-
'.$_encryptBlock.'
|
1308 |
-
$iv = $in;
|
1309 |
-
$block = $iv ^ substr($text, $i);
|
1310 |
-
$iv = substr_replace($iv, $block, 0, $len);
|
1311 |
-
$ciphertext.= $block;
|
1312 |
-
$pos = $len;
|
1313 |
-
}
|
1314 |
-
return $ciphertext;
|
1315 |
-
';
|
1316 |
-
|
1317 |
-
$decrypt = '
|
1318 |
-
$plaintext = "";
|
1319 |
-
$buffer = &$self->debuffer;
|
1320 |
-
|
1321 |
-
if ($self->continuousBuffer) {
|
1322 |
-
$iv = &$self->decryptIV;
|
1323 |
-
$pos = &$buffer["pos"];
|
1324 |
-
} else {
|
1325 |
-
$iv = $self->decryptIV;
|
1326 |
-
$pos = 0;
|
1327 |
-
}
|
1328 |
-
$len = strlen($text);
|
1329 |
-
$i = 0;
|
1330 |
-
if ($pos) {
|
1331 |
-
$orig_pos = $pos;
|
1332 |
-
$max = '.$block_size.' - $pos;
|
1333 |
-
if ($len >= $max) {
|
1334 |
-
$i = $max;
|
1335 |
-
$len-= $max;
|
1336 |
-
$pos = 0;
|
1337 |
-
} else {
|
1338 |
-
$i = $len;
|
1339 |
-
$pos+= $len;
|
1340 |
-
$len = 0;
|
1341 |
-
}
|
1342 |
-
$plaintext = substr($iv, $orig_pos) ^ $text;
|
1343 |
-
$iv = substr_replace($iv, substr($text, 0, $i), $orig_pos, $i);
|
1344 |
-
}
|
1345 |
-
while ($len >= '.$block_size.') {
|
1346 |
-
$in = $iv;
|
1347 |
-
'.$_encryptBlock.'
|
1348 |
-
$iv = $in;
|
1349 |
-
$cb = substr($text, $i, '.$block_size.');
|
1350 |
-
$plaintext.= $iv ^ $cb;
|
1351 |
-
$iv = $cb;
|
1352 |
-
$len-= '.$block_size.';
|
1353 |
-
$i+= '.$block_size.';
|
1354 |
-
}
|
1355 |
-
if ($len) {
|
1356 |
-
$in = $iv;
|
1357 |
-
'.$_encryptBlock.'
|
1358 |
-
$iv = $in;
|
1359 |
-
$plaintext.= $iv ^ substr($text, $i);
|
1360 |
-
$iv = substr_replace($iv, substr($text, $i), 0, $len);
|
1361 |
-
$pos = $len;
|
1362 |
-
}
|
1363 |
-
|
1364 |
-
return $plaintext;
|
1365 |
-
';
|
1366 |
-
break;
|
1367 |
-
case CRYPT_BLOWFISH_MODE_OFB:
|
1368 |
-
$encrypt = '
|
1369 |
-
$ciphertext = "";
|
1370 |
-
$plaintext_len = strlen($text);
|
1371 |
-
$xor = $self->encryptIV;
|
1372 |
-
$buffer = &$self->enbuffer;
|
1373 |
-
|
1374 |
-
if (strlen($buffer["xor"])) {
|
1375 |
-
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
|
1376 |
-
$block = substr($text, $i, '.$block_size.');
|
1377 |
-
if (strlen($block) > strlen($buffer["xor"])) {
|
1378 |
-
$in = $xor;
|
1379 |
-
'.$_encryptBlock.'
|
1380 |
-
$xor = $in;
|
1381 |
-
$buffer["xor"].= $xor;
|
1382 |
-
}
|
1383 |
-
$key = $self->_string_shift($buffer["xor"]);
|
1384 |
-
$ciphertext.= $block ^ $key;
|
1385 |
-
}
|
1386 |
-
} else {
|
1387 |
-
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
|
1388 |
-
$in = $xor;
|
1389 |
-
'.$_encryptBlock.'
|
1390 |
-
$xor = $in;
|
1391 |
-
$ciphertext.= substr($text, $i, '.$block_size.') ^ $xor;
|
1392 |
-
}
|
1393 |
-
$key = $xor;
|
1394 |
-
}
|
1395 |
-
if ($self->continuousBuffer) {
|
1396 |
-
$self->encryptIV = $xor;
|
1397 |
-
if ($start = $plaintext_len % '.$block_size.') {
|
1398 |
-
$buffer["xor"] = substr($key, $start) . $buffer["xor"];
|
1399 |
-
}
|
1400 |
-
}
|
1401 |
-
return $ciphertext;
|
1402 |
-
';
|
1403 |
-
|
1404 |
-
$decrypt = '
|
1405 |
-
$plaintext = "";
|
1406 |
-
$ciphertext_len = strlen($text);
|
1407 |
-
$xor = $self->decryptIV;
|
1408 |
-
$buffer = &$self->debuffer;
|
1409 |
-
|
1410 |
-
if (strlen($buffer["xor"])) {
|
1411 |
-
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') {
|
1412 |
-
$block = substr($text, $i, '.$block_size.');
|
1413 |
-
if (strlen($block) > strlen($buffer["xor"])) {
|
1414 |
-
$in = $xor;
|
1415 |
-
'.$_encryptBlock.'
|
1416 |
-
$xor = $in;
|
1417 |
-
$buffer["xor"].= $xor;
|
1418 |
-
}
|
1419 |
-
$key = $self->_string_shift($buffer["xor"]);
|
1420 |
-
$plaintext.= $block ^ $key;
|
1421 |
-
}
|
1422 |
-
} else {
|
1423 |
-
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') {
|
1424 |
-
$in = $xor;
|
1425 |
-
'.$_encryptBlock.'
|
1426 |
-
$xor = $in;
|
1427 |
-
$plaintext.= substr($text, $i, '.$block_size.') ^ $xor;
|
1428 |
-
}
|
1429 |
-
$key = $xor;
|
1430 |
-
}
|
1431 |
-
if ($self->continuousBuffer) {
|
1432 |
-
$self->decryptIV = $xor;
|
1433 |
-
if ($start = $ciphertext_len % '.$block_size.') {
|
1434 |
-
$buffer["xor"] = substr($key, $start) . $buffer["xor"];
|
1435 |
-
}
|
1436 |
-
}
|
1437 |
-
return $plaintext;
|
1438 |
-
';
|
1439 |
-
break;
|
1440 |
-
}
|
1441 |
-
$fnc_head = '$action, &$self, $text';
|
1442 |
-
$fnc_body = $init_cryptBlock . 'if ($action == "encrypt") { ' . $encrypt . ' } else { ' . $decrypt . ' }';
|
1443 |
-
|
1444 |
-
if (function_exists('create_function') && is_callable('create_function')) {
|
1445 |
-
$lambda_functions[$code_hash] = create_function($fnc_head, $fnc_body);
|
1446 |
-
} else {
|
1447 |
-
eval('function ' . ($lambda_functions[$code_hash] = 'f' . md5(microtime())) . '(' . $fnc_head . ') { ' . $fnc_body . ' }');
|
1448 |
-
}
|
1449 |
-
}
|
1450 |
-
$this->inline_crypt = $lambda_functions[$code_hash];
|
1451 |
-
}/*}}}*/
|
1452 |
-
|
1453 |
-
/**
|
1454 |
-
* Holds the lambda_functions table (classwide)
|
1455 |
-
*
|
1456 |
-
* @see inline_crypt_setup()
|
1457 |
-
* @return Array
|
1458 |
-
* @access private
|
1459 |
-
*/
|
1460 |
-
function &get_lambda_functions()
|
1461 |
-
{
|
1462 |
-
static $functions = array();
|
1463 |
-
return $functions;
|
1464 |
-
}
|
1465 |
-
}
|
1466 |
-
|
1467 |
-
// vim: ts=4:sw=4:et:
|
1468 |
-
// vim6: fdl=1:
|
1 |
+
<?php
|
2 |
+
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Pure-PHP implementation of Blowfish.
|
6 |
+
*
|
7 |
+
* Uses mcrypt, if available, and an internal implementation, otherwise.
|
8 |
+
*
|
9 |
+
* PHP versions 4 and 5
|
10 |
+
*
|
11 |
+
* Useful resources are as follows:
|
12 |
+
*
|
13 |
+
* - {@link http://en.wikipedia.org/wiki/Blowfish Wikipedia description of Blowfish}
|
14 |
+
*
|
15 |
+
* Here's a short example of how to use this library:
|
16 |
+
* <code>
|
17 |
+
* <?php
|
18 |
+
* include('Crypt/Blowfish.php');
|
19 |
+
*
|
20 |
+
* $blowfish = new Crypt_Blowfish();
|
21 |
+
*
|
22 |
+
* $blowfish->setKey('12345678901234567890123456789012');
|
23 |
+
*
|
24 |
+
* $plaintext = str_repeat('a', 1024);
|
25 |
+
*
|
26 |
+
* echo $blowfish->decrypt($blowfish->encrypt($plaintext));
|
27 |
+
* ?>
|
28 |
+
* </code>
|
29 |
+
*
|
30 |
+
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
31 |
+
* of this software and associated documentation files (the "Software"), to deal
|
32 |
+
* in the Software without restriction, including without limitation the rights
|
33 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
34 |
+
* copies of the Software, and to permit persons to whom the Software is
|
35 |
+
* furnished to do so, subject to the following conditions:
|
36 |
+
*
|
37 |
+
* The above copyright notice and this permission notice shall be included in
|
38 |
+
* all copies or substantial portions of the Software.
|
39 |
+
*
|
40 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
41 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
42 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
43 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
44 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
45 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
46 |
+
* THE SOFTWARE.
|
47 |
+
*
|
48 |
+
* @category Crypt
|
49 |
+
* @package Crypt_Blowfish
|
50 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
51 |
+
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
52 |
+
* @copyright MMVII Jim Wigginton
|
53 |
+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
54 |
+
* @version 1.0
|
55 |
+
* @link http://phpseclib.sourceforge.net
|
56 |
+
*/
|
57 |
+
|
58 |
+
/**#@+
|
59 |
+
* @access public
|
60 |
+
* @see Crypt_Blowfish::encrypt()
|
61 |
+
* @see Crypt_Blowfish::decrypt()
|
62 |
+
*/
|
63 |
+
/**
|
64 |
+
* Encrypt / decrypt using the Counter mode.
|
65 |
+
*
|
66 |
+
* Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
|
67 |
+
*
|
68 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
|
69 |
+
*/
|
70 |
+
define('CRYPT_BLOWFISH_MODE_CTR', -1);
|
71 |
+
/**
|
72 |
+
* Encrypt / decrypt using the Electronic Code Book mode.
|
73 |
+
*
|
74 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
|
75 |
+
*/
|
76 |
+
define('CRYPT_BLOWFISH_MODE_ECB', 1);
|
77 |
+
/**
|
78 |
+
* Encrypt / decrypt using the Code Book Chaining mode.
|
79 |
+
*
|
80 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
|
81 |
+
*/
|
82 |
+
define('CRYPT_BLOWFISH_MODE_CBC', 2);
|
83 |
+
/**
|
84 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
85 |
+
*
|
86 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
|
87 |
+
*/
|
88 |
+
define('CRYPT_BLOWFISH_MODE_CFB', 3);
|
89 |
+
/**
|
90 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
91 |
+
*
|
92 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
|
93 |
+
*/
|
94 |
+
define('CRYPT_BLOWFISH_MODE_OFB', 4);
|
95 |
+
/**#@-*/
|
96 |
+
|
97 |
+
/**#@+
|
98 |
+
* @access private
|
99 |
+
* @see Crypt_Blowfish::Crypt_Blowfish()
|
100 |
+
*/
|
101 |
+
/**
|
102 |
+
* Toggles the internal implementation
|
103 |
+
*/
|
104 |
+
define('CRYPT_BLOWFISH_MODE_INTERNAL', 1);
|
105 |
+
/**
|
106 |
+
* Toggles the mcrypt implementation
|
107 |
+
*/
|
108 |
+
define('CRYPT_BLOWFISH_MODE_MCRYPT', 2);
|
109 |
+
/**#@-*/
|
110 |
+
|
111 |
+
/**
|
112 |
+
* Pure-PHP implementation of Blowfish.
|
113 |
+
*
|
114 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
115 |
+
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
116 |
+
* @version 1.0
|
117 |
+
* @access public
|
118 |
+
* @package Crypt_Blowfish
|
119 |
+
*/
|
120 |
+
class Crypt_Blowfish {
|
121 |
+
/**
|
122 |
+
* The Key as String
|
123 |
+
*
|
124 |
+
* @see Crypt_Blowfish::setKey()
|
125 |
+
* @var Array
|
126 |
+
* @access private
|
127 |
+
*/
|
128 |
+
var $key = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
|
129 |
+
|
130 |
+
/**
|
131 |
+
* The Encryption Mode
|
132 |
+
*
|
133 |
+
* @see Crypt_Blowfish::Crypt_Blowfish()
|
134 |
+
* @var Integer
|
135 |
+
* @access private
|
136 |
+
*/
|
137 |
+
var $mode;
|
138 |
+
|
139 |
+
/**
|
140 |
+
* Continuous Buffer status
|
141 |
+
*
|
142 |
+
* @see Crypt_Blowfish::enableContinuousBuffer()
|
143 |
+
* @var Boolean
|
144 |
+
* @access private
|
145 |
+
*/
|
146 |
+
var $continuousBuffer = false;
|
147 |
+
|
148 |
+
/**
|
149 |
+
* Padding status
|
150 |
+
*
|
151 |
+
* @see Crypt_Blowfish::enablePadding()
|
152 |
+
* @var Boolean
|
153 |
+
* @access private
|
154 |
+
*/
|
155 |
+
var $padding = true;
|
156 |
+
|
157 |
+
/**
|
158 |
+
* The Initialization Vector
|
159 |
+
*
|
160 |
+
* @see Crypt_Blowfish::setIV()
|
161 |
+
* @var String
|
162 |
+
* @access private
|
163 |
+
*/
|
164 |
+
var $iv = "\0\0\0\0\0\0\0\0";
|
165 |
+
|
166 |
+
/**
|
167 |
+
* A "sliding" Initialization Vector
|
168 |
+
*
|
169 |
+
* @see Crypt_Blowfish::enableContinuousBuffer()
|
170 |
+
* @var String
|
171 |
+
* @access private
|
172 |
+
*/
|
173 |
+
var $encryptIV = "\0\0\0\0\0\0\0\0";
|
174 |
+
|
175 |
+
/**
|
176 |
+
* A "sliding" Initialization Vector
|
177 |
+
*
|
178 |
+
* @see Crypt_Blowfish::enableContinuousBuffer()
|
179 |
+
* @var String
|
180 |
+
* @access private
|
181 |
+
*/
|
182 |
+
var $decryptIV = "\0\0\0\0\0\0\0\0";
|
183 |
+
|
184 |
+
/**
|
185 |
+
* mcrypt resource for encryption
|
186 |
+
*
|
187 |
+
* The mcrypt resource can be recreated every time something needs to be created or it can be created just once.
|
188 |
+
* Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.
|
189 |
+
*
|
190 |
+
* @see Crypt_Blowfish::encrypt()
|
191 |
+
* @var String
|
192 |
+
* @access private
|
193 |
+
*/
|
194 |
+
var $enmcrypt;
|
195 |
+
|
196 |
+
/**
|
197 |
+
* mcrypt resource for decryption
|
198 |
+
*
|
199 |
+
* The mcrypt resource can be recreated every time something needs to be created or it can be created just once.
|
200 |
+
* Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.
|
201 |
+
*
|
202 |
+
* @see Crypt_Blowfish::decrypt()
|
203 |
+
* @var String
|
204 |
+
* @access private
|
205 |
+
*/
|
206 |
+
var $demcrypt;
|
207 |
+
|
208 |
+
/**
|
209 |
+
* Does the enmcrypt resource need to be (re)initialized?
|
210 |
+
*
|
211 |
+
* @see Crypt_Blowfish::setKey()
|
212 |
+
* @see Crypt_Blowfish::setIV()
|
213 |
+
* @var Boolean
|
214 |
+
* @access private
|
215 |
+
*/
|
216 |
+
var $enchanged = true;
|
217 |
+
|
218 |
+
/**
|
219 |
+
* Does the demcrypt resource need to be (re)initialized?
|
220 |
+
*
|
221 |
+
* @see Crypt_Blowfish::setKey()
|
222 |
+
* @see Crypt_Blowfish::setIV()
|
223 |
+
* @var Boolean
|
224 |
+
* @access private
|
225 |
+
*/
|
226 |
+
var $dechanged = true;
|
227 |
+
|
228 |
+
/**
|
229 |
+
* Is the mode one that is paddable?
|
230 |
+
*
|
231 |
+
* @see Crypt_Blowfish::Crypt_Blowfish()
|
232 |
+
* @var Boolean
|
233 |
+
* @access private
|
234 |
+
*/
|
235 |
+
var $paddable = false;
|
236 |
+
|
237 |
+
/**
|
238 |
+
* Encryption buffer for CTR, OFB and CFB modes
|
239 |
+
*
|
240 |
+
* @see Crypt_Blowfish::encrypt()
|
241 |
+
* @var Array
|
242 |
+
* @access private
|
243 |
+
*/
|
244 |
+
var $enbuffer = array('encrypted' => '', 'xor' => '', 'pos' => 0, 'enmcrypt_init' => true);
|
245 |
+
|
246 |
+
/**
|
247 |
+
* Decryption buffer for CTR, OFB and CFB modes
|
248 |
+
*
|
249 |
+
* @see Crypt_Blowfish::decrypt()
|
250 |
+
* @var Array
|
251 |
+
* @access private
|
252 |
+
*/
|
253 |
+
var $debuffer = array('ciphertext' => '', 'xor' => '', 'pos' => 0, 'demcrypt_init' => true);
|
254 |
+
|
255 |
+
/**
|
256 |
+
* mcrypt resource for CFB mode
|
257 |
+
*
|
258 |
+
* @see Crypt_Blowfish::encrypt()
|
259 |
+
* @see Crypt_Blowfish::decrypt()
|
260 |
+
* @var String
|
261 |
+
* @access private
|
262 |
+
*/
|
263 |
+
var $ecb;
|
264 |
+
|
265 |
+
/**
|
266 |
+
* Performance-optimized callback function for en/decrypt()
|
267 |
+
*
|
268 |
+
* @var Callback
|
269 |
+
* @access private
|
270 |
+
*/
|
271 |
+
var $inline_crypt;
|
272 |
+
|
273 |
+
/**
|
274 |
+
* The fixed subkeys boxes ($sbox0 - $sbox3) with 256 entries each
|
275 |
+
*
|
276 |
+
* S-Box 1
|
277 |
+
*
|
278 |
+
* @access private
|
279 |
+
* @var array
|
280 |
+
*/
|
281 |
+
var $sbox0 = array (
|
282 |
+
0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
|
283 |
+
0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
|
284 |
+
0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
|
285 |
+
0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
|
286 |
+
0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
|
287 |
+
0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
|
288 |
+
0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
|
289 |
+
0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
|
290 |
+
0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
|
291 |
+
0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
|
292 |
+
0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
|
293 |
+
0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
|
294 |
+
0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
|
295 |
+
0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
|
296 |
+
0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
|
297 |
+
0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
|
298 |
+
0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
|
299 |
+
0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
|
300 |
+
0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
|
301 |
+
0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
|
302 |
+
0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
|
303 |
+
0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
|
304 |
+
0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
|
305 |
+
0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
|
306 |
+
0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
|
307 |
+
0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
|
308 |
+
0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
|
309 |
+
0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
|
310 |
+
0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
|
311 |
+
0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
|
312 |
+
0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
|
313 |
+
0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a
|
314 |
+
);
|
315 |
+
|
316 |
+
/**
|
317 |
+
* S-Box 1
|
318 |
+
*
|
319 |
+
* @access private
|
320 |
+
* @var array
|
321 |
+
*/
|
322 |
+
var $sbox1 = array(
|
323 |
+
0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
|
324 |
+
0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
|
325 |
+
0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
|
326 |
+
0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
|
327 |
+
0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
|
328 |
+
0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
|
329 |
+
0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
|
330 |
+
0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
|
331 |
+
0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
|
332 |
+
0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
|
333 |
+
0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
|
334 |
+
0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
|
335 |
+
0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
|
336 |
+
0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
|
337 |
+
0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
|
338 |
+
0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
|
339 |
+
0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
|
340 |
+
0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
|
341 |
+
0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
|
342 |
+
0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
|
343 |
+
0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
|
344 |
+
0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
|
345 |
+
0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
|
346 |
+
0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
|
347 |
+
0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
|
348 |
+
0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
|
349 |
+
0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
|
350 |
+
0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
|
351 |
+
0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
|
352 |
+
0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
|
353 |
+
0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
|
354 |
+
0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7
|
355 |
+
);
|
356 |
+
|
357 |
+
/**
|
358 |
+
* S-Box 2
|
359 |
+
*
|
360 |
+
* @access private
|
361 |
+
* @var array
|
362 |
+
*/
|
363 |
+
var $sbox2 = array(
|
364 |
+
0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
|
365 |
+
0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
|
366 |
+
0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
|
367 |
+
0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
|
368 |
+
0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
|
369 |
+
0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
|
370 |
+
0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
|
371 |
+
0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
|
372 |
+
0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
|
373 |
+
0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
|
374 |
+
0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
|
375 |
+
0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
|
376 |
+
0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
|
377 |
+
0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
|
378 |
+
0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
|
379 |
+
0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
|
380 |
+
0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
|
381 |
+
0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
|
382 |
+
0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
|
383 |
+
0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
|
384 |
+
0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
|
385 |
+
0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
|
386 |
+
0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
|
387 |
+
0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
|
388 |
+
0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
|
389 |
+
0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
|
390 |
+
0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
|
391 |
+
0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
|
392 |
+
0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
|
393 |
+
0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
|
394 |
+
0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
|
395 |
+
0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0
|
396 |
+
);
|
397 |
+
|
398 |
+
/**
|
399 |
+
* S-Box 3
|
400 |
+
*
|
401 |
+
* @access private
|
402 |
+
* @var array
|
403 |
+
*/
|
404 |
+
var $sbox3 = array(
|
405 |
+
0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
|
406 |
+
0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
|
407 |
+
0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
|
408 |
+
0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
|
409 |
+
0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
|
410 |
+
0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
|
411 |
+
0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
|
412 |
+
0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
|
413 |
+
0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
|
414 |
+
0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
|
415 |
+
0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
|
416 |
+
0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
|
417 |
+
0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
|
418 |
+
0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
|
419 |
+
0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
|
420 |
+
0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
|
421 |
+
0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
|
422 |
+
0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
|
423 |
+
0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
|
424 |
+
0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
|
425 |
+
0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
|
426 |
+
0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
|
427 |
+
0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
|
428 |
+
0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
|
429 |
+
0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
|
430 |
+
0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
|
431 |
+
0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
|
432 |
+
0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
|
433 |
+
0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
|
434 |
+
0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
|
435 |
+
0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
|
436 |
+
0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
|
437 |
+
);
|
438 |
+
|
439 |
+
/**
|
440 |
+
* P-Array consists of 18 32-bit subkeys
|
441 |
+
*
|
442 |
+
* @var array $parray
|
443 |
+
* @access private
|
444 |
+
*/
|
445 |
+
var $parray = array(
|
446 |
+
0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0,
|
447 |
+
0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
|
448 |
+
0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b
|
449 |
+
);
|
450 |
+
|
451 |
+
/**
|
452 |
+
* The BCTX-working Array
|
453 |
+
*
|
454 |
+
* Holds the expanded key [p] and the key-depended s-boxes [sb]
|
455 |
+
*
|
456 |
+
* @var array $bctx
|
457 |
+
* @access private
|
458 |
+
*/
|
459 |
+
var $bctx = array();
|
460 |
+
|
461 |
+
/**
|
462 |
+
* Default Constructor.
|
463 |
+
*
|
464 |
+
* Determines whether or not the mcrypt extension should be used.
|
465 |
+
* If not explictly set, CRYPT_BLOWFISH_MODE_CBC will be used.
|
466 |
+
*
|
467 |
+
* @param optional Integer $mode
|
468 |
+
* @access public
|
469 |
+
*/
|
470 |
+
function Crypt_Blowfish($mode = CRYPT_BLOWFISH_MODE_CBC)
|
471 |
+
{
|
472 |
+
if ( !defined('CRYPT_BLOWFISH_MODE') ) {
|
473 |
+
switch (true) {
|
474 |
+
case extension_loaded('mcrypt') && in_array('blowfish', mcrypt_list_algorithms()):
|
475 |
+
define('CRYPT_BLOWFISH_MODE', CRYPT_BLOWFISH_MODE_MCRYPT);
|
476 |
+
break;
|
477 |
+
default:
|
478 |
+
define('CRYPT_BLOWFISH_MODE', CRYPT_BLOWFISH_MODE_INTERNAL);
|
479 |
+
}
|
480 |
+
}
|
481 |
+
|
482 |
+
switch ( CRYPT_BLOWFISH_MODE ) {
|
483 |
+
case CRYPT_BLOWFISH_MODE_MCRYPT:
|
484 |
+
switch ($mode) {
|
485 |
+
case CRYPT_BLOWFISH_MODE_ECB:
|
486 |
+
$this->paddable = true;
|
487 |
+
$this->mode = MCRYPT_MODE_ECB;
|
488 |
+
break;
|
489 |
+
case CRYPT_BLOWFISH_MODE_CTR:
|
490 |
+
$this->mode = 'ctr';
|
491 |
+
break;
|
492 |
+
case CRYPT_BLOWFISH_MODE_CFB:
|
493 |
+
$this->mode = 'ncfb';
|
494 |
+
$this->ecb = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_ECB, '');
|
495 |
+
break;
|
496 |
+
case CRYPT_BLOWFISH_MODE_OFB:
|
497 |
+
$this->mode = MCRYPT_MODE_NOFB;
|
498 |
+
break;
|
499 |
+
case CRYPT_BLOWFISH_MODE_CBC:
|
500 |
+
default:
|
501 |
+
$this->paddable = true;
|
502 |
+
$this->mode = MCRYPT_MODE_CBC;
|
503 |
+
}
|
504 |
+
$this->enmcrypt = mcrypt_module_open(MCRYPT_BLOWFISH, '', $this->mode, '');
|
505 |
+
$this->demcrypt = mcrypt_module_open(MCRYPT_BLOWFISH, '', $this->mode, '');
|
506 |
+
|
507 |
+
break;
|
508 |
+
default:
|
509 |
+
switch ($mode) {
|
510 |
+
case CRYPT_BLOWFISH_MODE_ECB:
|
511 |
+
case CRYPT_BLOWFISH_MODE_CBC:
|
512 |
+
$this->paddable = true;
|
513 |
+
$this->mode = $mode;
|
514 |
+
break;
|
515 |
+
case CRYPT_BLOWFISH_MODE_CTR:
|
516 |
+
case CRYPT_BLOWFISH_MODE_CFB:
|
517 |
+
case CRYPT_BLOWFISH_MODE_OFB:
|
518 |
+
$this->mode = $mode;
|
519 |
+
break;
|
520 |
+
default:
|
521 |
+
$this->paddable = true;
|
522 |
+
$this->mode = CRYPT_BLOWFISH_MODE_CBC;
|
523 |
+
}
|
524 |
+
$this->inline_crypt_setup();
|
525 |
+
}
|
526 |
+
}
|
527 |
+
|
528 |
+
/**
|
529 |
+
* Sets the key.
|
530 |
+
*
|
531 |
+
* Keys can be of any length. Blowfish, itself, requires the use of a key between 32 and max. 448-bits long.
|
532 |
+
* If the key is less than 32-bits we NOT fill the key to 32bit but let the key as it is to be compatible
|
533 |
+
* with mcrypt because mcrypt act this way with blowfish key's < 32 bits.
|
534 |
+
*
|
535 |
+
* If the key is more than 448-bits, we trim the excess bits.
|
536 |
+
*
|
537 |
+
* If the key is not explicitly set, or empty, it'll be assumed a 128 bits key to be all null bytes.
|
538 |
+
*
|
539 |
+
* @access public
|
540 |
+
* @param String $key
|
541 |
+
*/
|
542 |
+
function setKey($key)
|
543 |
+
{
|
544 |
+
$keylength = strlen($key);
|
545 |
+
|
546 |
+
if (!$keylength) {
|
547 |
+
$key = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
|
548 |
+
}
|
549 |
+
elseif ($keylength > 56) {
|
550 |
+
$key = substr($key, 0, 56);
|
551 |
+
}
|
552 |
+
|
553 |
+
$this->key = $key;
|
554 |
+
|
555 |
+
$this->enchanged = true;
|
556 |
+
$this->dechanged = true;
|
557 |
+
|
558 |
+
if (CRYPT_BLOWFISH_MODE == CRYPT_BLOWFISH_MODE_MCRYPT) {
|
559 |
+
return;
|
560 |
+
}
|
561 |
+
|
562 |
+
/* key-expanding p[] and S-Box building sb[] */
|
563 |
+
$this->bctx = array(
|
564 |
+
'p' => array(),
|
565 |
+
'sb' => array(
|
566 |
+
$this->sbox0,
|
567 |
+
$this->sbox1,
|
568 |
+
$this->sbox2,
|
569 |
+
$this->sbox3
|
570 |
+
)
|
571 |
+
);
|
572 |
+
|
573 |
+
// unpack binary string in unsigned chars
|
574 |
+
$key = array_values(unpack('C*', $key));
|
575 |
+
$keyl = count($key);
|
576 |
+
for ($j = 0, $i = 0; $i < 18; ++$i) {
|
577 |
+
// xor P1 with the first 32-bits of the key, xor P2 with the second 32-bits ...
|
578 |
+
for ($data = 0, $k = 0; $k < 4; ++$k) {
|
579 |
+
$data = ($data << 8) | $key[$j];
|
580 |
+
if (++$j >= $keyl) {
|
581 |
+
$j = 0;
|
582 |
+
}
|
583 |
+
}
|
584 |
+
$this->bctx['p'][] = $this->parray[$i] ^ $data;
|
585 |
+
}
|
586 |
+
|
587 |
+
// encrypt the zero-string, replace P1 and P2 with the encrypted data,
|
588 |
+
// encrypt P3 and P4 with the new P1 and P2, do it with all P-array and subkeys
|
589 |
+
$datal = 0;
|
590 |
+
$datar = 0;
|
591 |
+
for ($i = 0; $i < 18; $i += 2) {
|
592 |
+
$this->_encryptBlock($datal, $datar);
|
593 |
+
$this->bctx['p'][$i ] = $datal;
|
594 |
+
$this->bctx['p'][$i + 1] = $datar;
|
595 |
+
}
|
596 |
+
for ($i = 0; $i < 4; ++$i) {
|
597 |
+
for ($j = 0; $j < 256; $j += 2) {
|
598 |
+
$this->_encryptBlock($datal, $datar);
|
599 |
+
$this->bctx['sb'][$i][$j ] = $datal;
|
600 |
+
$this->bctx['sb'][$i][$j + 1] = $datar;
|
601 |
+
}
|
602 |
+
}
|
603 |
+
}
|
604 |
+
|
605 |
+
/**
|
606 |
+
* Encrypt the block.
|
607 |
+
*
|
608 |
+
* @access private
|
609 |
+
* @param int $Xl left uInt32 part of the block
|
610 |
+
* @param int $Xr right uInt32 part of the block
|
611 |
+
* @return void
|
612 |
+
*/
|
613 |
+
function _encryptBlock(&$Xl, &$Xr)
|
614 |
+
{
|
615 |
+
$p = $this->bctx['p'];
|
616 |
+
$sb_0 = $this->bctx['sb'][0];
|
617 |
+
$sb_1 = $this->bctx['sb'][1];
|
618 |
+
$sb_2 = $this->bctx['sb'][2];
|
619 |
+
$sb_3 = $this->bctx['sb'][3];
|
620 |
+
$l = $Xl;
|
621 |
+
$r = $Xr;
|
622 |
+
|
623 |
+
$i = -1;
|
624 |
+
while ($i < 15) {
|
625 |
+
$l^= $p[++$i];
|
626 |
+
$r^= ($sb_0[$l >> 24 & 0xff] +
|
627 |
+
$sb_1[$l >> 16 & 0xff] ^
|
628 |
+
$sb_2[$l >> 8 & 0xff]) +
|
629 |
+
$sb_3[$l & 0xff];
|
630 |
+
|
631 |
+
$r^= $p[++$i];
|
632 |
+
$l^= ($sb_0[$r >> 24 & 0xff] +
|
633 |
+
$sb_1[$r >> 16 & 0xff] ^
|
634 |
+
$sb_2[$r >> 8 & 0xff]) +
|
635 |
+
$sb_3[$r & 0xff];
|
636 |
+
|
637 |
+
}
|
638 |
+
$Xr = $l ^ $p[16];
|
639 |
+
$Xl = $r ^ $p[17];
|
640 |
+
}
|
641 |
+
|
642 |
+
/**
|
643 |
+
* Sets the password.
|
644 |
+
*
|
645 |
+
* Depending on what $method is set to, setPassword()'s (optional) parameters are as follows:
|
646 |
+
* {@link http://en.wikipedia.org/wiki/PBKDF2 pbkdf2}:
|
647 |
+
* $hash, $salt, $count
|
648 |
+
*
|
649 |
+
* @param String $password
|
650 |
+
* @param optional String $method
|
651 |
+
* @access public
|
652 |
+
*/
|
653 |
+
function setPassword($password, $method = 'pbkdf2')
|
654 |
+
{
|
655 |
+
$key = '';
|
656 |
+
|
657 |
+
switch ($method) {
|
658 |
+
default: // 'pbkdf2'
|
659 |
+
list(, , $hash, $salt, $count) = func_get_args();
|
660 |
+
if (!isset($hash)) {
|
661 |
+
$hash = 'sha1';
|
662 |
+
}
|
663 |
+
// WPA and WPA2 use the SSID as the salt
|
664 |
+
if (!isset($salt)) {
|
665 |
+
$salt = 'phpseclib/salt';
|
666 |
+
}
|
667 |
+
// RFC2898#section-4.2 uses 1,000 iterations by default
|
668 |
+
// WPA and WPA2 use 4,096.
|
669 |
+
if (!isset($count)) {
|
670 |
+
$count = 1000;
|
671 |
+
}
|
672 |
+
|
673 |
+
if (!class_exists('Crypt_Hash')) {
|
674 |
+
require_once('Crypt/Hash.php');
|
675 |
+
}
|
676 |
+
|
677 |
+
$i = 1;
|
678 |
+
while (strlen($key) < 56) {
|
679 |
+
//$dk.= $this->_pbkdf($password, $salt, $count, $i++);
|
680 |
+
$hmac = new Crypt_Hash();
|
681 |
+
$hmac->setHash($hash);
|
682 |
+
$hmac->setKey($password);
|
683 |
+
$f = $u = $hmac->hash($salt . pack('N', $i++));
|
684 |
+
for ($j = 2; $j <= $count; $j++) {
|
685 |
+
$u = $hmac->hash($u);
|
686 |
+
$f^= $u;
|
687 |
+
}
|
688 |
+
$key.= $f;
|
689 |
+
}
|
690 |
+
}
|
691 |
+
|
692 |
+
$this->setKey($key);
|
693 |
+
}
|
694 |
+
|
695 |
+
/**
|
696 |
+
* Sets the initialization vector. (optional)
|
697 |
+
*
|
698 |
+
* SetIV is not required when CRYPT_BLOWFISH_MODE_ECB is being used. If not explictly set, it'll be assumed
|
699 |
+
* to be all null bytes.
|
700 |
+
*
|
701 |
+
* @access public
|
702 |
+
* @param String $iv
|
703 |
+
*/
|
704 |
+
function setIV($iv)
|
705 |
+
{
|
706 |
+
$this->encryptIV = $this->decryptIV = $this->iv = str_pad(substr($iv, 0, 8), 8, chr(0));
|
707 |
+
$this->enchanged = true;
|
708 |
+
$this->dechanged = true;
|
709 |
+
}
|
710 |
+
|
711 |
+
/**
|
712 |
+
* Encrypts a message.
|
713 |
+
*
|
714 |
+
* $plaintext will be padded with up to 8 additional bytes. Other Blowfish implementations may or may not pad in the
|
715 |
+
* same manner. Other common approaches to padding and the reasons why it's necessary are discussed in the following
|
716 |
+
* URL:
|
717 |
+
*
|
718 |
+
* {@link http://www.di-mgt.com.au/cryptopad.html http://www.di-mgt.com.au/cryptopad.html}
|
719 |
+
*
|
720 |
+
* An alternative to padding is to, separately, send the length of the file. This is what SSH, in fact, does.
|
721 |
+
* strlen($plaintext) will still need to be a multiple of 8, however, arbitrary values can be added to make it that
|
722 |
+
* length.
|
723 |
+
*
|
724 |
+
* @see Crypt_Blowfish::decrypt()
|
725 |
+
* @access public
|
726 |
+
* @param String $plaintext
|
727 |
+
*/
|
728 |
+
function encrypt($plaintext)
|
729 |
+
{
|
730 |
+
if ( CRYPT_BLOWFISH_MODE == CRYPT_BLOWFISH_MODE_MCRYPT ) {
|
731 |
+
if ($this->paddable) {
|
732 |
+
$plaintext = $this->_pad($plaintext);
|
733 |
+
}
|
734 |
+
|
735 |
+
if ($this->enchanged) {
|
736 |
+
mcrypt_generic_init($this->enmcrypt, $this->key, $this->encryptIV);
|
737 |
+
if ($this->mode == 'ncfb') {
|
738 |
+
mcrypt_generic_init($this->ecb, $this->key, "\0\0\0\0\0\0\0\0");
|
739 |
+
}
|
740 |
+
$this->enchanged = false;
|
741 |
+
}
|
742 |
+
|
743 |
+
if ($this->mode != 'ncfb' || !$this->continuousBuffer) {
|
744 |
+
$ciphertext = mcrypt_generic($this->enmcrypt, $plaintext);
|
745 |
+
} else {
|
746 |
+
$iv = &$this->encryptIV;
|
747 |
+
$pos = &$this->enbuffer['pos'];
|
748 |
+
$len = strlen($plaintext);
|
749 |
+
$ciphertext = '';
|
750 |
+
$i = 0;
|
751 |
+
if ($pos) {
|
752 |
+
$orig_pos = $pos;
|
753 |
+
$max = 8 - $pos;
|
754 |
+
if ($len >= $max) {
|
755 |
+
$i = $max;
|
756 |
+
$len-= $max;
|
757 |
+
$pos = 0;
|
758 |
+
} else {
|
759 |
+
$i = $len;
|
760 |
+
$pos+= $len;
|
761 |
+
$len = 0;
|
762 |
+
}
|
763 |
+
$ciphertext = substr($iv, $orig_pos) ^ $plaintext;
|
764 |
+
$iv = substr_replace($iv, $ciphertext, $orig_pos, $i);
|
765 |
+
$this->enbuffer['enmcrypt_init'] = true;
|
766 |
+
}
|
767 |
+
if ($len >= 8) {
|
768 |
+
if ($this->enbuffer['enmcrypt_init'] === false || $len > 600) {
|
769 |
+
if ($this->enbuffer['enmcrypt_init'] === true) {
|
770 |
+
mcrypt_generic_init($this->enmcrypt, $this->key, $iv);
|
771 |
+
$this->enbuffer['enmcrypt_init'] = false;
|
772 |
+
}
|
773 |
+
$ciphertext.= mcrypt_generic($this->enmcrypt, substr($plaintext, $i, $len - $len % 8));
|
774 |
+
$iv = substr($ciphertext, -8);
|
775 |
+
$len%= 8;
|
776 |
+
} else {
|
777 |
+
while ($len >= 8) {
|
778 |
+
$iv = mcrypt_generic($this->ecb, $iv) ^ substr($plaintext, $i, 8);
|
779 |
+
$ciphertext.= $iv;
|
780 |
+
$len-= 8;
|
781 |
+
$i+= 8;
|
782 |
+
}
|
783 |
+
}
|
784 |
+
}
|
785 |
+
if ($len) {
|
786 |
+
$iv = mcrypt_generic($this->ecb, $iv);
|
787 |
+
$block = $iv ^ substr($plaintext, -$len);
|
788 |
+
$iv = substr_replace($iv, $block, 0, $len);
|
789 |
+
$ciphertext.= $block;
|
790 |
+
$pos = $len;
|
791 |
+
}
|
792 |
+
return $ciphertext;
|
793 |
+
}
|
794 |
+
|
795 |
+
if (!$this->continuousBuffer) {
|
796 |
+
mcrypt_generic_init($this->enmcrypt, $this->key, $this->encryptIV);
|
797 |
+
}
|
798 |
+
|
799 |
+
return $ciphertext;
|
800 |
+
}
|
801 |
+
|
802 |
+
if (empty($this->bctx)) {
|
803 |
+
$this->setKey($this->key);
|
804 |
+
}
|
805 |
+
|
806 |
+
$inline = $this->inline_crypt;
|
807 |
+
return $inline('encrypt', $this, $plaintext);
|
808 |
+
}
|
809 |
+
|
810 |
+
/**
|
811 |
+
* Decrypts a message.
|
812 |
+
*
|
813 |
+
* If strlen($ciphertext) is not a multiple of 8, null bytes will be added to the end of the string until it is.
|
814 |
+
*
|
815 |
+
* @see Crypt_Blowfish::encrypt()
|
816 |
+
* @access public
|
817 |
+
* @param String $ciphertext
|
818 |
+
*/
|
819 |
+
function decrypt($ciphertext)
|
820 |
+
{
|
821 |
+
if ( CRYPT_BLOWFISH_MODE == CRYPT_BLOWFISH_MODE_MCRYPT ) {
|
822 |
+
if ($this->paddable) {
|
823 |
+
// we pad with chr(0) since that's what mcrypt_generic does. to quote from http://php.net/function.mcrypt-generic :
|
824 |
+
// "The data is padded with "\0" to make sure the length of the data is n * blocksize."
|
825 |
+
$ciphertext = str_pad($ciphertext, strlen($ciphertext) + (8 - strlen($ciphertext) % 8) % 8, chr(0));
|
826 |
+
}
|
827 |
+
|
828 |
+
if ($this->dechanged) {
|
829 |
+
mcrypt_generic_init($this->demcrypt, $this->key, $this->decryptIV);
|
830 |
+
if ($this->mode == 'ncfb') {
|
831 |
+
mcrypt_generic_init($this->ecb, $this->key, "\0\0\0\0\0\0\0\0");
|
832 |
+
}
|
833 |
+
$this->dechanged = false;
|
834 |
+
}
|
835 |
+
|
836 |
+
if ($this->mode != 'ncfb' || !$this->continuousBuffer) {
|
837 |
+
$plaintext = mdecrypt_generic($this->demcrypt, $ciphertext);
|
838 |
+
} else {
|
839 |
+
$iv = &$this->decryptIV;
|
840 |
+
$pos = &$this->debuffer['pos'];
|
841 |
+
$len = strlen($ciphertext);
|
842 |
+
$plaintext = '';
|
843 |
+
$i = 0;
|
844 |
+
if ($pos) {
|
845 |
+
$orig_pos = $pos;
|
846 |
+
$max = 8 - $pos;
|
847 |
+
if ($len >= $max) {
|
848 |
+
$i = $max;
|
849 |
+
$len-= $max;
|
850 |
+
$pos = 0;
|
851 |
+
} else {
|
852 |
+
$i = $len;
|
853 |
+
$pos+= $len;
|
854 |
+
$len = 0;
|
855 |
+
}
|
856 |
+
$plaintext = substr($iv, $orig_pos) ^ $ciphertext;
|
857 |
+
$iv = substr_replace($iv, substr($ciphertext, 0, $i), $orig_pos, $i);
|
858 |
+
}
|
859 |
+
if ($len >= 8) {
|
860 |
+
$cb = substr($ciphertext, $i, $len - $len % 8);
|
861 |
+
$plaintext.= mcrypt_generic($this->ecb, $iv . $cb) ^ $cb;
|
862 |
+
$iv = substr($cb, -8);
|
863 |
+
$len%= 8;
|
864 |
+
}
|
865 |
+
if ($len) {
|
866 |
+
$iv = mcrypt_generic($this->ecb, $iv);
|
867 |
+
$plaintext.= $iv ^ substr($ciphertext, -$len);
|
868 |
+
$iv = substr_replace($iv, substr($ciphertext, -$len), 0, $len);
|
869 |
+
$pos = $len;
|
870 |
+
}
|
871 |
+
return $plaintext;
|
872 |
+
}
|
873 |
+
|
874 |
+
if (!$this->continuousBuffer) {
|
875 |
+
mcrypt_generic_init($this->demcrypt, $this->key, $this->decryptIV);
|
876 |
+
}
|
877 |
+
|
878 |
+
return $this->paddable ? $this->_unpad($plaintext) : $plaintext;
|
879 |
+
}
|
880 |
+
|
881 |
+
if (empty($this->bctx)) {
|
882 |
+
$this->setKey($this->key);
|
883 |
+
}
|
884 |
+
|
885 |
+
$inline = $this->inline_crypt;
|
886 |
+
return $inline('decrypt', $this, $ciphertext);
|
887 |
+
}
|
888 |
+
|
889 |
+
/**
|
890 |
+
* Treat consecutive "packets" as if they are a continuous buffer.
|
891 |
+
*
|
892 |
+
* @see Crypt_Blowfish::disableContinuousBuffer()
|
893 |
+
* @access public
|
894 |
+
*/
|
895 |
+
function enableContinuousBuffer()
|
896 |
+
{
|
897 |
+
$this->continuousBuffer = true;
|
898 |
+
}
|
899 |
+
|
900 |
+
/**
|
901 |
+
* Treat consecutive packets as if they are a discontinuous buffer.
|
902 |
+
*
|
903 |
+
* The default behavior.
|
904 |
+
*
|
905 |
+
* @see Crypt_Blowfish::enableContinuousBuffer()
|
906 |
+
* @access public
|
907 |
+
*/
|
908 |
+
function disableContinuousBuffer()
|
909 |
+
{
|
910 |
+
$this->continuousBuffer = false;
|
911 |
+
$this->encryptIV = $this->iv;
|
912 |
+
$this->decryptIV = $this->iv;
|
913 |
+
$this->enbuffer = array('encrypted' => '', 'xor' => '', 'pos' => 0, 'enmcrypt_init' => true);
|
914 |
+
$this->debuffer = array('ciphertext' => '', 'xor' => '', 'pos' => 0, 'demcrypt_init' => true);
|
915 |
+
|
916 |
+
if (CRYPT_BLOWFISH_MODE == CRYPT_BLOWFISH_MODE_MCRYPT) {
|
917 |
+
mcrypt_generic_init($this->enmcrypt, $this->key, $this->iv);
|
918 |
+
mcrypt_generic_init($this->demcrypt, $this->key, $this->iv);
|
919 |
+
}
|
920 |
+
}
|
921 |
+
|
922 |
+
/**
|
923 |
+
* Pad "packets".
|
924 |
+
*
|
925 |
+
* Blowfish works by encrypting 8 bytes at a time. If you ever need to encrypt or decrypt something that's not
|
926 |
+
* a multiple of 8, it becomes necessary to pad the input so that it's length is a multiple of eight.
|
927 |
+
*
|
928 |
+
* Padding is enabled by default. Sometimes, however, it is undesirable to pad strings. Such is the case in SSH1,
|
929 |
+
* where "packets" are padded with random bytes before being encrypted. Unpad these packets and you risk stripping
|
930 |
+
* away characters that shouldn't be stripped away. (SSH knows how many bytes are added because the length is
|
931 |
+
* transmitted separately)
|
932 |
+
*
|
933 |
+
* @see Crypt_Blowfish::disablePadding()
|
934 |
+
* @access public
|
935 |
+
*/
|
936 |
+
function enablePadding()
|
937 |
+
{
|
938 |
+
$this->padding = true;
|
939 |
+
}
|
940 |
+
|
941 |
+
/**
|
942 |
+
* Do not pad packets.
|
943 |
+
*
|
944 |
+
* @see Crypt_Blowfish::enablePadding()
|
945 |
+
* @access public
|
946 |
+
*/
|
947 |
+
function disablePadding()
|
948 |
+
{
|
949 |
+
$this->padding = false;
|
950 |
+
}
|
951 |
+
|
952 |
+
/**
|
953 |
+
* Pads a string
|
954 |
+
*
|
955 |
+
* Pads a string using the RSA PKCS padding standards so that its length is a multiple of the blocksize (8).
|
956 |
+
*
|
957 |
+
* If padding is disabled and $text is not a multiple of the blocksize, the string will be padded regardless
|
958 |
+
* and padding will, hence forth, be enabled.
|
959 |
+
*
|
960 |
+
* @see Crypt_Blowfish::_unpad()
|
961 |
+
* @access private
|
962 |
+
*/
|
963 |
+
function _pad($text)
|
964 |
+
{
|
965 |
+
$length = strlen($text);
|
966 |
+
|
967 |
+
if (!$this->padding) {
|
968 |
+
if ($length % 8 == 0) {
|
969 |
+
return $text;
|
970 |
+
} else {
|
971 |
+
user_error("The plaintext's length ($length) is not a multiple of the block size (8)");
|
972 |
+
$this->padding = true;
|
973 |
+
}
|
974 |
+
}
|
975 |
+
|
976 |
+
$pad = 8 - ($length % 8);
|
977 |
+
|
978 |
+
return str_pad($text, $length + $pad, chr($pad));
|
979 |
+
}
|
980 |
+
|
981 |
+
/**
|
982 |
+
* Unpads a string
|
983 |
+
*
|
984 |
+
* If padding is enabled and the reported padding length is invalid the encryption key will be assumed to be wrong
|
985 |
+
* and false will be returned.
|
986 |
+
*
|
987 |
+
* @see Crypt_Blowfish::_pad()
|
988 |
+
* @access private
|
989 |
+
*/
|
990 |
+
function _unpad($text)
|
991 |
+
{
|
992 |
+
if (!$this->padding) {
|
993 |
+
return $text;
|
994 |
+
}
|
995 |
+
|
996 |
+
$length = ord($text[strlen($text) - 1]);
|
997 |
+
|
998 |
+
if (!$length || $length > 8) {
|
999 |
+
return false;
|
1000 |
+
}
|
1001 |
+
|
1002 |
+
return substr($text, 0, -$length);
|
1003 |
+
}
|
1004 |
+
|
1005 |
+
/**
|
1006 |
+
* String Shift
|
1007 |
+
*
|
1008 |
+
* Inspired by array_shift
|
1009 |
+
*
|
1010 |
+
* @param String $string
|
1011 |
+
* @return String
|
1012 |
+
* @access private
|
1013 |
+
*/
|
1014 |
+
function _string_shift(&$string)
|
1015 |
+
{
|
1016 |
+
$substr = substr($string, 0, 8);
|
1017 |
+
$string = substr($string, 8);
|
1018 |
+
return $substr;
|
1019 |
+
}
|
1020 |
+
|
1021 |
+
/**
|
1022 |
+
* Generate CTR XOR encryption key
|
1023 |
+
*
|
1024 |
+
* Encrypt the output of this and XOR it against the ciphertext / plaintext to get the
|
1025 |
+
* plaintext / ciphertext in CTR mode.
|
1026 |
+
*
|
1027 |
+
* @see Crypt_Blowfish::decrypt()
|
1028 |
+
* @see Crypt_Blowfish::encrypt()
|
1029 |
+
* @access public
|
1030 |
+
* @param String $iv
|
1031 |
+
*/
|
1032 |
+
function _generate_xor(&$iv)
|
1033 |
+
{
|
1034 |
+
$xor = $iv;
|
1035 |
+
for ($j = 4; $j <= 8; $j+=4) {
|
1036 |
+
$temp = substr($iv, -$j, 4);
|
1037 |
+
switch ($temp) {
|
1038 |
+
case "\xFF\xFF\xFF\xFF":
|
1039 |
+
$iv = substr_replace($iv, "\x00\x00\x00\x00", -$j, 4);
|
1040 |
+
break;
|
1041 |
+
case "\x7F\xFF\xFF\xFF":
|
1042 |
+
$iv = substr_replace($iv, "\x80\x00\x00\x00", -$j, 4);
|
1043 |
+
break 2;
|
1044 |
+
default:
|
1045 |
+
extract(unpack('Ncount', $temp));
|
1046 |
+
$iv = substr_replace($iv, pack('N', $count + 1), -$j, 4);
|
1047 |
+
break 2;
|
1048 |
+
}
|
1049 |
+
}
|
1050 |
+
|
1051 |
+
return $xor;
|
1052 |
+
}
|
1053 |
+
|
1054 |
+
/**
|
1055 |
+
* Creates performance-optimized function for de/encrypt(), storing it in $this->inline_crypt
|
1056 |
+
*
|
1057 |
+
* @access private
|
1058 |
+
*/
|
1059 |
+
function inline_crypt_setup()
|
1060 |
+
{/*{{{*/
|
1061 |
+
$lambda_functions =& Crypt_Blowfish::get_lambda_functions();
|
1062 |
+
$block_size = 8;
|
1063 |
+
$mode = $this->mode;
|
1064 |
+
$code_hash = "$mode";
|
1065 |
+
|
1066 |
+
if (!isset($lambda_functions[$code_hash])) {
|
1067 |
+
$init_cryptBlock = '
|
1068 |
+
extract($self->bctx["p"], EXTR_PREFIX_ALL, "p");
|
1069 |
+
extract($self->bctx["sb"], EXTR_PREFIX_ALL, "sb");
|
1070 |
+
';
|
1071 |
+
|
1072 |
+
// Generating encrypt code:
|
1073 |
+
$_encryptBlock = '
|
1074 |
+
$in = unpack("N*", $in);
|
1075 |
+
$l = $in[1];
|
1076 |
+
$r = $in[2];
|
1077 |
+
';
|
1078 |
+
for ($i = 0; $i < 16; $i+= 2) {
|
1079 |
+
$_encryptBlock.= '
|
1080 |
+
$l^= $p_'.($i).';
|
1081 |
+
$r^= ($sb_0[$l >> 24 & 0xff] +
|
1082 |
+
$sb_1[$l >> 16 & 0xff] ^
|
1083 |
+
$sb_2[$l >> 8 & 0xff]) +
|
1084 |
+
$sb_3[$l & 0xff];
|
1085 |
+
|
1086 |
+
$r^= $p_'.($i + 1).';
|
1087 |
+
$l^= ($sb_0[$r >> 24 & 0xff] +
|
1088 |
+
$sb_1[$r >> 16 & 0xff] ^
|
1089 |
+
$sb_2[$r >> 8 & 0xff]) +
|
1090 |
+
$sb_3[$r & 0xff];
|
1091 |
+
';
|
1092 |
+
}
|
1093 |
+
$_encryptBlock.= '
|
1094 |
+
$in = pack("N*", $r ^ $p_17, $l ^ $p_16);
|
1095 |
+
';
|
1096 |
+
|
1097 |
+
// Generating decrypt code:
|
1098 |
+
$_decryptBlock = '
|
1099 |
+
$in = unpack("N*", $in);
|
1100 |
+
$l = $in[1];
|
1101 |
+
$r = $in[2];
|
1102 |
+
';
|
1103 |
+
|
1104 |
+
for ($i = 17; $i > 2; $i-= 2) {
|
1105 |
+
$_decryptBlock.= '
|
1106 |
+
$l^= $p_'.($i).';
|
1107 |
+
$r^= ($sb_0[$l >> 24 & 0xff] +
|
1108 |
+
$sb_1[$l >> 16 & 0xff] ^
|
1109 |
+
$sb_2[$l >> 8 & 0xff]) +
|
1110 |
+
$sb_3[$l & 0xff];
|
1111 |
+
|
1112 |
+
$r^= $p_'.($i - 1).';
|
1113 |
+
$l^= ($sb_0[$r >> 24 & 0xff] +
|
1114 |
+
$sb_1[$r >> 16 & 0xff] ^
|
1115 |
+
$sb_2[$r >> 8 & 0xff]) +
|
1116 |
+
$sb_3[$r & 0xff];
|
1117 |
+
';
|
1118 |
+
}
|
1119 |
+
|
1120 |
+
$_decryptBlock.= '
|
1121 |
+
$in = pack("N*", $r ^ $p_0, $l ^ $p_1);
|
1122 |
+
';
|
1123 |
+
|
1124 |
+
// Generating mode of operation code:
|
1125 |
+
switch ($mode) {
|
1126 |
+
case CRYPT_BLOWFISH_MODE_ECB:
|
1127 |
+
$encrypt = '
|
1128 |
+
$ciphertext = "";
|
1129 |
+
$text = $self->_pad($text);
|
1130 |
+
$plaintext_len = strlen($text);
|
1131 |
+
|
1132 |
+
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
|
1133 |
+
$in = substr($text, $i, '.$block_size.');
|
1134 |
+
'.$_encryptBlock.'
|
1135 |
+
$ciphertext.= $in;
|
1136 |
+
}
|
1137 |
+
return $ciphertext;
|
1138 |
+
';
|
1139 |
+
|
1140 |
+
$decrypt = '
|
1141 |
+
$plaintext = "";
|
1142 |
+
$text = str_pad($text, strlen($text) + ('.$block_size.' - strlen($text) % '.$block_size.') % '.$block_size.', chr(0));
|
1143 |
+
$ciphertext_len = strlen($text);
|
1144 |
+
|
1145 |
+
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') {
|
1146 |
+
$in = substr($text, $i, '.$block_size.');
|
1147 |
+
'.$_decryptBlock.'
|
1148 |
+
$plaintext.= $in;
|
1149 |
+
}
|
1150 |
+
|
1151 |
+
return $self->_unpad($plaintext);
|
1152 |
+
';
|
1153 |
+
break;
|
1154 |
+
case CRYPT_BLOWFISH_MODE_CBC:
|
1155 |
+
$encrypt = '
|
1156 |
+
$ciphertext = "";
|
1157 |
+
$text = $self->_pad($text);
|
1158 |
+
$plaintext_len = strlen($text);
|
1159 |
+
|
1160 |
+
$in = $self->encryptIV;
|
1161 |
+
|
1162 |
+
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
|
1163 |
+
$in = substr($text, $i, '.$block_size.') ^ $in;
|
1164 |
+
'.$_encryptBlock.'
|
1165 |
+
$ciphertext.= $in;
|
1166 |
+
}
|
1167 |
+
|
1168 |
+
if ($self->continuousBuffer) {
|
1169 |
+
$self->encryptIV = $in;
|
1170 |
+
}
|
1171 |
+
|
1172 |
+
return $ciphertext;
|
1173 |
+
';
|
1174 |
+
|
1175 |
+
$decrypt = '
|
1176 |
+
$plaintext = "";
|
1177 |
+
$text = str_pad($text, strlen($text) + ('.$block_size.' - strlen($text) % '.$block_size.') % '.$block_size.', chr(0));
|
1178 |
+
$ciphertext_len = strlen($text);
|
1179 |
+
|
1180 |
+
$iv = $self->decryptIV;
|
1181 |
+
|
1182 |
+
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') {
|
1183 |
+
$in = $block = substr($text, $i, '.$block_size.');
|
1184 |
+
'.$_decryptBlock.'
|
1185 |
+
$plaintext.= $in ^ $iv;
|
1186 |
+
$iv = $block;
|
1187 |
+
}
|
1188 |
+
|
1189 |
+
if ($self->continuousBuffer) {
|
1190 |
+
$self->decryptIV = $iv;
|
1191 |
+
}
|
1192 |
+
|
1193 |
+
return $self->_unpad($plaintext);
|
1194 |
+
';
|
1195 |
+
break;
|
1196 |
+
case CRYPT_BLOWFISH_MODE_CTR:
|
1197 |
+
$encrypt = '
|
1198 |
+
$ciphertext = "";
|
1199 |
+
$plaintext_len = strlen($text);
|
1200 |
+
$xor = $self->encryptIV;
|
1201 |
+
$buffer = &$self->enbuffer;
|
1202 |
+
|
1203 |
+
if (strlen($buffer["encrypted"])) {
|
1204 |
+
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
|
1205 |
+
$block = substr($text, $i, '.$block_size.');
|
1206 |
+
if (strlen($block) > strlen($buffer["encrypted"])) {
|
1207 |
+
$in = $self->_generate_xor($xor);
|
1208 |
+
'.$_encryptBlock.'
|
1209 |
+
$buffer["encrypted"].= $in;
|
1210 |
+
}
|
1211 |
+
$key = $self->_string_shift($buffer["encrypted"]);
|
1212 |
+
$ciphertext.= $block ^ $key;
|
1213 |
+
}
|
1214 |
+
} else {
|
1215 |
+
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
|
1216 |
+
$block = substr($text, $i, '.$block_size.');
|
1217 |
+
$in = $self->_generate_xor($xor);
|
1218 |
+
'.$_encryptBlock.'
|
1219 |
+
$key = $in;
|
1220 |
+
$ciphertext.= $block ^ $key;
|
1221 |
+
}
|
1222 |
+
}
|
1223 |
+
if ($self->continuousBuffer) {
|
1224 |
+
$self->encryptIV = $xor;
|
1225 |
+
if ($start = $plaintext_len % '.$block_size.') {
|
1226 |
+
$buffer["encrypted"] = substr($key, $start) . $buffer["encrypted"];
|
1227 |
+
}
|
1228 |
+
}
|
1229 |
+
|
1230 |
+
return $ciphertext;
|
1231 |
+
';
|
1232 |
+
|
1233 |
+
$decrypt = '
|
1234 |
+
$plaintext = "";
|
1235 |
+
$ciphertext_len = strlen($text);
|
1236 |
+
$xor = $self->decryptIV;
|
1237 |
+
$buffer = &$self->debuffer;
|
1238 |
+
|
1239 |
+
if (strlen($buffer["ciphertext"])) {
|
1240 |
+
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') {
|
1241 |
+
$block = substr($text, $i, '.$block_size.');
|
1242 |
+
if (strlen($block) > strlen($buffer["ciphertext"])) {
|
1243 |
+
$in = $self->_generate_xor($xor);
|
1244 |
+
'.$_encryptBlock.'
|
1245 |
+
$buffer["ciphertext"].= $in;
|
1246 |
+
}
|
1247 |
+
$key = $self->_string_shift($buffer["ciphertext"]);
|
1248 |
+
$plaintext.= $block ^ $key;
|
1249 |
+
}
|
1250 |
+
} else {
|
1251 |
+
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') {
|
1252 |
+
$block = substr($text, $i, '.$block_size.');
|
1253 |
+
$in = $self->_generate_xor($xor);
|
1254 |
+
'.$_encryptBlock.'
|
1255 |
+
$key = $in;
|
1256 |
+
$plaintext.= $block ^ $key;
|
1257 |
+
}
|
1258 |
+
}
|
1259 |
+
if ($self->continuousBuffer) {
|
1260 |
+
$self->decryptIV = $xor;
|
1261 |
+
if ($start = $ciphertext_len % '.$block_size.') {
|
1262 |
+
$buffer["ciphertext"] = substr($key, $start) . $buffer["ciphertext"];
|
1263 |
+
}
|
1264 |
+
}
|
1265 |
+
return $plaintext;
|
1266 |
+
';
|
1267 |
+
break;
|
1268 |
+
case CRYPT_BLOWFISH_MODE_CFB:
|
1269 |
+
$encrypt = '
|
1270 |
+
$ciphertext = "";
|
1271 |
+
$buffer = &$self->enbuffer;
|
1272 |
+
|
1273 |
+
if ($self->continuousBuffer) {
|
1274 |
+
$iv = &$self->encryptIV;
|
1275 |
+
$pos = &$buffer["pos"];
|
1276 |
+
} else {
|
1277 |
+
$iv = $self->encryptIV;
|
1278 |
+
$pos = 0;
|
1279 |
+
}
|
1280 |
+
$len = strlen($text);
|
1281 |
+
$i = 0;
|
1282 |
+
if ($pos) {
|
1283 |
+
$orig_pos = $pos;
|
1284 |
+
$max = '.$block_size.' - $pos;
|
1285 |
+
if ($len >= $max) {
|
1286 |
+
$i = $max;
|
1287 |
+
$len-= $max;
|
1288 |
+
$pos = 0;
|
1289 |
+
} else {
|
1290 |
+
$i = $len;
|
1291 |
+
$pos+= $len;
|
1292 |
+
$len = 0;
|
1293 |
+
}
|
1294 |
+
$ciphertext = substr($iv, $orig_pos) ^ $text;
|
1295 |
+
$iv = substr_replace($iv, $ciphertext, $orig_pos, $i);
|
1296 |
+
}
|
1297 |
+
while ($len >= '.$block_size.') {
|
1298 |
+
$in = $iv;
|
1299 |
+
'.$_encryptBlock.';
|
1300 |
+
$iv = $in ^ substr($text, $i, '.$block_size.');
|
1301 |
+
$ciphertext.= $iv;
|
1302 |
+
$len-= '.$block_size.';
|
1303 |
+
$i+= '.$block_size.';
|
1304 |
+
}
|
1305 |
+
if ($len) {
|
1306 |
+
$in = $iv;
|
1307 |
+
'.$_encryptBlock.'
|
1308 |
+
$iv = $in;
|
1309 |
+
$block = $iv ^ substr($text, $i);
|
1310 |
+
$iv = substr_replace($iv, $block, 0, $len);
|
1311 |
+
$ciphertext.= $block;
|
1312 |
+
$pos = $len;
|
1313 |
+
}
|
1314 |
+
return $ciphertext;
|
1315 |
+
';
|
1316 |
+
|
1317 |
+
$decrypt = '
|
1318 |
+
$plaintext = "";
|
1319 |
+
$buffer = &$self->debuffer;
|
1320 |
+
|
1321 |
+
if ($self->continuousBuffer) {
|
1322 |
+
$iv = &$self->decryptIV;
|
1323 |
+
$pos = &$buffer["pos"];
|
1324 |
+
} else {
|
1325 |
+
$iv = $self->decryptIV;
|
1326 |
+
$pos = 0;
|
1327 |
+
}
|
1328 |
+
$len = strlen($text);
|
1329 |
+
$i = 0;
|
1330 |
+
if ($pos) {
|
1331 |
+
$orig_pos = $pos;
|
1332 |
+
$max = '.$block_size.' - $pos;
|
1333 |
+
if ($len >= $max) {
|
1334 |
+
$i = $max;
|
1335 |
+
$len-= $max;
|
1336 |
+
$pos = 0;
|
1337 |
+
} else {
|
1338 |
+
$i = $len;
|
1339 |
+
$pos+= $len;
|
1340 |
+
$len = 0;
|
1341 |
+
}
|
1342 |
+
$plaintext = substr($iv, $orig_pos) ^ $text;
|
1343 |
+
$iv = substr_replace($iv, substr($text, 0, $i), $orig_pos, $i);
|
1344 |
+
}
|
1345 |
+
while ($len >= '.$block_size.') {
|
1346 |
+
$in = $iv;
|
1347 |
+
'.$_encryptBlock.'
|
1348 |
+
$iv = $in;
|
1349 |
+
$cb = substr($text, $i, '.$block_size.');
|
1350 |
+
$plaintext.= $iv ^ $cb;
|
1351 |
+
$iv = $cb;
|
1352 |
+
$len-= '.$block_size.';
|
1353 |
+
$i+= '.$block_size.';
|
1354 |
+
}
|
1355 |
+
if ($len) {
|
1356 |
+
$in = $iv;
|
1357 |
+
'.$_encryptBlock.'
|
1358 |
+
$iv = $in;
|
1359 |
+
$plaintext.= $iv ^ substr($text, $i);
|
1360 |
+
$iv = substr_replace($iv, substr($text, $i), 0, $len);
|
1361 |
+
$pos = $len;
|
1362 |
+
}
|
1363 |
+
|
1364 |
+
return $plaintext;
|
1365 |
+
';
|
1366 |
+
break;
|
1367 |
+
case CRYPT_BLOWFISH_MODE_OFB:
|
1368 |
+
$encrypt = '
|
1369 |
+
$ciphertext = "";
|
1370 |
+
$plaintext_len = strlen($text);
|
1371 |
+
$xor = $self->encryptIV;
|
1372 |
+
$buffer = &$self->enbuffer;
|
1373 |
+
|
1374 |
+
if (strlen($buffer["xor"])) {
|
1375 |
+
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
|
1376 |
+
$block = substr($text, $i, '.$block_size.');
|
1377 |
+
if (strlen($block) > strlen($buffer["xor"])) {
|
1378 |
+
$in = $xor;
|
1379 |
+
'.$_encryptBlock.'
|
1380 |
+
$xor = $in;
|
1381 |
+
$buffer["xor"].= $xor;
|
1382 |
+
}
|
1383 |
+
$key = $self->_string_shift($buffer["xor"]);
|
1384 |
+
$ciphertext.= $block ^ $key;
|
1385 |
+
}
|
1386 |
+
} else {
|
1387 |
+
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
|
1388 |
+
$in = $xor;
|
1389 |
+
'.$_encryptBlock.'
|
1390 |
+
$xor = $in;
|
1391 |
+
$ciphertext.= substr($text, $i, '.$block_size.') ^ $xor;
|
1392 |
+
}
|
1393 |
+
$key = $xor;
|
1394 |
+
}
|
1395 |
+
if ($self->continuousBuffer) {
|
1396 |
+
$self->encryptIV = $xor;
|
1397 |
+
if ($start = $plaintext_len % '.$block_size.') {
|
1398 |
+
$buffer["xor"] = substr($key, $start) . $buffer["xor"];
|
1399 |
+
}
|
1400 |
+
}
|
1401 |
+
return $ciphertext;
|
1402 |
+
';
|
1403 |
+
|
1404 |
+
$decrypt = '
|
1405 |
+
$plaintext = "";
|
1406 |
+
$ciphertext_len = strlen($text);
|
1407 |
+
$xor = $self->decryptIV;
|
1408 |
+
$buffer = &$self->debuffer;
|
1409 |
+
|
1410 |
+
if (strlen($buffer["xor"])) {
|
1411 |
+
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') {
|
1412 |
+
$block = substr($text, $i, '.$block_size.');
|
1413 |
+
if (strlen($block) > strlen($buffer["xor"])) {
|
1414 |
+
$in = $xor;
|
1415 |
+
'.$_encryptBlock.'
|
1416 |
+
$xor = $in;
|
1417 |
+
$buffer["xor"].= $xor;
|
1418 |
+
}
|
1419 |
+
$key = $self->_string_shift($buffer["xor"]);
|
1420 |
+
$plaintext.= $block ^ $key;
|
1421 |
+
}
|
1422 |
+
} else {
|
1423 |
+
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') {
|
1424 |
+
$in = $xor;
|
1425 |
+
'.$_encryptBlock.'
|
1426 |
+
$xor = $in;
|
1427 |
+
$plaintext.= substr($text, $i, '.$block_size.') ^ $xor;
|
1428 |
+
}
|
1429 |
+
$key = $xor;
|
1430 |
+
}
|
1431 |
+
if ($self->continuousBuffer) {
|
1432 |
+
$self->decryptIV = $xor;
|
1433 |
+
if ($start = $ciphertext_len % '.$block_size.') {
|
1434 |
+
$buffer["xor"] = substr($key, $start) . $buffer["xor"];
|
1435 |
+
}
|
1436 |
+
}
|
1437 |
+
return $plaintext;
|
1438 |
+
';
|
1439 |
+
break;
|
1440 |
+
}
|
1441 |
+
$fnc_head = '$action, &$self, $text';
|
1442 |
+
$fnc_body = $init_cryptBlock . 'if ($action == "encrypt") { ' . $encrypt . ' } else { ' . $decrypt . ' }';
|
1443 |
+
|
1444 |
+
if (function_exists('create_function') && is_callable('create_function')) {
|
1445 |
+
$lambda_functions[$code_hash] = create_function($fnc_head, $fnc_body);
|
1446 |
+
} else {
|
1447 |
+
eval('function ' . ($lambda_functions[$code_hash] = 'f' . md5(microtime())) . '(' . $fnc_head . ') { ' . $fnc_body . ' }');
|
1448 |
+
}
|
1449 |
+
}
|
1450 |
+
$this->inline_crypt = $lambda_functions[$code_hash];
|
1451 |
+
}/*}}}*/
|
1452 |
+
|
1453 |
+
/**
|
1454 |
+
* Holds the lambda_functions table (classwide)
|
1455 |
+
*
|
1456 |
+
* @see inline_crypt_setup()
|
1457 |
+
* @return Array
|
1458 |
+
* @access private
|
1459 |
+
*/
|
1460 |
+
function &get_lambda_functions()
|
1461 |
+
{
|
1462 |
+
static $functions = array();
|
1463 |
+
return $functions;
|
1464 |
+
}
|
1465 |
+
}
|
1466 |
+
|
1467 |
+
// vim: ts=4:sw=4:et:
|
1468 |
+
// vim6: fdl=1:
|
modules/phpseclib/Crypt/DES.php
CHANGED
@@ -1,2536 +1,2536 @@
|
|
1 |
-
<?php
|
2 |
-
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
3 |
-
|
4 |
-
/**
|
5 |
-
* Pure-PHP implementation of DES.
|
6 |
-
*
|
7 |
-
* Uses mcrypt, if available, and an internal implementation, otherwise.
|
8 |
-
*
|
9 |
-
* PHP versions 4 and 5
|
10 |
-
*
|
11 |
-
* Useful resources are as follows:
|
12 |
-
*
|
13 |
-
* - {@link http://en.wikipedia.org/wiki/DES_supplementary_material Wikipedia: DES supplementary material}
|
14 |
-
* - {@link http://www.itl.nist.gov/fipspubs/fip46-2.htm FIPS 46-2 - (DES), Data Encryption Standard}
|
15 |
-
* - {@link http://www.cs.eku.edu/faculty/styer/460/Encrypt/JS-DES.html JavaScript DES Example}
|
16 |
-
*
|
17 |
-
* Here's a short example of how to use this library:
|
18 |
-
* <code>
|
19 |
-
* <?php
|
20 |
-
* include('Crypt/DES.php');
|
21 |
-
*
|
22 |
-
* $des = new Crypt_DES();
|
23 |
-
*
|
24 |
-
* $des->setKey('abcdefgh');
|
25 |
-
*
|
26 |
-
* $size = 10 * 1024;
|
27 |
-
* $plaintext = '';
|
28 |
-
* for ($i = 0; $i < $size; $i++) {
|
29 |
-
* $plaintext.= 'a';
|
30 |
-
* }
|
31 |
-
*
|
32 |
-
* echo $des->decrypt($des->encrypt($plaintext));
|
33 |
-
* ?>
|
34 |
-
* </code>
|
35 |
-
*
|
36 |
-
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
37 |
-
* of this software and associated documentation files (the "Software"), to deal
|
38 |
-
* in the Software without restriction, including without limitation the rights
|
39 |
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
40 |
-
* copies of the Software, and to permit persons to whom the Software is
|
41 |
-
* furnished to do so, subject to the following conditions:
|
42 |
-
*
|
43 |
-
* The above copyright notice and this permission notice shall be included in
|
44 |
-
* all copies or substantial portions of the Software.
|
45 |
-
*
|
46 |
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
47 |
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
48 |
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
49 |
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
50 |
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
51 |
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
52 |
-
* THE SOFTWARE.
|
53 |
-
*
|
54 |
-
* @category Crypt
|
55 |
-
* @package Crypt_DES
|
56 |
-
* @author Jim Wigginton <terrafrost@php.net>
|
57 |
-
* @copyright MMVII Jim Wigginton
|
58 |
-
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
59 |
-
* @link http://phpseclib.sourceforge.net
|
60 |
-
*/
|
61 |
-
|
62 |
-
/**#@+
|
63 |
-
* @access private
|
64 |
-
* @see Crypt_DES::_prepareKey()
|
65 |
-
* @see Crypt_DES::_processBlock()
|
66 |
-
*/
|
67 |
-
/**
|
68 |
-
* Contains array_reverse($keys[CRYPT_DES_DECRYPT])
|
69 |
-
*/
|
70 |
-
define('CRYPT_DES_ENCRYPT', 0);
|
71 |
-
/**
|
72 |
-
* Contains array_reverse($keys[CRYPT_DES_ENCRYPT])
|
73 |
-
*/
|
74 |
-
define('CRYPT_DES_DECRYPT', 1);
|
75 |
-
/**
|
76 |
-
* Contains $keys[CRYPT_DES_ENCRYPT] as 1-dim array
|
77 |
-
*/
|
78 |
-
define('CRYPT_DES_ENCRYPT_1DIM', 2);
|
79 |
-
/**
|
80 |
-
* Contains $keys[CRYPT_DES_DECRYPT] as 1-dim array
|
81 |
-
*/
|
82 |
-
define('CRYPT_DES_DECRYPT_1DIM', 3);
|
83 |
-
/**#@-*/
|
84 |
-
|
85 |
-
/**#@+
|
86 |
-
* @access public
|
87 |
-
* @see Crypt_DES::encrypt()
|
88 |
-
* @see Crypt_DES::decrypt()
|
89 |
-
*/
|
90 |
-
/**
|
91 |
-
* Encrypt / decrypt using the Counter mode.
|
92 |
-
*
|
93 |
-
* Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
|
94 |
-
*
|
95 |
-
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
|
96 |
-
*/
|
97 |
-
define('CRYPT_DES_MODE_CTR', -1);
|
98 |
-
/**
|
99 |
-
* Encrypt / decrypt using the Electronic Code Book mode.
|
100 |
-
*
|
101 |
-
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
|
102 |
-
*/
|
103 |
-
define('CRYPT_DES_MODE_ECB', 1);
|
104 |
-
/**
|
105 |
-
* Encrypt / decrypt using the Code Book Chaining mode.
|
106 |
-
*
|
107 |
-
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
|
108 |
-
*/
|
109 |
-
define('CRYPT_DES_MODE_CBC', 2);
|
110 |
-
/**
|
111 |
-
* Encrypt / decrypt using the Cipher Feedback mode.
|
112 |
-
*
|
113 |
-
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
|
114 |
-
*/
|
115 |
-
define('CRYPT_DES_MODE_CFB', 3);
|
116 |
-
/**
|
117 |
-
* Encrypt / decrypt using the Cipher Feedback mode.
|
118 |
-
*
|
119 |
-
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
|
120 |
-
*/
|
121 |
-
define('CRYPT_DES_MODE_OFB', 4);
|
122 |
-
/**#@-*/
|
123 |
-
|
124 |
-
/**#@+
|
125 |
-
* @access private
|
126 |
-
* @see Crypt_DES::Crypt_DES()
|
127 |
-
*/
|
128 |
-
/**
|
129 |
-
* Toggles the internal implementation
|
130 |
-
*/
|
131 |
-
define('CRYPT_DES_MODE_INTERNAL', 1);
|
132 |
-
/**
|
133 |
-
* Toggles the mcrypt implementation
|
134 |
-
*/
|
135 |
-
define('CRYPT_DES_MODE_MCRYPT', 2);
|
136 |
-
/**#@-*/
|
137 |
-
|
138 |
-
/**
|
139 |
-
* Pure-PHP implementation of DES.
|
140 |
-
*
|
141 |
-
* @author Jim Wigginton <terrafrost@php.net>
|
142 |
-
* @version 0.1.0
|
143 |
-
* @access public
|
144 |
-
* @package Crypt_DES
|
145 |
-
*/
|
146 |
-
class Crypt_DES {
|
147 |
-
/**
|
148 |
-
* The Key Schedule
|
149 |
-
*
|
150 |
-
* @see Crypt_DES::setKey()
|
151 |
-
* @var Array
|
152 |
-
* @access private
|
153 |
-
*/
|
154 |
-
var $keys = "\0\0\0\0\0\0\0\0";
|
155 |
-
|
156 |
-
/**
|
157 |
-
* The Encryption Mode
|
158 |
-
*
|
159 |
-
* @see Crypt_DES::Crypt_DES()
|
160 |
-
* @var Integer
|
161 |
-
* @access private
|
162 |
-
*/
|
163 |
-
var $mode;
|
164 |
-
|
165 |
-
/**
|
166 |
-
* Continuous Buffer status
|
167 |
-
*
|
168 |
-
* @see Crypt_DES::enableContinuousBuffer()
|
169 |
-
* @var Boolean
|
170 |
-
* @access private
|
171 |
-
*/
|
172 |
-
var $continuousBuffer = false;
|
173 |
-
|
174 |
-
/**
|
175 |
-
* Padding status
|
176 |
-
*
|
177 |
-
* @see Crypt_DES::enablePadding()
|
178 |
-
* @var Boolean
|
179 |
-
* @access private
|
180 |
-
*/
|
181 |
-
var $padding = true;
|
182 |
-
|
183 |
-
/**
|
184 |
-
* The Initialization Vector
|
185 |
-
*
|
186 |
-
* @see Crypt_DES::setIV()
|
187 |
-
* @var String
|
188 |
-
* @access private
|
189 |
-
*/
|
190 |
-
var $iv = "\0\0\0\0\0\0\0\0";
|
191 |
-
|
192 |
-
/**
|
193 |
-
* A "sliding" Initialization Vector
|
194 |
-
*
|
195 |
-
* @see Crypt_DES::enableContinuousBuffer()
|
196 |
-
* @var String
|
197 |
-
* @access private
|
198 |
-
*/
|
199 |
-
var $encryptIV = "\0\0\0\0\0\0\0\0";
|
200 |
-
|
201 |
-
/**
|
202 |
-
* A "sliding" Initialization Vector
|
203 |
-
*
|
204 |
-
* @see Crypt_DES::enableContinuousBuffer()
|
205 |
-
* @var String
|
206 |
-
* @access private
|
207 |
-
*/
|
208 |
-
var $decryptIV = "\0\0\0\0\0\0\0\0";
|
209 |
-
|
210 |
-
/**
|
211 |
-
* mcrypt resource for encryption
|
212 |
-
*
|
213 |
-
* The mcrypt resource can be recreated every time something needs to be created or it can be created just once.
|
214 |
-
* Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.
|
215 |
-
*
|
216 |
-
* @see Crypt_DES::encrypt()
|
217 |
-
* @var String
|
218 |
-
* @access private
|
219 |
-
*/
|
220 |
-
var $enmcrypt;
|
221 |
-
|
222 |
-
/**
|
223 |
-
* mcrypt resource for decryption
|
224 |
-
*
|
225 |
-
* The mcrypt resource can be recreated every time something needs to be created or it can be created just once.
|
226 |
-
* Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.
|
227 |
-
*
|
228 |
-
* @see Crypt_DES::decrypt()
|
229 |
-
* @var String
|
230 |
-
* @access private
|
231 |
-
*/
|
232 |
-
var $demcrypt;
|
233 |
-
|
234 |
-
/**
|
235 |
-
* Does the enmcrypt resource need to be (re)initialized?
|
236 |
-
*
|
237 |
-
* @see Crypt_DES::setKey()
|
238 |
-
* @see Crypt_DES::setIV()
|
239 |
-
* @var Boolean
|
240 |
-
* @access private
|
241 |
-
*/
|
242 |
-
var $enchanged = true;
|
243 |
-
|
244 |
-
/**
|
245 |
-
* Does the demcrypt resource need to be (re)initialized?
|
246 |
-
*
|
247 |
-
* @see Crypt_DES::setKey()
|
248 |
-
* @see Crypt_DES::setIV()
|
249 |
-
* @var Boolean
|
250 |
-
* @access private
|
251 |
-
*/
|
252 |
-
var $dechanged = true;
|
253 |
-
|
254 |
-
/**
|
255 |
-
* Is the mode one that is paddable?
|
256 |
-
*
|
257 |
-
* @see Crypt_DES::Crypt_DES()
|
258 |
-
* @var Boolean
|
259 |
-
* @access private
|
260 |
-
*/
|
261 |
-
var $paddable = false;
|
262 |
-
|
263 |
-
/**
|
264 |
-
* Encryption buffer for CTR, OFB and CFB modes
|
265 |
-
*
|
266 |
-
* @see Crypt_DES::encrypt()
|
267 |
-
* @var Array
|
268 |
-
* @access private
|
269 |
-
*/
|
270 |
-
var $enbuffer = array('encrypted' => '', 'xor' => '', 'pos' => 0, 'enmcrypt_init' => true);
|
271 |
-
|
272 |
-
/**
|
273 |
-
* Decryption buffer for CTR, OFB and CFB modes
|
274 |
-
*
|
275 |
-
* @see Crypt_DES::decrypt()
|
276 |
-
* @var Array
|
277 |
-
* @access private
|
278 |
-
*/
|
279 |
-
var $debuffer = array('ciphertext' => '', 'xor' => '', 'pos' => 0, 'demcrypt_init' => true);
|
280 |
-
|
281 |
-
/**
|
282 |
-
* mcrypt resource for CFB mode
|
283 |
-
*
|
284 |
-
* @see Crypt_DES::encrypt()
|
285 |
-
* @see Crypt_DES::decrypt()
|
286 |
-
* @var String
|
287 |
-
* @access private
|
288 |
-
*/
|
289 |
-
var $ecb;
|
290 |
-
|
291 |
-
/**
|
292 |
-
* Performance-optimized callback function for en/decrypt()
|
293 |
-
*
|
294 |
-
* @var Callback
|
295 |
-
* @access private
|
296 |
-
*/
|
297 |
-
var $inline_crypt;
|
298 |
-
|
299 |
-
/**
|
300 |
-
* Holds whether performance-optimized $inline_crypt should be used or not.
|
301 |
-
*
|
302 |
-
* @var Boolean
|
303 |
-
* @access private
|
304 |
-
*/
|
305 |
-
var $use_inline_crypt = false;
|
306 |
-
|
307 |
-
/**
|
308 |
-
* Shuffle table.
|
309 |
-
*
|
310 |
-
* For each byte value index, the entry holds an 8-byte string
|
311 |
-
* with each byte containing all bits in the same state as the
|
312 |
-
* corresponding bit in the index value.
|
313 |
-
*
|
314 |
-
* @see Crypt_DES::_processBlock()
|
315 |
-
* @see Crypt_DES::_prepareKey()
|
316 |
-
* @var Array
|
317 |
-
* @access private
|
318 |
-
*/
|
319 |
-
var $shuffle = array(
|
320 |
-
"\x00\x00\x00\x00\x00\x00\x00\x00", "\x00\x00\x00\x00\x00\x00\x00\xFF",
|
321 |
-
"\x00\x00\x00\x00\x00\x00\xFF\x00", "\x00\x00\x00\x00\x00\x00\xFF\xFF",
|
322 |
-
"\x00\x00\x00\x00\x00\xFF\x00\x00", "\x00\x00\x00\x00\x00\xFF\x00\xFF",
|
323 |
-
"\x00\x00\x00\x00\x00\xFF\xFF\x00", "\x00\x00\x00\x00\x00\xFF\xFF\xFF",
|
324 |
-
"\x00\x00\x00\x00\xFF\x00\x00\x00", "\x00\x00\x00\x00\xFF\x00\x00\xFF",
|
325 |
-
"\x00\x00\x00\x00\xFF\x00\xFF\x00", "\x00\x00\x00\x00\xFF\x00\xFF\xFF",
|
326 |
-
"\x00\x00\x00\x00\xFF\xFF\x00\x00", "\x00\x00\x00\x00\xFF\xFF\x00\xFF",
|
327 |
-
"\x00\x00\x00\x00\xFF\xFF\xFF\x00", "\x00\x00\x00\x00\xFF\xFF\xFF\xFF",
|
328 |
-
"\x00\x00\x00\xFF\x00\x00\x00\x00", "\x00\x00\x00\xFF\x00\x00\x00\xFF",
|
329 |
-
"\x00\x00\x00\xFF\x00\x00\xFF\x00", "\x00\x00\x00\xFF\x00\x00\xFF\xFF",
|
330 |
-
"\x00\x00\x00\xFF\x00\xFF\x00\x00", "\x00\x00\x00\xFF\x00\xFF\x00\xFF",
|
331 |
-
"\x00\x00\x00\xFF\x00\xFF\xFF\x00", "\x00\x00\x00\xFF\x00\xFF\xFF\xFF",
|
332 |
-
"\x00\x00\x00\xFF\xFF\x00\x00\x00", "\x00\x00\x00\xFF\xFF\x00\x00\xFF",
|
333 |
-
"\x00\x00\x00\xFF\xFF\x00\xFF\x00", "\x00\x00\x00\xFF\xFF\x00\xFF\xFF",
|
334 |
-
"\x00\x00\x00\xFF\xFF\xFF\x00\x00", "\x00\x00\x00\xFF\xFF\xFF\x00\xFF",
|
335 |
-
"\x00\x00\x00\xFF\xFF\xFF\xFF\x00", "\x00\x00\x00\xFF\xFF\xFF\xFF\xFF",
|
336 |
-
"\x00\x00\xFF\x00\x00\x00\x00\x00", "\x00\x00\xFF\x00\x00\x00\x00\xFF",
|
337 |
-
"\x00\x00\xFF\x00\x00\x00\xFF\x00", "\x00\x00\xFF\x00\x00\x00\xFF\xFF",
|
338 |
-
"\x00\x00\xFF\x00\x00\xFF\x00\x00", "\x00\x00\xFF\x00\x00\xFF\x00\xFF",
|
339 |
-
"\x00\x00\xFF\x00\x00\xFF\xFF\x00", "\x00\x00\xFF\x00\x00\xFF\xFF\xFF",
|
340 |
-
"\x00\x00\xFF\x00\xFF\x00\x00\x00", "\x00\x00\xFF\x00\xFF\x00\x00\xFF",
|
341 |
-
"\x00\x00\xFF\x00\xFF\x00\xFF\x00", "\x00\x00\xFF\x00\xFF\x00\xFF\xFF",
|
342 |
-
"\x00\x00\xFF\x00\xFF\xFF\x00\x00", "\x00\x00\xFF\x00\xFF\xFF\x00\xFF",
|
343 |
-
"\x00\x00\xFF\x00\xFF\xFF\xFF\x00", "\x00\x00\xFF\x00\xFF\xFF\xFF\xFF",
|
344 |
-
"\x00\x00\xFF\xFF\x00\x00\x00\x00", "\x00\x00\xFF\xFF\x00\x00\x00\xFF",
|
345 |
-
"\x00\x00\xFF\xFF\x00\x00\xFF\x00", "\x00\x00\xFF\xFF\x00\x00\xFF\xFF",
|
346 |
-
"\x00\x00\xFF\xFF\x00\xFF\x00\x00", "\x00\x00\xFF\xFF\x00\xFF\x00\xFF",
|
347 |
-
"\x00\x00\xFF\xFF\x00\xFF\xFF\x00", "\x00\x00\xFF\xFF\x00\xFF\xFF\xFF",
|
348 |
-
"\x00\x00\xFF\xFF\xFF\x00\x00\x00", "\x00\x00\xFF\xFF\xFF\x00\x00\xFF",
|
349 |
-
"\x00\x00\xFF\xFF\xFF\x00\xFF\x00", "\x00\x00\xFF\xFF\xFF\x00\xFF\xFF",
|
350 |
-
"\x00\x00\xFF\xFF\xFF\xFF\x00\x00", "\x00\x00\xFF\xFF\xFF\xFF\x00\xFF",
|
351 |
-
"\x00\x00\xFF\xFF\xFF\xFF\xFF\x00", "\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF",
|
352 |
-
"\x00\xFF\x00\x00\x00\x00\x00\x00", "\x00\xFF\x00\x00\x00\x00\x00\xFF",
|
353 |
-
"\x00\xFF\x00\x00\x00\x00\xFF\x00", "\x00\xFF\x00\x00\x00\x00\xFF\xFF",
|
354 |
-
"\x00\xFF\x00\x00\x00\xFF\x00\x00", "\x00\xFF\x00\x00\x00\xFF\x00\xFF",
|
355 |
-
"\x00\xFF\x00\x00\x00\xFF\xFF\x00", "\x00\xFF\x00\x00\x00\xFF\xFF\xFF",
|
356 |
-
"\x00\xFF\x00\x00\xFF\x00\x00\x00", "\x00\xFF\x00\x00\xFF\x00\x00\xFF",
|
357 |
-
"\x00\xFF\x00\x00\xFF\x00\xFF\x00", "\x00\xFF\x00\x00\xFF\x00\xFF\xFF",
|
358 |
-
"\x00\xFF\x00\x00\xFF\xFF\x00\x00", "\x00\xFF\x00\x00\xFF\xFF\x00\xFF",
|
359 |
-
"\x00\xFF\x00\x00\xFF\xFF\xFF\x00", "\x00\xFF\x00\x00\xFF\xFF\xFF\xFF",
|
360 |
-
"\x00\xFF\x00\xFF\x00\x00\x00\x00", "\x00\xFF\x00\xFF\x00\x00\x00\xFF",
|
361 |
-
"\x00\xFF\x00\xFF\x00\x00\xFF\x00", "\x00\xFF\x00\xFF\x00\x00\xFF\xFF",
|
362 |
-
"\x00\xFF\x00\xFF\x00\xFF\x00\x00", "\x00\xFF\x00\xFF\x00\xFF\x00\xFF",
|
363 |
-
"\x00\xFF\x00\xFF\x00\xFF\xFF\x00", "\x00\xFF\x00\xFF\x00\xFF\xFF\xFF",
|
364 |
-
"\x00\xFF\x00\xFF\xFF\x00\x00\x00", "\x00\xFF\x00\xFF\xFF\x00\x00\xFF",
|
365 |
-
"\x00\xFF\x00\xFF\xFF\x00\xFF\x00", "\x00\xFF\x00\xFF\xFF\x00\xFF\xFF",
|
366 |
-
"\x00\xFF\x00\xFF\xFF\xFF\x00\x00", "\x00\xFF\x00\xFF\xFF\xFF\x00\xFF",
|
367 |
-
"\x00\xFF\x00\xFF\xFF\xFF\xFF\x00", "\x00\xFF\x00\xFF\xFF\xFF\xFF\xFF",
|
368 |
-
"\x00\xFF\xFF\x00\x00\x00\x00\x00", "\x00\xFF\xFF\x00\x00\x00\x00\xFF",
|
369 |
-
"\x00\xFF\xFF\x00\x00\x00\xFF\x00", "\x00\xFF\xFF\x00\x00\x00\xFF\xFF",
|
370 |
-
"\x00\xFF\xFF\x00\x00\xFF\x00\x00", "\x00\xFF\xFF\x00\x00\xFF\x00\xFF",
|
371 |
-
"\x00\xFF\xFF\x00\x00\xFF\xFF\x00", "\x00\xFF\xFF\x00\x00\xFF\xFF\xFF",
|
372 |
-
"\x00\xFF\xFF\x00\xFF\x00\x00\x00", "\x00\xFF\xFF\x00\xFF\x00\x00\xFF",
|
373 |
-
"\x00\xFF\xFF\x00\xFF\x00\xFF\x00", "\x00\xFF\xFF\x00\xFF\x00\xFF\xFF",
|
374 |
-
"\x00\xFF\xFF\x00\xFF\xFF\x00\x00", "\x00\xFF\xFF\x00\xFF\xFF\x00\xFF",
|
375 |
-
"\x00\xFF\xFF\x00\xFF\xFF\xFF\x00", "\x00\xFF\xFF\x00\xFF\xFF\xFF\xFF",
|
376 |
-
"\x00\xFF\xFF\xFF\x00\x00\x00\x00", "\x00\xFF\xFF\xFF\x00\x00\x00\xFF",
|
377 |
-
"\x00\xFF\xFF\xFF\x00\x00\xFF\x00", "\x00\xFF\xFF\xFF\x00\x00\xFF\xFF",
|
378 |
-
"\x00\xFF\xFF\xFF\x00\xFF\x00\x00", "\x00\xFF\xFF\xFF\x00\xFF\x00\xFF",
|
379 |
-
"\x00\xFF\xFF\xFF\x00\xFF\xFF\x00", "\x00\xFF\xFF\xFF\x00\xFF\xFF\xFF",
|
380 |
-
"\x00\xFF\xFF\xFF\xFF\x00\x00\x00", "\x00\xFF\xFF\xFF\xFF\x00\x00\xFF",
|
381 |
-
"\x00\xFF\xFF\xFF\xFF\x00\xFF\x00", "\x00\xFF\xFF\xFF\xFF\x00\xFF\xFF",
|
382 |
-
"\x00\xFF\xFF\xFF\xFF\xFF\x00\x00", "\x00\xFF\xFF\xFF\xFF\xFF\x00\xFF",
|
383 |
-
"\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", "\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF",
|
384 |
-
"\xFF\x00\x00\x00\x00\x00\x00\x00", "\xFF\x00\x00\x00\x00\x00\x00\xFF",
|
385 |
-
"\xFF\x00\x00\x00\x00\x00\xFF\x00", "\xFF\x00\x00\x00\x00\x00\xFF\xFF",
|
386 |
-
"\xFF\x00\x00\x00\x00\xFF\x00\x00", "\xFF\x00\x00\x00\x00\xFF\x00\xFF",
|
387 |
-
"\xFF\x00\x00\x00\x00\xFF\xFF\x00", "\xFF\x00\x00\x00\x00\xFF\xFF\xFF",
|
388 |
-
"\xFF\x00\x00\x00\xFF\x00\x00\x00", "\xFF\x00\x00\x00\xFF\x00\x00\xFF",
|
389 |
-
"\xFF\x00\x00\x00\xFF\x00\xFF\x00", "\xFF\x00\x00\x00\xFF\x00\xFF\xFF",
|
390 |
-
"\xFF\x00\x00\x00\xFF\xFF\x00\x00", "\xFF\x00\x00\x00\xFF\xFF\x00\xFF",
|
391 |
-
"\xFF\x00\x00\x00\xFF\xFF\xFF\x00", "\xFF\x00\x00\x00\xFF\xFF\xFF\xFF",
|
392 |
-
"\xFF\x00\x00\xFF\x00\x00\x00\x00", "\xFF\x00\x00\xFF\x00\x00\x00\xFF",
|
393 |
-
"\xFF\x00\x00\xFF\x00\x00\xFF\x00", "\xFF\x00\x00\xFF\x00\x00\xFF\xFF",
|
394 |
-
"\xFF\x00\x00\xFF\x00\xFF\x00\x00", "\xFF\x00\x00\xFF\x00\xFF\x00\xFF",
|
395 |
-
"\xFF\x00\x00\xFF\x00\xFF\xFF\x00", "\xFF\x00\x00\xFF\x00\xFF\xFF\xFF",
|
396 |
-
"\xFF\x00\x00\xFF\xFF\x00\x00\x00", "\xFF\x00\x00\xFF\xFF\x00\x00\xFF",
|
397 |
-
"\xFF\x00\x00\xFF\xFF\x00\xFF\x00", "\xFF\x00\x00\xFF\xFF\x00\xFF\xFF",
|
398 |
-
"\xFF\x00\x00\xFF\xFF\xFF\x00\x00", "\xFF\x00\x00\xFF\xFF\xFF\x00\xFF",
|
399 |
-
"\xFF\x00\x00\xFF\xFF\xFF\xFF\x00", "\xFF\x00\x00\xFF\xFF\xFF\xFF\xFF",
|
400 |
-
"\xFF\x00\xFF\x00\x00\x00\x00\x00", "\xFF\x00\xFF\x00\x00\x00\x00\xFF",
|
401 |
-
"\xFF\x00\xFF\x00\x00\x00\xFF\x00", "\xFF\x00\xFF\x00\x00\x00\xFF\xFF",
|
402 |
-
"\xFF\x00\xFF\x00\x00\xFF\x00\x00", "\xFF\x00\xFF\x00\x00\xFF\x00\xFF",
|
403 |
-
"\xFF\x00\xFF\x00\x00\xFF\xFF\x00", "\xFF\x00\xFF\x00\x00\xFF\xFF\xFF",
|
404 |
-
"\xFF\x00\xFF\x00\xFF\x00\x00\x00", "\xFF\x00\xFF\x00\xFF\x00\x00\xFF",
|
405 |
-
"\xFF\x00\xFF\x00\xFF\x00\xFF\x00", "\xFF\x00\xFF\x00\xFF\x00\xFF\xFF",
|
406 |
-
"\xFF\x00\xFF\x00\xFF\xFF\x00\x00", "\xFF\x00\xFF\x00\xFF\xFF\x00\xFF",
|
407 |
-
"\xFF\x00\xFF\x00\xFF\xFF\xFF\x00", "\xFF\x00\xFF\x00\xFF\xFF\xFF\xFF",
|
408 |
-
"\xFF\x00\xFF\xFF\x00\x00\x00\x00", "\xFF\x00\xFF\xFF\x00\x00\x00\xFF",
|
409 |
-
"\xFF\x00\xFF\xFF\x00\x00\xFF\x00", "\xFF\x00\xFF\xFF\x00\x00\xFF\xFF",
|
410 |
-
"\xFF\x00\xFF\xFF\x00\xFF\x00\x00", "\xFF\x00\xFF\xFF\x00\xFF\x00\xFF",
|
411 |
-
"\xFF\x00\xFF\xFF\x00\xFF\xFF\x00", "\xFF\x00\xFF\xFF\x00\xFF\xFF\xFF",
|
412 |
-
"\xFF\x00\xFF\xFF\xFF\x00\x00\x00", "\xFF\x00\xFF\xFF\xFF\x00\x00\xFF",
|
413 |
-
"\xFF\x00\xFF\xFF\xFF\x00\xFF\x00", "\xFF\x00\xFF\xFF\xFF\x00\xFF\xFF",
|
414 |
-
"\xFF\x00\xFF\xFF\xFF\xFF\x00\x00", "\xFF\x00\xFF\xFF\xFF\xFF\x00\xFF",
|
415 |
-
"\xFF\x00\xFF\xFF\xFF\xFF\xFF\x00", "\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF",
|
416 |
-
"\xFF\xFF\x00\x00\x00\x00\x00\x00", "\xFF\xFF\x00\x00\x00\x00\x00\xFF",
|
417 |
-
"\xFF\xFF\x00\x00\x00\x00\xFF\x00", "\xFF\xFF\x00\x00\x00\x00\xFF\xFF",
|
418 |
-
"\xFF\xFF\x00\x00\x00\xFF\x00\x00", "\xFF\xFF\x00\x00\x00\xFF\x00\xFF",
|
419 |
-
"\xFF\xFF\x00\x00\x00\xFF\xFF\x00", "\xFF\xFF\x00\x00\x00\xFF\xFF\xFF",
|
420 |
-
"\xFF\xFF\x00\x00\xFF\x00\x00\x00", "\xFF\xFF\x00\x00\xFF\x00\x00\xFF",
|
421 |
-
"\xFF\xFF\x00\x00\xFF\x00\xFF\x00", "\xFF\xFF\x00\x00\xFF\x00\xFF\xFF",
|
422 |
-
"\xFF\xFF\x00\x00\xFF\xFF\x00\x00", "\xFF\xFF\x00\x00\xFF\xFF\x00\xFF",
|
423 |
-
"\xFF\xFF\x00\x00\xFF\xFF\xFF\x00", "\xFF\xFF\x00\x00\xFF\xFF\xFF\xFF",
|
424 |
-
"\xFF\xFF\x00\xFF\x00\x00\x00\x00", "\xFF\xFF\x00\xFF\x00\x00\x00\xFF",
|
425 |
-
"\xFF\xFF\x00\xFF\x00\x00\xFF\x00", "\xFF\xFF\x00\xFF\x00\x00\xFF\xFF",
|
426 |
-
"\xFF\xFF\x00\xFF\x00\xFF\x00\x00", "\xFF\xFF\x00\xFF\x00\xFF\x00\xFF",
|
427 |
-
"\xFF\xFF\x00\xFF\x00\xFF\xFF\x00", "\xFF\xFF\x00\xFF\x00\xFF\xFF\xFF",
|
428 |
-
"\xFF\xFF\x00\xFF\xFF\x00\x00\x00", "\xFF\xFF\x00\xFF\xFF\x00\x00\xFF",
|
429 |
-
"\xFF\xFF\x00\xFF\xFF\x00\xFF\x00", "\xFF\xFF\x00\xFF\xFF\x00\xFF\xFF",
|
430 |
-
"\xFF\xFF\x00\xFF\xFF\xFF\x00\x00", "\xFF\xFF\x00\xFF\xFF\xFF\x00\xFF",
|
431 |
-
"\xFF\xFF\x00\xFF\xFF\xFF\xFF\x00", "\xFF\xFF\x00\xFF\xFF\xFF\xFF\xFF",
|
432 |
-
"\xFF\xFF\xFF\x00\x00\x00\x00\x00", "\xFF\xFF\xFF\x00\x00\x00\x00\xFF",
|
433 |
-
"\xFF\xFF\xFF\x00\x00\x00\xFF\x00", "\xFF\xFF\xFF\x00\x00\x00\xFF\xFF",
|
434 |
-
"\xFF\xFF\xFF\x00\x00\xFF\x00\x00", "\xFF\xFF\xFF\x00\x00\xFF\x00\xFF",
|
435 |
-
"\xFF\xFF\xFF\x00\x00\xFF\xFF\x00", "\xFF\xFF\xFF\x00\x00\xFF\xFF\xFF",
|
436 |
-
"\xFF\xFF\xFF\x00\xFF\x00\x00\x00", "\xFF\xFF\xFF\x00\xFF\x00\x00\xFF",
|
437 |
-
"\xFF\xFF\xFF\x00\xFF\x00\xFF\x00", "\xFF\xFF\xFF\x00\xFF\x00\xFF\xFF",
|
438 |
-
"\xFF\xFF\xFF\x00\xFF\xFF\x00\x00", "\xFF\xFF\xFF\x00\xFF\xFF\x00\xFF",
|
439 |
-
"\xFF\xFF\xFF\x00\xFF\xFF\xFF\x00", "\xFF\xFF\xFF\x00\xFF\xFF\xFF\xFF",
|
440 |
-
"\xFF\xFF\xFF\xFF\x00\x00\x00\x00", "\xFF\xFF\xFF\xFF\x00\x00\x00\xFF",
|
441 |
-
"\xFF\xFF\xFF\xFF\x00\x00\xFF\x00", "\xFF\xFF\xFF\xFF\x00\x00\xFF\xFF",
|
442 |
-
"\xFF\xFF\xFF\xFF\x00\xFF\x00\x00", "\xFF\xFF\xFF\xFF\x00\xFF\x00\xFF",
|
443 |
-
"\xFF\xFF\xFF\xFF\x00\xFF\xFF\x00", "\xFF\xFF\xFF\xFF\x00\xFF\xFF\xFF",
|
444 |
-
"\xFF\xFF\xFF\xFF\xFF\x00\x00\x00", "\xFF\xFF\xFF\xFF\xFF\x00\x00\xFF",
|
445 |
-
"\xFF\xFF\xFF\xFF\xFF\x00\xFF\x00", "\xFF\xFF\xFF\xFF\xFF\x00\xFF\xFF",
|
446 |
-
"\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00", "\xFF\xFF\xFF\xFF\xFF\xFF\x00\xFF",
|
447 |
-
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00", "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
|
448 |
-
);
|
449 |
-
|
450 |
-
/**
|
451 |
-
* IP mapping helper table.
|
452 |
-
*
|
453 |
-
* Indexing this table with each source byte performs the initial bit permutation.
|
454 |
-
*
|
455 |
-
* @var Array
|
456 |
-
* @access private
|
457 |
-
*/
|
458 |
-
var $ipmap = array(
|
459 |
-
0x00, 0x10, 0x01, 0x11, 0x20, 0x30, 0x21, 0x31,
|
460 |
-
0x02, 0x12, 0x03, 0x13, 0x22, 0x32, 0x23, 0x33,
|
461 |
-
0x40, 0x50, 0x41, 0x51, 0x60, 0x70, 0x61, 0x71,
|
462 |
-
0x42, 0x52, 0x43, 0x53, 0x62, 0x72, 0x63, 0x73,
|
463 |
-
0x04, 0x14, 0x05, 0x15, 0x24, 0x34, 0x25, 0x35,
|
464 |
-
0x06, 0x16, 0x07, 0x17, 0x26, 0x36, 0x27, 0x37,
|
465 |
-
0x44, 0x54, 0x45, 0x55, 0x64, 0x74, 0x65, 0x75,
|
466 |
-
0x46, 0x56, 0x47, 0x57, 0x66, 0x76, 0x67, 0x77,
|
467 |
-
0x80, 0x90, 0x81, 0x91, 0xA0, 0xB0, 0xA1, 0xB1,
|
468 |
-
0x82, 0x92, 0x83, 0x93, 0xA2, 0xB2, 0xA3, 0xB3,
|
469 |
-
0xC0, 0xD0, 0xC1, 0xD1, 0xE0, 0xF0, 0xE1, 0xF1,
|
470 |
-
0xC2, 0xD2, 0xC3, 0xD3, 0xE2, 0xF2, 0xE3, 0xF3,
|
471 |
-
0x84, 0x94, 0x85, 0x95, 0xA4, 0xB4, 0xA5, 0xB5,
|
472 |
-
0x86, 0x96, 0x87, 0x97, 0xA6, 0xB6, 0xA7, 0xB7,
|
473 |
-
0xC4, 0xD4, 0xC5, 0xD5, 0xE4, 0xF4, 0xE5, 0xF5,
|
474 |
-
0xC6, 0xD6, 0xC7, 0xD7, 0xE6, 0xF6, 0xE7, 0xF7,
|
475 |
-
0x08, 0x18, 0x09, 0x19, 0x28, 0x38, 0x29, 0x39,
|
476 |
-
0x0A, 0x1A, 0x0B, 0x1B, 0x2A, 0x3A, 0x2B, 0x3B,
|
477 |
-
0x48, 0x58, 0x49, 0x59, 0x68, 0x78, 0x69, 0x79,
|
478 |
-
0x4A, 0x5A, 0x4B, 0x5B, 0x6A, 0x7A, 0x6B, 0x7B,
|
479 |
-
0x0C, 0x1C, 0x0D, 0x1D, 0x2C, 0x3C, 0x2D, 0x3D,
|
480 |
-
0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F,
|
481 |
-
0x4C, 0x5C, 0x4D, 0x5D, 0x6C, 0x7C, 0x6D, 0x7D,
|
482 |
-
0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F,
|
483 |
-
0x88, 0x98, 0x89, 0x99, 0xA8, 0xB8, 0xA9, 0xB9,
|
484 |
-
0x8A, 0x9A, 0x8B, 0x9B, 0xAA, 0xBA, 0xAB, 0xBB,
|
485 |
-
0xC8, 0xD8, 0xC9, 0xD9, 0xE8, 0xF8, 0xE9, 0xF9,
|
486 |
-
0xCA, 0xDA, 0xCB, 0xDB, 0xEA, 0xFA, 0xEB, 0xFB,
|
487 |
-
0x8C, 0x9C, 0x8D, 0x9D, 0xAC, 0xBC, 0xAD, 0xBD,
|
488 |
-
0x8E, 0x9E, 0x8F, 0x9F, 0xAE, 0xBE, 0xAF, 0xBF,
|
489 |
-
0xCC, 0xDC, 0xCD, 0xDD, 0xEC, 0xFC, 0xED, 0xFD,
|
490 |
-
0xCE, 0xDE, 0xCF, 0xDF, 0xEE, 0xFE, 0xEF, 0xFF
|
491 |
-
);
|
492 |
-
|
493 |
-
/**
|
494 |
-
* Inverse IP mapping helper table.
|
495 |
-
* Indexing this table with a byte value reverses the bit order.
|
496 |
-
*
|
497 |
-
* @var Array
|
498 |
-
* @access private
|
499 |
-
*/
|
500 |
-
var $invipmap = array(
|
501 |
-
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
|
502 |
-
0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
|
503 |
-
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
|
504 |
-
0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
|
505 |
-
0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
|
506 |
-
0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
|
507 |
-
0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
|
508 |
-
0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
|
509 |
-
0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
|
510 |
-
0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
|
511 |
-
0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
|
512 |
-
0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
|
513 |
-
0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
|
514 |
-
0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
|
515 |
-
0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
|
516 |
-
0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
|
517 |
-
0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
|
518 |
-
0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
|
519 |
-
0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
|
520 |
-
0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
|
521 |
-
0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
|
522 |
-
0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
|
523 |
-
0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
|
524 |
-
0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
|
525 |
-
0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
|
526 |
-
0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
|
527 |
-
0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
|
528 |
-
0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
|
529 |
-
0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
|
530 |
-
0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
|
531 |
-
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
|
532 |
-
0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
|
533 |
-
);
|
534 |
-
|
535 |
-
/**
|
536 |
-
* Pre-permuted S-box1
|
537 |
-
*
|
538 |
-
* Each box ($sbox1-$sbox8) has been vectorized, then each value pre-permuted using the
|
539 |
-
* P table: concatenation can then be replaced by exclusive ORs.
|
540 |
-
*
|
541 |
-
* @var Array
|
542 |
-
* @access private
|
543 |
-
*/
|
544 |
-
var $sbox1 = array(
|
545 |
-
0x00808200, 0x00000000, 0x00008000, 0x00808202,
|
546 |
-
0x00808002, 0x00008202, 0x00000002, 0x00008000,
|
547 |
-
0x00000200, 0x00808200, 0x00808202, 0x00000200,
|
548 |
-
0x00800202, 0x00808002, 0x00800000, 0x00000002,
|
549 |
-
0x00000202, 0x00800200, 0x00800200, 0x00008200,
|
550 |
-
0x00008200, 0x00808000, 0x00808000, 0x00800202,
|
551 |
-
0x00008002, 0x00800002, 0x00800002, 0x00008002,
|
552 |
-
0x00000000, 0x00000202, 0x00008202, 0x00800000,
|
553 |
-
0x00008000, 0x00808202, 0x00000002, 0x00808000,
|
554 |
-
0x00808200, 0x00800000, 0x00800000, 0x00000200,
|
555 |
-
0x00808002, 0x00008000, 0x00008200, 0x00800002,
|
556 |
-
0x00000200, 0x00000002, 0x00800202, 0x00008202,
|
557 |
-
0x00808202, 0x00008002, 0x00808000, 0x00800202,
|
558 |
-
0x00800002, 0x00000202, 0x00008202, 0x00808200,
|
559 |
-
0x00000202, 0x00800200, 0x00800200, 0x00000000,
|
560 |
-
0x00008002, 0x00008200, 0x00000000, 0x00808002
|
561 |
-
);
|
562 |
-
|
563 |
-
/**
|
564 |
-
* Pre-permuted S-box2
|
565 |
-
*
|
566 |
-
* @var Array
|
567 |
-
* @access private
|
568 |
-
*/
|
569 |
-
var $sbox2 = array(
|
570 |
-
0x40084010, 0x40004000, 0x00004000, 0x00084010,
|
571 |
-
0x00080000, 0x00000010, 0x40080010, 0x40004010,
|
572 |
-
0x40000010, 0x40084010, 0x40084000, 0x40000000,
|
573 |
-
0x40004000, 0x00080000, 0x00000010, 0x40080010,
|
574 |
-
0x00084000, 0x00080010, 0x40004010, 0x00000000,
|
575 |
-
0x40000000, 0x00004000, 0x00084010, 0x40080000,
|
576 |
-
0x00080010, 0x40000010, 0x00000000, 0x00084000,
|
577 |
-
0x00004010, 0x40084000, 0x40080000, 0x00004010,
|
578 |
-
0x00000000, 0x00084010, 0x40080010, 0x00080000,
|
579 |
-
0x40004010, 0x40080000, 0x40084000, 0x00004000,
|
580 |
-
0x40080000, 0x40004000, 0x00000010, 0x40084010,
|
581 |
-
0x00084010, 0x00000010, 0x00004000, 0x40000000,
|
582 |
-
0x00004010, 0x40084000, 0x00080000, 0x40000010,
|
583 |
-
0x00080010, 0x40004010, 0x40000010, 0x00080010,
|
584 |
-
0x00084000, 0x00000000, 0x40004000, 0x00004010,
|
585 |
-
0x40000000, 0x40080010, 0x40084010, 0x00084000
|
586 |
-
);
|
587 |
-
|
588 |
-
/**
|
589 |
-
* Pre-permuted S-box3
|
590 |
-
*
|
591 |
-
* @var Array
|
592 |
-
* @access private
|
593 |
-
*/
|
594 |
-
var $sbox3 = array(
|
595 |
-
0x00000104, 0x04010100, 0x00000000, 0x04010004,
|
596 |
-
0x04000100, 0x00000000, 0x00010104, 0x04000100,
|
597 |
-
0x00010004, 0x04000004, 0x04000004, 0x00010000,
|
598 |
-
0x04010104, 0x00010004, 0x04010000, 0x00000104,
|
599 |
-
0x04000000, 0x00000004, 0x04010100, 0x00000100,
|
600 |
-
0x00010100, 0x04010000, 0x04010004, 0x00010104,
|
601 |
-
0x04000104, 0x00010100, 0x00010000, 0x04000104,
|
602 |
-
0x00000004, 0x04010104, 0x00000100, 0x04000000,
|
603 |
-
0x04010100, 0x04000000, 0x00010004, 0x00000104,
|
604 |
-
0x00010000, 0x04010100, 0x04000100, 0x00000000,
|
605 |
-
0x00000100, 0x00010004, 0x04010104, 0x04000100,
|
606 |
-
0x04000004, 0x00000100, 0x00000000, 0x04010004,
|
607 |
-
0x04000104, 0x00010000, 0x04000000, 0x04010104,
|
608 |
-
0x00000004, 0x00010104, 0x00010100, 0x04000004,
|
609 |
-
0x04010000, 0x04000104, 0x00000104, 0x04010000,
|
610 |
-
0x00010104, 0x00000004, 0x04010004, 0x00010100
|
611 |
-
);
|
612 |
-
|
613 |
-
/**
|
614 |
-
* Pre-permuted S-box4
|
615 |
-
*
|
616 |
-
* @var Array
|
617 |
-
* @access private
|
618 |
-
*/
|
619 |
-
var $sbox4 = array(
|
620 |
-
0x80401000, 0x80001040, 0x80001040, 0x00000040,
|
621 |
-
0x00401040, 0x80400040, 0x80400000, 0x80001000,
|
622 |
-
0x00000000, 0x00401000, 0x00401000, 0x80401040,
|
623 |
-
0x80000040, 0x00000000, 0x00400040, 0x80400000,
|
624 |
-
0x80000000, 0x00001000, 0x00400000, 0x80401000,
|
625 |
-
0x00000040, 0x00400000, 0x80001000, 0x00001040,
|
626 |
-
0x80400040, 0x80000000, 0x00001040, 0x00400040,
|
627 |
-
0x00001000, 0x00401040, 0x80401040, 0x80000040,
|
628 |
-
0x00400040, 0x80400000, 0x00401000, 0x80401040,
|
629 |
-
0x80000040, 0x00000000, 0x00000000, 0x00401000,
|
630 |
-
0x00001040, 0x00400040, 0x80400040, 0x80000000,
|
631 |
-
0x80401000, 0x80001040, 0x80001040, 0x00000040,
|
632 |
-
0x80401040, 0x80000040, 0x80000000, 0x00001000,
|
633 |
-
0x80400000, 0x80001000, 0x00401040, 0x80400040,
|
634 |
-
0x80001000, 0x00001040, 0x00400000, 0x80401000,
|
635 |
-
0x00000040, 0x00400000, 0x00001000, 0x00401040
|
636 |
-
);
|
637 |
-
|
638 |
-
/**
|
639 |
-
* Pre-permuted S-box5
|
640 |
-
*
|
641 |
-
* @var Array
|
642 |
-
* @access private
|
643 |
-
*/
|
644 |
-
var $sbox5 = array(
|
645 |
-
0x00000080, 0x01040080, 0x01040000, 0x21000080,
|
646 |
-
0x00040000
|
647 |
-
0x20040080, 0x00040000, 0x01000080, 0x20040080,
|
648 |
-
0x21000080, 0x21040000, 0x00040080, 0x20000000,
|
649 |
-
0x01000000, 0x20040000, 0x20040000, 0x00000000,
|
650 |
-
0x20000080, 0x21040080, 0x21040080, 0x01000080,
|
651 |
-
0x21040000, 0x20000080, 0x00000000, 0x21000000,
|
652 |
-
0x01040080, 0x01000000, 0x21000000, 0x00040080,
|
653 |
-
0x00040000, 0x21000080, 0x00000080, 0x01000000,
|
654 |
-
0x20000000, 0x01040000, 0x21000080, 0x20040080,
|
655 |
-
0x01000080, 0x20000000, 0x21040000, 0x01040080,
|
656 |
-
0x20040080, 0x00000080, 0x01000000, 0x21040000,
|
657 |
-
0x21040080, 0x00040080, 0x21000000, 0x21040080,
|
658 |
-
0x01040000, 0x00000000, 0x20040000, 0x21000000,
|
659 |
-
0x00040080, 0x01000080, 0x20000080, 0x00040000,
|
660 |
-
0x00000000, 0x20040000, 0x01040080, 0x20000080
|
661 |
-
);
|
662 |
-
|
663 |
-
/**
|
664 |
-
* Pre-permuted S-box6
|
665 |
-
*
|
666 |
-
* @var Array
|
667 |
-
* @access private
|
668 |
-
*/
|
669 |
-
var $sbox6 = array(
|
670 |
-
0x10000008, 0x10200000, 0x00002000, 0x10202008,
|
671 |
-
0x10200000, 0x00000008, 0x10202008, 0x00200000,
|
672 |
-
0x10002000, 0x00202008, 0x00200000, 0x10000008,
|
673 |
-
0x00200008, 0x10002000, 0x10000000, 0x00002008,
|
674 |
-
0x00000000, 0x00200008, 0x10002008, 0x00002000,
|
675 |
-
0x00202000, 0x10002008, 0x00000008, 0x10200008,
|
676 |
-
0x10200008, 0x00000000, 0x00202008, 0x10202000,
|
677 |
-
0x00002008, 0x00202000, 0x10202000, 0x10000000,
|
678 |
-
0x10002000, 0x00000008, 0x10200008, 0x00202000,
|
679 |
-
0x10202008, 0x00200000, 0x00002008, 0x10000008,
|
680 |
-
0x00200000, 0x10002000, 0x10000000, 0x00002008,
|
681 |
-
0x10000008, 0x10202008, 0x00202000, 0x10200000,
|
682 |
-
0x00202008, 0x10202000, 0x00000000, 0x10200008,
|
683 |
-
0x00000008, 0x00002000, 0x10200000, 0x00202008,
|
684 |
-
0x00002000, 0x00200008, 0x10002008, 0x00000000,
|
685 |
-
0x10202000, 0x10000000, 0x00200008, 0x10002008
|
686 |
-
);
|
687 |
-
|
688 |
-
/**
|
689 |
-
* Pre-permuted S-box7
|
690 |
-
*
|
691 |
-
* @var Array
|
692 |
-
* @access private
|
693 |
-
*/
|
694 |
-
var $sbox7 = array(
|
695 |
-
0x00100000, 0x02100001, 0x02000401, 0x00000000,
|
696 |
-
0x00000400, 0x02000401, 0x00100401, 0x02100400,
|
697 |
-
0x02100401, 0x00100000, 0x00000000, 0x02000001,
|
698 |
-
0x00000001, 0x02000000, 0x02100001, 0x00000401,
|
699 |
-
0x02000400, 0x00100401, 0x00100001, 0x02000400,
|
700 |
-
0x02000001, 0x02100000, 0x02100400, 0x00100001,
|
701 |
-
0x02100000, 0x00000400, 0x00000401, 0x02100401,
|
702 |
-
0x00100400, 0x00000001, 0x02000000, 0x00100400,
|
703 |
-
0x02000000, 0x00100400, 0x00100000, 0x02000401,
|
704 |
-
0x02000401, 0x02100001, 0x02100001, 0x00000001,
|
705 |
-
0x00100001, 0x02000000, 0x02000400, 0x00100000,
|
706 |
-
0x02100400, 0x00000401, 0x00100401, 0x02100400,
|
707 |
-
0x00000401, 0x02000001, 0x02100401, 0x02100000,
|
708 |
-
0x00100400, 0x00000000, 0x00000001, 0x02100401,
|
709 |
-
0x00000000, 0x00100401, 0x02100000, 0x00000400,
|
710 |
-
0x02000001, 0x02000400, 0x00000400, 0x00100001
|
711 |
-
);
|
712 |
-
|
713 |
-
/**
|
714 |
-
* Pre-permuted S-box8
|
715 |
-
*
|
716 |
-
* @var Array
|
717 |
-
* @access private
|
718 |
-
*/
|
719 |
-
var $sbox8 = array(
|
720 |
-
0x08000820, 0x00000800, 0x00020000, 0x08020820,
|
721 |
-
0x08000000, 0x08000820, 0x00000020, 0x08000000,
|
722 |
-
0x00020020, 0x08020000, 0x08020820, 0x00020800,
|
723 |
-
0x08020800, 0x00020820, 0x00000800, 0x00000020,
|
724 |
-
0x08020000, 0x08000020, 0x08000800, 0x00000820,
|
725 |
-
0x00020800, 0x00020020, 0x08020020, 0x08020800,
|
726 |
-
0x00000820, 0x00000000, 0x00000000, 0x08020020,
|
727 |
-
0x08000020, 0x08000800, 0x00020820, 0x00020000,
|
728 |
-
0x00020820, 0x00020000, 0x08020800, 0x00000800,
|
729 |
-
0x00000020, 0x08020020, 0x00000800, 0x00020820,
|
730 |
-
0x08000800, 0x00000020, 0x08000020, 0x08020000,
|
731 |
-
0x08020020, 0x08000000, 0x00020000, 0x08000820,
|
732 |
-
0x00000000, 0x08020820, 0x00020020, 0x08000020,
|
733 |
-
0x08020000, 0x08000800, 0x08000820, 0x00000000,
|
734 |
-
0x08020820, 0x00020800, 0x00020800, 0x00000820,
|
735 |
-
0x00000820, 0x00020020, 0x08000000, 0x08020800
|
736 |
-
);
|
737 |
-
|
738 |
-
/**
|
739 |
-
* Default Constructor.
|
740 |
-
*
|
741 |
-
* Determines whether or not the mcrypt extension should be used. $mode should only, at present, be
|
742 |
-
* CRYPT_DES_MODE_ECB or CRYPT_DES_MODE_CBC. If not explictly set, CRYPT_DES_MODE_CBC will be used.
|
743 |
-
*
|
744 |
-
* @param optional Integer $mode
|
745 |
-
* @return Crypt_DES
|
746 |
-
* @access public
|
747 |
-
*/
|
748 |
-
function __construct($mode = CRYPT_DES_MODE_CBC)
|
749 |
-
{
|
750 |
-
if ( !defined('CRYPT_DES_MODE') ) {
|
751 |
-
switch (true) {
|
752 |
-
case extension_loaded('mcrypt') && in_array('des', mcrypt_list_algorithms()):
|
753 |
-
define('CRYPT_DES_MODE', CRYPT_DES_MODE_MCRYPT);
|
754 |
-
break;
|
755 |
-
default:
|
756 |
-
define('CRYPT_DES_MODE', CRYPT_DES_MODE_INTERNAL);
|
757 |
-
}
|
758 |
-
}
|
759 |
-
|
760 |
-
switch ( CRYPT_DES_MODE ) {
|
761 |
-
case CRYPT_DES_MODE_MCRYPT:
|
762 |
-
switch ($mode) {
|
763 |
-
case CRYPT_DES_MODE_ECB:
|
764 |
-
$this->paddable = true;
|
765 |
-
$this->mode = MCRYPT_MODE_ECB;
|
766 |
-
break;
|
767 |
-
case CRYPT_DES_MODE_CTR:
|
768 |
-
$this->mode = 'ctr';
|
769 |
-
//$this->mode = in_array('ctr', mcrypt_list_modes()) ? 'ctr' : CRYPT_DES_MODE_CTR;
|
770 |
-
break;
|
771 |
-
case CRYPT_DES_MODE_CFB:
|
772 |
-
$this->mode = 'ncfb';
|
773 |
-
$this->ecb = mcrypt_module_open(MCRYPT_DES, '', MCRYPT_MODE_ECB, '');
|
774 |
-
break;
|
775 |
-
case CRYPT_DES_MODE_OFB:
|
776 |
-
$this->mode = MCRYPT_MODE_NOFB;
|
777 |
-
break;
|
778 |
-
case CRYPT_DES_MODE_CBC:
|
779 |
-
default:
|
780 |
-
$this->paddable = true;
|
781 |
-
$this->mode = MCRYPT_MODE_CBC;
|
782 |
-
}
|
783 |
-
$this->enmcrypt = mcrypt_module_open(MCRYPT_DES, '', $this->mode, '');
|
784 |
-
$this->demcrypt = mcrypt_module_open(MCRYPT_DES, '', $this->mode, '');
|
785 |
-
|
786 |
-
break;
|
787 |
-
default:
|
788 |
-
switch ($mode) {
|
789 |
-
case CRYPT_DES_MODE_ECB:
|
790 |
-
case CRYPT_DES_MODE_CBC:
|
791 |
-
$this->paddable = true;
|
792 |
-
$this->mode = $mode;
|
793 |
-
break;
|
794 |
-
case CRYPT_DES_MODE_CTR:
|
795 |
-
case CRYPT_DES_MODE_CFB:
|
796 |
-
case CRYPT_DES_MODE_OFB:
|
797 |
-
$this->mode = $mode;
|
798 |
-
break;
|
799 |
-
default:
|
800 |
-
$this->paddable = true;
|
801 |
-
$this->mode = CRYPT_DES_MODE_CBC;
|
802 |
-
}
|
803 |
-
if (function_exists('create_function') && is_callable('create_function')) {
|
804 |
-
$this->inline_crypt_setup();
|
805 |
-
$this->use_inline_crypt = true;
|
806 |
-
}
|
807 |
-
}
|
808 |
-
}
|
809 |
-
|
810 |
-
/**
|
811 |
-
* Sets the key.
|
812 |
-
*
|
813 |
-
* Keys can be of any length. DES, itself, uses 64-bit keys (eg. strlen($key) == 8), however, we
|
814 |
-
* only use the first eight, if $key has more then eight characters in it, and pad $key with the
|
815 |
-
* null byte if it is less then eight characters long.
|
816 |
-
*
|
817 |
-
* DES also requires that every eighth bit be a parity bit, however, we'll ignore that.
|
818 |
-
*
|
819 |
-
* If the key is not explicitly set, it'll be assumed to be all zero's.
|
820 |
-
*
|
821 |
-
* @access public
|
822 |
-
* @param String $key
|
823 |
-
*/
|
824 |
-
function setKey($key)
|
825 |
-
{
|
826 |
-
$this->keys = ( CRYPT_DES_MODE == CRYPT_DES_MODE_MCRYPT ) ? str_pad(substr($key, 0, 8), 8, chr(0)) : $this->_prepareKey($key);
|
827 |
-
$this->enchanged = true;
|
828 |
-
$this->dechanged = true;
|
829 |
-
}
|
830 |
-
|
831 |
-
/**
|
832 |
-
* Sets the password.
|
833 |
-
*
|
834 |
-
* Depending on what $method is set to, setPassword()'s (optional) parameters are as follows:
|
835 |
-
* {@link http://en.wikipedia.org/wiki/PBKDF2 pbkdf2}:
|
836 |
-
* $hash, $salt, $count
|
837 |
-
*
|
838 |
-
* @param String $password
|
839 |
-
* @param optional String $method
|
840 |
-
* @access public
|
841 |
-
*/
|
842 |
-
function setPassword($password, $method = 'pbkdf2')
|
843 |
-
{
|
844 |
-
$key = '';
|
845 |
-
|
846 |
-
switch ($method) {
|
847 |
-
default: // 'pbkdf2'
|
848 |
-
list(, , $hash, $salt, $count) = func_get_args();
|
849 |
-
if (!isset($hash)) {
|
850 |
-
$hash = 'sha1';
|
851 |
-
}
|
852 |
-
// WPA and WPA2 use the SSID as the salt
|
853 |
-
if (!isset($salt)) {
|
854 |
-
$salt = 'phpseclib/salt';
|
855 |
-
}
|
856 |
-
// RFC2898#section-4.2 uses 1,000 iterations by default
|
857 |
-
// WPA and WPA2 use 4,096.
|
858 |
-
if (!isset($count)) {
|
859 |
-
$count = 1000;
|
860 |
-
}
|
861 |
-
|
862 |
-
if (!class_exists('Crypt_Hash')) {
|
863 |
-
require_once('Crypt/Hash.php');
|
864 |
-
}
|
865 |
-
|
866 |
-
$i = 1;
|
867 |
-
while (strlen($key) < 8) { // $dkLen == 8
|
868 |
-
//$dk.= $this->_pbkdf($password, $salt, $count, $i++);
|
869 |
-
$hmac = new Crypt_Hash();
|
870 |
-
$hmac->setHash($hash);
|
871 |
-
$hmac->setKey($password);
|
872 |
-
$f = $u = $hmac->hash($salt . pack('N', $i++));
|
873 |
-
for ($j = 2; $j <= $count; $j++) {
|
874 |
-
$u = $hmac->hash($u);
|
875 |
-
$f^= $u;
|
876 |
-
}
|
877 |
-
$key.= $f;
|
878 |
-
}
|
879 |
-
}
|
880 |
-
|
881 |
-
$this->setKey($key);
|
882 |
-
}
|
883 |
-
|
884 |
-
/**
|
885 |
-
* Sets the initialization vector. (optional)
|
886 |
-
*
|
887 |
-
* SetIV is not required when CRYPT_DES_MODE_ECB is being used. If not explictly set, it'll be assumed
|
888 |
-
* to be all zero's.
|
889 |
-
*
|
890 |
-
* @access public
|
891 |
-
* @param String $iv
|
892 |
-
*/
|
893 |
-
function setIV($iv)
|
894 |
-
{
|
895 |
-
$this->encryptIV = $this->decryptIV = $this->iv = str_pad(substr($iv, 0, 8), 8, chr(0));
|
896 |
-
$this->enchanged = true;
|
897 |
-
$this->dechanged = true;
|
898 |
-
}
|
899 |
-
|
900 |
-
/**
|
901 |
-
* Generate CTR XOR encryption key
|
902 |
-
*
|
903 |
-
* Encrypt the output of this and XOR it against the ciphertext / plaintext to get the
|
904 |
-
* plaintext / ciphertext in CTR mode.
|
905 |
-
*
|
906 |
-
* @see Crypt_DES::decrypt()
|
907 |
-
* @see Crypt_DES::encrypt()
|
908 |
-
* @access public
|
909 |
-
* @param String $iv
|
910 |
-
*/
|
911 |
-
function _generate_xor(&$iv)
|
912 |
-
{
|
913 |
-
$xor = $iv;
|
914 |
-
for ($j = 4; $j <= 8; $j+=4) {
|
915 |
-
$temp = substr($iv, -$j, 4);
|
916 |
-
switch ($temp) {
|
917 |
-
case "\xFF\xFF\xFF\xFF":
|
918 |
-
$iv = substr_replace($iv, "\x00\x00\x00\x00", -$j, 4);
|
919 |
-
break;
|
920 |
-
case "\x7F\xFF\xFF\xFF":
|
921 |
-
$iv = substr_replace($iv, "\x80\x00\x00\x00", -$j, 4);
|
922 |
-
break 2;
|
923 |
-
default:
|
924 |
-
extract(unpack('Ncount', $temp));
|
925 |
-
$iv = substr_replace($iv, pack('N', $count + 1), -$j, 4);
|
926 |
-
break 2;
|
927 |
-
}
|
928 |
-
}
|
929 |
-
|
930 |
-
return $xor;
|
931 |
-
}
|
932 |
-
|
933 |
-
/**
|
934 |
-
* Encrypts a message.
|
935 |
-
*
|
936 |
-
* $plaintext will be padded with up to 8 additional bytes. Other DES implementations may or may not pad in the
|
937 |
-
* same manner. Other common approaches to padding and the reasons why it's necessary are discussed in the following
|
938 |
-
* URL:
|
939 |
-
*
|
940 |
-
* {@link http://www.di-mgt.com.au/cryptopad.html http://www.di-mgt.com.au/cryptopad.html}
|
941 |
-
*
|
942 |
-
* An alternative to padding is to, separately, send the length of the file. This is what SSH, in fact, does.
|
943 |
-
* strlen($plaintext) will still need to be a multiple of 8, however, arbitrary values can be added to make it that
|
944 |
-
* length.
|
945 |
-
*
|
946 |
-
* @see Crypt_DES::decrypt()
|
947 |
-
* @access public
|
948 |
-
* @param String $plaintext
|
949 |
-
*/
|
950 |
-
function encrypt($plaintext)
|
951 |
-
{
|
952 |
-
if ($this->paddable) {
|
953 |
-
$plaintext = $this->_pad($plaintext);
|
954 |
-
}
|
955 |
-
|
956 |
-
if ( CRYPT_DES_MODE == CRYPT_DES_MODE_MCRYPT ) {
|
957 |
-
if ($this->enchanged) {
|
958 |
-
mcrypt_generic_init($this->enmcrypt, $this->keys, $this->encryptIV);
|
959 |
-
if ($this->mode == 'ncfb') {
|
960 |
-
mcrypt_generic_init($this->ecb, $this->keys, "\0\0\0\0\0\0\0\0");
|
961 |
-
}
|
962 |
-
$this->enchanged = false;
|
963 |
-
}
|
964 |
-
|
965 |
-
if ($this->mode != 'ncfb' || !$this->continuousBuffer) {
|
966 |
-
$ciphertext = mcrypt_generic($this->enmcrypt, $plaintext);
|
967 |
-
} else {
|
968 |
-
$iv = &$this->encryptIV;
|
969 |
-
$pos = &$this->enbuffer['pos'];
|
970 |
-
$len = strlen($plaintext);
|
971 |
-
$ciphertext = '';
|
972 |
-
$i = 0;
|
973 |
-
if ($pos) {
|
974 |
-
$orig_pos = $pos;
|
975 |
-
$max = 8 - $pos;
|
976 |
-
if ($len >= $max) {
|
977 |
-
$i = $max;
|
978 |
-
$len-= $max;
|
979 |
-
$pos = 0;
|
980 |
-
} else {
|
981 |
-
$i = $len;
|
982 |
-
$pos+= $len;
|
983 |
-
$len = 0;
|
984 |
-
}
|
985 |
-
$ciphertext = substr($iv, $orig_pos) ^ $plaintext;
|
986 |
-
$iv = substr_replace($iv, $ciphertext, $orig_pos, $i);
|
987 |
-
$this->enbuffer['enmcrypt_init'] = true;
|
988 |
-
}
|
989 |
-
if ($len >= 8) {
|
990 |
-
if ($this->enbuffer['enmcrypt_init'] === false || $len > 600) {
|
991 |
-
if ($this->enbuffer['enmcrypt_init'] === true) {
|
992 |
-
mcrypt_generic_init($this->enmcrypt, $this->keys, $iv);
|
993 |
-
$this->enbuffer['enmcrypt_init'] = false;
|
994 |
-
}
|
995 |
-
$ciphertext.= mcrypt_generic($this->enmcrypt, substr($plaintext, $i, $len - $len % 8));
|
996 |
-
$iv = substr($ciphertext, -8);
|
997 |
-
$len%= 8;
|
998 |
-
} else {
|
999 |
-
while ($len >= 8) {
|
1000 |
-
$iv = mcrypt_generic($this->ecb, $iv) ^ substr($plaintext, $i, 8);
|
1001 |
-
$ciphertext.= $iv;
|
1002 |
-
$len-= 8;
|
1003 |
-
$i+= 8;
|
1004 |
-
}
|
1005 |
-
}
|
1006 |
-
}
|
1007 |
-
if ($len) {
|
1008 |
-
$iv = mcrypt_generic($this->ecb, $iv);
|
1009 |
-
$block = $iv ^ substr($plaintext, -$len);
|
1010 |
-
$iv = substr_replace($iv, $block, 0, $len);
|
1011 |
-
$ciphertext.= $block;
|
1012 |
-
$pos = $len;
|
1013 |
-
}
|
1014 |
-
return $ciphertext;
|
1015 |
-
}
|
1016 |
-
|
1017 |
-
if (!$this->continuousBuffer) {
|
1018 |
-
mcrypt_generic_init($this->enmcrypt, $this->keys, $this->encryptIV);
|
1019 |
-
}
|
1020 |
-
|
1021 |
-
return $ciphertext;
|
1022 |
-
}
|
1023 |
-
|
1024 |
-
if (!is_array($this->keys)) {
|
1025 |
-
$this->keys = $this->_prepareKey("\0\0\0\0\0\0\0\0");
|
1026 |
-
}
|
1027 |
-
|
1028 |
-
if ($this->use_inline_crypt) {
|
1029 |
-
$inline = $this->inline_crypt;
|
1030 |
-
return $inline('encrypt', $this, $plaintext);
|
1031 |
-
}
|
1032 |
-
|
1033 |
-
$buffer = &$this->enbuffer;
|
1034 |
-
$continuousBuffer = $this->continuousBuffer;
|
1035 |
-
$ciphertext = '';
|
1036 |
-
switch ($this->mode) {
|
1037 |
-
case CRYPT_DES_MODE_ECB:
|
1038 |
-
for ($i = 0; $i < strlen($plaintext); $i+=8) {
|
1039 |
-
$ciphertext.= $this->_processBlock(substr($plaintext, $i, 8), CRYPT_DES_ENCRYPT);
|
1040 |
-
}
|
1041 |
-
break;
|
1042 |
-
case CRYPT_DES_MODE_CBC:
|
1043 |
-
$xor = $this->encryptIV;
|
1044 |
-
for ($i = 0; $i < strlen($plaintext); $i+=8) {
|
1045 |
-
$block = substr($plaintext, $i, 8);
|
1046 |
-
$block = $this->_processBlock($block ^ $xor, CRYPT_DES_ENCRYPT);
|
1047 |
-
$xor = $block;
|
1048 |
-
$ciphertext.= $block;
|
1049 |
-
}
|
1050 |
-
if ($this->continuousBuffer) {
|
1051 |
-
$this->encryptIV = $xor;
|
1052 |
-
}
|
1053 |
-
break;
|
1054 |
-
case CRYPT_DES_MODE_CTR:
|
1055 |
-
$xor = $this->encryptIV;
|
1056 |
-
if (strlen($buffer['encrypted'])) {
|
1057 |
-
for ($i = 0; $i < strlen($plaintext); $i+=8) {
|
1058 |
-
$block = substr($plaintext, $i, 8);
|
1059 |
-
if (strlen($block) > strlen($buffer['encrypted'])) {
|
1060 |
-
$buffer['encrypted'].= $this->_processBlock($this->_generate_xor($xor), CRYPT_DES_ENCRYPT);
|
1061 |
-
}
|
1062 |
-
$key = $this->_string_shift($buffer['encrypted']);
|
1063 |
-
$ciphertext.= $block ^ $key;
|
1064 |
-
}
|
1065 |
-
} else {
|
1066 |
-
for ($i = 0; $i < strlen($plaintext); $i+=8) {
|
1067 |
-
$block = substr($plaintext, $i, 8);
|
1068 |
-
$key = $this->_processBlock($this->_generate_xor($xor), CRYPT_DES_ENCRYPT);
|
1069 |
-
$ciphertext.= $block ^ $key;
|
1070 |
-
}
|
1071 |
-
}
|
1072 |
-
if ($this->continuousBuffer) {
|
1073 |
-
$this->encryptIV = $xor;
|
1074 |
-
if ($start = strlen($plaintext) & 7) {
|
1075 |
-
$buffer['encrypted'] = substr($key, $start) . $buffer['encrypted'];
|
1076 |
-
}
|
1077 |
-
}
|
1078 |
-
break;
|
1079 |
-
case CRYPT_DES_MODE_CFB:
|
1080 |
-
if ($this->continuousBuffer) {
|
1081 |
-
$iv = &$this->encryptIV;
|
1082 |
-
$pos = &$buffer['pos'];
|
1083 |
-
} else {
|
1084 |
-
$iv = $this->encryptIV;
|
1085 |
-
$pos = 0;
|
1086 |
-
}
|
1087 |
-
$len = strlen($plaintext);
|
1088 |
-
$i = 0;
|
1089 |
-
if ($pos) {
|
1090 |
-
$orig_pos = $pos;
|
1091 |
-
$max = 8 - $pos;
|
1092 |
-
if ($len >= $max) {
|
1093 |
-
$i = $max;
|
1094 |
-
$len-= $max;
|
1095 |
-
$pos = 0;
|
1096 |
-
} else {
|
1097 |
-
$i = $len;
|
1098 |
-
$pos+= $len;
|
1099 |
-
$len = 0;
|
1100 |
-
}
|
1101 |
-
$ciphertext = substr($iv, $orig_pos) ^ $plaintext;
|
1102 |
-
$iv = substr_replace($iv, $ciphertext, $orig_pos, $i);
|
1103 |
-
}
|
1104 |
-
while ($len >= 8) {
|
1105 |
-
$iv = $this->_processBlock($iv, CRYPT_DES_ENCRYPT) ^ substr($plaintext, $i, 8);
|
1106 |
-
$ciphertext.= $iv;
|
1107 |
-
$len-= 8;
|
1108 |
-
$i+= 8;
|
1109 |
-
}
|
1110 |
-
if ($len) {
|
1111 |
-
$iv = $this->_processBlock($iv, CRYPT_DES_ENCRYPT);
|
1112 |
-
$block = $iv ^ substr($plaintext, $i);
|
1113 |
-
$iv = substr_replace($iv, $block, 0, $len);
|
1114 |
-
$ciphertext.= $block;
|
1115 |
-
$pos = $len;
|
1116 |
-
}
|
1117 |
-
return $ciphertext;
|
1118 |
-
case CRYPT_DES_MODE_OFB:
|
1119 |
-
$xor = $this->encryptIV;
|
1120 |
-
if (strlen($buffer['xor'])) {
|
1121 |
-
for ($i = 0; $i < strlen($plaintext); $i+=8) {
|
1122 |
-
$block = substr($plaintext, $i, 8);
|
1123 |
-
if (strlen($block) > strlen($buffer['xor'])) {
|
1124 |
-
$xor = $this->_processBlock($xor, CRYPT_DES_ENCRYPT);
|
1125 |
-
$buffer['xor'].= $xor;
|
1126 |
-
}
|
1127 |
-
$key = $this->_string_shift($buffer['xor']);
|
1128 |
-
$ciphertext.= $block ^ $key;
|
1129 |
-
}
|
1130 |
-
} else {
|
1131 |
-
for ($i = 0; $i < strlen($plaintext); $i+=8) {
|
1132 |
-
$xor = $this->_processBlock($xor, CRYPT_DES_ENCRYPT);
|
1133 |
-
$ciphertext.= substr($plaintext, $i, 8) ^ $xor;
|
1134 |
-
}
|
1135 |
-
$key = $xor;
|
1136 |
-
}
|
1137 |
-
if ($this->continuousBuffer) {
|
1138 |
-
$this->encryptIV = $xor;
|
1139 |
-
if ($start = strlen($plaintext) & 7) {
|
1140 |
-
$buffer['xor'] = substr($key, $start) . $buffer['xor'];
|
1141 |
-
}
|
1142 |
-
}
|
1143 |
-
}
|
1144 |
-
|
1145 |
-
return $ciphertext;
|
1146 |
-
}
|
1147 |
-
|
1148 |
-
/**
|
1149 |
-
* Decrypts a message.
|
1150 |
-
*
|
1151 |
-
* If strlen($ciphertext) is not a multiple of 8, null bytes will be added to the end of the string until it is.
|
1152 |
-
*
|
1153 |
-
* @see Crypt_DES::encrypt()
|
1154 |
-
* @access public
|
1155 |
-
* @param String $ciphertext
|
1156 |
-
*/
|
1157 |
-
function decrypt($ciphertext)
|
1158 |
-
{
|
1159 |
-
if ($this->paddable) {
|
1160 |
-
// we pad with chr(0) since that's what mcrypt_generic does. to quote from http://php.net/function.mcrypt-generic :
|
1161 |
-
// "The data is padded with "\0" to make sure the length of the data is n * blocksize."
|
1162 |
-
$ciphertext = str_pad($ciphertext, (strlen($ciphertext) + 7) & 0xFFFFFFF8, chr(0));
|
1163 |
-
}
|
1164 |
-
|
1165 |
-
if ( CRYPT_DES_MODE == CRYPT_DES_MODE_MCRYPT ) {
|
1166 |
-
if ($this->dechanged) {
|
1167 |
-
mcrypt_generic_init($this->demcrypt, $this->keys, $this->decryptIV);
|
1168 |
-
if ($this->mode == 'ncfb') {
|
1169 |
-
mcrypt_generic_init($this->ecb, $this->keys, "\0\0\0\0\0\0\0\0");
|
1170 |
-
}
|
1171 |
-
$this->dechanged = false;
|
1172 |
-
}
|
1173 |
-
|
1174 |
-
if ($this->mode != 'ncfb' || !$this->continuousBuffer) {
|
1175 |
-
$plaintext = mdecrypt_generic($this->demcrypt, $ciphertext);
|
1176 |
-
} else {
|
1177 |
-
$iv = &$this->decryptIV;
|
1178 |
-
$pos = &$this->debuffer['pos'];
|
1179 |
-
$len = strlen($ciphertext);
|
1180 |
-
$plaintext = '';
|
1181 |
-
$i = 0;
|
1182 |
-
if ($pos) {
|
1183 |
-
$orig_pos = $pos;
|
1184 |
-
$max = 8 - $pos;
|
1185 |
-
if ($len >= $max) {
|
1186 |
-
$i = $max;
|
1187 |
-
$len-= $max;
|
1188 |
-
$pos = 0;
|
1189 |
-
} else {
|
1190 |
-
$i = $len;
|
1191 |
-
$pos+= $len;
|
1192 |
-
$len = 0;
|
1193 |
-
}
|
1194 |
-
$plaintext = substr($iv, $orig_pos) ^ $ciphertext;
|
1195 |
-
$iv = substr_replace($iv, substr($ciphertext, 0, $i), $orig_pos, $i);
|
1196 |
-
}
|
1197 |
-
if ($len >= 8) {
|
1198 |
-
$cb = substr($ciphertext, $i, $len - $len % 8);
|
1199 |
-
$plaintext.= mcrypt_generic($this->ecb, $iv . $cb) ^ $cb;
|
1200 |
-
$iv = substr($cb, -8);
|
1201 |
-
$len%= 8;
|
1202 |
-
}
|
1203 |
-
if ($len) {
|
1204 |
-
$iv = mcrypt_generic($this->ecb, $iv);
|
1205 |
-
$plaintext.= $iv ^ substr($ciphertext, -$len);
|
1206 |
-
$iv = substr_replace($iv, substr($ciphertext, -$len), 0, $len);
|
1207 |
-
$pos = $len;
|
1208 |
-
}
|
1209 |
-
return $plaintext;
|
1210 |
-
}
|
1211 |
-
|
1212 |
-
if (!$this->continuousBuffer) {
|
1213 |
-
mcrypt_generic_init($this->demcrypt, $this->keys, $this->decryptIV);
|
1214 |
-
}
|
1215 |
-
|
1216 |
-
return $this->paddable ? $this->_unpad($plaintext) : $plaintext;
|
1217 |
-
}
|
1218 |
-
|
1219 |
-
if (!is_array($this->keys)) {
|
1220 |
-
$this->keys = $this->_prepareKey("\0\0\0\0\0\0\0\0");
|
1221 |
-
}
|
1222 |
-
|
1223 |
-
if ($this->use_inline_crypt) {
|
1224 |
-
$inline = $this->inline_crypt;
|
1225 |
-
return $inline('decrypt', $this, $ciphertext);
|
1226 |
-
}
|
1227 |
-
|
1228 |
-
$buffer = &$this->debuffer;
|
1229 |
-
$continuousBuffer = $this->continuousBuffer;
|
1230 |
-
$plaintext = '';
|
1231 |
-
switch ($this->mode) {
|
1232 |
-
case CRYPT_DES_MODE_ECB:
|
1233 |
-
for ($i = 0; $i < strlen($ciphertext); $i+=8) {
|
1234 |
-
$plaintext.= $this->_processBlock(substr($ciphertext, $i, 8), CRYPT_DES_DECRYPT);
|
1235 |
-
}
|
1236 |
-
break;
|
1237 |
-
case CRYPT_DES_MODE_CBC:
|
1238 |
-
$xor = $this->decryptIV;
|
1239 |
-
for ($i = 0; $i < strlen($ciphertext); $i+=8) {
|
1240 |
-
$block = substr($ciphertext, $i, 8);
|
1241 |
-
$plaintext.= $this->_processBlock($block, CRYPT_DES_DECRYPT) ^ $xor;
|
1242 |
-
$xor = $block;
|
1243 |
-
}
|
1244 |
-
if ($this->continuousBuffer) {
|
1245 |
-
$this->decryptIV = $xor;
|
1246 |
-
}
|
1247 |
-
break;
|
1248 |
-
case CRYPT_DES_MODE_CTR:
|
1249 |
-
$xor = $this->decryptIV;
|
1250 |
-
if (strlen($buffer['ciphertext'])) {
|
1251 |
-
for ($i = 0; $i < strlen($ciphertext); $i+=8) {
|
1252 |
-
$block = substr($ciphertext, $i, 8);
|
1253 |
-
if (strlen($block) > strlen($buffer['ciphertext'])) {
|
1254 |
-
$buffer['ciphertext'].= $this->_processBlock($this->_generate_xor($xor), CRYPT_DES_ENCRYPT);
|
1255 |
-
}
|
1256 |
-
$key = $this->_string_shift($buffer['ciphertext']);
|
1257 |
-
$plaintext.= $block ^ $key;
|
1258 |
-
}
|
1259 |
-
} else {
|
1260 |
-
for ($i = 0; $i < strlen($ciphertext); $i+=8) {
|
1261 |
-
$block = substr($ciphertext, $i, 8);
|
1262 |
-
$key = $this->_processBlock($this->_generate_xor($xor), CRYPT_DES_ENCRYPT);
|
1263 |
-
$plaintext.= $block ^ $key;
|
1264 |
-
}
|
1265 |
-
}
|
1266 |
-
if ($this->continuousBuffer) {
|
1267 |
-
$this->decryptIV = $xor;
|
1268 |
-
if ($start = strlen($ciphertext) % 8) {
|
1269 |
-
$buffer['ciphertext'] = substr($key, $start) . $buffer['ciphertext'];
|
1270 |
-
}
|
1271 |
-
}
|
1272 |
-
break;
|
1273 |
-
case CRYPT_DES_MODE_CFB:
|
1274 |
-
if ($this->continuousBuffer) {
|
1275 |
-
$iv = &$this->decryptIV;
|
1276 |
-
$pos = &$buffer['pos'];
|
1277 |
-
} else {
|
1278 |
-
$iv = $this->decryptIV;
|
1279 |
-
$pos = 0;
|
1280 |
-
}
|
1281 |
-
$len = strlen($ciphertext);
|
1282 |
-
$i = 0;
|
1283 |
-
if ($pos) {
|
1284 |
-
$orig_pos = $pos;
|
1285 |
-
$max = 8 - $pos;
|
1286 |
-
if ($len >= $max) {
|
1287 |
-
$i = $max;
|
1288 |
-
$len-= $max;
|
1289 |
-
$pos = 0;
|
1290 |
-
} else {
|
1291 |
-
$i = $len;
|
1292 |
-
$pos+= $len;
|
1293 |
-
$len = 0;
|
1294 |
-
}
|
1295 |
-
$plaintext = substr($iv, $orig_pos) ^ $ciphertext;
|
1296 |
-
$iv = substr_replace($iv, substr($ciphertext, 0, $i), $orig_pos, $i);
|
1297 |
-
}
|
1298 |
-
while ($len >= 8) {
|
1299 |
-
$iv = $this->_processBlock($iv, CRYPT_DES_ENCRYPT);
|
1300 |
-
$cb = substr($ciphertext, $i, 8);
|
1301 |
-
$plaintext.= $iv ^ $cb;
|
1302 |
-
$iv = $cb;
|
1303 |
-
$len-= 8;
|
1304 |
-
$i+= 8;
|
1305 |
-
}
|
1306 |
-
if ($len) {
|
1307 |
-
$iv = $this->_processBlock($iv, CRYPT_DES_ENCRYPT);
|
1308 |
-
$plaintext.= $iv ^ substr($ciphertext, $i);
|
1309 |
-
$iv = substr_replace($iv, substr($ciphertext, $i), 0, $len);
|
1310 |
-
$pos = $len;
|
1311 |
-
}
|
1312 |
-
return $plaintext;
|
1313 |
-
case CRYPT_DES_MODE_OFB:
|
1314 |
-
$xor = $this->decryptIV;
|
1315 |
-
if (strlen($buffer['xor'])) {
|
1316 |
-
for ($i = 0; $i < strlen($ciphertext); $i+=8) {
|
1317 |
-
$block = substr($ciphertext, $i, 8);
|
1318 |
-
if (strlen($block) > strlen($buffer['xor'])) {
|
1319 |
-
$xor = $this->_processBlock($xor, CRYPT_DES_ENCRYPT);
|
1320 |
-
$buffer['xor'].= $xor;
|
1321 |
-
}
|
1322 |
-
$key = $this->_string_shift($buffer['xor']);
|
1323 |
-
$plaintext.= $block ^ $key;
|
1324 |
-
}
|
1325 |
-
} else {
|
1326 |
-
for ($i = 0; $i < strlen($ciphertext); $i+=8) {
|
1327 |
-
$xor = $this->_processBlock($xor, CRYPT_DES_ENCRYPT);
|
1328 |
-
$plaintext.= substr($ciphertext, $i, 8) ^ $xor;
|
1329 |
-
}
|
1330 |
-
$key = $xor;
|
1331 |
-
}
|
1332 |
-
if ($this->continuousBuffer) {
|
1333 |
-
$this->decryptIV = $xor;
|
1334 |
-
if ($start = strlen($ciphertext) % 8) {
|
1335 |
-
$buffer['xor'] = substr($key, $start) . $buffer['xor'];
|
1336 |
-
}
|
1337 |
-
}
|
1338 |
-
}
|
1339 |
-
|
1340 |
-
return $this->paddable ? $this->_unpad($plaintext) : $plaintext;
|
1341 |
-
}
|
1342 |
-
|
1343 |
-
/**
|
1344 |
-
* Treat consecutive "packets" as if they are a continuous buffer.
|
1345 |
-
*
|
1346 |
-
* Say you have a 16-byte plaintext $plaintext. Using the default behavior, the two following code snippets
|
1347 |
-
* will yield different outputs:
|
1348 |
-
*
|
1349 |
-
* <code>
|
1350 |
-
* echo $des->encrypt(substr($plaintext, 0, 8));
|
1351 |
-
* echo $des->encrypt(substr($plaintext, 8, 8));
|
1352 |
-
* </code>
|
1353 |
-
* <code>
|
1354 |
-
* echo $des->encrypt($plaintext);
|
1355 |
-
* </code>
|
1356 |
-
*
|
1357 |
-
* The solution is to enable the continuous buffer. Although this will resolve the above discrepancy, it creates
|
1358 |
-
* another, as demonstrated with the following:
|
1359 |
-
*
|
1360 |
-
* <code>
|
1361 |
-
* $des->encrypt(substr($plaintext, 0, 8));
|
1362 |
-
* echo $des->decrypt($des->encrypt(substr($plaintext, 8, 8)));
|
1363 |
-
* </code>
|
1364 |
-
* <code>
|
1365 |
-
* echo $des->decrypt($des->encrypt(substr($plaintext, 8, 8)));
|
1366 |
-
* </code>
|
1367 |
-
*
|
1368 |
-
* With the continuous buffer disabled, these would yield the same output. With it enabled, they yield different
|
1369 |
-
* outputs. The reason is due to the fact that the initialization vector's change after every encryption /
|
1370 |
-
* decryption round when the continuous buffer is enabled. When it's disabled, they remain constant.
|
1371 |
-
*
|
1372 |
-
* Put another way, when the continuous buffer is enabled, the state of the Crypt_DES() object changes after each
|
1373 |
-
* encryption / decryption round, whereas otherwise, it'd remain constant. For this reason, it's recommended that
|
1374 |
-
* continuous buffers not be used. They do offer better security and are, in fact, sometimes required (SSH uses them),
|
1375 |
-
* however, they are also less intuitive and more likely to cause you problems.
|
1376 |
-
*
|
1377 |
-
* @see Crypt_DES::disableContinuousBuffer()
|
1378 |
-
* @access public
|
1379 |
-
*/
|
1380 |
-
function enableContinuousBuffer()
|
1381 |
-
{
|
1382 |
-
$this->continuousBuffer = true;
|
1383 |
-
}
|
1384 |
-
|
1385 |
-
/**
|
1386 |
-
* Treat consecutive packets as if they are a discontinuous buffer.
|
1387 |
-
*
|
1388 |
-
* The default behavior.
|
1389 |
-
*
|
1390 |
-
* @see Crypt_DES::enableContinuousBuffer()
|
1391 |
-
* @access public
|
1392 |
-
*/
|
1393 |
-
function disableContinuousBuffer()
|
1394 |
-
{
|
1395 |
-
$this->continuousBuffer = false;
|
1396 |
-
$this->encryptIV = $this->iv;
|
1397 |
-
$this->decryptIV = $this->iv;
|
1398 |
-
$this->enbuffer = array('encrypted' => '', 'xor' => '', 'pos' => 0, 'enmcrypt_init' => true);
|
1399 |
-
$this->debuffer = array('ciphertext' => '', 'xor' => '', 'pos' => 0, 'demcrypt_init' => true);
|
1400 |
-
|
1401 |
-
if (CRYPT_DES_MODE == CRYPT_DES_MODE_MCRYPT) {
|
1402 |
-
mcrypt_generic_init($this->enmcrypt, $this->keys, $this->iv);
|
1403 |
-
mcrypt_generic_init($this->demcrypt, $this->keys, $this->iv);
|
1404 |
-
}
|
1405 |
-
}
|
1406 |
-
|
1407 |
-
/**
|
1408 |
-
* Pad "packets".
|
1409 |
-
*
|
1410 |
-
* DES works by encrypting eight bytes at a time. If you ever need to encrypt or decrypt something that's not
|
1411 |
-
* a multiple of eight, it becomes necessary to pad the input so that it's length is a multiple of eight.
|
1412 |
-
*
|
1413 |
-
* Padding is enabled by default. Sometimes, however, it is undesirable to pad strings. Such is the case in SSH1,
|
1414 |
-
* where "packets" are padded with random bytes before being encrypted. Unpad these packets and you risk stripping
|
1415 |
-
* away characters that shouldn't be stripped away. (SSH knows how many bytes are added because the length is
|
1416 |
-
* transmitted separately)
|
1417 |
-
*
|
1418 |
-
* @see Crypt_DES::disablePadding()
|
1419 |
-
* @access public
|
1420 |
-
*/
|
1421 |
-
function enablePadding()
|
1422 |
-
{
|
1423 |
-
$this->padding = true;
|
1424 |
-
}
|
1425 |
-
|
1426 |
-
/**
|
1427 |
-
* Do not pad packets.
|
1428 |
-
*
|
1429 |
-
* @see Crypt_DES::enablePadding()
|
1430 |
-
* @access public
|
1431 |
-
*/
|
1432 |
-
function disablePadding()
|
1433 |
-
{
|
1434 |
-
$this->padding = false;
|
1435 |
-
}
|
1436 |
-
|
1437 |
-
/**
|
1438 |
-
* Pads a string
|
1439 |
-
*
|
1440 |
-
* Pads a string using the RSA PKCS padding standards so that its length is a multiple of the blocksize (8).
|
1441 |
-
* 8 - (strlen($text) & 7) bytes are added, each of which is equal to chr(8 - (strlen($text) & 7)
|
1442 |
-
*
|
1443 |
-
* If padding is disabled and $text is not a multiple of the blocksize, the string will be padded regardless
|
1444 |
-
* and padding will, hence forth, be enabled.
|
1445 |
-
*
|
1446 |
-
* @see Crypt_DES::_unpad()
|
1447 |
-
* @access private
|
1448 |
-
*/
|
1449 |
-
function _pad($text)
|
1450 |
-
{
|
1451 |
-
$length = strlen($text);
|
1452 |
-
|
1453 |
-
if (!$this->padding) {
|
1454 |
-
if (($length & 7) == 0) {
|
1455 |
-
return $text;
|
1456 |
-
} else {
|
1457 |
-
user_error("The plaintext's length ($length) is not a multiple of the block size (8)");
|
1458 |
-
$this->padding = true;
|
1459 |
-
}
|
1460 |
-
}
|
1461 |
-
|
1462 |
-
$pad = 8 - ($length & 7);
|
1463 |
-
return str_pad($text, $length + $pad, chr($pad));
|
1464 |
-
}
|
1465 |
-
|
1466 |
-
/**
|
1467 |
-
* Unpads a string
|
1468 |
-
*
|
1469 |
-
* If padding is enabled and the reported padding length is invalid the encryption key will be assumed to be wrong
|
1470 |
-
* and false will be returned.
|
1471 |
-
*
|
1472 |
-
* @see Crypt_DES::_pad()
|
1473 |
-
* @access private
|
1474 |
-
*/
|
1475 |
-
function _unpad($text)
|
1476 |
-
{
|
1477 |
-
if (!$this->padding) {
|
1478 |
-
return $text;
|
1479 |
-
}
|
1480 |
-
|
1481 |
-
$length = ord($text[strlen($text) - 1]);
|
1482 |
-
|
1483 |
-
if (!$length || $length > 8) {
|
1484 |
-
return false;
|
1485 |
-
}
|
1486 |
-
|
1487 |
-
return substr($text, 0, -$length);
|
1488 |
-
}
|
1489 |
-
|
1490 |
-
/**
|
1491 |
-
* Encrypts or decrypts a 64-bit block
|
1492 |
-
*
|
1493 |
-
* $mode should be either CRYPT_DES_ENCRYPT or CRYPT_DES_DECRYPT. See
|
1494 |
-
* {@link http://en.wikipedia.org/wiki/Image:Feistel.png Feistel.png} to get a general
|
1495 |
-
* idea of what this function does.
|
1496 |
-
*
|
1497 |
-
* @access private
|
1498 |
-
* @param String $block
|
1499 |
-
* @param Integer $mode
|
1500 |
-
* @return String
|
1501 |
-
*/
|
1502 |
-
function _processBlock($block, $mode)
|
1503 |
-
{
|
1504 |
-
$shuffle = $this->shuffle;
|
1505 |
-
$invipmap = $this->invipmap;
|
1506 |
-
$ipmap = $this->ipmap;
|
1507 |
-
$sbox1 = $this->sbox1;
|
1508 |
-
$sbox2 = $this->sbox2;
|
1509 |
-
$sbox3 = $this->sbox3;
|
1510 |
-
$sbox4 = $this->sbox4;
|
1511 |
-
$sbox5 = $this->sbox5;
|
1512 |
-
$sbox6 = $this->sbox6;
|
1513 |
-
$sbox7 = $this->sbox7;
|
1514 |
-
$sbox8 = $this->sbox8;
|
1515 |
-
$keys = $this->keys[$mode];
|
1516 |
-
|
1517 |
-
// Do the initial IP permutation.
|
1518 |
-
$t = unpack('Nl/Nr', $block);
|
1519 |
-
list($l, $r) = array($t['l'], $t['r']);
|
1520 |
-
$block = ($shuffle[$ipmap[$r & 0xFF]] & "\x80\x80\x80\x80\x80\x80\x80\x80") |
|
1521 |
-
($shuffle[$ipmap[($r >> 8) & 0xFF]] & "\x40\x40\x40\x40\x40\x40\x40\x40") |
|
1522 |
-
($shuffle[$ipmap[($r >> 16) & 0xFF]] & "\x20\x20\x20\x20\x20\x20\x20\x20") |
|
1523 |
-
($shuffle[$ipmap[($r >> 24) & 0xFF]] & "\x10\x10\x10\x10\x10\x10\x10\x10") |
|
1524 |
-
($shuffle[$ipmap[$l & 0xFF]] & "\x08\x08\x08\x08\x08\x08\x08\x08") |
|
1525 |
-
($shuffle[$ipmap[($l >> 8) & 0xFF]] & "\x04\x04\x04\x04\x04\x04\x04\x04") |
|
1526 |
-
($shuffle[$ipmap[($l >> 16) & 0xFF]] & "\x02\x02\x02\x02\x02\x02\x02\x02") |
|
1527 |
-
($shuffle[$ipmap[($l >> 24) & 0xFF]] & "\x01\x01\x01\x01\x01\x01\x01\x01");
|
1528 |
-
|
1529 |
-
// Extract L0 and R0.
|
1530 |
-
$t = unpack('Nl/Nr', $block);
|
1531 |
-
list($l, $r) = array($t['l'], $t['r']);
|
1532 |
-
|
1533 |
-
// Perform the 16 steps.
|
1534 |
-
for ($i = 0; $i < 16; $i++) {
|
1535 |
-
// start of "the Feistel (F) function" - see the following URL:
|
1536 |
-
// http://en.wikipedia.org/wiki/Image:Data_Encryption_Standard_InfoBox_Diagram.png
|
1537 |
-
// Merge key schedule.
|
1538 |
-
$b1 = (($r >> 3) & 0x1FFFFFFF) ^ ($r << 29) ^ $keys[$i][0];
|
1539 |
-
$b2 = (($r >> 31) & 0x00000001) ^ ($r << 1) ^ $keys[$i][1];
|
1540 |
-
|
1541 |
-
// S-box indexing.
|
1542 |
-
$t = $sbox1[($b1 >> 24) & 0x3F] ^ $sbox2[($b2 >> 24) & 0x3F] ^
|
1543 |
-
$sbox3[($b1 >> 16) & 0x3F] ^ $sbox4[($b2 >> 16) & 0x3F] ^
|
1544 |
-
$sbox5[($b1 >> 8) & 0x3F] ^ $sbox6[($b2 >> 8) & 0x3F] ^
|
1545 |
-
$sbox7[$b1 & 0x3F] ^ $sbox8[$b2 & 0x3F] ^ $l;
|
1546 |
-
// end of "the Feistel (F) function"
|
1547 |
-
|
1548 |
-
$l = $r;
|
1549 |
-
$r = $t;
|
1550 |
-
}
|
1551 |
-
|
1552 |
-
// Perform the inverse IP permutation.
|
1553 |
-
return ($shuffle[$invipmap[($l >> 24) & 0xFF]] & "\x80\x80\x80\x80\x80\x80\x80\x80") |
|
1554 |
-
($shuffle[$invipmap[($r >> 24) & 0xFF]] & "\x40\x40\x40\x40\x40\x40\x40\x40") |
|
1555 |
-
($shuffle[$invipmap[($l >> 16) & 0xFF]] & "\x20\x20\x20\x20\x20\x20\x20\x20") |
|
1556 |
-
($shuffle[$invipmap[($r >> 16) & 0xFF]] & "\x10\x10\x10\x10\x10\x10\x10\x10") |
|
1557 |
-
($shuffle[$invipmap[($l >> 8) & 0xFF]] & "\x08\x08\x08\x08\x08\x08\x08\x08") |
|
1558 |
-
($shuffle[$invipmap[($r >> 8) & 0xFF]] & "\x04\x04\x04\x04\x04\x04\x04\x04") |
|
1559 |
-
($shuffle[$invipmap[$l & 0xFF]] & "\x02\x02\x02\x02\x02\x02\x02\x02") |
|
1560 |
-
($shuffle[$invipmap[$r & 0xFF]] & "\x01\x01\x01\x01\x01\x01\x01\x01");
|
1561 |
-
}
|
1562 |
-
|
1563 |
-
/**
|
1564 |
-
* Creates the key schedule.
|
1565 |
-
*
|
1566 |
-
* @access private
|
1567 |
-
* @param String $key
|
1568 |
-
* @return Array
|
1569 |
-
*/
|
1570 |
-
function _prepareKey($key)
|
1571 |
-
{
|
1572 |
-
static $shifts = array( // number of key bits shifted per round
|
1573 |
-
1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1
|
1574 |
-
);
|
1575 |
-
|
1576 |
-
static $pc1map = array(
|
1577 |
-
0x00, 0x00, 0x08, 0x08, 0x04, 0x04, 0x0C, 0x0C,
|
1578 |
-
0x02, 0x02, 0x0A, 0x0A, 0x06, 0x06, 0x0E, 0x0E,
|
1579 |
-
0x10, 0x10, 0x18, 0x18, 0x14, 0x14, 0x1C, 0x1C,
|
1580 |
-
0x12, 0x12, 0x1A, 0x1A, 0x16, 0x16, 0x1E, 0x1E,
|
1581 |
-
0x20, 0x20, 0x28, 0x28, 0x24, 0x24, 0x2C, 0x2C,
|
1582 |
-
0x22, 0x22, 0x2A, 0x2A, 0x26, 0x26, 0x2E, 0x2E,
|
1583 |
-
0x30, 0x30, 0x38, 0x38, 0x34, 0x34, 0x3C, 0x3C,
|
1584 |
-
0x32, 0x32, 0x3A, 0x3A, 0x36, 0x36, 0x3E, 0x3E,
|
1585 |
-
0x40, 0x40, 0x48, 0x48, 0x44, 0x44, 0x4C, 0x4C,
|
1586 |
-
0x42, 0x42, 0x4A, 0x4A, 0x46, 0x46, 0x4E, 0x4E,
|
1587 |
-
0x50, 0x50, 0x58, 0x58, 0x54, 0x54, 0x5C, 0x5C,
|
1588 |
-
0x52, 0x52, 0x5A, 0x5A, 0x56, 0x56, 0x5E, 0x5E,
|
1589 |
-
0x60, 0x60, 0x68, 0x68, 0x64, 0x64, 0x6C, 0x6C,
|
1590 |
-
0x62, 0x62, 0x6A, 0x6A, 0x66, 0x66, 0x6E, 0x6E,
|
1591 |
-
0x70, 0x70, 0x78, 0x78, 0x74, 0x74, 0x7C, 0x7C,
|
1592 |
-
0x72, 0x72, 0x7A, 0x7A, 0x76, 0x76, 0x7E, 0x7E,
|
1593 |
-
0x80, 0x80, 0x88, 0x88, 0x84, 0x84, 0x8C, 0x8C,
|
1594 |
-
0x82, 0x82, 0x8A, 0x8A, 0x86, 0x86, 0x8E, 0x8E,
|
1595 |
-
0x90, 0x90, 0x98, 0x98, 0x94, 0x94, 0x9C, 0x9C,
|
1596 |
-
0x92, 0x92, 0x9A, 0x9A, 0x96, 0x96, 0x9E, 0x9E,
|
1597 |
-
0xA0, 0xA0, 0xA8, 0xA8, 0xA4, 0xA4, 0xAC, 0xAC,
|
1598 |
-
0xA2, 0xA2, 0xAA, 0xAA, 0xA6, 0xA6, 0xAE, 0xAE,
|
1599 |
-
0xB0, 0xB0, 0xB8, 0xB8, 0xB4, 0xB4, 0xBC, 0xBC,
|
1600 |
-
0xB2, 0xB2, 0xBA, 0xBA, 0xB6, 0xB6, 0xBE, 0xBE,
|
1601 |
-
0xC0, 0xC0, 0xC8, 0xC8, 0xC4, 0xC4, 0xCC, 0xCC,
|
1602 |
-
0xC2, 0xC2, 0xCA, 0xCA, 0xC6, 0xC6, 0xCE, 0xCE,
|
1603 |
-
0xD0, 0xD0, 0xD8, 0xD8, 0xD4, 0xD4, 0xDC, 0xDC,
|
1604 |
-
0xD2, 0xD2, 0xDA, 0xDA, 0xD6, 0xD6, 0xDE, 0xDE,
|
1605 |
-
0xE0, 0xE0, 0xE8, 0xE8, 0xE4, 0xE4, 0xEC, 0xEC,
|
1606 |
-
0xE2, 0xE2, 0xEA, 0xEA, 0xE6, 0xE6, 0xEE, 0xEE,
|
1607 |
-
0xF0, 0xF0, 0xF8, 0xF8, 0xF4, 0xF4, 0xFC, 0xFC,
|
1608 |
-
0xF2, 0xF2, 0xFA, 0xFA, 0xF6, 0xF6, 0xFE, 0xFE
|
1609 |
-
);
|
1610 |
-
|
1611 |
-
// Mapping tables for the PC-2 transformation.
|
1612 |
-
static $pc2mapc1 = array(
|
1613 |
-
0x00000000, 0x00000400, 0x00200000, 0x00200400,
|
1614 |
-
0x00000001, 0x00000401, 0x00200001, 0x00200401,
|
1615 |
-
0x02000000, 0x02000400, 0x02200000, 0x02200400,
|
1616 |
-
0x02000001, 0x02000401, 0x02200001, 0x02200401
|
1617 |
-
);
|
1618 |
-
static $pc2mapc2 = array(
|
1619 |
-
0x00000000, 0x00000800, 0x08000000, 0x08000800,
|
1620 |
-
0x00010000, 0x00010800, 0x08010000, 0x08010800,
|
1621 |
-
0x00000000, 0x00000800, 0x08000000, 0x08000800,
|
1622 |
-
0x00010000, 0x00010800, 0x08010000, 0x08010800,
|
1623 |
-
0x00000100, 0x00000900, 0x08000100, 0x08000900,
|
1624 |
-
0x00010100, 0x00010900, 0x08010100, 0x08010900,
|
1625 |
-
0x00000100, 0x00000900, 0x08000100, 0x08000900,
|
1626 |
-
0x00010100, 0x00010900, 0x08010100, 0x08010900,
|
1627 |
-
0x00000010, 0x00000810, 0x08000010, 0x08000810,
|
1628 |
-
0x00010010, 0x00010810, 0x08010010, 0x08010810,
|
1629 |
-
0x00000010, 0x00000810, 0x08000010, 0x08000810,
|
1630 |
-
0x00010010, 0x00010810, 0x08010010, 0x08010810,
|
1631 |
-
0x00000110, 0x00000910, 0x08000110, 0x08000910,
|
1632 |
-
0x00010110, 0x00010910, 0x08010110, 0x08010910,
|
1633 |
-
0x00000110, 0x00000910, 0x08000110, 0x08000910,
|
1634 |
-
0x00010110, 0x00010910, 0x08010110, 0x08010910,
|
1635 |
-
0x00040000, 0x00040800, 0x08040000, 0x08040800,
|
1636 |
-
0x00050000, 0x00050800, 0x08050000, 0x08050800,
|
1637 |
-
0x00040000, 0x00040800, 0x08040000, 0x08040800,
|
1638 |
-
0x00050000, 0x00050800, 0x08050000, 0x08050800,
|
1639 |
-
0x00040100, 0x00040900, 0x08040100, 0x08040900,
|
1640 |
-
0x00050100, 0x00050900, 0x08050100, 0x08050900,
|
1641 |
-
0x00040100, 0x00040900, 0x08040100, 0x08040900,
|
1642 |
-
0x00050100, 0x00050900, 0x08050100, 0x08050900,
|
1643 |
-
0x00040010, 0x00040810, 0x08040010, 0x08040810,
|
1644 |
-
0x00050010, 0x00050810, 0x08050010, 0x08050810,
|
1645 |
-
0x00040010, 0x00040810, 0x08040010, 0x08040810,
|
1646 |
-
0x00050010, 0x00050810, 0x08050010, 0x08050810,
|
1647 |
-
0x00040110, 0x00040910, 0x08040110, 0x08040910,
|
1648 |
-
0x00050110, 0x00050910, 0x08050110, 0x08050910,
|
1649 |
-
0x00040110, 0x00040910, 0x08040110, 0x08040910,
|
1650 |
-
0x00050110, 0x00050910, 0x08050110, 0x08050910,
|
1651 |
-
0x01000000, 0x01000800, 0x09000000, 0x09000800,
|
1652 |
-
0x01010000, 0x01010800, 0x09010000, 0x09010800,
|
1653 |
-
0x01000000, 0x01000800, 0x09000000, 0x09000800,
|
1654 |
-
0x01010000, 0x01010800, 0x09010000, 0x09010800,
|
1655 |
-
0x01000100, 0x01000900, 0x09000100, 0x09000900,
|
1656 |
-
0x01010100, 0x01010900, 0x09010100, 0x09010900,
|
1657 |
-
0x01000100, 0x01000900, 0x09000100, 0x09000900,
|
1658 |
-
0x01010100, 0x01010900, 0x09010100, 0x09010900,
|
1659 |
-
0x01000010, 0x01000810, 0x09000010, 0x09000810,
|
1660 |
-
0x01010010, 0x01010810, 0x09010010, 0x09010810,
|
1661 |
-
0x01000010, 0x01000810, 0x09000010, 0x09000810,
|
1662 |
-
0x01010010, 0x01010810, 0x09010010, 0x09010810,
|
1663 |
-
0x01000110, 0x01000910, 0x09000110, 0x09000910,
|
1664 |
-
0x01010110, 0x01010910, 0x09010110, 0x09010910,
|
1665 |
-
0x01000110, 0x01000910, 0x09000110, 0x09000910,
|
1666 |
-
0x01010110, 0x01010910, 0x09010110, 0x09010910,
|
1667 |
-
0x01040000, 0x01040800, 0x09040000, 0x09040800,
|
1668 |
-
0x01050000, 0x01050800, 0x09050000, 0x09050800,
|
1669 |
-
0x01040000, 0x01040800, 0x09040000, 0x09040800,
|
1670 |
-
0x01050000, 0x01050800, 0x09050000, 0x09050800,
|
1671 |
-
0x01040100, 0x01040900, 0x09040100, 0x09040900,
|
1672 |
-
0x01050100, 0x01050900, 0x09050100, 0x09050900,
|
1673 |
-
0x01040100, 0x01040900, 0x09040100, 0x09040900,
|
1674 |
-
0x01050100, 0x01050900, 0x09050100, 0x09050900,
|
1675 |
-
0x01040010, 0x01040810, 0x09040010, 0x09040810,
|
1676 |
-
0x01050010, 0x01050810, 0x09050010, 0x09050810,
|
1677 |
-
0x01040010, 0x01040810, 0x09040010, 0x09040810,
|
1678 |
-
0x01050010, 0x01050810, 0x09050010, 0x09050810,
|
1679 |
-
0x01040110, 0x01040910, 0x09040110, 0x09040910,
|
1680 |
-
0x01050110, 0x01050910, 0x09050110, 0x09050910,
|
1681 |
-
0x01040110, 0x01040910, 0x09040110, 0x09040910,
|
1682 |
-
0x01050110, 0x01050910, 0x09050110, 0x09050910
|
1683 |
-
);
|
1684 |
-
static $pc2mapc3 = array(
|
1685 |
-
0x00000000, 0x00000004, 0x00001000, 0x00001004,
|
1686 |
-
0x00000000, 0x00000004, 0x00001000, 0x00001004,
|
1687 |
-
0x10000000, 0x10000004, 0x10001000, 0x10001004,
|
1688 |
-
0x10000000, 0x10000004, 0x10001000, 0x10001004,
|
1689 |
-
0x00000020, 0x00000024, 0x00001020, 0x00001024,
|
1690 |
-
0x00000020, 0x00000024, 0x00001020, 0x00001024,
|
1691 |
-
0x10000020, 0x10000024, 0x10001020, 0x10001024,
|
1692 |
-
0x10000020, 0x10000024, 0x10001020, 0x10001024,
|
1693 |
-
0x00080000, 0x00080004, 0x00081000, 0x00081004,
|
1694 |
-
0x00080000, 0x00080004, 0x00081000, 0x00081004,
|
1695 |
-
0x10080000, 0x10080004, 0x10081000, 0x10081004,
|
1696 |
-
0x10080000, 0x10080004, 0x10081000, 0x10081004,
|
1697 |
-
0x00080020, 0x00080024, 0x00081020, 0x00081024,
|
1698 |
-
0x00080020, 0x00080024, 0x00081020, 0x00081024,
|
1699 |
-
0x10080020, 0x10080024, 0x10081020, 0x10081024,
|
1700 |
-
0x10080020, 0x10080024, 0x10081020, 0x10081024,
|
1701 |
-
0x20000000, 0x20000004, 0x20001000, 0x20001004,
|
1702 |
-
0x20000000, 0x20000004, 0x20001000, 0x20001004,
|
1703 |
-
0x30000000, 0x30000004, 0x30001000, 0x30001004,
|
1704 |
-
0x30000000, 0x30000004, 0x30001000, 0x30001004,
|
1705 |
-
0x20000020, 0x20000024, 0x20001020, 0x20001024,
|
1706 |
-
0x20000020, 0x20000024, 0x20001020, 0x20001024,
|
1707 |
-
0x30000020, 0x30000024, 0x30001020, 0x30001024,
|
1708 |
-
0x30000020, 0x30000024, 0x30001020, 0x30001024,
|
1709 |
-
0x20080000, 0x20080004, 0x20081000, 0x20081004,
|
1710 |
-
0x20080000, 0x20080004, 0x20081000, 0x20081004,
|
1711 |
-
0x30080000, 0x30080004, 0x30081000, 0x30081004,
|
1712 |
-
0x30080000, 0x30080004, 0x30081000, 0x30081004,
|
1713 |
-
0x20080020, 0x20080024, 0x20081020, 0x20081024,
|
1714 |
-
0x20080020, 0x20080024, 0x20081020, 0x20081024,
|
1715 |
-
0x30080020, 0x30080024, 0x30081020, 0x30081024,
|
1716 |
-
0x30080020, 0x30080024, 0x30081020, 0x30081024,
|
1717 |
-
0x00000002, 0x00000006, 0x00001002, 0x00001006,
|
1718 |
-
0x00000002, 0x00000006, 0x00001002, 0x00001006,
|
1719 |
-
0x10000002, 0x10000006, 0x10001002, 0x10001006,
|
1720 |
-
0x10000002, 0x10000006, 0x10001002, 0x10001006,
|
1721 |
-
0x00000022, 0x00000026, 0x00001022, 0x00001026,
|
1722 |
-
0x00000022, 0x00000026, 0x00001022, 0x00001026,
|
1723 |
-
0x10000022, 0x10000026, 0x10001022, 0x10001026,
|
1724 |
-
0x10000022, 0x10000026, 0x10001022, 0x10001026,
|
1725 |
-
0x00080002, 0x00080006, 0x00081002, 0x00081006,
|
1726 |
-
0x00080002, 0x00080006, 0x00081002, 0x00081006,
|
1727 |
-
0x10080002, 0x10080006, 0x10081002, 0x10081006,
|
1728 |
-
0x10080002, 0x10080006, 0x10081002, 0x10081006,
|
1729 |
-
0x00080022, 0x00080026, 0x00081022, 0x00081026,
|
1730 |
-
0x00080022, 0x00080026, 0x00081022, 0x00081026,
|
1731 |
-
0x10080022, 0x10080026, 0x10081022, 0x10081026,
|
1732 |
-
0x10080022, 0x10080026, 0x10081022, 0x10081026,
|
1733 |
-
0x20000002, 0x20000006, 0x20001002, 0x20001006,
|
1734 |
-
0x20000002, 0x20000006, 0x20001002, 0x20001006,
|
1735 |
-
0x30000002, 0x30000006, 0x30001002, 0x30001006,
|
1736 |
-
0x30000002, 0x30000006, 0x30001002, 0x30001006,
|
1737 |
-
0x20000022, 0x20000026, 0x20001022, 0x20001026,
|
1738 |
-
0x20000022, 0x20000026, 0x20001022, 0x20001026,
|
1739 |
-
0x30000022, 0x30000026, 0x30001022, 0x30001026,
|
1740 |
-
0x30000022, 0x30000026, 0x30001022, 0x30001026,
|
1741 |
-
0x20080002, 0x20080006, 0x20081002, 0x20081006,
|
1742 |
-
0x20080002, 0x20080006, 0x20081002, 0x20081006,
|
1743 |
-
0x30080002, 0x30080006, 0x30081002, 0x30081006,
|
1744 |
-
0x30080002, 0x30080006, 0x30081002, 0x30081006,
|
1745 |
-
0x20080022, 0x20080026, 0x20081022, 0x20081026,
|
1746 |
-
0x20080022, 0x20080026, 0x20081022, 0x20081026,
|
1747 |
-
0x30080022, 0x30080026, 0x30081022, 0x30081026,
|
1748 |
-
0x30080022, 0x30080026, 0x30081022, 0x30081026
|
1749 |
-
);
|
1750 |
-
static $pc2mapc4 = array(
|
1751 |
-
0x00000000, 0x00100000, 0x00000008, 0x00100008,
|
1752 |
-
0x00000200, 0x00100200, 0x00000208, 0x00100208,
|
1753 |
-
0x00000000, 0x00100000, 0x00000008, 0x00100008,
|
1754 |
-
0x00000200, 0x00100200, 0x00000208, 0x00100208,
|
1755 |
-
0x04000000, 0x04100000, 0x04000008, 0x04100008,
|
1756 |
-
0x04000200, 0x04100200, 0x04000208, 0x04100208,
|
1757 |
-
0x04000000, 0x04100000, 0x04000008, 0x04100008,
|
1758 |
-
0x04000200, 0x04100200, 0x04000208, 0x04100208,
|
1759 |
-
0x00002000, 0x00102000, 0x00002008, 0x00102008,
|
1760 |
-
0x00002200, 0x00102200, 0x00002208, 0x00102208,
|
1761 |
-
0x00002000, 0x00102000, 0x00002008, 0x00102008,
|
1762 |
-
0x00002200, 0x00102200, 0x00002208, 0x00102208,
|
1763 |
-
0x04002000, 0x04102000, 0x04002008, 0x04102008,
|
1764 |
-
0x04002200, 0x04102200, 0x04002208, 0x04102208,
|
1765 |
-
0x04002000, 0x04102000, 0x04002008, 0x04102008,
|
1766 |
-
0x04002200, 0x04102200, 0x04002208, 0x04102208,
|
1767 |
-
0x00000000, 0x00100000, 0x00000008, 0x00100008,
|
1768 |
-
0x00000200, 0x00100200, 0x00000208, 0x00100208,
|
1769 |
-
0x00000000, 0x00100000, 0x00000008, 0x00100008,
|
1770 |
-
0x00000200, 0x00100200, 0x00000208, 0x00100208,
|
1771 |
-
0x04000000, 0x04100000, 0x04000008, 0x04100008,
|
1772 |
-
0x04000200, 0x04100200, 0x04000208, 0x04100208,
|
1773 |
-
0x04000000, 0x04100000, 0x04000008, 0x04100008,
|
1774 |
-
0x04000200, 0x04100200, 0x04000208, 0x04100208,
|
1775 |
-
0x00002000, 0x00102000, 0x00002008, 0x00102008,
|
1776 |
-
0x00002200, 0x00102200, 0x00002208, 0x00102208,
|
1777 |
-
0x00002000, 0x00102000, 0x00002008, 0x00102008,
|
1778 |
-
0x00002200, 0x00102200, 0x00002208, 0x00102208,
|
1779 |
-
0x04002000, 0x04102000, 0x04002008, 0x04102008,
|
1780 |
-
0x04002200, 0x04102200, 0x04002208, 0x04102208,
|
1781 |
-
0x04002000, 0x04102000, 0x04002008, 0x04102008,
|
1782 |
-
0x04002200, 0x04102200, 0x04002208, 0x04102208,
|
1783 |
-
0x00020000, 0x00120000, 0x00020008, 0x00120008,
|
1784 |
-
0x00020200, 0x00120200, 0x00020208, 0x00120208,
|
1785 |
-
0x00020000, 0x00120000, 0x00020008, 0x00120008,
|
1786 |
-
0x00020200, 0x00120200, 0x00020208, 0x00120208,
|
1787 |
-
0x04020000, 0x04120000, 0x04020008, 0x04120008,
|
1788 |
-
0x04020200, 0x04120200, 0x04020208, 0x04120208,
|
1789 |
-
0x04020000, 0x04120000, 0x04020008, 0x04120008,
|
1790 |
-
0x04020200, 0x04120200, 0x04020208, 0x04120208,
|
1791 |
-
0x00022000, 0x00122000, 0x00022008, 0x00122008,
|
1792 |
-
0x00022200, 0x00122200, 0x00022208, 0x00122208,
|
1793 |
-
0x00022000, 0x00122000, 0x00022008, 0x00122008,
|
1794 |
-
0x00022200, 0x00122200, 0x00022208, 0x00122208,
|
1795 |
-
0x04022000, 0x04122000, 0x04022008, 0x04122008,
|
1796 |
-
0x04022200, 0x04122200, 0x04022208, 0x04122208,
|
1797 |
-
0x04022000, 0x04122000, 0x04022008, 0x04122008,
|
1798 |
-
0x04022200, 0x04122200, 0x04022208, 0x04122208,
|
1799 |
-
0x00020000, 0x00120000, 0x00020008, 0x00120008,
|
1800 |
-
0x00020200, 0x00120200, 0x00020208, 0x00120208,
|
1801 |
-
0x00020000, 0x00120000, 0x00020008, 0x00120008,
|
1802 |
-
0x00020200, 0x00120200, 0x00020208, 0x00120208,
|
1803 |
-
0x04020000, 0x04120000, 0x04020008, 0x04120008,
|
1804 |
-
0x04020200, 0x04120200, 0x04020208, 0x04120208,
|
1805 |
-
0x04020000, 0x04120000, 0x04020008, 0x04120008,
|
1806 |
-
0x04020200, 0x04120200, 0x04020208, 0x04120208,
|
1807 |
-
0x00022000, 0x00122000, 0x00022008, 0x00122008,
|
1808 |
-
0x00022200, 0x00122200, 0x00022208, 0x00122208,
|
1809 |
-
0x00022000, 0x00122000, 0x00022008, 0x00122008,
|
1810 |
-
0x00022200, 0x00122200, 0x00022208, 0x00122208,
|
1811 |
-
0x04022000, 0x04122000, 0x04022008, 0x04122008,
|
1812 |
-
0x04022200, 0x04122200, 0x04022208, 0x04122208,
|
1813 |
-
0x04022000, 0x04122000, 0x04022008, 0x04122008,
|
1814 |
-
0x04022200, 0x04122200, 0x04022208, 0x04122208
|
1815 |
-
);
|
1816 |
-
static $pc2mapd1 = array(
|
1817 |
-
0x00000000, 0x00000001, 0x08000000, 0x08000001,
|
1818 |
-
0x00200000, 0x00200001, 0x08200000, 0x08200001,
|
1819 |
-
0x00000002, 0x00000003, 0x08000002, 0x08000003,
|
1820 |
-
0x00200002, 0x00200003, 0x08200002, 0x08200003
|
1821 |
-
);
|
1822 |
-
static $pc2mapd2 = array(
|
1823 |
-
0x00000000, 0x00100000, 0x00000800, 0x00100800,
|
1824 |
-
0x00000000, 0x00100000, 0x00000800, 0x00100800,
|
1825 |
-
0x04000000, 0x04100000, 0x04000800, 0x04100800,
|
1826 |
-
0x04000000, 0x04100000, 0x04000800, 0x04100800,
|
1827 |
-
0x00000004, 0x00100004, 0x00000804, 0x00100804,
|
1828 |
-
0x00000004, 0x00100004, 0x00000804, 0x00100804,
|
1829 |
-
0x04000004, 0x04100004, 0x04000804, 0x04100804,
|
1830 |
-
0x04000004, 0x04100004, 0x04000804, 0x04100804,
|
1831 |
-
0x00000000, 0x00100000, 0x00000800, 0x00100800,
|
1832 |
-
0x00000000, 0x00100000, 0x00000800, 0x00100800,
|
1833 |
-
0x04000000, 0x04100000, 0x04000800, 0x04100800,
|
1834 |
-
0x04000000, 0x04100000, 0x04000800, 0x04100800,
|
1835 |
-
0x00000004, 0x00100004, 0x00000804, 0x00100804,
|
1836 |
-
0x00000004, 0x00100004, 0x00000804, 0x00100804,
|
1837 |
-
0x04000004, 0x04100004, 0x04000804, 0x04100804,
|
1838 |
-
0x04000004, 0x04100004, 0x04000804, 0x04100804,
|
1839 |
-
0x00000200, 0x00100200, 0x00000A00, 0x00100A00,
|
1840 |
-
0x00000200, 0x00100200, 0x00000A00, 0x00100A00,
|
1841 |
-
0x04000200, 0x04100200, 0x04000A00, 0x04100A00,
|
1842 |
-
0x04000200, 0x04100200, 0x04000A00, 0x04100A00,
|
1843 |
-
0x00000204, 0x00100204, 0x00000A04, 0x00100A04,
|
1844 |
-
0x00000204, 0x00100204, 0x00000A04, 0x00100A04,
|
1845 |
-
0x04000204, 0x04100204, 0x04000A04, 0x04100A04,
|
1846 |
-
0x04000204, 0x04100204, 0x04000A04, 0x04100A04,
|
1847 |
-
0x00000200, 0x00100200, 0x00000A00, 0x00100A00,
|
1848 |
-
0x00000200, 0x00100200, 0x00000A00, 0x00100A00,
|
1849 |
-
0x04000200, 0x04100200, 0x04000A00, 0x04100A00,
|
1850 |
-
0x04000200, 0x04100200, 0x04000A00, 0x04100A00,
|
1851 |
-
0x00000204, 0x00100204, 0x00000A04, 0x00100A04,
|
1852 |
-
0x00000204, 0x00100204, 0x00000A04, 0x00100A04,
|
1853 |
-
0x04000204, 0x04100204, 0x04000A04, 0x04100A04,
|
1854 |
-
0x04000204, 0x04100204, 0x04000A04, 0x04100A04,
|
1855 |
-
0x00020000, 0x00120000, 0x00020800, 0x00120800,
|
1856 |
-
0x00020000, 0x00120000, 0x00020800, 0x00120800,
|
1857 |
-
0x04020000, 0x04120000, 0x04020800, 0x04120800,
|
1858 |
-
0x04020000, 0x04120000, 0x04020800, 0x04120800,
|
1859 |
-
0x00020004, 0x00120004, 0x00020804, 0x00120804,
|
1860 |
-
0x00020004, 0x00120004, 0x00020804, 0x00120804,
|
1861 |
-
0x04020004, 0x04120004, 0x04020804, 0x04120804,
|
1862 |
-
0x04020004, 0x04120004, 0x04020804, 0x04120804,
|
1863 |
-
0x00020000, 0x00120000, 0x00020800, 0x00120800,
|
1864 |
-
0x00020000, 0x00120000, 0x00020800, 0x00120800,
|
1865 |
-
0x04020000, 0x04120000, 0x04020800, 0x04120800,
|
1866 |
-
0x04020000, 0x04120000, 0x04020800, 0x04120800,
|
1867 |
-
0x00020004, 0x00120004, 0x00020804, 0x00120804,
|
1868 |
-
0x00020004, 0x00120004, 0x00020804, 0x00120804,
|
1869 |
-
0x04020004, 0x04120004, 0x04020804, 0x04120804,
|
1870 |
-
0x04020004, 0x04120004, 0x04020804, 0x04120804,
|
1871 |
-
0x00020200, 0x00120200, 0x00020A00, 0x00120A00,
|
1872 |
-
0x00020200, 0x00120200, 0x00020A00, 0x00120A00,
|
1873 |
-
0x04020200, 0x04120200, 0x04020A00, 0x04120A00,
|
1874 |
-
0x04020200, 0x04120200, 0x04020A00, 0x04120A00,
|
1875 |
-
0x00020204, 0x00120204, 0x00020A04, 0x00120A04,
|
1876 |
-
0x00020204, 0x00120204, 0x00020A04, 0x00120A04,
|
1877 |
-
0x04020204, 0x04120204, 0x04020A04, 0x04120A04,
|
1878 |
-
0x04020204, 0x04120204, 0x04020A04, 0x04120A04,
|
1879 |
-
0x00020200, 0x00120200, 0x00020A00, 0x00120A00,
|
1880 |
-
0x00020200, 0x00120200, 0x00020A00, 0x00120A00,
|
1881 |
-
0x04020200, 0x04120200, 0x04020A00, 0x04120A00,
|
1882 |
-
0x04020200, 0x04120200, 0x04020A00, 0x04120A00,
|
1883 |
-
0x00020204, 0x00120204, 0x00020A04, 0x00120A04,
|
1884 |
-
0x00020204, 0x00120204, 0x00020A04, 0x00120A04,
|
1885 |
-
0x04020204, 0x04120204, 0x04020A04, 0x04120A04,
|
1886 |
-
0x04020204, 0x04120204, 0x04020A04, 0x04120A04
|
1887 |
-
);
|
1888 |
-
static $pc2mapd3 = array(
|
1889 |
-
0x00000000, 0x00010000, 0x02000000, 0x02010000,
|
1890 |
-
0x00000020, 0x00010020, 0x02000020, 0x02010020,
|
1891 |
-
0x00040000, 0x00050000, 0x02040000, 0x02050000,
|
1892 |
-
0x00040020, 0x00050020, 0x02040020, 0x02050020,
|
1893 |
-
0x00002000, 0x00012000, 0x02002000, 0x02012000,
|
1894 |
-
0x00002020, 0x00012020, 0x02002020, 0x02012020,
|
1895 |
-
0x00042000, 0x00052000, 0x02042000, 0x02052000,
|
1896 |
-
0x00042020, 0x00052020, 0x02042020, 0x02052020,
|
1897 |
-
0x00000000, 0x00010000, 0x02000000, 0x02010000,
|
1898 |
-
0x00000020, 0x00010020, 0x02000020, 0x02010020,
|
1899 |
-
0x00040000, 0x00050000, 0x02040000, 0x02050000,
|
1900 |
-
0x00040020, 0x00050020, 0x02040020, 0x02050020,
|
1901 |
-
0x00002000, 0x00012000, 0x02002000, 0x02012000,
|
1902 |
-
0x00002020, 0x00012020, 0x02002020, 0x02012020,
|
1903 |
-
0x00042000, 0x00052000, 0x02042000, 0x02052000,
|
1904 |
-
0x00042020, 0x00052020, 0x02042020, 0x02052020,
|
1905 |
-
0x00000010, 0x00010010, 0x02000010, 0x02010010,
|
1906 |
-
0x00000030, 0x00010030, 0x02000030, 0x02010030,
|
1907 |
-
0x00040010, 0x00050010, 0x02040010, 0x02050010,
|
1908 |
-
0x00040030, 0x00050030, 0x02040030, 0x02050030,
|
1909 |
-
0x00002010, 0x00012010, 0x02002010, 0x02012010,
|
1910 |
-
0x00002030, 0x00012030, 0x02002030, 0x02012030,
|
1911 |
-
0x00042010, 0x00052010, 0x02042010, 0x02052010,
|
1912 |
-
0x00042030, 0x00052030, 0x02042030, 0x02052030,
|
1913 |
-
0x00000010, 0x00010010, 0x02000010, 0x02010010,
|
1914 |
-
0x00000030, 0x00010030, 0x02000030, 0x02010030,
|
1915 |
-
0x00040010, 0x00050010, 0x02040010, 0x02050010,
|
1916 |
-
0x00040030, 0x00050030, 0x02040030, 0x02050030,
|
1917 |
-
0x00002010, 0x00012010, 0x02002010, 0x02012010,
|
1918 |
-
0x00002030, 0x00012030, 0x02002030, 0x02012030,
|
1919 |
-
0x00042010, 0x00052010, 0x02042010, 0x02052010,
|
1920 |
-
0x00042030, 0x00052030, 0x02042030, 0x02052030,
|
1921 |
-
0x20000000, 0x20010000, 0x22000000, 0x22010000,
|
1922 |
-
0x20000020, 0x20010020, 0x22000020, 0x22010020,
|
1923 |
-
0x20040000, 0x20050000, 0x22040000, 0x22050000,
|
1924 |
-
0x20040020, 0x20050020, 0x22040020, 0x22050020,
|
1925 |
-
0x20002000, 0x20012000, 0x22002000, 0x22012000,
|
1926 |
-
0x20002020, 0x20012020, 0x22002020, 0x22012020,
|
1927 |
-
0x20042000, 0x20052000, 0x22042000, 0x22052000,
|
1928 |
-
0x20042020, 0x20052020, 0x22042020, 0x22052020,
|
1929 |
-
0x20000000, 0x20010000, 0x22000000, 0x22010000,
|
1930 |
-
0x20000020, 0x20010020, 0x22000020, 0x22010020,
|
1931 |
-
0x20040000, 0x20050000, 0x22040000, 0x22050000,
|
1932 |
-
0x20040020, 0x20050020, 0x22040020, 0x22050020,
|
1933 |
-
0x20002000, 0x20012000, 0x22002000, 0x22012000,
|
1934 |
-
0x20002020, 0x20012020, 0x22002020, 0x22012020,
|
1935 |
-
0x20042000, 0x20052000, 0x22042000, 0x22052000,
|
1936 |
-
0x20042020, 0x20052020, 0x22042020, 0x22052020,
|
1937 |
-
0x20000010, 0x20010010, 0x22000010, 0x22010010,
|
1938 |
-
0x20000030, 0x20010030, 0x22000030, 0x22010030,
|
1939 |
-
0x20040010, 0x20050010, 0x22040010, 0x22050010,
|
1940 |
-
0x20040030, 0x20050030, 0x22040030, 0x22050030,
|
1941 |
-
0x20002010, 0x20012010, 0x22002010, 0x22012010,
|
1942 |
-
0x20002030, 0x20012030, 0x22002030, 0x22012030,
|
1943 |
-
0x20042010, 0x20052010, 0x22042010, 0x22052010,
|
1944 |
-
0x20042030, 0x20052030, 0x22042030, 0x22052030,
|
1945 |
-
0x20000010, 0x20010010, 0x22000010, 0x22010010,
|
1946 |
-
0x20000030, 0x20010030, 0x22000030, 0x22010030,
|
1947 |
-
0x20040010, 0x20050010, 0x22040010, 0x22050010,
|
1948 |
-
0x20040030, 0x20050030, 0x22040030, 0x22050030,
|
1949 |
-
0x20002010, 0x20012010, 0x22002010, 0x22012010,
|
1950 |
-
0x20002030, 0x20012030, 0x22002030, 0x22012030,
|
1951 |
-
0x20042010, 0x20052010, 0x22042010, 0x22052010,
|
1952 |
-
0x20042030, 0x20052030, 0x22042030, 0x22052030
|
1953 |
-
);
|
1954 |
-
static $pc2mapd4 = array(
|
1955 |
-
0x00000000, 0x00000400, 0x01000000, 0x01000400,
|
1956 |
-
0x00000000, 0x00000400, 0x01000000, 0x01000400,
|
1957 |
-
0x00000100, 0x00000500, 0x01000100, 0x01000500,
|
1958 |
-
0x00000100, 0x00000500, 0x01000100, 0x01000500,
|
1959 |
-
0x10000000, 0x10000400, 0x11000000, 0x11000400,
|
1960 |
-
0x10000000, 0x10000400, 0x11000000, 0x11000400,
|
1961 |
-
0x10000100, 0x10000500, 0x11000100, 0x11000500,
|
1962 |
-
0x10000100, 0x10000500, 0x11000100, 0x11000500,
|
1963 |
-
0x00080000, 0x00080400, 0x01080000, 0x01080400,
|
1964 |
-
0x00080000, 0x00080400, 0x01080000, 0x01080400,
|
1965 |
-
0x00080100, 0x00080500, 0x01080100, 0x01080500,
|
1966 |
-
0x00080100, 0x00080500, 0x01080100, 0x01080500,
|
1967 |
-
0x10080000, 0x10080400, 0x11080000, 0x11080400,
|
1968 |
-
0x10080000, 0x10080400, 0x11080000, 0x11080400,
|
1969 |
-
0x10080100, 0x10080500, 0x11080100, 0x11080500,
|
1970 |
-
0x10080100, 0x10080500, 0x11080100, 0x11080500,
|
1971 |
-
0x00000008, 0x00000408, 0x01000008, 0x01000408,
|
1972 |
-
0x00000008, 0x00000408, 0x01000008, 0x01000408,
|
1973 |
-
0x00000108, 0x00000508, 0x01000108, 0x01000508,
|
1974 |
-
0x00000108, 0x00000508, 0x01000108, 0x01000508,
|
1975 |
-
0x10000008, 0x10000408, 0x11000008, 0x11000408,
|
1976 |
-
0x10000008, 0x10000408, 0x11000008, 0x11000408,
|
1977 |
-
0x10000108, 0x10000508, 0x11000108, 0x11000508,
|
1978 |
-
0x10000108, 0x10000508, 0x11000108, 0x11000508,
|
1979 |
-
0x00080008, 0x00080408, 0x01080008, 0x01080408,
|
1980 |
-
0x00080008, 0x00080408, 0x01080008, 0x01080408,
|
1981 |
-
0x00080108, 0x00080508, 0x01080108, 0x01080508,
|
1982 |
-
0x00080108, 0x00080508, 0x01080108, 0x01080508,
|
1983 |
-
0x10080008, 0x10080408, 0x11080008, 0x11080408,
|
1984 |
-
0x10080008, 0x10080408, 0x11080008, 0x11080408,
|
1985 |
-
0x10080108, 0x10080508, 0x11080108, 0x11080508,
|
1986 |
-
0x10080108, 0x10080508, 0x11080108, 0x11080508,
|
1987 |
-
0x00001000, 0x00001400, 0x01001000, 0x01001400,
|
1988 |
-
0x00001000, 0x00001400, 0x01001000, 0x01001400,
|
1989 |
-
0x00001100, 0x00001500, 0x01001100, 0x01001500,
|
1990 |
-
0x00001100, 0x00001500, 0x01001100, 0x01001500,
|
1991 |
-
0x10001000, 0x10001400, 0x11001000, 0x11001400,
|
1992 |
-
0x10001000, 0x10001400, 0x11001000, 0x11001400,
|
1993 |
-
0x10001100, 0x10001500, 0x11001100, 0x11001500,
|
1994 |
-
0x10001100, 0x10001500, 0x11001100, 0x11001500,
|
1995 |
-
0x00081000, 0x00081400, 0x01081000, 0x01081400,
|
1996 |
-
0x00081000, 0x00081400, 0x01081000, 0x01081400,
|
1997 |
-
0x00081100, 0x00081500, 0x01081100, 0x01081500,
|
1998 |
-
0x00081100, 0x00081500, 0x01081100, 0x01081500,
|
1999 |
-
0x10081000, 0x10081400, 0x11081000, 0x11081400,
|
2000 |
-
0x10081000, 0x10081400, 0x11081000, 0x11081400,
|
2001 |
-
0x10081100, 0x10081500, 0x11081100, 0x11081500,
|
2002 |
-
0x10081100, 0x10081500, 0x11081100, 0x11081500,
|
2003 |
-
0x00001008, 0x00001408, 0x01001008, 0x01001408,
|
2004 |
-
0x00001008, 0x00001408, 0x01001008, 0x01001408,
|
2005 |
-
0x00001108, 0x00001508, 0x01001108, 0x01001508,
|
2006 |
-
0x00001108, 0x00001508, 0x01001108, 0x01001508,
|
2007 |
-
0x10001008, 0x10001408, 0x11001008, 0x11001408,
|
2008 |
-
0x10001008, 0x10001408, 0x11001008, 0x11001408,
|
2009 |
-
0x10001108, 0x10001508, 0x11001108, 0x11001508,
|
2010 |
-
0x10001108, 0x10001508, 0x11001108, 0x11001508,
|
2011 |
-
0x00081008, 0x00081408, 0x01081008, 0x01081408,
|
2012 |
-
0x00081008, 0x00081408, 0x01081008, 0x01081408,
|
2013 |
-
0x00081108, 0x00081508, 0x01081108, 0x01081508,
|
2014 |
-
0x00081108, 0x00081508, 0x01081108, 0x01081508,
|
2015 |
-
0x10081008, 0x10081408, 0x11081008, 0x11081408,
|
2016 |
-
0x10081008, 0x10081408, 0x11081008, 0x11081408,
|
2017 |
-
0x10081108, 0x10081508, 0x11081108, 0x11081508,
|
2018 |
-
0x10081108, 0x10081508, 0x11081108, 0x11081508
|
2019 |
-
);
|
2020 |
-
|
2021 |
-
// pad the key and remove extra characters as appropriate.
|
2022 |
-
$key = str_pad(substr($key, 0, 8), 8, chr(0));
|
2023 |
-
|
2024 |
-
// Perform the PC/1 transformation and compute C and D.
|
2025 |
-
$t = unpack('Nl/Nr', $key);
|
2026 |
-
list($l, $r) = array($t['l'], $t['r']);
|
2027 |
-
$key = ($this->shuffle[$pc1map[$r & 0xFF]] & "\x80\x80\x80\x80\x80\x80\x80\x00") |
|
2028 |
-
($this->shuffle[$pc1map[($r >> 8) & 0xFF]] & "\x40\x40\x40\x40\x40\x40\x40\x00") |
|
2029 |
-
($this->shuffle[$pc1map[($r >> 16) & 0xFF]] & "\x20\x20\x20\x20\x20\x20\x20\x00") |
|
2030 |
-
($this->shuffle[$pc1map[($r >> 24) & 0xFF]] & "\x10\x10\x10\x10\x10\x10\x10\x00") |
|
2031 |
-
($this->shuffle[$pc1map[$l & 0xFF]] & "\x08\x08\x08\x08\x08\x08\x08\x00") |
|
2032 |
-
($this->shuffle[$pc1map[($l >> 8) & 0xFF]] & "\x04\x04\x04\x04\x04\x04\x04\x00") |
|
2033 |
-
($this->shuffle[$pc1map[($l >> 16) & 0xFF]] & "\x02\x02\x02\x02\x02\x02\x02\x00") |
|
2034 |
-
($this->shuffle[$pc1map[($l >> 24) & 0xFF]] & "\x01\x01\x01\x01\x01\x01\x01\x00");
|
2035 |
-
$key = unpack('Nc/Nd', $key);
|
2036 |
-
$c = ($key['c'] >> 4) & 0x0FFFFFFF;
|
2037 |
-
$d = (($key['d'] >> 4) & 0x0FFFFFF0) | ($key['c'] & 0x0F);
|
2038 |
-
|
2039 |
-
$keys = array();
|
2040 |
-
for ($i = 0; $i < 16; $i++) {
|
2041 |
-
$c <<= $shifts[$i];
|
2042 |
-
$c = ($c | ($c >> 28)) & 0x0FFFFFFF;
|
2043 |
-
$d <<= $shifts[$i];
|
2044 |
-
$d = ($d | ($d >> 28)) & 0x0FFFFFFF;
|
2045 |
-
|
2046 |
-
// Perform the PC-2 transformation.
|
2047 |
-
$cp = $pc2mapc1[$c >> 24] | $pc2mapc2[($c >> 16) & 0xFF] |
|
2048 |
-
$pc2mapc3[($c >> 8) & 0xFF] | $pc2mapc4[$c & 0xFF];
|
2049 |
-
$dp = $pc2mapd1[$d >> 24] | $pc2mapd2[($d >> 16) & 0xFF] |
|
2050 |
-
$pc2mapd3[($d >> 8) & 0xFF] | $pc2mapd4[$d & 0xFF];
|
2051 |
-
|
2052 |
-
// Reorder: odd bytes/even bytes. Push the result in key schedule.
|
2053 |
-
$keys[] = array(
|
2054 |
-
($cp & 0xFF000000) | (($cp << 8) & 0x00FF0000) |
|
2055 |
-
(($dp >> 16) & 0x0000FF00) | (($dp >> 8) & 0x000000FF),
|
2056 |
-
(($cp << 8) & 0xFF000000) | (($cp << 16) & 0x00FF0000) |
|
2057 |
-
(($dp >> 8) & 0x0000FF00) | ($dp & 0x000000FF)
|
2058 |
-
);
|
2059 |
-
}
|
2060 |
-
|
2061 |
-
$keys = array(
|
2062 |
-
CRYPT_DES_ENCRYPT => $keys,
|
2063 |
-
CRYPT_DES_DECRYPT => array_reverse($keys),
|
2064 |
-
CRYPT_DES_ENCRYPT_1DIM => array(),
|
2065 |
-
CRYPT_DES_DECRYPT_1DIM => array()
|
2066 |
-
);
|
2067 |
-
|
2068 |
-
// Generate 1-dim arrays for inline en/decrypting
|
2069 |
-
for ($i = 0; $i < 16; ++$i) {
|
2070 |
-
$keys[CRYPT_DES_ENCRYPT_1DIM][] = $keys[CRYPT_DES_ENCRYPT][$i][0];
|
2071 |
-
$keys[CRYPT_DES_ENCRYPT_1DIM][] = $keys[CRYPT_DES_ENCRYPT][$i][1];
|
2072 |
-
$keys[CRYPT_DES_DECRYPT_1DIM][] = $keys[CRYPT_DES_DECRYPT][$i][0];
|
2073 |
-
$keys[CRYPT_DES_DECRYPT_1DIM][] = $keys[CRYPT_DES_DECRYPT][$i][1];
|
2074 |
-
}
|
2075 |
-
|
2076 |
-
return $keys;
|
2077 |
-
}
|
2078 |
-
|
2079 |
-
/**
|
2080 |
-
* String Shift
|
2081 |
-
*
|
2082 |
-
* Inspired by array_shift
|
2083 |
-
*
|
2084 |
-
* @param String $string
|
2085 |
-
* @return String
|
2086 |
-
* @access private
|
2087 |
-
*/
|
2088 |
-
function _string_shift(&$string)
|
2089 |
-
{
|
2090 |
-
$substr = substr($string, 0, 8);
|
2091 |
-
$string = substr($string, 8);
|
2092 |
-
return $substr;
|
2093 |
-
}
|
2094 |
-
|
2095 |
-
/**
|
2096 |
-
* Creates performance-optimized function for de/encrypt(), storing it in $this->inline_crypt
|
2097 |
-
*
|
2098 |
-
* @param optional Integer $des_rounds (1 = DES[default], 3 = TribleDES)
|
2099 |
-
* @access private
|
2100 |
-
*/
|
2101 |
-
function inline_crypt_setup($des_rounds = 1)
|
2102 |
-
{
|
2103 |
-
$lambda_functions =& Crypt_DES::get_lambda_functions();
|
2104 |
-
$block_size = 8;
|
2105 |
-
$mode = $this->mode;
|
2106 |
-
|
2107 |
-
$code_hash = "$mode,$des_rounds";
|
2108 |
-
|
2109 |
-
if (!isset($lambda_functions[$code_hash])) {
|
2110 |
-
// Generating encrypt code:
|
2111 |
-
$ki = -1;
|
2112 |
-
$init_cryptBlock = '
|
2113 |
-
$shuffle = $self->shuffle;
|
2114 |
-
$invipmap = $self->invipmap;
|
2115 |
-
$ipmap = $self->ipmap;
|
2116 |
-
$sbox1 = $self->sbox1;
|
2117 |
-
$sbox2 = $self->sbox2;
|
2118 |
-
$sbox3 = $self->sbox3;
|
2119 |
-
$sbox4 = $self->sbox4;
|
2120 |
-
$sbox5 = $self->sbox5;
|
2121 |
-
$sbox6 = $self->sbox6;
|
2122 |
-
$sbox7 = $self->sbox7;
|
2123 |
-
$sbox8 = $self->sbox8;
|
2124 |
-
';
|
2125 |
-
|
2126 |
-
$_cryptBlock = '$in = unpack("N*", $in);'."\n";
|
2127 |
-
// Do the initial IP permutation.
|
2128 |
-
$_cryptBlock .= '
|
2129 |
-
$l = $in[1];
|
2130 |
-
$r = $in[2];
|
2131 |
-
$in = unpack("N*",
|
2132 |
-
($shuffle[$ipmap[ $r & 0xFF]] & "\x80\x80\x80\x80\x80\x80\x80\x80") |
|
2133 |
-
($shuffle[$ipmap[($r >> 8) & 0xFF]] & "\x40\x40\x40\x40\x40\x40\x40\x40") |
|
2134 |
-
($shuffle[$ipmap[($r >> 16) & 0xFF]] & "\x20\x20\x20\x20\x20\x20\x20\x20") |
|
2135 |
-
($shuffle[$ipmap[($r >> 24) & 0xFF]] & "\x10\x10\x10\x10\x10\x10\x10\x10") |
|
2136 |
-
($shuffle[$ipmap[ $l & 0xFF]] & "\x08\x08\x08\x08\x08\x08\x08\x08") |
|
2137 |
-
($shuffle[$ipmap[($l >> 8) & 0xFF]] & "\x04\x04\x04\x04\x04\x04\x04\x04") |
|
2138 |
-
($shuffle[$ipmap[($l >> 16) & 0xFF]] & "\x02\x02\x02\x02\x02\x02\x02\x02") |
|
2139 |
-
($shuffle[$ipmap[($l >> 24) & 0xFF]] & "\x01\x01\x01\x01\x01\x01\x01\x01")
|
2140 |
-
);
|
2141 |
-
|
2142 |
-
'.'' /* Extract L0 and R0 */ .'
|
2143 |
-
$l = $in[1];
|
2144 |
-
$r = $in[2];
|
2145 |
-
';
|
2146 |
-
|
2147 |
-
$l = 'l';
|
2148 |
-
$r = 'r';
|
2149 |
-
for ($des_round = 0; $des_round < $des_rounds; ++$des_round) {
|
2150 |
-
// Perform the 16 steps.
|
2151 |
-
// start of "the Feistel (F) function" - see the following URL:
|
2152 |
-
// http://en.wikipedia.org/wiki/Image:Data_Encryption_Standard_InfoBox_Diagram.png
|
2153 |
-
// Merge key schedule.
|
2154 |
-
for ($i = 0; $i < 8; ++$i) {
|
2155 |
-
$_cryptBlock .= '
|
2156 |
-
$b1 = (($' . $r . ' >> 3) & 0x1FFFFFFF) ^ ($' . $r . ' << 29) ^ $k_'.(++$ki).';
|
2157 |
-
$b2 = (($' . $r . ' >> 31) & 0x00000001) ^ ($' . $r . ' << 1) ^ $k_'.(++$ki).';
|
2158 |
-
$' . $l . ' = $sbox1[($b1 >> 24) & 0x3F] ^ $sbox2[($b2 >> 24) & 0x3F] ^
|
2159 |
-
$sbox3[($b1 >> 16) & 0x3F] ^ $sbox4[($b2 >> 16) & 0x3F] ^
|
2160 |
-
$sbox5[($b1 >> 8) & 0x3F] ^ $sbox6[($b2 >> 8) & 0x3F] ^
|
2161 |
-
$sbox7[ $b1 & 0x3F] ^ $sbox8[ $b2 & 0x3F] ^ $' . $l . ';
|
2162 |
-
|
2163 |
-
$b1 = (($' . $l . ' >> 3) & 0x1FFFFFFF) ^ ($' . $l . ' << 29) ^ $k_'.(++$ki).';
|
2164 |
-
$b2 = (($' . $l . ' >> 31) & 0x00000001) ^ ($' . $l . ' << 1) ^ $k_'.(++$ki).';
|
2165 |
-
$' . $r . ' = $sbox1[($b1 >> 24) & 0x3F] ^ $sbox2[($b2 >> 24) & 0x3F] ^
|
2166 |
-
$sbox3[($b1 >> 16) & 0x3F] ^ $sbox4[($b2 >> 16) & 0x3F] ^
|
2167 |
-
$sbox5[($b1 >> 8) & 0x3F] ^ $sbox6[($b2 >> 8) & 0x3F] ^
|
2168 |
-
$sbox7[ $b1 & 0x3F] ^ $sbox8[ $b2 & 0x3F] ^ $' . $r . ';
|
2169 |
-
';
|
2170 |
-
}
|
2171 |
-
|
2172 |
-
// Last step should not permute L & R.
|
2173 |
-
$t = $l;
|
2174 |
-
$l = $r;
|
2175 |
-
$r = $t;
|
2176 |
-
}
|
2177 |
-
|
2178 |
-
// Perform the inverse IP permutation.
|
2179 |
-
$_cryptBlock .= '$in = (
|
2180 |
-
($shuffle[$invipmap[($' . $r . ' >> 24) & 0xFF]] & "\x80\x80\x80\x80\x80\x80\x80\x80") |
|
2181 |
-
($shuffle[$invipmap[($' . $l . ' >> 24) & 0xFF]] & "\x40\x40\x40\x40\x40\x40\x40\x40") |
|
2182 |
-
($shuffle[$invipmap[($' . $r . ' >> 16) & 0xFF]] & "\x20\x20\x20\x20\x20\x20\x20\x20") |
|
2183 |
-
($shuffle[$invipmap[($' . $l . ' >> 16) & 0xFF]] & "\x10\x10\x10\x10\x10\x10\x10\x10") |
|
2184 |
-
($shuffle[$invipmap[($' . $r . ' >> 8) & 0xFF]] & "\x08\x08\x08\x08\x08\x08\x08\x08") |
|
2185 |
-
($shuffle[$invipmap[($' . $l . ' >> 8) & 0xFF]] & "\x04\x04\x04\x04\x04\x04\x04\x04") |
|
2186 |
-
($shuffle[$invipmap[ $' . $r . ' & 0xFF]] & "\x02\x02\x02\x02\x02\x02\x02\x02") |
|
2187 |
-
($shuffle[$invipmap[ $' . $l . ' & 0xFF]] & "\x01\x01\x01\x01\x01\x01\x01\x01")
|
2188 |
-
);
|
2189 |
-
';
|
2190 |
-
|
2191 |
-
// Generating mode of operation code:
|
2192 |
-
switch ($mode) {
|
2193 |
-
case CRYPT_DES_MODE_ECB:
|
2194 |
-
$encrypt = $init_cryptBlock . '
|
2195 |
-
extract($self->keys[CRYPT_DES_ENCRYPT_1DIM], EXTR_PREFIX_ALL, "k");
|
2196 |
-
$ciphertext = "";
|
2197 |
-
$plaintext_len = strlen($text);
|
2198 |
-
|
2199 |
-
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
|
2200 |
-
$in = substr($text, $i, '.$block_size.');
|
2201 |
-
'.$_cryptBlock.'
|
2202 |
-
$ciphertext.= $in;
|
2203 |
-
}
|
2204 |
-
|
2205 |
-
return $ciphertext;
|
2206 |
-
';
|
2207 |
-
|
2208 |
-
$decrypt = $init_cryptBlock . '
|
2209 |
-
extract($self->keys[CRYPT_DES_DECRYPT_1DIM], EXTR_PREFIX_ALL, "k");
|
2210 |
-
$plaintext = "";
|
2211 |
-
$ciphertext_len = strlen($text);
|
2212 |
-
|
2213 |
-
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') {
|
2214 |
-
$in = substr($text, $i, '.$block_size.');
|
2215 |
-
'.$_cryptBlock.'
|
2216 |
-
$plaintext.= $in;
|
2217 |
-
}
|
2218 |
-
|
2219 |
-
return $self->_unpad($plaintext);
|
2220 |
-
';
|
2221 |
-
break;
|
2222 |
-
case CRYPT_DES_MODE_CBC:
|
2223 |
-
$encrypt = $init_cryptBlock . '
|
2224 |
-
extract($self->keys[CRYPT_DES_ENCRYPT_1DIM], EXTR_PREFIX_ALL, "k");
|
2225 |
-
$ciphertext = "";
|
2226 |
-
$plaintext_len = strlen($text);
|
2227 |
-
|
2228 |
-
$in = $self->encryptIV;
|
2229 |
-
|
2230 |
-
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
|
2231 |
-
$in = substr($text, $i, '.$block_size.') ^ $in;
|
2232 |
-
'.$_cryptBlock.'
|
2233 |
-
$ciphertext.= $in;
|
2234 |
-
}
|
2235 |
-
|
2236 |
-
if ($self->continuousBuffer) {
|
2237 |
-
$self->encryptIV = $in;
|
2238 |
-
}
|
2239 |
-
|
2240 |
-
return $ciphertext;
|
2241 |
-
';
|
2242 |
-
|
2243 |
-
$decrypt = $init_cryptBlock . '
|
2244 |
-
extract($self->keys[CRYPT_DES_DECRYPT_1DIM], EXTR_PREFIX_ALL, "k");
|
2245 |
-
$plaintext = "";
|
2246 |
-
$ciphertext_len = strlen($text);
|
2247 |
-
|
2248 |
-
$iv = $self->decryptIV;
|
2249 |
-
|
2250 |
-
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') {
|
2251 |
-
$in = $block = substr($text, $i, '.$block_size.');
|
2252 |
-
'.$_cryptBlock.'
|
2253 |
-
$plaintext.= $in ^ $iv;
|
2254 |
-
$iv = $block;
|
2255 |
-
}
|
2256 |
-
|
2257 |
-
if ($self->continuousBuffer) {
|
2258 |
-
$self->decryptIV = $iv;
|
2259 |
-
}
|
2260 |
-
|
2261 |
-
return $self->_unpad($plaintext);
|
2262 |
-
';
|
2263 |
-
break;
|
2264 |
-
case CRYPT_DES_MODE_CTR:
|
2265 |
-
$encrypt = $init_cryptBlock . '
|
2266 |
-
extract($self->keys[CRYPT_DES_ENCRYPT_1DIM], EXTR_PREFIX_ALL, "k");
|
2267 |
-
$ciphertext = "";
|
2268 |
-
$plaintext_len = strlen($text);
|
2269 |
-
$xor = $self->encryptIV;
|
2270 |
-
$buffer = &$self->enbuffer;
|
2271 |
-
|
2272 |
-
if (strlen($buffer["encrypted"])) {
|
2273 |
-
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
|
2274 |
-
$block = substr($text, $i, '.$block_size.');
|
2275 |
-
if (strlen($block) > strlen($buffer["encrypted"])) {
|
2276 |
-
$in = $self->_generate_xor($xor);
|
2277 |
-
'.$_cryptBlock.'
|
2278 |
-
$buffer["encrypted"].= $in;
|
2279 |
-
}
|
2280 |
-
$key = $self->_string_shift($buffer["encrypted"]);
|
2281 |
-
$ciphertext.= $block ^ $key;
|
2282 |
-
}
|
2283 |
-
} else {
|
2284 |
-
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
|
2285 |
-
$block = substr($text, $i, '.$block_size.');
|
2286 |
-
$in = $self->_generate_xor($xor);
|
2287 |
-
'.$_cryptBlock.'
|
2288 |
-
$key = $in;
|
2289 |
-
$ciphertext.= $block ^ $key;
|
2290 |
-
}
|
2291 |
-
}
|
2292 |
-
if ($self->continuousBuffer) {
|
2293 |
-
$self->encryptIV = $xor;
|
2294 |
-
if ($start = $plaintext_len % '.$block_size.') {
|
2295 |
-
$buffer["encrypted"] = substr($key, $start) . $buffer["encrypted"];
|
2296 |
-
}
|
2297 |
-
}
|
2298 |
-
|
2299 |
-
return $ciphertext;
|
2300 |
-
';
|
2301 |
-
|
2302 |
-
$decrypt = $init_cryptBlock . '
|
2303 |
-
extract($self->keys[CRYPT_DES_ENCRYPT_1DIM], EXTR_PREFIX_ALL, "k");
|
2304 |
-
$plaintext = "";
|
2305 |
-
$ciphertext_len = strlen($text);
|
2306 |
-
$xor = $self->decryptIV;
|
2307 |
-
$buffer = &$self->debuffer;
|
2308 |
-
|
2309 |
-
if (strlen($buffer["ciphertext"])) {
|
2310 |
-
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') {
|
2311 |
-
$block = substr($text, $i, '.$block_size.');
|
2312 |
-
if (strlen($block) > strlen($buffer["ciphertext"])) {
|
2313 |
-
$in = $self->_generate_xor($xor);
|
2314 |
-
'.$_cryptBlock.'
|
2315 |
-
$buffer["ciphertext"].= $in;
|
2316 |
-
}
|
2317 |
-
$key = $self->_string_shift($buffer["ciphertext"]);
|
2318 |
-
$plaintext.= $block ^ $key;
|
2319 |
-
}
|
2320 |
-
} else {
|
2321 |
-
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') {
|
2322 |
-
$block = substr($text, $i, '.$block_size.');
|
2323 |
-
$in = $self->_generate_xor($xor);
|
2324 |
-
'.$_cryptBlock.'
|
2325 |
-
$key = $in;
|
2326 |
-
$plaintext.= $block ^ $key;
|
2327 |
-
}
|
2328 |
-
}
|
2329 |
-
if ($self->continuousBuffer) {
|
2330 |
-
$self->decryptIV = $xor;
|
2331 |
-
if ($start = $ciphertext_len % '.$block_size.') {
|
2332 |
-
$buffer["ciphertext"] = substr($key, $start) . $buffer["ciphertext"];
|
2333 |
-
}
|
2334 |
-
}
|
2335 |
-
|
2336 |
-
return $plaintext;
|
2337 |
-
';
|
2338 |
-
break;
|
2339 |
-
case CRYPT_DES_MODE_CFB:
|
2340 |
-
$encrypt = $init_cryptBlock . '
|
2341 |
-
extract($self->keys[CRYPT_DES_ENCRYPT_1DIM], EXTR_PREFIX_ALL, "k");
|
2342 |
-
$ciphertext = "";
|
2343 |
-
$buffer = &$self->enbuffer;
|
2344 |
-
|
2345 |
-
if ($self->continuousBuffer) {
|
2346 |
-
$iv = &$self->encryptIV;
|
2347 |
-
$pos = &$buffer["pos"];
|
2348 |
-
} else {
|
2349 |
-
$iv = $self->encryptIV;
|
2350 |
-
$pos = 0;
|
2351 |
-
}
|
2352 |
-
$len = strlen($text);
|
2353 |
-
$i = 0;
|
2354 |
-
if ($pos) {
|
2355 |
-
$orig_pos = $pos;
|
2356 |
-
$max = '.$block_size.' - $pos;
|
2357 |
-
if ($len >= $max) {
|
2358 |
-
$i = $max;
|
2359 |
-
$len-= $max;
|
2360 |
-
$pos = 0;
|
2361 |
-
} else {
|
2362 |
-
$i = $len;
|
2363 |
-
$pos+= $len;
|
2364 |
-
$len = 0;
|
2365 |
-
}
|
2366 |
-
$ciphertext = substr($iv, $orig_pos) ^ $text;
|
2367 |
-
$iv = substr_replace($iv, $ciphertext, $orig_pos, $i);
|
2368 |
-
}
|
2369 |
-
while ($len >= '.$block_size.') {
|
2370 |
-
$in = $iv;
|
2371 |
-
'.$_cryptBlock.';
|
2372 |
-
$iv = $in ^ substr($text, $i, '.$block_size.');
|
2373 |
-
$ciphertext.= $iv;
|
2374 |
-
$len-= '.$block_size.';
|
2375 |
-
$i+= '.$block_size.';
|
2376 |
-
}
|
2377 |
-
if ($len) {
|
2378 |
-
$in = $iv;
|
2379 |
-
'.$_cryptBlock.'
|
2380 |
-
$iv = $in;
|
2381 |
-
$block = $iv ^ substr($text, $i);
|
2382 |
-
$iv = substr_replace($iv, $block, 0, $len);
|
2383 |
-
$ciphertext.= $block;
|
2384 |
-
$pos = $len;
|
2385 |
-
}
|
2386 |
-
return $ciphertext;
|
2387 |
-
';
|
2388 |
-
|
2389 |
-
$decrypt = $init_cryptBlock . '
|
2390 |
-
extract($self->keys[CRYPT_DES_ENCRYPT_1DIM], EXTR_PREFIX_ALL, "k");
|
2391 |
-
$plaintext = "";
|
2392 |
-
$buffer = &$self->debuffer;
|
2393 |
-
|
2394 |
-
if ($self->continuousBuffer) {
|
2395 |
-
$iv = &$self->decryptIV;
|
2396 |
-
$pos = &$buffer["pos"];
|
2397 |
-
} else {
|
2398 |
-
$iv = $self->decryptIV;
|
2399 |
-
$pos = 0;
|
2400 |
-
}
|
2401 |
-
$len = strlen($text);
|
2402 |
-
$i = 0;
|
2403 |
-
if ($pos) {
|
2404 |
-
$orig_pos = $pos;
|
2405 |
-
$max = '.$block_size.' - $pos;
|
2406 |
-
if ($len >= $max) {
|
2407 |
-
$i = $max;
|
2408 |
-
$len-= $max;
|
2409 |
-
$pos = 0;
|
2410 |
-
} else {
|
2411 |
-
$i = $len;
|
2412 |
-
$pos+= $len;
|
2413 |
-
$len = 0;
|
2414 |
-
}
|
2415 |
-
$plaintext = substr($iv, $orig_pos) ^ $text;
|
2416 |
-
$iv = substr_replace($iv, substr($text, 0, $i), $orig_pos, $i);
|
2417 |
-
}
|
2418 |
-
while ($len >= '.$block_size.') {
|
2419 |
-
$in = $iv;
|
2420 |
-
'.$_cryptBlock.'
|
2421 |
-
$iv = $in;
|
2422 |
-
$cb = substr($text, $i, '.$block_size.');
|
2423 |
-
$plaintext.= $iv ^ $cb;
|
2424 |
-
$iv = $cb;
|
2425 |
-
$len-= '.$block_size.';
|
2426 |
-
$i+= '.$block_size.';
|
2427 |
-
}
|
2428 |
-
if ($len) {
|
2429 |
-
$in = $iv;
|
2430 |
-
'.$_cryptBlock.'
|
2431 |
-
$iv = $in;
|
2432 |
-
$plaintext.= $iv ^ substr($text, $i);
|
2433 |
-
$iv = substr_replace($iv, substr($text, $i), 0, $len);
|
2434 |
-
$pos = $len;
|
2435 |
-
}
|
2436 |
-
|
2437 |
-
return $plaintext;
|
2438 |
-
';
|
2439 |
-
break;
|
2440 |
-
case CRYPT_DES_MODE_OFB:
|
2441 |
-
$encrypt = $init_cryptBlock . '
|
2442 |
-
extract($self->keys[CRYPT_DES_ENCRYPT_1DIM], EXTR_PREFIX_ALL, "k");
|
2443 |
-
$ciphertext = "";
|
2444 |
-
$plaintext_len = strlen($text);
|
2445 |
-
$xor = $self->encryptIV;
|
2446 |
-
$buffer = &$self->enbuffer;
|
2447 |
-
|
2448 |
-
if (strlen($buffer["xor"])) {
|
2449 |
-
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
|
2450 |
-
$block = substr($text, $i, '.$block_size.');
|
2451 |
-
if (strlen($block) > strlen($buffer["xor"])) {
|
2452 |
-
$in = $xor;
|
2453 |
-
'.$_cryptBlock.'
|
2454 |
-
$xor = $in;
|
2455 |
-
$buffer["xor"].= $xor;
|
2456 |
-
}
|
2457 |
-
$key = $self->_string_shift($buffer["xor"]);
|
2458 |
-
$ciphertext.= $block ^ $key;
|
2459 |
-
}
|
2460 |
-
} else {
|
2461 |
-
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
|
2462 |
-
$in = $xor;
|
2463 |
-
'.$_cryptBlock.'
|
2464 |
-
$xor = $in;
|
2465 |
-
$ciphertext.= substr($text, $i, '.$block_size.') ^ $xor;
|
2466 |
-
}
|
2467 |
-
$key = $xor;
|
2468 |
-
}
|
2469 |
-
if ($self->continuousBuffer) {
|
2470 |
-
$self->encryptIV = $xor;
|
2471 |
-
if ($start = $plaintext_len % '.$block_size.') {
|
2472 |
-
$buffer["xor"] = substr($key, $start) . $buffer["xor"];
|
2473 |
-
}
|
2474 |
-
}
|
2475 |
-
return $ciphertext;
|
2476 |
-
';
|
2477 |
-
|
2478 |
-
$decrypt = $init_cryptBlock . '
|
2479 |
-
extract($self->keys[CRYPT_DES_ENCRYPT_1DIM], EXTR_PREFIX_ALL, "k");
|
2480 |
-
$plaintext = "";
|
2481 |
-
$ciphertext_len = strlen($text);
|
2482 |
-
$xor = $self->decryptIV;
|
2483 |
-
$buffer = &$self->debuffer;
|
2484 |
-
|
2485 |
-
if (strlen($buffer["xor"])) {
|
2486 |
-
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') {
|
2487 |
-
$block = substr($text, $i, '.$block_size.');
|
2488 |
-
if (strlen($block) > strlen($buffer["xor"])) {
|
2489 |
-
$in = $xor;
|
2490 |
-
'.$_cryptBlock.'
|
2491 |
-
$xor = $in;
|
2492 |
-
$buffer["xor"].= $xor;
|
2493 |
-
}
|
2494 |
-
$key = $self->_string_shift($buffer["xor"]);
|
2495 |
-
$plaintext.= $block ^ $key;
|
2496 |
-
}
|
2497 |
-
} else {
|
2498 |
-
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') {
|
2499 |
-
$in = $xor;
|
2500 |
-
'.$_cryptBlock.'
|
2501 |
-
$xor = $in;
|
2502 |
-
$plaintext.= substr($text, $i, '.$block_size.') ^ $xor;
|
2503 |
-
}
|
2504 |
-
$key = $xor;
|
2505 |
-
}
|
2506 |
-
if ($self->continuousBuffer) {
|
2507 |
-
$self->decryptIV = $xor;
|
2508 |
-
if ($start = $ciphertext_len % '.$block_size.') {
|
2509 |
-
$buffer["xor"] = substr($key, $start) . $buffer["xor"];
|
2510 |
-
}
|
2511 |
-
}
|
2512 |
-
return $plaintext;
|
2513 |
-
';
|
2514 |
-
break;
|
2515 |
-
}
|
2516 |
-
$lambda_functions[$code_hash] = create_function('$action, &$self, $text', 'if ($action == "encrypt") { '.$encrypt.' } else { '.$decrypt.' }');
|
2517 |
-
}
|
2518 |
-
$this->inline_crypt = $lambda_functions[$code_hash];
|
2519 |
-
}
|
2520 |
-
|
2521 |
-
/**
|
2522 |
-
* Holds the lambda_functions table (classwide)
|
2523 |
-
*
|
2524 |
-
* @see inline_crypt_setup()
|
2525 |
-
* @return Array
|
2526 |
-
* @access private
|
2527 |
-
*/
|
2528 |
-
function &get_lambda_functions()
|
2529 |
-
{
|
2530 |
-
static $functions = array();
|
2531 |
-
return $functions;
|
2532 |
-
}
|
2533 |
-
}
|
2534 |
-
|
2535 |
-
// vim: ts=4:sw=4:et:
|
2536 |
-
// vim6: fdl=1:
|
1 |
+
<?php
|
2 |
+
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Pure-PHP implementation of DES.
|
6 |
+
*
|
7 |
+
* Uses mcrypt, if available, and an internal implementation, otherwise.
|
8 |
+
*
|
9 |
+
* PHP versions 4 and 5
|
10 |
+
*
|
11 |
+
* Useful resources are as follows:
|
12 |
+
*
|
13 |
+
* - {@link http://en.wikipedia.org/wiki/DES_supplementary_material Wikipedia: DES supplementary material}
|
14 |
+
* - {@link http://www.itl.nist.gov/fipspubs/fip46-2.htm FIPS 46-2 - (DES), Data Encryption Standard}
|
15 |
+
* - {@link http://www.cs.eku.edu/faculty/styer/460/Encrypt/JS-DES.html JavaScript DES Example}
|
16 |
+
*
|
17 |
+
* Here's a short example of how to use this library:
|
18 |
+
* <code>
|
19 |
+
* <?php
|
20 |
+
* include('Crypt/DES.php');
|
21 |
+
*
|
22 |
+
* $des = new Crypt_DES();
|
23 |
+
*
|
24 |
+
* $des->setKey('abcdefgh');
|
25 |
+
*
|
26 |
+
* $size = 10 * 1024;
|
27 |
+
* $plaintext = '';
|
28 |
+
* for ($i = 0; $i < $size; $i++) {
|
29 |
+
* $plaintext.= 'a';
|
30 |
+
* }
|
31 |
+
*
|
32 |
+
* echo $des->decrypt($des->encrypt($plaintext));
|
33 |
+
* ?>
|
34 |
+
* </code>
|
35 |
+
*
|
36 |
+
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
37 |
+
* of this software and associated documentation files (the "Software"), to deal
|
38 |
+
* in the Software without restriction, including without limitation the rights
|
39 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
40 |
+
* copies of the Software, and to permit persons to whom the Software is
|
41 |
+
* furnished to do so, subject to the following conditions:
|
42 |
+
*
|
43 |
+
* The above copyright notice and this permission notice shall be included in
|
44 |
+
* all copies or substantial portions of the Software.
|
45 |
+
*
|
46 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
47 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
48 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
49 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
50 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
51 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
52 |
+
* THE SOFTWARE.
|
53 |
+
*
|
54 |
+
* @category Crypt
|
55 |
+
* @package Crypt_DES
|
56 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
57 |
+
* @copyright MMVII Jim Wigginton
|
58 |
+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
59 |
+
* @link http://phpseclib.sourceforge.net
|
60 |
+
*/
|
61 |
+
|
62 |
+
/**#@+
|
63 |
+
* @access private
|
64 |
+
* @see Crypt_DES::_prepareKey()
|
65 |
+
* @see Crypt_DES::_processBlock()
|
66 |
+
*/
|
67 |
+
/**
|
68 |
+
* Contains array_reverse($keys[CRYPT_DES_DECRYPT])
|
69 |
+
*/
|
70 |
+
define('CRYPT_DES_ENCRYPT', 0);
|
71 |
+
/**
|
72 |
+
* Contains array_reverse($keys[CRYPT_DES_ENCRYPT])
|
73 |
+
*/
|
74 |
+
define('CRYPT_DES_DECRYPT', 1);
|
75 |
+
/**
|
76 |
+
* Contains $keys[CRYPT_DES_ENCRYPT] as 1-dim array
|
77 |
+
*/
|
78 |
+
define('CRYPT_DES_ENCRYPT_1DIM', 2);
|
79 |
+
/**
|
80 |
+
* Contains $keys[CRYPT_DES_DECRYPT] as 1-dim array
|
81 |
+
*/
|
82 |
+
define('CRYPT_DES_DECRYPT_1DIM', 3);
|
83 |
+
/**#@-*/
|
84 |
+
|
85 |
+
/**#@+
|
86 |
+
* @access public
|
87 |
+
* @see Crypt_DES::encrypt()
|
88 |
+
* @see Crypt_DES::decrypt()
|
89 |
+
*/
|
90 |
+
/**
|
91 |
+
* Encrypt / decrypt using the Counter mode.
|
92 |
+
*
|
93 |
+
* Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
|
94 |
+
*
|
95 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
|
96 |
+
*/
|
97 |
+
define('CRYPT_DES_MODE_CTR', -1);
|
98 |
+
/**
|
99 |
+
* Encrypt / decrypt using the Electronic Code Book mode.
|
100 |
+
*
|
101 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
|
102 |
+
*/
|
103 |
+
define('CRYPT_DES_MODE_ECB', 1);
|
104 |
+
/**
|
105 |
+
* Encrypt / decrypt using the Code Book Chaining mode.
|
106 |
+
*
|
107 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
|
108 |
+
*/
|
109 |
+
define('CRYPT_DES_MODE_CBC', 2);
|
110 |
+
/**
|
111 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
112 |
+
*
|
113 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
|
114 |
+
*/
|
115 |
+
define('CRYPT_DES_MODE_CFB', 3);
|
116 |
+
/**
|
117 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
118 |
+
*
|
119 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
|
120 |
+
*/
|
121 |
+
define('CRYPT_DES_MODE_OFB', 4);
|
122 |
+
/**#@-*/
|
123 |
+
|
124 |
+
/**#@+
|
125 |
+
* @access private
|
126 |
+
* @see Crypt_DES::Crypt_DES()
|
127 |
+
*/
|
128 |
+
/**
|
129 |
+
* Toggles the internal implementation
|
130 |
+
*/
|
131 |
+
define('CRYPT_DES_MODE_INTERNAL', 1);
|
132 |
+
/**
|
133 |
+
* Toggles the mcrypt implementation
|
134 |
+
*/
|
135 |
+
define('CRYPT_DES_MODE_MCRYPT', 2);
|
136 |
+
/**#@-*/
|
137 |
+
|
138 |
+
/**
|
139 |
+
* Pure-PHP implementation of DES.
|
140 |
+
*
|
141 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
142 |
+
* @version 0.1.0
|
143 |
+
* @access public
|
144 |
+
* @package Crypt_DES
|
145 |
+
*/
|
146 |
+
class Crypt_DES {
|
147 |
+
/**
|
148 |
+
* The Key Schedule
|
149 |
+
*
|
150 |
+
* @see Crypt_DES::setKey()
|
151 |
+
* @var Array
|
152 |
+
* @access private
|
153 |
+
*/
|
154 |
+
var $keys = "\0\0\0\0\0\0\0\0";
|
155 |
+
|
156 |
+
/**
|
157 |
+
* The Encryption Mode
|
158 |
+
*
|
159 |
+
* @see Crypt_DES::Crypt_DES()
|
160 |
+
* @var Integer
|
161 |
+
* @access private
|
162 |
+
*/
|
163 |
+
var $mode;
|
164 |
+
|
165 |
+
/**
|
166 |
+
* Continuous Buffer status
|
167 |
+
*
|
168 |
+
* @see Crypt_DES::enableContinuousBuffer()
|
169 |
+
* @var Boolean
|
170 |
+
* @access private
|
171 |
+
*/
|
172 |
+
var $continuousBuffer = false;
|
173 |
+
|
174 |
+
/**
|
175 |
+
* Padding status
|
176 |
+
*
|
177 |
+
* @see Crypt_DES::enablePadding()
|
178 |
+
* @var Boolean
|
179 |
+
* @access private
|
180 |
+
*/
|
181 |
+
var $padding = true;
|
182 |
+
|
183 |
+
/**
|
184 |
+
* The Initialization Vector
|
185 |
+
*
|
186 |
+
* @see Crypt_DES::setIV()
|
187 |
+
* @var String
|
188 |
+
* @access private
|
189 |
+
*/
|
190 |
+
var $iv = "\0\0\0\0\0\0\0\0";
|
191 |
+
|
192 |
+
/**
|
193 |
+
* A "sliding" Initialization Vector
|
194 |
+
*
|
195 |
+
* @see Crypt_DES::enableContinuousBuffer()
|
196 |
+
* @var String
|
197 |
+
* @access private
|
198 |
+
*/
|
199 |
+
var $encryptIV = "\0\0\0\0\0\0\0\0";
|
200 |
+
|
201 |
+
/**
|
202 |
+
* A "sliding" Initialization Vector
|
203 |
+
*
|
204 |
+
* @see Crypt_DES::enableContinuousBuffer()
|
205 |
+
* @var String
|
206 |
+
* @access private
|
207 |
+
*/
|
208 |
+
var $decryptIV = "\0\0\0\0\0\0\0\0";
|
209 |
+
|
210 |
+
/**
|
211 |
+
* mcrypt resource for encryption
|
212 |
+
*
|
213 |
+
* The mcrypt resource can be recreated every time something needs to be created or it can be created just once.
|
214 |
+
* Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.
|
215 |
+
*
|
216 |
+
* @see Crypt_DES::encrypt()
|
217 |
+
* @var String
|
218 |
+
* @access private
|
219 |
+
*/
|
220 |
+
var $enmcrypt;
|
221 |
+
|
222 |
+
/**
|
223 |
+
* mcrypt resource for decryption
|
224 |
+
*
|
225 |
+
* The mcrypt resource can be recreated every time something needs to be created or it can be created just once.
|
226 |
+
* Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.
|
227 |
+
*
|
228 |
+
* @see Crypt_DES::decrypt()
|
229 |
+
* @var String
|
230 |
+
* @access private
|
231 |
+
*/
|
232 |
+
var $demcrypt;
|
233 |
+
|
234 |
+
/**
|
235 |
+
* Does the enmcrypt resource need to be (re)initialized?
|
236 |
+
*
|
237 |
+
* @see Crypt_DES::setKey()
|
238 |
+
* @see Crypt_DES::setIV()
|
239 |
+
* @var Boolean
|
240 |
+
* @access private
|
241 |
+
*/
|
242 |
+
var $enchanged = true;
|
243 |
+
|
244 |
+
/**
|
245 |
+
* Does the demcrypt resource need to be (re)initialized?
|
246 |
+
*
|
247 |
+
* @see Crypt_DES::setKey()
|
248 |
+
* @see Crypt_DES::setIV()
|
249 |
+
* @var Boolean
|
250 |
+
* @access private
|
251 |
+
*/
|
252 |
+
var $dechanged = true;
|
253 |
+
|
254 |
+
/**
|
255 |
+
* Is the mode one that is paddable?
|
256 |
+
*
|
257 |
+
* @see Crypt_DES::Crypt_DES()
|
258 |
+
* @var Boolean
|
259 |
+
* @access private
|
260 |
+
*/
|
261 |
+
var $paddable = false;
|
262 |
+
|
263 |
+
/**
|
264 |
+
* Encryption buffer for CTR, OFB and CFB modes
|
265 |
+
*
|
266 |
+
* @see Crypt_DES::encrypt()
|
267 |
+
* @var Array
|
268 |
+
* @access private
|
269 |
+
*/
|
270 |
+
var $enbuffer = array('encrypted' => '', 'xor' => '', 'pos' => 0, 'enmcrypt_init' => true);
|
271 |
+
|
272 |
+
/**
|
273 |
+
* Decryption buffer for CTR, OFB and CFB modes
|
274 |
+
*
|
275 |
+
* @see Crypt_DES::decrypt()
|
276 |
+
* @var Array
|
277 |
+
* @access private
|
278 |
+
*/
|
279 |
+
var $debuffer = array('ciphertext' => '', 'xor' => '', 'pos' => 0, 'demcrypt_init' => true);
|
280 |
+
|
281 |
+
/**
|
282 |
+
* mcrypt resource for CFB mode
|
283 |
+
*
|
284 |
+
* @see Crypt_DES::encrypt()
|
285 |
+
* @see Crypt_DES::decrypt()
|
286 |
+
* @var String
|
287 |
+
* @access private
|
288 |
+
*/
|
289 |
+
var $ecb;
|
290 |
+
|
291 |
+
/**
|
292 |
+
* Performance-optimized callback function for en/decrypt()
|
293 |
+
*
|
294 |
+
* @var Callback
|
295 |
+
* @access private
|
296 |
+
*/
|
297 |
+
var $inline_crypt;
|
298 |
+
|
299 |
+
/**
|
300 |
+
* Holds whether performance-optimized $inline_crypt should be used or not.
|
301 |
+
*
|
302 |
+
* @var Boolean
|
303 |
+
* @access private
|
304 |
+
*/
|
305 |
+
var $use_inline_crypt = false;
|
306 |
+
|
307 |
+
/**
|
308 |
+
* Shuffle table.
|
309 |
+
*
|
310 |
+
* For each byte value index, the entry holds an 8-byte string
|
311 |
+
* with each byte containing all bits in the same state as the
|
312 |
+
* corresponding bit in the index value.
|
313 |
+
*
|
314 |
+
* @see Crypt_DES::_processBlock()
|
315 |
+
* @see Crypt_DES::_prepareKey()
|
316 |
+
* @var Array
|
317 |
+
* @access private
|
318 |
+
*/
|
319 |
+
var $shuffle = array(
|
320 |
+
"\x00\x00\x00\x00\x00\x00\x00\x00", "\x00\x00\x00\x00\x00\x00\x00\xFF",
|
321 |
+
"\x00\x00\x00\x00\x00\x00\xFF\x00", "\x00\x00\x00\x00\x00\x00\xFF\xFF",
|
322 |
+
"\x00\x00\x00\x00\x00\xFF\x00\x00", "\x00\x00\x00\x00\x00\xFF\x00\xFF",
|
323 |
+
"\x00\x00\x00\x00\x00\xFF\xFF\x00", "\x00\x00\x00\x00\x00\xFF\xFF\xFF",
|
324 |
+
"\x00\x00\x00\x00\xFF\x00\x00\x00", "\x00\x00\x00\x00\xFF\x00\x00\xFF",
|
325 |
+
"\x00\x00\x00\x00\xFF\x00\xFF\x00", "\x00\x00\x00\x00\xFF\x00\xFF\xFF",
|
326 |
+
"\x00\x00\x00\x00\xFF\xFF\x00\x00", "\x00\x00\x00\x00\xFF\xFF\x00\xFF",
|
327 |
+
"\x00\x00\x00\x00\xFF\xFF\xFF\x00", "\x00\x00\x00\x00\xFF\xFF\xFF\xFF",
|
328 |
+
"\x00\x00\x00\xFF\x00\x00\x00\x00", "\x00\x00\x00\xFF\x00\x00\x00\xFF",
|
329 |
+
"\x00\x00\x00\xFF\x00\x00\xFF\x00", "\x00\x00\x00\xFF\x00\x00\xFF\xFF",
|
330 |
+
"\x00\x00\x00\xFF\x00\xFF\x00\x00", "\x00\x00\x00\xFF\x00\xFF\x00\xFF",
|
331 |
+
"\x00\x00\x00\xFF\x00\xFF\xFF\x00", "\x00\x00\x00\xFF\x00\xFF\xFF\xFF",
|
332 |
+
"\x00\x00\x00\xFF\xFF\x00\x00\x00", "\x00\x00\x00\xFF\xFF\x00\x00\xFF",
|
333 |
+
"\x00\x00\x00\xFF\xFF\x00\xFF\x00", "\x00\x00\x00\xFF\xFF\x00\xFF\xFF",
|
334 |
+
"\x00\x00\x00\xFF\xFF\xFF\x00\x00", "\x00\x00\x00\xFF\xFF\xFF\x00\xFF",
|
335 |
+
"\x00\x00\x00\xFF\xFF\xFF\xFF\x00", "\x00\x00\x00\xFF\xFF\xFF\xFF\xFF",
|
336 |
+
"\x00\x00\xFF\x00\x00\x00\x00\x00", "\x00\x00\xFF\x00\x00\x00\x00\xFF",
|
337 |
+
"\x00\x00\xFF\x00\x00\x00\xFF\x00", "\x00\x00\xFF\x00\x00\x00\xFF\xFF",
|
338 |
+
"\x00\x00\xFF\x00\x00\xFF\x00\x00", "\x00\x00\xFF\x00\x00\xFF\x00\xFF",
|
339 |
+
"\x00\x00\xFF\x00\x00\xFF\xFF\x00", "\x00\x00\xFF\x00\x00\xFF\xFF\xFF",
|
340 |
+
"\x00\x00\xFF\x00\xFF\x00\x00\x00", "\x00\x00\xFF\x00\xFF\x00\x00\xFF",
|
341 |
+
"\x00\x00\xFF\x00\xFF\x00\xFF\x00", "\x00\x00\xFF\x00\xFF\x00\xFF\xFF",
|
342 |
+
"\x00\x00\xFF\x00\xFF\xFF\x00\x00", "\x00\x00\xFF\x00\xFF\xFF\x00\xFF",
|
343 |
+
"\x00\x00\xFF\x00\xFF\xFF\xFF\x00", "\x00\x00\xFF\x00\xFF\xFF\xFF\xFF",
|
344 |
+
"\x00\x00\xFF\xFF\x00\x00\x00\x00", "\x00\x00\xFF\xFF\x00\x00\x00\xFF",
|
345 |
+
"\x00\x00\xFF\xFF\x00\x00\xFF\x00", "\x00\x00\xFF\xFF\x00\x00\xFF\xFF",
|
346 |
+
"\x00\x00\xFF\xFF\x00\xFF\x00\x00", "\x00\x00\xFF\xFF\x00\xFF\x00\xFF",
|
347 |
+
"\x00\x00\xFF\xFF\x00\xFF\xFF\x00", "\x00\x00\xFF\xFF\x00\xFF\xFF\xFF",
|
348 |
+
"\x00\x00\xFF\xFF\xFF\x00\x00\x00", "\x00\x00\xFF\xFF\xFF\x00\x00\xFF",
|
349 |
+
"\x00\x00\xFF\xFF\xFF\x00\xFF\x00", "\x00\x00\xFF\xFF\xFF\x00\xFF\xFF",
|
350 |
+
"\x00\x00\xFF\xFF\xFF\xFF\x00\x00", "\x00\x00\xFF\xFF\xFF\xFF\x00\xFF",
|
351 |
+
"\x00\x00\xFF\xFF\xFF\xFF\xFF\x00", "\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF",
|
352 |
+
"\x00\xFF\x00\x00\x00\x00\x00\x00", "\x00\xFF\x00\x00\x00\x00\x00\xFF",
|
353 |
+
"\x00\xFF\x00\x00\x00\x00\xFF\x00", "\x00\xFF\x00\x00\x00\x00\xFF\xFF",
|
354 |
+
"\x00\xFF\x00\x00\x00\xFF\x00\x00", "\x00\xFF\x00\x00\x00\xFF\x00\xFF",
|
355 |
+
"\x00\xFF\x00\x00\x00\xFF\xFF\x00", "\x00\xFF\x00\x00\x00\xFF\xFF\xFF",
|
356 |
+
"\x00\xFF\x00\x00\xFF\x00\x00\x00", "\x00\xFF\x00\x00\xFF\x00\x00\xFF",
|
357 |
+
"\x00\xFF\x00\x00\xFF\x00\xFF\x00", "\x00\xFF\x00\x00\xFF\x00\xFF\xFF",
|
358 |
+
"\x00\xFF\x00\x00\xFF\xFF\x00\x00", "\x00\xFF\x00\x00\xFF\xFF\x00\xFF",
|
359 |
+
"\x00\xFF\x00\x00\xFF\xFF\xFF\x00", "\x00\xFF\x00\x00\xFF\xFF\xFF\xFF",
|
360 |
+
"\x00\xFF\x00\xFF\x00\x00\x00\x00", "\x00\xFF\x00\xFF\x00\x00\x00\xFF",
|
361 |
+
"\x00\xFF\x00\xFF\x00\x00\xFF\x00", "\x00\xFF\x00\xFF\x00\x00\xFF\xFF",
|
362 |
+
"\x00\xFF\x00\xFF\x00\xFF\x00\x00", "\x00\xFF\x00\xFF\x00\xFF\x00\xFF",
|
363 |
+
"\x00\xFF\x00\xFF\x00\xFF\xFF\x00", "\x00\xFF\x00\xFF\x00\xFF\xFF\xFF",
|
364 |
+
"\x00\xFF\x00\xFF\xFF\x00\x00\x00", "\x00\xFF\x00\xFF\xFF\x00\x00\xFF",
|
365 |
+
"\x00\xFF\x00\xFF\xFF\x00\xFF\x00", "\x00\xFF\x00\xFF\xFF\x00\xFF\xFF",
|
366 |
+
"\x00\xFF\x00\xFF\xFF\xFF\x00\x00", "\x00\xFF\x00\xFF\xFF\xFF\x00\xFF",
|
367 |
+
"\x00\xFF\x00\xFF\xFF\xFF\xFF\x00", "\x00\xFF\x00\xFF\xFF\xFF\xFF\xFF",
|
368 |
+
"\x00\xFF\xFF\x00\x00\x00\x00\x00", "\x00\xFF\xFF\x00\x00\x00\x00\xFF",
|
369 |
+
"\x00\xFF\xFF\x00\x00\x00\xFF\x00", "\x00\xFF\xFF\x00\x00\x00\xFF\xFF",
|
370 |
+
"\x00\xFF\xFF\x00\x00\xFF\x00\x00", "\x00\xFF\xFF\x00\x00\xFF\x00\xFF",
|
371 |
+
"\x00\xFF\xFF\x00\x00\xFF\xFF\x00", "\x00\xFF\xFF\x00\x00\xFF\xFF\xFF",
|
372 |
+
"\x00\xFF\xFF\x00\xFF\x00\x00\x00", "\x00\xFF\xFF\x00\xFF\x00\x00\xFF",
|
373 |
+
"\x00\xFF\xFF\x00\xFF\x00\xFF\x00", "\x00\xFF\xFF\x00\xFF\x00\xFF\xFF",
|
374 |
+
"\x00\xFF\xFF\x00\xFF\xFF\x00\x00", "\x00\xFF\xFF\x00\xFF\xFF\x00\xFF",
|
375 |
+
"\x00\xFF\xFF\x00\xFF\xFF\xFF\x00", "\x00\xFF\xFF\x00\xFF\xFF\xFF\xFF",
|
376 |
+
"\x00\xFF\xFF\xFF\x00\x00\x00\x00", "\x00\xFF\xFF\xFF\x00\x00\x00\xFF",
|
377 |
+
"\x00\xFF\xFF\xFF\x00\x00\xFF\x00", "\x00\xFF\xFF\xFF\x00\x00\xFF\xFF",
|
378 |
+
"\x00\xFF\xFF\xFF\x00\xFF\x00\x00", "\x00\xFF\xFF\xFF\x00\xFF\x00\xFF",
|
379 |
+
"\x00\xFF\xFF\xFF\x00\xFF\xFF\x00", "\x00\xFF\xFF\xFF\x00\xFF\xFF\xFF",
|
380 |
+
"\x00\xFF\xFF\xFF\xFF\x00\x00\x00", "\x00\xFF\xFF\xFF\xFF\x00\x00\xFF",
|
381 |
+
"\x00\xFF\xFF\xFF\xFF\x00\xFF\x00", "\x00\xFF\xFF\xFF\xFF\x00\xFF\xFF",
|
382 |
+
"\x00\xFF\xFF\xFF\xFF\xFF\x00\x00", "\x00\xFF\xFF\xFF\xFF\xFF\x00\xFF",
|
383 |
+
"\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", "\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF",
|
384 |
+
"\xFF\x00\x00\x00\x00\x00\x00\x00", "\xFF\x00\x00\x00\x00\x00\x00\xFF",
|
385 |
+
"\xFF\x00\x00\x00\x00\x00\xFF\x00", "\xFF\x00\x00\x00\x00\x00\xFF\xFF",
|
386 |
+
"\xFF\x00\x00\x00\x00\xFF\x00\x00", "\xFF\x00\x00\x00\x00\xFF\x00\xFF",
|
387 |
+
"\xFF\x00\x00\x00\x00\xFF\xFF\x00", "\xFF\x00\x00\x00\x00\xFF\xFF\xFF",
|
388 |
+
"\xFF\x00\x00\x00\xFF\x00\x00\x00", "\xFF\x00\x00\x00\xFF\x00\x00\xFF",
|
389 |
+
"\xFF\x00\x00\x00\xFF\x00\xFF\x00", "\xFF\x00\x00\x00\xFF\x00\xFF\xFF",
|
390 |
+
"\xFF\x00\x00\x00\xFF\xFF\x00\x00", "\xFF\x00\x00\x00\xFF\xFF\x00\xFF",
|
391 |
+
"\xFF\x00\x00\x00\xFF\xFF\xFF\x00", "\xFF\x00\x00\x00\xFF\xFF\xFF\xFF",
|
392 |
+
"\xFF\x00\x00\xFF\x00\x00\x00\x00", "\xFF\x00\x00\xFF\x00\x00\x00\xFF",
|
393 |
+
"\xFF\x00\x00\xFF\x00\x00\xFF\x00", "\xFF\x00\x00\xFF\x00\x00\xFF\xFF",
|
394 |
+
"\xFF\x00\x00\xFF\x00\xFF\x00\x00", "\xFF\x00\x00\xFF\x00\xFF\x00\xFF",
|
395 |
+
"\xFF\x00\x00\xFF\x00\xFF\xFF\x00", "\xFF\x00\x00\xFF\x00\xFF\xFF\xFF",
|
396 |
+
"\xFF\x00\x00\xFF\xFF\x00\x00\x00", "\xFF\x00\x00\xFF\xFF\x00\x00\xFF",
|
397 |
+
"\xFF\x00\x00\xFF\xFF\x00\xFF\x00", "\xFF\x00\x00\xFF\xFF\x00\xFF\xFF",
|
398 |
+
"\xFF\x00\x00\xFF\xFF\xFF\x00\x00", "\xFF\x00\x00\xFF\xFF\xFF\x00\xFF",
|
399 |
+
"\xFF\x00\x00\xFF\xFF\xFF\xFF\x00", "\xFF\x00\x00\xFF\xFF\xFF\xFF\xFF",
|
400 |
+
"\xFF\x00\xFF\x00\x00\x00\x00\x00", "\xFF\x00\xFF\x00\x00\x00\x00\xFF",
|
401 |
+
"\xFF\x00\xFF\x00\x00\x00\xFF\x00", "\xFF\x00\xFF\x00\x00\x00\xFF\xFF",
|
402 |
+
"\xFF\x00\xFF\x00\x00\xFF\x00\x00", "\xFF\x00\xFF\x00\x00\xFF\x00\xFF",
|
403 |
+
"\xFF\x00\xFF\x00\x00\xFF\xFF\x00", "\xFF\x00\xFF\x00\x00\xFF\xFF\xFF",
|
404 |
+
"\xFF\x00\xFF\x00\xFF\x00\x00\x00", "\xFF\x00\xFF\x00\xFF\x00\x00\xFF",
|
405 |
+
"\xFF\x00\xFF\x00\xFF\x00\xFF\x00", "\xFF\x00\xFF\x00\xFF\x00\xFF\xFF",
|
406 |
+
"\xFF\x00\xFF\x00\xFF\xFF\x00\x00", "\xFF\x00\xFF\x00\xFF\xFF\x00\xFF",
|
407 |
+
"\xFF\x00\xFF\x00\xFF\xFF\xFF\x00", "\xFF\x00\xFF\x00\xFF\xFF\xFF\xFF",
|
408 |
+
"\xFF\x00\xFF\xFF\x00\x00\x00\x00", "\xFF\x00\xFF\xFF\x00\x00\x00\xFF",
|
409 |
+
"\xFF\x00\xFF\xFF\x00\x00\xFF\x00", "\xFF\x00\xFF\xFF\x00\x00\xFF\xFF",
|
410 |
+
"\xFF\x00\xFF\xFF\x00\xFF\x00\x00", "\xFF\x00\xFF\xFF\x00\xFF\x00\xFF",
|
411 |
+
"\xFF\x00\xFF\xFF\x00\xFF\xFF\x00", "\xFF\x00\xFF\xFF\x00\xFF\xFF\xFF",
|
412 |
+
"\xFF\x00\xFF\xFF\xFF\x00\x00\x00", "\xFF\x00\xFF\xFF\xFF\x00\x00\xFF",
|
413 |
+
"\xFF\x00\xFF\xFF\xFF\x00\xFF\x00", "\xFF\x00\xFF\xFF\xFF\x00\xFF\xFF",
|
414 |
+
"\xFF\x00\xFF\xFF\xFF\xFF\x00\x00", "\xFF\x00\xFF\xFF\xFF\xFF\x00\xFF",
|
415 |
+
"\xFF\x00\xFF\xFF\xFF\xFF\xFF\x00", "\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF",
|
416 |
+
"\xFF\xFF\x00\x00\x00\x00\x00\x00", "\xFF\xFF\x00\x00\x00\x00\x00\xFF",
|
417 |
+
"\xFF\xFF\x00\x00\x00\x00\xFF\x00", "\xFF\xFF\x00\x00\x00\x00\xFF\xFF",
|
418 |
+
"\xFF\xFF\x00\x00\x00\xFF\x00\x00", "\xFF\xFF\x00\x00\x00\xFF\x00\xFF",
|
419 |
+
"\xFF\xFF\x00\x00\x00\xFF\xFF\x00", "\xFF\xFF\x00\x00\x00\xFF\xFF\xFF",
|
420 |
+
"\xFF\xFF\x00\x00\xFF\x00\x00\x00", "\xFF\xFF\x00\x00\xFF\x00\x00\xFF",
|
421 |
+
"\xFF\xFF\x00\x00\xFF\x00\xFF\x00", "\xFF\xFF\x00\x00\xFF\x00\xFF\xFF",
|
422 |
+
"\xFF\xFF\x00\x00\xFF\xFF\x00\x00", "\xFF\xFF\x00\x00\xFF\xFF\x00\xFF",
|
423 |
+
"\xFF\xFF\x00\x00\xFF\xFF\xFF\x00", "\xFF\xFF\x00\x00\xFF\xFF\xFF\xFF",
|
424 |
+
"\xFF\xFF\x00\xFF\x00\x00\x00\x00", "\xFF\xFF\x00\xFF\x00\x00\x00\xFF",
|
425 |
+
"\xFF\xFF\x00\xFF\x00\x00\xFF\x00", "\xFF\xFF\x00\xFF\x00\x00\xFF\xFF",
|
426 |
+
"\xFF\xFF\x00\xFF\x00\xFF\x00\x00", "\xFF\xFF\x00\xFF\x00\xFF\x00\xFF",
|
427 |
+
"\xFF\xFF\x00\xFF\x00\xFF\xFF\x00", "\xFF\xFF\x00\xFF\x00\xFF\xFF\xFF",
|
428 |
+
"\xFF\xFF\x00\xFF\xFF\x00\x00\x00", "\xFF\xFF\x00\xFF\xFF\x00\x00\xFF",
|
429 |
+
"\xFF\xFF\x00\xFF\xFF\x00\xFF\x00", "\xFF\xFF\x00\xFF\xFF\x00\xFF\xFF",
|
430 |
+
"\xFF\xFF\x00\xFF\xFF\xFF\x00\x00", "\xFF\xFF\x00\xFF\xFF\xFF\x00\xFF",
|
431 |
+
"\xFF\xFF\x00\xFF\xFF\xFF\xFF\x00", "\xFF\xFF\x00\xFF\xFF\xFF\xFF\xFF",
|
432 |
+
"\xFF\xFF\xFF\x00\x00\x00\x00\x00", "\xFF\xFF\xFF\x00\x00\x00\x00\xFF",
|
433 |
+
"\xFF\xFF\xFF\x00\x00\x00\xFF\x00", "\xFF\xFF\xFF\x00\x00\x00\xFF\xFF",
|
434 |
+
"\xFF\xFF\xFF\x00\x00\xFF\x00\x00", "\xFF\xFF\xFF\x00\x00\xFF\x00\xFF",
|
435 |
+
"\xFF\xFF\xFF\x00\x00\xFF\xFF\x00", "\xFF\xFF\xFF\x00\x00\xFF\xFF\xFF",
|
436 |
+
"\xFF\xFF\xFF\x00\xFF\x00\x00\x00", "\xFF\xFF\xFF\x00\xFF\x00\x00\xFF",
|
437 |
+
"\xFF\xFF\xFF\x00\xFF\x00\xFF\x00", "\xFF\xFF\xFF\x00\xFF\x00\xFF\xFF",
|
438 |
+
"\xFF\xFF\xFF\x00\xFF\xFF\x00\x00", "\xFF\xFF\xFF\x00\xFF\xFF\x00\xFF",
|
439 |
+
"\xFF\xFF\xFF\x00\xFF\xFF\xFF\x00", "\xFF\xFF\xFF\x00\xFF\xFF\xFF\xFF",
|
440 |
+
"\xFF\xFF\xFF\xFF\x00\x00\x00\x00", "\xFF\xFF\xFF\xFF\x00\x00\x00\xFF",
|
441 |
+
"\xFF\xFF\xFF\xFF\x00\x00\xFF\x00", "\xFF\xFF\xFF\xFF\x00\x00\xFF\xFF",
|
442 |
+
"\xFF\xFF\xFF\xFF\x00\xFF\x00\x00", "\xFF\xFF\xFF\xFF\x00\xFF\x00\xFF",
|
443 |
+
"\xFF\xFF\xFF\xFF\x00\xFF\xFF\x00", "\xFF\xFF\xFF\xFF\x00\xFF\xFF\xFF",
|
444 |
+
"\xFF\xFF\xFF\xFF\xFF\x00\x00\x00", "\xFF\xFF\xFF\xFF\xFF\x00\x00\xFF",
|
445 |
+
"\xFF\xFF\xFF\xFF\xFF\x00\xFF\x00", "\xFF\xFF\xFF\xFF\xFF\x00\xFF\xFF",
|
446 |
+
"\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00", "\xFF\xFF\xFF\xFF\xFF\xFF\x00\xFF",
|
447 |
+
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00", "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
|
448 |
+
);
|
449 |
+
|
450 |
+
/**
|
451 |
+
* IP mapping helper table.
|
452 |
+
*
|
453 |
+
* Indexing this table with each source byte performs the initial bit permutation.
|
454 |
+
*
|
455 |
+
* @var Array
|
456 |
+
* @access private
|
457 |
+
*/
|
458 |
+
var $ipmap = array(
|
459 |
+
0x00, 0x10, 0x01, 0x11, 0x20, 0x30, 0x21, 0x31,
|
460 |
+
0x02, 0x12, 0x03, 0x13, 0x22, 0x32, 0x23, 0x33,
|
461 |
+
0x40, 0x50, 0x41, 0x51, 0x60, 0x70, 0x61, 0x71,
|
462 |
+
0x42, 0x52, 0x43, 0x53, 0x62, 0x72, 0x63, 0x73,
|
463 |
+
0x04, 0x14, 0x05, 0x15, 0x24, 0x34, 0x25, 0x35,
|
464 |
+
0x06, 0x16, 0x07, 0x17, 0x26, 0x36, 0x27, 0x37,
|
465 |
+
0x44, 0x54, 0x45, 0x55, 0x64, 0x74, 0x65, 0x75,
|
466 |
+
0x46, 0x56, 0x47, 0x57, 0x66, 0x76, 0x67, 0x77,
|
467 |
+
0x80, 0x90, 0x81, 0x91, 0xA0, 0xB0, 0xA1, 0xB1,
|
468 |
+
0x82, 0x92, 0x83, 0x93, 0xA2, 0xB2, 0xA3, 0xB3,
|
469 |
+
0xC0, 0xD0, 0xC1, 0xD1, 0xE0, 0xF0, 0xE1, 0xF1,
|
470 |
+
0xC2, 0xD2, 0xC3, 0xD3, 0xE2, 0xF2, 0xE3, 0xF3,
|
471 |
+
0x84, 0x94, 0x85, 0x95, 0xA4, 0xB4, 0xA5, 0xB5,
|
472 |
+
0x86, 0x96, 0x87, 0x97, 0xA6, 0xB6, 0xA7, 0xB7,
|
473 |
+
0xC4, 0xD4, 0xC5, 0xD5, 0xE4, 0xF4, 0xE5, 0xF5,
|
474 |
+
0xC6, 0xD6, 0xC7, 0xD7, 0xE6, 0xF6, 0xE7, 0xF7,
|
475 |
+
0x08, 0x18, 0x09, 0x19, 0x28, 0x38, 0x29, 0x39,
|
476 |
+
0x0A, 0x1A, 0x0B, 0x1B, 0x2A, 0x3A, 0x2B, 0x3B,
|
477 |
+
0x48, 0x58, 0x49, 0x59, 0x68, 0x78, 0x69, 0x79,
|
478 |
+
0x4A, 0x5A, 0x4B, 0x5B, 0x6A, 0x7A, 0x6B, 0x7B,
|
479 |
+
0x0C, 0x1C, 0x0D, 0x1D, 0x2C, 0x3C, 0x2D, 0x3D,
|
480 |
+
0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F,
|
481 |
+
0x4C, 0x5C, 0x4D, 0x5D, 0x6C, 0x7C, 0x6D, 0x7D,
|
482 |
+
0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F,
|
483 |
+
0x88, 0x98, 0x89, 0x99, 0xA8, 0xB8, 0xA9, 0xB9,
|
484 |
+
0x8A, 0x9A, 0x8B, 0x9B, 0xAA, 0xBA, 0xAB, 0xBB,
|
485 |
+
0xC8, 0xD8, 0xC9, 0xD9, 0xE8, 0xF8, 0xE9, 0xF9,
|
486 |
+
0xCA, 0xDA, 0xCB, 0xDB, 0xEA, 0xFA, 0xEB, 0xFB,
|
487 |
+
0x8C, 0x9C, 0x8D, 0x9D, 0xAC, 0xBC, 0xAD, 0xBD,
|
488 |
+
0x8E, 0x9E, 0x8F, 0x9F, 0xAE, 0xBE, 0xAF, 0xBF,
|
489 |
+
0xCC, 0xDC, 0xCD, 0xDD, 0xEC, 0xFC, 0xED, 0xFD,
|
490 |
+
0xCE, 0xDE, 0xCF, 0xDF, 0xEE, 0xFE, 0xEF, 0xFF
|
491 |
+
);
|
492 |
+
|
493 |
+
/**
|
494 |
+
* Inverse IP mapping helper table.
|
495 |
+
* Indexing this table with a byte value reverses the bit order.
|
496 |
+
*
|
497 |
+
* @var Array
|
498 |
+
* @access private
|
499 |
+
*/
|
500 |
+
var $invipmap = array(
|
501 |
+
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
|
502 |
+
0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
|
503 |
+
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
|
504 |
+
0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
|
505 |
+
0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
|
506 |
+
0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
|
507 |
+
0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
|
508 |
+
0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
|
509 |
+
0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
|
510 |
+
0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
|
511 |
+
0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
|
512 |
+
0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
|
513 |
+
0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
|
514 |
+
0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
|
515 |
+
0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
|
516 |
+
0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
|
517 |
+
0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
|
518 |
+
0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
|
519 |
+
0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
|
520 |
+
0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
|
521 |
+
0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
|
522 |
+
0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
|
523 |
+
0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
|
524 |
+
0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
|
525 |
+
0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
|
526 |
+
0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
|
527 |
+
0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
|
528 |
+
0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
|
529 |
+
0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
|
530 |
+
0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
|
531 |
+
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
|
532 |
+
0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
|
533 |
+
);
|
534 |
+
|
535 |
+
/**
|
536 |
+
* Pre-permuted S-box1
|
537 |
+
*
|
538 |
+
* Each box ($sbox1-$sbox8) has been vectorized, then each value pre-permuted using the
|
539 |
+
* P table: concatenation can then be replaced by exclusive ORs.
|
540 |
+
*
|
541 |
+
* @var Array
|
542 |
+
* @access private
|
543 |
+
*/
|
544 |
+
var $sbox1 = array(
|
545 |
+
0x00808200, 0x00000000, 0x00008000, 0x00808202,
|
546 |
+
0x00808002, 0x00008202, 0x00000002, 0x00008000,
|
547 |
+
0x00000200, 0x00808200, 0x00808202, 0x00000200,
|
548 |
+
0x00800202, 0x00808002, 0x00800000, 0x00000002,
|
549 |
+
0x00000202, 0x00800200, 0x00800200, 0x00008200,
|
550 |
+
0x00008200, 0x00808000, 0x00808000, 0x00800202,
|
551 |
+
0x00008002, 0x00800002, 0x00800002, 0x00008002,
|
552 |
+
0x00000000, 0x00000202, 0x00008202, 0x00800000,
|
553 |
+
0x00008000, 0x00808202, 0x00000002, 0x00808000,
|
554 |
+
0x00808200, 0x00800000, 0x00800000, 0x00000200,
|
555 |
+
0x00808002, 0x00008000, 0x00008200, 0x00800002,
|
556 |
+
0x00000200, 0x00000002, 0x00800202, 0x00008202,
|
557 |
+
0x00808202, 0x00008002, 0x00808000, 0x00800202,
|
558 |
+
0x00800002, 0x00000202, 0x00008202, 0x00808200,
|
559 |
+
0x00000202, 0x00800200, 0x00800200, 0x00000000,
|
560 |
+
0x00008002, 0x00008200, 0x00000000, 0x00808002
|
561 |
+
);
|
562 |
+
|
563 |
+
/**
|
564 |
+
* Pre-permuted S-box2
|
565 |
+
*
|
566 |
+
* @var Array
|
567 |
+
* @access private
|
568 |
+
*/
|
569 |
+
var $sbox2 = array(
|
570 |
+
0x40084010, 0x40004000, 0x00004000, 0x00084010,
|
571 |
+
0x00080000, 0x00000010, 0x40080010, 0x40004010,
|
572 |
+
0x40000010, 0x40084010, 0x40084000, 0x40000000,
|
573 |
+
0x40004000, 0x00080000, 0x00000010, 0x40080010,
|
574 |
+
0x00084000, 0x00080010, 0x40004010, 0x00000000,
|
575 |
+
0x40000000, 0x00004000, 0x00084010, 0x40080000,
|
576 |
+
0x00080010, 0x40000010, 0x00000000, 0x00084000,
|
577 |
+
0x00004010, 0x40084000, 0x40080000, 0x00004010,
|
578 |
+
0x00000000, 0x00084010, 0x40080010, 0x00080000,
|
579 |
+
0x40004010, 0x40080000, 0x40084000, 0x00004000,
|
580 |
+
0x40080000, 0x40004000, 0x00000010, 0x40084010,
|
581 |
+
0x00084010, 0x00000010, 0x00004000, 0x40000000,
|
582 |
+
0x00004010, 0x40084000, 0x00080000, 0x40000010,
|
583 |
+
0x00080010, 0x40004010, 0x40000010, 0x00080010,
|
584 |
+
0x00084000, 0x00000000, 0x40004000, 0x00004010,
|
585 |
+
0x40000000, 0x40080010, 0x40084010, 0x00084000
|
586 |
+
);
|
587 |
+
|
588 |
+
/**
|
589 |
+
* Pre-permuted S-box3
|
590 |
+
*
|
591 |
+
* @var Array
|
592 |
+
* @access private
|
593 |
+
*/
|
594 |
+
var $sbox3 = array(
|
595 |
+
0x00000104, 0x04010100, 0x00000000, 0x04010004,
|
596 |
+
0x04000100, 0x00000000, 0x00010104, 0x04000100,
|
597 |
+
0x00010004, 0x04000004, 0x04000004, 0x00010000,
|
598 |
+
0x04010104, 0x00010004, 0x04010000, 0x00000104,
|
599 |
+
0x04000000, 0x00000004, 0x04010100, 0x00000100,
|
600 |
+
0x00010100, 0x04010000, 0x04010004, 0x00010104,
|
601 |
+
0x04000104, 0x00010100, 0x00010000, 0x04000104,
|
602 |
+
0x00000004, 0x04010104, 0x00000100, 0x04000000,
|
603 |
+
0x04010100, 0x04000000, 0x00010004, 0x00000104,
|
604 |
+
0x00010000, 0x04010100, 0x04000100, 0x00000000,
|
605 |
+
0x00000100, 0x00010004, 0x04010104, 0x04000100,
|
606 |
+
0x04000004, 0x00000100, 0x00000000, 0x04010004,
|
607 |
+
0x04000104, 0x00010000, 0x04000000, 0x04010104,
|
608 |
+
0x00000004, 0x00010104, 0x00010100, 0x04000004,
|
609 |
+
0x04010000, 0x04000104, 0x00000104, 0x04010000,
|
610 |
+
0x00010104, 0x00000004, 0x04010004, 0x00010100
|
611 |
+
);
|
612 |
+
|
613 |
+
/**
|
614 |
+
* Pre-permuted S-box4
|
615 |
+
*
|
616 |
+
* @var Array
|
617 |
+
* @access private
|
618 |
+
*/
|
619 |
+
var $sbox4 = array(
|
620 |
+
0x80401000, 0x80001040, 0x80001040, 0x00000040,
|
621 |
+
0x00401040, 0x80400040, 0x80400000, 0x80001000,
|
622 |
+
0x00000000, 0x00401000, 0x00401000, 0x80401040,
|
623 |
+
0x80000040, 0x00000000, 0x00400040, 0x80400000,
|
624 |
+
0x80000000, 0x00001000, 0x00400000, 0x80401000,
|
625 |
+
0x00000040, 0x00400000, 0x80001000, 0x00001040,
|
626 |
+
0x80400040, 0x80000000, 0x00001040, 0x00400040,
|
627 |
+
0x00001000, 0x00401040, 0x80401040, 0x80000040,
|
628 |
+
0x00400040, 0x80400000, 0x00401000, 0x80401040,
|
629 |
+
0x80000040, 0x00000000, 0x00000000, 0x00401000,
|
630 |
+
0x00001040, 0x00400040, 0x80400040, 0x80000000,
|
631 |
+
0x80401000, 0x80001040, 0x80001040, 0x00000040,
|
632 |
+
0x80401040, 0x80000040, 0x80000000, 0x00001000,
|
633 |
+
0x80400000, 0x80001000, 0x00401040, 0x80400040,
|
634 |
+
0x80001000, 0x00001040, 0x00400000, 0x80401000,
|
635 |
+
0x00000040, 0x00400000, 0x00001000, 0x00401040
|
636 |
+
);
|
637 |
+
|
638 |
+
/**
|
639 |
+
* Pre-permuted S-box5
|
640 |
+
*
|
641 |
+
* @var Array
|
642 |
+
* @access private
|
643 |
+
*/
|
644 |
+
var $sbox5 = array(
|
645 |
+
0x00000080, 0x01040080, 0x01040000, 0x21000080,
|
646 |
+
0x00040000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|