Chr*_*rus 3 html apache perl cgi
我正在使用以下代码连接到运行HTML页面的服务器:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta name="generator" content=
"HTML Tidy for Linux/x86 (vers 1st February 2005), see www.w3.org">
<title>Calculator</title>
<link type="text/css" rel="stylesheet" href="mystyle.css">
</head>
<body>
<h1>Calculator</h1>
<p>This is a calculator form that uses a CGI script.</p>
<form method="post" action="./cgi-bin/badcalc.pl">
Expression <input type="text" name="exp" size="10">
<input type="submit" value="Calculate">
<input type="reset">
</form><br>
<p>The cgi script that does the calculation may be viewed <a href=
"cgi-bin/code2html.pl?file=badcalc.pl">here</a>.</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这链接到包含代码的Perl文件:
#!/usr/bin/perl
use strict;
use warnings;
use Safe; #using Sandbox
use CGI;
use HTML::Entities; #For encoding the output
my $query = new CGI;
my $exp = $query->param('exp');
print $query->header,
$query->start_html(-title=>'Fixed calculator',
-style=>{'src' => '../mystyle.css'},
-target=>'_blank'),
$query->h1('Fixed calculator');
my $compartment = Safe->new();
##Defining a new sandbox
$compartment->permit_only(qw(atan2 sin cos exp log sqrt :default )); #Defines te functions that are permitted for execution
my $result = $compartment->reval($exp) or die("Error: ".$@);
#Execute the calculation, if input is trapped or an error occurs, die and print to log
if (defined $result)
{
print "<br> ".encode_entities($exp)." = " encode_entities($result).""; ##Encodes the output to ensure that there is no problems on the page
}else
{
print "<br> Oh dear! That input is not allowed or has been incorrectly formatted.\n"; #Makes error message suitable
}
print $query->end_html;
Run Code Online (Sandbox Code Playgroud)
与旧版本(使用eval()而不是reval())相比,这应该执行简单的计算并提供更高的安全性,但是当我尝试执行像1 + 1这样的简单计算时,它会带回内部服务器错误并且来自错误的日志位于下方.
Can't locate HTML/Entities.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at /home/1001542/public_html/cgi-bin/badcalc.pl line 10. BEGIN failed--compilation aborted at /home/1001542/public_html/cgi-bin/badcalc.pl line 10. [Mon May 06 10:58:05 2013] [error] [client 10.0.0.25] Premature end of script headers: badcalc.pl, referer: http://10.0.0.3/~1001542/calc.html
Run Code Online (Sandbox Code Playgroud)
第10行是"使用HTML :: Entities;".
有帮助吗?
**编辑** 原始的Perl文件工作得很好奇怪.码:
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
my $query = new CGI;
my $exp = $query->param('exp');
print $query->header,
$query->start_html(-title=>'Broken calculator',
-style=>{'src' => '../mystyle.css'},
-target=>'_blank'),
$query->h1('Broken calculator');
my $result = eval($exp);
if (defined $result)
{
print "<br> $exp = $result";
}else
{
print "<br> oops! $@";
}
print $query->end_html;
Run Code Online (Sandbox Code Playgroud)
再次编辑** 我使用我大学提供的服务器来做这个,但现在已经在我自己的虚拟机的apache服务器上进行了设置.如果我解决它,我会回复所有人.
Chr*_*rus 12
我设法自己排序.
当我使用我大学提供的服务器时,我没有权限安装所需的模块(HTML :: Entities).
我决定然后在我自己的Apache Web服务器上在虚拟机上设置所需的模块,并在整理出一些语法/拼写错误后设法让它以这种方式工作.
我安装HTML :: Entities模块的方式是通过synaptic包管理器,只需搜索libhtml-parser-perl就可以找到并安装模块.我重新启动了Apache和VM,以防万一.
感谢大家的投入!
归档时间: |
|
查看次数: |
10406 次 |
最近记录: |