Advertisement
Guest User

Untitled

a guest
Apr 5th, 2012
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2.  
  3. use strict;
  4. use mod_perl2 '1.9922';
  5. use Encode;
  6. use CGI;
  7. use PVE::pvecfg;
  8. use PVE::JSONSchema;
  9. use PVE::AccessControl;
  10. use PVE::REST;
  11.  
  12. sub send_output {
  13. my ($r, $data) = @_;
  14.  
  15. $r->no_cache (1);
  16. my $x = length ($data);
  17. $r->content_type ("text/html;charset=UTF-8");
  18. $r->headers_out->set ("Content-length", "$x");
  19. $r->headers_out->set ("Pragma", "no-cache");
  20.  
  21. $r->print ($data);
  22. }
  23.  
  24. # NOTE: Requests to this page are not authenticated
  25. # so we must be very careful here
  26.  
  27. my $lang = 'en';
  28.  
  29. my $r = Apache2::RequestUtil->request();
  30. my $username;
  31. my $token = 'null';
  32. if (my $cookie = $r->headers_in->{Cookie}) {
  33.  
  34. if (my $newlang = ($cookie =~ /(?:^|\s)PVELangCookie=([^;]*)/)[0]) {
  35. if ($newlang =~ m/^[a-z]{2,3}(_[A-Z]{2,3})?$/) {
  36. $lang = $newlang;
  37. }
  38. }
  39.  
  40. my $ticket = PVE::REST::extract_auth_cookie($cookie);
  41. if (($username = PVE::AccessControl::verify_ticket($ticket, 1))) {
  42. $token = PVE::AccessControl::assemble_csrf_prevention_token($username);
  43. }
  44. }
  45. my $version = PVE::pvecfg::version_text();
  46. $username = '' if !$username;
  47.  
  48. my $cgi = CGI->new($r);
  49. my %args = $cgi->Vars();
  50.  
  51. my $workspace = defined($args{console}) ?
  52. "PVE.ConsoleWorkspace" : "PVE.StdWorkspace";
  53.  
  54. my $jssrc = <<_EOJS;
  55. if (!PVE) PVE = {};
  56. PVE.GUIVersion = '$version';
  57. PVE.UserName = '$username';
  58. PVE.CSRFPreventionToken = '$token';
  59. _EOJS
  60.  
  61. my $langfile = "/usr/share/pve-manager/ext4/locale/ext-lang-${lang}.js";
  62. $jssrc .= PVE::Tools::file_get_contents($langfile) if -f $langfile;
  63.  
  64. my $i18nsrc;
  65. $langfile = "/usr/share/pve-manager/root/pve-lang-${lang}.js";
  66. if (-f $langfile) {
  67. $i18nsrc = PVE::Tools::file_get_contents($langfile);
  68. } else {
  69. $i18nsrc = 'function gettext(buf) { return buf; }';
  70. }
  71.  
  72. $jssrc .= <<_EOJS;
  73.  
  74. // we need this (the java applet ignores the zindex)
  75. Ext.useShims = true;
  76.  
  77. Ext.History.fieldid = 'x-history-field';
  78.  
  79. Ext.onReady(function() { Ext.create('$workspace');});
  80.  
  81. _EOJS
  82.  
  83. my $page = <<_EOD;
  84. <html>
  85. <head>
  86. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  87.  
  88. <title>Proxmox Virtual Environment</title>
  89.  
  90. <link rel="stylesheet" type="text/css" href="/pve2/ext4/resources/css/ext-all.css" />
  91. <link rel="stylesheet" type="text/css" href="/pve2/css/ext-pve.css" />
  92.  
  93. <script type="text/javascript">$i18nsrc</script>
  94. <script type="text/javascript" src="/pve2/ext4/ext-all-debug.js"></script>
  95. <script type="text/javascript" src="/pve2/ext4/pvemanagerlib.js"></script>
  96. <script type="text/javascript">$jssrc</script>
  97.  
  98. </head>
  99. <body>
  100. <!-- Fields required for history management -->
  101. <form id="history-form" class="x-hidden">
  102. <input type="hidden" id="x-history-field"/>
  103. </form>
  104. <!-- Fields required for login form completion -->
  105. <iframe name="hiddenloginiframe" class="x-hidden" src=""></iframe>
  106. <form name="hiddenlogin" class="x-hidden" target="hiddenloginiframe">
  107. <input type="text" name="username" autocomplete="on" value=""/>
  108. <input type="password" name="password" autocomplete="on" value=""/>
  109. </form>
  110. </body>
  111. </html>
  112. _EOD
  113.  
  114. send_output ($r, $page);
  115. exit (0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement