diff options
Diffstat (limited to 'apps')
-rwxr-xr-x | apps/files_encryption/lib/helper.php | 51 | ||||
-rw-r--r-- | apps/files_encryption/lib/proxy.php | 12 | ||||
-rw-r--r-- | apps/files_encryption/lib/stream.php | 27 | ||||
-rw-r--r-- | apps/files_encryption/lib/util.php | 22 | ||||
-rw-r--r-- | apps/files_encryption/tests/helper.php | 15 | ||||
-rwxr-xr-x | apps/files_encryption/tests/util.php | 58 | ||||
-rw-r--r-- | apps/files_external/3rdparty/smb4php/smb.php | 3 | ||||
-rw-r--r-- | apps/user_ldap/css/settings.css | 18 | ||||
-rw-r--r-- | apps/user_ldap/js/settings.js | 93 | ||||
-rw-r--r-- | apps/user_ldap/templates/part.wizardcontrols.php | 3 |
10 files changed, 241 insertions, 61 deletions
diff --git a/apps/files_encryption/lib/helper.php b/apps/files_encryption/lib/helper.php index 314ac577b2f..0ac6fcf403a 100755 --- a/apps/files_encryption/lib/helper.php +++ b/apps/files_encryption/lib/helper.php @@ -165,7 +165,7 @@ class Helper { public static function isPartialFilePath($path) { $extension = pathinfo($path, PATHINFO_EXTENSION); - if ( $extension === 'part' || $extension === 'etmp') { + if ( $extension === 'part') { return true; } else { return false; @@ -183,7 +183,7 @@ class Helper { public static function stripPartialFileExtension($path) { $extension = pathinfo($path, PATHINFO_EXTENSION); - if ( $extension === 'part' || $extension === 'etmp') { + if ( $extension === 'part') { $newLength = strlen($path) - 5; // 5 = strlen(".part") = strlen(".etmp") $fPath = substr($path, 0, $newLength); @@ -256,24 +256,53 @@ class Helper { } /** - * @brief get path to the correspondig file in data/user/files + * @brief get path to the correspondig file in data/user/files if path points + * to a version or to a file in cache * @param string $path path to a version or a file in the trash * @return string path to correspondig file relative to data/user/files */ public static function getPathToRealFile($path) { $trimmed = ltrim($path, '/'); $split = explode('/', $trimmed); - - if (count($split) < 3 || $split[1] !== "files_versions") { - return false; + $result = false; + + if (count($split) >= 3 && ($split[1] === "files_versions" || $split[1] === 'cache')) { + $sliced = array_slice($split, 2); + $result = implode('/', $sliced); + if ($split[1] === "files_versions") { + // we skip user/files + $sliced = array_slice($split, 2); + $relPath = implode('/', $sliced); + //remove the last .v + $result = substr($relPath, 0, strrpos($relPath, '.v')); + } + if ($split[1] === "cache") { + // we skip /user/cache/transactionId + $sliced = array_slice($split, 3); + $result = implode('/', $sliced); + //prepare the folders + self::mkdirr($path, new \OC\Files\View('/')); + } } - $sliced = array_slice($split, 2); - $realPath = implode('/', $sliced); - //remove the last .v - $realPath = substr($realPath, 0, strrpos($realPath, '.v')); + return $result; + } - return $realPath; + /** + * @brief create directory recursively + * @param string $path + * @param \OC\Files\View $view + */ + public static function mkdirr($path, $view) { + $dirname = \OC_Filesystem::normalizePath(dirname($path)); + $dirParts = explode('/', $dirname); + $dir = ""; + foreach ($dirParts as $part) { + $dir = $dir . '/' . $part; + if (!$view->file_exists($dir)) { + $view->mkdir($dir); + } + } } /** diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index e2bc8f6b163..54c3b9caa15 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -90,7 +90,13 @@ class Proxy extends \OC_FileProxy { return true; } - $handle = fopen('crypt://' . $path . '.etmp', 'w'); + // create random cache folder + $cacheFolder = rand(); + $path_slices = explode('/', \OC_Filesystem::normalizePath($path)); + $path_slices[2] = "cache/".$cacheFolder; + $tmpPath = implode('/', $path_slices); + + $handle = fopen('crypt://' . $tmpPath, 'w'); if (is_resource($handle)) { // write data to stream @@ -104,10 +110,10 @@ class Proxy extends \OC_FileProxy { \OC_FileProxy::$enabled = false; // get encrypted content - $data = $view->file_get_contents($path . '.etmp'); + $data = $view->file_get_contents($tmpPath); // remove our temp file - $view->unlink($path . '.etmp'); + $view->deleteAll('/' . \OCP\User::getUser() . '/cache/' . $cacheFolder); // re-enable proxy - our work is done \OC_FileProxy::$enabled = $proxyStatus; diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php index 5ce5caf80ce..fe85b2eac4a 100644 --- a/apps/files_encryption/lib/stream.php +++ b/apps/files_encryption/lib/stream.php @@ -67,6 +67,7 @@ class Stream { * @var \OC\Files\View */ private $rootView; // a fsview object set to '/' + /** * @var \OCA\Encryption\Session */ @@ -108,7 +109,7 @@ class Stream { } if($this->relPath === false) { - \OCP\Util::writeLog('Encryption library', 'failed to open file "' . $this->rawPath . '" expecting a path to user/files or to user/files_versions', \OCP\Util::ERROR); + \OCP\Util::writeLog('Encryption library', 'failed to open file "' . $this->rawPath . '" expecting a path to "files", "files_versions" or "cache"', \OCP\Util::ERROR); return false; } @@ -528,20 +529,22 @@ class Stream { \OC_FileProxy::$enabled = $proxyStatus; } + // we need to update the file info for the real file, not for the + // part file. + $path = Helper::stripPartialFileExtension($this->rawPath); + // get file info - $fileInfo = $this->rootView->getFileInfo($this->rawPath); - if (!is_array($fileInfo)) { - $fileInfo = array(); + $fileInfo = $this->rootView->getFileInfo($path); + if (is_array($fileInfo)) { + // set encryption data + $fileInfo['encrypted'] = true; + $fileInfo['size'] = $this->size; + $fileInfo['unencrypted_size'] = $this->unencryptedSize; + + // set fileinfo + $this->rootView->putFileInfo($path, $fileInfo); } - // set encryption data - $fileInfo['encrypted'] = true; - $fileInfo['size'] = $this->size; - $fileInfo['unencrypted_size'] = $this->unencryptedSize; - - // set fileinfo - $this->rootView->putFileInfo($this->rawPath, $fileInfo); - } return fclose($this->handle); diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index f099a36d0c0..1af5e56e10b 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -717,17 +717,17 @@ class Util { // Encrypt unencrypted files foreach ($found['encrypted'] as $encryptedFile) { - //get file info - $fileInfo = \OC\Files\Filesystem::getFileInfo($encryptedFile['path']); - //relative to data/<user>/file $relPath = Helper::stripUserFilesPath($encryptedFile['path']); + //get file info + $fileInfo = \OC\Files\Filesystem::getFileInfo($relPath); + //relative to /data $rawPath = $encryptedFile['path']; //get timestamp - $timestamp = $this->view->filemtime($rawPath); + $timestamp = $fileInfo['mtime']; //enable proxy to use OC\Files\View to access the original file \OC_FileProxy::$enabled = true; @@ -768,10 +768,10 @@ class Util { $this->view->rename($relPath . '.part', $relPath); - $this->view->chroot($fakeRoot); - //set timestamp - $this->view->touch($rawPath, $timestamp); + $this->view->touch($relPath, $timestamp); + + $this->view->chroot($fakeRoot); // Add the file to the cache \OC\Files\Filesystem::putFileInfo($relPath, array( @@ -839,7 +839,7 @@ class Util { $rawPath = '/' . $this->userId . '/files/' . $plainFile['path']; // keep timestamp - $timestamp = $this->view->filemtime($rawPath); + $timestamp = $fileInfo['mtime']; // Open plain file handle for binary reading $plainHandle = $this->view->fopen($rawPath, 'rb'); @@ -858,10 +858,10 @@ class Util { $this->view->rename($relPath . '.part', $relPath); - $this->view->chroot($fakeRoot); - // set timestamp - $this->view->touch($rawPath, $timestamp); + $this->view->touch($relPath, $timestamp); + + $this->view->chroot($fakeRoot); // Add the file to the cache \OC\Files\Filesystem::putFileInfo($relPath, array( diff --git a/apps/files_encryption/tests/helper.php b/apps/files_encryption/tests/helper.php index 067fc763a95..cd2be70a8fe 100644 --- a/apps/files_encryption/tests/helper.php +++ b/apps/files_encryption/tests/helper.php @@ -51,4 +51,17 @@ class Test_Encryption_Helper extends \PHPUnit_Framework_TestCase { $this->assertEquals('testfile.txt', Encryption\Helper::stripPartialFileExtension($filename)); } -}
\ No newline at end of file + function testGetPathToRealFile() { + + // the relative path to /user/files/ that's what we want to get from getPathToRealFile() + $relativePath = "foo/bar/test.txt"; + + // test paths + $versionPath = "/user/files_versions/foo/bar/test.txt.v456756835"; + $cachePath = "/user/cache/transferid636483/foo/bar/test.txt"; + + $this->assertEquals($relativePath, Encryption\Helper::getPathToRealFile($versionPath)); + $this->assertEquals($relativePath, Encryption\Helper::getPathToRealFile($cachePath)); + } + +} diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php index 1b93bc36c8e..e8dfb74f3f3 100755 --- a/apps/files_encryption/tests/util.php +++ b/apps/files_encryption/tests/util.php @@ -281,6 +281,64 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase { $this->assertFalse($this->util->isSharedPath($path)); } + function testEncryptAll() { + + $filename = "/encryptAll" . time() . ".txt"; + $util = new Encryption\Util($this->view, $this->userId); + + // disable encryption to upload a unencrypted file + \OC_App::disable('files_encryption'); + + $this->view->file_put_contents($this->userId . '/files/' . $filename, $this->dataShort); + + $fileInfoUnencrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename); + + $this->assertTrue(is_array($fileInfoUnencrypted)); + + // enable file encryption again + \OC_App::enable('files_encryption'); + + // encrypt all unencrypted files + $util->encryptAll('/' . $this->userId . '/' . 'files'); + + $fileInfoEncrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename); + + $this->assertTrue(is_array($fileInfoEncrypted)); + + // check if mtime and etags unchanged + $this->assertEquals($fileInfoEncrypted['mtime'], $fileInfoUnencrypted['mtime']); + $this->assertEquals($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']); + + $this->view->unlink($this->userId . '/files/' . $filename); + } + + + function testDecryptAll() { + + $filename = "/decryptAll" . time() . ".txt"; + $util = new Encryption\Util($this->view, $this->userId); + + $this->view->file_put_contents($this->userId . '/files/' . $filename, $this->dataShort); + + $fileInfoEncrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename); + + $this->assertTrue(is_array($fileInfoEncrypted)); + + // encrypt all unencrypted files + $util->decryptAll('/' . $this->userId . '/' . 'files'); + + $fileInfoUnencrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename); + + $this->assertTrue(is_array($fileInfoUnencrypted)); + + // check if mtime and etags unchanged + $this->assertEquals($fileInfoEncrypted['mtime'], $fileInfoUnencrypted['mtime']); + $this->assertEquals($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']); + + $this->view->unlink($this->userId . '/files/' . $filename); + + } + /** * @large */ diff --git a/apps/files_external/3rdparty/smb4php/smb.php b/apps/files_external/3rdparty/smb4php/smb.php index e91b0a59581..1a6cd05590c 100644 --- a/apps/files_external/3rdparty/smb4php/smb.php +++ b/apps/files_external/3rdparty/smb4php/smb.php @@ -460,7 +460,8 @@ class smb_stream_wrapper extends smb { function stream_tell () { return ftell($this->stream); } - function stream_seek ($offset, $whence=null) { return fseek($this->stream, $offset, $whence); } + // PATCH: the wrapper must return true when fseek succeeded by returning 0. + function stream_seek ($offset, $whence=null) { return fseek($this->stream, $offset, $whence) === 0; } function stream_flush () { if ($this->mode <> 'r' && $this->need_flush) { diff --git a/apps/user_ldap/css/settings.css b/apps/user_ldap/css/settings.css index be03419c2de..490c3e95926 100644 --- a/apps/user_ldap/css/settings.css +++ b/apps/user_ldap/css/settings.css @@ -108,4 +108,22 @@ select[multiple=multiple] + button { padding-top: 6px !important; min-width: 40%; max-width: 40%; +} + +.ldap_config_state_indicator_sign { + display: inline-block; + height: 16px; + width: 16px; + vertical-align: text-bottom; +} +.ldap_config_state_indicator_sign.success { + background: #37ce02; + border-radius: 8px; +} +.ldap_config_state_indicator_sign.error { + background: #ce3702; +} + +.ldap_grey { + color: #777; }
\ No newline at end of file diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js index dcaeb70b57f..2fa0ed066c4 100644 --- a/apps/user_ldap/js/settings.js +++ b/apps/user_ldap/js/settings.js @@ -103,6 +103,20 @@ var LdapConfiguration = { ); }, + testConfiguration: function(onSuccess, onError) { + $.post( + OC.filePath('user_ldap','ajax','testConfiguration.php'), + $('#ldap').serialize(), + function (result) { + if (result.status === 'success') { + onSuccess(result); + } else { + onError(result); + } + } + ); + }, + clearMappings: function(mappingSubject) { $.post( OC.filePath('user_ldap','ajax','clearMappings.php'), @@ -187,6 +201,7 @@ var LdapWizard = { user = $('#ldap_dn').val(); pass = $('#ldap_agent_password').val(); + //FIXME: determine base dn with anonymous access if(host && port && user && pass) { param = 'action=guessBaseDN'+ '&ldap_serverconfig_chooser='+$('#ldap_serverconfig_chooser').val(); @@ -205,7 +220,7 @@ var LdapWizard = { function (result) { LdapWizard.hideSpinner('#ldap_base'); LdapWizard.showInfoBox('Please specify a Base DN'); - $('#ldap_base').prop('disabled', false); + LdapWizard.showInfoBox('Could not determine Base DN'); } ); } @@ -234,7 +249,7 @@ var LdapWizard = { function (result) { LdapWizard.hideSpinner('#ldap_port'); $('#ldap_port').prop('disabled', false); - LdapWizard.showInfoBox('Please specify the Port'); + LdapWizard.showInfoBox('Please specify the port'); } ); } @@ -428,14 +443,16 @@ var LdapWizard = { functionalityCheck: function() { //criterias to enable the connection: - // - host, port, user filter, login filter + // - host, port, basedn, user filter, login filter host = $('#ldap_host').val(); port = $('#ldap_port').val(); - userfilter = $('#ldap_dn').val(); - loginfilter = $('#ldap_agent_password').val(); + base = $('#ldap_base').val(); + userfilter = $('#ldap_userlist_filter').val(); + loginfilter = $('#ldap_login_filter').val(); //FIXME: activates a manually deactivated configuration. - if(host && port && userfilter && loginfilter) { + if(host && port && base && userfilter && loginfilter) { + LdapWizard.updateStatusIndicator(true); if($('#ldap_configuration_active').is(':checked')) { return; } @@ -446,6 +463,7 @@ var LdapWizard = { $('#ldap_configuration_active').prop('checked', false); LdapWizard.save($('#ldap_configuration_active')[0]); } + LdapWizard.updateStatusIndicator(false); } }, @@ -463,6 +481,7 @@ var LdapWizard = { init: function() { LdapWizard.basicStatusCheck(); + LdapWizard.functionalityCheck(); }, initGroupFilter: function() { @@ -543,6 +562,7 @@ var LdapWizard = { if($('#ldapSettings').tabs('option', 'active') == 0) { LdapWizard.basicStatusCheck(); + LdapWizard.functionalityCheck(); } }, @@ -643,6 +663,38 @@ var LdapWizard = { '#ldap_userfilter_groups', 'userFilterGroupSelectState' ); + }, + + updateStatusIndicator: function(isComplete) { + if(isComplete) { + LdapConfiguration.testConfiguration( + //onSuccess + function(result) { + $('.ldap_config_state_indicator').text(t('user_ldap', + 'Configuration OK' + )); + $('.ldap_config_state_indicator').addClass('ldap_grey'); + $('.ldap_config_state_indicator_sign').removeClass('error'); + $('.ldap_config_state_indicator_sign').addClass('success'); + }, + //onError + function(result) { + $('.ldap_config_state_indicator').text(t('user_ldap', + 'Configuration incorrect' + )); + $('.ldap_config_state_indicator').removeClass('ldap_grey'); + $('.ldap_config_state_indicator_sign').addClass('error'); + $('.ldap_config_state_indicator_sign').removeClass('success'); + } + ); + } else { + $('.ldap_config_state_indicator').text(t('user_ldap', + 'Configuration incomplete' + )); + $('.ldap_config_state_indicator').removeClass('ldap_grey'); + $('.ldap_config_state_indicator_sign').removeClass('error'); + $('.ldap_config_state_indicator_sign').removeClass('success'); + } } }; @@ -681,21 +733,20 @@ $(document).ready(function() { }); $('.ldap_action_test_connection').click(function(event){ event.preventDefault(); - $.post( - OC.filePath('user_ldap','ajax','testConfiguration.php'), - $('#ldap').serialize(), - function (result) { - if (result.status === 'success') { - OC.dialogs.alert( - result.message, - t('user_ldap', 'Connection test succeeded') - ); - } else { - OC.dialogs.alert( - result.message, - t('user_ldap', 'Connection test failed') - ); - } + LdapConfiguration.testConfiguration( + //onSuccess + function(result) { + OC.dialogs.alert( + result.message, + t('user_ldap', 'Connection test succeeded') + ); + }, + //onError + function(result) { + OC.dialogs.alert( + result.message, + t('user_ldap', 'Connection test failed') + ); } ); }); diff --git a/apps/user_ldap/templates/part.wizardcontrols.php b/apps/user_ldap/templates/part.wizardcontrols.php index db99145d514..f17b362c737 100644 --- a/apps/user_ldap/templates/part.wizardcontrols.php +++ b/apps/user_ldap/templates/part.wizardcontrols.php @@ -1,4 +1,5 @@ <div class="ldapWizardControls"> + <span class="ldap_config_state_indicator"></span> <span class="ldap_config_state_indicator_sign"></span> <button class="ldap_action_back invisible" name="ldap_action_back" type="button"> <?php p($l->t('Back'));?> @@ -10,6 +11,6 @@ target="_blank"> <img src="<?php print_unescaped(OCP\Util::imagePath('', 'actions/info.png')); ?>" style="height:1.75ex" /> - <?php p($l->t('Help'));?> + <span class="ldap_grey"><?php p($l->t('Help'));?></span> </a> </div>
\ No newline at end of file |