mirror of
https://github.com/checktheroads/hyperglass
synced 2024-05-11 05:55:08 +00:00
converted /lg POST to jquery ajax
This commit is contained in:
Binary file not shown.
Binary file not shown.
BIN
.flask_cache/2a6f99d4936620a3f0bd95fedf526b2f
Normal file
BIN
.flask_cache/2a6f99d4936620a3f0bd95fedf526b2f
Normal file
Binary file not shown.
BIN
.flask_cache/4d39e19ce3b3acf5580716fe63ee17a6
Normal file
BIN
.flask_cache/4d39e19ce3b3acf5580716fe63ee17a6
Normal file
Binary file not shown.
Binary file not shown.
BIN
.flask_cache/7ccf01c622d424f11a8e98761770e19a
Normal file
BIN
.flask_cache/7ccf01c622d424f11a8e98761770e19a
Normal file
Binary file not shown.
BIN
.flask_cache/8e5cc37f0d5eb521574b7675b78fbb7a
Normal file
BIN
.flask_cache/8e5cc37f0d5eb521574b7675b78fbb7a
Normal file
Binary file not shown.
BIN
.flask_cache/95b12f8cd6b93bf78161ab0764ef7d66
Normal file
BIN
.flask_cache/95b12f8cd6b93bf78161ab0764ef7d66
Normal file
Binary file not shown.
BIN
.flask_cache/aabe6e7d021b7037492975340fe21c03
Normal file
BIN
.flask_cache/aabe6e7d021b7037492975340fe21c03
Normal file
Binary file not shown.
BIN
.flask_cache/bfec0932dad185d106f4b86af0f7c734
Normal file
BIN
.flask_cache/bfec0932dad185d106f4b86af0f7c734
Normal file
Binary file not shown.
BIN
.flask_cache/c59a0149864f3a0ccffa8e150c81bc43
Normal file
BIN
.flask_cache/c59a0149864f3a0ccffa8e150c81bc43
Normal file
Binary file not shown.
BIN
.flask_cache/d277c4e120e0e4b7fa8f80455a32af2e
Normal file
BIN
.flask_cache/d277c4e120e0e4b7fa8f80455a32af2e
Normal file
Binary file not shown.
BIN
.flask_cache/dd6eca7ee6b5f09a8f1821c6c4a5510b
Normal file
BIN
.flask_cache/dd6eca7ee6b5f09a8f1821c6c4a5510b
Normal file
Binary file not shown.
BIN
.flask_cache/e6ed342200608fc2907bdfc4b3dfe59d
Normal file
BIN
.flask_cache/e6ed342200608fc2907bdfc4b3dfe59d
Normal file
Binary file not shown.
Binary file not shown.
BIN
.flask_cache/f9a2505762c137a92600cf2ad6c0527d
Normal file
BIN
.flask_cache/f9a2505762c137a92600cf2ad6c0527d
Normal file
Binary file not shown.
@@ -147,8 +147,9 @@ def lg():
|
||||
except:
|
||||
raise RuntimeError("Unable to add output to cache.", 415, *value_params)
|
||||
# If 200, return output
|
||||
response = cache.get(cache_key)
|
||||
if value_code == 200:
|
||||
return Response(cache.get(cache_key))
|
||||
return Response(cache.get(cache_key), value_code)
|
||||
# If 400 error, return error message and code
|
||||
elif value_code in [405, 415]:
|
||||
return Response(cache.get(cache_key), value_code)
|
||||
@@ -156,7 +157,7 @@ def lg():
|
||||
else:
|
||||
logger.info(f"Cache match for: {cache_key}, returning cached entry...")
|
||||
try:
|
||||
return Response(cache.get(cache_key))
|
||||
return Response(cache.get(cache_key), value_code)
|
||||
except:
|
||||
id = 4152
|
||||
raise RuntimeError(
|
||||
|
@@ -4,13 +4,6 @@ var progress = ($('#progress'));
|
||||
var resultsbox = ($('#resultsbox'));
|
||||
resultsbox.hide();
|
||||
progress.hide();
|
||||
clientIP ();
|
||||
|
||||
function clientIP () {
|
||||
$.getJSON("https://jsonip.com?callback=?", function(data) {
|
||||
clientip = data.ip
|
||||
});
|
||||
};
|
||||
|
||||
$( document ).ready(function(){
|
||||
var defaultasn = $ ( "#network" ).val();
|
||||
@@ -189,58 +182,37 @@ var submitForm = function() {
|
||||
</div>
|
||||
`)
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '/lg', true);
|
||||
resultsbox.show()
|
||||
progress.show()
|
||||
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8')
|
||||
xhr.send(JSON.stringify({router: router, cmd: cmd, ipprefix: ipprefix}))
|
||||
console.log(JSON.stringify({router: router, cmd: cmd, ipprefix: ipprefix}));
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
xhr_timer = window.setInterval(function() {
|
||||
if (xhr.readyState == XMLHttpRequest.DONE) {
|
||||
progress.hide();
|
||||
window.clearTimeout(xhr_timer);
|
||||
$.ajax({
|
||||
url: `/lg`,
|
||||
type: 'POST',
|
||||
data: JSON.stringify({router: router, cmd: cmd, ipprefix: ipprefix}),
|
||||
contentType: "application/json; charset=utf-8",
|
||||
readyState: resultsbox.show() && progress.show(),
|
||||
statusCode: {
|
||||
200: function(response, code) {
|
||||
console.log(code, response);
|
||||
progress.hide();
|
||||
$('#output').html(`<br><div class="content"><p class="query-output" id="output">${response}</p></div>`);
|
||||
},
|
||||
405: function(response, code) {
|
||||
console.log(code, response);
|
||||
progress.hide();
|
||||
$('#ipprefix').addClass('is-warning');
|
||||
$('#output').html(`<br><div class="notification is-warning" id="output">${response.responseText}</div>`);
|
||||
},
|
||||
415: function(response, code) {
|
||||
console.log(code, response);
|
||||
progress.hide();
|
||||
$('#ipprefix').addClass('is-danger');
|
||||
$('#output').html(`<br><div class="notification is-danger" id="output">${response.responseText}</div>`);
|
||||
},
|
||||
429: function(response, code) {
|
||||
console.log(code, response);
|
||||
progress.hide();
|
||||
$("#ratelimit").addClass("is-active");
|
||||
}
|
||||
}
|
||||
var output = document.getElementById('output')
|
||||
if (xhr.status == 415){
|
||||
console.log(XMLHttpRequest.status, 'error')
|
||||
var output = document.getElementById('output')
|
||||
$('#ipprefix').addClass('is-danger')
|
||||
output.innerHTML =
|
||||
'<br>' +
|
||||
'<div class="notification is-danger" id="output">' +
|
||||
xhr.responseText +
|
||||
'</div>'
|
||||
}
|
||||
if (xhr.status == 405){
|
||||
console.log(XMLHttpRequest.status, 'error')
|
||||
var output = document.getElementById('output')
|
||||
$('#ipprefix').addClass('is-warning')
|
||||
output.innerHTML =
|
||||
'<br>' +
|
||||
'<div class="notification is-warning" id="output">' +
|
||||
xhr.responseText +
|
||||
'</div>'
|
||||
}
|
||||
else if (xhr.status == 200){
|
||||
console.log(xhr.status, 'success')
|
||||
var output = document.getElementById('output')
|
||||
output.innerHTML =
|
||||
'<br>' +
|
||||
'<div class="content">' +
|
||||
'<p class="query-output" id="output">' +
|
||||
xhr.responseText +
|
||||
'</p>' +
|
||||
'</div>'
|
||||
}
|
||||
else if (xhr.status == 429){
|
||||
console.log(xhr.status, 'rate limit reached');
|
||||
$("#ratelimit").addClass("is-active");
|
||||
}
|
||||
}, 500);
|
||||
|
||||
xhr.addEventListener("error", function(e) {
|
||||
console.log("error: " + e);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user