Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

The objective was to write a simple HTTP server that supported resuming of downloads via the Range heeaders. The server should also be fairly secure, as it runs unattended on my firewall box, and thus, it should also not require any fancy setup that could be misconfigured.

The server must be run with the taint option of Perl for even more security. I toyed with the idea of locking the server in a chroot() jail, but getting Perl/HTTP::Daemon to work in such a jail is no easy feat, so I ditched the idea (see objective above).

The server works under both, Win32 and Unix, but under Win32 it dosen't support fork, as the fork emulation is not always working for me. In the spirit of simplicity, it also dosen't support any CGI capabilities, since CGI capabilities present a security hole waiting to be exploited. Also, "hidden" files starting with a dot (".") are not available for download as well. On the upside, the server fully supports persistent connections.

Of course, the total number of lines is arbitrarily set at 99 lines, as there is much whitespace to be compressed, but I wanted to keep a sensible mix of obfuscation/compression and readability, as I think that maybe other people than me would want to use this code.

Command line options

perl -wT miniserver.pl [document_root]

Disclaimer

Even though I tried to be as paranoid as possible about my own code, I can't guarantee that the code is secure in any way other than taking up valuable CPU time and/or disk space. If you find any interesting exploits, please add them in a reply here, so others can learn from my mistakes.

2001-10-05 Update: Fixed small germanism thanks to John M. Dlugosz

2001-10-05 Update: Fixed missing use strict; at the top of the script. Thanks to ybiC for mentioning it to me. My Pascal upbringing seems to have protected me against violating strict, as no code rework was necessary...

2004-07-11 Update: Fixed _stamp routine so it actually displays a useful timestamp. Thanks to BrowserUK for finding it in that code.


In reply to Documentation for the Simple HTTP server in under 100 lines by Corion
in thread Simple HTTP in under 100 lines by Corion

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 11:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found