Esempio n. 1
0
 public function fetchData()
 {
     if ($this->already_fetched) {
         return;
     }
     $this->already_fetched = true;
     try {
         if (!$this->customImportEnabled()) {
             if (in_array($this['source'], array("csv_upload", "extern"))) {
                 return;
             } elseif ($this['source'] === "database") {
                 $this->fetchDataFromDatabase();
                 return;
             } elseif ($this['source'] === "csv_weblink") {
                 $this->fetchDataFromWeblink();
                 return;
             } elseif ($this['source'] === "csv_studipfile") {
                 $output = $this->getCSVDataFromFile(get_upload_file_path($this['tabledata']['weblink']['file_id']), ";");
                 $headline = array_shift($output);
                 $this->createTable($headline, $output);
                 return;
             }
         } else {
             $this->getPlugin()->fetchData();
         }
     } catch (Exception $e) {
         PageLayout::postMessage(MessageBox::error(sprintf(_("Konnte Tabelle '%s' nicht mit Daten befüllen."), $this['name'])));
     }
 }
Esempio n. 2
0
 /**
  * Inhalte einer Datei
  *
  * @get /file/:file_id/content
  *
  * @see public/sendfile.php
  */
 public function getFileContent($file_id)
 {
     $file = $this->loadFile($file_id);
     if (!isset($file)) {
         $this->notFound("File not found");
     }
     if ($file->url) {
         $this->streamLinkedFile($file);
     } else {
         if (!file_exists($real_file = get_upload_file_path($file_id))) {
             $this->notFound();
         }
         TrackAccess($file_id, 'dokument');
         $this->lastModified($file->chdate);
         $this->sendFile($real_file, array('filename' => $file->getValue('filename')));
     }
 }
 function down()
 {
     global $UPLOAD_PATH;
     $db = DBManager::get();
     $result = $db->query('SELECT dokument_id FROM dokumente');
     foreach ($result as $row) {
         $document = $row['dokument_id'];
         $file_path = get_upload_file_path($document);
         if (is_file($file_path)) {
             rename($file_path, $UPLOAD_PATH . '/' . $document);
         }
     }
     for ($i = 0; $i <= 0xff; ++$i) {
         $directory = sprintf('%s/%02x', $UPLOAD_PATH, $i);
         if (is_dir($directory)) {
             rmdir($directory);
         }
     }
 }
Esempio n. 4
0
        $path_file = false;
        break;
        //download linked file
    //download linked file
    case 6:
        $path_file = getLinkPath($file_id);
        break;
        //we want to download a file attached to a system message (this mode performs perm checks)
    //we want to download a file attached to a system message (this mode performs perm checks)
    case 7:
        $path_file = get_upload_file_path($file_id);
        break;
        //we want to download from the regular upload-folder (this mode performs perm checks)
    //we want to download from the regular upload-folder (this mode performs perm checks)
    default:
        $path_file = get_upload_file_path($file_id);
        break;
}
//replace bad charakters to avoid problems when saving the file
$file_name = prepareFilename(basename(Request::get('file_name')));
if (Request::int('zip') && is_file($path_file)) {
    $tmp_id = md5(uniqid("suppe"));
    $zip_path_file = "{$TMP_PATH}/{$tmp_id}";
    $tmp_file_name = escapeshellcmd("{$TMP_PATH}/{$file_name}");
    @copy($path_file, $tmp_file_name);
    if (create_zip_from_file($tmp_file_name, "{$zip_path_file}.zip") === false) {
        @unlink($zip_path_file . '.zip');
        @unlink($tmp_file_name);
        throw new Exception(_("Fehler beim Erstellen des Zip-Archivs!"));
    } else {
        $file_name = $file_name . ".zip";
Esempio n. 5
0
 function routes(&$router)
 {
     $router->get('/documents/:range_id/folder(/:folder_id)', function ($range_id, $folder_id = null) use($router) {
         $folder_id = $folder_id ?: $range_id;
         if (!Document::isActivated($range_id)) {
             $router->halt(400, sprintf('Range %s has no documents', $range_id));
         }
         if (!Helper::UserHasAccessToRange($range_id)) {
             $router->halt(403, sprintf('User may not access range %s', $range_id));
         }
         if (!Document::folderBelongsToRange($range_id, $folder_id)) {
             $router->halt(404, sprintf('No folder %s for range %s', $folder_id, $range_id));
         }
         $folders = Document::loadFolders($folder_id);
         $documents = Document::loadFiles($folder_id, 'folder');
         if ($router->compact()) {
             $router->render(compact('folders', 'documents'));
             return;
         }
         $users = array();
         foreach ($folders as &$folder) {
             if (!isset($users[$folder['user_id']])) {
                 $users[$folder['user_id']] = reset($router->dispatch('get', '/user(/:user_id)', $folder['user_id']));
             }
         }
         foreach ($documents as &$document) {
             if (!isset($users[$document['user_id']])) {
                 $users[$document['user_id']] = reset($router->dispatch('get', '/user(/:user_id)', $document['user_id']));
             }
         }
         $router->render(compact('folders', 'documents', 'users'));
     });
     $router->get('/documents/:document_id', function ($document_id) use($router) {
         $document = new StudipDocument($document_id);
         if (!$document->checkAccess($GLOBALS['user']->id)) {
             $router->halt(403, sprintf('User may not access file %s', $document_id));
         }
         $document = Document::loadFiles($document_id);
         if ($router->compact()) {
             $router->render(compact('document'));
             return;
         }
         $user[$document['user_id']] = reset($router->dispatch('get', '/user(/:user_id)', $document['user_id']));
         $router->render(compact('document', 'user'));
     });
     // See public/sendfile.php
     $router->get('/documents/:document_id/download', function ($document_id) use($router) {
         $document = new StudipDocument($document_id);
         if (!$document->checkAccess($GLOBALS['user']->id)) {
             $router->halt(403, sprintf('User may not access file %s', $document_id));
         }
         $file = $path_file = get_upload_file_path($document_id);
         if (!file_exists($file)) {
             $router->halt(404, sprintf('File contents for file %s not found', $document_id));
         }
         header('Expires: Mon, 12 Dec 2001 08:00:00 GMT');
         header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
         if ($_SERVER['HTTPS'] == 'on') {
             header('Pragma: public');
             header('Cache-Control: private');
         } else {
             header('Pragma: no-cache');
             header('Cache-Control: no-store, no-cache, must-revalidate');
             // HTTP/1.1
         }
         header('Cache-Control: post-check=0, pre-check=0', false);
         header(sprintf('Content-Type: %s; name="%s"', get_mime_type($document->getValue('filename')), $document->getValue('filename')));
         header('Content-Description: File Transfer');
         header('Content-Transfer-Encoding: binary');
         header('Content-Length: ' . filesize($file));
         @readfile_chunked($path_file);
         TrackAccess($document_id, 'dokument');
         die;
     });
 }
Esempio n. 6
0
function delete_document($dokument_id, $delete_only_file = FALSE)
{
    $query = "SELECT url FROM dokumente WHERE dokument_id = ?";
    $statement = DBManager::get()->prepare($query);
    $statement->execute(array($dokument_id));
    $url = $statement->fetchColumn();

    if ($url !== false) {
        if (!$url) {   //Bei verlinkten Datein nicht nachsehen ob es Datei gibt!
            @unlink(get_upload_file_path($dokument_id));
            if ($delete_only_file){
                return TRUE;
            }
        }
    }

    // eintrag aus der Datenbank werfen
    $doc = new StudipDocument($dokument_id);
    return $doc->delete();
}
Esempio n. 7
0
 private function safeStore()
 {
     try {
         $result = $this->store();
     } catch (Exception $e) {
         $result = false;
     }
     if ($result === false) {
         @unlink(get_upload_file_path($this->getId()));
     }
     return $result !== false;
 }
Esempio n. 8
0
 public function delete_attachment_action()
 {
     CSRFProtection::verifyUnsafeRequest();
     $doc = StudipDocument::find(Request::option('document_id'));
     if ($doc && $doc->range_id == 'provisional' && $doc->description == Request::option('message_id')) {
         @unlink(get_upload_file_path($doc->id));
         $doc->delete();
     }
     $this->render_nothing();
 }
Esempio n. 9
0
 /**
  * Converts URLs in images so that the webserver can access them without proxy.
  * @param string $url of an image
  * @return string " src=\"".$converted_url."\""
  */
 protected function convertURL($url)
 {
     $convurl = $url;
     $url_elements = @parse_url($url);
     $url = $url_elements['path'] . '?' . $url_elements['query'];
     if (strpos(implode('#', $this->domains), $url_elements['host']) !== false) {
         if (strpos($url, 'dispatch.php/media_proxy?url=') !== false) {
             $targeturl = urldecode(substr($url, 4));
             try {
                 // is file in cache?
                 if (!($metadata = $this->media_proxy->getMetaData($targeturl))) {
                     $convurl = $targeturl;
                 } else {
                     $convurl = $this->config->getValue('MEDIA_CACHE_PATH') . '/' . md5($targeturl);
                 }
             } catch (Exception $e) {
                 $convurl = '';
             }
         } else {
             if (stripos($url, 'dispatch.php/document/download') !== false) {
                 if (preg_match('#([a-f0-9]{32})#', $url, $matches)) {
                     $convurl = DirectoryEntry::find($matches[1])->file->getStorageObject()->getPath();
                 }
             } else {
                 if (stripos($url, 'download') !== false || stripos($url, 'sendfile.php') !== false) {
                     //// get file id
                     if (preg_match('#([a-f0-9]{32})#', $url, $matches)) {
                         $document = new StudipDocument($matches[1]);
                         if ($document->checkAccess($GLOBALS['user']->id)) {
                             $convurl = get_upload_file_path($matches[1]);
                         } else {
                             $convurl = Assets::image_path('messagebox/exception.png');
                         }
                     }
                 }
             }
         }
     }
     return 'src="' . $convurl . '"';
 }
Esempio n. 10
0
 /**
  * @param $dokument_id
  * @return StudipMail provides fluent interface
  */
 function addStudipAttachment($dokument_id)
 {
     $doc = new StudipDocument($dokument_id);
     if (!$doc->isNew()) {
         $this->addFileAttachment(get_upload_file_path($doc->getId()), $doc->getValue('filename'));
     }
     return $this;
 }