package Modules::Apache::Config::VServer;

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

# $id: VServer.pm, v 1.0 2003/11/7 $

#push @INC,'../../';
#require  Apache::Config::DomainSet;
use Modules::Apache::Config::DomainSet;

my $class;

BEGIN {
	use Exporter;
	
  our @ISA = ('Exporter');
  our @EXPORT = qw//;

  $class="Modules::Apache::Config::VServer";
}

use strict('vars');

sub new {
  my $class = shift;
  my $self = {};

  bless($self, $class);

  my %args = (
							'ip' => '127.0.0.1',
							'kunde' => '',
							'cssl' => 0,
							'pfad' => '/',
							'level' => 0,
							'gesperrt' => 0,
							'zusatz' => '',
	      @_
	     );

	my ($key);
	foreach my $key ('ip','pfad','cssl','level','gesperrt','zusatz','kunde','uid') {
		$self->{"_$key"}      = $args{$key} ;
	}

	foreach my $key ('_frontpage', '_perl', '_modpython', '_php', '_ssi', '_statistik',
									 '_fehlerseiten', '_pwschutz', '_phpupload', '_dirlist', '_wap') {
		$self->{$key} = 0;
	}

  $self->{'_domainset'} = Modules::Apache::Config::DomainSet->new;

  return $self;
}

sub setattr {
  my $self = shift;
  if ( @_){
    my %args = (
	      @_
	     );

		while ( my ($key,$value) = each %args ) {
			if ( $key eq 'domain' ) {
				if ( ref($self->{'_domainset'} )=~/DomainSet/i ){
					$self->{'_domainset'}->domain( $value );
				}
			} else {
				$self->{"_$key"} = $value;
			}
		}
  }
}

sub copyfrom {
  my $self = shift;
  if ( @_){
    my $src=shift;
    if (ref($src) =~ /$class/ ){
      $self->{'_ip'} = $src->ip;
      $self->{'_pfad'} = $src->pfad;
      $self->{'_kunde'} = $src->kunde;
      $self->{'_uid'} = $src->uid;
      $self->{'_cssl'} = $src->cssl;
      $self->{'_level'} = $src->level;
      $self->{'_gesperrt'} = $src->gesperrt;
      $self->{'_zusatz'} = $src->zusatz;

      $self->{'_frontpage'} = $src->fronpage;
      $self->{'_perl'} = $src->perl;
      $self->{'_modpython'} = $src->modpython;
      $self->{'_php'} = $src->php;
      $self->{'_ssi'} = $src->ssi;
      $self->{'_statistik'} = $src->statistik;
      $self->{'_fehlerseiten'} = $src->fehlerseiten;
      $self->{'_pwschutz'} = $src->pwschutz;
      $self->{'_phpupload'} = $src->phpupload;
      $self->{'_dirlist'} = $src->dirlist;
      $self->{'_wap'} = $src->wap;

      if ( ref($self->{'_domainset'} ) ) {
				$self->{'_domainset'}->copyfrom( $src->domainset );
      }
    }
  }
}


sub clone {
  my $class = shift;
  my $self = {};

  if ( @_){
    my $src=shift;
    if (ref($src) =~ /$class/){
      bless($self, $class);
      $self->copyfrom($src);
      return $self;
    }
  }
}


sub ip {
  my $self = shift;
  if ( @_ ) {
    $self->{'_ip'} = shift;
  }
  return $self->{'_ip'};
}

sub pfad {
  my $self = shift;
  if ( @_ ) {
    $self->{'_pfad'} = shift;
  }
  return $self->{'_pfad'};
}

sub cssl {
  my $self = shift;
  if ( @_ ) {
    $self->{'_cssl'} = shift;
  }
  return $self->{'_cssl'};
}

sub gesperrt {
  my $self = shift;
  if ( @_ ) {
    $self->{'_gesperrt'} = shift;
  }
  return $self->{'_gesperrt'};
}

sub level {
  my $self = shift;
  if ( @_ ) {
    $self->{'_level'} = shift;
  }
  return $self->{'_level'};
}

sub zusatz {
  my $self = shift;
  if ( @ _) {
    $self->{'_zusatz'} = shift;
  }
  return $self->{'_zusatz'};
}

sub getkey {
  my $self = shift;
  return join('#!#',$self->{'_level','_gesperrt','_ip','_pfad','_kunde','_cssl','_zusatz'});
}

sub isequiv {
  my $self = shift;
  my $ret;
  if ( @_ ){
    my $pattern = shift;
    if (ref($pattern) =~ /$class/){
      $ret = $self->{'_ip'}       eq $pattern->ip   &&
	     $self->{'_pfad'}     eq $pattern->pfad &&
	     $self->{'_kunde'}    eq $pattern->kunde &&
	     $self->{'_cssl'}     == $pattern->cssl &&
	     $self->{'_level'}    == $pattern->level &&
	     $self->{'_gesperrt'} == $pattern->gesperrt &&
	     $self->{'_zusatz'}   eq $pattern->zusatz;
    }
  }
  return $ret;
}

sub totext {
  my $self = shift;
  my $prefix = shift||'';
  my $ret='';
  my ($key,$val,$rec,$ref,$cnt,$i,$vkey,$vval);
  while (($key,$val)=(each %$self)){
    if ( $key eq '_domainset' && defined( $val ) ){
      $ret .= "$prefix$key:\t(".ref($val).")\n";
      $ret .= $val->totext("$prefix\t");
    }else{
      $ref = ref($val);
      if ($ref eq 'ARRAY'){
				$cnt = @$val;
				$ret .= "$prefix$key (array) $cnt:\n";
				for ($i=0; $i<$cnt; $i++) {
					$ret .= "$prefix\t[$i]:\t".$val->[$i]."\n";
				}

      } elsif ( $ref eq 'HASH' ) {
				$cnt = scalar(keys %$val);
				$ret .= "$prefix$key (hash) $cnt:\n";
				while ( ( $vkey,$vval ) = ( each %$val ) ) {
					$ret .= "$prefix\t$vkey\t=>\t$vval\n";
				}

      } else {
				if ( defined ( $val ) ) {
					$ret .= "$prefix$key\t=\t$val\n";
				}else{
					$ret .= "$prefix$key\t=\tundef\n";
				}
      }
    }
  }
  return $ret;
}

sub kunde {
  my $self = shift;
  if ( @_ ) {
    $self->{'_kunde'} = shift;
  }
  return $self->{'_kunde'};
}

sub uid {
  my $self = shift;
  if ( @_ ) {
    $self->{'_uid'} = shift;
  }
  return $self->{'_uid'};
}


sub domain {
 my $self = shift;
 if ( defined $self->{'_domainset'} ) {
   return $self->{'_domainset'}->domain( @_ );
 }else{
   return undef;
 }
}


sub frontpage {
  my $self = shift;
  if ( @_ ) {
    $self->{'_frontpage'} = shift;
  }
  return $self->{'_frontpage'};
}

sub perl {
  my $self = shift;
  if ( @_ ) {
    $self->{'_perl'} = shift;
  }
  return $self->{'_perl'};
}

sub modpython {
  my $self = shift;
  if ( @_ ) {
    $self->{'_modpython'} = shift;
  }
  return $self->{'_modpython'};
}

sub php {
  my $self = shift;
  if ( @_ ) {
    $self->{'_php'} = shift;
  }
  return $self->{'_php'};
}

sub ssi {
  my $self = shift;
  if ( @_ ) {
    $self->{'_ssi'} = shift;
  }
  return $self->{'_ssi'};
}

sub statistik {
  my $self = shift;
  if ( @_ ) {
    $self->{'_statistik'} = shift;
  }
  return $self->{'_statistik'};
}

sub fehlerseiten {
  my $self = shift;
  if ( @_ ) {
    $self->{'_fehlerseiten'} = shift;
  }
  return $self->{'_fehlerseiten'};
}

sub pwschutz {
  my $self = shift;
  if (@_) {
    $self->{'_pwschutz'} = shift;
  }
  return $self->{'_pwschutz'};
}

sub phpupload {
  my $self = shift;
  if (@_) {
    $self->{'_phpupload'} = shift;
  }
  return $self->{'_phpupload'};
}

sub dirlist {
  my $self = shift;
  if (@_) {
    $self->{'_dirlist'} = shift;
  }
  return $self->{'_dirlist'};
}

sub wap {
  my $self = shift;
  if (@_) {
    $self->{'_wap'} = shift;
  }
  return $self->{'_wap'};
}

sub domains {
  my $self = shift;
  if ( ref( $self->{'_domainset'} ) ) {
    return $self->{'_domainset'}->domains;
  }else{
    return undef;
  }
}


sub cntdomains {
  my $self = shift;
  if ( ref( $self->{'_domainset'} ) ) {
    return $self->{'_domainset'}->count;
  }else{
    return 0;
  }
}

sub indomains {
  my $self = shift;
  if ( defined( $self->{'_domainset'})){
    return $self->{'_domainset'}->has( @_ );
  }else{
    return 0;
  }
}

sub domainset {
  my $self = shift;
  return $self->{'_domainset'};
}

1;
