diff --git a/application/modules/default/controllers/DlController.php b/application/modules/default/controllers/DlController.php index 570ee3717..3e158e68f 100755 --- a/application/modules/default/controllers/DlController.php +++ b/application/modules/default/controllers/DlController.php @@ -1,255 +1,249 @@ . **/ class DlController extends Local_Controller_Action_DomainSwitch { - + public function indexAction() { $this->_helper->layout->disableLayout(); - + $file_id = $this->getParam('file_id'); $file_type = $this->getParam('file_type'); $file_name = $this->getParam('file_name'); $file_size = $this->getParam('file_size'); $projectId = $this->getParam('project_id'); - if($this->hasParam('link_type')) { - $linkType = $this->getParam('link_type'); + if ($this->hasParam('link_type')) { + $linkType = $this->getParam('link_type'); } else { $linkType = "download"; } $isExternal = $this->getParam('is_external'); $externalLink = $this->getParam('external_link'); - + $hasTorrent = $this->getParam('has_torrent'); - + $modelProduct = new Default_Model_Project(); $productInfo = $modelProduct->fetchProductInfo($projectId); - + $collectionID = $productInfo->ppload_collection_id; $sModel = new Default_Model_Section(); $section = $sModel->fetchSectionForCategory($productInfo->project_category_id); $info = new Default_Model_Info(); $supporter = $info->getRandomSupporterForSection($section['section_id']); - + $this->view->section_id = $section['section_id']; $this->view->link_type = $linkType; $this->view->file_name = $file_name; $this->view->file_size = $file_size; $this->view->file_size_human = $this->humanFileSize($file_size); $this->view->project_title = $productInfo->title; $this->view->project_owner = $productInfo->username; $this->view->project_id = $projectId; $this->view->is_external = $isExternal; $this->view->external_link = $externalLink; $this->view->supporter = $supporter; - $this->view->has_torrent = ($hasTorrent=="1"); + $this->view->has_torrent = ($hasTorrent == "1"); $this->view->file_id = $file_id; - + $memberId = $this->_authMember->member_id; - if ($_SERVER['REQUEST_METHOD'] == 'POST') { - + if ($_SERVER['REQUEST_METHOD'] == 'POST') { /* //Log download try { $filesDl = new Default_Model_DbTable_PploadFilesDownloaded(); $id = $filesDl->getNewId(); $data = array('id' => $id, 'client_id' => PPLOAD_CLIENT_ID, 'owner_id' => $productInfo->member_id, 'collection_id' => $collectionID, 'file_id' => $file_id, 'downloaded_timestamp' => new Zend_Db_Expr ('Now()'), 'downloaded_ip' => $this->getRealIpAddr(), 'referer' => $this->getReferer()); if(!empty($memberId)) { $data['user_id'] = $memberId; } $data['source'] = 'OCS-Webserver'; $data['link_type'] = $linkType; $filesDl->createRow($data)->save(); } catch (Exception $exc) { //echo $exc->getTraceAsString(); $errorLog = Zend_Registry::get('logger'); $errorLog->err(__METHOD__ . ' - ' . $exc->getMessage() . ' ---------- ' . PHP_EOL); } */ - //create ppload download hash: secret + collection_id + expire-timestamp $salt = PPLOAD_DOWNLOAD_SECRET; - + $timestamp = time() + 3600; // one hour valid //20181009 ronald: change hash from MD5 to SHA512 //$hash = md5($salt . $collectionID . $timestamp); // order isn't important at all... just do the same when verifying - $hash = hash('sha512',$salt . $collectionID . $timestamp); // order isn't important at all... just do the same when verifying + $hash = hash('sha512', + $salt . $collectionID . $timestamp); // order isn't important at all... just do the same when verifying // handle cookie - $config = Zend_Registry::get('config'); + $config = Zend_Registry::get('config'); $cookieName = $config->settings->session->auth->anonymous; - $storedInCookie = isset($_COOKIE[$cookieName]) ? $_COOKIE[$cookieName] : NULL; - if(!$storedInCookie) - { - $remember_me_seconds = $config->settings->session->remember_me->cookie_lifetime; - $cookieExpire = time() + $remember_me_seconds; - $storedInCookie = $hash; - setcookie($cookieName, $hash, $cookieExpire, '/'); - } + $storedInCookie = isset($_COOKIE[$cookieName]) ? $_COOKIE[$cookieName] : null; + if (!$storedInCookie) { + $remember_me_seconds = $config->settings->session->remember_me->cookie_lifetime; + $cookieExpire = time() + $remember_me_seconds; + $storedInCookie = $hash; + setcookie($cookieName, $hash, $cookieExpire, '/'); + } $url = PPLOAD_API_URI . 'files/download/id/' . $file_id . '/s/' . $hash . '/t/' . $timestamp; - if(isset($memberId)) { + if (isset($memberId)) { $url .= '/u/' . $memberId; } - $url .= '/c/' . $storedInCookie; + $url .= '/c/' . $storedInCookie; $url .= '/lt/' . $linkType . '/' . $file_name; - - if($linkType == 'install') { + $session = new Zend_Session_Namespace(); + $payload = array('id'=>$file_id, 's'=>$hash, 't'=> $timestamp, 'u'=>$memberId, 'c'=>$storedInCookie, 'lt'=>$linkType, 'stfp'=>$session->stat_fp, 'stip'=>$session->stat_ipv6?$session->stat_ipv6:$session->stat_ipv4); + $jwt = Default_Model_Jwt::encodeFromArray($payload); + $url = PPLOAD_API_URI . 'files/download/j/'.$jwt.'/'.$file_name; + + if ($linkType == 'install') { $helperCatXdgType = new Default_View_Helper_CatXdgType(); $xdgType = $helperCatXdgType->catXdgType($productInfo->project_category_id); $url = 'ocs://install' - . '?url=' . urlencode($url) - . '&type=' . urlencode($xdgType) - . '&filename=' . urldecode($file_name); + . '?url=' . urlencode($url) + . '&type=' . urlencode($xdgType) + . '&filename=' . urldecode($file_name); } $this->view->url = $url; // save to member_download_history - if(isset($file_id) && isset($projectId)) { - - // $data = array('project_id' => $projectId, 'member_id' => $memberId,'anonymous_cookie'=>$storedInCookie, 'file_id' => $file_id, 'file_type' => $file_type, 'file_name' => $file_name, 'file_size' => $file_size,'downloaded_ip' => $this->getRealIpAddr()); + if (isset($file_id) && isset($projectId)) { + // $data = array('project_id' => $projectId, 'member_id' => $memberId,'anonymous_cookie'=>$storedInCookie, 'file_id' => $file_id, 'file_type' => $file_type, 'file_name' => $file_name, 'file_size' => $file_size,'downloaded_ip' => $this->getRealIpAddr()); - $server_info = ''; + $server_info = ''; - foreach ( $_SERVER as $key=>$value ) { - if ($value) { - $server_info = $server_info.$key.': '.$value.' '; - } + foreach ($_SERVER as $key => $value) { + if ($value) { + $server_info = $server_info . $key . ': ' . $value . ' '; + } } $data = array( 'project_id' => $projectId, 'member_id' => $memberId, 'anonymous_cookie' => $storedInCookie, 'file_id' => $file_id, 'file_type' => $file_type, 'file_name' => $file_name, 'file_size' => $file_size, 'downloaded_ip' => $this->getRealIpAddr(), 'HTTP_X_FORWARDED_FOR' => isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : null, 'HTTP_X_FORWARDED' => isset($_SERVER['HTTP_X_FORWARDED']) ? $_SERVER['HTTP_X_FORWARDED'] : null, 'HTTP_CLIENT_IP' => isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : null, 'HTTP_FORWARDED_FOR' => isset($_SERVER['HTTP_FORWARDED_FOR']) ? $_SERVER['HTTP_FORWARDED_FOR'] : null, 'HTTP_FORWARDED' => isset($_SERVER['HTTP_FORWARDED']) ? $_SERVER['HTTP_FORWARDED'] : null, 'REMOTE_ADDR' => $_SERVER['REMOTE_ADDR'], 'server_info' => $server_info ); $memberDlHistory = new Default_Model_DbTable_MemberDownloadHistory(); $memberDlHistory->createRow($data)->save(); } // anonymous dl save to member_download_fingerprint 17.07 temperately deactived /*if(isset($file_id) && isset($projectId) && !isset($memberId)) { $config = Zend_Registry::get('config'); $cookieName = $config->settings->session->auth->anonymous; $storedInCookie = isset($_COOKIE[$cookieName]) ? $_COOKIE[$cookieName] : NULL; if(!$storedInCookie) { $remember_me_seconds = $config->settings->session->remember_me->cookie_lifetime; $cookieExpire = time() + $remember_me_seconds; setcookie($cookieName, $hash, $cookieExpire, '/'); } $memberDlAnonymous = new Default_Model_DbTable_MemberDownloadAnonymous(); $data = array('project_id' => $projectId, 'user' => $_COOKIE[$cookieName], 'file_id' => $file_id); $memberDlAnonymous->createRow($data)->save(); }*/ } - + } + function humanFileSize($bytes) + { + if (!empty($bytes)) { + $size = round($bytes / 1048576, 2); + if ($size == 0.0) { + return '0.01 MB'; + } else { + return $size . ' MB'; + } + } else { + return null; + } } function getRealIpAddr() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { - $ip=$_SERVER['HTTP_CLIENT_IP']; - } - elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy - { - $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; - } - else + $ip = $_SERVER['HTTP_CLIENT_IP']; + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy { - $ip=$_SERVER['REMOTE_ADDR']; + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; + } else { + $ip = $_SERVER['REMOTE_ADDR']; } + return $ip; } function getReferer() { $referer = null; if (!empty($_SERVER['HTTP_REFERER'])) { $referer = $_SERVER['HTTP_REFERER']; } + return $referer; } - - function formatBytes($bytes, $precision = 2) { - $units = array('B', 'KB', 'MB', 'GB', 'TB'); - $bytes = max($bytes, 0); - $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); - $pow = min($pow, count($units) - 1); + function formatBytes($bytes, $precision = 2) + { + $units = array('B', 'KB', 'MB', 'GB', 'TB'); + + $bytes = max($bytes, 0); + $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); + $pow = min($pow, count($units) - 1); // Uncomment one of the following alternatives // $bytes /= pow(1024, $pow); - // $bytes /= (1 << (10 * $pow)); + // $bytes /= (1 << (10 * $pow)); - return round($bytes, $precision) . ' ' . $units[$pow]; - } - - function humanFileSize($bytes) { - if(!empty($bytes)) - { - $size = round($bytes / 1048576, 2); - if($size == 0.0) - { - return '0.01 MB'; - }else - { - return $size.' MB'; - } - } - else - { - return null; - } + return round($bytes, $precision) . ' ' . $units[$pow]; } - } \ No newline at end of file diff --git a/application/modules/default/models/Jwt.php b/application/modules/default/models/Jwt.php index a47d3a4ed..2270bf169 100644 --- a/application/modules/default/models/Jwt.php +++ b/application/modules/default/models/Jwt.php @@ -1,64 +1,71 @@ . * * Created: 10.10.2018 */ class Default_Model_Jwt { public static function encode($member_id) { $config = Zend_Registry::get('config')->settings->jwt; $member_data = self::getMemberData($member_id); $payload = self::buildPayload($member_data, $config); return JWT::encode($payload, $config->secret, $algo = 'HS256'); } private static function getMemberData($member_id) { $model = new Default_Model_Member(); return $model->fetchMemberData($member_id)->toArray(); } private static function buildPayload($member_data, $config) { $date = new DateTime(); $interval = DateInterval::createFromDateString($config->expire->cookie); $payload['exp'] = $date->add($interval)->getTimestamp(); $payload['vt'] = 4; //type=cookie_ltat $payload['user'] = $member_data['external_id']; $payload['hash'] = crc32($member_data['username'] . $member_data['mail'] . $member_data['password']); return $payload; } public static function decode($jwt, $verify = true) { $config = Zend_Registry::get('config')->settings->jwt; return JWT::decode($jwt, $config->secret, $verify); } + + public static function encodeFromArray(array $payload) + { + $config = Zend_Registry::get('config')->settings->jwt; + + return JWT::encode($payload, $config->secret, $algo = 'HS256'); + } } \ No newline at end of file diff --git a/application/modules/default/views/scripts/dl/index.phtml b/application/modules/default/views/scripts/dl/index.phtml index 65dbc5d85..6c8b4e276 100644 --- a/application/modules/default/views/scripts/dl/index.phtml +++ b/application/modules/default/views/scripts/dl/index.phtml @@ -1,491 +1,531 @@ . **/ $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); - + $fileName = $this->file_name; $lastIndex = strripos($fileName, '.'); $fileExt = ""; -if(!empty($lastIndex)) { - $fileExt = substr($fileName, $lastIndex+1); +if (!empty($lastIndex)) { + $fileExt = substr($fileName, $lastIndex + 1); } $fileExt = strtoupper($fileExt); $isAppimage = false; -if($fileExt == 'APPIMAGE') { +if ($fileExt == 'APPIMAGE') { $isAppimage = true; } $isExternal = ($this->is_external == "true"); $hasTorrent = ($this->has_torrent == "true" || $this->has_torrent == "1"); $link = ""; -if($isExternal) { +if ($isExternal) { $link = $this->external_link; -} +} ?> Download/Install - - + + - + - + + - - - + - - - + */ + + // Render all files into to the page + torrent.files.forEach(function (file) { + + console.log('Filename: ' + file.name); + console.log('Filepath: ' + file.path); + console.log('Filelength: ' + file.length); + + //file.appendTo('.log') + //log('(Blob URLs only work if the file is loaded from a server. "http//localhost" works. "file://" does not.)') + file.getBlobURL(function (err, url) { + if (err) { + $('#Form1').show(); + $('#Form1').submit(); + console.log('Error: ' + err + ', Url: ' + url); + return log(err.message); + } + //log('File done.') + //log('Download full file: ' + file.name + ''); + //window.location.assign(url); + + console.log('Fileurl: ' + url); + + var a = document.createElement("a"); + document.body.appendChild(a); + a.style = "display: none"; + a.href = url; + a.download = file.name; + a.click(); + window.URL.revokeObjectURL(url); + + //parent.jQuery.fancybox.close(); + }) + }) + } + + + function log(str) { + $('.log').innerHTML = str; + console.log(str); + } + }); + + + + -
- -
-
-
- +
+ +
+
+
+ Click button below to follow external link. - link_type == 'download') { ?> - Download prepared successfully, click the button below to start. + link_type == 'download') { ?> + Download prepared successfully, click the button below to start. - Installation prepared successfully, click the button below to start. - - -
-
-

project_title ?>

- - -
- - url.'">Please click here'; - echo ''; + Installation prepared successfully, click the button below to start. + - } else { - ?> - - - - +
+

project_title ?>

+ + +
+ + url.'">Please click here'; + echo ''; + + } else { + ?> + + + +
- link_type == 'download') { ?> - + link_type == 'download') { ?> + - -

*Install things with ocs-url or ocs-store.

+ +

*Install things with ocs-url or ocs-store.

- + For Appimages we recommend AppImageLauncher for system integration

"); } ?> - +

Download-Progress:

- + +
- 0 of file_size_human ?> | 0% + 0 of file_size_human ?> | 0%
Peers: 0 | 0/s
Start direct download
- +
- +
- -
- link_type == 'download') {?> - - link_type == 'install') { ?> - -

*Install things with ocs-url or ocs-store.

- link_type == 'download') { ?> - - - -

*Install things with ocs-url or ocs-store.

- - - ".$link."

"); - } - if($isAppimage) { - echo("

For Appimages we recommend AppImageLauncher for system integration

"); + + + link_type == 'download') { ?> + + link_type == 'install') { ?> + +

*Install things with ocs-url or ocs-store.

+ link_type == 'download') { ?> + + + +

*Install things with ocs-url or ocs-store.

+ - - - + + " . $link . "

"); + } + if ($isAppimage) { + echo("

For Appimages we recommend AppImageLauncher for system integration

"); } - ?> + ?> + + + -
- - -
+ -
+ +
+ +
This download is made possible by supporters like -
- - -
- - settings->client->default; - $baseurlStore = $config->baseurl_store; - $identity = Zend_Auth::getInstance()->getIdentity(); - ?> -

-

- - - Become a Supporter. -
- -

-
-
-
+
+ + +
+ + settings->client->default; + $baseurlStore = $config->baseurl_store; + $identity = Zend_Auth::getInstance()->getIdentity(); + ?> +

+

+ + + Become a Supporter. +
+ +

+
+
-
+
+
+ if (viewport()['width'] < 600 && "is_external ?>" === "true") { + document.body.style = 'height: 500px; background-color: #f8f9fa;'; + } + +