Forum: Ruby on Rails Directory Listing outside of app structure

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
21c26386eabccd11f40c029b0ebf94e7?d=identicon&s=25 Brian Ablaza (zakifataya)
on 2006-03-29 16:21
I need to show a directory listing of a folder outside of the Rails app
structure. Moving the folder is not an option. In fact, changing
anything (including modes) is not possible for the folder.

I have working directory listing code in Ruby, but if I call chdir in
Rails to set the working directory to a folder outside the app tree,
nothing is returned to the browser. It's fine if I chdir to a folder
inside the public folder.

To get this to work in Ruby, I needed to change the UID for the Ruby
file. I don't think this approach will work in Rails.

I understand the security issues here, but would like to somehow say
that it's safe to chdir to a particular directory. I can't find any
discussion of Rails safety/security similar to the $SAFE information in
the Pickaxe book.
807e34b31d5463a9ac05d41458a9e537?d=identicon&s=25 Al Evans (al-evans)
on 2006-03-29 17:08
Brian Ablaza wrote:
> I need to show a directory listing of a folder outside of the Rails app
> structure

s = `ls /path/to/file`

seems to work for me, unless there's something I'm not understanding
about your requirements. For example,

  def foop
    render :text => `ls -l /opt/local/share`
  end

produces the expected output for http://<server>/<controller>/foop

--Al Evans
21c26386eabccd11f40c029b0ebf94e7?d=identicon&s=25 Brian Ablaza (zakifataya)
on 2006-03-30 01:26
Al Evans wrote:
>
> s = `ls /path/to/file`
>
> seems to work for me, unless there's something I'm not understanding
> about your requirements. For example,
>
>   def foop
>     render :text => `ls -l /opt/local/share`
>   end
>
> produces the expected output for http://<server>/<controller>/foop
>
> --Al Evans

Thanks for the response, Al. I should have been clearer. I'm working on
a directory indexer, so I need a listing equivalent to what you'd get
with <pre> Dir["*"].sort_by {|f| test(?M, f)}</pre>. In my Ruby version,
I just chdir to set the working directory.

Ideas?
807e34b31d5463a9ac05d41458a9e537?d=identicon&s=25 Al Evans (al-evans)
on 2006-03-30 15:16
Brian Ablaza wrote:

> Thanks for the response, Al. I should have been clearer. I'm working on
> a directory indexer, so I need a listing equivalent to what you'd get
> with <pre> Dir["*"].sort_by {|f| test(?M, f)}</pre>. In my Ruby version,
> I just chdir to set the working directory.

Maybe I'm still missing something, but except for the formatting,

  def foop
    foo = Dir['/opt/local/share/*'].sort_by {|f| test(?M, f)}
    render :text => foo
  end

seems to work for me.

--Al Evans
21c26386eabccd11f40c029b0ebf94e7?d=identicon&s=25 Brian Ablaza (zakifataya)
on 2006-04-09 23:21
> Maybe I'm still missing something, but except for the formatting,
>
>   def foop
>     foo = Dir['/opt/local/share/*'].sort_by {|f| test(?M, f)}
>     render :text => foo
>   end
>
> seems to work for me.
>
> --Al Evans

Yeah, it works. I didn't realize that you could use a string as a file
ref that way. Thanks, Al.
This topic is locked and can not be replied to.