-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
34 lines (25 loc) · 811 Bytes
/
server.py
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
import os, sys
from portsmith.log import Log
from portsmith.profiles import Profiles
from portsmith.knocklsiten import KnockListener
from portsmith.PortOpener import PortOpener
def checkConditions():
if(not os.geteuid() == 0):
print("run the server code as root")
sys.exit()
if(not os.path.isdir('/etc/portsmith.d/profiles/')):
print("generate profiles first ")
sys.exit()
def handleFirewall(input, config):
portOpener = PortOpener(input)
portOpener.waitForKnocks()
def knockHandler(output, profiles):
portOpener = PortOpener(output)
knockListener = KnockListener(logFile, profiles, portOpener)
knockListener.listenAndOpen()
def main(argv):
logFile = Log('/var/log/kern.log')
checkConditions()
knockHandler(os.fdopen(output, "w"), profiles)
if __name__ == '__main__':
main(sys.argv)