Skip to content

Commit a8dec0c

Browse files
committed
UI/UX fixes
1 parent d2d2efe commit a8dec0c

File tree

5 files changed

+41
-52
lines changed

5 files changed

+41
-52
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Ignore packet dumps
2+
*.pcap
3+
*.pcapng
4+
15
*~
26
.*
37
!.gitattributes

src/libinspector/common.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,16 @@ def show_warning():
6161
else:
6262
# ID is missing or invalid -> BLOCK and show input form
6363
st.subheader("Prolific ID Required")
64-
st.warning("Please enter your Prolific ID to proceed. This ID is essential for data labeling.")
64+
st.warning("Please enter your Prolific ID to proceed. This ID is essential for data labeling and your payment.")
6565

6666
with st.form("prolific_id_form"):
6767
input_id = st.text_input(
68-
"Enter your Prolific ID (1-50 Alphanumeric Characters):",
68+
"Enter your Prolific ID:",
6969
value="",
7070
key="prolific_id_input"
7171
).strip()
7272

7373
submitted = st.form_submit_button("Submit ID")
74-
7574
if submitted:
7675
if is_prolific_id_valid(input_id):
7776
config_set("prolific_id", input_id)

src/libinspector/device_detail_page.py

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _send_packets_callback():
8585
_labeling_event_deque[-1]['end_time'] = int(time.time())
8686
st.session_state['end_time'] = _labeling_event_deque[-1]['end_time']
8787

88-
# st.rerun() will occur after this, showing the results.
88+
reset_labeling_state()
8989

9090

9191
def label_thread():
@@ -101,7 +101,7 @@ def label_thread():
101101
logger.info("[Packets] Will check if there are labeled packets to send...")
102102
# 1. Check if labeling session has ended
103103
if len(_labeling_event_deque) == 0:
104-
common.config_set('api_message', "warning| There is no labeling event ready. No packets sent.")
104+
common.config_set('api_message', "success| The packet collector thread is idle.")
105105
logger.info("[Packets] There is no labeling event ready. Not sending packets.")
106106
continue
107107
else:
@@ -110,14 +110,14 @@ def label_thread():
110110
# Make sure end time is NOT a none
111111
end_time = _labeling_event_deque[0].get('end_time', None)
112112
if end_time is None:
113-
common.config_set('api_message', "warning| The most recent labeling session doesn't have an end time set yet. Not sending packets yet.")
113+
common.config_set('api_message', "success| The packet collector thread is idle.")
114114
logger.info("[Packets] End time hasn't been set yet, The labeling session is still ongoing. Not sending packets yet.")
115115
continue
116116

117117
# If the labeling session is still ongoing, skip sending
118118
if time.time() <= end_time:
119119
logger.info("[Packets] Labeling session not complete yet. The end time is still in the future.")
120-
common.config_set('api_message', "warning| The labeling session is still ongoing as the end time is in the future. Not sending packets yet.")
120+
common.config_set('api_message', "warning| The packet collector thread is waiting for the labeling session to complete.")
121121
continue
122122

123123
# 2. Process and empty the queue
@@ -134,6 +134,13 @@ def label_thread():
134134

135135
payload = _labeling_event_deque.popleft()
136136
payload['packets'] = pending_packet_list
137+
138+
139+
device_name = payload.get('device_name', 'Unknown Device')
140+
activity_label = payload.get('activity_label', 'Unknown Activity')
141+
duration = payload.get('end_time', 0) - payload.get('start_time', 0)
142+
label_data = f"Device: {device_name}, Activity: {activity_label}, Duration: {duration} seconds, Packets: {len(pending_packet_list)}"
143+
137144
# 3. API Sending Logic - results are saved to api_message for display
138145
try:
139146
if len(pending_packet_list) > 0:
@@ -152,7 +159,7 @@ def label_thread():
152159
)
153160
if response.status_code == 200:
154161
logger.info(f"[Packets] {time.strftime('%Y-%m-%d %H:%M:%S')} - All packets sent successfully.")
155-
common.config_set('api_message', f"success| {len(pending_packet_list)} Labeled packets successfully sent to the server.")
162+
common.config_set('api_message', f"success| Labeled packets successfully sent to the server. \n {label_data}")
156163
else:
157164
logger.info(f"[Packets] {time.strftime('%Y-%m-%d %H:%M:%S')} - API Failed, packets NOT sent!.")
158165
common.config_set('api_message', f"error|Failed to send labeled packets. Server status: {response.status_code}. {len(pending_packet_list)} Packets were not sent.")
@@ -231,30 +238,12 @@ def label_activity_workflow(mac_address: str):
231238
Args:
232239
mac_address (str): The MAC address of the device targeted for the activity labeling.
233240
"""
234-
# --- 1. Permission Check ---
235-
if not st.session_state.get('external_data_permission_granted', False):
236-
# ... (Permission Check UI remains here) ...
237-
# [Content truncated for clarity, assuming original code is here]
238-
st.warning(
239-
"As part of this research project, only the network activity of the device you select will be shared with NYU mLab, and only while you are labeling an activity. "
240-
"By entering your Prolific ID and continuing, you agree to share this data for research and compensation. "
241-
"**Please confirm your Prolific ID is correct to ensure you receive payment for your participation.**"
242-
)
243-
prolific_id = common.config_get("prolific_id", "")
244-
if st.button("Continue", help="Click to confirm you have read and agree to the above statement."):
245-
if prolific_id.strip():
246-
st.session_state['external_data_permission_granted'] = True
247-
st.rerun()
248-
else:
249-
st.warning("Prolific ID is required to proceed.")
250-
return
251-
252-
# --- 2. Initialize State ---
241+
# --- 1. Initialize State ---
253242
for key in ['countdown', 'show_labeling_setup', 'start_time', 'end_time', 'device_name', 'activity_label']:
254243
if key not in st.session_state:
255244
st.session_state[key] = None if key in ['start_time', 'end_time', 'device_name', 'activity_label'] else False
256245

257-
# --- 3. Initial "Label" Button / State Check ---
246+
# --- 2. Initial "Label" Button / State Check ---
258247
session_active = common.config_get('labeling_in_progress', default=False)
259248

260249
if st.button(
@@ -272,7 +261,7 @@ def label_activity_workflow(mac_address: str):
272261
st.session_state['show_labeling_setup'] = True
273262
st.rerun() # Rerun to show setup menu
274263

275-
# --- 4. Label Setup UI (Persists through collection) ---
264+
# --- 3. Label Setup UI (Persists through collection) ---
276265
if st.session_state['show_labeling_setup'] or st.session_state['start_time']:
277266
st.subheader("1. Select Activity")
278267
activity_json = os.path.join(os.path.dirname(__file__), 'data', 'activity.json')
@@ -298,6 +287,7 @@ def label_activity_workflow(mac_address: str):
298287
disabled=is_currently_labeling)
299288

300289
activity_labels = activity_data[selected_category][selected_device]
290+
activity_labels.append("Idle Time: No Activity, just background traffic for 2 minutes")
301291
selected_label = st.selectbox("Select activity label",
302292
activity_labels,
303293
key="label_select",
@@ -335,7 +325,7 @@ def label_activity_workflow(mac_address: str):
335325
# The logic for displaying the API message has been moved into this fragment,
336326
display_api_status()
337327

338-
# --- 5. Countdown Logic (Blocking, happens between Start and Collection) ---
328+
# --- 4. Countdown Logic (Blocking, happens between Start and Collection) ---
339329
if st.session_state['countdown']:
340330
countdown_placeholder = st.empty()
341331
for i in range(5, 0, -1):
@@ -351,17 +341,6 @@ def label_activity_workflow(mac_address: str):
351341
st.info("Packet collection is **ACTIVE**. Perform the activity on your device now.")
352342
st.rerun() # Rerun to update button state and message
353343

354-
# --- 6. Final Results and Display ---
355-
if st.session_state['end_time']:
356-
st.header("Labeling Session Complete")
357-
st.markdown(f"**Device:** `{st.session_state.get('device_name')}`")
358-
st.markdown(f"**Activity:** `{st.session_state.get('activity_label')}`")
359-
duration = st.session_state['end_time'] - (st.session_state['start_time'] or st.session_state['end_time'])
360-
st.markdown(f"**Duration:** {duration} seconds")
361-
st.button("Reset Labeling",
362-
on_click=reset_labeling_state,
363-
help="Click to reset the labeling session and start over.")
364-
365344

366345
def save_labeled_activity_packets(pkt):
367346
"""

src/libinspector/device_list_page.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ def worker_thread():
5454
custom_name = api_output["Vendor"]
5555
if api_output["Vendor"] != "":
5656
common.config_set(custom_name_key, custom_name)
57+
else:
58+
# If API is down, just try using OUI vendor
59+
common.config_set(custom_name_key, meta_data.get('oui_vendor', 'Unknown Device, likely a Mobile Phone'))
5760
except Exception as e:
5861
logger.info("[Device ID API] Exception when calling API: %s", str(e))
5962
continue
@@ -214,8 +217,13 @@ def show_device_card(device_dict: dict):
214217
# --- Add bar charts for upload/download ---
215218
now = int(time.time())
216219
df_upload_bar_graph, df_download_bar_graph = common.bar_graph_data_frame(device_dict['mac_address'], now)
217-
common.plot_traffic_volume(df_upload_bar_graph, now, "Upload Traffic (sent by device) in the last 60 seconds")
218-
common.plot_traffic_volume(df_download_bar_graph, now,"Download Traffic (received by device) in the last 60 seconds")
220+
chart_col_upload, chart_col_download = st.columns(2)
221+
with chart_col_upload:
222+
common.plot_traffic_volume(df_upload_bar_graph, now,
223+
"Upload Traffic (sent by device) in the last 60 seconds")
224+
with chart_col_download:
225+
common.plot_traffic_volume(df_download_bar_graph, now,
226+
"Download Traffic (received by device) in the last 60 seconds")
219227

220228
# Set whether a device is to be inspected, favorite, or blocked
221229
with c2:

src/libinspector/sidebar.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44

55
def show():
66
"""
7-
This page shows a toggle to connect to IoT Inspector cloud.
87
This will generate a list of all favorite devices found in IoT Inspector derived from config.json
98
"""
10-
with st.container(border=True):
11-
st.toggle(
12-
"Connect to the IoT Inspector Cloud for enhanced features (Recommended)",
13-
key='connect_to_nyu_inspector_cloud',
14-
value=common.config_get('connect_to_nyu_inspector_cloud', False),
15-
help="Toggle ON if you need help with identifying devices and detecting anonymous devices and activities, but provided that you are okay with IoT Inspector sharing anonymous data with New York University researchers.",
16-
on_change=lambda: common.config_set('connect_to_nyu_inspector_cloud', st.session_state['connect_to_nyu_inspector_cloud'])
17-
)
9+
#with st.container(border=True):
10+
# st.toggle(
11+
# "Connect to the IoT Inspector Cloud for enhanced features (Recommended)",
12+
# key='connect_to_nyu_inspector_cloud',
13+
# value=common.config_get('connect_to_nyu_inspector_cloud', False),
14+
# help="Toggle ON if you need help with identifying devices and detecting anonymous devices and activities, but provided that you are okay with IoT Inspector sharing anonymous data with New York University researchers.",
15+
# on_change=lambda: common.config_set('connect_to_nyu_inspector_cloud', st.session_state['connect_to_nyu_inspector_cloud'])
16+
#)
1817
show_favorite_device_list()
1918

2019

0 commit comments

Comments
 (0)