Files
databunker/ui/index.html
2020-08-16 22:18:41 +00:00

281 lines
13 KiB
HTML

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Data Bunker Login</title>
<script src="site/site.js"></script>
<link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="site/style.css">
<script>
conf = loadUIConfiguration();
if (conf["custom_css_link"]) {
document.write("<link rel='stylesheet' type='text/css' href='" + conf["custom_css_link"] +"' />");
}
</script>
</head>
<body>
<div class="container col-md-6 pY-100">
<script>
conf = loadUIConfiguration();
if (conf["LogoLink"]) {
document.write("<center><div class='col-6'><img class='logo img-responsive' src='"+conf["LogoLink"]+"'></div></center>" );
}
</script>
<div class="row">
<div class="bigblock">
<h4>Find my data</h4>
<p>Select login method and enter login details:</p>
<form id="loginform">
<div class="form-group">
<select onchange="changemethod(this);" class="custom-select" required id="keymethod">
<option value="Admin">Admin Token</option>
<option value="Record">Record Token</option>
<option selected value="Email">Email</option>
<option value="Phone">Phone</option>
</select>
</div>
<div class="form-group" id="email-conf-form" style="display:none;">
<p>We might send your email using 3rd party service. Check the <b>Privacy policy</b> bellow.</p>
<div class="form-check">
<input type="checkbox" class="form-check-input" onclick="hidealert();" id="emailchk">
<label class="form-check-label" for="emailchk">Confirm to allow sending access code using 3rd party service.</label>
</div>
</div>
<div class="form-group" id="sms-conf-form" style="display:none;">
<p>We might send you SMS using 3rd party service. Check the <b>Privacy policy</b> bellow.</p>
<div class="form-check">
<input type="checkbox" class="form-check-input" onclick="hidealert();" id="smschk">
<label class="form-check-label" for="smschk">Confirm to allow sending access code using 3rd party service.</label>
</div>
</div>
<div id="confalert" class="alert alert-warning" role="alert" style="display:none;">
We can not send you access code!
</div>
<div id="badformat" class="alert alert-warning" role="alert" style="display:none;">
Bad input value!
</div>
<div id="notfound" class="alert alert-warning" role="alert" style="display:none;">
User not found
</div>
<div class="form-group">
<input id="loginvalue" type="login" autocomplete="off" class="form-control" onclick="hidebadformat();"
placeholder="Enter token...">
</div>
<div class="form-group">
<div class="peers ai-c jc-sb fxw-nw">
<div class="peer"><button onclick="return submitbtn();"
class="btn btn-primary">Login</button></div>
</div>
</div>
</form>
<div id="loading" style="display:none;">
<center><img src="/site/loading.gif" /></center>
</div>
</div>
</div>
<script>displayFooterLinks();</script>
</div>
<script>
var lookupTimer;
var lookupCount;
function lookupUser(url) {
if (lookupCount > 0) {
// try to login with user again
var xhr10 = new XMLHttpRequest();
xhr10.open('GET', url);
xhr10.onload = function () {
if (xhr10.status === 200) {
document.location = "/site/login.html";
}
}
xhr10.send();
lookupCount = lookupCount - 1;
} else {
clearTimeout(lookupTimer);
var loading = document.getElementById('loading');
loading.style.display = "none";
var notfound = document.getElementById('notfound');
notfound.style.display = "block";
}
}
function isUUID(uuid) {
let s = "" + uuid;
s = s.match('^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$');
if (s === null) {
return false;
}
return true;
}
function hidealert() {
var confalert = document.getElementById('confalert');
confalert.style.display = "none";
var badformat = document.getElementById('badformat');
badformat.style.display = "none";
}
function hidebadformat() {
var badformat = document.getElementById('badformat');
var notfound = document.getElementById('notfound');
badformat.style.display = "none";
notfound.style.display = "none";
}
function changemethod(obj) {
var value = obj.value;
if (!value) {
return false;
}
changemethoddo(value);
}
function changemethoddo(value) {
var element = document.getElementById('loginvalue');
var smsform = document.getElementById('sms-conf-form');
var emailform = document.getElementById('email-conf-form');
var smschk = document.getElementById('smschk');
var emailchk = document.getElementById('emailchk');
var confalert = document.getElementById('confalert');
var badformat = document.getElementById('badformat');
var loading = document.getElementById('loading');
var notfound = document.getElementById('notfound');
if (!element || !smsform || !emailform ||
!smschk || !emailchk || !confalert ||
!badformat || !loading) {
return false;
}
badformat.style.display = "none";
notfound.style.display = "none";
smschk.checked = false;
emailchk.checked = false;
value = value.toLowerCase();
valueDisplay = value;
if (valueDisplay === "admin") {
valueDisplay = "admin token";
}
var key = element.placeholder = "Enter " + valueDisplay + "...";
confalert.style.display = "none";
if (value == "email") {
smsform.style.display = "none";
emailform.style.display = "block";
} else if (value == "phone") {
smsform.style.display = "block";
emailform.style.display = "none";
} else {
smsform.style.display = "none";
emailform.style.display = "none";
}
}
function submitbtn() {
var element = document.getElementById('loginvalue')
var smschk = document.getElementById('smschk');
var emailchk = document.getElementById('emailchk');
var confalert = document.getElementById('confalert');
var keymethod = document.getElementById('keymethod');
var badformat = document.getElementById('badformat');
if (!element || !smschk || !emailchk || !confalert || !keymethod) {
return false;
}
var key = element.value;
if (!key) {
return false;
}
var kkk = keymethod.options[keymethod.selectedIndex].value;
if ((kkk == "Email" && emailchk.checked == false) ||
(kkk == "Phone" && smschk.checked == false)) {
confalert.style.display = "block";
return false;
}
if (kkk == "Record" && isUUID(key) == true) {
var xhr = new XMLHttpRequest();
xhr.open('GET', "/v1/get/" + key);
xhr.onload = function () {
if (xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
if (data && data.status && data.status == "ok") {
window.localStorage.setItem('record', key);
window.localStorage.setItem('type', data.type);
if (data.data) {
document.location = "/site/display-data.html";
} else {
document.location = "/site/admin-events.html";
}
}
}
};
xhr.send();
} else if (kkk == "Admin" && (key == "DEMO" || isUUID(key) == true)) {
var xhr = new XMLHttpRequest();
xhr.open('GET', "/v1/userapps");
xhr.setRequestHeader("X-Bunker-Token", key)
xhr.setRequestHeader("Content-type", "application/json");
xhr.onload = function () {
if (xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
if (data && data.status && data.status == "ok") {
window.localStorage.setItem('xtoken', key);
window.localStorage.setItem('type', data.type);
document.location = "/site/admin-view-requests.html";
}
}
};
xhr.send();
} else if (kkk == "Email" && key.indexOf('@') > 0) {
window.localStorage.setItem('login', key);
var xhr0 = new XMLHttpRequest();
xhr0.open('POST', "/v1/agreement/send-email-on-login/email/" + encodeURI(key) + "");
xhr0.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr0.onload = function () {
if (xhr0.status === 200) {
var xhr = new XMLHttpRequest();
var url = "/v1/prelogin/email/" + encodeURI(key)
xhr.open('GET', url);
xhr.onload = function () {
if (xhr.status === 200) {
document.location = "/site/login.html";
} else /* if (conf["MagicLookup"]) */ {
//error
var loading = document.getElementById('loading');
loading.style.display = "block";
lookupCount = 5;
lookupTimer = setInterval(lookupUser, 2500, url);
}
}
xhr.send();
}
}
xhr0.send();
} else if (kkk == "Phone") {
window.localStorage.setItem('login', key);
var xhr0 = new XMLHttpRequest();
xhr0.open('POST', "/v1/agreement/send-sms-on-login/phone/" + encodeURI(key) + "");
xhr0.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr0.onload = function () {
if (xhr0.status === 200) {
var xhr = new XMLHttpRequest();
xhr.open('GET', "/v1/prelogin/phone/" + encodeURI(key));
xhr.onload = function () {
if (xhr.status === 200) {
document.location = "/site/login.html";
}
}
xhr.send();
}
}
xhr0.send();
} else {
badformat.style.display = "block";
}
return false;
}
(function() {
changemethoddo('Email');
})();
</script>
</body>