diff --git a/control_mqtt.py b/control_mqtt.py index 94b4482..a88f60b 100755 --- a/control_mqtt.py +++ b/control_mqtt.py @@ -35,7 +35,7 @@ class CurrentClients: def start_client(self, client, args): process = subprocess.Popen( - [f'{self.venv_path}/bin/python3', args.ase_receiver, client], + [f'{self.venv_path}/bin/python3 {args.ase_receiver} {client}'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True @@ -82,7 +82,7 @@ def ctrl_client_mod(client, userdata, message): def get_credentials(args): url = args.wallet + "get" data = { - "master_password": "Ase#2024@wallet!", + "master_password": os.getenv('WALLET_MASTER_PASSWORD'), "site": "mqtt_control" } response = requests.post(url, json=data) diff --git a/password_wallet_api.py b/password_wallet_api.py index 23c688d..ed265a0 100644 --- a/password_wallet_api.py +++ b/password_wallet_api.py @@ -75,6 +75,23 @@ def get_password(site, cipher): return username, decrypted_password return None, None +# Cancella una password dal database +def delete_password(site): + conn = sqlite3.connect(db_file) + cursor = conn.cursor() + cursor.execute("DELETE FROM passwords WHERE site = ?", (site,)) + conn.commit() + conn.close() + +# Ottieni la lista di tutti i siti +def list_sites(): + conn = sqlite3.connect(db_file) + cursor = conn.cursor() + cursor.execute("SELECT site FROM passwords") + sites = [row[0] for row in cursor.fetchall()] + conn.close() + return sites + # Endpoint per aggiungere una password @app.route('/add', methods=['POST']) def add_password_api(): @@ -109,6 +126,29 @@ def get_password_api(): return jsonify({"site": site, "username": username, "password": password}) +# Endpoint per cancellare una password +@app.route('/delete', methods=['POST']) +def delete_password_api(): + master_password = request.json.get('master_password') + site = request.json.get('site') + + if not authenticate(master_password): + return jsonify({"error": "Master password errata"}), 403 + + delete_password(site) + return jsonify({"message": "Password cancellata con successo"}) + +# Endpoint per listare tutti i siti +@app.route('/list', methods=['POST']) +def list_sites_api(): + master_password = request.json.get('master_password') + + if not authenticate(master_password): + return jsonify({"error": "Master password errata"}), 403 + + sites = list_sites() + return jsonify({"sites": sites}) + # Avvio dell'app if __name__ == '__main__': init_db() diff --git a/services/mqtt_ase_receiver.service b/services/mqtt_ase_receiver.service index 1655b16..97958d1 100644 --- a/services/mqtt_ase_receiver.service +++ b/services/mqtt_ase_receiver.service @@ -5,6 +5,7 @@ After=network.target [Service] WorkingDirectory=/var/lib/mosquitto ExecStart=/var/lib/mosquitto/.venv/bin/python3 ./control_mqtt.py +EnvironmentFile=/var/lib/mosquitto/data/.env Restart=always [Install] diff --git a/subscribe_ase_receiver.py b/subscribe_ase_receiver.py index 962055f..2fc65a3 100644 --- a/subscribe_ase_receiver.py +++ b/subscribe_ase_receiver.py @@ -15,5 +15,6 @@ print(f"Inizio elaborazione per {username} (PID: {os.getpid()})") try: while True: time.sleep(5) # Simula un lavoro in corso + print(os.getenv('WALLET_MASTER_PASSWORD')) except KeyboardInterrupt: print(f"Processo per {username} terminato") \ No newline at end of file