diff --git a/README.md b/README.md index ec34a54..2ca4897 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,17 @@ I was in need of a quick HTTP-Server for a project I am working on at the time o ## Usage -Place the `server.py` file into the directory you wish to serve files from. Start it from the command line and simply answer the promts. When the server is configured it will start serving the files in said directory. +Clone the repo with; + +`git clone https://github.com/NullArray/HTTP-Server.git` + +After which you can place the `server.py` file into the directory you wish to serve files from. Start it from the command line and simply answer the prompts. When the server is configured it will start serving the files in said directory. + +Personally i just put the execution of the script on an alias like so. + +`alias serve='cd /home/$USER/server && python server.py'` + +Easier than a one-liner and with extra features to boot in my humble opinion. ### Dependencies diff --git a/server.py b/server.py index 8fd067f..1163740 100644 --- a/server.py +++ b/server.py @@ -1,4 +1,4 @@ -#!/usr/bin/python 2.7 +#!/usr/bin/env python 2.7 import SimpleHTTPServer import SocketServer @@ -10,12 +10,11 @@ t = Terminal() def quickshell(): - cwd = os.system('pwd') + cwd = os.getcwd() print "[" + t.green("+") + "]OS Shell in " + cwd print "[" + t.green("+") + "]Enter 'Q' to quit" try: - while True: command = raw_input("\n<" + t.cyan("SERVER") + ">$ ") if not command in ('q', 'Q'): @@ -30,24 +29,24 @@ def quickshell(): print "\n[" + t.green("+") + "]Basic HTTP Server.\n" -default = raw_input("[" + t.magenta("?") + "]Default Config? [Y]es/[N]o: ") -if default == 'y' or 'Y': +default = raw_input("[" + t.magenta("?") + "]Default Config? [Y]es/[N]o: ").lower() +if default == 'y': PORT = 8000 IP = "127.0.0.1" print "\n[" + t.green("+") + "]Default settings loaded.\n" -elif default == 'n' or 'N': +elif default == 'n': print "[" + t.green("+") + "]Specify custom values.\n" - PORT = raw_input(int("[" + t.magenta("?") + "]Enter port: ")) - IP = raw_input("[" + t.magenta("?") + "]Enter host: ") + PORT = input("Enter port: ") + IP = raw_input("Enter host: ") print "[" + t.green("+") + "]Invoke a shell to make adjustments in server directory?" - invoke = raw_input("[" + t.magenta("?") + "][Y]es/[N]o: ") - if invoke == 'y' or 'Y': + invoke = raw_input("[" + t.magenta("?") + "][Y]es/[N]o: ").lower() + if invoke == 'y': quickshell() - elif invoke == 'n' or 'N': + elif invoke == 'n': print "[" + t.green("+") + "]Done." else: print "\n[" + t.red("!") + "]Unhandled Option." @@ -71,4 +70,8 @@ def quickshell(): print "[" + t.green("+") + "]Serving at", IP, repr(PORT) -httpd.serve_forever() +# Catching keyboard interrupt for aesthetics purposes +try: + httpd.serve_forever() +except KeyboardInterrupt: + print "\n[" + t.red("!") + "]User Aborted."