Exemplo n.º 1
0
<?php

/**
 * Created by PhpStorm.
 * User: Harry
 * Date: 05/06/14
 * Time: 12:36
 */
header('Content-Type: text/html; charset=utf-8');
$projectRoot = $_SERVER['DOCUMENT_ROOT'] . '/Nestbox';
require_once $projectRoot . '/required.php';
if (isset($_SESSION['userId'])) {
    $userId = $_SESSION['userId'];
}
if (isset($_POST['var']) && !empty($_POST['var'])) {
    $elementManager = new ElementPdoManager();
    $refElementManager = new RefElementPdoManager();
    $userManager = new UserPdoManager();
    $refElementEmptyDirectory = $refElementManager->findOne(array('code' => '4002', 'state' => 1));
    if ($refElementEmptyDirectory instanceof RefElement) {
        $idRefElementEmptyDirectory = $refElementEmptyDirectory->getId();
    } else {
        return $refElementEmptyDirectory;
    }
    $refElementNotEmptyDirectory = $refElementManager->findOne(array('code' => '4003', 'state' => 1));
    if ($refElementNotEmptyDirectory instanceof RefElement) {
        $idRefElementNotEmptyDirectory = $refElementNotEmptyDirectory->getId();
    } else {
        return $refElementNotEmptyDirectory;
    }
    $element = $elementManager->findById($_GET['id']);
<?php

/**
 * Created by PhpStorm.
 * User: Crocell
 * Date: 04/06/14
 * Time: 23:53
 */
/** @var string $projectRoot chemin du projet dans le système de fichier */
$projectRoot = $_SERVER['DOCUMENT_ROOT'] . '/Nestbox';
require_once $projectRoot . '/required.php';
$elementPdoManager = new ElementPdoManager();
$rightPdoManager = new RightPdoManager();
//Chemin des fichiers de test
$path = 'D:\\Cours SUPINFO\\M1\\Projet Fin d\'annee\\Nestbox\\Fichiers de test/';
/**
 *  /Nestbox/
 *          IMG/
 *              Croquis Nesbtox.jpg
 *          code/
 *              js/
 *                 front/
 *                       js.txt
 *              css/
 *                  test.txt
 *
 *          suivi de projet.gdoc
 *          liens upload.gdoc
 *          Explorateur de fichier.gdoc
 *  /Nestbox - test/
 *	carte.gif
Exemplo n.º 3
0
<?php

/**
 * Created by PhpStorm.
 * User: Harry
 * Date: 05/06/14
 * Time: 12:36
 */
header('Content-Type: text/html; charset=utf-8');
$projectRoot = $_SERVER['DOCUMENT_ROOT'] . '/Nestbox';
require_once $projectRoot . '/required.php';
if (isset($_SESSION['userId'])) {
    $userId = $_SESSION['userId'];
}
if (isset($_POST['var']) && !empty($_POST['var'])) {
    $elementManager = new ElementPdoManager();
    $refElementManager = new RefElementPdoManager();
    $userManager = new UserPdoManager();
    $refElementEmptyDirectory = $refElementManager->findOne(array('code' => '4002', 'state' => 1));
    if ($refElementEmptyDirectory instanceof RefElement) {
        $idRefElementEmptyDirectory = $refElementEmptyDirectory->getId();
    } else {
        return $refElementEmptyDirectory;
    }
    $refElementNotEmptyDirectory = $refElementManager->findOne(array('code' => '4003', 'state' => 1));
    if ($refElementNotEmptyDirectory instanceof RefElement) {
        $idRefElementNotEmptyDirectory = $refElementNotEmptyDirectory->getId();
    } else {
        return $refElementNotEmptyDirectory;
    }
    $element = $elementManager->findById($_GET['id']);
Exemplo n.º 4
0
                <span class="icon-bar"></span>
            </button>
            <a style="height: 70px" class="navbar-brand" href="/Cubbyhole" target="_blank"><img id="nestboxLogo" src="/Nestbox/content/img/logo/logoNestbox.png"><strong>NESTBOX</strong></a>
        </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 
Exemplo n.º 5
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);
        }
    }
}
Exemplo n.º 6
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.');
    }
}
Exemplo n.º 7
0
/**
 * Permet de désactiver les droits d'un élément pour un user, gestion récursive pour les dossiers.
 * @author Harry Bellod & Alban Truc
 * @param string|MongoId $idElement  id de l'élément qu'on veut désactiver
 * @param string|MongoId $idUser  id de l'utilisateur concerné
 * @param string|MongoId $idOwner  id du propriétaire de l'élément
 * @since 15/06/2014
 * @return bool|array contenant un message d'erreur
 */
function disableShareRights($idElement, $idUser, $idOwner)
{
    $idElement = new MongoId($idElement);
    $idUser = new MongoId($idUser);
    $idOwner = new MongoId($idOwner);
    $elementManager = new ElementPdoManager();
    $refElementManager = new RefElementPdoManager();
    $rightPdoManager = new RightPdoManager();
    $element = $elementManager->findById($idElement);
    $refElement = $refElementManager->findById($element['idRefElement']);
    $idRefElement = $refElement['_id'];
    /** @var  $isFolder => bool, true si l'élément est bien un dossier, sinon false */
    $isFolder = isFolder($idRefElement);
    if (is_bool($isFolder) && $isFolder == TRUE) {
        $serverPath = $element['serverPath'] . $element['name'] . '/';
        //récupération des éléments contenus dans le dossier
        $seekElementsInFolder = array('state' => (int) 1, 'serverPath' => new MongoRegex("/^{$serverPath}/i"), 'idOwner' => $idOwner);
        //liste des éléments contenus dans le dossier
        $elementsInFolder = $elementManager->find($seekElementsInFolder);
        foreach ($elementsInFolder as $subElement) {
            $rightCriteria = array('state' => (int) 1, 'idElement' => new MongoId($subElement['_id']), 'idUser' => $idUser);
            $rightUpdate = array('$set' => array('state' => (int) 0));
            //pour chaque élément on désactive le droit qui lui était affecté
            $disableElementsInFolder = $rightPdoManager->update($rightCriteria, $rightUpdate);
            if (is_bool($disableElementsInFolder) && $disableElementsInFolder != TRUE) {
                return array('error' => 'No match found.');
            }
        }
    }
    $rightCriteria = array('state' => (int) 1, 'idElement' => $idElement, 'idUser' => $idUser);
    $rightUpdate = array('$set' => array('state' => (int) 0));
    //désactivation de l'élément parent
    $disableParent = $rightPdoManager->update($rightCriteria, $rightUpdate);
    if (is_bool($disableParent) && $disableParent != TRUE) {
        return array('error' => 'No match found.');
    }
}
Exemplo n.º 8
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;
        }
    }
}
Exemplo n.º 9
0
$projectRoot = $_SERVER['DOCUMENT_ROOT'] . '/Nestbox';
require_once $projectRoot . '/required.php';
/**
 * Created by PhpStorm.
 * User: Harry
 * Date: 12/06/14
 * Time: 19:42
 */
$path = 'C:/wamp/www/Nestbox/' . $userId . '/Tmp-' . $userId . '';
/* Si l'utilisateur décide d'uploader un element */
if (isset($_POST['destination']) && isset($_SESSION['file'])) {
    $returnMoveFS = moveFSElement($userId, '/Tmp-' . $userId . '/', $_SESSION['file']['name'], $_POST['destination'], $_SESSION['file']['name']);
    if ($returnMoveFS == TRUE) {
        $newPath = $projectRoot . '/' . $userId . $_POST['destination'];
        $elementManager = new ElementPdoManager();
        $refElementManager = new RefElementPdoManager();
        $hash = sha1_file($newPath . $_SESSION['file']['name']);
        $size = fileSize64($newPath . $_SESSION['file']['name']);
        $pathInfo = pathinfo($newPath . $_SESSION['file']['name']);
        $refElement = $refElementManager->findOne(array('extension' => '.' . $pathInfo['extension']));
        if (is_array($refElement) && array_key_exists('error', $refElement)) {
            echo "Extension not found";
        } else {
            $idRefElement = $refElement->getId();
            $criteria = array('downloadLink' => '', 'idOwner' => $userId, 'idRefElement' => $idRefElement, 'name' => $pathInfo['filename'], 'state' => 1, 'hash' => $hash, 'serverPath' => $_POST['destination'], 'size' => $size);
            $createElement = $elementManager->create($criteria);
            updateFolderStatus($_POST['destination'], $userId);
            echo "Your element has been successfully uploaded.";
        }
        unset($_SESSION['file']);