picbbs¾Æ½ÃÁÒ?
¹ØÀº post.cgiÀÔ´Ï´Ù.
ÀÌ°Ç picbbs(¿À¿¡Ä«Å°?¶óÄíÄ«Å°?)¿¡¼ ±×¸²À» ÀúÀåÇϸé ó¸®ÇØÁÖ´Â
ÆÄÀÏÀä..
ÆÄÀÏÀ̸§À» »ç¿ëÀÚ ÀÓÀÇ·Î ÁöÁ¤ÇÒ¼ö ÀÖµµ·Ï µµ¿ÍÁÖ¼¼¿ä.
ºÎŹµå¸³´Ï´Ù.
#!/usr/bin/perl
# ¼³Ä¡ÇÒ ¼¹öÀÇ ÆÞ °æ·Î.
#-DON
T REMOVE>>-----------------------------------------------------
# Picuture BBS - Read PNG File Program ($Revision: 1.1 $)
# Copyright (C) Yasuo OHNO , 2000
# All rights reserved.
# »ó¼¼ÇÑ »ç¿ë Á¶°Ç¡¤»ç¿ë ¹æ¹ýµîÀº ¾Æ·¡ÀÇ »çÀÌÆ®¸¦ ÂüÁ¶ÇϽʽÿÀ£®
# - SCENERY AND FISH - http://www16.cds.ne.jp/~ohno/
# - ÇȻߺñ¿¡¾¥ - http://picbbs.com (ÇѱÛÆÇ ¹èÆ÷»çÀÌÆ®)
#-----------------------------------------------------<< DON
T REMOVE -
#----------------------------------------------------------------------
# Á¤¼ö
#----------------------------------------------------------------------
# ¿¡·¯ ÄÚµå
$ERR_FATAL =
000
;
$ERR_LOCK =
001
;
$ERR_BUSY =
002
;
$ERR_PNGSIZE =
003
;
$ERR_MSGSIZE =
004
;
$ERR_PASSWORD =
005
;
$ERR_PERM =
006
;
#----------------------------------------------------------------------
# ÃʱâÈ
#----------------------------------------------------------------------
$maketemp = 0;
#----------------------------------------------------------------------
# main
#----------------------------------------------------------------------
# ¼³Á¤ ÆÄÀÏÀÇ Àбâ
require
config.cgi
;
binmode(STDIN);
_putappheader();
# POST ÇÏ¿© ¿À´Â È£½ºÆ®ÀÇ È®ÀÎ
if (! _checkhost()) {
nack($ERR_PERM);
}
$content_length = $ENV{
CONTENT_LENGTH
};
if ($content_length < 8) {
nack($ERR_FATAL);
}
if (read(STDIN, $ext, 3) != 3) {
nack($ERR_FATAL);
}
$content_length -= 3;
if (read(STDIN, $pngsize, 8) != 8) {
nack($ERR_FATAL);
}
$content_length -= 8;
$pngsize = int($pngsize);
if ($pngsize > $g_pngmax) {
nack($ERR_PNGSIZE);
}
if (($content_length - $pngsize) > $g_msgmax) {
nack($ERR_MSGSIZE);
}
if ($pngsize > $content_length) {
nack($ERR_FATAL);
}
if (! _lock()) {
nack($ERR_LOCK);
}
$pngtemp = _gettemporarily();
_unlock();
if (! receive_png_file($pngtemp, $pngsize)) {
nack($ERR_FATAL);
}
$content_length -= $pngsize;
binmode(STDIN);
if (! _parseform($content_length)) {
nack($ERR_FATAL);
}
# ÀÔ·ÂÄ¡ÀÇ È®ÀÎ
if ($FORM{
PASSWORD
} eq
) {
nack($ERR_PASSWORD);
}
if (! _lock()) {
nack($ERR_LOCK);
}
# Àбâ Ãø ¿ÀÇÂ
if (! open(LOGIN, $g_logfile)) {
nack($ERR_FATAL);
}
# ¾²±â Ãø ¿ÀÇÂ
if (! open(LOGOUT,
>
. $g_logtemp)) {
nack($ERR_FATAL);
}
# Çì´õ Àбâ
$in = ;
chomp($in);
($nextbase, $nextpng) = split(/ /, $in);
if ($nextbase == 0 || $nextpng == 0) {
nack($ERR_FATAL);
}
# Çì´õ ¾²±â
$basenum = $nextbase++;
$pngfile = sprintf("%d." . $ext, $nextpng++);
$password= _crypt($FORM{
PASSWORD
});
$timestr = _gettimestr(_time());
$remote = _getremoteaddress();
print LOGOUT $nextbase . " " . $nextpng . "
";
# picture ÇàÀÇ ±âÀÔ
print LOGOUT "${basenum} 0 ${pngfile} 0 ${password} ${remote} ${timestr}
";
# Àб⠾²±â ·çÇÁ
$count = 1;
READWRITE_LOOP: while () {
($current) = split(/ /, $_);
if ($basenum != $current) {
$basenum = $current;
$count++;
if ($count > $g_logmax) {
last READWRITE_LOOP;
}
}
print LOGOUT $_;
}
close(LOGOUT);
# PNG ÆÄÀÏ ¼Ò°Å ·çÇÁ
if ($count > $g_logmax) {
do {
($basenum, $mode, $removefile) = split(/ /, $_);
if ($basenum != 0 && $mode == 0) {
unlink "$g_pngwdir/$removefile";
}
} while ();
}
close(LOGIN);
if (! rename($g_logtemp, $g_logfile)) {
sleep(1);
if (! rename($g_logtemp, $g_logfile)) {
# ¿©±â¿¡¼ ½ÇÆÐÇÏ¸é ¿À·¡µÈ ±×¸²À» Áö¿î´Ù. ·Î±×´Â ³²À½.
nack($ERR_FATAL);
}
}
if (! rename($pngtemp, $g_pngwdir .
/
. $pngfile)) {
sleep(1);
if (! rename($pngtemp, $g_pngwdir .
/
. $pngfile)) {
# ¿©±â¿¡¼ ½ÇÆÐÇÑ´Ù¸é ±×¸²Àº ÇÒ¼ö ¾ø°í ±×¸²ÀÇ ±â»ç¸¸ ÇÒ¼ö ÀÖÀ½.
nack($ERR_FATAL);
}
}
_unlock();
print "ACK
";
exit 0;
#----------------------------------------------------------------------
# ¿¡·¯ Á¾·á
#----------------------------------------------------------------------
# argument:
# 0 - ¿¡·¯ ÄÚµå
sub nack {
remove_tempfile();
_unlock();
print "NACK $_[0]
";
exit 0;
}
#----------------------------------------------------------------------
# PNG ÆÄÀÏÀÇ ¼ö½Å
#----------------------------------------------------------------------
# argument:
# 0:$filename - ÆÄÀÏ À̸§
# 1:$size - ÆÄÀÏ »çÀÌÁî
sub receive_png_file {
# my $filename = $_[0];
my $filename = $_[0];
my $size = $_[1];
my $buffer;
if (! open(TEMPOUT, ">$filename")) {
return 0;
}
binmode(TEMPOUT);
$maketemp = 1;
$tempfile = $filename;
while ($size > 0) {
# Àб⠻çÀÌÁîÀÇ °áÁ¤
if ($size > 4096) {
$readsize = 4096;
}
else {
$readsize = $size;
}
# Àбâ
if (read(STDIN, $buffer, $readsize) != $readsize) {
close(TEMPOUT);
return 0;
}
$size -= $readsize;
# ¾²±â
if (! print TEMPOUT $buffer) {
close(TEMPOUT);
return 0;
}
}
close(TEMPOUT);
return 1;
}
#----------------------------------------------------------------------
# Àӽà ÆÄÀÏÀÇ ÈÄ Ã³¸®
#----------------------------------------------------------------------
# memo:
# Àӽà ÆÄÀÏÀÌ ÀÛ¼ºµÇ°í ÀÖ´Ù¸é »èÁ¦ÇÕ´Ï´Ù£®
sub remove_tempfile {
if ($maketemp) {
unlink $tempfile;
$maketemp = 0;
}
}
#----------------------------------------------------------------------
# Á¾·á ·çƾ
#----------------------------------------------------------------------
END {
remove_tempfile();
}
Ȥ½Ã ÇÊ¿äÇÒ±îºÁ config.cgiµµ ³Ö½À´Ï´Ù.
#-DON
T REMOVE>>-----------------------------------------------------
# Picuture BBS - Read PNG File Program ($Revision: 1.1 $)
# Copyright (C) Yasuo OHNO , 2000
# All rights reserved.
# »ó¼¼ÇÑ »ç¿ë Á¶°Ç¡¤»ç¿ë ¹æ¹ýµîÀº ¾Æ·¡ÀÇ »çÀÌÆ®¸¦ ÂüÁ¶ÇϽʽÿÀ£®
# - SCENERY AND FISH - http://www16.cds.ne.jp/~ohno/
# - ÇȻߺñ¿¡¾¥ - http://picbbs.com (ÇѱÛÆÇ ¹èÆ÷»çÀÌÆ®)
#-----------------------------------------------------<< DON
T REMOVE -
#----------------------------------------------------------------------
# Çʼö ¼³Á¤ Ç׸ñ
#----------------------------------------------------------------------
# memo:
# ÀÌ ¾Æ·¡ÀÇ ¼³Á¤Àº ¹Ýµå½Ã ¼³Ä¡ÇÑ È¯°æ¿¡ ¸ÂÃç ¼³Á¤ÇØ Ã£¾Æ ¿À°í Âõ°í£®
# ȨÀ¸·Î ¹öÆ°À» ´·¶À» ¶§ÀÇ URL
$g_returnurl =
../../index.htm
;
#----------------------------------------------------------------------
# ȯ°æ ¼³Á¤(À̺κÐÀÌ ¸¹ÀÌ ´Þ¶óÁ³½À´Ï´ç~^^)
#----------------------------------------------------------------------
# memo:
# ¼³Á¤ Ç׸ñÁß È¯°æ °ü°èÀÇ ¼³Á¤ °ªÀÔ´Ï´Ù£®
# ±âÈ£¿¡ ¸ÂÃç ¼³Á¤ÇϽʽÿÀ£®
# °Ô½ÃÆÇÀÇ Å¸ÀÌƲ
$g_title = "";
# °Ô½ÃÆÇ Å¸ÀÌƲÀÇ ±×·¡ÇÈ
# ÇÊ¿ä°¡ ¾ø´Â °æ¿ì´Â £¬
À¸·Î ±×³É µÎ¼¼¿ä^^.
$g_titlegraphic =
; # ŸÀÌƲ ±×¸²ÀÇ URL
$g_titlegwidth =
; # ŸÀÌƲ ±×¸²ÀÇ °¡·ÎÆø(¿¹:300Çȼ¿=300À¸·Î Ç¥±â)
$g_titlegheight =
; # ŸÀÌƲ ±×¸²ÀÇ ¼¼·ÎÆø
# °Ô½ÃÆÇÀÇ »ó´Ü¿¡ µé¾î°¥ ¹®±¸
# º¸ÅëÀÇ °æ¿ì.
$g_topmessage = <<_EOS;
±×¸±°Å¾ß? <(-_-)/ ±×¸®°í µ¹¾Æ¿À¸é F5¸¦ ²Ù¿í! ´·¯¼ °»½ÅÀ»!
--------------------------------------------------------------------------------
_EOS
# °Ô½ÃÆÇÀÇ »ö
$g_bgcolor = "white"; # ¹è°æ »ö
$g_titlebg = "white"; # ÀÛ°¡ ÄÚ¸àÆ®ÀÇ Å¸ÀÌƲÀÇ ¹è°æ »ö
$g_titlefg = "#aaaaaa"; # ÀÛ°¡ ÄÚ¸àÆ®ÀÇ Å¸ÀÌƲÀÇ ¹®ÀÚ »ö
$g_commentbg = "white"; # ÄÚ¸àÆ®ÀÇ Å¸ÀÌƲÀÇ ¹è°æ »ö
$g_commentfg = "#aaaaaa"; # ÄÚ¸àÆ®ÀÇ Å¸ÀÌƲÀÇ ¹®ÀÚ »ö
$g_textcolor = "#aaaaaa"; # ÄÚ¸àÆ®ÀÇ ¹®ÀÚ »ö
$g_linkcolor = "#cccccc"; # ¸µÅ©ÀÇ »ö
$g_vlinkcolor= "#cccccc"; # ¸µÅ©ÀÇ »ö
$g_alinkcolor= "#cccccc"; # ¸µÅ©ÀÇ »ö
$g_headercolor="#cccccc"; # ±×¸²ÀÇ Çì´õÀÇ »ö
# °Ô½ÃÆÇÀÇ ¹è°æ À̹ÌÁöÀÇ URL
# ÇÊ¿ä°¡ ¾ø´Â °æ¿ì´Â £¬
À¸·Î µÎ¼¼¿ä^^
$g_bggraphic1 =
; # °Ô½ÃÆÇ ¿¶÷ ȸé
$g_bggraphic2 =
; # ÄÚ¸àÆ® ±âÀÔ È¸é
$g_bggraphic3 =
; # ±×¸®±â ȸé
# ¾ÖÇø´ÀÇ »ö
# ±×¸²À» ±×¸®´Â ¾ÖÇø´ÀÇ À©µµ¿ìÀÇ »öÀ̶óµç°¡ ¹è°æ»öÀ» ÁöÁ¤ÇÕ´Ï´Ù£®
$g_appcolor = "white"; # ÀÛ¾÷ Áö¿ªÀÇ »ö
$g_captioncolor = "#aaaaaa"; # ÇÁ·¹ÀÓÀÇ ¹ÙÀÇ »ö
$g_windowcolor = "#efefef"; # À©µµ¿ìÀÇ »ö
# ¾ÖÇø´ÀÇ »çÀÌÁî
# ³Ê¹« Å©°Ô ÇÑ´Ù¸é ¸®¼Ò½º¸¦ Áö³ªÄ¡°Ô ¾²°í µ¿ÀÛÀÌ ºÒ¾ÈÁ¤ÇÏ°Ô µÇ°Å³ª ÇÕ´Ï´Ù
# ¼³Á¤À» º¯°æÇÑ °æ¿ì´Â ½ÅÁßÈ÷£®
$g_appwidth = 600; # °¡·Î ³ªºñ
$g_appheight= 400; # Á¾Æø
# IP addressÀÇ Ç¥½Ã
# 0 - IP address¸¦ ÀÏü Ç¥½ÃÇÏÁö ¾Ê´Ù(·Î±×¿¡´Â ±â·ÏµË´Ï´Ù)
# 1 - IP address¸¦ ÄÚ¸àÆ®¿¡¼ HTML¿¡ ³Ö´Ù(
¼Ò½ºº¸±â
ÇÏ¸é º¸ÀÔ´Ï´Ù)
# 2 - IP address¸¦ Ç¥½ÃÇÕ´Ï´Ù
$g_viewaddress = 1;
# £± ÆäÀÌÁö¿¡ Ç¥½ÃÇÑ ±×¸²ÀÇ ¸Å¼ö
# ±×´ÙÁö(³Ê¹«) Å« ¼öÄ¡¸¦ ÁöÁ¤ÇÑ´Ù¸é Ç¥½Ã°¡ ´Ê¾îÁö±â¶§¹®¿¡ °¡´ÉÇÑ ÇÑ Àû°Ô Àâ¾Æ ÁÖ¼¼¿ä£®
$g_pagemax = 8;
# ±×¸²ÀÇ »çÀÌÁî·Î¼ Çã¿ëÇÑ »çÀÌÁî
# ¼±µÎÀÇ °ªÀÌ µðÆúÆ®·Î ¼³Á¤µÈ »çÀÌÁîÀÔ´Ï´Ù£®
@g_picwidth = (
300
,
100
,
200
,
300
,
400
);
@g_picheight = (
300
,
100
,
200
,
300
,
400
);
#----------------------------------------------------------------------
# ±âº» ¼³Á¤
#----------------------------------------------------------------------
# memo:
# ±âº»ÀûÀÎ ¼³Á¤ Ç׸ñÀÔ´Ï´Ù£®Àû´çÈ÷ º¯°æÇϽʽÿÀ£®
# jcode.pl ÀÇ °æ·Î
$g_jcode =
./jcode.pl
;
# ÃÖ´ë ·Î±× ¼ö
# ÃÖ´ë·Î ¸î °ÇÀÇ ·Î±×¸¦ ³²°Ü µÎ´ÂÁö¸¦ ÁöÁ¤ÇÕ´Ï´Ù£®
# ÀÌ°Í¿¡´Â ±âÀÔ¿¡ ´ëÇÑ ÄÚ¸àÆ®´Â Æ÷ÇÔµÇÁö ¾Ê½À´Ï´Ù£®
# ÀÌ°ÍÀ» ³Ñ¾î°£ ºÎºÐÀº ±×¸²¡¤ÄÚ¸àÆ® µ¿½Ã¿¡ »èÁ¦µË´Ï´Ù£®
$g_logmax = 40;
# ÃÖ´ë ¸Þ½ÃÁö »çÀÌÁî
# ³Ê¹« ±ä ÄÚ¸àÆ®¸¦ Á¢¼öÇÏ°í ½ÍÁö ¾Ê´Â °æ¿ì´Â ÀÌ°ÍÀ» Á¶ÀýÇϽʽÿÀ£®
$g_msgmax = 4096;
# ÃÖ´ë È»ó Åõ°í »çÀÌÁî
# Åõ°í½Ã¿¡ Á¢¼öÇÑ È»ó ÆÄÀÏ(PNG)ÀÇ ÃÖ´ë »çÀÌÁîÀÔ´Ï´Ù£®
$g_pngmax = 270057;
# µðÆúÆ®·Î JPEG ½ºÀ§Ä¡¸¦ ONÀ¸·Î ÇÔ
# ÀÌ °ªÀ» true ·ÎºÎÅÍ false ·Î º¯°æÇÑ´Ù¸é µðÆúÆ®·Î JPEG ½ºÀ§Ä¡°¡
# OFF°¡ µÇ¾î£¬¹Ýµå½Ã PNG Çü½ÄÀ¸·Î ¼¼À̺êµË´Ï´Ù£®
$g_usejpeg =
true
;
# ÄÚ¸àÆ®¸¦ ºÙÀ϶§ ŸÀÌƲ ÀԷ¶õ °¨Ãß±â(±×³É À̸§°ú Àǰ߸¸ Ãâ·Â...)
# ÀÌ °ªÀ» 0 À¸·Î ÇÏ¸é £¬ÄÚ¸àÆ®¸¦ ºÙÀÏ ¶§¿¡ ŸÀÌƲ ÀԷ³ÀÌ Ãâ·ÂµÇÁö ¾Ê°Ô µË´Ï´Ù.
$g_usecommenttitle = 1;
# ÄÚ¸àÆ®ÀÇ Å¸ÀÌƲÀ» ÇʼöÀÔ·ÂÇÏ°Ô Çϱâ
# ÀÌ °ªÀ» 1·Î ÇÏ¸é £¬ÄÚ¸àÆ®¸¦ ºÙÀÏ ¶§¿¡ ŸÀÌƲÀÌ ÇʼöÇ׸ñÀÌ µË´Ï´Ù£®
$g_needcommenttitle = 0;
# lock ÀÇ ¹æ¹ý
# 0 ... symlink/unlink
# 1 ... mkdir/rmdir
# 2 ... flock(̵̧)
# flock ÀÌ(°¡) »ç¿ëÇÒ ¼ö ÀÖ´Â ¼¹ö·Î´Â 2 À»(¸¦) ÁöÁ¤
# symlink ÀÌ(°¡) »ç¿ëÇÒ ¼ö ¾ø´Â ¼¹ö·Î´Â 1 À»(¸¦) ÁöÁ¤£®
# ÁÖÀÇ£º¼³Ä¡ÈÄ¿¡ ÀÌ °ªÀ» º¯°æÇÑ °æ¿ì´Â £¬data µð·ºÅ丮¼ÓÀÇ
# lock À̶ó´Â ÆÄÀÏÀ» »èÁ¦ÇÏ°í ³ª¼ º¯°æÇÑ °Í£¡
$g_lockmethod = 2;
# lock À»(¸¦) ½ÃµµÇØ º¸´Â ȸ¼ö
$g_trylock = 3;
# JavaARchive À»(¸¦) µÎ´Â µð·ºÅ丮
$g_codebase = "./";
# JavaARchive ÀÇ À̸§
$g_jarfile = "PicApp.jar";
# È»ó Åõ°íÈÄ¿¡ À̵¿ÇÒ ¶§ÀÇ Å¸°Ù
$g_movetarget = "_self";
# ±×¸²À̳ª ·Î±× µ¥ÀÌÅ͸¦ µÎ´Â µð·ºÅ丮
# Åë»ó ÀüºÎ µ¿ÀÏÇÏ°Ô ÇØ ÁֽʽÿÀ£®
$g_datadir =
data
; # log.cgi lock À»(¸¦) ±âÀÔÇÑ Àå¼Ò
$g_pngrdir =
data
; # IMG ű׷ΠÁöÁ¤ÇÏ´Â pngÀÇ µð·ºÅ丮
$g_pngwdir =
data
; # post.cgi °¡ ±âÀÔÇÏ´Â pngÀÇ µð·ºÅ丮
# ·Ï ÆÄÀÏ
$g_lockfile = "${g_datadir}/lock";
# png ÆÄÀÏÀÇ tempÆÄÀÏ À̸§
$g_pngtempform = "${g_pngwdir}/png%d.tmp";
# log ÆÄÀÏ°ú templogÆÄÀÏ
$g_logfile = "${g_datadir}/log.cgi";
$g_logtemp = "${g_datadir}/logtmp.cgi";
# °ü¸®ÀÚ Æнº ¿öµå ÆÄÀÏ
$g_passfile = "admpwd.cgi";
# ÄíÅ°¸¦ µðÆúÆ®·Î »ç¿ëÇϵµ·Ï ÇÕ´Ï´Ù£®
$g_cookiedefaultuse = 1;
# CGI ÆÄÀÏÀÇ Æнº
# º¹¼öÀÇ °Ô½ÃÆÇÀ» ¼³Ä¡ÇÏ°í ÀÖ°í cookie¸¦ °ø¿ëÇÏ°í ½ÍÀº °æ¿ì¿¡ ¼³Á¤À» º¯°æÇϽʽÿÀ£®
# Åë»ó£¬_basepath() ·Î ÀÚµ¿ÀûÀ¸·Î ¼³Á¤µË´Ï´Ù£®
# ex)
# $g_cookiepath =
/~myid/cgi-bin/picbbs
;
$g_cookiepath = _basepath();
# ÄíÅ°ÀÇ À̸§
$g_cookiename =
bykal_com_PicBBS
;
# ÄíÅ°·Î ±â¾ïÇÑ ÆûÀÇ ¸íĪ
@g_cookies = (
NAME
,
URL
,
MAIL
,
PASSWORD
,
USECOOKIE
);
# ÄíÅ°ÀÇ À¯È¿ ±â°£
# Àϼö¿¡ ÁöÁ¤ÇÕ´Ï´Ù£®10 À̶ó¸é 10ÀÏ°£ À¯È¿
$g_cookieexpires = 10;
# ÇØ¿Ü ¼¹ö·Î localtime¿¡ ÀϺ»°ú ¿ÀÂ÷°¡ ÀÖ´Â ¼¹öÀÇ °æ¿ì¿¡ ¼³Á¤ÇÏ´Ù
# -9½Ã »çÀ̶ó¸é 9 * 60 * 60 = 32400
$g_tz = 0;
# ½Å±Ô ÀÛ¼ºµÈ ÆÄÀÏÀÇ Çã°¡ MASK
# ÀÛ¼ºµÈ ÆÄÀÏÀÌ nobody:nobody µÇ´Ù 0000
# ÀÛ¼ºµÈ ÆÄÀÏÀÌ nobody: µÇ´Ù 0002
# ÀÛ¼ºµÈ ÆÄÀÏÀÌ : µÇ´Ù 0022
# À§ÀÇ £³ Á¾·ùÀÇ ¼³Á¤ÀÇ ¾î´À °ÍÀÌ¶óµµ ¿î¿ëÀº °¡´ÉÇÕ´Ï´Ù£®
# º¸¾ÈÀ» Á¶±ÝÀÌ¶óµµ Çâ»ó½ÃÅ°°í ½ÍÀº °æ¿ì 0022 ¼ÂÊ°ú ÁÖ¼¼¿ä£®
# ´Ü, ±× °æ¿ì °Ô½ÃÆÇÀ» »èÁ¦ÇÑ ¶§¿¡ ¹®Á¦·Î µÉ °¡´É¼ºÀÌ ÀÖ½À´Ï´Ù£®
$g_umask = 0000;
# ¸Å´º¾óÀÇ URL
$g_manurl =
http://ezgraphics.net/manual.htm
;
# µ¿ÀÛ È¯°æÀÇ URL
$g_infourl =
http://ezgraphics.net/info.htm
;
#----------------------------------------------------------------------
# »óȲ
#----------------------------------------------------------------------
# Çì´õ Ãâ·Â ³¡³ª°í Ç÷¡±×
$g_header = 0;
# ·Ï ³¡³ª°í Ç÷¡±×
$g_locked = 0;
#----------------------------------------------------------------------
# ÃʱâÈ
#----------------------------------------------------------------------
require $g_jcode;
umask $g_umask;
return 1;
#----------------------------------------------------------------------
# °øÅë ¼ºê·çƾ
#----------------------------------------------------------------------
# ¸®¸ðÆ® È£½ºÆ®ÀÇ È®ÀÎ
#----------------------------------------------------------------------
# return:
# 1 À̸é Åõ°í °¡´É£®0 À̸é Åõ°í ºÒ°¡´É£®
# memo:
# ¾î¶² ÀÌÀ¯·Î ±×¸²Åõ°í¸¦ ¸·°í ½ÍÀº °æ¿ì¿¡ »ç¿ëÇÕ´Ï´Ù£®
# °Ô½ÃÆÇÀ» ¾û¸ÁÀ¸·Î ÇѴٰųª ·Î±×ÀÌ»óÀÇ °Ô½ÃÆÇ º¸Á¸½Ã¿¡...
sub _checkhost {
## ÁöÁ¤ÇÑ URL ÀÌ¿Ü¿¡¼ÀÇ Åõ°íÀÇ ±ÝÁö
# if ($ENV{
HTTP_REFERER
} ne
http://www.server.com/~me/picbbs/write.html
) {
# return 0;
# }
## ÁöÁ¤ÇÑ È£½ºÆ®·ÎºÎÅÍÀÇ Åõ°íÀÇ ±ÝÁö
# my $ip = _getremoteaddress();
# if ($ip =~ /^192.168.1./) {
# return 0;
# }
# if ($ip =~ /provider.ne.jp$/) {
# return 0;
# }
return 1;
}
#----------------------------------------------------------------------
# °ü¸® ¸ðµå ¸®¸ðÆ® È£½ºÆ®ÀÇ È®ÀÎ
#----------------------------------------------------------------------
# return:
# 1 ÀÌ¸é °ü¸® ¸ðµå »ç¿ë °¡´É£®0 ÀÌ¸é °ü¸® ¸ðµå »ç¿ë ºÒ°¡´É£®
# memo:
# °ü¸® ¸ðµåÇϴ ȣ½ºÆ®ÀÇ Ã¼Å©¸¦ ÇÕ´Ï´Ù£®
# º¸¾È»ó °ü¸®¸ðµå¸¦ ÇÒ ¼ö Àִ ȣ½ºÆ®¸¦ Á¦ÇÑÇÕ´Ï´Ù£®
# °¡´ÉÇÏ¸é °ü¸®ÀÚ°¡ ¾×¼¼½ºÇÒ °¡´É¼ºÀÌ Àִ ȣ½ºÆ®¸¸ Çã°¡Çϼ¼¿ä.
sub _admcheckhost {
## ÁöÁ¤ÇÑ URL ÀÌ¿Ü¿¡¼ÀÇ °ü¸® ¸ðµå »ç¿ëÀÇ ±ÝÁö
# if ($ENV{
HTTP_REFERER
} ne
http://www.server.com/~me/picbbs/write.html
) {
# return 0;
# }
## ÁöÁ¤ÇÑ È£½ºÆ®·ÎºÎÅÍÀÇ °ü¸® ¸ðµå »ç¿ëÀÇ ±ÝÁö
# my $ip = _getremoteaddress();
# if ($ip =~ /^192.168.1./) {
# return 0;
# }
# if ($ip =~ /provider.ne.jp$/) {
# return 0;
# }
return 1;
}
#----------------------------------------------------------------------
# ¸®¸ðÆ® È£½ºÆ®ÀÇ Ãëµæ
#----------------------------------------------------------------------
# return:
# ¾×¼¼½ºµÈ È£½ºÆ®ÀÇ Ãëµæ
# memo:
# ±â·ÏµÈ addressÀÇ Ãëµæ
sub _getremoteaddress {
my $result;
# REMOTE_HOST ÀÇ ±â·Ï
if ($ENV{
REMOTE_HOST
} eq
) {
$result = $ENV{
REMOTE_ADDR
};
} else {
$result = $ENV{
REMOTE_HOST
};
}
# gethostbyaddress À» »ç¿ëÇÏ°í È£½ºÆ® À̸§À» ±¸ÇÏ°í ±×°ÍÀ» ±â·Ï
if ($result eq $ENV{
REMOTE_ADDR
}) {
$result = gethostbyaddr(pack(
C4
,split(/./,$result)),2) || $ENV{
REMOTE_ADDR
};
}
# PROXY ÀÇ ÃÖÁ¾ Àü¼Ûó¸¦ Ãß°¡
if ($ENV{
HTTP_X_FORWARDED_FOR
} ne
) {
$result .=
-
. $ENV{
HTTP_X_FORWARDED_FOR
};
}
return $result;
}
#----------------------------------------------------------------------
# remote address ÀÇ Ãâ·Â
#----------------------------------------------------------------------
# argument:
# 0:$remote - remote address
sub _putremoteaddress {
my $remote = $_[0];
if ($g_viewaddress == 1) {
_printsjis("");
} elsif ($g_viewaddress == 2) {
_printsjis("${remote}");
}
}
#----------------------------------------------------------------------
# HTML Çì´õÀÇ Ãâ·Â
#----------------------------------------------------------------------
# memo:
# HTML ÀÇ Çì´õ¸¦ Ãâ·ÂÇÕ´Ï´Ù£®
sub _puthtmlheader {
if (! $g_header) {
print "Content-type: text/html; charset=euc-kr
";
$g_header = 1;
}
}
#----------------------------------------------------------------------
# text/plain Çì´õÀÇ Ãâ·Â
#----------------------------------------------------------------------
# memo:
# ÅؽºÆ® ŸÀÔÀÇ Çì´õ¸¦ Ãâ·ÂÇÕ´Ï´Ù£®
sub _puttextheader {
if (! $g_header) {
print "Content-type: text/plain
";
$g_header = 1;
}
}
#----------------------------------------------------------------------
# application/octet-stream Çì´õÀÇ Ãâ·Â
#----------------------------------------------------------------------
# memo:
# ÅؽºÆ® ŸÀÔÀÇ Çì´õ¸¦ Ãâ·ÂÇÕ´Ï´Ù£®
sub _putappheader {
if (! $g_header) {
print "Content-type: application/octet-stream
";
$g_header = 1;
}
}
#----------------------------------------------------------------------
# ´Ù¸¥ ÆäÀÌÁö·Î °©´Ï´Ù.
#----------------------------------------------------------------------
# argument:
# 0:$url - ·ÎÄÉÀ̼Ç
sub _location {
my $url = $_[0];
if (! $g_header) {
print "Location: $url
";
} else {
_printsjis("ÀÌ°÷À¸·ÎÀ̵¿ÇØ ÁÖ¼¼¿ä
");
}
}
#----------------------------------------------------------------------
# ¿¡·¯ Á¾·á
#----------------------------------------------------------------------
# argument:
# 0:$errtitle - ¿¡·¯ Ç¥½ÃÀÇ Å¸ÀÌƲ
# 1:$errmessage - ¿¡·¯ Ç¥½Ã
# memo:
# ¿¡·¯ Ãâ·ÂÈÄ¿¡ exit ÇÕ´Ï´Ù£®
sub _errorend {
my ($errtitle, $errmessage) = @_;
_unlock();
_puthtmlheader();
_printsjis("
");
_printsjis("
$errtitle
");
_printsjis($errmessage);
_printsjis("
");
exit 0;
}
#----------------------------------------------------------------------
# ½Ã°¢ÀÇ Ãëµæ
#----------------------------------------------------------------------
# return:
# GMT ·ÎºÎÅÍÀÇ °æ°ú Ãʼö
# memo:
# $g_tz ¿¡ ÀÇÇÏ¿© ½ÃÂ÷¸¦ º¸Á¤ÇÕ´Ï´Ù£®
sub _time {
return time() - $g_tz;
}
#----------------------------------------------------------------------
# Ç¥½Ã¿ëÀÇ ½Ã°¢ ¹®ÀÚ¿ÀÇ Ãëµæ
#----------------------------------------------------------------------
# argument:
# 0 - GMT·ÎºÎÅÍÀÇ °æ°ú Ãʼö
# return:
# ½Ã°¢ÀÇ ¹®ÀÚ ¿
sub _gettimestr {
my (@weekday) = (
ÀÏ
,
¿ù
,
È
,
¼ö
,
¸ñ
,
±Ý
,
Åä
);
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($_[0]);
return sprintf("%02d/%02d(%s)%02d:%02d:", $mon +1, $mday, $weekday[$wday], $hour, $min,);
}
#----------------------------------------------------------------------
# CGIÀÇ º£À̽º ÆнºÀÇ Ãëµæ
#----------------------------------------------------------------------
# return:
# ÀÌ CGIÀÇ º£À̽º Æнº
sub _basepath {
my ($result);
$result = $ENV{
SCRIPT_NAME
};
$result =~ s/[^/]*$//;
return $result;
}
#----------------------------------------------------------------------
# HTML ¹®ÀÚ¿ÀÇ Ã³¸®
#----------------------------------------------------------------------
# argument:
# 0 - ´ë»ó ¹®ÀÚ ¿
# return:
# Ư¼öÇÑ ¹®ÀÚ¸¦ ´ëÄ¡Çϰųª »èÁ¦Çϰųª ÇÕ´Ï´Ù£®
sub _escapehtml {
my ($result) = $_[0];
$result =~ s/&/&/g;
$result =~ s/"/"/g; # ";
$result =~ s/ $result =~ s/>/>/g;
$result =~ s/
//g;
$result =~ s/
/
/g;
$result =~ s/ //g;
return $result;
}
#----------------------------------------------------------------------
# ÆûÀÇ Àü°³
#----------------------------------------------------------------------
# argument:
# 0:$len - Åõ°íµÈ ¹®ÀÚ ¼ö
# global reference:
# FORM - FORM
# memo:
# ÁöÁ¤µÈ ¹ÙÀÌÆ® ¼ö STDIN ·ÎºÎÅÍ Àо°í FORM¿¡ Àü°³ÇÕ´Ï´Ù£®
sub _parseform {
my ($buffer, @pairs, $name, $value, $len);
$len = $_[0];
if ($len != 0) {
if (read(STDIN, $buffer, $len) != $len) {
return 0;
}
@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} = jcode::euc($value);
}
}
return 1;
}
#----------------------------------------------------------------------
# QUERY ¹®ÀÚ¿ÀÇ Àü°³
#----------------------------------------------------------------------
# global reference:
# FORM - FORM
# memo:
# QUERY ¹®ÀÚ¿À» FORM¿¡ Àü°³ÇÕ´Ï´Ù£®
sub _parsequery {
my (@pairs, $name, $value);
@pairs = split(/&/, $ENV{
QUERY_STRING
});
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} = jcode::euc($value);
}
return 1;
}
#----------------------------------------------------------------------
# ÄíÅ°ÀÇ Àü°³
#----------------------------------------------------------------------
# global reference:
# $g_cookiename - ÄíÅ°ÀÇ À̸§
# COOKIE - ÄíÅ°
# memo:
# ÄíÅ°¸¦ ÃëµæÇÏ°í COOKIE¿¡ Àü°³ÇÕ´Ï´Ù£®
sub _parsecookie {
my ($line, $name, $value, $pair);
foreach $line (split(/; /, $ENV{
HTTP_COOKIE
})) {
($name, $value) = split(/=/, $line, 2);
if ($name eq $g_cookiename) {
foreach $pair (split(/,/, $value)) {
($name, $value) = split(/:/, $pair, 2);
$COOKIE{$name} = _unescapecookie($value);
}
last;
}
}
}
sub _unescapecookie
{
my ($result) = $_[0];
$result=~ s/#3/;/g;
$result=~ s/#2/:/g;
$result=~ s/#1/,/g;
$result=~ s/# /#/g;
$result = jcode::euc($result);
return $result;
}
#----------------------------------------------------------------------
# Set-Cookie Çì´õÀÇ ¼Û½Å
#----------------------------------------------------------------------
# global reference:
# $g_cookiename - ÄíÅ°ÀÇ À̸§
# $g_cookiepath - ÄíÅ°¸¦ ¼Û½ÅÇÑ Æнº
# $g_cookieexpires - ÄíÅ°ÀÇ À¯È¿ ±â°£ Àϼö
# COOKIE - ÄíÅ°
# FORM - Æû
sub _setcookie {
if ($FORM{
USECOOKIE
} eq
remove
) {
print "Set-Cookie: ${g_cookiename}=; path=${g_cookiepath}
";
}
if ($FORM{
USECOOKIE
} eq
use
) {
foreach my $c (@g_cookies) {
if (defined($FORM{$c})) {
$COOKIE{$c} = $FORM{$c};
}
}
print "Set-Cookie: " . _makecookie() . "
";
}
}
sub _makecookie {
my ($result, $value, @keyval, $len, $key, $val);
@keyval = %COOKIE;
$len = @keyval;
if ($len < 2) {
return;
}
$val = pop(@keyval);
$key = pop(@keyval);
$value = $key .
:
. _escapecookie($val);
my ($i);
for ($i = 2; $i < $len; $i += 2) {
$val = pop(@keyval);
$key = pop(@keyval);
$value .=
,
. $key .
:
. _escapecookie($val);
}
my $expires;
$expires = time() + $g_cookieexpires * 24 * 60 * 60;
$result = $g_cookiename .
=
. $value .
; expires=
. makeRFC1123($expires) .
; path=
. $g_cookiepath;
return $result;
}
sub _escapecookie
{
my ($result) = jcode::sjis($_[0]);
$result =~ s/#/# /g;
$result =~ s/,/#1/g;
$result =~ s/:/#2/g;
$result =~ s/;/#3/g;
return $result;
}
#----------------------------------------------------------------------
# ÀÏÀÚ ¹®ÀÚ¿ÀÇ Ãëµæ
#----------------------------------------------------------------------
# argument:
# 0 - GMT ·ÎºÎÅÍÀÇ °æ°ú Ãʼö
# return:
# RFC 822(RFC 1123·Î °»½Å) ·Î Á¤ÀÇµÈ ½Ã°¢ ¹®ÀÚ¿À» µ¹·Á Áش٣®
sub makeRFC1123 {
my (@exp) = gmtime($_[0]);
$exp[6] = (
Sun
,
Mon
,
Tue
,
Wed
,
Thu
,
Fri
,
Sat
)[$exp[6]];
$exp[4] = (
Jan
,
Feb
,
Mar
,
Apr
,
May
,
Jun
,
Jul
,
Aug
,
Sep
,
Oct
,
Nov
,
Dec
)[$exp[4]];
$exp[5] += 1900;
return sprintf("%s, %02d %s %4d %02d:%02d:%02d GMT",
$exp[6], $exp[3], $exp[4], $exp[5],
$exp[2], $exp[1], $exp[0]);
}
#----------------------------------------------------------------------
# ¾ÏÈ£È ·çƾ
#----------------------------------------------------------------------
# argument:
# 0 - ¾ÏÈ£ º¯ÇÏ°í ÀÖÁö ¾Ê´Â Æнº ¿öµå
# return:
# ¾ÏÈ£ ÈÁ¦ÀÇ Æнº ¿öµå
# memo:
# salt ¸¦ ·£´ýÇÏ°Ô ¼±ÅÃÇÏ°í Æнº ¿öµå¸¦ ¾ÏÈ£È ÇÕ´Ï´Ù£®
sub _crypt {
my (@saltchar) = (
a
..
z
,
A
..
Z
,
0
..
9
,
.
,
/
);
my $salt = ($$ * time() + int(rand(4096))) % 4096;
$salt = $saltchar[int($salt / 64)] . $saltchar[$salt % 64];
return crypt($_[0], $salt);
}
#----------------------------------------------------------------------
# Æнº ¿öµåÀÇ È®ÀÎ
#----------------------------------------------------------------------
# argument:
# 0:$plain - ¾ÏÈ£ ÈÀüÀÇ Æнº ¿öµå
# 1:$pass - ¾ÏÈ£ ÈÁ¦ÀÇ Æнº ¿öµå
# return:
# Æнº ¿öµå°¡ ÀÏÄ¡Çϸé 1, ºÒÀÏÄ¡¶ó¸é 0
sub _auth {
my ($plain, $pass) = @_;
my $salt;
if ($pass =~ /^$1$/) {
$salt = substr($pass, 3, 2);
}
else {
$salt = substr($pass, 0, 2);
}
return (crypt($plain, $salt) eq $pass);
}
#----------------------------------------------------------------------
# °ü¸®ÀÎ Æнº ¿öµåÀÇ Ãëµæ
#----------------------------------------------------------------------
# global reference:
# $g_adminpass - °ü¸®ÀÎ Æнº ¿öµå
# $g_passfile - °ü¸®ÀÎ Æнº ¿öµå ÆÄÀÏ
# return:
# ÃëµæµÈ °ü¸®ÀÎ Æнº ¿öµå
# memo:
# ¾ÆÁ÷ ÀÐÈ÷°í ÀÖÁö ¾Ê´Ù
sub _adminpass {
if (! defined($g_adminpass)) {
if (open(_IN, $g_passfile)) {
$g_adminpass = <_IN>;
chomp($g_adminpass);
close(_IN);
}
}
return $g_adminpass;
}
#----------------------------------------------------------------------
# ÇѶ§ ÆÄÀÏ À̸§ÀÇ ÀÛ¼º
#----------------------------------------------------------------------
# global reference:
# $g_pngtempform - PNG ÇѶ§ ÆÄÀÏÀÇ Æ÷¸Ë
# return:
# ÀÛ¼ºµÈ Àӽà ÆÄÀÏ À̸§£®lock Áß¿¡ ºÒ·¯³»´Â °ÍÀ¸·Î ´ÜÀÏÆÄÀÏ
# À̸§ÀÎ °ÍÀÌ º¸ÁõµË´Ï´Ù£®
sub _gettemporarily {
my $num = int(rand(100));
my $result;
for (my $i = 0; $i < 10; $i++) {
$num = ($num + 63) % 100;
$result = sprintf($g_pngtempform, $num);
if (! -e $result) {
last;
}
}
if (-e $result) {
$result = undef;
}
return $result;
}
#----------------------------------------------------------------------
# lockÀÇ Ãëµæ
#----------------------------------------------------------------------
# global reference:
# $g_locked <-> lock »óÅÂ
# $g_lockmethod -> lockÀÇ ¹æ¹ý
# $g_trylock -> lockÀ» ½ÃµµÇØ º¸´Â ȸ¼ö
# $g_lockfile -> lock ÆÄÀÏ
# return:
# lock¿¡ ¼º°øÇϸé 1, ½ÇÆÐÇϸé 0
sub _lock {
if (! $g_locked) {
my $tries = 0;
while ($tries++ <= $g_trylock) {
if ($g_lockmethod == 0) {
$g_locked = _lock1();
}
elsif ($g_lockmethod == 1) {
$g_locked = _lock2();
}
elsif ($g_lockmethod == 2) {
$g_locked = _lock3();
}
if ($g_locked) {
last;
}
sleep(2);
}
}
return $g_locked;
}
sub _lock1 {
return symlink(
dummy
, $g_lockfile);
}
sub _lock2 {
return mkdir($g_lockfile, 0777);
}
sub _lock3 {
if (! open(G_HLOCK,
>>
. $g_lockfile)) {
return 0;
}
# if (flock(G_HLOCK, LOCK_EX|LOCK_NB)) {
if (flock(G_HLOCK, 6)) {
return 1;
} else {
close(G_HLOCK);
return 0;
}
}
#----------------------------------------------------------------------
# lockÀÇ Çعæ
#----------------------------------------------------------------------
# global reference:
# $g_locked <-> lock »óÅÂ
# $g_lockmethod -> lockÀÇ ¹æ¹ý
# $g_trylock -> ¾ðlock¸¦ ½ÃµµÇØ º¸´Â ȸ¼ö
# return:
# lock¿¡ ¼º°øÇϸé 1, ½ÇÆÐÇϸé 0
sub _unlock {
if ($g_locked) {
my $tries = 0;
my $result;
while ($tries++ <= $g_trylock) {
if ($g_lockmethod == 0) {
$result = _unlock1();
}
elsif ($g_lockmethod == 1) {
$result = _unlock2();
}
elsif ($g_lockmethod == 2) {
$result = _unlock3();
}
if ($result) {
$g_locked = 0;
last;
}
select undef, undef, undef, 0.2;
}
}
}
sub _unlock1 {
return unlink($g_lockfile);
}
sub _unlock2 {
return rmdir($g_lockfile);
}
sub _unlock3 {
#flock(G_HLOCK, LOCK_UN);
flock(G_HLOCK, 8);
return close(G_HLOCK);
}
#----------------------------------------------------------------------
# lock »óÅÂÀÇ Ãëµæ
#----------------------------------------------------------------------
# global reference:
# $g_locked <-> lock »óÅÂ
# return:
# lock¿¡ ¼º°øÇϸé 1, ½ÇÆÐÇϸé 0
sub _islocked {
return $g_locked;
}
#----------------------------------------------------------------------
# µð¹ö±× ·Î±×ÀÇ ±âÀÔ
#----------------------------------------------------------------------
sub _debug {
open(_DEBUGOUT, ">>debug.log");
print _DEBUGOUT @_;
close(_DEBUGOUT);
}
sub _access {
open(_ACCESSOUT, ">>access.log");
print _ACCESSOUT $_[0] .
:
. time() .
:
. $ENV{
REMOTE_ADDR
} .
:
. _getremoteaddress() .
:
. $ENV{
HTTP_USER_AGENT
} .
:
. $COOKIE{
NAME
} . "
";
close(_ACCESSOUT);
}
#----------------------------------------------------------------------
# SJIS·ÎÀÇ Ãâ·Â ·çƾ
#----------------------------------------------------------------------
# memo:
# º¹¼öÀÇ Æз¯¹ÌÅ͸¦ ÁØ °æ¿ì£¬°¢ Æз¯¹ÌÅÍ »çÀÌ¿¡´Â ½ºÆäÀ̽º°¡ »ðÀԵǰí
# ÀÔ´Ï´Ù£®
sub _printsjis {
print @_[0];
}
#----------------------------------------------------------------------
# Á¾·á ·çƾ
#----------------------------------------------------------------------
# memo:
# lockµÇ¾ú´ø »óŶó¸é unlock ÇÕ´Ï´Ù£®
END {
_unlock();
}
|