diff --git a/doc/MANUAL.md b/doc/MANUAL.md index 7c97072..b65a004 100644 --- a/doc/MANUAL.md +++ b/doc/MANUAL.md @@ -2,15 +2,27 @@ This is the manual for version %%VERSION%%. + + + ## Table of Contents 1. [Introduction](#intro) - [Terminology](#intro_terminology) +1. [Installation](#inst) + - [Debian / Ubuntu](#inst_debian) + - [Redhat / Centos](#inst_redhat) + - [Other](#inst_other) 1. [Invocations](#invocations) - [Shell foreground](#invocations_foreground) - [Daemon](#invocations_daemon) - [Init script](#invocations_init) + * [Debian / Ubuntu](#invocations_init_debian) + * [RedHat / Centos](#invocations_init_redhat) - [Behind Apache](#invocations_apache) +1. [Tutorial](#tutorial) + - [Your first form](#tutorial_firstform) + - [Output types](#tutorial_output) 1. [Form config (JSON) files](#form_config) 1. [Field types](#field_types) - [String](#field_types_string) @@ -38,6 +50,10 @@ This is the manual for version %%VERSION%%. - [Custom CSS](#cust_css) 1. [Security](#security) + + + + ## Introduction Scriptform is a stand-alone webserver that automatically generates forms from @@ -49,6 +65,74 @@ user can select a form and fill it out. When the user submits the form, it is validated and the associated script is called. Data entered in the form is passed to the script through the environment. + + + + +## Installation and configuration + +### Requirements + +ScriptForm requires: + +* Python 2.6+ + +No other libraries are required. Python v2.6+ is generally available by default +on almost every major linux distribution. For other platforms Python is almost +certainly available. + +### Debian / Ubuntu + +Download the .deb package from: + +https://github.com/fboender/scriptform/releases + +Either double-click the package in a file browser or open up a terminal and type: + + $ cd Downloads/ + $ sudo dpkg -i scriptform-*.deb + +Scriptform is now installed. For the next steps, see: + +* The tutorial on how to write form configuration files. +* Invocations for how to run Scriptform and how to start it at boot time + +### RedHat / Centos + +Download the .rpm package from: + +https://github.com/fboender/scriptform/releases + +Open up a terminal and type: + + $ cd Downloads/ + $ sudo rpm -i scriptform-*.rpm + +Scriptform is now installed. For the next steps, see: + +* The tutorial on how to write form configuration files. +* Invocations for how to run Scriptform and how to start it at boot time + +### Other Unix-like Operating Systems + +Install Python v2.6+. + +Download the .tar.gz package from: + +https://github.com/fboender/scriptform/releases + +Open up a terminal and type: + + $ cd Downloads/ + $ tar -vxzf scriptform-*.tar.gz + $ cd scriptform-X.Y + $ sudo make install + +Scriptform is now installed. For the next steps, see: + +* The tutorial on how to write form configuration files. +* Invocations for how to run Scriptform and how to start it at boot time + ### Terminology Scriptform uses various terminology to distinguish between different components @@ -66,6 +150,9 @@ of the application. variety of different field types, such as 'string', 'integer', 'date', etc. + + + ## Invocations Upon starting Scriptform, it will change the working directory to the path @@ -107,6 +194,8 @@ specify at least the `--pid-file` option, if the daemon was started with one. ### Init script +#### Debian / Ubuntu + An example init script is provided in the *contrib* directory. For the Debian package, you can find it in `/usr/share/doc/scriptform/`. To install it on Debian-derived systems: @@ -124,6 +213,30 @@ Finally, start it: sudo /etc/init.d/scriptform start +#### RedHat / CentOs + +Install the init script: + + sudo cp /usr/share/doc/scriptform/scriptform.init.d_redhat /etc/init.d/scriptform + sudo chmod 755 /etc/init.d/scriptform + +Then, edit the init script so it points to your form configuration file: + + sudo vi /etc/init.d/scriptform + FORM_CONFIG="/usr/local/scriptform/myscript/myscript.json + +Finally, enable the init script to run at boot time: + + sudo chkconfig --add scriptform + sudo chkconfig scriptform on + +Now we can start it: + + sudo /etc/init.d/scriptform start + Starting scriptform: + + + ### Behind Apache Scriptform does not support HTTPS / SSL, so for production environments you @@ -148,6 +261,140 @@ Otherwise, you may encounter the following error: + TypeError: index() got an unexpected keyword argument 'form_name' + + + +## Tutorial + +### Your first form + +This tutorial assumes you've already installed Scriptform on your system. + +Let's start off by creating a new form configuration file. Create a directory: + + $ mkdir sf_tutorial + $ cd sf_tutorial + +Edit a new file called `sf_tutorial.json` in your favorite editor and put the +following in: + + + { + "title": "Tutorial", + "forms": [ + { + "name": "System information", + "title": "System information", + "description": "Show information about the operating system", + "script": "job_sysinfo.sh", + "fields": [] + } + ] + } + +This is a form configuration with a single form definition "System +information". The form has no fields; we'll get to that later. First, let's +implement the `job_sysinfo.sh` script so we can perform a form callback. + +Edit a new file in the same directory called `job_sysinfo.sh`: + + #!/bin/sh + + HOSTNAME=$(hostname -f) + MEM=$(free -h) + DISK=$(df -h) + + cat << END_OF_TEXT + Hostname + ======== + + $HOSTNAME + + + Memory + ====== + + $MEM + + + Disk + ==== + + $DISK + END_OF_TEXT + +Fix the permisions so it is executable: + + $ chmod 755 ./job_sysinfo.sh + +Now start Scriptform with our newly created form configuration file: + + $ scriptform -p8000 -f -r ./sf_tutorial.json + +This starts the built-in webserver which will serve the form on port 8000. When +you open it in your browser (http://127.0.0.1:8000/) you will immediately see +the form. If we had multiple forms in this form configuration, you would first +see a list of all the forms. + +The `-p` option controls the port on which Scriptform will listen. Normally, +Scriptform would go into the background and run as a daemon. We can surpress +this with the `-f` (foreground) switch, which makes it easier to stop +Scriptform by pressing Ctrl-c. The `-r` option tells Scriptform to reload the +form configuration file on each request. This makes development much easier, +since you won't have to stop and restart Scriptform whenever you make a change. + + +### Output types + +The output of our first form isn't exactly good-looking. We can change that by +changing the output type of our form. There are three types: escaped, html and +raw. Let's change our output to HTML. + +Open the `sf_tutorial.json` file and add an `output` property to the form: + + ... + "script": "job_sysinfo.sh", + "output": "html", + "fields": [] + ... + +Now modify the `job_sysinfo.sh` script to output HTML instead of plain text: + + cat << END_OF_TEXT +
$HOSTNAME+ +
$MEM+ +
$DISK+ END_OF_TEXT + +Open http://127.0.0.1:8000 in your browser and submit the form. That looks a +little better, doesn't it? The `html` output type lets you embed HTML in the +output of the script. The default output type is `escaped`, which escaped any +HTML and just outputs plain text wrapped in a Scriptform response header and +footer. The last output type is `raw`, in which case Scriptform will send the +*exact* output of your script directly to the browser. This means your script +should not just output a result, but also the required HTTP headers to properly +display it. This lets your send binary files (images, downloads, etc) to the +browser. + +### Fields + +As you've seen, we've kept the `fields` option empty in the previous examples. +The `fields` option lets us specify input fields that will appear in the form. +Every field has at least a `name`, `title` and `type`. Many fields support +additional options for validation, etc. + +The simplest is the `string` field. This field type simply lets the user enter +a value. Put the following in the `sf_tutorial.json` file, replacing the +original content: + + + + ## Form config (JSON) files Forms are defined in JSON format. They are referred to as *Form config* @@ -292,6 +539,9 @@ For example, here's a form config file that contains two forms: Many more examples can be found in the `examples` directory in the source code. + + + ## Field types Scriptform supports multiple field types. Field types determine what users may @@ -458,6 +708,33 @@ For example: ### Select +The `select` field presents the user with a dropdown list from which they can +pick a value. + +The `select` field type supports the following additional options: + +- **`options`**: A list of available options from which the user can choose. + Each item in the list is itself a list of two values: the value and the + title. + +For example + + ... + "fields": [ + { + "name": "source_sql", + "title": "Load which kind of database?", + "type": "select", + "options": [ + ["empty", "Empty database"], + ["dev", "Development test database"], + ["ua", "Acceptance database"] + ] + } + ] + ... + + ### Text The `text` field presents the user with a field in which they can enter @@ -521,6 +798,9 @@ For example: ] ... + + + ## Output **All output is assumed to be UTF8, regardless of system encoding!** @@ -588,6 +868,9 @@ Scriptform does not provide the browser with a content-type of the file, since it is impossible to guess. Generally, browsers do a decent job at figuring it out themselves. + + + ## Script execution When the user submits the form, Scriptform will validate the provided values. @@ -662,6 +945,8 @@ Examples of file uploads can be found in the `examples/simple` and `examples/megacorp` directories. + + ## Users ScriptForm supports basic htauth user authentication. Users can be defined, and @@ -717,6 +1002,9 @@ For an example, see the [beginning of this chapter](#users). *does* support HTTPS, such as Apache. For more information on that, see the "Invocations" chapter. + + + ## Form customization ### Custom CSS @@ -753,6 +1041,9 @@ the form configuration file's location. For a good example, see the `examples/customize/` directory in the source. + + + ## Security There are a few security issues to take into consideration when deploying Scriptform: @@ -765,10 +1056,9 @@ There are a few security issues to take into consideration when deploying Script - Scriptform does not natively support secure HTTPS connections. This means usernames and passwords are transmitted over the line in nearly plain text. - If - you wish to prevent this, you should put Scriptform behind a proxy that - *does* support HTTPS, such as Apache. For more information on that, see - the "Invocations" chapter. + If you wish to prevent this, you should put Scriptform behind a proxy that + *does* support HTTPS, such as Apache. For more information on that, see the + "Invocations" chapter. - Scriptform logs the invocation of scripts and variables to the log file for auditing purposes.