]>
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
;
30 use base
qw(PVE::RESTHandler);
32 my $section_type_enum = PMG
::Config
::Base-
>lookup_types();
34 __PACKAGE__-
>register_method ({
35 subclass
=> "PMG::API2::RuleDB",
39 __PACKAGE__-
>register_method ({
40 subclass
=> "PMG::API2::SMTPWhitelist",
44 __PACKAGE__-
>register_method ({
45 subclass
=> "PMG::API2::LDAP",
49 __PACKAGE__-
>register_method ({
50 subclass
=> "PMG::API2::Domains",
54 __PACKAGE__-
>register_method ({
55 subclass
=> "PMG::API2::Fetchmail",
59 __PACKAGE__-
>register_method ({
60 subclass
=> "PMG::API2::Transport",
64 __PACKAGE__-
>register_method ({
65 subclass
=> "PMG::API2::MyNetworks",
66 # set fragment delimiter (no subdirs) - we need that, because CIDRs
68 fragmentDelimiter
=> '',
72 __PACKAGE__-
>register_method ({
73 subclass
=> "PMG::API2::Cluster",
77 __PACKAGE__-
>register_method ({
78 subclass
=> "PMG::API2::MimeTypes",
82 __PACKAGE__-
>register_method ({
83 subclass
=> "PMG::API2::DestinationTLSPolicy",
87 __PACKAGE__-
>register_method({
88 subclass
=> "PMG::API2::DKIMSign",
92 __PACKAGE__-
>register_method({
93 subclass
=> "PMG::API2::SACustom",
94 path
=> 'customscores',
97 __PACKAGE__-
>register_method ({
98 subclass
=> "PMG::API2::PBS::Remote",
102 __PACKAGE__-
>register_method ({
106 description
=> "Directory index.",
108 additionalProperties
=> 0,
115 properties
=> { section
=> { type
=> 'string'} },
117 links
=> [ { rel
=> 'child', href
=> "{section}" } ],
123 foreach my $section (@$section_type_enum) {
124 push @$res, { section
=> $section };
127 push @$res, { section
=> 'ldap' };
128 push @$res, { section
=> 'mynetworks' };
129 push @$res, { section
=> 'mimetypes' };
130 push @$res, { section
=> 'users' };
131 push @$res, { section
=> 'domains' };
132 push @$res, { section
=> 'fetchmail' };
133 push @$res, { section
=> 'cluster' };
134 push @$res, { section
=> 'ruledb' };
135 push @$res, { section
=> 'transport' };
136 push @$res, { section
=> 'whitelist' };
137 push @$res, { section
=> 'regextest' };
138 push @$res, { section
=> 'tlspolicy' };
139 push @$res, { section
=> 'dkim' };
140 push @$res, { section
=> 'pbs' };
145 my $api_read_config_section = sub {
148 my $cfg = PMG
::Config-
>new();
150 my $data = dclone
($cfg->{ids
}->{$section} // {});
151 $data->{digest
} = $cfg->{digest
};
152 delete $data->{type
};
157 my $api_update_config_section = sub {
158 my ($section, $param) = @_;
161 my $cfg = PMG
::Config-
>new();
162 my $ids = $cfg->{ids
};
164 my $digest = extract_param
($param, 'digest');
165 PVE
::SectionConfig
::assert_if_modified
($cfg, $digest);
167 my $delete_str = extract_param
($param, 'delete');
168 die "no options specified\n"
169 if !$delete_str && !scalar(keys %$param);
171 foreach my $opt (PVE
::Tools
::split_list
($delete_str)) {
172 delete $ids->{$section}->{$opt};
175 my $plugin = PMG
::Config
::Base-
>lookup($section);
176 my $config = $plugin->check_config($section, $param, 0, 1);
178 foreach my $p (keys %$config) {
179 $ids->{$section}->{$p} = $config->{$p};
184 $cfg->rewrite_config(undef, 1);
187 PMG
::Config
::lock_config
($code, "update config section '$section' failed");
190 foreach my $section (@$section_type_enum) {
192 my $plugin = PMG
::Config
::Base-
>lookup($section);
194 __PACKAGE__-
>register_method ({
195 name
=> "read_${section}_section",
199 permissions
=> { check
=> [ 'admin', 'audit' ] },
200 description
=> "Read $section configuration properties.",
202 additionalProperties
=> 0,
205 returns
=> { type
=> 'object' },
209 return $api_read_config_section->($section);
212 __PACKAGE__-
>register_method ({
213 name
=> "update_${section}_section",
218 permissions
=> { check
=> [ 'admin' ] },
219 description
=> "Update $section configuration properties.",
220 parameters
=> $plugin->updateSchema(1),
221 returns
=> { type
=> 'null' },
225 $api_update_config_section->($section, $param);
231 __PACKAGE__-
>register_method({
236 permissions
=> { check
=> [ 'admin', 'qmanager', 'audit' ] },
237 description
=> "Test Regex ignoring case",
239 additionalProperties
=> 0,
243 description
=> 'The Regex to test',
248 description
=> 'The String to test',
259 my $text = $param->{text
};
260 my $regex = $param->{regex
};
262 my $regex_check = sub {
263 my $start_time = [Time
::HiRes
::gettimeofday
];
265 if ($text =~ /$regex/i) {
268 my $elapsed = Time
::HiRes
::tv_interval
($start_time) * 1000;
269 die "The Regular Expression '$regex' did not match the text '$text' (elapsed time: $elapsed ms)\n"
274 my $elapsed = PVE
::Tools
::run_fork_with_timeout
(2, $regex_check);
275 if ($elapsed eq '') {
276 die "The Regular Expression timed out\n";