LDAPAccountManager/lam/templates/config/profmanage.php

304 lines
11 KiB
PHP
Raw Normal View History

<?php
/*
$Id$
2009-10-27 18:47:12 +00:00
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
2012-01-14 13:24:57 +00:00
Copyright (C) 2003 - 2012 Roland Gruber
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2004-06-02 12:48:54 +00:00
*/
2006-09-24 14:19:50 +00:00
2004-06-02 12:48:54 +00:00
/**
* Configuration profile management.
*
* @package configuration
* @author Roland Gruber
*/
2004-06-02 12:48:54 +00:00
/** Access to config functions */
include_once('../../lib/config.inc');
2004-06-02 12:48:54 +00:00
/** Used to print status messages */
include_once('../../lib/status.inc');
// start session
2009-07-08 18:03:28 +00:00
if (strtolower(session_module_name()) == 'files') {
session_save_path("../../sess");
}
@session_start();
2003-07-06 17:54:11 +00:00
setlanguage();
2006-09-24 14:19:50 +00:00
$cfg = new LAMCfgMain();
// check if submit button was pressed
2012-01-14 13:24:57 +00:00
if (isset($_POST['action'])) {
// check master password
2007-11-07 21:02:13 +00:00
if (!$cfg->checkPassword($_POST['passwd'])) {
$error = _("Master password is wrong!");
}
// add new profile
elseif ($_POST['action'] == "add") {
2009-08-14 18:06:15 +00:00
if (preg_match("/^[a-z0-9_-]+$/i", $_POST['addprofile']) && !in_array($_POST['addprofile'], getConfigProfiles())) {
// check profile password
if ($_POST['addpassword'] && $_POST['addpassword2'] && ($_POST['addpassword'] == $_POST['addpassword2'])) {
2010-07-23 11:12:59 +00:00
// check if lam.conf_sample exists
if (!is_file("../../config/lam.conf_sample")) {
2010-10-11 20:27:48 +00:00
$error = "The file config/lam.conf_sample was not found. Please restore it.";
2010-07-23 11:12:59 +00:00
}
else {
// create new profile file
@copy("../../config/lam.conf_sample", "../../config/" . $_POST['addprofile'] . ".conf");
@chmod ("../../config/" . $_POST['addprofile'] . ".conf", 0600);
$file = is_file("../../config/" . $_POST['addprofile'] . ".conf");
if ($file) {
// load as config and write new password
$conf = new LAMConfig($_POST['addprofile']);
$conf->set_Passwd($_POST['addpassword']);
$conf->save();
2011-12-10 09:08:27 +00:00
$_SESSION['conf_isAuthenticated'] = $_POST['addprofile'];
$_SESSION['conf_config'] = $conf;
$_SESSION['conf_messages'][] = array('INFO', _("Created new profile."), $_POST['addprofile']);
metaRefresh('confmain.php');
exit;
2010-07-23 11:12:59 +00:00
}
else {
$error = _("Unable to create new profile!");
}
}
}
else $error = _("Profile passwords are different or empty!");
}
else $error = _("Profile name is invalid!");
}
// rename profile
elseif ($_POST['action'] == "rename") {
if (preg_match("/^[a-z0-9_-]+$/i", $_POST['oldfilename']) && preg_match("/^[a-z0-9_-]+$/i", $_POST['renfilename']) && !in_array($_POST['renfilename'], getConfigProfiles())) {
if (rename("../../config/" . $_POST['oldfilename'] . ".conf", "../../config/" . $_POST['renfilename'] . ".conf")) {
$msg = _("Renamed profile.");
}
else $error = _("Could not rename file!");
// update default profile setting if needed
if ($cfg->default == $_POST['oldfilename']) {
$cfg->default = $_POST['renfilename'];
$cfg->save();
}
}
else $error = _("Profile name is invalid!");
}
// delete profile
elseif ($_POST['action'] == "delete") {
2009-08-14 18:06:15 +00:00
if (preg_match("/^[a-z0-9_-]+$/i", $_POST['delfilename']) && @unlink("../../config/" . $_POST['delfilename'] . ".conf")) {
$msg = _("Profile deleted.");
}
else $error = _("Unable to delete profile!");
}
// set new profile password
elseif ($_POST['action'] == "setpass") {
2012-03-13 21:02:37 +00:00
if (preg_match("/^[a-z0-9_-]+$/i", $_POST['setprofile'])) {
if ($_POST['setpassword'] && $_POST['setpassword2'] && ($_POST['setpassword'] == $_POST['setpassword2'])) {
$config = new LAMConfig($_POST['setprofile']);
$config->set_Passwd($_POST['setpassword']);
$config->save();
$config = null;
$msg = _("New password set successfully.");
}
else $error = _("Profile passwords are different or empty!");
}
2012-03-13 21:02:37 +00:00
else $error = _("Profile name is invalid!");
}
// set default profile
elseif ($_POST['action'] == "setdefault") {
2012-03-13 21:02:37 +00:00
if (preg_match("/^[a-z0-9_-]+$/i", $_POST['defaultfilename'])) {
$configMain = new LAMCfgMain();
$configMain->default = $_POST['defaultfilename'];
$configMain->save();
$configMain = null;
$msg = _("New default profile set successfully.");
}
else $error = _("Profile name is invalid!");
}
2011-12-10 09:08:27 +00:00
}
echo $_SESSION['header'];
?>
<title>
<?php
echo _("Profile management");
?>
</title>
<?php
// include all CSS files
$cssDirName = dirname(__FILE__) . '/../../style';
$cssDir = dir($cssDirName);
while ($cssEntry = $cssDir->read()) {
if (substr($cssEntry, strlen($cssEntry) - 4, 4) != '.css') continue;
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../../style/" . $cssEntry . "\">\n";
2008-07-20 15:41:12 +00:00
}
2011-12-10 09:08:27 +00:00
?>
<link rel="shortcut icon" type="image/x-icon" href="../../graphics/favicon.ico">
</head>
<body>
<table border=0 width="100%" class="lamHeader ui-corner-all">
<tr>
<td align="left" height="30">
<a class="lamHeader" href="http://www.ldap-account-manager.org/" target="new_window">&nbsp;<img src="../../graphics/logo32.png" width=24 height=24 class="align-middle" alt="LDAP Account Manager">&nbsp;&nbsp;LDAP Account Manager</a>
</td>
<td align="right" height=20>
<a href="conflogin.php"><IMG alt="configuration" src="../../graphics/undo.png">&nbsp;<?php echo _("Back to profile login") ?></a>
</td>
</tr>
</table>
<br>
<?php
// include all JavaScript files
$jsDirName = dirname(__FILE__) . '/../lib';
$jsDir = dir($jsDirName);
$jsFiles = array();
while ($jsEntry = $jsDir->read()) {
if (substr($jsEntry, strlen($jsEntry) - 3, 3) != '.js') continue;
$jsFiles[] = $jsEntry;
}
sort($jsFiles);
foreach ($jsFiles as $jsEntry) {
echo "<script type=\"text/javascript\" src=\"../lib/" . $jsEntry . "\"></script>\n";
}
2011-12-10 09:08:27 +00:00
// print messages
if (isset($error) || isset($msg)) {
if (isset($error)) {
StatusMessage("ERROR", $error);
}
if (isset($msg)) {
StatusMessage("INFO", $msg);
}
}
2004-10-07 10:16:53 +00:00
// check if config.cfg is valid
2007-11-07 21:02:13 +00:00
if (!isset($cfg->default)) {
2004-10-07 10:16:53 +00:00
StatusMessage("ERROR", _("Please set up your master configuration file (config/config.cfg) first!"), "");
echo "</body>\n</html>\n";
die();
}
?>
<br>
<!-- form for adding/renaming/deleting profiles -->
2012-01-14 13:24:57 +00:00
<form id="profileForm" name="profileForm" action="profmanage.php" method="post">
<input type="hidden" name="action" id="action" value="none">
<div id="passwordDialogDiv" class="hidden">
<?PHP echo _("Master password"); ?>
<input type="password" name="passwd">
2005-04-24 19:41:39 +00:00
<?PHP
2009-02-07 22:28:28 +00:00
printHelpLink(getHelp('', '236'), '236');
2005-04-24 19:41:39 +00:00
?>
2012-01-14 13:24:57 +00:00
</div>
<div class="filled ui-corner-all">
<?php
$files = getConfigProfiles();
$topicSpacer = new htmlSpacer(null, '20px');
$tabindex = 1;
$container = new htmlTable();
$container->addElement(new htmlTitle(_("Profile management")), true);
// new profile
$container->addElement(new htmlSubTitle(_("Add profile")), true);
$newProfileInput = new htmlTableExtendedInputField(_("Profile name"), 'addprofile', null, '230');
$newProfileInput->setFieldSize(15);
$container->addElement($newProfileInput, true);
$profileNewPwd1 = new htmlTableExtendedInputField(_("Profile password"), 'addpassword');
$profileNewPwd1->setIsPassword(true);
$profileNewPwd1->setFieldSize(15);
$container->addElement($profileNewPwd1, true);
$profileNewPwd2 = new htmlTableExtendedInputField(_("Reenter password"), 'addpassword2');
$profileNewPwd2->setIsPassword(true);
$profileNewPwd2->setFieldSize(15);
$container->addElement($profileNewPwd2, true);
$newProfileButton = new htmlButton('btnAddProfile', _('Add'));
$newProfileButton->setOnClick("jQuery('#action').val('add');showConfirmationDialog('" . _("Add profile") . "', '" .
2012-04-09 13:20:24 +00:00
_('Ok') . "', '" . _('Cancel') . "', 'passwordDialogDiv', 'profileForm', null);");
2012-01-14 13:24:57 +00:00
$container->addElement($newProfileButton, true);
$container->addElement($topicSpacer, true);
// rename profile
$container->addElement(new htmlSubTitle(_("Rename profile")), true);
$container->addElement(new htmlTableExtendedSelect('oldfilename', $files, array(), _('Profile name'), '231'), true);
$oldProfileInput = new htmlTableExtendedInputField(_('New profile name'), 'renfilename');
$oldProfileInput->setFieldSize(15);
$container->addElement($oldProfileInput, true);
$renameProfileButton = new htmlButton('btnRenameProfile', _('Rename'));
$renameProfileButton->setOnClick("jQuery('#action').val('rename');showConfirmationDialog('" . _("Rename profile") . "', '" .
2012-04-09 13:20:24 +00:00
_('Ok') . "', '" . _('Cancel') . "', 'passwordDialogDiv', 'profileForm', null);");
2012-01-14 13:24:57 +00:00
$container->addElement($renameProfileButton, true);
$container->addElement($topicSpacer, true);
// delete profile
$container->addElement(new htmlSubTitle(_("Delete profile")), true);
$container->addElement(new htmlTableExtendedSelect('delfilename', $files, array(), _('Profile name'), '232'), true);
$deleteProfileButton = new htmlButton('btnDeleteProfile', _('Delete'));
$deleteProfileButton->setOnClick("jQuery('#action').val('delete');showConfirmationDialog('" . _("Delete profile") . "', '" .
2012-04-09 13:20:24 +00:00
_('Ok') . "', '" . _('Cancel') . "', 'passwordDialogDiv', 'profileForm', null);");
2012-01-14 13:24:57 +00:00
$container->addElement($deleteProfileButton, true);
$container->addElement($topicSpacer, true);
// set password
$container->addElement(new htmlSubTitle(_("Set profile password")), true);
$container->addElement(new htmlTableExtendedSelect('setprofile', $files, array(), _('Profile name'), '233'), true);
$profileSetPwd1 = new htmlTableExtendedInputField(_("Profile password"), 'setpassword');
$profileSetPwd1->setIsPassword(true);
$profileSetPwd1->setFieldSize(15);
$container->addElement($profileSetPwd1, true);
$profileSetPwd2 = new htmlTableExtendedInputField(_("Reenter password"), 'setpassword2');
$profileSetPwd2->setIsPassword(true);
$profileSetPwd2->setFieldSize(15);
$container->addElement($profileSetPwd2, true);
$setPasswordProfileButton = new htmlButton('btnSetPasswordProfile', _('Set profile password'));
$setPasswordProfileButton->setOnClick("jQuery('#action').val('setpass');showConfirmationDialog('" . _("Set profile password") . "', '" .
2012-04-09 13:20:24 +00:00
_('Ok') . "', '" . _('Cancel') . "', 'passwordDialogDiv', 'profileForm', null);");
2012-01-14 13:24:57 +00:00
$container->addElement($setPasswordProfileButton, true);
$container->addElement($topicSpacer, true);
// set default profile
$conf = new LAMCfgMain();
$defaultprofile = $conf->default;
$container->addElement(new htmlSubTitle(_("Change default profile")), true);
$container->addElement(new htmlTableExtendedSelect('defaultfilename', $files, array($defaultprofile), _('Profile name'), '234'), true);
$defaultProfileButton = new htmlButton('btnDefaultProfile', _('Ok'));
$defaultProfileButton->setOnClick("jQuery('#action').val('setdefault');showConfirmationDialog('" . _("Change default profile") . "', '" .
2012-04-09 13:20:24 +00:00
_('Ok') . "', '" . _('Cancel') . "', 'passwordDialogDiv', 'profileForm', null);");
2012-01-14 13:24:57 +00:00
$container->addElement($defaultProfileButton, true);
$container->addElement($topicSpacer, true);
parseHtml('', $container, array(), false, $tabindex, 'user');
2012-01-14 13:24:57 +00:00
?>
</div>
</form>
<p><br></p>
</body>
</html>