Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
#!/usr/bin/env python2.7 # -*- coding: utf-8 -*- import cgi import logging import os ''' Factory to make the request handler and add arguments to it. It exists to allow the handler to access the opts.path variable locally. ''' class HTTPRequestHandler: def do_GET(BaseHTTPRequestHandler): m_BaseHTTPRequest = BaseHTTPRequestHandler # Parse out the arguments. # The arguments follow a '?' in the URL. Here is an example: # http://example.com?arg1=val1 args = {} idx = m_BaseHTTPRequest.path.find('?') if idx >= 0: rpath = m_BaseHTTPRequest.path[:idx] args = cgi.parse_qs(m_BaseHTTPRequest.path[idx+1:]) else: rpath = m_BaseHTTPRequest.path # Print out logging information about the path and args. if 'content-type' in m_BaseHTTPRequest.headers: ctype, _ = cgi.parse_header(m_BaseHTTPRequest.headers['content-type']) logging.debug('TYPE %s' % (ctype)) logging.debug('PATH %s' % (rpath)) logging.debug('ARGS %d' % (len(args))) if len(args): i = 0 for key in sorted(args): logging.debug('ARG[%d] %s=%s' % (i, key, args[key])) i += 1 # Check to see whether the file is stored locally, # if it is, display it. # Get the file path. path = HTTPRequestHandler.m_opts.rootdir + rpath dirpath = None logging.debug('FILE %s' % (path)) # If it is a directory look for index.html # or process it directly if there are 3 # trailing slashed. if rpath[-3:] == '///': dirpath = path elif os.path.exists(path) and os.path.isdir(path): dirpath = path # the directory portion index_files = ['/index.html', '/index.htm', ] for index_file in index_files: tmppath = path + index_file if os.path.exists(tmppath): path = tmppath break # Allow the user to type "///" at the end to see the # directory listing. if os.path.exists(path) and os.path.isfile(path): # This is valid file, send it as the response # after determining whether it is a type that # the server recognizes. _, ext = os.path.splitext(path) ext = ext.lower() content_type = { '.css': 'text/css', '.gif': 'image/gif', '.htm': 'text/html', '.html': 'text/html', '.jpeg': 'image/jpeg', '.jpg': 'image/jpg', '.js': 'text/javascript', '.png': 'image/png', '.text': 'text/plain', '.txt': 'text/plain', } # If it is a known extension, set the correct # content type in the response. if ext in content_type: m_BaseHTTPRequest.send_response(200) # OK m_BaseHTTPRequest.send_header('Content-type', content_type[ext]) m_BaseHTTPRequest.end_headers() with open(path) as ifp: m_BaseHTTPRequest.wfile.write(ifp.read()) else: # Unknown file type or a directory. # Treat it as plain text. m_BaseHTTPRequest.send_response(200) # OK m_BaseHTTPRequest.send_header('Content-type', 'text/plain') m_BaseHTTPRequest.end_headers() with open(path) as ifp: m_BaseHTTPRequest.wfile.write(ifp.read()) elif 1 == 2: # There is special handling for http://127.0.0.1/info. That URL # displays some internal information. if m_BaseHTTPRequest.path == '/info' or m_BaseHTTPRequest.path == '/info/': m_BaseHTTPRequest.send_response(200) # OK m_BaseHTTPRequest.send_header('Content-type', 'text/html') m_BaseHTTPRequest.end_headers() m_BaseHTTPRequest.info() else: if dirpath is None or m_BaseHTTPRequest.m_opts.no_dirlist == True: # Invalid file path, respond with a server access error m_BaseHTTPRequest.send_response(500) # generic server error for now m_BaseHTTPRequest.send_header('Content-type', 'text/html') m_BaseHTTPRequest.end_headers() m_BaseHTTPRequest.wfile.write('<html>') m_BaseHTTPRequest.wfile.write(' <head>') m_BaseHTTPRequest.wfile.write(' <title>Server Access Error</title>') m_BaseHTTPRequest.wfile.write(' </head>') m_BaseHTTPRequest.wfile.write(' <body>') m_BaseHTTPRequest.wfile.write(' <p>Server access error.</p>') m_BaseHTTPRequest.wfile.write(' <p>%r</p>' % (repr(m_BaseHTTPRequest.path))) m_BaseHTTPRequest.wfile.write(' <p><a href="%s">Back</a></p>' % (rpath)) m_BaseHTTPRequest.wfile.write(' </body>') m_BaseHTTPRequest.wfile.write('</html>') else: # List the directory contents. Allow simple navigation. logging.debug('DIR %s' % (dirpath)) m_BaseHTTPRequest.send_response(200) # OK m_BaseHTTPRequest.send_header('Content-type', 'text/html') m_BaseHTTPRequest.end_headers() m_BaseHTTPRequest.wfile.write('<html>') m_BaseHTTPRequest.wfile.write(' <head>') m_BaseHTTPRequest.wfile.write(' <title>%s</title>' % (dirpath)) m_BaseHTTPRequest.wfile.write(' </head>') m_BaseHTTPRequest.wfile.write(' <body>') m_BaseHTTPRequest.wfile.write(' <a href="%s">Home</a><br>' % ('/')); # Make the directory path navigable. dirstr = '' href = None for seg in rpath.split('/'): if href is None: href = seg else: href = href + '/' + seg dirstr += '/' dirstr += '<a href="%s">%s</a>' % (href, seg) m_BaseHTTPRequest.wfile.write(' <p>Directory: %s</p>' % (dirstr)) # Write out the simple directory list (name and size). m_BaseHTTPRequest.wfile.write(' <table border="0">') m_BaseHTTPRequest.wfile.write(' <tbody>') fnames = ['..'] fnames.extend(sorted(os.listdir(dirpath), key=str.lower)) for fname in fnames: m_BaseHTTPRequest.wfile.write(' <tr>') m_BaseHTTPRequest.wfile.write(' <td align="left">') path = rpath + '/' + fname fpath = os.path.join(dirpath, fname) if os.path.isdir(path): m_BaseHTTPRequest.wfile.write(' <a href="%s">%s/</a>' % (path, fname)) else: m_BaseHTTPRequest.wfile.write(' <a href="%s">%s</a>' % (path, fname)) m_BaseHTTPRequest.wfile.write(' <td> </td>') m_BaseHTTPRequest.wfile.write(' </td>') m_BaseHTTPRequest.wfile.write(' <td align="right">%d</td>' % (os.path.getsize(fpath))) m_BaseHTTPRequest.wfile.write(' </tr>') m_BaseHTTPRequest.wfile.write(' </tbody>') m_BaseHTTPRequest.wfile.write(' </table>') m_BaseHTTPRequest.wfile.write(' </body>') m_BaseHTTPRequest.wfile.write('</html>')
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Untitled
Python | 59 min ago | 0.13 KB
Decentralized Moneys
1 hour ago | 0.42 KB
120 million in 5 years
2 hours ago | 0.12 KB
December smells like money
2 hours ago | 0.07 KB
Crypto Liquidity Pools
2 hours ago | 0.47 KB
Trustless Finance
2 hours ago | 0.51 KB
The Lunar Kitsune - Yohana Tsukiko
4 hours ago | 21.38 KB
Crypto profits are insane
4 hours ago | 0.12 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!