@roflsec/fail2scan 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/daemon.js +24 -16
  2. package/package.json +1 -1
package/bin/daemon.js CHANGED
@@ -5,19 +5,23 @@ const { execFile, spawn } = require('child_process');
5
5
  const { promisify } = require('util');
6
6
  const execFileP = promisify(execFile);
7
7
  require('dotenv').config({ quiet:true})
8
+
8
9
  // -------------------- IPGeolocation --------------------
9
- const IPGeolocationAPI = require("ip-geolocation-api-javascript-sdk");
10
- const GeolocationParams = require("ip-geolocation-api-javascript-sdk/GeolocationParams.js");
11
- const ipGeo = new IPGeolocationAPI(`${process.env.IPGEO_API_KEY}`, true);
12
-
13
- const getGeo = (ip) => {
14
- return new Promise((resolve) => {
15
- const params = new GeolocationParams();
16
- params.setIPAddress(ip);
17
- params.setFields("geo,time_zone,currency,asn,security");
18
- ipGeo.getGeolocation((res) => resolve(res), params);
19
- });
20
- };
10
+ let getGeo = async (ip) => null;
11
+ if(process.env.IPGEO_API_KEY){
12
+ const IPGeolocationAPI = require("ip-geolocation-api-javascript-sdk");
13
+ const GeolocationParams = require("ip-geolocation-api-javascript-sdk/GeolocationParams.js");
14
+ const ipGeo = new IPGeolocationAPI(`${process.env.IPGEO_API_KEY}`, true);
15
+
16
+ getGeo = (ip) => {
17
+ return new Promise((resolve) => {
18
+ const params = new GeolocationParams();
19
+ params.setIPAddress(ip);
20
+ params.setFields("geo,time_zone,currency,asn,security");
21
+ ipGeo.getGeolocation((res) => resolve(res), params);
22
+ });
23
+ };
24
+ }
21
25
 
22
26
  // -------------------- CLI / CONFIG --------------------
23
27
  const argv = process.argv.slice(2);
@@ -149,10 +153,14 @@ async function performScan(ip){
149
153
 
150
154
  try{ fs.writeFileSync(path.join(outDir,'summary.json'),JSON.stringify(summary,null,2)); } catch (e) {}
151
155
 
152
- try {
153
- const geo = await getGeo(ip);
154
- fs.writeFileSync(path.join(outDir, 'geo.json'), JSON.stringify(geo, null, 2));
155
- } catch(e) {}
156
+ // geo non bloquant
157
+ if(process.env.IPGEO_API_KEY){
158
+ getGeo(ip)
159
+ .then(geo => {
160
+ try{ fs.writeFileSync(path.join(outDir,'geo.json'), JSON.stringify(geo, null, 2)); } catch(e){}
161
+ })
162
+ .catch(e=>{});
163
+ }
156
164
 
157
165
  try{ fs.chmodSync(outDir,0o750); } catch (e) {}
158
166
  log('Scan written for',ip,'->',outDir);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roflsec/fail2scan",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Fail2Scan daemon - watches fail2ban logs and scans banned IPs using nmap, dig and whois.",
5
5
  "bin": {
6
6
  "fail2scan-daemon": "./bin/daemon.js"