class Canceled(dbus.DBusException):
_dbus_error_name = "net.connman.Error.Canceled"
-class LaunchBrowser(dbus.DBusException):
- _dbus_error_name = "net.connman.Agent.Error.LaunchBrowser"
-
class Agent(dbus.service.Object):
- name = None
- ssid = None
identity = None
passphrase = None
wpspin = None
response = {}
if not self.identity and not self.passphrase and not self.wpspin:
- print "Service credentials requested, type cancel to cancel"
args = raw_input('Answer: ')
for arg in args.split():
- if arg.startswith("cancel"):
- response["Error"] = arg
if arg.startswith("Identity="):
identity = arg.replace("Identity=", "", 1)
response["Identity"] = identity
response = {}
if not self.username and not self.password:
- print "User login requested, type cancel to cancel"
- print "or browser to login through the browser by yourself."
args = raw_input('Answer: ')
for arg in args.split():
- if arg.startswith("cancel") or arg.startswith("browser"):
- response["Error"] = arg
if arg.startswith("Username="):
username = arg.replace("Username=", "", 1)
response["Username"] = username
return response
- def input_hidden(self):
- response = {}
-
- if not self.name and not self.ssid:
- args = raw_input('Answer ')
-
- for arg in args.split():
- if arg.startswith("Name="):
- name = arg.replace("Name=", "", 1)
- response["Name"] = name
- break
- if arg.startswith("SSID="):
- ssid = arg.replace("SSID", "", 1)
- response["SSID"] = ssid
- break
- else:
- if self.name:
- response["Name"] = self.name
- if self.ssid:
- response["SSID"] = self.ssid
-
- return response
-
@dbus.service.method("net.connman.Agent",
in_signature='oa{sv}',
out_signature='a{sv}')
def RequestInput(self, path, fields):
print "RequestInput (%s,%s)" % (path, fields)
- response = {}
+ response = None
- if fields.has_key("Name"):
- response.update(self.input_hidden())
if fields.has_key("Passphrase"):
- response.update(self.input_passphrase())
- if fields.has_key("Username"):
- response.update(self.input_username())
-
- if response.has_key("Error"):
- if response["Error"] == "cancel":
- raise Canceled("canceled")
- return
- if response["Error"] == "browser":
- raise LaunchBrowser("launch browser")
- return
+ response = self.input_passphrase()
+ elif fields.has_key("Username"):
+ response = self.input_username()
+ else:
+ print "No method to answer the input request"
print "returning (%s)" % (response)
@dbus.service.method("net.connman.Agent",
in_signature='os',
out_signature='')
- def RequestBrowser(self, path, url):
- print "RequestBrowser (%s,%s)" % (path, url)
-
- print "Please login through the given url in a browser"
- print "Then press enter to accept or some text to cancel"
-
- args = raw_input('> ')
-
- if len(args) > 0:
- raise Canceled("canceled")
-
- return
-
- @dbus.service.method("net.connman.Agent",
- in_signature='os',
- out_signature='')
def ReportError(self, path, error):
print "ReportError %s, %s" % (path, error)
retry = raw_input("Retry service (yes/no): ")
def print_usage():
print "Usage:"
- print "For hidden service:"
- print "%s Name=<hidden service name> [SSID=<hidden ssid>]" % (sys.argv[0])
print "For EAP/WPA input:"
print "%s Identity=<identity> Passphrase=<passphrase> WPS=<wpspin>" % (sys.argv[0])
print "For WISPr login input:"
if len(sys.argv) >= 2:
for arg in sys.argv[1:]:
- if arg.startswith("Name="):
- object.name = arg.replace("Name=", "", 1)
- elif arg.startswith("SSID="):
- object.ssid = arg.replace("SSID=", "", 1)
- elif arg.startswith("Identity="):
+ if arg.startswith("Identity="):
object.identity = arg.replace("Identity=", "", 1)
elif arg.startswith("Passphrase="):
object.passphrase = arg.replace("Passphrase=", "", 1)