LDAPAccountManager/lam/templates/config/profmanage.php

403 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/)
2011-01-14 19:16:54 +00:00
Copyright (C) 2003 - 2011 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();
2003-07-29 11:52:26 +00:00
echo $_SESSION['header'];
?>
<title>
<?php
echo _("Profile management");
?>
</title>
2010-08-31 18:05:17 +00:00
<?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-01-01 13:06:51 +00:00
<link rel="shortcut icon" type="image/x-icon" href="../../graphics/favicon.ico">
</head>
<body>
2010-08-31 18:05:17 +00:00
<table border=0 width="100%" class="lamHeader ui-corner-all">
2010-07-30 16:08:20 +00:00
<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>
2003-09-01 21:28:26 +00:00
<?php
2010-01-01 17:39:38 +00:00
// include all JavaScript files
$jsDirName = dirname(__FILE__) . '/../lib';
$jsDir = dir($jsDirName);
2010-08-28 12:27:06 +00:00
$jsFiles = array();
2010-01-01 17:39:38 +00:00
while ($jsEntry = $jsDir->read()) {
if (substr($jsEntry, strlen($jsEntry) - 3, 3) != '.js') continue;
2010-08-28 12:27:06 +00:00
$jsFiles[] = $jsEntry;
}
sort($jsFiles);
foreach ($jsFiles as $jsEntry) {
2010-01-01 17:39:38 +00:00
echo "<script type=\"text/javascript\" src=\"../lib/" . $jsEntry . "\"></script>\n";
}
2006-09-24 14:19:50 +00:00
$cfg = new LAMCfgMain();
// check if submit button was pressed
2010-10-11 17:52:30 +00:00
if (isset($_POST['submit'])) {
// 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();
$msg = _("Created new profile.");
}
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") {
if ($_POST['setpassword'] && $_POST['setpassword2'] && ($_POST['setpassword'] == $_POST['setpassword2'])) {
2006-09-24 14:19:50 +00:00
$config = new LAMConfig($_POST['setprofile']);
$config->set_Passwd($_POST['setpassword']);
$config->save();
2008-07-20 15:41:12 +00:00
$config = null;
$msg = _("New password set successfully.");
}
else $error = _("Profile passwords are different or empty!");
}
// set default profile
elseif ($_POST['action'] == "setdefault") {
2008-07-20 15:41:12 +00:00
$configMain = new LAMCfgMain();
$configMain->default = $_POST['defaultfilename'];
$configMain->save();
$configMain = null;
$msg = _("New default profile set successfully.");
}
// print messages
2008-07-20 15:41:12 +00:00
if (isset($error) || isset($msg)) {
if (isset($error)) {
StatusMessage("ERROR", $error);
}
if (isset($msg)) {
StatusMessage("INFO", $msg);
}
}
else exit;
}
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 -->
<form action="profmanage.php" method="post">
2003-09-24 20:28:23 +00:00
<table>
<tr><td>
2011-01-14 19:16:54 +00:00
<fieldset class="ui-corner-all">
2003-08-02 09:05:47 +00:00
<legend><b> <?php echo _("Profile management"); ?> </b></legend>
2007-12-31 12:37:00 +00:00
<br>
2003-09-24 20:28:23 +00:00
<table cellspacing=0 border=0>
<!-- add profile -->
<tr>
<td>
<input type="radio" name="action" value="add" checked>
</td>
<td>
<b>
2003-09-22 19:18:16 +00:00
<?php echo _("Add profile") . ":"; ?>
</b>
2003-09-24 20:28:23 +00:00
</td>
<td align="right">
<?php echo _("Profile name") . ":"; ?>
<input type="text" name="addprofile">
</td>
2003-09-24 20:28:23 +00:00
<td>&nbsp;
2005-04-24 19:41:39 +00:00
<?PHP
2009-02-07 22:28:28 +00:00
printHelpLink(getHelp('', '230'), '230');
2005-04-24 19:41:39 +00:00
?>
</td>
</tr>
<tr>
2003-09-24 20:28:23 +00:00
<td>&nbsp;</td>
<td>&nbsp;</td>
<td align="right">
<?php echo _("Profile password") . ":"; ?>
<input type="password" name="addpassword">
2003-09-24 20:28:23 +00:00
</td>
<td></td>
</tr>
<tr>
2003-09-24 20:28:23 +00:00
<td>&nbsp;</td>
<td>&nbsp;</td>
<td align="right">
<?php echo _("Reenter profile password") . ":"; ?>
<input type="password" name="addpassword2">
</td>
<td></td>
</tr>
<tr>
2007-12-31 12:37:00 +00:00
<td colspan=4>&nbsp;</td>
</tr>
<!-- rename profile -->
<tr>
<td>
<input type="radio" name="action" value="rename">
</td>
<td>
<select size=1 name="oldfilename">
<?php
$files = getConfigProfiles();
for ($i = 0; $i < sizeof($files); $i++) echo ("<option>" . $files[$i] . "</option>\n");
?>
</select>
<b>
2003-09-24 20:28:23 +00:00
<?php echo _("Rename profile"); ?>
</b>
2003-09-24 20:28:23 +00:00
</td>
<td align="right">
<?php echo _("Profile name") . ":"; ?>
<input type="text" name="renfilename">
</td>
2003-09-24 20:28:23 +00:00
<td>&nbsp;
2005-04-24 19:41:39 +00:00
<?PHP
2009-02-07 22:28:28 +00:00
printHelpLink(getHelp('', '231'), '231');
2005-04-24 19:41:39 +00:00
?>
</td>
</tr>
<tr>
2007-12-31 12:37:00 +00:00
<td colspan=4>&nbsp;</td>
</tr>
<!-- delete profile -->
<tr>
<td>
<input type="radio" name="action" value="delete">
</td>
2003-09-24 20:28:23 +00:00
<td colspan=2>
<select size=1 name="delfilename">
<?php
$files = getConfigProfiles();
for ($i = 0; $i < sizeof($files); $i++) echo ("<option>" . $files[$i] . "</option>\n");
?>
</select>
<b>
<?php echo _("Delete profile"); ?>
</b>
</td>
2003-09-24 20:28:23 +00:00
<td>&nbsp;
2005-04-24 19:41:39 +00:00
<?PHP
2009-02-07 22:28:28 +00:00
printHelpLink(getHelp('', '232'), '232');
2005-04-24 19:41:39 +00:00
?>
</td>
</tr>
<tr>
2007-12-31 12:37:00 +00:00
<td colspan=4>&nbsp;</td>
</tr>
<!-- set profile password -->
<tr>
<td>
<input type="radio" name="action" value="setpass">
</td>
<td>
<select size=1 name="setprofile">
<?php
$files = getConfigProfiles();
for ($i = 0; $i < sizeof($files); $i++) echo ("<option>" . $files[$i] . "</option>\n");
?>
</select>
<b>
<?php echo _("Set profile password"); ?>
</b>
</td>
2003-09-24 20:28:23 +00:00
<td align="right">
<?php echo _("Profile password") . ":"; ?>
<input type="password" name="setpassword">
</td>
<td>&nbsp;
2005-04-24 19:41:39 +00:00
<?PHP
2009-02-07 22:28:28 +00:00
printHelpLink(getHelp('', '233'), '233');
2005-04-24 19:41:39 +00:00
?>
</td>
</tr>
<tr>
2003-09-24 20:28:23 +00:00
<td>&nbsp;</td>
<td>&nbsp;</td>
<td align="right">
<?php echo _("Reenter profile password") . ":"; ?>
<input type="password" name="setpassword2">
</td>
2003-09-24 20:28:23 +00:00
<td>&nbsp;</td>
</tr>
<tr>
2007-12-31 12:37:00 +00:00
<td colspan=4>&nbsp;</td>
</tr>
<!-- change default profile -->
<tr>
<td>
<input type="radio" name="action" value="setdefault">
</td>
2003-10-13 17:35:49 +00:00
<td>
<select size=1 name="defaultfilename">
<?php
$files = getConfigProfiles();
2006-09-24 14:19:50 +00:00
$conf = new LAMCfgMain();
$defaultprofile = $conf->default;
for ($i = 0; $i < sizeof($files); $i++) {
if ($files[$i] == $defaultprofile) echo ("<option selected>" . $files[$i] . "</option>\n");
else echo ("<option>" . $files[$i] . "</option>\n");
}
?>
</select>
<b>
<?php echo _("Change default profile"); ?>
</b>
</td>
2003-10-13 17:35:49 +00:00
<td>&nbsp;</td>
2003-09-24 20:28:23 +00:00
<td>&nbsp;
2005-04-24 19:41:39 +00:00
<?PHP
2009-02-07 22:28:28 +00:00
printHelpLink(getHelp('', '234'), '234');
2005-04-24 19:41:39 +00:00
?>
</td>
</tr>
</table>
</fieldset>
2003-09-24 20:28:23 +00:00
</td></tr>
</table>
2007-12-31 12:37:00 +00:00
<p>&nbsp;</p>
<!-- password field and submit button -->
<b>
2006-05-13 16:52:45 +00:00
<?php echo _("Master password"); ?>:
</b>
2007-12-31 12:37:00 +00:00
&nbsp;
<input type="password" name="passwd">
2007-12-31 12:37:00 +00:00
&nbsp;
2010-10-11 17:52:30 +00:00
<button id="submitButton" name="submit" class="smallPadding"><?php echo _("Ok"); ?></button>
2007-12-31 12:37:00 +00:00
&nbsp;
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
?>
2010-10-11 17:52:30 +00:00
<script type="text/javascript" language="javascript">
jQuery(document).ready(function() {
jQuery('#submitButton').button();
});
</script>
</form>
<p><br></p>
</body>
</html>