diff --git a/core/ssh_flasher.py b/core/ssh_flasher.py index dc6da1d..2d46ec0 100644 --- a/core/ssh_flasher.py +++ b/core/ssh_flasher.py @@ -113,7 +113,7 @@ def set_device_password(ip, user="root", old_password="", new_password="admin123 def flash_device_ssh(ip, firmware_path, user="root", password="admin123a", - set_passwd=False, status_cb=None): + backup_password="", set_passwd=False, status_cb=None): """ Flash firmware to an OpenWrt device via SSH/SCP. @@ -134,8 +134,14 @@ def flash_device_ssh(ip, firmware_path, user="root", password="admin123a", if set_passwd: result = set_device_password(ip, user, "", password, status_cb) if result.startswith("FAIL"): - # Try with current password as old password - result = set_device_password(ip, user, password, password, status_cb) + # Try with backup password if set + if backup_password: + result = set_device_password(ip, user, backup_password, password, status_cb) + + # If still failing, try with current intended password just in case it was already set + if result.startswith("FAIL"): + result = set_device_password(ip, user, password, password, status_cb) + if result.startswith("FAIL"): return result diff --git a/core/workers.py b/core/workers.py index b3b36f6..af8ec98 100644 --- a/core/workers.py +++ b/core/workers.py @@ -55,7 +55,7 @@ class FlashThread(QThread): def __init__(self, devices, firmware_path, max_workers=10, method="api", ssh_user="root", ssh_password="admin123a", - set_passwd=False): + ssh_backup_password="", set_passwd=False): super().__init__() self.devices = devices self.firmware_path = firmware_path @@ -63,6 +63,7 @@ class FlashThread(QThread): self.method = method self.ssh_user = ssh_user self.ssh_password = ssh_password + self.ssh_backup_password = ssh_backup_password self.set_passwd = set_passwd def run(self): @@ -76,6 +77,7 @@ class FlashThread(QThread): dev["ip"], self.firmware_path, user=self.ssh_user, password=self.ssh_password, + backup_password=self.ssh_backup_password, set_passwd=self.set_passwd, status_cb=on_status ) diff --git a/main.py b/main.py index 421c7dc..0701e6b 100644 --- a/main.py +++ b/main.py @@ -300,6 +300,19 @@ class App(QWidget): ssh_row1.addStretch() ssh_creds_layout.addLayout(ssh_row1) + ssh_row2 = QHBoxLayout() + ssh_lbl3 = QLabel("Backup Pass:") + ssh_lbl3.setStyleSheet("font-size: 12px; font-weight: bold;") + ssh_row2.addWidget(ssh_lbl3) + self.ssh_backup_pass_input = QLineEdit("admin") + self.ssh_backup_pass_input.setEchoMode(QLineEdit.EchoMode.Password) + self.ssh_backup_pass_input.setFixedWidth(130) + self.ssh_backup_pass_input.setStyleSheet(str_qlineedit) + self.ssh_backup_pass_input.setToolTip("Password to try if device already has a password (fallback)") + ssh_row2.addWidget(self.ssh_backup_pass_input) + ssh_row2.addStretch() + ssh_creds_layout.addLayout(ssh_row2) + self.set_passwd_cb = QCheckBox("Set password before flash (passwd → admin123a)") self.set_passwd_cb.setChecked(True) self.set_passwd_cb.setStyleSheet("color: #94a3b8; font-size: 12px; font-weight: bold;") @@ -629,11 +642,13 @@ class App(QWidget): method = "ssh" ssh_user = "root" ssh_password = "admin123a" + ssh_backup_password = "admin" 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_backup_password = self.ssh_backup_pass_input.text() set_passwd = self.set_passwd_cb.isChecked() if method == "ssh" else False # Run flashing in background thread so UI doesn't freeze @@ -643,6 +658,7 @@ class App(QWidget): 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)