2016-04-28 01:27:27 +02:00
|
|
|
#!/usr/bin/python3
|
2015-02-27 15:01:14 +01:00
|
|
|
|
2015-03-20 05:53:16 +01:00
|
|
|
from gi.repository import GLib
|
2015-02-27 15:01:14 +01:00
|
|
|
|
|
|
|
import dbus
|
|
|
|
import dbus.service
|
|
|
|
import dbus.mainloop.glib
|
|
|
|
import sys
|
|
|
|
from random import randrange
|
|
|
|
|
|
|
|
class Canceled(dbus.DBusException):
|
2015-03-20 05:53:16 +01:00
|
|
|
_dbus_error_name = "net.connman.iwd.Error.Canceled"
|
2015-02-27 15:01:14 +01:00
|
|
|
|
|
|
|
class Agent(dbus.service.Object):
|
2015-03-20 05:53:16 +01:00
|
|
|
passphrase = None
|
2015-02-27 15:01:14 +01:00
|
|
|
|
2015-03-20 05:53:16 +01:00
|
|
|
@dbus.service.method("net.connman.iwd.Agent",
|
|
|
|
in_signature='', out_signature='')
|
|
|
|
def Release(self):
|
|
|
|
print("Release")
|
|
|
|
mainloop.quit()
|
2015-02-27 15:01:14 +01:00
|
|
|
|
2015-03-20 05:53:16 +01:00
|
|
|
@dbus.service.method("net.connman.iwd.Agent",
|
|
|
|
in_signature='o',
|
|
|
|
out_signature='s')
|
|
|
|
def RequestPassphrase(self, path):
|
|
|
|
print("RequestPassphrase (%s)" % (path))
|
2015-02-27 15:01:14 +01:00
|
|
|
|
2015-05-26 19:51:26 +02:00
|
|
|
print("Service credentials requested, type cancel to cancel")
|
2016-04-28 01:27:27 +02:00
|
|
|
passphrase = input('Answer: ')
|
2015-02-27 15:01:14 +01:00
|
|
|
|
2015-05-26 19:51:26 +02:00
|
|
|
if not passphrase or passphrase == 'cancel':
|
|
|
|
raise Canceled("canceled")
|
2015-02-27 15:01:14 +01:00
|
|
|
|
2015-05-26 19:51:26 +02:00
|
|
|
print("returning (%s)" % (passphrase))
|
|
|
|
return passphrase
|
2015-02-27 15:01:14 +01:00
|
|
|
|
2015-03-20 05:53:16 +01:00
|
|
|
@dbus.service.method("net.connman.iwd.Agent",
|
2016-06-10 11:49:35 +02:00
|
|
|
in_signature='s', out_signature='')
|
|
|
|
def Cancel(self, reason):
|
|
|
|
print("Cancel: " + reason)
|
2015-02-27 15:01:14 +01:00
|
|
|
|
|
|
|
def print_usage():
|
2015-03-20 05:53:16 +01:00
|
|
|
print("Usage:")
|
|
|
|
print("For WPA input:")
|
|
|
|
print("%s Passphrase=<passphrase>" % (sys.argv[0]))
|
|
|
|
print("Help: %s help" % (sys.argv[0]))
|
|
|
|
sys.exit(1)
|
2015-02-27 15:01:14 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2015-03-20 05:53:16 +01:00
|
|
|
if len(sys.argv) == 2 and sys.argv[1] == "help":
|
|
|
|
print_usage()
|
2015-02-27 15:01:14 +01:00
|
|
|
|
2015-03-20 05:53:16 +01:00
|
|
|
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
2015-02-27 15:01:14 +01:00
|
|
|
|
2015-03-20 05:53:16 +01:00
|
|
|
bus = dbus.SystemBus()
|
|
|
|
manager = dbus.Interface(bus.get_object('net.connman.iwd', "/"),
|
2016-05-21 03:39:37 +02:00
|
|
|
'net.connman.iwd.AgentManager')
|
2015-02-27 15:01:14 +01:00
|
|
|
|
2015-03-20 05:53:16 +01:00
|
|
|
path = "/test/agent/" + str(randrange(100))
|
|
|
|
object = Agent(bus, path)
|
2015-02-27 15:01:14 +01:00
|
|
|
|
2015-03-20 05:53:16 +01:00
|
|
|
if len(sys.argv) >= 2:
|
|
|
|
for arg in sys.argv[1:]:
|
|
|
|
if arg.startswith("Passphrase="):
|
|
|
|
object.passphrase = arg.replace("Passphrase=", "", 1)
|
|
|
|
else:
|
|
|
|
print_usage()
|
2015-02-27 15:01:14 +01:00
|
|
|
|
2015-03-20 05:53:16 +01:00
|
|
|
try:
|
|
|
|
manager.RegisterAgent(path)
|
|
|
|
except:
|
|
|
|
print("Cannot register iwd agent.")
|
2015-02-27 15:01:14 +01:00
|
|
|
|
2015-03-20 05:53:16 +01:00
|
|
|
mainloop = GLib.MainLoop()
|
|
|
|
mainloop.run()
|