| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined('ABSPATH') ) |
| 4 |
die(); |
| 5 |
|
| 6 |
$iwp_addon_moredatabase = new IWP_MMB_Addon_MoreDatabase; |
| 7 |
|
| 8 |
class IWP_MMB_Addon_MoreDatabase { |
| 9 |
|
| 10 |
private $database_tables; |
| 11 |
|
| 12 |
/** |
| 13 |
* Class constructor |
| 14 |
*/ |
| 15 |
public function __construct() { |
| 16 |
add_filter('IWP_encrypt_file', array($this, 'encrypt_file'), 10, 5); |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* This function encrypts the database when specified. Used in backup.php. |
| 21 |
* |
| 22 |
* @param array $result |
| 23 |
* @param string $file this is the file name of the db zip to be encrypted |
| 24 |
* @param string $encryption This is the encryption word (salting) to be used when encrypting the data |
| 25 |
* @param string $whichdb This specifies the correct DB |
| 26 |
* @param string $whichdb_suffix This spcifies the DB suffix |
| 27 |
* @return string returns the encrypted file name |
| 28 |
*/ |
| 29 |
public function encrypt_file($result, $file, $encryption, $whichdb, $whichdb_suffix) { |
| 30 |
|
| 31 |
global $iwp_backup_core; |
| 32 |
$iwp_backup_dir = $iwp_backup_core->backups_dir_location(); |
| 33 |
$iwp_backup_core->jobdata_set('jobstatus', 'dbencrypting'.$whichdb_suffix); |
| 34 |
$encryption_result = 0; |
| 35 |
$time_started = microtime(true); |
| 36 |
$file_size = @filesize($iwp_backup_dir.'/'.$file)/1024; |
| 37 |
|
| 38 |
$memory_limit = ini_get('memory_limit'); |
| 39 |
$memory_usage = round(@memory_get_usage(false)/1048576, 1); |
| 40 |
$memory_usage2 = round(@memory_get_usage(true)/1048576, 1); |
| 41 |
$iwp_backup_core->log("Encryption being requested: file_size: ".round($file_size, 1)." KB memory_limit: ".$memory_limit." (used: memory_usage}M | ".$memory_usage2); |
| 42 |
|
| 43 |
$encrypted_file = IWP_MMB_Encryption::encrypt($iwp_backup_dir.'/'.$file, $encryption); |
| 44 |
|
| 45 |
if (false !== $encrypted_file) { |
| 46 |
// return basename($file); |
| 47 |
$time_taken = max(0.000001, microtime(true)-$time_started); |
| 48 |
|
| 49 |
$checksums = $iwp_backup_core->which_checksums(); |
| 50 |
|
| 51 |
foreach ($checksums as $checksum) { |
| 52 |
$cksum = hash_file($checksum, $iwp_backup_dir.'/'.$file.'.crypt'); |
| 53 |
$iwp_backup_core->jobdata_set($checksum.'-db'.(('wp' == $whichdb) ? '0' : $whichdb.'0').'.crypt', $cksum); |
| 54 |
$iwp_backup_core->log("$file: encryption successful: ".round($file_size, 1)."KB in ".round($time_taken, 2)."s (".round($file_size/$time_taken, 1)."KB/s) ($checksum checksum: $cksum)"); |
| 55 |
|
| 56 |
} |
| 57 |
|
| 58 |
// Delete unencrypted file |
| 59 |
@unlink($iwp_backup_dir.'/'.$file); |
| 60 |
|
| 61 |
$iwp_backup_core->jobdata_set('jobstatus', 'dbencrypted'.$whichdb_suffix); |
| 62 |
|
| 63 |
return basename($file.'.crypt'); |
| 64 |
} else { |
| 65 |
$iwp_backup_core->log("Encryption error occurred when encrypting database. Encryption aborted."); |
| 66 |
$iwp_backup_core->log(__("Encryption error occurred when encrypting database. Encryption aborted.", 'InfiniteWP'), 'error'); |
| 67 |
return basename($file); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
} |
| 72 |
|