From 38b04057253226b9eb1cf50f2917abb4b6ef96d8 Mon Sep 17 00:00:00 2001 From: opensides Date: Wed, 28 Jul 2010 19:30:11 +0000 Subject: [PATCH] - First stable version of GOsa-si from trunk, more fixes to come git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6@19193 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/README | 2 +- gosa-si/client.conf | 10 +- gosa-si/client.conf.pod | 14 +- gosa-si/client/events/corefunctions.pm | 244 ++++--- gosa-si/client/events/dak.pm | 22 +- gosa-si/client/events/gosaTriggered.pm | 46 +- gosa-si/client/events/installation.pm | 20 +- gosa-si/client/events/krb5.pm | 23 +- gosa-si/client/events/load_reporter.pm | 52 +- gosa-si/client/events/mailqueue.pm | 36 +- gosa-si/debian/README.source | 1 + gosa-si/debian/changelog | 4 +- gosa-si/debian/control | 20 +- gosa-si/debian/copyright | 9 +- gosa-si/debian/gosa-si-client.default | 4 + gosa-si/debian/gosa-si-client.init | 84 +++ .../debian/gosa-si-client.lintian-overrides | 1 - gosa-si/debian/gosa-si-client.logrotate | 1 - gosa-si/debian/gosa-si-client.postinst | 6 +- gosa-si/debian/gosa-si-common.default | 3 - gosa-si/debian/gosa-si-common.dirs | 4 +- gosa-si/debian/gosa-si-common.init | 134 ---- gosa-si/debian/gosa-si-common.install | 6 +- gosa-si/debian/gosa-si-common.postinst | 7 +- gosa-si/debian/gosa-si-server-opsi.install | 7 +- gosa-si/debian/gosa-si-server.default | 6 + gosa-si/debian/gosa-si-server.init | 85 +++ gosa-si/debian/gosa-si-server.install | 28 +- .../debian/gosa-si-server.lintian-overrides | 2 - gosa-si/debian/gosa-si-server.logrotate | 1 - gosa-si/debian/gosa-si-server.postinst | 6 +- gosa-si/debian/rules | 14 +- gosa-si/gosa-si-client | 683 +++++++++++------- gosa-si/gosa-si-client.1 | 10 +- gosa-si/gosa-si-client.conf.5 | 30 +- gosa-si/gosa-si-client.pod | 56 -- gosa-si/gosa-si-server | 669 +++++++++-------- gosa-si/gosa-si-server.1 | 12 +- gosa-si/gosa-si-server.conf.5 | 32 +- gosa-si/gosa-si-server.pod | 71 -- gosa-si/modules/ArpHandler.pm | 18 +- gosa-si/modules/ClientPackages.pm | 31 +- gosa-si/modules/DBsqlite.pm | 73 +- gosa-si/modules/GosaPackages.pm | 27 +- gosa-si/modules/GosaSupportDaemon.pm | 86 +-- gosa-si/modules/ServerPackages.pm | 10 +- gosa-si/modules/TestModule.pm | 9 +- gosa-si/server.conf | 8 +- gosa-si/server.conf.pod | 18 +- gosa-si/server/events/clMessages.pm | 26 +- gosa-si/server/events/databases.pm | 19 +- gosa-si/server/events/gosaTriggered.pm | 33 +- gosa-si/server/events/logHandling.pm | 28 +- gosa-si/server/events/mailqueue_com.pm | 26 +- gosa-si/server/events/opsi_com.pm | 21 +- gosa-si/server/events/server_server_com.pm | 24 +- gosa-si/server/events/siTriggered.pm | 36 +- 57 files changed, 1612 insertions(+), 1346 deletions(-) create mode 100644 gosa-si/debian/README.source create mode 100644 gosa-si/debian/gosa-si-client.default create mode 100644 gosa-si/debian/gosa-si-client.init delete mode 100644 gosa-si/debian/gosa-si-client.lintian-overrides delete mode 100644 gosa-si/debian/gosa-si-common.default delete mode 100755 gosa-si/debian/gosa-si-common.init create mode 100644 gosa-si/debian/gosa-si-server.default create mode 100644 gosa-si/debian/gosa-si-server.init delete mode 100644 gosa-si/debian/gosa-si-server.lintian-overrides delete mode 100644 gosa-si/gosa-si-client.pod delete mode 100644 gosa-si/gosa-si-server.pod diff --git a/gosa-si/README b/gosa-si/README index 961e7b826..8e545bc08 100644 --- a/gosa-si/README +++ b/gosa-si/README @@ -1,5 +1,5 @@ -/usr/share/perl5/GOSA +/usr/share/perl5/GOsaSI common: - GosaSupportDaemon.pm - DBsqlite.pm diff --git a/gosa-si/client.conf b/gosa-si/client.conf index bf2ebfcc8..88008aee5 100644 --- a/gosa-si/client.conf +++ b/gosa-si/client.conf @@ -1,11 +1,11 @@ -[general] -log-file = /var/log/gosa-si-client.log -pid-file = /var/run/gosa-si-client.pid +[General] +log-file = /var/log/gosa-si/gosa-si-client.log +pid-file = /var/run/gosa-si/gosa-si-client.pid -[client] +[Client] fai-logpath = /var/log/fai/fai.log -[server] +[Server] key = secret-server-password #[krb5] diff --git a/gosa-si/client.conf.pod b/gosa-si/client.conf.pod index 6f5a2a3ad..68b91d6d9 100644 --- a/gosa-si/client.conf.pod +++ b/gosa-si/client.conf.pod @@ -10,26 +10,26 @@ The gosa-si-client.conf file defines all parameter GOsa-SI-client needs for runn =head1 DIRECTIVES -=head2 [general] +=head2 [General] =over 4 -=item log-file = /var/run/gosa-si-client.log +=item log-file = /var/log/gosa-si/gosa-si-client.log Defines the location for the log file. -=item pid-file = /var/run/gosa-si-client.pid +=item pid-file = /var/run/gosa-si/gosa-si-client.pid Defines the location for the pid file. -=item opts-file = var/run/gosa-si-client.opts +=item opts-file = var/run/gosa-si/gosa-si-client.opts Defines the location for the opts file. =back -=head2 [client] +=head2 [Client] =over 4 @@ -80,7 +80,7 @@ Open a different fifo for system communication =back -=head2 [server] +=head2 [Server] =over 4 @@ -131,7 +131,7 @@ Please report any bugs, or post any suggestions, to the GOsa mailing list ) -Copyright (C) 2003-2009 GONICUS GmbH +Copyright (C) 2003-2010 GONICUS GmbH This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of diff --git a/gosa-si/client/events/corefunctions.pm b/gosa-si/client/events/corefunctions.pm index 1b387e5fe..fadd579f4 100644 --- a/gosa-si/client/events/corefunctions.pm +++ b/gosa-si/client/events/corefunctions.pm @@ -1,32 +1,39 @@ package corefunctions; -use Exporter; -@ISA = qw(Exporter); -my @events = ( - "get_events", - "registered", - 'new_syslog_config', - "new_ntp_config", - "new_ldap_config", - "new_key", - "generate_hw_digest", # no implementations - "detect_hardware", - "confirm_new_key", - "ping", - "import_events", # no implementations - ); -@EXPORT = @events; use strict; use warnings; -use Fcntl; -use GOSA::GosaSupportDaemon; + use File::Basename; +use GOsaSI::GosaSupportDaemon; + +use Exporter; +use Fcntl; + -my ($ldap_enabled, $offline_enabled, $ldap_config, $pam_config, $nss_config, $fai_logpath); +our @ISA = qw(Exporter); + +my @events = ( + "get_events", + "registered", + "new_syslog_config", + "new_ntp_config", + "new_ldap_config", + "new_key", + "generate_hw_digest", # no implementations + "detect_hardware", + "confirm_new_key", + "ping", + "import_events", # no implementations + ); + +our @EXPORT = @events; + +my ($ldap_enabled, $offline_enabled, $ldap_config, $pam_config, $nss_config, $fai_logpath, $ldap_config_exit_hook); my $chrony_file = "/etc/chrony/chrony.conf"; my $syslog_file = "/etc/syslog.conf"; +# why is it re read here, the config is read at the start of the program no !! my %cfg_defaults = ( "client" => { "ldap" => [\$ldap_enabled, 1], @@ -35,6 +42,7 @@ my %cfg_defaults = ( "pam-config" => [\$pam_config, "/etc/pam_ldap.conf"], "nss-config" => [\$nss_config, "/etc/libnss-ldap.conf"], "fai-logpath" => [\$fai_logpath, "/var/log/fai/fai.log"], + "ldap-config-exit-hook" => [\$ldap_config_exit_hook, undef], }, ); @@ -44,6 +52,7 @@ END {} ### Start ###################################################################### +# why not using the config read in the main ?? !! &main::read_configfile($main::cfg_file, %cfg_defaults); @@ -69,18 +78,18 @@ sub write_to_file { chomp($string); if( not -f $file ) { - open (FILE, "$file"); - close(FILE); + open (my $FD_FILE, "$file"); + close($FD_FILE); } - open(FILE, ">> $file") or &main::daemon_log("ERROR in corefunctions.pm: can not open '$file' to write '$string'", 1);; - print FILE $string."\n"; - close(FILE); + open(my $FD_FILE, ">>", "$file") or &main::daemon_log("ERROR in corefunctions.pm: can not open '$file' to write '$string'", 1);; + print $FD_FILE $string."\n"; + close($FD_FILE); } - return; + return; } - +# should be the first function of each module of gosa-si !! sub get_events { return \@events; } @@ -151,7 +160,7 @@ sub server_leaving { # registrated at new daemon &main::register_at_server(); - return; + return; } @@ -180,9 +189,9 @@ sub new_syslog_config { } # Substitute existing server with new syslog server - open (FILE, "<$syslog_file"); - my @file = ; - close FILE; + open (my $syslog, "<","$syslog_file"); + my @file = <$syslog>; + close($syslog); my $syslog_server_line = "*.*\t@".$syslog_server."\n"; foreach my $line (@file) { if ($line =~ /^\*\.\*\s+@/) { @@ -198,9 +207,9 @@ sub new_syslog_config { } # Write changes to file and close it - open (FILE, "+>$syslog_file"); - print FILE join("", @file); - close FILE; + open (my $new_syslog, "+>","$syslog_file"); + print $new_syslog join("", @file); + close($new_syslog); &main::daemon_log("INFO: Wrote new configuration file: $syslog_file", 5); # Restart syslog deamon @@ -237,9 +246,9 @@ sub new_ntp_config { } # Substitute existing server with new ntp server - open (FILE, "<$chrony_file"); - my @file = ; - close FILE; + open (my $ntp, "<","$chrony_file"); + my @file = <$ntp>; + close($ntp); my @new_file; foreach my $line (@file) { if ($line =~ /^server\s+/) { @@ -260,9 +269,9 @@ sub new_ntp_config { } # Write changes to file and close it - open (FILE, ">$chrony_file"); - print FILE join("", @new_file); - close FILE; + open (my $new_ntp, ">","$chrony_file"); + print $new_ntp join("", @new_file); + close($new_ntp); &main::daemon_log("INFO: Wrote new configuration file: $chrony_file", 5); # Restart chrony deamon @@ -292,7 +301,18 @@ sub new_ldap_config { my $department= ""; my $release= ""; my $unit_tag; - + my $ldap_file; + my $pam_file; + my $nss_file; + my $goto_file; + my $goto_secret_file; + my $ldap_offline_file; + my $ldap_shell_file; + + my $ldap_shell_config = "/etc/ldap/ldap-shell.conf"; + my $ldap_offline_config = "/etc/ldap/ldap-offline.conf"; + my $goto_secret_config = "/etc/goto/secret"; + # Transform input into array while ( my ($key, $value) = each(%$msg_hash) ) { if ($key =~ /^(source|target|header)$/) { @@ -355,97 +375,113 @@ sub new_ldap_config { } # Setup ldap.conf - my $file1; - my $file2; - open(file1, "> $ldap_config"); - print file1 "# This file was automatically generated by gosa-si-client. Do not change.\n"; - print file1 "URI"; + open($ldap_file, ">","$ldap_config"); + print $ldap_file "# This file was automatically generated by gosa-si-client. Do not change.\n"; + print $ldap_file "URI"; + foreach $element (@ldap_uris) { - print file1 " $element"; + print $ldap_file " $element"; } - print file1 "\nBASE $ldap_base\n"; + + print $ldap_file "\nBASE $ldap_base\n"; foreach $element (@ldap_options) { - print file1 "$element\n"; + print $ldap_file "$element\n"; } - close (file1); + + close ($ldap_file); daemon_log("INFO: Wrote $ldap_config", 5); # Setup pam_ldap.conf / libnss-ldap.conf - open(file1, "> $pam_config"); - open(file2, "> $nss_config"); - print file1 "# This file was automatically generated by gosa-si-client. Do not change.\n"; - print file2 "# This file was automatically generated by gosa-si-client. Do not change.\n"; - print file1 "uri"; - print file2 "uri"; + open($pam_file, ">","$pam_config"); + open($nss_file, ">","$nss_config"); + print $pam_file "# This file was automatically generated by gosa-si-client. Do not change.\n"; + print $nss_file "# This file was automatically generated by gosa-si-client. Do not change.\n"; + print $pam_file "uri"; + print $nss_file "uri"; + foreach $element (@ldap_uris) { - print file1 " $element"; - print file2 " $element"; + print $pam_file " $element"; + print $nss_file " $element"; } - print file1 "\nbase $ldap_base\n"; - print file2 "\nbase $ldap_base\n"; + + print $pam_file "\nbase $ldap_base\n"; + print $nss_file "\nbase $ldap_base\n"; + foreach $element (@pam_options) { - print file1 "$element\n"; + print $pam_file "$element\n"; } + foreach $element (@nss_options) { - print file2 "$element\n"; + print $nss_file "$element\n"; } - close (file2); + + close ($nss_file); daemon_log("INFO: Wrote $nss_config", 5); - close (file1); + close ($pam_file); daemon_log("INFO: Wrote $pam_config", 5); # Create goto.secrets if told so - for compatibility reasons if (defined $goto_admin){ - open(file1, "> /etc/goto/secret"); - close(file1); - chown(0,0, "/etc/goto/secret"); - chmod(0600, "/etc/goto/secret"); - open(file1, "> /etc/goto/secret"); - print file1 "GOTOADMIN=\"$goto_admin\"\nGOTOSECRET=\"$goto_secret\"\n"; - close(file1); - daemon_log("INFO: Wrote /etc/goto/secret", 5); + open($goto_file, ">",$goto_secret_config); + print $goto_file "GOTOADMIN=\"$goto_admin\"\nGOTOSECRET=\"$goto_secret\"\n"; + close($goto_file); + chown(0,0, $goto_file); + chmod(0600, $goto_file); + daemon_log("INFO: Wrote $goto_secret_config", 5); } # Write shell based config - my $cfg_name= "/etc/ldap/ldap-shell.conf"; # Get first LDAP server my $ldap_server= $ldap_uris[0]; $ldap_server=~ s/^ldap:\/\/([^:]+).*$/$1/; - open(file1, "> $cfg_name"); - print file1 "LDAP_BASE=\"$ldap_base\"\n"; - print file1 "LDAP_SERVER=\"$ldap_server\"\n"; - print file1 "LDAP_URIS=\"@ldap_uris\"\n"; - print file1 "ADMIN_BASE=\"$admin_base\"\n"; - print file1 "DEPARTMENT=\"$department\"\n"; - print file1 "RELEASE=\"$release\"\n"; - print file1 "UNIT_TAG=\"".(defined $unit_tag ? "$unit_tag" : "")."\"\n"; - print file1 "UNIT_TAG_FILTER=\"".(defined $unit_tag ? "(gosaUnitTag=$unit_tag)" : "")."\"\n"; - close(file1); - daemon_log("INFO: Wrote $cfg_name", 5); + open($ldap_shell_file, ">","$ldap_shell_config"); + print $ldap_shell_file "LDAP_BASE=\"$ldap_base\"\n"; + print $ldap_shell_file "LDAP_SERVER=\"$ldap_server\"\n"; + print $ldap_shell_file "LDAP_URIS=\"@ldap_uris\"\n"; + print $ldap_shell_file "ADMIN_BASE=\"$admin_base\"\n"; + print $ldap_shell_file "DEPARTMENT=\"$department\"\n"; + print $ldap_shell_file "RELEASE=\"$release\"\n"; + print $ldap_shell_file "UNIT_TAG=\"".(defined $unit_tag ? "$unit_tag" : "")."\"\n"; + print $ldap_shell_file "UNIT_TAG_FILTER=\"".(defined $unit_tag ? "(gosaUnitTag=$unit_tag)" : "")."\"\n"; + close($ldap_shell_file); + + # Set permissions and ownership structure of + chown(0, 0, $ldap_shell_file); + chmod(0644, $ldap_shell_file); + + daemon_log("INFO: Wrote $ldap_shell_config", 5); # Write offline config if ($offline_enabled){ - $cfg_name= "/etc/ldap/ldap-offline.conf"; # Get first LDAP server - open(file1, "> $cfg_name"); - print file1 "LDAP_BASE=\"$ldap_base\"\n"; - print file1 "LDAP_SERVER=\"127.0.0.1\"\n"; - print file1 "LDAP_URIS=\"ldap://127.0.0.1\"\n"; - print file1 "ADMIN_BASE=\"$admin_base\"\n"; - print file1 "DEPARTMENT=\"$department\"\n"; - print file1 "RELEASE=\"$release\"\n"; - print file1 "UNIT_TAG=\"".(defined $unit_tag ? "$unit_tag" : "")."\"\n"; - print file1 "UNIT_TAG_FILTER=\"".(defined $unit_tag ? "(gosaUnitTag=$unit_tag)" : "")."\"\n"; - close(file1); - daemon_log("INFO: Wrote $cfg_name", 5); + open( $ldap_offline_file, ">","$ldap_offline_config"); + print $ldap_offline_file "LDAP_BASE=\"$ldap_base\"\n"; + print $ldap_offline_file "LDAP_SERVER=\"127.0.0.1\"\n"; + print $ldap_offline_file "LDAP_URIS=\"ldap://127.0.0.1\"\n"; + print $ldap_offline_file "ADMIN_BASE=\"$admin_base\"\n"; + print $ldap_offline_file "DEPARTMENT=\"$department\"\n"; + print $ldap_offline_file "RELEASE=\"$release\"\n"; + print $ldap_offline_file "UNIT_TAG=\"".(defined $unit_tag ? "$unit_tag" : "")."\"\n"; + print $ldap_offline_file "UNIT_TAG_FILTER=\"".(defined $unit_tag ? "(gosaUnitTag=$unit_tag)" : "")."\"\n"; + close($ldap_offline_file); + + # Set permissions and ownership structure of + chown(0, 0, $ldap_offline_file); + chmod(0644, $ldap_offline_file); + + daemon_log("INFO: Wrote $ldap_offline_config", 5); } - # Set permissions and ownership structure of - chown(0, 0, $cfg_name); - chmod(0644, $cfg_name); + + + # Allow custom scripts to be executed + if (defined $ldap_config_exit_hook) { + system($ldap_config_exit_hook); + daemon_log("Hook $ldap_config_exit_hook returned with code ".($? >> 8), 5); + } return; } @@ -467,7 +503,7 @@ sub new_key { $main::server_key = $new_server_key; } - return; + return; } @@ -592,11 +628,11 @@ sub detect_hardware { &main::daemon_log("Hardware detection done!", 4); &write_to_file('goto-hardware-detection-stop', $fai_logpath); - - &main::send_msg_hash_to_target( - &main::create_xml_hash("detected_hardware", $main::client_address, $main::server_address, $result), - $main::server_address, - $main::server_key, + + &main::send_msg_hash_to_target( + &main::create_xml_hash("detected_hardware", $main::client_address, $main::server_address, $result), + $main::server_address, + $main::server_key, ); return; diff --git a/gosa-si/client/events/dak.pm b/gosa-si/client/events/dak.pm index c1566a8ee..0b1cb129b 100644 --- a/gosa-si/client/events/dak.pm +++ b/gosa-si/client/events/dak.pm @@ -3,21 +3,25 @@ # @brief Implementation of a GOsa-SI-client event module. package dak; + +use strict; +use warnings; + +use GOsaSI::GosaSupportDaemon; +use MIME::Base64; + use Exporter; -@ISA = qw(Exporter); + +our @ISA = qw(Exporter); + my @events = ( "get_events", "get_dak_keyring", "import_dak_key", "remove_dak_key", ); -@EXPORT = @events; - -use strict; -use warnings; -use GOSA::GosaSupportDaemon; -use MIME::Base64; +our @EXPORT = @events; BEGIN {} @@ -33,7 +37,7 @@ my %cfg_defaults = ( "dak-user" => [\$dak_user, "deb-dak"], }, ); -&GOSA::GosaSupportDaemon::read_configfile($main::config_file, %cfg_defaults); +&GOsaSI::GosaSupportDaemon::read_configfile($main::config_file, %cfg_defaults); ## @method get_events() @@ -129,7 +133,7 @@ sub import_dak_key { &add_content2xml_hash($out_hash, "error", "DAK Keyring is not writable"); } else { my $keyfile; - open($keyfile, ">/tmp/gosa_si_tmp_dak_key"); + open(my $keyfile, ">","/tmp/gosa_si_tmp_dak_key"); print $keyfile $key; close($keyfile); my $command = "$gpg --import /tmp/gosa_si_tmp_dak_key"; diff --git a/gosa-si/client/events/gosaTriggered.pm b/gosa-si/client/events/gosaTriggered.pm index e73b69f7c..4a304eb93 100644 --- a/gosa-si/client/events/gosaTriggered.pm +++ b/gosa-si/client/events/gosaTriggered.pm @@ -25,10 +25,19 @@ Andreas Rettenberger =cut - package gosaTriggered; + +use strict; +use warnings; + +use MIME::Base64; +use File::Temp qw/ tempfile/; +use GOsaSI::GosaSupportDaemon; + use Exporter; -@ISA = qw(Exporter); + +our @ISA = qw(Exporter); + my @events = ( "get_events", "usr_msg", @@ -41,13 +50,8 @@ my @events = ( "trigger_action_instant_update", "trigger_goto_settings_reload", ); -@EXPORT = @events; - -use strict; -use warnings; -use GOSA::GosaSupportDaemon; -use MIME::Base64; -use File::Temp qw/ tempfile/; + +our @EXPORT = @events; BEGIN {} @@ -191,9 +195,9 @@ sub trigger_action_localboot { # Check logged in user my @user_list = &get_logged_in_users; if( @user_list >= 1 ) { - open(FILE, "> /etc/gosa-si/event"); - print FILE "trigger_action_localboot\n"; - close(FILE); + open(my $FILE, ">", "/etc/gosa-si/event"); + print $FILE "trigger_action_localboot\n"; + close($FILE); } } else { @@ -291,9 +295,9 @@ sub trigger_action_reboot { my @user_list = &get_logged_in_users; if( @user_list >= 1 ) { system( "/usr/bin/goto-notify reboot" ); - open(FILE, "> /etc/gosa-si/event"); - print FILE "reboot\n"; - close(FILE); + open(my $FILE, ">", "/etc/gosa-si/event"); + print $FILE "reboot\n"; + close($FILE); } } else { @@ -353,9 +357,9 @@ sub trigger_action_halt { my @user_list = &get_logged_in_users; if( @user_list >= 1 ) { system( "/usr/bin/goto-notify halt" ); - open(FILE, "> /etc/gosa-si/event"); - print FILE "halt\n"; - close(FILE); + open(my $FILE, ">", "/etc/gosa-si/event"); + print $FILE "halt\n"; + close($FILE); } } else { system( "/sbin/shutdown -h +$timeout &" ); @@ -405,9 +409,9 @@ sub trigger_action_reinstall { my @user_list = &get_logged_in_users; if( @user_list >= 1 ) { system( "/usr/bin/goto-notify install" ); - open(FILE, "> /etc/gosa-si/event"); - print FILE "install\n"; - close(FILE); + open(my $FILE, ">", "/etc/gosa-si/event"); + print $FILE "install\n"; + close($FILE); } } else { system( "/sbin/shutdown -r now &" ); diff --git a/gosa-si/client/events/installation.pm b/gosa-si/client/events/installation.pm index 9a5fa786a..a335948dd 100644 --- a/gosa-si/client/events/installation.pm +++ b/gosa-si/client/events/installation.pm @@ -1,13 +1,17 @@ package installation; -use Exporter; -@ISA = qw(Exporter); -my @events = qw(get_events set_activated_for_installation); -@EXPORT = @events; use strict; use warnings; + +use Exporter; use Fcntl; +our @ISA = qw(Exporter); + +my @events = qw(get_events set_activated_for_installation); + +our @EXPORT = @events; + BEGIN {} END {} @@ -25,10 +29,10 @@ sub set_activated_for_installation { my $target = @{$msg_hash->{'target'}}[0]; my $source = @{$msg_hash->{'source'}}[0]; - my $Datei = "/var/run/gosa-si-client.activated"; - open(DATEI, ">$Datei"); - print DATEI "$msg\n"; - close DATEI; + my $Datei = "/var/run/gosa-si/gosa-si-client.activated"; + open(my $FILE, ">", "$Datei"); + print $FILE "$msg\n"; + close($FILE); return; } diff --git a/gosa-si/client/events/krb5.pm b/gosa-si/client/events/krb5.pm index c0cc930a6..a4ccd33bc 100644 --- a/gosa-si/client/events/krb5.pm +++ b/gosa-si/client/events/krb5.pm @@ -1,6 +1,17 @@ package krb5; + + +use strict; +use warnings; + +use Authen::Krb5; +use Authen::Krb5::Admin qw(:constants); +use GOsaSI::GosaSupportDaemon; + use Exporter; -@ISA = qw(Exporter); + +our @ISA = qw(Exporter); + my @events = ( "get_events", "krb5_list_principals", @@ -15,13 +26,8 @@ my @events = ( "krb5_del_policy", "krb5_set_password", ); -@EXPORT = @events; - -use strict; -use warnings; -use GOSA::GosaSupportDaemon; -use Authen::Krb5; -use Authen::Krb5::Admin qw(:constants); + +our @EXPORT = @events; BEGIN {} @@ -41,6 +47,7 @@ my %cfg_defaults = ( "password" => [\$krb_password, ""], }, ); +# why not using the main::read_configfile, the code seems exactly the same &krb5_read_configfile($main::cfg_file, %cfg_defaults); diff --git a/gosa-si/client/events/load_reporter.pm b/gosa-si/client/events/load_reporter.pm index d68f28107..be9b6a29f 100644 --- a/gosa-si/client/events/load_reporter.pm +++ b/gosa-si/client/events/load_reporter.pm @@ -1,31 +1,39 @@ package load_reporter; -use Exporter; -@ISA = qw(Exporter); -my @events = ( - "get_events", - "get_terminal_server", - "get_load", - "report_load", - "set_terminal_server", - ); -@EXPORT = @events; + use strict; use warnings; -use GOSA::GosaSupportDaemon; + +use GOsaSI::GosaSupportDaemon; + +use Exporter; BEGIN {} END {} +our @ISA = qw(Exporter); + +my @events = ( + "get_events", + "get_terminal_server", + "get_load", + "report_load", + "set_terminal_server", + ); + +our @EXPORT = @events; + my $ts_load_file; my $waiting_for_ts_info; my %cfg_defaults = ( - "client" => { - "ts-load-file" => [\$ts_load_file, "/var/run/gosa-si-client-ts-load.txt"], - "waiting-for-ts-info" => [\$waiting_for_ts_info, 5], - }, + "client" => { + "ts-load-file" => [\$ts_load_file, "/var/run/gosa-si/gosa-si-client-ts-load.txt"], + "waiting-for-ts-info" => [\$waiting_for_ts_info, 5], + }, ); -&GOSA::GosaSupportDaemon::read_configfile($main::cfg_file, %cfg_defaults); + +# to be removed ugly !! why not using main::_read_configfile +&GOsaSI::GosaSupportDaemon::read_configfile($main::cfg_file, %cfg_defaults); ### FUNCTIONS ################################################################# @@ -55,9 +63,9 @@ sub get_load my $file = "/proc/loadavg"; if ((not -f $file) || (not -r $file)) { return } - open(FHD, "<$file"); - my $line = ; - close(FHD); + open(my $FHD, "<", "$file"); + my $line = <$FHD>; + close($FHD); chomp($line); $out_msg = &create_xml_string(&create_xml_hash("report_load", $target, $source, $line)); @@ -83,9 +91,9 @@ sub set_terminal_server { $file_content .= "$ts $load\n"; } - open(FHD, ">$ts_load_file.part"); - printf FHD $file_content; - close FHD; + open(my $FHD, ">", "$ts_load_file.part"); + printf $FHD $file_content; + close($FHD); system("mv $ts_load_file.part $ts_load_file"); &main::daemon_log("INFO: Wrote terminal server load information to $ts_load_file", 5); diff --git a/gosa-si/client/events/mailqueue.pm b/gosa-si/client/events/mailqueue.pm index 7e3699cb8..43552af74 100644 --- a/gosa-si/client/events/mailqueue.pm +++ b/gosa-si/client/events/mailqueue.pm @@ -25,8 +25,18 @@ Andreas Rettenberger package mailqueue; + + +use strict; +use warnings; + +use MIME::Base64; +use GOsaSI::GosaSupportDaemon; + use Exporter; -@ISA = qw(Exporter); + +our @ISA = qw(Exporter); + my @events = ( "get_events", "mailqueue_query", @@ -36,12 +46,8 @@ my @events = ( "mailqueue_del", "mailqueue_header", ); -@EXPORT = @events; -use strict; -use warnings; -use GOSA::GosaSupportDaemon; -use MIME::Base64; +our @EXPORT = @events; BEGIN {} @@ -120,16 +126,16 @@ sub mailqueue_query { my $error = 0; my $error_string; my $msg_id; - my $msg_hold; - my $msg_size; - my $arrival_time; +#my $msg_hold; +#my $msg_size; +#my $arrival_time; my $sender; my $recipient; - my $status_message; +#my $status_message; my $out_hash; my $out_msg; - &main::daemon_log("DEBUG: run /usr/bin/mailq\n", 7); + &main::daemon_log("DEBUG: run /usr/bin/mailq\n", 7); my $result = qx("/usr/bin/mailq"); my @result_l = split(/([0-9A-Z]{10,12})/, $result); @@ -230,9 +236,13 @@ sub mailqueue_query { &main::daemon_log("$session_id WARNING: $error_string", 3); } - # If query was successful, add resutls to answer + # If query was successful, add results to answer if ($query_positiv) { - $j++; + $j++; + foreach my $key (keys %{ $act_result }) { + $act_result->{$key} =~ s/\{$key} =~ s/\>/\>\;/g; + } $result_collection->{$j} = $act_result; } } diff --git a/gosa-si/debian/README.source b/gosa-si/debian/README.source new file mode 100644 index 000000000..1c919f041 --- /dev/null +++ b/gosa-si/debian/README.source @@ -0,0 +1 @@ +/usr/share/doc/dpatch/README.source.gz diff --git a/gosa-si/debian/changelog b/gosa-si/debian/changelog index fbe9f1d74..c12b49b6a 100644 --- a/gosa-si/debian/changelog +++ b/gosa-si/debian/changelog @@ -1,5 +1,5 @@ -gosa-si (2.6.7-1) unstable; urgency=low +gosa-si (2.6.10-1) unstable; urgency=low * Initial upload (Closes: #534303) - -- Cajus Pollmeier Tue, 23 Jun 2009 16:10:48 +0200 + -- Benoit Mortier Sat, 22 May 2010 18:30:00 +0100 diff --git a/gosa-si/debian/control b/gosa-si/debian/control index 9fc4f5427..aeff6bacf 100644 --- a/gosa-si/debian/control +++ b/gosa-si/debian/control @@ -3,15 +3,15 @@ Section: utils Priority: optional Maintainer: GOsa packages mainteners group Uploaders: Cajus Pollmeier , Benoit Mortier -Standards-Version: 3.8.0 -Build-Depends: debhelper(>= 4.2.32), dpatch +Standards-Version: 3.8.4 +Build-Depends: debhelper(>= 5), dpatch Homepage: https://oss.gonicus.de/labs/gosa/ Vcs-Browser: https://oss.gonicus.de/repositories/gosa/trunk/gosa-si Vcs-Svn: https://oss.gonicus.de/repositories/gosa/trunk/gosa-si Package: gosa-si-common Architecture: any -Depends: libconfig-inifiles-perl, libcrypt-rijndael-perl, libio-socket-ssl-perl, libxml-simple-perl, libdata-dumper-simple-perl, libmime-perl | libmime-tools-perl, libdbd-sqlite3-perl, libnet-ldap-perl, libnetaddr-ip-perl, libpoe-perl, libnet-dns-perl, libnet-pcap-perl, libconvert-asn1-perl, libdigest-hmac-perl, libnet-ip-perl, libdigest-sha1-perl, libnet-mac-vendor-perl, libpoe-component-pcap-perl, libnet-arp-perl, libdatetime-perl, libjson-rpc-perl, libxml-quote-perl, libcrypt-ssleay-perl +Depends: ${misc:Depends}, libconfig-inifiles-perl, libcrypt-rijndael-perl, libio-socket-ssl-perl, libxml-simple-perl, libdata-dumper-simple-perl, libmime-tools-perl, libdbd-sqlite3-perl, libnet-ldap-perl, libnetaddr-ip-perl, libpoe-perl, libnet-dns-perl, libnet-pcap-perl, libconvert-asn1-perl, libdigest-hmac-perl, libnet-ip-perl, libdigest-sha1-perl, libnet-mac-vendor-perl, libpoe-component-pcap-perl, libnet-arp-perl, libdatetime-perl, libjson-rpc-perl, libxml-quote-perl, libcrypt-ssleay-perl, libnet-arp-perl, libfile-pid-perl Suggests: gosa-si-server, gosa-si-client Description: GOsa support infrastructure GOsa is a combination of system-administrator and end-user web @@ -22,7 +22,7 @@ Description: GOsa support infrastructure Package: gosa-si-server Architecture: any -Depends: gosa-si-common, libcrypt-smbhash-perl +Depends: ${misc:Depends}, gosa-si-common, libcrypt-smbhash-perl, wget Suggests: gosa, gosa-si-server-postfix, gosa-si-server-dak Description: GOsa support infrastructure server GOsa is a combination of system-administrator and end-user web @@ -34,7 +34,7 @@ Description: GOsa support infrastructure server Package: gosa-si-client Architecture: any -Depends: gosa-si-common, hwinfo, libdatetime-perl +Depends: ${misc:Depends}, gosa-si-common, hwinfo, libdatetime-perl Suggests: goto-fai-progress, gosa-si-client-krb5 Description: GOsa support infrastructure client GOsa is a combination of system-administrator and end-user web @@ -45,7 +45,7 @@ Description: GOsa support infrastructure client Package: gosa-si-server-postfix Architecture: any -Depends: gosa-si-server, postfix +Depends: ${misc:Depends}, gosa-si-server, postfix Description: GOsa support infrastructure postfix module GOsa is a combination of system-administrator and end-user web interface, designed to handle LDAP based setups. @@ -54,7 +54,7 @@ Description: GOsa support infrastructure postfix module Package: gosa-si-client-krb5 Architecture: any -Depends: gosa-si-client, libauthen-krb5-perl, libauthen-krb5-admin-perl +Depends: ${misc:Depends}, gosa-si-client, libauthen-krb5-perl, libauthen-krb5-admin-perl Description: GOsa support infrastructure kerberos module GOsa is a combination of system-administrator and end-user web interface, designed to handle LDAP based setups. @@ -64,7 +64,7 @@ Description: GOsa support infrastructure kerberos module Package: gosa-si-server-dak Architecture: any -Depends: gosa-si-server, dak +Depends: ${misc:Depends}, gosa-si-server, dak Description: GOsa support infrastructure dak module GOsa is a combination of system-administrator and end-user web interface, designed to handle LDAP based setups. @@ -74,7 +74,7 @@ Description: GOsa support infrastructure dak module Package: gosa-si-server-opsi Architecture: any -Depends: gosa-si-server +Depends: ${misc:Depends}, gosa-si-server Description: GOsa support infrastructure opsi module GOsa is a combination of system-administrator and end-user web interface, designed to handle LDAP based setups. @@ -83,7 +83,7 @@ Description: GOsa support infrastructure opsi module Package: gosa-si-client-loadreporter Architecture: any -Depends: gosa-si-client +Depends: ${misc:Depends}, gosa-si-client Description: GOsa support infrastructure system load reporter module GOsa is a combination of system-administrator and end-user web interface, designed to handle LDAP based setups. diff --git a/gosa-si/debian/copyright b/gosa-si/debian/copyright index 99dd31702..d7541c4f1 100644 --- a/gosa-si/debian/copyright +++ b/gosa-si/debian/copyright @@ -5,7 +5,10 @@ It was downloaded from http://www.gosa-project.org Copyright: - Copyright (C) 2001-2009 Cajus Pollmeier + (c) 2007-2009 by Andreas Rettenberger + (c) 2008-2010 by Cajus Pollmeier + (c) 2008-2009 by Jan Wenzel + (c) 2010 by Benoit Mortier License: @@ -24,8 +27,8 @@ License: Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA On Debian systems, the complete text of the GNU General -Public License can be found in `/usr/share/common-licenses/GPL'. +Public License can be found in `/usr/share/common-licenses/GPL-2'. -The Debian packaging is (C) 2008, Cajus Pollmeier and +The Debian packaging is (C) Copyright 2001-2010, Cajus Pollmeier and is licensed under the GPL, see above. diff --git a/gosa-si/debian/gosa-si-client.default b/gosa-si/debian/gosa-si-client.default new file mode 100644 index 000000000..b16721850 --- /dev/null +++ b/gosa-si/debian/gosa-si-client.default @@ -0,0 +1,4 @@ +# Should we start the client +START_CLIENT=1 +# Level of debugging for the client +DEBUG=-vvvvvvv diff --git a/gosa-si/debian/gosa-si-client.init b/gosa-si/debian/gosa-si-client.init new file mode 100644 index 000000000..f20f4d43d --- /dev/null +++ b/gosa-si/debian/gosa-si-client.init @@ -0,0 +1,84 @@ +#!/bin/sh +# Start/stop the GOsa support daemon infrastructure. +# +### BEGIN INIT INFO +# Provides: gosa-si-client +# Required-Start: $network $remote_fs $named $syslog $time +# Required-Stop: $network $remote_fs $named $syslog $time +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: GOsa message server/client component +# Description: gosa-si establishes the communication between a couple of +# GOsa hosting servers and optionally clients to do event +# signaling for all communication partners. +### END INIT INFO + +# variables for the gosa-si client. +CLIENT="gosa-si-client" +DAEMON_CLIENT="/usr/sbin/${CLIENT}" +RUN_DIRECTORY="/var/run/gosa-si" +PIDFILE_CLIENT="$RUN_DIRECTORY/${CLIENT}.pid" + +PATH="/sbin:/usr/sbin:/bin:/usr/bin" + +# Load defaults +[ -r /etc/default/gosa-si-client ] && . /etc/default/gosa-si-client + +# Load LSB support functions +. /lib/lsb/init-functions + +if [ ! -d "/var/run/gosa-si" ]; then + mkdir $RUN_DIRECTORY +fi + +start_client() { + start-stop-daemon --start --quiet --pidfile ${PIDFILE_CLIENT} --name ${CLIENT} --startas ${DAEMON_CLIENT} -- $DEBUG +} + +stop_client() { + start-stop-daemon --stop --retry 5 --quiet --pidfile ${PIDFILE_CLIENT} --name ${CLIENT} +} + +case "$1" in +start) log_daemon_msg "Starting GOsa support infrastructure client" + if [ "$START_CLIENT" = "1" -a -x ${DAEMON_CLIENT} ]; then + log_progress_msg "client" + start_client + fi + log_end_msg $? + ;; +stop) log_daemon_msg "Stopping GOsa support infrastructure Client" + if [ "$START_CLIENT" = "1" -a -x ${DAEMON_CLIENT} ]; then + log_progress_msg "client" + stop_client + fi + log_end_msg $? + ;; +reload|force-reload|restart) log_daemon_msg "Restarting GOsa support infrastructure client" + if [ "$START_CLIENT" = "1" -a -x ${DAEMON_CLIENT} ]; then + stop_client + start_client + fi + log_progress_msg "done" + log_end_msg $? + ;; +status) + if [ "$START_CLIENT" = "1" -a -x ${DAEMON_CLIENT} ]; then + status=0 + pidofproc -p "${PIDFILE_CLIENT}" "${DAEMON_CLIENT}" >/dev/null || status="$?" + log_daemon_msg "Status of GOsa-si client" "${NAME}" + if [ "$status" = 0 ]; then + log_progress_msg "is running" + log_end_msg 0 + else + log_progress_msg "is not running" + log_end_msg $status + fi + fi + ;; + +*) log_action_msg "Usage: /etc/init.d/gosa-si-client {start|stop|restart|reload|force-reload|status}" + exit 2 + ;; +esac +exit 0 diff --git a/gosa-si/debian/gosa-si-client.lintian-overrides b/gosa-si/debian/gosa-si-client.lintian-overrides deleted file mode 100644 index 7932c14d3..000000000 --- a/gosa-si/debian/gosa-si-client.lintian-overrides +++ /dev/null @@ -1 +0,0 @@ -gosa-si-client: binary-without-manpage usr/sbin/gosa-si-client diff --git a/gosa-si/debian/gosa-si-client.logrotate b/gosa-si/debian/gosa-si-client.logrotate index 7e9fd81e3..2a5a417ca 100644 --- a/gosa-si/debian/gosa-si-client.logrotate +++ b/gosa-si/debian/gosa-si-client.logrotate @@ -4,7 +4,6 @@ compress missingok postrotate - pkill -SIGUSR1 gosa-si-client > /dev/null || true endscript } diff --git a/gosa-si/debian/gosa-si-client.postinst b/gosa-si/debian/gosa-si-client.postinst index cafe8c1cb..917f50c18 100644 --- a/gosa-si/debian/gosa-si-client.postinst +++ b/gosa-si/debian/gosa-si-client.postinst @@ -11,13 +11,13 @@ case "$1" in *) exit 0; esac -[ ! -d /usr/lib/gosa-si/client/events ] && install -d -o root -g root -m 750 /usr/lib/gosa-si/client/events +#[ ! -d /usr/lib/gosa-si/client/events ] && install -d -o root -g root -m 750 /usr/lib/gosa-si/client/events # Fix permission -[ -f /etc/gosa-si/client.conf ] && chmod go-rwx /etc/gosa-si/client.conf +#[ -f /etc/gosa-si/client.conf ] && chmod go-rwx /etc/gosa-si/client.conf # Restart daemon -invoke-rc.d gosa-si restart +#invoke-rc.d gosa-si-client start exit 0 diff --git a/gosa-si/debian/gosa-si-common.default b/gosa-si/debian/gosa-si-common.default deleted file mode 100644 index fede17e5f..000000000 --- a/gosa-si/debian/gosa-si-common.default +++ /dev/null @@ -1,3 +0,0 @@ -# /etc/default/gosa-si - configure the init script -START_CLIENT=1 -DEBUG=-vvv diff --git a/gosa-si/debian/gosa-si-common.dirs b/gosa-si/debian/gosa-si-common.dirs index 2d13e8f10..b154e52a8 100644 --- a/gosa-si/debian/gosa-si-common.dirs +++ b/gosa-si/debian/gosa-si-common.dirs @@ -1,2 +1,2 @@ -/etc/default -/usr/share/perl5/GOSA +/usr/share/perl5/GOsaSI +/var/log/gosa-si diff --git a/gosa-si/debian/gosa-si-common.init b/gosa-si/debian/gosa-si-common.init deleted file mode 100755 index 68c59fc65..000000000 --- a/gosa-si/debian/gosa-si-common.init +++ /dev/null @@ -1,134 +0,0 @@ -#!/bin/sh -# Start/stop the GOsa support daemon infrastructure. -# -### BEGIN INIT INFO -# Provides: gosa-si -# Required-Start: $network $named $syslog $time -# Required-Stop: $network $named $syslog $time -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: GOsa message server/client component -# Description: gosa-si establishes the communication between a couple of -# GOsa hosting servers and optionally clients to do event -# signaling for all communication partners. -### END INIT INFO - -# Start/stop the ctftpd daemon. -SERVER="gosa-si-server" -CLIENT="gosa-si-client" -DAEMON_SERVER="/usr/sbin/${SERVER}" -DAEMON_CLIENT="/usr/sbin/${CLIENT}" -PIDFILE_SERVER="/var/run/${SERVER}.pid" -PIDFILE_CLIENT="/var/run/${CLIENT}.pid" - -PATH="/sbin:/usr/sbin:/bin:/usr/bin" - -# Load defaults -[ -r /etc/default/gosa-si ] && . /etc/default/gosa-si - -# Load LSB support functions -. /lib/lsb/init-functions - - -start_client() { - start-stop-daemon --start --quiet --pidfile ${PIDFILE_CLIENT} --name ${CLIENT} --startas ${DAEMON_CLIENT} -- $DEBUG -} - - -start_server() { - start-stop-daemon --start --quiet --pidfile ${PIDFILE_SERVER} --name ${SERVER} --startas ${DAEMON_SERVER} -- $1 $DEBUG -} - - -stop_client() { - start-stop-daemon --stop --retry 5 --quiet --pidfile ${PIDFILE_CLIENT} --name ${CLIENT} - kill `ps -C gosa-si-client -o pid=` > /dev/null 2>&1 - ! ps -C gosa-si-client -o pid= > /dev/null 2>&1 -} - - -stop_server() { - start-stop-daemon --stop --retry 5 --quiet --pidfile ${PIDFILE_SERVER} --name ${SERVER} - kill `ps -C gosa-si-server -o pid=` > /dev/null 2>&1 - ! ps -C gosa-si-server -o pid= > /dev/null 2>&1 -} - - -case "$1" in -start) log_daemon_msg "Starting GOsa support infrastructure" - if [ -x ${DAEMON_SERVER} ]; then - log_progress_msg "daemon" - start_server - fi - if [ "$START_CLIENT" = "1" -a -x ${DAEMON_CLIENT} ]; then - log_progress_msg "client" - start_client - fi - log_end_msg $? - ;; -stop) log_daemon_msg "Stopping GOsa support infrastructure" - if [ "$START_CLIENT" = "1" -a -x ${DAEMON_CLIENT} ]; then - log_progress_msg "client" - stop_client - fi - if [ -x ${DAEMON_SERVER} ]; then - log_progress_msg "daemon" - stop_server - fi - log_end_msg $? - ;; -reload|force-reload|restart) log_daemon_msg "Restarting GOsa support infrastructure" - if [ "$START_CLIENT" = "1" -a -x ${DAEMON_CLIENT} ]; then - stop_client - fi - if [ -x ${DAEMON_SERVER} ]; then - stop_server - start_server - fi - if [ "$START_CLIENT" = "1" -a -x ${DAEMON_CLIENT} ]; then - start_client - fi - log_progress_msg "done" - log_end_msg $? - ;; -restart-client) log_daemon_msg "Restarting GOsa support infrastructure client" - if [ "$START_CLIENT" = "1" -a -x ${DAEMON_CLIENT} ]; then - stop_client - fi - if [ "$START_CLIENT" = "1" -a -x ${DAEMON_CLIENT} ]; then - start_client - fi - log_progress_msg "done" - log_end_msg $? - ;; -status) - status=0 - pidofproc -p "${PIDFILE_SERVER}" "${DAEMON_SERVER}" >/dev/null || status="$?" - log_daemon_msg "Status of GOsa-si server" "${NAME}" - if [ "$status" = 0 ]; then - log_progress_msg "is running" - log_end_msg 0 - else - log_progress_msg "is not running" - log_end_msg $status - fi - - if [ "$START_CLIENT" = "1" -a -x ${DAEMON_CLIENT} ]; then - status=0 - pidofproc -p "${PIDFILE_CLIENT}" "${DAEMON_CLIENT}" >/dev/null || status="$?" - log_daemon_msg "Status of GOsa-si client" "${NAME}" - if [ "$status" = 0 ]; then - log_progress_msg "is running" - log_end_msg 0 - else - log_progress_msg "is not running" - log_end_msg $status - fi - fi - ;; - -*) log_action_msg "Usage: /etc/init.d/gosa-si {start|stop|restart|restart-client|reload|force-reload|status}" - exit 2 - ;; -esac -exit 0 diff --git a/gosa-si/debian/gosa-si-common.install b/gosa-si/debian/gosa-si-common.install index 4fede15d3..49815e703 100644 --- a/gosa-si/debian/gosa-si-common.install +++ b/gosa-si/debian/gosa-si-common.install @@ -1,3 +1,3 @@ -modules/GosaSupportDaemon.pm usr/share/perl5/GOSA -modules/DBsqlite.pm usr/share/perl5/GOSA -modules/ArpWatch.pm usr/share/perl5/POE/Component +modules/GosaSupportDaemon.pm usr/share/perl5/GOsaSI +modules/DBsqlite.pm usr/share/perl5/GOsaSI +modules/ArpWatch.pm usr/share/perl5/POE/Component diff --git a/gosa-si/debian/gosa-si-common.postinst b/gosa-si/debian/gosa-si-common.postinst index ef7bfbbd0..cc4606610 100644 --- a/gosa-si/debian/gosa-si-common.postinst +++ b/gosa-si/debian/gosa-si-common.postinst @@ -11,5 +11,10 @@ case "$1" in *) exit 0; esac -[ -d /var/lib/gosa-si ] || install -d -o root -g root -m 750 /var/lib/gosa-si +# create missing /var/lib/gosa-si +[ ! -d /var/lib/gosa-si/ ] && mkdir /var/lib/gosa-si +# start daemon +#invoke-rc.d gosa-si-server start + +exit 0 diff --git a/gosa-si/debian/gosa-si-server-opsi.install b/gosa-si/debian/gosa-si-server-opsi.install index ffe16d06d..d6137aeac 100644 --- a/gosa-si/debian/gosa-si-server-opsi.install +++ b/gosa-si/debian/gosa-si-server-opsi.install @@ -1,3 +1,4 @@ -server/events/opsi_com.pm usr/lib/gosa-si/server/GosaPackages -server/events/opsi_com.pm usr/lib/gosa-si/server/ServerPackages - +server/events/opsi_com.pm usr/lib/gosa-si/server/GosaPackages +server/events/opsi_com.pm usr/lib/gosa-si/server/ServerPackages +contrib/90_gosa.conf usr/share/doc/gosa-si-server-opsi +contrib/README usr/share/doc/gosa-si-server-opsi diff --git a/gosa-si/debian/gosa-si-server.default b/gosa-si/debian/gosa-si-server.default new file mode 100644 index 000000000..9c37a35c8 --- /dev/null +++ b/gosa-si/debian/gosa-si-server.default @@ -0,0 +1,6 @@ +# Should we start the server +START_SERVER=0 +# Configure Debuging Level +DEBUG=-vvvvvvv +# Debug parts of GOsa-si server see man gosa-si-server +#DEBUGPARTS= diff --git a/gosa-si/debian/gosa-si-server.init b/gosa-si/debian/gosa-si-server.init new file mode 100644 index 000000000..1656e1388 --- /dev/null +++ b/gosa-si/debian/gosa-si-server.init @@ -0,0 +1,85 @@ +#!/bin/sh +# Start/stop the GOsa support daemon infrastructure. +# +### BEGIN INIT INFO +# Provides: gosa-si-server +# Required-Start: $network $remote_fs $named $syslog $time +# Required-Stop: $network $remote_fs $named $syslog $time +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: GOsa message server component +# Description: gosa-si-server establishes the communication between a couple of +# GOsa hosting servers and optionally clients to do event +# signaling for all communication partners. +### END INIT INFO + +# variables for the gosa-si-server. +SERVER="gosa-si-server" +DAEMON_SERVER="/usr/sbin/${SERVER}" +RUN_DIRECTORY="/var/run/gosa-si" +PIDFILE_SERVER="$RUN_DIRECTORY/${SERVER}.pid" + +PATH="/sbin:/usr/sbin:/bin:/usr/bin" + +# Load defaults +[ -r /etc/default/gosa-si-server ] && . /etc/default/gosa-si-server + +# Load LSB support functions +. /lib/lsb/init-functions + +if [ ! -d "/var/run/gosa-si" ]; then + mkdir $RUN_DIRECTORY +fi + +start_server() { + start-stop-daemon --start --quiet --pidfile ${PIDFILE_SERVER} --name ${SERVER} --startas ${DAEMON_SERVER} -- $1 $DEBUG +} + +stop_server() { + start-stop-daemon --stop --retry 5 --quiet --pidfile ${PIDFILE_SERVER} --name ${SERVER} +} + + +case "$1" in + start) log_daemon_msg "Starting GOsa support infrastructure Server" + if [ "$START_SERVER" = "1" -a -x ${DAEMON_SERVER} ]; then + log_progress_msg "server" + start_server + fi + log_end_msg $? + ;; +stop) log_daemon_msg "Stopping GOsa support infrastructure Server" + if [ "$START_SERVER" = "1" -a -x ${DAEMON_SERVER} ]; then + log_progress_msg "server" + stop_server + fi + log_end_msg $? +;; +reload|force-reload|restart) log_daemon_msg "Restarting GOsa support infrastructure Server" + if [ "$START_SERVER" = "1" -a -x ${DAEMON_SERVER} ]; then + stop_server + start_server + fi + log_progress_msg "done" + log_end_msg $? +;; +status) + if [ "$START_SERVER" = "1" -a -x ${DAEMON_SERVER} ]; then + status=0 + pidofproc -p "${PIDFILE_SERVER}" "${DAEMON_SERVER}" >/dev/null || status="$?" + log_daemon_msg "Status of GOsa-si server" "${NAME}" + if [ "$status" = 0 ]; then + log_progress_msg "is running" + log_end_msg 0 + else + log_progress_msg "is not running" + log_end_msg $status + fi + fi +;; + +*) log_action_msg "Usage: /etc/init.d/gosa-si {start|stop|restart|reload|force-reload|status}" + exit 2 + ;; +esac +exit 0 diff --git a/gosa-si/debian/gosa-si-server.install b/gosa-si/debian/gosa-si-server.install index 99882e7ad..ce2ed768b 100644 --- a/gosa-si/debian/gosa-si-server.install +++ b/gosa-si/debian/gosa-si-server.install @@ -1,16 +1,16 @@ -gosa-si-server usr/sbin -server.conf etc/gosa-si -modules/ClientPackages.pm usr/lib/gosa-si/modules -modules/GosaPackages.pm usr/lib/gosa-si/modules -modules/ArpHandler.pm usr/lib/gosa-si/modules -modules/oui.txt usr/lib/gosa-si/modules -modules/ServerPackages.pm usr/lib/gosa-si/modules -server/events/gosaTriggered.pm usr/lib/gosa-si/server/GosaPackages -server/events/siTriggered.pm usr/lib/gosa-si/server/ClientPackages -server/events/clMessages.pm usr/lib/gosa-si/server/ClientPackages -server/events/databases.pm usr/lib/gosa-si/server/GosaPackages -server/events/databases.pm usr/lib/gosa-si/server/ServerPackages -server/events/logHandling.pm usr/lib/gosa-si/server/GosaPackages -server/events/logHandling.pm usr/lib/gosa-si/server/ServerPackages +gosa-si-server usr/sbin +server.conf etc/gosa-si +modules/ClientPackages.pm usr/lib/gosa-si/modules +modules/GosaPackages.pm usr/lib/gosa-si/modules +modules/ArpHandler.pm usr/lib/gosa-si/modules +modules/oui.txt usr/lib/gosa-si/modules +modules/ServerPackages.pm usr/lib/gosa-si/modules +server/events/gosaTriggered.pm usr/lib/gosa-si/server/GosaPackages +server/events/siTriggered.pm usr/lib/gosa-si/server/ClientPackages +server/events/clMessages.pm usr/lib/gosa-si/server/ClientPackages +server/events/databases.pm usr/lib/gosa-si/server/GosaPackages +server/events/databases.pm usr/lib/gosa-si/server/ServerPackages +server/events/logHandling.pm usr/lib/gosa-si/server/GosaPackages +server/events/logHandling.pm usr/lib/gosa-si/server/ServerPackages server/events/server_server_com.pm usr/lib/gosa-si/server/ServerPackages diff --git a/gosa-si/debian/gosa-si-server.lintian-overrides b/gosa-si/debian/gosa-si-server.lintian-overrides deleted file mode 100644 index 123bbc7cf..000000000 --- a/gosa-si/debian/gosa-si-server.lintian-overrides +++ /dev/null @@ -1,2 +0,0 @@ -gosa-si-server: binary-without-manpage usr/sbin/gosa-si-server - diff --git a/gosa-si/debian/gosa-si-server.logrotate b/gosa-si/debian/gosa-si-server.logrotate index c10f95e34..38441437e 100644 --- a/gosa-si/debian/gosa-si-server.logrotate +++ b/gosa-si/debian/gosa-si-server.logrotate @@ -4,7 +4,6 @@ compress missingok postrotate - pkill -SIGUSR1 gosa-si-server > /dev/null || true endscript } diff --git a/gosa-si/debian/gosa-si-server.postinst b/gosa-si/debian/gosa-si-server.postinst index c990f4ba4..147bd4064 100644 --- a/gosa-si/debian/gosa-si-server.postinst +++ b/gosa-si/debian/gosa-si-server.postinst @@ -12,9 +12,9 @@ case "$1" in esac # Fix permission -[ -f /etc/gosa-si/server.conf ] && chmod go-rwx /etc/gosa-si/server.conf +#[ -f /etc/gosa-si/server.conf ] && chmod go-rwx /etc/gosa-si/server.conf -# Restart daemon -invoke-rc.d gosa-si restart +# start daemon +#invoke-rc.d gosa-si-server start exit 0 diff --git a/gosa-si/debian/rules b/gosa-si/debian/rules index 933e5482a..c6880978f 100755 --- a/gosa-si/debian/rules +++ b/gosa-si/debian/rules @@ -35,13 +35,6 @@ install-stamp: -for i in *; do \ cp -R $$i debian/tmp ; \ done - -find debian/tmp -name '*.svn' -type d -exec rm -rf {} \; 2> /dev/null - - -for i in gosa-si-client gosa-si-server modules/GosaPackages.pm modules/ClientPackages.pm modules/ServerPackages.pm server/events/*; do sed -i 's/use GosaSupportDaemon;/use GOSA::GosaSupportDaemon;/g;s/use DBsqlite;/use GOSA::DBsqlite;/g' debian/tmp/$$i; done - - -sed -i 's!"/etc/gosa-si/modules";!use lib "/usr/lib/gosa-si/modules";!g' debian/tmp/gosa-si-server - - -sed -i 's!"/etc/gosa-si/server/events";!"/usr/lib/gosa-si/server/events";!g' debian/tmp/modules/GosaPackages.pm touch install-stamp @@ -56,18 +49,13 @@ binary-indep: install dh_install --sourcedir=debian/tmp - install -D -m 644 debian/gosa-si-server.lintian-overrides debian/gosa-si-server/usr/share/lintian/overrides/gosa-si-server - install -D -m 644 debian/gosa-si-client.lintian-overrides debian/gosa-si-client/usr/share/lintian/overrides/gosa-si-client - dh_installdocs dh_installcron dh_installexamples dh_installchangelogs dh_installman dh_installlogrotate - #dh_installdebconf - dh_installinit --init-script=gosa-si -- start 00 2 3 4 5 . stop 29 1 . - + dh_installinit chmod 640 debian/gosa-si-server/etc/gosa-si/server.conf debian/gosa-si-client/etc/gosa-si/client.conf dh_link diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client index 992dda4c3..56200d996 100755 --- a/gosa-si/gosa-si-client +++ b/gosa-si/gosa-si-client @@ -1,54 +1,105 @@ #!/usr/bin/perl -#=============================================================================== -# -# FILE: gosa-si-client +#********************************************************************* # -# USAGE: gosa-si-client +# gosa-si-client -- client for the gosa-si-server # -# DESCRIPTION: +# (c) 2007-2009 by Andreas Rettenberger +# (c) 2008-2010 by Cajus Pollmeier +# (c) 2008-2009 by Jan Wenzel +# (c) 2010 by Benoit Mortier # -# OPTIONS: --- -# REQUIREMENTS: libnetaddr-ip-perl -# BUGS: --- -# NOTES: -# AUTHOR: (Andreas Rettenberger), -# COMPANY: -# VERSION: 1.0 -# CREATED: 12.09.2007 08:54:41 CEST -# REVISION: --- -#=============================================================================== +#********************************************************************* -my $client_version = '$HeadURL$:$Rev$'; +=head1 NAME + +gosa-si-client - Client for GOsa support infrastructure + +=head1 SYNOPSIS + +gosa-si-client [-hvf] [-c config] + +=head1 OPTIONS + +B<-h>, B<--help> + print out this help message + +B<-v>, B<--verbose> + be verbose (multiple v's will increase verbosity) + -v ERROR level + -vvv WARNING + ERROR level + -vvvvv INFO + WARNING level + -vvvvvvv DEBUG + INFO level + -vvvvvvvvv in and out going xml messages will be displayed + +B<-f>, B<--foreground> + foregroud, process will not be forked to background + +B<-c> I, B<--config=>I + configuration file, default F + +B<-x> + dump configuration to stdout + ( 1 = current, 2 = default ) + +=head1 DESCRIPTION + +B belongs to the support infrastructure of GOsa. +The client registrates at a GOsa-SI-server and accepts messages from it. +Each message is related to a working instruction which will be executed on the client. +Depending on the message an answer can be send back to the server. + +=head1 BUGS + +Please report any bugs, or post any suggestions, to the GOsa mailing list or to + + +=head1 LICENCE AND COPYRIGHT + +This code is part of GOsa (L) + +Copyright (C) 2003-2010 GONICUS GmbH + +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. + +=cut use strict; use warnings; + use Getopt::Long; use Config::IniFiles; -use POSIX; use Time::HiRes qw( gettimeofday ); - -use POE qw(Component::Server::TCP Wheel::FollowTail Wheel::Run); use IO::Socket::INET; use NetAddr::IP; use Crypt::Rijndael; -use GOSA::GosaSupportDaemon; use Digest::MD5 qw(md5_hex md5 md5_base64); use MIME::Base64; use XML::Simple; use File::Basename; use File::Spec; +use File::Pid; +use Net::ARP; +use GOsaSI::GosaSupportDaemon; + +use POE qw(Component::Server::TCP Wheel::FollowTail Wheel::Run); use Fcntl; +use POSIX; # Workaround: need pure perl to make it work with UTF-8 :-( $XML::Simple::PREFERRED_PARSER= "XML::SAX::PurePerl"; +my $client_version = '$HeadURL$:$Rev$'; + my $client_headURL; my $client_revision; my $client_status; my $event_dir = "/usr/lib/gosa-si/client/events"; use lib "/usr/lib/gosa-si/client/events"; -my (%cfg_defaults, $foreground, $verbose, $pid_file, $procid, $pid, $log_file, $fai_logpath); +my (%cfg_defaults, $foreground, $pid_file, $procid, $pid, $log_file, $fai_logpath); my ($server_ip, $server_port, $server_timeout, $server_domain, $server_key_lifetime); my ($client_port, $ldap_enabled, $ldap_config, $pam_config, $nss_config); my ($root_uid, $adm_gid); @@ -58,7 +109,9 @@ my $default_server_key; my @servers; my $gotoHardwareChecksum; my $system_com; -$verbose= 1; +my $servers_string; + +my $client_status_hash = { 'developmental'=>'revision', 'stable'=>'release'}; # globalise variables which are used in imported events our $global_kernel; @@ -72,19 +125,26 @@ our $client_dnsname; our $client_force_hostname; our $server_key; our $terminal_server_hash; +our $opts_dnslookup; +our $verbose= 0; + +# where is the config stored by default and his name +our $config = '/etc/gosa-si/client.conf'; + +# by default dumping of config is undefined +our $dump_config = undef; # default variables my $REGISTERED = 0; # path to fifo for non-gosa-si-client messages to gosa-si-server -my $fai_com_fifo = "/var/run/gosa-si-client.socket"; -my $system_com_fifo = "/var/run/gosa-si-client-system-com.socket"; +my $fai_com_fifo = "/var/run/gosa-si/gosa-si-client.socket"; +my $system_com_fifo = "/var/run/gosa-si/gosa-si-client-system-com.socket"; my %files_to_watch = (fai_fifo => $fai_com_fifo, system_fifo => $system_com_fifo); -# in function register_at_gosa_si_server, after which period of seconds a new registration should be tried if a registration was -# not successful until now +# in function register_at_gosa_si_server, after which period of seconds a new registration should be tried if a registration was not successful until now my $delay_set_time = 10; -our $prg= basename($0); +#our $prg= basename($0); # all n seconds the client reports logged_in users to gosa-si-server my $trigger_logged_in_users_report_delay = 600; @@ -96,12 +156,12 @@ my $trigger_seen_messages_delay = 30; my $fai_log_dir = "/var/log/fai"; %cfg_defaults = ( -"general" => - {"log-file" => [\$log_file, "/var/run/".$prg.".log"], - "pid-file" => [\$pid_file, "/var/run/".$prg.".pid"], - "opts-file" => [\$opts_file, "/var/run/".$prg.".opts"], +"General" => + {"log-file" => [\$log_file, "/var/log/gosa-si/gosa-si.log"], + "pid-file" => [\$pid_file, "/var/run/gosa-si/gosa-si-client.pid"], + "opts-file" => [\$opts_file, "/var/run/gosa-si/gosa-si-client.opts"], }, -"client" => +"Client" => {"port" => [\$client_port, "20083"], "ip" => [\$client_ip, "0.0.0.0"], "mac-address" => [\$client_mac_address, "00:00:00:00:00:00"], @@ -114,12 +174,13 @@ my $fai_log_dir = "/var/log/fai"; "force-hostname" => [\$client_force_hostname, "false"], "system-com" => [\$system_com, "disabled"], }, -"server" => { - "ip" => [\$server_ip, "127.0.0.1"], +"Server" => { + "ip" => [\$servers_string, "127.0.0.1"], "port" => [\$server_port, "20081"], "key" => [\$server_key, ""], "timeout" => [\$server_timeout, 10], - "key-lifetime" => [\$server_key_lifetime, 600], + "key-lifetime" => [\$server_key_lifetime, 600], + "dns-lookup" => [\$opts_dnslookup, "true"], }, ); @@ -127,102 +188,139 @@ my $fai_log_dir = "/var/log/fai"; #=== FUNCTIONS = functions ===================================================== -sub usage { - print STDERR << "EOF" ; -usage: $prg [-hvf] [-c config] +############################# +# +# @brief Display error message and/or help text. +# +# In correspondence to previous GetOptions +# +# @param $text - string to print as error message +# @param $help - set true, if you want to show usage help +# +sub usage +{ + my( $text, $help ) = @_; - -h : this (help) message - -c : config file - -f : foreground, process will not be forked to background - -v : be verbose (multiple to increase verbosity) - + $text = undef if( 'h' eq $text ); + (defined $text) && print STDERR "\n$text\n"; + + if( (defined $help && $help) + || (!defined $help && !defined $text) ) +{ + print STDERR << "EOF"; + + usage: $0 [-hvf] [-c config] + + -h : this (help) message + -c : config file (default: ${config}) + -x : dump configuration to stdout + ( 1 = current, 2 = default ) + -f : foreground (don't fork) + -v : be verbose (multiple to increase verbosity) EOF - print "\n" ; } + print( "\n" ); -#=== FUNCTION ================================================================ -# NAME: check_cmdline_param -# PARAMETERS: -# RETURNS: -# DESCRIPTION: -#=============================================================================== -sub check_cmdline_param () { - my $err_config; - my $err_counter = 0; - if(not defined($cfg_file)) { - $cfg_file = "/etc/gosa-si/client.conf"; - if(! -r $cfg_file) { - $err_config = "please specify a config file"; - $err_counter += 1; - } - } - if( $err_counter > 0 ) { - &usage( "", 1 ); - if( defined( $err_config)) { print STDERR "$err_config\n"} - print STDERR "\n"; - exit( -1 ); - } + exit( -1 ); } +############################# +# +# @brief Manage gosa-si-client configuration. +# +# Will exit after successfull dump to stdout (type = 1 | 2) +# +# Dump type can be: +# 1: Current gosa-si-client configuration in config file (exit) +# 2: Default gosa-si-client configuration (exit) +# 3: Dump to logfile (no exit) +# +# @param int config type +# +sub dump_configuration { -#=== FUNCTION ================================================================ -# NAME: check_pid -# PARAMETERS: -# RETURNS: -# DESCRIPTION: -#=============================================================================== -sub check_pid { - $pid = -1; - # Check, if we are already running - if( open(LOCK_FILE, "<$pid_file") ) { - $pid = ; - if( defined $pid ) { - chomp( $pid ); - if( -f "/proc/$pid/stat" ) { - my($stat) = `cat /proc/$pid/stat` =~ m/$pid \((.+)\).*/; - if( $0 eq $stat ) { - close( LOCK_FILE ); - exit -1; - } - } - } - close( LOCK_FILE ); - unlink( $pid_file ); - } + my( $cfg_type ) = @_; + + return if( ! defined $cfg_type ); + + if(1==$cfg_type ) { + print( "# Current gosa-si-client configuration\n" ); + } elsif (2==$cfg_type) { + print( "# Default gosa-si-client configuration\n" ); + } elsif (3==$cfg_type) { + daemon_log( "Dumping gosa-si-client configuration\n", 2 ); + } else { + return; + } + + foreach my $section (keys %cfg_defaults) { + if( 3 != $cfg_type ) { + print( "\n[${section}]\n" ); + } else { + daemon_log( "\n [${section}]\n", 3 ); + } + + foreach my $param (sort( keys %{$cfg_defaults{ $section }})) { + my $pinfo = $cfg_defaults{ $section }{ $param }; + my $value; + if (1==$cfg_type) { + if( defined( ${@$pinfo[ 0 ]} ) ) { + $value = ${@$pinfo[ 0 ]}; + print( "$param=$value\n" ); + } else { + print( "#${param}=\n" ); + } + } elsif (2==$cfg_type) { + $value = @{$pinfo}[ 1 ]; + if( defined( @$pinfo[ 1 ] ) ) { + $value = @{$pinfo}[ 1 ]; + print( "$param=$value\n" ); + } else { + print( "#${param}=\n" ); + } + } elsif (3==$cfg_type) { + if( defined( ${@$pinfo[ 0 ]} ) ) { + $value = ${@$pinfo[ 0 ]}; + daemon_log( " $param=$value\n", 3 ) + } + } + } + } - # 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 = )) - { - chomp($pid); - $msg .= "(PID $pid)\n"; - } else { - $msg .= "(unable to read PID)\n"; - } - if( ! ($foreground) ) { - openlog( $0, "cons,pid", "daemon" ); - syslog( "warning", $msg ); - closelog(); - } - else { - print( STDERR " $msg " ); - } - exit( -1 ); - } -} +# We just exit at stdout dump + if( 3 == $cfg_type ) { + daemon_log( "\n", 3 ); + } else { + exit( 0 ); + } +} +############################# +# +# @brief When caching an interrupt remove file pid and stopping gosa-si +# sub sig_int_handler { - my ($signal) = @_; - - daemon_log("shutting down gosa-si-client", 1); - system("kill `ps -C gosa-si-client -o pid=`"); + my ($signal) = @_; + + daemon_log("shutting down gosa-si-client", 1); + + # shtudown the client by telling the poe kernel + $global_kernel->yield('shutdown'); + + #removing the opts file + unlink ('/var/run/gosa-si/gosa-si-client.opts'); + + #removing the fifo for communication + unlink ($fai_com_fifo); + + #removing the pid + $pid->remove or warn "Could not remove $pid_file\n"; + + exit(0); } $SIG{INT} = \&sig_int_handler; - #=== FUNCTION ================================================================ # NAME: logging # PARAMETERS: level - string - default 'info' @@ -265,7 +363,7 @@ sub daemon_log { $microSeconds =~ s/^\d*(.\d\d)$/$1/; - my $log_msg = "$month $monthday $hours:$minutes:$seconds$microSeconds $prg $msg\n"; + my $log_msg = "$month $monthday $hours:$minutes:$seconds$microSeconds gosa-si-client $msg\n"; print LOG_HANDLE $log_msg; if( $foreground ) { print STDERR $log_msg; @@ -297,25 +395,12 @@ sub get_mac { $result = "00:00:00:00:00:00"; } } else { - my $SIOCGIFHWADDR= 0x8927; # man 2 ioctl_list - # A configured MAC Address should always override a guessed value if ($client_mac_address and length($client_mac_address) > 0 and not($client_mac_address eq "00:00:00:00:00:00")) { $result= $client_mac_address; } else { - socket SOCKET, PF_INET, SOCK_DGRAM, getprotobyname('ip') - or die "socket: $!"; - - if(ioctl SOCKET, $SIOCGIFHWADDR, $ifreq) { - my ($if, $mac)= unpack 'h36 H12', $ifreq; - - if (length($mac) > 0) { - $mac=~ m/^([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/; - $mac= sprintf("%s:%s:%s:%s:%s:%s", $1, $2, $3, $4, $5, $6); - $result = $mac; - } - } + $result = Net::ARP::get_mac($ifreq); } } } @@ -346,12 +431,12 @@ sub get_local_mac_for_remote_ip { if($server_ip =~ /^(\d\d?\d?\.){3}\d\d?\d?$/) { my $PROC_NET_ROUTE= ('/proc/net/route'); - open(PROC_NET_ROUTE, "<$PROC_NET_ROUTE") + open(my $PROC_NET, "<","$PROC_NET_ROUTE") or die "Could not open $PROC_NET_ROUTE"; - my @ifs = ; + my @ifs = <$PROC_NET>; - close(PROC_NET_ROUTE); + close($PROC_NET); # Eat header line shift @ifs; @@ -478,7 +563,7 @@ sub send_msg_to_target { if ($REGISTERED == 1) { &_setREGISTERED(0); # if server is not available, cause reregistering daemon_log("INFO: cause reregistering at gosa-si-server", 5); - $global_kernel->yield('register_at_gosa_si_server'); + $global_kernel->post('client_session', 'register_at_gosa_si_server'); } $error++; @@ -505,11 +590,11 @@ sub write_to_file { my $error = 0; if( not defined $file || not -f $file ) { - &main::daemon_log("ERROR: $prg: check '-f file' failed: $file", 1); + &main::daemon_log("ERROR: gosa-si-client : check '-f file' failed: $file", 1); $error++; } if( not defined $string || 0 == length($string)) { - &main::daemon_log("ERROR: $prg: empty string to write to file '$file'", 1); + &main::daemon_log("ERROR: gosa-si-client : empty string to write to file '$file'", 1); $error++; } @@ -517,13 +602,13 @@ sub write_to_file { chomp($string); - if (open(FILE, ">> $file")){ - print FILE $string."\n"; - close(FILE); + if (open(my $FILE, ">>", "$file")){ + print $FILE $string."\n"; + close($FILE); } } - return; + return; } @@ -806,7 +891,7 @@ sub trigger_logged_in_users_report { @logged_in_user_list = split(/\s/, $result); } - system("echo 'CURRENTLY_LOGGED_IN ".join(" ", @logged_in_user_list)."' > /var/run/gosa-si-client.socket"); + system("echo 'CURRENTLY_LOGGED_IN ".join(" ", @logged_in_user_list)."' > /var/run/gosa-si/gosa-si-client.socket"); $kernel->delay_set('trigger_logged_in_users_report', $trigger_logged_in_users_report_delay); } else { # try it in 10 sec again @@ -840,9 +925,9 @@ sub trigger_seen_messages { # Check if file has 'seen' tag foreach my $goto_file (@goto_files) { - open(FILE, "$goto_dir/$goto_file"); - my @lines = ; - close FILE; + open(my $FILE, "$goto_dir/$goto_file"); + my @lines = <$FILE>; + close($FILE); my $source; my $target; @@ -1006,9 +1091,9 @@ sub save_fai_log { next; } - open(FILE, "<$log_file"); - my @lines = ; - close (FILE); + open(my $FILE, "<","$log_file"); + my @lines = <$FILE> ; + close ($FILE); my $log_string = join("", @lines); $log .= &encode_base64($log_string); push(@log_list, $log); @@ -1138,82 +1223,195 @@ sub post_processing_and_sending return; } +sub find_servers { + # add gosa-si-server address from config file at first position of server list + my $server_check_cfg = Config::IniFiles->new( -file => $config ); -#==== MAIN = main ============================================================== -# parse commandline options -Getopt::Long::Configure( "bundling" ); -GetOptions("h|help" => \&usage, - "c|config=s" => \$cfg_file, - "f|foreground" => \$foreground, - "v|verbose+" => \$verbose, - ); + # Parse servers string + my @conf_servers = split(',', $servers_string); -# read and set config parameters -&check_cmdline_param ; -&read_configfile($cfg_file, %cfg_defaults); -&check_pid; + # Now search for fallback servers in the configuration + foreach my $cur_server (@conf_servers) { + # Remove spaces from the IP + $cur_server =~ s/\s//g; + my $ip = $cur_server; + if(not $cur_server =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) { + my $ip_address = inet_ntoa(scalar gethostbyname($ip)); + if(defined($ip_address) && $ip_address =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) { + # Write ip address to $server_ip variable + $ip = $ip_address; + } + } -# forward error messages to logfile -if ( ! $foreground ) { - open( STDIN, '+>/dev/null' ); - open( STDOUT, '+>&STDIN' ); - open( STDERR, '+>&STDIN' ); -} + my $server_addr = sprintf("%s:%s", $ip, $server_port); + if (not grep { $_ eq $server_addr } @servers) { + push(@servers, $server_addr); + } + } + + my $servers_string = join(", ", @servers); + daemon_log("INFO: found servers in configuration file: $servers_string", 1); + + # Last but not least search for fallback servers in the DNS + if (defined($opts_dnslookup) and $opts_dnslookup eq "true") { + my @tmp_servers; + if ( !$server_domain) { + # Try our DNS Searchlist + my @domain_list = &get_dns_domains(); + my $tmp_domains; + my $error_string; + for my $domain (@domain_list) { + chomp($domain); + ($tmp_domains, $error_string) = &get_server_addresses($domain); + if(@$tmp_domains) { + for my $tmp_server(@$tmp_domains) { + push @tmp_servers, $tmp_server; + } + } + } + + if (0 == @tmp_servers) { + daemon_log("INFO: No servers found in DNS.", 1); + } + else { + my $servers_string = join(", ", @tmp_servers); + daemon_log("INFO: found servers in DNS: $servers_string", 1); + } + } else { + @tmp_servers = &get_server_addresses($server_domain); + if( 0 == @tmp_servers ) { + daemon_log("INFO: No servers found in DNS for domain '$server_domain'",1); + } + } -# Just fork, if we are not in foreground mode -if( ! $foreground ) { - chdir '/' or die "Can't chdir to /: $!"; - $pid = fork; - setsid or die "Can't start a new session: $!"; - umask 0; -} else { - $pid = $$; + if ( 0 != @tmp_servers ) { + foreach my $server_addr (@tmp_servers) { + if (not grep { $_ eq $server_addr } @servers) { + push(@servers, $server_addr); + } + } + } + } + + if (0 == scalar(@servers)) { + daemon_log("ERROR: No servers found in the configuration or DNS.", 1); + exit(1); + } + + # Define first server as server_ip + $server_ip = $servers[0]; + + # prepare variables + if( inet_aton($server_ip) ){ $server_ip = inet_ntoa(inet_aton($server_ip)); } + if (defined $server_ip && defined $server_port) { + $server_address = $server_ip.":".$server_port; + } } -# 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 ); - if( !$foreground ) { - exit( 0 ) - }; + +sub start_daemon { + + if( ! $foreground ) { + chdir '/' or die "Can't chdir to /: $!"; + umask 0; + open STDIN, '+>/dev/null' or die "Can't read /dev/null: $!"; + open STDOUT, '+>&STDIN' or die "Can't write to /dev/null: $!"; + open STDERR, '+>&STDIN' or die "Can't write to /dev/null: $!"; + defined($pid = fork) or die "Can't fork: $!"; + exit if $pid; + setsid or die "Can't start a new session: $!"; + } + return; } -# parse head url and revision from svn -my $client_status_hash = { 'developmental'=>'revision', 'stable'=>'release'}; -$client_version =~ /^\$HeadURL: (\S+) \$:\$Rev: (\d+) \$$/; -$client_headURL = defined $1 ? $1 : 'unknown' ; -$client_revision = defined $2 ? $2 : 'unknown' ; -if ($client_headURL =~ /\/tag\// || +sub put_version { + + # parse head url and revision from svn + $client_version =~ /^\$HeadURL: (\S+) \$:\$Rev: (\d+) \$$/; + $client_headURL = defined $1 ? $1 : 'unknown' ; + $client_revision = defined $2 ? $2 : 'unknown' ; + if ($client_headURL =~ /\/tag\// || $client_headURL =~ /\/branches\// ) { $client_status = "stable"; -} else { + } else { $client_status = "developmental" ; + } + return; } -# Determine root uid and adm gid, used for creating log files -$root_uid = getpwnam('root'); -$adm_gid = getgrnam('adm'); -if(not defined $adm_gid){ - $adm_gid = getgrnam('root'); +sub get_perms_admin { + # Determine root uid and adm gid, used for creating log files + $root_uid = getpwnam('root'); + $adm_gid = getgrnam('adm'); + if(not defined $adm_gid){ + $adm_gid = getgrnam('root'); + } + return; +} + +sub create_pid { + # Create the PID object + $pid = File::Pid->new({ file => $pid_file }); + + # Write the PID file + $pid->write; + + return; } +# +#==== MAIN = main ============================================================== +# +# Parse options and allow '-vvv' +Getopt::Long::Configure( 'bundling' ); +GetOptions( 'v|verbose+' => \$verbose, + 'h|help' => \&usage, + 'c|config=s' => \$config, + 'x|dump-config=i' => \$dump_config, + 'f|foreground' => \$foreground) + or usage( '', 1 ); + +# We may want to dump the default configuration +if( defined $dump_config ) { + if($dump_config==1) { + } elsif ($dump_config==2) { + dump_configuration( $dump_config ); + } else { + usage( "Dump configuration value has to be 1 or 2" ); + } +} + +# read and set config parameters +&read_configfile($config, %cfg_defaults); + +# daemonize the program +&start_daemon($foreground); + +# create pid file +&create_pid($pid, $pid_file); + +# Determine root uid and adm gid, used for creating log files +&get_perms_admin($root_uid, $adm_gid); + +# put version +&put_version($client_status_hash, $client_version, $client_version, $client_headURL, $client_status); + daemon_log(" ", 1); -daemon_log("$prg started!", 1); +daemon_log("$0 started!", 1); daemon_log("INFO: status: $client_status", 1); daemon_log("INFO: ".$client_status_hash->{$client_status}.": $client_revision", 1); -# delete old DBsqlite lock files -system('rm -f /tmp/gosa_si_lock*gosa-si-client*'); +# to be changed maybe not trace of it when running +#system('rm -f /tmp/gosa_si_lock*gosa-si-client*'); # detect ip and mac address and complete host address $client_address = $client_ip.":".$client_port; my $network_interface= &get_interface_for_ip($client_ip); $client_mac_address= &get_mac($network_interface); + daemon_log("INFO: ip address detected: $client_ip", 1); -daemon_log("INFO: gosa-si-client mac address detected: $client_mac_address", 1); +daemon_log("INFO: $0 mac address detected: $client_mac_address", 1); # import events @@ -1237,7 +1435,6 @@ foreach my $log_line (@$result) { $gotoHardwareChecksum= &generate_hw_digest(); daemon_log("INFO: gotoHardwareChecksum detected: $gotoHardwareChecksum", 1); - # create socket for incoming xml messages POE::Component::Server::TCP->new( Alias => 'gosa-si-client', @@ -1246,68 +1443,16 @@ POE::Component::Server::TCP->new( ); daemon_log("INFO: start socket for incoming xml messages at port '$client_port' ", 1); - -# prepare variables -if( inet_aton($server_ip) ){ $server_ip = inet_ntoa(inet_aton($server_ip)); } -if (defined $server_ip && defined $server_port) { - $server_address = $server_ip.":".$server_port; -} $xml = new XML::Simple(); $default_server_key = $server_key; -# add gosa-si-server address from config file at first position of server list -my $server_check_cfg = Config::IniFiles->new( -file => $cfg_file ); -my $server_check = (defined($server_check_cfg))?$server_check_cfg->val( "server", "ip"):undef; -if( defined $server_check ) { - unshift(@servers, $server_address); - my $servers_string = join(", ", @servers); - daemon_log("INFO: found servers in configuration file: $servers_string", 1); -} else { - my @tmp_servers; - if ( !$server_domain) { - # Try our DNS Searchlist - my @domain_list = &get_dns_domains(); - my $tmp_domains; - my $error_string; - for my $domain (@domain_list) { - chomp($domain); - ($tmp_domains, $error_string) = &get_server_addresses($domain); - if(@$tmp_domains) { - for my $tmp_server(@$tmp_domains) { - push @tmp_servers, $tmp_server; - } - } - } - if (0 == @tmp_servers) { - my $log_string = "no gosa-si-server found in DNS for domain: ".join(", ", @domain_list) if (@domain_list); - my $log_string2 = "server addresses in domain: ".join(", ",@$tmp_domains) if (defined($tmp_domains)); - daemon_log("ERROR: $log_string", 1) if (defined($log_string)); - daemon_log("ERROR: $log_string2", 1) if (defined($log_string2)); - daemon_log("ERROR: $error_string", 1) if (defined($error_string)); - daemon_log("ERROR: please specify a gosa-si-server address or a domain in config file", 1); - kill 2, $$; - } - } else { - @tmp_servers = &get_server_addresses($server_domain); - if( 0 == @tmp_servers ) { - daemon_log("ERROR: no gosa-si-server found in DNS for domain '$server_domain'",1); - daemon_log("ERROR: please specify a gosa-si-server address or a domain in config file", 1); - kill 2, $$; - } - } - - foreach my $server (@tmp_servers) { - unshift(@servers, $server); - } - my $servers_string = join(", ", @servers); - daemon_log("INFO: found servers in DNS: $servers_string", 1); -} - - # Open a new fifo for FAI messages to gosa-si-server if (-p $fai_com_fifo) { unlink $fai_com_fifo } POSIX::mkfifo("$fai_com_fifo", 0600); +# Find servers from config and DNS +&find_servers; + # Open a new fifo for system communication, if (-p $system_com_fifo) { unlink $system_com_fifo } if ($system_com eq "enabled") @@ -1317,26 +1462,26 @@ if ($system_com eq "enabled") POE::Session->create( inline_states => { - _start => \&_start, - _default => \&_default, - sig_handler => \&sig_handler, - register_at_gosa_si_server => \®ister_at_gosa_si_server, + _start => \&_start, + _default => \&_default, + sig_handler => \&sig_handler, + register_at_gosa_si_server => \®ister_at_gosa_si_server, - # trigger periodical tasks - trigger_new_key => \&trigger_new_key, - trigger_logged_in_users_report => \&trigger_logged_in_users_report, - trigger_seen_messages => \&trigger_seen_messages, + # trigger periodical tasks + trigger_new_key => \&trigger_new_key, + trigger_logged_in_users_report => \&trigger_logged_in_users_report, + trigger_seen_messages => \&trigger_seen_messages, # trigger non periodical tasks trigger_set_terminal_server => \&trigger_set_terminal_server, - - # handle records from each defined file differently - fai_fifo_record => \&fai_fifo_got_record, + + # handle records from each defined file differently + fai_fifo_record => \&fai_fifo_got_record, system_fifo_record => \&system_fifo_got_record, - # handle file resets and errors the same way for each file - file_reset => \&generic_file_reset, - file_error => \&generic_file_error, + # handle file resets and errors the same way for each file + file_reset => \&generic_file_reset, + file_error => \&generic_file_error, } ); diff --git a/gosa-si/gosa-si-client.1 b/gosa-si/gosa-si-client.1 index c1a51b9c2..6d2a205f8 100644 --- a/gosa-si/gosa-si-client.1 +++ b/gosa-si/gosa-si-client.1 @@ -1,4 +1,4 @@ -.\" Automatically generated by Pod::Man 2.1801 (Pod::Simple 3.05) +.\" Automatically generated by Pod::Man 2.1801 (Pod::Simple 3.07) .\" .\" Standard preamble: .\" ======================================================================== @@ -124,7 +124,7 @@ .\" ======================================================================== .\" .IX Title "GOSA-SI-CLIENT 1" -.TH GOSA-SI-CLIENT 1 "2009-09-04" "perl v5.10.0" "User Contributed Perl Documentation" +.TH GOSA-SI-CLIENT 1 "2010-05-17" "perl v5.10.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -152,6 +152,10 @@ gosa-si-client [\-hvf] [\-c config] .PP \&\fB\-c\fR \fIfile\fR, \fB\-\-config=\fR\fIfile\fR configuration file, default \fI/etc/gosa\-si/client.conf\fR +.PP +\&\fB\-x\fR + dump configuration to stdout + ( 1 = current, 2 = default ) .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\fBgosa-si-client\fR belongs to the support infrastructure of GOsa. @@ -165,7 +169,7 @@ Please report any bugs, or post any suggestions, to the GOsa mailing list ) .PP -Copyright (C) 2003\-2009 \s-1GONICUS\s0 GmbH +Copyright (C) 2003\-2010 \s-1GONICUS\s0 GmbH .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 diff --git a/gosa-si/gosa-si-client.conf.5 b/gosa-si/gosa-si-client.conf.5 index b87dc2113..41bab58d3 100644 --- a/gosa-si/gosa-si-client.conf.5 +++ b/gosa-si/gosa-si-client.conf.5 @@ -1,4 +1,4 @@ -.\" Automatically generated by Pod::Man 2.1801 (Pod::Simple 3.05) +.\" Automatically generated by Pod::Man 2.1801 (Pod::Simple 3.07) .\" .\" Standard preamble: .\" ======================================================================== @@ -124,7 +124,7 @@ .\" ======================================================================== .\" .IX Title "CLIENT.CONF 1" -.TH CLIENT.CONF 1 "2009-12-09" "perl v5.10.0" "User Contributed Perl Documentation" +.TH CLIENT.CONF 1 "2010-05-17" "perl v5.10.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -136,19 +136,19 @@ gosa\-si\-client.conf \- Configuration file for gosa\-si\-client. The gosa\-si\-client.conf file defines all parameter GOsa-SI-client needs for running and communication with GOsa-SI-server. It is normally located in the \fI/etc/gosa\-si/\fR directory and is generated automatically by the \fIgosa\-si\-client\fR\|(1) program during installation. .SH "DIRECTIVES" .IX Header "DIRECTIVES" -.SS "[general]" -.IX Subsection "[general]" -.IP "log-file = /var/run/gosa\-si\-client.log" 4 -.IX Item "log-file = /var/run/gosa-si-client.log" +.SS "[General]" +.IX Subsection "[General]" +.IP "log-file = /var/log/gosa\-si/gosa\-si\-client.log" 4 +.IX Item "log-file = /var/log/gosa-si/gosa-si-client.log" Defines the location for the log file. -.IP "pid-file = /var/run/gosa\-si\-client.pid" 4 -.IX Item "pid-file = /var/run/gosa-si-client.pid" +.IP "pid-file = /var/run/gosa\-si/gosa\-si\-client.pid" 4 +.IX Item "pid-file = /var/run/gosa-si/gosa-si-client.pid" Defines the location for the pid file. -.IP "opts-file = var/run/gosa\-si\-client.opts" 4 -.IX Item "opts-file = var/run/gosa-si-client.opts" +.IP "opts-file = var/run/gosa\-si/gosa\-si\-client.opts" 4 +.IX Item "opts-file = var/run/gosa-si/gosa-si-client.opts" Defines the location for the opts file. -.SS "[client]" -.IX Subsection "[client]" +.SS "[Client]" +.IX Subsection "[Client]" .IP "port = 20083" 4 .IX Item "port = 20083" Defines the port GOsa-SI-client is listening for incoming messages. @@ -182,8 +182,8 @@ If set to true, client will try to get the hostname for registration from \f(CW$ .IP "system-com = disabled | enabled" 4 .IX Item "system-com = disabled | enabled" Open a different fifo for system communication -.SS "[server]" -.IX Subsection "[server]" +.SS "[Server]" +.IX Subsection "[Server]" .IP "ip = 127.0.0.1" 4 .IX Item "ip = 127.0.0.1" If set GOsa-SI-client is forced to register at specified GOsa-SI-Server. If it is not set, GOsa-SI tries to register at GOsa-SI-servers found in \s-1DNS\s0. @@ -214,7 +214,7 @@ Please report any bugs, or post any suggestions, to the GOsa mailing list ) .PP -Copyright (C) 2003\-2009 \s-1GONICUS\s0 GmbH +Copyright (C) 2003\-2010 \s-1GONICUS\s0 GmbH .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 diff --git a/gosa-si/gosa-si-client.pod b/gosa-si/gosa-si-client.pod deleted file mode 100644 index 7a2f84a0d..000000000 --- a/gosa-si/gosa-si-client.pod +++ /dev/null @@ -1,56 +0,0 @@ - -=head1 NAME - -gosa-si-client - Client for GOsa support infrastructure - -=head1 SYNOPSIS - -gosa-si-client [-hvf] [-c config] - -=head1 OPTIONS - -B<-h>, B<--help> - print out this help message - -B<-v>, B<--verbose> - be verbose (multiple v's will increase verbosity) - -v ERROR level - -vvv WARNING + ERROR level - -vvvvv INFO + WARNING level - -vvvvvvv DEBUG + INFO level - -vvvvvvvvv in and out going xml messages will be displayed - -B<-f>, B<--foreground> - foregroud, process will not be forked to background - -B<-c> I, B<--config=>I - configuration file, default F - - -=head1 DESCRIPTION - -B belongs to the support infrastructure of GOsa. -The client registrates at a GOsa-SI-server and accepts messages from it. -Each message is related to a working instruction which will be executed on the client. -Depending on the message an answer can be send back to the server. - -=head1 BUGS - -Please report any bugs, or post any suggestions, to the GOsa mailing list or to - - -=head1 LICENCE AND COPYRIGHT - -This code is part of GOsa (L) - -Copyright (C) 2003-2009 GONICUS GmbH - -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. - -=cut - - - diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 94f568e9e..9d92dc997 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -1,38 +1,95 @@ #!/usr/bin/perl -#=============================================================================== -# -# FILE: gosa-si-server +#********************************************************************* # -# USAGE: ./gosa-si-server +# gosa-si-client -- client for the gosa-si-server # -# DESCRIPTION: +# (c) 2007-2009 by Andreas Rettenberger +# (c) 2008-2010 by Cajus Pollmeier +# (c) 2008-2009 by Jan Wenzel +# (c) 2010 by Benoit Mortier # -# OPTIONS: --- -# REQUIREMENTS: libconfig-inifiles-perl libcrypt-rijndael-perl libxml-simple-perl -# libdata-dumper-simple-perl libdbd-sqlite3-perl libnet-ldap-perl -# libpoe-perl -# BUGS: --- -# NOTES: -# AUTHOR: (Andreas Rettenberger), -# COMPANY: -# VERSION: 1.0 -# CREATED: 12.09.2007 08:54:41 CEST -# REVISION: --- -#=============================================================================== +#********************************************************************* -my $server_version = '$HeadURL: https://oss.gonicus.de/repositories/gosa/trunk/gosa-si/gosa-si-server $:$Rev$'; + +=head1 NAME + +gosa-si-server -Support infrastructure for GOsa + +=head1 SYNOPSIS + +gosa-si-server [-hvf] [-c config] [-x dump ] + +=head1 OPTIONS + +B<-h>, B<--help> + print out this help message + +B<-v>, B<--verbose> + be verbose (multiple v's will increase verbosity) + -v ERROR level + -vvv WARNING + ERROR level + -vvvvv INFO + WARNING level + -vvvvvvv DEBUG + INFO level + -vvvvvvvvv in and out going xml messages will be displayed + +B<-f>, B<--foreground> + foregroud, process will not be forked to background + +B<-c> I, B<--config=>I + configuration file, default F + +B<--no-arp> + starts script without connection to arp module + +B<-d> + if verbose level is higher than 7 '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 + 16 : message processing + 32 : ldap connectivity + 64 : database status and connectivity + 128 : main process + 256 : creation of packages_list_db + 512 : ARP debug information + +B<-x> + dump configuration to stdout + ( 1 = current, 2 = default ) + +=head1 DESCRIPTION + +gosa-si-server belongs to the support infrastructure of GOsa. Several gosa-si-clients can connect to one gosa-si-server. The server take care of the message forwarding from GOsa to si-clients. At the client site each message is related to a working instruction which will be executed there. Depending of the message an answer from the client to GOsa via the server is possible. Additional to answers clients reporting events or information to the server. The server registers himself at other servers in network and shares his knowledge with them. So messages to clients which are no registrated locally will be forward to the client corresponding server. The communication within the complete SI nework is realised by XML messages. + + +=head1 BUGS + +Please report any bugs, or post any suggestions, to the GOsa mailing list or to + + +=head1 LICENCE AND COPYRIGHT + +This code is part of GOsa (L) + +Copyright (C) 2003-2010 GONICUS GmbH + +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. + +=cut use strict; use warnings; + use Getopt::Long; use Config::IniFiles; -use POSIX; - -use Fcntl qw/:flock/; use IO::Socket::INET; use IO::Handle; use IO::Select; -use Symbol qw(qualify_to_ref); use Crypt::Rijndael; use MIME::Base64; use Digest::MD5 qw(md5 md5_hex md5_base64); @@ -40,41 +97,43 @@ use XML::Simple; use Data::Dumper; use Sys::Syslog qw( :DEFAULT setlogsock); use Time::HiRes qw( usleep clock_gettime ); -use Cwd; use File::Spec; use File::Basename; use File::Find; use File::Copy; use File::Path; -use GOSA::GosaSupportDaemon; -use POE qw(Component::Server::TCP Wheel::Run Filter::Reference); use Net::LDAP; use Net::LDAP::Util qw(:escape); +use File::Pid; +use GOsaSI::GosaSupportDaemon; +use POE qw(Component::Server::TCP Wheel::Run Filter::Reference); +use Symbol qw(qualify_to_ref); +use Fcntl qw/:flock/; +use POSIX; + +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; my $server_status; -our $prg= basename($0); -our $verbose= 0; my $db_module = "DBsqlite"; { no strict "refs"; -require ("GOSA/".$db_module.".pm"); -("GOSA/".$db_module)->import; +require ("GOsaSI/".$db_module.".pm"); +("GOsaSI/".$db_module)->import; } my $modules_path = "/usr/lib/gosa-si/modules"; use lib "/usr/lib/gosa-si/modules"; -our $global_kernel; my ($foreground, $ping_timeout); my ($server); my ($gosa_server, $job_queue_timeout, $job_queue_loop_delay); my ($messaging_db_loop_delay); -my ($procid, $pid); +my $procid; my $arp_fifo; my $debug_parts = 0; my $debug_parts_bitstring; @@ -85,8 +144,10 @@ my %repo_files=(); my $repo_path; my %repo_dirs=(); +my $server_status_hash = { 'developmental'=>'revision', 'stable'=>'release'}; + # Variables declared in config file are always set to 'our' -our (%cfg_defaults, $log_file, $pid_file, +our (%cfg_defaults, $log_file, $pid_file, $pid, $server_ip, $server_port, $ClientPackages_key, $dns_lookup, $arp_activ, $gosa_unit_tag, $GosaPackages_key, $gosa_timeout, @@ -111,6 +172,14 @@ our $known_modules; our $known_functions; our $root_uid; our $adm_gid; +our $verbose= 0; +our $global_kernel; + +# where is the config stored by default and his name +our $config = '/etc/gosa-si/server.conf'; + +# by default dumping of config is undefined +our $dump_config = undef; # if foreground is not null, script will be not forked to background $foreground = 0 ; @@ -208,7 +277,6 @@ my $messaging_file_name; our $client_fai_log_dir = "/var/log/fai"; # queue which stores taskes until one of the $max_children children are ready to process the task -#my @tasks = qw(); my @msgs_to_decrypt = qw(); my $max_children = 2; @@ -231,11 +299,11 @@ our $check_periodic = {"months"=>'', "weeks"=>'', "days"=>'', "hours"=>'', "minu %cfg_defaults = ( -"general" => { - "log-file" => [\$log_file, "/var/run/".$prg.".log"], - "pid-file" => [\$pid_file, "/var/run/".$prg.".pid"], +"General" => { + "log-file" => [\$log_file, "/var/log/gosa-si/gosa-si-server.log"], + "pid-file" => [\$pid_file, "/var/run/gosa-si/gosa-si-server.pid"], }, -"server" => { +"Server" => { "ip" => [\$server_ip, "0.0.0.0"], "port" => [\$server_port, "20081"], "known-clients" => [\$known_clients_file_name, '/var/lib/gosa-si/clients.db' ], @@ -248,7 +316,7 @@ 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'], "debian-arch" => [\$arch, 'i386'], "ldap-uri" => [\$ldap_uri, ""], "ldap-base" => [\$ldap_base, ""], @@ -298,26 +366,40 @@ our $check_periodic = {"months"=>'', "weeks"=>'', "days"=>'', "hours"=>'', "minu ); +############################# +# +# @brief Display error message and/or help text. +# +# In correspondence to previous GetOptions +# +# @param $text - string to print as error message +# @param $help - set true, if you want to show usage help +# +sub usage +{ + my( $text, $help ) = @_; + + $text = undef if( 'h' eq $text ); + (defined $text) && print STDERR "\n$text\n"; -#=== FUNCTION ================================================================ -# NAME: usage -# PARAMETERS: nothing -# RETURNS: nothing -# DESCRIPTION: print out usage text to STDERR -#=============================================================================== -sub usage { - print STDERR << "EOF" ; -usage: $prg [-hvf] [-c config] [-d number] + if( (defined $help && $help) + || (!defined $help && !defined $text) ) +{ + print STDERR << "EOF"; - -h : this (help) message - -c : config file - -f : foreground, process will not be forked to background + usage: $0 [-hvf] [-c config] [-d number] + + -h : this (help) message + -c : config file (default: ${config}) + -x : dump configuration to stdout + ( 1 = current, 2 = default ) + -f : foreground (don't fork) -v : be verbose (multiple to increase verbosity) 'v': error logs 'vvv': warning plus error logs 'vvvvv': info plus warning logs 'vvvvvvv': debug plus info logs - -no-arp : starts $prg without connection to arp module + -no-arp : starts gosa-si-server without connection to arp module -d : if verbose level is higher than 7x 'v' specified parts can be debugged 1 : report incoming messages 2 : report unencrypted outgoing messages @@ -330,7 +412,82 @@ usage: $prg [-hvf] [-c config] [-d number] 256 : creation of packages_list_db 512 : ARP debug information EOF - exit(0); +} + print( "\n" ); + + exit( -1 ); +} + +############################# +# +# @brief Manage gosa-si-client configuration. +# +# Will exit after successfull dump to stdout (type = 1 | 2) +# +# Dump type can be: +# 1: Current gosa-si-client configuration in config file (exit) +# 2: Default gosa-si-client configuration (exit) +# 3: Dump to logfile (no exit) +# +# @param int config type +# +sub dump_configuration { + + my( $cfg_type ) = @_; + + return if( ! defined $cfg_type ); + + if(1==$cfg_type ) { + print( "# Current gosa-si-server configuration\n" ); + } elsif (2==$cfg_type) { + print( "# Default gosa-si-server configuration\n" ); + } elsif (3==$cfg_type) { + daemon_log( "Dumping gosa-si-server configuration\n", 2 ); + } else { + return; + } + + foreach my $section (keys %cfg_defaults) { + if( 3 != $cfg_type ) { + print( "\n[${section}]\n" ); + } else { + daemon_log( "\n [${section}]\n", 3 ); + } + + foreach my $param (sort( keys %{$cfg_defaults{ $section }})) { + my $pinfo = $cfg_defaults{ $section }{ $param }; + my $value; + if (1==$cfg_type) { + if( defined( ${@$pinfo[ 0 ]} ) ) { + $value = ${@$pinfo[ 0 ]}; + print( "$param=$value\n" ); + } else { + print( "#${param}=\n" ); + } + } elsif (2==$cfg_type) { + $value = @{$pinfo}[ 1 ]; + if( defined( @$pinfo[ 1 ] ) ) { + $value = @{$pinfo}[ 1 ]; + print( "$param=$value\n" ); + } else { + print( "#${param}=\n" ); + } + } elsif (3==$cfg_type) { + if( defined( ${@$pinfo[ 0 ]} ) ) { + $value = ${@$pinfo[ 0 ]}; + daemon_log( " $param=$value\n", 3 ) + } + } + } + } + + +# We just exit at stdout dump + if( 3 == $cfg_type ) { + daemon_log( "\n", 3 ); + } else { + exit( 0 ); + } } @@ -394,7 +551,7 @@ sub daemon_log { # Build log message and write it to log file and commandline chomp($msg); - my $log_msg = "$month $monthday $hours:$minutes:$seconds$microSeconds $prg $msg\n"; + my $log_msg = "$month $monthday $hours:$minutes:$seconds$microSeconds $0 $msg\n"; flock(LOG_HANDLE, LOCK_EX); seek(LOG_HANDLE, 0, 2); print LOG_HANDLE $log_msg; @@ -408,93 +565,6 @@ sub daemon_log { } } - -#=== FUNCTION ================================================================ -# NAME: check_cmdline_param -# PARAMETERS: nothing -# RETURNS: nothing -# DESCRIPTION: validates commandline parameter -#=============================================================================== -sub check_cmdline_param () { - my $err_counter = 0; - - # Check configuration file - if(not defined($cfg_file)) { - $cfg_file = "/etc/gosa-si/server.conf"; - if(! -r $cfg_file) { - print STDERR "Please specify a config file.\n"; - $err_counter++; - } - } - - # Prepare identification which gosa-si parts should be debugged and which not - if (defined $debug_parts) - { - if ($debug_parts =~ /^\d+$/) - { - $debug_parts_bitstring = unpack("B32", pack("N", $debug_parts)); - } - else - { - print STDERR "Value '$debug_parts' invalid for option d (number expected)\n"; - $err_counter++; - } - } - - # Exit if an error occour - if( $err_counter > 0 ) { &usage( "", 1 ); } -} - - -#=== FUNCTION ================================================================ -# NAME: check_pid -# PARAMETERS: nothing -# RETURNS: nothing -# DESCRIPTION: handels pid processing -#=============================================================================== -sub check_pid { - $pid = -1; - # Check, if we are already running - if( open(LOCK_FILE, "<$pid_file") ) { - $pid = ; - 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 ); - exit -1; - } - } - } - close( LOCK_FILE ); - unlink( $pid_file ); - } - - # 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 = )) - { - chomp($pid); - $msg .= "(PID $pid)\n"; - } else { - $msg .= "(unable to read PID)\n"; - } - if( ! ($foreground) ) { - openlog( $0, "cons,pid", "daemon" ); - syslog( "warning", $msg ); - closelog(); - } - else { - print( STDERR " $msg " ); - } - exit( -1 ); - } -} - #=== FUNCTION ================================================================ # NAME: import_modules # PARAMETERS: module_path - string - abs. path to the directory the modules @@ -574,21 +644,27 @@ sub password_check { #=== FUNCTION ================================================================ # NAME: sig_int_handler -# PARAMETERS: signal - string - signal arose from system +# PARAMETERS: signal - string - signal came from system # RETURNS: nothing -# DESCRIPTION: handels tasks to be done befor signal becomes active +# DESCRIPTION: handle tasks to be done before signal becomes active #=============================================================================== sub sig_int_handler { - my ($signal) = @_; + my ($signal) = @_; # if (defined($ldap_handle)) { # $ldap_handle->disconnect; # } - # TODO alle verbliebenden ldap verbindungen aus allen heaps beenden +# TODO all ldap connections shoudl be closed + daemon_log("shutting down gosa-si-server", 1); + + # asking the poe kernel to shutdown the server + $global_kernel->yield(TCP_SERVER => 'shutdown'); + + # removing the pidfile + $pid->remove or warn "Could not remove $pid_file\n"; - daemon_log("shutting down gosa-si-server", 1); - system("kill `ps -C gosa-si-server -o pid=`"); + exit(0); } $SIG{INT} = \&sig_int_handler; @@ -1707,25 +1783,25 @@ sub process_task { } sub session_start { - my ($kernel) = $_[KERNEL]; - $global_kernel = $kernel; - $kernel->yield('register_at_foreign_servers'); + my ($kernel) = $_[KERNEL]; + $global_kernel = $kernel; + $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->sig(USR1 => "sig_handler"); $kernel->sig(USR2 => "recreate_packages_db"); $kernel->delay_set('watch_for_new_jobs', $job_queue_loop_delay); $kernel->delay_set('watch_for_done_jobs', $job_queue_loop_delay); - $kernel->delay_set('watch_for_modified_jobs', $modified_jobs_loop_delay); + $kernel->delay_set('watch_for_modified_jobs', $modified_jobs_loop_delay); $kernel->delay_set('watch_for_new_messages', $messaging_db_loop_delay); - $kernel->delay_set('watch_for_delivery_messages', $messaging_db_loop_delay); + $kernel->delay_set('watch_for_delivery_messages', $messaging_db_loop_delay); $kernel->delay_set('watch_for_done_messages', $messaging_db_loop_delay); - $kernel->delay_set('watch_for_old_known_clients', $job_queue_loop_delay); + $kernel->delay_set('watch_for_old_known_clients', $job_queue_loop_delay); - # Start opsi check - if ($opsi_enabled eq "true") { - $kernel->delay_set('watch_for_opsi_jobs', $job_queue_opsi_delay); - } + # Start opsi check + if ($opsi_enabled eq "true") { + $kernel->delay_set('watch_for_opsi_jobs', $job_queue_opsi_delay); + } } @@ -2880,8 +2956,7 @@ sub create_sources_list { &main::daemon_log("$session_id DEBUG: remove an old version of '$result'", 7); } - 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; @@ -2964,14 +3039,14 @@ sub create_packages_list_db { 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; }; # Read lines - while ($line = ){ + while ($line = <$CONFIG>){ # Unify chop($line); $line =~ s/^\s+//; @@ -2993,9 +3068,12 @@ sub create_packages_list_db { &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 )); @@ -3183,7 +3261,6 @@ sub parse_package { my ($path, $dist, $srv_path, $session_id)= @_; if (not defined $session_id) { $session_id = 0;} my ($package, $version, $section, $description); - my $PACKAGES; my $timestamp = &get_time(); if(not stat("$path.in")) { @@ -3191,7 +3268,7 @@ sub parse_package { 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; @@ -3282,9 +3359,9 @@ sub cleanup_and_extract { my $tmpl= ""; { local $/=undef; - open FILE, "$dir/DEBIAN/templates"; - $tmpl = &encode_base64(); - close FILE; + open(my $FILE, "$dir/DEBIAN/templates"); + $tmpl = &encode_base64(<$FILE>); + close($FILE); } rmtree("$dir/DEBIAN/templates"); @@ -3456,72 +3533,121 @@ sub control_server_registration { return; } +sub start_daemon { -#==== MAIN = main ============================================================== -# parse commandline options -Getopt::Long::Configure( "bundling" ); -GetOptions("h|help" => \&usage, - "c|config=s" => \$cfg_file, - "f|foreground" => \$foreground, - "v|verbose+" => \$verbose, - "no-arp+" => \$no_arp, - "d=s" => \$debug_parts, - ) or &usage("", 1); + #to prevent zombie child + $SIG{CHLD} = 'IGNORE'; -# read and set config parameters -&check_cmdline_param ; -&read_configfile($cfg_file, %cfg_defaults); -&check_pid; - -#to prevent sombie child -$SIG{CHLD} = 'IGNORE'; - -# forward error messages to logfile -if( ! $foreground ) { - open( STDIN, '+>/dev/null' ); - open( STDOUT, '+>&STDIN' ); - open( STDERR, '+>&STDIN' ); -} - -# Just fork, if we are not in foreground mode -if( ! $foreground ) { - chdir '/' or die "Can't chdir to /: $!"; - $pid = fork; - setsid or die "Can't start a new session: $!"; - umask 0; -#} else { -# $pid = $$; -} - -# 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 ); - if( !$foreground ) { - exit( 0 ) - }; + if( ! $foreground ) { + chdir '/' or die "Can't chdir to /: $!"; + umask 0; + open STDIN, '+>/dev/null' or die "Can't read /dev/null: $!"; + open STDOUT, '+>&STDIN' or die "Can't write to /dev/null: $!"; + open STDERR, '+>&STDIN' or die "Can't write to /dev/null: $!"; + defined($pid = fork) or die "Can't fork: $!"; + exit if $pid; + setsid or die "Can't start a new session: $!"; + } + return; } -# parse head url and revision from svn -my $server_status_hash = { 'developmental'=>'revision', 'stable'=>'release'}; -$server_version =~ /^\$HeadURL: (\S+) \$:\$Rev: (\d+) \$$/; -$server_headURL = defined $1 ? $1 : 'unknown' ; -$server_revision = defined $2 ? $2 : 'unknown' ; -if ($server_headURL =~ /\/tag\// || +sub put_version { + + # parse head url and revision from svn + $server_version =~ /^\$HeadURL: (\S+) \$:\$Rev: (\d+) \$$/; + $server_headURL = defined $1 ? $1 : 'unknown' ; + $server_revision = defined $2 ? $2 : 'unknown' ; + if ($server_headURL =~ /\/tag\// || $server_headURL =~ /\/branches\// ) { - $server_status = "stable"; -} else { + $server_status = "stable"; + } else { $server_status = "developmental" ; + } + return; +} + +sub get_perms_admin { +# Determine root uid and adm gid, used for creating log files + $root_uid = getpwnam('root'); + $adm_gid = getgrnam('adm'); + if(not defined $adm_gid){ + $adm_gid = getgrnam('root'); + } + return; +} + +sub open_log { + # Prepare log file and set permissions + open(my $log, ">>", "$log_file"); + close($log); + chmod(0440, $log_file); + chown($root_uid, $adm_gid, $log_file); + + return; +} + +sub create_pid { + # Create the PID object + $pid = File::Pid->new({ file => $pid_file }); + + # Write the PID file + $pid->write; + + return; } -# Prepare log file and set permissions -$root_uid = getpwnam('root'); -$adm_gid = getgrnam('adm'); -open(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"); + +# +#==== MAIN = main ============================================================== +# +# Parse options and allow '-vvv' +Getopt::Long::Configure( 'bundling' ); +GetOptions( 'v|verbose+' => \$verbose, + 'h|help' => \&usage, + 'c|config=s' => \$config, + 'x|dump-config=i' => \$dump_config, + 'f|foreground' => \$foreground, + 'd=s' => \$debug_parts) + or usage( '', 1 ); + +# We may want to dump the default configuration +if( defined $dump_config ) { + if($dump_config==1) { + } elsif ($dump_config==2) { + dump_configuration( $dump_config ); + } else { + usage( "Dump configuration value has to be 1 or 2" ); + } +} + +# read and set config parameters +&read_configfile($config, %cfg_defaults); + +# daemonize the program +&start_daemon($pid, $foreground); + +# create pid file +&create_pid($pid, $pid_file); + +# Determine root uid and adm gid, used for creating log files +&get_perms_admin($root_uid, $adm_gid); + +# put version +&put_version($server_status_hash, $server_version, $server_headURL, $server_revision, $server_status); + +#open log file +&open_log($root_uid, $adm_gid, $log_file); + +# prepare directory for databases +mkpath('/var/lib/gosa-si', 0, {owner=>'root', group=>'root', mode=> '0755'}); + +# remove leftover files in tmp for packaged.db populate +rmtree( '/tmp/packages_list_db',0,1); + +# remove list of sources from apt.sources.list +unlink '/tmp/gosa_si_tmp_sources_list'; + +# remove marker that the list creation is in progress +unlink '/tmp/packages_list_creation_in_progress'; daemon_log(" ", 1); daemon_log("$0 started!", 1); @@ -3532,102 +3658,78 @@ daemon_log($server_status_hash->{$server_status}.": $server_revision", 1); { no strict "refs"; - if ($db_module eq "DBmysql") { - - daemon_log("0 INFO: importing database module '$db_module'", 1); + daemon_log("0 INFO: importing database module '$db_module'", 1); + if ($db_module eq "DBmysql") { + # connect to incoming_db - $incoming_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password); + $incoming_db = ("GOsaSI::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password); # connect to gosa-si job queue - $job_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password); + $job_db = ("GOsaSI::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password); # connect to known_clients_db - $known_clients_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password); + $known_clients_db = ("GOsaSI::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password); # connect to foreign_clients_db - $foreign_clients_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password); + $foreign_clients_db = ("GOsaSI::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password); # connect to known_server_db - $known_server_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password); + $known_server_db = ("GOsaSI::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password); # connect to login_usr_db - $login_users_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password); + $login_users_db = ("GOsaSI::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password); # connect to fai_server_db - $fai_server_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password); + $fai_server_db = ("GOsaSI::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password); # connect to fai_release_db - $fai_release_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password); + $fai_release_db = ("GOsaSI::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password); # connect to packages_list_db - $packages_list_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password); + $packages_list_db = ("GOsaSI::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password); # connect to messaging_db - $messaging_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password); + $messaging_db = ("GOsaSI::".$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); + daemon_log("0 INFO: Removing SQLlite lock files", 1); + + # delete old DBsqlite lock files to be replace by rmtree !! + system('rm -f /var/lib/gosa-si/*.si.lock*'); + #rmtree( '/var/lib/gosa-si/',0,1); # connect to incoming_db unlink($incoming_file_name); - $incoming_db = GOSA::DBsqlite->new($incoming_file_name); - chmod(0640, $incoming_file_name); - chown($root_uid, $adm_gid, $incoming_file_name); - + $incoming_db = ("GOsaSI::".$db_module)->new($incoming_file_name); + # connect to gosa-si job queue - $job_db = GOSA::DBsqlite->new($job_queue_file_name); - chmod(0640, $job_queue_file_name); - chown($root_uid, $adm_gid, $job_queue_file_name); + $job_db = ("GOsaSI::".$db_module)->new($job_queue_file_name); # connect to known_clients_db - #unlink($known_clients_file_name); - $known_clients_db = GOSA::DBsqlite->new($known_clients_file_name); - chmod(0640, $known_clients_file_name); - chown($root_uid, $adm_gid, $known_clients_file_name); + $known_clients_db = ("GOsaSI::".$db_module)->new($known_clients_file_name); # connect to foreign_clients_db - #unlink($foreign_clients_file_name); - $foreign_clients_db = GOSA::DBsqlite->new($foreign_clients_file_name); - chmod(0640, $foreign_clients_file_name); - chown($root_uid, $adm_gid, $foreign_clients_file_name); + $foreign_clients_db = ("GOsaSI::".$db_module)->new($foreign_clients_file_name); # connect to known_server_db - unlink($known_server_file_name); # do not delete, gosa-si-server should be forced to check config file and dns at each start - $known_server_db = GOSA::DBsqlite->new($known_server_file_name); - chmod(0640, $known_server_file_name); - chown($root_uid, $adm_gid, $known_server_file_name); + $known_server_db = ("GOsaSI::".$db_module)->new($known_server_file_name); # connect to login_usr_db - #unlink($login_users_file_name); - $login_users_db = GOSA::DBsqlite->new($login_users_file_name); - chmod(0640, $login_users_file_name); - chown($root_uid, $adm_gid, $login_users_file_name); + $login_users_db = ("GOsaSI::".$db_module)->new($login_users_file_name); # connect to fai_server_db - unlink($fai_server_file_name); - $fai_server_db = GOSA::DBsqlite->new($fai_server_file_name); - chmod(0640, $fai_server_file_name); - chown($root_uid, $adm_gid, $fai_server_file_name); + $fai_server_db = ("GOsaSI::".$db_module)->new($fai_server_file_name); # connect to fai_release_db - unlink($fai_release_file_name); - $fai_release_db = GOSA::DBsqlite->new($fai_release_file_name); - chmod(0640, $fai_release_file_name); - chown($root_uid, $adm_gid, $fai_release_file_name); + $fai_release_db = ("GOsaSI::".$db_module)->new($fai_release_file_name); # connect to packages_list_db - unlink($packages_list_under_construction); - $packages_list_db = GOSA::DBsqlite->new($packages_list_file_name); - chmod(0640, $packages_list_file_name); - chown($root_uid, $adm_gid, $packages_list_file_name); + $packages_list_db = ("GOsaSI::".$db_module)->new($packages_list_file_name); # connect to messaging_db - #unlink($messaging_file_name); - $messaging_db = GOSA::DBsqlite->new($messaging_file_name); - chmod(0640, $messaging_file_name); - chown($root_uid, $adm_gid, $messaging_file_name); + $messaging_db = ("GOsaSI::".$db_module)->new($messaging_file_name); } } @@ -3678,6 +3780,7 @@ if ($opsi_enabled eq "true") { $opsi_client = new JSON::RPC::Client; } +daemon_log("0 INFO: start socket for incoming xml messages at port '$server_port' ", 1); POE::Component::Server::TCP->new( Alias => "TCP_SERVER", @@ -3713,14 +3816,12 @@ POE::Component::Server::TCP->new( } ); -daemon_log("0 INFO: start socket for incoming xml messages at port '$server_port' ", 1); - # create session for repeatedly checking the job queue for jobs POE::Session->create( inline_states => { - _start => \&session_start, + _start => \&session_start, register_at_foreign_servers => \®ister_at_foreign_servers, - control_server_registration => \&control_server_registration, + control_server_registration => \&control_server_registration, sig_handler => \&sig_handler, next_task => \&next_task, task_result => \&handle_task_result, @@ -3729,7 +3830,7 @@ POE::Session->create( watch_for_new_messages => \&watch_for_new_messages, watch_for_delivery_messages => \&watch_for_delivery_messages, watch_for_done_messages => \&watch_for_done_messages, - watch_for_new_jobs => \&watch_for_new_jobs, + watch_for_new_jobs => \&watch_for_new_jobs, watch_for_modified_jobs => \&watch_for_modified_jobs, watch_for_done_jobs => \&watch_for_done_jobs, watch_for_opsi_jobs => \&watch_for_opsi_jobs, @@ -3737,7 +3838,7 @@ POE::Session->create( create_packages_list_db => \&run_create_packages_list_db, create_fai_server_db => \&run_create_fai_server_db, create_fai_release_db => \&run_create_fai_release_db, - recreate_packages_db => \&run_recreate_packages_db, + recreate_packages_db => \&run_recreate_packages_db, session_run_result => \&session_run_result, session_run_debug => \&session_run_debug, session_run_done => \&session_run_done, diff --git a/gosa-si/gosa-si-server.1 b/gosa-si/gosa-si-server.1 index a097799b1..78e90100e 100644 --- a/gosa-si/gosa-si-server.1 +++ b/gosa-si/gosa-si-server.1 @@ -1,4 +1,4 @@ -.\" Automatically generated by Pod::Man 2.1801 (Pod::Simple 3.05) +.\" Automatically generated by Pod::Man 2.1801 (Pod::Simple 3.07) .\" .\" Standard preamble: .\" ======================================================================== @@ -124,7 +124,7 @@ .\" ======================================================================== .\" .IX Title "GOSA-SI-SERVER 1" -.TH GOSA-SI-SERVER 1 "2009-09-23" "perl v5.10.0" "User Contributed Perl Documentation" +.TH GOSA-SI-SERVER 1 "2010-05-17" "perl v5.10.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -133,7 +133,7 @@ gosa\-si\-server \-Support infrastructure for GOsa .SH "SYNOPSIS" .IX Header "SYNOPSIS" -gosa-si-server [\-hvf] [\-c config] +gosa-si-server [\-hvf] [\-c config] [\-x dump ] .SH "OPTIONS" .IX Header "OPTIONS" \&\fB\-h\fR, \fB\-\-help\fR @@ -171,6 +171,10 @@ gosa-si-server [\-hvf] [\-c config] \& 256 : creation of packages_list_db \& 512 : ARP debug information .Ve +.PP +\&\fB\-x\fR + dump configuration to stdout + ( 1 = current, 2 = default ) .SH "DESCRIPTION" .IX Header "DESCRIPTION" gosa-si-server belongs to the support infrastructure of GOsa. Several gosa-si-clients can connect to one gosa-si-server. The server take care of the message forwarding from GOsa to si-clients. At the client site each message is related to a working instruction which will be executed there. Depending of the message an answer from the client to GOsa via the server is possible. Additional to answers clients reporting events or information to the server. The server registers himself at other servers in network and shares his knowledge with them. So messages to clients which are no registrated locally will be forward to the client corresponding server. The communication within the complete \s-1SI\s0 nework is realised by \s-1XML\s0 messages. @@ -181,7 +185,7 @@ Please report any bugs, or post any suggestions, to the GOsa mailing list ) .PP -Copyright (C) 2003\-2009 \s-1GONICUS\s0 GmbH +Copyright (C) 2003\-2010 \s-1GONICUS\s0 GmbH .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 diff --git a/gosa-si/gosa-si-server.conf.5 b/gosa-si/gosa-si-server.conf.5 index 2d601f578..2c8d0c660 100644 --- a/gosa-si/gosa-si-server.conf.5 +++ b/gosa-si/gosa-si-server.conf.5 @@ -1,4 +1,4 @@ -.\" Automatically generated by Pod::Man 2.1801 (Pod::Simple 3.05) +.\" Automatically generated by Pod::Man 2.1801 (Pod::Simple 3.07) .\" .\" Standard preamble: .\" ======================================================================== @@ -124,7 +124,7 @@ .\" ======================================================================== .\" .IX Title "SERVER.CONF 1" -.TH SERVER.CONF 1 "2009-10-02" "perl v5.10.0" "User Contributed Perl Documentation" +.TH SERVER.CONF 1 "2010-05-17" "perl v5.10.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -136,15 +136,15 @@ gosa\-si\-server.conf \- Configuration file for gosa\-si\-server. The gosa\-si\-server.conf file defines all parameter GOsa-SI-server needs for running. It is normally located in the /etc/gosa\-si/ directory and is generated automatically by the \fIgosa\-si\-server\fR\|(1) program during installation. .SH "DIRECTIVES" .IX Header "DIRECTIVES" -.SS "[general]" -.IX Subsection "[general]" -.IP "logfile = /var/log/gosa\-si\-server.log" 4 -.IX Item "logfile = /var/log/gosa-si-server.log" +.SS "[General]" +.IX Subsection "[General]" +.IP "logfile = /var/log/gosa\-si/gosa\-si\-server.log" 4 +.IX Item "logfile = /var/log/gosa-si/gosa-si-server.log" Defines the location for the log file. -.IP "pid-file = /var/run/gosa\-si\-server.pid Defines the location for the pid file." 4 -.IX Item "pid-file = /var/run/gosa-si-server.pid Defines the location for the pid file." -.SS "[server]" -.IX Subsection "[server]" +.IP "pid-file = /var/run/gosa\-si/gosa\-si\-server.pid Defines the location for the pid file." 4 +.IX Item "pid-file = /var/run/gosa-si/gosa-si-server.pid Defines the location for the pid file." +.SS "[Server]" +.IX Subsection "[Server]" .PD 0 .IP "ip = 1.2.3.4" 4 .IX Item "ip = 1.2.3.4" @@ -183,8 +183,8 @@ Defines the location for the local \s-1DB\s0 'foreign_clients'. .IP "source-list = /etc/apt/sources.list" 4 .IX Item "source-list = /etc/apt/sources.list" Defines the location for the sources file. -.IP "repo-path = /srv/www/repository" 4 -.IX Item "repo-path = /srv/www/repository" +.IP "repo-path = /srv/www/" 4 +.IX Item "repo-path = /srv/www/" Defines the location of the dak Archive or local Debian Mirror and is scanned for Debian Packages. .IP "debian-arch = i386" 4 .IX Item "debian-arch = i386" @@ -258,7 +258,7 @@ the user is marked to be no longer logged in or the host is no longer running. .IX Subsection "[ServerPackages]" .IP "address =" 4 .IX Item "address =" -Comma seperated list of GOsa-si-servers (1.2.3.4:20081,9.8.7.6:123) in network where this SI-server should register. These given SI-servers extend the list of SI-servers found in \s-1DNS\s0. +Comma separated list of GOsa-si-servers (1.2.3.4:20081,9.8.7.6:123) in network where this SI-server should register. These given SI-servers extend the list of SI-servers found in \s-1DNS\s0. .IP "dns-lookup = true" 4 .IX Item "dns-lookup = true" Perform a \s-1DNS\s0 lookup for server registration @@ -273,7 +273,7 @@ Defines the password incoming ServerPackages messages should be encrypted. This Defines the lifetime in seconds of a GOsa-SI-server key. After expiring the key will be automatically renewed. .IP "job-synchronization-enabled = true" 4 .IX Item "job-synchronization-enabled = true" -Defines whether job queue informations are be shared with other GOsa-SI-server in network. +Defines whether job queue information are be shared with other GOsa-SI-server in network. .IP "synchronization-loog = 5" 4 .IX Item "synchronization-loog = 5" Defines in seconds after which time the job queue synchronization is being done. @@ -289,7 +289,7 @@ Space\- or comma-separated list of interfaces on which to start an ARP-Daemon. E .IX Subsection "[Opsi]" .IP "enabled = false" 4 .IX Item "enabled = false" -Defines wheter Opsi integration is being enabled or not. +Defines whether Opsi integration is being enabled or not. .IP "server = localhost" 4 .IX Item "server = localhost" Define the hostname of the Opsi server @@ -306,7 +306,7 @@ Please report any bugs, or post any suggestions, to the GOsa mailing list ) .PP -Copyright (C) 2003\-2009 \s-1GONICUS\s0 GmbH +Copyright (C) 2003\-2010 \s-1GONICUS\s0 GmbH .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 diff --git a/gosa-si/gosa-si-server.pod b/gosa-si/gosa-si-server.pod deleted file mode 100644 index e4ceb6777..000000000 --- a/gosa-si/gosa-si-server.pod +++ /dev/null @@ -1,71 +0,0 @@ - -=head1 NAME - -gosa-si-server -Support infrastructure for GOsa - -=head1 SYNOPSIS - -gosa-si-server [-hvf] [-c config] - -=head1 OPTIONS - -B<-h>, B<--help> - print out this help message - -B<-v>, B<--verbose> - be verbose (multiple v's will increase verbosity) - -v ERROR level - -vvv WARNING + ERROR level - -vvvvv INFO + WARNING level - -vvvvvvv DEBUG + INFO level - -vvvvvvvvv in and out going xml messages will be displayed - -B<-f>, B<--foreground> - foregroud, process will not be forked to background - -B<-c> I, B<--config=>I - configuration file, default F - -B<--no-arp> - starts script without connection to arp module - -B<-d> - if verbose level is higher than 7 '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 - 16 : message processing - 32 : ldap connectivity - 64 : database status and connectivity - 128 : main process - 256 : creation of packages_list_db - 512 : ARP debug information - - -=head1 DESCRIPTION - -gosa-si-server belongs to the support infrastructure of GOsa. Several gosa-si-clients can connect to one gosa-si-server. The server take care of the message forwarding from GOsa to si-clients. At the client site each message is related to a working instruction which will be executed there. Depending of the message an answer from the client to GOsa via the server is possible. Additional to answers clients reporting events or information to the server. The server registers himself at other servers in network and shares his knowledge with them. So messages to clients which are no registrated locally will be forward to the client corresponding server. The communication within the complete SI nework is realised by XML messages. - - -=head1 BUGS - -Please report any bugs, or post any suggestions, to the GOsa mailing list or to - - -=head1 LICENCE AND COPYRIGHT - -This code is part of GOsa (L) - -Copyright (C) 2003-2009 GONICUS GmbH - -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. - -=cut - - - diff --git a/gosa-si/modules/ArpHandler.pm b/gosa-si/modules/ArpHandler.pm index 210e95654..408d80ac6 100644 --- a/gosa-si/modules/ArpHandler.pm +++ b/gosa-si/modules/ArpHandler.pm @@ -1,21 +1,23 @@ package ArpHandler; -use Exporter; -@ISA = ("Exporter"); - use strict; use warnings; -use GOSA::GosaSupportDaemon; -use POSIX; -use Fcntl; + use Net::LDAP; use Net::LDAP::LDIF; use Net::LDAP::Entry; use Net::DNS; use Switch; use Data::Dumper; +use GOsaSI::GosaSupportDaemon; + +use Exporter; +use POSIX; +use Fcntl; use Socket; +our @ISA = ("Exporter"); + # Don't start if some of the modules are missing my $start_service=1; my $lookup_vendor=1; @@ -53,6 +55,7 @@ my %cfg_defaults = }, ); +# to be removed use only main::read_configfile #=== FUNCTION ================================================================ # NAME: read_configfile # PARAMETERS: cfg_file - string - @@ -85,6 +88,7 @@ sub get_module_info { # Don't start if some of the modules are missing if(($arp_enabled eq 'true') && $start_service) { if($lookup_vendor) { + # put the file in /etc/gosa/oui.txt or use the native oui.txt from snmp eval("Net::MAC::Vendor::load_cache('file:///usr/lib/gosa-si/modules/oui.txt')"); if($@) { &main::daemon_log("Loading OUI cache file failed! MAC Vendor lookup disabled", 1); @@ -234,7 +238,7 @@ sub get_host_from_ldap { my $mac=shift; my $result={}; - my $ldap_handle = &main::get_ldap_handle(); + my $ldap_handle = &main::get_ldap_handle(); if(defined($ldap_handle)) { my $ldap_result= &search_ldap_entry( $ldap_handle, diff --git a/gosa-si/modules/ClientPackages.pm b/gosa-si/modules/ClientPackages.pm index fb8aab830..ad94ee2f0 100644 --- a/gosa-si/modules/ClientPackages.pm +++ b/gosa-si/modules/ClientPackages.pm @@ -1,13 +1,10 @@ package ClientPackages; -use Exporter; -@ISA = ("Exporter"); - # Each module has to have a function 'process_incoming_msg'. This function works as a interface to gosa-sd and receives the msg hash from gosa-sd. 'process_incoming_function checks, wether it has a function to process the incoming msg and forward the msg to it. use strict; use warnings; -use GOSA::GosaSupportDaemon; + use IO::Socket::INET; use XML::Simple; use Data::Dumper; @@ -16,6 +13,11 @@ use Net::LDAP; use Net::LDAP::Util; use Socket; use Net::hostent; +use GOsaSI::GosaSupportDaemon; + +use Exporter; + +our @ISA = ("Exporter"); my $event_dir = "/usr/lib/gosa-si/server/ClientPackages"; use lib "/usr/lib/gosa-si/server/ClientPackages"; @@ -30,7 +32,7 @@ my (@ldap_cfg, @pam_cfg, @nss_cfg, $goto_admin, $goto_secret); my $mesg; my %cfg_defaults = ( -"server" => { +"Server" => { "ip" => [\$server_ip, "0.0.0.0"], "mac-address" => [\$main::server_mac_address, "00:00:00:00:00"], "port" => [\$server_port, "20081"], @@ -48,6 +50,7 @@ my %cfg_defaults = ( ### START ##################################################################### # read configfile and import variables +#why not using the main::read_configfile !! &local_read_configfile(); @@ -451,9 +454,9 @@ sub here_i_am { if ( defined($msg_hash->{'force-hostname'}[0]) && length($msg_hash->{'force-hostname'}[0]) > 0){ # $heap->{force-hostname}->{$mac_address}= $msg_hash->{'force-hostname'}[0]; - open (TFILE, ">/var/tmp/$mac_address"); - print TFILE $msg_hash->{'force-hostname'}[0]; - close (TFILE); + open (my $TFILE, ">", "/var/tmp/$mac_address"); + print $TFILE $msg_hash->{'force-hostname'}[0]; + close ($TFILE); } else { # $heap->{force-hostname}->{$mac_address}= undef; if ( -e "/var/tmp/$mac_address") { @@ -563,7 +566,7 @@ sub here_i_am { if($ldap_res->code) { &main::daemon_log("$session_id ERROR: LDAP Entry for client with mac address $mac_address not found: ".$ldap_res->error, 1); } elsif ($ldap_res->count != 1) { - &main::daemon_log("$session_id ERROR: client with mac address $mac_address not found/unique/active - not updating ldap entry". + &main::daemon_log("$session_id WARNING: client with mac address $mac_address not found/unique/active - not updating ldap entry". "\n\tbase: $ldap_base". "\n\tscope: sub". "\n\tattrs: ipHostNumber". @@ -663,7 +666,7 @@ sub new_syslog_config { # Sanity check if ($ldap_res->count != 1) { - &main::daemon_log("$session_id ERROR: client with mac address $mac_address not found/unique/active - not sending syslog config". + &main::daemon_log("$session_id WARNING: client with mac address $mac_address not found/unique/active - not sending syslog config". "\n\tbase: $ldap_base". "\n\tscope: sub". "\n\tattrs: gotoSyslogServer". @@ -879,7 +882,7 @@ sub new_ldap_config { # Sanity check if ($mesg->count != 1) { - &main::daemon_log("$session_id ERROR: new_ldap_config: client with mac address $macaddress not found/unique/active - not sending ldap config". + &main::daemon_log("$session_id WARNING: new_ldap_config: client with mac address $macaddress not found/unique/active - not sending ldap config". "\n\tbase: $ldap_base". "\n\tscope: sub". "\n\tattrs: dn, gotoLdapServer, FAIclass". @@ -1081,12 +1084,12 @@ sub server_matches { } else { my $PROC_NET_ROUTE= ('/proc/net/route'); - open(PROC_NET_ROUTE, "<$PROC_NET_ROUTE") + open(my $FD_PROC_NET_ROUTE, "<", "$PROC_NET_ROUTE") or die "Could not open $PROC_NET_ROUTE"; - my @ifs = ; + my @ifs = <$FD_PROC_NET_ROUTE>; - close(PROC_NET_ROUTE); + close($FD_PROC_NET_ROUTE); # Eat header line shift @ifs; diff --git a/gosa-si/modules/DBsqlite.pm b/gosa-si/modules/DBsqlite.pm index 9f0b12b4a..8e3784df7 100644 --- a/gosa-si/modules/DBsqlite.pm +++ b/gosa-si/modules/DBsqlite.pm @@ -1,13 +1,16 @@ -package GOSA::DBsqlite; +package GOsaSI::DBsqlite; use strict; use warnings; -use Carp; -use DBI; -use GOSA::GosaSupportDaemon; + + use Time::HiRes qw(usleep); use Data::Dumper; +use GOsaSI::GosaSupportDaemon; + use Fcntl qw/:DEFAULT :flock/; # import LOCK_* constants +use Carp; +use DBI; our $col_names = {}; @@ -42,8 +45,8 @@ sub new { sub connect { my $self = shift; - if(not defined($self) or ref($self) ne 'GOSA::DBsqlite') { - &main::daemon_log("0 ERROR: GOSA::DBsqlite::connect was called static! Argument was '$self'!", 1); + if(not defined($self) or ref($self) ne 'GOsaSI::DBsqlite') { + &main::daemon_log("0 ERROR: GOsaSI::DBsqlite::connect was called static! Argument was '$self'!", 1); return; } @@ -56,8 +59,8 @@ sub connect { sub disconnect { my $self = shift; - if(not defined($self) or ref($self) ne 'GOSA::DBsqlite') { - &main::daemon_log("0 ERROR: GOSA::DBsqlite::disconnect was called static! Argument was '$self'!", 1); + if(not defined($self) or ref($self) ne 'GOsaSI::DBsqlite') { + &main::daemon_log("0 ERROR: GOsaSI::DBsqlite::disconnect was called static! Argument was '$self'!", 1); return; } @@ -76,8 +79,8 @@ sub disconnect { sub lock { my $self = shift; - if(not defined($self) or ref($self) ne 'GOSA::DBsqlite') { - &main::daemon_log("0 ERROR: GOSA::DBsqlite::lock was called static! Argument was '$self'!", 1); + if(not defined($self) or ref($self) ne 'GOsaSI::DBsqlite') { + &main::daemon_log("0 ERROR: GOsaSI::DBsqlite::lock was called static! Argument was '$self'!", 1); return; } @@ -101,8 +104,8 @@ get_lock: sub unlock { my $self = shift; - if(not defined($self) or ref($self) ne 'GOSA::DBsqlite') { - &main::daemon_log("0 ERROR: GOSA::DBsqlite::unlock was called static! Argument was '$self'!", 1); + if(not defined($self) or ref($self) ne 'GOsaSI::DBsqlite') { + &main::daemon_log("0 ERROR: GOsaSI::DBsqlite::unlock was called static! Argument was '$self'!", 1); return; } if(not ref $self->{db_lock_handle}) { @@ -117,8 +120,8 @@ sub unlock { sub create_table { my $self = shift; - if(not defined($self) or ref($self) ne 'GOSA::DBsqlite') { - &main::daemon_log("0 ERROR: GOSA::DBsqlite::create_table was called static! Statement was '$self'!", 1); + if(not defined($self) or ref($self) ne 'GOsaSI::DBsqlite') { + &main::daemon_log("0 ERROR: GOsaSI::DBsqlite::create_table was called static! Statement was '$self'!", 1); return; } my $table_name = shift; @@ -325,8 +328,8 @@ sub add_dbentry { sub update_dbentry { my ($self, $sql)= @_; - if(not defined($self) or ref($self) ne 'GOSA::DBsqlite') { - &main::daemon_log("0 ERROR: GOSA::DBsqlite::update_dbentry was called static! Statement was '$self'!", 1); + if(not defined($self) or ref($self) ne 'GOsaSI::DBsqlite') { + &main::daemon_log("0 ERROR: GOsaSI::DBsqlite::update_dbentry was called static! Statement was '$self'!", 1); return; } my $db_answer= $self->exec_statement($sql); @@ -336,8 +339,8 @@ sub update_dbentry { sub del_dbentry { my ($self, $sql)= @_;; - if(not defined($self) or ref($self) ne 'GOSA::DBsqlite') { - &main::daemon_log("0 ERROR: GOSA::DBsqlite::del_dbentry was called static! Statement was '$self'!", 1); + if(not defined($self) or ref($self) ne 'GOsaSI::DBsqlite') { + &main::daemon_log("0 ERROR: GOsaSI::DBsqlite::del_dbentry was called static! Statement was '$self'!", 1); return; } my $db_res= $self->exec_statement($sql); @@ -347,8 +350,8 @@ sub del_dbentry { sub get_table_columns { my $self = shift; - if(not defined($self) or ref($self) ne 'GOSA::DBsqlite') { - &main::daemon_log("0 ERROR: GOSA::DBsqlite::get_table_columns was called static! Statement was '$self'!", 1); + if(not defined($self) or ref($self) ne 'GOsaSI::DBsqlite') { + &main::daemon_log("0 ERROR: GOsaSI::DBsqlite::get_table_columns was called static! Statement was '$self'!", 1); return; } my $table = shift; @@ -371,8 +374,8 @@ sub get_table_columns { sub select_dbentry { my ($self, $sql)= @_; - if(not defined($self) or ref($self) ne 'GOSA::DBsqlite') { - &main::daemon_log("0 ERROR: GOSA::DBsqlite::select_dbentry was called static! Statement was '$self'!", 1); + if(not defined($self) or ref($self) ne 'GOsaSI::DBsqlite') { + &main::daemon_log("0 ERROR: GOsaSI::DBsqlite::select_dbentry was called static! Statement was '$self'!", 1); return; } my $error= 0; @@ -412,8 +415,8 @@ sub select_dbentry { sub show_table { my $self = shift; - if(not defined($self) or ref($self) ne 'GOSA::DBsqlite') { - &main::daemon_log("0 ERROR: GOSA::DBsqlite::show_table was called static! Statement was '$self'!", 1); + if(not defined($self) or ref($self) ne 'GOsaSI::DBsqlite') { + &main::daemon_log("0 ERROR: GOsaSI::DBsqlite::show_table was called static! Statement was '$self'!", 1); return; } my $table_name = shift; @@ -432,13 +435,13 @@ sub show_table { sub exec_statement { my $self = shift; my $sql_statement = shift; - if(not defined($self) or ref($self) ne 'GOSA::DBsqlite') { - &main::daemon_log("0 ERROR: GOSA::DBsqlite::exec_statement was called static! Statement was '$self'!", 1); + if(not defined($self) or ref($self) ne 'GOsaSI::DBsqlite') { + &main::daemon_log("0 ERROR: GOsaSI::DBsqlite::exec_statement was called static! Statement was '$self'!", 1); return; } if(not defined($sql_statement) or length($sql_statement) == 0) { - &main::daemon_log("0 ERROR: GOSA::DBsqlite::exec_statement was called with empty statement!", 1); + &main::daemon_log("0 ERROR: GOsaSI::DBsqlite::exec_statement was called with empty statement!", 1); return; } @@ -518,8 +521,8 @@ sub exec_statement { sub exec_statementlist { my $self = shift; my $sql_list = shift; - if(not defined($self) or ref($self) ne 'GOSA::DBsqlite') { - &main::daemon_log("0 ERROR: GOSA::DBsqlite::exec_statementlist was called static!", 1); + if(not defined($self) or ref($self) ne 'GOsaSI::DBsqlite') { + &main::daemon_log("0 ERROR: GOsaSI::DBsqlite::exec_statementlist was called static!", 1); return; } my @db_answer; @@ -538,8 +541,8 @@ sub exec_statementlist { sub count_dbentries { my ($self, $table)= @_; - if(not defined($self) or ref($self) ne 'GOSA::DBsqlite') { - &main::daemon_log("0 ERROR: GOSA::DBsqlite::count_dbentries was called static!", 1); + if(not defined($self) or ref($self) ne 'GOsaSI::DBsqlite') { + &main::daemon_log("0 ERROR: GOsaSI::DBsqlite::count_dbentries was called static!", 1); return; } my $error= 0; @@ -557,8 +560,8 @@ sub count_dbentries { sub move_table { my ($self, $from, $to) = @_; - if(not defined($self) or ref($self) ne 'GOSA::DBsqlite') { - &main::daemon_log("0 ERROR: GOSA::DBsqlite::move_table was called static!", 1); + if(not defined($self) or ref($self) ne 'GOsaSI::DBsqlite') { + &main::daemon_log("0 ERROR: GOsaSI::DBsqlite::move_table was called static!", 1); return; } @@ -625,11 +628,11 @@ sub move_table { }; if($@) { $self->{dbh}->rollback(); - &main::daemon_log("0 ERROR: GOSA::DBsqlite::move_table crashed! Operation failed with $@", 1); + &main::daemon_log("0 ERROR: GOsaSI::DBsqlite::move_table crashed! Operation failed with $@", 1); } } - &main::daemon_log("0 INFO: GOSA::DBsqlite::move_table: Operation successful!", 7); + &main::daemon_log("0 INFO: GOsaSI::DBsqlite::move_table: Operation successful!", 7); $self->unlock(); return; diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index 835eaa520..c18472eb8 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -1,17 +1,19 @@ package GosaPackages; -use Exporter; -@ISA = ("Exporter"); - use strict; use warnings; -use GOSA::GosaSupportDaemon; + +use Exporter; +use GOsaSI::GosaSupportDaemon; use IO::Socket::INET; use Socket; use XML::Simple; use File::Spec; use Data::Dumper; use MIME::Base64; +use Net::ARP; + +our @ISA = ("Exporter"); my $event_dir = "/usr/lib/gosa-si/server/GosaPackages"; use lib "/usr/lib/gosa-si/server/GosaPackages"; @@ -73,29 +75,16 @@ sub get_module_info { sub get_mac { my $ifreq= shift; my $result; - if ($ifreq && length($ifreq) > 0) { + if ($ifreq && length($ifreq) > 0) { if($ifreq eq "all") { $result = "00:00:00:00:00:00"; } else { - my $SIOCGIFHWADDR= 0x8927; # man 2 ioctl_list - # A configured MAC Address should always override a guessed value if ($gosa_mac_address and length($gosa_mac_address) > 0) { $result= $gosa_mac_address; } - socket SOCKET, PF_INET, SOCK_DGRAM, getprotobyname('ip') - or die "socket: $!"; - - if(ioctl SOCKET, $SIOCGIFHWADDR, $ifreq) { - my ($if, $mac)= unpack 'h36 H12', $ifreq; - - if (length($mac) > 0) { - $mac=~ m/^([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/; - $mac= sprintf("%s:%s:%s:%s:%s:%s", $1, $2, $3, $4, $5, $6); - $result = $mac; - } - } + $result = Net::ARP::get_mac($ifreq); } } return $result; diff --git a/gosa-si/modules/GosaSupportDaemon.pm b/gosa-si/modules/GosaSupportDaemon.pm index 7d769c08a..651bd57d7 100644 --- a/gosa-si/modules/GosaSupportDaemon.pm +++ b/gosa-si/modules/GosaSupportDaemon.pm @@ -1,12 +1,28 @@ -package GOSA::GosaSupportDaemon; +package GOsaSI::GosaSupportDaemon; +use strict; +use warnings; + +use IO::Socket::INET; +use Crypt::Rijndael; +use Digest::MD5 qw(md5 md5_hex md5_base64); +use MIME::Base64; +use XML::Quote qw(:all); +use XML::Simple; +use Data::Dumper; +use Net::DNS; +use Net::ARP; + +use DateTime; use Exporter; -@ISA = qw(Exporter); + +our @ISA = qw(Exporter); + my @functions = ( "create_passwd", "create_xml_hash", - "createXmlHash", - "myXmlHashToString", + "createXmlHash", + "myXmlHashToString", "get_content_from_xml_hash", "add_content2xml_hash", "create_xml_string", @@ -38,19 +54,9 @@ my @functions = ( "check_opsi_res", "calc_timestamp", "opsi_callobj2string", - ); -@EXPORT = @functions; -use strict; -use warnings; -use IO::Socket::INET; -use Crypt::Rijndael; -use Digest::MD5 qw(md5 md5_hex md5_base64); -use MIME::Base64; -use XML::Quote qw(:all); -use XML::Simple; -use Data::Dumper; -use Net::DNS; -use DateTime; + ); + +our @EXPORT = @functions; my $op_hash = { 'eq' => '=', @@ -509,8 +515,8 @@ sub get_orderby_statement { sub get_dns_domains() { my $line; my @searches; - open(RESOLV, "){ + open(my $RESOLV, "<", "/etc/resolv.conf") or return @searches; + while(<$RESOLV>){ $line= $_; chomp $line; $line =~ s/^\s+//; @@ -522,7 +528,7 @@ sub get_dns_domains() { push(@searches, split(/ /, $1)); } } - close(RESOLV); + close($RESOLV); my %tmp = map { $_ => 1 } @searches; @searches = sort keys %tmp; @@ -722,12 +728,12 @@ sub get_interfaces { my @result; my $PROC_NET_DEV= ('/proc/net/dev'); - open(PROC_NET_DEV, "<$PROC_NET_DEV") + open(my $FD_PROC_NET_DEV, "<", "$PROC_NET_DEV") or die "Could not open $PROC_NET_DEV"; - my @ifs = ; + my @ifs = <$FD_PROC_NET_DEV>; - close(PROC_NET_DEV); + close($FD_PROC_NET_DEV); # Eat first two line shift @ifs; @@ -750,12 +756,12 @@ sub get_local_ip_for_remote_ip { if($remote_ip =~ /^(\d\d?\d?\.){3}\d\d?\d?$/) { my $PROC_NET_ROUTE= ('/proc/net/route'); - open(PROC_NET_ROUTE, "<$PROC_NET_ROUTE") + open(my $FD_PROC_NET_ROUTE, "<", "$PROC_NET_ROUTE") or die "Could not open $PROC_NET_ROUTE"; - my @ifs = ; + my @ifs = <$FD_PROC_NET_ROUTE>; - close(PROC_NET_ROUTE); + close($FD_PROC_NET_ROUTE); # Eat header line shift @ifs; @@ -802,29 +808,11 @@ sub get_local_ip_for_remote_ip { sub get_mac_for_interface { my $ifreq= shift; my $result; - if ($ifreq && length($ifreq) > 0) { + if ($ifreq && length($ifreq) > 0) { if($ifreq eq "all") { $result = "00:00:00:00:00:00"; } else { - my $SIOCGIFHWADDR= 0x8927; # man 2 ioctl_list - - # A configured MAC Address should always override a guessed value - if ($main::server_mac_address and length($main::server_mac_address) > 0) { - $result= $main::server_mac_address; - } - - socket SOCKET, PF_INET, SOCK_DGRAM, getprotobyname('ip') - or die "socket: $!"; - - if(ioctl SOCKET, $SIOCGIFHWADDR, $ifreq) { - my ($if, $mac)= unpack 'h36 H12', $ifreq; - - if (length($mac) > 0) { - $mac=~ m/^([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/; - $mac= sprintf("%s:%s:%s:%s:%s:%s", $1, $2, $3, $4, $5, $6); - $result = $mac; - } - } + $result = Net::ARP::get_mac($ifreq); } } return $result; @@ -872,10 +860,10 @@ sub run_as { &main::daemon_log("ERROR: The sudo utility is not available! Please fix this!"); } my $cmd_line= "$sudo_cmd su - $uid -c '$command'"; - open(PIPE, "$cmd_line |"); + open(my $PIPE, "$cmd_line |"); my $result = {'command' => $cmd_line}; - push @{$result->{'output'}}, ; - close(PIPE); + push @{$result->{'output'}}, <$PIPE>; + close($PIPE); my $exit_value = $? >> 8; $result->{'resultCode'} = $exit_value; return $result; diff --git a/gosa-si/modules/ServerPackages.pm b/gosa-si/modules/ServerPackages.pm index b008d01a9..bf4ac091b 100644 --- a/gosa-si/modules/ServerPackages.pm +++ b/gosa-si/modules/ServerPackages.pm @@ -1,14 +1,18 @@ package ServerPackages; -use Exporter; -@ISA = ("Exporter"); + # Each module has to have a function 'process_incoming_msg'. This function works as a interface to gosa-sd and receives the msg hash from gosa-sd. 'process_incoming_function checks, wether it has a function to process the incoming msg and forward the msg to it. use strict; use warnings; -use GOSA::GosaSupportDaemon; + use Data::Dumper; +use GOsaSI::GosaSupportDaemon; + +use Exporter; + +our @ISA = ("Exporter"); my $event_dir = "/usr/lib/gosa-si/server/ServerPackages"; use lib "/usr/lib/gosa-si/server/ServerPackages"; diff --git a/gosa-si/modules/TestModule.pm b/gosa-si/modules/TestModule.pm index 90c8d6abb..c920d413d 100644 --- a/gosa-si/modules/TestModule.pm +++ b/gosa-si/modules/TestModule.pm @@ -1,11 +1,14 @@ package TestModule; -use Exporter; -@ISA = ("Exporter"); use strict; use warnings; -use GosaSupportDaemon; + +use GOsaSI::GOsaSupportDaemon; + +use Exporter; + +our @ISA = ("Exporter"); BEGIN{ } diff --git a/gosa-si/server.conf b/gosa-si/server.conf index c4c0a3712..554ac444c 100644 --- a/gosa-si/server.conf +++ b/gosa-si/server.conf @@ -1,8 +1,8 @@ -[general] -log-file = /var/log/gosa-si-server.log -pid-file = /var/run/gosa-si-server.pid +[General] +log-file = /var/log/gosa-si/gosa-si-server.log +pid-file = /var/run/gosa-si/gosa-si-server.pid -[server] +[Server] max-clients = 100 ldap-uri = ldap://127.0.0.1 ldap-base = dc=your,dc=domain diff --git a/gosa-si/server.conf.pod b/gosa-si/server.conf.pod index 2ad848e68..a708d94b4 100644 --- a/gosa-si/server.conf.pod +++ b/gosa-si/server.conf.pod @@ -11,21 +11,21 @@ The gosa-si-server.conf file defines all parameter GOsa-SI-server needs for runn =head1 DIRECTIVES -=head2 [general] +=head2 [General] =over 4 -=item logfile = /var/log/gosa-si-server.log +=item logfile = /var/log/gosa-si/gosa-si-server.log Defines the location for the log file. -=item pid-file = /var/run/gosa-si-server.pid +=item pid-file = /var/run/gosa-si/gosa-si-server.pid Defines the location for the pid file. =back -=head2 [server] +=head2 [Server] =over 4 @@ -77,7 +77,7 @@ Defines the location for the local DB 'foreign_clients'. Defines the location for the sources file. -=item repo-path = /srv/www/repository +=item repo-path = /srv/www/ Defines the location of the dak Archive or local Debian Mirror and is scanned for Debian Packages. @@ -188,7 +188,7 @@ the user is marked to be no longer logged in or the host is no longer running. =item address = -Comma seperated list of GOsa-si-servers (1.2.3.4:20081,9.8.7.6:123) in network where this SI-server should register. These given SI-servers extend the list of SI-servers found in DNS. +Comma separated list of GOsa-si-servers (1.2.3.4:20081,9.8.7.6:123) in network where this SI-server should register. These given SI-servers extend the list of SI-servers found in DNS. =item dns-lookup = true @@ -208,7 +208,7 @@ Defines the lifetime in seconds of a GOsa-SI-server key. After expiring the key =item job-synchronization-enabled = true -Defines whether job queue informations are be shared with other GOsa-SI-server in network. +Defines whether job queue information are be shared with other GOsa-SI-server in network. =item synchronization-loog = 5 @@ -237,7 +237,7 @@ Space- or comma-separated list of interfaces on which to start an ARP-Daemon. En =item enabled = false -Defines wheter Opsi integration is being enabled or not. +Defines whether Opsi integration is being enabled or not. =item server = localhost @@ -262,7 +262,7 @@ Please report any bugs, or post any suggestions, to the GOsa mailing list ) -Copyright (C) 2003-2009 GONICUS GmbH +Copyright (C) 2003-2010 GONICUS GmbH This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of diff --git a/gosa-si/server/events/clMessages.pm b/gosa-si/server/events/clMessages.pm index 6c1e05460..dc57144ea 100644 --- a/gosa-si/server/events/clMessages.pm +++ b/gosa-si/server/events/clMessages.pm @@ -3,8 +3,19 @@ # @details A GOsa-SI event module containing all functions to handle incoming messages from clients. package clMessages; + + +use strict; +use warnings; + +use Data::Dumper; +use MIME::Base64; +use GOsaSI::GosaSupportDaemon; + use Exporter; -@ISA = qw(Exporter); + +our @ISA = qw(Exporter); + my @events = ( "confirm_usr_msg", "PROGRESS", @@ -20,14 +31,7 @@ my @events = ( "CURRENTLY_LOGGED_IN", "save_fai_log", ); -@EXPORT = @events; - -use strict; -use warnings; -use Data::Dumper; -use GOSA::GosaSupportDaemon; -use MIME::Base64; - +our @EXPORT = @events; BEGIN {} @@ -101,7 +105,7 @@ sub save_fai_log { my ($log_file, $log_string) = split(":", $log); my $client_fai_log_file = File::Spec->catfile( $client_fai_log_dir, $log_file); - open(my $LOG_FILE, ">$client_fai_log_file"); + open(my $LOG_FILE, ">", "$client_fai_log_file"); print $LOG_FILE &decode_base64($log_string); close($LOG_FILE); chown($main::root_uid, $main::adm_gid, $client_fai_log_file); @@ -333,7 +337,7 @@ sub set_last_system { ); # Sanity check of user search if ($ldap_mesg->count == 0) { - &main::daemon_log("$session_id ERROR: no user with uid='$user' was found in base '". + &main::daemon_log("$session_id WARNING: no user with uid='$user' was found in base '". $main::ldap_base."', setting of 'gotoLastSystem' and 'gotoLastSystemLogin' stopped!", 1); # Set gotoLastSystem and gotoLastSystemLogin diff --git a/gosa-si/server/events/databases.pm b/gosa-si/server/events/databases.pm index 881ebb820..796e97f3d 100644 --- a/gosa-si/server/events/databases.pm +++ b/gosa-si/server/events/databases.pm @@ -1,6 +1,15 @@ package databases; + +use strict; +use warnings; + +use Data::Dumper; +use GOsaSI::GosaSupportDaemon; + use Exporter; -@ISA = qw(Exporter); + +our @ISA = qw(Exporter); + my @events = ( "get_events", "query_jobdb", @@ -15,12 +24,8 @@ my @events = ( "query_fai_release", "count_fai_release", ); -@EXPORT = @events; -use strict; -use warnings; -use GOSA::GosaSupportDaemon; -use Data::Dumper; +our @EXPORT = @events; BEGIN {} @@ -28,8 +33,6 @@ END {} ### Start ###################################################################### -#&main::read_configfile($main::cfg_file, %cfg_defaults); - sub get_events { return \@events; } diff --git a/gosa-si/server/events/gosaTriggered.pm b/gosa-si/server/events/gosaTriggered.pm index 2a54b86e0..f014ad124 100644 --- a/gosa-si/server/events/gosaTriggered.pm +++ b/gosa-si/server/events/gosaTriggered.pm @@ -3,8 +3,23 @@ # @brief Implementation of a GOsa-SI event module. package gosaTriggered; + +use strict; +use warnings; + +use Crypt::SmbHash; +use Net::ARP; +use Net::Ping; +use Time::HiRes qw( usleep); +use MIME::Base64; +use Data::Dumper; +use GOsaSI::GosaSupportDaemon; + use Exporter; -@ISA = qw(Exporter); +use Socket; + +our @ISA = qw(Exporter); + my @events = ( "get_events", "get_login_usr_for_client", @@ -34,21 +49,11 @@ my @events = ( "recreate_packages_list_db", "send_user_msg", "get_available_kernel", - "trigger_activate_new", + "trigger_activate_new", "get_hosts_with_module", ); -@EXPORT = @events; - -use strict; -use warnings; -use GOSA::GosaSupportDaemon; -use Crypt::SmbHash; -use Net::ARP; -use Net::Ping; -use Socket; -use Time::HiRes qw( usleep); -use MIME::Base64; -use Data::Dumper; + +our @EXPORT = @events; BEGIN {} diff --git a/gosa-si/server/events/logHandling.pm b/gosa-si/server/events/logHandling.pm index 9fdce81d0..9e1f38cd9 100644 --- a/gosa-si/server/events/logHandling.pm +++ b/gosa-si/server/events/logHandling.pm @@ -1,6 +1,18 @@ package logHandling; + + +use strict; +use warnings; + +use Data::Dumper; +use File::Spec; +use MIME::Base64; +use GOsaSI::GosaSupportDaemon; + use Exporter; -@ISA = qw(Exporter); + +our @ISA = qw(Exporter); + my @events = ( "get_events", "show_log_by_mac", @@ -11,14 +23,8 @@ my @events = ( "get_recent_log_by_mac", "delete_log_by_date_and_mac", ); -@EXPORT = @events; -use strict; -use warnings; -use GOSA::GosaSupportDaemon; -use Data::Dumper; -use File::Spec; -use MIME::Base64; +our @EXPORT = @events; BEGIN {} @@ -301,9 +307,9 @@ sub get_log_file_by_date_and_mac { # read log file my $log_content; - open(FILE, "<$act_log_file"); - my @log_lines = ; - close(FILE); + open(my $FILE, "<$act_log_file"); + my @log_lines = <$FILE>; + close($FILE); # prepare content for xml sending $log_content = join("", @log_lines); diff --git a/gosa-si/server/events/mailqueue_com.pm b/gosa-si/server/events/mailqueue_com.pm index 87642ebd0..63d8d0c93 100644 --- a/gosa-si/server/events/mailqueue_com.pm +++ b/gosa-si/server/events/mailqueue_com.pm @@ -21,22 +21,26 @@ be automatically imported by GOsa-SI if it is under Fexec_statement($sql_statement); } @@ -170,7 +174,7 @@ sub mailqueue_header { my ($sql, $res); if( defined $jobdb_id) { - my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id"; + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=$jobdb_id"; &main::daemon_log("$session_id DEBUG: $sql_statement", 7); my $res = $main::job_db->exec_statement($sql_statement); } diff --git a/gosa-si/server/events/opsi_com.pm b/gosa-si/server/events/opsi_com.pm index 1c67f577e..2c3698147 100644 --- a/gosa-si/server/events/opsi_com.pm +++ b/gosa-si/server/events/opsi_com.pm @@ -4,10 +4,19 @@ package opsi_com; + +use strict; +use warnings; + +use Data::Dumper; +use XML::Quote qw(:all); +use GOsaSI::GosaSupportDaemon; + use Exporter; use UNIVERSAL 'isa'; -@ISA = qw(Exporter); +our @ISA = qw(Exporter); + my @events = ( "get_events", "opsi_install_client", @@ -44,13 +53,9 @@ my @events = ( "opsi_unboundHostFromLicense", "opsi_test", ); -@EXPORT = @events; -use strict; -use warnings; -use GOSA::GosaSupportDaemon; -use Data::Dumper; -use XML::Quote qw(:all); +our @EXPORT = @events; + BEGIN {} @@ -70,7 +75,9 @@ my %cfg_defaults = ( "password" => [\$opsi_password, "secret"], }, ); + &read_configfile($main::cfg_file, %cfg_defaults); + if ($opsi_enabled eq "true") { use JSON::RPC::Client; use XML::Quote qw(:all); diff --git a/gosa-si/server/events/server_server_com.pm b/gosa-si/server/events/server_server_com.pm index b13762622..5fbc4cc06 100644 --- a/gosa-si/server/events/server_server_com.pm +++ b/gosa-si/server/events/server_server_com.pm @@ -1,6 +1,17 @@ package server_server_com; + +use strict; +use warnings; + +use Data::Dumper; +use Time::HiRes qw( usleep); +use GOsaSI::GosaSupportDaemon; + use Exporter; -@ISA = qw(Exporter); +use Socket; + +our @ISA = qw(Exporter); + my @events = ( 'information_sharing', 'new_server', @@ -10,15 +21,8 @@ my @events = ( 'foreign_job_updates', 'confirm_usr_msg', ); -@EXPORT = @events; - -use strict; -use warnings; -use Data::Dumper; -use GOSA::GosaSupportDaemon; -use Time::HiRes qw( usleep); -use Socket; - + +our @EXPORT = @events; BEGIN {} diff --git a/gosa-si/server/events/siTriggered.pm b/gosa-si/server/events/siTriggered.pm index 530da9292..4ef51a5bc 100644 --- a/gosa-si/server/events/siTriggered.pm +++ b/gosa-si/server/events/siTriggered.pm @@ -1,22 +1,25 @@ package siTriggered; -use Exporter; -@ISA = qw(Exporter); -my @events = ( - "got_ping", - "detected_hardware", - "trigger_wake", - "reload_ldap_config", - "get_terminal_server", - ); -@EXPORT = @events; use strict; use warnings; + use Data::Dumper; -use GOSA::GosaSupportDaemon; +use GOsaSI::GosaSupportDaemon; + +use Exporter; use Socket; +our @ISA = qw(Exporter); +my @events = ( + "got_ping", + "detected_hardware", + "trigger_wake", + "reload_ldap_config", + "get_terminal_server", + ); + +our @EXPORT = @events; BEGIN {} @@ -31,14 +34,15 @@ my $ldap_admin_password; my $mesg; my %cfg_defaults = ( - "server" => { + "Server" => { "ldap-uri" => [\$ldap_uri, ""], "ldap-base" => [\$ldap_base, ""], "ldap-admin-dn" => [\$ldap_admin_dn, ""], "ldap-admin-password" => [\$ldap_admin_password, ""], }, ); -&GOSA::GosaSupportDaemon::read_configfile($main::cfg_file, %cfg_defaults); +# why not using it from main::read_configfile +&GOsaSI::GosaSupportDaemon::read_configfile($main::cfg_file, %cfg_defaults); sub get_terminal_server @@ -225,9 +229,9 @@ sub detected_hardware { # $dnsname= $heap->{force-hostname}->{$macaddress}; # &main::daemon_log("INFO: Using forced hostname $dnsname for client $address", 4); if (-e "/var/tmp/$macaddress" ){ - open(TFILE, "< /var/tmp/$macaddress"); - $dnsname= ; - close(TFILE); + open(my $TFILE, "<", "/var/tmp/$macaddress"); + $dnsname= <$TFILE>; + close($TFILE); } else { $dnsname= gethostbyaddr(inet_aton($ipaddress), AF_INET) || $ipaddress; } -- 2.30.2