Commit 50f9a519 authored by Amos Latteier's avatar Amos Latteier

Added informational logging to Medusa! No longer does medusa report problems and information

with print statements. This is accomplished by adding a log_info method to asyncore.dispatcher.
I've sent the patches to Sam, and he indicates that he will accept them.
parent 5177144c
# -*- Mode: Python; tab-width: 4 -*- # -*- Mode: Python; tab-width: 4 -*-
# $Id: asyncore.py,v 1.4 1999/05/27 21:57:23 amos Exp $ # $Id: asyncore.py,v 1.5 1999/07/20 16:53:49 amos Exp $
# Author: Sam Rushing <rushing@nightmare.com> # Author: Sam Rushing <rushing@nightmare.com>
# ====================================================================== # ======================================================================
...@@ -143,14 +143,12 @@ class dispatcher: ...@@ -143,14 +143,12 @@ class dispatcher:
return '<__repr__ (self) failed for object at %x (addr=%s)>' % (id(self),ar) return '<__repr__ (self) failed for object at %x (addr=%s)>' % (id(self),ar)
def add_channel (self): def add_channel (self):
if __debug__: self.log_info ('adding channel %s' % self)
self.log ('adding channel %s' % self)
socket_map [self] = 1 socket_map [self] = 1
def del_channel (self): def del_channel (self):
if socket_map.has_key (self): if socket_map.has_key (self):
if __debug__: self.log_info ('closing channel %d:%s' % (self.fileno(), self))
self.log ('closing channel %d:%s' % (self.fileno(), self))
del socket_map [self] del socket_map [self]
def create_socket (self, family, type): def create_socket (self, family, type):
...@@ -267,9 +265,17 @@ class dispatcher: ...@@ -267,9 +265,17 @@ class dispatcher:
def __getattr__ (self, attr): def __getattr__ (self, attr):
return getattr (self.socket, attr) return getattr (self.socket, attr)
# log and log_info maybe overriden to provide more sophisitcated
# logging and warning methods. In general, log is for 'hit' logging
# and 'log_info' is for informational, warning and error logging.
def log (self, message): def log (self, message):
print 'log:', message print 'log:', message
def log_info (self, message, type='info'):
if __debug__ or type != 'info':
print '%s: %s' %(type, message)
def handle_read_event (self): def handle_read_event (self):
if self.accepting: if self.accepting:
# for an accepting socket, getting a read implies # for an accepting socket, getting a read implies
...@@ -303,39 +309,34 @@ class dispatcher: ...@@ -303,39 +309,34 @@ class dispatcher:
except: except:
self_repr = '<__repr__ (self) failed for object at %0x>' % id(self) self_repr = '<__repr__ (self) failed for object at %0x>' % id(self)
print ( self.log_info (
'uncaptured python exception, closing channel %s (%s:%s %s)' % ( 'uncaptured python exception, closing channel %s (%s:%s %s)' % (
self_repr, self_repr,
t, t,
v, v,
tbinfo tbinfo
) ),
'error'
) )
self.close() self.close()
def handle_expt (self): def handle_expt (self):
if __debug__: self.log_info ('unhandled exception', 'warning')
self.log ('unhandled exception')
def handle_read (self): def handle_read (self):
if __debug__: self.log_info ('unhandled read event', 'waring')
self.log ('unhandled read event')
def handle_write (self): def handle_write (self):
if __debug__: self.log_info ('unhandled write event', 'warning')
self.log ('unhandled write event')
def handle_connect (self): def handle_connect (self):
if __debug__: self.log_info ('unhandled connect event', 'warning')
self.log ('unhandled connect event')
def handle_accept (self): def handle_accept (self):
if __debug__: self.log_info ('unhandled accept event', 'warning')
self.log ('unhandled accept event')
def handle_close (self): def handle_close (self):
if __debug__: self.log_info ('unhandled close event', 'warning')
self.log ('unhandled close event')
self.close() self.close()
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
...@@ -361,7 +362,7 @@ class dispatcher_with_send (dispatcher): ...@@ -361,7 +362,7 @@ class dispatcher_with_send (dispatcher):
def send (self, data): def send (self, data):
if self.debug: if self.debug:
self.log ('sending %s' % repr(data)) self.log_info ('sending %s' % repr(data))
self.out_buffer = self.out_buffer + data self.out_buffer = self.out_buffer + data
self.initiate_send() self.initiate_send()
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
# If you are interested in using this software in a commercial context, # If you are interested in using this software in a commercial context,
# or in purchasing support, please contact the author. # or in purchasing support, please contact the author.
RCS_ID = '$Id: ftp_server.py,v 1.5 1999/05/26 02:08:30 amos Exp $' RCS_ID = '$Id: ftp_server.py,v 1.6 1999/07/20 16:53:49 amos Exp $'
# An extensible, configurable, asynchronous FTP server. # An extensible, configurable, asynchronous FTP server.
# #
...@@ -481,7 +481,7 @@ class ftp_channel (asynchat.async_chat): ...@@ -481,7 +481,7 @@ class ftp_channel (asynchat.async_chat):
else: else:
file = line[1] file = line[1]
if not self.filesystem.isfile (file): if not self.filesystem.isfile (file):
print 'checking %s' % file self.log_info ('checking %s' % file)
self.respond ('550 No such file') self.respond ('550 No such file')
else: else:
try: try:
...@@ -603,7 +603,7 @@ class ftp_channel (asynchat.async_chat): ...@@ -603,7 +603,7 @@ class ftp_channel (asynchat.async_chat):
self.respond ('230 %s' % message) self.respond ('230 %s' % message)
self.filesystem = fs self.filesystem = fs
self.authorized = 1 self.authorized = 1
self.log ('Successful login: Filesystem=%s' % repr(fs)) self.log_info('Successful login: Filesystem=%s' % repr(fs))
else: else:
self.respond ('530 %s' % message) self.respond ('530 %s' % message)
...@@ -732,11 +732,11 @@ class ftp_server (asyncore.dispatcher): ...@@ -732,11 +732,11 @@ class ftp_server (asyncore.dispatcher):
else: else:
self.logger = logger.unresolving_logger (logger_object) self.logger = logger.unresolving_logger (logger_object)
print 'FTP server started at %s\n\tAuthorizer:%s\n\tHostname: %s\n\tPort: %d' % ( self.log_info('FTP server started at %s\n\tAuthorizer:%s\n\tHostname: %s\n\tPort: %d' % (
time.ctime(time.time()), time.ctime(time.time()),
repr (self.authorizer), repr (self.authorizer),
self.hostname, self.hostname,
self.port self.port)
) )
def writable (self): def writable (self):
...@@ -751,7 +751,7 @@ class ftp_server (asyncore.dispatcher): ...@@ -751,7 +751,7 @@ class ftp_server (asyncore.dispatcher):
def handle_accept (self): def handle_accept (self):
conn, addr = self.accept() conn, addr = self.accept()
self.total_sessions.increment() self.total_sessions.increment()
print 'Incoming connection from %s:%d' % (addr[0], addr[1]) self.log_info('Incoming connection from %s:%d' % (addr[0], addr[1]))
self.ftp_channel_class (self, conn, addr) self.ftp_channel_class (self, conn, addr)
# return a producer describing the state of the server # return a producer describing the state of the server
...@@ -873,7 +873,7 @@ class xmit_channel (asynchat.async_chat): ...@@ -873,7 +873,7 @@ class xmit_channel (asynchat.async_chat):
def handle_error (self): def handle_error (self):
# usually this is to catch an unexpected disconnect. # usually this is to catch an unexpected disconnect.
self.log ('unexpected disconnect on data xmit channel') self.log_info ('unexpected disconnect on data xmit channel', 'error')
try: try:
self.close() self.close()
except: except:
...@@ -929,7 +929,7 @@ class recv_channel (asyncore.dispatcher): ...@@ -929,7 +929,7 @@ class recv_channel (asyncore.dispatcher):
try: try:
self.fd.write (block) self.fd.write (block)
except IOError: except IOError:
print 'got exception writing block...' self.log_info ('got exception writing block...', 'error')
def handle_close (self): def handle_close (self):
s = self.channel.server s = self.channel.server
...@@ -1060,7 +1060,7 @@ if os.name == 'posix': ...@@ -1060,7 +1060,7 @@ if os.name == 'posix':
try: try:
asyncore.loop() asyncore.loop()
except KeyboardInterrupt: except KeyboardInterrupt:
print 'FTP server shutting down. (received SIGINT)' self.log_info('FTP server shutting down. (received SIGINT)', 'warning')
# close everything down on SIGINT. # close everything down on SIGINT.
# of course this should be a cleaner shutdown. # of course this should be a cleaner shutdown.
sm = socket.socket_map sm = socket.socket_map
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
# interested in using this software in a commercial context, or in # interested in using this software in a commercial context, or in
# purchasing support, please contact the author. # purchasing support, please contact the author.
RCS_ID = '$Id: http_server.py,v 1.7 1999/05/26 02:08:30 amos Exp $' RCS_ID = '$Id: http_server.py,v 1.8 1999/07/20 16:53:49 amos Exp $'
# python modules # python modules
import os import os
...@@ -142,16 +142,18 @@ class http_request: ...@@ -142,16 +142,18 @@ class http_request:
if self.collector: if self.collector:
self.collector.collect_incoming_data (data) self.collector.collect_incoming_data (data)
else: else:
sys.stderr.write ( self.log_info(
'warning: dropping %d bytes of incoming request data\n' % len(data) 'Dropping %d bytes of incoming request data' % len(data),
'warning'
) )
def found_terminator (self): def found_terminator (self):
if self.collector: if self.collector:
self.collector.found_terminator() self.collector.found_terminator()
else: else:
sys.stderr.write ( self.log_info (
'warning: unexpected end-of-record for incoming request\n' 'Unexpected end-of-record for incoming request',
'warning'
) )
def push (self, thing): def push (self, thing):
...@@ -461,8 +463,9 @@ class http_channel (asynchat.async_chat): ...@@ -461,8 +463,9 @@ class http_channel (asynchat.async_chat):
except: except:
self.server.exceptions.increment() self.server.exceptions.increment()
(file, fun, line), t, v, tbinfo = asyncore.compact_traceback() (file, fun, line), t, v, tbinfo = asyncore.compact_traceback()
# Log this to a better place. self.log_info(
print 'Server Error: %s, %s: file: %s line: %s' % (t,v,file,line) 'Server Error: %s, %s: file: %s line: %s' % (t,v,file,line),
'error')
try: try:
r.error (500) r.error (500)
except: except:
...@@ -521,12 +524,12 @@ class http_server (asyncore.dispatcher): ...@@ -521,12 +524,12 @@ class http_server (asyncore.dispatcher):
host, port = self.socket.getsockname() host, port = self.socket.getsockname()
if not ip: if not ip:
print 'Warning: computing default hostname' self.log_info('Computing default hostname', 'warning')
ip = socket.gethostbyname (socket.gethostname()) ip = socket.gethostbyname (socket.gethostname())
try: try:
self.server_name = socket.gethostbyaddr (ip)[0] self.server_name = socket.gethostbyaddr (ip)[0]
except socket.error: except socket.error:
print 'Warning: cannot do reverse lookup' self.log_info('Cannot do reverse lookup', 'warning')
self.server_name = ip # use the IP address as the "hostname" self.server_name = ip # use the IP address as the "hostname"
self.server_port = port self.server_port = port
...@@ -544,7 +547,7 @@ class http_server (asyncore.dispatcher): ...@@ -544,7 +547,7 @@ class http_server (asyncore.dispatcher):
else: else:
self.logger = logger.unresolving_logger (logger_object) self.logger = logger.unresolving_logger (logger_object)
sys.stdout.write ( self.log_info (
'Medusa (V%s) started at %s' 'Medusa (V%s) started at %s'
'\n\tHostname: %s' '\n\tHostname: %s'
'\n\tPort:%d' '\n\tPort:%d'
...@@ -577,7 +580,7 @@ class http_server (asyncore.dispatcher): ...@@ -577,7 +580,7 @@ class http_server (asyncore.dispatcher):
# accept. socketmodule.c:makesockaddr complains that the # accept. socketmodule.c:makesockaddr complains that the
# address family is unknown. We don't want the whole server # address family is unknown. We don't want the whole server
# to shut down because of this. # to shut down because of this.
sys.stderr.write ('warning: server accept() threw an exception\n') self.log_info('Server accept() threw an exception', 'warning')
return return
self.channel_class (self, conn, addr) self.channel_class (self, conn, addr)
......
...@@ -19,7 +19,7 @@ def max_server_sockets(): ...@@ -19,7 +19,7 @@ def max_server_sockets():
sl.append (s) sl.append (s)
except: except:
break break
num = len(sl) - 1 num = len(sl)
for s in sl: for s in sl:
s.close() s.close()
del sl del sl
...@@ -39,7 +39,7 @@ def max_client_sockets(): ...@@ -39,7 +39,7 @@ def max_client_sockets():
sl.append ((s,conn)) sl.append ((s,conn))
except: except:
break break
num = len(sl) - 1 num = len(sl)
for s,c in sl: for s,c in sl:
s.close() s.close()
c.close() c.close()
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# python REPL channel. # python REPL channel.
# #
RCS_ID = '$Id: monitor.py,v 1.2 1999/05/27 17:25:55 amos Exp $' RCS_ID = '$Id: monitor.py,v 1.3 1999/07/20 16:53:50 amos Exp $'
import md5 import md5
import socket import socket
...@@ -93,7 +93,7 @@ class monitor_channel (asynchat.async_chat): ...@@ -93,7 +93,7 @@ class monitor_channel (asynchat.async_chat):
result = eval (co, self.local_env) result = eval (co, self.local_env)
method = 'eval' method = 'eval'
if result is not None: if result is not None:
print repr(result) self.log_info(repr(result))
self.local_env['_'] = result self.local_env['_'] = result
except SyntaxError: except SyntaxError:
try: try:
...@@ -120,15 +120,15 @@ class monitor_channel (asynchat.async_chat): ...@@ -120,15 +120,15 @@ class monitor_channel (asynchat.async_chat):
method = 'exception' method = 'exception'
self.multi_line = [] self.multi_line = []
(file, fun, line), t, v, tbinfo = asyncore.compact_traceback() (file, fun, line), t, v, tbinfo = asyncore.compact_traceback()
print t, v, tbinfo self.log_info('%s %s %s' %(t, v, tbinfo), 'warning')
finally: finally:
sys.stdout = oldout sys.stdout = oldout
sys.stderr = olderr sys.stderr = olderr
print '%s:%s (%s)> %s' % ( self.log_info('%s:%s (%s)> %s' % (
self.number, self.number,
self.line_counter, self.line_counter,
method, method,
repr(line) repr(line))
) )
self.push_with_producer (p) self.push_with_producer (p)
self.prompt() self.prompt()
...@@ -161,7 +161,7 @@ class monitor_server (asyncore.dispatcher): ...@@ -161,7 +161,7 @@ class monitor_server (asyncore.dispatcher):
self.create_socket (socket.AF_INET, socket.SOCK_STREAM) self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
self.set_reuse_addr() self.set_reuse_addr()
self.bind ((hostname, port)) self.bind ((hostname, port))
print '%s started on port %d' % (self.SERVER_IDENT, port) self.log_info('%s started on port %d' % (self.SERVER_IDENT, port))
self.listen (5) self.listen (5)
self.closed = 0 self.closed = 0
self.failed_auths = 0 self.failed_auths = 0
...@@ -173,7 +173,7 @@ class monitor_server (asyncore.dispatcher): ...@@ -173,7 +173,7 @@ class monitor_server (asyncore.dispatcher):
def handle_accept (self): def handle_accept (self):
conn, addr = self.accept() conn, addr = self.accept()
print 'Incoming monitor connection from %s:%d' % addr self.log_info('Incoming monitor connection from %s:%d' % addr)
self.channel_class (self, conn, addr) self.channel_class (self, conn, addr)
self.total_sessions.increment() self.total_sessions.increment()
...@@ -216,7 +216,7 @@ class secure_monitor_channel (monitor_channel): ...@@ -216,7 +216,7 @@ class secure_monitor_channel (monitor_channel):
def found_terminator (self): def found_terminator (self):
if not self.authorized: if not self.authorized:
if hex_digest ('%s%s' % (self.timestamp, self.server.password)) != self.data: if hex_digest ('%s%s' % (self.timestamp, self.server.password)) != self.data:
self.log ('%s: failed authorization' % self) self.log_info ('%s: failed authorization' % self, 'warning')
self.server.failed_auths = self.server.failed_auths + 1 self.server.failed_auths = self.server.failed_auths + 1
self.close() self.close()
else: else:
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# Author: Sam Rushing <rushing@nightmare.com> # Author: Sam Rushing <rushing@nightmare.com>
# #
RCS_ID = '$Id: resolver.py,v 1.3 1999/05/26 02:08:30 amos Exp $' RCS_ID = '$Id: resolver.py,v 1.4 1999/07/20 16:53:50 amos Exp $'
# Fast, low-overhead asynchronous name resolver. uses 'pre-cooked' # Fast, low-overhead asynchronous name resolver. uses 'pre-cooked'
...@@ -212,12 +212,14 @@ class resolver (asyncore.dispatcher): ...@@ -212,12 +212,14 @@ class resolver (asyncore.dispatcher):
pass pass
def handle_close (self): def handle_close (self):
print 'closing!' self.log_info('closing!')
self.close() self.close()
def handle_error (self): # don't close the connection on error def handle_error (self): # don't close the connection on error
(file,fun,line), t, v, tbinfo = asyncore.compact_traceback() (file,fun,line), t, v, tbinfo = asyncore.compact_traceback()
print 'Problem with DNS lookup (%s:%s %s)' % (t, v, tbinfo) self.log_info(
'Problem with DNS lookup (%s:%s %s)' % (t, v, tbinfo),
'error')
def get_id (self): def get_id (self):
return (self.id.as_long() % (1<<16)) return (self.id.as_long() % (1<<16))
...@@ -233,7 +235,7 @@ class resolver (asyncore.dispatcher): ...@@ -233,7 +235,7 @@ class resolver (asyncore.dispatcher):
callback (host, 0, None) # timeout val is (0,None) callback (host, 0, None) # timeout val is (0,None)
except: except:
(file,fun,line), t, v, tbinfo = asyncore.compact_traceback() (file,fun,line), t, v, tbinfo = asyncore.compact_traceback()
print t,v,tbinfo self.log_info('%s %s %s' % (t,v,tbinfo), 'error')
def resolve (self, host, callback): def resolve (self, host, callback):
self.reap() # first, get rid of old guys self.reap() # first, get rid of old guys
...@@ -271,7 +273,7 @@ class resolver (asyncore.dispatcher): ...@@ -271,7 +273,7 @@ class resolver (asyncore.dispatcher):
callback (host, ttl, answer) callback (host, ttl, answer)
except: except:
(file,fun,line), t, v, tbinfo = asyncore.compact_traceback() (file,fun,line), t, v, tbinfo = asyncore.compact_traceback()
print t,v,tbinfo self.log_info('%s %s %s' % ( t,v,tbinfo), 'error')
class rbl (resolver): class rbl (resolver):
...@@ -289,8 +291,7 @@ class rbl (resolver): ...@@ -289,8 +291,7 @@ class rbl (resolver):
def check_reply (self, r): def check_reply (self, r):
# we only need to check RCODE. # we only need to check RCODE.
rcode = (ord(r[3])&0xf) rcode = (ord(r[3])&0xf)
print 'MAPS RBL; RCODE =%02x' % rcode self.log_info('MAPS RBL; RCODE =%02x\n %s' % (rcode, repr(r)))
print repr(r)
return 0, rcode # (ttl, answer) return 0, rcode # (ttl, answer)
......
# -*- Mode: Python; tab-width: 4 -*- # -*- Mode: Python; tab-width: 4 -*-
VERSION_STRING = "$Id: select_trigger.py,v 1.4 1999/06/15 18:50:16 amos Exp $" VERSION_STRING = "$Id: select_trigger.py,v 1.5 1999/07/20 16:53:50 amos Exp $"
import asyncore import asyncore
import asynchat import asynchat
...@@ -82,7 +82,9 @@ if os.name == 'posix': ...@@ -82,7 +82,9 @@ if os.name == 'posix':
thunk() thunk()
except: except:
(file, fun, line), t, v, tbinfo = asyncore.compact_traceback() (file, fun, line), t, v, tbinfo = asyncore.compact_traceback()
print 'exception in trigger thunk: (%s:%s %s)' % (t, v, tbinfo) self.log_info(
'exception in trigger thunk: (%s:%s %s)' % (t, v, tbinfo),
'error')
self.thunks = [] self.thunks = []
finally: finally:
self.lock.release() self.lock.release()
...@@ -145,7 +147,9 @@ else: ...@@ -145,7 +147,9 @@ else:
thunk() thunk()
except: except:
(file, fun, line), t, v, tbinfo = asyncore.compact_traceback() (file, fun, line), t, v, tbinfo = asyncore.compact_traceback()
print 'exception in trigger thunk: (%s:%s %s)' % (t, v, tbinfo) self.log_info(
'exception in trigger thunk: (%s:%s %s)' % (t, v, tbinfo),
'error')
self.thunks = [] self.thunks = []
finally: finally:
self.lock.release() self.lock.release()
......
# -*- Mode: Python; tab-width: 4 -*- # -*- Mode: Python; tab-width: 4 -*-
# $Id: asyncore.py,v 1.4 1999/05/27 21:57:23 amos Exp $ # $Id: asyncore.py,v 1.5 1999/07/20 16:53:49 amos Exp $
# Author: Sam Rushing <rushing@nightmare.com> # Author: Sam Rushing <rushing@nightmare.com>
# ====================================================================== # ======================================================================
...@@ -143,14 +143,12 @@ class dispatcher: ...@@ -143,14 +143,12 @@ class dispatcher:
return '<__repr__ (self) failed for object at %x (addr=%s)>' % (id(self),ar) return '<__repr__ (self) failed for object at %x (addr=%s)>' % (id(self),ar)
def add_channel (self): def add_channel (self):
if __debug__: self.log_info ('adding channel %s' % self)
self.log ('adding channel %s' % self)
socket_map [self] = 1 socket_map [self] = 1
def del_channel (self): def del_channel (self):
if socket_map.has_key (self): if socket_map.has_key (self):
if __debug__: self.log_info ('closing channel %d:%s' % (self.fileno(), self))
self.log ('closing channel %d:%s' % (self.fileno(), self))
del socket_map [self] del socket_map [self]
def create_socket (self, family, type): def create_socket (self, family, type):
...@@ -267,9 +265,17 @@ class dispatcher: ...@@ -267,9 +265,17 @@ class dispatcher:
def __getattr__ (self, attr): def __getattr__ (self, attr):
return getattr (self.socket, attr) return getattr (self.socket, attr)
# log and log_info maybe overriden to provide more sophisitcated
# logging and warning methods. In general, log is for 'hit' logging
# and 'log_info' is for informational, warning and error logging.
def log (self, message): def log (self, message):
print 'log:', message print 'log:', message
def log_info (self, message, type='info'):
if __debug__ or type != 'info':
print '%s: %s' %(type, message)
def handle_read_event (self): def handle_read_event (self):
if self.accepting: if self.accepting:
# for an accepting socket, getting a read implies # for an accepting socket, getting a read implies
...@@ -303,39 +309,34 @@ class dispatcher: ...@@ -303,39 +309,34 @@ class dispatcher:
except: except:
self_repr = '<__repr__ (self) failed for object at %0x>' % id(self) self_repr = '<__repr__ (self) failed for object at %0x>' % id(self)
print ( self.log_info (
'uncaptured python exception, closing channel %s (%s:%s %s)' % ( 'uncaptured python exception, closing channel %s (%s:%s %s)' % (
self_repr, self_repr,
t, t,
v, v,
tbinfo tbinfo
) ),
'error'
) )
self.close() self.close()
def handle_expt (self): def handle_expt (self):
if __debug__: self.log_info ('unhandled exception', 'warning')
self.log ('unhandled exception')
def handle_read (self): def handle_read (self):
if __debug__: self.log_info ('unhandled read event', 'waring')
self.log ('unhandled read event')
def handle_write (self): def handle_write (self):
if __debug__: self.log_info ('unhandled write event', 'warning')
self.log ('unhandled write event')
def handle_connect (self): def handle_connect (self):
if __debug__: self.log_info ('unhandled connect event', 'warning')
self.log ('unhandled connect event')
def handle_accept (self): def handle_accept (self):
if __debug__: self.log_info ('unhandled accept event', 'warning')
self.log ('unhandled accept event')
def handle_close (self): def handle_close (self):
if __debug__: self.log_info ('unhandled close event', 'warning')
self.log ('unhandled close event')
self.close() self.close()
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
...@@ -361,7 +362,7 @@ class dispatcher_with_send (dispatcher): ...@@ -361,7 +362,7 @@ class dispatcher_with_send (dispatcher):
def send (self, data): def send (self, data):
if self.debug: if self.debug:
self.log ('sending %s' % repr(data)) self.log_info ('sending %s' % repr(data))
self.out_buffer = self.out_buffer + data self.out_buffer = self.out_buffer + data
self.initiate_send() self.initiate_send()
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
# If you are interested in using this software in a commercial context, # If you are interested in using this software in a commercial context,
# or in purchasing support, please contact the author. # or in purchasing support, please contact the author.
RCS_ID = '$Id: ftp_server.py,v 1.5 1999/05/26 02:08:30 amos Exp $' RCS_ID = '$Id: ftp_server.py,v 1.6 1999/07/20 16:53:49 amos Exp $'
# An extensible, configurable, asynchronous FTP server. # An extensible, configurable, asynchronous FTP server.
# #
...@@ -481,7 +481,7 @@ class ftp_channel (asynchat.async_chat): ...@@ -481,7 +481,7 @@ class ftp_channel (asynchat.async_chat):
else: else:
file = line[1] file = line[1]
if not self.filesystem.isfile (file): if not self.filesystem.isfile (file):
print 'checking %s' % file self.log_info ('checking %s' % file)
self.respond ('550 No such file') self.respond ('550 No such file')
else: else:
try: try:
...@@ -603,7 +603,7 @@ class ftp_channel (asynchat.async_chat): ...@@ -603,7 +603,7 @@ class ftp_channel (asynchat.async_chat):
self.respond ('230 %s' % message) self.respond ('230 %s' % message)
self.filesystem = fs self.filesystem = fs
self.authorized = 1 self.authorized = 1
self.log ('Successful login: Filesystem=%s' % repr(fs)) self.log_info('Successful login: Filesystem=%s' % repr(fs))
else: else:
self.respond ('530 %s' % message) self.respond ('530 %s' % message)
...@@ -732,11 +732,11 @@ class ftp_server (asyncore.dispatcher): ...@@ -732,11 +732,11 @@ class ftp_server (asyncore.dispatcher):
else: else:
self.logger = logger.unresolving_logger (logger_object) self.logger = logger.unresolving_logger (logger_object)
print 'FTP server started at %s\n\tAuthorizer:%s\n\tHostname: %s\n\tPort: %d' % ( self.log_info('FTP server started at %s\n\tAuthorizer:%s\n\tHostname: %s\n\tPort: %d' % (
time.ctime(time.time()), time.ctime(time.time()),
repr (self.authorizer), repr (self.authorizer),
self.hostname, self.hostname,
self.port self.port)
) )
def writable (self): def writable (self):
...@@ -751,7 +751,7 @@ class ftp_server (asyncore.dispatcher): ...@@ -751,7 +751,7 @@ class ftp_server (asyncore.dispatcher):
def handle_accept (self): def handle_accept (self):
conn, addr = self.accept() conn, addr = self.accept()
self.total_sessions.increment() self.total_sessions.increment()
print 'Incoming connection from %s:%d' % (addr[0], addr[1]) self.log_info('Incoming connection from %s:%d' % (addr[0], addr[1]))
self.ftp_channel_class (self, conn, addr) self.ftp_channel_class (self, conn, addr)
# return a producer describing the state of the server # return a producer describing the state of the server
...@@ -873,7 +873,7 @@ class xmit_channel (asynchat.async_chat): ...@@ -873,7 +873,7 @@ class xmit_channel (asynchat.async_chat):
def handle_error (self): def handle_error (self):
# usually this is to catch an unexpected disconnect. # usually this is to catch an unexpected disconnect.
self.log ('unexpected disconnect on data xmit channel') self.log_info ('unexpected disconnect on data xmit channel', 'error')
try: try:
self.close() self.close()
except: except:
...@@ -929,7 +929,7 @@ class recv_channel (asyncore.dispatcher): ...@@ -929,7 +929,7 @@ class recv_channel (asyncore.dispatcher):
try: try:
self.fd.write (block) self.fd.write (block)
except IOError: except IOError:
print 'got exception writing block...' self.log_info ('got exception writing block...', 'error')
def handle_close (self): def handle_close (self):
s = self.channel.server s = self.channel.server
...@@ -1060,7 +1060,7 @@ if os.name == 'posix': ...@@ -1060,7 +1060,7 @@ if os.name == 'posix':
try: try:
asyncore.loop() asyncore.loop()
except KeyboardInterrupt: except KeyboardInterrupt:
print 'FTP server shutting down. (received SIGINT)' self.log_info('FTP server shutting down. (received SIGINT)', 'warning')
# close everything down on SIGINT. # close everything down on SIGINT.
# of course this should be a cleaner shutdown. # of course this should be a cleaner shutdown.
sm = socket.socket_map sm = socket.socket_map
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
# interested in using this software in a commercial context, or in # interested in using this software in a commercial context, or in
# purchasing support, please contact the author. # purchasing support, please contact the author.
RCS_ID = '$Id: http_server.py,v 1.7 1999/05/26 02:08:30 amos Exp $' RCS_ID = '$Id: http_server.py,v 1.8 1999/07/20 16:53:49 amos Exp $'
# python modules # python modules
import os import os
...@@ -142,16 +142,18 @@ class http_request: ...@@ -142,16 +142,18 @@ class http_request:
if self.collector: if self.collector:
self.collector.collect_incoming_data (data) self.collector.collect_incoming_data (data)
else: else:
sys.stderr.write ( self.log_info(
'warning: dropping %d bytes of incoming request data\n' % len(data) 'Dropping %d bytes of incoming request data' % len(data),
'warning'
) )
def found_terminator (self): def found_terminator (self):
if self.collector: if self.collector:
self.collector.found_terminator() self.collector.found_terminator()
else: else:
sys.stderr.write ( self.log_info (
'warning: unexpected end-of-record for incoming request\n' 'Unexpected end-of-record for incoming request',
'warning'
) )
def push (self, thing): def push (self, thing):
...@@ -461,8 +463,9 @@ class http_channel (asynchat.async_chat): ...@@ -461,8 +463,9 @@ class http_channel (asynchat.async_chat):
except: except:
self.server.exceptions.increment() self.server.exceptions.increment()
(file, fun, line), t, v, tbinfo = asyncore.compact_traceback() (file, fun, line), t, v, tbinfo = asyncore.compact_traceback()
# Log this to a better place. self.log_info(
print 'Server Error: %s, %s: file: %s line: %s' % (t,v,file,line) 'Server Error: %s, %s: file: %s line: %s' % (t,v,file,line),
'error')
try: try:
r.error (500) r.error (500)
except: except:
...@@ -521,12 +524,12 @@ class http_server (asyncore.dispatcher): ...@@ -521,12 +524,12 @@ class http_server (asyncore.dispatcher):
host, port = self.socket.getsockname() host, port = self.socket.getsockname()
if not ip: if not ip:
print 'Warning: computing default hostname' self.log_info('Computing default hostname', 'warning')
ip = socket.gethostbyname (socket.gethostname()) ip = socket.gethostbyname (socket.gethostname())
try: try:
self.server_name = socket.gethostbyaddr (ip)[0] self.server_name = socket.gethostbyaddr (ip)[0]
except socket.error: except socket.error:
print 'Warning: cannot do reverse lookup' self.log_info('Cannot do reverse lookup', 'warning')
self.server_name = ip # use the IP address as the "hostname" self.server_name = ip # use the IP address as the "hostname"
self.server_port = port self.server_port = port
...@@ -544,7 +547,7 @@ class http_server (asyncore.dispatcher): ...@@ -544,7 +547,7 @@ class http_server (asyncore.dispatcher):
else: else:
self.logger = logger.unresolving_logger (logger_object) self.logger = logger.unresolving_logger (logger_object)
sys.stdout.write ( self.log_info (
'Medusa (V%s) started at %s' 'Medusa (V%s) started at %s'
'\n\tHostname: %s' '\n\tHostname: %s'
'\n\tPort:%d' '\n\tPort:%d'
...@@ -577,7 +580,7 @@ class http_server (asyncore.dispatcher): ...@@ -577,7 +580,7 @@ class http_server (asyncore.dispatcher):
# accept. socketmodule.c:makesockaddr complains that the # accept. socketmodule.c:makesockaddr complains that the
# address family is unknown. We don't want the whole server # address family is unknown. We don't want the whole server
# to shut down because of this. # to shut down because of this.
sys.stderr.write ('warning: server accept() threw an exception\n') self.log_info('Server accept() threw an exception', 'warning')
return return
self.channel_class (self, conn, addr) self.channel_class (self, conn, addr)
......
...@@ -19,7 +19,7 @@ def max_server_sockets(): ...@@ -19,7 +19,7 @@ def max_server_sockets():
sl.append (s) sl.append (s)
except: except:
break break
num = len(sl) - 1 num = len(sl)
for s in sl: for s in sl:
s.close() s.close()
del sl del sl
...@@ -39,7 +39,7 @@ def max_client_sockets(): ...@@ -39,7 +39,7 @@ def max_client_sockets():
sl.append ((s,conn)) sl.append ((s,conn))
except: except:
break break
num = len(sl) - 1 num = len(sl)
for s,c in sl: for s,c in sl:
s.close() s.close()
c.close() c.close()
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# python REPL channel. # python REPL channel.
# #
RCS_ID = '$Id: monitor.py,v 1.2 1999/05/27 17:25:55 amos Exp $' RCS_ID = '$Id: monitor.py,v 1.3 1999/07/20 16:53:50 amos Exp $'
import md5 import md5
import socket import socket
...@@ -93,7 +93,7 @@ class monitor_channel (asynchat.async_chat): ...@@ -93,7 +93,7 @@ class monitor_channel (asynchat.async_chat):
result = eval (co, self.local_env) result = eval (co, self.local_env)
method = 'eval' method = 'eval'
if result is not None: if result is not None:
print repr(result) self.log_info(repr(result))
self.local_env['_'] = result self.local_env['_'] = result
except SyntaxError: except SyntaxError:
try: try:
...@@ -120,15 +120,15 @@ class monitor_channel (asynchat.async_chat): ...@@ -120,15 +120,15 @@ class monitor_channel (asynchat.async_chat):
method = 'exception' method = 'exception'
self.multi_line = [] self.multi_line = []
(file, fun, line), t, v, tbinfo = asyncore.compact_traceback() (file, fun, line), t, v, tbinfo = asyncore.compact_traceback()
print t, v, tbinfo self.log_info('%s %s %s' %(t, v, tbinfo), 'warning')
finally: finally:
sys.stdout = oldout sys.stdout = oldout
sys.stderr = olderr sys.stderr = olderr
print '%s:%s (%s)> %s' % ( self.log_info('%s:%s (%s)> %s' % (
self.number, self.number,
self.line_counter, self.line_counter,
method, method,
repr(line) repr(line))
) )
self.push_with_producer (p) self.push_with_producer (p)
self.prompt() self.prompt()
...@@ -161,7 +161,7 @@ class monitor_server (asyncore.dispatcher): ...@@ -161,7 +161,7 @@ class monitor_server (asyncore.dispatcher):
self.create_socket (socket.AF_INET, socket.SOCK_STREAM) self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
self.set_reuse_addr() self.set_reuse_addr()
self.bind ((hostname, port)) self.bind ((hostname, port))
print '%s started on port %d' % (self.SERVER_IDENT, port) self.log_info('%s started on port %d' % (self.SERVER_IDENT, port))
self.listen (5) self.listen (5)
self.closed = 0 self.closed = 0
self.failed_auths = 0 self.failed_auths = 0
...@@ -173,7 +173,7 @@ class monitor_server (asyncore.dispatcher): ...@@ -173,7 +173,7 @@ class monitor_server (asyncore.dispatcher):
def handle_accept (self): def handle_accept (self):
conn, addr = self.accept() conn, addr = self.accept()
print 'Incoming monitor connection from %s:%d' % addr self.log_info('Incoming monitor connection from %s:%d' % addr)
self.channel_class (self, conn, addr) self.channel_class (self, conn, addr)
self.total_sessions.increment() self.total_sessions.increment()
...@@ -216,7 +216,7 @@ class secure_monitor_channel (monitor_channel): ...@@ -216,7 +216,7 @@ class secure_monitor_channel (monitor_channel):
def found_terminator (self): def found_terminator (self):
if not self.authorized: if not self.authorized:
if hex_digest ('%s%s' % (self.timestamp, self.server.password)) != self.data: if hex_digest ('%s%s' % (self.timestamp, self.server.password)) != self.data:
self.log ('%s: failed authorization' % self) self.log_info ('%s: failed authorization' % self, 'warning')
self.server.failed_auths = self.server.failed_auths + 1 self.server.failed_auths = self.server.failed_auths + 1
self.close() self.close()
else: else:
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# Author: Sam Rushing <rushing@nightmare.com> # Author: Sam Rushing <rushing@nightmare.com>
# #
RCS_ID = '$Id: resolver.py,v 1.3 1999/05/26 02:08:30 amos Exp $' RCS_ID = '$Id: resolver.py,v 1.4 1999/07/20 16:53:50 amos Exp $'
# Fast, low-overhead asynchronous name resolver. uses 'pre-cooked' # Fast, low-overhead asynchronous name resolver. uses 'pre-cooked'
...@@ -212,12 +212,14 @@ class resolver (asyncore.dispatcher): ...@@ -212,12 +212,14 @@ class resolver (asyncore.dispatcher):
pass pass
def handle_close (self): def handle_close (self):
print 'closing!' self.log_info('closing!')
self.close() self.close()
def handle_error (self): # don't close the connection on error def handle_error (self): # don't close the connection on error
(file,fun,line), t, v, tbinfo = asyncore.compact_traceback() (file,fun,line), t, v, tbinfo = asyncore.compact_traceback()
print 'Problem with DNS lookup (%s:%s %s)' % (t, v, tbinfo) self.log_info(
'Problem with DNS lookup (%s:%s %s)' % (t, v, tbinfo),
'error')
def get_id (self): def get_id (self):
return (self.id.as_long() % (1<<16)) return (self.id.as_long() % (1<<16))
...@@ -233,7 +235,7 @@ class resolver (asyncore.dispatcher): ...@@ -233,7 +235,7 @@ class resolver (asyncore.dispatcher):
callback (host, 0, None) # timeout val is (0,None) callback (host, 0, None) # timeout val is (0,None)
except: except:
(file,fun,line), t, v, tbinfo = asyncore.compact_traceback() (file,fun,line), t, v, tbinfo = asyncore.compact_traceback()
print t,v,tbinfo self.log_info('%s %s %s' % (t,v,tbinfo), 'error')
def resolve (self, host, callback): def resolve (self, host, callback):
self.reap() # first, get rid of old guys self.reap() # first, get rid of old guys
...@@ -271,7 +273,7 @@ class resolver (asyncore.dispatcher): ...@@ -271,7 +273,7 @@ class resolver (asyncore.dispatcher):
callback (host, ttl, answer) callback (host, ttl, answer)
except: except:
(file,fun,line), t, v, tbinfo = asyncore.compact_traceback() (file,fun,line), t, v, tbinfo = asyncore.compact_traceback()
print t,v,tbinfo self.log_info('%s %s %s' % ( t,v,tbinfo), 'error')
class rbl (resolver): class rbl (resolver):
...@@ -289,8 +291,7 @@ class rbl (resolver): ...@@ -289,8 +291,7 @@ class rbl (resolver):
def check_reply (self, r): def check_reply (self, r):
# we only need to check RCODE. # we only need to check RCODE.
rcode = (ord(r[3])&0xf) rcode = (ord(r[3])&0xf)
print 'MAPS RBL; RCODE =%02x' % rcode self.log_info('MAPS RBL; RCODE =%02x\n %s' % (rcode, repr(r)))
print repr(r)
return 0, rcode # (ttl, answer) return 0, rcode # (ttl, answer)
......
# -*- Mode: Python; tab-width: 4 -*- # -*- Mode: Python; tab-width: 4 -*-
VERSION_STRING = "$Id: select_trigger.py,v 1.4 1999/06/15 18:50:16 amos Exp $" VERSION_STRING = "$Id: select_trigger.py,v 1.5 1999/07/20 16:53:50 amos Exp $"
import asyncore import asyncore
import asynchat import asynchat
...@@ -82,7 +82,9 @@ if os.name == 'posix': ...@@ -82,7 +82,9 @@ if os.name == 'posix':
thunk() thunk()
except: except:
(file, fun, line), t, v, tbinfo = asyncore.compact_traceback() (file, fun, line), t, v, tbinfo = asyncore.compact_traceback()
print 'exception in trigger thunk: (%s:%s %s)' % (t, v, tbinfo) self.log_info(
'exception in trigger thunk: (%s:%s %s)' % (t, v, tbinfo),
'error')
self.thunks = [] self.thunks = []
finally: finally:
self.lock.release() self.lock.release()
...@@ -145,7 +147,9 @@ else: ...@@ -145,7 +147,9 @@ else:
thunk() thunk()
except: except:
(file, fun, line), t, v, tbinfo = asyncore.compact_traceback() (file, fun, line), t, v, tbinfo = asyncore.compact_traceback()
print 'exception in trigger thunk: (%s:%s %s)' % (t, v, tbinfo) self.log_info(
'exception in trigger thunk: (%s:%s %s)' % (t, v, tbinfo),
'error')
self.thunks = [] self.thunks = []
finally: finally:
self.lock.release() self.lock.release()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment