[! use strict; use GD; use Proxmox::Form; use Proxmox::Utils; use Proxmox::ConfigServer; use Proxmox::Config::System; !] [- my $frm = Proxmox::Form->new (\%fdat); my $system_cfg = $fdat{__system_config}; my $logofn = "/etc/proxmox/custom-logo.png"; my $out = ''; my $fieldname = { col_std => __("Standard Foreground Color"), col_menubg => __("Menu Background Color"), col_highlight => __("Highlight Color"), col_inputbg => __("Input Field Color"), }; $frm->add_cfg_element ('spamquar', 'col_std', "text", undef, $fieldname->{'col_std'}); $frm->add_cfg_element ('spamquar', 'col_menubg', "text", undef, $fieldname->{col_menubg}); $frm->add_cfg_element ('spamquar', 'col_highlight', "text", undef, $fieldname->{'col_highlight'}); $frm->add_cfg_element ('spamquar', 'col_inputbg', "text", undef, $fieldname->{'col_inputbg'}); $frm->add_element(__("reset colors"), "link", "?action=resetcols", ''); $frm->add_cfg_element ('spamquar', 'logolink', "text", undef, __("Custom HREF")); # DUMMY ACTION to force a redirect to the same page - user can press reload $frm->add_element ('action', "hidden", 'reloadcol'); $frm->add_element ('logofile', "file", '', __('Upload custom logo') . ' (png,gif,jpg)', ''); if (-f $logofn) { $frm->add_element(__("delete custom logo"), "link", "?action=deletelogo", ''); } sub apply_cfg { my $conn = Proxmox::ConfigClient::connect (); $conn->rewrite_config_css (); } if ($udat{action}) { if ($udat{AM} eq 'w') { if ($udat{action} eq 'deletelogo') { unlink $logofn; } elsif ($udat{action} eq 'resetcols') { $system_cfg->reset_value ('spamquar', 'col_std'); $system_cfg->reset_value ('spamquar', 'col_menubg'); $system_cfg->reset_value ('spamquar', 'col_highlight'); $system_cfg->reset_value ('spamquar', 'col_inputbg'); $system_cfg->save(); apply_cfg(); } else { # ignore other actions } } else { $udat{popup_error} = Proxmox::Utils::msg ('nowr'); } } if ($frm->submit==0) { $frm->load_cfg ($system_cfg); } else { if ($udat{AM} eq 'w') { eval { Proxmox::Utils::check_field ($fieldname->{'col_std'}, $fdat{col_std}, 'HTMLCOLOR'); Proxmox::Utils::check_field ($fieldname->{'col_menubg'}, $fdat{col_menubg}, 'HTMLCOLOR'); Proxmox::Utils::check_field ($fieldname->{'col_highlight'}, $fdat{col_highlight}, 'HTMLCOLOR'); Proxmox::Utils::check_field ($fieldname->{'col_inputbg'}, $fdat{col_inputbg}, 'HTMLCOLOR'); }; if ($@) { $udat{popup_error} = $@; } else { if ($fdat{logofile}) { # fixme: check file format my $buffer = ""; my $tmpfn = "$logofn.tmp"; eval { open FILE, ">$tmpfn"; print FILE $buffer while read($fdat{logofile}, $buffer, 32768); close FILE; if (my $image = GD::Image->new ($tmpfn)) { rename $tmpfn, $logofn; } else { $udat{popup_error} = __('Unable to upload image - wrong format'); } }; unlink $tmpfn; } $frm->save_cfg ($system_cfg); apply_cfg(); } } else { $udat{popup_error} = Proxmox::Utils::msg ('nowr'); } } $out .= $frm->out_form; print OUT $out; -]