#!/usr/local/bin/perl
use Time::Local;
use strict;
use lite;
require "jcode.pl";
$main::title = 'Elecra Secret Square';
%main::PASS = ('hoge' => 'fuga', 'komaba' => 'hongo');
$main::me = 'el.cgi';
$main::title = 'えれくら内部サイト';
$main::top_file = 'top.html';
$main::list_file = 'dat/list.dat';
$main::notice_file = 'dat/notice.dat';
$main::event_file = 'dat/event.dat';
$main::lock = 'dat/lock';
$main::style = 'el.css';
$main::admin = 'xyzzy';
$main::mailto = '高橋 慧';
$main::new = '[New!]';
$main::dir = './file/'; # /を付ける
$main::platform = 'Unix'; # Unix/Windows/Mac
$main::filecode = 'euc'; # euc/sjis/jis
$main::maxfilesize = 50000; # 0:ファイルサイズ n:nキロバイトまで
$main::permission = 0664; # ファイルに設定するOS上でのパーミッション
@main::name_add_txt = ('pl', 'cgi', 'php', 'rb', 'sht', 'shtm', 'shtml'); # '.txt'を付加する拡張子
@main::name_add_bin = ('exe'); # '.bin'を付加する拡張子
#@main::list = ('title', 'filename','update', 'name', 'pass');
#@main::event = ('eid', 'edate', 'name', 'mail', 'title', 'contact', 'cdate', 'rdate');
@main::key_cookie = ('id', 'pass', 'lastview', 'name', 'fpass', 'mail');
{ package List;
@List::log;
sub regist {
my @TEMP = @_;
my $i = List::search(1, "$TEMP[1]");
if($i >= 0) {
List::error('既に登録されています');
}
unshift(@List::log, \@TEMP);
}
sub update {
my $title = Form::get('title');
my $filename = Form::get('filename');
jcode::convert( \$filename, "euc" );
my $name = Form::get('name');
my $fpass = Form::get('fpass');
Cookie::set('name', $name);
Cookie::set('fpass', $fpass);
my $i = List::search(1, $filename);
if($i < 0) {
List::error('ファイルがありません');
}
my @DAT = @{$List::log[$i]};
if(($fpass ne $DAT[4])&&($fpass ne $main::admin)){
List::error('パスワードが違います');
Cookie::set('fpass', '');
}
$DAT[0] = $title;
$DAT[3] = $name;
splice(@List::log, $i, 1, \@DAT);
}
sub delete {
my $filename = Form::get('filename');
jcode::convert( \$filename, "euc" );
my $fpass = Form::get('fpass');
Cookie::set('fpass', $fpass);
my $i = List::search(1, $filename);
if($i < 0) {
List::error('項目が見つかりません');
}
my @TEMP = @{$List::log[$i]};
if(($fpass ne $TEMP[4])&&($fpass ne $main::admin)){
List::error('パスワードが違います');
}
unlink($main::dir . $filename) or List::error('ファイルを削除できませんでした');
splice(@List::log, $i, 1);
}
sub search {
my($key, $value) = @_;
my @TEMP;
my $i;
for($i=0;$i<=$#List::log;$i++){
@TEMP = @{$List::log[$i]};
if($TEMP[$key] eq $value){
return $i;
}
}
return -1;
}
sub load {
if( !(-f $main::list_file)){
if( !open( DB, "> $main::list_file" ) ) {
List::error( 'データファイルを作れません' );
}
print DB "\n";
close DB;
chmod(0666, $main::list_file);
}
open DB, $main::list_file;
while (){
chomp();
my @temp = split /<>/;
if($#temp > 1 ){
push(@List::log, \@temp);
}
}
close( DB );
}
sub save {
if( !open( DB, ">$main::list_file" ) ) {
List::error( "データファイルを開けません" );
}
foreach (@List::log){
print DB join('<>', @$_)."\n";
}
close( DB );
}
sub error {
MyUtils::free_lock('list');
HTML::error($_[0]);
}
}
{ package Event;
@Event::log;
$Event::nextid;
sub load {
if(!(-f $main::event_file)){
if( !open( DB, "> $main::event_file" ) ) {
Event::error( 'データファイルを作れません' );
}
print DB "\n";
close DB;
chmod(0666, $main::event_file);
}
open DB, $main::event_file;
my $now = time();
$Event::nextid = ;
chomp($Event::nextid);
if($Event::nextid == 0) {$Event::nextid = 1;}
while (){
chomp();
my @temp = split /<>/;
if(($#temp > 1 )&&($temp[1] > $now)){
push(@Event::log, \@temp);
}
}
close( DB );
}
sub save {
if( !open( DB, ">$main::event_file" ) ) {
Event::error( "データファイルを開けません" );
}
print DB "$Event::nextid\n";
foreach (@Event::log){
print DB join('<>', @$_)."\n";
}
close( DB );
}
sub regist {
my @temp;
$temp[2] = Form::get('name');
$temp[3] = Form::get('mail');
if($temp[2] ne ''){ Cookie::set('name', $temp[2]); }
if($temp[3] ne ''){ Cookie::set('mail', $temp[3]); }
$temp[0] = $Event::nextid;
my $xmin = Form::get('min');
my $xhour = Form::get('hour');
my $xmday = Form::get('mday');
my $xmon = Form::get('mon');
$xmon--;
my $xyear = Form::get('year');
if($xmday eq '' || $xmon eq '' || $xyear eq ''){
Event::error('日付を全て入力してください');
}
$temp[1] = Time::Local::timelocal(0, $xmin, $xhour, $xmday, $xmon, $xyear);
$temp[4] = Form::get('title');
if($temp[4] eq ""){Event::error('題名を入力してください');}
$temp[5] = Form::get('contact');
if($temp[5] != 0){
if($temp[2] eq ''){Event::error('名前を入力してください');}
if($temp[3] eq ''){Event::error('メールアドレスを入力してください');}
$xmday = Form::get('cmday');
$xmon = Form::get('cmon');
$xyear = Form::get('cyear');
if($xmday eq '' || $xmon eq '' || $xyear eq ''){
Event::error('連絡期限を入力して下さい');
}
$xmon--;
$temp[6] = Time::Local::timelocal(59, 59, 23, $xmday, $xmon, $xyear);
}
$temp[7] = time();
Event::insert(\@temp);
$Event::nextid++;
}
sub update {
my @temp;
$temp[0] = Form::get('eid');
my $xmin = Form::get('min');
my $xhour = Form::get('hour');
my $xmday = Form::get('mday');
my $xmon = Form::get('mon');
$xmon--;
my $xyear = Form::get('year');
if($xmday eq '' || $xmon eq '' || $xyear eq ''){
Event::error('日付を全て入力してください');
}
$temp[1] = Time::Local::timelocal(0, $xmin, $xhour, $xmday, $xmon, $xyear);
$temp[2] = Form::get('name');
$temp[3] = Form::get('mail');
if($temp[2] ne ''){ Cookie::set('name', $temp[2]); }
if($temp[3] ne ''){ Cookie::set('mail', $temp[3]); }
$temp[4] = Form::get('title');
if($temp[4] eq ""){Event::error('題名を入力してください');}
$temp[5] = Form::get('contact');
if($temp[5] != 0){
if($temp[2] eq ''){Event::error('名前を入力してください');}
if($temp[3] eq ''){Event::error('メールアドレスを入力してください');}
$xmday = Form::get('cmday');
$xmon = Form::get('cmon');
$xmon--;
$xyear = Form::get('cyear');
if($xmday eq '' || $xmon eq '' || $xyear eq ''){
Event::error('連絡期限を入力して下さい');
}
$temp[6] = Time::Local::timelocal(59, 59, 23, $xmday, $xmon, $xyear);
}
$temp[7] = time();
my $i = Event::search(0, Form::get('eid'));
splice(@Event::log, $i, 1);
Event::insert(\@temp);
}
sub insert {
my @DAT = @{$_[0]};
my $i;
for( $i = 0; $i > $#Event::log; $i++){
if(${$Event::log[$i]}[1] < $DAT[1]){
splice(@Event::log, $i, 0, \@DAT);
return;
}
}
splice(@Event::log, $i, 0, \@DAT);
}
sub delete {
my $i = Event::search(0, Form::get('eid'));
if($i < 0) {
Event::error('記事が見つかりません');
}
splice(@Event::log, $i, 1);
}
sub search {
my($key, $value) = @_;
my @TEMP;
my $i;
for($i = 0; $i <= $#Event::log; $i++){
@TEMP = @{$Event::log[$i]};
if($TEMP[$key] eq $value){
return $i;
}
}
return -1;
}
sub error {
MyUtils::free_lock('event');
HTML::error($_[0]);
}
}
{ package HTML;
sub header {
Cookie::save();
print <<"_END_";
Content-type: text/html
$main::title
_END_
}
sub footer {
print <<"_END_";
* by *