all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH 1/2] tui: always use mail@example.invalid as default email address
@ 2023-06-21 12:30 Dominik Csapak
  2023-06-21 12:30 ` [pve-devel] [PATCH 2/2] tui: verify email with basic regex Dominik Csapak
  0 siblings, 1 reply; 4+ messages in thread
From: Dominik Csapak @ 2023-06-21 12:30 UTC (permalink / raw)
  To: pve-devel

like the gui installer

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 proxmox-tui-installer/src/main.rs    |  2 +-
 proxmox-tui-installer/src/options.rs | 14 +++-----------
 2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs
index 90da81d..77cfb63 100644
--- a/proxmox-tui-installer/src/main.rs
+++ b/proxmox-tui-installer/src/main.rs
@@ -179,7 +179,7 @@ fn main() {
         options: InstallerOptions {
             bootdisk: BootdiskOptions::defaults_from(&runtime_info.disks[0]),
             timezone: TimezoneOptions::defaults_from(&runtime_info, &locales),
-            password: PasswordOptions::defaults_from(&runtime_info),
+            password: Default::default(),
             network: NetworkOptions::from(&runtime_info.network),
             autoreboot: false,
         },
diff --git a/proxmox-tui-installer/src/options.rs b/proxmox-tui-installer/src/options.rs
index 6855f4a..5f3d295 100644
--- a/proxmox-tui-installer/src/options.rs
+++ b/proxmox-tui-installer/src/options.rs
@@ -306,18 +306,10 @@ pub struct PasswordOptions {
     pub root_password: String,
 }
 
-impl PasswordOptions {
-    pub fn defaults_from(info: &RuntimeInfo) -> Self {
-        let domain = info
-            .network
-            .dns
-            .domain
-            .clone()
-            // Safety: The provided default domain will always be valid.
-            .unwrap_or_else(|| Fqdn::from("example.invalid").unwrap());
-
+impl Default for PasswordOptions {
+    fn default() -> Self {
         Self {
-            email: format!("mail@{domain}"),
+            email: "mail@example.invalid".to_string(),
             root_password: String::new(),
         }
     }
-- 
2.30.2





^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] [PATCH 2/2] tui: verify email with basic regex
  2023-06-21 12:30 [pve-devel] [PATCH 1/2] tui: always use mail@example.invalid as default email address Dominik Csapak
@ 2023-06-21 12:30 ` Dominik Csapak
  2023-06-21 12:34   ` Thomas Lamprecht
  2023-06-21 12:45   ` Maximiliano Sandoval
  0 siblings, 2 replies; 4+ messages in thread
From: Dominik Csapak @ 2023-06-21 12:30 UTC (permalink / raw)
  To: pve-devel

regex copied from perl gui installer

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
this needs librust-regex-dev as build-dependency
 proxmox-tui-installer/Cargo.toml  | 1 +
 proxmox-tui-installer/src/main.rs | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/proxmox-tui-installer/Cargo.toml b/proxmox-tui-installer/Cargo.toml
index 9d57b5b..5a50c69 100644
--- a/proxmox-tui-installer/Cargo.toml
+++ b/proxmox-tui-installer/Cargo.toml
@@ -11,5 +11,6 @@ homepage = "https://www.proxmox.com"
 cursive = { version = "0.20.0", default-features = false, features = ["termion-backend"] }
 serde = { version = "1.0", features = ["derive"] }
 serde_json = "1.0"
+regex = "1.7"
 
 proxmox-sys = "0.5.0"
diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs
index 77cfb63..2d048f0 100644
--- a/proxmox-tui-installer/src/main.rs
+++ b/proxmox-tui-installer/src/main.rs
@@ -25,6 +25,8 @@ use cursive::{
     Cursive, CursiveRunnable, ScreenId, View, XY,
 };
 
+use regex::Regex;
+
 use proxmox_sys::linux::procfs;
 
 mod options;
@@ -484,12 +486,18 @@ fn password_dialog(siv: &mut Cursive) -> InstallerView {
                     .get_value::<EditView, _>(2)
                     .ok_or("failed to retrieve email")?;
 
+                let email_regex =
+                    Regex::new(r"^[\w\+\-\~]+(\.[\w\+\-\~]+)*@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*$")
+                        .unwrap();
+
                 if root_password.len() < 5 {
                     Err("password too short")
                 } else if root_password != confirm_password {
                     Err("passwords do not match")
                 } else if email == "mail@example.invalid" {
                     Err("invalid email address")
+                } else if !email_regex.is_match(&email) {
+                    Err("Email does not look like a valid address (user@domain.tld)")
                 } else {
                     Ok(PasswordOptions {
                         root_password,
-- 
2.30.2





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [pve-devel] [PATCH 2/2] tui: verify email with basic regex
  2023-06-21 12:30 ` [pve-devel] [PATCH 2/2] tui: verify email with basic regex Dominik Csapak
@ 2023-06-21 12:34   ` Thomas Lamprecht
  2023-06-21 12:45   ` Maximiliano Sandoval
  1 sibling, 0 replies; 4+ messages in thread
From: Thomas Lamprecht @ 2023-06-21 12:34 UTC (permalink / raw)
  To: Proxmox VE development discussion, Dominik Csapak

Am 21/06/2023 um 14:30 schrieb Dominik Csapak:
> regex copied from perl gui installer
> 
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> this needs librust-regex-dev as build-dependency
>  proxmox-tui-installer/Cargo.toml  | 1 +
>  proxmox-tui-installer/src/main.rs | 8 ++++++++
>  2 files changed, 9 insertions(+)
> 
> diff --git a/proxmox-tui-installer/Cargo.toml b/proxmox-tui-installer/Cargo.toml
> index 9d57b5b..5a50c69 100644
> --- a/proxmox-tui-installer/Cargo.toml
> +++ b/proxmox-tui-installer/Cargo.toml
> @@ -11,5 +11,6 @@ homepage = "https://www.proxmox.com"
>  cursive = { version = "0.20.0", default-features = false, features = ["termion-backend"] }
>  serde = { version = "1.0", features = ["derive"] }
>  serde_json = "1.0"
> +regex = "1.7"

FYI: needs also an build-dependency entry in d/control to be complete, but can fix
that on applying.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [pve-devel] [PATCH 2/2] tui: verify email with basic regex
  2023-06-21 12:30 ` [pve-devel] [PATCH 2/2] tui: verify email with basic regex Dominik Csapak
  2023-06-21 12:34   ` Thomas Lamprecht
@ 2023-06-21 12:45   ` Maximiliano Sandoval
  1 sibling, 0 replies; 4+ messages in thread
From: Maximiliano Sandoval @ 2023-06-21 12:45 UTC (permalink / raw)
  To: Proxmox VE development discussion, Dominik Csapak

Note that the HTML5 standard [1] suggests 

    /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/

as a regex, I am not sure whats the difference but it might be worth it to check if there is any relevant difference. This is used by the validator crate [2] for example.

[1] https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
[2] https://docs.rs/validator/latest/validator/fn.validate_email.html

> On 21.06.2023 14:30 CEST Dominik Csapak <d.csapak@proxmox.com> wrote:
> 
>  
> regex copied from perl gui installer
> 
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> this needs librust-regex-dev as build-dependency
>  proxmox-tui-installer/Cargo.toml  | 1 +
>  proxmox-tui-installer/src/main.rs | 8 ++++++++
>  2 files changed, 9 insertions(+)
> 
> diff --git a/proxmox-tui-installer/Cargo.toml b/proxmox-tui-installer/Cargo.toml
> index 9d57b5b..5a50c69 100644
> --- a/proxmox-tui-installer/Cargo.toml
> +++ b/proxmox-tui-installer/Cargo.toml
> @@ -11,5 +11,6 @@ homepage = "https://www.proxmox.com"
>  cursive = { version = "0.20.0", default-features = false, features = ["termion-backend"] }
>  serde = { version = "1.0", features = ["derive"] }
>  serde_json = "1.0"
> +regex = "1.7"
>  
>  proxmox-sys = "0.5.0"
> diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs
> index 77cfb63..2d048f0 100644
> --- a/proxmox-tui-installer/src/main.rs
> +++ b/proxmox-tui-installer/src/main.rs
> @@ -25,6 +25,8 @@ use cursive::{
>      Cursive, CursiveRunnable, ScreenId, View, XY,
>  };
>  
> +use regex::Regex;
> +
>  use proxmox_sys::linux::procfs;
>  
>  mod options;
> @@ -484,12 +486,18 @@ fn password_dialog(siv: &mut Cursive) -> InstallerView {
>                      .get_value::<EditView, _>(2)
>                      .ok_or("failed to retrieve email")?;
>  
> +                let email_regex =
> +                    Regex::new(r"^[\w\+\-\~]+(\.[\w\+\-\~]+)*@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*$")
> +                        .unwrap();
> +
>                  if root_password.len() < 5 {
>                      Err("password too short")
>                  } else if root_password != confirm_password {
>                      Err("passwords do not match")
>                  } else if email == "mail@example.invalid" {
>                      Err("invalid email address")
> +                } else if !email_regex.is_match(&email) {
> +                    Err("Email does not look like a valid address (user@domain.tld)")
>                  } else {
>                      Ok(PasswordOptions {
>                          root_password,
> -- 
> 2.30.2
> 
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-06-21 12:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-21 12:30 [pve-devel] [PATCH 1/2] tui: always use mail@example.invalid as default email address Dominik Csapak
2023-06-21 12:30 ` [pve-devel] [PATCH 2/2] tui: verify email with basic regex Dominik Csapak
2023-06-21 12:34   ` Thomas Lamprecht
2023-06-21 12:45   ` Maximiliano Sandoval

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal