]>
git.proxmox.com Git - pmg-api.git/blob - 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
;
27 use base
qw(PVE::RESTHandler);
29 my $section_type_enum = PMG
::Config
::Base-
>lookup_types();
31 __PACKAGE__-
>register_method ({
32 subclass
=> "PMG::API2::RuleDB",
36 __PACKAGE__-
>register_method ({
37 subclass
=> "PMG::API2::SMTPWhitelist",
41 __PACKAGE__-
>register_method ({
42 subclass
=> "PMG::API2::LDAP",
46 __PACKAGE__-
>register_method ({
47 subclass
=> "PMG::API2::Domains",
51 __PACKAGE__-
>register_method ({
52 subclass
=> "PMG::API2::Fetchmail",
56 __PACKAGE__-
>register_method ({
57 subclass
=> "PMG::API2::Transport",
61 __PACKAGE__-
>register_method ({
62 subclass
=> "PMG::API2::MyNetworks",
63 # set fragment delimiter (no subdirs) - we need that, because CIDRs
65 fragmentDelimiter
=> '',
69 __PACKAGE__-
>register_method ({
70 subclass
=> "PMG::API2::Cluster",
74 __PACKAGE__-
>register_method ({
75 subclass
=> "PMG::API2::MimeTypes",
79 __PACKAGE__-
>register_method ({
80 subclass
=> "PMG::API2::DestinationTLSPolicy",
84 __PACKAGE__-
>register_method ({
88 description
=> "Directory index.",
90 additionalProperties
=> 0,
97 properties
=> { section
=> { type
=> 'string'} },
99 links
=> [ { rel
=> 'child', href
=> "{section}" } ],
105 foreach my $section (@$section_type_enum) {
106 push @$res, { section
=> $section };
109 push @$res, { section
=> 'ldap' };
110 push @$res, { section
=> 'mynetworks' };
111 push @$res, { section
=> 'mimetypes' };
112 push @$res, { section
=> 'users' };
113 push @$res, { section
=> 'domains' };
114 push @$res, { section
=> 'fetchmail' };
115 push @$res, { section
=> 'cluster' };
116 push @$res, { section
=> 'ruledb' };
117 push @$res, { section
=> 'transport' };
118 push @$res, { section
=> 'whitelist' };
119 push @$res, { section
=> 'regextest' };
120 push @$res, { section
=> 'tlspolicy' };
125 my $api_read_config_section = sub {
128 my $cfg = PMG
::Config-
>new();
130 my $data = dclone
($cfg->{ids
}->{$section} // {});
131 $data->{digest
} = $cfg->{digest
};
132 delete $data->{type
};
137 my $api_update_config_section = sub {
138 my ($section, $param) = @_;
141 my $cfg = PMG
::Config-
>new();
142 my $ids = $cfg->{ids
};
144 my $digest = extract_param
($param, 'digest');
145 PVE
::SectionConfig
::assert_if_modified
($cfg, $digest);
147 my $delete_str = extract_param
($param, 'delete');
148 die "no options specified\n"
149 if !$delete_str && !scalar(keys %$param);
151 foreach my $opt (PVE
::Tools
::split_list
($delete_str)) {
152 delete $ids->{$section}->{$opt};
155 my $plugin = PMG
::Config
::Base-
>lookup($section);
156 my $config = $plugin->check_config($section, $param, 0, 1);
158 foreach my $p (keys %$config) {
159 $ids->{$section}->{$p} = $config->{$p};
164 $cfg->rewrite_config(undef, 1);
167 PMG
::Config
::lock_config
($code, "update config section '$section' failed");
170 foreach my $section (@$section_type_enum) {
172 my $plugin = PMG
::Config
::Base-
>lookup($section);
174 __PACKAGE__-
>register_method ({
175 name
=> "read_${section}_section",
179 permissions
=> { check
=> [ 'admin', 'audit' ] },
180 description
=> "Read $section configuration properties.",
182 additionalProperties
=> 0,
185 returns
=> { type
=> 'object' },
189 return $api_read_config_section->($section);
192 __PACKAGE__-
>register_method ({
193 name
=> "update_${section}_section",
198 permissions
=> { check
=> [ 'admin' ] },
199 description
=> "Update $section configuration properties.",
200 parameters
=> $plugin->updateSchema(1),
201 returns
=> { type
=> 'null' },
205 $api_update_config_section->($section, $param);
211 __PACKAGE__-
>register_method({
216 permissions
=> { check
=> [ 'admin', 'qmanager', 'audit' ] },
217 description
=> "Test Regex",
219 additionalProperties
=> 0,
223 description
=> 'The Regex to test',
228 description
=> 'The String to test',
239 my $text = $param->{text
};
240 my $regex = $param->{regex
};
242 my $regex_check = sub {
243 my $start_time = [Time
::HiRes
::gettimeofday
];
245 if ($text =~ /$regex/) {
248 my $elapsed = Time
::HiRes
::tv_interval
($start_time) * 1000;
249 die "The Regular Expression '$regex' did not match the text '$text' (elapsed time: $elapsed ms)\n"
254 my $elapsed = PVE
::Tools
::run_fork_with_timeout
(2, $regex_check);
255 if ($elapsed eq '') {
256 die "The Regular Expression timed out\n";