1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
6 <TITLE>CGIscriptor
2.0 Manual
</TITLE>
14 <I>CGIscriptor
2.0</I>: An implementation of integrated server side CGI scripts
19 <LI><A HREF=
"#HYPE">HYPE
</A>
20 <LI><A HREF=
"#HOWITWORKS">THIS IS HOW IT WORKS
</A>
21 <LI><A HREF=
"#HTML4">HTML
4 COMPLIANCE
</A>
22 <LI><A HREF=
"#SECURITY">SECURITY
</A>
26 <LI><A HREF=
"#MANUAL">USER MANUAL
</A>
28 <LI><A HREF=
"#INTRODUCTION">INTRODUCTION
</A>
29 <LI><A HREF=
"#NON-HTML">NON-HTML CONTENT TYPES
</A>
30 <LI><A HREF=
"#BINFILES">NON-HTML FILES
</A>
31 <LI><A HREF=
"#META">THE META TAG
</A>
32 <LI><A HREF=
"#DIV">THE DIV/INS TAG
</A>
33 <LI><A HREF=
"#IFUNLESS">CONDITIONAL PROCESSING: THE 'IF' AND 'UNLESS' ATTRIBUTES
</A>
34 <LI><A HREF=
"#SRC">THE MAGIC SOURCE ATTRIBUTE (SRC=)
</A>
35 <LI><A HREF=
"#ROOT">THE CGISCRIPTOR ROOT DIRECTORIES ~/ AND ./
</A>
36 <LI><A HREF=
"#OSSHELL">OS SHELL SCRIPT EVALUATION (CONTENT-TYPE=TEXT/OSSHELL)
</A>
37 <LI><A HREF=
"#TRANSLATIONS">RUN TIME TRANSLATION OF INPUT FILES
</A>
38 <LI><A HREF=
"#LANGUAGES">EVALUATION OF OTHER SCRIPTING LANGUAGES
</A>
39 <LI><A HREF=
"#APPLIC">APPLICATION MIME TYPES
</A>
40 <LI><A HREF=
"#PIPES">SHELL SCRIPT PIPING
</A>
41 <LI><A HREF=
"#SSPERL">PERL CODE EVALUATION (CONTENT-TYPE=TEXT/SSPERL)
</A>
42 <LI><A HREF=
"#SESSIONTICKETS">SERVER SIDE SESSIONS AND ACCESS CONTROL (LOGIN)
</A>
43 <LI><A HREF=
"#USEREXTENSIONS">USER EXTENSIONS
</A>
44 <LI><A HREF=
"#RESULTSSTACK">THE RESULTS STACK: @CGIscriptorResults
</A>
45 <LI><A HREF=
"#CGIPREDEFINED">USEFULL CGI PREDEFINED VARIABLES
</A>
46 <LI><A HREF=
"#ENVIRONMENT">USEFULL CGI ENVIRONMENT VARIABLES
</A>
47 <LI><A HREF=
"#RUNNING">INSTRUCTIONS FOR RUNNING CGIscriptor ON UNIX
</A>
48 <LI><A HREF=
"#NON-UNIX">NON-UNIX OS-PLATFORMS
</A>
50 <LI><A HREF=
"#license">license
</A>
55 <A NAME=
"HYPE"><H2 ALIGN=
"CENTER">HYPE
</H2></A>
58 CGIscriptor merges plain ASCII HTML files transparantly and safely
59 with CGI variables, in-line PERL code, shell commands, and executable
60 scripts in many languages (on-line and real-time). It combines the
61 "ease of use" of HTML files with the versatillity of specialized
62 scripts and PERL programs. It hides all the specifics and
63 idiosyncrasies of correct output and CGI coding and naming. Scripts
64 do not have to be aware of HTML, HTTP, or CGI conventions just as HTML
65 files can be ignorant of scripts and the associated values. CGIscriptor
66 complies with the W3C HTML
4.0 recommendations.
70 In addition to its use as a WWW embeded CGI processor, it can
71 be used as a command-line document preprocessor (text-filter).
74 <A NAME=
"HOWITWORKS"><H2 ALIGN=
"CENTER">THIS IS HOW IT WORKS
</H2></A>
77 The aim of CGIscriptor is to execute
"plain" scripts inside a text file
78 using any required CGIparameters and environment variables. It
79 is optimized to transparantly process HTML files inside a WWW server.
80 The native language is Perl, but many other scripting languages
85 CGIscriptor reads text files from the requested input file (i.e., from
86 $YOUR_HTML_FILES$PATH_INFO) and writes them to
<STDOUT
> (i.e., the client
87 requesting the service) preceded by the obligatory
88 "Content-type: text/html\n\n" or
"Content-type: text/plain\n\n" string
89 (except for
"raw" files which supply their own Content-type message
90 and only if the SERVER_PROTOCOL contains HTTP, FTP, GOPHER, MAIL, or MIME).
94 When CGIscriptor encounters an embedded script, indicated by an HTML4 tag
98 <SCRIPT
TYPE=
"text/ssperl" [
CGI=
"$name='default value'"] [
SRC=
"ScriptSource"]
>
106 <SCRIPT
TYPE=
"text/osshell" [
CGI=
"$name='default value'"] [
SRC=
"ScriptSource"]
>
112 construct (anything between []-brackets is optional, other MIME-types are
113 supported), the embedded script is removed and both the contents of the
114 source file (i.e.,
"do 'ScriptSource'") AND the script are evaluated as a
115 PERL program (i.e., by eval()), a shell script (i.e., by a
"safe" version
116 of `Command`, qx) or an external interpreter. The output of the eval()
117 function takes the place of the original
<SCRIPT
></SCRIPT
>
118 construct in the output string. Any CGI parameters declared by the CGI
119 attribute are available as simple perl variables, and can subsequently
120 be made available as variables to other scripting languages (e.g., bash,
125 Example: printing
"Hello World"
129 <HTML
><HEAD
><TITLE
>Hello World
</TITLE
>
131 <H1
><SCRIPT
TYPE=
"text/ssperl">"Hello World"</SCRIPT
></H1
>
132 </BODY
></HTML
>
136 Save this in a file, hello.html, in the directory you indicated with
137 $YOUR_HTML_FILES and access http://your_server/SHTML/hello.html
138 (or to whatever name you use as an alias for CGIscriptor.pl).
139 This is realy ALL you need to do to get going.
143 You can use any values that are delivered in CGI-compliant form (i.e.,
144 the
"?name=value" type URL additions) transparently as
"$name" variables
145 in your scripts IFF you have declared them in a META or SCRIPT tag before e.g.:
149 <META
CONTENT=
"text/ssperl; CGI='$name = `default value`'
150 [SRC='ScriptSource']">
154 <SCRIPT TYPE=text/ssperl
CGI=
"$name = 'default value'"
155 [SRC='ScriptSource']
>
159 After such a 'CGI' attribute, you can use $name as an ordinary PERL variable
160 (the ScriptSource file is immediately evaluated with
"do 'ScriptSource'").
161 The CGIscriptor script allows you to write ordinary HTML files which will
162 include dynamic CGI aware (run time) features, such as on-line answers
163 to specific CGI requests, queries, or the results of calculations.
167 For example, if you wanted to answer questions of clients, you could write
168 a Perl program called
"Answer.pl" with a function
"AnswerQuestion()"
169 that prints out the answer to requests given as arguments. You then write
170 a HTML page
"Respond.html" containing the following fragment:
176 The Answer to your question
177 <META
CONTENT=
"text/ssperl; CGI='$Question'">
178 <h3
><SCRIPT
TYPE=
"text/ssperl">$Question
</SCRIPT
></h3
>
180 <h3
><SCRIPT
TYPE=
"text/ssperl" SRC=
"./PATH/Answer.pl">
181 AnswerQuestion($Question);
182 </SCRIPT
></h3
>
184 <FORM ACTION=Respond.html METHOD=GET
>
185 Next question:
<INPUT
NAME=
"Question" TYPE=TEXT SIZE=
40><br
>
186 <INPUT TYPE=SUBMIT
VALUE=
"Ask">
192 The output could look like the following (in HTML-speak):
198 The Answer to your question
199 <h3>What is the capital of the Netherlands?
</h3>
203 <FORM ACTION=Respond.html METHOD=GET
>
204 Next question:
<INPUT NAME=
"Question" TYPE=TEXT SIZE=
40><br>
205 <INPUT TYPE=SUBMIT
VALUE=
"Ask">
210 Note that the function
"Answer.pl" does know nothing about CGI or HTML,
211 it just prints out answers to arguments. Likewise, the text has no
212 provisions for scripts or CGI like constructs. Also, it is completely
213 trivial to extend this
"program" to use the
"Answer" later in the page
214 to call up other information or pictures/sounds. The final text never
215 shows any cue as to what the original
"source" looked like, i.e.,
216 where you store your scripts and how they are called.
220 There are some extra's. The argument of the files called in a SRC= tag
221 can access the CGI variables declared in the preceding META tag from
222 the @ARGV array. Executable files are called as:
223 `file '$ARGV[
0]' ... ` (e.g., `Answer.pl \'$Question\'`;)
224 The files called from SRC can even be (CGIscriptor) html files which are
225 processed in-line. Furthermore, the SRC= tag can contain a perl block
226 that is evaluated. That is,
230 <META
CONTENT=
"text/ssperl; CGI='$Question' SRC='{$Question}'">
234 will result in the evaluation of
"print do {$Question};" and the VALUE
235 of $Question will be printed. Note that these
"SRC-blocks" can be
236 preceded and followed by other file names, but only a single block is
237 allowed in a SRC= tag.
241 One of the major hassles of dynamic WWW pages is the fact that several
242 mutually incompatible browsers and platforms must be supported. For example,
243 the way sound is played automatically is different for Netscape and
244 Internet Explorer, and for each browser it is different again on
245 Unix, MacOS, and Windows. Realy dangerous is processing user-supplied
246 (form-) values to construct email addresses, file names, or database
247 queries. All Apache WWW-server exploits reported in the media are
248 based on faulty CGI-scripts that didn't check their user-data properly.
252 There is no panacee for these problems, but a lot of work and problems
253 can be safed by allowing easy and transparent control over which
254 <SCRIPT
></SCRIPT
> blocks are executed on what CGI-data. CGIscriptor
255 supplies such a method in the form of a pair of attributes:
256 IF='...condition..' and UNLESS='...condition...'. When added to a
257 script tag, the whole block (including the SRC attribute) will be
258 ignored if the condition is false (IF) or true (UNLESS).
259 For example, the following block will NOT be evaluated if the value
260 of the CGI variable FILENAME is NOT a valid filename:
264 <SCRIPT TYPE='text/ssperl' CGI='$FILENAME' IF='CGIscriptor::CGIsafeFileName($FILENAME)'
>
270 (the function CGIsafeFileName(String) returns an empty string (
"")
271 if the String argument is not a valid filename).
272 The UNLESS attribute is the mirror image of IF.
276 A user manual follows the HTML
4 and security paragraphs below.
280 <A NAME=
"HTML4"><H2 ALIGN=
"CENTER">HTML
4 COMPLIANCE
</H2></A>
283 In general, CGIscriptor.pl complies with the HTML
4 recommendations of
284 the W3C. This means that any software to manage Web sites will be able
285 to handle CGIscriptor files, as will web agents.
289 All script code should be placed between
<SCRIPT
></SCRIPT
> tags, the
290 script type is indicated with
TYPE=
"mime-type", the LANGUAGE
291 feature is ignored, and a SRC feature is implemented. All CGI specific
292 features are delegated to the CGI attribute.
296 However, the behavior deviates from the W3C recommendations at some
297 points. Most notably:
301 <dt>0- The scripts are executed at the server side, invisible to the
302 client (i.e., the browser)
303 <dt>1- The mime-types are personal and idiosyncratic, but can be adapted.
304 <dt>2- Code in the body of a
<SCRIPT
></SCRIPT
> tag-pair is still evaluated
305 when a SRC feature is present.
306 <dt>3- The SRC feature reads a list of files.
307 <dt>4- The files in a SRC feature are processed according to file type.
308 <dt>5- The SRC feature evaluates inline Perl code.
309 <dt>6- Processed META, INS, and DIV tags are removed from the output document.
310 <dt>7- All attributes of the processed META tags, except CONTENT, are ignored
311 (i.e., deleted from the output).
312 <dt>8- META tags can be placed ANYWHERE in the document.
313 <dt>9- Through the SRC feature, META tags can have visible output in the
315 <dt>10- The CGI attribute that declares CGI parameters, can be used
316 inside the
<SCRIPT
> tag.
317 <dt>11- Use of an extended quote set, i.e., '',
"", ``, (), {}, []
318 and their \-slashed combinations: \'\', \
"\", \`\`, \(\),
320 <dt>12- IF and UNLESS attributes to
<SCRIPT
>,
<META
>,
321 <INS
>, and
<DIV
> tags.
322 <dt>13-
<DIV
> tags cannot be nested,
<DIV
> tags are not
323 rendered with new-lines.
324 <dt>14- The XML style
<TAG .... /
> is recognized and handled correctly.
325 (i.e., no content is processed)
329 The reasons for these choices are:
333 You can still write completely HTML4 compliant documents. CGIscriptor
334 will not force you to write
"deviant" code. However, it allows you to
335 do so (which is, in fact, just as bad). The prime design principle
336 was to allow users to include plain Perl code. The code itself should
337 be
"enhancement free". Therefore, extra features were needed to
338 supply easy access to CGI and Web site components. For security
339 reasons these have to be declared explicitly. The SRC feature
340 transparently manages access to external files, especially the safe
341 use of executable files.
345 The CGI attribute handles the declarations of external (CGI) variables
346 in the SCRIPT and META tag's.
<BR>
347 EVERYTHING THE CGI ATTRIBUTE AND THE META TAG DO CAN BE DONE INSIDE
348 A
<SCRIPT
></SCRIPT
> TAG CONSTRUCT.
352 The reason for the IF, UNLESS, and SRC attributes (and its Perl code evaluation)
353 were build into the META and SCRIPT tags is part laziness, part security. The SRC
354 blocks allows more compact documents and easier debugging. The values of the
355 CGI variables can be immediately screened for security by IF or UNLESS
356 conditions, and even SRC attributes (e.g., email addresses and file names), and
357 a few commands can be called without having to add another Perl TAG pair.
358 This is especially important for documents that require the use of other
359 (restricted)
"scripting" languages that lag transparent control structures.
363 <A NAME=
"SECURITY"><H2 ALIGN=
"CENTER">SECURITY
</H2></A>
366 Your WWW site is a few keystrokes away from a few hundred million internet
367 users. A fair percentage of these users knows more about your computer
368 than you do. And some of these just might have bad intentions.
372 To ensure uncompromized operation of your server and platform, several
373 features are incorporated in CGIscriptor.pl to enhance security.
374 First of all, you should check the source of this program. No security
375 measures will help you when you download programs from anonymous sources.
376 If you want to use THIS file, please make sure that it is uncompromized.
377 The best way to do this is to contact the source and try to determine
378 whether s/he is reliable (and accountable).
382 BE AWARE THAT ANY PROGRAMMER CAN CHANGE THIS PROGRAM IN SUCH A WAY THAT
383 IT WILL SET THE DOORS TO YOUR SYSTEM WIDE OPEN
387 I would like to ask any user who finds bugs that could compromise
388 security to report them to me (and any other bug too,
389 Email: R.J.J.H.vanSon@uva.nl or ifa@hum.uva.nl).
392 <H2 ALIGN=
"CENTER">Security features
</H2>
396 <dd>The inner workings of the HTML source files are completely hidden
397 from the client. Only the HTTP header and the ever changing content
398 of the output distinguish it from the output of a plain, fixed HTML
399 file. Names, structures, and arguments of the
"embedded" scripts
400 are invisible to the client. Error output is suppressed except
401 during debugging (user configurable).
403 <dt>2 Separate directory trees
404 <dd>Directories containing Inline text and script files can reside on
405 separate trees, distinct from those of the HTTP server. This means
406 that NEITHER the text files, NOR the script files can be read by
407 clients other than through CGIscriptor.pl, UNLESS they are
408 EXPLICITELY made available.
410 <dt>3 Requests are NEVER
"evaluated"
411 <dd>All client supplied values are used as literal values (''-quoted).
412 Client supplied ''-quotes are ALWAYS removed. Therefore, as long as the
413 embedded scripts do NOT themselves evaluate these values, clients CANNOT
414 supply executable commands. Be sure to AVOID scripts like:
417 <META
CONTENT=
"text/ssperl; CGI='$UserValue'">
418 <SCRIPT
TYPE=
"text/ssperl">$dir = `ls -
1 $UserValue`;
</SCRIPT
>
422 These are a recipe for disaster. However, the following quoted
423 form should be save (but is still not adviced):
427 <SCRIPT
TYPE=
"text/ssperl">$dir = `ls -
1 \'$UserValue\'`;
</SCRIPT
>
431 A special function, SAFEqx(), will automatically do exactly this,
432 e.g., SAFEqx('ls -
1 $UserValue') will execute `ls -
1 \'$UserValue\'`
433 with $UserValue interpolated. I recommend to use SAFEqx() instead
434 of backticks whenever you can. The OS shell scripts inside
438 <SCRIPT
TYPE=
"text/osshell">ls -
1 $UserValue
</SCRIPT
>
442 are handeld by SAFEqx and automatically ''-quoted.
445 <dt>4 Logging of requests
446 <dd>All requests can be logged separate from the Host server. The level of
447 detail is user configurable: Including or excluding the actual queries.
448 This allows for the inspection of (im-) proper use.
450 <dt>5 Access control: Clients
451 <dd>The Remote addresses can be checked against a list of authorized
452 (i.e., accepted) or non-authorized (i.e., rejected) clients. Both
453 REMOTE_HOST and REMOTE_ADDR are tested so clients without a proper
454 HOST name can be (in-) excluded by their IP-address. Client patterns
455 containing all numbers and dots are considered IP-addresses, all others
456 domain names. No wild-cards or regexp's are allowed, only partial
458 Matching of names is done from the back to the front (domain first,
459 i.e., $REMOTE_HOST =~ /\Q$pattern\E$/is), so including
".edu" will
460 accept or reject all clients from the domain EDU. Matching of
461 IP-addresses is done from the front to the back (domain first, i.e.,
462 $REMOTE_ADDR =~ /^\Q$pattern\E/is), so including
"128." will (in-)
463 exclude all clients whose IP-address starts with
128.
464 There are two special symbols:
"-" matches HOSTs with no name and
"*"
465 matches ALL HOSTS/clients.
<br>
468 For those needing more expressional power, lines starting with
469 "-e" are evaluated by the perl eval() function. E.g.,
470 '-e $REMOTE_HOST =~ /\.edu$/is;' will accept/reject clients from the
474 <dt>6 Access control: Files
475 <dd>In principle, CGIscriptor could read ANY file in the directory
476 tree as discussed in
1. However, for security reasons this is
477 restricted to text files. It can be made more restricted by entering
478 a global file pattern (e.g.,
".html"). This is done by default.
479 For each client requesting access, the file pattern(s) can be made
480 more restrictive than the global pattern by entering client specific
481 file patterns in the Access Control files (see
5).
482 For example: if the ACCEPT file contained the lines
491 Then all clients could request paths containing
"DEMO" or
"demo", e.g.
492 "/my/demo/file.html" ($PATH_INFO =~ /\Q$pattern\E/), Clients from
493 *.hum.uva.nl could also request paths containing
"LET or "let
", e.g.
494 "/my/let/file.html
", and clients from the local cluster
495 145.18.230.[0-9]+ could access ALL files.
496 Again, for those needing more expressional power, lines starting with
497 "-e
" are evaluated. For instance: <br />
498 '-e $REMOTE_HOST =~ /\.edu$/is && $PATH_INFO =~ m@/DEMO/@is;' <br />
499 will accept/reject requests for files from the directory "/demo/
" from
500 clients from the domain '.edu'.
503 <dt>7 Access control: Server side session tickets
504 <dd>Specific paths can be controlled by Session Tickets which must be
505 present as a CGI or Cookie value in the request. These paths
506 are defined in %TicketRequiredPatterns as pairs of:<br />
507 ('regexp' => 'SessionPath\tPasswordPath\tLogin.html\tExpiration').<br />
508 Session Tickets are stored in a separate directory (SessionPath, e.g.,
509 "Private/.Session
") as files with the exact same name of the TICKET
511 The following is an example of a SESSION ticket:
515 AllowedPaths: ^/Private/Name/
516 DeniedPaths: ^/Private/CreateUser\.
521 Other content can follow. <br />
523 It is adviced that Session Tickets should expire and be deleted
524 after some (idle) time. The IP address should be the IP number at login, and
525 the ticket will be rejected if it is presented from another IP address.
526 AllowedPaths and DeniedPaths are perl regexps. Be careful how they match. Make sure to delimit
527 the names to prevent access to overlapping names, eg, "^/Private/Rob
" will also
528 match "^/Private/Robert
", however, "^/Private/Rob/
" will not. Expires is the
529 time the ticket will remain valid after creation (file ctime). Time can be given
530 in s[econds] (default), m[inutes], h[hours], or d[ays], eg, "24h
" means 24 hours.
531 Only the <em>Type:</em> field needs be present.<br />
533 Next to Session Tickets, there are four other type of ticket files:<br />
534 - LOGIN tickets store information about a current login request<br />
535 - PASSWORD tickets store account information to authorize login requests<br />
536 - IPADDRESS tickets for IP address-only checks<br />
537 - CHALLENGE tickets for challenge tasks for every request<br />
540 <dt>8 Query length limiting
541 <dd>The length of the Query string can be limited. If CONTENT_LENGTH is larger
542 than this limit, the request is rejected. The combined length of the
543 Query string and the POST input is checked before any processing is done.
544 This will prevent clients from overloading the scripts.
545 The actual, combined, Query Size is accessible as a variable through
550 <dt>9 Illegal filenames, paths, and protected directories
551 <dd>One of the primary security concerns in handling CGI-scripts is the
552 use of "funny
" characters in the requests that con scripts in executing
553 malicious commands. Examples are inserting ';', null bytes, or <newline> characters
554 in URL's and filenames, followed by executable commands. A special
555 variable $FileAllowedChars stores a string of all allowed characters.
556 Any request that translates to a filename with a character OUTSIDE
557 this set will be rejected.<br>
558 In general, all (readable files) in the ServerRoot tree are accessible.
559 This might not be what you want. For instance, your ServerRoot directory
560 might be the working directory of a CVS project and contain sensitive
561 information (e.g., the password to get to the repository). You can block
562 access to these subdirectories by adding the corresponding patterns to
563 the $BlockPathAccess variable. For instance, $BlockPathAccess = '/CVS/'
564 will block any request that contains '/CVS/' or:<br>
566 die if $BlockPathAccess && $ENV{'PATH_INFO'} =~ m@$BlockPathAccess@;
571 <dt>10 The execution of code blocks can be controlled in a transparent way
572 by adding IF or UNLESS conditions in the tags themselves.
573 <dd>That is, a simple check of the validity of filenames or email
574 addresses can be done before any code is executed.
581 <A NAME="MANUAL
"><H1 ALIGN="CENTER
">USER MANUAL</H1></A>
584 <LI><A HREF="#INTRODUCTION
">INTRODUCTION</A>
585 <LI><A HREF="#NON-HTML
">NON-HTML CONTENT TYPES</A>
586 <LI><A HREF="#BINFILES
">NON-HTML FILES</A>
587 <LI><A HREF="#META
">THE META TAG</A>
588 <LI><A HREF="#DIV
">THE DIV/INS TAG</A>
589 <LI><A HREF="#IFUNLESS
">CONDITIONAL PROCESSING: THE 'IF' AND 'UNLESS' ATTRIBUTES</A>
590 <LI><A HREF="#SRC
">THE MAGIC SOURCE ATTRIBUTE (SRC=)</A>
591 <LI><A HREF="#ROOT
">THE CGISCRIPTOR ROOT DIRECTORIES ~/ AND ./</A>
592 <LI><A HREF="#OSSHELL
">OS SHELL SCRIPT EVALUATION (CONTENT-TYPE=TEXT/OSSHELL)</A>
593 <LI><A HREF="#TRANSLATIONS
">RUN TIME TRANSLATION OF INPUT FILES</A>
594 <LI><A HREF="#LANGUAGES
">EVALUATION OF OTHER SCRIPTING LANGUAGES</A>
595 <LI><A HREF="#PIPES
">SHELL SCRIPT PIPING</A>
596 <LI><A HREF="#SSPERL
">PERL CODE EVALUATION (CONTENT-TYPE=TEXT/SSPERL)</A>
597 <LI><A HREF="#SESSIONTICKETS
">SERVER SIDE SESSIONS AND ACCESS CONTROL (LOGIN)</A>
598 <LI><A HREF="#USEREXTENSIONS
">USER EXTENSIONS</A>
599 <LI><A HREF="#RESULTSSTACK
">THE RESULTS STACK: @CGIscriptorResults</A>
600 <LI><A HREF="#CGIPREDEFINED
">USEFULL CGI PREDEFINED VARIABLES</A>
601 <LI><A HREF="#ENVIRONMENT
">USEFULL CGI ENVIRONMENT VARIABLES</A>
602 <LI><A HREF="#RUNNING
">INSTRUCTIONS FOR RUNNING CGIscriptor ON UNIX</A>
603 <LI><A HREF="#NON-UNIX
">NON-UNIX OS-PLATFORMS</A>
606 <A NAME="INTRODUCTION
"><H2 ALIGN="CENTER
">INTRODUCTION</H2></A>
609 CGIscriptor removes embedded scripts, indicated by an HTML 4 type
610 <SCRIPT TYPE='text/ssperl'> </SCRIPT> or <SCRIPT TYPE='text/osshell'>
611 </SCRIPT> constructs. The contents of the directive are executed by
612 the PERL eval() and `` functions (in a separate name space). The
613 result of the eval() function replaces the <SCRIPT> </SCRIPT> construct
614 in the output file. You can use the values that are delivered in
615 CGI-compliant form (i.e., the "?name=value&..
" type URL additions)
616 transparently as "$name
" variables in your directives after they are
617 defined in a <META> or <SCRIPT> tag.
618 If you define the variable "$CGIscriptorResults
" in a CGI attribute, all
619 subsequent <SCRIPT> and <META> results (including the defining
620 tag) will also be pushed onto a stack: @CGIscriptorResults. This list
621 behaves like any other, ordinary list and can be manipulated.
625 Both GET and POST requests are accepted. These two methods are treated
626 equal. Variables, i.e., those values that are determined when a file is
627 processed, are indicated in the CGI attribute by $<name> or
628 $<name>=<default> in which <name> is the name of the
629 variable and <default> is the value used when there is NO current CGI
630 value for <name> (you can use white-spaces in
631 $<name>=<default> but really DO make sure that the default
632 value is followed by white space or is quoted). Names can contain any
633 alphanumeric characters and _ (i.e., names match /[\w]+/).<br>
634 If the <i>Content-type:</i> is 'multipart/*', the input is treated as a
635 MIME multipart message and automatically delimited. CGI variables get the
636 "raw
" (i.e., undecoded) body of the corresponding message part.
640 Variables can be CGI variables, i.e., those from the QUERY_STRING,
641 environment variables, e.g., REMOTE_USER, REMOTE_HOST, or REMOTE_ADDR,
642 or predefined values, e.g., CGI_Decoded_QS (The complete, decoded,
643 query string), CGI_Content_Length (the length of the decoded query
644 string), CGI_Year, CGI_Month, CGI_Time, and CGI_Hour (the current
649 All these are available when defined in a CGI attribute. All environment
650 variables are accessible as $ENV{'name'}. So, to access the REMOTE_HOST
651 and the REMOTE_USER, use, e.g.:
655 <SCRIPT TYPE='text/ssperl'>
656 ($ENV{'REMOTE_HOST'}||"-
")." $ENV{'REMOTE_USER'}
"
661 (This will print a "-
" if REMOTE_HOST is not known)
662 Another way to do this is:
666 <META CONTENT="text/ssperl; CGI='$REMOTE_HOST = - $REMOTE_USER'
">
667 <SCRIPT TYPE='text/ssperl'>"$REMOTE_HOST $REMOTE_USER
"</SCRIPT>
673 <META CONTENT='text/ssperl; CGI="$REMOTE_HOST = - $REMOTE_USER
"
674 SRC={"$REMOTE_HOST $REMOTE_USER\n
"}'>
678 This is possible because ALL environment variables are available as
679 CGI variables. The environment variables take precedence over CGI
680 names in case of a "name clash
". For instance:
684 <META CONTENT="text/ssperl; CGI='$HOME' SRC={$HOME}
">
688 Will print the current HOME directory (environment) irrespective whether
689 there is a CGI variable from the query
690 (e.g., Where do you live? <INPUT TYPE="TEXT
" NAME="HOME
">)
691 THIS IS A SECURITY FEATURE. It prevents clients from changing
692 the values of defined environment variables (e.g., by supplying
693 a bogus $REMOTE_ADDR). Although $ENV{} is not changed by the META tags,
694 it would make the use of declared variables insecure. You can still
695 access CGI variables after a name clash with
696 CGIscriptor::CGIparseValue(<name>).
700 Some CGI variables are present several times in the query string
701 (e.g., from multiple selections). These should be defined as
702 @VARIABLENAME=default in the CGI attribute. The list @VARIABLENAME
703 will contain ALL VARIABLENAME values from the query, or a single
704 default value. If there is an ENVIRONMENT variable of the
705 same name, it will be used instead of the default AND the query
706 values. The corresponding function is
707 CGIscriptor::CGIparseValueList(<name>)
711 CGI variables collected in a @VARIABLENAME list are unordered.
712 When more structured variables are needed, a hash table can be used.
713 A variable defined as %VARIABLE=default will collect all
714 CGI-parameter values whose name start with 'VARIABLE' in a hash table
715 with the remainder of the name as a key. For instance, %PERSON will
716 collect PERSONname='John Doe', PERSONbirthdate='01 Jan 00', and
717 PERSONspouse='Alice' into a hash table %PERSON such that
718 $PERSON{'spouse'} equals 'Alice'. Any default value or environment
719 value will be stored under the "" key. If there is an ENVIRONMENT
720 variable of the same name, it will be used instead of the default
721 AND the query values. The corresponding function is
722 CGIscriptor::CGIparseValueHash(<name>)
726 This method of first declaring your environment and CGI variables
727 before being able to use them in the scripts might seem somewhat
728 clumsy, but it protects you from inadvertedly printing out the values of
729 system environment variables when their names coincide with those used
730 in the CGI forms. It also prevents "clients
" from supplying CGI parameter
731 values for your private variables.
732 THIS IS A SECURITY FEATURE!
735 <A NAME="NON-HTML
"><H2 ALIGN="CENTER
">NON-HTML CONTENT TYPES</H2></A>
738 Normally, CGIscriptor prints the standard "Content-type: text/html\n\n
"
739 message before anything is printed. This has been extended to include
740 plain text (.txt) files, for which the Content-type (MIME type)
741 'text/plain' is printed. In all other respects, text files are treated as
742 HTML files (this can be switched off by removing '.txt' from the
743 $FilePattern variable). When the content type should be something else,
744 e.g., with multipart files, use the $RawFilePattern (.xmr, see also next
745 item). CGIscriptor will not print a Content-type message for this file type
746 (which must supply its OWN Content-type message). Raw files must still
747 conform to the <SCRIPT></SCRIPT> and <META> tag
751 <A NAME="BINFILES
"><H2 ALIGN="CENTER
">NON-HTML FILES</H2></A>
754 CGIscriptor is intended to process HTML and text files only. You can
755 create documents of any mime-type on-the-fly using "raw
" text files, e.g.,
756 with the .xmr extension. However, CGIscriptor will not process binary files
757 of any type, e.g., pictures or sounds. Given the sheer number of formats, I
758 do not have any intention to do so. However, an escape route has been
759 provided. You can construct a genuine raw (.xmr) text file that contains
760 the perl code to service any file type you want. If the global
761 $BinaryMapFile variable contains the path to this file (e.g.,
762 /BinaryMapFile.xmr), this file will be called whenever an unsupported
763 (non-HTML) file type is requested. The path to the requested binary file
764 is stored in $ENV('CGI_BINARY_FILE') and can be used like any other
765 CGI-variable. Servicing binary files then becomes supplying the correct
766 Content-type (e.g., print "Content-type: image/jpeg\n\n
";) and reading the
767 file and writing it to STDOUT (e.g., using sysread() and syswrite()).
770 <A NAME="META
"><H2 ALIGN="CENTER
">THE META TAG</H2></A>
773 All attributes of a META tag are ignored, except the
774 CONTENT='text/ssperl; CGI=" ...
" [SRC=" ...
"]' attribute. The string
775 inside the quotes following the CONTENT= indication (white-space is
776 ignored, "'` (){}[]-quotes are allowed, plus their \ versions) MUST
777 start with any of the CGIscriptor mime-types (e.g.: text/ssperl or
778 text/osshell) and a comma or semicolon.
779 The quoted string following CGI= contains a white-space separated list
780 of declarations of the CGI (and Environment) values and default values
781 used when no CGI values are supplied by the query string.
785 If the default value is a longer string containing special characters,
786 possibly spanning several lines, the string must be enclosed in quotes.
787 You may use any pair of quotes or brackets from the list '',
"", ``, (),
788 [], or {} to distinguish default values (or preceded by \, e.g., \(...\)
789 is different from (...)). The outermost pair will always be used and any
790 other quotes inside the string are considered to be part of the string
800 will result in $Value getting the default value
809 (NOTE that the newline is part of the default value!).
813 Internally, for defining and initializing CGI (ENV) values, the META
814 and SCRIPT tags use the function
"defineCGIvariable($name, $default)"
815 (scalars) and
"defineCGIvariableList($name, $default)" (lists).
816 These functions can be used inside scripts as
817 "CGIscriptor::defineCGIvariable($name, $default)" and
818 "CGIscriptor::defineCGIvariableList($name, $default)".
822 The CGI attribute will be processed exactly identical when used inside
823 the
<SCRIPT
> tag. However, this use is not according to the
824 HTML
4.0 specifications of the W3C.
827 <A NAME=
"DIV"><H2 ALIGN=
"CENTER">THE DIV/INS TAG
</H2></A>
830 There is a problem when constructing html files containing
831 server-side perl scripts with standard HTML tools. These
832 tools will refuse to process any text between
833 <SCRIPT
></SCRIPT
>
834 tags. This is quite annoying when you want to use large
835 HTML templates where you will fill in values.
839 For this purpose, CGIscriptor will read the neutral
840 <DIV
CLASS=
"ssperl" ID=
"varname"></DIV
>
841 <INS
CLASS=
"ssperl" ID=
"varname"></INS
>
842 tag (in Cascading Style Sheet manner) Note that
"varname" has
843 NO '$' before it, it is a bare name. Any text between
844 these
<DIV ...
></DIV
> or
845 <INS ...
></INS
> tags will be assigned
846 to '$varname' as is (e.g., as a literal). No
847 processing or interpolation will be performed.
848 There is also NO nesting possible. Do NOT nest
849 </DIV
> inside a
<DIV
></DIV
>!
850 Moreover, DIV tags do NOT ensure a block structure in
851 the final rendering (i.e., no empty lines).
855 Note that
<DIV
CLASS=
"ssperl" ID=
"varname"/
>
856 is handled the XML way. No content is processed,
857 but varname is defined, and any SRC directives are
862 You can use $varname like any other variable name.
863 However, $varname is NOT a CGI variable and will be
864 completely internal to your script. There is NO
865 interaction between $varname and the outside world.
869 To interpolate a DIV derived text, you can use:
871 $varname =~ s/([\]])/\\\
1/g; # Mark ']'-quotes
872 $varname = eval(
"qq[$varname]"); # Interpolate all values
877 The DIV tag will process IF, UNLESS, CGI and SRC attributes.
878 The SRC files will be pre-pended to the body
882 <A NAME=
"IFUNLESS"><H2 ALIGN=
"CENTER">
883 CONDITIONAL PROCESSING: THE 'IF' AND 'UNLESS' ATTRIBUTES
887 It is often necessary to include code-blocks that should be executed
888 conditionally, e.g., only for certain browsers or operating system.
889 Furthermore, quite often sanity and security checks are necessary
890 before user (form) data can be processed, e.g., with respect to
891 email addresses and filenames.
895 Checks added to the code are often difficult to find, interpret or
896 maintain and in general mess up the code flow. This kind of confussion
897 is dangerous. Also, for many of the supported
"foreign" scripting
898 languages, adding these checks is cumbersome or even impossible.
902 As a uniform method for asserting the correctness of
"context", two
903 attributes are added to all supported tags: IF and UNLESS.
904 They both evaluate their value and block execution when the
905 result is
<FALSE
> (IF) or
<TRUE
> (UNLESS) in Perl, e.g.,
906 UNLESS='$NUMBER \
> 100;' blocks execution if $NUMBER
<=
100. Note that
907 the backslash in the '\
>' is removed and only used to differentiate
908 this conditional '
>' from the tag-closing '
>'. For symmetry, the
909 backslash in '\
<' is also removed. Inside these conditionals,
910 ~/ and ./ are expanded to their respective directory root paths.
914 For example, the following tag will be ignored when the filename is
919 <SCRIPT TYPE='text/ssperl' CGI='$FILENAME'
920 IF='CGIscriptor::CGIsafeFileName($FILENAME);'
>
926 The IF and UNLESS values must be quoted. The same quotes are supported
927 as with the other attributes. The SRC attribute is ignored when IF and
928 UNLESS block execution.
931 <A NAME=
"SRC"><H2 ALIGN=
"CENTER">
932 THE MAGIC SOURCE ATTRIBUTE (SRC=)
</H2></A>
935 The SRC attribute inside tags accepts a list of filenames and URL's
936 separated by
"," comma's (or
";" semicolons).
940 ALL the variable values defined in the CGI attribute are available in
941 @ARGV as if the file was executed from the command line, in
942 the exact order in which they were declared in the preceding CGI
947 First, a SRC={}-block will be evaluated as if the code inside the
948 block was part of a
<SCRIPT
></SCRIPT
> construct, i.e.,
949 "print do { code };'';" or `code` (i.e., SAFEqx('code)).
950 Only a single block is evaluated. Note that this is processed less
951 efficiently than
<SCRIPT
> </SCRIPT
> blocks. Type of evaluation
952 depends on the content-type: Perl for text/ssperl and OS shell for
953 text/osshell. For other mime types (scripting languages), anything in
954 the source block is put in front of the code block
"inside" the tag.
958 Second, executable files (i.e., -x filename !=
0) are evaluated as:
959 print `filename \'$ARGV[
0]\' \'$ARGV[
1]\' ...`
960 That is, you can actually call executables savely from the SRC tag.
964 Third, text files that match the file pattern, used by CGIscriptor to
965 check whether files should be processed ($FilePattern), are
966 processed in-line (i.e., recursively) by CGIscriptor as if the code
967 was inserted in the original source file. Recursions, i.e., calling
968 a file inside itself, are blocked. If you need them, you have to code
969 them explicitely using
"main::ProcessFile($file_path)".
973 Fourth, Perl text files (i.e., -T filename !=
0) are evaluated as:
978 Last, URL's (i.e., starting with 'HTTP://', 'FTP://', 'GOPHER://', 'TELNET://',
979 'WHOIS://' etc.) are loaded and printed. The loading and handling of
<BASE
>
980 and document header is done by main::GET_URL($URL [,
0]). You can enter your own
981 code (default is
<i>curl
</i>,
<i>snarf
</i>, or
<i>wget
</i> and some
982 post-processing to add a
<BASE
> tag).
986 There are two pseudo-file names: PREFIX and POSTFIX. These implement
987 a switch from prefixing the SRC code/files (PREFIX, default) before the content of
988 the tag to appending the code after the content of the tag (POSTFIX). The switches
989 are done in the order in which the PREFIX and POSTFIX labels are encountered.
990 You can mix PREFIX and POSTFIX labels in any order with the SRC files.
991 Note that the ORDER of file execution is determined for prefixed and
992 postfixed files seperately.
996 File paths can be preceded by the URL protocol prefix
"file://". This
997 is simply STRIPPED from the name.
1006 "http://cgi-bin/Action_Forms.pl/Statistics/Sign_Test.html?positive=8&negative=22
1007 will result in printing "${SS_PUB}/Statistics/Sign_Test.html
"
1008 With QUERY_STRING = "positive=
8&negative=
22"
1012 on encountering the lines:
1016 <META CONTENT="text/osshell; CGI='$positive=
11 $negative=
3'
">
1017 <b><SCRIPT TYPE="text/ssperl
" SRC="./Statistics/SignTest.pl
">
1018 </SCRIPT></b><p>"
1021 This line will be processed as:
1024 "<b>`${SS_SCRIPT}/Statistics/SignTest.pl '8' '22'`</b><p>"
1028 In which
"${SS_SCRIPT}/Statistics/SignTest.pl" is an executable script,
1029 This line will end up printed as:
1033 "<b>p <= 0.0161</b><p>"
1037 Note that the META tag itself will never be printed, and is invisible to
1042 The SRC files in a DIV/INS tag will be added (pre-pended) to the body
1043 of the
<DIV
></DIV
> tag. Blocks are NOT executed!
1046 <A NAME=
"ROOT"><H2 ALIGN=
"CENTER">THE CGISCRIPTOR ROOT DIRECTORIES ~/ AND ./
</H2></A>
1049 Inside
<SCRIPT
></SCRIPT
> tags, filepaths starting
1050 with
"~/" are replaced by
"$YOUR_HTML_FILES/", this way files in the
1051 public directories can be accessed without direct reference to the
1052 actual paths. Filepaths starting with
"./" are replaced by
1053 "$YOUR_SCRIPTS/" and this should only be used for scripts.
1054 The
"$YOUR_SCRIPTS" directory is added to @INC so, e.g., the
1055 'require' command will load from the
"$YOUR_SCRIPTS" directory.
1059 <b>Note:
</b> this replacement can seriously affect Perl scripts. Watch
1060 out for constructs like $a =~ s/aap\./noot./g, use
1061 $a =~ s@aap\.@noot.@g instead.
1065 CGIscriptor.pl will assign the values of $SS_PUB and $SS_SCRIPT
1066 (i.e., $YOUR_HTML_FILES and $YOUR_SCRIPTS) to the environment variables
1067 $SS_PUB and $SS_SCRIPT. These can be accessed by the scripts that are
1068 executed. The
"$SS_SCRIPT" ($YOUR_SCRIPTS) directory is added to
1069 @INC so, e.g., the 'require' command will load from the
"$SS_SCRIPT"
1071 Values not preceded by $, ~/, or ./ are used as literals
1074 <A NAME=
"OSSHELL"><H2 ALIGN=
"CENTER">OS SHELL SCRIPT EVALUATION (CONTENT-TYPE=TEXT/OSSHELL)
</H2></A>
1077 OS scripts are executed by a
"safe" version of the `` operator (i.e.,
1078 SAFEqx(), see also below) and any output is printed. CGIscriptor will
1079 interpolate the script and replace all user-supplied CGI-variables by
1080 their ''-quoted values (actually, all variables defined in CGI attributes are
1081 quoted). Other Perl variables are interpolated in a simple fasion, i.e.,
1082 $scalar by their value, @list by join(' ', @list), and %hash by their
1083 name=value pairs. Complex references, e.g., @$variable, are all
1084 evaluated in a scalar context. Quotes should be used with care.
1085 NOTE: the results of the shell script evaluation will appear in the
1086 @CGIscriptorResults stack just as any other result.
1090 All occurrences of $@% that should NOT be interpolated must be
1091 preceeded by a
"\". Interpolation can be switched off completely by
1092 setting $CGIscriptor::NoShellScriptInterpolation =
1
1093 (set to
0 or undef to switch interpolation on again)
1098 <SCRIPT
TYPE=
"text/ssperl">
1099 $CGIscriptor::NoShellScriptInterpolation =
1;
1103 <A NAME=
"TRANSLATIONS">
1104 <H2 ALIGN=
"CENTER">RUN TIME TRANSLATION OF INPUT FILES
</h2>
1107 Allows general and global conversions of files using Regular Expressions.
1108 Very handy (but costly) to rewrite legacy pages to a new format.
1109 Select files to use it on with
<br>
1110 my $TranslationPaths = 'filepattern';
<br>
1111 This is costly. For efficiency, define:
<br>
1112 $TranslationPaths = ''; when not using translations.
<br>
1113 Accepts general regular expressions: [$pattern, $replacement]
1119 my $TranslationPaths = 'filepattern'; # Pattern matching PATH_INFO
1121 push(@TranslationTable, ['pattern', 'replacement']);
1122 # e.g. (for Ruby Rails):
1123 push(@TranslationTable, ['
<%=', '
<SCRIPT
TYPE=
"text/ssruby">']);
1124 push(@TranslationTable, ['%
>', '
</SCRIPT
>']);
1128 foreach $currentRegExp (@TranslationTable)
1130 my ($pattern, $replacement) = @$currentRegExp;
1131 $$text =~ s!$pattern!$replacement!msg;
1135 <A NAME=
"LANGUAGES">
1136 <H2 ALIGN=
"CENTER">EVALUATION OF OTHER SCRIPTING LANGUAGES
</H2>
1140 Adding a MIME-type and an interpreter command to
1141 %ScriptingLanguages automatically will catch any other
1142 scripting language in the standard
1143 <SCRIPT
TYPE=
"[mime]"></SCRIPT
> manner.
1144 E.g., adding: $ScriptingLanguages{'text/sspython'} = 'python';
1145 will actually execute the folowing code in an HTML page
1146 (ignore 'REMOTE_HOST' for the moment):
1150 <SCRIPT
TYPE=
"text/sspython">
1152 x = [
"A",
"real",
"python",
"script",
"Hello",
"World",
"and", REMOTE_HOST]
1153 print x[
4:
8] # Prints the list [
"Hello",
"World",
"and", REMOTE_HOST]
1158 The script code is NOT interpolated by perl, EXCEPT for those
1159 interpreters that cannot handle variables themselves.
1160 Currently, several interpreters are pre-installed:
1164 Perl test -
"text/testperl" =
> 'perl',
1165 Python -
"text/sspython" =
> 'python',
1166 Ruby -
"text/ssruby" =
> 'ruby',
1167 Tcl -
"text/sstcl" =
> 'tcl',
1168 Awk -
"text/ssawk" =
> 'awk -f-',
1169 Gnu Lisp -
"text/sslisp" =
> 'rep | tail +
5 '.
1170 #
"| egrep -v '> |^rep. |^nil\\\$'",
1171 Gnu Prolog-
"text/ssprolog" =
> 'gprolog',
1172 M4 macro's-
"text/ssm4" =
> 'm4',
1173 Born shell-
"text/sh" =
> 'sh',
1174 Bash -
"text/bash" =
> 'bash',
1175 C-shell -
"text/csh" =
> 'csh',
1176 Korn shell-
"text/ksh" =
> 'ksh',
1177 Praat -
"text/sspraat" =
> "praat - | sed 's/Praat > //g'",
1178 R -
"text/ssr" =
> "R --vanilla --slave | sed 's/^[\[0-9\]*] //g'",
1179 REBOL -
"text/ssrebol" =
>
1180 "rebol --quiet|egrep -v '^[> ]* == '|sed 's/^\s*\[> \]* //g'",
1181 PostgreSQL-
"text/postgresql" =
> 'psql
2>/dev/null',
1186 Note that the
"value" of $ScriptingLanguages{mime} must be a command
1187 that reads Standard Input and writes to standard output. Any extra
1188 output of interactive interpreters (banners, echo's, prompts)
1189 should be removed by piping the output through 'tail', 'grep',
1190 'sed', or even 'awk' or 'perl'.
1194 For access to CGI variables there is a special hashtable:
1195 %ScriptingCGIvariables.
1196 CGI variables can be accessed in three ways.
1198 <dt>1. If the mime type is not present in %ScriptingCGIvariables,
1199 nothing is done and the script itself should parse the relevant
1200 environment variables.
1201 <dt>2. If the mime type IS present in %ScriptingCGIvariables, but it's
1202 value is empty, e.g., $ScriptingCGIvariables{
"text/sspraat"} = '';,
1203 the script text is interpolated by perl. That is, all $var, @array,
1204 %hash, and \-slashes are replaced by their respective values.
1205 <dt>3. In all other cases, the CGI and environment variables are added
1206 in front of the script according to the format stored in
1207 %ScriptingCGIvariables. That is, the following (pseudo-)code is
1208 executed for each CGI- or Environment variable defined in the CGI-tag:
1209 printf(INTERPRETER, $ScriptingCGIvariables{$mime}, $CGI_NAME, $CGI_VALUE);
1214 For instance,
"text/testperl" =
> '$%s =
"%s";' defines variable
1215 definitions for Perl, and
"text/sspython" =
> '%s =
"%s"' for Python
1216 (note that these definitions are not save, the real ones contain '-quotes).
1220 THIS WILL NOT WORK FOR @VARIABLES, the (empty) $VARIABLES will be used
1225 The $CGI_VALUE parameters are
"shrubed" of all control characters
1226 and quotes (by &shrubCGIparameter($CGI_VALUE)). Control characters
1227 are replaced by \
0<octal ascii value
> and quotes by their HTML character
1228 value (
’ -
> &#
8217;
‘ -
> &#
8216;
1229 " -
> &quot;). For example:
1230 if a client would supply the string value (in standard perl)
1234 <PRE>"/dev/null';\nrm -rf *;\necho '"</PRE>
1235 it would be processed as
1236 <PRE>'/dev/null
&#
8217;;\
015rm -rf *;\
015echo
&#
8217;'
</PRE>
1237 (e.g., sh or bash would process the latter more according to your
1239 If your intepreter requires different protection measures, you will
1240 have to supply these in %main::SHRUBcharacterTR (string =
> translation),
1244 $SHRUBcharacterTR{
"\'"} =
"&#8217;";
1249 Currently, the following definitions are used:
1253 %ScriptingCGIvariables = (
1254 "text/testperl" =
> "\$\%s = '\%s';", # Perl $VAR = 'value' (for testing)
1255 "text/sspython" =
> "\%s = '\%s'", # Python VAR = 'value'
1256 "text/ssruby" =
> '@%s =
"%s"', # Ruby @VAR =
"value"
1257 "text/sstcl" =
> 'set %s
"%s"', # TCL set VAR
"value"
1258 "text/ssawk" =
> '%s =
"%s";', # Awk VAR =
"value";
1259 "text/sslisp" =
> '(setq %s
"%s")', # Gnu lisp (rep) (setq VAR
"value")
1260 "text/ssprolog" =
> '', # Gnu prolog (interpolated)
1261 "text/ssm4" =
> "define(`\%s', `\%s')", # M4 macro's define(`VAR', `value')
1262 "text/sh" =
> "\%s='\%s';", # Born shell VAR='value';
1263 "text/bash" =
> "\%s='\%s';", # Born again shell VAR='value';
1264 "text/csh" =
> "\$\%s = '\%s';", # C shell $VAR = 'value';
1265 "text/ksh" =
> "\$\%s = '\%s';", # Korn shell $VAR = 'value';
1266 "text/sspraat" =
> '', # Praat (interpolation)
1267 "text/ssr" =
> '%s
<-
"%s";', # R VAR
<-
"value";
1268 "text/ssrebol" =
> '%s: copy
"%s"', # REBOL VAR: copy
"value"
1269 "text/postgresql" =
> '', # PostgreSQL (interpolation)
1275 Four tables allow fine-tuning of interpreter with code that should be
1276 added before and after each code block:
1280 Code added before each script block
1284 %ScriptingPrefix = (
1285 "text/testperl" =
> "\# Prefix Code;", # Perl script testing
1286 "text/ssm4" =
> 'divert(
0)' # M4 macro's (open STDOUT)
1291 Code added at the end of each script block
1295 %ScriptingPostfix = (
1296 "text/testperl" =
> "\# Postfix Code;", # Perl script testing
1297 "text/ssm4" =
> 'divert(-
1)' # M4 macro's (block STDOUT)
1302 Initialization code, inserted directly after opening (NEVER interpolated)
1306 %ScriptingInitialization = (
1307 "text/testperl" =
> "\# Initialization Code;", # Perl script testing
1308 "text/ssawk" =
> 'BEGIN {', # Server Side awk scripts
1309 "text/sslisp" =
> '(prog1 nil ', # Lisp (rep)
1310 "text/ssm4" =
> 'divert(-
1)' # M4 macro's (block STDOUT)
1315 Cleanup code, inserted before closing (NEVER interpolated)
1319 %ScriptingCleanup = (
1320 "text/testperl" =
> "\# Cleanup Code;", # Perl script testing
1321 "text/sspraat" =
> 'Quit',
1322 "text/ssawk" =
> '};', # Server Side awk scripts
1323 "text/sslisp" =
> '(princ
"\n" standard-output)).' # Closing print to rep
1324 "text/postgresql" =
> '\q',
1329 The SRC attribute is NOT magical for these interpreters. In short,
1330 all code inside a source file or {} block is written verbattim
1331 to the interpreter. No (pre-)processing or executional magic is done.
1335 A serious shortcomming of the described mechanism for handling other
1336 (scripting) languages, with respect to standard perl scripts
1337 (i.e., 'text/ssperl'), is that the code is only executed when
1338 the pipe to the interpreter is closed. So the pipe has to be
1339 closed at the end of each block. This means that the state of the
1340 interpreter (e.g., all variable values) is lost after the closing of
1341 the next
</SCRIPT
> tag. The standard 'text/ssperl' scripts retain
1342 all values and definitions.
1346 <A NAME=
"APPLIC"><H2 ALIGN=
"CENTER">APPLICATION MIME TYPES
</H2></A>
1349 To ease some important auxilliary functions from within the
1350 html pages I have added them as MIME types. This uses
1351 the mechanism that is also used for the evaluation of
1352 other scripting languages, with interpolation of CGI
1353 parameters (and perl-variables). Actually, these are
1354 defined exactly like any other
"scripting language".
1359 <dd>display some (HTML) text with interpolated
1360 variables (uses `cat`).
1362 <dd>write (append) the interpolated block to the file
1363 mentioned on the first, non-empty line
1364 (the filename can be preceded by 'File: ',
1365 note the space after the ':',
1366 uses `awk ....
>> <filename
>`).
1368 <dd>send email directly from within the script block.
1369 The first line of the body must contain
1370 To:Name@Valid.Email.Address
1371 (note: NO space between 'To:' and the email adres)
1372 For other options see the mailto man pages.
1373 It works by directly sending the (interpolated)
1374 content of the text block to a pipe into the
1375 Linux program 'mailto'.
1379 In these script blocks, all Perl variables will be
1380 replaced by their values. All CGI variables are cleaned before
1381 they are used. These CGI variables must be redefined with a
1382 CGI attribute to restore their original values.
1383 In general, this will be more secure than constructing
1384 e.g., your own email command lines. For instance, Mailto will
1385 not execute any odd (forged) email address, but just stops
1386 when the email address is invalid and awk will construct
1387 any filename you give it (e.g. '
<File;rm\\\
040-f' would end up
1388 as a
"valid" UNIX filename). Note that it will also gladly
1389 store this file anywhere (/../../../etc/passwd will work!).
1390 Use the CGIscriptor::CGIsafeFileName() function to clean the
1394 <A NAME=
"PIPES"><H2 ALIGN=
"CENTER">SHELL SCRIPT PIPING
</H2></A>
1397 If a shell script starts with the UNIX style
"#! <shell command> \n"
1398 line, the rest of the shell script is piped into the indicated command,
1400 open(COMMAND,
"| command");print COMMAND $RestOfScript;
1404 In many ways this is equivalent to the MIME-type profiling for
1405 evaluating other scripting languages as discussed above. The
1406 difference breaks down to convenience. Shell script piping is a
1407 "raw" implementation. It allows you to control all aspects of
1408 execution. Using the MIME-type profiling is easier, but has a
1409 lot of defaults built in that might get in the way. Another
1410 difference is that shell script piping uses the SAFEqx() function,
1411 and MIME-type profiling does not.
1415 Execution of shell scripts is under the control of the Perl Script blocks
1416 in the document. The MIME-type triggered execution of
<SCRIPT></SCRIPT>
1417 blocks can be simulated easily. You can switch to a different shell, e.g. tcl,
1418 completely by executing the following Perl commands inside your document:
1422 <SCRIPT
TYPE=
"text/ssperl">
1423 $main::ShellScriptContentType =
"text/ssTcl"; # Yes, you can do this
1424 CGIscriptor::RedirectShellScript('/usr/bin/tcl'); # Pipe to Tcl
1425 $CGIscriptor::NoShellScriptInterpolation =
1;
1430 After this script is executed, CGIscriptor will parse scripts of
1431 TYPE=
"text/ssTcl" and pipe their contents into '|/usr/bin/tcl'
1432 WITHOUT interpolation (i.e., NO substitution of Perl variables).
1433 The crucial function is :
1437 CGIscriptor::RedirectShellScript('/usr/bin/tcl')
1441 After executing this function, all shell scripts AND all
1442 calls to SAFEqx()) are piped into '|/usr/bin/tcl'. If the argument
1443 of RedirectShellScript is empty, e.g., '', the original (default)
1448 The standard output, STDOUT, of any pipe is send to the client.
1449 Currently, you should be carefull with quotes in such a piped script.
1450 The results of a pipe is NOT put on the @CGIscriptorResults stack.
1451 As a result, you do not have access to the output of any piped (#!)
1452 process! If you want such access, execute
1456 <SCRIPT
TYPE=
"text/ssperl">echo
"script"|command
</SCRIPT
>
1464 <SCRIPT
TYPE=
"text/ssperl">
1465 $resultvar = SAFEqx('echo
"script"|command');
1470 Safety is never complete. Although SAFEqx() prevents some of the
1471 most obvious forms of attacks and security slips, it cannot prevent
1472 them all. Especially, complex combinations of quotes and intricate
1473 variable references cannot be handled safely by SAFEqx. So be on
1477 <A NAME=
"SSPERL"><H2 ALIGN=
"CENTER">PERL CODE EVALUATION (CONTENT-TYPE=TEXT/SSPERL)
</H2></A>
1480 All PERL scripts are evaluated inside a PERL package. This package
1481 has a separate name space. This isolated name space protects the
1482 CGIscriptor.pl program against interference from user code. However,
1483 some variables, e.g., $_, are global and cannot be protected. You are
1484 advised NOT to use such global variable names. You CAN write
1485 directives that directly access the variables in the main program.
1486 You do so at your own risk (there is definitely enough rope available
1487 to hang yourself). The behavior of CGIscriptor becomes undefined if
1488 you change its private variables during run time. The PERL code
1489 directives are used as in:
1493 $Result = eval($directive); print $Result;'';
1497 ($directive contains all text between
<SCRIPT
></SCRIPT
>).
1498 That is, the
<directive
> is treated as ''-quoted string and
1499 the result is treated as a scalar. To prevent the VALUE of the code
1500 block from appearing on the client's screen, end the directive with
1501 ';
""</SCRIPT
>'. Evaluated directives return the last value, just as
1502 eval(), blocks, and subroutines, but only as a scalar.
1506 IMPORTANT: All PERL variables defined are persistent. Each
<SCRIPT
>
1507 </SCRIPT
> construct is evaluated as a {}-block with associated scope
1508 (e.g., for
"my $var;" declarations). This means that values assigned
1509 to a PERL variable can be used throughout the document unless they
1510 were declared with
"my". The following will actually work as intended
1511 (note that the ``-quotes in this example are NOT evaluated, but used
1516 <META
CONTENT=
"text/ssperl; CGI=`$String='abcdefg'`">
1518 <SCRIPT
TYPE=
"text/ssperl">@List = split('', $String);
</SCRIPT
>
1520 <SCRIPT
TYPE=
"text/ssperl">join(
", ", @List[
1..$#List]);
</SCRIPT
>
1524 The first
<SCRIPT
TYPE=
"text/ssperl"></SCRIPT
> construct will return the
1525 value scalar(@List), the second
<SCRIPT
TYPE=
"text/ssperl"></SCRIPT
>
1526 construct will print the elements of $String separated by commas, leaving
1527 out the first element, i.e., $List[
0].
1531 Another warning: './' and '~/' are ALWAYS replaced by the values of
1532 $YOUR_SCRIPTS and $YOUR_HTML_FILES, respectively . This can interfere
1533 with pattern matching, e.g., $a =~ s/aap\./noot\./g will result in the
1534 evaluations of $a =~ s/aap\\${YOUR_SCRIPTS}noot\./g. Use
1535 s@
<i>regexp
</i>@
<i>replacement
</i>@g instead.
1538 <A NAME=
"SESSIONTICKETS"><H2 ALIGN=
"CENTER">SERVER SIDE SESSIONS AND ACCESS CONTROL (LOGIN)
</H2></A>
1540 An infrastructure for user acount authorization and file access control
1541 is available. Each request is matched against a list of URL path patterns.
1542 If the request matches, a Session Ticket is required to access the URL.
1543 This Session Ticket should be present as a CGI parameter or Cookie, eg:
1546 CGI: SESSIONTICKET=
<value
><br />
1547 Cookie: CGIscriptorSESSION=
<value
></p>
1549 The example implementation stores Session Tickets as files in a local
1550 directory. To create Session Tickets, a Login request must be given
1551 with a LOGIN=
<value
> CGI parameter, a user name and a (doubly hashed)
1552 password. The user name and (singly hashed) password are stored in a
1553 PASSWORD ticket with the same name as the user account (name cleaned up
1557 The example session model implements
4 functions:
1560 The password is hashed with the user name and server side salt, and then
1561 hashed with a random salt. Client and Server both perform these actions
1562 and the Server only grants access if restults are the same. The server
1563 side only stores the password hashed with the user name and
1564 server side salt. Neither the plain password, nor the hashed password is
1565 ever exchanged. Only values hashed with the one-time salt are exchanged.
1568 For every access to a restricted URL, the Session Ticket is checked before
1569 access is granted. There are three session modes. The first uses a fixed
1570 Session Ticket that is stored as a cookie value in the browser (actually,
1571 as a sessionStorage value). The second uses only the IP address at login
1572 to authenticate requests. The third
1573 is a Challenge mode, where the client has to calculate the value of the
1574 next one-time Session Ticket from a value derived from the password and
1577 <li>Password Change
<br />
1578 A new password is hashed with the user name and server side salt, and
1579 then encrypted (XORed)
1580 with the old password hashed with the user name and salt and rehashed with
1581 the login ticket number. Ath the server side this operation is reversed.
1582 Again, the stored password value is never exchanged unencrypted.
1584 <li>New Account
<br />
1585 The text of a new account (Type: PASSWORD) file is constructed from
1586 the new username (CGI:
<em>NEWUSERNAME
</em>, converted to lowercase) and
1587 hashed new password (CGI:
<em>NEWPASSWORD
</em>).
1588 The same process is used to encrypt
1589 the new password as is used for the Password Change function.
1590 Again, the stored password value is never exchanged unencrypted.
1591 Some default setting are encoded. For display in the browser, the new password
1592 is reencrypted (XORed) with a special key, the old password hash
1593 hashed with a session specific random hex value sent initially with the
1594 session login ticket ($RANDOMSALT).
1595 <br />For example for user
<em>NewUser
</em>
1596 and password
<em>NewPassword
</em>:
1600 Password:
84b26fd2aaacae1c2e42fe07da1793e8232ffe548eceb519b46646fe9ff32612
1601 Salt:
970e68017413fb0ea84d7fe3c463077636dd6d53486910d4a53c693dd4109b1a
1602 AllowedPaths: ^/Private/[\w\-]+\.html?
1603 AllowedPaths: ^/Private/newuser/
1605 Date: Thu Jun
14 12:
34:
40 2012 UTC
1608 The password is created with the Unix commands:
1610 printf '%s' '
970e68017413fb0ea84d7fe3c463077636dd6d53486910d4a53c693dd4109b1aNewPasswordnewuser'|shasum -a
256
1615 <H3 ALIGN=
"CENTER">Implementation
</H3>
1617 The session authentication mechanism is based on the exchange of ticket
1618 identifiers. A ticket identifier is just a string of characters, a name
1619 or a random
64 character hexadecimal string. Ticket identifiers should be
1620 "safe" filenames (except user names). There are four types of tickets:
1622 <li>PASSWORD: User account descriptors, including a user name and password
</li>
1623 <li>LOGIN: Temporary anonymous tickets used during login
</li>
1624 <li>IPADDRESS: Authetication tokens that allow access based on the IP address of the request
</li>
1625 <li>SESSION: Reusable authetication tokens
</li>
1626 <li>CHALLENGE: One-time authetication tokens
</li>
1628 All tickets can have an expiration date in the form of a time duration
1629 from creation, in seconds, minutes, hours, or days (
<em>+duration
</em>[smhd]).
1630 An absolute time can be given in seconds since the epoch of the server host.
1631 Note that expiration times of CHALLENGE authetication tokens are calculated
1632 from the last access time. Accounts can include a maximal lifetime
1633 for session tickets (MaxLifetime).
1636 A Login page should create a LOGIN ticket file locally and send a
1637 server specific salt, a Random salt, and a LOGIN ticket
1638 identifier. The server side compares the username and hashed password,
1639 actually hashed(Random salt+hashed(serversalt+password)) from the client with
1640 the values it calculates from the stored Random salt from the LOGIN
1641 ticket and the hashed(serversalt+password) from the PASSWORD ticket. If
1642 successful, a new SESSION ticket is generated as a hash sum of the LOGIN
1643 ticket and the stored password. This SESSION ticket should also be
1644 generated by the client and stored as sessionStorage and cookie values
1645 as needed. The Username, IP address and Path are available as
1646 $LoginUsername, $LoginIPaddress, and $LoginPath, respectively.
1649 The CHALLENGE protocol stores the same value as the SESSION tickets.
1650 However, this value is not exchanged, but kept secret in the JavaScript
1651 <em>sessionStorage
</em> object. Instead, every page returned from the
1652 server will contain a one-time Challenge value ($CHALLENGETICKET) which
1653 has to be hashed with the stored value to return the current ticket
1657 In the current example implementation, all random values are created as
1658 full,
256 bit SHA256 hash values (Hex strings) of
64 bytes read from
1662 <H3 ALIGN=
"CENTER">Security considerations with Session tickets
</H3>
1664 For strong security, please use end-to-end encryption. This can be
1665 achieved using a VPN (Virtual Private Network), SSH tunnel, or a HTTPS
1666 capable server with OpenSSL. The session ticket system of CGIscriptor.pl
1667 is intended to be used as a simple authentication mechanism WITHOUT
1668 END-TO-END ENCRYPTION. The authenticating mechanism tries to use some
1669 simple means to protect the authentication process from eavesdropping.
1670 For this it uses a secure hash function, SHA256. For all practial purposes,
1671 it is impossible to
"decrypt" a SHA256 sum. But this login scheme is
1672 only as secure as your browser. Which, in general, is not very secure.
1675 Humans tend to reuse passwords. A compromise of a site running
1676 CGIscriptor.pl could therefore lead to a compromise of user accounts at
1677 other sites. Therefore, plain text passwords are never stored, used, or
1678 exchanged. Instead, a server site salt value is
"encrypted" with
1679 the plain password and user name. Actually, all are concatenated and hashed
1680 with a one-way secure hash function (SHA256) into a single string.
1681 Whenever the word
"password" is used, this hash sum is meant. Note that
1682 the salts are generated from /dev/urandom. You should check whether the
1683 implementation of /dev/urandom on your platform is secure before
1684 relying on it. This might be a problem when running CGIscriptor under
1685 Cygwin on MS Windows.
<br />
1686 <em>Note: no attempt is made to slow down the password hash, so bad
1687 passwords can be cracked by brute force
</em>
1690 As the (hashed) passwords are all that is needed to identify at the site,
1691 these should not be stored in this form. A site specific passphrase
1692 can be entered as an environment variable ($ENV{'CGIMasterKey'}). This
1693 phrase is hashed with the server site salt and the result is hashed with
1694 the user name and then XORed with the password when it is stored. Also, to
1695 detect changes to the account (PASSWORD) and session tickets, a
1696 (HMAC) hash of some of the contents of the ticket with the server salt and
1697 CGIMasterKey is stored in each ticket.
1700 Creating a valid (hashed) password, encrypt it with the CGIMasterKey and
1701 construct a signature of the ticket are non-trivial. This has to be redone
1702 with every change of the ticket file or CGIMasterKey change. CGIscriptor
1703 can do this from the command line with the command:
1705 perl CGIscriptor.pl --managelogin salt=Private/.Passwords/SALT \
1706 masterkey='Sherlock investigates oleander curry in Bath' \
1707 password='There is no password like more password' \
1710 CGIscriptor will exit after this command with the first option being
1711 <em>--managelogin
</em>. Options have the form:
1713 <li>salt=[file or string]
<br />Server salt value to use io the value
1714 stored in the ticket file. Will replace the stored value if a new
1715 password is given. If you change the server salt, you have to
1716 reset all the passwords. There is
<em>absolutely no
</em> procedure known
1717 to recover plaintext passwords, except asking the account holders.
1718 You are strongly adviced to make a backup before you apply such a change
</li>
1719 <li>masterkey=[file or string]
<br />CGIMasterKey used to read and decrypt
1721 <li>newmasterkey=[file or string]
<br />CGIMasterKey used to encrypt, sign,
1722 and write the ticket. Defaults to the masterkey. If you change
1723 the masterkey, you will have to reset all the accounts. You are strongly
1724 adviced to make a backup before you apply such a change
</li>
1725 <li>password=[file or string]
<br />New plaintext password
</li>
1727 When the value of an option is a existing file path, the first line of
1728 that file is used. Options are followed by one or more paths plus names
1729 of existing ticket files. Each password option is only used for a single
1730 ticket file. It is most definitely a bad idea to use a password that is
1731 identical to an existing filepath, as the file will be read instead. Be
1732 aware that the name of the file should be a cleaned up version of the
1733 Username.This will not be checked.
1736 For the authentication and a change of password, the (old) password
1737 is used to
"encrypt" a random one-time token or the new password,
1738 respectively. For authentication, decryption is not needed, so a secure
1739 hash function (SHA256) is used to create a one-way hash sum
"encryption".
1740 A new password must be decrypted. New passwords are encryped by XORing
1741 them with the old password.
1744 <h3 align=CENTER
>Strong Passwords: It is so easy
</h3>
1745 <p align=CENTER
><em>If you only could see what you are typing
</em></p>
1747 Your password might be vulnerable to
1748 <a href=
"https://en.wikipedia.org/wiki/Brute_force_attack">
1749 <em>brute force
</em></a> guessing. Protections against such attacks are
1750 costly in terms of code complexity, bugs, and execution time.
1751 However, there is a very simple and secure counter measure. See the
1752 <a href=
"http://xkcd.com/936/" target=
"_blank">XKCD comic
</a>. The phrase,
1753 <em>There is no password like more password
</em> would
1754 be both much easier to remember, and still stronger than
1755 <em>h4]D%@m:
49</em>, at least before this phrase was pasted as an example
1756 on the Internet.
<br />
1757 For the procedures used at this site, a basic computer setup can check
1758 in the order of a billion passwords per second. You need a password (or
1759 phrase) strength in the order of
56 bits to be a little secure (one year
1760 on a single computer). One of the largest network in the world, Bitcoin
1761 mining, can check some
12 terahashes per second (June
2012). This
1762 corresponds to checking
6 times
10<sup>12</sup> passwords per second.
1763 It would take a passwords strength of ~
68 bits to keep the equivalent of
1764 the Bitcoin computer network occupied for around a year before it found
1766 Please be so kind and add the name of your favorite flower, dish,
1767 fictional character, or small town to your password. Say,
1768 <em>Oleander
</em>,
<em>Curry
</em>,
<em>Sherlock
</em>, or
<em>Bath
</em> (each adds
1769 ~
12 bits) or even the phrase
<em>Sherlock investigates oleander curry in
1770 Bath
</em> (adds
> 56 bits, note that oleander is
<em>poisonous
</em>, so
1771 do not try this curry at home). That would be more effective than adding
1772 a thousand rounds of encryption.
1773 Typing long passwords without seeing what you are typing is problematic.
1774 So a button should be included to make password visible.
1776 <h3 align=CENTER
>Technical matters
</h3>
1778 Client side JavaScript code definitions. Variable names starting with '$'
1779 are CGIscriptor CGI variables. Some of the hashes could be strengthened
1780 by switching to HMAC signatures. However, the security issues of
1781 maintaining parallel functions for HMAC in both Perl and Javascript seem
1782 to be more serious than the attack vectors against the hashes. But HMAC
1783 is indeed used for the ticket signatures.
1787 HashPlaintextPassword() {
1788 var plaintextpassword = document.getElementById('PASSWORD');
1789 var serversalt = document.getElementById('SERVERSALT');
1790 var username = document.getElementById('CGIUSERNAME');
1791 return hex_sha256(serversalt.value+plaintextpassword.value+username.value.toLowerCase());
1793 var randomsalt = $RANDOMSALT; // From CGIscriptor
1794 var loginticket = $LOGINTICKET; // From CGIscriptor
1795 // Hash plaintext password
1796 var password = HashPlaintextPassword();
1798 var hashedpassword = hex_sha256(randomsalt+password);
1800 var sessionticket = hex_sha256(loginticket+password);
1801 sessionStorage.setItem(
"CGIscriptorPRIVATE", sessionticket);
1802 // Secretkey for encrypting new passwords, acts like a one-time pad
1803 // Is set anew with
<em>every
</em> login, ie, also whith password changes
1804 // and for each create new user request
1805 var secretkey = hex_sha256(randomsalt+loginticket+password);
1806 sessionStorage.setItem(
"CGIscriptorSECRET", secretkey);
1808 // For a SESSION type request
1809 sessionticket = sessionStorage.getItem(
"CGIscriptorPRIVATE");
1810 createCookie(
"CGIscriptorSESSION",sessionticket,
0,
"");
1812 // For a CHALLENGE type request
1813 var sessionset =
"$CHALLENGETICKET"; // From CGIscriptor
1814 var sessionkey = sessionStorage.getItem(
"CGIscriptorPRIVATE");
1815 sessionticket = hex_sha256(sessionset+sessionkey);
1816 createCookie(
"CGIscriptorCHALLENGE",sessionticket,
0,
"");
1818 // For transmitting a new password
1819 HashPlaintextNewPassword() {
1820 var plaintextpassword = document.getElementById('NEWPASSWORD');
1821 var serversalt = document.getElementById('SERVERSALT');
1822 var username = document.getElementById('NEWUSERNAME');
1823 return hex_sha256(serversalt.value+plaintextpassword.value+username.value.toLowerCase());
1826 var newpassword = document.getElementById('NEWPASSWORD');
1827 var newpasswordrep = document.getElementById('NEWPASSWORDREP');
1828 // Hash plaintext password
1829 newpassword.value = HashPlaintextNewPassword();
1830 var secretkey = sessionStorage.getItem(
"CGIscriptorSECRET");
1832 var encrypted = XOR_hex_strings(secretkey, newpassword.value);
1833 newpassword.value = encrypted;
1834 newpasswordrep.value = encrypted;
1836 // XOR of hexadecimal strings of equal length
1837 function XOR_hex_strings(hex1, hex2) {
1839 var maxlength = Math.max(hex1.length, hex2.length);
1841 for(var i=
0; i
< maxlength; ++i) {
1842 var h1 = hex1.charAt(i);
1844 var h2 = hex2.charAt(i);
1846 var d1 = parseInt(h1,
16);
1847 var d2 = parseInt(h2,
16);
1848 var resultD = d1^d2;
1849 resultHex = resultHex+resultD.toString(
16);
1857 <A NAME=
"USEREXTENSIONS"><H2 ALIGN=
"CENTER">USER EXTENSIONS
</H2></A>
1860 A CGIscriptor package is attached to the bottom of this file. With
1861 this package you can personalize your version of CGIscriptor by
1862 including often used perl routines. These subroutines can be
1863 accessed by prefixing their names with CGIscriptor::, e.g.,
1867 <SCRIPT
TYPE=
"text/ssperl">
1868 CGIscriptor::ListDocs(
"/Books/*") # List all documents in /Books
1873 It already contains some useful subroutines for Document Management.
1874 As it is a separate package, it has its own namespace, isolated from
1875 both the evaluator and the main program. To access variables from
1876 the document
<SCRIPT
></SCRIPT
> blocks, use $CGIexecute::
<var
>.
1880 Currently, the following functions are implemented
1881 (precede them with CGIscriptor::, see below for more information)
1885 <LI>SAFEqx ('String') -
> result of qx/
"String"/ # Safe application of ``-quotes
<br>
1886 Is used by text/osshell Shell scripts. Protects all CGI
1887 (client-supplied) values with single quotes before executing the
1888 commands (one of the few functions that also works WITHOUT CGIscriptor::
1890 <LI>defineCGIvariable ($name[, $default) -
> 0/
1 (i.e.,
1891 failure/success)
<br>
1892 Is used by the META tag to define and initialize CGI and ENV
1893 name/value pairs. Tries to obtain an initializing value from (in
1896 The Query string
<br>
1897 The default value given (if any)
<br>
1898 (one of the few functions that also works WITHOUT CGIscriptor::
1900 <LI>CGIsafeFileName (FileName) -
> FileName or
""<br>
1901 Check a string against the Allowed File Characters (and ../ /..).
1902 Returns an empty string for unsafe filenames.
1903 <LI>CGIsafeEmailAddress (Email) -
> Email or
""<br>
1904 Check a string against correct email address pattern.
1905 Returns an empty string for unsafe addresses.
1906 <LI>RedirectShellScript ('CommandString') -
> FILEHANDLER or undef
<br>
1907 Open a named PIPE for SAFEqx to receive ALL shell scripts
1908 <LI>URLdecode (URL encoded string) -
> plain string # Decode URL encoded argument
<br>
1909 <LI>URLencode (plain string) -
> URL encoded string # Encode argument as URL code
<br>
1910 <LI>CGIparseValue (ValueName [, URL_encoded_QueryString]) -
> Decoded value
<br>
1911 Extract the value of a CGI variable from the global or a private
1912 URL-encoded query (multipart POST raw, NOT decoded)
1913 <li>CGIparseValueList (ValueName [, URL_encoded_QueryString])
1914 -
> List of decoded values.
<br>
1915 As CGIparseValue, but now assembles ALL values of ValueName into a list.
1916 <LI>CGIparseHeader (ValueName [, URL_encoded_QueryString]) -
> Header
<br>
1917 Extract the header of a multipart CGI variable from the global or a private
1918 URL-encoded query (
"" when not a multipart variable or absent)
1919 <LI>CGIparseForm ([URL_encoded_QueryString]) -
> Decoded Form
<br>
1920 Decode the complete global URL-encoded query or a private
1922 <LI>read_url(URL)
<br>
1923 Returns the page from URL (with added base tag, both FTP and HTTP)
1924 Uses main::GET_URL(URL,
1) to get at the command to read the URL.
1925 <LI>BrowseDirs(RootDirectory [, Pattern, Startdir, CGIname]) # print browsable directories
1926 <LI>ListDocs(Pattern [,ListType]) # Prints a nested HTML directory listing of
1927 all documents, e.g., ListDocs(
"/*",
"dl");.
<br>
1928 <LI>HTMLdocTree(Pattern [,ListType]) # Prints a nested HTML listing of all
1929 local links starting from a given document, e.g.,
1930 HTMLdocTree(
"/Welcome.html",
"dl");
<br>
1933 <A NAME=
"RESULTSSTACK"><H2 ALIGN=
"CENTER">THE RESULTS STACK: @CGIscriptorResults
</H2></A>
1936 If the pseudo-variable
"$CGIscriptorResults" has been defined in a
1937 META tag, all subsequent SCRIPT and META results are pushed
1938 on the @CGIscriptorResults stack. This list is just another
1939 Perl variable and can be used and manipulated like any other list.
1940 $CGIscriptorResults[-
1] is always the last result.
1941 This is only of limited use, e.g., to use the results of an OS shell
1942 script inside a Perl script. Will NOT contain the results of Pipes
1943 or code from MIME-profiling.
1946 <A NAME=
"CGIPREDEFINED"><H2 ALIGN=
"CENTER">USEFULL CGI PREDEFINED VARIABLES (DO NOT ASSIGN TO THESE)
</H2></A>
1949 <li>$CGI_HOME - The ServerRoot directory
1950 <li>$CGI_Decoded_QS - The complete decoded Query String
1951 <li>$CGI_Content_Length - The ACTUAL length of the Query String
1952 <li>$CGI_Date - Current date and time
1953 <li>$CGI_Year $CGI_Month $CGI_Day $CGI_WeekDay - Current Date
1954 <li>$CGI_Time - Current Time
1955 <li>$CGI_Hour $CGI_Minutes $CGI_Seconds - Current Time, split
1957 <li>$CGI_GMTYear $CGI_GMTMonth $CGI_GMTDay $CGI_GMTWeekDay $CGI_GMTYearDay
1958 <li>$CGI_GMTHour $CGI_GMTMinutes $CGI_GMTSeconds $CGI_GMTisdst
1961 <A NAME=
"ENVIRONMENT"><H2 ALIGN=
"CENTER">USEFULL CGI ENVIRONMENT VARIABLES
</H2></A>
1964 Variables accessible (in APACHE) as $ENV{
"<name>"}
1965 (see:
"http://hoohoo.ncsa.uiuc.edu/cgi/env.html"):
1969 <LI>QUERY_STRING - The query part of URL, that is, everything that follows the
1971 <LI>PATH_INFO - Extra path information given after the script name
1972 <LI>PATH_TRANSLATED - Extra pathinfo translated through the rule system.
1973 (This doesn't always make sense.)
1974 <LI>REMOTE_USER - If the server supports user authentication, and the script is
1975 protected, this is the username they have authenticated as.
1976 <LI>REMOTE_HOST - The hostname making the request. If the server does not have
1977 this information, it should set REMOTE_ADDR and leave this unset
1978 <LI>REMOTE_ADDR - The IP address of the remote host making the request.
1979 <LI>REMOTE_IDENT - If the HTTP server supports RFC
931 identification, then this
1980 variable will be set to the remote user name retrieved from
1981 the server. Usage of this variable should be limited to logging
1983 <LI>AUTH_TYPE - If the server supports user authentication, and the script
1984 is protected, this is the protocol-specific authentication
1985 method used to validate the user.
1986 <LI>CONTENT_TYPE - For queries which have attached information, such as HTTP
1987 POST and PUT, this is the content type of the data.
1988 <LI>CONTENT_LENGTH - The length of the said content as given by the client.
1989 <LI>SERVER_SOFTWARE - The name and version of the information server software
1990 answering the request (and running the gateway).
1991 Format: name/version
1992 <LI>SERVER_NAME - The server's hostname, DNS alias, or IP address as it
1993 would appear in self-referencing URLs
1994 <LI>GATEWAY_INTERFACE - The revision of the CGI specification to which this
1995 server complies. Format: CGI/revision
1996 <LI>SERVER_PROTOCOL - The name and revision of the information protocol this
1997 request came in with. Format: protocol/revision
1998 <LI>SERVER_PORT - The port number to which the request was sent.
1999 <LI>REQUEST_METHOD - The method with which the request was made. For HTTP,
2000 this is
"GET",
"HEAD",
"POST", etc.
2001 <LI>SCRIPT_NAME - A virtual path to the script being executed, used for
2002 self-referencing URLs.
2003 <LI>HTTP_ACCEPT - The MIME types which the client will accept, as given by
2004 HTTP headers. Other protocols may need to get this
2005 information from elsewhere. Each item in this list should
2006 be separated by commas as per the HTTP spec.
2007 Format: type/subtype, type/subtype
2008 <LI>HTTP_USER_AGENT - The browser the client is using to send the request.
2009 General format: software/version library/version.
2012 <A NAME=
"RUNNING"><H2 ALIGN=
"CENTER">INSTRUCTIONS FOR RUNNING CGIscriptor ON UNIX
</H2></A>
2015 CGIscriptor.pl will run on any WWW server that runs Perl scripts,
2016 just add a line like the following to your srm.conf file
2021 ScriptAlias /SHTML/ /real-path/CGIscriptor.pl/
2025 URL's that refer to http://www.your.address/SHTML/... will now be handled
2026 by CGIscriptor.pl, which can use a private directory tree (default is the
2027 DOCUMENT_ROOT directory tree, but it can be anywhere, see manual).
2031 If your hosting ISP won't let you add ScriptAlias lines you can use
2032 the following
"rewrite"-based
"scriptalias" in .htaccess
2039 RewriteCond %{REQUEST_FILENAME} .html$
2040 RewriteCond %{SCRIPT_FILENAME} !cgiscriptor.pl$
2041 RewriteCond %{REQUEST_FILENAME} -f
2042 RewriteRule ^(.*)$ /cgi-bin/cgiscriptor.pl/$
1?%{QUERY_STRING}
2046 Everthing with the extension
".html" and not including
"cgiscriptor.pl"
2047 in the url and where the file
"path/filename.html" exists is redirected
2048 to
"/cgi.bin/cgiscriptor.pl/path/filename.html?query".
2049 The user configuration should get the same path-level as the
2054 # Just enter your own directory path here
2055 $YOUR_HTML_FILES =
"$ENV{'DOCUMENT_ROOT'}";
2056 # use DOCUMENT_ROOT only, if .htaccess lies in the root-directory.
2060 If this .htaccess goes in a specific directory, the path to this
2061 directory must be added to $ENV{'DOCUMENT_ROOT'}.
2065 The CGIscriptor file contains all documentation as comments. These comments
2066 can be removed to speed up loading (e.g., `egrep -v '^#' CGIscriptor.pl`
>
2067 leanScriptor.pl). A bare bones version of CGIscriptor.pl, lacking
2068 documentation, most comments, access control, example functions etc.
2069 (but still with the copyright notice and some minimal documentation)
2070 can be obtained by calling CGIscriptor.pl on the command line with the
2071 '-slim' command line argument, e.g.,
2075 >CGIscriptor.pl -slim
> slimCGIscriptor.pl
2079 CGIscriptor.pl can be run from the command line with
<path
> and
<query
> as
2080 arguments, as `CGIscriptor.pl
<path
> <query
>`, inside a perl script with
2081 'do CGIscriptor.pl' after setting $ENV{PATH_INFO} and $ENV{QUERY_STRING},
2082 or CGIscriptor.pl can be loaded with 'require
"/real-path/CGIscriptor.pl"'.
2083 In the latter case, requests are processed by 'Handle_Request();'
2084 (again after setting $ENV{PATH_INFO} and $ENV{QUERY_STRING}).
2088 The --help command line switch will print the manual.
2092 Using the command line execution option, CGIscriptor.pl can be used as a document
2093 (meta-)preprocessor. If the first argument is '-', STDIN will be read. For example:
2097 > cat MyDynamicDocument.html | CGIscriptor.pl - '[QueryString]'
> MyStaticFile.html
2101 This command line will produce a STATIC file with the DYNAMIC content of
2102 MyDocument.html
"interpolated". This option would be very dangerous when
2103 available over the internet. If someone could sneak a
2104 'http://www.your.domain/-' URL past your server, CGIscriptor could EXECUTE
2105 any POSTED contend. Therefore, for security reasons, STDIN will NOT
2106 be read if ANY of the HTTP server environment variables is set (e.g., SERVER_PORT,
2107 SERVER_PROTOCOL, SERVER_NAME, SERVER_SOFTWARE, HTTP_USER_AGENT,
2109 This block on processing STDIN on HTTP requests can be lifted by setting
2111 $BLOCK_STDIN_HTTP_REQUEST =
0;
2113 In the security configuration. But be carefull when doing this.
2114 It can be very dangerous.
2118 Running demo's and more information can be found at
2119 http://www.fon.hum.uva.nl/~rob/OSS/OSS.html
2123 A pocket-size HTTP daemon, CGIservlet.pl, is available from my web site
2124 or CPAN that can use CGIscriptor.pl as the base of a µWWW server and
2125 demonstrates its use.
2128 <A NAME=
"NON-UNIX"><H2 ALIGN=
"CENTER">NON-UNIX PLATFORMS
</H2></A>
2131 CGIscriptor.pl was mainly developed and tested on UNIX. However, as I
2132 coded part of the time on an Apple Macintosh under MacPerl, I made sure
2133 CGIscriptor did run under MacPerl (with command line options). But only as
2134 an independend script, not as part of a HTTP server. I have used it
2135 under Apache in Windows XP.
2138 <A NAME=
"license"><H2 ALIGN=
"CENTER">license
</H2></A>
2141 This program is free software; you can redistribute it and/or
2142 modify it under the terms of the GNU General Public License
2143 as published by the Free Software Foundation; either version
2
2144 of the License, or (at your option) any later version.
2148 This program is distributed in the hope that it will be useful,
2149 but WITHOUT ANY WARRANTY; without even the implied warranty of
2150 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2151 GNU General Public License for more details.
2155 You should have received a copy of the GNU General Public License
2156 along with this program; if not, write to the Free Software
2157 Foundation, Inc.,
59 Temple Place - Suite
330,
2158 Boston, MA
02111-
1307, USA.
2164 R.J.J.H.vanSon@uva.nl
2165 University of Amsterdam