Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Edouard Klein committed Jan 13, 2015
0 parents commit 3f1b6e2
Show file tree
Hide file tree
Showing 7 changed files with 418 additions and 0 deletions.
11 changes: 11 additions & 0 deletions 100unix2web.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<VirtualHost *:80>
WSGIDaemonProcess app
WSGIScriptAlias / /var/www/unix2web/unix2web.wsgi

<Directory /var/www/unix2web>
WSGIProcessGroup app
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
102 changes: 102 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
================
unix2web
================
----------
Expose a UNIX filter on a web page
----------

Purpose
=============

You have an UNIX filter that does one job and do it well. For example it converts a .doc file to PDF :
doc2pdf < file.doc >file.pdf

This tool lets you host a nice web page where people can upload the input file and download the output file. This is
useful if UNIX-disabled people need to use your filter.

In a matter of minutes you can make an unix script available to the world on e.g. an AWS EC2 instance.

Installation
=============

We assume you have a UNIX-like server where your filter works (this tool does not handle the installation of your filter
or its dependencies).

Clone the repo somewhere :

git clone https://github.com/edouardklein/unix2web/

Change the index.html file to your liking (most notably the title and description).

Modify unix2web.wsgi if you want the webapp to live somewhere else than /var/www/unix2web/ (not useful if you intend
to only run one filter on the server).

Same procedure for 100web2unix.conf

Same procedure for unix2web.py

Review the install.sh file, modify if necessary, then upload all the files on your server and run install.sh
scp -i private_key.pem *.* login@example.com:/tmp/
ssh -i private_key.pem login@example.com 'cd /tmp/ && sudo sh install.sh'


Example use cases
=========

Converting .doc to .pdf from anywhere.

Compiling LaTeX files.

I'd be happy to hear about your uses. If you deploy this, please send me a word.

Security
========

Security is hard, so we did not do it beyond the obvious (not using the user's filename).

Easy to DDoS (just send a big file).

No password protection.

We advise to deploy this behind a hard-to-find, non-indexable URL and to share the link wisely.


Bugs and Todo
============

Near future
----------

This probably scales badly (untested).

The error output comes all at once, would be nice if, for long processes, it came as it appears server-side.

Security is bad. At least we should check input size and kill long processes.

Output files are not cleaned up (easily doable with a cron-job, though).

Distant future
-------------

Parsing the --help string à la docopt and automatically creating an interface for the options would be wonderful.

Author
======
See http://rdklein.fr

License
=======

unix2web is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Foobar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with unix2web. If not, see <http://www.gnu.org/licenses/>.

19 changes: 19 additions & 0 deletions index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.btn-file {
position: relative;
overflow: hidden;
}
.btn-file input[type=file] {
position: absolute;
top: 0;
right: 0;
min-width: 100%;
min-height: 100%;
font-size: 100px;
text-align: right;
filter: alpha(opacity=0);
opacity: 0;
outline: none;
background: white;
cursor: inherit;
display: block;
}
113 changes: 113 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<!DOCTYPE html>
<html>
<!--AJAX upload code from https://stackoverflow.com/questions/18334717/how-to-upload-a-file-using-an-ajax-call-in-flask . Thanks !-->
<!--Nice file input code from http://www.abeautifulsite.net/whipping-file-inputs-into-shape-with-bootstrap-3/ . Thanks -->
<!--unix2web is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Foobar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with unix2web. If not, see <http://www.gnu.org/licenses/>.-->
<head>
<title>Test unix2web page</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="index.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<script>
$(document).on('change', '.btn-file :file', function() {
var input = $(this),
numFiles = input.get(0).files ? input.get(0).files.length : 1,
label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
input.trigger('fileselect', [numFiles, label]);
});

$(document).ready( function() {
$('.btn-file :file').on('fileselect', function(event, numFiles, label) {

var input = $(this).parents('.input-group').find(':text'),
log = numFiles > 1 ? numFiles + ' files selected' : label;

if( input.length ) {
input.val(log);
} else {
if( log ) alert(log);
}

});
});
//from https://stackoverflow.com/questions/18334717/how-to-upload-a-file-using-an-ajax-call-in-flask
$(function() {
$('#upload-file-btn').click(function(e) {
e.preventDefault() //Took me ages to find this. Thanks to https://stackoverflow.com/questions/20238452/staying-on-page-depending-on-value-jquery
var form_data = new FormData($('#upload-file')[0]);
$.ajax({
type: 'POST',
url: '/',
data: form_data,
contentType: false,
cache: false,
processData: false,
async: false,
success: function(data) {
console.log(data);
$('#stderr').text(data['stderr']);
$('#outputfile').text(data['outputfile_url']);
$('#outputfile').attr('href',data['outputfile_url']);
},
error: function(data){
console.log('error')
},
});
});
});
</script>
</head>
<body class="container">
<div class="row jumbotron">
<h1>unix2web</h1>
<p>Make any UNIX filter accessible wia the web. For demo purposes we use a simple sed one liner that changes
all instances of "the web" to "UNIX" and echoes the date on stderr :
<code>(date>&2; sed s/the web/UNIX/gI <input)>output</code>.</p>
</div>
<form action="" method=post enctype=multipart/form-data id="upload-file">
<div class="row">
<div class="col-md-8 col-md-offset-1">
<div class="input-group">
<span class="input-group-btn">
<span class="btn btn-primary btn-file">
Input file&hellip; <input type="file" name="file" multiple>
</span>
</span>
<input type="text" class="form-control" readonly>
</div>
</div>
<div class='col-md-1'>
<button id="upload-file-btn" class="btn btn-success">Run !</button>
</div>
</div>
</form>
<div class="row">
<div class="col-md-10 col-md-offset-1">
<pre id="stderr" style="margin-top:1em;"></pre>
</div>
</div>
<div class="row">
<div class="col-md-8 col-md-offset-1">
Output file : <a id="outputfile" href=""></a>
</div>
</div>
<div class="row">
<div class="col-md-8 col-md-offset-1">
Output file : <a id="outputfile" href=""></a>
</div>
</div>
<a href="https://github.com/edouardklein/unix2web"><img style="position: absolute; top: 0; left: 0; border: 0;" src="https://camo.githubusercontent.com/82b228a3648bf44fc1163ef44c62fcc60081495e/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f6c6566745f7265645f6161303030302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_left_red_aa0000.png"></a>
</body>
</html>
17 changes: 17 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This will install the web-app on a ubuntu server
# intallation instructions follow recipe given here http://blog.garethdwyer.co.za/2013/07/getting-simple-flask-app-running-on.html . Thanks !

APPNAME=unix2web
INSTALLDIR=/var/www/$APPNAME
sudo yes | apt-get install apache2 libapache2-mod-wsgi python-flask
sudo mkdir -p $INSTALLDIR
sudo mv /tmp/index.html $INSTALLDIR/
sudo mv /tmp/index.css $INSTALLDIR/
sudo mv /tmp/$APPNAME.py $INSTALLDIR/
sudo mv /tmp/$APPNAME.wsgi $INSTALLDIR/
sudo mv /tmp/100$APPNAME.conf /etc/apache2/sites-available
sudo a2dissite 000-default
sudo a2ensite 100$APPNAME
sudo /etc/init.d/apache2 restart


Loading

0 comments on commit 3f1b6e2

Please sign in to comment.