forked from seba/servefile
Basic dirlisting with SimpleHTTPRequestHandler
This commit is contained in:
parent
bd611eb219
commit
6c5cca4a00
16
servefile
16
servefile
|
@ -16,6 +16,7 @@ import datetime
|
||||||
import urllib
|
import urllib
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import SimpleHTTPServer
|
||||||
import SocketServer
|
import SocketServer
|
||||||
import socket
|
import socket
|
||||||
from stat import ST_SIZE
|
from stat import ST_SIZE
|
||||||
|
@ -309,7 +310,7 @@ class ServeFileException(Exception):
|
||||||
class ServeFile():
|
class ServeFile():
|
||||||
""" Main class to manage everything. """
|
""" Main class to manage everything. """
|
||||||
|
|
||||||
(MODE_SINGLE, MODE_UPLOAD, MODE_DIRLIST) = range(3)
|
(MODE_SINGLE, MODE_UPLOAD, MODE_LISTDIR) = range(3)
|
||||||
|
|
||||||
def __init__(self, target, port=8080, serveMode=0, useSSL=False):
|
def __init__(self, target, port=8080, serveMode=0, useSSL=False):
|
||||||
self.target = target
|
self.target = target
|
||||||
|
@ -482,6 +483,13 @@ class ServeFile():
|
||||||
FilePutter.targetDir = self.target
|
FilePutter.targetDir = self.target
|
||||||
FilePutter.maxUploadSize = self.maxUploadSize
|
FilePutter.maxUploadSize = self.maxUploadSize
|
||||||
handler = FilePutter
|
handler = FilePutter
|
||||||
|
elif self.serveMode == self.MODE_LISTDIR:
|
||||||
|
try:
|
||||||
|
os.chdir(self.target)
|
||||||
|
except OSError:
|
||||||
|
raise ServeFileException("Error: Could not change directory to '%s'" % self.target)
|
||||||
|
handler = SimpleHTTPServer.SimpleHTTPRequestHandler
|
||||||
|
|
||||||
|
|
||||||
if self.auth:
|
if self.auth:
|
||||||
# do authentication
|
# do authentication
|
||||||
|
@ -540,6 +548,8 @@ def main():
|
||||||
help="Enable uploads to a given directory")
|
help="Enable uploads to a given directory")
|
||||||
parser.add_argument('-s', '--max-upload-size', type=str, \
|
parser.add_argument('-s', '--max-upload-size', type=str, \
|
||||||
help="Limit uploadsize in kb. Size modifiers are allowed, e.g. 2G, 12Mb, 1b.")
|
help="Limit uploadsize in kb. Size modifiers are allowed, e.g. 2G, 12Mb, 1b.")
|
||||||
|
parser.add_argument('-l', '--list-dir', action="store_true", default=False, \
|
||||||
|
help="Show directory indexes and allow access to all subdirectories")
|
||||||
parser.add_argument('--ssl', action="store_true", default=False, \
|
parser.add_argument('--ssl', action="store_true", default=False, \
|
||||||
help="Enable SSL. If no key/cert is specified one will be generated.")
|
help="Enable SSL. If no key/cert is specified one will be generated.")
|
||||||
parser.add_argument('--key', type=str, \
|
parser.add_argument('--key', type=str, \
|
||||||
|
@ -591,8 +601,8 @@ def main():
|
||||||
mode = None
|
mode = None
|
||||||
if args.upload:
|
if args.upload:
|
||||||
mode = ServeFile.MODE_UPLOAD
|
mode = ServeFile.MODE_UPLOAD
|
||||||
#elif args.listdir:
|
elif args.list_dir:
|
||||||
# mode = ServeFile.MODE_LISTDIR
|
mode = ServeFile.MODE_LISTDIR
|
||||||
else:
|
else:
|
||||||
mode = ServeFile.MODE_SINGLE
|
mode = ServeFile.MODE_SINGLE
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue