#!/usr/local/bin/perl -w

use strict 'vars';

use warnings;

# ソースコードはUTF-8として保存

# utf8プラグマを有効にする

##use open ':std', ':encoding(UTF-8)';

#use utf8;

#use Encode 'decode';

#use Encode 'encode';

use LWP::UserAgent;

use HTTP::Request;

use HTTP::Status;

use HTTP::Request::Common;

$| = 1 ;

umask(0) ;

my $P53 = "off" ; # "off" = off , "on" = on

$P53 = "on" ; # "off" = off , "on" = on

my $KB = 1024 * 400 ; # 出動バイト数

# 自動修復 p53 を作るぞ at hello.2ch.net/_bg/

my $debdeb = 1;

#my $thisCgi = "p53.cgi ver 0.00 (Perl,SJIS) 2015/11/18 FOX. [$P53]";

my $thisCgi = "p53 ver 0.05 (Perl,SJIS) 2015/12/26 FOX. [$P53]";

my $home = $ENV{"HOME"};

my $here = "$home/public_html/_bg";

my $debFile = "$here/1p53.txt";

my $semFile = "$here/sem.p53.txt";

# タイムゾーンの設定

$ENV{'TZ'} = "JST-9";

my $now = time ;

my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($now);

$year += 1900 ;

$mon ++ ;

my $exe_uptime= `/usr/bin/uptime`;

my $LA1 = $exe_uptime;

$LA1 =~ s/.+load averages: //;

$LA1 =~ s/,.+//;

$LA1 =~ s/

//;

if($mon < 10) {$mon = "0$mon" ;}

if($mday < 10) {$mday = "0$mday";}

if($hour < 10) {$hour = "0$hour";}

if($min < 10) {$min = "0$min" ;}

if($sec < 10) {$sec = "0$sec" ;}

my $repFile = "$home/public_html/_service/p53-$year$mon$mday.txt";

$debFile = "$here/logs/p$year$mon$mday.txt";

&debLog("===== $thisCgi =====") ;

#&debLog("here=[$here]") ;

if(-f $semFile)

{

print "$year/$mon/$mday $hour:$min:$sec skip ?

";

my $modtime = time - (stat($semFile))[9];

print " # $modtime pasted.

";

if($modtime < 60*15)

{

print " # < 15 min skiped.

";

exit;

}

print " # > 15 run !

";

}

print "$year-$mon-$mday $hour:$min:$sec run run run !

";

if(open(SEM,"> $semFile"))

{

print SEM "now making $thisCgi

";

close(SEM);

}

my $SRV = &getThisServer() ;

my $BBS = "bbs ???" ;

my $KEY = "key 123 ???" ;

my $SUB = "sub スレタイ ???" ;

my $OLDkey = "old key 123 ???" ;

my $MAEstr = "" ;

my $MAElen = 0 ;

if($min eq "00") {&Report("## これは = $thisCgi)");}

&foxP53() ;

&debLog("### ended. $thisCgi") ;

unlink($semFile);

exit;

#################################################################################

# getThisServer #

#################################################################################

sub getThisServer()

{

my $fName = "/var/tmp/hostname";

my @srv = () ;

if(!open(HOST,"$fName")) {return "??? $fName";}

@srv = <HOST> ;

close(HOST) ;

my $server = $srv[0] ;

return "$server" ;

}

#################################################################################

# foxP53 #

#################################################################################

sub foxP53()

{

#my ($dir,$oFile) = @_;

#&debLog("foxP53()") ;

#&execP53("../newsplus") ;

$BBS = "iPhone" ;

#&execP53("../$BBS") ;

#&execP53("$home/public_html/_zzz/$BBS") ;

#return 1;

my $dir = ".." ;

$dir = "$home/public_html" ;

#&debLog("dir=[$dir]") ;

if(!opendir(DIR, "$dir"))

{

&debLog("foxP53() open Error $dir");

return 0;

}

my @filelist = grep !/^\./, readdir DIR;

closedir(DIR);

foreach my $time (@filelist)

{

#&debLog("foxP53() $time");

$BBS = $time ;

if($BBS =~ /tr$/) {next;}

#&execP53("../$BBS") ;

my $speed = &getSpeed("$home/public_html/$BBS/SETTING.TXT") ;

if(!$speed) {next;}

&execP53($speed,"$home/public_html/_zzz/$BBS") ;

}

return 1 ;

}

#################################################################################

# getSpeed #

#################################################################################

sub getSpeed()

{

my ($txt) = @_ ;

my @set= () ;

return 300;

return 1000;

if(!open(SET,"$txt")) {return 0;}

@set = <SET> ;

close(SET) ;

foreach my $line (@set)

{

if($line =~ /FOX_P53=(\d+)/)

{

my $speed = $1 ;

if($speed < 1) {$speed = 0;}

if($speed > 3333) {$speed = 3333;}

#&debLog("stopSetting($txt)=$line($speed)");

return $speed ;

}

}

return 0;

}

#################################################################################

# existDat #

#################################################################################

sub existDat()

{

my ($key) = @_;

my $dat = "123" ;

# check here

$dat = "$home/public_html/_zzz/$BBS/dat/$key.dat" ;

if(-f "$dat")

{

#&debLog("here =[$dat]") ;

return 1;

}

# check there 1

$dat = "$home/_datArea/$BBS/pool/$key.dat" ;

if(-f "$dat")

{

#&debLog("there 1=[$dat]") ;

return 1;

}

# check there 2

my $k4 = substr($key,0,4) ;

$dat = "$home/_datArea/$BBS/oyster/$k4/$key.dat" ;

if(-f "$dat")

{

#&debLog("there 2=[$dat]") ;

return 1;

}

return 0 ;

}

#################################################################################

# makeNextKey #

#################################################################################

sub makeNextKey()

{

my ($key) = @_;

my $ii = 0 ;

for($ii=0;$ii<200;$ii++)

{

$key ++ ;

if(!&existDat($key)) {return $key;}

}

return 0 ;

}

#################################################################################

# execP53 #

#################################################################################

sub execP53()

{

my ($speed,$bbsDir) = @_;

#&debLog("execP53($bbsDir)") ;

my $dir = "$bbsDir/dat" ;

#&debLog("dir=[$dir]") ;

if(!opendir(DIR, "$dir"))

{

#&debLog("execP53() open Error $dir");

return 0;

}

my @filelist = grep !/^\./, readdir DIR;

closedir(DIR);

my %timefile;

foreach my $file (@filelist)

{

#my $mtime = (stat("$dir/$file"))[9];

my $mtime = (stat("$dir/$file"))[7]; ## file size

#my $mtime = $file; ## file name

#&debLog("execP53() $file = $mtime");

#print "$file = $mtime

";

push @{$timefile{$mtime}},"$file";

}

my $delCount = 0 ;

my $thrCount = 0 ;

foreach my $time (sort {$b <=> $a} keys %timefile)

{

foreach (@{$timefile{$time}})

{

if($_ !~ /\.dat$/) {next;}

$thrCount ++ ;

my $key = $_ ;

$key =~ s/\.dat// ;

$OLDkey = $key ;

$KEY = &makeNextKey($key);

if(!$KEY) {next;}

my $kaimeX = $KEY - $key ;

my $kaime = $KEY - $key ;

if($kaime < 1) {$kaime = 1;}

if($kaime > 5) {$kaime = 5;}

my $limit = int($speed * (0.7 ** $kaime)) ;

my $rNum = getResNum("$dir/$_") ;

if($rNum < 20) {next;}

my $ratio = int($time / $rNum ) ;

if($ratio < $limit) {next;}

if(!(-w "$dir/$_")) {next;}

#next;

# if($time < $KB) {next;}

#if($key ne "1447778990") {next;}

#if($key ne "1447905734") {next;}

#&debLog("execP53($BBS) $time/$rNum=$ratio($speed,$kaime,$limit) $key - $KEY");

if(&removeUme("$dir/$key.dat","$dir/$KEY.dat",$kaimeX,$key))

{

&debLog("execP53($BBS) $time/$rNum=$ratio($speed,\033[0;33m${kaimeX}\033[0;39m,$limit) $key - $KEY");

$delCount ++ ;

}

}

}

#&debLog("execP53($BBS) $delCount/$thrCount found.");

return 1 ;

}

#################################################################################

# removeUme #

#################################################################################

sub removeUme()

{

my ($datFile,$newFile,$kaime,$orgKey) = @_;

#&debLog("removeUme($datFile)") ;

#&debLog("removeUme($newFile)") ;

# check

if(-f $datFile)

{

#&debLog("checkD($datFile)=exist") ;

}

else

{

&debLog("checkD($datFile)=NOT exist") ;

return 0;

}

if(-f $newFile)

{

&debLog("checkN($newFile)=exist") ;

return 0;

}

else

{

#&debLog("checkN($newFile)=NOT exist") ;

}

if(-w $datFile)

{

#&debLog("checkD($datFile)=writable") ;

}

else

{

if($BBS eq "iPhone") {&debLog("checkD($BBS/$KEY)=NOTw");}

return 0;

}

if(-w $newFile)

{

#&debLog("checkN($newFile)=writable") ;

}

else

{

#&debLog("checkN($newFile)=NOT writable") ;

}

#return 0;

# read

my @dat = () ;

if(!open(DAT,"$datFile"))

{

&debLog("removeUme() open Error $datFile");

return 0;

}

@dat = <DAT> ;

close(DAT) ;

my $resMax = @dat ;

if($resMax < 900)

{

#&debLog("removeUme resMax=$resMax") ;

# return 0;

}

#remove

my $ume = 0 ;

my $ii = 0 ;

$MAEstr = "" ;

$MAElen = 0 ;

my @hash= () ;

foreach my $line(@dat)

{

my $jj = $ii + 1 ;

my ($name,$mail,$hizke,$honb,$sub) = split(/<>/,$line) ;

if($jj eq 1)

{

if($name !~ /(●=|侍=|☆=|旭=|麒=)/)

{

#&Report(" ★スレ=skip[$name]");

return 0;

}

else

{

$sub =~ s/

//g;

#&Report(" ★スレ=GO[$name] $orgKey $sub");

&debLog("GO! $BBS:$orgKey:$resMax") ;

}

$SUB = "$sub";

$SUB =~ s/

$// ;

}

$hash[$ii] = &makeHash($ii,$line,$orgKey) ;

$ii ++ ;

if(!&isUmetate($jj,$line,$orgKey,@hash)) {next;}

$ume ++ ;

#&debLog("AAremoveUme $jj=$hizke") ;

}

if($ume < 1)

{

#&debLog("P53 ng($BBS:$KEY) ume=${ume} [$P53]") ;

return 0;

}

##return 0;

# create new dat

#unlink("$newFile") ;

#&debLog("removeUme(new) $newFile") ;

if(-f "$newFile")

{

&debLog("removeUme() already exist $newFile");

#return 0;

}

#&debLog("removeUme($datFile)") ;

#&debLog("ume=$ume") ;

#return 0;

&debLog("P53 \033[0;36mgo\033[0;39m($BBS:$orgKey) ume=${ume} [$P53]") ;

#&debLog("http://${SRV}/test/read.cgi/${BBS}/${OLDkey}/l2") ;

if($P53 ne "on") {return 1;}

#return 0;

if(!open(DAT,"> $newFile"))

{

&debLog("removeUme() open Error $newFile");

return 0;

}

my $p53 = "P53a<>やっとでました<>date<>やっとでた<>title";

$ii = 0 ;

my $xx = 1 ;

my @zz = () ;

$MAEstr = "" ;

$MAElen = 0 ;

foreach my $line(@dat)

{

my $jj = $ii + 1 ;

$ii ++ ;

# バイト文字列(外部からの入力)を内部文字列に変換($strがShift_Jisの場合)

#$line = decode('Shift_Jis',$line);

my ($name,$mail,$hizke,$honb,$sub) = split(/<>/,$line) ;

#my $p53 = "P53a<>やっとでました<>$hizke<>やっとでた<>$sub";

if(&isUmetate($jj,$line,$orgKey,@hash))

{

next ;

}

$zz[$jj] = $xx ;

$xx ++ ;

$p53 = $line ;

##if($jj eq 1) {$p53 =~ s/

$/ p53

/ ;}

#href="../test/read.cgi/iPhone/1447905734/742" target="_blank">

#if($p53 =~ /href=\"\.\.\/test\/read.cgi\/(\.+)\/([-\d]+)\/(\d+)\" target=\"_blank\">/)

if($p53 =~ /\/([0-9a-zA-Z]+)\/([0-9]+)\/([0-9]+)\"/)

{

my $bbs = $1 ;

my $key = $KEY ;

my $nn = $3 ;

if(!$nn) {$nn = 1;}

if($nn >= $jj) {$nn = 1;}

my $yy = $zz[$nn] ;

if(!$yy) {$yy = 1;}

#&debLog(">>$nn - $yy($jj)") ;

#$p53 =~ s/href=\"\.\.\/test\/read.cgi\/\.+\/[-\d]+\/\d+\"/href=\"\.\.\/test\/read.cgi\/$bbs\/$key\/$yy\"/ ;

#$p53 =~ s/href=/href=AAA\/${bbs}\/${key}\/${yy}BBB/ ;

$p53 =~ s/href=\"\.\.\/test\/read\.cgi\/([0-9a-zA-Z]+)\/([0-9]+)\/([0-9]+)\"/href=\"..\/test\/read.cgi\/${bbs}\/${key}\/${yy}\"/ ;

$p53 =~ s/>>[\d]+/>>${yy}/ ;

}

## if($p53 =~ />>([\d]+)/)

## {

## my $nn = $1 ;

## my $yy = $zz[$nn] ;

## #$p53 =~ s/>>[\d]+/>>yy ${nn} → ${yy}/ ;

## $p53 =~ s/>>[\d]+/>>${yy}/ ;

## }

# 内部文字列をUTF-8バイト文字列に変換する場合

#$p53 = encode('Shift_Jis', $p53);

print DAT "$p53";

}

close(DAT) ;

my $szOld = (stat("$datFile"))[7]; ## file size

my $szNew = (stat("$newFile"))[7]; ## file size

if($kaime < 1)

{

if(!open(DAT,">> $newFile"))

{

&debLog("removeUme(2) open Error $newFile");

return 0;

}

my $OLDkey = $KEY ;

$SUB =~ s/

//g;

$p53 = "" ;

$p53 .= "p53 ★<>" ;

$p53 .= "やっとでました<>" ;

$p53 .= "やっと出た<>" ;

#$p53 .= "$thisCgi <br>" ;

$p53 .= "<a href=\"../test/read.cgi/${BBS}/${OLDkey}/1\">>>1</a> 元のスレ " ;

#$p53 .= "<br>" ;

#$p53 .= "$SUB " ;

$p53 .= "<b>$szOld -> $szNew</b> (バイト)<br>" ;

#$p53 .= 'p53 テストに夢中。これ以降書いても消えちゃうかも<br>' ;

#$p53 .= 'p53 テストに夢中。ちょっと通りますよ。再開↓<br>' ;

#$p53 .= 'p53 とは、http://server.maido3.com/?txt=kirei#top<br>' ;

$p53 .= "<>

" ;

print DAT "$p53";

close(DAT) ;

}

# swap

chmod(0555, "$datFile") ;

rename("$datFile","$datFile.tmp") ;

rename("$newFile","$datFile") ;

rename("$datFile.tmp","$newFile") ;

my $sakusei = "作成済";

if($kaime > 10)

#if($kaime > 1)

{

$sakusei = "不作成" ;

unlink("$newFile") ;

#unlink("$datFile.tmp") ;

}

else

{

my $pool = "$home/_datArea/$BBS/pool/$KEY.dat" ;

#&debLog("BBS[$BBS]") ;

#&debLog("newFile[$newFile]") ;

#&debLog("pool[$pool]") ;

#rename("$datFile.tmp","$newFile") ;

my $cmd = "mv $newFile $pool" ;

#&debLog("cmd[$cmd]") ;

system("$cmd") ;

#rename("$newFile","$pool") ;

#_mv("$datFile.tmp","$pool") ;

}

$SUB =~ s/[ \t ]+$//;

$SUB =~ s/\[転載禁止\]//;

$SUB =~ s/©2ch.net//;

$xx -- ;

&Report("$BBS $szOld -(${ume}削)-> $szNew(bytes) $SUB($xx)");

&Report(" 現スレ=http://${SRV}/test/read.cgi/${BBS}/${OLDkey}/l2 ${kaime}回目");

&Report(" 元スレ=http://${SRV}/test/read.cgi/${BBS}/${KEY}/l2 ${sakusei}");

return 1;

}

#################################################################################

# getResNum #

#################################################################################

sub getResNum()

{

my ($fName) = @_;

my @dat = () ;

if(!open(DAT,"$fName"))

{

return 0;

}

@dat = <DAT> ;

close(DAT) ;

my $resMax = @dat ;

return $resMax ;

}

#################################################################################

# HowManyDan #

#################################################################################

sub HowManyDan()

{

my ($honb) = @_;

if(!$honb) {return 0;}

my @n1 = $honb =~ /<br>/gi ; # 数えられる(文字列の個数もOK)

my $ko = scalar(@n1) ; #個数

return $ko ;

}

#################################################################################

# HowMany #

#################################################################################

sub HowMany()

{

my ($word,$honb) = @_;

if(!$honb) {return 0;}

my @n1 = $honb =~ /${word}/gi ; # 数えられる(文字列の個数もOK)

my $ko = scalar(@n1) ; #個数

return $ko ;

}

#################################################################################

# onaji #

#################################################################################

sub onaji()

{

my ($n0,$n1) = @_;

if($n0 < $n1)

{

my $nx = $n0 ;

$n0 = $n1 ;

$n1 = $nx ;

}

if($n0 < 20) {return 0;}

my $sa = int($n0 * 0.2) ;

if($n0 - $n1 < $sa) {return 1;}

return 0 ;

}

#################################################################################

# isUmetate #

#################################################################################

sub isUmetate()

{

my ($resNo,$line,$orgKey,@hash) = @_;

#&debLog("isUmetate()") ;

#&debLog("isUmetate($resNo,$orgKey) Hash=$#hash") ;

if($resNo < 20) {return 0;}

if(!$line) {return 0;}

my ($name,$mail,$hizke,$honb,$sub) = split(/<>/,$line) ;

my $mailLen = length($mail) ;

if($mailLen > 12) {return 1;}

my @gyo = split(/<br>/, $honb) ;

my $gyoN = $#gyo ;

if($gyoN > 13) {return 1;}

if($gyoN > 5)

{

#&debLog("gyoN=$gyoN");

my @ll = () ;

my $ii= 0 ;

foreach my $gg (@gyo)

{

my $lll = length($gg) ;

if($lll < 20) {next;}

if($ii > 1 && !($ll[$ii-1] -30 < $lll && $lll < $ll[$ii-1] +30)) {next;}

$ll[$ii] = length($gg) ;

#&debLog(" -- $orgKey $resNo -- gyoN=$gyoN [$ii]=$ll[$ii]");

$ii++;

}

##if($#ll > 4 && $ll[1] eq $ll[3] && $ll[1] eq $ll[4]) {return 1;}

if($#ll > 4 && &onaji($ll[1],$ll[3]) && &onaji($ll[1],$ll[4]) ) {return 1;}

#return 0;

}

my $abc = $honb ;

$abc =~ s/<br>//gi ;

$abc =~ s/[\. 0-9a-zA-Z\/\: ]//gi ;

my $abcLen = length($abc) ;

if($abcLen < 10) {&debLog("abcLen=$abcLen [$abc][$mail]");}

if($abcLen < 10) {return 1;}

if($honb =~ /Rock/i) {return 1;}

my $len = length($honb);

if($len > 1500) {return 1;}

#if($len > 1000) {&debLog("len=$len");}

#my $dan = &HowManyDan($honb);

#if($dan > 13) {return 1;}

my $href = &HowMany("href",$honb);

#if($href > 5) &debLog("HowMany(href) = $href") ;

if($href > 5) {return 1;}

my $ttp = &HowMany("ttp",$honb);

#if($ttp > 9) &debLog("HowMany(ttp) = $ttp") ;

if($ttp > 9) {return 1;}

#&debLog("Hash=$#hash") ;

if($resNo < 2) {return 1;}

my $resIdx = $resNo-1;

my $ImaStr = $hash[$resIdx] ;

my $ImaLen = length($ImaStr) ;

for(my $iii=0;$iii<$resNo-1;$iii++)

{

my $MaeStr = $hash[$iii] ;

my $MaeLen = length($MaeStr) ;

#&debLog("Hash[$iii] L=$hashL") ;

#&debLog("000($resIdx,$iii) Hash=$#hash len $MaeLen -> $ImaLen

Mae=[$MaeStr]

Ima=[$ImaStr]") ;

if(&samePost($MaeStr,$MaeLen,$ImaStr,$ImaLen))

{

&debLog("($resIdx,$iii) Hash=$#hash len $MaeLen -> $ImaLen

Mae=[$MaeStr]

Ima=[$ImaStr]") ;

return 1 ;

} }

return 0;

my $IMAstr = $honb ;

#$IMAstr =~ s/[0-9a-zA-Z]+//g ;

$IMAstr =~ s/\d+//g ;

#$IMAstr =~ s/(ー|？|！|。|、)//g ;

$IMAstr =~ s/\x83[\x40-\x96]//g ; # カタカナ

#$IMAstr =~ s/\x82[\x9f-\xf1]//g ; # ひらがな

#$IMAstr =~ s/(ア|イ|ウ|エ|オ)//g ;

$IMAstr =~ s/<\/?.*>//g ;

$IMAstr =~ s/

//g ;

$IMAstr =~ s/ //g ;

$IMAstr =~ s/ //g ;

$IMAstr =~ s/<br>//g ;

my $IMAlen = length($IMAstr) ;

if(&samePost($MAEstr,$MAElen,$IMAstr,$IMAlen))

{

&debLog("($resNo) len $MAElen -> $IMAlen

$MAEstr

$IMAstr") ;

$MAEstr = $IMAstr ;

$MAElen = $IMAlen ;

return 1 ;

}

$MAEstr = $IMAstr ;

$MAElen = $IMAlen ;

return 0;

}

#################################################################################

# makeHash #

#################################################################################

sub makeHash()

{

my ($resNo,$line,$orgKey) = @_;

#&debLog("makeHash($resNo,$orgKey)") ;

#if($resNo < 20) {return "";}

if(!$line) {return "";}

my ($name,$mail,$hizke,$honb,$sub) = split(/<>/,$line) ;

my $IMAstr = $honb ;

#$IMAstr =~ s/[0-9a-zA-Z]+//g ;

$IMAstr =~ s/\d+//g ;

#$IMAstr =~ s/(ー|？|！|。|、)//g ;

$IMAstr =~ s/\x83[\x40-\x96]//g ; # カタカナ

#$IMAstr =~ s/\x82[\x9f-\xf1]//g ; # ひらがな

#$IMAstr =~ s/(ア|イ|ウ|エ|オ)//g ;

$IMAstr =~ s/<\/?.*>//g ;

$IMAstr =~ s/

//g ;

$IMAstr =~ s/ //g ;

$IMAstr =~ s/ //g ;

$IMAstr =~ s/<br>//g ;

return "$IMAstr";

}

#################################################################################

# debLog #

#################################################################################

sub samePost()

{

my ($maeStr,$maeLen,$imaStr,$imaLen) = @_;

if($maeStr eq $imaStr) {return 1;}

#if($imaLen < $maeLen - 2) {return 0;}

#if($imaLen > $maeLen + 2) {return 0;}

return 0;

}

#################################################################################

# debLog #

#################################################################################

sub debLog()

{

my ($mes) = @_;

my $now = time ;

my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($now);

$year += 1900 ;

$mon ++ ;

if($mon < 10) {$mon = "0$mon" ;}

if($mday < 10) {$mday = "0$mday";}

if($hour < 10) {$hour = "0$hour";}

if($min < 10) {$min = "0$min" ;}

if($sec < 10) {$sec = "0$sec" ;}

#print "$year/$mon/$mday $hour:$min:$sec $mes

";

if(!$debdeb) {return 0;}

if(!open(LOG,">> $debFile")) {return 0;}

print "$hour:$min:$sec $mes

";

#print LOG "$year/$mon/$mday $hour:$min:$sec $mes

";

print LOG "$min:$sec $mes

";

close(LOG) ;

return 0;

}

#################################################################################

# Report #

#################################################################################

sub Report()

{

my ($mes) = @_;

my $now = time ;

my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($now);

$year += 1900 ;

$mon ++ ;

if($mon < 10) {$mon = "0$mon" ;}

if($mday < 10) {$mday = "0$mday";}

if($hour < 10) {$hour = "0$hour";}

if($min < 10) {$min = "0$min" ;}

if($sec < 10) {$sec = "0$sec" ;}

#print "$year/$mon/$mday $hour:$min:$sec $mes

";

if(!open(LOG,">> $repFile")) {return 0;}

print LOG "$mon/$mday $hour:$min $mes

";

close(LOG) ;

return 0;

}

##################################################

sub _cp

{

local $/;

open(local *SRC, $_[0]) or return;

open(local *DST, '>', $_[1]) or close(SRC), return;

my $st = stat(*SRC);

print DST <SRC>;

close(DST);

close(SRC);

chmod($st->mode, $_[1]);

utime($st->atime, $st->mtime, $_[1]);

1;

}

sub _mv

{

rename($_[0], $_[1]) and return 1;

$! == EXDEV or return;

_cp($_[0], $_[1]) and unlink($_[0]);

}

sub _rm_rf

{

opendir(local *D, $_[0]) or return;

while (defined (my $e = readdir(D))) {

if ($e eq '.' || $e eq '..') {

}

elsif (-d "$_[0]/$e") {

_rm_rf("$_[0]/$e");

}

else {

unlink("$_[0]/$e");

}

}

closedir(D);

rmdir($_[0]);

}

exit;

#################################################################################

# end of hs file #