|
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 |
|
|
|
|
|
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) |
|
|
|
|
|
username = st.session_state['username'] |
|
raw_location = st.session_state['raw_location'] |
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
st.header('Testing tool') |
|
|
|
|
|
|
|
|
|
use_cases = ['','Real time','Custom','1', '2','3','4','5'] |
|
option = st.selectbox('Select test case',use_cases) |
|
|
|
|
|
if option == 'Real time': |
|
|
|
st.write('You selected use case:', option) |
|
|
|
|
|
login_time = datetime.datetime.now() |
|
|
|
|
|
|
|
user_dict, location = collect_data(username, raw_location, login_time) |
|
|
|
|
|
show_test_data(user_dict, location) |
|
|
|
|
|
submit_test_case(user_dict, location) |
|
|
|
elif option == '': |
|
st.warning('Please select use case') |
|
|
|
elif option == 'Custom': |
|
|
|
|
|
coor_input = st.text_input('Enter location (lattitude, longitude)') |
|
|
|
|
|
ip_v4 = st.text_input('Enter IP Address (IPv4) (eg. 123.20.144.183)') |
|
|
|
|
|
device_name = st.text_input('Enter Device Name (eg. Linhs-MacBook-Air-2.local)') |
|
|
|
|
|
mac_address = st.text_input('Enter Device Mac address (eg. 8c:7a:aa:f2:e5:88)') |
|
|
|
|
|
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)') |
|
|
|
|
|
if coor_input and ip_v4 and mac_address: |
|
|
|
|
|
login_time = datetime.datetime.now() |
|
|
|
|
|
collect_coor = lambda x : [i for i in re.split(",", x) if i != ""] |
|
coor = collect_coor(coor_input) |
|
lat = coor[0] |
|
lon = coor[1] |
|
|
|
|
|
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) |
|
|
|
|
|
location, suburb, district, city, country = get_location(lat, lon) |
|
|
|
|
|
device_vendor = get_from_api("https://api.macvendors.com/", mac_address) |
|
device_ram = str(round(psutil.virtual_memory().total / (1024.0 **3)))+" GB" |
|
|
|
|
|
user_dict = { |
|
"username": username, |
|
"login_time": login_time, |
|
|
|
"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 |
|
} |
|
|
|
|
|
st.session_state['location'] = location |
|
st.session_state['user_dict'] = user_dict |
|
|
|
|
|
show_test_data(user_dict, location) |
|
|
|
|
|
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=',') |
|
|
|
|
|
|
|
login_time = df[df['test_id'] == int(option)]['login_time'].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] |
|
|
|
|
|
user_dict = { |
|
"username": username, |
|
"login_time": login_time, |
|
|
|
"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)) |
|
|
|
|
|
show_test_data(user_dict, location) |
|
|
|
|
|
submit_test_case(user_dict, location) |