diff --git a/CHANGES.txt b/CHANGES.txt index 8515765..8ec3187 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,7 @@ +## Version 3.0.0 du 24/12/2015-15:39 + +4b1c30b nouvelles fonctions pour le module cgi. cgilsxml, cgiupload et cgiparams sont rassemblés dans le module cgisupport + ## Version 2.26.0 du 24/12/2015-12:17 d5a2cce cgilsxml.py: rajouter la variable env/query_vars diff --git a/VERSION.txt b/VERSION.txt index 7a25c70..4a36342 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -2.26.0 +3.0.0 diff --git a/lib/ulib/.ulibver b/lib/ulib/.ulibver index e24b6c4..6435415 100644 --- a/lib/ulib/.ulibver +++ b/lib/ulib/.ulibver @@ -1 +1 @@ -009011000 +010000000 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"(?