3 Commits

3 changed files with 52 additions and 20 deletions

34
ding
View File

@ -3,7 +3,7 @@
# Author: Bandie Canis
# License: 2-Clause BSD License
import sys, ssl, socket, os
import sys, ssl, socket, os, getopt
import configparser
@ -14,14 +14,17 @@ certfile = None
keyfile = None
exitcode = 1
def readConfig():
def init(conf):
if(os.name == 'nt'):
CONFIG = "ding.win.cfg"
if(conf == None):
if(os.name == 'nt'):
CONFIG = "ding.win.cfg"
else:
CONFIG = "ding.cfg"
else:
CONFIG = "ding.cfg"
CONFIG = conf
cfg = configparser.SafeConfigParser()
cfg = configparser.ConfigParser()
try:
cfg.read(CONFIG)
@ -67,7 +70,7 @@ def send(conn, cmd):
quit(exitcode)
def main():
def main(arg):
try:
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
context.verify_mode = ssl.CERT_REQUIRED
@ -85,7 +88,7 @@ def main():
try:
send(conn, bytes(sys.argv[1], sys.stdin.encoding))
send(conn, bytes(arg[0], sys.stdin.encoding))
except IndexError:
print(sys.argv[0], ": Missing argument.\nSyntax: ", sys.argv[0], " <COMMAND>", file=sys.stderr)
except ConnectionRefusedError:
@ -98,7 +101,16 @@ def main():
if(__name__ == "__main__"):
readConfig()
main()
quit(exitcode)
try:
conf = None
opts, args = getopt.getopt(sys.argv[1:], "c:")
for o, a in opts:
if o == "-c":
conf = a
init(conf)
main(args)
except getopt.GetoptError as e:
print("Error using options. Allowed options:\n-c [FILE] - Config file\n")
quit(2)
quit(exitcode)

28
dingd
View File

@ -3,7 +3,7 @@
# Author: Bandie Canis
# License: 2-Clause BSD license
import ssl, socket, subprocess, time, os, sys
import ssl, socket, subprocess, time, os, sys, getopt
import configparser
CONFIG = None
@ -26,7 +26,7 @@ def getTimestamp():
return t
def execFromConfig(option, pw=False):
cfg = configparser.SafeConfigParser()
cfg = configparser.ConfigParser()
cfg.read(CONFIG)
if(pw):
@ -107,16 +107,19 @@ def main():
except EOFError:
print(getTimestamp(), "EOF")
def init():
def init(cfg=None):
global CONFIG, host, port, cafile, certfile, keyfile, pw_on, password, pwtimeout, tmppw_on, context, bindsocket
if(os.name == 'nt'):
CONFIG = "dingd.win.cfg"
if(cfg==None):
if(os.name == 'nt'):
CONFIG = "dingd.win.cfg"
else:
CONFIG = "dingd.cfg"
else:
CONFIG = "dingd.cfg"
CONFIG = cfg
cfg = configparser.SafeConfigParser()
cfg = configparser.ConfigParser()
cfg.read(CONFIG)
try:
@ -176,10 +179,17 @@ def init():
if(__name__ == "__main__"):
try:
init()
conf = None
opts, args = getopt.getopt(sys.argv[1:], "c:")
for o, a in opts:
if o == "-c":
conf = a
init(conf)
main()
except getopt.GetoptError as e:
print("Error using options. Allowed options:\n-c [FILE] - Config file\n")
quit(2)
except KeyboardInterrupt:
print("\r\rServer stopped.")

10
systemd/dingd.service Normal file
View File

@ -0,0 +1,10 @@
[Unit]
Description=dingd Service
[Service]
ExecStart=/root/ding/dingd -c /path/to/config/file/dingd.cfg
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=default.target