You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

201 lines
4.9 KiB

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Monday, April 29, 2024, 11:10 AM -->
<!-- MuClient version 5.07-pre -->
<!-- Plugin "Keycheck" generated by Plugin Wizard -->
<muclient>
<plugin
name="Keycheck"
author="Crowley"
id="233640c875089ec10c96199d"
language="Lua"
purpose="Displays expiring keys"
save_state="y"
date_written="2024-04-29 11:09:48"
requires="5.07"
version="1.0"
>
</plugin>
<!-- Triggers -->
<triggers>
<trigger
enabled="n"
group="KeyRingList"
match="{keyring}"
name="keyStart"
omit_from_output="y"
script="keyringStart"
send_to="12"
sequence="100"
>
</trigger>
<trigger
group="KeyRingList"
match="{/keyring}"
name="disableKeys"
omit_from_output="y"
sequence="100"
>
</trigger>
<trigger
group="KeyRingList"
match="^(.*)$"
name="captureKeys"
omit_from_output="y"
regexp="y"
script="processKey"
send_to="12"
sequence="100"
>
</trigger>
</triggers>
<!-- Aliases -->
<aliases>
<alias
enabled="y"
group="KeyRingList"
match="keycheck"
script="keyCheck"
sequence="100">
</alias>
</aliases>
<!-- Script -->
<script>
<![CDATA[
dofile(GetInfo(60) .. "aardwolf_colors.lua")
require 'themed_miniwindows'
require 'serialize'
if GetVariable("keyAreas") then
assert(loadstring(GetVariable("keyAreas")))()
else
keyAreas = {}
SetVariable("keyAreas", serialize.save("keyAreas"))
end
local keyringList = {}
local fName, fSize = GetAlphaOption("output_font_name"), GetOption("output_font_height")
local keyHeader = "@wKey ID Key Name Expiry Area@w"
local keyBreak = "@G------------ ---------------------------------------- -------------------- -------------------------@w"
local keyString = "%-12d %s%s %s"
function convertTime(totalSeconds)
local secondsInADay = 86400
local secondsInAnHour = 3600
local secondsInAMinute = 60
local days = math.floor(totalSeconds / secondsInADay)
local hours = math.floor((totalSeconds % secondsInADay) / secondsInAnHour)
local minutes = math.floor((totalSeconds % secondsInAnHour) / secondsInAMinute)
local seconds = totalSeconds % secondsInAMinute
local dayLabel = days == 1 and "day" or "days"
return string.format("%2d", days) .. " " .. dayLabel .. " and " .. string.format("%02d:%02d:%02d", hours, minutes, seconds)
end
function keyCheck()
EnableTrigger("keyStart")
Send("keyring data")
end
function keyringStart(name, line, wildcards)
keyringWin = ThemedTextWindow(
"keyring",
0, 0, 0, 0,
"Expiring Keys",
"center",
true,
true,
false,
true,
true,
true,
false,
fName, fSize, fName, fSize,
1000,
5,
true,
false
)
EnableTrigger("captureKeys")
EnableTrigger("disableKeys")
keyringList = {}
end
function processKey(name, line, wildcards)
if line == "{/keyring}" then keyEnd() return end
local keyID, keyName, keyExpiry = line:match("^(%d+),[^,]*,(.-),[^,]+,[^,]+,[^,]+,[^,]+,(.*)$")
keyExpiry = tonumber(keyExpiry)
if keyExpiry == -1 then keyExpiry = 0 end
if keyExpiry > 0 then
table.insert(keyringList, {keyID = keyID, keyName = keyName, keyExpiry = keyExpiry})
end
end
function keyEnd()
keyringWin:clear(true)
table.sort(keyringList, function(a, b)
return a.keyExpiry < b.keyExpiry
end)
keyringWin:add_text(keyHeader)
keyringWin:add_text(keyBreak)
for _, key in ipairs(keyringList) do
stopLoc = #strip_colours(key.keyName) + 14
local links = {{label = "Set area for key", start = 14, stop = stopLoc, text = "a='" .. key.keyName .. "';DoAfterSpecial(.1, 'addArea(a)', 12)"}}
local area = keyAreas[key.keyName] or "Unknown"
local addLine =keyString:format(key.keyID, key.keyName .. string.rep(" ", 42-#strip_colours(key.keyName)), convertTime(key.keyExpiry), area)
keyringWin:add_text(addLine, true, links)
end
keyringWin:fit_contents()
keyringWin:set_scroll(1)
keyringWin:show()
EnableTrigger("captureKeys", false)
EnableTrigger("disableKeys", false)
EnableTrigger("keyStart", false)
end
function addArea(keyName)
if not keyAreas[keyName] then
areaName = utils.inputbox("What area is this key from?", "Area Name")
else
utils.msgbox("This key name is already associated with an area. If you wish to override it, do so at the next prompt.")
areaName = utils.inputbox("What area is this key from?", "Area Name", keyAreas[keyName])
end
if areaName then
keyAreas[keyName] = areaName
end
SetVariable("keyAreas", serialize.save("keyAreas"))
Execute("keycheck")
end
]]>
</script>
</muclient>