diff --git a/.flask_cache/77c5444ceabaa72e7f3ca61c79d8a07b b/.flask_cache/1842a0ff0c5b4bdbdca506a3489cceed similarity index 96% rename from .flask_cache/77c5444ceabaa72e7f3ca61c79d8a07b rename to .flask_cache/1842a0ff0c5b4bdbdca506a3489cceed index 29ac769..e1078ec 100644 Binary files a/.flask_cache/77c5444ceabaa72e7f3ca61c79d8a07b and b/.flask_cache/1842a0ff0c5b4bdbdca506a3489cceed differ diff --git a/.flask_cache/2029240f6d1128be89ddc32729463129 b/.flask_cache/2029240f6d1128be89ddc32729463129 index 8bd88e5..61c5ec0 100644 Binary files a/.flask_cache/2029240f6d1128be89ddc32729463129 and b/.flask_cache/2029240f6d1128be89ddc32729463129 differ diff --git a/.flask_cache/2a6f99d4936620a3f0bd95fedf526b2f b/.flask_cache/2a6f99d4936620a3f0bd95fedf526b2f new file mode 100644 index 0000000..ccb499d Binary files /dev/null and b/.flask_cache/2a6f99d4936620a3f0bd95fedf526b2f differ diff --git a/.flask_cache/4d39e19ce3b3acf5580716fe63ee17a6 b/.flask_cache/4d39e19ce3b3acf5580716fe63ee17a6 new file mode 100644 index 0000000..912d89a Binary files /dev/null and b/.flask_cache/4d39e19ce3b3acf5580716fe63ee17a6 differ diff --git a/.flask_cache/74bc75c0764cbc805c70645cef1f026b b/.flask_cache/74bc75c0764cbc805c70645cef1f026b index 1c2abdd..e58b6a8 100644 Binary files a/.flask_cache/74bc75c0764cbc805c70645cef1f026b and b/.flask_cache/74bc75c0764cbc805c70645cef1f026b differ diff --git a/.flask_cache/7ccf01c622d424f11a8e98761770e19a b/.flask_cache/7ccf01c622d424f11a8e98761770e19a new file mode 100644 index 0000000..b3b7d35 Binary files /dev/null and b/.flask_cache/7ccf01c622d424f11a8e98761770e19a differ diff --git a/.flask_cache/8e5cc37f0d5eb521574b7675b78fbb7a b/.flask_cache/8e5cc37f0d5eb521574b7675b78fbb7a new file mode 100644 index 0000000..807e1c1 Binary files /dev/null and b/.flask_cache/8e5cc37f0d5eb521574b7675b78fbb7a differ diff --git a/.flask_cache/95b12f8cd6b93bf78161ab0764ef7d66 b/.flask_cache/95b12f8cd6b93bf78161ab0764ef7d66 new file mode 100644 index 0000000..64f06ed Binary files /dev/null and b/.flask_cache/95b12f8cd6b93bf78161ab0764ef7d66 differ diff --git a/.flask_cache/aabe6e7d021b7037492975340fe21c03 b/.flask_cache/aabe6e7d021b7037492975340fe21c03 new file mode 100644 index 0000000..8243355 Binary files /dev/null and b/.flask_cache/aabe6e7d021b7037492975340fe21c03 differ diff --git a/.flask_cache/bfec0932dad185d106f4b86af0f7c734 b/.flask_cache/bfec0932dad185d106f4b86af0f7c734 new file mode 100644 index 0000000..65d071d Binary files /dev/null and b/.flask_cache/bfec0932dad185d106f4b86af0f7c734 differ diff --git a/.flask_cache/c59a0149864f3a0ccffa8e150c81bc43 b/.flask_cache/c59a0149864f3a0ccffa8e150c81bc43 new file mode 100644 index 0000000..8d39188 Binary files /dev/null and b/.flask_cache/c59a0149864f3a0ccffa8e150c81bc43 differ diff --git a/.flask_cache/d277c4e120e0e4b7fa8f80455a32af2e b/.flask_cache/d277c4e120e0e4b7fa8f80455a32af2e new file mode 100644 index 0000000..30c8d04 Binary files /dev/null and b/.flask_cache/d277c4e120e0e4b7fa8f80455a32af2e differ diff --git a/.flask_cache/dd6eca7ee6b5f09a8f1821c6c4a5510b b/.flask_cache/dd6eca7ee6b5f09a8f1821c6c4a5510b new file mode 100644 index 0000000..5cb2d5e Binary files /dev/null and b/.flask_cache/dd6eca7ee6b5f09a8f1821c6c4a5510b differ diff --git a/.flask_cache/e6ed342200608fc2907bdfc4b3dfe59d b/.flask_cache/e6ed342200608fc2907bdfc4b3dfe59d new file mode 100644 index 0000000..56babdf Binary files /dev/null and b/.flask_cache/e6ed342200608fc2907bdfc4b3dfe59d differ diff --git a/.flask_cache/f2a7e36076223a740fa17b882df5c74a b/.flask_cache/f2a7e36076223a740fa17b882df5c74a deleted file mode 100644 index 82a0b43..0000000 Binary files a/.flask_cache/f2a7e36076223a740fa17b882df5c74a and /dev/null differ diff --git a/.flask_cache/f9a2505762c137a92600cf2ad6c0527d b/.flask_cache/f9a2505762c137a92600cf2ad6c0527d new file mode 100644 index 0000000..9a5ce0a Binary files /dev/null and b/.flask_cache/f9a2505762c137a92600cf2ad6c0527d differ diff --git a/hyperglass/hyperglass.py b/hyperglass/hyperglass.py index da453ce..56228ae 100644 --- a/hyperglass/hyperglass.py +++ b/hyperglass/hyperglass.py @@ -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( diff --git a/hyperglass/static/js/hyperglass.js b/hyperglass/static/js/hyperglass.js index 6de396c..d390c8b 100644 --- a/hyperglass/static/js/hyperglass.js +++ b/hyperglass/static/js/hyperglass.js @@ -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() { `) - 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(`

${response}

`); + }, + 405: function(response, code) { + console.log(code, response); + progress.hide(); + $('#ipprefix').addClass('is-warning'); + $('#output').html(`
${response.responseText}
`); + }, + 415: function(response, code) { + console.log(code, response); + progress.hide(); + $('#ipprefix').addClass('is-danger'); + $('#output').html(`
${response.responseText}
`); + }, + 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 = - '
' + - '
' + - xhr.responseText + - '
' - } - if (xhr.status == 405){ - console.log(XMLHttpRequest.status, 'error') - var output = document.getElementById('output') - $('#ipprefix').addClass('is-warning') - output.innerHTML = - '
' + - '
' + - xhr.responseText + - '
' - } - else if (xhr.status == 200){ - console.log(xhr.status, 'success') - var output = document.getElementById('output') - output.innerHTML = - '
' + - '
' + - '

' + - xhr.responseText + - '

' + - '
' - } - 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); - }); + }) }