diff options
author | Raúl Benencia <rul@kalgan.cc> | 2012-10-03 19:46:06 -0300 |
---|---|---|
committer | Raúl Benencia <rul@kalgan.cc> | 2012-10-03 19:46:06 -0300 |
commit | 9866dfb204b8bdbb5bf341204371a4e4e458a9c4 (patch) | |
tree | 4073e444214359403dee60b5a499642049749590 /pywhoisd.py | |
parent | 9ca5c7e07f1e5ab4a28c042a72a7f9f29b3426c5 (diff) |
Global refactoring
Diffstat (limited to 'pywhoisd.py')
-rwxr-xr-x | pywhoisd.py | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/pywhoisd.py b/pywhoisd.py index 11ad133..ec793e7 100755 --- a/pywhoisd.py +++ b/pywhoisd.py @@ -1,16 +1,18 @@ #!/usr/bin/python3 import configparser import concurrent.futures +import signal +import sys -import core -import model +from lib import core +from lib import model +from lib.config import Config class PyWhoisD(): """Main class. It reads the configuration options and starts the server""" def __init__(self): - self.config = configparser.ConfigParser() - self.config.read('pywhoisd.conf') + self.config = Config().parser self.data = None self.daemon = None @@ -19,17 +21,20 @@ class PyWhoisD(): self.executor = concurrent.futures.ThreadPoolExecutor(max_workers=2) - # What kind of storage are we using? + def signal_sigint(self, signal, frame): + print("[+] Received SIGINT signal. Aborting...") + + sys.exit(0) + + # What kind of storage are we using? def config_data(self): - """Config data sources. + """Config data sources.""" - At the moment only XML is supported. - """ - + #At the moment only XML is supported. mode = self.config['Storage']['mode'] if mode == 'xml': - self.data = model.DataXML(self.config) + self.data = model.DataXML() def config_daemon(self): """Config common information source for all configured servers""" @@ -53,12 +58,12 @@ class PyWhoisD(): """Sets up server configuration from config files""" if self.classic(): - self.classic_server = core.ClassicServer(self.config, self.daemon) + self.classic_server = core.ClassicServer(self.daemon) else: print("[+] Classic server is not enabled") if self.web(): - self.web_server = core.WebServer(self.config, self.daemon) + self.web_server = core.WebServer(self.daemon) else: print("[+] Web server is not enabled") @@ -77,11 +82,13 @@ class PyWhoisD(): def main(self): + signal.signal(signal.SIGINT, self.signal_sigint) + self.config_daemon() self.start_servers() # Wait for running server to finish. Probably never. - self.executor.shutdown() + # self.executor.shutdown() if __name__ == "__main__": pwd = PyWhoisD() |