Skip to content

Commit 1a68434

Browse files
committed
first version
1 parent a20b479 commit 1a68434

File tree

4 files changed

+155
-0
lines changed

4 files changed

+155
-0
lines changed

example/example.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
var KEY = 'MM72AkzHXdHpC8iP65VVEEVrJjp7zkgd';
3+
4+
var ds = require('loopback').createDataSource({connector: require('../'), key: KEY});
5+
6+
var Shodan = ds.createModel('shodan', {
7+
type: {type: String, id: true, required: true}
8+
});
9+
10+
console.log(Shodan);
11+
12+
Shodan.search("port:80", function (err, data) {
13+
if (err) {
14+
console.log(err);
15+
} else {
16+
console.log(data);
17+
}
18+
});

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./lib/shodan');

lib/shodan.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* jamesjara, netdb.io */
2+
3+
'use strict';
4+
5+
var shodanLib = require('shodan-client'),
6+
util = require('util'),
7+
Connector = require('loopback-connector').Connector,
8+
Shodan = function Shodan() {};
9+
10+
/* eslint-disable no-unused-vars */
11+
var shodanInstance = {};
12+
/* eslint-enable no-unused-vars */
13+
14+
var ShodanConnector = function ShodanConnector(settings) {
15+
assert(typeof settings.api_key === 'string', 'cannot init connector without api key');
16+
if (settings.api_key){
17+
this.shodan = shodanLib;
18+
}
19+
20+
this.key = settings.api_key;
21+
shodanInstance = this.shodan;
22+
};
23+
24+
ShodanConnector.initialize = function (dataSource, callback) {
25+
dataSource.connector = new ShodanConnector(dataSource.settings);
26+
callback();
27+
};
28+
29+
ShodanConnector.prototype.DataAccessObject = Shodan;
30+
31+
/**
32+
* Send transactional email with options
33+
* Full list of options are available here: https://www.npmjs.com/package/sendgrid#available-params
34+
*
35+
* @param {Object} options
36+
* {
37+
* from: { name: "John", email: "john@cellarise.com" },
38+
39+
* subject: "Test mail",
40+
* text: "Plain text message",
41+
* html: "<b>Html messages</b> here"
42+
* }
43+
*
44+
* @param {Function} cb callback
45+
* @returns {Function} deferred promise
46+
*/
47+
Shodan.query = function (options, cb) { // eslint-disable-line
48+
var dataSource = this.dataSource,
49+
connector = dataSource.connector,
50+
deferred = Q.defer(),
51+
request;
52+
53+
var fn = function (err, result) {
54+
if (err) {
55+
deferred.reject(err);
56+
} else {
57+
deferred.resolve(result);
58+
}
59+
return cb && cb(err, result);
60+
};
61+
62+
if (options.__data) {
63+
options = R.clone(options.__data);
64+
} else {
65+
options = R.clone(options);
66+
}
67+
68+
assert(connector, 'Cannot query without a connector!');
69+
70+
if (connector.shodan) {
71+
72+
shodanLib.search('asterisk port:5061', 'YOURKEYHERE', searchOpts)
73+
.then(res => {
74+
console.log('Result:');
75+
fn(null, options);
76+
})
77+
.catch(err => {
78+
console.log('Error:');
79+
console.log(err);
80+
fn(null, response);
81+
});
82+
83+
84+
} else {
85+
process.nextTick(function nextTick() { // eslint-disable-line
86+
fn(null, options);
87+
});
88+
}
89+
return deferred.promise;
90+
};
91+
92+
/**
93+
* Query Shodan instance using instance
94+
*/
95+
96+
Shodan.prototype.query = function protoQuery(fn) {
97+
return this.constructor.query(this, fn);
98+
};
99+
100+
/**
101+
* Export the connector class
102+
*/
103+
module.exports = ShodanConnector;
104+

package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "shodan-api-strongloop-connector",
3+
"version": "1.0.0",
4+
"description": "Strongloop connector for shodan APi",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/jamesjara/shodan-api-strongloop-connector.git"
12+
},
13+
"keywords": [
14+
"strongloop",
15+
"shodan",
16+
"connector",
17+
"api"
18+
],
19+
"dependencies": {
20+
"shodan-client": "2.0.0",
21+
"loopback-connector": "*"
22+
},
23+
"author": "jamesjara",
24+
"license": {
25+
"name": "MIT",
26+
"url": "https://github.com/jamesjara/shodan-api-strongloop-connector/blob/master/LICENSE"
27+
},
28+
"bugs": {
29+
"url": "https://github.com/jamesjara/shodan-api-strongloop-connector/issues"
30+
},
31+
"homepage": "https://github.com/jamesjara/shodan-api-strongloop-connector#readme"
32+
}

0 commit comments

Comments
 (0)