403Webshell
Server IP : 69.39.225.240  /  Your IP : 216.73.216.138
Web Server : Apache
System : Linux bronze7.serverhost.net 3.10.0-1160.105.1.el7.x86_64 #1 SMP Thu Dec 7 15:39:45 UTC 2023 x86_64
User : reademotions ( 1074)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib64/perl5/Spectro/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib64/perl5/Spectro/Shared.pm
#
#Change Log:
#11/8/01: added notify2 sub

package Spectro::Shared;

#use strict;

use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);

use Exporter;
$VERSION = 1.0;

@ISA = qw(Exporter);
@EXPORT = (
	'&chownbyname',
	'&delvirtualhost',
	'&getdir',
	'&getgroup',
	'&getip',
	'&getdomainsline',
	'&getallusers',
	'&getfpvirtualhost',
	'&getmainuser',
	'&getvirtualhost',
	'&is_dedicated',
	'&is_our_box',
	'&is_our_ip',
	'&notify',
	'&notify2',
	'&putfpvirtualhost',
	'&putvirtualhost',
	'&valid_username',
	'&valid_password',
	'&valid_domainname',
	'$username_rules',
	'$password_rules',
	'$ServerVersion',
	'$cgilib_path'
);

@EXPORT_OK = qw();
%EXPORT_TAGS = ();

#if ( -e '/no/more/rh4/support') {
#	$ServerVersion	= 1;
#	$ifconfig_path	= '/sbin/ifconfig';
#	$cgilib_path	= '/usr/local/lib/cgi-lib.pl';
#} else {
	$ServerVersion	= 2;
	$ifconfig_path	= '/usr/local/bin/.ifconfig';
	$cgilib_path	= '/usr/local/lib/cgi-lib.pl';
#}

$min_username_chars = 1;
$max_username_chars = 80;
$min_passwd_chars = 6;
$max_passwd_chars = 80;
$password_rules = "Passwords must be between $min_passwd_chars and $max_passwd_chars alpha-numeric, and punctuation characters";
$username_rules = "User names must be between $min_username_chars and $max_username_chars alpha-numeric characters including dashes (-) anywhere except the beginning";


###########################################################
#getdir - returns web directory name (without /www/) for a given domain
sub getdir	{
	my ($dom) = @_;
	my $grp = &getgroup($dom);
	my $dir = $grp;

	$dir =~ s/grp$// or $dir =~ s/^grp// if ($dir);
	return($dir);
}
	
###########################################################
#getgroup - returns group name for a given domain
sub getgroup	{
	my ($dom) = @_;
	my ($line, $grp);

	chomp($line = &getdomainsline($dom));
	$grp = (split /\s+/, $line)[2];
	return($grp);
}
	
###########################################################
#getip - returns ip number for a given domain
sub getip	{
	my ($dom) = @_;
	my ($line, $ip);

	chomp($line = &getdomainsline($dom));
	$ip = (split /\s+/, $line)[1];
	return($ip);
}

###########################################################
#getdomainsline - returns the line in /etc/domains for a given domain
sub getdomainsline	{
	my ($dom) = @_;
	my $line;

	if (open(DOM, "/etc/domains"))	{
		foreach (<DOM>)	{
			next unless /^$dom\s/;
			$line = $_;
			last;
		}
		close DOM;
	}
	return ($line);
}

###########################################################
#getallusers - returns list of all users for a given domain
sub getallusers	{
	my ($dom) = @_;
	my @users = ();
	my ($u, $g);
	my $grp = &getgroup($dom);
	my $gid = (getgrnam $grp)[2];

	return unless ($gid);
	if (open(PWD, "/etc/passwd"))	{
		foreach (<PWD>)	{
			($u, $g) = (split /\:/)[0,3];
			push (@users, $u) if ($g == $gid);
		}
		close PWD;
	}
	return (@users);
}

###########################################################
#getmainuser - returns main user name for a given domain
sub getmainuser	{
	my ($dom) = @_;
	my ($grp, $g, $gid, @chk, $dir, $muid, $uid, $u, $uh);
	my $user = "";
	my $host = `/bin/hostname`;

	chomp($host);
	$grp = &getgroup($dom);
	$gid = (getgrnam $grp)[2];
	return("") unless ($gid);
	$dir = &getdir($dom);
	$muid = (stat "/www/$dir/cgi-bin")[4];


	#check /etc/aliases file for sinfobots line, that should have the main user
        @chk = `grep \"^$dom: \" /etc/aliases`;
	foreach (@chk)	{
		chomp;
		next unless (/^$dom\: \"\|\/usr\/spc\/sinfobots .*\"$/);
                $user = (split)[2];
                $user =~ s/\"$//;
		if ($user)	{	#see if gid for this user is correct for this domain
			$g = (getpwnam $user)[3];
			return($user) if ($g and ($g == $gid));
		}
        }
	#check /etc/aliases3 file for sinfobots line, if there, call newaliases
        @chk = `grep \"^$dom: \" /etc/aliases3`;
	foreach (@chk)	{
		chomp;
		next unless (/^$dom\: \"\|\/usr\/spc\/sinfobots .*\"$/);
                $user = (split)[2];
                $user =~ s/\"$//;
		if ($user)	{	#see if gid for this user is correct for this domain
			$g = (getpwnam $user)[3];
			if ($g and ($g == $gid))	{
				system "/usr/spc/newaliases";
			        $chk = `grep \"^$dom: .*$user\" /etc/aliases`;
				return($user) if ($chk);
			}
		}
        }

	if (open(PWD, "/etc/passwd"))	{
		foreach (<PWD>)	{
			($u, $uid, $g, $uh) = (split /\:/)[0,2,3,5];
			if (($g == $gid) and (-d "$uh/.wusage") and ($uid == $muid))	{
				if (open(A3, ">>/etc/aliases3"))	{
					print A3 "$dom: \"|/usr/spc/sinfobots $u\"\n";
					close A3;
					system "/usr/spc/newaliases";
				}
				return($u);
			}
		}
		close PWD;
	}
	
	return("");
}
	
###########################################################
#getvirtualhost - returns all lines of httpd.conf virtualhost section for given domain
sub getvirtualhost	{
	my ($dom) = @_;
	my $active = 0;
	my @vh = ();
	my ($hcfile, $ip, @thevh);

	return unless ($dom);
	$dom =~ s/^www\.//;
	$ip = &getip($dom);
	return unless ($ip);
	if (-f "/usr/local/apache/conf/httpd.conf")	{
		$hcfile = "/usr/local/apache/conf/httpd.conf";
	} else	{
		$hcfile = "/www/conf/httpd.conf";
	}
	if (open(HC, "$hcfile"))	{
		foreach (<HC>)	{
			$active = 1 if (/virtualhost (www\.$dom|$dom|$ip)(\>| |:80)/);
			push(@vh, $_) if ($active);
			if ($active and /^\<\/virtualhost\>/i)	{
				@thevh = @vh;
				if ($vh[0] =~ /$ip/)	{
					unless (grep /^ServerName +(|www\.)$dom$/, @vh)	{
						@vh = ();
						$active = 0;
						next;
					}
				}
				last;
			}
		}
		close HC;
	}
	return @thevh;
}

###########################################################
#getfpvirtualhost - returns all lines of apache/$dom/httpd.conf virtualhost section for given domain
sub getfpvirtualhost	{
	my ($dom) = @_;
	my $active = 0;
	my @vh = ();
	my ($hcfile, $ip, @thevh);

	return unless ($dom);
	$dom =~ s/^www\.//;
	$ip = &getip($dom);
	return unless ($ip);
	if (-f "/usr/local/apache/conf/$dom/httpd.conf")	{
		$hcfile = "/usr/local/apache/conf/$dom/httpd.conf";
	} else	{
		$hcfile = "/www/conf/$dom/httpd.conf";
	}
	if (open(HC, "$hcfile"))	{
		foreach (<HC>)	{
			$active = 1 if (/virtualhost (www\.$dom|$dom|$ip)(\>| |:80)/);
			push(@vh, $_) if ($active);
			if ($active and /^\<\/virtualhost\>/i)	{
				@thevh = @vh;
				if ($vh[0] =~ /$ip/)	{
					unless (grep /^ServerName +(|www\.)$dom$/, @vh)	{
						@vh = ();
						$active = 0;
						next;
					}
				}
				last;
			}
		}
		close HC;
	}
	return @thevh;
}

##########################################################
# is_our_ip -
#   returns non-zero if $ip falls in the following IP ranges:
#      216.71, 64.33, 209.204.192 - 209.204.255,
#      209.150.128 - 209.150.159

sub is_our_ip {

#	my($ipa) = @_;
#	my($a, $b, $c, $d) = split (/\./, $ipa);
#
#	if (($ipa =~ /^216\.71\./) || ($ipa =~ /^64\.33\./) ||
#		(($ipa =~ /^209\.204\./) && ($c >= 192)) ||
#		(($ipa =~ /^209\.150\./) && (($c >= 128) && ($c <= 159))) ) {
		return 1;
#	} else {
#		return 0;
#	}
}


###########################################################
# is_our_box
# - returns non-zero if ifconfig reports an OLM IP for eth0
sub is_our_box {
#	my $ifc = `$ifconfig_path eth0 2> /dev/null | grep "inet addr"`;
#	my ($ip) = ($ifc =~ /inet addr:(\d+\.\d+\.\d+\.\d+)\s+B/);
#	if (&is_our_ip($ip)) {
		return 1;
#	} else {
		return 0;
#	
}


###########################################################
sub valid_password {
    local ($passwd) = @_;

    if (
        ($passwd =~ /^[\w\d_\@\%\#]+$/) &&	#allow these 3 new chars
        (length($passwd) >= $min_passwd_chars) &&
        (length($passwd) <= $max_passwd_chars)
    ) {
        return 1;
    } else {
        return 0;
    }
}


###########################################################
sub valid_username {
    my ($username) = @_;

    if (
        ($username =~ /^[A-Za-z][A-Za-z0-9\-\.]*$/) &&
        (length($username) >= $min_username_chars) &&
        (length($username) <= $max_username_chars)
    ) {
        return 1;
    }
    return 0;
}

###########################################################
sub valid_domainname {
    my ($domname) = @_;

    if (
        ($domname =~ /^[A-Za-z][A-Za-z0-9\-\.]*$/) &&
	($domname =~ /\./) &&
	($domname !~ /\.(\.|$)/)
    ) {
        return 1;
    }
    return 0;
}


###########################################################
sub is_dedicated {
	unless (`/bin/hostname` =~ /host4u\.net/) {
		return 1;
	}
	return 0;
}


###########################################################
sub notify {
        local($msg, $subject) = @_;
        my $time = time;
	my $mail_path = '/bin/mail';
	my @notify_email = (
		"message\@dragon.axxs.net",
	);
        $msg = "[$time] $msg";
	foreach (@notify_email) {
		open (MAIL, "|$mail_path -s '$subject' $_");
		print MAIL "$msg";
		close(MAIL);
	}
}

sub notify2 {
        local($msg, $subject) = @_;
        my $time = time;
	my $mail_path = '/bin/mail';
	my @notify_email = (
		"message2\@dragon.axxs.net",
	);
        $msg = "[$time] $msg";
	foreach (@notify_email) {
		open (MAIL, "|$mail_path -s '$subject' $_");
		print MAIL "$msg";
		close(MAIL);
	}
}

###########################################################
#putvirtualhost - writes given virtualhost lines to httpd.conf for given domain
sub putvirtualhost	{
	my ($dom, @vh) = @_;
	my $active = 0;
	my ($hcfile, $ip, @lines);
	my @buffer = ();

	return unless ($dom and scalar(@vh));
	$dom =~ s/^www\.//;
	$ip = &getip($dom);
	return unless ($ip);
	if (-f "/usr/local/apache/conf/httpd.conf")	{
		$hcfile = "/usr/local/apache/conf/httpd.conf";
	} else	{
		$hcfile = "/www/conf/httpd.conf";
	}
	system "cp $hcfile $hcfile.bak";
	@lines = `cat $hcfile`;
	system "/usr/bin/lockfile -l 60 $hcfile.new.lock";
	if (open(HC, ">$hcfile.new"))	{
		foreach (@lines)	{
			$active = 1 if (/virtualhost (www\.$dom|$dom|$ip)(\>| |:80)/);
			if ($active)	{
				push(@buffer, $_);
			} else	{
				print HC;
			}
			if ($active and /^\<\/virtualhost\>/i)	{
				$active = 0;
				if ($buffer[0] =~ /$ip/)	{
					unless (grep /^ServerName +(|www\.)$dom$/, @buffer)	{
						print HC @buffer;
					}
				}
				@buffer = ();
			}
		}
		print HC @vh;
		print HC "\n";
		close HC;
		system "mv $hcfile.new $hcfile";
		system "httpd.reload";
		unlink "$hcfile.new.lock";
		return(1);
	}
	unlink "$hcfile.new.lock";
	return(0);
}

###########################################################
#putfpvirtualhost - writes given virtualhost lines to apache/$dom/httpd.conf for given domain
sub putfpvirtualhost	{
	my ($dom, @vh) = @_;
	my $active = 0;
	my ($hcfile, $ip, @lines);
	my @buffer = ();

	return unless ($dom and scalar(@vh));
	$dom =~ s/^www\.//;
	$ip = &getip($dom);
	return unless ($ip);
	if (-f "/usr/local/apache/conf/$dom/httpd.conf")	{
		$hcfile = "/usr/local/apache/conf/$dom/httpd.conf";
	} else	{
		$hcfile = "/www/conf/$dom/httpd.conf";
	}
	system "cp $hcfile $hcfile.bak";
	@lines = `cat $hcfile`;
	system "/usr/bin/lockfile -l 60 $hcfile.new.lock";
	if (open(HC, ">$hcfile.new"))	{
		foreach (@lines)	{
			$active = 1 if (/virtualhost (www\.$dom|$dom|$ip)(\>| |:80)/);
			if ($active)	{
				push(@buffer, $_);
			} else	{
				print HC;
			}
			if ($active and /^\<\/virtualhost\>/i)	{
				$active = 0;
				if ($buffer[0] =~ /$ip/)	{
					unless (grep /^ServerName +(|www\.)$dom$/, @buffer)	{
						print HC @buffer;
					}
				}
				@buffer = ();
			}
		}
		print HC @vh;
		print HC "\n";
		close HC;
		system "mv $hcfile.new $hcfile";
		system "httpd.reload";
		unlink "$hcfile.new.lock";
		return(1);
	}
	unlink "$hcfile.new.lock";
	return(0);
}

###########################################################
#delvirtualhost - removes virtualhost lines from httpd.conf for given domain
sub delvirtualhost	{
	my ($dom) = @_;
	my $active = 0;
	my ($hcfile, @lines);

	return unless ($dom);
	$dom =~ s/^www\.//;
	if (-f "/usr/local/apache/conf/httpd.conf")	{
		$hcfile = "/usr/local/apache/conf/httpd.conf";
	} else	{
		$hcfile = "/www/conf/httpd.conf";
	}
	system "cp $hcfile $hcfile.bak";
	if (open(HC, "$hcfile"))	{
		@lines = <HC>;
		close HC;
	} else	{
		return(0);
	}
	system "/usr/bin/lockfile -l 60 $hcfile.new.lock";
	if (open(HC, ">$hcfile.new"))	{
		foreach (@lines)	{
			$active = 1 if (/virtualhost (www\.|)$dom(\>| |:80)/);
			print HC unless ($active);
			$active = 0 if ($active and /^\<\/virtualhost\>/i);
		}
		close HC;
		system "mv $hcfile.new $hcfile";
		system "httpd.reload";
		unlink "$hcfile.new.lock";
		return(1);
	}
	unlink "$hcfile.new.lock";
	return(0);
}

sub chownbyname	{
	local ($user, $pattern) = @_;

	if ($pattern =~ / /)	{
		chown((getpwnam($user))[2,3], "$pattern");
	} else	{
		chown((getpwnam($user))[2,3], glob($pattern));
	}
}

# end of OLM::Shared module subroutines
##########################################################
1;



Youez - 2016 - github.com/yon3zu
LinuXploit