[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> <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;}
@ -47,60 +48,76 @@ config_waf_captcha_html=[[
</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>
<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> <p data-sw-translate>To continue accessing the webpage, please enter the characters shown below:</p>
<div class="form"> <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>
</div> </div>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<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 // hash
$.post(url).then((res) => { getImg()
const {errno, errmsg, data} = JSON.parse(res) function getImg() {
if (errno) { $.get(url).then((res) => {
return alert(errmsg) $('#captcha-img').attr('src', urlimg + '/' + res.data.image_url)
} $('#captcha-id').val(res.data.captcha_id)
})
// }
document.querySelector('#captcha-img').src = `${url}/${data}` $('#captcha-img').on('click',function(e) {
getImg()
// })
document.querySelector('#captcha-submit').addEventListener('click', e => { $('#captcha-submit').on('click', function(e) {
$.post(`${url}/check`, { var data = {
key: data, captcha_id: $('#captcha-id').val(),
code: document.querySelector('#captcha-input').value, captcha_code: document.querySelector('#captcha-input').value,
}).then(res => {
const {errno, errmsg, data} = JSON.parse(res)
if (errno) {
return location.reload()
} }
$.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') var targetUrl = new URLSearchParams(location.search).get('continue')
targetUrl = atob(targetUrl) //targetUrl = atob(targetUrl)
location.href = targetUrl //location.href = targetUrl
}) },
}) error: function(e) {
location.reload()
}
}) })
})
window.SwaggerTranslator = { window.SwaggerTranslator = {
_words: [], _words: [],
translate: function () { translate: function() {
var $this = this; var $this = this;
$('[data-sw-translate]').each(function () { $('[data-sw-translate]').each(function() {
$(this).html($this._tryTranslate($(this).html())); $(this).html($this._tryTranslate($(this).html()));
$(this).val($this._tryTranslate($(this).val())); $(this).val($this._tryTranslate($(this).val()));
$(this).attr('title', $this._tryTranslate($(this).attr('title'))); $(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;
} }
}; };
@ -113,7 +130,7 @@ config_waf_captcha_html=[[
"Submit": "提交", "Submit": "提交",
}); });
$(function () { $(function() {
window.SwaggerTranslator.translate(); window.SwaggerTranslator.translate();
}); });
</script> </script>