Skip to content

Commit

Permalink
new blocked IP html error template
Browse files Browse the repository at this point in the history
  • Loading branch information
sebadob committed Oct 25, 2023
1 parent 11270d9 commit 98e5f1a
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
13 changes: 13 additions & 0 deletions rauthy-models/src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,19 @@ impl PwdResetHtml<'_> {
}
}

#[derive(Default, Template)]
#[template(path = "error/429.html")]
pub struct TooManyRequestsHtml<'a> {
pub ip: &'a str,
pub exp: i64,
}

impl TooManyRequestsHtml<'_> {
pub fn build(ip: &str, exp: i64) -> String {
TooManyRequestsHtml { ip, exp }.render().unwrap()
}
}

#[derive(Default, Template)]
#[template(path = "html/users/{id}/email_confirm/email_confirm.html")]
pub struct UserEmailChangeConfirmHtml<'a> {
Expand Down
54 changes: 54 additions & 0 deletions templates/error/429.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Roboto', 'Segoe UI', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
color: #383838;
}
h1 { font-size: 1.3rem; }
h2 { font-size: 1.25rem; }
</style>
<title>IP Blocked</title>
</head>
<body>
<h1>Too Many Requests</h1>
<h2>Your IP {{ ip }} has been blocked until <span id="exp"></span></h2>
<p>This incident has been reported</p>
<script>
let exp = {{ exp }};
const offset = -new Date().getTimezoneOffset();
const d = new Date((exp + offset * 60) * 1000);

let dd = d.getUTCDate();
if (dd < 10) {
dd = '0' + dd;
}
let mm = d.getUTCMonth() + 1;
if (mm < 10) {
mm = '0' + mm;
}
const yyyy = d.getUTCFullYear();

let hr = d.getUTCHours();
if (hr < 10) {
hr = '0' + hr;
}
let mn = d.getUTCMinutes();
if (mn < 10) {
mn = '0' + mn;
}
let sc = d.getUTCSeconds();
if (sc < 10) {
sc = '0' + sc;
}

const ts = `${yyyy}/${mm}/${dd} ${hr}:${mn}:${sc}`;
const el = document.getElementById('exp');
el.innerText = ts;
</script>
</body>
</html>

0 comments on commit 98e5f1a

Please sign in to comment.