PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 1.4.4
JetBackup – Backup, Restore & Migrate v1.4.4
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / com / core / SGBoot.php
backup / com / core Last commit date
backup 5 years ago database 5 years ago exception 5 years ago extension 5 years ago log 5 years ago notice 5 years ago restore 5 years ago schedule 5 years ago storage 5 years ago widget 5 years ago SGBoot.php 5 years ago SGConfig.php 5 years ago SGPing.php 5 years ago functions.php 5 years ago
SGBoot.php
308 lines
1 <?php
2 //check PHP version
3 if (version_compare(PHP_VERSION, '5.3.3', '<')) {
4 die('PHP >=5.3.3 version required.');
5 }
6
7 require_once(SG_EXCEPTION_PATH.'SGException.php');
8 require_once(SG_CORE_PATH.'functions.php');
9 backupGuardIncludeFile(SG_CORE_PATH.'functions.silver.php');
10 backupGuardIncludeFile(SG_CORE_PATH.'functions.gold.php');
11 backupGuardIncludeFile(SG_CORE_PATH.'functions.platinum.php');
12 require_once(SG_CORE_PATH.'SGPing.php');
13 require_once(SG_DATABASE_PATH.'SGDatabase.php');
14 require_once(SG_CORE_PATH.'SGConfig.php');
15 require_once(SG_NOTICE_PATH.'SGNotice.php');
16 require_once(SG_NOTICE_PATH.'SGNoticeHandler.php');
17 backupGuardIncludeFile(SG_BACKUP_PATH.'SGBackupSchedule.php');
18 backupGuardIncludeFile(SG_EXTENSION_PATH.'SGExtension.php');
19
20 class SGBoot
21 {
22 public static $executionTimeLimit = 0;
23 public static $memoryLimit = 0;
24
25 public static function init()
26 {
27 //get current execution time limit
28 self::$executionTimeLimit = ini_get('max_execution_time');
29
30 //get current memory limit
31 self::$memoryLimit = ini_get('memory_limit');
32
33 //remove execution time limit
34 @ini_set('max_execution_time', 0);
35
36 //change initial memory limit
37 @ini_set('memory_limit', '512M');
38
39 //don't let server to abort scripts
40 @ignore_user_abort(true);
41
42 //load all config variables from database
43 SGConfig::getAll();
44
45 try {
46 //check minimum requirements
47 self::checkMinimumRequirements();
48
49 //prepare directory for backups
50 self::prepare();
51 }
52 catch (SGException $exception) {
53 die($exception);
54 }
55 }
56
57 public static function didInstallForFirstTime()
58 {
59 self::setPluginInstallUpdateDate();
60 }
61
62 public static function didUpdatePluginVersion()
63 {
64 self::setPluginInstallUpdateDate();
65 }
66
67 public static function setPluginInstallUpdateDate()
68 {
69 SGConfig::set('SG_PLUGIN_INSTALL_UPDATE_DATE', time());
70 }
71
72 private static function installConfigTable($sgdb)
73 {
74 $dbEngine = backupGuardGetDatabaseEngine();
75 //create config table
76 $res = $sgdb->query(
77 'CREATE TABLE IF NOT EXISTS `'.SG_CONFIG_TABLE_NAME.'` (
78 `ckey` varchar(100) NOT NULL,
79 `cvalue` text NOT NULL,
80 PRIMARY KEY (`ckey`)
81 ) ENGINE='.$dbEngine.' DEFAULT CHARSET=utf8;'
82 );
83 if ($res===false) {
84 return false;
85 }
86
87 //delete all content from config table (just in case if wasn't dropped)
88 $sgdb->query('DELETE FROM `'.SG_CONFIG_TABLE_NAME.'`;');
89
90 //populate config table
91 $res = $sgdb->query(
92 "INSERT INTO `".SG_CONFIG_TABLE_NAME."` VALUES
93 ('SG_BACKUP_GUARD_VERSION','".SG_BACKUP_GUARD_VERSION."'),
94 ('SG_BACKUP_WITH_RELOADINGS', '1'),
95 ('SG_BACKUP_SYNCHRONOUS_STORAGE_UPLOAD','1'),
96 ('SG_NOTIFICATIONS_ENABLED','0'),
97 ('SG_SHOW_STATISTICS_WIDGET','1'),
98 ('SG_NOTIFICATIONS_EMAIL_ADDRESS',''),
99 ('SG_STORAGE_BACKUPS_FOLDER_NAME','sg_backups');"
100 );
101 if ($res===false) {
102 return false;
103 }
104
105 return true;
106 }
107
108 private static function installScheduleTable($sgdb)
109 {
110 $dbEngine = backupGuardGetDatabaseEngine();
111
112 //create schedule table
113 $res = $sgdb->query(
114 'CREATE TABLE IF NOT EXISTS `'.SG_SCHEDULE_TABLE_NAME.'` (
115 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
116 `label` varchar(255) NOT NULL,
117 `status` tinyint(3) unsigned NOT NULL,
118 `schedule_options` varchar(255) NOT NULL,
119 `backup_options` text NOT NULL,
120 PRIMARY KEY (`id`)
121 ) ENGINE='.$dbEngine.' DEFAULT CHARSET=utf8;'
122 );
123 if ($res===false) {
124 return false;
125 }
126
127 return true;
128 }
129
130 private static function installActionTable($sgdb)
131 {
132 $dbEngine = backupGuardGetDatabaseEngine();
133
134 //create action table
135 $res = $sgdb->query(
136 "CREATE TABLE IF NOT EXISTS `".SG_ACTION_TABLE_NAME."` (
137 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
138 `name` varchar(255) NOT NULL,
139 `type` tinyint(3) unsigned NOT NULL,
140 `subtype` tinyint(3) unsigned NOT NULL DEFAULT '0',
141 `status` tinyint(3) unsigned NOT NULL,
142 `progress` tinyint(3) unsigned NOT NULL DEFAULT '0',
143 `start_date` datetime NOT NULL,
144 `update_date` datetime DEFAULT NULL,
145 `options` text NOT NULL,
146 PRIMARY KEY (`id`)
147 ) ENGINE=".$dbEngine." DEFAULT CHARSET=utf8;"
148 );
149 if ($res===false) {
150 return false;
151 }
152
153 return true;
154 }
155
156 public static function install()
157 {
158 $sgdb = SGDatabase::getInstance();
159
160 try {
161 if (!self::installConfigTable($sgdb)) {
162 throw new SGExceptionDatabaseError('Could not install config table');
163 }
164
165 if (!self::installScheduleTable($sgdb)) {
166 throw new SGExceptionDatabaseError('Could not install schedule table');
167 }
168
169 if (!self::installActionTable($sgdb)) {
170 throw new SGExceptionDatabaseError('Could not install action table');
171 }
172
173 self::installReviewSettings();
174 }
175 catch (SGException $exception) {
176 die($exception);
177 }
178 }
179
180 private static function installReviewSettings()
181 {
182 $usageDays = SGConfig::get('usageDays');
183 if (!$usageDays) {
184 SGConfig::set('usageDays', 0);
185
186 $timeDate = new \DateTime('now');
187 $installTime = strtotime($timeDate->format('Y-m-d H:i:s'));
188 SGConfig::set('installDate', $installTime);
189 $timeDate->modify('+'.SG_BACKUP_REVIEW_PERIOD.' day');
190
191 $timeNow = strtotime($timeDate->format('Y-m-d H:i:s'));
192 SGConfig::set('openNextTime', $timeNow);
193 }
194 $backupCountReview = SGConfig::get('backupReviewCount');
195 if (!$backupCountReview) {
196 SGConfig::set('backupReviewCount', SG_BACKUP_REVIEW_BACKUP_COUNT);
197 }
198
199 $restoreReviewCount = SGConfig::get('restoreReviewCount');
200 if (!$restoreReviewCount) {
201 SGConfig::set('restoreReviewCount', SG_BACKUP_REVIEW_RESTORE_COUNT);
202 }
203 }
204
205 private static function cleanupSchedules()
206 {
207 $schedules = SGBackupSchedule::getAllSchedules();
208 foreach ($schedules as $schedule) {
209 SGBackupSchedule::remove($schedule['id']);
210 }
211 }
212
213 public static function uninstall($deleteBackups = false)
214 {
215 try {
216 @unlink(SG_PING_FILE_PATH);
217
218 if (self::isFeatureAvailable('SCHEDULE')) {
219 self::cleanupSchedules();
220 }
221
222 $sgdb = SGDatabase::getInstance();
223
224 //drop config table
225 $res = $sgdb->query('DROP TABLE IF EXISTS `'.SG_CONFIG_TABLE_NAME.'`;');
226 if ($res===false) {
227 throw new SGExceptionDatabaseError('Could not execute query');
228 }
229
230 //drop schedule table
231 $res = $sgdb->query('DROP TABLE IF EXISTS `'.SG_SCHEDULE_TABLE_NAME.'`;');
232 if ($res===false) {
233 throw new SGExceptionDatabaseError('Could not execute query');
234 }
235
236 //drop action table
237 $res = $sgdb->query('DROP TABLE IF EXISTS `'.SG_ACTION_TABLE_NAME.'`;');
238 if ($res===false) {
239 throw new SGExceptionDatabaseError('Could not execute query');
240 }
241
242 //delete directory of backups
243 if ($deleteBackups) {
244 $backupPath = SGConfig::get('SG_BACKUP_DIRECTORY');
245 backupGuardDeleteDirectory($backupPath);
246 }
247 }
248 catch (SGException $exception) {
249 die($exception);
250 }
251 }
252
253 public static function checkRequirement($requirement)
254 {
255 if ($requirement=='ftp' && !extension_loaded('ftp')) {
256 throw new SGExceptionNotFound('FTP extension is not loaded.');
257 }
258 else if ($requirement=='curl' && !function_exists('curl_version')) {
259 throw new SGExceptionNotFound('cURL extension is not loaded.');
260 }
261 else if ($requirement=='intSize' && PHP_INT_SIZE < 8) {
262 throw new SGExceptionIO("BackupGuard uses 64-bit integers, but it looks like we're running on a version of PHP that doesn't support 64-bit integers (PHP_INT_MAX=" . ((string) PHP_INT_MAX) . ")");
263 }
264 }
265
266 public static function isFeatureAvailable($feature)
267 {
268 return (SGConfig::get('SG_FEATURE_'.strtoupper($feature))===1?true:false);
269 }
270
271 private static function prepare()
272 {
273 $backupPath = SGConfig::get('SG_BACKUP_DIRECTORY');
274
275 //create directory for backups
276 if (!is_dir($backupPath)) {
277 if (!@mkdir($backupPath)) {
278 throw new SGExceptionMethodNotAllowed('Cannot create folder: '.$backupPath);
279 }
280
281 if (!@file_put_contents($backupPath.'.htaccess', 'deny from all')) {
282 throw new SGExceptionMethodNotAllowed('Cannot create htaccess file');
283 }
284
285 if (!@file_put_contents($backupPath.'index.php', "<?php\n// Silence is golden")) {
286 throw new SGExceptionMethodNotAllowed('Cannot create index file');
287 }
288 }
289
290 //check permissions of backups directory
291 if (!is_writable($backupPath)) {
292 throw new SGExceptionForbidden('Permission denied. Directory is not writable: '.$backupPath);
293 }
294
295 //prepare notices
296 $noticeHandler = new SGNoticeHandler();
297 $noticeHandler->run();
298 }
299
300 private static function checkMinimumRequirements()
301 {
302 //check ZLib library
303 if (!function_exists('gzdeflate')) {
304 throw new SGExceptionNotFound('ZLib extension is not loaded.');
305 }
306 }
307 }
308