Async ISP lookup

This commit is contained in:
JonnyWong16 2016-07-31 17:51:40 -07:00
parent 9b067a437c
commit ba8e4ff33c
5 changed files with 149 additions and 69 deletions

View file

@ -3009,8 +3009,10 @@ a:hover .overlay-refresh-image {
a:hover .overlay-refresh-image:hover {
opacity: .9;
}
#ip_error {
#ip_error, #isp_error {
color: #aaa;
display: none;
text-align: center;
padding-top: 10px;
padding-bottom: 10px;
}

View file

@ -13,10 +13,10 @@
</h4>
</div>
<div class="modal-body" id="modal-text">
<div id="ip_error" class="text-muted"></div>
<div class="col-sm-12">
<h4><strong>Location Details</strong></h4>
<h4><strong>Location Details</strong><span id="ip_loading" style="padding-left: 5px;"><i class="fa fa-refresh fa-spin"></i></span></h4>
</div>
<div id="ip_error" class="col-sm-12 text-muted"></div>
<div class="col-sm-6">
<ul class="list-unstyled">
<li>Continent: <strong><span id="continent"></span></strong></li>
@ -35,8 +35,9 @@
</ul>
</div>
<div class="col-sm-12">
<h4><strong>Connection Details</strong></h4>
<h4><strong>Connection Details</strong><span id="isp_loading" style="padding-left: 5px;"><i class="fa fa-refresh fa-spin"></i></span></h4>
</div>
<div id="isp_error" class="col-sm-12 text-muted"></div>
<div class="col-sm-6" id="isp_instance">
<ul class="list-unstyled">
<li>ISP: <strong><span id="isp"></span></strong></li>
@ -59,13 +60,16 @@
type: 'GET',
data: { ip_address: ip_address },
cache: true,
async: true,
async: true,
complete: function () {
$('#ip_loading').remove();
},
error: function () {
$('#ip_error').html('<i class="fa fa-exclamation-circle"></i> Request failed.<br /><br />').show();
$('#ip_error').html('<i class="fa fa-exclamation-circle"></i> Internal request failed.').show();
},
success: function (data) {
if ('error' in data) {
$('#ip_error').html('<i class="fa fa-exclamation-circle"></i> ' + data.error + '<br /><br />').show();
$('#ip_error').html('<i class="fa fa-exclamation-circle"></i> ' + data.error).show();
} else {
$('#continent').html(data.continent);
$('#country').html(data.country);
@ -76,30 +80,54 @@
$('#latitude').html(data.latitude);
$('#longitude').html(data.longitude);
$('#accuracy').html(data.accuracy + ' km');
var nets = data.nets;
if (!(nets.length)) {
$('#isp').html('Not Found')
$('#isp_address').html('Not Found')
} else {
$('#isp_instance').remove();
$.each(nets, function (index, net) {
$('#modal-text').append('<div class="col-sm-6"> \
<ul class="list-unstyled"> \
<li>ISP: <strong>' + net.description + '</strong></li> \
<li><span style="float: left;">Address:&nbsp;</span> \
<span style="float: left;"><strong>' + net.address + '</strong><br /> \
<strong>' + net.city + ", " + net.state + "&nbsp;&nbsp;" + net.postal_code + '</strong><br /> \
<strong>' + net.country + '</strong></span> \
</li> \
</ul> \
</div>')
});
}
}
}
});
}
function getUserConnection(ip_address) {
$.ajax({
url: 'get_whois_lookup',
type: 'GET',
data: { ip_address: ip_address },
cache: true,
async: true,
complete: function () {
$('#isp_loading').remove();
},
error: function () {
$('#isp_error').html('<i class="fa fa-exclamation-circle"></i> Internal request failed.').show();
},
success: function (data) {
if ('error' in data) {
$('#isp_error').html('<i class="fa fa-exclamation-circle"></i> ' + data.error).show();
} else if (!(data.length)) {
$('#isp_error').html('<i class="fa fa-exclamation-circle"></i> Connection details not found.').show();
} else {
$('#isp_instance').remove();
$.each(data, function (index, net) {
var s = '';
if (net.city || net.state || net.postal_code) {
s = (net.city && net.state) ? net.city + ', ' + net.state : net.city || net.state || '';
s = (s && net.postal_code) ? s + '&nbsp;&nbsp;' + net.postal_code : s || net.postal_code || '';
}
s = (s) ? '<strong>' + s + '</strong><br />' : s;
$('#modal-text').append('<div class="col-sm-6"> \
<ul class="list-unstyled"> \
<li>ISP: <strong>' + net.description + '</strong></li> \
<li><span style="float: left;">Address:&nbsp;</span> \
<span style="float: left;"><strong>' + net.address + '</strong><br />' + s +
'<strong>' + net.country + '</strong></span> \
</li> \
</ul> \
</div>')
});
}
}
});
}
getUserLocation('${data}');
getUserConnection('${data}');
</script>
% endif