root/controlies/Server.py @ 92
61 | manumora | ##############################################################################
|
|
# -*- coding: utf-8 -*-
|
|||
# Project: ControlIES
|
|||
# Module: Server.py
|
|||
# Purpose: ControlIES web server
|
|||
# Language: Python 2.5
|
|||
# Date: 7-Feb-2011.
|
|||
# Ver: 7-Feb-2011.
|
|||
# Author: Manuel Mora Gordillo
|
|||
# Copyright: 2011 - Manuel Mora Gordillo <manuito @no-spam@ gmail.com>
|
|||
#
|
|||
# ControlIES is free software: you can redistribute it and/or modify
|
|||
# it under the terms of the GNU General Public License as published by
|
|||
# the Free Software Foundation, either version 3 of the License, or
|
|||
# (at your option) any later version.
|
|||
# ControlIES is distributed in the hope that it will be useful,
|
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|||
# GNU General Public License for more details.
|
|||
# You should have received a copy of the GNU General Public License
|
|||
91 | manumora | # along with ControlIES. If not, see <http://www.gnu.org/licenses/>.
|
|
61 | manumora | #
|
|
##############################################################################
|
|||
91 | manumora | from Utils.avahiClient import avahiClient
|
|
61 | manumora | from twisted.web import static, server
|
|
from twisted.web.server import Session
|
|||
from twisted.python.components import registerAdapter
|
|||
import MainLoop
|
|||
from zope.interface import Interface, Attribute, implements
|
|||
from Plugins.LdapConnection import LdapConnection, ILdapConnection
|
|||
91 | manumora | import os.path
|
|
61 | manumora | ||
91 | manumora | ||
61 | manumora | registerAdapter(LdapConnection, Session, ILdapConnection)
|
|
# Start up the web service.
|
|||
Root = MainLoop.ControlIESProtocol() #Resource object
|
|||
89 | manumora | Root.PageDir='/home/manu/proyectos/controlies/www/'
|
|
#Root.PageDir='/home/chisco/Proyectos/controlies/www'
|
|||
61 | manumora | site = server.Site(Root)
|
|
91 | manumora | fileName = '/tmp/controlIES.ltpsSevers'
|
|
61 | manumora | ||
91 | manumora | if os.path.isfile(fileName):
|
|
os.remove(fileName)
|
|||
f = open(fileName, 'w')
|
|||
def _add_location(self, name, address, port):
|
|||
f = open(fileName, 'r+')
|
|||
f.write(name)
|
|||
f.close()
|
|||
print "add"
|
|||
def _remove_location(self, name, address, port):
|
|||
print "remove"
|
|||
#remove ipv6 entries:
|
|||
if address.find(":") == -1:
|
|||
print "removed:" + name,address,port
|
|||
try:
|
|||
_monitor = avahiClient()
|
|||
_monitor.add_callback('new-service', _add_location)
|
|||
_monitor.add_callback('remove-service', _remove_location)
|
|||
_monitor.start()
|
|||
except Exception, ex:
|
|||
error_msg = "Couldn't initialize Avahi monitor: %s" % str(ex)
|
|||
#raise InitializeFailure(self.name, error_msg)
|
|||
from twisted.internet import reactor
|
|||
61 | manumora | reactor.listenTCP(7778,site)
|
|
reactor.run()
|