Created
June 19, 2023 14:04
-
-
Save earnhardt3rd/56555c535b78712138c01a8ecd530daf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'getopts.pl'; | |
Getopts('m:d:t'); | |
my $MODE = uc($opt_m) || ""; | |
my $DEBUG = $opt_d || 0; | |
if (defined $opt_t) { my %TEST = &_USER_DATA();} | |
1; | |
sub _USER_DATA { | |
my $data_type = shift || ""; | |
print " DEBUG:_USER_DATA($data_type)\n" if $DEBUG > 1; | |
my $rtn_data; | |
my $os_user=$USERNAME; | |
if (scalar(keys %AUTHORIZED) <= 0) {&_LOAD_AUTHORIZED();} | |
if (scalar(keys %AUTHORIZED) > 0) { | |
if (!exists($AUTHORIZED{$ORIG_USER}{"GROUPS"})) {$AUTHORIZED{$ORIG_USER}{"GROUPS"}="";} | |
if ($AUTHORIZED{$ORIG_USER}{"GROUPS"} =~ /ADMIN/) { | |
if (exists($ENV{"POSER"}) and $ENV{"POSER"} ne "") { | |
if (exists($AUTHORIZED{$ENV{"POSER"}})) { | |
$os_user=$ENV{"POSER"}; | |
if ($USERNAME ne $os_user) { | |
my $poseMsg=" Hello $ORIG_USER, You Are Currently POSING AS '$os_user' \n"; | |
my $posubMsg.=" --BIN :" . $AUTHORIZED{$os_user}{"BIN"} . " \n"; | |
$posubMsg.=" --EMAIL :" . $AUTHORIZED{$os_user}{"EMAIL"} . " \n"; | |
$posubMsg.=" --GROUPS:" . $AUTHORIZED{$os_user}{"GROUPS"} . " \n"; | |
$poseMsg.= &displayMessageInBox($posubMsg,".","INT"); | |
$poseMsg.=" Proceed with caution...\n"; | |
&displayMessageInBox($poseMsg); | |
$USERNAME=$os_user; | |
$USER_ACCESS = $AUTHORIZED{$os_user}{"GROUPS"}; | |
$BINNAME=$AUTHORIZED{$os_user}{"BIN"}; | |
$OS_FOLDERS{"UBIN"} = $OS_FOLDERS{"BIN"} . $SLASH . $BINNAME; | |
} | |
} else { | |
$USERNAME="";#$ENV{"POSER"}; | |
if (lc($data_type) eq 'creds') {$rtn_data="GUEST";} | |
if (lc($data_type) eq 'bin') {$rtn_data="";} | |
if (lc($data_type) eq 'email') {$rtn_data="";} | |
$USER_ACCESS="GUEST"; | |
$BINNAME=""; | |
$OS_FOLDERS{"UBIN"} = $OS_FOLDERS{"PDM"} . $SLASH . "\.temp"; | |
return "";# $rtn_data; | |
} | |
} | |
} else { | |
if (exists($ENV{"POSER"}) and $ENV{"POSER"} ne "") { | |
print " DEBUG:ALLOW_IMPERSONATE=$ALLOW_IMPERSONATE\n" if $DEBUG > 100; | |
print " DEBUG:ALLOW_GUEST=$ALLOW_GUEST\n" if $DEBUG > 100; | |
if ($ALLOW_IMPERSONATE eq "TRUE") { | |
if (exists($AUTHORIZED{$ENV{"POSER"}})) { | |
$os_user=$ENV{"POSER"}; | |
if ($USERNAME ne $os_user) { | |
my $poseMsg=" Hello $ORIG_USER, You Are Currently POSING AS '$os_user' \n"; | |
my $posubMsg.=" --BIN :" . $AUTHORIZED{$os_user}{"BIN"} . " \n"; | |
$posubMsg.=" --EMAIL :" . $AUTHORIZED{$os_user}{"EMAIL"} . " \n"; | |
$posubMsg.=" --GROUPS:" . $AUTHORIZED{$os_user}{"GROUPS"} . " \n"; | |
$poseMsg.= &displayMessageInBox($posubMsg,".","INT"); | |
$poseMsg.=" Proceed with caution...\n"; | |
&displayMessageInBox($poseMsg); | |
$USERNAME=$os_user; | |
$USER_ACCESS = $AUTHORIZED{$os_user}{"GROUPS"}; | |
$BINNAME=$AUTHORIZED{$os_user}{"BIN"}; | |
$OS_FOLDERS{"UBIN"} = $OS_FOLDERS{"BIN"} . $SLASH . $BINNAME; | |
} | |
} else { | |
if ($ALLOW_GUEST eq "TRUE") { | |
$USERNAME=$ENV{"POSER"}; | |
if (lc($data_type) eq 'creds') {$rtn_data="GUEST";} | |
if (lc($data_type) eq 'bin') {$rtn_data="";} | |
if (lc($data_type) eq 'email') {$rtn_data="";} | |
$USER_ACCESS = $AUTHORIZED{$os_user}{"GROUPS"}; | |
$BINNAME=$AUTHORIZED{$os_user}{"BIN"}; | |
$OS_FOLDERS{"UBIN"} = $OS_FOLDERS{"BIN"} . $SLASH . $BINNAME; | |
return $rtn_data; | |
} else { | |
$USER_ACCESS="GUEST"; | |
$BINNAME=""; | |
$OS_FOLDERS{"UBIN"} = $OS_FOLDERS{"PDM"} . $SLASH . "\.temp"; | |
$rtn_data=""; | |
} | |
} | |
} | |
} | |
} | |
if (lc($data_type) eq 'creds') {if (exists($AUTHORIZED{$os_user}{"GROUPS"})) {$rtn_data=$AUTHORIZED{$os_user}{"GROUPS"};}} | |
if (lc($data_type) eq 'bin') {if (exists($AUTHORIZED{$os_user}{"BIN"})) {$rtn_data=$AUTHORIZED{$os_user}{"BIN"};}} | |
if (lc($data_type) eq 'email') {if (exists($AUTHORIZED{$os_user}{"EMAIL"})) {$rtn_data=$AUTHORIZED{$os_user}{"EMAL"};}} | |
} else { | |
&displayMessageInBox(" THERE ARE NO AUTHORIZED USERS CONFIGURED! ",":","INT"); | |
} | |
print " _USER_DATA($data_type) => $rtn_data\n" if $DEBUG >= 147; | |
return $rtn_data; | |
my $creds; | |
my %CS; | |
my $cName=""; | |
my $cUser=""; | |
if ($creds eq "") { | |
print " DEBUG:_USER_ACCESS:BUILDING AUTHORIZATION FOR USER ( $os_user )\n" if $DEBUG > 100; | |
if ($^O =~ /Win/) { | |
print " --$^O...\n"; | |
if (exists($ENV{"CLIENTNAME"})) { | |
$cName = $ENV{"CLIENTNAME"}; | |
$cName = lc($cName); | |
} | |
} else { | |
print " --$^O...\n"; | |
$cName = `who am i`; | |
chomp($cName); | |
print " DEBUG:WHO:$cName\n"if $DEBUG > 0; | |
$cName =~ s/.*\(//g; | |
print " DEBUG:WHO:$cName\n"if $DEBUG > 0; | |
$cName =~ s/\).*//g; | |
print " DEBUG:WHO:$cName\n"if $DEBUG > 0; | |
$cName = lc($cName); | |
} | |
if ($cName eq "") {$cName = "unknown";} | |
print " --CLIENTNAME:=$cName\n"; | |
my $saveCreds = $BIN . $SLASH . "\.creds_${cName}"; | |
print " DEBUG:SAVE BASE $saveCreds\n" if $DEBUG > 100; | |
my $ret_dir = cwd; | |
chdir $BIN; | |
opendir(LP,$BIN); | |
my @CS_FILES = grep { /^\.creds/ } readdir(LP); | |
closedir(LP); | |
for (my $cs=0;$cs<=scalar(@CS_FILES)-1 ;$cs++) { | |
my $cTmp = $CS_FILES[$cs]; | |
$cTmp =~ s/\.txt$//g; | |
print " DEBUG:$cTmp\n" if $DEBUG > 100; | |
my ($junk,$cname,$uname) = split('_',$cTmp); | |
if (! exists($CS{$cname})) {$CS{$cname}="";} | |
if ($CS{$cname} eq "") { | |
$CS{$cname} = $uname; | |
} else { | |
my @cCS = split(',',$CS{$cname}); | |
my $cCSFlag=0; | |
for (my $cx=0;$cx<=scalar(@cCS)-1 ;$cx++) { | |
if (lc($cCS[$cx]) eq lc($uname)) { | |
$cCSFlag++; | |
} | |
} | |
if ($cCSFlag eq "0") { | |
$CS{$cname}.= ",$uname"; | |
} | |
} | |
} | |
chdir $ret_dir; | |
if (exists($CS{$cName})) { | |
print " DEBUG:Found CS{$cName}=" . $CS{$cName} . "\n" if $DEBUG > 100; | |
my @cList = split(',',$CS{$cName}); | |
if (scalar(@cList) eq "1") { | |
$cUser = $CS{$cName}; | |
} else { | |
} | |
} else { | |
print " DEBUG:ALLOW_IMPERSONATE=$ALLOW_IMPERSONATE\n" if $DEBUG > 100; | |
print " DEBUG:ALLOW_GUEST=$ALLOW_GUEST\n" if $DEBUG > 100; | |
if ($ALLOW_IMPERSONATE eq "FALSE") { | |
if ($ALLOW_GUEST eq "TRUE") { | |
$creds="guest"; | |
} else { | |
$creds=""; | |
} | |
} else { | |
print "\n"; | |
print " =========================================================\n"; | |
print " I am unable to determine who you really are ($os_user)\n"; | |
print "\n"; | |
print " Please enter your real domain login acount:"; | |
my $ina = <STDIN>; | |
chomp($ina); | |
$ina =~ s/.*\\//g; | |
if ($ina eq "") { | |
if ($ALLOW_GUEST eq "TRUE") { | |
print " =========================================================\n"; | |
print " guest!\n"; | |
$creds="guest"; | |
} else { | |
$creds=""; | |
} | |
} else { | |
$cUser = $ina; | |
print " =========================================================\n"; | |
} | |
} | |
} | |
#========================================================================= | |
$creds = $AUTHORIZED{$cUser} || ""; | |
if ($creds eq "") { | |
print "\n"; | |
print " =========================================================\n"; | |
print " I'm sorry but I do not know who that is\n"; | |
print " Please contact systems team!\n"; | |
print " =========================================================\n"; | |
if ($ALLOW_GUEST eq "TRUE") { | |
$creds="guest"; | |
} else { | |
$creds=""; | |
} | |
} else { | |
$USERNAME = $cUser; | |
$ENV{"USERNAME"} = $USERNAME; | |
$saveCreds.="_${cUser}.txt"; | |
print " DEBUG:SAVE CREDS:$saveCreds\n" if $DEBUG > 100; | |
if ($cName ne "") { | |
open (SC,">> $saveCreds"); | |
print SC "${DT},${TM}\n"; | |
close(SC); | |
} | |
} | |
} else { | |
print " DEBUG:_USER_ACCESS:FOUND AUTHORIZED FOR USER ( $os_user ) AS $creds!\n"if $DEBUG > 100; | |
} | |
return $creds; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment