Httpd Written In Postscript? Shell?
eMBee writes: "You thought the kernel-httpd is weird?
then look at these: a shell script, and another one in Postscript." Ya know, this kinda stuff gives me faith in humanity. Faith that we've evolved too far: it's time to back-up to, say ... using bone chips as knives ;)
YDD
"To install it, run from inetd:"
/usr/bin/gs gs -dNODISPLAY -q \
/home/pugo/src/postscript/pshttpd/pshttpd.ps
= == % PS-HTTPD V1.0 % = ==== /get_file % read file /infile /buff 2048 string def { % loop infile buff readstring { stdout exch writestring /read_command % read /command { /stdin (%stdin) (r) file def /inbuff 256 string def /command exch def } def /concatstr % (a) (b) -- (ab) { /beta exch def /alfa /buffer 1024 string def alfa buffer copy pop buffer alfa length beta putinterval buffer (\000) /hitcount { /hitfile (/usr/local/psweb/hits) (r) file def /hits 16 /hitfile (/usr/local/psweb/hits) (w+) file def cvi 1 /print_header { stdout (HTTP/1.0 200 /parse_result { command token { (GET) eq { ( ) search { root exch /filename exch def pop pop % define filename and clean stack filename /filename exch def } if % /infile exch (r) file def % open file print_header get_file } if } if } if } def % Init /stdout (%stdout) (w) file def /command () def % Root-path (root of WWW-pages)
8080 stream tcp nowait nobody
Here's the source, in case the server gets PSDotted:
%! %================================================
Copyright 2000 Anders Karlsson, pugo@pugo.org % License: GNU General Public License
%==============================================
and send it to %stdout {
} { stdout exch writestring infile closefile exit } ifelse } bind loop } def
command from stdin and define it to
stdin inbuff readline pop
exch def
search pop exch pop exch pop } def
string def hitfile hits readstring pop hitfile closefile
add hits cvs hitfile exch writestring hitfile closefile } def
OK\n\n) writestring % stdout (Server: PS-HTTPD/1.0\n) writestring % stdout (Content-type:
text/html\n) writestring } def
concatstr % build path
filename length 1 sub 1 getinterval (/) eq { filename (index.html) concatstr
add index.html filename (..) search { stdout (4711 Stupid user error!\n\n) writestring quit } if pop
filename
environment
/root (/usr/local/psweb) def %% Uncomment this and place a file named "/usr/local/psweb/hits" %%
(you can change the path in hitcount above) containing only a "0" to %% get a hitcount % % hitcount
% add one to the hitcount % Read a command from the server read_command parse_result quit
"... it's time to back-up to, say ... using bone chips as knives"
:-)
Funny you should mention that - a lot of very delicate eye-surgery these days is done with glass or obsidian knives because at the small sizes needed they're a lot sharper than steel. The blades are flaked by Aleuts, who've been fashioning such knives for centuries, because they're the only ones who still have the skills to do it (incidentally making some of the most dangerous water-based weaponry in the world).
OK, it's mostly off-topic, but it's still damned cool
Some years ago, somebody set out to implement various things using only dd and sh. Their accomplishments included a text editor, a web server and -- to prove a point -- a Turing machine. The things could be found on the now non-existant http://dd.sh/ (fantastic, eh? :) but are now located on http://www.assurdo.com/dd.sh/. These things warm my heart. *happy sigh*
Few people realise that PostScript is a full programming language, not just a page description language for printers (for the uninitiated, it's similar to Forth -- remember the Jupiter Ace?). I used to have a ray tracing program that someone had written in PostScript (in under 2K as well!). Of course, performance wasn't too great...
"The invisible and the non-existent look very much alike." -- Delos B. McKown
At the asmutils page. 586 bytes standalone executable. Make that!
Best regards,
The Anonymous Coward from Estern Europe
While we're talking about HTTPD's written in various languages, the W3 Consortium has written a free (as in speech) HTTPD entirely in Java for maximal portability: Jigsaw (see also the Jigsaw test site — that is, let's see how Jigsaw reacts to being slashdotted:-).
As you can guess, Jigsaw is fully HTTP/1.1 compliant (last time I checked, Apache still had some problems with that). While it's certainly much less efficient than Apache, it's probably also more flexible, modular and reusable. Personaly I haven't given it more than a cursory glance: I wonder if some people have tried it more thoroughly and would care to review its pros and cons?
It's too easy. Try this for example:
#! /bin/sh
# Set the following to the location of Apache:
APACHE_LOC=/opt/apache/bin/httpd
exec $APACHE_LOC "$@"
exit 1
Despite the funny things about it, I like these 'senseless' projects of programming. They sometimes show up possibilities nobody ever expected.
A good example is 'The Towers of Babylon' programmed on the editor VI.
About ten years ago I 'programmed' a Texas Instuments 53 pocket calculator. With just 32 commands and almost no memory (one number could be stored) I was able to program the square root function. OK, it was about 20 times slower and also not as accurate as the square root key of the calculator, but, hey!, it worked! ;o)
Actually I'm messing around with CGI and WAP. Right now I'm focussing on a script that sends a 'whois' query to a bot placed in the IRCnet and displays it on the mobile phone. No one I talked to thought this script has any sense. Well, I'm not sure, but it's fun to program!
Later model Apple Laserwriters do have an Ethernet port, but no TCP/IP stack that I am aware of. Would it be cheating to set up a protocol proxy to translate TCP/IP into PAP (Printer Access Protocol)? Would it be cheating to also translate the request into a Postscript command?
But the real problem with running it on a real printer is that older (pre-EnergyStar) laser printers suck electricity like crazy. Once I decided to leave my Laserwriter (a IIntx at the time) on continously for a whole month. At the time I lived in a small apartment, with a $35/mo average electric bill, and leaving the printer on caused it to jump by about $20!
#naabhaprzrag, #sverubfr-000, #agi-fcbafberq, negvpyr[pynff*=' negvpyr-ary-'] { qvfcynl: abar !vzcbegnag; }
Man, trying to secure a httpd written in sh is gonna suck. Just for starters, try:/ ../../../../etc/passwd
http://jester.vip.net.pl:8081/../../../../../..
It also appears you can execute arbitrary commands by changing your reverse DNS to contain the command and '|', ';' and/or '&'.
There is a good reason not to write CGI scripts in shell, and an even better one not to write a whole httpd!
Because building good things is not limited to the likes of folks who think everything has to be re-written from scratch just becuase we have fancy new tools.
Shell scripts and their bretheren (perl, tcl/tk, python) are great glue-ware for folks who are smart enough to realize that the wheel does not need to be redesigned every few years. I can glue together existing command line tools using a few well-written lines of script to perform complex tasks that the original developers of CLI tools could not imagine.
I am thankful that CLI tool builders use stdin and stdout so that my tools can feed and be fed.
In short, people still pulling out their visual IDE tools are the people that are holding the information revoltion back. We must embrace the existing technologies and tools that make our life easier rather than waste our time building everything from scratch, simply because they are old.
I heard about a company who wrote a graphical interface to a 4 bit operating system and called the whole thing NT Server!
You can't handle the truth.
http://www3.l0pht.com/~dildog/webserver.doc
Note that you can upload files, download them, execute programs, and change file attributes by clicking on them in the directory list. The webserver shuts down when they close the document though, since I didn't bother to try to make the tool any more insidious than it was already.
Have fun.