#! /usr/bin/perl
#
# grmob.cgi
#
# 1.002 : 2/28/08 : 携帯で選択した送信者が正常に選択されないバグを修正
# 1.001 : 2/1/08 : 送信文確認画面モードを追加
# 1.0 : 1/5/08 : Initial revision
#
# Group mail
# 携帯版グループメール
#
# グループモードとユーザーモードとあります。
# - グループモード
# グループモードでは管理人のみメールアドレスを登録することができます。
# 登録されているユーザーはグループパスワードを使ってのみメールを
# 送信することができます。
# 登録削除は管理人のみ可能です。
# - ユーザーモード
# ユーザーモードではユーザーが自分のメールアドレスを登録することができます。
# 登録の際にはグループパスワードが必要になります。その際個人パスワードを
# 設定します。
# メールを送信するときには個人のパスワードが必要になります。
# 登録削除はユーザーが個人のパスワードを使ってすることができます。
#
# いずれのモードもメール送信にはパスワードが必要になります。
#
# http://www.hidekik.com/
#
# Copyright(c) 2005-2008, Hideki Kanayama All rights reserved
use strict;
use CGI qw(:cgi-lib);
use CGI::Carp qw(fatalsToBrowser);
use File::Basename;
use Jcode;
my $lastupdatedyear = 2008;
my $version = "1.002";
my $script = basename($0);
my $setupfile = "grmob_setup.pl";
my $admindat = "adminpwd.dat";
my $groupdat = "grouppwd.dat";
my $charset = "Shift_JIS";
my $lang = 0;
###########################################
our $datafile = "member.dat";
# Title
our $title = ('携帯版グループメール','Group mail')[$lang];
# Back link
our $backlink_en = 1;
our $backlink = '..';
our $backlink_name = '戻る';
# Display admin link
our $setup_en = 1;
our $setup_name = '管理用';
# Group mode 0:user mode, 1:group mode
our $group_mode = 0;
# Bcc copoy 0:off, 1:on
our $bcc_en = 1;
# Confirmation 0:off, 1:on
our $confirm_en = 0;
# return page after sending a mail
# 0: group mail, 1: done page, 2: top page
our $return_page = 0;
# mail command
our $mail_cmd = '/usr/sbin/sendmail -t';
# Recipent, sender non-display mode
our $recip_nondisp = 0;
our $sender_nondisp = 0;
our $sender_dummy = 'dummy@dummy.dum';
# Name on To:, From:, Bcc:
# 1: display, 0:no display
our $mail_name = 1;
#######################################
require "$setupfile" if (-e "$setupfile");
my $q = CGI->new;
my $cgierror = $q->cgi_error;
&error($cgierror) if ($cgierror);
my %in = $q->Vars;
if (! -e "$admindat"){
if ($in{mode} eq 'wradminpwd'){
&wradminpwd($in{pwd},$admindat);
} else {
&setadminpwd($admindat);
}
}
if (! -e "$groupdat"){
if ($in{mode} eq 'grwradminpwd'){
&wradminpwd($in{pwd},$groupdat);
} else {
&setadminpwd($groupdat);
}
}
if ($in{mode} eq 'setmember'){
&setmember;
} elsif ($in{mode} eq 'register_list'){
®ister_list;
} elsif ($in{mode} eq 'register'){
®ister;
} elsif ($in{mode} eq 'delete_list'){
&delete_list;
} elsif ($in{mode} eq 'delete_mail'){
&delete_mail;
} elsif ($in{mode} eq 'setup'){
&setup;
} elsif ($in{mode} eq 'setupwrite'){
&setupwrite;
} elsif ($in{mode} eq 'send'){
&send;
} elsif ($in{mode} eq 'confirm'){
&confirm;
} elsif ($in{mode} eq 'next'){
&nextaction;
} else {
&mainpage;
}
sub mainpage {
&nomember if (! -e $datafile);
my ($maillist,$finnum,$items) = &get_maillist;
&htmlhead($title);
print "$backlink_name
" if ($backlink_en);
# print qq(
\n); print qq(
END
print qq($titleへ);
&htmltail;
}
sub register {
if ($group_mode) {
&error('グループモードなので管理人のみ登録できます。') if (!&checkadmin($in{grouppwd}));
} else {
&error('グループパスワードが違います。') if (!&checkadmin($in{grouppwd},$groupdat));
}
my ($data, $finnum) = &get_maillist;
$finnum++ if (-e $datafile);
my $pwd;
if ($group_mode == 0){
$pwd = &makecrypt($in{persopwd});
}
open(FILE, ">> $datafile") or &error('$datafileが開けません。');
print FILE "$finnum,$in{name},$in{address},$pwd\n";
close(FILE);
print "Location: $script\n\n";
}
sub get_maillist {
my @data;
if (open(FILE, "< $datafile")) {
my @detail;
my $i=0;
my $items;
while ( $title $backlink_name");
} else {
print "Location: $backlink\n\n";
}
}
sub delete_list {
&htmlhead('メールアドレス削除');
my ($maillist,$finnum) = &get_maillist;
print qq( \n);
print qq($titleへ);
&htmltail;
}
sub delete_mail {
my ($data, $finnum) = &get_maillist;
my $inpwd;
if ($group_mode) {
&error('グループモードなので管理人のみ削除できます。') unless (&checkadmin($in{pwd}));
} else {
$inpwd = $data->[$in{delnumber}][3];
&error('個人用パスワードが違います。') unless (&checkcrypt($in{pwd},$inpwd));
}
&error("削除する名前を選択してください。") if ($in{delnumber} eq 'none');
open(FILE, "< $datafile") or &error("$datafileが開けません。");
open(TMP, "> tmp.$$");
while (
grmob.cgi Ver. $version\n";
print "Copyright(C) 2005-$lastupdatedyear, hidekik.com\n";
}
sub htmltail {
©right;
print "\n";
exit;
}
sub error {
my ($msg) = shift;
&htmlhead($msg);
print "