[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

@ -32,10 +32,11 @@ config_waf_output = "html"
config_waf_redirect_url = "/captcha" config_waf_redirect_url = "/captcha"
config_waf_captcha_html=[[ config_waf_captcha_html=[[
<html> <html>
<head> <head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title data-sw-translate>Please enter verification code - OneinStack WAF</title> <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;} .head_title{margin-top:100px; font-family:"微软雅黑"; font-size:50px; font-weight:lighter;}
p{font-family:"微软雅黑"; font-size:16px; font-weight:lighter; color:#666666;} 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;} .btn{ float:left;margin-left:15px; margin-top:5px; width:85px; height:30px; background:#56c458;font-family:"微软雅黑"; font-size:16px; color:#FFFFFF; border:0;}
@ -44,80 +45,96 @@ config_waf_captcha_html=[[
.fors{ margin:0 auto;width:500px; height:40px;} .fors{ margin:0 auto;width:500px; height:40px;}
.form {width: 500px; margin: 2em auto;} .form {width: 500px; margin: 2em auto;}
</style> </style>
</head> </head>
<body> <body>
<div align="center"> <div align="center">
<p><h1 class="head_title" data-sw-translate>Sorry...</h1></p> <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> <h1 class="head_title" data-sw-translate>Sorry...</h1>
<p data-sw-translate>To continue accessing the webpage, please enter the characters shown below:</p> </p>
<div class="form"> <p data-sw-translate>Your query looks similar to an automated request from computer software. In order to protect
<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" /> our users, please forgive us for temporarily not processing your request.</p>
</div> <p data-sw-translate>To continue accessing the webpage, please enter the characters shown below:</p>
</div> <div class="form">
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> <img id="captcha-img" class="yz" src="https://oneinstack.com/api/v1/captcha/BrqDr57p3mjj0xAuEQEW.png" alt="Captcha image">
<script> <input id="captcha-input" class="inp_s" type="text" name="response" />
var url = 'https://oneinstack.com/restapi/v1/captchas' <input id="captcha-id" class="inp_s" type="hidden" name="response" />
// hash <input id="captcha-submit" class="btn" type="submit"
$.post(url).then((res) => { data-sw-translate value="Submit" />
const {errno, errmsg, data} = JSON.parse(res) </div>
if (errno) { </div>
return alert(errmsg) <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
} <script>
let captcha_id = ''
var url = 'https://oneinstack.com/api/v1/captcha'
var urlimg = 'https://oneinstack.com/api/v1/'
// hash
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({
document.querySelector('#captcha-img').src = `${url}/${data}` url: `${url}/verify`,
type: 'post',
// dataType: 'json',
document.querySelector('#captcha-submit').addEventListener('click', e => { contentType: 'application/json',
$.post(`${url}/check`, { data: JSON.stringify(data),
key: data, cache: false,
code: document.querySelector('#captcha-input').value, success: function(res){
}).then(res => { var targetUrl = new URLSearchParams(location.search).get('continue')
const {errno, errmsg, data} = JSON.parse(res) //targetUrl = atob(targetUrl)
if (errno) { //location.href = targetUrl
return location.reload() },
} error: function(e) {
location.reload()
var targetUrl = new URLSearchParams(location.search).get('continue') }
targetUrl = atob(targetUrl)
location.href = targetUrl
})
}) })
})
window.SwaggerTranslator = { })
_words: [], window.SwaggerTranslator = {
translate: function () { _words: [],
var $this = this; translate: function() {
$('[data-sw-translate]').each(function () { var $this = this;
$(this).html($this._tryTranslate($(this).html())); $('[data-sw-translate]').each(function() {
$(this).val($this._tryTranslate($(this).val())); $(this).html($this._tryTranslate($(this).html()));
$(this).attr('title', $this._tryTranslate($(this).attr('title'))); $(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; return this._words[$.trim(word)] !== undefined ? this._words[$.trim(word)] : word;
}, },
learn: function (wordsMap) { learn: function(wordsMap) {
this._words = wordsMap; this._words = wordsMap;
} }
}; };
window.SwaggerTranslator.learn({ window.SwaggerTranslator.learn({
"Please enter verification code - OneinStack WAF": "输入验证码 - OneinStack防火墙", "Please enter verification code - OneinStack WAF": "输入验证码 - OneinStack防火墙",
"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.": "您的查询看起来类似于来自计算机软件的自动请求。为了保护我们的用户,请原谅我们现在暂时不能处理您的请求。", "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.": "您的查询看起来类似于来自计算机软件的自动请求。为了保护我们的用户,请原谅我们现在暂时不能处理您的请求。",
"To continue accessing the webpage, please enter the characters shown below:": "要继续访问网页,请输入下面所示字符:", "To continue accessing the webpage, please enter the characters shown below:": "要继续访问网页,请输入下面所示字符:",
"Sorry...": "很抱歉...", "Sorry...": "很抱歉...",
"Submit": "提交", "Submit": "提交",
}); });
$(function () { $(function() {
window.SwaggerTranslator.translate(); window.SwaggerTranslator.translate();
}); });
</script> </script>
</body> </body>
</html> </html>
]] ]]
config_output_html=[[ config_output_html=[[