update signup.php to work with userqueue changes to help race condition

This commit is contained in:
deepend 2023-08-25 07:02:30 +00:00
parent 34a344a952
commit d15eb9206e
1 changed files with 21 additions and 29 deletions

View File

@ -9,13 +9,10 @@ $interest = $_GET['interest'];
$pubkey = $_GET['pubkey']; $pubkey = $_GET['pubkey'];
$tv = $_GET['tv']; $tv = $_GET['tv'];
// username passed lowercased
$username = strtolower($username); $username = strtolower($username);
// strip new line characters from the end
$pubkey = trim($pubkey); $pubkey = trim($pubkey);
$from = 'From: www-data <www-data@thunix.net>'; $from = 'From: www-data <www-data@thunix.net>';
$destination_addr = "newuser@thunix.net"; $destination_addr = "newuser@thunix.net";
$subject = "New User Registration"; $subject = "New User Registration";
$mailbody = "A new user has tried to register. $mailbody = "A new user has tried to register.
@ -25,38 +22,33 @@ Email Address: $email
Interest: $interest Interest: $interest
Pubkey: $pubkey"; Pubkey: $pubkey";
// In the future, here, we *should* be able to build a process that
// somehow auto-verifies the user, and instead of email, it'll kick off the new user process here
$user_queue = '/dev/shm/userqueue'; $user_queue = '/dev/shm/userqueue';
$user_file = $user_queue . '/' . $username;
// Spam attempt
$success = 'success1'; $success = 'success1';
if ( $tv == "tildeverse" ) if ($tv == "tildeverse") {
{ $success = 'success2';
// Success!
$success = 'success2';
// Check if username already taken
exec("id $username 2>&1", $null, $retval);
if($retval == 0)
$success = 'success3';
// Check SSH public key format: // Check if username already taken
exec("echo $pubkey | ssh-keygen -l -f - 2>&1", $null, $retval); exec("id $username 2>&1", $null, $retval);
if($retval != 0) if ($retval == 0)
$success = 'success4'; $success = 'success3';
if ( $success == "success2" ) // Check SSH public key format:
{ exec("echo $pubkey | ssh-keygen -l -f - 2>&1", $null, $retval);
mail($destination_addr, $subject, $mailbody, $from); if ($retval != 0)
$fp = fopen($user_queue, 'a'); $success = 'success4';
fwrite($fp, "'$username','$email','$pubkey'\n");
fclose($fp); if ($success == "success2") {
} mail($destination_addr, $subject, $mailbody, $from);
// Use a file for each username to avoid race conditions
$fp = fopen($user_file, 'w');
fwrite($fp, "'$username','$email','$pubkey'\n");
fclose($fp);
}
} }
header("Location: $site_root/?page=$success"); header("Location: $site_root/?page=$success");
die(); die();
?> ?>