2015-11-30 21:30:54 +00:00
|
|
|
<?php
|
2018-03-19 22:24:44 +00:00
|
|
|
/*-------------------------------------------------------------------------------------------------------------| www.vdm.io |------/
|
|
|
|
____ ____ __ __ __
|
|
|
|
/\ _`\ /\ _`\ __ /\ \__ __/\ \ /\ \__
|
|
|
|
\ \,\L\_\ __ _ __ ___ ___ ___ ___ \ \ \/\ \/\_\ ____\ \ ,_\ _ __ /\_\ \ \____ __ __\ \ ,_\ ___ _ __
|
|
|
|
\/_\__ \ /'__`\/\`'__\/' __` __`\ / __`\ /' _ `\ \ \ \ \ \/\ \ /',__\\ \ \/ /\`'__\/\ \ \ '__`\/\ \/\ \\ \ \/ / __`\/\`'__\
|
|
|
|
/\ \L\ \/\ __/\ \ \/ /\ \/\ \/\ \/\ \L\ \/\ \/\ \ \ \ \_\ \ \ \/\__, `\\ \ \_\ \ \/ \ \ \ \ \L\ \ \ \_\ \\ \ \_/\ \L\ \ \ \/
|
|
|
|
\ `\____\ \____\\ \_\ \ \_\ \_\ \_\ \____/\ \_\ \_\ \ \____/\ \_\/\____/ \ \__\\ \_\ \ \_\ \_,__/\ \____/ \ \__\ \____/\ \_\
|
|
|
|
\/_____/\/____/ \/_/ \/_/\/_/\/_/\/___/ \/_/\/_/ \/___/ \/_/\/___/ \/__/ \/_/ \/_/\/___/ \/___/ \/__/\/___/ \/_/
|
|
|
|
|
|
|
|
/------------------------------------------------------------------------------------------------------------------------------------/
|
2015-11-30 21:30:54 +00:00
|
|
|
|
2018-03-03 16:43:27 +00:00
|
|
|
@version 2.0.x
|
2015-11-30 21:30:54 +00:00
|
|
|
@created 22nd October, 2015
|
|
|
|
@package Sermon Distributor
|
|
|
|
@subpackage download.php
|
|
|
|
@author Llewellyn van der Merwe <https://www.vdm.io/>
|
|
|
|
@copyright Copyright (C) 2015. All Rights Reserved
|
2015-12-23 12:44:56 +00:00
|
|
|
@license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
|
|
|
|
A sermon distributor that links to Dropbox.
|
|
|
|
|
2018-03-19 22:24:44 +00:00
|
|
|
/----------------------------------------------------------------------------------------------------------------------------------*/
|
2015-11-30 21:30:54 +00:00
|
|
|
|
|
|
|
// No direct access to this file
|
|
|
|
defined('_JEXEC') or die('Restricted access');
|
|
|
|
|
|
|
|
// import Joomla controllerform library
|
|
|
|
jimport('joomla.application.component.controller');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sermondistributor Download Controller
|
|
|
|
*/
|
|
|
|
class SermondistributorControllerDownload extends JControllerLegacy
|
|
|
|
{
|
|
|
|
|
|
|
|
public function __construct($config)
|
|
|
|
{
|
|
|
|
parent::__construct($config);
|
|
|
|
// load the tasks
|
|
|
|
$this->registerTask('file', 'download');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function download()
|
|
|
|
{
|
|
|
|
$jinput = JFactory::getApplication()->input;
|
|
|
|
// Check Token!
|
|
|
|
$token = JSession::getFormToken();
|
|
|
|
$call_token = $jinput->get('token', 0, 'ALNUM');
|
|
|
|
if($token == $call_token)
|
2018-03-19 22:24:44 +00:00
|
|
|
{
|
2015-11-30 21:30:54 +00:00
|
|
|
$task = $this->getTask();
|
|
|
|
switch($task)
|
2018-03-19 22:24:44 +00:00
|
|
|
{
|
2015-11-30 21:30:54 +00:00
|
|
|
case 'file':
|
2016-11-27 04:20:48 +00:00
|
|
|
$keys = SermondistributorHelper::base64_urldecode($jinput->get('key', NULL, 'STRING'));
|
|
|
|
$enUrl = SermondistributorHelper::base64_urldecode($jinput->get('link', NULL, 'STRING'));
|
2018-03-03 23:35:30 +00:00
|
|
|
$infoKey = SermondistributorHelper::base64_urldecode($jinput->get('info', NULL, 'STRING'));
|
2015-11-30 21:30:54 +00:00
|
|
|
$filename = $jinput->get('filename', NULL, 'CMD');
|
|
|
|
if((base64_encode(base64_decode($enUrl, true)) === $enUrl) && (base64_encode(base64_decode($keys, true)) === $keys) && $filename)
|
|
|
|
{
|
|
|
|
// we must first count this download
|
|
|
|
if (SermondistributorHelper::countDownload($keys,$filename))
|
|
|
|
{
|
2019-06-12 20:59:35 +00:00
|
|
|
$model = SermondistributorHelper::getModel('preachers', JPATH_COMPONENT_ADMINISTRATOR);
|
|
|
|
if (($result = $model->getSomeStuff($filename)) !== false)
|
|
|
|
{
|
|
|
|
// on success do some thing more (code here)
|
|
|
|
}
|
2016-11-02 00:18:26 +00:00
|
|
|
// get Site name
|
|
|
|
$config = JFactory::getConfig();
|
|
|
|
$vendor = $config->get('sitename');
|
|
|
|
$name = SermondistributorHelper::safeString($filename, 'Ww');
|
2015-11-30 21:30:54 +00:00
|
|
|
// Get local key
|
|
|
|
$localkey = SermondistributorHelper::getLocalKey();
|
2016-11-02 00:18:26 +00:00
|
|
|
$opener = new FOFEncryptAes($localkey, 128);
|
2016-11-27 04:20:48 +00:00
|
|
|
$link = rtrim($opener->decryptString($enUrl), "\0");
|
2018-03-03 23:35:30 +00:00
|
|
|
// check if we have local listing info
|
|
|
|
if (!$info = SermondistributorHelper::getFileInfo($infoKey))
|
|
|
|
{
|
|
|
|
$info = $this->getContentInfo($link);
|
|
|
|
}
|
2015-11-30 21:30:54 +00:00
|
|
|
// set headers
|
2016-07-22 10:09:14 +00:00
|
|
|
$app = JFactory::getApplication();
|
2016-11-02 00:18:26 +00:00
|
|
|
$app->setHeader('Accept-ranges', 'bytes', true);
|
|
|
|
$app->setHeader('Connection', 'keep-alive', true);
|
2016-07-22 10:09:14 +00:00
|
|
|
$app->setHeader('Content-Encoding', 'none', true);
|
|
|
|
$app->setHeader('Content-disposition', 'attachment; filename="'.$filename.'";', true);
|
2015-11-30 21:30:54 +00:00
|
|
|
if (isset($info['type']) && $info['type'])
|
|
|
|
{
|
2016-07-22 10:09:14 +00:00
|
|
|
$app->setHeader('Content-Type', $info['type'], true);
|
2015-11-30 21:30:54 +00:00
|
|
|
}
|
|
|
|
elseif (strpos($filename, '.mp3') !== false)
|
|
|
|
{
|
2016-07-22 10:09:14 +00:00
|
|
|
$app->setHeader('Content-Type', 'audio/mpeg', true);
|
2015-11-30 21:30:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-22 10:09:14 +00:00
|
|
|
$app->setHeader('Content-Type', 'application/octet-stream', true);
|
2015-11-30 21:30:54 +00:00
|
|
|
}
|
2016-07-22 10:09:14 +00:00
|
|
|
// important to have the file size.
|
2015-11-30 21:30:54 +00:00
|
|
|
if (isset($info['filesize']) && $info['filesize'])
|
|
|
|
{
|
2016-07-22 10:09:14 +00:00
|
|
|
$app->setHeader('Content-Length', (int) $info['filesize'], true);
|
2016-11-02 00:18:26 +00:00
|
|
|
$app->setHeader('Content-Size', (int) $info['filesize'], true);
|
2015-11-30 21:30:54 +00:00
|
|
|
}
|
2016-11-02 00:18:26 +00:00
|
|
|
$app->setHeader('Content-security-policy', 'referrer no-referrer', true);
|
|
|
|
$app->setHeader('Content-Name', '"'.$name.'"', true);
|
|
|
|
$app->setHeader('Content-Version', '1.0', true);
|
|
|
|
$app->setHeader('Content-Vendor', '"'.$vendor.'"', true);
|
2018-03-19 22:24:44 +00:00
|
|
|
$app->setHeader('Content-URL', '"'.JUri::getInstance().'"', true);
|
2016-07-22 10:09:14 +00:00
|
|
|
$app->setHeader('etag', md5($enUrl), true);
|
|
|
|
$app->setHeader('Pragma', 'public', true);
|
2018-03-19 22:24:44 +00:00
|
|
|
$app->setHeader('cache-control', 'must-revalidate, post-check=0, pre-check=0', true);
|
2016-07-22 10:09:14 +00:00
|
|
|
$app->setHeader('x-robots-tag', 'noindex, nofollow, noimageindex', true);
|
|
|
|
$app->setHeader('x-content-security-policy', 'referrer no-referrer', true);
|
|
|
|
$app->setHeader('x-webkit-csp', 'referrer no-referrer', true);
|
|
|
|
$app->setHeader('x-content-security-policy', 'referrer no-referrer', true);
|
|
|
|
// get the file
|
2018-03-19 22:24:44 +00:00
|
|
|
readfile($link);
|
2016-07-22 10:09:14 +00:00
|
|
|
$app->sendHeaders();
|
|
|
|
$app->close();
|
2015-11-30 21:30:54 +00:00
|
|
|
jexit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-11-27 04:20:48 +00:00
|
|
|
die('Restricted access');
|
2015-11-30 21:30:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getContentInfo($url)
|
|
|
|
{
|
|
|
|
if ($this->_isCurl())
|
|
|
|
{
|
|
|
|
$ch = curl_init($url);
|
|
|
|
curl_setopt($ch, CURLOPT_NOBODY, true);
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
curl_setopt($ch, CURLOPT_HEADER, true);
|
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
|
|
|
|
|
|
$data = curl_exec($ch);
|
|
|
|
curl_close($ch);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// then we try getheaders (this is slower)
|
|
|
|
stream_context_set_default( array('http' => array('method' => 'HEAD')));
|
|
|
|
$headers = get_headers($url);
|
|
|
|
if (SermondistributorHelper::checkArray($headers))
|
|
|
|
{
|
|
|
|
$data = implode("\n", $headers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// get the Content Length
|
|
|
|
if (preg_match('/Content-Length: (\d+)/', $data, $matches))
|
|
|
|
{
|
|
|
|
// Contains file size in bytes
|
2016-11-02 00:18:26 +00:00
|
|
|
$found['filesize'] = (int) $matches[1];
|
2015-11-30 21:30:54 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
// get the Content Type
|
|
|
|
if (preg_match_all('/Content-Type: (.+)/', $data, $matches))
|
|
|
|
{
|
|
|
|
foreach ($matches[1] as $match)
|
|
|
|
{
|
|
|
|
// not the html
|
|
|
|
if (strpos( $match, 'text/html') === false)
|
|
|
|
{
|
|
|
|
$found['type'] = $match;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// return found values
|
|
|
|
if (isset($found) && SermondistributorHelper::checkArray($found))
|
|
|
|
{
|
|
|
|
return $found;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function _isCurl()
|
|
|
|
{
|
|
|
|
return function_exists('curl_version');
|
|
|
|
}
|
|
|
|
}
|