Ejemplo n.º 1
0
 public static function getPresentations()
 {
     $presentations = array();
     $list = \OC_FileCache::searchByMime('application', 'zip');
     foreach ($list as $l) {
         $info = pathinfo($l);
         $size = \OC_Filesystem::filesize($l);
         $mtime = \OC_Filesystem::filemtime($l);
         $entry = array('url' => $l, 'name' => $info['filename'], 'size' => $size, 'mtime' => $mtime);
         $presentations[] = $entry;
     }
     return $presentations;
 }
 public function preCopy($path1, $path2)
 {
     return OC_Filesystem::filesize($path1) < $this->getFreeSpace() or $this->getFreeSpace() == 0;
 }
Ejemplo n.º 3
0
 /**
  * checks if the selected files are within the size constraint. If not, outputs an error page.
  *
  * @param dir   $dir
  * @param files $files
  */
 static function validateZipDownload($dir, $files)
 {
     if (!OC_Config::getValue('allowZipDownload', true)) {
         $l = OC_L10N::get('files');
         header("HTTP/1.0 409 Conflict");
         $tmpl = new OC_Template('', 'error', 'user');
         $errors = array(array('error' => $l->t('ZIP download is turned off.'), 'hint' => $l->t('Files need to be downloaded one by one.') . '<br/><a href="javascript:history.back()">' . $l->t('Back to Files') . '</a>'));
         $tmpl->assign('errors', $errors);
         $tmpl->printPage();
         exit;
     }
     $zipLimit = OC_Config::getValue('maxZipInputSize', OC_Helper::computerFileSize('800 MB'));
     if ($zipLimit > 0) {
         $totalsize = 0;
         if (is_array($files)) {
             foreach ($files as $file) {
                 $totalsize += OC_Filesystem::filesize($dir . '/' . $file);
             }
         } else {
             $totalsize += OC_Filesystem::filesize($dir . '/' . $files);
         }
         if ($totalsize > $zipLimit) {
             $l = OC_L10N::get('files');
             header("HTTP/1.0 409 Conflict");
             $tmpl = new OC_Template('', 'error', 'user');
             $errors = array(array('error' => $l->t('Selected files too large to generate zip file.'), 'hint' => 'Download the files in smaller chunks, seperately or kindly ask your administrator.<br/><a href="javascript:history.back()">' . $l->t('Back to Files') . '</a>'));
             $tmpl->assign('errors', $errors);
             $tmpl->printPage();
             exit;
         }
     }
 }
        OC_JSON::error(array("data" => array("message" => $errors[$error])));
        exit;
    }
}
$files = $_FILES['files'];
$dir = $_POST['dir'];
$dir .= '/';
$error = '';
$totalSize = 0;
foreach ($files['size'] as $size) {
    $totalSize += $size;
}
if ($totalSize > OC_Filesystem::free_space('/')) {
    OC_JSON::error(array("data" => array("message" => "Not enough space available")));
    exit;
}
$result = array();
if (strpos($dir, '..') === false) {
    $fileCount = count($files['name']);
    for ($i = 0; $i < $fileCount; $i++) {
        $target = stripslashes($dir) . $files['name'][$i];
        if (OC_Filesystem::fromUploadedFile($files['tmp_name'][$i], $target)) {
            $result[] = array("status" => "success", 'mime' => OC_Filesystem::getMimeType($target), 'size' => OC_Filesystem::filesize($target), 'name' => $files['name'][$i]);
        }
    }
    OC_JSON::encodedPrint($result);
    exit;
} else {
    $error = 'invalid dir';
}
OC_JSON::error(array('data' => array('error' => $error, "file" => $fileName)));
Ejemplo n.º 5
0
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*
*/
// Init owncloud
// Check if we are a user
OCP\User::checkLoggedIn();
$filename = $_GET["file"];
if (!OC_Filesystem::file_exists($filename)) {
    header("HTTP/1.0 404 Not Found");
    $tmpl = new OCP\Template('', '404', 'guest');
    $tmpl->assign('file', $filename);
    $tmpl->printPage();
    exit;
}
$ftype = OC_Filesystem::getMimeType($filename);
header('Content-Type:' . $ftype);
header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
OCP\Response::disableCaching();
header('Content-Length: ' . OC_Filesystem::filesize($filename));
@ob_end_clean();
OC_Filesystem::readfile($filename);
        $breadcrumbNav->assign("baseURL", OC_Helper::linkTo("files_sharing", "get.php") . "?token=" . $token . "&path=");
        $list = new OC_Template("files", "part.list", "");
        $list->assign("files", $files);
        $list->assign("baseURL", OC_Helper::linkTo("files_sharing", "get.php") . "?token=" . $token . "&path=");
        $list->assign("downloadURL", OC_Helper::linkTo("files_sharing", "get.php") . "?token=" . $token . "&path=");
        $list->assign("readonly", true);
        $tmpl = new OC_Template("files", "index", "user");
        $tmpl->assign("fileList", $list->fetchPage());
        $tmpl->assign("breadcrumb", $breadcrumbNav->fetchPage());
        $tmpl->assign("readonly", true);
        $tmpl->printPage();
    } else {
        //get time mimetype and set the headers
        $mimetype = OC_Filesystem::getMimeType($source);
        header("Content-Transfer-Encoding: binary");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Pragma: public");
        header('Content-Disposition: filename="' . basename($source) . '"');
        header("Content-Type: " . $mimetype);
        header("Content-Length: " . OC_Filesystem::filesize($source));
        //download the file
        @ob_clean();
        OC_Filesystem::readfile($source);
    }
} else {
    header("HTTP/1.0 404 Not Found");
    $tmpl = new OC_Template("", "404", "guest");
    $tmpl->printPage();
    die;
}
Ejemplo n.º 7
0
 /**
  * Returns the size of the node, in bytes
  *
  * @return int
  */
 public function getSize()
 {
     return OC_Filesystem::filesize($this->path);
 }
Ejemplo n.º 8
0
 /**
  * called when files are deleted
  * @param array $params
  * @param string root (optional)
  */
 public static function fileSystemWatcherRename($params, $root = '')
 {
     if (!$root) {
         $root = OC_Filesystem::getRoot();
     }
     if ($root == '/') {
         $root = '';
     }
     $oldPath = $params['oldpath'];
     $newPath = $params['newpath'];
     $fullOldPath = $root . $oldPath;
     $fullNewPath = $root . $newPath;
     if (($id = self::getFileId($fullOldPath)) != -1) {
         $oldSize = self::getCachedSize($oldPath, $root);
     } else {
         return;
     }
     $size = OC_Filesystem::filesize($newPath);
     self::increaseSize(dirname($fullOldPath), -$oldSize);
     self::increaseSize(dirname($fullNewPath), $oldSize);
     self::move($oldPath, $newPath);
 }
 /**
  * return the content of a file or return a zip file containning multiply files
  *
  * @param dir  $dir
  * @param file $file ; seperated list of files to download
  */
 public static function get($dir, $files)
 {
     if (strpos($files, ';')) {
         $files = explode(';', $files);
     }
     if (is_array($files)) {
         $zip = new ZipArchive();
         $filename = sys_get_temp_dir() . "/ownCloud.zip";
         if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
             exit("cannot open <{$filename}>\n");
         }
         foreach ($files as $file) {
             $file = $dir . '/' . $file;
             if (OC_Filesystem::is_file($file)) {
                 $tmpFile = OC_Filesystem::toTmpFile($file);
                 self::$tmpFiles[] = $tmpFile;
                 $zip->addFile($tmpFile, basename($file));
             } elseif (OC_Filesystem::is_dir($file)) {
                 self::zipAddDir($file, $zip);
             }
         }
         $zip->close();
     } elseif (OC_Filesystem::is_dir($dir . '/' . $files)) {
         $zip = new ZipArchive();
         $filename = sys_get_temp_dir() . "/ownCloud.zip";
         if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
             exit("cannot open <{$filename}>\n");
         }
         $file = $dir . '/' . $files;
         self::zipAddDir($file, $zip);
         $zip->close();
     } else {
         $zip = false;
         $filename = $dir . '/' . $files;
     }
     if ($zip or OC_Filesystem::is_readable($filename)) {
         header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
         header('Content-Transfer-Encoding: binary');
         header('Expires: 0');
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         header('Pragma: public');
         if ($zip) {
             header('Content-Type: application/zip');
             header('Content-Length: ' . filesize($filename));
         } else {
             header('Content-Type: ' . OC_Filesystem::getMimeType($filename));
             header('Content-Length: ' . OC_Filesystem::filesize($filename));
         }
     } elseif ($zip or !OC_Filesystem::file_exists($filename)) {
         header("HTTP/1.0 404 Not Found");
         $tmpl = new OC_Template('', '404', 'guest');
         $tmpl->assign('file', $filename);
         $tmpl->printPage();
         // 			die('404 Not Found');
     } else {
         header("HTTP/1.0 403 Forbidden");
         die('403 Forbidden');
     }
     @ob_end_clean();
     if ($zip) {
         readfile($filename);
         unlink($filename);
     } else {
         OC_Filesystem::readfile($filename);
     }
     foreach (self::$tmpFiles as $tmpFile) {
         if (file_exists($tmpFile) and is_file($tmpFile)) {
             unlink($tmpFile);
         }
     }
 }
/**
 * Copyright (c) 2011, Robin Appelman <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or later.
 * See the COPYING-README file.
 */
require_once '../lib/base.php';
OC_Util::checkLoggedIn();
// Highlight navigation entry
OC_Util::addScript('settings', 'personal');
OC_Util::addStyle('settings', 'settings');
OC_Util::addScript('3rdparty', 'chosen/chosen.jquery.min');
OC_Util::addStyle('3rdparty', 'chosen');
OC_App::setActiveNavigationEntry('personal');
// calculate the disc space
$used = OC_Filesystem::filesize('/');
$free = OC_Filesystem::free_space();
$total = $free + $used;
$relative = round($used / $total * 10000) / 100;
$email = OC_Preferences::getValue(OC_User::getUser(), 'settings', 'email', '');
$lang = OC_Preferences::getValue(OC_User::getUser(), 'core', 'lang', 'en');
$languageCodes = OC_L10N::findAvailableLanguages();
//put the current language in the front
unset($languageCodes[array_search($lang, $languageCodes)]);
array_unshift($languageCodes, $lang);
$languageNames = (include 'languageCodes.php');
$languages = array();
foreach ($languageCodes as $lang) {
    $languages[] = array('code' => $lang, 'name' => $languageNames[$lang]);
}
// Return template
Ejemplo n.º 11
0
 public function postFopen($path, &$result)
 {
     if (!$result) {
         return $result;
     }
     $meta = stream_get_meta_data($result);
     if (self::isEncrypted($path)) {
         fclose($result);
         $result = fopen('crypt://' . $path, $meta['mode']);
     } elseif (self::shouldEncrypt($path) and $meta['mode'] != 'r' and $meta['mode'] != 'rb') {
         if (OC_Filesystem::file_exists($path) and OC_Filesystem::filesize($path) > 0) {
             //first encrypt the target file so we don't end up with a half encrypted file
             OCP\Util::writeLog('files_encryption', 'Decrypting ' . $path . ' before writing', OCP\Util::DEBUG);
             $tmp = fopen('php://temp');
             OCP\Files::streamCopy($result, $tmp);
             fclose($result);
             OC_Filesystem::file_put_contents($path, $tmp);
             fclose($tmp);
         }
         $result = fopen('crypt://' . $path, $meta['mode']);
     }
     return $result;
 }
Ejemplo n.º 12
0
}
if ($source) {
    if (substr($source, 0, 8) != 'https://' and substr($source, 0, 7) != 'http://') {
        OCP\JSON::error(array("data" => array("message" => "Not a valid source")));
        exit;
    }
    $ctx = stream_context_create(null, array('notification' => 'progress'));
    $sourceStream = fopen($source, 'rb', false, $ctx);
    $target = $dir . '/' . $filename;
    $result = OC_Filesystem::file_put_contents($target, $sourceStream);
    if ($result) {
        $target = OC_Filesystem::normalizePath($target);
        $meta = OC_FileCache::get($target);
        $mime = $meta['mimetype'];
        $id = OC_FileCache::getId($target);
        $eventSource->send('success', array('mime' => $mime, 'size' => OC_Filesystem::filesize($target), 'id' => $id));
    } else {
        $eventSource->send('error', "Error while downloading " . $source . ' to ' . $target);
    }
    $eventSource->close();
    exit;
} else {
    if ($content) {
        if (OC_Filesystem::file_put_contents($dir . '/' . $filename, $content)) {
            $meta = OC_FileCache::get($dir . '/' . $filename);
            $id = OC_FileCache::getId($dir . '/' . $filename);
            OCP\JSON::success(array("data" => array('content' => $content, 'id' => $id)));
            exit;
        }
    } elseif (OC_Files::newFile($dir, $filename, 'file')) {
        $meta = OC_FileCache::get($dir . '/' . $filename);
        case 'play':
            ob_end_clean();
            $ftype = OC_Filesystem::getMimeType($arguments['path']);
            $songId = OC_MEDIA_COLLECTION::getSongByPath($arguments['path']);
            OC_MEDIA_COLLECTION::registerPlay($songId);
            header('Content-Type:' . $ftype);
            // calc an offset of 24 hours
            $offset = 3600 * 24;
            // calc the string in GMT not localtime and add the offset
            $expire = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
            //output the HTTP header
            header($expire);
            header('Cache-Control: max-age=3600, must-revalidate');
            header('Pragma: public');
            header('Accept-Ranges: bytes');
            header('Content-Length: ' . OC_Filesystem::filesize($arguments['path']));
            $gmt_mtime = gmdate('D, d M Y H:i:s', OC_Filesystem::filemtime($arguments['path'])) . ' GMT';
            header("Last-Modified: " . $gmt_mtime);
            OC_Filesystem::readfile($arguments['path']);
            exit;
        case 'find_music':
            OC_JSON::encodedPrint(findMusic());
            exit;
    }
}
function findMusic($path = '')
{
    $music = array();
    $dh = OC_Filesystem::opendir($path);
    if ($dh) {
        while ($filename = readdir($dh)) {
if (OC_User::checkPassword($user, $pass)) {
    OC_Util::setupFS($user);
    OC_MEDIA_COLLECTION::$uid = $user;
} else {
    exit;
}
if (isset($_POST['play']) and $_POST['play'] == 'true') {
    if (!isset($_POST['song'])) {
        exit;
    }
    $song = OC_MEDIA_COLLECTION::getSong($_POST['song']);
    $ftype = OC_Filesystem::getMimeType($song['song_path']);
    header('Content-Type:' . $ftype);
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . OC_Filesystem::filesize($song['song_path']));
    OC_Filesystem::readfile($song['song_path']);
}
$artist = isset($_POST['artist']) ? '%' . $_POST['artist'] . '%' : '';
$album = isset($_POST['album']) ? '%' . $_POST['album'] . '%' : '';
$song = isset($_POST['song']) ? $_POST['song'] : '';
$artist = OC_MEDIA_COLLECTION::getArtistId($artist);
$album = OC_MEDIA_COLLECTION::getAlbumId($album, $artist);
$songs = OC_MEDIA_COLLECTION::getSongs($artist, $album, $song);
$baseUrl = OC_Util::getServerURL() . OC_Helper::linkTo('media', 'tomahawk.php');
$results = array();
foreach ($songs as $song) {
    $results[] = (object) array('artist' => OC_MEDIA_COLLECTION::getArtistName($song['song_artist']), 'album' => OC_MEDIA_COLLECTION::getAlbumName($song['song_album']), 'track' => $song['song_name'], 'source' => 'ownCloud', 'mimetype' => OC_Filesystem::getMimeType($song['song_path']), 'extension' => substr($song['song_path'], strrpos($song['song_path'], '.')), 'url' => $baseUrl . '?play=true&song=' . $song['song_id'], 'bitrate' => round($song['song_id'] / $song['song_length'], 0), 'duration' => round($song['song_length'], 0), 'size' => $song['song_size'], 'score' => (double) 1.0);
}
OC_JSON::encodedPrint($results);
 /**
  * Returns available diskspace information
  *
  * @return array
  */
 public function getQuotaInfo()
 {
     return array(OC_Filesystem::filesize('/'), OC_Filesystem::free_space());
 }
Ejemplo n.º 16
0
 * Copyright 2013 EnginSoft S.p.A.
 * All rights reserved
 */
$filename = $_POST['filename'];
$json = false;
if (isset($_POST['json'])) {
    $json = (bool) $_POST["json"];
}
/*
 * max size of output file, to avoid reading a very big output and clogging the network
 */
$MAX_SIZE = 1024 * 512;
# "512k of memory should be enough for everyone"
$content = "";
if (OC_Filesystem::is_file($filename) && OC_Filesystem::is_readable($filename)) {
    if (OC_Filesystem::filesize($filename) > $MAX_SIZE) {
        $handle = OC_Filesystem::fopen($filename, "r");
        if ($handle) {
            $content = fread($handle, $MAX_SIZE);
            fclose($handle);
        }
    } else {
        $content = OC_Filesystem::file_get_contents($filename);
    }
} else {
    echo "ERROR: Cannot read " . $filename;
}
if ($json) {
    $json_obj = json_decode($content);
    foreach ($json_obj as $key => $value) {
        echo "{$key} : {$value}\n";