S
sitnam81
Hello all,
I am working on a web front end that would allow administrators to
manage Solaris users on multiple servers -- a php page with a form
passes input to this perl cgi script, which ssh's to the selected
servers and executes shell scripts to add/remove the input user. These
schell scripts return one line of output, which I want to pass back to
the perl script, to display the results. I keep getting "500" errors
with the following in the apache log:
[error] malformed header from script. Bad header=user inputusername
removed: add_remove_user.cgi, referer: http://IP/useradmin.php
Like the example above the output from the shell script is like "user
inputusername removed" -- how can I pass this back to the page? Here
is the perl scipt:
*******************************************************************
#!/usr/bin/perl -w
print "Content-type:text/html\n\n";
$loop = 0;
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
if($value eq "ON") {
$SERVER{$loop} = $name;
$loop++
}
else {
$FORM{$name} = $value;
}
}
$loopc = $loop;
$user = "specifieduser";
$addcommand = "sudo /etc/scripts/useradd $FORM{uname} $FORM{UID}
$FORM{group}";
$rmcommand = "sudo /etc/scripts/userremove $FORM{uname}";
print "<html><head><title>Form Output</title></head><body>";
print "<h2>Results from FORM post</h2>\n";
if($FORM{pass} eq "") {
print "Please enter a password<br>";
print "<br><a href='javascript: history.go(-1)'>Back</a>";
}
elsif($FORM{pass} eq $FORM{pass2}) {
if($FORM{radio} eq "add") {
for($loop = 0; $loop < $loopc; $loop++)
{
print "ADDING Username: $FORM{uname} UID: $FORM{UID} Group:
$FORM{group} to $SERVER{$loop}\n\n";
#$ADDRESPONSE = system("ssh", "-l", "$user", "-q", "$SERVER{$loop}",
$addcommand);
#print "$ADDRESPONSE\n";
print system("ssh", "-l", "$user", "-q",
"$SERVER{$loop}", $addcommand);
}
}
else {
for($loop = 0; $loop < $loopc; $loop++)
{
print "REMOVING Username: $FORM{uname} UID: $FORM{UID}
Group: $FORM{group} to $SERVER{$loop}\n\n";
#system("ssh", "-l", $user, "-q", $SERVER{$loop},
$rmcommand, "| 2>&1 >/dev/null");
$RMRESPONSE = system("ssh", "-l", "$user", "-q",
"$SERVER{$loop}", $rmcommand);
print "$RMRESPONSE\n";
print system("ssh", "-l", "$user", "-q",
"$SERVER{$loop}", $rmcommand);
}
}
print "<br><a href='javascript: history.go(-1)'>Back</a>";
}
else {
print "Passwords do not match<br>";
print "<br><a href='javascript: history.go(-1)'>Back</a>";
}
print "</body></html>";
*******************************************************************
Thanks!
I am working on a web front end that would allow administrators to
manage Solaris users on multiple servers -- a php page with a form
passes input to this perl cgi script, which ssh's to the selected
servers and executes shell scripts to add/remove the input user. These
schell scripts return one line of output, which I want to pass back to
the perl script, to display the results. I keep getting "500" errors
with the following in the apache log:
[error] malformed header from script. Bad header=user inputusername
removed: add_remove_user.cgi, referer: http://IP/useradmin.php
Like the example above the output from the shell script is like "user
inputusername removed" -- how can I pass this back to the page? Here
is the perl scipt:
*******************************************************************
#!/usr/bin/perl -w
print "Content-type:text/html\n\n";
$loop = 0;
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
if($value eq "ON") {
$SERVER{$loop} = $name;
$loop++
}
else {
$FORM{$name} = $value;
}
}
$loopc = $loop;
$user = "specifieduser";
$addcommand = "sudo /etc/scripts/useradd $FORM{uname} $FORM{UID}
$FORM{group}";
$rmcommand = "sudo /etc/scripts/userremove $FORM{uname}";
print "<html><head><title>Form Output</title></head><body>";
print "<h2>Results from FORM post</h2>\n";
if($FORM{pass} eq "") {
print "Please enter a password<br>";
print "<br><a href='javascript: history.go(-1)'>Back</a>";
}
elsif($FORM{pass} eq $FORM{pass2}) {
if($FORM{radio} eq "add") {
for($loop = 0; $loop < $loopc; $loop++)
{
print "ADDING Username: $FORM{uname} UID: $FORM{UID} Group:
$FORM{group} to $SERVER{$loop}\n\n";
#$ADDRESPONSE = system("ssh", "-l", "$user", "-q", "$SERVER{$loop}",
$addcommand);
#print "$ADDRESPONSE\n";
print system("ssh", "-l", "$user", "-q",
"$SERVER{$loop}", $addcommand);
}
}
else {
for($loop = 0; $loop < $loopc; $loop++)
{
print "REMOVING Username: $FORM{uname} UID: $FORM{UID}
Group: $FORM{group} to $SERVER{$loop}\n\n";
#system("ssh", "-l", $user, "-q", $SERVER{$loop},
$rmcommand, "| 2>&1 >/dev/null");
$RMRESPONSE = system("ssh", "-l", "$user", "-q",
"$SERVER{$loop}", $rmcommand);
print "$RMRESPONSE\n";
print system("ssh", "-l", "$user", "-q",
"$SERVER{$loop}", $rmcommand);
}
}
print "<br><a href='javascript: history.go(-1)'>Back</a>";
}
else {
print "Passwords do not match<br>";
print "<br><a href='javascript: history.go(-1)'>Back</a>";
}
print "</body></html>";
*******************************************************************
Thanks!