Compare commits
31 Commits
Author | SHA1 | Date | |
---|---|---|---|
cc0f1c40a6 | |||
9da04081e4 | |||
4ae0925043 | |||
4e862e784b | |||
cf8abfd4f0 | |||
93c4488b9b | |||
39493465c6 | |||
cab696e45b | |||
67682892ae | |||
5c13987686 | |||
97841e0973 | |||
c8ccde9d84 | |||
654a4c6b54 | |||
12b8793c19 | |||
24e861e5b4 | |||
c7d2b2c031 | |||
f08713bb45 | |||
ad0fa8c65a | |||
88a9bfc20d | |||
0248d6f253 | |||
8d1b302e70 | |||
34bee225d5 | |||
ccece078a2 | |||
a04151e537 | |||
d71346e763 | |||
817894b6ce | |||
bba219ddef | |||
9af53a5b58 | |||
4fcdeb8c3d | |||
5c7d2de902 | |||
f105cdc806 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,8 +15,6 @@ node_modules/
|
|||||||
|
|
||||||
# builds
|
# builds
|
||||||
dist/
|
dist/
|
||||||
dist_web/
|
dist_*/
|
||||||
dist_serve/
|
|
||||||
dist_ts_web/
|
|
||||||
|
|
||||||
# custom
|
# custom
|
102
.gitlab-ci.yml
102
.gitlab-ci.yml
@ -3,14 +3,14 @@ image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
@ -18,21 +18,36 @@ stages:
|
|||||||
mirror:
|
mirror:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
- npmci command npm install --production --ignore-scripts
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command snyk test
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
auditDevDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
@ -41,37 +56,36 @@ snyk:
|
|||||||
testStable:
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- priv
|
|
||||||
|
|
||||||
testBuild:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command npm run build
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# metadata stage
|
# metadata stage
|
||||||
@ -79,35 +93,39 @@ release:
|
|||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g tslint typescript
|
||||||
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- priv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-dbase:npmci
|
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
|
- npmci node install lts
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
@ -115,5 +133,5 @@ pages:
|
|||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
4
.snyk
Normal file
4
.snyk
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
||||||
|
version: v1.13.5
|
||||||
|
ignore: {}
|
||||||
|
patch: {}
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "current file",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"${relativeFile}"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "test.ts",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"test/test.ts"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"json.schemas": [
|
||||||
|
{
|
||||||
|
"fileMatch": ["/npmextra.json"],
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"npmci": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for npmci"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for gitzone",
|
||||||
|
"properties": {
|
||||||
|
"projectType": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -4,6 +4,7 @@
|
|||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
},
|
},
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
|
13080
package-lock.json
generated
13080
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
46
package.json
46
package.json
@ -1,41 +1,45 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartnetwork",
|
"name": "@pushrocks/smartnetwork",
|
||||||
"version": "1.1.7",
|
"version": "2.0.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "network diagnostics",
|
"description": "network diagnostics",
|
||||||
"main": "dist/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.17",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
"@gitzone/tstest": "^1.0.24",
|
"@gitzone/tstest": "^1.0.52",
|
||||||
"@pushrocks/tapbundle": "^3.0.13",
|
"@pushrocks/tapbundle": "^3.2.14",
|
||||||
"tslint": "^5.19.0",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@pushrocks/smartpromise": "^3.1.3",
|
||||||
"@pushrocks/smartstring": "^3.0.10",
|
"@pushrocks/smartstring": "^3.0.24",
|
||||||
"@types/default-gateway": "^3.0.0",
|
"@types/default-gateway": "^3.0.1",
|
||||||
"@types/portscanner": "^2.1.0",
|
"isopen": "^1.3.0",
|
||||||
"default-gateway": "^5.0.3",
|
"public-ip": "^4.0.3",
|
||||||
"portscanner": "^2.2.0",
|
"speedtest-net": "^2.1.1",
|
||||||
"speedtest-net": "^1.5.1"
|
"systeminformation": "^5.6.12"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/*",
|
"ts/**/*",
|
||||||
"ts_web/*",
|
"ts_web/**/*",
|
||||||
"dist/*",
|
"dist/**/*",
|
||||||
"dist_web/*",
|
"dist_*/**/*",
|
||||||
"dist_ts_web/*",
|
"dist_ts/**/*",
|
||||||
"assets/*",
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
25
readme.md
25
readme.md
@ -8,13 +8,20 @@ network diagnostics
|
|||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartnetwork/)
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartnetwork/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
[](https://gitlab.com/pushrocks/smartnetwork/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/smartnetwork/commits/master)
|
Status Category | Status Badge
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartnetwork)
|
-- | --
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smartnetwork)
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
npm | [](https://lossless.cloud)
|
||||||
[](https://prettier.io/)
|
Snyk | [](https://lossless.cloud)
|
||||||
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
Code Style | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
|
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -38,6 +45,10 @@ const run = async () => {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
14
test/test.ts
14
test/test.ts
@ -24,9 +24,19 @@ tap.test('should scan a port', async () => {
|
|||||||
// await expect(testSmartNetwork.isRemotePortAvailable('lossless.com:444')).to.eventually.be.false;
|
// await expect(testSmartNetwork.isRemotePortAvailable('lossless.com:444')).to.eventually.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should get the default gateways', async () => {
|
tap.test('should get gateways', async () => {
|
||||||
|
const gatewayResult = await testSmartNetwork.getGateways();
|
||||||
|
console.log(gatewayResult);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should get the default gateway', async () => {
|
||||||
const gatewayResult = await testSmartNetwork.getDefaultGateway();
|
const gatewayResult = await testSmartNetwork.getDefaultGateway();
|
||||||
console.log(gatewayResult);
|
console.log(gatewayResult);
|
||||||
})
|
});
|
||||||
|
|
||||||
|
tap.test('should get public ips', async () => {
|
||||||
|
const ips = await testSmartNetwork.getPublicIps();
|
||||||
|
console.log(ips);
|
||||||
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -43,10 +43,10 @@ export class SmartNetwork {
|
|||||||
public async getSpeed(measurementTime = 5000): Promise<ISpeedtestData> {
|
public async getSpeed(measurementTime = 5000): Promise<ISpeedtestData> {
|
||||||
const done = plugins.smartpromise.defer<ISpeedtestData>();
|
const done = plugins.smartpromise.defer<ISpeedtestData>();
|
||||||
const test = plugins.speedtestNet({ maxTime: measurementTime });
|
const test = plugins.speedtestNet({ maxTime: measurementTime });
|
||||||
test.on('data', data => {
|
test.on('data', (data) => {
|
||||||
done.resolve(data);
|
done.resolve(data);
|
||||||
});
|
});
|
||||||
test.on('error', err => {
|
test.on('error', (err) => {
|
||||||
done.reject(err);
|
done.reject(err);
|
||||||
});
|
});
|
||||||
return await done.promise;
|
return await done.promise;
|
||||||
@ -83,7 +83,7 @@ export class SmartNetwork {
|
|||||||
|
|
||||||
// test IPv6 space
|
// test IPv6 space
|
||||||
const ipv6Test = net.createServer();
|
const ipv6Test = net.createServer();
|
||||||
ipv6Test.once('error', function(err: any) {
|
ipv6Test.once('error', function (err: any) {
|
||||||
if (err.code !== 'EADDRINUSE') {
|
if (err.code !== 'EADDRINUSE') {
|
||||||
doneIpV6.resolve(false);
|
doneIpV6.resolve(false);
|
||||||
return;
|
return;
|
||||||
@ -114,12 +114,9 @@ export class SmartNetwork {
|
|||||||
const domainPart = domainArg.split(':')[0];
|
const domainPart = domainArg.split(':')[0];
|
||||||
const port = portArg ? portArg : parseInt(domainArg.split(':')[1], 10);
|
const port = portArg ? portArg : parseInt(domainArg.split(':')[1], 10);
|
||||||
|
|
||||||
plugins.portscanner.checkPortStatus(port, domainPart, (err, status) => {
|
plugins.isopen(domainPart, port, (response) => {
|
||||||
if (err) {
|
console.log(response);
|
||||||
// console.log(err);
|
if (response[port.toString()].isOpen) {
|
||||||
return done.resolve(false);
|
|
||||||
}
|
|
||||||
if (status === 'open') {
|
|
||||||
done.resolve(true);
|
done.resolve(true);
|
||||||
} else {
|
} else {
|
||||||
done.resolve(false);
|
done.resolve(false);
|
||||||
@ -129,11 +126,34 @@ export class SmartNetwork {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getDefaultGateway() {
|
public async getGateways() {
|
||||||
const result = {
|
const result = plugins.os.networkInterfaces();
|
||||||
v4: await plugins.defaultGateway.v4(),
|
|
||||||
v6: await plugins.defaultGateway.v6()
|
|
||||||
};
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getDefaultGateway(): Promise<{
|
||||||
|
ipv4: plugins.os.NetworkInterfaceInfo;
|
||||||
|
ipv6: plugins.os.NetworkInterfaceInfo;
|
||||||
|
}> {
|
||||||
|
const defaultGatewayName = await plugins.systeminformation.networkInterfaceDefault();
|
||||||
|
if (!defaultGatewayName) {
|
||||||
|
console.log('Cannot determine default gateway');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const gateways = await this.getGateways();
|
||||||
|
const defaultGateway = gateways[defaultGatewayName];
|
||||||
|
return {
|
||||||
|
ipv4: defaultGateway[0],
|
||||||
|
ipv6: defaultGateway[1],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getPublicIps() {
|
||||||
|
return {
|
||||||
|
v4: await plugins.publicIp.v4({
|
||||||
|
timeout: 1000,
|
||||||
|
onlyHttps: true,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
// native scope
|
// native scope
|
||||||
|
import * as os from 'os';
|
||||||
|
|
||||||
|
export { os };
|
||||||
|
|
||||||
// @pushrocks scope
|
// @pushrocks scope
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
@ -7,8 +10,9 @@ import * as smartstring from '@pushrocks/smartstring';
|
|||||||
export { smartpromise, smartstring };
|
export { smartpromise, smartstring };
|
||||||
|
|
||||||
// @third party scope
|
// @third party scope
|
||||||
import defaultGateway from 'default-gateway';
|
import isopen from 'isopen';
|
||||||
const speedtestNet = require('speedtest-net');
|
import publicIp from 'public-ip';
|
||||||
import * as portscanner from 'portscanner';
|
import speedtestNet from 'speedtest-net';
|
||||||
|
import * as systeminformation from 'systeminformation';
|
||||||
|
|
||||||
export { defaultGateway, speedtestNet, portscanner };
|
export { isopen, publicIp, speedtestNet, systeminformation };
|
||||||
|
Reference in New Issue
Block a user