@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | /** |
| 71 | 71 | * Returns the filename with encrypted suffix |
| 72 | 72 | * |
| 73 | - * @param $filename |
|
| 73 | + * @param string $filename |
|
| 74 | 74 | * @return string |
| 75 | 75 | */ |
| 76 | 76 | public function get_encrypted_target_backup_file_name( $filename ) { |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | /** |
| 82 | 82 | * Returns the filename without encrypted suffix |
| 83 | 83 | * |
| 84 | - * @param $filename |
|
| 84 | + * @param string $filename |
|
| 85 | 85 | * @return string |
| 86 | 86 | */ |
| 87 | 87 | public function get_decrypted_target_backup_file_name( $filename ) { |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * @param string $dest File name where the encryped file should be written to. |
| 97 | 97 | * @param string $key The key used for the encryption |
| 98 | 98 | * @param int $start Start position for reading when doing incremental mode. |
| 99 | - * @param string $iv The IV key to use. |
|
| 99 | + * @param integer $iv The IV key to use. |
|
| 100 | 100 | * @param bool $verification Weather we should we try to verify the decryption. |
| 101 | 101 | * @return string|false Returns the file name that has been created or FALSE if an error occured |
| 102 | 102 | */ |
@@ -206,6 +206,9 @@ discard block |
||
| 206 | 206 | return array("target_file" => $dest, "finished" => 1); |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | + /** |
|
| 210 | + * @param string $file |
|
| 211 | + */ |
|
| 209 | 212 | public function verify_encrypted_file($file) { |
| 210 | 213 | if(is_object($this->logger)) { |
| 211 | 214 | $this->logger->info(sprintf('Verifying encrypted file %s', $file)); |
@@ -224,7 +227,7 @@ discard block |
||
| 224 | 227 | * @param string $dest File name where the decryped file should be written to. |
| 225 | 228 | * @param string $key The key used for the decryption (must be the same as for encryption) |
| 226 | 229 | * @param int $start Start position for reading when doing incremental mode. |
| 227 | - * @param string $iv The IV key to use. |
|
| 230 | + * @param integer $iv The IV key to use. |
|
| 228 | 231 | * @return string|false Returns the file name that has been created or FALSE if an error occured |
| 229 | 232 | */ |
| 230 | 233 | public function decrypt_file($source, $dest = "", $key = "", $start = 0, $iv = 0, $recursive = false) |
@@ -10,370 +10,370 @@ |
||
| 10 | 10 | |
| 11 | 11 | class Xcloner_Encryption |
| 12 | 12 | { |
| 13 | - const FILE_ENCRYPTION_BLOCKS = 1024*1024; |
|
| 14 | - const FILE_ENCRYPTION_SUFFIX = ".encrypted"; |
|
| 15 | - const FILE_DECRYPTION_SUFFIX = ".decrypted"; |
|
| 16 | - |
|
| 17 | - private $xcloner_settings; |
|
| 18 | - private $logger; |
|
| 19 | - private $verification = false; |
|
| 20 | - |
|
| 21 | - public function __construct(Xcloner $xcloner_container) |
|
| 22 | - { |
|
| 23 | - $this->xcloner_container = $xcloner_container; |
|
| 24 | - if(method_exists($xcloner_container, 'get_xcloner_settings')) { |
|
| 25 | - $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
|
| 26 | - }else{ |
|
| 27 | - $this->xcloner_settings = ""; |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - if(method_exists($xcloner_container, 'get_xcloner_logger')) { |
|
| 31 | - $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_encryption"); |
|
| 32 | - }else{ |
|
| 33 | - $this->logger = ""; |
|
| 34 | - } |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Returns the backup encryption key |
|
| 39 | - * |
|
| 40 | - * @return SECURE_AUTH_SALT|null |
|
| 41 | - */ |
|
| 42 | - public function get_backup_encryption_key() |
|
| 43 | - { |
|
| 44 | - if(is_object($this->xcloner_settings)) { |
|
| 45 | - return $this->xcloner_settings->get_xcloner_encryption_key(); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - return ""; |
|
| 49 | - |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Check if provided filename has encrypted suffix |
|
| 54 | - * |
|
| 55 | - * @param $filename |
|
| 56 | - * @return bool |
|
| 57 | - */ |
|
| 58 | - public function is_encrypted_file($filename) { |
|
| 59 | - $fp = fopen($this->get_xcloner_path() .$filename, 'r'); |
|
| 60 | - $encryption_length = fread($fp, 16); |
|
| 61 | - fclose($fp); |
|
| 62 | - if(is_numeric($encryption_length)) { |
|
| 63 | - return true; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - return false; |
|
| 67 | - |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Returns the filename with encrypted suffix |
|
| 72 | - * |
|
| 73 | - * @param $filename |
|
| 74 | - * @return string |
|
| 75 | - */ |
|
| 76 | - public function get_encrypted_target_backup_file_name( $filename ) { |
|
| 77 | - |
|
| 78 | - return str_replace(self::FILE_DECRYPTION_SUFFIX, "", $filename) . self::FILE_ENCRYPTION_SUFFIX; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Returns the filename without encrypted suffix |
|
| 83 | - * |
|
| 84 | - * @param $filename |
|
| 85 | - * @return string |
|
| 86 | - */ |
|
| 87 | - public function get_decrypted_target_backup_file_name( $filename ) { |
|
| 88 | - |
|
| 89 | - return str_replace(self::FILE_ENCRYPTION_SUFFIX, "", $filename) . self::FILE_DECRYPTION_SUFFIX; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Encrypt the passed file and saves the result in a new file with ".enc" as suffix. |
|
| 94 | - * |
|
| 95 | - * @param string $source Path to file that should be encrypted |
|
| 96 | - * @param string $dest File name where the encryped file should be written to. |
|
| 97 | - * @param string $key The key used for the encryption |
|
| 98 | - * @param int $start Start position for reading when doing incremental mode. |
|
| 99 | - * @param string $iv The IV key to use. |
|
| 100 | - * @param bool $verification Weather we should we try to verify the decryption. |
|
| 101 | - * @return string|false Returns the file name that has been created or FALSE if an error occured |
|
| 102 | - */ |
|
| 103 | - public function encrypt_file($source, $dest = "" , $key= "", $start = 0, $iv = 0, $verification = true, $recursive = false) |
|
| 104 | - { |
|
| 105 | - if(is_object($this->logger)) { |
|
| 106 | - $this->logger->info(sprintf('Encrypting file %s at position %d IV %s', $source, $start, base64_encode($iv))); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - //$key = substr(sha1($key, true), 0, 16); |
|
| 110 | - if(!$key){ |
|
| 111 | - $key = self::get_backup_encryption_key(); |
|
| 112 | - } |
|
| 113 | - $key_digest = openssl_digest ($key, "md5", true); |
|
| 114 | - |
|
| 115 | - $keep_local = 1; |
|
| 116 | - if(!$dest) { |
|
| 117 | - $dest = $this->get_encrypted_target_backup_file_name($source); |
|
| 118 | - $keep_local = 0; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - if(!$iv || !$start) { |
|
| 122 | - //$iv = openssl_random_pseudo_bytes(16); |
|
| 123 | - $iv = str_pad(self::FILE_ENCRYPTION_BLOCKS, 16, "0000000000000000", STR_PAD_LEFT); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - if( !$start ) { |
|
| 127 | - $fpOut = fopen($this->get_xcloner_path() .$dest, 'w'); |
|
| 128 | - }else{ |
|
| 129 | - $fpOut = fopen($this->get_xcloner_path() .$dest, 'a'); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - if ( $fpOut ) { |
|
| 133 | - |
|
| 134 | - // Put the initialization vector to the beginning of the file |
|
| 135 | - if(!$start) { |
|
| 136 | - fwrite($fpOut, $iv); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - if (file_exists($this->get_xcloner_path() .$source) && |
|
| 140 | - $fpIn = fopen($this->get_xcloner_path() .$source, 'rb')) { |
|
| 141 | - |
|
| 142 | - fseek($fpIn, (int)$start); |
|
| 143 | - |
|
| 144 | - if (!feof($fpIn)) { |
|
| 145 | - |
|
| 146 | - $plaintext = fread($fpIn, 16 * self::FILE_ENCRYPTION_BLOCKS); |
|
| 147 | - $ciphertext = openssl_encrypt($plaintext, 'AES-128-CBC', $key_digest, OPENSSL_RAW_DATA, $iv); |
|
| 148 | - |
|
| 149 | - // Use the first 16 bytes of the ciphertext as the next initialization vector |
|
| 150 | - $iv = substr($ciphertext, 0, 16); |
|
| 151 | - //$iv = openssl_random_pseudo_bytes(16); |
|
| 152 | - |
|
| 153 | - fwrite($fpOut, $ciphertext); |
|
| 154 | - |
|
| 155 | - $start = ftell($fpIn); |
|
| 156 | - |
|
| 157 | - fclose($fpOut ); |
|
| 158 | - |
|
| 159 | - if(!feof($fpIn)) { |
|
| 160 | - fclose($fpIn); |
|
| 161 | - //echo "\n NEW:".$key.md5($iv); |
|
| 162 | - //self::encryptFile($source, $dest, $key, $start, $iv); |
|
| 163 | - if($recursive ){ |
|
| 164 | - $this->encrypt_file($source, $dest, $key, $start, ($iv), $verification, $recursive); |
|
| 165 | - }else { |
|
| 166 | - |
|
| 167 | - if(($iv) != base64_decode(base64_encode($iv))) |
|
| 168 | - { |
|
| 169 | - throw new \Exception('Could not encode IV for transport'); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - return array( |
|
| 173 | - "start" => $start, |
|
| 174 | - "iv" => base64_encode($iv), |
|
| 175 | - "target_file" => $dest, |
|
| 176 | - "finished" => 0 |
|
| 177 | - ); |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - } |
|
| 182 | - } else { |
|
| 183 | - if(is_object($this->logger)) { |
|
| 184 | - $this->logger->error('Unable to read source file for encryption.'); |
|
| 185 | - } |
|
| 186 | - throw new \Exception("Unable to read source file for encryption."); |
|
| 187 | - } |
|
| 188 | - } else { |
|
| 189 | - if(is_object($this->logger)) { |
|
| 190 | - $this->logger->error('Unable to write destination file for encryption.'); |
|
| 191 | - } |
|
| 192 | - throw new \Exception("Unable to write destination file for encryption."); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - if($verification) { |
|
| 196 | - $this->verify_encrypted_file($dest); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - //we replace the original backup with the encrypted one |
|
| 200 | - if( !$keep_local && copy($this->get_xcloner_path() .$dest, |
|
| 201 | - $this->get_xcloner_path() .$source) ) { |
|
| 202 | - unlink($this->get_xcloner_path() .$dest); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - return array("target_file" => $dest, "finished" => 1); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - public function verify_encrypted_file($file) { |
|
| 210 | - if(is_object($this->logger)) { |
|
| 211 | - $this->logger->info(sprintf('Verifying encrypted file %s', $file)); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - $this->verification = true; |
|
| 215 | - $this->decrypt_file($file); |
|
| 216 | - $this->verification = false; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Dencrypt the passed file and saves the result in a new file, removing the |
|
| 221 | - * last 4 characters from file name. |
|
| 222 | - * |
|
| 223 | - * @param string $source Path to file that should be decrypted |
|
| 224 | - * @param string $dest File name where the decryped file should be written to. |
|
| 225 | - * @param string $key The key used for the decryption (must be the same as for encryption) |
|
| 226 | - * @param int $start Start position for reading when doing incremental mode. |
|
| 227 | - * @param string $iv The IV key to use. |
|
| 228 | - * @return string|false Returns the file name that has been created or FALSE if an error occured |
|
| 229 | - */ |
|
| 230 | - public function decrypt_file($source, $dest = "", $key = "", $start = 0, $iv = 0, $recursive = false) |
|
| 231 | - { |
|
| 232 | - if(is_object($this->logger)) { |
|
| 233 | - $this->logger->info(sprintf('Decrypting file %s at position %d with IV %s', $source, $start, base64_encode($iv))); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - //$key = substr(sha1($key, true), 0, 16); |
|
| 237 | - if(!$key){ |
|
| 238 | - $key = self::get_backup_encryption_key(); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - $key_digest = openssl_digest ($key, "md5", true); |
|
| 242 | - |
|
| 243 | - $keep_local = 1; |
|
| 244 | - if(!$dest) { |
|
| 245 | - $dest = $this->get_decrypted_target_backup_file_name($source); |
|
| 246 | - $keep_local = 0; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - if( !$start ) { |
|
| 250 | - if($this->verification){ |
|
| 251 | - $fpOut = fopen("php://stdout", 'w'); |
|
| 252 | - }else { |
|
| 253 | - $fpOut = fopen($this->get_xcloner_path() . $dest, 'w'); |
|
| 254 | - } |
|
| 255 | - }else{ |
|
| 256 | - if($this->verification){ |
|
| 257 | - $fpOut = fopen("php://stdout", 'a'); |
|
| 258 | - }else { |
|
| 259 | - $fpOut = fopen($this->get_xcloner_path() . $dest, 'a'); |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - if ( $fpOut ) { |
|
| 264 | - if ( file_exists($this->get_xcloner_path() .$source) && |
|
| 265 | - $fpIn = fopen($this->get_xcloner_path() .$source, 'rb')) { |
|
| 266 | - |
|
| 267 | - $encryption_length = (int)fread($fpIn, 16); |
|
| 268 | - if(!$encryption_length) { |
|
| 269 | - $encryption_length = self::FILE_ENCRYPTION_BLOCKS; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - fseek($fpIn, (int)$start); |
|
| 273 | - |
|
| 274 | - // Get the initialzation vector from the beginning of the file |
|
| 275 | - if(!$iv) { |
|
| 276 | - $iv = fread($fpIn, 16); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - if (!feof($fpIn)) { |
|
| 280 | - |
|
| 281 | - // we have to read one block more for decrypting than for encrypting |
|
| 282 | - $ciphertext = fread($fpIn, 16 * ($encryption_length + 1)); |
|
| 283 | - $plaintext = openssl_decrypt($ciphertext, 'AES-128-CBC', $key_digest, OPENSSL_RAW_DATA, $iv); |
|
| 284 | - |
|
| 285 | - if(!$plaintext){ |
|
| 286 | - unlink($this->get_xcloner_path() . $dest); |
|
| 287 | - if(is_object($this->logger)) { |
|
| 288 | - $this->logger->error('Backup decryption failed, please check your provided Encryption Key.'); |
|
| 289 | - } |
|
| 290 | - throw new \Exception("Backup decryption failed, please check your provided Encryption Key."); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - // Use the first 16 bytes of the ciphertext as the next initialization vector |
|
| 294 | - $iv = substr($ciphertext, 0, 16); |
|
| 295 | - |
|
| 296 | - if( !$this->verification) { |
|
| 297 | - fwrite($fpOut, $plaintext); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - $start = ftell($fpIn); |
|
| 301 | - |
|
| 302 | - fclose($fpOut ); |
|
| 303 | - |
|
| 304 | - if(!feof($fpIn)) { |
|
| 305 | - fclose($fpIn); |
|
| 306 | - if($this->verification || $recursive) { |
|
| 307 | - $ciphertext = ""; |
|
| 308 | - $plaintext = ""; |
|
| 309 | - $this->decrypt_file($source, $dest, $key, $start, $iv, $recursive); |
|
| 310 | - }else { |
|
| 311 | - if(($iv) != base64_decode(base64_encode($iv))) |
|
| 312 | - { |
|
| 313 | - throw new \Exception('Could not encode IV for transport'); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - return array( |
|
| 317 | - "start" => $start, |
|
| 318 | - "encryption_length" => $encryption_length, |
|
| 319 | - "iv" => base64_encode($iv), |
|
| 320 | - "target_file" => $dest, |
|
| 321 | - "finished" => 0 |
|
| 322 | - ); |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - } |
|
| 327 | - } else { |
|
| 328 | - if(is_object($this->logger)) { |
|
| 329 | - $this->logger->error('Unable to read source file for decryption'); |
|
| 330 | - } |
|
| 331 | - throw new \Exception("Unable to read source file for decryption"); |
|
| 332 | - } |
|
| 333 | - } else { |
|
| 334 | - if(is_object($this->logger)) { |
|
| 335 | - $this->logger->error('Unable to write destination file for decryption'); |
|
| 336 | - } |
|
| 337 | - throw new \Exception("Unable to write destination file for decryption"); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - //we replace the original backup with the encrypted one |
|
| 341 | - if( !$keep_local && !$this->verification && copy($this->get_xcloner_path() .$dest, |
|
| 342 | - $this->get_xcloner_path() .$source) ) { |
|
| 343 | - unlink($this->get_xcloner_path() .$dest); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - return array("target_file" => $dest, "finished" => 1); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - public function get_xcloner_path(){ |
|
| 350 | - if(is_object($this->xcloner_settings)) { |
|
| 351 | - return $this->xcloner_settings->get_xcloner_store_path() . DS; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - return null; |
|
| 355 | - } |
|
| 13 | + const FILE_ENCRYPTION_BLOCKS = 1024*1024; |
|
| 14 | + const FILE_ENCRYPTION_SUFFIX = ".encrypted"; |
|
| 15 | + const FILE_DECRYPTION_SUFFIX = ".decrypted"; |
|
| 16 | + |
|
| 17 | + private $xcloner_settings; |
|
| 18 | + private $logger; |
|
| 19 | + private $verification = false; |
|
| 20 | + |
|
| 21 | + public function __construct(Xcloner $xcloner_container) |
|
| 22 | + { |
|
| 23 | + $this->xcloner_container = $xcloner_container; |
|
| 24 | + if(method_exists($xcloner_container, 'get_xcloner_settings')) { |
|
| 25 | + $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
|
| 26 | + }else{ |
|
| 27 | + $this->xcloner_settings = ""; |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + if(method_exists($xcloner_container, 'get_xcloner_logger')) { |
|
| 31 | + $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_encryption"); |
|
| 32 | + }else{ |
|
| 33 | + $this->logger = ""; |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Returns the backup encryption key |
|
| 39 | + * |
|
| 40 | + * @return SECURE_AUTH_SALT|null |
|
| 41 | + */ |
|
| 42 | + public function get_backup_encryption_key() |
|
| 43 | + { |
|
| 44 | + if(is_object($this->xcloner_settings)) { |
|
| 45 | + return $this->xcloner_settings->get_xcloner_encryption_key(); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + return ""; |
|
| 49 | + |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Check if provided filename has encrypted suffix |
|
| 54 | + * |
|
| 55 | + * @param $filename |
|
| 56 | + * @return bool |
|
| 57 | + */ |
|
| 58 | + public function is_encrypted_file($filename) { |
|
| 59 | + $fp = fopen($this->get_xcloner_path() .$filename, 'r'); |
|
| 60 | + $encryption_length = fread($fp, 16); |
|
| 61 | + fclose($fp); |
|
| 62 | + if(is_numeric($encryption_length)) { |
|
| 63 | + return true; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + return false; |
|
| 67 | + |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Returns the filename with encrypted suffix |
|
| 72 | + * |
|
| 73 | + * @param $filename |
|
| 74 | + * @return string |
|
| 75 | + */ |
|
| 76 | + public function get_encrypted_target_backup_file_name( $filename ) { |
|
| 77 | + |
|
| 78 | + return str_replace(self::FILE_DECRYPTION_SUFFIX, "", $filename) . self::FILE_ENCRYPTION_SUFFIX; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Returns the filename without encrypted suffix |
|
| 83 | + * |
|
| 84 | + * @param $filename |
|
| 85 | + * @return string |
|
| 86 | + */ |
|
| 87 | + public function get_decrypted_target_backup_file_name( $filename ) { |
|
| 88 | + |
|
| 89 | + return str_replace(self::FILE_ENCRYPTION_SUFFIX, "", $filename) . self::FILE_DECRYPTION_SUFFIX; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Encrypt the passed file and saves the result in a new file with ".enc" as suffix. |
|
| 94 | + * |
|
| 95 | + * @param string $source Path to file that should be encrypted |
|
| 96 | + * @param string $dest File name where the encryped file should be written to. |
|
| 97 | + * @param string $key The key used for the encryption |
|
| 98 | + * @param int $start Start position for reading when doing incremental mode. |
|
| 99 | + * @param string $iv The IV key to use. |
|
| 100 | + * @param bool $verification Weather we should we try to verify the decryption. |
|
| 101 | + * @return string|false Returns the file name that has been created or FALSE if an error occured |
|
| 102 | + */ |
|
| 103 | + public function encrypt_file($source, $dest = "" , $key= "", $start = 0, $iv = 0, $verification = true, $recursive = false) |
|
| 104 | + { |
|
| 105 | + if(is_object($this->logger)) { |
|
| 106 | + $this->logger->info(sprintf('Encrypting file %s at position %d IV %s', $source, $start, base64_encode($iv))); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + //$key = substr(sha1($key, true), 0, 16); |
|
| 110 | + if(!$key){ |
|
| 111 | + $key = self::get_backup_encryption_key(); |
|
| 112 | + } |
|
| 113 | + $key_digest = openssl_digest ($key, "md5", true); |
|
| 114 | + |
|
| 115 | + $keep_local = 1; |
|
| 116 | + if(!$dest) { |
|
| 117 | + $dest = $this->get_encrypted_target_backup_file_name($source); |
|
| 118 | + $keep_local = 0; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + if(!$iv || !$start) { |
|
| 122 | + //$iv = openssl_random_pseudo_bytes(16); |
|
| 123 | + $iv = str_pad(self::FILE_ENCRYPTION_BLOCKS, 16, "0000000000000000", STR_PAD_LEFT); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + if( !$start ) { |
|
| 127 | + $fpOut = fopen($this->get_xcloner_path() .$dest, 'w'); |
|
| 128 | + }else{ |
|
| 129 | + $fpOut = fopen($this->get_xcloner_path() .$dest, 'a'); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + if ( $fpOut ) { |
|
| 133 | + |
|
| 134 | + // Put the initialization vector to the beginning of the file |
|
| 135 | + if(!$start) { |
|
| 136 | + fwrite($fpOut, $iv); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + if (file_exists($this->get_xcloner_path() .$source) && |
|
| 140 | + $fpIn = fopen($this->get_xcloner_path() .$source, 'rb')) { |
|
| 141 | + |
|
| 142 | + fseek($fpIn, (int)$start); |
|
| 143 | + |
|
| 144 | + if (!feof($fpIn)) { |
|
| 145 | + |
|
| 146 | + $plaintext = fread($fpIn, 16 * self::FILE_ENCRYPTION_BLOCKS); |
|
| 147 | + $ciphertext = openssl_encrypt($plaintext, 'AES-128-CBC', $key_digest, OPENSSL_RAW_DATA, $iv); |
|
| 148 | + |
|
| 149 | + // Use the first 16 bytes of the ciphertext as the next initialization vector |
|
| 150 | + $iv = substr($ciphertext, 0, 16); |
|
| 151 | + //$iv = openssl_random_pseudo_bytes(16); |
|
| 152 | + |
|
| 153 | + fwrite($fpOut, $ciphertext); |
|
| 154 | + |
|
| 155 | + $start = ftell($fpIn); |
|
| 156 | + |
|
| 157 | + fclose($fpOut ); |
|
| 158 | + |
|
| 159 | + if(!feof($fpIn)) { |
|
| 160 | + fclose($fpIn); |
|
| 161 | + //echo "\n NEW:".$key.md5($iv); |
|
| 162 | + //self::encryptFile($source, $dest, $key, $start, $iv); |
|
| 163 | + if($recursive ){ |
|
| 164 | + $this->encrypt_file($source, $dest, $key, $start, ($iv), $verification, $recursive); |
|
| 165 | + }else { |
|
| 166 | + |
|
| 167 | + if(($iv) != base64_decode(base64_encode($iv))) |
|
| 168 | + { |
|
| 169 | + throw new \Exception('Could not encode IV for transport'); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + return array( |
|
| 173 | + "start" => $start, |
|
| 174 | + "iv" => base64_encode($iv), |
|
| 175 | + "target_file" => $dest, |
|
| 176 | + "finished" => 0 |
|
| 177 | + ); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + } |
|
| 182 | + } else { |
|
| 183 | + if(is_object($this->logger)) { |
|
| 184 | + $this->logger->error('Unable to read source file for encryption.'); |
|
| 185 | + } |
|
| 186 | + throw new \Exception("Unable to read source file for encryption."); |
|
| 187 | + } |
|
| 188 | + } else { |
|
| 189 | + if(is_object($this->logger)) { |
|
| 190 | + $this->logger->error('Unable to write destination file for encryption.'); |
|
| 191 | + } |
|
| 192 | + throw new \Exception("Unable to write destination file for encryption."); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + if($verification) { |
|
| 196 | + $this->verify_encrypted_file($dest); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + //we replace the original backup with the encrypted one |
|
| 200 | + if( !$keep_local && copy($this->get_xcloner_path() .$dest, |
|
| 201 | + $this->get_xcloner_path() .$source) ) { |
|
| 202 | + unlink($this->get_xcloner_path() .$dest); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + return array("target_file" => $dest, "finished" => 1); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + public function verify_encrypted_file($file) { |
|
| 210 | + if(is_object($this->logger)) { |
|
| 211 | + $this->logger->info(sprintf('Verifying encrypted file %s', $file)); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + $this->verification = true; |
|
| 215 | + $this->decrypt_file($file); |
|
| 216 | + $this->verification = false; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Dencrypt the passed file and saves the result in a new file, removing the |
|
| 221 | + * last 4 characters from file name. |
|
| 222 | + * |
|
| 223 | + * @param string $source Path to file that should be decrypted |
|
| 224 | + * @param string $dest File name where the decryped file should be written to. |
|
| 225 | + * @param string $key The key used for the decryption (must be the same as for encryption) |
|
| 226 | + * @param int $start Start position for reading when doing incremental mode. |
|
| 227 | + * @param string $iv The IV key to use. |
|
| 228 | + * @return string|false Returns the file name that has been created or FALSE if an error occured |
|
| 229 | + */ |
|
| 230 | + public function decrypt_file($source, $dest = "", $key = "", $start = 0, $iv = 0, $recursive = false) |
|
| 231 | + { |
|
| 232 | + if(is_object($this->logger)) { |
|
| 233 | + $this->logger->info(sprintf('Decrypting file %s at position %d with IV %s', $source, $start, base64_encode($iv))); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + //$key = substr(sha1($key, true), 0, 16); |
|
| 237 | + if(!$key){ |
|
| 238 | + $key = self::get_backup_encryption_key(); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + $key_digest = openssl_digest ($key, "md5", true); |
|
| 242 | + |
|
| 243 | + $keep_local = 1; |
|
| 244 | + if(!$dest) { |
|
| 245 | + $dest = $this->get_decrypted_target_backup_file_name($source); |
|
| 246 | + $keep_local = 0; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + if( !$start ) { |
|
| 250 | + if($this->verification){ |
|
| 251 | + $fpOut = fopen("php://stdout", 'w'); |
|
| 252 | + }else { |
|
| 253 | + $fpOut = fopen($this->get_xcloner_path() . $dest, 'w'); |
|
| 254 | + } |
|
| 255 | + }else{ |
|
| 256 | + if($this->verification){ |
|
| 257 | + $fpOut = fopen("php://stdout", 'a'); |
|
| 258 | + }else { |
|
| 259 | + $fpOut = fopen($this->get_xcloner_path() . $dest, 'a'); |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + if ( $fpOut ) { |
|
| 264 | + if ( file_exists($this->get_xcloner_path() .$source) && |
|
| 265 | + $fpIn = fopen($this->get_xcloner_path() .$source, 'rb')) { |
|
| 266 | + |
|
| 267 | + $encryption_length = (int)fread($fpIn, 16); |
|
| 268 | + if(!$encryption_length) { |
|
| 269 | + $encryption_length = self::FILE_ENCRYPTION_BLOCKS; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + fseek($fpIn, (int)$start); |
|
| 273 | + |
|
| 274 | + // Get the initialzation vector from the beginning of the file |
|
| 275 | + if(!$iv) { |
|
| 276 | + $iv = fread($fpIn, 16); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + if (!feof($fpIn)) { |
|
| 280 | + |
|
| 281 | + // we have to read one block more for decrypting than for encrypting |
|
| 282 | + $ciphertext = fread($fpIn, 16 * ($encryption_length + 1)); |
|
| 283 | + $plaintext = openssl_decrypt($ciphertext, 'AES-128-CBC', $key_digest, OPENSSL_RAW_DATA, $iv); |
|
| 284 | + |
|
| 285 | + if(!$plaintext){ |
|
| 286 | + unlink($this->get_xcloner_path() . $dest); |
|
| 287 | + if(is_object($this->logger)) { |
|
| 288 | + $this->logger->error('Backup decryption failed, please check your provided Encryption Key.'); |
|
| 289 | + } |
|
| 290 | + throw new \Exception("Backup decryption failed, please check your provided Encryption Key."); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + // Use the first 16 bytes of the ciphertext as the next initialization vector |
|
| 294 | + $iv = substr($ciphertext, 0, 16); |
|
| 295 | + |
|
| 296 | + if( !$this->verification) { |
|
| 297 | + fwrite($fpOut, $plaintext); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + $start = ftell($fpIn); |
|
| 301 | + |
|
| 302 | + fclose($fpOut ); |
|
| 303 | + |
|
| 304 | + if(!feof($fpIn)) { |
|
| 305 | + fclose($fpIn); |
|
| 306 | + if($this->verification || $recursive) { |
|
| 307 | + $ciphertext = ""; |
|
| 308 | + $plaintext = ""; |
|
| 309 | + $this->decrypt_file($source, $dest, $key, $start, $iv, $recursive); |
|
| 310 | + }else { |
|
| 311 | + if(($iv) != base64_decode(base64_encode($iv))) |
|
| 312 | + { |
|
| 313 | + throw new \Exception('Could not encode IV for transport'); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + return array( |
|
| 317 | + "start" => $start, |
|
| 318 | + "encryption_length" => $encryption_length, |
|
| 319 | + "iv" => base64_encode($iv), |
|
| 320 | + "target_file" => $dest, |
|
| 321 | + "finished" => 0 |
|
| 322 | + ); |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + } |
|
| 327 | + } else { |
|
| 328 | + if(is_object($this->logger)) { |
|
| 329 | + $this->logger->error('Unable to read source file for decryption'); |
|
| 330 | + } |
|
| 331 | + throw new \Exception("Unable to read source file for decryption"); |
|
| 332 | + } |
|
| 333 | + } else { |
|
| 334 | + if(is_object($this->logger)) { |
|
| 335 | + $this->logger->error('Unable to write destination file for decryption'); |
|
| 336 | + } |
|
| 337 | + throw new \Exception("Unable to write destination file for decryption"); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + //we replace the original backup with the encrypted one |
|
| 341 | + if( !$keep_local && !$this->verification && copy($this->get_xcloner_path() .$dest, |
|
| 342 | + $this->get_xcloner_path() .$source) ) { |
|
| 343 | + unlink($this->get_xcloner_path() .$dest); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + return array("target_file" => $dest, "finished" => 1); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + public function get_xcloner_path(){ |
|
| 350 | + if(is_object($this->xcloner_settings)) { |
|
| 351 | + return $this->xcloner_settings->get_xcloner_store_path() . DS; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + return null; |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | |
| 360 | 360 | try { |
| 361 | 361 | |
| 362 | - if(isset($argv[1])) { |
|
| 363 | - |
|
| 364 | - class Xcloner { |
|
| 365 | - public function __construct() |
|
| 366 | - { |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - $xcloner_encryption = new Xcloner_Encryption( new Xcloner() ); |
|
| 370 | - |
|
| 371 | - if ($argv[1] == "-e") { |
|
| 372 | - $xcloner_encryption->encrypt_file($argv[2], $argv[2] . ".enc", $argv[4], '', '', '', true); |
|
| 373 | - } elseif ($argv[1] == "-d") { |
|
| 374 | - $xcloner_encryption->decrypt_file($argv[2], $argv[2] . ".dec", $argv[4], '', '', true); |
|
| 375 | - } |
|
| 376 | - } |
|
| 362 | + if(isset($argv[1])) { |
|
| 363 | + |
|
| 364 | + class Xcloner { |
|
| 365 | + public function __construct() |
|
| 366 | + { |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + $xcloner_encryption = new Xcloner_Encryption( new Xcloner() ); |
|
| 370 | + |
|
| 371 | + if ($argv[1] == "-e") { |
|
| 372 | + $xcloner_encryption->encrypt_file($argv[2], $argv[2] . ".enc", $argv[4], '', '', '', true); |
|
| 373 | + } elseif ($argv[1] == "-d") { |
|
| 374 | + $xcloner_encryption->decrypt_file($argv[2], $argv[2] . ".dec", $argv[4], '', '', true); |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | 377 | }catch(\Exception $e) { |
| 378 | - echo "CAUGHT: " . $e->getMessage(); |
|
| 378 | + echo "CAUGHT: " . $e->getMessage(); |
|
| 379 | 379 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | class Xcloner_Encryption |
| 12 | 12 | { |
| 13 | - const FILE_ENCRYPTION_BLOCKS = 1024*1024; |
|
| 13 | + const FILE_ENCRYPTION_BLOCKS = 1024 * 1024; |
|
| 14 | 14 | const FILE_ENCRYPTION_SUFFIX = ".encrypted"; |
| 15 | 15 | const FILE_DECRYPTION_SUFFIX = ".decrypted"; |
| 16 | 16 | |
@@ -21,15 +21,15 @@ discard block |
||
| 21 | 21 | public function __construct(Xcloner $xcloner_container) |
| 22 | 22 | { |
| 23 | 23 | $this->xcloner_container = $xcloner_container; |
| 24 | - if(method_exists($xcloner_container, 'get_xcloner_settings')) { |
|
| 24 | + if (method_exists($xcloner_container, 'get_xcloner_settings')) { |
|
| 25 | 25 | $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
| 26 | - }else{ |
|
| 26 | + } else { |
|
| 27 | 27 | $this->xcloner_settings = ""; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - if(method_exists($xcloner_container, 'get_xcloner_logger')) { |
|
| 30 | + if (method_exists($xcloner_container, 'get_xcloner_logger')) { |
|
| 31 | 31 | $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_encryption"); |
| 32 | - }else{ |
|
| 32 | + } else { |
|
| 33 | 33 | $this->logger = ""; |
| 34 | 34 | } |
| 35 | 35 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function get_backup_encryption_key() |
| 43 | 43 | { |
| 44 | - if(is_object($this->xcloner_settings)) { |
|
| 44 | + if (is_object($this->xcloner_settings)) { |
|
| 45 | 45 | return $this->xcloner_settings->get_xcloner_encryption_key(); |
| 46 | 46 | } |
| 47 | 47 | |
@@ -56,10 +56,10 @@ discard block |
||
| 56 | 56 | * @return bool |
| 57 | 57 | */ |
| 58 | 58 | public function is_encrypted_file($filename) { |
| 59 | - $fp = fopen($this->get_xcloner_path() .$filename, 'r'); |
|
| 59 | + $fp = fopen($this->get_xcloner_path().$filename, 'r'); |
|
| 60 | 60 | $encryption_length = fread($fp, 16); |
| 61 | 61 | fclose($fp); |
| 62 | - if(is_numeric($encryption_length)) { |
|
| 62 | + if (is_numeric($encryption_length)) { |
|
| 63 | 63 | return true; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -73,9 +73,9 @@ discard block |
||
| 73 | 73 | * @param $filename |
| 74 | 74 | * @return string |
| 75 | 75 | */ |
| 76 | - public function get_encrypted_target_backup_file_name( $filename ) { |
|
| 76 | + public function get_encrypted_target_backup_file_name($filename) { |
|
| 77 | 77 | |
| 78 | - return str_replace(self::FILE_DECRYPTION_SUFFIX, "", $filename) . self::FILE_ENCRYPTION_SUFFIX; |
|
| 78 | + return str_replace(self::FILE_DECRYPTION_SUFFIX, "", $filename).self::FILE_ENCRYPTION_SUFFIX; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | * @param $filename |
| 85 | 85 | * @return string |
| 86 | 86 | */ |
| 87 | - public function get_decrypted_target_backup_file_name( $filename ) { |
|
| 87 | + public function get_decrypted_target_backup_file_name($filename) { |
|
| 88 | 88 | |
| 89 | - return str_replace(self::FILE_ENCRYPTION_SUFFIX, "", $filename) . self::FILE_DECRYPTION_SUFFIX; |
|
| 89 | + return str_replace(self::FILE_ENCRYPTION_SUFFIX, "", $filename).self::FILE_DECRYPTION_SUFFIX; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -100,44 +100,44 @@ discard block |
||
| 100 | 100 | * @param bool $verification Weather we should we try to verify the decryption. |
| 101 | 101 | * @return string|false Returns the file name that has been created or FALSE if an error occured |
| 102 | 102 | */ |
| 103 | - public function encrypt_file($source, $dest = "" , $key= "", $start = 0, $iv = 0, $verification = true, $recursive = false) |
|
| 103 | + public function encrypt_file($source, $dest = "", $key = "", $start = 0, $iv = 0, $verification = true, $recursive = false) |
|
| 104 | 104 | { |
| 105 | - if(is_object($this->logger)) { |
|
| 105 | + if (is_object($this->logger)) { |
|
| 106 | 106 | $this->logger->info(sprintf('Encrypting file %s at position %d IV %s', $source, $start, base64_encode($iv))); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | //$key = substr(sha1($key, true), 0, 16); |
| 110 | - if(!$key){ |
|
| 110 | + if (!$key) { |
|
| 111 | 111 | $key = self::get_backup_encryption_key(); |
| 112 | 112 | } |
| 113 | - $key_digest = openssl_digest ($key, "md5", true); |
|
| 113 | + $key_digest = openssl_digest($key, "md5", true); |
|
| 114 | 114 | |
| 115 | 115 | $keep_local = 1; |
| 116 | - if(!$dest) { |
|
| 116 | + if (!$dest) { |
|
| 117 | 117 | $dest = $this->get_encrypted_target_backup_file_name($source); |
| 118 | 118 | $keep_local = 0; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - if(!$iv || !$start) { |
|
| 121 | + if (!$iv || !$start) { |
|
| 122 | 122 | //$iv = openssl_random_pseudo_bytes(16); |
| 123 | 123 | $iv = str_pad(self::FILE_ENCRYPTION_BLOCKS, 16, "0000000000000000", STR_PAD_LEFT); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - if( !$start ) { |
|
| 127 | - $fpOut = fopen($this->get_xcloner_path() .$dest, 'w'); |
|
| 128 | - }else{ |
|
| 129 | - $fpOut = fopen($this->get_xcloner_path() .$dest, 'a'); |
|
| 126 | + if (!$start) { |
|
| 127 | + $fpOut = fopen($this->get_xcloner_path().$dest, 'w'); |
|
| 128 | + } else { |
|
| 129 | + $fpOut = fopen($this->get_xcloner_path().$dest, 'a'); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if ( $fpOut ) { |
|
| 132 | + if ($fpOut) { |
|
| 133 | 133 | |
| 134 | 134 | // Put the initialization vector to the beginning of the file |
| 135 | - if(!$start) { |
|
| 135 | + if (!$start) { |
|
| 136 | 136 | fwrite($fpOut, $iv); |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - if (file_exists($this->get_xcloner_path() .$source) && |
|
| 140 | - $fpIn = fopen($this->get_xcloner_path() .$source, 'rb')) { |
|
| 139 | + if (file_exists($this->get_xcloner_path().$source) && |
|
| 140 | + $fpIn = fopen($this->get_xcloner_path().$source, 'rb')) { |
|
| 141 | 141 | |
| 142 | 142 | fseek($fpIn, (int)$start); |
| 143 | 143 | |
@@ -154,17 +154,17 @@ discard block |
||
| 154 | 154 | |
| 155 | 155 | $start = ftell($fpIn); |
| 156 | 156 | |
| 157 | - fclose($fpOut ); |
|
| 157 | + fclose($fpOut); |
|
| 158 | 158 | |
| 159 | - if(!feof($fpIn)) { |
|
| 159 | + if (!feof($fpIn)) { |
|
| 160 | 160 | fclose($fpIn); |
| 161 | 161 | //echo "\n NEW:".$key.md5($iv); |
| 162 | 162 | //self::encryptFile($source, $dest, $key, $start, $iv); |
| 163 | - if($recursive ){ |
|
| 163 | + if ($recursive) { |
|
| 164 | 164 | $this->encrypt_file($source, $dest, $key, $start, ($iv), $verification, $recursive); |
| 165 | - }else { |
|
| 165 | + } else { |
|
| 166 | 166 | |
| 167 | - if(($iv) != base64_decode(base64_encode($iv))) |
|
| 167 | + if (($iv) != base64_decode(base64_encode($iv))) |
|
| 168 | 168 | { |
| 169 | 169 | throw new \Exception('Could not encode IV for transport'); |
| 170 | 170 | } |
@@ -180,26 +180,26 @@ discard block |
||
| 180 | 180 | |
| 181 | 181 | } |
| 182 | 182 | } else { |
| 183 | - if(is_object($this->logger)) { |
|
| 183 | + if (is_object($this->logger)) { |
|
| 184 | 184 | $this->logger->error('Unable to read source file for encryption.'); |
| 185 | 185 | } |
| 186 | 186 | throw new \Exception("Unable to read source file for encryption."); |
| 187 | 187 | } |
| 188 | 188 | } else { |
| 189 | - if(is_object($this->logger)) { |
|
| 189 | + if (is_object($this->logger)) { |
|
| 190 | 190 | $this->logger->error('Unable to write destination file for encryption.'); |
| 191 | 191 | } |
| 192 | 192 | throw new \Exception("Unable to write destination file for encryption."); |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - if($verification) { |
|
| 195 | + if ($verification) { |
|
| 196 | 196 | $this->verify_encrypted_file($dest); |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | //we replace the original backup with the encrypted one |
| 200 | - if( !$keep_local && copy($this->get_xcloner_path() .$dest, |
|
| 201 | - $this->get_xcloner_path() .$source) ) { |
|
| 202 | - unlink($this->get_xcloner_path() .$dest); |
|
| 200 | + if (!$keep_local && copy($this->get_xcloner_path().$dest, |
|
| 201 | + $this->get_xcloner_path().$source)) { |
|
| 202 | + unlink($this->get_xcloner_path().$dest); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | public function verify_encrypted_file($file) { |
| 210 | - if(is_object($this->logger)) { |
|
| 210 | + if (is_object($this->logger)) { |
|
| 211 | 211 | $this->logger->info(sprintf('Verifying encrypted file %s', $file)); |
| 212 | 212 | } |
| 213 | 213 | |
@@ -229,50 +229,50 @@ discard block |
||
| 229 | 229 | */ |
| 230 | 230 | public function decrypt_file($source, $dest = "", $key = "", $start = 0, $iv = 0, $recursive = false) |
| 231 | 231 | { |
| 232 | - if(is_object($this->logger)) { |
|
| 232 | + if (is_object($this->logger)) { |
|
| 233 | 233 | $this->logger->info(sprintf('Decrypting file %s at position %d with IV %s', $source, $start, base64_encode($iv))); |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | //$key = substr(sha1($key, true), 0, 16); |
| 237 | - if(!$key){ |
|
| 237 | + if (!$key) { |
|
| 238 | 238 | $key = self::get_backup_encryption_key(); |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - $key_digest = openssl_digest ($key, "md5", true); |
|
| 241 | + $key_digest = openssl_digest($key, "md5", true); |
|
| 242 | 242 | |
| 243 | 243 | $keep_local = 1; |
| 244 | - if(!$dest) { |
|
| 244 | + if (!$dest) { |
|
| 245 | 245 | $dest = $this->get_decrypted_target_backup_file_name($source); |
| 246 | 246 | $keep_local = 0; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - if( !$start ) { |
|
| 250 | - if($this->verification){ |
|
| 249 | + if (!$start) { |
|
| 250 | + if ($this->verification) { |
|
| 251 | 251 | $fpOut = fopen("php://stdout", 'w'); |
| 252 | - }else { |
|
| 253 | - $fpOut = fopen($this->get_xcloner_path() . $dest, 'w'); |
|
| 252 | + } else { |
|
| 253 | + $fpOut = fopen($this->get_xcloner_path().$dest, 'w'); |
|
| 254 | 254 | } |
| 255 | - }else{ |
|
| 256 | - if($this->verification){ |
|
| 255 | + } else { |
|
| 256 | + if ($this->verification) { |
|
| 257 | 257 | $fpOut = fopen("php://stdout", 'a'); |
| 258 | - }else { |
|
| 259 | - $fpOut = fopen($this->get_xcloner_path() . $dest, 'a'); |
|
| 258 | + } else { |
|
| 259 | + $fpOut = fopen($this->get_xcloner_path().$dest, 'a'); |
|
| 260 | 260 | } |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - if ( $fpOut ) { |
|
| 264 | - if ( file_exists($this->get_xcloner_path() .$source) && |
|
| 265 | - $fpIn = fopen($this->get_xcloner_path() .$source, 'rb')) { |
|
| 263 | + if ($fpOut) { |
|
| 264 | + if (file_exists($this->get_xcloner_path().$source) && |
|
| 265 | + $fpIn = fopen($this->get_xcloner_path().$source, 'rb')) { |
|
| 266 | 266 | |
| 267 | 267 | $encryption_length = (int)fread($fpIn, 16); |
| 268 | - if(!$encryption_length) { |
|
| 268 | + if (!$encryption_length) { |
|
| 269 | 269 | $encryption_length = self::FILE_ENCRYPTION_BLOCKS; |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | fseek($fpIn, (int)$start); |
| 273 | 273 | |
| 274 | 274 | // Get the initialzation vector from the beginning of the file |
| 275 | - if(!$iv) { |
|
| 275 | + if (!$iv) { |
|
| 276 | 276 | $iv = fread($fpIn, 16); |
| 277 | 277 | } |
| 278 | 278 | |
@@ -282,9 +282,9 @@ discard block |
||
| 282 | 282 | $ciphertext = fread($fpIn, 16 * ($encryption_length + 1)); |
| 283 | 283 | $plaintext = openssl_decrypt($ciphertext, 'AES-128-CBC', $key_digest, OPENSSL_RAW_DATA, $iv); |
| 284 | 284 | |
| 285 | - if(!$plaintext){ |
|
| 286 | - unlink($this->get_xcloner_path() . $dest); |
|
| 287 | - if(is_object($this->logger)) { |
|
| 285 | + if (!$plaintext) { |
|
| 286 | + unlink($this->get_xcloner_path().$dest); |
|
| 287 | + if (is_object($this->logger)) { |
|
| 288 | 288 | $this->logger->error('Backup decryption failed, please check your provided Encryption Key.'); |
| 289 | 289 | } |
| 290 | 290 | throw new \Exception("Backup decryption failed, please check your provided Encryption Key."); |
@@ -293,22 +293,22 @@ discard block |
||
| 293 | 293 | // Use the first 16 bytes of the ciphertext as the next initialization vector |
| 294 | 294 | $iv = substr($ciphertext, 0, 16); |
| 295 | 295 | |
| 296 | - if( !$this->verification) { |
|
| 296 | + if (!$this->verification) { |
|
| 297 | 297 | fwrite($fpOut, $plaintext); |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | $start = ftell($fpIn); |
| 301 | 301 | |
| 302 | - fclose($fpOut ); |
|
| 302 | + fclose($fpOut); |
|
| 303 | 303 | |
| 304 | - if(!feof($fpIn)) { |
|
| 304 | + if (!feof($fpIn)) { |
|
| 305 | 305 | fclose($fpIn); |
| 306 | - if($this->verification || $recursive) { |
|
| 306 | + if ($this->verification || $recursive) { |
|
| 307 | 307 | $ciphertext = ""; |
| 308 | 308 | $plaintext = ""; |
| 309 | 309 | $this->decrypt_file($source, $dest, $key, $start, $iv, $recursive); |
| 310 | - }else { |
|
| 311 | - if(($iv) != base64_decode(base64_encode($iv))) |
|
| 310 | + } else { |
|
| 311 | + if (($iv) != base64_decode(base64_encode($iv))) |
|
| 312 | 312 | { |
| 313 | 313 | throw new \Exception('Could not encode IV for transport'); |
| 314 | 314 | } |
@@ -325,30 +325,30 @@ discard block |
||
| 325 | 325 | |
| 326 | 326 | } |
| 327 | 327 | } else { |
| 328 | - if(is_object($this->logger)) { |
|
| 328 | + if (is_object($this->logger)) { |
|
| 329 | 329 | $this->logger->error('Unable to read source file for decryption'); |
| 330 | 330 | } |
| 331 | 331 | throw new \Exception("Unable to read source file for decryption"); |
| 332 | 332 | } |
| 333 | 333 | } else { |
| 334 | - if(is_object($this->logger)) { |
|
| 334 | + if (is_object($this->logger)) { |
|
| 335 | 335 | $this->logger->error('Unable to write destination file for decryption'); |
| 336 | 336 | } |
| 337 | 337 | throw new \Exception("Unable to write destination file for decryption"); |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | //we replace the original backup with the encrypted one |
| 341 | - if( !$keep_local && !$this->verification && copy($this->get_xcloner_path() .$dest, |
|
| 342 | - $this->get_xcloner_path() .$source) ) { |
|
| 343 | - unlink($this->get_xcloner_path() .$dest); |
|
| 341 | + if (!$keep_local && !$this->verification && copy($this->get_xcloner_path().$dest, |
|
| 342 | + $this->get_xcloner_path().$source)) { |
|
| 343 | + unlink($this->get_xcloner_path().$dest); |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | return array("target_file" => $dest, "finished" => 1); |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | - public function get_xcloner_path(){ |
|
| 350 | - if(is_object($this->xcloner_settings)) { |
|
| 351 | - return $this->xcloner_settings->get_xcloner_store_path() . DS; |
|
| 349 | + public function get_xcloner_path() { |
|
| 350 | + if (is_object($this->xcloner_settings)) { |
|
| 351 | + return $this->xcloner_settings->get_xcloner_store_path().DS; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | return null; |
@@ -359,21 +359,21 @@ discard block |
||
| 359 | 359 | |
| 360 | 360 | try { |
| 361 | 361 | |
| 362 | - if(isset($argv[1])) { |
|
| 362 | + if (isset($argv[1])) { |
|
| 363 | 363 | |
| 364 | 364 | class Xcloner { |
| 365 | 365 | public function __construct() |
| 366 | 366 | { |
| 367 | 367 | } |
| 368 | 368 | } |
| 369 | - $xcloner_encryption = new Xcloner_Encryption( new Xcloner() ); |
|
| 369 | + $xcloner_encryption = new Xcloner_Encryption(new Xcloner()); |
|
| 370 | 370 | |
| 371 | 371 | if ($argv[1] == "-e") { |
| 372 | - $xcloner_encryption->encrypt_file($argv[2], $argv[2] . ".enc", $argv[4], '', '', '', true); |
|
| 372 | + $xcloner_encryption->encrypt_file($argv[2], $argv[2].".enc", $argv[4], '', '', '', true); |
|
| 373 | 373 | } elseif ($argv[1] == "-d") { |
| 374 | - $xcloner_encryption->decrypt_file($argv[2], $argv[2] . ".dec", $argv[4], '', '', true); |
|
| 374 | + $xcloner_encryption->decrypt_file($argv[2], $argv[2].".dec", $argv[4], '', '', true); |
|
| 375 | 375 | } |
| 376 | 376 | } |
| 377 | -}catch(\Exception $e) { |
|
| 378 | - echo "CAUGHT: " . $e->getMessage(); |
|
| 377 | +}catch (\Exception $e) { |
|
| 378 | + echo "CAUGHT: ".$e->getMessage(); |
|
| 379 | 379 | } |
@@ -106,11 +106,11 @@ discard block |
||
| 106 | 106 | private $backup_storage_dir; |
| 107 | 107 | private $parent_api; |
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Xcloner_Restore constructor. |
|
| 111 | - * @param string $parent_api |
|
| 112 | - * @throws Exception |
|
| 113 | - */ |
|
| 109 | + /** |
|
| 110 | + * Xcloner_Restore constructor. |
|
| 111 | + * @param string $parent_api |
|
| 112 | + * @throws Exception |
|
| 113 | + */ |
|
| 114 | 114 | public function __construct($parent_api = "") |
| 115 | 115 | { |
| 116 | 116 | register_shutdown_function(array($this, 'exception_handler')); |
@@ -150,9 +150,9 @@ discard block |
||
| 150 | 150 | |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * Exception handler method |
|
| 155 | - */ |
|
| 153 | + /** |
|
| 154 | + * Exception handler method |
|
| 155 | + */ |
|
| 156 | 156 | public function exception_handler() { |
| 157 | 157 | |
| 158 | 158 | $error = error_get_last(); |
@@ -164,20 +164,20 @@ discard block |
||
| 164 | 164 | |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * @param $type |
|
| 169 | - * @return mixed|string |
|
| 170 | - */ |
|
| 167 | + /** |
|
| 168 | + * @param $type |
|
| 169 | + * @return mixed|string |
|
| 170 | + */ |
|
| 171 | 171 | private function friendly_error_type($type) { |
| 172 | - static $levels=null; |
|
| 173 | - if ($levels===null) { |
|
| 174 | - $levels=[]; |
|
| 175 | - foreach (get_defined_constants() as $key=>$value) { |
|
| 176 | - if (strpos($key,'E_')!==0) {continue;} |
|
| 172 | + static $levels=null; |
|
| 173 | + if ($levels===null) { |
|
| 174 | + $levels=[]; |
|
| 175 | + foreach (get_defined_constants() as $key=>$value) { |
|
| 176 | + if (strpos($key,'E_')!==0) {continue;} |
|
| 177 | 177 | $levels[$value]= $key; //substr($key,2); |
| 178 | - } |
|
| 179 | - } |
|
| 180 | - return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}"); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}"); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | public function get_logger_filename() |
@@ -187,12 +187,12 @@ discard block |
||
| 187 | 187 | return $filename; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - /** |
|
| 191 | - * Init method |
|
| 192 | - * |
|
| 193 | - * @return mixed|void |
|
| 194 | - * @throws Exception |
|
| 195 | - */ |
|
| 190 | + /** |
|
| 191 | + * Init method |
|
| 192 | + * |
|
| 193 | + * @return mixed|void |
|
| 194 | + * @throws Exception |
|
| 195 | + */ |
|
| 196 | 196 | public function init() |
| 197 | 197 | { |
| 198 | 198 | if(isset($_POST['xcloner_action']) and $_POST['xcloner_action']) |
@@ -216,12 +216,12 @@ discard block |
||
| 216 | 216 | return $this->check_system(); |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - /** |
|
| 220 | - * Write file method |
|
| 221 | - * |
|
| 222 | - * @return bool|int |
|
| 223 | - * @throws Exception |
|
| 224 | - */ |
|
| 219 | + /** |
|
| 220 | + * Write file method |
|
| 221 | + * |
|
| 222 | + * @return bool|int |
|
| 223 | + * @throws Exception |
|
| 224 | + */ |
|
| 225 | 225 | public function write_file_action() |
| 226 | 226 | { |
| 227 | 227 | if(isset($_POST['file'])) |
@@ -248,10 +248,10 @@ discard block |
||
| 248 | 248 | throw new Exception("Unable to write data to file $target_file"); |
| 249 | 249 | |
| 250 | 250 | try { |
| 251 | - unlink($_FILES['blob']['tmp_name']); |
|
| 252 | - }catch(Exception $e){ |
|
| 251 | + unlink($_FILES['blob']['tmp_name']); |
|
| 252 | + }catch(Exception $e){ |
|
| 253 | 253 | |
| 254 | - } |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | 256 | }elseif(isset($_POST['blob'])){ |
| 257 | 257 | $this->logger->debug(sprintf('Writing %s bytes to file %s starting position %s using POST blob', strlen($_POST['blob']), $target_file, $_POST['start'])); |
@@ -271,16 +271,16 @@ discard block |
||
| 271 | 271 | |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - /** |
|
| 275 | - * Connect to mysql server method |
|
| 276 | - * |
|
| 277 | - * @param $remote_mysql_host |
|
| 278 | - * @param $remote_mysql_user |
|
| 279 | - * @param $remote_mysql_pass |
|
| 280 | - * @param $remote_mysql_db |
|
| 281 | - * @return mysqli |
|
| 282 | - * @throws Exception |
|
| 283 | - */ |
|
| 274 | + /** |
|
| 275 | + * Connect to mysql server method |
|
| 276 | + * |
|
| 277 | + * @param $remote_mysql_host |
|
| 278 | + * @param $remote_mysql_user |
|
| 279 | + * @param $remote_mysql_pass |
|
| 280 | + * @param $remote_mysql_db |
|
| 281 | + * @return mysqli |
|
| 282 | + * @throws Exception |
|
| 283 | + */ |
|
| 284 | 284 | public function mysql_connect($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db ) |
| 285 | 285 | { |
| 286 | 286 | $this->logger->info(sprintf('Connecting to mysql database %s with %s@%s', $remote_mysql_db, $remote_mysql_user, $remote_mysql_host)); |
@@ -302,11 +302,11 @@ discard block |
||
| 302 | 302 | return $mysqli; |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - /** |
|
| 306 | - * Restore mysql backup file |
|
| 307 | - * |
|
| 308 | - * @throws Exception |
|
| 309 | - */ |
|
| 305 | + /** |
|
| 306 | + * Restore mysql backup file |
|
| 307 | + * |
|
| 308 | + * @throws Exception |
|
| 309 | + */ |
|
| 310 | 310 | public function restore_mysql_backup_action() |
| 311 | 311 | { |
| 312 | 312 | $mysqldump_file = filter_input(INPUT_POST, 'mysqldump_file', FILTER_SANITIZE_STRING); |
@@ -437,14 +437,14 @@ discard block |
||
| 437 | 437 | $this->send_response(200, $return); |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | - /** |
|
| 441 | - * Url replace method inside database backup file |
|
| 442 | - * |
|
| 443 | - * @param $search |
|
| 444 | - * @param $replace |
|
| 445 | - * @param $query |
|
| 446 | - * @return mixed|string|string[]|null |
|
| 447 | - */ |
|
| 440 | + /** |
|
| 441 | + * Url replace method inside database backup file |
|
| 442 | + * |
|
| 443 | + * @param $search |
|
| 444 | + * @param $replace |
|
| 445 | + * @param $query |
|
| 446 | + * @return mixed|string|string[]|null |
|
| 447 | + */ |
|
| 448 | 448 | private function url_replace($search, $replace, $query) |
| 449 | 449 | { |
| 450 | 450 | $this->logger->info(sprintf("Doing url replace on query with length %s", strlen($query)), array("QUERY_REPLACE")); |
@@ -467,11 +467,11 @@ discard block |
||
| 467 | 467 | return $query; |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | - /** |
|
| 471 | - * List backup files method |
|
| 472 | - * |
|
| 473 | - * @throws \League\Flysystem\FileNotFoundException |
|
| 474 | - */ |
|
| 470 | + /** |
|
| 471 | + * List backup files method |
|
| 472 | + * |
|
| 473 | + * @throws \League\Flysystem\FileNotFoundException |
|
| 474 | + */ |
|
| 475 | 475 | public function list_backup_files_action() |
| 476 | 476 | { |
| 477 | 477 | $backup_parts = array(); |
@@ -537,11 +537,11 @@ discard block |
||
| 537 | 537 | $this->send_response(200, $return); |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | - /** |
|
| 541 | - * Finish backup restore method |
|
| 542 | - * |
|
| 543 | - * @throws \League\Flysystem\FileNotFoundException |
|
| 544 | - */ |
|
| 540 | + /** |
|
| 541 | + * Finish backup restore method |
|
| 542 | + * |
|
| 543 | + * @throws \League\Flysystem\FileNotFoundException |
|
| 544 | + */ |
|
| 545 | 545 | public function restore_finish_action() |
| 546 | 546 | { |
| 547 | 547 | $remote_path = filter_input(INPUT_POST, 'remote_path', FILTER_SANITIZE_STRING); |
@@ -582,12 +582,12 @@ discard block |
||
| 582 | 582 | $this->send_response(200, $return); |
| 583 | 583 | } |
| 584 | 584 | |
| 585 | - /** |
|
| 586 | - * Delete backup temporary folder |
|
| 587 | - * |
|
| 588 | - * @param $remote_path |
|
| 589 | - * @return bool |
|
| 590 | - */ |
|
| 585 | + /** |
|
| 586 | + * Delete backup temporary folder |
|
| 587 | + * |
|
| 588 | + * @param $remote_path |
|
| 589 | + * @return bool |
|
| 590 | + */ |
|
| 591 | 591 | private function delete_backup_temporary_folder($remote_path) |
| 592 | 592 | { |
| 593 | 593 | $this->target_adapter = new Local($remote_path ,LOCK_EX, 'SKIP_LINKS'); |
@@ -615,11 +615,11 @@ discard block |
||
| 615 | 615 | |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | - /** |
|
| 619 | - * Delete restore script method |
|
| 620 | - * |
|
| 621 | - * @throws \League\Flysystem\FileNotFoundException |
|
| 622 | - */ |
|
| 618 | + /** |
|
| 619 | + * Delete restore script method |
|
| 620 | + * |
|
| 621 | + * @throws \League\Flysystem\FileNotFoundException |
|
| 622 | + */ |
|
| 623 | 623 | private function delete_self() |
| 624 | 624 | { |
| 625 | 625 | if($this->filesystem->has("vendor.phar")) |
@@ -652,14 +652,14 @@ discard block |
||
| 652 | 652 | |
| 653 | 653 | } |
| 654 | 654 | |
| 655 | - /** |
|
| 656 | - * Update Wordpress url in wp-config.php method |
|
| 657 | - * @param $wp_path |
|
| 658 | - * @param $url |
|
| 659 | - * @param $mysqli |
|
| 660 | - * @return bool |
|
| 661 | - * @throws Exception |
|
| 662 | - */ |
|
| 655 | + /** |
|
| 656 | + * Update Wordpress url in wp-config.php method |
|
| 657 | + * @param $wp_path |
|
| 658 | + * @param $url |
|
| 659 | + * @param $mysqli |
|
| 660 | + * @return bool |
|
| 661 | + * @throws Exception |
|
| 662 | + */ |
|
| 663 | 663 | private function update_wp_url($wp_path, $url, $mysqli) |
| 664 | 664 | { |
| 665 | 665 | $wp_config = $wp_path.DS."wp-config.php"; |
@@ -687,17 +687,17 @@ discard block |
||
| 687 | 687 | return true; |
| 688 | 688 | } |
| 689 | 689 | |
| 690 | - /** |
|
| 691 | - * Update local wp-config.php file method |
|
| 692 | - * |
|
| 693 | - * @param $remote_path |
|
| 694 | - * @param $remote_mysql_host |
|
| 695 | - * @param $remote_mysql_user |
|
| 696 | - * @param $remote_mysql_pass |
|
| 697 | - * @param $remote_mysql_db |
|
| 698 | - * @return string |
|
| 699 | - * @throws Exception |
|
| 700 | - */ |
|
| 690 | + /** |
|
| 691 | + * Update local wp-config.php file method |
|
| 692 | + * |
|
| 693 | + * @param $remote_path |
|
| 694 | + * @param $remote_mysql_host |
|
| 695 | + * @param $remote_mysql_user |
|
| 696 | + * @param $remote_mysql_pass |
|
| 697 | + * @param $remote_mysql_db |
|
| 698 | + * @return string |
|
| 699 | + * @throws Exception |
|
| 700 | + */ |
|
| 701 | 701 | private function update_wp_config($remote_path, $remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db) |
| 702 | 702 | { |
| 703 | 703 | $wp_config = $remote_path.DS."wp-config.php"; |
@@ -729,10 +729,10 @@ discard block |
||
| 729 | 729 | |
| 730 | 730 | } |
| 731 | 731 | |
| 732 | - /** |
|
| 733 | - * List mysqldump database backup files |
|
| 734 | - * |
|
| 735 | - */ |
|
| 732 | + /** |
|
| 733 | + * List mysqldump database backup files |
|
| 734 | + * |
|
| 735 | + */ |
|
| 736 | 736 | public function list_mysqldump_backups_action() |
| 737 | 737 | { |
| 738 | 738 | $source_backup_file = filter_input(INPUT_POST, 'backup_file', FILTER_SANITIZE_STRING); |
@@ -782,12 +782,12 @@ discard block |
||
| 782 | 782 | $this->send_response(200, $return); |
| 783 | 783 | } |
| 784 | 784 | |
| 785 | - /** |
|
| 786 | - * Get backup hash method |
|
| 787 | - * |
|
| 788 | - * @param $backup_file |
|
| 789 | - * @return bool |
|
| 790 | - */ |
|
| 785 | + /** |
|
| 786 | + * Get backup hash method |
|
| 787 | + * |
|
| 788 | + * @param $backup_file |
|
| 789 | + * @return bool |
|
| 790 | + */ |
|
| 791 | 791 | private function get_hash_from_backup($backup_file) |
| 792 | 792 | { |
| 793 | 793 | if(!$backup_file) |
@@ -801,11 +801,11 @@ discard block |
||
| 801 | 801 | return false; |
| 802 | 802 | } |
| 803 | 803 | |
| 804 | - /** |
|
| 805 | - * List backup archives found on local system |
|
| 806 | - * |
|
| 807 | - * @throws \League\Flysystem\FileNotFoundException |
|
| 808 | - */ |
|
| 804 | + /** |
|
| 805 | + * List backup archives found on local system |
|
| 806 | + * |
|
| 807 | + * @throws \League\Flysystem\FileNotFoundException |
|
| 808 | + */ |
|
| 809 | 809 | public function list_backup_archives_action() |
| 810 | 810 | { |
| 811 | 811 | $local_backup_file = filter_input(INPUT_POST, 'local_backup_file', FILTER_SANITIZE_STRING); |
@@ -864,12 +864,12 @@ discard block |
||
| 864 | 864 | |
| 865 | 865 | } |
| 866 | 866 | |
| 867 | - /** |
|
| 868 | - * Restore backup archive to local path |
|
| 869 | - * |
|
| 870 | - * @throws \League\Flysystem\FileNotFoundException |
|
| 871 | - * @throws \splitbrain\PHPArchive\ArchiveIOException |
|
| 872 | - */ |
|
| 867 | + /** |
|
| 868 | + * Restore backup archive to local path |
|
| 869 | + * |
|
| 870 | + * @throws \League\Flysystem\FileNotFoundException |
|
| 871 | + * @throws \splitbrain\PHPArchive\ArchiveIOException |
|
| 872 | + */ |
|
| 873 | 873 | public function restore_backup_to_path_action() |
| 874 | 874 | { |
| 875 | 875 | $source_backup_file = filter_input(INPUT_POST, 'backup_file', FILTER_SANITIZE_STRING); |
@@ -944,9 +944,9 @@ discard block |
||
| 944 | 944 | $this->send_response(200, $return); |
| 945 | 945 | } |
| 946 | 946 | |
| 947 | - /** |
|
| 948 | - * Get current directory method |
|
| 949 | - */ |
|
| 947 | + /** |
|
| 948 | + * Get current directory method |
|
| 949 | + */ |
|
| 950 | 950 | public function get_current_directory_action() |
| 951 | 951 | { |
| 952 | 952 | global $wpdb; |
@@ -980,11 +980,11 @@ discard block |
||
| 980 | 980 | $this->send_response(200, $return); |
| 981 | 981 | } |
| 982 | 982 | |
| 983 | - /** |
|
| 984 | - * Check current filesystem |
|
| 985 | - * |
|
| 986 | - * @throws Exception |
|
| 987 | - */ |
|
| 983 | + /** |
|
| 984 | + * Check current filesystem |
|
| 985 | + * |
|
| 986 | + * @throws Exception |
|
| 987 | + */ |
|
| 988 | 988 | public function check_system() |
| 989 | 989 | { |
| 990 | 990 | //check if i can write |
@@ -1006,35 +1006,35 @@ discard block |
||
| 1006 | 1006 | $this->send_response(200, $return); |
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | - /** |
|
| 1010 | - * Return bytes from human readable value |
|
| 1011 | - * |
|
| 1012 | - * @param $val |
|
| 1013 | - * @return int |
|
| 1014 | - * |
|
| 1015 | - */ |
|
| 1016 | - private function return_bytes($val) { |
|
| 1017 | - $numeric_val = (int)trim($val); |
|
| 1018 | - $last = strtolower($val[strlen($val)-1]); |
|
| 1019 | - switch($last) { |
|
| 1020 | - // The 'G' modifier is available since PHP 5.1.0 |
|
| 1021 | - case 'g': |
|
| 1022 | - $numeric_val *= 1024; |
|
| 1023 | - case 'm': |
|
| 1024 | - $numeric_val *= 1024; |
|
| 1025 | - case 'k': |
|
| 1026 | - $numeric_val *= 1024; |
|
| 1027 | - } |
|
| 1028 | - |
|
| 1029 | - return $numeric_val; |
|
| 1030 | - } |
|
| 1031 | - |
|
| 1032 | - /** |
|
| 1033 | - * Check if backup archive os multipart |
|
| 1034 | - * |
|
| 1035 | - * @param $backup_name |
|
| 1036 | - * @return bool |
|
| 1037 | - */ |
|
| 1009 | + /** |
|
| 1010 | + * Return bytes from human readable value |
|
| 1011 | + * |
|
| 1012 | + * @param $val |
|
| 1013 | + * @return int |
|
| 1014 | + * |
|
| 1015 | + */ |
|
| 1016 | + private function return_bytes($val) { |
|
| 1017 | + $numeric_val = (int)trim($val); |
|
| 1018 | + $last = strtolower($val[strlen($val)-1]); |
|
| 1019 | + switch($last) { |
|
| 1020 | + // The 'G' modifier is available since PHP 5.1.0 |
|
| 1021 | + case 'g': |
|
| 1022 | + $numeric_val *= 1024; |
|
| 1023 | + case 'm': |
|
| 1024 | + $numeric_val *= 1024; |
|
| 1025 | + case 'k': |
|
| 1026 | + $numeric_val *= 1024; |
|
| 1027 | + } |
|
| 1028 | + |
|
| 1029 | + return $numeric_val; |
|
| 1030 | + } |
|
| 1031 | + |
|
| 1032 | + /** |
|
| 1033 | + * Check if backup archive os multipart |
|
| 1034 | + * |
|
| 1035 | + * @param $backup_name |
|
| 1036 | + * @return bool |
|
| 1037 | + */ |
|
| 1038 | 1038 | public function is_multipart($backup_name) |
| 1039 | 1039 | { |
| 1040 | 1040 | if(stristr($backup_name, "-multipart")) |
@@ -1043,13 +1043,13 @@ discard block |
||
| 1043 | 1043 | return false; |
| 1044 | 1044 | } |
| 1045 | 1045 | |
| 1046 | - /** |
|
| 1047 | - * Get backup archive size |
|
| 1048 | - * |
|
| 1049 | - * @param $backup_name |
|
| 1050 | - * @return bool|false|int |
|
| 1051 | - * @throws \League\Flysystem\FileNotFoundException |
|
| 1052 | - */ |
|
| 1046 | + /** |
|
| 1047 | + * Get backup archive size |
|
| 1048 | + * |
|
| 1049 | + * @param $backup_name |
|
| 1050 | + * @return bool|false|int |
|
| 1051 | + * @throws \League\Flysystem\FileNotFoundException |
|
| 1052 | + */ |
|
| 1053 | 1053 | public function get_backup_size($backup_name) |
| 1054 | 1054 | { |
| 1055 | 1055 | $backup_size = $this->filesystem->getSize($backup_name); |
@@ -1063,12 +1063,12 @@ discard block |
||
| 1063 | 1063 | return $backup_size; |
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | - /** |
|
| 1067 | - * Get multipart backup files list |
|
| 1068 | - * @param $backup_name |
|
| 1069 | - * @return array |
|
| 1070 | - * @throws \League\Flysystem\FileNotFoundException |
|
| 1071 | - */ |
|
| 1066 | + /** |
|
| 1067 | + * Get multipart backup files list |
|
| 1068 | + * @param $backup_name |
|
| 1069 | + * @return array |
|
| 1070 | + * @throws \League\Flysystem\FileNotFoundException |
|
| 1071 | + */ |
|
| 1072 | 1072 | public function get_multipart_files($backup_name) |
| 1073 | 1073 | { |
| 1074 | 1074 | $files = array(); |
@@ -1089,58 +1089,58 @@ discard block |
||
| 1089 | 1089 | return $files; |
| 1090 | 1090 | } |
| 1091 | 1091 | |
| 1092 | - /** |
|
| 1093 | - * Sort_by method |
|
| 1094 | - * |
|
| 1095 | - * @param $array |
|
| 1096 | - * @param $field |
|
| 1097 | - * @param string $direction |
|
| 1098 | - * @return bool |
|
| 1099 | - */ |
|
| 1100 | - private function sort_by( &$array, $field, $direction = 'asc') |
|
| 1101 | - { |
|
| 1102 | - $direction = strtolower($direction); |
|
| 1103 | - |
|
| 1104 | - usort($array, |
|
| 1105 | - function($a, $b) use($field, $direction){ |
|
| 1106 | - |
|
| 1107 | - $a = $a[$field]; |
|
| 1108 | - $b = $b[$field]; |
|
| 1109 | - |
|
| 1110 | - if ($a == $b) |
|
| 1111 | - { |
|
| 1112 | - return 0; |
|
| 1113 | - } |
|
| 1114 | - |
|
| 1115 | - if($direction == 'desc') { |
|
| 1116 | - if($a > $b) { |
|
| 1117 | - return -1; |
|
| 1118 | - } |
|
| 1119 | - else{ |
|
| 1120 | - return 1; |
|
| 1121 | - } |
|
| 1122 | - }else { |
|
| 1123 | - if($a < $b) { |
|
| 1124 | - return -1; |
|
| 1125 | - } |
|
| 1126 | - else{ |
|
| 1127 | - return 1; |
|
| 1128 | - } |
|
| 1129 | - } |
|
| 1130 | - |
|
| 1131 | - //return ($a.($direction == 'desc' ? '>' : '<').$b) ? -1 : 1; |
|
| 1132 | - } |
|
| 1133 | - ); |
|
| 1134 | - |
|
| 1135 | - return true; |
|
| 1136 | - } |
|
| 1137 | - |
|
| 1138 | - /** |
|
| 1139 | - * Send response method |
|
| 1140 | - * |
|
| 1141 | - * @param int $status |
|
| 1142 | - * @param $response |
|
| 1143 | - */ |
|
| 1092 | + /** |
|
| 1093 | + * Sort_by method |
|
| 1094 | + * |
|
| 1095 | + * @param $array |
|
| 1096 | + * @param $field |
|
| 1097 | + * @param string $direction |
|
| 1098 | + * @return bool |
|
| 1099 | + */ |
|
| 1100 | + private function sort_by( &$array, $field, $direction = 'asc') |
|
| 1101 | + { |
|
| 1102 | + $direction = strtolower($direction); |
|
| 1103 | + |
|
| 1104 | + usort($array, |
|
| 1105 | + function($a, $b) use($field, $direction){ |
|
| 1106 | + |
|
| 1107 | + $a = $a[$field]; |
|
| 1108 | + $b = $b[$field]; |
|
| 1109 | + |
|
| 1110 | + if ($a == $b) |
|
| 1111 | + { |
|
| 1112 | + return 0; |
|
| 1113 | + } |
|
| 1114 | + |
|
| 1115 | + if($direction == 'desc') { |
|
| 1116 | + if($a > $b) { |
|
| 1117 | + return -1; |
|
| 1118 | + } |
|
| 1119 | + else{ |
|
| 1120 | + return 1; |
|
| 1121 | + } |
|
| 1122 | + }else { |
|
| 1123 | + if($a < $b) { |
|
| 1124 | + return -1; |
|
| 1125 | + } |
|
| 1126 | + else{ |
|
| 1127 | + return 1; |
|
| 1128 | + } |
|
| 1129 | + } |
|
| 1130 | + |
|
| 1131 | + //return ($a.($direction == 'desc' ? '>' : '<').$b) ? -1 : 1; |
|
| 1132 | + } |
|
| 1133 | + ); |
|
| 1134 | + |
|
| 1135 | + return true; |
|
| 1136 | + } |
|
| 1137 | + |
|
| 1138 | + /** |
|
| 1139 | + * Send response method |
|
| 1140 | + * |
|
| 1141 | + * @param int $status |
|
| 1142 | + * @param $response |
|
| 1143 | + */ |
|
| 1144 | 1144 | public static function send_response($status = 200, $response) |
| 1145 | 1145 | { |
| 1146 | 1146 | header("Access-Control-Allow-Origin: *"); |
@@ -1163,12 +1163,12 @@ discard block |
||
| 1163 | 1163 | exit; |
| 1164 | 1164 | } |
| 1165 | 1165 | |
| 1166 | - /** |
|
| 1167 | - * Serialize fix methods below for mysql query lines |
|
| 1168 | - * |
|
| 1169 | - * @param $query |
|
| 1170 | - * @return string|string[]|null |
|
| 1171 | - */ |
|
| 1166 | + /** |
|
| 1167 | + * Serialize fix methods below for mysql query lines |
|
| 1168 | + * |
|
| 1169 | + * @param $query |
|
| 1170 | + * @return string|string[]|null |
|
| 1171 | + */ |
|
| 1172 | 1172 | |
| 1173 | 1173 | function do_serialized_fix($query) |
| 1174 | 1174 | { |
@@ -1181,51 +1181,51 @@ discard block |
||
| 1181 | 1181 | $m[3] = ""; |
| 1182 | 1182 | |
| 1183 | 1183 | $data = 's:'.strlen(($m[3])).':\"'.($m[3]).'\";'; |
| 1184 | - //return $this->unescape_quotes($data); |
|
| 1184 | + //return $this->unescape_quotes($data); |
|
| 1185 | 1185 | |
| 1186 | - return $data; |
|
| 1187 | - }, $query); |
|
| 1186 | + return $data; |
|
| 1187 | + }, $query); |
|
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | - /** |
|
| 1191 | - * Unescape quotes method |
|
| 1192 | - * |
|
| 1193 | - * @param $value |
|
| 1194 | - * @return mixed |
|
| 1195 | - */ |
|
| 1190 | + /** |
|
| 1191 | + * Unescape quotes method |
|
| 1192 | + * |
|
| 1193 | + * @param $value |
|
| 1194 | + * @return mixed |
|
| 1195 | + */ |
|
| 1196 | 1196 | private function unescape_quotes($value) { |
| 1197 | 1197 | return str_replace('\"', '"', $value); |
| 1198 | 1198 | } |
| 1199 | 1199 | |
| 1200 | - /** |
|
| 1201 | - * Unescape mysql method |
|
| 1202 | - * |
|
| 1203 | - * @param $value |
|
| 1204 | - * @return mixed |
|
| 1205 | - */ |
|
| 1200 | + /** |
|
| 1201 | + * Unescape mysql method |
|
| 1202 | + * |
|
| 1203 | + * @param $value |
|
| 1204 | + * @return mixed |
|
| 1205 | + */ |
|
| 1206 | 1206 | private function unescape_mysql($value) { |
| 1207 | 1207 | return str_replace(array("\\\\", "\\0", "\\n", "\\r", "\Z", "\'", '\"'), |
| 1208 | 1208 | array("\\", "\0", "\n", "\r", "\x1a", "'", '"'), |
| 1209 | 1209 | $value); |
| 1210 | 1210 | } |
| 1211 | 1211 | |
| 1212 | - /** |
|
| 1213 | - * Check if string is in serialized format |
|
| 1214 | - * |
|
| 1215 | - * @param $s |
|
| 1216 | - * @return bool |
|
| 1217 | - */ |
|
| 1212 | + /** |
|
| 1213 | + * Check if string is in serialized format |
|
| 1214 | + * |
|
| 1215 | + * @param $s |
|
| 1216 | + * @return bool |
|
| 1217 | + */ |
|
| 1218 | 1218 | private function has_serialized($s) |
| 1219 | 1219 | { |
| 1220 | 1220 | if( |
| 1221 | - stristr($s, '{' ) !== false && |
|
| 1222 | - stristr($s, '}' ) !== false && |
|
| 1223 | - stristr($s, ';' ) !== false && |
|
| 1224 | - stristr($s, ':' ) !== false |
|
| 1225 | - ){ |
|
| 1226 | - return true; |
|
| 1221 | + stristr($s, '{' ) !== false && |
|
| 1222 | + stristr($s, '}' ) !== false && |
|
| 1223 | + stristr($s, ';' ) !== false && |
|
| 1224 | + stristr($s, ':' ) !== false |
|
| 1225 | + ){ |
|
| 1226 | + return true; |
|
| 1227 | 1227 | }else{ |
| 1228 | - return false; |
|
| 1228 | + return false; |
|
| 1229 | 1229 | } |
| 1230 | 1230 | |
| 1231 | 1231 | } |
@@ -1,30 +1,30 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if(!defined('AUTH_KEY')) |
|
| 3 | +if (!defined('AUTH_KEY')) |
|
| 4 | 4 | { |
| 5 | 5 | define('AUTH_KEY', ''); |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | -if(!defined("DS")) |
|
| 8 | +if (!defined("DS")) |
|
| 9 | 9 | { |
| 10 | 10 | define("DS", DIRECTORY_SEPARATOR); |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | -if(!defined('XCLONER_PLUGIN_ACCESS') || XCLONER_PLUGIN_ACCESS != 1) |
|
| 13 | +if (!defined('XCLONER_PLUGIN_ACCESS') || XCLONER_PLUGIN_ACCESS != 1) |
|
| 14 | 14 | { |
| 15 | - if(!AUTH_KEY) |
|
| 15 | + if (!AUTH_KEY) |
|
| 16 | 16 | { |
| 17 | 17 | Xcloner_Restore::send_response("404", "Could not run restore script, AUTH_KEY not set!"); |
| 18 | 18 | exit; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - if(!isset($_REQUEST['hash'])) |
|
| 21 | + if (!isset($_REQUEST['hash'])) |
|
| 22 | 22 | { |
| 23 | 23 | Xcloner_Restore::send_response("404", "Could not run restore script, sent HASH is empty!"); |
| 24 | 24 | exit; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - if($_REQUEST['hash'] != AUTH_KEY) |
|
| 27 | + if ($_REQUEST['hash'] != AUTH_KEY) |
|
| 28 | 28 | { |
| 29 | 29 | Xcloner_Restore::send_response("404", "Could not run restore script, AUTH_KEY doesn't match the sent HASH!"); |
| 30 | 30 | exit; |
@@ -32,28 +32,28 @@ discard block |
||
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | //check minimum PHP version |
| 35 | -if(version_compare(phpversion(), Xcloner_Restore::xcloner_minimum_version, '<')) |
|
| 35 | +if (version_compare(phpversion(), Xcloner_Restore::xcloner_minimum_version, '<')) |
|
| 36 | 36 | { |
| 37 | - Xcloner_Restore::send_response(500, sprintf(("XCloner requires minimum PHP version %s in order to run correctly. We have detected your version as %s"),Xcloner_Restore::xcloner_minimum_version, phpversion()) ); |
|
| 37 | + Xcloner_Restore::send_response(500, sprintf(("XCloner requires minimum PHP version %s in order to run correctly. We have detected your version as %s"), Xcloner_Restore::xcloner_minimum_version, phpversion())); |
|
| 38 | 38 | exit; |
| 39 | 39 | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | -$file = dirname( __DIR__ ) . DS.'vendor'.DS.'autoload.php'; |
|
| 42 | +$file = dirname(__DIR__).DS.'vendor'.DS.'autoload.php'; |
|
| 43 | 43 | |
| 44 | -if(file_exists($file)) |
|
| 44 | +if (file_exists($file)) |
|
| 45 | 45 | { |
| 46 | 46 | |
| 47 | 47 | require_once($file); |
| 48 | 48 | } |
| 49 | -elseif(file_exists("vendor.phar") and extension_loaded('phar')) |
|
| 49 | +elseif (file_exists("vendor.phar") and extension_loaded('phar')) |
|
| 50 | 50 | { |
| 51 | 51 | require_once(__DIR__.DS."vendor.phar"); |
| 52 | -}else{ |
|
| 52 | +} else { |
|
| 53 | 53 | |
| 54 | - $file = dirname( __FILE__ ) . DS.'vendor'.DS.'autoload.php'; |
|
| 54 | + $file = dirname(__FILE__).DS.'vendor'.DS.'autoload.php'; |
|
| 55 | 55 | |
| 56 | - if(!file_exists($file)) |
|
| 56 | + if (!file_exists($file)) |
|
| 57 | 57 | { |
| 58 | 58 | Xcloner_Restore::send_response("404", "File $file does not exists, please extract the vendor.tgz archive on the server or enable PHP Phar module!"); |
| 59 | 59 | exit; |
@@ -78,16 +78,16 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | //do not modify below |
| 80 | 80 | $that = ""; |
| 81 | -if(defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS) |
|
| 81 | +if (defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS) |
|
| 82 | 82 | { |
| 83 | 83 | $that = $this; |
| 84 | 84 | } |
| 85 | 85 | $xcloner_restore = new Xcloner_Restore($that); |
| 86 | 86 | |
| 87 | -try{ |
|
| 87 | +try { |
|
| 88 | 88 | $return = $xcloner_restore->init(); |
| 89 | 89 | $xcloner_restore->send_response(200, $return); |
| 90 | -}catch(Exception $e){ |
|
| 90 | +}catch (Exception $e) { |
|
| 91 | 91 | $xcloner_restore->send_response(417, $e->getMessage()); |
| 92 | 92 | } |
| 93 | 93 | |
@@ -96,10 +96,10 @@ discard block |
||
| 96 | 96 | |
| 97 | 97 | const xcloner_minimum_version = "5.4.0"; |
| 98 | 98 | |
| 99 | - private $backup_archive_extensions = array("zip", "tar", "tgz", "tar.gz", "gz", "csv"); |
|
| 100 | - private $process_files_limit = 150; |
|
| 101 | - private $process_files_limit_list = 350; |
|
| 102 | - private $process_mysql_records_limit = 250; |
|
| 99 | + private $backup_archive_extensions = array("zip", "tar", "tgz", "tar.gz", "gz", "csv"); |
|
| 100 | + private $process_files_limit = 150; |
|
| 101 | + private $process_files_limit_list = 350; |
|
| 102 | + private $process_mysql_records_limit = 250; |
|
| 103 | 103 | private $adapter; |
| 104 | 104 | private $filesystem; |
| 105 | 105 | private $logger; |
@@ -115,12 +115,12 @@ discard block |
||
| 115 | 115 | { |
| 116 | 116 | register_shutdown_function(array($this, 'exception_handler')); |
| 117 | 117 | |
| 118 | - if(defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS) |
|
| 118 | + if (defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS) |
|
| 119 | 119 | { |
| 120 | 120 | $dir = $parent_api->get_xcloner_container()->get_xcloner_settings()->get_xcloner_store_path(); |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - if(!isset($dir) || !$dir){ |
|
| 123 | + if (!isset($dir) || !$dir) { |
|
| 124 | 124 | $dir = dirname(__FILE__); |
| 125 | 125 | } |
| 126 | 126 | |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | |
| 129 | 129 | $this->backup_storage_dir = $dir; |
| 130 | 130 | |
| 131 | - $this->adapter = new Local($dir ,LOCK_EX, 'SKIP_LINKS'); |
|
| 131 | + $this->adapter = new Local($dir, LOCK_EX, 'SKIP_LINKS'); |
|
| 132 | 132 | $this->filesystem = new Filesystem($this->adapter, new Config([ |
| 133 | 133 | 'disable_asserts' => true, |
| 134 | 134 | ])); |
@@ -137,15 +137,15 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | $logger_path = $this->get_logger_filename(); |
| 139 | 139 | |
| 140 | - if(!is_writeable($logger_path) and !touch($logger_path)) |
|
| 140 | + if (!is_writeable($logger_path) and !touch($logger_path)) |
|
| 141 | 141 | { |
| 142 | 142 | $logger_path = "php://stderr"; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | $this->logger->pushHandler(new StreamHandler($logger_path, Logger::DEBUG)); |
| 146 | 146 | |
| 147 | - if(isset($_POST['API_ID'])){ |
|
| 148 | - $this->logger->info("Processing ajax request ID ".substr(filter_input(INPUT_POST, 'API_ID', FILTER_SANITIZE_STRING), 0 , 15)); |
|
| 147 | + if (isset($_POST['API_ID'])) { |
|
| 148 | + $this->logger->info("Processing ajax request ID ".substr(filter_input(INPUT_POST, 'API_ID', FILTER_SANITIZE_STRING), 0, 15)); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | } |
@@ -157,9 +157,9 @@ discard block |
||
| 157 | 157 | |
| 158 | 158 | $error = error_get_last(); |
| 159 | 159 | |
| 160 | - if($error['type'] and $this->logger) |
|
| 160 | + if ($error['type'] and $this->logger) |
|
| 161 | 161 | { |
| 162 | - $this->logger->info($this->friendly_error_type ($error['type']).": ".var_export($error, true)); |
|
| 162 | + $this->logger->info($this->friendly_error_type($error['type']).": ".var_export($error, true)); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | } |
@@ -169,12 +169,12 @@ discard block |
||
| 169 | 169 | * @return mixed|string |
| 170 | 170 | */ |
| 171 | 171 | private function friendly_error_type($type) { |
| 172 | - static $levels=null; |
|
| 173 | - if ($levels===null) { |
|
| 174 | - $levels=[]; |
|
| 172 | + static $levels = null; |
|
| 173 | + if ($levels === null) { |
|
| 174 | + $levels = []; |
|
| 175 | 175 | foreach (get_defined_constants() as $key=>$value) { |
| 176 | - if (strpos($key,'E_')!==0) {continue;} |
|
| 177 | - $levels[$value]= $key; //substr($key,2); |
|
| 176 | + if (strpos($key, 'E_') !== 0) {continue; } |
|
| 177 | + $levels[$value] = $key; //substr($key,2); |
|
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}"); |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | |
| 183 | 183 | public function get_logger_filename() |
| 184 | 184 | { |
| 185 | - $filename = $this->backup_storage_dir .DS. "xcloner_restore.log"; |
|
| 185 | + $filename = $this->backup_storage_dir.DS."xcloner_restore.log"; |
|
| 186 | 186 | |
| 187 | 187 | return $filename; |
| 188 | 188 | } |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | */ |
| 196 | 196 | public function init() |
| 197 | 197 | { |
| 198 | - if(isset($_POST['xcloner_action']) and $_POST['xcloner_action']) |
|
| 198 | + if (isset($_POST['xcloner_action']) and $_POST['xcloner_action']) |
|
| 199 | 199 | { |
| 200 | 200 | $method = filter_input(INPUT_POST, 'xcloner_action', FILTER_SANITIZE_STRING); |
| 201 | 201 | |
@@ -203,13 +203,13 @@ discard block |
||
| 203 | 203 | |
| 204 | 204 | $method .= "_action"; |
| 205 | 205 | |
| 206 | - if(method_exists($this, $method)) |
|
| 206 | + if (method_exists($this, $method)) |
|
| 207 | 207 | { |
| 208 | 208 | $this->logger->debug(sprintf('Starting action %s', $method)); |
| 209 | 209 | return call_user_func(array($this, $method)); |
| 210 | 210 | |
| 211 | - }else{ |
|
| 212 | - throw new Exception($method ." does not exists"); |
|
| 211 | + } else { |
|
| 212 | + throw new Exception($method." does not exists"); |
|
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | |
@@ -224,43 +224,43 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | public function write_file_action() |
| 226 | 226 | { |
| 227 | - if(isset($_POST['file'])) |
|
| 227 | + if (isset($_POST['file'])) |
|
| 228 | 228 | { |
| 229 | 229 | $target_file = filter_input(INPUT_POST, 'file', FILTER_SANITIZE_STRING); |
| 230 | 230 | |
| 231 | - if(!$_POST['start']) |
|
| 231 | + if (!$_POST['start']) |
|
| 232 | 232 | $fp = fopen($target_file, "wb+"); |
| 233 | 233 | else |
| 234 | 234 | $fp = fopen($target_file, "ab+"); |
| 235 | 235 | |
| 236 | - if(!$fp) |
|
| 236 | + if (!$fp) |
|
| 237 | 237 | throw new Exception("Unable to open $target_file file for writing"); |
| 238 | 238 | |
| 239 | 239 | fseek($fp, $_POST['start']); |
| 240 | 240 | |
| 241 | - if(isset($_FILES['blob'])) |
|
| 241 | + if (isset($_FILES['blob'])) |
|
| 242 | 242 | { |
| 243 | 243 | $this->logger->debug(sprintf('Writing %s bytes to file %s starting position %s using FILES blob', filesize($_FILES['blob']['tmp_name']), $target_file, $_POST['start'])); |
| 244 | 244 | |
| 245 | 245 | $blob = file_get_contents($_FILES['blob']['tmp_name']); |
| 246 | 246 | |
| 247 | - if(!$bytes_written = fwrite($fp, $blob)) |
|
| 247 | + if (!$bytes_written = fwrite($fp, $blob)) |
|
| 248 | 248 | throw new Exception("Unable to write data to file $target_file"); |
| 249 | 249 | |
| 250 | 250 | try { |
| 251 | 251 | unlink($_FILES['blob']['tmp_name']); |
| 252 | - }catch(Exception $e){ |
|
| 252 | + }catch (Exception $e) { |
|
| 253 | 253 | |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - }elseif(isset($_POST['blob'])){ |
|
| 256 | + }elseif (isset($_POST['blob'])) { |
|
| 257 | 257 | $this->logger->debug(sprintf('Writing %s bytes to file %s starting position %s using POST blob', strlen($_POST['blob']), $target_file, $_POST['start'])); |
| 258 | 258 | |
| 259 | 259 | $blob = $_POST['blob']; |
| 260 | 260 | |
| 261 | - if(!$bytes_written = fwrite($fp, $blob)) |
|
| 261 | + if (!$bytes_written = fwrite($fp, $blob)) |
|
| 262 | 262 | throw new Exception("Unable to write data to file $target_file"); |
| 263 | - }else{ |
|
| 263 | + } else { |
|
| 264 | 264 | throw new Exception("Upload failed, did not receive any binary data"); |
| 265 | 265 | } |
| 266 | 266 | |
@@ -281,20 +281,20 @@ discard block |
||
| 281 | 281 | * @return mysqli |
| 282 | 282 | * @throws Exception |
| 283 | 283 | */ |
| 284 | - public function mysql_connect($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db ) |
|
| 284 | + public function mysql_connect($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db) |
|
| 285 | 285 | { |
| 286 | 286 | $this->logger->info(sprintf('Connecting to mysql database %s with %s@%s', $remote_mysql_db, $remote_mysql_user, $remote_mysql_host)); |
| 287 | 287 | |
| 288 | 288 | $mysqli = new mysqli($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db); |
| 289 | 289 | |
| 290 | 290 | if ($mysqli->connect_error) { |
| 291 | - throw new Exception('Connect Error (' . $mysqli->connect_errno . ') ' |
|
| 291 | + throw new Exception('Connect Error ('.$mysqli->connect_errno.') ' |
|
| 292 | 292 | . $mysqli->connect_error); |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | $mysqli->query("SET sql_mode='';"); |
| 296 | 296 | $mysqli->query("SET foreign_key_checks = 0;"); |
| 297 | - if(isset($_REQUEST['charset_of_file']) and $_REQUEST['charset_of_file']) |
|
| 297 | + if (isset($_REQUEST['charset_of_file']) and $_REQUEST['charset_of_file']) |
|
| 298 | 298 | $mysqli->query("SET NAMES ".$_REQUEST['charset_of_file'].""); |
| 299 | 299 | else |
| 300 | 300 | $mysqli->query("SET NAMES utf8;"); |
@@ -309,15 +309,15 @@ discard block |
||
| 309 | 309 | */ |
| 310 | 310 | public function restore_mysql_backup_action() |
| 311 | 311 | { |
| 312 | - $mysqldump_file = filter_input(INPUT_POST, 'mysqldump_file', FILTER_SANITIZE_STRING); |
|
| 313 | - $remote_path = filter_input(INPUT_POST, 'remote_path', FILTER_SANITIZE_STRING); |
|
| 312 | + $mysqldump_file = filter_input(INPUT_POST, 'mysqldump_file', FILTER_SANITIZE_STRING); |
|
| 313 | + $remote_path = filter_input(INPUT_POST, 'remote_path', FILTER_SANITIZE_STRING); |
|
| 314 | 314 | $remote_mysql_user = filter_input(INPUT_POST, 'remote_mysql_user', FILTER_SANITIZE_STRING); |
| 315 | 315 | $remote_mysql_pass = filter_input(INPUT_POST, 'remote_mysql_pass', FILTER_SANITIZE_STRING); |
| 316 | - $remote_mysql_db = filter_input(INPUT_POST, 'remote_mysql_db', FILTER_SANITIZE_STRING); |
|
| 316 | + $remote_mysql_db = filter_input(INPUT_POST, 'remote_mysql_db', FILTER_SANITIZE_STRING); |
|
| 317 | 317 | $remote_mysql_host = filter_input(INPUT_POST, 'remote_mysql_host', FILTER_SANITIZE_STRING); |
| 318 | - $execute_query = trim(stripslashes($_POST['query'])); |
|
| 319 | - $error_line = filter_input(INPUT_POST, 'error_line', FILTER_SANITIZE_NUMBER_INT); |
|
| 320 | - $start = filter_input(INPUT_POST, 'start', FILTER_SANITIZE_NUMBER_INT); |
|
| 318 | + $execute_query = trim(stripslashes($_POST['query'])); |
|
| 319 | + $error_line = filter_input(INPUT_POST, 'error_line', FILTER_SANITIZE_NUMBER_INT); |
|
| 320 | + $start = filter_input(INPUT_POST, 'start', FILTER_SANITIZE_NUMBER_INT); |
|
| 321 | 321 | |
| 322 | 322 | $wp_home_url = filter_input(INPUT_POST, 'wp_home_url', FILTER_SANITIZE_STRING); |
| 323 | 323 | $remote_restore_url = filter_input(INPUT_POST, 'remote_restore_url', FILTER_SANITIZE_STRING); |
@@ -327,8 +327,8 @@ discard block |
||
| 327 | 327 | |
| 328 | 328 | $mysql_backup_file = $remote_path.DS.$mysqldump_file; |
| 329 | 329 | |
| 330 | - if(!file_exists($mysql_backup_file)) |
|
| 331 | - throw new Exception(sprintf("Mysql backup file %s does not exists",$mysql_backup_file)); |
|
| 330 | + if (!file_exists($mysql_backup_file)) |
|
| 331 | + throw new Exception(sprintf("Mysql backup file %s does not exists", $mysql_backup_file)); |
|
| 332 | 332 | |
| 333 | 333 | |
| 334 | 334 | /*if(defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS) |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | }*/ |
| 343 | 343 | |
| 344 | 344 | { |
| 345 | - $mysqli = $this->mysql_connect($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db ); |
|
| 345 | + $mysqli = $this->mysql_connect($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db); |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | $line_count = 0; |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | $return['backup_size'] = filesize($mysql_backup_file); |
| 353 | 353 | |
| 354 | 354 | $fp = fopen($mysql_backup_file, "r"); |
| 355 | - if($fp) |
|
| 355 | + if ($fp) |
|
| 356 | 356 | { |
| 357 | 357 | $this->logger->info(sprintf("Opening mysql dump file %s at position %s.", $mysql_backup_file, $start)); |
| 358 | 358 | fseek($fp, $start); |
@@ -360,49 +360,49 @@ discard block |
||
| 360 | 360 | // process the line read. |
| 361 | 361 | |
| 362 | 362 | //check if line is comment |
| 363 | - if(substr($line, 0, 1) == "#") |
|
| 363 | + if (substr($line, 0, 1) == "#") |
|
| 364 | 364 | continue; |
| 365 | 365 | |
| 366 | 366 | //check if line is empty |
| 367 | - if($line == "\n" or trim($line) == "") |
|
| 367 | + if ($line == "\n" or trim($line) == "") |
|
| 368 | 368 | continue; |
| 369 | 369 | |
| 370 | - if(substr($line, strlen($line)-2, strlen($line)) == ";\n") |
|
| 370 | + if (substr($line, strlen($line) - 2, strlen($line)) == ";\n") |
|
| 371 | 371 | $query .= $line; |
| 372 | - else{ |
|
| 372 | + else { |
|
| 373 | 373 | $query .= $line; |
| 374 | 374 | continue; |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | - if($execute_query) |
|
| 377 | + if ($execute_query) |
|
| 378 | 378 | { |
| 379 | - $query = (($execute_query)); |
|
| 379 | + $query = (($execute_query)); |
|
| 380 | 380 | $execute_query = ""; |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | //Doing serialized url replace here |
| 384 | 384 | |
| 385 | - if($wp_site_url and $wp_home_url and strlen($wp_home_url) < strlen($wp_site_url)) |
|
| 385 | + if ($wp_site_url and $wp_home_url and strlen($wp_home_url) < strlen($wp_site_url)) |
|
| 386 | 386 | { |
| 387 | - list($wp_home_url,$wp_site_url) = array($wp_site_url,$wp_home_url); |
|
| 388 | - list($remote_restore_url,$restore_site_url) = array($restore_site_url,$remote_restore_url); |
|
| 387 | + list($wp_home_url, $wp_site_url) = array($wp_site_url, $wp_home_url); |
|
| 388 | + list($remote_restore_url, $restore_site_url) = array($restore_site_url, $remote_restore_url); |
|
| 389 | 389 | |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - if($wp_home_url and $remote_restore_url and strpos($query, $wp_home_url) !== false) |
|
| 392 | + if ($wp_home_url and $remote_restore_url and strpos($query, $wp_home_url) !== false) |
|
| 393 | 393 | { |
| 394 | 394 | $query = $this->url_replace($wp_home_url, $remote_restore_url, $query); |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | - if($wp_site_url and $restore_site_url and strpos($query, $wp_site_url) !== false) |
|
| 397 | + if ($wp_site_url and $restore_site_url and strpos($query, $wp_site_url) !== false) |
|
| 398 | 398 | { |
| 399 | 399 | $query = $this->url_replace($wp_site_url, $restore_site_url, $query); |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | - if(!$mysqli->query($query) && !stristr($mysqli->error,"Duplicate entry")) |
|
| 402 | + if (!$mysqli->query($query) && !stristr($mysqli->error, "Duplicate entry")) |
|
| 403 | 403 | { |
| 404 | 404 | //$return['error_line'] = $line_count; |
| 405 | - $return['start'] = ftell($fp)-strlen($line); |
|
| 405 | + $return['start'] = ftell($fp) - strlen($line); |
|
| 406 | 406 | $return['query_error'] = true; |
| 407 | 407 | $return['query'] = $query; |
| 408 | 408 | $return['message'] = sprintf("Mysql Error: %s\n", $mysqli->error); |
@@ -423,12 +423,12 @@ discard block |
||
| 423 | 423 | |
| 424 | 424 | $return['start'] = ftell($fp); |
| 425 | 425 | |
| 426 | - $this->logger->info(sprintf("Executed %s queries of size %s bytes", $line_count, ($return['start']-$start))); |
|
| 426 | + $this->logger->info(sprintf("Executed %s queries of size %s bytes", $line_count, ($return['start'] - $start))); |
|
| 427 | 427 | |
| 428 | - if(!feof($fp)) |
|
| 428 | + if (!feof($fp)) |
|
| 429 | 429 | { |
| 430 | 430 | $return['finished'] = 0; |
| 431 | - }else{ |
|
| 431 | + } else { |
|
| 432 | 432 | $this->logger->info(sprintf("Mysql Import Done.")); |
| 433 | 433 | } |
| 434 | 434 | |
@@ -451,12 +451,12 @@ discard block |
||
| 451 | 451 | $query = str_replace($search, $replace, $query); |
| 452 | 452 | $original_query = $query; |
| 453 | 453 | |
| 454 | - if($this->has_serialized($query)) |
|
| 454 | + if ($this->has_serialized($query)) |
|
| 455 | 455 | { |
| 456 | 456 | $this->logger->info(sprintf("Query contains serialized data, doing serialized size fix"), array("QUERY_REPLACE")); |
| 457 | 457 | $query = $this->do_serialized_fix($query); |
| 458 | 458 | |
| 459 | - if(!$query) |
|
| 459 | + if (!$query) |
|
| 460 | 460 | { |
| 461 | 461 | $this->logger->info(sprintf("Serialization probably failed here..."), array("QUERY_REPLACE")); |
| 462 | 462 | $query = $original_query; |
@@ -477,37 +477,37 @@ discard block |
||
| 477 | 477 | $backup_parts = array(); |
| 478 | 478 | |
| 479 | 479 | $source_backup_file = filter_input(INPUT_POST, 'file', FILTER_SANITIZE_STRING); |
| 480 | - $start = (int)filter_input(INPUT_POST, 'start', FILTER_SANITIZE_STRING); |
|
| 481 | - $return['part'] = (int)filter_input(INPUT_POST, 'part', FILTER_SANITIZE_STRING); |
|
| 480 | + $start = (int)filter_input(INPUT_POST, 'start', FILTER_SANITIZE_STRING); |
|
| 481 | + $return['part'] = (int)filter_input(INPUT_POST, 'part', FILTER_SANITIZE_STRING); |
|
| 482 | 482 | |
| 483 | 483 | $backup_file = $source_backup_file; |
| 484 | 484 | |
| 485 | - if($this->is_multipart($backup_file)) |
|
| 485 | + if ($this->is_multipart($backup_file)) |
|
| 486 | 486 | { |
| 487 | 487 | $backup_parts = $this->get_multipart_files($backup_file); |
| 488 | 488 | $backup_file = $backup_parts[$return['part']]; |
| 489 | 489 | } |
| 490 | 490 | |
| 491 | - try{ |
|
| 491 | + try { |
|
| 492 | 492 | $tar = new Tar(); |
| 493 | 493 | $tar->open($this->backup_storage_dir.DS.$backup_file, $start); |
| 494 | 494 | |
| 495 | 495 | $data = $tar->contents($this->process_files_limit_list); |
| 496 | - }catch(Exception $e) |
|
| 496 | + }catch (Exception $e) |
|
| 497 | 497 | { |
| 498 | 498 | $return['error'] = true; |
| 499 | 499 | $return['message'] = $e->getMessage(); |
| 500 | 500 | $this->send_response(200, $return); |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | - $return['files'] = array(); |
|
| 504 | - $return['finished'] = 1; |
|
| 505 | - $return['total_size'] = filesize($this->backup_storage_dir.DS.$backup_file); |
|
| 503 | + $return['files'] = array(); |
|
| 504 | + $return['finished'] = 1; |
|
| 505 | + $return['total_size'] = filesize($this->backup_storage_dir.DS.$backup_file); |
|
| 506 | 506 | $i = 0; |
| 507 | 507 | |
| 508 | - if(isset($data['extracted_files']) and is_array($data['extracted_files'])) |
|
| 508 | + if (isset($data['extracted_files']) and is_array($data['extracted_files'])) |
|
| 509 | 509 | { |
| 510 | - foreach($data['extracted_files'] as $file) |
|
| 510 | + foreach ($data['extracted_files'] as $file) |
|
| 511 | 511 | { |
| 512 | 512 | $return['files'][$i]['path'] = $file->getPath(); |
| 513 | 513 | $return['files'][$i]['size'] = $file->getSize(); |
@@ -517,18 +517,18 @@ discard block |
||
| 517 | 517 | } |
| 518 | 518 | } |
| 519 | 519 | |
| 520 | - if(isset($data['start'])) |
|
| 520 | + if (isset($data['start'])) |
|
| 521 | 521 | { |
| 522 | 522 | $return['start'] = $data['start']; |
| 523 | 523 | $return['finished'] = 0; |
| 524 | - }else{ |
|
| 525 | - if($this->is_multipart($source_backup_file)) |
|
| 524 | + } else { |
|
| 525 | + if ($this->is_multipart($source_backup_file)) |
|
| 526 | 526 | { |
| 527 | 527 | $return['start'] = 0; |
| 528 | 528 | |
| 529 | 529 | ++$return['part']; |
| 530 | 530 | |
| 531 | - if($return['part'] < sizeof($backup_parts)) |
|
| 531 | + if ($return['part'] < sizeof($backup_parts)) |
|
| 532 | 532 | $return['finished'] = 0; |
| 533 | 533 | |
| 534 | 534 | } |
@@ -551,28 +551,28 @@ discard block |
||
| 551 | 551 | |
| 552 | 552 | $remote_mysql_user = filter_input(INPUT_POST, 'remote_mysql_user', FILTER_SANITIZE_STRING); |
| 553 | 553 | $remote_mysql_pass = filter_input(INPUT_POST, 'remote_mysql_pass', FILTER_SANITIZE_STRING); |
| 554 | - $remote_mysql_db = filter_input(INPUT_POST, 'remote_mysql_db', FILTER_SANITIZE_STRING); |
|
| 554 | + $remote_mysql_db = filter_input(INPUT_POST, 'remote_mysql_db', FILTER_SANITIZE_STRING); |
|
| 555 | 555 | $remote_mysql_host = filter_input(INPUT_POST, 'remote_mysql_host', FILTER_SANITIZE_STRING); |
| 556 | 556 | |
| 557 | - $update_remote_site_url = filter_input(INPUT_POST, 'update_remote_site_url', FILTER_SANITIZE_NUMBER_INT); |
|
| 558 | - $delete_restore_script = filter_input(INPUT_POST, 'delete_restore_script', FILTER_SANITIZE_NUMBER_INT); |
|
| 559 | - $delete_backup_temporary_folder = filter_input(INPUT_POST, 'delete_backup_temporary_folder', FILTER_SANITIZE_NUMBER_INT); |
|
| 557 | + $update_remote_site_url = filter_input(INPUT_POST, 'update_remote_site_url', FILTER_SANITIZE_NUMBER_INT); |
|
| 558 | + $delete_restore_script = filter_input(INPUT_POST, 'delete_restore_script', FILTER_SANITIZE_NUMBER_INT); |
|
| 559 | + $delete_backup_temporary_folder = filter_input(INPUT_POST, 'delete_backup_temporary_folder', FILTER_SANITIZE_NUMBER_INT); |
|
| 560 | 560 | |
| 561 | - if($update_remote_site_url) |
|
| 561 | + if ($update_remote_site_url) |
|
| 562 | 562 | { |
| 563 | - $mysqli = $this->mysql_connect($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db ); |
|
| 563 | + $mysqli = $this->mysql_connect($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db); |
|
| 564 | 564 | $this->update_wp_config($remote_path, $remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db); |
| 565 | 565 | $this->update_wp_url($remote_path, $remote_restore_url, $mysqli); |
| 566 | 566 | } |
| 567 | 567 | |
| 568 | - if($delete_backup_temporary_folder) |
|
| 568 | + if ($delete_backup_temporary_folder) |
|
| 569 | 569 | { |
| 570 | 570 | $this->delete_backup_temporary_folder($remote_path); |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | - if(!defined('XCLONER_PLUGIN_ACCESS') || XCLONER_PLUGIN_ACCESS != 1) |
|
| 573 | + if (!defined('XCLONER_PLUGIN_ACCESS') || XCLONER_PLUGIN_ACCESS != 1) |
|
| 574 | 574 | { |
| 575 | - if($delete_restore_script) |
|
| 575 | + if ($delete_restore_script) |
|
| 576 | 576 | { |
| 577 | 577 | $this->delete_self(); |
| 578 | 578 | } |
@@ -590,7 +590,7 @@ discard block |
||
| 590 | 590 | */ |
| 591 | 591 | private function delete_backup_temporary_folder($remote_path) |
| 592 | 592 | { |
| 593 | - $this->target_adapter = new Local($remote_path ,LOCK_EX, 'SKIP_LINKS'); |
|
| 593 | + $this->target_adapter = new Local($remote_path, LOCK_EX, 'SKIP_LINKS'); |
|
| 594 | 594 | $this->target_filesystem = new Filesystem($this->target_adapter, new Config([ |
| 595 | 595 | 'disable_asserts' => true, |
| 596 | 596 | ])); |
@@ -598,13 +598,13 @@ discard block |
||
| 598 | 598 | $mysqldump_list = array(); |
| 599 | 599 | $list = $this->target_filesystem->listContents(); |
| 600 | 600 | |
| 601 | - foreach($list as $file) |
|
| 601 | + foreach ($list as $file) |
|
| 602 | 602 | { |
| 603 | 603 | $matches = array(); |
| 604 | 604 | |
| 605 | - if($file['type'] == "dir") |
|
| 605 | + if ($file['type'] == "dir") |
|
| 606 | 606 | { |
| 607 | - if(preg_match("/xcloner-(\w*)/", $file['basename'], $matches)){ |
|
| 607 | + if (preg_match("/xcloner-(\w*)/", $file['basename'], $matches)) { |
|
| 608 | 608 | $this->logger->info(sprintf('Deleting temporary folder %s', $file['path'])); |
| 609 | 609 | $this->target_filesystem->deleteDir($file['path']); |
| 610 | 610 | } |
@@ -622,29 +622,29 @@ discard block |
||
| 622 | 622 | */ |
| 623 | 623 | private function delete_self() |
| 624 | 624 | { |
| 625 | - if($this->filesystem->has("vendor.phar")) |
|
| 625 | + if ($this->filesystem->has("vendor.phar")) |
|
| 626 | 626 | { |
| 627 | 627 | $this->logger->info(sprintf('Deleting vendor.phar')); |
| 628 | 628 | $this->filesystem->delete("vendor.phar"); |
| 629 | 629 | } |
| 630 | - if($this->filesystem->has("vendor")) |
|
| 630 | + if ($this->filesystem->has("vendor")) |
|
| 631 | 631 | { |
| 632 | 632 | $this->logger->info(sprintf('Deleting vendor folder')); |
| 633 | 633 | $this->filesystem->deleteDir("vendor"); |
| 634 | 634 | } |
| 635 | - if($this->filesystem->has("xcloner_restore.php")) |
|
| 635 | + if ($this->filesystem->has("xcloner_restore.php")) |
|
| 636 | 636 | { |
| 637 | 637 | $this->logger->info(sprintf('Deleting xcloner_restore.php')); |
| 638 | 638 | $this->filesystem->delete("xcloner_restore.php"); |
| 639 | 639 | } |
| 640 | 640 | |
| 641 | - if($this->filesystem->has("xcloner_restore.log")) |
|
| 641 | + if ($this->filesystem->has("xcloner_restore.log")) |
|
| 642 | 642 | { |
| 643 | 643 | $this->logger->info(sprintf('Deleting xcloner_restore.log')); |
| 644 | 644 | $this->filesystem->delete("xcloner_restore.log"); |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | - if($this->filesystem->has($this->get_logger_filename())) |
|
| 647 | + if ($this->filesystem->has($this->get_logger_filename())) |
|
| 648 | 648 | { |
| 649 | 649 | $this->logger->info(sprintf('Deleting logger file %s', $this->get_logger_filename())); |
| 650 | 650 | $this->filesystem->delete($this->get_logger_filename()); |
@@ -666,11 +666,11 @@ discard block |
||
| 666 | 666 | |
| 667 | 667 | $this->logger->info(sprintf('Updating site url to %s', $url)); |
| 668 | 668 | |
| 669 | - if(file_exists($wp_config)) |
|
| 669 | + if (file_exists($wp_config)) |
|
| 670 | 670 | { |
| 671 | 671 | $config = file_get_contents($wp_config); |
| 672 | 672 | preg_match("/.*table_prefix.*=.*'(.*)'/i", $config, $matches); |
| 673 | - if(isset($matches[1])) |
|
| 673 | + if (isset($matches[1])) |
|
| 674 | 674 | $table_prefix = $matches[1]; |
| 675 | 675 | else |
| 676 | 676 | throw new Exception("Could not load wordpress table prefix from wp-config.php file."); |
@@ -678,10 +678,10 @@ discard block |
||
| 678 | 678 | else |
| 679 | 679 | throw new Exception("Could not update the SITEURL and HOME, wp-config.php file not found"); |
| 680 | 680 | |
| 681 | - if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='home'")) |
|
| 681 | + if (!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='home'")) |
|
| 682 | 682 | throw new Exception(sprintf("Could not update the HOME option, error: %s\n", $mysqli->error)); |
| 683 | 683 | |
| 684 | - if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='siteurl'")) |
|
| 684 | + if (!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='siteurl'")) |
|
| 685 | 685 | throw new Exception(sprintf("Could not update the SITEURL option, error: %s\n", $mysqli->error)); |
| 686 | 686 | |
| 687 | 687 | return true; |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | { |
| 703 | 703 | $wp_config = $remote_path.DS."wp-config.php"; |
| 704 | 704 | |
| 705 | - if(!file_exists($wp_config)) |
|
| 705 | + if (!file_exists($wp_config)) |
|
| 706 | 706 | { |
| 707 | 707 | throw new Exception("Could not find the wp-config.php in ".$remote_path); |
| 708 | 708 | } |
@@ -720,7 +720,7 @@ discard block |
||
| 720 | 720 | |
| 721 | 721 | $this->logger->info(sprintf('Updating wp-config.php file with the new mysql details')); |
| 722 | 722 | |
| 723 | - if(!file_put_contents($wp_config, $content)) |
|
| 723 | + if (!file_put_contents($wp_config, $content)) |
|
| 724 | 724 | throw new Exception("Could not write updated config data to ".$wp_config); |
| 725 | 725 | |
| 726 | 726 | chmod($wp_config, $file_perms); |
@@ -740,7 +740,7 @@ discard block |
||
| 740 | 740 | |
| 741 | 741 | $hash = $this->get_hash_from_backup($source_backup_file); |
| 742 | 742 | |
| 743 | - $this->target_adapter = new Local($remote_path ,LOCK_EX, 'SKIP_LINKS'); |
|
| 743 | + $this->target_adapter = new Local($remote_path, LOCK_EX, 'SKIP_LINKS'); |
|
| 744 | 744 | $this->target_filesystem = new Filesystem($this->target_adapter, new Config([ |
| 745 | 745 | 'disable_asserts' => true, |
| 746 | 746 | ])); |
@@ -748,25 +748,25 @@ discard block |
||
| 748 | 748 | $mysqldump_list = array(); |
| 749 | 749 | $list = $this->target_filesystem->listContents(); |
| 750 | 750 | |
| 751 | - foreach($list as $file) |
|
| 751 | + foreach ($list as $file) |
|
| 752 | 752 | { |
| 753 | 753 | $matches = array(); |
| 754 | 754 | |
| 755 | - if($file['type'] == "dir") |
|
| 755 | + if ($file['type'] == "dir") |
|
| 756 | 756 | { |
| 757 | - if(preg_match("/xcloner-(\w*)/", $file['basename'], $matches)) |
|
| 757 | + if (preg_match("/xcloner-(\w*)/", $file['basename'], $matches)) |
|
| 758 | 758 | { |
| 759 | 759 | $files = $this->target_filesystem->listContents($file['basename']); |
| 760 | - foreach($files as $file) |
|
| 760 | + foreach ($files as $file) |
|
| 761 | 761 | { |
| 762 | - if($file['extension'] == "sql") |
|
| 762 | + if ($file['extension'] == "sql") |
|
| 763 | 763 | { |
| 764 | 764 | $this->logger->info(sprintf('Found %s mysql backup file', $file['path'])); |
| 765 | 765 | $mysqldump_list[$file['path']]['path'] = $file['path']; |
| 766 | 766 | $mysqldump_list[$file['path']]['size'] = $file['size']; |
| 767 | - $mysqldump_list[$file['path']]['timestamp'] = date("d M,Y H:i",$file['timestamp']); |
|
| 767 | + $mysqldump_list[$file['path']]['timestamp'] = date("d M,Y H:i", $file['timestamp']); |
|
| 768 | 768 | |
| 769 | - if($hash and $hash == $matches[1]) |
|
| 769 | + if ($hash and $hash == $matches[1]) |
|
| 770 | 770 | $mysqldump_list[$file['path']]['selected'] = "selected"; |
| 771 | 771 | else |
| 772 | 772 | $mysqldump_list[$file['path']]['selected'] = ""; |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | } |
| 777 | 777 | } |
| 778 | 778 | |
| 779 | - $this->sort_by($mysqldump_list, 'timestamp','desc'); |
|
| 779 | + $this->sort_by($mysqldump_list, 'timestamp', 'desc'); |
|
| 780 | 780 | $return['files'] = $mysqldump_list; |
| 781 | 781 | |
| 782 | 782 | $this->send_response(200, $return); |
@@ -790,12 +790,12 @@ discard block |
||
| 790 | 790 | */ |
| 791 | 791 | private function get_hash_from_backup($backup_file) |
| 792 | 792 | { |
| 793 | - if(!$backup_file) |
|
| 793 | + if (!$backup_file) |
|
| 794 | 794 | return false; |
| 795 | 795 | |
| 796 | - $result = preg_match("/-(\w*)./", substr($backup_file, strlen($backup_file)-10, strlen($backup_file)), $matches) ; |
|
| 796 | + $result = preg_match("/-(\w*)./", substr($backup_file, strlen($backup_file) - 10, strlen($backup_file)), $matches); |
|
| 797 | 797 | |
| 798 | - if($result and isset($matches[1])) |
|
| 798 | + if ($result and isset($matches[1])) |
|
| 799 | 799 | return ($matches[1]); |
| 800 | 800 | |
| 801 | 801 | return false; |
@@ -814,18 +814,18 @@ discard block |
||
| 814 | 814 | $backup_files = array(); |
| 815 | 815 | $parents = array(); |
| 816 | 816 | |
| 817 | - foreach($list as $file_info) |
|
| 817 | + foreach ($list as $file_info) |
|
| 818 | 818 | { |
| 819 | 819 | $data = array(); |
| 820 | 820 | |
| 821 | - if(isset($file_info['extension']) and $file_info['extension'] == "csv") |
|
| 821 | + if (isset($file_info['extension']) and $file_info['extension'] == "csv") |
|
| 822 | 822 | { |
| 823 | 823 | $lines = explode(PHP_EOL, $this->filesystem->read($file_info['path'])); |
| 824 | - foreach($lines as $line) |
|
| 825 | - if($line) |
|
| 824 | + foreach ($lines as $line) |
|
| 825 | + if ($line) |
|
| 826 | 826 | { |
| 827 | 827 | $data = str_getcsv($line); |
| 828 | - if(is_array($data)){ |
|
| 828 | + if (is_array($data)) { |
|
| 829 | 829 | $parents[$data[0]] = $file_info['path']; |
| 830 | 830 | $file_info['childs'][] = $data; |
| 831 | 831 | $file_info['size'] += $data[2]; |
@@ -834,19 +834,19 @@ discard block |
||
| 834 | 834 | |
| 835 | 835 | } |
| 836 | 836 | |
| 837 | - if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
| 837 | + if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
| 838 | 838 | $backup_files[$file_info['path']] = $file_info; |
| 839 | 839 | } |
| 840 | 840 | |
| 841 | 841 | $new_list = array(); |
| 842 | 842 | |
| 843 | - foreach($backup_files as $key=>$file_info) |
|
| 843 | + foreach ($backup_files as $key=>$file_info) |
|
| 844 | 844 | { |
| 845 | - if(isset($parents[$file_info['path']])) |
|
| 845 | + if (isset($parents[$file_info['path']])) |
|
| 846 | 846 | $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
| 847 | - else{ |
|
| 847 | + else { |
|
| 848 | 848 | |
| 849 | - if($local_backup_file and ($file_info['basename'] == $local_backup_file)) |
|
| 849 | + if ($local_backup_file and ($file_info['basename'] == $local_backup_file)) |
|
| 850 | 850 | $file_info['selected'] = 'selected'; |
| 851 | 851 | |
| 852 | 852 | $this->logger->info(sprintf('Found %s backup file', $file_info['path'])); |
@@ -856,7 +856,7 @@ discard block |
||
| 856 | 856 | |
| 857 | 857 | } |
| 858 | 858 | |
| 859 | - $this->sort_by($new_list, "timestamp","desc"); |
|
| 859 | + $this->sort_by($new_list, "timestamp", "desc"); |
|
| 860 | 860 | |
| 861 | 861 | $return['files'] = $new_list; |
| 862 | 862 | |
@@ -872,15 +872,15 @@ discard block |
||
| 872 | 872 | */ |
| 873 | 873 | public function restore_backup_to_path_action() |
| 874 | 874 | { |
| 875 | - $source_backup_file = filter_input(INPUT_POST, 'backup_file', FILTER_SANITIZE_STRING); |
|
| 876 | - $remote_path = filter_input(INPUT_POST, 'remote_path', FILTER_SANITIZE_STRING); |
|
| 875 | + $source_backup_file = filter_input(INPUT_POST, 'backup_file', FILTER_SANITIZE_STRING); |
|
| 876 | + $remote_path = filter_input(INPUT_POST, 'remote_path', FILTER_SANITIZE_STRING); |
|
| 877 | 877 | $include_filter_files = filter_input(INPUT_POST, 'filter_files', FILTER_SANITIZE_STRING); |
| 878 | 878 | $exclude_filter_files = ""; |
| 879 | - $start = filter_input(INPUT_POST, 'start', FILTER_SANITIZE_NUMBER_INT); |
|
| 880 | - $return['part'] = (int)filter_input(INPUT_POST, 'part', FILTER_SANITIZE_NUMBER_INT); |
|
| 879 | + $start = filter_input(INPUT_POST, 'start', FILTER_SANITIZE_NUMBER_INT); |
|
| 880 | + $return['part'] = (int)filter_input(INPUT_POST, 'part', FILTER_SANITIZE_NUMBER_INT); |
|
| 881 | 881 | $return['processed'] = (int)filter_input(INPUT_POST, 'processed', FILTER_SANITIZE_NUMBER_INT); |
| 882 | 882 | |
| 883 | - $this->target_adapter = new Local($remote_path ,LOCK_EX, 'SKIP_LINKS'); |
|
| 883 | + $this->target_adapter = new Local($remote_path, LOCK_EX, 'SKIP_LINKS'); |
|
| 884 | 884 | $this->target_filesystem = new Filesystem($this->target_adapter, new Config([ |
| 885 | 885 | 'disable_asserts' => true, |
| 886 | 886 | ])); |
@@ -892,9 +892,9 @@ discard block |
||
| 892 | 892 | $return['total_size'] = $this->get_backup_size($backup_file); |
| 893 | 893 | |
| 894 | 894 | $backup_archive = new Tar(); |
| 895 | - if($this->is_multipart($backup_file)) |
|
| 895 | + if ($this->is_multipart($backup_file)) |
|
| 896 | 896 | { |
| 897 | - if(!$return['part']) |
|
| 897 | + if (!$return['part']) |
|
| 898 | 898 | $return['processed'] += $this->filesystem->getSize($backup_file); |
| 899 | 899 | |
| 900 | 900 | $backup_parts = $this->get_multipart_files($backup_file); |
@@ -902,41 +902,41 @@ discard block |
||
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | $this->logger->info(sprintf('Opening backup archive %s at position %s', $backup_file, $start)); |
| 905 | - $backup_archive->open($this->backup_storage_dir .DS. $backup_file, $start); |
|
| 905 | + $backup_archive->open($this->backup_storage_dir.DS.$backup_file, $start); |
|
| 906 | 906 | |
| 907 | - $data = $backup_archive->extract($remote_path, '',$exclude_filter_files,$include_filter_files, $this->process_files_limit); |
|
| 907 | + $data = $backup_archive->extract($remote_path, '', $exclude_filter_files, $include_filter_files, $this->process_files_limit); |
|
| 908 | 908 | |
| 909 | - if(isset($data['extracted_files'])) |
|
| 909 | + if (isset($data['extracted_files'])) |
|
| 910 | 910 | { |
| 911 | - foreach($data['extracted_files'] as $spl_fileinfo) |
|
| 911 | + foreach ($data['extracted_files'] as $spl_fileinfo) |
|
| 912 | 912 | { |
| 913 | 913 | $this->logger->info(sprintf('Extracted %s file', $spl_fileinfo->getPath())); |
| 914 | 914 | $return['extracted_files'][] = $spl_fileinfo->getPath()." (".$spl_fileinfo->getSize()." bytes)"; |
| 915 | 915 | } |
| 916 | 916 | } |
| 917 | 917 | |
| 918 | - if(isset($data['start'])) |
|
| 918 | + if (isset($data['start'])) |
|
| 919 | 919 | //if(isset($data['start']) and $data['start'] <= $this->filesystem->getSize($backup_file)) |
| 920 | 920 | { |
| 921 | 921 | $return['finished'] = 0; |
| 922 | 922 | $return['start'] = $data['start']; |
| 923 | - }else{ |
|
| 923 | + } else { |
|
| 924 | 924 | |
| 925 | 925 | $return['processed'] += $start; |
| 926 | 926 | |
| 927 | - if($this->is_multipart($source_backup_file)) |
|
| 927 | + if ($this->is_multipart($source_backup_file)) |
|
| 928 | 928 | { |
| 929 | 929 | $return['start'] = 0; |
| 930 | 930 | |
| 931 | 931 | ++$return['part']; |
| 932 | 932 | |
| 933 | - if($return['part'] < sizeof($backup_parts)) |
|
| 933 | + if ($return['part'] < sizeof($backup_parts)) |
|
| 934 | 934 | $return['finished'] = 0; |
| 935 | 935 | |
| 936 | 936 | } |
| 937 | 937 | } |
| 938 | 938 | |
| 939 | - if($return['finished']) |
|
| 939 | + if ($return['finished']) |
|
| 940 | 940 | $this->logger->info(sprintf('Done extracting %s', $source_backup_file)); |
| 941 | 941 | |
| 942 | 942 | $return['backup_file'] = $backup_file; |
@@ -953,24 +953,24 @@ discard block |
||
| 953 | 953 | |
| 954 | 954 | $restore_script_url = filter_input(INPUT_POST, 'restore_script_url', FILTER_SANITIZE_STRING); |
| 955 | 955 | |
| 956 | - $pathinfo = pathinfo( __FILE__); |
|
| 956 | + $pathinfo = pathinfo(__FILE__); |
|
| 957 | 957 | |
| 958 | 958 | $suffix = ""; |
| 959 | 959 | $return['remote_mysql_host'] = "localhost"; |
| 960 | 960 | $return['remote_mysql_user'] = ""; |
| 961 | 961 | $return['remote_mysql_pass'] = ""; |
| 962 | - $return['remote_mysql_db'] = ""; |
|
| 962 | + $return['remote_mysql_db'] = ""; |
|
| 963 | 963 | |
| 964 | - if(defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS) |
|
| 964 | + if (defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS) |
|
| 965 | 965 | { |
| 966 | 966 | $return['dir'] = realpath(get_home_path().DS.$suffix); |
| 967 | - $return['restore_script_url'] = get_site_url(); |
|
| 967 | + $return['restore_script_url'] = get_site_url(); |
|
| 968 | 968 | $return['remote_mysql_host'] = $wpdb->dbhost; |
| 969 | 969 | $return['remote_mysql_user'] = $wpdb->dbuser; |
| 970 | 970 | $return['remote_mysql_pass'] = $wpdb->dbpassword; |
| 971 | - $return['remote_mysql_db'] = $wpdb->dbname; |
|
| 971 | + $return['remote_mysql_db'] = $wpdb->dbname; |
|
| 972 | 972 | } |
| 973 | - else{ |
|
| 973 | + else { |
|
| 974 | 974 | $return['dir'] = ($pathinfo['dirname']).DS.$suffix; |
| 975 | 975 | $return['restore_script_url'] = str_replace($pathinfo['basename'], "", $restore_script_url).$suffix; |
| 976 | 976 | } |
@@ -989,17 +989,17 @@ discard block |
||
| 989 | 989 | { |
| 990 | 990 | //check if i can write |
| 991 | 991 | $tmp_file = md5(time()); |
| 992 | - if(!file_put_contents($tmp_file, "++")) |
|
| 992 | + if (!file_put_contents($tmp_file, "++")) |
|
| 993 | 993 | throw new Exception("Could not write to new host"); |
| 994 | 994 | |
| 995 | - if(!unlink($tmp_file)) |
|
| 995 | + if (!unlink($tmp_file)) |
|
| 996 | 996 | throw new Exception("Could not delete temporary file from new host"); |
| 997 | 997 | |
| 998 | 998 | $max_upload = $this->return_bytes((ini_get('upload_max_filesize'))); |
| 999 | 999 | $max_post = $this->return_bytes((ini_get('post_max_size'))); |
| 1000 | 1000 | |
| 1001 | 1001 | $return['max_upload_size'] = min($max_upload, $max_post); // bytes |
| 1002 | - $return['status'] = true; |
|
| 1002 | + $return['status'] = true; |
|
| 1003 | 1003 | |
| 1004 | 1004 | $this->logger->info(sprintf('Current filesystem max upload size is %s bytes', $return['max_upload_size'])); |
| 1005 | 1005 | |
@@ -1015,8 +1015,8 @@ discard block |
||
| 1015 | 1015 | */ |
| 1016 | 1016 | private function return_bytes($val) { |
| 1017 | 1017 | $numeric_val = (int)trim($val); |
| 1018 | - $last = strtolower($val[strlen($val)-1]); |
|
| 1019 | - switch($last) { |
|
| 1018 | + $last = strtolower($val[strlen($val) - 1]); |
|
| 1019 | + switch ($last) { |
|
| 1020 | 1020 | // The 'G' modifier is available since PHP 5.1.0 |
| 1021 | 1021 | case 'g': |
| 1022 | 1022 | $numeric_val *= 1024; |
@@ -1037,7 +1037,7 @@ discard block |
||
| 1037 | 1037 | */ |
| 1038 | 1038 | public function is_multipart($backup_name) |
| 1039 | 1039 | { |
| 1040 | - if(stristr($backup_name, "-multipart")) |
|
| 1040 | + if (stristr($backup_name, "-multipart")) |
|
| 1041 | 1041 | return true; |
| 1042 | 1042 | |
| 1043 | 1043 | return false; |
@@ -1053,10 +1053,10 @@ discard block |
||
| 1053 | 1053 | public function get_backup_size($backup_name) |
| 1054 | 1054 | { |
| 1055 | 1055 | $backup_size = $this->filesystem->getSize($backup_name); |
| 1056 | - if($this->is_multipart($backup_name)) |
|
| 1056 | + if ($this->is_multipart($backup_name)) |
|
| 1057 | 1057 | { |
| 1058 | 1058 | $backup_parts = $this->get_multipart_files($backup_name); |
| 1059 | - foreach($backup_parts as $part_file) |
|
| 1059 | + foreach ($backup_parts as $part_file) |
|
| 1060 | 1060 | $backup_size += $this->filesystem->getSize($part_file); |
| 1061 | 1061 | } |
| 1062 | 1062 | |
@@ -1073,12 +1073,12 @@ discard block |
||
| 1073 | 1073 | { |
| 1074 | 1074 | $files = array(); |
| 1075 | 1075 | |
| 1076 | - if($this->is_multipart($backup_name)) |
|
| 1076 | + if ($this->is_multipart($backup_name)) |
|
| 1077 | 1077 | { |
| 1078 | 1078 | $lines = explode(PHP_EOL, $this->filesystem->read($backup_name)); |
| 1079 | - foreach($lines as $line) |
|
| 1079 | + foreach ($lines as $line) |
|
| 1080 | 1080 | { |
| 1081 | - if($line) |
|
| 1081 | + if ($line) |
|
| 1082 | 1082 | { |
| 1083 | 1083 | $data = str_getcsv($line); |
| 1084 | 1084 | $files[] = $data[0]; |
@@ -1097,7 +1097,7 @@ discard block |
||
| 1097 | 1097 | * @param string $direction |
| 1098 | 1098 | * @return bool |
| 1099 | 1099 | */ |
| 1100 | - private function sort_by( &$array, $field, $direction = 'asc') |
|
| 1100 | + private function sort_by(&$array, $field, $direction = 'asc') |
|
| 1101 | 1101 | { |
| 1102 | 1102 | $direction = strtolower($direction); |
| 1103 | 1103 | |
@@ -1112,18 +1112,18 @@ discard block |
||
| 1112 | 1112 | return 0; |
| 1113 | 1113 | } |
| 1114 | 1114 | |
| 1115 | - if($direction == 'desc') { |
|
| 1116 | - if($a > $b) { |
|
| 1115 | + if ($direction == 'desc') { |
|
| 1116 | + if ($a > $b) { |
|
| 1117 | 1117 | return -1; |
| 1118 | 1118 | } |
| 1119 | - else{ |
|
| 1119 | + else { |
|
| 1120 | 1120 | return 1; |
| 1121 | 1121 | } |
| 1122 | - }else { |
|
| 1123 | - if($a < $b) { |
|
| 1122 | + } else { |
|
| 1123 | + if ($a < $b) { |
|
| 1124 | 1124 | return -1; |
| 1125 | 1125 | } |
| 1126 | - else{ |
|
| 1126 | + else { |
|
| 1127 | 1127 | return 1; |
| 1128 | 1128 | } |
| 1129 | 1129 | } |
@@ -1149,11 +1149,11 @@ discard block |
||
| 1149 | 1149 | $return['status'] = $status; |
| 1150 | 1150 | $return['statusText'] = $response; |
| 1151 | 1151 | |
| 1152 | - if(isset($response['error']) && $response['error']) |
|
| 1152 | + if (isset($response['error']) && $response['error']) |
|
| 1153 | 1153 | { |
| 1154 | 1154 | $return['statusText'] = $response['message']; |
| 1155 | 1155 | $return['error'] = true; |
| 1156 | - }elseif($status != 200 and $status != 418) |
|
| 1156 | + }elseif ($status != 200 and $status != 418) |
|
| 1157 | 1157 | { |
| 1158 | 1158 | $return['error'] = true; |
| 1159 | 1159 | $return['message'] = $response; |
@@ -1172,12 +1172,12 @@ discard block |
||
| 1172 | 1172 | |
| 1173 | 1173 | function do_serialized_fix($query) |
| 1174 | 1174 | { |
| 1175 | - $query = str_replace(array("\\n","\\r","\\'"), array("","","\""), ($query)); |
|
| 1175 | + $query = str_replace(array("\\n", "\\r", "\\'"), array("", "", "\""), ($query)); |
|
| 1176 | 1176 | |
| 1177 | - return preg_replace_callback('!s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");!', function ($m) { |
|
| 1177 | + return preg_replace_callback('!s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");!', function($m) { |
|
| 1178 | 1178 | $data = ""; |
| 1179 | 1179 | |
| 1180 | - if(!isset($m[3])) |
|
| 1180 | + if (!isset($m[3])) |
|
| 1181 | 1181 | $m[3] = ""; |
| 1182 | 1182 | |
| 1183 | 1183 | $data = 's:'.strlen(($m[3])).':\"'.($m[3]).'\";'; |
@@ -1204,8 +1204,8 @@ discard block |
||
| 1204 | 1204 | * @return mixed |
| 1205 | 1205 | */ |
| 1206 | 1206 | private function unescape_mysql($value) { |
| 1207 | - return str_replace(array("\\\\", "\\0", "\\n", "\\r", "\Z", "\'", '\"'), |
|
| 1208 | - array("\\", "\0", "\n", "\r", "\x1a", "'", '"'), |
|
| 1207 | + return str_replace(array("\\\\", "\\0", "\\n", "\\r", "\Z", "\'", '\"'), |
|
| 1208 | + array("\\", "\0", "\n", "\r", "\x1a", "'", '"'), |
|
| 1209 | 1209 | $value); |
| 1210 | 1210 | } |
| 1211 | 1211 | |
@@ -1217,14 +1217,14 @@ discard block |
||
| 1217 | 1217 | */ |
| 1218 | 1218 | private function has_serialized($s) |
| 1219 | 1219 | { |
| 1220 | - if( |
|
| 1221 | - stristr($s, '{' ) !== false && |
|
| 1222 | - stristr($s, '}' ) !== false && |
|
| 1223 | - stristr($s, ';' ) !== false && |
|
| 1224 | - stristr($s, ':' ) !== false |
|
| 1225 | - ){ |
|
| 1220 | + if ( |
|
| 1221 | + stristr($s, '{') !== false && |
|
| 1222 | + stristr($s, '}') !== false && |
|
| 1223 | + stristr($s, ';') !== false && |
|
| 1224 | + stristr($s, ':') !== false |
|
| 1225 | + ) { |
|
| 1226 | 1226 | return true; |
| 1227 | - }else{ |
|
| 1227 | + } else { |
|
| 1228 | 1228 | return false; |
| 1229 | 1229 | } |
| 1230 | 1230 | |
@@ -45,11 +45,10 @@ discard block |
||
| 45 | 45 | { |
| 46 | 46 | |
| 47 | 47 | require_once($file); |
| 48 | -} |
|
| 49 | -elseif(file_exists("vendor.phar") and extension_loaded('phar')) |
|
| 48 | +} elseif(file_exists("vendor.phar") and extension_loaded('phar')) |
|
| 50 | 49 | { |
| 51 | 50 | require_once(__DIR__.DS."vendor.phar"); |
| 52 | -}else{ |
|
| 51 | +} else{ |
|
| 53 | 52 | |
| 54 | 53 | $file = dirname( __FILE__ ) . DS.'vendor'.DS.'autoload.php'; |
| 55 | 54 | |
@@ -87,7 +86,7 @@ discard block |
||
| 87 | 86 | try{ |
| 88 | 87 | $return = $xcloner_restore->init(); |
| 89 | 88 | $xcloner_restore->send_response(200, $return); |
| 90 | -}catch(Exception $e){ |
|
| 89 | +} catch(Exception $e){ |
|
| 91 | 90 | $xcloner_restore->send_response(417, $e->getMessage()); |
| 92 | 91 | } |
| 93 | 92 | |
@@ -208,7 +207,7 @@ discard block |
||
| 208 | 207 | $this->logger->debug(sprintf('Starting action %s', $method)); |
| 209 | 208 | return call_user_func(array($this, $method)); |
| 210 | 209 | |
| 211 | - }else{ |
|
| 210 | + } else{ |
|
| 212 | 211 | throw new Exception($method ." does not exists"); |
| 213 | 212 | } |
| 214 | 213 | } |
@@ -228,13 +227,15 @@ discard block |
||
| 228 | 227 | { |
| 229 | 228 | $target_file = filter_input(INPUT_POST, 'file', FILTER_SANITIZE_STRING); |
| 230 | 229 | |
| 231 | - if(!$_POST['start']) |
|
| 232 | - $fp = fopen($target_file, "wb+"); |
|
| 233 | - else |
|
| 234 | - $fp = fopen($target_file, "ab+"); |
|
| 230 | + if(!$_POST['start']) { |
|
| 231 | + $fp = fopen($target_file, "wb+"); |
|
| 232 | + } else { |
|
| 233 | + $fp = fopen($target_file, "ab+"); |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - if(!$fp) |
|
| 237 | - throw new Exception("Unable to open $target_file file for writing"); |
|
| 236 | + if(!$fp) { |
|
| 237 | + throw new Exception("Unable to open $target_file file for writing"); |
|
| 238 | + } |
|
| 238 | 239 | |
| 239 | 240 | fseek($fp, $_POST['start']); |
| 240 | 241 | |
@@ -244,23 +245,25 @@ discard block |
||
| 244 | 245 | |
| 245 | 246 | $blob = file_get_contents($_FILES['blob']['tmp_name']); |
| 246 | 247 | |
| 247 | - if(!$bytes_written = fwrite($fp, $blob)) |
|
| 248 | - throw new Exception("Unable to write data to file $target_file"); |
|
| 248 | + if(!$bytes_written = fwrite($fp, $blob)) { |
|
| 249 | + throw new Exception("Unable to write data to file $target_file"); |
|
| 250 | + } |
|
| 249 | 251 | |
| 250 | 252 | try { |
| 251 | 253 | unlink($_FILES['blob']['tmp_name']); |
| 252 | - }catch(Exception $e){ |
|
| 254 | + } catch(Exception $e){ |
|
| 253 | 255 | |
| 254 | 256 | } |
| 255 | 257 | |
| 256 | - }elseif(isset($_POST['blob'])){ |
|
| 258 | + } elseif(isset($_POST['blob'])){ |
|
| 257 | 259 | $this->logger->debug(sprintf('Writing %s bytes to file %s starting position %s using POST blob', strlen($_POST['blob']), $target_file, $_POST['start'])); |
| 258 | 260 | |
| 259 | 261 | $blob = $_POST['blob']; |
| 260 | 262 | |
| 261 | - if(!$bytes_written = fwrite($fp, $blob)) |
|
| 262 | - throw new Exception("Unable to write data to file $target_file"); |
|
| 263 | - }else{ |
|
| 263 | + if(!$bytes_written = fwrite($fp, $blob)) { |
|
| 264 | + throw new Exception("Unable to write data to file $target_file"); |
|
| 265 | + } |
|
| 266 | + } else{ |
|
| 264 | 267 | throw new Exception("Upload failed, did not receive any binary data"); |
| 265 | 268 | } |
| 266 | 269 | |
@@ -294,10 +297,11 @@ discard block |
||
| 294 | 297 | |
| 295 | 298 | $mysqli->query("SET sql_mode='';"); |
| 296 | 299 | $mysqli->query("SET foreign_key_checks = 0;"); |
| 297 | - if(isset($_REQUEST['charset_of_file']) and $_REQUEST['charset_of_file']) |
|
| 298 | - $mysqli->query("SET NAMES ".$_REQUEST['charset_of_file'].""); |
|
| 299 | - else |
|
| 300 | - $mysqli->query("SET NAMES utf8;"); |
|
| 300 | + if(isset($_REQUEST['charset_of_file']) and $_REQUEST['charset_of_file']) { |
|
| 301 | + $mysqli->query("SET NAMES ".$_REQUEST['charset_of_file'].""); |
|
| 302 | + } else { |
|
| 303 | + $mysqli->query("SET NAMES utf8;"); |
|
| 304 | + } |
|
| 301 | 305 | |
| 302 | 306 | return $mysqli; |
| 303 | 307 | } |
@@ -327,8 +331,9 @@ discard block |
||
| 327 | 331 | |
| 328 | 332 | $mysql_backup_file = $remote_path.DS.$mysqldump_file; |
| 329 | 333 | |
| 330 | - if(!file_exists($mysql_backup_file)) |
|
| 331 | - throw new Exception(sprintf("Mysql backup file %s does not exists",$mysql_backup_file)); |
|
| 334 | + if(!file_exists($mysql_backup_file)) { |
|
| 335 | + throw new Exception(sprintf("Mysql backup file %s does not exists",$mysql_backup_file)); |
|
| 336 | + } |
|
| 332 | 337 | |
| 333 | 338 | |
| 334 | 339 | /*if(defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS) |
@@ -360,16 +365,18 @@ discard block |
||
| 360 | 365 | // process the line read. |
| 361 | 366 | |
| 362 | 367 | //check if line is comment |
| 363 | - if(substr($line, 0, 1) == "#") |
|
| 364 | - continue; |
|
| 368 | + if(substr($line, 0, 1) == "#") { |
|
| 369 | + continue; |
|
| 370 | + } |
|
| 365 | 371 | |
| 366 | 372 | //check if line is empty |
| 367 | - if($line == "\n" or trim($line) == "") |
|
| 368 | - continue; |
|
| 373 | + if($line == "\n" or trim($line) == "") { |
|
| 374 | + continue; |
|
| 375 | + } |
|
| 369 | 376 | |
| 370 | - if(substr($line, strlen($line)-2, strlen($line)) == ";\n") |
|
| 371 | - $query .= $line; |
|
| 372 | - else{ |
|
| 377 | + if(substr($line, strlen($line)-2, strlen($line)) == ";\n") { |
|
| 378 | + $query .= $line; |
|
| 379 | + } else{ |
|
| 373 | 380 | $query .= $line; |
| 374 | 381 | continue; |
| 375 | 382 | } |
@@ -428,7 +435,7 @@ discard block |
||
| 428 | 435 | if(!feof($fp)) |
| 429 | 436 | { |
| 430 | 437 | $return['finished'] = 0; |
| 431 | - }else{ |
|
| 438 | + } else{ |
|
| 432 | 439 | $this->logger->info(sprintf("Mysql Import Done.")); |
| 433 | 440 | } |
| 434 | 441 | |
@@ -493,7 +500,7 @@ discard block |
||
| 493 | 500 | $tar->open($this->backup_storage_dir.DS.$backup_file, $start); |
| 494 | 501 | |
| 495 | 502 | $data = $tar->contents($this->process_files_limit_list); |
| 496 | - }catch(Exception $e) |
|
| 503 | + } catch(Exception $e) |
|
| 497 | 504 | { |
| 498 | 505 | $return['error'] = true; |
| 499 | 506 | $return['message'] = $e->getMessage(); |
@@ -521,15 +528,16 @@ discard block |
||
| 521 | 528 | { |
| 522 | 529 | $return['start'] = $data['start']; |
| 523 | 530 | $return['finished'] = 0; |
| 524 | - }else{ |
|
| 531 | + } else{ |
|
| 525 | 532 | if($this->is_multipart($source_backup_file)) |
| 526 | 533 | { |
| 527 | 534 | $return['start'] = 0; |
| 528 | 535 | |
| 529 | 536 | ++$return['part']; |
| 530 | 537 | |
| 531 | - if($return['part'] < sizeof($backup_parts)) |
|
| 532 | - $return['finished'] = 0; |
|
| 538 | + if($return['part'] < sizeof($backup_parts)) { |
|
| 539 | + $return['finished'] = 0; |
|
| 540 | + } |
|
| 533 | 541 | |
| 534 | 542 | } |
| 535 | 543 | } |
@@ -670,19 +678,22 @@ discard block |
||
| 670 | 678 | { |
| 671 | 679 | $config = file_get_contents($wp_config); |
| 672 | 680 | preg_match("/.*table_prefix.*=.*'(.*)'/i", $config, $matches); |
| 673 | - if(isset($matches[1])) |
|
| 674 | - $table_prefix = $matches[1]; |
|
| 675 | - else |
|
| 676 | - throw new Exception("Could not load wordpress table prefix from wp-config.php file."); |
|
| 681 | + if(isset($matches[1])) { |
|
| 682 | + $table_prefix = $matches[1]; |
|
| 683 | + } else { |
|
| 684 | + throw new Exception("Could not load wordpress table prefix from wp-config.php file."); |
|
| 685 | + } |
|
| 686 | + } else { |
|
| 687 | + throw new Exception("Could not update the SITEURL and HOME, wp-config.php file not found"); |
|
| 677 | 688 | } |
| 678 | - else |
|
| 679 | - throw new Exception("Could not update the SITEURL and HOME, wp-config.php file not found"); |
|
| 680 | 689 | |
| 681 | - if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='home'")) |
|
| 682 | - throw new Exception(sprintf("Could not update the HOME option, error: %s\n", $mysqli->error)); |
|
| 690 | + if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='home'")) { |
|
| 691 | + throw new Exception(sprintf("Could not update the HOME option, error: %s\n", $mysqli->error)); |
|
| 692 | + } |
|
| 683 | 693 | |
| 684 | - if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='siteurl'")) |
|
| 685 | - throw new Exception(sprintf("Could not update the SITEURL option, error: %s\n", $mysqli->error)); |
|
| 694 | + if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='siteurl'")) { |
|
| 695 | + throw new Exception(sprintf("Could not update the SITEURL option, error: %s\n", $mysqli->error)); |
|
| 696 | + } |
|
| 686 | 697 | |
| 687 | 698 | return true; |
| 688 | 699 | } |
@@ -720,8 +731,9 @@ discard block |
||
| 720 | 731 | |
| 721 | 732 | $this->logger->info(sprintf('Updating wp-config.php file with the new mysql details')); |
| 722 | 733 | |
| 723 | - if(!file_put_contents($wp_config, $content)) |
|
| 724 | - throw new Exception("Could not write updated config data to ".$wp_config); |
|
| 734 | + if(!file_put_contents($wp_config, $content)) { |
|
| 735 | + throw new Exception("Could not write updated config data to ".$wp_config); |
|
| 736 | + } |
|
| 725 | 737 | |
| 726 | 738 | chmod($wp_config, $file_perms); |
| 727 | 739 | |
@@ -766,10 +778,11 @@ discard block |
||
| 766 | 778 | $mysqldump_list[$file['path']]['size'] = $file['size']; |
| 767 | 779 | $mysqldump_list[$file['path']]['timestamp'] = date("d M,Y H:i",$file['timestamp']); |
| 768 | 780 | |
| 769 | - if($hash and $hash == $matches[1]) |
|
| 770 | - $mysqldump_list[$file['path']]['selected'] = "selected"; |
|
| 771 | - else |
|
| 772 | - $mysqldump_list[$file['path']]['selected'] = ""; |
|
| 781 | + if($hash and $hash == $matches[1]) { |
|
| 782 | + $mysqldump_list[$file['path']]['selected'] = "selected"; |
|
| 783 | + } else { |
|
| 784 | + $mysqldump_list[$file['path']]['selected'] = ""; |
|
| 785 | + } |
|
| 773 | 786 | } |
| 774 | 787 | } |
| 775 | 788 | } |
@@ -790,13 +803,15 @@ discard block |
||
| 790 | 803 | */ |
| 791 | 804 | private function get_hash_from_backup($backup_file) |
| 792 | 805 | { |
| 793 | - if(!$backup_file) |
|
| 794 | - return false; |
|
| 806 | + if(!$backup_file) { |
|
| 807 | + return false; |
|
| 808 | + } |
|
| 795 | 809 | |
| 796 | 810 | $result = preg_match("/-(\w*)./", substr($backup_file, strlen($backup_file)-10, strlen($backup_file)), $matches) ; |
| 797 | 811 | |
| 798 | - if($result and isset($matches[1])) |
|
| 799 | - return ($matches[1]); |
|
| 812 | + if($result and isset($matches[1])) { |
|
| 813 | + return ($matches[1]); |
|
| 814 | + } |
|
| 800 | 815 | |
| 801 | 816 | return false; |
| 802 | 817 | } |
@@ -821,10 +836,11 @@ discard block |
||
| 821 | 836 | if(isset($file_info['extension']) and $file_info['extension'] == "csv") |
| 822 | 837 | { |
| 823 | 838 | $lines = explode(PHP_EOL, $this->filesystem->read($file_info['path'])); |
| 824 | - foreach($lines as $line) |
|
| 825 | - if($line) |
|
| 839 | + foreach($lines as $line) { |
|
| 840 | + if($line) |
|
| 826 | 841 | { |
| 827 | 842 | $data = str_getcsv($line); |
| 843 | + } |
|
| 828 | 844 | if(is_array($data)){ |
| 829 | 845 | $parents[$data[0]] = $file_info['path']; |
| 830 | 846 | $file_info['childs'][] = $data; |
@@ -834,20 +850,22 @@ discard block |
||
| 834 | 850 | |
| 835 | 851 | } |
| 836 | 852 | |
| 837 | - if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
| 838 | - $backup_files[$file_info['path']] = $file_info; |
|
| 853 | + if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) { |
|
| 854 | + $backup_files[$file_info['path']] = $file_info; |
|
| 855 | + } |
|
| 839 | 856 | } |
| 840 | 857 | |
| 841 | 858 | $new_list = array(); |
| 842 | 859 | |
| 843 | 860 | foreach($backup_files as $key=>$file_info) |
| 844 | 861 | { |
| 845 | - if(isset($parents[$file_info['path']])) |
|
| 846 | - $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
|
| 847 | - else{ |
|
| 862 | + if(isset($parents[$file_info['path']])) { |
|
| 863 | + $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
|
| 864 | + } else{ |
|
| 848 | 865 | |
| 849 | - if($local_backup_file and ($file_info['basename'] == $local_backup_file)) |
|
| 850 | - $file_info['selected'] = 'selected'; |
|
| 866 | + if($local_backup_file and ($file_info['basename'] == $local_backup_file)) { |
|
| 867 | + $file_info['selected'] = 'selected'; |
|
| 868 | + } |
|
| 851 | 869 | |
| 852 | 870 | $this->logger->info(sprintf('Found %s backup file', $file_info['path'])); |
| 853 | 871 | |
@@ -894,8 +912,9 @@ discard block |
||
| 894 | 912 | $backup_archive = new Tar(); |
| 895 | 913 | if($this->is_multipart($backup_file)) |
| 896 | 914 | { |
| 897 | - if(!$return['part']) |
|
| 898 | - $return['processed'] += $this->filesystem->getSize($backup_file); |
|
| 915 | + if(!$return['part']) { |
|
| 916 | + $return['processed'] += $this->filesystem->getSize($backup_file); |
|
| 917 | + } |
|
| 899 | 918 | |
| 900 | 919 | $backup_parts = $this->get_multipart_files($backup_file); |
| 901 | 920 | $backup_file = $backup_parts[$return['part']]; |
@@ -915,12 +934,13 @@ discard block |
||
| 915 | 934 | } |
| 916 | 935 | } |
| 917 | 936 | |
| 918 | - if(isset($data['start'])) |
|
| 919 | - //if(isset($data['start']) and $data['start'] <= $this->filesystem->getSize($backup_file)) |
|
| 937 | + if(isset($data['start'])) { |
|
| 938 | + //if(isset($data['start']) and $data['start'] <= $this->filesystem->getSize($backup_file)) |
|
| 920 | 939 | { |
| 921 | 940 | $return['finished'] = 0; |
| 941 | + } |
|
| 922 | 942 | $return['start'] = $data['start']; |
| 923 | - }else{ |
|
| 943 | + } else{ |
|
| 924 | 944 | |
| 925 | 945 | $return['processed'] += $start; |
| 926 | 946 | |
@@ -930,14 +950,16 @@ discard block |
||
| 930 | 950 | |
| 931 | 951 | ++$return['part']; |
| 932 | 952 | |
| 933 | - if($return['part'] < sizeof($backup_parts)) |
|
| 934 | - $return['finished'] = 0; |
|
| 953 | + if($return['part'] < sizeof($backup_parts)) { |
|
| 954 | + $return['finished'] = 0; |
|
| 955 | + } |
|
| 935 | 956 | |
| 936 | 957 | } |
| 937 | 958 | } |
| 938 | 959 | |
| 939 | - if($return['finished']) |
|
| 940 | - $this->logger->info(sprintf('Done extracting %s', $source_backup_file)); |
|
| 960 | + if($return['finished']) { |
|
| 961 | + $this->logger->info(sprintf('Done extracting %s', $source_backup_file)); |
|
| 962 | + } |
|
| 941 | 963 | |
| 942 | 964 | $return['backup_file'] = $backup_file; |
| 943 | 965 | |
@@ -969,8 +991,7 @@ discard block |
||
| 969 | 991 | $return['remote_mysql_user'] = $wpdb->dbuser; |
| 970 | 992 | $return['remote_mysql_pass'] = $wpdb->dbpassword; |
| 971 | 993 | $return['remote_mysql_db'] = $wpdb->dbname; |
| 972 | - } |
|
| 973 | - else{ |
|
| 994 | + } else{ |
|
| 974 | 995 | $return['dir'] = ($pathinfo['dirname']).DS.$suffix; |
| 975 | 996 | $return['restore_script_url'] = str_replace($pathinfo['basename'], "", $restore_script_url).$suffix; |
| 976 | 997 | } |
@@ -989,11 +1010,13 @@ discard block |
||
| 989 | 1010 | { |
| 990 | 1011 | //check if i can write |
| 991 | 1012 | $tmp_file = md5(time()); |
| 992 | - if(!file_put_contents($tmp_file, "++")) |
|
| 993 | - throw new Exception("Could not write to new host"); |
|
| 1013 | + if(!file_put_contents($tmp_file, "++")) { |
|
| 1014 | + throw new Exception("Could not write to new host"); |
|
| 1015 | + } |
|
| 994 | 1016 | |
| 995 | - if(!unlink($tmp_file)) |
|
| 996 | - throw new Exception("Could not delete temporary file from new host"); |
|
| 1017 | + if(!unlink($tmp_file)) { |
|
| 1018 | + throw new Exception("Could not delete temporary file from new host"); |
|
| 1019 | + } |
|
| 997 | 1020 | |
| 998 | 1021 | $max_upload = $this->return_bytes((ini_get('upload_max_filesize'))); |
| 999 | 1022 | $max_post = $this->return_bytes((ini_get('post_max_size'))); |
@@ -1037,8 +1060,9 @@ discard block |
||
| 1037 | 1060 | */ |
| 1038 | 1061 | public function is_multipart($backup_name) |
| 1039 | 1062 | { |
| 1040 | - if(stristr($backup_name, "-multipart")) |
|
| 1041 | - return true; |
|
| 1063 | + if(stristr($backup_name, "-multipart")) { |
|
| 1064 | + return true; |
|
| 1065 | + } |
|
| 1042 | 1066 | |
| 1043 | 1067 | return false; |
| 1044 | 1068 | } |
@@ -1056,8 +1080,9 @@ discard block |
||
| 1056 | 1080 | if($this->is_multipart($backup_name)) |
| 1057 | 1081 | { |
| 1058 | 1082 | $backup_parts = $this->get_multipart_files($backup_name); |
| 1059 | - foreach($backup_parts as $part_file) |
|
| 1060 | - $backup_size += $this->filesystem->getSize($part_file); |
|
| 1083 | + foreach($backup_parts as $part_file) { |
|
| 1084 | + $backup_size += $this->filesystem->getSize($part_file); |
|
| 1085 | + } |
|
| 1061 | 1086 | } |
| 1062 | 1087 | |
| 1063 | 1088 | return $backup_size; |
@@ -1115,15 +1140,13 @@ discard block |
||
| 1115 | 1140 | if($direction == 'desc') { |
| 1116 | 1141 | if($a > $b) { |
| 1117 | 1142 | return -1; |
| 1118 | - } |
|
| 1119 | - else{ |
|
| 1143 | + } else{ |
|
| 1120 | 1144 | return 1; |
| 1121 | 1145 | } |
| 1122 | - }else { |
|
| 1146 | + } else { |
|
| 1123 | 1147 | if($a < $b) { |
| 1124 | 1148 | return -1; |
| 1125 | - } |
|
| 1126 | - else{ |
|
| 1149 | + } else{ |
|
| 1127 | 1150 | return 1; |
| 1128 | 1151 | } |
| 1129 | 1152 | } |
@@ -1153,7 +1176,7 @@ discard block |
||
| 1153 | 1176 | { |
| 1154 | 1177 | $return['statusText'] = $response['message']; |
| 1155 | 1178 | $return['error'] = true; |
| 1156 | - }elseif($status != 200 and $status != 418) |
|
| 1179 | + } elseif($status != 200 and $status != 418) |
|
| 1157 | 1180 | { |
| 1158 | 1181 | $return['error'] = true; |
| 1159 | 1182 | $return['message'] = $response; |
@@ -1177,8 +1200,9 @@ discard block |
||
| 1177 | 1200 | return preg_replace_callback('!s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");!', function ($m) { |
| 1178 | 1201 | $data = ""; |
| 1179 | 1202 | |
| 1180 | - if(!isset($m[3])) |
|
| 1181 | - $m[3] = ""; |
|
| 1203 | + if(!isset($m[3])) { |
|
| 1204 | + $m[3] = ""; |
|
| 1205 | + } |
|
| 1182 | 1206 | |
| 1183 | 1207 | $data = 's:'.strlen(($m[3])).':\"'.($m[3]).'\";'; |
| 1184 | 1208 | //return $this->unescape_quotes($data); |
@@ -1224,7 +1248,7 @@ discard block |
||
| 1224 | 1248 | stristr($s, ':' ) !== false |
| 1225 | 1249 | ){ |
| 1226 | 1250 | return true; |
| 1227 | - }else{ |
|
| 1251 | + } else{ |
|
| 1228 | 1252 | return false; |
| 1229 | 1253 | } |
| 1230 | 1254 | |