Update pve RustDesk GA sync scripts
This commit is contained in:
@@ -38,6 +38,8 @@ GUEST_READ_PATHS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
PS_READ_ID = r'''
|
PS_READ_ID = r'''
|
||||||
|
$ProgressPreference = 'SilentlyContinue'
|
||||||
|
$ErrorActionPreference = 'SilentlyContinue'
|
||||||
$paths = @(
|
$paths = @(
|
||||||
'C:\ProgramData\Blair\rustdesk-report.json',
|
'C:\ProgramData\Blair\rustdesk-report.json',
|
||||||
'C:\Windows\ServiceProfiles\LocalService\AppData\Roaming\RustDesk\config\RustDesk2.toml',
|
'C:\Windows\ServiceProfiles\LocalService\AppData\Roaming\RustDesk\config\RustDesk2.toml',
|
||||||
@@ -145,16 +147,36 @@ def decode_exec_payload(st: dict) -> tuple[str, str]:
|
|||||||
return out, err
|
return out, err
|
||||||
|
|
||||||
|
|
||||||
|
def clean_exec_text(text: str) -> str:
|
||||||
|
if not text:
|
||||||
|
return ''
|
||||||
|
text = re.sub(r'#< CLIXML.*', '', text, flags=re.DOTALL)
|
||||||
|
return text.strip()
|
||||||
|
|
||||||
|
|
||||||
|
def extract_id_from_exec(out: str, err: str) -> str | None:
|
||||||
|
combined = '\n'.join(filter(None, (clean_exec_text(out), clean_exec_text(err))))
|
||||||
|
for line in combined.splitlines():
|
||||||
|
line = line.strip()
|
||||||
|
if re.fullmatch(r'\d{6,12}', line):
|
||||||
|
return line
|
||||||
|
match = re.search(r'\d{6,12}', combined)
|
||||||
|
return match.group(0) if match else None
|
||||||
|
|
||||||
|
|
||||||
def parse_exec_result(st: dict) -> tuple[str | None, str | None]:
|
def parse_exec_result(st: dict) -> tuple[str | None, str | None]:
|
||||||
try:
|
try:
|
||||||
exitcode = int(st.get('exitcode', 1))
|
exitcode = int(st.get('exitcode', 1))
|
||||||
out, err = decode_exec_payload(st)
|
out, err = decode_exec_payload(st)
|
||||||
|
rid = extract_id_from_exec(out, err)
|
||||||
|
if rid:
|
||||||
|
return rid, None
|
||||||
if exitcode != 0:
|
if exitcode != 0:
|
||||||
return None, err or out or f'guest exit {exitcode}'
|
brief = clean_exec_text(err) or clean_exec_text(out) or f'guest exit {exitcode}'
|
||||||
match = re.search(r'\d{6,12}', out)
|
if len(brief) > 120:
|
||||||
if not match:
|
brief = brief[:120] + '...'
|
||||||
return None, f'no id in exec output: {out!r}'
|
return None, brief
|
||||||
return match.group(0), None
|
return None, f'no id in exec output: {out!r}'
|
||||||
except Exception as exc: # noqa: BLE001
|
except Exception as exc: # noqa: BLE001
|
||||||
return None, f'exec decode error: {exc}'
|
return None, f'exec decode error: {exc}'
|
||||||
|
|
||||||
@@ -258,7 +280,7 @@ def guest_exec_powershell(vmid: int) -> tuple[str | None, str | None]:
|
|||||||
enc = powershell_encoded(PS_READ_ID)
|
enc = powershell_encoded(PS_READ_ID)
|
||||||
return guest_exec_text(
|
return guest_exec_text(
|
||||||
vmid,
|
vmid,
|
||||||
['powershell.exe', '-NoProfile', '-EncodedCommand', enc],
|
['powershell.exe', '-NoProfile', '-NonInteractive', '-EncodedCommand', enc],
|
||||||
timeout=120,
|
timeout=120,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user