mioga-patch 21.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
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
index 3582d20..0d9ef77 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -115,7 +115,7 @@ my $docsubdirs = "docs";
19 20 21 22 23 24 25 26
 # ----------------------------------------------------------------------------
 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
27
@@ -124,10 +124,7 @@ tardist: doc
28 29 30 31 32 33 34 35 36 37 38
 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 \
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
@@ -156,6 +153,29 @@ install-all ::
 
 	(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)"
+	cp -R --parents Makefile.PL sql web/conf conf "$(MIOGA_BUILDINST)"
+
+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 \
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
74 75 76 77 78 79 80 81 82 83 84 85 86
 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;
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
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
114 115 116 117 118 119 120 121 122 123
@@ -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"/>
124 125 126
@@ -35,8 +38,18 @@
     <parameter name="authentication" question="Authentification method ?" 
                type="enum" default="Mioga2" values="Mioga2"
127
                xpath="/authentication"/>
128 129 130 131 132 133
-    
+
+    <parameter name="bin_dir" question="Directory for helper scripts and binaries ?" 
+               type="text" default="/usr/local/bin"
+               xpath="/bin_dir"/>
+
134 135 136 137 138 139 140 141 142 143
     <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"/>              
144 145 146 147 148
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 {
149 150 151 152 153 154 155 156 157 158 159 160 161 162
 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;
163 164 165 166 167
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
168 169 170
   
   # convert uri to UTF-8
   my $uri     = uri_unescape($options{uri});
171 172 173
+    
   
   # attempt to see if uri is utf8 to avoid detection
Viktor Horvath's avatar
Viktor Horvath committed
174
-  my $conv    = Text::Iconv->new('utf8', 'utf8');
175 176
+  my $conv    = Text::Iconv->new('UTF-8', 'UTF-8');
   my $tmp_uri = $conv->convert($uri);
Viktor Horvath's avatar
Viktor Horvath committed
177
-  
178 179
+
   unless ($tmp_uri) {
180 181
-    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
182 183
     warn "charset = '$charset' for uri = '$uri'" if $debug;
-    $conv = Text::Iconv->new($charset, "utf8");
184
+    $conv = Text::Iconv->new($charset, "UTF-8");
Viktor Horvath's avatar
Viktor Horvath committed
185 186 187
     $uri  = $conv->convert($uri);
     warn "==> converted uri = '$uri'" if $debug;
   }
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
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;
206 207 208 209
 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
210 211 212 213 214 215 216 217
 use XML::LibXML ();
 use Mioga2::Constants;
 
-my $debug = 0;
+my $debug = 5;
 
 my $MULTI_STATUS	= 207;	# code DAV for the Multi-status response
 
218
@@ -756,13 +757,17 @@ sub make_request {
Viktor Horvath's avatar
Viktor Horvath committed
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
 	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;
 
237
@@ -774,7 +779,7 @@ sub make_request {
Viktor Horvath's avatar
Viktor Horvath committed
238 239 240 241 242 243 244 245
 
 		# 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);
 		}
246 247 248 249 250
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
251 252 253 254 255 256 257 258
 	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);
 		}
259
@@ -72,8 +72,10 @@ sub new {
Viktor Horvath's avatar
Viktor Horvath committed
260 261 262 263 264 265 266 267 268 269 270
 	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);
 
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
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
291
 
292 293 294 295 296 297
 =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 {
298 299 300
 		$conf->RunHooks($self->{config}->{miogaconf});
 
 		# Run crawl.sh to initialize search engine database
301
-		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');
302
+		my $crawlcmd = $self->{config}->{miogaconf}->GetMiogaPrefix () . "/bin/mioga2_index.pl --conf=" . $self->{config}->GetMiogaConfPath () 
303 304
+			. ' --search_conf=' . $self->{config}->{miogaconf}->GetInstallDir()."/conf/search_conf.xml" 
+                	. ' '. $self->Get ('ident');
305 306 307
 		system ("$crawlcmd");
 	}
 	elsif (scalar (keys (%{$self->{update}}))) {
308 309 310 311 312
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
313 314 315 316 317 318 319 320 321 322 323 324 325 326
 			$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);
327
@@ -853,7 +856,7 @@ sub GetResource {
328 329 330 331 332 333 334 335
 			);
 			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)/)
336 337 338 339 340
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
341 342 343 344 345 346 347 348
         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);
349 350 351 352 353
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
354 355 356 357 358 359 360 361
 	}
 
 	if ($response->code >= 500) {
-		warn "Mioga2::Magellan::ExecuteRequest Failed: " . $response->content;
+		warn "Mioga2::Magellan::DAV::ExecuteRequest Failed: " . $response->content;
 	}
 
 	return  $response;
362 363 364 365 366
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
367 368 369 370 371 372 373 374 375 376 377 378 379 380
 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;
381 382 383 384 385 386 387
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
388
 
389 390 391
-	return $self->{binaries_dir};
+	return $self->{bin_dir};
 }
Viktor Horvath's avatar
Viktor Horvath committed
392
 
393 394 395 396 397 398
 # ============================================================================
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
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
 	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;
 	}
415 416 417 418 419
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
420 421 422 423 424 425 426
 use Mioga2::XML::Simple;
 use Exporter;
 use Text::Iconv;
+use Encode;
 use Encode::Detect::Detector;
 use Data::Dumper;
 use HTML::TokeParser::Simple;
427
@@ -715,11 +716,11 @@ Check if string is UTF8 and convert it if needed
Viktor Horvath's avatar
Viktor Horvath committed
428 429 430 431
 sub st_CheckUTF8 {
     my ($str) = @_;
     
-    my $conv    = Text::Iconv->new('utf8', 'utf8');
432 433 434
+    my $conv    = Text::Iconv->new('UTF-8', 'UTF-8');
     my $tmp_str = $conv->convert($str);
     unless ($tmp_str) {
435
-        my $charset = detect($str) || 'iso-8859-15'; # defaults to latin9
Viktor Horvath's avatar
Viktor Horvath committed
436
-        $conv = Text::Iconv->new($charset, "utf8");
437
+        my $charset = detect($str) || 'ISO-8859-15'; # defaults to latin9
438
+        $conv = Text::Iconv->new($charset, "UTF-8");
Viktor Horvath's avatar
Viktor Horvath committed
439 440 441
         $str  = $conv->convert($str);
 		utf8::decode ($str);
     }
442 443 444 445 446
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
447 448 449 450 451 452 453 454 455 456
 	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}) {
457
@@ -858,6 +862,7 @@ sub CheckDepends
458 459 460 461 462 463 464
 		}
 	}
 	
+	$ENV{PATH} = $oldpath;
 
 	foreach my $dep (@{$self->{CONFIG}->{dependencies}->[0]->{clib}}) {
 		my $version;
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
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' ] ; \
481 482
 	then \
 		echo "Initialize database"; \
483 484 485
-		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" && \
486 487
-		perl -w -I../lib initdb.pl ; \
-	elif [ $(INIT_SQL) != 'noupdate' ]; then \
488 489 490
+        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 && \
491 492
+		perl -w -I../lib initdb.pl force_init_sql=1; \
+	elif [ $(DB_STATE) = 'present' ]; then \
493
 		echo "Update database"; \
494 495 496 497 498 499 500 501 502 503 504 505 506 507
 		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
508 509 510 511 512 513 514 515 516 517
     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
518
@@ -839,6 +835,10 @@ create table m_profile (
Viktor Horvath's avatar
Viktor Horvath committed
519 520 521 522 523 524 525 526 527 528
 );
 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
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
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 ();
598 599 600 601 602 603 604
 use MIME::Parser ();
 use MIME::QuotedPrint ();
 use MiogaConf ();
+use Net::INET6Glue::INET_is_INET6;
 use Net::LDAP ();
 use Parse::Yapp::Driver ();
 use Storable ();
605 606 607 608 609 610 611 612 613 614 615 616 617
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)