Files
luos/workflow/engine/methods/setup/pluginsChange.php

116 lines
4.7 KiB
PHP
Raw Normal View History

2010-12-02 23:34:41 +00:00
<?php
/**
* pluginsChange.php
2019-09-06 15:49:07 -04:00
* If the feature is enable and the code_scanner_scope was enable with the argument enable_plugin, will check the code
* Review when a plugin was enable
2010-12-02 23:34:41 +00:00
*
2019-09-06 15:49:07 -04:00
* @link https://wiki.processmaker.com/3.0/Plugins#Enable_and_Disable_a_Plugin
2010-12-02 23:34:41 +00:00
*/
2017-08-04 09:32:25 -04:00
use ProcessMaker\Plugins\PluginRegistry;
/**
* Main execution block - handles plugin change requests and returns JSON response
*/
try {
$result = handlePluginChange();
header('Content-Type: application/json');
echo json_encode($result);
} catch (Exception $e) {
// Handle any unexpected errors with proper HTTP status
header('Content-Type: application/json');
http_response_code(400);
echo json_encode(['success' => false, 'error' => 'Invalid request']);
}
/**
* Handles plugin enable/disable operations with security validation
*
* @return array Response array with success status and details
* @throws InvalidArgumentException When input parameters are invalid
* @throws SecurityException When security validation fails
* @throws FileNotFoundException When plugin files are not found
*/
function handlePluginChange() {
try {
// Validate required input parameters
if (!isset($_GET['id']) || !isset($_GET['status'])) {
throw new InvalidArgumentException('Missing required parameters');
}
$pluginFile = $_GET['id'];
$pluginStatus = $_GET['status'];
// Validate plugin file format (alphanumeric, underscore, hyphen + .php extension)
if (!preg_match('/^[a-zA-Z0-9_-]+\.php$/', $pluginFile)) {
throw new InvalidArgumentException('Invalid plugin file format');
}
// Validate status parameter (only '0' or '1' allowed)
if (!in_array($pluginStatus, ['0', '1'], true)) {
throw new InvalidArgumentException('Invalid plugin status');
}
// Sanitize plugin name by removing directory components and extension
$pluginName = basename(str_replace(".php", "", $pluginFile));
// Additional validation for plugin name format
if (!preg_match('/^[a-zA-Z0-9_-]+$/', $pluginName)) {
throw new InvalidArgumentException('Invalid plugin name format');
}
// Secure path validation to prevent directory traversal attacks
$pluginFilePath = realpath(PATH_PLUGINS . $pluginFile);
$pluginDirPath = realpath(PATH_PLUGINS . $pluginName);
$pluginsDir = realpath(PATH_PLUGINS);
// Ensure plugin file is within the allowed plugins directory
if (!$pluginFilePath || strpos($pluginFilePath, $pluginsDir) !== 0) {
throw new SecurityException('Plugin file outside allowed directory');
}
// Verify plugin file exists
if (!is_file($pluginFilePath)) {
throw new FileNotFoundException('Plugin file not found');
}
// Get plugin registry singleton instance
$oPluginRegistry = PluginRegistry::loadSingleton();
if ($pluginStatus === '1') {
// Disable plugin operation
$details = $oPluginRegistry->getPluginDetails($pluginFile);
if ($details) {
2017-08-01 12:16:06 -04:00
$oPluginRegistry->disablePlugin($details->getNamespace());
2017-08-10 21:55:18 -04:00
$oPluginRegistry->savePlugin($details->getNamespace());
2017-08-01 12:16:06 -04:00
G::auditLog("DisablePlugin", "Plugin Name: " . $details->getNamespace());
return ['success' => true, 'action' => 'disabled', 'plugin' => $details->getNamespace()];
}
} else {
// Enable plugin operation
if ($pluginDirPath && is_dir($pluginDirPath)) {
// Safely include the validated plugin file
require_once($pluginFilePath);
$details = $oPluginRegistry->getPluginDetails($pluginFile);
if ($details) {
2017-08-01 12:16:06 -04:00
$oPluginRegistry->enablePlugin($details->getNamespace());
$oPluginRegistry->setupPlugins(); // Initialize all enabled plugins
2017-08-01 12:16:06 -04:00
$oPluginRegistry->savePlugin($details->getNamespace());
G::auditLog("EnablePlugin", "Plugin Name: " . $details->getNamespace());
return ['success' => true, 'action' => 'enabled', 'plugin' => $details->getNamespace()];
PM-473 "Analisis de los resultados de escaneo de las..." SOLVED Issue: Analisis de los resultados de escaneo de las funciones en ProcessMaker. Plugin/trigger code scanner. Cause: Nueva solicitud de funciones Solution: Se ha implementado esta nueva funcionalidad, que consta de lo siguiente: - Escaneo de codigo al importar un plugin (no se aplica a plugins enterprise) - Escaneo de codigo al habilitar un plugin (si el plugin ya se encuentra fisicamente en el directorio de los plugins) - Escaneo de codigo al importar un proceso - Escaneo de codigo al crear/modificar codigo de un trigger - Escaneo de codigo al ejecutar un caso que tenga seteados triggers en sus steps (si el trigger tiene codigo no deseado, no se ejecuta el trigger) - Se ha agregado la opcion "check-plugin-disabled-code" al comando "./gulliver", el mismo muestra informacion sobre los plugins con codigo no deseado. Ej: $ ./gulliver check-plugin-disabled-code [enterprise-plugin|custom-plugin|all|<plugin-name>] - Se ha agregado la opcion "check-workspace-disabled-code" al comando "./processmaker", el mismo muestra informacion sobre los workspaces con codigo no deseado en sus triggers. Ej: $ ./processmaker check-workspace-disabled-code <myWorkspace> - Por defecto ProcessMaker no realiza el escaneo de codigo, si se desea escanear codigo no deseado, se debera definir el atributo "enable_blacklist = 1" en el archivo "env.ini", este atributo no se aplica a las nuevas opciones creadas para los comandos "./gulliver" y "./processmaker" - Para una configuracion personalizada de codigo no deseado (lista negra), se pueden definir las mismas en el archivo "path/to/processmaker/workflow/engine/config/blacklist.ini" (si no existe el archivo se puede crear), o tambien en el atributo "disable_functions" esto en el archivo "php.ini" Ejemplo de "blacklist.ini": ;Classes ;======= DashletInterface ;Functions ;========= eval exec ;date ;echo strlen
2014-11-19 16:47:22 -04:00
}
} else {
throw new FileNotFoundException('Plugin directory not found');
}
2010-12-02 23:34:41 +00:00
}
// Fallback response if no operation was performed
return ['success' => false, 'error' => 'Plugin operation failed'];
} catch (Exception $e) {
// Log error and return failure response
G::auditLog('PluginChange', 'Error: ' . $e->getMessage());
return ['success' => false, 'error' => $e->getMessage()];
2010-12-02 23:34:41 +00:00
}
}