Commit 34b8b737 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Merge branch '5951-main-inc-files-should-not-be-needed' into '1.4-dev'

Resolve "main.inc files should not be needed."

See merge request fusiondirectory/fd!513
parents d0394191 002bc57c
......@@ -97,11 +97,11 @@ Language::init();
/* Prepare plugin list */
pluglist::load();
/* Check Plugin variable */
if (session::global_is_set('plugin_dir')) {
$old_plugin_dir = session::global_get('plugin_dir');
/* Check previous plugin index */
if (session::global_is_set('plugin_index')) {
$old_plugin_index = session::global_get('plugin_index');
} else {
$old_plugin_dir = "";
$old_plugin_index = '';
}
$plist->gen_menu();
......@@ -140,19 +140,12 @@ if ($config->get_cfg_value("handleExpiredAccounts") == "TRUE") {
}
if (isset($_GET['plug']) && $plist->plugin_access_allowed($_GET['plug'])) {
$plug = validate($_GET['plug']);
$plugin_dir = $plist->get_path($plug);
session::global_set('plugin_dir', $plugin_dir);
if ($plugin_dir == '') {
logging::log('security', 'fusiondirectory', '', array(), "main.php called with invalid plug parameter \"$plug\"");
header ('Location: index.php?signout=1&message=invalidparameter&plug='.$plug);
exit;
}
$plugin_index = validate($_GET['plug']);
} else {
/* set to welcome page as default plugin */
session::global_set('plugin_dir', 'welcome');
$plugin_dir = "$BASE_DIR/plugins/generic/welcome";
$plugin_index = 'welcome';
}
session::global_set('plugin_index', $plugin_index);
/* Handle plugin locks.
- Remove the plugin from session if we switched to another. (cleanup)
......@@ -162,14 +155,9 @@ if (isset($_GET['plug']) && $plist->plugin_access_allowed($_GET['plug'])) {
$cleanup = FALSE;
$remove_lock = FALSE;
/* Check if we have changed the selected plugin
*/
if ($old_plugin_dir != $plugin_dir && $old_plugin_dir != "") {
if (is_file("$old_plugin_dir/main.inc")) {
$cleanup = $remove_lock = TRUE;
require ("$old_plugin_dir/main.inc");
$cleanup = $remove_lock = FALSE;
}
/* Check if we have changed the selected plugin */
if (!empty($old_plugin_index) && ($old_plugin_index != $plugin_index)) {
pluglist::runMainInc($old_plugin_index, TRUE);
} elseif ((isset($_GET['reset']) && $_GET['reset'] == 1) || isset($_POST['delete_lock'])) {
/* Reset was posted, remove all created locks for the current plugin */
$remove_lock = TRUE;
......@@ -195,8 +183,8 @@ $lang = session::global_get('lang');
$smarty->assign ('lang', preg_replace('/_.*$/', '', $lang));
$smarty->assign ('rtl', Language::isRTL($lang));
$smarty->assign ('must', '<span class="must">*</span>');
if (isset($plug)) {
$plug = "?plug=$plug";
if (isset($plugin_index)) {
$plug = "?plug=$plugin_index";
} else {
$plug = "";
}
......@@ -234,28 +222,7 @@ if (($_SERVER['REQUEST_METHOD'] == 'POST')
}
/* Load plugin */
if (is_file("$plugin_dir/main.inc")) {
$display = "";
try {
require ("$plugin_dir/main.inc");
} catch (Exception $e) {
$smarty->assign('header', print_header('geticon.php?context=status&icon=dialog-error&size=32', _('Fatal error!')));
$display = '<h1>'._('An unrecoverable error occurred. Please contact your administator.').'</h1><p>';
if (ini_get('display_errors') == 1) {
$display .= nl2br(htmlentities((string)$e, ENT_COMPAT, 'UTF-8'));
} else {
$display .= 'Error detail display is turned off.';
}
$display .= '</p>'."\n";
}
} else {
msg_dialog::display(
_("Plugin"),
sprintf(_("Fatal error: Cannot find any plugin definitions for plugin '%s' ('%s' is not a file)!"), $plug, "$plugin_dir/main.inc"),
FATAL_ERROR_DIALOG);
exit();
}
pluglist::runMainInc($plugin_index);
/* Print_out last ErrorMessage repeated string. */
$smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
......
......@@ -101,8 +101,7 @@ IconTheme::loadThemes('themes');
/* Fake user bypassing acl system */
$ui = new userinfoNoAuth('setup');
/* Call setup */
$display = "";
require_once("../setup/main.inc");
setup::mainInc();
$focus = '<script type="text/javascript">';
$focus .= 'next_msg_dialog();';
......
......@@ -537,5 +537,48 @@ class pluglist {
return $plist;
}
static function runMainInc($index, $forceCleanup = FALSE)
{
global $BASE_DIR, $config, $plist, $ui, $smarty, $display, $remove_lock, $cleanup, $plug;
if ($index == 'welcome') {
$plugin_dir = "$BASE_DIR/plugins/generic/welcome";
$plugin = $index;
} else {
$plugin_dir = $plist->get_path($index);
$plugin = $plist->dirlist[$index];
}
try {
if ($forceCleanup) {
$cleanup = $remove_lock = TRUE;
}
if (is_file("$plugin_dir/main.inc")) {
$display = '';
require ("$plugin_dir/main.inc");
} elseif (is_callable(array($plugin, 'mainInc'))) {
$plugin::mainInc();
} else {
msg_dialog::display(
_('Plugin'),
sprintf(_("Fatal error: Cannot find any plugin definitions for plugin '%s' ('%s' is not a file)!"), $plugin, "$plugin_dir/main.inc"),
FATAL_ERROR_DIALOG
);
exit();
}
if ($forceCleanup) {
$cleanup = $remove_lock = FALSE;
}
} catch (Exception $e) {
$smarty->assign('header', print_header('geticon.php?context=status&icon=dialog-error&size=32', _('Fatal error!')));
$display = '<h1>'._('An unrecoverable error occurred. Please contact your administator.').'</h1><p>';
if (ini_get('display_errors') == 1) {
$display .= nl2br(htmlentities((string)$e, ENT_COMPAT, 'UTF-8'));
} else {
$display .= 'Error detail display is turned off.';
}
$display .= '</p>'."\n";
}
}
}
?>
......@@ -1217,10 +1217,14 @@ class management
}
static function mainInc ($classname, $objectTypes = FALSE)
static function mainInc ($classname = NULL, $objectTypes = FALSE)
{
global $remove_lock, $cleanup, $display;
if ($classname === NULL) {
$classname = get_called_class();
}
/* Remove locks */
if ($remove_lock && session::is_set($classname)) {
$macl = session::get($classname);
......
......@@ -2054,10 +2054,18 @@ class simplePlugin
* \param string $objectType The objectType to use (will be taken in the plInfo if FALSE)
*
*/
static function mainInc ($classname, $entry_dn, $tabs = FALSE, $edit_mode = TRUE, $objectType = FALSE)
static function mainInc ($classname = NULL, $entry_dn = NULL, $tabs = FALSE, $edit_mode = TRUE, $objectType = FALSE)
{
global $remove_lock, $cleanup, $display, $config, $plug, $ui;
if ($classname === NULL) {
$classname = get_called_class();
}
if ($entry_dn === NULL) {
$entry_dn = $ui->dn;
}
$plInfo = pluglist::pluginInfos($classname);
$plIcon = (isset($plInfo['plIcon']) ? $plInfo['plIcon'] : 'plugin.png');
$plHeadline = $plInfo['plTitle'];
......
......@@ -115,5 +115,17 @@ class dashboard extends simplePlugin
return $stats;
}
static function mainInc($classname = NULL, $entry_dn = NULL, $tabs = TRUE, $edit_mode = FALSE, $objectType = FALSE)
{
if ($classname === NULL) {
$classname = get_called_class();
}
if ($entry_dn === NULL) {
$entry_dn = '';
}
parent::mainInc($classname, $entry_dn, $tabs, $edit_mode, $objectType);
}
}
?>
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org)
Copyright (C) 2013-2016 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
simplePlugin::mainInc('dashboard', '', TRUE, FALSE);
?>
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2013-2018 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
management::mainInc('aclManagement');
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2013-2016 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
management::mainInc('aclRoleManagement');
?>
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003 Cajus Pollmeier
Copyright (C) 2011-2018 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
management::mainInc('departmentManagement');
?>
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2013-2018 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
management::mainInc('groupManagement');
?>
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003 Cajus Pollmeier
Copyright (C) 2011-2018 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
management::mainInc('userManagement');
?>
......@@ -600,5 +600,20 @@ class configInLdap extends simplePlugin
}
return array_unique($themes);
}
static function mainInc($classname = NULL, $entry_dn = NULL, $tabs = TRUE, $edit_mode = TRUE, $objectType = FALSE)
{
global $config;
if ($classname === NULL) {
$classname = get_called_class();
}
if ($entry_dn === NULL) {
$entry_dn = CONFIGRDN.$config->current['BASE'];
}
parent::mainInc($classname, $entry_dn, $tabs, $edit_mode, $objectType);
}
}
?>
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2012-2016 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
simplePlugin::mainInc('configInLdap', CONFIGRDN.$config->current['BASE'], TRUE);
?>
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2013-2016 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
simplePlugin::mainInc('user', $ui->dn);
?>
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2015-2016 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
simplePlugin::mainInc('userRoles', $ui->dn);
?>
......@@ -2,7 +2,7 @@
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003 Cajus Pollmeier
Copyright (C) 2011-2016 FusionDirectory
Copyright (C) 2011-2019 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -292,5 +292,24 @@ class setup
$this->o_steps[$this->i_config]->is_completed = $completed;
}
}
static function mainInc()
{
global $setup, $display;
$display = '';
/* Create a new setup class if necessary */
if (!session::is_set('setup') || (isset($_GET['reset']) && ($_GET['reset'] == 1))) {
session::set('setup', new setup());
}
$setup = session::get('setup');
/* Execute formular */
$setup->save_object();
$display = $setup->execute();
/* Store changes in session */
session::set('setup', $setup);
}
}
?>
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2007 Fabian Hickert
Copyright (C) 2011-2016 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/* Create a new setup class if necessary */
if (!session::is_set('setup') || (isset($_GET['reset']) && $_GET['reset'] == 1)) {
session::set('setup', new setup());
}
$setup = session::get('setup');
/* Execute formular */
$setup->save_object();
$display = $setup->execute();
/* Store changes in session */
session::set('setup', $setup);
?>
  • SonarQube analysis indicates that quality gate is failed.

    • Security Rating on New Code is passed: Actual value 1
    • Reliability Rating on New Code is failed: Actual value 3 > 1
    • Maintainability Rating on New Code is passed: Actual value 1
    • Duplicated Lines on New Code (%) is passed: Actual value 3.364830606130445

    SonarQube analysis reported no issues.

Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment