]>
git.proxmox.com Git - pmg-api.git/blob - src/PMG/API2/Config.pm
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
;
28 use PMG
::API2
::PBS
::Remote
;
31 use base
qw(PVE::RESTHandler);
33 my $section_type_enum = PMG
::Config
::Base-
>lookup_types();
35 __PACKAGE__-
>register_method ({
36 subclass
=> "PMG::API2::RuleDB",
40 __PACKAGE__-
>register_method ({
41 subclass
=> "PMG::API2::SMTPWhitelist",
45 __PACKAGE__-
>register_method ({
46 subclass
=> "PMG::API2::LDAP",
50 __PACKAGE__-
>register_method ({
51 subclass
=> "PMG::API2::Domains",
55 __PACKAGE__-
>register_method ({
56 subclass
=> "PMG::API2::Fetchmail",
60 __PACKAGE__-
>register_method ({
61 subclass
=> "PMG::API2::Transport",
65 __PACKAGE__-
>register_method ({
66 subclass
=> "PMG::API2::MyNetworks",
67 # set fragment delimiter (no subdirs) - we need that, because CIDRs
69 fragmentDelimiter
=> '',
73 __PACKAGE__-
>register_method ({
74 subclass
=> "PMG::API2::Cluster",
78 __PACKAGE__-
>register_method ({
79 subclass
=> "PMG::API2::MimeTypes",
83 __PACKAGE__-
>register_method ({
84 subclass
=> "PMG::API2::DestinationTLSPolicy",
88 __PACKAGE__-
>register_method({
89 subclass
=> "PMG::API2::DKIMSign",
93 __PACKAGE__-
>register_method({
94 subclass
=> "PMG::API2::SACustom",
95 path
=> 'customscores',
98 __PACKAGE__-
>register_method ({
99 subclass
=> "PMG::API2::PBS::Remote",
103 __PACKAGE__-
>register_method ({
104 subclass
=> "PMG::API2::ACME",
108 __PACKAGE__-
>register_method ({
112 description
=> "Directory index.",
114 additionalProperties
=> 0,
121 properties
=> { section
=> { type
=> 'string'} },
123 links
=> [ { rel
=> 'child', href
=> "{section}" } ],
129 foreach my $section (@$section_type_enum) {
130 push @$res, { section
=> $section };
133 push @$res, { section
=> 'ldap' };
134 push @$res, { section
=> 'mynetworks' };
135 push @$res, { section
=> 'mimetypes' };
136 push @$res, { section
=> 'users' };
137 push @$res, { section
=> 'domains' };
138 push @$res, { section
=> 'fetchmail' };
139 push @$res, { section
=> 'cluster' };
140 push @$res, { section
=> 'ruledb' };
141 push @$res, { section
=> 'transport' };
142 push @$res, { section
=> 'whitelist' };
143 push @$res, { section
=> 'regextest' };
144 push @$res, { section
=> 'tlspolicy' };
145 push @$res, { section
=> 'dkim' };
146 push @$res, { section
=> 'pbs' };
147 push @$res, { section
=> 'acme' };
152 my $api_read_config_section = sub {
155 my $cfg = PMG
::Config-
>new();
157 my $data = dclone
($cfg->{ids
}->{$section} // {});
158 $data->{digest
} = $cfg->{digest
};
159 delete $data->{type
};
164 my $api_update_config_section = sub {
165 my ($section, $param) = @_;
168 my $cfg = PMG
::Config-
>new();
169 my $ids = $cfg->{ids
};
171 my $digest = extract_param
($param, 'digest');
172 PVE
::SectionConfig
::assert_if_modified
($cfg, $digest);
174 my $delete_str = extract_param
($param, 'delete');
175 die "no options specified\n"
176 if !$delete_str && !scalar(keys %$param);
178 foreach my $opt (PVE
::Tools
::split_list
($delete_str)) {
179 delete $ids->{$section}->{$opt};
182 my $plugin = PMG
::Config
::Base-
>lookup($section);
183 my $config = $plugin->check_config($section, $param, 0, 1);
185 foreach my $p (keys %$config) {
186 $ids->{$section}->{$p} = $config->{$p};
191 $cfg->rewrite_config(undef, 1);
194 PMG
::Config
::lock_config
($code, "update config section '$section' failed");
197 foreach my $section (@$section_type_enum) {
199 my $plugin = PMG
::Config
::Base-
>lookup($section);
201 __PACKAGE__-
>register_method ({
202 name
=> "read_${section}_section",
206 permissions
=> { check
=> [ 'admin', 'audit' ] },
207 description
=> "Read $section configuration properties.",
209 additionalProperties
=> 0,
212 returns
=> { type
=> 'object' },
216 return $api_read_config_section->($section);
219 __PACKAGE__-
>register_method ({
220 name
=> "update_${section}_section",
225 permissions
=> { check
=> [ 'admin' ] },
226 description
=> "Update $section configuration properties.",
227 parameters
=> $plugin->updateSchema(1),
228 returns
=> { type
=> 'null' },
232 $api_update_config_section->($section, $param);
238 __PACKAGE__-
>register_method({
243 permissions
=> { check
=> [ 'admin', 'qmanager', 'audit' ] },
244 description
=> "Test Regex ignoring case",
246 additionalProperties
=> 0,
250 description
=> 'The Regex to test',
255 description
=> 'The String to test',
266 my $text = $param->{text
};
267 my $regex = $param->{regex
};
269 my $regex_check = sub {
270 my $start_time = [Time
::HiRes
::gettimeofday
];
272 if ($text =~ /$regex/i) {
275 my $elapsed = Time
::HiRes
::tv_interval
($start_time) * 1000;
276 die "The Regular Expression '$regex' did not match the text '$text' (elapsed time: $elapsed ms)\n"
281 my $elapsed = PVE
::Tools
::run_fork_with_timeout
(2, $regex_check);
282 if ($elapsed eq '') {
283 die "The Regular Expression timed out\n";