-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbluepim.py
More file actions
executable file
·72 lines (60 loc) · 2.3 KB
/
bluepim.py
File metadata and controls
executable file
·72 lines (60 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
#http://wiki.bluez.org/wiki/PasskeyAgent
import dbus
import dbus.glib
import dbus.service
import gobject
import sys
import gtk
def pin_entry(address):
# build dialog
dialog = gtk.Dialog("New bluetooth connection", None, gtk.DIALOG_MODAL,
(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
dialog.set_default_response(gtk.RESPONSE_ACCEPT)
dialog.set_position(gtk.WIN_POS_CENTER)
# tabulka
table = gtk.Table(2, 2, False)
dialog.vbox.pack_start(table)
table.show()
# entry
entry = gtk.Entry()
entry.set_activates_default(True)
table.attach(entry, 1, 2, 1, 2, gtk.EXPAND|gtk.FILL, gtk.EXPAND|gtk.FILL, 10, 2)
entry.show()
# icon
icon = gtk.Image()
icon.set_from_stock(gtk.STOCK_DIALOG_AUTHENTICATION, gtk.ICON_SIZE_DIALOG)
table.attach(icon, 0, 1, 0, 2, gtk.FILL, gtk.FILL, 12, 12)
icon.show()
# label
label = gtk.Label("New bluetooth connection to " + address + "\nPlease enter PIN:")
label.set_alignment(0, 1)
table.attach(label, 1, 2, 0, 1, gtk.EXPAND|gtk.FILL, gtk.EXPAND|gtk.FILL, 10, 2)
label.show()
# run dialog
if dialog.run() == gtk.RESPONSE_ACCEPT:
pin = entry.get_text()
else:
pin = ""
dialog.destroy()
return pin
class PasskeyAgent(dbus.service.Object):
def __init__(self, path):
dbus.service.Object.__init__(self, dbus.SystemBus(), path)
@dbus.service.method(dbus_interface='org.bluez.PasskeyAgent',
in_signature='ssb', out_signature='s')
def Request(self, path, address, numeric):
try:
pin = pin_entry(address)
return pin
except:
return ""
if __name__ == "__main__":
PATH = '/my/PasskeyAgent'
bus = dbus.SystemBus();
handler = PasskeyAgent(PATH)
adapter = bus.get_object('org.bluez', '/org/bluez/hci0')
sec = dbus.Interface(adapter, 'org.bluez.Security')
sec.RegisterDefaultPasskeyAgent(PATH)
main_loop = gobject.MainLoop()
main_loop.run()