//error_reporting(-1);
//ini_set("display_errors","1");
@ini_set('log_errors','On'); // enable or disable php error logging (use 'On' or 'Off')
@ini_set('display_errors','Off'); // enable or disable public display of errors (use 'On' or 'Off')
@ini_set('error_log','/home/missmurettocomftp/public_html/NEW/logs/php-errors.log'); // path to server-writable log file
setlocale(LC_ALL, "it_IT");
$constants['SITE_BASEPATH']= realpath(dirname(__FILE__)."/../");
$constants['SITE_RELATIVE_INSTALL_DIR']= substr(realpath(dirname(__FILE__)."/../"),strlen($constants['SITE_BASEPATH']));
$constants['SITE_ABSOLUTE_INSTALL_DIR']= $constants['SITE_BASEPATH'].$constants['SITE_RELATIVE_INSTALL_DIR'];
if ( preg_match("/^\/([^\/]*\/){0,}([^\/]*)$/",$_SERVER["PHP_SELF"],$tmp_fnmatches) )
{
$tmp_fnmatches[1]=substr($_SERVER["PHP_SELF"],0,strlen($_SERVER["PHP_SELF"])-strlen($tmp_fnmatches[2]));
$tmp_fnpath=explode("/",$tmp_fnmatches[1]);
$constants['SITE_AREA']=$tmp_fnpath[count($tmp_fnpath) -2];
unset($tmp_fnpath[count($tmp_fnpath) -2]);
$tmp_fnmatches[1]=implode("/",$tmp_fnpath);
$constants['SITE_ABSOLUTE_URL']="http://".$_SERVER["SERVER_NAME"].$tmp_fnmatches[1];
$constants['SITE_RELATIVE_URL']=$tmp_fnmatches[1];
unset($tmp_fnmatches);
unset($tmp_fnpath);
}
switch($constants['SITE_AREA'])
{
case "admin": $constants['USER_SESSION_TIMEOUT']=20; break;
default: $constants['USER_SESSION_TIMEOUT']=50;
}
session_set_cookie_params(time() + $constants['USER_SESSION_TIMEOUT'] * 100,$constants['SITE_RELATIVE_URL'].$constants['SITE_AREA']."/");
if (isset($_COOKIE[session_name()])) setcookie(session_name(), $_COOKIE[session_name()], time() + $constants['USER_SESSION_TIMEOUT']* 100, $constants['SITE_RELATIVE_URL'].$constants['SITE_AREA']."/");
session_start();
if (!isset($_SESSION['results_per_page']))
{
$_SESSION['results_per_page']=10;
}
function createChallenge()
{
srand();
$challenge = "";
for ($i = 0; $i < 80; $i++) {
$challenge .= dechex(rand(0, 15));
}
return $challenge;
}
function RandomString($length=1)
{
if ($length < 1 ) return "";
$gen_rand="1234567890qpwoeirutylaksjdhfgmznxbcv";
$str_casuale="";
mt_srand((double)microtime() * 1000000);
for ($l=0; $l < $length; $l++ ) $str_casuale.=$gen_rand[mt_rand(0,strlen($gen_rand)-1)];
return $str_casuale;
}
function RandomNumber($length=1)
{
if ($length < 1 ) return "";
$gen_rand="123456789123456789";
$str_casuale="";
mt_srand((double)microtime() * 1000000);
for ($l=0; $l < $length; $l++ ) $str_casuale.=$gen_rand[mt_rand(0,strlen($gen_rand)-1)];
return $str_casuale;
}
function ACPrintError($string)
{
echo "
\n";
exit();
}
function ConnectToDBase()
{
global $connessione_generica;
if (!is_resource($connessione_generica) || get_resource_type($connessione_generica)!="mysql link" || !mysql_ping($connessione_generica))
{
if (is_resource($connessione_generica) && get_resource_type($connessione_generica)=="mysql link" ) mysql_close($connessione_generica);
$connessione_generica = mysql_connect("localhost","missmuretto01_wp","A1vXvQxRJxSD5sbGC2t2D9yjpzjcLO6PIahhEC7BdEbfncS70406aSSH0dhMi0B");
if (!is_resource($connessione_generica) ) ACPrintError("Errore imprevisto ConnectToDBase");
mysql_select_db("missmuretto01_wp",$connessione_generica);
mysql_set_charset("utf8",$connessione_generica);
}
}
function Authenticate($username="", $challenge="", $response="")
{
global $constants;
// AUTHENTICATION
if (preg_match("/^([a-zA-Z0-9]{1,16})$/", $username) && preg_match("/^([a-zA-Z0-9]{40})$/", $response) && preg_match("/^([a-zA-Z0-9]{80})$/", $challenge))
{
// verifico corrispondenza login<-> psw a database
// se ok, estraggo gia' le info dell'utente, tanto non mi costa nulla in piu'.
// IMPOSTO LA CONNESSIONE E FACCIO LA RICHIESTA
ConnectToDBase();
// VERIFICO CREDENZIALI
//On server: take hashed pw from database, then add salt (concatenate session_id string), then hash again
$query1="SELECT * from admins WHERE UserName='$username' AND STRCMP(SHA1(CONCAT('".$challenge."',UserPassword)), '".$response."')=0";
$res1 = mysql_query($query1);
if (!$res1) ACPrintError("Errore Auth1");
if (mysql_num_rows($res1)!=1)
{
// dati errati o assenti, azzero sessione e porto a pagina di login
Logout("Login e/o Password errati");
}
else
{
$_SESSION["username"] = $username;
$_SESSION["challenge"] = $challenge;
$_SESSION["response"] = $response;
$_SESSION["userData"] = mysql_fetch_assoc($res1);
unset($_SESSION["userData"]["UserPassword"]);
//AUTHORIZATION
// Bypassato. Non ci sono altre aree e l'admin ha sempre ragione.
//ACCOUNTING
//Bypassato. Non serve.
}
}
else
{
// tentato accesso fallito.
// azzero la sessione e riporto alla pagina di benvenuto.
Logout("Login e/o Password errati");
}
return true;
}
function is_Authenticated()
{
global $constants;
if (!isset($_SESSION["username"]) || !isset($_SESSION["challenge"]) || !isset($_SESSION["response"]) ) return false;
ConnectToDBase();
$query1="SELECT * from admins WHERE UserName='".$_SESSION["username"]."' AND STRCMP(SHA1(CONCAT('".$_SESSION["challenge"]."',UserPassword)), '".$_SESSION["response"]."')=0";
$res1 = mysql_query($query1);
if (!$res1) return false;
if (mysql_num_rows($res1)!=1) return false;
unset($_SESSION["userData"]);
$_SESSION["userData"] = mysql_fetch_assoc($res1);
unset($_SESSION["userData"]["UserPassword"]);
//AUTHORIZATION
// Bypassato. Non ci sono altre aree e l'admin ha sempre ragione.
return true;
/*
if ( isset ($_SESSION["userName"]) && $_SESSION["authenticated"]==true ) return true;
else return false;
*/
}
function Log_Error($function, $msg)
{
global $fp_log_error,$constants;
if ($fp_log_error ==0)
{
$fp_log_error=fopen(realpath(dirname(__FILE__)."/../")."/logs/error.log","a+");
}
$riga=strftime("%d/%m/%Y %T")." : Area ".$constants["SITE_AREA"]." : ".$function." : ".$msg."\n";
fwrite($fp_log_error,$riga,strlen($riga));
}
function Logout($motivo="")
{
global $constants;
if (isset($_COOKIE[session_name()])) setcookie(session_name(), $_COOKIE[session_name()], 0, $constants['SITE_RELATIVE_URL'].$constants['SITE_AREA']."/");
session_destroy();
if ($motivo!="") $querystring="?motivo=".$motivo;
header("Location:".$constants['SITE_ABSOLUTE_URL'].$constants['SITE_AREA']."/".$querystring);
exit();
}
function Logoff()
{
Authenticate();
//Accounting($user_data["username"],"OUT");
Logout("Logoff Completato - Arrivederci");
exit();
}
function check_email_mx($email2) {
$regexp="/^([a-z0-9]+([_\\.-][a-z0-9]+)*)@(([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,})$/i";
$regexp_simple="/^(.*)@(.*)$/i";
//if( (preg_match('/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/', $email2)) || (preg_match('/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/',$email2)) ) {
//$host = explode('@', $email2);
if (preg_match($regexp,$email2,$matches))
{
//preg_match($regexp_simple,$email2,$matches2);
//if(checkdnsrr($matches2, 'MX') ) return true;
return true;
}
else return false;
//if(checkdnsrr($host[1].'.', 'A') ) return true;
//if(checkdnsrr($host[1].'.', 'CNAME') ) return true;
//}
//return false;
}
function scaleImage($image,$scale)
{
$originalPhotoSize = getimagesize($image);
$width=$originalPhotoSize[0];
$height=$originalPhotoSize[1];
$newImageWidth = ceil($width * $scale);
$newImageHeight = ceil($height * $scale);
$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
//echo "width : $width , height : $height ";
//echo "newImageWidth : $newImageWidth , newImageHeight : $newImageHeight ";
//exit();
//$newImage = imagecreate($newImageWidth,$newImageHeight);
//echo "newImage:";
//print_r($newImage);
//echo "<<<<\n";
$ext = strtolower(substr(basename($image), strrpos(basename($image), ".") + 1));
$source = "";
/*
switch($ext)
{
case "jpg":
case "jpeg": $source = imagecreatefromjpeg($image); break;
case "png": $source = imagecreatefrompng($image); break;
case "gif": $source = imagecreatefromgif($image); break;
default: imagedestroy($newImage); imagedestroy($source); return $image;
}
*/
$source = imagecreatefromjpeg($image);
//echo "source:";
//print_r($source);
//echo "<<<<\n";
if (!imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height)) { echo "NON RESAMPLED\n"; return false; }
/*
switch($ext)
{
case "jpg":
case "jpeg": imagejpeg($newImage,$image,90); break;
case "png": imagepng($newImage,$image,0); break;
case "gif": imagegif($newImage,$image); break;
default: imagedestroy($newImage); imagedestroy($source); return $image;
}
*/
if (!imagejpeg($newImage,$image,90)) { /*echo "NON imagejpegato\n"; */ return false; }
if (!imagedestroy($newImage) || !imagedestroy($source)) { /* echo "NON imagedestroy\n"; */ return false; }
chmod($image, 0666);
//echo "finalmente OK";
//echo "MEM: ".memory_get_peak_usage(true)."\n";
return $image;
}
//area from src_image of width src_w and height src_h at position (src_x,src_y) and place it in a rectangular area of dst_image of width dst_w and height dst_h at position (dst_x,dst_y)
function cropImage($image, $from_x=0 , $from_y=0, $from_w=1, $from_h=1 )
{
$originalPhotoSize = getimagesize($image);
$newImage = imagecreatetruecolor($from_w,$from_h);
$ext = strtolower(substr(basename($image), strrpos(basename($image), ".") + 1));
$source = "";
/*
switch($ext)
{
case "jpg":
case "jpeg": $source = imagecreatefromjpeg($image); break;
case "png": $source = imagecreatefrompng($image); break;
case "gif": $source = imagecreatefromgif($image); break;
default: imagedestroy($newImage); imagedestroy($source); return $image;
}
*/
$source= imagecreatefromjpeg($image);
imagecopyresampled($newImage,$source,0,0,$from_x,$from_y,$from_w,$from_h,$from_w,$from_h);
/*
switch($ext)
{
case "jpg":
case "jpeg": imagejpeg($newImage,$image,90); break;
case "png": imagepng($newImage,$image,0); break;
case "gif": imagegif($newImage,$image); break;
default: imagedestroy($newImage); imagedestroy($source); return $image;
}
*/
imagejpeg($newImage,$image,90);
imagedestroy($newImage);
imagedestroy($source);
chmod($image, 0666);
return $image;
}
?>