Permalink
Browse files

Add help message and avoid multiple launch of same component in screen

  • Loading branch information...
root
root committed Jul 13, 2018
1 parent 1ad1ad3 commit ae2fdf587deee45e7af520fd31bc2a6acfb5d62c
Showing with 37 additions and 23 deletions.
  1. +3 −3 config.default.yml
  2. +20 −1 osfw.py
  3. +14 −19 run.sh
@@ -19,16 +19,16 @@ workers: 8
# Time interval between each refresh cycle
refreshDelay: 14400

# Settings related to HTTP(S) requests (to fetch feeds)
# Settings related to DNS and HTTP(S) requests (to fetch feeds)
queryTimeout: 10
queryUserAgent: UPPERSAFE-OSFW (UPPERSAFE Open Source Firewall) https://github.com/dev2lead/uppersafe-osfw

# Group IP range (if set to no each IP range will be converted to a list of IP addresses)
groupRange: yes

# Settings related to filtering (classic|forward)
# classic = filter traffic based on the INPUT chain and OUTPUT chain of iptables
# forward = filter traffic based only the FORWARD chain of iptables
# In classic mode, filtering is based on the INPUT chain and OUTPUT chain of iptables
# In forward mode, filtering is only based on the FORWARD chain of iptables
filterMode: classic

# Location of the file where the threats list must be saved (only used in server mode)
21 osfw.py
@@ -8,19 +8,38 @@
import sys, unittest, importlib
from tests import *

HELP = '''
|------------------------------------------------------------------------------|
| Usage: bash run.sh [cmd] |
|------------------------------------------------------------------------------|
|---------------|--------------------------------------------------------------|
| Command | Description |
|---------------|--------------------------------------------------------------|
| daemon/sensor | Launch the firewall sensor component |
| daemon/syncfw | Launch the firewall core component |
| webapp | Launch the web server component |
|---------------|--------------------------------------------------------------|
'''

def main():
if len(sys.argv) == 2 and "daemon/sensor" in sys.argv:
daemon = importlib.import_module("daemon.sensor")
daemon.sensor()
return 0
if len(sys.argv) == 2 and "daemon/syncfw" in sys.argv:
daemon = importlib.import_module("daemon.syncfw")
daemon.syncfw()
return 0
if len(sys.argv) == 2 and "webapp" in sys.argv:
webapp = importlib.import_module("webapp")
webapp.app.run(webapp.conf.get("host"), webapp.conf.get("port"))
return 0
if len(sys.argv) == 2 and "assert" in sys.argv:
unittest.main(argv=sys.argv[0:1])
return 0
return 0
print(HELP.strip())
return 1

if __name__ == "__main__":
main()
33 run.sh
@@ -15,25 +15,20 @@ export LC_ALL="C.UTF-8"
export LANG="C.UTF-8"

if [ -z "$1" ]; then
screen -dmS osfw-sensor bash run.sh daemon/sensor
screen -dmS osfw-syncfw bash run.sh daemon/syncfw
screen -dmS osfw-webapp bash run.sh webapp
fi

if [ "$1" == "daemon/sensor" ]; then
python osfw.py daemon/sensor
fi

if [ "$1" == "daemon/syncfw" ]; then
python osfw.py daemon/syncfw
fi

if [ "$1" == "webapp" ]; then
python osfw.py webapp
fi

if [ "$1" == "assert" ]; then
python osfw.py assert
RESULT=`find /var/run/screen -name "*.osfw-sensor"`
if [ -z "$RESULT" ]; then
screen -dmS osfw-sensor python osfw.py daemon/sensor
fi
RESULT=`find /var/run/screen -name "*.osfw-syncfw"`
if [ -z "$RESULT" ]; then
screen -dmS osfw-syncfw python osfw.py daemon/syncfw
fi
RESULT=`find /var/run/screen -name "*.osfw-webapp"`
if [ -z "$RESULT" ]; then
screen -dmS osfw-webapp python osfw.py webapp
fi
else
python osfw.py "$1"
fi

popd > /dev/null 2>&1

0 comments on commit ae2fdf5

Please sign in to comment.