下面的正則表達式的工作,以確認是否傳遞給它的輸入包含字符串「平」如何匹配& or ;或< or >或|在正則表達式中?
elsif($RunCommand =~ m/^\s*ping\s+(.+)/)
現在我想確認是否通過輸入包含管道命令|
下似乎並沒有被正確地工作:
elsif($RunCommand =~ m/^\s*|\s+(.+)/)
對於方面,我有以下如果ELSEIF子程序。我只是將5條語句添加到頂部,以檢查&或;或<或>或|。但它不能正常工作...現在它總是去& PrintPageHeaderBC(「c」);並且包含ping,nslookup等(可接受的命令)的嘗試現在不做他們應該做的事情。我相信問題必須是我添加的5個正則表達式對於匹配和輸入的文本不正確,其中包含&或;或<或>或|。任何幫助?我確信我所做的5個單獨陳述(可能不正確),也可以合併爲一個陳述。
# First discard command attempts that contain & ; < > |, then acceptable commands are executed, then final else to non-functional command
if($RunCommand =~ m/^\s*&\s+(.+)/)
{
# Print PageHeaderBC that informs of non-functional command
&PrintPageHeaderBC("c");
}
elsif($RunCommand =~ m/^\s*;\s+(.+)/)
{
# Print PageHeaderBC that informs of non-functional command
&PrintPageHeaderBC("c");
}
elsif($RunCommand =~ m/^\s*<\s+(.+)/)
{
# Print PageHeaderBC that informs of non-functional command
&PrintPageHeaderBC("c");
}
elsif($RunCommand =~ m/^\s*>\s+(.+)/)
{
# Print PageHeaderBC that informs of non-functional command
&PrintPageHeaderBC("c");
}
elsif($RunCommand =~ m/^\s*|\s+(.+)/)
{
# Print PageHeaderBC that informs of non-functional command
&PrintPageHeaderBC("c");
}
# Now start acceptable commands
# PING
elsif($RunCommand =~ m/^\s*ping\s+(.+)/)
{
&PrintPageHeader("c");
#$Prompt = $WinNT ? "$CurrentDir> " : "[admin\@$ServerName $CurrentDir]\$ ";
$Prompt = $WinNT ? "$CurrentDir> " : "\$ ";
print "<code>$Prompt $RunCommand</code><xmp>";
$Command = "cd \"$CurrentDir\"".$CmdSep.$RunCommand.$Redirector;
if(!$WinNT)
{
$SIG{'ALRM'} = \&CommandTimeout;
alarm($CommandTimeoutDuration);
}
if($ShowDynamicOutput) # show output as it is generated
{
$|=1;
$Command .= " |";
open(CommandOutput, $Command);
while(<CommandOutput>)
{
$_ =~ s/(\n|\r\n)$//;
print "$_\n";
}
$|=0;
}
else # show output after command completes
{
print `$Command`;
}
if(!$WinNT)
{
alarm(0);
}
print "</xmp>";
}
# TELNET
elsif($RunCommand =~ m/^\s*telnet\s+(.+)/)
{
&PrintPageHeader("c");
#$Prompt = $WinNT ? "$CurrentDir> " : "[admin\@$ServerName $CurrentDir]\$ ";
$Prompt = $WinNT ? "$CurrentDir> " : "\$ ";
print "<code>$Prompt $RunCommand</code><xmp>";
$Command = "cd \"$CurrentDir\"".$CmdSep.$RunCommand.$Redirector;
if(!$WinNT)
{
$SIG{'ALRM'} = \&CommandTimeout;
alarm($CommandTimeoutDuration);
}
if($ShowDynamicOutput) # show output as it is generated
{
$|=1;
$Command .= " |";
open(CommandOutput, $Command);
while(<CommandOutput>)
{
$_ =~ s/(\n|\r\n)$//;
print "$_\n";
}
$|=0;
}
else # show output after command completes
{
print `$Command`;
}
if(!$WinNT)
{
alarm(0);
}
print "</xmp>";
}
#DIG
elsif($RunCommand =~ m/^\s*dig\s+(.+)/)
{
&PrintPageHeader("c");
#$Prompt = $WinNT ? "$CurrentDir> " : "[admin\@$ServerName $CurrentDir]\$ ";
$Prompt = $WinNT ? "$CurrentDir> " : "\$ ";
print "<code>$Prompt $RunCommand</code><xmp>";
$Command = "cd \"$CurrentDir\"".$CmdSep.$RunCommand.$Redirector;
if(!$WinNT)
{
$SIG{'ALRM'} = \&CommandTimeout;
alarm($CommandTimeoutDuration);
}
if($ShowDynamicOutput) # show output as it is generated
{
$|=1;
$Command .= " |";
open(CommandOutput, $Command);
while(<CommandOutput>)
{
$_ =~ s/(\n|\r\n)$//;
print "$_\n";
}
$|=0;
}
else # show output after command completes
{
print `$Command`;
}
if(!$WinNT)
{
alarm(0);
}
print "</xmp>";
}
#NSLOOKUP
elsif($RunCommand =~ m/^\s*nslookup\s+(.+)/)
{
&PrintPageHeader("c");
#$Prompt = $WinNT ? "$CurrentDir> " : "[admin\@$ServerName $CurrentDir]\$ ";
$Prompt = $WinNT ? "$CurrentDir> " : "\$ ";
print "<code>$Prompt $RunCommand</code><xmp>";
$Command = "cd \"$CurrentDir\"".$CmdSep.$RunCommand.$Redirector;
if(!$WinNT)
{
$SIG{'ALRM'} = \&CommandTimeout;
alarm($CommandTimeoutDuration);
}
if($ShowDynamicOutput) # show output as it is generated
{
$|=1;
$Command .= " |";
open(CommandOutput, $Command);
while(<CommandOutput>)
{
$_ =~ s/(\n|\r\n)$//;
print "$_\n";
}
$|=0;
}
else # show output after command completes
{
print `$Command`;
}
if(!$WinNT)
{
alarm(0);
}
print "</xmp>";
}
#HOST
elsif($RunCommand =~ m/^\s*host\s+(.+)/)
{
&PrintPageHeader("c");
#$Prompt = $WinNT ? "$CurrentDir> " : "[admin\@$ServerName $CurrentDir]\$ ";
$Prompt = $WinNT ? "$CurrentDir> " : "\$ ";
print "<code>$Prompt $RunCommand</code><xmp>";
$Command = "cd \"$CurrentDir\"".$CmdSep.$RunCommand.$Redirector;
if(!$WinNT)
{
$SIG{'ALRM'} = \&CommandTimeout;
alarm($CommandTimeoutDuration);
}
if($ShowDynamicOutput) # show output as it is generated
{
$|=1;
$Command .= " |";
open(CommandOutput, $Command);
while(<CommandOutput>)
{
$_ =~ s/(\n|\r\n)$//;
print "$_\n";
}
$|=0;
}
else # show output after command completes
{
print `$Command`;
}
if(!$WinNT)
{
alarm(0);
}
print "</xmp>";
}
#NMAP
elsif($RunCommand =~ m/^\s*nmap\s+(.+)/)
{
&PrintPageHeader("c");
#$Prompt = $WinNT ? "$CurrentDir> " : "[admin\@$ServerName $CurrentDir]\$ ";
$Prompt = $WinNT ? "$CurrentDir> " : "\$ ";
print "<code>$Prompt $RunCommand</code><xmp>";
$Command = "cd \"$CurrentDir\"".$CmdSep.$RunCommand.$Redirector;
if(!$WinNT)
{
$SIG{'ALRM'} = \&CommandTimeout;
alarm($CommandTimeoutDuration);
}
if($ShowDynamicOutput) # show output as it is generated
{
$|=1;
$Command .= " |";
open(CommandOutput, $Command);
while(<CommandOutput>)
{
$_ =~ s/(\n|\r\n)$//;
print "$_\n";
}
$|=0;
}
else # show output after command completes
{
print `$Command`;
}
if(!$WinNT)
{
alarm(0);
}
print "</xmp>";
}
#TRACEROUTE
elsif($RunCommand =~ m/^\s*traceroute\s+(.+)/)
{
&PrintPageHeader("c");
#$Prompt = $WinNT ? "$CurrentDir> " : "[admin\@$ServerName $CurrentDir]\$ ";
$Prompt = $WinNT ? "$CurrentDir> " : "\$ ";
print "<code>$Prompt $RunCommand</code><xmp>";
$Command = "cd \"$CurrentDir\"".$CmdSep.$RunCommand.$Redirector;
if(!$WinNT)
{
$SIG{'ALRM'} = \&CommandTimeout;
alarm($CommandTimeoutDuration);
}
if($ShowDynamicOutput) # show output as it is generated
{
$|=1;
$Command .= " |";
open(CommandOutput, $Command);
while(<CommandOutput>)
{
$_ =~ s/(\n|\r\n)$//;
print "$_\n";
}
$|=0;
}
else # show output after command completes
{
print `$Command`;
}
if(!$WinNT)
{
alarm(0);
}
print "</xmp>";
}
#WHOIS
elsif($RunCommand =~ m/^\s*whois\s+(.+)/)
{
&PrintPageHeader("c");
#$Prompt = $WinNT ? "$CurrentDir> " : "[admin\@$ServerName $CurrentDir]\$ ";
$Prompt = $WinNT ? "$CurrentDir> " : "\$ ";
print "<code>$Prompt $RunCommand</code><xmp>";
$Command = "cd \"$CurrentDir\"".$CmdSep.$RunCommand.$Redirector;
if(!$WinNT)
{
$SIG{'ALRM'} = \&CommandTimeout;
alarm($CommandTimeoutDuration);
}
if($ShowDynamicOutput) # show output as it is generated
{
$|=1;
$Command .= " |";
open(CommandOutput, $Command);
while(<CommandOutput>)
{
$_ =~ s/(\n|\r\n)$//;
print "$_\n";
}
$|=0;
}
else # show output after command completes
{
print `$Command`;
}
if(!$WinNT)
{
alarm(0);
}
print "</xmp>";
}
else
{
# Print PageHeaderBC that informs of non-functional command
&PrintPageHeaderBC("c");
}
&PrintCommandLineInputForm;
&PrintPageFooter;
}
調用子程序的標準方法是不** **領先符號:'PrintPageHeaderBC ( 「C」)'。 &符號調用樣式用於特定目的,詳見'perldoc perlsub'(http://perldoc.perl.org/perlsub.html)。 – FMc
感謝您的信息......代碼實際上來自我已修改的cgi-telnet。我相信這是在2001年寫的:)不知道他是否有這樣做的原因,所以我只保留了他使用的相同格式。 – twain
'cat/etc/password「|」' - 不包含管道命令,但我認爲它會通過正則表達式。 – Quentin