#!/usr/bin/perl -w use strict; use mod_perl2 '1.9922'; use Encode; use CGI; use PVE::pvecfg; use PVE::JSONSchema; use PVE::AccessControl; use PVE::REST; sub send_output { my ($r, $data) = @_; $r->no_cache (1); my $x = length ($data); $r->content_type ("text/html;charset=UTF-8"); $r->headers_out->set ("Content-length", "$x"); $r->headers_out->set ("Pragma", "no-cache"); $r->print ($data); } # NOTE: Requests to this page are not authenticated # so we must be very careful here my $lang = 'en'; my $r = Apache2::RequestUtil->request(); my $username; my $token = 'null'; if (my $cookie = $r->headers_in->{Cookie}) { if (my $newlang = ($cookie =~ /(?:^|\s)PVELangCookie=([^;]*)/)[0]) { if ($newlang =~ m/^[a-z]{2,3}(_[A-Z]{2,3})?$/) { $lang = $newlang; } } my $ticket = PVE::REST::extract_auth_cookie($cookie); if (($username = PVE::AccessControl::verify_ticket($ticket, 1))) { $token = PVE::AccessControl::assemble_csrf_prevention_token($username); } } my $version = PVE::pvecfg::version_text(); $username = '' if !$username; my $cgi = CGI->new($r); my %args = $cgi->Vars(); my $workspace = defined($args{console}) ? "PVE.ConsoleWorkspace" : "PVE.StdWorkspace"; my $jssrc = <<_EOJS; if (!PVE) PVE = {}; PVE.GUIVersion = '$version'; PVE.UserName = '$username'; PVE.CSRFPreventionToken = '$token'; _EOJS my $langfile = "/usr/share/pve-manager/ext4/locale/ext-lang-${lang}.js"; $jssrc .= PVE::Tools::file_get_contents($langfile) if -f $langfile; my $i18nsrc; $langfile = "/usr/share/pve-manager/root/pve-lang-${lang}.js"; if (-f $langfile) { $i18nsrc = PVE::Tools::file_get_contents($langfile); } else { $i18nsrc = 'function gettext(buf) { return buf; }'; } $jssrc .= <<_EOJS; // we need this (the java applet ignores the zindex) Ext.useShims = true; Ext.History.fieldid = 'x-history-field'; Ext.onReady(function() { Ext.create('$workspace');}); _EOJS my $page = <<_EOD;