Commit 1b1469fb authored by Celine Noirot's avatar Celine Noirot
Browse files

Finalization of purge managment

parent cec7c0e9
......@@ -134,6 +134,7 @@ class tx_nG6_utils {
function hash_password($password){
return tx_saltedpasswords_salts_factory::getSaltingInstance()->getHashedPassword($password);
}
function get_ssh_connection($user_login, $user_pwd){
$connection = ssh2_connect('127.0.0.1', 22);
if (!$connection) return NULL;
......@@ -142,26 +143,6 @@ class tx_nG6_utils {
return $connection ;
}
function purge_files($connection,$directory){
error_log("purge_files: >".$directory."< \n");
$files = array_slice(scandir($directory),2);
// First try to connect the specified user using ssh
//TODO : BUG
// si unix user plantage de la suppression
// si ng6test erreur du ssh2_auth_password, voir avec MS
error_log("connection: ".$connection."\n");
foreach ($files as $file){
if (substr($file,-4) != ".png" AND substr($file,-5) != ".html") {
// And process the directories structure
$res=ssh2_exec($connection, 'rm '.$directory."/".$file);
error_log("purge_files: rm -rf >".$directory."/".$file."< return : ".$res."\n");
if (file_exists($directory."/".$file)) {
return 1;
}
}
}
return 0;
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/class.tx_nG6_utils.php']) {
......
......@@ -434,21 +434,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</tfoot>
</table>
<div id="purge_demand_menu" class="clearfix">
<div>
<p>
Please enter the purge demand number to process (one number per line):
</p>
<textarea id="purge_demand_input" rows="4" cols="50"></textarea>
<br />
<button id="delete_data_from_text" type="button" class="btn btn-sm btn-default" ><i class="glyphicon glyphicon-remove"></i> Delete data</button>
<button id="extend_data_retention_from_text" type="button" class="btn btn-sm btn-default"><i class="glyphicon glyphicon-pencil"></i> Extend retention date </button>
<br />
</div>
</div>
</div> <!--end purge_demand_list-->
</div> <!--purge demand management-->
......
......@@ -104,25 +104,30 @@ class tx_nG6_pi6 extends tslib_pibase {
}
function send_purge_demand_mail($user_id,$project_ids) {
$template_mail= 'Dear user,
$template_mail= 'Mail automatique / en phase de TEST
Dear user,
The data storage time limit of ###nb_run### run(s) and ###nb_analyse### analyse(s) of ###PROJECT_NAME### project (###PROJET_ID###) is coming to end.
The data storage time limit of ###nb_run### run(s) and ###nb_analyse### analyse(s) of ###PROJECT_NAME### project is coming to end.
This purge alert number ###DEMAND_ID### corresponds to the files (size : ###STORAGE_SIZE###) linked to the following
* runs names: ###RUNS_LIST###
* analyses ids: ###ANALYSES_LIST###
This purge alert No ###DEMAND_ID### corresponds to ###STORAGE_SIZE### (see below for more details)
In ###PURGE_DELAY### days, your data will be delete. Until then, you can save them by your own, or ask for extention period with number ###DEMAND_ID###.
In ###PURGE_DELAY### days, your data will be delete. Keep us informed if you wish to extend the storage period by answering to this email with following this informations:
###EMAILS###Keep us informed if you wish to extend the storage so that we do not delete the data by error, by answering to this email with following this informations :
Demand number: ###DEMAND_ID###
Request for extension term: XXX (minimal unit: ###EXTENSION_DURATION###)
Request for extension size: XXX (mininal unit: ###EXTENSION_SIZE###)
Laboratory name/Institution:
Demand number : ###DEMAND_ID###
Extension term (min ###EXTENSION_DURATION###) :
Extension size (min ###EXTENSION_SIZE###) :
Price for ###EXTENSION_SIZE### during ###EXTENSION_DURATION### is about ###EXTENSION_PRICE###.
Prices are available at ###EXTENSION_URL_PRICES###.
###EMAILS###It would be appreciable if you could group your demand by laboratory.
Yours sincerely
nG6 team';
nG6 team
Files details:
* runs names: ###RUNS_LIST###
* analyses ids: ###ANALYSES_LIST###
';
$project_name="";
$txNG6Utils = new tx_nG6_utils;
foreach(explode(",", $project_ids) as $project_id){
......@@ -143,19 +148,19 @@ nG6 team';
$admin_name[] = $u["user_name"];
}
}
#Warn if mail is sent to several manager
$email_warn="" ;
$purge_email_to="";
if ( count($managers_email) > 1 ) {
$email_warn="This project is associated to several managers (all recieved this email), please send only one answer per purge alert number.(".join(',', $managers_email).")\n";
if ( count($managers_email) >= 1 ) {
$email_warn="This project is associated to several managers (all recieved this email), please send only one answer per purge alert number.\n";
$purge_email_to=join(',', $managers_email);
}elseif ( count($managers_email ==0)) {
$email_warn="As this project do not have managers, administrators recieved this alert (".join(',', $admin_email).")\n";
$email_warn="As this project do not have managers, administrators recieved this alert.\n";
$purge_email_to=join(',', $admin_email);
$managers_name=$admin_name;
}
//Retrieve purgeable information for email
$run_info="";
$run_info=Array();
$all_purgeable_runs=array_merge($p[$project_id]["state"]["stored"]["run_ids"],$p[$project_id]["state"]["extended"]["run_ids"]);
$all_purgeable_analysis=array_merge($p[$project_id]["state"]["stored"]["analysis_ids"],$p[$project_id]["state"]["extended"]["analysis_ids"]);
......@@ -165,7 +170,7 @@ nG6 team';
foreach($all_purgeable_runs as $run_id ){
$run = tx_nG6_db::select_run($run_id);
$run_name = $run["name"];
$run_info .= $run["name"]." ($run_id), ";
$run_info[]= $run["name"]." ($run_id)";
}
#Add purge demand to get id
......@@ -174,23 +179,21 @@ nG6 team';
#Build corresponding string array
$search=array("###nb_run###","###nb_analyse###","###PROJECT_NAME###","###PROJET_ID###","###DEMAND_ID###",
"###EMAILS###","###RUNS_LIST###","###ANALYSES_LIST###","###STORAGE_SIZE###",
"###EXTENSION_DURATION###","###EXTENSION_SIZE###","###EXTENSION_PRICE###","###PURGE_DELAY###");
"###EXTENSION_DURATION###","###EXTENSION_SIZE###","###EXTENSION_URL_PRICES###","###PURGE_DELAY###");
$replace=array($nb_run_purgeable,$nb_analyse_purgeable,$p[$project_id]["project_name"],$project_id, $purge_demand_id ,
$email_warn, $run_info , $analysis_list, tx_nG6_utils::get_octet_string_representation($p[$project_id]["total_purgeable_size"] ),
$email_warn, join(', ', $run_info), join(', ', $all_purgeable_analysis), tx_nG6_utils::get_octet_string_representation($p[$project_id]["total_purgeable_size"] ),
$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['min_extension_duration'],$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['min_extension_size'],
$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['min_extension_price'],$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['delay_purge']);
$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['extension_url_price'],$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['delay_purge']);
$mail=str_replace($search, $replace, $template_mail);
$to = $purge_email_to;
$to = $purge_email_to;
$subject = '[nG6 purge] No '.$purge_demand_id.' - Project '.$p[$project_id]["project_name"];
$headers[] = 'From: '.$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['email_from'];
#$headers[] = 'Cc: '.$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['email_from'];
$headers[] = 'Reply-To: '.$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['email_from'];
$headers[] = 'X-Mailer: PHP/' . phpversion();
#TODO Uncomment
#$to = "celine.noirot@inra.fr";
mail($to, $subject, $mail, implode("\r\n", $headers));
//return $headers ;
}
return implode("\r\n", $headers).$mail;
}
......
......@@ -366,6 +366,7 @@ $(function () {
//Obsolete project / purge demand
//mark mail sent
$("#send_mail").click(function(){
$('#data_table_obsolete_wait').show();
$('#obsolete_list').hide();
var all_runs="",
......@@ -390,28 +391,17 @@ $(function () {
}
});
});
// Delete data after writing list of ids demand
$("#delete_data_from_text").click(function(){
delete_data($("#purge_demand_input").val().replace("\n",","),purge_table["demand"]);
});
// Delete data after selecting list of ids demand
$("#delete_data_from_list").click(function(){
console.log("delete_data_from_list");
demands="";
var demands=[];
$(':checked[id^=chk_demand').each(function(){
demand_id=$(this).val();
demands+=demand_id+"," ;
demands.push(demand_id);
});
demands=demands.slice(0,-1);
delete_data(demands,purge_table["demand"]);
});
// Extend retention after writing list of ids demand
$("#extend_data_retention_from_text").click(function(){
extend_date($("#purge_demand_input").val().replace("\n",","),purge_table["demand"],purge_table["obsolete"]);
});
// Extend retention after selecting list of ids demand
$("#extend_data_retention_from_list").click(function(){
demands="";
......@@ -424,7 +414,6 @@ $(function () {
});
/***** DataTable Obsolete & Demand chek all ****/
$("[id^=all_chk_]").change(function(){
var type = $(this).attr("id").split("_")[2];
var chk_status = $(this)[0].checked ;
......@@ -435,56 +424,146 @@ $(function () {
function delete_data(list_ids,purge_demand_datatable){
console.log("delete_data");
console.log(list_ids);
var _get_workflow_status = function(workflow_id, callback, error_callback){
$.ajax({
url : $("#server_url").val() + '/get_workflow_status?display=list&workflow_id=' + workflow_id ,
url : $("#server_url").val() + '/get_workflow_status?display=list&workflow_id=' + workflow_id ,
dataType : 'jsonp',
timeout: 20000 ,
success : function(data){
if (callback){
callback(data);
}
},
error : function(jqXHR, textStatus, errorThrown){
if (error_callback){
error_callback(jqXHR, textStatus, errorThrown);
}
}
});
};
var _retrieve_data = function(workflow_id, callback, error_callback){
$.ajax({
url : $("#server_url").val() + '/get_workflow_outputs?workflow_id=' + workflow_id,
dataType : 'jsonp',
timeout: 20000 ,
success : function(data){
if (callback){
callback(data);
}
},
error : function(jqXHR, textStatus, errorThrown){
if (callback) {
callback(data);
}
},
error : function(jqXHR, textStatus, errorThrown){
if (error_callback){
error_callback(jqXHR, textStatus, errorThrown);
}
}
}
});
};
var _retrieve_url_list = function(modal, running_wf, ufilename , process_data){
modal.$body.html([
};
var _display_file_content = function(filepath, $elmt){
$.get(filepath, function(data){
$elmt.html([
'<div class="alert">',
' <p>',
' <strong>Success !</strong> You will find bellow the list of deteted paths.',
' </p>',
'</div>',
].join(''));
var client = new ZeroClipboard($("#copy_urls"));
});
};
$('#setAndRunModalLabel').html("Loading");
$('#setAndRunModalFooter').html([
' <div class="btn-group">',
' <button id="close" class="btn btn-default" data-dismiss="modal"><i class="glyphicon glyphicon-remove"></i> Close</button>',
' </div>',
' <div class="btn-group">',
' <button id="reset_workflow" class="btn btn-default"><i class="glyphicon glyphicon-refresh"></i> Reset</button>',
' <button id="run_workflow" class="btn btn-primary"><i class="glyphicon glyphicon-floppy-save"></i> Start</button>',
' </div>'
].join(''));
$("#reset_workflow, #run_workflow").hide();
$("#close").show();
$('#setAndRunModalBody').html([
'<div >',
' <p id="wf-help" class="text-justify"></p><br/><br/>',
' <div id="wfform"><div class="tx-nG6-wait">Please wait</div></div>',
'</div>',
].join(''));
var modal = {
'$label' : $('#setAndRunModalLabel'),
'$body' : $('#setAndRunModalBody'),
'$footer' : $('#setAndRunModalFooter'),
'$modal' : $('#setAndRunModal')
};
var wfform_options = {
workflowClass: "PurgeDemand",
serverURL: $("#server_url").val(),
displayRunButton: false,
displayResetButton: false,
parameters : {
"admin_login" : $("#user_name").val(),
"demand_id" : list_ids
}
};
$('#wfform').on("loaded.wfform", function(event, workflow) {
$("#reset_workflow, #run_workflow").show();
$("#close").hide();
if(workflow){
modal.$label.html(workflow["name"]) ;
$('#wf-help').html(workflow["help"]);
}
else{
modal.$body.html('<div class="alert alert-warning"> <strong>Warning !</strong> The workflow "PurgeDemand" is not available</div>');
}
});
$("#reset_workflow").click(function(){
$('#wfform').wfform('reset');
});
$("#run_workflow").click(function(){
$('#wfform').wfform('run');
});
// remove plugin data
$('#wfform').removeData();
modal.$modal.modal();
modal.$modal.find('#wfform').wfform(wfform_options);
modal.$modal.find('#wfform').on('run.wfform', function(event, running_wf) {
modal.$body.html([
'<div>',
' <div class="alert alert-info">',
' <p>',
' <strong>Data</strong> are being deleted. Use the refresh button to get the list of files.',
' <strong>The data</strong> are being deleted. Use the refresh button to get the status and retrieve list of deleted directories.',
' </p>',
' </div>',
' <div id="wfstatus">',
' </div>',
'</div>'
].join(''));
modal.$footer.html([
' <div class="btn-group">',
' <button id="refresh_workflow" class="btn btn-default"><i class="glyphicon glyphicon-refresh"></i> Get data</button>',
' </div>',
' <div class="btn-group">',
' <button id="close" class="btn btn-default" data-dismiss="modal"><i class="glyphicon glyphicon-remove"></i> Close</button>',
' </div>',
].join(''));
$('#wfstatus').wfstatus({
].join(''));
modal.$footer.html([
' <div class="btn-group">',
' <button id="refresh_workflow" class="btn btn-default"><i class="glyphicon glyphicon-refresh"></i> Refresh</button>',
' </div>',
' <div class="btn-group">',
' <button id="close" class="btn btn-default" data-dismiss="modal"><i class="glyphicon glyphicon-remove"></i> Close</button>',
' </div>',
].join(''));
modal.$modal.find('#wfstatus').wfstatus({
workflowID : running_wf.id,
display : 'list',
serverURL: $("#server_url").val(),
})
$("#refresh_workflow").click(function(){
modal.$body.html("<div class='tx-nG6-wait'> <strong>Please</strong> wait...</div>");
});
$("#refresh_workflow").click(function(){
modal.$body.find('#wfstatus').html("<div class='tx-nG6-wait'> <strong>Please</strong> wait...</div>");
button = this;
button.disabled = true;
......@@ -494,13 +573,13 @@ function delete_data(list_ids,purge_demand_datatable){
if (statusdata.status == "completed"){
_retrieve_data(running_wf.id, function(data){
$(button).hide();
$.each(data, function(i, component) {
$.each(component, function(filename, file) {
if (filename == ufilename){
_display_file_content(file.url, modal.$body, process_data);
}
});
});
$.each(data, function(i, component) {
$.each(component, function(filename, file) {
if (filename == "remove_list.txt"){
_display_file_content(file.url, modal.$body);
}
});
});
},
//errorcb
function(jqXHR, textStatus, errorThrown){
......@@ -513,175 +592,18 @@ function delete_data(list_ids,purge_demand_datatable){
);
}
else {
$('#wfstatus').wfstatus('reload');
modal.$modal.find('#wfstatus').wfstatus('reload');
button.disabled = false;
}
},
// errorcb
function(){
$('#wfstatus').wfstatus('reload');
modal.$modal.find('#wfstatus').wfstatus('reload');
button.disabled = false;
}
);
});
};
var _retrieve_data = function(workflow_id, callback, error_callback){
$.ajax({
url : $("#server_url").val() + '/get_workflow_outputs?workflow_id=' + workflow_id,
dataType : 'jsonp',
success : function(data){
if (callback) {
callback(data);
}
},
error : function(jqXHR, textStatus, errorThrown){
if (error_callback){
error_callback(jqXHR, textStatus, errorThrown);
}
}
});
};
var _display_file_content = function(filepath, $elmt, process_data){
$.get(filepath, function(data){
if (process_data) {
data = process_data(data);
}
$elmt.html([
'<div class="alert">',
' <p>',
' <strong>Success !</strong> You will find bellow the list of deleted file.',
' Use the <i class="glyphicon glyphicon-floppy-save"></i> button to copy all paths to the clipboard.<br/>',
' </p>',
'</div>',
'<div>',
' <button id="copy_urls" class="btn btn-default btn-sm pull-right" data-clipboard-target="url_filelist">',
' <i class="glyphicon glyphicon-floppy-save"></i>&nbsp;',
' </button><br/>',
' <textarea readonly id="url_filelist" rows="25" style="resize:none;white-space: pre; word-wrap: normal; overflow-x: scroll; width: 100%">',
data.trim(),
' </textarea>',
'</div>'
].join(''));
var client = new ZeroClipboard($("#copy_urls"));
});
};
$('#setAndRunModalLabel').html("Loading");
$('#setAndRunModalFooter').html([
' <div class="btn-group">',
' <button id="close" class="btn btn-default" data-dismiss="modal"><i class="glyphicon glyphicon-remove"></i> Close</button>',
' </div>',
' <div class="btn-group">',
' <button id="reset_workflow" class="btn btn-default"><i class="glyphicon glyphicon-refresh"></i> Reset</button>',
' <button id="run_workflow" class="btn btn-primary"><i class="glyphicon glyphicon-floppy-save"></i> Start</button>',
' </div>'
].join(''));
$("#reset_workflow, #run_workflow").hide();
$("#close").show();
$('#setAndRunModalBody').html([
'<div >',
' <p id="wf-help" class="text-justify"></p><br/><br/>',
' <div id="wfform"><div class="tx-nG6-wait">Please wait</div></div>',
'</div>',
].join(''));
var modal = {
'$label' : $('#setAndRunModalLabel'),
'$body' : $('#setAndRunModalBody'),
'$footer' : $('#setAndRunModalFooter'),
'$modal' : $('#setAndRunModal')
};
console.log(list_ids);
var wfform_options = {
workflowClass: "PurgeDemand",
serverURL: $("#server_url").val(),
displayRunButton: false,
displayResetButton: false,
parameters : {
"demand" : list_ids,
"admin_login" : $("#user_name").val()
}
};
$('#wfform').on("loaded.wfform", function(event, workflow) {
$("#reset_workflow, #run_workflow").show();
$("#close").hide();
if(workflow){
modal.$label.html(workflow["name"]) ;
$('#wf-help').html(workflow["help"]);
}
else{
modal.$body.html('<div class="alert alert-warning"> <strong>Warning !</strong> The workflow "PurgeDemand" is not available</div>');
}
});
$("#reset_workflow").click(function(){
$('#wfform').wfform('reset');
});
$("#run_workflow").click(function(){
$('#wfform').wfform('run');
});
// remove plugin data
$('#wfform').removeData();
modal.$modal.modal();
modal.$modal.find('#wfform').wfform(wfform_options);
modal.$modal.find('#wfform').on('run.wfform', function(event, running_wf) {
console.log(running_wf)
//_retrieve_url_list(modal, running_wf, 'output_list.txt');
});
/*
$("#modal-label-tmpl").text("Purge login");
$("#modal-body-tmpl").html('<p id="wf-help" class="text-justify">For purging files, please enter a unix login and password.</p>'
+'<div> <div class="form-group param-field">'
+'<label id="label_default" class="col-sm-2 control-label" for="username">Username</label>'
+'<div class="col-sm-10">'
+'<input id="username" name="username" value="" class="form-control" type="text">'
+'<span class="help-block">A valid user username on the server</span>'
+'</div>'
+'</div>'
+'<div class="form-group param-field">'
+'<label id="label_default" class="col-sm-2 control-label" for="password">Password</label>'
+'<div class="col-sm-10">'
+'<input id="password" name="password" value="" class="form-control" type="password">'
+'<span class="help-block">The connection password for the username on the server</span>'
+'</div>'
+'</div></div>');
$("#modal-foot-tmpl").html('<button id="close" class="btn btn-default" data-dismiss="modal" ><i class="glyphicon glyphicon-remove"></i> Close</button> </div> <div class="btn-group"> '
+'<button id="modal-btn-send-delete" class="btn btn-primary">Delete</button>');
$("#ng6modal").modal();
$("#modal-btn-send-delete").click(function(){
var user = $("#username").val(),
password= $("#password").val();
$("#ng6modal").modal('hide');
$('#data_table_purge_demand_wait').show();
$('#purge_demand_list').hide();
$.ajax({
url: "index.php?eID=tx_nG6&type=delete_data&data_folder="+data_folder+"&purge_demand="+list_ids+"&username="+user+"&password="+password+"&user_id="+$('input[id=user_id]').val(),
dataType: 'json',
success: function(val, status, xhr) {
if (val.startsWith("Error")) {
$("#purge_demand_error").text(val).fadeIn().delay(3000).fadeOut();
}
refresh_purge_demand(purge_demand_datatable);
},
error: function( jqXHR, textStatus, errorThrown) {
$("#purge_demand_error").text("Error while deleting data"+textStatus).fadeIn().delay(3000).fadeOut();
$('#data_table_purge_demand_wait').hide();
$('#purge_demand_list').show();
}
});
});*/
}
function extend_date(list_ids, purge_demand_datatable, obsolete_project_datatable){
......@@ -763,6 +685,7 @@ function refresh_purge_demand(purge_demand_datatable){
});
}
function refresh_project_obsolete(obsolete_project_datatable){
$('#data_table_obsolete_wait').show();
......