-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a simple tool to help run cgi scripts from the command line
Also fix garbage in .gitignore
- Loading branch information
Showing
3 changed files
with
58 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,34 +4,11 @@ Makefile | |
*.cmo | ||
*.cmx | ||
*.o | ||
*.byte | ||
*.opt | ||
config.cache | ||
config.log | ||
config.status | ||
opam-version: "2.0" | ||
version: "0.10" | ||
maintainer: "[email protected]" | ||
authors: [ | ||
"Daniel de Rauglaudre" | ||
"Jean-Christophe FILLIATRE" | ||
"Cedric Cellier" ] | ||
homepage: "https://www.lri.fr/~filliatr/ftp/ocaml/cgi/" | ||
bug-reports: "https://github.com/rixed/ocaml-cgi/issues" | ||
dev-repo: "git+https://github.com/rixed/ocaml-cgi.git" | ||
build: [ | ||
["./configure"] | ||
[make] | ||
] | ||
install: [make "install"] | ||
remove: [["ocamlfind" "remove" "cgi"]] | ||
depends: [ | ||
"ocaml" {> "4.01.0"} | ||
"ocamlfind" {build} | ||
] | ||
synopsis: "Library for writing CGIs" | ||
flags: light-uninstall | ||
url { | ||
src: "https://github.com/rixed/ocaml-cgi/archive/v0.10.tar.gz" | ||
checksum: "md5=1e1b9e4de0ba12688b4b66523f42125d" | ||
} | ||
runcgi | ||
configure.lineno | ||
autom4te.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
(* Runs a command with CGI related envvars set. *) | ||
|
||
let () = | ||
let meth = ref "GET" | ||
and typ = ref "text/plain" | ||
and body = ref "" | ||
and query = ref "" | ||
and cmd = ref [] in | ||
let default d h = h ^" (default: "^ String.escaped d ^")" in | ||
Arg.(parse | ||
[ "-method", Set_string meth, default !meth "HTTP method (likely GET or POST)" ; | ||
"-type", Set_string typ, default !typ "Content type" ; | ||
"-body", Set_string body, default !body "Content body" ; | ||
"-query", Set_string query, default !query "Query string (after the \"?\" in the URL, ex: \"x=1&y=2\")" ] | ||
(fun s -> cmd := s :: !cmd) | ||
"runcgi -method <meth> -type <type> -body <txt> -query <qry> command ...args...") ; | ||
let cmd = List.rev !cmd in | ||
if cmd = [] then ( | ||
Printf.eprintf "Missing command\n" ; | ||
exit 1 | ||
) ; | ||
let cmd = Array.of_list cmd in | ||
let env = | ||
[ "CONTENT_LENGTH", string_of_int (String.length !body) ; | ||
"REQUEST_METHOD", !meth ; | ||
"CONTENT_TYPE", !typ ; | ||
"QUERY_STRING", !query ; | ||
"SERVER_PORT", "80" ; | ||
"SCRIPT_NAME", cmd.(0) ; | ||
"SERVER_NAME", "runcgi" ] in | ||
let add_env n env = | ||
match Sys.getenv n with | ||
| exception Not_found -> env | ||
| s -> (n, s) :: env in | ||
let env = add_env "HOME" env in | ||
let env = add_env "PATH" env in | ||
let env = | ||
List.map (fun (n, v) -> n ^"="^ v) env |> | ||
Array.of_list in | ||
Unix.execvpe cmd.(0) cmd env |