el_finder 1.0.3 → 1.0.4

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/README.rdoc CHANGED
@@ -9,13 +9,10 @@ open-source file manager for web, written in JavaScript using jQuery UI.
9
9
 
10
10
  == Features/Problems:
11
11
 
12
- * Does not yet support archive/extraction.
13
12
  * Does not yet support thumbnail generation.
14
13
 
15
14
  == Todo:
16
15
 
17
- * Add support for archive/extraction.
18
- * Add support for thumbnail generation.
19
16
  * Document library.
20
17
  * Document how to implement custom image size/resize methods.
21
18
 
@@ -46,7 +43,24 @@ the defaults.
46
43
  def elfinder
47
44
  h, r = ElFinder::Connector.new(
48
45
  :root => File.join(Rails.public_path, 'system', 'elfinder'),
49
- :url => '/system/elfinder'
46
+ :url => '/system/elfinder',
47
+ :perms => {
48
+ /^(Welcome|README)$/ => {:read => true, :write => false, :rm => false},
49
+ '.' => {:read => true, :write => false, :rm => false}, # '.' is the proper way to specify the home/root directory.
50
+ /^test$/ => {:read => true, :write => true, :rm => false},
51
+ 'logo.png' => {:read => true},
52
+ /\.png$/ => {:read => false} # This will cause 'logo.png' to be unreadable.
53
+ # Permissions err on the safe side. Once false, always false.
54
+ },
55
+ :extractors => {
56
+ 'application/zip' => ['unzip', '-qq', '-o'], # Each argument will be shellescaped (also true for archivers)
57
+ 'application/x-gzip' => ['tar', '-xzf'],
58
+ },
59
+ :archivers => {
60
+ 'application/zip' => ['.zip', 'zip', '-qr9'], # Note first argument is archive extension
61
+ 'application/x-gzip' => ['.tgz', 'tar', '-czf'],
62
+ },
63
+
50
64
  ).run(params)
51
65
  headers.merge!(h)
52
66
  render (r.empty? ? {:nothing => true} : {:text => r.to_json}), :layout => false
@@ -13,8 +13,8 @@ module ElFinder
13
13
  :disabled_commands => [],
14
14
  :show_dot_files => true,
15
15
  :upload_max_size => '50M',
16
- :archivers => [],
17
- :extractors => [],
16
+ :archivers => {},
17
+ :extractors => {},
18
18
  :home => 'Home',
19
19
  :default_perms => {:read => true, :write => true, :rm => true},
20
20
  :perms => []
@@ -114,8 +114,8 @@ module ElFinder
114
114
  @response[:params] = {
115
115
  :dotFiles => @options[:show_dot_files],
116
116
  :uplMaxSize => @options[:upload_max_size],
117
- :archives => @options[:archivers],
118
- :extract => @options[:extractors],
117
+ :archives => @options[:archivers].keys,
118
+ :extract => @options[:extractors].keys,
119
119
  :url => @options[:url]
120
120
  }
121
121
  end
@@ -303,12 +303,33 @@ module ElFinder
303
303
 
304
304
  #
305
305
  def _extract
306
- command_not_implemented
306
+ @response[:error] = 'Invalid Parameters' and return unless @target.file? && @current.directory?
307
+ @response[:error] = 'Access Denied' and return unless perms_for(@target)[:read] == true && perms_for(@current)[:write] == true
308
+ @response[:error] = 'No extractor available for this file type' and return if (extractor = @options[:extractors][mime_handler.for(@target)]).nil?
309
+ cmd = ['cd', @current.shellescape, '&&', extractor.map(&:shellescape), @target.basename.shellescape].flatten.join(' ')
310
+ if system(cmd)
311
+ @params[:tree] = true
312
+ _open(@current)
313
+ else
314
+ @response[:error] = 'Unable to extract files from archive'
315
+ end
307
316
  end # of extract
308
317
 
309
318
  #
310
319
  def _archive
311
- command_not_implemented
320
+ @response[:error] = 'Invalid Parameters' and return unless !@targets.nil? && @targets.all?{|e| e.exist?} && @current.directory?
321
+ @response[:error] = 'Access Denied' and return unless !@targets.nil? && @targets.all?{|e| perms_for(e)[:read]} && perms_for(@current)[:write] == true
322
+ @response[:error] = 'No archiver available for this file type' and return if (archiver = @options[:archivers][@params[:type]]).nil?
323
+ extension = archiver.shift
324
+ basename = @params[:name] || @targets.first.basename_without_extension
325
+ archive = ElFinder::Pathname.new_with_root(@root, "#{basename}#{extension}").unique
326
+ cmd = ['cd', @current.shellescape, '&&', archiver.map(&:shellescape), archive.shellescape, @targets.map{|t| t.basename.shellescape}].flatten.join(' ')
327
+ if system(cmd)
328
+ @response[:select] = [to_hash(archive)]
329
+ _open(@current)
330
+ else
331
+ @response[:error] = 'Unable to create archive'
332
+ end
312
333
  end # of archive
313
334
 
314
335
  #
@@ -15,19 +15,29 @@ module ElFinder
15
15
  self.class.new(super(*args).to_s)
16
16
  end
17
17
 
18
+ #
19
+ def shellescape
20
+ to_s.shellescape
21
+ end
22
+
18
23
  #
19
24
  def rename(to)
20
25
  super(to)
21
26
  rescue Errno::EXDEV
22
27
  FileUtils.move(self.to_s, to.to_s)
23
28
  @path = to.to_s
24
- end
29
+ end # of rename
25
30
 
26
31
  #
27
32
  def self.new_with_root(root, path = '')
28
33
  new(superclass.new(File.join(root, path)).cleanpath.to_s)
29
34
  end # of self.new_with_root
30
35
 
36
+ #
37
+ def basename_without_extension
38
+ basename(extname)
39
+ end
40
+
31
41
  #
32
42
  def duplicate
33
43
  _dirname = dirname
@@ -41,11 +51,27 @@ module ElFinder
41
51
 
42
52
  begin
43
53
  copy += 1
44
- duplicate = self.class.superclass.new(_dirname + "#{_basename} copy #{copy}#{_extname}")
45
- end while duplicate.exist?
46
- duplicate
54
+ new_file = self.class.superclass.new(_dirname + "#{_basename} copy #{copy}#{_extname}")
55
+ end while new_file.exist?
56
+ new_file
47
57
  end # of duplicate
48
58
 
59
+ #
60
+ def unique
61
+ return self.dup unless self.file?
62
+
63
+ _dirname = dirname
64
+ _extname = extname
65
+ _basename = basename(_extname)
66
+ copy = 0
67
+
68
+ begin
69
+ copy += 1
70
+ new_file = self.class.superclass.new(_dirname + "#{_basename} #{copy}#{_extname}")
71
+ end while new_file.exist?
72
+ new_file
73
+ end # of unique
74
+
49
75
  #
50
76
  def relative_to(pathname)
51
77
  self == pathname ? '' : relative_path_from(pathname).to_s
@@ -1,3 +1,3 @@
1
1
  module ElFinder
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
@@ -1,23 +1,23 @@
1
1
  require "test/unit"
2
2
  require "el_finder"
3
3
 
4
- class TestElFinderImageSize < Test::Unit::TestCase
4
+ class TestImageSize < Test::Unit::TestCase
5
5
 
6
6
  def test_that_method_exists
7
7
  assert_respond_to ElFinder::ImageSize, :for
8
8
  end
9
9
 
10
10
  def test_that_logos_are_correct_size
11
- assert_equal '70x66', ElFinder::ImageSize.for( File.join(File.dirname(__FILE__), 'files/elfinder.png') )
12
- assert_equal '100x100', ElFinder::ImageSize.for( File.join(File.dirname(__FILE__), 'files/pjkh.png') )
11
+ assert_equal '70x66', ElFinder::ImageSize.for( File.join(File.dirname(__FILE__), '../files/elfinder.png') )
12
+ assert_equal '100x100', ElFinder::ImageSize.for( File.join(File.dirname(__FILE__), '../files/pjkh.png') )
13
13
  end
14
14
 
15
15
  def test_that_nil_is_returned_on_non_images
16
- assert_equal nil, ElFinder::ImageSize.for( File.join(File.dirname(__FILE__), 'files/README.txt') )
16
+ assert_equal nil, ElFinder::ImageSize.for( File.join(File.dirname(__FILE__), '../files/README.txt') )
17
17
  end
18
18
 
19
19
  def test_that_nil_is_returned_on_nonexistint_files
20
- assert_equal nil, ElFinder::ImageSize.for( File.join(File.dirname(__FILE__), 'files/NON_EXIST') )
20
+ assert_equal nil, ElFinder::ImageSize.for( File.join(File.dirname(__FILE__), '../files/NON_EXIST') )
21
21
  end
22
22
 
23
23
  end
@@ -1,7 +1,7 @@
1
1
  require "test/unit"
2
2
  require "el_finder"
3
3
 
4
- class TestElFinderMimeType < Test::Unit::TestCase
4
+ class TestMimeType < Test::Unit::TestCase
5
5
 
6
6
  def test_that_method_exists
7
7
  assert_respond_to ElFinder::MimeType, :for
@@ -2,12 +2,12 @@ require "test/unit"
2
2
  require "el_finder"
3
3
  require "fileutils"
4
4
 
5
- class TestElFinderPathname < Test::Unit::TestCase
5
+ class TestPathname < Test::Unit::TestCase
6
6
 
7
7
  def setup
8
8
  @vroot = '/tmp/elfinder'
9
9
  FileUtils.mkdir_p(@vroot)
10
- FileUtils.cp_r "#{File.dirname(__FILE__)}/files/.", @vroot
10
+ FileUtils.cp_r "#{File.dirname(__FILE__)}/../files/.", @vroot
11
11
  end
12
12
 
13
13
  def teardown
@@ -83,14 +83,38 @@ class TestElFinderPathname < Test::Unit::TestCase
83
83
 
84
84
  ################################################################################
85
85
 
86
+ def test_shellescape
87
+ assert_respond_to ElFinder::Pathname.new_with_root(@vroot, 'foo.txt'), :shellescape
88
+ end
89
+
90
+ def test_basename_without_extension
91
+ file = ElFinder::Pathname.new_with_root(@vroot, 'foo.txt')
92
+ assert_respond_to file, :basename_without_extension
93
+ assert_equal 'foo', file.basename_without_extension.to_s
94
+ end
95
+
96
+ def test_unique_on_create
97
+ file = ElFinder::Pathname.new_with_root(@vroot, 'foo.txt')
98
+ assert_equal 'foo.txt', file.unique.basename.to_s
99
+ end
100
+
101
+ def test_unique_conflict
102
+ file = ElFinder::Pathname.new_with_root(@vroot, 'pjkh.png')
103
+ assert_equal 'pjkh 1.png', file.unique.basename.to_s
104
+ end
105
+
106
+ def test_unique_conflict_twice
107
+ FileUtils.touch ElFinder::Pathname.new_with_root(@vroot, 'pjkh 1.png')
108
+ file = ElFinder::Pathname.new_with_root(@vroot, 'pjkh.png')
109
+ assert_equal 'pjkh 2.png', file.unique.basename.to_s
110
+ end
111
+
86
112
  def test_relative_to_method
87
113
  assert_equal "", ElFinder::Pathname.new_with_root(@vroot).relative_to(::Pathname.new(@vroot)).to_s
88
114
  assert_equal "foo.txt", ElFinder::Pathname.new_with_root(@vroot, 'foo.txt').relative_to(::Pathname.new(@vroot)).to_s
89
115
  assert_equal "foo/bar.txt", ElFinder::Pathname.new_with_root(@vroot, 'foo/bar.txt').relative_to(::Pathname.new(@vroot)).to_s
90
116
  end
91
117
 
92
- ################################################################################
93
-
94
118
  def test_class_type
95
119
  assert_kind_of ElFinder::Pathname, ElFinder::Pathname.new_with_root(@vroot, 'foo')
96
120
  assert_kind_of ElFinder::Pathname, ElFinder::Pathname.new_with_root(@vroot, 'foo') + 'bar'
@@ -0,0 +1,22 @@
1
+ require 'test/unit'
2
+ require 'el_finder'
3
+ require 'pp'
4
+
5
+ module ElFinderTestCase
6
+
7
+ def setup
8
+ @vroot = '/tmp/elfinder'
9
+ FileUtils.mkdir_p(@vroot)
10
+ FileUtils.cp_r "#{File.dirname(__FILE__)}/files/.", @vroot
11
+ @elfinder = ElFinder::Connector.new({
12
+ :root => @vroot,
13
+ :url => '/elfinder',
14
+ :original_filename_method => lambda {|file| File.basename(file.path)}
15
+ })
16
+ end
17
+
18
+ def teardown
19
+ FileUtils.rm_rf(@vroot)
20
+ end
21
+
22
+ end
Binary file