diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2015-01-10 20:14:14 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2015-01-10 20:14:14 +0200 |
commit | 1c22a86e073d57c4b35ac5b7ffea07aa541141c4 (patch) | |
tree | c90f3fc758b5dfc2f8e8fd64f2ef0a87343b3e50 | |
parent | 2b99881a880d101ae32a94b3d1e0a792224cb74c (diff) | |
download | ellinika-1c22a86e073d57c4b35ac5b7ffea07aa541141c4.tar.gz ellinika-1c22a86e073d57c4b35ac5b7ffea07aa541141c4.tar.bz2 |
Make it possible to use apache rewrite rules to create nice cgi urls
Example: configure with options: --without-script-suffix
--without-script-dir, and add the following to the Apache
virtual host configuration:
RewriteEngine on
RewriteRule ^/dict(.*) /cgi-bin/dict.cgi$1 [H=cgi-script]
RewriteRule ^/nea(.*) /cgi-bin/nea.cgi$1 [H=cgi-script]
RewriteRule ^/conj(.*) /cgi-bin/conj.cgi$1 [H=cgi-script]
All cgi's will then be referred to directly, as in:
http://ellinika/dict?lang=pl.
* configure.ac (REAL_SCRIPT_SUFFIX): New subst var
New options --with-script-suffix, --with-script-dir
* src/cgi-bin/.gitignore: Remove cgi
* src/cgi-bin/Makefile.am: Rename installed scm's in place
* src/ellinika/cgi.scm4 (cgi-program-name): Suffix can be empty.
* xml/lingua.conf.in: =SCRIPT_SUFFIX= always begins with dot
-rw-r--r-- | configure.ac | 33 | ||||
-rw-r--r-- | src/cgi-bin/.gitignore | 2 | ||||
-rw-r--r-- | src/cgi-bin/Makefile.am | 27 | ||||
-rw-r--r-- | src/ellinika/cgi.scm4 | 2 | ||||
-rw-r--r-- | xml/lingua.conf.in | 6 |
5 files changed, 48 insertions, 22 deletions
diff --git a/configure.ac b/configure.ac index 302f2df..7cdcc32 100644 --- a/configure.ac +++ b/configure.ac @@ -14,13 +14,13 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # AC_PREREQ(2.61) -AC_REVISION(2015-01-07 14:56:15 gray) +AC_REVISION(2015-01-10 19:52:52 gray) AC_INIT(ellinika, 1.99.99, [gray+ellinika@gnu.org.ua]) AC_CONFIG_SRCDIR(src/cgi-bin/dict.scm4) AC_CONFIG_AUX_DIR([build-aux]) AC_CANONICAL_SYSTEM AM_INIT_AUTOMAKE([1.11 silent-rules no-exeext]) AM_CONFIG_HEADER([config.h]) @@ -104,30 +104,53 @@ AC_ARG_VAR([PROD_URL], [URL for the production site]) AC_ARG_VAR([EXP_URL], [URL for the experimental site]) AC_ARG_VAR([STATE], [EXP for experimental, PROD for production]) +AC_SUBST(REAL_SCRIPT_SUFFIX) AC_SUBST(SCRIPT_SUFFIX) AC_SUBST(SCRIPT_DIR) AC_SUBST(CGIDIR) if test $APACHE_IFACE = "CGI"; then - SCRIPT_SUFFIX=cgi + REAL_SCRIPT_SUFFIX=.cgi if test -n "$TARGET_DIR"; then SCRIPT_DIR=cgi-bin else SCRIPT_DIR=/cgi-bin fi CGIDIR='$(prefix)/cgi-bin' else - SCRIPT_SUFFIX=scm + REAL_SCRIPT_SUFFIX=.scm SCRIPT_DIR=scm CGIDIR='$(prefix)/scm' -fi - +fi + +AC_ARG_WITH(script-suffix, + AC_HELP_STRING([--with-script-suffix=.STRING], + [CGI script suffix]), + [if test -z "$withval"; then + SCRIPT_SUFFIX= + else + case $withval in + no) SCRIPT_SUFFIX=;; + .*) SCRIPT_SUFFIX=$withval;; + *) AC_MSG_ERROR([script suffix must begin with dot]) + esac + fi], + [SCRIPT_SUFFIX=$REAL_SCRIPT_SUFFIX]) + +AC_ARG_WITH(script-dir, + AC_HELP_STRING([--with-script-dir=DIR], + [script directory prefix]), + [case $withval in + no) SCRIPT_DIR=;; + *) SCRIPT_DIR=$withval;; + esac]) + AC_ARG_WITH(cgi-bin, AC_HELP_STRING([--with-cgi-bin=DIR], [install CGI programs in DIR [[PREFIX/cgi-bin]]]), [CGIDIR=$withval]) dnl Check for Emacs site-lisp directory diff --git a/src/cgi-bin/.gitignore b/src/cgi-bin/.gitignore index a2d76a3..21128b6 100644 --- a/src/cgi-bin/.gitignore +++ b/src/cgi-bin/.gitignore @@ -1,7 +1,5 @@ -dict.cgi dict.m4 dict.scm dict.sed -nea.cgi nea.scm conj.scm diff --git a/src/cgi-bin/Makefile.am b/src/cgi-bin/Makefile.am index f085e57..aca9137 100644 --- a/src/cgi-bin/Makefile.am +++ b/src/cgi-bin/Makefile.am @@ -11,16 +11,17 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -cgidir=@CGIDIR@ -cgi_SCRIPTS=$(EXTRA_DIST:.scm4=.@SCRIPT_SUFFIX@) -EXTRA_DIST=dict.scm4 nea.scm4 conj.scm4 -CLEANFILES=dict.m4 dict.scm nea.scm dict.cgi nea.cgi conj.cgi +cgidir = @CGIDIR@ +CGI_SOURCES = dict.scm4 nea.scm4 conj.scm4 +EXTRA_DIST = $(CGI_SOURCES) +cgi_SCRIPTS = $(CGI_SOURCES:.scm4=.scm) +CLEANFILES = dict.m4 $(cgi_SCRIPTS) dict.m4: Makefile $(AM_V_GEN){ \ echo 'divert(-1)'; \ echo 'changequote([,])'; \ echo 'changecom([;],['; \ @@ -40,21 +41,25 @@ dict.m4: Makefile echo ')dnl'; \ echo '@AUTOGENERATED@'; \ echo 'ifelse(IFACE,[CGI],!#'; \ echo ')dnl'; \ } > dict.m4 -SUFFIXES = .scm4 .scm .cgi +SUFFIXES = .scm4 .scm .scm4.scm: $(AM_V_GEN)m4 dict.m4 $< > $@ -.scm.cgi: - $(AM_V_GEN)cp $< $@ - dict.scm: dict.scm4 dict.m4 nea.scm: nea.scm4 dict.m4 conj.scm: conj.scm4 dict.m4 -dict.cgi: dict.scm -nea.cgi: nea.scm -conj.cgi: conj.scm +install-data-hook: + $(AM_V_GEN)if test @REAL_SCRIPT_SUFFIX@ != .scm; then\ + here=`pwd`; \ + cd $(DESTDIR)$(cgidir); \ + for file in $(cgi_SCRIPTS); do\ + mv $$file $${file%%.scm}@REAL_SCRIPT_SUFFIX@;\ + done;\ + cd $$here;\ + fi + diff --git a/src/ellinika/cgi.scm4 b/src/ellinika/cgi.scm4 index 51f9570..28adea1 100644 --- a/src/ellinika/cgi.scm4 +++ b/src/ellinika/cgi.scm4 @@ -124,13 +124,13 @@ ifelse(IFACE,[CGI],[ arglist (cons "?" arglist)))))) (define-public (cgi-program-name prog) (string-append (substring cgi-script-name 0 (string-rindex cgi-script-name #\/)) "/" - prog ".SCRIPT_SUFFIX")) + prog ifelse(SCRIPT_SUFFIX,,,"SCRIPT_SUFFIX"))) (define-public (expand-template explist template) "(expand-template EXPLIST TEMPLATE) Expands string TEMPLATE in accordance with EXPLIST. EXPLIST is a list of elements: diff --git a/xml/lingua.conf.in b/xml/lingua.conf.in index d736bcb..87f40e3 100644 --- a/xml/lingua.conf.in +++ b/xml/lingua.conf.in @@ -6,13 +6,13 @@ <DIRECTORY OUT="=OUTDIR=" /> <DIRECTORY TARGET="=TARGET_DIR=" /> <DIRECTORY SOUND="=TARGET_DIR=/sound" /> <AUTHOR EMAIL="=PACKAGE_BUGREPORT=" HOMEPAGE="http://gray.gnu.org.ua" /> - <DICT PROG="dict.=SCRIPT_SUFFIX=" /> + <DICT PROG="dict=SCRIPT_SUFFIX=" /> <BASE HREF="=BASE_HREF=" /> <SEARCH ARGS="(list (lingua:gettext "Search") (lingua:attr "LINGUA" "LANG"))"> <![CDATA[ <form method="get" action="/search" enctype="application/x-www-form-urlencoded"> @@ -33,23 +33,23 @@ (define-macro (install-nea) `(use-modules (xmltrans lingua) (xmltools dict)) (letrec ((nea (lambda (. args) (string-append (lingua:get-cgi-bin) - "/nea.=SCRIPT_SUFFIX=?lang=" + "/nea=SCRIPT_SUFFIX=?lang=" (lingua:LANG args))))) (xmltrans:set-attr "LINGUA" "NEA" nea))) (define-macro (install-conj) `(use-modules (xmltrans lingua) (xmltools dict)) (letrec ((conj (lambda (. args) (string-append (lingua:get-cgi-bin) - "/conj.=SCRIPT_SUFFIX=?lang=" + "/conj=SCRIPT_SUFFIX=?lang=" (lingua:LANG args))))) (xmltrans:set-attr "LINGUA" "CONJ" conj))) (define-macro (install-srch) `(letrec ((srch (lambda (. args) (string-append "/search?l=" (lingua:LANG args))))) |