I created a simple PHP site we would like to use to disable/enable ports on a cisco switch. I am passing over two arguments (port and action) to a bash script via the php function exec(). For debugging I set those arguments at the end inside the bash script.
The important part of the php function I am calling looks like this:
function PortAction($port, $action){
echo "<hr /> Port:".$port."<br />Action:".$action;
chdir('/usr/local/icinga-1.7.0/videowand/');
echo exec('sh /usr/local/icinga-1.7.0/videowand/action2.sh 2>&1',$output, $return);
echo "Return / Output: ".$return;
print_r($output);
}
The bash script "action2.sh":
#!/bin/bash
/usr/libexec/rancid/clogin -c "conf t; int Fa0/1; shutdown" 192.168.6.6
If i execute the bash script manually (or even the directly the clogin command) as apache user, it all works as expected, the port gets disabled. But as soon as I call it over the PHP function, I get the output:
Array ( [0] => no such variable [1] => (read trace on "env(HOME)") [2] => invoked from within [3] => "set password_file $env(HOME)/.cloginrc" [4] => (file "/usr/libexec/rancid/clogin" line 66)
And nothing gets done. Which indicates some problem with the password entry (as far as I can see). Permissions on this file(s) are correct, I guess they have to otherwise it wouldn't work directly inside the shell. Even tried to change the .cloginrc path using the -f switch, no success. PHP Safe-mode: Off Display errors: On
The script takes a while because a telnet connection needs to be opened. This is why I put this into a separate bash script.