137 lines
5.2 KiB
PHP
137 lines
5.2 KiB
PHP
<!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="tr">
|
||
<head>
|
||
<meta name="viewport" content="width=device-width">
|
||
<meta charset="UTF-8">
|
||
<meta name="description" content="~vern'in mail listesi kayıt ol">
|
||
<link rel="preload" href="//gcdn.vern.cc/vernsite/style.css">
|
||
<link rel="stylesheet" href="//gcdn.vern.cc/vernsite/style.css">
|
||
<title>Mail Listesi | ~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;
|
||
}
|
||
$err = $email = $code = $code_err = '';
|
||
$confirmed = false;
|
||
if (!empty($_GET['action'])) {
|
||
if (!empty($_GET['email'])) {
|
||
if (filter_var(sanitize($_GET['email']), FILTER_VALIDATE_EMAIL)) {
|
||
if (preg_match("/^" . preg_quote($_GET['email']) . "$/m", file_get_contents("/var/spool/list")) === 1) {
|
||
if ($_GET['action'] == "unsub")
|
||
$email = sanitize($_GET['email']);
|
||
else $err = "E-mail zaten listede";
|
||
} else {
|
||
if ($_GET['action'] == "sub")
|
||
$email = sanitize($_GET['email']);
|
||
else $err = "E-mail listede yok";
|
||
}
|
||
} else $err = "Geçersiz E-mail";
|
||
} else $err = "E-mail gereklidir";
|
||
}
|
||
|
||
$filename = "/tmp/list-code-" . $email;
|
||
|
||
if (empty($err)) {
|
||
if (!empty($_GET['code'])) {
|
||
if (file_get_contents($filename) == $_GET['code']) {
|
||
if ($_GET['action'] == "sub") {
|
||
file_put_contents("/var/spool/list", $email . PHP_EOL, FILE_APPEND);
|
||
} else {
|
||
$contents = file_get_contents("/var/spool/list");
|
||
$contents = preg_replace("/^" . preg_quote($email) . "$/m", '', $contents);
|
||
$contents = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $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 = "Şu anda ~vern duyuru mail listesin" . ($_GET['action'] == "sub" ? "e eklendiniz" : "den ayrıldınız");
|
||
|
||
mail($email, $subject, $message, $headers);
|
||
$confirmed = true;
|
||
} else {
|
||
$code_err = 'Hatalı kod';
|
||
}
|
||
} else {
|
||
$code = substr(md5(rand()), 0, 8);
|
||
$handle = fopen($filename, "w+");
|
||
chmod($filename, 0600);
|
||
fwrite($handle, $code);
|
||
fclose($handle);
|
||
|
||
$subject = "Doğrulama kodunuz";
|
||
$headers = "From: announcements@vern.cc\n";
|
||
$headers .= "MIME-Version: 1.0\n";
|
||
$headers .= "Content-type: text/plain\n";
|
||
$message = "Doğrulama kodunuz $code. Kimseyle paylaşmayın.\n\nBunu siz başlatmadıysanız bu mesajı güvenle göz ardı edebilirsiniz.";
|
||
|
||
mail($email, $subject, $message, $headers);
|
||
}
|
||
}
|
||
|
||
if ((($_GET['action'] != "sub" && $_GET['action'] != "unsub")) || (!empty($err) && empty($code_err))) {
|
||
|
||
?>
|
||
<div class=h><h1 id=list>Mail Listesi</h1> <a aria-hidden=true href=#list>#list</a></div>
|
||
<form method="get" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]) ?>">
|
||
<p>E-mail <span class="red">* <?php echo $err; ?></span>
|
||
<input type="text" name="email"></p>
|
||
|
||
<select id="action" name="action">
|
||
<option value="sub">Abone ol</option>
|
||
<option value="unsub">Abonelikten çık</option>
|
||
</select><br>
|
||
|
||
<br>
|
||
<span><input type="submit" value="Submit" style="width:100px;height:40px;font-size:20px"></span>
|
||
</form><br>
|
||
<?php
|
||
} else if (!$confirmed) {
|
||
?>
|
||
<div class=h><h1 id=confirm>Eylemi Onayla</h1> <a aria-hidden=true href=#confirm>#confirm</a></div>
|
||
<p>Doğrulama kodu <?php echo htmlspecialchars($email); ?> adresine gönderildi</p>
|
||
<form method="get" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]) ?>">
|
||
<input type="text" id="email" name="email" value="<?php echo htmlspecialchars($email); ?>" hidden>
|
||
|
||
<p>Code <span class="red">* <?php echo $code_err; ?></span>
|
||
<input type="text" name="code"></p>
|
||
|
||
<select id="action" name="action" hidden>
|
||
<option value="<?php echo htmlspecialchars($_GET['action']); ?>"></option>
|
||
</select>
|
||
|
||
<br>
|
||
<span><input type="submit" value="Confirm" style="width:100px;height:40px;font-size:20px"></span>
|
||
</form><br>
|
||
<?php
|
||
} else {
|
||
?>
|
||
<meta http-equiv="refresh" content="5;url=/tur/" />
|
||
<div class=h><h1 id=thanks>Onaylandı!</h1> <a aria-hidden=true href=#thanks>#thanks</a></div>
|
||
<p>İşlemi onaylayan bir e-posta da alacaksınız.</p>
|
||
<p>5 saniye içerisinde <a href="/tur/">ana sayfaya</a> yönlendiriceksiniz.</p>
|
||
<?php
|
||
}
|
||
?>
|
||
<!--#include file="footer.cgi" -->
|
||
</body>
|
||
</html>
|