Jump to content

stealthrt

New Members
  • Posts

    6
  • Joined

  • Last visited

stealthrt's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hey all I am new at doing anything regarding PHP Shell_exec commands. I have some UCI code that allows me to add a rule to my firewall. This works just fine in SSH but when I try running the same thing in the PHP page it does not seem to do anything and without any error lettings me know whats going on.... My code: <?php try { $cmd = "uci add firewall rule ". "uci set firewall.@rule[-1].name='my iphone' ". "uci set firewall.@rule[-1].src='lan' ". "uci set firewall.@rule[-1].dest='wan' ". "uci set firewall.@rule[-1].src_mac='XX:XX:XX:XX:XX:XX' ". "uci set firewall.@rule[-1].proto='all' ". "uci set firewall.@rule[-1].target='REJECT' ". "uci set firewall.@rule[-1].enabled='1' ". "commit firewall ". "service firewall restart "; echo 'command: ', $cmd; $output = shell_exec($cmd); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } echo "<pre>output: $output</pre>"; ?> I've even tried adding 2>&1 at the end: <?php try { $cmd = "uci add firewall rule 2>&1". "uci set firewall.@rule[-1].name='my iphone' 2>&1". "uci set firewall.@rule[-1].src='lan' 2>&1". [more code here] And I've tried using only 1 uci for the whole command: <?php try { $cmd = "uci add firewall rule 2>&1". "set firewall.@rule[-1].name='my iphone' 2>&1". "set firewall.@rule[-1].src='lan' 2>&1". [more code here] And I've tried using the same as above but without the 2>&1 <?php try { $cmd = "uci add firewall rule ". "set firewall.@rule[-1].name='my iphone' ". "set firewall.@rule[-1].src='lan' ". [more code here] And lastly I've tried it with the 2>&1 just at the end of the command and with only 1 uci: <?php try { $cmd = "uci add firewall rule ". "set firewall.@rule[-1].name='my iphone' ". "set firewall.@rule[-1].src='lan' ". [more code here] "service firewall restart 2>&1"; [more code here] and with each having uci: <?php try { $cmd = "uci add firewall rule ". "uci set firewall.@rule[-1].name='my iphone' ". "uci set firewall.@rule[-1].src='lan' ". [more code here] "service firewall restart 2>&1"; [more code here] It first code block above outputs this on the page: But like I said, it doesn't give any errors. I tested a simple ls command with it and it works as expected: So, what am I missing?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.