From ffda932161a92e17ff989770a184027ba3646550 Mon Sep 17 00:00:00 2001 From: Ferry Boender Date: Thu, 19 Mar 2015 10:21:50 +0100 Subject: [PATCH] Simple example. --- examples/simple/htaccess | 0 examples/simple/job_add_user.sh | 29 +++++++++++++++++++ examples/simple/job_import.sh | 7 +++++ examples/simple/simple.json | 50 +++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 examples/simple/htaccess create mode 100755 examples/simple/job_add_user.sh create mode 100755 examples/simple/job_import.sh create mode 100644 examples/simple/simple.json diff --git a/examples/simple/htaccess b/examples/simple/htaccess new file mode 100644 index 0000000..e69de29 diff --git a/examples/simple/job_add_user.sh b/examples/simple/job_add_user.sh new file mode 100755 index 0000000..e3114ee --- /dev/null +++ b/examples/simple/job_add_user.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +HTACCESS=htaccess + +err() { + echo $* >&2 + exit 1 +} + +if [ -z "$password1" ]; then + err "Empty password specified" +fi +if [ "$password1" != "$password2" ]; then + err "Passwords do not match." +fi + +if [ $(egrep "^$username:" $HTACCESS) ]; then + UPDATE=1 +else + UPDATE=0 +fi + +htpasswd -s -b $HTACCESS $username $password1 || exit $? + +if [ "$UPDATE" -eq 1 ]; then + echo "User password updated" +else + echo "User created" +fi diff --git a/examples/simple/job_import.sh b/examples/simple/job_import.sh new file mode 100755 index 0000000..0d14471 --- /dev/null +++ b/examples/simple/job_import.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +MYSQL_DEFAULTS_FILE="my.cnf" +MYSQL="mysql --defaults-file=$MYSQL_DEFAULTS_FILE" + +echo "echo 'DROP DATABASE scriptform_acc' | $MYSQL" +echo "$MYSQL < dbs/${sample_db}.sql" diff --git a/examples/simple/simple.json b/examples/simple/simple.json new file mode 100644 index 0000000..a899499 --- /dev/null +++ b/examples/simple/simple.json @@ -0,0 +1,50 @@ +{ + "title": "Test server", + "forms": { + "import": { + "title": "Import data", + "description": "Import CSV data into a database", + "submit_title": "Import", + "script": "job_import.sh", + "fields": [ + { + "name": "target_db", + "title": "Database to import to", + "type": "select", + "options": [ + ["devtest", "Dev Test db"], + ["prodtest", "Prod Test db"] + ] + }, + { + "name": "csv_file", + "title": "CSV file", + "type": "file" + } + ] + }, + "add_user": { + "title": "Add user", + "description": "Add a user to the htaccess file or change their password", + "submit_title": "Add user", + "script": "job_add_user.sh", + "fields": [ + { + "name": "username", + "title": "Username", + "type": "string" + }, + { + "name": "password1", + "title": "Password", + "type": "password" + }, + { + "name": "password2", + "title": "Password (Repear)", + "type": "password" + } + ] + } + } +}