[pve-devel] r4839 - in pve-manager/pve2: bin/test debian lib/PVE www/manager

svn-commits at proxmox.com svn-commits at proxmox.com
Thu Jun 24 14:12:10 CEST 2010


Author: dietmar
Date: 2010-06-24 12:12:10 +0000 (Thu, 24 Jun 2010)
New Revision: 4839

Added:
   pve-manager/pve2/bin/test/example1.pl
Removed:
   pve-manager/pve2/www/manager/base64.js
Modified:
   pve-manager/pve2/debian/control.in
   pve-manager/pve2/lib/PVE/API2.pm
   pve-manager/pve2/lib/PVE/API2Client.pm
   pve-manager/pve2/lib/PVE/APIDaemon.pm
   pve-manager/pve2/lib/PVE/OpenVZ.pm
   pve-manager/pve2/lib/PVE/REST.pm
   pve-manager/pve2/lib/PVE/RESTHandler.pm
   pve-manager/pve2/www/manager/LoginWindow.js
Log:
done more work on the REST API



Added: pve-manager/pve2/bin/test/example1.pl
===================================================================
--- pve-manager/pve2/bin/test/example1.pl	                        (rev 0)
+++ pve-manager/pve2/bin/test/example1.pl	2010-06-24 12:12:10 UTC (rev 4839)
@@ -0,0 +1,21 @@
+#!/usr/bin/perl -w
+
+
+use strict;
+use PVE::API2Client;
+
+use Data::Dumper;
+
+my $ticket = "root::root::";
+
+my $conn = PVE::API2Client->new(
+    username => 'root',
+    password => 'admin',
+#    ticket => $ticket,
+   host => 'lana',
+#   host => 'localhost',
+    );
+
+my $res = $conn->post("api2/", {});
+
+print "TEST: " . Dumper($res);


Property changes on: pve-manager/pve2/bin/test/example1.pl
___________________________________________________________________
Added: svn:executable
   + *

Modified: pve-manager/pve2/debian/control.in
===================================================================
--- pve-manager/pve2/debian/control.in	2010-06-24 05:22:01 UTC (rev 4838)
+++ pve-manager/pve2/debian/control.in	2010-06-24 12:12:10 UTC (rev 4839)
@@ -3,7 +3,7 @@
 Section: admin
 Priority: optional
 Architecture: all
-Depends: perl5, libtimedate-perl, apache2-mpm-prefork, postfix (>= 2.2.8), libembperl-perl, libauthen-pam-perl, libintl-perl, libfilesys-smbclient-perl, rsync, libsoap-lite-perl, libapache-authcookie-perl, libgd-graph-perl, libapache2-request-perl, atsar, libjson-perl, libfile-sync-perl, libdigest-sha1-perl, vncterm, qemu-server (>= 1.1-1), libwww-perl, wget, libnet-dns-perl, vlan, ifenslave-2.6 (>= 1.1.0-10), liblinux-inotify2-perl, debconf (>= 0.5) | debconf-2.0, libjs-prototype (>= 1.6.0.3-1), netcat-traditional, libpve-storage-perl, libterm-readline-gnu-perl
+Depends: perl5, libtimedate-perl, apache2-mpm-prefork, postfix (>= 2.2.8), libembperl-perl, libauthen-pam-perl, libintl-perl, libfilesys-smbclient-perl, rsync, libsoap-lite-perl, libapache-authcookie-perl, libgd-graph-perl, libapache2-request-perl, atsar, libjson-perl, libfile-sync-perl, libdigest-sha1-perl, vncterm, qemu-server (>= 1.1-1), libwww-perl, wget, libnet-dns-perl, vlan, ifenslave-2.6 (>= 1.1.0-10), liblinux-inotify2-perl, debconf (>= 0.5) | debconf-2.0, libjs-prototype (>= 1.6.0.3-1), netcat-traditional, libpve-storage-perl, libterm-readline-gnu-perl, libhttp-request-params-perl
 Conflicts: netcat-openbsd
 Maintainer: Proxmox Support Team <support at proxmox.com>
 Description: The Proxmox Virtul Environment

Modified: pve-manager/pve2/lib/PVE/API2.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2.pm	2010-06-24 05:22:01 UTC (rev 4838)
+++ pve-manager/pve2/lib/PVE/API2.pm	2010-06-24 12:12:10 UTC (rev 4839)
@@ -54,6 +54,7 @@
 	    ],
     },
 }); 
+
 sub index {
     my ($conn, $resp) = @_;
     

Modified: pve-manager/pve2/lib/PVE/API2Client.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2Client.pm	2010-06-24 05:22:01 UTC (rev 4838)
+++ pve-manager/pve2/lib/PVE/API2Client.pm	2010-06-24 12:12:10 UTC (rev 4839)
@@ -7,61 +7,89 @@
 use LWP::UserAgent;
 use JSON;
 use PVE::API2;
+use Data::Dumper; # fixme: remove
 
-sub BEGIN {
-    no strict 'refs'; 
-    #print "making accessors\n";
+sub get {
+    my ($self, $path, $param) = @_;
 
-    foreach my $member (qw (test)) {
+    return $self->call('GET', $path, $param);
+}
 
-	*{$member} = sub { 
-	    my ($self, %param) = @_;
+sub post {
+    my ($self, $path, $param) = @_;
+
+    return $self->call('POST', $path, $param);
+}
+
+sub call {
+    my ($self, $method, $path, $param) = @_;
 	
-	    #print "wrapper called\n";
-       
-	    my $func = PVE::API2->can($member) ||
-		die "no such method";
+    #print "wrapper called\n";
 
-	    my $method = 'POST';
+    my $ticket;
 
-	    $method = "GET" if PVE::API2->check_attribute($member, "GET");
+    my $ua = $self->{useragent};
+    my $cj = $self->{cookie_jar};
 
-	    my $uri = URI->new("http://$self->{config}->{host}/api2/$member");
+    $cj->scan(sub {
+	my ($version, $key, $val) = @_;
+	$ticket = $val if $key eq 'PVEAuthCookie';
+    });
+    
+    if (!$ticket && $self->{username} && $self->{password}) {
+	my $uri = URI->new();
+	$uri->scheme($self->{protocol});
+	$uri->host($self->{host});
+	$uri->port($self->{port});
+	$uri->path('/api2/ticket');
 
-	    if ($method eq 'GET') {
-		$uri->query_form(\%param);
-	    }
+	my $response = $ua->post($uri, { 
+	    username => $self->{username},
+	    password => $self->{password}});
 
-	    #print "CALL : " .  $uri->as_string() . "\n";
-	    #print "PATH : " .  $uri->path() . "\n";
+	if (!$response->is_success) {
+	    die $response->status_line . "\n";
+	}
+    }
 
-	    my $ua = $self->{useragent};
+    my $uri = URI->new();
+    $uri->scheme($self->{protocol});
+    $uri->host($self->{host});
+    $uri->port($self->{port});
+    $uri->path($path);
 
-	    my $response;
-	    if ($method eq 'GET') {
-		$response = $ua->get($uri);
-	    } elsif ($method eq 'POST') {
-		$response = $ua->post($uri, \%param);
-	    } else {
-		die "method $method not implemented\n";
-	    }
 
-	    if ($response->is_success) {
-		my $ct = $response->header('Content-Type');
+    print $ua->{cookie_jar}->as_string;
 
-		die "got unexpected content type" if $ct ne 'application/json';
+    my $response;
+    if ($method eq 'GET') {
+	$uri->query_form($param);
+	print "CALL GET : " .  $uri->as_string() . "\n";
+	$response = $ua->get($uri);
+	print "RESP: " . Dumper($response) . "\n";
+    } elsif ($method eq 'POST') {
+	print "CALL POST : " .  $uri->as_string() . "\n";
+	$response = $ua->post($uri, $param);
+	print "RESP: " . Dumper($response) . "\n";
+    } else {
+	die "method $method not implemented\n";
+    }
 
-		my $data = decode_json($response->decoded_content);
+    if ($response->is_success) {
+	my $ct = $response->header('Content-Type');
 
-		die $data->{error} if $data->{error};
+	die "got unexpected content type" if $ct ne 'application/json';
 
-		return $data;
+	my $data = decode_json($response->decoded_content);
 
-	    } else {
-		die $response->status_line . "\n";
-	    }
+	die $data->{error} if $data->{error};
 
-	}; 
+	return $data;
+
+    } else {
+
+	die $response->status_line . "\n";
+
     }
 }
 
@@ -69,27 +97,34 @@
     my ($class, %param) = @_;
 
     my $self = { 
-	config => {
-	    ticket => $param{ticket},
-	    username => $param{username},
-	    password => $param{password},
-	    host => $param{host} || 'localhost',
-	    port => $param{port} || 85,
-	    timeout => $param{timeout} || 60,
-	},
+	ticket => $param{ticket},
+	username => $param{username},
+	password => $param{password},
+	host => $param{host} || 'localhost',
+	port => $param{port},
+	timeout => $param{timeout} || 60,
     };
     bless $self;
 
+    if (!$self->{port}) {
+	$self->{port} = $self->{host} eq 'localhost' ? 85 : 443;
+    }
+    if (!$self->{protocol}) {
+	$self->{protocol} = $self->{host} eq 'localhost' ? 'http' : 'https';
+    }
+
     $self->{cookie_jar} = HTTP::Cookies->new (ignore_discard => 1);
 
-    if ($self->{config}->{ticket}) {
-	 $self->{cookie_jar}->set_cookie(0, 'PVEAuthTicket', $self->{config}->{ticket},  
-					 '/', $self->{config}->{host});
+    if ($self->{ticket}) {
+	my $domain = "$self->{host}.local" unless  $self->{host} =~ /\./;
+	$self->{cookie_jar}->set_cookie(0, 'PVEAuthCookie', $self->{ticket},  
+					'/', $domain);
     }
 
     $self->{useragent} = LWP::UserAgent->new(
-	timeout => $self->{config}->{timeout},
 	cookie_jar => $self->{cookie_jar},
+	protocols_allowed => [ 'http', 'https'],
+	timeout => $self->{timeout},
 	);
   
     return $self;

Modified: pve-manager/pve2/lib/PVE/APIDaemon.pm
===================================================================
--- pve-manager/pve2/lib/PVE/APIDaemon.pm	2010-06-24 05:22:01 UTC (rev 4838)
+++ pve-manager/pve2/lib/PVE/APIDaemon.pm	2010-06-24 12:12:10 UTC (rev 4839)
@@ -3,24 +3,20 @@
 use strict;
 use warnings;
 use vars qw(@ISA);
-use MIME::Base64;
-#use Sys::Syslog;
 use PVE::SafeSyslog;
 use PVE::Config;
 use POSIX qw(EINTR);
 use POSIX ":sys_wait_h";
 use IO::Handle;
 use IO::Select;
-use vars qw(@ISA);
 use HTTP::Daemon;
 use HTTP::Status qw(:constants);
-use HTTP::Request::Params; # fixme: remove
+use HTTP::Request::Params;
 use Data::Dumper; # fixme: remove
-use URI;
+use PVE::REST;
 use JSON;
-use PVE::API2;
  
-# This is a quite simple pre-fork server
+# This is a quite simple pre-fork server - only listens to local port
 
 @ISA = qw(HTTP::Daemon);
 
@@ -30,6 +26,9 @@
 
 my $max_workers = 3;    # pre-forked worker processes
 my $max_requests = 500; # max requests per worker
+
+
+# some global vars
 my $child_terminate = 0;
 my $child_reload_config = 0;
 
@@ -192,33 +191,6 @@
     }
 }
 
-sub send_basic_auth_request {
-    my ($c) = @_;
-    
-    my $realm = 'PVE API Daemon';
-    my $auth_request_res = HTTP::Response->new(401, 'Unauthorized');
-    $auth_request_res->header('WWW-Authenticate' => qq{Basic realm="$realm"});
-    $auth_request_res->is_error(1);
-    $auth_request_res->error_as_HTML(1);
-    $c->send_response($auth_request_res);
-}
-
-sub send_error {
-    my ($c, $code, $msg) = @_;
-
-    $c->send_response(HTTP::Response->new($code, $msg));
-}
-
-sub handle_login {
-    my ($daemon, $c, $r) = @_;
-
-    # my $cuser = ident_user ($c->peerport, $c->sockport);
-
-    my $h =  $r->headers;
-
-    print "Head: " . Dumper($h) . "\n";
-}
-
 sub handle_requests {
     my $self = shift;
 
@@ -233,7 +205,7 @@
 	if (scalar (@ready = $sel->can_read($timeout))) {
 
 	    my $c;
-	    while (($c = $self->accept) || ($! == EINTR)) {
+	    while (($c = $self->accept) || ($! == EINTR && !$child_terminate)) {
 		next if !$c; # EINTR
 
 		if ($child_reload_config) {
@@ -248,68 +220,46 @@
 
 		# handle requests 
 		while (my $r = $c->get_request) {
-		    print "Request: " .  $r->as_string() . "\nEND REQUEST\n";
-		    #print "Method: " .  $r->method() . "\n";
-		    #print "CALL: " .  $r->uri->as_string() . "\n";
-		    #print "PATH: " .  $r->uri->path() . "\n";
-		    #print "Content: " . $r->content() . "\n";
 			
 		    my $method =  $r->method();
 
-		    syslog('info', "$method: " . $r->uri->as_string());
+		    my $uri = $r->uri->path();
 
+		    syslog('info', "start $method $uri");
+
 		    my $headers = $r->headers;
 
-		    my $ct = $headers->header('Content-Type');
+		    my $cookie = $headers->header('Cookie');
 
+		    my $ticket = PVE::REST::extract_auth_cookie($cookie);
+
 		    my $parser = HTTP::Request::Params->new({req => $r});
 		    my $params = $parser->params;
 		
-		    #print "params: " .  Dumper($params) . "\n";
+		    my $res = PVE::REST::rest_handler($method, $uri, $ticket, $params);
 
-		    if ($method eq 'POST' || $method eq 'GET') {
+		    my $response = HTTP::Response->new($res->{status});
+		    $response->header("Content-Type" => 'application/json');
+		    $response->header("Pragma", "no-cache");
 
-			my $path =  $r->uri->path();
-			print "PATH: $path\n";
-			
-			if ($path =~ m|^/api2/(\w+)$|) {
+		    if ($res->{ticket}) {
+			my $cookie = PVE::REST::create_auth_cookie($res->{ticket});
+			$response->header("Set-Cookie" => $cookie);
+		    }
 
-			    my $rpcmethod = $1;
+		    if ($res->{data}) {
+			my $raw = to_json($res->{data}, {utf8 => 1});
+			$response->content($raw);
+			$response->header("Content-Length" => length($raw));
 
-			    my $data;
-			    eval {
-
-				my $serv = bless {}, 'PVE::API2';
-
-				die "no such method\n" if !$serv->check_attribute($rpcmethod, "Public");
-				
-				my $func = PVE::API2->can($rpcmethod) || die "no such method\n";
-
-				$data = &$func($serv, $params);
-
-			    };
-			    my $error = $@;
-
-			    my $json = encode_json({ result => $data, error => $error || undef});
-
-			    my $response = HTTP::Response->new(200);
-			    my $x = length ($json);
-			    $response->header("Content-Type" => 'application/json');
-			    $response->header("Content-Length" => $x);
-			    $response->header("Pragma", "no-cache");
-			    $response->content($json);
-		       
-			    #print "RESPONSE: " . $response->as_string . "\n";
+		    } else {
+			$response->header("Content-Length" => 0);
+		    }
 			
-			    $c->send_response($response);
+		    $c->send_response($response);
 
-			} else {
-			    $c->send_error(HTTP_FORBIDDEN);
-			} 
+		    syslog('info', "end $method $uri ($res->{status})");
 
-		    } else {
-			$c->send_error(HTTP_METHOD_NOT_ALLOWED);
-		    }
 		}
 		$rcount++;
 

Modified: pve-manager/pve2/lib/PVE/OpenVZ.pm
===================================================================
--- pve-manager/pve2/lib/PVE/OpenVZ.pm	2010-06-24 05:22:01 UTC (rev 4838)
+++ pve-manager/pve2/lib/PVE/OpenVZ.pm	2010-06-24 12:12:10 UTC (rev 4839)
@@ -9,6 +9,8 @@
 
 my $last_proc_vestat = {};
 
+$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
+
 my $kernel_version = `uname -r`;
 
 sub vmlist {

Modified: pve-manager/pve2/lib/PVE/REST.pm
===================================================================
--- pve-manager/pve2/lib/PVE/REST.pm	2010-06-24 05:22:01 UTC (rev 4838)
+++ pve-manager/pve2/lib/PVE/REST.pm	2010-06-24 12:12:10 UTC (rev 4839)
@@ -12,6 +12,7 @@
 
 use Data::Dumper; # fixme: remove
 
+my $realm = 'PVE API Server';
 my $cookie_name = 'PVEAuthCookie';
 
 my $baseuri = "/api2";
@@ -46,102 +47,182 @@
     return undef;
 }
 
-sub handler {
-     my($r) = @_;
+sub extract_auth_cookie {
+    my ($cookie) = @_;
 
-     syslog('info', "perl handler called");
+    return undef if !$cookie;
 
-     my $auth_type = $r->ap_auth_type;
-     my $uri = $r->uri;
-     my $method = $r->method;
+    return ($cookie =~ /(?:^|\s)$cookie_name=([^;]*)/)[0];
+}
 
-     my $cgi = CGI->new ($r);
+sub create_auth_cookie {
+    my ($ticket) = @_;
 
-     my $params = $cgi->Vars();
+    return cookie_string($cookie_name, $ticket);
+}
 
-     ##&& $method eq 'PUSH'
-     if ($uri eq '/api2/ticket') {
-	 my $user = $params->{username};
-	 my $pw = $params->{password};
-	 
-	 syslog('info', "get ticket $user $pw");
+sub send_response {
+    my($r, $data) = @_;
+    
+    # my $accept = $r->headers_in->{Accept};
 
-	 if (my $ticket = create_ticket($user, $pw)) {
-	     my $cookie = cookie_string($cookie_name, $ticket);
-	     $r->err_headers_out()->add("Set-Cookie" => $cookie);
-	     $r->content_type ('application/json');
-	     my $data = to_json({ success => 1, ticket => $ticket }, {utf8 => 1});
-	     $r->print($data);
-	     return OK;
-	 } else {
-	     return FORBIDDEN;
-	 }
-     }
+    #$r->content_type ('text/plain');
+    
+    $r->content_type ('application/json');
 
-     my $cookie = $r->headers_in->{Cookie} || '';
-     syslog('info', "perl handler test1 '$cookie'");
+    return if !defined($data);
 
-     return DECLINED if !$cookie;
+    my $raw = to_json($data, {utf8 => 1});
+    $r->print($raw);
+}
 
-     ($cookie) = $cookie =~ /$cookie_name=([^;]+)/;
+sub local_proxy_handler {
+    my($r, $method, $abs_uri, $ticket, $params) = @_;
 
-     return DECLINED if !$cookie;
+    syslog('info', "local proxy start $method, $abs_uri");
 
-     my ($username, $age) = verify_ticket ($cookie);
+    my $ua = LWP::UserAgent->new(
+	protocols_allowed => [ 'http' ],
+	timeout => 30,
+	);
 
-     if ($username) {
-	 syslog ('info', "GOT VALID TICKET $cookie");
-     } else {
-	 syslog ('info', "GOT INVALID TICKET $cookie");
-	 # fixme: remove cookie
-	 return FORBIDDEN;
-     }
+    $ua->default_header('cookie' => "${cookie_name}=$ticket") if $ticket;
 
-     $uri =~ s/^\Q$baseuri\E//; 
+    my $uri = URI->new();
+    $uri->scheme('http');
+    $uri->host('localhost');
+    $uri->port(85);
+    $uri->path($abs_uri);
 
-     my ($user, $group) = split /::/, $cookie;
+    my $response;
+    if ($method eq 'GET') {
+	$uri->query_form($params);
+	$response = $ua->get($uri);
+    } elsif ($method eq 'POST') {
+	$response = $ua->post($uri, $params);
+    } else {
+	die "proxy method $method not implemented\n";
+    }
 
-     my $stack = [ grep { length($_) > 0 }  split('\/+' , $uri)] ; # skip empty fragments
+    if (my $cookie = $response->header("Set-Cookie")) {
+	$r->err_headers_out()->add("Set-Cookie" => $cookie);
+    }
 
-     # fixme: language ?
-     my $conn = {
-	 uri => $uri,
-	 user => $user,
-	 group => $group,
-	 ticket => $cookie,
-	 params => $params,
-     };
+    my $code = $response->code;
 
+    my $ct = $response->header('Content-Type');
+    die "got unexpected content type" if $ct ne 'application/json';
+
+    if ($code && ($code != OK)) {
+	$r->status($code);
+    }
+    my $message = $response->message;
+    if ($message) {
+	$r->status_line("$code $message");
+    }
+
+    $r->content_type ('application/json');
+    $r->print($response->decoded_content);
+
+    syslog('info', "local proxy end $code");
+
+    return $code;
+}
+
+sub rest_handler {
+    my ($method, $abs_uri, $ticket, $params) = @_;
+ 
+    my $euid = $>;
+   
+    my $rel_uri = $abs_uri;
+    $rel_uri =~ s/^\Q$baseuri\E//; 
+
+    if ($rel_uri eq '/ticket') {
+	my $user = $params->{username} || '';
+	my $pw = $params->{password} || '';
+
+	return { require_priv => 1,  status => FORBIDDEN } if ($euid != 0);
+
+	#syslog('info', "ticket auth $user $pw");
+
+	if ($ticket = create_ticket($user, $pw)) {
+	    return { status => OK, ticket => $ticket, 
+		     data => { success => 1, ticket => $ticket }};
+	}
+
+	return { status => HTTP_UNAUTHORIZED };
+    }
+
+    my ($username, $age);
+    ($username, $age) = verify_ticket ($ticket) if $ticket;
+
+    return { status => HTTP_UNAUTHORIZED } if !($ticket && $username);
+
+    syslog ('info', "GOT VALID TICKET $ticket");
+    
+    my $stack = [ grep { length($_) > 0 }  split('\/+' , $rel_uri)] ; # skip empty fragments
+
+    # fixme: language ?
+    my $conn = {
+	abs_uri => $abs_uri,
+	rel_uri => $rel_uri,
+	user => $username,
+	ticket => $ticket,
+	params => $params,
+    };
+
+    my $resp = {};
+ 
+    my $ret = { status => PVE::API2->handle($method, $stack, $conn, $resp) };
+
+    # fixme: update ticket if too old
+    # $ret->{ticket} = update_ticket($ticket);
+
+    $ret->{data} = $resp->{data} if $resp->{data};
+    $ret->{message} = $resp->{message} if $resp->{message};
+    
+    return $ret;
+}
+
+sub handler {
+     my($r) = @_;
+
+     syslog('info', "perl handler called");
+
+     my $method = $r->method;
+     my $cgi = CGI->new ($r);
+
+     my $params = $cgi->Vars();
+
+     my $cookie = $r->headers_in->{Cookie};
+
+     my $ticket = extract_auth_cookie($cookie);
+
      $r->no_cache (1);
 
-     my $resp = {};
-     my $res = PVE::API2->handle($method, $stack, $conn, $resp);
+     my $res = rest_handler($method, $r->uri, $ticket, $params);
 
-     $r->content_type ('application/json');
-     #$r->content_type ('text/plain');
+     return local_proxy_handler($r, $method, $r->uri, $ticket, $params)
+	 if $res->{require_priv};
 
-     #my $data = "test response $$ $user $uri\n" . Dumper($resp->{data});
-     my $data = to_json($resp->{data}, {utf8 => 1});
-
-     if ($res && ($res != Apache2::Const::HTTP_OK)) {
-	 $r->status($res);
+     if ($res->{ticket}) {
+	 my $cookie = create_auth_cookie($res->{ticket});
+	 $r->err_headers_out()->add("Set-Cookie" => $cookie);
      }
 
-     if ($resp->{message}) {
-	 $r->status_line("$res $resp->{message}");
+     if ($res->{status} && ($res->{status} != OK)) {
+	 $r->status($res->{status});
+     } 
+
+     if ($res->{message}) {
+	 $r->status_line("$res $res->{message}");
      }
 
-     if ($res && $res =~ /^2/) {
-	 $r->headers_out()->add('Content-length' , length($data));
-     } else {
-	 $r->err_headers_out()->add('Content-length' , length($data));
-     }
+     send_response($r, $res->{data});
     
-     $r->print($data);
+     syslog('info', "perl handler end $res->{status}");
 
-     syslog('info', "perl handler end $res");
-
-     return Apache2::Const::OK ;
+     return $res->{status};
 }
 
 1;

Modified: pve-manager/pve2/lib/PVE/RESTHandler.pm
===================================================================
--- pve-manager/pve2/lib/PVE/RESTHandler.pm	2010-06-24 05:22:01 UTC (rev 4838)
+++ pve-manager/pve2/lib/PVE/RESTHandler.pm	2010-06-24 12:12:10 UTC (rev 4839)
@@ -32,7 +32,7 @@
 
     my $stacklen = scalar(@$stack);
 
-    #syslog ('info', "MAPTEST:$self: " . join ('/', @$stack));
+    #syslog ('info', "MAPTEST:$method:$self: " . join ('/', @$stack));
 
     foreach my $info (@$ma) {
 	#syslog ('info', "TEST0 " . Dumper($info));
@@ -44,7 +44,7 @@
 	    next if $stacklen != $regexlen;
 	}
 
-	#syslog ('info', "TEST1");
+	#syslog ('info', "TEST1 " . Dumper($info));
 
 	my $i = 0;
 	for (; $i < $regexlen; $i++) {
@@ -128,11 +128,17 @@
 
     # fixme: this is only to be safe
     if (my $schema = $info->{returns}) {
+
 	my $res = PVE::JSONSchema::validate($resp->{data}, $schema);
 	if (!$res->{valid}) {
+
 	    $resp->{message} = "SERVER ERROR: result verification vailed";
 	    $resp->{status} = HTTP_INTERNAL_SERVER_ERROR;
-	    $resp->{data} = { errors => $res->{errors} };
+	    $resp->{data} = { 
+		errors => $res->{errors},
+		data => $resp->{data},
+	    };
+
 	    return $resp->{status}
 	} 
     }

Modified: pve-manager/pve2/www/manager/LoginWindow.js
===================================================================
--- pve-manager/pve2/www/manager/LoginWindow.js	2010-06-24 05:22:01 UTC (rev 4838)
+++ pve-manager/pve2/www/manager/LoginWindow.js	2010-06-24 12:12:10 UTC (rev 4839)
@@ -5,19 +5,10 @@
     onLogon: function() {
 	var form = this.get(0).getForm();
 
-	var values = form.getValues(false); 
-	var user = values.username;
-	var pass = values.password;
-
-	var tok = user + ':' + pass;
-	var hash = Ext.util.base64.encode(tok);
-	var auth = "Basic " + hash;
-
 	if(form.isValid()){
             this.el.mask('Please wait...', 'x-mask-loading');
 
 	    form.submit({
-		headers: { Authorization : auth },
 		scope: this,
 		failure: function(f, resp){
 		    this.el.unmask();

Deleted: pve-manager/pve2/www/manager/base64.js
===================================================================
--- pve-manager/pve2/www/manager/base64.js	2010-06-24 05:22:01 UTC (rev 4838)
+++ pve-manager/pve2/www/manager/base64.js	2010-06-24 12:12:10 UTC (rev 4839)
@@ -1,51 +0,0 @@
-Ext.util.base64 = {
-
-    // code from extjs forom
-
-    base64s : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
-    
-    encode: function(decStr){
-        if (typeof btoa === 'function') {
-             return btoa(decStr);            
-        }
-        var base64s = this.base64s;
-        var bits;
-        var dual;
-        var i = 0;
-        var encOut = "";
-        while(decStr.length >= i + 3){
-            bits = (decStr.charCodeAt(i++) & 0xff) <<16 | (decStr.charCodeAt(i++) & 0xff) <<8 | decStr.charCodeAt(i++) & 0xff;
-            encOut += base64s.charAt((bits & 0x00fc0000) >>18) + base64s.charAt((bits & 0x0003f000) >>12) + base64s.charAt((bits & 0x00000fc0) >> 6) + base64s.charAt((bits & 0x0000003f));
-        }
-        if(decStr.length -i > 0 && decStr.length -i < 3){
-            dual = Boolean(decStr.length -i -1);
-            bits = ((decStr.charCodeAt(i++) & 0xff) <<16) |    (dual ? (decStr.charCodeAt(i) & 0xff) <<8 : 0);
-            encOut += base64s.charAt((bits & 0x00fc0000) >>18) + base64s.charAt((bits & 0x0003f000) >>12) + (dual ? base64s.charAt((bits & 0x00000fc0) >>6) : '=') + '=';
-        }
-        return(encOut);
-    },
-    
-    decode: function(encStr){
-        if (typeof atob === 'function') {
-            return atob(encStr); 
-        }
-        var base64s = this.base64s;        
-        var bits;
-        var decOut = "";
-        var i = 0;
-        for(; i<encStr.length; i += 4){
-            bits = (base64s.indexOf(encStr.charAt(i)) & 0xff) <<18 | (base64s.indexOf(encStr.charAt(i +1)) & 0xff) <<12 | (base64s.indexOf(encStr.charAt(i +2)) & 0xff) << 6 | base64s.indexOf(encStr.charAt(i +3)) & 0xff;
-            decOut += String.fromCharCode((bits & 0xff0000) >>16, (bits & 0xff00) >>8, bits & 0xff);
-        }
-        if(encStr.charCodeAt(i -2) == 61){
-            return(decOut.substring(0, decOut.length -2));
-        }
-        else if(encStr.charCodeAt(i -1) == 61){
-            return(decOut.substring(0, decOut.length -1));
-        }
-        else {
-            return(decOut);
-        }
-    }
-
-};
\ No newline at end of file



More information about the pve-devel mailing list