]>
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.",
25 additionalProperties
=> 0,
33 domain
=> { type
=> 'string' },
34 host
=> { type
=> 'string' },
35 port
=> { type
=> 'integer' },
36 nomx
=> { type
=> 'boolean' },
37 comment
=> { type
=> 'string'},
40 links
=> [ { rel
=> 'child', href
=> "{id}" } ],
45 my $tmap = PVE
::INotify
::read_file
('transport');
49 foreach my $domain (sort keys %$tmap) {
50 push @$res, $tmap->{$domain};
56 __PACKAGE__-
>register_method ({
62 description
=> "Add transport map entry.",
64 additionalProperties
=> 0,
67 description
=> "Domain name.",
68 type
=> 'string', format
=> 'dns-name',
71 description
=> "Target host (name or IP address).",
72 type
=> 'string', format
=> 'address',
75 description
=> "SMTP port.",
83 description
=> "Disable MX lookups.",
89 description
=> "Comment.",
95 returns
=> { type
=> 'null' },
101 my $tmap = PVE
::INotify
::read_file
('transport');
103 die "Transport map entry '$param->{domain}' already exists\n"
104 if $tmap->{$param->{domain
}};
106 $tmap->{$param->{domain
}} = {
107 domain
=> $param->{domain
},
108 host
=> $param->{host
},
109 port
=> $param->{port
} // 25,
110 nomx
=> $param->{nomx
} // 0,
111 comment
=> $param->{comment
} // '',
114 PVE
::INotify
::write_file
('transport', $tmap);
116 PMG
::Config
::postmap_pmg_transport
();
119 PMG
::Config
::lock_config
($code, "add transport map entry failed");
124 __PACKAGE__-
>register_method ({
128 description
=> "Read transport map entry.",
131 additionalProperties
=> 0,
134 description
=> "Domain name.",
135 type
=> 'string', format
=> 'dns-name',
142 domain
=> { type
=> 'string'},
143 host
=> { type
=> 'string'},
144 port
=> { type
=> 'integer'},
145 nomx
=> { type
=> 'boolean'},
146 comment
=> { type
=> 'string'},
152 my $tmap = PVE
::INotify
::read_file
('transport');
154 if (my $entry = $tmap->{$param->{domain
}}) {
158 die "Transport map entry '$param->{domain}' does not exist\n";
161 __PACKAGE__-
>register_method ({
165 description
=> "Update transport map entry.",
169 additionalProperties
=> 0,
172 description
=> "Domain name.",
173 type
=> 'string', format
=> 'dns-name',
176 description
=> "Target host (name or IP address).",
177 type
=> 'string', format
=> 'address',
181 description
=> "SMTP port.",
188 description
=> "Disable MX lookups.",
193 description
=> "Comment.",
199 returns
=> { type
=> 'null' },
205 my $tmap = PVE
::INotify
::read_file
('transport');
207 my $domain = extract_param
($param, 'domain');
209 my $data = $tmap->{$domain};
211 die "Transport map entry '$param->{domain}' does not exist\n" if !$data;
213 die "no options specified\n" if !scalar(keys %$param);
215 for my $prop (qw(host port nomx comment)) {
216 $data->{$prop} = $param->{$prop} if defined($param->{$prop});
219 PVE
::INotify
::write_file
('transport', $tmap);
221 PMG
::Config
::postmap_pmg_transport
();
224 PMG
::Config
::lock_config
($code, "update transport map entry failed");
229 __PACKAGE__-
>register_method ({
233 description
=> "Delete a transport map entry",
237 additionalProperties
=> 0,
240 description
=> "Domain name.",
241 type
=> 'string', format
=> 'dns-name',
245 returns
=> { type
=> 'null' },
251 my $tmap = PVE
::INotify
::read_file
('transport');
253 die "Transport map entry '$param->{domain}' does not exist\n"
254 if !$tmap->{$param->{domain
}};
256 delete $tmap->{$param->{domain
}};
258 PVE
::INotify
::write_file
('transport', $tmap);
260 PMG
::Config
::postmap_pmg_transport
();
263 PMG
::Config
::lock_config
($code, "delete transport map extry failed");