Update: Fix loi up FW lan 2 that bai do thiet bi da duoc cai PassWord (them o nhap Backup PassWord va fallback)
This commit is contained in:
@@ -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
|
||||
# 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
|
||||
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
16
main.py
16
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)
|
||||
|
||||
Reference in New Issue
Block a user