Improvement™
This commit is contained in:
parent
600524809c
commit
a7d27c5ee9
11
ding
11
ding
@ -7,7 +7,11 @@ import sys, ssl, socket, os
|
|||||||
import configparser
|
import configparser
|
||||||
|
|
||||||
|
|
||||||
global exitcode
|
host = None
|
||||||
|
port = 0
|
||||||
|
cafile = None
|
||||||
|
certfile = None
|
||||||
|
keyfile = None
|
||||||
exitcode = 1
|
exitcode = 1
|
||||||
|
|
||||||
def readConfig():
|
def readConfig():
|
||||||
@ -22,7 +26,6 @@ def readConfig():
|
|||||||
cfg.read(CONFIG)
|
cfg.read(CONFIG)
|
||||||
|
|
||||||
global host, port, cafile, certfile, keyfile
|
global host, port, cafile, certfile, keyfile
|
||||||
|
|
||||||
host = cfg.get("Client", "host")
|
host = cfg.get("Client", "host")
|
||||||
port = int(cfg.get("Client", "port"))
|
port = int(cfg.get("Client", "port"))
|
||||||
|
|
||||||
@ -38,7 +41,7 @@ def send(conn, cmd):
|
|||||||
|
|
||||||
conn.connect((host, port))
|
conn.connect((host, port))
|
||||||
buf = conn.recv(1024)
|
buf = conn.recv(1024)
|
||||||
if(buf == b"OK 1337\n"):
|
if(buf == b"OK 1337\n"):
|
||||||
conn.sendall(cmd)
|
conn.sendall(cmd)
|
||||||
buf = conn.recv(1024)
|
buf = conn.recv(1024)
|
||||||
if(buf == b"OK CMD"):
|
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)
|
print("The server seems to be crazy. Nothing sent.", file=sys.stderr)
|
||||||
|
|
||||||
conn.close()
|
conn.close()
|
||||||
|
quit(exitcode)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
27
dingd
27
dingd
@ -6,6 +6,20 @@
|
|||||||
import ssl, socket, subprocess, time, os, sys
|
import ssl, socket, subprocess, time, os, sys
|
||||||
import configparser
|
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():
|
def getTimestamp():
|
||||||
t = "[" + time.strftime("%Y-%m-%d %H:%M:%S") + "]"
|
t = "[" + time.strftime("%Y-%m-%d %H:%M:%S") + "]"
|
||||||
@ -13,14 +27,13 @@ def getTimestamp():
|
|||||||
|
|
||||||
def execFromConfig(option, pw=False):
|
def execFromConfig(option, pw=False):
|
||||||
cfg = configparser.SafeConfigParser()
|
cfg = configparser.SafeConfigParser()
|
||||||
cfg.read(CONFIG)
|
cfg.read(CONFIG)
|
||||||
|
|
||||||
if(pw):
|
if(pw):
|
||||||
if(option == password):
|
if(option == password):
|
||||||
return 4
|
return 4
|
||||||
else:
|
else:
|
||||||
return 5
|
return 5
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
@ -45,7 +58,7 @@ def main():
|
|||||||
while True:
|
while True:
|
||||||
newsocket, fromaddr = bindsocket.accept()
|
newsocket, fromaddr = bindsocket.accept()
|
||||||
try:
|
try:
|
||||||
connstream = context.wrap_socket(newsocket, server_side=True)
|
connstream = context.wrap_socket(newsocket, server_side=True)
|
||||||
print(getTimestamp(), "Incoming connection:", fromaddr[0])
|
print(getTimestamp(), "Incoming connection:", fromaddr[0])
|
||||||
connstream.send(b"OK 1337\n")
|
connstream.send(b"OK 1337\n")
|
||||||
|
|
||||||
@ -155,10 +168,10 @@ def init():
|
|||||||
print("Error: Can't bind for port number ", port, ". Permission denied.", sep="")
|
print("Error: Can't bind for port number ", port, ". Permission denied.", sep="")
|
||||||
quit(1)
|
quit(1)
|
||||||
|
|
||||||
print("Running dingd on ", host, ":", port,
|
print("Running dingd on ", host, ":", port,
|
||||||
"\nConfig: ", CONFIG,
|
"\nConfig: ", CONFIG,
|
||||||
"\nCAFile: ", cafile,
|
"\nCAFile: ", cafile,
|
||||||
"\nCertfile: ", certfile,
|
"\nCertfile: ", certfile,
|
||||||
"\nKeyfile: ", keyfile,
|
"\nKeyfile: ", keyfile,
|
||||||
"\nPassword lock: ", pw_on,
|
"\nPassword lock: ", pw_on,
|
||||||
"\nPassword timeout: ", pwtimeout,
|
"\nPassword timeout: ", pwtimeout,
|
||||||
|
Loading…
Reference in New Issue
Block a user