Commit 41cb0fd2 authored by Celine Noirot's avatar Celine Noirot

Merge branch 'issue#129' into 'master'

Merge branch Issue#129 with master

See merge request !83
parents 6c16a1fa 22bf6e1e
<?php
/***************************************************************
* Copyright notice
......@@ -622,7 +624,53 @@ class tx_nG6_eid {
}
}
else if ($type = 'check_ssh_user'){
$user_login = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('user_login'));
$user_pwd = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('user_pwd'));
$project_id = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('project_id'));
$path_to_check = tx_nG6_utils::get_project_data_save_dir($project_id);
$res = 3;
// check login and password
if (isset($user_login) && isset($user_pwd) && $user_login != 'undefined' && $user_pwd != 'undefined') {
$ssh_command = 'touch '.$path_to_check.'/test ; rm -f '.$path_to_check.'/test' ;
$connection = ssh2_connect('127.0.0.1', 22);
if (!$connection) {
//1st test, basic SSH connection
$res = 3;
} else if( !ssh2_auth_password($connection, $user_login,$user_pwd ) ){
//2nd test, SSH connection with user + pwd
$res = 2;
}else{
//3rd test, excuting the SSH command
$stream = ssh2_exec($connection, $ssh_command );
$errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
// Enable blocking for both streams
stream_set_blocking($errorStream, true);
stream_set_blocking($stream, true);
if(stream_get_contents($errorStream)) {
// Close the streams
fclose($errorStream);
fclose($stream);
$res = 4;
}else{
fclose($errorStream);
fclose($stream);
$res = 0;
}
}
} else {
//The user and/or password is missing
$res = 3;
}
print $res;
}
else if ( $type == 'add_to_ng6_admin'){
$userid = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('userid'));
tx_nG6_db::add_to_ng6_admin($userid);
......
......@@ -286,6 +286,7 @@ please have a look at our storage fees (<a href="###URL_PRICE###">###URL_PRICE##
return($config_file_content);
}
//Return a php array containing the section relative to the given space_id
static function get_retention_policy_from_space_id($space_id = "default"){
$config_file_content = tx_nG6_utils::get_config_content("default");
......@@ -352,6 +353,44 @@ please have a look at our storage fees (<a href="###URL_PRICE###">###URL_PRICE##
return($return_text);
}
static function get_project_data_save_dir($project_id){
$space_id = tx_nG6_db::get_project_space_id($project_id);
$space_config = tx_nG6_utils::get_retention_policy_from_space_id($space_id);
$path_to_space_save_dir = '';
foreach($space_config as $line_id => $line_content){
if(strpos($line_content, 'dir_name') === 0){
//We get the value in the "dir_name = " line
$space_save_dir = trim( substr( $line_content, strpos( $line_content, '=')+1 ) );
}
}
$save_dir = tx_nG6_utils::get_save_dir();
$path_to_space_save_dir = $save_dir.'/'.$space_save_dir;
return($path_to_space_save_dir);
}
static function get_save_dir(){
$config_file_content = tx_nG6_utils::get_config_content($space_id);
$pattern_to_find = 'save_directory';
$array_config_content = explode(PHP_EOL, $config_file_content);
$path_to_save_dir='';
foreach($array_config_content as $line_id => $line_content){
//if we found the right section
if( strpos($line_content,$pattern_to_find)===0 && ! $is_pattern_found){
//We copy the line from the first '/'
$path_to_save_dir = substr($line_content, strpos( $line_content, '/')) ;
}
}
return($path_to_save_dir);
}
static function convert_epoch_timestamp_to_nice_date( $epoch_date ){
//return(gmdate('D, d M Y', $epoch_date));
return(gmdate('l jS \of F Y', $epoch_date));
......@@ -359,6 +398,8 @@ please have a look at our storage fees (<a href="###URL_PRICE###">###URL_PRICE##
}
}
......
......@@ -44,7 +44,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<div class="ng6-content-header-left project">
<h2>Projet <small>{$projects[key($projects)].name}</small></h2>
<div><p>Current space: <b><span id="current_space_id">{$projects[key($projects)].space_id}</span></b></p></div>
{if $is_ng6_superadmin}
{if $projects[key($projects)].is_admin}
<div id="change_space_id_warning"><p><i>Warning, migrating a project from one space to another will update both the files location and the retention limits.</i></p></div>
<div id="change_space_id_form"></div>
<div id="wf_id"></div>
......
/***************************************************************
* Copyright notice
*
......@@ -1590,7 +1591,7 @@ function deletePRAHandler() {
url: val_url,
success: function(val, status, xhr) {
// return code : 0 = ok, 1 = right error, 2 = authentication error, 3 = connexion error
if (val == "0") {
if (val == '0') {
// Uncheck all checkboxes
$(':checked').each(function(i){
$(this).attr('checked',false);
......@@ -1599,11 +1600,11 @@ function deletePRAHandler() {
location.reload();
} else {
$("#modal-label-tmpl").html("Error");
if (val == "1") {
if (val == '1') {
$("#modal-body-tmpl").html("<div class='tx-nG6-pi1-error'>You don't have write permission on the specified directory.</div>");
} else if (val == "2") {
} else if (val == '2') {
$("#modal-body-tmpl").html("<div class='tx-nG6-pi1-error'>An error occurred during login. Most likely you didn't enter the username or password correctly. Be certain that you enter them precisely as they are, including upper/lower case.</div>");
} else if (val == "3") {
} else if (val == '3') {
$("#modal-body-tmpl").html("<div class='tx-nG6-pi1-error'>An error occurred during server connection. Please contact the site administrator.</div>");
}
$("#modal-foot-tmpl").html('<button class="btn btn-default" data-dismiss="modal" aria-hidden="true"><i class="glyphicon glyphicon-remove"></i> Close</button>');
......@@ -2237,8 +2238,68 @@ function setChangeSpaceForm(){
//When clicking 'migrate'
$("#run_workflow").click(function(){
$('#change_space_id_form').wfform('run');
var params = simpleQueryParams(location.href),
project_id = params["tx_nG6_pi1[project_id]"];
//We show a modal to check if the given SSH user + password is ok
var switch_space_auth_html = [
'<div class="tx-nG6-pi1-login">',
' This functionality is only available if you have an account on the ' + $("#server_name").val() + ' server. <br /> <br /> ',
' <form class="form-horizontal" id="tx-nG6-pi1-login-form" >',
' <div class="input-group" style="margin-left:50px">',
' <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>',
' <input class="form-control" style="width:200px" type="text" id="user_login_val" name="user_login_val" placeholder="Username"/>',
' </div><br/>',
' <div class="input-group" style="margin-left:50px">',
' <span class="input-group-addon"><i class="glyphicon glyphicon-wrench"></i></span>',
' <input class="form-control" style="width:200px" type="password" id="user_pwd_val" name="user_pwd_val" placeholder="Password"/>',
' </div>',
' </form>',
'</div>'
].join('');
$("#modal-label-tmpl").html("Migrate");
$("#modal-body-tmpl").html(switch_space_auth_html);
$("#modal-foot-tmpl").html('<button class="btn btn-default" data-dismiss="modal" aria-hidden="true"><i class="glyphicon glyphicon-remove"></i> Close</button>' +
'<button id="modal-btn-migrate" class="btn btn-primary"><i class="glyphicon glyphicon-trash"></i> Migrate</button>');
$("#ng6modal").modal();
$("#modal-btn-migrate").click(function(){
var params = simpleQueryParams(location.href),
project_id = params["tx_nG6_pi1[project_id]"];
//We call the ajax check "check_ssh_user"
var val_url = "index.php?eID=tx_nG6&type=check_ssh_user";
val_url += "&user_login=" + $("#user_login_val").val() + "&user_pwd=" + $("#user_pwd_val").val() + "&project_id=" + project_id;
$.ajax({
url: val_url,
success: function(val, status, xhr) {
// return codes : 0 = ok, 2 = authentication error, 3 = connexion error, 4 = the user doesn't have the rights
// For no reason I understand, the string returned is "\n\n<ret_code>", so we parse it to int.
val = parseInt(val);
if (val == 0) {
$("#ng6modal").modal('hide');
//Run switch_space_id workflow
$('#change_space_id_form').wfform('run');
} else {
$("#modal-label-tmpl").html("Error");
if (val == 2) {
$("#modal-body-tmpl").html("<div class='tx-nG6-pi1-error'>An error occurred during login. Most likely you didn't enter the username or password correctly. Be certain that you enter them precisely as they are, including upper/lower case.</div>");
} else if (val == 3) {
$("#modal-body-tmpl").html("<div class='tx-nG6-pi1-error'>An error occurred during server connection. Please contact the site administrator.</div>");
} else if(val == 4){
$("#modal-body-tmpl").html("<div class='tx-nG6-pi1-error'>The user you entered doesn't have the rights to perform this action.</div>");
}
$("#modal-foot-tmpl").html('<button class="btn btn-default" data-dismiss="modal" aria-hidden="true"><i class="glyphicon glyphicon-remove"></i> Close</button>');
$("#ng6modal").modal();
}
}
});
});
});
//The status label has to be display just for a few seconds each time we hit "Migrate" or "Refresh"
$("#change_space_id_status").hide();
......
Markdown is supported
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