PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 1.5.3
JetBackup – Backup, Restore & Migrate v1.5.3
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
309 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_BACKUP_SEND_USAGE_STATUS','0'),
99 ('SG_NOTIFICATIONS_EMAIL_ADDRESS',''),
100 ('SG_STORAGE_BACKUPS_FOLDER_NAME','sg_backups');"
101 );
102 if ($res===false) {
103 return false;
104 }
105
106 return true;
107 }
108
109 private static function installScheduleTable($sgdb)
110 {
111 $dbEngine = backupGuardGetDatabaseEngine();
112
113 //create schedule table
114 $res = $sgdb->query(
115 'CREATE TABLE IF NOT EXISTS `'.SG_SCHEDULE_TABLE_NAME.'` (
116 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
117 `label` varchar(255) NOT NULL,
118 `status` tinyint(3) unsigned NOT NULL,
119 `schedule_options` varchar(255) NOT NULL,
120 `backup_options` text NOT NULL,
121 PRIMARY KEY (`id`)
122 ) ENGINE='.$dbEngine.' DEFAULT CHARSET=utf8;'
123 );
124 if ($res===false) {
125 return false;
126 }
127
128 return true;
129 }
130
131 private static function installActionTable($sgdb)
132 {
133 $dbEngine = backupGuardGetDatabaseEngine();
134
135 //create action table
136 $res = $sgdb->query(
137 "CREATE TABLE IF NOT EXISTS `".SG_ACTION_TABLE_NAME."` (
138 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
139 `name` varchar(255) NOT NULL,
140 `type` tinyint(3) unsigned NOT NULL,
141 `subtype` tinyint(3) unsigned NOT NULL DEFAULT '0',
142 `status` tinyint(3) unsigned NOT NULL,
143 `progress` tinyint(3) unsigned NOT NULL DEFAULT '0',
144 `start_date` datetime NOT NULL,
145 `update_date` datetime DEFAULT NULL,
146 `options` text NOT NULL,
147 PRIMARY KEY (`id`)
148 ) ENGINE=".$dbEngine." DEFAULT CHARSET=utf8;"
149 );
150 if ($res===false) {
151 return false;
152 }
153
154 return true;
155 }
156
157 public static function install()
158 {
159 $sgdb = SGDatabase::getInstance();
160
161 try {
162 if (!self::installConfigTable($sgdb)) {
163 throw new SGExceptionDatabaseError('Could not install config table');
164 }
165
166 if (!self::installScheduleTable($sgdb)) {
167 throw new SGExceptionDatabaseError('Could not install schedule table');
168 }
169
170 if (!self::installActionTable($sgdb)) {
171 throw new SGExceptionDatabaseError('Could not install action table');
172 }
173
174 self::installReviewSettings();
175 }
176 catch (SGException $exception) {
177 die($exception);
178 }
179 }
180
181 private static function installReviewSettings()
182 {
183 $usageDays = SGConfig::get('usageDays');
184 if (!$usageDays) {
185 SGConfig::set('usageDays', 0);
186
187 $timeDate = new \DateTime('now');
188 $installTime = strtotime($timeDate->format('Y-m-d H:i:s'));
189 SGConfig::set('installDate', $installTime);
190 $timeDate->modify('+'.SG_BACKUP_REVIEW_PERIOD.' day');
191
192 $timeNow = strtotime($timeDate->format('Y-m-d H:i:s'));
193 SGConfig::set('openNextTime', $timeNow);
194 }
195 $backupCountReview = SGConfig::get('backupReviewCount');
196 if (!$backupCountReview) {
197 SGConfig::set('backupReviewCount', SG_BACKUP_REVIEW_BACKUP_COUNT);
198 }
199
200 $restoreReviewCount = SGConfig::get('restoreReviewCount');
201 if (!$restoreReviewCount) {
202 SGConfig::set('restoreReviewCount', SG_BACKUP_REVIEW_RESTORE_COUNT);
203 }
204 }
205
206 private static function cleanupSchedules()
207 {
208 $schedules = SGBackupSchedule::getAllSchedules();
209 foreach ($schedules as $schedule) {
210 SGBackupSchedule::remove($schedule['id']);
211 }
212 }
213
214 public static function uninstall($deleteBackups = false)
215 {
216 try {
217 @unlink(SG_PING_FILE_PATH);
218
219 if (self::isFeatureAvailable('SCHEDULE')) {
220 self::cleanupSchedules();
221 }
222
223 $sgdb = SGDatabase::getInstance();
224
225 //drop config table
226 $res = $sgdb->query('DROP TABLE IF EXISTS `'.SG_CONFIG_TABLE_NAME.'`;');
227 if ($res===false) {
228 throw new SGExceptionDatabaseError('Could not execute query');
229 }
230
231 //drop schedule table
232 $res = $sgdb->query('DROP TABLE IF EXISTS `'.SG_SCHEDULE_TABLE_NAME.'`;');
233 if ($res===false) {
234 throw new SGExceptionDatabaseError('Could not execute query');
235 }
236
237 //drop action table
238 $res = $sgdb->query('DROP TABLE IF EXISTS `'.SG_ACTION_TABLE_NAME.'`;');
239 if ($res===false) {
240 throw new SGExceptionDatabaseError('Could not execute query');
241 }
242
243 //delete directory of backups
244 if ($deleteBackups) {
245 $backupPath = SGConfig::get('SG_BACKUP_DIRECTORY');
246 backupGuardDeleteDirectory($backupPath);
247 }
248 }
249 catch (SGException $exception) {
250 die($exception);
251 }
252 }
253
254 public static function checkRequirement($requirement)
255 {
256 if ($requirement=='ftp' && !extension_loaded('ftp')) {
257 throw new SGExceptionNotFound('FTP extension is not loaded.');
258 }
259 else if ($requirement=='curl' && !function_exists('curl_version')) {
260 throw new SGExceptionNotFound('cURL extension is not loaded.');
261 }
262 else if ($requirement=='intSize' && PHP_INT_SIZE < 8) {
263 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) . ")");
264 }
265 }
266
267 public static function isFeatureAvailable($feature)
268 {
269 return ((int)SGConfig::get('SG_FEATURE_'.strtoupper($feature))===1?true:false);
270 }
271
272 private static function prepare()
273 {
274 $backupPath = SGConfig::get('SG_BACKUP_DIRECTORY');
275
276 //create directory for backups
277 if (!is_dir($backupPath)) {
278 if (!@mkdir($backupPath)) {
279 throw new SGExceptionMethodNotAllowed('Cannot create folder: '.$backupPath);
280 }
281
282 if (!@file_put_contents($backupPath.'.htaccess', 'deny from all')) {
283 throw new SGExceptionMethodNotAllowed('Cannot create htaccess file');
284 }
285
286 if (!@file_put_contents($backupPath.'index.php', "<?php\n// Silence is golden")) {
287 throw new SGExceptionMethodNotAllowed('Cannot create index file');
288 }
289 }
290
291 //check permissions of backups directory
292 if (!is_writable($backupPath)) {
293 throw new SGExceptionForbidden('Permission denied. Directory is not writable: '.$backupPath);
294 }
295
296 //prepare notices
297 $noticeHandler = new SGNoticeHandler();
298 $noticeHandler->run();
299 }
300
301 private static function checkMinimumRequirements()
302 {
303 //check ZLib library
304 if (!function_exists('gzdeflate')) {
305 throw new SGExceptionNotFound('ZLib extension is not loaded.');
306 }
307 }
308 }
309