[! use strict; use Proxmox::Form; use Proxmox::Utils; use Proxmox::Config::System; use Proxmox::ConfigServer; use Proxmox::HTMLTable; use Proxmox::HTMLDropDown; use HTML::Entities; !] [- my $frm = Proxmox::Form->new (\%fdat); my $system_cfg = $fdat{__system_config}; my $url = $req_rec->uri; my $out = ""; my $conn = Proxmox::ConfigClient::connect (); if ($udat{action}) { if ($udat{AM} eq 'w') { if ($udat{action} eq 'awaken') { my $fetchmail_state = $conn->service_state ('fetchmail')->result; if ($fetchmail_state eq 'running') { $conn->service_cmd ('fetchmail', 'awaken'); } else { $conn->service_cmd ('fetchmail', 'restart'); } } } else { $udat{popup_error} = Proxmox::Utils::msg ('nowr'); } } my $fmconfig = Proxmox::Config::System::load_fmconfig; if ($udat{action} eq 'delete') { if ($udat{AM} eq 'w') { if ($fdat{aa} && defined ($fmconfig->{$fdat{aa}})) { delete $fmconfig->{$fdat{aa}}; Proxmox::Config::System::save_fmconfig ($fmconfig); $conn->rewrite_config_fetchmail (); } } else { $udat{popup_error} = Proxmox::Utils::msg ('nowr'); } } if ($frm->postback) { if ($fdat{usessl}) { $fdat{port} = 995 if $fdat{port} == 110; } else { $fdat{port} = 110 if $fdat{port} == 995; } $fdat{edit} = $fdat{mode}; } elsif ($frm->submit) { if ($udat{AM} eq 'w') { my $err; $fdat{server} = Proxmox::Utils::trim ($fdat{server}); $fdat{user} = Proxmox::Utils::trim ($fdat{user}); $fdat{target} = Proxmox::Utils::trim ($fdat{target}); eval { Proxmox::Utils::check_field (__('Server'), $fdat{server}, 'NOTEMPTY', 'NOWHITESPACES', 'CHAREXCL:[\'\"\:\,\;]'); Proxmox::Utils::check_field (__('Username'), $fdat{user}, 'NOTEMPTY', 'NOWHITESPACES'); Proxmox::Utils::check_field (__('Password'), $fdat{passwd}, 'NOTEMPTY'); Proxmox::Utils::check_field (__('Deliver to'), $fdat{target}, 'NOTEMPTY', 'NOWHITESPACES', 'EMAIL'); }; $err = $@; if (($frm->submit == 1) && !$err) { my $pollid; if ($fdat{mode} == 2) { for (my $i = 1; $i < 10000; $i++) { my $id = sprintf ("proxmox%04d", $i); next if defined ($fmconfig->{$id}); $pollid = $id; last; } } else { $pollid = $fdat{aa}; } my $data = { id => $pollid, server => $fdat{server}, protocol => 'pop3', ssl => $fdat{usessl}, keep => $fdat{keep}, port => $fdat{port}, user => $fdat{user}, pass => $fdat{passwd}, target => $fdat{target}, interval => $fdat{interval} }; $fmconfig->{$pollid} = $data; Proxmox::Config::System::save_fmconfig ($fmconfig); $conn->rewrite_config_fetchmail (); my $fetchmail_state = $conn->service_state ('fetchmail')->result; if ($fetchmail_state ne 'running') { $conn->service_cmd ('fetchmail', 'restart'); } } else { $udat{popup_error} = $err; $fdat{edit} = $fdat{mode}; } } else { $udat{popup_error} = Proxmox::Utils::msg ('nowr'); } } if ($fdat{edit} == 1 || ($fdat{edit} == 2 && $udat{AM} eq 'w')) { my $pollid = $fdat{aa}; my $data = $fmconfig->{$pollid}; my $title = $fdat{aa} ? __("Edit user") : __("Create new user"); $frm->add_element("section1", "hsection", undef, $title); $frm->add_element('server', "text", $data->{server}, __("Server")); $frm->add_element('usessl', 'dynamicbool', $data->{ssl}, __("Use SSL")); $frm->add_element('keep', 'bool', $data->{keep}, __("Keep old mails")); $frm->add_element('port', 'port', $data->{port}, __("Port")); $frm->add_element('user', "text", $data->{user}, __("Username")); $frm->add_element('passwd', "password", $data->{pass}, __("Password")); $frm->add_element('target', "text", $data->{target}, __("Deliver to")); $frm->add_element('interval', "dropdown",$data->{interval}, __("Interval"), [[ 5, '5 min'], [ 15, '15 min'], [ 30, '30 min'], [ 60, '1 hour'], [ 60*6, '6 hours'], [ 60*12, '12 hours'], [ 0, 'Never (inactive)']]); $frm->add_element("m3", "hidden"); $frm->add_element("aa", "hidden", $pollid); $frm->add_element("mode", "hidden", $fdat{edit}); $out .= $frm->out_form; } else { my $ddown = Proxmox::HTMLDropDown->new (); $ddown->add_item("menu0","$url?edit=2", __("Create new user")); $ddown->add_item("menu0","$url?action=awaken", __("Start downloading now")); $ddown->add_item("menu1","$url?edit=1", __("Edit user")); $ddown->add_item("menu1","$url?action=delete", __("Delete")); $ddown->add_item("menu2","$url?edit=1", __("Edit user")); my @cellwidth = ( '20px', '10px', '200px', '200px', '200px', '50px'); my @header = ( '1', '20px', ' ', '1', '10px', ' ', '1', '200px', __('Server'), '1', '200px', __('Username'), '1', '200px', __('Deliver to'), '1', '50px', __('Interval'), ); my $table = Proxmox::HTMLTable->new (\@cellwidth); $table->add_headline (\@header); foreach my $k (sort {$fmconfig->{$a}->{server} cmp $fmconfig->{$b}->{server}} keys %$fmconfig) { my $ref = $fmconfig->{$k}; my $menu = $ddown->out_symbol ("menu1","","&aa=$ref->{id}"); $table->set_row_link ("$url?edit=1&aa=$ref->{id}"); my $astr = $ref->{interval} ? $ref->{interval} : '-'; $table->add_row ('', $menu, '', $ref->{server}, $ref->{user}, $ref->{target}, $astr); } $out .= $ddown->out_dropdown_menu("menu0"); $out .= $ddown->out_dropdown_menu("menu1"); $out .= $ddown->out_dropdown_menu("menu2"); $out .= "

" . $ddown->out_symbol("menu0", "iarrdown") . " " . __("POP3 Accounts") . "


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