PageSourceSearch

https://dshield.org/js/main.js

js dshield.org collected 2026-10-02 03:29:52 UTC 3,344 bytes, 112 lines download raw bytes

1'use strict';
2
3
4var getIpInfo = function (ip) {
5
6    return Promise.all([
7        $.ajax({
8            url: '/api/ip/' + ip + '?json',
9            type: 'GET',
10            dataType: 'json'
11        }),
12        $.ajax({
13            url: '/api/ipwhois/' + ip + '?json',
14            type: 'GET',
15            dataType: 'json'
16        })
17    ]);
18};
19
20var modal;
21var openModal = function (content, closeButton, onCloseCallback) {
22    modal = $('<div id="myModal" class="modal"><div class="modal-content"></div></div>');
23    if (closeButton) {
24        var cb = $('<div class="close close-modal" aria-label="Close"><span aria-hidden="true">&times;</span></div>');
25        $(cb).on('click', function () {
26            onCloseCallback && onCloseCallback();
27            closeModal();
28        });
29        modal.find('.modal-content').append(cb);
30    }
31    modal.find('.modal-content').append(content);
32    $('body').append(modal);
33    modal.show();
34};
35
36var closeModal = function () {
37    modal.remove();
38};
39
40
41var startSpinner = function (el) {
42    var spinner = document.createElement('div');
43    spinner.className = 'spinner-wrapper';
44    spinner.innerHTML = '<div class="spinner"></div>';
45    spinner.firstChild.innerHTML = '<div class="bounce1"></div><div class="bounce2"></div><div class="bounce3"></div>';
46    el.prepend(spinner);
47};
48
49var stopSpinner = function (el) {
50    el.find('.spinner-wrapper').remove();
51};
52
53
54var bindIpModal = function (link) {
55    var ip = link.html();
56    var content = $('<div></div>');
57
58    content.append('<h2>IP: ' + ip + '</h2>');
59    content.append('<div class="inner-content"></div>');
60
61    var ic = content.find('.inner-content');
62
63    link.on('click', function (event) {
64        event.preventDefault();
65
66        startSpinner(ic);
67
68        getIpInfo(ip).then(function (resp) {
69
70            var keyLabel = {
71                as: 'AS',
72                attacks: 'Targets',
73                as_name: 'AS Name',
74                country: 'Country',
75                hostname: 'Hostname',
76                count: 'Reports',
77                maxdate: 'Most Recent Report',
78                mindate: 'First Reported',
79                network: 'Network',
80                updated: 'Updated'
81            }
82
83            var table = $('<Table><tbody></tbody></Table>');
84            var body = table.find('tbody');
85            var i = 0;
86            $.each($.extend(resp[0]['ip'], resp[1]['ipwhois']), function (key, value) {
87                var className  = i % 2 === 0 ? 'evenrow' : 'oddrow';
88                if (typeof keyLabel[key] !== 'undefined') {
89                    body.append(
90                        '<tr class="' + className + '"><td>' + keyLabel[key] + ': </td><td>' + (value || '- none -') + '</td></tr>'
91                    )
92                    i++;
93                }
94            });
95            ic.append(table);
96        }).catch(function () {
97            ic.append('<p>Unable to fetch IP info. Please try again later.</p>');
98        }).finally(function () {
99            ic.append(
100                '<div style="text-align: right;"><a href="/ipinfo.html?ip=' + ip + '">Go to info: ' + ip + '</a></div>'
101            );
102            stopSpinner(ic);
103        });
104        openModal(content, true, function () {
105            ic.empty()
106        });
107    });
108};
109
110$('.ip-modal').each(function (i, link) {
111    bindIpModal($(link));
112});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.