Commit a3948aa3 authored by Benoit Mortier's avatar Benoit Mortier
Browse files

Merge branch 'argonaut-0.9.1'

parents f399e8fe 4eacbdbf
......@@ -26,7 +26,13 @@ use warnings;
use 5.008;
use base qw(JSON::RPC::Procedure); # requires Perl 5.6 or later
use Argonaut::Libraries::Common qw(:config);
my $base;
BEGIN {
$base = (USE_LEGACY_JSON_RPC ? "JSON::RPC::Legacy::Procedure" : "JSON::RPC::Procedure");
}
use base $base;
=item echo
return the parameters passed to it
......
......@@ -28,9 +28,13 @@ use warnings;
use 5.008;
use base qw(JSON::RPC::Procedure); # requires Perl 5.6 or later
use Argonaut::Libraries::Common qw(:ldap :config);
use Argonaut::Libraries::Common qw(:ldap);
my $base;
BEGIN {
$base = (USE_LEGACY_JSON_RPC ? "JSON::RPC::Legacy::Procedure" : "JSON::RPC::Procedure");
}
use base $base;
=item getServiceName
Returns the local name of a service
......@@ -38,14 +42,11 @@ Returns the local name of a service
sub getServiceName : Private {
my ($nameFD) = @_;
my $ldapinfos = argonaut_ldap_init ($main::ldap_configfile, 0, $main::ldap_dn, 0, $main::ldap_password);
my ($ldap,$ldap_base) = argonaut_ldap_handle($main::config);
if ($ldapinfos->{'ERROR'} > 0) {
die $ldapinfos->{'ERRORMSG'}."\n";
}
my $mesg = $ldapinfos->{'HANDLE'}->search( # perform a search
base => $ldapinfos->{'BASE'},
my $mesg = $ldap->search( # perform a search
base => $ldap_base,
filter => "(&(objectClass=argonautClient)(ipHostNumber=".$main::client_settings->{'ip'}."))",
attrs => [ 'argonautServiceName' ]
);
......
......@@ -28,9 +28,13 @@ use warnings;
use 5.008;
use base qw(JSON::RPC::Procedure); # requires Perl 5.6 or later
use Argonaut::Libraries::Common qw(:ldap :config);
use Argonaut::Libraries::Common qw(:ldap);
my $base;
BEGIN {
$base = (USE_LEGACY_JSON_RPC ? "JSON::RPC::Legacy::Procedure" : "JSON::RPC::Procedure");
}
use base $base;
=item halt
shutdown the computer
......
......@@ -4,7 +4,7 @@
#
# argonaut-client-management
#
# Copyright (C) 2011-2013 FusionDirectory project <contact@fusiondirectory.org>
# Copyright (C) 2011-2014 FusionDirectory project <contact@fusiondirectory.org>
#
# Author: Côme BERNIGAUD
#
......@@ -28,19 +28,17 @@ use warnings;
use 5.008;
use JSON::RPC::Server::Daemon;
use Config::IniFiles;
use Argonaut::Libraries::Common qw(:ldap :config :file);
use if (USE_LEGACY_JSON_RPC), 'JSON::RPC::Legacy::Server::Daemon';
use if not (USE_LEGACY_JSON_RPC), 'JSON::RPC::Server::Daemon';
use Log::Handler;
use App::Daemon qw(daemonize);
use Argonaut::Libraries::Common qw(:ldap :file);
# where to look for modules files
use Module::Pluggable search_path => 'Argonaut::ClientDaemon::Modules', sub_name => 'modules';
our ($client_settings, $server_settings);
our ($ldap_configfile, $ldap_dn, $ldap_password);
my $configfile = "/etc/argonaut/argonaut.conf";
our ($config, $client_settings, $server_settings);
my $logfile = "argonaut-client.log";
my $piddir = "/var/run/argonaut";
my $pidfile = "argonaut-client.pid";
......@@ -89,16 +87,10 @@ $server->dispatch_to($modules)->handle();
sub readConfig {
my $config = Config::IniFiles->new( -file => $configfile, -allowempty => 1, -nocase => 1);
my $client_ip = $config->val( client => "client_ip" ,"");
my $server_ip = $config->val( server => "server_ip" ,"");
$ldap_configfile = $config->val( ldap => "config" ,"/etc/ldap/ldap.conf");
$ldap_dn = $config->val( ldap => "dn" ,"");
$ldap_password = $config->val( ldap => "password" ,"");
$config = argonaut_read_config;
$server_settings = argonaut_get_server_settings($ldap_configfile,$ldap_dn,$ldap_password,$server_ip);
$client_settings = argonaut_get_client_settings($ldap_configfile,$ldap_dn,$ldap_password,$client_ip);
$server_settings = argonaut_get_server_settings($config,$config->{'server_ip'});
$client_settings = argonaut_get_client_settings($config,$config->{'client_ip'});
}
......@@ -134,7 +126,7 @@ argonaut-client
=head1 DESCRIPTION
argonaut-client is getting actions from argonaut server and run them. It is modular
argonaut-client is getting actions from argonaut server and run them. It is modular
and can load various modules at run time.
=head1 BUGS
......@@ -148,7 +140,7 @@ This code is part of FusionDirectory <http://www.fusiondirectory.org>
=over 1
=item Copyright (C) 2011-2013 FusionDirectory project
=item Copyright (C) 2011-2014 FusionDirectory project
=back
......
#!/usr/bin/perl
#######################################################################
#
# argonaut-client-fai-get-id -- get deployment queue job id
#
# Copyright (C) 2011-2013 FusionDirectory project <contact@fusiondirectory.org>
#
# Author: Côme BERNIGAUD
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
#######################################################################
use strict;
use warnings;
use 5.008;
use JSON::RPC::Client;
use Config::IniFiles;
use Log::Handler;
use Argonaut::Libraries::Common qw(:net :ldap :file);
=pod
This program ask the argonaut-server for the assigned taskid for the fai installation.
It store the info into the file specified in the config file.
=cut
my $configfile = "/etc/argonaut/argonaut.conf";
my $logfile = "argonaut-client-fai-getid.log";
my $config = Config::IniFiles->new( -file => $configfile, -allowempty => 1, -nocase => 1);
my $server_ip = $config->val( server => "server_ip" ,"");
my $client_ip = $config->val( client => "client_ip" ,"");
my $ldap_configfile = $config->val( ldap => "config" ,"/etc/ldap/ldap.conf");
my $ldap_dn = $config->val( ldap => "dn" ,"");
my $ldap_password = $config->val( ldap => "password" ,"");
my $client_settings = argonaut_get_client_settings($ldap_configfile,$ldap_dn,$ldap_password,$client_ip);
my $file = $client_settings->{'taskidfile'};
my $interface = $client_settings->{'interface'};
my $logdir = $client_settings->{'logdir'};
my $myMac = $client_settings->{'mac'};
my $server_settings = argonaut_get_server_settings($ldap_configfile,$ldap_dn,$ldap_password,$server_ip);
my $server_port = $server_settings->{'port'};
my $protocol = $server_settings->{'protocol'};
argonaut_create_dir($logdir);
my $log = Log::Handler->create_logger("argonaut-client-fai-get-id");
$log->add(
file => {
filename => "$logdir/$logfile",
maxlevel => "debug",
minlevel => "emergency"
}
);
my $client = new JSON::RPC::Client;
$client->version('1.0');
my $callobj = {
method => "get_my_id",
params => [$myMac],
};
my $taskid = $client->call($protocol.$server_ip.":".$server_port, $callobj);
if($taskid) {
if ($taskid->is_error) {
print $myMac;
$log->error("Error : ", $taskid->error_message);
die "Error : ", $taskid->error_message;
} else {
open (ID, ">$file") or die "cannot write in $file";
print ID $taskid->content->{result};
close(ID);
}
} else {
print $myMac;
$log->error("Error while trying to contact Argonaut server : ".$client->status_line);
die "Error while trying to contact Argonaut server : ".$client->status_line;
}
print $myMac;
__END__
# vim:ts=2:sw=2:expandtab:shiftwidth=2:syntax:paste
#!/usr/bin/perl
#######################################################################
#
# argonaut-client-fai-sendmon
#
# Copyright (C) 2011-2013 FusionDirectory project <contact@fusiondirectory.org>
#
# Author: Côme BERNIGAUD
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
#######################################################################
use strict;
use warnings;
use 5.008;
use JSON::RPC::Client;
use Config::IniFiles;
use Log::Handler;
use Argonaut::Libraries::Common qw(:ldap :file);
my $configfile = "/etc/argonaut/argonaut.conf";
my $logfile = "argonaut-client-fai-sendmon.log";
my $config = Config::IniFiles->new( -file => $configfile, -allowempty => 1, -nocase => 1);
my $server_ip = $config->val( server => "server_ip" ,"");
my $client_ip = $config->val( client => "client_ip" ,"");
my $ldap_configfile = $config->val( ldap => "config" ,"/etc/ldap/ldap.conf");
my $ldap_dn = $config->val( ldap => "dn" ,"");
my $ldap_password = $config->val( ldap => "password" ,"");
my $client_settings = argonaut_get_client_settings($ldap_configfile,$ldap_dn,$ldap_password,$client_ip);
my $file = $client_settings->{'taskidfile'};
my $logdir = $client_settings->{'logdir'};
my $server_settings = argonaut_get_server_settings($ldap_configfile,$ldap_dn,$ldap_password,$server_ip);
my $server_port = $server_settings->{'port'};
my $protocol = $server_settings->{'protocol'};
my $taskid;
my %progress_value = (
"confdir" => 0,
"setup" => 1,
"defclass" => 1,
"defvar" => 1,
"action" => 1,
"install" => 2,
"partition" => 2,
"extrbase" => 3,
"debconf" => 15,
"prepareapt"=> 15,
"updatebase"=> 15,
"instsoft" => 16,
"configure" => 80,
"savelog" => 90
);
argonaut_create_dir($logdir);
my $log = Log::Handler->create_logger("argonaut-client-fai-sendmon");
$log->add(
file => {
filename => "$logdir/$logfile",
maxlevel => "debug",
minlevel => "emergency"
}
);
=pod
This program read on stdin the sendmon fai output, extract useful information and send them to argonaut-server.
=cut
open (ID, "<$file") or die "cannot open $file";
$taskid = <ID>;
close(ID);
chomp($taskid);
while (my $var = <STDIN>) {
$var =~ /(\w+) (\S+)\s?(\S*)/;
my $keyword = $1;
my $taskname = $2;
my $errorcode = $3;
if($keyword eq "TASKBEGIN") {
print "[sendmon] Task $taskname begun\n";
my $progress = undef;
if(defined $progress_value{$taskname}) {
$progress = $progress_value{$taskname};
}
my $client = new JSON::RPC::Client;
$client->version('1.0');
my $callobj = {
method => "set_task_substatus",
params => [$taskid,$taskname,$progress],
};
my $res = $client->call($protocol.$server_ip.":".$server_port, $callobj);
if($res) {
if ($res->is_error) {
$log->error("Error : ".$res->error_message);
die "Error : ", $res->error_message;
}
} else {
$log->error("Error while trying to contact Argonaut server : ".$client->status_line);
die "Error while trying to contact Argonaut server : ".$client->status_line;
}
} elsif($keyword eq "TASKEND") {
print "[sendmon] Task $taskname ended\n";
if($taskname eq "faiend") {
my $client = new JSON::RPC::Client;
$client->version('1.0');
my $callobj = {
method => "set_task_substatus",
params => [$taskid,$taskname,100],
};
my $res = $client->call($protocol.$server_ip.":".$server_port, $callobj);
if($res) {
if ($res->is_error) {
$log->error("Error : ".$res->error_message);
die "Error : ", $res->error_message;
}
} else {
$log->error("Error while trying to contact Argonaut server : ".$client->status_line);
die "Error while trying to contact Argonaut server : ".$client->status_line;
}
}
} elsif($keyword eq "TASKERROR") {
print "[sendmon] Task error $taskname $errorcode\n";
my $client = new JSON::RPC::Client;
$client->version('1.0');
my $callobj = {
method => "set_error",
params => [$taskid,$taskname." ".$errorcode],
};
my $res = $client->call($protocol.$server_ip.":".$server_port, $callobj);
if($res) {
if ($res->is_error) {
$log->error("Error : ".$res->error_message);
die "Error : ", $res->error_message;
}
}
else {
$log->notice("Status : ".$client->status_line);
die "Status : ".$client->status_line;
}
}
}
__END__
# vim:ts=2:sw=2:expandtab:shiftwidth=2:syntax:paste
......@@ -124,7 +124,7 @@
.\" ========================================================================
.\"
.IX Title "ARGONAUT-CLIENT 1"
.TH ARGONAUT-CLIENT 1 "2013-11-29" "Argonaut 0.9" "Argonaut Documentation"
.TH ARGONAUT-CLIENT 1 "2014-06-24" "Argonaut 0.9.1" "Argonaut Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
......@@ -136,8 +136,8 @@ argonaut\-client \- running actions given by the argonaut server
argonaut-client
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
argonaut-client is getting actions from argonaut server and run them. It is modular
and can load various modules at run time
argonaut-client is getting actions from argonaut server and run them. It is modular
and can load various modules at run time.
.SH "BUGS"
.IX Header "BUGS"
Please report any bugs, or post any suggestions, to the fusiondirectory mailing list fusiondirectory-users or to
......@@ -145,8 +145,8 @@ Please report any bugs, or post any suggestions, to the fusiondirectory mailing
.SH "LICENCE AND COPYRIGHT"
.IX Header "LICENCE AND COPYRIGHT"
This code is part of FusionDirectory <http://www.fusiondirectory.org>
.IP "Copyright (C) 2011\-2013 FusionDirectory project" 1
.IX Item "Copyright (C) 2011-2013 FusionDirectory project"
.IP "Copyright (C) 2011\-2014 FusionDirectory project" 1
.IX Item "Copyright (C) 2011-2014 FusionDirectory project"
.PP
This program is distributed in the hope that it will be useful,
but \s-1WITHOUT\s0 \s-1ANY\s0 \s-1WARRANTY\s0; without even the implied warranty of
......
......@@ -3,7 +3,7 @@
# Argonaut::Libraries::Common -- Argonaut basic functions.
#
# Copyright (c) 2008 Landeshauptstadt München
# Copyright (C) 2011-2013 FusionDirectory project
# Copyright (C) 2011-2014 FusionDirectory project
#
# Author: Matthias S. Benkmann
# Come Bernigaud
......@@ -31,13 +31,21 @@ use warnings;
use 5.008;
use JSON::RPC ();
use constant USE_LEGACY_JSON_RPC => ($JSON::RPC::VERSION > 0.96);
use Net::LDAP;
use Net::LDAP::Constant qw(LDAP_NO_SUCH_OBJECT LDAP_REFERRAL);
use URI;
use File::Path;
use Config::IniFiles;
my $iptool = "ifconfig";
my $die_endl = "\n"; # Change to "" to have verbose dies
my $configfile = "/etc/argonaut/argonaut.conf";
BEGIN
{
use Exporter ();
......@@ -55,6 +63,7 @@ BEGIN
&argonaut_ldap_is_single_result
&argonaut_ldap_split_dn
&argonaut_ldap_init
&argonaut_ldap_handle
&argonaut_get_generic_settings
&argonaut_get_client_settings
&argonaut_get_server_settings
......@@ -77,6 +86,10 @@ BEGIN
)],
'net' => [qw(
&argonaut_get_mac
)],
'config' => [qw(
&argonaut_read_config
USE_LEGACY_JSON_RPC
)]
);
......@@ -143,13 +156,13 @@ sub argonaut_get_mac_pxe {
#
sub argonaut_ldap_init {
my( $ldap_conf, $prompt_dn, $bind_dn,
$prompt_pwd, $bind_pwd, $obfuscate_pwd ) = @_;
$prompt_pwd, $bind_pwd, $obfuscate_pwd, $ldap_tls ) = @_;
my %results;
undef $bind_dn if ($bind_dn eq '');
# Parse ldap config
my ($base,$ldapuris) = argonaut_ldap_parse_config( $ldap_conf );
my ($base,$ldapuris,$tlsoptions) = argonaut_ldap_parse_config( $ldap_conf );
%results = ( 'BASE' => $base, 'URIS' => $ldapuris);
if ( ! defined $base ) {
......@@ -169,6 +182,15 @@ sub argonaut_ldap_init {
return \%results;
}
if ($ldap_tls) {
$ldap->start_tls(
verify => $tlsoptions->{'REQCERT'},
clientcert => $tlsoptions->{'CERT'},
clientkey => $tlsoptions->{'KEY'},
capath => $tlsoptions->{'CACERTDIR'}
);
}
$results{ 'HANDLE' } = $ldap;
# Prompt for DN
......@@ -227,6 +249,17 @@ sub argonaut_ldap_init {
return \%results;
}
sub argonaut_ldap_handle {
my ($config) = @_;
my $ldapinfos = argonaut_ldap_init ($config->{'ldap_configfile'}, 0, $config->{'ldap_dn'}, 0, $config->{'ldap_password'}, 0, $config->{'ldap_tls'});
if ( $ldapinfos->{'ERROR'} > 0) {
die $ldapinfos->{'ERRORMSG'}."$die_endl";
}
return ($ldapinfos->{'HANDLE'},$ldapinfos->{'BASE'},$ldapinfos);
}
#------------------------------------------------------------------------------
sub argonaut_ldap_parse_config
{
......@@ -248,7 +281,7 @@ sub argonaut_ldap_parse_config
my @content=<LDAPCONF>;
close(LDAPCONF);
my ($ldap_base, @ldap_uris);
my ($ldap_base, @ldap_uris, %tls_options);
# Scan LDAP config
foreach my $line (@content) {
$line =~ /^\s*(#|$)/ && next;
......@@ -270,43 +303,13 @@ sub argonaut_ldap_parse_config
}
next;
}
}
return( $ldap_base, \@ldap_uris );
}
#------------------------------------------------------------------------------
sub argonaut_ldap_parse_config_ex
{
my %result = ();
my $ldap_info = '/etc/ldap/ldap-shell.conf';
if ( -r '/etc/ldap/ldap-offline.conf' ) {
$ldap_info = '/etc/ldap/ldap-offline.conf';
}
if (!open( LDAPINFO, "<${ldap_info}" ))
{
warn "Couldn't open ldap info ($ldap_info): $!\n";
return undef;
}
while( <LDAPINFO> ) {
if( $_ =~ m/^([a-zA-Z_0-9]+)="(.*)"$/ ) {
if ($1 eq "LDAP_URIS") {
my @uris = split(/ /,$2);
$result{$1} = \@uris;
}
else {
$result{$1} = $2;
}
if ($line =~ m/^TLS_(REQCERT|CERT|KEY|CACERTDIR)\s+(.*)\s*$/) {
$tls_options{$1} = $2;
next;
}
}