hi linux programmers
my friend and i are writing a perl program, the idea is using web browser as command prompt. a form for user to enter a command for the remote linux computer, then the output/result will print out in the browser.
However, some of the command still unable to do like "cd" ...etc
what it can do is "ls", "man" ... something like that...
#!/usr/bin/perl
print "Content-type: text/html\nPragma: no-cache\n\n";
sub form_handler
{
my($hashRef) = shift;
my($buffer)="";
if ($ENV{'REQUEST_METHOD'} eq 'GET' ){
$buffer=$ENV{'QUERY_STRING'};
}
else {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}
#print "$buffer";
foreach (split(/&/, $buffer)) {
my($key, $value) = split(/=/, $_);
#print "$key = $value";
$key = decodeURL($key);
$value=decodeURL($value);
%{$hashRef} -> {$key} = $value;
}
}
sub decodeURL {
$_ = shift;
tr/+/ /;
s/%(..)/pack('c', hex($1))/eg;
return($_);
}
sub form{
print "<form action='command.cgi'><input type=text name=command><input
type=submit></form><br><br>";
}
form_handler(\%form);
form();
print $form{command};
if($form{command}){
$temp = `$form{command}`;
$_ = $temp;
#s/\x0d/<br>/eg;
print $_;
}
ANY suggestion(s) for further improvement plz ??thx a lot