_dbus_error_name = "net.connman.Error.Canceled"
class Agent(dbus.service.Object):
- passphrase = ""
+ identity = None
+ passphrase = None
+ wpspin = None
+ username = None
+ password = None
@dbus.service.method("net.connman.Agent",
in_signature='', out_signature='')
print("Release")
mainloop.quit()
+ def input_passphrase(self):
+ response = {}
+
+ if not self.identity and not self.passphrase and not self.wpspin:
+ args = raw_input('Answer: ')
+
+ for arg in args.split():
+ if arg.startswith("Identity="):
+ identity = arg.replace("Identity=", "", 1)
+ response["Identity"] = identity
+ if arg.startswith("Passphrase="):
+ passphrase = arg.replace("Passphrase=", "", 1)
+ response["Passphrase"] = passphrase
+ if arg.startswith("WPS="):
+ wpspin = arg.replace("WPS=", "", 1)
+ response["WPS"] = wpspin
+ break
+ else:
+ if self.identity:
+ response["Identity"] = self.identity
+ if self.passphrase:
+ response["Passphrase"] = self.passphrase
+ if self.wpspin:
+ response["WPS"] = self.wpspin
+
+ return response
+
+ def input_username(self):
+ response = {}
+
+ if not self.username and not self.password:
+ args = raw_input('Answer: ')
+
+ for arg in args.split():
+ if arg.startswith("Username="):
+ username = arg.replace("Username=", "", 1)
+ response["Username"] = username
+ if arg.startswith("Password="):
+ password = arg.replace("Password=", "", 1)
+ response["Password"] = password
+ else:
+ if self.username:
+ response["Username"] = self.username
+ if self.password:
+ response["Password"] = self.password
+
+ 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["Passphrase"] = self.passphrase
+ response = None
+
+ if fields.has_key("Passphrase"):
+ 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)
return response
@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): ")
+ if (retry == "yes"):
+ class Retry(dbus.DBusException):
+ _dbus_error_name = "net.connman.Agent.Error.Retry"
+
+ raise Retry("retry service")
+ else:
+ return
+
+
+ @dbus.service.method("net.connman.Agent",
in_signature='', out_signature='')
def Cancel(self):
print "Cancel"
-
+def print_usage():
+ print "Usage:"
+ print "For EAP/WPA input:"
+ print "%s Identity=<identity> Passphrase=<passphrase> WPS=<wpspin>" % (sys.argv[0])
+ print "For WISPr login input:"
+ print "%s Username=<username> Password=<password>" % (sys.argv[0])
+ print "Help: %s help" % (sys.argv[0])
+ sys.exit(1)
if __name__ == '__main__':
- if len(sys.argv) < 2:
- print "Usage: %s <passphrase>" % (sys.argv[0])
- sys.exit(1)
+ if len(sys.argv) == 2 and sys.argv[1] == "help":
+ print_usage()
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
path = "/test/agent"
object = Agent(bus, path)
- object.passphrase = sys.argv[1]
+
+ if len(sys.argv) >= 2:
+ for arg in sys.argv[1:]:
+ if arg.startswith("Identity="):
+ object.identity = arg.replace("Identity=", "", 1)
+ elif arg.startswith("Passphrase="):
+ object.passphrase = arg.replace("Passphrase=", "", 1)
+ elif arg.startswith("WPS="):
+ object.wpspin = arg.replace("WPS=", "", 1)
+ elif arg.startswith("Username="):
+ object.username = arg.replace("Username=", "", 1)
+ elif arg.startswith("Password="):
+ object.password = arg.replace("Password=", "", 1)
+ else:
+ print_usage()
manager.RegisterAgent(path)