// VERSIONE 2.3
error_reporting(501);
$controllochk=false;
$notifypm=true;
//info per log AG
$typeAG="- LOGAGMATRIX 1H logger name:";
$userip=$_SERVER['REMOTE_ADDR'];
$serverip=$userip;
$userts=date("Y-m-d\TH:i:sP");
$operationAG="delete";
$fileAG="";
$pathAG="";
$objidAG=uniqid();
$noteAG="";
$serviceip="multimedia-fe";
$md5AG="";
$delimAG=chr(12);
$hostnameAG=exec('hostname');
$filenameAG="MULTIMEDIA.".date("Y.m.d").".".$hostnameAG."_AVATAR"."."."0001";
$PATH_LOG_AG="/LOGAG";
//Path fisici e valori di default
$PATH_MEDIA="/media/fileroot";
// $PATH_LOG="/usr/local/apache-2.0.54/logs/logs_pm"; // mettere vuoto se non si vuole tenere un log
$PATH_DEL="/media/cancellati";
$URL_PMFOTO="http://muco.pm.local:8080/pm/multimediac6/setNumeroFoto.jsp";
$URL_PMAV="http://muco.pm.local:8080/pm/multimediac6/setAttributoAudioVideo.jsp";
$community="mu";
$profilo="f00";
$valore="";
$nickname="";
$mustcomp=true;
global $NOME_HOST;
$NOME_HOST="multimediatlantide.alice.it";
global $nickname;
// ######### Classificazione degli errori #########
$NOERR="200 OK";
// Errori nei parametri del form
$ERR_NONICK="401 Il campo nickname è vuoto";
$ERR_NOVALIDNICK="402 Il nickname inviato è troppo corto";
$ERR_NOVALIDTYPE="403 l'attribute_name inviato non è in un formato valido";
$ERR_NOVALIDVALUE="404 il campo attribute_value inviato non è in un formato valido";
// Errori nel checksum
$ERR_CHK="411 Non è stato inviata la stringa per il controllo MD5";
$ERR_MD5="412 Errore nella verifica del checksum del nickname";
// Errori nella comunicazione con il Profile Manager
$ERR_PM1="501 Errore di collegamento con il Profile Manager";
$ERR_PM2="502 Errore di risposta dal Profile Manager";
$ERR_PM3="503 Errore nell'esecuzione delle query sul Profile Manager";
// Errori nella cancellazione dei files
$ERR_NO_FILE="442 file non presente";
$ERR_FSUSERDIR="511 il nickname specificato non possiede una directory per i contenuti multimediali";
$ERR_FSBKDIR="512 Errore nella creazione della directory di backup";
$ERR_FSDEL="513 Errore nella cancellazione di uno o più files";
$errore=$NOERR;
// numero di estensioni differenti ( 0,x = immagini, 1,x = audio , 2,x = video )
global $NUMEXT;
$NUMEXT[0]=4;
$NUMEXT[1]=12;
$NUMEXT[2]=10;
// Estensioni permesse per i vari files ( 0,x = immagini, 1,x = audio , 2,x = video )
global $ESTENSIONI;
$ESTENSIONI[0][0]="jpg";
$ESTENSIONI[0][1]="jpeg";
$ESTENSIONI[0][2]="gif";
$ESTENSIONI[0][3]="png";
$ESTENSIONI[1][0]="aif";
$ESTENSIONI[1][1]="aifc";
$ESTENSIONI[1][2]="aiff";
$ESTENSIONI[1][3]="au";
$ESTENSIONI[1][4]="ra";
$ESTENSIONI[1][5]="ram";
$ESTENSIONI[1][6]="snd";
$ESTENSIONI[1][7]="wav";
$ESTENSIONI[1][8]="mp3";
$ESTENSIONI[1][9]="m3u";
$ESTENSIONI[1][10]="rm";
$ESTENSIONI[1][11]="rmm";
$ESTENSIONI[2][0]="m1v";
$ESTENSIONI[2][1]="mp2";
$ESTENSIONI[2][2]="mpa";
$ESTENSIONI[2][3]="mpe";
$ESTENSIONI[2][4]="mpeg";
$ESTENSIONI[2][5]="mpg";
$ESTENSIONI[2][6]="mov";
$ESTENSIONI[2][7]="qt";
$ESTENSIONI[2][8]="avi";
$ESTENSIONI[2][9]="3gp";
// NON MODIFICARE NULLA DA QUESTO PUNTO IN POI !!!!!
$today = getdate();
$data = $today['year'] . "-" . substr( "0" . $today['mon'] , -2) . "-" . substr( "0" . $today['mday'] , -2);
$ora = substr( "0" . $today['hours'] , -2) . "-" . substr( "0" . $today['minutes'] , -2) . "-" . substr( "0" . $today['seconds'] , -2);
$chk = urldecode($HTTP_GET_VARS['chk']);
$nickname = urldecode($HTTP_GET_VARS[nickname]);
if ($HTTP_GET_VARS[community] != "") $community = strtolower(urldecode($HTTP_GET_VARS[community]));
if (strtolower(urldecode($HTTP_GET_VARS['mustcomp'] == "no"))) $mustcomp = false;
if (strtolower(urldecode($HTTP_GET_VARS['notifypm'] == "no"))) $notifypm = false;
if (urldecode($HTTP_GET_VARS['attribute_name']) != "") $profilo = strtolower(urldecode($HTTP_GET_VARS['attribute_name']));
if (urldecode($HTTP_GET_VARS['attribute_value']) != "") $valore = strtolower(urldecode($HTTP_GET_VARS['attribute_value']));
$path="";
$path2="";
// ########## Verifica dati inseriti ##########
// Nel caso sia stato popolato il campo attribute_valore lo uso per recuperare nickname e profilo
if ($valore != "") {
$filename = substr(strrchr($valore , "/") , 1);
$profilo = substr(strrchr($filename , ",") , 1 , 3);
$nickname = substr($filename , 0 , strpos($filename , ","));
if ($nickname == "" || $profilo == ""){
$errore = $ERR_NOVALIDVALUE;
}
}
// Verifica Nickname non nullo e di lunghezza >= 2
If ($errore == $NOERR){
if($nickname == ""){
$errore = $ERR_NONICK;
} elseif(strlen($nickname)<2){
$errore = $ERR_NOVALIDNICK;
}
}
// Verifica del campo attribute name
if ($errore == $NOERR) {
if(strlen($profilo)==3 && ($profilo=="all" || ((substr($profilo,0,1)=="f" || substr($profilo,0,1)=="a" || substr($profilo,0,1)=="v") && is_numeric(substr($profilo,-2))))){
// Profilo a posto
} else $errore = $ERR_NOVALIDTYPE;
}
// Controllo del checksum MD5 del nickname
if ($errore == $NOERR && $controllochk) {
if($chk == ""){
$errore=$ERR_CHK; // decommentare in seguito
}else{
$salt=substr($chk,0,8);
$contr= (md5($nickname.$salt,false));
if ($salt.$contr != $chk) $errore=$ERR_MD5;
}
}
// Controllo che il nickname indicato abbia una cartella di contenuti e creo la cartella di backup
if ($errore == $NOERR){
$path = $PATH_MEDIA . "/" . $community . "/" . $nickname{0} . "/" . substr($nickname , -2) . "/" . $nickname;
$pathAG="$path/";
$path2 = "";
if (is_dir($path)) {
// Se richiesto preparo la cartella per il backup dei files
//if($PATH_DEL != "") {
//if(!is_dir("$PATH_DEL/$data")) mkdir("$PATH_DEL/$data", 0777);
//if(!is_dir("$PATH_DEL/$data/$ora")) mkdir("$PATH_DEL/$data/$ora", 0777);
//if(!is_dir("$PATH_DEL/$data/$ora/$nickname")) mkdir("$PATH_DEL/$data/$ora/$nickname", 0777);
//if (!is_dir("$PATH_DEL/$data/$ora/$nickname")){
// $errore = $ERR_FSBKDIR;
//} else {
// $path2 = "$PATH_DEL/$data/$ora/$nickname";
//}
//}
} else {
$errore = $ERR_FSUSERDIR;
}
}
// Procedo a spostare o cancellare i files
if ($errore == $NOERR){
$contatore = 0;
if ($profilo!="all"){
//scrivo il log AG
$fileAG=exec("ls $path/$nickname,$profilo.???", $output, $retval);
//prendo lo uniqid della foto
$objidAG = getObjid("$path/$nickname,$profilo.html");
if ($retval == 0)
{
$md5AG=md5_file($fileAG);
$fileAG=explode("/", $fileAG);
$noteAG="http://$NOME_HOST/contenuti/$fileAG[7]";
$recordAG=$typeAG.$delimAG.$userip.$delimAG.$userts.$delimAG.$nickname.$delimAG.$operationAG.$delimAG.$fileAG[7].$delimAG.$pathAG.$delimAG.$objidAG.$delimAG.$noteAG.$delimAG.$serviceip;
//logAG per datacenter Pomezia
//error_log("$recordAG\n", 3, "$PATH_LOG_AG/$filenameAG");
//logAG per datacenter Rozzano
$ret_sys = syslog(LOG_INFO, "$recordAG\n");
//if ($ret_sys)
//{
// print "scrittura su syslog: ok
";
//}
}
else
{
//imposto l' errore
$errore = $ERR_NO_FILE;
}
$contatore = $contatore + process_content($path , $path2 , "$nickname," . $profilo);
} else {
for ($i=0; $i<=5; $i++) {
//scrivo il log AG
$fileAG=exec("ls $path/$nickname,f0${i}.???", $output, $retval);
//prendo lo uniqid della foto
$objidAG = getObjid("$path/$nickname,f0${i}.html");
if ($retval == 0)
{
$md5AG=md5_file($fileAG);
$fileAG=explode("/", $fileAG);
$noteAG="http://$NOME_HOST/contenuti/$fileAG[7]";
$recordAG=$typeAG.$delimAG.$userip.$delimAG.$userts.$delimAG.$nickname.$delimAG.$operationAG.$delimAG.$fileAG[7].$delimAG.$pathAG.$delimAG.$objidAG.$delimAG.$noteAG.$delimAG.$serviceip;
//logAG per datacenter Pomezia
//error_log("$recordAG\n", 3, "$PATH_LOG_AG/$filenameAG");
//logAG per datacenter Rozzano
$ret_sys = syslog(LOG_INFO, "$recordAG\n");
//if ($ret_sys)
//{
// print "scrittura su syslog: ok
";
//}
}
$contatore = $contatore + process_content($path , $path2 , "$nickname,f0${i}");
}
//$contatore = $contatore + process_content($path , $path2 , "$nickname,f00");
//$contatore = $contatore + process_content($path , $path2 , "$nickname,f01");
//$contatore = $contatore + process_content($path , $path2 , "$nickname,f02");
//$contatore = $contatore + process_content($path , $path2 , "$nickname,f03");
//$contatore = $contatore + process_content($path , $path2 , "$nickname,f04");
//$contatore = $contatore + process_content($path , $path2 , "$nickname,f05");
$contatore = $contatore + process_content($path , $path2 , "$nickname,a00");
$contatore = $contatore + process_content($path , $path2 , "$nickname,v00");
}
if ($contatore < 0) {
$errore = $ERR_FS;
} else {
rmdir($path); //cancello la directory vuota
if($mustcomp) compatta_foto("$path/$nickname,");
}
}
// comunicazione con il profile manager
if ($errore == $NOERR && $notifypm){
#bug: viene notificato al PM solo il #foto e non i contenuti audio/video
if ($profilo == "all")
{
$tipofile = 0;
}
else
{
$tipofile= get_type(substr($profilo , -3 , 1 ));
}
$nick=urlencode($nickname);
$community=strtoupper($community);
//echo "DEBUG: tipofile: $tipofile\n";
if($tipofile == 0){ //foto
$numfoto=conta_foto("$path/$nickname,");
//workaround per il pm
if ($profilo == 'all')
{
$md5AG = "all";
$objidAG = "all";
}
//encodo i parametri per il pm
$userts = urlencode($userts);
error_log("DEBUG: call url: $URL_PMFOTO?nickname=$nick&comunita=$community&numerofoto=$numfoto&userip=$userip&userts=$userts&serviceip=$serviceip&md5=$md5AG&action=$operationAG&serverip=$serverip&uniqid=$objidAG
");
$sFile = file_get_contents("$URL_PMFOTO?nickname=$nick&comunita=$community&numerofoto=$numfoto&userip=$userip&userts=$userts&serviceip=$serviceip&md5=$md5AG&action=$operationAG&serverip=$serverip&uniqid=$objidAG");
error_log("DEBUG: response from PM: $sFile
");
}else{ //audio o video
$filename = urlencode("/contenuti/$nickname,$profilo.mp3");
if($tipofile == 1){
$nomeattributo="audio";
}else{
$nomeattributo="video";
}
$sFile = file_get_contents("$URL_PMAV?nickname=$nick&comunita=$community&nomeattributo=$nomeattributo&valoreattributo=$filename&cmd=delete");
error_log("$URL_PMAV?nickname=$nick&comunita=$community&nomeattributo=$nomeattributo&valoreattributo=$filename&cmd=delete
");
}
if($sFile){
if(strlen($sFile)>2){
if(substr($sFile,0,3)!="200") $errore = $ERR_PM3;
}else{
$errore = $ERR_PM2;
}
}else{
$errore = $ERR_PM1;
}
}
// Stampa a video del risultato dell'operazione
//if ($errore != $NOERR){
error_log("DELETE: ".$nickname." ".$errore);
// }
echo $errore;
exit;
// Funzione per lo spostamento di un contenuto
function process_content($path1 , $path2 , $fileprefix) {
global $NUMEXT;
global $ESTENSIONI;
$pcont = 0;
$tipofile= get_type(substr($fileprefix , -3 , 1 ));
$pcont = $pcont + process_file($path1 , $path2 , "$fileprefix.html");
for ($ne = 0; $ne < $NUMEXT[$tipofile]; $ne++ ) {
$pcont = $pcont + process_file($path1 , $path2 , "$fileprefix.". $ESTENSIONI[$tipofile][$ne]);
}
if ($tipofile==0){
$pcont = $pcont + process_file($path1 , $path2 , substr_replace($fileprefix , "i" , -3 , 1) . ".jpg");
$pcont = $pcont + process_file($path1 , $path2 , substr_replace($fileprefix , "t" , -3 , 1) . ".jpg");
$pcont = $pcont + process_file($path1 , $path2 , substr_replace($fileprefix , "c" , -3 , 1) . ".jpg");
$pcont = $pcont + process_file($path1 , $path2 , substr_replace($fileprefix , "n" , -3 , 1) . ".jpg");
$pcont = $pcont + process_file($path1 , $path2 , substr_replace($fileprefix , "b" , -3 , 1) . ".jpg");
$pcont = $pcont + process_file($path1 , $path2 , substr_replace($fileprefix , "d" , -3 , 1) . ".jpg");
$pcont = $pcont + process_file($path1 , $path2 , substr_replace($fileprefix , "e" , -3 , 1) . ".jpg");
$pcont = $pcont + process_file($path1 , $path2 , substr_replace($fileprefix , "g" , -3 , 1) . ".jpg");
$pcont = $pcont + process_file($path1 , $path2 , substr_replace($fileprefix , "o" , -3 , 1) . ".jpg");
}
return $pcont;
}
// Funzione per lo spostamento dei singoli files
function process_file($p1,$p2,$fn) {
if ( is_file( "$p1/$fn" )) {
if(is_dir($p2)) copy("$p1/$fn" , "$p2/$fn");
unlink( "$p1/$fn" );
if ( is_file( "$p1/$fn" )) {
return -999;
} else {
return 1;
}
}else {
return 0;
}
}
// funzione per la "compattazione" delle foto
function compatta_foto($uri) {
$maxfoto = 6;
$firstempty = 0;
global $NUMEXT;
global $ESTENSIONI;
global $NOME_HOST;
global $nickname;
for ($co=0; $co<($maxfoto); $co++) {
if (is_file($uri."f0".$co.".html")){
if ($firstempty < $co){ //sposta
unlink($uri."f0".$co.".html");
for ($ne = 0; $ne < $NUMEXT[0]; $ne++ ) {
if(is_file($uri."f0".$co.".".$ESTENSIONI[0][$ne])){
rename($uri."f0".$co.".".$ESTENSIONI[0][$ne],$uri."f0".$firstempty.".".$ESTENSIONI[0][$ne]);
make_html($uri."f0".$firstempty.".html","http://$NOME_HOST/contenuti/$nickname,f0$firstempty.".$ESTENSIONI[0][$ne]);
}
}
if(is_file($uri."i0".$co.".jpg")) rename($uri."i0".$co.".jpg",$uri."i0".$firstempty.".jpg");
if(is_file($uri."t0".$co.".jpg")) rename($uri."t0".$co.".jpg",$uri."t0".$firstempty.".jpg");
if(is_file($uri."c0".$co.".jpg")) rename($uri."c0".$co.".jpg",$uri."c0".$firstempty.".jpg");
if(is_file($uri."n0".$co.".jpg")) rename($uri."n0".$co.".jpg",$uri."n0".$firstempty.".jpg");
if(is_file($uri."b0".$co.".jpg")) rename($uri."b0".$co.".jpg",$uri."b0".$firstempty.".jpg");
if(is_file($uri."d0".$co.".jpg")) rename($uri."d0".$co.".jpg",$uri."d0".$firstempty.".jpg");
if(is_file($uri."e0".$co.".jpg")) rename($uri."e0".$co.".jpg",$uri."e0".$firstempty.".jpg");
if(is_file($uri."g0".$co.".jpg")) rename($uri."g0".$co.".jpg",$uri."g0".$firstempty.".jpg");
if(is_file($uri."o0".$co.".jpg")) rename($uri."o0".$co.".jpg",$uri."o0".$firstempty.".jpg");
}
$firstempty++;
}
}
return true;
}
//funzione per creare i files html di reindirizzamento
function make_html($file,$url){
$fileout=fopen ($file ,"w");
if($fileout) {
fwrite($fileout,"\n");
fwrite($fileout,"