#!/usr/bin/python # Software written by Juhani Haverinen (nortti). Influenced in idea and # some implementation details by https://github.com/puckipedia/pyGopher/ # ----------------------------------------------------------------------- # This is free and unencumbered software released into the public domain. # # Anyone is free to copy, modify, publish, use, compile, sell, or # distribute this software, either in source code form or as a compiled # binary, for any purpose, commercial or non-commercial, and by any # means. # # In jurisdictions that recognize copyright laws, the author or authors # of this software dedicate any and all copyright interest in the # software to the public domain. We make this dedication for the benefit # of the public at large and to the detriment of our heirs and # successors. We intend this dedication to be an overt act of # relinquishment in perpetuity of all present and future rights to this # software under copyright law. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. # ----------------------------------------------------------------------- # NOTE: Requires python 2 import os import socket import stat import subprocess import threading import time # Config port = 7777 gopherroot = os.environ['HOME']+'/gopher' blacklistfile = os.environ['HOME']+'/gopher_blacklist_1' # Set up socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) #DEBG sock.bind(('', port)) sock.listen(1) # Helper functions def exist(path): return os.access(path, os.F_OK) def isdir(path): st = os.stat(path) return stat.S_ISDIR(st.st_mode) def isexecutable(path): return os.access(path, os.X_OK) def normalizepath(path): path = path.split('/') while '' in path: path.remove('') while '..' in path: i = path.index('..') if i == 0: return None # Attempted to access something outside gopherroot path = path[:i-1] + path[i+1:] return '/'.join(path) # Error handling def error(conn, ishttp, text, code): sendheader(conn, ishttp, '1', code) if ishttp: conn.sendall('\n' '\t
\n' '\t\t%s
\n' '\t\n' '