dolibarr/htdocs/admin/security_other.php

340 lines
11 KiB
PHP
Raw Normal View History

<?php
2013-02-24 18:08:52 +01:00
/* Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
2012-12-30 15:13:49 +01:00
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
2013-11-16 13:00:21 +01:00
* Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
*
* 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 3 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
2011-08-01 00:21:57 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
2008-10-12 13:41:13 +02:00
* \file htdocs/admin/security_other.php
* \ingroup core
2008-10-28 21:46:22 +01:00
* \brief Security options setup
2008-10-12 13:41:13 +02:00
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
2012-09-02 22:15:00 +02:00
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
$langs->load("users");
$langs->load("admin");
2007-04-27 11:19:42 +02:00
$langs->load("other");
2012-08-09 16:35:39 +02:00
if (! $user->admin)
accessforbidden();
$action=GETPOST('action','alpha');
$upload_dir=$conf->admin->dir_temp;
/*
* Actions
*/
2012-07-29 16:44:19 +02:00
if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
2012-09-02 22:15:00 +02:00
dol_add_file_process($upload_dir, 0, 0, 'userfile');
}
2012-09-02 22:04:30 +02:00
if (preg_match('/set_(.*)/',$action,$reg))
{
2012-09-02 22:04:30 +02:00
$code=$reg[1];
$value=(GETPOST($code) ? GETPOST($code) : 1);
if (dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity) > 0)
{
Header("Location: ".$_SERVER["PHP_SELF"]);
exit;
}
else
{
dol_print_error($db);
}
}
2012-09-02 22:04:30 +02:00
else if (preg_match('/del_(.*)/',$action,$reg))
2010-11-08 12:40:52 +01:00
{
2012-09-02 22:04:30 +02:00
$code=$reg[1];
if (dolibarr_del_const($db, $code, $conf->entity) > 0)
{
Header("Location: ".$_SERVER["PHP_SELF"]);
exit;
}
else
{
dol_print_error($db);
}
2010-11-08 12:40:52 +01:00
}
2012-09-02 22:04:30 +02:00
2012-08-09 16:35:39 +02:00
else if ($action == 'MAIN_SESSION_TIMEOUT')
2008-10-12 13:41:13 +02:00
{
2011-09-21 15:16:13 +02:00
if (! dolibarr_set_const($db, "MAIN_SESSION_TIMEOUT", $_POST["MAIN_SESSION_TIMEOUT"],'chaine',0,'',$conf->entity)) dol_print_error($db);
else setEventMessage($langs->trans("RecordModifiedSuccessfully"));
2011-07-29 23:04:27 +02:00
}
2012-08-09 16:35:39 +02:00
else if ($action == 'MAIN_UPLOAD_DOC')
2011-07-29 23:04:27 +02:00
{
2011-09-21 15:16:13 +02:00
if (! dolibarr_set_const($db, 'MAIN_UPLOAD_DOC',$_POST["MAIN_UPLOAD_DOC"],'chaine',0,'',$conf->entity)) dol_print_error($db);
else setEventMessage($langs->trans("RecordModifiedSuccessfully"));
2008-10-12 13:41:13 +02:00
}
2012-08-09 16:35:39 +02:00
else if ($action == 'MAIN_UMASK')
{
2011-09-21 15:16:13 +02:00
if (! dolibarr_set_const($db, "MAIN_UMASK", $_POST["MAIN_UMASK"],'chaine',0,'',$conf->entity)) dol_print_error($db);
else setEventMessage($langs->trans("RecordModifiedSuccessfully"));
}
2012-08-09 16:35:39 +02:00
else if ($action == 'MAIN_ANTIVIRUS_COMMAND')
{
2011-09-21 15:16:13 +02:00
if (! dolibarr_set_const($db, "MAIN_ANTIVIRUS_COMMAND", $_POST["MAIN_ANTIVIRUS_COMMAND"],'chaine',0,'',$conf->entity)) dol_print_error($db);
else setEventMessage($langs->trans("RecordModifiedSuccessfully"));
}
2012-08-09 16:35:39 +02:00
else if ($action == 'MAIN_ANTIVIRUS_PARAM')
{
2011-09-21 15:16:13 +02:00
if (! dolibarr_set_const($db, "MAIN_ANTIVIRUS_PARAM", $_POST["MAIN_ANTIVIRUS_PARAM"],'chaine',0,'',$conf->entity)) dol_print_error($db);
else setEventMessage($langs->trans("RecordModifiedSuccessfully"));
}
2012-09-02 22:15:00 +02:00
// Delete file
else if ($action == 'delete')
{
$langs->load("other");
$file = $conf->admin->dir_temp . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
$ret=dol_delete_file($file);
if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
Header('Location: '.$_SERVER["PHP_SELF"]);
exit;
}
/*
* View
*/
$form = new Form($db);
2013-03-24 07:11:44 +01:00
llxHeader('',$langs->trans("Miscellaneous"));
print_fiche_titre($langs->trans("SecuritySetup"),'','setup');
2013-03-24 07:11:44 +01:00
print $langs->trans("MiscellaneousDesc")."<br>\n";
print "<br>\n";
2008-02-28 21:37:04 +01:00
$head=security_prepare_head();
dol_fiche_head($head, 'misc', $langs->trans("Security"));
// Timeout
$var=true;
print '<table width="100%" class="noborder">';
print '<tr class="liste_titre">';
print '<td colspan="2">'.$langs->trans("Parameters").'</td>';
print '<td>'.$langs->trans("Value").'</td>';
print '<td width="100">&nbsp;</td>';
print "</tr>\n";
$var=!$var;
$sessiontimeout=ini_get("session.gc_maxlifetime");
if (empty($conf->global->MAIN_SESSION_TIMEOUT)) $conf->global->MAIN_SESSION_TIMEOUT=$sessiontimeout;
2008-10-12 13:41:13 +02:00
print '<form action="'.$_SERVER["PHP_SELF"].'?action=MAIN_SESSION_TIMEOUT" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2008-10-12 13:41:13 +02:00
print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("SessionTimeOut").'</td><td align="right">';
print $form->textwithpicto('',$langs->trans("SessionExplanation",ini_get("session.gc_probability"),ini_get("session.gc_divisor")));
2008-10-12 13:41:13 +02:00
print '</td>';
print '<td class="nowrap">';
print '<input class="flat" name="MAIN_SESSION_TIMEOUT" type="text" size="6" value="'.htmlentities($conf->global->MAIN_SESSION_TIMEOUT).'"> '.strtolower($langs->trans("Seconds"));
2008-10-12 13:41:13 +02:00
print '</td>';
print '<td align="right">';
2008-10-12 13:41:13 +02:00
print '<input type="submit" class="button" name="button" value="'.$langs->trans("Modify").'">';
print '</td>';
print '</tr></form>';
print '</table>';
print '<br>';
// Other Options
$var=true;
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td colspan="3">'.$langs->trans("Parameters").'</td>';
print '<td align="right" width="100">'.$langs->trans("Status").'</td>';
print '</tr>';
// Enable Captcha code
$var=!$var;
print "<tr ".$bc[$var].">";
print '<td colspan="3">'.$langs->trans("UseCaptchaCode").'</td>';
print '<td align="right">';
if (function_exists("imagecreatefrompng"))
{
2012-09-02 22:04:30 +02:00
if (! empty($conf->use_javascript_ajax))
{
print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA');
}
else
{
if (empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA))
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_SECURITY_ENABLECAPTCHA">'.img_picto($langs->trans("Disabled"),'off').'</a>';
}
else
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_SECURITY_ENABLECAPTCHA">'.img_picto($langs->trans("Enabled"),'on').'</a>';
}
}
}
else
{
$desc = $form->textwithpicto('',$langs->transnoentities("EnableGDLibraryDesc"),1,'warning');
2011-09-21 15:16:13 +02:00
print $desc;
}
2012-09-02 22:04:30 +02:00
print '</td></tr>';
2010-11-08 12:40:52 +01:00
// Enable advanced perms
$var=!$var;
print "<tr ".$bc[$var].">";
print '<td colspan="3">'.$langs->trans("UseAdvancedPerms").'</td>';
print '<td align="right">';
2012-09-02 22:04:30 +02:00
if (! empty($conf->use_javascript_ajax))
2010-11-08 12:40:52 +01:00
{
2012-09-02 22:04:30 +02:00
print ajax_constantonoff('MAIN_USE_ADVANCED_PERMS');
2010-11-08 12:40:52 +01:00
}
2012-08-09 16:35:39 +02:00
else
2010-11-08 12:40:52 +01:00
{
2012-09-02 22:04:30 +02:00
if (empty($conf->global->MAIN_USE_ADVANCED_PERMS))
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_USE_ADVANCED_PERMS">'.img_picto($langs->trans("Disabled"),'off').'</a>';
}
else
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_USE_ADVANCED_PERMS">'.img_picto($langs->trans("Enabled"),'on').'</a>';
}
2010-11-08 12:40:52 +01:00
}
2012-09-02 22:04:30 +02:00
print "</td></tr>";
print '</table>';
print '<br>';
// Upload options
$var=false;
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td colspan="2">'.$langs->trans("Parameters").'</td>';
print '<td>'.$langs->trans("Value").'</td>';
print '<td width="100">&nbsp;</td>';
print '</tr>';
2011-07-29 23:04:27 +02:00
print '<form action="'.$_SERVER["PHP_SELF"].'?action=MAIN_UPLOAD_DOC" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<tr '.$bc[$var].'>';
print '<td colspan="2">'.$langs->trans("MaxSizeForUploadedFiles").'.';
$max=@ini_get('upload_max_filesize');
if ($max) print ' '.$langs->trans("MustBeLowerThanPHPLimit",$max*1024,$langs->trans("Kb")).'.';
else print ' '.$langs->trans("NoMaxSizeByPHPLimit").'.';
print '</td>';
print '<td class="nowrap">';
2010-01-07 23:12:41 +01:00
print '<input class="flat" name="MAIN_UPLOAD_DOC" type="text" size="6" value="'.htmlentities($conf->global->MAIN_UPLOAD_DOC).'"> '.$langs->trans("Kb");
print '</td>';
print '<td align="right">';
print '<input type="submit" class="button" name="button" value="'.$langs->trans("Modify").'">';
print '</td>';
print '</tr></form>';
2007-10-21 22:40:43 +02:00
$var=!$var;
print '<form action="'.$_SERVER["PHP_SELF"].'?action=MAIN_UMASK" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("UMask").'</td><td align="right">';
print $form->textwithpicto('',$langs->trans("UMaskExplanation"));
2007-10-21 22:40:43 +02:00
print '</td>';
print '<td class="nowrap">';
2010-01-07 23:12:41 +01:00
print '<input class="flat" name="MAIN_UMASK" type="text" size="6" value="'.htmlentities($conf->global->MAIN_UMASK).'">';
2007-10-21 22:40:43 +02:00
print '</td>';
print '<td align="right">';
print '<input type="submit" class="button" name="button" value="'.$langs->trans("Modify").'">';
print '</td>';
print '</tr></form>';
2007-10-21 22:40:43 +02:00
// Use anti virus
$var=!$var;
print '<form action="'.$_SERVER["PHP_SELF"].'?action=MAIN_ANTIVIRUS_COMMAND" method="POST">';
2010-01-08 11:34:14 +01:00
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print "<tr ".$bc[$var].">";
print '<td colspan="2">'.$langs->trans("AntiVirusCommand").'<br>';
print $langs->trans("AntiVirusCommandExample");
// Check command in inside safe_mode
print '</td>';
2011-09-05 23:37:05 +02:00
print '<td>';
if (ini_get('safe_mode') && ! empty($conf->global->MAIN_ANTIVIRUS_COMMAND))
{
2011-09-21 15:16:13 +02:00
$langs->load("errors");
$basedir=preg_replace('/"/','',dirname($conf->global->MAIN_ANTIVIRUS_COMMAND));
$listdir=explode(';',ini_get('safe_mode_exec_dir'));
if (! in_array($basedir,$listdir))
{
print img_warning($langs->trans('WarningSafeModeOnCheckExecDir'));
dol_syslog("safe_mode is on, basedir is ".$basedir.", safe_mode_exec_dir is ".ini_get('safe_mode_exec_dir'), LOG_WARNING);
}
}
2012-08-09 16:35:39 +02:00
print '<input type="text" name="MAIN_ANTIVIRUS_COMMAND" size="72" value="'.(! empty($conf->global->MAIN_ANTIVIRUS_COMMAND)?dol_htmlentities($conf->global->MAIN_ANTIVIRUS_COMMAND):'').'">';
2007-10-21 22:40:43 +02:00
print "</td>";
print '<td align="right">';
print '<input type="submit" class="button" name="button" value="'.$langs->trans("Modify").'">';
print '</td>';
2007-10-21 22:40:43 +02:00
print '</tr>';
print '</form>';
2007-10-21 22:40:43 +02:00
// Use anti virus
$var=!$var;
print '<form action="'.$_SERVER["PHP_SELF"].'?action=MAIN_ANTIVIRUS_PARAM" method="POST">';
2010-01-08 11:34:14 +01:00
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print "<tr ".$bc[$var].">";
print '<td colspan="2">'.$langs->trans("AntiVirusParam").'<br>';
print $langs->trans("AntiVirusParamExample");
print '</td>';
2011-09-05 23:37:05 +02:00
print '<td>';
2012-08-09 16:35:39 +02:00
print '<input type="text" name="MAIN_ANTIVIRUS_PARAM" size="72" value="'.(! empty($conf->global->MAIN_ANTIVIRUS_PARAM)?dol_htmlentities($conf->global->MAIN_ANTIVIRUS_PARAM):'').'">';
print "</td>";
print '<td align="right">';
print '<input type="submit" class="button" name="button" value="'.$langs->trans("Modify").'">';
print '</td>';
print '</tr>';
print '</form>';
print '</table>';
dol_fiche_end();
// Form to test upload
print '<br>';
$formfile=new FormFile($db);
2013-11-16 13:00:21 +01:00
$formfile->form_attach_new_file($_SERVER['PHP_SELF'], $langs->trans("FormToTestFileUploadForm"), 0, 0, 1, 50, '', '', 1, '', 0);
2012-09-02 22:15:00 +02:00
// List of document
$filearray=dol_dir_list($upload_dir, "files", 0, '', '', 'name', SORT_ASC, 1);
$formfile->list_of_documents($filearray, '', 'admin_temp', '');
llxFooter();
2012-01-08 00:52:07 +01:00
$db->close();
?>