CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Running ADMIN level commands on a webserver

 



fuzioneer
stranger

Aug 28, 2001, 7:41 AM

Post #1 of 1 (855 views)
Running ADMIN level commands on a webserver Can't Post

I am a beginner to perl and wish to design a web site that allows me to run administration jobs remotely. I have a completed forms page which posts to my perl script and that detects, parses and prints out all variables correctly. However when I wish to run commands that require administrator access I cannot as the perl script is running under the IUSR account in IIS and does not have the required privileges. Any one have any idea how I can get around this. I enclose the partially finished script for review

#!/localhost/perl/bin
#########################################################################################################
# #
# #
# Ver 1.1 (Now takes input from web page form) 25th August 2001 #
# #
#########################################################################################################
# Setup Variables
$true="1";
$|=1; # Flush immediately.
print "Content-Type: text/plain\n\n";

# Get Information from Form output

if ( $ENV{'REQUEST_METHOD'} eq "GET" &&
$ENV{'QUERY_STRING'} ne '') {
$form = $ENV{'QUERY_STRING'};
}
elsif ( $ENV{'REQUEST_METHOD'} eq "POST" ) {
read(STDIN,$form, $ENV{'CONTENT_LENGTH'});
} else {
print "\n You haven't entered any Information";
exit;
}

# Now the variable $form has your input data. Create associative array.
foreach $pair (split('&', $form)) {
if ($pair =~ /(.*)=(.*)/) { # found key=value;
($key,$value) = ($1,$2); # get key, value.
$value =~ s/\+/ /g; # substitute spaces for + signs.
$value =~ s/%(..)/pack('c',hex($1))/eg;
$inputs{$key} = $value; # Create Associative Array.
}
}

foreach $item (keys(%inputs)) {

#print "$item is set to $inputs{$item}\n";
if ($item eq "hostname") {
$server =$inputs{$item};
} elsif ($item eq "ipaddress") {
$ipaddress=$inputs{$item};
} elsif ($item eq "scans") {
$scans=$inputs{$item};
} elsif ($item eq "test") {
$test=$inputs{$item};
}
}
# print out results so far
#print "Server name is $server \n"; #commented out used for diagnostics
#print "ipaddress is $ipaddress \n"; #commented out used for diagnostics
#print "Scan Repetition is $scans \n"; #commented out used for diagnostics
#print "Test type is $test \n"; #commented out used for diagnostics
# Carry out logical testing for test to carry out
if ($test == 1) {
&quick;
} elsif ($test == 2) {
&intensive;
} elsif ($test == 3) {
&mcafee;
} elsif ($test == 4) {
&hfnetchk;
} elsif ($test == 5) {
&domain;
} elsif ($test == 6) {
&lastuser;
} else {
print "incorrect option somehow\n";
}
#########################################################################################################
# use input to form variable
##########################################################################################################
sub quick {
# print "quick scan subroutine\n";
}
sub intensive {
# print "intensive scan subroutine\n";
}
sub mcafee {
# print "mcafee subroutine\n";
system "mcafee.bat $server";
}
sub hfnetchk {
# print "hfnetchk subroutine\n";
system "hfnet.bat $server";
}
sub domain {
# print "domain subroutine\n";
}
sub lastuser {
print "Last User subroutine\n";
# carry out Reg Query and action as required
use Win32::TieRegistry ( Delimiter=>"/", ArrayValues=>1 );

$Registry->Delimiter("/"); # Set delimiter to "/".

$remKey= $Registry->Connect( "$server", "LMachine", { Access=>KEY_READ,Delimiter=>"/" } );
# or die "Can't access registry key: $^E\n"; # Connect to remote registry

$regkey = $remKey->{"Software/Microsoft/Windows NT/CurrentVersion/Winlogon//DontDisplayLastUserName"};

# print "@$regkey[0]\n"; # Print it (note it is a reference to an array -hence the @$)uncomment for bug fixing

$reg=@$regkey[0];
if ($reg eq "0") {
print "Key present but not enabled, ";
} elsif ($reg eq "1") {
print "Key present & enabled already \n";
} else {
print "key missing \n";
}
# Carry out logical test
if (@$regkey[0] ne $true) {
system "regadd.bat $server";
print "Implemented Patch, \n";
} else {
print "Skipping\n";
}
}


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives