forked from vern/website
Merge newsletter.php and confirm.php
Signed-off-by: Skylar "The Cobra" Widulski <cobra@vern.cc>
This commit is contained in:
parent
283ab54f84
commit
1f913dcaac
|
@ -1,99 +0,0 @@
|
|||
<?php session_start(); ?>
|
||||
<!DOCTYPE html>
|
||||
<!--
|
||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta charset="UTF-8">
|
||||
<meta name="description" content="Confirm action">
|
||||
<link rel="stylesheet" href="//gcdn.vern.cc/vernsite/style.css">
|
||||
<title>Confirm | ~vern</title>
|
||||
</head>
|
||||
<body>
|
||||
<!--#include file="nav.php" -->
|
||||
|
||||
<?php
|
||||
function sanitize($str) {
|
||||
$str = trim($str);
|
||||
$str = stripslashes($str);
|
||||
$str = htmlspecialchars($str);
|
||||
$str = str_replace("\r", '', $str);
|
||||
return $str;
|
||||
}
|
||||
|
||||
$email = $err = '';
|
||||
|
||||
if (!empty($_GET['email'])) {
|
||||
if (filter_var(sanitize($_GET['email']), FILTER_VALIDATE_EMAIL)) {
|
||||
if (preg_match("/^" . preg_quote($_GET['email']) . "$/", file_get_contents("/var/spool/list")) === 1) {
|
||||
$email = sanitize($_GET['email']);
|
||||
} else {
|
||||
$err = "E-mail already in use";
|
||||
}
|
||||
} 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']) {
|
||||
$handle = fopen("/var/spool/list", "a");
|
||||
fwrite($handle, $code . "\n");
|
||||
fclose($handle);
|
||||
}
|
||||
} else {
|
||||
if (empty($err)) {
|
||||
if (empty($_GET['fail'])) {
|
||||
$code = substr(md5(rand()), 0, 8);
|
||||
|
||||
$handle = fopen($filename, "w+");
|
||||
chmod($filename, 0600);
|
||||
fwrite($handle, $code);
|
||||
fclose($handle);
|
||||
|
||||
$to = $email;
|
||||
$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($to, $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>
|
||||
<form method="get" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]) ?>">
|
||||
<input type="text" id="email" name="email" value="<?php echo htmlspecialchars($email); ?>" disabled hidden>
|
||||
|
||||
<p>Code <span class="red">* <?php echo $sub_err; ?></span>
|
||||
<input type="text" name="code"></p>
|
||||
|
||||
<br>
|
||||
<span><input type="submit" value="Confirm" style="width:100px;height:40px;font-size:20px"></span>
|
||||
</form><br>
|
||||
<?php
|
||||
} else {
|
||||
session_start();
|
||||
$_SESSION["err"] = $err;
|
||||
?>
|
||||
<meta http-equiv="refresh" content="0;url=/en/newsletter">
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!--#include file="footer.cgi" -->
|
||||
</body>
|
||||
</html>
|
|
@ -1,4 +1,3 @@
|
|||
<?php session_start(); ?>
|
||||
<!DOCTYPE html>
|
||||
<!--
|
||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
@ -26,38 +25,85 @@
|
|||
$str = str_replace("\r", '', $str);
|
||||
return $str;
|
||||
}
|
||||
$err = '';
|
||||
if (!empty($_SESSION['err'])) {
|
||||
$err = sanitize($_SESSION['err']);
|
||||
$err = $email = $code_err = '';
|
||||
if (!empty($_GET['email'])) {
|
||||
if (filter_var(sanitize($_GET['email']), FILTER_VALIDATE_EMAIL)) {
|
||||
if (preg_match("/^" . preg_quote($_GET['email']) . "$/", file_get_contents("/var/spool/list")) === 1) {
|
||||
$email = sanitize($_GET['email']);
|
||||
} else {
|
||||
$err = "E-mail already in use";
|
||||
}
|
||||
} else {
|
||||
$err = "Invalid E-mail";
|
||||
}
|
||||
} else {
|
||||
$err = "E-mail is required";
|
||||
}
|
||||
if (empty($_GET['action']) || ($_GET['action'] != "sub" && $_GET['action'] != "unsub") || !empty($err)) {
|
||||
?>
|
||||
<div class=h><h1 id=list>Mailing List</h1> <a aria-hidden=true href=#list>#list</a></div>
|
||||
<div class=h><h2 id=subscribe>Subscribe</h1> <a aria-hidden=true href=#subscribe>#subscribe</a></div>
|
||||
<span class="red">* Required field</span>
|
||||
<form method="get" action="/en/confirm">
|
||||
<p>E-mail <span class="red">* <?php echo $err; ?></span>
|
||||
<input type="text" name="email"></p>
|
||||
|
||||
<input type="checkbox" id="sub" name="sub" checked disabled hidden>
|
||||
<select id="action" name="action">
|
||||
<option value="sub">Subscribe</option>
|
||||
<option value="unsub">Unsubscribe</option>
|
||||
</select>
|
||||
|
||||
<br>
|
||||
<span><input type="submit" value="Subscribe" style="width:100px;height:40px;font-size:20px"></span>
|
||||
<span><input type="submit" value="Submit" style="width:100px;height:40px;font-size:20px"></span>
|
||||
</form><br>
|
||||
<div class=h><h2 id=unsubscribe>Unsubscribe</h1> <a aria-hidden=true href=#unsubscribe>#unsubscribe</a></div>
|
||||
<span class="red">* Required field</span>
|
||||
<form method="get" action="/en/confirm">
|
||||
<p>E-mail <span class="red">* <?php echo $err; ?></span>
|
||||
<input type="text" name="email"></p>
|
||||
<?php
|
||||
} else {
|
||||
$filename = "/tmp/list-code-" . $email;
|
||||
|
||||
<input type="checkbox" id="unsub" name="unsub" checked disabled hidden>
|
||||
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);
|
||||
} else {
|
||||
$code_err = 'Incorrect code';
|
||||
}
|
||||
} else {
|
||||
$code = substr(md5(rand()), 0, 8);
|
||||
$handle = fopen($filename, "w+");
|
||||
chmod($filename, 0600);
|
||||
fwrite($handle, $code);
|
||||
fclose($handle);
|
||||
|
||||
$to = $email;
|
||||
$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($to, $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>
|
||||
<form method="get" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]) ?>">
|
||||
<input type="text" id="email" name="email" value="<?php echo htmlspecialchars($email); ?>" disabled hidden>
|
||||
|
||||
<p>Code <span class="red">* <?php echo $code_err; ?></span>
|
||||
<input type="text" name="code"></p>
|
||||
|
||||
<br>
|
||||
<span><input type="submit" value="Unsubscribe" style="width:100px;height:40px;font-size:20px"></span>
|
||||
<span><input type="submit" value="Confirm" style="width:100px;height:40px;font-size:20px"></span>
|
||||
</form><br>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<!--#include file="footer.cgi" -->
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
unset($_SESSION['err']);
|
||||
session_destroy();
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue