Because cats have 9 lives, but servers don't - so they need backup-restore! Complete backup solution with S3/MinIO support. - Full WordPress backup (files + database) - S3 / MinIO / S3-compatible storage backends - Scheduled automatic backups - Disaster recovery / one-click restore - Backup integrity validation - Cat-themed admin interface Includes build.sh and .distignore for WordPress-installable release ZIPs.
139 lines
4.3 KiB
PHP
139 lines
4.3 KiB
PHP
<?php
|
|
/**
|
|
* TigerStyle Life9 Validator Class
|
|
*
|
|
* Input validation utilities
|
|
*
|
|
* @package TigerStyleLife9
|
|
* @subpackage Security
|
|
* @since 1.0.0
|
|
*/
|
|
|
|
// Exit if accessed directly
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* TigerStyle Life9 Input Validator
|
|
*
|
|
* Validates all input with cat-themed error messages
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
class TigerStyle_Life9_Validator {
|
|
|
|
/**
|
|
* Validate backup name
|
|
*
|
|
* @param string $name Backup name to validate
|
|
* @return array Validation result
|
|
*/
|
|
public static function validate_backup_name($name) {
|
|
$errors = [];
|
|
|
|
if (empty($name)) {
|
|
$errors[] = __('🙀 Backup name cannot be empty! Even cats need names for their territories.', 'tigerstyle-life9');
|
|
}
|
|
|
|
if (strlen($name) > 255) {
|
|
$errors[] = __('🙀 Backup name too long! Keep it shorter than a cat\'s attention span (255 characters).', 'tigerstyle-life9');
|
|
}
|
|
|
|
if (preg_match('/[<>:"/\\|?*]/', $name)) {
|
|
$errors[] = __('🙀 Invalid characters in backup name! Cats prefer simple, clean names.', 'tigerstyle-life9');
|
|
}
|
|
|
|
return [
|
|
'valid' => empty($errors),
|
|
'errors' => $errors
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Validate file path
|
|
*
|
|
* @param string $path File path to validate
|
|
* @return array Validation result
|
|
*/
|
|
public static function validate_file_path($path) {
|
|
$errors = [];
|
|
|
|
if (empty($path)) {
|
|
$errors[] = __('🙀 File path cannot be empty! Cats need to know where things are.', 'tigerstyle-life9');
|
|
}
|
|
|
|
if (strpos($path, '..') !== false) {
|
|
$errors[] = __('🙀 Path traversal detected! This cat is too clever for such tricks.', 'tigerstyle-life9');
|
|
}
|
|
|
|
if (strpos($path, '\0') !== false) {
|
|
$errors[] = __('🙀 Null bytes detected in path! Sneaky, but this cat sees everything.', 'tigerstyle-life9');
|
|
}
|
|
|
|
return [
|
|
'valid' => empty($errors),
|
|
'errors' => $errors
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Validate email address
|
|
*
|
|
* @param string $email Email to validate
|
|
* @return array Validation result
|
|
*/
|
|
public static function validate_email($email) {
|
|
$errors = [];
|
|
|
|
if (empty($email)) {
|
|
$errors[] = __('🙀 Email address cannot be empty! How will the cat send notifications?', 'tigerstyle-life9');
|
|
} elseif (!is_email($email)) {
|
|
$errors[] = __('🙀 Invalid email address! Cats are picky about proper formatting.', 'tigerstyle-life9');
|
|
}
|
|
|
|
return [
|
|
'valid' => empty($errors),
|
|
'errors' => $errors
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Validate backup configuration
|
|
*
|
|
* @param array $config Configuration to validate
|
|
* @return array Validation result
|
|
*/
|
|
public static function validate_backup_config($config) {
|
|
$errors = [];
|
|
|
|
// Validate backup name
|
|
if (isset($config['name'])) {
|
|
$name_validation = self::validate_backup_name($config['name']);
|
|
if (!$name_validation['valid']) {
|
|
$errors = array_merge($errors, $name_validation['errors']);
|
|
}
|
|
}
|
|
|
|
// Validate storage backend
|
|
if (isset($config['storage_backend'])) {
|
|
$allowed_backends = ['local', 's3', 'google_drive'];
|
|
if (!in_array($config['storage_backend'], $allowed_backends)) {
|
|
$errors[] = __('🙀 Invalid storage backend! This cat only knows local, S3, and Google Drive territories.', 'tigerstyle-life9');
|
|
}
|
|
}
|
|
|
|
// Validate that at least one backup type is selected
|
|
$include_files = isset($config['include_files']) ? (bool) $config['include_files'] : false;
|
|
$include_database = isset($config['include_database']) ? (bool) $config['include_database'] : false;
|
|
|
|
if (!$include_files && !$include_database) {
|
|
$errors[] = __('🙀 You must select at least files or database! Cats need something to backup.', 'tigerstyle-life9');
|
|
}
|
|
|
|
return [
|
|
'valid' => empty($errors),
|
|
'errors' => $errors
|
|
];
|
|
}
|
|
} |