SSH::RPC

  1. write the class (and server, but it is always the same) in the remote server machine
  2. automatically produce documentation about the service
  3. generate and publish key pair in the server machine,
  4. set appropriate entry in the authorized_keys file (server) with command restricted to the service application
  5. reverse-publish private key on each client, /.ssh/key
  6. make an entry in the /.ssh/config file
  7. write the client in the client machine according to the intructions

En El Lado del Cliente

$ ./time-client.pl 
17:25:3

$ cat -n time-client.pl 
   1  #!/usr/bin/env perl 
   2  use lib '../lib';
   3  use warnings;
   4  use strict;
   5  use SSH::RPC::Client;
   6  use Getopt::Long;
   7  
   8  my ($host, $hires);
   9  
  10  $host = 'sshrpc';
  11  my $ssh = SSH::RPC::Client->new($host); 
  12  my $command = ($hires) ? "hiResTime" : "time";
  13  my $result = $ssh->run($command);
  14  if ($result->isSuccess) {
  15      if ($hires) {
  16          printf "%02d:%02d:%02d.%d\n", @{$result->getResponse};
  17      }
  18      else {
  19          print $result->getResponse."\n";
  20      }
  21  }
  22  else {
  23      die $result->getError;
  24  }

En El Lado del Servidor

El servidor:

$ cat -n time-shell.pl 
     1  #!/usr/bin/perl
     2  
     3  use strict;
     4  use TimeShell;
     5  
     6  TimeShell->run();
El Módulo cargado por el servidor:
$ cat -n TimeShell.pm 
   1  package TimeShell;
   2  
   3  use lib '../lib';
   4  use strict;
   5  use base 'SSH::RPC::Shell';
   6  use Time::HiRes;
   7  
   8  sub run_time {
   9      my @time = localtime(time());
  10      return {
  11          status      => 200,
  12          response    => join(":", $time[2], $time[1], $time[0]),
  13          };
  14  }
  15  
  16  sub run_hiResTime {
  17      my ($seconds, $microseconds) = Time::HiRes::gettimeofday();
  18      my @time = localtime($seconds);
  19      return {
  20          status      => 200,
  21          response    => [ $time[2], $time[1], $time[0], $microseconds ],
  22          };
  23  }
  24  
  25  1;

Comando forzado:

pp2@nereida:~/Lbook$ cat /home/pp2/.ssh/authorized_keys 
ssh-dss ...
...
command="/home/pp2/Lperltesting/SSHRPC/examples/time-shell.pl" ssh-dss AAAA...= casiano@MacBookdeCasiano.local



Subsecciones
Casiano Rodríguez León
Licencia de Creative Commons
Programación Distribuida y Mejora del Rendimiento
por Casiano Rodríguez León is licensed under a Creative Commons Reconocimiento 3.0 Unported License.

Permissions beyond the scope of this license may be available at http://campusvirtual.ull.es/ocw/course/view.php?id=44.
2012-06-19