Giter Club home page Giter Club logo

webcommand's Introduction

Unix command line utilities as web services

Build Status

Synopsis

This module provides functions that allow the exposure of any unix command utility to node.js mapping the commands stdin and stdout to the webserver in out and the url's path to the uitilities arguments. There are three functions createCommandServer, webCommand and getCommandList.

#Description To create a command server call createCommandServer. You may provide an array with the allowed commands.

createCommandServer([commandList]);

To execute commands call the webCommand method of the command server

webCommand(command,arguments, inStream, outStream);

To get the list of allowed commands for a CommandServer.

getCommandList()

The 'normal' use case for this library is to expose the power of the unix command utilities within a more restricted enviorment, for example the browser. For example you can easily create an awk javascript function (replace sort above with awk..). Note that while these unix facilities are obtaining significant user access (even readonly) to the server, the server would probably be a rooted slug - e.g. a heroku app - whose disk is containing no user information besides the code it serves.

#Example with express In this example a post of a form in index.html will call sort and stream the results back to browser.

var express = require('express');
var app = express();
var webcommand=require('./lib/index.js');

var port = process.env.PORT || 8000;

var commandServer=webcommand.createCommandServer();

app.get('/getCommands', function(req,res) {
	  res.send(JSON.stringify(commandServer.getCommandList()));
	});


app.get('/', function(req,res) {
	  res.sendfile('index.html');
	});

app.post('/index.html', function(req,res){
	res.on('error', function(error){
		    console.log(error);
		});
	commandServer.webCommand('sort',req.query.args.split(' '), req, res);
});

app.listen(port);
console.log('Listening on port: '+port);

Installation

To run locally:

> hub clone ogt/webcommand && cd webcommand
> npm install
> node test.js&
> open localhost:8000

You can test the default command (sort) or replace any command that is in your path. Remember that if if you are to use a command that doesn't need stdin you will need to clear the input textarea - otherwise you will get a pipe error.

webcommand's People

Watchers

 avatar

webcommand's Issues

The heroku app should be from a different repo.

Currently the heroku webcommand.herokupapp.com site uses the webcommand repo.

However, the repository of an npm module needs to have a different structure than the repository of a deployable web app. (among other things the web app is supposed to be including in the repo its node_modules, while the node module shouldn't).
My idea was to use the ogt/sorter repo (and rename it into webcommandserver or something like that) and make that repo the one that powers the heroku app.

I have captured this and several other related points in the "roadmap" issue of that repo - ogt/webcommand-app#3 , I would suggest to do that as a separate project.

Use a more flexible html client as example/index.html

The index.html file of https://github.com/ogt/clocserver (you can see it at http://cloc.herokuapp.com)
allows the user to submit a variety of commands not just sort.
It also has a better naming for parameter/input fields and has fixed some other issues that the original index.html (which is currently yours) had.
So we should use the file instead of the one you are using.

FYI, clocserver currently depends (and thus is compatible with) the ogt/webcommand module (it depends on it by using a dircect repository reference in package.json . To the extent that your refactored code is compatible with the version your forked from .. it should work just fine - by just using your webcommand module.

Catch exceptions

I had to add an exception catching stmt - otherwise any non zero exit from the command causes permenant damage to the service

Somehow the commit of it didn't make it in the version I pushed to github -
you can see it now:

ogt/clocserver@676c3e2#index.js

  process.on('uncaughtException', function (err) {
    try {
      console.log('error: ' + (err.stack || err))
    } catch (e) {}
  });

I think you will need to add this (or sth similar) to the library code (right now the webcommand.herokuapp is broken - after I used a bad argument)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.