Tadashi Okoshi
slash****@users*****
2005年 7月 12日 (火) 03:01:42 JST
Index: affelio/setup.cgi
diff -u affelio/setup.cgi:1.12 affelio/setup.cgi:1.13
--- affelio/setup.cgi:1.12 Mon Jul 4 10:14:01 2005
+++ affelio/setup.cgi Tue Jul 12 03:01:42 2005
@@ -16,7 +16,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
-# $Id: setup.cgi,v 1.12 2005/07/04 01:14:01 slash5234 Exp $
+# $Id: setup.cgi,v 1.13 2005/07/11 18:01:42 slash5234 Exp $
use strict;
@@ -27,8 +27,11 @@
use DBI;
use lib("./extlib");
use HTML::Template;
+use Error qw(:try);
+
use lib("./lib");
use Affelio;
+use Affelio::misc::CGIError;
use Affelio::misc::MyCrypt;
use Affelio::misc::L10N;
use Affelio::misc::Debug qw(debug_print);
@@ -152,7 +155,6 @@
-
############################################################################
#Sub routines
############################################################################
@@ -164,6 +166,7 @@
$g_actionurl="setup.cgi?stage=10";
}
+#########################################
sub show_10{
$TMPL_FILE = "$g_fsroot/templates/default/owner_side/setup_1.tmpl";
$g_title= $g_lh->maketext("_SETUP_title_10");
@@ -375,17 +378,32 @@
my $userdata_dir="";
my $dir;
- opendir(DIR, "./userdata");
+ try{
+ opendir(DIR, "./userdata");
+ }catch Error with{
+ my $e = shift;
+ error $cgi, "Error in check350: $e";
+ };
while (defined($dir = readdir(DIR))) {
if(($dir ne '.') && ($dir ne '..')
&& ($dir ne 'default') && ($dir ne 'CVS')){
$userdata_dir = "./userdata/$dir";
}
}
- closedir(DIR);
+ try{
+ closedir(DIR);
+ }catch Error with{
+ my $e = shift;
+ error $cgi, "Error in check350: $e";
+ };
#Generate login.cfg file
- open(OUT, "> $userdata_dir/db.cfg");
+ try{
+ open(OUT, "> $userdata_dir/db.cfg");
+ }catch Error with{
+ my $e = shift;
+ error $cgi, "Error in check350: $e";
+ };
print OUT "[db]\n";
print OUT "type=$db_type\n";
print OUT "dbname=$db_dbname\n";
@@ -425,46 +443,73 @@
##########################################################
my @salts = ( "A".."Z", "a".."z", "0".."9", ".", "/" );
my $salt = $salts[int(rand(64))] . $salts[int(rand(64))];
- $g_crypted_password = crypt($g_password, $salt);
+ try{
+ $g_crypted_password = crypt($g_password, $salt);
+ }catch Error with{
+ my $e = shift;
+ error($cgi, "Check400-1: password generation : $e");
+ };
##########################################################
#Determine userdata/..../ directory
##########################################################
my $userdata_dir="";
my $dir;
- opendir(DIR, "./userdata");
- while (defined($dir = readdir(DIR))) {
- if(($dir ne '.') && ($dir ne '..')
- && ($dir ne 'default') && ($dir ne 'CVS')){
- $userdata_dir = "./userdata/$dir";
+ try{
+ opendir(DIR, "./userdata")
+ or error($cgi, "Check400-2: cannot open userdata: $@");
+ while (defined($dir = readdir(DIR))) {
+ if(($dir ne '.') && ($dir ne '..')
+ && ($dir ne 'default') && ($dir ne 'CVS')){
+ $userdata_dir = "./userdata/$dir";
+ }
}
- }
- closedir(DIR);
+ closedir(DIR)
+ or error($cgi, "Check400-3: cannot close userdata: $@");
+ }catch Error with{
+ my $e = shift;
+ error($cgi, "Check400-4: $e");
+ };
##########################################################
#Copy files
##########################################################
- #Copy default face JPEG file
- system("cp -f defaults/profile_face.jpg $userdata_dir/profile_face.jpg");
- system("chmod 666 $userdata_dir/profile_face.jpg");
+ try{
+ #Copy default face JPEG file
+ system("cp -f defaults/profile_face.jpg $userdata_dir/profile_face.jpg");
+ system("chmod 666 $userdata_dir/profile_face.jpg");
- #Copy default preference file
- system("cp -f defaults/preference.cfg $userdata_dir/preference.cfg");
-
- #Generate login.cfg file
- open(OUT, "> $userdata_dir/login.cfg");
- print OUT "[auth]\n";
- print OUT "username=$g_username\n";
- print OUT "password=$g_crypted_password\n";
- close OUT;
+ #Copy default preference file
+ system("cp -f defaults/preference.cfg $userdata_dir/preference.cfg");
+
+ #Generate login.cfg file
+ open(OUT, "> $userdata_dir/login.cfg")
+ or error($cgi, "Check400-8: cannot open login.cfg for W: $@");
+ print OUT "[auth]\n";
+ print OUT "username=$g_username\n";
+ print OUT "password=$g_crypted_password\n";
+ close OUT
+ or error($cgi, "Check400-9: cannot close login.cfg: $@");
+
+ }catch Error with{
+ my $e = shift;
+ error($cgi, "Check400-10: $e");
+ };
##########################################################
#Load Affelio
##########################################################
my $cfg_dir = ".";
- my $af = new Affelio(ConfigDir => $cfg_dir,
- Mode => "init");
- my $dbh = $af->{db};
+ my $af;
+ my $dbh;
+ try{
+ $af = new Affelio(ConfigDir => $cfg_dir,
+ Mode => "init");
+ $dbh = $af->{db};
+ }catch Error with{
+ my $e = shift;
+ error($cgi, "Check400-11: Cannot load Affelio: $e");
+ };
##########################################################
#Database initialization
@@ -477,14 +522,17 @@
CREATE TABLE AFuser_CORE_prof(attribute TEXT, value TEXT)
EOT
if(!$dbh->do($create_tbl_cmd)){
- die $dbh->errstr;
+ error($cgi, "Check400-12: Cannot create prof table: $@");
}
$af->{user__nickname} = $g_nickname;
$af->{user__email1} = $g_email;
-
- $af->{pm}->save_profile();
-
+ try{
+ $af->{pm}->save_profile();
+ }catch Error with{
+ my $e = shift;
+ error($cgi, "Check400-13: Cannot save_profile: $@");
+ };
debug_print("saved profile");
################################
@@ -494,20 +542,29 @@
CREATE TABLE AFuser_CORE_prof_attr(aid INTEGER, name TEXT, type INTEGER)
EOT
if(!$dbh->do($create_tbl_cmd)){
- die $dbh->errstr;
+ error($cgi, "Check400-14: Cannot create attr table: $@");
}
- my $sth = $dbh->prepare(q{insert into AFuser_CORE_prof_attr(aid, name, type) values (?,?,?)}) or die $dbh->errstr;
+ my $sth = $dbh->prepare(q{insert into AFuser_CORE_prof_attr(aid, name, type) values (?,?,?)})
+ or error($cgi, "Check400-15: Cannot prepare SQL statement: $@");
- open(FIN, "$cfg_dir/defaults/AFuser_CORE_prof_attr.csv");
- while(my $line=<FIN>){
- chomp($line);
- my ($aid, $name, $type) = split(',', $line);
- #print "$aid - $name - $type\n";
-
- $sth->execute($aid, $name, $type) or die $af->{db}->errstr;
- }
- close(FIN);
+ try{
+ open(FIN, "$cfg_dir/defaults/AFuser_CORE_prof_attr.csv")
+ or error($cgi, "Check400-16: Cannot open default prof attr.: $@");
+
+ while(my $line=<FIN>){
+ chomp($line);
+ my ($aid, $name, $type) = split(',', $line);
+ #print "$aid - $name - $type\n";
+
+ $sth->execute($aid, $name, $type)
+ or error($cgi, "Check400-17: Cannot execute SQL: $@");
+ }
+ close(FIN);
+ }catch Error with{
+ my $e = shift;
+ error $cgi, "Check400-18: $e";
+ };
################################
#friends DB
@@ -516,7 +573,7 @@
CREATE TABLE AFuser_CORE_friends(uid INTEGER PRIMARY KEY, af_id CHAR(255), nickname TEXT, timestamp TEXT, password TEXT, intro TEXT, option_pid INTEGER, lastupdated TEXT, f2list TEXT)
EOT
if(!$dbh->do($create_tbl_cmd)){
- die $dbh->errstr;
+ error($cgi, "Check400-19: cannot create friends table: $@");
}
################################
@@ -526,7 +583,7 @@
CREATE TABLE AFuser_CORE_erasedfriends(uid INTEGER PRIMARY KEY, af_id CHAR(255), timestamp TEXT)
EOT
if(!$dbh->do($create_tbl_cmd)){
- die $dbh->errstr;
+ error($cgi, "Check400-20: cannot create erased friends table: $@");
}
################################
@@ -536,7 +593,7 @@
CREATE TABLE AFuser_CORE_friendsfriends(uid INTEGER PRIMARY KEY, af_id CHAR(255), nickname TEXT, timestamp TEXT, f1list TEXT)
EOT
if(!$dbh->do($create_tbl_cmd)){
- die $dbh->errstr;
+ error($cgi, "Check400-21: cannot create F2 table: $@");
}
################################
@@ -546,7 +603,7 @@
CREATE TABLE AFuser_CORE_group(gid INTEGER, group_name TEXT, members TEXT, option_pid INTEGER)
EOT
if(!$dbh->do($create_tbl_cmd)){
- die $dbh->errstr;
+ error($cgi, "Check400-22: cannot create group table: $@");
}
################################
@@ -563,7 +620,7 @@
$create_tbl_cmd .= ")";
debug_print("setup: create [$create_tbl_cmd]");
if(!$dbh->do($create_tbl_cmd)){
- die $dbh->errstr;
+ error($cgi, "Check400-23: cannot create permission table: $@");
}
################################
@@ -573,7 +630,7 @@
CREATE TABLE AFuser_SNS_tmp_recvd_hs(sessionid TEXT, timestamp TEXT, af_id CHAR(255), nickname TEXT, DH_key_str TEXT)
EOT
if(!$dbh->do($create_tbl_cmd)){
- die $dbh->errstr;
+ error($cgi, "Check400-24: cannot create tmp_recvd table: $@");
}
################################
@@ -583,7 +640,7 @@
CREATE TABLE AFuser_SNS_tmp_sent_hs(sessionid TEXT, timestamp TEXT, af_id CHAR(255), nickname TEXT, DH_key_str TEXT)
EOT
if(!$dbh->do($create_tbl_cmd)){
- die $dbh->errstr;
+ error($cgi, "Check400-25: cannot create tmp_sent table: $@");
}
################################
@@ -593,51 +650,85 @@
CREATE TABLE AFuser_CORE_message(mid INTEGER PRIMARY KEY, timestamp TEXT, msgtitle TEXT, msgtype TEXT, msgfrom TEXT, msgbody TEXT, readflag INTEGER)
EOT
if(!$dbh->do($create_tbl_cmd)){
- die $dbh->errstr;
+ error($cgi, "Check400-26: cannot create message table: $@");
}
- $dbh->disconnect;
+ try{
+ $dbh->disconnect;
+ }catch Error with{
+ my $e = shift;
+ error $cgi, "Check400-28: db disconnect : $e";
+ };
##########################################################
#Setting Initial Values ...
##########################################################
- undef($af);
- $af = new Affelio(ConfigDir => $cfg_dir);
+ try{
+ undef($af);
+ $af = new Affelio(ConfigDir => $cfg_dir);
+ }catch Error with{
+ my $e = shift;
+ error $cgi, "Check400-29: Affelio load error : $e";
+ };
################################
#Set permission to F1
################################
# n names b i intro email url im
my @flag_array = (1,1,1,1, 1,1, 1,1, 0,0,0,0, 1,1,1,1, 0,0,0,0,0,0, 1);
- $af->{perm}->add_permission("f", "f1", \@flag_array);
+ try{
+ $af->{perm}->add_permission("f", "f1", \@flag_array);
+ }catch Error with{
+ my $e = shift;
+ error $cgi, "Check400-30: $e";
+ };
################################
#Set permission to F2
################################
# n names b i intro email url im
my @flag_array = (1,0,0,0, 0,1, 1,1, 0,0,0,0, 1,1,1,1, 0,0,0,0,0,0, 1);
+ try{
$af->{perm}->add_permission("f", "f2", \@flag_array);
+ }catch Error with{
+ my $e = shift;
+ error $cgi, "Check400-31: $e";
+ };
################################
#Set permission to PB
################################
# n names b i intro email url im
my @flag_array = (1,0,0,0, 0,0, 1,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,0,0, 0);
- $af->{perm}->add_permission("f", "pb", \@flag_array);
+ try{
+ $af->{perm}->add_permission("f", "pb", \@flag_array);
+ }catch Error with{
+ my $e = shift;
+ error $cgi, "Check400-32: $e";
+ };
################################
#Make a new group "dear_friend"
################################
- my $gid = $af->{gm}->add_group($g_lh->maketext("_SETUP_group_dear_friend"));
-
+ my $gid;
+ try{
+ $gid = $af->{gm}->add_group($g_lh->maketext("_SETUP_group_dear_friend"));
+ }catch Error with{
+ my $e = shift;
+ error $cgi, "Check400-33: $e";
+ };
#####################################
#Set permission to group "dear_friend"
#####################################
# n names b i intro email url im
my @flag_array = (1,1,1,1, 1,1, 1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1,1,1, 1);
- $af->{perm}->add_permission("g", $gid, \@flag_array);
-
+ try{
+ $af->{perm}->add_permission("g", $gid, \@flag_array);
+ }catch Error with{
+ my $e = shift;
+ error $cgi, "Check400-34: $e";
+ };
##########################################################
#Others...
@@ -646,19 +737,33 @@
################################
#Copy default template files
################################
- system("cp -fr defaults/af_templates/$g_locale ./$af->{site__user_dir}/af_templates");
+ try{
+ system("cp -fr defaults/af_templates/$g_locale ./$af->{site__user_dir}/af_templates");
+ }catch Error with{
+ my $e = shift;
+ error $cgi, "Check400-35: $e";
+ };
################################
#Rebuild templates_dyn
################################
use Affelio::App::Admin::EditTemplates qw(rebuild);
- Affelio::App::Admin::EditTemplates::rebuild($af);
+ try{
+ Affelio::App::Admin::EditTemplates::rebuild($af);
+ }catch Error with{
+ my $e = shift;
+ error $cgi, "Check400-36: Template rebuild error: $e";
+ };
################################
#Finally, "chmod"
################################
- system("chmod -R 777 ./$af->{site__user_dir}");
-
+ try{
+ system("chmod -R 777 ./$af->{site__user_dir}");
+ }catch Error with{
+ my $e = shift;
+ error $cgi, "Check400-37: $e";
+ };
return("");
}
@@ -709,7 +814,7 @@
sub load_locale{
my $locale_name = shift;
$g_lh = Affelio::misc::L10N->get_handle(($locale_name));
- die "Couldn't make a language handle. \n$@" unless $g_lh;
+ error $cgi, "Couldn't make a language handle. \n$@" unless $g_lh;
}
sub translate_templateL10N_for_setup {