row editing
This commit is contained in:
+24
-6
@@ -7909,11 +7909,26 @@ private enum LaravelBcryptService {
|
||||
return String(result.prefix(length))
|
||||
}
|
||||
|
||||
static func resolvedPHPPath(_ preferred: String = "") -> String? {
|
||||
let fm = FileManager.default
|
||||
let root = "/Applications/ServBay/package/php"
|
||||
let versions = (try? fm.contentsOfDirectory(atPath: root)) ?? []
|
||||
let servBay = versions.sorted { $0.compare($1, options: .numeric) == .orderedDescending }
|
||||
.map { version -> String in
|
||||
let base = "\(root)/\(version)"
|
||||
let builds = (try? fm.contentsOfDirectory(atPath: base)) ?? []
|
||||
let latest = builds.sorted { $0.compare($1, options: .numeric) == .orderedDescending }
|
||||
return latest.first(where: { fm.isExecutableFile(atPath: "\(base)/\($0)/bin/php") })
|
||||
.map { "\(base)/\($0)/bin/php" } ?? ""
|
||||
}
|
||||
let candidates = [preferred.trimmingCharacters(in: .whitespacesAndNewlines),
|
||||
"/Applications/ServBay/script/alias/php"] + servBay +
|
||||
["/opt/homebrew/bin/php", "/usr/local/bin/php", "/usr/bin/php"]
|
||||
return candidates.first(where: { !$0.isEmpty && $0.hasPrefix("/") && fm.isExecutableFile(atPath: $0) })
|
||||
}
|
||||
|
||||
static func hash(_ plaintext: String, phpPath: String) throws -> String {
|
||||
let candidates = [phpPath, "/opt/homebrew/bin/php", "/usr/local/bin/php", "/usr/bin/php"]
|
||||
guard let executable = candidates.first(where: {
|
||||
!$0.isEmpty && $0.hasPrefix("/") && FileManager.default.isExecutableFile(atPath: $0)
|
||||
}) else { throw HashError.noPHP }
|
||||
guard let executable = resolvedPHPPath(phpPath) else { throw HashError.noPHP }
|
||||
|
||||
let process = Process()
|
||||
process.executableURL = URL(fileURLWithPath: executable)
|
||||
@@ -7946,7 +7961,7 @@ private struct DBSynLaravelPasswordGenerator: View {
|
||||
let onUseHash: (String) -> Void
|
||||
@State private var plaintext = ""
|
||||
@State private var hashed = ""
|
||||
@State private var phpPath = ""
|
||||
@AppStorage("DBSyn.LaravelPHPPath") private var phpPath = ""
|
||||
@State private var showPassword = false
|
||||
@State private var busy = false
|
||||
@State private var errorText: String?
|
||||
@@ -7974,9 +7989,12 @@ private struct DBSynLaravelPasswordGenerator: View {
|
||||
HStack {
|
||||
TextField("PHP executable path (optional)", text: $phpPath)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
Text("Uses Homebrew PHP automatically when available")
|
||||
Text("Detects ServBay and Homebrew PHP automatically")
|
||||
.font(.caption).foregroundStyle(.secondary)
|
||||
}
|
||||
Text("PHP: " + (LaravelBcryptService.resolvedPHPPath(phpPath) ?? "Not found"))
|
||||
.font(.caption.monospaced()).foregroundStyle(.secondary)
|
||||
.textSelection(.enabled)
|
||||
HStack {
|
||||
Button(busy ? "Hashing…" : "Generate bcrypt Hash") { generateHash() }
|
||||
.disabled(plaintext.isEmpty || busy)
|
||||
|
||||
Reference in New Issue
Block a user