Commit 0a0fcc3f authored by Gerald Salin's avatar Gerald Salin
Browse files

#21 : enhance ssh2_connect management

parent eaf80301
...@@ -101,9 +101,23 @@ class tx_nG6_utils { ...@@ -101,9 +101,23 @@ class tx_nG6_utils {
if ($directory != 'undefined' && $directory != '') { if ($directory != 'undefined' && $directory != '') {
// And process the directories structure // And process the directories structure
//TODO BUG NE RETOURNE PAS D'ERREUR si pas supprimer $stream = ssh2_exec($connection, 'rm -rf '.$directory."/");
if (!ssh2_exec($connection, 'rm -rf '.$directory."/")) { $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
if(stream_get_contents($errorStream)) {
// Close the streams
fclose($errorStream);
fclose($stream);
return 1; return 1;
}else{
// Close the streams
fclose($errorStream);
fclose($stream);
return 0;
} }
} }
return 0; return 0;
...@@ -120,8 +134,7 @@ class tx_nG6_utils { ...@@ -120,8 +134,7 @@ class tx_nG6_utils {
static function purge_directory($user_login, $user_pwd, $directory) { static function purge_directory($user_login, $user_pwd, $directory) {
if ($directory != 'undefined' && $directory != '') { if ($directory != 'undefined' && $directory != '') {
// And process the directories structure, remove all files except .html ans .png // And process the directories structure, remove all files except .html and .png
$connection = ssh2_connect('127.0.0.1', 22); $connection = ssh2_connect('127.0.0.1', 22);
if (!$connection) { if (!$connection) {
return 3; return 3;
...@@ -135,18 +148,19 @@ class tx_nG6_utils { ...@@ -135,18 +148,19 @@ class tx_nG6_utils {
// Enable blocking for both streams // Enable blocking for both streams
stream_set_blocking($errorStream, true); stream_set_blocking($errorStream, true);
stream_set_blocking($stream, 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 // Whichever of the two below commands is listed first will receive its appropriate output. The second command receives nothing
if(stream_get_contents($errorStream)) { if(stream_get_contents($errorStream)) {
// Close the streams
fclose($errorStream);
fclose($stream);
return 1; return 1;
}else{ }else{
// Close the streams
fclose($errorStream);
fclose($stream);
return 0; return 0;
} }
// Close the streams
fclose($errorStream);
fclose($stream);
} }
} }
} }
......
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