From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 3BC491FF14F for ; Fri, 08 May 2026 17:57:38 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C26731D69B; Fri, 8 May 2026 17:57:37 +0200 (CEST) From: Shannon Sterz To: yew-devel@lists.proxmox.com Subject: [PATCH yew-mobile-gui v2 17/21] lxc: add support for a rudimentary firewall tab for lxc guests Date: Fri, 8 May 2026 17:57:18 +0200 Message-ID: <20260508155722.464564-18-s.sterz@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260508155722.464564-1-s.sterz@proxmox.com> References: <20260508155722.464564-1-s.sterz@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1778255736666 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.035 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_2 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_4 0.1 random spam to be learned in bayes SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: EDVSDJQ42JL76XBVROD53WEYCJH42F6R X-Message-ID-Hash: EDVSDJQ42JL76XBVROD53WEYCJH42F6R X-MailFrom: s.sterz@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Yew framework devel list at Proxmox List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Signed-off-by: Shannon Sterz --- src/pages/page_lxc_status/firewall_panel.rs | 172 ++++++++++++++++++++ src/pages/page_lxc_status/mod.rs | 17 ++ 2 files changed, 189 insertions(+) create mode 100644 src/pages/page_lxc_status/firewall_panel.rs diff --git a/src/pages/page_lxc_status/firewall_panel.rs b/src/pages/page_lxc_status/firewall_panel.rs new file mode 100644 index 0000000..10d76dd --- /dev/null +++ b/src/pages/page_lxc_status/firewall_panel.rs @@ -0,0 +1,172 @@ +use std::rc::Rc; + +use serde::{Deserialize, Serialize}; +use yew::virtual_dom::{VComp, VNode}; + +use pwt::prelude::*; +use pwt::props::StorageLocation; +use pwt::state::PersistentState; +use pwt::widget::{Column, MiniScroll, TabBar, TabBarItem}; + +use proxmox_yew_comp::configuration::pve::{FirewallOptionsGuestPanel, FirewallRulesPanel}; +use proxmox_yew_comp::form::pve::PveGuestType; + +#[derive(Clone, PartialEq, Properties)] +pub struct LxcFirewallPanel { + vmid: u32, + node: AttrValue, +} + +impl LxcFirewallPanel { + pub fn new(node: impl Into, vmid: u32) -> Self { + Self { + node: node.into(), + vmid, + } + } +} + +#[derive(Copy, Clone, Default, PartialEq, Serialize, Deserialize)] +pub enum ViewState { + #[default] + Rules, + Options, + //Alias, + //IPSet, + //Log, +} +pub struct PveLxcFirewallPanel { + view_state: PersistentState, +} + +pub enum Msg { + SetViewState(ViewState), +} + +impl Component for PveLxcFirewallPanel { + type Message = Msg; + type Properties = LxcFirewallPanel; + + fn create(ctx: &Context) -> Self { + let props = ctx.props(); + + let view_state = PersistentState::new(StorageLocation::session(format!( + "ct-{}-firewall-tab-bar-state", + props.vmid + ))); + + Self { view_state } + } + + fn update(&mut self, _ctx: &Context, msg: Self::Message) -> bool { + match msg { + Msg::SetViewState(view_state) => { + self.view_state.update(view_state); + } + } + true + } + fn view(&self, ctx: &Context) -> Html { + let props = ctx.props(); + + let (active_tab, content): (_, Html) = match *self.view_state { + ViewState::Rules => ( + "rules", + FirewallRulesPanel::guest_firewall( + PveGuestType::Lxc, + props.node.clone(), + props.vmid, + ) + .mobile(true) + .readonly(true) + .into(), + ), + ViewState::Options => ( + "options", + FirewallOptionsGuestPanel::new(PveGuestType::Lxc, props.node.clone(), props.vmid) + .mobile(true) + .readonly(true) + .into(), + ), + /*ViewState::Alias => ( + "alias", + html! { +
{ format!("Firewall alias for VM {}", props.vmid) }
+ }, + ), + ViewState::IPSet => ( + "ipset", + html! { +
{ format!("Firewall ipset for VM {}", props.vmid) }
+ }, + ), + ViewState::Log => ( + "log", + html! { +
{ format!("Firewall log for VM {}", props.vmid) }
+ }, + ),*/ + }; + + let tab_bar = TabBar::new() + .style(pwt::widget::TabBarStyle::MaterialSecondary) + .class(pwt::css::JustifyContent::Center) + .class("pwt-flex-fill") + .active(active_tab) + .with_item( + TabBarItem::new() + .key("rules") + .label(tr!("Rules")) + .icon_class("fa fa-shield") + .on_activate(ctx.link().callback(|_| Msg::SetViewState(ViewState::Rules))), + ) + .with_item( + TabBarItem::new() + .key("options") + .label(tr!("Options")) + .icon_class("fa fa-gear") + .on_activate( + ctx.link() + .callback(|_| Msg::SetViewState(ViewState::Options)), + ), + ) + /*.with_item( + TabBarItem::new() + .key("alias") + .label(tr!("Alias")) + .icon_class("fa fa-external-link") + .on_activate(ctx.link().callback(|_| Msg::SetViewState(ViewState::Alias))), + ) + .with_item( + TabBarItem::new() + .key("ipset") + .label(tr!("IPSet")) + .icon_class("fa fa-list-ol") + .on_activate(ctx.link().callback(|_| Msg::SetViewState(ViewState::IPSet))), + ) + .with_item( + TabBarItem::new() + .key("log") + .label(tr!("Log")) + .icon_class("fa fa-list") + .on_activate(ctx.link().callback(|_| Msg::SetViewState(ViewState::Log))), + )*/; + + Column::new() + .class(pwt::css::FlexFit) + .with_child( + MiniScroll::new(tab_bar) + .class("pwt-flex-none") + .scroll_mode(pwt::widget::MiniScrollMode::Native), + ) + .with_child(content) + .into() + } +} + +impl From for VNode { + fn from(val: LxcFirewallPanel) -> Self { + let comp = VComp::new::(Rc::new(val), None); + VNode::from(comp) + } +} diff --git a/src/pages/page_lxc_status/mod.rs b/src/pages/page_lxc_status/mod.rs index 301e894..dcde151 100644 --- a/src/pages/page_lxc_status/mod.rs +++ b/src/pages/page_lxc_status/mod.rs @@ -14,7 +14,9 @@ use pwt::widget::{Column, MiniScroll, TabBar, TabBarItem}; use crate::widgets::{GuestBackupPanel, TopNavBar}; mod dashboard_panel; +mod firewall_panel; pub use dashboard_panel::LxcDashboardPanel; +use firewall_panel::LxcFirewallPanel; use proxmox_yew_comp::configuration::pve::LxcOptionsPanel; @@ -39,6 +41,7 @@ pub enum ViewState { Dashboard, Options, Backup, + Firewall, } pub enum Msg { @@ -92,6 +95,10 @@ impl Component for PvePageLxcStatus { .readonly(true) .into(), ), + ViewState::Firewall => ( + "firewall", + LxcFirewallPanel::new(props.node.clone(), props.vmid).into(), + ), }; let tab_bar = TabBar::new() @@ -127,6 +134,16 @@ impl Component for PvePageLxcStatus { ctx.link() .callback(|_| Msg::SetViewState(ViewState::Backup)), ), + ) + .with_item( + TabBarItem::new() + .label(tr!("Firewall")) + .icon_class("fa fa-shield") + .key("firewall") + .on_activate( + ctx.link() + .callback(|_| Msg::SetViewState(ViewState::Firewall)), + ), ); Column::new() -- 2.47.3