]>
git.proxmox.com Git - pmg-api.git/blob - src/PMG/API2/Config.pm
d4a9679ea0e9d5abf73039ed10d8c885d7c75695
1 package PMG
::API2
::Config
;
8 use PVE
::Tools
qw(extract_param);
9 use HTTP
::Status
qw(:constants);
10 use Storable
qw(dclone);
11 use PVE
::JSONSchema
qw(get_standard_option);
16 use PMG
::API2
::RuleDB
;
18 use PMG
::API2
::Domains
;
19 use PMG
::API2
::Transport
;
20 use PMG
::API2
::Cluster
;
21 use PMG
::API2
::MyNetworks
;
22 use PMG
::API2
::SMTPWhitelist
;
23 use PMG
::API2
::MimeTypes
;
24 use PMG
::API2
::Fetchmail
;
25 use PMG
::API2
::DestinationTLSPolicy
;
26 use PMG
::API2
::DKIMSign
;
27 use PMG
::API2
::SACustom
;
29 use base
qw(PVE::RESTHandler);
31 my $section_type_enum = PMG
::Config
::Base-
>lookup_types();
33 __PACKAGE__-
>register_method ({
34 subclass
=> "PMG::API2::RuleDB",
38 __PACKAGE__-
>register_method ({
39 subclass
=> "PMG::API2::SMTPWhitelist",
43 __PACKAGE__-
>register_method ({
44 subclass
=> "PMG::API2::LDAP",
48 __PACKAGE__-
>register_method ({
49 subclass
=> "PMG::API2::Domains",
53 __PACKAGE__-
>register_method ({
54 subclass
=> "PMG::API2::Fetchmail",
58 __PACKAGE__-
>register_method ({
59 subclass
=> "PMG::API2::Transport",
63 __PACKAGE__-
>register_method ({
64 subclass
=> "PMG::API2::MyNetworks",
65 # set fragment delimiter (no subdirs) - we need that, because CIDRs
67 fragmentDelimiter
=> '',
71 __PACKAGE__-
>register_method ({
72 subclass
=> "PMG::API2::Cluster",
76 __PACKAGE__-
>register_method ({
77 subclass
=> "PMG::API2::MimeTypes",
81 __PACKAGE__-
>register_method ({
82 subclass
=> "PMG::API2::DestinationTLSPolicy",
86 __PACKAGE__-
>register_method({
87 subclass
=> "PMG::API2::DKIMSign",
91 __PACKAGE__-
>register_method({
92 subclass
=> "PMG::API2::SACustom",
93 path
=> 'customscores',
96 __PACKAGE__-
>register_method ({
100 description
=> "Directory index.",
102 additionalProperties
=> 0,
109 properties
=> { section
=> { type
=> 'string'} },
111 links
=> [ { rel
=> 'child', href
=> "{section}" } ],
117 foreach my $section (@$section_type_enum) {
118 push @$res, { section
=> $section };
121 push @$res, { section
=> 'ldap' };
122 push @$res, { section
=> 'mynetworks' };
123 push @$res, { section
=> 'mimetypes' };
124 push @$res, { section
=> 'users' };
125 push @$res, { section
=> 'domains' };
126 push @$res, { section
=> 'fetchmail' };
127 push @$res, { section
=> 'cluster' };
128 push @$res, { section
=> 'ruledb' };
129 push @$res, { section
=> 'transport' };
130 push @$res, { section
=> 'whitelist' };
131 push @$res, { section
=> 'regextest' };
132 push @$res, { section
=> 'tlspolicy' };
133 push @$res, { section
=> 'dkim' };
138 my $api_read_config_section = sub {
141 my $cfg = PMG
::Config-
>new();
143 my $data = dclone
($cfg->{ids
}->{$section} // {});
144 $data->{digest
} = $cfg->{digest
};
145 delete $data->{type
};
150 my $api_update_config_section = sub {
151 my ($section, $param) = @_;
154 my $cfg = PMG
::Config-
>new();
155 my $ids = $cfg->{ids
};
157 my $digest = extract_param
($param, 'digest');
158 PVE
::SectionConfig
::assert_if_modified
($cfg, $digest);
160 my $delete_str = extract_param
($param, 'delete');
161 die "no options specified\n"
162 if !$delete_str && !scalar(keys %$param);
164 foreach my $opt (PVE
::Tools
::split_list
($delete_str)) {
165 delete $ids->{$section}->{$opt};
168 my $plugin = PMG
::Config
::Base-
>lookup($section);
169 my $config = $plugin->check_config($section, $param, 0, 1);
171 foreach my $p (keys %$config) {
172 $ids->{$section}->{$p} = $config->{$p};
177 $cfg->rewrite_config(undef, 1);
180 PMG
::Config
::lock_config
($code, "update config section '$section' failed");
183 foreach my $section (@$section_type_enum) {
185 my $plugin = PMG
::Config
::Base-
>lookup($section);
187 __PACKAGE__-
>register_method ({
188 name
=> "read_${section}_section",
192 permissions
=> { check
=> [ 'admin', 'audit' ] },
193 description
=> "Read $section configuration properties.",
195 additionalProperties
=> 0,
198 returns
=> { type
=> 'object' },
202 return $api_read_config_section->($section);
205 __PACKAGE__-
>register_method ({
206 name
=> "update_${section}_section",
211 permissions
=> { check
=> [ 'admin' ] },
212 description
=> "Update $section configuration properties.",
213 parameters
=> $plugin->updateSchema(1),
214 returns
=> { type
=> 'null' },
218 $api_update_config_section->($section, $param);
224 __PACKAGE__-
>register_method({
229 permissions
=> { check
=> [ 'admin', 'qmanager', 'audit' ] },
230 description
=> "Test Regex ignoring case",
232 additionalProperties
=> 0,
236 description
=> 'The Regex to test',
241 description
=> 'The String to test',
252 my $text = $param->{text
};
253 my $regex = $param->{regex
};
255 my $regex_check = sub {
256 my $start_time = [Time
::HiRes
::gettimeofday
];
258 if ($text =~ /$regex/i) {
261 my $elapsed = Time
::HiRes
::tv_interval
($start_time) * 1000;
262 die "The Regular Expression '$regex' did not match the text '$text' (elapsed time: $elapsed ms)\n"
267 my $elapsed = PVE
::Tools
::run_fork_with_timeout
(2, $regex_check);
268 if ($elapsed eq '') {
269 die "The Regular Expression timed out\n";