サーバー上でプログラムを実行する方法はありますか? 例: Firefox、Gimp など
私のコンセプトは、自分の電話でローカルの LAMP サーバーにログインし、テキスト ボックス (例: /usr/bin/firefox) にコマンドを入力し、post メソッドを使用してコマンド文字列を別のサーバーに送信するボタンを押すことです。サーバーでプログラムを起動する PHP スクリプト。これは、移動中に「firefox http://www.blahblah.net」を起動し、firefox を開いた状態でコンピュータに戻る場合に便利です。はい、セキュリティの問題は認識していますが、これは概念実証にすぎません。
exec() および system() コマンドを試しましたが、うまくいかないようです.... 何か間違っていますか?
#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'
disable :protection # not needed on something this simple
set :port, 11111 # think 1APPX
get '/' do
# this handles both apps (via ?app=...) and files (via ?file=...)
if params[:app] then
# as a side effect, this also happens to actually run the app, which is
# pretty much what we wanted in the first place
@fn = params[:app][1..-2];
`/usr/bin/env #{@fn}`
elsif params[:file] then
# bugfix, remove quotes...
@fn = params[:file][1..-2];
# xdg-open anyone?
puts "DEBUG /usr/bin/env xdg-open #{@fn}";
`"/usr/bin/env xdg-open #{@fn}"`
else
# nothing...
404
end
end
not_found do
status 404
"Application #{@fn} not found. Usage: /?app=\"[appname]\" or /?file=\"[filename]\""
end