#!/usr/bin/perl
# 
# 1997.9.14
# ՂƁ@΂@䂢Ɓ@
# @@@@@@@@@Since  1996

# Ł
$copyright = 'ڂ+[Õ`+΃JE^ 2001N1027';
# AFzurubon@lycos.ne.jp

# ɉ炱"+ hogehoge"ƏƗǂȂ
$modified = '';

# 2001N1027ŕύX_
# EL̊JnԍK001ł͂ȂACӂ̐Jnł悤ɂ
# EL̘AԂ3\4\ɕύX(ex. 001.jpg -> 0001.jpg)
# E摜{[h̊OςύX
# ET[ofBXNgpʂ̊TZ\(FTP[hɂ͔Ή)
# EANZXWɂAbv[h~Xh~኱
# ȆׂƂE\[XR[h̃_CGbg

# ڂ񂠂Ղ낾T|[gy[W
# ߋ̉Ń\[XɒuĂ܂B
# http://zurubon.strange-x.com/uploader/


# ۏ
# @̃XNvggp邱ƂɂĐȂ
# @QEɂāAڂ͈ӁE⏞ł܂B

# 2zz
# @䂢Ƃ̔zzɏ̂Ƃ܂B

# uFTP[hvgpɊւ钍ӎ
# @2000N317CłۑFTPzXgwł悤ɂȂĂ܂B
# @FTP[h͏\ɃeXgĂ킯ł͂܂B
# @ĈEȓ]ꍇɂ͎gpȂ悤ɂĂB
# @܂AZLeB[̖ʂł肪܂̂ŕۑFTPzXg
# @NbNč悤ȃT[o[w肵ȂłB

# oO|[g͊}܂
# @NɃeXgɌJĂ܂̂ł炭oOƎv܂B
# @CÂ̓_܂Aɒڃ[𑗂邩A
# @vO}̃A`_E\R[_[fɂłłB
# @ÃXLA]ɂɂE܂̂ŕKΏłƂ͌ȂƂmuB

# 
# @vO}AyуA`_E\R[_[f͂₵[ǂ̈ꕔłB
# @݂̍ۂ́A₵[ǂɑ݂肢܂B
# @ɂQ˂l^₻ɗގ鏑݂͂B

# 
# ȏ̂Ƃ𗹏݂̂p
# 

# ӎ
# ݂炢Ղ낾Ǘll 2000/09/07
# HTML^O̊ԈႢAswEɊ
# 
#  by [Õ` - Sat, Apr 15, 2000 - gkJVMgleaMcTQ
# 
# @@@  
# `P(L[`)RgɃ^OĂƏ肭&lt;ɕϊȂ̂C
# @UUP U@U@@MIME type̊gq̋
# @@@@@@@ MIME type̋L^/\
# @@@@@@@ Avꂽt@C̖ɃS~ăE[F̂
# 
#  by [Õ` - Thu, May 11, 2000 - gkwWZ40tgKf5I
# 
# gq̎̋
# F̑lzh̑Ή
# 
#  by [Õ` - Fri, Jun 30, 2000 - gkHcafwBNEY86
# 
# MIME typeMȂꍇւ̑Ή̏C
# MIME typesC

# ################################
# ݒ	Kݒ/ύX
# ################################

# ̃XNvgURL(HTTP)
# F̂܂܂̐ݒœ삵Ȃꍇ͐mURL(URI)͂ĂB
$url = "http://$ENV{SERVER_NAME}$ENV{SCRIPT_NAME}";

# Abv[hf[^̊i[fBNg
# p[~bVF700->777
# FFTP[h̏ꍇƗpɎĝŕKݒ肵ĂB
$storedir = './source/';

# Abv[hf[^̊i[fBNgURL
# FURLXg쐬E摜{[hŎg܂B
# FTP[hgp̏ꍇ͐ݒ肵ĂȂ
# K҂t@C_E[hłȂȂ܂B
$storeurl = 'http://zurubon.strange-x.com/source/';

# Ot@C
# p[~bVF600->666
$log_file = './sourcelog.txt';

# e̔rplockt@C
# F̃t@CpӂĂB
# p[~bVF600->604  (vCGIǂ߂邾OKłB)
$up_lockfile = './upload.lock';

# \^Cg
$title = 'ǂ\[XAbv';

# ^Cg̉ɕ\邨m点
$info = '
CɂȂLE\[XÃ\[XȂǁR(L[M)m 
';

# ########################################
# ׂݒ
# ########################################

# HTMLBODYݒ
$body = '<body bgcolor="#004040" text="#ffffff" link="#eeffee" vlink="#dddddd" alink="#ff0000">';

# HTML̃X^CV[gݒ
$css = '
A	{text-decoration: none;}
A:link	{text-decoration: none;}
A:hover	{text-decoration: none; background-color: #508080; color: #FFFFFF;}
select	{background-color:#007f7f; color:#FFFFFF;}
.button	{background-color:#007f7f; color:#FFFFFF; border-color:#FFFFFF;}

';

# HTML̍Loi[ݒ
# FݒuT[o[ɉďĂB
$ban = '<!--#echo banner=""-->';

# No[
# e̓sEɍ킹ēKXCĂB
$links = '
| <a href="./bbs.cgi">f</a> |

';

# ^Cg̓Ir̐F
$obi = '#007f7f';

# ۑt@C̐ړ
# F'up0001.jpg'̂悤ȃt@Cŕۑ܂BȂɂȂĂOKłB
$prefix = 'up';

# L̊Jnԍ
# FL̊JnԍCӂ̐ɕύXł܂B
$start_num = '0001';

# Rg̃I[gN
# 1: 0:Ȃ
$autolink = 1;

# Rg̒
# FPʂ̓oCgłB
$comment_max = 256;

# ftHgł1y[Wɂ\
$lmaxdef = 25;

# O̍ő匏
$max = 200;

# t@CTCY(LoCgP)
$limitk = 300;

# URLXgo̓tH[
# 1:\ 0:\Ȃ
$listform_enable = 0;

# ΃JE^[
# 
# JE^vXl(LqF"+1000")
$shiba::countplus = "";

# JE^Jn
$shiba::countdate = '2001/08/23';

# JE^[ƗpfBNgEt@C̎w
# FJE^[@\gꍇ̓JE^[ƗpfBNg쐬ĂB
# ȉ̐ݒł̃JE^[ƗpfBNgcountɂȂ܂B
# ./count/ȉ"count"t@C͍쐬Kv͂܂B
# p[~bVF700->707
$shiba::countfile = './count/count';

# JE^[Ɨpt@C̊gq
# F^pɖ薳ꍇ͕ύXKv͂܂B
$shiba::countfiledat = '.txt';

# JE^x(0傫lE0̂Ƃ͎gpȂ)
# FJE^[@\gꍇ1ȏ̐lݒ肵ĂB
# (pɂɃANZX悤ȃTCgł3`4炢ŏ\łB)
$shiba::countlevel = 0;

# ߋOpjcode.pl
# FߋOjcode.plgꍇ́Ajcode.plւ̃T[o[pXĂB
# ȉ͂Ղ낾{̂ƓfBNgɒuꍇ̐ݒłB
# KݒuKv͂܂BݒuȂĂG[ɂ͂Ȃ܂B
$jcode = './jcode.pl';

# bNt@C
# 1:gp 0:gpȂ
$lock = 0;

# bNt@C̃fBNg+t@C
# FbNpfBNg p[~bV700->777
$lockfile = './lock/lock-file.lock';

# Ήt@C`
# FpJ}ŋ؂ēʂɑΉt@C`
$support = '';

# ########################################
# Ƃނݒ
# ########################################

# et@C폜
# 1:gp 0:gpȂ
# Fe҂pX[hݒ肵Ď̓ef[^폜ł悤ɂȂ܂B
# ̃IvVLɂĂpX[hݒ肳Ȃꍇ
# Ǘ҈ȊO폜łȂȂ܂B
$del_enable = 0;

# et@C폜pX''
# Fݒ蕶''Ƃč폜pX[h𐶐܂B
$del_seed = 'z8';

# et@C̊Ǘҍ폜
# 1:gp 0:gpȂ
# FSĂ̓et@C폜łǗ҃pX[hݒ肵܂B
# L"et@C폜"LɂKv܂B
$admindel_enable = 0;

# Ǘ҃pX[h''
# FL̓eppX[h𐶐ƂɗpłB
$adminseed = 'z8';

# Ǘ҃pX[h
# F̃pX[hł͂ȂÍꂽ̂KvłB
# 
# ܂http://zurubon.strange-x.com/crypt.txt̗pT[o[ɐݒuāA
# ̃pX[hƊǗ҃pX[h̎́AꂽÍpX[h
# ɐݒ肵ĂB
$adminpass = 'z8aGslNZD.HSm6';

# gzipk]
# FHTMLy[Wgzipňk]ł悤ɂȂ܂B
# T[o[ɂ镉S㏸܂B
# 1: 0:Ȃ
$gzipenc_enable = 0;

# gzipk]ꍇA
# Fgzipk]ftHgƂ邩
# 1:ftHgƂ 0:ftHgƂȂ
$gzipenc_def = 0;

# crc`FbNTZo
# 1:gp 0:gpȂ
# Fy􎁍dcrcA܂crc.pl𗘗păt@C̃`FbNTL^܂B
# dcrchttp://daisakuretsu.hypermart.net/dcrc.htmlł܂B
# \[Xt@CAtelnetNCAgtelnet.cgigăRpCĂB
# crc.plhttp://zurubon.strange-x.com/uploader/crc_pl.txtł܂B
# 
$dcrc_enable = 0;

# dcrc̏ꏊ
$dcrc_path = './dcrc';

# Perlcrc`FbNTZo
# Fٍcrc.plgCRC`FbNTZo܂B
# dcrcŌvZꍇɔׂďXs[hȂ藎܂B
# 
# crc.plgCRCvZꍇcrc.plւ̃pXݒ肵ĂB
$crc_pl = './crc.pl';

# md5`FbNTZo
# 1:gp 0:gpȂ
# FT[o[md5R}h܂md5.pl𗘗păt@C̃`FbNTL^܂B
# md5.plhttp://zurubon.strange-x.com/uploader/md5_pl.txtł܂B
# Abv[hɋL^
$md5_enable = 0;

# md5R}h̃T[o[pX
$md5_path = '/sbin/md5';

# md5.plւ̃T[o[pX
# ȂׂT[o[md5R}hgȂꍇ̑֏uƂmd5.plg悤ɂĂB
# md5R}hŌvZꍇɔׂĂȂ菈x܂B
# 
# md5.plgMD5vZꍇmd5.plւ̃pXݒ肵ĂB
$md5_pl = './md5.pl';

# FTP[h
# 1:gp 0:gpȂ
$ftp_enable = 0;

# upftp.plւ̃T[o[pX
# Fupftp.plhttp://zurubon.strange-x.com/uploader/upftp_pl.txtł܂B
# FTP[hgpȂꍇupftp.plݒuKv͂܂B
$upftp_pl = './upftp.pl';

# FTP]zXg
$ftp_host = 'ftp.strange-world.co.jp';

# FTP[U[
$ftp_user = 'nyasu_daisensei';

# FTPpX[h
$ftp_pass = 'daisensei_password';

# FTPۑfBNg
# FFTP]zXgɃOCw肳ꂽfBNg
# ړĂɃf[^Abv[h܂B
$ftp_dir = '.';

# uݒvŔscookie̗L
# FftHg90(悻3)
# ܂ɓ𑽂ĂuEU[ŏs\ƂȂ܂̂łقǂقǂɁB
$cookie_limit_day = 90;

# ########################################
# ZLeB[Ɋւݒ
# ########################################

# HTMLt@C͊gq*.txtɕύX(C^Yh~)
# 1:ύX 0:ύXȂ
$htmlext = 0;

# eIP̃Ot@Cւ̋L^
# 1:L^ 0:L^Ȃ
$getip = 0;

# eppX[h
# Fe҂͑SĊǗ҂ݒ肵pX[h͂Ȃ
# ełȂȂ܂B
$postpass_enable = 0;

# eppX[h''
# FL̓eppX[h𐶐ƂɗpłB
$postseed = 'z8';

# eppX[h
# F̃pX[hł͂ȂÍꂽ̂KvłB
# 
# ܂http://zurubon.strange-x.com/crypt.txt̗pT[o[ɐݒuāA
# ̃pX[hƓeppX[h̎́AꂽpX[h
# ɐݒ肵ĂB
$postpass = 'z8SwWsin2UzxM';

# AeԊu̐
# 1: 0:Ȃ
$continue_limit = 0;

# Aepf[^t@C
# p[~bVF600->666
$continue_file = './continue.cgi';

# AeԊu
# FftHg30B
# uȑO"IP"̓e30oēxeĂOKvƂƂłB
# Lqၟ
# 2ԁu200v
# 1Ԕu130v
# 30u030v
# 1u001v
$contine_time = '030';

# ANZX
# 1:gp 0:gpȂ
$access_ctl = 0;

# ANZXpf[^t@C
# F̃t@Cɂ̓ANZX֎~zXg
# u1s1zXgEFQDN(܂IPAhX)vŋLq܂B
# K\g܂B
$denylist = './deny.cgi';

# MIME types
%MIME =
(
# eLXg
	c   => "text/c",
	css => "text/css",
	csv => "text/comma-separated-values",
	htm => "text/html",
	js  => "text/(js|javascript)",
	rtf => "text/rtf|application/rtf",
	smi => "text/smil-basic|application/smil",
	txt => "text/plain",
	vbs => "text/vbscript",
	xml => "text/xml|application/xml",
# C[W
	bmp => "image/(bmp|x-bmp|x-MS-bmp)",
	gif => "image/gif",
	ico => "image/x-icon",
	jpg => "image/.*jpeg",
	png => "image/(png|x-png)",
	psd => "image/x-photoshop",
	tif => "image/(tiff|x-tiff)",
	xbm => "image/(x-xbm|x-xbitmap)",
# rfI
	asf => "video/(x-ms-asf|x-ms-asf-plugin)|application/x-mplayer2",
	avi => "video/(avi|msvideo|x-msvideo)",
	mov => "video/quicktime",
	mpg => "video/(mpg|mpeg|x-mpeg)",
# I[fBI
	aif => "audio/(aiff|x-aiff|x-pn-aiff)",
	au  => "audio/(basic|x-pn-au)",
	m3u => "audio/(mpegurl|x-scpls|x-mpegurl)",
	mid => "audio/(mid|midi|x-mid|x-midi)|application/x-midi|music/crescendo|x-music/x-midi",
	mod => "audio/x-mod",
	mp3 => "audio/(mp3|mpg|mpeg|x-mp3|x-mpg)",
	ra  => "audio/(x-realaudio|vnd\\.rn-realaudio)",
	ram => "audio/x-pn-realaudio",
	rm  => "application/vnd\\.rn-realmedia",
	rpm => "audio/x-pn-realaudio-plugin",
	vqe => "audio/x-twinvq-plugin",
	vqf => "audio/x-twinvq|application/x-twinvq",
	wav => "audio/(wav|x-wav|x-pn-wav|x-pn-windows-acm|x-pn-windows-pcm)",
	wma => "audio/x-ms-wma",
# 
	arj => "application/arj",
	bin => "application/(octet-stream|x-macbinary)",
	dcr => "application/x-director",
	exe => "application/(x-exe|x-msdownload)",
	gz  => "gzip",
	hlp => "application/(winhlp|x-winhelp)",
	jar => "application/java-archive",
	js  => "application/x-javascript",
	lzh => "lha|lzh|LhasaArchive|LHMelt",
	pac => "application/x-ns-proxy-autoconfig",
	pdf => "application/pdf",
	rar => "application/x-rar-compressed",
	sit => "application/x-stuffit",
	swf => "application/x-shockwave-flash",
	tar => "application/x-tar",
	uue => "application/x-uuencode",
	wmf => "application/x-msmetafile",
	wri => "application/application/x-mswrite",
	yz1 => "application/x-yz1",
	Z   => "application/x-compress",
	zip => "zip",
	wrl => "model/vrml|x-world/x-vrml",
);
%EMIM =
(
	"zip" => "gzip",
);

# ############################################################################
# ȉ̓XNvg̃GWBłɂƓȂȂ邩(
# ############################################################################

# ANZX
$host = $ENV{REMOTE_ADDR};
if($access_ctl){
	open(DB,"$denylist") || die &error('ANZXt@CI[vł܂','');
	@lines = <DB>;
	close(DB);
	foreach $line (@lines) {
		next if(length($line)<4);
		chop $line;
		if( $host=~/$line/ ){&error('ANZX','Ȃɂ̓ANZX܂B');}
	}
	$lines = 0;
}

@sup = split(/,/, $support);
@MEXT = sort keys(%MIME);
%sup = ();
grep($sup{$_} = 1, @sup, @MEXT);
if($htmlext != 0)
{
	delete $sup{"htm"} if exists $sup{"htm"};
	delete $sup{"html"} if exists $sup{"html"};
	delete $MIME{"htm"} if exists $MIME{"htm"};
	delete $MIME{"html"} if exists $MIME{"html"};
}
@sup = sort keys(%sup);

if($lock){
	$retry = 5;
	while (!symlink(".", $lockfile)) {
		if (--$retry <= 0){unlink($lockfile); exit;}
		sleep(1);
	}
}

# Oǂݍ
&readlog;

# Abv[hƃOւ̒ǉ
if ($ENV{REQUEST_METHOD} eq "POST") {
# $dateɌݎ
	$ENV{TZ} = 'JST-9';
	$times = time;
	($sec,$min,$hour,$mday,$month,$year,$wday,undef,undef) = localtime($times);
	$month++;
	$youbi = ('','','','','','','y') [$wday];
	$year = 1900 + $year;
	$date = sprintf("%dN%02d/%02d(%s)%02d:%02d", $year, $month, $mday, $youbi, $hour, $min);
# Ae
	if($continue_limit){
		$cont_val = &continue_check('check');
		&error('Ae','ԂuĂ蒼Ă') if(!$cont_val);
	}
	srand(time^$$);
	$uniq_name = time . int(rand(time)) . '.temp'; # temporaryuniqueȖOt
	unlink <$storedir*.temp>; # fBNgɃS~cĂꍇɂ͑|
	&decode;
	open (UPLOCK, "$up_lockfile");
	flock (UPLOCK, 2); # r̎n܂
	&readlog; # uploadIĂ烍Oǂ
	# $id߂
	if((-s "$log_file")==0){
		$id = $start_num;
	}else{
		($id) = split(/\t/, $lines[0]);
		$id = sprintf("%04d",++$id);
	}
	rename ("$storedir$uniq_name", "$storedir$prefix$id.$type"); # temporaryȖO琳ȖOrename
	chmod 0604, "$storedir$prefix$id.$type";
	if($ftp_enable){
		if(-f $upftp_pl){
			require $upftp_pl;
			use Cwd; my $olddir = cwd;
			chdir $storedir || die error('G[', "$storedirJ܂");
			&upftp::login($ftp_host, 21, $ftp_user, $ftp_pass);
			&upftp::cd($ftp_dir);
			&upftp::upload("$prefix$id.$type");
			&upftp::logout;
			chdir $olddir;
		}
		else{
			&error('G[','upftp.pl܂B<br>ݒĂB');
		}
		unlink("$storedir$prefix$id.$type");
	}
	&write if($comment);
	close (UPLOCK); # ȑI
	&readlog;
}

# tH[f[^̃fR[h(GET)
$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;
}

# ݒ胂[h
if($ENV{QUERY_STRING} eq 'env'){
	&env_form;
}
# ߋO
elsif($FORM{search} ne "" || $ENV{QUERY_STRING} eq "search"){
	if($FORM{search}){
		@search_ary = &search_log($FORM{search});
		$search_hit = @search_ary;
	}
	&search_result;
}
# 摜{[h
elsif($ENV{QUERY_STRING} eq "image" || $FORM{image} ne ""){
	&image_view($FORM{image});
}
# URLXg쐬
elsif($FORM{lstart} ne "" && $FORM{lend} ne ""){
	&list;
}
# ef[^폜tH[
elsif($FORM{del} ne "" && $del_enable){
	&del_form($FORM{del});
}
# ef[^̍폜
elsif($FORM{delid} && $FORM{delpass} ne ""){
	&del($FORM{delid},$FORM{delpass});
	&readlog;
	&html;
}
# md5\
elsif($md5_enable && $FORM{md5} ne ""){
	&md5_disp($FORM{md5});
}
# dcrc
elsif($dcrc_enable && $FORM{dcrc} ne ""){
	&dcrc_disp($FORM{dcrc});
}
# wv
elsif($FORM{help} ne ""){
	&help($FORM{help});
}
# gbvy[W\
else{
	&html;
}
# bNt@C폜
unlink($lockfile) if($lock);

# I
exit;

# ############################################################################
# ȉ֐`&
# ############################################################################

# Oǂݍ
sub readlog{
	if(!open(DB,"$log_file")){&error('Ot@CI[vł܂','XNvg̐ݒĂB');}
	seek(DB,0,0);
	@lines = <DB>;
	$end_num = (split(/\t/,$lines[0]))[0];
	close(DB);
}

# O
sub write{
	$size = $ENV{CONTENT_LENGTH}/1024;
	$size = 1 if($ENV{CONTENT_LENGTH} < 1024);
	$size = sprintf("%d", $size);
	$host = 'anonymous' if(!$getip);
	$pass = '*' if(!$del_enable);
	$value = &tjoin($id, $type, $comment, $host, $ENV{HTTP_USER_AGENT}, $date, $size, $ctype, $pass, $md5, $dcrc);
	$value .= "\n";

	#$value@linesɉ̂A
	if(@lines > $max-1){#ő𒴂폜܂B
		$del= pop(@lines);
		($id, $type) = split(/\t/, $del);
		if($ftp_enable){
			if(-f $upftp_pl){
				require $upftp_pl;
				&upftp::login($ftp_host, 21, $ftp_user, $ftp_pass);
				&upftp::cd($ftp_dir);
				&upftp::del("$prefix$id.$type");
				&upftp::logout;
			}
			else{
				&error('G[','upftp.pl܂B<br>ݒĂB');
			}
		}
		else{unlink("$storedir$prefix$id.$type");}
	}
	unshift(@lines,$value);
	open(DB,">$log_file");
	eval { flock(DB,2); };
	seek(DB,0,0);
	print DB @lines;
	eval { flock(DB,8); };
	close(DB);
}

# POSTꂽf[^MIME^CvACRCEMD5ZoA
# RgvZEpX[hƍ
sub decode{
	my $size, $expfile;

	return if($ENV{CONTENT_LENGTH} > $limitk*1024);
	return unless($ENV{HTTP_REFERER} =~/$url/);

	binmode(STDIN);
	while(<STDIN>){
		last if(/^\r\n/);
		$bound = $_ if(/^--/);
		$rext = $1 if(/^Content-Disposition:.*filename="(.*)"/i);
		$ctype = $1 if(/^Content-Type:(.*)/i);
	}

	$rext =~ s/.*\.//go;
	$ctype =~ s/(^\s|\s$)//go;
	$bound=~s/\r\n//;

	foreach $mext (@MEXT)
	{
		if($ctype =~ /$MIME{$mext}/)
		{
			next if (defined($EMIM{$mext}) && $ctype =~ /$EMIM{$mext}/);
			$type = $mext;
		}
	}

	if($rext ne "")
	{
		$rextl = "\L$rext\E";
		foreach $ext (@sup)
		{
			if("\L$ext\E" eq $rextl)
			 {
				$type = $ext;
				last;
			}
		}
	}

	$type = 'xxx' if($type eq '');
	$ctype = "www/none" unless $ctype;
	$ctype = &htmlenc($ctype);

	open(DB,">$storedir$uniq_name");
	binmode(DB);
	$dbuf = "";
		while(<STDIN>){
			last if($_=~/^$bound/);
			print DB $dbuf;
			$dbuf = $_;
		}
	$dbuf =~ s/\r\n$//;
	print DB $dbuf;
	close (DB);

	$size = -s "$storedir$uniq_name";
	&reload if(!$size); #size0Ȃ烊[h

	$ext = &post_decode;

	if($ext ne 'ext'){
		if(!grep($ext eq $_, @sup)){
			unlink("$storedir$uniq_name");
			&error('ef[^G[', 'ĂȂgqłB');
		}
		$type = $ext;
	}
	if($dcrc_enable){ # CRCvZ
		if(-f $crc_pl){
			require $crc_pl;
			$dcrc = &crc::crc16("$storedir$uniq_name");
		}
		else{
			$dcrc = &dcrc("$storedir$uniq_name");
		}
	}
	if($md5_enable){ # MD5vZ
		if(-f $md5_pl){
			require $md5_pl;
			$md5 = &md5::from_file("$storedir$uniq_name");
		}
		else{
			$md5 = &md5("$storedir$uniq_name");
		}
	}

	$comment = &post_decode;
	&reload if(!$comment); # RgĂȂꍇReload
	&error('eG[','Rg܂') if(length($comment) > $comment_max);
	$comment = &htmlenc($comment);
	$comment =~ s/(https?|ftp|news)(:.*)([a-z]|[A-Z]|[0-9]|\/)/<a href="$1$2$3">$1$2$3<\/a>/g if($autolink);

	if($del_enable){
		$input_pass = &post_decode;
		$pass = crypt($input_pass, $del_seed);
		$pass = '*' if($input_pass eq '');
		&error('eG[','pX[h܂') if(length($input_pass) > 10);
		if($postpass_enable){
			&error('eppX[hႢ܂','eppX[hǗ҂肵ĂB') if(!&postpass);
		}
	}
	elsif($postpass_enable){
		&error('eppX[hႢ܂','eppX[hǗ҂肵ĂB') if(!&postpass);
	}

	&continue_check('add') if($continue_limit);
}#decode END

# POSTf[^𕶎ɕϊĕԂ
sub post_decode{
	my $post_str;
	while(<STDIN>){
		last if(/^$bound/);
		next if(/^\r\n/);
		next if(/^Content/);
		$post_str .=$_;  $post_str=~s/\r\n//;
	}
	return $post_str;
}

# gbvy[W\
sub html{
	$page = $FORM{page};
	$page=0 unless($page);
	$lmax = $FORM{lm};
	$lmax=$lmaxdef unless($lmax);# y[Wɂǂꂾ\邩H
	$page2 = $page*$lmax;

	&print_header;
	print <<"_HTML_";
	<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="$url" >
	Avt@C<strong>i$limitk K܂Łj</strong><br>
	<INPUT TYPE=file  SIZE="40" NAME="filedata">
	<select name="ext">
	<option value="ext" selected>gqI</option>
_HTML_

	foreach (@sup){print "<option value=\"$_\">$_</option>\n";}
	print "</select>\n";
	print "<br>Rg<i><small>iRgL̏ꍇ[hɂȂ܂\n";
	print "/URL̓I[gN܂" if($autolink);
	print "j</small></i><br>\n", "<INPUT TYPE=text SIZE=\"45\" NAME=\"comment\">\n",
	"<INPUT TYPE=submit VALUE=\"Up/Reload\" class=\"button\"><INPUT TYPE=reset VALUE=\"Cancel\" class=\"button\"><br>\n";
	print " <a href=\"$url?help=del\">del pass</a>: <INPUT TYPE=password SIZE=\"10\" NAME=\"delpass\" maxlength=\"10\">\n" if($del_enable);
	print " <a href=\"$url?help=post\">post pass</a>: <INPUT TYPE=password SIZE=\"10\" NAME=\"postpass\">\n" if($postpass_enable);
	print "</FORM>\n";
	print "<form method=\"GET\" action=\"$url\">\n" if($listform_enable);
	&shiba::html_out; # JE^[
	print "<small>\n";
	print ' DFeL폜' if($del_enable);
	print ' CFCRC\' if($dcrc_enable);
	print ' 5Fmd5\' if($md5_enable);
	print "</small>\n",
		"<HR><small>| <a href=\"$url?search\">ߋO</a>\n",
		" | <a href=\"$url?image\">摜{</a> | <a href=\"$url?env\">ݒ</a> $links</small>\n",
		"<HR>y[WF[<A HREF=\"$url?page=0&lm=$max\">ALL</A>] \n";
	$total = @lines;
	$count = int(($total-1)/$lmax);
	for($i=0;$i<=$count;$i++){
	        if($i eq $page){$disp = $i + 1; print "[<b>$disp</b>] \n";}else{
			$disp = $i + 1;
	                print "[<A HREF=\"$url?page=$i&lm=$lmax\">$disp</A>] \n";
	        }
	} # for
	print "<HR>\n";
	if($listform_enable){
		print "Range\:<input type=\"text\" size=\"5\" name=\"lstart\" value=\"$start_num\"> -",
			"<input type=\"text\" size=\"5\" name=\"lend\" value=\"$end_num\">\n";
		print " <input type=\"checkbox\" name=\"md5list\" value=\"checked\">md5\n" if($md5_enable);
		print " <input type=\"checkbox\" name=\"dcrclist\" value=\"checked\">CRC\n" if($dcrc_enable);
		print " <select name=\"extlist\"><option value=\"\" selected>gq</option>\n";
		foreach (@sup){print "<option value=\"$_\">$_</option>\n";}
		print "</select>\n", " <input type=\"submit\" value=\"URL list\" class=\"button\"><HR>\n";
	}
	(@lines < $lmax) || (@lines = @lines[$page2 .. $page2+$lmax-1]);
	&print_postdata(@lines);

	print "<hr>Ήt@CtH[}bgF\n<tt>\n";
	for($i = 0; $i < $#MEXT; $i++)
	{
	        print "<br>\n" if(($i % 12) == 0);
	        print "*.$MEXT[$i] ";
	}
	print "*.$MEXT[$i]",
	"</tt><br>\n";

	print "̑̃t@CtH[}bgFɎw̖*.xxxƂĕۑ܂B<br>\n",
	"OێE$max1y[Wɂ$lmaxdefÂ\\\܂B<br>\n";
	if(!$ftp_enable){
		print "݂̃T[ofBXNgpʂ͖"; print(&calc_disk_usage); print "kbłB\n";
	}
	print "</form>\n" if($listform_enable);
	&print_footer;
}#html END

# HTML̃wb_
sub print_header{
	my $subtitle = shift;
	my $title_h;

	if(!$subtitle){$title_h = $title}
	else{$title_h = "$title -$subtitle-";}

	# ݒcookie擾
	&get_cookie;

	print "Content-type: text/html\n";
	if($FORM{mode} eq 'envset'){
		&send_cookie; # cookieM
		# Vݒ肳ꂽݒL
		$crce=$FORM{crce}; $md5e=$FORM{md5e}; $acte=$FORM{acte}; $commente=$FORM{commente};
		$sizee=$FORM{sizee}; $mimee=$FORM{mimee}; $datee=$FORM{datee}; $anothere=$FORM{anothere};
		$gzipence=$FORM{gzipence};
	}
	if($gzipenc_enable && $gzipence){&gzip_encode;}
	else{print "\n";}

	print <<"HEADER";
	<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
	<HTML LANG="ja">
	<HEAD>
	<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=Shift_JIS">
	<TITLE>$title_h</TITLE>
	<STYLE><!--$css--></STYLE>
	</HEAD>
	$body
	<table width="100%"><tr><td bgcolor="$obi"><strong><font size="4">$title_h</font></strong></td></tr></table>
	<p>$info</p>
HEADER
}

# HTML̃tb^
sub print_footer{
	print "<HR><H5 ALIGN=right><A HREF=\"http://www.cup.com/yui/\">䂢́[</A> + \n",
	"<a href=\"http://zurubon.virtualave.net/upload.txt\">$copyright</a> $modified\n",
	"</H5>\n<p>$ban</p>\n</body></html>\n";
	close(STDOUT) if($gzipenc_enable && $gzipence);
}

# eLHTML
sub print_postdata{
	my @matrix = @_;
	my $id, $type, $comment, $host, $brauza, $date, $size, $ctype, $pass, $md5, $dcrc;

	print "<table><tr>\n";
	print "<th>ACT</th>\n" if($acte);
	print "<th>NAME</th>\n";
	print "<th>COMMENT</th>\n" if($commente);
	print "<th>SIZE(KB)</th>\n" if($sizee);
	print "<th>MIME</th>\n" if($mimee);
	print "<th>DATE</th>\n" if($datee);
	print "<th>MD5</th>\n" if($md5e && $md5_enable);
	print "<th>CRC</th>\n" if($crce && $dcrc_enable);
	print "</tr>\n";
	foreach (@matrix){
		s/\n//g;
		($id, $type,$comment,$host,$brauza,$date,$size,$ctype,$pass,$md5,$dcrc) = split(/\t/);
		next unless($id);
		print "<tr>\n";

		if($acte){
			print "<td><small>\n";
			print "<a href=\"$url?del=$id\">D</a>\n" if($del_enable);
			print " <a href=\"$url?dcrc=$id\">C</a>\n" if($dcrc_enable && !$crce);
			print " <a href=\"$url?md5=$id\">5</a>\n" if($md5_enable && !$md5e);
			print "</small></td>\n";
		}

		print "<td>[<a href=\"";
		if($ftp_enable){ print "$storeurl"; }
		else{ print "$storedir"; }
		print "$prefix$id.$type\"";
		print " target=\"anotherwin\"" if($anothere);
		print ">$prefix$id.$type</a>]</td>\n";

		print "<td><font size=2>$comment</font></td>\n" if($commente);
		print "<td align=right><b><font size=2>$size</font></b></td>\n" if($sizee);
		print "<td><font size=2 color=\"#888888\">$ctype</font></td>\n" if($mimee);
		print "<td><font size=2>$date</font></td>\n" if($datee);
		print "<td><small>$md5</small></td>\n" if($md5e && $md5_enable);
		print "<td><small>$dcrc</small></td>\n" if($crce && $dcrc_enable);
		print "</tr>\n";
	}
	print "</table>\n";
}

#gzipk]
sub gzip_encode{
	if($ENV{HTTP_ACCEPT_ENCODING}=~/gzip/){
		if($ENV{HTTP_ACCEPT_ENCODING}=~/x-gzip/ ){
			print "Content-encoding: x-gzip\n\n";
		}else{
			print "Content-encoding: gzip\n\n";
		}
		open(STDOUT,"| gzip -1 -c");
		print "<!--gzip_enable-->\n";
	}
}

#URLXgo
sub list{
	my $id, $type, $comment, $host, $brauza, $date, $size, $ctype, $pass, $md5, $dcrc;
	my $start = $FORM{lstart};
	my $end = $FORM{lend};
	my $ext = $FORM{extlist} if($FORM{extlist});

	print "Content-type: text/plain\n\n";
	foreach(@lines){
		s/\n//g;
		($id,$type,$comment,$host,$brauza,$date,$size,$ctype,$pass,$md5,$dcrc) = split(/\t/);
		next if($ext && ($type ne $ext));

		if($id <= $end){
			print "$storeurl$prefix$id.$type";
			print "\t$md5" if($FORM{md5list} eq "checked");
			print "\t$dcrc" if($FORM{dcrclist} eq "checked");
			print "\n";
		}
		last if($id eq $start);
	}
}

# ef[^폜tH[
sub del_form{
	my $target_id = shift;

	&print_header('ef[^폜');
	print <<"DEL";
	<h3>IDF$target_id폜܂</h3>
	<form action=$url method="GET">
	<input type="hidden" name="delid" value="$target_id">
	pX[h́F<input type="password" size="12" name="delpass"><br>
	<input type="submit" value="폜" class=\"button\">
	</form>
DEL
	&print_footer;
}

# et@C폜
sub del{
	my ($target_id, $target_pass) = @_;
	my $id, $type, $pass, $target_type;

	foreach (@lines){
		chop;
		($id, $type, undef, undef, undef, undef, undef, undef, $pass, undef, undef) = split(/\t/);
		if($id eq $target_id){$target_type=$type; $org_pass=$pass; last;}
	}
	&error('폜G[','Yt@C') if(!$target_type);

	if(!$admindel_enable || ($admindel_enable && $adminpass ne (crypt($target_pass, $adminseed)))){
		&error('폜G[','폜֎~t@Cł') if($org_pass eq '*');
		&error('폜G[','pX[hႢ܂') if($org_pass ne (crypt($target_pass, $del_seed)));
	}
	if($ftp_enable){
		if(-f $upftp_pl){
			require $upftp_pl;
			&upftp::login($ftp_host, 21, $ftp_user, $ftp_pass);
			&upftp::cd($ftp_dir);
			&upftp::del("$prefix$id.$type");
			&upftp::logout;
		}
		else{
			&error('G[','upftp.pl܂B<br>ݒĂB');
		}
	}
	else{unlink("$storedir$prefix$target_id.$target_type");}

	open(DB,">$log_file");
	eval { flock DB, 2; };
	foreach (@lines){
		next if($target_id eq (split(/\t/))[0]);
		s/\n//g;
		print DB "$_\n";
	}
	eval { flock DB, 8; };
	close(DB);
}

# G[o
sub error{
	&print_header('NoticeI');
	print <<"ERROR";
	<hr>
	<center>
	<strong>$_[0]</strong><br>
	<p>$_[1]</p>
	<a href="$url">Return</a>
	</center>
ERROR
	&print_footer;
	exit;
}

# ̔z𕪉ă^uŋ؂ꂽԂ
sub tjoin
{
	my @data = @_;
	foreach (@data)
	{
		next if(!$_);
		s/\s/ /go;
	}
	return join("\t", @data);
}

# 񒆂HTML^O𖳌ɂ
sub htmlenc
{
	my $str = shift;
	$str =~ s/\&/&amp;/go;
	$str =~ s/\</&lt;/go;
	$str =~ s/\>/&gt;/go;
	$str =~ s/\"/&quot;/go;
	$str =~ s/\t/ /go;
	return $str;
}

# md5R}hmd5 CRC𓾂
sub md5{
	open MD5, "$md5_path $_[0] |";
	my $val = <MD5>;
	close MD5;
	$val =~ s/ //g;
	$val = (split(/\=/,$val))[1];
	return $val;
}

# md5\
sub md5_disp{
	my $target_id = $_[0];
	my $ans, $id, $md5;

	foreach (@lines){
		chop;
		($id, undef, undef, undef, undef, undef, undef, undef, undef, $md5, undef) = split(/\t/);
		if($id eq $target_id){$ans = $md5; last;}
	}
	&error('G[','Yt@C݂ȂAmd5`FbNTL^Ă܂B') if(!$ans);
	&error("$target_idmd5`FbNT","$ans");
}

# Ot@CČʂ[zԂ
sub search_log{
	my $search_str = $_[0];
	my $count = 0;
	my $id, $type, $comment, $host, $brauza, $date, $size, $ctype;
	my $start, $end, $ext;
	my @ans;

	$start = $FORM{sstart};
	$end = $FORM{send};
	$ext = $FORM{extlist};
	$min = $FORM{size_min};
	$max = $FORM{size_max};

	if(-f $jcode){
		require $jcode;
		&jcode'convert(*search_str,'sjis') if(!$FORM{nojcode});
	}
	$search_str = quotemeta($search_str);
	foreach (@lines){
		s/\n//g;
		($id,$type,$comment,$host,$brauza,$date,$size,$ctype) = split(/\t/);
		if($id >= $start && $id <= $end){
			if($ext ne '' && $ext ne $type){next;}
			else{
				if($size >= $min){
					if($size <= $max || !$max){
						if(/$search_str/){$ans[$count] = $_; $count++;}
					}
				}
			}
		}
	}
	return @ans;
}

# ߋÕgbvy[W/ \
sub search_result{
	if($FORM{sstart}){$sstart = $FORM{sstart};}else{$sstart = $start_num;}
	if($FORM{send}){$send = $FORM{send};}else{$send = $end_num;}
	if($FORM{size_min}){$size_min = $FORM{size_min};}else{$size_min = 1;}
	if($FORM{size_max}){$size_max = $FORM{size_max};}else{$size_max = '';}
	if($FORM{extlist}){$ext = $FORM{extlist}; $extv = $FORM{extlist};}
	else{$ext = 'gq'; $extv = '';}

	&print_header('ߋO');
	print <<"FORM";
	<form method=GET action="$url">
	:<INPUT TYPE=text SIZE="25" NAME="search" value="">
	<INPUT TYPE=submit VALUE="Search/Return" class="button">
	<INPUT TYPE=reset VALUE="Cancel" class="button"><br>
	͈:<input type="text" size="5" name="sstart" value="$sstart"> -
	<input type="text" size="5" name="send" value="$send">
	<select name="extlist"><option value="$extv" selected>$ext</option>
FORM

	foreach (@sup){print "<option value=\"$_\">$_</option>\n";}

	print <<"FORM";
	</select><br>
	TCY:<input type="text" size="10" name="size_min" value="$size_min">K`<input type="text" size="10" name="size_max" value="$size_max">K̊Ԃ
FORM

	print "<INPUT TYPE=checkbox NAME=nojcode value=checked checked>jcode.plgȂ\n" if(-f $jcode);
	print "</FORM><small>\n";
	print ' DFeL폜' if($del_enable);
	print ' CFCRC\' if($dcrc_enable);
	print ' 5Fmd5\' if($md5_enable);
	print "</small>\n";
	print '<hr>';
	if($search_hit){&print_postdata(@search_ary);}
	if($search_str){
		print "<h4>\"$search_str\"$search_hit܂B</h4>" if($search_hit);
		print "<h4>\"$search_str\"͌܂łB</h4>" if(!$search_hit);
	}
	&print_footer;
}

# dcrc^[Qbgt@CCRC𓾂
sub dcrc{
	my $target = shift;
	open DCRC, "$dcrc_path $target |";
	my $val = <DCRC>;
	close DCRC;
	$val = (split(/ /,$val))[1];
	return $val;
}

# CRC\
sub dcrc_disp{
	my $target_id, $ans, $id, $dcrc;

	$target_id = $_[0];
	foreach (@lines){
		chop;
		($id, undef, undef, undef, undef, undef, undef, undef, undef, undef, $dcrc) = split(/\t/);
		if($id eq $target_id){$ans = $dcrc; last;}
	}
	&error('G[','Yt@C݂ȂACRC`FbNTL^Ă܂B') if(!$ans);
	&error("$target_idCRC`FbNT","$ans");
}

# eppX`FbN
sub postpass{
	my $input_postpass = &post_decode;

	if($postpass ne crypt($input_postpass, $postseed)){
		unlink "$storedir$uniq_name";
		return 0;
	}
	return 1;
}

# 摜{[h
sub image_view{
	my $page = $_[0];
	my $total, $page_max, $id, $type, $comment, $date, $size, $i;
	my @images;

	foreach (@lines){
		if((split(/\t/))[1] =~ /(jpg|png|gif)/){
			$images[$count] = $_; $count++;
		}
	}
	$total = @images;
	$page_max = int($total/5);
	$page_max++ if((split(/\./, $total/5))[1]);
	$page = 1 if(!$page || $page > $page_max);

	&print_header('摜{');
	print "<HR><small>| <a href=\"$url?search\">ߋO</a>\n",
	" | <a href=\"$url?image\">摜{</a> | <a href=\"$url?env\">ݒ</a> $links</small>\n";
	print "<hr>\n", "y[W: ";
	for($i=1; $i<=$page_max; $i++){
		if($i==$page){ print "<strong>[$i]</strong>\n"; }
		else { print "<a href=\"$url?image=$i\">[$i]</a>\n"; }
	}

	print "<hr>\n<center>\n";
	if($page == 1){ print "<s>[Prev]</s>&nbsp;&nbsp;&nbsp;\n"; }
	else { print sprintf("<a href=\"$url?image=%d\">[Prev]</a>&nbsp;&nbsp;&nbsp;\n", ($page-1)); }
	print "<a href=\"$url\">[߂]</a>\n";
	if($page == $page_max){ print "&nbsp;&nbsp;&nbsp;<s>[Next]</s>\n"; }
	else { print sprintf("&nbsp;&nbsp;&nbsp;<a href=\"$url?image=%d\">[Next]</a>\n", ($page+1)); }
	print "</center>\n";

	for($i=($page*5-5); $i<=($page*5-1); $i++){
		last if(($i+1) > $total);
		($id, $type, $comment, undef, undef, $date, $size, undef, undef, undef, undef) = split(/\t/, $images[$i]);
		print "<p><a href=\"$storeurl$prefix$id.$type\"";
		print " target=\"new_win\"" if($anothere);
		print "><img src=\"$storeurl$prefix$id.$type\" height=\"250\"></a><br>\n";
		print "<a href=\"$storeurl$prefix$id.$type\">$prefix$id.$type</a><br>\n",
		"$comment <small>$date</small></p>\n";
	}

	&print_footer;
}

# Reload
sub reload{
	unlink "$storedir$prefix$id.$type";
	&readlog;
	&html;
	exit;
}

# Aet@C̓ǂݏAAe`FbN
sub continue_check{
	my $mode = shift;
	my $date_id, $post_ip, $line_c, $line_num, $ans, $ip, $id;

	$date_id = sprintf("%d%02d%02d%02d%02d", $year, $month, $mday, $hour, $min);
	$post_ip = $ENV{REMOTE_ADDR};
	if(!open(DB, "$continue_file")){&error('Aet@CI[vł܂');}
	@line_c = <DB>;
	close(DB);

	if($mode eq 'check'){ # eҏ̃`FbN
		foreach (reverse(@line_c)){
			chop;
			($ip,$id) = split(/:/);
			if($post_ip eq $ip){
				$ans = $date_id - $id;
				return 0 if($ans < $contine_time);
			}
		}
	}
	if($mode eq 'add'){ # Aet@Cɓeҏǉ
		$line_num = @line_c;
		push(@line_c, "$post_ip:$date_id");
		pop(@line_c) if($line_num > $max-1);
		if(!open(DB,">$continue_file")){
		&error('Aet@C݃[hŊJ܂','t@C̃p[~bVĂ');}
		eval { flock DB, 2; };
		foreach (@line_c){print DB "$_\n";}
		eval { flock DB, 8; };
		close (DB);
	}
	return 1;
}

# ݒtH[
sub env_form{
	&print_header('ݒ');
	print <<"ENV";
	<hr>
	<strong>ݒ</strong><br>
	<form method="GET" action="$url">
	<input type="hidden" name="mode" value="envset">
	<ul>
	<li><strong>\\\ݒ</strong>
	<ul>
ENV
	if($md5_enable){
		print '<input type="checkbox" name="md5e" value="1"';
		print " checked" if($md5e); print ">MD5<br>\n";
	}
	if($dcrc_enable){
		print '<input type="checkbox" name="crce" value="1"';
		print " checked" if($crce); print ">CRC<br>\n";
	}
	print '<input type="checkbox" name="acte" value="1"';
	print " checked" if($acte); print ">ACT<br>\n";
	print '<input type="checkbox" name="commente" value="1"';
	print " checked" if($commente); print ">COMMENT<br>\n";
	print '<input type="checkbox" name="sizee" value="1"';
	print " checked" if($sizee); print ">SIZE<br>\n";
	print '<input type="checkbox" name="mimee" value="1"';
	print " checked" if($mimee); print ">MIME<br>\n";
	print '<input type="checkbox" name="datee" value="1"';
	print " checked" if($datee); print ">DATE<br>\n";
	print "</ul>\n<li><strong>ݒ</strong>\n<ul>\n";
	print '<input type="checkbox" name="anothere" value="1"';
	print " checked" if($anothere); print ">t@CJ͕ʑŊJ<br>\n";
	if($gzipenc_enable){
		print '<input type="checkbox" name="gzipence" value="1"';
		print " checked" if($gzipence); print ">gzipk]<br>\n";
	}
print <<"ENV";
</ul>
<br>
cookie𗘗pĂ܂B<br>
L̐ݒŁu$titlevK₷邱Ƃł܂B<br><br>
<input type="submit" value="o^" class=\"button\">
<input type="reset" value="ɖ߂" class=\"button\">
</form>
<a href="$url">߂</a>
ENV
	&print_footer;
}

# cookieM
sub send_cookie{
	my $cookie = "crce:$FORM{crce}<>md5e:$FORM{md5e}<>acte:$FORM{acte}<>";
	$cookie .= "commente:$FORM{commente}<>sizee:$FORM{sizee}<>mimee:$FORM{mimee}<>";
	$cookie .= "datee:$FORM{datee}<>anothere:$FORM{anothere}<>gzipence:$FORM{gzipence}";

	# cookie̗ĽvZ
	my($sec, $min, $hour, $mday, $month, $year, $wday) = gmtime(time + $cookie_limit_day * 24 * 60 * 60);
	my $youbi = ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') [$wday];
	my $tuki = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec') [$month];
	my $year = 1900 + $year;
	my $expire = sprintf("%s, %02d-%s-%04d %02d:%02d:%02d GMT", $youbi, $mday, $tuki, $year, $hour, $min, $sec);

	print "Set-Cookie: env=$cookie; expires=$expire\n";
}

# cookie擾
sub get_cookie{
	my $key, $value, $db, $db2, $env;

	foreach (split(/; /,$ENV{HTTP_COOKIE})){
		($key, $value) = split(/=/);
		$db{$key} = $value;
	}
	$env = $db{env};
	foreach (split(/<>/,$env)){
		($key, $value) = split(/:/);
		$db2{$key} = $value;
	}
	$crce = $db2{crce}; $md5e = $db2{md5e};
	$acte = $db2{acte}; $commente = $db2{commente};
	$sizee = $db2{sizee}; $mimee = $db2{mimee};
	$datee = $db2{datee}; $anothere = $db2{anothere};
	$gzipence = $db2{gzipence};

	if(!$env){ # cookie擾łȂꍇ
		$acte=1; $commente=1; $sizee=1;
		$datee=1; $gzipence=$gzipenc_def;
	}
}

# HELPy[W\
sub help{
	my $target = shift;

	&print_header('HELP');
	if($target eq 'del'){
		print <<"DEL";
		<h3>eL폜pXɂ</h3>
		<p>
		e҂X̓eL폜ꍇɓ͂܂B<br>
		pX[h͂Ȃ܂ܓeꂽL͊Ǘ҂ɂ폜łȂȂ܂B<br>
		pX[hɂ10̉pLwł܂B
		</p>
DEL
	}
	elsif($target eq 'post'){
		print <<"POST";
		<h3>eppX[hɂ</h3>
		<p>
		SĂ̓e҂́AǗ҂炩ߐݒ肵eppX[hA"postpass"<br>
		tB[hɓ͂Kv܂BeppX[h́ATCg̊Ǘ҂<br>
		肵ĂB
		</p>
POST
	}
	else{
		print "̍ڂɂẴwv͂܂B";
	}
	print "<a href=\"$url\">߂</a>\n";
	&print_footer;
	exit;
}

# T[ofBXNgpʂvZ
sub calc_disk_usage{
	my $sum = 0;
	opendir DIR, "$storedir";
	foreach (readdir DIR){
		next if(/^\.$|^\.\.$/);
		$sum += -s "$storedir/$_";
	}
	closedir DIR;
	return int($sum/1024);
}

# ΃JE^[̈ڐA from minibbsΉ
package shiba;

sub html_out {
	if ( $countlevel > 0 ){
		print "$countdate ";
		&counter; print "$countplusiɂx$countlevelj\n";
	}
}

sub counter {
	my $i, $maxcount, $mincount;
	my @count, @filenumber, @sortedcount;

	for( $i=0 ; $i < $countlevel ; $i++){
		open(IN,"$countfile$i$countfiledat");
		$count[$i] = <IN>;
		$filenumber[$count[$i]] = $i;
		close(IN);
	}
	@sortedcount = sort { $a <=> $b; } @count;
	$maxcount = $sortedcount[$countlevel-1];
	$mincount = $sortedcount[0];
	$maxcount++;
	print $maxcount;
	open(OUT,">$countfile$filenumber[$mincount]$countfiledat");
	print OUT $maxcount;
	close(OUT);
}
1;
# end of package shiba

__END__
