Skip to content

Commit

Permalink
Adapto a qa-control y agrego LEEME.md
Browse files Browse the repository at this point in the history
  • Loading branch information
emilioplatzer committed Apr 10, 2016
1 parent 7a5ad46 commit bec55b8
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 67 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -26,3 +26,6 @@ node_modules

# Users Environment Variables
.lock-wscript

local-*
*-local.*
18 changes: 16 additions & 2 deletions LEEME.md
Expand Up @@ -2,17 +2,22 @@
# kill-9
<!--lang:es-->
un modo de matar el proceso **node** desde el navegador. Algo así como http://yoursite.kom/kill-9

<!--lang:en--]
a way to kill node process from client navigator. Something like http://yoursite.kom/kill-9
[!--lang:*-->

<!-- cucardas -->
[![version](https://img.shields.io/npm/v/kill-9.svg)](https://npmjs.org/package/kill-9)
![extending](https://img.shields.io/badge/stability-extending-orange.svg)
[![npm-version](https://img.shields.io/npm/v/kill-9.svg)](https://npmjs.org/package/kill-9)
[![downloads](https://img.shields.io/npm/dm/kill-9.svg)](https://npmjs.org/package/kill-9)
[![build](https://img.shields.io/travis/codenautas/kill-9/master.svg)](https://travis-ci.org/codenautas/kill-9)
[![linux](https://img.shields.io/travis/codenautas/kill-9/master.svg)](https://travis-ci.org/codenautas/kill-9)
[![windows](https://ci.appveyor.com/api/projects/status/github/codenautas/kill-9?svg=true)](https://ci.appveyor.com/project/codenautas/kill-9)
[![coverage](https://img.shields.io/coveralls/codenautas/kill-9/master.svg)](https://coveralls.io/r/codenautas/kill-9)
[![climate](https://img.shields.io/codeclimate/github/codenautas/kill-9.svg)](https://codeclimate.com/github/codenautas/kill-9)
[![dependencies](https://img.shields.io/david/codenautas/kill-9.svg)](https://david-dm.org/codenautas/kill-9)
[![qa-control](http://codenautas.com/github/codenautas/kill-9.svg)](http://codenautas.com/github/codenautas/kill-9)

<!--multilang buttons-->

Expand Down Expand Up @@ -158,6 +163,15 @@ test_app.use(
assert.equal(mp.codeRecived, 444);
});
```
<!--lang:es-->

## Notas

+ **No es seguro para poner en un server en producción.** Kill-9 no valida el usuario ni confirma la instrucción
+ puede usarse junto con [login-plus](npmjs.org/package/login-plus) o algún otro middleware que valide el usuario (lo que tiene el defecto de no poder matar el proceso si el mecanismo de validación de usuarios está fallando)
+ Actualmente options.pid puede ser un texto, esto podría cambiar en futuras versiones.

<!--lang:en--]
## Notes
Expand Down
74 changes: 31 additions & 43 deletions README.md
@@ -1,11 +1,21 @@
# kill-9
a way to kill node process from client navigator. Something like http://yoursite.kom/kill-9

[![version](https://img.shields.io/npm/v/kill-9.svg)](https://npmjs.org/package/kill-9)

![extending](https://img.shields.io/badge/stability-extending-orange.svg)
[![npm-version](https://img.shields.io/npm/v/kill-9.svg)](https://npmjs.org/package/kill-9)
[![downloads](https://img.shields.io/npm/dm/kill-9.svg)](https://npmjs.org/package/kill-9)
[![build](https://img.shields.io/travis/codenautas/kill-9/master.svg)](https://travis-ci.org/codenautas/kill-9)
[![linux](https://img.shields.io/travis/codenautas/kill-9/master.svg)](https://travis-ci.org/codenautas/kill-9)
[![windows](https://ci.appveyor.com/api/projects/status/github/codenautas/kill-9?svg=true)](https://ci.appveyor.com/project/codenautas/kill-9)
[![coverage](https://img.shields.io/coveralls/codenautas/kill-9/master.svg)](https://coveralls.io/r/codenautas/kill-9)
[![climate](https://img.shields.io/codeclimate/github/codenautas/kill-9.svg)](https://codeclimate.com/github/codenautas/kill-9)
[![dependencies](https://img.shields.io/david/codenautas/kill-9.svg)](https://david-dm.org/codenautas/kill-9)
[![qa-control](http://codenautas.com/github/codenautas/kill-9.svg)](http://codenautas.com/github/codenautas/kill-9)


language: ![English](https://raw.githubusercontent.com/codenautas/multilang/master/img/lang-en.png)
also available in:
[![Spanish](https://raw.githubusercontent.com/codenautas/multilang/master/img/lang-es.png)](LEEME.md)

## Install

Expand All @@ -31,7 +41,7 @@ var server = app.listen(3000, function() {

app.use(kill9({log:true}));

// complete example:
// complete example:
function site_up(req,res){
var kill_url='kill-9?pid='+process.pid;
res.send("<h1>kill-9 demo</h1><p>site up<p>try <a href="+kill_url+">"+kill_url+"</a>");
Expand All @@ -43,28 +53,30 @@ app.get('/',site_up);

### kill9([options])

Returns a function middleware to use with ``express.use``.
Returns a function middleware to use with ``express.use``.
Once installed you can kill the process typing "kill sentence" in the navigator.
Example:

### Example:

```url
http://thesite.kom/kill-9?pid=12345
```

### options

#### statement *text default "kill-9"*

The statement that you must type in the url.

#### pid *integer default process.pid*
option | type | default value | details
--------------|---------|---------------|-------------------------
statement | text | "kill-9" | The statement that you must type in the url.
pid | integer | process.pid | The pid value that you must pass in the pid parameter. By default kill-9 uses the real pid obteined from ``pid`` property of ``process`` object: ``process.pid``
log | boolean | false | If log is set kill-9 show a console.log when it is installed. You can send true or a message.
statusKilled | integer | 200 | The status sent in the response for the case of success.
location | url | | The location for a redirect. This is mandatory if statusKilled between 300 and 303.
messageKilled | text | "kill -9 success" | The message to display in successful kills.
statusBad | integer | 404 | The status sent when the pid doesn't match.
locationBad | url | | The location for a redirect. This is mandatory if statusKilled between 300 and 303.
messageBad | text | "kill -9 unknown" | The message to display when when the pid doesn't match.
process | object | process | The process option is for test purpose. You can pass a *mock object*.

The pid value that you must pass in the pid parameter.
By default kill-9 uses the real pid obteined from ``pid`` property of ``process`` object: ``process.pid``

#### log *boolean default false*

If log is set kill-9 show a console.log when it is installed. You can send true or a message.

```js
app.use(kill9({log:"remember to delete in production"}));
Expand All @@ -75,43 +87,18 @@ if(getMode()=='develop'){
}
```

#### statusKilled *integer default 200*

The status sent in the response for the case of success.
```js
app.use(kill9({statusKilled:301, location:'other_site.kom'}));
```

#### location *url*

The location for a redirect. This is mandatory if statusKilled between 300 and 303.

#### messageKilled *text default "kill -9 success"*

The message to display in successful kills.
```js
app.use(kill9({messageKilled: "I'll be back"}));
```

#### statusBad *integer default 404*

The status sent when the pid doesn't match.

#### locationBad *url*

The location for a redirect. This is mandatory if statusKilled between 300 and 303.

#### messageBad *text default "kill -9 unknown"*

The message to display when when the pid doesn't match.
```js
app.use(kill9({messageBad: "Not foud"}));
```

#### process *object default process*

The process option is for test purpose. You can pass a *mock object*.

```js
function ProcessMock(){
this.pid=444;
Expand All @@ -134,8 +121,9 @@ test_app.use(
## Notes

+ **This is not secure in production servers. Use it only in developer servers**. Kill-9 lacks of password or validate user or any way for confirm legal use.
+ Actually options.pid can be a text, but I don't know if this will change in the future.

+ Actually options.pid can be a text, but I don't know if this will change in the future.


## License

[GPL-2.0](LICENSE)
Expand Down
35 changes: 13 additions & 22 deletions kill-9.js
@@ -1,39 +1,28 @@
/*!
* kill-9
* 2015 Emilio Platzer
* GNU Licensed
*/

"use strict";

/**
* Module dependencies.
*/
/*jshint eqnull:true */
/*jshint node:true */
/*eslint-disable no-console */

var express = require('express');
var kill9 = {};

/**
* @param {Object} opts
* @return {Function}
* @api public
*/
var express = require('express');

var kill9 = exports = module.exports = function kill9(opts){
kill9 = function kill9(opts){
var killer=express();
var _process=opts.process || process;
var pid=opts.pid || _process.pid;
if(kill9.isRedirectCode(opts.statusKilled) && !('location' in opts)){
throw new Error('kill-9: options.location required');
};
}
if(kill9.isRedirectCode(opts.statusBad) && !('locationBad' in opts)){
throw new Error('kill-9: options.locationBad required');
};
}
if(!kill9.isRedirectCode(opts.statusKilled) && ('location' in opts)){
throw new Error('kill-9: options.location is only for redirect');
};
}
if(!kill9.isRedirectCode(opts.statusBad) && ('locationBad' in opts)){
throw new Error('kill-9: options.locationBad is only for redirect');
};
}
if(opts.log){
console.log('kill-9 installed. '+opts.log);
console.log('pid='+pid);
Expand Down Expand Up @@ -69,4 +58,6 @@ kill9.defaults={

kill9.isRedirectCode = function isRedirectCode(htmlCode){
return htmlCode>=300 && htmlCode<=303;
};
};

module.exports = kill9;
27 changes: 27 additions & 0 deletions package.json
Expand Up @@ -22,5 +22,32 @@
"test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
"start": "node example/server.js"
},
"jshintConfig": {
"asi": false,
"forin": true,
"curly": true,
"esversion": 6
},
"eslintConfig":{
"env": {
"node": false
},
"rules": {
"strict": 0,
"no-console": 1,
"no-unused-vars": 1
},
"parserOptions": {
"ecmaVersion": 6
}
},
"qa-control": {
"package-version": "0.2.0",
"run-in": "server",
"stability": "extending",
"test-appveyor": true,
"type": "lib",
"coverage": 100
}
}

0 comments on commit bec55b8

Please sign in to comment.