]>
git.proxmox.com Git - pmg-api.git/blob - PMG/API2/Fetchmail.pm
1 package PMG
::API2
::Fetchmail
;
9 use PVE
::Tools
qw(extract_param);
10 use PVE
::JSONSchema
qw(get_standard_option);
17 use base
qw(PVE::RESTHandler);
19 my $fetchmail_properties = {
21 description
=> "Unique ID",
23 pattern
=> '[A-Za-z0-9]+',
27 description
=> "Flag to enable or disable polling.",
33 description
=> "Server address (IP or DNS name).",
34 type
=> 'string', format
=> 'address',
38 description
=> "Specify the protocol to use when communicating with the remote mailserver",
40 enum
=> [ 'pop3', 'imap' ],
44 description
=> "Port number.",
51 description
=> "Only check this site every <interval> poll cycles. A poll cycle is 5 minutes.",
58 description
=> "Use SSL.",
64 description
=> "Keep retrieved messages on the remote mailserver.",
70 description
=> "The user identification to be used when logging in to the server",
77 description
=> "The password used tfor server login.",
82 target
=> get_standard_option
('pmg-email-address', {
83 description
=> "The target email address (where to deliver fetched mails).",
88 our $fetchmail_create_properties = clone
($fetchmail_properties);
89 delete $fetchmail_create_properties->{id
};
90 foreach my $k (qw(server protocol user pass target)) {
91 delete $fetchmail_create_properties->{$k}->{optional
};
94 __PACKAGE__-
>register_method ({
98 description
=> "List fetchmail users.",
99 permissions
=> { check
=> [ 'admin', 'audit' ] },
103 additionalProperties
=> 0,
110 properties
=> $fetchmail_properties,
112 links
=> [ { rel
=> 'child', href
=> "{id}" } ],
117 my $fmcfg = PVE
::INotify
::read_file
('fetchmailrc');
121 foreach my $id (sort keys %$fmcfg) {
122 push @$res, $fmcfg->{$id};
128 __PACKAGE__-
>register_method ({
132 description
=> "Read fetchmail user configuration.",
134 permissions
=> { check
=> [ 'admin', 'audit' ] },
137 additionalProperties
=> 0,
139 id
=> $fetchmail_properties->{id
},
144 properties
=> $fetchmail_properties,
149 my $fmcfg = PVE
::INotify
::read_file
('fetchmailrc');
151 my $data = $fmcfg->{$param->{id
}};
152 die "Fetchmail entry '$param->{id}' does not exist\n"
158 __PACKAGE__-
>register_method ({
162 description
=> "Create fetchmail user configuration.",
164 permissions
=> { check
=> [ 'admin' ] },
167 additionalProperties
=> 0,
168 properties
=> $fetchmail_create_properties,
170 returns
=> $fetchmail_properties->{id
},
178 my $fmcfg = PVE
::INotify
::read_file
('fetchmailrc');
180 for (my $i = 0; $i < 9999; $i++) {
181 my $tmpid = sprintf("proxmox%04d", $i);
182 if (!defined($fmcfg->{$tmpid})) {
187 die "unable to find free Fetchmail entry ID\n"
190 my $entry = { id
=> $id };
191 foreach my $k (keys %$param) {
192 $entry->{$k} = $param->{$k};
195 $fmcfg->{$id} = $entry;
197 PVE
::INotify
::write_file
('fetchmailrc', $fmcfg);
200 PMG
::Config
::lock_config
($code, "update fechtmail configuration failed");
205 __PACKAGE__-
>register_method ({
209 description
=> "Update fetchmail user configuration.",
211 permissions
=> { check
=> [ 'admin' ] },
214 additionalProperties
=> 0,
215 properties
=> $fetchmail_properties,
217 returns
=> { type
=> 'null' },
221 my $id = extract_param
($param, 'id');
225 my $fmcfg = PVE
::INotify
::read_file
('fetchmailrc');
227 my $data = $fmcfg->{$id};
228 die "Fetchmail entry '$id' does not exist\n"
231 foreach my $k (keys %$param) {
232 $data->{$k} = $param->{$k};
235 PVE
::INotify
::write_file
('fetchmailrc', $fmcfg);
238 PMG
::Config
::lock_config
($code, "update fechtmail configuration failed");
243 __PACKAGE__-
>register_method ({
247 description
=> "Delete a fetchmail configuration entry.",
249 permissions
=> { check
=> [ 'admin' ] },
252 additionalProperties
=> 0,
254 id
=> $fetchmail_properties->{id
},
257 returns
=> { type
=> 'null' },
261 my $id = extract_param
($param, 'id');
265 my $fmcfg = PVE
::INotify
::read_file
('fetchmailrc');
267 die "Fetchmail entry '$id' does not exist\n"
270 delete $fmcfg->{$id};
272 PVE
::INotify
::write_file
('fetchmailrc', $fmcfg);
275 PMG
::Config
::lock_config
($code, "delete fechtmail configuration failed");