From a7d27c5ee9984b2af4bb4c41817aff92d0208e3d Mon Sep 17 00:00:00 2001 From: Bandie Date: Wed, 4 Apr 2018 16:24:52 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Improvement=E2=84=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ding | 11 +++++++---- dingd | 27 ++++++++++++++++++++------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/ding b/ding index 7c9b04e..bb6cf55 100755 --- a/ding +++ b/ding @@ -7,7 +7,11 @@ import sys, ssl, socket, os import configparser -global exitcode +host = None +port = 0 +cafile = None +certfile = None +keyfile = None exitcode = 1 def readConfig(): @@ -22,7 +26,6 @@ def readConfig(): cfg.read(CONFIG) global host, port, cafile, certfile, keyfile - host = cfg.get("Client", "host") port = int(cfg.get("Client", "port")) @@ -38,7 +41,7 @@ def send(conn, cmd): conn.connect((host, port)) buf = conn.recv(1024) - if(buf == b"OK 1337\n"): + if(buf == b"OK 1337\n"): conn.sendall(cmd) buf = conn.recv(1024) if(buf == b"OK CMD"): @@ -61,7 +64,7 @@ def send(conn, cmd): print("The server seems to be crazy. Nothing sent.", file=sys.stderr) conn.close() - + quit(exitcode) def main(): diff --git a/dingd b/dingd index 6db6dd1..f651945 100755 --- a/dingd +++ b/dingd @@ -6,6 +6,20 @@ import ssl, socket, subprocess, time, os, sys import configparser +CONFIG = None +host = None +port = 0 +cafile = None +certfile = None +keyfile = None +pw_on = None +password = None +pwtimeout = 30 +tmppw_on = None +context = None +bindsocket = None + + def getTimestamp(): t = "[" + time.strftime("%Y-%m-%d %H:%M:%S") + "]" @@ -13,14 +27,13 @@ def getTimestamp(): def execFromConfig(option, pw=False): cfg = configparser.SafeConfigParser() - cfg.read(CONFIG) + cfg.read(CONFIG) if(pw): if(option == password): return 4 else: - return 5 - + return 5 else: @@ -45,7 +58,7 @@ def main(): while True: newsocket, fromaddr = bindsocket.accept() try: - connstream = context.wrap_socket(newsocket, server_side=True) + connstream = context.wrap_socket(newsocket, server_side=True) print(getTimestamp(), "Incoming connection:", fromaddr[0]) connstream.send(b"OK 1337\n") @@ -155,10 +168,10 @@ def init(): print("Error: Can't bind for port number ", port, ". Permission denied.", sep="") quit(1) - print("Running dingd on ", host, ":", port, + print("Running dingd on ", host, ":", port, "\nConfig: ", CONFIG, - "\nCAFile: ", cafile, - "\nCertfile: ", certfile, + "\nCAFile: ", cafile, + "\nCertfile: ", certfile, "\nKeyfile: ", keyfile, "\nPassword lock: ", pw_on, "\nPassword timeout: ", pwtimeout, From 406accc71679d04a7ad913d3f9cdc25dd24da944 Mon Sep 17 00:00:00 2001 From: Bandie Date: Wed, 4 Apr 2018 16:33:36 +0200 Subject: [PATCH 2/3] Removing trailing whitespaces --- ding | 2 +- dingd | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ding b/ding index bb6cf55..ef1385d 100755 --- a/ding +++ b/ding @@ -41,7 +41,7 @@ def send(conn, cmd): conn.connect((host, port)) buf = conn.recv(1024) - if(buf == b"OK 1337\n"): + if(buf == b"OK 1337\n"): conn.sendall(cmd) buf = conn.recv(1024) if(buf == b"OK CMD"): diff --git a/dingd b/dingd index f651945..8b523c1 100755 --- a/dingd +++ b/dingd @@ -33,7 +33,7 @@ def execFromConfig(option, pw=False): if(option == password): return 4 else: - return 5 + return 5 else: @@ -52,13 +52,12 @@ def execFromConfig(option, pw=False): print(getTimestamp(), "No execution set:", option) return 1 - - + def main(): while True: newsocket, fromaddr = bindsocket.accept() try: - connstream = context.wrap_socket(newsocket, server_side=True) + connstream = context.wrap_socket(newsocket, server_side=True) print(getTimestamp(), "Incoming connection:", fromaddr[0]) connstream.send(b"OK 1337\n") From 9b03d6f928ff65f4c06758ab064c7a8bc2ba512f Mon Sep 17 00:00:00 2001 From: Bandie Date: Wed, 4 Apr 2018 16:39:23 +0200 Subject: [PATCH 3/3] Removing trailing whitespaces No 2 --- dingd | 1 - 1 file changed, 1 deletion(-) diff --git a/dingd b/dingd index 8b523c1..b5958cd 100755 --- a/dingd +++ b/dingd @@ -52,7 +52,6 @@ def execFromConfig(option, pw=False): print(getTimestamp(), "No execution set:", option) return 1 - def main(): while True: newsocket, fromaddr = bindsocket.accept()