public function fopen($path, $mode) { switch ($mode) { case 'r': case 'rb': case 'w': case 'wb': case 'a': case 'ab': //these are supported by the wrapper $context = stream_context_create(array('ftp' => array('overwrite' => true))); return fopen($this->constructUrl($path), $mode, false, $context); case 'r+': case 'w+': case 'wb+': case 'a+': case 'x': case 'x+': case 'c': case 'c+': //emulate these if (strrpos($path, '.') !== false) { $ext = substr($path, strrpos($path, '.')); } else { $ext = ''; } $tmpFile = OCP\Files::tmpFile($ext); OC_CloseStreamWrapper::$callBacks[$tmpFile] = array($this, 'writeBack'); if ($this->file_exists($path)) { $this->getFile($path, $tmpFile); } self::$tempFiles[$tmpFile] = $path; return fopen('close://' . $tmpFile, $mode); } }
public function testContent() { $this->instance = $this->getExisting(); $dir = OC::$SERVERROOT . '/tests/data'; $textFile = $dir . '/lorem.txt'; $this->assertEquals(file_get_contents($textFile), $this->instance->getFile('lorem.txt')); $tmpFile = OCP\Files::tmpFile('.txt'); $this->instance->extractFile('lorem.txt', $tmpFile); $this->assertEquals(file_get_contents($textFile), file_get_contents($tmpFile)); }
/** * get a cryptstream to a temporary file * @param string $id * @param string $mode * @return resource */ function getStream($id, $mode) { if ($id === '') { $id = uniqid(); } if (!isset($this->tmpFiles[$id])) { $file = OCP\Files::tmpFile(); $this->tmpFiles[$id] = $file; } else { $file = $this->tmpFiles[$id]; } $stream = fopen($file, $mode); OC_CryptStream::$sourceStreams[$id] = array('path' => 'dummy', 'stream' => $stream); return fopen('crypt://streams/' . $id, $mode); }
function testEncryption() { $key = uniqid(); $file = OC::$SERVERROOT . '/3rdparty/MDB2.php'; $source = file_get_contents($file); //nice large text file $encrypted = OC_Crypt::encrypt($source, $key); $decrypted = OC_Crypt::decrypt($encrypted, $key); $decrypted = rtrim($decrypted, ""); $this->assertNotEqual($encrypted, $source); $this->assertEqual($decrypted, $source); $chunk = substr($source, 0, 8192); $encrypted = OC_Crypt::encrypt($chunk, $key); $this->assertEqual(strlen($chunk), strlen($encrypted)); $decrypted = OC_Crypt::decrypt($encrypted, $key); $decrypted = rtrim($decrypted, ""); $this->assertEqual($decrypted, $chunk); $encrypted = OC_Crypt::blockEncrypt($source, $key); $decrypted = OC_Crypt::blockDecrypt($encrypted, $key); $this->assertNotEqual($encrypted, $source); $this->assertEqual($decrypted, $source); $tmpFileEncrypted = OCP\Files::tmpFile(); OC_Crypt::encryptfile($file, $tmpFileEncrypted, $key); $encrypted = file_get_contents($tmpFileEncrypted); $decrypted = OC_Crypt::blockDecrypt($encrypted, $key); $this->assertNotEqual($encrypted, $source); $this->assertEqual($decrypted, $source); $tmpFileDecrypted = OCP\Files::tmpFile(); OC_Crypt::decryptfile($tmpFileEncrypted, $tmpFileDecrypted, $key); $decrypted = file_get_contents($tmpFileDecrypted); $this->assertEqual($decrypted, $source); $file = OC::$SERVERROOT . '/core/img/weather-clear.png'; $source = file_get_contents($file); //binary file $encrypted = OC_Crypt::encrypt($source, $key); $decrypted = OC_Crypt::decrypt($encrypted, $key); $decrypted = rtrim($decrypted, ""); $this->assertEqual($decrypted, $source); $encrypted = OC_Crypt::blockEncrypt($source, $key); $decrypted = OC_Crypt::blockDecrypt($encrypted, $key); $this->assertEqual($decrypted, $source); }
/** * get a file handler * * @param string $path * @param string $mode * @return resource */ function getStream($path, $mode) { if (strrpos($path, '.') !== false) { $ext = substr($path, strrpos($path, '.')); } else { $ext = ''; } $tmpFile = OCP\Files::tmpFile($ext); if ($this->fileExists($path)) { $this->extractFile($path, $tmpFile); } elseif ($mode == 'r' or $mode == 'rb') { return false; } if ($mode == 'r' or $mode == 'rb') { return fopen($tmpFile, $mode); } else { \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack')); self::$tempFiles[$tmpFile] = $path; return fopen('close://' . $tmpFile, $mode); } }
protected function getNew() { return new OC_Archive_TAR(OCP\Files::tmpFile('.tar.gz')); }
protected function getNew() { return new OC_Archive_ZIP(OCP\Files::tmpFile('.zip')); }
/** * get a file handler * @param string path * @param string mode * @return resource */ function getStream($path, $mode) { if ($mode == 'r' or $mode == 'rb') { return $this->zip->getStream($path); } else { //since we cant directly get a writable stream, //make a temp copy of the file and put it back //in the archive when the stream is closed if (strrpos($path, '.') !== false) { $ext = substr($path, strrpos($path, '.')); } else { $ext = ''; } $tmpFile = OCP\Files::tmpFile($ext); OC_CloseStreamWrapper::$callBacks[$tmpFile] = array($this, 'writeBack'); if ($this->fileExists($path)) { $this->extractFile($path, $tmpFile); } self::$tempFiles[$tmpFile] = $path; return fopen('close://' . $tmpFile, $mode); } }
private function getTmpFile($path) { $obj = $this->getObject($path); if (!is_null($obj)) { $tmpFile = OCP\Files::tmpFile(); $obj->save_to_filename($tmpFile); return $tmpFile; } else { return false; } }
public function fopen($path, $mode) { $path = $this->cleanPath($path); switch ($mode) { case 'r': case 'rb': //straight up curl instead of sabredav here, sabredav put's the entire get result in memory $curl = curl_init(); $fp = fopen('php://temp', 'r+'); curl_setopt($curl, CURLOPT_USERPWD, $this->user . ':' . $this->password); curl_setopt($curl, CURLOPT_URL, $this->createBaseUri() . $path); curl_setopt($curl, CURLOPT_FILE, $fp); curl_exec($curl); curl_close($curl); rewind($fp); return $fp; case 'w': case 'wb': case 'a': case 'ab': case 'r+': case 'w+': case 'wb+': case 'a+': case 'x': case 'x+': case 'c': case 'c+': //emulate these if (strrpos($path, '.') !== false) { $ext = substr($path, strrpos($path, '.')); } else { $ext = ''; } $tmpFile = OCP\Files::tmpFile($ext); OC_CloseStreamWrapper::$callBacks[$tmpFile] = array($this, 'writeBack'); if ($this->file_exists($path)) { $this->getFile($path, $tmpFile); } self::$tempFiles[$tmpFile] = $path; return fopen('close://' . $tmpFile, $mode); } }
public function setUp() { $this->tmpFile = OCP\Files::tmpFile('.tar.gz'); $this->instance = new OC_Filestorage_Archive(array('archive' => $this->tmpFile)); }
public function touch($path, $mtime = null) { if (is_null($mtime)) { $tmpFile = OCP\Files::tmpFile(); $this->archive->extractFile($path, $tmpFile); $this->archive->addfile($path, $tmpFile); } else { return false; //not supported } }