v-wordpress-plugin-updater/update-api/classes/forms/PlFormHandler.php

116 lines
4.3 KiB
PHP
Raw Normal View History

modified: .gitignore modified: README.md modified: mu-plugin/v-sys-plugin-updater-mu.php modified: mu-plugin/v-sys-plugin-updater.php modified: mu-plugin/v-sys-theme-updater.php deleted: update-api/app/forms/home-forms.php deleted: update-api/app/forms/plupdate-forms.php deleted: update-api/app/forms/thupdate-forms.php deleted: update-api/app/helpers/home-helper.php deleted: update-api/app/helpers/logs-helper.php deleted: update-api/app/helpers/plupdate-helper.php deleted: update-api/app/helpers/thupdate-helper.php new file: update-api/classes/forms/HomeFormHandler.php new file: update-api/classes/forms/PlFormHandler.php new file: update-api/classes/forms/ThFormHandler.php new file: update-api/classes/helpers/HomeHelper.php new file: update-api/classes/helpers/LogsHelper.php new file: update-api/classes/helpers/PlHelper.php new file: update-api/classes/helpers/ThHelper.php new file: update-api/classes/util/security.php modified: update-api/lib/auth-lib.php new file: update-api/lib/class-lib.php modified: update-api/lib/load-lib.php deleted: update-api/lib/waf-lib.php modified: update-api/public/.htaccess new file: update-api/public/api.php modified: update-api/public/assets/css/login.css modified: update-api/public/assets/css/mobile.css deleted: update-api/public/assets/css/pages.css modified: update-api/public/assets/css/styles.css modified: update-api/public/index.php modified: update-api/public/login.php deleted: update-api/public/plugins/api.php deleted: update-api/public/plugins/download.php deleted: update-api/public/themes/api.php deleted: update-api/public/themes/download.php renamed: update-api/app/pages/home.php -> update-api/views/home.php renamed: update-api/app/pages/logs.php -> update-api/views/logs.php renamed: update-api/app/pages/plupdate.php -> update-api/views/plupdate.php renamed: update-api/app/pages/thupdate.php -> update-api/views/thupdate.php
2025-06-29 14:59:47 -04:00
<?php
2025-07-04 20:30:15 -04:00
// @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
modified: .gitignore modified: README.md modified: mu-plugin/v-sys-plugin-updater-mu.php modified: mu-plugin/v-sys-plugin-updater.php modified: mu-plugin/v-sys-theme-updater.php deleted: update-api/app/forms/home-forms.php deleted: update-api/app/forms/plupdate-forms.php deleted: update-api/app/forms/thupdate-forms.php deleted: update-api/app/helpers/home-helper.php deleted: update-api/app/helpers/logs-helper.php deleted: update-api/app/helpers/plupdate-helper.php deleted: update-api/app/helpers/thupdate-helper.php new file: update-api/classes/forms/HomeFormHandler.php new file: update-api/classes/forms/PlFormHandler.php new file: update-api/classes/forms/ThFormHandler.php new file: update-api/classes/helpers/HomeHelper.php new file: update-api/classes/helpers/LogsHelper.php new file: update-api/classes/helpers/PlHelper.php new file: update-api/classes/helpers/ThHelper.php new file: update-api/classes/util/security.php modified: update-api/lib/auth-lib.php new file: update-api/lib/class-lib.php modified: update-api/lib/load-lib.php deleted: update-api/lib/waf-lib.php modified: update-api/public/.htaccess new file: update-api/public/api.php modified: update-api/public/assets/css/login.css modified: update-api/public/assets/css/mobile.css deleted: update-api/public/assets/css/pages.css modified: update-api/public/assets/css/styles.css modified: update-api/public/index.php modified: update-api/public/login.php deleted: update-api/public/plugins/api.php deleted: update-api/public/plugins/download.php deleted: update-api/public/themes/api.php deleted: update-api/public/themes/download.php renamed: update-api/app/pages/home.php -> update-api/views/home.php renamed: update-api/app/pages/logs.php -> update-api/views/logs.php renamed: update-api/app/pages/plupdate.php -> update-api/views/plupdate.php renamed: update-api/app/pages/thupdate.php -> update-api/views/thupdate.php
2025-06-29 14:59:47 -04:00
/*
* Project: Update API
* Author: Vontainment
* URL: https://vontainment.com
* File: PluginUpdateFormHandler.php
* Description: WordPress Update API
*/
class PlFormHandler
{
2025-07-04 20:16:50 -04:00
public function handleRequest(): void
modified: .gitignore modified: README.md modified: mu-plugin/v-sys-plugin-updater-mu.php modified: mu-plugin/v-sys-plugin-updater.php modified: mu-plugin/v-sys-theme-updater.php deleted: update-api/app/forms/home-forms.php deleted: update-api/app/forms/plupdate-forms.php deleted: update-api/app/forms/thupdate-forms.php deleted: update-api/app/helpers/home-helper.php deleted: update-api/app/helpers/logs-helper.php deleted: update-api/app/helpers/plupdate-helper.php deleted: update-api/app/helpers/thupdate-helper.php new file: update-api/classes/forms/HomeFormHandler.php new file: update-api/classes/forms/PlFormHandler.php new file: update-api/classes/forms/ThFormHandler.php new file: update-api/classes/helpers/HomeHelper.php new file: update-api/classes/helpers/LogsHelper.php new file: update-api/classes/helpers/PlHelper.php new file: update-api/classes/helpers/ThHelper.php new file: update-api/classes/util/security.php modified: update-api/lib/auth-lib.php new file: update-api/lib/class-lib.php modified: update-api/lib/load-lib.php deleted: update-api/lib/waf-lib.php modified: update-api/public/.htaccess new file: update-api/public/api.php modified: update-api/public/assets/css/login.css modified: update-api/public/assets/css/mobile.css deleted: update-api/public/assets/css/pages.css modified: update-api/public/assets/css/styles.css modified: update-api/public/index.php modified: update-api/public/login.php deleted: update-api/public/plugins/api.php deleted: update-api/public/plugins/download.php deleted: update-api/public/themes/api.php deleted: update-api/public/themes/download.php renamed: update-api/app/pages/home.php -> update-api/views/home.php renamed: update-api/app/pages/logs.php -> update-api/views/logs.php renamed: update-api/app/pages/plupdate.php -> update-api/views/plupdate.php renamed: update-api/app/pages/thupdate.php -> update-api/views/thupdate.php
2025-06-29 14:59:47 -04:00
{
if (
$_SERVER['REQUEST_METHOD'] === 'POST'
&& isset($_POST['csrf_token'], $_SESSION['csrf_token'])
&& $_POST['csrf_token'] === $_SESSION['csrf_token']
) {
2025-07-04 21:29:02 -04:00
// Validate POST and FILES inputs
modified: .gitignore modified: README.md modified: mu-plugin/v-sys-plugin-updater-mu.php modified: mu-plugin/v-sys-plugin-updater.php modified: mu-plugin/v-sys-theme-updater.php deleted: update-api/app/forms/home-forms.php deleted: update-api/app/forms/plupdate-forms.php deleted: update-api/app/forms/thupdate-forms.php deleted: update-api/app/helpers/home-helper.php deleted: update-api/app/helpers/logs-helper.php deleted: update-api/app/helpers/plupdate-helper.php deleted: update-api/app/helpers/thupdate-helper.php new file: update-api/classes/forms/HomeFormHandler.php new file: update-api/classes/forms/PlFormHandler.php new file: update-api/classes/forms/ThFormHandler.php new file: update-api/classes/helpers/HomeHelper.php new file: update-api/classes/helpers/LogsHelper.php new file: update-api/classes/helpers/PlHelper.php new file: update-api/classes/helpers/ThHelper.php new file: update-api/classes/util/security.php modified: update-api/lib/auth-lib.php new file: update-api/lib/class-lib.php modified: update-api/lib/load-lib.php deleted: update-api/lib/waf-lib.php modified: update-api/public/.htaccess new file: update-api/public/api.php modified: update-api/public/assets/css/login.css modified: update-api/public/assets/css/mobile.css deleted: update-api/public/assets/css/pages.css modified: update-api/public/assets/css/styles.css modified: update-api/public/index.php modified: update-api/public/login.php deleted: update-api/public/plugins/api.php deleted: update-api/public/plugins/download.php deleted: update-api/public/themes/api.php deleted: update-api/public/themes/download.php renamed: update-api/app/pages/home.php -> update-api/views/home.php renamed: update-api/app/pages/logs.php -> update-api/views/logs.php renamed: update-api/app/pages/plupdate.php -> update-api/views/plupdate.php renamed: update-api/app/pages/thupdate.php -> update-api/views/thupdate.php
2025-06-29 14:59:47 -04:00
if (isset($_FILES['plugin_file'])) {
$this->uploadPluginFiles();
} elseif (isset($_POST['delete_plugin'])) {
2025-07-04 21:29:02 -04:00
$plugin_name = isset($_POST['plugin_name']) ? SecurityHandler::validateSlug($_POST['plugin_name']) : null;
modified: .gitignore modified: README.md modified: mu-plugin/v-sys-plugin-updater-mu.php modified: mu-plugin/v-sys-plugin-updater.php modified: mu-plugin/v-sys-theme-updater.php deleted: update-api/app/forms/home-forms.php deleted: update-api/app/forms/plupdate-forms.php deleted: update-api/app/forms/thupdate-forms.php deleted: update-api/app/helpers/home-helper.php deleted: update-api/app/helpers/logs-helper.php deleted: update-api/app/helpers/plupdate-helper.php deleted: update-api/app/helpers/thupdate-helper.php new file: update-api/classes/forms/HomeFormHandler.php new file: update-api/classes/forms/PlFormHandler.php new file: update-api/classes/forms/ThFormHandler.php new file: update-api/classes/helpers/HomeHelper.php new file: update-api/classes/helpers/LogsHelper.php new file: update-api/classes/helpers/PlHelper.php new file: update-api/classes/helpers/ThHelper.php new file: update-api/classes/util/security.php modified: update-api/lib/auth-lib.php new file: update-api/lib/class-lib.php modified: update-api/lib/load-lib.php deleted: update-api/lib/waf-lib.php modified: update-api/public/.htaccess new file: update-api/public/api.php modified: update-api/public/assets/css/login.css modified: update-api/public/assets/css/mobile.css deleted: update-api/public/assets/css/pages.css modified: update-api/public/assets/css/styles.css modified: update-api/public/index.php modified: update-api/public/login.php deleted: update-api/public/plugins/api.php deleted: update-api/public/plugins/download.php deleted: update-api/public/themes/api.php deleted: update-api/public/themes/download.php renamed: update-api/app/pages/home.php -> update-api/views/home.php renamed: update-api/app/pages/logs.php -> update-api/views/logs.php renamed: update-api/app/pages/plupdate.php -> update-api/views/plupdate.php renamed: update-api/app/pages/thupdate.php -> update-api/views/thupdate.php
2025-06-29 14:59:47 -04:00
$this->deletePlugin($plugin_name);
} else {
die('Invalid form action.');
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
die('Invalid CSRF token.');
}
}
2025-07-04 20:16:50 -04:00
private function uploadPluginFiles(): void
modified: .gitignore modified: README.md modified: mu-plugin/v-sys-plugin-updater-mu.php modified: mu-plugin/v-sys-plugin-updater.php modified: mu-plugin/v-sys-theme-updater.php deleted: update-api/app/forms/home-forms.php deleted: update-api/app/forms/plupdate-forms.php deleted: update-api/app/forms/thupdate-forms.php deleted: update-api/app/helpers/home-helper.php deleted: update-api/app/helpers/logs-helper.php deleted: update-api/app/helpers/plupdate-helper.php deleted: update-api/app/helpers/thupdate-helper.php new file: update-api/classes/forms/HomeFormHandler.php new file: update-api/classes/forms/PlFormHandler.php new file: update-api/classes/forms/ThFormHandler.php new file: update-api/classes/helpers/HomeHelper.php new file: update-api/classes/helpers/LogsHelper.php new file: update-api/classes/helpers/PlHelper.php new file: update-api/classes/helpers/ThHelper.php new file: update-api/classes/util/security.php modified: update-api/lib/auth-lib.php new file: update-api/lib/class-lib.php modified: update-api/lib/load-lib.php deleted: update-api/lib/waf-lib.php modified: update-api/public/.htaccess new file: update-api/public/api.php modified: update-api/public/assets/css/login.css modified: update-api/public/assets/css/mobile.css deleted: update-api/public/assets/css/pages.css modified: update-api/public/assets/css/styles.css modified: update-api/public/index.php modified: update-api/public/login.php deleted: update-api/public/plugins/api.php deleted: update-api/public/plugins/download.php deleted: update-api/public/themes/api.php deleted: update-api/public/themes/download.php renamed: update-api/app/pages/home.php -> update-api/views/home.php renamed: update-api/app/pages/logs.php -> update-api/views/logs.php renamed: update-api/app/pages/plupdate.php -> update-api/views/plupdate.php renamed: update-api/app/pages/thupdate.php -> update-api/views/thupdate.php
2025-06-29 14:59:47 -04:00
{
$allowed_extensions = ['zip'];
$total_files = count($_FILES['plugin_file']['name']);
for ($i = 0; $i < $total_files; $i++) {
$file_name = isset($_FILES['plugin_file']['name'][$i])
2025-07-04 21:29:02 -04:00
? SecurityHandler::validateFilename($_FILES['plugin_file']['name'][$i])
modified: .gitignore modified: README.md modified: mu-plugin/v-sys-plugin-updater-mu.php modified: mu-plugin/v-sys-plugin-updater.php modified: mu-plugin/v-sys-theme-updater.php deleted: update-api/app/forms/home-forms.php deleted: update-api/app/forms/plupdate-forms.php deleted: update-api/app/forms/thupdate-forms.php deleted: update-api/app/helpers/home-helper.php deleted: update-api/app/helpers/logs-helper.php deleted: update-api/app/helpers/plupdate-helper.php deleted: update-api/app/helpers/thupdate-helper.php new file: update-api/classes/forms/HomeFormHandler.php new file: update-api/classes/forms/PlFormHandler.php new file: update-api/classes/forms/ThFormHandler.php new file: update-api/classes/helpers/HomeHelper.php new file: update-api/classes/helpers/LogsHelper.php new file: update-api/classes/helpers/PlHelper.php new file: update-api/classes/helpers/ThHelper.php new file: update-api/classes/util/security.php modified: update-api/lib/auth-lib.php new file: update-api/lib/class-lib.php modified: update-api/lib/load-lib.php deleted: update-api/lib/waf-lib.php modified: update-api/public/.htaccess new file: update-api/public/api.php modified: update-api/public/assets/css/login.css modified: update-api/public/assets/css/mobile.css deleted: update-api/public/assets/css/pages.css modified: update-api/public/assets/css/styles.css modified: update-api/public/index.php modified: update-api/public/login.php deleted: update-api/public/plugins/api.php deleted: update-api/public/plugins/download.php deleted: update-api/public/themes/api.php deleted: update-api/public/themes/download.php renamed: update-api/app/pages/home.php -> update-api/views/home.php renamed: update-api/app/pages/logs.php -> update-api/views/logs.php renamed: update-api/app/pages/plupdate.php -> update-api/views/plupdate.php renamed: update-api/app/pages/thupdate.php -> update-api/views/thupdate.php
2025-06-29 14:59:47 -04:00
: '';
$file_tmp = isset($_FILES['plugin_file']['tmp_name'][$i])
? $_FILES['plugin_file']['tmp_name'][$i]
: '';
$file_size = isset($_FILES['plugin_file']['size'][$i])
? filter_var($_FILES['plugin_file']['size'][$i], FILTER_VALIDATE_INT)
: 0;
$file_error = isset($_FILES['plugin_file']['error'][$i])
? filter_var($_FILES['plugin_file']['error'][$i], FILTER_VALIDATE_INT)
: UPLOAD_ERR_NO_FILE;
$file_extension = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
$plugin_slug = explode("_", $file_name)[0];
$existing_plugins = glob(PLUGINS_DIR . '/' . $plugin_slug . '_*');
foreach ($existing_plugins as $plugin) {
if (is_file($plugin)) {
unlink($plugin);
}
}
if ($file_error !== UPLOAD_ERR_OK || !in_array($file_extension, $allowed_extensions)) {
echo '<script>'
. 'alert("Error uploading: '
. htmlspecialchars($file_name, ENT_QUOTES, 'UTF-8')
. '. Only .zip files are allowed.");'
. 'window.location.href = "/plupdate";'
. '</script>';
exit;
}
$plugin_path = PLUGINS_DIR . '/' . $file_name;
if (move_uploaded_file($file_tmp, $plugin_path)) {
echo '<script>'
. 'alert("'
. htmlspecialchars($file_name, ENT_QUOTES, 'UTF-8')
. ' uploaded successfully.");'
. 'window.location.href = "/plupdate";'
. '</script>';
} else {
echo '<script>'
. 'alert("Error uploading: '
. htmlspecialchars($file_name, ENT_QUOTES, 'UTF-8')
. '");'
. 'window.location.href = "/plupdate";'
. '</script>';
}
}
}
2025-07-04 20:16:50 -04:00
private function deletePlugin(?string $plugin_name): void
modified: .gitignore modified: README.md modified: mu-plugin/v-sys-plugin-updater-mu.php modified: mu-plugin/v-sys-plugin-updater.php modified: mu-plugin/v-sys-theme-updater.php deleted: update-api/app/forms/home-forms.php deleted: update-api/app/forms/plupdate-forms.php deleted: update-api/app/forms/thupdate-forms.php deleted: update-api/app/helpers/home-helper.php deleted: update-api/app/helpers/logs-helper.php deleted: update-api/app/helpers/plupdate-helper.php deleted: update-api/app/helpers/thupdate-helper.php new file: update-api/classes/forms/HomeFormHandler.php new file: update-api/classes/forms/PlFormHandler.php new file: update-api/classes/forms/ThFormHandler.php new file: update-api/classes/helpers/HomeHelper.php new file: update-api/classes/helpers/LogsHelper.php new file: update-api/classes/helpers/PlHelper.php new file: update-api/classes/helpers/ThHelper.php new file: update-api/classes/util/security.php modified: update-api/lib/auth-lib.php new file: update-api/lib/class-lib.php modified: update-api/lib/load-lib.php deleted: update-api/lib/waf-lib.php modified: update-api/public/.htaccess new file: update-api/public/api.php modified: update-api/public/assets/css/login.css modified: update-api/public/assets/css/mobile.css deleted: update-api/public/assets/css/pages.css modified: update-api/public/assets/css/styles.css modified: update-api/public/index.php modified: update-api/public/login.php deleted: update-api/public/plugins/api.php deleted: update-api/public/plugins/download.php deleted: update-api/public/themes/api.php deleted: update-api/public/themes/download.php renamed: update-api/app/pages/home.php -> update-api/views/home.php renamed: update-api/app/pages/logs.php -> update-api/views/logs.php renamed: update-api/app/pages/plupdate.php -> update-api/views/plupdate.php renamed: update-api/app/pages/thupdate.php -> update-api/views/thupdate.php
2025-06-29 14:59:47 -04:00
{
2025-07-04 21:29:02 -04:00
$plugin_name = SecurityHandler::validateFilename($plugin_name);
$plugin_name = basename((string) $plugin_name);
modified: .gitignore modified: README.md modified: mu-plugin/v-sys-plugin-updater-mu.php modified: mu-plugin/v-sys-plugin-updater.php modified: mu-plugin/v-sys-theme-updater.php deleted: update-api/app/forms/home-forms.php deleted: update-api/app/forms/plupdate-forms.php deleted: update-api/app/forms/thupdate-forms.php deleted: update-api/app/helpers/home-helper.php deleted: update-api/app/helpers/logs-helper.php deleted: update-api/app/helpers/plupdate-helper.php deleted: update-api/app/helpers/thupdate-helper.php new file: update-api/classes/forms/HomeFormHandler.php new file: update-api/classes/forms/PlFormHandler.php new file: update-api/classes/forms/ThFormHandler.php new file: update-api/classes/helpers/HomeHelper.php new file: update-api/classes/helpers/LogsHelper.php new file: update-api/classes/helpers/PlHelper.php new file: update-api/classes/helpers/ThHelper.php new file: update-api/classes/util/security.php modified: update-api/lib/auth-lib.php new file: update-api/lib/class-lib.php modified: update-api/lib/load-lib.php deleted: update-api/lib/waf-lib.php modified: update-api/public/.htaccess new file: update-api/public/api.php modified: update-api/public/assets/css/login.css modified: update-api/public/assets/css/mobile.css deleted: update-api/public/assets/css/pages.css modified: update-api/public/assets/css/styles.css modified: update-api/public/index.php modified: update-api/public/login.php deleted: update-api/public/plugins/api.php deleted: update-api/public/plugins/download.php deleted: update-api/public/themes/api.php deleted: update-api/public/themes/download.php renamed: update-api/app/pages/home.php -> update-api/views/home.php renamed: update-api/app/pages/logs.php -> update-api/views/logs.php renamed: update-api/app/pages/plupdate.php -> update-api/views/plupdate.php renamed: update-api/app/pages/thupdate.php -> update-api/views/thupdate.php
2025-06-29 14:59:47 -04:00
$plugin_path = PLUGINS_DIR . '/' . $plugin_name;
2025-07-04 19:30:40 -04:00
if (
file_exists($plugin_path)
&& dirname(realpath($plugin_path)) === realpath(PLUGINS_DIR)
) {
modified: .gitignore modified: README.md modified: mu-plugin/v-sys-plugin-updater-mu.php modified: mu-plugin/v-sys-plugin-updater.php modified: mu-plugin/v-sys-theme-updater.php deleted: update-api/app/forms/home-forms.php deleted: update-api/app/forms/plupdate-forms.php deleted: update-api/app/forms/thupdate-forms.php deleted: update-api/app/helpers/home-helper.php deleted: update-api/app/helpers/logs-helper.php deleted: update-api/app/helpers/plupdate-helper.php deleted: update-api/app/helpers/thupdate-helper.php new file: update-api/classes/forms/HomeFormHandler.php new file: update-api/classes/forms/PlFormHandler.php new file: update-api/classes/forms/ThFormHandler.php new file: update-api/classes/helpers/HomeHelper.php new file: update-api/classes/helpers/LogsHelper.php new file: update-api/classes/helpers/PlHelper.php new file: update-api/classes/helpers/ThHelper.php new file: update-api/classes/util/security.php modified: update-api/lib/auth-lib.php new file: update-api/lib/class-lib.php modified: update-api/lib/load-lib.php deleted: update-api/lib/waf-lib.php modified: update-api/public/.htaccess new file: update-api/public/api.php modified: update-api/public/assets/css/login.css modified: update-api/public/assets/css/mobile.css deleted: update-api/public/assets/css/pages.css modified: update-api/public/assets/css/styles.css modified: update-api/public/index.php modified: update-api/public/login.php deleted: update-api/public/plugins/api.php deleted: update-api/public/plugins/download.php deleted: update-api/public/themes/api.php deleted: update-api/public/themes/download.php renamed: update-api/app/pages/home.php -> update-api/views/home.php renamed: update-api/app/pages/logs.php -> update-api/views/logs.php renamed: update-api/app/pages/plupdate.php -> update-api/views/plupdate.php renamed: update-api/app/pages/thupdate.php -> update-api/views/thupdate.php
2025-06-29 14:59:47 -04:00
if (unlink($plugin_path)) {
echo '<script>'
. 'alert("Plugin deleted successfully!");'
. 'window.location.href = "/plupdate";'
. '</script>';
} else {
echo '<script>'
. 'alert("Failed to delete plugin file. Please try again.");'
. 'window.location.href = "/plupdate";'
. '</script>';
}
}
}
}