Пример #1
0
 /**
  * @PublicPage
  * @NoCSRFRequired
  *
  * @return TemplateResponse
  */
 public function showPad($file, $dir)
 {
     /* Retrieve file content to find pad’s URL */
     $content = \OC\Files\Filesystem::file_get_contents($dir . "/" . $file);
     preg_match('/URL=(.*)$/', $content, $matches);
     $url = $matches[1];
     $title = $file;
     $params = ['urlGenerator' => $this->urlGenerator, 'url' => $url, 'title' => $title];
     $response = new TemplateResponse($this->appName, 'viewer', $params, 'blank');
     return $response;
 }
Пример #2
0
 /**
  * @PublicPage
  * @NoCSRFRequired
  *
  * @return TemplateResponse
  */
 public function showPad($file, $dir)
 {
     /* Retrieve file content to find pad’s URL */
     $content = \OC\Files\Filesystem::file_get_contents($dir . "/" . $file);
     preg_match('/URL=(.*)$/', $content, $matches);
     $url = $matches[1];
     $title = $file;
     /* Not totally sure that this is the right way to proceed…
      *
      * First we decode the URL (to avoid double encode), then we
      * replace spaces with underscore (as they are converted as
      * such by Etherpad), then we encode the URL properly (and we
      * avoid to urlencode() the protocol scheme).
      *
      * Magic urlencode() function was stolen from this answer on
      * StackOverflow: <http://stackoverflow.com/a/7974253>.
      */
     $url = urldecode($url);
     $url = str_replace(' ', '_', $url);
     $url = preg_replace_callback('#://([^/]+)/([^?]+)#', function ($match) {
         return '://' . $match[1] . '/' . join('/', array_map('rawurlencode', explode('/', $match[2])));
     }, $url);
     $params = ['urlGenerator' => $this->urlGenerator, 'url' => $url, 'title' => $title];
     $response = new TemplateResponse($this->appName, 'viewer', $params, 'blank');
     /* Allow Etherpad and Ethercalc domains to the
      * Content-Security-frame- list.
      *
      * This feature was introduced in ownCloud 8.1.
      */
     $policy = new ContentSecurityPolicy();
     $appConfig = \OC::$server->getAppConfig();
     $policy->addAllowedFrameDomain($appConfig->getValue('ownpad', 'ownpad_etherpad_host', ''));
     $policy->addAllowedFrameDomain($appConfig->getValue('ownpad', 'ownpad_ethercalc_host', ''));
     $response->setContentSecurityPolicy($policy);
     return $response;
 }
Пример #3
0
 /**
  * @brief Loads an image from a local file.
  * @param $imageref The path to a local file.
  * @returns An image resource or false on error
  */
 public function loadFromFile($imagePath = false)
 {
     // exif_imagetype throws "read error!" if file is less than 12 byte
     if (!@is_file($imagePath) || !file_exists($imagePath) || filesize($imagePath) < 12 || !is_readable($imagePath)) {
         // Debug output disabled because this method is tried before loadFromBase64?
         OC_Log::write('core', 'OC_Image->loadFromFile, couldn\'t load: ' . $imagePath, OC_Log::DEBUG);
         return false;
     }
     $iType = exif_imagetype($imagePath);
     switch ($iType) {
         case IMAGETYPE_GIF:
             if (imagetypes() & IMG_GIF) {
                 $this->resource = imagecreatefromgif($imagePath);
             } else {
                 OC_Log::write('core', 'OC_Image->loadFromFile, GIF images not supported: ' . $imagePath, OC_Log::DEBUG);
             }
             break;
         case IMAGETYPE_JPEG:
             if (imagetypes() & IMG_JPG) {
                 $this->resource = imagecreatefromjpeg($imagePath);
             } else {
                 OC_Log::write('core', 'OC_Image->loadFromFile, JPG images not supported: ' . $imagePath, OC_Log::DEBUG);
             }
             break;
         case IMAGETYPE_PNG:
             if (imagetypes() & IMG_PNG) {
                 $this->resource = imagecreatefrompng($imagePath);
             } else {
                 OC_Log::write('core', 'OC_Image->loadFromFile, PNG images not supported: ' . $imagePath, OC_Log::DEBUG);
             }
             break;
         case IMAGETYPE_XBM:
             if (imagetypes() & IMG_XPM) {
                 $this->resource = imagecreatefromxbm($imagePath);
             } else {
                 OC_Log::write('core', 'OC_Image->loadFromFile, XBM/XPM images not supported: ' . $imagePath, OC_Log::DEBUG);
             }
             break;
         case IMAGETYPE_WBMP:
             if (imagetypes() & IMG_WBMP) {
                 $this->resource = imagecreatefromwbmp($imagePath);
             } else {
                 OC_Log::write('core', 'OC_Image->loadFromFile, WBMP images not supported: ' . $imagePath, OC_Log::DEBUG);
             }
             break;
         case IMAGETYPE_BMP:
             $this->resource = $this->imagecreatefrombmp($imagePath);
             break;
             /*
             case IMAGETYPE_TIFF_II: // (intel byte order)
             	break;
             case IMAGETYPE_TIFF_MM: // (motorola byte order)
             	break;
             case IMAGETYPE_JPC:
             	break;
             case IMAGETYPE_JP2:
             	break;
             case IMAGETYPE_JPX:
             	break;
             case IMAGETYPE_JB2:
             	break;
             case IMAGETYPE_SWC:
             	break;
             case IMAGETYPE_IFF:
             	break;
             case IMAGETYPE_ICO:
             	break;
             case IMAGETYPE_SWF:
             	break;
             case IMAGETYPE_PSD:
             	break;
             */
         /*
         case IMAGETYPE_TIFF_II: // (intel byte order)
         	break;
         case IMAGETYPE_TIFF_MM: // (motorola byte order)
         	break;
         case IMAGETYPE_JPC:
         	break;
         case IMAGETYPE_JP2:
         	break;
         case IMAGETYPE_JPX:
         	break;
         case IMAGETYPE_JB2:
         	break;
         case IMAGETYPE_SWC:
         	break;
         case IMAGETYPE_IFF:
         	break;
         case IMAGETYPE_ICO:
         	break;
         case IMAGETYPE_SWF:
         	break;
         case IMAGETYPE_PSD:
         	break;
         */
         default:
             // this is mostly file created from encrypted file
             $this->resource = imagecreatefromstring(\OC\Files\Filesystem::file_get_contents(\OC\Files\Filesystem::getLocalPath($imagePath)));
             $iType = IMAGETYPE_PNG;
             OC_Log::write('core', 'OC_Image->loadFromFile, Default', OC_Log::DEBUG);
             break;
     }
     if ($this->valid()) {
         $this->imageType = $iType;
         $this->mimeType = image_type_to_mime_type($iType);
         $this->filePath = $imagePath;
     }
     return $this->resource;
 }
Пример #4
0
 /**
  * Loads an image from a local file.
  *
  * @param bool|string $imagePath The path to a local file.
  * @return bool|resource An image resource or false on error
  */
 public function loadFromFile($imagePath = false)
 {
     // exif_imagetype throws "read error!" if file is less than 12 byte
     if (!@is_file($imagePath) || !file_exists($imagePath) || filesize($imagePath) < 12 || !is_readable($imagePath)) {
         return false;
     }
     $iType = exif_imagetype($imagePath);
     switch ($iType) {
         case IMAGETYPE_GIF:
             if (imagetypes() & IMG_GIF) {
                 $this->resource = imagecreatefromgif($imagePath);
                 // Preserve transparency
                 imagealphablending($this->resource, true);
                 imagesavealpha($this->resource, true);
             } else {
                 $this->logger->debug('OC_Image->loadFromFile, GIF images not supported: ' . $imagePath, array('app' => 'core'));
             }
             break;
         case IMAGETYPE_JPEG:
             if (imagetypes() & IMG_JPG) {
                 $this->resource = imagecreatefromjpeg($imagePath);
             } else {
                 $this->logger->debug('OC_Image->loadFromFile, JPG images not supported: ' . $imagePath, array('app' => 'core'));
             }
             break;
         case IMAGETYPE_PNG:
             if (imagetypes() & IMG_PNG) {
                 $this->resource = imagecreatefrompng($imagePath);
                 // Preserve transparency
                 imagealphablending($this->resource, true);
                 imagesavealpha($this->resource, true);
             } else {
                 $this->logger->debug('OC_Image->loadFromFile, PNG images not supported: ' . $imagePath, array('app' => 'core'));
             }
             break;
         case IMAGETYPE_XBM:
             if (imagetypes() & IMG_XPM) {
                 $this->resource = imagecreatefromxbm($imagePath);
             } else {
                 $this->logger->debug('OC_Image->loadFromFile, XBM/XPM images not supported: ' . $imagePath, array('app' => 'core'));
             }
             break;
         case IMAGETYPE_WBMP:
             if (imagetypes() & IMG_WBMP) {
                 $this->resource = imagecreatefromwbmp($imagePath);
             } else {
                 $this->logger->debug('OC_Image->loadFromFile, WBMP images not supported: ' . $imagePath, array('app' => 'core'));
             }
             break;
         case IMAGETYPE_BMP:
             $this->resource = $this->imagecreatefrombmp($imagePath);
             break;
             /*
             case IMAGETYPE_TIFF_II: // (intel byte order)
             	break;
             case IMAGETYPE_TIFF_MM: // (motorola byte order)
             	break;
             case IMAGETYPE_JPC:
             	break;
             case IMAGETYPE_JP2:
             	break;
             case IMAGETYPE_JPX:
             	break;
             case IMAGETYPE_JB2:
             	break;
             case IMAGETYPE_SWC:
             	break;
             case IMAGETYPE_IFF:
             	break;
             case IMAGETYPE_ICO:
             	break;
             case IMAGETYPE_SWF:
             	break;
             case IMAGETYPE_PSD:
             	break;
             */
         /*
         case IMAGETYPE_TIFF_II: // (intel byte order)
         	break;
         case IMAGETYPE_TIFF_MM: // (motorola byte order)
         	break;
         case IMAGETYPE_JPC:
         	break;
         case IMAGETYPE_JP2:
         	break;
         case IMAGETYPE_JPX:
         	break;
         case IMAGETYPE_JB2:
         	break;
         case IMAGETYPE_SWC:
         	break;
         case IMAGETYPE_IFF:
         	break;
         case IMAGETYPE_ICO:
         	break;
         case IMAGETYPE_SWF:
         	break;
         case IMAGETYPE_PSD:
         	break;
         */
         default:
             // this is mostly file created from encrypted file
             $this->resource = imagecreatefromstring(\OC\Files\Filesystem::file_get_contents(\OC\Files\Filesystem::getLocalPath($imagePath)));
             $iType = IMAGETYPE_PNG;
             $this->logger->debug('OC_Image->loadFromFile, Default', array('app' => 'core'));
             break;
     }
     if ($this->valid()) {
         $this->imageType = $iType;
         $this->mimeType = image_type_to_mime_type($iType);
         $this->filePath = $imagePath;
     }
     return $this->resource;
 }
Пример #5
0
/**
 * Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
OCP\JSON::checkLoggedIn();
OCP\App::checkAppEnabled('calendar');
OCP\JSON::callCheck();
session_write_close();
if (isset($_POST['progresskey']) && isset($_POST['getprogress'])) {
    echo OCP\JSON::success(array('percent' => OC_Cache::get($_POST['progresskey'])));
    exit;
}
$file = \OC\Files\Filesystem::file_get_contents($_POST['path'] . '/' . $_POST['file']);
if (!$file) {
    OCP\JSON::error(array('error' => '404'));
}
$file = Sabre\VObject\StringUtil::convertToUTF8($file);
$import = new OC_Calendar_Import($file);
$import->setUserID(OCP\User::getUser());
$import->setTimeZone(OC_Calendar_App::$tz);
$import->enableProgressCache();
$import->setProgresskey($_POST['progresskey']);
if (!$import->isValid()) {
    OCP\JSON::error(array('error' => 'notvalid'));
    exit;
}
$newcal = false;
if ($_POST['method'] == 'new') {
Пример #6
0
 /**
  * @NoAdminRequired
  */
 public function importVcards()
 {
     $pProgresskey = $this->params('progresskey');
     $pGetprogress = $this->params('getprogress');
     $pPath = $this->params('path');
     $pFile = $this->params('file');
     $pMethod = $this->params('method');
     $pAddressbook = $this->params('addressbookname');
     $pIsDragged = $this->params('isDragged');
     $pId = $this->params('id');
     $pOverwrite = $this->params('overwrite');
     \OC::$server->getSession()->close();
     if (isset($pProgresskey) && isset($pGetprogress)) {
         $aCurrent = \OC::$server->getCache()->get($pProgresskey);
         $aCurrent = json_decode($aCurrent);
         $numVC = isset($aCurrent->{'all'}) ? $aCurrent->{'all'} : 0;
         $currentVCCount = isset($aCurrent->{'current'}) ? $aCurrent->{'current'} : 0;
         $currentFn = isset($aCurrent->{'currentFn'}) ? $aCurrent->{'currentFn'} : '';
         $percent = isset($aCurrent->{'percent'}) ? $aCurrent->{'percent'} : '';
         if ($percent == '') {
             $percent = 0;
         }
         $params = ['status' => 'success', 'percent' => $percent, 'currentmsg' => $currentFn . ' ' . $percent . '% (' . $currentVCCount . '/' . $numVC . ')'];
         $response = new JSONResponse($params);
         return $response;
     }
     if ($pIsDragged === 'true') {
         //OCP\JSON::error(array('error'=>'404'));
         $file = explode(',', $pFile);
         $file = end($file);
         $file = base64_decode($file);
     } else {
         $file = \OC\Files\Filesystem::file_get_contents($pPath . '/' . $pFile);
     }
     if (!$file) {
         $params = ['status' => 'error', 'error' => '404'];
         $response = new JSONResponse($params);
         return $response;
     }
     $file = \Sabre\VObject\StringUtil::convertToUTF8($file);
     $import = new Import($file);
     $import->setUserID($this->userId);
     $import->setProgresskey($pProgresskey);
     $import->enableProgressCache();
     \OCP\Util::writeLog($this->appName, ' PROG: ' . $pProgresskey, \OCP\Util::DEBUG);
     if (!$import->isValid()) {
         $params = ['status' => 'error', 'error' => 'notvalid'];
         $response = new JSONResponse($params);
         return $response;
     }
     $newAddressbook = false;
     if ($pMethod == 'new') {
         $id = Addressbook::add($this->userId, $pAddressbook);
         if ($id) {
             Addressbook::setActive($id, 1);
             $newAddressbook = true;
         }
     } else {
         $id = $pId;
         Addressbook::find($id);
         $import->setOverwrite($pOverwrite);
     }
     //\OCP\Util::writeLog($this->appName,' METHOD: '.$pMethod.'ID:'.$id, \OCP\Util::DEBUG);
     $import->setAddressbookId($id);
     try {
         $import->import();
     } catch (\Exception $e) {
         $params = ['status' => 'error', 'message' => $this->l10n->t('Import failed')];
         $response = new JSONResponse($params);
         return $response;
     }
     $count = $import->getCount();
     $errorCount = $import->getErrorCount();
     if ($count == 0) {
         if ($newAddressbook) {
             Addressbook::delete($id);
         }
         $params = ['status' => 'error', 'message' => $this->l10n->t('The file contained either no vcard or all vcards are already saved in your addessbook.')];
         $response = new JSONResponse($params);
         return $response;
     } else {
         if ($newAddressbook) {
             $params = ['status' => 'success', 'message' => $count . ' ' . $this->l10n->t('vcards has been saved in the new addressbook') . ' ' . strip_tags($pAddressbook)];
             $response = new JSONResponse($params);
             return $response;
         } else {
             $params = ['status' => 'success', 'message' => $errorCount . ' Error - ' . $count . ' ' . $this->l10n->t('vcards has been saved in your addressbook')];
             $response = new JSONResponse($params);
             return $response;
         }
     }
 }
Пример #7
0
 /**
  * @NoAdminRequired
  */
 public function importEvents()
 {
     $pProgresskey = $this->params('progresskey');
     $pGetprogress = $this->params('getprogress');
     $pPath = $this->params('path');
     $pFile = $this->params('file');
     $pMethod = $this->params('method');
     $pCalname = $this->params('calname');
     $pCalcolor = $this->params('calcolor');
     $pId = $this->params('id');
     $pOverwrite = $this->params('overwrite');
     $pIsDragged = $this->params('isDragged');
     $pIsSub = $this->params('isSub');
     $pSubUri = $this->params('subUri');
     $pSubUri = isset($pSubUri) ? $pSubUri : '';
     \OC::$server->getSession()->close();
     if (isset($pProgresskey) && isset($pGetprogress)) {
         $aCurrent = \OC::$server->getCache()->get($pProgresskey);
         $aCurrent = json_decode($aCurrent);
         $numVO = isset($aCurrent->{'all'}) ? $aCurrent->{'all'} : 0;
         $currentVOCount = isset($aCurrent->{'current'}) ? $aCurrent->{'current'} : 0;
         $currentSummary = isset($aCurrent->{'currentSummary'}) ? $aCurrent->{'currentSummary'} : '';
         $percent = isset($aCurrent->{'percent'}) ? $aCurrent->{'percent'} : '';
         if ($percent == '') {
             $percent = 0;
         }
         $params = ['status' => 'success', 'percent' => $percent, 'currentmsg' => $currentSummary . ' ' . $percent . '% (' . $currentVOCount . '/' . $numVO . ')'];
         $response = new JSONResponse($params);
         return $response;
     }
     if ($pIsDragged === 'true') {
         //OCP\JSON::error(array('error'=>'404'));
         $file = explode(',', $pFile);
         $file = end($file);
         $file = base64_decode($file);
     } elseif ($pIsSub === 'true') {
         $file = $pFile;
     } else {
         $file = \OC\Files\Filesystem::file_get_contents($pPath . '/' . $pFile);
     }
     if (!$file) {
         $params = ['status' => 'error', 'error' => '404'];
         $response = new JSONResponse($params);
         return $response;
     }
     $file = \Sabre\VObject\StringUtil::convertToUTF8($file);
     $import = new Import($file);
     $import->setUserID($this->userId);
     $import->setTimeZone(CalendarApp::$tz);
     $import->enableProgressCache();
     $import->setProgresskey($pProgresskey);
     $bUriImport = $pIsSub === 'true' ? true : false;
     $import->setImportFromUri($bUriImport);
     if (!$import->isValid()) {
         $params = ['status' => 'error', 'error' => 'notvalid'];
         $response = new JSONResponse($params);
         return $response;
     }
     $newcal = false;
     if ($pMethod == 'new') {
         $calendars = CalendarCalendar::allCalendars($this->userId);
         foreach ($calendars as $calendar) {
             if ($calendar['displayname'] == $pCalname) {
                 $id = $calendar['id'];
                 $newcal = false;
                 break;
             }
             $newcal = true;
         }
         if ($newcal) {
             $isSubscribed = 0;
             if ($pIsSub === 'true') {
                 $isSubscribed = 1;
             }
             $id = CalendarCalendar::addCalendar($this->userId, strip_tags($pCalname), 'VEVENT,VTODO,VJOURNAL', null, 0, strip_tags($pCalcolor), $isSubscribed, $pSubUri);
             CalendarCalendar::setCalendarActive($id, 1);
         }
     } else {
         $id = $pId;
         $calendar = CalendarApp::getCalendar($id);
         if ($calendar['userid'] != $this->userId) {
             $params = ['status' => 'error', 'error' => 'missingcalendarrights'];
             $response = new JSONResponse($params);
             return $response;
         }
         $import->setOverwrite($pOverwrite);
     }
     $import->setCalendarID($id);
     try {
         $import->import();
     } catch (\Exception $e) {
         $params = ['status' => 'error', 'message' => $this->l10n->t('Import failed')];
         $response = new JSONResponse($params);
         return $response;
     }
     $count = $import->getCount();
     if ($count == 0) {
         if ($newcal) {
             CalendarCalendar::deleteCalendar($id);
         }
         $params = ['status' => 'error', 'message' => $this->l10n->t('The file contained either no events or all events are already saved in your calendar.')];
         $response = new JSONResponse($params);
         return $response;
     } else {
         if ($newcal) {
             $params = ['status' => 'success', 'message' => $count . ' ' . $this->l10n->t('events has been saved in the new calendar') . ' ' . strip_tags($pCalname), 'eventSource' => CalendarCalendar::getEventSourceInfo(CalendarCalendar::find($id))];
             $response = new JSONResponse($params);
             return $response;
         } else {
             $params = ['status' => 'success', 'message' => $count . ' ' . $this->l10n->t('events has been saved in your calendar'), 'eventSource' => ''];
             $response = new JSONResponse($params);
             return $response;
         }
     }
 }
Пример #8
0
 /**
  * @dataProvider usersProvider
  */
 function testMoveFileToFolder($userId)
 {
     $view = new \OC\Files\View('/' . self::TEST_ENCRYPTION_SHARE_USER1);
     $filename = '/tmp-' . $this->getUniqueID();
     $folder = '/folder' . $this->getUniqueID();
     \OC\Files\Filesystem::mkdir($folder);
     // Save long data as encrypted file using stream wrapper
     $cryptedFile = \OC\Files\Filesystem::file_put_contents($folder . $filename, $this->dataShort);
     // Test that data was successfully written
     $this->assertInternalType('int', $cryptedFile);
     // Get file decrypted contents
     $decrypt = \OC\Files\Filesystem::file_get_contents($folder . $filename);
     $this->assertEquals($this->dataShort, $decrypt);
     $subFolder = $folder . '/subfolder' . $this->getUniqueID();
     \OC\Files\Filesystem::mkdir($subFolder);
     // get the file info from previous created file
     $fileInfo = \OC\Files\Filesystem::getFileInfo($folder);
     $this->assertInstanceOf('\\OC\\Files\\FileInfo', $fileInfo);
     // share the folder
     \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL);
     // check that the share keys exist
     $this->assertTrue($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
     $this->assertTrue($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
     // move the file into the subfolder as the test user
     self::loginHelper($userId);
     \OC\Files\Filesystem::rename($folder . $filename, $subFolder . $filename);
     self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);
     // Get file decrypted contents
     $newDecrypt = \OC\Files\Filesystem::file_get_contents($subFolder . $filename);
     $this->assertEquals($this->dataShort, $newDecrypt);
     // check if additional share key for user2 exists
     $this->assertTrue($view->file_exists('files_encryption/keys' . $subFolder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
     $this->assertTrue($view->file_exists('files_encryption/keys' . $subFolder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
     // check that old keys were removed/moved properly
     $this->assertFalse($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
     $this->assertFalse($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
     // tear down
     \OC\Files\Filesystem::unlink($subFolder);
     \OC\Files\Filesystem::unlink($folder);
 }
 /**
  * @NoAdminRequired
  */
 public function prepare()
 {
     $request = $this->request;
     $params = $this->request->urlParams;
     $addressBookId = $params['addressBookId'];
     $format = $params['importType'];
     $response = new JSONResponse();
     $filename = $request->post['filename'];
     $path = $request->post['path'];
     $view = \OCP\Files::getStorage('contacts');
     if (!$view->file_exists('imports')) {
         $view->mkdir('imports');
     }
     $content = \OC\Files\Filesystem::file_get_contents($path . '/' . $filename);
     if ($view->file_put_contents('/imports/' . $filename, $content)) {
         $progresskey = 'contacts-import-' . rand();
         $response->setParams(array('filename' => $filename, 'progresskey' => $progresskey, 'backend' => $params['backend'], 'addressBookId' => $params['addressBookId'], 'importType' => $params['importType']));
     } else {
         $response->bailOut(App::$l10n->t('Error moving file to imports folder.'));
     }
     return $response;
 }
Пример #10
0
 * 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\JSON::checkLoggedIn();
// Set the session key for the file we are about to edit.
$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
$filename = isset($_GET['file']) ? $_GET['file'] : '';
if (!empty($filename)) {
    $path = $dir . '/' . $filename;
    $writeable = \OC\Files\Filesystem::isUpdatable($path);
    $mime = \OC\Files\Filesystem::getMimeType($path);
    $mtime = \OC\Files\Filesystem::filemtime($path);
    $filecontents = \OC\Files\Filesystem::file_get_contents($path);
    $encoding = mb_detect_encoding($filecontents . "a", "UTF-8, WINDOWS-1252, ISO-8859-15, ISO-8859-1, ASCII", true);
    if ($encoding == "") {
        // set default encoding if it couldn't be detected
        $encoding = 'ISO-8859-15';
    }
    $filecontents = iconv($encoding, "UTF-8", $filecontents);
    OCP\JSON::success(array('data' => array('filecontents' => $filecontents, 'writeable' => $writeable, 'mime' => $mime, 'mtime' => $mtime)));
} else {
    OCP\JSON::error(array('data' => array('message' => 'Invalid file path supplied.')));
}
Пример #11
0
 /**
  * test if additional share keys are added if we move a folder to a shared parent
  * @medium
  */
 function testMoveFolder()
 {
     $view = new \OC\Files\View('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
     $filename = '/tmp-' . uniqid();
     $folder = '/folder' . uniqid();
     \OC\Files\Filesystem::mkdir($folder);
     // Save long data as encrypted file using stream wrapper
     $cryptedFile = \OC\Files\Filesystem::file_put_contents($folder . $filename, $this->dataShort);
     // Test that data was successfully written
     $this->assertTrue(is_int($cryptedFile));
     // Get file decrypted contents
     $decrypt = \OC\Files\Filesystem::file_get_contents($folder . $filename);
     $this->assertEquals($this->dataShort, $decrypt);
     $newFolder = '/newfolder/subfolder' . uniqid();
     \OC\Files\Filesystem::mkdir('/newfolder');
     // get the file info from previous created file
     $fileInfo = \OC\Files\Filesystem::getFileInfo('/newfolder');
     $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
     // share the folder
     \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, OCP\PERMISSION_ALL);
     \OC\Files\Filesystem::rename($folder, $newFolder);
     // Get file decrypted contents
     $newDecrypt = \OC\Files\Filesystem::file_get_contents($newFolder . $filename);
     $this->assertEquals($this->dataShort, $newDecrypt);
     // check if additional share key for user2 exists
     $this->assertTrue($view->file_exists('files_encryption/share-keys' . $newFolder . '/' . $filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
     // tear down
     \OC\Files\Filesystem::unlink($newFolder);
     \OC\Files\Filesystem::unlink('/newfolder');
 }
Пример #12
0
 /**
  * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  */
 public static function file_get_contents($path)
 {
     return \OC\Files\Filesystem::file_get_contents($path);
 }
Пример #13
0
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*
*/
require_once 'lib/impress.php';
// Check if we are a user
OCP\User::checkLoggedIn();
OCP\JSON::checkAppEnabled('impress');
$filename = OCP\Util::sanitizeHTML($_GET['file']);
$title = OCP\Util::sanitizeHTML($_GET['name']);
if (!\OC\Files\Filesystem::file_exists($filename)) {
    header("HTTP/1.0 404 Not Found");
    $tmpl = new OCP\Template('', '404', 'guest');
    $tmpl->assign('file', $filename);
    $tmpl->printPage();
    exit;
}
$data = \OC\Files\Filesystem::file_get_contents($filename);
if (stripos($data, '<html') != false or stripos($data, '<head') != false or stripos($data, '<body') != false) {
    echo '<br /><center>This is not a valid impress file. Please check the documentation.</center>';
    exit;
}
if (stripos($data, '<script') != false) {
    echo '<br /><center>Please don\'t use javascript in impress files.</center>';
    exit;
}
header('Content-Type: text/html', true);
OCP\Response::disableCaching();
@ob_end_clean();
\OCA_Impress\Storage::showHeader($title);
\OC\Files\Filesystem::readfile($filename);
\OCA_Impress\Storage::showFooter();
Пример #14
0
 public function getListing($FOLDER, $showdel)
 {
     // Get the listing from the database
     $requery = false;
     $uid = \OCP\User::getUser();
     $query = \OCP\DB::prepare("SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name");
     $results = $query->execute(array($uid))->fetchAll();
     $results2 = $results;
     if ($results) {
         foreach ($results as $result) {
             foreach ($results2 as $result2) {
                 if ($result['id'] != $result2['id'] && $result['name'] == $result2['name'] && $result['grouping'] == $result2['grouping']) {
                     // We have a duplicate that should not exist. Need to remove the offending record first
                     $delid = -1;
                     if ($result['mtime'] == $result2['mtime']) {
                         // If the mtime's match, delete the oldest ID.
                         $delid = $result['id'];
                         if ($result['id'] > $result2['id']) {
                             $delid = $result2['id'];
                         }
                     } elseif ($result['mtime'] > $result2['mtime']) {
                         // Again, delete the oldest
                         $delid = $result2['id'];
                     } elseif ($result['mtime'] < $result2['mtime']) {
                         // The only thing left is if result is older
                         $delid = $result['id'];
                     }
                     if ($delid != -1) {
                         $delquery = \OCP\DB::prepare("DELETE FROM *PREFIX*ownnote WHERE id=?");
                         $delquery->execute(array($delid));
                         $requery = true;
                     }
                 }
             }
         }
     }
     if ($requery) {
         $query = \OCP\DB::prepare("SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name");
         $results = $query->execute(array($uid))->fetchAll();
         $requery = false;
     }
     // Tests to add a bunch of notes
     //$now = new DateTime();
     //for ($x = 0; $x < 199; $x++) {
     //saveNote('', "Test ".$x, '', '', $now->getTimestamp());
     //}
     $farray = array();
     if ($FOLDER != '') {
         // Create the folder if it doesn't exist
         if (!\OC\Files\Filesystem::is_dir($FOLDER)) {
             if (!\OC\Files\Filesystem::mkdir($FOLDER)) {
                 echo "ERROR: Could not create ownNote directory.";
                 exit;
             }
         }
         // Synchronize files to the database
         $filearr = array();
         if ($listing = \OC\Files\Filesystem::opendir($FOLDER)) {
             if (!$listing) {
                 echo "ERROR: Error listing directory.";
                 exit;
             }
             while (($file = readdir($listing)) !== false) {
                 $tmpfile = $file;
                 if ($tmpfile == "." || $tmpfile == "..") {
                     continue;
                 }
                 if (!$this->endsWith($tmpfile, ".htm") && !$this->endsWith($tmpfile, ".html")) {
                     continue;
                 }
                 if ($info = \OC\Files\Filesystem::getFileInfo($FOLDER . "/" . $tmpfile)) {
                     // Check for EVERNOTE but wait to rename them to get around:
                     // https://github.com/owncloud/core/issues/16202
                     if ($this->endsWith($tmpfile, ".html")) {
                         $this->checkEvernote($FOLDER, $tmpfile);
                     }
                     // Separate the name and group name
                     $name = preg_replace('/\\.[^.\\s]{3,4}$/', '', $tmpfile);
                     $group = "";
                     if (substr($name, 0, 1) == "[") {
                         $end = strpos($name, ']');
                         $group = substr($name, 1, $end - 1);
                         $name = substr($name, $end + 1, strlen($name) - $end + 1);
                         $name = trim($name);
                     }
                     // Set array for later checking
                     $filearr[] = $tmpfile;
                     // Check to see if the file is in the DB
                     $fileindb = false;
                     if ($results) {
                         foreach ($results as $result) {
                             if ($result['deleted'] == 0) {
                                 if ($name == $result['name'] && $group == $result['grouping']) {
                                     $fileindb = true;
                                     // If it is in the DB, check if the filesystem file is newer than the DB
                                     if ($result['mtime'] < $info['mtime']) {
                                         // File is newer, this could happen if a user updates a file
                                         $html = "";
                                         $html = \OC\Files\Filesystem::file_get_contents($FOLDER . "/" . $tmpfile);
                                         $this->saveNote('', $result['name'], $result['grouping'], $html, $info['mtime']);
                                         $requery = true;
                                     }
                                 }
                             }
                         }
                     }
                     if (!$fileindb) {
                         // If it's not in the DB, add it.
                         $html = "";
                         if ($html = \OC\Files\Filesystem::file_get_contents($FOLDER . "/" . $tmpfile)) {
                         } else {
                             $html = "";
                         }
                         $this->saveNote('', $name, $group, $html, $info['mtime']);
                         $requery = true;
                     }
                     // We moved the rename down here to overcome the OC issue
                     if ($this->endsWith($tmpfile, ".html")) {
                         $tmpfile = substr($tmpfile, 0, -1);
                         if (!\OC\Files\Filesystem::file_exists($FOLDER . "/" . $tmpfile)) {
                             \OC\Files\Filesystem::rename($FOLDER . "/" . $file, $FOLDER . "/" . $tmpfile);
                         }
                     }
                 }
             }
         }
         if ($requery) {
             $query = \OCP\DB::prepare("SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name");
             $results = $query->execute(array($uid))->fetchAll();
         }
         // Now also make sure the files exist, they may not if the user switched folders in admin.
         if ($results) {
             foreach ($results as $result) {
                 if ($result['deleted'] == 0) {
                     $tmpfile = $result['name'] . ".htm";
                     if ($result['grouping'] != '') {
                         $tmpfile = '[' . $result['grouping'] . '] ' . $result['name'] . '.htm';
                     }
                     $filefound = false;
                     foreach ($filearr as $f) {
                         if ($f == $tmpfile) {
                             $filefound = true;
                             break;
                         }
                     }
                     if (!$filefound) {
                         $content = $this->editNote($result['name'], $result['grouping']);
                         $this->saveNote($FOLDER, $result['name'], $result['grouping'], $content, 0);
                     }
                 }
             }
         }
     }
     // Now loop through and return the listing
     if ($results) {
         $count = 0;
         $now = new DateTime();
         $filetime = new DateTime();
         $l = \OCP\Util::getL10N('ownnote');
         foreach ($results as $result) {
             if ($result['deleted'] == 0 || $showdel == true) {
                 $filetime->setTimestamp($result['mtime']);
                 $timestring = $this->getTimeString($filetime, $now, $l);
                 $f = array();
                 $f['id'] = $result['id'];
                 $f['name'] = $result['name'];
                 $f['group'] = $result['grouping'];
                 $f['timestring'] = $timestring;
                 $f['mtime'] = $result['mtime'];
                 $f['timediff'] = $now->getTimestamp() - $result['mtime'];
                 $f['deleted'] = $result['deleted'];
                 $farray[$count] = $f;
                 $count++;
             }
         }
     }
     return $farray;
 }
Пример #15
0
function editNote($FOLDER, $id) {
	$ret = "";
	if ($html = \OC\Files\Filesystem::file_get_contents($FOLDER."/".$id)) {
		$ret = $html;
	}
	return $ret;
}
Пример #16
0
{
    global $progresskey;
    OC_Cache::set($progresskey, $pct, 300);
}
writeProgress('10');
$view = null;
$inputfile = strtr($_POST['file'], array('/' => '', "\\" => ''));
if (OC\Files\Filesystem::isFileBlacklisted($inputfile)) {
    OCP\JSON::error(array('data' => array('message' => 'Upload of blacklisted file: ' . $inputfile)));
    exit;
}
if (isset($_POST['fstype']) && $_POST['fstype'] == 'OC_FilesystemView') {
    $view = OCP\Files::getStorage('contacts');
    $file = $view->file_get_contents('/imports/' . $inputfile);
} else {
    $file = \OC\Files\Filesystem::file_get_contents($_POST['path'] . '/' . $inputfile);
}
if (!$file) {
    OCP\JSON::error(array('data' => array('message' => 'Import file was empty.')));
    exit;
}
if (isset($_POST['method']) && $_POST['method'] == 'new') {
    $id = OCA\Contacts\Addressbook::add(OCP\USER::getUser(), $_POST['addressbookname']);
    if (!$id) {
        OCP\JSON::error(array('data' => array('message' => 'Error creating address book.')));
        exit;
    }
    OCA\Contacts\Addressbook::setActive($id, 1);
} else {
    $id = $_POST['id'];
    if (!$id) {