1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 12:00:09 +02:00

👌 Improve proxy subject validation

This commit is contained in:
2022-05-10 00:38:13 +02:00
parent 3fc21fff2a
commit f7a98b88a7
2 changed files with 14 additions and 9 deletions

View File

@ -63,8 +63,6 @@ class AddProxyVC: NSViewController, NSTextFieldDelegate {
}
@IBAction func pressedCreateProxy(_ sender: Any) {
// TODO: Validate the input before allowing proxy creation
let domain = self.inputDomainName.stringValue
let proxyName = self.inputProxySubject.stringValue
let secure = self.buttonSecure.state == .on ? " --secure" : ""
@ -104,18 +102,24 @@ class AddProxyVC: NSViewController, NSTextFieldDelegate {
}
private func validate(domain: String, proxy: String) -> Bool {
if domain.isEmpty {
textFieldError.isHidden = false
textFieldError.stringValue = "domain_list.add.errors.empty".localized
return false
}
if proxy.isEmpty {
textFieldError.isHidden = false
textFieldError.stringValue = "domain_list.add.errors.empty_proxy".localized
return false
}
if proxy.range(of: #"(http:\/\/|https:\/\/)(.*)(:)(\d*)"#, options: .regularExpression) == nil {
textFieldError.isHidden = false
textFieldError.stringValue = "domain_list.add.errors.subject_invalid".localized
return false
}
if domain.isEmpty {
textFieldError.isHidden = false
textFieldError.stringValue = "domain_list.add.errors.empty".localized
return false
}
if Valet.shared.sites.contains(where: { $0.name == domain }) {
textFieldError.isHidden = false
textFieldError.stringValue = "domain_list.add.errors.already_exists".localized

View File

@ -106,7 +106,7 @@
// ADD PROXY TO DOMAINS LIST
"domain_list.add.set_up_proxy" = "Set up a Proxy";
"domain_list.add.proxy_subject" = "Proxy subject (usually: protocol, IP address and port)";
"domain_list.add.proxy_subject" = "Proxy subject (must include protocol and port)";
"domain_list.add.domain_name" = "Domain name";
"domain_list.add.create_proxy" = "Create Proxy";
"domain_list.add.proxy_available" = "%@ will be proxied and will be available via: %@://%@.%@";
@ -124,6 +124,7 @@
"domain_list.add.empty_fields" = "One or more fields are empty. Please fill all required fields.";
"domain_list.add.errors.empty" = "You must enter a domain name.";
"domain_list.add.errors.empty_proxy" = "You must enter what will be proxied.";
"domain_list.add.errors.subject_invalid" = "The subject you've entered is not valid.\nYou must include the protocol and port.";
"domain_list.add.errors.already_exists" = "A link with that name already exists.";
// ADD SITE ERROR: FOLDER MISSING SINCE SELECTION