Permalink
Browse files

Added CGI documentation including a new page http://yaws.hyber.org/cg…

  • Loading branch information...
1 parent 91a5018 commit 7cd40802df98ce6454bdc1003bb126a354cda3a4 @klacke committed Mar 10, 2008
Showing with 109 additions and 7 deletions.
  1. +1 −1 scripts/yaws.conf.template
  2. +2 −1 src/Makefile
  3. +14 −0 src/yaws_appmod_cgi.erl
  4. +5 −3 src/yaws_cgi.erl
  5. +1 −2 src/yaws_server.erl
  6. +1 −0 www/TAB.inc
  7. +8 −0 www/cgi-bin/foo.py
  8. +77 −0 www/cgi.yaws
@@ -125,14 +125,14 @@ use_fdsrv = false
port = %port%
listen = 0.0.0.0
docroot = %docroot%
+ appmods = <cgi-bin, yaws_appmod_cgi>
</server>
<server localhost>
port = %port%
listen = 0.0.0.0
docroot = /tmp
dir_listings = true
- dav = true
<auth>
realm = foobar
dir = /
View
@@ -36,7 +36,8 @@ MODULES=yaws \
json jsonrpc yaws_jsonrpc yaws_xmlrpc\
haxe yaws_rpc \
yaws_soap_srv yaws_soap_lib \
- authmod_gssapi
+ authmod_gssapi \
+ yaws_appmod_cgi
EBIN_FILES=$(MODULES:%=../ebin/%.$(EMULATOR)) ../ebin/yaws.app
View
@@ -0,0 +1,14 @@
+%%% File : yaws_appmod_cgi.erl
+%%% Author : Claes Wikstrom <klacke@hyber.org>
+%%% Description :
+%%% Created : 10 Mar 2008 by Claes Wikstrom <klacke@hyber.org>
+
+-module(yaws_appmod_cgi).
+-export([out/1]).
+-include("../include/yaws_api.hrl").
+
+out(Arg) ->
+ yaws_cgi:call_cgi(Arg, lists:flatten(Arg#arg.fullpath)).
+
+
+
View
@@ -83,8 +83,8 @@ start_worker(Arg, Exefilename, Scriptfilename, Pathinfo, ExtraEnv, SC) ->
undefined -> Arg#arg.pathinfo;
OK -> OK
end,
- Worker = spawn(?MODULE, cgi_worker,
- [self(), Arg, ExeFN, Scriptfilename, PI, ExtraEnv, SC]),
+ Worker = proc_lib:spawn(?MODULE, cgi_worker,
+ [self(), Arg, ExeFN, Scriptfilename, PI, ExtraEnv, SC]),
Worker.
@@ -456,7 +456,9 @@ do_work(Parent, Arg, Port) ->
header_loop(Parent, Arg, {start, Port}).
header_loop(Parent, Arg, S) ->
- case get_line(S) of
+ Line = get_line(S),
+ ?Debug("Line = ~p~n", [Line]),
+ case Line of
{failure, F} ->
Parent ! {self(), failure, F};
{[], T} ->
View
@@ -658,7 +658,6 @@ ssl_opts(GC, SC, SSL) ->
{ip, SC#sconf.listen},
{packet, http},
{active, false} | ssl_opts(GC, SSL)],
- io:format("OPTS ~p~n", [Opts]),
Opts.
@@ -702,7 +701,7 @@ ssl_opts(GC, SSL) ->
if ?gc_use_old_ssl(GC) ->
false;
true ->
- %{ssl_imp, new}
+ %{ssl_imp, new} .... doesn't work yet
false
end
],
View
@@ -54,6 +54,7 @@ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<div class="%%haxe_intro%%"> <a href="/haxe_intro.yaws">haXe remoting</a></div>
<div class="%%soap_intro%%"> <a href="/soap_intro.yaws">SOAP with Yaws</a></div>
<div class="%%yapp_intro%%"> <a href="/yapp_intro.yaws">Yaws applications</a></div>
+<div class="%%cgi%%"> <a href="/cgi.yaws">CGI</a></div>
<h4> Misc </h4>
<div class="%%internals%%"> <a href="/internals.yaws">Internals</a> </div>
View
@@ -0,0 +1,8 @@
+#!/usr/bin/python
+
+import cgi
+
+print "Content-type: text/html\n\n"
+
+print "hi there "
+
View
@@ -0,0 +1,77 @@
+
+<erl>
+
+
+box(Str) ->
+ {'div',[{class,"box"}],
+ {pre,[], yaws_api:htmlize(Str)}}.
+
+tbox(T) ->
+ box(lists:flatten(io_lib:format("~p",[T]))).
+
+
+out(A) ->
+ [{ssi, "TAB.inc", "%%",[{"cgi", "choosen"}]},
+ {ehtml,
+ {'div', [{id, "entry"}],
+
+ [{h1, [], "Plain CGI and PHP"},
+
+ {p,[],
+ "Yaws supports plain CGI just fine. the two most common ways to run yaws cgi script is either as regular cgi scripts or as php scripts through the typical php-cgi binary. Yaws chooses how to ship a file pased on file extension. Let's start with the php-cgi example. PHP files have the extension .php and if we enable php by indicating it in yaws.conf:"},
+ box("php_exe_path = /usr/bin/php-cgi"
+ ),
+ {p,[], "And then also ensure that we have enaable php processing for the individual server as in "},
+ box("
+
+<server www.hyber.org>
+ port = 80
+ listen = 0.0.0.0
+ allowed_scripts = php yaws cgi
+ ...."
+ ),
+ {p, [], "Yaws will invoke the php-cgi binary and talk the CGI protocol to the binary. "},
+
+ {p, [], "Another common situation is that we write our CGI scripts in e.g. python and use python libraries to speak the CGI protocol. The easiest way forward here is to rename the python scripts with the extension \".cgi\" as in this example:"
+ },
+
+ {p, [], " We have the following python file called foo.cgi"},
+ box("
+#!/usr/bin/python
+
+import cgi
+
+print \"Content-type: text/html\n\n\"
+print \"<h1>hi there </h1>\"
+ "),
+
+ {p, [], "Since the file ends with the magic suffix \".cgi\", Yaws will just invoke the file as an executable and speak CGI to it. Thus for this scheme to work we must also make the file exeutable"},
+
+ {p, [], "Yet another common scenario is when have a set of CGI files not ending with the \".cgi\" file extension. We can put all the CGI files in a common directory and define an appmod as follows:"},
+
+box("
+
+out(Arg) ->
+ yaws_cgi:call_cgi(Arg, lists:flatten(Arg#arg.fullpath)).
+
+"),
+
+{p, [], "and then configure the appmod appropriately in yaws.conf. The default yaws.conf file contains an entry"},
+box("
+ appmods = <cgi-bin, yaws_appmod_cgi>
+"),
+
+{p, [], "Thus if we put put any executable files in the \"cgi-bin\" directory under the docroot, Yaws will speak CGI to those executables."}
+
+
+
+]}},
+
+
+
+
+{ssi, "END2",[],[]}
+].
+
+</erl>
+

0 comments on commit 7cd4080

Please sign in to comment.