File size: 3,228 Bytes
c44d66d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Import libraries
import os
import streamlit as st
import pandas as pd
import numpy as np
from PIL import Image
from streamlit_extras.switch_page_button import switch_page
from baam_functions import *
from pathlib import Path

# Set parent direction as current folder
sourceFileDir = Path(os.path.dirname(os.path.abspath(__file__))).parent.absolute()
os.chdir(sourceFileDir)

logo = Image.open('img/logo.png')
st.set_page_config(page_title = "BAAM", page_icon = logo)

def main():

    # Get user_dict & location from previous page
    user_dict = st.session_state['user_dict']
    location = st.session_state['location']
    score_dict = st.session_state['score_dict']
    risk_threshold = st.session_state['risk_threshold']

    # Get username from user_dict
    username = user_dict.get('username', '')

    # Header of the page
    col1, col2, col3 = st.columns([6,6,2])				
    with col1:
        st.subheader("Welcome " + username)
    with col2:
        st.write(' ')					
    with col3:
        st.image("img/Standard_Chartered.png", width=100)

    if not(score_dict):
        st.write('This is the 1st login time of this username.')

    else:

        device_score = score_dict.get('device_score', '')
        ip_score = score_dict.get('ip_score', '')
        location_score = score_dict.get('location_score', '')
        jump_score = score_dict.get('jump_score', '')
        vpn_score = score_dict.get('vpn_score', '')
        total_score = score_dict.get('total_score', '')

        # Show history
        col = ['login_time','device_name', 'device_uuid','mac_address', 'device_vendor', 'device_model', 'device_ram',\
        'ip_v4','ip_country', 'ip_region', 'ip_city', 'ip_lat', 'ip_lon', 'isp_name','isp_org',\
        'is_vpn', 'is_proxy', 'is_tor', 'is_relay',   \
            'lat', 'lon','suburb', 'district', 'city', 'country']

        user_db = pd.DataFrame(get_login_history(username)).T

        user_db.columns= col
        st.subheader("Historical data: ")
        st.write(user_db)
        print(user_db)

        # Display user's current information on the page
        st.subheader("Current login: ")
        show_test_data(user_dict, location)

        user_db['lat'] = pd.to_numeric(user_db['lat'])
        user_db['lon'] = pd.to_numeric(user_db['lon'])

        col1, col2 = st.columns([4,6])				
        with col1:		
            st.write('Device score', round(device_score))
            st.write('IP score', round(ip_score))
            st.write('Location score', round(location_score))
            st.write('Jump score', round(jump_score))
            st.write('VPN score', round(vpn_score))
            st.write('----------------------')
            st.write('Total score')
            st.write('device_score + ip_score + location_score - (jump_score + vpn_score)', round(total_score))

            if total_score > risk_threshold:
                st.write('Total score > Risk threshold')
                st.image("img/passed_da.png", width=200)
            else:
                st.write('Total score < Risk threshold')
                st.image("img/failed_da.png", width=200)
            
        with col2:
            st.map(user_db[['lat', 'lon']])

if __name__ == '__main__':
	main()