def main(): if not '-d' in sys.argv: become_daemon() config = json.loads(file('/etc/foobox.conf', 'r').read()) logging.basicConfig(filename=config['common']['log_path'], level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') urls = [ ('^/(?P<user>[_\w]+)/message/(?P<id>[a-z0-9\-]+)$', Message), ('^/(?P<user>[_\w]+)/message$', Message), ('^/(?P<user>[_\w]+)/route/(?P<id>[a-z0-9\-]+)$', Route), ('^/(?P<user>[_\w]+)/route$', Route), ('^/(?P<user>[_\w]+)/app/(?P<id>[a-z0-9\-]+)$', App), ('^/(?P<user>[_\w]+)/app$', App), ('^/$', StaticPage), ] data = HTTPStore(config['common']['data_url']) app = WSGIApp(urls, data=data) #server = WSGIServer(app, bindAddress=(config['bind_address'], int(config['bind_port']))) server = make_server(config['foobox']['bind_address'], config['foobox']['bind_port'], app) worker = Worker(Message.queue) try: worker.start() logging.info('foobox server running at %s:%s' % (config['foobox']['bind_address'], config['foobox']['bind_port'])) server.serve_forever() except: logging.error(format_exc())
from netgrowl import GrowlRegistrationPacket, GrowlNotificationPacket, GROWL_UDP_PORT from socket import socket, AF_INET, SOCK_DGRAM import logging class Growl(FooApp): name = 'growl' config_opts = { 'target': 'IP address to send growl notifications to', } def __init__(self, server=None): FooApp.__init__(self, server) self.data = FileStore('/tmp/apps/growl') self.sock = socket(AF_INET, SOCK_DGRAM) p = GrowlRegistrationPacket(application='foobox', password='') p.addNotification('Message', enabled=True) self.sock.sendto(p.payload(), (self.data['target'], GROWL_UDP_PORT)) def send(self, msg): p = GrowlNotificationPacket(application='foobox', notification='Message', title=msg['src'], description=msg['text']) self.sock.sendto(p.payload(), (self.data['target'], GROWL_UDP_PORT)) if __name__ == '__main__': become_daemon() start_app(Growl)
return Response(status=200) class IndexHandler(RequestHandler): def get(self): ip = self.request.remote_addr template = file('index.html', 'rb').read() template = template.replace('$REMOTE_ADDR', ip) if ip in [x[7] for x in iplist()]: template = template.replace('$STATUS', 'ACCEPT') else: template = template.replace('$STATUS', 'DROP') return Response(status=200, body=template) if __name__ == '__main__': from flup.server.fcgi import WSGIServer if conf('server.daemonize'): from ncore.daemon import become_daemon become_daemon(out_log=conf('server.daemon_log'), err_log=conf('server.daemon_log')) app = Application([ ('/foothold/api/(?P<ip>[0-9.]+)/*$', IPHandler), ('/foothold/*$', IndexHandler), ]) #server = make_server(conf('server.bind_address'), conf('server.bind_port'), app) server = WSGIServer(app, bindAddress=(conf('server.bind_address'), conf('server.bind_port')), debug=True) server.run()