예제 #1
0
        </div>
    </div><!-- /.container-fluid -->
</nav>

<div class="grouse">
    <div class="container">
        <div class="row wrapGrouse">
            <div class="col-md-12 header">
                <div class="">

                    <?php 
if (isset($_GET['token'])) {
    $elementManager = new ElementPdoManager();
    $userManager = new UserPdoManager();
    $refElementManager = new RefElementPdoManager();
    $element = $elementManager->findOne(array('downloadLink' => $_GET['token']));
    $user = $userManager->findById($element->getOwner());
    $refElement = $refElementManager->findById($element->getRefElement());
    ?>

                    <div id="elementInformations" class="col-md-6 elemInfo">
                        <h3 style="margin-top: 0">Element information:</h3>
                        <ul class="ulElem">
                            <li>Element name : <?php 
    echo $element->getName();
    ?>
</li>
                            <li>Extension : <?php 
    echo $refElement->getExtension();
    ?>
</li>
예제 #2
0
function shareWithAnonymous($idElement, $idOwner, $recipientEmail = '')
{
    $idElement = new MongoId($idElement);
    $idOwner = new MongoId($idOwner);
    $elementPdoManager = new ElementPdoManager();
    $elementCriteria = array('state' => (int) 1, '_id' => $idElement);
    $element = $elementPdoManager->findOne($elementCriteria);
    if ($element->getDownloadLink() == '') {
        /*
         * vérification que l'idOwner en param de la fonction est le même que celui de l'element, la gestion des partages
         * n'étant dans cette version qu'accessible au propriétaire de l'élément
         */
        if ($idOwner == $element->getOwner()) {
            //vérification que l'email indiquée appartient bien à un utilisateur inscrit
            $userCriteria = array('state' => (int) 1, 'email' => $recipientEmail);
            $userPdoManager = new UserPdoManager();
            $recipientUser = $userPdoManager->findOne($userCriteria);
            /*
             * Tentative de génération de lien de téléchargement anonyme pour un utilsateur existant.
             * L'interdire ici ne résoudra cependant que partiellement cet éventuel problème,
             * mais au moins on limite la permissivité.
             */
            if ($recipientUser instanceof User) {
                return array('error' => 'The email you entered belongs to one of our users, please use the \'share with a user\' functionality.');
            }
            $downloadLink = $elementPdoManager->generateGUID();
            $updateDownloadLink = array('$set' => array('downloadLink' => $downloadLink));
            $updateStatus = $elementPdoManager->update($elementCriteria, $updateDownloadLink);
            if (is_bool($updateStatus) && $updateStatus == TRUE) {
                return array('downloadLink' => $downloadLink);
            } else {
                return $updateStatus;
            }
        } else {
            return array('error' => 'You are not the owner of this element, you cannot share it.');
        }
    } else {
        return array('error', 'There is already a download link for this element.');
    }
}
예제 #3
0
/**
 * @todo vérification du ratio du propriétaire (suffisant ou non pour autoriser le téléchargement)
 * @todo support de lourds fichiers
 * @author Alban Truc
 * @param $token
 * @param int $downloadSpeed par défaut 100 KB/s
 * @since 15/06/2014
 * @return array
 */
function anonymousDownload($token, $downloadSpeed = 102400)
{
    if ($token == '') {
        return array('error' => 'Invalid link.');
    }
    $elementPdoManager = new ElementPdoManager();
    $elementCriteria = array('state' => (int) 1, 'downloadLink' => $token);
    $element = $elementPdoManager->findOne($elementCriteria);
    if (!$element instanceof Element) {
        return $element;
    }
    //récupère le code et l'extension de notre élément
    $refElementPdoManager = new RefElementPdoManager();
    $fieldsToReturn = array('code' => TRUE, 'extension' => TRUE);
    $refElement = $refElementPdoManager->findById($element->getRefElement(), $fieldsToReturn);
    if (!array_key_exists('error', $refElement)) {
        if (preg_match('/^4/', $refElement['code']) || preg_match('/^9/', $refElement['code'])) {
            // dossier ou non reconnu, pas d'extension à rajouter
            return array('error' => 'Donwload not available on folder or unrecognized element');
        }
    } else {
        return $refElement;
    }
    $filePath = PATH . $element->getOwner() . $element->getServerPath();
    $fileName = $element->getName() . $refElement['extension'];
    $fullFilePath = $filePath . $fileName;
    $fileSize = round($element->getSize() * 1024);
    set_time_limit(0);
    if ($fd = fopen($fullFilePath, 'r')) {
        header("Cache-Control: public");
        header("Content-Description: File Transfer");
        header("Content-Disposition: attachment; filename=\"{$fileName}\"");
        header("Content-Transfer-Encoding: binary");
        header("Content-length: {$fileSize}");
        $fileExtension = pathinfo($fullFilePath, PATHINFO_EXTENSION);
        //déterminer le Content-Type
        $ctype = getContentType($fileExtension);
        header("Content-Type: {$ctype}");
        $file = @fopen($fullFilePath, 'rb');
        if ($file) {
            while (!feof($file)) {
                print fread($file, 1024 * $downloadSpeed);
                flush();
                usleep(500);
                if (connection_status() != 0) {
                    @fclose($file);
                    die;
                }
            }
            @fclose($file);
        }
    }
}
예제 #4
0
/** Permet de vérifier si l'utilisateur possède les droits maximums dans le dossier courant
 * @author Harry Bellod
 * @param $serverPath | path actuel
 * @param $idUser | id de l'user connecté
 * @return bool | true si l'user à les droits maximums (écriture/lecture)
 */
function checkRightOnCurrentDirectory($serverPath, $idUser)
{
    $elementManager = new ElementPdoManager();
    $rightManager = new RightPdoManager();
    $refRightManager = new RefRightPdoManager();
    if ($serverPath != "/") {
        // on récupère le nom du dossier ou l'on se trouve
        $explode = explode("/", $serverPath);
        $currentDirectory = $explode[sizeof($explode) - 2];
        // on récupère son serverPath
        $pattern = "#" . $currentDirectory . "/#";
        $path = preg_replace($pattern, "", $serverPath, 1);
        $criteria = array('name' => $currentDirectory, 'serverPath' => $path, 'state' => 1);
        $element = $elementManager->findOne($criteria);
        $rightCriteria = array('idElement' => $element->getId(), 'idUser' => $idUser);
        $right = $rightManager->findOne($rightCriteria);
        $refRight = $refRightManager->findById($right->getRefRight());
        //si l'utilisateur n'a que les droits de lecture alors return false, sinon true
        if ($refRight->getCode() == '01') {
            return false;
        } else {
            return true;
        }
    }
}