# Eu Server

<article {width: 950px; display: table;}

This uses a heavily modified httpd.ex (from the Eu demos) to serve up files over the local network.

Apache would work, but who wants to deal with all that arcane stuff?, Besides, I'd still have to write cgi code to display the pages... so why go thru all that just to share some files? This solution is much simpler, and is written in Euphoria, so you can modify it as you wish!

Httpd.ex can work from a command line - just issue `%> eui httpd` to see the options. When running from the command line, you'll need to enter your server's IP address (use ifconfig to get that), and port, perhaps 8080, and the root (starting directory).

You can run more than one server at a time, just use a different port for each. For example, set the root for port 8081 to your Music/Blues folder, and the root for port 8082 to your Music/Opera folder - that way, listeners won't have to wade thru albums they may be allergic to:)

To make the server easier to use, I've added the EuGTK GUI shown above, which lets you select some options, and then starts the server running in the background when you click the OK button. Once it's running, you just enter the IP address and port in your tablet or phone's browser address bar to connect. e.g: `192.168.1.100:8080`

###

httpd.ex

- -help displays Usage
- -bind required ip_address:port, e.g. 192.168.1.100:8080
- -root required e.g. /home/irv/demos/documentation
- -log optional, name of log file
- -h optional, show hidden files in directory listing
- -s optional, sort directory listings
- -r optional, include full request and response in log
- -t optional, number of tries to obtain port before giving up

###

webserver.ex

- IP:
    Your network address, or 127.0.0.1 (a.k.a. localhost) if not networked. This should be filled in automatically. If it's wrong, use ifconfig to get the inet addr of your computer.
- Port:
    use 8080, 8081, etc. -- Avoid port 80
- Root:
    Starting (root) directory to serve up. Set this to your Music directory or a mounted music CD. Also, try your Pictures directory, Demos, etc... I have tried to make it difficult to browse 'off-limits', i.e: into files or folders which are not in or subfolders of doc_root. You may have better ideas than I do on this topic. Please contribute!
- Log file:
    Name of a file to write transactions to. A new log file will be created if necessary. You should delete it when no longer needed, since it continues to grow... I suggest you make the log file a hidden file, so it won't show in normal directory listings. Log entries will have date and time, client IP, plus name of file requested.
- Tail -f:
    If checked, opens a terminal which follows the log file. With mate-terminal, which I use, this opens a single terminal with two tabs, one for the web server messages, and another for following the log file. You may need to modify the routine at the top of webserver.ex which chooses a terminal, depending upon what terminal programs you have available. If, like mate-terminal, your term has different profiles, it will be helpful to create a new profile named 'logview' with different colors, a tiny font size, etc. for most convenient viewing of the log output. This is how I get the nice transparent log view shown in the screenshot at top.
- Sort:
    If checked, sort the file listing.
- Show Full Request
    Adds the full request string to the server log. This includes info on the browser doing the request. This info might be used to create and return different results depending upon whether the browser was running on a computer, or perhaps a cell phone.
- Show Hidden:
    If checked, show hidden files along with others in the directory listing

The appearance of the page is controlled by a file named .httpd.css, if it exists in the currently-browsed folder. This is done so that directory listings from different folders can have their own individual appearances (see screenshot above). If no .httpd.css exists in a given folder, defaults built into httpd.ex will be used.

Above, webserver.ex serving a specified file as entered on the address bar, or by clicking on a link in a previous page.

After closing the server, or a crash, it may take several seconds to minutes for your computer to free the port you've used. Trying to run again too soon using the same port will result in an error (-2). I have included a loop which will retry up to 20 times (unless overridden by the -t option), and then abort. If this happens, and you are running from the GUI, you can try hitting the OK button again. It may take several tries, or you may have to shut down the port manually from a terminal.