refactor code, ẩn thông tin ssh

This commit is contained in:
2026-03-09 11:59:55 +07:00
parent 9f6bd8c35a
commit 1297511122
13 changed files with 1043 additions and 504 deletions

52
main.py
View File

@@ -23,9 +23,9 @@ from PyQt6.QtGui import QFont, QColor, QIcon, QAction
import datetime
from core.scanner import scan_network
from core.flasher import flash_device
from core.ssh_flasher import flash_device_ssh
from core.workers import ScanThread, FlashThread
from core.workers import ScanThread
from core.flash_new_worker import NewFlashThread
from core.flash_update_worker import UpdateFlashThread
from utils.network import _resolve_hostname, get_default_network
from utils.system import resource_path, get_machine_info, get_version
@@ -307,11 +307,11 @@ class App(QWidget):
self.ssh_creds_widget.setVisible(False)
method_layout.addWidget(self.ssh_creds_widget)
flash_layout.addWidget(self.method_container)
# Warning UI for Update Mode
self.update_warning_lbl = QLabel("⚠️ FW Update Mode: Forced to SSH (root/admin123a). Target IP [192.168.11.102]. Other IPs require confirmation.")
self.update_warning_lbl = QLabel("⚠️ FW Update Mode: Forced to SSH. Target IP [192.168.11.102]. Other IPs require confirmation.")
self.update_warning_lbl.setStyleSheet("color: #f38ba8; font-size: 13px; font-weight: bold; padding: 8px; border: 1px dotted #f38ba8;")
self.update_warning_lbl.setWordWrap(True)
self.update_warning_lbl.setVisible(False)
@@ -565,9 +565,8 @@ class App(QWidget):
self._on_method_changed(self.method_combo.currentIndex())
def _on_method_changed(self, index):
"""Show/hide SSH credentials based on selected method."""
method = self.method_combo.currentData()
self.ssh_creds_widget.setVisible(method == "ssh")
"""SSH credentials are always hidden; credentials are hardcoded."""
self.ssh_creds_widget.setVisible(False)
def _get_selected_devices(self):
"""Return list of (table_row_index, device_dict) for checked devices."""
@@ -639,26 +638,33 @@ class App(QWidget):
set_passwd = False
else:
method = self.method_combo.currentData()
ssh_user = self.ssh_user_input.text().strip() or "root"
ssh_password = self.ssh_pass_input.text() or "admin123a"
ssh_user = "root"
ssh_password = "admin123a"
ssh_backup_password = "admin123a"
set_passwd = self.set_passwd_cb.isChecked() if method == "ssh" else False
set_passwd = True if method == "ssh" else False
# Run flashing in background thread so UI doesn't freeze
self.flash_thread = FlashThread(
flash_devices, self.firmware,
max_workers=self.parallel_spin.value(),
method=method,
ssh_user=ssh_user,
ssh_password=ssh_password,
ssh_backup_password=ssh_backup_password,
set_passwd=set_passwd
)
# Chọn đúng worker theo mode và chạy trong background thread
max_w = self.parallel_spin.value()
if mode == "update":
self.flash_thread = UpdateFlashThread(
flash_devices, self.firmware,
max_workers=max_w,
)
else:
self.flash_thread = NewFlashThread(
flash_devices, self.firmware,
max_workers=max_w,
method=method,
ssh_user=ssh_user,
ssh_password=ssh_password,
ssh_backup_password=ssh_backup_password,
set_passwd=set_passwd,
)
self.flash_thread.device_status.connect(self._on_flash_status)
self.flash_thread.device_done.connect(self._on_flash_done)
self.flash_thread.all_done.connect(self._on_flash_all_done)
# Disable flash button during flashing
# Disable flash button trong khi đang flash
self.btn_flash.setEnabled(False)
self.flash_thread.start()