From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 77C60F4A3 for ; Thu, 15 Dec 2022 17:57:36 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 56B3B1A29D for ; Thu, 15 Dec 2022 17:57:06 +0100 (CET) Received: from nena.proxmox.com (unknown [94.136.29.99]) by firstgate.proxmox.com (Proxmox) with ESMTP for ; Thu, 15 Dec 2022 17:57:04 +0100 (CET) Received: by nena.proxmox.com (Postfix, from userid 1000) id CF3D3295EBF; Thu, 15 Dec 2022 17:57:04 +0100 (CET) From: Mira Limbeck To: pve-devel@lists.proxmox.com Date: Thu, 15 Dec 2022 17:57:00 +0100 Message-Id: <20221215165700.2061397-1-m.limbeck@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -1.141 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_EVIL_NUMBERS4 1 Phone Numbers used by scammers KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods NO_DNS_FOR_FROM 0.001 Envelope sender has no MX or A DNS records RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [report.pm] Subject: [pve-devel] [PATCH manager] report: filter comments in VM/CT configs X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Dec 2022 16:57:36 -0000 Since some users keep their passwords in the VM/CT configs as comments and those are most of the time unnecessary when looking through the report, filter those. In addition to the comments, also filter the `cipassword` option since it contains the hash of the password. To facilitate the filtering, a new sub 'file2text' is introduced that can filter the file contents if required. This sub replaces the 'cat ...' commands. Signed-off-by: Mira Limbeck --- I did not add print to STDERR in file2text for now since it got quite chatty. If this is wanted, I'll send a v2 adding it. But since file2text is also called by dir2text the 'OK' at the end won't always align, especially when dir2text is used. PVE/Report.pm | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/PVE/Report.pm b/PVE/Report.pm index 90b7cb1c..7ebe98f7 100644 --- a/PVE/Report.pm +++ b/PVE/Report.pm @@ -5,16 +5,34 @@ use warnings; use PVE::Tools; +my sub file2text { + my ($file, $filter) = @_; + my $text = "\n# cat $file\n"; + + my $contents = PVE::Tools::file_get_contents($file); + if ($filter) { + foreach my $line (split('\n', $contents)) { + next if $line =~ m/^\s*#/; + next if $line =~ m/^cipassword/; + + $text .= "$line\n"; + } + } else { + $text .= $contents; + } + + return $text; +} + # output the content of all the files of a directory my sub dir2text { - my ($target_dir, $regexp) = @_; + my ($target_dir, $regexp, $filter) = @_; print STDERR "dir2text '${target_dir}${regexp}'..."; my $text = ''; PVE::Tools::dir_glob_foreach($target_dir, $regexp, sub { my ($file) = @_; - $text .= "\n# cat $target_dir$file\n"; - $text .= PVE::Tools::file_get_contents($target_dir.$file)."\n"; + $text .= file2text($target_dir.$file, $filter)."\n"; }); return $text; } @@ -30,9 +48,9 @@ my $init_report_cmds = sub { cmds => [ 'hostname', 'pveversion --verbose', - 'cat /etc/hosts', + sub { file2text('/etc/hosts') }, 'pvesubscription get', - 'cat /etc/apt/sources.list', + sub { file2text('/etc/apt/sources.list') }, sub { dir2text('/etc/apt/sources.list.d/', '.*list') }, sub { dir2text('/etc/apt/sources.list.d/', '.*sources') }, 'lscpu', @@ -50,9 +68,9 @@ my $init_report_cmds = sub { storage => { order => 30, cmds => [ - 'cat /etc/pve/storage.cfg', + sub { file2text('/etc/pve/storage.cfg') }, 'pvesm status', - 'cat /etc/fstab', + sub { file2text('/etc/fstab') }, 'findmnt --ascii', 'df --human -T', 'proxmox-boot-tool status', @@ -62,9 +80,9 @@ my $init_report_cmds = sub { order => 40, cmds => [ 'qm list', - sub { dir2text('/etc/pve/qemu-server/', '\d.*conf') }, + sub { dir2text('/etc/pve/qemu-server/', '\d.*conf', 1) }, 'pct list', - sub { dir2text('/etc/pve/lxc/', '\d.*conf') }, + sub { dir2text('/etc/pve/lxc/', '\d.*conf', 1) }, ], }, network => { @@ -73,14 +91,14 @@ my $init_report_cmds = sub { 'ip -details -statistics address', 'ip -details -4 route show', 'ip -details -6 route show', - 'cat /etc/network/interfaces', + sub { file2text('/etc/network/interfaces') }, ], }, firewall => { order => 50, cmds => [ sub { dir2text('/etc/pve/firewall/', '.*fw') }, - 'cat /etc/pve/local/host.fw', + sub { file2text('/etc/pve/local/host.fw') }, 'iptables-save', ], }, @@ -89,7 +107,7 @@ my $init_report_cmds = sub { cmds => [ 'pvecm nodes', 'pvecm status', - 'cat /etc/pve/corosync.conf 2>/dev/null', + sub { file2text('/etc/pve/corosync.conf') }, 'ha-manager status', ], }, @@ -135,7 +153,7 @@ my $init_report_cmds = sub { 'ceph df', 'ceph osd df tree', 'ceph device ls', - 'cat /etc/ceph/ceph.conf', + sub { file2text('/etc/ceph/ceph.conf') }, 'ceph config dump', 'pveceph pool ls', 'ceph versions', @@ -144,8 +162,8 @@ my $init_report_cmds = sub { if (cmd_exists('multipath')) { push @{$report_def->{disks}->{cmds}}, - 'cat /etc/multipath.conf', - 'cat /etc/multipath/wwids', + sub { file2text('/etc/multipath.conf') }, + sub { file2text('/etc/multipath/wwids') }, 'multipath -ll', ; } -- 2.30.2