mirror of
https://git.proxmox.com/git/pve-http-server
synced 2025-06-30 17:25:06 +00:00
pass $title to formatter functions
This commit is contained in:
parent
968a4a6d5d
commit
fc87cd5ec3
@ -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/");
|
||||
|
@ -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 {
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Proxmox VE API</title>
|
||||
<title>$self->{title}</title>
|
||||
|
||||
<!-- Bootstrap -->
|
||||
<link href="/css/bootstrap.min.css" rel="stylesheet">
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user