<?php
// phpcs:ignoreFile
/**
* The preset class.
*
* @since 5.3.0
*/
namespace LiteSpeed;
defined('WPINC') || exit();
class Preset extends Import {
protected $_summary;
const MAX_BACKUPS = 10;
const TYPE_APPLY = 'apply';
const TYPE_RESTORE = 'restore';
const STANDARD_DIR = LSCWP_DIR . 'data/preset';
const BACKUP_DIR = LITESPEED_STATIC_DIR . '/auto-backup';
/**
* Returns sorted backup names
*
* @since 5.3.0
* @access public
*/
public static function get_backups() {
self::init_filesystem();
global $wp_filesystem;
$backups = array_map(
function ( $path ) {
return self::basename($path['name']);
},
$wp_filesystem->dirlist(self::BACKUP_DIR) ?: array()
);
rsort($backups);
return $backups;
}
/**
* Removes extra backup files
*
* @since 5.3.0
* @access public
*/
public static function prune_backups() {
$backups = self::get_backups();
global $wp_filesystem;
foreach (array_slice($backups, self::MAX_BACKUPS) as $backup) {
$path = self::get_backup($backup);
$wp_filesystem->delete($path);
Debug2::debug('[Preset] Deleted old backup from ' . $backup);
}
}
/**
* Returns a settings file's extensionless basename given its filesystem path
*
* @since 5.3.0
* @access public
*/
public static function basename( $path ) {
return basename($path, '.data');
}
/**
* Returns a standard preset's path given its extensionless basename
*
* @since 5.3.0
* @access public
*/
public static function get_standard( $name ) {
return path_join(self::STANDARD_DIR, $name . '.data');
}
/**
* Returns a backup's path given its extensionless basename
*
* @since 5.3.0
* @access public
*/
public static function get_backup( $name ) {
return path_join(self::BACKUP_DIR, $name . '.data');
}
/**
* Initializes the global $wp_filesystem object and clears stat cache
*
* @since 5.3.0
*/
static function init_filesystem() {
require_once ABSPATH . '/wp-admin/includes/file.php';
\WP_Filesystem();
clearstatcache();
}
/**
* Init
*
* @since 5.3.0
*/
public function __construct() {
Debug2::debug('[Preset] Init');
$this->_summary = self::get_summary();
}
/**
* Applies a standard preset's settings given its extensionless basename
*
* @since 5.3.0
* @access public
*/
public function apply( $preset ) {
$this->make_backup($preset);
$path = self::get_standard($preset);
$result = $this->import_file($path) ? $preset : 'error';
$this->log($result);
}
/**
* Restores settings from the backup file with the given timestamp, then deletes the file
*
* @since 5.3.0
* @access public
*/
public function restore( $timestamp ) {
$backups = array();
foreach (self::get_backups() as $backup) {
if (preg_match('/^backup-' . $timestamp . '(-|$)/', $backup) === 1) {
$backups[] = $backup;
}
}
if (empty($backups)) {
$this->log('error');
return;
}
$backup = $backups[0];
$path = self::get_backup($backup);
if (!$this->import_file($path)) {
$this->log('error');
return;
}
self::init_filesystem();
global $wp_filesystem;
$wp_filesystem->delete($path);
Debug2::debug('[Preset] Deleted most recent backup from ' . $backup);
$this->log('backup');
}
/**
* Saves current settings as a backup file, then prunes extra backup files
*
* @since 5.3.0
* @access public
*/
public function make_backup( $preset ) {
$backup = 'backup-' . time() . '-before-' . $preset;
$data = $this->export(true);
$path = self::get_backup($backup);
File::save($path, $data, true);
Debug2::debug('[Preset] Backup saved to ' . $backup);
self::prune_backups();
}
/**
* Tries to import from a given settings file
*
* @since 5.3.0
*/
function import_file( $path ) {
$debug = function ( $result, $name ) {
$action = $result ? 'Applied' : 'Failed to apply';
Debug2::debug('[Preset] ' . $action . ' settings from ' . $name);
return $result;
};
$name = self::basename($path);
$contents = file_get_contents($path);
if (false === $contents) {
Debug2::debug('[Preset] ❌ Failed to get file contents');
return $debug(false, $name);
}
$parsed = array();
try {
// Check if the data is v4+
if (strpos($contents, '["_version",') === 0) {
$contents = explode("\n", $contents);
foreach ($contents as $line) {
$line = trim($line);
if (empty($line)) {
continue;
}
list($key, $value) = \json_decode($line, true);
$parsed[$key] = $value;
}
} else {
$parsed = \json_decode(base64_decode($contents), true);
}
} catch (\Exception $ex) {
Debug2::debug('[Preset] ❌ Failed to parse serialized data');
return $debug(false, $name);
}
if (empty($parsed)) {
Debug2::debug('[Preset] ❌ Nothing to apply');
return $debug(false, $name);
}
$this->cls('Conf')->update_confs($parsed);
return $debug(true, $name);
}
/**
* Updates the log
*
* @since 5.3.0
*/
function log( $preset ) {
$this->_summary['preset'] = $preset;
$this->_summary['preset_timestamp'] = time();
self::save_summary();
}
/**
* Handles all request actions from main cls
*
* @since 5.3.0
* @access public
*/
public function handler() {
$type = Router::verify_type();
switch ($type) {
case self::TYPE_APPLY:
$this->apply(!empty($_GET['preset']) ? $_GET['preset'] : false);
break;
case self::TYPE_RESTORE:
$this->restore(!empty($_GET['timestamp']) ? $_GET['timestamp'] : false);
break;
default:
break;
}
Admin::redirect();
}
}
| nama | waktu | ukuran | owner | perm | aksi |
|---|---|---|---|---|---|
| .. | |||||
| cdn/ | 2026-06-06 16:18 | 11.25 KB | 76129f60960:kunden | dxwrx-r--r | |
| data_structure/ | 2026-06-06 16:18 | 2.62 KB | 76129f60960:kunden | dxwrx-r--r | |
| activation.cls.php | 2026-06-06 16:18 | 17.31 KB | 76129f60960:kunden | -xw-x----- | |
| admin-display.cls.php | 2026-06-06 16:18 | 48.47 KB | 76129f60960:kunden | -xw-x----- | |
| admin-settings.cls.php | 2026-06-06 16:18 | 11.12 KB | 76129f60960:kunden | -xw-x----- | |
| admin.cls.php | 2026-06-06 16:18 | 6.13 KB | 76129f60960:kunden | -xw-x----- | |
| api.cls.php | 2026-06-06 16:18 | 10.36 KB | 76129f60960:kunden | -xw-x----- | |
| avatar.cls.php | 2026-06-06 16:18 | 8.65 KB | 76129f60960:kunden | -xw-x----- | |
| base.cls.php | 2026-06-06 16:18 | 37.66 KB | 76129f60960:kunden | -xw-x----- | |
| cdn.cls.php | 2026-06-06 16:18 | 15.92 KB | 76129f60960:kunden | -xw-x----- | |
| cloud-auth-callback.trait.php | 2026-06-06 16:18 | 10.43 KB | 76129f60960:kunden | -xw-x----- | |
| cloud-auth-ip.trait.php | 2026-06-06 16:18 | 4.33 KB | 76129f60960:kunden | -xw-x----- | |
| cloud-auth.trait.php | 2026-06-06 16:18 | 9.38 KB | 76129f60960:kunden | -xw-x----- | |
| cloud-misc.trait.php | 2026-06-06 16:18 | 10.32 KB | 76129f60960:kunden | -xw-x----- | |
| cloud-node.trait.php | 2026-06-06 16:18 | 5.95 KB | 76129f60960:kunden | -xw-x----- | |
| cloud-request.trait.php | 2026-06-06 16:18 | 19.68 KB | 76129f60960:kunden | -xw-x----- | |
| cloud.cls.php | 2026-06-06 16:18 | 7.32 KB | 76129f60960:kunden | -xw-x----- | |
| conf.cls.php | 2026-06-06 16:18 | 19.53 KB | 76129f60960:kunden | -xw-x----- | |
| control.cls.php | 2026-06-06 16:18 | 24.35 KB | 76129f60960:kunden | -xw-x----- | |
| core.cls.php | 2026-06-06 16:18 | 20.97 KB | 76129f60960:kunden | -xw-x----- | |
| crawler-map.cls.php | 2026-06-06 16:18 | 19.41 KB | 76129f60960:kunden | -xw-x----- | |
| crawler.cls.php | 2026-06-06 16:18 | 44.72 KB | 76129f60960:kunden | -xw-x----- | |
| css.cls.php | 2026-06-06 16:18 | 17.77 KB | 76129f60960:kunden | -xw-x----- | |
| data.cls.php | 2026-06-06 16:18 | 22.21 KB | 76129f60960:kunden | -xw-x----- | |
| data.upgrade.func.php | 2026-06-06 16:18 | 5.72 KB | 76129f60960:kunden | -xw-x----- | |
| db-optm.cls.php | 2026-06-06 16:18 | 15.35 KB | 76129f60960:kunden | -xw-x----- | |
| debug2.cls.php | 2026-06-06 16:18 | 18.4 KB | 76129f60960:kunden | -xw-x----- | |
| doc.cls.php | 2026-06-06 16:18 | 5.45 KB | 76129f60960:kunden | -xw-x----- | |
| error.cls.php | 2026-06-06 16:18 | 7.35 KB | 76129f60960:kunden | -xw-x----- | |
| esi.cls.php | 2026-06-06 16:18 | 27.18 KB | 76129f60960:kunden | -xw-x----- | |
| file.cls.php | 2026-06-06 16:18 | 10.57 KB | 76129f60960:kunden | -xw-x----- | |
| guest.cls.php | 2026-06-06 16:18 | 2.75 KB | 76129f60960:kunden | -xw-x----- | |
| gui.cls.php | 2026-06-06 16:18 | 36.57 KB | 76129f60960:kunden | -xw-x----- | |
| health.cls.php | 2026-06-06 16:18 | 2.83 KB | 76129f60960:kunden | -xw-x----- | |
| htaccess.cls.php | 2026-06-06 16:18 | 29.81 KB | 76129f60960:kunden | -xw-x----- | |
| img-optm-manage.trait.php | 2026-06-06 16:18 | 30.85 KB | 76129f60960:kunden | -xw-x----- | |
| img-optm-pull.trait.php | 2026-06-06 16:18 | 22.1 KB | 76129f60960:kunden | -xw-x----- | |
| img-optm-send.trait.php | 2026-06-06 16:18 | 21.9 KB | 76129f60960:kunden | -xw-x----- | |
| img-optm.cls.php | 2026-06-06 16:18 | 5.26 KB | 76129f60960:kunden | -xw-x----- | |
| import.cls.php | 2026-06-06 16:18 | 4.29 KB | 76129f60960:kunden | -xw-x----- | |
| import.preset.cls.php | 2026-06-06 16:18 | 5.5 KB | 76129f60960:kunden | -xw-x----- | |
| lang.cls.php | 2026-06-06 16:18 | 17.02 KB | 76129f60960:kunden | -xw-x----- | |
| localization.cls.php | 2026-06-06 16:18 | 4.03 KB | 76129f60960:kunden | -xw-x----- | |
| media.cls.php | 2026-06-06 16:18 | 44.08 KB | 76129f60960:kunden | -xw-x----- | |
| metabox.cls.php | 2026-06-06 16:18 | 5.29 KB | 76129f60960:kunden | -xw-x----- | |
| object-cache-wp.cls.php | 2026-06-06 16:18 | 18.82 KB | 76129f60960:kunden | -xw-x----- | |
| object-cache.cls.php | 2026-06-06 16:18 | 20.95 KB | 76129f60960:kunden | -xw-x----- | |
| object.lib.php | 2026-06-06 16:18 | 14.16 KB | 76129f60960:kunden | -xw-x----- | |
| optimize.cls.php | 2026-06-06 16:18 | 38.64 KB | 76129f60960:kunden | -xw-x----- | |
| optimizer.cls.php | 2026-06-06 16:18 | 10.5 KB | 76129f60960:kunden | -xw-x----- | |
| placeholder.cls.php | 2026-06-06 16:18 | 17.93 KB | 76129f60960:kunden | -xw-x----- | |
| purge.cls.php | 2026-06-06 16:18 | 34.41 KB | 76129f60960:kunden | -xw-x----- | |
| report.cls.php | 2026-06-06 16:18 | 6.12 KB | 76129f60960:kunden | -xw-x----- | |
| rest.cls.php | 2026-06-06 16:18 | 9.08 KB | 76129f60960:kunden | -xw-x----- | |
| root.cls.php | 2026-06-06 16:18 | 14.29 KB | 76129f60960:kunden | -xw-x----- | |
| router.cls.php | 2026-06-06 16:18 | 20.76 KB | 76129f60960:kunden | -xw-x----- | |
| str.cls.php | 2026-06-06 16:18 | 3.08 KB | 76129f60960:kunden | -xw-x----- | |
| tag.cls.php | 2026-06-06 16:18 | 9.26 KB | 76129f60960:kunden | -xw-x----- | |
| task.cls.php | 2026-06-06 16:18 | 7.05 KB | 76129f60960:kunden | -xw-x----- | |
| tool.cls.php | 2026-06-06 16:18 | 4.17 KB | 76129f60960:kunden | -xw-x----- | |
| ucss.cls.php | 2026-06-06 16:18 | 16.35 KB | 76129f60960:kunden | -xw-x----- | |
| utility.cls.php | 2026-06-06 16:18 | 26.01 KB | 76129f60960:kunden | -xw-x----- | |
| vary.cls.php | 2026-06-06 16:18 | 21.33 KB | 76129f60960:kunden | -xw-x----- | |
| vpi.cls.php | 2026-06-06 16:18 | 9.38 KB | 76129f60960:kunden | -xw-x----- | |