|
##############################################################################
|
|
# -*- 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
|
|
# along with ControlIES. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
##############################################################################
|
|
|
|
from Utils.avahiClient import avahiClient
|
|
|
|
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
|
|
import os.path
|
|
|
|
|
|
registerAdapter(LdapConnection, Session, ILdapConnection)
|
|
|
|
# Start up the web service.
|
|
Root = MainLoop.ControlIESProtocol() #Resource object
|
|
Root.PageDir='/home/manu/proyectos/controlies/www/'
|
|
#Root.PageDir='/home/chisco/Proyectos/controlies/www'
|
|
site = server.Site(Root)
|
|
|
|
fileName = '/tmp/controlIES.ltpsSevers'
|
|
|
|
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
|
|
|
|
reactor.listenTCP(7778,site)
|
|
reactor.run()
|