webXMPP

Check-in [915508d040]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Some logging for the Ham notification service. Suppress initial notification events while the notify daemon is starting up and catching up. Blacklist is an ofono thing, but it sits alongside the others on my Ubuntu phone, so I'll just keep it here for now
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:915508d040a86bdc2efc800e3d8054ca3b4f506f4ee341dfb73a736517ccd0d1
User & Date: vandys 2018-11-09 01:41:09
Context
2018-11-20
19:30
flite pronounces the word "underscore" for every single underscore in the message line... check-in: 0ef40c339b user: vandys tags: master, trunk
2018-11-09
01:41
Some logging for the Ham notification service. Suppress initial notification events while the notify daemon is starting up and catching up. Blacklist is an ofono thing, but it sits alongside the others on my Ubuntu phone, so I'll just keep it here for now check-in: 915508d040 user: vandys tags: master, trunk
2018-09-22
14:07
Fix usage check-in: 8543639bab user: vandys tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added tools/blacklist.py.





























































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
73
74
75
76
77
78
#!/usr/bin/python3
import sys, threading, os, time
import dbus, dbus.exceptions, dbus.mainloop.glib
from gi.repository import GLib
import pdb

class Blacklist(object):
    def __init__(self, fn):

        # Initial load of @fn
        self.fname = fn
        self.ftime = None
        self.reload()

        # Threading; one for the watcher, one for main
        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
        l = GLib.MainLoop()
        t = threading.Thread(target=l.run)
        t.start()

        # Connection to dbus
        bus = self.bus = dbus.SystemBus()
        bus.add_signal_receiver(self.watcher, "CallAdded",
            dbus_interface="org.ofono.VoiceCallManager")

    # Watching for new call
    def watcher(self, *args, **kwargs):
        self.reload()
        call = str(args[0])
        obdict = args[1]
        callerid = str(obdict["LineIdentification"])
        if any( (s in callerid) for s in self.rejects ):
            sys.stderr.write("%s Rejecting call from %s\n" %
                (time.strftime("%m/%d %H:%M"), callerid))
            self.hangup(call)

    # (re-)Load blacklist
    def reload(self):

        # Reload when needed
        try:
            f = open(self.fname, "r")
        except:
            self.ftime = None
            return
        st = os.fstat(f.fileno())
        if st.st_mtime == self.ftime:
            f.close()
            return
        self.ftime = st.st_mtime

        # Load new contents
        self.rejects = []
        for l in f:

            # One phone number per line
            l = l.strip()

            # Ignore empty and comments
            if not l:
                continue
            if l[0] == '#':
                continue

            # Add to reject list
            self.rejects.append(l)
        f.close()
        sys.stderr.write("%d blacklist items\n" %
            (len(self.rejects or ()),))

    # Drop the named call
    def hangup(self, callid):
        callob = self.bus.get_object('org.ofono', callid)
        call = dbus.Interface(callob, 'org.ofono.VoiceCall')
        call.Hangup()

if __name__ == "__main__":
    b = Blacklist(os.environ["HOME"] + "/.config/blacklist.txt")

Changes to tools/ham.py.

44
45
46
47
48
49
50





51
52
53
54
55
56
57
..
75
76
77
78
79
80
81



82
83
84
85
86
87
88
..
91
92
93
94
95
96
97
98
99





100

101
102
103
104
105
106
107
	rhost,rigcfg = cfg["rig"]
	rport = rigcfg["port"]
	self.raddr = (rhost, rport)
	rchan = rigcfg["channel"][0].upper()
	self.rtxon = json.dumps({"chan": rchan, "val": 1})
	self.rtxoff = json.dumps({"chan": rchan, "val": 0})






    # Transmitter control
    def tx_on(self):
	self.rconn.sendto(self.rtxon, self.raddr)
    def tx_off(self):
	self.rconn.sendto(self.rtxoff, self.raddr)

    # Configuration, indented chore style
................................................................................
	#  port Y
	#  channel Z
	#  audio "audio-device-name"
	c.onearg.add( ("rig",) )
	c.ints.add( ("rig", "port") )
	c.onearg.add( ("rig", "channel") )
	c.onearg.add( ("rig", "audio") )




	# Parse and set config dict
	self.cfg = c.load_cfg(fn)

    # New notifications contained in this packet
    def notify(self, pak):

................................................................................
	    if time.time() < self.starttm:
		return
	    self.starttm = None

	inner = pak.inner
	log("Notification: gen %d -> %d\n" % (self.gen, inner["gen"]))
	for tup in inner["msgs"]:
	    lt = len(tup)






	    # Ignore mirrors of our own sends on other devices

	    if lt and (not tup[0]):
		continue

	    # No details at all, so just show one notification
	    if lt in (0, 1):
		n1 = "New Message"
		n2 = None







>
>
>
>
>







 







>
>
>







 







<

>
>
>
>
>

>







44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
..
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
..
99
100
101
102
103
104
105

106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
	rhost,rigcfg = cfg["rig"]
	rport = rigcfg["port"]
	self.raddr = (rhost, rport)
	rchan = rigcfg["channel"][0].upper()
	self.rtxon = json.dumps({"chan": rchan, "val": 1})
	self.rtxoff = json.dumps({"chan": rchan, "val": 0})

	# Log all alerts?
	self.logf = None
	if "log" in cfg:
	    self.logf = open(cfg["log"], "a")

    # Transmitter control
    def tx_on(self):
	self.rconn.sendto(self.rtxon, self.raddr)
    def tx_off(self):
	self.rconn.sendto(self.rtxoff, self.raddr)

    # Configuration, indented chore style
................................................................................
	#  port Y
	#  channel Z
	#  audio "audio-device-name"
	c.onearg.add( ("rig",) )
	c.ints.add( ("rig", "port") )
	c.onearg.add( ("rig", "channel") )
	c.onearg.add( ("rig", "audio") )

	# Plain text dump of what we've been told to notify
	c.onearg.add( ("log",) )

	# Parse and set config dict
	self.cfg = c.load_cfg(fn)

    # New notifications contained in this packet
    def notify(self, pak):

................................................................................
	    if time.time() < self.starttm:
		return
	    self.starttm = None

	inner = pak.inner
	log("Notification: gen %d -> %d\n" % (self.gen, inner["gen"]))
	for tup in inner["msgs"]:


	    # Possibly record messaged text
	    if self.logf is not None:
		self.logf.write("%s\n" % (tup,))
		self.logf.flush()

	    # Ignore mirrors of our own sends on other devices
	    lt = len(tup)
	    if lt and (not tup[0]):
		continue

	    # No details at all, so just show one notification
	    if lt in (0, 1):
		n1 = "New Message"
		n2 = None

Changes to tools/notified.py.

58
59
60
61
62
63
64




65
66
67
68
69
70
71
...
273
274
275
276
277
278
279



280


281
282
283
284
285
286
287
# Are LEDs available for notification indication?
LED = "/sys/class/leds/red"
blinking = leds = False

# Initial condition, no events ever seen
gen = 0





# Hook for logging
def log(s):
    sys.stderr.write(s)
    sys.stderr.write('\n')

# Quick/easy way to turn dict into an ob with those k/v as attrs
class DictOb(object):
................................................................................
                break

            # Nothing happened
            if resp.inner["gen"] == gen:
                continue

            # New messages



            notify(resp)


            gen = resp.inner["gen"]

if __name__ == "__main__":
    load_cfg()

    # No arg, just be a service daemon
    if len(sys.argv) == 1:







>
>
>
>







 







>
>
>
|
>
>







58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
...
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# Are LEDs available for notification indication?
LED = "/sys/class/leds/red"
blinking = leds = False

# Initial condition, no events ever seen
gen = 0

# Timestamp of our start, for suppressing initial message
#  notifications
Started = time.time()

# Hook for logging
def log(s):
    sys.stderr.write(s)
    sys.stderr.write('\n')

# Quick/easy way to turn dict into an ob with those k/v as attrs
class DictOb(object):
................................................................................
                break

            # Nothing happened
            if resp.inner["gen"] == gen:
                continue

            # New messages
            # During startup, we'll get these as we
            #  catch up, so don't show those initial ones
            if (time.time() - Started) > 10:
                notify(resp)

            # Always note latest generation
            gen = resp.inner["gen"]

if __name__ == "__main__":
    load_cfg()

    # No arg, just be a service daemon
    if len(sys.argv) == 1: