[freeside-commits] freeside/httemplate/elements/fckeditor/editor/filemanager/connectors/perl basexml.pl, NONE, 1.1.2.2 commands.pl, NONE, 1.1.2.2 config.pl, NONE, 1.1.2.2 connector.cgi, NONE, 1.1.2.2 io.pl, NONE, 1.1.2.2 upload.cgi, NONE, 1.1.2.2 upload_fck.pl, NONE, 1.1.2.2 util.pl, NONE, 1.1.2.2
Mark Wells
mark at wavetail.420.am
Tue Mar 16 01:34:57 PDT 2010
- Previous message: [freeside-commits] freeside/httemplate/elements/fckeditor/editor/filemanager/connectors test.html, NONE, 1.1.2.2 uploadtest.html, NONE, 1.1.2.2
- Next message: [freeside-commits] freeside/httemplate/elements/fckeditor/editor/js fckadobeair.js, NONE, 1.1.2.2 fckeditorcode_gecko.js, 1.1, 1.1.6.1 fckeditorcode_ie.js, 1.1, 1.1.6.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /home/cvs/cvsroot/freeside/httemplate/elements/fckeditor/editor/filemanager/connectors/perl
In directory wavetail.420.am:/tmp/cvs-serv23603/editor/filemanager/connectors/perl
Added Files:
Tag: FREESIDE_1_9_BRANCH
basexml.pl commands.pl config.pl connector.cgi io.pl
upload.cgi upload_fck.pl util.pl
Log Message:
FCKeditor 2.6.6
--- NEW FILE: upload.cgi ---
#!/usr/bin/env perl
#####
# FCKeditor - The text editor for Internet - http://www.fckeditor.net
# Copyright (C) 2003-2010 Frederico Caldeira Knabben
#
# == BEGIN LICENSE ==
#
# Licensed under the terms of any of the following licenses at your
# choice:
#
# - GNU General Public License Version 2 or later (the "GPL")
# http://www.gnu.org/licenses/gpl.html
#
# - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
# http://www.gnu.org/licenses/lgpl.html
#
# - Mozilla Public License Version 1.1 or later (the "MPL")
# http://www.mozilla.org/MPL/MPL-1.1.html
#
# == END LICENSE ==
#
# This is the File Manager Connector for Perl.
#####
##
# ATTENTION: To enable this connector, look for the "SECURITY" comment in config.pl.
##
## START: Hack for Windows (Not important to understand the editor code... Perl specific).
if(Windows_check()) {
chdir(GetScriptPath($0));
}
sub Windows_check
{
# IIS,PWS(NT/95)
$www_server_os = $^O;
# Win98 & NT(SP4)
if($www_server_os eq "") { $www_server_os= $ENV{'OS'}; }
# AnHTTPd/Omni/IIS
if($ENV{'SERVER_SOFTWARE'} =~ /AnWeb|Omni|IIS\//i) { $www_server_os= 'win'; }
# Win Apache
if($ENV{'WINDIR'} ne "") { $www_server_os= 'win'; }
if($www_server_os=~ /win/i) { return(1); }
return(0);
}
sub GetScriptPath {
local($path) = @_;
if($path =~ /[\:\/\\]/) { $path =~ s/(.*?)[\/\\][^\/\\]+$/$1/; } else { $path = '.'; }
$path;
}
## END: Hack for IIS
require 'util.pl';
require 'io.pl';
require 'basexml.pl';
require 'commands.pl';
require 'upload_fck.pl';
require 'config.pl';
&read_input();
&DoResponse();
sub DoResponse
{
# Get the main request information.
$sCommand = 'FileUpload';
$sResourceType = &specialchar_cnv($FORM{'Type'});
$sCurrentFolder = "/";
if ($sResourceType eq '') {
$sResourceType = 'File' ;
}
if ( !($sResourceType =~ /^(File|Image|Flash|Media)$/) ) {
SendError( 1, "Invalid type specified" ) ;
}
# File Upload doesn't have to Return XML, so it must be intercepted before anything.
if($sCommand eq 'FileUpload') {
FileUpload($sResourceType,$sCurrentFolder);
return ;
}
}
--- NEW FILE: commands.pl ---
#####
# FCKeditor - The text editor for Internet - http://www.fckeditor.net
# Copyright (C) 2003-2010 Frederico Caldeira Knabben
#
# == BEGIN LICENSE ==
#
# Licensed under the terms of any of the following licenses at your
# choice:
#
# - GNU General Public License Version 2 or later (the "GPL")
# http://www.gnu.org/licenses/gpl.html
#
# - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
# http://www.gnu.org/licenses/lgpl.html
#
# - Mozilla Public License Version 1.1 or later (the "MPL")
# http://www.mozilla.org/MPL/MPL-1.1.html
#
# == END LICENSE ==
#
# This is the File Manager Connector for Perl.
#####
sub GetFolders
{
local($resourceType, $currentFolder) = @_;
# Map the virtual path to the local server path.
$sServerDir = &ServerMapFolder($resourceType, $currentFolder);
print "<Folders>"; # Open the "Folders" node.
opendir(DIR,"$sServerDir");
@files = grep(!/^\.\.?$/,readdir(DIR));
closedir(DIR);
foreach $sFile (@files) {
if($sFile != '.' && $sFile != '..' && (-d "$sServerDir$sFile")) {
$cnv_filename = &ConvertToXmlAttribute($sFile);
print '<Folder name="' . $cnv_filename . '" />';
}
}
print "</Folders>"; # Close the "Folders" node.
}
sub GetFoldersAndFiles
{
local($resourceType, $currentFolder) = @_;
# Map the virtual path to the local server path.
$sServerDir = &ServerMapFolder($resourceType,$currentFolder);
# Initialize the output buffers for "Folders" and "Files".
$sFolders = '<Folders>';
$sFiles = '<Files>';
opendir(DIR,"$sServerDir");
@files = grep(!/^\.\.?$/,readdir(DIR));
closedir(DIR);
foreach $sFile (@files) {
if($sFile ne '.' && $sFile ne '..') {
if(-d "$sServerDir$sFile") {
$cnv_filename = &ConvertToXmlAttribute($sFile);
$sFolders .= '<Folder name="' . $cnv_filename . '" />' ;
} else {
($iFileSize,$refdate,$filedate,$fileperm) = (stat("$sServerDir$sFile"))[7,8,9,2];
if($iFileSize > 0) {
$iFileSize = int($iFileSize / 1024);
if($iFileSize < 1) {
$iFileSize = 1;
}
}
$cnv_filename = &ConvertToXmlAttribute($sFile);
$sFiles .= '<File name="' . $cnv_filename . '" size="' . $iFileSize . '" />' ;
}
}
}
print $sFolders ;
print '</Folders>'; # Close the "Folders" node.
print $sFiles ;
print '</Files>'; # Close the "Files" node.
}
sub CreateFolder
{
local($resourceType, $currentFolder) = @_;
$sErrorNumber = '0' ;
$sErrorMsg = '' ;
if($FORM{'NewFolderName'} ne "") {
$sNewFolderName = $FORM{'NewFolderName'};
$sNewFolderName =~ s/\.|\\|\/|\||\:|\?|\*|\"|<|>|[[:cntrl:]]/_/g;
# Map the virtual path to the local server path of the current folder.
$sServerDir = &ServerMapFolder($resourceType, $currentFolder);
if(-w $sServerDir) {
$sServerDir .= $sNewFolderName;
$sErrorMsg = &CreateServerFolder($sServerDir);
if($sErrorMsg == 0) {
$sErrorNumber = '0';
} elsif($sErrorMsg eq 'Invalid argument' || $sErrorMsg eq 'No such file or directory') {
$sErrorNumber = '102'; #// Path too long.
} else {
$sErrorNumber = '110';
}
} else {
$sErrorNumber = '103';
}
} else {
$sErrorNumber = '102' ;
}
# Create the "Error" node.
$cnv_errmsg = &ConvertToXmlAttribute($sErrorMsg);
print '<Error number="' . $sErrorNumber . '" />';
}
sub FileUpload
{
eval("use File::Copy;");
local($resourceType, $currentFolder) = @_;
$allowedExtensions = $allowedExtensions{$resourceType};
$sErrorNumber = '0' ;
$sFileName = '' ;
if($new_fname) {
# Map the virtual path to the local server path.
$sServerDir = &ServerMapFolder($resourceType,$currentFolder);
# Get the uploaded file name.
$sFileName = $new_fname;
$sFileName =~ s/\\|\/|\||\:|\?|\*|\"|<|>|[[:cntrl:]]/_/g;
$sFileName =~ s/\.(?![^.]*$)/_/g;
$ext = '';
if($sFileName =~ /([^\\\/]*)\.(.*)$/) {
$ext = $2;
}
$allowedRegex = qr/^($allowedExtensions)$/i;
if (!($ext =~ $allowedRegex)) {
SendUploadResults('202', '', '', '');
}
$sOriginalFileName = $sFileName;
$iCounter = 0;
while(1) {
$sFilePath = $sServerDir . $sFileName;
if(-e $sFilePath) {
$iCounter++ ;
($path,$BaseName,$ext) = &RemoveExtension($sOriginalFileName);
$sFileName = $BaseName . '(' . $iCounter . ').' . $ext;
$sErrorNumber = '201';
} else {
copy("$img_dir/$new_fname","$sFilePath");
if (defined $CHMOD_ON_UPLOAD) {
if ($CHMOD_ON_UPLOAD) {
umask(000);
chmod($CHMOD_ON_UPLOAD,$sFilePath);
}
}
else {
umask(000);
chmod(0777,$sFilePath);
}
unlink("$img_dir/$new_fname");
last;
}
}
} else {
$sErrorNumber = '202' ;
}
$sFileName =~ s/"/\\"/g;
SendUploadResults($sErrorNumber, $GLOBALS{'UserFilesPath'}.$resourceType.$currentFolder.$sFileName, $sFileName, '');
}
sub SendUploadResults
{
local($sErrorNumber, $sFileUrl, $sFileName, $customMsg) = @_;
# Minified version of the document.domain automatic fix script (#1919).
# The original script can be found at _dev/domain_fix_template.js
# Note: in Perl replace \ with \\ and $ with \$
print <<EOF;
Content-type: text/html
<script type="text/javascript">
(function(){var d=document.domain;while (true){try{var A=window.parent.document.domain;break;}catch(e) {};d=d.replace(/.*?(?:\\.|\$)/,'');if (d.length==0) break;try{document.domain=d;}catch (e){break;}}})();
EOF
print 'window.parent.OnUploadCompleted(' . $sErrorNumber . ',"' . JS_cnv($sFileUrl) . '","' . JS_cnv($sFileName) . '","' . JS_cnv($customMsg) . '") ;';
print '</script>';
exit ;
}
1;
--- NEW FILE: connector.cgi ---
#!/usr/bin/env perl
#####
# FCKeditor - The text editor for Internet - http://www.fckeditor.net
# Copyright (C) 2003-2010 Frederico Caldeira Knabben
#
# == BEGIN LICENSE ==
#
# Licensed under the terms of any of the following licenses at your
# choice:
#
# - GNU General Public License Version 2 or later (the "GPL")
# http://www.gnu.org/licenses/gpl.html
#
# - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
# http://www.gnu.org/licenses/lgpl.html
#
# - Mozilla Public License Version 1.1 or later (the "MPL")
# http://www.mozilla.org/MPL/MPL-1.1.html
#
# == END LICENSE ==
#
# This is the File Manager Connector for Perl.
#####
##
# ATTENTION: To enable this connector, look for the "SECURITY" comment in config.pl.
##
## START: Hack for Windows (Not important to understand the editor code... Perl specific).
if(Windows_check()) {
chdir(GetScriptPath($0));
}
sub Windows_check
{
# IIS,PWS(NT/95)
$www_server_os = $^O;
# Win98 & NT(SP4)
if($www_server_os eq "") { $www_server_os= $ENV{'OS'}; }
# AnHTTPd/Omni/IIS
if($ENV{'SERVER_SOFTWARE'} =~ /AnWeb|Omni|IIS\//i) { $www_server_os= 'win'; }
# Win Apache
if($ENV{'WINDIR'} ne "") { $www_server_os= 'win'; }
if($www_server_os=~ /win/i) { return(1); }
return(0);
}
sub GetScriptPath {
local($path) = @_;
if($path =~ /[\:\/\\]/) { $path =~ s/(.*?)[\/\\][^\/\\]+$/$1/; } else { $path = '.'; }
$path;
}
## END: Hack for IIS
require 'util.pl';
require 'io.pl';
require 'basexml.pl';
require 'commands.pl';
require 'upload_fck.pl';
require 'config.pl';
&read_input();
&DoResponse();
sub DoResponse
{
if($FORM{'Command'} eq "" || $FORM{'Type'} eq "" || $FORM{'CurrentFolder'} eq "") {
return ;
}
# Get the main request informaiton.
$sCommand = &specialchar_cnv($FORM{'Command'});
$sResourceType = &specialchar_cnv($FORM{'Type'});
$sCurrentFolder = $FORM{'CurrentFolder'};
if ( !($sCommand =~ /^(FileUpload|GetFolders|GetFoldersAndFiles|CreateFolder)$/) ) {
SendError( 1, "Command not allowed" ) ;
}
if ( !($sResourceType =~ /^(File|Image|Flash|Media)$/) ) {
SendError( 1, "Invalid type specified" ) ;
}
# Check the current folder syntax (must begin and start with a slash).
if(!($sCurrentFolder =~ /\/$/)) {
$sCurrentFolder .= '/';
}
if(!($sCurrentFolder =~ /^\//)) {
$sCurrentFolder = '/' . $sCurrentFolder;
}
# Check for invalid folder paths (..)
if ( $sCurrentFolder =~ /(?:\.\.|\\)/ ) {
SendError( 102, "" ) ;
}
if ( $sCurrentFolder =~ /(\/\.)|[[:cntrl:]]|(\/\/)|(\\\\)|([\:\*\?\"\<\>\|])/ ) {
SendError( 102, "" ) ;
}
# File Upload doesn't have to Return XML, so it must be intercepted before anything.
if($sCommand eq 'FileUpload') {
FileUpload($sResourceType,$sCurrentFolder);
return ;
}
print << "_HTML_HEAD_";
Content-Type:text/xml; charset=utf-8
Pragma: no-cache
Cache-Control: no-cache
Expires: Thu, 01 Dec 1994 16:00:00 GMT
_HTML_HEAD_
&CreateXmlHeader($sCommand,$sResourceType,$sCurrentFolder);
# Execute the required command.
if($sCommand eq 'GetFolders') {
&GetFolders($sResourceType,$sCurrentFolder);
} elsif($sCommand eq 'GetFoldersAndFiles') {
&GetFoldersAndFiles($sResourceType,$sCurrentFolder);
} elsif($sCommand eq 'CreateFolder') {
&CreateFolder($sResourceType,$sCurrentFolder);
}
&CreateXmlFooter();
exit ;
}
--- NEW FILE: upload_fck.pl ---
#####
# FCKeditor - The text editor for Internet - http://www.fckeditor.net
# Copyright (C) 2003-2010 Frederico Caldeira Knabben
#
# == BEGIN LICENSE ==
#
# Licensed under the terms of any of the following licenses at your
# choice:
#
# - GNU General Public License Version 2 or later (the "GPL")
# http://www.gnu.org/licenses/gpl.html
#
# - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
# http://www.gnu.org/licenses/lgpl.html
#
# - Mozilla Public License Version 1.1 or later (the "MPL")
# http://www.mozilla.org/MPL/MPL-1.1.html
#
# == END LICENSE ==
#
# This is the File Manager Connector for Perl.
#####
# image data save dir
$img_dir = './temp/';
# File size max(unit KB)
$MAX_CONTENT_SIZE = 30000;
# After file is uploaded, sometimes it is required to change its permissions
# so that it was possible to access it at the later time.
# If possible, it is recommended to set more restrictive permissions, like 0755.
# Set to 0 to disable this feature.
$CHMOD_ON_UPLOAD = 0777;
# See comments above.
# Used when creating folders that does not exist.
$CHMOD_ON_FOLDER_CREATE = 0755;
# Filelock (1=use,0=not use)
$PM{'flock'} = '1';
# upload Content-Type list
my %UPLOAD_CONTENT_TYPE_LIST = (
'image/(x-)?png' => 'png', # PNG image
'image/p?jpe?g' => 'jpg', # JPEG image
'image/gif' => 'gif', # GIF image
'image/x-xbitmap' => 'xbm', # XBM image
'image/(x-(MS-)?)?bmp' => 'bmp', # Windows BMP image
'image/pict' => 'pict', # Macintosh PICT image
'image/tiff' => 'tif', # TIFF image
'application/pdf' => 'pdf', # PDF image
'application/x-shockwave-flash' => 'swf', # Shockwave Flash
'video/(x-)?msvideo' => 'avi', # Microsoft Video
'video/quicktime' => 'mov', # QuickTime Video
'video/mpeg' => 'mpeg', # MPEG Video
'video/x-mpeg2' => 'mpv2', # MPEG2 Video
'audio/(x-)?midi?' => 'mid', # MIDI Audio
'audio/(x-)?wav' => 'wav', # WAV Audio
'audio/basic' => 'au', # ULAW Audio
'audio/mpeg' => 'mpga', # MPEG Audio
'application/(x-)?zip(-compressed)?' => 'zip', # ZIP Compress
'text/html' => 'html', # HTML
'text/plain' => 'txt', # TEXT
'(?:application|text)/(?:rtf|richtext)' => 'rtf', # RichText
'application/msword' => 'doc', # Microsoft Word
'application/vnd.ms-excel' => 'xls', # Microsoft Excel
''
);
# Upload is permitted.
# A regular expression is possible.
my %UPLOAD_EXT_LIST = (
'png' => 'PNG image',
'p?jpe?g|jpe|jfif|pjp' => 'JPEG image',
'gif' => 'GIF image',
'xbm' => 'XBM image',
'bmp|dib|rle' => 'Windows BMP image',
'pi?ct' => 'Macintosh PICT image',
'tiff?' => 'TIFF image',
'pdf' => 'PDF image',
'swf' => 'Shockwave Flash',
'avi' => 'Microsoft Video',
'moo?v|qt' => 'QuickTime Video',
'm(p(e?gv?|e|v)|1v)' => 'MPEG Video',
'mp(v2|2v)' => 'MPEG2 Video',
'midi?|kar|smf|rmi|mff' => 'MIDI Audio',
'wav' => 'WAVE Audio',
'au|snd' => 'ULAW Audio',
'mp(e?ga|2|a|3)|abs' => 'MPEG Audio',
'zip' => 'ZIP Compress',
'lzh' => 'LZH Compress',
'cab' => 'CAB Compress',
'd?html?' => 'HTML',
'rtf|rtx' => 'RichText',
'txt|text' => 'Text',
''
);
# sjis or euc
my $CHARCODE = 'sjis';
$TRANS_2BYTE_CODE = 0;
##############################################################################
# Summary
#
# Form Read input
#
# Parameters
# Returns
# Memo
##############################################################################
sub read_input
{
eval("use File::Copy;");
eval("use File::Path;");
my ($FORM) = @_;
if (defined $CHMOD_ON_FOLDER_CREATE && !$CHMOD_ON_FOLDER_CREATE) {
mkdir("$img_dir");
}
else {
umask(000);
if (defined $CHMOD_ON_FOLDER_CREATE) {
mkdir("$img_dir",$CHMOD_ON_FOLDER_CREATE);
}
else {
mkdir("$img_dir",0777);
}
}
undef $img_data_exists;
undef @NEWFNAMES;
undef @NEWFNAME_DATA;
if($ENV{'CONTENT_LENGTH'} > 10000000 || $ENV{'CONTENT_LENGTH'} > $MAX_CONTENT_SIZE * 1024) {
&upload_error(
'Size Error',
sprintf(
"Transmitting size is too large.MAX <strong>%d KB</strong> Now Size <strong>%d KB</strong>(<strong>%d bytes</strong> Over)",
$MAX_CONTENT_SIZE,
int($ENV{'CONTENT_LENGTH'} / 1024),
$ENV{'CONTENT_LENGTH'} - $MAX_CONTENT_SIZE * 1024
)
);
}
my $Buffer;
if($ENV{'CONTENT_TYPE'} =~ /multipart\/form-data/) {
# METHOD POST only
return unless($ENV{'CONTENT_LENGTH'});
binmode(STDIN);
# STDIN A pause character is detected.'(MacIE3.0 boundary of $ENV{'CONTENT_TYPE'} cannot be trusted.)
my $Boundary = <STDIN>;
$Boundary =~ s/\x0D\x0A//;
$Boundary = quotemeta($Boundary);
while(<STDIN>) {
if(/^\s*Content-Disposition:/i) {
my($name,$ContentType,$FileName);
# form data get
if(/\bname="([^"]+)"/i || /\bname=([^\s:;]+)/i) {
$name = $1;
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
&Encode(\$name);
}
if(/\bfilename="([^"]*)"/i || /\bfilename=([^\s:;]*)/i) {
$FileName = $1 || 'unknown';
}
# head read
while(<STDIN>) {
last if(! /\w/);
if(/^\s*Content-Type:\s*"([^"]+)"/i || /^\s*Content-Type:\s*([^\s:;]+)/i) {
$ContentType = $1;
}
}
# body read
$value = "";
while(<STDIN>) {
last if(/^$Boundary/o);
$value .= $_;
};
$lastline = $_;
$value =~s /\x0D\x0A$//;
if($value ne '') {
if($FileName || $ContentType) {
$img_data_exists = 1;
(
$FileName, #
$Ext, #
$Length, #
$ImageWidth, #
$ImageHeight, #
$ContentName #
) = &CheckContentType(\$value,$FileName,$ContentType);
$FORM{$name} = $FileName;
$new_fname = $FileName;
push(@NEWFNAME_DATA,"$FileName\t$Ext\t$Length\t$ImageWidth\t$ImageHeight\t$ContentName");
# Multi-upload correspondence
push(@NEWFNAMES,$new_fname);
open(OUT,">$img_dir/$new_fname");
binmode(OUT);
eval "flock(OUT,2);" if($PM{'flock'} == 1);
print OUT $value;
eval "flock(OUT,8);" if($PM{'flock'} == 1);
close(OUT);
} elsif($name) {
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
&Encode(\$value,'trans');
$FORM{$name} .= "\0" if(defined($FORM{$name}));
$FORM{$name} .= $value;
}
}
};
last if($lastline =~ /^$Boundary\-\-/o);
}
} elsif($ENV{'CONTENT_LENGTH'}) {
read(STDIN,$Buffer,$ENV{'CONTENT_LENGTH'});
}
foreach(split(/&/,$Buffer),split(/&/,$ENV{'QUERY_STRING'})) {
my($name, $value) = split(/=/);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
&Encode(\$name);
&Encode(\$value,'trans');
$FORM{$name} .= "\0" if(defined($FORM{$name}));
$FORM{$name} .= $value;
}
}
##############################################################################
# Summary
#
# CheckContentType
#
# Parameters
# Returns
# Memo
##############################################################################
sub CheckContentType
{
my($DATA,$FileName,$ContentType) = @_;
my($Ext,$ImageWidth,$ImageHeight,$ContentName,$Infomation);
my $DataLength = length($$DATA);
# An unknown file type
$_ = $ContentType;
my $UnknownType = (
!$_
|| /^application\/(x-)?macbinary$/i
|| /^application\/applefile$/i
|| /^application\/octet-stream$/i
|| /^text\/plane$/i
|| /^x-unknown-content-type/i
);
# MacBinary(Mac Unnecessary data are deleted.)
if($UnknownType || $ENV{'HTTP_USER_AGENT'} =~ /Macintosh|Mac_/) {
if($DataLength > 128 && !unpack("C",substr($$DATA,0,1)) && !unpack("C",substr($$DATA,74,1)) && !unpack("C",substr($$DATA,82,1)) ) {
my $MacBinary_ForkLength = unpack("N", substr($$DATA, 83, 4)); # ForkLength Get
my $MacBinary_FileName = quotemeta(substr($$DATA, 2, unpack("C",substr($$DATA, 1, 1))));
if($MacBinary_FileName && $MacBinary_ForkLength && $DataLength >= $MacBinary_ForkLength + 128
&& ($FileName =~ /$MacBinary_FileName/i || substr($$DATA,102,4) eq 'mBIN')) { # DATA TOP 128byte MacBinary!!
$$DATA = substr($$DATA,128,$MacBinary_ForkLength);
my $ResourceLength = $DataLength - $MacBinary_ForkLength - 128;
$DataLength = $MacBinary_ForkLength;
}
}
}
# A file name is changed into EUC.
# &jcode::convert(\$FileName,'euc',$FormCodeDefault);
# &jcode::h2z_euc(\$FileName);
$FileName =~ s/^.*\\//; # Windows, Mac
$FileName =~ s/^.*\///; # UNIX
$FileName =~ s/&/&/g;
$FileName =~ s/"/"/g;
$FileName =~ s/</</g;
$FileName =~ s/>/>/g;
#
# if($CHARCODE ne 'euc') {
# &jcode::convert(\$FileName,$CHARCODE,'euc');
# }
# An extension is extracted and it changes into a small letter.
my $FileExt;
if($FileName =~ /\.(\w+)$/) {
$FileExt = $1;
$FileExt =~ tr/A-Z/a-z/;
}
# Executable file detection (ban on upload)
if($$DATA =~ /^MZ/) {
$Ext = 'exe';
}
# text
if(!$Ext && ($UnknownType || $ContentType =~ /^text\//i || $ContentType =~ /^application\/(?:rtf|richtext)$/i || $ContentType =~ /^image\/x-xbitmap$/i)
&& ! $$DATA =~ /[\000-\006\177\377]/) {
# $$DATA =~ s/\x0D\x0A/\n/g;
# $$DATA =~ tr/\x0D\x0A/\n\n/;
#
# if(
# $$DATA =~ /<\s*SCRIPT(?:.|\n)*?>/i
# || $$DATA =~ /<\s*(?:.|\n)*?\bONLOAD\s*=(?:.|\n)*?>/i
# || $$DATA =~ /<\s*(?:.|\n)*?\bONCLICK\s*=(?:.|\n)*?>/i
# ) {
# $Infomation = '(JavaScript contains)';
# }
# if($$DATA =~ /<\s*TABLE(?:.|\n)*?>/i
# || $$DATA =~ /<\s*BLINK(?:.|\n)*?>/i
# || $$DATA =~ /<\s*MARQUEE(?:.|\n)*?>/i
# || $$DATA =~ /<\s*OBJECT(?:.|\n)*?>/i
# || $$DATA =~ /<\s*EMBED(?:.|\n)*?>/i
# || $$DATA =~ /<\s*FRAME(?:.|\n)*?>/i
# || $$DATA =~ /<\s*APPLET(?:.|\n)*?>/i
# || $$DATA =~ /<\s*FORM(?:.|\n)*?>/i
# || $$DATA =~ /<\s*(?:.|\n)*?\bSRC\s*=(?:.|\n)*?>/i
# || $$DATA =~ /<\s*(?:.|\n)*?\bDYNSRC\s*=(?:.|\n)*?>/i
# ) {
# $Infomation = '(the HTML tag which is not safe is included)';
# }
if($FileExt =~ /^txt$/i || $FileExt =~ /^cgi$/i || $FileExt =~ /^pl$/i) { # Text File
$Ext = 'txt';
} elsif($ContentType =~ /^text\/html$/i || $FileExt =~ /html?/i || $$DATA =~ /<\s*HTML(?:.|\n)*?>/i) { # HTML File
$Ext = 'html';
} elsif($ContentType =~ /^image\/x-xbitmap$/i || $FileExt =~ /^xbm$/i) { # XBM(x-BitMap) Image
my $XbmName = $1;
my ($XbmWidth, $XbmHeight);
if($$DATA =~ /\#define\s*$XbmName\_width\s*(\d+)/i) {
$XbmWidth = $1;
}
if($$DATA =~ /\#define\s*$XbmName\_height\s*(\d+)/i) {
$XbmHeight = $1;
}
if($XbmWidth && $XbmHeight) {
$Ext = 'xbm';
$ImageWidth = $XbmWidth;
$ImageHeight = $XbmHeight;
}
} else { #
$Ext = 'txt';
}
}
# image
if(!$Ext && ($UnknownType || $ContentType =~ /^image\//i)) {
# PNG
if($$DATA =~ /^\x89PNG\x0D\x0A\x1A\x0A/) {
if(substr($$DATA, 12, 4) eq 'IHDR') {
$Ext = 'png';
($ImageWidth, $ImageHeight) = unpack("N2", substr($$DATA, 16, 8));
}
} elsif($$DATA =~ /^GIF8(?:9|7)a/) { # GIF89a(modified), GIF89a, GIF87a
$Ext = 'gif';
($ImageWidth, $ImageHeight) = unpack("v2", substr($$DATA, 6, 4));
} elsif($$DATA =~ /^II\x2a\x00\x08\x00\x00\x00/ || $$DATA =~ /^MM\x00\x2a\x00\x00\x00\x08/) { # TIFF
$Ext = 'tif';
} elsif($$DATA =~ /^BM/) { # BMP
$Ext = 'bmp';
} elsif($$DATA =~ /^\xFF\xD8\xFF/ || $$DATA =~ /JFIF/) { # JPEG
my $HeaderPoint = index($$DATA, "\xFF\xD8\xFF", 0);
my $Point = $HeaderPoint + 2;
while($Point < $DataLength) {
my($Maker, $MakerType, $MakerLength) = unpack("C2n",substr($$DATA,$Point,4));
if($Maker != 0xFF || $MakerType == 0xd9 || $MakerType == 0xda) {
last;
} elsif($MakerType >= 0xC0 && $MakerType <= 0xC3) {
$Ext = 'jpg';
($ImageHeight, $ImageWidth) = unpack("n2", substr($$DATA, $Point + 5, 4));
if($HeaderPoint > 0) {
$$DATA = substr($$DATA, $HeaderPoint);
$DataLength = length($$DATA);
}
last;
} else {
$Point += $MakerLength + 2;
}
}
}
}
# audio
if(!$Ext && ($UnknownType || $ContentType =~ /^audio\//i)) {
# MIDI Audio
if($$DATA =~ /^MThd/) {
$Ext = 'mid';
} elsif($$DATA =~ /^\x2esnd/) { # ULAW Audio
$Ext = 'au';
} elsif($$DATA =~ /^RIFF/ || $$DATA =~ /^ID3/ && $$DATA =~ /RIFF/) {
my $HeaderPoint = index($$DATA, "RIFF", 0);
$_ = substr($$DATA, $HeaderPoint + 8, 8);
if(/^WAVEfmt $/) {
# WAVE
if(unpack("V",substr($$DATA, $HeaderPoint + 16, 4)) == 16) {
$Ext = 'wav';
} else { # RIFF WAVE MP3
$Ext = 'mp3';
}
} elsif(/^RMIDdata$/) { # RIFF MIDI
$Ext = 'rmi';
} elsif(/^RMP3data$/) { # RIFF MP3
$Ext = 'rmp';
}
if($ContentType =~ /^audio\//i) {
$Infomation .= '(RIFF '. substr($$DATA, $HeaderPoint + 8, 4). ')';
}
}
}
# a binary file
unless ($Ext) {
# PDF image
if($$DATA =~ /^\%PDF/) {
# Picture size is not measured.
$Ext = 'pdf';
} elsif($$DATA =~ /^FWS/) { # Shockwave Flash
$Ext = 'swf';
} elsif($$DATA =~ /^RIFF/ || $$DATA =~ /^ID3/ && $$DATA =~ /RIFF/) {
my $HeaderPoint = index($$DATA, "RIFF", 0);
$_ = substr($$DATA,$HeaderPoint + 8, 8);
# AVI
if(/^AVI LIST$/) {
$Ext = 'avi';
}
if($ContentType =~ /^video\//i) {
$Infomation .= '(RIFF '. substr($$DATA, $HeaderPoint + 8, 4). ')';
}
} elsif($$DATA =~ /^PK/) { # ZIP Compress File
$Ext = 'zip';
} elsif($$DATA =~ /^MSCF/) { # CAB Compress File
$Ext = 'cab';
} elsif($$DATA =~ /^Rar\!/) { # RAR Compress File
$Ext = 'rar';
} elsif(substr($$DATA, 2, 5) =~ /^\-lh(\d+|d)\-$/) { # LHA Compress File
$Infomation .= "(lh$1)";
$Ext = 'lzh';
} elsif(substr($$DATA, 325, 25) eq "Apple Video Media Handler" || substr($$DATA, 325, 30) eq "Apple \x83\x72\x83\x66\x83\x49\x81\x45\x83\x81\x83\x66\x83\x42\x83\x41\x83\x6E\x83\x93\x83\x68\x83\x89") {
# QuickTime
$Ext = 'mov';
}
}
# Header analysis failure
unless ($Ext) {
# It will be followed if it applies for the MIME type from the browser.
foreach (keys %UPLOAD_CONTENT_TYPE_LIST) {
next unless ($_);
if($ContentType =~ /^$_$/i) {
$Ext = $UPLOAD_CONTENT_TYPE_LIST{$_};
$ContentName = &CheckContentExt($Ext);
if(
grep {$_ eq $Ext;} (
'png',
'gif',
'jpg',
'xbm',
'tif',
'bmp',
'pdf',
'swf',
'mov',
'zip',
'cab',
'lzh',
'rar',
'mid',
'rmi',
'au',
'wav',
'avi',
'exe'
)
) {
$Infomation .= ' / Header analysis failure';
}
if($Ext ne $FileExt && &CheckContentExt($FileExt) eq $ContentName) {
$Ext = $FileExt;
}
last;
}
}
# a MIME type is unknown--It judges from an extension.
unless ($Ext) {
$ContentName = &CheckContentExt($FileExt);
if($ContentName) {
$Ext = $FileExt;
$Infomation .= ' / MIME type is unknown('. $ContentType. ')';
last;
}
}
}
# $ContentName = &CheckContentExt($Ext) unless($ContentName);
# if($Ext && $ContentName) {
# $ContentName .= $Infomation;
# } else {
# &upload_error(
# 'Extension Error',
# "$FileName A not corresponding extension ($Ext)<BR>The extension which can be responded ". join(',', sort values(%UPLOAD_EXT_LIST))
# );
# }
# # SSI Tag Deletion
# if($Ext =~ /.?html?/ && $$DATA =~ /<\!/) {
# foreach (
# 'config',
# 'echo',
# 'exec',
# 'flastmod',
# 'fsize',
# 'include'
# ) {
# $$DATA =~ s/\#\s*$_/\&\#35\;$_/ig
# }
# }
return (
$FileName,
$Ext,
int($DataLength / 1024 + 1),
$ImageWidth,
$ImageHeight,
$ContentName
);
}
##############################################################################
# Summary
#
# Extension discernment
#
# Parameters
# Returns
# Memo
##############################################################################
sub CheckContentExt
{
my($Ext) = @_;
my $ContentName;
foreach (keys %UPLOAD_EXT_LIST) {
next unless ($_);
if($_ && $Ext =~ /^$_$/) {
$ContentName = $UPLOAD_EXT_LIST{$_};
last;
}
}
return $ContentName;
}
##############################################################################
# Summary
#
# Form decode
#
# Parameters
# Returns
# Memo
##############################################################################
sub Encode
{
my($value,$Trans) = @_;
# my $FormCode = &jcode::getcode($value) || $FormCodeDefault;
# $FormCodeDefault ||= $FormCode;
#
# if($Trans && $TRANS_2BYTE_CODE) {
# if($FormCode ne 'euc') {
# &jcode::convert($value, 'euc', $FormCode);
# }
# &jcode::tr(
# $value,
# "\xA3\xB0-\xA3\xB9\xA3\xC1-\xA3\xDA\xA3\xE1-\xA3\xFA",
# '0-9A-Za-z'
# );
# if($CHARCODE ne 'euc') {
# &jcode::convert($value,$CHARCODE,'euc');
# }
# } else {
# if($CHARCODE ne $FormCode) {
# &jcode::convert($value,$CHARCODE,$FormCode);
# }
# }
# if($CHARCODE eq 'euc') {
# &jcode::h2z_euc($value);
# } elsif($CHARCODE eq 'sjis') {
# &jcode::h2z_sjis($value);
# }
}
##############################################################################
# Summary
#
# Error Msg
#
# Parameters
# Returns
# Memo
##############################################################################
sub upload_error
{
local($error_message) = $_[0];
local($error_message2) = $_[1];
print "Content-type: text/html\n\n";
print<<EOF;
<HTML>
<HEAD>
<TITLE>Error Message</TITLE></HEAD>
<BODY>
<table border="1" cellspacing="10" cellpadding="10">
<TR bgcolor="#0000B0">
<TD bgcolor="#0000B0" NOWRAP><font size="-1" color="white"><B>Error Message</B></font></TD>
</TR>
</table>
<UL>
<H4> $error_message </H4>
$error_message2 <BR>
</UL>
</BODY>
</HTML>
EOF
&rm_tmp_uploaded_files; # Image Temporary deletion
exit;
}
##############################################################################
# Summary
#
# Image Temporary deletion
#
# Parameters
# Returns
# Memo
##############################################################################
sub rm_tmp_uploaded_files
{
if($img_data_exists == 1){
sleep 1;
foreach $fname_list(@NEWFNAMES) {
if(-e "$img_dir/$fname_list") {
unlink("$img_dir/$fname_list");
}
}
}
}
1;
--- NEW FILE: util.pl ---
#####
# FCKeditor - The text editor for Internet - http://www.fckeditor.net
# Copyright (C) 2003-2010 Frederico Caldeira Knabben
#
# == BEGIN LICENSE ==
#
# Licensed under the terms of any of the following licenses at your
# choice:
#
# - GNU General Public License Version 2 or later (the "GPL")
# http://www.gnu.org/licenses/gpl.html
#
# - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
# http://www.gnu.org/licenses/lgpl.html
#
# - Mozilla Public License Version 1.1 or later (the "MPL")
# http://www.mozilla.org/MPL/MPL-1.1.html
#
# == END LICENSE ==
#
# This is the File Manager Connector for Perl.
#####
sub RemoveFromStart
{
local($sourceString, $charToRemove) = @_;
$sPattern = '^' . $charToRemove . '+' ;
$sourceString =~ s/^$charToRemove+//g;
return $sourceString;
}
sub RemoveFromEnd
{
local($sourceString, $charToRemove) = @_;
$sPattern = $charToRemove . '+$' ;
$sourceString =~ s/$charToRemove+$//g;
return $sourceString;
}
sub ConvertToXmlAttribute
{
local($value) = @_;
return(&specialchar_cnv($value));
}
sub specialchar_cnv
{
local($ch) = @_;
$ch =~ s/&/&/g; # &
$ch =~ s/\"/"/g; #"
$ch =~ s/\'/'/g; # '
$ch =~ s/</</g; # <
$ch =~ s/>/>/g; # >
return($ch);
}
sub JS_cnv
{
local($ch) = @_;
$ch =~ s/\"/\\\"/g; #"
return($ch);
}
1;
--- NEW FILE: io.pl ---
#####
# FCKeditor - The text editor for Internet - http://www.fckeditor.net
# Copyright (C) 2003-2010 Frederico Caldeira Knabben
#
# == BEGIN LICENSE ==
#
# Licensed under the terms of any of the following licenses at your
# choice:
#
# - GNU General Public License Version 2 or later (the "GPL")
# http://www.gnu.org/licenses/gpl.html
#
# - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
# http://www.gnu.org/licenses/lgpl.html
#
# - Mozilla Public License Version 1.1 or later (the "MPL")
# http://www.mozilla.org/MPL/MPL-1.1.html
#
# == END LICENSE ==
#
# This is the File Manager Connector for Perl.
#####
sub GetUrlFromPath
{
local($resourceType, $folderPath) = @_;
if($resourceType eq '') {
$rmpath = &RemoveFromEnd($GLOBALS{'UserFilesPath'},'/');
return("$rmpath$folderPath");
} else {
return("$GLOBALS{'UserFilesPath'}$resourceType$folderPath");
}
}
sub RemoveExtension
{
local($fileName) = @_;
local($path, $base, $ext);
if($fileName !~ /\./) {
$fileName .= '.';
}
if($fileName =~ /([^\\\/]*)\.(.*)$/) {
$base = $1;
$ext = $2;
if($fileName =~ /(.*)$base\.$ext$/) {
$path = $1;
}
}
return($path,$base,$ext);
}
sub ServerMapFolder
{
local($resourceType,$folderPath) = @_;
# Get the resource type directory.
$sResourceTypePath = $GLOBALS{'UserFilesDirectory'} . $resourceType . '/';
# Ensure that the directory exists.
&CreateServerFolder($sResourceTypePath);
# Return the resource type directory combined with the required path.
$rmpath = &RemoveFromStart($folderPath,'/');
return("$sResourceTypePath$rmpath");
}
sub GetParentFolder
{
local($folderPath) = @_;
$folderPath =~ s/[\/][^\/]+[\/]?$//g;
return $folderPath;
}
sub CreateServerFolder
{
local($folderPath) = @_;
$sParent = &GetParentFolder($folderPath);
# Check if the parent exists, or create it.
if(!(-e $sParent)) {
$sErrorMsg = &CreateServerFolder($sParent);
if($sErrorMsg == 1) {
return(1);
}
}
if(!(-e $folderPath)) {
if (defined $CHMOD_ON_FOLDER_CREATE && !$CHMOD_ON_FOLDER_CREATE) {
mkdir("$folderPath");
}
else {
umask(000);
if (defined $CHMOD_ON_FOLDER_CREATE) {
mkdir("$folderPath",$CHMOD_ON_FOLDER_CREATE);
}
else {
mkdir("$folderPath",0777);
}
}
return(0);
} else {
return(1);
}
}
sub GetRootPath
{
#use Cwd;
# my $dir = getcwd;
# print $dir;
# $dir =~ s/$ENV{'DOCUMENT_ROOT'}//g;
# print $dir;
# return($dir);
# $wk = $0;
# $wk =~ s/\/connector\.cgi//g;
# if($wk) {
# $current_dir = $wk;
# } else {
# $current_dir = `pwd`;
# }
# return($current_dir);
use Cwd;
if($ENV{'DOCUMENT_ROOT'}) {
$dir = $ENV{'DOCUMENT_ROOT'};
} else {
my $dir = getcwd;
$workdir =~ s/\/connector\.cgi//g;
$dir =~ s/$workdir//g;
}
return($dir);
}
1;
--- NEW FILE: basexml.pl ---
#####
# FCKeditor - The text editor for Internet - http://www.fckeditor.net
# Copyright (C) 2003-2010 Frederico Caldeira Knabben
#
# == BEGIN LICENSE ==
#
# Licensed under the terms of any of the following licenses at your
# choice:
#
# - GNU General Public License Version 2 or later (the "GPL")
# http://www.gnu.org/licenses/gpl.html
#
# - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
# http://www.gnu.org/licenses/lgpl.html
#
# - Mozilla Public License Version 1.1 or later (the "MPL")
# http://www.mozilla.org/MPL/MPL-1.1.html
#
# == END LICENSE ==
#
# This is the File Manager Connector for Perl.
#####
sub CreateXmlHeader
{
local($command,$resourceType,$currentFolder) = @_;
# Create the XML document header.
print '<?xml version="1.0" encoding="utf-8" ?>';
# Create the main "Connector" node.
print '<Connector command="' . $command . '" resourceType="' . $resourceType . '">';
# Add the current folder node.
print '<CurrentFolder path="' . ConvertToXmlAttribute($currentFolder) . '" url="' . ConvertToXmlAttribute(GetUrlFromPath($resourceType,$currentFolder)) . '" />';
}
sub CreateXmlFooter
{
print '</Connector>';
}
sub SendError
{
local( $number, $text ) = @_;
print << "_HTML_HEAD_";
Content-Type:text/xml; charset=utf-8
Pragma: no-cache
Cache-Control: no-cache
Expires: Thu, 01 Dec 1994 16:00:00 GMT
_HTML_HEAD_
# Create the XML document header
print '<?xml version="1.0" encoding="utf-8" ?>' ;
if ($text) {
print '<Connector><Error number="' . $number . '" text="' . &specialchar_cnv( $text ) . '" /></Connector>' ;
}
else {
print '<Connector><Error number="' . $number . '" /></Connector>' ;
}
exit ;
}
1;
--- NEW FILE: config.pl ---
#####
# FCKeditor - The text editor for Internet - http://www.fckeditor.net
# Copyright (C) 2003-2010 Frederico Caldeira Knabben
#
# == BEGIN LICENSE ==
#
# Licensed under the terms of any of the following licenses at your
# choice:
#
# - GNU General Public License Version 2 or later (the "GPL")
# http://www.gnu.org/licenses/gpl.html
#
# - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
# http://www.gnu.org/licenses/lgpl.html
#
# - Mozilla Public License Version 1.1 or later (the "MPL")
# http://www.mozilla.org/MPL/MPL-1.1.html
#
# == END LICENSE ==
#
# This is the File Manager Connector for Perl.
#####
##
# SECURITY: REMOVE/COMMENT THE FOLLOWING LINE TO ENABLE THIS CONNECTOR.
##
&SendError( 1, 'This connector is disabled. Please check the "editor/filemanager/connectors/perl/config.cgi" file' ) ;
$GLOBALS{'UserFilesPath'} = '/userfiles/';
# Map the "UserFiles" path to a local directory.
$rootpath = &GetRootPath();
$GLOBALS{'UserFilesDirectory'} = $rootpath . $GLOBALS{'UserFilesPath'};
%allowedExtensions = ("File", "7z|aiff|asf|avi|bmp|csv|doc|fla|flv|gif|gz|gzip|jpeg|jpg|mid|mov|mp3|mp4|mpc|mpeg|mpg|ods|odt|pdf|png|ppt|pxd|qt|ram|rar|rm|rmi|rmvb|rtf|sdc|sitd|swf|sxc|sxw|tar|tgz|tif|tiff|txt|vsd|wav|wma|wmv|xls|xml|zip",
"Image", "bmp|gif|jpeg|jpg|png",
"Flash", "swf|flv",
"Media", "aiff|asf|avi|bmp|fla|flv|gif|jpeg|jpg|mid|mov|mp3|mp4|mpc|mpeg|mpg|png|qt|ram|rm|rmi|rmvb|swf|tif|tiff|wav|wma|wmv"
);
- Previous message: [freeside-commits] freeside/httemplate/elements/fckeditor/editor/filemanager/connectors test.html, NONE, 1.1.2.2 uploadtest.html, NONE, 1.1.2.2
- Next message: [freeside-commits] freeside/httemplate/elements/fckeditor/editor/js fckadobeair.js, NONE, 1.1.2.2 fckeditorcode_gecko.js, 1.1, 1.1.6.1 fckeditorcode_ie.js, 1.1, 1.1.6.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the freeside-commits
mailing list