#!/usr/local/bin/perl
# 우리가 쓰고 있는 방명록이다.
# 부디 열심히 분석하여 빛이 될 수 있기를... 훌쩍. !_!
# 무단도용하면 두금이야. --;
# 일단 기본 변수 선언를 선언한다.
$LogFile = 'bbs.txt';
$max = 100;
$slip = "\x01";
$newline = "\x03";
%form = &init;
$name = $form{ 'name' };
$message = $form{ 'message' };
$url = $form{ 'url' };
$email = $form{ 'email' };
$command = $form{ 'command' };
$args = $form{ 'args' };
print "Content-type: text/plain\n\n";
# flash에서 wite 키를 누르면 이쪽이 실행된다. flash에서 command에 wite 값을 주어서 이쪽으로 보낸다.
if( $command eq 'write' )
{
if( $name eq '' || $message eq '' )
{
&view( 1 );
}
open( Log, "<$LogFile" );
@lines = <Log>;
close( Log );
# 새로운 데이터 추가하고,
$str = "$name$slip$message$slip$url$slip$email";
$str =~ s/\r\n/$newline/g;
$str =~ s/\n\r/$newline/g;
$str =~ s/\n/$newline/g;
$str =~ s/\r/$newline/g;
$str .= "\n";
push( @new, $str );
$i = 0;
foreach $line ( @lines )
{
$i++;
if ( $i == $max ) { last; }
push( @new, $line );
}
# 로그 파일에 변수 저장하고,
open( Log, ">$LogFile" );
print Log @new;
close( Log );
print "name=$name&message=$message&url=$url&email=$email&command=end";
exit;
}
# 로그 파일의 라인 최대값 변수에 입력하고.
if( $command eq 'max' )
{
open( Log, "<$LogFile" );
@lines = <Log>;
close( Log );
$i = 0;
foreach $line ( @lines )
{
$i++;
}
print "max=$i&command=end";
exit;
}
&view( $args );
# 기본 함수 설정하는 부분이다. --+
sub init
{
local ($buffer, @pairs, $pair, $name, $value, %FORM);
$ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;
if ( $ENV{'REQUEST_METHOD'} eq "POST" )
{
read( STDIN, $buffer, $ENV{'CONTENT_LENGTH'} );
}
else
{
$buffer = $ENV{'QUERY_STRING'};
}
@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;
$FORM{$name} = $value;
}
%FORM;
}
# 자, 여기가 중요해. flash에 변수를 전달하는 부분이야. 잘 보거라. --+
sub view
{
$mnum = $_[0];
open( Log, "<$LogFile" );
@lines = <Log>;
close( Log );
@lines = reverse( @lines );
$i = 0;
foreach $line ( @lines )
{
$i++;
if( $i == $mnum )
{
( $name, $message, $url, $email ) = split( /$slip/, $line );
$message =~ s/$newline/\n/g;
print "name=$name&message=$message&url=$url&email=$email";
last;
}
}
print "&command=end";
exit;
}
exit;
# 됐냐? 열심히 연구해 보고 수 시간 내에 응답 바란다.
# 다시금 말하지만 정말 별 거 없다.
# 여기처럼 command값이 정해지면 그쪽으로 이동시켜서 실행시키면 되고,
# flash로 값 보내는 것도 여기처럼 하면 된다.
# 행운을 빈다. !_!
#
# - achor Webs. achor
|
Please log in first to leave a comment.
|
|