File indexing completed on 2024-12-22 05:33:30

0001 <?php
0002 
0003 /**
0004  *  ocs-webserver
0005  *
0006  *  Copyright 2016 by pling GmbH.
0007  *
0008  *    This file is part of ocs-webserver.
0009  *
0010  *    This program is free software: you can redistribute it and/or modify
0011  *    it under the terms of the GNU Affero General Public License as
0012  *    published by the Free Software Foundation, either version 3 of the
0013  *    License, or (at your option) any later version.
0014  *
0015  *    This program is distributed in the hope that it will be useful,
0016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0018  *    GNU Affero General Public License for more details.
0019  *
0020  *    You should have received a copy of the GNU Affero General Public License
0021  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0022  **/
0023 class AdsController extends Local_Controller_Action_DomainSwitch
0024 {
0025 
0026     public function indexAction()
0027     {
0028         $this->_helper->layout->disableLayout();
0029 
0030         $file_id = $this->getParam('file_id');
0031         $file_type = $this->getParam('file_type');
0032         $file_name = $this->getParam('file_name');
0033         $file_size = $this->getParam('file_size');
0034         $projectId = $this->getParam('project_id');
0035         if ($this->hasParam('link_type')) {
0036             $linkType = $this->getParam('link_type');
0037         } else {
0038             $linkType = "download";
0039         }
0040 
0041         $this->view->link_type = $linkType;
0042 
0043         $memberId = $this->_authMember->member_id;
0044 
0045         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
0046             if (isset($file_id) && isset($projectId) && isset($memberId)) {
0047                 $memberDlHistory = new Default_Model_DbTable_MemberDownloadHistory();
0048                 $data = array(
0049                     'project_id' => $projectId,
0050                     'member_id'  => $memberId,
0051                     'file_id'    => $file_id,
0052                     'file_type'  => $file_type,
0053                     'file_name'  => $file_name,
0054                     'file_size'  => $file_size
0055                 );
0056                 $memberDlHistory->createRow($data)->save();
0057             }
0058 
0059             $modelProduct = new Default_Model_Project();
0060             $productInfo = $modelProduct->fetchProductInfo($projectId);
0061 
0062             //create ppload download hash: secret + collection_id + expire-timestamp
0063             $salt = PPLOAD_DOWNLOAD_SECRET;
0064             $collectionID = $productInfo->ppload_collection_id;
0065             $timestamp = time() + 3600; // one hour valid
0066             //20181009 ronald: change hash from MD5 to SHA512
0067             //$hash = md5($salt . $collectionID . $timestamp); // order isn't important at all... just do the same when verifying
0068             $hash = hash('sha512', $salt . $collectionID . $timestamp); // order isn't important at all... just do the same when verifying
0069             $url = PPLOAD_API_URI . 'files/download/id/' . $file_id . '/s/' . $hash . '/t/' . $timestamp . '/u/' . $memberId . '/' . $file_name;
0070             $url = Default_Model_PpLoad::createDownloadUrl($productInfo->ppload_collection_id,$file_name,array('id'=>$file_id, 'u'=>$memberId));
0071 
0072             if ($linkType == 'install') {
0073                 $helperCatXdgType = new Default_View_Helper_CatXdgType();
0074                 $xdgType = $helperCatXdgType->catXdgType($productInfo->project_category_id);
0075 
0076                 $url = 'ocs://install'
0077                        . '?url=' . urlencode($url)
0078                        . '&type=' . urlencode($xdgType)
0079                        . '&filename=' . urldecode($file_name);
0080             }
0081 
0082             $this->view->url = $url;
0083         }
0084 
0085     }
0086 
0087 }