Created
February 6, 2017 21:15
-
-
Save mrts/99cd9d9b95316bdf2058dd40072bf967 to your computer and use it in GitHub Desktop.
Patch to Python's bundled CGIHTTPServer.py (from Python 2.7) to run Perl scripts. Useful for serving e.g. AWStats files. Copy `Python27/lib/CGIHTTPServer.py` out, apply the patch and run with `python CGIHTTPServer.py` in `wwwroot`. Then open http://localhost:8000/cgi-bin/awstats.pl?config=example.com in browser.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- /c/Python27/lib/CGIHTTPServer.py 2015-11-02 16:20:08.000000000 +0200 | |
+++ CGIHTTPServer.py 2017-02-06 23:05:09.734462300 +0200 | |
@@ -103,6 +103,11 @@ | |
head, tail = os.path.splitext(path) | |
return tail.lower() in (".py", ".pyw") | |
+ def is_perl(self, path): | |
+ """Test whether argument path is a Perl script.""" | |
+ head, tail = os.path.splitext(path) | |
+ return tail.lower() in (".pl") | |
+ | |
def run_cgi(self): | |
"""Execute a CGI script.""" | |
dir, rest = self.cgi_info | |
@@ -139,10 +144,10 @@ | |
self.send_error(403, "CGI script is not a plain file (%r)" % | |
scriptname) | |
return | |
- ispy = self.is_python(scriptname) | |
- if not ispy: | |
+ isscript = self.is_python(scriptname) or self.is_perl(scriptname) | |
+ if not isscript: | |
if not (self.have_fork or self.have_popen2 or self.have_popen3): | |
- self.send_error(403, "CGI script is not a Python script (%r)" % | |
+ self.send_error(403, "CGI script is not a Python or Perl script (%r)" % | |
scriptname) | |
return | |
if not self.is_executable(scriptfile): | |
@@ -260,6 +265,8 @@ | |
# On Windows, use python.exe, not pythonw.exe | |
interp = interp[:-5] + interp[-4:] | |
cmdline = [interp, '-u'] + cmdline | |
+ if self.is_perl(scriptfile): | |
+ cmdline = ['perl'] + cmdline | |
if '=' not in query: | |
cmdline.append(query) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment