better checking if config files are writable
This commit is contained in:
parent
c2b0745ce6
commit
5733e93070
|
@ -404,7 +404,7 @@ class LAMConfig {
|
||||||
array_push($file_array, "types: " . $t_settings[$i] . ": " . $this->typeSettings[$t_settings[$i]] . "\n");
|
array_push($file_array, "types: " . $t_settings[$i] . ": " . $this->typeSettings[$t_settings[$i]] . "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$file = fopen($conffile, "w");
|
$file = @fopen($conffile, "w");
|
||||||
if ($file) {
|
if ($file) {
|
||||||
for ($i = 0; $i < sizeof($file_array); $i++) fputs($file, $file_array[$i]);
|
for ($i = 0; $i < sizeof($file_array); $i++) fputs($file, $file_array[$i]);
|
||||||
fclose($file);
|
fclose($file);
|
||||||
|
@ -413,7 +413,6 @@ class LAMConfig {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
StatusMessage("ERROR", _("Cannot open config file!") . " (" . $conffile . ")");
|
StatusMessage("ERROR", _("Cannot open config file!") . " (" . $conffile . ")");
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1020,6 +1019,8 @@ class LAMCfgMain {
|
||||||
/** minimum character classes (upper, lower, numeric, symbols) */
|
/** minimum character classes (upper, lower, numeric, symbols) */
|
||||||
public $passwordMinClasses = 0;
|
public $passwordMinClasses = 0;
|
||||||
|
|
||||||
|
private $conffile;
|
||||||
|
|
||||||
/** list of data fields to save in config file */
|
/** list of data fields to save in config file */
|
||||||
private $settings = array("password", "default", "sessionTimeout",
|
private $settings = array("password", "default", "sessionTimeout",
|
||||||
"logLevel", "logDestination", "allowedHosts", "passwordMinLength",
|
"logLevel", "logDestination", "allowedHosts", "passwordMinLength",
|
||||||
|
@ -1030,6 +1031,7 @@ class LAMCfgMain {
|
||||||
* Loads preferences from config file
|
* Loads preferences from config file
|
||||||
*/
|
*/
|
||||||
function __construct() {
|
function __construct() {
|
||||||
|
$this->conffile = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/config/config.cfg";
|
||||||
// set default values
|
// set default values
|
||||||
$this->sessionTimeout = 30;
|
$this->sessionTimeout = 30;
|
||||||
$this->logLevel = LOG_NOTICE;
|
$this->logLevel = LOG_NOTICE;
|
||||||
|
@ -1044,9 +1046,8 @@ class LAMCfgMain {
|
||||||
* @return boolean true if file was readable
|
* @return boolean true if file was readable
|
||||||
*/
|
*/
|
||||||
private function reload() {
|
private function reload() {
|
||||||
$conffile = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/config/config.cfg";
|
if (is_file($this->conffile) == True) {
|
||||||
if (is_file($conffile) == True) {
|
$file = @fopen($this->conffile, "r");
|
||||||
$file = @fopen($conffile, "r");
|
|
||||||
if (!$file) return false; // abort if file is not readable
|
if (!$file) return false; // abort if file is not readable
|
||||||
while (!feof($file)) {
|
while (!feof($file)) {
|
||||||
$line = fgets($file, 1024);
|
$line = fgets($file, 1024);
|
||||||
|
@ -1071,9 +1072,8 @@ class LAMCfgMain {
|
||||||
* Saves preferences to config file config.cfg
|
* Saves preferences to config file config.cfg
|
||||||
*/
|
*/
|
||||||
public function save() {
|
public function save() {
|
||||||
$conffile = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/config/config.cfg";
|
if (is_file($this->conffile) == True) {
|
||||||
if (is_file($conffile) == True) {
|
$file = fopen($this->conffile, "r");
|
||||||
$file = fopen($conffile, "r");
|
|
||||||
$file_array = array();
|
$file_array = array();
|
||||||
// read config file
|
// read config file
|
||||||
while (!feof($file)) {
|
while (!feof($file)) {
|
||||||
|
@ -1110,14 +1110,13 @@ class LAMCfgMain {
|
||||||
if (!in_array("passwordMinNumeric", $saved)) array_push($file_array, "\n\n# Password: minimum numeric characters\n" . "passwordMinNumeric: " . $this->passwordMinNumeric);
|
if (!in_array("passwordMinNumeric", $saved)) array_push($file_array, "\n\n# Password: minimum numeric characters\n" . "passwordMinNumeric: " . $this->passwordMinNumeric);
|
||||||
if (!in_array("passwordMinSymbol", $saved)) array_push($file_array, "\n\n# Password: minimum symbolic characters\n" . "passwordMinSymbol: " . $this->passwordMinSymbol);
|
if (!in_array("passwordMinSymbol", $saved)) array_push($file_array, "\n\n# Password: minimum symbolic characters\n" . "passwordMinSymbol: " . $this->passwordMinSymbol);
|
||||||
if (!in_array("passwordMinClasses", $saved)) array_push($file_array, "\n\n# Password: minimum character classes (0-4)\n" . "passwordMinClasses: " . $this->passwordMinClasses);
|
if (!in_array("passwordMinClasses", $saved)) array_push($file_array, "\n\n# Password: minimum character classes (0-4)\n" . "passwordMinClasses: " . $this->passwordMinClasses);
|
||||||
$file = @fopen($conffile, "w");
|
$file = @fopen($this->conffile, "w");
|
||||||
if ($file) {
|
if ($file) {
|
||||||
for ($i = 0; $i < sizeof($file_array); $i++) fputs($file, $file_array[$i]);
|
for ($i = 0; $i < sizeof($file_array); $i++) fputs($file, $file_array[$i]);
|
||||||
fclose($file);
|
fclose($file);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
StatusMessage("ERROR", "", _("Cannot open config file!") . " (" . $conffile . ")");
|
StatusMessage("ERROR", "", _("Cannot open config file!") . " (" . $this->conffile . ")");
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1165,6 +1164,15 @@ class LAMCfgMain {
|
||||||
return "{SSHA}" . base64_encode(hex2bin(sha1($password . $salt))) . " " . base64_encode($salt);
|
return "{SSHA}" . base64_encode(hex2bin(sha1($password . $salt))) . " " . base64_encode($salt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if the configuration file is writable.
|
||||||
|
*
|
||||||
|
* @return boolean writable
|
||||||
|
*/
|
||||||
|
public function isWritable() {
|
||||||
|
return is_writeable($this->conffile);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -46,9 +46,9 @@ setlanguage();
|
||||||
// remove settings from session
|
// remove settings from session
|
||||||
if (isset($_SESSION["mainconf_password"])) unset($_SESSION["mainconf_password"]);
|
if (isset($_SESSION["mainconf_password"])) unset($_SESSION["mainconf_password"]);
|
||||||
|
|
||||||
|
$cfgMain = new LAMCfgMain();
|
||||||
// check if user entered a password
|
// check if user entered a password
|
||||||
if (isset($_POST['passwd'])) {
|
if (isset($_POST['passwd'])) {
|
||||||
$cfgMain = new LAMCfgMain();
|
|
||||||
if (isset($_POST['passwd']) && ($cfgMain->checkPassword($_POST['passwd']))) {
|
if (isset($_POST['passwd']) && ($cfgMain->checkPassword($_POST['passwd']))) {
|
||||||
$_SESSION["mainconf_password"] = $_POST['passwd'];
|
$_SESSION["mainconf_password"] = $_POST['passwd'];
|
||||||
metaRefresh("mainmanage.php");
|
metaRefresh("mainmanage.php");
|
||||||
|
@ -88,7 +88,14 @@ echo $_SESSION['header'];
|
||||||
<p align="center"><a href="http://www.ldap-account-manager.org/" target="_blank">
|
<p align="center"><a href="http://www.ldap-account-manager.org/" target="_blank">
|
||||||
<img src="../../graphics/banner.jpg" border=1 alt="LDAP Account Manager"></a>
|
<img src="../../graphics/banner.jpg" border=1 alt="LDAP Account Manager"></a>
|
||||||
</p>
|
</p>
|
||||||
<hr><br><br>
|
<hr><br>
|
||||||
|
<?php
|
||||||
|
// check if config file is writable
|
||||||
|
if (!$cfgMain->isWritable()) {
|
||||||
|
StatusMessage('WARN', 'The config file is not writable.', 'Your changes cannot be saved until you make the file writable for the webserver user.');
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<br>
|
||||||
<!-- form to change main options -->
|
<!-- form to change main options -->
|
||||||
<form action="mainlogin.php" method="post">
|
<form action="mainlogin.php" method="post">
|
||||||
<table align="center" border="2" rules="none" bgcolor="white">
|
<table align="center" border="2" rules="none" bgcolor="white">
|
||||||
|
|
|
@ -145,6 +145,11 @@ if (isset($_POST['submit'])) {
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if config file is writable
|
||||||
|
if (!$cfg->isWritable()) {
|
||||||
|
StatusMessage('WARN', 'The config file is not writable.', 'Your changes cannot be saved until you make the file writable for the webserver user.');
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
@ -357,7 +362,9 @@ if (isset($_POST['submit'])) {
|
||||||
<TR>
|
<TR>
|
||||||
<TD>
|
<TD>
|
||||||
<BR>
|
<BR>
|
||||||
|
<?php if ($cfg->isWritable()) { ?>
|
||||||
<input type="submit" name="submit" value=" <?php echo _("Ok"); ?> ">
|
<input type="submit" name="submit" value=" <?php echo _("Ok"); ?> ">
|
||||||
|
<?php } ?>
|
||||||
</TD>
|
</TD>
|
||||||
</TR>
|
</TR>
|
||||||
</table>
|
</table>
|
||||||
|
|
Loading…
Reference in New Issue