PHP|Débutant :: Forums

Advertisement

Besoin d'aide ? N'hésitez pas, mais respectez les règles

Vous n'êtes pas identifié(e).

#1 Re : Forum Général PHP » Commande ssh et php » 31-07-2013 12:37:07

utiliser pour le ssh2

<?php
$connection = ssh2_connect('exemple.com', 21);
ssh2_auth_password($connection, 'user', 'motdepasse);
$auth = ssh2_auth_password($shell, $user, $password);
?>
<?php

    $bin = $_POST['bin'];
        $path = $_POST['path'];
        $alias = $_POST['alias'];
        $options = $_POST ['options'];
        $screen = $_POST['screen'];
        $start = "screen -AmdS " . $screen;

if (isset($_POST['start'])) {
   //$start = "cd ". $path . " && screen -AmdS " . $alias . " ./" . $bin . " " . $options;
   echo ssh2_exec($connection ,$start);
}


?>



Par contre maintenant j'ai cette erreur WTF quoi ..



[Wed Jul 31 10:01:17 2013] [warn] [client 93.95.60.226] mod_fcgid: stderr: PHP Notice: Undefined index: bin in /var/www/clients/client3/web5/web/dev/panel/test.php on line 29
[Wed Jul 31 10:01:17 2013] [warn] [client 93.95.60.226] mod_fcgid: stderr: PHP Notice: Undefined index: path in /var/www/clients/client3/web5/web/dev/panel/test.php on line 30
[Wed Jul 31 10:01:17 2013] [warn] [client 93.95.60.226] mod_fcgid: stderr: PHP Notice: Undefined index: alias in /var/www/clients/client3/web5/web/dev/panel/test.php on line 31
[Wed Jul 31 10:01:17 2013] [warn] [client 93.95.60.226] mod_fcgid: stderr: PHP Notice: Undefined index: options in /var/www/clients/client3/web5/web/dev/panel/test.php on line 32
[Wed Jul 31 10:01:17 2013] [warn] [client 93.95.60.226] mod_fcgid: stderr: PHP Notice: Undefined index: screen in /var/www/clients/client3/web5/web/dev/panel/test.php on line 33
[Wed Jul 31 10:01:20 2013] [warn] [client 93.95.60.226] mod_fcgid: stderr: PHP Notice: Undefined variable: shell in /var/www/clients/client3/web5/web/dev/panel/test.php on line 4, referer:
[Wed Jul 31 10:01:20 2013] [warn] [client 93.95.60.226] mod_fcgid: stderr: PHP Notice: Undefined variable: user in /var/www/clients/client3/web5/web/dev/panel/test.php on line 4, referer:
[Wed Jul 31 10:01:20 2013] [warn] [client 93.95.60.226] mod_fcgid: stderr: PHP Notice: Undefined variable: password in /var/www/clients/client3/web5/web/dev/panel/test.php on line 4, referer:
[Wed Jul 31 10:01:20 2013] [warn] [client 93.95.60.226] mod_fcgid: stderr: PHP Warning: ssh2_auth_password() expects parameter 1 to be resource, null given in /var/www/clients/client3/web5/web/dev/panel/test.php on line 4,



et sur ma page test.php j'ai Resource id #2 qui apparaît ..


797798error.png

#2 Forum Général PHP » Commande ssh et php » 31-07-2013 12:37:07

WENKz
Réponses : 1

Bonjour je souhaite lancer un serveur de jeux via une page php que j'ai faite mais j'ai un peu de difficulté avec les variable php pour les inclure dans la commande ssh pouvez vous m'aider ?
voici ma page test

<?php
function ssh($command){
    $host = "*******";
    $port = "*******";
    $login = "*****";
    $mdp = "*****";
    if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
    if(!($con = ssh2_connect($host, $port))){
        echo "échec connexion\n";
    } else {
        if(!ssh2_auth_password($con, $login, $mdp)) {
            echo "échec authentification\n";
        } else {
            if (!($stream = ssh2_exec($con, $command ))) {
                echo "échec de l'exécution de la commande\n";
            } else {
                stream_set_blocking($stream, true);
                $data = "";
                while ($buf = fread($stream,4096)) {
                    $data .= $buf;
                }
                fclose($stream);
                return $data;
            }
        }
    }
}
?>
 
<h3>Ajouter un serveur</h3>
<div class="text">Completez le formulaire suivant pour ajouter un serveur :</div>
<form method="post">
        <fieldset>
                <p><label>Alias :</label><input type="text" class="text-medium" name="alias" /></p>
                <p><label>Type :</label><select name="type">
                <option value="1">Serveur de jeu</option>
                <option value="2">Serveur vocal</option>
                </select></p>
        </fieldset>
        <fieldset>
                <p><label>Exécutable du serveur :</label><input type="text" class="text-medium" name="bin" /></p>
                <p><label>Répertoire de l'éxécutable :</label><input type="text" class="text-medium" name="path" /></p>
                <p><label>Options de lancement :</label><textarea name="options"></textarea></p>
                <p><label>Nom du screen :</label><input type="text" class="text-medium" name="screen" /></p>
        </fieldset>
                        <button type="submit" name="start" class="button"><img src="icones/tick.png"> Ajouter ce serveur</button> <button type="reset" class="button negative"><img src="icones/cross.png"> Reset des champs</button>
       
</form>

<?php
if (isset($start)) {
   $bin=$_POST['bin'];
   $path=$_POST['path'];
   $screen=$_POST['screen'];
} else {
   $start = "cd ". $path . " && screen -AmdS " . $name . " ./" . $bin . " " . $options;
}


?>

merci et bonne journée !

Pied de page des forums

Propulsé par FluxBB