diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client
index fe07d32f42669cbd8ac6b09a7d003e2cde713f3f..2d9ce606325c9941e5036da1fd3fda7b7c8906cf 100755 (executable)
--- a/gosa-si/gosa-si-client
+++ b/gosa-si/gosa-si-client
my ($cfg_file, %cfg_defaults, $foreground, $verbose, $pid_file, $procid, $pid, $log_file);
my ($server_address, $server_ip, $server_port, $server_domain, $server_passwd, $server_cipher, $server_timeout);
-my ($client_address, $client_ip, $client_port, $client_mac_address, $network_interface, $ldap_config, $pam_config, $nss_config);
+my ($client_address, $client_ip, $client_port, $client_mac_address, $network_interface, $ldap_config, $pam_config, $nss_config, $gotoHardwareChecksum);
my ($input_socket, $rbits, $wbits, $ebits, $xml, $known_hosts, $ldap_enabled);
my (@events);
"client" =>
{"client_port" => [\$client_port, "20083"],
"client_ip" => [\$client_ip, "0.0.0.0"],
+ "client_mac_address" => [\$client_mac_address, "00:00:00:00:00:00"],
"ldap" => [\$ldap_enabled, 1],
"ldap_config" => [\$ldap_config, "/etc/ldap/ldap.conf"],
"pam_config" => [\$pam_config, "/etc/pam_ldap.conf"],
# DESCRIPTION: Uses ioctl to get mac address directly from system.
#===============================================================================
sub get_mac {
- my $ifreq= shift;
- my $result;
- if ($ifreq && length($ifreq) > 0) {
- if($ifreq eq "all") {
+ my $ifreq= shift;
+ my $result;
+
+ if ($ifreq && length($ifreq) > 0) {
+ if($ifreq eq "all") {
if(defined($server_ip)) {
$result = &get_local_mac_for_remote_ip($server_ip);
+ } elsif ($client_mac_address && length($client_mac_address) > 0) {
+ $result = $client_mac_address;
} else {
$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) {
- $result= $client_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;
- }
- }
- }
- }
- return $result;
+ } else {
+ my $SIOCGIFHWADDR= 0x8927; # man 2 ioctl_list
+
+ socket SOCKET, PF_INET, SOCK_DGRAM, getprotobyname('ip')
+ or die "socket: $!";
+
+ # A configured MAC Address should always override a guessed value
+ if ($client_mac_address and length($client_mac_address) > 0) {
+ $result = $client_mac_address;
+ } elsif(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;
+ }
+ }
+ }
+ }
+ return $result;
}
#=== FUNCTION ================================================================
&add_content2xml_hash($register_hash, "new_passwd", $new_server_passwd);
&add_content2xml_hash($register_hash, "mac_address", $client_mac_address);
&add_content2xml_hash($register_hash, "events", $events);
+ &add_content2xml_hash($register_hash, "gotoHardwareChecksum", $gotoHardwareChecksum);
# send xml hash to server with general server passwd
my $answer = &send_msg_hash2address($register_hash, $server, $server_passwd);
elsif ($header eq 'ping') { &got_ping($msg_hash) }
elsif ($header eq 'wake_up') { &execute_event($msg_hash)}
elsif ($header eq 'new_passwd') { &new_passwd()}
+ elsif ($header eq 'detect_hardware') { &detect_hardware()}
else { daemon_log("ERROR: no function assigned to msg $header", 5) }
return;
return;
}
+sub generate_hw_digest {
+ my $hw_data;
+ foreach my $line (split /\n/, `cat /proc/bus/pci/devices`) {
+ $hw_data.= sprintf "%s", $line =~ /[^\s]+\s([^\s]+)\s.*/;
+ }
+ return(md5_base64($hw_data));
+}
+
+sub detect_hardware {
+ my $hwinfo= `which hwinfo`;
+ chomp $hwinfo;
+
+ if (!(defined($hwinfo) && length($hwinfo) > 0)) {
+ &main::daemon_log("ERROR: hwinfo was not found in \$PATH! Hardware detection will not work!", 1);
+ return;
+ }
+
+ my $result= {
+ macAddress => $client_mac_address,
+ gotoXMonitor => "",
+ gotoXDriver => "",
+ gotoXMouseType => "",
+ gotoXMouseport => "",
+ gotoXkbModel => "",
+ gotoXHsync => "",
+ gotoXVsync => "",
+ gotoXResolution => "",
+ ghUsbSupport => "",
+ gotoSndModule => "",
+ ghGfxAdapter => "",
+ ghNetNic => "",
+ ghSoundAdapter => "",
+ ghMemSize => "",
+ ghCpuType => "",
+ gotoModules => [],
+ ghIdeDev => [],
+ ghScsiDev => [],
+ };
+
+ &main::daemon_log("Starting hardware detection", 4);
+ my $gfxcard= `$hwinfo --gfxcard`;
+ my $primary_adapter= $1 if $gfxcard =~ /^Primary display adapter:\s#(\d+)\n/m;
+ if(defined($primary_adapter)) {
+ ($result->{ghGfxAdapter}, $result->{gotoXDriver}) = ($1,$2) if
+ $gfxcard =~ /$primary_adapter:.*?Model:\s\"([^\"]*)\".*?Server Module:\s(\w*).*?\n\n/s;
+ }
+ my $monitor= `$hwinfo --monitor`;
+ my $primary_monitor= $1 if $monitor =~ /^(\d*):.*/m;
+ if(defined($primary_monitor)) {
+ ($result->{gotoXMonitor}, $result->{gotoXResolution}, $result->{gotoXVsync}, $result->{gotoXHsync})= ($1,$2,$3,$4) if
+ $monitor =~ /$primary_monitor:\s.*?Model:\s\"(.*?)\".*?Max\.\sResolution:\s([0-9x]*).*?Vert\.\sSync\sRange:\s([\d\-]*)\sHz.*?Hor\.\sSync\sRange:\s([\d\-]*)\skHz.*/s;
+ }
+
+ if(length($result->{gotoXHsync}) == 0) {
+ # set default values
+ $result->{gotoXHsync} = "30+50";
+ $result->{gotoXVsync} = "30+90";
+ }
+ my $mouse= `$hwinfo --mouse`;
+ my $primary_mouse= $1 if $mouse =~ /^(\d*):.*/m;
+ if(defined($primary_mouse)) {
+ ($result->{gotoXMouseport}, $result->{gotoXMouseType}) = ($1,$2) if
+ $mouse =~ /$primary_mouse:\s.*?Device\sFile:\s(.*?)\s.*?XFree86\sProtocol:\s(.*?)\n.*?/s;
+ }
+ my $sound= `$hwinfo --sound`;
+ my $primary_sound= $1 if $sound =~ /^(\d*):.*/m;
+ if(defined($primary_sound)) {
+ ($result->{ghSoundAdapter}, $result->{gotoSndModule})= ($1,$2) if
+ $sound =~ /$primary_sound:\s.*?Model:\s\"(.*?)\".*?Driver\sModules:\s\"(.*?)\".*/s;
+ }
+
+ my $netcard= `hwinfo --netcard`;
+ my $primary_netcard= $1 if $netcard =~ /^(\d*):.*/m;
+ if(defined($primary_netcard)) {
+ $result->{ghNetNic}= $1 if $netcard =~ /$primary_netcard:\s.*?Model:\s\"(.*?)\".*/s;
+ }
+
+ my $keyboard= `hwinfo --keyboard`;
+ my $primary_keyboard= $1 if $keyboard =~ /^(\d*):.*/m;
+ if(defined($primary_keyboard)) {
+ $result->{gotoXkbModel}= $1 if $keyboard =~ /$primary_keyboard:\s.*?XkbModel:\s(.*?)\n.*/s;
+ }
+
+ $result->{ghCpuType}= sprintf "%s / %s - %s",
+ `cat /proc/cpuinfo` =~ /.*?vendor_id\s+:\s(.*?)\n.*?model\sname\s+:\s(.*?)\n.*?cpu\sMHz\s+:\s(.*?)\n.*/s;
+ $result->{ghMemSize}= $1 if `cat /proc/meminfo` =~ /^MemTotal:\s+(.*?)\skB.*/s;
+
+ my @gotoModules=();
+ for my $line(`lsmod`) {
+ if (($line =~ /^Module.*$/) or ($line =~ /^snd.*$/)) {
+ next;
+ } else {
+ push @gotoModules, $1 if $line =~ /^(\w*).*$/
+ }
+ }
+ my %seen = ();
+
+ # Remove duplicates and save
+ push @{$result->{gotoModules}}, grep { ! $seen{$_} ++ } @gotoModules;
+
+ $result->{ghUsbSupport} = (-d "/proc/bus/usb")?"true":"false";
+
+ foreach my $device(`hwinfo --ide` =~ /^.*?Model:\s\"(.*?)\".*$/mg) {
+ push @{$result->{ghIdeDev}}, $device;
+ }
+
+ foreach my $device(`hwinfo --scsi` =~ /^.*?Model:\s\"(.*?)\".*$/mg) {
+ push @{$result->{ghScsiDev}}, $device;
+ }
+
+ &main::daemon_log("Hardware detection done!", 4);
+
+ return &send_msg_hash2address(
+ &create_xml_hash("detected_hardware", $client_address, $server_address, $result),
+ $server_address,
+ $server_passwd
+ );
+}
#==== MAIN = main ==============================================================
# setup xml parser
$xml = new XML::Simple();
+# compute hardware checksum
+$gotoHardwareChecksum= &generate_hw_digest();
+
# create input socket
daemon_log(" ", 1);
$rbits = $wbits = $ebits = "";