#!/usr/local/bin/perl
# ↑CGIが動かないようでしたらこれを調整してみて下さい。Perl 5.004以上必須です。
BEGIN{
# 「なつみかん」push型LIRS収集CGI「re.cgi」
# Copyright (C) 2000 hiya All Rights Reserved.

# 注意！！このSSIを使うときは、必ず下記設定をしてください。
#################################
# ここから設定範囲

####
# 共通設定ファイルの絶対パス
my $headfile		= "/home/hiya/public_html/hina/bin/nm.ph";

# 設定範囲はここまで
#################################
# これ以降はさわらないでください










































# 読み込み
require qq($headfile);


# シグナル設定
$SIG{'INT'} = $SIG{'BUS'} = $SIG{'HUP'} = $SIG{'QUIT'} = $SIG{'TERM'} = 'autokill';
if($nm::cf::os eq "unix"){
	alarm(60);
}


# 初期値設定
my ($uacheck, $svcheck);

print "Content-type: text/plain; charset=EUC-JP\015\012\015\012";

if($ENV{'REQUEST_METHOD'} eq "POST"){
	# User Agent判定
	foreach(@nm::cf::ua){
		if($ENV{'HTTP_USER_AGENT'} =~ /\Q$_\E/){
			$uacheck = 1;
			last;
		}
	}
	if(!$uacheck){
		print "error\012";
		exit(0);
	}

	my $client = $ENV{'REMOTE_HOST'}.$ENV{'REMOTE_ADDR'};
	$svcheck = 1;
	if(@nm::cf::denyserver){
		foreach(@nm::cf::denyserver){
			if($client =~ /\Q$_\E/i){
				$svcheck = 0;
				last;
			}
		}
	}
	if($svcheck == 1){
		$svcheck = 2;
		if(@nm::cf::allowserver){
			$svcheck = 1;
			foreach(@nm::cf::allowserver){
				if($client =~ /\Q$_\E/i){
					$svcheck = 2;
					last;
				}
			}
		}
	}
	if($svcheck < 2){
		print "error\012";
		exit(0);
	}
}
}


## メイン
require 5.004;
use strict;
use lib ("$nm::cf::lib", "$nm::cf::bin", "$nm::cf::base");

use nm::files;
use CGI;


my $Files = new nm::files;
my $q = new CGI;

my $receive = $q->param('lirs');

if($receive =~ /^LIRS,\d+,\d+,\d+,\d+,.+,.+,.+,.+,$/ ){
	if(length($receive) < 200){
		$Files->add_file($nm::cf::re, $receive, $nm::cf::os);
		chmod 0666, $nm::cf::re;

		print "Content-type: text/plain; charset=EUC-JP\015\012\015\012";
		print "$receive\012";

		exit(0);
	}

}else{
	print "error\012";
	exit(0);
}

exit(0);



















































## サブルーチン群

##
# 自爆サブルーチン
sub autokill{
	print STDERR "$!\n";
	exit(0);
}


1;
