site/signup/signup-handler.php

67 lines
2.5 KiB
PHP
Raw Normal View History

2018-06-09 03:17:35 +00:00
<?php
require __DIR__.'/../vendor/autoload.php';
if ($_SERVER["SERVER_NAME"] != "localhost")
require_once "/home/ben/ultimate-email/support/smtp.php";
2018-06-20 16:02:28 +00:00
$reserved_names = ['git', 'irc', 'mail', 'pad', 'sudo', 'root', 'admin', 'postmaster', 'paste', 'quotes'];
2018-06-09 03:17:35 +00:00
$message = "";
if (isset($_REQUEST["username"]) && isset($_REQUEST["email"])) {
// Check the name.
$name = trim($_REQUEST["username"]);
if ($name == "")
$message .= "<li>please fill in your desired username</li>";
if (strlen($name) > 32)
$message .= "<li>username too long (32 character max)</li>";
if (!preg_match('/^[A-Za-z][A-Za-z0-9]{2,31}$/', $name))
$message .= "<li>username contains invalid characters (lowercase only, must start with a letter)</li>";
2018-06-20 16:02:28 +00:00
if (posix_getpwnam($name) || in_array($name, $reserved_names))
2018-06-09 03:17:35 +00:00
$message .= "<li>sorry, the username $name is unavailable</li>";
// Check the e-mail address.
$email = trim($_REQUEST["email"]);
if ($email == "")
$message .= "<li>please fill in your email address</li>";
else {
$result = SMTP::MakeValidEmailAddress($_REQUEST["email"]);
if (!$result["success"])
$message .= "<li>invalid email address: " . htmlspecialchars($result["error"]) . "</li>";
elseif ($result["email"] != $email)
$message .= "<li>invalid email address. did you mean: " . htmlspecialchars($result["email"]) . "</li>";
}
if ($_REQUEST["sshkey"] == "") {
$message .= "<li>ssh key required: please create one and submit the public key</li>";
}
if ($message == "") { // no validation errors
2018-06-12 00:22:34 +00:00
$msgbody = "
desired username: {$_REQUEST["username"]}
contact email: {$_REQUEST["email"]}
reason: {$_REQUEST["interest"]}
ssh key:
{$_REQUEST["sshkey"]}
";
2018-06-09 03:17:35 +00:00
2018-06-11 22:39:13 +00:00
if (mail('sudoers', 'new tilde.team signup', $msgbody, "Reply-To: {$_REQUEST["email"]}")) {
2018-06-11 22:36:01 +00:00
echo '<div class="alert alert-success" role="alert">
email sent! i\'ll get back to you soon with login instructions! <a href="/">back to tilde.team home</a>
</div>';
} else {
echo '<div class="alert alert-danger" role="alert">
something went wrong... please send an email to <a href="mailto:sudoers@tilde.team">sudoers@tilde.team</a> with details of what happened
</div>';
}
2018-06-09 03:17:35 +00:00
} else {
?>
<div class="alert alert-warning" role="alert">
<strong>please correct the following errors: </strong>
<?=$message?>
</div>
<?php
}
}
?>