[! 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 ('ipconfig', 'ssh_allow') || ""; my $fieldnames = { h => __("Hostname/IP Address"), d => __("Domain"), n => __("IP Address"), }; my $typedesc = { n => __('Network'), h => __('Host'), d => __('Domain'), }; if ($frm->submit) { if ($udat{AM} eq 'w') { my $err; # fixme: verify my $host = $fdat{host}; eval { Proxmox::Utils::check_field ($fieldnames->{$fdat{itype}}, $host, 'NOTEMPTY', 'NOWHITESPACES','CHAREXCL:[,;&:]'); }; $err = $@ if $@; $host = ".$host" if ($fdat{itype} eq 'd'); my $mask = $fdat{mask}; $mask = '' if $mask eq '255.255.255.255'; my $value; if ($mask) { my $bits = Proxmox::Utils::ip_mask_bits ($mask); $err = "illegal subnet mask" if $mask ne Proxmox::Utils::bits_to_mask ($bits); $value = "$host/$mask"; } else { $value = $host; } if (!$err && (!$fdat{aa} || ($fdat{aa} ne $value))) { foreach my $t (sort split (/\s+/, $networks)) { if ($t eq $value){ $err = __("host/network already exists"); last; } } } if (!$err) { my @res = (); foreach my $t (sort split (/\s+/, $networks)) { push @res, $t if $t ne $fdat{aa}; } $networks = join (' ', @res); $networks .= " " if $networks; $networks .= $mask ? "$host/$mask" : $host; $system_cfg->set ('ipconfig', 'ssh_allow', $networks); $system_cfg->save(); $conn->rewrite_config_access (); } 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 (/\s+/, $networks)) { push @res, $t if $t ne $fdat{aa}; } $networks = join (' ', @res); $system_cfg->set ('ipconfig', 'ssh_allow', $networks); $system_cfg->save(); $conn->rewrite_config_access (); } 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', "text", $host, $fieldnames->{$fdat{itype}}); $frm->add_element('mask', "hidden", ''); } elsif ($fdat{itype} eq 'd') { my $title = $fdat{aa} ? __("Edit Domain") : __("Add Domain"); $frm->add_element("section1", "hsection", undef, $title); my $v = $host; $v =~ s/^\.//; $frm->add_element('host', "text", $v, $fieldnames->{$fdat{itype}}); $frm->add_element('mask', "hidden", ''); } 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", $fieldnames->{$fdat{itype}}); $frm->add_element('mask', "ip", $mask || "255.255.255.0", __("Subnet Mask")); } $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', __('Value'), '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=d&edit=2", __("Add Domain")); $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 (/\s+/, $networks)) { my ($host, $mask) = split ('/', $t); my $itype; if (!$mask) { if ($host =~ m/^\./) { $itype = 'd'; $host =~ s/^\.//; } else { $itype = 'h'; } } else { $itype = 'n'; } my $typetxt = $typedesc->{$itype}; my $menu = $ddown->out_symbol ('menu1', '', "&itype=$itype&aa=$t"); $table->set_row_link ("?edit=1&itype=$itype&aa=$t"); $table->add_row ('' ,$menu, '', $typetxt, $host, $itype eq "n" ? $mask : "-"); } $out .= $ddown->out_dropdown_menu("menu"); $out .= "

" . $ddown->out_symbol("menu", "iarrdown") . " " . __("Allowed IP Networks/Hosts") . "


"; $out .= $ddown->out_dropdown_menu ("menu1"); $out .= $table->out_table (); } print OUT $out; -]