mirror of https://github.com/tildeclub/site.git
Update signup-handler.php
This commit is contained in:
parent
b47dbaec0c
commit
da8f2e95e1
|
@ -1,20 +1,59 @@
|
||||||
<?php
|
<?php
|
||||||
|
$filepath = __FILE__;
|
||||||
|
require __DIR__.'/../vendor/autoload.php';
|
||||||
require_once "email/smtp.php";
|
require_once "email/smtp.php";
|
||||||
|
|
||||||
function forbidden_name($name) {
|
function getUserIpAddr() {
|
||||||
return in_array($name, [
|
if(!empty($_SERVER['HTTP_CLIENT_IP'])) {
|
||||||
|
//ip from share internet
|
||||||
|
$ip = $_SERVER['HTTP_CLIENT_IP'];
|
||||||
|
} elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||||
|
//ip pass from proxy
|
||||||
|
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||||
|
} else {
|
||||||
|
$ip = $_SERVER['REMOTE_ADDR'];
|
||||||
|
}
|
||||||
|
return $ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
function add_ban_info($name, $email): void
|
||||||
|
{
|
||||||
|
$user_ip = getUserIpAddr();
|
||||||
|
$user_info = "$name - $email - $user_ip";
|
||||||
|
file_put_contents("/var/signups_banned", $user_info.PHP_EOL, FILE_APPEND);
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_ssh_pubkey($string): bool
|
||||||
|
{
|
||||||
|
// list from sshd(8)
|
||||||
|
$valid_pubkeys = [
|
||||||
|
'sk-ecdsa-sha2-nistp256@openssh.com',
|
||||||
|
'ecdsa-sha2-nistp256',
|
||||||
|
'ecdsa-sha2-nistp384',
|
||||||
|
'ecdsa-sha2-nistp521',
|
||||||
|
'sk-ssh-ed25519@openssh.com',
|
||||||
|
'ssh-ed25519',
|
||||||
|
'ssh-dss',
|
||||||
|
'ssh-rsa',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($valid_pubkeys as $pub)
|
||||||
|
if (str_starts_with($string, $pub)) return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function forbidden_name($name): bool
|
||||||
|
{
|
||||||
|
$badnames = [
|
||||||
'0x0',
|
'0x0',
|
||||||
'abuse',
|
'abuse',
|
||||||
'adam',
|
|
||||||
'admin',
|
'admin',
|
||||||
'administrator',
|
'administrator',
|
||||||
'amcclure',
|
|
||||||
'anton',
|
|
||||||
'auth',
|
'auth',
|
||||||
'autoconfig',
|
'autoconfig',
|
||||||
'bbj',
|
'bbj',
|
||||||
'broadcasthost',
|
'broadcasthost',
|
||||||
'chickfilla',
|
|
||||||
'cloud',
|
'cloud',
|
||||||
'forum',
|
'forum',
|
||||||
'ftp',
|
'ftp',
|
||||||
|
@ -30,7 +69,6 @@ function forbidden_name($name) {
|
||||||
'localdomain',
|
'localdomain',
|
||||||
'localhost',
|
'localhost',
|
||||||
'lounge',
|
'lounge',
|
||||||
'lukewarmcat',
|
|
||||||
'mail',
|
'mail',
|
||||||
'mailer-daemon',
|
'mailer-daemon',
|
||||||
'marketing',
|
'marketing',
|
||||||
|
@ -60,32 +98,58 @@ function forbidden_name($name) {
|
||||||
'wpad',
|
'wpad',
|
||||||
'www',
|
'www',
|
||||||
'znc',
|
'znc',
|
||||||
]);
|
];
|
||||||
|
|
||||||
|
return in_array(
|
||||||
|
$name,
|
||||||
|
array_merge(
|
||||||
|
$badnames,
|
||||||
|
file("/var/signups_current", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES),
|
||||||
|
file("/var/banned_names.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function forbidden_email($email): bool
|
||||||
|
{
|
||||||
|
$femail = file("/var/banned_emails.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||||
|
return in_array($email, $femail);
|
||||||
|
}
|
||||||
|
|
||||||
|
function forbidden_sshkey($sshkey): bool
|
||||||
|
{
|
||||||
|
$fsshkey = file("/var/banned_sshkeys.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||||
|
$fsk = [];
|
||||||
|
foreach ($fsshkey as $line) {
|
||||||
|
$fsk_line = explode(' ',trim($line));
|
||||||
|
$fsk[] = $fsk_line[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
$sk = explode(' ',trim($sshkey));
|
||||||
|
|
||||||
|
return in_array($sk[1], $fsk);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$message = "";
|
$message = "";
|
||||||
if (isset($_REQUEST["username"]) && isset($_REQUEST["email"])) {
|
if (isset($_REQUEST["username"]) && isset($_REQUEST["email"])) {
|
||||||
// Check the name.
|
// Check the name.
|
||||||
$name = trim($_REQUEST["username"]);
|
$name = trim($_REQUEST["username"]);
|
||||||
if ($name == "")
|
if ($name == "")
|
||||||
$message .= "<li>please fill in your desired username</li>";
|
$message .= "<li>fill in your desired username</li>\n";
|
||||||
|
else {
|
||||||
|
if (strlen($name) < 2)
|
||||||
|
$message .= "<li>username is too short (2 character min)</li>\n";
|
||||||
|
|
||||||
if (strlen($name) > 32)
|
if (strlen($name) > 32)
|
||||||
$message .= "<li>username too long (32 character max)</li>";
|
$message .= "<li>username too long (32 character max)</li>\n";
|
||||||
|
|
||||||
if (!preg_match('/^[a-z][a-z0-9]{1,31}$/', $name))
|
if (strlen($name) > 1 && !preg_match('/^[a-z][a-z0-9]{1,31}$/', $name))
|
||||||
$message .= "<li>username contains invalid characters (lowercase ascii only, must start with a letter)</li>";
|
$message .= "<li>username contains invalid characters (lowercase only, must start with a letter).</li>\n";
|
||||||
|
|
||||||
if ($_REQUEST["sshkey"] == "" || mb_substr($_REQUEST["sshkey"], 0, 4) !== "ssh-")
|
if (posix_getpwnam($name) || forbidden_name($name))
|
||||||
$message .= '<li>ssh key required: please create one and submit the public key. '
|
$message .= "<li>sorry, the username $name is unavailable</li>\n";
|
||||||
. 'see our <a href="https://tilde.club/wiki/ssh.html">ssh wiki</a> or '
|
}
|
||||||
. 'hop on <a href="https://web.tilde.chat/?join=club">irc</a> and ask for help</li>';
|
|
||||||
|
|
||||||
if ($_REQUEST["interest"] == "")
|
|
||||||
$message .= "<li>please explain why you're interested so we can make sure you're a real human being</li>";
|
|
||||||
|
|
||||||
if (posix_getpwnam($name) || forbidden_name($name))
|
|
||||||
$message .= "<li>sorry, the username $name is unavailable</li>";
|
|
||||||
|
|
||||||
// Check the e-mail address.
|
// Check the e-mail address.
|
||||||
$email = trim($_REQUEST["email"]);
|
$email = trim($_REQUEST["email"]);
|
||||||
|
@ -97,13 +161,35 @@ if (isset($_REQUEST["username"]) && isset($_REQUEST["email"])) {
|
||||||
$message .= "<li>invalid email address: " . htmlspecialchars($result["error"]) . "</li>";
|
$message .= "<li>invalid email address: " . htmlspecialchars($result["error"]) . "</li>";
|
||||||
elseif ($result["email"] != $email)
|
elseif ($result["email"] != $email)
|
||||||
$message .= "<li>invalid email address. did you mean: " . htmlspecialchars($result["email"]) . "</li>";
|
$message .= "<li>invalid email address. did you mean: " . htmlspecialchars($result["email"]) . "</li>";
|
||||||
|
|
||||||
|
elseif ($name != "" && forbidden_email($email)) {
|
||||||
|
$message .= "<li>your email is banned!</li><br />";
|
||||||
|
add_ban_info($name, $email);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_REQUEST["interest"] == "")
|
||||||
|
$message .= "<li>please explain why you're interested so we can make sure you're a real human being</li>";
|
||||||
|
|
||||||
|
$sshkey = trim($_REQUEST["sshkey"]);
|
||||||
|
if ($sshkey == "" || !is_ssh_pubkey($sshkey))
|
||||||
|
$message .= '<li>ssh key required: please create one and submit the public key. '
|
||||||
|
. 'see our <a href="https://tilde.club/wiki/ssh">ssh wiki</a> or '
|
||||||
|
. 'hop on <a href="https://web.newnet.net/?join=club">irc</a> and ask for help</li>';
|
||||||
|
else {
|
||||||
|
if ($name != "" && $email != "") {
|
||||||
|
if (forbidden_sshkey($sshkey)) {
|
||||||
|
$message .= "<li>your sshkey is banned!</li>\n";
|
||||||
|
add_ban_info($name, $email);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// no validation errors
|
// no validation errors
|
||||||
if ($message == "") {
|
if ($message == "") {
|
||||||
$sshkey = trim($_REQUEST["sshkey"]);
|
$makeuser = "makeuser {$_REQUEST["username"]} {$_REQUEST["email"]} \"$sshkey\"";
|
||||||
$makeuser = "makeuser {$_REQUEST["username"]} {$_REQUEST["email"]} \"{$sshkey}\"";
|
|
||||||
$msgbody = "
|
$msgbody = "
|
||||||
username: {$_REQUEST["username"]}
|
username: {$_REQUEST["username"]}
|
||||||
email: {$_REQUEST["email"]}
|
email: {$_REQUEST["email"]}
|
||||||
|
@ -112,25 +198,28 @@ reason: {$_REQUEST["interest"]}
|
||||||
$makeuser
|
$makeuser
|
||||||
";
|
";
|
||||||
|
|
||||||
if (mail('root', 'new tilde.club signup', $msgbody)) {
|
if (mail('sudoers', 'new tilde.club signup', $msgbody)) {
|
||||||
echo '<div class="alert alert-success" role="alert">
|
echo '<div class="alert alert-success" role="alert">
|
||||||
email sent! we\'ll get back to you soon (usually within a day) with login instructions! be sure to check your spam folder as we\'ve had several reports of being marked as spam! <a href="/">back to tilde.club home</a>
|
email sent! we\'ll get back to you soon (usually within a day) with login instructions! <a href="/">back to tilde.club home</a>
|
||||||
</div>';
|
</div>';
|
||||||
|
// temp. add to forbidden to prevent double signups (cleanup after user creation)
|
||||||
|
file_put_contents("/var/signups_current", $name.PHP_EOL, FILE_APPEND);
|
||||||
file_put_contents("/var/signups", $makeuser.PHP_EOL, FILE_APPEND);
|
file_put_contents("/var/signups", $makeuser.PHP_EOL, FILE_APPEND);
|
||||||
|
// clear form fields
|
||||||
|
$_REQUEST["email"] = $_REQUEST["username"] = $_REQUEST["sshkey"] = $_REQUEST["interest"] = "";
|
||||||
} else {
|
} else {
|
||||||
echo '<div class="alert alert-danger" role="alert">
|
echo '<div class="alert alert-danger" role="alert">
|
||||||
something went wrong... please send an email to <a href="mailto:root@tilde.club">root@tilde.club</a> with details of what happened
|
something went wrong... please send an email to <a href="mailto:root@tilde.club">root@tilde.club</a> with details of what happened
|
||||||
</div>';
|
</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
?>
|
?>
|
||||||
<div class="alert alert-warning" role="alert">
|
<div class="alert alert-warning" role="alert">
|
||||||
<strong>please correct the following errors: </strong>
|
<strong>notice: </strong>
|
||||||
<?=$message?>
|
<?=$message?>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue