[37385] branches/gsoc08-logging

dpemmons at macports.org dpemmons at macports.org
Thu Jun 5 03:26:14 PDT 2008


Revision: 37385
          http://trac.macosforge.org/projects/macports/changeset/37385
Author:   dpemmons at macports.org
Date:     2008-06-05 03:26:11 -0700 (Thu, 05 Jun 2008)

Log Message:
-----------
adding the beginnings of a simple perl-based xml-rpc server so we have something to test with later on

Added Paths:
-----------
    branches/gsoc08-logging/testing server/
    branches/gsoc08-logging/testing server/XML-RPC Client.app.zip
    branches/gsoc08-logging/testing server/info.txt
    branches/gsoc08-logging/testing server/logs/
    branches/gsoc08-logging/testing server/server.pl
    branches/gsoc08-logging/testing server/users.txt

Added: branches/gsoc08-logging/testing server/XML-RPC Client.app.zip
===================================================================
(Binary files differ)


Property changes on: branches/gsoc08-logging/testing server/XML-RPC Client.app.zip
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: branches/gsoc08-logging/testing server/info.txt
===================================================================
--- branches/gsoc08-logging/testing server/info.txt	                        (rev 0)
+++ branches/gsoc08-logging/testing server/info.txt	2008-06-05 10:26:11 UTC (rev 37385)
@@ -0,0 +1,14 @@
+This is a simple xml-rpc server for testing log submissions.  It's written in Perl and requires RPC::XML::Server and Digest::SHA.  It will run on localhost:8822.
+
+XML-RPC Client.app is a nice little XML-RPC testing app from:
+http://ditchnet.org/xmlrpc/
+
+The submission process on the client side works kinda like this:
+
+$salt = logging.login.getSalt($myUserName);
+$passwordHash = sha256_hex($myUserName.$myPassword.$salt);
+$sessionID = logging.login.getSessionID($myUserName,$passwordHash);
+
+## now the sessionID can be used for any other operations, like:
+
+logging.log.submit($sessionID, $portName, $log);
\ No newline at end of file

Added: branches/gsoc08-logging/testing server/server.pl
===================================================================
--- branches/gsoc08-logging/testing server/server.pl	                        (rev 0)
+++ branches/gsoc08-logging/testing server/server.pl	2008-06-05 10:26:11 UTC (rev 37385)
@@ -0,0 +1,122 @@
+#!/opt/local/bin/perl -w
+
+use strict;
+use Carp;
+use RPC::XML::Server;
+use RPC::XML::Procedure;
+use Digest::SHA qw(sha256_hex);
+
+## configuration stuff
+my $port = 8822;
+my $usersFile = "./users.txt";
+
+## setup
+my $superSalt = generateRandomString(64);
+my $users = load_users();
+my %sessions;
+
+## let's go!
+run_server();
+
+sub run_server {
+	print "Setting up RPC Testing Server...\n";
+	my $srv = RPC::XML::Server->new(port => $port);
+	
+	$srv->add_default_methods();
+
+	$srv->add_method({ name => 'logging.login.getSalt',
+                       code => \&logging_login_getSalt,
+                       signature => [ 'string string' ] });
+	$srv->add_method({ name => 'logging.login.getSessionID',
+                       code => \&logging_login_getSessionID,
+                       signature => [ 'string string string' ] });
+
+	$srv->add_method({ name => 'logging.logs.submit',
+                       code => \&logging_logs_submit,
+                       signature => [ 'string string string string' ] });
+		
+	print "RPC Testing Server is listening on port $port...\n";
+	$srv->server_loop; 
+	print "Quit.\n";
+}
+
+
+## read in the users file, assign the username/password pairs to a
+## hash and return a reference to the hash.
+sub load_users {
+	my %users;
+	open(INFILE, "$usersFile") or die "Couldn't open users file: $!";
+	foreach my $line (<INFILE>) {
+		chomp $line;
+		my ($user, $pass) = split(/\s/,$line);
+		$users{$user} = $pass;
+	}
+	close(INFILE);
+	return \%users;
+}
+
+## takes a username; checks wheter it's valid, and if so returns an SHA hash
+## of the username+$superSalt
+sub logging_login_getSalt {
+	my $srv = shift;
+	my $userName = shift;
+	if ($users->{$userName}) {
+		my $salt = sha256_hex($userName.$superSalt);
+		return $salt;
+	} else {
+		return "BAD_USERNAME";
+	}
+}
+
+sub logging_login_getSessionID {
+	my $srv = shift;
+	my $userName = shift;
+	my $passHash = shift;
+	
+	if ($users->{$userName}) {
+		my $salt = sha256_hex($userName.$superSalt);
+
+		my $password = $users->{$userName};
+		my $correctPasswordHash = sha256_hex($userName.$password.$salt);
+
+		if ($passHash eq $correctPasswordHash) {
+			## generate a sessionID and give it to the client
+			my $sessionID = generateRandomString(64);
+			$sessions{$sessionID} = $userName;
+		} else {
+			return "BAD_PASSWORD";
+		}
+
+	} else {
+		return "BAD_USERNAME";
+	}
+	
+}
+
+
+sub logging_logs_submit {
+	my $srv = shift;
+	my $sessionID = shift;
+	my $portName = shift;
+	my $log = shift;
+
+	my $time = time();
+	
+	open (OUTFILE,">./logs/$portName.s$sessionID.t$time.log") or warn "Couldn't open file \"./logs/$portName.s$sessionID.t$time.log\" for writing: $!";
+	print OUTFILE $log;
+	close (OUTFILE);
+	
+	return "OK";
+}
+
+
+
+sub generateRandomString {
+	my $len=shift;
+	my @chars=('a'..'z','A'..'Z','0'..'9','_');
+	my $str;
+	foreach (1..$len) {
+		$str.=$chars[rand @chars];
+	}
+	return $str;
+}


Property changes on: branches/gsoc08-logging/testing server/server.pl
___________________________________________________________________
Name: svn:executable
   + *

Added: branches/gsoc08-logging/testing server/users.txt
===================================================================
--- branches/gsoc08-logging/testing server/users.txt	                        (rev 0)
+++ branches/gsoc08-logging/testing server/users.txt	2008-06-05 10:26:11 UTC (rev 37385)
@@ -0,0 +1,2 @@
+testuser testpass
+testuser2 testpass2
\ No newline at end of file

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20080605/94755bdb/attachment.htm 


More information about the macports-changes mailing list