-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
190 lines (171 loc) · 9.68 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<!DOCTYPE html>
<html lang="en">
<head>
<!-- META -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test your OTP Application, with OTPTest.de!</title>
<meta name="description" content="This site is for everyone who wants to quickly test an OTP, like TOTP. I build it for myself while testing OTP Applications.">
<meta name="keywords" content="otp,test,totp,otptest,totptest,security,login,2fa,qrcode">
<meta name="robots" content="index, follow">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="language" content="English">
<meta name="author" content="Phil Roggenbuck (phrogg)">
<!-- Thanks to heymeta.com -->
<!-- Google / Search Engine Tags -->
<meta itemprop="name" content="Test your OTP Application, with OTPTest.de!">
<meta itemprop="description" content="This site is for everyone who wants to quickly test an OTP, like TOTP. I build it for myself while testing OTP Applications.">
<meta itemprop="image" content="https://otptest.de/prev.png">
<!-- Facebook Meta Tags -->
<meta property="og:url" content="https://otptest.de">
<meta property="og:type" content="website">
<meta property="og:title" content="Test your OTP Application, with OTPTest.de!">
<meta property="og:description" content="This site is for everyone who wants to quickly test an OTP, like TOTP. I build it for myself while testing OTP Applications.">
<meta property="og:image" content="https://otptest.de/prev.png">
<!-- Twitter Meta Tags -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Test your OTP Application, with OTPTest.de!">
<meta name="twitter:description" content="This site is for everyone who wants to quickly test an OTP, like TOTP. I build it for myself while testing OTP Applications.">
<meta name="twitter:image" content="https://otptest.de/prev.png">
<!-- Meta Tags Generated via http://heymeta.com -->
<!-- /META -->
<link href="https://unpkg.com/primer/build/build.css" rel="stylesheet">
<link rel="icon" href="favicon.ico" type="image/gif" sizes="256x256">
<style>
html,
body {
padding-top: 10px;
text-align: center;
align: center;
}
input[type=text],
input[type=submit] {
border-radius: 4px;
text-align: center;
}
</style>
<script>
// pre code block
// Remove the cookie with the oldSecret
function del_cookie() { //src: https://stackoverflow.com/a/57644049/5638397
document.cookie = 'secret=; Max-Age=0; path=/; domain=' + location.host;
window.location = window.location.href.split("?")[0]; // when changing the secret, don't check the last otp
setTimeout(new function() {
location.reload()
}, 3000);
}
// Copy OTP and Secret to Clipboard
function copy2Clip(objectId) {
var copyText = document.getElementById(objectId);
copyText.select();
copyText.setSelectionRange(0, 99999);
document.execCommand("copy");
}
// progressbar update
function prgUpdate() {
var element = document.getElementById("prgBar");
var width = 1;
var identity = setInterval(scene, 1000);
function scene() {
if (width >= 30) {
location.reload();
clearInterval(identity);
} else {
width++;
element.value = width;
}
}
}
</script>
</head>
<?php
$emojiSize = 15;
require_once('vendor/autoload.php');
use OTPHP\TOTP;
use chillerlan\QRCode\QRCode;
$otp = TOTP::create();
$oldSecret = false;
if (!isset($_COOKIE["secret"])) {
$secret = substr($otp->getSecret(), 96);
//$secret = $otp->getSecret();
} else {
$secret = $_COOKIE["secret"];
$oldSecret = true;
}
$otp = TOTP::create($secret);
setcookie("secret", $secret, time() + (86400 * 30), "/");
$otp->setLabel('OTPTest.de');
?>
<body>
<h1>OTPTest.de</h1>
<div class="Box Box--spacious col-6 mx-auto text-center" style="margin-top: 20px;">
<div class="Box-body" style="padding-top: 0px;">
<!-- <progress id="prgBar" value="0" max="30" style="width: 30%;">Test</progress> TODO: Fix time -->
<h3 class="f1-light">
<font size=4>Token:</font><br>
<input type="text" value="<?php echo $otp->now(); ?>" id="clip1" size=3 style="outline: none; border: none; width:auto;"><button type="button" onclick="copy2Clip('clip1');" class="text-gray right-0 top-0 m-2 js-zeroclipboard btn btn-sm zeroclipboard-button tooltipped tooltipped-s" aria-label="Copy" data-copied-hint="Copied!">
<svg class="octicon octicon-clippy js-icon" viewBox="0 0 14 16" version="1.1" width="14" height="16" aria-hidden="true">
<path fill-rule="evenodd" d="M2 13h4v1H2v-1zm5-6H2v1h5V7zm2 3V8l-3 3 3 3v-2h5v-2H9zM4.5 9H2v1h2.5V9zM2 12h2.5v-1H2v1zm9 1h1v2c-.02.28-.11.52-.3.7-.19.18-.42.28-.7.3H1c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h3c0-1.11.89-2 2-2 1.11 0 2 .89 2 2h3c.55 0 1 .45 1 1v5h-1V6H1v9h10v-2zM2 5h8c0-.55-.45-1-1-1H8c-.55 0-1-.45-1-1s-.45-1-1-1-1 .45-1 1-.45 1-1 1H3c-.55 0-1 .45-1 1z"></path>
</svg>
</button>
</h3>
<dl class="form-group mb-4">
<?php
echo "<dt><label>" . '<img src="' . (new QRCode)->render($otp->getProvisioningUri()) . '" alt="QR Code" /><br>' . "</label></dt>";
?>
<dt><label>
<font size=2>Secret:</font><br>
<input type="text" value="<?php echo $otp->getSecret(); ?>" id="clip2" size=6 style="outline: none; border: none; width:auto;"><button type="button" onclick="copy2Clip('clip2');" class="text-gray right-0 top-0 m-2 js-zeroclipboard btn btn-sm zeroclipboard-button tooltipped tooltipped-s" aria-label="Copy" data-copied-hint="Copied!">
<svg class="octicon octicon-clippy js-icon" viewBox="0 0 14 16" version="1.1" width="14" height="16" aria-hidden="true">
<path fill-rule="evenodd" d="M2 13h4v1H2v-1zm5-6H2v1h5V7zm2 3V8l-3 3 3 3v-2h5v-2H9zM4.5 9H2v1h2.5V9zM2 12h2.5v-1H2v1zm9 1h1v2c-.02.28-.11.52-.3.7-.19.18-.42.28-.7.3H1c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h3c0-1.11.89-2 2-2 1.11 0 2 .89 2 2h3c.55 0 1 .45 1 1v5h-1V6H1v9h10v-2zM2 5h8c0-.55-.45-1-1-1H8c-.55 0-1-.45-1-1s-.45-1-1-1-1 .45-1 1-.45 1-1 1H3c-.55 0-1 .45-1 1z"></path>
</svg>
</button>
</label></dt>
</dl>
<?php if ($oldSecret) { ?>
<button class="btn btn-primary btn-block" onclick='del_cookie()'>
Create new Secret
</button>
<?php } ?>
For your convenience we created a cookie that lasts one day.
</div>
<div class="Box-body" style="padding-top: 10px;">
<!-- <h3 class="f1-light">Verify a token</h3> -->
<form action="" method="GET">
<input type="text" minlength="6" maxlength="6" id="otp" size="5" name="otp" placeholder="<?php echo $_GET['otp']; ?>" required />
<input type="submit" value="Verify Token" />
</form>
<?php
if (isset($_GET['otp'])) {
if ($otp->verify($_GET['otp']) == 1) {
?>
<script>
document.getElementById("otp").style.border = "2px solid green"
</script>
<h2 style='color: green;'>This token is valid!</h2>
<?php
} else {
?>
<script>
document.getElementById("otp").style.border = "2px solid red"
</script>
<h2 style='color: red;'>This token is invalid!</h2>
<?php
}
}
?>
</div>
<div class="Box-body" style="padding-bottom: 5px;padding-top: 5px;">
<img src="https://img.shields.io/github/release/phrogg/OTPTest.de.svg?logo=github" />
<img src="https://img.shields.io/github/license/phrogg/OTPTest.de.svg" />
<img src="https://img.shields.io/github/issues/phrogg/OTPTest.de.svg" />
<br>Based on:<br>
<a href="https://github.com/chillerlan/php-qrcode" target="_BLANK"><img src="https://img.shields.io/badge/chillerlan-QRCode-blue.svg" /></a>
<a href="https://github.com/Spomky-Labs/otphp/" target="_BLANK"><img src="https://img.shields.io/badge/SpomkyLabs-otphp-orange.svg" /></a><br>
<a href="https://www.iconfinder.com/icons/1930259/green_hole_key_keyhole_icon" target="_BLANK"><img src="https://img.shields.io/badge/Keyhole-favicon-green.svg" /></a>
</div>
</div>
<div style="margin-top: 5px;"><img class="emoji" alt="wrench" height="<?php echo $emojiSize; ?>" width="<?php echo $emojiSize; ?>" src="https://github.githubassets.com/images/icons/emoji/unicode/1f527.png"> with <img class="emoji" alt="heart" height="<?php echo $emojiSize; ?>" width="<?php echo $emojiSize; ?>" src="https://github.githubassets.com/images/icons/emoji/unicode/2764.png"> in <img class="emoji" alt="de" height="<?php echo $emojiSize; ?>" width="<?php echo $emojiSize; ?>" src="https://github.githubassets.com/images/icons/emoji/unicode/1f1e9-1f1ea.png"></div>
<br><a href="https://paypal.me/proggenbuck" target="_BLANK"><img src="https://img.shields.io/badge/Donate-Here-green.svg" /></a>
</body>
</html>