geoip-lite2 2.1.6 β†’ 2.1.8

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.
package/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  .idea
2
2
  node_modules
3
- tmp
3
+ tmp
4
+ command.txt
package/AUTHORS CHANGED
@@ -1,2 +1,3 @@
1
1
  Philip Tellis <philip@bluesmoon.info> (https://bluesmoon.info)
2
2
  Arturs Sosins <@ar2rsawseen>
3
+ Modified by: Sefinek <contact@sefinek.net> (https://sefinek.net)
package/LICENSE CHANGED
@@ -20,6 +20,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
20
  See the License for the specific language governing permissions and
21
21
  limitations under the License.
22
22
 
23
+
23
24
  DATABASES LICENSE (GeoLite2 databases)
24
25
 
25
26
  Copyright (c) 2012-2018 MaxMind, Inc. All Rights Reserved.
package/README.md CHANGED
@@ -1,16 +1,17 @@
1
- πŸ—ΊοΈ GeoIP-Lite2 v2.1 - Now even faster!
2
- ==========
3
- A native Node.js API for the GeoLite data from MaxMind.
4
-
5
- This product includes GeoLite data created by MaxMind, available from: https://www.maxmind.com
6
-
7
- <a href="https://www.npmjs.com/package/geoip-lite2" target="_blank" title="geoip-lite2 - npm" style="text-decoration:none">
8
- <img src="https://img.shields.io/npm/dt/geoip-lite2?maxAge=3600" alt="The number of downloads">
9
- <img src="https://img.shields.io/github/last-commit/sefinek24/geoip-lite2" alt="Last commit">
10
- <img src="https://img.shields.io/github/issues/sefinek24/geoip-lite2" alt="Issues">
11
- <img src="https://img.shields.io/github/commit-activity/w/sefinek24/geoip-lite2" alt="Commit activity">
12
- <img src="https://img.shields.io/github/languages/code-size/sefinek24/geoip-lite2" alt="Code size">
13
- </a>
1
+ <div align="center">
2
+ <h1>πŸ—ΊοΈ GeoIP-Lite2 v2.1 - Now even faster!</h1>
3
+ A native Node.js API for the GeoLite data from MaxMind.<br>
4
+ This product includes GeoLite data created by MaxMind, available from: https://www.maxmind.com
5
+ <br><br>
6
+ <a href="https://www.npmjs.com/package/geoip-lite2" target="_blank" title="geoip-lite2 - npm" style="text-decoration:none">
7
+ <img src="https://img.shields.io/npm/dt/geoip-lite2?maxAge=3600" alt="The number of downloads">
8
+ <img src="https://img.shields.io/github/last-commit/sefinek24/geoip-lite2" alt="Last commit">
9
+ <img src="https://img.shields.io/github/issues/sefinek24/geoip-lite2" alt="Issues">
10
+ <img src="https://img.shields.io/github/commit-activity/w/sefinek24/geoip-lite2" alt="Commit activity">
11
+ <img src="https://img.shields.io/github/languages/code-size/sefinek24/geoip-lite2" alt="Code size">
12
+ </a>
13
+ </div>
14
+
14
15
 
15
16
  πŸš€ Improved GeoIP Module by [Sefinek](https://sefinek.net)
16
17
  ------------
@@ -1 +1 @@
1
- 5cb8483a585354b99dd0edf0f2fde41de392c4671c98cc51f782263adbc147e1 GeoLite2-City-CSV_20230912.zip
1
+ ef6b46b8a2d067b8d453f763f63c14180f086a095a0cdf82bb7378b79cc20479 GeoLite2-City-CSV_20230922.zip
@@ -1 +1 @@
1
- 926fd3b7a33234806141df355e34713229de458e56cdfb6f5b2881ddaca4ea32 GeoLite2-Country-CSV_20230912.zip
1
+ e5e56baea61630fa8d22f76ca804fd353024ac38364abd2a65c126be7e7fab8c GeoLite2-Country-CSV_20230922.zip
Binary file
Binary file
Binary file
Binary file
Binary file
package/lib/geoip.js CHANGED
@@ -1 +1 @@
1
- const e=require('node:fs'),t=require('node:net'),r=require('node:path'),n=require('async'),i=require('./utils.js'),o=require('./fsWatcher.js'),{version:a}=require('../package.json');e.existsSync=e.existsSync||r.existsSync;const c='dataWatcher',f=r.resolve(__dirname,global.geoDataDir||process.env.geoDataDIR||'../data/'),s={city:r.join(f,'geoip-city.dat'),city6:r.join(f,'geoip-city6.dat'),cityNames:r.join(f,'geoip-city-names.dat'),country:r.join(f,'geoip-country.dat'),country6:r.join(f,'geoip-country6.dat')},l=[[i.aton4('10.0.0.0'),i.aton4('10.255.255.255')],[i.aton4('172.16.0.0'),i.aton4('172.31.255.255')],[i.aton4('192.168.0.0'),i.aton4('192.168.255.255')]],u={firstIP:null,lastIP:null,lastLine:0,locationBuffer:null,locationRecordSize:88,mainBuffer:null,recordSize:24},d={firstIP:null,lastIP:null,lastLine:0,mainBuffer:null,recordSize:48};let y=JSON.parse(JSON.stringify(u)),S=JSON.parse(JSON.stringify(d));const p=e=>{let t,r,n=0,i=y.lastIP,o=y.lastLine,a=y.firstIP;const c=y.mainBuffer,f=y.locationBuffer,s=l,u=y.recordSize,d=y.locationRecordSize;let S;const p={range:'',country:'',region:'',eu:'',timezone:'',city:'',ll:[0,0]};if(e>y.lastIP||e<y.firstIP)return null;for(S=0;S<s.length;S++)if(e>=s[S][0]&&e<=s[S][1])return null;for(;;){if(t=Math.round((o-n)/2)+n,i=c.readUInt32BE(t*u),a=c.readUInt32BE(t*u+4),i<=e&&a>=e)return p.range=[i,a],10===u?p.country=c.toString('utf8',t*u+8,t*u+10):(r=c.readUInt32BE(t*u+8),p.country=f.toString('utf8',r*d,r*d+2).replace(/\u0000.*/,''),p.region=f.toString('utf8',r*d+2,r*d+5).replace(/\u0000.*/,''),p.metro=f.readInt32BE(r*d+5),p.ll[0]=c.readInt32BE(t*u+12)/1e4,p.ll[1]=c.readInt32BE(t*u+16)/1e4,p.area=c.readUInt32BE(t*u+20),p.eu=f.toString('utf8',r*d+9,r*d+10).replace(/\u0000.*/,''),p.timezone=f.toString('utf8',r*d+10,r*d+42).replace(/\u0000.*/,''),p.city=f.toString('utf8',r*d+42,r*d+d).replace(/\u0000.*/,'')),p;if(n===o)return null;n===o-1?t===n?n=o:o=n:i>e?o=t:a<e&&(n=t)}};function B(t){let r,i;const o=JSON.parse(JSON.stringify(u));if('function'==typeof arguments[0])n.series([t=>{n.series([t=>{e.open(s.cityNames,'r',((e,n)=>{r=n,t(e)}))},t=>{e.fstat(r,((e,r)=>{i=r.size,o.locationBuffer=Buffer.alloc(i),t(e)}))},t=>{e.read(r,o.locationBuffer,0,i,0,t)},t=>{e.close(r,t)},t=>{e.open(s.city,'r',((e,n)=>{r=n,t(e)}))},t=>{e.fstat(r,((e,r)=>{i=r.size,t(e)}))}],(n=>{if(n){if('ENOENT'!==n.code&&'EBADF'!==n.code)throw n;e.open(s.country,'r',((n,a)=>{n?t(n):(r=a,e.fstat(r,((e,r)=>{i=r.size,o.recordSize=10,t()})))}))}else t()}))},()=>{o.mainBuffer=Buffer.alloc(i),n.series([t=>{e.read(r,o.mainBuffer,0,i,0,t)},t=>{e.close(r,t)}],(e=>{e||(o.lastLine=i/o.recordSize-1,o.lastIP=o.mainBuffer.readUInt32BE(o.lastLine*o.recordSize+4),o.firstIP=o.mainBuffer.readUInt32BE(0),y=o),t(e)}))}]);else{try{if(r=e.openSync(s.cityNames,'r'),i=e.fstatSync(r).size,0===i)throw{code:'EMPTY_FILE'};y.locationBuffer=Buffer.alloc(i),e.readSync(r,y.locationBuffer,0,i,0),e.closeSync(r),r=e.openSync(s.city,'r'),i=e.fstatSync(r).size}catch(t){if('ENOENT'!==t.code&&'EBADF'!==t.code&&'EMPTY_FILE'!==t.code)throw t;r=e.openSync(s.country,'r'),i=e.fstatSync(r).size,y.recordSize=10}y.mainBuffer=Buffer.alloc(i),e.readSync(r,y.mainBuffer,0,i,0),e.closeSync(r),y.lastLine=i/y.recordSize-1,y.lastIP=y.mainBuffer.readUInt32BE(y.lastLine*y.recordSize+4),y.firstIP=y.mainBuffer.readUInt32BE(0)}}function g(t){let r,i;const o=JSON.parse(JSON.stringify(d));if('function'==typeof arguments[0])n.series([t=>{n.series([t=>{e.open(s.city6,'r',((e,n)=>{r=n,t(e)}))},t=>{e.fstat(r,((e,r)=>{i=r.size,t(e)}))}],(n=>{if(n){if('ENOENT'!==n.code&&'EBADF'!==n.code)throw n;e.open(s.country6,'r',((n,a)=>{n?t(n):(r=a,e.fstat(r,((e,r)=>{i=r.size,o.recordSize=34,t()})))}))}else t()}))},()=>{o.mainBuffer=Buffer.alloc(i),n.series([t=>{e.read(r,o.mainBuffer,0,i,0,t)},t=>{e.close(r,t)}],(e=>{e||(o.lastLine=i/o.recordSize-1,S=o),t(e)}))}]);else{try{if(r=e.openSync(s.city6,'r'),i=e.fstatSync(r).size,0===i)throw{code:'EMPTY_FILE'}}catch(t){if('ENOENT'!==t.code&&'EBADF'!==t.code&&'EMPTY_FILE'!==t.code)throw t;r=e.openSync(s.country6,'r'),i=e.fstatSync(r).size,S.recordSize=34}S.mainBuffer=Buffer.alloc(i),e.readSync(r,S.mainBuffer,0,i,0),e.closeSync(r),S.lastLine=i/S.recordSize-1}}module.exports={cmp:i.cmp,lookup:e=>{if(!e)return null;if('number'==typeof e)return p(e);if(4===t.isIP(e))return p(i.aton4(e));if(6===t.isIP(e)){const t=(e=>{const t=e.toUpperCase(),r=['0:0:0:0:0:FFFF:','::FFFF:'];for(let e=0;e<r.length;e++){const n=r[e];if(0===t.indexOf(n))return t.substring(n.length)}return null})(e);return t?p(i.aton4(t)):(e=>{const t=S.mainBuffer,r=S.recordSize,n=y.locationBuffer,o=y.locationRecordSize,a={range:'',country:'',region:'',city:'',ll:[0,0]},c=(e,n)=>{let i=0;const o=[];for(i=0;i<2;i++)o.push(t.readUInt32BE(e*r+16*n+4*i));return o};S.lastIP=c(S.lastLine,1),S.firstIP=c(0,0);let f,s,l=0,u=S.lastIP,d=S.lastLine,p=S.firstIP;if(i.cmp6(e,S.lastIP)>0||i.cmp6(e,S.firstIP)<0)return null;for(;;){if(f=Math.round((d-l)/2)+l,u=c(f,0),p=c(f,1),i.cmp6(u,e)<=0&&i.cmp6(p,e)>=0)return 34===r?a.country=t.toString('utf8',f*r+32,f*r+34).replace(/\u0000.*/,''):(s=t.readUInt32BE(f*r+32),a.country=n.toString('utf8',s*o,s*o+2).replace(/\u0000.*/,''),a.region=n.toString('utf8',s*o+2,s*o+5).replace(/\u0000.*/,''),a.metro=n.readInt32BE(s*o+5),a.ll[0]=t.readInt32BE(f*r+36)/1e4,a.ll[1]=t.readInt32BE(f*r+40)/1e4,a.area=t.readUInt32BE(f*r+44),a.eu=n.toString('utf8',s*o+9,s*o+10).replace(/\u0000.*/,''),a.timezone=n.toString('utf8',s*o+10,s*o+42).replace(/\u0000.*/,''),a.city=n.toString('utf8',s*o+42,s*o+o).replace(/\u0000.*/,'')),a;if(l===d)return null;l===d-1?f===l?l=d:d=l:i.cmp6(u,e)>0?d=f:i.cmp6(p,e)<0&&(l=f)}})(i.aton6(e))}return null},pretty:e=>'string'==typeof e?e:'number'==typeof e?i.ntoa4(e):Array.isArray(e)?i.ntoa6(e):e,startWatchingDataUpdate:e=>{o.makeFsWatchFilter(c,f,6e4,(()=>{n.series([e=>{B(e)},e=>{g(e)}],e)}))},stopWatchingDataUpdate:()=>{o.stopWatching(c)},clear:()=>{y=JSON.parse(JSON.stringify(u)),S=JSON.parse(JSON.stringify(d))},reloadDataSync:()=>{B(),g()},reloadData:e=>{n.series([e=>{B(e)},e=>{g(e)}],e)},version:a},B(),g();
1
+ const e=require('node:fs'),t=require('node:net'),r=require('node:path'),n=require('async'),i=require('./utils.js'),o=require('./fsWatcher.js'),{version:a}=require('../package.json');e.existsSync=e.existsSync||r.existsSync;const c='dataWatcher',f=r.resolve(__dirname,global.geoDataDir||process.env.geoDataDIR||'../data/'),s={city:r.join(f,'geoip-city.dat'),city6:r.join(f,'geoip-city6.dat'),cityNames:r.join(f,'geoip-city-names.dat'),country:r.join(f,'geoip-country.dat'),country6:r.join(f,'geoip-country6.dat')},l=[[i.aton4('10.0.0.0'),i.aton4('10.255.255.255')],[i.aton4('172.16.0.0'),i.aton4('172.31.255.255')],[i.aton4('192.168.0.0'),i.aton4('192.168.255.255')]],u={firstIP:null,lastIP:null,lastLine:0,locationBuffer:null,locationRecordSize:88,mainBuffer:null,recordSize:24},d={firstIP:null,lastIP:null,lastLine:0,mainBuffer:null,recordSize:48};let y=JSON.parse(JSON.stringify(u)),S=JSON.parse(JSON.stringify(d));const p=e=>{let t,r,n=0,i=y.lastIP,o=y.lastLine,a=y.firstIP;const c=y.mainBuffer,f=y.locationBuffer,s=l,u=y.recordSize,d=y.locationRecordSize;let S;const p={range:'',country:'',region:'',eu:'',timezone:'',city:'',ll:[0,0]};if(e>y.lastIP||e<y.firstIP)return null;for(S=0;S<s.length;S++)if(e>=s[S][0]&&e<=s[S][1])return null;for(;;){if(t=Math.round((o-n)/2)+n,i=c.readUInt32BE(t*u),a=c.readUInt32BE(t*u+4),i<=e&&a>=e)return p.range=[i,a],10===u?p.country=c.toString('utf8',t*u+8,t*u+10):(r=c.readUInt32BE(t*u+8),p.country=f.toString('utf8',r*d,r*d+2).replace(/\u0000.*/,''),p.region=f.toString('utf8',r*d+2,r*d+5).replace(/\u0000.*/,''),p.metro=f.readInt32BE(r*d+5),p.ll[0]=c.readInt32BE(t*u+12)/1e4,p.ll[1]=c.readInt32BE(t*u+16)/1e4,p.area=c.readUInt32BE(t*u+20),p.eu=f.toString('utf8',r*d+9,r*d+10).replace(/\u0000.*/,''),p.timezone=f.toString('utf8',r*d+10,r*d+42).replace(/\u0000.*/,''),p.city=f.toString('utf8',r*d+42,r*d+d).replace(/\u0000.*/,'')),p;if(n===o)return null;n===o-1?t===n?n=o:o=n:i>e?o=t:a<e&&(n=t)}};function B(t){let r,i;const o=JSON.parse(JSON.stringify(u));if('function'==typeof arguments[0])n.series([t=>{n.series([t=>{e.open(s.cityNames,'r',((e,n)=>{r=n,t(e)}))},t=>{e.fstat(r,((e,r)=>{i=r.size,o.locationBuffer=Buffer.alloc(i),t(e)}))},t=>{e.read(r,o.locationBuffer,0,i,0,t)},t=>{e.close(r,t)},t=>{e.open(s.city,'r',((e,n)=>{r=n,t(e)}))},t=>{e.fstat(r,((e,r)=>{i=r.size,t(e)}))}],(n=>{if(n){if('ENOENT'!==n.code&&'EBADF'!==n.code)throw n;e.open(s.country,'r',((n,a)=>{n?t(n):(r=a,e.fstat(r,((e,r)=>{i=r.size,o.recordSize=10,t()})))}))}else t()}))},()=>{o.mainBuffer=Buffer.alloc(i),n.series([t=>{e.read(r,o.mainBuffer,0,i,0,t)},t=>{e.close(r,t)}],(e=>{e||(o.lastLine=i/o.recordSize-1,o.lastIP=o.mainBuffer.readUInt32BE(o.lastLine*o.recordSize+4),o.firstIP=o.mainBuffer.readUInt32BE(0),y=o),t(e)}))}]);else{try{if(r=e.openSync(s.cityNames,'r'),i=e.fstatSync(r).size,0===i)throw{code:'EMPTY_FILE'};y.locationBuffer=Buffer.alloc(i),e.readSync(r,y.locationBuffer,0,i,0),e.closeSync(r),r=e.openSync(s.city,'r'),i=e.fstatSync(r).size}catch(t){if('ENOENT'!==t.code&&'EBADF'!==t.code&&'EMPTY_FILE'!==t.code)throw t;r=e.openSync(s.country,'r'),i=e.fstatSync(r).size,y.recordSize=10}y.mainBuffer=Buffer.alloc(i),e.readSync(r,y.mainBuffer,0,i,0),e.closeSync(r),y.lastLine=i/y.recordSize-1,y.lastIP=y.mainBuffer.readUInt32BE(y.lastLine*y.recordSize+4),y.firstIP=y.mainBuffer.readUInt32BE(0)}}function g(t){let r,i;const o=JSON.parse(JSON.stringify(d));if('function'==typeof arguments[0])n.series([t=>{n.series([t=>{e.open(s.city6,'r',((e,n)=>{r=n,t(e)}))},t=>{e.fstat(r,((e,r)=>{i=r.size,t(e)}))}],(n=>{if(n){if('ENOENT'!==n.code&&'EBADF'!==n.code)throw n;e.open(s.country6,'r',((n,a)=>{n?t(n):(r=a,e.fstat(r,((e,r)=>{i=r.size,o.recordSize=34,t()})))}))}else t()}))},()=>{o.mainBuffer=Buffer.alloc(i),n.series([t=>{e.read(r,o.mainBuffer,0,i,0,t)},t=>{e.close(r,t)}],(e=>{e||(o.lastLine=i/o.recordSize-1,S=o),t(e)}))}]);else{try{if(r=e.openSync(s.city6,'r'),i=e.fstatSync(r).size,0===i)throw{code:'EMPTY_FILE'}}catch(t){if('ENOENT'!==t.code&&'EBADF'!==t.code&&'EMPTY_FILE'!==t.code)throw t;r=e.openSync(s.country6,'r'),i=e.fstatSync(r).size,S.recordSize=34}S.mainBuffer=Buffer.alloc(i),e.readSync(r,S.mainBuffer,0,i,0),e.closeSync(r),S.lastLine=i/S.recordSize-1}}module.exports={cmp:i.cmp,lookup:e=>{if(!e)return null;if('number'==typeof e)return p(e);if(4===t.isIP(e))return p(i.aton4(e));if(6===t.isIP(e)){const t=(e=>{const t=e.toUpperCase(),r=['0:0:0:0:0:FFFF:','::FFFF:'];for(let e=0;e<r.length;e++){const n=r[e];if(0===t.indexOf(n))return t.substring(n.length)}return null})(e);return t?p(i.aton4(t)):(e=>{const t=S.mainBuffer,r=S.recordSize,n=y.locationBuffer,o=y.locationRecordSize,a={range:'',country:'',region:'',city:'',ll:[0,0]},c=(e,n)=>{let i;const o=[];for(i=0;i<2;i++)o.push(t.readUInt32BE(e*r+16*n+4*i));return o};S.lastIP=c(S.lastLine,1),S.firstIP=c(0,0);let f,s,l=0,u=S.lastIP,d=S.lastLine,p=S.firstIP;if(i.cmp6(e,S.lastIP)>0||i.cmp6(e,S.firstIP)<0)return null;for(;;){if(f=Math.round((d-l)/2)+l,u=c(f,0),p=c(f,1),i.cmp6(u,e)<=0&&i.cmp6(p,e)>=0)return 34===r?a.country=t.toString('utf8',f*r+32,f*r+34).replace(/\u0000.*/,''):(s=t.readUInt32BE(f*r+32),a.country=n.toString('utf8',s*o,s*o+2).replace(/\u0000.*/,''),a.region=n.toString('utf8',s*o+2,s*o+5).replace(/\u0000.*/,''),a.metro=n.readInt32BE(s*o+5),a.ll[0]=t.readInt32BE(f*r+36)/1e4,a.ll[1]=t.readInt32BE(f*r+40)/1e4,a.area=t.readUInt32BE(f*r+44),a.eu=n.toString('utf8',s*o+9,s*o+10).replace(/\u0000.*/,''),a.timezone=n.toString('utf8',s*o+10,s*o+42).replace(/\u0000.*/,''),a.city=n.toString('utf8',s*o+42,s*o+o).replace(/\u0000.*/,'')),a;if(l===d)return null;l===d-1?f===l?l=d:d=l:i.cmp6(u,e)>0?d=f:i.cmp6(p,e)<0&&(l=f)}})(i.aton6(e))}return null},pretty:e=>'string'==typeof e?e:'number'==typeof e?i.ntoa4(e):Array.isArray(e)?i.ntoa6(e):e,startWatchingDataUpdate:e=>{o.makeFsWatchFilter(c,f,6e4,(()=>{n.series([e=>{B(e)},e=>{g(e)}],e)}))},stopWatchingDataUpdate:()=>{o.stopWatching(c)},clear:()=>{y=JSON.parse(JSON.stringify(u)),S=JSON.parse(JSON.stringify(d))},reloadDataSync:()=>{B(),g()},reloadData:e=>{n.series([e=>{B(e)},e=>{g(e)}],e)},version:a},B(),g();
package/lib/utils.js CHANGED
@@ -1 +1 @@
1
- const t=module.exports={};t.aton4=function(t){return t=t.split(/\./),(parseInt(t[0],10)<<24>>>0)+(parseInt(t[1],10)<<16>>>0)+(parseInt(t[2],10)<<8>>>0)+(parseInt(t[3],10)>>>0)},t.aton6=function(t){const n=(t=t.replace(/"/g,'').split(/:/)).length-1;let r;if(''===t[n]&&(t[n]=0),n<7)for(t.length=8,r=n;r>=0&&''!==t[r];r--)t[7-n+r]=t[r];for(r=0;r<8;r++)t[r]?t[r]=parseInt(t[r],16):t[r]=0;const e=[];for(r=0;r<4;r++)e.push((t[2*r]<<16)+t[2*r+1]>>>0);return e},t.cmp=function(t,n){return'number'==typeof t&&'number'==typeof n?t<n?-1:t>n?1:0:t instanceof Array&&n instanceof Array?this.cmp6(t,n):null},t.cmp6=function(t,n){for(let r=0;r<2;r++){if(t[r]<n[r])return-1;if(t[r]>n[r])return 1}return 0},t.isPrivateIP=function(t){return null!=(t=t.toString()).match(/^10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^192\.168\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^172\.16\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^169\.254\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^fc00:/)||null!=t.match(/^fe80:/)},t.ntoa4=function(t){return t=((t=t.toString())>>>24&255)+'.'+(t>>>16&255)+'.'+(t>>>8&255)+'.'+(255&t)},t.ntoa6=function(t){let n='[';for(let r=0;r<t.length;r++)n+=(t[r]>>>16).toString(16)+':',n+=(65535&t[r]).toString(16)+':';return n=n.replace(/:$/,']').replace(/:0+/g,':').replace(/::+/,'::'),n};
1
+ const t=module.exports={};t.aton4=t=>(t=t.split(/\./),(parseInt(t[0],10)<<24>>>0)+(parseInt(t[1],10)<<16>>>0)+(parseInt(t[2],10)<<8>>>0)+(parseInt(t[3],10)>>>0)),t.aton6=t=>{const n=(t=t.replace(/"/g,'').split(/:/)).length-1;let r;if(''===t[n]&&(t[n]=0),n<7)for(t.length=8,r=n;r>=0&&''!==t[r];r--)t[7-n+r]=t[r];for(r=0;r<8;r++)t[r]?t[r]=parseInt(t[r],16):t[r]=0;const e=[];for(r=0;r<4;r++)e.push((t[2*r]<<16)+t[2*r+1]>>>0);return e},t.cmp=(t,n)=>'number'==typeof t&&'number'==typeof n?t<n?-1:t>n?1:0:t instanceof Array&&n instanceof Array?this.cmp6(t,n):null,t.cmp6=(t,n)=>{for(let r=0;r<2;r++){if(t[r]<n[r])return-1;if(t[r]>n[r])return 1}return 0},t.isPrivateIP=t=>null!=(t=t.toString()).match(/^10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^192\.168\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^172\.16\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^169\.254\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^fc00:/)||null!=t.match(/^fe80:/),t.ntoa4=t=>t=((t=t.toString())>>>24&255)+'.'+(t>>>16&255)+'.'+(t>>>8&255)+'.'+(255&t),t.ntoa6=t=>{let n='[';for(let r=0;r<t.length;r++)n+=(t[r]>>>16).toString(16)+':',n+=(65535&t[r]).toString(16)+':';return n=n.replace(/:$/,']').replace(/:0+/g,':').replace(/::+/,'::'),n};
package/package.json CHANGED
@@ -1,77 +1,77 @@
1
- {
2
- "name": "geoip-lite2",
3
- "version": "2.1.6",
4
- "description": "A light weight native JavaScript implementation of GeoIP API from MaxMind.",
5
- "keywords": [
6
- "city",
7
- "country",
8
- "fast-geoip",
9
- "geo",
10
- "geoip",
11
- "geolite",
12
- "geolite2",
13
- "geolocation",
14
- "geolookup",
15
- "ip",
16
- "ipv4",
17
- "ipv6",
18
- "location",
19
- "maxmind",
20
- "region",
21
- "state"
22
- ],
23
- "homepage": "https://github.com/sefinek24/geoip-lite2#readme",
24
- "bugs": {
25
- "url": "https://github.com/sefinek24/geoip-lite2/issues"
26
- },
27
- "repository": {
28
- "type": "git",
29
- "url": "git+https://github.com/sefinek24/geoip-lite2.git"
30
- },
31
- "license": "Apache-2.0",
32
- "author": "Philip Tellis <philip@bluesmoon.info> (https://bluesmoon.info)",
33
- "main": "lib/geoip.js",
34
- "types": "index.d.ts",
35
- "directories": {
36
- "lib": "lib",
37
- "test": "test"
38
- },
39
- "files": [
40
- "data/",
41
- "lib/",
42
- "test/",
43
- "utils/",
44
- ".gitignore",
45
- "AUTHORS",
46
- "index.d.ts",
47
- "LICENSE"
48
- ],
49
- "scripts": {
50
- "eslint": "eslint .",
51
- "minify-linux": "echo \"Please wait...\n\" && bash _Minify/linux.bash",
52
- "minify-win": "powershell.exe -ExecutionPolicy Bypass .\\_Minify\\windows.ps1",
53
- "test": "jest test",
54
- "up": "ncu -u -x chalk && npm install && npm update && npm audit fix",
55
- "updatedb": "node utils/updatedb.js",
56
- "updatedb-debug": "node utils/updatedb.js debug",
57
- "updatedb-force": "node utils/updatedb.js force",
58
- "version": "node test/version.js"
59
- },
60
- "dependencies": {
61
- "adm-zip": "^0.5.10",
62
- "async": "^3.2.4",
63
- "chalk": "4.1.2",
64
- "iconv-lite": "0.6.3",
65
- "ip-address": "^8.1.0",
66
- "lazy": "1.0.11",
67
- "rimraf": "^5.0.1"
68
- },
69
- "devDependencies": {
70
- "eslint": "^8.49.0",
71
- "jest": "^29.7.0",
72
- "terser": "^5.19.4"
73
- },
74
- "engines": {
75
- "node": ">=5.10.0"
76
- }
77
- }
1
+ {
2
+ "name": "geoip-lite2",
3
+ "version": "2.1.8",
4
+ "description": "A light weight native JavaScript implementation of GeoIP API from MaxMind.",
5
+ "keywords": [
6
+ "city",
7
+ "country",
8
+ "fast-geoip",
9
+ "geo",
10
+ "geoip",
11
+ "geoip-api",
12
+ "geolite",
13
+ "geolite2",
14
+ "geolocation",
15
+ "geolookup",
16
+ "ip",
17
+ "ipv4",
18
+ "ipv6",
19
+ "location",
20
+ "maxmind",
21
+ "region",
22
+ "state"
23
+ ],
24
+ "homepage": "https://github.com/sefinek24/geoip-lite2#readme",
25
+ "bugs": {
26
+ "url": "https://github.com/sefinek24/geoip-lite2/issues"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/sefinek24/geoip-lite2.git"
31
+ },
32
+ "license": "Apache-2.0",
33
+ "author": "Philip Tellis <philip@bluesmoon.info> (https://bluesmoon.info)",
34
+ "main": "lib/geoip.js",
35
+ "types": "index.d.ts",
36
+ "directories": {
37
+ "lib": "lib",
38
+ "test": "test"
39
+ },
40
+ "files": [
41
+ "data/",
42
+ "lib/",
43
+ "test/",
44
+ "utils/",
45
+ ".gitignore",
46
+ "AUTHORS",
47
+ "index.d.ts",
48
+ "LICENSE"
49
+ ],
50
+ "scripts": {
51
+ "minify-linux": "echo \"Please wait...\n\" && bash _Minify/linux.bash",
52
+ "minify-win": "powershell.exe -ExecutionPolicy Bypass .\\_Minify\\windows.ps1",
53
+ "test": "jest test",
54
+ "up": "ncu -u -x chalk && npm install && npm update && npm audit fix",
55
+ "updatedb": "node utils/updatedb.js",
56
+ "updatedb-debug": "node utils/updatedb.js debug",
57
+ "updatedb-force": "node utils/updatedb.js force",
58
+ "version": "node test/version.js"
59
+ },
60
+ "dependencies": {
61
+ "adm-zip": "^0.5.10",
62
+ "async": "^3.2.4",
63
+ "chalk": "4.1.2",
64
+ "iconv-lite": "0.6.3",
65
+ "ip-address": "^8.1.0",
66
+ "lazy": "1.0.11",
67
+ "rimraf": "^5.0.1"
68
+ },
69
+ "devDependencies": {
70
+ "eslint": "^8.50.0",
71
+ "jest": "^29.7.0",
72
+ "terser": "^5.20.0"
73
+ },
74
+ "engines": {
75
+ "node": ">=5.10.0"
76
+ }
77
+ }
package/utils/updatedb.js CHANGED
@@ -1 +1 @@
1
- 'use strict';const{name:e,version:t}=require('../package.json'),n=`Mozilla/5.0 (compatible; ${e}/${t}; +https://sefinek.net)`,o=require('node:fs'),r=require('node:http'),s=require('node:https'),i=require('node:path'),c=require('node:url'),l=require('node:zlib');o.existsSync=o.existsSync||i.existsSync;const a=require('async'),u=require('chalk'),d=require('iconv-lite'),p=require('lazy'),f=require('rimraf').sync,g=require('adm-zip'),m=require('../lib/utils.js'),{Address6:h,Address4:w}=require('ip-address'),y=process.argv.slice(2);let S=y.find((function(e){return null!==e.match(/^license_key=[a-zA-Z0-9]+/)}));void 0===S&&void 0!==process.env.LICENSE_KEY&&(S='license_key='+process.env.LICENSE_KEY);let v=y.find((function(e){return null!==e.match(/^geoDataDir=[\w./]+/)}));void 0===v&&void 0!==process.env.GEODATADIR&&(v='geoDataDir='+process.env.GEODATADIR);let x=i.resolve(__dirname,'..','data');void 0!==v&&(x=i.resolve(process.cwd(),v.split('=')[1]),o.existsSync(x)||(console.log(u.red('ERROR')+': Directory doesn\'t exist: '+x),process.exit(1)));const E=i.resolve(__dirname,'..','tmp'),k={},I={},D=[{type:'country',url:'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&suffix=zip&'+S,checksum:'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&suffix=zip.sha256&'+S,fileName:'GeoLite2-Country-CSV.zip',src:['GeoLite2-Country-Locations-en.csv','GeoLite2-Country-Blocks-IPv4.csv','GeoLite2-Country-Blocks-IPv6.csv'],dest:['','geoip-country.dat','geoip-country6.dat']},{type:'city',url:'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&suffix=zip&'+S,checksum:'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&suffix=zip.sha256&'+S,fileName:'GeoLite2-City-CSV.zip',src:['GeoLite2-City-Locations-en.csv','GeoLite2-City-Blocks-IPv4.csv','GeoLite2-City-Blocks-IPv6.csv'],dest:['geoip-city-names.dat','geoip-city.dat','geoip-city6.dat']}];function C(e){const t=i.dirname(e);o.existsSync(t)||o.mkdirSync(t)}function R(e){const t=/^\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*(?:,\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*)*$/;if(!t.test(e)&&(e=function(e){let t=0,n=-1;for(e=e.replace(/""/,'\\"').replace(/'/g,'\\\'');t<e.length&&n<e.length;)t=n,n=e.indexOf(',',t+1),n<0&&(n=e.length),e.indexOf('\'',t||0)>-1&&e.indexOf('\'',t)<n&&'"'!=e[t+1]&&'"'!=e[n-1]&&(n=(e=e.substr(0,t+1)+'"'+e.substr(t+1,n-t-1)+'"'+e.substr(n,e.length-n)).indexOf(',',n+1),n<0&&(n=e.length));return e}(e),!t.test(e)))return null;const n=[];return e.replace(/(?!\s*$)\s*(?:'([^'\\]*(?:\\[\S\s][^'\\]*)*)'|"([^"\\]*(?:\\[\S\s][^"\\]*)*)"|([^,'"\s\\]*(?:\s+[^,'"\s\\]+)*))\s*(?:,|$)/g,(function(e,t,o,r){return void 0!==t?n.push(t.replace(/\\'/g,'\'')):void 0!==o?n.push(o.replace(/\\"/g,'"').replace(/\\'/g,'\'')):void 0!==r&&n.push(r),''})),/,\s*$/.test(e)&&n.push(''),n}function B(e){const t=c.parse(e);if(t.headers={'User-Agent':n},process.env.http_proxy||process.env.https_proxy)try{const e=require('node:https-proxy-agent');t.agent=new e(process.env.http_proxy||process.env.https_proxy)}catch(e){console.error('Install https-proxy-agent to use an HTTP/HTTPS proxy'),process.exit(-1)}return t}function b(e,t){if(-1!==y.indexOf('force'))return t(null,e);const n=e.checksum;if(void 0===n)return t(null,e);o.readFile(i.join(x,e.type+'.checksum'),{encoding:'utf8'},(function(o,i){!o&&i&&i.length&&(e.checkValue=i),console.log('Checking ',e.fileName);var c=s.get(B(n),(function(n){const o=n.statusCode;200!==o&&(console.log(u.red('ERROR')+n.data),console.log(u.red('ERROR')+': HTTP Request Failed [%d %s]',o,r.STATUS_CODES[o]),c.abort(),process.exit(1));let s='';n.on('data',(function(e){s+=e})),n.on('end',(()=>{s&&s.length?s==e.checkValue?(console.log(u.green('Database "'+e.type+'" is up to date')),e.skip=!0):(console.log(u.green('Database '+e.type+' has new data')),e.checkValue=s):(console.log(u.red('ERROR')+': Could not retrieve checksum for',e.type,u.red('Aborting')),console.log('Run with "force" to update without checksum'),c.abort(),process.exit(1)),t(null,e)}))}))}))}function _(e,t){if(e.skip)return t(null,null,null,e);const n=e.url;let c=e.fileName;const a='.gz'===i.extname(c);a&&(c=c.replace('.gz',''));const d=i.join(E,c);if(o.existsSync(d))return t(null,d,c,e);console.log('Fetching ',c),C(d);var p=s.get(B(n),(function(n){const s=n.statusCode;let i;200!==s&&(console.error(u.red('ERROR')+': HTTP Request Failed [%d %s]',s,r.STATUS_CODES[s]),p.abort(),process.exit(1));const f=o.createWriteStream(d);i=a?n.pipe(l.createGunzip()).pipe(f):n.pipe(f),i.on('close',(()=>{console.log(u.green(' DONE')),t(null,d,c,e)}))}));process.stdout.write('Retrieving '+c+'...')}function A(e,t,n,r){if(n.skip)return r(null,n);if('.zip'!==i.extname(t))r(null,n);else{process.stdout.write('Extracting '+t+'...');new g(e).getEntries().forEach((e=>{if(e.isDirectory)return;const t=e.entryName.split('/'),n=t[t.length-1],r=i.join(E,n);o.writeFileSync(r,e.getData())})),console.log(u.green(' DONE')),r(null,n)}}function O(e,t,n){let r=0;const s=i.join(x,t),c=i.join(E,e);f(s),C(s),process.stdout.write('Processing data (may take a moment)...');var l=Date.now(),a=o.openSync(s,'w');p(o.createReadStream(c)).lines.map((function(e){return d.decode(e,'latin1')})).skip(1).map((function(e){const t=R(e);if(!t||t.length<6)return void console.warn('weird line: %s::',e);let n,s,i;r++;const c=k[t[1]];let u,d,p;if(c){if(t[0].match(/:/)){for(d=34,i=new h(t[0]),n=m.aton6(i.startAddress().correctForm()),s=m.aton6(i.endAddress().correctForm()),u=Buffer.alloc(d),p=0;p<n.length;p++)u.writeUInt32BE(n[p],4*p);for(p=0;p<s.length;p++)u.writeUInt32BE(s[p],16+4*p)}else d=10,i=new w(t[0]),n=parseInt(i.startAddress().bigInteger(),10),s=parseInt(i.endAddress().bigInteger(),10),u=Buffer.alloc(d),u.fill(0),u.writeUInt32BE(n,0),u.writeUInt32BE(s,4);u.write(c,d-2),o.writeSync(a,u,0,d,null),Date.now()-l>5e3&&(l=Date.now(),process.stdout.write('\nStill working ('+r+')...'))}})).on('pipe',(()=>{console.log(u.green(' DONE')),n()}))}function q(e,t,n){let r=0;const s=i.join(x,t),c=i.join(E,e);f(s),process.stdout.write('Processing Data (may take a moment) ...');var l=Date.now(),a=o.openSync(s,'w');p(o.createReadStream(c)).lines.map((function(e){return d.decode(e,'latin1')})).skip(1).map((function(e){if(e.match(/^Copyright/)||!e.match(/\d/))return;const t=R(e);if(!t)return void console.warn('weird line: %s::',e);let n,s,i,c,u,d,p,f,g,y;if(r++,t[0].match(/:/)){let e=0;for(d=48,i=new h(t[0]),n=m.aton6(i.startAddress().correctForm()),s=m.aton6(i.endAddress().correctForm()),c=parseInt(t[1],10),c=I[c],u=Buffer.alloc(d),u.fill(0),y=0;y<n.length;y++)u.writeUInt32BE(n[y],e),e+=4;for(y=0;y<s.length;y++)u.writeUInt32BE(s[y],e),e+=4;u.writeUInt32BE(c>>>0,32),p=Math.round(1e4*parseFloat(t[7])),f=Math.round(1e4*parseFloat(t[8])),g=parseInt(t[9],10),u.writeInt32BE(p,36),u.writeInt32BE(f,40),u.writeInt32BE(g,44)}else d=24,i=new w(t[0]),n=parseInt(i.startAddress().bigInteger(),10),s=parseInt(i.endAddress().bigInteger(),10),c=parseInt(t[1],10),c=I[c],u=Buffer.alloc(d),u.fill(0),u.writeUInt32BE(n>>>0,0),u.writeUInt32BE(s>>>0,4),u.writeUInt32BE(c>>>0,8),p=Math.round(1e4*parseFloat(t[7])),f=Math.round(1e4*parseFloat(t[8])),g=parseInt(t[9],10),u.writeInt32BE(p,12),u.writeInt32BE(f,16),u.writeInt32BE(g,20);o.writeSync(a,u,0,u.length,null),Date.now()-l>5e3&&(l=Date.now(),process.stdout.write('\nStill working ('+r+')...'))})).on('pipe',n)}function L(e,t){if(e.skip)return t(null,e);const n=e.type,r=e.src,s=e.dest;'country'===n?Array.isArray(r)?function(e,t){const n=i.join(E,e);process.stdout.write('Processing Lookup Data (may take a moment)...'),p(o.createReadStream(n)).lines.map((function(e){return d.decode(e,'latin1')})).skip(1).map((function(e){const t=R(e);!t||t.length<6?console.log('weird line: %s::',e):k[t[0]]=t[4]})).on('pipe',(()=>{console.log(u.green(' DONE')),t()}))}(r[0],(()=>{O(r[1],s[1],(()=>{O(r[2],s[2],(()=>{t(null,e)}))}))})):O(r,s,(()=>{t(null,e)})):'city'===n&&function(e,t,n){let r=null,s=0;const c=i.join(x,t),l=i.join(E,e);f(c);var a=o.openSync(c,'w');p(o.createReadStream(l)).lines.map((function(e){return d.decode(e,'utf-8')})).skip(1).map((function(e){if(e.match(/^Copyright/)||!e.match(/\d/))return;const t=Buffer.alloc(88),n=R(e);if(!n)return void console.warn('weird line: %s::',e);r=parseInt(n[0]),I[r]=s;const i=n[4],c=n[6],l=n[10],u=parseInt(n[11]),d=n[12],p=n[13];t.fill(0),t.write(i,0),t.write(c,2),u&&t.writeInt32BE(u,5),t.write(p,9),t.write(d,10),t.write(l,42),o.writeSync(a,t,0,t.length,null),s++})).on('pipe',n)}(r[0],s[0],(()=>{q(r[1],s[1],(()=>{console.log('city data processed'),q(r[2],s[2],(()=>{console.log(u.green(' DONE')),t(null,e)}))}))}))}function F(e,t){if(e.skip||!e.checkValue)return t();o.writeFile(i.join(x,e.type+'.checksum'),e.checkValue,'utf8',(function(n){n&&console.log(u.red('Failed to Update checksums.'),'Database:',e.type),t()}))}S||(console.error(u.red('ERROR')+': Missing license_key'),process.exit(1)),f(E),C(E),a.eachSeries(D,(function(e,t){a.seq(b,_,A,L,F)(e,t)}),(function(e){e?(console.error(u.red('Failed to update databases from MaxMind.'),e),process.exit(1)):(console.log(u.green('Successfully updated databases from MaxMind.')),-1!==y.indexOf('debug')?console.debug(u.yellow.bold('Notice: temporary files are not deleted for debug purposes.')):f(E),process.exit(0))}));
1
+ 'use strict';const{name:e,version:t}=require('../package.json'),n=`Mozilla/5.0 (compatible; ${e}/${t}; +https://sefinek.net)`,o=require('node:fs'),r=require('node:http'),s=require('node:https'),i=require('node:path'),c=require('node:url'),a=require('node:zlib');o.existsSync=o.existsSync||i.existsSync;const l=require('async'),d=require('chalk'),u=require('iconv-lite'),p=require('lazy'),f=require('rimraf').sync,g=require('adm-zip'),m=require('../lib/utils.js'),{Address6:h,Address4:y}=require('ip-address'),w=process.argv.slice(2);let S=w.find((function(e){return null!==e.match(/^license_key=[a-zA-Z0-9]+/)}));void 0===S&&void 0!==process.env.LICENSE_KEY&&(S='license_key='+process.env.LICENSE_KEY);let v=w.find((function(e){return null!==e.match(/^geoDataDir=[\w./]+/)}));void 0===v&&void 0!==process.env.GEODATADIR&&(v='geoDataDir='+process.env.GEODATADIR);let x=i.resolve(__dirname,'..','data');void 0!==v&&(x=i.resolve(process.cwd(),v.split('=')[1]),o.existsSync(x)||(console.log(d.red('ERROR')+': Directory doesn\'t exist: '+x),process.exit(1)));const E=i.resolve(__dirname,'..','tmp'),k={},I={},C=[{type:'country',url:'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&suffix=zip&'+S,checksum:'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&suffix=zip.sha256&'+S,fileName:'GeoLite2-Country-CSV.zip',src:['GeoLite2-Country-Locations-en.csv','GeoLite2-Country-Blocks-IPv4.csv','GeoLite2-Country-Blocks-IPv6.csv'],dest:['','geoip-country.dat','geoip-country6.dat']},{type:'city',url:'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&suffix=zip&'+S,checksum:'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&suffix=zip.sha256&'+S,fileName:'GeoLite2-City-CSV.zip',src:['GeoLite2-City-Locations-en.csv','GeoLite2-City-Blocks-IPv4.csv','GeoLite2-City-Blocks-IPv6.csv'],dest:['geoip-city-names.dat','geoip-city.dat','geoip-city6.dat']}];function D(e){const t=i.dirname(e);o.existsSync(t)||o.mkdirSync(t)}function R(e){const t=/^\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*(?:,\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*)*$/;if(!t.test(e)&&(e=function(e){let t=0,n=-1;for(e=e.replace(/""/,'\\"').replace(/'/g,'\\\'');t<e.length&&n<e.length;)t=n,n=e.indexOf(',',t+1),n<0&&(n=e.length),e.indexOf('\'',t||0)>-1&&e.indexOf('\'',t)<n&&'"'!=e[t+1]&&'"'!=e[n-1]&&(n=(e=e.substr(0,t+1)+'"'+e.substr(t+1,n-t-1)+'"'+e.substr(n,e.length-n)).indexOf(',',n+1),n<0&&(n=e.length));return e}(e),!t.test(e)))return null;const n=[];return e.replace(/(?!\s*$)\s*(?:'([^'\\]*(?:\\[\S\s][^'\\]*)*)'|"([^"\\]*(?:\\[\S\s][^"\\]*)*)"|([^,'"\s\\]*(?:\s+[^,'"\s\\]+)*))\s*(?:,|$)/g,(function(e,t,o,r){return void 0!==t?n.push(t.replace(/\\'/g,'\'')):void 0!==o?n.push(o.replace(/\\"/g,'"').replace(/\\'/g,'\'')):void 0!==r&&n.push(r),''})),/,\s*$/.test(e)&&n.push(''),n}function B(e){const t=c.parse(e);if(t.headers={'User-Agent':n},process.env.http_proxy||process.env.https_proxy)try{const e=require('node:https-proxy-agent');t.agent=new e(process.env.http_proxy||process.env.https_proxy)}catch(e){console.error('Install https-proxy-agent to use an HTTP/HTTPS proxy'),process.exit(-1)}return t}function _(e,t){if(-1!==w.indexOf('force'))return t(null,e);const n=e.checksum;if(void 0===n)return t(null,e);o.readFile(i.join(x,e.type+'.checksum'),{encoding:'utf8'},(function(o,i){!o&&i&&i.length&&(e.checkValue=i),console.log('Checking ',e.fileName);var c=s.get(B(n),(function(n){const o=n.statusCode;200!==o&&(console.error(d.red('ERROR')+n.data),console.error(d.red('ERROR')+': HTTP Request Failed [%d %s]',o,r.STATUS_CODES[o]),c.end(),process.exit(1));let s='';n.on('data',(function(e){s+=e})),n.on('end',(()=>{s&&s.length?s===e.checkValue?(console.log(d.green('Database "'+e.type+'" is up to date')),e.skip=!0):(console.log(d.green('Database '+e.type+' has new data')),e.checkValue=s):(console.error(d.red('ERROR')+': Could not retrieve checksum for',e.type,d.red('Aborting')),console.error('Run with "force" to update without checksum'),c.end(),process.exit(1)),t(null,e)}))}))}))}function b(e,t){if(e.skip)return t(null,null,null,e);const n=e.url;let c=e.fileName;const l='.gz'===i.extname(c);l&&(c=c.replace('.gz',''));const u=i.join(E,c);if(o.existsSync(u))return t(null,u,c,e);console.log('Fetching ',c),D(u);var p=s.get(B(n),(function(n){const s=n.statusCode;let i;200!==s&&(console.error(d.red('ERROR')+': HTTP Request Failed [%d %s]',s,r.STATUS_CODES[s]),p.end(),process.exit(1));const f=o.createWriteStream(u);i=l?n.pipe(a.createGunzip()).pipe(f):n.pipe(f),i.on('close',(()=>{console.log(d.green(' DONE')),t(null,u,c,e)}))}));process.stdout.write('Retrieving '+c+'...')}function A(e,t,n,r){if(n.skip)return r(null,n);if('.zip'!==i.extname(t))r(null,n);else{process.stdout.write('Extracting '+t+'...');new g(e).getEntries().forEach((e=>{if(e.isDirectory)return;const t=e.entryName.split('/'),n=t[t.length-1],r=i.join(E,n);o.writeFileSync(r,e.getData())})),console.log(d.green(' DONE')),r(null,n)}}function O(e,t,n){let r=0;const s=i.join(x,t),c=i.join(E,e);f(s),D(s),process.stdout.write('Processing data (may take a moment)...');var a=Date.now(),l=o.openSync(s,'w');p(o.createReadStream(c)).lines.map((e=>u.decode(e,'latin1'))).skip(1).map((function(e){const t=R(e);if(!t||t.length<6)return void console.warn('weird line: %s::',e);let n,s,i;r++;const c=k[t[1]];let d,u,p;if(c){if(t[0].match(/:/)){for(u=34,i=new h(t[0]),n=m.aton6(i.startAddress().correctForm()),s=m.aton6(i.endAddress().correctForm()),d=Buffer.alloc(u),p=0;p<n.length;p++)d.writeUInt32BE(n[p],4*p);for(p=0;p<s.length;p++)d.writeUInt32BE(s[p],16+4*p)}else u=10,i=new y(t[0]),n=parseInt(i.startAddress().bigInteger(),10),s=parseInt(i.endAddress().bigInteger(),10),d=Buffer.alloc(u),d.fill(0),d.writeUInt32BE(n,0),d.writeUInt32BE(s,4);d.write(c,u-2),o.writeSync(l,d,0,u,null),Date.now()-a>5e3&&(a=Date.now(),process.stdout.write('\nStill working ('+r+')...'))}})).on('pipe',(()=>{console.log(d.green(' DONE')),n()}))}function q(e,t,n){let r=0;const s=i.join(x,t),c=i.join(E,e);f(s),process.stdout.write('Processing data (may take a moment) ...');var a=Date.now(),l=o.openSync(s,'w');p(o.createReadStream(c)).lines.map((e=>u.decode(e,'latin1'))).skip(1).map((function(e){if(e.match(/^Copyright/)||!e.match(/\d/))return;const t=R(e);if(!t)return void console.warn('Weird line: %s::',e);let n,s,i,c,d,u,p,f,g,w;if(r++,t[0].match(/:/)){let e=0;for(u=48,i=new h(t[0]),n=m.aton6(i.startAddress().correctForm()),s=m.aton6(i.endAddress().correctForm()),c=parseInt(t[1],10),c=I[c],d=Buffer.alloc(u),d.fill(0),w=0;w<n.length;w++)d.writeUInt32BE(n[w],e),e+=4;for(w=0;w<s.length;w++)d.writeUInt32BE(s[w],e),e+=4;d.writeUInt32BE(c>>>0,32),p=Math.round(1e4*parseFloat(t[7])),f=Math.round(1e4*parseFloat(t[8])),g=parseInt(t[9],10),d.writeInt32BE(p,36),d.writeInt32BE(f,40),d.writeInt32BE(g,44)}else u=24,i=new y(t[0]),n=parseInt(i.startAddress().bigInteger(),10),s=parseInt(i.endAddress().bigInteger(),10),c=parseInt(t[1],10),c=I[c],d=Buffer.alloc(u),d.fill(0),d.writeUInt32BE(n>>>0,0),d.writeUInt32BE(s>>>0,4),d.writeUInt32BE(c>>>0,8),p=Math.round(1e4*parseFloat(t[7])),f=Math.round(1e4*parseFloat(t[8])),g=parseInt(t[9],10),d.writeInt32BE(p,12),d.writeInt32BE(f,16),d.writeInt32BE(g,20);o.writeSync(l,d,0,d.length,null),Date.now()-a>5e3&&(a=Date.now(),process.stdout.write('\nStill working ('+r+')...'))})).on('pipe',n)}function L(e,t){if(e.skip)return t(null,e);const n=e.type,r=e.src,s=e.dest;'country'===n?Array.isArray(r)?function(e,t){const n=i.join(E,e);process.stdout.write('Processing Lookup Data (may take a moment)...'),p(o.createReadStream(n)).lines.map((e=>u.decode(e,'latin1'))).skip(1).map((function(e){const t=R(e);!t||t.length<6?console.log('weird line: %s::',e):k[t[0]]=t[4]})).on('pipe',(()=>{console.log(d.green(' DONE')),t()}))}(r[0],(()=>{O(r[1],s[1],(()=>{O(r[2],s[2],(()=>{t(null,e)}))}))})):O(r,s,(()=>{t(null,e)})):'city'===n&&function(e,t,n){let r=null,s=0;const c=i.join(x,t),a=i.join(E,e);f(c);var l=o.openSync(c,'w');p(o.createReadStream(a)).lines.map((e=>u.decode(e,'utf-8'))).skip(1).map((function(e){if(e.match(/^Copyright/)||!e.match(/\d/))return;const t=Buffer.alloc(88),n=R(e);if(!n)return void console.warn('Weird line: %s::',e);r=parseInt(n[0]),I[r]=s;const i=n[4],c=n[6],a=n[10],d=parseInt(n[11]),u=n[12],p=n[13];t.fill(0),t.write(i,0),t.write(c,2),d&&t.writeInt32BE(d,5),t.write(p,9),t.write(u,10),t.write(a,42),o.writeSync(l,t,0,t.length,null),s++})).on('pipe',n)}(r[0],s[0],(()=>{q(r[1],s[1],(()=>{console.log('city data processed'),q(r[2],s[2],(()=>{console.log(d.green(' DONE')),t(null,e)}))}))}))}function F(e,t){if(e.skip||!e.checkValue)return t();o.writeFile(i.join(x,e.type+'.checksum'),e.checkValue,'utf8',(function(n){n&&console.log(d.red('Failed to Update checksums.'),'Database:',e.type),t()}))}S||(console.error(d.red('ERROR')+': Missing license_key'),process.exit(1)),D(E),l.eachSeries(C,((e,t)=>{l.seq(_,b,A,L,F)(e,t)}),(e=>{e?(console.error(d.red('Failed to update databases from MaxMind.'),e),process.exit(1)):(console.log(d.green('Successfully updated databases from MaxMind.')),-1!==w.indexOf('debug')?console.debug(d.blue.bold('Notice: temporary files are not deleted for debug purposes.')):f(E),process.exit(0))}));