-
-
Notifications
You must be signed in to change notification settings - Fork 330
/
Copy pathapp.py
142 lines (103 loc) · 2.97 KB
/
app.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python
# -*- coding: utf_8 -*-
"""The nodejsscan webapp."""
import re
import os
from flask import Flask, request
from nodejsscan.models import db
import nodejsscan.settings as settings
import nodejsscan.utils as utils
from web.upload import handle_upload
from web.git_utils import clone
from web.dashboard import (
home,
issue_hide,
issue_revert,
scan_delete,
scan_result,
scans,
search_file,
view_file,
)
app = Flask(__name__,
template_folder='../templates',
static_folder='../static')
app.url_map.converters['regex'] = utils.RegexConverter
app.config['UPLOAD_FOLDER'] = settings.UPLOAD_FOLDER
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get(
'SQLALCHEMY_DATABASE_URI', settings.SQLALCHEMY_DATABASE_URI)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
@app.template_filter('slugify')
def _slugify(string):
if not string:
return ''
return utils.slugify(string)
@app.template_filter('deslugify')
def _deslugify(string):
if not string:
return ''
return utils.deslugify(string)
@app.template_filter('relative')
def relative(string):
if not string:
return ''
result = re.compile(r'[A-Fa-f0-9]{64}[/\\]').search(string)
if not result:
return string
return string.split(result.group(0), 1)[1]
@app.context_processor
def _year():
return {'year': utils.year()}
@app.teardown_appcontext
def shutdown_session(exception=None):
"""Closes db session."""
db.session.remove()
@app.template_filter('js_escape')
def _js_escape(string):
if not string:
return ''
return utils.js_escape(string)
@app.route('/', methods=['GET'])
def index():
"""Handle Index."""
return home()
@app.route('/upload/', methods=['POST'])
def upload():
"""Upload and scan from zip."""
return handle_upload(app, request)
@app.route('/git/', methods=['POST'])
def git_clone():
"""Scan from git."""
return clone(request)
@app.route('/scans/', methods=['GET'])
def allscans():
"""Display list of scans."""
return scans()
@app.route('/scan/<regex(r\'[0-9a-f]{64}\'):sha2>/', methods=['GET'])
def scan(sha2):
"""Show a scan result."""
return scan_result(sha2)
@app.route('/delete_scan', methods=['POST'])
def delete_scan():
"""Delete Scan result."""
return scan_delete(request)
@app.route('/revert', methods=['POST'])
def revert():
"""Revert not an issue to issue."""
return issue_revert(request)
@app.route('/false_positive', methods=['POST'])
def false_positive():
"""Mark the issue as fasle_positive."""
return issue_hide(request, 'fp')
@app.route('/not_applicable', methods=['POST'])
def not_applicable():
"""Mark the issue as fasle_positive."""
return issue_hide(request, 'na')
@app.route('/view_file', methods=['POST'])
def view():
return view_file(request)
@app.route('/search', methods=['POST'])
def search():
"""Search in source files."""
return search_file(request)