#!/usr/bin/perl 

########## Confixx(R) 3.0 Professional ############
####### Copyright SWsoft, Inc. 2004-2005 ##########
#### http://www.sw-soft.com - info@sw-soft.com ####


# DBI : 3
# IO: 0

## Pre-Main

BEGIN { 
    use FindBin; 
    use lib "$FindBin::Bin/subs"; 
    use lib "$FindBin::Bin/../"; # = $installDir 
} 
use File::Basename;
use DBI;

use lib_module_common;
use lib_module_db;

use Modules::Cronjobs qw(&del_crontab);

use strict;

use vars qw( $server_mail $use_confixx_updates $use_mail 
						 $VERSION $VERSION_PRO $VERSION_LIGHT1 $VERSION_LIGHT2
						 $dbh );

my @mtas = ('sendmail', 'postfix', 'qmail');
my $confixxInstallScript = 1; # fake ;-)

&initConfig;

my $wDir = "$installDir/admin";

my $proFTPD_install_script = "$installDir/admin/subs/proFTPD_install.pl";
my $wuftpd_install_script = "$installDir/admin/subs/wu-ftpd_install.pl";
my $sendmail_install_script = "$installDir/admin/subs/sendmail_install.pl";
my $qmail_install_script = "$installDir/admin/subs/qmail_install.pl";
my $postfix_install_script = "$installDir/admin/subs/postfix_install.pl";

my $spamassassin_install_script = "$installDir/admin/subs/spamassassin_install.pl";
my $spamassassin_wizard_script = "$installDir/admin/subs/spamassassin_wizard.pl";

my $cgisInstall = "$installDir/admin/subs/cgis_install.pl";


foreach my $script qw ( subs_include_modules.pl
												subs_include_files.pl
												subs_include_questions.pl
												subs_include_writeConfig.pl
												subs_include_IDN.pl
												IDN_install.pl
												subs_include_webInstall.pl
												MySQLLogin_install.pl
												scponly_install.pl
												subs_include_mhost.pl
												subs_include_majo.pl
												majordomo_install.pl
												subs_include_db.pl
											){
	safe_do "$installDir/admin/subs/$script";
}

safe_do "$installDir/subs_include_quota.pl";

&ReadMainConfigFile;
## Pre-Main

## Main
$dbh = DBI->connect($db_address, $dbUser, $dbPw) or 
	die &ltext('db_connect', '#2001', $DBI::errstr);
&getVersion;
&MainMenue;
$dbh->disconnect;
## /Main

## Unterprogramme

sub MainMenue
{
  my (%defaults, $menue, %auswahl, %changes, $change, $quit, $return, $sth, @row);
  $quit = 0;
  while($quit != 1){
    if($quit == 2){
      $quit = 0;
    }
    system("clear");
    &header2( &ltext('admin_main_head') );
    print &ltext('admin_main_intro');
    if ( $server_mail ne '0' ) {
      $menue = &Selection(&ltext('admin_main_common'), &ltext('admin_main_web'),
			  &ltext('admin_main_mail'), &ltext('admin_main_language'));
    }else{
      $menue = &Selection(&ltext('admin_main_common'), &ltext('admin_main_web'),
			  &ltext('admin_main_language'));
    }
	
    if($menue eq &ltext('admin_main_common')){
      $sth = $dbh->prepare("SELECT quota, statistik, webftp, mysql, shell, subdomains, ftp, stdcgi,".
				    "dns,dnr,cronjobs,checkupdates,idn,scponly FROM admin");

      $sth->execute or die("$DBI::errstr");
      @row = $sth->fetchrow_array;
      if($row[8] eq "1"){
	%defaults = (&ltext('admin_name_quota') => "$row[0]",
		     &ltext('admin_name_webalizer') => "$row[1]",
		     &ltext('admin_name_webftp') => "$row[2]",
		     &ltext('admin_name_mysql') => "$row[3]",
		     &ltext('admin_name_shell') => "$row[4]",
		     &ltext('admin_name_scponly') => "$row[13]",
		     &ltext('admin_name_subdomains') => "$row[5]",
		     &ltext('admin_name_ftp') => "$row[6]",
		     &ltext('admin_name_stdcgi') => "$row[7]",
		     &ltext('admin_name_dns') => "$row[8]",
		     &ltext('admin_name_cronjobs') => "$row[10]",
		     &ltext('admin_name_confixx_updates') => "$row[11]",
		     &ltext('admin_name_dnr') => "$row[9]",
		     &ltext('admin_name_unzip') => $bin_unzip ne "",
		     &ltext('admin_name_IDN') => "$row[12]");
      } else  {
	%defaults = (&ltext('admin_name_quota') => "$row[0]",
		     &ltext('admin_name_webalizer') => "$row[1]",
		     &ltext('admin_name_webftp') => "$row[2]",
		     &ltext('admin_name_mysql') => "$row[3]",
		     &ltext('admin_name_shell') => "$row[4]",
		     &ltext('admin_name_scponly') => "$row[13]",
		     &ltext('admin_name_subdomains') => "$row[5]",
		     &ltext('admin_name_ftp') => "$row[6]",
		     &ltext('admin_name_stdcgi') => "$row[7]",
		     &ltext('admin_name_dns') => "$row[8]",
		     &ltext('admin_name_cronjobs') => "$row[10]",
		     &ltext('admin_name_confixx_updates') => "$row[11]",
		     &ltext('admin_name_unzip') => $bin_unzip ne "",
		     &ltext('admin_name_IDN') => "$row[12]"
		  );
      }
    }
    elsif($menue eq &ltext('admin_main_web')){
      $sth = $dbh->prepare("SELECT cssl, frontpage, ssi, wap, perl, coldfusion, modpython FROM admin");
      $sth->execute or die("$DBI::errstr");
      @row = $sth->fetchrow_array;
      %defaults = (&ltext('admin_name_ssl') => "$row[0]",
		   &ltext('admin_name_fp') => "$row[1]",
		   &ltext('admin_name_ssi') => "$row[2]",
		   &ltext('admin_name_wap') => "$row[3]",
		   &ltext('admin_name_cgiperl') => "$row[4]",
		   &ltext('admin_name_modpython') => "$row[6]",
		   &ltext('admin_name_coldfusion') => "$row[5]"
		  );
    }elsif($menue eq &ltext('admin_main_mail')){
      $sth = $dbh->prepare("SELECT webmail, autoresponder, spamfilter,majordomo FROM admin");
      $sth->execute or die("$DBI::errstr");
      @row = $sth->fetchrow_array;
      %defaults = (&ltext('admin_name_webmail') => "$row[0]",
		   &ltext('admin_name_autoresponder') => "$row[1]",
		   &ltext('admin_name_spamfilter') => "$row[2]",
		   &ltext('admin_name_majo') => "$row[3]"
		);
    } elsif($menue eq &ltext('admin_main_language')){
      system("clear");
      &header2( &ltext('admin_sub_head', &ltext('admin_main_language') ) );
      &choose_language;
      &UpdateMainConfig;
      $quit = 2;
    }elsif($menue == 0){
      $quit = 1;
    }elsif($menue == 99){
      $quit = 2;
    }

    unless($quit)	{
      $return = 2;
      while(!($return == 1 || $return == 0)) {
	%auswahl = &Auswahl($menue, %defaults);
	$change = 0;

	($change, %changes) = &CheckChanges( \%defaults, \%auswahl );

	if($change){
	  $return = &Test(%changes);
	  if($return == 1){
	    &Change(%changes);
	  }
	}else{
	  $return = 0;
	}
      }
    }else	{
      #system("clear");
    }
  }
}


sub Auswahl{
  my ($name, %items) = @_;
  my (@itemsarray,$lastItem,$i,$item);
  $lastItem = 0;
  $i = 0;
  $itemsarray[$i++] = &ltext('admin_select_continue');
  foreach $item ( sort { uc($a) cmp uc($b) } keys(%items) ){
    $itemsarray[$i++] = $item;
    $lastItem++;
  }
  my ($count, $index, $tickbox);
  my $auswahl = -1;
  system("clear");
  while ($auswahl !~ /^\d+$/ || (!($auswahl == 0))){
    &header2( &ltext('admin_sub_head', $name) );
    print &ltext('admin_sub_intro', "1..$lastItem", '0');
    print "\n";
    $~ = "MAIN";
    for ($count = 1; $count <= $lastItem; $count++){
      $index = "($count)";
      if ($items{$itemsarray[$count]}){
        $tickbox = "[X]";
      }
      else{
        $tickbox = "[ ]";
      }
      write;
    }
    print &ltext('admin_select_promt',  $itemsarray[0]);
    $auswahl = <STDIN>;
    chop ($auswahl);
    if ($auswahl =~ /^\d+$/ && $auswahl >= 0 && $auswahl <= $lastItem){
      if ($items{$itemsarray[$auswahl]}){
        $items{$itemsarray[$auswahl]} = 0;
      }
      else{
        $items{$itemsarray[$auswahl]} = 1;
      }
    }
    if ($auswahl !~ /\d+/ || $auswahl != 0){
      system("clear");
    }
  }

format MAIN =
 @>>> @<<<<<<<<<<<<<<< @<<
$index, $itemsarray[$count] , $tickbox
.

  return(%items);
}


sub CheckChanges{
  my ($vor, $nach) = @_;

  my ( %return, $changes, $feature);

  $changes = 0;
  foreach $feature (keys(%{$vor})){
    if($vor->{$feature} > $nach->{$feature}){
      $return{$feature} = 0;
      $changes = 1;
    }
    elsif($vor->{$feature} < $nach->{$feature}){
      $return{$feature} = 1;
      $changes = 1;
    }
  }
  return($changes, %return);
}


sub Test{
  my (%changes) = @_;
  my ($return, $weiter, $antwort, $sth, $num);
  system("clear");
  ## Webserver
  if(defined $changes{&ltext('admin_name_ssl')}){
    print &ltext('admin_feature_check', &ltext('admin_name_ssl'));
    if($changes{&ltext('admin_name_ssl')}){
      print &ltext('admin_feature_on', &ltext('admin_name_ssl'));
    }
    else{
      $num = 0;
      $sth = $dbh->prepare("SELECT count(cssl) FROM domains WHERE cssl > 0");
      $sth->execute or die("$DBI::errstr");
      $num = $sth->fetchrow;
      if($num){
        print &ltext('admin_feature_count', $num, &ltext('admin_name_ssl'));
      }
    }
  }
  if(defined $changes{&ltext('admin_name_cgiperl')}){
    print &ltext('admin_feature_check', &ltext('admin_name_cgiperl'));
    if($changes{&ltext('admin_name_cgiperl')}){
      print &ltext('admin_feature_on', &ltext('admin_name_cgiperl'));
    }
    else{
      $num = 0;
      $sth = $dbh->prepare("SELECT count(perl) FROM kunden WHERE perl > 0");
      $sth->execute or die("$DBI::errstr");
      $num = $sth->fetchrow;
      if($num){
        print &ltext('admin_feature_count', $num, &ltext('admin_name_cgiperl'));
      }
    }
  }
  if(defined $changes{&ltext('admin_name_modpython')}){
    print &ltext('admin_feature_check', &ltext('admin_name_modpython'));
    if($changes{&ltext('admin_name_modpython')}){
      print &ltext('admin_feature_on', &ltext('admin_name_modpython'));
    }
    else{
      $num = 0;
      $sth = $dbh->prepare("SELECT count(*) FROM kunden WHERE modpython > 0");
      $sth->execute or die("$DBI::errstr");
      $num = $sth->fetchrow;
      if($num){
        print &ltext('admin_feature_count', $num, &ltext('admin_name_modpython'));
      }
    }
  }
  if(defined $changes{&ltext('admin_name_ssi')}){
    print &ltext('admin_feature_check', &ltext('admin_name_ssi'));
    if($changes{&ltext('admin_name_ssi')}){
      print &ltext('admin_feature_on', &ltext('admin_name_ssi'));
    }
    else{
      $num = 0;
      $sth = $dbh->prepare("SELECT count(ssi) FROM kunden WHERE ssi=1");
      $sth->execute or die("$DBI::errstr");
      $num = $sth->fetchrow;
      if($num){
        print &ltext('admin_feature_count', $num, &ltext('admin_name_ssi'));
      }
    }
  }
  if(defined $changes{&ltext('admin_name_fp')}){
    print &ltext('admin_feature_check', &ltext('admin_name_fp'));
    if($changes{&ltext('admin_name_fp')}){
      print &ltext('admin_feature_on', &ltext('admin_name_fp'));
    }
    else{
      $num = 0;
      $sth = $dbh->prepare("SELECT count(frontpage) FROM kunden WHERE frontpage=1");
      $sth->execute or die("$DBI::errstr");
      $num = $sth->fetchrow;
      if($num){
        print &ltext('admin_feature_count', $num, &ltext('admin_name_fp'));
      }
    }
  }
  if(defined $changes{&ltext('admin_name_wap')}){
    print &ltext('admin_feature_check', &ltext('admin_name_wap'));
    if($changes{&ltext('admin_name_wap')}){
      print &ltext('admin_feature_on', &ltext('admin_name_wap'));
    }
    else{
      $num = 0;
      $sth = $dbh->prepare("SELECT count(wap) FROM kunden WHERE wap=1");
      $sth->execute or die("$DBI::errstr");
      $num = $sth->fetchrow;
      if($num){
        print &ltext('admin_feature_count', $num, &ltext('admin_name_wap'));
      }
    }
  }
  if(defined $changes{&ltext('admin_name_coldfusion')}){
    print &ltext('admin_feature_check', &ltext('admin_name_coldfusion'));
    if($changes{&ltext('admin_name_coldfusion')}){
      print &ltext('admin_feature_on', &ltext('admin_name_coldfusion'));
    }
    else{
      $num = 0;
      $sth = $dbh->prepare("SELECT count(coldfusion) FROM kunden WHERE coldfusion>0");
      $sth->execute or die("$DBI::errstr");
      $num = $sth->fetchrow;
      if($num){
        print &ltext('admin_feature_count', $num, &ltext('admin_name_coldfusion'));
      }
    }
  }
  ## /Webserver

  ## Allgemein
  if(defined $changes{&ltext('admin_name_shell')}){
    print &ltext('admin_feature_check', &ltext('admin_name_shell'));
    if($changes{&ltext('admin_name_shell')}){
       print &ltext('admin_feature_on', &ltext('admin_name_shell'));
    }
    else{
      $num = 0;
      $sth = $dbh->prepare("SELECT count(shell) FROM kunden WHERE shell=1");
      $sth->execute or die("$DBI::errstr");
      $num = $sth->fetchrow;
      if($num){
        print &ltext('admin_feature_count', $num, &ltext('admin_name_shell'));
      }
    }
  }

  if(defined $changes{&ltext('admin_name_scponly')}){
    print &ltext('admin_feature_check', &ltext('admin_name_scponly'));
    if($changes{&ltext('admin_name_scponly')}){
       print &ltext('admin_feature_on', &ltext('admin_name_scponly'));
    }
    else{
      $num = 0;
      $sth = $dbh->prepare("SELECT count(scponly) FROM kunden WHERE scponly=1");
      $sth->execute or die("$DBI::errstr");
      $num = $sth->fetchrow;
      if($num){
        print &ltext('admin_feature_count', $num, &ltext('admin_name_scponly'));
      }
    }
  }

  if(defined $changes{&ltext('admin_name_quota')}){
    print &ltext('admin_feature_check', &ltext('admin_name_quota'));
    if($changes{&ltext('admin_name_quota')}){
       print &ltext('admin_feature_quota_on');
    }
    else{
       print &ltext('admin_feature_quota_off');
    }
  }
  if(defined $changes{&ltext('admin_name_webalizer')}){
    print &ltext('admin_feature_check', &ltext('admin_name_webalizer'));
    if($changes{&ltext('admin_name_webalizer')}){
      print &ltext('admin_feature_on', &ltext('admin_name_webalizer'));
    }
    else{
      $num = 0;
      $sth = $dbh->prepare("SELECT count(statistik) FROM kunden WHERE statistik=1");
      $sth->execute or die("$DBI::errstr");
      $num = $sth->fetchrow;
      if($num){
        print &ltext('admin_feature_count', $num, &ltext('admin_name_webalizer'));
      }
    }
  }


  if(defined $changes{&ltext('admin_name_dns')}){
    print &ltext('admin_feature_check', &ltext('admin_name_dns'));
    if($changes{&ltext('admin_name_dns')}){
      print &ltext('admin_feature_on', &ltext('admin_name_dns'));
    }
    else{
      $num = 0;
      $sth = $dbh->prepare("SELECT count(dns) FROM anbieter WHERE dns=1");
      $sth->execute or die("$DBI::errstr");
      if($num){
        print &ltext('admin_feature_count', $num, &ltext('admin_name_dns'));
      }
    }
  }
  if(defined $changes{&ltext('admin_name_dnr')}){
    print &ltext('admin_feature_check', &ltext('admin_name_dnr'));
    if($changes{&ltext('admin_name_dnr')}){
      print &ltext('admin_feature_on', &ltext('admin_name_dnr'));
    }
    else{
      $num = 0;
      $sth = $dbh->prepare("SELECT count(dnr) FROM anbieter WHERE dnr=1");
      $sth->execute or die("$DBI::errstr");
      if($num){
        print &ltext('admin_feature_count', $num, &ltext('admin_name_dnr'));
      }
    }
  }


  if(defined $changes{&ltext('admin_name_subdomains')}){
    print &ltext('admin_feature_check', &ltext('admin_name_subdomains'));
    if($changes{&ltext('admin_name_subdomains')}){
      print &ltext('admin_feature_on', &ltext('admin_name_subdomains'));
    }
    else{
      $num = 0;
      $sth = $dbh->prepare("SELECT count(maxsubdomains) FROM kunden WHERE maxsubdomains!=0");
      $sth->execute or die("$DBI::errstr");
      $num = $sth->fetchrow;
      if($num){
        print &ltext('admin_feature_count', $num, &ltext('admin_name_subdomains'));
      }
    }
  }
  if(defined $changes{&ltext('admin_name_ftp')}){
    print &ltext('admin_feature_check', &ltext('admin_name_ftp'));
    if($changes{&ltext('admin_name_ftp')}){
      print &ltext('admin_feature_on', &ltext('admin_name_ftp'));
    }
    else{
      $num = 0;
      $sth = $dbh->prepare("SELECT count(ftp) FROM kunden WHERE ftp!=0");
      $sth->execute or die("$DBI::errstr");
      $num = $sth->fetchrow;
      if($num){
        print &ltext('admin_feature_count', $num, &ltext('admin_name_ftp'));
      }
    }
  }
  if(defined $changes{&ltext('admin_name_webftp')}){
    print &ltext('admin_feature_check', &ltext('admin_name_webftp'));
    if($changes{&ltext('admin_name_webftp')}){
      print &ltext('admin_feature_on', &ltext('admin_name_webftp'));
    }
    else{
      $num = 0;
      $sth = $dbh->prepare("SELECT count(webftp) FROM kunden WHERE webftp=1");
      $sth->execute or die("$DBI::errstr");
      $num = $sth->fetchrow;
      if($num){
        print &ltext('admin_feature_count', $num, &ltext('admin_name_webftp'));
      }
    }
  }
  if(defined $changes{&ltext('admin_name_mysql')}){
    print &ltext('admin_feature_check', &ltext('admin_name_mysql'));
    if($changes{&ltext('admin_name_mysql')}){
      print &ltext('admin_feature_mysql_on');
    }
    else{
      print &ltext('admin_feature_mysql_off');
    }
  }
  if(defined $changes{&ltext('admin_name_stdcgi')}){
    print &ltext('admin_feature_check', &ltext('admin_name_stdcgi'));
    if($changes{&ltext('admin_name_stdcgi')}){
       print &ltext('admin_feature_stdcgi_on', "$installDir/cgi/");
    }
    else{
      print &ltext('admin_feature_off', &ltext('admin_name_stdcgi'));
    }
  }
  ## /Allgemein

  ## E-Mail
  if(defined $changes{&ltext('admin_name_webmail')}){
    print &ltext('admin_feature_check', &ltext('admin_name_webmail'));
    if($changes{&ltext('admin_name_webmail')}){
      print &ltext('admin_feature_on', &ltext('admin_name_webmail'));
    }
    else{
      $num = 0;
      $sth = $dbh->prepare("SELECT count(webmail) FROM kunden WHERE webmail=1");
      $sth->execute or die("$DBI::errstr");
      $num = $sth->fetchrow;
      if($num){
        print &ltext('admin_feature_count', $num, &ltext('admin_name_webmail'));
      }
    }
  }
  if(defined $changes{&ltext('admin_name_autoresponder')}){
    print &ltext('admin_feature_check', &ltext('admin_name_autoresponder'));
    if($changes{&ltext('admin_name_autoresponder')}){
       print &ltext('admin_feature_on', &ltext('admin_name_autoresponder'));
    }
    else{
      $num = 0;
      $sth = $dbh->prepare("SELECT count(maxautoresponder) FROM kunden WHERE maxautoresponder != 0");
      $sth->execute or die("$DBI::errstr");
      $num = $sth->fetchrow;
      if($num){
        print &ltext('admin_feature_count', $num, &ltext('admin_name_autoresponder'));
      }
    }
  }
  if(defined ($changes{&ltext('admin_name_spamfilter')})){
    my $msg=&ltext('admin_name_spamfilter');
    print &ltext('admin_feature_check', $msg);
    if($changes{$msg}) {
      print &ltext('admin_feature_on', $msg);
    }else{
      $num = 0;
      $sth = $dbh->prepare("SELECT count(*) FROM kunden WHERE spamfilter>0");
      $sth->execute or die("$DBI::errstr");
      $num = $sth->fetchrow;
      if($num){
        print &ltext('admin_feature_count', $num, $msg);
      }
    }
  }
  ## /E-Mail
  
  if(defined ($changes{&ltext('admin_name_confixx_updates')}))  {
    print &ltext('admin_feature_check', &ltext('admin_name_confixx_updates'));
    if($changes{&ltext('admin_name_confixx_updates')})
    {
	print &ltext('admin_feature_on', &ltext('admin_name_confixx_updates'));
    }
    else
    {
	print &ltext('admin_feature_off', &ltext('admin_name_confixx_updates'));
    }
  }

  if(defined $changes{&ltext('admin_name_cronjobs')}) {
    print &ltext('admin_feature_check', &ltext('admin_name_cronjobs'));
    if($changes{&ltext('admin_name_cronjobs')})  {
	  print &ltext('admin_feature_on', &ltext('admin_name_cronjobs'));
    } else {
	#print &ltext('admin_feature_off', &ltext('admin_name_confixx_updates'));
	  $num = 0;
	  $sth = $dbh->prepare("SELECT count(*) FROM cronjobs");
	  $sth->execute or die("$DBI::errstr");
	  $num = $sth->fetchrow;
	  if($num)	  {
	    print &ltext('admin_feature_count', $num, &ltext('admin_name_cronjobs'));
	  }
    }
  }

  if(defined $changes{&ltext('admin_name_IDN')}) {
    print &ltext('admin_feature_check', &ltext('admin_name_IDN'));
    if($changes{&ltext('admin_name_IDN')})  {
	  print &ltext('admin_feature_on', &ltext('admin_name_IDN'));
    } else {
	#print &ltext('admin_feature_off', &ltext('admin_name_confixx_updates'));
	  $num = 0;
	  $sth = $dbh->prepare("SELECT count(*) FROM idn_aliases where not isnull(ascii_name)");
	  $sth->execute or die("$DBI::errstr");
	  $num = $sth->fetchrow;
	  if($num)	  {
	    print &ltext('admin_feature_count', $num, &ltext('admin_name_IDN'));
	  }
    }
  }

  if(defined $changes{&ltext('admin_name_unzip')}) {
    print &ltext('admin_feature_check', &ltext('admin_name_unzip'));
    if($changes{&ltext('admin_name_unzip')}) {
      print &ltext('admin_feature_on', &ltext('admin_name_unzip'));
    }
  }

  while(!(defined $return)){
    print &ltext('admin_input_info');
    $antwort = <STDIN>;
    chop($antwort);
    if(($antwort =~ /^\d+$/) && ($antwort >= 0) && ($antwort <= 2)){
      $return = $antwort;
    }
    else{
      print &ltext('admin_input_error');
    }
  }
  return($return);
}


sub Selection{
  my (@options) = @_;
  my ($count, $selection, $return);
  my $lastOption = @options;
  for ($count=1; $count <= $lastOption; $count++){
    if($count < 10){
      print "    ($count) $options[$count-1]\n";
    }
    else{
      print "   ($count) $options[$count-1]\n";
    }
  }
  print &ltext('admin_select_quit');
  print &ltext('admin_select_info', "0..$lastOption");
  $selection = <STDIN>;
  chop($selection);
  if(($selection =~ /^\d+$/) && (1 <= $selection) && ($selection <= $lastOption)){
    $return = $options[$selection -1];
  }
  elsif(($selection =~ /^\d+$/) && ($selection == 0)){
    $return = 0;
  }
  else{
    $return = 99;
  }
  return($return);
}


sub Change{
  my (%changes) = @_;
  my ($sth, $line, @array, $i, $exists, @row, $timestamp, $kunde);
  $timestamp = time();

  ## Webserver
  if(defined $changes{&ltext('admin_name_ssl')}){
    print &ltext('admin_feature_change', &ltext('admin_name_ssl'));
    if($changes{&ltext('admin_name_ssl')}){
			my ($default_sslKeyDir,$default_sslCrtDir,$default_sslDir);
			$default_sslDir=dirname($::httpd_conf);
			$default_sslKeyDir = $default_sslDir.'/ssl.key/';
      $default_sslCrtDir = $default_sslDir.'/ssl.crt/';

      $sslKeyDir = &PathQuestion(&ltext('install_ssl_keydir'), $default_sslKeyDir);
      $sslCrtDir = &PathQuestion(&ltext('install_ssl_crtdir'), $default_sslCrtDir);

			unless (-d $sslKeyDir){
				mkdir $sslKeyDir or
					warn "Error: unable to create dir $sslKeyDir: $!\n";			
			}	
			unless (-d $sslCrtDir){
				mkdir $sslCrtDir or
					warn "Error: unable to create dir $sslCrtDir: $!\n";	
			}	

      $bin{'openssl'} = &getBin('openssl');
      $dbh->do("UPDATE admin SET cssl=1") or &soft_error("$DBI::errstr");

    }
    else{
      $dbh->do("UPDATE admin SET cssl=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE anbieter SET cssl=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE domains SET cssl=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE cssl SET loeschen=1") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE allgemein SET httpdupdate=0, cssl=1");
		}

#
# safe SSL files
#
		my($ptrMHost,$ip,$port,$keyKey,$keyCrt,$pathKey,$pathCrt,$ptrConfixxVHost,$ptrSSLVHost);
		$ptrMHost = &parseMHost();
		&checkSSLFiles($ptrMHost);

		&UpdateMainConfig;

		($ptrConfixxVHost,$ptrSSLVHost) = &getConfixxVHost($ptrMHost);

		if(ref($ptrConfixxVHost)=~/HASH/){
			unless(ref($ptrSSLVHost)=~/HASH/){ ## add ssl virtual host for the confixx ip-address
 				my $ip = $ptrConfixxVHost->{'ip'};
				my $confixxDomain = $ptrConfixxVHost->{'ServerName'};
				$ptrMHost->{$ip}->{443}={%{$ptrConfixxVHost}};
				$ptrSSLVHost=$ptrMHost->{$ip}->{443};
				$ptrSSLVHost->{'port'}=443;
				$ptrSSLVHost->{'SSLEngine'}='on';
				$ptrSSLVHost->{'SSLCertificateKeyFile'}="$sslKeyDir/$confixxDomain.key";
				$ptrSSLVHost->{'SSLCertificateFile'}="$sslCrtDir/$confixxDomain.crt";
			}

			print "Create file: $mhost_conf\n";
			&writeMHost($ptrConfixxVHost->{'ip'},
									$ptrConfixxVHost->{'ServerName'}||$::hostname,
									$ptrConfixxVHost->{'CustomLog'},
									$ptrConfixxVHost->{'ErrorLog'},
									$ptrConfixxVHost->{'port'}||80,
									$ptrMHost
								 );

		}
  }


  if(defined $changes{&ltext('admin_name_dns')}){
    print &ltext('admin_feature_change', &ltext('admin_name_dns'));
    if($changes{&ltext('admin_name_dns')}){

			our ($stdIP, $use_dnr);

      $dns_server = ($mail_server==2)? 2: 1;

			safe_do "$installDir/admin/subs/subs_include_dns.pl";

#
# get standard IP
#
			$sth = $dbh->prepare("SELECT standardip FROM admin");
			$sth->execute or die("$DBI::errstr");
			($stdIP) = $sth->fetchrow;
			$sth->finish();
#
# end get standard IP
#
			&configureDns();

			&installDns();

      $dbh->do("UPDATE admin SET dns=1,dnr=$use_dnr,ip_pns='$ip_pns',ip_sns='$ip_sns'") or 
				&soft_error("$DBI::errstr");

    }
    else{
      $dns_server = 0;
      $dbh->do("UPDATE admin SET dns=0,dnr=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE anbieter SET dns=0,dnr=0") or &soft_error("$DBI::errstr");
    }
    &UpdateMainConfig;
  }



  if(defined $changes{&ltext('admin_name_dnr')}){
    print &ltext('admin_feature_change', &ltext('admin_name_dnr'));
    if($changes{&ltext('admin_name_dnr')}){
      $dbh->do("UPDATE admin SET dnr=1") or &soft_error("$DBI::errstr");
    }
    else{
      $dbh->do("UPDATE admin SET dnr=0") or &soft_error("$DBI::errstr");
    }
  }


  if(defined $changes{&ltext('admin_name_ssi')}){
    print &ltext('admin_feature_change', &ltext('admin_name_ssi'));
    if($changes{'SSI'}){
      $dbh->do("UPDATE admin SET ssi=1") or &soft_error("$DBI::errstr");
    }
    else{
      $dbh->do("UPDATE admin SET ssi=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE anbieter SET ssi=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE kunden SET ssi=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE allgemein SET httpd=1");
    }
  }
  if(defined $changes{&ltext('admin_name_cgiperl')}){
    print &ltext('admin_feature_change', &ltext('admin_name_cgiperl'));
    if($changes{&ltext('admin_name_cgiperl')}){
      $dbh->do("UPDATE admin SET perl=1") or &soft_error("$DBI::errstr");
    }
    else{
      $dbh->do("UPDATE admin SET perl=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE anbieter SET perl=0, lastchange='$timestamp'") or &soft_error("$DBI::errstr");
      $sth = $dbh->prepare("SELECT kunde FROM kunden WHERE perl > 0");
      $sth->execute or &soft_error("$DBI::errstr");
      $i = 0;
      undef @array;
      while($line = $sth->fetchrow){
        $array[$i++] = $line;
      }
      foreach $kunde (@array){
        $sth = $dbh->prepare("SELECT kunde FROM perl WHERE kunde='$kunde'");
        $sth->execute or &soft_error("$DBI::errstr");
        $exists = 0;
        $exists = $sth->rows;
        if($exists){
          $dbh->do("UPDATE perl SET loeschen=1 WHERE kunde='$kunde'") or &soft_error("$DBI::errstr");
        }
        else{
          $dbh->do("INSERT INTO perl (loeschen,kunde) VALUES (1,'$kunde')") or &soft_error("$DBI::errstr");
        }
      }
      $dbh->do("UPDATE kunden SET perl=0, lastchange='$timestamp'") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE allgemein SET httpd=1, perl=1") or &soft_error("$DBI::errstr");
    }
  }
  if(defined $changes{&ltext('admin_name_modpython')}){
    print &ltext('admin_feature_change', &ltext('admin_name_modpython'));
    if($changes{&ltext('admin_name_modpython')}){
      $dbh->do ("UPDATE admin SET modpython=1") or &soft_error("$DBI::errstr");
    }
    else{
      $dbh->do ("UPDATE admin SET modpython=0") or &soft_error("$DBI::errstr");
      $dbh->do ("UPDATE anbieter SET modpython=0, lastchange='$timestamp'") or &soft_error("$DBI::errstr");
      $dbh->do ("UPDATE kunden SET modpython=0, lastchange='$timestamp'") or &soft_error("$DBI::errstr");
      $dbh->do ("UPDATE allgemein SET httpd=1") or &soft_error("$DBI::errstr");
    }
  }
	if(defined $changes{&ltext('admin_name_fp')}){
		print &ltext('admin_feature_change', &ltext('admin_name_fp'));
		if($changes{&ltext('admin_name_fp')}){

			my $fpversion = &SelectQuestion( &ltext('install_question_fpversion') , 
																			 'FPSE 2000 (4.0)', 
																			 'FPSE 2002 (5.0)'
																		 );

			if($fpversion =~ /2000/){
				$bin{'fpsrvadm'} = &getBin( 'fpsrvadm.exe',0,
																		'/usr/local/frontpage/version4.0/bin',
																		'/usr/lib/frontpage/version4.0/bin');
			} else {
				$bin{'fpsrvadm'} = &getBin( 'owsadm.exe',0,
																		'/usr/local/frontpage/version5.0/bin',
																		'/usr/lib/frontpage/version5.0/bin');
			}

			my $default_fphome = '/usr/local/frontpage';
			if($bin{'fpsrvadm'} =~ /(\/\S+\/frontpage)\/\S+/){
				$default_fphome = $1;
			}
			$bin_fpsrvadm=$bin{'fpsrvadm'};
			$fp_homeDir = &DirQuestion( &ltext('install_question_frontpagedir') , $default_fphome);
			$fp_uid = (getpwnam('bin'))[2];
			$fp_gid = (getpwnam('bin'))[3];
			unless( $fpfake ){
				$fpfake = $httpd_conf;
				$fpfake =~ s/\/[^\/]+$/\/fpfake/;
			}

			$dbh->do("UPDATE admin SET frontpage=1") or &soft_error("$DBI::errstr");

		} else {
			my $port;
			$dbh->do("UPDATE admin SET frontpage=0") or &soft_error("$DBI::errstr");
			$dbh->do("UPDATE anbieter SET frontpage=0") or &soft_error("$DBI::errstr");
			$dbh->do("DELETE FROM frontpage WHERE neu=1") or &soft_error("$DBI::errstr");
			$dbh->do("DELETE FROM frontpagealias WHERE neu=1") or &soft_error("$DBI::errstr");
			$dbh->do("UPDATE frontpage SET loeschen=1") or &soft_error("$DBI::errstr");
			$sth = $dbh->prepare("SELECT domains.domain, kunden.kunde, domains.cssl, kunden.anbieter FROM domains,kunden WHERE domains.kunde = kunden.kunde AND kunden.frontpage=1 AND domains.domain NOT LIKE '*%'");
			$sth->execute or die("$DBI::errstr");
			while(@row = $sth->fetchrow_array){
				$row[2] ? ($port = 443) : ($port = 80);
				$dbh->do("INSERT INTO frontpagealias (domain,kunde,anbieter,port,loeschen) ".
								 "VALUES ('$row[0]','$row[1]','$row[3]',$port,1)") or &soft_error("$DBI::errstr");
			}
			$dbh->do("UPDATE kunden SET frontpage=0") or &soft_error("$DBI::errstr");
			$dbh->do("UPDATE domains SET frontpage=0") or &soft_error("$DBI::errstr");
			$dbh->do("UPDATE allgemein SET frontpage=1") or &soft_error("$DBI::errstr");
		}

		&UpdateMainConfig;
	}

  if(defined $changes{&ltext('admin_name_wap')}){
    print &ltext('admin_feature_change', &ltext('admin_name_wap'));
    if($changes{&ltext('admin_name_wap')}){
      $dbh->do("UPDATE admin SET wap=1") or &soft_error("$DBI::errstr");
    }
    else{
      $dbh->do("UPDATE admin SET wap=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE anbieter SET wap=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE angebote SET wap=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE kunden SET wap=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE allgemein SET httpd=1");
    }
    &UpdateMainConfig;
  }
  if(defined $changes{&ltext('admin_name_coldfusion')}){
    print &ltext('admin_feature_change', &ltext('admin_name_coldfusion'));
    if($changes{&ltext('admin_name_coldfusion')}){
      $dbh->do("UPDATE admin SET coldfusion=1") or &soft_error("$DBI::errstr");
      $coldfusion_support = 1;
    }
    else{
      $dbh->do("UPDATE admin SET coldfusion=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE anbieter SET coldfusion=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE kunden SET coldfusion=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE allgemein SET httpd=1");
      $coldfusion_support = 0;
    }
    &UpdateMainConfig;
  }
  ## /Webserver

  ## Allgemein
  if(defined $changes{&ltext('admin_name_shell')}){
    print &ltext('admin_feature_change', &ltext('admin_name_shell'));
    if($changes{&ltext('admin_name_shell')}){
      $dbh->do("UPDATE admin SET shell=1") or &soft_error("$DBI::errstr");
    }
    else{
      $dbh->do("UPDATE admin SET shell=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE anbieter SET shell=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE angebote SET shell=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE kunden SET shell=0") or &soft_error("$DBI::errstr");
    }
  }
  if(defined $changes{&ltext('admin_name_scponly')}){
    &ReadMainConfigFile;
    print &ltext('admin_feature_change', &ltext('admin_name_scponly'));
    if($changes{&ltext('admin_name_scponly')}){
      &RestoreBin($dbh,\%bin,'scponly');
      my %scpBin = ('scponly'=>$bin{'scponly'},
		    'ldd'=>$bin{'ldd'});

      my($scpShell,$scpChroot)=&scponlyConfigure(\%scpBin,$user_homeDir,$user_prefix,
							 basename($confixx_homeDir),'empty');

      if (-x $scpShell){
				my $chrootDir;
				&checkShells($scpShell,'/etc/shells');
				if ($scpChroot){
					$chrootDir="$user_homeDir/$scpChroot";
					&RecCreateDir($chrootDir, 0700);
					&scponlyMakeChroot($chrootDir,\%bin);
				}
				
				$dbh->do("UPDATE admin SET scponly=1") or &soft_error("$DBI::errstr");
				&StoreBin($dbh,\%scpBin,'scponly');
				$scponly_chroot = $scpChroot;
				$scponly_shell = $scpShell;
	
      }
    } else{
      $dbh->do("UPDATE admin SET scponly=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE anbieter SET scponly=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE angebote SET scponly=0") or &soft_error("$DBI::errstr");

#
# clear root tree of users
#

#
# /clear root tree of users
#

      $dbh->do("UPDATE kunden SET scponly=0") or &soft_error("$DBI::errstr");
      $scponly_chroot="";
      $scponly_shell="";
    }
    &WriteMainConfigFile;
  }


  if(defined $changes{&ltext('admin_name_quota')}){
    print &ltext('admin_feature_change', &ltext('admin_name_quota'));

    if($changes{&ltext('admin_name_quota')}){

       $use_quota= 1;

       &checkAndInstallPkgs( 'Quota' );

       $user_quota = 1;
       $mail_quota = 1;
       if ( -d $majordomo_ldir ) {
				 $majordomo_quota = 1;
       } else {
				 $majordomo_quota = '0';
       }

       &quotaSupportCheck( 'admin' );

       if ( ($user_quota eq '0') && ($mail_quota eq '0') && ( $majordomo_quota eq '0') ){
#
# quota is not supported 
#
				 $use_quota= '0';

       }else{
				 $dbh->do("UPDATE admin SET quota=1") or &soft_error("$DBI::errstr");
				 if ($user_quota ne '0'){
					 $dbh->do("UPDATE kunden SET quota=1") or &soft_error("$DBI::errstr");
					 $dbh->do("UPDATE ftp SET quota=1") or &soft_error("$DBI::errstr");
				 }
				 if ($mail_quota ne '0'){
					 $dbh->do("UPDATE pop3 SET quota=1") or &soft_error("$DBI::errstr");
				 }
				 if ($majordomo_quota ne '0' && -d $majordomo_ldir){
					 $dbh->do("UPDATE maillist SET quota=1") or &soft_error("$DBI::errstr");
				 }
       }
    } else{
      $use_quota= '0';
      &unsetQuota;
      $dbh->do("UPDATE admin SET quota=0") or &soft_error("$DBI::errstr");
    }
    $dbh->do("UPDATE allgemein SET quota=1") or &soft_error("$DBI::errstr");
    &UpdateMainConfig;
  }

  if(defined $changes{&ltext('admin_name_stdcgi')}){
    print &ltext('admin_feature_change', &ltext('admin_name_stdcgi'));
    if($changes{&ltext('admin_name_stdcgi')}){
       $dbh->do("UPDATE admin SET stdcgi=1") or &soft_error("$DBI::errstr");
    }
    else{
      $dbh->do("UPDATE admin SET stdcgi=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE anbieter SET stdcgi=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE kunden SET stdcgi=0") or &soft_error("$DBI::errstr");
    }
    $dbh->do("UPDATE allgemein SET stdcgi=0") or &soft_error("$DBI::errstr");
  }
  if(defined $changes{&ltext('admin_name_webalizer')}){
    print &ltext('admin_feature_change', &ltext('admin_name_webalizer'));
    if($changes{&ltext('admin_name_webalizer')}){
      $dbh->do("UPDATE admin SET statistik=1") or &soft_error("$DBI::errstr");
      unless(-x $bin_webalizer){
        $bin_webalizer = &BinQuestion(&ltext('install_bin_path', 'webalizer'), "/usr/bin/webalizer");
      }
      $bin{'webalizer'}=$bin_webalizer;
      &writeHTTPDTraffik;
    }
    else{
      $dbh->do("UPDATE admin SET statistik=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE anbieter SET statistik=0, lastchange='$timestamp'") or &soft_error("$DBI::errstr");
      $sth = $dbh->prepare("SELECT kunde FROM kunden WHERE statistik=1");
      $sth->execute or &soft_error("$DBI::errstr");
      my(@users);
      while( ($line) = $sth->fetchrow ) {
        push @users, $line;
      }
			$sth->finish;

      foreach $kunde (@users){
        $sth = $dbh->prepare("SELECT kunde FROM webalizer WHERE kunde='$kunde'");
        $sth->execute or &soft_error("$DBI::errstr");
        $exists = 0;
        $exists = $sth->rows;
        if($exists){
          $dbh->do("UPDATE webalizer SET loeschen=1 WHERE kunde='$kunde'") or &soft_error("$DBI::errstr");
        }
        else{
          $dbh->do("INSERT INTO webalizer (loeschen,kunde) VALUES (1,'$kunde')") or &soft_error("$DBI::errstr");
        }
      }
      $dbh->do("UPDATE kunden SET statistik=0, lastchange='$timestamp'") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE allgemein SET httpd=1, webalizer=1") or &soft_error("$DBI::errstr");
      $bin_webalizer = "";
    }
    &UpdateMainConfig;
  }
  if(defined $changes{&ltext('admin_name_subdomains')}){
    print &ltext('admin_feature_change', &ltext('admin_name_subdomains'));
    if($changes{&ltext('admin_name_subdomains')}){
      $dbh->do("UPDATE admin SET subdomains=1") or &soft_error("$DBI::errstr");
    }
    else{
      $dbh->do("UPDATE admin SET subdomains=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE anbieter SET maxsubdomains=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE kunden SET maxsubdomains=0") or &soft_error("$DBI::errstr");
      $sth = $dbh->prepare("SELECT domain FROM domains WHERE richtigedomain=0");
      $sth->execute or &soft_error("$DBI::errstr");
      while($line = $sth->fetchrow){
        $dbh->do("DELETE FROM email WHERE domain='$line'") or &soft_error("$DBI::errstr");
      }
      $dbh->do("DELETE FROM domains WHERE richtigedomain=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE allgemein SET httpd=1");
    }
  }
  if(defined $changes{&ltext('admin_name_webftp')}){
    print &ltext('admin_feature_change', &ltext('admin_name_webftp'));
    if($changes{&ltext('admin_name_webftp')}){
      $dbh->do("UPDATE admin SET webftp=1") or &soft_error("$DBI::errstr");

			$use_webftp = 1;

      safe_do $cgisInstall;

			&configureCgis( $dbh );

    }
    else{
      $dbh->do("UPDATE admin SET webftp=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE anbieter SET webftp=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE kunden SET webftp=0") or &soft_error("$DBI::errstr");

			$use_webftp = 0;

    }
    &UpdateMainConfig;
  }
  if(defined $changes{&ltext('admin_name_mysql')}){
    print &ltext('admin_feature_change', &ltext('admin_name_mysql'));
    if($changes{&ltext('admin_name_mysql')}){

      &configureMysql;

      $dbh->do("UPDATE admin SET mysql=1") or &soft_error("$DBI::errstr");
      $use_mysqlshell=0;
      if($use_mysqlshell){
        $dbh->do("UPDATE admin SET mysqlshelluser='$mysql_shell_user', ".
								 "mysqlshellpasswort='$mysql_shell_user_pw', ".
								 "mysqlshellhost='$mysql_shell_user_host', ".
								 "mysqlshelllongpwcrypt='$mysql_shell_user_pw_crypt', ".
								 "mysqlshelluid='$mysql_shell_uid'") or 
									 &soft_error("$DBI::errstr");

#
# undelete mysql shell account
#
      if ($mysql_shell_user){
				$dbh->do("delete from delaccs where account='$mysql_shell_user' and type='mysql'");
      }
	
				&installMySQLLogin;
      
      }

    }else{
      $dbh->do("UPDATE admin SET mysql=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE anbieter SET maxmysql=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE kunden SET maxmysql=0") or &soft_error("$DBI::errstr");
      $dbh->do("DELETE FROM mysql_datenbanken") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE admin SET mysqlshelluser='', mysqlshelllongpwcrypt='', mysqlshellhost='', mysqlshellpasswort='', mysqlshelluser=''") or &soft_error("$DBI::errstr");

#
# delete mysql shell account
#
      if ($mysql_shell_user){
				$dbh->do("insert into delaccs (account,type) values ('$mysql_shell_user','mysql')");
      }
      
      &uninstallMySQLLogin( $mysqlUserServer, $mysqlUserUser, $mysqlUserPw, $mysqlUserPort );

      $use_mysqlshell = 0;
      $mysqlUserServer = '';
      $mysqlUserUser = '';
      $mysqlUserPw = '';
      $mysqlUserPort = '';
      $mysql_homeDir = '';

    }
    $dbh->do("UPDATE allgemein SET newpwd=1") or &soft_error("$DBI::errstr");
    &WriteMainConfigFile;
    &UpdateAllConfig;

  }

  if(defined $changes{&ltext('admin_name_ftp')}){
    print &ltext('admin_feature_change', &ltext('admin_name_ftp'));
    if($changes{&ltext('admin_name_ftp')}){
      $dbh->do("UPDATE admin SET ftp=1") or &soft_error("$DBI::errstr");
    }
    else{
      $dbh->do("UPDATE admin SET ftp=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE anbieter SET ftp=0, maxftp=0, lastchange='$timestamp'") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE kunden SET ftp=0, maxftp=0, lastchange='$timestamp'") or &soft_error("$DBI::errstr");
      $sth = $dbh->prepare("SELECT account,pfad,kunde FROM ftp WHERE neu=0");
      $sth->execute or &soft_error("$DBI::errstr");
      $i = 0;

      my (@array,@row);
			
      while(@row = $sth->fetchrow_array){
        $array[$i++] = "$row[0]#!#$row[1]#!#$row[2]";
      }
			$sth->finish();

      $dbh->do("DELETE FROM ftp") or &soft_error("$DBI::errstr");

      foreach my $account (@array){
        @row = split(/#!#/, $account);
        $sth = $dbh->prepare("SELECT account FROM delaccs WHERE account='$row[0]'");
        $sth->execute or &soft_error("$DBI::errstr");
        $exists = $sth->rows;
        unless($exists){
          $dbh->do("INSERT INTO delaccs (account,type,pfad,kunde) VALUES ('$row[0]','ftp','$row[1]','$row[2]')") or &soft_error("$DBI::errstr");
        }
      }
      $dbh->do("UPDATE admin SET webftp=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE anbieter SET webftp=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE kunden SET webftp=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE allgemein SET delftp=1") or &soft_error("$DBI::errstr");

      &UpdateMainConfig;
    }
  }
  ## /Allgemein

  ## E-Mail
  if(defined $changes{&ltext('admin_name_webmail')}){
    print &ltext('admin_feature_change', &ltext('admin_name_webmail'));
    if($changes{&ltext('admin_name_webmail')}){
      $dbh->do("UPDATE admin SET webmail=1") or &soft_error("$DBI::errstr");
			$use_webmail = 1;

      safe_do $cgisInstall;

			&configureCgis( $dbh );
    }
    else{
      $dbh->do("UPDATE admin SET webmail=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE anbieter SET webmail=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE kunden SET webmail=0") or &soft_error("$DBI::errstr");
			$use_webmail = 0;
    }
    &UpdateMainConfig;
  }
  if(defined $changes{&ltext('admin_name_autoresponder')}){
    print &ltext('admin_feature_change', &ltext('admin_name_autoresponder'));
    if($changes{&ltext('admin_name_autoresponder')}){
      $dbh->do("UPDATE admin SET autoresponder=1") or &soft_error("$DBI::errstr");
      $use_autorespond = "1";
      unless (-x $bin_autorespond){
				$bin_autorespond = &getBin('autoresponder.pl');
				unless (-x $bin_autorespond){
					$bin_autorespond = &BinQuestion(&ltext('install_bin_path', 'autoresponder.pl'), 
																					"/usr/bin/autoresponder.pl");
				}
      }

      $bin{'autorespond'} = $bin_autorespond;

    }else{

      $dbh->do("UPDATE admin SET autoresponder=0") or &soft_error("$DBI::errstr");
#      $dbh->do("UPDATE anbieter SET maxautoresponder=0") or &soft_error("$DBI::errstr");
#      $dbh->do("UPDATE kunden SET maxautoresponder=0") or &soft_error("$DBI::errstr");
#      $dbh->do("DELETE FROM autoresponder") or &soft_error("$DBI::errstr");
      $use_autorespond = "0";
    }
    $dbh->do("UPDATE allgemein SET aliases=1") or &soft_error("$DBI::errstr");
    &UpdateMainConfig;
  }

  if ( defined $changes{&ltext( 'admin_name_spamfilter' )} ) {
    my $msg = &ltext('admin_name_spamfilter');
    print &ltext('admin_feature_change', $msg);

    if ( $changes{$msg} ) {

       safe_do $spamassassin_install_script;

	&configureSpamassassin();

	&UpdateAllConfig;
	
	&installSpamassassin();

      $dbh->do("UPDATE admin SET spamfilter=1") or &soft_error("$DBI::errstr");
      $spamassassin_support=1;

    } else {
      $dbh->do("UPDATE admin SET spamfilter=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE anbieter SET spamfilter=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE kunden SET spamfilter=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE angebote SET spamfilter=0") or &soft_error("$DBI::errstr");
      $dbh->do("UPDATE allgemein SET spamupdate = 1") or &soft_error("$DBI::errstr");
      #$dbh->do("DELETE FROM spampref") or &soft_error("$DBI::errstr");
      $spamassassin_support=0;

	&UpdateAllConfig;

    }
      
    }



  ## /E-Mail
  
  if(defined $changes{&ltext('admin_name_confixx_updates')}) {
    print &ltext('admin_feature_change', &ltext('admin_name_confixx_updates'));
    if( $changes{&ltext('admin_name_confixx_updates')} ) {
			$dbh->do("UPDATE admin SET checkupdates=1") or 
				&soft_error("$DBI::errstr");
			$dbh->do("UPDATE zeiten SET checknewversion=12") or 
				&soft_error("$DBI::errstr");
			$use_confixx_updates = 1;
    }  else  {
			$dbh->do("UPDATE admin SET checkupdates=0") or 
				&soft_error("$DBI::errstr");
			$use_confixx_updates = "0";
    }
    &UpdateMainConfig;
  }

  if(defined $changes{&ltext('admin_name_cronjobs')})
  {
    print &ltext('admin_feature_change', &ltext('admin_name_cronjobs'));
    if($changes{&ltext('admin_name_cronjobs')}) {
			$dbh->do("UPDATE admin SET cronjobs=1") or &soft_error("$DBI::errstr");
			$cronjobs_support = 1;

    } else  {
			$dbh->do("UPDATE admin SET cronjobs=0") or &soft_error("$DBI::errstr");
			$dbh->do("UPDATE anbieter SET maxcronjobs=0") or &soft_error("$DBI::errstr");
			$dbh->do("UPDATE kunden SET maxcronjobs=0") or &soft_error("$DBI::errstr");

        #&del_crontab($user) or &soft_error("Unable to remove crontab for user '$user'");

      $sth = $dbh->prepare("SELECT count(*) FROM cronjobs");
      $sth->execute or 
				die("$DBI::errstr");
      my $num = $sth->fetchrow;
			$sth->finish;
      if ( $num ) {
				if( &YesNoQuestion( &ltext('admin_delete_users_crontab') ) ) {
					$sth = $dbh->prepare("select kunde from cronjobs");
					$sth->execute or 
						&soft_error("$DBI::errstr");
					while( my ($user) = $sth->fetchrow_array)	{
						&del_crontab($user) or 
							&soft_error("Unable to remove crontab for user '$user'");
					}
					$dbh->do("DELETE FROM cronjobs") or &soft_error("$DBI::errstr");
				}
      }
			$cronjobs_support = '0';
    }
    &UpdateMainConfig;
  }

	if( defined $changes{&ltext('admin_name_majo')} ){

		print &ltext('admin_feature_change', &ltext('admin_name_majo'));

		if( $changes{&ltext('admin_name_majo')} ){

			&configureMajordomo();

			&installMajordomo();

			if ($::mail_server){
				&checkQmailForwards();
			}
			
			$dbh->do("UPDATE admin SET majordomo=1, majordomohome=".$dbh->quote($majordomo_home).
							 ", majordomoml=".$dbh->quote($majordomo_ldir));
			$dbh->do("update maillist set neu=0");

    }else{
			$majordomo_wrapper='';
			$dbh->do("update admin set majordomo=0");
			$dbh->do("update maillist set neu=2");
		}
		&UpdateMainConfig;
  }

  if(defined $changes{&ltext('admin_name_IDN')})
  {
	  print &ltext('admin_feature_change', &ltext('admin_name_IDN'));
	  &ReadMainConfigFile;
	  if($changes{&ltext('admin_name_IDN')})
	  {
		  my %idnBin=('idn'=>$bin{'idn'},
									'iconv'=>$bin{'iconv'});
			my ($iconv_utf8);
		  ($idn_vendor,$idn_shell,$iconv_shell,$iconv_utf8) =  &idnConfigure(\%idnBin);
		  if ($idn_vendor){
			  $dbh->do("update admin set idn=1");
			  &StoreBin($dbh,\%idnBin,'idn');
		  }
		  my %idn_opt = ( 
				  'idn_shell'		=> $idn_shell,
				  'idn_vendor'	=> $idn_vendor,
					'iconv_shell' => $iconv_shell,
					'iconv_utf8'  => $iconv_utf8,					
				  );

		  &installScript('idn_translate.pl', $confixx_uid, $confixx_gid, 0755, $confixx_binDir, %idn_opt);
	  }else{
		  $idn_vendor="";
		  $dbh->do("update admin set idn=0");
	  }
	  &WriteMainConfigFile;
		unless($dns_server == 2 || $mail_server == 2){  ## launch only on primary server
			&WritePHPConfigFile;  ## write $iconv_utf8
		}
  }

  if(defined $changes{&ltext('admin_name_unzip')})
  {
    &ReadMainConfigFile;
    if($changes{&ltext('admin_name_unzip')})
    {
      $bin{"unzip"} = $bin_unzip = &getBin ( 'unzip' );
      &installScript ( 'skinmng.pl', $confixx_uid, $gidapache, 0750, $confixx_sbinDir, &skinmng_opt );
    }
    else
    {
      $bin{"unzip"} = $bin_unzip = "";
    }
    &StoreBin($dbh,\%bin);
    &WriteMainConfigFile;
  }

  print &ltext('admin_wait_key');
  my $tmp = <STDIN>;
}


sub unsetQuota{
  require Quota;
  my (@row, $sth, $userdev, $emaildev, $err, $majodev);


  if (undef $bin_setquota){
    $bin_setquota=$bin{'setquota'};
  }
  if (undef $bin_quota){
    $bin_quota=$bin{'quota'};
  }

#
# check binaries
#
  unless (-x $bin_setquota && -x $bin_quota){
    &RestoreBin($dbh,\%bin,'quota');
    if (-x $bin{'setquota'} && -x $bin{'quota'}){
      $bin_setquota=$bin{'setquota'};
      $bin_quota=$bin{'quota'};
    }else{
      &quotaCheckBin(\$bin_setquota,\%bin,'setquota','/usr/sbin/setquota');
      &quotaCheckBin(\$bin_quota,\%bin,'quota','/usr/bin/quota');

      if (-x $bin_setquota || -x $bin_quota){
	&StoreBin($dbh,\%bin);
      }
    }
  }

#
# get file systems with quota support
#
  my $ptrQFS = &quotaGetFS();

  $userdev = Quota::getqcarg($user_homeDir) || &soft_error(&ltext('quota_dev_get', $user_homeDir, $!));

# check the quota support in mount options
  unless (exists $ptrQFS->{$userdev}){
    $user_quota=0;
  }

  if( $use_mail ) {
    my $mailDir = (($mailSpool eq "") && (-d $pop_homeDir))
		? $pop_homeDir
		: $mailSpool;
    $emaildev = Quota::getqcarg($mailDir) || &soft_error(&ltext('quota_dev_get', $mailDir, $!));

# check the quota support in mount options
    unless (exists $ptrQFS->{$emaildev}){
      $mail_quota=0;
    }
  }

  if(-d $majordomo_ldir){
    $majodev = Quota::getqcarg($majordomo_ldir) 
      || &soft_error(&ltext('quota_dev_get', $majordomo_ldir, $!));

# check the quota support in mount options
    unless (exists $ptrQFS->{$majodev}){
      $majordomo_quota=0;
    }
  }

  unless(defined $inode_std){
    $inode_std = 0;
  }

  if ($userdev && $user_quota ){
    $sth = $dbh->prepare("SELECT kunde,uid FROM kunden");
    $sth->execute or &soft_error("$DBI::errstr");
    while(@row = $sth->fetchrow_array){
      if(Quota::setqlim($userdev, $row[1], 0, 0, 0, 0)){
	$err = Quota::strerr();
	if ($bin_setquota){
	  $err=`$bin_setquota -u $row[1] 0 0 0 0 $userdev 2>&1`;
	  unless ($?){
	    $err='';
	  }
	}
	if ($err){
	  &soft_error(&ltext('quota_user_set', '# ', $row[0], '0', $err));
	}
      }
    }
    $sth = $dbh->prepare("SELECT account,uid FROM ftp");
    $sth->execute or &soft_error("$DBI::errstr");
    while(@row = $sth->fetchrow_array){
      if(Quota::setqlim($userdev, $row[1], 0, 0, 0, 0)){
	$err = Quota::strerr();
	if ($bin_setquota){
	  $err=`$bin_setquota -u $row[1] 0 0 0 0 $userdev 2>&1`;
	  unless ($?){
	    $err='';
	  }
	}
	if ($err){
	  &soft_error( &ltext('quota_ftp_set', '# ',$row[0], '0', $err));
	}
      }
    }
  }
  if($emaildev && $mail_quota){
    $sth = $dbh->prepare("SELECT account,uid FROM pop3");
    $sth->execute or &soft_error("$DBI::errstr");
    while(@row = $sth->fetchrow_array){
      if(Quota::setqlim($emaildev, $row[1], 0, 0, 0, 0)){
        $err = Quota::strerr();
	if ($bin_setquota){
	  $err=`$bin_setquota -u $row[1] 0 0 0 0 $emaildev 2>&1`;
	  unless ($?){
	    $err='';
	  }
	}
	if ($err){
	  &soft_error(&ltext('quota_pop_set', '# ',$row[0], '0', $err));
	}
      }
    }
  }
  if($majodev && $majordomo_quota){
    my $sql="SELECT k.kunde, k.uid FROM domains d, kunden k, maillist m ".
      "where d.kunde=k.kunde and m.domain_id=d.id";
    $sth = $dbh->prepare($sql);
    $sth->execute or 
			&soft_error("$DBI::errstr");
    while(@row = $sth->fetchrow_array){
      if(Quota::setqlim($majodev, $row[1], 0, 0, 0, 0)){
        $err = Quota::strerr();
				if ($bin_setquota){
					$err=`$bin_setquota -u $row[1] 0 0 0 0 $majodev 2>&1`;
					unless ($?){
						$err='';
					}
				}
				if ($err){
					&soft_error(&ltext('quota_majordomo_set', '# ',$row[0], '0', $err));
				}
      }
    }
		$sth->finish;
  }

}


sub soft_error{
  my ($message) = @_;
  print &ltext('admin_error') . ": $message\n";
}


sub configureMysql{
  my $default_dbServer = 'localhost';
	my $default_dbPort = '';
  my $default_mysql_shell_user = 'mysqlshell';
  my ($weiter, $salt);
  if ( $dbType ne 'mysql' ) {
    &modulesCheck('DBD::mysql');
		my($ret,$errstr) = &loadPackcage('DBD::mysql');
    unless( $ret ){
     die( $errstr."\n".
					&ltext('install_module_load', 'DBD::mysql')
				);
    }
    system( 'clear' );
    print "\n";
  }
  if ( $dbType eq 'mysql' ) {
		$default_dbServer = $dbServer;
		$default_dbPort = $dbPort;
	}

	$mysqlUserServer = &ServerQuestion( &ltext('install_mysql_userserver_server') , $default_dbServer);

	( $mysqlUserServer, $mysqlUserUser, $mysqlUserPw, $mysqlUserPort) = 
		&configRootDbAccess( $mysqlUserServer, undef, undef, $default_dbPort );

	my ($ptrHash,$errstr) = &getMysqlInfo( { 'user' => $mysqlUserUser,
																					 'server' => $mysqlUserServer,
																					 'password' => $mysqlUserPw,
																					 'port' => $mysqlUserPort}
																			 );
	if ( $ptrHash ) {
		( undef, $mysqlUserHost) = split( /@/, $ptrHash->{'current user'} );
		$mysqlUserVersion = $ptrHash->{'server version'};
	} else {
		print STDERR "Error: unable to connect to database: $errstr\n";
	}
	my ($default_mysql_homeDir);
  if ( $mysqlUserServer eq 'localhost' ) {
    $mysql_shell_user_host = $hostname;
		my ($ptrHash,$errstr) = &parseMyCnf( '/etc/my.cnf', 'datadir' );
		if ( $ptrHash && $ptrHash->{'datadir'} ) {
			$default_mysql_homeDir = $ptrHash->{'datadir'};
		}
		unless ( $default_mysql_homeDir && -d $default_mysql_homeDir ) {
			$default_mysql_homeDir = '/var/lib/mysql';
			foreach my $dir ( '/var/db/mysql','/usr/local/mysql/data' ) {
				if ( -d $dir ) {
					$default_mysql_homeDir = $dir;
					last;
				}
			}
		}
		$mysql_homeDir = &DirQuestion( &ltext('install_question_mysqlhomedir') , $default_mysql_homeDir);
  } else {
    $mysql_shell_user_host = $mysqlUserServer;
		$mysql_homeDir = '';
  }

	$use_mysqlshell = 0;
	$mysql_shell_uid = '';
	$mysql_shell_user_pw_crypt = '';

}


sub getVersion{
  my $sth = $dbh->prepare("SELECT version FROM register");
  if ( $sth->execute ) {
		$VERSION = $sth->fetchrow;
		$sth->finish;
	}
  $VERSION_PRO = 'Pro';
  $VERSION_LIGHT1 = 'Light';
  $VERSION_LIGHT2 = 'Limited';
}


sub CheckMysql {
  my ($user, $pw, $server) = @_;
  my ($return);


  my $dbaddress = &makeDSN('mysql',$server,'mysql');

  my $dbh = DBI->connect($dbaddress, $user, $pw)
    or &soft_error (&ltext('db_connect', '#2003', $DBI::errstr)) and my $error = 1;
  if (!($error)){
    my $sth = $dbh->prepare("select * from user where User = '$user' and  Select_priv = 'Y' and Insert_priv = 'Y' and Update_priv = 'Y' and Delete_priv = 'Y' and  Create_priv = 'Y' and  Drop_priv = 'Y' and Reload_priv = 'Y'");
    $sth->execute;
    my $hasPermissions = $sth->rows;
    $sth->finish;
    $dbh->disconnect;
    if ($hasPermissions){
      $return = 1;
    }
    else{
      $return = 0;
    }
  }
  else{
    $return = 0;
  }
  return($return);
}


sub AddGroup{
  my($group) = @_;
  my($gid, %gid, $i, $stop);
  $gid = getgrnam($group);
  if(defined $gid && $gid =~ /^\d+$/){
    $i = $gid;
  }
  else{
    open(GROUP, "$groupDir");
    while(<GROUP>){
      if($_ =~ /.*:.*:(\d+):/){
        $gid{$1} = 1;
      }
    }
    close(GROUP);
    $stop = 0;
    $i = "500";
    until($stop){
      $i++;
      unless(defined $gid{$i}){
        $stop = 1;
      }
    }
    print &ltext('install_groupadd', $group);
    open(GROUP, ">>$groupDir");
    print GROUP "$group:x:$i:\n";
    close(GROUP);
  }
  return($i);
}


sub choose_language{

  print "\n\n";

  do "$wDir/languages/$language/scripts.local";

  my ($lang, %lang, @lang, $i);

  opendir(DIR, "$wDir/languages");
  while(defined($lang = readdir(DIR))){
    if(($lang =~ /^\w+$/) && (-T "$wDir/languages/$lang/misc.local")){
      do "$wDir/languages/$lang/misc.local";
      $lang{$lang_text{'language_name_nat'}} = $lang if ( $langfileversion eq $lang_version );
      undef ($lang_version);
    }
  }
  closedir(DIR);

  $i = 0;
  foreach $lang (keys %lang){
    $lang[$i++] = $lang;
  }

  $lang = &SelectQuestion( &ltext('install_question_language') , @lang);
  $language = $lang{$lang};

  do "$wDir/languages/$language/scripts.local";

  print "\n\n";

}
## /Unterprogramme
