I have an iframe to send the commands from control panel when the user clicks the button. Using the code below, nothing happens with the button when the user clicks as there is a syntax error in the code.

$items['googledotcom'] = array
        (
            'description'=>'DNS resolution test',
            '1'=>1,
            '0'=>0,
            'fixCommand'=>'EXC service network restart; echo "nameserver 8.8.8.8" >> /etc/resolv.conf; sleep 10; health check',
        );

The above code doesn't work, because of this line: echo "nameserver 8.8.8.8" >> /etc/resolv.conf;

But the code will work when I remove the above line. But I need to add the above line as well.

Any suggestions for the syntax?

Thanks!

UPDATE

Format of command: enter image description here

doCommand Javascript:

<script type='text/javascript'>

function doCommand(command)
{
    var r=confirm("Are you sure you want to \"" + command + "\"");
    if (!r)
    {
        return;
    }

    $.post('/device/commands-frame/', { id : '<?=$this->site->id;?>', act : command, command : command }, function(data)
    {
        alert('Command has been sent');
    });
}
</script>
有帮助吗?

解决方案

Try this:

<?php
$items['googledotcom'] = array
    (
        'description'=>'DNS resolution test',
        '1'=>1,
        '0'=>0,
        'fixCommand'=>"EXC service network restart; echo 'nameserver 8.8.8.8' >> /etc/resolv.conf; sleep 10; curo health check"
    );
    var_dump($items);
?>

This shows:

array(1) { ["googledotcom"]=> array(4) { ["description"]=> string(19) "DNS resolution test" [1]=> int(1) [0]=> int(0) ["fixCommand"]=> string(103) "EXC service network restart; echo 'nameserver 8.8.8.8' >> /etc/resolv.conf; sleep 10; curo health check" } }

Now i test the value with the following fiddle and it's working: http://jsfiddle.net/EjXmp/

That fiddle contains the following code:

$(document).ready(function(){

$("#clickme").click(function(){
doCommand("EXC service network restart; echo 'nameserver 8.8.8.8' >> /etc/resolv.conf; sleep 10; curo health check");
});

function doCommand(command)
{
var r=confirm("Are you sure you want to \"" + command + "\"");
if (!r)
{
    return;
}

$.post('/device/commands-frame/', { id : '<?=$this->site->id;?>', act : command, command : command }, function(data)
{
    alert('Command has been sent');
});
}

});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top