small changes to myserver

master
ademant 2019-11-08 21:29:47 +01:00
parent 90b51fea44
commit ae109055b9
1 changed files with 24 additions and 6 deletions

View File

@ -1,6 +1,23 @@
#!/usr/bin/env python
import socket, threading
import requests,threading,time,json,zlib,gnupg,socket,psutil,os,sys,pymysql,queue,numpy
gpg=gnupg.GPG()
pathname = os.path.dirname(sys.argv[0])
abspath=os.path.abspath(pathname)
configfile=abspath+"/config.json"
try:
cf=open(configfile,"r")
except:
cf=open(configfile+".template","r")
log_conf=json.load(cf)
cf.close()
parameter={"device":socket.gethostname(),"allowed_ip":{"127.0.0.1":"25A4CF79414F10FD"},"gpg_keyid":"25A4CF79414F10FD"}
for n in parameter:
if n in log_conf:
parameter[n]=log_conf[n]
class ClientThread(threading.Thread):
@ -36,12 +53,13 @@ tcpsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
tcpsock.bind((host,port))
while True:
tcpsock.listen(4)
print("\nListening for incoming connections...")
(clientsock, (ip, port)) = tcpsock.accept()
newthread = ClientThread(ip, port, clientsock)
newthread.start()
if ip in parameter["allowed_ip"]:
newthread = ClientThread(ip, port, clientsock)
newthread.start()
else:
clientsock.close()
print("Denied Access from ",ip)