From fc87cd5ec3b1393915dec05b6d21e22594e3ff3e Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sat, 14 Jan 2017 16:39:25 +0100 Subject: [PATCH] pass $title to formatter functions --- PVE/APIServer/AnyEvent.pm | 4 +++- PVE/APIServer/Formatter/Bootstrap.pm | 6 +++--- PVE/APIServer/Formatter/HTML.pm | 22 ++++++++++------------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/PVE/APIServer/AnyEvent.pm b/PVE/APIServer/AnyEvent.pm index 256febc..04b8900 100755 --- a/PVE/APIServer/AnyEvent.pm +++ b/PVE/APIServer/AnyEvent.pm @@ -740,7 +740,8 @@ sub handle_api2_request { } my $csrfgen_func = $self->can('generate_csrf_prevention_token'); - my ($raw, $ct, $nocomp) = &$formatter($res, $res->{data}, $params, $path, $auth, $csrfgen_func); + my ($raw, $ct, $nocomp) = &$formatter($res, $res->{data}, $params, $path, + $auth, $csrfgen_func, $self->{title}); my $resp; if (ref($raw) && (ref($raw) eq 'HTTP::Response')) { @@ -1579,6 +1580,7 @@ sub new { $self->{cookie_name} //= 'PVEAuthCookie'; $self->{base_uri} //= "/api2"; $self->{dirs} //= {}; + $self->{title} //= 'API Inspector'; my $base = '/usr/share/libpve-http-server-perl'; add_dirs($self->{dirs}, '/css/' => "$base/css/"); diff --git a/PVE/APIServer/Formatter/Bootstrap.pm b/PVE/APIServer/Formatter/Bootstrap.pm index c0ee3d4..ddef413 100644 --- a/PVE/APIServer/Formatter/Bootstrap.pm +++ b/PVE/APIServer/Formatter/Bootstrap.pm @@ -6,7 +6,6 @@ use URI::Escape; use HTML::Entities; use JSON; -# FIXME: page title # FIXME: cookie_name # FIXME: console code?? @@ -66,10 +65,11 @@ PVE = { _EOJS sub new { - my ($class, $res, $url, $auth, $csrfgen_func) = @_; + my ($class, $res, $url, $auth, $csrfgen_func, $title) = @_; my $self = bless { url => $url, + title => $title, js => '', }; @@ -96,7 +96,7 @@ sub body { - Proxmox VE API + $self->{title} diff --git a/PVE/APIServer/Formatter/HTML.pm b/PVE/APIServer/Formatter/HTML.pm index ca976c6..e3c5f85 100644 --- a/PVE/APIServer/Formatter/HTML.pm +++ b/PVE/APIServer/Formatter/HTML.pm @@ -18,7 +18,7 @@ my $baseurl = "/api2/$portal_format"; my $login_url = "$baseurl/access/ticket"; sub render_page { - my ($doc, $html) = @_; + my ($doc, $html, $title) = @_; my $items = []; @@ -32,8 +32,6 @@ sub render_page { }}; - my $title = "Proxmox VE"; - my $nav = $doc->el( class => "navbar navbar-inverse navbar-fixed-top", role => "navigation", cn => { @@ -167,14 +165,14 @@ PVE::APIServer::Formatter::register_login_formatter($portal_format, sub { }); PVE::APIServer::Formatter::register_formatter($portal_format, sub { - my ($res, $data, $param, $path, $auth, $csrfgen_func) = @_; + my ($res, $data, $param, $path, $auth, $csrfgen_func, $title) = @_; # fixme: clumsy! PVE::APIServer::Formatter::Standard::prepare_response_data($portal_format, $res); $data = $res->{data}; my $html = ''; - my $doc = PVE::APIServer::Formatter::Bootstrap->new($res, $path, $auth, $csrfgen_func); + my $doc = PVE::APIServer::Formatter::Bootstrap->new($res, $path, $auth, $csrfgen_func, $title); if (!HTTP::Status::is_success($res->{status})) { $html .= $doc->alert(text => "Error $res->{status}: $res->{message}"); @@ -239,7 +237,7 @@ PVE::APIServer::Formatter::register_formatter($portal_format, sub { $html = $doc->el(class => 'container', html => $html); - my $raw = render_page($doc, $html); + my $raw = render_page($doc, $html, $title); return ($raw, $portal_ct); }); @@ -248,13 +246,13 @@ PVE::APIServer::Formatter::register_page_formatter( method => 'GET', path => "/access/ticket", code => sub { - my ($res, $data, $param, $path, $auth, $csrfgen_func) = @_; + my ($res, $data, $param, $path, $auth, $csrfgen_func, $title) = @_; - my $doc = PVE::APIServer::Formatter::Bootstrap->new($res, $path, $auth, $csrfgen_func); + my $doc = PVE::APIServer::Formatter::Bootstrap->new($res, $path, $auth, $csrfgen_func, $title); my $html = &$login_form($doc); - my $raw = render_page($doc, $html); + my $raw = render_page($doc, $html, $title); return ($raw, $portal_ct); }); @@ -263,7 +261,7 @@ PVE::APIServer::Formatter::register_page_formatter( method => 'POST', path => "/access/ticket", code => sub { - my ($res, $data, $param, $path, $auth, $csrfgen_func) = @_; + my ($res, $data, $param, $path, $auth, $csrfgen_func, $title) = @_; if (HTTP::Status::is_success($res->{status})) { my $cookie = PVE::APIServer::Formatter::create_auth_cookie( @@ -277,11 +275,11 @@ PVE::APIServer::Formatter::register_page_formatter( # Note: HTTP server redirects to 'GET /access/ticket', so below # output is not really visible. - my $doc = PVE::APIServer::Formatter::Bootstrap->new($res, $path, $auth, $csrfgen_func); + my $doc = PVE::APIServer::Formatter::Bootstrap->new($res, $path, $auth, $csrfgen_func, $title); my $html = &$login_form($doc); - my $raw = render_page($doc, $html); + my $raw = render_page($doc, $html, $title); return ($raw, $portal_ct); }); -- 2.39.2