diff --git a/lib/ulib/cgi b/lib/ulib/cgi index de86837..4c59d8f 100644 --- a/lib/ulib/cgi +++ b/lib/ulib/cgi @@ -32,6 +32,13 @@ function nocache_header() { echo "Expires: Thu, 01 Jan 1970 00:00:00 GMT" } +function cgiredirect() { + # Rediriger le client vers une autre page + echo "Status: 302 Found" + echo "Location: $1" + echo "" +} + function cgicontent() { # Générer les en-têtes nécessaire avant de servir le contenu. # $1(=text/html) est le type de contenu. S'il faut servir le contenu avec @@ -71,3 +78,9 @@ function cgicontent_nocache() { echo "" [ -f "$contentfile" ] && cat "$contentfile" } + +function cgierror() { + # Afficher un message d'erreur + cgicontent_nocache text/plain + echo "ERROR: $*" +} diff --git a/lib/ulib/cgilsxml b/lib/ulib/cgilsxml deleted file mode 100644 index 8e78929..0000000 --- a/lib/ulib/cgilsxml +++ /dev/null @@ -1,8 +0,0 @@ -##@cooked comments # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 -## Fonction de support pour cgilsxml -##@cooked nocomments -##@require ulib -uprovide cgilsxml -urequire ulib - -function cgilsxml() { "$ULIBDIR/support/cgilsxml.py" "$@"; } diff --git a/lib/ulib/cgiupload b/lib/ulib/cgisupport similarity index 51% rename from lib/ulib/cgiupload rename to lib/ulib/cgisupport index 3d6e4d9..21caa89 100644 --- a/lib/ulib/cgiupload +++ b/lib/ulib/cgisupport @@ -1,8 +1,10 @@ ##@cooked comments # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 -## Fonction de support pour cgiupload +## Fonction de support pour faire des scripts CGI ##@cooked nocomments ##@require ulib -uprovide cgiupload +uprovide cgisupport urequire ulib +function cgiparams() { "$ULIBDIR/support/cgiparams.py" "$@"; } +function cgilsxml() { "$ULIBDIR/support/cgilsxml.py" "$@"; } function cgiupload() { "$ULIBDIR/support/cgiupload.py" "$@"; } diff --git a/lib/ulib/support/cgiparams.py b/lib/ulib/support/cgiparams.py new file mode 100755 index 0000000..1087b89 --- /dev/null +++ b/lib/ulib/support/cgiparams.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python +# -*- coding: utf-8 mode: python -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 + +u"""Ce script est prévu pour être utilisé dans un script CGI. + +Il permet de lister les paramètres du formulaire et d'y accéder depuis un script bash +""" + +import re, cgi + +RE_NAME_VALUE = re.compile(r'([a-zA-Z0-9_-]+)(?:=(.*))?$') + +def quote(value, q=False): + if value or q: + value = "'%s'" % value.replace("'", "'\\''") + value = re.sub(r"(?