altd 0.0.2 → 0.0.4

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/README.md CHANGED
@@ -1,16 +1,11 @@
1
- [![Build Status](https://travis-ci.org/freddiefujiwara/altd.svg?branch=master)](https://travis-ci.org/freddiefujiwara/altd)
2
- [![Build status](https://ci.appveyor.com/api/projects/status/f6wch68buqp93hc7/branch/master?svg=true)](https://ci.appveyor.com/project/freddiefujiwara/altd/branch/master)
3
- [![CircleCI](https://circleci.com/gh/freddiefujiwara/altd.svg?style=svg)](https://circleci.com/gh/freddiefujiwara/altd)
4
1
  [![npm version](https://badge.fury.io/js/altd.svg)](https://badge.fury.io/js/altd)
5
- [![codecov](https://codecov.io/gh/freddiefujiwara/altd/branch/master/graph/badge.svg)](https://codecov.io/gh/freddiefujiwara/altd)
6
- [![dependencies Status](https://david-dm.org/freddiefujiwara/altd/status.svg)](https://david-dm.org/freddiefujiwara/altd)
7
2
 
8
3
  # altd
9
- Web Server(like nginx..) Access log tail dispatcher
4
+ Web server access log tail dispatcher for running whitelisted commands based on GET requests.
10
5
 
11
6
  ## Requirements
12
7
 
13
- - Node 7.6 or later
8
+ - Node.js 18 or later
14
9
 
15
10
  ## Installation
16
11
 
@@ -18,26 +13,30 @@ Web Server(like nginx..) Access log tail dispatcher
18
13
  npm i -g altd
19
14
  ```
20
15
 
16
+ ## Build
17
+
18
+ ```bash
19
+ npm run build
20
+ ```
21
+
21
22
  ## Usage
22
- ```bash
23
- Usage: altd <access_log.file> -w [commands]
24
-
25
-
26
- Options:
27
-
28
- -V, --version output the version number
29
- -h, --help output usage information
23
+
24
+ ```bash
25
+ altd <access_log.file> -w [commands]
30
26
  ```
31
27
 
28
+ ### Options
29
+
30
+ - `-V, --version` output the version number
31
+ - `-h, --help` output usage information
32
+ - `-w, --whitelist <commands>` comma-separated list of allowed commands
33
+
32
34
  ## Example
35
+
33
36
  ```bash
34
37
  altd /var/log/nginx/access_log -w ls,hostname
35
38
  ```
36
39
 
37
- ## FAQ
38
-
39
- [FAQ](https://github.com/freddiefujiwara/altd/wiki/FAQ)
40
-
41
40
  ## Contributing
42
41
 
43
42
  Bug reports and pull requests are welcome on GitHub at https://github.com/freddiefujiwara/altd
package/dist/altd.js ADDED
@@ -0,0 +1,132 @@
1
+ import {spawn} from 'child_process';
2
+ import Tail from 'nodejs-tail';
3
+ /**
4
+ ** main class of AccessLogTailDispatcher
5
+ */
6
+ export default class AccessLogTailDispatcher {
7
+ /**
8
+ * @constructor
9
+ * @param {string} file access_log
10
+ * @param {Array} whitelist ['command1','command2'..]
11
+ */
12
+ constructor(file, whitelist) {
13
+ this.file = file;
14
+ this.whitelist = whitelist;
15
+ this.spawn = undefined;
16
+ this.tail = undefined;
17
+ }
18
+ /**
19
+ * Get the path from 'GET /path/to/dir HTTP'
20
+ * @param {string} line access_log
21
+ * @return {string} /path/to/dir
22
+ */
23
+ path(line) {
24
+ if (!(typeof line === 'string')) {
25
+ return '';
26
+ }
27
+ let match = line.match(
28
+ /GET\s((\/[a-z0-9-._~%!$&'()*+,;=:@?]+)+\/?)\sHTTP/i);
29
+ if (null !== match && match.length > 2) {
30
+ return match[1];
31
+ }
32
+ return '';
33
+ }
34
+
35
+ /**
36
+ * Extract command and args
37
+ * @param {string} path
38
+ * @return {Array} [command,arg1,arg2...]
39
+ */
40
+ commandWithArgs(path) {
41
+ if (!(typeof path === 'string')) {
42
+ return [];
43
+ }
44
+ let commands = path.split(/\//).map(function(element, index, array) {
45
+ let ret = "";
46
+ try{
47
+ ret = decodeURIComponent(element);
48
+ }catch(e){
49
+ console.error(e);
50
+ }
51
+ return ret;
52
+ });
53
+ commands.shift();
54
+ return commands;
55
+ }
56
+
57
+ /**
58
+ * Filter by whitelist
59
+ * @param {Array} commandWithArgs [command,arg1,arg2...]
60
+ * @param {Array} whitelist ['command1','command2'...]
61
+ * @return {Array} filtered commandWithArgs
62
+ */
63
+ filterByWhitelist(commandWithArgs, whitelist) {
64
+ if (!this.isArray(commandWithArgs) ||
65
+ !this.isArray(whitelist) ||
66
+ commandWithArgs.length == 0 ||
67
+ whitelist.indexOf(commandWithArgs[0]) == -1
68
+ ) {
69
+ return [];
70
+ }
71
+ return commandWithArgs;
72
+ }
73
+
74
+ /**
75
+ * Dispatch
76
+ * @param {Array} commandWithArgs [command,arg1,arg2...]
77
+ */
78
+ dispatch(commandWithArgs) {
79
+ if (commandWithArgs.length == 0) {
80
+ return;
81
+ }
82
+ let command = commandWithArgs.shift();
83
+ let proc = this.spawn(command, commandWithArgs);
84
+ proc.on('error', (err) => {
85
+ console.error(err);
86
+ });
87
+ proc.stdout.on('data', (data) => {
88
+ process.stdout.write(data.toString());
89
+ });
90
+ }
91
+
92
+ /**
93
+ * isArray
94
+ * @param {object} obj [command,arg1,arg2...]
95
+ * @return {boolean}
96
+ */
97
+ isArray(obj) {
98
+ return Object.prototype.toString.call(obj) === '[object Array]';
99
+ }
100
+
101
+ /**
102
+ * run
103
+ * @param {string} file
104
+ * @param {Array} whitelist ['command1','command2'...]
105
+ */
106
+ run(file, whitelist) {
107
+ if ( typeof file !== 'undefined') {
108
+ this.file = file;
109
+ }
110
+ if ( typeof whitelist !== 'undefined') {
111
+ this.whitelist = whitelist;
112
+ }
113
+ if ( typeof this.spawn === 'undefined') {
114
+ this.spawn = spawn;
115
+ }
116
+ if ( typeof this.tail === 'undefined') {
117
+ this.tail = new Tail(this.file,
118
+ {alwaysStat: true, ignoreInitial: true, persistent: true});
119
+ }
120
+ this.tail.on('line', (line) => {
121
+ this.dispatch(
122
+ this.filterByWhitelist(
123
+ this.commandWithArgs(
124
+ this.path(line)),
125
+ this.whitelist));
126
+ });
127
+ this.tail.on('close', () => {
128
+ console.log('watching stopped');
129
+ });
130
+ this.tail.watch();
131
+ }
132
+ }
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import pkg from '../package.json' assert { type: 'json' };
4
+ import AccessLogTailDispatcher from './altd.js';
5
+
6
+ const program = new Command();
7
+
8
+ program
9
+ .name('altd')
10
+ .version(pkg.version)
11
+ .description(pkg.description)
12
+ .argument('<file>')
13
+ .option(
14
+ '-w, --whitelist <commands>',
15
+ 'Add commands to whitelist',
16
+ (commands) => commands.split(',')
17
+ )
18
+ .parse(process.argv);
19
+
20
+ const fileValue = program.args[0];
21
+ const { whitelist } = program.opts();
22
+
23
+ if (!fileValue || !whitelist) {
24
+ console.log('altd <file> -w <commands...>');
25
+ process.exit(1);
26
+ }
27
+
28
+ const altd = new AccessLogTailDispatcher(fileValue, whitelist);
29
+ altd.run();
package/index.js CHANGED
@@ -1,24 +1,29 @@
1
1
  #!/usr/bin/env node
2
- let program = require('commander');
3
- let pkg = require('./package');
4
- let fileValue = undefined;
5
- let whitelist = undefined;
2
+ import { Command } from 'commander';
3
+ import pkg from './package.json' assert { type: 'json' };
4
+ import AccessLogTailDispatcher from './src/altd.js';
5
+
6
+ const program = new Command();
6
7
 
7
8
  program
8
- .version(pkg.version)
9
- .description(pkg.description)
10
- .arguments('<file>')
11
- .option('-w, --whitelist <commands>', 'Add commands to whitelist', (commands)=>commands.split(','))
12
- .action(function(file){
13
- fileValue = file;
14
- });
15
- program.parse(process.argv);
16
- if(typeof fileValue === 'undefined' ||
17
- typeof program.whitelist === 'undefined'){
18
- console.log('altd <file> -w <commands...>');
19
- process.exit(1);
9
+ .name('altd')
10
+ .version(pkg.version)
11
+ .description(pkg.description)
12
+ .argument('<file>')
13
+ .option(
14
+ '-w, --whitelist <commands>',
15
+ 'Add commands to whitelist',
16
+ (commands) => commands.split(',')
17
+ )
18
+ .parse(process.argv);
19
+
20
+ const fileValue = program.args[0];
21
+ const { whitelist } = program.opts();
22
+
23
+ if (!fileValue || !whitelist) {
24
+ console.log('altd <file> -w <commands...>');
25
+ process.exit(1);
20
26
  }
21
- let AccessLogTailDispatcher = require('./lib/altd');
22
27
 
23
- let altd = new AccessLogTailDispatcher(fileValue,program.whitelist);
28
+ const altd = new AccessLogTailDispatcher(fileValue, whitelist);
24
29
  altd.run();
package/package.json CHANGED
@@ -1,65 +1,70 @@
1
1
  {
2
- "name": "altd",
3
- "version": "0.0.2",
4
- "description": "Access log tail dispatcher",
5
- "scripts": {
6
- "clean": "rimraf lib",
7
- "test": "cross-env BABEL_ENV=commonjs mocha --require babel-core/register --require babel-polyfill --recursive",
8
- "test:watch": "npm test -- --watch",
9
- "lint": "eslint -c google src test",
10
- "build": "cross-env BABEL_ENV=commonjs babel src --out-dir lib",
11
- "codecov": "mkdir -p .nyc_output && nyc report --reporter=text-lcov > coverage.lcov && codecov -t 3e4320c7-d0e0-46a4-bb31-d5d8d2388bc4",
12
- "coverage": "mkdir -p .nyc_output && nyc --reporter=lcov --reporter=text npm run test",
13
- "prepublishOnly": "npm i && npm run clean && npm run lint && npm run coverage && npm run codecov && npm run build",
14
- "requirements-check": "node check-version.js",
15
- "postinstall": "npm run requirements-check"
16
- },
17
- "bin": {
18
- "altd": "index.js"
19
- },
20
- "main": "lib/altd.js",
21
- "files": [
22
- "lib",
23
- "index.js",
24
- "check-version.js"
25
- ],
26
- "repository": {
27
- "type": "git",
28
- "url": "git+https://github.com/freddiefujiwara/altd.git"
29
- },
30
- "keywords": [
31
- "access log",
32
- "httpd",
33
- "log"
34
- ],
35
- "author": "Fumikazu Fujiwara <npm@ze.gs> (http://freddiefujiwara.com)",
36
- "license": "MIT",
37
- "bugs": {
38
- "url": "https://github.com/freddiefujiwara/altd/issues"
39
- },
40
- "homepage": "https://github.com/freddiefujiwara/altd#readme",
41
- "devDependencies": {
42
- "babel-cli": "^6.24.1",
43
- "babel-core": "^6.25.0",
44
- "babel-eslint": "^7.2.3",
45
- "babel-plugin-add-module-exports": "^0.2.1",
46
- "babel-preset-es2015": "^6.24.1",
47
- "babel-register": "^6.24.1",
48
- "chai": "^4.0.2",
49
- "codecov": "^3.6.5",
50
- "cross-env": "^5.0.1",
51
- "eslint": "^4.1.1",
52
- "eslint-config-google": "^0.9.1",
53
- "mocha": "^7.1.1",
54
- "nyc": "^15.0.1",
55
- "rimraf": "^2.6.1"
56
- },
57
- "dependencies": {
58
- "commander": "^2.20.3",
59
- "nodejs-tail": "^1.1.0",
60
- "semver": "^5.7.1"
61
- },
62
- "engines": {
63
- "node": ">=7.6"
2
+ "name": "altd",
3
+ "version": "0.0.4",
4
+ "description": "Access log tail dispatcher",
5
+ "type": "module",
6
+ "bin": {
7
+ "altd": "./dist/index.js"
8
+ },
9
+ "main": "./dist/altd.js",
10
+ "exports": {
11
+ ".": "./dist/altd.js"
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "src",
16
+ "index.js",
17
+ "scripts",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "scripts": {
22
+ "build": "node scripts/build.js",
23
+ "test": "vitest run --coverage",
24
+ "test:watch": "vitest",
25
+ "prepublishOnly": "npm run build"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/freddiefujiwara/altd.git"
30
+ },
31
+ "keywords": [
32
+ "access log",
33
+ "httpd",
34
+ "log"
35
+ ],
36
+ "author": "Fumikazu Fujiwara <npm@ze.gs> (http://freddiefujiwara.com)",
37
+ "license": "MIT",
38
+ "bugs": {
39
+ "url": "https://github.com/freddiefujiwara/altd/issues"
40
+ },
41
+ "homepage": "https://github.com/freddiefujiwara/altd#readme",
42
+ "engines": {
43
+ "node": ">=18"
44
+ },
45
+ "dependencies": {
46
+ "commander": "^12.1.0",
47
+ "nodejs-tail": "^1.1.0"
48
+ },
49
+ "devDependencies": {
50
+ "@vitest/coverage-v8": "^2.1.8",
51
+ "vitest": "^2.1.8"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
55
+ },
56
+ "vitest": {
57
+ "coverage": {
58
+ "provider": "v8",
59
+ "reporter": [
60
+ "text",
61
+ "html",
62
+ "lcov"
63
+ ],
64
+ "exclude": [
65
+ "node_modules",
66
+ "test"
67
+ ]
64
68
  }
69
+ }
65
70
  }
@@ -0,0 +1,17 @@
1
+ import { mkdir, readFile, writeFile, copyFile } from 'node:fs/promises';
2
+ import { dirname, join } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ const rootDir = dirname(fileURLToPath(import.meta.url));
6
+ const projectRoot = dirname(rootDir);
7
+ const distDir = join(projectRoot, 'dist');
8
+
9
+ await mkdir(distDir, { recursive: true });
10
+
11
+ const indexSource = await readFile(join(projectRoot, 'index.js'), 'utf8');
12
+ const indexOutput = indexSource
13
+ .replace('./src/altd.js', './altd.js')
14
+ .replace('./package.json', '../package.json');
15
+
16
+ await writeFile(join(distDir, 'index.js'), indexOutput);
17
+ await copyFile(join(projectRoot, 'src', 'altd.js'), join(distDir, 'altd.js'));
package/src/altd.js ADDED
@@ -0,0 +1,132 @@
1
+ import {spawn} from 'child_process';
2
+ import Tail from 'nodejs-tail';
3
+ /**
4
+ ** main class of AccessLogTailDispatcher
5
+ */
6
+ export default class AccessLogTailDispatcher {
7
+ /**
8
+ * @constructor
9
+ * @param {string} file access_log
10
+ * @param {Array} whitelist ['command1','command2'..]
11
+ */
12
+ constructor(file, whitelist) {
13
+ this.file = file;
14
+ this.whitelist = whitelist;
15
+ this.spawn = undefined;
16
+ this.tail = undefined;
17
+ }
18
+ /**
19
+ * Get the path from 'GET /path/to/dir HTTP'
20
+ * @param {string} line access_log
21
+ * @return {string} /path/to/dir
22
+ */
23
+ path(line) {
24
+ if (!(typeof line === 'string')) {
25
+ return '';
26
+ }
27
+ let match = line.match(
28
+ /GET\s((\/[a-z0-9-._~%!$&'()*+,;=:@?]+)+\/?)\sHTTP/i);
29
+ if (null !== match && match.length > 2) {
30
+ return match[1];
31
+ }
32
+ return '';
33
+ }
34
+
35
+ /**
36
+ * Extract command and args
37
+ * @param {string} path
38
+ * @return {Array} [command,arg1,arg2...]
39
+ */
40
+ commandWithArgs(path) {
41
+ if (!(typeof path === 'string')) {
42
+ return [];
43
+ }
44
+ let commands = path.split(/\//).map(function(element, index, array) {
45
+ let ret = "";
46
+ try{
47
+ ret = decodeURIComponent(element);
48
+ }catch(e){
49
+ console.error(e);
50
+ }
51
+ return ret;
52
+ });
53
+ commands.shift();
54
+ return commands;
55
+ }
56
+
57
+ /**
58
+ * Filter by whitelist
59
+ * @param {Array} commandWithArgs [command,arg1,arg2...]
60
+ * @param {Array} whitelist ['command1','command2'...]
61
+ * @return {Array} filtered commandWithArgs
62
+ */
63
+ filterByWhitelist(commandWithArgs, whitelist) {
64
+ if (!this.isArray(commandWithArgs) ||
65
+ !this.isArray(whitelist) ||
66
+ commandWithArgs.length == 0 ||
67
+ whitelist.indexOf(commandWithArgs[0]) == -1
68
+ ) {
69
+ return [];
70
+ }
71
+ return commandWithArgs;
72
+ }
73
+
74
+ /**
75
+ * Dispatch
76
+ * @param {Array} commandWithArgs [command,arg1,arg2...]
77
+ */
78
+ dispatch(commandWithArgs) {
79
+ if (commandWithArgs.length == 0) {
80
+ return;
81
+ }
82
+ let command = commandWithArgs.shift();
83
+ let proc = this.spawn(command, commandWithArgs);
84
+ proc.on('error', (err) => {
85
+ console.error(err);
86
+ });
87
+ proc.stdout.on('data', (data) => {
88
+ process.stdout.write(data.toString());
89
+ });
90
+ }
91
+
92
+ /**
93
+ * isArray
94
+ * @param {object} obj [command,arg1,arg2...]
95
+ * @return {boolean}
96
+ */
97
+ isArray(obj) {
98
+ return Object.prototype.toString.call(obj) === '[object Array]';
99
+ }
100
+
101
+ /**
102
+ * run
103
+ * @param {string} file
104
+ * @param {Array} whitelist ['command1','command2'...]
105
+ */
106
+ run(file, whitelist) {
107
+ if ( typeof file !== 'undefined') {
108
+ this.file = file;
109
+ }
110
+ if ( typeof whitelist !== 'undefined') {
111
+ this.whitelist = whitelist;
112
+ }
113
+ if ( typeof this.spawn === 'undefined') {
114
+ this.spawn = spawn;
115
+ }
116
+ if ( typeof this.tail === 'undefined') {
117
+ this.tail = new Tail(this.file,
118
+ {alwaysStat: true, ignoreInitial: true, persistent: true});
119
+ }
120
+ this.tail.on('line', (line) => {
121
+ this.dispatch(
122
+ this.filterByWhitelist(
123
+ this.commandWithArgs(
124
+ this.path(line)),
125
+ this.whitelist));
126
+ });
127
+ this.tail.on('close', () => {
128
+ console.log('watching stopped');
129
+ });
130
+ this.tail.watch();
131
+ }
132
+ }
package/check-version.js DELETED
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- var _semver = require('semver');
5
-
6
- var _semver2 = _interopRequireDefault(_semver);
7
-
8
- var _package = require('./package');
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- var version = _package.engines.node;
13
- if (!_semver2.default.satisfies(process.version, version)) {
14
- var warn = 'Required node version ' + version + ' ';
15
- warn += 'not satisfied with current version ' + process.version + '.';
16
- console.log(warn);
17
- process.exit(1);
18
- }
19
-
package/lib/altd.js DELETED
@@ -1,161 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8
-
9
- var _child_process = require('child_process');
10
-
11
- var _nodejsTail = require('nodejs-tail');
12
-
13
- var _nodejsTail2 = _interopRequireDefault(_nodejsTail);
14
-
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
-
17
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
-
19
- /**
20
- ** main class of AccessLogTailDispatcher
21
- */
22
- var AccessLogTailDispatcher = function () {
23
- /**
24
- * @constructor
25
- * @param {string} file access_log
26
- * @param {Array} whitelist ['command1','command2'..]
27
- */
28
- function AccessLogTailDispatcher(file, whitelist) {
29
- _classCallCheck(this, AccessLogTailDispatcher);
30
-
31
- this.file = file;
32
- this.whitelist = whitelist;
33
- this.spawn = undefined;
34
- this.tail = undefined;
35
- }
36
- /**
37
- * Get the path from 'GET /path/to/dir HTTP'
38
- * @param {string} line access_log
39
- * @return {string} /path/to/dir
40
- */
41
-
42
-
43
- _createClass(AccessLogTailDispatcher, [{
44
- key: 'path',
45
- value: function path(line) {
46
- if (!(typeof line === 'string')) {
47
- return '';
48
- }
49
- var match = line.match(/GET\s((\/[a-z0-9-._~%!$&'()*+,;=:@?]+)+\/?)\sHTTP/i);
50
- if (null !== match && match.length > 2) {
51
- return match[1];
52
- }
53
- return '';
54
- }
55
-
56
- /**
57
- * Extract command and args
58
- * @param {string} path
59
- * @return {Array} [command,arg1,arg2...]
60
- */
61
-
62
- }, {
63
- key: 'commandWithArgs',
64
- value: function commandWithArgs(path) {
65
- if (!(typeof path === 'string')) {
66
- return [];
67
- }
68
- var commands = path.split(/\//).map(function (element, index, array) {
69
- var ret = "";
70
- try {
71
- ret = decodeURIComponent(element);
72
- } catch (e) {
73
- console.error(e);
74
- }
75
- return ret;
76
- });
77
- commands.shift();
78
- return commands;
79
- }
80
-
81
- /**
82
- * Filter by whitelist
83
- * @param {Array} commandWithArgs [command,arg1,arg2...]
84
- * @param {Array} whitelist ['command1','command2'...]
85
- * @return {Array} filtered commandWithArgs
86
- */
87
-
88
- }, {
89
- key: 'filterByWhitelist',
90
- value: function filterByWhitelist(commandWithArgs, whitelist) {
91
- if (!this.isArray(commandWithArgs) || !this.isArray(whitelist) || commandWithArgs.length == 0 || whitelist.indexOf(commandWithArgs[0]) == -1) {
92
- return [];
93
- }
94
- return commandWithArgs;
95
- }
96
-
97
- /**
98
- * Dispatch
99
- * @param {Array} commandWithArgs [command,arg1,arg2...]
100
- */
101
-
102
- }, {
103
- key: 'dispatch',
104
- value: function dispatch(commandWithArgs) {
105
- if (commandWithArgs.length == 0) {
106
- return;
107
- }
108
- var command = commandWithArgs.shift();
109
- var proc = this.spawn(command, commandWithArgs);
110
- proc.on('error', function (err) {
111
- console.error(err);
112
- });
113
- proc.stdout.on('data', function (data) {
114
- process.stdout.write(data.toString());
115
- });
116
- }
117
-
118
- /**
119
- * isArray
120
- * @param {object} obj [command,arg1,arg2...]
121
- * @return {boolean}
122
- */
123
-
124
- }, {
125
- key: 'isArray',
126
- value: function isArray(obj) {
127
- return Object.prototype.toString.call(obj) === '[object Array]';
128
- }
129
-
130
- /**
131
- * run
132
- * @param {string} file
133
- * @param {Array} whitelist ['command1','command2'...]
134
- */
135
-
136
- }, {
137
- key: 'run',
138
- value: function run(file, whitelist) {
139
- var _this = this;
140
-
141
- if (typeof this.spawn === 'undefined') {
142
- this.spawn = _child_process.spawn;
143
- }
144
- if (typeof this.tail === 'undefined') {
145
- this.tail = new _nodejsTail2.default(this.file, { alwaysStat: true, ignoreInitial: true, persistent: true });
146
- }
147
- this.tail.on('line', function (line) {
148
- _this.dispatch(_this.filterByWhitelist(_this.commandWithArgs(_this.path(line)), _this.whitelist));
149
- });
150
- this.tail.on('close', function () {
151
- console.log('watching stopped');
152
- });
153
- this.tail.watch();
154
- }
155
- }]);
156
-
157
- return AccessLogTailDispatcher;
158
- }();
159
-
160
- exports.default = AccessLogTailDispatcher;
161
- module.exports = exports['default'];