]> git.proxmox.com Git - pve-http-server.git/commitdiff
pass $title to formatter functions
authorDietmar Maurer <dietmar@proxmox.com>
Sat, 14 Jan 2017 15:39:25 +0000 (16:39 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Sat, 14 Jan 2017 15:39:25 +0000 (16:39 +0100)
PVE/APIServer/AnyEvent.pm
PVE/APIServer/Formatter/Bootstrap.pm
PVE/APIServer/Formatter/HTML.pm

index 256febc003de3caac655588f7113f7dd73baedfc..04b8900f81c5239f4b10d41af07ba76b714ff0a7 100755 (executable)
@@ -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/");
index c0ee3d42e2f0f6f6839f13bf8f55e1474198b000..ddef41375a712bd1939ec3629f49152b6c39c035 100644 (file)
@@ -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">
index ca976c60d25201b68c67b46024104698886b45a0..e3c5f8512f1d1f6698dc5570deea3a604339534d 100644 (file)
@@ -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);
     });