#!/usr/bin/env python3 # Author: Bandie Canis # License: 2-Clause BSD license import ssl, socket, subprocess, time, os, sys, getopt 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") + "]" return t def execFromConfig(option, pw=False): cfg = configparser.ConfigParser() cfg.read(CONFIG) if(pw): if(option == password): return 4 else: return 5 else: try: cmd = cfg.get("Commands", option).replace("\"", "").replace("\'", "") cmd = cmd.split(" ") try: subprocess.Popen(cmd) return 0 except FileNotFoundError: print(getTimestamp(), "Can't execute", cmd, ". File not found.") return 2 except configparser.NoOptionError: 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) print(getTimestamp(), "Incoming connection:", fromaddr[0]) connstream.send(b"OK 1337\n") con_loop = True while con_loop: global tmppw_on, pw_on, pwtimeout if('timeout' in locals() and timeout