reformat/reorganise code

This commit is contained in:
David Goodwin committed 2023-12-23 21:59:33 +00:00
1 parent 8003978ca5
commit ccbf3f9ab3
1 file changed
+33 -52
+33 -52
View File
@@ -31,13 +31,13 @@ require_once('common.php');
$smarty = PFASmarty::getInstance();
$smarty->configureTheme('../');
$username = authentication_get_username();
list($local_part, $domain) = explode('@', $username);
$pPassword_text = "";
$pUser_text = '';
$pUser = '';
$username = authentication_get_username();
list($local_part, $domain) = explode('@', $username);
$pPassword_text = "";
$pUser_text = '';
$pUser = '';
$username = authentication_get_username();
$username = authentication_get_username();
if (authentication_has_role('global-admin')) {
$login = new Login('admin');
@@ -65,25 +65,41 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
}
if (isset($_POST['fPassword_current']) && $_POST['fPassword_current'] != '') {
$fPass = $_POST['fPassword_current'];
$fIp = $_POST['fIp'];
$fDesc = $_POST['fDesc'];
$fUser = $_POST['fUser'];
add_exception($username, $fPass, $fIp, $fDesc, $fUser, $totppf, $PALANG);
$fPass = $_POST['fPassword_current'];
$fIp = $_POST['fIp'];
$fDesc = $_POST['fDesc'];
$fUser = $_POST['fUser'];
try {
if ($totppf->addException($username, $fPass, $fIp, $fUser, $fDesc)) {
flash_info($PALANG['pTotp_exception_result_success']);
header("Location: totp-exceptions.php");
exit(0);
} else {
flash_error($PALANG['pTotp_exception_result_error']);
}
} catch (\Exception $e) {
flash_error($e->getMessage());
}
}
if (isset($_POST['fId']) && $_POST['fId'] != '' && is_numeric($_POST['fId'])) {
$fId = $_POST['fId'];
revoke_exception($username, $fId, $totppf, $PALANG);
$fId = $_POST['fId'];
// No extra password check by design, user might be in a hurry
$result = $totppf->deleteException($username, (int)$fId);
if ($result) {
flash_info($PALANG['pTotp_exceptions_revoked']);
}
}
}
// Generate list of existing exceptions
if ($admin==2) {
$exceptions = $totppf->getAllExceptions();
if ($admin == 2) {
$exceptions = $totppf->getAllExceptions();
} else {
$exceptions = $totppf->getExceptionsFor($username);
$exceptions = $totppf->getExceptionsFor($username);
}
// User can revoke exceptions for own username
@@ -96,13 +112,12 @@ foreach ($exceptions as $n => $ex) {
if ($admin == 2) {
$exceptions[$n]['edit'] = 1;
}
if ($admin==1 && $ex['username'] == $domain) {
if ($admin == 1 && $ex['username'] == $domain) {
$exceptions[$n]['edit'] = 1;
}
}
$smarty->assign('SESSID_USERNAME', $username);
$smarty->assign('pPassword_text', $pPassword_text, false);
$smarty->assign('pUser_text', $pUser_text, false);
@@ -113,39 +128,5 @@ $smarty->assign('smarty_template', 'totp-exceptions');
$smarty->display('index.tpl');
/**
* @param string $username - current user from $_SESSION
* @param string $fPassword_current - password for current user (to prevent user spoofing?)
* @param string $fException_ip - IP address
* @param string $fException_desc
* @param string $fException_user
* @param TotpPf $totppf
* @param array $PALANG
* @return void
*/
function add_exception(string $username, string $fPassword_current, string $fException_ip, string $fException_desc, string $fException_user, TotpPf $totppf,array $PALANG)
{
try {
if ($totppf->addException($username, $fPassword_current, $fException_ip, $fException_user, $fException_desc)) {
flash_info($PALANG['pTotp_exception_result_success']);
header("Location: totp-exceptions.php");
exit(0);
} else {
flash_error($PALANG['pTotp_exception_result_error']);
}
} catch (\Exception $e) {
flash_error($e->getMessage());
}
}
function revoke_exception(string $username, int $id, TotpPf $totppf, array $PALANG)
{
// No extra password check by design, user might be in a hurry
$result = $totppf->deleteException($username, $id);
if ($result) {
flash_info($PALANG['pTotp_exceptions_revoked']);
}
}
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */