1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2026-03-27 06:20:08 +01:00

Add certificate check to warning manager

This commit is contained in:
2025-11-06 11:41:40 +01:00
parent 8b8fcbeb9d
commit f9e7b99cd1
9 changed files with 66 additions and 19 deletions

View File

@@ -2554,7 +2554,7 @@
attributes = {
BuildIndependentTargetsInParallel = YES;
LastSwiftUpdateCheck = 1420;
LastUpgradeCheck = 2600;
LastUpgradeCheck = 2610;
ORGANIZATIONNAME = "Nico Verbruggen";
TargetAttributes = {
C406A5EF298AD2CE00B5B85A = {

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "2600"
LastUpgradeVersion = "2610"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "2600"
LastUpgradeVersion = "2610"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "2600"
LastUpgradeVersion = "2610"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "2600"
LastUpgradeVersion = "2610"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"

View File

@@ -87,6 +87,19 @@ class Valet {
return self.shared.sites + self.shared.proxies
}
/**
Retrieve a list of all domains, including sites & proxies
that have expired certificates.
*/
public static func getExpiredDomainListable() -> [ValetListable] {
return self.getDomainListable().filter { item in
if let expiry = item.getListableCertificateExpiryDate() {
return expiry < Date()
}
return false
}
}
/**
Updates the internal version number of Laravel Valet.
If this version number cannot be determined, it fails,

View File

@@ -10,7 +10,7 @@ import NVAlert
import Foundation
extension DomainListVC {
func checkForCertificateRenewal() {
func checkForCertificateRenewal(completion: @escaping () async -> Void = {}) {
// Check for expired certificates
let expired = domains.filter { item in
if let expiry = item.getListableCertificateExpiryDate() {
@@ -43,7 +43,10 @@ extension DomainListVC {
description: "cert_alert.domains".localized(domainListing)
)
.withPrimary(text: "cert_alert.renew".localized, action: { vc in
Task { await self.renewCertificates(expired) }
Task {
await self.renewCertificates(expired)
await completion()
}
vc.close(with: .OK)
})
.withSecondary(text: "cert_alert.cancel".localized, action: { vc in
@@ -54,20 +57,23 @@ extension DomainListVC {
}
public func renewCertificates(_ expired: [ValetListable]) async {
waitAndExecute {
for domain in expired {
// Unsecure domain first
try? await domain.toggleSecure()
// Resecure if unsecured
if !domain.getListableSecured() {
return await withCheckedContinuation { continuation in
waitAndExecute {
for domain in expired {
// Unsecure domain first
try? await domain.toggleSecure()
// Resecure if unsecured
if !domain.getListableSecured() {
try? await domain.toggleSecure()
}
}
} completion: {
Task {
await delay(seconds: 1)
await self.reloadDomainsWithoutUI()
continuation.resume()
}
}
} completion: {
Task {
await delay(seconds: 1)
await self.reloadDomainsWithoutUI()
}
}
}

View File

@@ -6,10 +6,35 @@
// Copyright © 2025 Nico Verbruggen. All rights reserved.
//
import Foundation
extension WarningManager {
// swiftlint:disable function_body_length
func allAvailableWarnings() -> [Warning] {
return [
Warning(
command: {
if Valet.installed {
return !Valet.getExpiredDomainListable().isEmpty
}
return false
},
name: "One or more domain certificates expired",
title: "warnings.certificates_expired.title",
paragraphs: { return ["warnings.certificates_expired.description"] },
url: nil,
fix: {
await DomainListVC.show()
if let vc = await App.shared.domainListWindowController?
.window?.contentViewController as? DomainListVC {
await vc.checkForCertificateRenewal {
await self.checkEnvironment()
}
}
}
),
Warning(
command: {
return await self.container.shell.pipe("sysctl -n sysctl.proc_translated").out

View File

@@ -856,6 +856,9 @@ When files like these are missing, you should switch to the PHP version associat
"warnings.extensions_tap_missing.title" = "`shivammathur/extensions` tap is missing";
"warnings.extensions_tap_missing.description" = "This Homebrew tap is required to install extensions via this app's PHP Extension Manager.";
"warnings.certificates_expired.title" = "One or more certificates that are being used to serve a domain have expired.";
"warnings.certificates_expired.description" = "Expired certificates will stop HTTPS traffic from working correctly. You can have PHP Monitor automatically attempt to resolve this for you by opening the Domains list.";
"warnings.none" = "There are no recommendations available for you right now. You're all good!";
// ONBOARDING