-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservermain.py
More file actions
80 lines (68 loc) · 2.49 KB
/
servermain.py
File metadata and controls
80 lines (68 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Server Main module
# OpenRS v 0.1.0
# Author: William Barr
#This is the entry point for the server.
import config
import logging
import sys
import threading
import sslserver
import multiprocessing
from multiprocessing import Manager, Process, Pipe
class ServerShellDisplayThread(threading.Thread):
def __init__(self, parentShellPipe):
super().__init__()
self.parentShellPipe = parentShellPipe
def run(self):
logger = multiprocessing.log_to_stderr()
stillRunning = True
while stillRunning:
data = str(self.parentShellPipe.recv())
if(data == "quit"):
stillRunning = False
logging.info("Shell: %s", data)
print(">> {0}".format(data))
logger.info("Server Shell Display Thread terminating.")
class ServerShellInputThread(threading.Thread):
def __init__(self, childShellPipe, childShellPipeLock, serverShellParentPipe):
super().__init__()
self.childShellPipe = childShellPipe
self.childShellPipeLock = childShellPipeLock
self.serverShellParentPipe = serverShellParentPipe
def run(self):
logger = multiprocessing.log_to_stderr()
stillRunning = True
with self.childShellPipeLock:
self.childShellPipe.send("Shell ready.")
while stillRunning:
cmd = input("\n")
cmd = cmd.strip()
if(cmd == "quit"):
stillRunning = False
if(cmd != ""):
logging.info(">> %s", cmd)
with self.childShellPipeLock:
self.childShellPipe.send(cmd)
serverShellParentPipe.send(cmd)
logger.info("Server Shell Input Thread terminating.")
if __name__ == "__main__":
## masterMgr = Manager()
##
## #Read the configuration file
config.readConfigFile()
logging.info("Config read.")
## parentShellPipe, childShellPipe = Pipe()
## childShellPipeLock = masterMgr.Lock()
## serverShellParentPipe, serverShellChildPipe = Pipe()
##
## #Start the interactive shell
## displayThread = ServerShellDisplayThread(parentShellPipe)
## displayThread.start()
## logger.debug("Shell display started.")
## inputThread = ServerShellInputThread(childShellPipe, childShellPipeLock, serverShellParentPipe)
## inputThread.start()
## logger.debug("Shell input started.")
#Fire up the server
serverThread = sslserver.ServerListener()
serverThread.start()
serverThread.join()