diff --git a/pages/users.php b/pages/users.php index 5b6c34e..0ae2cca 100644 --- a/pages/users.php +++ b/pages/users.php @@ -16,21 +16,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { include_once 'app/FormValidator.php'; - if (isset($_POST['genpw'])) { - $validator = new FormValidator(array( - 'userid' => array('required' => true, 'regex' => '/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/') - )); - - if ($validator->isValid($_POST)) { - require_once 'app/utils.php'; - $token = generateToken(32); - $setToken = $RUNTIME['PDO']->prepare('REPLACE INTO PasswordResetTokens(PrincipalID,Token,RequestTime) VALUES(?,?,?)'); - $setToken->execute([$_POST['userid'], $token, time()]); - $resetLink = "https://".$RUNTIME['DOMAIN'].'/index.php?page=reset-password&token='.$token; - - $HTML->ReplaceSeitenInhalt("%%MESSAGE%%", ''); - } - } elseif (isset($_POST['generateLink'])) { + if (isset($_POST['generateLink'])) { $validator = new FormValidator(array()); // Needed only for CSRF token validation if ($validator->isValid($_POST)) { @@ -42,6 +28,46 @@ $HTML->ReplaceSeitenInhalt("%%link%%", $link); } + } elseif (isset($_POST['delident'])) { + $validator = new FormValidator(array( + 'userid' => array('required' => true, 'regex' => '/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/'), + 'identid' => array('required' => true, 'regex' => '/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/') + )); + + if ($validator->isValid($_POST)) { + include_once 'app/OpenSim.php'; + $os = new OpenSim(); + $identName = $os->getUserName($_POST['identid']); + $userName = $os->getUserName($_POST['userid']); + if($os->deleteIdentity($_POST['userid'], $_POST['identid'])) { + $HTML->ReplaceSeitenInhalt("%%MESSAGE%%", ''); + } else { + $HTML->ReplaceSeitenInhalt("%%MESSAGE%%", ''); + } + } + } else { + $validator = new FormValidator(array( + 'userid' => array('required' => true, 'regex' => '/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/') + )); + + if ($validator->isValid($_POST)) { + if (isset($_POST['genpw'])) { + require_once 'app/utils.php'; + $token = generateToken(32); + $setToken = $RUNTIME['PDO']->prepare('REPLACE INTO PasswordResetTokens(PrincipalID,Token,RequestTime) VALUES(?,?,?)'); + $setToken->execute([$_POST['userid'], $token, time()]); + $resetLink = "https://".$RUNTIME['DOMAIN'].'/index.php?page=reset-password&token='.$token; + + $HTML->ReplaceSeitenInhalt("%%MESSAGE%%", ''); + } elseif (isset($_POST['deluser'])) { + $name = $opensim->getUserName($_POST['userid']); + if ($opensim->deleteUser($_POST['userid'])) { + $HTML->ReplaceSeitenInhalt("%%MESSAGE%%", ''); + } else { + $HTML->ReplaceSeitenInhalt("%%MESSAGE%%", ''); + } + } + } } } @@ -59,7 +85,7 @@ $entry = ''.htmlspecialchars($row['FirstName']).''.htmlspecialchars($row['LastName']).''.htmlspecialchars($row['UserLevel']).'
%%CSRF%%
'; $statementIdent->execute([$row['PrincipalID']]); while ($identRow = $statementIdent->fetch()) { - $entry = $entry.''.htmlspecialchars($identRow['FirstName']).''.htmlspecialchars($identRow['LastName']).''.htmlspecialchars($identRow['UserLevel']).'
%%CSRF%%
'; + $entry = $entry.''.htmlspecialchars($identRow['FirstName']).''.htmlspecialchars($identRow['LastName']).''.htmlspecialchars($identRow['UserLevel']).'
%%CSRF%%
'; } $table = str_replace("%%ENTRY%%", $entry."%%ENTRY%%", $table); }