Code

Fixed URL extraction
[gosa.git] / gosa-si / gosa-si-bus
index 7d436d3068ae6b814af21963ef2c163c3ae19e35..f1da0ba054484b770c43b024289afa80ddc9f4cc 100755 (executable)
@@ -28,25 +28,28 @@ use Time::HiRes qw( gettimeofday );
 use POE qw(Component::Server::TCP);
 use Data::Dumper;
 use Crypt::Rijndael;
-use GOSA::DBsqlite;
-use GOSA::GosaSupportDaemon;
 use IO::Socket::INET;
 use NetAddr::IP;
 use XML::Simple;
 use MIME::Base64;
+use File::Basename;
 use Digest::MD5  qw(md5 md5_hex md5_base64);
+use utf8;
 
+use GOSA::GosaSupportDaemon;
+use GOSA::DBsqlite;
 
 my ($cfg_file, $default_cfg_file, %cfg_defaults, $foreground, $verbose, $pid_file, $procid, $pid, $log_file,);
 my ($bus_address, $bus_key, $bus_ip, $bus_port, $bus_mac_address);
 my ($bus_known_server_db, $bus_known_server_file_name, $bus_known_clients_db, $bus_known_clients_file_name);
 my $xml;
+our $prg= basename($0);
 
 $foreground = 0 ;
 %cfg_defaults = (
 "general" => {
-    "log_file" => [\$log_file, "/var/run/".$0.".log"],
-    "pid_file" => [\$pid_file, "/var/run/".$0.".pid"],
+    "log_file" => [\$log_file, "/var/run/".$prg.".log"],
+    "pid_file" => [\$pid_file, "/var/run/".$prg.".pid"],
     },
 "bus" => {
     "key"  => [\$bus_key, "secret-bus-password"],
@@ -173,7 +176,7 @@ sub check_pid {
 #===============================================================================
 sub usage {
     print STDERR << "EOF" ;
-usage: $0 [-hvf] [-c config]
+usage: $prg [-hvf] [-c config]
 
     -h        : this (help) message
     -c <file> : config file
@@ -213,10 +216,8 @@ sub daemon_log {
                 $month = $monthnames[$month];
                 $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
                 $year+=1900;
-                my $name = $0;
-                $name =~ s/\.\///;
 
-                my $log_msg = "$month $monthday $hours:$minutes:$seconds $name $msg\n";
+                my $log_msg = "$month $monthday $hours:$minutes:$seconds $prg $msg\n";
                 print LOG_HANDLE $log_msg;
                 if( $foreground ) { 
                     print STDERR $log_msg;
@@ -466,6 +467,47 @@ sub create_passwd {
 }
 
 
+sub create_ciphering {
+    my ($passwd) = @_;
+       if((!defined($passwd)) || length($passwd)==0) {
+               $passwd = "";
+       }
+    $passwd = substr(md5_hex("$passwd") x 32, 0, 32);
+    my $iv = substr(md5_hex('GONICUS GmbH'),0, 16);
+    my $my_cipher = Crypt::Rijndael->new($passwd , Crypt::Rijndael::MODE_CBC());
+    $my_cipher->set_iv($iv);
+    return $my_cipher;
+}
+
+
+sub encrypt_msg {
+    my ($msg, $key) = @_;
+    my $my_cipher = &create_ciphering($key);
+    my $len;
+    {
+           use bytes;
+           $len= 16-length($msg)%16;
+    }
+    $msg = "\0"x($len).$msg;
+    $msg = $my_cipher->encrypt($msg);
+    chomp($msg = &encode_base64($msg));
+    # there are no newlines allowed inside msg
+    $msg=~ s/\n//g;
+    return $msg;
+}
+
+
+sub decrypt_msg {
+
+    my ($msg, $key) = @_ ;
+    $msg = &decode_base64($msg);
+    my $my_cipher = &create_ciphering($key);
+    $msg = $my_cipher->decrypt($msg); 
+    $msg =~ s/\0*//g;
+    return $msg;
+}
+
+
 sub send_msg_hash2address {
     my ($msg_hash, $address, $encrypt_key) = @_ ;
     my $msg = &create_xml_string($msg_hash);