#============================================================
# BrowseFilesObject
#============================================================
package BrowseFilesObject;
use Common;
@ISA = qw(Common);
#公開したいサブルーチン
#@EXPORT = qw(erfc tan);
@EXPORT_OK = qw();
use strict;
use MyArchive;
use CGI::ViewFileInformation;
use CGI::TkWiki;
use Mail::ALMail32;
#==========================================
# 大域変数
#==========================================
my $ModuleName = "BrowseFilesObject";
my $ModuleExplanation = "Browse Files Object";
my $Privilege = 'BrowseFilesObject';
sub Name { return $ModuleName; }
sub Explanation { return $ModuleExplanation; }
sub Privilege { return $Privilege; }
my $ChangePasswordPrivilege = 'ChangeDownloadAccountPassword';
my $CreateHTAccessPrivilege = 'CreateHTAccess';
my $ModifyFilePrivilege = 'ModifyFile';
my $EditTemplatePrivilege = 'EditTemplate';
my $UploadFilePrivilege = 'UploadFile';
my $ShowDirTreeLinkPrivilege = 'ShowDirTreeLink';
my $InformedFileRegExp = "\.(mp3|wma|wmv|ra|ram|html?|mht|xml|css|alm|adr|txt|lst|out|csv|js|php|c|cpp|pm|pl|php|py|rb|bat|inf)\$";
#ZIPファイル内のファイル名文字コード
my $ZIPFileCharCode = 'sjis';
#ダウンロードする際のファイル名文字コード
my $DownloadFileCharCode = 'sjis';
#Upload可能なファイルの指定
my $UploadFileMaxSize = 200 * 1024 * 1024;
#編集可能なファイル名
my @EdittableFileRegExp = ("\\.(html?|mht|alm|adr|css|txt|csv|ini|lst|out|mysql|pm|pl|bat|inf)\$");
#受付可能なMIME型と拡張子(正規表現)
#my @TypeOkList = qw(text\/[\w]+ application\/vnd.ms-excel application\/vnd.ms-word message\/rfc822);
my @TypeOkList = ();
#my @TypeOkList = qw (text\/[\w]+ application\/octet-streatm application\/pdf
# application\/msword application\/vnd.ms-powerpoint message\/rfc822);
#my @ExtOkList = qw(csv);
my @ExtOkList = qw ();
#my @ExtOkList = qw (txt html htm csv xls xlsx pdf doc docx ppt pptx zip gz lha ini);
#============================================================
# コンストラクタ、デストラクタ
#============================================================
sub new
{
my ($module) = @_;
my $this = {};
bless $this,$module;
# $this->SUPER::new(@_);
$this->{pALMail} = new ALMail32;
return $this;
}
sub DESTROY
{
my $this = shift;
$this->SUPER::DESTROY(@_);
}
sub FindRootPath
{
my ($this, $App, $pParams, $p) = @_;
my @paths = ($p->{pRootPaths})? @{$p->{pRootPaths}} : ($p->{RootPath});
my $code = Jcode::getcode(join(',', @paths));
for(my $i = 0 ; $i < @paths ; $i++) {
my $path = Template->new()->ReplaceByHash($paths[$i], $pParams, '{', '}', 0, $pParams->{WebCharSet}, 0, 1, 0);
Jcode::convert(\$path, $pParams->{FileSystemCharCode}, $code);
#$App->print("p[$path]\n");
return $path if(-d $path);
#$App->print(" no dir\n");
}
return undef;
}
sub GetPath
{
my ($this, $App, $pParams, $Path) = @_;
return $Path if($Path ne '');
if($pParams->{Path}) {
$Path = Utils::DelQuote(Utils::URLDecode($pParams->{Path}));
}
else {
$Path = $this->{RootPath};
}
$Path =~ s/\\/\//g;
return $Path;
}
sub GetRootPath
{
my ($this, $App, $pParams, $RootPath) = @_;
return $RootPath if($RootPath ne '');
#$RootDir = $this->{RootPath};
#$App->print("RootPath[$this->{RootPath}][$pParams->{RootPath}][$pParams->{OnlyLoadModules}]\n");
if($this->{RootPath}) {
$RootPath = Utils::DelQuote(Utils::URLDecode($this->{RootPath}));
}
elsif($pParams->{RootPath}) {
$RootPath = Utils::DelQuote(Utils::URLDecode($pParams->{RootPath}));
}
$RootPath =~ s/\\/\//g;
$RootPath = Utils::ReduceDirectory($RootPath);
#$App->print("R[$RootPath]\n");
return $RootPath;
}
sub Configure
{
my ($this, $modulename, $privilege, $rootpath, $keyword,
$pPermittedDirs, $pBrowseFiles, $pDenyFiles,
$pSubstitutionSource, $pSubstitutionTarget,
$pURLSubstitutionList, $pURLReverseSubstitutionList,
$showdate, $showdirectory, $showparentdirectory, $showfilesize, $targetpage, %args) = @_;
#print("BroseFilesObject::Configure
\n");
$this->{ModuleName} = $modulename if(defined $modulename);
$this->{Privilege} = $privilege if(defined $privilege);
#Utils::InitHTML();
#print("r[$this->{RootPath}][$rootpath]
\n");
$this->{RootPath} = $rootpath if(defined $rootpath);
$this->{Keyword} = $keyword if(defined $keyword);
#print("r[$this->{RootPath}][$rootpath]
\n");
# $UploadFileMaxSize = $args{UploadFileMaxSize} if(defined $args{UploadFileMaxSize});
@EdittableFileRegExp = @{$args{pEdittableFileRegExp}} if(defined $args{pEdittableFileRegExp});
@TypeOkList = @{$args{pTypeOkList}} if(defined $args{pTypeOkList});
@ExtOkList = @{$args{pExtOkList}} if(defined $args{pExtOkList});
$Privilege = $this->{Privilege} = $args{Privilege} if($args{Privilege} ne '');
$ChangePasswordPrivilege = $this->{ChangePasswordPrivilege} = $args{ChangePasswordPrivilege} if($args{ChangePasswordPrivilege} ne '');
$CreateHTAccessPrivilege = $this->{CreateHTAccessPrivilege} = $args{CreateHTAccessPrivilege} if($args{CreateHTAccessPrivilege} ne '');
$ModifyFilePrivilege = $this->{ModifyFilePrivilege} = $args{ModifyFilePrivilege} if($args{ModifyFilePrivilege} ne '');
$EditTemplatePrivilege = $this->{EditTemplatePrivilege} = $args{EditTemplatePrivilege} if($args{EditTemplatePrivilege} ne '');
$UploadFilePrivilege = $this->{UploadFilePrivilege} = $args{UploadFilePrivilege} if($args{UploadFilePrivilege} ne '');
$ShowDirTreeLinkPrivilege = $this->{ShowDirTreeLinkPrivilege} = $args{ShowDirTreeLinkPrivilege} if($args{ShowDirTreeLinkPrivilege} ne '');
$this->{pPermittedDirs} = $pPermittedDirs if(defined $pPermittedDirs);
$this->{pBrowseFiles} = $pBrowseFiles if(defined $pBrowseFiles);
$this->{pDenyFiles} = $pDenyFiles if(defined $pDenyFiles);
$this->{pSubstitutionSource} = $pSubstitutionSource if(defined $pSubstitutionSource);
$this->{pSubstitutionTarget} = $pSubstitutionTarget if(defined $pSubstitutionTarget);
$this->{pURLSubstitutionList} = $pURLSubstitutionList if(defined $pURLSubstitutionList);
$this->{pURLReverseSubstitutionList} = $pURLReverseSubstitutionList if(defined $pURLReverseSubstitutionList);
if($args{App}) {
my $App = $args{App};
my $pParams = $App->pParams();
my @DownloadDirs = Utils::MergeList(@{$this->{pPermittedDirs}}, @{$pParams->{pDownloadDirs}});
#$App->print("dirs [", join(',', @DownloadDirs), "]\n");
$pParams->{pDownloadDirs} = \@DownloadDirs;
my @DownloadDirsRegExp = $App->ConvertAllowedDirArrayToRegExp(\@DownloadDirs);
$pParams->{pDownloadDirsRegExp} = \@DownloadDirsRegExp;
}
$this->{ShowDate} = $showdate if(defined $showdate);
$this->{ShowDirectory} = $showdirectory if(defined $showdirectory);
$this->{ShowParentDirectory} = $showparentdirectory if(defined $showparentdirectory);
$this->{ShowFileSize} = $showfilesize if(defined $showfilesize);
$this->{TargetPage} = $targetpage if(defined $targetpage);
}
#============================================================
# メンバー関数
#============================================================
sub GetParameterHash
{
my ($this, $App, $pParams) = @_;
return {};
}
sub IsOpen
{
my ($this, $App, $pParams, $IsPrint) = @_;
return 0 if($this->{RootPath} eq '');
#$App->print("p[$this->{Privilege}]\n");
return $App->HasPrivilege($this->{Privilege}, $IsPrint);
}
sub ShowMenu
{
my ($this, $App, $pParams, $ProgramPath, $BaseOption) = @_;
return 0;
}
sub HasInformation
{
my ($this, $App, $pParams, $path) = @_;
return 1 if($path =~ /$InformedFileRegExp/i);
return 0;
}
sub MakeDirLink
{
my ($this, $App, $pParams, $dir, $label, $target) = @_;
return '' if($dir eq '.');
return '' if($dir eq '..' and !$pParams->{ShowParentDirectory});
if($target ne '') {
}
elsif($this->{TargetPage} ne '') {
$target = $this->{TargetPage};
}
else {
$target = '_self';
}
$dir = Utils::URLEncode($dir);
my ($Option, $target) = $App->GetCGIParameters(
{
Action => "$this->{ModuleName}::ShowPage",
PrevAction => $pParams->{Action},
Path => $dir,
ShowParentDirectory => $this->{ShowParentDirectory},
ShowDirectory => $this->{ShowDirectory},
ShowDate => $this->{ShowDate},
ShowFileSize => $this->{ShowFileSize},
},
[qw(+Action Path Key SubMenuFunction UserSN IsChildFrame FrameMode ShowParentDirectory ShowDirectory ShowDate ShowFileSize Key iRootDir)],
undef, undef, 0);
my $s = "{ScriptPath}?$Option\" target=\"$target\">$label";
return $s;
}
sub MakeEditLink
{
my ($this, $App, $pParams, $path, $label, $pAllowedExtRegExps, $target) = @_;
if($target ne '') {
}
elsif($this->{TargetPage} ne '') {
$target = $this->{TargetPage};
}
else {
$target = '_blank';
}
my $Passed = 0;
for(my $i = 0 ; $i < @$pAllowedExtRegExps ; $i++) {
my $p = $pAllowedExtRegExps->[$i];
#$App->print("$i:[$p][$path]\n");
if($path =~ /$p/i) {
$Passed = 1;
}
}
return '' if(!$Passed);
return '' if($path eq '.');
return '' if($path eq '..' and !$pParams->{ShowParentDirectory});
$path =~ s/^file:\/\///i;
Jcode::convert(\$path, $pParams->{FileSystemCharCode});
$path = Utils::URLEncode($path);
my ($Option, $target) = $App->GetCGIParameters(
{
Action => "EditTemplate::EditFile",
PrevAction => $pParams->{Action},
Path => $path,
ShowParentDirectory => $this->{ShowParentDirectory},
ShowDirectory => $this->{ShowDirectory},
ShowDate => $this->{ShowDate},
ShowFileSize => $this->{ShowFileSize},
},
[qw(+Action Path Key UserSN IsChildFrame FrameMode ShowParentDirectory ShowDirectory ShowDate ShowFileSize Key iRootDir)],
"_blank", "_blank", 0);
return "{ScriptPath}?$Option\" target=\"$target\">$label"
}
sub MakeFileLink
{
my ($this, $App, $pParams, $path, $label, $target) = @_;
if($target ne '') {
}
elsif($this->{TargetPage} ne '') {
$target = $this->{TargetPage};
}
else {
$target = '_blank';
}
$path =~ s/^file:\/\///i;
Jcode::convert(\$path, $pParams->{FileSystemCharCode});
#$App->print("path: [$path]\n");
return $App->MakeFileLink($pParams, undef, $path, $label, undef, undef, undef, undef, $target);
my $RegExpRootDir = Utils::RegExpQuote($pParams->{WebDocumentRootDir});
if($path =~ /^$RegExpRootDir/) {
# if($path !~ /cgi-bin/i and $pParams->{WebDocumentRoot} ne '') {
if($path =~ s/^$RegExpRootDir//i) {
$path = "/$path" if($path !~ /^\//);
Jcode::convert(\$label, $pParams->{FileSystemCharCode});
#$path = Utils::URLEncode($path, 1);
#$App->print("p[$path]\n");
return "$label"
}
}
$path = Utils::URLEncode($path);
my ($Option, $target) = $App->GetCGIParameters(
{
Action => "$this->{ModuleName}::Download",
PrevAction => $pParams->{Action},
Path => $path,
ShowParentDirectory => $this->{ShowParentDirectory},
ShowDirectory => $this->{ShowDirectory},
ShowDate => $this->{ShowDate},
ShowFileSize => $this->{ShowFileSize},
},
[qw(+Action Path Key SubMenuFunction UserSN IsChildFrame FrameMode ShowParentDirectory ShowDirectory ShowDate ShowFileSize Key iRootDir)],
"_blank", "_blank", 0);
return "{ScriptPath}?$Option\" target=\"$target\">$label"
}
sub MakeDirTreeLink
{
my ($this, $App, $pParams, $dir) = @_;
Jcode::convert(\$dir, "euc-jp", $pParams->{FileSystemCharCode});
#$App->print("path: [$dir]\n");
$dir =~ s/\\/\//g;
my @a = Utils::Split("\\/", $dir);
Jcode::convert(\$dir, $pParams->{FileSystemCharCode}, "euc-jp");
for(my $i = 0 ; $i < @a ; $i++) {
Jcode::convert(\$a[$i], $pParams->{FileSystemCharCode}, "euc-jp");
}
my $Path = $a[0];
if($Path =~ /:$/) {
$Path .= "/";
}
else {
$Path = "/$Path";
}
my $s = '';
my $label = $Path;
#$App->print("path[$Path]\n");
for(my $i = 0 ; $i < @a ; $i++) {
my ($IsPermitted, $BrowseDir, $FileRegExp, $DirRegExp, $ss, $st) = $this->IsPermitted($App, $pParams, $Path);
if(!$IsPermitted) {
$Path = Utils::MakePath($Path, $a[$i+1], '/', 0);
# $label = Utils::MakePath($label, $a[$i+1], '/', 0);
# $label = '$Root'. '/' . $a[$i+1];
$label = 'ROOTDIR';
next;
}
if(-d $Path) {
# my $link = ($i == 0)? $this->MakeDirLink($App, $pParams, $Path, '$Root/') :
# $this->MakeDirLink($App, $pParams, $Path, $label);
my $link = $this->MakeDirLink($App, $pParams, $Path, $label);
$s .= '/' . $link;
}
elsif(-f $Path) {
$s .= '/' . $this->MakeFileLink($App, $pParams, $Path, $label);
}
else {
}
$Path = Utils::MakePath($Path, $a[$i+1], '/', 0);
$label = $a[$i+1];
}
$s =~ s/\///;
$s = "$dir (not permitted)" if($s eq '');
return $s;
}
sub PrintFileFunc
{
my ($this, $App, $pParams, $path) = @_;
my ($drive, $directory, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($path);
my $link = $this->MakeFileLink($App, $pParams, $path, $filename);
$App->PrintRawHTML("
\n");
$App->PrintRawHTML(" $link | \n");
my $mdate = Utils::GetWriteDate($path);
my $date = Utils::BuildDateString($mdate);
$App->PrintRawHTML(" $date | \n");
my ($size, $unit) = Utils::GetFileSize($path, 'kb', "%12.3f");
$App->PrintRawHTML(" $size | \n");
my $dir = "$drive$directory";
$dir =~ s/\\/\//g;
$dir =~ s/\/$//;
my $link = $this->MakeDirLink($App, $pParams, $dir, $dir);
$App->PrintRawHTML(" $link | \n");
$App->PrintRawHTML("
\n");
}
sub SearchRecursive
{
my ($this, $App, $pParams, $dir, $fmask, $func) = @_;
my ($IsPermitted, $pd, $bf, $bd, $ss, $st) = $this->IsPermitted($App, $pParams, $dir);
return if(!$IsPermitted);
my $path = Utils::MakePath($dir, "*", '/', 0);
my @files = $App->GetFileList($pParams, $path, 1);
for(my $i = 0 ; $i < @files ; $i++) {
#$App->print("d: [$files[$i]]\n");
next if($files[$i] =~ /[\\\/]\.\.?$/);
next if(!-d $files[$i]);
my ($IsPermitted, $BrowseDir, $FileRegExp, $DirRegExp, $ss, $st) = $this->IsPermitted($App, $pParams, $files[$i]);
next if(!$IsPermitted);
my ($drive, $directory, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($files[$i]);
$this->SearchRecursive($App, $pParams, $files[$i], $fmask, $func);
}
my $count = 0;
my $path = Utils::MakePath($dir, '*', '/', 0);
# my $path = Utils::MakePath($dir, $fmask, '/', 0);
Jcode::convert(\$path, $pParams->{FileSystemCharCode});
my @files = $App->GetFileList($pParams, $path, 1);
for(my $i = 0 ; $i < @files ; $i++) {
#$App->print("f: [$files[$i]]\n");
next if(!-f $files[$i]);
my ($drive, $directory, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($files[$i]);
next if($filename !~ /$fmask/i);
my ($IsPermitted, $BrowseDir, $FileRegExp, $DirRegExp, $ss, $st) = $this->IsPermitted($App, $pParams, $files[$i]);
next if(!$IsPermitted);
if($count == 0) {
# $App->PrintRawHTML("\n");
$count++;
}
&$func($files[$i]);
}
if($count > 0) {
# $App->PrintRawHTML("
\n");
}
}
sub SearchFile
{
my ($this, $App, $pParams) = @_;
return if(!$this->IsOpen($App, $pParams, 0));
my $SearchWord = $pParams->{SearchWord};
$App->H2("Search for [$SearchWord] \n");
Jcode::convert(\$SearchWord, $pParams->{FileSystemCharCode});
# $SearchWord = "*$SearchWord*" if($SearchWord !~ /\*/);
my $path = ($pParams->{Path})? $pParams->{Path} : $this->{RootPath};
if(!-d $path) {
$path = Utils::URLDecode($path);
Jcode::convert(\$path, $pParams->{FileSystemCharCode});
}
#$App->print("Search from [$path]\n");
$pParams->{Path} = $path;
$this->ShowSearchForm($App, $pParams);
$this->{MultiFunctionTableJScript} = JSParams->new()->GetMultiFunctionalTableString('.TableTest3', sortList => '[[0,-1]]', excludeColumns => '[2]')
if($this->{MultiFunctionTableJScript});
$this->{pMultiFunctionTableConfig} = {
class => 'tablesorter'
} if(!$this->{pMultiFunctionTableConfig});
$App->PrintRawHTML($this->{MultiFunctionTableJScript}) if($this->{MultiFunctionTableJScript});
my $pHash = $this->{pMultiFunctionTableConfig};
my $black1 = "";
my $black2 = "";
$App->BeginTable(1, undef, %$pHash);
$App->BeginTableHeader();
$App->BeginRow();
$App->PrintRawHTML(" ${black1}" . $App->GetPhrase('File name') . "${black2} | \n");
$App->PrintRawHTML(" ${black1}" . $App->GetPhrase('Date') . "${black2} | \n");
$App->PrintRawHTML(" ${black1}" . $App->GetPhrase('Size (KB)') . "${black2} | \n");
$App->PrintRawHTML(" ${black1}" . $App->GetPhrase('Folder') . "${black2} | \n");
$App->EndRow();
$App->EndTableHeader();
$this->SearchRecursive($App, $pParams, $path, $SearchWord,
sub { $this->PrintFileFunc($App, $pParams, @_); });
$App->EndTableBody();
$App->EndTable();
$App->HR();
$this->ShowPage($App, $pParams);
}
sub ShowSearchForm
{
my ($this, $App, $pParams) = @_;
my $Option = $App->BuildCGIOption(
{
PrevAction => $pParams->{Action},
},
[qw(+App EMail Password Language Key Path RootDir Key iRootDir ShowAll ExtendedMenu PrevAction DBConfigName Year Month Day Key iRootDir)],
);
my $BaseAction = ($this->{ModuleName} =~ /Admin/i)? 'AdminPictureGalleryOption::ShowPage' : 'UserPictureGalleryOption::ShowPage';
my $PictureGalleryLink ="{ScriptPath}?Action=$BaseAction&$Option\" target=\"_blank\">"
.$App->mlText('en' => "Image View", 'jp' => "写真一覧表示") . " ";
my $path = $pParams->{Path};
$path = Utils::URLEncode($path);
my ($Option, $target) = $App->GetCGIParameters(
{
Action => "$this->{ModuleName}::SearchFile",
PrevAction => $pParams->{Action},
Path => $path,
},
[qw(+Action Key Path RootDir Key iRootDir UserSN IsChildFrame FrameMode Key iRootDir)],
$this->{TargetPage}, $pParams->{TargetFrame}, 1);
my $SearchStr = $App->mlText('en' => 'Search file', 'jp' => '検索ファイル名');
#Jcode::convert(\$SearchStr, $pParams->{WebCharCode});
$App->BeginForm($pParams, $pParams->{ScriptPath}, "POST", "_self", 1);
$App->PrintRawHTML(" $SearchStr: {SearchWord}\" size=\"20\">\n");
$App->PrintFormButton("submit", $App->GetPhrase('Execute search'));
$App->PrintRawHTML($PictureGalleryLink);
$App->PrintRawHTML("$Option\n");
$App->EndForm(undef, undef, undef, undef);
}
sub UpdateFileList
{
my ($this, $App, $pParams, $RootPath) = @_;
$App->SendNotificationForPrivilegedAccessMail($App, $pParams);
return if(!$App->HasPrivilege($ModifyFilePrivilege, 1));
my $Kara = '~'; #'~';
my $KaraZIPCharCode = $Kara;
Jcode::convert(\$Kara, $pParams->{FileSystemCharCode}, 'utf-8');#$pParams->{ScriptCharCode});
Jcode::convert(\$KaraZIPCharCode, $ZIPFileCharCode, 'utf-8');
$RootPath = $this->{RootPath} if($RootPath eq '');
my ($Option, $target) = $App->GetCGIParameters(
{
Action => $pParams->{Action}, #"$this->{ModuleName}::ShowPage", #$this->{NextAction},
PrevAction => $pParams->{Action},
# Path => Utils::URLEncode($RootPath),
},
[qw(+Action Path Key SubMenuFunction IsChildFrame FrameMode Key iRootDir)],
undef, undef, 1,
);
my $Path = Utils::URLDecode($pParams->{Path});
my $PathRegExp = Utils::RegExpQuote($Path);
if($pParams->{Delete} ne '') {
$App->H2($App->GetPhrase('Delete files') . "\n");
foreach my $key (sort keys %$pParams) {
next if($key !~ /^CheckFile-(.*)$/);
next if($pParams->{$key} ne 'ON');
my $key = $1;
my $newname = $pParams->{"NewFile-$key"};
if($newname ne '') {
$App->H3("Error in ${ModuleName}::UpdateFileList: New name [$newname] is not null. Delete will not be executed.\n");
return;
}
# my $Path0 = Utils::URLDecode($pParams->{Path});
my $path = Utils::MakePath($RootPath, Utils::URLDecode($key), '/', 0);
if(!-d $path) {
if(Utils::DeleteFile($path) == 1) {
$App->H3("[$path] deleted.\n");
}
else {
$App->H3("Error in ${ModuleName}::UpdateFileList: [$path] could not be deleted.\n");
}
}
else {
if(Utils::DeleteDirectory($path) == 1) {
$App->H3("Directory [$path] deleted.\n");
}
else {
$App->H3("Error in ${ModuleName}::UpdateFileList: Directory [$path] could not be deleted.\n");
}
}
}
}
elsif($pParams->{Rename} ne '') {
$App->H2($App->GetPhrase('Rename files') . "\n");
foreach my $key (sort keys %$pParams) {
next if($key !~ /^CheckFile-(.*)$/);
next if($pParams->{$key} ne 'ON');
my $key = $1;
my $newname = $pParams->{"NewFile-$key"};
next if($newname eq '');
my $fname = Utils::URLDecode($key);
my $inpath = Utils::MakePath($RootPath, $fname, '/', 0);
Utils::URLDecode($newname);
Jcode::convert(\$newname, $pParams->{FileSystemCharCode}, $pParams->{WebCharCode});
my $newpath = Utils::MakePath($Path, $newname, '/', 0);
#$App->print("renmae [$inpath] to [$newpath]\n");
if(Utils::MoveFile($inpath, $newpath) == 1) {
$App->H3("[$inpath] was renamed to [$newpath].\n");
}
else {
$App->H3("Error in ${ModuleName}::UpdateFileList: [$inpath] could not be renamed to [$newpath].\n");
}
}
}
elsif($pParams->{CreatePasswordedZip} ne '') {
$App->H2($App->GetPhrase('Create Passworded Zip files') . "\n");
$App->BeginForm($pParams, $pParams->{ScriptPath}, "POST", "_self", 1);
$App->PrintFormButton("ExecuteCreatePasswordedZip", "Execute");
$App->print("\n");
$App->PasswordTextbox('ZipPassword', 30, $pParams->{ZipPassword}, 'Password: ');
$App->print("\n");
my $count = 0;
foreach my $key (sort keys %$pParams) {
next if($key !~ /^CheckFile-(.*)$/);
my $key0 = $1;
my $fname = Utils::URLDecode($key0);
next if($pParams->{$key} ne 'ON');
my ($drive, $directory, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($fname);
$fname = $filename;
if($count == 0 and $pParams->{ZipFileName} eq '') {
$count++;
$pParams->{ZipFileName} = "$filebody.zip";
$App->Textbox('ZipFileName', 30, $pParams->{ZipFileName}, 'Zip file name: ');
$App->print("\n");
}
my $cs = $App->BuildCheckboxString($key, $pParams->{$key}, '');
$App->PrintRawHTML($cs);
$App->print("$fname");
$App->print("\n");
}
$App->PrintRawHTML("$Option\n");
$App->EndForm(undef, undef, undef, undef);
}
elsif($pParams->{ExecuteCreatePasswordedZip} ne '') {
$App->H2("Execute CreatePasswordedZipFiles\n");
if($pParams->{ZipPassword} eq '') {
$App->H3("Error in ${ModuleName}::UpdateFileList: Password must not be null.\n");
$pParams->{CreatePasswordedZip} = 'ON';
delete $pParams->{ExecuteCreatePasswordedZip};
$App->HR();
$this->UpdateFileList($App, $pParams, $RootPath);
return;
}
my @files;
my $TargetPath = Utils::MakePath($Path, $pParams->{ZipFileName}, '/', 0);
foreach my $key (sort keys %$pParams) {
next if($key !~ /^CheckFile-(.*)$/);
my $key0 = $1;
my $fname = Utils::URLDecode($key0);
next if($pParams->{$key} ne 'ON');
my $NewFileKey = "NewFile-$key0";
my $NewFile = $pParams->{$NewFileKey};
#Jcode::convert(\$fname, $pParams->{FileSystemCharCode});
Jcode::convert(\$NewFile, $pParams->{FileSystemCharCode}, $pParams->{WebCharCode});
$fname =~ s/\\/\//g;
my $SourcePath = Utils::MakePath($RootPath, $fname, '/', 0);
push(@files, $SourcePath);
# my ($drive, $directory, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($SourcePath);
# $directory =~ s/\\/\//g;
#$App->print("S: $SourcePath => ");
# $SourcePath =~ s/^$PathRegExp//;
# $SourcePath =~ s/^\///;
# my $TargetPath = Utils::MakePath("$drive$directory", $NewFile, '/', 0);
# $TargetPath =~ s/^$PathRegExp//;
# $TargetPath =~ s/^\///;
#$App->print("$SourcePath\n");
}
my $ret = MyArchive->new()->MakePasswordedZIP(
$TargetPath, $Path, \@files, $pParams->{ZipPassword}, '-D', $pParams->{FileSystemCharCode}, $ZIPFileCharCode, $App);
}
elsif($pParams->{BurstZip} ne '') {
$App->H2($App->GetPhrase('Burst Zip files') . "\n");
foreach my $key (sort keys %$pParams) {
next if($key !~ /^CheckFile-(.*)$/);
my $key0 = $1;
my $fname = Utils::URLDecode($key0);
next if($pParams->{$key} ne 'ON');
my $SourcePath = Utils::MakePath($RootPath, $fname, '/', 0);
$SourcePath =~ s/^$PathRegExp//;
$SourcePath =~ s/^\///;
my $ret = MyArchive->new()->BurstZIP($SourcePath, $Path, '', $App);
if($ret) {
$App->H3("Burst [$SourcePath] succeeded.\n");
}
else {
$App->H3("Error in ${ModuleName}::UpdateFileList: Burst [$SourcePath] failed.\n");
}
}
}
elsif($pParams->{CreateDir} ne '') {
$App->H2($App->GetPhrase('Create Dir') . "\n");
my $newname = $pParams->{NewPath};
Utils::URLDecode($newname);
Jcode::convert(\$newname, $pParams->{FileSystemCharCode}, $pParams->{WebCharCode});
my $newpath = Utils::MakePath($Path, $newname, '/', 0);
#$App->print("mkdir [$newpath]\n");
if(Utils::CreateDirectory($newpath, '/', 0) == 1) {
$App->H3("Directory [$newpath] has been created.\n");
}
else {
$App->H3("Error in ${ModuleName}::UpdateFileList: Directory [$newpath] could not be created.\n");
}
}
elsif($pParams->{CreateFile} ne '') {
$App->H2($App->GetPhrase('Create File') . "\n");
my $newname = $pParams->{NewPath};
Utils::URLDecode($newname);
Jcode::convert(\$newname, $pParams->{FileSystemCharCode}, $pParams->{WebCharCode});
my $newpath = Utils::MakePath($Path, $newname, '/', 0);
if(-e $newpath) {
$App->H3("Error in ${ModuleName}::UpdateFileList: [$newpath] already exists.\n");
}
else {
my $out = new JFile($newpath, 'w');
if($out) {
$App->H3("File [$newpath] has been created.\n");
$out->Close();
}
else {
$App->H3("Error in ${ModuleName}::UpdateFileList: File [$newpath] could not be created.\n");
}
}
}
elsif($pParams->{Upload} ne '') {
$App->H2($App->GetPhrase('Upload file') . "\n");
my $SourceFileName = $pParams->{UploadFilePath};
$SourceFileName =~ s/\\/\//g;
if($SourceFileName =~ /\//) {
my ($drive, $directory, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($SourceFileName);
$SourceFileName = $filename;
}
if($SourceFileName eq '') {
$App->H3("Error in ${ModuleName}::UpdateFileList: Source path [$SourceFileName] is not null.\n");
return;
}
my $ServerFileName = $SourceFileName;
#my $code = Jcode::getcode($Kara);
#$App->print("code: $code Kara:[$Kara] S[$ServerFileName]\n");
$ServerFileName =~ s/$Kara/-/g if($^O ne 'MSWin32');
my $TargetPath = Utils::MakePath($Path, $ServerFileName, '/', 0);
Jcode::convert(\$TargetPath, $pParams->{FileSystemCharCode});
#$App->print("[$SourceFileName][$ServerFileName][$TargetPath]\n");
my %args = (
# FileFieldName => 'UploadFilePath',
UploadFilePath => $SourceFileName,
UploadFileMaxSize => $UploadFileMaxSize,
ServerFileName => $ServerFileName,
ServerFilePath => $TargetPath,
pTypeOkList => \@TypeOkList,
pExtOkList => \@ExtOkList,
);
my $ret = $App->MyHTMLApplication::UploadFile($pParams, $App->Args()->CGIForm(), %args);
if($ret ne 'OK') {
$App->H3("Error in ${ModuleName}::UpdateFileList: File [$SourceFileName] could not be uploaded to [$TargetPath] with ret=$ret.\n");
return;
}
else {
#Jcode::convert(\$SourceFileName, $pParams->{WebCharCode});
Jcode::convert(\$TargetPath, $pParams->{WebCharCode});
$App->H3("File [$SourceFileName] has been uploaded to [$TargetPath].\n");
}
}
}
sub BeginTable
{
my ($this, $App, $pParams, $pHash, $pTableDef) = @_;
$App->BeginTable(1, undef, %$pHash);
$App->BeginTableHeader();
$App->BeginRow();
for(my $i = 0 ; $i < @$pTableDef ; $i++) {
$App->PrintRawHTML(" $pTableDef->[$i]->[0] | \n");
}
$App->EndRow();
$App->EndTableHeader();
$App->BeginTableBody();
}
sub DownloadAttachedFile
{
my ($this, $App, $pParams) = @_;
my $Debug = 0;
my $iA = $pParams->{iAttachedFile};
my $Path = $pParams->{Path};
$App->print("iAttachedFile=$iA\n") if($Debug);
$App->print("Path=$Path\n") if($Debug);
my ($IsPermitted, $BrowseDir, $FileRegExp, $DirRegExp, $ss, $st) = $this->IsPermitted($App, $pParams, $Path);
if(!$IsPermitted) {
# $App->H2("Error in ${ModuleName}::DownloadAttachedFile: Download [$Path] is not permitted.\n");
# return;
}
my $mf = new MailFile;
my $pTextArray = $mf->Read($Path, 0);
if(!$pTextArray) {
$App->H2("Error: Can not read [$Path]\n");
return 0;
}
my $Header = $mf->GetHeader();
# my $Content = $mf->GetContent();
my $Content = $mf->GetMailBoy();
# my $Content = $mf->GetFullContent();
my $psp = $mf->{pSerialPartsInf};
my $p = $psp->[$iA];
if(!$p) {
$App->H2("Error: Can not find mail part [$iA] in [$Path]\n");
return 0;
}
my ($pHeader, $pContent) = $mf->SplitHeaderFromString($p->{Content});
my $content = join('', @$pContent);
my $ContentType = $p->GetHeaderFromString("Content-Type", $pParams->{WebCharCode}, 0, $pHeader); #, $p->{Content});
my $ContentTransferEncoding = $p->GetHeaderFromString("Content-Transfer-Encoding", $pParams->{WebCharCode}, 0, $pHeader); #, $p->{Content});
my $ContentDisposition = $p->GetHeaderFromString("Content-Disposition", $pParams->{WebCharCode}, 0, $pHeader);
$App->print("Content-Type: $ContentType [$ContentTransferEncoding]\n") if($Debug);
$App->print("Content-Disposition: $ContentDisposition\n") if($Debug);
if($ContentType !~ /application/i and $ContentType !~ /stream/i) {
$App->H2("Error: No attached file in this mail part [$pParams->{iAttachedFile}] in [$Path]\n");
return 0;
}
my $filename = $mf->GetAttachedFileName($pHeader, $pParams->{WebCharCode});
Jcode::convert(\$filename, 'sjis');
$App->print("f[$filename]\n") if($Debug);
#$App->print("c[$content]\n");
if($ContentTransferEncoding) {
$content = $mf->DecodeContent($pParams->{WebCharCode}, 1, undef, $content, $ContentTransferEncoding);
}
$App->print("c[$content]\n") if($Debug);
my $CGIForm = $App->CGIForm();
my $Length = length($content);
binmode(STDOUT);
print(STDOUT
$CGIForm->header(
-Content_Disposition => "attachment; filename=$filename",
-Content_Length => $Length,
-type => "application/octet-stream",
# -type => "application/download",
)
);
print STDOUT $content;
}
sub ViewHTML
{
my ($this, $App, $pParams) = @_;
my $Debug = 0;
my $iA = $pParams->{iAttachedFile};
my $Path = $pParams->{Path};
$App->print("iAttachedFile=$iA\n") if($Debug);
$App->print("Path=$Path\n") if($Debug);
my ($IsPermitted, $BrowseDir, $FileRegExp, $DirRegExp, $ss, $st) = $this->IsPermitted($App, $pParams, $Path);
if(!$IsPermitted) {
# $App->H2("Error in ${ModuleName}::DownloadAttachedFile: Download [$Path] is not permitted.\n");
# return;
}
my $mf = new MailFile;
my $pTextArray = $mf->Read($Path, 0);
if(!$pTextArray) {
$App->H2("Error: Can not read [$Path]\n");
return 0;
}
my $Header = $mf->GetHeader();
# my $Content = $mf->GetContent();
my $Content = $mf->GetMailBoy();
# my $Content = $mf->GetFullContent();
my $psp = $mf->{pSerialPartsInf};
my $p = $psp->[$iA];
if(!$p) {
$App->H2("Error: Can not find mail part [$iA] in [$Path]\n");
return 0;
}
my ($pHeader, $pContent) = $mf->SplitHeaderFromString($p->{Content});
my $content = join('', @$pContent);
my $ContentType = $p->GetHeaderFromString("Content-Type", $pParams->{WebCharCode}, 0, $pHeader); #, $p->{Content});
my $ContentTransferEncoding = $p->GetHeaderFromString("Content-Transfer-Encoding", $pParams->{WebCharCode}, 0, $pHeader); #, $p->{Content});
my $ContentDisposition = $p->GetHeaderFromString("Content-Disposition", $pParams->{WebCharCode}, 0, $pHeader);
$App->print("Content-Type: $ContentType [$ContentTransferEncoding]\n") if($Debug);
$App->print("Content-Disposition: $ContentDisposition\n") if($Debug);
if($ContentType !~ /html/i) {
$App->H2("Error: No html in this mail part [$pParams->{iAttachedFile}] in [$Path]\n");
return 0;
}
if($ContentTransferEncoding) {
$content = $mf->DecodeContent($pParams->{WebCharCode}, 1, undef, $content, $ContentTransferEncoding);
}
$App->PrintRawHTML($content);
}
sub ViewInformation
{
my ($this, $App, $pParams, $Path) = @_;
return if(!$this->IsOpen($App, $pParams, 0));
$Path = $pParams->{Path} if($Path eq '');
$Path =~ s/^file:\/\///i;
#$App->print("P[$Path][$pParams->{Path}]\n");
my ($Option, $target) = $App->GetCGIParameters(
{
NoMenu => 1,
},
[qw(EMail Password NoMenu Key iRootDir)],
undef, undef, 0);
$pParams->{DownloadFileLink} = "$pParams->{ScriptPath}?Action=$this->{ModuleName}::DownloadAttachedFile&$Option";
$pParams->{ViewHTMLBaseLink} = "$pParams->{ScriptPath}?Action=$this->{ModuleName}::ViewHTML&$Option";
ViewFileInformation->new()->ViewInformation($App, $pParams, $Path);
}
sub GetFileInf
{
my ($this, $App, $pParams, $path, $charcode) = @_;
my ($type, $label);
$type = (-d $path)? 'directory' : 'file';
my ($drive, $directory, $fname, $ext, $lastdir, $filebody) = Deps::SplitFilePath($path);
Jcode::convert(\$fname, $charcode) if($charcode);
$this->{pALMail} = new ALMail32 if(!defined $this->{pALMail});
if($path =~ /\.alm$/i and $this->{pFileNameSubstitutionList}) {
my $p = $this->{pFileNameSubstitutionList};
my $key = uc $filebody;
my $title = "$p->{$key}->{subject}: $p->{$key}->{from}" if($p->{$key});
Utils::DelSpace($title);
Jcode::convert(\$title, $charcode) if($charcode ne '');
return ('ALMailMailFile', "$title [$fname]", $fname) if($title);
}
my ($title, $CurrentFolderType) = $this->{pALMail}->GetALMailFolderTitle($path, 0);
if($title ne '') {
Jcode::convert(\$title, $charcode) if($charcode);
return ('ALMailFolder', "$title [$fname]", $fname);
}
if($fname =~ /^[\dA-F]+\.txt/) {
my $name = CGI::TkWiki->new()->DecodePukiWikiName($fname);
Jcode::convert(\$name, $charcode) if($charcode);
return ('PukiWikiFolder', "$name [$fname]", $fname);
}
if($path =~ /%[\dA-Z]{2}/) {
$label = Utils::URLDecode($path);
Jcode::convert(\$label, $charcode) if($charcode);
if($label =~ /fswiki/i) {
$label =~ s/^.*\///;
$label =~ s/\.wiki$//;
}
return ($type, "$label [$fname]", $fname);
}
return ($type, $fname, $fname);
}
sub GetFileNameSubstitutionList
{
my ($this, $App, $pParams, $RootPath) = @_;
delete $this->{pFileNameSubstitutionList};
return $this->{pFileNameSubstitutionList} = ALMail32->new()->GetLSTFileHashByDir($RootPath);
}
sub GetFileList
{
my ($this, $App, $pParams) = @_;
# my $RootDir = $this->GetPath($App, $pParams);
my $RootDir = $this->GetRootPath($App, $pParams);
#$App->print("Root[$RootDir]\n");
print "Content-type: text/html\n\n";
#print "root[$params->{root}]\n";
my $dir = Utils::URLDecode($pParams->{dir});
$dir = Utils::URLDecode($dir);
Jcode::convert(\$dir, $pParams->{FileSystemCharCode}, $pParams->{WebCharCode});
#$App->print("\ndir[$dir]\n");
return if($dir =~ /\.\./);
my $FullDir = Utils::MakePath($RootDir, $dir, '/', 0);
exit if(!-e $FullDir);
$this->GetFileNameSubstitutionList($App, $pParams, $FullDir);
if(!opendir(BIN, $FullDir)) {
$App->H2("${ModuleName}::GetFileList: Can't open [$dir]: $!\n");
return;
}
my (@dirs, @files);
my $total = 0;
while( defined (my $file = readdir BIN) ) {
next if($file eq '.' or $file eq '..');
$total++;
my $FullPath = Utils::MakePath($FullDir, $file, '/', 0);
if(-d $FullPath) {
# my $link = $this->MakeDirLink($App, $pParams, $FullPath, "[$file]", '_blank');
# push (@dirs, $link);
push (@dirs, $file);
}
else {
# my $link = $this->MakeFileLink($App, $pParams, $FullPath, "$file", '_blank');
# push (@files, $link);
push (@files, $file);
}
}
closedir(BIN);
return if($total == 0);
print "";
# print Folders
foreach my $file (sort @dirs) {
my $FullPath = Utils::MakePath($FullDir, $file, '/', 0);
next if(!-e $FullPath);
my $path = $dir . $file;
my ($type, $label, $filename) = $this->GetFileInf($App, $pParams, $FullPath, $pParams->{WebCharCode});
Jcode::convert(\$path, $pParams->{WebCharCode}, $pParams->{FileSystemCharCode});
Jcode::convert(\$file, $pParams->{WebCharCode}, $pParams->{FileSystemCharCode});
$path = Utils::URLEncode($path);
print '- ' . $label . '
';
}
# print Files
foreach my $file (sort @files) {
my $FullPath = Utils::MakePath($FullDir, $file, '/', 0);
next if(!-e $FullPath);
$file =~ /\.(.+)$/;
my $ext = $1;
my $path = $dir . $file;
my ($type, $label, $filename) = $this->GetFileInf($App, $pParams, $path, $pParams->{WebCharCode});
Jcode::convert(\$ext, $pParams->{WebCharCode}, $pParams->{FileSystemCharCode});
Jcode::convert(\$path, $pParams->{WebCharCode}, $pParams->{FileSystemCharCode});
Jcode::convert(\$file, $pParams->{WebCharCode}, $pParams->{FileSystemCharCode});
$path = Utils::URLEncode($path);
#$path =~ s/\.\///g;
#$path = Utils::MakePath($RootDir, $path, '/', 0);
#$path = Utils::ReduceDirectory(Utils::MakePath($RootDir, $path, '/', 0));
print '- ' . $label . '
';
}
print "
\n";
}
sub ShowTreeViewPage
{
my ($this, $App, $pParams, $pPrevFunc, $pPostFunc) = @_;
# $App->SendNotificationForPrivilegedAccessMail($App, $pParams);
return if(!$this->IsOpen($App, $pParams, 0));
my $Action = "$this->{ModuleName}::GetFileList";
my $RootDir = $this->GetRootPath($App, $pParams);
#$App->print("RT[$this->{RootPath}]\n");
my $s =<
Browse [$RootDir]