MaintenanceModePlugin (requires composer update) BT#12478

remotes/angel/1.11.x
jmontoyaa 8 years ago
parent 06b5f5e9e2
commit d265a83c34
  1. 5
      main/inc/lib/formvalidator/FormValidator.class.php
  2. 31
      plugin/maintenancemode/MaintenanceModePlugin.php
  3. 0
      plugin/maintenancemode/index.php
  4. 0
      plugin/maintenancemode/install.php
  5. 15
      plugin/maintenancemode/lang/english.php
  6. 14
      plugin/maintenancemode/lang/french.php
  7. 59
      plugin/maintenancemode/plugin.php

@ -176,14 +176,17 @@ EOT;
* @param string $name The element name
* @param bool $required (optional) Is the form-element required (default=true)
* @param array $attributes (optional) List of attributes for the form-element
* @return HTML_QuickForm_text
*/
public function addText($name, $label, $required = true, $attributes = array())
{
$this->addElement('text', $name, $label, $attributes);
$element = $this->addElement('text', $name, $label, $attributes);
$this->applyFilter($name, 'trim');
if ($required) {
$this->addRule($name, get_lang('ThisFieldIsRequired'), 'required');
}
return $element;
}
/**

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

@ -0,0 +1,15 @@
<?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['TheMaintenanceModeIsOff'] = "Maintenance mode is off";
$strings['TheMaintenanceModeIsOn'] = "Maintenance mode is on";
$strings['IPAdminDescription'] = "The admin with this IP will only have access to the platform.";
$strings['MaintenanceFileNotPresent'] = "Can't create file: %s. Check permissions in the root folder";

@ -0,0 +1,14 @@
<?php
$strings['plugin_title'] = "Maintenance mode";
$strings['plugin_comment'] = "Put chamilo in maintenance mode";
$strings['tool_enable'] = 'Enable plugin';
$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";

@ -6,14 +6,8 @@
* @package chamilo.plugin
*/
//the plugin title
$plugin_info['title'] = 'Edit htaccess';
//the comments that go with the plugin
$plugin_info['comment'] = 'Edit htaccess';
//the plugin version
$plugin_info['version'] = '1.0';
//the plugin author
$plugin_info['author'] = 'Julio Montoya';
$plugin = MaintenanceModePlugin::create();
$plugin_info = $plugin->get_info();
$editFile = false;
@ -80,14 +74,17 @@ if ($editFile && api_is_platform_admin()) {
$form = new FormValidator('htaccess');
$form->addHtml('The following text will be added in the /.htaccess');
$form->addText('ip', 'IP');
$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',
//'fullPage' => true,
'allowedContent' => true
];
@ -99,16 +96,23 @@ if ($editFile && api_is_platform_admin()) {
$config
);
$form->addCheckBox('active', null, get_lang('Active'));
$form->addButtonSave(get_lang('Save'));
$content = '';
if (is_file($maintenanceHtml)) {
if (file_exists($maintenanceHtml)) {
$content = file_get_contents($maintenanceHtml);
}
if (empty($content)) {
$content = '<html><head><title></title></head><body></body></html>';
}
$ip = api_get_plugin_setting('edit_htaccess', 'ip');
$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');
@ -122,18 +126,23 @@ RewriteRule \.*$ '.$append.'/maintenance.html [R=302,L]
$block = $default;
}
$form->setDefaults(['text' => $block, 'maintenance' => $content, 'ip' => $ip]);
$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 = $contentNoBlock;
$newFileContent .= $beginLine.PHP_EOL;
$newFileContent .= $text.PHP_EOL;
$newFileContent = $beginLine.PHP_EOL;
$newFileContent .= trim($text).PHP_EOL;
$newFileContent .= $endLine;
$newFileContent .= PHP_EOL;
$newFileContent .= $contentNoBlock;
file_put_contents($file, $newFileContent);
$handle = curl_init(api_get_path(WEB_PATH));
@ -152,8 +161,22 @@ RewriteRule \.*$ '.$append.'/maintenance.html [R=302,L]
);
file_put_contents($file, $originalContent);
} else {
file_put_contents($maintenanceHtml, $content);
Display::addFlash(Display::return_message('Saved'));
$result = file_put_contents($maintenanceHtml, $content);
if ($result === false) {
Display::addFlash(
Display::return_message(
sprintf($plugin->get_lang('MaintenanceFileNotPresent'), $maintenanceHtml),
'warning'
)
);
}
}
if ($active == false) {
Display::addFlash(Display::return_message($plugin->get_lang('TheMaintenanceModeIsOff')));
file_put_contents($file, $contentNoBlock);
} else {
Display::addFlash(Display::return_message($plugin->get_lang('MaintenanceModeIsOn')));
}
}
$plugin_info['settings_form'] = $form;
Loading…
Cancel
Save