el_finder_ftp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +23 -0
- data/.gitignore +5 -0
- data/.yardopts +7 -0
- data/Gemfile +4 -0
- data/README.md +115 -0
- data/Rakefile +14 -0
- data/TODO +5 -0
- data/el_finder_ftp.gemspec +29 -0
- data/lib/el_finder_ftp.rb +13 -0
- data/lib/el_finder_ftp/action.rb +32 -0
- data/lib/el_finder_ftp/base64.rb +24 -0
- data/lib/el_finder_ftp/connector.rb +618 -0
- data/lib/el_finder_ftp/ftp_adapter.rb +309 -0
- data/lib/el_finder_ftp/ftp_authentication_error.rb +4 -0
- data/lib/el_finder_ftp/ftp_pathname.rb +161 -0
- data/lib/el_finder_ftp/image.rb +30 -0
- data/lib/el_finder_ftp/mime_type.rb +83 -0
- data/lib/el_finder_ftp/pathname.rb +197 -0
- data/lib/el_finder_ftp/railties.rb +7 -0
- data/lib/el_finder_ftp/version.rb +5 -0
- metadata +150 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'shellwords'
|
3
|
+
require 'image_size'
|
4
|
+
|
5
|
+
module ElFinderFtp
|
6
|
+
|
7
|
+
# Represents default image handler.
|
8
|
+
# It uses *mogrify* to resize images and *convert* to create thumbnails.
|
9
|
+
class Image
|
10
|
+
|
11
|
+
def self.size(pathname)
|
12
|
+
return nil unless File.exist?(pathname)
|
13
|
+
s = ::ImageSize.new(File.open(pathname)).size.to_s
|
14
|
+
s = nil if s.empty?
|
15
|
+
return s
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.resize(pathname, options = {})
|
19
|
+
return nil unless File.exist?(pathname)
|
20
|
+
system( ::Shellwords.join(['mogrify', '-resize', "#{options[:width]}x#{options[:height]}!", pathname.to_s]) )
|
21
|
+
end # of self.resize
|
22
|
+
|
23
|
+
def self.thumbnail(src, dst, options = {})
|
24
|
+
return nil unless File.exist?(src)
|
25
|
+
system( ::Shellwords.join(['convert', '-resize', "#{options[:width]}x#{options[:height]}", '-background', 'white', '-gravity', 'center', '-extent', "#{options[:width]}x#{options[:height]}", src.to_s, dst.to_s]) )
|
26
|
+
end # of self.resize
|
27
|
+
|
28
|
+
end # of class Image
|
29
|
+
|
30
|
+
end # of module ElFinderFtp
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module ElFinderFtp
|
2
|
+
|
3
|
+
# Represents default MIME types recognizer.
|
4
|
+
class MimeType
|
5
|
+
|
6
|
+
# File extension to mime type mapping.
|
7
|
+
TYPES = {
|
8
|
+
'ai' => 'application/postscript',
|
9
|
+
'eps' => 'application/postscript',
|
10
|
+
'exe' => 'application/octet-stream',
|
11
|
+
'doc' => 'application/vnd.ms-word',
|
12
|
+
'xls' => 'application/vnd.ms-excel',
|
13
|
+
'ppt' => 'application/vnd.ms-powerpoint',
|
14
|
+
'pps' => 'application/vnd.ms-powerpoint',
|
15
|
+
'pdf' => 'application/pdf',
|
16
|
+
'xml' => 'application/xml',
|
17
|
+
'odt' => 'application/vnd.oasis.opendocument.text',
|
18
|
+
'swf' => 'application/x-shockwave-flash',
|
19
|
+
# archives
|
20
|
+
'gz' => 'application/x-gzip',
|
21
|
+
'tgz' => 'application/x-gzip',
|
22
|
+
'bz' => 'application/x-bzip2',
|
23
|
+
'bz2' => 'application/x-bzip2',
|
24
|
+
'tbz' => 'application/x-bzip2',
|
25
|
+
'zip' => 'application/zip',
|
26
|
+
'rar' => 'application/x-rar',
|
27
|
+
'tar' => 'application/x-tar',
|
28
|
+
'7z' => 'application/x-7z-compressed',
|
29
|
+
# texts
|
30
|
+
'txt' => 'text/plain',
|
31
|
+
'php' => 'text/x-php',
|
32
|
+
'html' => 'text/html',
|
33
|
+
'htm' => 'text/html',
|
34
|
+
'js' => 'text/javascript',
|
35
|
+
'css' => 'text/css',
|
36
|
+
'rtf' => 'text/rtf',
|
37
|
+
'rtfd' => 'text/rtfd',
|
38
|
+
'py' => 'text/x-python',
|
39
|
+
'java' => 'text/x-java-source',
|
40
|
+
'rb' => 'text/x-ruby',
|
41
|
+
'sh' => 'text/x-shellscript',
|
42
|
+
'pl' => 'text/x-perl',
|
43
|
+
'sql' => 'text/x-sql',
|
44
|
+
# images
|
45
|
+
'bmp' => 'image/x-ms-bmp',
|
46
|
+
'jpg' => 'image/jpeg',
|
47
|
+
'jpeg' => 'image/jpeg',
|
48
|
+
'gif' => 'image/gif',
|
49
|
+
'png' => 'image/png',
|
50
|
+
'tif' => 'image/tiff',
|
51
|
+
'tiff' => 'image/tiff',
|
52
|
+
'tga' => 'image/x-targa',
|
53
|
+
'psd' => 'image/vnd.adobe.photoshop',
|
54
|
+
# audio
|
55
|
+
'mp3' => 'audio/mpeg',
|
56
|
+
'mid' => 'audio/midi',
|
57
|
+
'ogg' => 'audio/ogg',
|
58
|
+
'mp4a' => 'audio/mp4',
|
59
|
+
'wav' => 'audio/wav',
|
60
|
+
'wma' => 'audio/x-ms-wma',
|
61
|
+
# video
|
62
|
+
'avi' => 'video/x-msvideo',
|
63
|
+
'dv' => 'video/x-dv',
|
64
|
+
'mp4' => 'video/mp4',
|
65
|
+
'mpeg' => 'video/mpeg',
|
66
|
+
'mpg' => 'video/mpeg',
|
67
|
+
'mov' => 'video/quicktime',
|
68
|
+
'wm' => 'video/x-ms-wmv',
|
69
|
+
'flv' => 'video/x-flv',
|
70
|
+
'mkv' => 'video/x-matroska'
|
71
|
+
}
|
72
|
+
|
73
|
+
# Gets MIME type fort specified path.
|
74
|
+
# @param [::Pathname, String] pathname Path to recognize its MIME type.
|
75
|
+
# @return [String] MIME type if known; 'unknown/unknown' otherwise.
|
76
|
+
def self.for(pathname)
|
77
|
+
pathname = ::Pathname.new(pathname) if pathname.is_a?(String)
|
78
|
+
TYPES[pathname.extname.downcase[1..-1]] || 'application/octet-stream'
|
79
|
+
end # of for
|
80
|
+
|
81
|
+
end # of class MimeType
|
82
|
+
|
83
|
+
end # of module ElFinderFtp
|
@@ -0,0 +1,197 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module ElFinderFtp
|
5
|
+
|
6
|
+
class Pathname
|
7
|
+
attr_reader :root, :path, :adapter
|
8
|
+
|
9
|
+
#
|
10
|
+
def initialize(adapter_or_root, path = '.')
|
11
|
+
@adapter = adapter_or_root.is_a?(ElFinderFtp::Pathname) ? adapter_or_root.adapter : adapter_or_root
|
12
|
+
|
13
|
+
@root = path.is_a?(ElFinderFtp::Pathname) ? path.root : FtpPathname.new(@adapter, '/')
|
14
|
+
|
15
|
+
if path.is_a?(ElFinderFtp::Pathname)
|
16
|
+
@path = path.path
|
17
|
+
elsif path.is_a?(ElFinderFtp::FtpPathname)
|
18
|
+
@path = path
|
19
|
+
else
|
20
|
+
@path = FtpPathname.new(@adapter, path)
|
21
|
+
end
|
22
|
+
if absolute?
|
23
|
+
if @path.cleanpath.to_s.start_with?(@root.to_s)
|
24
|
+
@path = FtpPathname.new( @adapter, @path.to_s.slice((@root.to_s.length)..-1), @path.attrs)
|
25
|
+
elsif @path.cleanpath.to_s.start_with?(@root.realpath.to_s)
|
26
|
+
@path = FtpPathname.new( @adapter, @path.to_s.slice((@root.realpath.to_s.length)..-1), @path.attrs)
|
27
|
+
else
|
28
|
+
raise SecurityError, "Absolute paths are not allowed"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
raise SecurityError, "Paths outside the root are not allowed" if outside_of_root?
|
32
|
+
|
33
|
+
end # of initialize
|
34
|
+
|
35
|
+
#
|
36
|
+
def +(other)
|
37
|
+
if other.is_a? ::ElFinderFtp::Pathname
|
38
|
+
other = other.path
|
39
|
+
end
|
40
|
+
self.class.new(@adapter, @path + other)
|
41
|
+
end # of +
|
42
|
+
|
43
|
+
#
|
44
|
+
def is_root?
|
45
|
+
@path.to_s == '.'
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
def absolute?
|
50
|
+
@path.absolute?
|
51
|
+
end # of absolute?
|
52
|
+
|
53
|
+
#
|
54
|
+
def relative?
|
55
|
+
@path.relative?
|
56
|
+
end # of relative?
|
57
|
+
|
58
|
+
#
|
59
|
+
def outside_of_root?
|
60
|
+
!cleanpath.to_s.start_with?(@root.to_s)
|
61
|
+
end # of outside_of_root?
|
62
|
+
|
63
|
+
#
|
64
|
+
def fullpath
|
65
|
+
@fullpath ||= (@path.nil? ? @root : @root + @path)
|
66
|
+
end # of fullpath
|
67
|
+
|
68
|
+
#
|
69
|
+
def cleanpath
|
70
|
+
fullpath.cleanpath
|
71
|
+
end # of cleanpath
|
72
|
+
|
73
|
+
#
|
74
|
+
def realpath
|
75
|
+
fullpath.realpath
|
76
|
+
end # of realpath
|
77
|
+
|
78
|
+
#
|
79
|
+
def basename(*args)
|
80
|
+
@path.basename(*args)
|
81
|
+
end # of basename
|
82
|
+
|
83
|
+
#
|
84
|
+
def basename_sans_extension
|
85
|
+
@path.basename(@path.extname)
|
86
|
+
end # of basename
|
87
|
+
|
88
|
+
#
|
89
|
+
def basename(*args)
|
90
|
+
@path.basename(*args)
|
91
|
+
end # of basename
|
92
|
+
|
93
|
+
#
|
94
|
+
def dirname
|
95
|
+
self.class.new(@adapter, @path.dirname)
|
96
|
+
end # of basename
|
97
|
+
|
98
|
+
#
|
99
|
+
def extname
|
100
|
+
@path.nil? ? '' : @path.extname
|
101
|
+
end # of extname
|
102
|
+
|
103
|
+
#
|
104
|
+
def to_s
|
105
|
+
cleanpath.to_s
|
106
|
+
end # of to_s
|
107
|
+
alias_method :to_str, :to_s
|
108
|
+
|
109
|
+
#
|
110
|
+
def child_directories(with_directory=true)
|
111
|
+
adapter.children(self, with_directory).select{ |child| child.directory? }.map{|e| self.class.new(@adapter, e)}
|
112
|
+
end
|
113
|
+
|
114
|
+
#
|
115
|
+
def files(with_directory=true)
|
116
|
+
adapter.children(self, with_directory).select{ |child| child.file? }.map{|e| self.class.new(@adapter, e)}
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
#
|
121
|
+
def children(with_directory=true)
|
122
|
+
adapter.children(self, with_directory).map{|e| self.class.new(@adapter, e)}
|
123
|
+
end
|
124
|
+
|
125
|
+
#
|
126
|
+
def touch(options = {})
|
127
|
+
adapter.touch(cleanpath, options)
|
128
|
+
end
|
129
|
+
|
130
|
+
#
|
131
|
+
def relative_to(other)
|
132
|
+
@path.relative_path_from(other)
|
133
|
+
end
|
134
|
+
|
135
|
+
#
|
136
|
+
def unique
|
137
|
+
return self.dup unless fullpath.file?
|
138
|
+
copy = 1
|
139
|
+
begin
|
140
|
+
new_file = self.class.new(@adapter, dirname + "#{basename_sans_extension} #{copy}#{extname}")
|
141
|
+
copy += 1
|
142
|
+
end while new_file.exist?
|
143
|
+
new_file
|
144
|
+
end # of unique
|
145
|
+
|
146
|
+
#
|
147
|
+
def duplicate
|
148
|
+
_basename = basename_sans_extension
|
149
|
+
copy = 1
|
150
|
+
if _basename.to_s =~ /^(.*) copy (\d+)$/
|
151
|
+
_basename = $1
|
152
|
+
copy = $2.to_i
|
153
|
+
end
|
154
|
+
begin
|
155
|
+
new_file = self.class.new(@adapter, dirname + "#{_basename} copy #{copy}#{extname}")
|
156
|
+
copy += 1
|
157
|
+
end while new_file.exist?
|
158
|
+
new_file
|
159
|
+
end # of duplicate
|
160
|
+
|
161
|
+
#
|
162
|
+
def rename(to)
|
163
|
+
to = self.class.new(@adapter, to)
|
164
|
+
realpath.rename(to.fullpath.to_s)
|
165
|
+
to
|
166
|
+
end # of rename
|
167
|
+
|
168
|
+
{
|
169
|
+
'directory?' => {:path => 'realpath', :rescue => true },
|
170
|
+
'exist?' => {:path => 'realpath', :rescue => true },
|
171
|
+
'file?' => {:path => 'realpath', :rescue => true },
|
172
|
+
'ftype' => {:path => 'realpath', },
|
173
|
+
'mkdir' => {:path => 'fullpath', :args => '(*args)' },
|
174
|
+
'mkdir' => {:path => 'fullpath', :args => '(*args)' },
|
175
|
+
'mtime' => {:path => 'realpath', },
|
176
|
+
'open' => {:path => 'fullpath', :args => '(*args, &block)' },
|
177
|
+
'read' => {:path => 'fullpath', :args => '(*args)' },
|
178
|
+
'write' => {:path => 'fullpath', :args => '(*args)' },
|
179
|
+
'readlink' => {:path => 'fullpath', },
|
180
|
+
'readable?' => {:path => 'realpath', :rescue => true },
|
181
|
+
'size' => {:path => 'realpath', },
|
182
|
+
'symlink?' => {:path => 'fullpath', },
|
183
|
+
'unlink' => {:path => 'realpath', },
|
184
|
+
'writable?' => {:path => 'realpath', :rescue => true },
|
185
|
+
}.each_pair do |meth, opts|
|
186
|
+
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
187
|
+
def #{meth}#{opts[:args]}
|
188
|
+
#{opts[:path]}.#{meth}#{opts[:args]}
|
189
|
+
#{"rescue Errno::ENOENT\nfalse" if opts[:rescue]}
|
190
|
+
end
|
191
|
+
METHOD
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
end # of class Pathname
|
196
|
+
|
197
|
+
end # of module ElFinderFtp
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: el_finder_ftp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris Micacchi
|
9
|
+
- Philip Hallstrom
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-08-26 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: image_size
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 1.0.0
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: net-ftp-list
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 3.2.5
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 3.2.5
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: browser
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.1.6
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.1.6
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: yard
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ~>
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 0.8.1
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 0.8.1
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: redcarpet
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ~>
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 2.1.1
|
87
|
+
type: :development
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 2.1.1
|
95
|
+
description: Ruby library to provide server side functionality for elFinder. elFinder
|
96
|
+
is an open-source file manager for web, written in JavaScript using jQuery UI.
|
97
|
+
email:
|
98
|
+
- cmicacchi@solvco.com
|
99
|
+
- philip@pjkh.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .autotest
|
105
|
+
- .gitignore
|
106
|
+
- .yardopts
|
107
|
+
- Gemfile
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- TODO
|
111
|
+
- el_finder_ftp.gemspec
|
112
|
+
- lib/el_finder_ftp.rb
|
113
|
+
- lib/el_finder_ftp/action.rb
|
114
|
+
- lib/el_finder_ftp/base64.rb
|
115
|
+
- lib/el_finder_ftp/connector.rb
|
116
|
+
- lib/el_finder_ftp/ftp_adapter.rb
|
117
|
+
- lib/el_finder_ftp/ftp_authentication_error.rb
|
118
|
+
- lib/el_finder_ftp/ftp_pathname.rb
|
119
|
+
- lib/el_finder_ftp/image.rb
|
120
|
+
- lib/el_finder_ftp/mime_type.rb
|
121
|
+
- lib/el_finder_ftp/pathname.rb
|
122
|
+
- lib/el_finder_ftp/railties.rb
|
123
|
+
- lib/el_finder_ftp/version.rb
|
124
|
+
homepage: https://github.com/Nivio/el_finder_ftp
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ! '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project: el_finder_ftp
|
145
|
+
rubygems_version: 1.8.25
|
146
|
+
signing_key:
|
147
|
+
specification_version: 3
|
148
|
+
summary: elFinder server side connector for Ruby, with an FTP backend.
|
149
|
+
test_files: []
|
150
|
+
has_rdoc:
|