Move all the stuff to the top so it can be run always

Signed-off-by: Skylar "The Cobra" Widulski <cobra@vern.cc>
This commit is contained in:
Skylar "The Cobra" Widulski 2023-08-26 04:13:29 -04:00
parent 321b935558
commit a8250004a5
Signed by: cobra
GPG Key ID: 4FD8F812083FF6F9
1 changed files with 41 additions and 40 deletions

View File

@ -39,6 +39,47 @@
else $err = "Invalid E-mail";
else $err = "E-mail is required";
$filename = "/tmp/list-code-" . $email;
if (!empty($_GET['code'])) {
if (file_get_contents($filename) == $_GET['code']) {
if ($_GET['action'] == "sub") {
$handle = fopen("/var/spool/list", "a");
fwrite($handle, $code . "\n");
fclose($handle);
} else {
$contents = file_get_contents("/var/spool/list");
$contents = str_replace($line . PHP_EOL, '', $contents);
file_put_contents("/var/spool/list", $contents);
}
unlink($filename);
$subject = $_GET['action'] == "sub" ? "S" : "Uns" . "ubscription confirmed";
$headers = "From: announcements@vern.cc\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain\n";
$message = "You have been " . $_GET['action'] == "sub" ? "added to" : "removed from" . " the ~vern announcement mailing list";
mail($email, $subject, $message, $headers);
} else {
$code_err = 'Incorrect code';
}
} else {
$code = substr(md5(rand()), 0, 8);
$handle = fopen($filename, "w+");
chmod($filename, 0600);
fwrite($handle, $code);
fclose($handle);
$subject = "Your confirmation code";
$headers = "From: announcements@vern.cc\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain\n";
$message = "Your confirmation code is $code. Do not share it with anyone.\n\nIf you did not initiate this, you can safely ignore this message.";
mail($email, $subject, $message, $headers);
}
if (empty($_GET['action']) || ($_GET['action'] != "sub" && $_GET['action'] != "unsub") || !empty($err) && empty($_GET['code'])) {
?>
@ -57,46 +98,6 @@
</form><br>
<?php
} else {
$filename = "/tmp/list-code-" . $email;
if (!empty($_GET['code'])) {
if (file_get_contents($filename) == $_GET['code']) {
if ($_GET['action'] == "sub") {
$handle = fopen("/var/spool/list", "a");
fwrite($handle, $code . "\n");
fclose($handle);
} else {
$contents = file_get_contents("/var/spool/list");
$contents = str_replace($line . PHP_EOL, '', $contents);
file_put_contents("/var/spool/list", $contents);
}
unlink($filename);
$subject = $_GET['action'] == "sub" ? "S" : "Uns" . "ubscription confirmed";
$headers = "From: announcements@vern.cc\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain\n";
$message = "You have been " . $_GET['action'] == "sub" ? "added to" : "removed from" . " the ~vern announcement mailing list";
mail($email, $subject, $message, $headers);
} else {
$code_err = 'Incorrect code';
}
} else {
$code = substr(md5(rand()), 0, 8);
$handle = fopen($filename, "w+");
chmod($filename, 0600);
fwrite($handle, $code);
fclose($handle);
$subject = "Your confirmation code";
$headers = "From: announcements@vern.cc\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain\n";
$message = "Your confirmation code is $code. Do not share it with anyone.\n\nIf you did not initiate this, you can safely ignore this message.";
mail($email, $subject, $message, $headers);
}
?>
<div class=h><h1 id=confirm>Confirm Action</h1> <a aria-hidden=true href=#confirm>#confirm</a></div>
<p>A confirmation code was sent to <?php echo htmlspecialchars($email); ?></p>