Initial commit

This commit is contained in:
2021-08-26 21:47:42 +02:00
commit fe941c6433
1432 changed files with 161130 additions and 0 deletions

113
node_modules/ping/lib/builder/factory.js generated vendored Normal file
View File

@ -0,0 +1,113 @@
'use strict';
var __ = require('underscore');
var util = require('util');
// Our library
var linuxBuilder = require('./linux');
var macBuilder = require('./mac');
var winBuilder = require('./win');
/**
* A factory creates argument builders for different platform
* @constructor
*/
function factory() {}
/**
* Check out linux platform
*/
factory.isLinux = function (p) {
var platforms = [
'aix',
'android',
'linux',
];
return platforms.indexOf(p) >= 0;
};
/**
* Check out macos platform
*/
factory.isMacOS = function (p) {
var platforms = [
'darwin',
'freebsd',
];
return platforms.indexOf(p) >= 0;
};
/**
* Check out window platform
*/
factory.isWindow = function (p) {
return p && p.match(/^win/) !== null;
};
/**
* Check whether given platform is supported
* @param {string} p - Name of the platform
* @return {bool} - True or False
*/
factory.isPlatformSupport = function (p) {
return __.some([
this.isWindow(p),
this.isLinux(p),
this.isMacOS(p),
]);
};
/**
* Return a path to the ping executable in the system
* @param {string} platform - Name of the platform
* @param {bool} v6 - Ping via ipv6 or not
* @return {string} - Executable path for system command ping
* @throw if given platform is not supported
*/
factory.getExecutablePath = function (platform, v6) {
if (!this.isPlatformSupport(platform)) {
throw new Error(util.format('Platform |%s| is not support', platform));
}
var ret = null;
if (platform === 'aix') {
ret = '/usr/sbin/ping';
} else if (factory.isLinux(platform)) {
ret = v6 ? 'ping6' : 'ping';
} else if (factory.isWindow(platform)) {
ret = process.env.SystemRoot + '/system32/ping.exe';
} else if (factory.isMacOS(platform)) {
ret = v6 ? '/sbin/ping6' : '/sbin/ping';
}
return ret;
};
/**
* Create a builder
* @param {string} platform - Name of the platform
* @return {object} - Argument builder
* @throw if given platform is not supported
*/
factory.createBuilder = function (platform) {
if (!this.isPlatformSupport(platform)) {
throw new Error(util.format('Platform |%s| is not support', platform));
}
var ret = null;
if (factory.isLinux(platform)) {
ret = linuxBuilder;
} else if (factory.isWindow(platform)) {
ret = winBuilder;
} else if (factory.isMacOS(platform)) {
ret = macBuilder;
}
return ret;
};
module.exports = factory;

125
node_modules/ping/lib/builder/linux.js generated vendored Normal file
View File

@ -0,0 +1,125 @@
'use strict';
/**
* A builder builds command line arguments for ping in linux environment
* @module lib/builder/linux
*/
var util = require('util');
var builder = {};
/**
* Cross platform config representation
* @typedef {Object} PingConfig
* @property {boolean} numeric - Map IP address to hostname or not
* @property {number} timeout - Time to wait for a response, in seconds.
* The option affects only timeout in absence of any responses,
* otherwise ping waits for two RTTs.
* @property {number} deadline - Specify a timeout, in seconds,
* before ping exits regardless of how many packets have been sent or received.
* In this case ping does not stop after count packet are sent,
* it waits either for deadline expire or until count probes are answered
* or for some error notification from network.
* This option is only available on linux and mac.
* @property {number} min_reply - Exit after sending number of ECHO_REQUEST
* @property {boolean} v6 - Use IPv4 (default) or IPv6
* @property {string} sourceAddr - source address for sending the ping
* @property {number} packetSize - Specifies the number of data bytes to be sent
* Default: Linux / MAC: 56 Bytes,
* Window: 32 Bytes
* @property {string[]} extra - Optional options does not provided
*/
var defaultConfig = {
numeric: true,
timeout: 2,
deadline: false,
min_reply: 1,
v6: false,
sourceAddr: '',
packetSize: 56,
extra: [],
};
/**
* Get the finalized array of command line arguments
* @param {string} target - hostname or ip address
* @param {PingConfig} [config] - Configuration object for cmd line argument
* @return {string[]} - Command line argument according to the configuration
*/
builder.getCommandArguments = function (target, config) {
var _config = config || {};
// Empty argument
var ret = [];
// Make every key in config has been setup properly
var keys = ['numeric', 'timeout', 'deadline', 'min_reply', 'v6',
'sourceAddr', 'extra', 'packetSize'];
keys.forEach(function (k) {
// Falsy value will be overridden without below checking
if (typeof(_config[k]) !== 'boolean') {
_config[k] = _config[k] || defaultConfig[k];
}
});
if (_config.numeric) {
ret.push('-n');
}
if (_config.timeout) {
ret = ret.concat([
'-W',
util.format('%d', _config.timeout),
]);
}
if (_config.deadline) {
ret = ret.concat([
'-w',
util.format('%d', _config.deadline),
]);
}
if (_config.min_reply) {
ret = ret.concat([
'-c',
util.format('%d', _config.min_reply),
]);
}
if (_config.sourceAddr) {
ret = ret.concat([
'-I',
util.format('%s', _config.sourceAddr),
]);
}
if (_config.packetSize) {
ret = ret.concat([
'-s',
util.format('%d', _config.packetSize),
]);
}
if (_config.extra) {
ret = ret.concat(_config.extra);
}
ret.push(target);
return ret;
};
/**
* Compute an option object for child_process.spawn
* @return {object} - Refer to document of child_process.spawn
*/
builder.getSpawnOptions = function () {
return {
shell: false,
env: Object.assign(process.env, {LANG: 'C'}),
};
};
module.exports = builder;

129
node_modules/ping/lib/builder/mac.js generated vendored Normal file
View File

@ -0,0 +1,129 @@
'use strict';
/**
* A builder builds command line arguments for ping in mac environment
* @module lib/builder/mac
*/
var util = require('util');
var builder = {};
/**
* Cross platform config representation
* @typedef {Object} PingConfig
* @property {boolean} numeric - Map IP address to hostname or not
* @property {number} timeout - Time to wait for a response, in seconds.
* The option affects only timeout in absence of any responses,
* otherwise ping waits for two RTTs.
* @property {number} deadline - Specify a timeout, in seconds,
* before ping exits regardless of how many packets have been sent or received.
* In this case ping does not stop after count packet are sent,
* it waits either for deadline expire or until count probes are answered
* or for some error notification from network.
* This option is only available on linux and mac.
* @property {number} min_reply - Exit after sending number of ECHO_REQUEST
* @property {boolean} v6 - Use IPv4 (default) or IPv6
* @property {string} sourceAddr - source address for sending the ping
* @property {number} packetSize - Specifies the number of data bytes to be sent
* Default: Linux / MAC: 56 Bytes,
* Window: 32 Bytes
* @property {string[]} extra - Optional options does not provided
*/
var defaultConfig = {
numeric: true,
timeout: 2,
deadline: false,
min_reply: 1,
v6: false,
sourceAddr: '',
packetSize: 56,
extra: [],
};
/**
* Get the finalized array of command line arguments
* @param {string} target - hostname or ip address
* @param {PingConfig} [config] - Configuration object for cmd line argument
* @return {string[]} - Command line argument according to the configuration
* @throws If there are errors on building arguments with given inputs
*/
builder.getCommandArguments = function (target, config) {
var _config = config || {};
// Empty argument
var ret = [];
// Make every key in config has been setup properly
var keys = ['numeric', 'timeout', 'deadline', 'min_reply', 'v6',
'sourceAddr', 'extra', 'packetSize'];
keys.forEach(function (k) {
// Falsy value will be overridden without below checking
if (typeof(_config[k]) !== 'boolean') {
_config[k] = _config[k] || defaultConfig[k];
}
});
if (_config.numeric) {
ret.push('-n');
}
if (_config.timeout) {
// XXX: There is no timeout option on mac's ping6
if (config.v6) {
throw new Error('There is no timeout option on ping6');
}
ret = ret.concat([
'-W',
util.format('%d', _config.timeout * 1000),
]);
}
if (_config.deadline) {
ret = ret.concat([
'-t',
util.format('%d', _config.deadline),
]);
}
if (_config.min_reply) {
ret = ret.concat([
'-c',
util.format('%d', _config.min_reply),
]);
}
if (_config.sourceAddr) {
ret = ret.concat([
'-S',
util.format('%s', _config.sourceAddr),
]);
}
if (_config.packetSize) {
ret = ret.concat([
'-s',
util.format('%d', _config.packetSize),
]);
}
if (_config.extra) {
ret = ret.concat(_config.extra);
}
ret.push(target);
return ret;
};
/**
* Compute an option object for child_process.spawn
* @return {object} - Refer to document of child_process.spawn
*/
builder.getSpawnOptions = function () {
return {};
};
module.exports = builder;

119
node_modules/ping/lib/builder/win.js generated vendored Normal file
View File

@ -0,0 +1,119 @@
'use strict';
/**
* A builder builds command line arguments for ping in window environment
* @module lib/builder/win
*/
var util = require('util');
var builder = {};
/**
* Cross platform config representation
* @typedef {Object} PingConfig
* @property {boolean} numeric - Map IP address to hostname or not
* @property {number} timeout - Timeout in seconds for each ping request
* @property {number} min_reply - Exit after sending number of ECHO_REQUEST
* @property {boolean} v6 - Use IPv4 (default) or IPv6
* @property {string} sourceAddr - source address for sending the ping
* @property {number} packetSize - Specifies the number of data bytes to be sent
* Default: Linux / MAC: 56 Bytes,
* Window: 32 Bytes
* @property {string[]} extra - Optional options does not provided
*/
var defaultConfig = {
numeric: true,
timeout: 5,
min_reply: 1,
v6: false,
sourceAddr: '',
packetSize: 32,
extra: [],
};
/**
* Get the finalized array of command line arguments
* @param {string} target - hostname or ip address
* @param {PingConfig} [config] - Configuration object for cmd line argument
* @return {string[]} - Command line argument according to the configuration
*/
builder.getCommandArguments = function (target, config) {
var _config = config || {};
// Empty argument
var ret = [];
// Make every key in config has been setup properly
var keys = [
'numeric', 'timeout', 'min_reply', 'v6', 'sourceAddr', 'extra',
'packetSize',
];
keys.forEach(function (k) {
// Falsy value will be overrided without below checking
if (typeof(_config[k]) !== 'boolean') {
_config[k] = _config[k] || defaultConfig[k];
}
});
ret.push(_config.v6 ? '-6' : '-4');
if (!_config.numeric) {
ret.push('-a');
}
if (_config.timeout) {
// refs #56: Unit problem
// Our timeout is in second while timeout in window is in milliseconds
// so we need to convert our units accordingly
ret = ret.concat([
'-w',
util.format('%d', _config.timeout * 1000),
]);
}
if (_config.deadline) {
throw new Error('There is no deadline option on windows');
}
if (_config.min_reply) {
ret = ret.concat([
'-n',
util.format('%d', _config.min_reply),
]);
}
if (_config.sourceAddr) {
ret = ret.concat([
'-S',
util.format('%s', _config.sourceAddr),
]);
}
if (_config.packetSize) {
ret = ret.concat([
'-l',
util.format('%d', _config.packetSize),
]);
}
if (_config.extra) {
ret = ret.concat(_config.extra);
}
ret.push(target);
return ret;
};
/**
* Compute an option object for child_process.spawn
* @return {object} - Refer to document of child_process.spawn
*/
builder.getSpawnOptions = function () {
return {
windowsHide: true,
};
};
module.exports = builder;