Commit 1b59c113 authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(legacy) refactor src/www/system_usermanager_passwordmg.php

parent e04627ad
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
require_once("guiconfig.inc"); require_once("guiconfig.inc");
$pgtitle = array(gettext("System"),gettext("User Password")); $pgtitle = array(gettext("System"), gettext("User Password"));
if (session_status() == PHP_SESSION_NONE) { if (session_status() == PHP_SESSION_NONE) {
session_start(); session_start();
...@@ -37,7 +37,7 @@ if (session_status() == PHP_SESSION_NONE) { ...@@ -37,7 +37,7 @@ if (session_status() == PHP_SESSION_NONE) {
$username = $_SESSION['Username']; $username = $_SESSION['Username'];
if (isset($_POST['save'])) { if (isset($_POST['save'])) {
unset($input_errors); $input_errors = array();
/* input validation */ /* input validation */
$reqdfields = explode(" ", "passwordfld0 passwordfld1 passwordfld2"); $reqdfields = explode(" ", "passwordfld0 passwordfld1 passwordfld2");
...@@ -49,7 +49,19 @@ if (isset($_POST['save'])) { ...@@ -49,7 +49,19 @@ if (isset($_POST['save'])) {
$input_errors[] = gettext("The passwords do not match."); $input_errors[] = gettext("The passwords do not match.");
} }
if (!$input_errors) { /* determine if user is not local to system */
$userFound = false;
foreach ($config['system']['user'] as $user) {
if ($user['name'] == $username) {
$userFound = true;
}
}
if (!$userFound) {
$input_errors[] = gettext("Sorry, you cannot change the password for a non-local user.");
}
if (count($input_errors) == 0) {
// all values are okay --> saving changes // all values are okay --> saving changes
$config['system']['user'][$userindex[$username]]['password'] = crypt($_POST['passwordfld1'], '$6$'); $config['system']['user'][$userindex[$username]]['password'] = crypt($_POST['passwordfld1'], '$6$');
local_user_set($config['system']['user'][$userindex[$username]]); local_user_set($config['system']['user'][$userindex[$username]]);
...@@ -62,84 +74,60 @@ if (isset($_POST['save'])) { ...@@ -62,84 +74,60 @@ if (isset($_POST['save'])) {
session_write_close(); session_write_close();
/* determine if user is not local to system */
$islocal = false;
foreach ($config['system']['user'] as $user) {
if ($user['name'] == $username) {
$islocal = true;
}
}
include("head.inc"); include("head.inc");
?> ?>
<body> <body>
<?php include("fbegin.inc"); ?> <?php include("fbegin.inc"); ?>
<section class="page-content-main"> <section class="page-content-main">
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<? <?
if (isset($input_errors) && count($input_errors) > 0) { if (isset($input_errors) && count($input_errors) > 0) {
print_input_errors($input_errors); print_input_errors($input_errors);
} }
if (isset($savemsg)) { if (isset($savemsg)) {
print_info_box($savemsg); print_info_box($savemsg);
} }
?>
if ($islocal == false) { <section class="col-xs-12">
echo gettext("Sorry, you cannot change the password for a non-local user."); <div class="content-box">
include("foot.inc"); <form action="system_usermanager_passwordmg.php" method="post" name="iform" id="iform">
exit; <div class="table-responsive">
} <table class="table table-striped">
<tr>
?> <td colspan="2"><?=$username?>'s <?=gettext("Password"); ?></td>
<section class="col-xs-12"> </tr>
<tr>
<div class="content-box"> <td><?=gettext("Old password"); ?></td>
<td>
<form action="system_usermanager_passwordmg.php" method="post" name="iform" id="iform"> <input name="passwordfld0" type="password" id="passwordfld0" size="20" />
</td>
<div class="table-responsive"> </tr>
<table class="table table-striped table-sort"> <tr>
<tr> <td><?=gettext("New password"); ?></td>
<td colspan="2" valign="top" class="listtopic"><?=$username?>'s <?=gettext("Password"); ?></td> <td>
</tr> <input name="passwordfld1" type="password" id="passwordfld1" size="20" />
<tr> </td>
<td width="22%" valign="top" class="vncell"><?=gettext("Old password"); ?></td> </tr>
<td width="78%" class="vtable"> <tr>
<input name="passwordfld0" type="password" class="formfld pwd" id="passwordfld0" size="20" /> <td><?=gettext("Confirmation");?></td>
</td> <td>
</tr> <input name="passwordfld2" type="password" id="passwordfld2" size="20" />
<tr> </td>
<td width="22%" valign="top" class="vncell"><?=gettext("New password"); ?></td> </tr>
<td width="78%" class="vtable"> <tr>
<input name="passwordfld1" type="password" class="formfld pwd" id="passwordfld1" size="20" /> <td>&nbsp;</td>
</td> <td>
</tr> <input name="save" type="submit" class="btn btn-primary" value="<?=gettext("Save");?>" />
<tr> </td>
<td width="22%" valign="top" class="vncell"><?=gettext("Confirmation");?></td> </tr>
<td width="78%" class="vtable"> </table>
<input name="passwordfld2" type="password" class="formfld pwd" id="passwordfld2" size="20" />
</td>
</tr>
<tr>
<td width="22%" valign="top">&nbsp;</td>
<td width="78%">
<input name="save" type="submit" class="btn btn-primary" value="<?=gettext("Save");?>" />
</td>
</tr>
</table>
</div> </div>
</form> </form>
</div> </div>
</section> </section>
</div>
</div> </div>
</section> </div>
</section>
<?php include("foot.inc"); <?php include("foot.inc");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment