2014-12-04 50 views
0

所需信息: 我正在使用家庭PC网络服务器运行此操作,Fedora 20使用httpd从yum回购。 我把我的.cgi文件的基本版本从:http://www.instructables.com/id/Simple-linux-commands-from-a-web-page/,一直试图根据我的需要进行修改。通过CGI运行服务器端Bash脚本

我的问题 - 我可以非常轻松地将cgi脚本与/ usr/bin文件夹中的任何脚本一起运行uname,lspci,ls以及简单显示文本。 但是,我不能运行一个实际上做了什么的脚本。例如,我无法让cgi运行“rhythmbox-client --next”来跳过Rhythmbox Media Player中的歌曲。

我的意图是:我为我的朋友ventrilo服务器运行'音乐机器人',并且我想给他们(密码保护)的方式从网络访问机器人,更改歌曲,将歌曲添加到播放队列等等。

的功能(其中没有我可以开始工作),我需要的是: 下一首乐曲(Rhythmbox的客户端---接着) 一首歌曲(Rhythmbox的客户端--previous) 将歌曲添加到队列(Rhythmbox的(rhythmbox客户端 - 打印播放) 显示计算机上的歌曲列表(ls/home/user) /音乐| grep“.mp3”)

尽我所能,我不能得到任何这些东西的工作。我也尝试使用Banshee而不是rhythmbox,具有相同的问题。

假设执行命令的脚本部分如下: echo“” echo“Elite Music Bot控制面板” PATH =“/ bin:/ usr/bin:/ usr/ucb:/ USR的/ opt/BIN” 出口$ PATH 回声 “” 回声 “”

# test if any parameters were passed 
if [ $CMD ] 
then 
    case "$CMD" in 
    BotInfo) 
    echo "<pre>" 
     /bin/BotInfo 
    echo "System Name:" `/bin/uname -n` 
     echo "</pre>" 
     ;; 

    next) 
     echo "Skipped to the next song." 
     /bin/rhythmbox-client --next 
     ;; 

    back) 
     echo "Repeating the previous song. <pre>" 
     /bin/rhythmbox-client --previous 
     echo "</pre>" 
     ;; 

playing) 
     echo "The current song playing is... <pre>" 
     rhythmbox-client --print-playing 
     echo "</pre>" 
     ;; 

queue) 
     echo "The requested song has been added to the queue. <pre>" 
     rhythembox-client --enqueue $QUEUE_SONG 
     echo "</pre>" 
     ;; 

     rating) 
      echo "The rating of the current song has been set to $RATING. <pre>" 
      /bin/rhythmbox-client --set-rating $RATING 
      echo "</pre>" 
      ;; 
ls) 
    echo "<pre>" 
    list=`ls /home/USER/Music | grep ".mp3"` 
    echo "$list" 
    echo "</pre>" 
    ;; 
    *) 
     echo "Unknown command $CMD<br>" 
     ;; 
    esac 
fi 

非常第一个是一个简单的脚本显示系统时间(日期),cpuinfo中,meminfo中,ECT和它的工作。其他人却没有。

我已经尝试运行的bash命令,

echo "$(command)" 

用于打印扮演我试着做它喜欢:

playing=`rhythmbox-client --print-playing` 
echo "$playing" 

我也尝试创建一个脚本,该脚本:

#!/bin/bash 
echo "This command worked!" 
rhythmbox-client --next 

我命名的rhynext,使用chmod + x和移动到/ usr/bin中,当它的工作原理终端中运行,告诉c当gi做/ usr/bin/rhynext它什么都不做。

请帮忙。

我非常聪明,可以反向工程代码,如果你可以简单地给我一个单独的片段/代码的例子,我将很有可能将它转换为我的用途。提前致谢。

编辑:当作为apache用户运行Banshee的'next'脚本时..

sudo -u apache /usr/bin/next 
[sudo] password for OMMITED: 
Unhandled Exception: System.UnauthorizedAccessException: Access to the path "/usr/share/httpd/.config" is denied. 
    at System.IO.Directory.CreateDirectoriesInternal (System.String path) [0x00000] in <filename unknown>:0 
    at System.IO.Directory.CreateDirectory (System.String path) [0x00000] in <filename unknown>:0 
    at System.IO.DirectoryInfo.Create() [0x00000] in <filename unknown>:0 
    at (wrapper remoting-invoke-with-check) System.IO.DirectoryInfo:Create() 
    at System.IO.Directory.CreateDirectoriesInternal (System.String path) [0x00000] in <filename unknown>:0 
    at System.IO.Directory.CreateDirectory (System.String path) [0x00000] in <filename unknown>:0 
    at Hyena.Paths.InitializePaths() [0x00000] in <filename unknown>:0 
    at Hyena.Paths.set_ApplicationName (System.String value) [0x00000] in <filename unknown>:0 
    at Banshee.ServiceStack.Application.InitializePaths() [0x00000] in <filename unknown>:0 
    at Booter.Booter.Main() [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.UnauthorizedAccessException: Access to the path "/usr/share/httpd/.config" is denied. 
    at System.IO.Directory.CreateDirectoriesInternal (System.String path) [0x00000] in <filename unknown>:0 
    at System.IO.Directory.CreateDirectory (System.String path) [0x00000] in <filename unknown>:0 
    at System.IO.DirectoryInfo.Create() [0x00000] in <filename unknown>:0 
    at (wrapper remoting-invoke-with-check) System.IO.DirectoryInfo:Create() 
    at System.IO.Directory.CreateDirectoriesInternal (System.String path) [0x00000] in <filename unknown>:0 
    at System.IO.Directory.CreateDirectory (System.String path) [0x00000] in <filename unknown>:0 
    at Hyena.Paths.InitializePaths() [0x00000] in <filename unknown>:0 
    at Hyena.Paths.set_ApplicationName (System.String value) [0x00000] in <filename unknown>:0 
    at Banshee.ServiceStack.Application.InitializePaths() [0x00000] in <filename unknown>:0 
    at Booter.Booter.Main() [0x00000] in <filename unknown>:0 
+1

你试过到stderr重定向到文件(查看是否出现任何错误消息)? – syme 2014-12-04 20:10:44

+1

'/ bin/rhythmbox-client'可能希望连接到当前用户的rhythmbox dbus接口,这个cgi将无法做到这一点。您可能需要手动公开正确的dbus会话。 – 2014-12-04 20:24:45

+0

当您测试它时,以apache用户身份运行脚本(例如'sudo -u www-data。/ yourscript')。 – 2014-12-04 20:35:07

回答

0

问题从Rhythmbox的客户端朵朵希望连接到当前用户的DBUS会议收集的Rhythmbox信息/发出命令。 (感谢Etan Reisner指出)

在小小的在线挖掘之后,我找到了解决方案。创建2个文件,一个用于在登录时将当前用户的dbus会话地址保存到临时文件中,另一个用于调用dbus地址并通过它发送CGI命令。

文件1:将所需的文件夹中,添加启动项,使运行(chmod + x)的名字 “Get.DBus.sh”

#!/bin/bash 
set | grep DBUS_SESSION_BUS_ADDRESS > ~/.DBUS_temp 

文件2:请可执行文件,移动到/ usr /箱,使运行(chmod + x)的名称为 “Run.DBus.sh”

#!/bin/bash 
source /home/USER/.DBUS_temp 
export DBUS_SESSION_BUS_ADDRESS 
$* 

变化在CGI从所需命令的执行命令..

command) 
    /bin/command 
;; 

TO

command) 
/bin/RunDBus.sh /bin/command 
;; 

问题解决了。所有命令按预期工作。

感谢大家的帮助,永远不会有,虽然这是一个问题的DBus XD

相关问题