]>
git.proxmox.com Git - pmg-api.git/blob - PMG/API2/Transport.pm
1 package PMG
::API2
::Transport
;
8 use PVE
::Tools
qw(extract_param);
9 use HTTP
::Status
qw(:constants);
10 use PVE
::JSONSchema
qw(get_standard_option);
16 use base
qw(PVE::RESTHandler);
18 __PACKAGE__-
>register_method ({
22 description
=> "List transport map entries.",
24 permissions
=> { check
=> [ 'admin', 'audit' ] },
26 additionalProperties
=> 0,
34 domain
=> { type
=> 'string' },
35 host
=> { type
=> 'string' },
36 port
=> { type
=> 'integer' },
37 use_mx
=> { type
=> 'boolean' },
38 comment
=> { type
=> 'string'},
41 links
=> [ { rel
=> 'child', href
=> "{domain}" } ],
46 my $tmap = PVE
::INotify
::read_file
('transport');
50 foreach my $domain (sort keys %$tmap) {
51 push @$res, $tmap->{$domain};
57 __PACKAGE__-
>register_method ({
63 permissions
=> { check
=> [ 'admin' ] },
64 description
=> "Add transport map entry.",
66 additionalProperties
=> 0,
69 description
=> "Domain name.",
70 type
=> 'string', format
=> 'transport-domain-or-email',
73 description
=> "Target host (name or IP address).",
74 type
=> 'string', format
=> 'address',
77 description
=> "SMTP port.",
85 description
=> "Enable MX lookups.",
91 description
=> "Comment.",
97 returns
=> { type
=> 'null' },
103 my $tmap = PVE
::INotify
::read_file
('transport');
105 die "Transport map entry '$param->{domain}' already exists\n"
106 if $tmap->{$param->{domain
}};
108 $tmap->{$param->{domain
}} = {
109 domain
=> $param->{domain
},
110 host
=> $param->{host
},
111 port
=> $param->{port
} // 25,
112 use_mx
=> $param->{use_mx
} // 1,
113 comment
=> $param->{comment
} // '',
116 PVE
::INotify
::write_file
('transport', $tmap);
118 PMG
::Config
::postmap_pmg_transport
();
121 PMG
::Config
::lock_config
($code, "add transport map entry failed");
126 __PACKAGE__-
>register_method ({
130 description
=> "Read transport map entry.",
132 permissions
=> { check
=> [ 'admin', 'audit' ] },
134 additionalProperties
=> 0,
137 description
=> "Domain name.",
138 type
=> 'string', format
=> 'transport-domain-or-email',
145 domain
=> { type
=> 'string'},
146 host
=> { type
=> 'string'},
147 port
=> { type
=> 'integer'},
148 use_mx
=> { type
=> 'boolean'},
149 comment
=> { type
=> 'string'},
155 my $tmap = PVE
::INotify
::read_file
('transport');
157 if (my $entry = $tmap->{$param->{domain
}}) {
161 die "Transport map entry '$param->{domain}' does not exist\n";
164 __PACKAGE__-
>register_method ({
168 description
=> "Update transport map entry.",
170 permissions
=> { check
=> [ 'admin' ] },
173 additionalProperties
=> 0,
176 description
=> "Domain name.",
177 type
=> 'string', format
=> 'transport-domain-or-email',
180 description
=> "Target host (name or IP address).",
181 type
=> 'string', format
=> 'address',
185 description
=> "SMTP port.",
192 description
=> "Enable MX lookups.",
197 description
=> "Comment.",
203 returns
=> { type
=> 'null' },
209 my $tmap = PVE
::INotify
::read_file
('transport');
211 my $domain = extract_param
($param, 'domain');
213 my $data = $tmap->{$domain};
215 die "Transport map entry '$param->{domain}' does not exist\n" if !$data;
217 die "no options specified\n" if !scalar(keys %$param);
219 for my $prop (qw(host port use_mx comment)) {
220 $data->{$prop} = $param->{$prop} if defined($param->{$prop});
223 PVE
::INotify
::write_file
('transport', $tmap);
225 PMG
::Config
::postmap_pmg_transport
();
228 PMG
::Config
::lock_config
($code, "update transport map entry failed");
233 __PACKAGE__-
>register_method ({
237 description
=> "Delete a transport map entry",
239 permissions
=> { check
=> [ 'admin' ] },
242 additionalProperties
=> 0,
245 description
=> "Domain name.",
246 type
=> 'string', format
=> 'transport-domain-or-email',
250 returns
=> { type
=> 'null' },
256 my $tmap = PVE
::INotify
::read_file
('transport');
258 die "Transport map entry '$param->{domain}' does not exist\n"
259 if !$tmap->{$param->{domain
}};
261 delete $tmap->{$param->{domain
}};
263 PVE
::INotify
::write_file
('transport', $tmap);
265 PMG
::Config
::postmap_pmg_transport
();
268 PMG
::Config
::lock_config
($code, "delete transport map extry failed");