运行 shell 客户端 Rails 上的 Ruby 脚本形式
Running shell script form Ruby on Rails on the Client
我想在客户端上从我的 Rails 应用程序执行 shell 脚本。
在我的例子中,当他点击 link 时,我想在客户端 PC 上打开一个 .odt
文件。
至于现在,我所能做的就是使用 e.g.
`libreoffice path_to_my_odt_file`
在我的服务器上 运行 shell 脚本。
在这种情况下,我在服务器上使用 LivreOffice 打开我的文件。
有没有办法在我的客户端上从 Rails 执行此代码?
如果我尝试 运行 我的应用程序,当我调用调用脚本的操作时,文件会在我的服务器上打开。
提前谢谢你。
如评论中所述,来自 http 服务器的客户端上的 运行 任意 shell 脚本将是一个巨大的安全漏洞。
只要您的 Rails 服务器提供下载 link 和 send_data
(e.g. dynamically_generated_odt_file
), the browser will ask if it should download the file or open it. If the user wants to avoid any extra interaction, there's the possibility to tick :
"Do this automatically for files like this from now on"
您可能必须通过添加
来指定 MIME 类型
Mime::Type.register "application/vnd.oasis.opendocument.text", :odt
至config/initializers/mime_types.rb
。
我想在客户端上从我的 Rails 应用程序执行 shell 脚本。
在我的例子中,当他点击 link 时,我想在客户端 PC 上打开一个 .odt
文件。
至于现在,我所能做的就是使用 e.g.
`libreoffice path_to_my_odt_file`
在我的服务器上 运行 shell 脚本。
在这种情况下,我在服务器上使用 LivreOffice 打开我的文件。
有没有办法在我的客户端上从 Rails 执行此代码?
如果我尝试 运行 我的应用程序,当我调用调用脚本的操作时,文件会在我的服务器上打开。
提前谢谢你。
如评论中所述,来自 http 服务器的客户端上的 运行 任意 shell 脚本将是一个巨大的安全漏洞。
只要您的 Rails 服务器提供下载 link 和 send_data
(e.g. dynamically_generated_odt_file
), the browser will ask if it should download the file or open it. If the user wants to avoid any extra interaction, there's the possibility to tick :
"Do this automatically for files like this from now on"
您可能必须通过添加
来指定 MIME 类型Mime::Type.register "application/vnd.oasis.opendocument.text", :odt
至config/initializers/mime_types.rb
。