#----------------------------------------------------------------------
#
# copyright (C) Decaux Nicolas Aka 'GawiNDX'
# contributor: Nicolas Decaux <decauxnico@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
#----------------------------------------------------------------------
# Mozilla Updates Server
{
    use esmith::db;
    use esmith::config;
    use esmith::ConfigDB;

    $OUT = "";

    my $c = esmith::ConfigDB->open_ro('Mozus');
    my $mozusstatus = $c->get('Mozus')->prop('status') || 'disabled' ;
    if  ( $mozusstatus eq 'enabled' ) {
	my $mirrordir = $c->get('Mozus')->prop('mirrordir') || '/opt/mozilla-updates/mirror';
	my $sogoplug_dir = $c->get('Mozus')->prop('SOGo-pluginsDir') || '/opt/mozilla-updates/SOGo-plugins';
	my $access = $c->get('Mozus')->prop('access') || 'private';

	$OUT .= "Alias /moz-updates $mirrordir\n\n";
	$OUT .= "<Directory $mirrordir>\n"
		    ."    Options None\n"
		    ."    Options +Indexes\n"
		    ."    Options +Includes\n"
       	    ."    AllowOverride None\n"
	           ."    order deny,allow\n"
       	    ."    deny from all\n"
       	    ."    IndexIgnore updates\n"
		    ."    <FILES updates>\n"
		    ."    	ForceType application/x-httpd-php\n"
		    ."    </FILES>\n";
	if ("$access" eq "private")
	    {
	    $OUT .= "    allow from $localAccess $externalSSLAccess\n";
	    }
	    elsif ("$access" eq "public")
	    {
	    $OUT .= "    allow from all\n";
	    }
	$OUT .= "   php_flag short_open_tag off\n"
		 ."</Directory>\n\n";
	$OUT .= "# SOGo-plugins Server\n";
	$OUT .= "Alias /SOGo-plugins $sogoplug_dir\n\n"
	       ."<Directory $sogoplug_dir>\n"
	       ."     Options None\n"
	       ."     Options +Indexes\n"
	       ."     Options +Includes\n"
	       ."     Options +FollowSymLinks\n"
      	   	."     AllowOverride None\n"
	       ."     order deny,allow\n"
	       ."     deny from all\n"
	       ."     IndexIgnore updates.php\n"
	       ."     IndexIgnore *.crt\n"
	       ."     <FILES updates.php>\n"
	       ."    		ForceType application/x-httpd-php\n"
	       ."     </FILES>\n";
	if ("$access" eq "private")
	    {
	    $OUT .= "     allow from $localAccess $externalSSLAccess\n";
	    }
	    elsif ("$access" eq "public")
	    {
	    $OUT .= "     allow from all\n";
	    }
	$OUT .= "</Directory>\n";
   }
}
