PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 2.0.3
JetBackup – Backup, Restore & Migrate v2.0.3
3.1.22.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 3 years ago database 3 years ago exception 3 years ago extension 3 years ago notice 3 years ago restore 3 years ago schedule 3 years ago storage 3 years ago SGBoot.php 3 years ago SGConfig.php 3 years ago functions.php 3 years ago
SGBoot.php
275 lines
1 <?php
2
3 //check PHP version
4 if (version_compare(PHP_VERSION, '5.3.3', '<')) {
5 die('PHP >=5.3.3 version required.');
6 }
7
8 require_once SG_EXCEPTION_PATH . 'SGException.php';
9 require_once SG_CORE_PATH . 'functions.php';
10 backupGuardIncludeFile(SG_CORE_PATH . 'functions.silver.php');
11 backupGuardIncludeFile(SG_CORE_PATH . 'functions.gold.php');
12 backupGuardIncludeFile(SG_CORE_PATH . 'functions.platinum.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 $noticeHandler = new SGNoticeHandler();
46 $noticeHandler->run();
47 }
48
49 public static function didInstallForFirstTime()
50 {
51 self::setPluginInstallUpdateDate();
52 }
53
54 public static function didUpdatePluginVersion()
55 {
56 self::setPluginInstallUpdateDate();
57 }
58
59 public static function setPluginInstallUpdateDate()
60 {
61 SGConfig::set('SG_PLUGIN_INSTALL_UPDATE_DATE', time());
62 }
63
64 private static function installConfigTable($sgdb)
65 {
66 $dbEngine = backupGuardGetDatabaseEngine();
67 $downloadMode = backupGuardCheckDownloadMode();
68 //create config table
69 $res = $sgdb->query(
70 'CREATE TABLE IF NOT EXISTS `' . SG_CONFIG_TABLE_NAME . '` (
71 `ckey` varchar(100) NOT NULL,
72 `cvalue` text NOT NULL,
73 PRIMARY KEY (`ckey`)
74 ) ENGINE=' . $dbEngine . ' DEFAULT CHARSET=utf8;'
75 );
76 if ($res === false) {
77 return false;
78 }
79
80 //delete all content from config table (just in case if wasn't dropped)
81 $sgdb->query('DELETE FROM `' . SG_CONFIG_TABLE_NAME . '`;');
82
83 //populate config table
84 $res = $sgdb->query(
85 "INSERT INTO `" . SG_CONFIG_TABLE_NAME . "` VALUES
86 ('SG_BACKUP_GUARD_VERSION','" . SG_BACKUP_GUARD_VERSION . "'),
87 ('SG_BACKUP_WITH_RELOADINGS', '1'),
88 ('SG_BACKUP_SYNCHRONOUS_STORAGE_UPLOAD','1'),
89 ('SG_NOTIFICATIONS_ENABLED','0'),
90 ('SG_SHOW_STATISTICS_WIDGET','1'),
91 ('SG_NOTIFICATIONS_EMAIL_ADDRESS',''),
92 ('SG_STORAGE_BACKUPS_FOLDER_NAME','jetbackup'),
93 ('SG_DOWNLOAD_MODE'," . $downloadMode . ");"
94 );
95 if ($res === false) {
96 return false;
97 }
98
99 return true;
100 }
101
102 private static function installScheduleTable($sgdb)
103 {
104 $dbEngine = backupGuardGetDatabaseEngine();
105
106 //create schedule table
107 $res = $sgdb->query(
108 'CREATE TABLE IF NOT EXISTS `' . SG_SCHEDULE_TABLE_NAME . '` (
109 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
110 `label` varchar(255) NOT NULL,
111 `status` tinyint(3) unsigned NOT NULL,
112 `schedule_options` varchar(255) NOT NULL,
113 `backup_options` text NOT NULL,
114 PRIMARY KEY (`id`)
115 ) ENGINE=' . $dbEngine . ' DEFAULT CHARSET=utf8;'
116 );
117 if ($res === false) {
118 return false;
119 }
120
121 return true;
122 }
123
124 private static function installActionTable($sgdb)
125 {
126 $dbEngine = backupGuardGetDatabaseEngine();
127
128 //create action table
129 $res = $sgdb->query(
130 "CREATE TABLE IF NOT EXISTS `" . SG_ACTION_TABLE_NAME . "` (
131 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
132 `name` varchar(255) NOT NULL,
133 `type` tinyint(3) unsigned NOT NULL,
134 `subtype` tinyint(3) unsigned NOT NULL DEFAULT '0',
135 `status` tinyint(3) unsigned NOT NULL,
136 `progress` tinyint(3) unsigned NOT NULL DEFAULT '0',
137 `start_date` datetime NOT NULL,
138 `update_date` datetime DEFAULT NULL,
139 `options` text NOT NULL,
140 PRIMARY KEY (`id`)
141 ) ENGINE=" . $dbEngine . " DEFAULT CHARSET=utf8;"
142 );
143 if ($res === false) {
144 return false;
145 }
146
147 return true;
148 }
149
150 public static function install()
151 {
152 $sgdb = SGDatabase::getInstance();
153
154 try {
155 if (!self::installConfigTable($sgdb)) {
156 throw new SGExceptionDatabaseError('Could not install config table');
157 }
158
159 if (!self::installScheduleTable($sgdb)) {
160 throw new SGExceptionDatabaseError('Could not install schedule table');
161 }
162
163 if (!self::installActionTable($sgdb)) {
164 throw new SGExceptionDatabaseError('Could not install action table');
165 }
166
167 self::installReviewSettings();
168 self::checkliteSpeedHosting();
169 } catch (SGException $exception) {
170 die($exception);
171 }
172 }
173
174 private static function installReviewSettings()
175 {
176 $usageDays = SGConfig::get('usageDays');
177 if (!$usageDays) {
178 SGConfig::set('usageDays', 0);
179
180 $timeDate = new \DateTime('now');
181 $installTime = strtotime($timeDate->format('Y-m-d H:i:s'));
182 SGConfig::set('installDate', $installTime);
183 $timeDate->modify('+' . SG_BACKUP_REVIEW_PERIOD . ' day');
184
185 $timeNow = strtotime($timeDate->format('Y-m-d H:i:s'));
186 SGConfig::set('openNextTime', $timeNow);
187 }
188 $backupCountReview = SGConfig::get('backupReviewCount');
189 if (!$backupCountReview) {
190 SGConfig::set('backupReviewCount', SG_BACKUP_REVIEW_BACKUP_COUNT);
191 }
192
193 $restoreReviewCount = SGConfig::get('restoreReviewCount');
194 if (!$restoreReviewCount) {
195 SGConfig::set('restoreReviewCount', SG_BACKUP_REVIEW_RESTORE_COUNT);
196 }
197
198 SGConfig::set('closeReviewBanner', 1);
199 }
200
201 private static function checkliteSpeedHosting($delete = false)
202 {
203 if ($delete) {
204 removeLiteSpeedHtaccessModule();
205 } else {
206 addLiteSpeedHtaccessModule();
207 }
208 }
209
210 private static function cleanupSchedules()
211 {
212 $schedules = SGBackupSchedule::getAllSchedules();
213 foreach ($schedules as $schedule) {
214 SGBackupSchedule::remove($schedule['id']);
215 }
216 }
217
218 public static function uninstall($deleteBackups = false)
219 {
220 try {
221 @unlink(SG_PING_FILE_PATH);
222
223 if (self::isFeatureAvailable('SCHEDULE')) {
224 self::cleanupSchedules();
225 }
226
227 $sgdb = SGDatabase::getInstance();
228
229 //drop config table
230 $res = $sgdb->query('DROP TABLE IF EXISTS `' . SG_CONFIG_TABLE_NAME . '`;');
231 if ($res === false) {
232 throw new SGExceptionDatabaseError('Could not execute query');
233 }
234
235 //drop schedule table
236 $res = $sgdb->query('DROP TABLE IF EXISTS `' . SG_SCHEDULE_TABLE_NAME . '`;');
237 if ($res === false) {
238 throw new SGExceptionDatabaseError('Could not execute query');
239 }
240
241 //drop action table
242 $res = $sgdb->query('DROP TABLE IF EXISTS `' . SG_ACTION_TABLE_NAME . '`;');
243 if ($res === false) {
244 throw new SGExceptionDatabaseError('Could not execute query');
245 }
246
247 self::checkliteSpeedHosting(true);
248
249 //delete directory of backups
250 if ($deleteBackups) {
251 $backupPath = SGConfig::get('SG_BACKUP_DIRECTORY');
252 backupGuardDeleteDirectory($backupPath);
253 }
254 } catch (SGException $exception) {
255 die($exception);
256 }
257 }
258
259 public static function checkRequirement($requirement)
260 {
261 if ($requirement == 'ftp' && !extension_loaded('ftp')) {
262 throw new SGExceptionNotFound('FTP extension is not loaded.');
263 } else if ($requirement == 'curl' && !function_exists('curl_version')) {
264 throw new SGExceptionNotFound('cURL extension is not loaded.');
265 } else if ($requirement == 'intSize' && PHP_INT_SIZE < 8) {
266 throw new SGExceptionIO("JetBackup 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) . ")");
267 }
268 }
269
270 public static function isFeatureAvailable($feature)
271 {
272 return ((int) SGConfig::get('SG_FEATURE_' . strtoupper($feature)) === 1 ? true : false);
273 }
274 }
275