Skip to content

Commit 9ebe380

Browse files
integrated whois informations
1 parent d429856 commit 9ebe380

File tree

1 file changed

+108
-10
lines changed

1 file changed

+108
-10
lines changed

ipb.php

Lines changed: 108 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@
165165
Utils.callService('ping', 'id='+uuid+'&time='+time+'&rnd='+Utils.generateUUID(), null, function(data){
166166
successCallback(data.valid);
167167
}, failureCallback);
168+
},
169+
callWhoisService : function(ip, successCallback, failureCallback){
170+
Utils.callService('ipwhois', 'ip='+ip, null, function(data){
171+
successCallback(data.whoisResults);
172+
}, failureCallback);
168173
}
169174
},
170175

@@ -271,9 +276,14 @@
271276
}, {
272277
name : 'whois.com',
273278
url : 'https://www.whois.com/whois/'+ip
279+
}, {
280+
name : 'ripe.net statistics',
281+
url : 'https://stat.ripe.net/'+ip
274282
}];
275283
//http://freegeoip.net/json/83.65.190.82
276284
//https://stackoverflow.com/questions/17290256/get-google-map-link-with-latitude-longitude
285+
//https://apps.db.ripe.net/search/query.html?searchtext=83.65.190.82&bflag=false&source=RIPE#resultsAnchor#resultsAnchor
286+
//https://whois.arin.net/rest/nets;q=8.8.8.8?showDetails=true&showARIN=false&showNonArinTopLevelNet=false&ext=netref2
277287

278288
var list = '';
279289
ipAnalyzeServiceList.forEach(function(ipAnalyzeService){
@@ -300,7 +310,7 @@
300310
var domId = Utils.generateUUID();
301311
$('#reportsDiv').prepend(
302312
$('<div class="list-group-item">').append(
303-
$('<div class="row link" title="Click for details">').append(
313+
$('<div class="row link" id="'+domId+'_overview_div" title="Click for details">').append(
304314
$('<div class="col-lg-2">').append(
305315
'<h4><span class="label label-default">'+track.time+'</span></h4>'
306316
)
@@ -317,7 +327,19 @@
317327
_generateAnalyzeIPButtons(track.ip)
318328
)
319329
)
320-
).click(function(e){
330+
).append(
331+
$('<div class="col-lg-4">').append(
332+
$('<div class="input-group">').append(
333+
'<span class="input-group-addon">Owner: </span>'
334+
).append(
335+
$('<input type="text" id="'+domId+'_ip_owner_txt" class="form-control" readonly>').click(function(e){
336+
$(this).select();
337+
document.execCommand("copy");
338+
})
339+
)
340+
)
341+
)
342+
.click(function(e){
321343
if (e.target.tagName != 'BUTTON' && e.target.tagName != 'A' && e.target.tagName != 'INPUT')
322344
$('#'+domId+'_headers_div').toggle();
323345
})
@@ -346,6 +368,23 @@
346368
)
347369
).hide().fadeIn(500)
348370
);
371+
Dashboard.services.callWhoisService(track.ip, function(whoisResults){
372+
$('#'+domId+'_ip_owner_txt').val(whoisResults.netName).popover({
373+
placement : 'auto right',
374+
container : 'body',
375+
html : true,
376+
title : 'WHOIS ' + track.ip,
377+
content : function(){
378+
var html = '<pre>'+whoisResults.output+'</pre>';
379+
return html;
380+
}(),
381+
382+
trigger : 'hover click'
383+
});
384+
}, function(error){
385+
Utils.showError(error, $('#reportsTable'));
386+
});
387+
349388
});
350389

351390
}, function(error){
@@ -770,6 +809,9 @@
770809
.link:hover{
771810
color: #FFFFFF;
772811
background-color: #428bca;
812+
}
813+
.popover {
814+
max-width: 50em !important;
773815
}
774816
</style>
775817
</head>
@@ -985,7 +1027,7 @@
9851027
if(isset($_GET['op']) && $_GET['op'] == 'shortening'){
9861028
header('Content-Type: application/json');
9871029
try{
988-
if(!isset($_GET['url']))
1030+
if(!isset($_GET['url']) || $_GET['url']=='')
9891031
throw new Exception('url parameter required');
9901032
$shortenedUrl = @file_get_contents('http://tinyurl.com/api-create.php?url='.$_GET['url']);
9911033
echo '{"status" : 0, "shortenedUrl" : "'.$shortenedUrl.'"}';
@@ -1032,7 +1074,7 @@
10321074
if(isset($_GET['op']) && $_GET['op'] == 'loadConfig'){
10331075
header('Content-Type: application/json');
10341076
try{
1035-
if(!isset($_GET['id']))
1077+
if(!isset($_GET['id']) || $_GET['id']=='')
10361078
throw new Exception('id parameter required');
10371079
$configUUID = $_GET['id'];
10381080
if(!file_exists(getcwd().'/'.$configFolder.'/'.$configUUID.'.json'))
@@ -1049,7 +1091,7 @@
10491091
if(isset($_GET['op']) && $_GET['op'] == 'loadTrack'){
10501092
header('Content-Type: application/json');
10511093
try{
1052-
if(!isset($_GET['id']))
1094+
if(!isset($_GET['id']) || $_GET['id']=='')
10531095
throw new Exception('id parameter required');
10541096
$configUUID = $_GET['id'];
10551097
if(!file_exists(getcwd().'/'.$configFolder.'/'.$configUUID.'.json'))
@@ -1070,9 +1112,9 @@
10701112
if(isset($_GET['op']) && $_GET['op'] == 'ping'){
10711113
header('Content-Type: application/json');
10721114
try{
1073-
if(!isset($_GET['id']))
1115+
if(!isset($_GET['id']) || $_GET['id']=='')
10741116
throw new Exception('id parameter required');
1075-
if(!isset($_GET['time']))
1117+
if(!isset($_GET['time']) || $_GET['time']=='')
10761118
throw new Exception('time parameter required');
10771119
$trackUUID = $_GET['id'];
10781120
$localTime = $_GET['time'];
@@ -1087,9 +1129,65 @@
10871129
exit();
10881130
}
10891131

1132+
if(isset($_GET['op']) && $_GET['op'] == 'ipwhois'){
1133+
header('Content-Type: application/json; charset=utf8');
1134+
try{
1135+
if(!isset($_GET['ip']) || $_GET['ip']=='')
1136+
throw new Exception('ip parameter required');
1137+
$ip = $_GET['ip'];
1138+
/*WHOIS IP Server list
1139+
whois.afrinic.net -> Africa - but returns data for ALL locations worldwide
1140+
whois.lacnic.net -> Latin America and Caribbean but returns data for ALL locations worldwide
1141+
whois.apnic.net -> Asia/Pacific only
1142+
whois.arin.net -> North America only
1143+
whois.ripe.net -> Europe, Middle East and Central Asia only
1144+
*/
1145+
$whoisserver = 'whois.lacnic.net';
1146+
if(!($fp = fsockopen($whoisserver, 43, $errno, $errstr, 10)))
1147+
throw new Exception("Error contacting the WHOIS server $whoisserver : $errstr ($errno)");
1148+
1149+
fprintf($fp, "%s\r\n", $ip);
1150+
$whoisResultString = "";
1151+
$netNameString = "";
1152+
$lineCount = 0;
1153+
while(!feof($fp)){
1154+
$line = fgets($fp);
1155+
if(trim($line[0])!='' && $line[0]!='#' && $line[0]!='%'){
1156+
$whoisResultString.=$line;
1157+
$lineCount++;
1158+
if(strpos($line, ':') !== false){
1159+
$lineSplit = explode(':', $line);
1160+
if(strtolower($lineSplit[0])=='netname')
1161+
$netNameString = trim($lineSplit[1]);
1162+
} else {
1163+
if($lineCount == 2)
1164+
$netNameString = trim(explode('(NET', $line)[0]);
1165+
}
1166+
}
1167+
}
1168+
fclose($fp);
1169+
1170+
$ret = json_encode((object) array(
1171+
'status' => 0,
1172+
'whoisResults' => (object) array(
1173+
'output' => utf8_encode($whoisResultString),
1174+
'netName' => utf8_encode($netNameString)
1175+
)
1176+
));
1177+
1178+
if(json_last_error()!=0)
1179+
throw new Exception("Error encoding the JSON response");
1180+
echo $ret;
1181+
}catch(Exception $ex){
1182+
echo '{"status" : -1, "error" : "'.$ex->getMessage().'"}';
1183+
$logError($ex->getMessage());
1184+
}
1185+
exit();
1186+
}
1187+
10901188
if(isset($_GET['op']) && $_GET['op'] == 'i'){
10911189
try{
1092-
if(!isset($_GET['tid']))
1190+
if(!isset($_GET['tid']) || $_GET['tid']=='')
10931191
throw new Exception('tid parameter required');
10941192
$trackUUID = $_GET['tid'];
10951193
if(!file_exists(getcwd().'/'.$reportFolder.'/'.$trackUUID.'.json'))
@@ -1129,9 +1227,9 @@
11291227

11301228
if(isset($_GET['op']) && $_GET['op'] == 'l'){
11311229
try{
1132-
if(!isset($_GET['tid']))
1230+
if(!isset($_GET['tid']) || $_GET['tid']=='')
11331231
throw new Exception('tid parameter required');
1134-
if(!isset($_GET['lid']))
1232+
if(!isset($_GET['lid']) || $_GET['lid']=='')
11351233
throw new Exception('lid parameter required');
11361234
$trackUUID = $_GET['tid'];
11371235
$linkUUID = $_GET['lid'];

0 commit comments

Comments
 (0)