Skip to content

cleanup panel/account.php #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/functional/LoginShellSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testSetLoginShellCustom(string $shell): void
// FIXME shell is not validated
post(
__DIR__ . "/../../webroot/panel/account.php",
["form_type" => "loginshell", "shellSelect" => "custom", "shell" => $shell]
["form_type" => "loginshell", "shellSelect" => "Custom", "shell" => $shell]
);
$this->assertEquals($shell, $USER->getLoginShell());
}
Expand Down
97 changes: 41 additions & 56 deletions webroot/panel/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
$USER->setSSHKeys($keys, $OPERATOR); // Update user keys
break;
case "loginshell":
if ($_POST["shellSelect"] == "custom") {
if ($_POST["shellSelect"] == "Custom") {
$USER->setLoginShell($_POST["shell"], $OPERATOR);
} else {
$USER->setLoginShell($_POST["shellSelect"], $OPERATOR);
Expand Down Expand Up @@ -186,49 +186,28 @@
<hr>

<form action="" method="POST">

<input type="hidden" name="form_type" value="loginshell">

<select id="loginSelector" name= "shellSelect">

<option value="" disabled hidden>Select Login Shell...</option>

<?php
$cur_shell = $USER->getLoginShell();
$found_selector = false;
foreach ($CONFIG["loginshell"]["shell"] as $shell) {
if ($cur_shell == $shell) {
echo "<option selected>$shell</option>";
$found_selector = true;
} else {
echo "<option>$shell</option>";
}
}

if ($found_selector) {
echo "<option value='custom'>Custom</option>";
} else {
echo "<option value='custom' selected>Custom</option>";
}
?>
</select>

<?php

if ($found_selector) {
echo "<input id='customLoginBox' type='text'
placeholder='Enter login shell path (ie. /bin/bash)' name='shell'>";
} else {
echo "<input id='customLoginBox' type='text'
placeholder='Enter login shell path (ie. /bin/bash)' name='shell' value='$cur_shell'>";
}

?>
<br>
<input type='submit' value='Set Login Shell'>

<input type="hidden" name="form_type" value="loginshell">
<select id="loginSelector" name="shellSelect">
<?php
foreach ($CONFIG["loginshell"]["shell"] as $shell) {
echo "<option>$shell</option>";
}
echo "<option id='customLoginSelectorOption'>Custom</option>";
?>
</select>
<?php
echo "
<input
id='customLoginBox'
type='text'
placeholder='Enter login shell path (ie. /bin/bash)'
name='shell'
>
";
?>
<br>
<input id='submitLoginShell' type='submit' value='Set Login Shell'>
</form>

<hr>

<h5>Account Deletion</h5>
Expand Down Expand Up @@ -257,30 +236,36 @@


<script>
const sitePrefix = '<?php echo $CONFIG["site"]["prefix"]; ?>';
const ldapLoginShell = '<?php echo $USER->getLoginShell(); ?>';

$("button.btnAddKey").click(function() {
openModal("Add New Key", "<?php echo $CONFIG["site"]["prefix"]; ?>/panel/modal/new_key.php");
openModal("Add New Key", `${sitePrefix}/panel/modal/new_key.php`);
});

var customLoginBox = $("#customLoginBox");
if (customLoginBox.val() == "") {
// login box is empty, so we hide it by default
// if the login box had a value, that means it would be a custom shell
// and should not hide by default
customLoginBox.hide();
var defaultShellSelected = false;
$("#loginSelector option").each(function(i, e) {
if ($(this).val() == ldapLoginShell) {
$(this).prop("selected", true);
defaultShellSelected = true;
}
});
if (!defaultShellSelected) {
$("#customLoginBox").val(ldapLoginShell);
$("#customLoginSelectorOption").prop("selected", true);
}

$("#loginSelector").change(function() {
function showOrHideCustomLoginBox() {
var customBox = $("#customLoginBox");
if($(this).val() == "custom") {
if($("#loginSelector").val() == "Custom") {
customBox.show();
} else {
customBox.hide();
}
});

if ($("#loginSelector").val() == "custom") {
$("#customLoginBox").show();
}
$("#loginSelector").change(showOrHideCustomLoginBox);
showOrHideCustomLoginBox();

</script>

<style>
Expand Down
Loading