68 lines
2.2 KiB
Lua
68 lines
2.2 KiB
Lua
|
|
-- "Пароль от GitHub" — decrypts via DPAPI, copies to clipboard for 30 seconds,
|
|||
|
|
-- speaks ONLY the service name (never the password).
|
|||
|
|
local phrase = (jarvis.context.phrase or ""):lower()
|
|||
|
|
local name = jarvis.text.strip_trigger(phrase, {
|
|||
|
|
"покажи пароль от",
|
|||
|
|
"достань пароль от",
|
|||
|
|
"пароль от",
|
|||
|
|
"дай пароль",
|
|||
|
|
"password for",
|
|||
|
|
"get password",
|
|||
|
|
"пароль від",
|
|||
|
|
})
|
|||
|
|
name = name:gsub("^[%s,:%.]+", ""):gsub("%s+$", "")
|
|||
|
|
|
|||
|
|
if name == "" then
|
|||
|
|
return jarvis.cmd.error("От чего пароль?")
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
local b64 = jarvis.memory.recall("vault." .. name)
|
|||
|
|
if not b64 or b64 == "" then
|
|||
|
|
return jarvis.cmd.not_found("Пароля для " .. name .. " нет.")
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
local ps = string.format([[
|
|||
|
|
Add-Type -AssemblyName System.Security;
|
|||
|
|
$bytes = [Convert]::FromBase64String('%s');
|
|||
|
|
try {
|
|||
|
|
$dec = [System.Security.Cryptography.ProtectedData]::Unprotect($bytes, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser);
|
|||
|
|
$text = [System.Text.Encoding]::UTF8.GetString($dec);
|
|||
|
|
Set-Clipboard -Value $text;
|
|||
|
|
Write-Output 'OK'
|
|||
|
|
} catch {
|
|||
|
|
Write-Output 'ERR'
|
|||
|
|
}
|
|||
|
|
]], b64)
|
|||
|
|
|
|||
|
|
local res = jarvis.system.exec(string.format(
|
|||
|
|
'powershell -NoProfile -Command "%s"', ps:gsub('"', '\\"'):gsub("\r?\n", "; ")
|
|||
|
|
))
|
|||
|
|
local out = res and (res.stdout or ""):gsub("%s+", "") or ""
|
|||
|
|
if out ~= "OK" then
|
|||
|
|
return jarvis.cmd.error("Не получилось расшифровать.")
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
-- Schedule clipboard clear in 30 seconds via the scheduler.
|
|||
|
|
local cmd_path = jarvis.context.command_path
|
|||
|
|
local clear_script = cmd_path .. "\\_clear_clip.lua"
|
|||
|
|
clear_script = clear_script:gsub("/", "\\")
|
|||
|
|
|
|||
|
|
if not jarvis.fs.is_file(clear_script) then
|
|||
|
|
jarvis.fs.write(clear_script, [[
|
|||
|
|
jarvis.system.clipboard.set("")
|
|||
|
|
return { chain = false }
|
|||
|
|
]])
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
local ok, _ = pcall(function()
|
|||
|
|
jarvis.scheduler.remove("vault_clip_clear")
|
|||
|
|
jarvis.scheduler.add({
|
|||
|
|
id = "vault_clip_clear",
|
|||
|
|
name = "Clear clipboard after vault paste",
|
|||
|
|
schedule = "in 30 seconds",
|
|||
|
|
action = { type = "lua", script_path = clear_script },
|
|||
|
|
})
|
|||
|
|
end)
|
|||
|
|
|
|||
|
|
return jarvis.cmd.ok("Пароль от " .. name .. " в буфере на 30 секунд.")
|