Commit 6f82456f authored by Claire Kuchly's avatar Claire Kuchly
Browse files

fix connexion bug for purge demand directory

parent fa8a0822
......@@ -120,38 +120,45 @@ class tx_nG6_utils {
* @param string $directory
* @return 0=>everything ok, 1=>user right problem, 2=>wrong authentification, 3=>connection error
*/
function purge_directory($user_login, $user_pwd, $directory) {
// First try to connect the specified user using ssh
$connection = ssh2_connect('127.0.0.1', 22);
if (!$connection) return 3;
if (!ssh2_auth_password($connection, $user_login, $user_pwd)) return 2;
if ($directory != 'undefined' && $directory != '') {
// And process the directories structure, remove all files except .html ans .png
//TO DEBUG
/*
$stream = ssh2_exec($connection, 'ls '.$directory.'/* | grep -v -e ".html$" -e ".png$" | xargs rm -f');
stream_set_blocking($stream, true);
$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
error_log( stream_get_contents($stream_out) . $stream);
error_log( 'ls '.$directory.'/* | grep -v -e ".html$" -e ".png$" | xargs rm -f');
if ($stream === False) {
return 4;
}*//*
$ssh = new Net_SSH2('127.0.0.1');
if (!$ssh->login($user_login, $user_pwd)) {
return 2;
}
// First try to connect the specified user using ssh
if ($directory != 'undefined' && $directory != '') {
// And process the directories structure, remove all files except .html ans .png
$val_return = $ssh->exec( 'ls '.$directory.'/* | grep -v -e ".html$" -e ".png$" | xargs rm -f');
if ($val_return != 0 ) {
return 4;
}*/
}
return 4;
$connection = ssh2_connect('127.0.0.1', 22);
if (!$connection) {
return 3;
}else{
if (!ssh2_auth_password($connection, $user_login,$user_pwd )){
return 2;
}else{
$stream = ssh2_exec($connection, 'ls '.$directory.'/* | grep -v -e ".html$" -e ".png$" | xargs rm -f' );
$errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
// Enable blocking for both streams
stream_set_blocking($errorStream, true);
stream_set_blocking($stream, true);
// Whichever of the two below commands is listed first will receive its appropriate output. The second command receives nothing
error_log("Output: " . stream_get_contents($stream));
if(stream_get_contents($errorStream)) {
error_log("mauvais identifiant");
return 1;
}else{
error_log("bon identifiant ");
return 0;
}
// Close the streams
fclose($errorStream);
fclose($stream);
}
}
}
return 0;
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment