generate password when script is run not when script is generated

This commit is contained in:
Arya Kiran 2022-11-23 20:25:25 +05:30
parent 8da014b850
commit f8289ccee5
1 changed files with 11 additions and 22 deletions

View File

@ -26,17 +26,6 @@
$str = str_replace("\r", '', $str);
return $str;
}
function getName() {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < 50; $i++) {
$index = rand(0, strlen($characters) - 1);
$randomString .= $characters[$index];
}
return $randomString;
}
$password = getName();
$success = false;
$username = $email = $ssh = $reason =
@ -96,7 +85,6 @@
?>
<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>-->
<span class="red">* Required field</span>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<p>Username:
@ -181,9 +169,10 @@
$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($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";
$contents .= 'password="$(tr -dc A-Za-z0-9 </dev/urandom | head -c 64)"' . "\n";
$contents .= '~/bin/mktuser ' . escapeshellarg($username) . ' "$password"' . " <<< " . escapeshellarg($_POST['ssh']) . "\n";
$contents .= 'echo "$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) . ' "$password"' . "\n";
if ($use_fedi) {
$pass_file = '/home/' . $username . '/mastodon-pass';
$contents .= 'touch /sshfs' . $pass_file . "\n";
@ -192,13 +181,13 @@
$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($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";
if ($use_git) $contents .= '~/bin/mkguser ' . escapeshellarg($username) . ' "$password"' . ' ' . escapeshellarg($email) . "\n";
if ($use_nc) $contents .= '~/bin/mknuser ' . escapeshellarg($username) . ' "$password"' . "\n";
if ($use_peertube) $contents .= '~/bin/mkpuser ' . escapeshellarg($username) . ' "$password"' . ' ' . escapeshellarg($email) . "\n";
if ($use_jitsi) $contents .= '~/bin/mkxuser ' . escapeshellarg($username) . ' "$password"' . " jitsi.vern.cc\n";
if ($use_xmpp) $contents .= '~/bin/mkxuser ' . escapeshellarg($username) . ' "$password"' . " vern.cc\n";
if ($use_xmppo) $contents .= '~/bin/mkxuser ' . escapeshellarg($username) . ' "$password"' . " vernccvbvyi5qhfzyqengccj7lkove6bjot2xhh5kajhwvidqafczrad.onion\n";
if ($use_xmppi) $contents .= '~/bin/mkxuser ' . escapeshellarg($username) . ' "$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";