public function setBestReloadMethod() { $method = SG_RELOAD_METHOD_NONE; if (function_exists('curl_version')) { $method = SG_RELOAD_METHOD_CURL; } else { if ($this->testStreamConnection()) { $method = SG_RELOAD_METHOD_STREAM; } else { if ($this->testSocketConnection()) { $method = SG_RELOAD_METHOD_SOCKET; } } } SGConfig::set('SG_RELOAD_METHOD', $method, true); $this->reloadMethod = $method; }
<?php require_once dirname(__FILE__) . '/../boot.php'; require_once SG_BACKUP_PATH . 'SGBackup.php'; if (isAjax()) { $error = array(); try { //Check if any running action $runningAction = getRunningActions(); if ($runningAction) { throw new SGException(_t('There is already another process running.', true)); } @unlink(SG_BACKUP_DIRECTORY . 'sg_backup.state'); SGConfig::set('SG_RUNNING_ACTION', 0, true); die('{"success":1}'); } catch (SGException $exception) { array_push($error, $exception->getMessage()); die(json_encode($error)); } }
$error = array(); $success = array('success' => 1); if (isAjax() && isset($_POST['cancel'])) { SGConfig::set('SG_NOTIFICATIONS_ENABLED', 0); SGConfig::set('SG_NOTIFICATIONS_EMAIL_ADDRESS', ''); die(json_encode($success)); } if (isAjax() && count($_POST)) { if (isset($_POST['sgIsEmailNotification'])) { $email = ''; $email = @$_POST['sgUserEmail']; if (empty($email)) { array_push($error, _t('Email is required.', true)); } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { array_push($error, _t('Invalid email address.', true)); } } $ajaxInterval = (int) $_POST['ajaxInterval']; if (count($error)) { die(json_decode($error)); } SGConfig::set('SG_SEND_ANONYMOUS_STATISTICS', 0); if (isset($_POST['sgAnonymousStatistics'])) { SGConfig::set('SG_SEND_ANONYMOUS_STATISTICS', true); } SGConfig::set('SG_AJAX_REQUEST_FREQUENCY', $ajaxInterval); SGConfig::set('SG_NOTIFICATIONS_ENABLED', 1); SGConfig::set('SG_NOTIFICATIONS_EMAIL_ADDRESS', $email); die(json_encode($success)); }
private function prepareForRestore($backupName) { //prepare file name $this->fileName = $backupName; //set paths $restorePath = SG_BACKUP_DIRECTORY . $this->fileName; $this->filesBackupPath = $restorePath . '/' . $this->fileName . '.sgbp'; $this->databaseBackupPath = $restorePath . '/' . $this->fileName . '.sql'; //prepare folder $this->prepareRestoreFolder($restorePath); //start logging SGBackupLog::writeAction('restore', SG_BACKUP_LOG_POS_START); SGConfig::set('SG_RUNNING_ACTION', 1, true); //save timestamp for future use $this->actionStartTs = time(); //create action inside db $this->actionId = self::createAction($this->fileName, SG_ACTION_TYPE_RESTORE, SG_ACTION_STATUS_IN_PROGRESS_FILES); //register shutdown function (used for handling execution time limits) register_shutdown_function('shutdownAction', $this->actionId, SG_ACTION_TYPE_RESTORE, $this->filesBackupPath, $this->databaseBackupPath, $this); }
<?php require_once dirname(__FILE__) . '/../boot.php'; $directories = SGConfig::get('SG_BACKUP_FILE_PATHS'); $directories = explode(',', $directories); $dropbox = SGConfig::get('SG_DROPBOX_ACCESS_TOKEN'); $gdrive = SGConfig::get('SG_GOOGLE_DRIVE_REFRESH_TOKEN'); $ftp = SGConfig::get('SG_STORAGE_FTP_CONNECTED'); ?> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title"><?php _t('Manual Backup'); ?> </h4> </div> <form class="form-horizontal" method="post" id="manualBackup"> <div class="modal-body sg-modal-body"> <!-- Multiple Radios --> <div class="form-group"> <div class="col-md-12"> <div class="radio"> <label for="fullbackup-radio"> <input type="radio" name="backupType" id="fullbackup-radio" value="1" checked="checked"> <?php _t('Full backup'); ?> </label> </div>
<?php require_once dirname(__FILE__) . '/../boot.php'; if (isAjax() && count($_POST)) { $state = (int) $_POST['reviewState']; SGConfig::set('SG_REVIEW_POPUP_STATE', $state); die('0'); }
<tr> <td><?php echo $backup['name']; ?> </td> <td><?php echo $backup['date']; ?> </td> <td id="sg-status-tabe-data" <?php echo $backup['active'] ? 'data-toggle="tooltip" data-placement="top" data-original-title="" data-container="#sg-wrapper"' : ''; ?> > <?php if ($backup['active']) { $activeOptions = json_decode(SGConfig::get('SG_ACTIVE_BACKUP_OPTIONS'), true); $filteredStatuses = filterStatusesByActionType($backup, $activeOptions); ?> <input type="hidden" id="sg-active-action-id" value="<?php echo $backup['id']; ?> "/> <?php foreach ($filteredStatuses as $statusCode) { ?> <span class="btn-xs sg-status-icon sg-status-<?php echo $statusCode; ?> "> </span> <?php }
<?php require_once dirname(__FILE__) . '/../boot.php'; $backupDirectory = SGConfig::get('SG_BACKUP_DIRECTORY'); $maxUploadSize = ini_get('upload_max_filesize'); ?> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title"><?php _t('Import'); ?> </h4> </div> <div class="modal-body sg-modal-body"> <div class="col-md-12"> <div class="form-group"> <label class="col-md-2 control-label sg-upload-label" for="textinput"><?php _t('SGBP file'); ?> </label> <div class="col-md-10"> <div class="input-group"> <span class="input-group-btn"> <span class="btn btn-primary btn-file"> <?php _t('Browse'); ?> … <input type="file" class="sg-backup-upload-input" name="sgbpFile" accept=".sgbp" data-max-file-size="<?php echo convertToBytes($maxUploadSize . 'B');
function backup_guard_schedule() { if (@in_array('wp-content', $_POST['directory'])) { $_POST['directory'] = array('wp-content'); } if ($_POST['backupType'] == SG_BACKUP_TYPE_FULL) { SGConfig::set('SG_BACKUP_FILE_PATHS', 'wp-content', false); } require_once SG_PUBLIC_AJAX_PATH . 'schedule.php'; }
function setManualBackupOptions($options) { $activeOptions = array('backupDatabase' => 0, 'backupFiles' => 0, 'ftp' => 0, 'gdrive' => 0, 'dropbox' => 0, 'background' => 0); //If background mode $isBackgroundMode = !empty($options['backgroundMode']) ? 1 : 0; SGConfig::set('SG_BACKUP_IN_BACKGROUND_MODE', $isBackgroundMode, false); $activeOptions['background'] = $isBackgroundMode; //If cloud backup if (!empty($options['backupCloud']) && count($options['backupStorages'])) { $clouds = $activeOptions['backupStorages'] = $options['backupStorages']; SGConfig::set('SG_BACKUP_UPLOAD_TO_STORAGES', implode(',', $clouds), false); $activeOptions['backupCloud'] = $options['backupCloud']; $activeOptions['gdrive'] = in_array(SG_STORAGE_GOOGLE_DRIVE, $options['backupStorages']) ? 1 : 0; $activeOptions['ftp'] = in_array(SG_STORAGE_FTP, $options['backupStorages']) ? 1 : 0; $activeOptions['dropbox'] = in_array(SG_STORAGE_DROPBOX, $options['backupStorages']) ? 1 : 0; } $activeOptions['backupType'] = $options['backupType']; if ($options['backupType'] == SG_BACKUP_TYPE_FULL) { SGConfig::set('SG_ACTION_BACKUP_DATABASE_AVAILABLE', 1, false); SGConfig::set('SG_ACTION_BACKUP_FILES_AVAILABLE', 1, false); SGConfig::set('SG_BACKUP_FILE_PATHS', 'wp-content', false); $activeOptions['backupDatabase'] = 1; $activeOptions['backupFiles'] = 1; } else { if ($options['backupType'] == SG_BACKUP_TYPE_CUSTOM) { //If database backup $isDatabaseBackup = !empty($options['backupDatabase']) ? 1 : 0; SGConfig::set('SG_ACTION_BACKUP_DATABASE_AVAILABLE', $isDatabaseBackup, false); $activeOptions['backupDatabase'] = $isDatabaseBackup; //If files backup if (@in_array('wp-content', $options['directory'])) { SGConfig::set('SG_ACTION_BACKUP_FILES_AVAILABLE', 1, false); SGConfig::set('SG_BACKUP_FILE_PATHS', 'wp-content', false); $activeOptions['backupFiles'] = 1; } else { if (!empty($options['backupFiles']) && count($options['directory'])) { $directories = $options['directory']; SGConfig::set('SG_ACTION_BACKUP_FILES_AVAILABLE', 1, false); SGConfig::set('SG_BACKUP_FILE_PATHS', implode(',', $directories), false); $activeOptions['backupFiles'] = 1; $activeOptions['directory'] = $directories; } else { SGConfig::set('SG_ACTION_BACKUP_FILES_AVAILABLE', 0, false); SGConfig::set('SG_BACKUP_FILE_PATHS', 0, false); } } } } SGConfig::set('SG_ACTIVE_BACKUP_OPTIONS', json_encode($activeOptions)); }
<?php require_once dirname(__FILE__) . '/boot.php'; require_once SG_PUBLIC_INCLUDE_PATH . '/header.php'; $isNotificationEnabled = SGConfig::get('SG_NOTIFICATIONS_ENABLED'); $userEmail = SGConfig::get('SG_NOTIFICATIONS_EMAIL_ADDRESS'); $isAnonymousStatisticsEnabled = SGConfig::get('SG_SEND_ANONYMOUS_STATISTICS'); $intervalSelectElement = array('1000' => '1 second', '2000' => '2 seconds', '3000' => '3 seconds', '5000' => '5 seconds', '7000' => '7 seconds', '10000' => '10 seconds'); $selectedInterval = SGConfig::get('SG_AJAX_REQUEST_FREQUENCY') ? SGConfig::get('SG_AJAX_REQUEST_FREQUENCY') : SG_AJAX_DEFAULT_REQUEST_FREQUENCY; require_once SG_PUBLIC_INCLUDE_PATH . 'sidebar.php'; ?> <div id="sg-content-wrapper"> <div class="container-fluid"> <div class="row sg-settings-container"> <div class="col-md-12"> <form class="form-horizontal" method="post" data-sgform="ajax" data-type="sgsettings"> <fieldset> <legend><?php echo _t('General settings'); ?> </legend> <?php if (SGBoot::isFeatureAvailable('NOTIFICATIONS')) { ?> <div class="form-group"> <label class="col-md-8 sg-control-label sg-user-info"> <?php echo _t('Email notifications'); if (!empty($userEmail)) { ?> <br/><span class="text-muted sg-user-email sg-helper-block"><?php
<?php require_once dirname(__FILE__) . '/../boot.php'; require_once SG_BACKUP_PATH . 'SGBackup.php'; if (isAjax()) { while (true) { $created = SGConfig::get('SG_RUNNING_ACTION', true); if ($created) { die('1'); } } die('2'); }
public function __construct() { $this->startTs = time(); $this->timeout = SGConfig::get('SG_RELOAD_INTERVAL'); }
<?php require_once dirname(__FILE__) . '/../boot.php'; require_once SG_BACKUP_PATH . 'SGBackup.php'; if (isAjax() && count($_POST)) { //Unset Active Options $activeOptions = array('database' => 0, 'files' => 0, 'ftp' => 0, 'gdrive' => 0, 'dropbox' => 0, 'background' => 0); SGConfig::set('SG_ACTIVE_BACKUP_OPTIONS', json_encode($activeOptions)); //Getting Backup Name $backupName = $_POST['bname']; $backup = new SGBackup(); $backup->restore($backupName); }
private static function prepare() { $backupPath = SGConfig::get('SG_BACKUP_DIRECTORY'); //create directory for backups if (!is_dir($backupPath)) { if (!@mkdir($backupPath)) { throw new SGExceptionMethodNotAllowed('Cannot create folder: ' . $backupPath); } if (!@file_put_contents($backupPath . '.htaccess', 'deny from all')) { throw new SGExceptionMethodNotAllowed('Cannot create htaccess file'); } } //check permissions of backups directory if (!is_writable($backupPath)) { throw new SGExceptionForbidden('Permission denied. Directory is not writable: ' . $backupPath); } }
private function getTables() { $tableNames = array(); $tables = $this->sgdb->query('SHOW TABLES FROM ' . SG_DB_NAME); if (!$tables) { throw new SGExceptionDatabaseError('Could not get tables of database: ' . SG_DB_NAME); } foreach ($tables as $table) { $tableName = $table['Tables_in_' . SG_DB_NAME]; $tablesToExclude = explode(',', SGConfig::get('SG_BACKUP_DATABASE_EXCLUDE')); if (in_array($tableName, $tablesToExclude)) { continue; } $tableNames[] = $tableName; } return $tableNames; }
function getReport() { $jsonArray = array(); $headerArray = array(); $jsonArray['ptype'] = '1'; $jsonArray['token'] = '28016ffb35b451291bfed7c5905474d6'; $lastReportTime = SGConfig::get('SG_LAST_REPORT_DATE'); if (!$lastReportTime) { SGConfig::set('SG_LAST_REPORT_DATE', time()); } SGBackup::getLogFileHeader($headerArray); $jsonArray['header'] = $headerArray; $jsonArray['header']['uid'] = sha1("http://" . @$_SERVER[HTTP_HOST] . @$_SERVER[REQUEST_URI]); $sgdb = SGDatabase::getInstance(); $res = $sgdb->query('SELECT type, subtype, status, count(*) AS scount FROM ' . SG_ACTION_TABLE_NAME . ' WHERE update_date > FROM_UNIXTIME(%d) GROUP BY type, subtype, status', array($lastReportTime)); if (count($res)) { foreach ($res as $item) { $jsonArray['log'][] = $item; } } return json_encode($jsonArray); }
private function resetRestoreProgress($restorePath) { $this->currentBackupFileCount = 0; $this->progressUpdateInterval = SGConfig::get('SG_ACTION_PROGRESS_UPDATE_INTERVAL'); $this->nextProgressUpdate = $this->progressUpdateInterval; }
?> </td> </tr> <?php } ?> </tbody> </table> <div class="text-right"> <ul class="pagination"></ul> </div> </fieldset> </div> <?php require_once SG_PUBLIC_INCLUDE_PATH . '/footer.php'; ?> <?php if (time() - SGConfig::get('SG_LAST_REPORT_DATE') > SG_REPORT_INTERVAL && SGConfig::get('SG_SEND_ANONYMOUS_STATISTICS') !== '0') { $report = base64_encode(getReport()); SGConfig::set('SG_LAST_REPORT_DATE', time()); ?> <script type="text/javascript">jQuery.post('https://backup-guard.com/tms/api', {report: "<?php echo $report; ?> "});</script> <?php } ?> </div> <div class="clearfix"></div>