@@ -162,11 +162,11 @@ |
||
| 162 | 162 | private $logger; |
| 163 | 163 | private $xcloner; |
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * Xcloner_Remote_Storage constructor. |
|
| 167 | - * @param Xcloner $xcloner_container |
|
| 168 | - */ |
|
| 169 | - public function __construct( Xcloner $xcloner_container ) { |
|
| 165 | + /** |
|
| 166 | + * Xcloner_Remote_Storage constructor. |
|
| 167 | + * @param Xcloner $xcloner_container |
|
| 168 | + */ |
|
| 169 | + public function __construct( Xcloner $xcloner_container ) { |
|
| 170 | 170 | $this->xcloner_sanitization = $xcloner_container->get_xcloner_sanitization(); |
| 171 | 171 | $this->xcloner_file_system = $xcloner_container->get_xcloner_filesystem(); |
| 172 | 172 | $this->logger = $xcloner_container->get_xcloner_logger()->withName( "xcloner_remote_storage" ); |
@@ -166,26 +166,26 @@ discard block |
||
| 166 | 166 | * Xcloner_Remote_Storage constructor. |
| 167 | 167 | * @param Xcloner $xcloner_container |
| 168 | 168 | */ |
| 169 | - public function __construct( Xcloner $xcloner_container ) { |
|
| 169 | + public function __construct(Xcloner $xcloner_container) { |
|
| 170 | 170 | $this->xcloner_sanitization = $xcloner_container->get_xcloner_sanitization(); |
| 171 | 171 | $this->xcloner_file_system = $xcloner_container->get_xcloner_filesystem(); |
| 172 | - $this->logger = $xcloner_container->get_xcloner_logger()->withName( "xcloner_remote_storage" ); |
|
| 172 | + $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_remote_storage"); |
|
| 173 | 173 | $this->xcloner = $xcloner_container; |
| 174 | 174 | |
| 175 | - foreach($this->storage_fields as $main_key=>$array){ |
|
| 175 | + foreach ($this->storage_fields as $main_key=>$array) { |
|
| 176 | 176 | |
| 177 | - if(is_array($array)) { |
|
| 177 | + if (is_array($array)) { |
|
| 178 | 178 | foreach ($array as $key => $type) { |
| 179 | 179 | |
| 180 | - if( $type == "raw") { |
|
| 181 | - add_filter("pre_update_option_" . $this->storage_fields['option_prefix'] . $key, |
|
| 182 | - function ($value) { |
|
| 180 | + if ($type == "raw") { |
|
| 181 | + add_filter("pre_update_option_".$this->storage_fields['option_prefix'].$key, |
|
| 182 | + function($value) { |
|
| 183 | 183 | |
| 184 | 184 | return $this->simple_crypt($value, 'e'); |
| 185 | 185 | |
| 186 | 186 | }, 10, 1); |
| 187 | 187 | |
| 188 | - add_filter("option_" . $this->storage_fields['option_prefix'] . $key, function ($value) { |
|
| 188 | + add_filter("option_".$this->storage_fields['option_prefix'].$key, function($value) { |
|
| 189 | 189 | |
| 190 | 190 | return $this->simple_crypt($value, 'd'); |
| 191 | 191 | |
@@ -205,22 +205,22 @@ discard block |
||
| 205 | 205 | * @param string $action |
| 206 | 206 | * @return string |
| 207 | 207 | */ |
| 208 | - private function simple_crypt( $string, $action = 'e' ) { |
|
| 208 | + private function simple_crypt($string, $action = 'e') { |
|
| 209 | 209 | // you may change these values to your own |
| 210 | 210 | $secret_key = NONCE_KEY; |
| 211 | 211 | $secret_iv = NONCE_SALT; |
| 212 | 212 | |
| 213 | 213 | $output = $string; |
| 214 | 214 | $encrypt_method = "AES-256-CBC"; |
| 215 | - $key = hash( 'sha256', $secret_key ); |
|
| 216 | - $iv = substr( hash( 'sha256', $secret_iv ), 0, 16 ); |
|
| 215 | + $key = hash('sha256', $secret_key); |
|
| 216 | + $iv = substr(hash('sha256', $secret_iv), 0, 16); |
|
| 217 | 217 | |
| 218 | - if( $action == 'e' && function_exists('openssl_encrypt')) { |
|
| 219 | - $output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) ); |
|
| 218 | + if ($action == 'e' && function_exists('openssl_encrypt')) { |
|
| 219 | + $output = base64_encode(openssl_encrypt($string, $encrypt_method, $key, 0, $iv)); |
|
| 220 | 220 | } |
| 221 | - else if( $action == 'd' && function_exists('openssl_decrypt') && base64_decode( $string )){ |
|
| 222 | - $decrypt = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv ); |
|
| 223 | - if($decrypt) { |
|
| 221 | + else if ($action == 'd' && function_exists('openssl_decrypt') && base64_decode($string)) { |
|
| 222 | + $decrypt = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv); |
|
| 223 | + if ($decrypt) { |
|
| 224 | 224 | //we check if decrypt was succesful |
| 225 | 225 | $output = $decrypt; |
| 226 | 226 | } |
@@ -235,121 +235,121 @@ discard block |
||
| 235 | 235 | |
| 236 | 236 | public function get_available_storages() { |
| 237 | 237 | $return = array(); |
| 238 | - foreach ( $this->storage_fields as $storage => $data ) { |
|
| 239 | - $check_field = $this->storage_fields["option_prefix"] . $storage . "_enable"; |
|
| 240 | - if ( get_option( $check_field ) ) { |
|
| 241 | - $return[ $storage ] = $data['text']; |
|
| 238 | + foreach ($this->storage_fields as $storage => $data) { |
|
| 239 | + $check_field = $this->storage_fields["option_prefix"].$storage."_enable"; |
|
| 240 | + if (get_option($check_field)) { |
|
| 241 | + $return[$storage] = $data['text']; |
|
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | return $return; |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - public function save( $action = "ftp" ) { |
|
| 249 | - if ( ! $action ) { |
|
| 248 | + public function save($action = "ftp") { |
|
| 249 | + if (!$action) { |
|
| 250 | 250 | return false; |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - $storage = $this->xcloner_sanitization->sanitize_input_as_string( $action ); |
|
| 254 | - $this->logger->debug( sprintf( "Saving the remote storage %s options", strtoupper( $action ) ) ); |
|
| 253 | + $storage = $this->xcloner_sanitization->sanitize_input_as_string($action); |
|
| 254 | + $this->logger->debug(sprintf("Saving the remote storage %s options", strtoupper($action))); |
|
| 255 | 255 | |
| 256 | - if ( is_array( $this->storage_fields[ $storage ] ) ) { |
|
| 257 | - foreach ( $this->storage_fields[ $storage ] as $field => $validation ) { |
|
| 258 | - $check_field = $this->storage_fields["option_prefix"] . $field; |
|
| 259 | - $sanitize_method = "sanitize_input_as_" . $validation; |
|
| 256 | + if (is_array($this->storage_fields[$storage])) { |
|
| 257 | + foreach ($this->storage_fields[$storage] as $field => $validation) { |
|
| 258 | + $check_field = $this->storage_fields["option_prefix"].$field; |
|
| 259 | + $sanitize_method = "sanitize_input_as_".$validation; |
|
| 260 | 260 | |
| 261 | - if ( ! isset( $_POST[ $check_field ] ) ) { |
|
| 262 | - $_POST[ $check_field ] = 0; |
|
| 261 | + if (!isset($_POST[$check_field])) { |
|
| 262 | + $_POST[$check_field] = 0; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - if ( ! method_exists( $this->xcloner_sanitization, $sanitize_method ) ) { |
|
| 265 | + if (!method_exists($this->xcloner_sanitization, $sanitize_method)) { |
|
| 266 | 266 | $sanitize_method = "sanitize_input_as_string"; |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - $sanitized_value = $this->xcloner_sanitization->$sanitize_method( stripslashes( $_POST[ $check_field ] ) ); |
|
| 270 | - update_option( $check_field, $sanitized_value ); |
|
| 269 | + $sanitized_value = $this->xcloner_sanitization->$sanitize_method(stripslashes($_POST[$check_field])); |
|
| 270 | + update_option($check_field, $sanitized_value); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - $this->xcloner->trigger_message( __( "%s storage settings saved.", 'xcloner-backup-and-restore' ), "success", $this->storage_fields[ $action ]['text'] ); |
|
| 273 | + $this->xcloner->trigger_message(__("%s storage settings saved.", 'xcloner-backup-and-restore'), "success", $this->storage_fields[$action]['text']); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - public function check( $action = "ftp" ) { |
|
| 278 | + public function check($action = "ftp") { |
|
| 279 | 279 | try { |
| 280 | - $this->verify_filesystem( $action ); |
|
| 281 | - $this->xcloner->trigger_message( __( "%s connection is valid.", 'xcloner-backup-and-restore' ), "success", $this->storage_fields[ $action ]['text'] ); |
|
| 282 | - $this->logger->debug( sprintf( "Connection to remote storage %s is valid", strtoupper( $action ) ) ); |
|
| 283 | - } catch ( Exception $e ) { |
|
| 284 | - $this->xcloner->trigger_message( "%s connection error: " . $e->getMessage(), "error", $this->storage_fields[ $action ]['text'] ); |
|
| 280 | + $this->verify_filesystem($action); |
|
| 281 | + $this->xcloner->trigger_message(__("%s connection is valid.", 'xcloner-backup-and-restore'), "success", $this->storage_fields[$action]['text']); |
|
| 282 | + $this->logger->debug(sprintf("Connection to remote storage %s is valid", strtoupper($action))); |
|
| 283 | + }catch (Exception $e) { |
|
| 284 | + $this->xcloner->trigger_message("%s connection error: ".$e->getMessage(), "error", $this->storage_fields[$action]['text']); |
|
| 285 | 285 | } |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
| 289 | 289 | * @param string $storage_type |
| 290 | 290 | */ |
| 291 | - public function verify_filesystem( $storage_type ) { |
|
| 292 | - $method = "get_" . $storage_type . "_filesystem"; |
|
| 291 | + public function verify_filesystem($storage_type) { |
|
| 292 | + $method = "get_".$storage_type."_filesystem"; |
|
| 293 | 293 | |
| 294 | - $this->logger->info( sprintf( "Checking validity of the remote storage %s filesystem", strtoupper( $storage_type ) ) ); |
|
| 294 | + $this->logger->info(sprintf("Checking validity of the remote storage %s filesystem", strtoupper($storage_type))); |
|
| 295 | 295 | |
| 296 | - if ( ! method_exists( $this, $method ) ) { |
|
| 296 | + if (!method_exists($this, $method)) { |
|
| 297 | 297 | return false; |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - list( $adapter, $filesystem ) = $this->$method(); |
|
| 300 | + list($adapter, $filesystem) = $this->$method(); |
|
| 301 | 301 | |
| 302 | - $test_file = substr( ".xcloner_" . md5( time() ), 0, 15 ); |
|
| 302 | + $test_file = substr(".xcloner_".md5(time()), 0, 15); |
|
| 303 | 303 | |
| 304 | - if ( $storage_type == "gdrive" ) { |
|
| 305 | - if ( ! is_array( $filesystem->listContents() ) ) { |
|
| 306 | - throw new Exception( __( "Could not read data", 'xcloner-backup-and-restore' ) ); |
|
| 304 | + if ($storage_type == "gdrive") { |
|
| 305 | + if (!is_array($filesystem->listContents())) { |
|
| 306 | + throw new Exception(__("Could not read data", 'xcloner-backup-and-restore')); |
|
| 307 | 307 | } |
| 308 | - $this->logger->debug( sprintf( "I can list data from remote storage %s", strtoupper( $storage_type ) ) ); |
|
| 308 | + $this->logger->debug(sprintf("I can list data from remote storage %s", strtoupper($storage_type))); |
|
| 309 | 309 | |
| 310 | 310 | return true; |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | //testing write access |
| 314 | - if ( ! $filesystem->write( $test_file, "data" ) ) { |
|
| 315 | - throw new Exception( __( "Could not write data", 'xcloner-backup-and-restore' ) ); |
|
| 314 | + if (!$filesystem->write($test_file, "data")) { |
|
| 315 | + throw new Exception(__("Could not write data", 'xcloner-backup-and-restore')); |
|
| 316 | 316 | } |
| 317 | - $this->logger->debug( sprintf( "I can write data to remote storage %s", strtoupper( $storage_type ) ) ); |
|
| 317 | + $this->logger->debug(sprintf("I can write data to remote storage %s", strtoupper($storage_type))); |
|
| 318 | 318 | |
| 319 | 319 | //testing read access |
| 320 | - if ( ! $filesystem->has( $test_file ) ) { |
|
| 321 | - throw new Exception( __( "Could not read data", 'xcloner-backup-and-restore' ) ); |
|
| 320 | + if (!$filesystem->has($test_file)) { |
|
| 321 | + throw new Exception(__("Could not read data", 'xcloner-backup-and-restore')); |
|
| 322 | 322 | } |
| 323 | - $this->logger->debug( sprintf( "I can read data to remote storage %s", strtoupper( $storage_type ) ) ); |
|
| 323 | + $this->logger->debug(sprintf("I can read data to remote storage %s", strtoupper($storage_type))); |
|
| 324 | 324 | |
| 325 | 325 | //delete test file |
| 326 | - if ( ! $filesystem->delete( $test_file ) ) { |
|
| 327 | - throw new Exception( __( "Could not delete data", 'xcloner-backup-and-restore' ) ); |
|
| 326 | + if (!$filesystem->delete($test_file)) { |
|
| 327 | + throw new Exception(__("Could not delete data", 'xcloner-backup-and-restore')); |
|
| 328 | 328 | } |
| 329 | - $this->logger->debug( sprintf( "I can delete data to remote storage %s", strtoupper( $storage_type ) ) ); |
|
| 329 | + $this->logger->debug(sprintf("I can delete data to remote storage %s", strtoupper($storage_type))); |
|
| 330 | 330 | |
| 331 | 331 | return true; |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - public function upload_backup_to_storage( $file, $storage ) { |
|
| 335 | - if ( ! $this->xcloner_file_system->get_storage_filesystem()->has( $file ) ) { |
|
| 336 | - $this->logger->info( sprintf( "File not found %s in local storage", $file ) ); |
|
| 334 | + public function upload_backup_to_storage($file, $storage) { |
|
| 335 | + if (!$this->xcloner_file_system->get_storage_filesystem()->has($file)) { |
|
| 336 | + $this->logger->info(sprintf("File not found %s in local storage", $file)); |
|
| 337 | 337 | |
| 338 | 338 | return false; |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | - $method = "get_" . $storage . "_filesystem"; |
|
| 341 | + $method = "get_".$storage."_filesystem"; |
|
| 342 | 342 | |
| 343 | - if ( ! method_exists( $this, $method ) ) { |
|
| 343 | + if (!method_exists($this, $method)) { |
|
| 344 | 344 | return false; |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | - list( $remote_storage_adapter, $remote_storage_filesystem ) = $this->$method(); |
|
| 347 | + list($remote_storage_adapter, $remote_storage_filesystem) = $this->$method(); |
|
| 348 | 348 | |
| 349 | 349 | //doing remote storage cleaning here |
| 350 | - $this->clean_remote_storage( $storage, $remote_storage_filesystem ); |
|
| 350 | + $this->clean_remote_storage($storage, $remote_storage_filesystem); |
|
| 351 | 351 | |
| 352 | - $this->logger->info( sprintf( "Transferring backup %s to remote storage %s", $file, strtoupper( $storage ) ), array( "" ) ); |
|
| 352 | + $this->logger->info(sprintf("Transferring backup %s to remote storage %s", $file, strtoupper($storage)), array("")); |
|
| 353 | 353 | |
| 354 | 354 | /*if(!$this->xcloner_file_system->get_storage_filesystem()->has($file)) |
| 355 | 355 | { |
@@ -59,24 +59,24 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | protected $filters; |
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @var Xcloner |
|
| 64 | - */ |
|
| 65 | - private $xcloner_plugin; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @var Xcloner |
|
| 69 | - */ |
|
| 70 | - private $xcloner_container; |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Initialize the collections used to maintain the actions and filters. |
|
| 75 | - * |
|
| 76 | - * Xcloner_Loader constructor. |
|
| 77 | - * @param Xcloner $xcloner_container |
|
| 78 | - */ |
|
| 79 | - public function __construct(Xcloner $xcloner_container) |
|
| 62 | + /** |
|
| 63 | + * @var Xcloner |
|
| 64 | + */ |
|
| 65 | + private $xcloner_plugin; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @var Xcloner |
|
| 69 | + */ |
|
| 70 | + private $xcloner_container; |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Initialize the collections used to maintain the actions and filters. |
|
| 75 | + * |
|
| 76 | + * Xcloner_Loader constructor. |
|
| 77 | + * @param Xcloner $xcloner_container |
|
| 78 | + */ |
|
| 79 | + public function __construct(Xcloner $xcloner_container) |
|
| 80 | 80 | { |
| 81 | 81 | |
| 82 | 82 | $this->actions = array(); |
@@ -86,10 +86,10 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Add XCloner to Admin Menu |
|
| 91 | - */ |
|
| 92 | - public function xcloner_backup_add_admin_menu() |
|
| 89 | + /** |
|
| 90 | + * Add XCloner to Admin Menu |
|
| 91 | + */ |
|
| 92 | + public function xcloner_backup_add_admin_menu() |
|
| 93 | 93 | { |
| 94 | 94 | if (function_exists('add_menu_page')) { |
| 95 | 95 | add_menu_page(__('Site Backup', 'xcloner-backup-and-restore'), |
@@ -19,11 +19,11 @@ discard block |
||
| 19 | 19 | private $xcloner_container; |
| 20 | 20 | private $verification = false; |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Xcloner_Encryption constructor. |
|
| 24 | - * @param Xcloner $xcloner_container |
|
| 25 | - */ |
|
| 26 | - public function __construct(Xcloner $xcloner_container) |
|
| 22 | + /** |
|
| 23 | + * Xcloner_Encryption constructor. |
|
| 24 | + * @param Xcloner $xcloner_container |
|
| 25 | + */ |
|
| 26 | + public function __construct(Xcloner $xcloner_container) |
|
| 27 | 27 | { |
| 28 | 28 | $this->xcloner_container = $xcloner_container; |
| 29 | 29 | if (method_exists($xcloner_container, 'get_xcloner_settings')) { |
@@ -63,12 +63,12 @@ discard block |
||
| 63 | 63 | public function is_encrypted_file($filename) { |
| 64 | 64 | $fp = fopen($this->get_xcloner_path().$filename, 'r'); |
| 65 | 65 | if($fp) { |
| 66 | - $encryption_length = fread($fp, 16); |
|
| 67 | - fclose($fp); |
|
| 68 | - if (is_numeric($encryption_length)) { |
|
| 69 | - return true; |
|
| 70 | - } |
|
| 71 | - } |
|
| 66 | + $encryption_length = fread($fp, 16); |
|
| 67 | + fclose($fp); |
|
| 68 | + if (is_numeric($encryption_length)) { |
|
| 69 | + return true; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | 73 | return false; |
| 74 | 74 | |
@@ -372,10 +372,10 @@ discard block |
||
| 372 | 372 | if (isset($argv[1])) { |
| 373 | 373 | |
| 374 | 374 | class Xcloner { |
| 375 | - /** |
|
| 376 | - * Xcloner constructor. |
|
| 377 | - */ |
|
| 378 | - public function __construct() |
|
| 375 | + /** |
|
| 376 | + * Xcloner constructor. |
|
| 377 | + */ |
|
| 378 | + public function __construct() |
|
| 379 | 379 | { |
| 380 | 380 | } |
| 381 | 381 | } |
@@ -62,7 +62,7 @@ |
||
| 62 | 62 | */ |
| 63 | 63 | public function is_encrypted_file($filename) { |
| 64 | 64 | $fp = fopen($this->get_xcloner_path().$filename, 'r'); |
| 65 | - if($fp) { |
|
| 65 | + if ($fp) { |
|
| 66 | 66 | $encryption_length = fread($fp, 16); |
| 67 | 67 | fclose($fp); |
| 68 | 68 | if (is_numeric($encryption_length)) { |
@@ -387,6 +387,6 @@ |
||
| 387 | 387 | $xcloner_encryption->decrypt_file($argv[2], $argv[2].".dec", $argv[4], 0, 0, true); |
| 388 | 388 | } |
| 389 | 389 | } |
| 390 | -}catch (\Exception $e) { |
|
| 390 | +} catch (\Exception $e) { |
|
| 391 | 391 | echo "CAUGHT: ".$e->getMessage(); |
| 392 | 392 | } |