Commit d67015f2 authored by Celine Noirot's avatar Celine Noirot
Browse files

Add purge management

parent add9ee64
......@@ -709,7 +709,6 @@ class tx_nG6_eid {
$smarty->setConfigDir(t3lib_extMgm::extPath('nG6').'/res/smarty/configs');
$smarty->security = true;
$smarty->security_settings['MODIFIER_FUNCS'] = array('count');
$user_id = trim(t3lib_div::_GP('user_id'));
$login_user = intVal(trim(t3lib_div::_GP('login_user')));
$page_id = intVal(trim(t3lib_div::_GP('page_id')));
$projects = tx_nG6_db::select_all_user_projects($user_id, 'tx_nG6_project.name');
......@@ -737,7 +736,6 @@ class tx_nG6_eid {
$smarty->setConfigDir(t3lib_extMgm::extPath('nG6').'/res/smarty/configs');
$smarty->security = true;
$smarty->security_settings['MODIFIER_FUNCS'] = array('count');
$user_id = trim(t3lib_div::_GP('user_id'));
$login_user = intVal(trim(t3lib_div::_GP('login_user')));
$page_id = intVal(trim(t3lib_div::_GP('page_id')));
$project_id = intVal(trim(t3lib_div::_GP('project_id')));
......@@ -840,13 +838,18 @@ class tx_nG6_eid {
print json_encode(tx_nG6_db::select_storage_evolution($values, $by, $role, $get_analyzes, $octet, $cumulate));
} elseif ($type == 'purge_managment_mail') {
$user_id = trim(t3lib_div::_GP('user_id'));
$all_projects = trim(t3lib_div::_GP('project'));
print json_encode(tx_nG6_pi6::send_purge_demand_mail($user_id,$all_projects));
//TODO check if user is still logged
if ($user_id == ""){
print json_encode("Error: reconnect");
} else {
$all_projects = trim(t3lib_div::_GP('project'));
print json_encode(tx_nG6_pi6::send_purge_demand_mail($user_id,$all_projects));
}
} elseif ($type == 'refresh_purge_demand') {
$purge_delay = trim(t3lib_div::_GP('purge_delay'));
print json_encode(tx_nG6_db::get_purge_demand_list($purge_delay));
} elseif ($type == 'refresh_purge_list') {
$max_retention_date = trim(t3lib_div::_GP('max_retention_date'));
$max_retention_date = trim(t3lib_div::_GP('max_retention_date'));
$filter_size = trim(t3lib_div::_GP('filter_size'));
$without_laboratories_id = trim(t3lib_div::_GP('without_lab'));
$create_users = trim(t3lib_div::_GP('create_users'));
......@@ -854,21 +857,30 @@ class tx_nG6_eid {
print json_encode(tx_nG6_db::filter_list_retention_data_info($filter_size,$max_retention_date,$create_users, $without_laboratories_id));
} elseif ($type == 'delete_data') {
//Delete data link to the list of purge demand
$purge_ids = trim(t3lib_div::_GP('purge_demand'));
#TODO
print json_encode(tx_nG6_db::set_purge_demand_processed(explode(',',$purge_ids),"delete",""));
}
elseif ($type == 'extend_rentention_date') {
//Extend the retention date for the
$purge_ids = trim(t3lib_div::_GP('purge_demand'));
$value = trim(t3lib_div::_GP('date_value'));
//Change date format
$date = explode('/', $value);
$timestamp = mktime (0, 0, 1, $date[1], $date[0], $date[2]);
error_log("extend_rentention_date : ".$purge_ids."\n",3,"/save/ng6-test/src/nG6/ui/nG6/pi6/test.log");
print json_encode(tx_nG6_db::set_purge_demand_processed(explode(',',$purge_ids),"extend",$timestamp));
//TODO check if user is still logged
if ($user_id == ""){
print json_encode("Error: reconnect");
} else {
//Delete data link to the list of purge demand
$purge_ids = trim(t3lib_div::_GP('purge_demand'));
$data_folder = trim(t3lib_div::_GP('data_folder'));
$user = trim(t3lib_div::_GP('username'));
$password = trim(t3lib_div::_GP('password'));
print json_encode(tx_nG6_pi6::set_purge_demand_processed(explode(',',$purge_ids),"delete",$data_folder,$user,$password));
}
} elseif ($type == 'extend_rentention_date') {
//Extend the retention date for the
//TODO check if user is still logged
if ($user_id == ""){
print json_encode("Error: reconnect");
} else {
$purge_ids = trim(t3lib_div::_GP('purge_demand'));
$value = trim(t3lib_div::_GP('date_value'));
//Change date format
$date = explode('/', $value);
$timestamp = mktime (0, 0, 1, $date[1], $date[0], $date[2]);
print json_encode(tx_nG6_pi6::set_purge_demand_processed(explode(',',$purge_ids),"extend",$timestamp));
}
}
}
......
This diff is collapsed.
......@@ -134,6 +134,34 @@ 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;
if (!ssh2_auth_password($connection, $user_login, $user_pwd)) return NULL;
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
foreach ($files as $file){
if (substr($file,-4) != ".png") {
// And process the directories structure
$res=ssh2_exec($connection, 'rm '.$file);
error_log("purge_files: rm -rf >".$file."< return : ".$res."\n");
if (!$res) {
return 1;
}
}
}
return 0;
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/class.tx_nG6_utils.php']) {
......
......@@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<input type="hidden" id="data_folder" value="{$data_folder}" />
<input type="hidden" id="usergroup" value="{$group_info.uid}" />
<input type="hidden" id="server_url" value="{$server_url}" />
<input type="hidden" id="purge_delay" value="{$ng6_purge_delay}" />
<div class="sub-content sc-top">
<div class="ng6-content-header-left administration">
<h2>Administration <small> center </small> </h2>
......@@ -221,7 +221,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<table class="table table-striped table-bordered dataTable" id="users_data_table">
<thead>
<tr>
<th><center><input type="checkbox" id="chk_all_user"></center></th>
<th><center></th>
<th>Login</th>
<th>Last name</th>
<th>First name</th>
......@@ -342,25 +342,26 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<div class="row">
<div class="col-sm-offset-10 col-sm-2">
<button type="button" id="refresh_purge_list_btn" class="multiple-selection-btn btn btn-primary"> <i class="glyphicon glyphicon-refresh"></i> Refresh list</button>
<button type="button" id="refresh_obsolete_list_btn" class="multiple-selection-btn btn btn-primary"> <i class="glyphicon glyphicon-refresh"></i> Refresh list</button>
</div>
</div>
</div>
<br />
<div id="purge_list">
<div class="tx-nG6-wait" id="data_table_obsolete_wait">Please wait while processing ...</span></div>
<div id="obsolete_list">
<div>
<p>
Table with the number of runs and analysis who is obsolete and who has no purge demand mail sended.
Following table contains runs and analysis which can be purged, please alert project managers with button "send mail" after selecting projects.</br>
Then the project will be available for extention or purge in tab "Purge demand management"
</p>
</div>
<table class="table table-striped table-bordered dataTable" id="data_table_obsolete">
<thead>
<tr>
<th rowspan="2"><center><input type="checkbox" id="chk_all_runs"></center></th>
<th rowspan="2"><center><input type="checkbox" id="all_chk_obsolete"></center></th>
<th rowspan="2">Project</th>
<th rowspan="2">All Run</th>
<th colspan="2"><center>Obsoletes Runs </center></th>
......@@ -376,26 +377,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<th>Nb Analyze extended</th>
</tr>
</thead>
<tbody>
{foreach from=$ng6_purge_projects key=c_project_id item=project_values}
<tr id="tr_project_{$c_project_id}" >
<td><center><input type="checkbox" id="chk_project_{$c_project_id}" value="project_{$c_project_id}" /></center></td>
<td><a href="index.php?id=3&tx_nG6_pi1[project_id]={$c_project_id}">{$project_values.project_name}</a> </td>
<td>{$project_values.nb_runs}</td>
<td><input type="hidden" values="{$project_values.state.stored.run_ids}" id="rstored_project_{$c_project_id}" />{if $project_values.state.stored.nb_run}{$project_values.state.stored.nb_run} ({$tx_nG6_utils->get_octet_string_representation($project_values.state.stored.size_run)} ){else} - {/if}</td>
<td><input type="hidden" values="{$project_values.state.extended.run_ids}" id="rextended_project_{$c_project_id}" />{if $project_values.state.extended.nb_run}{$project_values.state.extended.nb_run} ({$tx_nG6_utils->get_octet_string_representation($project_values.state.extended.size_run)}) {else} - {/if}</td>
<td>{$project_values.nb_analyses}</td>
<td><input type="hidden" values="{$project_values.state.stored.analysis_ids}" id="astored_project_{$c_project_id}" />{if $project_values.state.stored.nb_analyze}{$project_values.state.stored.nb_analyze} ({$tx_nG6_utils->get_octet_string_representation($project_values.state.stored.size_analyze)}){else} - {/if}</td>
<td><input type="hidden" values="{$project_values.state.extended.analysis_ids}" id="aextended_project_{$c_project_id}" />{if $project_values.state.extended.nb_analyze}{$project_values.state.extended.nb_analyze} ({$tx_nG6_utils->get_octet_string_representation($project_values.state.extended.size_analyze)}){else} - {/if}</td>
<td>{$tx_nG6_utils->get_octet_string_representation($project_values.total_purgeable_size)}</td>
<td>
{foreach from=$project_values.users key=c_user_i item=user_values}
{$user_values.user_name} {if $user_values.right_level_label=="manager"} [{$user_values.email}, {$user_values.user_group_title}] {/if},
{/foreach}
</td>
</tr>
{/foreach}
</tbody>
<tfoot>
<tr>
......@@ -412,26 +394,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</div>
<div class="tab-pane fade" id="purge_demand_management">
<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>
</div>
</div>
<div>
<p>
Following table contains list of purge demand sent, here you can delete data or extend retention date.</br>
Delay exceeded is yes if mail sent more than {$ng6_purge_delay} days, so if you don't have answer from manager you can purge data.
</p>
</div>
<div class="tx-nG6-wait" id="data_table_purge_demand_wait">Please wait while processing ...</div>
<div class="alert alert-danger" id="purge_demand_error"></div>
<div id="purge_demand_list">
<table class="table table-striped table-bordered dataTable" id="data_table_demand">
<thead>
<tr>
<th><center><input type="checkbox" id="chk_purge_demand"></center></th>
<th><center><input type="checkbox" id="all_chk_demand"></center></th>
<th>Demand number</th>
<th>Project name</th>
<th>Purgeable size</th>
......@@ -442,24 +418,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</thead>
<tbody>
{foreach from=$ng6_purge_demands key=c_demand_id item=demand_values}
<tr id="tr_demand_{$c_demand_id}" >
<td><center><input type="checkbox" id="chk_demand_{$c_demand_id}" value="{$c_demand_id}" /></center></td>
<td>{$c_demand_id}</td>
<td><a href="index.php?id=3&tx_nG6_pi1[project_id]={$demand_values.project_id}">{$demand_values.project_name}</a> </td>
<td>{$tx_nG6_utils->get_octet_string_representation($demand_values.purge_size)}</td>
<td>{$demand_values.mail_sent_date|date_format:"%d/%m/%y"}</td>
<td>
{foreach from=$demand_values.users key=c_user_i item=user_values}
{$user_values.username}[{$user_values.user_group_title}],
{/foreach}
</td>
<td class="data-filter">{if $demand_values.delay_excedeed} Yes {else} No {/if}</td>
</tr>
{/foreach}
</tbody>
<tfoot>
<tr>
......@@ -474,7 +433,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</tfoot>
</table>
</div>
<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-->
</div>
......
......@@ -96,11 +96,11 @@ class tx_nG6_pi6 extends tslib_pibase {
$smarty->assign('distribution', $distribution);
$smarty->assign('ng6_admin_users', tx_nG6_db::get_ng6_admin_users() );
$this->projects_obsolete=tx_nG6_db::select_obsolete_list_retention_data_info();
$smarty->assign('ng6_purge_projects',$this->projects_obsolete);
$this->ng6_purge_demands=tx_nG6_db::get_purge_demand_list($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['delay_purge']);
$smarty->assign('ng6_purge_demands',$this->ng6_purge_demands);
//$this->projects_obsolete=tx_nG6_db::select_obsolete_list_retention_data_info();
//$smarty->assign('ng6_purge_projects',$this->projects_obsolete);
//$this->ng6_purge_demands=tx_nG6_db::get_purge_demand_list();
$smarty->assign('ng6_purge_delay',$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['delay_purge']);
//$smarty->assign('ng6_purge_demands',$this->ng6_purge_demands);
$txNG6Utils = new tx_nG6_utils;
$smarty->assign_by_ref('tx_nG6_utils', $txNG6Utils);
return $smarty->fetch('administration_view.tpl');
......@@ -126,18 +126,18 @@ Price for ###EXTENSION_SIZE### during ###EXTENSION_DURATION### is about ###EXTEN
Yours sincerely
nG6 team';
$project_name="";
foreach(explode(",", $project_ids) as $id){
$project_name="";
$txNG6Utils = new tx_nG6_utils;
foreach(explode(",", $project_ids) as $project_id){
#retrieve project data
$p=tx_nG6_db::select_a_project_retention_data_info($id);
$p=tx_nG6_db::select_a_project_retention_data_info($project_id);
#build email list of managers
$managers_email=Array();
$managers_name=Array();
$admin_email = Array();
$admin_name = Array();
foreach ( $p[$id]["users"] as $u ){
foreach ( $p[$project_id]["users"] as $u ){
if ( $u["right_level_label"] == "manager" ){
$managers_email[]=$u["email"];
$managers_name[]=$u["user_name"];
......@@ -151,55 +151,133 @@ nG6 team';
$email_warn="" ;
$purge_email_to="";
if ( count($managers_email) > 1 ) {
$email_warn="This project is associated to several manager (all recieved this email), please send only one answer per purge alert number.(".join(',', $managers_email).")\n";
$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";
$purge_email_to=join(',', $managers_email);
}elseif ( count($managers_email ==0)) {
$email_warn="This project isn't associated to manager, as administrator (".join(',', $admin_email).")of this project you recieved this purge alert \n";
$email_warn="As this project do not have managers, administrators recieved this alert (".join(',', $admin_email).")\n";
$purge_email_to=join(',', $admin_email);
}
//Retrieve purgeable information for email
$run_info="";
$run_list =split(",", $p[$id]["state"]["stored"]["run_ids"]);
if(count($run_list) != 0){
for( $i=0;$i<count($run_list);$i++){
$run = tx_nG6_db::select_run($run_list[$i]);
$run_name = $run["name"];
$run_info .= "$run_name ($run_list[$i]), ";
}
}else{
$run = tx_nG6_db::select_run($run_list);
$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"]);
$nb_run_purgeable = $p[$project_id]["state"]["stored"]["nb_run"]+ $p[$project_id]["state"]["extended"]["nb_run"];
$nb_analyse_purgeable = $p[$project_id]["state"]["stored"]["nb_analyze"]+ $p[$project_id]["state"]["extended"]["nb_analyze"];
//Retrieve run name
foreach($all_purgeable_runs as $run_id ){
$run = tx_nG6_db::select_run($run_id);
$run_name = $run["name"];
$run_info .= "$run_name ($run_list[$i]), ";
$run_info .= $run["name"]." ($run_id), ";
}
$analysis_list = $p[$id]["state"]["stored"]["analysis_ids"];
#Add purge demand to get id
$add_id = tx_nG6_db::add_purge_demand($user_id,$id,$p[$id]["total_purgeable_size"],$p[$id]["state"]["stored"]["run_ids"],$analysis_list,$managers_name);
$purge_demand_id = tx_nG6_db::add_purge_demand($user_id,$project_id,$p[$project_id]["total_purgeable_size"],$all_purgeable_runs,$all_purgeable_analysis,$managers_name);
#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###");
$replace=array($p[$id]["state"]["stored"]["nb_run"],$p[$id]["state"]["stored"]["nb_analyze"],$p[$id]["project_name"],$id,$add_id ,
$email_warn, $run_info , $analysis_list, $p[$id]["total_purgeable_size"] ,
$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"] ),
$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']);
$mail=str_replace($search, $replace, $template_mail);
$to = $purge_email_to;
$subject = '[nG6 purge] No '.$add_id.' - Project '.$p[$id]["project_name"];
$subject = '[nG6 purge] No '.$purge_demand_id.' - Project '.$p[$project_id]["project_name"];
$headers[] = 'From: '.$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['purge_email_from'];
#$headers[] = 'Cc: '.$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['purge_email_from'];
$headers[] = 'Reply-To: '.$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['purge_email_from'];
$headers[] = 'X-Mailer: PHP/' . phpversion();
#mail($to, $subject, $mail, implode("\r\n", $headers));
return $headers ;
//return $headers ;
}
return $mail;
}
function set_purge_demand_processed($demand_ids,$process, $value,$user,$pwd){
$all_demands=tx_nG6_db::get_purge_demand_from_id($demand_ids);
$all_runs=array();
$all_analyses=array();
foreach($all_demands as $res){
if ($res["state"] != "deleted")
{
$all_analyses=array_merge($all_analyses,explode(',',$res["analyze_ids"]));
$all_runs=array_merge($all_runs,explode(',',$res["run_ids"]));
}
}
//extend
if ($process == "extend"){
$date=$value;
tx_nG6_db::update_field('tx_nG6_run', $all_runs,
array("retention_date","data_state", "mail_sent_date","purge_demand_id"),
array($date,"extended","","NULL"),
array("purge_demand_id"));
tx_nG6_db::update_field('tx_nG6_analyze',$all_analyses,
array("retention_date","data_state", "mail_sent_date","purge_demand_id"),
array($date,"extended","","NULL"),
array("purge_demand_id"));
tx_nG6_db::update_field('tx_nG6_purge_demand',$demand_ids,
array("processed_date","demand_state"),
array($date,"extended"));
return("Done extend");
}else{ //delete
$data_folder=$value;
$date= time();
$all_runs_purged=array();
$all_analyses_purged=array();
$connexion=tx_nG6_utils::get_ssh_connection($user,$pwd);
if ( $connexion )
{
foreach ($all_runs as $run_id){
$r = tx_nG6_db::select_run($run_id);
if ($r["directory"] != "" ) {
$res = tx_nG6_utils::purge_files($connexion, $data_folder.$r["directory"]);
if ($res == 0){
$all_runs_purged[]=$run_id;
}else{
error_log("Error ".$res." while purging run id >".$run_id."< directory : >".$data_folder.$r["directory"]."< \n");
}
}
}
foreach ($all_analyses as $analyse_id){
$a = tx_nG6_db::select_analyse($analyse_id);
if ($a["directory"] != "" ) {
$res = tx_nG6_utils::purge_files($connexion, $data_folder.$a["directory"]);
if ($res == 0){
$all_analyses_purged[]=$analyse_id;
}else{
error_log("Error ".$res." while purging analyse id >".$analyse_id."< directory : >".$data_folder.$a["directory"]."< \n");
}
}
}
//purged_size = storage_size !!!
tx_nG6_db::update_field('tx_nG6_run', $all_runs_purged, array("purged_size","data_state", "purged_date", "storage_size"),
array("storage_size","purged",$date, 0),
array("purged_size"));
tx_nG6_db::update_field('tx_nG6_analyze',$all_analyses_purged, array("purged_size","data_state", "purged_date", "storage_size"),
array("storage_size","purged",$date, 0),
array("purged_size"));
if (count($all_runs_purged)==count($all_runs) and count($all_analyses_purged)==count($all_analyses)){
tx_nG6_db::update_field('tx_nG6_purge_demand',$demand_ids,
array("processed_date","demand_state"),
array($date,"deleted"));
return("Done delete, res : ".$res);
}else{
return("Error: not all runs or analyses were purged , please check unix permission (see apache logs).");
}
}else{
return("Error while ssh login.");
}
}
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/pi6/class.tx_nG6_pi6.php']) {
......
This diff is collapsed.
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