1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2026-03-31 16:50:09 +02:00

Add certificate expiry check for sites and proxies

The lock is either locked (secured) or unlocked (unsecured).

The color of this icon depends on the state:
- Default appearance is OK, not expired
- Orange icon means expired
- Red icon means expired OR unsecured
This commit is contained in:
2025-10-29 14:43:15 +01:00
parent c6a60274f9
commit 85addf1f35
5 changed files with 1229 additions and 30 deletions

View File

@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.180",
"green" : "0.500",
"red" : "1.000"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.426",
"green" : "0.655",
"red" : "1.000"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -14,6 +14,14 @@ class ValetProxy: ValetListable {
var target: String
var secured: Bool = false
var certificateExpiryDate: Date?
var isCertificateExpired: Bool {
guard let certificateExpiryDate = certificateExpiryDate else {
return false
}
return certificateExpiryDate < Date()
}
var favorited: Bool = false
var favoriteSignature: String {
"proxy:domain:\(domain).\(tld)|target:\(target)"
@@ -79,7 +87,20 @@ class ValetProxy: ValetListable {
// MARK: - Interactions
func determineSecured() {
self.secured = container.filesystem.fileExists("~/.config/valet/Certificates/\(self.domain).\(self.tld).key")
let certificatePath = "~/.config/valet/Certificates/\(self.domain).\(self.tld).crt"
let (exists, expiryDate) = CertificateValidator(container)
.validateCertificate(at: certificatePath)
if exists, let expiryDate {
Log.info("Certificate for \(self.domain).\(self.tld) expires at: \(expiryDate).")
} else {
Log.info("No certificate for \(self.domain).\(self.tld).")
}
// Persist the information for the list
self.secured = exists
self.certificateExpiryDate = expiryDate
}
func toggleFavorite() {

View File

@@ -39,7 +39,15 @@ class ValetSite: ValetListable {
var secured: Bool!
/// When the certificate expires.
var expiryDate: Date?
var certificateExpiryDate: Date?
/// A simple bool to check if the certificate has expired.
var isCertificateExpired: Bool {
guard let certificateExpiryDate = certificateExpiryDate else {
return false
}
return certificateExpiryDate < Date()
}
/// What driver is currently in use. If not detected, defaults to nil.
var driver: String?
@@ -141,7 +149,7 @@ class ValetSite: ValetListable {
// Persist the information for the list
self.secured = exists
self.expiryDate = expiryDate
self.certificateExpiryDate = expiryDate
}
/**

View File

@@ -17,14 +17,25 @@ class DomainListTLSCell: NSTableCellView, DomainListCellProtocol {
}
func populateCell(with site: ValetSite) {
imageViewLock.image = NSImage(named: site.secured ? "Lock" : "LockUnlocked")!
imageViewLock.contentTintColor = site.secured
? NSColor(named: "IconColorGreen")
? nil
: NSColor(named: "IconColorRed")
if site.secured && site.isCertificateExpired {
imageViewLock.contentTintColor = NSColor(named: "StatusColorOrange")
}
}
func populateCell(with proxy: ValetProxy) {
imageViewLock.image = NSImage(named: proxy.secured ? "Lock" : "LockUnlocked")!
imageViewLock.contentTintColor = proxy.secured
? NSColor(named: "IconColorGreen")
? nil
: NSColor(named: "IconColorRed")
if proxy.secured && proxy.isCertificateExpired {
imageViewLock.contentTintColor = NSColor(named: "StatusColorOrange")
}
}
}