From aab4793fe8b39c14ca4fe282bca87f0a1afaea1b Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Tue, 7 Jan 2020 14:54:24 -0500 Subject: [PATCH 1/5] correct thes for compressed pkt; fix output format --- hbc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hbc b/hbc index 21d13ae..a1460f5 100755 --- a/hbc +++ b/hbc @@ -136,7 +136,7 @@ def dicttos(ID, d): def stodict(msg): d = {} - if len(msg) > 0 and chr(msg[0]) == "!": + if len(msg) > 0 and msg[0] == "!": pk = zlib.decompress(msg[5:]).decode() d['ID'] = msg[1:4].decode() else: @@ -334,7 +334,7 @@ def process(): try: msgDict = stodict(data) except Exception as e: - print("failed to parse incoming data from %s: " % (addr, data)) + print("failed to parse incoming data from %s: %s (%s)" % (addr, data, e)) continue if verbose: print("sock.recvfrom: %s (%s) %s" % (addr, len(data), str(msgDict)[:80])) From 7786b842857e327f73391b6cb0cd4bc43a5e8cbe Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Tue, 7 Jan 2020 15:43:49 -0500 Subject: [PATCH 2/5] finish conversion to python 3 --- hbc | 17 +++++++++-------- hbd | 8 +++++--- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/hbc b/hbc index a1460f5..9ea624a 100755 --- a/hbc +++ b/hbc @@ -16,8 +16,7 @@ import shutil import zlib import subprocess import syslog - -import syslog +import codecs PORT = 50003 @@ -136,7 +135,7 @@ def dicttos(ID, d): def stodict(msg): d = {} - if len(msg) > 0 and msg[0] == "!": + if len(msg) > 0 and chr(msg[0]) == "!": pk = zlib.decompress(msg[5:]).decode() d['ID'] = msg[1:4].decode() else: @@ -151,8 +150,10 @@ def stodict(msg): d[k] = None else: v = vr[1].strip() - if v[0].isdigit(): + try: v = eval(v) + except: + pass d[k] = v if verbose: print("msg is %s" % d) return d @@ -241,7 +242,7 @@ def doexec(conn, data): def doupdate(conn, msgDict): fail = None try: - code = msgDict['code'].decode('base64') + code = codecs.decode(msgDict['code'],'base64').decode() csum = msgDict['csum'] except: fail = "csum/code missing" @@ -258,8 +259,8 @@ def doupdate(conn, msgDict): def doupdateone(code, csum): - m = md5.new() - m.update(code) + m = md5() + m.update(code.encode()) icsum = m.hexdigest() if icsum != csum: return "checksum error" @@ -330,7 +331,7 @@ def process(): for rfh in r[0]: conn = conIds[rfh] data, addr = ifiles[rfh].recvfrom(MAXRECV) -# if verbose: print("sock.recvfrom: %s (%s) %s" % (addr, len(data), data[:4])) + if verbose: print("sock.recvfrom: %s (%s) %s" % (addr, len(data), data[:4])) try: msgDict = stodict(data) except Exception as e: diff --git a/hbd b/hbd index 8e3d5a8..a0d286f 100755 --- a/hbd +++ b/hbd @@ -26,6 +26,7 @@ import queue from hashlib import md5 import json import zlib +import codecs from subprocess import Popen, STDOUT, PIPE @@ -501,10 +502,11 @@ def updatecode(ucode, uname): except Exception as e: fail = "cannot read new code: %s" % e if not fail: - m = md5.new() - m.update(new_code) + m = md5() + new_codeE = new_code.encode() + m.update(new_codeE) icsum = m.hexdigest() - rmsg = {'csum': icsum, 'code': new_code.encode('base64','strict') } + rmsg = {'csum': icsum, 'code': codecs.encode(new_codeE, 'base64') } hbdclass.Host.hosts[uname].cmds.append(('UPD',rmsg)) return fail From b607e652fea8a1b72068cb87ae07b7bd49a7ea8f Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Tue, 7 Jan 2020 15:49:34 -0500 Subject: [PATCH 3/5] bump ver --- hbc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hbc b/hbc index 9ea624a..c47c4f1 100755 --- a/hbc +++ b/hbc @@ -23,7 +23,7 @@ PORT = 50003 INTERVAL = 10 REOPENC = 6 PIDFILE = '/tmp/hbc.pid' -VER = 5 +VER = 6 MAXRECV = 32767 running = True From 7cb3717176da357e72f84d17f542f252a54caa95 Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Wed, 15 Jan 2020 16:38:42 -0500 Subject: [PATCH 4/5] make nsupdate bin configurable --- hbd | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/hbd b/hbd index a0d286f..192a7bc 100755 --- a/hbd +++ b/hbd @@ -34,6 +34,8 @@ from subprocess import Popen, STDOUT, PIPE import hbdclass +NSUPDATE_BIN = "/usr/local/bin/nsupdate" # override in .hbrc possible + SEND_EMAIL=False SEND_PUSHOVER=True @@ -241,7 +243,7 @@ answer """ % D if DEBUG > 0: log(None, "DBG: nsup %s" % nsup) - cmd = ["/usr/local/bin/nsupdate", "-k", "/etc/dhcpc/K%(domain)s.+157+00000." % D, "-v"] + cmd = [nsupdate_bin, "-k", "/etc/dhcpc/K%(domain)s.+157+00000." % D, "-v"] if DEBUG > 0: log(None, "DBG: cmd %s" % cmd) try: p = Popen(cmd, shell=False, bufsize=1, stdin=PIPE, stdout=PIPE, stderr=STDOUT) @@ -251,9 +253,9 @@ answer return "nsupdate: some error occured" (output, err) = p.communicate(nsup.encode()) - if output.find('status: NOERROR') >= 0: + if output.decode().find('status: NOERROR') >= 0: return None - return output + return output.decode() # @@ -826,6 +828,7 @@ grace = GRACE watchhosts = [] dyndnshosts = [] drophosts = [] +nsupdate_bin = NSUPDATE_BIN try: f = open(configfile, "r") @@ -874,6 +877,8 @@ if f: dyndnshosts = a elif o == 'drophosts': drophosts = a + elif o == 'nsupdate_bin': + nsupdate_bin = a f.close() if len(args) != 0: From 439111f53f6288d1c5661c79aa1c913f9aa59734 Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Sun, 26 Jan 2020 14:37:31 -0500 Subject: [PATCH 5/5] force use of python3 --- hbc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hbc b/hbc index c47c4f1..ef4b1fb 100755 --- a/hbc +++ b/hbc @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # $Id: hbc,v 1.9 2012/03/29 02:08:36 andreas Exp $ # NEW import sys