Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 通过CGI运行服务器端Bash脚本_Linux_Apache_Bash_Cgi - Fatal编程技术网

Linux 通过CGI运行服务器端Bash脚本

Linux 通过CGI运行服务器端Bash脚本,linux,apache,bash,cgi,Linux,Apache,Bash,Cgi,所需信息: 我正在使用来自yum-repo的带有httpd的家庭PC网络服务器Fedora 20运行此功能。 我从中获取了.cgi文件的基本版本,并一直试图根据我的需要对其进行修改 我的问题-我可以很容易地让cgi脚本运行uname、lspci、ls,以及/usr/bin文件夹中任何只显示文本的脚本。 但是,我不能运行一个实际执行某些操作的脚本。。例如,我无法让cgi运行rhythmbox客户端-下一步在rhythmbox Media Player上向前跳过一首歌曲 我的意图是:我为我的朋友ve

所需信息: 我正在使用来自yum-repo的带有httpd的家庭PC网络服务器Fedora 20运行此功能。 我从中获取了.cgi文件的基本版本,并一直试图根据我的需要对其进行修改

我的问题-我可以很容易地让cgi脚本运行uname、lspci、ls,以及/usr/bin文件夹中任何只显示文本的脚本。 但是,我不能运行一个实际执行某些操作的脚本。。例如,我无法让cgi运行rhythmbox客户端-下一步在rhythmbox Media Player上向前跳过一首歌曲

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

我无法使用的功能包括: 下一首歌曲节奏盒客户端-下一个 上一首歌曲节奏盒客户端-上一首 将歌曲添加到队列节奏框clinet-队列名称 清除歌曲队列盒客户端-清除队列 显示当前播放的歌曲节奏盒客户端-打印播放 在计算机ls/home/user/Music | grep.mp3上显示歌曲列表

尽管我尽了最大的努力,我还是无法让这些东西发挥作用。我也试过用女妖代替节奏盒,但也有同样的问题

脚本中执行命令的部分如下所示: 回响 回显Elite Music机器人控制面板 路径=/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
对于打印播放,我尝试过这样做:

command)
 /bin/RunDBus.sh /bin/command
;;
我还尝试创建了一个脚本:

我将该rhynext命名为chmod+x,并移动到/usr/bin,当在终端中运行时,它工作,当告诉cgi执行/usr/bin/rhynext时,它什么也不做

请帮忙

我很聪明,可以对代码进行反向工程,如果你能简单地给我一段代码/一个代码示例,我很有可能将其转换为我的用途。提前谢谢

编辑:以apache用户身份运行Banshee的“下一步”脚本时


问题源于rhythmbox客户端希望连接到当前用户的dbus会话以收集rhythmbox信息/发出命令。感谢Etan Reisner指出这一点

在网上进行了一点挖掘之后,我找到了解决办法。创建2个文件,一个用于在登录时将当前用户的dbus会话地址保存到临时文件中,另一个用于调用dbus地址并通过它路由CGI命令

文件1:保留在所需文件夹中,添加到开始项,使可执行文件chmod+x name Get.DBus.sh

文件2:Make executable,移动到/usr/bin,Make executable chmod+x name Run.DBus.sh

将CGI中所需命令的执行命令更改为

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


感谢大家的帮助,尽管这是一个DBus问题XD

您是否尝试将stderr重定向到一个文件以查看是否出现任何错误消息?/bin/rhythmbox客户端可能希望连接到当前用户的rhythmbox DBus接口,此cgi将无法做到这一点。您可能需要手动公开正确的dbus会话。在测试它时,以apache用户的身份运行脚本,例如sudo-u www-data./yourscript.Etan-我该怎么做,因为我非常确定您的说法是正确的,因为当我通过ssh登录时,我必须在运行此类命令之前运行dbus脚本。另一个家伙-我做了,我从中得到了一大堆错误。。更新了原始问题以显示errornewdevelopment-如果我将apache用户更改为我的用户名和用户组,那么ls命令会起作用,我知道这是不可接受的,但我想看看如果我这样做会发生什么,所以可能对其中一些人来说也是权限问题?如何允许apache用户查看我的ls音乐文件夹?还有-是否有方法使ls命令列表文件也位于所选目录的子目录中?
playing=`rhythmbox-client --print-playing`
echo "$playing" 
#!/bin/bash
echo "This command worked!"
rhythmbox-client --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 
#!/bin/bash
set | grep DBUS_SESSION_BUS_ADDRESS > ~/.DBUS_temp
#!/bin/bash
source /home/USER/.DBUS_temp
export DBUS_SESSION_BUS_ADDRESS
$*
command)
  /bin/command
;;
command)
 /bin/RunDBus.sh /bin/command
;;