]>
git.proxmox.com Git - pmg-api.git/blob - PMG/API2/MyNetworks.pm
1 package PMG
::API2
::MyNetworks
;
8 use PVE
::Tools
qw(extract_param);
9 use HTTP
::Status
qw(:constants);
10 use PVE
::JSONSchema
qw(get_standard_option);
16 use base
qw(PVE::RESTHandler);
18 __PACKAGE__-
>register_method ({
22 description
=> "List of trusted networks from where SMTP clients are allowed to relay mail through Proxmox Mail Gateway.",
24 permissions
=> { check
=> [ 'admin', 'audit' ] },
26 additionalProperties
=> 0,
34 cidr
=> { type
=> 'string'},
37 links
=> [ { rel
=> 'child', href
=> "{cidr}" } ],
42 my $mynetworks = PVE
::INotify
::read_file
('mynetworks');
46 foreach my $cidr (sort keys %$mynetworks) {
47 push @$res, $mynetworks->{$cidr};
53 __PACKAGE__-
>register_method ({
59 permissions
=> { check
=> [ 'admin' ] },
60 description
=> "Add a trusted network.",
62 additionalProperties
=> 0,
65 description
=> "IPv4 or IPv6 network in CIDR notation.",
66 type
=> 'string', format
=> 'CIDR',
69 description
=> "Comment.",
75 returns
=> { type
=> 'null' },
81 my $mynetworks = PVE
::INotify
::read_file
('mynetworks');
83 die "trusted network '$param->{cidr}' already exists\n"
84 if $mynetworks->{$param->{cidr
}};
86 $mynetworks->{$param->{cidr
}} = {
87 comment
=> $param->{comment
} // '',
90 PVE
::INotify
::write_file
('mynetworks', $mynetworks);
92 my $cfg = PMG
::Config-
>new();
94 if ($cfg->rewrite_config_postfix()) {
95 PMG
::Utils
::service_cmd
('postfix', 'reload');
99 PMG
::Config
::lock_config
($code, "add trusted network failed");
104 __PACKAGE__-
>register_method ({
108 description
=> "Read trusted network data (comment).",
110 permissions
=> { check
=> [ 'admin', 'audit' ] },
112 additionalProperties
=> 0,
115 description
=> "IPv4 or IPv6 network in CIDR notation.",
116 type
=> 'string', format
=> 'CIDR',
123 cidr
=> { type
=> 'string'},
124 comment
=> { type
=> 'string'},
130 my $mynetworks = PVE
::INotify
::read_file
('mynetworks');
132 die "trusted network '$param->{cidr}' does not exist\n"
133 if !$mynetworks->{$param->{cidr
}};
135 return $mynetworks->{$param->{cidr
}}
138 __PACKAGE__-
>register_method ({
142 description
=> "Update trusted data (comment).",
144 permissions
=> { check
=> [ 'admin' ] },
147 additionalProperties
=> 0,
150 description
=> "IPv4 or IPv6 network in CIDR notation.",
151 type
=> 'string', #format => 'CIDR',
154 description
=> "Comment.",
159 returns
=> { type
=> 'null' },
165 my $mynetworks = PVE
::INotify
::read_file
('mynetworks');
167 die "trusted network '$param->{cidr}' does not exist\n"
168 if !$mynetworks->{$param->{cidr
}};
170 $mynetworks->{$param->{cidr
}}->{comment
} = $param->{comment
};
172 PVE
::INotify
::write_file
('mynetworks', $mynetworks);
175 PMG
::Config
::lock_config
($code, "update trusted network failed");
180 __PACKAGE__-
>register_method ({
184 description
=> "Delete a truster network",
186 permissions
=> { check
=> [ 'admin' ] },
189 additionalProperties
=> 0,
192 description
=> "IPv4 or IPv6 network in CIDR notation.",
193 type
=> 'string', format
=> 'CIDR',
197 returns
=> { type
=> 'null' },
203 my $mynetworks = PVE
::INotify
::read_file
('mynetworks');
205 die "trusted network '$param->{cidr}' does not exist\n"
206 if !$mynetworks->{$param->{cidr
}};
208 delete $mynetworks->{$param->{cidr
}};
210 PVE
::INotify
::write_file
('mynetworks', $mynetworks);
212 my $cfg = PMG
::Config-
>new();
214 if ($cfg->rewrite_config_postfix()) {
215 PMG
::Utils
::service_cmd
('postfix', 'reload');
219 PMG
::Config
::lock_config
($code, "delete trusted network failed");