Send ssh command via php with submit button

1

My problem is the following one I have a form which it sends by means of the ssh2 command of php5, the restart or restart to a mikrotik by ssh, what I want is that this button is only allowed to click once every 10 seconds and that when I think it's like I'm loading the page again, but it's not working for me

this is the code

of the index.php

                   Restart the internet

<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">

<script src="js/jquery-1.10.1.min.js" type="text/javascript"></script>

<script type="text/javascript">
    $(document).ready(function() {
        $('#reiniciar1').click(function(e) {
            e.preventDefault();
            var el = $(this);
            el.prop('disabled', true);
            setTimeout(function(){el.prop('disabled', false); }, 3000);

        });
    });
</script>


<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        setTimeout(function() {
        $(".content").fadeOut(1500);
        },3000);
    });
</script>

<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
    $(document).ready(function(){

    $("input[type=submit]").click(function() {
        var accion = $(this).attr('dir');
        $('form').attr('action', accion);
        $('form').submit();
    });

    });
</script>

</head>
<body>
<?php if( isset( $_GET['msg'] ) && $_GET['msg'] == 1 ): ?>
    <div class="alert alert-success content">
        <center><img src='img/smile.gif' border='0' align='absmiddle'>
        El Servicio a sido $ACTION espere 1 min antes de volverlo a     $ACTION.
        </center>
    </div>

<?php endif; ?>

<div class="text-center" style="position: fixed; width: 100%;top: 7%;">
<form method="post" action="">

    <input type="submit" class="btn btn-warning" name="Reiniciar" value="Reiniciar" dir="release.php" id="reiniciar1" href="#" />

</form>
</div>
<div class="text-center" style="position: fixed; width: 100%;top: 27%;">
<form method="post" action="">
    <input type="submit" class="btn btn-warning" name="boton_1" value="Boton 1" dir="release.php" id="reiniciar1" href="#" />
    <input type="submit" class="btn btn-warning" name="boton_2" value="Boton 2" dir="release.php" id="reiniciar1" href="#" />

</form>
</div>

</body>
</html>

This is the one in the release.php

include_once 'php/Components_Ssh.php';
include_once 'php/config.php';

$fecha = new DateTime();

$fp = fopen('php/log.txt', 'a');
fputs($fp, $_SERVER['REMOTE_ADDR'] . ' - ' . $fecha->format('d/m/Y H:i:s') . ' - reiniciar ' . '');
fclose($fp);

$ssh = new Components_Ssh($conf['host'], $conf['user'], $conf['pass'], $conf['puerto']);

$ssh->cmd("ip dhcp-client release 10");

$ssh->disconnect();

header("Location: /test/index.php?msg=1");
die();
    
asked by Pedro Rafael Santiesteban 02.06.2017 в 06:08
source

1 answer

2

In this case I think your problem is that you are refreshing the page. Then the counter "reboots" every time the page refreshes.

The best thing you can do is add a ajax so that the page does not recharge and therefore the counter does not start from scratch.

Remember also the answer (headers) in PHP. I give you an example of ajax:

$('#reiniciar1').click(function(e) {
    e.preventDefault();
    var el = $(this);
    el.prop('disabled', true);
    setTimeout(function(){el.prop('disabled', false); }, 3000);
    $.ajax({
        type:  'GET',
        url:   'release.php'
    }).done(function() {
        alert('todo ha salido bien')
    }).fail(function() {
        alert('algo ha fallado')
    });
});
    
answered by 02.06.2017 в 09:09