blob: d85acf4acafab01a5a81975a746ff32fcfe7ad58 [file] [log] [blame]
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Implement an activation server
import BaseHTTPServer
import dbus
import mm
import os
import SimpleHTTPServer
import SocketServer
def Carrier():
bus = dbus.SystemBus()
obj = bus.get_object('org.chromium.ModemManager',
return dbus.Interface(obj, 'org.chromium.ModemManager.Carrier')
PORT = 8080
class LocalCarrierRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self, *args, **kwargs):
"""Handle GET request.
The LocalCarrierRequestHandler handles 2 specific GET commands
based on the path in the url. These are:
payment_succeeded.html: Payment succeeded
payment_failed.html: Payment request failed
In both cases a DBUS message is sent to the fake-cromo server so
that it can implement carrier specific behavior associated with
path = self.translate_path(self.path)
basename = os.path.basename(path)
if basename == 'payment_succeeded.html':
elif basename == 'payment_failed.html':
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self, *args, **kwargs)
def PaymentSucceeded(self):
# Always recreate to allow restarts for fake-cromo
carrier = Carrier()
print 'user paid'
def PaymentFailed(self):
# Always recreate to allow restarts for fake-cromo
carrier = Carrier()
print 'user failed to pay'
def send_response(self, code, message=None):
"""Send the response header
This version marks all pages as non cacheable after sending
the other default headers in the base class
BaseHTTPServer.BaseHTTPRequestHandler.send_response(self, code, message)
self.send_header('Cache-Control', 'no-cache')
class ThreadingBaseHTTPServer(SocketServer.ThreadingMixIn,
BaseHTTPServer.HTTPServer): pass
httpd = ThreadingBaseHTTPServer(("", PORT), LocalCarrierRequestHandler)
print "serving at port", PORT