Update of /cvsroot/thyapi/thyapi/thywidgets/external/fckeditor/editor/filemanager/browser/mcpuk/connectors/php/Commands/helpers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv563/thywidgets/external/fckeditor/editor/filemanager/browser/mcpuk/connectors/php/Commands/helpers Added Files: .htaccess header.cgi iconlookup.php progress.cgi upload.cgi Log Message: Commiting file additions and modification from SVN revision 2028 to 2029... Changes made by frank on 2005-09-29 21:42:57 +0200 (Thu, 29 Sep 2005) corresponding to SVN revision 2029 with message: updating fckeditor in dynapi --- NEW FILE: header.cgi --- #!/usr/bin/perl # Mega Upload # PHP File Uploader with progress bar Version 1.42 # Copyright (C) Raditha Dissanyake 2003 # http://www.raditha.com # Licence: # The contents of this file are subject to the Mozilla Public # License Version 1.1 (the "License"); you may not use this file # except in compliance with the License. You may obtain a copy of # the License at http://www.mozilla.org/MPL/ # # Software distributed under the License is distributed on an "AS # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or # implied. See the License for the specific language governing # rights and limitations under the License. # # The Initial Developer of the Original Code is Raditha Dissanayake. # Portions created by Raditha are Copyright (C) 2003 # Raditha Dissanayake. All Rights Reserved. # $tmp_dir="/www/m/c/mcpuk.net/tmp"; $|=1; #unbuffers streams $interval=1; # how often to refresh the progress bar $max_upload = 500000000000; # set this to whatever you feel suitable for you. # don't change the next few lines unless you have a very good reason to. $post_data_file = "$tmp_dir/$sessionid"."_postdata"; $monitor_file = "$tmp_dir/$sessionid"."_flength"; $signal_file = "$tmp_dir/$sessionid"."_signal"; 1; --- NEW FILE: progress.cgi --- #!/usr/bin/perl -w # PHP File Uploader with progress bar Version 1.43 # Copyright (C) Raditha Dissanyake 2003,2004 # http://www.raditha.com # Licence: # The contents of this file are subject to the Mozilla Public # License Version 1.1 (the "License"); you may not use this file # except in compliance with the License. You may obtain a copy of # the License at http://www.mozilla.org/MPL/ # # Software distributed under the License is distributed on an "AS # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or # implied. See the License for the specific language governing # rights and limitations under the License. # # The Initial Developer of the Original Code is Raditha Dissanayake. # Portions created by Raditha are Copyright (C) 2003,2004 # Raditha Dissanayake. All Rights Reserved. # # Portions contributed by Orest Kinasevych are Copyright (C) # 2003 Kinasevych Saj # # CHANGES # 1.00 # No longer uses cookies. This has two major benefits; the first # being that minority of users who do not like cookies are not # inconvinienced. Secondly there is one less dependecy and this # would lead to a smoother setup for most people. # (if you want to use cookies look at the contrib folder) # # 1.02 # added a cache control header in version 1.02 # # 1.10 # Added a more detailed progress bar in version # # 1.42 # The organization of the temporary files have been improved so to # make is easier to clean up after abandoned uploads. (as suggested # by Igor Kryltsov) # # use CGI; use Fcntl qw(:DEFAULT :flock); #use Carp; # Carp is only needed if you want debugging. Uncomment the above line # if you comment out any of the carp statements in the body of the # script. # # the most obvious issue that we will face is file locking. # if two threads read and write from the same file at the same # time only one of them will be allowed to finish the operation. # Since we are storing our temporary data in a file we are likely to # run into that exact same problem. # We can't overcome it but we can make sure the progress bar does # not display junk when that happens. # # # status codes = 0-uploading, 1-started, 2- complete $query = new CGI(); $sessionid = $query->param('sessionid'); $sessionid =~ s/[^a-zA-Z0-9]//g; # santized as suggested by Terrence Johnson. $iTotal = $query->param('iTotal'); $iRead = $query->param('iRead'); $status = $query->param('iStatus'); ## # The code that deals with calculating elapsed time, time remaining # and upload speed were contributed by Orest Kinasevych ## ## # Get values assigned for current time and upload start time ## #$dtnow = $query->param('dtnow'); # assign value for current time $dtnow=time; $dtstart = $query->param('dtstart'); # assign value for upload start time ## #carp "$dtnow $dtstart"; $thisUrl = $query->url; ## # Elapsed time # Calculate elapsed time and format for display ## $dtelapsed = $dtnow - $dtstart; $dtelapsed_sec = ($dtelapsed % 60); # gets number of seconds $dtelapsed_min = ((($dtelapsed - $dtelapsed_sec) % 3600) / 60); # gets number of minutes $dtelapsed_hours = (((($dtelapsed - $dtelapsed_sec) - ($dtelapsed_min * 60)) % 86400) / 3600); # gets number of hours; assuming that we won't be going into days! if ($dtelapsed_sec < 10) { $dtelapsed_sec = "0$dtelapsed_sec"; } # append leading zero if ($dtelapsed_min < 10) { $dtelapsed_min = "0$dtelapsed_min"; } # append leading zero if ($dtelapsed_hours < 10) { $dtelapsed_hours = "0$dtelapsed_hours"; } # append leading zero $dtelapsedf = "$dtelapsed_hours:$dtelapsed_min:$dtelapsed_sec"; # display as 00:00:00 ## ## # Upload speed ## $bSpeed = 0; # if not yet determined if ($dtelapsed > 0) # avoid divide by zero errors { $bSpeed = $iRead / $dtelapsed; # Bytes uploaded / Seconds elapsed = Bytes/Second speed $bitSpeed = $bSpeed * 8; # bps $kbitSpeed = $bitSpeed / 1000; # Kbps } else { $kbitSpeed = $bSpeed; # just pass the zero value } $bSpeedf = sprintf("%d",$kbitSpeed); # remove decimals ## # Est remaining time # Calculate remaining time based on upload speed so far ## $bRemaining = $iTotal - $iRead; # Total size - amount uploaded = amount remaining $dtRemaining = 0; if ($bSpeed > 0) { # Bytes remaining / Bytes/Second = Seconds $dtRemaining = $bRemaining / $bSpeed; } $dtRemaining = sprintf("%d",$dtRemaining); # remove decimals $dtRemaining_sec = ($dtRemaining % 60); # gets number of seconds $dtRemaining_min = ((($dtRemaining - $dtRemaining_sec) % 3600) / 60); # gets number of minutes $dtRemaining_hours = (((($dtRemaining - $dtRemaining_sec) - ($dtRemaining_min * 60)) % 86400) / 3600); # gets number of hours; assuming that we won't be going into days! if ($dtRemaining_sec < 10) { # append leading zero $dtRemaining_sec = "0$dtRemaining_sec"; } if ($dtRemaining_min < 10) { # append leading zero $dtRemaining_min = "0$dtRemaining_min"; } if ($dtRemaining_hours < 10) { # append leading zero $dtRemaining_hours = "0$dtRemaining_hours"; } $dtRemainingf = "$dtRemaining_hours:$dtRemaining_min:$dtRemaining_sec"; # display as 00:00:00 ## # The values for iStatus are # 0 - in progress # 1 - New upload # 2 - Complete ## #carp "iTotal = $iTotal, iRead = $iRead, status = $status, sessionId = $sessionid"; require("./header.cgi"); sub readFlength() { if(open (STAT, $monitor_file)) { sysopen(STAT, $monitor_file, O_RDONLY) or die "can't open numfile: $!"; $ofh = select(STAT); $| = 1; select ($ofh); $iTotal = <STAT>; #carp "trying to read the stuff in $iTotal"; if(defined($iTotal) && $iTotal ne "") { return 1; } else { return 0; } } return 0; } ## # many thanx to Terrence Johnson who pointed out the fact that i should have added # cache control header. ## print "Pragma: no-cache\n"; print "Content-type: text/xml\n\n "; if($status == 1) { #new upload starting show_starting(); } elsif($status ==0) { ## # in progress # we will try to read in the total size of data to be transfered from the # shared file. It will also tell us how much data has been transfered upto # now. ## $bRead = -s "$post_data_file"; if(defined $bRead) { # We have been able to read in it from the file. $percent = $bRead * 100 / $iTotal; $iRead=$bRead; } else { &show_error(); exit(); } # # division results in truncation errors at times so don't compare percentage # There have been occaisional reports of the progress bar showing 100% but not # disappearing even after file upload has been completed. # # Nils Menrad came up with the solution which is to modify the end of upload # test. # if((($iTotal == $bRead) && $bRead != 0) || $bRead>$iTotal) { if($status == 1 && -e "$signal_file") { $bRead=0; $status=0; &get_last_values(); } else { show_complete(); unlink $monitor_file; unlink $post_data_file; unlink $signal_file; exit; } } else { $kachal = "$bRead , $iTotal"; } &make_progress_bar(); exit; } else { show_complete(); } # # Since the progress bar is in html, so it needs to refresh itself periodicaly to # obtain new values. The refresh url with the query string is generated by this # function. sub make_url { #print "Content-type: text/html\n\n "; #print "hellow $iTotal $iStatus $sessionid $iRead <br>\n" ; ## $url = "$thisUrl?iTotal=$iTotal&iRead=$iRead&iStatus=$status&sessionid=$sessionid&dtnow=$dtnow&dtstart=$dtstart"; ## $url =~ s/\n//; return $url; } sub make_progress_bar { $url = make_url(); print <<__PART1__; <UploadProgress sessionID="$sessionid"> <RefreshURL><![CDATA[$url]]></RefreshURL> <TotalBytes>$iTotal</TotalBytes> <ReadBytes>$iRead</ReadBytes> <Status>$status</Status> <Speed>$bSpeedf</Speed> <TimeRemaining>$dtRemainingf</TimeRemaining> <TimeElapsed>$dtelapsedf</TimeElapsed> </UploadProgress> __PART1__ } sub show_complete { $status=2; $url = make_url(); print <<__PART2__; <UploadProgress sessionID="$sessionid"> <RefreshURL><![CDATA[$url]]></RefreshURL> <TotalBytes>$iTotal</TotalBytes> <ReadBytes>$iRead</ReadBytes> <Status>$status</Status> <Speed>$bSpeedf</Speed> <TimeRemaining>0</TimeRemaining> <TimeElapsed>$dtelapsedf</TimeElapsed> </UploadProgress> __PART2__ } sub show_starting { #carp "starting"; if(readFlength() == 1) { $status=0; } $url = make_url(); print <<__PART2__; <UploadProgress sessionID="$sessionid"> <RefreshURL><![CDATA[$url]]></RefreshURL> <TotalBytes>$iTotal</TotalBytes> <ReadBytes>$iRead</ReadBytes> <Status>$status</Status> <Speed>$bSpeedf</Speed> <TimeRemaining>$dtRemainingf</TimeRemaining> <TimeElapsed>$dtelapsedf</TimeElapsed> </UploadProgress> __PART2__ } sub show_error { $url = make_url(); print <<__PART2__; <UploadProgress sessionID="$sessionid"> <RefreshURL><![CDATA[$url]]></RefreshURL> <TotalBytes>$iTotal</TotalBytes> <ReadBytes>$iRead</ReadBytes> <Status>-1</Status> <Speed>$bSpeedf</Speed> <TimeRemaining>$dtRemainingf</TimeRemaining> <TimeElapsed>$dtelapsedf</TimeElapsed> </UploadProgress> __PART2__ } # this function may not return; sub get_last_values() { if($status == 1) { show_starting(); exit; } else { if($status == 2) { show_complete(); exit; } else { # # we have done everything possible to try to retrieve the data # now try to calculate the percentage once again # $iTotal = $iTotal; $bRead = $iRead; if(defined($iTotal) && $iTotal != 0) { $percent = $bRead * 100 / $iTotal; $kachal="1"; } else { &show_error(); exit; } } } } --- NEW FILE: upload.cgi --- #!/usr/bin/perl # PHP File Uploader with progress bar Version 1.43 # Copyright (C) Raditha Dissanyake 2003 # http://www.raditha.com # Licence: # The contents of this file are subject to the Mozilla Public # License Version 1.1 (the "License"); you may not use this file # except in compliance with the License. You may obtain a copy of # the License at http://www.mozilla.org/MPL/ # # Software distributed under this License is distributed on an "AS # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or # implied. See the License for the specific language governing # rights and limitations under the License. # # The Initial Developer of the Original Code is Raditha Dissanayake. # Portions created by Raditha are Copyright (C) 2003 # Raditha Dissanayake. All Rights Reserved. # # CHANGES: # As of version 1.00 cookies were abolished! # as of version 1.02 stdin is no longer set to non blocking. # 1.40 - POST is no longer required and processing is more efficient. # Please refer online docs for details. # 1.42 - The temporary locations were changed, to make it easier to # clean up afterwards. use CGI; use Fcntl qw(:DEFAULT :flock); use File::Temp qw/ tempfile tempdir /; #use Carp; @qstring=split(/&/,$ENV{'QUERY_STRING'}); @p1 = split(/=/,$qstring[0]); $sessionid = $p1[1]; $sessionid =~ s/[^a-zA-Z0-9]//g; # sanitized as suggested by Terrence Johnson. @p1 = split(/=/,$qstring[1]); $php_uploader = $p1[1]; require("./header.cgi"); #carp "$post_data_file and $monitor_file"; $content_type = $ENV{'CONTENT_TYPE'}; $len = $ENV{'CONTENT_LENGTH'}; $bRead=0; $|=1; sub bye_bye { $mes = shift; print "Content-type: text/html\n\n"; print "<br>$mes<br>\n"; exit; } # # The thing to watch out for is file locking. Only # one thread may open a file for writing at any given time. # if (-e "$post_data_file") { unlink("$post_data_file"); } if (-e "$monitor_file") { unlink("$monitor_file"); } sysopen(FH, $monitor_file, O_RDWR | O_CREAT, 0x777) or die "can't open numfile: $!"; # autoflush FH $ofh = select(FH); $| = 1; select ($ofh); flock(FH, LOCK_EX) or die "can't write-lock numfile: $!"; seek(FH, 0, 0) or die "can't rewind numfile : $!"; print FH $len; close(FH); sleep(1); open(TMP,">","$post_data_file") or &bye_bye ("can't open temp file"); # # read and store the raw post data on a temporary file so that we can # pass it though to a CGI instance later on. # my $i=0; $ofh = select(TMP); $| = 1; select ($ofh); while (read (STDIN ,$LINE, 32768) && $bRead < $len ) { $bRead += length $LINE; select(undef, undef, undef,0.01); # sleep for 0.35 of a second. # Many thanx to Patrick Knoell who came up with the optimized value for # the duration of the sleep $i++; print TMP $LINE; } close (TMP); # # We don't want to decode the post data ourselves. That's like # reinventing the wheel. If we handle the post data with the perl # CGI module that means the PHP script does not get access to the # files, but there is a way around this. # # We can ask the CGI module to save the files, then we can pass # these filenames to the PHP script. In other words instead of # giving the raw post data (which contains the 'bodies' of the # files), we just send a list of file names. # #print "\n\n"; open(STDIN,"$post_data_file") or die "can't open temp file"; # chmod the file so everyone can read it # added by Ben Lancaster (be...@st...) chmod (0666, $post_data_file); my $cg = new CGI(); my $qstring="?"; my %vars = $cg->Vars; my $j=0; while(($key,$value) = each %vars) { $file_upload = $cg->param($key); if(defined $value && $value ne '') { my $fh = $cg->upload($key); #print "::".$key."::".$fh."::\n"; if(defined $fh) { #carp $fh; ($tmp_fh, $tmp_filename) = tempfile(); # chmod the file so everyone can read it # added by Ben Lancaster (be...@st...) chmod (0666, $tmp_filename); while(<$fh>) { print $tmp_fh $_; } close($tmp_fh); $fsize =(-s $fh); $fh =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg; $tmp_filename =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg; $qstring .= "file[$key][name]=$fh&file[$key][size]=$fsize&"; $qstring .= "file[$key][tmp_name]=$tmp_filename&"; $j++; } else { $value =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg; $qstring .= "$key=$value&" ; } } } my $url = $php_uploader . $qstring . "&" . $ENV{'QUERY_STRING'}; open (SIGNAL,">", $signal_file); print SIGNAL "\n"; close (SIGNAL); print "Location: $url\n\n"; --- NEW FILE: iconlookup.php --- <?php /* * FCKeditor - The text editor for internet * Copyright (C) 2003-2005 Frederico Caldeira Knabben * * Licensed under the terms of the GNU Lesser General Public License: * http://www.opensource.org/licenses/lgpl-license.php * * For further information visit: * http://www.fckeditor.net/ * * File Name: iconlookup.php * (!) * * File Authors: * Grant French (gr...@mc...) */ function iconLookup($mime,$ext) { $mimeIcons=array( "image"=>"image.jpg", "audio"=>"sound.jpg", "video"=>"video.jpg", "text"=>"document2.jpg", "text/html"=>"html.jpg", "application"=>"binary.jpg", "application/pdf"=>"pdf.jpg", "application/msword"=>"document2.jpg", "application/postscript"=>"postscript.jpg", "application/rtf"=>"document2.jpg", "application/vnd.ms-excel"=>"document2.jpg", "application/vnd.ms-powerpoint"=>"document2.jpg", "application/x-tar"=>"tar.jpg", "application/zip"=>"tar.jpg", "message"=>"email.jpg", "message/html"=>"html.jpg", "model"=>"kmplot.jpg", "multipart"=>"kmultiple.jpg" ); $extIcons=array( "pdf"=>"pdf.jpg", "ps"=>"postscript.jpg", "eps"=>"postscript.jpg", "ai"=>"postscript.jpg", "ra"=>"real_doc.jpg", "rm"=>"real_doc.jpg", "ram"=>"real_doc.jpg", "wav"=>"sound.jpg", "mp3"=>"sound.jpg", "ogg"=>"sound.jpg", "eml"=>"email.jpg", "tar"=>"tar.jpg", "zip"=>"tar.jpg", "bz2"=>"tar.jpg", "tgz"=>"tar.jpg", "gz"=>"tar.jpg", "rar"=>"tar.jpg", "avi"=>"video.jpg", "mpg"=>"video.jpg", "mpeg"=>"video.jpg", "jpg"=>"image.jpg", "gif"=>"image.jpg", "png"=>"image.jpg", "jpeg"=>"image.jpg", "nfo"=>"info.jpg", "xls"=>"spreadsheet.jpg", "csv"=>"spreadsheet.jpg", "html"=>"html.jpg", "doc"=>"document2.jpg", "rtf"=>"document2.jpg", "txt"=>"document2.jpg", "xla"=>"document2.jpg", "xlc"=>"document2.jpg", "xlt"=>"document2.jpg", "xlw"=>"document2.jpg", "txt"=>"document2.jpg" ); if ($mime!="text/plain") { //Check specific cases $mimes=array_keys($mimeIcons); if (in_array($mime,$mimes)) { return $_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF'])."/images/".$mimeIcons[$mime]; } else { //Check for the generic mime type $mimePrefix="text"; $firstSlash=strpos($mime,"/"); if ($firstSlash!==false) $mimePrefix=substr($mime,0,$firstSlash); if (in_array($mimePrefix,$mimes)) { return $_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF'])."/images/".$mimeIcons[$mimePrefix]; } else { return $_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF'])."/images/empty.jpg"; } } } else { $extensions=array_keys($extIcons); if (in_array($ext,$extensions)) { return $_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF'])."/images/".$extIcons[$ext]; } else { return $_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF'])."/images/empty.jpg"; } } return $_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF'])."/images/empty.jpg"; } ?> --- NEW FILE: .htaccess --- Options ExecCGI |