Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
genotoul-bioinfo
ng6
Commits
6f82456f
Commit
6f82456f
authored
Jun 19, 2018
by
Claire Kuchly
Browse files
fix connexion bug for purge demand directory
parent
fa8a0822
Changes
1
Hide whitespace changes
Inline
Side-by-side
ui/nG6/lib/class.tx_nG6_utils.php
View file @
6f82456f
...
...
@@ -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
;
}
/**
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment