Move conf file information into page of dolibarr conf information.

New: Enhance https forcing.
This commit is contained in:
Laurent Destailleur 2010-02-20 11:40:36 +00:00
parent f1af02f79e
commit 3acd11c13c
6 changed files with 143 additions and 121 deletions

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
@ -27,6 +27,8 @@
require("./pre.inc.php");
$langs->load("admin");
$langs->load("user");
$langs->load("install");
if (!$user->admin)
@ -41,6 +43,100 @@ llxHeader();
print_fiche_titre($langs->trans("SummaryConst"),'','setup');
print_titre($langs->trans("ConfigurationFile"));
// Parameters in conf.php file
$configfileparameters=array(
// 'separator',
'dolibarr_main_url_root',
'dolibarr_main_document_root',
'dolibarr_main_data_root',
'separator',
'dolibarr_main_db_host',
'dolibarr_main_db_port',
'dolibarr_main_db_name',
'dolibarr_main_db_type',
'dolibarr_main_db_user',
'dolibarr_main_db_pass',
'dolibarr_main_db_character_set',
'dolibarr_main_db_collation',
'separator',
'dolibarr_main_authentication',
'separator',
'dolibarr_main_auth_ldap_login_attribute',
'dolibarr_main_auth_ldap_host',
'dolibarr_main_auth_ldap_port',
'dolibarr_main_auth_ldap_version',
'dolibarr_main_auth_ldap_dn',
'dolibarr_main_auth_ldap_admin_login',
'dolibarr_main_auth_ldap_admin_pass',
'dolibarr_main_auth_ldap_debug'
);
$configfilelib=array(
// 'separator',
$langs->trans("URLRoot"),
$langs->trans("DocumentRootServer"),
$langs->trans("DataRootServer"),
'separator',
$langs->trans("DatabaseServer"),
$langs->trans("DatabasePort"),
$langs->trans("DatabaseName"),
$langs->trans("DriverType"),
$langs->trans("User"),
$langs->trans("Password"),
$langs->trans("DBStoringCharset"),
$langs->trans("DBSortingCharset"),
'separator',
$langs->trans("AuthenticationMode"),
'separator',
'dolibarr_main_auth_ldap_login_attribute',
'dolibarr_main_auth_ldap_host',
'dolibarr_main_auth_ldap_port',
'dolibarr_main_auth_ldap_version',
'dolibarr_main_auth_ldap_dn',
'dolibarr_main_auth_ldap_admin_login',
'dolibarr_main_auth_ldap_admin_pass',
'dolibarr_main_auth_ldap_debug'
);
$var=true;
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td width="280">'.$langs->trans("Label").'</td>';
print '<td>'.$langs->trans("Parameter").'</td>';
print '<td>'.$langs->trans("Value").'</td>';
print '</tr>'."\n";
$i=0;
foreach($configfileparameters as $key)
{
$var=!$var;
print "<tr ".$bc[$var].">";
if ($key == 'separator')
{
print '<td colspan="3">&nbsp;</td>';
}
else
{
print "<td>".$configfilelib[$i].'</td><td>'.$key.'</td>';
print "<td>";
if ($key == 'dolibarr_main_db_pass') print preg_replace('/./i','*',${$key});
else print ${$key};
// TODO Afficher charset effectif de base $db
if ($key == 'dolibarr_main_db_charset')
{
}
print "</td>";
}
print "</tr>\n";
$i++;
}
print '</table>';
print '<br>';
// Parameters in database
print_titre($langs->trans("Database"));
print '<table class="noborder">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Parameter").'</td>';
@ -73,18 +169,18 @@ if ($resql)
$num = $db->num_rows($resql);
$i = 0;
$var=True;
while ($i < $num)
{
$obj = $db->fetch_object($resql);
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td>'.$obj->name.'</td>'."\n";
print '<td>'.$obj->value.'</td>'."\n";
if (empty($conf->multicompany->enabled) || !$user->entity) print '<td>'.$obj->entity.'</td>'."\n"; // If superadmin or multicompany disabled
print "</tr>\n";
$i++;
}
}

View File

@ -18,8 +18,8 @@
*/
/**
* \file htdocs/lib/memory.lib.php
* \brief Fichier page info systemes Dolibarr
* \file htdocs/admin/system/dolibarr.php
* \brief Page to show Dolibarr informations
* \version $Id$
*/
@ -74,7 +74,7 @@ print '<br>';
// Session
$var=true;
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td>'.$langs->trans("Version").'</td><td colspan="2">'.$langs->trans("Value").'</td></tr>'."\n";
print '<tr class="liste_titre"><td>'.$langs->trans("Session").'</td><td colspan="2">'.$langs->trans("Value").'</td></tr>'."\n";
$var=!$var;
print "<tr ".$bc[$var]."><td width=\"300\">".$langs->trans("SessionSavePath").'</td><td colspan="2">'.session_save_path()."</td></tr>\n";
$var=!$var;

View File

@ -91,94 +91,5 @@ print "<tr $bc[0]><td width=\"280\">".$langs->trans("Version")."</td><td>" .$dbl
print '</table>';
print '<br>';
// conf.php file
$configfileparameters=array(
// 'separator',
'dolibarr_main_url_root',
'dolibarr_main_document_root',
'dolibarr_main_data_root',
'separator',
'dolibarr_main_db_host',
'dolibarr_main_db_port',
'dolibarr_main_db_name',
'dolibarr_main_db_type',
'dolibarr_main_db_user',
'dolibarr_main_db_pass',
'dolibarr_main_db_character_set',
'dolibarr_main_db_collation',
'separator',
'dolibarr_main_authentication',
'separator',
'dolibarr_main_auth_ldap_login_attribute',
'dolibarr_main_auth_ldap_host',
'dolibarr_main_auth_ldap_port',
'dolibarr_main_auth_ldap_version',
'dolibarr_main_auth_ldap_dn',
'dolibarr_main_auth_ldap_admin_login',
'dolibarr_main_auth_ldap_admin_pass',
'dolibarr_main_auth_ldap_debug'
);
$configfilelib=array(
// 'separator',
$langs->trans("URLRoot"),
$langs->trans("DocumentRootServer"),
$langs->trans("DataRootServer"),
'separator',
$langs->trans("DatabaseServer"),
$langs->trans("DatabasePort"),
$langs->trans("DatabaseName"),
$langs->trans("DriverType"),
$langs->trans("User"),
$langs->trans("Password"),
$langs->trans("DBStoringCharset"),
$langs->trans("DBSortingCharset"),
'separator',
$langs->trans("AuthenticationMode"),
'separator',
'dolibarr_main_auth_ldap_login_attribute',
'dolibarr_main_auth_ldap_host',
'dolibarr_main_auth_ldap_port',
'dolibarr_main_auth_ldap_version',
'dolibarr_main_auth_ldap_dn',
'dolibarr_main_auth_ldap_admin_login',
'dolibarr_main_auth_ldap_admin_pass',
'dolibarr_main_auth_ldap_debug'
);
$var=true;
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td width="280">'.$langs->trans("ConfigurationFile").'</td>';
print '<td>'.$langs->trans("Parameter").'</td>';
print '<td>'.$langs->trans("Value").'</td>';
print '</tr>'."\n";
$i=0;
foreach($configfileparameters as $key)
{
$var=!$var;
print "<tr ".$bc[$var].">";
if ($key == 'separator')
{
print '<td colspan="3">&nbsp;</td>';
}
else
{
print "<td>".$configfilelib[$i].'</td><td>'.$key.'</td>';
print "<td>";
if ($key == 'dolibarr_main_db_pass') print preg_replace('/./i','*',${$key});
else print ${$key};
// TODO Afficher charset effectif de base $db
if ($key == 'dolibarr_main_db_charset')
{
}
print "</td>";
}
print "</tr>\n";
$i++;
}
print '</table>';
print '<br>';
llxFooter('$Date$ - $Revision$');
?>

View File

@ -137,9 +137,8 @@ $dolibarr_main_authentication="dolibarr";
# dolibarr_main_force_https
# This parameter allows to force the HTTPS mode.
# Warning: If you enable this parameter, your dolibarr_main_url_root parameter
# must contains an URL with https and web server must be configured to respond
# to such an URL.
# Warning: If you enable this parameter, your web server must be configured
# to respond URL with https protocol.
# Default value: 0
# Possible values: 0 or 1
# Examples:

View File

@ -133,35 +133,44 @@ session_start();
// This include will set: config file variable $dolibarr_xxx, $conf, $langs and $mysoc objects
require_once("master.inc.php");
// Check if HTTPS
// Force HTTPS if required ($conf->file->main_force_https is 0/1 or https dolibarr root url)
if ($conf->file->main_force_https)
{
if (! empty($_SERVER["SCRIPT_URI"])) // If SCRIPT_URI supported by server
$newurl='';
if ($conf->file->main_force_https == '1')
{
if (preg_match('/^http:/i',$_SERVER["SCRIPT_URI"]) && ! preg_match('/^https:/i',$_SERVER["SCRIPT_URI"])) // If link is http
if (! empty($_SERVER["SCRIPT_URI"])) // If SCRIPT_URI supported by server
{
$newurl=preg_replace('/^http:/i','https:',$_SERVER["SCRIPT_URI"]);
dol_syslog("main.inc: dolibarr_main_force_https is on, we make a redirect to ".$newurl);
header("Location: ".$newurl);
exit;
if (preg_match('/^http:/i',$_SERVER["SCRIPT_URI"]) && ! preg_match('/^https:/i',$_SERVER["SCRIPT_URI"])) // If link is http
{
$newurl=preg_replace('/^http:/i','https:',$_SERVER["SCRIPT_URI"]);
}
}
else // Check HTTPS environment variable (Apache/mod_ssl only)
{
// $_SERVER["HTTPS"] is 'on' when link is https, otherwise $_SERVER["HTTPS"] is empty or 'off'
if (empty($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] != 'on') // If link is http
{
$uri=preg_replace('/^http(s?):\/\//i','',$dolibarr_main_url_root);
$val=explode('/',$uri); // $val[0] contains domain name and port
$newurl='https://'.$val[0].$_SERVER["REQUEST_URI"];
}
}
}
else // Check on HTTPS environment variable (Apache/mod_ssl only)
else
{
// $_SERVER["HTTPS"] is 'on' when link is https, otherwise $_SERVER["HTTPS"] is empty or 'off'
if (empty($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] != 'on') // If link is http
{
$uri=preg_replace('/^http(s?):\/\//i','',$dolibarr_main_url_root);
$val=explode('/',$uri);
$domaineport=$val[0]; // $domaineport contient nom domaine et port
$newurl='https://'.$domaineport.$_SERVER["REQUEST_URI"];
//print 'eee'.$newurl; exit;
dol_syslog("main.inc: dolibarr_main_force_https is on, we make a redirect to ".$newurl);
header("Location: ".$newurl);
exit;
}
$newurl=$conf->file->main_force_https.$_SERVER["REQUEST_URI"];
}
// Start redirect
if ($newurl)
{
dol_syslog("main.inc: dolibarr_main_force_https is on, we make a redirect to ".$newurl);
header("Location: ".$newurl);
exit;
}
else
{
dol_syslog("main.inc: dolibarr_main_force_https is on but we failed to forge new https url so no redirect is done", LOG_WARNING);
}
}

View File

@ -75,6 +75,12 @@ if (empty($dolibarr_main_db_host))
print 'Please, click <a href="install/index.php">here to finish Dolibarr install process</a> ...'."\n";
exit;
}
if (empty($dolibarr_main_url_root))
{
print 'Value for parameter dolibarr_main_url_root is not defined in your conf.php file'."\n";
print 'You must add here your Dolibarr full Url (Example: http://mydomain/myurl/)'."\n";
exit;
}
if (empty($dolibarr_main_db_type)) $dolibarr_main_db_type='mysql'; // Pour compatibilite avec anciennes configs, si non defini, on prend 'mysql'
if (empty($dolibarr_main_data_root))
{
@ -86,6 +92,7 @@ if (empty($dolibarr_main_data_root))
// Define some constants
define('DOL_DOCUMENT_ROOT', $dolibarr_main_document_root); // Filesystem pages php (htdocs)
define('DOL_DATA_ROOT', $dolibarr_main_data_root); // Filesystem donnes (documents)
// If dolibarr_main_url_root = auto (Hidden feature for developers only), we try to forge it.
if ($dolibarr_main_url_root == 'auto' && ! empty($_SERVER["SCRIPT_URL"]) && ! empty($_SERVER["SCRIPT_URI"]))
{
$dolibarr_main_url_root=str_replace($_SERVER["SCRIPT_URL"],'',$_SERVER["SCRIPT_URI"]);