[fix] Update captcha api

pull/4/head
lj2007331@gmail.com 2019-11-16 23:03:44 +08:00
parent 4f5382bb7c
commit 33c1476ecf
1 changed files with 88 additions and 71 deletions

View File

@ -35,7 +35,8 @@ config_waf_captcha_html=[[
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title data-sw-translate>Please enter verification code - OneinStack WAF</title>
<style> body { font-family: Tahoma, Verdana, Arial, sans-serif; }
<style>
body { font-family: Tahoma, Verdana, Arial, sans-serif; }
.head_title{margin-top:100px; font-family:"微软雅黑"; font-size:50px; font-weight:lighter;}
p{font-family:"微软雅黑"; font-size:16px; font-weight:lighter; color:#666666;}
.btn{ float:left;margin-left:15px; margin-top:5px; width:85px; height:30px; background:#56c458;font-family:"微软雅黑"; font-size:16px; color:#FFFFFF; border:0;}
@ -47,60 +48,76 @@ config_waf_captcha_html=[[
</head>
<body>
<div align="center">
<p><h1 class="head_title" data-sw-translate>Sorry...</h1></p>
<p data-sw-translate>Your query looks similar to an automated request from computer software. In order to protect our users, please forgive us for temporarily not processing your request.</p>
<p>
<h1 class="head_title" data-sw-translate>Sorry...</h1>
</p>
<p data-sw-translate>Your query looks similar to an automated request from computer software. In order to protect
our users, please forgive us for temporarily not processing your request.</p>
<p data-sw-translate>To continue accessing the webpage, please enter the characters shown below:</p>
<div class="form">
<img id="captcha-img" class="yz" src="https://oneinstack.com/restapi/v1/captchas/038fb48d9f8170e9a7c67aee79106a31" alt="Captcha image"><input id="captcha-input" class="inp_s" type="text" name="response" /><input id="captcha-submit" class="btn" type="submit" data-sw-translate value="Submit" />
<img id="captcha-img" class="yz" src="https://oneinstack.com/api/v1/captcha/BrqDr57p3mjj0xAuEQEW.png" alt="Captcha image">
<input id="captcha-input" class="inp_s" type="text" name="response" />
<input id="captcha-id" class="inp_s" type="hidden" name="response" />
<input id="captcha-submit" class="btn" type="submit"
data-sw-translate value="Submit" />
</div>
</div>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script>
var url = 'https://oneinstack.com/restapi/v1/captchas'
let captcha_id = ''
var url = 'https://oneinstack.com/api/v1/captcha'
var urlimg = 'https://oneinstack.com/api/v1/'
// hash
$.post(url).then((res) => {
const {errno, errmsg, data} = JSON.parse(res)
if (errno) {
return alert(errmsg)
}
//
document.querySelector('#captcha-img').src = `${url}/${data}`
//
document.querySelector('#captcha-submit').addEventListener('click', e => {
$.post(`${url}/check`, {
key: data,
code: document.querySelector('#captcha-input').value,
}).then(res => {
const {errno, errmsg, data} = JSON.parse(res)
if (errno) {
return location.reload()
getImg()
function getImg() {
$.get(url).then((res) => {
$('#captcha-img').attr('src', urlimg + '/' + res.data.image_url)
$('#captcha-id').val(res.data.captcha_id)
})
}
$('#captcha-img').on('click',function(e) {
getImg()
})
$('#captcha-submit').on('click', function(e) {
var data = {
captcha_id: $('#captcha-id').val(),
captcha_code: document.querySelector('#captcha-input').value,
}
$.ajax({
url: `${url}/verify`,
type: 'post',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify(data),
cache: false,
success: function(res){
var targetUrl = new URLSearchParams(location.search).get('continue')
targetUrl = atob(targetUrl)
location.href = targetUrl
})
})
//targetUrl = atob(targetUrl)
//location.href = targetUrl
},
error: function(e) {
location.reload()
}
})
})
window.SwaggerTranslator = {
_words: [],
translate: function () {
translate: function() {
var $this = this;
$('[data-sw-translate]').each(function () {
$('[data-sw-translate]').each(function() {
$(this).html($this._tryTranslate($(this).html()));
$(this).val($this._tryTranslate($(this).val()));
$(this).attr('title', $this._tryTranslate($(this).attr('title')));
});
},
_tryTranslate: function (word) {
_tryTranslate: function(word) {
return this._words[$.trim(word)] !== undefined ? this._words[$.trim(word)] : word;
},
learn: function (wordsMap) {
learn: function(wordsMap) {
this._words = wordsMap;
}
};
@ -113,7 +130,7 @@ config_waf_captcha_html=[[
"Submit": "提交",
});
$(function () {
$(function() {
window.SwaggerTranslator.translate();
});
</script>