diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index 1d59cd75ef7a83776f0ee1e0e48e4aed731be3cf..255fa3391de4ed93aac794f748b6d230a4378c53 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
#!/usr/bin/perl
#===============================================================================
#
-# FILE: gosa-sd
+# FILE: gosa-si-server
#
-# USAGE: ./gosa-sd
+# USAGE: ./gosa-si-server
#
# DESCRIPTION:
#
# REVISION: ---
#===============================================================================
-my $server_version = '$HeadURL: https://oss.gonicus.de/repositories/gosa/trunk/gosa-si/gosa-si-server $:$Rev$';
-
use strict;
use warnings;
use Getopt::Long;
use XML::Simple;
use Data::Dumper;
use Sys::Syslog qw( :DEFAULT setlogsock);
-use Time::HiRes qw( usleep);
+use Time::HiRes qw( usleep clock_gettime );
use Cwd;
use File::Spec;
use File::Basename;
use Net::LDAP;
use Net::LDAP::Util qw(:escape);
+my $server_version = '$HeadURL: https://oss.gonicus.de/repositories/gosa/trunk/gosa-si/gosa-si-server $:$Rev$';
+
# revision number of server and program name
my $server_headURL;
my $server_revision;
no strict "refs";
require ("GOSA/".$db_module.".pm");
("GOSA/".$db_module)->import;
-#daemon_log("0 INFO: importing database module '$db_module'", 1);
}
my $modules_path = "/usr/lib/gosa-si/modules";
$wake_on_lan_passwd, $job_synchronization, $modified_jobs_loop_delay,
$arp_enabled, $arp_interface,
$opsi_enabled, $opsi_server, $opsi_admin, $opsi_password,
- $new_systems_ou,
+ $new_systems_ou,
+ $arch,
);
# additional variable which should be globaly accessable
our $no_arp;
our $forground;
our $cfg_file;
-our ($ldap_uri, $ldap_base, $ldap_admin_dn, $ldap_admin_password, $ldap_server_dn, $ldap_version);
+our ($ldap_uri, $ldap_base, $ldap_admin_dn, $ldap_admin_password, $ldap_server_dn, $ldap_version, $ldap_retry_sec);
our ($mysql_username, $mysql_password, $mysql_database, $mysql_host);
our $known_modules;
our $known_functions;
my $packages_list_file_name;
our @packages_list_col_names = ("distribution VARCHAR(255)", "package VARCHAR(255)", "version VARCHAR(255)", "section VARCHAR(255)", "description TEXT", "template LONGBLOB", "timestamp VARCHAR(14)");
my $outdir = "/tmp/packages_list_db";
-my $arch = "i386";
# holds all messages which should be delivered to a user
our $messaging_db;
@@ -248,43 +247,45 @@ our $check_periodic = {"months"=>'', "weeks"=>'', "days"=>'', "hours"=>'', "minu
"messaging" => [\$messaging_file_name, '/var/lib/gosa-si/messaging.db'],
"foreign-clients" => [\$foreign_clients_file_name, '/var/lib/gosa-si/foreign_clients.db'],
"source-list" => [\$sources_list, '/etc/apt/sources.list'],
- "repo-path" => [\$repo_path, '/srv/www/repository'],
+ "repo-path" => [\$repo_path, '/srv/www'],
+ "debian-arch" => [\$arch, 'i386'],
"ldap-uri" => [\$ldap_uri, ""],
"ldap-base" => [\$ldap_base, ""],
"ldap-admin-dn" => [\$ldap_admin_dn, ""],
"ldap-admin-password" => [\$ldap_admin_password, ""],
"ldap-version" => [\$ldap_version, 3],
+ "ldap-retry-sec" => [\$ldap_retry_sec, 10],
"gosa-unit-tag" => [\$gosa_unit_tag, ""],
"max-clients" => [\$max_clients, 10],
"wol-password" => [\$wake_on_lan_passwd, ""],
- "mysql-username" => [\$mysql_username, "gosa_si"],
- "mysql-password" => [\$mysql_password, ""],
- "mysql-database" => [\$mysql_database, "gosa_si"],
- "mysql-host" => [\$mysql_host, "127.0.0.1"],
+ "mysql-username" => [\$mysql_username, "gosa_si"],
+ "mysql-password" => [\$mysql_password, ""],
+ "mysql-database" => [\$mysql_database, "gosa_si"],
+ "mysql-host" => [\$mysql_host, "127.0.0.1"],
},
"GOsaPackages" => {
"job-queue" => [\$job_queue_file_name, '/var/lib/gosa-si/jobs.db'],
"job-queue-loop-delay" => [\$job_queue_loop_delay, 3],
"messaging-db-loop-delay" => [\$messaging_db_loop_delay, 3],
"key" => [\$GosaPackages_key, "none"],
- "new-systems-ou" => [\$new_systems_ou, 'ou=workstations,ou=systems'],
+ "new-systems-ou" => [\$new_systems_ou, 'ou=workstations,ou=systems'],
},
"ClientPackages" => {
"key" => [\$ClientPackages_key, "none"],
"user-date-of-expiry" => [\$logged_in_user_date_of_expiry, 600],
},
"ServerPackages"=> {
- "enabled" => [\$serverPackages_enabled, "true"],
+ "enabled" => [\$serverPackages_enabled, "true"],
"address" => [\$foreign_server_string, ""],
- "dns-lookup" => [\$dns_lookup, "true"],
- "domain" => [\$server_domain, ""],
- "key" => [\$ServerPackages_key, "none"],
+ "dns-lookup" => [\$dns_lookup, "true"],
+ "domain" => [\$server_domain, ""],
+ "key" => [\$ServerPackages_key, "none"],
"key-lifetime" => [\$foreign_servers_register_delay, 120],
"job-synchronization-enabled" => [\$job_synchronization, "true"],
"synchronization-loop" => [\$modified_jobs_loop_delay, 5],
},
"ArpHandler" => {
- "enabled" => [\$arp_enabled, "true"],
+ "enabled" => [\$arp_enabled, "false"],
"interface" => [\$arp_interface, "all"],
},
"Opsi" => {
'vvvvvvv': debug plus info logs
-no-arp : starts $prg without connection to arp module
-d <int> : if verbose level is higher than 7x 'v' specified parts can be debugged
- 1 : receiving messages
- 2 : sending messages
- 4 : encrypting/decrypting messages
- 8 : verification if a message complies gosa-si requirements
+ 1 : report incoming messages
+ 2 : report unencrypted outgoing messages
+ 4 : report encrypting key for messages
+ 8 : report decrypted incoming message and verification if the message complies gosa-si requirements
16 : message processing
32 : ldap connectivity
64 : database status and connectivity
128 : main process
+ 256 : creation of packages_list_db
+ 512 : ARP debug information
EOF
exit(0);
}
$monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
$year+=1900;
-
+ # Microseconds since epoch
+ my $microSeconds = sprintf("%.2f", &Time::HiRes::clock_gettime());
+ $microSeconds =~ s/^\d*(.\d\d)$/$1/;
+
# Build log message and write it to log file and commandline
chomp($msg);
- my $log_msg = "$month $monthday $hours:$minutes:$seconds $prg $msg\n";
+ my $log_msg = "$month $monthday $hours:$minutes:$seconds$microSeconds $prg $msg\n";
flock(LOG_HANDLE, LOCK_EX);
seek(LOG_HANDLE, 0, 2);
print LOG_HANDLE $log_msg;
sub check_pid {
$pid = -1;
# Check, if we are already running
- if( open(LOCK_FILE, "<$pid_file") ) {
- $pid = <LOCK_FILE>;
+ if( open( my $LOCK_FILE, "<", "$pid_file" ) ) {
+ $pid = <$LOCK_FILE>;
if( defined $pid ) {
chomp( $pid );
if( -f "/proc/$pid/stat" ) {
my($stat) = `cat /proc/$pid/stat` =~ m/$pid \((.+)\).*/;
if( $stat ) {
print STDERR "\nERROR: Already running!\n";
- close( LOCK_FILE );
+ close( $LOCK_FILE );
exit -1;
}
}
# create a syslog msg if it is not to possible to open PID file
if (not sysopen(LOCK_FILE, $pid_file, O_WRONLY|O_CREAT|O_EXCL, 0644)) {
my($msg) = "Couldn't obtain lockfile '$pid_file' ";
- if (open(LOCK_FILE, '<', $pid_file)
- && ($pid = <LOCK_FILE>))
+ if (open(my $LOCK_FILE, '<', $pid_file)
+ && ($pid = <$LOCK_FILE>))
{
chomp($pid);
$msg .= "(PID $pid)\n";
if($new_status eq "down"){
daemon_log("$session_id WARNING: set '$address' from status '$act_status' to '$new_status'", 3);
} else {
- daemon_log("$session_id INFO: set '$address' from status '$act_status' to '$new_status'", 5);
+ daemon_log("$session_id DEBUG: set '$address' from status '$act_status' to '$new_status'", 138);
}
}
}
if($new_status eq "down"){
daemon_log("$session_id WARNING: set '$address' from status '$act_status' to '$new_status'", 3);
} else {
- daemon_log("$session_id INFO: set '$address' from status '$act_status' to '$new_status'", 5);
+ daemon_log("$session_id DEBUG: set '$address' from status '$act_status' to '$new_status'", 138);
}
}
}
||($job_header eq "trigger_action_reinstall")
||($job_header eq "trigger_activate_new")
) {
- &reactivate_job_with_delay($session_id, $job_target, $job_header, 30 );
-
+ if ($job_target =~ /^([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2})$/i) {
+ &reactivate_job_with_delay($session_id, $job_target, $job_header, 30 );
+ } else {
+ # If we don't have the mac adress at this time, we use the plainname
+ my $plainname_result = $job_db->select_dbentry("SELECT plainname from jobs where id=$jobdb_id");
+ my $plainname = $job_target;
+ if ((keys(%$plainname_result) > 0) ) {
+ $plainname = $plainname_result->{1}->{$job_target};
+ }
+ &reactivate_job_with_delay($session_id, $plainname, $job_header, 30 );
+ }
# For all other messages
} else {
my $sql_statement = "UPDATE $job_queue_tn ".
if (not defined $delay) { $delay = 30 } ;
my $delay_timestamp = &calc_timestamp(&get_time(), "plus", $delay);
- my $sql = "UPDATE $job_queue_tn Set timestamp='$delay_timestamp', status='waiting' WHERE (macaddress LIKE 'target' AND headertag='$header')";
+ my $sql = "UPDATE $job_queue_tn Set timestamp='$delay_timestamp', status='waiting' WHERE (macaddress LIKE '$target' OR plainname LIKE '$target') AND headertag='$header'";
my $res = $job_db->update_dbentry($sql);
daemon_log("$session_id INFO: '$header'-job will be reactivated at '$delay_timestamp' ".
"cause client '$target' is currently not available", 5);
module=>$module,
sessionid=>$session_id,
} );
-
+ $kernel->yield('watch_for_next_tasks');
}
# target is own address with forward_to_gosa-tag pointing at myself -> forward to gosa
sessionid=>$session_id,
} );
$done = 1;
+ $kernel->yield('watch_for_next_tasks');
}
while ($answer_str =~ /<header>(\w+)<\/header>/g) {
push(@headers, $1);
}
- daemon_log("$session_id INFO: got answer message(s) with header: '".join("', '", @headers)."'", 5);
- daemon_log("$session_id DEBUG: $module: got answer from module: \n".$answer_str,26);
+ daemon_log("$session_id DEBUG: got answer message(s) with header: '".join("', '", @headers)."'", 26);
} else {
daemon_log("$session_id DEBUG: $module: got no answer from module!" ,26);
}
if( defined $session_id ) {
$add_on = ".session_id=$session_id";
}
+ my $header = ($1) if $answer =~ /<header>(\S*)<\/header>/;
+ daemon_log("$session_id INFO: send ".$header." message to GOsa", 5);
+ daemon_log("$session_id DEBUG: message:\n$answer", 12);
# answer is for GOSA and has to returned to connected client
my $gosa_answer = &encrypt_msg($answer, $GosaPackages_key);
$client_answer = $gosa_answer.$add_on;
# Target of msg is a mac address
elsif( $answer_target =~ /^([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2})$/i ) {
- daemon_log("$session_id INFO: target is mac address '$answer_target', looking for host in known_clients and foreign_clients", 5);
+ daemon_log("$session_id DEBUG: target is mac address '$answer_target', looking for host in known_clients and foreign_clients", 138);
# Looking for macaddress in known_clients
my $sql_statement = "SELECT * FROM known_clients WHERE macaddress LIKE '$answer_target'";
$kernel->yield('register_at_foreign_servers');
$kernel->yield('create_fai_server_db', $fai_server_tn );
$kernel->yield('create_fai_release_db', $fai_release_tn );
- $kernel->yield('watch_for_next_tasks');
$kernel->sig(USR1 => "sig_handler");
$kernel->sig(USR2 => "recreate_packages_db");
$kernel->delay_set('watch_for_new_jobs', $job_queue_loop_delay);
sub watch_for_opsi_jobs {
my ($kernel) = $_[KERNEL];
-
# This is not very nice to look for opsi install jobs, but headertag has to be trigger_action_reinstall. The only way to identify a
# opsi install job is to parse the xml message. There is still the correct header.
my $sql_statement = "SELECT * FROM ".$job_queue_tn." WHERE ((xmlmessage LIKE '%opsi_install_client</header>%') AND (status='processing') AND (siserver='localhost'))";
};
my $hres = $opsi_client->call($opsi_url, $callobj);
- #my ($hres_err, $hres_err_string) = &check_opsi_res($hres);
+ # TODO : move all opsi relevant statments to opsi plugin
+ # The following 3 lines must be tested befor they can replace the rubbish above and below !!!
+ #my ($res, $err) = &opsi_com::_getProductStates_hash(hostId=>$hostId)
+ #if (not $err) {
+ # my $htmp = $res->{$hostId};
+ #
if (not &check_opsi_res($hres)) {
my $htmp= $hres->result->{$hostId};
-
# Check state != not_installed or action == setup -> load and add
my $products= 0;
my $installed= 0;
my $sql = "DELETE FROM $incoming_tn WHERE id=$message_id";
my $res = $incoming_db->exec_statement($sql);
}
-
- $kernel->delay_set('watch_for_next_tasks', 1);
}
get_handle:
my $ldap_handle = Net::LDAP->new( $ldap_uri );
if (not ref $ldap_handle) {
- daemon_log("$session_id ERROR: Connection to LDAP URI '$ldap_uri' failed! Retrying!", 1);
- usleep(100000);
+ daemon_log("$session_id ERROR: Connection to LDAP URI '$ldap_uri' failed! Retrying in $ldap_retry_sec seconds.", 1);
+ sleep($ldap_retry_sec);
goto get_handle;
} else {
daemon_log("$session_id DEBUG: Connection to LDAP URI '$ldap_uri' established.", 42);
}
my $fh;
- open($fh, ">$result");
+ open(my $fh, ">", "$result");
if (not defined $fh) {
&main::daemon_log("$session_id DEBUG: cannot open '$result' for writing", 7);
return undef;
my $line;
- open(CONFIG, "<$sources_file") or do {
+ open(my $CONFIG, "<", "$sources_file") or do {
daemon_log( "$session_id ERROR: create_packages_list_db: Failed to open '$sources_file'", 1);
unlink($packages_list_under_construction);
return;
&parse_package_info( $baseurl, $dist, $section, $session_id );
}
}
+ else {
+ daemon_log("$session_id ERROR: cannot parse line '$line'", 1);
+ }
}
- close (CONFIG);
+ close ($CONFIG);
if(keys(%repo_dirs)) {
find(\&cleanup_and_extract, keys( %repo_dirs ));
$repo_dirs{ "${repo_path}/pool" } = 1;
foreach $package ("Packages.gz"){
- daemon_log("$session_id DEBUG: create_packages_list: fetch $baseurl, $dist, $section", 7);
+ daemon_log("$session_id DEBUG: create_packages_list: fetch $baseurl, $dist, $section", 266);
get_package( "$baseurl/dists/$dist/$section/binary-$arch/$package", "$outdir/$dist/$section", $session_id );
parse_package( "$outdir/$dist/$section", $dist, $path, $session_id );
}
# This is ugly, but I've no time to take a look at "how it works in perl"
if(0 == system("wget '$url' -O '$dest' 2>/dev/null") ) {
system("gunzip -cd '$dest' > '$dest.in'");
- daemon_log("$session_id DEBUG: run command: gunzip -cd '$dest' > '$dest.in'", 7);
+ daemon_log("$session_id DEBUG: run command: gunzip -cd '$dest' > '$dest.in'", 266);
unlink($dest);
- daemon_log("$session_id DEBUG: delete file '$dest'", 7);
+ daemon_log("$session_id DEBUG: delete file '$dest'", 266);
} else {
daemon_log("$session_id ERROR: create_packages_list_db: get_packages: fetching '$url' into '$dest' failed!", 1);
}
return;
}
- open($PACKAGES, "<$path.in");
+ open(my $PACKAGES, "<", "$path.in");
if(not defined($PACKAGES)) {
daemon_log("$session_id ERROR: create_packages_list_db: parse_package: cannot open '$path.in'",1);
return;
if( -f "$dir/DEBIAN/templates" ) {
- daemon_log("0 DEBUG: Found debconf templates in '$package' - $newver", 7);
+ daemon_log("0 DEBUG: Found debconf templates in '$package' - $newver", 266);
my $tmpl= ""; {
local $/=undef;
- open FILE, "$dir/DEBIAN/templates";
- $tmpl = &encode_base64(<FILE>);
- close FILE;
+ open(my $FILE, "$dir/DEBIAN/templates");
+ $tmpl = &encode_base64(<$FILE>);
+ close($FILE);
}
rmtree("$dir/DEBIAN/templates");
# Do something useful - put our PID into the pid_file
if( 0 != $pid ) {
- open( LOCK_FILE, ">$pid_file" );
- print LOCK_FILE "$pid\n";
- close( LOCK_FILE );
+ open( my $LOCK_FILE, ">", "$pid_file" );
+ print $LOCK_FILE "$pid\n";
+ close( $LOCK_FILE );
if( !$foreground ) {
exit( 0 )
};
# Prepare log file and set permissions
$root_uid = getpwnam('root');
$adm_gid = getgrnam('adm');
-open(FH, ">>$log_file");
-close FH;
+open(my $FH, ">>", "$log_file");
+close($FH);
chmod(0440, $log_file);
chown($root_uid, $adm_gid, $log_file);
chown($root_uid, $adm_gid, "/var/lib/gosa-si");
no strict "refs";
if ($db_module eq "DBmysql") {
+
+ daemon_log("0 INFO: importing database module '$db_module'", 1);
+
# connect to incoming_db
$incoming_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
$messaging_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
} elsif ($db_module eq "DBsqlite") {
+
+ daemon_log("0 INFO: importing database module '$db_module'", 1);
+
# connect to incoming_db
unlink($incoming_file_name);
$incoming_db = GOSA::DBsqlite->new($incoming_file_name);
}
# Creating tables
+
+daemon_log("0 INFO: creating tables in database with '$db_module'", 1);
+
$messaging_db->create_table($messaging_tn, \@messaging_col_names);
$packages_list_db->create_table($packages_list_tn, \@packages_list_col_names);
$fai_release_db->create_table($fai_release_tn, \@fai_release_col_names);
},
InlineStates => {
msg_to_decrypt => \&msg_to_decrypt,
+ watch_for_next_tasks => \&watch_for_next_tasks,
next_task => \&next_task,
task_result => \&handle_task_result,
task_done => \&handle_task_done,
task_result => \&handle_task_result,
task_done => \&handle_task_done,
task_debug => \&handle_task_debug,
- watch_for_next_tasks => \&watch_for_next_tasks,
watch_for_new_messages => \&watch_for_new_messages,
watch_for_delivery_messages => \&watch_for_delivery_messages,
watch_for_done_messages => \&watch_for_done_messages,