Actualización

This commit is contained in:
Xes
2025-04-10 12:36:07 +02:00
parent 1da7c3f3b9
commit 4aff98e77b
3147 changed files with 320647 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Class MaintenanceModePlugin.
*/
class MaintenanceModePlugin extends Plugin
{
/**
* MaintenanceModePlugin constructor.
*/
public function __construct()
{
parent::__construct(
'0.1',
'Julio Montoya',
[
'tool_enable' => 'boolean',
]
);
}
/**
* @return $this
*/
public static function create()
{
static $result = null;
return $result ? $result : $result = new self();
}
}

View File

@@ -0,0 +1,9 @@
Maintenance Mode plugin
===
This plugin allows administrators to set the portal in maintenance mode through the change of the .htaccess file located
in the root folder of Chamilo.
As such, it requires the web server (user www-data, httpd or nobody) to temporarily have write access to the .htaccess
file. Maintaining write access on this file is a security vulnerability, so please only set those permissions for the
required time to put your site in maintenance mode, and then return them to non-writable by the web server.

View File

@@ -0,0 +1 @@
<?php

View File

@@ -0,0 +1 @@
<?php

View File

@@ -0,0 +1,13 @@
<?php
$strings['plugin_title'] = "Maintenance mode";
$strings['plugin_comment'] = "Put chamilo in maintenance mode";
$strings['tool_enable'] = 'Enable plugin';
$strings['IPAdmin'] = "Admin's IP";
$strings['MaintenanceModeIsOff'] = "Maintenance mode is off";
$strings['MaintenanceModeIsOn'] = "Maintenance mode is on";
$strings['IPAdminDescription'] = "Only the admin with this IP will maintain access to the platform during maintenance mode.";
$strings['MaintenanceFileNotPresent'] = "Can't create file: %s. Check permissions in the root folder";
$strings['TheFollowingTextWillBeAddedToHtaccess'] = "The text below (editor box) will be temporarily added to the .htaccess file.";

View File

@@ -0,0 +1,13 @@
<?php
$strings['plugin_title'] = "Mode maintenance";
$strings['plugin_comment'] = "Mettre votre portail Chamilo en maintenance";
$strings['tool_enable'] = 'Activer le plugin';
$strings['MaintenanceModeIsOff'] = "Le mode maintenance est désactivé";
$strings['MaintenanceModeIsOn'] = "Le mode maintenance est activé";
$strings['IPAdmin'] = "IP de l'administrateur";
$strings['IPAdminDescription'] = "L'administrateur utilisant cette adresse IP conservera les droits d'accès à la plateforme. L'adresse IP indiquée est l'adresse détectée automatiquement par Chamilo par rapport à votre visite actuelle. Elle est également utilisée par défaut dans le bloc ci-dessous.";
$strings['MaintenanceFileNotPresent'] = "Le fichier %s à la racine de Chamilo n'est pas présent et n'a pas pu être créé. Veuillez créer le fichier manuellement et donner les permissions au serveur web de le modifier, par exemple en utilisant la commande 'chown www-data maintenance.html";
$strings['TheFollowingTextWillBeAddedToHtaccess'] = "Le texte suivant sera ajouté temporairement au fichier .htaccess à la racine de votre installation de Chamilo.";

View File

@@ -0,0 +1,13 @@
<?php
$strings['plugin_title'] = "Modo de mantenimiento";
$strings['plugin_comment'] = "Poner Chamilo en estado de mantenimiento";
$strings['tool_enable'] = 'Activar plugin';
$strings['MaintenanceModeIsOff'] = "El modo de mantenimiento no está activado";
$strings['MaintenanceModeIsOn'] = "El modo de mantenimiento está activado";
$strings['IPAdmin'] = "IP del administrador";
$strings['IPAdminDescription'] = "El administrador que use esta dirección IP mantendrá los permisos para acceder a la plataforma. La dirección IP indicada es la dirección detectada automáticamente por Chamilo según su situación actual. También es usada de manera predeterminada en el bloque siguiente.";
$strings['MaintenanceFileNotPresent'] = "El archivo %s en la raíz de Chamilo no está presente y tampoco ha podido ser creado. Por favor, crea el archivo manualmente (por FTP o SSH si es un servidor remoto) y de permisos para que el servidor web pueda modificarlo. Por ejemplo usando el comando 'chown www-data maintenance.html'";
$strings['TheFollowingTextWillBeAddedToHtaccess'] = "El texto siguiente (zona de edición) será añadido temporalmente al archivo .htaccess a la raíz de su instalación de Chamilo.";

View File

@@ -0,0 +1,201 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Maintenance mode facilitator plugin.
*
* @package chamilo.plugin
*/
/** @var \MaintenanceModePlugin $plugin */
$plugin = MaintenanceModePlugin::create();
$plugin_info = $plugin->get_info();
$isPlatformAdmin = api_is_platform_admin();
$editFile = false;
$file = api_get_path(SYS_PATH).'.htaccess';
$maintenanceHtml = api_get_path(SYS_PATH).'maintenance.html';
if ($plugin->isEnabled() && $isPlatformAdmin) {
if (!file_exists($file)) {
Display::addFlash(
Display::return_message(
"$file does not exists. ",
'warning'
)
);
} else {
if (is_readable($file) && is_writable($file)) {
$editFile = true;
} else {
if (!is_readable($file)) {
Display::addFlash(
Display::return_message("$file is not readable", 'warning')
);
}
if (!is_writable($file)) {
Display::addFlash(
Display::return_message("$file is not writable", 'warning')
);
}
}
}
}
if ($editFile && $isPlatformAdmin) {
$originalContent = file_get_contents($file);
$beginLine = '###@@ This part was generated by the edit_htaccess plugin @@##';
$endLine = '###@@ End @@##';
$handler = fopen($file, 'r');
$deleteLinesList = [];
$deleteLine = false;
$contentNoBlock = '';
$block = '';
while (!feof($handler)) {
$line = fgets($handler);
$lineTrimmed = trim($line);
if ($lineTrimmed == $beginLine) {
$deleteLine = true;
}
if ($deleteLine) {
$block .= $line;
} else {
$contentNoBlock .= $line;
}
if ($lineTrimmed == $endLine) {
$deleteLine = false;
}
}
fclose($handler);
$block = str_replace($beginLine, '', $block);
$block = str_replace($endLine, '', $block);
$form = new FormValidator('htaccess');
$form->addHtml($plugin->get_lang('TheFollowingTextWillBeAddedToHtaccess'));
$element = $form->addText(
'ip',
[$plugin->get_lang('IPAdmin'), $plugin->get_lang('IPAdminDescription')]
);
$element->freeze();
$form->addTextarea('text', 'htaccess', ['rows' => '15']);
$config = [
'ToolbarSet' => 'Documents',
'Width' => '100%',
'Height' => '400',
'allowedContent' => true,
];
$form->addHtmlEditor(
'maintenance',
'Maintenance',
true,
true,
$config
);
$form->addCheckBox('active', null, get_lang('Active'));
$form->addButtonSave(get_lang('Save'));
$content = '';
if (file_exists($maintenanceHtml)) {
$content = file_get_contents($maintenanceHtml);
}
if (empty($content)) {
$content = '<html><head><title></title></head><body></body></html>';
}
$isActive = api_get_plugin_setting('maintenancemode', 'active');
$ip = api_get_real_ip();
if ($ip == '::1') {
$ip = '127.0.0.1';
}
$ipSubList = explode('.', $ip);
$implode = implode('\.', $ipSubList);
$append = api_get_configuration_value('url_append');
$default = '
RewriteCond %{REQUEST_URI} !'.$append.'/maintenance.html$
RewriteCond %{REMOTE_ADDR} !^'.$implode.'
RewriteRule ^\.*$ '.$append.'/maintenance.html [R=302,L]
';
if (empty($block)) {
$block = $default;
}
$form->setDefaults([
'text' => $block,
'maintenance' => $content,
'ip' => $ip,
'active' => $isActive,
]);
if ($form->validate()) {
$values = $form->getSubmitValues();
$text = $values['text'];
$active = isset($values['active']) ? true : false;
$content = $values['maintenance'];
// Restore htaccess with out the block
$newFileContent = $beginLine.PHP_EOL;
$newFileContent .= trim($text).PHP_EOL;
$newFileContent .= $endLine;
$newFileContent .= PHP_EOL;
$newFileContent .= $contentNoBlock;
// Remove ^m chars
$newFileContent = str_ireplace("\x0D", '', $newFileContent);
file_put_contents($file, $newFileContent);
$handle = curl_init(api_get_path(WEB_PATH));
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($handle);
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
curl_close($handle);
$statusOkList = [
200,
301,
302,
];
if (in_array($httpCode, $statusOkList)) {
$result = file_put_contents($maintenanceHtml, $content);
if ($result === false) {
Display::addFlash(
Display::return_message(
sprintf($plugin->get_lang('MaintenanceFileNotPresent'), $maintenanceHtml),
'warning'
)
);
}
} else {
// Looks htaccess contains errors. Restore as it was.
Display::addFlash(
Display::return_message(
'Check your htaccess instructions. The original file was restored.',
'warning'
)
);
$originalContent = str_replace("\x0D", '', $originalContent);
file_put_contents($file, $originalContent);
}
if ($active == false) {
$message = $plugin->get_lang('MaintenanceModeIsOff');
$contentNoBlock = str_replace("\x0D", '', $contentNoBlock);
file_put_contents($file, $contentNoBlock);
} else {
$message = $plugin->get_lang('MaintenanceModeIsOn');
}
Display::addFlash(Display::return_message($message));
}
$plugin_info['settings_form'] = $form;
}