make register.php autogen passwords instead of asking user to input one

This commit is contained in:
Arya Kiran 2022-11-22 17:48:10 +05:30
parent c21b58ddad
commit 084706c221
1 changed files with 26 additions and 34 deletions

View File

@ -26,11 +26,21 @@
$str = str_replace("\r", '', $str);
return $str;
}
function getName() {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < 10; $i++) {
$index = rand(0, strlen($characters) - 1);
$randomString .= $characters[$index];
}
return $randomString;
}
$password = getName();
$success = false;
$username = $passowrd0 = $password1 = $email = $ssh = $reason =
$username_err = $password0_err = $password1_err = $email_err = $ssh_err = $reason_err = '';
$username = $email = $ssh = $reason =
$username_err = $email_err = $ssh_err = $reason_err = '';
$username_re = '/^[a-z_][a-z0-9_]{0,30}$/';
@ -50,17 +60,6 @@
$username_err = "Username is required";
}
if (!empty($_POST['password0'] || !empty($_POST['password1']))) {
if ($_POST['password1'] === $_POST['password0']) {
$password0 = $_POST['password0'];
$password1 = $_POST['password1'];
} else {
$password0_err = $password1_err = "Passwords do not match";
}
} else {
$password0_err = $password1_err = "Password is required";
}
if (!empty($_POST['email'])) {
if (filter_var(sanitize($_POST['email']), FILTER_VALIDATE_EMAIL)) {
$email = sanitize($_POST['email']);
@ -89,7 +88,7 @@
$reason_err = "Join reason is required";
}
if (empty($username_err . $password0_err . $password1_err . $email_err . $ssh_err . $reason_err))
if (empty($username_err . $email_err . $ssh_err . $reason_err))
$success = true;
}
@ -97,21 +96,13 @@
?>
<div class=h><h1 id=signup>Sign Up</h1> <a aria-hidden=true href=#signup>#signup</a></div>
<p>See the <a href=//wiki.vern.cc/doku.php?id=guides:register>wiki page</a> on how to register.</p>
<p>WARNING: Your password must contain at least one lowercase letter, one uppercase letter, and one number. This is a restriction of our mail server and PeerTube.</p>
<!--<p>WARNING: Your password must contain at least one lowercase letter, one uppercase letter, and one number. This is a restriction of our mail server and PeerTube.</p>-->
<span class="red">* Required field</span>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<p>Username:
<input type="text" name="username">
<span class="red">* <?php echo $username_err; ?></span></p>
<p>Password:
<input type="password" name="password0">
<span class="red">* <?php echo $password0_err; ?></span></p>
<p>Password:
<input type="password" name="password1">
<span class="red">* <?php echo $password1_err; ?></span></p>
<p>E-mail (We need one so we can contact you) <span class="red">* <?php echo $email_err; ?></span>
<input type="text" name="email"></p>
@ -190,8 +181,9 @@
$message .= ".\nJoin reason:\n$reason\n\n\nTo accept this request, run this command as root:\n/root/bin/accept $username\nTo deny this request, run this command as root:\n/root/bin/deny $username\n";
$contents = "#!/usr/bin/env -S bash -e\n\n# This is the registration script for $username \n# This script was automatically generated by http://" . $_SERVER['HTTP_HOST'] . htmlspecialchars($_SERVER['PHP_SELF']). "\n\n";
$contents .= '~/bin/mktuser ' . escapeshellarg($username) . ' ' . escapeshellarg($password0) . " <<< " . escapeshellarg($_POST['ssh']) . "\n\n";
if ($use_matrix) $contents .= '~/bin/mkmuser ' . escapeshellarg($username) . ' ' . escapeshellarg($password0) . "\n";
$contents .= '~/bin/mktuser ' . escapeshellarg($username) . ' ' . escapeshellarg($password) . " <<< " . escapeshellarg($_POST['ssh']) . "\n";
$contents .= 'echo ' . escapeshellarg($password) . ' > /sshfs/home/' . $username . '/pass && chmod 600 /sshfs/home/' . $username . '/pass && ssh 192.168.122.30 chown ' . escapeshellarg($username . ':' . $username) . ' /sshfs/home/' . $username . '/pass' . "\n\n";
if ($use_matrix) $contents .= '~/bin/mkmuser ' . escapeshellarg($username) . ' ' . escapeshellarg($password) . "\n";
if ($use_fedi) {
$pass_file = '/home/' . $username . '/mastodon-pass';
$contents .= 'touch /sshfs' . $pass_file . "\n";
@ -200,14 +192,14 @@
$contents .= '~/bin/mkfuser ' . escapeshellarg($username) . ' ' . escapeshellarg($email) . ' | tee /sshfs' . escapeshellarg($pass_file) . "\n";
unset($pass_file);
}
if ($use_git) $contents .= '~/bin/mkguser ' . escapeshellarg($username) . ' ' . escapeshellarg($password0) . ' ' . escapeshellarg($email) . "\n";
if ($use_nc) $contents .= '~/bin/mknuser ' . escapeshellarg($username) . ' ' . escapeshellarg($password0) . "\n";
if ($use_peertube) $contents .= '~/bin/mkpuser ' . escapeshellarg($username) . ' ' . escapeshellarg($password0) . ' ' . escapeshellarg($email) . "\n";
if ($use_jitsi) $contents .= '~/bin/mkxuser ' . escapeshellarg($username) . ' ' . escapeshellarg($password0) . " jitsi.vern.cc\n";
if ($use_xmpp) $contents .= '~/bin/mkxuser ' . escapeshellarg($username) . ' ' . escapeshellarg($password0) . " vern.cc\n";
if ($use_xmppo) $contents .= '~/bin/mkxuser ' . escapeshellarg($username) . ' ' . escapeshellarg($password0) . " vernccvbvyi5qhfzyqengccj7lkove6bjot2xhh5kajhwvidqafczrad.onion\n";
if ($use_xmppi) $contents .= '~/bin/mkxuser ' . escapeshellarg($username) . ' ' . escapeshellarg($password0) . " verncceu2kgz54wi7r5jatgmx2mqtsh3knxhiy4m5shescuqtqfa.b32.i2p\n";
$contents .= "s-nail -vr 'register@vern.cc' -c cobra@vern.cc -c neo@vern.cc -c aryak@vern.cc -s 'Your ~vern account has been created' -M text/plain " . escapeshellarg($email) . " < <(printf 'Hello %s,\\nYour membership request on ~vern has been accepted.\\nYou can now SSH into vern.cc using the public key(s) that you supplied to ~vern.\\nIf you signed up for Mastodon, a randomly generated password for the account will be in ~/mastodon-pass\\n\\nThank you for being a part of ~vern!' " . escapeshellarg($username) . ")\n";
if ($use_git) $contents .= '~/bin/mkguser ' . escapeshellarg($username) . ' ' . escapeshellarg($password) . ' ' . escapeshellarg($email) . "\n";
if ($use_nc) $contents .= '~/bin/mknuser ' . escapeshellarg($username) . ' ' . escapeshellarg($password) . "\n";
if ($use_peertube) $contents .= '~/bin/mkpuser ' . escapeshellarg($username) . ' ' . escapeshellarg($password) . ' ' . escapeshellarg($email) . "\n";
if ($use_jitsi) $contents .= '~/bin/mkxuser ' . escapeshellarg($username) . ' ' . escapeshellarg($password) . " jitsi.vern.cc\n";
if ($use_xmpp) $contents .= '~/bin/mkxuser ' . escapeshellarg($username) . ' ' . escapeshellarg($password) . " vern.cc\n";
if ($use_xmppo) $contents .= '~/bin/mkxuser ' . escapeshellarg($username) . ' ' . escapeshellarg($password) . " vernccvbvyi5qhfzyqengccj7lkove6bjot2xhh5kajhwvidqafczrad.onion\n";
if ($use_xmppi) $contents .= '~/bin/mkxuser ' . escapeshellarg($username) . ' ' . escapeshellarg($password) . " verncceu2kgz54wi7r5jatgmx2mqtsh3knxhiy4m5shescuqtqfa.b32.i2p\n";
$contents .= "s-nail -vr 'register@vern.cc' -c cobra@vern.cc -c neo@vern.cc -c aryak@vern.cc -s 'Your ~vern account has been created' -M text/plain " . escapeshellarg($email) . " < <(printf 'Hello %s,\\nYour membership request on ~vern has been accepted.\\nYou can now SSH into vern.cc using the public key(s) that you supplied to ~vern.\\nA global password for all the services you signed up to can be found at ~/pass. If you signed up for Mastodon, password for the account can be found at ~/mastodon-pass\\n\\nThank you for being a part of ~vern!' " . escapeshellarg($username) . ")\n";
$contents .= "rm -f $0\n";
$contents .= "exit\n\n\n";
$contents .= $reason . "\n";