#=============================================== # MyCGIApplication #=============================================== package MyCGIApplication; use MyHTMLApplication; use MySQLApplication; use MyAuthApplication; use MyPluginApplication; use MyMultiLanguageApplication; use MyMailApplication; use MySearchApplication; use JSParams; @ISA = qw(MyHTMLApplication MySQLApplication MyAuthApplication MyPluginApplication MyMultiLanguageApplication MyMailApplication MySearchApplication); #use Common; #@ISA = qw(MyHTMLApplication Common); use strict; use Template; use CSV; #========================================== # 大域変数 #========================================== my $DefaultSendmail = '/usr/sbin/sendmail'; my $SourceCharCode = Jcode::getcode('月火水木金土日 '); #========================================== # 変数取得関数 #========================================== sub Sendmail { my ($this) = @_; return $this->{sendmailPath} if(defined $this->{sendmailPath} or $this->{sendmailPath} ne ''); return $this->{sendmail} if(defined $this->{sendmail} or $this->{sendmail} ne ''); return $DefaultSendmail; } sub SetSendmail { my ($this,$s)=@_; return $this->{sendmail} = $s; } sub IsAdministrator { return shift->MyAuthApplication::IsAdministrator(@_); } sub IsPrivilegedIPAddress { return shift->MyAuthApplication::IsPrivilegedIPAddress(@_); } #========================================== # 変数取得関数 #========================================== sub Debug { my ($App) = @_; return 0 if($App->pParams()->{DoNotAllowDebugMode}); return $App->{Debug} if(defined $App->{Debug}); return 0; # return $Debug; } sub SetDebug { my ($App, $d) = @_; return $App->{Debug} = 0 if($App->pParams() and $App->pParams()->{DoNotAllowDebugMode}); return $App->{Debug} = $d; } sub pArgParams { my ($App) = @_; return $App->{pArgParams}; } sub IsModuleOpen { my ($App, $ModuleName) = @_; my $key = 'p' . $ModuleName; return 0 if(!$App->{$key}); return 0 if(!$App->{$key}->IsOpen($App, $App->pParams(), 0)); return 1; } sub GetTemplateString { my ($this, $TemplateKey, $pTemplateFileTemplates, %arg) = @_; my $pParams = $this->pParams(); my $lang = $this->Language(); if(defined $pParams->{$TemplateKey}) { $TemplateKey = $pParams->{$TemplateKey}; } if($TemplateKey =~ /^\w\w+:[a-zA-Z]+$/) { if($pTemplateFileTemplates->{$TemplateKey}) { $TemplateKey = $pTemplateFileTemplates->{$TemplateKey}; } elsif($arg{DefaultTemplate}) { $TemplateKey = $arg{DefaultTemplate}; } } $TemplateKey = Utils::URLDecode($TemplateKey); $TemplateKey =~ s/{LanguageCode}/$lang/g; return $TemplateKey; } sub GetTemplatePath { my ($this, $dir, $FileNameTemplate, $IsPrint, $EditLinkLabel, $EditTemplatePrivilege, $pTemplateFileTemplates, %arg) = @_; $IsPrint = 1 if(!defined $IsPrint); my $pParams = $this->pParams(); my $lang = $this->Language(); #$this->print("[$dir] $FileNameTemplate => "); if($FileNameTemplate =~ /^\w\w+:[a-zA-Z]+$/) { if($pTemplateFileTemplates->{$FileNameTemplate}) { $FileNameTemplate = $pTemplateFileTemplates->{$FileNameTemplate}; } elsif($arg{DefaultTemplate}) { $FileNameTemplate = $arg{DefaultTemplate}; } } $FileNameTemplate = Utils::URLDecode($FileNameTemplate); #$this->print("MyCGIApplication::GetTemplatePath: $FileNameTemplate => "); my @list = qw(ShortConfName); $dir =~ s/{LanguageCode}/$lang/g; $FileNameTemplate =~ s/{LanguageCode}/$lang/g; foreach my $key (@list) { $dir =~ s/{$key}/$pParams->{$key}/g; $FileNameTemplate =~ s/{$key}/$pParams->{$key}/g; } my $path = ($arg{UseCommon})? Utils::MakePath($pParams->{CommonFileRootDir}, ['Template', $dir, $FileNameTemplate], '/', 0) : Utils::MakePath($pParams->{TemplatePath}, [$dir, $FileNameTemplate], '/', 0); Jcode::convert(\$path, $pParams->{FileSystemCharCode}) if(defined $pParams->{FileSystemCharCode}); #$this->print("MyCGIApplication::GetTemplatePath: path1 [$path]\n"); if(!-e $path) { # my $path2 = Utils::MakePath($pParams->{CommonFileRootDir}, ['Template', $dir, $FileNameTemplate], '/', 0); # $path = $path2 if(-e $path2); #Jcode::convert(\$path, $pParams->{FileSystemCharCode}) if(defined $pParams->{FileSystemCharCode}); $path = Utils::MakePath($pParams->{CommonFileRootDir}, ['Template', $dir, $FileNameTemplate], '/', 0); Jcode::convert(\$path, $pParams->{FileSystemCharCode}) if(defined $pParams->{FileSystemCharCode}); } #$this->print("MyCGIApplication::GetTemplatePath: path2 [$path]\n"); if(!-e $path) { #$this->print("path2 [$path] does not exist\n"); #$this->print(" TemplatePath [$pParams->{TemplatePath}]\n"); $path = Utils::MakePath($pParams->{TemplatePath}, [$dir, $FileNameTemplate], '/', 0); #$this->print(" path: $path\n"); Jcode::convert(\$path, $pParams->{FileSystemCharCode}) if(defined $pParams->{FileSystemCharCode}); } #$this->print("MyCGIApplication::GetTemplatePath: path3 [$path]\n"); #$this->print("MyCGIApplication::GetTemplatePath: CommonFileRootDir [$pParams->{CommonFileRootDir}]\n"); #$this->print("MyCGIApplication::GetTemplatePath: TemplatePath [$pParams->{TemplatePath}]\n"); if(!-e $path) { $this->H3("Error in MyCGIApplication::GetTemplatePath: Can not read [$path] (", $this->pParams()->{TemplatePath}, ")") if($IsPrint); return undef; } #Utils::InitHTML(); #$this->print("ell[$EditLinkLabel]\n"); $this->ShowEditTemplateLink($pParams, $path, "$EditLinkLabel ({PathLink})
\n", $EditTemplatePrivilege) if($EditLinkLabel ne ''); #$this->print("MyCGIApplication::GetTemplatePath: path return [$path]\n"); return $path; } sub GetMailTemplatePath { my ($this, $FileNameTemplate, $IsPrint, $EditLinkLabel, $EditTemplatePrivilege, %arg) = @_; if(!defined $this->pParams()->{SendMail}) { $this->H3("Error: The variable SendMail is not defined"); return ''; } return $this->GetTemplatePath("Mail", $FileNameTemplate, $IsPrint, $EditLinkLabel, $EditTemplatePrivilege, undef, %arg); } sub GetHTMLTemplatePath { my ($this, $FileNameTemplate, $IsPrint, $EditLinkLabel, $EditTemplatePrivilege, %arg) = @_; return $this->GetTemplatePath("HTML", $FileNameTemplate, $IsPrint, $EditLinkLabel, $EditTemplatePrivilege, undef, %arg); } sub GetFileTemplatePath { my ($this, $FileNameTemplate, $IsPrint, $EditLinkLabel, $EditTemplatePrivilege, %arg) = @_; return $this->GetTemplatePath("File", $FileNameTemplate, $IsPrint, $EditLinkLabel, $EditTemplatePrivilege, undef, %arg); } sub GetConfigurationPath { my ($this, $FileNameTemplate, $IsPrint, $EditLinkLabel, $EditTemplatePrivilege, %arg) = @_; my $path = $this->GetTemplatePath("Configuration", $FileNameTemplate, $IsPrint, $EditLinkLabel, $EditTemplatePrivilege, undef, %arg); #$this->print("MyCGIApplication::GetConfigurationPath: path return [$path]\n"); return $path; } sub GetMailTemplatePath_old { my ($this, $FileNameTemplate, $CheckExistense) = @_; $CheckExistense = 1 if(!defined $CheckExistense); # return '' if(!$this->pParams()->{SendMail}); my $lang = $this->Language(); $FileNameTemplate =~ s/{LanguageCode}/$lang/g; Jcode::convert(\$FileNameTemplate, $this->pParams()->{FileSystemCharCode}) if($this->pParams()->{FileSystemCharCode} ne ''); my $TemplateDir = $this->pParams()->{MailTemplatePath}; Jcode::convert(\$TemplateDir, $this->pParams()->{FileSystemCharCode}) if($this->pParams()->{FileSystemCharCode} ne ''); my $path = Utils::MakePath($TemplateDir, $FileNameTemplate, '/', 0); if($CheckExistense and !-e $path) { $this->H3("Error in MyCGIApplication::GetMailTemplatePath: Can not read [$path]"); return undef; } return $path; } sub GetHTMLTemplatePath_old { my ($this, $FileNameTemplate, $CheckExistense) = @_; $CheckExistense = 1 if(!defined $CheckExistense); my $lang = $this->Language(); $FileNameTemplate =~ s/{LanguageCode}/$lang/g; Jcode::convert(\$FileNameTemplate, $this->pParams()->{FileSystemCharCode}) if($this->pParams()->{FileSystemCharCode} ne ''); my $TemplateDir = $this->pParams()->{HTMLTemplatePath}; Jcode::convert(\$TemplateDir, $this->pParams()->{FileSystemCharCode}) if($this->pParams()->{FileSystemCharCode} ne ''); my $path = Utils::MakePath($TemplateDir, $FileNameTemplate, '/', 0); if($CheckExistense and !-e $path) { $this->H3("Error in MyCGIApplication::GetHTMLTemplatePath: Can not read [$path]"); return undef; } return $path; } # 単語の多言語変換とリストの読み込み sub GetPhrase { my ($App, $phrase, $code) = @_; $App->ReadPhrases() if(!defined $App->{pPhrasesHash}); $code = $App->pParams()->{WebCharCode} if(!defined $code); my $w = $App->{pPhrasesHash}->{$phrase}; $w = (defined $w)? $w : $phrase; Jcode::convert(\$w, $code) if(defined $code and $code ne 'ascii'); return $w; } sub ReadPhrases { my ($App, $pParams) = @_; return $App->{pPhrasesHash} if(defined $App->{pPhrasesHash}); my $path = $App->GetConfigurationPath("Phrases-{LanguageCode}.txt", 0, undef, undef, UseCommon => 1); #$App->print("MyCGIApplication::ReadPhrases path [$path]\n"); if(!defined $path or $path eq '') { $App->H2("Error in MyCGIApplication::ReadPhrases: Null path for [Phrases-LanguageCode.txt]\n"); Utils::EndHTML(); exit(); } # $App->ReadPhraseFile($pParams, $path); # $path = $App->GetConfigurationPath("Phrases-{LanguageCode}.txt", 0, undef, undef, UseCommon => 0); my $ret = $App->ReadPhraseFile($pParams, $path); return $ret; } sub ReadPhraseFile { my ($App, $pParams, $path) = @_; my $in = new JFile; my $ret = $in->Open($path, "r"); if(!$ret) { $App->H2("Error in MyCGIApplications::ReadPhraseFile: Can not read [$path].\n"); return {}; } my $phash = ($App->{pPhrasesHash})? $App->{pPhrasesHash} : {}; while(1) { my $line = $in->ReadLine(); last if(!defined $line); my ($key, $target) = ($line =~ /^(.*?)=(.*)$/); next if(!defined $key); Utils::DelSpace($target); $phash->{$key} = $target; #$App->print("k: [$key]=[$target]\n"); } $in->Close(); return $App->{pPhrasesHash} = $phash; } sub ShowEditTemplateLink { my ($App, $pParams, $path, $Label, $Privilege) = @_; my $lang = ($pParams->{Language})? $pParams->{Language} : 'en'; $Label = ($lang eq 'en')? 'edit' : '編集' if($Label eq ''); $Privilege = 'EditTemplate' if($Privilege eq ''); return if(!$App->HasPrivilege($Privilege, 0)); $path = $App->GetTemplatePath($path) if(!-e $path); my $EncodedPath = Utils::URLEncode($path); my $Option = $App->BuildCGIOption( { Action => "EditTemplate::EditFile", NextAction => $pParams->{Action}, PrevAction => $pParams->{Action}, }, [qw(+Action NextAction)], # [qw(+)], ); if($Label =~ /{PathLink}/) { my $link = "{ScriptPath}?$Option&Path=$EncodedPath\" target=\"_self\">$path"; $Label =~ s/\{PathLink\}/$link/g; $App->PrintRawHTML($Label); } else { $App->PrintRawHTML("{ScriptPath}?$Option&Path=$EncodedPath\" target=\"_self\">$Label\n"); } return $path; } #============================================================ # 一般静的関数 #============================================================ sub BuildPreregistrationCode { my ($App, $sn, $email) = @_; ($sn, $email) = ($App, $sn) if(ref $App !~ /Hash/i); my $date = time(); srand(); return $date . $sn . int(rand(1000)) . $email; } sub BuildRegistrationCode { my ($sn, $email) = @_; my $date = time(); srand(); return $date . $sn . int(rand(1000)) . $email; } sub WeekdayString { my ($iwday) = @_; my @wday= ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); return $wday[$iwday]; } #============================================================ # コンストラクタ、デストラクタ #============================================================ sub new { my ($module, %args) = @_; my $this = {}; bless $this; # $this->SUPER::new(@_); #print "m: $module\n"; # $this->Initialize(%args); return $this; } sub DESTROY { my $this = shift; $this->SUPER::DESTROY(@_); } sub Initialize { my ($this, %args) = @_; #=============================================== # Applicationオブジェクト初期設定 #=============================================== if($this->SUPER::Initialize() < 0) { return $this->{LastError} = "-1: Application Initialize Error"; } my $pParams = $this->BuildParameterHash(); $pParams->{IPAddress} = $this->RemoteIPAddress(); foreach my $var (keys %args) { my $val = $args{$var}; $var =~ s/^-//; $pParams->{$var} = $val; } $pParams->{CommonFileRootDir} = $pParams->{BinFileRootDir}; if($pParams->{ProgramBaseName} =~ /5/) { $pParams->{CommonFileRootDir} =~ s/\/$pParams->{ProgramBaseName}\/$pParams->{SubName}$/\/Common5/; } else { $pParams->{CommonFileRootDir} =~ s/\/$pParams->{ProgramBaseName}\/$pParams->{SubName}$/\/Common3/; } #Utils::InitHTML(); #$this->print("ProgramBaseName: [$pParams->{ProgramBaseName}]
\n"); #$this->print("SubName: [$pParams->{SubName}]
\n"); #$this->print("BinFileRootDir: [$pParams->{BinFileRootDir}]
\n"); #$this->print("CommonFileRootDir: [$pParams->{CommonFileRootDir}]
\n"); #Utils::InitHTML(); #print "aa: $pParams->{WebRoot} [$0]
\n"; $pParams->{ProgramPath} = $this->SpeculateProgramPath($0, $pParams->{WebRoot}); $pParams->{ProgramName} = $this->ProgramName(); #print "ProgramPath: $pParams->{ProgramPath} [$0]
\n"; #print "ProgramName: $pParams->{ProgramName} [$0]
\n"; if($pParams->{sendmail}) { $this->SetSendmail($pParams->{sendmail}); } if($args{-pMainModule}) { $this->{pMain} = $args{pMainModule}; } if($args{-OutputMode}) { $this->SetOutputMode($args{-OutputMode}); } else { $this->SetOutputMode("auto"); } if($args{-Debug}) { $this->SetDebugMode($args{-Debug}); } $this->SetHTMLHeader($args{-WebTitle}, $args{-WebCharSet}, $args{-WebTarget}, $args{-CSSPath}, pHeaderFiles => $args{-pHeaderFiles}); $this->SetDebug($args{-Debug}) if(defined $args{-Debug}); #========================================== # コマンドラインオプション読み込み: # $App->ReadSettingより前に実行しないと、POSTの情報を受け取れない #========================================== my %Arg; if(!defined $args{-ReadArgs} or $args{-ReadArgs} != 0) { # $App->AddArgument("--Action", "--Action=[]", ''); # $App->AddArgument("--DebugMode", "--DebugMode: Set DebugMode", ''); if($this->ReadArgs(0, $this->WebCharCode(), 0, 1) != 1) { return $this->{LastError} = "-2: ReadArgs Error"; } my $Args = $this->Args(); $this->SetCGIForm(); %Arg = $Args->GetArgHash(); foreach my $key (keys %Arg) { $Arg{$key} = Utils::InvalidateHTMLTags($Arg{$key}); #print "$key: $Arg{$key}\n"; } Utils::MergeHash($pParams, \%Arg); $this->SetLanguage($pParams->{Language}); } $this->SetHTMLHeader($args{-WebTitle}, $args{-WebCharSet}, $args{-WebTarget}, $args{-CSSPath}, pHeaderFiles => $args{-pHeaderFiles}); #$this->print("WC: $args{-WebCharSet}\n"); #========================================== # 初期設定ファイル読み込み #========================================== if(!defined $args{-ReadArgs} and $args{-ReadArgs} != 0) { my $IniFile = $this->OpenIniFile($pParams->{ProgramPath}, 1); $this->AddIniFileVariable("\\Preferences\\AllowedIPAddress", "AllowedIPAddress", ""); # $this->ReadSetting(); } #========================================== # 引数を%Paramsに設定する #========================================== Utils::MergeHash($pParams, \%Arg); #=============================================== # cgi-bin/*.ini 初期設定ファイル読み込み #========================================== if($pParams->{ReadCGIIni}) { my $IniFile = $this->OpenIniFile($pParams->{ProgramPath}, 1); # $this->AddIniFileVariable("\\Preferences\\TextboxWidth", "TextboxWidth", 100); $this->ReadSetting(); } # $this->{TextboxWidth} = 100 if(!defined $App->{TextboxWidth} or $App->{TextboxWidth} < 10); # $this->{TextboxHeight} = 10 if(!defined $App->{TextboxHeight} or $App->{TextboxHeight} < 1); #=============================================== # BinDir/*.ini 初期設定ファイル読み込み #========================================== if($pParams->{IniFilePath} eq '' and $pParams->{IniFileName}) { $pParams->{IniFilePath} = Utils::MakePath($pParams->{BinFileRootDir}, $pParams->{IniFileName}, '/', 0); } #$this->print("Ini [$pParams->{IniFilePath}]\n"); if($pParams->{IniFilePath}) { $this->ReadIniFile($pParams, $pParams->{IniFilePath}); #$this->print("NoMessageForNonDBMode [$pParams->{NoMessageForNonDBMode}]\n"); #$this->print("MyCGIApplication: ExcludeModules [$pParams->{ExcludeModules}]\n"); } #$this->print("mm[$pParams->{MenuMode}][$this->{MenuMode}]\n"); #=============================================== # CSV 初期設定ファイル読み込み # DB->OpenDBでDB設定が上書きされるので、OpenDBの後で読み込む # => DBConfigArrayを上書きするようにしたので解決 #=============================================== my $RetReadCSVConf; if($this->can('ReadCSVConfigurationFile')) { $RetReadCSVConf = $this->ReadCSVConfigurationFile($pParams, 'CSVConfiguration:Conf', 0, 'Template', 'EditTemplate', DefaultTemplate => 'Configuration-Template.csv') } #$this->print("DB[$pParams->{DBName}]\n"); #=============================================== # データベースオブジェクト作成 #1 #=============================================== #print "DC: $args{-DBConfigName}\n"; my ($DB, $DBConfigName, $DBMName, $DBServer, $DBUser, $DBPassword, $DBName, @DBTables); if(defined $args{-DBConfigName}) { $this->SetHTMLHeader('Error', $pParams->{WebCharSet}, undef, $pParams->{CSSPath}); ($DB, $DBConfigName, $DBMName, $DBServer, $DBUser, $DBPassword, $DBName, @DBTables) = $this->OpenDB($args{-DBConfigName}, $args{-pDBConfigArray}); } #$this->print("DB[$DBName]\n"); #========================================== # デバッグモード、言語の設定 #========================================== if($args{-DoNotAllowDebugMode}) { $pParams->{Debug} = $Arg{DebugMode} = 0; } else { if(defined $Arg{DebugMode} and $Arg{DebugMode} ne '') { $pParams->{Debug} = $Arg{DebugMode}; } } $this->SetDebug($pParams->{Debug}); $this->SetLanguage($pParams->{Language}); if(Utils::IsCGI()) { $this->SetPrintCharCode($pParams->{WebCharCode}); } else { $this->SetPrintCharCode($pParams->{PrintCharCode}); } #=============================================== # データベースオブジェクト作成 #2 #=============================================== #print "DC: $args{-DBConfigName}\n"; if(defined $args{-DBConfigName}) { $RetReadCSVConf=0; if($RetReadCSVConf) { undef $DB; $DBConfigName = ''; $DBMName = $pParams->{DBMName} if($pParams->{DBMName} ne ''); $DBServer = $pParams->{DBServer} if($pParams->{DBServer} ne ''); $DBPassword = $pParams->{DBPassword} if($pParams->{DBPassword} ne ''); $DBName = $pParams->{DBName} if($pParams->{DBName} ne ''); $DB = new SQLDB($DBMName); #$this->print("DBp[$DBServer, $DBUser, $DBPassword, $DBName]\n"); my $ret = 0; if($DB) { $ret = $DB->Open($DBServer, $DBUser, $DBPassword, $DBName, undef, 0, 0); } if(!$ret) { ($DB, $DBConfigName, $DBMName, $DBServer, $DBUser, $DBPassword, $DBName, @DBTables) = (undef); # = (undef, '', undef, undef, undef, undef, undef, ()); } #$this->print("DB[$DB]\n"); } if(!$DB) { #$this->print("DB Error\n"); $this->print(""); $this->H2("Error in SQLDB:: Can not find DB configuration for [$args{-DBConfigName}]\n") if(defined $args{ErrorPrint} and $args{ErrorPrint}); return $this->{LastError} = "-3: OpenDB Error"; } #$this->print("OK\n"); #$this->print("DB: $DBConfigName\n"); #$this->print("DB[$DBName]\n"); $DB->SetApplication($this); $DB->SetDBCharCode($pParams->{SQLCharCode}); $DB->SetSourceCharCode($pParams->{WebCharCode}); $DB->SetDebug($pParams->{Debug}); $DB->SetAutoIncrementColumn("sn"); $this->SetDB($DB); $pParams->{DBConfigName} = $DBConfigName; $pParams->{DBMName} = $DBMName; $pParams->{DBServer} = $DBServer; $pParams->{DBUser} = $DBUser; $this->{DBPassword} = $DBPassword; $pParams->{DBName} = $DBName; $pParams->{pDBTables} = \@DBTables; $pParams->{UsersTableName} = $DBTables[0]; } #========================================== # DB変数を再設定する # 変数の優先順位は # コマンドライン変数 => DB変数 => スクリプト中の初期値・設定値 #========================================== my %ArgParams = %$pParams; $this->{pArgParams} = \%ArgParams; # ConfStartupでも呼んでいる # if(defined(&{"$this->MergeDBVars"})) { if($this->can('MergeDBVars')) { $this->MergeDBVars($pParams); Utils::MergeHash($pParams, \%Arg); } #$this->H1("PT[$pParams->{ProceedingsTitle_jp}]"); #========================================== # 言語の設定が終わったら、言語依存の変数を取得する #========================================== # ConfStartupでも呼んでいる $this->UpdateParams($pParams); $this->SetHTMLHeader($args{-WebTitle}, $args{-WebCharSet}, $args{-WebTarget}, $args{-CSSPath}, pHeaderFiles => $args{-pHeaderFiles}); #========================================== # 共通のCGIリンク #========================================== $pParams->{BaseCGILink} = "$pParams->{ScriptPath}?" ."Language=$pParams->{Language}&" ."ExtendedMenu=$pParams->{ExtendedMenu}&ShowAll=$pParams->{ShowAll}"; #$this->print("WC: $args{-WebCharSet}\n"); #$this->print("M: $pParams->{SendMail}\n"); #if($pParams->{SendMail}) { #} #$this->print("AdminPluginDir [$pParams->{AdminPluginDir}] does not exist.\n") if($pParams->{AdminPluginDir} ne '' and !-d $pParams->{AdminPluginDir}); #$this->print("UserPluginDir [$pParams->{UserPluginDir}] does not exist.\n") if($pParams->{UserPluginDir} ne '' and !-d $pParams->{UserPluginDir}); #$this->print("NoLogonPluginDir [$pParams->{NoLogonPluginDir}] does not exist.\n") if($pParams->{NoLogonPluginDir} ne '' and !-d $pParams->{NoLogonPluginDir}); #$this->print("pHeaderFiles=$args{-pHeaderFiles}\n"); $pParams->{DBRegistersTableName} = $pParams->{UsersTableName} if($pParams->{DBRegistersTableName} eq ''); $pParams->{UsersTableName} = $pParams->{DBRegistersTableName} if($pParams->{UsersTableName} eq ''); $pParams->{ShortAppName} = $pParams->{ShortLaboratoryName} if($pParams->{ShortAppName} eq ''); $pParams->{ShortAppName} = $pParams->{ShortConfName} if($pParams->{ShortAppName} eq ''); $pParams->{ShortLaboratoryName} = $pParams->{ShortAppName} if($pParams->{ShortLaboratoryName} eq ''); $pParams->{ShortLaboratoryName} = $pParams->{ShortConfName} if($pParams->{ShortLaboratoryName} eq ''); $pParams->{ShortConfName} = $pParams->{ShortAppName} if($pParams->{ShortConfName} eq ''); $pParams->{ShortConfName} = $pParams->{ShortLaboratoryName} if($pParams->{ShortConfName} eq ''); return 1; } sub ReadCSVConfigurationFile { my ($this, $pParams, $FileNameTemplate, $IsPrint, $EditLinkLabel, $EditTemplatePrivilege, %arg) = @_; my $path = $this->GetConfigurationPath($FileNameTemplate, $IsPrint, $EditLinkLabel, $EditTemplatePrivilege, %arg); #$this->print("Config[$path]\n"); return -1 if(!-f $path); my $csv = new CSV; if(!$csv->Open($path, 'r', 0)) { return -1; } my $IsParams = 0; while(!$csv->eof()) { my @a = $csv->ReadNextLine(); next if($a[0] eq ''); #$this->print("$a[0]: $a[1]\n"); if($a[0] =~ /^#Parameters/) { $IsParams = 1; next; } elsif($a[0] =~ /^#EndParameters/) { $IsParams = 0; next; } elsif($a[0] =~ /^#/) { $IsParams = 0; next; } if($IsParams) { if($a[0] =~ /^(.*)_(jp|en)$/) { my $key = $1; my $lang = $2; #$this->print("set [$a[1]] to var [\$$key\{$lang\}]\n"); my $cmd = "\$$key\{$lang\} = \"$a[1]\";"; #$this->print("cmd [$cmd]\n"); eval($cmd); } #$this->print("set [$a[1]] to var [$a[0]]\n"); my $key = $a[0]; my $val = $a[1]; if($a[0] =~ /^\$/ or $a[1] =~ /\$/) { my $cmd = "$key = \"$val\";"; #$this->print("cmd [$cmd]\n"); eval($cmd); } else { #$this->print("key [$key] = [$val]\n"); $pParams->{$key} = $val; } # @DBConfigArrayなどを上書きする場合、個別のApplication ObjectでReadCSVConfigurationFileをOverrideすること # if($key =~ /^DB/) { # my $n = @DBConfigArray; # for(my $j = 0 ; $j < $n ; $j += 7) { # if($key eq 'DBMName') { # $DBConfigArray[$j*7 + 1] = $pParams->{$key}; # } # elsif($key eq 'DBServer') { # $DBConfigArray[$j*7 + 2] = $pParams->{$key}; # } # elsif($key eq 'DBUser') { # $DBConfigArray[$j*7 + 3] = $pParams->{$key}; # } # elsif($key eq 'DBPassword') { # $DBConfigArray[$j*7 + 4] = $pParams->{$key}; # } # elsif($key eq 'DBName') { # $DBConfigArray[$j*7 + 5] = $pParams->{$key}; # } # } # } } } #$this->print("ForIEM: $pParams->{ForIEM}\n"); #$this->print("pParams{Conf}: $pParams->{ConfName}\n"); #$this->print("ConfName{jp}: $ConfName{jp}\n"); #$this->print("ConfName_jp: $pParams->{ConfName_jp}\n"); $csv->Close(); } sub ReadIniFile { my ($App, $pParams, $IniPath, $section, $pHash) = @_; $pHash = $pParams if(!defined $pHash); my $pTFT = $pParams->{pTemplateFileTemplates}; $IniPath = Utils::MakePath($pParams->{BinFileRootDir}, $IniPath, '/', 0) if($IniPath !~ /[\\\/]/); #$App->print("Ini=[$IniPath] section=[$section]\n"); return 0 if(!-e $IniPath); my $in = new JFile($IniPath, 'r'); return 0 if(!$in); $in->SkipTo("[$section]") if($section ne ''); while(!$in->eof()) { my $line = $in->ReadLine(); #$App->print("line:[$line]\n"); next if($line =~ /^[\[\#]/); last if($section ne '' and $line =~ /^\[/); Utils::DelSpace($line); my ($key, $val) = ($line =~ /^\s*(\S.*?)\s*=\s*(.*?)\s*$/); next if($key eq '' or !defined $val); while($val =~ /\\$/) { $val =~ s/\\$//; my $val2 = $in->ReadLine(); #$App->print("line2:[$val2]\n"); last if($val2 !~ /^\t/); Utils::DelSpace($val2); $val .= $val2; } #$App->print("$key: [$val]\n"); if($pTFT and $key =~ /:(HTML|Mail|File)$/i) { $pTFT->{$key} = $val; } else { $pHash->{$key} = $val; } } return $pHash; } sub MergeCategory { my ($App, @category) = @_; my %a; for(my $i = 0 ; $i < @category ; $i++) { my @b = Utils::Split("\\s*,\\s*", $category[$i]); for(my $j = 0 ; $j < @b ; $j++) { #$App->print("$i,$j: $b[$j]\n"); $a{$b[$j]}++; } } my $str = ""; foreach my $key (keys %a) { if($str eq '') { $str = $key; } else { $str .= ", $key"; } } return $str; } sub MergePrivilege { my ($App, @privilege) = @_; my %a; for(my $i = 0 ; $i < @privilege ; $i++) { my @b = Utils::Split("\\s*,\\s*", $privilege[$i]); for(my $j = 0 ; $j < @b ; $j++) { #$App->print("$i,$j: $b[$j]\n"); $a{$b[$j]}++; } } my $str = ""; foreach my $key (keys %a) { if($str eq '') { $str = $key; } else { $str .= ", $key"; } } return $str; } sub Execute2 { my ($App, $pParams, $Action) = @_; if($Action =~ /^(.*)::(.*)$/) { my $ModuleName = $1; my $Action = $2; my $pModule = $App->{"p$ModuleName"}; if($pModule) { $pModule->$Action($App, $pParams); } else { $App->H3("Error in MyCGIApplication::Execute2: Can not find module [$ModuleName].\n"); } } elsif($pParams->{Action} ne '') { $App->SetHTMLHeader($App->GetPhrase('Invalid Action') . " - $pParams->{ShortConfName}", "_blank", "../css/Master.css"); $App->H2("Error in MyCGIApplication::Execute2: Invalid Action [$pParams->{Action}]"); #no strict; # my $Action = $pParams->{Action}; # &$Action(); #use strict; } return; } sub Execute { my ($this, $pParams) = @_; my $App = $this; if(ref $pParams ne 'HASH') { ($this, $App, $pParams) = @_; } if($pParams->{Action} eq 'ExtendMenu') { $pParams->{ExtendedMenu} = 1; $pParams->{Action} = $pParams->{PrevAction}; # $pParams->{DoNotShowMenu} = 1; } elsif($pParams->{Action} eq 'ShrinkMenu') { $pParams->{ExtendedMenu} = 0; $pParams->{Action} = $pParams->{PrevAction}; # $pParams->{DoNotShowMenu} = 1; } my $Action = $pParams->{Action}; #$pParams->{DoNotShowMenu} = 1; # $Action = 'StartPage::ShowPage' if($Action eq 'Logon'); # $Action = 'Logon::ShowPage' if($Action eq 'Logon'); $Action = 'StartPage::ShowPage' if($Action eq 'ShowStartPage'); my ($ModuleName) = ($Action =~ /^(.*?)::/); #$this->print("Action: $Action ModuleName: $ModuleName E: $pParams->{ExtendedMenu} ChildFrame: $pParams->{IsChildFrame}\n"); if($Action !~/Logon/ and $Action !~ /^Download/ and $Action !~ /::Download/ and $pParams->{SubAction} !~ /^Download/ and $Action !~ /^NoLogon\w+::\w+$/ and !$App->{pNoLogonModuleHash}{$ModuleName}) { $App->ShowMenu($pParams, $pParams->{EMail}, $pParams->{Password}); } #$this->print("a[$Action]\n"); if($Action eq 'ExtendMenu' or $Action eq 'ShrinkMenu') { } elsif($Action =~ /^(.*)::(.*)$/) { my $ModuleName = $1; my $Action = $2; #$this->print("Execute [$ModuleName][$Action]\n"); my $pModule = $this->{"p$ModuleName"}; if($pModule) { #$this->print("Execute [$ModuleName][$Action]\n"); $pModule->$Action($this, $pParams); #exit; } else { $this->H3("Error in MyCGIApplication::Execute: The module [$ModuleName] is not loaded."); return; } } else { my ($act) = ($Action =~ /^\s*([^:]*)/); $act = $Action if(!defined $act); #$this->print("a[$act]\n"); no strict; if($this->can($act)) { #$this->print("a2[$act]\n"); $this->$act($this, $pParams); } elsif(main->can($act)) { #$this->print("a3[$act]\n"); &{"main::$act"} ($this, $this, $pParams); # eval("main::$act();"); } elsif($pParams->{Action} ne '') { $this->SetHTMLHeader($App->GetPhrase('Invalid Action') . " - $pParams->{ShortConfName}", "_blank", $pParams->{CSSPath}); $this->H2("Error: Invalid Action [$Action]"); # $this->H3("Error: Can not execute [$Action].\n"); } use strict; } # $this->SaveSetting(); $this->EndHTML(); delete $this->{pHeaderFiles}; $this->SetHTMLHeader($App->GetPhrase('Post execution message') . " - $pParams->{ShortConfName}", "_blank", undef); } #========================================== # 一般関数 #========================================== sub UpdateParams { my ($this, $pParams) = @_; return $pParams; } sub BuildParameterHash { my ($this) = @_; return $this->{pParams} if($this->{pParams}); return $this->{pParams} = {}; } sub BuildAllParameters { my ($this, $pParams) = @_; my $all = ''; foreach my $key (sort keys %$pParams) { next if($key =~ /pass/i); $all .= "$key=$pParams->{$key}\n"; #$this->print("key[$key]\n"); } $pParams->{AllParameters} = $all; #$this->print("a[$all]\n"); return $all; } #======================================================== # 日付関係 #======================================================== sub CheckPeriod { my ($App, $time, $start, $end) = @_; $time = $App->TimeStrToInt($time); #$App->print("t[$time]\n"); if(defined $start and $start > 0) { $start = $App->TimeStrToInt($start); #$App->print("s[$start]\n"); return -1 if($time < $start); } if(defined $end and $end > 0) { $end = $App->TimeStrToInt($end); #$App->print("e[$end]\n"); return 1 if($end < $time); } return 0; } sub GetDate { my($App, $sec, $min, $hour, $mday, $mon, $year, $wday) = localtime(time); $year += 1900; $mon++; return $year, $mon, $mday, $wday; } # 年、月 # その月の最初の曜日、その月の合計日数 # 基準: (Sun)10/17/1582 sub GetFirstWday { my ($App, $yyyy, $mm) = @_; return Utils::GetFirstWday($yyyy, $mm); } sub TimeStrToIntForSchedule { my ($this, $timestr) = @_; return $timestr if($timestr =~ /^-(\d+)$/); #print "t: $timestr
\n"; # $timestr = new Jcode($timestr)->z2h; my $ZenStr = "0-9A-Za-z ()_@−+:/"; Jcode::convert(\$ZenStr, $this->{WebCharCode}, $this->{PerlCharCode}); $timestr = new Jcode($timestr)->tr($ZenStr, '0-9A-Za-z ()_@-+:/'); #print "t: $timestr
\n"; return -1 if($timestr == -1 or $timestr =~ /\*/ or $timestr eq ''); return -2 if($timestr == -2 or $timestr =~ /\?/); #$this->print("t[$timestr]\n"); my @t = split(/[\s:]+/, $timestr); if($t[0] >= 90) { # $timestr = '?'; return -2; } elsif($t[0] >= 80) { # $timestr = '*'; return -1; } elsif($timestr =~ /AM/i) { $timestr =~ s/AM//i; } elsif($timestr =~ /PM/i) { $timestr =~ s/PM//i; if($timestr =~ /(\d+):(\d+)/) { my $hour = $1 + 12; my $min = $2; $timestr = "$hour:$min"; } else { $timestr += 12; } } #$this->print("t2[$timestr]\n"); if($timestr =~ /^(\d{1,2})(\d\d)$/) { $timestr = "$1:$2"; } #print "t: $timestr
\n"; if($timestr =~ /^(\d+)\.(\d*)/) { return $timestr * 60; } if($timestr =~ /^(\d+)(:?)(\d*)/) { return $1*60 + $3; } $this->H2("Input error: [$timestr] is not valid time."); return -1; } sub HourTimeStrToMiniteTime { my ($this, $timestr) = @_; return -1 if($timestr eq '' or $timestr eq '*' or $timestr < 0); if($timestr =~ /^\s*(\d+)\s*$/) { return $timestr * 60; } if($timestr =~ /^\s*(\d+):(\d+)\s*$/) { my $h = $1; my $m = $2; return $h * 60 + $m; } print "Error in HourTimeStrToTime: Invalid str [$timestr]
\n"; return ''; } sub TimeStrToTime { my ($this, $datestr) = @_; #print "datestr: $datestr
\n"; return '' if($datestr eq ''); my ($nsec, $nmin, $nhour, $nmday, $nmonth, $nyear, $wday, $yday, $isdst) = localtime(time()); $nyear += 1900; $nmonth -= 1; my ($year, $month, $mday); my ($hour, $min, $sec) = (0, 0, 0); if($datestr =~ /^(\d+)$/ and $datestr > 31) { my $str = Utils::BuildDateString($datestr); return $datestr; } elsif($datestr =~ /^\s*(\d+)\s*$/) { $mday = $1; } elsif($datestr =~ /^\s*(\d+)\/(\d+)\/(\d+)/) { $year = $1; $month = $2; $mday = $3; } elsif($datestr =~ /^\s*(\d+)\/(\d+)/) { if($1 > 1900) { $year = $1; $month = $2; } else { $month = $1; $mday = $2; } } if($datestr =~ /(\d+):(\d+):(\d+)/) { $hour = $1; $min = $2; $sec = $3; } elsif($datestr =~ /(\d+):(\d+)/) { $hour = $1; $min = $2; } if($datestr =~ /^\s*(\d+)\s+(\d+)\s*$/) { $mday = $1; $hour = $2; } $year = $nyear if(!defined $year); $month = $nmonth if(!defined $month); $mday = $nmday if(!defined $mday); $hour = $nhour if(!defined $hour); $min = $nmin if(!defined $min); $sec = $nsec if(!defined $sec); #$this->print(" time: $year / $month / $mday $hour : $min : $sec\n"); my $timeint = Utils::LocalTimeToTime($year, $month, $mday, $hour, $min, $sec, 0); #($sec, $min, $hour, $mday, $month, $year, $wday, $yday, $isdst) = localtime($timeint); #$year += 1900; #$month += 1; #$App->print(" => $year / $month / $mday $hour : $min : $sec\n"); return $timeint; } sub TimeStrToInt { my ($this, $timestr) = @_; return $this->TimeStrToTime($timestr); } sub TimeStrToIntForConference2 { my ($this, $timestr) = @_; my $ZenStr = "0-9A-Za-z ()_@−+:/"; if($timestr =~ /^(\d+)$/) { my $str = Utils::BuildDateString($timestr); return $timestr; } if($timestr =~ /^(\d+)\/(\d+)\/(\d+)$/) { return Utils::LocalTimeToTime($1, $2, $3, 0, 0, 0); } if($timestr =~ /^(\d+)\/(\d+)\/(\d+)\s+(\d+):(\d+):(\d+)$/) { return Utils::LocalTimeToTime($1, $2, $3, $4, $5, $6); } if($timestr =~ /^(\d+)\/(\d+)\/(\d+)\s+(\d+):(\d+)$/) { return Utils::LocalTimeToTime($1, $2, $3, $4, $5, 0); } if($timestr =~ /^(\d+)(:?)(\d*)/) { my $hour = $1; my $min = $3; my ($sec2, $min2, $hour2, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time()); return Utils::LocalTimeToTime($year, $mon, $mday, $hour, $min, 0); } $this->H2("TimeStrToInt: Input error: [$timestr] is not valid time."); return -1; } sub IntToTimeStr { my($this, $timeint) = @_; # $timeint = new Jcode($timeint)->z2h; return '*' if($timeint == -1); return '?' if($timeint == -2); my $hour = int($timeint / 60); my $minute = $timeint % 60; if($hour <= 9) { $hour = "0$hour"; } if($minute <= 9) { $minute = "0$minute"; } return "$hour:$minute"; } sub IntToTimeStrForSchedule { my($this, $timeint) = @_; # $timeint = new Jcode($timeint)->z2h; return '*' if($timeint == -1); return '?' if($timeint == -2); my $hour = int($timeint / 60); my $minute = $timeint % 60; if($hour <= 9) { $hour = "0$hour"; } if($minute <= 9) { $minute = "0$minute"; } return "$hour:$minute"; } sub ConvertCSVString { my ($this, $pParams, $content, $convert, $CSVCharCode, $SourceCharCode) = @_; $content = '' if(!defined $content); Jcode::convert(\$content, $CSVCharCode, $this->SQLCharCode()) if($CSVCharCode ne ''); if($convert =~ /TELstring/i) { $content = "'$content" if($content =~ /^\s*[+-]/); } elsif($convert =~ /string/i) { $content = "'$content"; } if($convert =~ /AddressCountry/i) { if($pParams->{Country} =~ /Japan/i) { } else { $content = "$pParams->{Address}, $pParams->{Country}"; } } elsif($convert =~ /date|day/i) { $content = $this->BuildDateString($content); if($convert =~ /^datetime$/i) { $content =~ s/\s*\d+:\d+:\d+\s*//; } elsif($convert =~ /^MonthDay$/i) { $content =~ s/\s*\d+\///; $content =~ s/\s*\d+:\d+:\d+\s*//; } } elsif($convert =~ /YesNoMaruBatsu/i) { if($content =~ /No/i) { $content = "×"; Jcode::convert(\$content, $CSVCharCode, $this->ProgramCharCode()) if($CSVCharCode ne ''); } else { $content = "○"; Jcode::convert(\$content, $CSVCharCode, $this->ProgramCharCode()) if($CSVCharCode ne ''); } } elsif($convert =~ /JYen/i) { $content = Utils::SeparateStringBy($content, ',', 3); } if($convert =~ /NoNULL/i) { $content =~ s/NULL//g; } return $content; } #========================================== # セキュリティ関係 #========================================== sub SendNotificationForPrivilegedAccess { my ($this, $SendNotificationForPrivilegedAccess) = @_; my $pParams = $this->pParams(); if(ref $SendNotificationForPrivilegedAccess eq 'HASH') { ($this, $pParams, $SendNotificationForPrivilegedAccess) = @_; } $SendNotificationForPrivilegedAccess = $pParams->{SendNotificationForPrivilegedAccess} if(!defined $SendNotificationForPrivilegedAccess); if(!defined $this->{nDidMergeDBVars} or $this->{nDidMergeDBVars} == 0) { $this->MergeDBVars($this->{pParams}); } return $SendNotificationForPrivilegedAccess; } sub SendNotificationForPrivilegedAccess_old { my ($this, $App, $pParams) = @_; $this->MergeDBVars($this->{pParams}); return $pParams->{SendMail} and $pParams->{SendNotificationForPrivilegedAccess}; } sub SendNotificationForPrivilegedAccessMail { my ($this, $App, $pParams0, $pNotSendNotificationForPrivilegedAccessHash, $DBTableName, $MailTemplateKey) = @_; #$App->print("Check Send: ", $App->SendNotificationForPrivilegedAccess(), ": ", $pParams0->{Action}, "\n"); return if(!$App->SendNotificationForPrivilegedAccess()); return if($pNotSendNotificationForPrivilegedAccessHash->{$pParams0->{Action}}); #$App->print("Send\n"); $MailTemplateKey = 'SendNotificationForPrivilegesAccess-{LanguageCode}-Template.txt' if($MailTemplateKey eq ''); my $DB = $App->DB(); return if(!$DB); $DBTableName = ($pParams0->{UsersTableName})? $pParams0->{UsersTableName} : $pParams0->{DBRegistersTableName}; my %p = %$pParams0; my $pParams = \%p; #$App->print("Table[$DBTableName]\n"); my $ret = ($pParams->{EMail})? $DB->Search($DBTableName, "EMail = \'$pParams->{EMail}\' order by sn", "*") : 0; #my $nHit = $DB->rows(); #$App->print("$nHit found for [$pParams->{EMail}].\n"); if($ret) { my %Hash = $DB->GetNextHit(); my $Password = $pParams->{Password}; Utils::MergeHash($pParams, \%Hash); $pParams->{Password} = $Password; } my $all = ''; foreach my $key (sort keys %$pParams) { next if($key =~ /Password/i); my $val = $pParams->{$key}; next if($val =~ /^ARRAY\(/ or $val =~ /^HASH\(/); next if($val eq ''); Jcode::convert(\$val, 'iso-2022-jp'); if($val =~ /[\r\n]/s) { $all .= "$key: \n[\n$val\n]\n"; } else { $all .= "$key: $val\n"; } if($pParams->{$key} =~ /\%\d\d/) { my $Decoded = Utils::URLDecode($pParams->{$key}); Jcode::convert(\$Decoded, 'iso-2022-jp'); $all .= " ($Decoded)\n"; } } $pParams->{AllParameters} = $all; my $TemplatePath = $App->GetMailTemplatePath($MailTemplateKey); #$App->print("mt[$MailTemplateKey][$TemplatePath]\n"); $pParams->{IPAddress} = $App->RemoteIPAddress(); $pParams->{LastLogonTime} = Utils::BuildDateString(time()) if($pParams->{LastLogonTime} eq ''); $pParams->{TodayString} = $pParams->{LastLogonTime}; my $text = Template->new()->GetTextByHash($TemplatePath, $pParams, '{', '}', 0, $pParams->{WebCharCode}, 1); #$App->print("mail content:\n$text\n"); #my ($this, $text, $sendmail, $TempPath, $PrintMail) = @_; $App->SendMail($text, undef, undef, 0); } sub SendNotificationForPrivilegedAccessMail_old { my ($this, $App, $pParams) = @_; } #========================================== # ネットワーク関係 #========================================== sub ShowLogonPage { my ($this, $App, $pParams) = @_; #$App->print("Logon [$App]\n"); $pParams->{NextAction} = 'ShowStartPage' if(!defined $pParams->{NextAction}); my $LangSelStr = $App->GetLanguageSelectFormString(); $App->InitHTML(); print <

Logon

Language $LangSelStr
E-Mail
Password
EOT } sub ShowUserInformation { my ($this, $App, $pParams) = @_; # return if(!$App->HasPriviledge('ShowParameters', 1)); # $App->SendNotificationForPriviledgedAccessMail($App, $pParams); $App->H3("User Information:"); $App->PrintRawHTML("Account: $pParams->{EMail}
\n"); $App->PrintRawHTML("Administrator Level: $pParams->{AdministratorLevel}
\n"); $App->PrintRawHTML("IPAddress Level : $pParams->{IPAddressLevel} [$pParams->{IPAddress}]
\n"); $App->PrintRawHTML("Authorization Level: $pParams->{AuthorizationLevel}
\n"); $App->PrintRawHTML("Logon Level : $pParams->{LogonLevel} [$pParams->{LogonLevelText}]
\n"); my $Pr = $pParams->{LogonUserPrivilege}; $Pr =~ s/,(\S)/, $1/g;; $App->PrintRawHTML("Privileges : $Pr
\n"); } 1;