www/includes/signup.php

63 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2019-07-13 15:01:11 +00:00
<?php
2019-07-13 17:34:43 +00:00
// This code is licensed under the AGPL 3 or later by ubergeek (https://tildegit.org/ubergeek)
2019-07-13 15:01:11 +00:00
include "../config.php";
$name = $_GET['contact_name'];
$email = $_GET['email_address'];
$username = $_GET['username'];
2019-07-13 16:14:59 +00:00
$interest = $_GET['interest'];
2019-07-13 15:01:11 +00:00
$pubkey = $_GET['pubkey'];
$tv = $_GET['tv'];
2021-03-01 18:27:46 +00:00
// username passed lowercased
$username = strtolower($username);
// strip new line characters from the end
$pubkey = trim($pubkey);
2024-03-25 02:29:18 +00:00
$from = 'From: www-data <www-data@thunix.net>';
2019-07-13 17:24:36 +00:00
$destination_addr = "newuser@thunix.net";
2019-07-13 15:01:11 +00:00
$subject = "New User Registration";
2019-07-13 16:13:02 +00:00
$mailbody = "A new user has tried to register.
2019-07-13 15:01:11 +00:00
Username: $username
Real Name: $name
Email Address: $email
Interest: $interest
Pubkey: $pubkey";
2024-03-25 02:29:18 +00:00
// In the future, here, we *should* be able to build a process that
2019-07-13 15:01:11 +00:00
// somehow auto-verifies the user, and instead of email, it'll kick off the new user process here
$user_queue = '/dev/shm/userqueue';
// Spam attempt
$success = 'success1';
if ( $tv == "tildeverse" )
{
// Success!
$success = 'success2';
2024-03-25 02:29:18 +00:00
2024-01-23 04:23:45 +00:00
// Check if username already taken
if (posix_getpwnam($username)) {
2020-05-07 10:03:45 +00:00
$success = 'success3';
2024-01-23 04:23:45 +00:00
}
2019-07-13 15:01:11 +00:00
2024-01-23 04:23:45 +00:00
// Simple SSH public key format check
$valid_key_starts = ['ssh-rsa', 'ssh-dss', 'ecdsa-sha2', 'ssh-ed25519'];
$key_parts = explode(' ', $pubkey, 3);
if (!in_array($key_parts[0], $valid_key_starts) || count($key_parts) < 2) {
$success = 'success4';
2024-01-23 04:23:45 +00:00
}
2020-05-07 11:34:14 +00:00
2024-01-23 04:23:45 +00:00
if ($success == "success2") {
mail($destination_addr, $subject, $mailbody, $from);
$fp = fopen($user_queue, 'a');
2021-03-01 18:27:46 +00:00
fwrite($fp, "'$username','$email','$pubkey'\n");
fclose($fp);
2024-01-23 04:23:45 +00:00
}
}
2019-07-13 15:01:11 +00:00
header("Location: $site_root/?page=$success");
2019-07-13 15:01:11 +00:00
die();
2024-01-23 04:23:45 +00:00
?>