]> git.proxmox.com Git - pve-firewall.git/blobdiff - src/PVE/Firewall.pm
define standard option pve-config-digest
[pve-firewall.git] / src / PVE / Firewall.pm
index 336aedbd72cacd417e7533257495eb3f9aa9dba5..aa3555a9786da965961064ee4103cd9f2d28a8cd 100644 (file)
@@ -56,6 +56,14 @@ PVE::JSONSchema::register_standard_option('ipset-name', {
     maxLength => 20,                     
 });
 
+PVE::JSONSchema::register_standard_option('pve-config-digest', {
+    description => "This digest/signature can be used to prevent updates when the original configuration was changed by somebody else.",
+    type => 'string',
+    optional => 1,
+    maxLength => 27,
+    minLength => 27,                                     
+});
+
 my $security_group_pattern = '[A-Za-z][A-Za-z0-9\-\_]+';
 
 PVE::JSONSchema::register_standard_option('pve-security-group-name', {
@@ -791,12 +799,7 @@ my $rule_properties = {
        minimum => 0,
        optional => 1,
     },
-    digest => {
-       type => 'string',
-       optional => 1,
-       maxLength => 27,
-       minLength => 27,
-    },
+    digest => get_standard_option('pve-config-digest'),
     type => {
        type => 'string',
        optional => 1,
@@ -1976,7 +1979,13 @@ sub parse_cluster_fw_rules {
     my $section;
     my $group;
 
-    my $res = { rules => [], options => {}, groups => {}, ipset => {} };
+    my $res = { 
+       rules => [], 
+       options => {}, 
+       groups => {}, 
+       group_comments => {}, 
+       ipset => {} 
+    };
 
     my $digest = Digest::SHA->new('sha1');
 
@@ -1994,10 +2003,12 @@ sub parse_cluster_fw_rules {
            next;
        }
 
-       if ($line =~ m/^\[group\s+(\S+)\]\s*$/i) {
+       if ($line =~ m/^\[group\s+(\S+)\]\s*(?:#\s*(.*?)\s*)?$/i) {
            $section = 'groups';
            $group = lc($1);
+           my $comment = $2;
            $res->{$section}->{$group} = [];
+           $res->{group_comments}->{$group} = $comment if $comment;
            next;
        }
 
@@ -2415,7 +2426,12 @@ sub save_clusterfw_conf {
 
     foreach my $group (sort keys %{$cluster_conf->{groups}}) {
        my $rules = $cluster_conf->{groups}->{$group};
-       $raw .= "[group $group]\n\n";
+       if (my $comment = $cluster_conf->{group_comments}->{$group}) {
+           $raw .= "[group $group] # $comment\n\n";
+       } else {
+           $raw .= "[group $group]\n\n";
+       }
+
        $raw .= &$format_rules($rules, 0);
        $raw .= "\n";
     }