CGI - Common Gateway Interface
Спецвыпуск хакер, номер #002, стр. 002-068-5
if ($page->param('new_user'))
{
my $rec = {};
my $now = time;
$rec->{'user'} = $page->param('new_user');
$rec->{'email'} = $page->param('new_email');
$rec->{'text'} = $page->param('new_text');
$comments{$now} = freeze $rec;
$page->param('new_user', "");
$page->param('new_email', "");
$page->param('new_text', "");
}
print $page->header, "\n";
if ($page->param('template'))
{
my $err = 0;
my $template = "$ENV{'DOCUMENT_ROOT'}/".$page->param('template');
open(TEMPLATE, $template) || do {$err = $!};
if ($err)
{
&display_default($template, $err);
}
else
{
while (<TEMPLATE>)
{
if (/!!FORM!!/)
{
&display_form;
}
elsif (/!!COMMENTS!!/)
{
&display_comments;
}
else
{
print;
}
}
}
}
else
{
&display_default;
}
sub display_form
{
print $page->start_form(-action=>'ms-guest.pl'), "\n";
print $page->hidden(-name=>'template', -value=>$page->param('template'))
if defined($page->param('template'));
print $page->hidden(-name=>'file', -value=>$file);
print $page->p('Your Name: ',
$page->textfield(-name=>new_user, -size=>30)), "\n";
print $page->p('Your Email: ',
$page->textfield(-name=>new_email,
-size=>30,
-default=>"$ENV{'USER'}\@$ENV{'REMOTE_HOST'}")), "\n";
print $page->p('Your Comments:',
$page->br,
$page->textarea(-name=>new_text,
-rows=>5, -cols=>50)), "\n";
print $page->submit(-value=>'Submit Entry'), "\n";
print $page->reset, "\n";
print $page->end_form, "\n";
}
sub display_comments
{
my ($k, $v);
my $comments = "";
my $then;
my $thing;
foreach $k (reverse sort keys %comments)
{
$v = $comments{$k};
$then = localtime $k;
($thing) = thaw($v);
$thing->{text} =~ s/</</;
$thing->{text} =~ s/\n/<BR>/;
$comments .= $page->p($page->strong($thing->{user}),
$page->em($then),
$page->br,
$page->a({-href=>"mailto:$thing->{email}"},
$thing->{email}),
$page->br,
$thing->{text})
. $page->hr . "\n";
}
print $comments;
}
sub display_default
{
print $page->start_html(-title=>'Guest Book'), "\n";
print $page->h1('Guest Book');
if (@_)
{
print $page->p("Can\'t open template: $_[0]. Error: $_[1]."), "\n";
}
&display_form;
print $page->hr, "\n";
&display_comments;
print $page->address('ms-guest v1.2',
$page->br,
'© 1998,',
$page->a({href=>'http://www.mag-sol.com'},