Slashdot Mirror


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 ;)

16 of 108 comments (clear)

  1. Why only the httpd? by yiegie · · Score: 4
    I've heard some people are building an entire operating system in LISP

    YDD

    --

    .sigmentation fault

    1. Re:Why only the httpd? by Anonymous Coward · · Score: 5
      (repost; better formatted)

      A modestly ugly HTTP server written in emacs lisp.

      ;;; Luke's Emacs Webserver ("LEW" aka "Loo" aka any toilet joke you please)
      ;;; Copyright (C) 1998-1999 Luke Gorrie
      ;;;
      ;;; This program is free software; you can redistribute it and/or
      ;;; modify it under the terms of the GNU General Public License
      ;;; as published by the Free Software Foundation; either version 2
      ;;; of the License, or (at your option) any later version.
      ;;;
      ;;; This program is distributed in the hope that it will be useful,
      ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
      ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      ;;; GNU General Public License for more details.
      ;;;
      ;;; You should have received a copy of the GNU General Public License
      ;;; along with this program; if not, write to the Free Software
      ;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

      ;;; TODO list:
      ;;; support HEAD requests
      ;;; add some sort of dynamic content facility, either for elisp `servlets' or cgi

      ;;; $Id: http-server.el,v 1.2 1999/07/01 19:01:06 luke Exp luke $

      (setq http-hits 0)

      ;;; configuration

      (setq http-404-message
      (concat "File not found."
      "File not found"
      "

      "
      "The file requested does not exist, or is not a regular file, "
      "or something."
      ""))

      ;; regex path -> mime-type mappings
      (setq mimetypes-alist
      '(("\\.gif" .
      "image/gif")
      ("\\.jpg" .
      "image/jpeg")
      ("\\.png" .
      "image/png")
      ("\\.\\(el\\|txt\\|erl\\|scm\\)" .
      "text/plain")
      ("\\.html" .
      "text/html")
      ("\\.\\(tar\\|gz\\|tgz\\|zip\\|exe\\|pdf\\|ps\\)" .
      "application/octet-stream")))

      ;; document root directory
      (setq document-base "/mnt/baked/www/vegetable.org")

      ;;; http server code

      ;; open a socket to the connection-connector with a transaction callback to
      ;; serve the request when it arrives
      (defun offer-http-service ()
      (let ((service-successful nil))
      (unwind-protect
      (progn
      (lexical-let ((proc (open-network-stream "bar" "baz" "localhost" 8012)))
      (set-process-sentinel proc 'http-sentinel)
      (let ((tq (tq-create proc)))
      (tq-enqueue tq "" ".*\r\n\r\n" "Http Connection"
      #'(lambda (closure answer)
      (lexical-let ((answer answer))
      (handle-http-request proc answer))))))
      (setq service-successful t))
      (if (not service-successful)
      (progn (offer-http-service) (message "service failed"))))))

      ;; called if there's an error in between offer-http-service
      ;; and handle-http-request -- usually when the connection is broken
      (defun http-sentinel (proc sentinel)
      (offer-http-service))

      ;; read a file as a string
      (defun filestring (filename)
      (save-excursion
      (switch-to-buffer "*loading-work*")
      (insert-file-contents filename)
      (let ((contents (buffer-string)))
      (kill-buffer "*loading-work*")
      contents)))

      (defun process-send-file (process filename)
      (save-excursion
      (switch-to-buffer "*loading-work*")
      (insert-file-contents filename)
      (mark-whole-buffer)
      (process-send-region process (point) (mark))
      (kill-buffer "*loading-work")))

      ;; returns the file length
      (defun load-file-for-io (filename)
      (save-excursion
      (switch-to-buffer "*loading-work*")
      (insert-file-contents filename)
      (mark-whole-buffer)
      (- (mark) (point))))

      (defun send-current-file (process)
      (save-excursion
      (switch-to-buffer "*loading-work*")
      (mark-whole-buffer)
      (process-send-region process (point) (mark))
      (kill-buffer "*loading-work*")))

      ;; handle a http request. Takes a process and request with headers,
      ;; and sends the response
      (defun handle-http-request (proc request)
      (unwind-protect
      (progn
      (string-match "\\( \\)\\(.*\\)\\( \\)" request)
      (let ((r-path (concat document-base (match-string 2 request))))
      (message r-path)
      ;; append "index.html" to and directory name
      (if (string-match "/$" r-path)
      (setq r-path (concat r-path "index.html")))
      ;; protect against accessing ../../ to get above document base
      (if (string-match "\\.\\." r-path)
      (setq r-path (concat document-base "/index.html")))
      ;; file exists?
      (if (file-regular-p r-path)
      (let ((length (load-file-for-io r-path)))
      (message "request")
      (process-send-string
      proc (concat "HTTP/1.0 200 OK\r\n"
      "Content-Type: "
      (get-mimetype r-path mimetypes-alist "text/html")
      "\r\n"
      "Content-length: "
      (number-to-string length) "\r\n"
      "Server: " (version) "\r\n"
      "Last-Modified: " (current-time-string) "\r\n"
      "Connection: close\r\n"
      "\r\n"
      ))
      (send-current-file proc))
      ;; not a regular file
      (process-send-string
      proc (concat "HTTP/1.0 404 Not Found\r\n"
      "Connection: close\r\n"
      "Content-Type: text/html\r\n"
      "\r\n"
      http-404-message)))
      (delete-process proc)
      (setq http-hits (+ 1 http-hits)))))
      (offer-http-service))

      ;; show number of hits
      (defun show-http-stats ()
      (message (concat "HTTP hits: " (number-to-string http-hits))))

      ;; determine the mimetype of path
      (defun get-mimetype (path map default)
      (if (eq map nil)
      default
      (let ((element (car map)))
      (if (string-match (car element) path)
      (cdr element)
      (get-mimetype path (cdr map) default)))))

  2. PS Source Code (GPL) by Mignon · · Score: 5

    "To install it, run from inetd:"

    8080 stream tcp nowait nobody /usr/bin/gs gs -dNODISPLAY -q \
    /home/pugo/src/postscript/pshttpd/pshttpd.ps

    Here's the source, in case the server gets PSDotted:

    %! %================================================= == % PS-HTTPD V1.0 %
    Copyright 2000 Anders Karlsson, pugo@pugo.org % License: GNU General Public License
    %=============================================== ==== /get_file % read file /infile
    and send it to %stdout { /buff 2048 string def { % loop infile buff readstring { stdout exch writestring
    } { stdout exch writestring infile closefile exit } ifelse } bind loop } def /read_command % read
    command from stdin and define it to /command { /stdin (%stdin) (r) file def /inbuff 256 string def
    stdin inbuff readline pop /command exch def } def /concatstr % (a) (b) -- (ab) { /beta exch def /alfa
    exch def /buffer 1024 string def alfa buffer copy pop buffer alfa length beta putinterval buffer (\000)
    search pop exch pop exch pop } def /hitcount { /hitfile (/usr/local/psweb/hits) (r) file def /hits 16
    string def hitfile hits readstring pop hitfile closefile /hitfile (/usr/local/psweb/hits) (w+) file def cvi 1
    add hits cvs hitfile exch writestring hitfile closefile } def /print_header { stdout (HTTP/1.0 200
    OK\n\n) writestring % stdout (Server: PS-HTTPD/1.0\n) writestring % stdout (Content-type:
    text/html\n) writestring } def /parse_result { command token { (GET) eq { ( ) search { root exch
    concatstr % build path /filename exch def pop pop % define filename and clean stack filename
    filename length 1 sub 1 getinterval (/) eq { filename (index.html) concatstr /filename exch def } if %
    add index.html filename (..) search { stdout (4711 Stupid user error!\n\n) writestring quit } if pop
    filename /infile exch (r) file def % open file print_header get_file } if } if } if } def % Init
    environment /stdout (%stdout) (w) file def /command () def % Root-path (root of WWW-pages)
    /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

  3. (OT) Retro technology comes full circle by Morbid+Curiosity · · Score: 5

    "... 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 :-)

  4. dd/sh by oyvindmo · · Score: 5

    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*

  5. PostScript flexibility by Tet · · Score: 4

    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
  6. HTTPD in assembler by Anonymous Coward · · Score: 4

    At the asmutils page. 586 bytes standalone executable. Make that!

    Best regards,
    The Anonymous Coward from Estern Europe

  7. Jigsaw by David+A.+Madore · · Score: 4

    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?

    1. Re:Jigsaw by hargettp · · Score: 3

      I use to run Jigsaw at home to serve up various documents on my network and to test server-based programming (Perl/CGI, Java servlets, etc.).

      As a positive, Jigsaw is a feature rich server.

      - Permits configuration of MIME types, content negotiation

      - Security-based access to selected resources (not SSL--just standard HTTP USER and PASSWORD authentication)

      - A Java-based admin tool suitable for remote administration

      - Support for virtual servers

      - Enables server-side processing, such as server side includes, CGI (through executables or through interpreters such as Perl), servlets, and a form of page scripting that allowed Java to be embedded in HTML (pre-JSP), among other techniques.

      - Conformance to current specifications.

      Eventually, I've abandoned Jigsaw, preferring either Apache or Tomcat. Here are my reasons:

      - Performance. Although Jigsaw is not abominable, this was never a fast server.

      - Frequent hangs. Although it is possible this was a WinNT issue, I found Jigsaw would frequently hang, often while serving images (?) for a document. On NT it would hang so badly Windows Explorer itself would no longer be able to display images for Web Folders unless I rebooted.

      - An arcane architectural model. Jigsaw has a very powerful yet very abstract design based upon resources, frames, and filters. Sure, that was great for providing nearly limitless ways of customizing it's behaviour, but it was pretty hard to figure out what type of class to extend in order to customize the server. Frankly, servlets +JSP+all else Java give me just about all the customization I need.

      - Slow integration with non-W3C standards. That's definitely a whine, but Jigsaw was usually a fraction of a step behind Sun's latest servlet spec, and took forever to adopt JSP in place of it's own Java-in-HTML service (although I did like their implementation). In fairness, this has been simply because W3C hasn't had resources for more than 1 or 2 people to handle the code, and the original author has unfortunately moved on from the W3C.

      So, I haven't found Jigsaw worth running on a regular basis, but I will leave you with this: there's a *heck* of a lot of free code inside that server, so if nothing else one can learn from their design and even borrow some bits (haven't checked the license recently) for other projects. Good source of samples for Java network programming.

      My $.02

  8. In shell by David+A.+Madore · · Score: 3

    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

  9. Coding in unusual languages by Nilz · · Score: 3

    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!

  10. Re:GS is cheating by Megane · · Score: 3

    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; }
  11. secure sh-httpd? by kijiki · · Score: 5

    Man, trying to secure a httpd written in sh is gonna suck. Just for starters, try:
    http://jester.vip.net.pl:8081/../../../../../../ ../../../../etc/passwd

    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!

  12. Re:What is the point of shell scripts? by darango · · Score: 3

    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.

  13. Big Deal by roman_mir · · Score: 4

    I heard about a company who wrote a graphical interface to a 4 bit operating system and called the whole thing NT Server!

  14. Web Fileserver written in MS Word VBA by dildog · · Score: 5
    I wrote this thing a while back to serve files on and off of a machine when a Word document is opened. Try downloading this, and running it with macros enabled. Then browse to your own port 80. If you don't trust word macros, take a look at the source first with the visual basic editor. Requires Office 2000, but will work with Office 97 if you convert it down.

    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.