This repository was archived by the owner on Oct 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathrun.py
executable file
·109 lines (91 loc) · 3.49 KB
/
run.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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!flask/bin/python
from werkzeug.exceptions import HTTPException
from flask import Flask,jsonify,render_template, request
from flask_restful import Resource, Api
from traceback import format_exc
import app.modules.handler as handler
import app.modules.apikeymgmt as keymgmt
import app.modules.firewalls as firewalls
import app.modules.status as status
import ConfigParser, os
import logging
import bs4
#Read configuration file
config = ConfigParser.RawConfigParser()
try:
config.read('/etc/assimilator/assimilator.conf')
LOG_FILE = config.get('General','logfile')
LOG_LEVEL = config.get('General','loglevel')
assert LOG_LEVEL in ['DEBUG', 'INFO', 'WARN', 'ERROR', 'CRIT', 'FATAL']
if LOG_LEVEL == 'DEBUG':
LOG_LEVEL = logging.DEBUG
elif LOG_LEVEL == 'INFO':
LOG_LEVEL = logging.INFO
elif LOG_LEVEL == 'WARN':
LOG_LEVEL = logging.WARNING
elif LOG_LEVEL == 'ERROR':
LOG_LEVEL = logging.ERROR
elif LOG_LEVEL == 'CRIT':
LOG_LEVEL = logging.CRITICAL
elif LOG_LEVEL == 'FATAL':
LOG_LEVEL = logging.FATAL
datefmt = config.get('General','format')
except Exception as e:
print "Error parsing configuration file: {0}".format(str(e))
quit()
logging.getLogger("requests").setLevel(logging.ERROR)
logging.getLogger("bs4").setLevel(logging.ERROR)
#Logging configuration
logging.basicConfig(filename=LOG_FILE,level=LOG_LEVEL,format='%(asctime)s - %(levelname)s - %(message)s', datefmt=datefmt)
app = Flask(__name__)
api = Api(app)
#Error handling
@app.errorhandler(Exception)
def handle_error(e):
logging.critical(str(format_exc()) + '\n' + str(e))
code = 500
if isinstance(e, HTTPException):
code = e.code
return jsonify(error='Unknown Error'), code
#API Keys management
api.add_resource(keymgmt.mgmt, '/keymgmt/<int:id>')
api.add_resource(keymgmt.mgmt_all, '/keymgmt')
api.add_resource(keymgmt.generate, '/keymgmt/generate')
#Firewall Management
api.add_resource(firewalls.firewalls, '/firewalls/<string:site>')
api.add_resource(firewalls.firewalls_all, '/firewalls')
#API REST Resources
#List Firewalls
api.add_resource(handler.listfirewalls, '/api/listfirewalls')
#STATUS
api.add_resource(status.status, '/api/status')
#CONFIG
api.add_resource(handler.config, '/api/<string:firewall>/config')
#RULES
api.add_resource(handler.rules, '/api/<string:firewall>/rules')
api.add_resource(handler.rules_move, '/api/<string:firewall>/rules/move')
api.add_resource(handler.rules_rename, '/api/<string:firewall>/rules/rename')
api.add_resource(handler.rules_match, '/api/<string:firewall>/rules/match')
#INTERFACES
api.add_resource(handler.interfaces, '/api/<string:firewall>/interfaces')
#OBJECTS
api.add_resource(handler.objects, '/api/<string:firewall>/objects/<string:object>')
api.add_resource(handler.objects_rename, '/api/<string:firewall>/objects/<string:object>/rename')
#ROUTE
api.add_resource(handler.route, '/api/<string:firewall>/route')
#api.add_resource(handler.route_match, '/api/<string:brand>/<string:firewall>/route/match')
####Device Specific####
##Palo Alto##
#LOCK
api.add_resource(handler.lock, '/api/<string:firewall>/locks')
api.add_resource(handler.lock_option, '/api/<string:firewall>/locks/<string:option>')
api.add_resource(handler.lock_admin, '/api/<string:firewall>/locks/<string:option>/<string:admin>')
#COMMIT
api.add_resource(handler.commit, '/api/<string:firewall>/commit')
#LOGGING
api.add_resource(handler.logging, '/api/<string:firewall>/logging')
##Palo Alto##
#Hitcount
api.add_resource(handler.hitcount, '/api/<string:firewall>/rules/hitcount')
if __name__ == '__main__':
app.run(host='0.0.0.0',debug=False)