Add file permissions validations see BT#13757

pull/2487/head
jmontoyaa 7 years ago
parent 841a661f7e
commit fc96dafff7
  1. 4
      plugin/nosearchindex/lang/english.php
  2. 67
      plugin/nosearchindex/plugin.php

@ -3,3 +3,7 @@
$strings['plugin_title'] = "No search engine index";
$strings['plugin_comment'] = "Hide portal from search engine bots.";
$strings['tool_enable'] = 'Enable plugin';
$strings['CheckTheWritingPermissionsOfRobotsFile'] = 'The plugin needs to create/edit some files: /robots.txt, /robots.dist.txt, /app/home/header_extra_content.txt check your file permissions.';

@ -16,37 +16,66 @@ $file = api_get_path(SYS_PATH).'robots.txt';
if ($isPlatformAdmin) {
$originalFile = api_get_path(SYS_PATH).'robots.dist.txt';
$extraContentFile = api_get_home_path().'header_extra_content.txt';
if (!file_exists($originalFile)) {
copy($file, $originalFile);
}
if (!file_exists($extraContentFile)) {
file_put_contents($extraContentFile, '');
}
$originalContent = file_get_contents($originalFile);
/** @var FormValidator $form */
$form = $plugin_info['settings_form'];
if ($form && $form->validate()) {
$values = $form->getSubmitValues();
$contents = file_get_contents($originalFile);
$extraContentFile = api_get_home_path().'header_extra_content.txt';
$noFollow = '<meta name="robots" content="noindex" />';
if (isset($values['tool_enable']) && $values['tool_enable'] == 'true') {
file_put_contents($file, $contents."\nDisallow: /\n");
$value = '';
if (file_exists($extraContentFile)) {
$backup = file_get_contents($extraContentFile);
file_put_contents($extraContentFile, $backup.$noFollow);
$continue = false;
if (is_readable($file) && is_writable($file) &&
file_exists($originalFile) && is_readable($originalFile) && is_writable($originalFile) &&
file_exists($extraContentFile) && is_readable($extraContentFile) && is_writable($extraContentFile)
) {
$continue = true;
}
$continue = false;
if ($continue) {
$contents = file_get_contents($originalFile);
$noFollow = '<meta name="robots" content="noindex" />';
if (isset($values['tool_enable']) && $values['tool_enable'] == 'true') {
$result = file_put_contents($file, $contents."\nDisallow: /\n");
$value = '';
if (file_exists($extraContentFile)) {
$backup = file_get_contents($extraContentFile);
file_put_contents($extraContentFile, $backup.$noFollow);
} else {
$value = file_put_contents($extraContentFile, $noFollow);
}
} else {
$value = file_put_contents($extraContentFile, $noFollow);
}
} else {
file_put_contents($file, $contents);
file_put_contents($file, $contents);
if (file_exists($extraContentFile)) {
$backup = file_get_contents($extraContentFile);
$backup = str_replace($noFollow, '', $backup);
file_put_contents($extraContentFile, $backup);
if (file_exists($extraContentFile)) {
$backup = file_get_contents($extraContentFile);
$backup = str_replace($noFollow, '', $backup);
file_put_contents($extraContentFile, $backup);
}
}
} else {
/*Display::addFlash(
Display::return_message($plugin->get_lang('CheckTheWritingPermissionsOfRobotsFile'), 'warning')
);*/
api_delete_settings_params(
[
'category = ? AND access_url = ? AND subkey = ? AND type = ? and variable = ?' => [
'Plugins',
api_get_current_access_url_id(),
'nosearchindex',
'setting',
'nosearchindex_tool_enable',
]
]
);
$form->setElementError('tool_enable', $plugin->get_lang('CheckTheWritingPermissionsOfRobotsFile'));
}
}
$plugin_info['settings_form'] = $form;

Loading…
Cancel
Save