From ae479275c654fe158ac831958cbd8aef7ca22b55 Mon Sep 17 00:00:00 2001 From: Jad Dina Date: Wed, 20 Nov 2024 20:09:09 -0700 Subject: [PATCH 1/4] added usb auth and permissions for state changes --- .../src/lib/hooks/useInteraction.ts | 95 +++-------- .../src/lib/hooks/usePocketbase.ts | 32 ++-- RocketControlUnitGUI/src/lib/message.ts | 60 +++++++ RocketControlUnitGUI/src/routes/+page.svelte | 16 +- backend/src/state_based_password.py | 154 ++++++++++++++++++ 5 files changed, 268 insertions(+), 89 deletions(-) create mode 100644 RocketControlUnitGUI/src/lib/message.ts create mode 100644 backend/src/state_based_password.py diff --git a/RocketControlUnitGUI/src/lib/hooks/useInteraction.ts b/RocketControlUnitGUI/src/lib/hooks/useInteraction.ts index 3e9614a..643d28a 100644 --- a/RocketControlUnitGUI/src/lib/hooks/useInteraction.ts +++ b/RocketControlUnitGUI/src/lib/hooks/useInteraction.ts @@ -1,6 +1,5 @@ -import { getModalStore, type ModalComponent, type ModalSettings } from '@skeletonlabs/skeleton'; +import { getModalStore, type ModalSettings } from '@skeletonlabs/skeleton'; import type { PocketbaseHook } from './usePocketbase'; -import PausablePromptModal, { type PausablePromptResponse } from '$lib/components/PausablePromptModal.svelte'; const stateToCommand: { [key: string]: string } = { RS_ABORT: 'RSC_ANY_TO_ABORT', @@ -23,13 +22,6 @@ const commandToState = Object.fromEntries( Object.freeze(stateToCommand); Object.freeze(commandToState); -interface LoadCellPromptStates { - [loadcell: string]: { - numberOfWeights: number, - onResume?: (loadcell: string) => void - } -} - export const useInteraction = (pocketbaseHook: PocketbaseHook) => { const modalStore = getModalStore(); @@ -60,8 +52,6 @@ export const useInteraction = (pocketbaseHook: PocketbaseHook) => { nextStatePending = ''; }; - let promptStates: LoadCellPromptStates = {} - const confirmRemoveWeight = (loadcell: string) => { const modal: ModalSettings = { type: 'confirm', @@ -79,6 +69,8 @@ export const useInteraction = (pocketbaseHook: PocketbaseHook) => { modalStore.trigger(modal); }; + let numberOfWeights = 0; + const promptEnterNumberOfWeights = (loadcell: string) => { const modal: ModalSettings = { type: 'prompt', @@ -87,17 +79,11 @@ export const useInteraction = (pocketbaseHook: PocketbaseHook) => { response: async (r: any) => { if (r) { // The modal was confirmed, set the number of weights - promptStates[loadcell] = { - numberOfWeights: parseInt(r) - }; - - if (promptStates[loadcell].numberOfWeights > 0) { + numberOfWeights = parseInt(r); + if (numberOfWeights > 0) { promptEnterWeight(loadcell); } } - else { - delete promptStates[loadcell]; - } } }; @@ -105,46 +91,28 @@ export const useInteraction = (pocketbaseHook: PocketbaseHook) => { }; const promptEnterWeight = (loadcell: string) => { - const modalComponent: ModalComponent = { - ref: PausablePromptModal, - props: { - heading: `Enter Weight (kg) (${promptStates[loadcell].numberOfWeights} remaining)`, - } - }; - - let shouldReRun = false; - const modal: ModalSettings = { - type: 'component', - component: modalComponent, - response: (res: PausablePromptResponse) => { - switch (res[0]) { - case 'submit': - // If this is the last weight, send the finish command - if (promptStates[loadcell].numberOfWeights === 1) { - pocketbaseHook.writeLoadCellCommand(loadcell, 'FINISH', parseFloat(res[1])); - - delete promptStates[loadcell]; - return; - } else { - // The modal was confirmed, send the calibrate command - pocketbaseHook.writeLoadCellCommand(loadcell, 'CALIBRATE', parseFloat(res[1])); - } - - // Decrease the number of weights and open the modal again if there are more weights to enter - promptStates[loadcell].numberOfWeights--; - if (promptStates[loadcell].numberOfWeights > 0) { - promptEnterWeight(loadcell); - } - - break; - case 'pause': - promptStates[loadcell].onResume = promptEnterWeight; - break; - default: // 'cancel' | undefined - pocketbaseHook.writeLoadCellCommand(loadcell, 'CANCEL', 0); - delete promptStates[loadcell]; - break; + type: 'prompt', + title: `Enter Weight (kg) (${numberOfWeights} remaining)`, + valueAttr: { type: 'text', required: true }, + response: async (r: any) => { + if (r) { + // If this is the last weight, send the finish command + if (numberOfWeights === 1) { + pocketbaseHook.writeLoadCellCommand(loadcell, 'FINISH', parseFloat(r)); + } else { + // The modal was confirmed, send the calibrate command + pocketbaseHook.writeLoadCellCommand(loadcell, 'CALIBRATE', parseFloat(r)); + } + + // Decrease the number of weights and open the modal again if there are more weights to enter + numberOfWeights--; + if (numberOfWeights > 0) { + promptEnterWeight(loadcell); + } + } else { + // The modal was cancelled, send a cancel command + pocketbaseHook.writeLoadCellCommand(loadcell, 'CANCEL', 0); } } }; @@ -152,18 +120,9 @@ export const useInteraction = (pocketbaseHook: PocketbaseHook) => { modalStore.trigger(modal); }; - const resumeConfirmRemoveWeight = (loadcell: string) => { - if (!promptStates[loadcell] || !promptStates[loadcell].onResume) { - confirmRemoveWeight(loadcell); - return; - } - - promptStates[loadcell].onResume!(loadcell); - } - return { confirmStateChange, instantStateChange, - resumeConfirmRemoveWeight, + confirmRemoveWeight }; }; diff --git a/RocketControlUnitGUI/src/lib/hooks/usePocketbase.ts b/RocketControlUnitGUI/src/lib/hooks/usePocketbase.ts index f4e3453..a1fd57c 100644 --- a/RocketControlUnitGUI/src/lib/hooks/usePocketbase.ts +++ b/RocketControlUnitGUI/src/lib/hooks/usePocketbase.ts @@ -1,27 +1,25 @@ import PocketBase from 'pocketbase'; import type { Timestamps } from '../timestamps'; import type { Stores } from '../stores'; -import { currentState } from '../stores'; +import {fetchPermission, fetchEmail, fetchPassword, getDecryption} from '$lib/message'; export type PocketbaseHook = ReturnType; export const usePocketbase = (timestamps: Timestamps, stores: Stores) => { - const pocketbase = new PocketBase('http://192.168.0.69:8090'); + const pocketbase = new PocketBase('http://localhost:8090'); const authenticate = async () => { - const email = import.meta.env.VITE_EMAIL; - const password = import.meta.env.VITE_PASSWORD; - + const email = await getDecryption(await fetchEmail()); + const password = await getDecryption(await fetchPassword()); + if (email && password) { pocketbase.authStore.clear(); await pocketbase.admins.authWithPassword(email, password); - return true; - } - + } return false; }; - + const sendHeartbeat = async () => { await pocketbase.collection('Heartbeat').create({ message: 'heartbeat' @@ -29,10 +27,17 @@ export const usePocketbase = (timestamps: Timestamps, stores: Stores) => { }; const writeStateChange = async (state: string) => { - await pocketbase.collection('CommandMessage').create({ - target: 'NODE_DMB', - command: state - }); + if(await getDecryption(await fetchPermission()) == "MasterKey"){ + await pocketbase.collection('CommandMessage').create({ + target: 'NODE_DMB', + command: state + }); + } + if(await getDecryption(await fetchPermission()) == "TesterKey"){ + //pass + //permission to change states is denied, + //writeStateChange will not be reassigned, state will not be changed + } }; const writeCommandMessage = async (target: string, command: string) => { @@ -175,7 +180,6 @@ export const usePocketbase = (timestamps: Timestamps, stores: Stores) => { // Subscribe to changes in the 'sys_state' collection pocketbase.collection('sys_state').subscribe('*', (e) => { stores.system_state.set(e.record.sys_state); - currentState.set(e.record.rocket_state); timestamps.sys_state = Date.now(); }); diff --git a/RocketControlUnitGUI/src/lib/message.ts b/RocketControlUnitGUI/src/lib/message.ts new file mode 100644 index 0000000..a0a9329 --- /dev/null +++ b/RocketControlUnitGUI/src/lib/message.ts @@ -0,0 +1,60 @@ + + export async function getDecryption(messageString: string){ + let decryptedText = ""; + let shift =3; + if(messageString == "usb drive not found"){ + return messageString; + } + for (let char of messageString) { + if (/[a-zA-Z]/.test(char)) { + const shiftBase = char === char.toUpperCase() ? 'A'.charCodeAt(0) : 'a'.charCodeAt(0); + const decryptedChar = String.fromCharCode(((char.charCodeAt(0) - shiftBase - shift + 26) % 26) + shiftBase); + decryptedText += decryptedChar; + } else { + decryptedText += char; + } + } + return decryptedText; + } + export async function fetchPermission() { + try { + const response = await fetch('http://127.0.0.1:5000/message'); + if (!response.ok) { + throw new Error('Network response was not ok'); + } + const data = await response.json(); + const serverResponse = data.permission; // Store the message + return serverResponse; // Return the message + } catch (error) { + console.error('Error:', error); + } + } + export async function fetchEmail() { + try { + const response = await fetch('http://127.0.0.1:5000/message'); + if (!response.ok) { + throw new Error('Network response was not ok'); + } + const data = await response.json(); + const serverResponse = data.email; // Store the message + return serverResponse; // Return the message + } catch (error) { + console.error('Error:', error); + } + } + export async function fetchPassword() { + try { + const response = await fetch('http://127.0.0.1:5000/message'); + if (!response.ok) { + throw new Error('Network response was not ok'); + } + const data = await response.json(); + const serverResponse = data.password; // Store the message + return serverResponse; // Return the message + } catch (error) { + console.error('Error:', error); + } + } + + + \ No newline at end of file diff --git a/RocketControlUnitGUI/src/routes/+page.svelte b/RocketControlUnitGUI/src/routes/+page.svelte index 31176b1..fd60894 100644 --- a/RocketControlUnitGUI/src/routes/+page.svelte +++ b/RocketControlUnitGUI/src/routes/+page.svelte @@ -7,7 +7,8 @@ import { useInteraction } from '$lib/hooks/useInteraction'; import { onMount } from 'svelte'; import { SlideToggle } from '@skeletonlabs/skeleton'; - + import {fetchPermission, getDecryption} from "$lib/message" + const timestamps = initTimestamps(); const stores = initStores(); const usePocketbaseHook = usePocketbase(timestamps, stores); @@ -25,7 +26,7 @@ const { confirmStateChange, instantStateChange, - resumeConfirmRemoveWeight + confirmRemoveWeight } = useInteractionHook; // Destructure stores for later use @@ -68,9 +69,9 @@ timer_remaining } = stores; + onMount(() => { let heartbeatInterval: NodeJS.Timeout; - // Handle pocketbase authentication const handleAuth = async () => { $auth = await authenticate(); @@ -137,6 +138,7 @@ window.removeEventListener('resize', handleResize); }; + }); $: ac1_display = $ac1_open === undefined ? 'N/A' : $ac1_open ? 'ON' : 'OFF'; @@ -463,7 +465,7 @@ class="btn btn-sm variant-filled-error" on:click={() => { writeLoadCellCommand("NOS1", "CANCEL", 0); - resumeConfirmRemoveWeight("NOS1");}} + confirmRemoveWeight("NOS1");}} > CAL @@ -485,7 +487,7 @@ class="btn btn-sm variant-filled-error" on:click={() => { writeLoadCellCommand("NOS2", "CANCEL", 0); - resumeConfirmRemoveWeight("NOS2");}} + confirmRemoveWeight("NOS2");}} > CAL @@ -507,7 +509,7 @@ class="btn btn-sm variant-filled-error" on:click={() => { writeLoadCellCommand("LAUNCHRAIL", "CANCEL", 0); - resumeConfirmRemoveWeight("LAUNCHRAIL");}} + confirmRemoveWeight("LAUNCHRAIL");}} > CAL @@ -604,7 +606,7 @@ - {#if $currentState == "RS_PRELAUNCH"} + {#if $currentState == "RS_PRELAUNCH" } @@ -488,7 +487,7 @@ class="btn btn-sm variant-filled-error" on:click={() => { writeLoadCellCommand("NOS2", "CANCEL", 0); - confirmRemoveWeight("NOS2");}} + resumeConfirmRemoveWeight("NOS2");}} > CAL @@ -510,7 +509,7 @@ class="btn btn-sm variant-filled-error" on:click={() => { writeLoadCellCommand("LAUNCHRAIL", "CANCEL", 0); - confirmRemoveWeight("LAUNCHRAIL");}} + resumeConfirmRemoveWeight("LAUNCHRAIL");}} > CAL diff --git a/backend/test/dumpy.py b/backend/test/dumpy.py deleted file mode 100644 index d061021..0000000 --- a/backend/test/dumpy.py +++ /dev/null @@ -1,213 +0,0 @@ -import time -from pocketbase import Client -import random -import concurrent.futures - -# Initialize PocketBase -pb = Client("http://127.0.0.1:8090") - -battery_data = ["INVALID", "GROUND", "ROCKET"] -random_bool = lambda: random.choice([True, False]) -random_int = lambda: random.randint(0, 100) - -coord_json = { - "degrees": random_int(), - "minutes": random_int(), -} - -gps_json = { - "altitude": random_int(), - "unit": random_int(), -} - - -# Define a function for each table -def baro_write(): - pb.collection("Baro").create( - { - "baro_pressure": random_int(), - "baro_temperature": random_int(), - } - ) - - -def battery_write(): - pb.collection("Battery").create( - { - "voltage": random_int(), - "power_source": random.choice(battery_data), - } - ) - - -def combustion_control_write(): - pb.collection("CombustionControlStatus").create( - { - "vent_open": random_int(), - "drain_open": random_int(), - "mev_open": random_bool(), - } - ) - - -def dmb_pressure_write(): - pb.collection("DmbPressure").create( - { - "upper_pv_pressure": random_int(), - } - ) - - -def gps_write(): - pb.collection("Gps").create( - { - "latitude": coord_json, - "longitude": coord_json, - "antenna_altitude": gps_json, - "geo_id_altitude": gps_json, - "total_altitude": gps_json, - "time": random_int(), - } - ) - - -def imu_write(): - pb.collection("Imu").create( - { - "accel_x": random_int(), - "accel_y": random_int(), - "accel_z": random_int(), - "gyro_x": random_int(), - "gyro_y": random_int(), - "gyro_z": random_int(), - "mag_x": random_int(), - "mag_y": random_int(), - "mag_z": random_int(), - } - ) - - -def lr_loadcell_write(): - pb.collection("LaunchRailLoadCell").create( - { - "rocket_mass": random_int(), - } - ) - -def nos_load_write(): - pb.collection("NosLoadCell").create( - { - "nos1_mass": random_int(), - "nos2_mass": random_int(), - } - ) - - -def pad_box_write(): - pb.collection("PadBoxStatus").create( - { - "continuity_1": random_bool(), - "continuity_2": random_bool(), - "box1_on": random_bool(), - "box2_on": random_bool(), - } - ) - - -def pbb_pressure_write(): - pb.collection("PbbPressure").create( - { - "ib_pressure": random_int(), - "lower_pv_pressure": random_int(), - } - ) - - -def pbb_temperature_write(): - pb.collection("PbbTemperature").create( - { - "ib_temperature": random_int(), - "pv_temperature": random_int(), - } - ) - - -def rcu_pressure_write(): - pb.collection("RcuPressure").create( - { - "pt1_pressure": random_int(), - "pt2_pressure": random_int(), - "pt3_pressure": random_int(), - "pt4_pressure": random_int(), - } - ) - - -def rcu_temperature_write(): - pb.collection("RcuTemperature").create( - { - "tc1_temperature": random_int(), - "tc2_temperature": random_int(), - } - ) - - -def relay_status_write(): - pb.collection("RelayStatus").create( - { - "ac1_open": random_bool(), - "ac2_open": random_bool(), - "pbv1_open": random_bool(), - "pbv2_open": random_bool(), - "pbv3_open": random_bool(), - "sol1_open": random_bool(), - "sol2_open": random_bool(), - "sol3_open": random_bool(), - "sol4_open": random_bool(), - "sol5_open": random_bool(), - "sol6_open": random_bool(), - "sol7_open": random_bool(), - "sol8a_open": random_bool(), - "sol8b_open": random_bool(), - } - ) - - -def sob_temperature_write(): - pb.collection("SobTemperature").create( - { - "tc1_temperature": random_int(), - "tc2_temperature": random_int(), - } - ) - - -# List of functions -functions = [ - baro_write, - battery_write, - combustion_control_write, - dmb_pressure_write, - gps_write, - imu_write, - lr_loadcell_write, - nos_load_write, - pad_box_write, - pbb_pressure_write, - pbb_temperature_write, - rcu_pressure_write, - rcu_temperature_write, - relay_status_write, - sob_temperature_write, -] - -# Create a ThreadPool -executor = concurrent.futures.ThreadPoolExecutor(max_workers=20) - -# Run all functions every 3 seconds -while True: - # Start a thread for each function - for function in functions: - executor.submit(function) - # Pause for 3 seconds - time.sleep(3) \ No newline at end of file diff --git a/backend/test/dumpy_reborn.py b/backend/test/dumpy_reborn.py index 35bce16..8a0dc6e 100644 --- a/backend/test/dumpy_reborn.py +++ b/backend/test/dumpy_reborn.py @@ -4,8 +4,8 @@ import concurrent.futures endpoint = "http://localhost:8090" -admin_email = "random@random.com" -admin_password = "testtest123" +admin_email = "test@test.com" +admin_password = "0123456789" # Initialize PocketBase pb = PocketBase(endpoint) @@ -13,9 +13,9 @@ # Authenticate admin_data = pb.admins.auth_with_password(admin_email, admin_password) -if not admin_data.is_valid: - print("Authentication failed") - exit() +# if not admin_data.is_valid: +# print("Authentication failed") +# exit() battery_data = ["INVALID", "GROUND", "ROCKET"] diff --git a/database/pb_migrations/1732397549_updated_Baro.js b/database/pb_migrations/1732397549_updated_Baro.js new file mode 100644 index 0000000..3d472ee --- /dev/null +++ b/database/pb_migrations/1732397549_updated_Baro.js @@ -0,0 +1,20 @@ +/// +migrate((db) => { + const dao = new Dao(db) + const collection = dao.findCollectionByNameOrId("2j2bfgv8i8le9vo") + + collection.createRule = "" + collection.updateRule = "" + collection.deleteRule = "" + + return dao.saveCollection(collection) +}, (db) => { + const dao = new Dao(db) + const collection = dao.findCollectionByNameOrId("2j2bfgv8i8le9vo") + + collection.createRule = null + collection.updateRule = null + collection.deleteRule = null + + return dao.saveCollection(collection) +}) diff --git a/database/pb_migrations/1732397558_updated_Battery.js b/database/pb_migrations/1732397558_updated_Battery.js new file mode 100644 index 0000000..2aed351 --- /dev/null +++ b/database/pb_migrations/1732397558_updated_Battery.js @@ -0,0 +1,20 @@ +/// +migrate((db) => { + const dao = new Dao(db) + const collection = dao.findCollectionByNameOrId("11ezzv9sbk3qspa") + + collection.createRule = "" + collection.updateRule = "" + collection.deleteRule = "" + + return dao.saveCollection(collection) +}, (db) => { + const dao = new Dao(db) + const collection = dao.findCollectionByNameOrId("11ezzv9sbk3qspa") + + collection.createRule = null + collection.updateRule = null + collection.deleteRule = null + + return dao.saveCollection(collection) +}) diff --git a/database/pb_migrations/1732397611_updated_CombustionControlStatus.js b/database/pb_migrations/1732397611_updated_CombustionControlStatus.js new file mode 100644 index 0000000..db3ab2f --- /dev/null +++ b/database/pb_migrations/1732397611_updated_CombustionControlStatus.js @@ -0,0 +1,20 @@ +/// +migrate((db) => { + const dao = new Dao(db) + const collection = dao.findCollectionByNameOrId("iem7zt60sts5imk") + + collection.createRule = "" + collection.updateRule = "" + collection.deleteRule = "" + + return dao.saveCollection(collection) +}, (db) => { + const dao = new Dao(db) + const collection = dao.findCollectionByNameOrId("iem7zt60sts5imk") + + collection.createRule = null + collection.updateRule = null + collection.deleteRule = null + + return dao.saveCollection(collection) +}) diff --git a/database/pb_migrations/1732397618_updated_CommandMessage.js b/database/pb_migrations/1732397618_updated_CommandMessage.js new file mode 100644 index 0000000..71ab970 --- /dev/null +++ b/database/pb_migrations/1732397618_updated_CommandMessage.js @@ -0,0 +1,20 @@ +/// +migrate((db) => { + const dao = new Dao(db) + const collection = dao.findCollectionByNameOrId("s3u9kc1izqjaeds") + + collection.createRule = "" + collection.updateRule = "" + collection.deleteRule = "" + + return dao.saveCollection(collection) +}, (db) => { + const dao = new Dao(db) + const collection = dao.findCollectionByNameOrId("s3u9kc1izqjaeds") + + collection.createRule = null + collection.updateRule = null + collection.deleteRule = null + + return dao.saveCollection(collection) +}) diff --git a/database/pb_migrations/1732397627_updated_DmbPressure.js b/database/pb_migrations/1732397627_updated_DmbPressure.js new file mode 100644 index 0000000..03d5867 --- /dev/null +++ b/database/pb_migrations/1732397627_updated_DmbPressure.js @@ -0,0 +1,20 @@ +/// +migrate((db) => { + const dao = new Dao(db) + const collection = dao.findCollectionByNameOrId("2oggvjgmpdoytyj") + + collection.createRule = "" + collection.updateRule = "" + collection.deleteRule = "" + + return dao.saveCollection(collection) +}, (db) => { + const dao = new Dao(db) + const collection = dao.findCollectionByNameOrId("2oggvjgmpdoytyj") + + collection.createRule = null + collection.updateRule = null + collection.deleteRule = null + + return dao.saveCollection(collection) +}) diff --git a/usb-backend/requirements.txt b/usb-backend/requirements.txt new file mode 100644 index 0000000..9f4d0c0 --- /dev/null +++ b/usb-backend/requirements.txt @@ -0,0 +1,2 @@ +Flask +Flask-Cors diff --git a/backend/src/state_based_password.py b/usb-backend/src/state_based_password.py similarity index 73% rename from backend/src/state_based_password.py rename to usb-backend/src/state_based_password.py index 70de30f..61bd3a0 100644 --- a/backend/src/state_based_password.py +++ b/usb-backend/src/state_based_password.py @@ -10,25 +10,10 @@ #allowing 'GET' cors = CORS(app, methods=['GET', 'POST']) -#this acquires the name of the usb we are looking for -def get_name_macos(): - - os.chdir('/Volumes') - List = os.listdir() - i = 0 - while i < len(List): - if (List[i] == 'Macintosh HD'): - del List[i:i+1] - continue - else: - if List[i] == "MASTER" or List[i] == "TESTER": - return List[i] - else: - i = i +1 - return None +usb_name = "MASTER" #lists usbs in the path provided in the parameter -def list_files_in_usb_macos(usb_path): +def list_files_in_usb(usb_path): try: # Check if the provided path exists if not os.path.exists(usb_path): @@ -75,6 +60,7 @@ def encrypt(text, shift): encrypted_text += char encrypted_list.append(encrypted_text) return encrypted_list + #finds usb for WINDOWS operating systems def find_specific_usb(volume_label): os_type = platform.system() @@ -119,38 +105,43 @@ def read_files_from_usb(usb_path): def send(): #This checks which os is being used by the user and calls the appropriate function if system[0] == "Darwin": - usb_name = get_name_macos() #calls the files listing function try: - if __name__ == "__main__": - usb_drive_path ='/Volumes/'+usb_name - list_files_in_usb_macos(usb_drive_path) - #calls the read file method - if __name__ == "__main__": - - usb_file_path = '/Volumes/'+ usb_name +'/' + list_files_in_usb_macos(usb_drive_path) # Linux/macOS example - password = read_file_from_usb(usb_file_path) - key = encrypt(password, 3) - return jsonify({'permission': key[0], 'email': key[1], 'password': key[2]}) + usb_drive_path ='/Volumes/'+usb_name + list_files_in_usb(usb_drive_path) + usb_file_path = '/Volumes/'+ usb_name +'/' + list_files_in_usb(usb_drive_path) # Linux/macOS example + password = read_file_from_usb(usb_file_path) + key = encrypt(password, 3) + return jsonify({'permission': key[0], 'email': key[1], 'password': key[2]}) #checks for type error,usb we searched for was not found except TypeError: return jsonify({'message' : "usb drive not found"}) #Checks which us WINDOWS is the os elif system[0] == "Windows": - if __name__ == "__main__": - volume_label = "MASTER" - usb_drive = find_specific_usb(volume_label) - print(usb_drive) - - if usb_drive: - password = read_files_from_usb(usb_drive) - key = encrypt(password, 3) - print(key) - return jsonify({'permission': key[0], 'email': key[1], 'password': key[2]}) - else: - return jsonify({'permission' : "usb drive not found"}) + usb_drive = find_specific_usb(usb_name) + print(usb_drive) + + if usb_drive: + password = read_files_from_usb(usb_drive) + key = encrypt(password, 3) + print(key) + return jsonify({'permission': key[0], 'email': key[1], 'password': key[2]}) + else: + return jsonify({'permission' : "usb drive not found"}) + + elif system[0] == "Linux": + try: + usb_drive_path ='/media/soar/'+usb_name + list_files_in_usb(usb_drive_path) + usb_file_path = '/media/soar/'+ usb_name +'/' + list_files_in_usb(usb_drive_path) # Linux/macOS example + password = read_file_from_usb(usb_file_path) + key = encrypt(password, 3) + return jsonify({'permission': key[0], 'email': key[1], 'password': key[2]}) + #checks for type error,usb we searched for was not found + except TypeError: + return jsonify({'message' : "usb drive not found"}) + #runs flask server - if __name__ == '__main__': app.run()