-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
94 lines (67 loc) · 2.94 KB
/
__init__.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
from flask import Flask, request, render_template, jsonify
from py.kflow_main import uploadFile, listFiles, getJsonFile
from py.kflow_main import generateCallFlowFilter, extractCalls
app = Flask(__name__)
@app.route('/')
def index():
files = listFiles()
return render_template('index.html', files=files)
@app.route('/pcapupload', methods=['POST'])
def upload():
uploadResponse = uploadFile()
return uploadResponse
@app.route('/calls')
def kflow():
pcapName = request.args.get('pcapname')
if pcapName is not None:
callFlows = extractCalls(pcapName)
if len(callFlows) < 5:
display_filter = 'sip'
flowTxtPath, jsonName = generateCallFlowFilter(pcapName, display_filter)
with open(flowTxtPath, 'r') as f:
flowText = f.read()
return render_template('kflow.html', flowText = flowText, pcapName = pcapName, jsonName = jsonName)
else:
return "Error: 'filename' parameter is missing from the URL"
return render_template('calls.html', pcapName = pcapName, callFlows = callFlows)
@app.route('/filtered-calls', methods=['POST'])
def submit():
# Access form data from the request object
pcapName = request.form['pcap_name']
call_ids = request.form.getlist('call_ids') # Get the list of selected call IDs
display_filter = f'sip.Call-ID == "{call_ids[0]}"' # Initialize with the first call ID
for call_id in call_ids[1:]:
display_filter += f' || sip.Call-ID == "{call_id}"' # Add OR conditions for each subsequent call ID
flowTxtPath, jsonName = generateCallFlowFilter(pcapName, display_filter)
with open(flowTxtPath, 'r') as f:
flowText = f.read()
return render_template('kflow.html', flowText = flowText, pcapName = pcapName, jsonName = jsonName)
@app.route('/get_json')
def get_json():
jsonName = request.args.get('json')
if jsonName is None:
return "Error: 'filename' parameter is missing from the URL"
flowJson = getJsonFile(jsonName)
return jsonify(flowJson)
# @kFlow.route('/kflow')
# def kflow():
# pcapName = request.args.get('pcapname')
# cidNo = request.args.get('cid-no')
# if pcapName is not None:
# flowText = getFlowText(pcapName)
# loadCidList = load_list_from_pkl(pcapName+'.cid.pkl')
# else:
# return "Error: 'filename' parameter is missing from the URL"
# if cidNo is not None:
# cidSr = int(cidNo) - 1
# flowText = generateFilterredCallIdFlow(pcapName, loadCidList[cidSr], cidSr)
# return render_template('kflow.html', flowText = flowText, pcapName = pcapName, loadCidList = loadCidList)
# @kFlow.route('/get_json')
# def get_json():
# pcapName = request.args.get('pcapname')
# if pcapName is None:
# return "Error: 'filename' parameter is missing from the URL"
# flowJson = getJsonFile(pcapName)
# return jsonify(flowJson)
if __name__ == '__main__':
app.run(debug=True)