header('Content-Type: text/html; charset=utf-8');
session_start();
// === Get Client IP ========================================================================
function get_client_ip()
{
$ipaddress = '';
if ($_SERVER['HTTP_CLIENT_IP'])
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if($_SERVER['HTTP_X_FORWARDED_FOR'])
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if($_SERVER['HTTP_X_FORWARDED'])
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if($_SERVER['HTTP_FORWARDED_FOR'])
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if($_SERVER['HTTP_FORWARDED'])
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if($_SERVER['REMOTE_ADDR'])
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
function send_mail($to, $subject, $message, $from_email, $from_name)
{
if(!preg_match("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,6}^", $to)){
return false;
}
$headers = 'MIME-Version: 1.0' . PHP_EOL;
$headers .= 'From: '.$from_name.' <'.$from_email.'>' . PHP_EOL;
$headers .= 'Reply-To: '.$from_name.' <'.$from_email.'>' . PHP_EOL;
$headers .= 'Return-Path: '.$from_name.' <'.$from_email.'>' . PHP_EOL;
$headers .= 'Content-Type: text/html; charset=UTF-8'.PHP_EOL;
$headers .= 'Content-Transfer-Encoding: base64 '.PHP_EOL;
$headers .= 'X-Mailer: PHP/' . phpversion();
$subject = '=?UTF-8?B?'.base64_encode($subject).'?=';
$message = chunk_split(base64_encode($message));
if(@mail($to, $subject, $message, $headers)) {
return true;
}
else {
return false;
}
}
function fSendMail($tfile,$tIP,$tContent)
{
if($tContent == "")
{
$tContent = 'Eine Datei';
};
$companyWorkMail = "nyb@nyta.ch";
$message = '
Mitteilung von n-iceware.com
Hallo Administrator!
' .$tContent .' wurde heruntergeladen:
Datei : '.$tfile .'
IP-Adresse : '.$tIP .'
';
send_mail($companyWorkMail, "Ein Download (" .$tContent .") auf n-iceware.com", $message, "noreply@n-iceware.com", "n-iceware - Mitteilung");
}
// === Process Download =============================================================================
function makeDownload($file,$dir)
{
$size = filesize($dir.$file);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$ext = pathinfo($dir.$file, PATHINFO_EXTENSION);
If ($ext == 'exe') {$type = "application/octet-stream";} else {$type = finfo_file($finfo, "$dir.$file");};
If ($ext == 'zip') {$type = "application/zip";};
finfo_close($finfo);
header("Content-Type: $type"); // = Determine the kind for download
header("Content-length: $size"); // = Needed to update progressbar in application
header("Content-Disposition: attachment; filename=\"$file\"");
$DBServer = 'localhost';
$DBUser = 'web536';
$DBPass = 'gUgzuG7F!';
$DBName = 'nicewarecom';
$accessPHPsessionID = session_id();
$accessIP = get_client_ip();
$query = "INSERT INTO nw_download (downloadFile,downloadPHPsessionID,downloadIP,downloadEXT,downloadSize) VALUES ('$file', '$accessPHPsessionID','$accessIP','$ext','$size')";
$c = mysqli_connect($DBServer, $DBUser, $DBPass, $DBName);
$q = mysqli_real_escape_string(mysqli_query($c, $query));
readfile($dir.$file);
if($file == "Update-TinyHelper.zip" or $file == "Setup-TinyHelper.msi")
{
if($file == "Update-TinyHelper.zip")
{
fSendMail($file,$accessIP,'Ein Update');
} else {
fSendMail($file,$accessIP,'Ein Setup');
};
} else {
fSendMail($file,$accessIP,'');
};
}
$dir = '/home/www/web536/html/downloads/';
//$dir = '/home/www/web536/html/n-iceware-com/tinyhelper/';
if(!empty($_GET['file']) && !preg_match('=/=', $_GET['file']))
{
if(file_exists ($dir.$_GET['file']))
{
makeDownload($_GET['file'], $dir);
}
}
// Beispielaufruf:
// http://www.ihreDomain.de/download.php?file=dieDatei.zip
?>