[! use strict; use Proxmox::Form; use Proxmox::Utils; use Proxmox::Config::System; use Proxmox::ConfigServer; use Proxmox::License; use Proxmox::HTMLTable; use Proxmox::HTMLDropDown; !] [- my $out = ""; my $frm = Proxmox::Form->new (\%fdat); my $conn = Proxmox::ConfigClient::connect (); my $system_cfg = $fdat{__system_config}; my $networks = $system_cfg->get ('mail', 'networks') || ""; if ($frm->submit) { if ($udat{AM} eq 'w') { my $err; # fixme: verify my $host = $fdat{host}; my $mask = $fdat{mask}; my $bits = Proxmox::Utils::ip_mask_bits ($mask); $err = "illegal subnet mask" if $mask ne Proxmox::Utils::bits_to_mask ($bits); if (!$err && (!$fdat{aa} || ($fdat{aa} ne "$host/$mask"))) { foreach my $t (sort split (/,/, $networks)) { if ($t eq "$host/$mask"){ $err = __("host/network already exists"); last; } } } if (!$err) { my @res = (); foreach my $t (sort split (/,/, $networks)) { push @res, $t if $t ne $fdat{aa}; } $networks = join (',', @res); $networks .= "," if $networks; $networks .= "$host/$mask"; $system_cfg->set ('mail', 'networks', $networks); $system_cfg->save(); $conn->rewrite_config_postfix (); $conn->service_cmd ('postfix', 'reload'); } else { $fdat{edit} = $fdat{mode}; $udat{popup_error} = $err; } } else { $udat{popup_error} = Proxmox::Utils::msg ('nowr'); } } else { if ($udat{action} eq 'delitem') { if ($udat{AM} eq 'w') { my @res = (); foreach my $t (sort split (/,/, $networks)) { push @res, $t if $t ne $fdat{aa}; } $networks = join (',', @res); $system_cfg->set ('mail', 'networks', $networks); $system_cfg->save(); $conn->rewrite_config_postfix (); $conn->service_cmd ('postfix', 'reload'); } else { $udat{popup_error} = Proxmox::Utils::msg ('nowr'); } } } if ($fdat{edit} == 1 || ($fdat{edit} == 2 && $udat{AM} eq 'w')) { my ($host, $mask) = split ('/', $fdat{aa}); if ($fdat{itype} eq 'h') { my $title = $fdat{aa} ? __("Edit Host") : __("Add Host"); $frm->add_element("section1", "hsection", undef, $title); $frm->add_element('host', "ip", $host || "127.0.0.1", __("IP Address")); $frm->add_element('mask', "hidden", "255.255.255.255"); } else { my $title = $fdat{aa} ? __("Edit Network") : __("Add Network"); $frm->add_element("section1", "hsection", undef, $title); $frm->add_element('host', "ip", $host || "127.0.0.1", __("IP Address")); $frm->add_element('mask', "ip", $mask || "255.255.255.0", __("Subnet Mask")); } $frm->add_element("m3", "hidden"); $frm->add_element("aa", "hidden", $fdat{aa}); $frm->add_element("itype", "hidden", $fdat{itype}); $frm->add_element("mode", "hidden", $fdat{edit}); $out .= $frm->out_form; } else { if ($fdat{edit}) { $udat{popup_error} = Proxmox::Utils::msg ('nowr'); } my @header = ('1', '20px', ' ', '1', '10px', ' ', '1', '100px', __("Type"), '1', '290px', 'IP', '1', '290px', __("Mask")); my @cellwidth = ('20px', '10px', '100px', '290px','290px'); my $table = Proxmox::HTMLTable->new (\@cellwidth); $table->add_headline (\@header); my $ddown = Proxmox::HTMLDropDown->new (); $ddown->add_item ("menu", "?itype=h&edit=2", __("Add Host")); $ddown->add_item ("menu", "?itype=n&edit=2", __("Add Network")); $ddown->add_item ('menu1', "?edit=1", __('Edit')); $ddown->add_item ('menu1', "?action=delitem", __('Delete')); foreach my $t (sort split (/,/, $networks)) { my ($host, $mask) = split ('/', $t); my $type = $mask eq "255.255.255.255" ? "Host" : "Network"; my $menu; my $typetxt; if ($type eq "Network") { $menu = $ddown->out_symbol ('menu1', '', "&itype=n&aa=$t"); $table->set_row_link ("?edit=1&itype=n&aa=$t"); $typetxt = __('Network'); } else { $menu = $ddown->out_symbol ('menu1', '', "&itype=h&aa=$t"); $table->set_row_link ("?edit=1&itype=h&aa=$t"); $typetxt = __('Host'); } $table->add_row ('' ,$menu, '', $typetxt, $host, $type eq "Network" ? $mask : "-"); } $out .= $ddown->out_dropdown_menu("menu"); $out .= "