HEX
Server: Apache/2.4.41 (FreeBSD) OpenSSL/1.0.2s mod_fcgid/2.3.9
System: FreeBSD salazo 12.0-RELEASE-p1303-ZFS hostBSD 12.0-RELEASE-p1303-ZFS DMR amd64
User: admin (1000)
PHP: 7.4.3
Disabled: NONE
Upload Files
File: /usr/local/www/apache24/cgi-bin/easytecc4/validator.pm
package validator;

BEGIN {
	if(-e '/etc/sudoers'){
		
		my $osversion = `/usr/bin/uname -K`;
		chomp $osversion;
		
		my $perl;
		
		if($osversion >= 1300000){
			
			$perl = '5.34';
		
		} elsif($osversion >= 1200000){
			
			$perl = '5.26';
		
		} elsif($osversion >= 1003000){
			
			$perl = '5.24';

		} else {
			
			$perl = '5.20';
			
		}
		
		@INC = (
				"/usr/iports/lib/perl5/site_perl",
				"/usr/iports/lib/perl5/amd64-freebsd-thread-multi",
				"/usr/iports/lib/perl5/$perl",
				"/usr/iports/lib/perl5/$perl/mach",
				"/usr/iports/lib/perl5/site_perl/mach/$perl",
				"/usr/local/lib/perl5/site_perl",
				"/usr/local/lib/perl5/amd64-freebsd-thread-multi",
				"/usr/local/lib/perl5/$perl",
				"/usr/local/lib/perl5/$perl/mach",
				"/usr/local/lib/perl5/site_perl/mach/$perl",
				"/usr/local/www/apache24/cgi-bin/easytecc4"
		);
				
			
	} else {
		push @INC, '/home/httpd/cgi-bin/easytecc4';
	}
}

require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(validate_input);

use Data::FormValidator::Constraints qw(:closures);
use Data::Validate::IP qw(is_ipv4);
use Data::FormValidator;
use CGI::Session;
use User::pwent;
use File::Basename;
use DBI;
use Net::IDN::Encode ':all';
use Encode;
use CGI::Carp "fatalsToBrowser";
use easytecc_class;
use easytecc3 qw(ascii_domain is_domain is_email is_tld);
my %input;
my $session;
use Passwd::Unix;
use Crypt::Passwd;
	
use Data::Dumper;	
	
#Jimmy: Log around the world
use Log::Dispatch;
use Log::Dispatch::File;
use File::Spec;
use Time::Format qw(%time %strftime);

use constant LOG_DIR    => '/home/web/log';
use constant LOG_FILE   => 'easytecc4.log';

our $loglevel = 'debug'; #'debug','info','notice','warning','error','critical','alert','emergency' # most reasonable is 'warning' or 'error' for production

sub dienice ($);
sub logline($$);

#
# Begin setup logging agent
# 

our $log = new Log::Dispatch(
		callbacks => sub {
logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	    	my %h=@_;
    	    my ($package, $filename, $line) = caller;
        	my $level = sprintf '%-8.8s', $h{level};
	        return $strftime{'%b %e %T'}." \[$$]: ".$level." => ".$h{message}."\n";
	    }
);
$log->add( Log::Dispatch::File->new( name      => 'logfile',
                                     min_level => $loglevel,
                                     mode      => 'append',
                                     filename  => File::Spec->catfile(LOG_DIR, LOG_FILE),
                                   )
);

my $debug = 1 if(-e '/etc/easytecc'); #run logline("debug",...) only when $debug=1

#
# End setup logging agent
#

my $fb = "";
if (-e '/etc/sudoers') {
    $fb = '1';
}

my ($easytecc_prefix, $droot_prefix, $droot_regex, $awstats_updateall, $awstats_conf_prefix);

if ($fb) {
	$easytecc_prefix = '/usr/local/www/apache24/cgi-bin/easytecc4';
	$droot_prefix = '/usr/local/www/apache24/noexec';
	$droot_regex = '\/usr\/local\/www\/apache24\/(noexec|data)\/?';
	$cgi_prefix = '/usr/local/www/apache24/cgi-bin';
	$awstats_updateall = '/usr/local/www/awstats/tools/awstats_updateall.pl -configdir=/usr/local/etc/awstats';
	$mysqlbackup_dir = '/usr/local/etc/easytecc/mysqlbackup';
	$mysql = '/usr/iports/bin/mysql';
	$awstats_conf_prefix = '/usr/local/etc/awstats';
}
else{
	$easytecc_prefix = '/home/httpd/cgi-bin/easytecc4';
	$droot_prefix = '/home/httpd/docs';
	$droot_regex = '\/home\/httpd\/docs\/';
	$cgi_prefix = '/home/httpd/cgi-bin';
	$awstats_updateall = '/usr/local/awstats/tools/awstats_updateall.pl';
	$mysqlbackup_dir = '/var/lib/mysqlbackup';
	$mysql = '/usr/local/mysql/bin/mysql';
	$awstats_conf_prefix = '/etc/awstats';
	
	#not used on FreeBSD, so use would fail
	eval "use Crypt::Passwd; 1";
}


sub validate_input{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my $input_hash_ref = shift;
	my $session_ref = shift;
	%input = %$input_hash_ref;
	$session = $$session_ref;

	my $profile = '';
	my $results = '';
	# Zu modifizierende Datei wird von Validator geöffnet und Objekt wird mit $result zurück an Anwendung gegeben, damit Datei
	# nicht zweimal geöffnet werden muss.
	my %file_handlers;

	my %error_message = (
		missing => 'Not Here!',
		invalid => 'Problematic!',
		invalid_separator => ' <br /> ',
		format => '%s'
	);

	if($input{'action'} eq 'exec_login'){
		$profile = {
			filters => 'trim',
			required => [qw( login_user login_password )],
			constraint_methods => {
				login_user =>  validate_auth( $input{'login_password'},  $input{'login_code'})
			}
		};
	}

	if($input{'action'} eq 'exec_new_forward'){
		my $httpd_conf = file->new({file_name => '/etc/httpd/conf/httpd.conf'});
		$httpd_conf->read_file;
		$profile = {
			filters => 'trim',
			required => [qw(	email
								domain_select
								password
								quota
			)],
			optional => [qw( alias forward )],
			optional_regexp => qr/^(alias|forward|domain_alias_select)[1-9]{1,2}/,
			constraint_method_regexp_map => {
				qr/^alias[1-9]{1,2}/    => validate_alias('not_exists', '@' . $input{'domain_select'}),
				qr/^forward[1-9]{1,2}/    => validate_email( 'valid'),
				qr/^domain_alias_select[1-9]{1,2}/    => validate_domain( 'exists', $httpd_conf, $input{'domain'})
			},
			constraint_methods => {
				domain_select => validate_domain( 'exists', $httpd_conf, $input{'domain'}),
				email => validate_email( 'valid', '@' . $input{'domain_select'} ),
				email => validate_email( 'not_exists', '@' . $input{'domain_select'} ),
				password => validate_pass($input{'email'} . '@' . $input{'domain_select'}),
				quota => validate_popquota()
			}
		};
	}

	if($input{'action'} eq 'exec_edit_forward'){
		my $httpd_conf = file->new({file_name => '/etc/httpd/conf/httpd.conf'});
		$httpd_conf->read_file;
		$profile = {
			filters => 'trim',
			required => [qw(	edit_email
								domain_select
								edit_password
								edit_quota
			)],			
			optional_regexp => qr/^(alias|forward|domain_alias_select)[1-9]{1,2}/,
			constraint_method_regexp_map => {
				qr/^edit_alias[1-9]{1,2}/    => validate_alias('edit_not_exists', '@' . $input{'domain_select'}),
				qr/^edit_forward[1-9]{1,2}/    => validate_email( 'valid'),
				qr/^domain_alias_select[1-9]{1,2}/    => validate_domain( 'exists', $httpd_conf, $input{'edit_domain'})
			},
			constraint_methods => {
				domain_select => validate_domain( 'exists', $httpd_conf, $input{'edit_domain'}),
				edit_email => validate_email( 'valid', '@' . $input{'domain_select'} ),
				edit_email => validate_email( 'edit_not_exists', '@' . $input{'domain_select'} ),
				edit_password => validate_pass($input{'email'} . '@' . $input{'domain_select'}),
				edit_quota => validate_popquota(),
			}
		};
	}

	if($input{'action'} eq 'exec_new_vhost'){
		
		my $httpd_conf = file->new({file_name => '/etc/httpd/conf/httpd.conf'});
		$httpd_conf->read_file;
		$profile = {
			filters => 'trim',
			required => [qw(	domains
								serveradmin
								droot
								quota
			)],
			optional => [qw(	ip_select
								stats
								webmail
								cgi-bin
								cgi-local
								special
								ftpuser
								ftppass
								ftpdescription
								ftpquota
								db
								dbuser
								dbpass
								pop
								for
								aut
								custom_tag
								admin_users
								openbasedir
			)],
			constraint_methods => {
				domains => [ validate_domains( 'valid', $httpd_conf ),
				validate_domains( 'not_exists', $httpd_conf), 
				validate_domains( 'allowed_admin_user', $httpd_conf) ],
				quota => validate_vhostquota(),
				serveradmin => validate_email('valid'),
				special => validate_special_httpd_conf(),
				droot => [ validate_directory('valid'), validate_documentroot(), validate_home()],
				'pop' => validate_pop3(),
				'for' => validate_forward(),
				aut => validate_autoresponder(),
				db => [	validate_db( 'valid' ),
				validate_db( 'not_exists' )],
				dbuser => validate_dbuser( 'valid' ),
				dbpass => validate_pass($input{'dbuser'}),
				ftpuser => [ validate_ftpuser( 'valid' ),
				validate_ftpuser( 'not_exists' )],
				ftppass => validate_pass($input{'ftpuser'}),
				ftpdescription => validate_description(),
				ftpquota => validate_ftpquota($input{'quota'}),
				custom_tag => validate_custom_tag($input{'custom_tag'}),
				admin_users => validate_adminusers(),
				openbasedir => validate_openbasedir(),
			},
			dependencies   => {
				mysql_db => [ qw( db dbuser dbpass ) ],
				ftp => [ qw( ftpuser ftppass ftpdescription ftpquota ) ]
			}
		};
	}

	if($input{'action'} eq 'exec_delete_vhost'){
		my $httpd_conf = file->new({file_name => '/etc/httpd/conf/httpd.conf'});
		$httpd_conf->read_file;
		$profile = {
			filters => 'trim',
			required => [qw( domain )],
			constraint_methods => {
				domain => validate_domain('exists', $httpd_conf),
			}
		};
	}

	if($input{'action'} eq 'exec_change_vhost'){
		my $httpd_conf = file->new({file_name => '/etc/httpd/conf/httpd.conf'});
		$httpd_conf->read_file;
		$profile = {
			filters => 'trim',
			required => [qw(	vhost
								domain
								ip
								port
								serveradmin
								droot
			)],
			optional => [qw(	domains
								redirect_domain
								ip_select
								quota
								stats
								webmail
								cgi-bin
								cgi-local
								special
								pop
								for
								aut
								ftpuser
								ftpquota
								ssl_port
								custom_tag
								admin_users
								openbasedir
			)],
			constraint_methods => {
				vhost => [	validate_domain( 'valid' ),
				validate_domain( 'exists', $httpd_conf, $input{'vhost'})],
				domain => [ validate_domain( 'valid' ),
				validate_domain( 'allowed_admin_user', $httpd_conf) ],
				domains => [ validate_domains( 'valid', $httpd_conf ),
				validate_domains( 'allowed_admin_user', $httpd_conf) ],
				redirect_domain => validate_domain('redirect'),
				quota => validate_vhostquota($input{'ftpquota'}, $input{'ftpuser'}),
				serveradmin => validate_email('valid'),
				special => validate_special_httpd_conf(),
				droot => [ validate_directory('valid'), validate_directory('exists'), validate_documentroot(), validate_home() ], 
				'pop' => validate_pop3(),
				'for' => validate_forward(),
				aut => validate_autoresponder(),
				ssl_port => validate_ssl_port(),
				custom_tag => validate_custom_tag($input{'custom_tag'}),
				admin_users => validate_adminusers(),
				openbasedir => validate_openbasedir(),
			}
		};
	}

	if($input{'action'} eq 'exec_change_popuser'){
		my $httpd_conf = file->new({file_name => '/etc/httpd/conf/httpd.conf'});
		$httpd_conf->read_file;
		$profile = {
			filters => 'trim',
			optional => [qw(	ftpuser
								ftpquota
			)],
			constraint_methods => {
				ftpuser => validate_ftpuser( 'exists' ),
				ftpquota => validate_ftpquota(),
			}
		};
	}

	if($input{'action'} eq 'exec_change_forward'){
		my $httpd_conf = file->new({file_name => '/etc/httpd/conf/httpd.conf'});
		$httpd_conf->read_file;
		$profile = {
			filters => 'trim',
			required => [qw( domain )],
			constraint_methods => {
				domain => validate_domain( 'exists', $httpd_conf )
			}
		};
	}
	
	if($input{'action'} eq 'exec_new_forward_single_edit'){
		my $httpd_conf = file->new({file_name => '/etc/httpd/conf/httpd.conf'});
		$httpd_conf->read_file;
		$profile = {
			filters => 'trim',
			required => [qw( domain )],
			constraint_methods => {
				domain => validate_domain( 'exists', $httpd_conf )
			}
		};
	}
	
	if($input{'action'} eq 'exec_change_forward_single_edit'){
		my $httpd_conf = file->new({file_name => '/etc/httpd/conf/httpd.conf'});
		$httpd_conf->read_file;
		$profile = {
			filters => 'trim',
			required => [qw( domain )],
			constraint_methods => {
				domain => validate_domain( 'exists', $httpd_conf )
			}
		};
	}

	if($input{'action'} eq 'exec_new_install'){
		my $httpd_conf = file->new({file_name => '/etc/httpd/conf/httpd.conf'});
		$httpd_conf->read_file;
		$profile = {
			filters => 'trim',
			required => [qw( domain )],
			constraint_methods => {
				domain => validate_domain( 'exists', $httpd_conf )
			}
		};
	}
	
	if($input{'action'} eq 'show_filemanager'){
		$profile = {
			filters => 'trim',
			optional => 'dir',
			constraint_methods => {
				dir => [ validate_directory( 'exists'), validate_directory( 'valid') ]
			}
		};
	}
	
	if($input{'action'} eq 'exec_new_dir'){
		$profile = {
			filters => 'trim',
			required => [ qw(dir newdir) ],
			constraint_methods => {
				newdir => [ validate_new_directory( 'notexists'), validate_new_directory( 'valid') ]
			}
		};
	}

	if($input{'action'} eq 'exec_new_autoreply'){
		$profile = {
			filters => 'trim',
			required => [qw(	forward )],
			optional => [qw(	autoreply_subject
								autoreply_text
			)],
			constraint_methods => {
				forward => validate_email( 'valid' ),
				autoreply_subject => validate_autoreply_subject(),
				autoreply_text => validate_autoreply_text(),
			}
		};
	}

	if($input{'action'} eq 'exec_new_ftpuser'){
		$profile = {
			filters => 'trim',
			required => [qw(	ftpuser
								ftppass
								ftpquota
			)],
			optional => [qw(	gecos
								home
			)],
			constraint_methods => {
				ftpuser => [ validate_ftpuser( 'valid' ),
				validate_ftpuser( 'not_exists' )],
				ftppass => validate_pass($input{'ftpuser'}),
				gecos => validate_description(),
				ftpquota => validate_ftpquota(),
				home => [ validate_home()],
			}
		};
	}

	if($input{'action'} eq 'exec_new_adminuser'){
		$profile = {
			filters => 'trim',
			required => [qw(	ftpuser
								ftppass
								ftpquota
			)],
			optional => [qw(	home
			)],
			constraint_methods => {
				ftpuser => [ validate_ftpuser( 'valid' ),
				validate_ftpuser( 'not_exists' )],
				ftppass => validate_pass($input{'ftpuser'}),
				ftpquota => validate_ftpquota(),
				home => [ validate_home()],
				general => [ validate_is_admin()],
			}
		};
	}
	
	if($input{'action'} eq 'exec_delete_ftpuser'){
		$profile = {
			filters => 'trim',
			required => [qw( 	ftpuser
								delete_home
			)],
			constraint_methods => {
				ftpuser => validate_ftpuser( 'exists'),
			}
		};
	}
	
	if($input{'action'} eq 'exec_delete_adminuser'){
		$profile = {
			filters => 'trim',
			required => [qw( 	ftpuser
								delete_home
			)],
			constraint_methods => {
				ftpuser => validate_ftpuser( 'exists'),
			}
		};
	}

	if($input{'action'} eq 'exec_change_ftpuser' || $input{'action'} eq 'exec_change_adminuser'){
		$profile = {
			filters => 'trim',
			required => [qw(	ftpuser
								ftpquota
								home
			)],
			optional => [qw(	gecos
								ftppass
								home_action
			)],
			constraint_methods => {
				ftpuser => validate_ftpuser( 'exists' ),
				ftppass => validate_pass($input{'ftpuser'}),
				gecos => validate_description(),
				ftpquota => validate_ftpquota(),
				home =>  validate_home($input{'ftpuser'}),
				home_action => validate_home_action()
			}
		};
		
		if($input{'action'} eq 'exec_change_adminuser'){
			$profile->{constraint_methods}->{general} = [ validate_is_admin()];
		}
	}
	
	if($input{'action'} eq 'exec_change_ftpuser_usertool'){
		$profile = {
			filters => 'trim',
			required => [qw( ftpuser )],
			optional => [qw( ftppass )],
			constraint_methods => {
				ftpuser => validate_ftpuser( 'exists' ),
				ftppass => validate_pass($input{'ftpuser'})
			}
		};
	}

	if($input{'action'} eq 'exec_change_spamfilter'){
		$profile = {
			filters => 'trim',
			required => [qw(	spamd
								pspam_level
								cspam_level
								action_virus
								action_pspam
								action_cspam
								report_safe
			)],
			optional => [qw(	whitelist
								blacklist
								postfix_virus
								subj_virus
								subj_pspam
								subj_cspam
								junkfolder
			)],
			constraint_methods => {
				pspam_level => validate_pspam_level(),
				cspam_level => validate_cspam_level(),
				action_virus => validate_action_virus(),
				action_pspam => validate_action_pspam(),
				action_cspam => validate_action_cspam(),
				report_safe => validate_report_safe(),
				whitelist => validate_email_white_blacklist(),
				blacklist => validate_email_white_blacklist(),
				postfix_virus => validate_postfix_virus(),
				subj_virus => validate_subjectprefix(),
				subj_pspam  => validate_subjectprefix(),
				subj_cspam => validate_subjectprefix(),
				junkfolder => validate_imap_folder(),
			}
		};
	}

	if($input{'action'} eq 'exec_new_special_spamfilter'){
		$profile = {
			filters => 'trim',
			required => [qw(	special_spam_user_domain
								special_spamd
								special_pspam_level
								special_cspam_level
								special_action_virus
								special_action_pspam
								special_action_cspam
								special_report_safe
			)],
			optional => [qw(	special_whitelist
								special_blacklist
								special_postfix_virus
								special_subj_virus
								special_subj_pspam
								special_subj_cspam
								special_junkfolder
			)],
			constraint_methods => {
				special_spam_user_domain => validate_spam_user_domain('not_exists'),
				special_pspam_level => validate_pspam_level(),
				special_cspam_level => validate_cspam_level(),
				special_action_virus => validate_action_virus(),
				special_action_pspam => validate_action_pspam(),
				special_action_cspam => validate_action_cspam(),
				special_report_safe => validate_report_safe(),
				special_whitelist => validate_email_white_blacklist(),
				special_blacklist => validate_email_white_blacklist(),
				special_postfix_virus => validate_postfix_virus(),
				special_subj_virus => validate_subjectprefix(),
				special_subj_pspam  => validate_subjectprefix(),
				special_subj_cspam => validate_subjectprefix(),
				special_junkfolder => validate_imap_folder(),
			}
		};
	}

	if($input{'action'} eq 'exec_change_special_spamfilter'){
		$profile = {
			filters => 'trim',
			required => [qw(	special_spam_user_domain
								special_spamd
								special_pspam_level
								special_cspam_level
								special_action_virus
								special_action_pspam
								special_action_cspam
								special_report_safe
			)],
			optional => [qw(	special_whitelist
								special_blacklist
								special_postfix_virus
								special_subj_virus
								special_subj_pspam
								special_subj_cspam
								special_junkfolder
			)],
			constraint_methods => {
				special_spam_user_domain => validate_spam_user_domain(),
				special_pspam_level => validate_pspam_level(),
				special_cspam_level => validate_cspam_level(),
				special_action_virus => validate_action_virus(),
				special_action_pspam => validate_action_pspam(),
				special_action_cspam => validate_action_cspam(),
				special_report_safe => validate_report_safe(),
				special_whitelist => validate_email_white_blacklist(),
				special_blacklist => validate_email_white_blacklist(),
				special_postfix_virus => validate_postfix_virus(),
				special_subj_virus => validate_subjectprefix(),
				special_subj_pspam  => validate_subjectprefix(),
				special_subj_cspam => validate_subjectprefix(),
				special_junkfolder => validate_imap_folder(),
			}
		};
	}

	if($input{'action'} eq 'exec_delete_special_spamfilter'){
		$profile = {
			filters => 'trim',
			required => [qw( special_spam_user_domain)],
			constraint_methods => {
				special_spam_user_domain => validate_spam_user_domain(),
			}
		};
	}

	if($input{'action'} eq 'exec_change_virusfilter'){
		$profile = {
			filters => 'trim',
			optional => [qw(	virusfilter
								virus_whitelist
								report_safe
								virus_found_sender
								virus_found_subject
								virus_found_text
								virusheader
			)],
			constraint_methods => {
				virusfilter => validate_virusfilter(),
				virus_whitelist => validate_email_white_blacklist(),
				report_safe => validate_report_safe(),
				virus_found_sender => validate_email('valid'),
				virus_found_subject => validate_virus_subject(),
				virus_found_text => validate_virus_text(),
				virusheader => validate_virus_header()
			}
		};
	}

	if($input{'action'} eq 'exec_scan_antivirus'){
		$profile = {
			filters => 'trim',
			required => [qw( filename )]
		};
	}

	if($input{'action'} eq 'exec_new_cronjob'){
		my $cronfile = file->new({file_name => '/home/web/cronfile'});
		$cronfile->read_file;
		my %cronjobs = %{$cronfile->file_parsed_hash()};
		$profile = {
			filters => 'trim',
			required => [qw(	min
								std
								mday
								mon
								wday
								command
			)],
			constraint_methods => {
				min => validate_cron_minute(),
				std => validate_cron_hour(),
				mday => validate_cron_day(),
				mon => validate_cron_month(),
				wday => validate_cron_weekday(),
				command => validate_cron_command(),
			}
		};
	}

	if($input{'action'} eq 'exec_auto_cronjob'){
		my $cronfile = file->new({file_name => '/home/web/cronfile'});
		$cronfile->read_file;
		my %cronjobs = %{$cronfile->file_parsed_hash()};
		$profile = {
			filters => 'trim',
			required => [qw( type )],
			constraint_methods => {
				type => validate_auto_cronjob(),
			}
		};
	}

	if($input{'action'} eq 'exec_delete_cronjob'){
		my $cronfile = file->new({file_name => '/home/web/cronfile'});
		$cronfile->read_file;
		my %cronjobs = %{$cronfile->file_parsed_hash()};
		$profile = {
			filters => 'trim',
			required => [qw(cronjob)],
			msgs => \%error_message,
			constraint_methods => {
				cronjob => validate_cronjob_line('exists', \%cronjobs),
			}
		};
	}

	if($input{'action'} eq 'exec_change_cronjob'){
		my $cronfile = file->new({file_name => '/home/web/cronfile'});
		$cronfile->read_file;
		my %cronjobs = %{$cronfile->file_parsed_hash()};
		$profile = {
			filters => 'trim',
			required => [qw( min
			std
			mday
			mon
			wday
			command
			cronjob )],
			constraint_methods => {
				min => validate_cron_minute(),
				std => validate_cron_hour(),
				mday => validate_cron_day(),
				mon => validate_cron_month(),
				wday => validate_cron_weekday(),
				command => validate_cron_command(),
				cronjob => validate_cronjob_line('exists', \%cronjobs)
			}
		};
	}

	if($input{'action'} eq 'exec_change_errordocs'){
		$profile = {
			filters => 'trim',
			optional => [qw( 401
							 403
							 404
							 500
			)],
		};
	}

	if($input{'action'} eq 'exec_new_htaccess'){
		$profile = {
			filters => 'trim',
			required => [qw( dir
			htaccessuser
			htaccesspass )],
			constraint_methods => {
				dir => [validate_directory('exists'),validate_directory('writeable')],
				htaccessuser => validate_user(),
				htaccesspass => validate_pass($input{'htaccessuser'}),
			}
		};
	}

	if($input{'action'} eq 'exec_delete_htaccess'){
		$profile = {
			filters => 'trim',
			required => [qw( dir )],
			optional => htaccessuser,
			constraint_methods => {
				dir => validate_directory('exists'),
			}
		};
	}

	if($input{'action'} eq 'exec_change_htaccess' && $input{'type'} eq 'newuser'){
		$profile = {
			filters => 'trim',
			required => [qw( dir type htaccessuser_newuser htaccesspass_newuser)],
			constraint_methods => {
				dir => validate_directory(),
				htaccessuser_newuser => validate_user(),
				htaccesspass_newuser => validate_pass($input{'htaccessuser_newuser'}),
				type => validate_change_htaccess_type()
			}
		};
	}
	
	if($input{'action'} eq 'exec_change_htaccess' && $input{'type'} eq 'changepass'){
		$profile = {
			filters => 'trim',
			required => [qw( dir type htaccesspass_changepass user_select)],
			constraint_methods => {
				dir => validate_directory(),
				user_select => validate_user(),
				htaccesspass_changepass => validate_pass($input{'user_select'}),
				type => validate_change_htaccess_type()
			}
		};
	}

	if($input{'action'} eq 'new_htaccess'){
		$profile = {
			filters => 'trim',
			optional => dir,
			constraint_methods => {
				dir => validate_directory( 'exists')
			}
		};
	}

	if($input{'action'} eq 'change_htaccess'){
		$profile = {
			filters => 'trim',
			optional => dir,
			constraint_methods => {
				dir => validate_directory( 'exists')
			}
		};
	}

	if($input{'action'} eq 'delete_htaccess'){
		$profile = {
			filters => 'trim',
			required => type,
			optional => dir,
			constraint_methods => {
				dir => validate_directory( 'exists'),
				type => validate_delete_htaccess_type()
			}
		};
	}

	if($input{'action'} eq 'exec_delete_domainlog'){
		$profile = {
			filters => 'trim',
			required => [qw( domain )],
			constraint_methods => {
				domain => validate_domain(),
			}
		};
	}

	if($input{'action'} eq 'exec_change_quota'){
		$profile = {
			filters => 'trim',
			required => [qw( user
						quota )],
			constraint_methods => {
				user => validate_user(),
				quota => validate_quota(),
			}
		};
	}

	if($input{'action'} eq 'exec_new_frontpage'){
		my $httpd_conf = file->new({file_name => '/etc/httpd/conf/httpd.conf'});
		$httpd_conf->read_file;
		$profile = {
			filters => 'trim',
			required => [qw( domain_select
			frontpageuser
			password )],
			constraint_methods => {
				domain_select => validate_domain('exists', $httpd_conf),
				frontpageuser => validate_frontpageuser(),
				password => validate_pass($input{'frontpageuser'}),
			}
		};
	}

	if($input{'action'} eq 'exec_delete_frontpage'){
		my $httpd_conf = file->new({file_name => '/etc/httpd/conf/httpd.conf'});
		$httpd_conf->read_file;
		$profile = {
			filters => 'trim',
			required => [qw( domain )],
			constraint_methods => {
				domain => validate_frontpage_domain('exists'),
			}
		};
	}

	if($input{'action'} eq 'exec_delete_mysqlbackup'){
		$profile = {
			filters => 'trim',
			required => [qw( database
						backup)],
			constraint_methods => {
				backup => validate_mysql_backup('exists', $input{'database'}),
			}
		};
	}

	if($input{'action'} eq 'exec_delete_mysql_auto_backup'){
		$profile = {
			filters => 'trim',
			required => [qw( database )],
		};
	}

	if($input{'action'} eq 'exec_change_mysqlbackup'){
		$profile = {
			filters => 'trim',
			required => [qw( backup_days )],
			optional => [qw( content
						admin_email_from
						admin_email_to )],
			constraint_methods => {
				email_backup => validate_email_backup(),
				backup_days => validate_backup_days(),
				admin_email_from => validate_email('valid'),
				admin_email_to => validate_email('valid')
			},
			dependencies   => {
				email_backup => [ qw( admin_email_from admin_email_to ) ]
			}
		};
	}

	if($input{'action'} eq 'exec_add_mysql_password'){
		$profile = {
			filters => 'trim',
			required => [qw( dbuser
			dbpass )],
			constraint_methods => {
				dbuser => validate_dbuser( 'valid' ,$input{'dbpass'}),
			}
		};
	}

	if($input{'action'} eq 'exec_new_mysqluser'){
		$profile = {
			filters => 'trim',
			required => [qw( dbuser dbpass)],
			optional => [qw( db )],
			constraint_methods => {
				db => [	validate_db( 'valid' ),
				validate_db( 'not_exists' )],
				dbuser => validate_dbuser( 'valid' ),
				dbpass => validate_pass($input{'dbuser'}),
			}
		};
	}

	if($input{'action'} eq 'exec_modify_dir'){
		$profile = {
			filters => 'trim',
			required => [qw( type )],
			constraint_methods => {
				type => validate_modify_dir_type($input{'dir'}, $input{'dir_mv'}, $input{'dir_cp'}, $input{'dir_chmod'}, $input{'old_owner'}, $input{'old_chmod'}, $input{'user_select'}, $input{'group_select'})
			}
		};
	}

	if($input{'action'} eq 'exec_modify_file'){
		$profile = {
			filters => 'trim',
			required => [qw( type )],
			constraint_methods => {
				type => validate_modify_file_type($input{'file'}, $input{'full_file'}, $input{'file_mv'}, $input{'file_cp'}, $input{'dir'}, $input{'file_chmod'}, $input{'old_owner'}, $input{'old_chmod'}, $input{'user_select'}, $input{'group_select'})
			}
		};
	}

	if($input{'action'} eq 'exec_new_sendmail_cw'){
		my $sendmail_cw = file->new({file_name => '/etc/mail/sendmail.cw'});
		$sendmail_cw->read_file;

		$profile = {
			filters => 'trim',
			required => [qw( domain )],
			constraint_methods => {
				domain => [validate_sendmail_cw('valid'),
				validate_sendmail_cw('not_exists', $sendmail_cw)]
			}
		};
	}

	if($input{'action'} eq 'exec_new_quotamessage'){
		
		$profile = {
			filters => 'trim',
			required => [qw( quotasender
						 quotasubject
						 quotamessage)]
		};
	}
		
	if($input{'action'} eq 'exec_domainsearch'){
		$profile = {
			filters => 'trim',
			required => [qw( name )],
			constraint_methods => {
				name => validate_domain('valid')
			}
		};
	}
		
	if($input{'action'} eq 'exec_add_ssl_vhost'){
		
		# wtf
		if(length($input{'letsencrypt'}) && $input{'letsencrypt'}){
				
				my $httpd_conf = '';
				$httpd_conf = file->new({file_name => '/etc/httpd/conf/httpd.conf'});
				$httpd_conf->read_file;
						
				$profile = {
						filters => 'trim',
						required => [qw( domain )],
						constraint_methods => {
								domain => validate_domains('points_to_us',$httpd_conf)
						}
				};
				
		}
		
		elsif(length($input{'csr'}) && $input{'csr'}){

				$profile = {
					filters => 'trim',
					required => [qw(	csr_country
										csr_email
					)],
					optional => [qw(	csr_state
										csr_city
										csr_company
										csr_section
					)],
					constraint_methods => {
						csr_country => validate_ssl_data('csr_country'),
						csr_state => validate_ssl_data('csr_state'),
						csr_city => validate_ssl_data('csr_city'),
						csr_company => validate_ssl_data('csr_company'),
						csr_section => validate_ssl_data('csr_section'),
						csr_email => validate_email('valid')
					}	
				};		
		
		}
		
		else {
				
				$profile = {
					filters => 'trim',
					required => [qw(	cert
										key
										chain
					)],
					constraint_methods => {
						cert => validate_ssl_data('cert'),
						key => validate_ssl_data('key'),
						chain => validate_ssl_data('chain')
					}	
				};
		
		}
	}
	
	if($input{'action'} eq 'exec_change_ssl_vhost'){
		
		# wtf
		if(length($input{'letsencrypt'}) && $input{'letsencrypt'}){
				
				my $httpd_conf = '';
				$httpd_conf = file->new({file_name => '/etc/httpd/conf/httpd.conf'});
				$httpd_conf->read_file;
						
				$profile = {
						filters => 'trim',
						required => [qw( domain )],
						constraint_methods => {
								domain => validate_domains('points_to_us',$httpd_conf)
						}
				};
				
		}
		
		else {
				
				$profile = {
					filters => 'trim',
					required => [qw(	cert
										key
										chain
					)],
					constraint_methods => {
						cert => validate_ssl_data('cert'),
						key => validate_ssl_data('key'),
						chain => validate_ssl_data('chain')
					}	
				};
		
		}
	}
	
	if($input{'action'} eq 'exec_list_add_ip'){
		$profile = {
			filters => 'trim',
			required => [ qw(ip) ],
			optional => [ qw(ttl) ],
			constraint_methods => {
				ip => => validate_ip(),
				ttl => validate_firewall_ttl()
			}
		};
	}
	
	if($input{'action'} eq 'exec_web2ban_add_rule'){
		$profile = {
			filters => 'trim',
			required => [ qw(	name
								rule
			)],
			optional => [ qw(ttl) ],
			constraint_methods => {
				name => validate_firewall_key(),
				rule => validate_firewall_rule()
			}
		};
	}
	
	if($input{'action'} eq 'exec_web2ban_edit_rule'){
		$profile = {
			filters => 'trim',
			required => [ qw(	name
								rule
			)],
			optional => [ qw(ttl) ],
			constraint_methods => {
				name => validate_firewall_key(),
				rule => validate_firewall_rule()
			}
		};
	}
	
	if($input{'action'} eq 'exec_scan2ban_add_port'){
		$profile = {
			filters => 'trim',
			required => [ qw(port) ],
			constraint_methods => {
				port => => validate_portlist()
			}
		};
	}
	
	if($input{'action'} eq 'exec_logrotate'){
		$profile = {
			filters => 'trim',
			required => [ qw(	logrotate_when
								logrotate_count
			)],
			optional => [ qw(ttl) ],
			constraint_methods => {
				logrotate_when => validate_logrotate_when(),
				logrotate_count => validate_logrotate_count()
			}
		};
	}
	
	$results = Data::FormValidator->check($input_hash_ref, $profile) if $profile;
	my $hashref = $results->msgs if $profile;
	my %hash = %$hashref;
	foreach(keys %hash){
		logline("debug","msgshash $_=" . $hash{$_}) if $debug;
	}
	logline("debug", $input{'action'} . " ################################################results=" . $results->success) if $debug && $profile;
	logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
	return($results) if $profile;
}

#fbsd
sub validate_auth_fb {
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my $password = shift;
	$password =~ s/\'/\\'/g;
	
	my $code = shift;
	$code =~ s/[^0-9]+//g;
	
	logline("debug","validate_auth_fb password=$password code=$code") if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_auth');
		my $user = $dfv->get_current_constraint_value();
		
		if(! $password){
			$dfv->set_current_constraint_name('L__Login fehlgeschlagen__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
		
		# 2fa
		elsif(!$code && -f "/usr/local/etc/easytecc/2fa/$user"){
			
			$dfv->set_current_constraint_name('L__Zwei-Faktor-Authentifizierung erforderlich__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
			
		}
		
		# keep domainadmin logic
		if($ENV{'REQUEST_URI'} =~ m/\/domainadmin/ && $user ne 'admin'){
			my $env_droot = $ENV{'DOCUMENT_ROOT'};
			#my $env_domain = $ENV{'SERVER_NAME'};
			#if ($env_domain !~ /^www\./) {
			#	$env_domain = 'www.' . $env_domain;
			#}

			#my $httpd_conf = file->new({file_name => '/etc/httpd/conf/httpd.conf'});
			#$httpd_conf->read_file;
			#my %domains = %{$httpd_conf->file_parsed_hash()};

			#my $env_droot = $domains{$env_domain}{'droot'};

			#my $pw = Passwd::Unix->new('passwd' => '/etc/passwd', 'shadow' => '/etc/passwd');        	
			#my $home = $pw->home($user);

			my $pw = getpwnam($user);
			if(! $pw){
				$dfv->set_current_constraint_name('L__Login fehlgeschlagen__L');
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			
			my $home = $pw->dir;

			logline("debug","home = $home") if $debug;

			my $authenticated = `/usr/iports/bin/sudo /usr/sbin/vsauth $user '$password' $code`;
			chomp $authenticated;

			logline("debug","authenticated=$authenticated env_droot=$env_droot") if $debug;

			if($authenticated ne 'OK'){
				$dfv->set_current_constraint_name('L__Login fehlgeschlagen__L');
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif($home ne $env_droot){
				logline("debug","home=$home env_droot=$env_droot") if $debug;
				$dfv->set_current_constraint_name('L__Login fehlgeschlagen__L');
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			# nur zur Sicherheit
			elsif(! $home || ! $env_droot){
				logline("debug","gibs nicht home=$home env_droot=$env_droot") if $debug;
				$dfv->set_current_constraint_name('L__Login fehlgeschlagen__L');
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		else{
		
			if($user ne 'admin'){
			
				my $allowed = 0;
			
				my $pw = getpwnam($user);
				if(defined($pw) && $pw->gecos =~ m/^CUST/){
					$allowed = 1;
				}
				#mailuser
				elsif($user =~ /\@/ && -e "/usr/local/etc/easytecc/mailuser/$user"){
								
					$allowed = 1;
					
				}
				
				if($allowed != 1){
					$dfv->set_current_constraint_name('L__Login fehlgeschlagen__L');
					logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
					return('');
				}
			}

			my $authenticated = `/usr/iports/bin/sudo /usr/sbin/vsauth $user '$password' $code`;
			chomp $authenticated;

			logline("debug","validate_auth_user_fb password=$password authenticated=$authenticated") if $debug;

			if($authenticated ne 'OK'){
				$dfv->set_current_constraint_name('L__Login fehlgeschlagen__L');
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_auth {
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my @args = @_;
	my $password = shift;

	logline("debug","validate_auth password=$password") if $debug;

	my $ref_fb = (caller(0))[3] . '_fb';
	if(defined *$ref_fb{CODE} && $fb){
		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return($ref_fb->(@args));
	}

	return sub {
	
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_auth');
		my $user = $dfv->get_current_constraint_value();

		if(! $password){
			$dfv->set_current_constraint_name('L__Login fehlgeschlagen__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
		elsif($ENV{'REQUEST_URI'} =~ m/\/domainadmin/ && $user ne 'admin'){
	
			my $env_droot = $ENV{'DOCUMENT_ROOT'};
			# my $pw = Passwd::Unix->new('passwd' => '/etc/passwd', 'shadow' => '/etc/passwd');
			# my $password_md5 = $pw->passwd($user);

			my $pw = getpwnam($user);
			if (! ref($pw)) {
				logline("debug","pw no such user") if $debug;
				$dfv->set_current_constraint_name('L__Login fehlgeschlagen__L');
				return('');
			}
			
			
			my $password_md5 = $pw->passwd;

			# my $home = $pw->home($user);

			my $home = $pw->dir;

			my $salt = substr($password_md5, 0, 2);
			my $login_password_md5 = unix_std_crypt($password, $salt);

			if($password_md5 ne $login_password_md5){
				logline("debug","passwd_md5=$password_md5  login_md5=$login_password_md5") if $debug;
				$dfv->set_current_constraint_name('L__Login fehlgeschlagen__L');
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif($home ne $env_droot){
				logline("debug","home=$home env_droot=$env_droot") if $debug;
				$dfv->set_current_constraint_name('L__Login fehlgeschlagen__L');
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			# nur zur Sicherheit
			elsif(! $home || ! $env_droot){
				logline("debug","gibs nicht home=$home env_droot=$env_droot") if $debug;
				$dfv->set_current_constraint_name('L__Login fehlgeschlagen__L');
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		
		else{
			# my $pw = Passwd::Unix->new('passwd' => '/etc/passwd', 'shadow' => '/etc/passwd');
			# my $password_md5 = $pw->passwd('admin');

			if($user ne 'admin'){
			
				my $allowed = 0;
			
				my $pw = getpwnam($user);
				if($pw && $pw->gecos =~ m/^CUST/){
				
					$allowed = 1;
					
				}
				#mailuser
				elsif(-e "/usr/local/etc/easytecc/mailuser/$user"){
								
					$allowed = 1;
																
				}
				elsif($user =~ /^(.*)\@/ && -e "/usr/local/etc/easytecc/mailuser/$1"){
													
					$allowed = 1;
					$user =~ s/\@.*$//;
					
				}
				
				if($allowed != 1){
				
					$dfv->set_current_constraint_name('L__Login fehlgeschlagen__L');
					logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
					return('');
				
				}

			}
			
			my $password_md5 = '...';
			
			my $pw = getpwnam($user);
			if($pw){
				
				$password_md5 = $pw->passwd; 
			
			}
			elsif(easytecc3::extern_mx()){
				
				my $socket = easytecc3::make_socket();
				
				print $socket "getpasswd_user=$user\n";
				$password_md5 = <$socket>;
				$password_md5 =~ s/^[^:]+://;
				$password_md5 =~ s/:.*$//;
				
				easytecc3::close_socket($socket);	
				
			}	
			
			my $salt = substr($password_md5, 0, 2);
			my $login_password_md5 = unix_std_crypt($password, $salt);

			logline("debug","passwd_md5=$password_md5  login_md5=$login_password_md5") if $debug;

			if($password_md5 ne $login_password_md5){
				$dfv->set_current_constraint_name('L__Login fehlgeschlagen__L');
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		
		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}


sub validate_sendmail_cw {
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my ($type, $sendmail_cw) = @_;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_sendmail_cw');
		my $domain = $dfv->get_current_constraint_value();

		if($type eq 'valid' && ! is_domain($domain)){
			$dfv->set_current_constraint_name('L__Domainname ungültig__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
		elsif($type eq 'not_exists'){
			my %domains = %{$sendmail_cw->file_parsed_hash()};
			if(exists $domains{$domain}){
				$dfv->set_current_constraint_name('L__Die Domain ist bereits in der Mailkonfiguration enthalten__L');
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_domain {
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my ($type, $httpd_conf, $vhost) = @_;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_domain');
		my $domain = $dfv->get_current_constraint_value();
		#vhost kann wildcard enthalten, was aber keine gültige Domain ist
		#wildcard abscgneiden und auf Rest überprüfen
		my $wildcard_domain = '';
		$wildcard_domain = $domain if ($domain =~ /^\*\./ || $domain =~ /^www\.\*\./ );

		logline("debug","1validate_domain vhost=$vhost val=$domain type=$type wildcard_domain=$wildcard_domain") if $debug;
		$domain =~ s/^\*\.//;
		$domain =~ s/^www\.\*\.//;
		
		if($type eq 'redirect'){
			
			$domain =~ s/\/.*$//;
			$type = 'valid';
			
		}
		
		logline("debug","2validate_domain val=$domain") if $debug;
		my $domain_ohne_www = $domain;
		$domain_ohne_www =~ s/^www\.//;
		$domain_ohne_www = ascii_domain( $domain_ohne_www );

		$domain = ascii_domain( $domain );

		if($type eq 'valid' && ! is_domain($domain)){
			$dfv->set_current_constraint_name('L__Domainname ungültig__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
		elsif($type eq 'exists'){
			logline("debug",qq~domain exists:$domain wildcard_domain=$wildcard_domain\n~) if $debug;
			logline("debug",qq~domain exists:~ . ord($domain) . "") if $debug;
			if(ord($domain) == '194' || $domain eq ''){
				$dfv->set_current_constraint_name(qq~$domain: L__Es wurde kein Domainname ausgewählt__L~);
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}

			my %domains = %{$httpd_conf->file_parsed_hash()};

			logline("debug","validate_domain exists domain" . %domains . "") if $debug;

			foreach(keys %domains){
				logline("debug","validate_domain domain:$_") if $debug;
				my @array = @{$domains{$_}{'domains'}};
				foreach(@array){
					logline("debug","array domain: $_") if $debug;	

					if ($_ eq $domain_ohne_www) {
						logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
						return('1');
					}			
				}
			}

			#unless(exists $domains{$domain} || exists $domains{$wildcard_domain}){
			#unless(grep (/^$domain_ohne_www$/, @{$domains{$vhost}{'domains'}})){
			#grep geht nicht, später testen
			unless(grep ("$domain", @{$domains{$vhost}{'domains'}})){
				$dfv->set_current_constraint_name('L__Die Domain ist keinem vHost zugeordnet__L');
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		elsif($type eq 'allowed_admin_user'){
		
			# filter domains
			if($session->param('user') ne 'admin'){
		
				my %httpd_conf_domains = %{$httpd_conf->file_parsed_hash()};
				my %allowed_domains;
				my $wanted_domain = $domain;
				
				foreach $domain (sort keys %httpd_conf_domains){
	
					my $admins = $httpd_conf_domains{$domain}{'admin_users'};
					$admins =~ s/[\s,]+/#/g;
					$admins = '#' . $admins . '#';
					$userregex = '#' . $session->param('user') . '#';
				
					logline("debug","admins:$admins\nuserregex:$userregex");
					
					if($admins =~ m/$userregex/i){

						foreach my $alias_domain (@{$httpd_conf_domains{$domain}{'domains'}}){
						
							$alias_domain =~ s/^www\.//;
							$alias_domain =~ s/^\*\.//;
							
							$allowed_domains{$alias_domain} = 1;
							
							logline("debug","allowed_domain:$alias_domain");
							
						}
						
						$domain =~ s/^www\.//;
						$domain =~ s/^\*\.//;
							
						$allowed_domains{$domain} = 1;
						
						logline("debug","allowed_domain:$domain");
					
					}
				}

				$wanted_domain = ascii_domain($wanted_domain);
				$wanted_domain =~ s/^www\.//;
				$wanted_domain =~ s/^\*\.//;

				my $cname_wanted_domain = $wanted_domain;
#				$wanted_domain =~ s/^.*\.(?=.*\..*)//;
				$wanted_domain =~ s/^[^\.]*\.(?=.*\..*)//;
				
				if(!exists $allowed_domains{$wanted_domain} && !exists $allowed_domains{$cname_wanted_domain}){
				
					$dfv->set_current_constraint_name(qq~$wanted_domain:L__Diese Domain können Sie nicht anlegen oder administrieren.__L~);
					logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
					return('');
				
				}
				
			}
				
		}
		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_special_httpd_conf{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_special_httpd_conf');
		my $special = $dfv->get_current_constraint_value();

		logline("debug","validate_special_httpd_conf val=$special") if $debug;

		my $syntax_ok = '';
		#SSL?
		my $ssl = '-DSSL' if(-e '/etc/SSL');

		my $apache = "";
		my $file_tmp = "";
		my $httpd_conf = "";

		if($fb){
			$apache = "24_fb";
			$file_tmp = "/home/web/httpd.conf.new";
			$httpd_conf = "/etc/apache24/httpd.conf";
		}
		else{
			$apache = `grep httpd_enable /etc/rc.conf`;
			chomp $apache;
			$file_tmp = "/etc/httpd/conf/httpd.conf.new";
			$httpd_conf = "/etc/httpd/conf/httpd.conf";
		}	

		my $got = `cp $httpd_conf $file_tmp`;

		if($got){
			$dfv->set_current_constraint_name("Fehler: Temporäre Apachekonfigurationsdatei konnte nicht geschrieben werden\n\n$got");
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		open(OUT, ">>$file_tmp") or $got = 'Fehler: Temporäre Apachekonfigurationsdatei konnte nicht geschrieben werden\n\n';
		print OUT $special . "\n";
		close OUT;

		if($got){
			$dfv->set_current_constraint_name("Fehler: Temporäre Apachekonfigurationsdatei konnte nicht geschrieben werden\n\n$got");
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		if($apache =~ /"1"/s){
			$syntax_ok = `/usr/local/apache/bin/httpd -t -f /etc/httpd/conf/httpd.conf.new -DAP1 $ssl 2>&1`;
		}
		elsif($apache =~ /"(2|F)"/s){
			$syntax_ok = `/usr/local/apache2/bin/httpd -t -f /etc/httpd/conf/httpd.conf.new -DAP2 $ssl 2>&1`;
		}
		elsif($apache =~ /"22"/s){
			$syntax_ok = `/usr/local/apache2.2/bin/httpd -t -f /etc/httpd/conf/httpd.conf.new -DAP22 $ssl 2>&1`;
		}
		elsif($apache =~ /"24"/s){
			$syntax_ok = `/usr/local/apache2.4/bin/httpd -t -f /etc/httpd/conf/httpd.conf.new -DAP24 $ssl 2>&1`;
		}
		elsif($apache eq "24_fb"){
			$syntax_ok = `/usr/iports/bin/sudo /usr/iports/sbin/httpd -t -f $file_tmp -DAP24 $ssl 2>&1`;
		}
		else{
			$dfv->set_current_constraint_name('Fehler: Unbekannte Apacheversion');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		logline("debug","syntax_ok = $syntax_ok") if $debug;

		`rm -f $file_tmp`;
		unless( $syntax_ok =~ /Syntax OK/s ){
			$dfv->set_current_constraint_name('Fehler: Die Apache-Direktiven sind ungültig' . $syntax_ok);
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name. >> $syntax_ok") if $debug;
			return('');
		}

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_domains {
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my ($type, $httpd_conf) = @_;
	#aktuell wird $sessions nur von domain_wizard Schritt 1 benutzt, um Domains aus Formularinput zu normalisieren
	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_domains');
		my $domains = $dfv->get_current_constraint_value();

		#Zeilenumbrüche aus mehrzeiligem Fomrularfeld entfernen
		$domains =~ s/\r\n/ /g;
		#lowercase
		$domains =~ tr/A-Z/a-z/;
		#erstes www. wenn vorhanden entfernen
		$domains =~ s/^www\.//;
		#wenn andere Domains mit www. dann das auch weg
		$domains =~ s/(;|:|,|\t+|\s+)www\./ /g;
		my @domains = split m(;|:|,|\t+|\s+), $domains;
		my $session_domains = '';
		foreach(@domains){
		$session_domains .= encode('utf-8', domain_to_unicode($_)) . ' ';
		}
		#my $session_domains = $domains;
		logline("debug","session_domains=$session_domains") if $debug;
		#$session_domains =~ s/(;|:|,|\t+|\s+)/ /g;
		#logline("debug","session_domains2=$session_domains") if $debug;
		#Domains werden aktuell nur bei Domainwizard in Session gespeichern
		#$session->param(-name=>'domains', -value=>"$domains") if $session;
		$session->param(-name=>'domains', -value=>"$session_domains") if $session;

		logline("debug","validate_domains val=$domains type=$type") if $debug;

		if($type eq 'valid'){
			foreach(@domains){
				#vhost kann wildcard enthalten, was aber keine gültige Domain ist
				#wildcard abscgneiden und auf Rest überprüfen
				s/^\*\.//;
				my $domain = ascii_domain( $_ );
				logline("debug","domain valid=$_###") if $debug;
				if(! is_domain($domain)){
					$dfv->set_current_constraint_name("L__Domainname ungültig__L:$domain");
					logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
					return('');
				}
			}
		}
		elsif($type eq 'points_to_us'){
			
			my %domains = %{$httpd_conf->file_parsed_hash()};
			my $domain = ascii_domain( $domains[0] );
			
			if($domain !~ m/^www\./){
				$domain = 'www.' . $domain;
			}
			
			@domains = @{$domains{$domain}{'domains'}};
								
			foreach(@domains){
				
				#vhost kann wildcard enthalten, was aber keine gültige Domain ist
				#wildcard abscgneiden und auf Rest überprüfen
				s/^\*\.//;
				my $domain = ascii_domain( $_ );
				logline("debug","domain valid=$_###") if $debug;
				if(! is_domain($domain)){
					$dfv->set_current_constraint_name("L__Domainname ungültig__L: $domain");
					logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
					return('');
				}
				
				# unsere cache ist oft zu langsam				
				#my $DomainHostIP = `/usr/bin/host $domain`;
				my $DomainHostIP = `host -t A $domain 8.8.8.8 | tail -n 1`;
				
				chomp ($DomainHostIP);
				logline("debug","$domain points to $DomainHostIP") if $debug;
            
				if ($DomainHostIP !~ /83.138./){
					$dfv->set_current_constraint_name("L__Die Domain zeigt nicht auf Ihren Server__L: $domain");
					logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
					return('');
				}
				
			}
			
		}
		elsif($type eq 'exists'){
			my %domains = %{$httpd_conf->file_parsed_hash()};
			my $domain = ascii_domain( $domains[0] );
			if(exists $domains{$domain}){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			elsif(exists $domains{'www.' . $domain}){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			else{
				$dfv->set_current_constraint_name(qq~$domains[0]: L__Die Domain ist keinem vHost zugeordnet__L~);
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		elsif($type eq 'not_exists'){
			my %domains = %{$httpd_conf->file_parsed_hash()};
			my $domain = ascii_domain( $domains[0] );
			if(exists $domains{$domain}){
				$dfv->set_current_constraint_name(qq~$domains[0]: L__Ein vHost zu dieser Domain existiert bereits__L~);
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			if(exists $domains{'www.' . $domain}){
				$dfv->set_current_constraint_name(qq~$domains[0]: L__Ein vHost zu dieser Domain existiert bereits__L~);
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		elsif($type eq 'allowed_admin_user'){
		
			# filter domains
			if($session->param('user') ne 'admin'){
		
				my %httpd_conf_domains = %{$httpd_conf->file_parsed_hash()};
				my %allowed_domains;
				
				foreach $domain (sort keys %httpd_conf_domains){
	
					my $admins = $httpd_conf_domains{$domain}{'admin_users'};
					$admins =~ s/[\s,]+/#/g;
					$admins = '#' . $admins . '#';
					$userregex = '#' . $session->param('user') . '#';
				
					logline("debug","admins:$admins\nuserregex:$userregex");
					
					if($admins =~ m/$userregex/i){

						foreach my $alias_domain (@{$httpd_conf_domains{$domain}{'domains'}}){
						
							$alias_domain =~ s/^www\.//;
							$alias_domain =~ s/^\*\.//;
							
							$allowed_domains{$alias_domain} = 1;
							
							logline("debug","allowed_domain:$alias_domain");
							
						}
						
						$domain =~ s/^www\.//;
						$domain =~ s/^\*\.//;
							
						$allowed_domains{$domain} = 1;
						
						logline("debug","allowed_domain:$domain");
					
					}
				}
				
				
				
				foreach $wanted_domain (@domains){
				
					$wanted_domain = ascii_domain($wanted_domain);
					$wanted_domain =~ s/^www\.//;
					$wanted_domain =~ s/^\*\.//;
					
					my $cname_wanted_domain = $wanted_domain;
#					$wanted_domain =~ s/^.*\.(?=.*\..*)//;
					$wanted_domain =~ s/^[^\.]*\.(?=.*\..*)//;
					
					if(!exists $allowed_domains{$wanted_domain} && !exists $allowed_domains{$cname_wanted_domain}){
					
						$dfv->set_current_constraint_name(qq~$wanted_domain:L__Diese Domain können Sie nicht anlegen oder administrieren.__L~);
						logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
						return('');
					
					}
				}
			}
				
		}
	
		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_vhostquota{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my $ftpquota = shift;
	my $ftpuser = shift;
	$ftpquota = $ftpquota / 1024;
	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_vhostquota');
		my $vhostquota = $dfv->get_current_constraint_value();

		if($vhostquota =~ /\D/) {
			$dfv->set_current_constraint_name('L__Die Mengenangabe für die Speicherbegrenzung darf nur aus Zahlen bestehen__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
		elsif( ! $vhostquota){
			$dfv->set_current_constraint_name('L__Sie haben für den vHost keine Speicherbegrenzung ausgewählt__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
		elsif($ftpquota ne '' && $vhostquota < $ftpquota){
			$dfv->set_current_constraint_name("L__die vHost-Gesamtquota darf nicht kleiner als die Quota des FTP-Users sein__L");
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_ftpquota{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	# wird nur übermittelt, wenn vhost und gleichzeitig ftpuser angelegt wird
	# dann ist darauf zu achten, daß Quota von ftpuser kleiner oder gleich der vhostquota ist
	my $vhostquota = shift;
	
	my ($mail_quota_sum, $ftp_quota, $vhostquota);
	
	if($session->param('user') ne 'admin'){
		$vhostquota = $session->param('vhost_quota');
		($mail_quota_sum, $ftpquota) =  easytecc3::get_mail_ftp_quota_vhost($session);
		$mail_quota_sum = $mail_quota_sum / 1024;
		logline("debug","domainadmin user=".$session->param('user') . "vhostquota=$vhostquota mail_quota_sum=$mail_quota_sum ftpquota=$ftpquota") if $debug;
	}

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_ftpquota');
		my $ftpquota = $dfv->get_current_constraint_value();

		if($ftpquota =~ /\D/) {
			$dfv->set_current_constraint_name('L__Die Mengenangabe für die Speicherbegrenzung darf nur aus Zahlen bestehen__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
		elsif( ! $ftpquota){
			$dfv->set_current_constraint_name('L__Sie haben für den FTP-Benutzer keine Speicherbegrenzung ausgewählt__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
		elsif($vhostquota && ($mail_quota_sum + $ftpquota > $vhostquota)){
			my $max_ftpquota = $vhostquota - $mail_quota_sum;
			$dfv->set_current_constraint_name("L__Die Quota des FTP-Benutzers darf nicht höher als die Gesamtquota des vhosts und der Emailbenutzer sein.__L L__Maximal verfügbare Quota für FTP-Benutzer:__L $max_ftpquota MB");
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_popquota{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_popquota');
		my $popquota = $dfv->get_current_constraint_value();

		if($popquota =~ /\D/) {
			$dfv->set_current_constraint_name('L__Die Mengenangabe für die Speicherbegrenzung darf nur aus Zahlen bestehen__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
		elsif( ! $popquota){
			$dfv->set_current_constraint_name('L__Sie haben für den Benutzer keine Speicherbegrenzung ausgewählt__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_pop3{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_pop3');
		my $pop3 = $dfv->get_current_constraint_value();

		if($pop3 && $pop3 =~ /\D/){
			$dfv->set_current_constraint_name('L__Die Anzahl der POP3-User ist ungültig__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		logline("debug","val=$val type=$type") if $debug;

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_ip{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_ip');
		my ($ip,$cidrprefix) = $dfv->get_current_constraint_value() =~ m/^([^\/]+)\/?(.*)$/;
		
		logline("debug","validate_ip val=$val type=$type") if $debug;
		
		if(!is_ipv4($ip)){
			$dfv->set_current_constraint_name("$ip: L__Keine gültige IP-Adresse__L");
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
		elsif(length($cidrprefix) && ($cidrprefix !~ m/[0-9]+/ || $cidrprefix > 32)){
			$dfv->set_current_constraint_name("/$cidrprefix: L__Keine gültiges Netzwerk__L");
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');	
		}
		else{
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}
		
	}
}

sub validate_firewall_ttl{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_firewall_ttl');
		my $ttl = $dfv->get_current_constraint_value();
		
		logline("debug","validate_firewall_ttl val=$ttl") if $debug;
		
		if(defined($ttl) && ($ttl !~ m/[0-9]+/ || $ttl > 48)){
			$dfv->set_current_constraint_name("$ttl: L__Keine gültige Dauer: Maximal 48 Stunden, 0 für permanent.__L");
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');	
		}
		else{
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}
		
	}
}

sub validate_firewall_name{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_firewall_name');
		my $user = $dfv->get_current_constraint_value();

		if($user =~ /[^a-zA-Z0-9\-\_\s]/){
			$dfv->set_current_constraint_name("$user: L__Der Name enthält ungültige Zeichen__L");
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		# get other data to refer to
		logline("debug","val=$val type=$type") if $debug;

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_firewall_key{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_firewall_key');
		my $user = $dfv->get_current_constraint_value();

		if($user =~ /[^a-zA-Z0-9\-]/){
			$dfv->set_current_constraint_name("$user: L__Der Schlüssel enthält ungültige Zeichen__L");
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		# get other data to refer to
		logline("debug","val=$val type=$type") if $debug;

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_firewall_rule{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_firewall_rule');
		my $rule = $dfv->get_current_constraint_value();
		$rule =~ s/[\\\s]+$//mg;
		$rule =~ s/$/ \\/mg;
		
		logline("debug","validate_firewall_rule val=$rule") if $debug;
		
		my $listfile_new = '/tmp/WEB2BAN_firewall_rule' . '.' . $$;
		open WEB2BAN_LIST_NEW, ">$listfile_new";
		print WEB2BAN_LIST_NEW "LogMessage \"#shell2ban\.web2ban#\" \"expr= \\\n";
		print WEB2BAN_LIST_NEW "$rule\n\"\n";
		close WEB2BAN_LIST_NEW;
		
		my $got = `/usr/iports/bin/sudo /usr/iports/sbin/httpd -C "LoadModule mpm_prefork_module libexec/apache24/mod_mpm_prefork.so" -C "LoadModule log_debug_module libexec/apache24/mod_log_debug.so" -t -f $listfile_new 2>&1`;
		chomp $got;
		`rm -f $listfile_new`;
		
		if($got !~ m/^Syntax OK$/s){
		
			my $error = $got;
			$error =~ s/^AH[0-9]+:[^:]+:/L__Die Regel enthält ungültige Apache-Direktiven.__L\n /;
			$dfv->set_current_constraint_name("$rule: $error");
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');	
		}
		else{
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}
		
	}
}

sub validate_portlist{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;
		logline("debug","validate_portlist val=$val type=$type") if $debug;
		
		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_portlist');
		my $port = $dfv->get_current_constraint_value();
		$port =~ s/\s//g;
		
		my @ports = split(/,\s*/,$port);
		foreach $port (@ports){
			
			if($port !~ /^[0-9]+$/ && $port !~ /^[0-9]+\-[0-9]+$/){
				
				$dfv->set_current_constraint_name("$ip: L__Keine gültigen Ports__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
		
			}
		
		}
		
		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
				
	}
}

sub validate_logrotate_when{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_logrotate_when');
		my $when = $dfv->get_current_constraint_value();
		
		logline("debug","validate_logrotate_when val=$when") if $debug;
		
		if($when !~ m/(never|daily|weekly|monthly)/){
			$dfv->set_current_constraint_name("$when: L__Keine gültiges Interval__L");
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');	
		}
		else{
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}
		
	}
}

sub validate_logrotate_count{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_logrotate_count');
		my $count = $dfv->get_current_constraint_value();
		
		logline("debug","validate_logrotate_count val=$count") if $debug;
		
		if($count !~ m/[0-9]+/ || $ttl > 100){
			$dfv->set_current_constraint_name("$when: L__Keine gültige Anzahl, es sind maximal 100 Sicherungen möglich__L");
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');	
		}
		else{
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}

		
	}
}

sub validate_alias{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my $type = shift;
	my $domainpart = shift;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_alias');
		my $email = $dfv->get_current_constraint_value();

		logline("debug","validate_alias email=$email type=$type domainpart=$domainpart") if $debug;

		#bei Formularen kann domainpart aus select_feld kommen oder ganze Emailadresse wird übermittelt
		#wenn $domainpart gesetzt, dann emailadresse zusammenfügen.
		$email = $email . $domainpart if $domainpart;

		if($email =~ /@/  && $email =~ /^.*[^a-zA-Z0-9_\-\.]{1,100}.*\@.*/ ){
			$dfv->set_current_constraint_name("$email: L__Die E-Mail-Adresse enthält ungültige Zeichen__L");
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		#wenn vor dem @ keine Sonderzeichen sind klappt auch email_to_ascii
		$email = email_to_ascii( $email );

		unless(is_email($email)){
			$dfv->set_current_constraint_name("$email: L__Keine gültige E-Mail-Adresse__L");
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		#ein alias ist kein User in /etc/mail/mailuser, sondern nur eine Weiterleitung auf Emailuser
		#damit dieser verschiedene Emailadressen empfangen kann

		if($type eq 'valid'){
			#wenn bis hierhin gekommen ist email ok, nur der Ordnung halber für jeden type ein if
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}
		elsif($type eq 'exists'){
			my $exists = `egrep "^$email\[\[:space:\]\]\{1,\}" /etc/mail/virtmaps`;
			if($exists){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			else{
				$dfv->set_current_constraint_name("$email: L__Die E-Mail-Adresse existiert nicht__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		elsif($type eq 'not_exists'){
			my $exists = `egrep "^$email\[\[:space:\]\]\{1,\}" /etc/mail/virtmaps`;
			chomp $exists;
			if($exists){
				$dfv->set_current_constraint_name("$email: L__Die E-Mail-Adresse existiert bereits__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			else{
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}		
		}
		elsif($type eq 'edit_not_exists'){
			#wenn Emailadresse editiert wird, kann es Verweis auf eigenen alias geben, hier wird abgefangen, ob es den Alias für eine andere Emailadresse gibt
			my $old_emailaddress = $input{'old_emailaddress'};
			my $exists = `egrep "^$email\[\[:space:\]\]\{1,\}" /etc/mail/virtmaps`;
			chomp $exists;
			if($exists && $exists !~ /\s+$old_emailaddress$/){
				$dfv->set_current_constraint_name("$email: L__Die E-Mail-Adresse existiert bereits__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			else{
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}		
		}
		else{
			return('');
		}
	}
}

sub validate_email_fb{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my $type = shift;
	my $domainpart = shift;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_email');
		my $email = $dfv->get_current_constraint_value();

		logline("debug","validate_email email=$email type=$type domainpart=$domainpart") if $debug;

		#bei Formularen kann domainpart aus select_feld kommen oder ganze Emailadresse wird übermittelt
		#wenn $domainpart gesetzt, dann emailadresse zusammenfügen.
		$email = $email . $domainpart if $domainpart;

		if($email =~ /@/  && $email =~ /^.*[^a-zA-Z0-9_\-\.]{1,100}.*\@.*/ ){
			$dfv->set_current_constraint_name("$email: L__Die E-Mail-Adresse enthält ungültige Zeichen__L");
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		#wenn vor dem @ keine Sonderzeichen sind klappt auch email_to_ascii
		$email = email_to_ascii( $email );

		unless(is_email($email)){
			$dfv->set_current_constraint_name("$email: L__Keine gültige E-Mail-Adresse__L");
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');	
		}

		if($type eq 'valid'){
			#wenn bis hierhin gekommen ist email ok, nur der Ordnung halber für jeden type ein if
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}
		elsif($type eq 'exists'){
			my $exists = `egrep "^$email:" /etc/mail/mailuser`;
			if($exists){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			else{
				$dfv->set_current_constraint_name("$email: L__Die E-Mail-Adresse existiert nicht__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		elsif($type eq 'not_exists'){
			my $exists = `egrep "^$email:" /etc/mail/mailuser`;
			if($exists){
				$dfv->set_current_constraint_name("$email: L__Die E-Mail-Adresse existiert bereits__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			else{
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}		
		}
		elsif($type eq 'edit_not_exists'){
			#edit_not_exists ist für Editieren der Adresse, die ja zwangsläufig vorhanden ist
			#wenn die alte emailadresse != neue emailadresse, dann darf neue Adresse noch nicht vorhanden sein
			#wenn alte emailadresse = neue emailadresse, dann muss adresse vorhanden sein.
			#die editierte emailadresse wird mit old_emailaddress übermittelt, die neue ist edit_email @ domain_select
			my $old_emailadress = $input{'old_emailaddress'};
			my $exists = `egrep "^$email:" /etc/mail/mailuser`;

			if($old_emailadress ne $email){
				if($exists){
					$dfv->set_current_constraint_name("$email: L__Die E-Mail-Adresse existiert bereits__L");
					logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
					return('');
				}
				else{
					logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
					return('1');
				}		
			}
			else{
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}						
		}
		else{
			return('');
		}
	}
}

sub validate_email{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my @args = @_;
	my $type = shift;

	my $ref_fb = (caller(0))[3] . '_fb';
	if(defined *$ref_fb{CODE} && $fb){return($ref_fb->(@args));}

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_email');
		my $email = $dfv->get_current_constraint_value();

		logline("debug","validate_email val=$val type=$type") if $debug;

		if($email =~ /@/  && $email =~ /^.*[^a-zA-Z0-9_\-\.]{1,100}.*\@.*/ ){
			$dfv->set_current_constraint_name("$email: L__Die E-Mail-Adresse enthält ungültige Zeichen__L");
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		#wenn vor dem @ keine Sonderzeichen sind klappt auch email_to_ascii
		$email = email_to_ascii( $email );

		if($type eq 'valid'){
			if(is_email($email)){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			else{
				$dfv->set_current_constraint_name("$email: L__Keine gültige E-Mail-Adresse__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		elsif($type eq 'exists'){
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}
		else{
			logline("debug","<<< Leaving ".(caller(0))[3]."() by ?.") if $debug;
			return('');
		}
	}
}

sub validate_forward{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my ($forward, $type) = shift;
	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_forward');
		my $for = $dfv->get_current_constraint_value();

		if($for && $for =~ /\D/){
			$dfv->set_current_constraint_name('L__Die Anzahl der Weiterleitungen ist ungültig__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		logline("debug","val=$val type=$type") if $debug;

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_autoresponder{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my ($autoresponder, $type) = shift;
	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_autoresponder');
		my $aut = $dfv->get_current_constraint_value();

		if($aut && $aut =~ /\D/){
			$dfv->set_current_constraint_name('L__Die Anzahl der Autoresponder ist ungültig__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		logline("debug","field=$field val=$val type=$type") if $debug;

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_custom_tag{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_custom_tag');
		my $custom_tag = $dfv->get_current_constraint_value();

		if(length($custom_tag) > 20){
			$dfv->set_current_constraint_name('L__Die Notiz ist zu lang (max. 20 Zeichen)__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_documentroot_fb{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my ($documentroot, $type) = shift;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_documentroot');
		my $droot = $dfv->get_current_constraint_value();

		if($droot !~ /\/usr\/local\/www\/apache24\//){
			$dfv->set_current_constraint_name('L__Das Documentroot muss unterhalb von /home liegen__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
		
		my $parent_dir = dirname($droot);
		if (! -d "$parent_dir") {
			$dfv->set_current_constraint_name("L__Das übergeordnete Verzeichnis $parent_dir existiert nicht. Sofern kein Tipfehler vorliegt das Verzeichnis bitte manuell anlegen und die Aktion erneut ausführen.__L");
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
		

		logline("debug","val=$val type=$type") if $debug;

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_documentroot{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my @args = @_;
	my ($documentroot, $type) = shift;

	my $ref_fb = (caller(0))[3] . '_fb';
	if(defined *$ref_fb{CODE} && $fb){return($ref_fb->(@args));}

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_documentroot');
		my $droot = $dfv->get_current_constraint_value();

		if($droot !~ /\/home\//){
			$dfv->set_current_constraint_name('L__Das Documentroot muss unterhalb von /home liegen__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		logline("debug","val=$val type=$type") if $debug;

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_openbasedir{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my @args = @_;
	my ($openbasedir, $type) = shift;

	my $ref_fb = (caller(0))[3] . '_fb';
	if(defined *$ref_fb{CODE} && $fb){return($ref_fb->(@args));}

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_openbasedir');
		my $openbasedir = $dfv->get_current_constraint_value();
		my @dirs = split(/:/,$openbasedir);
		my $dir = '';
		
		foreach $dir (@dirs){
			
			if(!-d $dir){
				
				if($input{'action'} eq 'exec_new_vhost' && $dir eq $input{'droot'}){
					next;
				}
				
				$dfv->set_current_constraint_name("$dir: L__Das Verzeichnis existiert nicht__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
				
			}
			
		}
	
		logline("debug","val=$val type=$type") if $debug;

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_user{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_user');
		my $user = $dfv->get_current_constraint_value();

		if($user =~ /[^a-zA-Z0-9\-\_]/){
			$dfv->set_current_constraint_name("$user: L__Der Benutzername enthält ungültige Zeichen__L");
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		# get other data to refer to
		logline("debug","val=$val type=$type") if $debug;

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_ftpuser{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my $type = shift;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_ftpuser');
		my $ftpuser = $dfv->get_current_constraint_value();

		if($input{'action'} eq 'exec_delete_ftpuser' && $ftpuser =~ /^(admin|web|ftp)$/){
			$dfv->set_current_constraint_name('L__Systemuser können nicht gelöscht werden__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		if($type eq 'valid'){
			$ftpuser = lc($ftpuser);
			my $first = substr($ftpuser,0,1);

			if($ftpuser =~ /[^a-z0-9\-\_]/ || $first =~ /[^a-z]/){
				$dfv->set_current_constraint_name("$ftpuser: L__Der Benutzername enthält ungültige Zeichen__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif(length($ftpuser) < 4){
				$dfv->set_current_constraint_name("$ftpuser: L__Der Benutzername ist zu kurz. Bitte geben Sie mindestens 4 Zeichen an.__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif(length($ftpuser) > 16){
				$dfv->set_current_constraint_name("$ftpuser: L__Der Benutzername ist zu lang. Bitte geben Sie höchstens 16 Zeichen an.__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}

			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}
		elsif($type eq 'exists'){
			my $passwd = file->new({file_name => '/etc/passwd'});
			$passwd->read_file;
			my %passwd = %{$passwd->file_parsed_hash()};

			if(exists $passwd{$ftpuser}){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			else{
				$dfv->set_current_constraint_name("$ftpuser: L__Der Benutzer existiert nicht__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		elsif($type eq 'not_exists'){
			my $passwd = file->new({file_name => '/etc/passwd'});
			$passwd->read_file;
			my %passwd = %{$passwd->file_parsed_hash()};

			if(not exists $passwd{$ftpuser}){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			else{
				$dfv->set_current_constraint_name("$ftpuser: L__Der Benutzer existiert bereits__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
	}
}

sub validate_adminusers{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_adminusers');
		
		my $adminusers = $dfv->get_current_constraint_value();
		
		if($session->param('user') ne 'admin' || !length($adminusers)){
		
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		
		}
		
		my @user = split(/[\s,]+/,lc($adminusers));
		
		my $passwd = file->new({file_name => '/etc/passwd'});
		$passwd->read_file;
		my %passwd = %{$passwd->file_parsed_hash()};

		foreach $ftpuser (@user){
		
			if($ftpuser =~ /^(admin|web|ftp|root)$/){
				$dfv->set_current_constraint_name('L__Systemuser können nicht als Administratoren verwendet werden.__L');
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			
			if(!exists $passwd{$ftpuser}){
			
				if($input{'action'} ne 'exec_new_vhost' || $ftpuser ne $input{'ftpuser'}){
				
					$dfv->set_current_constraint_name("$ftpuser: L__Der Benutzer existiert nicht__L");
					logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
					return('');
					
				}
			}	
			
		}
		
		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
		
	}
}

sub validate_frontpageuser{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_user');
		my $frontpageuser = $dfv->get_current_constraint_value();

		if($frontpageuser =~ /[^a-zA-Z0-9\-\_]/){
			$dfv->set_current_constraint_name("$frontpageuser: L__Der Benutzername enthält ungültige Zeichen__L");
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		logline("debug","val=$val type=$type") if $debug;

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_pass{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my $user = shift;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_pass');
		my $pass = $dfv->get_current_constraint_value();
		my %password_chars;
		my @password_chars = split //, $pass;
		foreach(@password_chars){
			$password_chars{$_} = '1';
		}

		logline("debug","passsword=" . ord($pass) . "") if $debug;

		if(!$pass) {
			$dfv->set_current_constraint_name('L__Bitte geben Sie ein Passwort an__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
		elsif($user eq $pass) {
			$dfv->set_current_constraint_name('L__Das Passwort darf nicht gleich dem Benutzernamen sein__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		if($pass =~ /^[0-9]{1,}$/){
			$dfv->set_current_constraint_name('L__Das Passwort darf nicht ausschliesslich aus Zahlen bestehen__L');
		}
		elsif($pass =~ /[äöüÄÖÜß]/){
			$dfv->set_current_constraint_name('L__Das Passwort enthält ungültige Zeichen__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
		elsif($pass !~ /[A-Za-z0-9\%\+\*\~\-\_\@\#\$\&\=\?\!]/) {
			$dfv->set_current_constraint_name('L__Das Passwort enthält ungültige Zeichen__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
		elsif($user ne 'admin' && length($pass) < 10) {
			$dfv->set_current_constraint_name('L__Das Passwort ist zu kurz__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
		elsif(keys(%password_chars) < 2){
			$dfv->set_current_constraint_name('L__Das Passwort muss mindestens zwei verschiedene Zeichen enthalten__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
				
		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_description{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_description');
		my $gecos = $dfv->get_current_constraint_value();

		if($gecos =~ /- POP/){
			$dfv->set_current_constraint_name('L__"- POP" ist in der Userbeschreibung nicht erlaubt__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
		elsif($gecos =~ /[^a-zA-Z0-9\-\_\+\s\.]/){
		
			$dfv->set_current_constraint_name('L__Die Userbeschreibung enthält ungültige Zeichen__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_subjectprefix{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my ($subjectprefix, $type) = shift;
	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_subjectprefix');
		my $val = $dfv->get_current_constraint_value();
		if($val =~ /[\|\$\;]/){
			$dfv->set_current_constraint_name('L__Das Subjektpräfix enthält ungültige Zeichen__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_imap_folder{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my ($subjectprefix, $type) = shift;
	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_imap_folder');
		my $val = $dfv->get_current_constraint_value();
		if($val !~ /^[A-Za-z0-9]+$/){
			$dfv->set_current_constraint_name('L__Der Imap-Ordner enthält ungültige Zeichen__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}



sub validate_spam_user_domain{

	my $type = shift;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_spam_user_domain');
		my $spam_user_domain = $dfv->get_current_constraint_value();
		$spam_user_domain =~ s/^www\.//;
		logline("debug","spam_user_domain=$spam_user_domain") if $debug;

		#erstmal gucken, ob unerlaubte Zeichen
		if($spam_user_domain =~ /[^a-zA-Z0-9\-\@\_\.]/){
			$dfv->set_current_constraint_name("$spam_user_domain: L__User/Domain enthält ungültige Zeichen__L");
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		$spam_user_domain = ascii_domain($spam_user_domain);
		my $spam_user_domain_mit_www = $spam_user_domain;
		$spam_user_domain_mit_www = 'www.' . $spam_user_domain_mit_www unless $spam_user_domain_mit_www =~ /^www\./;

		$mailpasswd = easytecc3::get_mailpasswd();
		my %mailpasswd = %{$mailpasswd->file_parsed_hash()};
		
		#my %mailpasswd = %{easytecc3::get_mailpasswd()};
		my $httpd_conf = file->new({file_name => '/etc/httpd/conf/httpd.conf'});
		$httpd_conf->read_file;
		my %domains = %{$httpd_conf->file_parsed_hash()};

		if(defined $session && $session->param('user') ne 'admin' && $session->param('user') ne '' && $ENV{'REQUEST_URI'} =~ m/\/domainadmin/){
			logline("debug","domainadmin x spam_user_domain user=" . $session->param('user') . "") if $debug;
			my $vhost = $session->param('vhost_no_www');

			#ok wenn session mit korrektem vhost, vhost ist immer mit www
			#return('1') if $spam_user_domain_mit_www eq $session->param('vhost');

			#my $passwd = file->new({file_name => '/etc/passwd'});
			#$passwd->read_file;
			#my %passwd = %{$passwd->file_parsed_hash()};
			
			#my $passwd = easytecc3::get_mailpasswd();
			#my %passwd = %{$passwd->file_parsed_hash()};

			my %passwd = %mailpasswd;
			
			foreach(@{$domains{$session->param('vhost')}{'domains'}}){
				if($spam_user_domain eq $_){
					if($type eq 'not_exists'){
						if(-e "/home/$spam_user_domain/.spamd/user_prefs"){
							$dfv->set_current_constraint_name("$spam_user_domain: L__Es existieren bereits spezielle Spameinstellungen.__L");
							logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
							return('');
						}
						else{
							logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
							return('1');
						}
					}
					else{
						logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
						return('1');
					}
				}
			}

			foreach(keys %passwd){
				logline("debug","validate_spam_user_domain passwd_user=$_") if $debug;
				next if($spam_user_domain ne $_);
				if($passwd{$spam_user_domain}{'gecos'} =~ /$vhost - POP/){
					if($type eq 'not_exists'){
						if(-e "/home/$spam_user_domain/.spamd/user_prefs"){
							$dfv->set_current_constraint_name("$spam_user_domain: L__Es existieren bereits spezielle Spameinstellungen.__L");
							logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
							return('');
						}
						else{
							logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
							return('1');
						}
					}
					else{
						logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
						return('1');
					}
				}
			}

			#nix gefunden
			$dfv->set_current_constraint_name('L__Der Benutzer oder die Domain existiert nicht__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
		
		elsif($session->param('user') ne 'admin' && !$session->param('is_mailuser')){
		
			# check user
			my $domain =  $mailpasswd{$spam_user_domain}{'gecos'};
			if(defined($domain)){
		
				$domain =~ s/ - POP$//;
	
				my $admins = $domains{'www.' . $domain}{'admin_users'};
				$admins =~ s/[\s,]+/#/g;
				$admins = '#' . $admins . '#';
				$userregex = '#' . $session->param('user') . '#';
			
				logline("debug","admins:$admins\nuserregex:$userregex");
							
				if($admins !~ m/$userregex/i){
									
					$dfv->set_current_constraint_name('L__Sie dürfen diesen Benutzer nicht administrieren.__L');
					return('');
					
				} else {
				
					return('1');
					
				}
			}
			
			my %allowed_domains;
				
			foreach $domain (sort keys %domains){

				my $admins = $domains{$domain}{'admin_users'};
				$admins =~ s/[\s,]+/#/g;
				$admins = '#' . $admins . '#';
				$userregex = '#' . $session->param('user') . '#';
			
				logline("debug","domain: $domain admins:$admins userregex:$userregex");
				
				if($admins =~ m/$userregex/i){

					foreach my $alias_domain (@{$domains{$domain}{'domains'}}){
					
						$alias_domain =~ s/^www\.//;
						$alias_domain =~ s/^\*\.//;
						
						$allowed_domains{$alias_domain} = 1;
						
						logline("debug","allowed_domain:$alias_domain");
						
					}
					
					$domain =~ s/^www\.//;
					$domain =~ s/^\*\.//;
						
					$allowed_domains{$domain} = 1;
					
					logline("debug","allowed_domain:$domain");
				
				}
			}
						
			$domain = ascii_domain($spam_user_domain);
			$domain =~ s/^www\.//;
			$domain =~ s/^\*\.//;
			# verhindert domains zu administrieren wie lars.hostnettest.de ...
			#$domain =~ s/^.*\.(?=.*\..*)//;

			if(!exists $allowed_domains{$domain}){
			
				$dfv->set_current_constraint_name('L__Sie dürfen diese Domain nicht administrieren.__L');
				return('');
			
			} else {
			
				return('1');
			
			}

		}
		
		else{
			#wenn Domain in vhost, dann ok
			foreach(keys %domains){
				foreach(@{$domains{$_}{'domains'}}){
					if($spam_user_domain eq $_){
						if($type eq 'not_exists'){
							if(-e "/home/$spam_user_domain/.spamd/user_prefs"){
								$dfv->set_current_constraint_name("$spam_user_domain: L__Es existieren bereits spezielle Spameinstellungen.__L");
								logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
								return('');
							}
							else{
								logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
								return('1');
							}
						}
						else{
							logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
							return('1');
						}
					}
				}
			}

			# ansonsten muss entweder Emailuser aus passwd vom Webserver oder aus passwd vom Mailserver sein, easytecc3::get_mailpasswd sucht sich
			# die richtige heraus.
			if(exists $mailpasswd{$spam_user_domain}){
				if($type eq 'not_exists'){
					if(-e "/home/$spam_user_domain/.spamd/user_prefs"){
						$dfv->set_current_constraint_name("$spam_user_domain: L__Es existieren bereits spezielle Spameinstellungen.__L");
						logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
						return('');
					}
					else{
						logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
						return('1');
					}
				}
				else{
					logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
					return('1');
				}
			}
			elsif( -e "/home/$spam_user_domain/.spamproc" && $type ne 'not_exists'){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			else{
				$dfv->set_current_constraint_name('L__Der Benutzer oder die Domain existiert nicht__L');
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
	}
}

sub validate_pspam_level{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_pspam');
		my $pspam_level = $dfv->get_current_constraint_value();

		if($pspam_level >=2 && $pspam_level <=12){
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}
		else{
			$dfv->set_current_constraint_name('L__Der Wert für wahrscheinlichen Spam ist ungültig__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
	}
}

sub validate_cspam_level{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_cspam');
		my $cspam_level = $dfv->get_current_constraint_value();

		if($cspam_level >=3 && $cspam_level <=20){
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}
		else{
			$dfv->set_current_constraint_name('L__Der Wert für sicheren Spam ist ungültig__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
	}
}

sub validate_action_pspam{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_action_pspam');
		my $action_pspam = $dfv->get_current_constraint_value();

		if($action_pspam =~ /^(MARK|HEADER)$/){
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}
		else{
			$dfv->set_current_constraint_name('L__Die Aktion für wahrscheinlichen Spam ist ungültig__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
	}
}

sub validate_action_cspam{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_action_cspam');
		my $action_cspam = $dfv->get_current_constraint_value();

		if($action_cspam =~ /^(DEL|MARK|HEADER)$/){
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}
		else{
			$dfv->set_current_constraint_name('L__Die Aktion für sicheren Spam ist ungültig__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
	}
}

sub validate_action_virus{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_action_virus');
		my $action_virus = $dfv->get_current_constraint_value();

		if($action_virus =~ /^(OFF|DEL|MARK)$/){
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}
		else{
			$dfv->set_current_constraint_name('L__Die Aktion für erkannten Virus ist ungültig__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
	}
}

sub validate_email_white_blacklist{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_email_white_blacklist');
		my $list = $dfv->get_current_constraint_value();

		logline("debug",qq~list1:$list###\neachchar\n~) if $debug;
		my @allchars = split //, $list;
		foreach my $char (@allchars){
			logline("debug",ord($char) . "") if $debug;
		}

		my @newlist = split m(\r\n|;|:|,|\t+|\s+), $list;

		foreach(@newlist){
			logline("debug",qq~\n\nlist2:$_###\n~) if $debug;
			next if (/^$/ || /^\n$/);
			if(! is_tld($_) && ! is_email($_) && ! is_domain($_)){
				$dfv->set_current_constraint_name("$_: L__Keine Domain oder E-Mail-Adresse__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_virusfilter{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_virusfilter');
		my $virusfilter = $dfv->get_current_constraint_value();
		if('1'){
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}

		$dfv->set_current_constraint_name('L__Ungültiger Wert__L');
		logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
		return('');
	}
}

sub validate_report_safe{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_report_safe');
		my $report_safe = $dfv->get_current_constraint_value();
		if($report_safe == '1' || $report_safe == '0'){
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}
		else{
			$dfv->set_current_constraint_name('L__Spamreport: Ungültiger Wert__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
	}
}

sub validate_virus_subject{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_virus_subject');
		my $virus_found_subject = $dfv->get_current_constraint_value();
		if('1'){
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}

		$dfv->set_current_constraint_name('L__Subjekt für erkannten Virus: Ungültiger Wert__L');
		logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
		return('');
	}
}

sub validate_virus_text{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my $dfv = shift;

	# Name it to refer to in the 'msgs' system.
	$dfv->name_this('validate_virus_text');
	my $virus_found_text = $dfv->get_current_constraint_value();
	if('1'){
		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}

	$dfv->set_current_constraint_name('L__Text für erkannten Virus: Ungültiger Wert__L');
	logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
	return('');
	}
}

sub validate_virus_header{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_virus_header');
		my $virusheader = $dfv->get_current_constraint_value();
		if('1'){
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}

		$dfv->set_current_constraint_name('L__Header für erkannten Virus: Ungültiger Wert__L');
		logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
		return('');
	}
}

sub validate_postfix_virus{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_postfix_virus');
		my $postfix = $dfv->get_current_constraint_value();
		my @postfix = split(/\s+|\;|\,/,$postfix);
		foreach(@postfix){
			logline("debug","postfix:$_") if $debug;
			if(/[^a-zA-Z0-9\.]/){
				$dfv->set_current_constraint_name('L__Virus-Postfix: Ungültiger Wert__L');
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_modify_file_type{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my $file = shift;
	my $fullfile = shift;
	my $file_mv = shift;
	my $file_cp = shift;
	# $dir nur bei mv um eindeutig den richtigen Ordner zu haben
	my $dir = shift;
	my $file_chmod = shift;
	my $old_owner = shift;
	my $old_chmod = shift;
	my $user_select = shift;
	my $group_select = shift;
	# $dir wird relativ von /home/httpd/docs bergeben
	$dir = $droot_prefix . '/' . $dir;

	logline("debug","dir=$dir file=$file fullfile=$fullfile type=$type") if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_modify_file_type');
		my $type = $dfv->get_current_constraint_value();
		if( $type eq 'mv' ){
			# nur generischer Test, Kram wegen überschreiben falls vorhanden und so wird von exec_modify_file gemacht
			if( $file  eq $file_mv){
				$dfv->set_current_constraint_name("$file: L__Das Umbenennen einer Datei erfordert, dass sich der neue Name vom alten Namen unterscheidet, da sich beim Umbenennen sonst keine Änderung ergibt__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif($file_mv =~ /[^a-zA-Z0-9\-_+:\.]/ || $file_mv =~ /\.\./){
				$dfv->set_current_constraint_name("$file_mv: L__Der Dateiname enthält ungültige Zeichen__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif(-f "$dir/$file" && ! -d "$dir/$file_mv"){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			elsif(! -f "$dir/$file"){
				$dfv->set_current_constraint_name("L__Die Datei existiert nicht__L: $dir/$file");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif(-d "$dir/$file_mv"){
				$dfv->set_current_constraint_name("$dir/$file_mv: L__Es existiert bereits ein Verzeichnis mit dem Zielnamen. Bitte wählen Sie einen anderen Namen__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		if( $type eq 'cp' ){
			# nur generischer Test, Kram wegen überschreiben falls vorhanden und so wird von exec_modify_file gemacht
			if( $file  eq $file_cp){
				$dfv->set_current_constraint_name("$file: L__Eine Datei kann nicht auf sich selbst kopiert werden__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif($file_cp =~ /[^a-zA-Z0-9\-_+:\.]/ || $file_cp =~ /\.\./){
				$dfv->set_current_constraint_name("$file_cp: L__Der Dateiname enthält ungültige Zeichen__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif(-f "$dir/$file" && ! -d "$dir/$file_cp"){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			elsif(! -f "$dir/$file"){
				$dfv->set_current_constraint_name("$dir/$file: L__Die Datei existiert nicht__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif(-d "$dir/$file_cp"){
				$dfv->set_current_constraint_name("$dir/$file_cp: L__Es existiert bereits ein Verzeichnis mit dem Zielnamen. Bitte wählen Sie einen anderen Namen__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		elsif($type eq 'rm'){
			# Löschen nur unterhalb von /home/httpd/docs erlauben und keine ../../../-Spässchen
			if($fullfile !~ /^$droot_regex/ || $fullfile =~ /\.\./){
				$dfv->set_current_constraint_name("$fullfile: L__Ungültige Pfadangabe. Die Datei kann nicht gelöscht werden__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif($fullfile =~ /[^a-zA-Z0-9\-_+:\/\.]/){
				$dfv->set_current_constraint_name("$dir: L__Der Dateiname enthält ungültige Zeichen__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif(-f "$fullfile"){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			elsif(! -f "$fullfile"){
				$dfv->set_current_constraint_name("$fullfile: L__Die Datei existiert nicht__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		elsif($type eq 'edit'){
			if($fullfile !~ /^$droot_regex/ || $fullfile =~ /\.\./){
				$dfv->set_current_constraint_name("$fullfile: L__Ungültige Pfadangabe. Die Datei kann nicht editiert werden__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif(-f "$fullfile"){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			elsif(! -f "$fullfile"){
				$dfv->set_current_constraint_name("$fullfile: L__Die Datei existiert nicht__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		elsif($type eq 'chmod'){
			if($fullfile !~ /^$droot_regex/ || $fullfile =~ /\.\./){
				$dfv->set_current_constraint_name("$fullfile: L__Ungültige Pfadangabe.__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif($file_chmod !~ /^[0-9]{3,4}$/){
				$dfv->set_current_constraint_name("$file_chmod: L__Ungültiger Wert für CHMOD.__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			#elsif($user_select eq $old_owner && $file_chmod eq $old_chmod){
			#	$dfv->set_current_constraint_name('L__Es wurde keine Änderung durchgeführt__L');
			#	logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			#	return('');
			#}
			elsif(-f "$fullfile"){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			elsif(! -f "$fullfile"){
				$dfv->set_current_constraint_name("$fullfile: L__Die Datei existiert nicht__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}

		$dfv->set_current_constraint_name('L__Datei: ungültiger Bearbeitungstyp__L');

		logline("debug","val=$val type=$type") if $debug;
		return ('');
	}
}

sub validate_modify_dir_type{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my $dir = shift;
	my $dir_mv = shift;
	my $dir_cp = shift;
	my $dir_chmod = shift;
	my $old_owner = shift;
	my $old_chmod = shift;
	my $user_select = shift;
	my $group_select = shift;
	
	# $dir wird relativ von /home/httpd/docs bergeben
	#<input type="hidden" name="dir" value="dav223/index_dateien2" />
	$dir = $droot_prefix . '/' . $dir;
	my $parent_dir = $dir;
	$parent_dir =~ s/\/[^\/]{1,}$//;

	logline("debug","dir=$dir type=$type") if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_modify_dir_type');
		my $type = $dfv->get_current_constraint_value();
		if( $type eq 'mv' ){
			#$dir_mv wird als einzelner Name übergeben: <input type="text" name="dir_mv" value="index_dateien2"  />
			#wenn /home/httpd/docs/dav223/index_dateien2 zu /home/httpd/docs/dav223/index_dateien3 umbenannt werden sollen benötigen wir den
			#übergeordneten Ordner von /home/httpd/docs/dav223/index_dateien2, also letztes Verzeichnsi abschneiden=/home/httpd/docs/dav223
			
			if(! length($dir_mv)){
				$dfv->set_current_constraint_name("L__Bitte geben Sie einen Verzeichnisnamen an.__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			
			$dir_mv = "$parent_dir/" . $dir_mv;

			if( $dir eq $dir_mv){
				$dfv->set_current_constraint_name("L__Das Umbenennen eines Verzeichnisses erfordert, dass sich der neue Name vom alten Namen unterscheidet, da sich beim Umbenennen sonst keine Änderung ergibt__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif($dir_mv =~ /[^a-zA-Z0-9\-_+:\.\/]/ || $dir_mv =~ /\.\./ || $dir_mv =~ /[\/]{2,}/){
				$dfv->set_current_constraint_name("L__Der Verzeichnisname enthält ungültige Zeichen__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif(-d "$dir" && ! -d "$dir_mv"){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			elsif(! -d "$dir"){
				$dfv->set_current_constraint_name("$dir: L__Das Verzeichnis existiert nicht__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif(-d "$dir_mv"){
				$dfv->set_current_constraint_name("L__Es existiert bereits ein Verzeichnis mit dem Zielnamen. Bitte wählen Sie einen anderen Namen__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		if( $type eq 'cp' ){
			
			if(! length($dir_cp)){
				$dfv->set_current_constraint_name("L__Bitte geben Sie einen Verzeichnisnamen an.__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			
			$dir_cp = "$parent_dir/" . $dir_cp;
			
			if( $dir  eq $dir_cp){
				$dfv->set_current_constraint_name("L__Ein Verzeichnis kann nicht auf sich selbst kopiert werden__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif($dir_cp =~ /[^a-zA-Z0-9\-_+:\.\/]/ || $dir_cp =~ /\.\./){
				$dfv->set_current_constraint_name("L__Der Verzeichnisname enthält ungültige Zeichen__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif(-d "$dir" && ! -d "$dir_cp"){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			elsif(! -d "$dir"){
				$dfv->set_current_constraint_name("$dir: L__Das Verzeichnis existiert nicht__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif(-d "$dir_cp"){
				# den Inhalt vom Quellverzeichnsi in ein vorhandenes Verzeichnis kopieren erlauben. Nachfrager ob vorhandene Dateien im Zielverzeichnis
				# berschrieben werden sollen.
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
		}
		elsif($type eq 'rm'){
			# Löschen nur unterhalb von /home/httpd/docs erlauben und keine ../../../-Spässchen
			if($dir !~ /^$droot_regex/ || $dir =~ /\.\./){
				$dfv->set_current_constraint_name("L__Ungültige Pfadangabe. Das Verzeichnis kann nicht gelöscht werden__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif($dir =~ /[\*\;\~\`\'\"]/){
				$dfv->set_current_constraint_name("L__Der Verzeichnisname enthält ungültige Zeichen__L. L__Bitte löschen Sie das Verzeichnis über Ihr FTP-Programm__L.");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif(-d "$dir"){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			elsif(! -d "$dir"){
				$dfv->set_current_constraint_name("$dir: L__Das Verzeichnis existiert nicht__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		elsif($type eq 'chmod'){
			if($dir !~ /^$droot_regex/ || $dir =~ /\.\./){
				$dfv->set_current_constraint_name("$dir: L__Ungültige Pfadangabe. Das Verzeichnis kann nicht geändert werden__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif($dir_chmod !~ /^[0-9]{3,4}$/){
				$dfv->set_current_constraint_name("$dir_chmod: L__Ungültiger Wert für CHMOD. Das Verzeichnis kann nicht geändert werden__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
#			elsif($user_select eq $old_owner && $dir_chmod eq $old_chmod){
#				$dfv->set_current_constraint_name('L__Es wurde keine Änderung durchgeführt__L');
#				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
#				return('');
#			}
			elsif(-d "$dir"){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			elsif(! -d "$dir"){
				$dfv->set_current_constraint_name("$dir: L__Das Verzeichnis existiert nicht__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		elsif($type eq 'cms_fix'){
			if($dir !~ /^$droot_regex/ || $dir =~ /\.\./ || $dir eq $droot_prefix . '/'){
				$dfv->set_current_constraint_name("$dir: L__Ungültige Pfadangabe. Das Verzeichnis kann nicht geändert werden__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif(-d "$dir"){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			elsif(! -d "$dir"){
				$dfv->set_current_constraint_name("$dir: L__Das Verzeichnis existiert nicht__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}

		$dfv->set_current_constraint_name('L__Verzeichnis: ungültiger Bearbeitungstyp__L');

		logline("debug","val=$val type=$type") if $debug;
		return ('');
	}
}

sub validate_cron_minute{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_cron_minute');
		my $min = $dfv->get_current_constraint_value();
		if( $min =~ /^(all|all2|all5|all10|all15|all30)$/ || ($min >= 0 && $min <= 59) ){
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}

		$dfv->set_current_constraint_name("$min: L__Ungültiger Minutenwert__L");
		logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
		return('');
	}
}

sub validate_cron_hour{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_cron_hour');
		my $std = $dfv->get_current_constraint_value();
		if( $std =~ /^(all|all2|all4|all6|all8|all12)$/ || ($std >= 0 && $std <= 23) ){
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}

		$dfv->set_current_constraint_name("$std: L__Ungültiger Stundenwert__L");
		logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
		return('');
	}
}

sub validate_cron_day{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_cron_day');
		my $mday = $dfv->get_current_constraint_value();
		if( $mday =~ /^(all|all2|first_half)$/ || ($mday >= 0 && $mday <= 31) ){
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}

		$dfv->set_current_constraint_name("$mday: L__Ungültiger Tageswert__L");
		logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
		return('');
	}
}

sub validate_cron_month{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_cron_month');
		my $mon = $dfv->get_current_constraint_value();
		if( $mon =~ /^(all|even|quarter|6_12)$/ || ($mon >= 0 && $mon <= 12) ){
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}

		$dfv->set_current_constraint_name("$mon: L__Ungültiger Monat__L");
		logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
		return('');
	}
}

sub validate_cron_weekday{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_cron_weekday');
		my $wday = $dfv->get_current_constraint_value();
		if( $wday =~ /^(all)$/ || ($wday >= 0 && $wday <= 6) ){
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}

		$dfv->set_current_constraint_name("$wday: L__Ungültiger Wochentag__L");
		logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
		return('');
	}
}

sub validate_cron_command{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_cron_command');
		my $command = $dfv->get_current_constraint_value();
		
		if($fb){
				
			$command =~ s#/apache24/noexec/#/apache24/data/#;
					
		}		
		
		# Zeilenumbrüche verbieten
		if( $command =~ /[\n\r]/){
			$dfv->set_current_constraint_name('L__Der auszuführende Befehl enthält ungültige Zeilenumbrüche__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		if($session->param('user') ne 'admin'){
	
			my $httpd_conf = file->new({file_name => '/etc/httpd/conf/httpd.conf'});
			$httpd_conf->read_file;
			my %domains = %{$httpd_conf->file_parsed_hash()};
			
			my $passwd = file->new({file_name => '/etc/passwd'});
			$passwd->read_file;
			my %passwd = %{$passwd->file_parsed_hash()};
			
			my %allowed_dirs;
			
			foreach my $domain (keys %domains){

				my $admins = $domains{$domain}{'admin_users'};
				$admins =~ s/[\s,]+/#/g;
				$admins = '#' . $admins . '#';
				$userregex = '#' . $session->param('user') . '#';
				
				logline("debug","admins:$admins\nuserregex:$userregex");
				
				if($admins !~ m/$userregex/i){
					next;
				}
			
				foreach my $alias_domain (@{$domains{$domain}{'domains'}}){
						
					$alias_domain =~ s/^www\.//;
					$alias_domain =~ s/^\*\.//;
					
					$allowed_domains{$alias_domain} = 1;
				
				}
						
				if($fb){
				
					$domains{$domain}{'droot'} =~ s#/apache24/noexec/#/apache24/data/#;
					
				}		
				$allowed_dirs{$domains{$domain}{'droot'}} = '1';
				
				$domain =~ s/^www\.//;
				$domain =~ s/^\*\.//;
					
				$allowed_domains{$domain} = 1;
				
			}
			
			$allowed_dirs{$passwd{$session->param('user')}{'home'}} = '1';
			
			my $allowed = 0;
			
			# check dirs
			foreach my $dir (keys %allowed_dirs){
		
				if($command =~ m#$dir/#){
		
					# check if other dirs are affected
					my $job = $command;
					$job =~ s#$dir/##;
					
					if($job !~ m#/home/# && $job !~ m#/usr/local/www/#){
					
						$allowed = 1;
						last;
					
					}

				}
				
			}
			
			# check domains
			if($allowed == 0){
			
				foreach my $domain (keys %allowed_domains){
				
					if($command =~ m#(ftp|http)s?://(www\.)?$domain/#){
					
						$allowed = 1;
						last;
					
					}
				
				}
			
			}
			
			if($allowed != 1){
			
				$dfv->set_current_constraint_name('L__Der auszuführende Befehl passt zu keinem Verzeichnis / keiner Domain, die Sie administrieren dürfen.__L');
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			
			}

		} 
		
	
		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
		
	}
}

sub validate_auto_cronjob{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_auto_cronjob');
		my $type = $dfv->get_current_constraint_value();
		# alles auer Zeilenumbrche erlauben
		if( $type eq 'delete_all_logs'){
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}

		if( $type eq 'delete_admin_email'){
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}

		$dfv->set_current_constraint_name('L__cronjob: unbekannter Typ__L');
		logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
		return('');
	}
}

sub validate_cronjob_line{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my $type = shift;
	my $cronjobs_ref = shift;
	my %cronjobs = %$cronjobs_ref;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;
		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_cronjob_line');
		my $cronjob_line = $dfv->get_current_constraint_value();

		# nix=fail
		# rückgabewert=success

		# Positivüberprüfung: wenn existiert, dann kein Fehler
		if($type eq 'exists'){
			# $cronjobs{$reverseline}{'count'} = $cronjob_line muss existieren
			foreach(keys %cronjobs){
				if($cronjobs{$_}{'count'} eq $cronjob_line) {
					logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
					return('1');
				}
			}

			$dfv->set_current_constraint_name('L__Der Cronjob existiert nicht__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
	}
}

sub validate_directory{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my $type = shift;
	
	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_directory');
		
		my $directory = $dfv->get_current_constraint_value();
		
		logline("debug","directory=" . $directory . "") if $debug;

		#Verzeichnis kann relativ oder absolut übergeben werden
		# ja, auch in fbsd...
		if($fb){
			$directory = $droot_prefix . '/' . $directory if $directory !~ $droot_regex;
		} else {
			$directory = $droot_prefix . '/' . $directory if $directory !~ $droot_regex;
		}

		if($type eq 'exists'){
			if ( ! -e $directory){
				$dfv->set_current_constraint_name("$directory: L__Das Verzeichnis existiert nicht__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name. x") if $debug;
				return('');
			}
		}
		elsif($type eq 'writeable'){
			my $got = `touch $directory/thisfileexists.txt`;
			`rm -f $directory/thisfileexists.txt` unless $got;

			if($got){
				$dfv->set_current_constraint_name("$directory: L__Das Verzeichnis ist für den Webserver nicht beschreibbar__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name. -> $got y") if $debug;
				return('');
			}
		}
		elsif($type eq 'valid'){
			if($directory =~ /[^äöüßÄÖÜa-zA-z0-9\.\-\_\+\#\s\/]/ || $directory =~ /\.\./){
				$dfv->set_current_constraint_name("$directory: L__Der Verzeichnisname enthält ungültige Zeichen__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name. z") if $debug;
				return('');
			}
		}
		elsif($type eq 'notexists'){
			if (-e $directory){
				$dfv->set_current_constraint_name("$directory: L__Das Verzeichnis existiert bereits__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name. x") if $debug;
				return('');
			}
		}

		logline("debug","xx val=$directory type=$type") if $debug;

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_new_directory{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my $type = shift;
	my $directory = $input{'dir'} . '/' . $input{'newdir'};
		
	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_new_directory');
		
		logline("debug","directory=" . $directory . "") if $debug;

		#Verzeichnis kann relativ oder absolut übergeben werden
		# ja, auch in fbsd...
		if($fb){
			$directory = $droot_prefix . '/' . $directory if $directory !~ $droot_regex;
		} else {
			$directory = $droot_prefix . '/' . $directory if $directory !~ $droot_regex;
		}

		if($type eq 'valid'){
			if($directory =~ /[^a-zA-z0-9\.\-\_\+\#\s\/]/ || $directory =~ /\.\./){
				$dfv->set_current_constraint_name("$directory: L__Der Verzeichnisname enthält ungültige Zeichen__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name. z") if $debug;
				return('');
			}
		}
		elsif($type eq 'notexists'){
			if (-e $directory){
				$dfv->set_current_constraint_name("$directory: L__Das Verzeichnis existiert bereits__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name. x") if $debug;
				return('');
			}
		}

		logline("debug","xx val=$directory type=$type") if $debug;

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_frontpage_domain{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my $type = shift;
	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_frontpage_domain');
		my $domain = $dfv->get_current_constraint_value();

		if($type eq 'exists'){
			my $frontpage_conf = qq~/usr/local/frontpage/$domain:80.cnf~;
			if(-e "$frontpage_conf"){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			else{
				$dfv->set_current_constraint_name("$domain: L__Kein Frontpageweb gefunden__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
	}
}

sub validate_db{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my $type = shift;
	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_db');
		my $database = $dfv->get_current_constraint_value();
		my $datadir = '';

		my $mysql4 = `grep mysql4_enable /etc/rc.conf`;
		if($mysql4 =~ /YES/){
			$datadir = '/var/lib/mysql/data';
		}
		else{
			$datadir = '/var/lib/mysql';
		}

		if($type eq 'exists'){
			if(-e "$datadir/$database"){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			else{
				$dfv->set_current_constraint_name("$database: L__Die Datenbank existiert nicht__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		elsif($type eq 'not_exists'){
			if(! -e "$datadir/$database"){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			else{
				$dfv->set_current_constraint_name("$database: L__Die Datenbank existiert bereits__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		elsif($type eq 'valid'){
						
			if($database !~ /[^a-zA-Z0-9_\-]/){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			else{
				$dfv->set_current_constraint_name("$database: L__Der Datenbankname enthält ungültige Zeichen__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}

		logline("debug","val=$val type=$type") if $debug;
		return ('');
	}
}

sub validate_dbuser{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my $type = shift;
	my $dbpass = shift;
	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;
		
		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_dbuser');
		my $dbuser = $dfv->get_current_constraint_value();

		my($dbh, $mysql_connect_error) = easytecc3::mysql_connect($dbuser, $dbpass);

		if($mysql_connect_error){
			$dfv->set_current_constraint_name('L__Die Datenbankverbindung konnte nicht hergestellt werden__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
		elsif($input{'action'} ne 'exec_add_mysql_password'){
		
			#my @dbusers = $dbh->selectrow_array("SELECT User FROM mysql.user WHERE User=? AND (Host=? OR Host LIKE ?)", undef, ( $dbuser, 'localhost', '%.han-solo.net' ));

			#$dbh->disconnect;
			
			#if(@dbusers){
				
			#	if(length($input{'dbpass'})){
			
			#		$dfv->set_current_constraint_name("$dbuser: L__Der MySQL-Benutzer existiert bereits.__L");
			#		logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			#		return('');

			#	}
				
			#} 
				
		}

		if($type eq 'valid'){
			if(length($dbuser) > 16){
				$dfv->set_current_constraint_name("$dbuser: L__Der Benutzername ist zu lang. Bitte geben Sie höchstens 16 Zeichen an.__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif($dbuser !~ /[a-zA-Z0-9_\-]/){
				$dfv->set_current_constraint_name("$dbuser: L__Der mySQL-Benutzername enthält ungültige Zeichen__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
			elsif($session->param('user') ne 'admin'){
			
				if($input{'ftpuser'} eq $dbuser){
				
					logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
					return('1');
					
				}	
			
				# gather allowed dirs
				my %allowed_dirs;
				if($session->param('user') ne 'admin'){
				
					my $httpd_conf = file->new({file_name => '/etc/httpd/conf/httpd.conf'});
					$httpd_conf->read_file;
					my %domains = %{$httpd_conf->file_parsed_hash()};
					
					foreach my $domain (keys %domains){

						my $admins = $domains{$domain}{'admin_users'};
						$admins =~ s/[\s,]+/#/g;
						$admins = '#' . $admins . '#';
						$userregex = '#' . $session->param('user') . '#';
						
						logline("debug","admins:$admins\nuserregex:$userregex");
						
						if($admins !~ m/$userregex/i){
							next;
						}
					
						$allowed_dirs{$domains{$domain}{'droot'}} = '1';
					}
					
					my $passwd = file->new({file_name => '/etc/passwd'});
					$passwd->read_file;
					my %passwd = %{$passwd->file_parsed_hash()};

					$allowed_dirs{$passwd{$session->param('user')}{'home'}} = '1';

				} 

				my $passwd = file->new({file_name => '/etc/passwd'});
				$passwd->read_file;
				my %passwd = %{$passwd->file_parsed_hash()};
				
				foreach my $user(sort keys %passwd){
					# chown nicht an POP-User ermöglichen
					next if $passwd{$user}{'gecos'} =~ / - POP/;

					my $home = $passwd{$user}{'home'};
					
					foreach my $dir (keys %allowed_dirs){
			
						if(($home eq $dir || $home =~ m#^$dir/#) && $user eq $dbuser){
				
							logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
							return('1');
					
						}
						
					}
					
				}
				
				$dfv->set_current_constraint_name("$dbuser: L__Der MySQL-Benutzername muss mit Ihrem oder einem FTP-Benutzernamen überinstimmen, den Sie administrieren dürfen.__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
					
			}
			
			else {
			
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			
			}
			
		}
		return ('');
	}
}

sub validate_mysql_backup{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my ($type) = shift;
	my $database = shift;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_mysql_backup');
		my $backup = $dfv->get_current_constraint_value();
		
		
		logline("debug","backup is $backup") if $debug;
		logline("debug","database is $database") if $debug;
		
		if($type eq 'exists'){
			if(-e "/var/lib/mysqlbackup/$database/$backup" && ! $fb){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			elsif(-e "/usr/local/etc/easytecc/mysqlbackup/$database/$backup" && $fb){
				logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
				return('1');
			}
			else{
				$dfv->set_current_constraint_name("$backup: L__Das mySQL-Backup existiert nicht__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}

		logline("debug","val=$val type=$type") if $debug;
		return ('');
	}
}

sub validate_email_backup{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_email_backup');
		my $email_backup = $dfv->get_current_constraint_value();
		if($email_backup =~ /^(yes|confirm)$/ || ! $email_backup){
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}
		else{
			$dfv->set_current_constraint_name('L__E-Mail-Backup: ungültige Option__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
	}
}

sub validate_backup_days{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;
	my $database = $input{'database'};

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_backup_days');
		my $backup_days = $dfv->get_current_constraint_value();

		if($backup_days =~ /^[0-9]{1,2}$/ && $backup_days > 0 && $backup_days < 15){
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');
		}
		elsif($backup_days eq '0' || ! length($backup_days) && -e "$mysqlbackup_dir/$database.dbb"){
			logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
			return('1');	
		}
		else{
			$dfv->set_current_constraint_name('L__Der Vorhaltezeitraum kann zwischen 1 und 14 Tage betragen__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
	}
}

sub validate_home{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my $user = shift;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_home');
		my $path = $dfv->get_current_constraint_value();

		logline("debug","validate_home path=$path") if $debug;
		
		if($user eq 'admin'){
			 #my $pw = Passwd::Unix->new('passwd' => '/etc/passwd', 'shadow' => '/etc/passwd');
			 #my $admin_home = $pw->home('admin');

			 my $pw = getpwnam("admin");
			 my $admin_home = $pw->dir;
			 
			 #my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $admin_home, $shell) = getpwnam("admin");
			#my $admin_home = `/usr/iports/bin/sudo /usr/local/bin/getpwnam_home -u admin`;
			 
			 logline("debug","validate_home admin_home=$admin_home path=$path") if $debug;
			 
			if($admin_home ne $path){
				$dfv->set_current_constraint_name("$path: L__Das home-Verzeichnis des Users admin kann nicht geändert werden.__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
			}
		}
		elsif($fb){
		
			if($session->param('user') ne 'admin'){
			
				# gather allowed dirs
				my %allowed_dirs;
				
				my $httpd_conf = file->new({file_name => '/etc/httpd/conf/httpd.conf'});
				$httpd_conf->read_file;
				my %domains = %{$httpd_conf->file_parsed_hash()};
				
				foreach my $domain (keys %domains){

					my $admins = $domains{$domain}{'admin_users'};
					$admins =~ s/[\s,]+/#/g;
					$admins = '#' . $admins . '#';
					$userregex = '#' . $session->param('user') . '#';
					
					logline("debug","admins:$admins\nuserregex:$userregex");
					
					if($admins !~ m/$userregex/i){
						next;
					}
				
					$allowed_dirs{$domains{$domain}{'droot'}} = '1';
				}
				
				my $passwd = file->new({file_name => '/etc/passwd'});
				$passwd->read_file;
				my %passwd = %{$passwd->file_parsed_hash()};

				$allowed_dirs{$passwd{$session->param('user')}{'home'}} = '1';
				
				foreach my $dir (keys %allowed_dirs){
				
					if($path eq $dir || $path =~ m#^$dir/#){
					
						return('1');
						
					}
				
				}
				
				$dfv->set_current_constraint_name("$path: L__Sie können dieses Verzeichnis nicht anlegen / administrieren.__L");
				return('');
			
			} else {
			
				#bei freebsd können user auch andere home-Verzeichnisse haben, z.B. mysql mit /var/db/mysql
				#oder virtmail mit homeverzeichnis /nonexistent
				if(($path !~ /^\/home\// &&
					$path !~ /^\/usr\/local\/www\// &&
					$path !~ /^\/var\// &&
					$path !~ /^\/nonexistent/) || $path =~ /\/\.$/ || $path =~ /\/\.\// || $path =~ /\.\./){
				$dfv->set_current_constraint_name("$path: L__Ein Home-Pfad für den User muss unterhalb des Verzeichnisses /home bzw. /usr/local/www liegen__L");
				logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
				return('');
				}	
			}
		}
		else{
				
			if($session->param('user') ne 'admin'){
			
				# gather allowed dirs
				my %allowed_dirs;
				
				my $httpd_conf = file->new({file_name => '/etc/httpd/conf/httpd.conf'});
				$httpd_conf->read_file;
				my %domains = %{$httpd_conf->file_parsed_hash()};
				
				foreach my $domain (keys %domains){

					my $admins = $domains{$domain}{'admin_users'};
					$admins =~ s/[\s,]+/#/g;
					$admins = '#' . $admins . '#';
					$userregex = '#' . $session->param('user') . '#';
					
					logline("debug","admins:$admins\nuserregex:$userregex");
					
					if($admins !~ m/$userregex/i){
						next;
					}
				
					$allowed_dirs{$domains{$domain}{'droot'}} = '1';
				}
				
				my $passwd = file->new({file_name => '/etc/passwd'});
				$passwd->read_file;
				my %passwd = %{$passwd->file_parsed_hash()};

				$allowed_dirs{$passwd{$session->param('user')}{'home'}} = '1';
				
				foreach my $dir (keys %allowed_dirs){
				
					if($path eq $dir || $path =~ m#^$dir/#){
					
						return('1');
						
					}
				
				}
				
				$dfv->set_current_constraint_name("$path: L__Sie können dieses Verzeichnis nicht anlegen / administrieren.__L");
				return('');
			
			} else {
		
				if($path !~ /^\/home\// || $path =~ /\/\.$/ || $path =~ /\/\.\// || $path =~ /\.\./){
					$dfv->set_current_constraint_name("$path: L__Ein Home-Pfad für den User muss unterhalb des Verzeichnisses /home liegen__L");
					logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
					return('');
				}
			}
		
		}	

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_home_action{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_home');
		my $home_action = $dfv->get_current_constraint_value();

		if($home_action !~ /^(delete|keep|cp|mv)$/){
			$dfv->set_current_constraint_name('L__home-verzeichnis: ungültige Aktion__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_autoreply_subject{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_autoreply_subject');
		my $autoreply_subject = $dfv->get_current_constraint_value();

		if($autoreply_subject =~ /\n/){
			$dfv->set_current_constraint_name('L__Das Subject enthält ungültige Zeichen__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_autoreply_text{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_autoreply_text');
		my $autoreply_text = $dfv->get_current_constraint_value();

		if(length($autoreply_text) > 5000){
			$dfv->set_current_constraint_name('L__Der Autorespondertext ist zu lang__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_change_htaccess_type{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my $type = shift;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_change_htaccess_type');
		my $type = $dfv->get_current_constraint_value();

		if($type !~ /^(newuser|changepass)$/){
			$dfv->set_current_constraint_name('L__Ungültiger Bearbeitungstyp__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_delete_htaccess_type{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	my $type = shift;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_delete_htaccess_type');
		my $type = $dfv->get_current_constraint_value();

		if($type !~ /^(delete_user|delete_all)$/){
			$dfv->set_current_constraint_name('L__Ungültiger Bearbeitungstyp__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_ssl_port{
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_ssl_port');
		my $ssl_port = $dfv->get_current_constraint_value();

		if($ssl_port !~ /^(443|8443|8444|8445|8446)$/){
			$dfv->set_current_constraint_name('L__Ungültige Portangabe für SSL__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}

		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
	}
}

sub validate_ssl_data{
		
	my ($type) = @_;	
		
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_ssl_data');
		my $data = $dfv->get_current_constraint_value();
		
		if($type =~ m/^(cert|key|chain)$/){
			
				if(
				   $fb && ! `/usr/iports/bin/sudo /usr/bin/du -A $data | sed 's/[^0-9].*//'` ||
				   !$fb && ! -e $data
				){
						
						$dfv->set_current_constraint_name('L__Die angegebene Datei existiert nicht__L');
						logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
						return('');
						
				}
				
		}
		
		elsif($type eq csr_country && length($data)){
				
				if($data !~ m/^(AF|AX|AL|DZ|AS|AD|AO|AI|AQ|AG|AR|AM|AW|AU|AT|AZ|BS|BH|BD|BB|BY|BE|BZ|BJ|BM|BT|BO|BQ|BA|BW|BV|BR|IO|BN|BG|BF|BI|KH|CM|CA|CV|KY|CF|TD|CL|CN|CX|CC|CO|KM|CG|CD|CK|CR|CI|HR|CU|CW|CY|CZ|DK|DJ|DM|DO|EC|EG|SV|GQ|ER|EE|ET|FK|FO|FJ|FI|FR|GF|PF|TF|GA|GM|GE|DE|GH|GI|GR|GL|GD|GP|GU|GT|GG|GN|GW|GY|HT|HM|VA|HN|HK|HU|IS|IN|ID|IR|IQ|IE|IM|IL|IT|JM|JP|JE|JO|KZ|KE|KI|KP|KR|KW|KG|LA|LV|LB|LS|LR|LY|LI|LT|LU|MO|MK|MG|MW|MY|MV|ML|MT|MH|MQ|MR|MU|YT|MX|FM|MD|MC|MN|ME|MS|MA|MZ|MM|NA|NR|NP|NL|NC|NZ|NI|NE|NG|NU|NF|MP|NO|OM|PK|PW|PS|PA|PG|PY|PE|PH|PN|PL|PT|PR|QA|RE|RO|RU|RW|BL|SH|KN|LC|MF|PM|VC|WS|SM|ST|SA|SN|RS|SC|SL|SG|SX|SK|SI|SB|SO|ZA|GS|SS|ES|LK|SD|SR|SJ|SZ|SE|CH|SY|TW|TJ|TZ|TH|TL|TG|TK|TO|TT|TN|TR|TM|TC|TV|UG|UA|AE|GB|US|UM|UY|UZ|VU|VE|VN|VG|VI|WF|EH|YE|ZM|ZW)$/){
						
						$dfv->set_current_constraint_name('L__Der angegebene Ländercode ist nicht korrekt__L');
						logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
						return('');
						
				}
				
		}
		
		elsif($type =~ m/^(csr_state|csr_city|csr_company|csr_section)$/ && length($data)){
				
				if($data !~ m/^[0-9A-Za-z\.-_ ]+$/){
						
						$dfv->set_current_constraint_name('L__Das Feld enthält ungültige Zeichen__L');
						logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
						return('');
						
				}
				
		}		
				
		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
		
	}
}

sub validate_is_admin{
		
	logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

	return sub {
		logline("debug",">>> Entering ".(caller(0))[3]."() from ".(caller(1))[3]."() Line: ".(caller(0))[2]) if $debug;

		my $dfv = shift;

		# Name it to refer to in the 'msgs' system.
		$dfv->name_this('validate_is_admin');
				
		if($session->param('user') ne 'admin'){					
			$dfv->set_current_constraint_name('L__Diese Funktion ist nur dem Administrator erlaubt__L');
			logline("debug","<<< Leaving ".(caller(0))[3]."() by $dfv->get_current_constraint_name.") if $debug;
			return('');
		}
				
		logline("debug","<<< Leaving ".(caller(0))[3]."().") if $debug;
		return('1');
		
	}
}




	
sub logline($$) {
	my $level = shift;
	my $message = shift;
	chomp $message;
	my ($package, $filename, $line) = caller;
	my $logline = sprintf '(%5.5d)', $line;
	$log->log( level => $level, message => $logline." ".$message);
}

sub dienice ($) {
	# write die messages to the log before die'ing
	my ($package, $filename, $line) = caller;
	logline("alert","$_[0] at line $line in $filename");
	die $_[0];
}

1;