ISGArchiveDelegate.php
3 years ago
SGBGArchive.php
3 years ago
SGBGArchiveCdr.php
3 years ago
SGBGArchiveHelper.php
3 years ago
SGBGCache.php
3 years ago
SGBGCacheableFile.php
3 years ago
SGBGDirectoryTreeFile.php
3 years ago
SGBGFile.php
3 years ago
SGBGFileHelper.php
3 years ago
SGBGJsonFile.php
3 years ago
SGBGLog.php
3 years ago
SGBGReloader.php
3 years ago
SGBGStateFile.php
3 years ago
SGBGTask.php
3 years ago
SGBGReloader.php
110 lines
| 1 | <?php |
| 2 | |
| 3 | class SGBGReloader |
| 4 | { |
| 5 | private static $instance = null; |
| 6 | protected $interval = 60; //seconds |
| 7 | protected $lastReloadTs = 0; |
| 8 | |
| 9 | private function __construct() |
| 10 | { |
| 11 | |
| 12 | } |
| 13 | |
| 14 | private function __clone() |
| 15 | { |
| 16 | |
| 17 | } |
| 18 | |
| 19 | public static function getInstance() |
| 20 | { |
| 21 | if (!self::$instance) { |
| 22 | self::$instance = new self(); |
| 23 | } |
| 24 | |
| 25 | return self::$instance; |
| 26 | } |
| 27 | |
| 28 | public function getInterval() |
| 29 | { |
| 30 | return $this->interval; |
| 31 | } |
| 32 | |
| 33 | public function setInterval($interval) |
| 34 | { |
| 35 | $this->interval = $interval; |
| 36 | } |
| 37 | |
| 38 | public function getLastReloadTs() |
| 39 | { |
| 40 | return $this->lastReloadTs; |
| 41 | } |
| 42 | |
| 43 | public function setLastReloadTs($lastReloadTs) |
| 44 | { |
| 45 | $this->lastReloadTs = $lastReloadTs; |
| 46 | } |
| 47 | |
| 48 | public function shouldReload() |
| 49 | { |
| 50 | return (time() - $this->getLastReloadTs() >= $this->getInterval()); |
| 51 | } |
| 52 | |
| 53 | protected function getCurrentUrl() |
| 54 | { |
| 55 | $scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')?'https':'http'; |
| 56 | return ($scheme.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); |
| 57 | } |
| 58 | |
| 59 | |
| 60 | private function doCurl ($url, $key, $action) { |
| 61 | |
| 62 | // Set post values |
| 63 | $postfields = array( |
| 64 | 'k' => $key, |
| 65 | 'action' => $action, |
| 66 | ); |
| 67 | |
| 68 | // Call the API |
| 69 | $ch = curl_init(); |
| 70 | curl_setopt($ch, CURLOPT_URL, $url); |
| 71 | curl_setopt($ch, CURLOPT_POST, 1); |
| 72 | curl_setopt($ch, CURLOPT_TIMEOUT, 30); |
| 73 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 74 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
| 75 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
| 76 | curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields)); |
| 77 | curl_exec($ch); |
| 78 | curl_close($ch); |
| 79 | |
| 80 | } |
| 81 | |
| 82 | public function reload() { |
| 83 | |
| 84 | |
| 85 | if (defined('BG_EXTERNAL_RESTORE_RUNNING') && BG_EXTERNAL_RESTORE_RUNNING) { |
| 86 | |
| 87 | $external = SGExternalRestore::getInstance()->getDestinationFileUrlArray(); |
| 88 | $action = "awake"; |
| 89 | $this->doCurl($external['url'].$external['restore_file'], $external['key'], $action); |
| 90 | |
| 91 | } else { |
| 92 | |
| 93 | $url = get_admin_url() . "admin-ajax.php?action=backup_guard_awake"; |
| 94 | $args = array( |
| 95 | 'timeout' => 2, |
| 96 | 'sslverify' => false, |
| 97 | 'headers' => [ |
| 98 | 'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9' |
| 99 | ] |
| 100 | ); |
| 101 | |
| 102 | wp_remote_get($url, $args); |
| 103 | |
| 104 | } |
| 105 | |
| 106 | |
| 107 | die; |
| 108 | } |
| 109 | } |
| 110 |