eev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[eev] basic CGIs


From: Eduardo Ochs
Subject: [eev] basic CGIs
Date: Mon, 11 Jul 2005 17:00:34 -0000

Hi, here's some code that I've been using to (re-)learn about CGIs.
The first block is to be run with F3, the second with F9s.

I've heard wonders about Ruby on Rails, and I'd like to have something
like this for Rails. There's something like this implemented for PHP
already - see:

    (find-eevex "php.e")
    (find-eev "eev-langs.el" "eephp")

By the way, what made me ressurect this code for CGIs was that I
realized that using JavaScript in web pages we could have HTML pages
with hyperlinks that would look nice on a graphical browser (say:
FireFox) and the action of those hyperlinks would be to do something
on a running Emacs. So, I've been working mostly on the "Emacs ->
other programs" direction, but in this case I'm doing smething in the
"FireFox -> Emacs" direction.

A link to

    javascript:e(e('(find-node "(emacs)Lisp Eval")')

is quite readable when displayed on the bottom of the FireFox window
(i.e., at that space where hyperlink targets are shown) and when
followed it would open, say, this page:

    http://127.0.0.1/cgi-bin/gnudoit.cgi?(find-node "(emacs)Lisp Eval")
                                         \----------------------------/
                                         %-encoded in the right way

and then gnudoit.cgi would verify that the connection comes from
127.0.0.1 and would invoke gnudoit (as the user "edrx") to run
`(find-node "(emacs)Lisp Eval")' in edrx's Emacs session.

Note that we could dispense with the JavaScript and use links whose
targets would be like this:

    http://127.0.0.1/cgi-bin/gnudoit.cgi?(find-node "(emacs)Lisp Eval")
                                         \----------------------------/
                                         %-encoded

but the "javascript:e('...')" version looks a bit cleaner, and why
not.

  Cheers,
    Edrx.



#####
#
# runtmpcgi
# 2005jun15
#
#####

#
# «runtmpcgi»
# Taken from: http://angg.twu.net/.zshrc.html#runtmpcgi
#
export EECGIFILE=/usr/lib/cgi-bin/tmp.cgi
export EECGIURL=http://127.0.0.1/cgi-bin/tmp.cgi
function tmpcgi () {
  wget -q -O - $EECGIURL$1 $*[2,-1]
}
function runtmpcgi () {
  cat     > $EECGIFILE
  chmod 755 $EECGIFILE
  tmpcgi $*
}
function runperltcgi () {
  { echo '#!/usr/bin/perl'
    echo -E 'print "Content-type: text/plain\n\n";'
    cat } | runtmpcgi $*
}
function runbashcgi () {
  { echo '#!/bin/bash'
    echo -E 'echo -e "Content-type: text/plain\n"'
    cat } | runtmpcgi $*
}
function runluacgi () {
  { echo "#!$(which lua50)"
    echo -E 'print("Content-type: text/plain\n")'
    cat } | runtmpcgi $*
}

#



#####
#
# cgis
# 2005jun15
#
#####

# (find-efunction 'eehtml)
# (find-angg ".zshrc" "runtmpcgi")
# (find-fline "~/.xchat2/downloads/")

 (eechannel-xterm "A")
sudo rm -v $EECGIFILE
sudo touch $EECGIFILE
sudo chown $USER:$USER $EECGIFILE

echo date | runbashcgi
echo set  | runbashcgi
echo set  | runbashcgi '?foo'
echo '
  echo REMOTE_ADDR=$REMOTE_ADDR
  echo QUERY_STRING=$QUERY_STRING
' | runbashcgi '?%28find-file%20%22%2Ftmp%2Ffoo%22%29'

echo 'print("hi")' | runluacgi
echo '
  hextochar = function (s) return string.char(tonumber(s, 16)) end
  unescape  = function (s) return string.gsub(s, "%%(%x%x)", hextochar)
  end
  q = unescape(os.getenv("QUERY_STRING"))
  print(q)
' | runluacgi '?A%40%20B'

QUERY_STRING=A%40B \
  $EECGIFILE

# (find-Lua50ref "")
# (find-Lua50ref "character class" "%x")
# (find-Lua50ref "string.gsub (s, pat, repl [, n])" "os.getenv")
# (find-Lua50ref "os.execute (command)")
# (find-node "(libc)Running a Command")

-- 
http://www.fastmail.fm - Send your email first class






reply via email to

[Prev in Thread] Current Thread [Next in Thread]