use QUERY_STRING and show reload icon

This commit is contained in:
Synox 2018-01-09 19:41:50 +01:00
parent ff2e437138
commit bfa4070c56
3 changed files with 211 additions and 212 deletions

View File

@ -51,8 +51,6 @@ function delete_email($mailid, $address) {
if (_load_one_email($mailid, $address) !== null) { if (_load_one_email($mailid, $address) !== null) {
$mailbox->deleteMail($mailid); $mailbox->deleteMail($mailid);
$mailbox->expungeDeletedMails(); $mailbox->expungeDeletedMails();
header('Content-type: application/json');
print(json_encode(array("success" => true)));
} else { } else {
error(404, 'delete error: invalid username/mailid combination'); error(404, 'delete error: invalid username/mailid combination');
} }
@ -140,8 +138,7 @@ function redirect_to_random($domains) {
$name = $word . $nr; $name = $word . $nr;
$domain = $domains[array_rand($domains)]; $domain = $domains[array_rand($domains)];
header("location: ?$name@$domain");
header("location: ?address=$name@$domain");
} }
/** /**
@ -157,11 +154,6 @@ function delete_old_messages() {
$mailbox->expungeDeletedMails(); $mailbox->expungeDeletedMails();
} }
//
//// Never cache requests:
//header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
//header("Cache-Control: post-check=0, pre-check=0", false);
//header("Pragma: no-cache");
// run on every request // run on every request
delete_old_messages(); delete_old_messages();

BIN
src/if_sync-01_186384.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@ -1,55 +1,50 @@
<?php <?php
require_once('backend.php'); require_once('backend.php');
// simple router:
if (isset($_GET['random'])) { if (isset($_GET['username']) && isset($_GET['domain'])) {
redirect_to_random($config['domains']);
die();
} elseif (isset($_GET['username']) && isset($_GET['domain'])) {
$username = filter_input(INPUT_GET, 'username', FILTER_SANITIZE_EMAIL); $username = filter_input(INPUT_GET, 'username', FILTER_SANITIZE_EMAIL);
$domain = filter_input(INPUT_GET, 'domain', FILTER_SANITIZE_EMAIL); $domain = filter_input(INPUT_GET, 'domain', FILTER_SANITIZE_EMAIL);
header("location: ?address=$username@$domain"); header("location: ?$username@$domain");
die(); exit();
} elseif (!isset($_GET['address'])) { } elseif (isset($_GET['download_email_id'])) {
redirect_to_random($config['domains']);
} else {
// perform common validation:
$address = filter_input(INPUT_GET, 'address', FILTER_SANITIZE_EMAIL); $address = filter_input(INPUT_GET, 'address', FILTER_SANITIZE_EMAIL);
$username = _clean_username($address);
$userDomain = _clean_domain($address);
if (strlen($address) === 0) {
error(400, 'invalid username');
}
if (strlen($userDomain) === 0 || !in_array($userDomain, $config['domains'])) {
error(400, 'invalid domain');
}
// simple router:
if (isset($_GET['download_email_id'])) {
download_email($_GET['download_email_id'], $address); download_email($_GET['download_email_id'], $address);
die(); exit();
} } elseif (isset($_GET['delete_email_id'])) {
if (isset($_GET['delete_email_id'])) { $address = filter_input(INPUT_GET, 'address', FILTER_SANITIZE_EMAIL);
$delete_email_id = filter_input(INPUT_GET, 'delete_email_id', FILTER_SANITIZE_NUMBER_INT); $delete_email_id = filter_input(INPUT_GET, 'delete_email_id', FILTER_SANITIZE_NUMBER_INT);
delete_email($delete_email_id, $address); delete_email($delete_email_id, $address);
header("location: ?$address");
exit();
} elseif (isset($_GET['random'])) {
redirect_to_random($config['domains']);
exit();
} else {
// validate & print emails:
$address = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_EMAIL);
$username = _clean_username($address);
$userDomain = _clean_domain($address);
if (empty($username) || empty($userDomain)) {
redirect_to_random($config['domains']);
exit();
} }
// print emails:
$emails = get_emails($address); $emails = get_emails($address);
}
?> ?>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Mailbox <?php echo $address ?></title> <title><?php echo $address ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" type="image/x-icon" href="favicon.ico"> <link rel="icon" type="image/x-icon" href="favicon.ico">
<meta name="mobile-web-app-capable" content="yes"> <meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black"> <meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css"
integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi" crossorigin="anonymous"> integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi"
crossorigin="anonymous">
<meta charset="utf-8"> <meta charset="utf-8">
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="spinner.css"> <link rel="stylesheet" href="spinner.css">
@ -62,10 +57,13 @@ if (isset($_GET['random'])) {
var scrollPosition; var scrollPosition;
function reload() { function reload() {
scrollPosition = [window.scrollX, window.scrollY];
Turbolinks.visit(window.location.toString(), {action: 'replace'}) Turbolinks.visit(window.location.toString(), {action: 'replace'})
} }
document.addEventListener('turbolinks:before-render', function () {
scrollPosition = [window.scrollX, window.scrollY];
});
document.addEventListener('turbolinks:load', function () { document.addEventListener('turbolinks:load', function () {
if (scrollPosition) { if (scrollPosition) {
window.scrollTo.apply(window, scrollPosition); window.scrollTo.apply(window, scrollPosition);
@ -79,7 +77,7 @@ if (isset($_GET['random'])) {
setInterval(function () { setInterval(function () {
reloadWithTurbolinks(); reloadWithTurbolinks();
}, 10000) }, 15000)
</script> </script>
</head> </head>
@ -87,7 +85,7 @@ if (isset($_GET['random'])) {
<body data-turbolinks="false"> <body data-turbolinks="false">
<header> <header data-turbolinks-permanent id="header">
<div class="container"> <div class="container">
<small class="form-text text-muted"> <small class="form-text text-muted">
change username: change username:
@ -97,11 +95,11 @@ if (isset($_GET['random'])) {
<div class="form-group row"> <div class="form-group row">
<div class="col-sm-4"> <div class="col-sm-4">
<input id="username" data-turbolinks-permanent class="form-control form-control-lg" name="username" <input id="username" class="form-control form-control-lg" name="username"
value="<?php echo $username ?>"> value="<?php echo $username ?>">
</div> </div>
<div class="col-sm-3"> <div class="col-sm-3">
<select id="domain" data-turbolinks-permanent class="form-control form-control-lg" name="domain"> <select id="domain" class="form-control form-control-lg" name="domain">
<?php <?php
foreach ($config['domains'] as $domain) { foreach ($config['domains'] as $domain) {
$selected = $domain === $userDomain ? ' selected ' : ''; $selected = $domain === $userDomain ? ' selected ' : '';
@ -110,7 +108,11 @@ if (isset($_GET['random'])) {
?> ?>
</select> </select>
</div> </div>
<div class="col-sm-1">
<button type="submit" class="btn" style="background-color:transparent">
<img src="if_sync-01_186384.png" width="32" height="32" alt="submit"/>
</button>
</div>
<div class="col-sm-3 random-column"> <div class="col-sm-3 random-column">
<span>or &nbsp;</span> <span>or &nbsp;</span>
<a role="button" href="?random=true" class="btn btn-outline-primary">generate random <a role="button" href="?random=true" class="btn btn-outline-primary">generate random
@ -173,9 +175,11 @@ if (isset($_GET['random'])) {
href="?download_email_id=<?php echo filter_var($email->id, FILTER_VALIDATE_INT); ?>&amp;address=<?php echo $address ?>">Download href="?download_email_id=<?php echo filter_var($email->id, FILTER_VALIDATE_INT); ?>&amp;address=<?php echo $address ?>">Download
</a> </a>
<!-- <button class="btn btn-sm btn-outline-danger" type="button">--> <a class="btn btn-sm btn-outline-danger"
<!-- Delete--> role="button"
<!-- </button>--> href="?delete_email_id=<?php echo filter_var($email->id, FILTER_VALIDATE_INT); ?>&amp;address=<?php echo $address ?>">Delete
</a>
</form> </form>
</div> </div>
</div> </div>
@ -238,3 +242,6 @@ if (isset($_GET['random'])) {
</main> </main>
</body> </body>
</html> </html>
<?php
}
?>