Linh Vuu
added files
c44d66d
raw history blame
No virus
8.71 kB
import os
import streamlit as st
from PIL import Image
from streamlit_extras.switch_page_button import switch_page
from baam_functions import *
from pathlib import Path
import re
import datetime
import pandas as pd
# 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)
# Get user_dict & location from previous page
username = st.session_state['username']
raw_location = st.session_state['raw_location']
# typing_speed = st.session_state['typing_speed']
# 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)
# Body of the page
# col1, col2 = st.columns(2)
# # Bank sidebar
# with col1:
# st.image("img/bank_sidebar.png")
# with col1:
st.header('Testing tool')
# new_title = '<p style="font-family:Roboto; font-size: 40px;">Testing tool</p>'
# st.markdown(new_title, unsafe_allow_html=True)
# Select box
use_cases = ['','Real time','Custom','1', '2','3','4','5']
option = st.selectbox('Select test case',use_cases)
# Select real time
if option == 'Real time':
st.write('You selected use case:', option)
# Record testing time
login_time = datetime.datetime.now()
# Collect user's information when logging in
# user_dict, location = collect_data(username, raw_location, login_time, typing_speed)
user_dict, location = collect_data(username, raw_location, login_time)
# Display user's current information on the page
show_test_data(user_dict, location)
# Submit button
submit_test_case(user_dict, location)
elif option == '':
st.warning('Please select use case')
elif option == 'Custom':
# Collect input as lat, long
coor_input = st.text_input('Enter location (lattitude, longitude)')
# Collect IPv4
ip_v4 = st.text_input('Enter IP Address (IPv4) (eg. 123.20.144.183)')
# Collect device name
device_name = st.text_input('Enter Device Name (eg. Linhs-MacBook-Air-2.local)')
# Collect mac address
mac_address = st.text_input('Enter Device Mac address (eg. 8c:7a:aa:f2:e5:88)')
# Collect other information
device_uuid = st.text_input('Enter Device UUID (eg. 24291951679256)')
device_model = st.text_input('Enter Device Model (eg. macOS-12.5.1-arm64-arm-64bit)')
# typing_speed = st.slider('Select username & password typing speed (characters per minute). Note: Average Typing Speed is between 190 and 200 characters per minute.', 0, 500)
if coor_input and ip_v4 and mac_address:
# Record testing time
login_time = datetime.datetime.now()
# Split lat, long from coor input
collect_coor = lambda x : [i for i in re.split(",", x) if i != ""]
coor = collect_coor(coor_input)
lat = coor[0]
lon = coor[1]
# Get information from IP
ip_country, ip_region, ip_city, ip_lat, ip_lon, isp_name, isp_org, is_vpn, is_proxy, is_tor, is_relay = get_ip_info(ip_v4)
# Get location from lat, long
location, suburb, district, city, country = get_location(lat, lon)
# Get device information from mac address
device_vendor = get_from_api("https://api.macvendors.com/", mac_address)
device_ram = str(round(psutil.virtual_memory().total / (1024.0 **3)))+" GB"
# Store everything in a dictionary
user_dict = {
"username": username,
"login_time": login_time,
# "typing_speed": typing_speed,
"device_name": device_name,
"device_uuid": device_uuid,
"mac_address": mac_address,
"device_vendor": device_vendor,
"device_model": device_model,
"device_ram": device_ram,
"ip_v4": ip_v4,
"ip_country": ip_country,
"ip_region": ip_region,
"ip_city": ip_city,
"ip_lat": ip_lat,
"ip_lon": ip_lon,
"isp_name": isp_name,
"isp_org": isp_org,
"is_vpn": is_vpn,
"is_proxy": is_proxy,
"is_tor": is_tor,
"is_relay": is_relay,
"lat": lat,
"lon": lon,
"suburb": suburb,
"district": district,
"city": city,
"country": country
}
# Update location, user_dict to pass to other pages
st.session_state['location'] = location
st.session_state['user_dict'] = user_dict
# Display user's current information on the page
show_test_data(user_dict, location)
# Submit button
submit_test_case(user_dict, location)
else:
st.write('You selected test case:', option)
if option == '1':
st.write('Case: Lili normal transaction')
elif option == '4':
st.write('Case: Scammer using Hong Kong VPN')
else:
st.write('Other cases, try your self!')
file_csv = 'test_cases.csv'
df = pd.read_csv(file_csv,sep=',')
# st.write(df)
# read data from a csv WHERE test_case = 'test case selected' to get the following information.
login_time = df[df['test_id'] == int(option)]['login_time'].values[0]
# typing_speed = df[df['test_id'] == int(option)]['typing_speed'].values[0]
device_name = df[df['test_id'] == int(option)]['device_name'].values[0]
device_uuid = df[df['test_id'] == int(option)]['device_uuid'].values[0]
mac_address = df[df['test_id'] == int(option)]['mac_address'].values[0]
device_vendor = df[df['test_id'] == int(option)]['device_vendor'].values[0]
device_model = df[df['test_id'] == int(option)]['device_model'].values[0]
device_ram = df[df['test_id'] == int(option)]['device_ram'].values[0]
ip_v4 = df[df['test_id'] == int(option)]['ip_v4'].values[0]
ip_country = df[df['test_id'] == int(option)]['ip_country'].values[0]
ip_region = df[df['test_id'] == int(option)]['ip_region'].values[0]
ip_city = df[df['test_id'] == int(option)]['ip_city'].values[0]
ip_lat = df[df['test_id'] == int(option)]['ip_lat'].values[0]
ip_lon = df[df['test_id'] == int(option)]['ip_lon'].values[0]
isp_name = df[df['test_id'] == int(option)]['isp_name'].values[0]
isp_org = df[df['test_id'] == int(option)]['isp_org'].values[0]
is_vpn = df[df['test_id'] == int(option)]['is_vpn'].values[0]
is_proxy = df[df['test_id'] == int(option)]['is_proxy'].values[0]
is_tor = df[df['test_id'] == int(option)]['is_tor'].values[0]
is_relay = df[df['test_id'] == int(option)]['is_relay'].values[0]
lat = df[df['test_id'] == int(option)]['lat'].values[0]
lon = df[df['test_id'] == int(option)]['lon'].values[0]
suburb = df[df['test_id'] == int(option)]['suburb'].values[0]
district = df[df['test_id'] == int(option)]['district'].values[0]
city = df[df['test_id'] == int(option)]['city'].values[0]
country = df[df['test_id'] == int(option)]['country'].values[0]
# Store everything in a dictionary
user_dict = {
"username": username,
"login_time": login_time,
# "typing_speed": typing_speed,
"device_name": device_name,
"device_uuid": device_uuid,
"mac_address": mac_address,
"device_vendor": device_vendor,
"device_model": device_model,
"device_ram": device_ram,
"ip_v4": ip_v4,
"ip_country": ip_country,
"ip_region": ip_region,
"ip_city": ip_city,
"ip_lat": ip_lat,
"ip_lon": ip_lon,
"isp_name": isp_name,
"isp_org": isp_org,
"is_vpn": is_vpn,
"is_proxy": is_proxy,
"is_tor": is_tor,
"is_relay": is_relay,
"lat": lat,
"lon": lon,
"suburb": suburb,
"district": district,
"city": city,
"country": country
}
location, suburb, district, city, country = get_location(str(lat), str(lon))
# Display user's current information on the page
show_test_data(user_dict, location)
# Submit button
submit_test_case(user_dict, location)