1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-11-07 21:20:07 +01:00

👌 Scan proxies (#105)

This commit is contained in:
2022-04-11 22:56:40 +02:00
parent 8304d774c3
commit f0f7a3f7d6
8 changed files with 86 additions and 10 deletions

View File

@@ -12,10 +12,23 @@ class NginxConfiguration {
var contents: String!
var domain: String
var tld: String
init(filePath: String) {
self.contents = try! String(contentsOfFile: filePath
.replacingOccurrences(of: "~", with: "/Users/\(Paths.whoami)")
let path = filePath.replacingOccurrences(
of: "~",
with: "/Users/\(Paths.whoami)"
)
self.contents = try! String(contentsOfFile: path)
let domain = String(path.split(separator: "/").last!)
let tld = String(domain.split(separator: ".").last!)
self.domain = domain
.replacingOccurrences(of: ".\(tld)", with: "")
self.tld = tld
}
/**

View File

@@ -10,6 +10,6 @@ import Foundation
protocol ProxyScanner {
// TODO
func resolveProxies(directoryPath: String) -> [ValetProxy]
}

View File

@@ -0,0 +1,28 @@
//
// ValetProxyScanner.swift
// PHP Monitor
//
// Created by Nico Verbruggen on 11/04/2022.
// Copyright © 2022 Nico Verbruggen. All rights reserved.
//
import Foundation
class ValetProxyScanner: ProxyScanner
{
func resolveProxies(directoryPath: String) -> [ValetProxy]
{
return try! FileManager
.default
.contentsOfDirectory(atPath: directoryPath)
.map {
return NginxConfiguration.init(filePath: "\(directoryPath)/\($0)")
}
.filter {
return $0.proxy != nil
}
.map {
return ValetProxy($0)
}
}
}

View File

@@ -10,6 +10,4 @@ import Foundation
extension ValetProxy {
//
}

View File

@@ -8,11 +8,15 @@
import Foundation
struct ValetProxy
class ValetProxy
{
var domain: String
var tld: String
var target: String
init(_ configuration: NginxConfiguration) {
self.domain = configuration.domain
self.tld = configuration.tld
self.target = configuration.proxy!
}
}

View File

@@ -35,10 +35,12 @@ class Valet {
/// Various feature flags. Enabled based on the installed Valet version.
var features: [FeatureFlag] = []
/// When initialising the Valet singleton assume no sites loaded. We will load the version later.
/// When initialising the Valet singleton, assume no sites or proxies loaded.
/// We will load the version later.
init() {
self.version = nil
self.sites = []
self.proxies = []
}
/**
@@ -54,6 +56,10 @@ class Valet {
return ValetSiteScanner()
}
static var proxyScanner: ProxyScanner {
return ValetProxyScanner()
}
/**
Check if a particular feature is enabled.
*/
@@ -176,7 +182,17 @@ class Valet {
sites = Self.siteScanner
.resolveSitesFrom(paths: config.paths)
.sorted { $0.absolutePath < $1.absolutePath }
.sorted {
$0.absolutePath < $1.absolutePath
}
proxies = Self.proxyScanner
.resolveProxies(
directoryPath: FileManager.default
.homeDirectoryForCurrentUser
.appendingPathComponent(".config/valet/Nginx")
.path
)
if let defaultPath = Valet.shared.config.defaultSite,
let site = ValetSiteScanner().resolveSite(path: defaultPath) {