Version Description
- Fiexed not working default setttings on settingspage
- crate .htaccsses on Apache and index.html on other webserver
- fixed global for $wp_version
- set max execution time to 0 for unlimeted job time
- use WP function to display job tables
- Backup file list and zip creation changes
- Added support for Amazon S3
- Only works with PHP 5 now
- Cmplete rewrite of job doing as PHP5 class
- PHP errors now in Backup log
- Log stred in files now again
Download this release
Release Info
Developer | danielhuesken |
Plugin | BackWPup – WordPress Backup Plugin |
Version | 0.8.0 |
Comparing to | |
See all releases |
Code changes from version 0.7.2 to 0.8.0
- app/backwpup_dojob.php +952 -0
- app/dojob/after.php +0 -61
- app/dojob/bevore.php +0 -101
- app/dojob/check.php +0 -37
- app/dojob/db.php +0 -153
- app/dojob/destination-ftp.php +0 -134
- app/dojob/destination-mail.php +0 -43
- app/dojob/file.php +0 -112
- app/dojob/optimize.php +0 -31
- app/functions.php +86 -154
- app/iframe-dojob.php +0 -21
- app/libs/S3.php +1365 -0
- app/options-jobs.php +27 -5
- app/options-logs.php +104 -82
- app/options-runnow-iframe.php +25 -0
- app/options-runnow.php +1 -1
- app/options-save.php +28 -22
- app/options-settings.php +19 -23
- app/options-tools.php +24 -0
- app/options-view_log-iframe.php +8 -0
- app/options-view_log.php +5 -20
- app/options.php +85 -67
- app/tools/db_restore.php +1 -3
- backwpup.php +4 -7
- readme.txt +18 -3
app/backwpup_dojob.php
ADDED
@@ -0,0 +1,952 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// don't load directly
|
3 |
+
if ( !defined('ABSPATH') )
|
4 |
+
die('-1');
|
5 |
+
|
6 |
+
|
7 |
+
//function for PHP error handling
|
8 |
+
function backwpup_joberrorhandler($errno, $errstr, $errfile, $errline) {
|
9 |
+
|
10 |
+
switch ($errno) {
|
11 |
+
case E_NOTICE:
|
12 |
+
case E_USER_NOTICE:
|
13 |
+
$errorstype = "";
|
14 |
+
$style='';
|
15 |
+
break;
|
16 |
+
case E_WARNING:
|
17 |
+
case E_USER_WARNING:
|
18 |
+
case E_CORE_WARNING;
|
19 |
+
case E_COMPILE_WARNING:
|
20 |
+
$errorstype = __("[WARNING]");
|
21 |
+
$logheader=backwpup_read_logheader(BACKWPUP_LOGFILE); //read waring count from log header
|
22 |
+
$warnings=$logheader['warnings']+1;
|
23 |
+
$style=' style="background-color:yellow;"';
|
24 |
+
break;
|
25 |
+
case E_ERROR:
|
26 |
+
case E_USER_ERROR:
|
27 |
+
case E_CORE_ERROR;
|
28 |
+
case E_COMPILE_ERROR;
|
29 |
+
$errorstype = __("[ERROR]");
|
30 |
+
$logheader=backwpup_read_logheader(BACKWPUP_LOGFILE); //read error count from log header
|
31 |
+
$errors=$logheader['errors']+1;
|
32 |
+
$style=' style="background-color:red;"';
|
33 |
+
break;
|
34 |
+
case E_DEPRECATED:
|
35 |
+
case E_USER_DEPRECATED:
|
36 |
+
$errorstype = __("[DEPRECATED]");
|
37 |
+
$style='';
|
38 |
+
break;
|
39 |
+
case E_PARSE:
|
40 |
+
$errorstype = __("[PARSING ERROR]");
|
41 |
+
$style='';
|
42 |
+
break;
|
43 |
+
case E_STRICT:
|
44 |
+
$errorstype = __("[STRICT NOTICE]");
|
45 |
+
$style='';
|
46 |
+
break;
|
47 |
+
case E_RECOVERABLE_ERROR:
|
48 |
+
$errorstype = __("[RECOVERABLE ERROR]");
|
49 |
+
$style='';
|
50 |
+
break;
|
51 |
+
default:
|
52 |
+
$errorstype = "[".$errno."]";
|
53 |
+
$style='';
|
54 |
+
break;
|
55 |
+
}
|
56 |
+
|
57 |
+
$title="[Line: ".$errline."|File: ".basename($errfile)."|Mem: ".backwpup_formatBytes(@memory_get_usage())."|Mem Max: ".backwpup_formatBytes(@memory_get_peak_usage())."|Mem Limit: ".ini_get('memory_limit')."]";
|
58 |
+
|
59 |
+
//wirte log file
|
60 |
+
$fd=@fopen(BACKWPUP_LOGFILE,"a+");
|
61 |
+
@fputs($fd,"<span style=\"background-color:c3c3c3;\" title=\"".$title."\">".date_i18n('Y-m-d H:i.s').":</span> <span".$style.">".$errorstype." ".$errstr."</span><br />\n");
|
62 |
+
@fclose($fd);
|
63 |
+
|
64 |
+
if (!defined('DOING_CRON'))
|
65 |
+
echo "<span style=\"background-color:c3c3c3;\" title=\"".$title."\">".date_i18n('Y-m-d H:i.s').":</span> <span".$style.">".$errorstype." ".$errstr."</span><script type=\"text/javascript\">window.scrollBy(0, 15);</script><br />\n";
|
66 |
+
|
67 |
+
//write new log header
|
68 |
+
if (isset($errors) or isset($warnings)) {
|
69 |
+
$fd=@fopen(BACKWPUP_LOGFILE,"r+");
|
70 |
+
while (!feof($fd)) {
|
71 |
+
$line=@fgets($fd);
|
72 |
+
if (stripos($line,"<meta name=\"backwpup_errors\"") !== false and isset($errors)) {
|
73 |
+
@fseek($fd,$filepos);
|
74 |
+
@fputs($fd,"<meta name=\"backwpup_errors\" content=\"".$errors."\" />".backwpup_fillspases(4-strlen($errors))."\n");
|
75 |
+
break;
|
76 |
+
}
|
77 |
+
if (stripos($line,"<meta name=\"backwpup_warnings\"") !== false and isset($warnings)) {
|
78 |
+
@fseek($fd,$filepos);
|
79 |
+
@fputs($fd,"<meta name=\"backwpup_warnings\" content=\"".$warnings."\" />".backwpup_fillspases(4-strlen($warnings))."\n");
|
80 |
+
break;
|
81 |
+
}
|
82 |
+
$filepos=ftell($fd);
|
83 |
+
}
|
84 |
+
@fclose($fd);
|
85 |
+
}
|
86 |
+
|
87 |
+
@flush();
|
88 |
+
@ob_flush();
|
89 |
+
|
90 |
+
if ($errno==E_ERROR or $errno==E_CORE_ERROR or $errno==E_COMPILE_ERROR) { //Die on fatal php errors.
|
91 |
+
die();
|
92 |
+
}
|
93 |
+
//true for nor more php error hadling.
|
94 |
+
return true;
|
95 |
+
}
|
96 |
+
|
97 |
+
|
98 |
+
|
99 |
+
|
100 |
+
/**
|
101 |
+
* BackWPup PHP class for WordPress
|
102 |
+
*
|
103 |
+
*/
|
104 |
+
class backwpup_dojob {
|
105 |
+
|
106 |
+
private $jobid=0;
|
107 |
+
private $filelist=array();
|
108 |
+
private $allfilesize=0;
|
109 |
+
private $backupfile='';
|
110 |
+
private $backupdir='';
|
111 |
+
private $logdir='';
|
112 |
+
private $logfile='';
|
113 |
+
private $tempdir='';
|
114 |
+
private $cfg=array();
|
115 |
+
private $job=array();
|
116 |
+
|
117 |
+
public function __construct($jobid) {
|
118 |
+
$this->jobid=$jobid; //set job id
|
119 |
+
$this->cfg=get_option('backwpup'); //load config
|
120 |
+
$jobs=get_option('backwpup_jobs'); //load jobdata
|
121 |
+
$jobs[$this->jobid]['starttime']=time(); //set start time for job
|
122 |
+
$jobs[$this->jobid]['stoptime']=''; //Set stop time for job
|
123 |
+
$jobs[$this->jobid]['scheduletime']=wp_next_scheduled('backwpup_cron',array('jobid'=>$this->jobid)); //set Schedule time to next scheduled
|
124 |
+
update_option('backwpup_jobs',$jobs); //Save job Settings
|
125 |
+
$this->job=$jobs[$this->jobid]; //Set job settings
|
126 |
+
//set Temp Dir
|
127 |
+
$this->tempdir=untrailingslashit($this->cfg['dirtemp']);
|
128 |
+
if (empty($this->tempdir))
|
129 |
+
$this->tempdir=get_temp_dir().'backwpup';
|
130 |
+
//set Backup Dir
|
131 |
+
$this->backupdir=untrailingslashit($this->job['backupdir']);
|
132 |
+
if (empty($this->backupdir))
|
133 |
+
$this->backupdir=get_temp_dir().'backwpup';
|
134 |
+
//set Logs Dir
|
135 |
+
$this->logdir=untrailingslashit($this->cfg['dirlogs']);
|
136 |
+
if (empty($this->logdir))
|
137 |
+
$this->logdir=get_temp_dir().'backwpup/logs';
|
138 |
+
//set Backup file name only for jos that makes backups
|
139 |
+
if ($this->job['type']=='FILE' or $this->job['type']=='DB+FILE' or $this->job['type']=='DB')
|
140 |
+
$this->backupfile='backwpup_'.$this->jobid.'_'.date_i18n('Y-m-d_H-i-s').'.zip';
|
141 |
+
//set Log file name
|
142 |
+
$this->logfile='backwpup_log_'.date_i18n('Y-m-d_H-i-s').'.html';
|
143 |
+
define('BACKWPUP_LOGFILE',$this->logdir.'/'.$this->logfile);
|
144 |
+
//Create log file
|
145 |
+
if (!$this->_check_folders($this->logdir))
|
146 |
+
return false;
|
147 |
+
$fd=@fopen(BACKWPUP_LOGFILE,"a+");
|
148 |
+
@fputs($fd,"<html>\n<head>\n");
|
149 |
+
@fputs($fd,"<meta name=\"backwpup_version\" content=\"".BACKWPUP_VERSION."\" />\n");
|
150 |
+
@fputs($fd,"<meta name=\"backwpup_logtime\" content=\"".time()."\" />\n");
|
151 |
+
@fputs($fd,"<meta name=\"backwpup_errors\" content=\"0\" />".backwpup_fillspases(3)."\n");
|
152 |
+
@fputs($fd,"<meta name=\"backwpup_warnings\" content=\"0\" />".backwpup_fillspases(3)."\n");
|
153 |
+
@fputs($fd,"<meta name=\"backwpup_jobid\" content=\"".$this->jobid."\" />\n");
|
154 |
+
@fputs($fd,"<meta name=\"backwpup_jobname\" content=\"".$this->job['name']."\" />\n");
|
155 |
+
@fputs($fd,"<meta name=\"backwpup_jobtype\" content=\"".backwpup_backup_types($this->job['type'],false)."\" />\n");
|
156 |
+
if (!empty($this->backupfile))
|
157 |
+
@fputs($fd,"<meta name=\"backwpup_backupfile\" content=\"".$this->backupdir."/".$this->backupfile."\" />\n");
|
158 |
+
@fputs($fd,"<meta name=\"backwpup_jobruntime\" content=\"0\" />".backwpup_fillspases(9)."\n");
|
159 |
+
@fputs($fd,"<title>".sprintf(__('BackWPup Log for %1$s from %2$s at %3$s','backwpup'),$this->job['name'],date_i18n(get_option('date_format')),date_i18n(get_option('time_format')))."</title>\n</head>\n<body style=\"font-family:monospace;font-size:12px;white-space:nowrap;\">\n");
|
160 |
+
@fclose($fd);
|
161 |
+
//PHP Error handling
|
162 |
+
set_error_handler("backwpup_joberrorhandler"); //set function for PHP error handling
|
163 |
+
//check dirs
|
164 |
+
if (!$this->_check_folders($this->tempdir))
|
165 |
+
return false;
|
166 |
+
if (!$this->_check_folders($this->backupdir))
|
167 |
+
return false;
|
168 |
+
//check max script execution tme
|
169 |
+
if (!ini_get('safe_mode') or strtolower(ini_get('safe_mode'))=='off' or ini_get('safe_mode')=='0') {
|
170 |
+
set_time_limit(0); //300 is most webserver time limit. 0= max time
|
171 |
+
} else {
|
172 |
+
trigger_error(sprintf(__('PHP Safe Mode is on!!! Max exec time is %1$d sec.','backwpup'),ini_get('max_execution_time')),E_USER_WARNING);
|
173 |
+
}
|
174 |
+
// check function for memorylimit
|
175 |
+
if (!function_exists('memory_get_usage')) {
|
176 |
+
if (empty($this->cfg['memorylimit']))
|
177 |
+
$this->cfg['memorylimit']='128M';
|
178 |
+
ini_set('memory_limit', $this->cfg['memorylimit']);
|
179 |
+
trigger_error(sprintf(__('Memory limit set to %1$s ,because can not use PHP: memory_get_usage() function to dynamicli increase the Memeory!','backwpup'),ini_get('memory_limit')),E_USER_WARNING);
|
180 |
+
}
|
181 |
+
//run job parts
|
182 |
+
switch ($this->job['type']) {
|
183 |
+
case 'CHECK':
|
184 |
+
$this->check_db($this->job['dbexclude']);
|
185 |
+
break;
|
186 |
+
case 'OPTIMIZE':
|
187 |
+
$this->optimize_db($this->job['dbexclude']);
|
188 |
+
break;
|
189 |
+
case 'DB':
|
190 |
+
$this->dump_db($this->job['dbexclude']);
|
191 |
+
$this->zip_files();
|
192 |
+
$this->destination_mail();
|
193 |
+
$this->destination_ftp();
|
194 |
+
$this->destination_s3();
|
195 |
+
$this->destination_dir();
|
196 |
+
break;
|
197 |
+
case 'DB+FILE':
|
198 |
+
$this->dump_db($this->job['dbexclude']);
|
199 |
+
$this->file_list();
|
200 |
+
$this->zip_files();
|
201 |
+
$this->destination_mail();
|
202 |
+
$this->destination_ftp();
|
203 |
+
$this->destination_s3();
|
204 |
+
$this->destination_dir();
|
205 |
+
break;
|
206 |
+
case 'FILE':
|
207 |
+
$this->file_list();
|
208 |
+
$this->zip_files();
|
209 |
+
$this->destination_mail();
|
210 |
+
$this->destination_ftp();
|
211 |
+
$this->destination_s3();
|
212 |
+
$this->destination_dir();
|
213 |
+
break;
|
214 |
+
}
|
215 |
+
}
|
216 |
+
|
217 |
+
private function _check_folders($folder) {
|
218 |
+
$folder=str_replace("\\","/",$folder);
|
219 |
+
$folder=untrailingslashit(str_replace("//","/",$folder));
|
220 |
+
if (!is_dir($folder)) { //create dir if not exists
|
221 |
+
if (!mkdir($folder,0777,true)) {
|
222 |
+
trigger_error(sprintf(__('Can not create Folder: %1$s','backwpup'),$folder),E_USER_ERROR);
|
223 |
+
return false;
|
224 |
+
}
|
225 |
+
}
|
226 |
+
if (!is_writeable($folder)) { //test if folder wirteable
|
227 |
+
trigger_error(sprintf(__('Can not write to Folder: %1$s','backwpup'),$folder),E_USER_ERROR);
|
228 |
+
return false;
|
229 |
+
}
|
230 |
+
//create .htaccess for apache and index.html for other
|
231 |
+
if (strtolower(substr($_SERVER["SERVER_SOFTWARE"],0,6))=="apache") { //check if it a apache webserver
|
232 |
+
if (!is_file($folder.'/.htaccess')) {
|
233 |
+
if($file = fopen($folder.'/.htaccess', 'w')) {
|
234 |
+
fwrite($file, "Order allow,deny\ndeny from all");
|
235 |
+
fclose($file);
|
236 |
+
}
|
237 |
+
}
|
238 |
+
} else {
|
239 |
+
if (!is_file($folder.'/index.html')) {
|
240 |
+
if($file = fopen($folder.'/index.html', 'w')) {
|
241 |
+
fwrite($file,"\n");
|
242 |
+
fclose($file);
|
243 |
+
}
|
244 |
+
}
|
245 |
+
}
|
246 |
+
return true;
|
247 |
+
}
|
248 |
+
|
249 |
+
private function need_free_memory($memneed) {
|
250 |
+
//fail back if fuction not exist
|
251 |
+
if (!function_exists('memory_get_usage'))
|
252 |
+
return true;
|
253 |
+
|
254 |
+
//calc mem to bytes
|
255 |
+
if (strtoupper(substr(trim(ini_get('memory_limit')),-1))=='K')
|
256 |
+
$memory=trim(substr(ini_get('memory_limit'),0,-1))*1024;
|
257 |
+
elseif (strtoupper(substr(trim(ini_get('memory_limit')),-1))=='M')
|
258 |
+
$memory=trim(substr(ini_get('memory_limit'),0,-1))*1024*1024;
|
259 |
+
elseif (strtoupper(substr(trim(ini_get('memory_limit')),-1))=='G')
|
260 |
+
$memory=trim(substr(ini_get('memory_limit'),0,-1))*1024*1024*1024;
|
261 |
+
else
|
262 |
+
$memory=trim(ini_get('memory_limit'));
|
263 |
+
|
264 |
+
// increase Memory
|
265 |
+
if (memory_get_usage()+$memneed>$memory) {
|
266 |
+
if (ini_get('safe_mode') or strtolower(ini_get('safe_mode'))=='on' or ini_get('safe_mode')=='1') {
|
267 |
+
trigger_error(sprintf(__('PHP Safe Mode is on!!! Can not increase Memory Limit is %1$s','backwpup'),ini_get('memory_limit')),E_USER_WARNING);
|
268 |
+
return false;
|
269 |
+
}
|
270 |
+
$newmemory=round((memory_get_usage()+$memneed)/1024/1024)+1;
|
271 |
+
if ($oldmem=ini_set('memory_limit', $newmemory.'M'))
|
272 |
+
trigger_error(sprintf(__('Memory increased from %1$s to %2$s','backwpup'),$oldmem,ini_get('memory_limit')),E_USER_NOTICE);
|
273 |
+
else
|
274 |
+
trigger_error(sprintf(__('Can not increase Memory Limit is %1$s','backwpup'),ini_get('memory_limit')),E_USER_WARNING);
|
275 |
+
}
|
276 |
+
return true;
|
277 |
+
}
|
278 |
+
|
279 |
+
private function check_db($exclude_tables) {
|
280 |
+
global $wpdb;
|
281 |
+
|
282 |
+
trigger_error(__('Run Database check...','backwpup'),E_USER_NOTICE);
|
283 |
+
|
284 |
+
$tables=$wpdb->get_col('SHOW TABLES FROM `'.DB_NAME.'`');
|
285 |
+
|
286 |
+
//exclude tables from check
|
287 |
+
if (is_array($exclude_tables)) {
|
288 |
+
foreach($tables as $tablekey => $tablevalue) {
|
289 |
+
if (in_array($tablevalue,$exclude_tables))
|
290 |
+
unset($tables[$tablekey]);
|
291 |
+
}
|
292 |
+
}
|
293 |
+
|
294 |
+
//check tables
|
295 |
+
if (sizeof($tables)>0) {
|
296 |
+
foreach ($tables as $table) {
|
297 |
+
$check=$wpdb->get_row('CHECK TABLE `'.$table.'` MEDIUM', ARRAY_A);
|
298 |
+
if ($check['Msg_type']=='error')
|
299 |
+
trigger_error(sprintf(__('Result of table check for %1$s is: %2$s','backwpup'), $table, $check['Msg_text']),E_USER_ERROR);
|
300 |
+
elseif ($check['Msg_type']=='warning')
|
301 |
+
trigger_error(sprintf(__('Result of table check for %1$s is: %2$s','backwpup'), $table, $check['Msg_text']),E_USER_WARNING);
|
302 |
+
else
|
303 |
+
trigger_error(sprintf(__('Result of table check for %1$s is: %2$s','backwpup'), $table, $check['Msg_text']),E_USER_NOTICE);
|
304 |
+
|
305 |
+
if ($sqlerr=mysql_error($wpdb->dbh)) //aditional SQL error
|
306 |
+
trigger_error(sprintf(__('BackWPup database error %1$s for query %2$s','backwpup'), $sqlerr, $sqlerr->last_query),E_USER_ERROR);
|
307 |
+
//Try to Repair tabele
|
308 |
+
if ($check['Msg_type']=='error' or $check['Msg_type']=='warning') {
|
309 |
+
$repair=$wpdb->get_row('REPAIR TABLE `'.$table.'`', ARRAY_A);
|
310 |
+
if ($repair['Msg_type']=='error')
|
311 |
+
trigger_error(sprintf(__('Result of table repair for %1$s is: %2$s','backwpup'), $table, $repair['Msg_text']),E_USER_ERROR);
|
312 |
+
elseif ($repair['Msg_type']=='warning')
|
313 |
+
trigger_error(sprintf(__('Result of table repair for %1$s is: %2$s','backwpup'), $table, $repair['Msg_text']),E_USER_WARNING);
|
314 |
+
else
|
315 |
+
trigger_error(sprintf(__('Result of table repair for %1$s is: %2$s','backwpup'), $table, $repair['Msg_text']),E_USER_NOTICE);
|
316 |
+
|
317 |
+
if ($sqlerr=mysql_error($wpdb->dbh)) //aditional SQL error
|
318 |
+
trigger_error(sprintf(__('BackWPup database error %1$s for query %2$s','backwpup'), $sqlerr, $sqlerr->last_query),E_USER_ERROR);
|
319 |
+
}
|
320 |
+
}
|
321 |
+
$wpdb->flush();
|
322 |
+
trigger_error(__('Database check done!','backwpup'),E_USER_NOTICE);
|
323 |
+
} else {
|
324 |
+
trigger_error(__('No Tables to check','backwpup'),E_USER_WARNING);
|
325 |
+
}
|
326 |
+
}
|
327 |
+
|
328 |
+
|
329 |
+
private function dump_db_table($table,$status,$file) {
|
330 |
+
global $wpdb;
|
331 |
+
$table = str_replace("�", "��", $table); //esc table name
|
332 |
+
|
333 |
+
// create dump
|
334 |
+
fwrite($file, "\n");
|
335 |
+
fwrite($file, "--\n");
|
336 |
+
fwrite($file, "-- Table structure for table $table\n");
|
337 |
+
fwrite($file, "--\n\n");
|
338 |
+
fwrite($file, "DROP TABLE IF EXISTS `" . $table . "`;\n");
|
339 |
+
fwrite($file, "/*!40101 SET @saved_cs_client = @@character_set_client */;\n");
|
340 |
+
fwrite($file, "/*!40101 SET character_set_client = '".mysql_client_encoding()."' */;\n");
|
341 |
+
//Dump the table structure
|
342 |
+
$result=mysql_query("SHOW CREATE TABLE `".$table."`");
|
343 |
+
if ($sqlerr=mysql_error($wpdb->dbh)) {
|
344 |
+
trigger_error(sprintf(__('BackWPup database error %1$s for query %2$s','backwpup'), $sqlerr, "SHOW CREATE TABLE `".$table."`"),E_USER_ERROR);
|
345 |
+
return false;
|
346 |
+
}
|
347 |
+
$tablestruc=mysql_fetch_assoc($result);
|
348 |
+
fwrite($file, $tablestruc['Create Table'].";\n");
|
349 |
+
fwrite($file, "/*!40101 SET character_set_client = @saved_cs_client */;\n");
|
350 |
+
|
351 |
+
//take data of table
|
352 |
+
$result=mysql_query("SELECT * FROM `".$table."`");
|
353 |
+
if ($sqlerr=mysql_error($wpdb->dbh)) {
|
354 |
+
trigger_error(sprintf(__('BackWPup database error %1$s for query %2$s','backwpup'), $sqlerr, "SELECT * FROM `".$table."`"),E_USER_ERROR);
|
355 |
+
return false;
|
356 |
+
}
|
357 |
+
|
358 |
+
fwrite($file, "--\n");
|
359 |
+
fwrite($file, "-- Dumping data for table $table\n");
|
360 |
+
fwrite($file, "--\n\n");
|
361 |
+
fwrite($file, "LOCK TABLES `".$table."` WRITE;\n\n");
|
362 |
+
if ($status['Engine']=='MyISAM')
|
363 |
+
fwrite($file, "/*!40000 ALTER TABLE `".$table."` DISABLE KEYS */;\n");
|
364 |
+
|
365 |
+
while ($data = mysql_fetch_assoc($result)) {
|
366 |
+
$keys = array();
|
367 |
+
$values = array();
|
368 |
+
foreach($data as $key => $value) {
|
369 |
+
$keys[] = "`".str_replace("�", "��", $key)."`"; // Add key to key list
|
370 |
+
if($value === NULL) // Make Value NULL to string NULL
|
371 |
+
$value = "NULL";
|
372 |
+
elseif($value === "" or $value === false) // if empty or false Value make "" as Value
|
373 |
+
$value = '""';
|
374 |
+
elseif(!is_numeric($value)) //is value not numeric esc
|
375 |
+
$value = "\"".mysql_real_escape_string($value)."\"";
|
376 |
+
|
377 |
+
$values[] = $value;
|
378 |
+
}
|
379 |
+
// make data dump
|
380 |
+
fwrite($file, "INSERT INTO `".$table."` ( ".implode(", ",$keys)." )\n\tVALUES ( ".implode(", ",$values)." );\n");
|
381 |
+
}
|
382 |
+
if ($status['Engine']=='MyISAM')
|
383 |
+
fwrite($file, "/*!40000 ALTER TABLE ".$table." ENABLE KEYS */;\n");
|
384 |
+
fwrite($file, "UNLOCK TABLES;\n");
|
385 |
+
}
|
386 |
+
|
387 |
+
public function dump_db($exclude_tables) {
|
388 |
+
global $wpdb;
|
389 |
+
trigger_error(__('Run Database Dump to file...','backwpup'),E_USER_NOTICE);
|
390 |
+
|
391 |
+
//Tables to backup
|
392 |
+
$tables=$wpdb->get_col('SHOW TABLES FROM `'.DB_NAME.'`');
|
393 |
+
if (is_array($exclude_tables)) {
|
394 |
+
foreach($tables as $tablekey => $tablevalue) {
|
395 |
+
if (in_array($tablevalue,$exclude_tables))
|
396 |
+
unset($tables[$tablekey]);
|
397 |
+
}
|
398 |
+
sort($tables);
|
399 |
+
}
|
400 |
+
|
401 |
+
if (sizeof($tables)>0) {
|
402 |
+
$result=$wpdb->get_results("SHOW TABLE STATUS FROM `".DB_NAME."`;", ARRAY_A); //get table status
|
403 |
+
if ($sqlerr=mysql_error($wpdb->dbh))
|
404 |
+
trigger_error(sprintf(__('BackWPup database error %1$s for query %2$s','backwpup'), $sqlerr, "SHOW TABLE STATUS FROM `".DB_NAME."`;"),E_USER_ERROR);
|
405 |
+
foreach($result as $statusdata) {
|
406 |
+
$status[$statusdata['Name']]=$statusdata;
|
407 |
+
}
|
408 |
+
|
409 |
+
if ($file = @fopen($this->tempdir.'/'.DB_NAME.'.sql', 'w')) {
|
410 |
+
fwrite($file, "-- ---------------------------------------------------------\n");
|
411 |
+
fwrite($file, "-- Dump with BackWPup ver.: ".BACKWPUP_VERSION."\n");
|
412 |
+
fwrite($file, "-- Plugin for WordPress by Daniel Huesken\n");
|
413 |
+
fwrite($file, "-- http://danielhuesken.de/portfolio/backwpup/\n");
|
414 |
+
fwrite($file, "-- Blog Name: ".get_option('blogname')."\n");
|
415 |
+
if (defined('WP_SITEURL'))
|
416 |
+
fwrite($file, "-- Blog URL: ".trailingslashit(WP_SITEURL)."\n");
|
417 |
+
else
|
418 |
+
fwrite($file, "-- Blog URL: ".trailingslashit(get_option('siteurl'))."\n");
|
419 |
+
fwrite($file, "-- Blog ABSPATH: ".trailingslashit(ABSPATH)."\n");
|
420 |
+
fwrite($file, "-- Table Prefix: ".$wpdb->prefix."\n");
|
421 |
+
fwrite($file, "-- Database Name: ".DB_NAME."\n");
|
422 |
+
fwrite($file, "-- Dump on: ".date_i18n('Y-m-d H:i.s')."\n");
|
423 |
+
fwrite($file, "-- ---------------------------------------------------------\n\n");
|
424 |
+
//for better import with mysql client
|
425 |
+
fwrite($file, "/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\n");
|
426 |
+
fwrite($file, "/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\n");
|
427 |
+
fwrite($file, "/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\n");
|
428 |
+
fwrite($file, "/*!40101 SET NAMES '".mysql_client_encoding()."' */;\n");
|
429 |
+
fwrite($file, "/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\n");
|
430 |
+
fwrite($file, "/*!40103 SET TIME_ZONE='".mysql_result(mysql_query("SELECT @@time_zone"),0)."' */;\n");
|
431 |
+
fwrite($file, "/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n");
|
432 |
+
fwrite($file, "/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n");
|
433 |
+
fwrite($file, "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\n");
|
434 |
+
fwrite($file, "/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\n\n");
|
435 |
+
//make table dumps
|
436 |
+
foreach($tables as $table) {
|
437 |
+
trigger_error(__('Dump Database table: ','backwpup').' '.$table,E_USER_NOTICE);
|
438 |
+
$this->need_free_memory(($status[$table]['Data_length']+$status[$table]['Index_length'])*1.3); //get more memory if needed
|
439 |
+
fwrite($file, $this->dump_db_table($table,$status[$table],$file));
|
440 |
+
}
|
441 |
+
//for better import with mysql client
|
442 |
+
fwrite($file, "\n");
|
443 |
+
fwrite($file, "/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;\n");
|
444 |
+
fwrite($file, "/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;\n");
|
445 |
+
fwrite($file, "/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\n");
|
446 |
+
fwrite($file, "/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\n");
|
447 |
+
fwrite($file, "/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\n");
|
448 |
+
fwrite($file, "/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n");
|
449 |
+
fwrite($file, "/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n");
|
450 |
+
fwrite($file, "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n");
|
451 |
+
fclose($file);
|
452 |
+
} else {
|
453 |
+
trigger_error(__('Can not create Database Dump file','backwpup'),E_USER_ERROR);
|
454 |
+
}
|
455 |
+
} else {
|
456 |
+
trigger_error(__('No Tables to Dump','backwpup'),E_USER_WARNING);
|
457 |
+
}
|
458 |
+
|
459 |
+
trigger_error(__('Database Dump done!','backwpup'),E_USER_NOTICE);
|
460 |
+
//add database file to backupfiles
|
461 |
+
trigger_error(__('Add Database Dump to Backup:','backwpup').' '.DB_NAME.'.sql '.backwpup_formatBytes(filesize($this->tempdir.'/'.DB_NAME.'.sql')),E_USER_NOTICE);
|
462 |
+
$this->allfilesize=$this->allfilesize+filesize($this->tempdir.'/'.DB_NAME.'.sql');
|
463 |
+
$this->filelist[]=array(79001=>$this->tempdir.'/'.DB_NAME.'.sql',79003=>DB_NAME.'.sql');
|
464 |
+
|
465 |
+
}
|
466 |
+
|
467 |
+
public function optimize_db($exclude_tables) {
|
468 |
+
global $wpdb;
|
469 |
+
|
470 |
+
trigger_error(__('Run Database optimize...','backwpup'),E_USER_NOTICE);
|
471 |
+
|
472 |
+
$tables=$wpdb->get_col('SHOW TABLES FROM `'.DB_NAME.'`');
|
473 |
+
|
474 |
+
//exclude tables from optimize
|
475 |
+
if (is_array($exclude_tables)) {
|
476 |
+
foreach($tables as $tablekey => $tablevalue) {
|
477 |
+
if (in_array($tablevalue,$exclude_tables))
|
478 |
+
unset($tables[$tablekey]);
|
479 |
+
}
|
480 |
+
}
|
481 |
+
|
482 |
+
if (sizeof($tables)>0) {
|
483 |
+
foreach ($tables as $table) {
|
484 |
+
$optimize=$wpdb->get_row('OPTIMIZE TABLE `'.$table.'`', ARRAY_A);
|
485 |
+
if ($optimize['Msg_type']=='error')
|
486 |
+
trigger_error(sprintf(__('Result of table optimize for %1$s is: %2$s','backwpup'), $table, $optimize['Msg_text']),E_USER_ERROR);
|
487 |
+
elseif ($optimize['Msg_type']=='warning')
|
488 |
+
trigger_error(sprintf(__('Result of table optimize for %1$s is: %2$s','backwpup'), $table, $optimize['Msg_text']),E_USER_WARNING);
|
489 |
+
else
|
490 |
+
trigger_error(sprintf(__('Result of table optimize for %1$s is: %2$s','backwpup'), $table, $optimize['Msg_text']),E_USER_NOTICE);
|
491 |
+
|
492 |
+
if ($sqlerr=mysql_error($wpdb->dbh))
|
493 |
+
trigger_error(sprintf(__('BackWPup database error %1$s for query %2$s','backwpup'), $sqlerr, $sqlerr->last_query),E_USER_ERROR);
|
494 |
+
}
|
495 |
+
$wpdb->flush();
|
496 |
+
trigger_error(__('Database optimize done!','backwpup'),E_USER_NOTICE);
|
497 |
+
} else {
|
498 |
+
trigger_error(__('No Tables to optimize','backwpup'),E_USER_WARNING);
|
499 |
+
}
|
500 |
+
}
|
501 |
+
|
502 |
+
private function _file_list_folder( $folder = '', $levels = 100, $excludes) {
|
503 |
+
if( empty($folder) )
|
504 |
+
return false;
|
505 |
+
if( ! $levels )
|
506 |
+
return false;
|
507 |
+
if ( $dir = @opendir( $folder ) ) {
|
508 |
+
while (($file = readdir( $dir ) ) !== false ) {
|
509 |
+
if ( in_array($file, array('.', '..','.svn') ) )
|
510 |
+
continue;
|
511 |
+
foreach ($excludes as $exclusion) { //exclude dirs and files
|
512 |
+
if (false !== stripos($folder.'/'.$file,str_replace('\\','/',$exclusion)))
|
513 |
+
continue 2;
|
514 |
+
}
|
515 |
+
if (!$this->job['backuproot'] and false !== stripos($folder.'/'.$file,str_replace('\\','/',ABSPATH)) and false === stripos($folder.'/'.$file,str_replace('\\','/',WP_CONTENT_DIR)) and !is_dir($folder.'/'.$file))
|
516 |
+
continue;
|
517 |
+
if (!$this->job['backupcontent'] and false !== stripos($folder.'/'.$file,str_replace('\\','/',WP_CONTENT_DIR)) and false === stripos($folder.'/'.$file,str_replace('\\','/',WP_PLUGIN_DIR)) and !is_dir($folder.'/'.$file))
|
518 |
+
continue;
|
519 |
+
if (!$this->job['backupplugins'] and false !== stripos($folder.'/'.$file,str_replace('\\','/',WP_PLUGIN_DIR)))
|
520 |
+
continue;
|
521 |
+
if ( is_dir( $folder . '/' . $file ) ) {
|
522 |
+
$this->_file_list_folder( $folder . '/' . $file, $levels - 1, $excludes);
|
523 |
+
} elseif (is_file( $folder . '/' . $file )) {
|
524 |
+
if (is_readable($folder . '/' . $file)) {
|
525 |
+
$this->filelist[]=array(79001=>$folder.'/' .$file,79003=>str_replace(str_replace('\\','/',trailingslashit(ABSPATH)),'',$folder.'/') . $file);
|
526 |
+
$this->allfilesize=$this->allfilesize+filesize($folder . '/' . $file);
|
527 |
+
trigger_error(__('Add File to Backup:','backwpup').' '.$folder . '/' . $file.' '.backwpup_formatBytes(filesize($folder . '/' . $file)),E_USER_NOTICE);
|
528 |
+
} else {
|
529 |
+
trigger_error(__('Can not read file:','backwpup').' '.$folder . '/' . $file,E_USER_WARNING);
|
530 |
+
}
|
531 |
+
} else {
|
532 |
+
trigger_error(__('Is not a file or directory:','backwpup').' '.$folder . '/' . $file,E_USER_WARNING);
|
533 |
+
}
|
534 |
+
}
|
535 |
+
@closedir( $dir );
|
536 |
+
}
|
537 |
+
}
|
538 |
+
|
539 |
+
public function file_list() {
|
540 |
+
//Make filelist
|
541 |
+
$backwpup_exclude=array(); $dirinclude=array();
|
542 |
+
|
543 |
+
if (!empty($this->job['fileexclude']))
|
544 |
+
$backwpup_exclude=explode(',',$this->job['fileexclude']);
|
545 |
+
//Exclude Temp dir
|
546 |
+
$backwpup_exclude[]=$this->tempdir;
|
547 |
+
//Exclude Backup dirs
|
548 |
+
$jobs=get_option('backwpup_jobs');
|
549 |
+
foreach($jobs as $jobsvale) {
|
550 |
+
if (!empty($jobsvale['backupdir']))
|
551 |
+
$backwpup_exclude[]=$jobsvale['backupdir'];
|
552 |
+
}
|
553 |
+
$backwpup_exclude=array_unique($backwpup_exclude);
|
554 |
+
|
555 |
+
//include dirs
|
556 |
+
if (!empty($this->job['dirinclude']))
|
557 |
+
$dirinclude=explode(',',str_replace('\\','/',$this->job['dirinclude']));
|
558 |
+
|
559 |
+
if ($this->job['backuproot']) //Include extra path
|
560 |
+
$dirinclude[]=ABSPATH;
|
561 |
+
if ($this->job['backupcontent'] and ((strtolower(str_replace('\\','/',substr(WP_CONTENT_DIR,0,strlen(ABSPATH))))!=strtolower(str_replace('\\','/',ABSPATH)) and $this->job['backuproot']) or !$this->job['backuproot']))
|
562 |
+
$dirinclude[]=WP_CONTENT_DIR;
|
563 |
+
if ($this->job['backupplugins'] and ((strtolower(str_replace('\\','/',substr(WP_PLUGIN_DIR,0,strlen(ABSPATH))))!=strtolower(str_replace('\\','/',ABSPATH)) and $this->job['backuproot']) or !$this->job['backuproot']) and ((strtolower(str_replace('\\','/',substr(WP_PLUGIN_DIR,0,strlen(WP_CONTENT_DIR))))!=strtolower(str_replace('\\','/',WP_CONTENT_DIR)) and $this->job['backupcontent']) or !$this->job['backupcontent']))
|
564 |
+
$dirinclude[]=WP_PLUGIN_DIR;
|
565 |
+
$dirinclude=array_unique($dirinclude);
|
566 |
+
//Crate file list
|
567 |
+
if (is_array($dirinclude)) {
|
568 |
+
foreach($dirinclude as $dirincludevalue) {
|
569 |
+
if (is_dir($dirincludevalue))
|
570 |
+
$this->_file_list_folder(untrailingslashit(str_replace('\\','/',$dirincludevalue)),100,$backwpup_exclude);
|
571 |
+
}
|
572 |
+
}
|
573 |
+
}
|
574 |
+
|
575 |
+
public function zip_files() {
|
576 |
+
|
577 |
+
define( 'PCLZIP_TEMPORARY_DIR', $this->tempdir );
|
578 |
+
|
579 |
+
if (!is_array($this->filelist[0])) {
|
580 |
+
trigger_error(__('No files to Backup','backwpup'),E_USER_ERROR);
|
581 |
+
} else {
|
582 |
+
trigger_error(__('Size off all files:','backwpup').' '.backwpup_formatBytes($this->allfilesize),E_USER_NOTICE);
|
583 |
+
}
|
584 |
+
|
585 |
+
//Create Zip File
|
586 |
+
if (is_array($this->filelist[0])) {
|
587 |
+
$this->need_free_memory(10485760); //10MB free memory for zip
|
588 |
+
trigger_error(__('Create Backup Zip file...','backwpup'),E_USER_NOTICE);
|
589 |
+
if (!class_exists('PclZip')) require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');
|
590 |
+
$zipbackupfile = new PclZip($this->backupdir.'/'.$this->backupfile);
|
591 |
+
if (0==$zipbackupfile -> create($this->filelist,PCLZIP_OPT_ADD_TEMP_FILE_ON)) {
|
592 |
+
trigger_error(__('Zip file create:','backwpup').' '.$zipbackupfile->errorInfo(true),E_USER_ERROR);
|
593 |
+
} else {
|
594 |
+
trigger_error(__('Backup Zip file create done! File size is:','backwpup').' '.backwpup_formatBytes(filesize($this->backupdir.'/'.$this->backupfile)),E_USER_NOTICE);
|
595 |
+
}
|
596 |
+
}
|
597 |
+
|
598 |
+
}
|
599 |
+
|
600 |
+
public function _ftp_raw_helper($ftp_conn_id,$command) { //FTP Comands helper function
|
601 |
+
$return=ftp_raw($ftp_conn_id,$command);
|
602 |
+
if (strtoupper(substr(trim($command),0,4))=="PASS") {
|
603 |
+
trigger_error(__('FTP Client command:','backwpup').' PASS *******',E_USER_NOTICE);
|
604 |
+
} else {
|
605 |
+
trigger_error(__('FTP Client command:','backwpup').' '.$command,E_USER_NOTICE);
|
606 |
+
}
|
607 |
+
foreach ($return as $returnline) {
|
608 |
+
$code=substr(trim($returnline),0,3);
|
609 |
+
if ($code>=100 and $code<200) {
|
610 |
+
trigger_error(__('FTP Server Preliminary reply:','backwpup').' '.$returnline,E_USER_NOTICE);
|
611 |
+
return true;
|
612 |
+
} elseif ($code>=200 and $code<300) {
|
613 |
+
trigger_error(__('FTP Server Completion reply:','backwpup').' '.$returnline,E_USER_NOTICE);
|
614 |
+
return true;
|
615 |
+
} elseif ($code>=300 and $code<400) {
|
616 |
+
trigger_error(__('FTP Server Intermediate reply:','backwpup').' '.$returnline,E_USER_NOTICE);
|
617 |
+
return true;
|
618 |
+
} elseif ($code>=400) {
|
619 |
+
trigger_error(__('FTP Server reply:','backwpup').' '.$returnline,E_USER_ERROR);
|
620 |
+
return false;
|
621 |
+
} else {
|
622 |
+
trigger_error(__('FTP Server reply:','backwpup').' '.$returnline,E_USER_NOTICE);
|
623 |
+
return $return;
|
624 |
+
}
|
625 |
+
}
|
626 |
+
}
|
627 |
+
|
628 |
+
|
629 |
+
public function destination_ftp() {
|
630 |
+
if (empty($this->job['ftphost']) or empty($this->job['ftpuser']) or empty($this->job['ftppass']))
|
631 |
+
return false;
|
632 |
+
|
633 |
+
$ftpport=21;
|
634 |
+
$ftphost=$this->job['ftphost'];
|
635 |
+
if (false !== strpos($this->job['ftphost'],':')) //look for port
|
636 |
+
list($ftphost,$ftpport)=explode(':',$this->job['ftphost'],2);
|
637 |
+
|
638 |
+
if (function_exists('ftp_ssl_connect')) { //make SSL FTP connection
|
639 |
+
$ftp_conn_id = ftp_ssl_connect($ftphost,$ftpport,10);
|
640 |
+
if ($ftp_conn_id) {
|
641 |
+
trigger_error(__('Connected by SSL to FTP server:','backwpup').' '.$this->job['ftphost'],E_USER_NOTICE);
|
642 |
+
}
|
643 |
+
}
|
644 |
+
if (!$ftp_conn_id) { //make normal FTP conection if SSL not work
|
645 |
+
$ftp_conn_id = ftp_connect($ftphost,$ftpport,10);
|
646 |
+
if ($ftp_conn_id) {
|
647 |
+
trigger_error(__('Connected insecure to FTP server:','backwpup').' '.$this->job['ftphost'],E_USER_NOTICE);
|
648 |
+
}
|
649 |
+
}
|
650 |
+
|
651 |
+
if (!$ftp_conn_id) {
|
652 |
+
trigger_error(__('Can not connect to FTP server:','backwpup').' '.$this->job['ftphost'],E_USER_ERROR);
|
653 |
+
return false;
|
654 |
+
}
|
655 |
+
|
656 |
+
//FTP Login
|
657 |
+
$loginok=false;
|
658 |
+
if (@ftp_login($ftp_conn_id, $this->job['ftpuser'], base64_decode($this->job['ftppass']))) {
|
659 |
+
trigger_error(__('FTP Server Completion reply:','backwpup').' 230 User '.$this->job['ftpuser'].' logged in.',E_USER_NOTICE);
|
660 |
+
$loginok=true;
|
661 |
+
} else { //if PHP ftp login don't work use raw login
|
662 |
+
if ($this->_ftp_raw_helper($ftp_conn_id,'USER '.$this->job['ftpuser'])) {
|
663 |
+
if ($this->_ftp_raw_helper($ftp_conn_id,'PASS '.base64_decode($this->job['ftppass']))) {
|
664 |
+
$loginok=true;
|
665 |
+
}
|
666 |
+
}
|
667 |
+
}
|
668 |
+
|
669 |
+
//if (ftp_login($ftp_conn_id, $jobs[$jobid]['ftpuser'], $jobs[$jobid]['ftppass'])) {
|
670 |
+
if (!$loginok)
|
671 |
+
return false;
|
672 |
+
|
673 |
+
//SYSTYPE
|
674 |
+
$this->_ftp_raw_helper($ftp_conn_id,'SYST');
|
675 |
+
//PASV
|
676 |
+
trigger_error(__('FTP Client command:','backwpup').' PASV',E_USER_NOTICE);
|
677 |
+
if (ftp_pasv($ftp_conn_id, true))
|
678 |
+
trigger_error(__('Server Completion reply: 227 Entering Passive Mode','backwpup'),E_USER_NOTICE);
|
679 |
+
else
|
680 |
+
trigger_error(__('FTP Server reply:','backwpup').' '.__('Can not Entering Passive Mode','backwpup'),E_USER_WARNING);
|
681 |
+
//ALLO show no erros in log if do not work
|
682 |
+
trigger_error(__('FTP Client command:','backwpup').' ALLO',E_USER_NOTICE);
|
683 |
+
ftp_alloc($ftp_conn_id,filesize($this->backupdir.'/'.$this->backupfile),$result);
|
684 |
+
trigger_error(__('FTP Server reply:','backwpup').' '.$result,E_USER_NOTICE);
|
685 |
+
|
686 |
+
//test ftp dir and create it f not exists
|
687 |
+
$ftpdirs=explode("/", untrailingslashit($this->job['ftpdir']));
|
688 |
+
foreach ($ftpdirs as $ftpdir) {
|
689 |
+
if (empty($ftpdir))
|
690 |
+
continue;
|
691 |
+
if (!@ftp_chdir($ftp_conn_id, $ftpdir)) {
|
692 |
+
trigger_error('"'.$ftpdir.'" '.__('FTP Dir on Server not exists!','backwpup'),E_USER_WARNING);
|
693 |
+
if (@ftp_mkdir($ftp_conn_id, $ftpdir)) {
|
694 |
+
trigger_error('"'.$ftpdir.'" '.__('FTP Dir created!','backwpup'),E_USER_NOTICE);
|
695 |
+
ftp_chdir($ftp_conn_id, $ftpdir);
|
696 |
+
} else {
|
697 |
+
trigger_error('"'.$ftpdir.'" '.__('FTP Dir on Server can not created!','backwpup'),E_USER_ERROR);
|
698 |
+
}
|
699 |
+
}
|
700 |
+
}
|
701 |
+
|
702 |
+
if (ftp_put($ftp_conn_id, trailingslashit($this->job['ftpdir']).$this->backupfile, $this->backupdir.'/'.$this->backupfile, FTP_BINARY)) //transfere file
|
703 |
+
trigger_error(__('Backup File transferred to FTP Server:','backwpup').' '.trailingslashit($this->job['ftpdir']).$this->backupfile,E_USER_NOTICE);
|
704 |
+
else
|
705 |
+
trigger_error(__('Can not transfer backup to FTP server.','backwpup'),E_USER_ERROR);
|
706 |
+
|
707 |
+
unset($backupfilelist);
|
708 |
+
if ($this->job['ftpmaxbackups']>0) { //Delete old backups
|
709 |
+
if ($filelist=ftp_nlist($ftp_conn_id, trailingslashit($this->job['ftpdir']))) {
|
710 |
+
foreach($filelist as $files) {
|
711 |
+
if ('backwpup_'.$this->jobid.'_' == substr(basename($files),0,strlen('backwpup_'.$this->jobid.'_')) and ".zip" == substr(basename($files),-4))
|
712 |
+
$backupfilelist[]=basename($files);
|
713 |
+
}
|
714 |
+
if (sizeof($backupfilelist)>0) {
|
715 |
+
rsort($backupfilelist);
|
716 |
+
$numdeltefiles=0;
|
717 |
+
for ($i=$this->job['ftpmaxbackups'];$i<sizeof($backupfilelist);$i++) {
|
718 |
+
if (ftp_delete($ftp_conn_id, trailingslashit($this->job['ftpdir']).$backupfilelist[$i])) //delte files on ftp
|
719 |
+
$numdeltefiles++;
|
720 |
+
else
|
721 |
+
trigger_error(__('Can not delete file on FTP Server:','backwpup').' '.trailingslashit($this->job['ftpdir']).$backupfilelist[$i],E_USER_ERROR);
|
722 |
+
}
|
723 |
+
if ($numdeltefiles>0)
|
724 |
+
trigger_error($numdeltefiles.' '.__('files deleted on FTP Server:','backwpup'),E_USER_NOTICE);
|
725 |
+
}
|
726 |
+
}
|
727 |
+
}
|
728 |
+
ftp_close($ftp_conn_id);
|
729 |
+
|
730 |
+
}
|
731 |
+
|
732 |
+
public function destination_mail() {
|
733 |
+
if (empty($this->job['mailaddress']))
|
734 |
+
return false;
|
735 |
+
|
736 |
+
trigger_error(__('Prepare Sending backupfile with mail...','backwpup'),E_USER_NOTICE);
|
737 |
+
|
738 |
+
if (!is_file($this->backupdir.'/'.$this->backupfile)) {
|
739 |
+
trigger_error(__('No file to send!','backwpup'),E_USER_ERROR);
|
740 |
+
return false;
|
741 |
+
}
|
742 |
+
|
743 |
+
//Crate PHP Mailer
|
744 |
+
require_once ABSPATH . WPINC . '/class-phpmailer.php';
|
745 |
+
require_once ABSPATH . WPINC . '/class-smtp.php';
|
746 |
+
$phpmailer = new PHPMailer();
|
747 |
+
//Setting den methode
|
748 |
+
if ($this->cfg['mailmethod']=="SMTP") {
|
749 |
+
$smtpport=25;
|
750 |
+
$smtphost=$this->cfg['mailhost'];
|
751 |
+
if (false !== strpos($this->cfg['mailhost'],':')) //look for port
|
752 |
+
list($smtphost,$smtpport)=explode(':',$this->cfg['mailhost'],2);
|
753 |
+
$phpmailer->Host=$smtphost;
|
754 |
+
$phpmailer->Port=$smtpport;
|
755 |
+
$phpmailer->SMTPSecure=$this->cfg['mailsecure'];
|
756 |
+
$phpmailer->Username=$this->cfg['mailuser'];
|
757 |
+
$phpmailer->Password=base64_decode($this->cfg['mailpass']);
|
758 |
+
if (!empty($this->cfg['mailuser']) and !empty($this->cfg['mailpass']))
|
759 |
+
$phpmailer->SMTPAuth=true;
|
760 |
+
$phpmailer->IsSMTP();
|
761 |
+
trigger_error(__('Send mail with SMTP','backwpup'),E_USER_NOTICE);
|
762 |
+
} elseif ($this->cfg['mailmethod']=="Sendmail") {
|
763 |
+
$phpmailer->Sendmail=$this->cfg['mailsendmail'];
|
764 |
+
$phpmailer->IsSendmail();
|
765 |
+
trigger_error(__('Send mail with Sendmail','backwpup'),E_USER_NOTICE);
|
766 |
+
} else {
|
767 |
+
$phpmailer->IsMail();
|
768 |
+
trigger_error(__('Send mail with PHP mail','backwpup'),E_USER_NOTICE);
|
769 |
+
}
|
770 |
+
|
771 |
+
|
772 |
+
trigger_error(__('Creating mail','backwpup'),E_USER_NOTICE);
|
773 |
+
$phpmailer->From = $this->cfg['mailsndemail'];
|
774 |
+
$phpmailer->FromName = $this->cfg['mailsndname'];
|
775 |
+
$phpmailer->AddAddress($this->job['mailaddress']);
|
776 |
+
$phpmailer->Subject = __('BackWPup File from','backwpup').' '.date_i18n('Y-m-d H:i',$this->job['starttime']).': '.$this->job['name'];
|
777 |
+
$phpmailer->IsHTML(false);
|
778 |
+
$phpmailer->Body = 'Backup File';
|
779 |
+
|
780 |
+
//check file Size
|
781 |
+
if (!empty($this->job['mailefilesize'])) {
|
782 |
+
$maxfilezise=abs($this->job['mailefilesize']*1024*1024);
|
783 |
+
if (filesize($this->backupdir.'/'.$this->backupfile)>$maxfilezise) {
|
784 |
+
trigger_error(__('Backup Archive too big for sending by mail','backwpup'),E_USER_ERROR);
|
785 |
+
return false;
|
786 |
+
}
|
787 |
+
}
|
788 |
+
|
789 |
+
trigger_error(__('Adding Attachment to mail','backwpup'),E_USER_NOTICE);
|
790 |
+
$this->need_free_memory(filesize($this->backupdir.'/'.$this->backupfile)*4);
|
791 |
+
$phpmailer->AddAttachment($this->backupdir.'/'.$this->backupfile);
|
792 |
+
|
793 |
+
trigger_error(__('Send mail....','backwpup'),E_USER_NOTICE);
|
794 |
+
if (!$phpmailer->Send()) {
|
795 |
+
trigger_error(__('Mail send!!!','backwpup'),E_USER_NOTICE);
|
796 |
+
} else {
|
797 |
+
trigger_error(__('Can not send mail:','backwpup').' '.$phpmailer->ErrorInfo,E_USER_ERROR);
|
798 |
+
}
|
799 |
+
|
800 |
+
}
|
801 |
+
|
802 |
+
public function destination_s3() {
|
803 |
+
if (empty($this->job['awsAccessKey']) or empty($this->job['awsSecretKey']) or empty($this->job['awsBucket']))
|
804 |
+
return false;
|
805 |
+
|
806 |
+
if (!(extension_loaded('curl') or @dl(PHP_SHLIB_SUFFIX == 'so' ? 'curl.so' : 'php_curl.dll'))) {
|
807 |
+
trigger_error(__('Can not load curl extension is needed for S3!','backwpup'),E_USER_ERROR);
|
808 |
+
return false;
|
809 |
+
}
|
810 |
+
|
811 |
+
if (!class_exists('S3')) require_once 'libs/S3.php';
|
812 |
+
|
813 |
+
$s3 = new S3($this->job['awsAccessKey'], $this->job['awsSecretKey'], $this->job['awsSSL']);
|
814 |
+
|
815 |
+
if (in_array($this->job['awsBucket'],$s3->listBuckets())) {
|
816 |
+
trigger_error(__('Connected to S3 Bucket:','backwpup').' '.$this->job['awsBucket'],E_USER_NOTICE);
|
817 |
+
//Transfer Backup to S3
|
818 |
+
if ($s3->putObjectFile($this->backupdir.'/'.$this->backupfile, $this->job['awsBucket'], str_replace('//','/',trailingslashit($this->job['awsdir'])).$this->backupfile, S3::ACL_PRIVATE)) //transfere file to S3
|
819 |
+
trigger_error(__('Backup File transferred to S3://','backwpup').$this->job['awsBucket'].'/'.str_replace('//','/',trailingslashit($this->job['awsdir'])).$this->backupfile,E_USER_NOTICE);
|
820 |
+
else
|
821 |
+
trigger_error(__('Can not transfer backup to S3.','backwpup'),E_USER_ERROR);
|
822 |
+
|
823 |
+
unset($backupfilelist);
|
824 |
+
if ($this->job['awsmaxbackups']>0) { //Delete old backups
|
825 |
+
if (($contents = $s3->getBucket($this->job['awsBucket'])) !== false) {
|
826 |
+
foreach ($contents as $object) {
|
827 |
+
if (trailingslashit($this->job['awsdir'])==substr($object['name'],0,strlen(trailingslashit($this->job['awsdir'])))) {
|
828 |
+
$files=basename($object['name']);
|
829 |
+
if ('backwpup_'.$this->jobid.'_' == substr(basename($files),0,strlen('backwpup_'.$this->jobid.'_')) and ".zip" == substr(basename($files),-4))
|
830 |
+
$backupfilelist[]=basename($object['name']);
|
831 |
+
}
|
832 |
+
}
|
833 |
+
}
|
834 |
+
if (sizeof($backupfilelist)>0) {
|
835 |
+
rsort($backupfilelist);
|
836 |
+
$numdeltefiles=0;
|
837 |
+
for ($i=$this->job['awsmaxbackups'];$i<sizeof($backupfilelist);$i++) {
|
838 |
+
if ($s3->deleteObject($this->job['awsBucket'], str_replace('//','/',trailingslashit($this->job['awsdir']).$backupfilelist[$i]))) //delte files on S3
|
839 |
+
$numdeltefiles++;
|
840 |
+
else
|
841 |
+
trigger_error(__('Can not delete file on S3//:','backwpup').$this->job['awsBucket'].'/'.str_replace('//','/',trailingslashit($this->job['awsdir']).$backupfilelist[$i]),E_USER_ERROR);
|
842 |
+
if ($numdeltefiles>0)
|
843 |
+
trigger_error($numdeltefiles.' '.__('files deleted on S3 Bucket!','backwpup'),E_USER_NOTICE);
|
844 |
+
}
|
845 |
+
}
|
846 |
+
}
|
847 |
+
} else {
|
848 |
+
trigger_error(__('S3 Bucket not exists:','backwpup').' '.$this->job['awsBucket'],E_USER_ERROR);
|
849 |
+
}
|
850 |
+
}
|
851 |
+
|
852 |
+
public function destination_dir() {
|
853 |
+
//Delete old Backupfiles
|
854 |
+
if (!empty($this->job['maxbackups']) and !empty($this->job['backupdir']) and is_dir($this->job['backupdir'])) {
|
855 |
+
if ( $dir = @opendir($this->job['backupdir']) ) { //make file list
|
856 |
+
while (($file = readdir($dir)) !== false ) {
|
857 |
+
if ('backwpup_'.$this->jobid.'_' == substr($file,0,strlen('backwpup_'.$this->jobid.'_')) and ".zip" == substr($file,-4))
|
858 |
+
$backupfilelist[]=$file;
|
859 |
+
}
|
860 |
+
@closedir( $dir );
|
861 |
+
}
|
862 |
+
if (sizeof($backupfilelist)>0) {
|
863 |
+
rsort($backupfilelist);
|
864 |
+
$numdeltefiles=0;
|
865 |
+
for ($i=$this->job['maxbackups'];$i<sizeof($backupfilelist);$i++) {
|
866 |
+
unlink(trailingslashit($this->job['backupdir']).$backupfilelist[$i]);
|
867 |
+
$numdeltefiles++;
|
868 |
+
}
|
869 |
+
if ($numdeltefiles>0)
|
870 |
+
trigger_error($numdeltefiles.' '.__('old backup files deleted!!!','backwpup'),E_USER_NOTICE);
|
871 |
+
}
|
872 |
+
}
|
873 |
+
}
|
874 |
+
|
875 |
+
public function __destruct() {
|
876 |
+
if (is_file($this->backupdir.'/'.$this->backupfile)) {
|
877 |
+
trigger_error(sprintf(__('Backup ZIP File size is %1s','backwpup'),backwpup_formatBytes(filesize($this->backupdir.'/'.$this->backupfile))),E_USER_NOTICE);
|
878 |
+
}
|
879 |
+
|
880 |
+
if (is_file($this->tempdir.'/'.DB_NAME.'.sql') ) { //delete sql temp file
|
881 |
+
unlink($this->tempdir.'/'.DB_NAME.'.sql');
|
882 |
+
}
|
883 |
+
|
884 |
+
if (empty($this->job['backupdir']) and ($this->backupdir!=$this->tempdir) and is_file($this->backupdir.'/'.$this->backupfile)) { //delete backup file in temp dir
|
885 |
+
unlink($this->backupdir.'/'.$this->backupfile);
|
886 |
+
}
|
887 |
+
|
888 |
+
//delete old logs
|
889 |
+
if (!empty($this->cfg['maxlogs'])) {
|
890 |
+
if ( $dir = @opendir($this->logdir) ) { //make file list
|
891 |
+
while (($file = readdir($dir)) !== false ) {
|
892 |
+
if ('backwpup_log_' == substr($file,0,strlen('backwpup_log_')) and ".html" == substr($file,-5))
|
893 |
+
$logfilelist[]=$file;
|
894 |
+
}
|
895 |
+
@closedir( $dir );
|
896 |
+
}
|
897 |
+
if (sizeof($logfilelist)>0) {
|
898 |
+
rsort($logfilelist);
|
899 |
+
$numdeltefiles=0;
|
900 |
+
for ($i=$this->cfg['maxlogs'];$i<sizeof($logfilelist);$i++) {
|
901 |
+
unlink(trailingslashit($this->logdir).$logfilelist[$i]);
|
902 |
+
$numdeltefiles++;
|
903 |
+
}
|
904 |
+
if ($numdeltefiles>0)
|
905 |
+
trigger_error($numdeltefiles.' '.__('old Log files deleted!!!','backwpup'),E_USER_NOTICE);
|
906 |
+
}
|
907 |
+
}
|
908 |
+
|
909 |
+
$jobs=get_option('backwpup_jobs');
|
910 |
+
$jobs[$this->jobid]['stoptime']=time();
|
911 |
+
$jobs[$this->jobid]['lastrun']=$jobs[$this->jobid]['starttime'];
|
912 |
+
$jobs[$this->jobid]['lastruntime']=$jobs[$this->jobid]['stoptime']-$jobs[$this->jobid]['starttime'];
|
913 |
+
$jobs[$this->jobid]['scheduletime']=wp_next_scheduled('backwpup_cron',array('jobid'=>$this->jobid));
|
914 |
+
update_option('backwpup_jobs',$jobs); //Save Settings
|
915 |
+
trigger_error(sprintf(__('Job done in %1s sec.','backwpup'),$jobs[$this->jobid]['lastruntime']),E_USER_NOTICE);
|
916 |
+
|
917 |
+
//write runtime header
|
918 |
+
$fd=@fopen(BACKWPUP_LOGFILE,"r+");
|
919 |
+
while (!feof($fd)) {
|
920 |
+
$line=@fgets($fd);
|
921 |
+
if (stripos($line,"<meta name=\"backwpup_jobruntime\"") !== false) {
|
922 |
+
@fseek($fd,$filepos);
|
923 |
+
@fputs($fd,"<meta name=\"backwpup_jobruntime\" content=\"".$jobs[$this->jobid]['lastruntime']."\" />".backwpup_fillspases(10-strlen($jobs[$this->jobid]['lastruntime']))."\n");
|
924 |
+
break;
|
925 |
+
}
|
926 |
+
$filepos=ftell($fd);
|
927 |
+
}
|
928 |
+
@fclose($fd);
|
929 |
+
//logfile end
|
930 |
+
$fd=fopen(BACKWPUP_LOGFILE,"a+");
|
931 |
+
fputs($fd,"</body>\n</html>\n");
|
932 |
+
fclose($fd);
|
933 |
+
restore_error_handler();
|
934 |
+
$logdata=backwpup_read_logheader(BACKWPUP_LOGFILE);
|
935 |
+
//Send mail with log
|
936 |
+
$sendmail=false;
|
937 |
+
if ($logdata['errors']>0 and $this->job['mailerroronly'] and !empty($this->job['mailaddresslog']))
|
938 |
+
$sendmail=true;
|
939 |
+
if (!$this->job['mailerroronly'] and !empty($this->job['mailaddresslog']))
|
940 |
+
$sendmail=true;
|
941 |
+
if ($sendmail) {
|
942 |
+
$mailbody=__("Jobname:","backwpup")." ".$logdata['name']."\n";
|
943 |
+
$mailbody.=__("Jobtype:","backwpup")." ".$logdata['type']."\n";
|
944 |
+
if (!empty($logdata['errors']))
|
945 |
+
$mailbody.=__("Errors:","backwpup")." ".$logdata['errors']."\n";
|
946 |
+
if (!empty($logdata['warnings']))
|
947 |
+
$mailbody.=__("Warnings:","backwpup")." ".$logdata['warnings']."\n";
|
948 |
+
wp_mail($this->job['mailaddresslog'],__('BackWPup Log File from','backwpup').' '.date_i18n('Y-m-d H:i',$this->job['starttime']).': '.$this->job['name'] ,$mailbody,'',array($this->logdir."/".$this->logfile));
|
949 |
+
}
|
950 |
+
}
|
951 |
+
}
|
952 |
+
?>
|
app/dojob/after.php
DELETED
@@ -1,61 +0,0 @@
|
|
1 |
-
<?PHP
|
2 |
-
// don't load directly
|
3 |
-
if ( !defined('ABSPATH') )
|
4 |
-
die('-1');
|
5 |
-
|
6 |
-
//Delete old Backupfiles
|
7 |
-
if (!empty($jobs[$jobid]['maxbackups']) and !empty($jobs[$jobid]['backupdir']) and is_dir($jobs[$jobid]['backupdir'])) {
|
8 |
-
unset($backupfilelist);
|
9 |
-
if ( $dir = @opendir($jobs[$jobid]['backupdir']) ) { //make file list
|
10 |
-
while (($file = readdir($dir)) !== false ) {
|
11 |
-
if ('backwpup_'.$jobid.'_' == substr($file,0,strlen('backwpup_'.$jobid.'_')) and ".zip" == substr($file,-4))
|
12 |
-
$backupfilelist[]=$file;
|
13 |
-
}
|
14 |
-
@closedir( $dir );
|
15 |
-
}
|
16 |
-
if (sizeof($backupfilelist)>0) {
|
17 |
-
rsort($backupfilelist);
|
18 |
-
$numdeltefiles=0;
|
19 |
-
for ($i=$jobs[$jobid]['maxbackups'];$i<sizeof($backupfilelist);$i++) {
|
20 |
-
unlink(trailingslashit($jobs[$jobid]['backupdir']).$backupfilelist[$i]);
|
21 |
-
$numdeltefiles++;
|
22 |
-
}
|
23 |
-
if ($numdeltefiles>0)
|
24 |
-
backwpup_joblog($logtime,$numdeltefiles.' '.__('old backup files deleted!!!','backwpup'));
|
25 |
-
}
|
26 |
-
}
|
27 |
-
//Delete old Logs
|
28 |
-
if (!empty($cfg['maxlogs'])) {
|
29 |
-
$countdellogs=0;
|
30 |
-
$result=mysql_query("SELECT * FROM ".$wpdb->backwpup_logs." ORDER BY logtime DESC LIMIT ".$cfg['maxlogs'].",18446744073709551615");
|
31 |
-
while ($logs = mysql_fetch_assoc($result)) {
|
32 |
-
$wpdb->query("DELETE FROM ".$wpdb->backwpup_logs." WHERE logtime=".$logs['logtime']);
|
33 |
-
$countdellogs++;
|
34 |
-
}
|
35 |
-
if ($countdellogs>0)
|
36 |
-
backwpup_joblog($logtime,$countdellogs.' '.__('old logs deleted!!!','backwpup'));
|
37 |
-
}
|
38 |
-
|
39 |
-
if (is_file($backupfile)) {
|
40 |
-
backwpup_joblog($logtime,sprintf(__('Backup ZIP File size is %1s','backwpup'),backwpup_formatBytes(filesize($backupfile))));
|
41 |
-
}
|
42 |
-
|
43 |
-
if (is_file(get_temp_dir().'backwpup/'.DB_NAME.'.sql') ) { //delete sql temp file
|
44 |
-
unlink(get_temp_dir().'backwpup/'.DB_NAME.'.sql');
|
45 |
-
}
|
46 |
-
|
47 |
-
if (empty($jobs[$jobid]['backupdir']) and (dirname($backupfile)!=get_temp_dir().'backwpup') and is_file($backupfile) ) { //delete backup file in temp dir
|
48 |
-
unlink($backupfile);
|
49 |
-
unset($backupfile);
|
50 |
-
}
|
51 |
-
|
52 |
-
$jobs=get_option('backwpup_jobs');
|
53 |
-
$jobs[$jobid]['stoptime']=time();
|
54 |
-
$jobs[$jobid]['lastrun']=$jobs[$jobid]['starttime'];
|
55 |
-
$jobs[$jobid]['lastruntime']=$jobs[$jobid]['stoptime']-$jobs[$jobid]['starttime'];
|
56 |
-
$jobs[$jobid]['scheduletime']=wp_next_scheduled('backwpup_cron',array('jobid'=>$jobid));
|
57 |
-
update_option('backwpup_jobs',$jobs); //Save Settings
|
58 |
-
backwpup_joblog($logtime,sprintf(__('Job done in %1s sec.','backwpup'),$jobs[$jobid]['lastruntime']));
|
59 |
-
//Write backupfile und worktime to log
|
60 |
-
$wpdb->update( $wpdb->backwpup_logs, array( 'worktime' => $jobs[$jobid]['lastruntime'], 'backupfile' => mysql_real_escape_string($backupfile)), array( 'logtime' => $logtime ));
|
61 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/dojob/bevore.php
DELETED
@@ -1,101 +0,0 @@
|
|
1 |
-
<?PHP
|
2 |
-
// don't load directly
|
3 |
-
if ( !defined('ABSPATH') )
|
4 |
-
die('-1');
|
5 |
-
|
6 |
-
global $logtime;
|
7 |
-
|
8 |
-
define( 'PCLZIP_TEMPORARY_DIR', get_temp_dir().'backwpup/' );
|
9 |
-
$cfg=get_option('backwpup');
|
10 |
-
$jobs=get_option('backwpup_jobs');
|
11 |
-
$logtime=time();
|
12 |
-
$jobs[$jobid]['starttime']=$logtime;
|
13 |
-
$jobs[$jobid]['stoptime']='';
|
14 |
-
$jobs[$jobid]['scheduletime']=wp_next_scheduled('backwpup_cron',array('jobid'=>$jobid));
|
15 |
-
update_option('backwpup_jobs',$jobs); //Save Settings
|
16 |
-
if ($jobs[$jobid]['type']=='FILE' or $jobs[$jobid]['type']=='DB+FILE' or $jobs[$jobid]['type']=='DB') {
|
17 |
-
if (!empty($jobs[$jobid]['backupdir'])) {
|
18 |
-
$backupfile=$jobs[$jobid]['backupdir'].'/backwpup_'.$jobid.'_'.date_i18n('Y-m-d_H-i-s',$jobs[$jobid]['starttime']).'.zip';
|
19 |
-
} else {
|
20 |
-
$backupfile=get_temp_dir().'backwpup/backwpup_'.$jobid.'_'.date_i18n('Y-m-d_H-i-s',$jobs[$jobid]['starttime']).'.zip';
|
21 |
-
}
|
22 |
-
} else {
|
23 |
-
$backupfile='';
|
24 |
-
}
|
25 |
-
|
26 |
-
//Create Log
|
27 |
-
$wpdb->insert( $wpdb->backwpup_logs, array( 'logtime' => $logtime, 'jobid' => $jobid, 'jobname' => $jobs[$jobid]['name'], 'type' => $jobs[$jobid]['type'], 'log' => '' ));
|
28 |
-
|
29 |
-
if (!ini_get('safe_mode') or strtolower(ini_get('safe_mode'))=='off' or ini_get('safe_mode')=='0') {
|
30 |
-
if (empty($cfg['maxexecutiontime']))
|
31 |
-
$cfg['maxexecutiontime']=300;
|
32 |
-
set_time_limit($cfg['maxexecutiontime']); //300 is most webserver time limit.
|
33 |
-
} else {
|
34 |
-
backwpup_joblog($logtime,__('WARNING:','backwpup').' '.sprintf(__('PHP Safe Mode is on!!! Max exec time is %1$s sec.','backwpup'),ini_get('max_execution_time')));
|
35 |
-
}
|
36 |
-
|
37 |
-
if (!function_exists('memory_get_usage')) {
|
38 |
-
if (empty($cfg['memorylimit']))
|
39 |
-
$cfg['memorylimit']='128M';
|
40 |
-
ini_set('memory_limit', $cfg['memorylimit']);
|
41 |
-
backwpup_joblog($logtime,__('WARNING:','backwpup').' '.sprintf(__('Memory limit set to %1$s ,because can not use PHP: memory_get_usage() function.','backwpup'),ini_get('memory_limit')));
|
42 |
-
}
|
43 |
-
|
44 |
-
//Look for and Crate Temp dir and secure
|
45 |
-
backwpup_joblog($logtime,sprintf(__('Temp dir is %1$s.','backwpup'),get_temp_dir().'backwpup'));
|
46 |
-
|
47 |
-
if (!is_dir(get_temp_dir().'backwpup')) {
|
48 |
-
if (!mkdir(get_temp_dir().'backwpup',0777,true)) {
|
49 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.__('Can not create Temp dir','backwpup'));
|
50 |
-
require_once('after.php');
|
51 |
-
return false;
|
52 |
-
}
|
53 |
-
}
|
54 |
-
if (!is_writeable(get_temp_dir().'backwpup')) {
|
55 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.__('Can not write to Temp dir','backwpup'));
|
56 |
-
require_once('after.php');
|
57 |
-
return false;
|
58 |
-
}
|
59 |
-
if (!is_file(get_temp_dir().'backwpup/.htaccess')) {
|
60 |
-
if($file = @fopen(get_temp_dir().'backwpup/.htaccess', 'w')) {
|
61 |
-
fwrite($file, "Order allow,deny\ndeny from all");
|
62 |
-
fclose($file);
|
63 |
-
}
|
64 |
-
}
|
65 |
-
if (!is_file(get_temp_dir().'backwpup/index.html')) {
|
66 |
-
if($file = @fopen(get_temp_dir().'backwpup/index.html', 'w')) {
|
67 |
-
fwrite($file,"\n");
|
68 |
-
fclose($file);
|
69 |
-
}
|
70 |
-
}
|
71 |
-
|
72 |
-
|
73 |
-
if (!empty($backupfile)) {
|
74 |
-
//Look for and Crate Backup dir and secure
|
75 |
-
if (!is_dir($jobs[$jobid]['backupdir'])) {
|
76 |
-
if (!mkdir($jobs[$jobid]['backupdir'],0777,true)) {
|
77 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.__('Can not create Backup dir','backwpup'));
|
78 |
-
require_once('after.php');
|
79 |
-
return false;
|
80 |
-
}
|
81 |
-
}
|
82 |
-
if (!is_writeable($jobs[$jobid]['backupdir'])) {
|
83 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.__('Can not write to Backup dir','backwpup'));
|
84 |
-
require_once('after.php');
|
85 |
-
return false;
|
86 |
-
}
|
87 |
-
if (!is_file($jobs[$jobid]['backupdir'].'/.htaccess')) {
|
88 |
-
if($file = fopen($jobs[$jobid]['backupdir'].'/.htaccess', 'w')) {
|
89 |
-
fwrite($file, "Order allow,deny\ndeny from all");
|
90 |
-
fclose($file);
|
91 |
-
}
|
92 |
-
}
|
93 |
-
if (!is_file($jobs[$jobid]['backupdir'].'/index.html')) {
|
94 |
-
if($file = fopen($jobs[$jobid]['backupdir'].'/index.html', 'w')) {
|
95 |
-
fwrite($file,"\n");
|
96 |
-
fclose($file);
|
97 |
-
}
|
98 |
-
}
|
99 |
-
backwpup_joblog($logtime,__('Backup zip file save to:','backwpup').' '.$backupfile);
|
100 |
-
}
|
101 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/dojob/check.php
DELETED
@@ -1,37 +0,0 @@
|
|
1 |
-
<?PHP
|
2 |
-
// don't load directly
|
3 |
-
if ( !defined('ABSPATH') )
|
4 |
-
die('-1');
|
5 |
-
|
6 |
-
//Optimize SQL Table
|
7 |
-
backwpup_joblog($logtime,__('Run Database check...','backwpup'));
|
8 |
-
$tables=$wpdb->get_col('SHOW TABLES FROM `'.DB_NAME.'`');
|
9 |
-
|
10 |
-
if (is_array($jobs[$jobid]['dbexclude'])) {
|
11 |
-
foreach($tables as $tablekey => $tablevalue) {
|
12 |
-
if (in_array($tablevalue,$jobs[$jobid]['dbexclude']))
|
13 |
-
unset($tables[$tablekey]);
|
14 |
-
}
|
15 |
-
}
|
16 |
-
|
17 |
-
if (sizeof($tables)>0) {
|
18 |
-
foreach ($tables as $table) {
|
19 |
-
if (!in_array($table,(array)$jobs[$jobid]['dbexclude'])) {
|
20 |
-
$check=$wpdb->get_row('CHECK TABLE `'.$table.'` MEDIUM', ARRAY_A);
|
21 |
-
backwpup_joblog($logtime,__(strtoupper($check['Msg_type']).':','backwpup').' '.sprintf(__('Result of table check for %1$s is: %2$s','backwpup'), $table, $check['Msg_text']));
|
22 |
-
if ($sqlerr=mysql_error($wpdb->dbh))
|
23 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.sprintf(__('BackWPup database error %1$s for query %2$s','backwpup'), $sqlerr, $sqlerr->last_query));
|
24 |
-
if ($check['Msg_type']=='error') {
|
25 |
-
$repair=$wpdb->get_row('REPAIR TABLE `'.$table.'`', ARRAY_A);
|
26 |
-
backwpup_joblog($logtime,__(strtoupper($repair['Msg_type']).':','backwpup').' '.sprintf(__('Result of table repair for %1$s is: %2$s ','backwpup'), $table, $repair['Msg_text']));
|
27 |
-
if ($sqlerr=mysql_error($wpdb->dbh))
|
28 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.sprintf(__('BackWPup database error %1$s for query %2$s','backwpup'), $sqlerr, $sqlerr->last_query));
|
29 |
-
}
|
30 |
-
}
|
31 |
-
}
|
32 |
-
$wpdb->flush();
|
33 |
-
backwpup_joblog($logtime,__('Database check done!','backwpup'));
|
34 |
-
} else {
|
35 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.__('No Tables to check','backwpup'));
|
36 |
-
}
|
37 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/dojob/db.php
DELETED
@@ -1,153 +0,0 @@
|
|
1 |
-
<?PHP
|
2 |
-
// don't load directly
|
3 |
-
if ( !defined('ABSPATH') )
|
4 |
-
die('-1');
|
5 |
-
|
6 |
-
backwpup_joblog($logtime,__('Run Database Backup...','backwpup'));
|
7 |
-
|
8 |
-
function backwpup_dump_table($table,$status,$file) {
|
9 |
-
global $wpdb,$logtime;
|
10 |
-
$table = str_replace("�", "��", $table); //esc table name
|
11 |
-
|
12 |
-
// create dump
|
13 |
-
fwrite($file, "\n");
|
14 |
-
fwrite($file, "--\n");
|
15 |
-
fwrite($file, "-- Table structure for table $table\n");
|
16 |
-
fwrite($file, "--\n\n");
|
17 |
-
fwrite($file, "DROP TABLE IF EXISTS `" . $table . "`;\n");
|
18 |
-
fwrite($file, "/*!40101 SET @saved_cs_client = @@character_set_client */;\n");
|
19 |
-
fwrite($file, "/*!40101 SET character_set_client = '".mysql_client_encoding()."' */;\n");
|
20 |
-
//Dump the table structure
|
21 |
-
$result=mysql_query("SHOW CREATE TABLE `".$table."`");
|
22 |
-
if ($sqlerr=mysql_error($wpdb->dbh)) {
|
23 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.sprintf(__('BackWPup database error %1$s for query %2$s','backwpup'), $sqlerr, "SHOW CREATE TABLE `".$table."`"));
|
24 |
-
return false;
|
25 |
-
}
|
26 |
-
$tablestruc=mysql_fetch_assoc($result);
|
27 |
-
fwrite($file, $tablestruc['Create Table'].";\n");
|
28 |
-
fwrite($file, "/*!40101 SET character_set_client = @saved_cs_client */;\n");
|
29 |
-
|
30 |
-
//take data of table
|
31 |
-
$result=mysql_query("SELECT * FROM `".$table."`");
|
32 |
-
if ($sqlerr=mysql_error($wpdb->dbh)) {
|
33 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.sprintf(__('BackWPup database error %1$s for query %2$s','backwpup'), $sqlerr, "SELECT * FROM `".$table."`"));
|
34 |
-
return false;
|
35 |
-
}
|
36 |
-
|
37 |
-
fwrite($file, "--\n");
|
38 |
-
fwrite($file, "-- Dumping data for table $table\n");
|
39 |
-
fwrite($file, "--\n\n");
|
40 |
-
fwrite($file, "LOCK TABLES `".$table."` WRITE;\n\n");
|
41 |
-
if ($status['Engine']=='MyISAM')
|
42 |
-
fwrite($file, "/*!40000 ALTER TABLE `".$table."` DISABLE KEYS */;\n");
|
43 |
-
|
44 |
-
while ($data = mysql_fetch_assoc($result)) {
|
45 |
-
$keys = array();
|
46 |
-
$values = array();
|
47 |
-
foreach($data as $key => $value) {
|
48 |
-
$keys[] = "`".str_replace("�", "��", $key)."`"; // Add key to key list
|
49 |
-
if($value === NULL) // Make Value NULL to string NULL
|
50 |
-
$value = "NULL";
|
51 |
-
elseif($value === "" or $value === false) // if empty or false Value make "" as Value
|
52 |
-
$value = '""';
|
53 |
-
elseif(!is_numeric($value)) //is value not numeric esc
|
54 |
-
$value = "\"".mysql_real_escape_string($value)."\"";
|
55 |
-
|
56 |
-
$values[] = $value;
|
57 |
-
}
|
58 |
-
// make data dump
|
59 |
-
fwrite($file, "INSERT INTO `".$table."` ( ".implode(", ",$keys)." )\n\tVALUES ( ".implode(", ",$values)." );\n");
|
60 |
-
}
|
61 |
-
if ($status['Engine']=='MyISAM')
|
62 |
-
fwrite($file, "/*!40000 ALTER TABLE ".$table." ENABLE KEYS */;\n");
|
63 |
-
fwrite($file, "UNLOCK TABLES;\n");
|
64 |
-
}
|
65 |
-
|
66 |
-
|
67 |
-
//Tables to backup
|
68 |
-
$tables=$wpdb->get_col('SHOW TABLES FROM `'.DB_NAME.'`');
|
69 |
-
$jobs[$jobid]['dbexclude'][]=$wpdb->backwpup_logs; //Exclude log table
|
70 |
-
if (is_array($jobs[$jobid]['dbexclude'])) {
|
71 |
-
foreach($tables as $tablekey => $tablevalue) {
|
72 |
-
if (in_array($tablevalue,$jobs[$jobid]['dbexclude']))
|
73 |
-
unset($tables[$tablekey]);
|
74 |
-
}
|
75 |
-
sort($tables);
|
76 |
-
}
|
77 |
-
|
78 |
-
if (sizeof($tables)>0) {
|
79 |
-
$result=$wpdb->get_results("SHOW TABLE STATUS FROM `".DB_NAME."`;", ARRAY_A); //get table status
|
80 |
-
if ($sqlerr=mysql_error($wpdb->dbh))
|
81 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.sprintf(__('BackWPup database error %1$s for query %2$s','backwpup'), $sqlerr, "SHOW TABLE STATUS FROM `".DB_NAME."`;"));
|
82 |
-
foreach($result as $statusdata) {
|
83 |
-
$status[$statusdata['Name']]=$statusdata;
|
84 |
-
}
|
85 |
-
|
86 |
-
if ($file = @fopen(get_temp_dir().'backwpup/'.DB_NAME.'.sql', 'w')) {
|
87 |
-
fwrite($file, "-- ---------------------------------------------------------\n");
|
88 |
-
fwrite($file, "-- Dump with BackWPup ver.: ".BACKWPUP_VERSION."\n");
|
89 |
-
fwrite($file, "-- Plugin for WordPress by Daniel Huesken\n");
|
90 |
-
fwrite($file, "-- http://danielhuesken.de/portfolio/backwpup/\n");
|
91 |
-
fwrite($file, "-- Blog Name: ".get_option('blogname')."\n");
|
92 |
-
if (defined('WP_SITEURL'))
|
93 |
-
fwrite($file, "-- Blog URL: ".trailingslashit(WP_SITEURL)."\n");
|
94 |
-
else
|
95 |
-
fwrite($file, "-- Blog URL: ".trailingslashit(get_option('siteurl'))."\n");
|
96 |
-
fwrite($file, "-- Blog ABSPATH: ".trailingslashit(ABSPATH)."\n");
|
97 |
-
fwrite($file, "-- Table Prefix: ".$wpdb->prefix."\n");
|
98 |
-
fwrite($file, "-- Database Name: ".DB_NAME."\n");
|
99 |
-
fwrite($file, "-- Dump on: ".date_i18n('Y-m-d H:i.s')."\n");
|
100 |
-
fwrite($file, "-- ---------------------------------------------------------\n\n");
|
101 |
-
//for better import with mysql client
|
102 |
-
fwrite($file, "/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\n");
|
103 |
-
fwrite($file, "/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\n");
|
104 |
-
fwrite($file, "/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\n");
|
105 |
-
fwrite($file, "/*!40101 SET NAMES '".mysql_client_encoding()."' */;\n");
|
106 |
-
fwrite($file, "/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\n");
|
107 |
-
fwrite($file, "/*!40103 SET TIME_ZONE='".mysql_result(mysql_query("SELECT @@time_zone"),0)."' */;\n");
|
108 |
-
fwrite($file, "/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n");
|
109 |
-
fwrite($file, "/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n");
|
110 |
-
fwrite($file, "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\n");
|
111 |
-
fwrite($file, "/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\n\n");
|
112 |
-
//make table dumps
|
113 |
-
foreach($tables as $table) {
|
114 |
-
backwpup_joblog($logtime,__('Database table to Backup: ','backwpup').' '.$table);
|
115 |
-
backwpup_needfreememory(($status[$table]['Data_length']+$status[$table]['Index_length'])*1.3); //get more memory if needed
|
116 |
-
fwrite($file, backwpup_dump_table($table,$status[$table],$file));
|
117 |
-
}
|
118 |
-
//for better import with mysql client
|
119 |
-
fwrite($file, "\n");
|
120 |
-
fwrite($file, "/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;\n");
|
121 |
-
fwrite($file, "/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;\n");
|
122 |
-
fwrite($file, "/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\n");
|
123 |
-
fwrite($file, "/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\n");
|
124 |
-
fwrite($file, "/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\n");
|
125 |
-
fwrite($file, "/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n");
|
126 |
-
fwrite($file, "/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n");
|
127 |
-
fwrite($file, "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n");
|
128 |
-
fclose($file);
|
129 |
-
} else {
|
130 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.__('Can not create Database Backup file','backwpup'));
|
131 |
-
}
|
132 |
-
} else {
|
133 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.__('No Tables to Backup','backwpup'));
|
134 |
-
}
|
135 |
-
|
136 |
-
|
137 |
-
backwpup_joblog($logtime,__('Database backup done!','backwpup'));
|
138 |
-
|
139 |
-
if ($jobs[$jobid]['type']=='DB' and is_file(get_temp_dir().'backwpup/'.DB_NAME.'.sql')) {
|
140 |
-
backwpup_needfreememory(10485760); //10MB free memory for zip
|
141 |
-
backwpup_joblog($logtime,__('Database file size:','backwpup').' '.backwpup_formatBytes(filesize(get_temp_dir().'backwpup/'.DB_NAME.'.sql')));
|
142 |
-
backwpup_joblog($logtime,__('Create Zip file from dump...','backwpup'));
|
143 |
-
$zipbackupfile = new PclZip($backupfile);
|
144 |
-
if (0==$zipbackupfile -> create(get_temp_dir().'backwpup/'.DB_NAME.'.sql',PCLZIP_OPT_REMOVE_ALL_PATH,PCLZIP_OPT_ADD_TEMP_FILE_ON)) {
|
145 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.__('Database Zip file create:','backwpup').' '.$zipbackupfile->errorInfo(true));
|
146 |
-
$joberror=true;
|
147 |
-
}
|
148 |
-
backwpup_joblog($logtime,__('Zip file created...','backwpup'));
|
149 |
-
}
|
150 |
-
//clean vars
|
151 |
-
unset($tables);
|
152 |
-
unset($zipbackupfile);
|
153 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/dojob/destination-ftp.php
DELETED
@@ -1,134 +0,0 @@
|
|
1 |
-
<?PHP
|
2 |
-
// don't load directly
|
3 |
-
if ( !defined('ABSPATH') )
|
4 |
-
die('-1');
|
5 |
-
|
6 |
-
if (!empty($jobs[$jobid]['ftphost']) and !empty($jobs[$jobid]['ftpuser']) and !empty($jobs[$jobid]['ftppass'])) {
|
7 |
-
|
8 |
-
function ftp_raw_helper($ftp_conn_id,$command) { //FTP Comands helper function
|
9 |
-
$return=ftp_raw($ftp_conn_id,$command);
|
10 |
-
if (strtoupper(substr(trim($command),0,4))=="PASS") {
|
11 |
-
backwpup_joblog($logtime,__('FTP Client command:','backwpup').' PASS *******');
|
12 |
-
} else {
|
13 |
-
backwpup_joblog($logtime,__('FTP Client command:','backwpup').' '.$command);
|
14 |
-
}
|
15 |
-
foreach ($return as $returnline) {
|
16 |
-
$code=substr(trim($returnline),0,3);
|
17 |
-
if ($code>=100 and $code<200) {
|
18 |
-
backwpup_joblog($logtime,__('FTP Server Preliminary reply:','backwpup').' '.$returnline);
|
19 |
-
return true;
|
20 |
-
} elseif ($code>=200 and $code<300) {
|
21 |
-
backwpup_joblog($logtime,__('FTP Server Completion reply:','backwpup').' '.$returnline);
|
22 |
-
return true;
|
23 |
-
} elseif ($code>=300 and $code<400) {
|
24 |
-
backwpup_joblog($logtime,__('FTP Server Intermediate reply:','backwpup').' '.$returnline);
|
25 |
-
return true;
|
26 |
-
} elseif ($code>=400) {
|
27 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.__('FTP Server reply:','backwpup').' '.$returnline);
|
28 |
-
return false;
|
29 |
-
} else {
|
30 |
-
backwpup_joblog($logtime,__('FTP Server reply:','backwpup').' '.$returnline);
|
31 |
-
return $return;
|
32 |
-
}
|
33 |
-
}
|
34 |
-
}
|
35 |
-
|
36 |
-
|
37 |
-
$ftpport=21;
|
38 |
-
$ftphost=$jobs[$jobid]['ftphost'];
|
39 |
-
if (false !== strpos($jobs[$jobid]['ftphost'],':')) //look for port
|
40 |
-
list($ftphost,$ftpport)=split(':',$jobs[$jobid]['ftphost'],2);
|
41 |
-
|
42 |
-
if (function_exists('ftp_ssl_connect')) { //make SSL FTP connection
|
43 |
-
$ftp_conn_id = ftp_ssl_connect($ftphost,$ftpport,10);
|
44 |
-
if ($ftp_conn_id) {
|
45 |
-
backwpup_joblog($logtime,__('Connected by SSL to FTP server:','backwpup').' '.$jobs[$jobid]['ftphost']);
|
46 |
-
}
|
47 |
-
}
|
48 |
-
if (!$ftp_conn_id) { //make normal FTP conection if SSL not work
|
49 |
-
$ftp_conn_id = ftp_connect($ftphost,$ftpport,10);
|
50 |
-
if ($ftp_conn_id) {
|
51 |
-
backwpup_joblog($logtime,__('Connected insecure to FTP server:','backwpup').' '.$jobs[$jobid]['ftphost']);
|
52 |
-
}
|
53 |
-
}
|
54 |
-
|
55 |
-
if ($ftp_conn_id) {
|
56 |
-
|
57 |
-
//FTP Login
|
58 |
-
$loginok=false;
|
59 |
-
|
60 |
-
if (@ftp_login($ftp_conn_id, $jobs[$jobid]['ftpuser'], base64_decode($jobs[$jobid]['ftppass']))) {
|
61 |
-
backwpup_joblog($logtime,__('FTP Server Completion reply:','backwpup').' 230 User '.$jobs[$jobid]['ftpuser'].' logged in.');
|
62 |
-
$loginok=true;
|
63 |
-
} else { //if PHP ftp login don't work use raw login
|
64 |
-
if (ftp_raw_helper($ftp_conn_id,'USER '.$jobs[$jobid]['ftpuser'])) {
|
65 |
-
if (ftp_raw_helper($ftp_conn_id,'PASS '.base64_decode($jobs[$jobid]['ftppass']))) {
|
66 |
-
$loginok=true;
|
67 |
-
}
|
68 |
-
}
|
69 |
-
}
|
70 |
-
|
71 |
-
//if (ftp_login($ftp_conn_id, $jobs[$jobid]['ftpuser'], $jobs[$jobid]['ftppass'])) {
|
72 |
-
if ($loginok) {
|
73 |
-
//SYSTYPE
|
74 |
-
ftp_raw_helper($ftp_conn_id,'SYST');
|
75 |
-
//PASV
|
76 |
-
backwpup_joblog($logtime,__('FTP Client command:','backwpup').' PASV');
|
77 |
-
if (ftp_pasv($ftp_conn_id, true))
|
78 |
-
backwpup_joblog($logtime,__('Server Completion reply: 227 Entering Passive Mode','backwpup').' '.$result);
|
79 |
-
else
|
80 |
-
backwpup_joblog($logtime,__('WARNING:','backwpup').' '.__('FTP Server reply:','backwpup').' '.__('Can not Entering Passive Mode','backwpup'));
|
81 |
-
//ALLO show no erros in log if do not work
|
82 |
-
backwpup_joblog($logtime,__('FTP Client command:','backwpup').' ALLO');
|
83 |
-
ftp_alloc($ftp_conn_id,filesize($backupfile),$result);
|
84 |
-
backwpup_joblog($logtime,__('FTP Server reply:','backwpup').' '.$result);
|
85 |
-
|
86 |
-
//test ftp dir and create it f not exists
|
87 |
-
$ftpdirs=split("/", untrailingslashit($jobs[$jobid]['ftpdir']));
|
88 |
-
foreach ($ftpdirs as $ftpdir) {
|
89 |
-
if (empty($ftpdir))
|
90 |
-
continue;
|
91 |
-
if (!@ftp_chdir($ftp_conn_id, $ftpdir)) {
|
92 |
-
backwpup_joblog($logtime,__('WARNING:','backwpup').' "'.$ftpdir.'" '.__('FTP Dir on Server not exists!','backwpup'));
|
93 |
-
if (@ftp_mkdir($ftp_conn_id, $ftpdir)) {
|
94 |
-
backwpup_joblog($logtime,'"'.$ftpdir.'" '.__('FTP Dir created!','backwpup'));
|
95 |
-
ftp_chdir($ftp_conn_id, $ftpdir);
|
96 |
-
} else {
|
97 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' "'.$ftpdir.'" '.__('FTP Dir on Server can not created!','backwpup'));
|
98 |
-
}
|
99 |
-
}
|
100 |
-
}
|
101 |
-
|
102 |
-
if (ftp_put($ftp_conn_id, trailingslashit($jobs[$jobid]['ftpdir']).basename($backupfile), $backupfile, FTP_BINARY)) //transfere file
|
103 |
-
backwpup_joblog($logtime,__('Backup File transferred to FTP Server:','backwpup').' '.trailingslashit($jobs[$jobid]['ftpdir']).basename($backupfile));
|
104 |
-
else
|
105 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.__('Can not transfer backup to FTP server.','backwpup'));
|
106 |
-
|
107 |
-
unset($backupfilelist);
|
108 |
-
if ($jobs[$jobid]['ftpmaxbackups']>0) { //Delete old backups
|
109 |
-
if ($filelist=ftp_nlist($ftp_conn_id, trailingslashit($jobs[$jobid]['ftpdir']))) {
|
110 |
-
foreach($filelist as $files) {
|
111 |
-
if ('backwpup_'.$jobid.'_' == substr(basename($files),0,strlen('backwpup_'.$jobid.'_')) and ".zip" == substr(basename($files),-4))
|
112 |
-
$backupfilelist[]=basename($files);
|
113 |
-
}
|
114 |
-
if (sizeof($backupfilelist)>0) {
|
115 |
-
rsort($backupfilelist);
|
116 |
-
$numdeltefiles=0;
|
117 |
-
for ($i=$jobs[$jobid]['ftpmaxbackups'];$i<sizeof($backupfilelist);$i++) {
|
118 |
-
if (ftp_delete($ftp_conn_id, trailingslashit($jobs[$jobid]['ftpdir']).$backupfilelist[$i])) //delte files on ftp
|
119 |
-
$numdeltefiles++;
|
120 |
-
else
|
121 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.__('Can not delete file on FTP Server:','backwpup').' '.trailingslashit($jobs[$jobid]['ftpdir']).$backupfilelist[$i]);
|
122 |
-
}
|
123 |
-
if ($numdeltefiles>0)
|
124 |
-
backwpup_joblog($logtime,$numdeltefiles.' '.__('files deleted on FTP Server:','backwpup'));
|
125 |
-
}
|
126 |
-
}
|
127 |
-
}
|
128 |
-
}
|
129 |
-
ftp_close($ftp_conn_id);
|
130 |
-
} else {
|
131 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.__('Can not connect to FTP server:','backwpup').' '.$jobs[$jobid]['ftphost']);
|
132 |
-
}
|
133 |
-
}
|
134 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/dojob/destination-mail.php
DELETED
@@ -1,43 +0,0 @@
|
|
1 |
-
<?PHP
|
2 |
-
// don't load directly
|
3 |
-
if ( !defined('ABSPATH') )
|
4 |
-
die('-1');
|
5 |
-
|
6 |
-
$sendmail=false;
|
7 |
-
$errorcount=$wpdb->get_var("SELECT error FROM ".$wpdb->backwpup_logs." WHERE logtime=".$logtime);
|
8 |
-
if ($errorcount>0 and $jobs[$jobid]['mailerroronly'])
|
9 |
-
$sendmail=true;
|
10 |
-
if (!$jobs[$jobid]['mailerroronly'])
|
11 |
-
$sendmail=true;
|
12 |
-
|
13 |
-
if (!empty($jobs[$jobid]['mailaddress']) and $sendmail) {
|
14 |
-
//maillig method
|
15 |
-
add_action('phpmailer_init', 'backwpup_use_mail_method');
|
16 |
-
global $phpmailer;
|
17 |
-
backwpup_joblog($logtime,__('Sending mail...','backwpup'));
|
18 |
-
if (is_file($backupfile) and !empty($jobs[$jobid]['mailefilesize'])) {
|
19 |
-
$maxfilezise=abs($jobs[$jobid]['mailefilesize']*1024*1024);
|
20 |
-
if (filesize($backupfile)<$maxfilezise) {
|
21 |
-
$mailfiles[0]=$backupfile;
|
22 |
-
if (!backwpup_needfreememory(filesize($backupfile)*4)) {
|
23 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.__('Can not increase Memory for sending Backup Archive by Mail','backwpup'));
|
24 |
-
unset($mailfiles);
|
25 |
-
}
|
26 |
-
} else {
|
27 |
-
if (!empty($jobs[$jobid]['backupdir'])) {
|
28 |
-
backwpup_joblog($logtime,__('WARNING:','backwpup').' '.__('Backup Archive too big for sending by mail','backwpup'));
|
29 |
-
} else {
|
30 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.__('Backup Archive too big for sending by mail','backwpup'));
|
31 |
-
}
|
32 |
-
unset($mailfiles);
|
33 |
-
}
|
34 |
-
}
|
35 |
-
if (wp_mail($jobs[$jobid]['mailaddress'],__('BackWPup Job:','backwpup').' '.date_i18n('Y-m-d H:i',$logtime).': '.$jobs[$jobid]['name'] ,$wpdb->get_var("SELECT log FROM ".$wpdb->backwpup_logs." WHERE logtime=".$logtime),'',$mailfiles)) {
|
36 |
-
backwpup_joblog($logtime,__('Mail send!!!','backwpup'));
|
37 |
-
} else {
|
38 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.__('Can not send mail:','backwpup').' '.$phpmailer->ErrorInfo);
|
39 |
-
}
|
40 |
-
}
|
41 |
-
//clean vars
|
42 |
-
unset($mailfiles);
|
43 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/dojob/file.php
DELETED
@@ -1,112 +0,0 @@
|
|
1 |
-
<?PHP
|
2 |
-
// don't load directly
|
3 |
-
if ( !defined('ABSPATH') )
|
4 |
-
die('-1');
|
5 |
-
|
6 |
-
global $backwupu_exclude ,$backwpup_allfilezise, $backwpup_jobs;
|
7 |
-
$backwpup_jobs=$jobs[$jobid];
|
8 |
-
backwpup_joblog($logtime,__('Run file backup...','backwpup'));
|
9 |
-
backwpup_joblog($logtime,__('Get files to backup...','backwpup'));
|
10 |
-
|
11 |
-
// helper function to scan dirs recursive
|
12 |
-
function backwpup_list_files( $folder = '', $levels = 100 ) {
|
13 |
-
global $backwupu_exclude ,$backwpup_allfilezise, $backwpup_jobs, $logtime;
|
14 |
-
if( empty($folder) )
|
15 |
-
return false;
|
16 |
-
if( ! $levels )
|
17 |
-
return false;
|
18 |
-
if ( $dir = @opendir( $folder ) ) {
|
19 |
-
while (($file = readdir( $dir ) ) !== false ) {
|
20 |
-
if ( in_array($file, array('.', '..','.svn') ) )
|
21 |
-
continue;
|
22 |
-
foreach ($backwupu_exclude as $exclusion) { //exclude dirs and files
|
23 |
-
if (false !== stripos($folder.'/'.$file,str_replace('\\','/',$exclusion)))
|
24 |
-
continue 2;
|
25 |
-
}
|
26 |
-
if (!$backwpup_jobs['backuproot'] and false !== stripos($folder.'/'.$file,str_replace('\\','/',ABSPATH)) and false === stripos($folder.'/'.$file,str_replace('\\','/',WP_CONTENT_DIR)) and !is_dir($folder.'/'.$file))
|
27 |
-
continue;
|
28 |
-
if (!$backwpup_jobs['backupcontent'] and false !== stripos($folder.'/'.$file,str_replace('\\','/',WP_CONTENT_DIR)) and false === stripos($folder.'/'.$file,str_replace('\\','/',WP_PLUGIN_DIR)) and !is_dir($folder.'/'.$file))
|
29 |
-
continue;
|
30 |
-
if (!$backwpup_jobs['backupplugins'] and false !== stripos($folder.'/'.$file,str_replace('\\','/',WP_PLUGIN_DIR)))
|
31 |
-
continue;
|
32 |
-
if ( is_dir( $folder . '/' . $file ) ) {
|
33 |
-
$files .= ",".backwpup_list_files( $folder . '/' . $file, $levels - 1);
|
34 |
-
} elseif (is_file( $folder . '/' . $file )) {
|
35 |
-
if (is_readable($folder . '/' . $file)) {
|
36 |
-
$files.=",". $folder . '/' . $file;
|
37 |
-
$filezise=filesize($folder . '/' . $file);
|
38 |
-
$backwpup_allfilezise=$backwpup_allfilezise+$filezise;
|
39 |
-
backwpup_joblog($logtime,__('File to Backup:','backwpup').' '.$folder . '/' . $file.' '.backwpup_formatBytes($filezise));
|
40 |
-
} else {
|
41 |
-
backwpup_joblog($logtime,__('WARNING:','backwpup').' '.__('Can not read file:','backwpup').' '.$folder . '/' . $file);
|
42 |
-
}
|
43 |
-
} else {
|
44 |
-
backwpup_joblog($logtime,__('WARNING:','backwpup').' '.__('Is not a file or directory:','backwpup').' '.$folder . '/' . $file);
|
45 |
-
}
|
46 |
-
}
|
47 |
-
}
|
48 |
-
@closedir( $dir );
|
49 |
-
return str_replace(',,',',',$files);;
|
50 |
-
}
|
51 |
-
|
52 |
-
|
53 |
-
//Make filelist
|
54 |
-
$backwupu_exclude=array(); $dirinclude=array(); $allfilezise=''; $filelist='';
|
55 |
-
|
56 |
-
if (!empty($jobs[$jobid]['fileexclude']))
|
57 |
-
$backwupu_exclude=split(',',$jobs[$jobid]['fileexclude']);
|
58 |
-
//Exclude Temp dir
|
59 |
-
$backwupu_exclude[]=get_temp_dir().'backwpup';
|
60 |
-
//Exclude Backup dirs
|
61 |
-
foreach($jobs as $jobsvale) {
|
62 |
-
$backwupu_exclude[]=$jobsvale['backupdir'];
|
63 |
-
}
|
64 |
-
$backwupu_exclude=array_unique($backwupu_exclude);
|
65 |
-
|
66 |
-
//include dirs
|
67 |
-
if (!empty($jobs[$jobid]['dirinclude']))
|
68 |
-
$dirinclude=split(',',str_replace('\\','/',$jobs[$jobid]['dirinclude']));
|
69 |
-
|
70 |
-
if ($jobs[$jobid]['backuproot']) //Include extra path
|
71 |
-
$dirinclude[]=ABSPATH;
|
72 |
-
if ($jobs[$jobid]['backupcontent'] and ((strtolower(str_replace('\\','/',substr(WP_CONTENT_DIR,0,strlen(ABSPATH))))!=strtolower(str_replace('\\','/',ABSPATH)) and $jobs[$jobid]['backuproot']) or !$jobs[$jobid]['backuproot']))
|
73 |
-
$dirinclude[]=WP_CONTENT_DIR;
|
74 |
-
if ($jobs[$jobid]['backupplugins'] and ((strtolower(str_replace('\\','/',substr(WP_PLUGIN_DIR,0,strlen(ABSPATH))))!=strtolower(str_replace('\\','/',ABSPATH)) and $jobs[$jobid]['backuproot']) or !$jobs[$jobid]['backuproot']) and ((strtolower(str_replace('\\','/',substr(WP_PLUGIN_DIR,0,strlen(WP_CONTENT_DIR))))!=strtolower(str_replace('\\','/',WP_CONTENT_DIR)) and $jobs[$jobid]['backupcontent']) or !$jobs[$jobid]['backupcontent']))
|
75 |
-
$dirinclude[]=WP_PLUGIN_DIR;
|
76 |
-
$dirinclude=array_unique($dirinclude);
|
77 |
-
//Crate file list
|
78 |
-
if (is_array($dirinclude)) {
|
79 |
-
foreach($dirinclude as $dirincludevalue) {
|
80 |
-
if (is_dir($dirincludevalue))
|
81 |
-
$filelist .=",".backwpup_list_files(untrailingslashit(str_replace('\\','/',$dirincludevalue)));
|
82 |
-
}
|
83 |
-
}
|
84 |
-
|
85 |
-
if (empty($filelist)) {
|
86 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.__('No files to Backup','backwpup'));
|
87 |
-
unset($filelist); //clean vars
|
88 |
-
} else {
|
89 |
-
backwpup_joblog($logtime,__('Size off all files:','backwpup').' '.backwpup_formatBytes($backwpup_allfilezise));
|
90 |
-
}
|
91 |
-
|
92 |
-
//Create Zip File
|
93 |
-
if (!empty($filelist)) {
|
94 |
-
backwpup_needfreememory(10485760); //10MB free memory for zip
|
95 |
-
backwpup_joblog($logtime,__('Create Backup Zip file...','backwpup'));
|
96 |
-
$zipbackupfile = new PclZip($backupfile);
|
97 |
-
if (0==$zipbackupfile -> create($filelist,PCLZIP_OPT_REMOVE_PATH,str_replace('\\','/',ABSPATH),PCLZIP_OPT_ADD_TEMP_FILE_ON)) {
|
98 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.__('Zip file create:','backwpup').' '.$zipbackupfile->errorInfo(true));
|
99 |
-
}
|
100 |
-
unset($filelist);
|
101 |
-
if ($jobs[$jobid]['type']=='DB+FILE') {
|
102 |
-
backwpup_joblog($logtime,__('Database file size:','backwpup').' '.backwpup_formatBytes(filesize(get_temp_dir().'backwpup/'.DB_NAME.'.sql')));
|
103 |
-
backwpup_joblog($logtime,__('Add Database dump to Backup Zip file...','backwpup'));
|
104 |
-
if (0==$zipbackupfile -> add(get_temp_dir().'backwpup/'.DB_NAME.'.sql',PCLZIP_OPT_REMOVE_ALL_PATH,PCLZIP_OPT_ADD_TEMP_FILE_ON)) {
|
105 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.__('Zip file create Add Database dump:','backwpup').' '.$zipbackupfile->errorInfo(true));
|
106 |
-
}
|
107 |
-
}
|
108 |
-
unset($zipbackupfile);
|
109 |
-
backwpup_joblog($logtime,__('Backup Zip file create done!','backwpup'));
|
110 |
-
}
|
111 |
-
|
112 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/dojob/optimize.php
DELETED
@@ -1,31 +0,0 @@
|
|
1 |
-
<?PHP
|
2 |
-
// don't load directly
|
3 |
-
if ( !defined('ABSPATH') )
|
4 |
-
die('-1');
|
5 |
-
|
6 |
-
//Optimize SQL Table
|
7 |
-
backwpup_joblog($logtime,__('Run Database optimize...','backwpup'));
|
8 |
-
$tables=$wpdb->get_col('SHOW TABLES FROM `'.DB_NAME.'`');
|
9 |
-
|
10 |
-
if (is_array($jobs[$jobid]['dbexclude'])) {
|
11 |
-
foreach($tables as $tablekey => $tablevalue) {
|
12 |
-
if (in_array($tablevalue,$jobs[$jobid]['dbexclude']))
|
13 |
-
unset($tables[$tablekey]);
|
14 |
-
}
|
15 |
-
}
|
16 |
-
|
17 |
-
if (sizeof($tables)>0) {
|
18 |
-
foreach ($tables as $table) {
|
19 |
-
if (!in_array($table,(array)$jobs[$jobid]['dbexclude'])) {
|
20 |
-
$optimize=$wpdb->get_row('OPTIMIZE TABLE `'.$table.'`', ARRAY_A);
|
21 |
-
backwpup_joblog($logtime,__(strtoupper($optimize['Msg_type']).':','backwpup').' '.sprintf(__('Result of table optimize for %1$s is: %2$s','backwpup'), $table, $optimize['Msg_text']));
|
22 |
-
if ($sqlerr=mysql_error($wpdb->dbh))
|
23 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.sprintf(__('BackWPup database error %1$s for query %2$s','backwpup'), $sqlerr, $sqlerr->last_query));
|
24 |
-
}
|
25 |
-
}
|
26 |
-
$wpdb->flush();
|
27 |
-
backwpup_joblog($logtime,__('Database optimize done!','backwpup'));
|
28 |
-
} else {
|
29 |
-
backwpup_joblog($logtime,__('ERROR:','backwpup').' '.__('No Tables to optimize','backwpup'));
|
30 |
-
}
|
31 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/functions.php
CHANGED
@@ -8,6 +8,8 @@ if ( !defined('ABSPATH') )
|
|
8 |
$hook = add_management_page(__('BackWPup','backwpup'), __('BackWPup','backwpup'), '10', 'BackWPup','backwpup_options_page') ;
|
9 |
add_action('load-'.$hook, 'backwpup_options_load');
|
10 |
add_contextual_help($hook,backwpup_show_help());
|
|
|
|
|
11 |
}
|
12 |
|
13 |
// Help too display
|
@@ -41,6 +43,7 @@ if ( !defined('ABSPATH') )
|
|
41 |
require_once(WP_PLUGIN_DIR.'/'.BACKWPUP_PLUGIN_DIR.'/app/options-jobs.php');
|
42 |
break;
|
43 |
case 'logs':
|
|
|
44 |
require_once(WP_PLUGIN_DIR.'/'.BACKWPUP_PLUGIN_DIR.'/app/options-logs.php');
|
45 |
break;
|
46 |
case 'settings':
|
@@ -57,8 +60,7 @@ if ( !defined('ABSPATH') )
|
|
57 |
require_once(WP_PLUGIN_DIR.'/'.BACKWPUP_PLUGIN_DIR.'/app/options-runnow.php');
|
58 |
break;
|
59 |
case 'view_log':
|
60 |
-
|
61 |
-
check_admin_referer('view-log');
|
62 |
require_once(WP_PLUGIN_DIR.'/'.BACKWPUP_PLUGIN_DIR.'/app/options-view_log.php');
|
63 |
break;
|
64 |
default:
|
@@ -82,43 +84,16 @@ if ( !defined('ABSPATH') )
|
|
82 |
|
83 |
//delete Otions
|
84 |
function backwpup_plugin_uninstall() {
|
85 |
-
global $wpdb;
|
86 |
delete_option('backwpup');
|
87 |
delete_option('backwpup_jobs');
|
88 |
-
$wpdb->query("DROP TABLE IF EXISTS ".$wpdb->backwpup_logs);
|
89 |
}
|
90 |
|
91 |
//On Plugin activate
|
92 |
function backwpup_plugin_activate() {
|
|
|
93 |
global $wpdb;
|
94 |
-
|
95 |
-
|
96 |
-
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
97 |
-
$charset_collate = '';
|
98 |
-
if($wpdb->supports_collation()) {
|
99 |
-
if(!empty($wpdb->charset)) {
|
100 |
-
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
101 |
-
}
|
102 |
-
if(!empty($wpdb->collate)) {
|
103 |
-
$charset_collate .= " COLLATE $wpdb->collate";
|
104 |
-
}
|
105 |
-
}
|
106 |
-
$statements = array(
|
107 |
-
"CREATE TABLE ".$wpdb->backwpup_logs." (
|
108 |
-
logtime BIGINT NOT NULL,
|
109 |
-
jobid INT NOT NULL,
|
110 |
-
jobname VARCHAR(255) NOT NULL,
|
111 |
-
type VARCHAR(20) NOT NULL,
|
112 |
-
error TINYINT NOT NULL default '0',
|
113 |
-
warning TINYINT NOT NULL default '0',
|
114 |
-
worktime TINYINT NOT NULL default '0',
|
115 |
-
log LONGTEXT NOT NULL default '',
|
116 |
-
backupfile VARCHAR(255),
|
117 |
-
PRIMARY KEY (logtime)
|
118 |
-
)".$charset_collate,
|
119 |
-
);
|
120 |
-
$sql = implode(';', $statements);
|
121 |
-
dbDelta($sql);
|
122 |
//add cron jobs
|
123 |
$jobs=get_option('backwpup_jobs');
|
124 |
if (is_array($jobs)) {
|
@@ -128,7 +103,17 @@ if ( !defined('ABSPATH') )
|
|
128 |
}
|
129 |
}
|
130 |
}
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
}
|
133 |
|
134 |
//on Plugin deaktivate
|
@@ -175,98 +160,19 @@ if ( !defined('ABSPATH') )
|
|
175 |
return $schedules;
|
176 |
}
|
177 |
|
178 |
-
|
179 |
//DoJob
|
180 |
function backwpup_dojob($args) {
|
181 |
-
|
182 |
-
|
183 |
-
if (is_array($args)) { //cron gifes no complete arry back!!!
|
184 |
extract($args, EXTR_SKIP );
|
185 |
} else {
|
186 |
$jobid=$args;
|
187 |
}
|
188 |
if (empty($jobid)) return false;
|
189 |
require_once(ABSPATH . 'wp-admin/includes/file.php'); //for get_tempdir();
|
190 |
-
require_once('
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
require_once('dojob/db.php');
|
195 |
-
require_once('dojob/file.php');
|
196 |
-
require_once('dojob/destination-ftp.php');
|
197 |
-
break;
|
198 |
-
case 'DB':
|
199 |
-
require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');
|
200 |
-
require_once('dojob/db.php');
|
201 |
-
require_once('dojob/destination-ftp.php');
|
202 |
-
break;
|
203 |
-
case 'FILE':
|
204 |
-
require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');
|
205 |
-
require_once('dojob/file.php');
|
206 |
-
require_once('dojob/destination-ftp.php');
|
207 |
-
break;
|
208 |
-
case 'OPTIMIZE':
|
209 |
-
require_once('dojob/optimize.php');
|
210 |
-
break;
|
211 |
-
case 'CHECK':
|
212 |
-
require_once('dojob/check.php');
|
213 |
-
break;
|
214 |
-
}
|
215 |
-
require_once('dojob/destination-mail.php');
|
216 |
-
require_once('dojob/after.php');
|
217 |
-
|
218 |
-
return $logtime;
|
219 |
-
}
|
220 |
-
|
221 |
-
//increase Memory need free memory in bytes
|
222 |
-
function backwpup_needfreememory($memneed) {
|
223 |
-
global $logtime;
|
224 |
-
if (!function_exists('memory_get_usage'))
|
225 |
-
return true;
|
226 |
-
|
227 |
-
//calc mem to bytes
|
228 |
-
if (strtoupper(substr(trim(ini_get('memory_limit')),-1))=='K')
|
229 |
-
$memory=trim(substr(ini_get('memory_limit'),0,-1))*1024;
|
230 |
-
elseif (strtoupper(substr(trim(ini_get('memory_limit')),-1))=='M')
|
231 |
-
$memory=trim(substr(ini_get('memory_limit'),0,-1))*1024*1024;
|
232 |
-
elseif (strtoupper(substr(trim(ini_get('memory_limit')),-1))=='G')
|
233 |
-
$memory=trim(substr(ini_get('memory_limit'),0,-1))*1024*1024*1024;
|
234 |
-
else
|
235 |
-
$memory=trim(ini_get('memory_limit'));
|
236 |
-
|
237 |
-
if (memory_get_usage()+$memneed>$memory) { // increase Memory
|
238 |
-
if (ini_get('safe_mode') or strtolower(ini_get('safe_mode'))=='on' or ini_get('safe_mode')=='1') {
|
239 |
-
backwpup_joblog($logtime,__('WARNING:','backwpup').' '.sprintf(__('PHP Safe Mode is on!!! Can not increase Memory Limit is %1$s','backwpup'),ini_get('memory_limit')));
|
240 |
-
return false;
|
241 |
-
}
|
242 |
-
$newmemory=round((memory_get_usage()+$memneed)/1024/1024)+1;
|
243 |
-
if ($oldmem=ini_set('memory_limit', $newmemory.'M'))
|
244 |
-
backwpup_joblog($logtime,sprintf(__('Memory increased from %1$s to %2$s','backwpup'),$oldmem,ini_get('memory_limit')));
|
245 |
-
else
|
246 |
-
backwpup_joblog($logtime,sprintf(__('ERROR:','backwpup').' '.__('Can not increase Memory Limit is %1$s','backwpup'),ini_get('memory_limit')));
|
247 |
-
}
|
248 |
-
return true;
|
249 |
-
}
|
250 |
-
|
251 |
-
|
252 |
-
//Make Log File for Jobs.
|
253 |
-
function backwpup_joblog($logtime,$entry) {
|
254 |
-
global $wpdb;
|
255 |
-
$errors=0;$warnings=0;
|
256 |
-
$style="";
|
257 |
-
if (substr($entry,0,strlen(__('ERROR:','backwpup')))==__('ERROR:','backwpup')) {
|
258 |
-
$errors=1;
|
259 |
-
$style=' style="background-color:red;"';
|
260 |
-
}
|
261 |
-
if (substr($entry,0,strlen(__('WARNING:','backwpup')))==__('WARNING:','backwpup')) {
|
262 |
-
$warnings=1;
|
263 |
-
$style=' style="background-color:yellow;"';
|
264 |
-
}
|
265 |
-
mysql_query("UPDATE ".$wpdb->backwpup_logs." SET error=error+".$errors.", warning=warning+".$warnings.", log=concat(log,'".mysql_real_escape_string(date_i18n('Y-m-d H:i.s').": ".$entry."\n")."') WHERE logtime=".$logtime);
|
266 |
-
if (!defined('DOING_CRON'))
|
267 |
-
echo "<span style=\"background-color:c3c3c3;\">".date_i18n('Y-m-d H:i.s').":</span> <span".$style.">".$entry."</span><script type=\"text/javascript\">window.scrollByLines(3);</script><br />\n";
|
268 |
-
flush();
|
269 |
-
ob_flush();
|
270 |
}
|
271 |
|
272 |
//file size
|
@@ -307,29 +213,79 @@ if ( !defined('ABSPATH') )
|
|
307 |
return $typename;
|
308 |
}
|
309 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
310 |
//Dashboard widget
|
311 |
function backwpup_dashboard_output() {
|
312 |
global $wpdb;
|
|
|
313 |
echo '<strong>'.__('Logs:','backwpup').'</strong><br />';
|
314 |
-
|
315 |
-
$
|
316 |
-
if (
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
321 |
else
|
322 |
-
echo $
|
323 |
echo '</i>';
|
324 |
-
if($
|
325 |
-
if ($
|
326 |
-
echo ' <span style="color:red;">'.$
|
327 |
-
if ($
|
328 |
-
echo ' <span style="color:yellow;">'.$
|
329 |
} else {
|
330 |
echo ' <span style="color:green;">'.__('OK','backwpup').'</span>';
|
331 |
}
|
332 |
echo '</a><br />';
|
|
|
|
|
|
|
333 |
}
|
334 |
} else {
|
335 |
echo '<i>'.__('none','backwpup').'</i><br />';
|
@@ -359,30 +315,6 @@ if ( !defined('ABSPATH') )
|
|
359 |
wp_add_dashboard_widget( 'backwpup_dashboard_widget', 'BackWPup', 'backwpup_dashboard_output' );
|
360 |
}
|
361 |
|
362 |
-
//Sed mail send Method
|
363 |
-
function backwpup_use_mail_method() {
|
364 |
-
global $phpmailer;
|
365 |
-
$cfg=get_option('backwpup'); //Load Settings
|
366 |
-
if ($cfg['mailmethod']=="SMTP") {
|
367 |
-
$smtpport=25;
|
368 |
-
$smtphost=$cfg['mailhost'];
|
369 |
-
if (false !== strpos($cfg['mailhost'],':')) //look for port
|
370 |
-
list($smtphost,$smtpport)=split(':',$cfg['mailhost'],2);
|
371 |
-
$phpmailer->Host=$smtphost;
|
372 |
-
$phpmailer->Port=$smtpport;
|
373 |
-
$phpmailer->SMTPSecure=$cfg['mailsecure'];
|
374 |
-
$phpmailer->Username=$cfg['mailuser'];
|
375 |
-
$phpmailer->Password=base64_decode($cfg['mailpass']);
|
376 |
-
if (!empty($cfg['mailuser']) and !empty($cfg['mailpass']))
|
377 |
-
$phpmailer->SMTPAuth=true;
|
378 |
-
$phpmailer->IsSMTP();
|
379 |
-
} elseif ($cfg['mailmethod']=="Sendmail") {
|
380 |
-
$phpmailer->Sendmail=$cfg['mailsendmail'];
|
381 |
-
$phpmailer->IsSendmail();
|
382 |
-
} else {
|
383 |
-
$phpmailer->IsMail();
|
384 |
-
}
|
385 |
-
}
|
386 |
|
387 |
// add all action and so on only if plugin loaded.
|
388 |
function backwpup_init() {
|
8 |
$hook = add_management_page(__('BackWPup','backwpup'), __('BackWPup','backwpup'), '10', 'BackWPup','backwpup_options_page') ;
|
9 |
add_action('load-'.$hook, 'backwpup_options_load');
|
10 |
add_contextual_help($hook,backwpup_show_help());
|
11 |
+
register_column_headers('backwpup_options',array('cb'=>'<input type="checkbox" />','id'=>__('ID','backwpup'),'name'=>__('Name','backwpup'),'type'=>__('Type','backwpup'),'next'=>__('Next Run','backwpup'),'last'=>__('Last Run','backwpup')));
|
12 |
+
register_column_headers('backwpup_options_logs',array('cb'=>'<input type="checkbox" />','id'=>__('Job','backwpup'),'type'=>__('Type','backwpup'),'log'=>__('Backup/Log Date/Time','backwpup'),'status'=>__('Status','backwpup'),'size'=>__('Size','backwpup'),'runtime'=>__('Runtime','backwpup')));
|
13 |
}
|
14 |
|
15 |
// Help too display
|
43 |
require_once(WP_PLUGIN_DIR.'/'.BACKWPUP_PLUGIN_DIR.'/app/options-jobs.php');
|
44 |
break;
|
45 |
case 'logs':
|
46 |
+
$cfg=get_option('backwpup');
|
47 |
require_once(WP_PLUGIN_DIR.'/'.BACKWPUP_PLUGIN_DIR.'/app/options-logs.php');
|
48 |
break;
|
49 |
case 'settings':
|
60 |
require_once(WP_PLUGIN_DIR.'/'.BACKWPUP_PLUGIN_DIR.'/app/options-runnow.php');
|
61 |
break;
|
62 |
case 'view_log':
|
63 |
+
check_admin_referer('view-log_'.basename($_GET['logfile']));
|
|
|
64 |
require_once(WP_PLUGIN_DIR.'/'.BACKWPUP_PLUGIN_DIR.'/app/options-view_log.php');
|
65 |
break;
|
66 |
default:
|
84 |
|
85 |
//delete Otions
|
86 |
function backwpup_plugin_uninstall() {
|
|
|
87 |
delete_option('backwpup');
|
88 |
delete_option('backwpup_jobs');
|
|
|
89 |
}
|
90 |
|
91 |
//On Plugin activate
|
92 |
function backwpup_plugin_activate() {
|
93 |
+
//delete old log table
|
94 |
global $wpdb;
|
95 |
+
$wpdb->backwpup_logs = $wpdb->prefix.'backwpup_logs';
|
96 |
+
$wpdb->query("DROP TABLE IF EXISTS ".$wpdb->backwpup_logs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
//add cron jobs
|
98 |
$jobs=get_option('backwpup_jobs');
|
99 |
if (is_array($jobs)) {
|
103 |
}
|
104 |
}
|
105 |
}
|
106 |
+
//Set defaults
|
107 |
+
$cfg=get_option('backwpup'); //Load Settings
|
108 |
+
if (empty($cfg['mailsndemail'])) $cfg['mailsndemail']=sanitize_email(get_bloginfo( 'admin_email' ));
|
109 |
+
if (empty($cfg['mailsndname'])) $cfg['mailsndname']='BackWPup '.get_bloginfo( 'name' );
|
110 |
+
if (empty($cfg['mailmethod'])) $cfg['mailmethod']='mail';
|
111 |
+
if (empty($cfg['mailsendmail'])) $cfg['mailsendmail']=substr(ini_get('sendmail_path'),0,strpos(ini_get('sendmail_path'),' -'));
|
112 |
+
if (empty($cfg['memorylimit'])) $cfg['memorylimit']='128M';
|
113 |
+
if (empty($cfg['maxlogs'])) $cfg['maxlogs']=0;
|
114 |
+
if (empty($cfg['dirlogs'])) $cfg['dirlogs']=str_replace('\\','/',stripslashes(get_temp_dir().'backwpup/logs'));
|
115 |
+
if (empty($cfg['dirtemp'])) $cfg['dirtemp']=str_replace('\\','/',stripslashes(get_temp_dir().'backwpup'));
|
116 |
+
update_option('backwpup',$cfg);
|
117 |
}
|
118 |
|
119 |
//on Plugin deaktivate
|
160 |
return $schedules;
|
161 |
}
|
162 |
|
|
|
163 |
//DoJob
|
164 |
function backwpup_dojob($args) {
|
165 |
+
if (is_array($args)) { //cron gifes no complete array back!!!
|
|
|
|
|
166 |
extract($args, EXTR_SKIP );
|
167 |
} else {
|
168 |
$jobid=$args;
|
169 |
}
|
170 |
if (empty($jobid)) return false;
|
171 |
require_once(ABSPATH . 'wp-admin/includes/file.php'); //for get_tempdir();
|
172 |
+
require_once('backwpup_dojob.php');
|
173 |
+
$dojob= new backwpup_dojob($jobid);
|
174 |
+
unset($dojob);
|
175 |
+
return BACKWPUP_LOGFILE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
}
|
177 |
|
178 |
//file size
|
213 |
return $typename;
|
214 |
}
|
215 |
|
216 |
+
//add spases
|
217 |
+
function backwpup_fillspases($number) {
|
218 |
+
$spaces='';
|
219 |
+
for ($i=0;$i<$number;$i++) {
|
220 |
+
$spaces.=' ';
|
221 |
+
}
|
222 |
+
return $spaces;
|
223 |
+
}
|
224 |
+
|
225 |
+
//read log file header
|
226 |
+
function backwpup_read_logheader($logfile) {
|
227 |
+
$headers=array("backwpup_version" => "version","backwpup_logtime" => "logtime","backwpup_errors" => "errors","backwpup_warnings" => "warnings","backwpup_jobid" => "jobid","backwpup_jobname" => "name","backwpup_jobtype" => "type","backwpup_jobruntime" => "runtime","backwpup_backupfile" => "backupfile");
|
228 |
+
if (!is_readable($logfile))
|
229 |
+
return false;
|
230 |
+
//Read file
|
231 |
+
$fp = @fopen( $logfile, 'r' );
|
232 |
+
$file_data = @fread( $fp, 1536 ); // Pull only the first 1,5kiB of the file in.
|
233 |
+
@fclose( $fp );
|
234 |
+
|
235 |
+
//get data form file
|
236 |
+
foreach ($headers as $keyword => $field) {
|
237 |
+
preg_match('/(<meta name="'.$keyword.'" content="(.*)" \/>)/i',$file_data,$content);
|
238 |
+
if (!empty($content))
|
239 |
+
$joddata[$field]=$content[2];
|
240 |
+
else
|
241 |
+
$joddata[$field]='';
|
242 |
+
}
|
243 |
+
|
244 |
+
if (empty($joddata['logtime']))
|
245 |
+
$joddata['logtime']=filectime($logfile);
|
246 |
+
|
247 |
+
return $joddata;
|
248 |
+
}
|
249 |
+
|
250 |
+
|
251 |
//Dashboard widget
|
252 |
function backwpup_dashboard_output() {
|
253 |
global $wpdb;
|
254 |
+
$cfg=get_option('backwpup');
|
255 |
echo '<strong>'.__('Logs:','backwpup').'</strong><br />';
|
256 |
+
//get log files
|
257 |
+
$logfiles=array();
|
258 |
+
if ( $dir = opendir( $cfg['dirlogs'] ) ) {
|
259 |
+
while (($file = readdir( $dir ) ) !== false ) {
|
260 |
+
if (is_file($cfg['dirlogs'].'/'.$file) and 'backwpup_log_' == substr($file,0,strlen('backwpup_log_')) and '.html' == substr($file,-5))
|
261 |
+
$logfiles[]=$file;
|
262 |
+
}
|
263 |
+
closedir( $dir );
|
264 |
+
rsort($logfiles);
|
265 |
+
}
|
266 |
+
|
267 |
+
if (is_array($logfiles)) {
|
268 |
+
$count=0;
|
269 |
+
foreach ($logfiles as $logfile) {
|
270 |
+
$logdata=backwpup_read_logheader($cfg['dirlogs'].'/'.$logfile);
|
271 |
+
echo '<a href="'.wp_nonce_url('admin.php?page=BackWPup&action=view_log&logfile='.$cfg['dirlogs'].'/'.$logfile, 'view-log_'.$logfile).'" title="'.__('View Log','backwpup').'">'.date_i18n(get_option('date_format'),$logdata['logtime']).' '.date_i18n(get_option('time_format'),$logdata['logtime']).': <i>';
|
272 |
+
if (empty($logdata['name']))
|
273 |
+
echo $logdata['type'];
|
274 |
else
|
275 |
+
echo $logdata['name'];
|
276 |
echo '</i>';
|
277 |
+
if($logdata['errors']>0 or $logdata['warnings']>0) {
|
278 |
+
if ($logdata['errors']>0)
|
279 |
+
echo ' <span style="color:red;">'.$logdata['errors'].' '.__('ERROR(S)','backwpup').'</span>';
|
280 |
+
if ($logdata['warnings']>0)
|
281 |
+
echo ' <span style="color:yellow;">'.$logdata['warnings'].' '.__('WARNING(S)','backwpup').'</span>';
|
282 |
} else {
|
283 |
echo ' <span style="color:green;">'.__('OK','backwpup').'</span>';
|
284 |
}
|
285 |
echo '</a><br />';
|
286 |
+
$count++;
|
287 |
+
if ($count>=5)
|
288 |
+
break;
|
289 |
}
|
290 |
} else {
|
291 |
echo '<i>'.__('none','backwpup').'</i><br />';
|
315 |
wp_add_dashboard_widget( 'backwpup_dashboard_widget', 'BackWPup', 'backwpup_dashboard_output' );
|
316 |
}
|
317 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
318 |
|
319 |
// add all action and so on only if plugin loaded.
|
320 |
function backwpup_init() {
|
app/iframe-dojob.php
DELETED
@@ -1,21 +0,0 @@
|
|
1 |
-
<?PHP
|
2 |
-
if ( !defined('ABSPATH') ) {
|
3 |
-
/** Setup WordPress environment */
|
4 |
-
require_once($_GET['ABSPATH'].'/wp-load.php');
|
5 |
-
}
|
6 |
-
?>
|
7 |
-
<html>
|
8 |
-
<head>
|
9 |
-
</head>
|
10 |
-
<body style="font-family:monospace;font-size:12px;white-space:nowrap;">
|
11 |
-
<?PHP
|
12 |
-
check_admin_referer('dojob-now_' . (int)$_GET['jobid']);
|
13 |
-
ignore_user_abort(true);
|
14 |
-
// flush any buffers and send the headers
|
15 |
-
ob_start();
|
16 |
-
while (@ob_end_flush());
|
17 |
-
flush();
|
18 |
-
backwpup_dojob($_GET['jobid']);
|
19 |
-
?>
|
20 |
-
</body>
|
21 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/libs/S3.php
ADDED
@@ -0,0 +1,1365 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* $Id: S3.php 47 2009-07-20 01:25:40Z don.schonknecht $
|
4 |
+
*
|
5 |
+
* Copyright (c) 2008, Donovan Schönknecht. All rights reserved.
|
6 |
+
*
|
7 |
+
* Redistribution and use in source and binary forms, with or without
|
8 |
+
* modification, are permitted provided that the following conditions are met:
|
9 |
+
*
|
10 |
+
* - Redistributions of source code must retain the above copyright notice,
|
11 |
+
* this list of conditions and the following disclaimer.
|
12 |
+
* - Redistributions in binary form must reproduce the above copyright
|
13 |
+
* notice, this list of conditions and the following disclaimer in the
|
14 |
+
* documentation and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17 |
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
19 |
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
20 |
+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
21 |
+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
22 |
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
23 |
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
24 |
+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
25 |
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
26 |
+
* POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* Amazon S3 is a trademark of Amazon.com, Inc. or its affiliates.
|
29 |
+
*/
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Amazon S3 PHP class
|
33 |
+
*
|
34 |
+
* @link http://undesigned.org.za/2007/10/22/amazon-s3-php-class
|
35 |
+
* @version 0.4.0
|
36 |
+
*/
|
37 |
+
class S3 {
|
38 |
+
// ACL flags
|
39 |
+
const ACL_PRIVATE = 'private';
|
40 |
+
const ACL_PUBLIC_READ = 'public-read';
|
41 |
+
const ACL_PUBLIC_READ_WRITE = 'public-read-write';
|
42 |
+
const ACL_AUTHENTICATED_READ = 'authenticated-read';
|
43 |
+
|
44 |
+
public static $useSSL = true;
|
45 |
+
|
46 |
+
private static $__accessKey; // AWS Access key
|
47 |
+
private static $__secretKey; // AWS Secret key
|
48 |
+
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Constructor - if you're not using the class statically
|
52 |
+
*
|
53 |
+
* @param string $accessKey Access key
|
54 |
+
* @param string $secretKey Secret key
|
55 |
+
* @param boolean $useSSL Enable SSL
|
56 |
+
* @return void
|
57 |
+
*/
|
58 |
+
public function __construct($accessKey = null, $secretKey = null, $useSSL = true) {
|
59 |
+
if ($accessKey !== null && $secretKey !== null)
|
60 |
+
self::setAuth($accessKey, $secretKey);
|
61 |
+
self::$useSSL = $useSSL;
|
62 |
+
}
|
63 |
+
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Set AWS access key and secret key
|
67 |
+
*
|
68 |
+
* @param string $accessKey Access key
|
69 |
+
* @param string $secretKey Secret key
|
70 |
+
* @return void
|
71 |
+
*/
|
72 |
+
public static function setAuth($accessKey, $secretKey) {
|
73 |
+
self::$__accessKey = $accessKey;
|
74 |
+
self::$__secretKey = $secretKey;
|
75 |
+
}
|
76 |
+
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Get a list of buckets
|
80 |
+
*
|
81 |
+
* @param boolean $detailed Returns detailed bucket list when true
|
82 |
+
* @return array | false
|
83 |
+
*/
|
84 |
+
public static function listBuckets($detailed = false) {
|
85 |
+
$rest = new S3Request('GET', '', '');
|
86 |
+
$rest = $rest->getResponse();
|
87 |
+
if ($rest->error === false && $rest->code !== 200)
|
88 |
+
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
|
89 |
+
if ($rest->error !== false) {
|
90 |
+
trigger_error(sprintf("S3::listBuckets(): [%s] %s", $rest->error['code'], $rest->error['message']), E_USER_WARNING);
|
91 |
+
return false;
|
92 |
+
}
|
93 |
+
$results = array();
|
94 |
+
if (!isset($rest->body->Buckets)) return $results;
|
95 |
+
|
96 |
+
if ($detailed) {
|
97 |
+
if (isset($rest->body->Owner, $rest->body->Owner->ID, $rest->body->Owner->DisplayName))
|
98 |
+
$results['owner'] = array(
|
99 |
+
'id' => (string)$rest->body->Owner->ID, 'name' => (string)$rest->body->Owner->ID
|
100 |
+
);
|
101 |
+
$results['buckets'] = array();
|
102 |
+
foreach ($rest->body->Buckets->Bucket as $b)
|
103 |
+
$results['buckets'][] = array(
|
104 |
+
'name' => (string)$b->Name, 'time' => strtotime((string)$b->CreationDate)
|
105 |
+
);
|
106 |
+
} else
|
107 |
+
foreach ($rest->body->Buckets->Bucket as $b) $results[] = (string)$b->Name;
|
108 |
+
|
109 |
+
return $results;
|
110 |
+
}
|
111 |
+
|
112 |
+
|
113 |
+
/*
|
114 |
+
* Get contents for a bucket
|
115 |
+
*
|
116 |
+
* If maxKeys is null this method will loop through truncated result sets
|
117 |
+
*
|
118 |
+
* @param string $bucket Bucket name
|
119 |
+
* @param string $prefix Prefix
|
120 |
+
* @param string $marker Marker (last file listed)
|
121 |
+
* @param string $maxKeys Max keys (maximum number of keys to return)
|
122 |
+
* @param string $delimiter Delimiter
|
123 |
+
* @param boolean $returnCommonPrefixes Set to true to return CommonPrefixes
|
124 |
+
* @return array | false
|
125 |
+
*/
|
126 |
+
public static function getBucket($bucket, $prefix = null, $marker = null, $maxKeys = null, $delimiter = null, $returnCommonPrefixes = false) {
|
127 |
+
$rest = new S3Request('GET', $bucket, '');
|
128 |
+
if ($prefix !== null && $prefix !== '') $rest->setParameter('prefix', $prefix);
|
129 |
+
if ($marker !== null && $marker !== '') $rest->setParameter('marker', $marker);
|
130 |
+
if ($maxKeys !== null && $maxKeys !== '') $rest->setParameter('max-keys', $maxKeys);
|
131 |
+
if ($delimiter !== null && $delimiter !== '') $rest->setParameter('delimiter', $delimiter);
|
132 |
+
$response = $rest->getResponse();
|
133 |
+
if ($response->error === false && $response->code !== 200)
|
134 |
+
$response->error = array('code' => $response->code, 'message' => 'Unexpected HTTP status');
|
135 |
+
if ($response->error !== false) {
|
136 |
+
trigger_error(sprintf("S3::getBucket(): [%s] %s", $response->error['code'], $response->error['message']), E_USER_WARNING);
|
137 |
+
return false;
|
138 |
+
}
|
139 |
+
|
140 |
+
$results = array();
|
141 |
+
|
142 |
+
$nextMarker = null;
|
143 |
+
if (isset($response->body, $response->body->Contents))
|
144 |
+
foreach ($response->body->Contents as $c) {
|
145 |
+
$results[(string)$c->Key] = array(
|
146 |
+
'name' => (string)$c->Key,
|
147 |
+
'time' => strtotime((string)$c->LastModified),
|
148 |
+
'size' => (int)$c->Size,
|
149 |
+
'hash' => substr((string)$c->ETag, 1, -1)
|
150 |
+
);
|
151 |
+
$nextMarker = (string)$c->Key;
|
152 |
+
}
|
153 |
+
|
154 |
+
if ($returnCommonPrefixes && isset($response->body, $response->body->CommonPrefixes))
|
155 |
+
foreach ($response->body->CommonPrefixes as $c)
|
156 |
+
$results[(string)$c->Prefix] = array('prefix' => (string)$c->Prefix);
|
157 |
+
|
158 |
+
if (isset($response->body, $response->body->IsTruncated) &&
|
159 |
+
(string)$response->body->IsTruncated == 'false') return $results;
|
160 |
+
|
161 |
+
if (isset($response->body, $response->body->NextMarker))
|
162 |
+
$nextMarker = (string)$response->body->NextMarker;
|
163 |
+
|
164 |
+
// Loop through truncated results if maxKeys isn't specified
|
165 |
+
if ($maxKeys == null && $nextMarker !== null && (string)$response->body->IsTruncated == 'true')
|
166 |
+
do {
|
167 |
+
$rest = new S3Request('GET', $bucket, '');
|
168 |
+
if ($prefix !== null && $prefix !== '') $rest->setParameter('prefix', $prefix);
|
169 |
+
$rest->setParameter('marker', $nextMarker);
|
170 |
+
if ($delimiter !== null && $delimiter !== '') $rest->setParameter('delimiter', $delimiter);
|
171 |
+
|
172 |
+
if (($response = $rest->getResponse(true)) == false || $response->code !== 200) break;
|
173 |
+
|
174 |
+
if (isset($response->body, $response->body->Contents))
|
175 |
+
foreach ($response->body->Contents as $c) {
|
176 |
+
$results[(string)$c->Key] = array(
|
177 |
+
'name' => (string)$c->Key,
|
178 |
+
'time' => strtotime((string)$c->LastModified),
|
179 |
+
'size' => (int)$c->Size,
|
180 |
+
'hash' => substr((string)$c->ETag, 1, -1)
|
181 |
+
);
|
182 |
+
$nextMarker = (string)$c->Key;
|
183 |
+
}
|
184 |
+
|
185 |
+
if ($returnCommonPrefixes && isset($response->body, $response->body->CommonPrefixes))
|
186 |
+
foreach ($response->body->CommonPrefixes as $c)
|
187 |
+
$results[(string)$c->Prefix] = array('prefix' => (string)$c->Prefix);
|
188 |
+
|
189 |
+
if (isset($response->body, $response->body->NextMarker))
|
190 |
+
$nextMarker = (string)$response->body->NextMarker;
|
191 |
+
|
192 |
+
} while ($response !== false && (string)$response->body->IsTruncated == 'true');
|
193 |
+
|
194 |
+
return $results;
|
195 |
+
}
|
196 |
+
|
197 |
+
|
198 |
+
/**
|
199 |
+
* Put a bucket
|
200 |
+
*
|
201 |
+
* @param string $bucket Bucket name
|
202 |
+
* @param constant $acl ACL flag
|
203 |
+
* @param string $location Set as "EU" to create buckets hosted in Europe
|
204 |
+
* @return boolean
|
205 |
+
*/
|
206 |
+
public static function putBucket($bucket, $acl = self::ACL_PRIVATE, $location = false) {
|
207 |
+
$rest = new S3Request('PUT', $bucket, '');
|
208 |
+
$rest->setAmzHeader('x-amz-acl', $acl);
|
209 |
+
|
210 |
+
if ($location !== false) {
|
211 |
+
$dom = new DOMDocument;
|
212 |
+
$createBucketConfiguration = $dom->createElement('CreateBucketConfiguration');
|
213 |
+
$locationConstraint = $dom->createElement('LocationConstraint', strtoupper($location));
|
214 |
+
$createBucketConfiguration->appendChild($locationConstraint);
|
215 |
+
$dom->appendChild($createBucketConfiguration);
|
216 |
+
$rest->data = $dom->saveXML();
|
217 |
+
$rest->size = strlen($rest->data);
|
218 |
+
$rest->setHeader('Content-Type', 'application/xml');
|
219 |
+
}
|
220 |
+
$rest = $rest->getResponse();
|
221 |
+
|
222 |
+
if ($rest->error === false && $rest->code !== 200)
|
223 |
+
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
|
224 |
+
if ($rest->error !== false) {
|
225 |
+
trigger_error(sprintf("S3::putBucket({$bucket}, {$acl}, {$location}): [%s] %s",
|
226 |
+
$rest->error['code'], $rest->error['message']), E_USER_WARNING);
|
227 |
+
return false;
|
228 |
+
}
|
229 |
+
return true;
|
230 |
+
}
|
231 |
+
|
232 |
+
|
233 |
+
/**
|
234 |
+
* Delete an empty bucket
|
235 |
+
*
|
236 |
+
* @param string $bucket Bucket name
|
237 |
+
* @return boolean
|
238 |
+
*/
|
239 |
+
public static function deleteBucket($bucket) {
|
240 |
+
$rest = new S3Request('DELETE', $bucket);
|
241 |
+
$rest = $rest->getResponse();
|
242 |
+
if ($rest->error === false && $rest->code !== 204)
|
243 |
+
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
|
244 |
+
if ($rest->error !== false) {
|
245 |
+
trigger_error(sprintf("S3::deleteBucket({$bucket}): [%s] %s",
|
246 |
+
$rest->error['code'], $rest->error['message']), E_USER_WARNING);
|
247 |
+
return false;
|
248 |
+
}
|
249 |
+
return true;
|
250 |
+
}
|
251 |
+
|
252 |
+
|
253 |
+
/**
|
254 |
+
* Create input info array for putObject()
|
255 |
+
*
|
256 |
+
* @param string $file Input file
|
257 |
+
* @param mixed $md5sum Use MD5 hash (supply a string if you want to use your own)
|
258 |
+
* @return array | false
|
259 |
+
*/
|
260 |
+
public static function inputFile($file, $md5sum = true) {
|
261 |
+
if (!file_exists($file) || !is_file($file) || !is_readable($file)) {
|
262 |
+
trigger_error('S3::inputFile(): Unable to open input file: '.$file, E_USER_WARNING);
|
263 |
+
return false;
|
264 |
+
}
|
265 |
+
return array('file' => $file, 'size' => filesize($file),
|
266 |
+
'md5sum' => $md5sum !== false ? (is_string($md5sum) ? $md5sum :
|
267 |
+
base64_encode(md5_file($file, true))) : '');
|
268 |
+
}
|
269 |
+
|
270 |
+
|
271 |
+
/**
|
272 |
+
* Create input array info for putObject() with a resource
|
273 |
+
*
|
274 |
+
* @param string $resource Input resource to read from
|
275 |
+
* @param integer $bufferSize Input byte size
|
276 |
+
* @param string $md5sum MD5 hash to send (optional)
|
277 |
+
* @return array | false
|
278 |
+
*/
|
279 |
+
public static function inputResource(&$resource, $bufferSize, $md5sum = '') {
|
280 |
+
if (!is_resource($resource) || $bufferSize < 0) {
|
281 |
+
trigger_error('S3::inputResource(): Invalid resource or buffer size', E_USER_WARNING);
|
282 |
+
return false;
|
283 |
+
}
|
284 |
+
$input = array('size' => $bufferSize, 'md5sum' => $md5sum);
|
285 |
+
$input['fp'] =& $resource;
|
286 |
+
return $input;
|
287 |
+
}
|
288 |
+
|
289 |
+
|
290 |
+
/**
|
291 |
+
* Put an object
|
292 |
+
*
|
293 |
+
* @param mixed $input Input data
|
294 |
+
* @param string $bucket Bucket name
|
295 |
+
* @param string $uri Object URI
|
296 |
+
* @param constant $acl ACL constant
|
297 |
+
* @param array $metaHeaders Array of x-amz-meta-* headers
|
298 |
+
* @param array $requestHeaders Array of request headers or content type as a string
|
299 |
+
* @return boolean
|
300 |
+
*/
|
301 |
+
public static function putObject($input, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $requestHeaders = array()) {
|
302 |
+
if ($input === false) return false;
|
303 |
+
$rest = new S3Request('PUT', $bucket, $uri);
|
304 |
+
|
305 |
+
if (is_string($input)) $input = array(
|
306 |
+
'data' => $input, 'size' => strlen($input),
|
307 |
+
'md5sum' => base64_encode(md5($input, true))
|
308 |
+
);
|
309 |
+
|
310 |
+
// Data
|
311 |
+
if (isset($input['fp']))
|
312 |
+
$rest->fp =& $input['fp'];
|
313 |
+
elseif (isset($input['file']))
|
314 |
+
$rest->fp = @fopen($input['file'], 'rb');
|
315 |
+
elseif (isset($input['data']))
|
316 |
+
$rest->data = $input['data'];
|
317 |
+
|
318 |
+
// Content-Length (required)
|
319 |
+
if (isset($input['size']) && $input['size'] >= 0)
|
320 |
+
$rest->size = $input['size'];
|
321 |
+
else {
|
322 |
+
if (isset($input['file']))
|
323 |
+
$rest->size = filesize($input['file']);
|
324 |
+
elseif (isset($input['data']))
|
325 |
+
$rest->size = strlen($input['data']);
|
326 |
+
}
|
327 |
+
|
328 |
+
// Custom request headers (Content-Type, Content-Disposition, Content-Encoding)
|
329 |
+
if (is_array($requestHeaders))
|
330 |
+
foreach ($requestHeaders as $h => $v) $rest->setHeader($h, $v);
|
331 |
+
elseif (is_string($requestHeaders)) // Support for legacy contentType parameter
|
332 |
+
$input['type'] = $requestHeaders;
|
333 |
+
|
334 |
+
// Content-Type
|
335 |
+
if (!isset($input['type'])) {
|
336 |
+
if (isset($requestHeaders['Content-Type']))
|
337 |
+
$input['type'] =& $requestHeaders['Content-Type'];
|
338 |
+
elseif (isset($input['file']))
|
339 |
+
$input['type'] = self::__getMimeType($input['file']);
|
340 |
+
else
|
341 |
+
$input['type'] = 'application/octet-stream';
|
342 |
+
}
|
343 |
+
|
344 |
+
// We need to post with Content-Length and Content-Type, MD5 is optional
|
345 |
+
if ($rest->size >= 0 && ($rest->fp !== false || $rest->data !== false)) {
|
346 |
+
$rest->setHeader('Content-Type', $input['type']);
|
347 |
+
if (isset($input['md5sum'])) $rest->setHeader('Content-MD5', $input['md5sum']);
|
348 |
+
|
349 |
+
$rest->setAmzHeader('x-amz-acl', $acl);
|
350 |
+
foreach ($metaHeaders as $h => $v) $rest->setAmzHeader('x-amz-meta-'.$h, $v);
|
351 |
+
$rest->getResponse();
|
352 |
+
} else
|
353 |
+
$rest->response->error = array('code' => 0, 'message' => 'Missing input parameters');
|
354 |
+
|
355 |
+
if ($rest->response->error === false && $rest->response->code !== 200)
|
356 |
+
$rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status');
|
357 |
+
if ($rest->response->error !== false) {
|
358 |
+
trigger_error(sprintf("S3::putObject(): [%s] %s", $rest->response->error['code'], $rest->response->error['message']), E_USER_WARNING);
|
359 |
+
return false;
|
360 |
+
}
|
361 |
+
return true;
|
362 |
+
}
|
363 |
+
|
364 |
+
|
365 |
+
/**
|
366 |
+
* Put an object from a file (legacy function)
|
367 |
+
*
|
368 |
+
* @param string $file Input file path
|
369 |
+
* @param string $bucket Bucket name
|
370 |
+
* @param string $uri Object URI
|
371 |
+
* @param constant $acl ACL constant
|
372 |
+
* @param array $metaHeaders Array of x-amz-meta-* headers
|
373 |
+
* @param string $contentType Content type
|
374 |
+
* @return boolean
|
375 |
+
*/
|
376 |
+
public static function putObjectFile($file, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $contentType = null) {
|
377 |
+
return self::putObject(self::inputFile($file), $bucket, $uri, $acl, $metaHeaders, $contentType);
|
378 |
+
}
|
379 |
+
|
380 |
+
|
381 |
+
/**
|
382 |
+
* Put an object from a string (legacy function)
|
383 |
+
*
|
384 |
+
* @param string $string Input data
|
385 |
+
* @param string $bucket Bucket name
|
386 |
+
* @param string $uri Object URI
|
387 |
+
* @param constant $acl ACL constant
|
388 |
+
* @param array $metaHeaders Array of x-amz-meta-* headers
|
389 |
+
* @param string $contentType Content type
|
390 |
+
* @return boolean
|
391 |
+
*/
|
392 |
+
public static function putObjectString($string, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $contentType = 'text/plain') {
|
393 |
+
return self::putObject($string, $bucket, $uri, $acl, $metaHeaders, $contentType);
|
394 |
+
}
|
395 |
+
|
396 |
+
|
397 |
+
/**
|
398 |
+
* Get an object
|
399 |
+
*
|
400 |
+
* @param string $bucket Bucket name
|
401 |
+
* @param string $uri Object URI
|
402 |
+
* @param mixed $saveTo Filename or resource to write to
|
403 |
+
* @return mixed
|
404 |
+
*/
|
405 |
+
public static function getObject($bucket, $uri, $saveTo = false) {
|
406 |
+
$rest = new S3Request('GET', $bucket, $uri);
|
407 |
+
if ($saveTo !== false) {
|
408 |
+
if (is_resource($saveTo))
|
409 |
+
$rest->fp =& $saveTo;
|
410 |
+
else
|
411 |
+
if (($rest->fp = @fopen($saveTo, 'wb')) !== false)
|
412 |
+
$rest->file = realpath($saveTo);
|
413 |
+
else
|
414 |
+
$rest->response->error = array('code' => 0, 'message' => 'Unable to open save file for writing: '.$saveTo);
|
415 |
+
}
|
416 |
+
if ($rest->response->error === false) $rest->getResponse();
|
417 |
+
|
418 |
+
if ($rest->response->error === false && $rest->response->code !== 200)
|
419 |
+
$rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status');
|
420 |
+
if ($rest->response->error !== false) {
|
421 |
+
trigger_error(sprintf("S3::getObject({$bucket}, {$uri}): [%s] %s",
|
422 |
+
$rest->response->error['code'], $rest->response->error['message']), E_USER_WARNING);
|
423 |
+
return false;
|
424 |
+
}
|
425 |
+
return $rest->response;
|
426 |
+
}
|
427 |
+
|
428 |
+
|
429 |
+
/**
|
430 |
+
* Get object information
|
431 |
+
*
|
432 |
+
* @param string $bucket Bucket name
|
433 |
+
* @param string $uri Object URI
|
434 |
+
* @param boolean $returnInfo Return response information
|
435 |
+
* @return mixed | false
|
436 |
+
*/
|
437 |
+
public static function getObjectInfo($bucket, $uri, $returnInfo = true) {
|
438 |
+
$rest = new S3Request('HEAD', $bucket, $uri);
|
439 |
+
$rest = $rest->getResponse();
|
440 |
+
if ($rest->error === false && ($rest->code !== 200 && $rest->code !== 404))
|
441 |
+
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
|
442 |
+
if ($rest->error !== false) {
|
443 |
+
trigger_error(sprintf("S3::getObjectInfo({$bucket}, {$uri}): [%s] %s",
|
444 |
+
$rest->error['code'], $rest->error['message']), E_USER_WARNING);
|
445 |
+
return false;
|
446 |
+
}
|
447 |
+
return $rest->code == 200 ? $returnInfo ? $rest->headers : true : false;
|
448 |
+
}
|
449 |
+
|
450 |
+
|
451 |
+
/**
|
452 |
+
* Copy an object
|
453 |
+
*
|
454 |
+
* @param string $bucket Source bucket name
|
455 |
+
* @param string $uri Source object URI
|
456 |
+
* @param string $bucket Destination bucket name
|
457 |
+
* @param string $uri Destination object URI
|
458 |
+
* @param constant $acl ACL constant
|
459 |
+
* @param array $metaHeaders Optional array of x-amz-meta-* headers
|
460 |
+
* @param array $requestHeaders Optional array of request headers (content type, disposition, etc.)
|
461 |
+
* @return mixed | false
|
462 |
+
*/
|
463 |
+
public static function copyObject($srcBucket, $srcUri, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $requestHeaders = array()) {
|
464 |
+
$rest = new S3Request('PUT', $bucket, $uri);
|
465 |
+
$rest->setHeader('Content-Length', 0);
|
466 |
+
foreach ($requestHeaders as $h => $v) $rest->setHeader($h, $v);
|
467 |
+
foreach ($metaHeaders as $h => $v) $rest->setAmzHeader('x-amz-meta-'.$h, $v);
|
468 |
+
$rest->setAmzHeader('x-amz-acl', $acl);
|
469 |
+
$rest->setAmzHeader('x-amz-copy-source', sprintf('/%s/%s', $srcBucket, $srcUri));
|
470 |
+
if (sizeof($requestHeaders) > 0 || sizeof($metaHeaders) > 0)
|
471 |
+
$rest->setAmzHeader('x-amz-metadata-directive', 'REPLACE');
|
472 |
+
$rest = $rest->getResponse();
|
473 |
+
if ($rest->error === false && $rest->code !== 200)
|
474 |
+
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
|
475 |
+
if ($rest->error !== false) {
|
476 |
+
trigger_error(sprintf("S3::copyObject({$srcBucket}, {$srcUri}, {$bucket}, {$uri}): [%s] %s",
|
477 |
+
$rest->error['code'], $rest->error['message']), E_USER_WARNING);
|
478 |
+
return false;
|
479 |
+
}
|
480 |
+
return isset($rest->body->LastModified, $rest->body->ETag) ? array(
|
481 |
+
'time' => strtotime((string)$rest->body->LastModified),
|
482 |
+
'hash' => substr((string)$rest->body->ETag, 1, -1)
|
483 |
+
) : false;
|
484 |
+
}
|
485 |
+
|
486 |
+
|
487 |
+
/**
|
488 |
+
* Set logging for a bucket
|
489 |
+
*
|
490 |
+
* @param string $bucket Bucket name
|
491 |
+
* @param string $targetBucket Target bucket (where logs are stored)
|
492 |
+
* @param string $targetPrefix Log prefix (e,g; domain.com-)
|
493 |
+
* @return boolean
|
494 |
+
*/
|
495 |
+
public static function setBucketLogging($bucket, $targetBucket, $targetPrefix = null) {
|
496 |
+
// The S3 log delivery group has to be added to the target bucket's ACP
|
497 |
+
if ($targetBucket !== null && ($acp = self::getAccessControlPolicy($targetBucket, '')) !== false) {
|
498 |
+
// Only add permissions to the target bucket when they do not exist
|
499 |
+
$aclWriteSet = false;
|
500 |
+
$aclReadSet = false;
|
501 |
+
foreach ($acp['acl'] as $acl)
|
502 |
+
if ($acl['type'] == 'Group' && $acl['uri'] == 'http://acs.amazonaws.com/groups/s3/LogDelivery') {
|
503 |
+
if ($acl['permission'] == 'WRITE') $aclWriteSet = true;
|
504 |
+
elseif ($acl['permission'] == 'READ_ACP') $aclReadSet = true;
|
505 |
+
}
|
506 |
+
if (!$aclWriteSet) $acp['acl'][] = array(
|
507 |
+
'type' => 'Group', 'uri' => 'http://acs.amazonaws.com/groups/s3/LogDelivery', 'permission' => 'WRITE'
|
508 |
+
);
|
509 |
+
if (!$aclReadSet) $acp['acl'][] = array(
|
510 |
+
'type' => 'Group', 'uri' => 'http://acs.amazonaws.com/groups/s3/LogDelivery', 'permission' => 'READ_ACP'
|
511 |
+
);
|
512 |
+
if (!$aclReadSet || !$aclWriteSet) self::setAccessControlPolicy($targetBucket, '', $acp);
|
513 |
+
}
|
514 |
+
|
515 |
+
$dom = new DOMDocument;
|
516 |
+
$bucketLoggingStatus = $dom->createElement('BucketLoggingStatus');
|
517 |
+
$bucketLoggingStatus->setAttribute('xmlns', 'http://s3.amazonaws.com/doc/2006-03-01/');
|
518 |
+
if ($targetBucket !== null) {
|
519 |
+
if ($targetPrefix == null) $targetPrefix = $bucket . '-';
|
520 |
+
$loggingEnabled = $dom->createElement('LoggingEnabled');
|
521 |
+
$loggingEnabled->appendChild($dom->createElement('TargetBucket', $targetBucket));
|
522 |
+
$loggingEnabled->appendChild($dom->createElement('TargetPrefix', $targetPrefix));
|
523 |
+
// TODO: Add TargetGrants?
|
524 |
+
$bucketLoggingStatus->appendChild($loggingEnabled);
|
525 |
+
}
|
526 |
+
$dom->appendChild($bucketLoggingStatus);
|
527 |
+
|
528 |
+
$rest = new S3Request('PUT', $bucket, '');
|
529 |
+
$rest->setParameter('logging', null);
|
530 |
+
$rest->data = $dom->saveXML();
|
531 |
+
$rest->size = strlen($rest->data);
|
532 |
+
$rest->setHeader('Content-Type', 'application/xml');
|
533 |
+
$rest = $rest->getResponse();
|
534 |
+
if ($rest->error === false && $rest->code !== 200)
|
535 |
+
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
|
536 |
+
if ($rest->error !== false) {
|
537 |
+
trigger_error(sprintf("S3::setBucketLogging({$bucket}, {$uri}): [%s] %s",
|
538 |
+
$rest->error['code'], $rest->error['message']), E_USER_WARNING);
|
539 |
+
return false;
|
540 |
+
}
|
541 |
+
return true;
|
542 |
+
}
|
543 |
+
|
544 |
+
|
545 |
+
/**
|
546 |
+
* Get logging status for a bucket
|
547 |
+
*
|
548 |
+
* This will return false if logging is not enabled.
|
549 |
+
* Note: To enable logging, you also need to grant write access to the log group
|
550 |
+
*
|
551 |
+
* @param string $bucket Bucket name
|
552 |
+
* @return array | false
|
553 |
+
*/
|
554 |
+
public static function getBucketLogging($bucket) {
|
555 |
+
$rest = new S3Request('GET', $bucket, '');
|
556 |
+
$rest->setParameter('logging', null);
|
557 |
+
$rest = $rest->getResponse();
|
558 |
+
if ($rest->error === false && $rest->code !== 200)
|
559 |
+
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
|
560 |
+
if ($rest->error !== false) {
|
561 |
+
trigger_error(sprintf("S3::getBucketLogging({$bucket}): [%s] %s",
|
562 |
+
$rest->error['code'], $rest->error['message']), E_USER_WARNING);
|
563 |
+
return false;
|
564 |
+
}
|
565 |
+
if (!isset($rest->body->LoggingEnabled)) return false; // No logging
|
566 |
+
return array(
|
567 |
+
'targetBucket' => (string)$rest->body->LoggingEnabled->TargetBucket,
|
568 |
+
'targetPrefix' => (string)$rest->body->LoggingEnabled->TargetPrefix,
|
569 |
+
);
|
570 |
+
}
|
571 |
+
|
572 |
+
|
573 |
+
/**
|
574 |
+
* Disable bucket logging
|
575 |
+
*
|
576 |
+
* @param string $bucket Bucket name
|
577 |
+
* @return boolean
|
578 |
+
*/
|
579 |
+
public static function disableBucketLogging($bucket) {
|
580 |
+
return self::setBucketLogging($bucket, null);
|
581 |
+
}
|
582 |
+
|
583 |
+
|
584 |
+
/**
|
585 |
+
* Get a bucket's location
|
586 |
+
*
|
587 |
+
* @param string $bucket Bucket name
|
588 |
+
* @return string | false
|
589 |
+
*/
|
590 |
+
public static function getBucketLocation($bucket) {
|
591 |
+
$rest = new S3Request('GET', $bucket, '');
|
592 |
+
$rest->setParameter('location', null);
|
593 |
+
$rest = $rest->getResponse();
|
594 |
+
if ($rest->error === false && $rest->code !== 200)
|
595 |
+
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
|
596 |
+
if ($rest->error !== false) {
|
597 |
+
trigger_error(sprintf("S3::getBucketLocation({$bucket}): [%s] %s",
|
598 |
+
$rest->error['code'], $rest->error['message']), E_USER_WARNING);
|
599 |
+
return false;
|
600 |
+
}
|
601 |
+
return (isset($rest->body[0]) && (string)$rest->body[0] !== '') ? (string)$rest->body[0] : 'US';
|
602 |
+
}
|
603 |
+
|
604 |
+
|
605 |
+
/**
|
606 |
+
* Set object or bucket Access Control Policy
|
607 |
+
*
|
608 |
+
* @param string $bucket Bucket name
|
609 |
+
* @param string $uri Object URI
|
610 |
+
* @param array $acp Access Control Policy Data (same as the data returned from getAccessControlPolicy)
|
611 |
+
* @return boolean
|
612 |
+
*/
|
613 |
+
public static function setAccessControlPolicy($bucket, $uri = '', $acp = array()) {
|
614 |
+
$dom = new DOMDocument;
|
615 |
+
$dom->formatOutput = true;
|
616 |
+
$accessControlPolicy = $dom->createElement('AccessControlPolicy');
|
617 |
+
$accessControlList = $dom->createElement('AccessControlList');
|
618 |
+
|
619 |
+
// It seems the owner has to be passed along too
|
620 |
+
$owner = $dom->createElement('Owner');
|
621 |
+
$owner->appendChild($dom->createElement('ID', $acp['owner']['id']));
|
622 |
+
$owner->appendChild($dom->createElement('DisplayName', $acp['owner']['name']));
|
623 |
+
$accessControlPolicy->appendChild($owner);
|
624 |
+
|
625 |
+
foreach ($acp['acl'] as $g) {
|
626 |
+
$grant = $dom->createElement('Grant');
|
627 |
+
$grantee = $dom->createElement('Grantee');
|
628 |
+
$grantee->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
|
629 |
+
if (isset($g['id'])) { // CanonicalUser (DisplayName is omitted)
|
630 |
+
$grantee->setAttribute('xsi:type', 'CanonicalUser');
|
631 |
+
$grantee->appendChild($dom->createElement('ID', $g['id']));
|
632 |
+
} elseif (isset($g['email'])) { // AmazonCustomerByEmail
|
633 |
+
$grantee->setAttribute('xsi:type', 'AmazonCustomerByEmail');
|
634 |
+
$grantee->appendChild($dom->createElement('EmailAddress', $g['email']));
|
635 |
+
} elseif ($g['type'] == 'Group') { // Group
|
636 |
+
$grantee->setAttribute('xsi:type', 'Group');
|
637 |
+
$grantee->appendChild($dom->createElement('URI', $g['uri']));
|
638 |
+
}
|
639 |
+
$grant->appendChild($grantee);
|
640 |
+
$grant->appendChild($dom->createElement('Permission', $g['permission']));
|
641 |
+
$accessControlList->appendChild($grant);
|
642 |
+
}
|
643 |
+
|
644 |
+
$accessControlPolicy->appendChild($accessControlList);
|
645 |
+
$dom->appendChild($accessControlPolicy);
|
646 |
+
|
647 |
+
$rest = new S3Request('PUT', $bucket, $uri);
|
648 |
+
$rest->setParameter('acl', null);
|
649 |
+
$rest->data = $dom->saveXML();
|
650 |
+
$rest->size = strlen($rest->data);
|
651 |
+
$rest->setHeader('Content-Type', 'application/xml');
|
652 |
+
$rest = $rest->getResponse();
|
653 |
+
if ($rest->error === false && $rest->code !== 200)
|
654 |
+
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
|
655 |
+
if ($rest->error !== false) {
|
656 |
+
trigger_error(sprintf("S3::setAccessControlPolicy({$bucket}, {$uri}): [%s] %s",
|
657 |
+
$rest->error['code'], $rest->error['message']), E_USER_WARNING);
|
658 |
+
return false;
|
659 |
+
}
|
660 |
+
return true;
|
661 |
+
}
|
662 |
+
|
663 |
+
|
664 |
+
/**
|
665 |
+
* Get object or bucket Access Control Policy
|
666 |
+
*
|
667 |
+
* @param string $bucket Bucket name
|
668 |
+
* @param string $uri Object URI
|
669 |
+
* @return mixed | false
|
670 |
+
*/
|
671 |
+
public static function getAccessControlPolicy($bucket, $uri = '') {
|
672 |
+
$rest = new S3Request('GET', $bucket, $uri);
|
673 |
+
$rest->setParameter('acl', null);
|
674 |
+
$rest = $rest->getResponse();
|
675 |
+
if ($rest->error === false && $rest->code !== 200)
|
676 |
+
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
|
677 |
+
if ($rest->error !== false) {
|
678 |
+
trigger_error(sprintf("S3::getAccessControlPolicy({$bucket}, {$uri}): [%s] %s",
|
679 |
+
$rest->error['code'], $rest->error['message']), E_USER_WARNING);
|
680 |
+
return false;
|
681 |
+
}
|
682 |
+
|
683 |
+
$acp = array();
|
684 |
+
if (isset($rest->body->Owner, $rest->body->Owner->ID, $rest->body->Owner->DisplayName)) {
|
685 |
+
$acp['owner'] = array(
|
686 |
+
'id' => (string)$rest->body->Owner->ID, 'name' => (string)$rest->body->Owner->DisplayName
|
687 |
+
);
|
688 |
+
}
|
689 |
+
if (isset($rest->body->AccessControlList)) {
|
690 |
+
$acp['acl'] = array();
|
691 |
+
foreach ($rest->body->AccessControlList->Grant as $grant) {
|
692 |
+
foreach ($grant->Grantee as $grantee) {
|
693 |
+
if (isset($grantee->ID, $grantee->DisplayName)) // CanonicalUser
|
694 |
+
$acp['acl'][] = array(
|
695 |
+
'type' => 'CanonicalUser',
|
696 |
+
'id' => (string)$grantee->ID,
|
697 |
+
'name' => (string)$grantee->DisplayName,
|
698 |
+
'permission' => (string)$grant->Permission
|
699 |
+
);
|
700 |
+
elseif (isset($grantee->EmailAddress)) // AmazonCustomerByEmail
|
701 |
+
$acp['acl'][] = array(
|
702 |
+
'type' => 'AmazonCustomerByEmail',
|
703 |
+
'email' => (string)$grantee->EmailAddress,
|
704 |
+
'permission' => (string)$grant->Permission
|
705 |
+
);
|
706 |
+
elseif (isset($grantee->URI)) // Group
|
707 |
+
$acp['acl'][] = array(
|
708 |
+
'type' => 'Group',
|
709 |
+
'uri' => (string)$grantee->URI,
|
710 |
+
'permission' => (string)$grant->Permission
|
711 |
+
);
|
712 |
+
else continue;
|
713 |
+
}
|
714 |
+
}
|
715 |
+
}
|
716 |
+
return $acp;
|
717 |
+
}
|
718 |
+
|
719 |
+
|
720 |
+
/**
|
721 |
+
* Delete an object
|
722 |
+
*
|
723 |
+
* @param string $bucket Bucket name
|
724 |
+
* @param string $uri Object URI
|
725 |
+
* @return boolean
|
726 |
+
*/
|
727 |
+
public static function deleteObject($bucket, $uri) {
|
728 |
+
$rest = new S3Request('DELETE', $bucket, $uri);
|
729 |
+
$rest = $rest->getResponse();
|
730 |
+
if ($rest->error === false && $rest->code !== 204)
|
731 |
+
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
|
732 |
+
if ($rest->error !== false) {
|
733 |
+
trigger_error(sprintf("S3::deleteObject(): [%s] %s",
|
734 |
+
$rest->error['code'], $rest->error['message']), E_USER_WARNING);
|
735 |
+
return false;
|
736 |
+
}
|
737 |
+
return true;
|
738 |
+
}
|
739 |
+
|
740 |
+
|
741 |
+
/**
|
742 |
+
* Get a query string authenticated URL
|
743 |
+
*
|
744 |
+
* @param string $bucket Bucket name
|
745 |
+
* @param string $uri Object URI
|
746 |
+
* @param integer $lifetime Lifetime in seconds
|
747 |
+
* @param boolean $hostBucket Use the bucket name as the hostname
|
748 |
+
* @param boolean $https Use HTTPS ($hostBucket should be false for SSL verification)
|
749 |
+
* @return string
|
750 |
+
*/
|
751 |
+
public static function getAuthenticatedURL($bucket, $uri, $lifetime, $hostBucket = false, $https = false) {
|
752 |
+
$expires = time() + $lifetime;
|
753 |
+
$uri = str_replace('%2F', '/', rawurlencode($uri)); // URI should be encoded (thanks Sean O'Dea)
|
754 |
+
return sprintf(($https ? 'https' : 'http').'://%s/%s?AWSAccessKeyId=%s&Expires=%u&Signature=%s',
|
755 |
+
$hostBucket ? $bucket : $bucket.'.s3.amazonaws.com', $uri, self::$__accessKey, $expires,
|
756 |
+
urlencode(self::__getHash("GET\n\n\n{$expires}\n/{$bucket}/{$uri}")));
|
757 |
+
}
|
758 |
+
|
759 |
+
/**
|
760 |
+
* Get upload POST parameters for form uploads
|
761 |
+
*
|
762 |
+
* @param string $bucket Bucket name
|
763 |
+
* @param string $uriPrefix Object URI prefix
|
764 |
+
* @param constant $acl ACL constant
|
765 |
+
* @param integer $lifetime Lifetime in seconds
|
766 |
+
* @param integer $maxFileSize Maximum filesize in bytes (default 5MB)
|
767 |
+
* @param string $successRedirect Redirect URL or 200 / 201 status code
|
768 |
+
* @param array $amzHeaders Array of x-amz-meta-* headers
|
769 |
+
* @param array $headers Array of request headers or content type as a string
|
770 |
+
* @param boolean $flashVars Includes additional "Filename" variable posted by Flash
|
771 |
+
* @return object
|
772 |
+
*/
|
773 |
+
public static function getHttpUploadPostParams($bucket, $uriPrefix = '', $acl = self::ACL_PRIVATE, $lifetime = 3600, $maxFileSize = 5242880, $successRedirect = "201", $amzHeaders = array(), $headers = array(), $flashVars = false) {
|
774 |
+
// Create policy object
|
775 |
+
$policy = new stdClass;
|
776 |
+
$policy->expiration = gmdate('Y-m-d\TH:i:s\Z', (time() + $lifetime));
|
777 |
+
$policy->conditions = array();
|
778 |
+
$obj = new stdClass; $obj->bucket = $bucket; array_push($policy->conditions, $obj);
|
779 |
+
$obj = new stdClass; $obj->acl = $acl; array_push($policy->conditions, $obj);
|
780 |
+
|
781 |
+
$obj = new stdClass; // 200 for non-redirect uploads
|
782 |
+
if (is_numeric($successRedirect) && in_array((int)$successRedirect, array(200, 201)))
|
783 |
+
$obj->success_action_status = (string)$successRedirect;
|
784 |
+
else // URL
|
785 |
+
$obj->success_action_redirect = $successRedirect;
|
786 |
+
array_push($policy->conditions, $obj);
|
787 |
+
|
788 |
+
array_push($policy->conditions, array('starts-with', '$key', $uriPrefix));
|
789 |
+
if ($flashVars) array_push($policy->conditions, array('starts-with', '$Filename', ''));
|
790 |
+
foreach (array_keys($headers) as $headerKey)
|
791 |
+
array_push($policy->conditions, array('starts-with', '$'.$headerKey, ''));
|
792 |
+
foreach ($amzHeaders as $headerKey => $headerVal) {
|
793 |
+
$obj = new stdClass; $obj->{$headerKey} = (string)$headerVal; array_push($policy->conditions, $obj);
|
794 |
+
}
|
795 |
+
array_push($policy->conditions, array('content-length-range', 0, $maxFileSize));
|
796 |
+
$policy = base64_encode(str_replace('\/', '/', json_encode($policy)));
|
797 |
+
|
798 |
+
// Create parameters
|
799 |
+
$params = new stdClass;
|
800 |
+
$params->AWSAccessKeyId = self::$__accessKey;
|
801 |
+
$params->key = $uriPrefix.'${filename}';
|
802 |
+
$params->acl = $acl;
|
803 |
+
$params->policy = $policy; unset($policy);
|
804 |
+
$params->signature = self::__getHash($params->policy);
|
805 |
+
if (is_numeric($successRedirect) && in_array((int)$successRedirect, array(200, 201)))
|
806 |
+
$params->success_action_status = (string)$successRedirect;
|
807 |
+
else
|
808 |
+
$params->success_action_redirect = $successRedirect;
|
809 |
+
foreach ($headers as $headerKey => $headerVal) $params->{$headerKey} = (string)$headerVal;
|
810 |
+
foreach ($amzHeaders as $headerKey => $headerVal) $params->{$headerKey} = (string)$headerVal;
|
811 |
+
return $params;
|
812 |
+
}
|
813 |
+
|
814 |
+
/**
|
815 |
+
* Create a CloudFront distribution
|
816 |
+
*
|
817 |
+
* @param string $bucket Bucket name
|
818 |
+
* @param boolean $enabled Enabled (true/false)
|
819 |
+
* @param array $cnames Array containing CNAME aliases
|
820 |
+
* @param string $comment Use the bucket name as the hostname
|
821 |
+
* @return array | false
|
822 |
+
*/
|
823 |
+
public static function createDistribution($bucket, $enabled = true, $cnames = array(), $comment = '') {
|
824 |
+
self::$useSSL = true; // CloudFront requires SSL
|
825 |
+
$rest = new S3Request('POST', '', '2008-06-30/distribution', 'cloudfront.amazonaws.com');
|
826 |
+
$rest->data = self::__getCloudFrontDistributionConfigXML($bucket.'.s3.amazonaws.com', $enabled, $comment, (string)microtime(true), $cnames);
|
827 |
+
$rest->size = strlen($rest->data);
|
828 |
+
$rest->setHeader('Content-Type', 'application/xml');
|
829 |
+
$rest = self::__getCloudFrontResponse($rest);
|
830 |
+
|
831 |
+
if ($rest->error === false && $rest->code !== 201)
|
832 |
+
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
|
833 |
+
if ($rest->error !== false) {
|
834 |
+
trigger_error(sprintf("S3::createDistribution({$bucket}, ".(int)$enabled.", '$comment'): [%s] %s",
|
835 |
+
$rest->error['code'], $rest->error['message']), E_USER_WARNING);
|
836 |
+
return false;
|
837 |
+
} elseif ($rest->body instanceof SimpleXMLElement)
|
838 |
+
return self::__parseCloudFrontDistributionConfig($rest->body);
|
839 |
+
return false;
|
840 |
+
}
|
841 |
+
|
842 |
+
|
843 |
+
/**
|
844 |
+
* Get CloudFront distribution info
|
845 |
+
*
|
846 |
+
* @param string $distributionId Distribution ID from listDistributions()
|
847 |
+
* @return array | false
|
848 |
+
*/
|
849 |
+
public static function getDistribution($distributionId) {
|
850 |
+
self::$useSSL = true; // CloudFront requires SSL
|
851 |
+
$rest = new S3Request('GET', '', '2008-06-30/distribution/'.$distributionId, 'cloudfront.amazonaws.com');
|
852 |
+
$rest = self::__getCloudFrontResponse($rest);
|
853 |
+
|
854 |
+
if ($rest->error === false && $rest->code !== 200)
|
855 |
+
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
|
856 |
+
if ($rest->error !== false) {
|
857 |
+
trigger_error(sprintf("S3::getDistribution($distributionId): [%s] %s",
|
858 |
+
$rest->error['code'], $rest->error['message']), E_USER_WARNING);
|
859 |
+
return false;
|
860 |
+
} elseif ($rest->body instanceof SimpleXMLElement) {
|
861 |
+
$dist = self::__parseCloudFrontDistributionConfig($rest->body);
|
862 |
+
$dist['hash'] = $rest->headers['hash'];
|
863 |
+
return $dist;
|
864 |
+
}
|
865 |
+
return false;
|
866 |
+
}
|
867 |
+
|
868 |
+
|
869 |
+
/**
|
870 |
+
* Update a CloudFront distribution
|
871 |
+
*
|
872 |
+
* @param array $dist Distribution array info identical to output of getDistribution()
|
873 |
+
* @return array | false
|
874 |
+
*/
|
875 |
+
public static function updateDistribution($dist) {
|
876 |
+
self::$useSSL = true; // CloudFront requires SSL
|
877 |
+
$rest = new S3Request('PUT', '', '2008-06-30/distribution/'.$dist['id'].'/config', 'cloudfront.amazonaws.com');
|
878 |
+
$rest->data = self::__getCloudFrontDistributionConfigXML($dist['origin'], $dist['enabled'], $dist['comment'], $dist['callerReference'], $dist['cnames']);
|
879 |
+
$rest->size = strlen($rest->data);
|
880 |
+
$rest->setHeader('If-Match', $dist['hash']);
|
881 |
+
$rest = self::__getCloudFrontResponse($rest);
|
882 |
+
|
883 |
+
if ($rest->error === false && $rest->code !== 200)
|
884 |
+
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
|
885 |
+
if ($rest->error !== false) {
|
886 |
+
trigger_error(sprintf("S3::updateDistribution({$dist['id']}, ".(int)$enabled.", '$comment'): [%s] %s",
|
887 |
+
$rest->error['code'], $rest->error['message']), E_USER_WARNING);
|
888 |
+
return false;
|
889 |
+
} else {
|
890 |
+
$dist = self::__parseCloudFrontDistributionConfig($rest->body);
|
891 |
+
$dist['hash'] = $rest->headers['hash'];
|
892 |
+
return $dist;
|
893 |
+
}
|
894 |
+
return false;
|
895 |
+
}
|
896 |
+
|
897 |
+
|
898 |
+
/**
|
899 |
+
* Delete a CloudFront distribution
|
900 |
+
*
|
901 |
+
* @param array $dist Distribution array info identical to output of getDistribution()
|
902 |
+
* @return boolean
|
903 |
+
*/
|
904 |
+
public static function deleteDistribution($dist) {
|
905 |
+
self::$useSSL = true; // CloudFront requires SSL
|
906 |
+
$rest = new S3Request('DELETE', '', '2008-06-30/distribution/'.$dist['id'], 'cloudfront.amazonaws.com');
|
907 |
+
$rest->setHeader('If-Match', $dist['hash']);
|
908 |
+
$rest = self::__getCloudFrontResponse($rest);
|
909 |
+
|
910 |
+
if ($rest->error === false && $rest->code !== 204)
|
911 |
+
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
|
912 |
+
if ($rest->error !== false) {
|
913 |
+
trigger_error(sprintf("S3::deleteDistribution({$dist['id']}): [%s] %s",
|
914 |
+
$rest->error['code'], $rest->error['message']), E_USER_WARNING);
|
915 |
+
return false;
|
916 |
+
}
|
917 |
+
return true;
|
918 |
+
}
|
919 |
+
|
920 |
+
|
921 |
+
/**
|
922 |
+
* Get a list of CloudFront distributions
|
923 |
+
*
|
924 |
+
* @return array
|
925 |
+
*/
|
926 |
+
public static function listDistributions() {
|
927 |
+
self::$useSSL = true; // CloudFront requires SSL
|
928 |
+
$rest = new S3Request('GET', '', '2008-06-30/distribution', 'cloudfront.amazonaws.com');
|
929 |
+
$rest = self::__getCloudFrontResponse($rest);
|
930 |
+
|
931 |
+
if ($rest->error === false && $rest->code !== 200)
|
932 |
+
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
|
933 |
+
if ($rest->error !== false) {
|
934 |
+
trigger_error(sprintf("S3::listDistributions(): [%s] %s",
|
935 |
+
$rest->error['code'], $rest->error['message']), E_USER_WARNING);
|
936 |
+
return false;
|
937 |
+
} elseif ($rest->body instanceof SimpleXMLElement && isset($rest->body->DistributionSummary)) {
|
938 |
+
$list = array();
|
939 |
+
if (isset($rest->body->Marker, $rest->body->MaxItems, $rest->body->IsTruncated)) {
|
940 |
+
//$info['marker'] = (string)$rest->body->Marker;
|
941 |
+
//$info['maxItems'] = (int)$rest->body->MaxItems;
|
942 |
+
//$info['isTruncated'] = (string)$rest->body->IsTruncated == 'true' ? true : false;
|
943 |
+
}
|
944 |
+
foreach ($rest->body->DistributionSummary as $summary) {
|
945 |
+
$list[(string)$summary->Id] = self::__parseCloudFrontDistributionConfig($summary);
|
946 |
+
}
|
947 |
+
return $list;
|
948 |
+
}
|
949 |
+
return array();
|
950 |
+
}
|
951 |
+
|
952 |
+
|
953 |
+
/**
|
954 |
+
* Get a DistributionConfig DOMDocument
|
955 |
+
*
|
956 |
+
* @internal Used to create XML in createDistribution() and updateDistribution()
|
957 |
+
* @param string $bucket Origin bucket
|
958 |
+
* @param boolean $enabled Enabled (true/false)
|
959 |
+
* @param string $comment Comment to append
|
960 |
+
* @param string $callerReference Caller reference
|
961 |
+
* @param array $cnames Array of CNAME aliases
|
962 |
+
* @return string
|
963 |
+
*/
|
964 |
+
private static function __getCloudFrontDistributionConfigXML($bucket, $enabled, $comment, $callerReference = '0', $cnames = array()) {
|
965 |
+
$dom = new DOMDocument('1.0', 'UTF-8');
|
966 |
+
$dom->formatOutput = true;
|
967 |
+
$distributionConfig = $dom->createElement('DistributionConfig');
|
968 |
+
$distributionConfig->setAttribute('xmlns', 'http://cloudfront.amazonaws.com/doc/2008-06-30/');
|
969 |
+
$distributionConfig->appendChild($dom->createElement('Origin', $bucket));
|
970 |
+
$distributionConfig->appendChild($dom->createElement('CallerReference', $callerReference));
|
971 |
+
foreach ($cnames as $cname)
|
972 |
+
$distributionConfig->appendChild($dom->createElement('CNAME', $cname));
|
973 |
+
if ($comment !== '') $distributionConfig->appendChild($dom->createElement('Comment', $comment));
|
974 |
+
$distributionConfig->appendChild($dom->createElement('Enabled', $enabled ? 'true' : 'false'));
|
975 |
+
$dom->appendChild($distributionConfig);
|
976 |
+
return $dom->saveXML();
|
977 |
+
}
|
978 |
+
|
979 |
+
|
980 |
+
/**
|
981 |
+
* Parse a CloudFront distribution config
|
982 |
+
*
|
983 |
+
* @internal Used to parse the CloudFront DistributionConfig node to an array
|
984 |
+
* @param object &$node DOMNode
|
985 |
+
* @return array
|
986 |
+
*/
|
987 |
+
private static function __parseCloudFrontDistributionConfig(&$node) {
|
988 |
+
$dist = array();
|
989 |
+
if (isset($node->Id, $node->Status, $node->LastModifiedTime, $node->DomainName)) {
|
990 |
+
$dist['id'] = (string)$node->Id;
|
991 |
+
$dist['status'] = (string)$node->Status;
|
992 |
+
$dist['time'] = strtotime((string)$node->LastModifiedTime);
|
993 |
+
$dist['domain'] = (string)$node->DomainName;
|
994 |
+
}
|
995 |
+
if (isset($node->CallerReference))
|
996 |
+
$dist['callerReference'] = (string)$node->CallerReference;
|
997 |
+
if (isset($node->Comment))
|
998 |
+
$dist['comment'] = (string)$node->Comment;
|
999 |
+
if (isset($node->Enabled, $node->Origin)) {
|
1000 |
+
$dist['origin'] = (string)$node->Origin;
|
1001 |
+
$dist['enabled'] = (string)$node->Enabled == 'true' ? true : false;
|
1002 |
+
} elseif (isset($node->DistributionConfig)) {
|
1003 |
+
$dist = array_merge($dist, self::__parseCloudFrontDistributionConfig($node->DistributionConfig));
|
1004 |
+
}
|
1005 |
+
if (isset($node->CNAME)) {
|
1006 |
+
$dist['cnames'] = array();
|
1007 |
+
foreach ($node->CNAME as $cname) $dist['cnames'][(string)$cname] = (string)$cname;
|
1008 |
+
}
|
1009 |
+
return $dist;
|
1010 |
+
}
|
1011 |
+
|
1012 |
+
|
1013 |
+
/**
|
1014 |
+
* Grab CloudFront response
|
1015 |
+
*
|
1016 |
+
* @internal Used to parse the CloudFront S3Request::getResponse() output
|
1017 |
+
* @param object &$rest S3Request instance
|
1018 |
+
* @return object
|
1019 |
+
*/
|
1020 |
+
private static function __getCloudFrontResponse(&$rest) {
|
1021 |
+
$rest->getResponse();
|
1022 |
+
if ($rest->response->error === false && isset($rest->response->body) &&
|
1023 |
+
is_string($rest->response->body) && substr($rest->response->body, 0, 5) == '<?xml') {
|
1024 |
+
$rest->response->body = simplexml_load_string($rest->response->body);
|
1025 |
+
// Grab CloudFront errors
|
1026 |
+
if (isset($rest->response->body->Error, $rest->response->body->Error->Code,
|
1027 |
+
$rest->response->body->Error->Message)) {
|
1028 |
+
$rest->response->error = array(
|
1029 |
+
'code' => (string)$rest->response->body->Error->Code,
|
1030 |
+
'message' => (string)$rest->response->body->Error->Message
|
1031 |
+
);
|
1032 |
+
unset($rest->response->body);
|
1033 |
+
}
|
1034 |
+
}
|
1035 |
+
return $rest->response;
|
1036 |
+
}
|
1037 |
+
|
1038 |
+
|
1039 |
+
/**
|
1040 |
+
* Get MIME type for file
|
1041 |
+
*
|
1042 |
+
* @internal Used to get mime types
|
1043 |
+
* @param string &$file File path
|
1044 |
+
* @return string
|
1045 |
+
*/
|
1046 |
+
public static function __getMimeType(&$file) {
|
1047 |
+
$type = false;
|
1048 |
+
// Fileinfo documentation says fileinfo_open() will use the
|
1049 |
+
// MAGIC env var for the magic file
|
1050 |
+
if (extension_loaded('fileinfo') && isset($_ENV['MAGIC']) &&
|
1051 |
+
($finfo = finfo_open(FILEINFO_MIME, $_ENV['MAGIC'])) !== false) {
|
1052 |
+
if (($type = finfo_file($finfo, $file)) !== false) {
|
1053 |
+
// Remove the charset and grab the last content-type
|
1054 |
+
$type = explode(' ', str_replace('; charset=', ';charset=', $type));
|
1055 |
+
$type = array_pop($type);
|
1056 |
+
$type = explode(';', $type);
|
1057 |
+
$type = trim(array_shift($type));
|
1058 |
+
}
|
1059 |
+
finfo_close($finfo);
|
1060 |
+
|
1061 |
+
// If anyone is still using mime_content_type()
|
1062 |
+
} elseif (function_exists('mime_content_type'))
|
1063 |
+
$type = trim(mime_content_type($file));
|
1064 |
+
|
1065 |
+
if ($type !== false && strlen($type) > 0) return $type;
|
1066 |
+
|
1067 |
+
// Otherwise do it the old fashioned way
|
1068 |
+
static $exts = array(
|
1069 |
+
'jpg' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png',
|
1070 |
+
'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'ico' => 'image/x-icon',
|
1071 |
+
'swf' => 'application/x-shockwave-flash', 'pdf' => 'application/pdf',
|
1072 |
+
'zip' => 'application/zip', 'gz' => 'application/x-gzip',
|
1073 |
+
'tar' => 'application/x-tar', 'bz' => 'application/x-bzip',
|
1074 |
+
'bz2' => 'application/x-bzip2', 'txt' => 'text/plain',
|
1075 |
+
'asc' => 'text/plain', 'htm' => 'text/html', 'html' => 'text/html',
|
1076 |
+
'css' => 'text/css', 'js' => 'text/javascript',
|
1077 |
+
'xml' => 'text/xml', 'xsl' => 'application/xsl+xml',
|
1078 |
+
'ogg' => 'application/ogg', 'mp3' => 'audio/mpeg', 'wav' => 'audio/x-wav',
|
1079 |
+
'avi' => 'video/x-msvideo', 'mpg' => 'video/mpeg', 'mpeg' => 'video/mpeg',
|
1080 |
+
'mov' => 'video/quicktime', 'flv' => 'video/x-flv', 'php' => 'text/x-php'
|
1081 |
+
);
|
1082 |
+
$ext = strtolower(pathInfo($file, PATHINFO_EXTENSION));
|
1083 |
+
return isset($exts[$ext]) ? $exts[$ext] : 'application/octet-stream';
|
1084 |
+
}
|
1085 |
+
|
1086 |
+
|
1087 |
+
/**
|
1088 |
+
* Generate the auth string: "AWS AccessKey:Signature"
|
1089 |
+
*
|
1090 |
+
* @internal Used by S3Request::getResponse()
|
1091 |
+
* @param string $string String to sign
|
1092 |
+
* @return string
|
1093 |
+
*/
|
1094 |
+
public static function __getSignature($string) {
|
1095 |
+
return 'AWS '.self::$__accessKey.':'.self::__getHash($string);
|
1096 |
+
}
|
1097 |
+
|
1098 |
+
|
1099 |
+
/**
|
1100 |
+
* Creates a HMAC-SHA1 hash
|
1101 |
+
*
|
1102 |
+
* This uses the hash extension if loaded
|
1103 |
+
*
|
1104 |
+
* @internal Used by __getSignature()
|
1105 |
+
* @param string $string String to sign
|
1106 |
+
* @return string
|
1107 |
+
*/
|
1108 |
+
private static function __getHash($string) {
|
1109 |
+
return base64_encode(extension_loaded('hash') ?
|
1110 |
+
hash_hmac('sha1', $string, self::$__secretKey, true) : pack('H*', sha1(
|
1111 |
+
(str_pad(self::$__secretKey, 64, chr(0x00)) ^ (str_repeat(chr(0x5c), 64))) .
|
1112 |
+
pack('H*', sha1((str_pad(self::$__secretKey, 64, chr(0x00)) ^
|
1113 |
+
(str_repeat(chr(0x36), 64))) . $string)))));
|
1114 |
+
}
|
1115 |
+
|
1116 |
+
}
|
1117 |
+
|
1118 |
+
final class S3Request {
|
1119 |
+
private $verb, $bucket, $uri, $resource = '', $parameters = array(),
|
1120 |
+
$amzHeaders = array(), $headers = array(
|
1121 |
+
'Host' => '', 'Date' => '', 'Content-MD5' => '', 'Content-Type' => ''
|
1122 |
+
);
|
1123 |
+
public $fp = false, $size = 0, $data = false, $response;
|
1124 |
+
|
1125 |
+
|
1126 |
+
/**
|
1127 |
+
* Constructor
|
1128 |
+
*
|
1129 |
+
* @param string $verb Verb
|
1130 |
+
* @param string $bucket Bucket name
|
1131 |
+
* @param string $uri Object URI
|
1132 |
+
* @return mixed
|
1133 |
+
*/
|
1134 |
+
function __construct($verb, $bucket = '', $uri = '', $defaultHost = 's3.amazonaws.com') {
|
1135 |
+
$this->verb = $verb;
|
1136 |
+
$this->bucket = strtolower($bucket);
|
1137 |
+
$this->uri = $uri !== '' ? '/'.str_replace('%2F', '/', rawurlencode($uri)) : '/';
|
1138 |
+
|
1139 |
+
if ($this->bucket !== '') {
|
1140 |
+
$this->headers['Host'] = $this->bucket.'.'.$defaultHost;
|
1141 |
+
$this->resource = '/'.$this->bucket.$this->uri;
|
1142 |
+
} else {
|
1143 |
+
$this->headers['Host'] = $defaultHost;
|
1144 |
+
//$this->resource = strlen($this->uri) > 1 ? '/'.$this->bucket.$this->uri : $this->uri;
|
1145 |
+
$this->resource = $this->uri;
|
1146 |
+
}
|
1147 |
+
$this->headers['Date'] = gmdate('D, d M Y H:i:s T');
|
1148 |
+
|
1149 |
+
$this->response = new STDClass;
|
1150 |
+
$this->response->error = false;
|
1151 |
+
}
|
1152 |
+
|
1153 |
+
|
1154 |
+
/**
|
1155 |
+
* Set request parameter
|
1156 |
+
*
|
1157 |
+
* @param string $key Key
|
1158 |
+
* @param string $value Value
|
1159 |
+
* @return void
|
1160 |
+
*/
|
1161 |
+
public function setParameter($key, $value) {
|
1162 |
+
$this->parameters[$key] = $value;
|
1163 |
+
}
|
1164 |
+
|
1165 |
+
|
1166 |
+
/**
|
1167 |
+
* Set request header
|
1168 |
+
*
|
1169 |
+
* @param string $key Key
|
1170 |
+
* @param string $value Value
|
1171 |
+
* @return void
|
1172 |
+
*/
|
1173 |
+
public function setHeader($key, $value) {
|
1174 |
+
$this->headers[$key] = $value;
|
1175 |
+
}
|
1176 |
+
|
1177 |
+
|
1178 |
+
/**
|
1179 |
+
* Set x-amz-meta-* header
|
1180 |
+
*
|
1181 |
+
* @param string $key Key
|
1182 |
+
* @param string $value Value
|
1183 |
+
* @return void
|
1184 |
+
*/
|
1185 |
+
public function setAmzHeader($key, $value) {
|
1186 |
+
$this->amzHeaders[$key] = $value;
|
1187 |
+
}
|
1188 |
+
|
1189 |
+
|
1190 |
+
/**
|
1191 |
+
* Get the S3 response
|
1192 |
+
*
|
1193 |
+
* @return object | false
|
1194 |
+
*/
|
1195 |
+
public function getResponse() {
|
1196 |
+
$query = '';
|
1197 |
+
if (sizeof($this->parameters) > 0) {
|
1198 |
+
$query = substr($this->uri, -1) !== '?' ? '?' : '&';
|
1199 |
+
foreach ($this->parameters as $var => $value)
|
1200 |
+
if ($value == null || $value == '') $query .= $var.'&';
|
1201 |
+
// Parameters should be encoded (thanks Sean O'Dea)
|
1202 |
+
else $query .= $var.'='.rawurlencode($value).'&';
|
1203 |
+
$query = substr($query, 0, -1);
|
1204 |
+
$this->uri .= $query;
|
1205 |
+
|
1206 |
+
if (array_key_exists('acl', $this->parameters) ||
|
1207 |
+
array_key_exists('location', $this->parameters) ||
|
1208 |
+
array_key_exists('torrent', $this->parameters) ||
|
1209 |
+
array_key_exists('logging', $this->parameters))
|
1210 |
+
$this->resource .= $query;
|
1211 |
+
}
|
1212 |
+
$url = ((S3::$useSSL && extension_loaded('openssl')) ?
|
1213 |
+
'https://':'http://').$this->headers['Host'].$this->uri;
|
1214 |
+
//var_dump($this->bucket, $this->uri, $this->resource, $url);
|
1215 |
+
|
1216 |
+
// Basic setup
|
1217 |
+
$curl = curl_init();
|
1218 |
+
curl_setopt($curl, CURLOPT_USERAGENT, 'S3/php');
|
1219 |
+
|
1220 |
+
if (S3::$useSSL) {
|
1221 |
+
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
|
1222 |
+
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1);
|
1223 |
+
}
|
1224 |
+
|
1225 |
+
curl_setopt($curl, CURLOPT_URL, $url);
|
1226 |
+
|
1227 |
+
// Headers
|
1228 |
+
$headers = array(); $amz = array();
|
1229 |
+
foreach ($this->amzHeaders as $header => $value)
|
1230 |
+
if (strlen($value) > 0) $headers[] = $header.': '.$value;
|
1231 |
+
foreach ($this->headers as $header => $value)
|
1232 |
+
if (strlen($value) > 0) $headers[] = $header.': '.$value;
|
1233 |
+
|
1234 |
+
// Collect AMZ headers for signature
|
1235 |
+
foreach ($this->amzHeaders as $header => $value)
|
1236 |
+
if (strlen($value) > 0) $amz[] = strtolower($header).':'.$value;
|
1237 |
+
|
1238 |
+
// AMZ headers must be sorted
|
1239 |
+
if (sizeof($amz) > 0) {
|
1240 |
+
sort($amz);
|
1241 |
+
$amz = "\n".implode("\n", $amz);
|
1242 |
+
} else $amz = '';
|
1243 |
+
|
1244 |
+
// Authorization string (CloudFront stringToSign should only contain a date)
|
1245 |
+
$headers[] = 'Authorization: ' . S3::__getSignature(
|
1246 |
+
$this->headers['Host'] == 'cloudfront.amazonaws.com' ? $this->headers['Date'] :
|
1247 |
+
$this->verb."\n".$this->headers['Content-MD5']."\n".
|
1248 |
+
$this->headers['Content-Type']."\n".$this->headers['Date'].$amz."\n".$this->resource
|
1249 |
+
);
|
1250 |
+
|
1251 |
+
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
1252 |
+
curl_setopt($curl, CURLOPT_HEADER, false);
|
1253 |
+
curl_setopt($curl, CURLOPT_RETURNTRANSFER, false);
|
1254 |
+
curl_setopt($curl, CURLOPT_WRITEFUNCTION, array(&$this, '__responseWriteCallback'));
|
1255 |
+
curl_setopt($curl, CURLOPT_HEADERFUNCTION, array(&$this, '__responseHeaderCallback'));
|
1256 |
+
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
1257 |
+
|
1258 |
+
// Request types
|
1259 |
+
switch ($this->verb) {
|
1260 |
+
case 'GET': break;
|
1261 |
+
case 'PUT': case 'POST': // POST only used for CloudFront
|
1262 |
+
if ($this->fp !== false) {
|
1263 |
+
curl_setopt($curl, CURLOPT_PUT, true);
|
1264 |
+
curl_setopt($curl, CURLOPT_INFILE, $this->fp);
|
1265 |
+
if ($this->size >= 0)
|
1266 |
+
curl_setopt($curl, CURLOPT_INFILESIZE, $this->size);
|
1267 |
+
} elseif ($this->data !== false) {
|
1268 |
+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $this->verb);
|
1269 |
+
curl_setopt($curl, CURLOPT_POSTFIELDS, $this->data);
|
1270 |
+
if ($this->size >= 0)
|
1271 |
+
curl_setopt($curl, CURLOPT_BUFFERSIZE, $this->size);
|
1272 |
+
} else
|
1273 |
+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $this->verb);
|
1274 |
+
break;
|
1275 |
+
case 'HEAD':
|
1276 |
+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'HEAD');
|
1277 |
+
curl_setopt($curl, CURLOPT_NOBODY, true);
|
1278 |
+
break;
|
1279 |
+
case 'DELETE':
|
1280 |
+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
|
1281 |
+
break;
|
1282 |
+
default: break;
|
1283 |
+
}
|
1284 |
+
|
1285 |
+
// Execute, grab errors
|
1286 |
+
if (curl_exec($curl))
|
1287 |
+
$this->response->code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
1288 |
+
else
|
1289 |
+
$this->response->error = array(
|
1290 |
+
'code' => curl_errno($curl),
|
1291 |
+
'message' => curl_error($curl),
|
1292 |
+
'resource' => $this->resource
|
1293 |
+
);
|
1294 |
+
|
1295 |
+
@curl_close($curl);
|
1296 |
+
|
1297 |
+
// Parse body into XML
|
1298 |
+
if ($this->response->error === false && isset($this->response->headers['type']) &&
|
1299 |
+
$this->response->headers['type'] == 'application/xml' && isset($this->response->body)) {
|
1300 |
+
$this->response->body = simplexml_load_string($this->response->body);
|
1301 |
+
|
1302 |
+
// Grab S3 errors
|
1303 |
+
if (!in_array($this->response->code, array(200, 204)) &&
|
1304 |
+
isset($this->response->body->Code, $this->response->body->Message)) {
|
1305 |
+
$this->response->error = array(
|
1306 |
+
'code' => (string)$this->response->body->Code,
|
1307 |
+
'message' => (string)$this->response->body->Message
|
1308 |
+
);
|
1309 |
+
if (isset($this->response->body->Resource))
|
1310 |
+
$this->response->error['resource'] = (string)$this->response->body->Resource;
|
1311 |
+
unset($this->response->body);
|
1312 |
+
}
|
1313 |
+
}
|
1314 |
+
|
1315 |
+
// Clean up file resources
|
1316 |
+
if ($this->fp !== false && is_resource($this->fp)) fclose($this->fp);
|
1317 |
+
|
1318 |
+
return $this->response;
|
1319 |
+
}
|
1320 |
+
|
1321 |
+
|
1322 |
+
/**
|
1323 |
+
* CURL write callback
|
1324 |
+
*
|
1325 |
+
* @param resource &$curl CURL resource
|
1326 |
+
* @param string &$data Data
|
1327 |
+
* @return integer
|
1328 |
+
*/
|
1329 |
+
private function __responseWriteCallback(&$curl, &$data) {
|
1330 |
+
if ($this->response->code == 200 && $this->fp !== false)
|
1331 |
+
return fwrite($this->fp, $data);
|
1332 |
+
else
|
1333 |
+
$this->response->body .= $data;
|
1334 |
+
return strlen($data);
|
1335 |
+
}
|
1336 |
+
|
1337 |
+
|
1338 |
+
/**
|
1339 |
+
* CURL header callback
|
1340 |
+
*
|
1341 |
+
* @param resource &$curl CURL resource
|
1342 |
+
* @param string &$data Data
|
1343 |
+
* @return integer
|
1344 |
+
*/
|
1345 |
+
private function __responseHeaderCallback(&$curl, &$data) {
|
1346 |
+
if (($strlen = strlen($data)) <= 2) return $strlen;
|
1347 |
+
if (substr($data, 0, 4) == 'HTTP')
|
1348 |
+
$this->response->code = (int)substr($data, 9, 3);
|
1349 |
+
else {
|
1350 |
+
list($header, $value) = explode(': ', trim($data), 2);
|
1351 |
+
if ($header == 'Last-Modified')
|
1352 |
+
$this->response->headers['time'] = strtotime($value);
|
1353 |
+
elseif ($header == 'Content-Length')
|
1354 |
+
$this->response->headers['size'] = (int)$value;
|
1355 |
+
elseif ($header == 'Content-Type')
|
1356 |
+
$this->response->headers['type'] = $value;
|
1357 |
+
elseif ($header == 'ETag')
|
1358 |
+
$this->response->headers['hash'] = $value{0} == '"' ? substr($value, 1, -1) : $value;
|
1359 |
+
elseif (preg_match('/^x-amz-meta-.*$/', $header))
|
1360 |
+
$this->response->headers[$header] = is_numeric($value) ? (int)$value : $value;
|
1361 |
+
}
|
1362 |
+
return $strlen;
|
1363 |
+
}
|
1364 |
+
|
1365 |
+
}
|
app/options-jobs.php
CHANGED
@@ -155,21 +155,43 @@ echo '</select><br />';
|
|
155 |
</td>
|
156 |
</tr>
|
157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
<?PHP } ?>
|
159 |
|
160 |
-
|
|
|
|
|
|
|
|
|
161 |
<tr valign="top">
|
162 |
-
<th scope="row"><label for="mailaddress"><?PHP _e('Send Mail to','backwpup'); ?></label></th>
|
163 |
<td><input name="mailaddress" id="mailaddress" type="text" value="<?PHP echo $jobs[$jobid]['mailaddress'];?>" class="regular-text" /><br />
|
164 |
<?PHP
|
165 |
-
|
166 |
-
echo __('Max File Size for sending Backups with mail:','backwpup').'<input name="mailefilesize" type="text" value="'.$jobs[$jobid]['mailefilesize'].'" class="small-text" />MB <span class="description">'.__('0=send log only.','backwpup').'</span><br />';
|
167 |
-
}
|
168 |
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
<input class="checkbox" value="1" type="checkbox" <?php checked($jobs[$jobid]['mailerroronly'],true); ?> name="mailerroronly" /> <?PHP _e('Send only mail on errors.','backwpup'); ?>
|
170 |
</td>
|
171 |
</tr>
|
172 |
|
|
|
173 |
</table>
|
174 |
<p class="submit">
|
175 |
<input type="submit" name="Submit" class="button-primary" value="<?php _e('Save Changes', 'backwpup'); ?>" />
|
155 |
</td>
|
156 |
</tr>
|
157 |
|
158 |
+
<?PHP if (extension_loaded('curl') or @dl(PHP_SHLIB_SUFFIX == 'so' ? 'curl.so' : 'php_curl.dll')) {?>
|
159 |
+
<tr valign="top">
|
160 |
+
<th scope="row"><label for="ftptransfer"><?PHP _e('Backup to Amazon S3','backwpup'); ?></label></th>
|
161 |
+
<td id="ftptransfer">
|
162 |
+
<?PHP _e('Access Key ID:','backwpup'); ?><input name="awsAccessKey" type="text" value="<?PHP echo $jobs[$jobid]['awsAccessKey'];?>" class="regular-text" /><br />
|
163 |
+
<?PHP _e('Secret Access Key:','backwpup'); ?><input name="awsSecretKey" type="text" value="<?PHP echo $jobs[$jobid]['awsSecretKey'];?>" class="regular-text" /><br />
|
164 |
+
<input class="checkbox" value="1" type="checkbox" <?php checked($jobs[$jobid]['awsSSL'],true); ?> name="awsSSL" /> <?PHP _e('Use SSL connection.','backwpup'); ?><br />
|
165 |
+
<?PHP _e('Bucket:','backwpup'); ?><input name="awsBucket" type="text" value="<?PHP echo $jobs[$jobid]['awsBucket'];?>" class="regular-text" /><br />
|
166 |
+
<?PHP _e('Directory in Bucket:','backwpup'); ?><input name="awsdir" type="text" value="<?PHP echo $jobs[$jobid]['awsdir'];?>" class="regular-text" /><br />
|
167 |
+
<?PHP _e('Max Backup files on Bucket:','backwpup'); ?><input name="awsmaxbackups" type="text" value="<?PHP echo $jobs[$jobid]['awsmaxbackups'];?>" class="small-text" /><span class="description"><?PHP _e('0=off','backwpup');?></span><br />
|
168 |
+
</td>
|
169 |
+
</tr>
|
170 |
<?PHP } ?>
|
171 |
|
172 |
+
<?PHP } ?>
|
173 |
+
|
174 |
+
<?PHP
|
175 |
+
if ($jobs[$jobid]['type']=='FILE' or $jobs[$jobid]['type']=='DB' or $jobs[$jobid]['type']=='DB+FILE') {
|
176 |
+
?>
|
177 |
<tr valign="top">
|
178 |
+
<th scope="row"><label for="mailaddress"><?PHP _e('Send Backup with Mail to','backwpup'); ?></label></th>
|
179 |
<td><input name="mailaddress" id="mailaddress" type="text" value="<?PHP echo $jobs[$jobid]['mailaddress'];?>" class="regular-text" /><br />
|
180 |
<?PHP
|
181 |
+
echo __('Max File Size for sending Backups with mail:','backwpup').'<input name="mailefilesize" type="text" value="'.$jobs[$jobid]['mailefilesize'].'" class="small-text" />MB <span class="description">'.__('0=send log only.','backwpup').'</span><br />';
|
|
|
|
|
182 |
?>
|
183 |
+
</td>
|
184 |
+
</tr>
|
185 |
+
<?PHP } ?>
|
186 |
+
|
187 |
+
<tr valign="top">
|
188 |
+
<th scope="row"><label for="mailaddresslog"><?PHP _e('Send Log Mail to','backwpup'); ?></label></th>
|
189 |
+
<td><input name="mailaddresslog" id="mailaddresslog" type="text" value="<?PHP echo $jobs[$jobid]['mailaddresslog'];?>" class="regular-text" /><br />
|
190 |
<input class="checkbox" value="1" type="checkbox" <?php checked($jobs[$jobid]['mailerroronly'],true); ?> name="mailerroronly" /> <?PHP _e('Send only mail on errors.','backwpup'); ?>
|
191 |
</td>
|
192 |
</tr>
|
193 |
|
194 |
+
|
195 |
</table>
|
196 |
<p class="submit">
|
197 |
<input type="submit" name="Submit" class="button-primary" value="<?php _e('Save Changes', 'backwpup'); ?>" />
|
app/options-logs.php
CHANGED
@@ -31,95 +31,117 @@ if ( !defined('ABSPATH') )
|
|
31 |
|
32 |
<div class="clear"></div>
|
33 |
|
34 |
-
<table class="widefat
|
35 |
-
<thead>
|
36 |
-
<tr>
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
<
|
42 |
-
<
|
43 |
-
|
44 |
-
</tr>
|
45 |
-
</
|
46 |
-
|
47 |
-
<tfoot>
|
48 |
-
<tr>
|
49 |
-
<th scope="col" class="manage-column column-cb check-column" style=""><input type="checkbox" /></th>
|
50 |
-
<th scope="col" class="manage-column column-id" style=""><?PHP _e('Job','backwpup'); ?></th>
|
51 |
-
<th scope="col" class="manage-column column-type" style=""><?PHP _e('Type','backwpup'); ?></th>
|
52 |
-
<th scope="col" class="manage-column column-log" style=""><?PHP _e('Backup/Log Date/Time','backwpup'); ?></th>
|
53 |
-
<th scope="col" class="manage-column column-status" style=""><?PHP _e('Status','backwpup'); ?></th>
|
54 |
-
<th scope="col" class="manage-column column-size" style=""><?PHP _e('Size','backwpup'); ?></th>
|
55 |
-
<th scope="col" class="manage-column column-runtime" style=""><?PHP _e('Runtime','backwpup'); ?></th>
|
56 |
-
</tr>
|
57 |
-
</tfoot>
|
58 |
|
59 |
<tbody id="the-list" class="list:post">
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
$name='';
|
78 |
if (is_file($logvalue['backupfile']))
|
79 |
$name=basename($logvalue['backupfile']);
|
80 |
-
|
81 |
-
<strong><a href="
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
}
|
113 |
-
|
114 |
-
</
|
115 |
-
|
116 |
-
|
117 |
-
echo $logvalue['worktime'].' '.__('sec.','backwpup');
|
118 |
-
?>
|
119 |
-
</td>
|
120 |
-
</tr>
|
121 |
-
<?PHP }}?>
|
122 |
-
</tbody>
|
123 |
</table>
|
124 |
|
125 |
<div class="tablenav">
|
31 |
|
32 |
<div class="clear"></div>
|
33 |
|
34 |
+
<table class="widefat" cellspacing="0">
|
35 |
+
<thead>
|
36 |
+
<tr>
|
37 |
+
<?php print_column_headers('backwpup_options_logs'); ?>
|
38 |
+
</tr>
|
39 |
+
</thead>
|
40 |
+
|
41 |
+
<tfoot>
|
42 |
+
<tr>
|
43 |
+
<?php print_column_headers('backwpup_options_logs', false); ?>
|
44 |
+
</tr>
|
45 |
+
</tfoot>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
<tbody id="the-list" class="list:post">
|
48 |
|
49 |
+
<?php
|
50 |
+
$item_columns = get_column_headers('backwpup_options_logs');
|
51 |
+
$hidden = get_hidden_columns('backwpup_options_logs');
|
52 |
+
|
53 |
+
//get log files
|
54 |
+
$logfiles=array();
|
55 |
+
if ( $dir = @opendir( $cfg['dirlogs'] ) ) {
|
56 |
+
while (($file = readdir( $dir ) ) !== false ) {
|
57 |
+
if (is_file($cfg['dirlogs'].'/'.$file) and 'backwpup_log_' == substr($file,0,strlen('backwpup_log_')) and '.html' == substr($file,-5))
|
58 |
+
$logfiles[]=$file;
|
59 |
+
}
|
60 |
+
closedir( $dir );
|
61 |
+
rsort($logfiles);
|
62 |
+
}
|
63 |
+
|
64 |
+
|
65 |
+
foreach ($logfiles as $logfile) {
|
66 |
+
$logdata=backwpup_read_logheader($cfg['dirlogs'].'/'.$logfile);
|
67 |
+
?><tr id="<?PHP echo $logfile?>" valign="top"><?PHP
|
68 |
+
foreach($item_columns as $column_name=>$column_display_name) {
|
69 |
+
$class = "class=\"column-$column_name\"";
|
70 |
+
|
71 |
+
$style = '';
|
72 |
+
if ( in_array($column_name, $hidden) )
|
73 |
+
$style = ' style="display:none;"';
|
74 |
+
|
75 |
+
$attributes = "$class$style";
|
76 |
+
|
77 |
+
switch($column_name) {
|
78 |
+
case 'cb':
|
79 |
+
echo '<th scope="row" class="check-column"><input type="checkbox" name="logfiles[]" value="'. esc_attr($logfile) .'" /></th>';
|
80 |
+
break;
|
81 |
+
case 'id':
|
82 |
+
echo '<td $attributes>'.$logdata['jobid'].'</td>';
|
83 |
+
break;
|
84 |
+
case 'type':
|
85 |
+
echo '<td $attributes>';
|
86 |
+
echo $logdata['type'];
|
87 |
+
echo '</td>';
|
88 |
+
break;
|
89 |
+
case 'log':
|
90 |
$name='';
|
91 |
if (is_file($logvalue['backupfile']))
|
92 |
$name=basename($logvalue['backupfile']);
|
93 |
+
|
94 |
+
echo '<td $attributes><strong><a href="'.wp_nonce_url('admin.php?page=BackWPup&action=view_log&logfile='.$cfg['dirlogs'].'/'.$logfile, 'view-log_'.$logfile).'" title="'.__('View log','backwpup').'">'.date_i18n(get_option('date_format'),$logdata['logtime']).' '.date_i18n(get_option('time_format'),$logdata['logtime']).': <i>'.$logdata['name'].'</i></a></strong>';
|
95 |
+
$actions = array();
|
96 |
+
$actions['view'] = "<a href=\"" . wp_nonce_url('admin.php?page=BackWPup&action=view_log&logfile='.$cfg['dirlogs'].'/'.$logfile, 'view-log_'.$logfile) . "\">" . __('View','backwpup') . "</a>";
|
97 |
+
$actions['delete'] = "<a class=\"submitdelete\" href=\"" . wp_nonce_url('admin.php?page=BackWPup&action=delete-logs&logfile='.$logfile, 'delete-log_'.$logfile) . "\" onclick=\"if ( confirm('" . esc_js(__("You are about to delete this Job. \n 'Cancel' to stop, 'OK' to delete.","backwpup")) . "') ) { return true;}return false;\">" . __('Delete') . "</a>";
|
98 |
+
$actions['downloadlog'] = "<a class=\"submitdelete\" href=\"" . wp_nonce_url('admin.php?page=BackWPup&action=download&file='.$cfg['dirlogs'].'/'.$logfile, 'download-backup_'.$logfile) . "\">" . __('Download Log','backwpup') . "</a>";
|
99 |
+
if (!empty($logdata['backupfile']) and is_file($logdata['backupfile']))
|
100 |
+
$actions['downloadbackup'] = "<a class=\"submitdelete\" href=\"" . wp_nonce_url('admin.php?page=BackWPup&action=download&file='.$logdata['backupfile'], 'download-backup_'.basename($logdata['backupfile'])) . "\">" . __('Download Backup','backwpup') . "</a>";
|
101 |
+
$action_count = count($actions);
|
102 |
+
$i = 0;
|
103 |
+
echo '<br /><div class="row-actions">';
|
104 |
+
foreach ( $actions as $action => $linkaction ) {
|
105 |
+
++$i;
|
106 |
+
( $i == $action_count ) ? $sep = '' : $sep = ' | ';
|
107 |
+
echo "<span class='$action'>$linkaction$sep</span>";
|
108 |
+
}
|
109 |
+
echo '</div>';
|
110 |
+
echo '</td>';
|
111 |
+
break;
|
112 |
+
case 'status':
|
113 |
+
echo '<td $attributes>';
|
114 |
+
if($logdata['errors']>0 or $logdata['warnings']>0) {
|
115 |
+
if ($logdata['errors']>0)
|
116 |
+
echo '<span style="color:red;">'.$logdata['errors'].' '.__('ERROR(S)','backwpup').'</span><br />';
|
117 |
+
if ($logdata['warnings']>0)
|
118 |
+
echo '<span style="color:yellow;">'.$logdata['warnings'].' '.__('WARNING(S)','backwpup').'</span>';
|
119 |
+
} else {
|
120 |
+
echo '<span style="color:green;">'.__('OK','backwpup').'</span>';
|
121 |
+
}
|
122 |
+
echo '</td>';
|
123 |
+
break;
|
124 |
+
case 'size':
|
125 |
+
echo '<td $attributes>';
|
126 |
+
if (!empty($logdata['backupfile']) and is_file($logdata['backupfile'])) {
|
127 |
+
echo backwpup_formatBytes(filesize($logdata['backupfile']));
|
128 |
+
} elseif (!empty($logdata['backupfile'])) {
|
129 |
+
_e('File not exists','backwpup');
|
130 |
+
} else {
|
131 |
+
_e('only Log','backwpup');
|
132 |
+
}
|
133 |
+
echo '</td>';
|
134 |
+
break;
|
135 |
+
case 'runtime':
|
136 |
+
echo '<td $attributes>';
|
137 |
+
echo $logdata['runtime'].' '.__('sec.','backwpup');
|
138 |
+
echo '</td>';
|
139 |
+
break;
|
140 |
}
|
141 |
+
}
|
142 |
+
echo "\n </tr>\n";
|
143 |
+
}
|
144 |
+
?></tbody>
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
</table>
|
146 |
|
147 |
<div class="tablenav">
|
app/options-runnow-iframe.php
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?PHP
|
2 |
+
if ( !defined('ABSPATH') ) {
|
3 |
+
/** Setup WordPress environment */
|
4 |
+
require_once($_GET['ABSPATH'].'/wp-load.php');
|
5 |
+
|
6 |
+
|
7 |
+
check_admin_referer('dojob-now_' . (int)$_GET['jobid']);
|
8 |
+
ignore_user_abort(true);
|
9 |
+
// flush any buffers and send the headers
|
10 |
+
ob_start();
|
11 |
+
while (@ob_end_flush());
|
12 |
+
flush();
|
13 |
+
}
|
14 |
+
?>
|
15 |
+
<html>
|
16 |
+
<head>
|
17 |
+
<meta http-equiv="expires" content="0">
|
18 |
+
<title><?PHP _e('Do Job','backwpup'); ?></title>
|
19 |
+
</head>
|
20 |
+
<body style="font-family:monospace;font-size:12px;white-space:nowrap;">
|
21 |
+
<?PHP
|
22 |
+
backwpup_dojob($_GET['jobid']);
|
23 |
+
?>
|
24 |
+
</body>
|
25 |
+
</html>
|
app/options-runnow.php
CHANGED
@@ -17,5 +17,5 @@ if ( !defined('ABSPATH') )
|
|
17 |
_e('Running Job','backwpup');
|
18 |
echo ' <strong>'.$jobs[$jobid]['name'].'</strong>';
|
19 |
?></big>
|
20 |
-
<iframe src="<?PHP echo wp_nonce_url(WP_PLUGIN_URL.'/'.BACKWPUP_PLUGIN_DIR.'/app/iframe
|
21 |
</div>
|
17 |
_e('Running Job','backwpup');
|
18 |
echo ' <strong>'.$jobs[$jobid]['name'].'</strong>';
|
19 |
?></big>
|
20 |
+
<iframe src="<?PHP echo wp_nonce_url(WP_PLUGIN_URL.'/'.BACKWPUP_PLUGIN_DIR.'/app/options-runnow-iframe.php?ABSPATH='.ABSPATH.'&jobid=' . $jobid, 'dojob-now_' . $jobid); ?>" name="Logframe" id="Logframe" width="100%" height="450" align="left" scrolling="auto" style="border: 1px solid gray" frameborder="0"></iframe>
|
21 |
</div>
|
app/options-save.php
CHANGED
@@ -31,24 +31,20 @@ case 'delete': //Delete Job
|
|
31 |
$_REQUEST['action']='';
|
32 |
break;
|
33 |
case 'delete-logs': //Delete Log
|
34 |
-
|
|
|
35 |
check_admin_referer('actions-logs');
|
36 |
$num=0;
|
37 |
-
foreach ($_POST['
|
38 |
-
$
|
39 |
-
|
40 |
-
unlink($backupfile);
|
41 |
-
$wpdb->query("DELETE FROM ".$wpdb->backwpup_logs." WHERE logtime=".$timestamp);
|
42 |
$num++;
|
43 |
}
|
44 |
$backwpup_message=$num.' '.__('Logs deleted', 'backwpup');
|
45 |
} else {
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
if (is_file($backupfile))
|
50 |
-
unlink($backupfile);
|
51 |
-
$wpdb->query("DELETE FROM ".$wpdb->backwpup_logs." WHERE logtime=".$timestamp);
|
52 |
$backwpup_message=__('Log deleted', 'backwpup');
|
53 |
}
|
54 |
$_REQUEST['action']='logs';
|
@@ -56,6 +52,8 @@ case 'delete-logs': //Delete Log
|
|
56 |
case 'savecfg': //Save config form Setings page
|
57 |
check_admin_referer('backwpup-cfg');
|
58 |
$cfg=get_option('backwpup'); //Load Settings
|
|
|
|
|
59 |
$cfg['mailmethod']=$_POST['mailmethod'];
|
60 |
$cfg['mailsendmail']=str_replace('\\','/',stripslashes($_POST['mailsendmail']));
|
61 |
$cfg['mailsecure']=$_POST['mailsecure'];
|
@@ -63,9 +61,10 @@ case 'savecfg': //Save config form Setings page
|
|
63 |
$cfg['mailuser']=$_POST['mailuser'];
|
64 |
$cfg['mailpass']=base64_encode($_POST['mailpass']);
|
65 |
$cfg['memorylimit']=$_POST['memorylimit'];
|
66 |
-
$cfg['maxexecutiontime']=$_POST['maxexecutiontime'];
|
67 |
$cfg['disablewpcron']=$_POST['disablewpcron']==1 ? true : false;
|
68 |
$cfg['maxlogs']=abs((int)$_POST['maxlogs']);
|
|
|
|
|
69 |
if (update_option('backwpup',$cfg))
|
70 |
$backwpup_message=__('Settings saved', 'backwpup');
|
71 |
$_REQUEST['action']='settings';
|
@@ -87,20 +86,18 @@ case 'copy': //Copy Job
|
|
87 |
$_REQUEST['action']='';
|
88 |
break;
|
89 |
case 'download': //Download Backup
|
90 |
-
|
91 |
-
|
92 |
-
$backupfile=$wpdb->get_var("SELECT backupfile FROM ".$wpdb->backwpup_logs." WHERE logtime=".$log);
|
93 |
-
if (is_file($backupfile)) {
|
94 |
header("Pragma: public");
|
95 |
header("Expires: 0");
|
96 |
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
|
97 |
header("Content-Type: application/force-download");
|
98 |
header("Content-Type: application/octet-stream");
|
99 |
header("Content-Type: application/download");
|
100 |
-
header("Content-Disposition: attachment; filename=".basename($
|
101 |
header("Content-Transfer-Encoding: binary");
|
102 |
-
header("Content-Length: ".filesize($
|
103 |
-
@readfile($
|
104 |
} else {
|
105 |
header('HTTP/1.0 404 Not Found');
|
106 |
die(__('File does not exist.', 'backwpup'));
|
@@ -136,7 +133,7 @@ case 'saveeditjob': //Save Job settings
|
|
136 |
$jobs[$jobid]['scheduleintervaltype']=$_POST['scheduleintervaltype'];
|
137 |
$jobs[$jobid]['scheduleintervalteimes']=$_POST['scheduleintervalteimes'];
|
138 |
$jobs[$jobid]['scheduleinterval']=$_POST['scheduleintervaltype']*$_POST['scheduleintervalteimes'];
|
139 |
-
$jobs[$jobid]['
|
140 |
$jobs[$jobid]['mailerroronly']= $_POST['mailerroronly']==1 ? true : false;
|
141 |
|
142 |
if ($savetype=='DB' or $savetype=='DB+FILE' or $savetype=='OPTIMIZE' or $savetype=='CHECK') {
|
@@ -159,8 +156,17 @@ case 'saveeditjob': //Save Job settings
|
|
159 |
$jobs[$jobid]['ftphost']=$_POST['ftphost'];
|
160 |
$jobs[$jobid]['ftpuser']=$_POST['ftpuser'];
|
161 |
$jobs[$jobid]['ftppass']=base64_encode($_POST['ftppass']);
|
162 |
-
$jobs[$jobid]['ftpdir']=str_replace('\\','/',stripslashes($_POST['ftpdir']));
|
163 |
$jobs[$jobid]['ftpmaxbackups']=abs((int)$_POST['ftpmaxbackups']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
}
|
165 |
|
166 |
if (update_option('backwpup_jobs',$jobs))
|
31 |
$_REQUEST['action']='';
|
32 |
break;
|
33 |
case 'delete-logs': //Delete Log
|
34 |
+
$cfg=get_option('backwpup'); //Load Settings
|
35 |
+
if (is_Array($_POST['logfiles'])) {
|
36 |
check_admin_referer('actions-logs');
|
37 |
$num=0;
|
38 |
+
foreach ($_POST['logfiles'] as $logfile) {
|
39 |
+
if (is_file($cfg['dirlogs'].'/'.$logfile))
|
40 |
+
unlink($cfg['dirlogs'].'/'.$logfile);
|
|
|
|
|
41 |
$num++;
|
42 |
}
|
43 |
$backwpup_message=$num.' '.__('Logs deleted', 'backwpup');
|
44 |
} else {
|
45 |
+
check_admin_referer('delete-log_' . $_GET['logfile']);
|
46 |
+
if (is_file($cfg['dirlogs'].'/'.$_GET['logfile']))
|
47 |
+
unlink($cfg['dirlogs'].'/'.$_GET['logfile']);
|
|
|
|
|
|
|
48 |
$backwpup_message=__('Log deleted', 'backwpup');
|
49 |
}
|
50 |
$_REQUEST['action']='logs';
|
52 |
case 'savecfg': //Save config form Setings page
|
53 |
check_admin_referer('backwpup-cfg');
|
54 |
$cfg=get_option('backwpup'); //Load Settings
|
55 |
+
$cfg['mailsndemail']=sanitize_email($_POST['mailsndemail']);
|
56 |
+
$cfg['mailsndname']=$_POST['mailsndname'];
|
57 |
$cfg['mailmethod']=$_POST['mailmethod'];
|
58 |
$cfg['mailsendmail']=str_replace('\\','/',stripslashes($_POST['mailsendmail']));
|
59 |
$cfg['mailsecure']=$_POST['mailsecure'];
|
61 |
$cfg['mailuser']=$_POST['mailuser'];
|
62 |
$cfg['mailpass']=base64_encode($_POST['mailpass']);
|
63 |
$cfg['memorylimit']=$_POST['memorylimit'];
|
|
|
64 |
$cfg['disablewpcron']=$_POST['disablewpcron']==1 ? true : false;
|
65 |
$cfg['maxlogs']=abs((int)$_POST['maxlogs']);
|
66 |
+
$cfg['dirlogs']=untrailingslashit(str_replace('\\','/',stripslashes($_POST['dirlogs'])));
|
67 |
+
$cfg['dirtemp']=untrailingslashit(str_replace('\\','/',stripslashes($_POST['dirtemp'])));
|
68 |
if (update_option('backwpup',$cfg))
|
69 |
$backwpup_message=__('Settings saved', 'backwpup');
|
70 |
$_REQUEST['action']='settings';
|
86 |
$_REQUEST['action']='';
|
87 |
break;
|
88 |
case 'download': //Download Backup
|
89 |
+
check_admin_referer('download-backup_'.basename($_GET['file']));
|
90 |
+
if (is_file($_GET['file'])) {
|
|
|
|
|
91 |
header("Pragma: public");
|
92 |
header("Expires: 0");
|
93 |
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
|
94 |
header("Content-Type: application/force-download");
|
95 |
header("Content-Type: application/octet-stream");
|
96 |
header("Content-Type: application/download");
|
97 |
+
header("Content-Disposition: attachment; filename=".basename($_GET['file']).";");
|
98 |
header("Content-Transfer-Encoding: binary");
|
99 |
+
header("Content-Length: ".filesize($_GET['file']));
|
100 |
+
@readfile($_GET['file']);
|
101 |
} else {
|
102 |
header('HTTP/1.0 404 Not Found');
|
103 |
die(__('File does not exist.', 'backwpup'));
|
133 |
$jobs[$jobid]['scheduleintervaltype']=$_POST['scheduleintervaltype'];
|
134 |
$jobs[$jobid]['scheduleintervalteimes']=$_POST['scheduleintervalteimes'];
|
135 |
$jobs[$jobid]['scheduleinterval']=$_POST['scheduleintervaltype']*$_POST['scheduleintervalteimes'];
|
136 |
+
$jobs[$jobid]['mailaddresslog']=sanitize_email($_POST['mailaddresslog']);
|
137 |
$jobs[$jobid]['mailerroronly']= $_POST['mailerroronly']==1 ? true : false;
|
138 |
|
139 |
if ($savetype=='DB' or $savetype=='DB+FILE' or $savetype=='OPTIMIZE' or $savetype=='CHECK') {
|
156 |
$jobs[$jobid]['ftphost']=$_POST['ftphost'];
|
157 |
$jobs[$jobid]['ftpuser']=$_POST['ftpuser'];
|
158 |
$jobs[$jobid]['ftppass']=base64_encode($_POST['ftppass']);
|
159 |
+
$jobs[$jobid]['ftpdir']=str_replace('\\','/',stripslashes(trim($_POST['ftpdir'])));
|
160 |
$jobs[$jobid]['ftpmaxbackups']=abs((int)$_POST['ftpmaxbackups']);
|
161 |
+
$jobs[$jobid]['awsAccessKey']=$_POST['awsAccessKey'];
|
162 |
+
$jobs[$jobid]['awsSecretKey']=$_POST['awsSecretKey'];
|
163 |
+
$jobs[$jobid]['awsSSL']= $_POST['awsSSL']==1 ? true : false;
|
164 |
+
$jobs[$jobid]['awsBucket']=$_POST['awsBucket'];
|
165 |
+
$jobs[$jobid]['awsdir']=str_replace('\\','/',stripslashes(trim($_POST['awsdir'])));
|
166 |
+
if (substr($jobs[$jobid]['awsdir'],0,1)=='/')
|
167 |
+
$jobs[$jobid]['awsdir']=substr($jobs[$jobid]['awsdir'],1);
|
168 |
+
$jobs[$jobid]['mailaddress']=sanitize_email($_POST['mailaddress']);
|
169 |
+
$jobs[$jobid]['awsmaxbackups']=abs((int)$_POST['awsmaxbackups']);
|
170 |
}
|
171 |
|
172 |
if (update_option('backwpup_jobs',$jobs))
|
app/options-settings.php
CHANGED
@@ -18,31 +18,15 @@ if ( !defined('ABSPATH') )
|
|
18 |
<?php wp_nonce_field('backwpup-cfg'); ?>
|
19 |
|
20 |
<table class="form-table">
|
21 |
-
<tr valign="top">
|
22 |
-
<th scope="row"><label for="runtime"><?PHP _e('Script Runtime','backwpup'); ?></label></th>
|
23 |
-
<td id="runtime">
|
24 |
-
<?
|
25 |
-
echo __('PHP.ini execution time:','backwpup').' '.ini_get('max_execution_time').' '.__('sec.','backwpup').'<br />';
|
26 |
-
|
27 |
-
if (empty($cfg['maxexecutiontime']));
|
28 |
-
$cfg['maxexecutiontime']=300;
|
29 |
-
|
30 |
-
if (!ini_get('safe_mode') or strtolower(ini_get('safe_mode'))=='off' or ini_get('safe_mode')=='0')
|
31 |
-
echo __('Set Max. execution Time for Scripts:','backwpup').'<input name="maxexecutiontime" type="text" value="'.$cfg['maxexecutiontime'].'" class="small-text" />'.__('sec.','backwpup');
|
32 |
-
else
|
33 |
-
echo '<input name="maxexecutiontime" type="hidden" value="'.$cfg['maxexecutiontime'].'" />';
|
34 |
|
35 |
-
?>
|
36 |
-
</td>
|
37 |
-
</tr>
|
38 |
|
39 |
<tr valign="top">
|
40 |
<th scope="row"><label for="memory"><?PHP _e('Max Memory Usage','backwpup'); ?></label></th>
|
41 |
<td id="memory">
|
42 |
-
<?
|
43 |
echo __('PHP.ini Memory Limit:','backwpup').' '.ini_get('memory_limit').'<br />';
|
44 |
|
45 |
-
if (empty($cfg['memorylimit']))
|
46 |
$cfg['memorylimit']='128M';
|
47 |
|
48 |
if (!function_exists('memory_get_usage'))
|
@@ -59,15 +43,14 @@ if (!function_exists('memory_get_usage'))
|
|
59 |
<tr valign="top">
|
60 |
<th scope="row"><label for="mailtype"><?PHP _e('Mail Send:','backwpup'); ?></label></th>
|
61 |
<td id="mailtype">
|
|
|
|
|
62 |
<?PHP _e('Send mail method:','backwpup');
|
63 |
echo '<select name="mailmethod">';
|
64 |
echo '<option value="mail"'.selected('mail',$cfg['mailmethod'],false).'>'.__('PHP: mail()','backwpup').'</option>';
|
65 |
echo '<option value="Sendmail"'.selected('Sendmail',$cfg['mailmethod'],false).'>'.__('Sendmail','backwpup').'</option>';
|
66 |
echo '<option value="SMTP"'.selected('SMTP',$cfg['mailmethod'],false).'>'.__('SMTP','backwpup').'</option>';
|
67 |
echo '</select>';
|
68 |
-
if (empty($cfg['mailsendmail'])) {
|
69 |
-
$cfg['mailsendmail']=substr(ini_get('sendmail_path'),0,strpos(ini_get('sendmail_path'),' -'));
|
70 |
-
}
|
71 |
?><br />
|
72 |
<?PHP _e('Sendmail Path:','backwpup'); ?><input name="mailhost" type="text" value="<?PHP echo $cfg['mailsendmail'];?>" class="regular-text" /><br />
|
73 |
<?PHP _e('SMTP Hostname:','backwpup'); ?><input name="mailhost" type="text" value="<?PHP echo $cfg['mailhost'];?>" class="regular-text" /><br />
|
@@ -77,8 +60,6 @@ echo '<option value=""'.selected('',$cfg['mailsecure'],false).'>'.__('none','bac
|
|
77 |
echo '<option value="ssl"'.selected('ssl',$cfg['mailsecure'],false).'>SSL</option>';
|
78 |
echo '<option value="tls"'.selected('tls',$cfg['mailsecure'],false).'>TLS</option>';
|
79 |
echo '</select>';
|
80 |
-
if (!empty($cfg['mailsendmail']))
|
81 |
-
$cfg['mailsendmail']='/usr/sbin/sendmail';
|
82 |
?><br />
|
83 |
<?PHP _e('SMTP Username:','backwpup'); ?><input name="mailuser" type="text" value="<?PHP echo $cfg['mailuser'];?>" class="user" /><br />
|
84 |
<?PHP _e('SMTP Password:','backwpup'); ?><input name="mailpass" type="password" value="<?PHP echo base64_decode($cfg['mailpass']);?>" class="password" /><br />
|
@@ -92,6 +73,13 @@ if (!empty($cfg['mailsendmail']))
|
|
92 |
</td>
|
93 |
</tr>
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
<tr valign="top">
|
96 |
<th scope="row"><label for="disablewpcron"><?PHP _e('Disable WP-Cron:','backwpup'); ?></label></th>
|
97 |
<td>
|
@@ -103,6 +91,14 @@ if (!empty($cfg['mailsendmail']))
|
|
103 |
</td>
|
104 |
</tr>
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
</table>
|
107 |
|
108 |
<p class="submit">
|
18 |
<?php wp_nonce_field('backwpup-cfg'); ?>
|
19 |
|
20 |
<table class="form-table">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
|
|
|
|
|
|
22 |
|
23 |
<tr valign="top">
|
24 |
<th scope="row"><label for="memory"><?PHP _e('Max Memory Usage','backwpup'); ?></label></th>
|
25 |
<td id="memory">
|
26 |
+
<?php
|
27 |
echo __('PHP.ini Memory Limit:','backwpup').' '.ini_get('memory_limit').'<br />';
|
28 |
|
29 |
+
if (empty($cfg['memorylimit']))
|
30 |
$cfg['memorylimit']='128M';
|
31 |
|
32 |
if (!function_exists('memory_get_usage'))
|
43 |
<tr valign="top">
|
44 |
<th scope="row"><label for="mailtype"><?PHP _e('Mail Send:','backwpup'); ?></label></th>
|
45 |
<td id="mailtype">
|
46 |
+
<?PHP _e('Sender Email:','backwpup'); ?><input name="mailsndemail" type="text" value="<?PHP echo $cfg['mailsndemail'];?>" class="user" /><br />
|
47 |
+
<?PHP _e('Sender Name:','backwpup'); ?><input name="mailsndname" type="text" value="<?PHP echo $cfg['mailsndname'];?>" class="user" /><br />
|
48 |
<?PHP _e('Send mail method:','backwpup');
|
49 |
echo '<select name="mailmethod">';
|
50 |
echo '<option value="mail"'.selected('mail',$cfg['mailmethod'],false).'>'.__('PHP: mail()','backwpup').'</option>';
|
51 |
echo '<option value="Sendmail"'.selected('Sendmail',$cfg['mailmethod'],false).'>'.__('Sendmail','backwpup').'</option>';
|
52 |
echo '<option value="SMTP"'.selected('SMTP',$cfg['mailmethod'],false).'>'.__('SMTP','backwpup').'</option>';
|
53 |
echo '</select>';
|
|
|
|
|
|
|
54 |
?><br />
|
55 |
<?PHP _e('Sendmail Path:','backwpup'); ?><input name="mailhost" type="text" value="<?PHP echo $cfg['mailsendmail'];?>" class="regular-text" /><br />
|
56 |
<?PHP _e('SMTP Hostname:','backwpup'); ?><input name="mailhost" type="text" value="<?PHP echo $cfg['mailhost'];?>" class="regular-text" /><br />
|
60 |
echo '<option value="ssl"'.selected('ssl',$cfg['mailsecure'],false).'>SSL</option>';
|
61 |
echo '<option value="tls"'.selected('tls',$cfg['mailsecure'],false).'>TLS</option>';
|
62 |
echo '</select>';
|
|
|
|
|
63 |
?><br />
|
64 |
<?PHP _e('SMTP Username:','backwpup'); ?><input name="mailuser" type="text" value="<?PHP echo $cfg['mailuser'];?>" class="user" /><br />
|
65 |
<?PHP _e('SMTP Password:','backwpup'); ?><input name="mailpass" type="password" value="<?PHP echo base64_decode($cfg['mailpass']);?>" class="password" /><br />
|
73 |
</td>
|
74 |
</tr>
|
75 |
|
76 |
+
<tr valign="top">
|
77 |
+
<th scope="row"><label for="dirlogs"><?PHP _e('Log file Folder:','backwpup'); ?></label></th>
|
78 |
+
<td>
|
79 |
+
<input name="dirlogs" type="text" value="<?PHP echo $cfg['dirlogs'];?>" class="regular-text" /><br />
|
80 |
+
</td>
|
81 |
+
</tr>
|
82 |
+
|
83 |
<tr valign="top">
|
84 |
<th scope="row"><label for="disablewpcron"><?PHP _e('Disable WP-Cron:','backwpup'); ?></label></th>
|
85 |
<td>
|
91 |
</td>
|
92 |
</tr>
|
93 |
|
94 |
+
<tr valign="top">
|
95 |
+
<th scope="row"><label for="dirtemp"><?PHP _e('Temp Folder for Backups:','backwpup'); ?></label></th>
|
96 |
+
<td>
|
97 |
+
<input name="dirtemp" type="text" value="<?PHP echo $cfg['dirtemp'];?>" class="regular-text" /><br />
|
98 |
+
</td>
|
99 |
+
</tr>
|
100 |
+
|
101 |
+
|
102 |
</table>
|
103 |
|
104 |
<p class="submit">
|
app/options-tools.php
CHANGED
@@ -50,6 +50,30 @@ if ($_POST['dbrestore']==__('Restore', 'backwpup') and is_file($_POST['sqlfile']
|
|
50 |
?>
|
51 |
</td>
|
52 |
</tr>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
</table>
|
54 |
</form>
|
55 |
</div>
|
50 |
?>
|
51 |
</td>
|
52 |
</tr>
|
53 |
+
|
54 |
+
<tr valign="top">
|
55 |
+
<th scope="row"><label for="sqlfile"><?PHP _e('Create Amazon S3 Bucket','backwpup'); ?></label></th>
|
56 |
+
<td>
|
57 |
+
<?PHP
|
58 |
+
if ($_POST['awsbucketcreate']==__('Create', 'backwpup') and !empty($_POST['awsAccessKey']) and !empty($_POST['awsSecretKey']) and !empty($_POST['awsBucket'])) {
|
59 |
+
if (!class_exists('S3')) require_once 'libs/S3.php';
|
60 |
+
$s3 = new S3($_POST['awsAccessKey'], $_POST['awsSecretKey'], false);
|
61 |
+
if ($s3->putBucket($_POST['awsBucket'], S3::ACL_PRIVATE, $_POST['awsRegion']))
|
62 |
+
echo __('Amazone S3 Bucket created.', 'backwpup')."<br />";
|
63 |
+
else
|
64 |
+
echo __('Can not create Amazon S3 Bucket.', 'backwpup')."<br />";
|
65 |
+
|
66 |
+
}
|
67 |
+
?>
|
68 |
+
<?php _e('Access Key ID:', 'backwpup'); ?><input type="text" name="awsAccessKey" id="awsAccessKey" value="<?PHP echo $_POST['awsAccessKey'];?>" class="regular-text" /><br />
|
69 |
+
<?php _e('Secret Access Key:', 'backwpup'); ?><input type="text" name="awsSecretKey" id="awsSecretKey" value="<?PHP echo $_POST['awsSecretKey'];?>" class="regular-text" /><br />
|
70 |
+
<?php _e('Bucket Name:', 'backwpup'); ?><input type="text" name="awsBucket" id="awsBucket" value="<?PHP echo $_POST['awsBucket'];?>" class="regular-text" /><br />
|
71 |
+
<?php _e('Bucket Region:', 'backwpup'); ?><select name="awsRegion"><option value=""><?php _e('US', 'backwpup'); ?></option><option value="EU"><?php _e('Europe', 'backwpup'); ?></option></select>
|
72 |
+
<input type="submit" name="awsbucketcreate" class="button" value="<?php _e('Create', 'backwpup'); ?>" />
|
73 |
+
</td>
|
74 |
+
</tr>
|
75 |
+
|
76 |
+
|
77 |
</table>
|
78 |
</form>
|
79 |
</div>
|
app/options-view_log-iframe.php
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?PHP
|
2 |
+
if ( !defined('ABSPATH') ) {
|
3 |
+
/** Setup WordPress environment */
|
4 |
+
require_once($_GET['ABSPATH'].'/wp-load.php');
|
5 |
+
}
|
6 |
+
check_admin_referer('viewlognow_'.basename($_GET['logfile']));
|
7 |
+
readfile($_GET['logfile']);
|
8 |
+
?>
|
app/options-view_log.php
CHANGED
@@ -13,24 +13,9 @@ if ( !defined('ABSPATH') )
|
|
13 |
<li><a href="admin.php?page=BackWPup&action=settings"><?PHP _e('Settings','backwpup'); ?></a></li>
|
14 |
</ul>
|
15 |
<br class="clear" />
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
<
|
21 |
-
<?PHP
|
22 |
-
foreach ($log as $line) {
|
23 |
-
if (empty($line)) {
|
24 |
-
echo "<br />\n";
|
25 |
-
continue;
|
26 |
-
}
|
27 |
-
$style='';
|
28 |
-
if (substr($line,21,strlen(__('ERROR:','backwpup')))==__('ERROR:','backwpup'))
|
29 |
-
$style=' style="background-color:red;color:black;"';
|
30 |
-
if (substr($line,21,strlen(__('WARNING:','backwpup')))==__('WARNING:','backwpup'))
|
31 |
-
$style=' style="background-color:yellow;color:black;"';
|
32 |
-
echo "<span style=\"background-color:gray;color:black;\">".substr($line,0,19).":</span> <span".$style.">".substr($line,21)."</span><br />\n";
|
33 |
-
}
|
34 |
-
?>
|
35 |
-
</div>
|
36 |
</div>
|
13 |
<li><a href="admin.php?page=BackWPup&action=settings"><?PHP _e('Settings','backwpup'); ?></a></li>
|
14 |
</ul>
|
15 |
<br class="clear" />
|
16 |
+
<big><?php
|
17 |
+
_e('View Log','backwpup');
|
18 |
+
echo ' <strong>'.basename($_GET['logfile']).'</strong>';
|
19 |
+
?></big>
|
20 |
+
<iframe src="<?PHP echo wp_nonce_url(WP_PLUGIN_URL.'/'.BACKWPUP_PLUGIN_DIR.'/app/options-view_log-iframe.php?ABSPATH='.ABSPATH.'&logfile=' . $_GET['logfile'], 'viewlognow_'.basename($_GET['logfile'])); ?>" name="Logframe" id="Logframe" width="100%" height="450" align="left" scrolling="auto" style="border: 1px solid gray" frameborder="0"></iframe>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
</div>
|
app/options.php
CHANGED
@@ -31,77 +31,95 @@ if ( !defined('ABSPATH') )
|
|
31 |
|
32 |
<div class="clear"></div>
|
33 |
|
34 |
-
<table class="widefat
|
35 |
-
<thead>
|
36 |
-
<tr>
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
<
|
42 |
-
<
|
43 |
-
|
44 |
-
</
|
45 |
-
|
46 |
-
<tfoot>
|
47 |
-
<tr>
|
48 |
-
<th scope="col" class="manage-column column-cb check-column" style=""><input type="checkbox" /></th>
|
49 |
-
<th scope="col" class="manage-column column-id" style=""><?PHP _e('ID','backwpup'); ?></th>
|
50 |
-
<th scope="col" class="manage-column column-name" style=""><?PHP _e('Name','backwpup'); ?></th>
|
51 |
-
<th scope="col" class="manage-column column-type" style=""><?PHP _e('Type','backwpup'); ?></th>
|
52 |
-
<th scope="col" class="manage-column column-next" style=""><?PHP _e('Next Run','backwpup'); ?></th>
|
53 |
-
<th scope="col" class="manage-column column-last" style=""><?PHP _e('Last Run','backwpup'); ?></th>
|
54 |
-
</tr>
|
55 |
-
</tfoot>
|
56 |
|
57 |
<tbody id="the-list" class="list:post">
|
|
|
|
|
|
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
}
|
100 |
-
|
101 |
-
</
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
</table>
|
106 |
|
107 |
<div class="tablenav">
|
31 |
|
32 |
<div class="clear"></div>
|
33 |
|
34 |
+
<table class="widefat" cellspacing="0">
|
35 |
+
<thead>
|
36 |
+
<tr>
|
37 |
+
<?php print_column_headers('backwpup_options'); ?>
|
38 |
+
</tr>
|
39 |
+
</thead>
|
40 |
+
|
41 |
+
<tfoot>
|
42 |
+
<tr>
|
43 |
+
<?php print_column_headers('backwpup_options', false); ?>
|
44 |
+
</tr>
|
45 |
+
</tfoot>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
<tbody id="the-list" class="list:post">
|
48 |
+
<?php
|
49 |
+
$item_columns = get_column_headers('backwpup_options');
|
50 |
+
$hidden = get_hidden_columns('backwpup_options');
|
51 |
|
52 |
+
if (is_array($jobs)) {
|
53 |
+
foreach ($jobs as $jobid => $jobvalue) {
|
54 |
+
?><tr id="job-<?PHP echo $jobid;?>" valign="top"><?PHP
|
55 |
+
foreach($item_columns as $column_name=>$column_display_name) {
|
56 |
+
$class = "class=\"column-$column_name\"";
|
57 |
+
|
58 |
+
$style = '';
|
59 |
+
if ( in_array($column_name, $hidden) )
|
60 |
+
$style = ' style="display:none;"';
|
61 |
+
|
62 |
+
$attributes = "$class$style";
|
63 |
+
|
64 |
+
switch($column_name) {
|
65 |
+
case 'cb':
|
66 |
+
echo '<th scope="row" class="check-column"><input type="checkbox" name="jobs[]" value="'. esc_attr($jobid) .'" /></th>';
|
67 |
+
break;
|
68 |
+
case 'id':
|
69 |
+
echo '<td $attributes>'.$jobid.'</td>';
|
70 |
+
break;
|
71 |
+
case 'name':
|
72 |
+
echo '<td $attributes><strong><a href="'.wp_nonce_url('admin.php?page=BackWPup&action=edit&jobid='.$jobid, 'edit-job').'" title="'.__('Edit:','backwpup').$jobvalue['name'].'">'.$jobvalue['name'].'</a></strong>';
|
73 |
+
$actions = array();
|
74 |
+
$actions['edit'] = "<a href=\"" . wp_nonce_url('admin.php?page=BackWPup&action=edit&jobid='.$jobid, 'edit-job') . "\">" . __('Edit') . "</a>";
|
75 |
+
$actions['copy'] = "<a href=\"" . wp_nonce_url('admin.php?page=BackWPup&action=copy&jobid='.$jobid, 'copy-job_'.$jobid) . "\">" . __('Copy','backwpup') . "</a>";
|
76 |
+
$actions['delete'] = "<a class=\"submitdelete\" href=\"" . wp_nonce_url('admin.php?page=BackWPup&action=delete&jobid='.$jobid, 'delete-job_'.$jobid) . "\" onclick=\"if ( confirm('" . esc_js(__("You are about to delete this Job. \n 'Cancel' to stop, 'OK' to delete.","backwpup")) . "') ) { return true;}return false;\">" . __('Delete') . "</a>";
|
77 |
+
$actions['runnow'] = "<a class=\"submitdelete\" href=\"" . wp_nonce_url('admin.php?page=BackWPup&action=runnow&jobid='.$jobid, 'runnow-job_'.$jobid) . "\">" . __('Run Now','backwpup') . "</a>";
|
78 |
+
$action_count = count($actions);
|
79 |
+
$i = 0;
|
80 |
+
echo '<br /><div class="row-actions">';
|
81 |
+
foreach ( $actions as $action => $linkaction ) {
|
82 |
+
++$i;
|
83 |
+
( $i == $action_count ) ? $sep = '' : $sep = ' | ';
|
84 |
+
echo "<span class='$action'>$linkaction$sep</span>";
|
85 |
+
}
|
86 |
+
echo '</div>';
|
87 |
+
echo '</td>';
|
88 |
+
break;
|
89 |
+
case 'type':
|
90 |
+
echo "<td $attributes>";
|
91 |
+
backwpup_backup_types($jobvalue['type'],true);
|
92 |
+
echo "</td>";
|
93 |
+
break;
|
94 |
+
case 'next':
|
95 |
+
echo "<td $attributes>";
|
96 |
+
if ($jobvalue['starttime']>0 and empty($jobvalue['stoptime'])) {
|
97 |
+
$runtime=time()-$jobvalue['starttime'];
|
98 |
+
echo __('Running since:','backwpup').' '.$runtime.' '.__('sec.','backwpup');
|
99 |
+
} elseif ($time=wp_next_scheduled('backwpup_cron',array('jobid'=>$jobid))) {
|
100 |
+
echo date_i18n(get_option('date_format'),$time); ?><br /><?PHP echo date_i18n(get_option('time_format'),$time);
|
101 |
+
} else {
|
102 |
+
_e('Inactive','backwpup');
|
103 |
+
}
|
104 |
+
echo "</td>";
|
105 |
+
break;
|
106 |
+
case 'last':
|
107 |
+
echo "<td $attributes>";
|
108 |
+
if ($jobvalue['lastrun']) {
|
109 |
+
echo date_i18n(get_option('date_format'),$jobvalue['lastrun']); ?><br /><?PHP echo date_i18n(get_option('time_format'),$jobvalue['lastrun']);
|
110 |
+
if (isset($jobvalue['lastruntime']))
|
111 |
+
echo '<br />'.__('Runtime:','backwpup').' '.$jobvalue['lastruntime'].' '.__('sec.','backwpup');
|
112 |
+
} else {
|
113 |
+
_e('None','backwpup');
|
114 |
+
}
|
115 |
+
echo "</td>";
|
116 |
+
break;
|
117 |
}
|
118 |
+
}
|
119 |
+
echo "\n </tr>\n";
|
120 |
+
}
|
121 |
+
}
|
122 |
+
?></tbody>
|
123 |
</table>
|
124 |
|
125 |
<div class="tablenav">
|
app/tools/db_restore.php
CHANGED
@@ -5,9 +5,7 @@ if ( !defined('ABSPATH') )
|
|
5 |
|
6 |
ignore_user_abort(true);
|
7 |
|
8 |
-
|
9 |
-
$cfg['maxexecutiontime']=300;
|
10 |
-
set_time_limit($cfg['maxexecutiontime']); //300 is most webserver time limit.
|
11 |
|
12 |
//Vars
|
13 |
$oldblogabspath="";
|
5 |
|
6 |
ignore_user_abort(true);
|
7 |
|
8 |
+
@set_time_limit(0); //300 is most webserver time limit.
|
|
|
|
|
9 |
|
10 |
//Vars
|
11 |
$oldblogabspath="";
|
backwpup.php
CHANGED
@@ -4,7 +4,7 @@ Plugin Name: BackWPup
|
|
4 |
Plugin URI: http://danielhuesken.de/portfolio/backwpup/
|
5 |
Description: Backup and more of your WordPress Blog Database and Files.
|
6 |
Author: Daniel Hüsken
|
7 |
-
Version: 0.
|
8 |
Author URI: http://danielhuesken.de
|
9 |
Text Domain: backwpup
|
10 |
Domain Path: /lang/
|
@@ -35,10 +35,7 @@ if ( !defined('ABSPATH') )
|
|
35 |
//Set plugin dirname
|
36 |
define('BACKWPUP_PLUGIN_DIR', dirname(plugin_basename(__FILE__)));
|
37 |
//Set Plugin Version
|
38 |
-
define('BACKWPUP_VERSION', '0.
|
39 |
-
//BackWPup Log Table Name
|
40 |
-
global $wpdb;
|
41 |
-
$wpdb->backwpup_logs = $wpdb->prefix.'backwpup_logs';
|
42 |
|
43 |
//load Text Domain
|
44 |
load_plugin_textdomain('backwpup', false, BACKWPUP_PLUGIN_DIR.'/lang');
|
@@ -52,8 +49,8 @@ register_deactivation_hook(__FILE__, 'backwpup_plugin_deactivate');
|
|
52 |
register_uninstall_hook(__FILE__, 'backwpup_plugin_uninstall');
|
53 |
|
54 |
//Version check
|
55 |
-
if (version_compare($wp_version, '2.8', '<')) { // Let only Activate on WordPress Version 2.8 or heiger
|
56 |
-
add_action('admin_notices', create_function('', 'echo \'<div id="message" class="error fade"><p><strong>' . __('Sorry, BackWPup works only
|
57 |
} else {
|
58 |
//Plugin init
|
59 |
add_action('plugins_loaded', 'backwpup_init');
|
4 |
Plugin URI: http://danielhuesken.de/portfolio/backwpup/
|
5 |
Description: Backup and more of your WordPress Blog Database and Files.
|
6 |
Author: Daniel Hüsken
|
7 |
+
Version: 0.8.0
|
8 |
Author URI: http://danielhuesken.de
|
9 |
Text Domain: backwpup
|
10 |
Domain Path: /lang/
|
35 |
//Set plugin dirname
|
36 |
define('BACKWPUP_PLUGIN_DIR', dirname(plugin_basename(__FILE__)));
|
37 |
//Set Plugin Version
|
38 |
+
define('BACKWPUP_VERSION', '0.8.0');
|
|
|
|
|
|
|
39 |
|
40 |
//load Text Domain
|
41 |
load_plugin_textdomain('backwpup', false, BACKWPUP_PLUGIN_DIR.'/lang');
|
49 |
register_uninstall_hook(__FILE__, 'backwpup_plugin_uninstall');
|
50 |
|
51 |
//Version check
|
52 |
+
if (version_compare($wp_version, '2.8', '<') and version_compare(phpversion(), '5.0.0', '<')) { // Let only Activate on WordPress Version 2.8 or heiger
|
53 |
+
add_action('admin_notices', create_function('', 'echo \'<div id="message" class="error fade"><p><strong>' . __('Sorry, BackWPup works only with WordPress 2.8 and PHP 5 or heigher!!!','backwpup') . '</strong></p></div>\';'));
|
54 |
} else {
|
55 |
//Plugin init
|
56 |
add_action('plugins_loaded', 'backwpup_init');
|
readme.txt
CHANGED
@@ -1,16 +1,17 @@
|
|
1 |
=== BackWPup ===
|
2 |
Contributors: danielhuesken
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=daniel%40huesken-net%2ede&item_name=Daniel%20Huesken%20Plugin%20Donation&item_number=BackWPup&no_shipping=0&no_note=1&tax=0¤cy_code=EUR&lc=DE&bn=PP%2dDonationsBF&charset=UTF%2d8
|
4 |
-
Tags: backup, admin, file, Database, mysql, cron
|
5 |
Requires at least: 2.8
|
6 |
-
Tested up to: 2.9.
|
7 |
-
Stable tag: 0.
|
8 |
|
9 |
Backup and more of your WordPress Blog Database and Files
|
10 |
|
11 |
== Description ==
|
12 |
|
13 |
This Plugin is under heavy Development. Please test it and give feedback!!!.
|
|
|
14 |
|
15 |
Backup and more your Blog.
|
16 |
|
@@ -21,6 +22,7 @@ Backup and more your Blog.
|
|
21 |
* Uses PCLZIP class of WordPress
|
22 |
* Store backup to Folder
|
23 |
* Store backup to FTP Server
|
|
|
24 |
* Send Log/Backup by eMail
|
25 |
|
26 |
|
@@ -44,6 +46,19 @@ in the root folder of the zip Archive. <i>DBName</i>.sql
|
|
44 |
1. Job Page
|
45 |
|
46 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
= 0.7.2 =
|
48 |
* make FTP any more robust
|
49 |
* increased memory for Zip Files
|
1 |
=== BackWPup ===
|
2 |
Contributors: danielhuesken
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=daniel%40huesken-net%2ede&item_name=Daniel%20Huesken%20Plugin%20Donation&item_number=BackWPup&no_shipping=0&no_note=1&tax=0¤cy_code=EUR&lc=DE&bn=PP%2dDonationsBF&charset=UTF%2d8
|
4 |
+
Tags: backup, admin, file, Database, mysql, cron, ftp, S3
|
5 |
Requires at least: 2.8
|
6 |
+
Tested up to: 2.9.3
|
7 |
+
Stable tag: 0.8.0
|
8 |
|
9 |
Backup and more of your WordPress Blog Database and Files
|
10 |
|
11 |
== Description ==
|
12 |
|
13 |
This Plugin is under heavy Development. Please test it and give feedback!!!.
|
14 |
+
Plugin Requires PHP 5.
|
15 |
|
16 |
Backup and more your Blog.
|
17 |
|
22 |
* Uses PCLZIP class of WordPress
|
23 |
* Store backup to Folder
|
24 |
* Store backup to FTP Server
|
25 |
+
* Store backup to Amazon S3
|
26 |
* Send Log/Backup by eMail
|
27 |
|
28 |
|
46 |
1. Job Page
|
47 |
|
48 |
== Changelog ==
|
49 |
+
= 0.8.0 =
|
50 |
+
* Fiexed not working default setttings on settingspage
|
51 |
+
* crate .htaccsses on Apache and index.html on other webserver
|
52 |
+
* fixed global for $wp_version
|
53 |
+
* set max execution time to 0 for unlimeted job time
|
54 |
+
* use WP function to display job tables
|
55 |
+
* Backup file list and zip creation changes
|
56 |
+
* Added support for Amazon S3
|
57 |
+
* Only works with PHP 5 now
|
58 |
+
* Cmplete rewrite of job doing as PHP5 class
|
59 |
+
* PHP errors now in Backup log
|
60 |
+
* Log stred in files now again
|
61 |
+
|
62 |
= 0.7.2 =
|
63 |
* make FTP any more robust
|
64 |
* increased memory for Zip Files
|