Code

Added additional cmd checks
[gosa.git] / gosa-si / modules / ClientPackages.pm
index 41cecf8c42d702a0f0070026fba6dacba73f078c..37942071659adb0d04de2d4c3a7e4f25dcf76c46 100644 (file)
@@ -23,20 +23,20 @@ BEGIN{}
 END {}
 
 my ($server_ip, $server_port, $ClientPackages_key, $max_clients, $ldap_uri, $ldap_base, $ldap_admin_dn, $ldap_admin_password, $server_interface);
-my ($bus_activ, $bus_key, $bus_ip, $bus_port);
+#my ($bus_activ, $bus_key, $bus_ip, $bus_port);
 my $server;
 my $network_interface;
-my $no_bus;
+#my $no_bus;
 my (@ldap_cfg, @pam_cfg, @nss_cfg, $goto_admin, $goto_secret);
 my $mesg;
 
 my %cfg_defaults = (
-"bus" => {
-    "activ" => [\$bus_activ, "on"],
-    "key" => [\$bus_key, ""],
-    "ip" => [\$bus_ip, ""],
-    "port" => [\$bus_port, "20080"],
-    },
+#"bus" => {
+#    "activ" => [\$bus_activ, "on"],
+#    "key" => [\$bus_key, ""],
+#    "ip" => [\$bus_ip, ""],
+#    "port" => [\$bus_port, "20080"],
+#    },
 "server" => {
     "ip" => [\$server_ip, "0.0.0.0"],
     "mac-address" => [\$main::server_mac_address, "00:00:00:00:00"],
@@ -153,24 +153,41 @@ my $server_address = "$server_ip:$server_port";
 $main::server_address = $server_address;
 
 
-if( inet_aton($bus_ip) ){ $bus_ip = inet_ntoa(inet_aton($bus_ip)); } 
-######################################################
-# to change
-if( $bus_ip eq "127.0.1.1" ) { $bus_ip = "127.0.0.1" }
-######################################################
-my $bus_address = "$bus_ip:$bus_port";
-$main::bus_address = $bus_address;
+#if( inet_aton($bus_ip) ){ $bus_ip = inet_ntoa(inet_aton($bus_ip)); } 
+#######################################################
+## to change
+#if( $bus_ip eq "127.0.1.1" ) { $bus_ip = "127.0.0.1" }
+#######################################################
+#my $bus_address = "$bus_ip:$bus_port";
+#$main::bus_address = $bus_address;
+
+
+#my $hostkey = &create_passwd;
+#my $res = $main::known_server_db->add_dbentry( {table=>$main::known_server_tn, 
+#            primkey=>['hostname'],
+#            hostname=>$main::server_address,
+#            status=>'myself',
+#            hostkey=>$hostkey,
+#            timestamp=>&get_time(),
+#            } );
+#if (not $res == 0) {
+#    &main::daemon_log("0 ERROR: cannot add server to known_server_db: $res", 1);
+#} else {
+#    &main::daemon_log("0 INFO: '$main::server_address' successfully added to known_server_db", 5);
+#}
 
-# create general settings for this module
-my $xml = new XML::Simple();
 
-# register at bus
-if ($main::no_bus > 0) {
-    $bus_activ = "off"
-}
-if($bus_activ eq "on") {
-    &register_at_bus();
-}
+
+## create general settings for this module
+#my $xml = new XML::Simple();
+#
+## register at bus
+#if ($main::no_bus > 0) {
+#    $bus_activ = "off"
+#}
+#if($bus_activ eq "on") {
+#    &register_at_bus();
+#}
 
 
 ### functions #################################################################
@@ -235,61 +252,63 @@ sub read_configfile {
 
 }
 
+# moved to GosaSupportDaemon: 03-06-2008 rettenbe
 #===  FUNCTION  ================================================================
 #         NAME:  get_interface_for_ip
 #   PARAMETERS:  ip address (i.e. 192.168.0.1)
 #      RETURNS:  array: list of interfaces if ip=0.0.0.0, matching interface if found, undef else
 #  DESCRIPTION:  Uses proc fs (/proc/net/dev) to get list of interfaces.
 #===============================================================================
-sub get_interface_for_ip {
-       my $result;
-       my $ip= shift;
-       if ($ip && length($ip) > 0) {
-               my @ifs= &get_interfaces();
-               if($ip eq "0.0.0.0") {
-                       $result = "all";
-               } else {
-                       foreach (@ifs) {
-                               my $if=$_;
-                               if(&main::get_ip($if) eq $ip) {
-                                       $result = $if;
-                               }
-                       }       
-               }
-       }       
-       return $result;
-}
+#sub get_interface_for_ip {
+#      my $result;
+#      my $ip= shift;
+#      if ($ip && length($ip) > 0) {
+#              my @ifs= &get_interfaces();
+#              if($ip eq "0.0.0.0") {
+#                      $result = "all";
+#              } else {
+#                      foreach (@ifs) {
+#                              my $if=$_;
+#                              if(&main::get_ip($if) eq $ip) {
+#                                      $result = $if;
+#                              }
+#                      }       
+#              }
+#      }       
+#      return $result;
+#}
 
+# moved to GosaSupportDaemon: 03-06-2008 rettenbe
 #===  FUNCTION  ================================================================
 #         NAME:  get_interfaces 
 #   PARAMETERS:  none
 #      RETURNS:  (list of interfaces) 
 #  DESCRIPTION:  Uses proc fs (/proc/net/dev) to get list of interfaces.
 #===============================================================================
-sub get_interfaces {
-       my @result;
-       my $PROC_NET_DEV= ('/proc/net/dev');
-
-       open(PROC_NET_DEV, "<$PROC_NET_DEV")
-               or die "Could not open $PROC_NET_DEV";
-
-       my @ifs = <PROC_NET_DEV>;
-
-       close(PROC_NET_DEV);
-
-       # Eat first two line
-       shift @ifs;
-       shift @ifs;
-
-       chomp @ifs;
-       foreach my $line(@ifs) {
-               my $if= (split /:/, $line)[0];
-               $if =~ s/^\s+//;
-               push @result, $if;
-       }
-
-       return @result;
-}
+#sub get_interfaces {
+#      my @result;
+#      my $PROC_NET_DEV= ('/proc/net/dev');
+#
+#      open(PROC_NET_DEV, "<$PROC_NET_DEV")
+#              or die "Could not open $PROC_NET_DEV";
+#
+#      my @ifs = <PROC_NET_DEV>;
+#
+#      close(PROC_NET_DEV);
+#
+#      # Eat first two line
+#      shift @ifs;
+#      shift @ifs;
+#
+#      chomp @ifs;
+#      foreach my $line(@ifs) {
+#              my $if= (split /:/, $line)[0];
+#              $if =~ s/^\s+//;
+#              push @result, $if;
+#      }
+#
+#      return @result;
+#}
 
 #===  FUNCTION  ================================================================
 #         NAME:  get_mac 
@@ -335,22 +354,22 @@ sub get_mac {
 #      RETURNS:  nothing
 #  DESCRIPTION:  creates an entry in known_daemons and send a 'here_i_am' msg to bus
 #===============================================================================
-sub register_at_bus {
-
-    # add bus to known_server_db
-    my $res = $main::known_server_db->add_dbentry( {table=>'known_server',
-                                                    primkey=>['hostname'],
-                                                    hostname=>$bus_address,
-                                                    status=>'bus',
-                                                    hostkey=>$bus_key,
-                                                    timestamp=>&get_time,
-                                                } );
-    my $msg_hash = &create_xml_hash("here_i_am", $server_address, $bus_address);
-    my $msg = &create_xml_string($msg_hash);
-
-    &main::send_msg_to_target($msg, $bus_address, $bus_key, "here_i_am");
-    return $msg;
-}
+#sub register_at_bus {
+#
+#    # add bus to known_server_db
+#    my $res = $main::known_server_db->add_dbentry( {table=>'known_server',
+#                                                    primkey=>['hostname'],
+#                                                    hostname=>$bus_address,
+#                                                    status=>'bus',
+#                                                    hostkey=>$bus_key,
+#                                                    timestamp=>&get_time,
+#                                                } );
+#    my $msg_hash = &create_xml_hash("here_i_am", $server_address, $bus_address);
+#    my $msg = &create_xml_string($msg_hash);
+#
+#    &main::send_msg_to_target($msg, $bus_address, $bus_key, "here_i_am");
+#    return $msg;
+#}
 
 
 
@@ -554,6 +573,7 @@ sub here_i_am {
        my $gotoHardwareChecksum = @{$msg_hash->{gotoHardwareChecksum}}[0];
     my $client_status = @{$msg_hash->{client_status}}[0];
     my $client_revision = @{$msg_hash->{client_revision}}[0];
+    my $key_lifetime = @{$msg_hash->{key_lifetime}}[0];
 
     # number of known clients
     my $nu_clients= $main::known_clients_db->count_dbentries('known_clients');
@@ -596,6 +616,7 @@ sub here_i_am {
                                                 status=>'registered',
                                                 hostkey=>$new_passwd,
                                                 timestamp=>$act_timestamp,
+                                                keylifetime=>$key_lifetime,
                                                 } );
 
     if ($res != 0)  {
@@ -607,24 +628,6 @@ sub here_i_am {
     $out_hash = &create_xml_hash("registered", $server_address, $source);
 
 
-
-
-#    # notify registered client to all other server
-#    if( $bus_activ eq "on") {
-#        # fetch actual bus key
-#        my $sql_statement= "SELECT * FROM known_server WHERE status='bus'";
-#        my $query_res = $main::known_server_db->select_dbentry( $sql_statement );
-#        my $hostkey = $query_res->{1}->{'hostkey'};
-#
-#        # send update msg to bus
-#        $out_hash = &create_xml_hash("new_client", $server_address, $bus_address, $source);
-#        &add_content2xml_hash($out_hash, "macaddress", $mac_address);
-#        &add_content2xml_hash($out_hash, "timestamp", $act_timestamp);
-#        my $new_client_out = &create_xml_string($out_hash);
-#        push(@out_msg_l, $new_client_out);
-#        &main::daemon_log("$session_id INFO: send bus msg that client '$source' has registered at server '$server_address'", 5);
-#    }
-
     # give the new client his ldap config
     # Workaround: Send within the registration response, if the client will get an ldap config later
        my $new_ldap_config_out = &new_ldap_config($source, $session_id);