mioga-patch 23.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
diff --git a/INSTALL b/INSTALL
index ef0f369..b275a48 100644
--- a/INSTALL
+++ b/INSTALL
@@ -382,6 +382,8 @@ A default init script is provided in file web/conf/mioga2.init.d. This script wo
 Additional configuration for the Search engine
 ----------------------------------------------
 
+The default init script starts the search engine daemon.
+
 You must edit the crawl_sample.sh to specify default location for configuration files and rename it to crawl.sh.
 This script must be run by cron in a day basis with apache user (www-data for Debian)
 
diff --git a/Makefile.PL b/Makefile.PL
15
index 3582d20..46608ca 100644
16 17
--- a/Makefile.PL
+++ b/Makefile.PL
18 19
@@ -20,8 +20,10 @@
 # ============================================================================
20
 
21 22
 
+use Cwd;
23 24 25 26 27 28
 use ExtUtils::MakeMaker;
 use ExtUtils::MakeMaker::Config;
+use File::Find;
 
 # ****************************************************************************
 # 
29
@@ -67,6 +69,7 @@ sub CheckPreDepends {
30 31 32 33 34 35 36
 
 my $disable_check = grep {lc($_) eq 'disable_check'} @ARGV;
 
+if (! $disable_check) {
 CheckPreDepends({ # 'Data::Dumper' => '2.101',
 		  # 'DBI'          => '1.13',
 		  # 'DBD::Pg'      => '1.01',
37
@@ -75,7 +78,8 @@ CheckPreDepends({ # 'Data::Dumper' => '2.101',
38 39 40 41 42 43 44 45 46
 		  'Error'        => '0.15',
 		  # 'Net::LDAP'    => '0.25',
 		  # 'Unicode::String' => '2.06',
-	      });
+          })
+}
     
 require MiogaConf;
     
47
@@ -115,7 +119,7 @@ my $docsubdirs = "docs";
48 49 50 51 52 53 54 55
 # ----------------------------------------------------------------------------
 sub MY::processPL {
 return '
-# Not realy in the good section, but at a good place:
+# Not really in the good section, but at a good place:
 # between "all" and next "tardist"
 
 include config.mk
56
@@ -124,10 +128,7 @@ tardist: doc
57 58 59 60 61 62 63 64 65 66 67
 dist: doc
 install ::
 	if test -e $(TMP_DIR) ; then \
-            if test -d $(TMP_DIR) ; then \
-                ( su - $(APACHE_USER) -c "id" -s /bin/sh || \
-                    ( echo "===> Problem with \"$(APACHE_USER)\" user" ; exit 1 ) ) \
-            else \
+            if ! test -d $(TMP_DIR) ; then \
                 echo "===> File $(TMP_DIR) exists but is not a directory ..." ; \
                 exit 1 ; \
             fi \
68
@@ -156,6 +157,31 @@ install-all ::
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
 
 	(cd web && $(MAKE) setperms) || exit 1;
 
+slapos-compilation :: install
+	for i in bin locales web ; \
+	do \
+		(cd $$i && $(MAKE) install) || exit 1;\
+	done
+	# Create symlinks for static content that can be shared among all SlapOS instances	
+	for i in var/lib/Mioga2/static var/lib/Mioga2/conf/themes/default var/lib/Mioga2/conf/xsl; do \
+		mkdir -p `dirname "$(MIOGA_STATIC)/$$i"` && \
+		mv "$(MIOGA_BASE)/$$i" "$(MIOGA_STATIC)/$$i" && \
+		ln -s "$(MIOGA_STATIC)/$$i" "$(MIOGA_BASE)/$$i"; \
+	done
+	# copy a minimal build system into mioga/build
+	mkdir -p "$(MIOGA_BUILDINST)"
85 86 87
+	cp -R --parents \
+		Makefile.PL sql web/conf conf bin/search/crawl_sample.sh \
+		"$(MIOGA_BUILDINST)"
88 89 90 91 92 93 94 95 96 97 98 99
+
+slapos-instantiation ::
+	for i in web/conf conf sql ; \
+	do \
+		(cd $$i && $(MAKE) install) || exit 1;\
+	done
+
+	(cd web && $(MAKE) setperms) || exit 1;
+
 doc:
 	for i in ' . $docsubdirs . ' ; \
 	do \
100
@@ -176,9 +202,26 @@ installall: install install-all
101 102 103 104
 # 
 # ----------------------------------------------------------------------------
 
+my $Mioga2_pm = 'lib/Mioga2.pm';
105 106 107 108 109
+foreach my $envkey (keys %ENV) {
+    print "VHH DEBUG: found envvar $envkey\n";
+}
+if ((not -e $Mioga2_pm) and exists($ENV{MIOGA_SITEPERL})) {
+    print "VHH DEBUG: looking into SITEPERL\n";
110
+    my $findfile = sub {
111 112 113 114
+        if ($_ eq 'Mioga2.pm') {
+            $Mioga2_pm = $File::Find::name;
+            print "VHH DEBUG: Found Mioga2.pm in $Mioga2_pm\n";
+        }
115 116 117
+    };
+    find($findfile, $ENV{MIOGA_SITEPERL});
+}; 
118 119 120
+print "VHH DEBUG: Found finally: $Mioga2_pm\n";
+print 'VHH DEBUG: SIZE = ' . ( stat($Mioga2_pm) )[8] . "\n";
+print "VHH DEBUG: Current directory is ".getcwd."\n";
121 122 123 124 125 126 127
 WriteMakefile(
    'NAME'  => 'Mioga',
    'DIR'   => ['bin', 'web',  'locales', 'docs', 'sql'],
-   'VERSION_FROM' => 'lib/Mioga2.pm',
+   'VERSION_FROM' => $Mioga2_pm,
 );
 
128 129 130 131 132
diff --git a/bin/mailinglist/miogamailinglist.pl b/bin/mailinglist/miogamailinglist.pl
index 80668e2..fa1603a 100755
--- a/bin/mailinglist/miogamailinglist.pl
+++ b/bin/mailinglist/miogamailinglist.pl
@@ -205,11 +205,11 @@ sub MsgSendStock
133 134 135 136 137 138 139 140 141 142 143 144 145
 sub CheckUTF8 {
     my ($str) = @_;
     
-    my $conv    = Text::Iconv->new('utf8', 'utf8');
+    my $conv    = Text::Iconv->new('UTF-8', 'UTF-8');
     my $tmp_str = $conv->convert($str);
     unless ($tmp_str) {
         my $charset = detect($str) || 'iso-8859-15'; # defaults to latin9
-        $conv = Text::Iconv->new($charset, "utf8");
+        $conv = Text::Iconv->new($charset, "UTF-8");
         $str  = $conv->convert($str);
     }
     return $str;
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
diff --git a/bin/notifier/searchengine.pl b/bin/notifier/searchengine.pl
index efd1ca2..fc5ba67 100755
--- a/bin/notifier/searchengine.pl
+++ b/bin/notifier/searchengine.pl
@@ -39,8 +39,7 @@ if (!open(FIFO, "+>$fifo")) {
     syslog('err', "Can't open fifo: $!. Exiting...");
 }
 my $flags   = fcntl(FIFO, F_GETFL, 0);
-
-
+my $crawler = $config->GetBinariesDir()."/crawl.sh";
 # MAIN LOOP
 
 my %instances;
@@ -53,7 +52,7 @@ while (1) {
 		$instances{$line} += 1;
     }
 	foreach my $inst (keys(%instances)) {
-		system("/usr/local/bin/crawl.sh $inst");
+		system("$crawler $inst");
 	}
     fcntl(FIFO, F_SETFL, $flags);
 }
diff --git a/conf/Config.xml b/conf/Config.xml
index e614cda..3dcccf5 100644
--- a/conf/Config.xml
+++ b/conf/Config.xml
173 174 175 176 177 178 179 180 181 182
@@ -3,6 +3,9 @@
   <version module="Mioga2"/>
 
   <config>
+    <parameter name="init_sql" question="Initialize database ?"
+	       type="bool" default="no" xpath="/init_sql"/>
+
     <parameter name="instance_ident" question="First Mioga instance Identifier ?"
                type="text" default="Mioga"
                xpath="/instance_ident"/>
183 184 185
@@ -35,8 +38,18 @@
     <parameter name="authentication" question="Authentification method ?" 
                type="enum" default="Mioga2" values="Mioga2"
186
                xpath="/authentication"/>
187 188 189 190 191 192
-    
+
+    <parameter name="bin_dir" question="Directory for helper scripts and binaries ?" 
+               type="text" default="/usr/local/bin"
+               xpath="/bin_dir"/>
+
193 194 195 196 197 198 199 200 201 202
     <parameter name="Database settings" type="submenu">
+      <parameter name="db_host" question=" Mioga database server name or address ?" 
+                 type="text" default="localhost"
+                 xpath="/database/DBhost"/>              
+      <parameter name="db_port" question=" Mioga database server port ?" 
+                 type="text" default="5432"
+                 xpath="/database/DBport"/>              
       <parameter name="db_name" question=" Name of Mioga database ?" 
                  type="text" default="mioga2"
                  xpath="/database/DBname"/>              
203 204 205 206 207
diff --git a/lib/Mioga2/Bottin.pm b/lib/Mioga2/Bottin.pm
index ba4cd8d..0db5651 100644
--- a/lib/Mioga2/Bottin.pm
+++ b/lib/Mioga2/Bottin.pm
@@ -1742,11 +1742,11 @@ sub InitSuperAdminMode {
208 209 210 211 212 213 214 215 216 217 218 219 220 221
 sub CheckUTF8 {
     my ($str) = @_;
     
-    my $conv    = Text::Iconv->new('utf8', 'utf8');
+    my $conv    = Text::Iconv->new('UTF-8', 'UTF-8');
     my $tmp_str = $conv->convert($str);
     unless ($tmp_str) {
-        my $charset = detect($str) || 'iso-8859-15'; # defaults to latin9
-        $conv = Text::Iconv->new($charset, "utf8");
+        my $charset = detect($str) || 'ISO-8859-15'; # defaults to latin9
+        $conv = Text::Iconv->new($charset, "UTF-8");
         $str  = $conv->convert($str);
     }
     return $str;
222 223 224 225 226
diff --git a/lib/Mioga2/Classes/URI.pm b/lib/Mioga2/Classes/URI.pm
index 8678b33..bf97e71 100644
--- a/lib/Mioga2/Classes/URI.pm
+++ b/lib/Mioga2/Classes/URI.pm
@@ -75,15 +75,16 @@ sub new {
Viktor Horvath's avatar
Viktor Horvath committed
227 228 229
   
   # convert uri to UTF-8
   my $uri     = uri_unescape($options{uri});
230 231 232
+    
   
   # attempt to see if uri is utf8 to avoid detection
Viktor Horvath's avatar
Viktor Horvath committed
233
-  my $conv    = Text::Iconv->new('utf8', 'utf8');
234 235
+  my $conv    = Text::Iconv->new('UTF-8', 'UTF-8');
   my $tmp_uri = $conv->convert($uri);
Viktor Horvath's avatar
Viktor Horvath committed
236
-  
237 238
+
   unless ($tmp_uri) {
239 240
-    my $charset = detect($uri) || 'iso-8859-15'; # defaults to latin9
+    my $charset = detect($uri) || 'ISO-8859-15'; # defaults to latin9
Viktor Horvath's avatar
Viktor Horvath committed
241 242
     warn "charset = '$charset' for uri = '$uri'" if $debug;
-    $conv = Text::Iconv->new($charset, "utf8");
243
+    $conv = Text::Iconv->new($charset, "UTF-8");
Viktor Horvath's avatar
Viktor Horvath committed
244 245 246
     $uri  = $conv->convert($uri);
     warn "==> converted uri = '$uri'" if $debug;
   }
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
diff --git a/lib/Mioga2/Config.pm b/lib/Mioga2/Config.pm
index b088823..4edac62 100644
--- a/lib/Mioga2/Config.pm
+++ b/lib/Mioga2/Config.pm
@@ -28,7 +28,7 @@ Config.pm: Access class to the current Mioga instance configuration.
 This module permits to access to the current Mioga instance
 configuration parameters.
 
-=head1 METHODS DESRIPTION
+=head1 METHODS DESCRIPTION
 
 =cut
 
diff --git a/lib/Mioga2/DAVFS.pm b/lib/Mioga2/DAVFS.pm
index b56c4ad..7810f82 100644
--- a/lib/Mioga2/DAVFS.pm
+++ b/lib/Mioga2/DAVFS.pm
@@ -141,10 +141,11 @@ use Mioga2::tools::APIAuthz;
265 266 267 268
 use Mioga2::tools::database;
 use Mioga2::tools::string_utils;
 use Mioga2::tools::Convert;
+use Net::INET6Glue::INET_is_INET6;
Viktor Horvath's avatar
Viktor Horvath committed
269 270 271 272 273 274 275 276
 use XML::LibXML ();
 use Mioga2::Constants;
 
-my $debug = 0;
+my $debug = 5;
 
 my $MULTI_STATUS	= 207;	# code DAV for the Multi-status response
 
277
@@ -756,13 +757,17 @@ sub make_request {
Viktor Horvath's avatar
Viktor Horvath committed
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
 	my $host = $self->{host};
 	my $port = $self->{port};
 
+    my $hostport = $host;
+    $hostport = '['.$hostport.']' if $host =~ /:.*:/;
+    $hostport .= ':'.$port;
+
 	my $dav_uri   = $config->GetDAVBasePath;
 	my $mioga_uri = $config->GetBasePath;
 
 	my $orig_uri = Mioga2::Classes::URI->new( uri => $callbacks->{uri}->() );
 	my $uri      = $orig_uri->as_string;
 	$uri =~ s/^$mioga_uri/$dav_uri/;
-	$uri = Mioga2::Classes::URI->new( uri => "$protocol://$host:$port$uri" )
+	$uri = Mioga2::Classes::URI->new( uri => "$protocol://$hostport$uri" )
 	  ->as_string;
 	print STDERR "[Mioga2::DAVFS::make_request] uri = $uri\n" if $debug;
 
296
@@ -774,7 +779,7 @@ sub make_request {
Viktor Horvath's avatar
Viktor Horvath committed
297 298 299 300 301 302 303 304
 
 		# process headers
 		if ( $header =~ /^destination/i && $value !~ $dav_uri ) {
-			$value =~ s!(//)[^/]+$mioga_uri!$1$host$dav_uri!;
+			$value =~ s!(//)[^/]+$mioga_uri!$1$hostport$dav_uri!; # was only $host before!
 			$value = Mioga2::Classes::URI->new( uri => $value )->as_string;
 			$value = $self->escapeSpecialChars($value);
 		}
305 306 307 308 309
diff --git a/lib/Mioga2/Database.pm b/lib/Mioga2/Database.pm
index 4afa54b..ca8368c 100644
--- a/lib/Mioga2/Database.pm
+++ b/lib/Mioga2/Database.pm
@@ -61,7 +61,7 @@ sub new {
Viktor Horvath's avatar
Viktor Horvath committed
310 311 312 313 314 315 316 317
 	my $self = { };
 	bless($self, $class);
 
-	for my $attr (qw/DBIlogin DBIpasswd DBIdriver DBname/) {
+	for my $attr (qw/DBhost DBport DBIlogin DBIpasswd DBIdriver DBname/) {
 		if (!defined ($attributes{$attr})) {
 			throw Mioga2::Exception::DB ("[Mioga2::Database::new]", "Cannot connect to database: " . $DBI::errstr);
 		}
318
@@ -72,8 +72,10 @@ sub new {
Viktor Horvath's avatar
Viktor Horvath committed
319 320 321 322 323 324 325 326 327 328 329
 	my $dbiPassword = $self->{database}->{DBIpasswd};
 	my $dbDriver = $self->{database}->{DBIdriver};
 	my $dbName = $self->{database}->{DBname};
+    my $dbHost = $self->{database}->{DBhost};
+    my $dbPort = $self->{database}->{DBport};
 
-	my $datasource = "dbi:$dbDriver:dbname=$dbName";
+	my $datasource = "dbi:$dbDriver:dbname=$dbName;host=$dbHost;port=$dbPort";
 
 	$self->{dbh} = DBI->connect($datasource, $dbiUser, $dbiPassword);
 
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
diff --git a/lib/Mioga2/Exception/DB.pm b/lib/Mioga2/Exception/DB.pm
index 7ce5020..bee00ca 100644
--- a/lib/Mioga2/Exception/DB.pm
+++ b/lib/Mioga2/Exception/DB.pm
@@ -76,6 +76,17 @@ sub as_string
 	return $string;
 }
 
+# ----------------------------------------------------------------------------
+=head2 getDBerror ()
+Return the error as sent by the database connector.
+=cut 
+# ----------------------------------------------------------------------------
+sub getDBerror {
+    my ($self) = @_;
+    return $self->{errDB}
+}
+
+
 # ============================================================================
Viktor Horvath's avatar
Viktor Horvath committed
350
 
351 352 353 354 355 356
 =head1 PRIVATE METHODS DESCRIPTION
diff --git a/lib/Mioga2/InstanceList.pm b/lib/Mioga2/InstanceList.pm
index 3e2cf7a..a676a1b 100644
--- a/lib/Mioga2/InstanceList.pm
+++ b/lib/Mioga2/InstanceList.pm
@@ -423,7 +423,9 @@ sub Store {
357 358 359
 		$conf->RunHooks($self->{config}->{miogaconf});
 
 		# Run crawl.sh to initialize search engine database
360
-		my $crawlcmd = $self->{config}->{miogaconf}->GetMiogaPrefix () . "/bin/mioga2_index.pl --conf=" . $self->{config}->GetMiogaConfPath () . ' --search_conf=' . $self->{config}->GetInstallPath . "/conf/search_conf.xml" . ' ' . $self->Get ('ident');
361
+		my $crawlcmd = $self->{config}->{miogaconf}->GetMiogaPrefix () . "/bin/mioga2_index.pl --conf=" . $self->{config}->GetMiogaConfPath () 
362 363
+			. ' --search_conf=' . $self->{config}->{miogaconf}->GetInstallDir()."/conf/search_conf.xml" 
+                	. ' '. $self->Get ('ident');
364 365 366
 		system ("$crawlcmd");
 	}
 	elsif (scalar (keys (%{$self->{update}}))) {
367 368 369 370 371
diff --git a/lib/Mioga2/Magellan.pm b/lib/Mioga2/Magellan.pm
index 86e2e42..4b3814a 100644
--- a/lib/Mioga2/Magellan.pm
+++ b/lib/Mioga2/Magellan.pm
@@ -327,10 +327,13 @@ sub GetNodes {
Viktor Horvath's avatar
Viktor Horvath committed
372 373 374 375 376 377 378 379 380 381 382 383 384 385
 			$mygroup = $group;
 		}
 
+        my $host = $config->GetMiogaConf()->GetDAVHost();
+        $host = "[${host}]" if $host =~ /:.*?:/;
+
         my $resources = Mioga2::Magellan::DAV::GetCollection(
             $context,
             $context->GetSessionToken,
-            $config->GetMiogaConf ()->GetDAVProtocol () . "://" . $config->GetMiogaConf ()->GetDAVHost () . ":" . $config->GetMiogaConf ()->GetDAVPort (), $node
+            $config->GetMiogaConf ()->GetDAVProtocol () . "://" . $host . ":" . $config->GetMiogaConf ()->GetDAVPort (), $node
         );
 
 		$inconsistent = pop (@$resources);
386
@@ -853,7 +856,7 @@ sub GetResource {
387 388 389 390 391 392 393 394
 			);
 			print STDERR "mime = $mime\n content= $content\n" if ($debug);
 			if ($mime) {
-				#my $conv = Text::Iconv->new( 'utf8', 'utf8' );
+				#my $conv = Text::Iconv->new( 'UTF-8', 'UTF-8' );
 				#my $encoding = $conv->convert($content);
 				#if ($encoding) {
 				if ($mime =~ /(application\/xml)|(text\/)|(application\/xsl)/)
395 396 397 398 399
diff --git a/lib/Mioga2/Magellan/Archive.pm b/lib/Mioga2/Magellan/Archive.pm
index 842ae90..3b9e7f7 100644
--- a/lib/Mioga2/Magellan/Archive.pm
+++ b/lib/Mioga2/Magellan/Archive.pm
@@ -163,7 +163,7 @@ sub Content
400 401 402 403 404 405 406 407
         return undef;
     }
 
-    my $conv  = Text::Iconv->new('utf8', 'utf8');
+    my $conv  = Text::Iconv->new('UTF-8', 'UTF-8');
     my %folders;
     while(my $file = <PRG>) {
       chomp($file);
408 409 410 411 412
diff --git a/lib/Mioga2/Magellan/DAV.pm b/lib/Mioga2/Magellan/DAV.pm
index cdf77f1..116ebf4 100644
--- a/lib/Mioga2/Magellan/DAV.pm
+++ b/lib/Mioga2/Magellan/DAV.pm
@@ -106,7 +106,7 @@ sub ExecuteRequest
Viktor Horvath's avatar
Viktor Horvath committed
413 414 415 416 417 418 419 420
 	}
 
 	if ($response->code >= 500) {
-		warn "Mioga2::Magellan::ExecuteRequest Failed: " . $response->content;
+		warn "Mioga2::Magellan::DAV::ExecuteRequest Failed: " . $response->content;
 	}
 
 	return  $response;
421 422 423 424 425
diff --git a/lib/Mioga2/MailingList.pm b/lib/Mioga2/MailingList.pm
index c7d631c..3a92466 100644
--- a/lib/Mioga2/MailingList.pm
+++ b/lib/Mioga2/MailingList.pm
@@ -749,11 +749,11 @@ sub MailDeleteMsg
426 427 428 429 430 431 432 433 434 435 436 437 438 439
 sub CheckUTF8 {
     my ($str) = @_;
     
-    my $conv    = Text::Iconv->new('utf8', 'utf8');
+    my $conv    = Text::Iconv->new('UTF-8', 'UTF-8');
     my $tmp_str = $conv->convert($str);
     unless ($tmp_str) {
-        my $charset = detect($str) || 'iso-8859-15'; # defaults to latin9
-        $conv = Text::Iconv->new($charset, "utf8");
+        my $charset = detect($str) || 'ISO-8859-15'; # defaults to latin9
+        $conv = Text::Iconv->new($charset, "UTF-8");
         $str  = $conv->convert($str);
     }
     return $str;
440 441 442 443 444 445 446
diff --git a/lib/Mioga2/MiogaConf.pm b/lib/Mioga2/MiogaConf.pm
index 5b74a96..a46e27c 100644
--- a/lib/Mioga2/MiogaConf.pm
+++ b/lib/Mioga2/MiogaConf.pm
@@ -258,7 +258,7 @@ sub GetFilenameEncoding {
 sub GetBinariesDir {
 	my ($self) = @_;
Viktor Horvath's avatar
Viktor Horvath committed
447
 
448 449 450
-	return $self->{binaries_dir};
+	return $self->{bin_dir};
 }
Viktor Horvath's avatar
Viktor Horvath committed
451
 
452 453 454 455 456 457
 # ============================================================================
diff --git a/lib/Mioga2/Search.pm b/lib/Mioga2/Search.pm
index 2c20259..292f864 100644
--- a/lib/Mioga2/Search.pm
+++ b/lib/Mioga2/Search.pm
@@ -447,13 +447,13 @@ sub CheckArgs
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
 	elsif (exists($context->{args}->{query})) {
 		$query_string = $context->{args}->{query};
 	}
-	my $conv    = Text::Iconv->new('utf8', 'utf8');
+	my $conv    = Text::Iconv->new('UTF-8', 'UTF-8');
  	my $tmp_query = $conv->convert($query_string);
   
 	unless ($tmp_query) {
-		my $charset = detect($query_string) || 'iso-8859-15'; # defaults to latin9
+		my $charset = detect($query_string) || 'ISO-8859-15'; # defaults to latin9
 		warn "charset = '$charset' for query_string = '$query_string'" if $debug;
-		$conv = Text::Iconv->new($charset, "utf8");
+		$conv = Text::Iconv->new($charset, "UTF-8");
 		$query_string  = $conv->convert($query_string);
 		warn "==> converted query_string = '$query_string'" if $debug;
 	}
474 475 476 477 478
diff --git a/lib/Mioga2/tools/string_utils.pm b/lib/Mioga2/tools/string_utils.pm
index c56cc3b..36bfa5a 100644
--- a/lib/Mioga2/tools/string_utils.pm
+++ b/lib/Mioga2/tools/string_utils.pm
@@ -46,6 +46,7 @@ use Mioga2::Content::XSLT;
Viktor Horvath's avatar
Viktor Horvath committed
479 480 481 482 483 484 485
 use Mioga2::XML::Simple;
 use Exporter;
 use Text::Iconv;
+use Encode;
 use Encode::Detect::Detector;
 use Data::Dumper;
 use HTML::TokeParser::Simple;
486
@@ -715,11 +716,11 @@ Check if string is UTF8 and convert it if needed
Viktor Horvath's avatar
Viktor Horvath committed
487 488 489 490
 sub st_CheckUTF8 {
     my ($str) = @_;
     
-    my $conv    = Text::Iconv->new('utf8', 'utf8');
491 492 493
+    my $conv    = Text::Iconv->new('UTF-8', 'UTF-8');
     my $tmp_str = $conv->convert($str);
     unless ($tmp_str) {
494
-        my $charset = detect($str) || 'iso-8859-15'; # defaults to latin9
Viktor Horvath's avatar
Viktor Horvath committed
495
-        $conv = Text::Iconv->new($charset, "utf8");
496
+        my $charset = detect($str) || 'ISO-8859-15'; # defaults to latin9
497
+        $conv = Text::Iconv->new($charset, "UTF-8");
Viktor Horvath's avatar
Viktor Horvath committed
498 499 500
         $str  = $conv->convert($str);
 		utf8::decode ($str);
     }
501 502 503 504 505
diff --git a/lib/MiogaConf.pm b/lib/MiogaConf.pm
index 0870174..bbcc80a 100644
--- a/lib/MiogaConf.pm
+++ b/lib/MiogaConf.pm
@@ -836,6 +836,10 @@ sub CheckDepends
506 507 508 509 510 511 512 513 514 515
 	my @missing;
 	my @missing_clib;
 
+	# Some modules rewrite $ENV{PATH} without hesitation when "require"d,      
+	# we need to put the old one back in place.                                
+	my $oldpath = $ENV{PATH}; 
+
 	foreach my $dep (@{$self->{CONFIG}->{dependencies}->[0]->{dep}}) {
 		my $version;
 		if(exists $dep->{version}) {
516
@@ -858,6 +862,7 @@ sub CheckDepends
517 518 519 520 521 522 523
 		}
 	}
 	
+	$ENV{PATH} = $oldpath;
 
 	foreach my $dep (@{$self->{CONFIG}->{dependencies}->[0]->{clib}}) {
 		my $version;
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
diff --git a/sql/Makefile b/sql/Makefile
index 07b26f5..f6b6c0f 100644
--- a/sql/Makefile
+++ b/sql/Makefile
@@ -1,4 +1,5 @@
 include ../config.mk
+DB_STATE=`perl -w testdb.pl`
 
 all:
 
@@ -15,19 +16,20 @@ install:
 	cp upgradeMiogletDesc.pl $(DESTDIR)$(INSTALL_DIR)/conf/Config.hook.d
 	chmod a+x $(DESTDIR)$(INSTALL_DIR)/conf/Config.hook.d/upgradeMiogletDesc.pl
 
-	if [ $(INIT_SQL) = 'yes' ] ; \
+	if [ $(DB_STATE) = 'nodb' ] ; \
540 541
 	then \
 		echo "Initialize database"; \
542 543 544
-		su - $(POSTGRES_USER) -c "dropdb $(DB_NAME)" ; \
-		su - $(POSTGRES_USER) -c "createdb --encoding UTF8 $(DB_NAME)" && \
-		su $(POSTGRES_USER) -c "psql $(DB_NAME) < create_lang.sql" && \
545 546
-		perl -w -I../lib initdb.pl ; \
-	elif [ $(INIT_SQL) != 'noupdate' ]; then \
547 548 549
+        dropdb -h $(DB_HOST) -p $(DB_PORT) -U $(DBI_LOGIN) $(DB_NAME) ; \
+		createdb --encoding UTF8 -h $(DB_HOST) -p $(DB_PORT) -U $(DBI_LOGIN) $(DB_NAME) && \
+		psql -h $(DB_HOST) -p $(DB_PORT) -U $(DBI_LOGIN) $(DB_NAME) < create_lang.sql && \
550 551
+		perl -w -I../lib initdb.pl force_init_sql=1; \
+	elif [ $(DB_STATE) = 'present' ]; then \
552
 		echo "Update database"; \
553 554 555 556 557 558 559 560 561 562 563 564 565 566
 		perl -w -I../lib updatedb.pl configxml=$(DESTDIR)$(INSTALL_DIR)/conf/Config.xml; \
+	elif [ $(DB_STATE) = 'noserver' ]; then \
+		echo "ERROR: Cannot connect to the database server!"; \
 	fi
 
-
 clean:
 	rm -f *~
 
diff --git a/sql/schema_base.sql b/sql/schema_base.sql
index b7d8cc2..88d5e2d 100644
--- a/sql/schema_base.sql
+++ b/sql/schema_base.sql
@@ -429,10 +429,6 @@ CREATE OR REPLACE FUNCTION check_group_base_default_profile_id () RETURNS trigge
Viktor Horvath's avatar
Viktor Horvath committed
567 568 569 570 571 572 573 574 575 576
     END;
 ' LANGUAGE 'plpgsql';
 
-CREATE TRIGGER m_group_base_default_profile_id_check
-     BEFORE DELETE ON m_profile FOR EACH ROW
-     EXECUTE PROCEDURE check_group_base_default_profile_id ();
-
 
 CREATE OR REPLACE FUNCTION check_group_base_mioga_id () RETURNS trigger AS '
     DECLARE
577
@@ -839,6 +835,10 @@ create table m_profile (
Viktor Horvath's avatar
Viktor Horvath committed
578 579 580 581 582 583 584 585 586 587
 );
 create unique index m_profile_ident_group_index on m_profile (ident, group_id);
 
+CREATE TRIGGER m_group_base_default_profile_id_check
+     BEFORE DELETE ON m_profile FOR EACH ROW
+     EXECUTE PROCEDURE check_group_base_default_profile_id ();
+
 
 --
 -- Add referencial integrity on default_profile_id in m_group_base
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
diff --git a/sql/testdb.pl b/sql/testdb.pl
new file mode 100755
index 0000000..2fa3fe7
--- /dev/null
+++ b/sql/testdb.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/perl -w
+
+# Tests the availability of the Mioga2 database.
+# Returns on stdout one of:
+# 'present'  - The Mioga2 database has been found.
+# 'nodb'     - There is no Mioga2 database but the database server is working fine
+#              (i.e. one can try to create the database)
+# 'noserver' - Connection to the database server failed.
+
+# This has been written for Mioga2/SlapOS, to avoid overwriting the database
+# when re-instantiating the Apache/mod_perl partition.
+
+use strict;
+use lib "../lib";
+
+use Data::Dumper;
+use Error qw(:try);
+use Mioga2::Exception::DB;
+use Mioga2::MiogaConf;
+
+# TODO: get this through a parameter?
+# my $configxml = "../conf/Config.xml";
+my $miogaconf = "../web/conf/Mioga.conf";
+
+try {
+    my $config = new Mioga2::MiogaConf($miogaconf);
+    print 'present';
+} catch Mioga2::Exception::DB with {
+    my $err = shift;
+    if ($err->getDBerror() =~ m#database "mioga2" does not exist#) {
+        print 'nodb';
+    } else {
+        print 'noserver';
+    }
+} otherwise {
+    print 'noserver';
+}
diff --git a/web/Makefile b/web/Makefile
index 66af45f..9649a02 100644
--- a/web/Makefile
+++ b/web/Makefile
@@ -16,11 +16,11 @@ all ::
 
 
 install ::
-	if [ $(INIT_SQL) = 'yes' -a -d $(INSTALL_DIR) ] ; \
-	then \
-	     su - $(POSTGRES_USER) -c "pg_dump -b -Ft --column-inserts $(DB_NAME) | gzip" > ${INSTALL_DIR}/db_dump.tar.gz ; \
-	     mv $(INSTALL_DIR) $(BACKUP_DIR) ; \
-        fi
+#	if [ $(INIT_SQL) = 'yes' -a -d $(INSTALL_DIR) ] ; \
+#	then \
+#	     su - $(POSTGRES_USER) -c "pg_dump -b -Ft --column-inserts $(DB_NAME) | gzip" > ${INSTALL_DIR}/db_dump.tar.gz ; \
+#	     mv $(INSTALL_DIR) $(BACKUP_DIR) ; \
+#       fi
 
 	mkdir -p $(TMP_DIR)
 	mkdir -p $(DESTDIR)$(INSTALL_DIR)/$(INSTANCE_IDENT)/$(MIOGA_FILES)
diff --git a/web/conf/startup.pl b/web/conf/startup.pl
index a9dc968..6558061 100644
--- a/web/conf/startup.pl
+++ b/web/conf/startup.pl
@@ -29,6 +29,7 @@ use MIME::Entity ();
657 658 659 660 661 662 663
 use MIME::Parser ();
 use MIME::QuotedPrint ();
 use MiogaConf ();
+use Net::INET6Glue::INET_is_INET6;
 use Net::LDAP ();
 use Parse::Yapp::Driver ();
 use Storable ();
664 665 666 667 668 669 670 671 672 673 674 675 676
diff --git a/web/skel/Makefile b/web/skel/Makefile
index e604e7d..fbaad2d 100644
--- a/web/skel/Makefile
+++ b/web/skel/Makefile
@@ -33,7 +33,7 @@ fr_FR : $(SRC_FR_FILES)
 install:
 	rsync $(RSYNC_OPTS) $(SUBDIRS) $(DESTDIR)$(INSTALL_DIR)/conf/skel/
 	# Update instance default skeletons
-	for i in `mioga2_info.pl --conf=$(DESTDIR)$(INSTALL_DIR)/conf/Mioga.conf instances`; do if [ ! -d /var/lib/Mioga2/$$i/MiogaFiles/skel/ ]; then mkdir $(DESTDIR)$(INSTALL_DIR)/$$i/MiogaFiles/skel/; fi; cp -R $(DESTDIR)$(INSTALL_DIR)/conf/skel/* $(DESTDIR)$(INSTALL_DIR)/$$i/MiogaFiles/skel/; done
+#	for i in `mioga2_info.pl --conf=$(DESTDIR)$(INSTALL_DIR)/conf/Mioga.conf instances`; do if [ ! -d /var/lib/Mioga2/$$i/MiogaFiles/skel/ ]; then mkdir $(DESTDIR)$(INSTALL_DIR)/$$i/MiogaFiles/skel/; fi; cp -R $(DESTDIR)$(INSTALL_DIR)/conf/skel/* $(DESTDIR)$(INSTALL_DIR)/$$i/MiogaFiles/skel/; done
 
 clean:
 	rm -rf $(SUBDIRS)