Advertisement
Guest User

Untitled

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