Beginning of malware warning

This commit is contained in:
2019-03-27 23:57:53 +01:00
parent bd8ebcddf1
commit 16d3bb118f
6 changed files with 71 additions and 5 deletions

View File

@@ -30,7 +30,45 @@ var Toolbar = {
}
},
download: function () {
document.getElementById("download_frame").src = "/api/file/" + Viewer.currentFile + "?download";
var triggerDL = function(){
document.getElementById("download_frame").src = "/api/file/" + Viewer.currentFile + "?download";
}
if (captchaKey === "a"){
// If the server doesn't support captcha there's no use in checking
// availability
triggerDL();
return;
}
$.getJSON(
apiEndpoint + "/file/" + Viewer.currentFile + "/availability"
).done(function(data){
if(data.success === true){
// Downloading is allowed, start the download
triggerDL();
}
}).fail(function(data){
console.log(data);
if(data.responseJSON.success === false) {
var popupDiv = document.getElementById("captcha_popup");
if(data.responseJSON.value === "file_rate_limited_captcha_required") {
popupDiv.innerHTML = '<div class="highlight_light border_top border_bottom">Rate limiting enabled!</div>'+
data.responseJSON.message;
}else if(data.responseJSON.value === "virus_detected_captcha_required"){
popupDiv.innerHTML = '<div class="highlight_light border_top border_bottom">Malware warning!</div>'+
data.responseJSON.message+
"<hr/>Malware type: " + data.responseJSON.extra;
}
popupDiv.style.opacity = "1";
popupDiv.style.visibility = "visible";
}else{
// No JSON, try download anyway
triggerDL();
}
});
},
downloadList: function(){
if(!Viewer.isList){

View File

@@ -208,6 +208,24 @@ body{
box-shadow: var(--shadow_color) 0px 0px 50px;
z-index: 100;
}
.captcha_popup{
position: fixed;
visibility: hidden;
opacity: 0;
transition: visibility 1s, opacity 1s, left 1s;
background-color: var(--background_color);
height: auto;
width: 500px;
max-width: 100%;
top: 50px;
left: 50%;
margin-left: -200px;
padding: 0 10px;
box-sizing: border-box;
text-align: left;
box-shadow: var(--shadow_color) 0px 0px 50px;
z-index: 100;
}
table {width: auto !important;}
table > tbody > tr {border: none !important;}

View File

@@ -29,7 +29,10 @@
<meta property="article:author" content="Fornax96" />
<link rel="image_src" href="{{.OGData.Image}}" />
<script type="text/javascript">var apiEndpoint = '{{.APIEndpoint}}';</script>
<script type="text/javascript">
var apiEndpoint = '{{.APIEndpoint}}';
var captchaKey = '{{.Other.CaptchaKey}}';
</script>
</head>
<body>
@@ -163,6 +166,7 @@
<br/>
</span>
</div>
<div id="captcha_popup" class="captcha_popup"></div>
<div id="filepreview">
<img src="/res/img/misc/loadthink.gif" style="margin-top: 20%; width: 200px; height: 200px;" />