Exemplo n.º 1
0
    def __init__(self):
        Resource.__init__(self)
	ami.connect()
	self.call_manager = CallManager()
	our_dir = os.path.dirname(os.path.dirname(obelisk.__file__))
	ami.connector.registerEvent('CEL', self.call_manager.on_event)
        self.putChild("voip", PeersResource())
        self.putChild("prices", PricesResource())
        self.putChild("voicemail", VoiceMailResource())
        self.putChild("user", UserResource())
        self.putChild("sse", SSEResource())
        self.putChild("calls", CallsResource())
        self.putChild("password", ChangePassResource())
        self.putChild("credit", CreditResource())
        self.putChild("register", RegisterResource())
        self.putChild("options", OptionsResource())
        self.putChild("stats", StatsResource())
        self.putChild("providers", ProvidersResource())
        self.putChild("login", LoginResource())
        self.putChild("logout", LogoutResource())
        self.putChild("admin", AdminResource())
        self.putChild("docs", DocsResource())
        self.putChild("icons", File("/usr/share/icons"))
        self.putChild("tpl", File(os.path.join(our_dir, "templates")))
        self.putChild("sip", File("/home/lluis/tst_sip_gui"))
        self.putChild("jssip", File("/home/caedes/jssip"))
        self.putChild("favicon.ico", File(os.path.join(our_dir, "templates", "telephone_icon.ico")))
        self.putChild("tinc", TincResource())
        self.putChild("dundi", DundiResource())
        self.putChild("pln", PLNResource())
        self.putChild("btcin", BtcInResource())
	if 'pln' in obelisk.config.config:
		pln_name = obelisk.config.config['pln']['name']
		self.putChild(pln_name, Redirect('/tinc/pubkey'))
		self.putChild(pln_name +'.pub', Redirect('/dundi/pubkey'))
	self.putChild('node.json', Redirect('/pln/node.json'))

	reactor.callLater(2, reactor.callInThread, self.get_winners)
	reactor.callLater(4, reactor.callInThread, self.get_channel_test)
	self.channel_tester = TestChannels()
        # start running the ticker
        ticker.ticker()
Exemplo n.º 2
0
class RootResource(Resource):
    def __init__(self):
        Resource.__init__(self)
	ami.connect()
	self.call_manager = CallManager()
	our_dir = os.path.dirname(os.path.dirname(obelisk.__file__))
	ami.connector.registerEvent('CEL', self.call_manager.on_event)
        self.putChild("voip", PeersResource())
        self.putChild("prices", PricesResource())
        self.putChild("voicemail", VoiceMailResource())
        self.putChild("user", UserResource())
        self.putChild("sse", SSEResource())
        self.putChild("calls", CallsResource())
        self.putChild("password", ChangePassResource())
        self.putChild("credit", CreditResource())
        self.putChild("register", RegisterResource())
        self.putChild("options", OptionsResource())
        self.putChild("stats", StatsResource())
        self.putChild("providers", ProvidersResource())
        self.putChild("login", LoginResource())
        self.putChild("logout", LogoutResource())
        self.putChild("admin", AdminResource())
        self.putChild("docs", DocsResource())
        self.putChild("icons", File("/usr/share/icons"))
        self.putChild("tpl", File(os.path.join(our_dir, "templates")))
        self.putChild("sip", File("/home/lluis/tst_sip_gui"))
        self.putChild("jssip", File("/home/caedes/jssip"))
        self.putChild("favicon.ico", File(os.path.join(our_dir, "templates", "telephone_icon.ico")))
        self.putChild("tinc", TincResource())
        self.putChild("dundi", DundiResource())
        self.putChild("pln", PLNResource())
	if 'pln' in obelisk.config.config:
		pln_name = obelisk.config.config['pln']['name']
		self.putChild(pln_name, Redirect('/tinc/pubkey'))
		self.putChild(pln_name +'.pub', Redirect('/dundi/pubkey'))
	self.putChild('node.json', Redirect('/pln/node.json'))

	reactor.callLater(2, reactor.callInThread, self.get_winners)
	reactor.callLater(4, reactor.callInThread, self.get_channel_test)
	self.channel_tester = TestChannels()

    def get_winners(self):
	get_winners()
	reactor.callLater(600, reactor.callInThread, self.get_winners)

    def get_channel_test(self):
	test = self.channel_tester.get_rates()
	if test:
		reactor.callFromThread(sse.resource.notify, test, 'channels', 'all')
	reactor.callLater(5, reactor.callInThread, self.get_channel_test)

    def getChild(self, name, request):
        return self

    def render_GET(self, request):

	output = "<li><a href='/prices'>precios</a></li>"
	output += "<li><a href='/docs'>documentacion</a></li>"

	user = session.get_user(request)
        main_page = print_template('portada', {})
	if user:
		user_ext = user.voip_id
		output_user = "<li><a href='/user/"+user.voip_id+"'>datos usuario</a></li>"
		output_user += "<li><a href='/voip'>listin telefonico</a></li>"
		output_user += "<li><a href='/stats'>estadisticas</a></li>"
		if user.admin == 1:
			output_user += "<li><a href='/admin'>admin</a></li>"
			user_ext += " eres admin"
		output_user += "<li><a href='/logout'>logout</a></li>"

	        return print_template('logged-pbx-lorea', {'LINKS':output, 'LOGGED_LINKS':output_user, 'user': user_ext, 'content': main_page})
	else:
		output += "<li><a href='/register'>registrarse</a></li>"
	        return print_template('home-pbx-lorea', {'LINKS':output, 'content': main_page})

    def render_POST(self, request):
	return "<p>xxxxx</p>"