Twisted Perspective Broker: get client ip

2011-09-14 Thread Andrea Di Mario
Hi, i'm writing a perspective broker server. Now, i should get the
client IP, that perspective broker writes well in the log. I've tried
to get it from MyRealm with: mind.broker.transport.getPeer(), without
success. I've tried self.transport.getPeer() to, with this result:
exceptions.AttributeError: Listner instance has no attribute 'transport'
It's strange, because PB wrote the client IP, infact in log i've line with:
2011-09-11 16:41:58+0200 [Broker,0,127.0.0.1] 

Could you suggest me something?
Thanks.
Here the code:

from OpenSSL import SSL
from twisted.internet import reactor, ssl
from ConfigParser import SafeConfigParser
from twisted.python import log
from twisted.spread import pb
from twisted.cred import checkers, portal
from zope.interface import implements
import hashlib

class Listner(pb.Avatar):

   def __init__(self, name):
   self.name = name

   def perspective_getDictionary(self, dictionary):
  print dictionary

   def perspective_simplyAccess(self, access):
  print access

def verifyCallback(connection, x509,  errnum, errdepth, ok):
   if not ok:
  log.msg("Certificato non valido: %s" % x509.get_subject())
  return False
   else:
  log.msg("Connessione stabilita, vertificato valido: %s" %
x509.get_subject())
   return True


class MyRealm:
implements(portal.IRealm)
def requestAvatar(self, avatarId, mind, *interfaces):
if pb.IPerspective not in interfaces:
raise NotImplementedError
return pb.IPerspective, Listner(avatarId), lambda:None


if __name__ == "__main__":

   CONFIGURATION = SafeConfigParser()
   CONFIGURATION.read('server.conf')
   PORT = CONFIGURATION.get('general', 'port')
   LOGFILE = CONFIGURATION.get('general', 'log')

log.startLogging(open(LOGFILE,'a'))


   myContextFactory =
ssl.DefaultOpenSSLContextFactory(CONFIGURATION.get('general',
'keypath'), CONFIGURATION.get('general', 'certpath'))
   ctx = myContextFactory.getContext()
   ctx.set_verify(SSL.VERIFY_PEER |
SSL.VERIFY_FAIL_IF_NO_PEER_CERT, verifyCallback)

   ctx.load_verify_locations(CONFIGURATION.get('general', 'cacert'))

   p = portal.Portal(MyRealm())
   c = checkers.FilePasswordDB('passwords.txt',
caseSensitive=True, cache=True)
   p.registerChecker(c)
   factory = pb.PBServerFactory(p)
   reactor.listenSSL(int(PORT), factory, myContextFactory)
   reactor.run()

-- 
Andrea Di Mario
-- 
http://mail.python.org/mailman/listinfo/python-list


Notifications when process is killed

2011-08-02 Thread Andrea Di Mario
> You won't be able to catch SIGTERM, as Thomas said, but if you need to
> know what caused a process to end, the best way is to have code in the
> parent process to catch SIGCHLD. When the child ends, for any reason,
> its parent is sent SIGCHLD with some parameters, including the signal
> number that caused the termination; you can then log anything you
> want.

Hi, i understand, i've read that SIGKILL can't catch, but nothing
about SIGTERM.
If i use SIGCHLD, i will have difficult when parent receive a SIGTERM, or not?

Thanks, regards.

--
Andrea Di Mario
-- 
http://mail.python.org/mailman/listinfo/python-list


Notifications when process is killed

2011-08-01 Thread Andrea Di Mario
Thanks Thomas, it is what i'm looking for.

Regards

-- 
Andrea Di Mario
-- 
http://mail.python.org/mailman/listinfo/python-list


Notifications when process is killed

2011-08-01 Thread Andrea Di Mario
Hi, i've created a twisted server application and i want that the
server send me a message when someone stops or kills the process.
I want to override reactor.stop(), but do this way send me message
when the process is stopped by a system kill?
Could you suggest me if there's a way to do this?

Thanks, regards.

-- 
Andrea Di Mario
-- 
http://mail.python.org/mailman/listinfo/python-list


Secure ssl connection with wrap_socket

2011-07-05 Thread Andrea Di Mario
Hi, I'm a new python user and I'm writing a small web service with ssl.
I want use a self-signed certificate like in wiki:
http://docs.python.org/dev/library/ssl.html#certificates
I've used wrap_socket, but if i try to use
cert_reqs=ssl.CERT_REQUIRED, it doesn't work with error:

urllib2.URLError: 

It works only with CERT_NONE (the default) but with this option i
could access to the service in insicure mode.

Have you some suggestions for my service?

Thanks. Regards.

-- 
Andrea Di Mario
-- 
http://mail.python.org/mailman/listinfo/python-list