-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargus.py
executable file
·52 lines (38 loc) · 1.43 KB
/
argus.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
import sys, logging
from bottle import get, post, run, template, request, redirect, static_file
from lib.argus import Executor, Frequency, Checker
import config
ex = Executor(config.actions)
user = Checker(config.users)
f = Frequency()
@get('/')
def index():
return template('lib/argus', name='argus', target='/action/' + config.default_action)
@get('/assets/<filename>')
def server_static(filename):
return static_file(filename, root='public')
#@post('/login') # or @route('/login', method='POST')
@post('/action/<action>')
def do_login(action):
ip = request.get('REMOTE_ADDR')
if not f.limit(ip):
status, u = user.check(request.forms.get('username'), request.forms.get('password'))
if status:
f.clear(ip)
ex.run(action)
redirect("/")
else:
return "<p>Login failed.</p>"
else:
ex.execute('alarm_action')
return "<p>Login failed.</p>"
if __name__ == '__main__':
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format='%(asctime)s %(levelname)s -- : %(message)s')
logging.info('=== Start ' + config.name + ' ===')
logging.debug('This message should go to the log file')
#run(host=config.host, port=config.port, reloader=True)
run(host=config.host, port=config.port)
# Need gunicorn
#run(host=config.host, port=config.port, server='gunicorn', workers=1)