7 import dbus.mainloop.glib
10 class Canceled(dbus.DBusException):
11 _dbus_error_name = "net.connman.Error.Canceled"
13 class Agent(dbus.service.Object):
20 @dbus.service.method("net.connman.Agent",
21 in_signature='', out_signature='')
26 def input_passphrase(self):
29 if not self.identity and not self.passphrase and not self.wpspin:
30 args = raw_input('Answer: ')
32 for arg in args.split():
33 if arg.startswith("Identity="):
34 identity = arg.replace("Identity=", "", 1)
35 response["Identity"] = identity
37 if arg.startswith("Passphrase="):
38 passphrase = arg.replace("Passphrase=", "", 1)
39 response["Passphrase"] = passphrase
41 if arg.startswith("WPS="):
42 wpspin = arg.replace("WPS=", "", 1)
43 response["WPS"] = wpspin
47 response["Identity"] = self.identity
49 response["Passphrase"] = self.passphrase
51 response["WPS"] = self.wpspin
55 def input_username(self):
58 if not self.username and not self.password:
59 args = raw_input('Answer: ')
61 for arg in args.split():
62 if arg.startswith("Username="):
63 username = arg.replace("Username=", "", 1)
64 response["Username"] = username
66 if arg.startswith("Password="):
67 password = arg.replace("Password=", "", 1)
68 response["Password"] = password
72 response["Username"] = self.username
74 response["Password"] = self.password
78 @dbus.service.method("net.connman.Agent",
79 in_signature='oa{sv}',
80 out_signature='a{sv}')
81 def RequestInput(self, path, fields):
82 print "RequestInput (%s,%s)" % (path, fields)
86 if fields.has_key("Passphrase"):
87 response = self.input_passphrase()
88 elif fields.has_key("Username"):
89 response = self.input_username()
91 print "No method to answer the input request"
93 print "returning (%s)" % (response)
97 @dbus.service.method("net.connman.Agent",
100 def ReportError(self, path, error):
101 print "ReportError %s, %s" % (path, error)
102 retry = raw_input("Retry service (yes/no): ")
104 class Retry(dbus.DBusException):
105 _dbus_error_name = "net.connman.Agent.Error.Retry"
107 raise Retry("retry service")
112 @dbus.service.method("net.connman.Agent",
113 in_signature='', out_signature='')
119 print "For EAP/WPA input:"
120 print "%s Identity=<identity> Passphrase=<passphrase> WPS=<wpspin>" % (sys.argv[0])
121 print "For WISPr login input:"
122 print "%s Username=<username> Password=<password>" % (sys.argv[0])
123 print "Help: %s help" % (sys.argv[0])
126 if __name__ == '__main__':
127 if len(sys.argv) == 2 and sys.argv[1] == "help":
130 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
132 bus = dbus.SystemBus()
133 manager = dbus.Interface(bus.get_object('net.connman', "/"),
134 'net.connman.Manager')
137 object = Agent(bus, path)
139 if len(sys.argv) >= 2:
140 for arg in sys.argv[1:]:
141 if arg.startswith("Identity="):
142 object.identity = arg.replace("Identity=", "", 1)
143 elif arg.startswith("Passphrase="):
144 object.passphrase = arg.replace("Passphrase=", "", 1)
145 elif arg.startswith("WPS="):
146 object.wpspin = arg.replace("WPS=", "", 1)
147 elif arg.startswith("Username="):
148 object.username = arg.replace("Username=", "", 1)
149 elif arg.startswith("Password="):
150 object.password = arg.replace("Password=", "", 1)
154 manager.RegisterAgent(path)
156 mainloop = gobject.MainLoop()
159 #manager.UnregisterAgent(path)