]>
git.proxmox.com Git - pmg-api.git/blob - src/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 protocol
=> { type
=> 'string' },
37 port
=> { type
=> 'integer' },
38 use_mx
=> { type
=> 'boolean' },
39 comment
=> { type
=> 'string'},
42 links
=> [ { rel
=> 'child', href
=> "{domain}" } ],
47 my $tmap = PVE
::INotify
::read_file
('transport');
51 foreach my $domain (sort keys %$tmap) {
52 push @$res, $tmap->{$domain};
58 __PACKAGE__-
>register_method ({
64 permissions
=> { check
=> [ 'admin' ] },
65 description
=> "Add transport map entry.",
67 additionalProperties
=> 0,
70 description
=> "Domain name.",
71 type
=> 'string', format
=> 'transport-domain-or-email',
74 description
=> "Target host (name or IP address).",
75 type
=> 'string', format
=> 'address',
78 description
=> "Transport protocol.",
80 enum
=> [qw(smtp lmtp)],
85 description
=> "Transport port.",
93 description
=> "Enable MX lookups (SMTP).",
99 description
=> "Comment.",
105 returns
=> { type
=> 'null' },
111 my $tmap = PVE
::INotify
::read_file
('transport');
113 die "Transport map entry '$param->{domain}' already exists\n"
114 if $tmap->{$param->{domain
}};
116 $tmap->{$param->{domain
}} = {
117 domain
=> $param->{domain
},
118 host
=> $param->{host
},
119 protocol
=> $param->{protocol
} // 'smtp',
120 port
=> $param->{port
} // 25,
121 use_mx
=> $param->{use_mx
} // 1,
122 comment
=> $param->{comment
} // '',
125 PVE
::INotify
::write_file
('transport', $tmap);
127 PMG
::Config
::postmap_pmg_transport
();
130 PMG
::Config
::lock_config
($code, "add transport map entry failed");
135 __PACKAGE__-
>register_method ({
139 description
=> "Read transport map entry.",
141 permissions
=> { check
=> [ 'admin', 'audit' ] },
143 additionalProperties
=> 0,
146 description
=> "Domain name.",
147 type
=> 'string', format
=> 'transport-domain-or-email',
154 domain
=> { type
=> 'string'},
155 host
=> { type
=> 'string'},
156 protocol
=> { type
=> 'string'},
157 port
=> { type
=> 'integer'},
158 use_mx
=> { type
=> 'boolean'},
159 comment
=> { type
=> 'string'},
165 my $tmap = PVE
::INotify
::read_file
('transport');
167 if (my $entry = $tmap->{$param->{domain
}}) {
171 die "Transport map entry '$param->{domain}' does not exist\n";
174 __PACKAGE__-
>register_method ({
178 description
=> "Update transport map entry.",
180 permissions
=> { check
=> [ 'admin' ] },
183 additionalProperties
=> 0,
186 description
=> "Domain name.",
187 type
=> 'string', format
=> 'transport-domain-or-email',
190 description
=> "Target host (name or IP address).",
191 type
=> 'string', format
=> 'address',
195 description
=> "Transport protocol.",
197 enum
=> [qw(smtp lmtp)],
202 description
=> "Transport port.",
209 description
=> "Enable MX lookups (SMTP).",
214 description
=> "Comment.",
220 returns
=> { type
=> 'null' },
226 my $tmap = PVE
::INotify
::read_file
('transport');
228 my $domain = extract_param
($param, 'domain');
230 my $data = $tmap->{$domain};
232 die "Transport map entry '$param->{domain}' does not exist\n" if !$data;
234 die "no options specified\n" if !scalar(keys %$param);
236 for my $prop (qw(host protocol port use_mx comment)) {
237 $data->{$prop} = $param->{$prop} if defined($param->{$prop});
240 PVE
::INotify
::write_file
('transport', $tmap);
242 PMG
::Config
::postmap_pmg_transport
();
245 PMG
::Config
::lock_config
($code, "update transport map entry failed");
250 __PACKAGE__-
>register_method ({
254 description
=> "Delete a transport map entry",
256 permissions
=> { check
=> [ 'admin' ] },
259 additionalProperties
=> 0,
262 description
=> "Domain name.",
263 type
=> 'string', format
=> 'transport-domain-or-email',
267 returns
=> { type
=> 'null' },
273 my $tmap = PVE
::INotify
::read_file
('transport');
275 die "Transport map entry '$param->{domain}' does not exist\n"
276 if !$tmap->{$param->{domain
}};
278 delete $tmap->{$param->{domain
}};
280 PVE
::INotify
::write_file
('transport', $tmap);
282 PMG
::Config
::postmap_pmg_transport
();
285 PMG
::Config
::lock_config
($code, "delete transport map extry failed");