From 9ecfd07f23e7fe2924bee6103792c00c6ec3cb0a Mon Sep 17 00:00:00 2001
From: Sam Tuke
Date: Thu, 28 Mar 2013 18:29:18 +0100
Subject: Added ajax scripts for setting pwd recovery preferences
---
apps/files_encryption/ajax/userrecovery.php | 42 +++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
create mode 100644 apps/files_encryption/ajax/userrecovery.php
(limited to 'apps/files_encryption/ajax/userrecovery.php')
diff --git a/apps/files_encryption/ajax/userrecovery.php b/apps/files_encryption/ajax/userrecovery.php
new file mode 100644
index 00000000000..56c18f7ad5b
--- /dev/null
+++ b/apps/files_encryption/ajax/userrecovery.php
@@ -0,0 +1,42 @@
+setValue( $app, $key, $value )
+
+
+ * This file is licensed under the Affero General Public License version 3 or later.
+ * See the COPYING-README file.
+ *
+ * @brief Script to handle admin settings for encrypted key recovery
+ */
+
+use OCA\Encryption;
+
+\OCP\JSON::checkLoggedIn();
+\OCP\JSON::checkAppEnabled( 'files_encryption' );
+\OCP\JSON::callCheck();
+
+if (
+ isset( $_POST['userEnableRecovery'] )
+) {
+
+ // Ensure preference is an integer
+ $recoveryEnabled = intval( $_POST['userEnableRecovery'] );
+
+ $userId = \OCP\USER::getUser();
+ $view = new \OC_FilesystemView( '/' );
+ $util = new Util( $view, $userId );
+
+ // Save recovery preference to DB
+ $result = $util->setRecovery( $recoveryEnabled );
+
+ if ( $result ) {
+
+ \OCP\JSON::success();
+
+ } else {
+
+ \OCP\JSON::error();
+
+ }
+
+}
\ No newline at end of file
--
cgit v1.2.3
From ba29147e34a22142c4bfd2afa3f5b9f1e6efcd63 Mon Sep 17 00:00:00 2001
From: Sam Tuke
Date: Wed, 1 May 2013 19:18:31 +0200
Subject: Fixed recoveryadmin settings in user and admin settings pages (js,
templates, ajax) Renamed recovery methods in Util{} for clarity Added note
about bug causing slow page load and redundant keypair generation
recoveryAdmin functionality not yet complete
---
apps/files_encryption/ajax/adminrecovery.php | 27 ++++++--
apps/files_encryption/ajax/userrecovery.php | 9 +--
apps/files_encryption/appinfo/app.php | 4 +-
apps/files_encryption/js/settings-admin.js | 37 ++++++++++
apps/files_encryption/js/settings-personal.js | 23 +++++++
apps/files_encryption/js/settings.js | 36 ----------
apps/files_encryption/lib/keymanager.php | 2 +-
apps/files_encryption/lib/session.php | 18 +++--
apps/files_encryption/lib/util.php | 79 ++++++++++++++--------
apps/files_encryption/settings-admin.php | 28 ++++++++
apps/files_encryption/settings-personal.php | 20 ++++++
apps/files_encryption/settings.php | 27 --------
apps/files_encryption/templates/settings-admin.php | 39 +++++++++++
.../templates/settings-personal.php | 22 ++++++
apps/files_encryption/templates/settings.php | 39 -----------
apps/files_encryption/tests/util.php | 14 ++--
16 files changed, 267 insertions(+), 157 deletions(-)
create mode 100644 apps/files_encryption/js/settings-admin.js
create mode 100644 apps/files_encryption/js/settings-personal.js
delete mode 100644 apps/files_encryption/js/settings.js
create mode 100644 apps/files_encryption/settings-admin.php
delete mode 100644 apps/files_encryption/settings.php
create mode 100644 apps/files_encryption/templates/settings-admin.php
delete mode 100644 apps/files_encryption/templates/settings.php
(limited to 'apps/files_encryption/ajax/userrecovery.php')
diff --git a/apps/files_encryption/ajax/adminrecovery.php b/apps/files_encryption/ajax/adminrecovery.php
index cec0cd4ddda..157fc8f313c 100644
--- a/apps/files_encryption/ajax/adminrecovery.php
+++ b/apps/files_encryption/ajax/adminrecovery.php
@@ -17,11 +17,12 @@ use OCA\Encryption;
$return = $doSetup = false;
+// Enable recoveryAdmin
if (
isset( $_POST['adminEnableRecovery'] )
- && $_POST['adminEnableRecovery'] == 1
- && isset( $_POST['recoveryPassword'] )
- && ! empty ( $_POST['recoveryPassword'] )
+ && 1 == $_POST['adminEnableRecovery']
+// && isset( $_POST['recoveryPassword'] )
+// && ! empty ( $_POST['recoveryPassword'] )
) {
// TODO: Let the admin set this themselves
@@ -29,7 +30,7 @@ if (
// If desired recoveryAdmin UID is already in use
if ( ! \OC_User::userExists( $recoveryAdminUid ) ) {
-
+
// Create new recoveryAdmin user
\OC_User::createUser( $recoveryAdminUid, $_POST['recoveryPassword'] );
@@ -55,11 +56,11 @@ if (
}
- // If recoveryAdmin has passed other checks
+ // Setup recoveryAdmin user for encryption
if ( $doSetup ) {
$view = new \OC_FilesystemView( '/' );
- $util = new Util( $view, $recoveryAdminUid );
+ $util = new \OCA\Encryption\Util( $view, $recoveryAdminUid );
// Ensure recoveryAdmin is ready for encryption (has usable keypair etc.)
$util->setupServerSide( $_POST['recoveryPassword'] );
@@ -71,6 +72,20 @@ if (
}
+ // Set recoveryAdmin as enabled
+ OC_Appconfig::setValue( 'files_encryption', 'recoveryAdminEnabled', 1 );
+
+// Disable recoveryAdmin
+} elseif (
+ isset( $_POST['adminEnableRecovery'] )
+ && 0 == $_POST['adminEnableRecovery']
+) {
+
+ // Set recoveryAdmin as enabled
+ OC_Appconfig::setValue( 'files_encryption', 'recoveryAdminEnabled', 0 );
+
+ $return = true;
+
}
($return) ? OC_JSON::success() : OC_JSON::error();
\ No newline at end of file
diff --git a/apps/files_encryption/ajax/userrecovery.php b/apps/files_encryption/ajax/userrecovery.php
index 56c18f7ad5b..f72be3181ef 100644
--- a/apps/files_encryption/ajax/userrecovery.php
+++ b/apps/files_encryption/ajax/userrecovery.php
@@ -13,21 +13,18 @@ use OCA\Encryption;
\OCP\JSON::checkLoggedIn();
\OCP\JSON::checkAppEnabled( 'files_encryption' );
-\OCP\JSON::callCheck();
if (
isset( $_POST['userEnableRecovery'] )
+ && ( 0 == $_POST['userEnableRecovery'] || 1 == $_POST['userEnableRecovery'] )
) {
- // Ensure preference is an integer
- $recoveryEnabled = intval( $_POST['userEnableRecovery'] );
-
$userId = \OCP\USER::getUser();
$view = new \OC_FilesystemView( '/' );
- $util = new Util( $view, $userId );
+ $util = new \OCA\Encryption\Util( $view, $userId );
// Save recovery preference to DB
- $result = $util->setRecovery( $recoveryEnabled );
+ $result = $util->setRecoveryForUser( $_POST['userEnableRecovery'] );
if ( $result ) {
diff --git a/apps/files_encryption/appinfo/app.php b/apps/files_encryption/appinfo/app.php
index 9ae6c8331f8..a7253c43332 100644
--- a/apps/files_encryption/appinfo/app.php
+++ b/apps/files_encryption/appinfo/app.php
@@ -28,7 +28,7 @@ OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OCA\Encryption\Hooks', 'p
stream_wrapper_register( 'crypt', 'OCA\Encryption\Stream' );
-$view = new OC_FilesystemView( '/' );
+$view = new \OC\Files\View( '/' );
$session = new OCA\Encryption\Session( $view );
@@ -50,5 +50,5 @@ if (
}
// Register settings scripts
-OCP\App::registerAdmin( 'files_encryption', 'settings' );
+OCP\App::registerAdmin( 'files_encryption', 'settings-admin' );
OCP\App::registerPersonal( 'files_encryption', 'settings-personal' );
diff --git a/apps/files_encryption/js/settings-admin.js b/apps/files_encryption/js/settings-admin.js
new file mode 100644
index 00000000000..48b5598d524
--- /dev/null
+++ b/apps/files_encryption/js/settings-admin.js
@@ -0,0 +1,37 @@
+/**
+ * Copyright (c) 2013, Sam Tuke , Robin Appelman
+ *
+ * This file is licensed under the Affero General Public License version 3 or later.
+ * See the COPYING-README file.
+ */
+
+
+$(document).ready(function(){
+ // Trigger ajax on filetype blacklist change
+ $('#encryption_blacklist').multiSelect({
+ oncheck:blackListChange,
+ onuncheck:blackListChange,
+ createText:'...'
+ });
+
+ // Trigger ajax on recoveryAdmin status change
+ $( 'input:radio[name="adminEnableRecovery"]' ).change(
+ function() {
+
+ var recoveryStatus = $( this ).val();
+
+ $.post(
+ OC.filePath( 'files_encryption', 'ajax', 'adminrecovery.php' )
+ , { adminEnableRecovery: recoveryStatus, recoveryPassword: 'password' }
+ , function( data ) {
+ alert( data );
+ }
+ );
+ }
+ );
+
+ function blackListChange(){
+ var blackList=$( '#encryption_blacklist' ).val().join( ',' );
+ OC.AppConfig.setValue( 'files_encryption', 'type_blacklist', blackList );
+ }
+})
\ No newline at end of file
diff --git a/apps/files_encryption/js/settings-personal.js b/apps/files_encryption/js/settings-personal.js
new file mode 100644
index 00000000000..e4a1b7448f4
--- /dev/null
+++ b/apps/files_encryption/js/settings-personal.js
@@ -0,0 +1,23 @@
+/**
+ * Copyright (c) 2013, Sam Tuke
+ * This file is licensed under the Affero General Public License version 3 or later.
+ * See the COPYING-README file.
+ */
+
+$(document).ready(function(){
+ // Trigger ajax on recoveryAdmin status change
+ $( 'input:radio[name="userEnableRecovery"]' ).change(
+ function() {
+
+ var recoveryStatus = $( this ).val();
+
+ $.post(
+ OC.filePath( 'files_encryption', 'ajax', 'userrecovery.php' )
+ , { userEnableRecovery: recoveryStatus }
+ , function( data ) {
+ alert( data );
+ }
+ );
+ }
+ );
+})
\ No newline at end of file
diff --git a/apps/files_encryption/js/settings.js b/apps/files_encryption/js/settings.js
deleted file mode 100644
index 9a0bebf2478..00000000000
--- a/apps/files_encryption/js/settings.js
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * Copyright (c) 2011, Robin Appelman
- * This file is licensed under the Affero General Public License version 3 or later.
- * See the COPYING-README file.
- */
-
-
-$(document).ready(function(){
- // Trigger ajax on filetype blacklist change
- $('#encryption_blacklist').multiSelect({
- oncheck:blackListChange,
- onuncheck:blackListChange,
- createText:'...'
- });
-
- // Trigger ajax on recoveryAdmin status change
- $( 'input:radio[name="adminEnableRecovery"]' ).change(
- function() {
-
- var foo = $( this ).val();
-
- $.post(
- OC.filePath('files_encryption', 'ajax', 'adminrecovery.php')
- , { adminEnableRecovery: foo, recoveryPassword: 'password' }
- , function( data ) {
- alert( data );
- }
- );
- }
- );
-
- function blackListChange(){
- var blackList=$('#encryption_blacklist').val().join(',');
- OC.AppConfig.setValue('files_encryption','type_blacklist',blackList);
- }
-})
\ No newline at end of file
diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php
index 9f3cb8120ca..51d4f8ffc04 100755
--- a/apps/files_encryption/lib/keymanager.php
+++ b/apps/files_encryption/lib/keymanager.php
@@ -32,7 +32,7 @@ class Keymanager {
/**
* @brief retrieve the ENCRYPTED private key from a user
*
- * @return string private key or false
+ * @return string private key or false (hopefully)
* @note the key returned by this method must be decrypted before use
*/
public static function getPrivateKey( \OC_FilesystemView $view, $user ) {
diff --git a/apps/files_encryption/lib/session.php b/apps/files_encryption/lib/session.php
index 0c6a7131fd9..0e6bb96605f 100644
--- a/apps/files_encryption/lib/session.php
+++ b/apps/files_encryption/lib/session.php
@@ -35,22 +35,28 @@ class Session {
*
* The ownCloud key pair is used to allow public link sharing even if encryption is enabled
*/
- public function __construct( \OC_FilesystemView $view ) {
+ public function __construct( $view ) {
$this->view = $view;
if ( ! $this->view->is_dir( 'owncloud_private_key' ) ) {
- $this->view->mkdir('owncloud_private_key');
+ $this->view->mkdir( 'owncloud_private_key' );
+
}
-
if (
- ! $this->view->file_exists("/public-keys/owncloud.public.key")
- || ! $this->view->file_exists("/owncloud_private_key/owncloud.private.key" )
+ ! $this->view->file_exists( "/public-keys/owncloud.public.key" )
+ || ! $this->view->file_exists( "/owncloud_private_key/owncloud.private.key" )
) {
-
+
+ //FIXME: Bug: for some reason file_exists is returning
+ // false in above if statement, and causing new keys
+ // to be generated on each page load. At last check
+ // our app.php is being executed 18 times per page load
+ // , causing 18 new keypairs and huge performance hit.
+
$keypair = Crypt::createKeypair();
\OC_FileProxy::$enabled = false;
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index eabb34f7ab0..015125370bc 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -24,11 +24,8 @@
# Bugs
# ----
# Sharing a file to a user without encryption set up will not provide them with access but won't notify the sharer
-# Timeouts on first login due to encryption of very large files (fix in progress, as a result streaming is currently broken)
# Sharing all files to admin for recovery purposes still in progress
# Possibly public links are broken (not tested since last merge of master)
-# encryptAll during login mangles paths: /files/files/
-# encryptAll is accessing files via encryption proxy - perhaps proxies should be disabled?
# Missing features
@@ -204,12 +201,18 @@ class Util {
$this->view->file_put_contents( $this->privateKeyPath, $encryptedPrivateKey );
\OC_FileProxy::$enabled = true;
-
- // create database configuration
- $sql = 'INSERT INTO `*PREFIX*encryption` (`uid`,`mode`,`recovery`) VALUES (?,?,?)';
- $args = array( $this->userId, 'server-side', 0);
- $query = \OCP\DB::prepare( $sql );
- $query->execute( $args );
+
+ }
+
+ // If there's no record for this user's encryption preferences
+ if ( false === $this->recoveryEnabledForUser() ) {
+
+ // create database configuration
+ $sql = 'INSERT INTO `*PREFIX*encryption` (`uid`,`mode`,`recovery`) VALUES (?,?,?)';
+ $args = array( $this->userId, 'server-side', 0);
+ $query = \OCP\DB::prepare( $sql );
+ $query->execute( $args );
+
}
return true;
@@ -218,11 +221,11 @@ class Util {
/**
* @brief Check whether pwd recovery is enabled for a given user
- * @return bool
+ * @return 1 = yes, 0 = no, false = no record
* @note If records are not being returned, check for a hidden space
* at the start of the uid in db
*/
- public function recoveryEnabled() {
+ public function recoveryEnabledForUser() {
$sql = 'SELECT
recovery
@@ -237,16 +240,25 @@ class Util {
$result = $query->execute( $args );
- // Set default in case no records found
- $recoveryEnabled = 0;
+ $recoveryEnabled = array();
while( $row = $result->fetchRow() ) {
- $recoveryEnabled = $row['recovery'];
+ $recoveryEnabled[] = $row['recovery'];
}
- return $recoveryEnabled;
+ // If no record is found
+ if ( empty( $recoveryEnabled ) ) {
+
+ return false;
+
+ // If a record is found
+ } else {
+
+ return $recoveryEnabled[0];
+
+ }
}
@@ -255,20 +267,33 @@ class Util {
* @param bool $enabled Whether to enable or disable recovery
* @return bool
*/
- public function setRecovery( $enabled ) {
+ public function setRecoveryForUser( $enabled ) {
- $sql = 'UPDATE
- *PREFIX*encryption
- SET
- recovery = ?
- WHERE
- uid = ?';
+ $recoveryStatus = $this->recoveryEnabledForUser();
+
+ // If a record for this user already exists, update it
+ if ( false === $recoveryStatus ) {
- // Ensure value is an integer
- $enabled = intval( $enabled );
+ $sql = 'INSERT INTO `*PREFIX*encryption`
+ (`uid`,`mode`,`recovery`)
+ VALUES (?,?,?)';
+
+ $args = array( $this->userId, 'server-side', $enabled );
- $args = array( $enabled, $this->userId );
-
+ // Create a new record instead
+ } else {
+
+ $sql = 'UPDATE
+ *PREFIX*encryption
+ SET
+ recovery = ?
+ WHERE
+ uid = ?';
+
+ $args = array( $enabled, $this->userId );
+
+ }
+
$query = \OCP\DB::prepare( $sql );
if ( $query->execute( $args ) ) {
@@ -888,7 +913,7 @@ class Util {
public function getSharingUsersArray( $sharingEnabled, $filePath, $currentUserId = false ) {
// Check if key recovery is enabled
- $recoveryEnabled = $this->recoveryEnabled();
+ $recoveryEnabled = $this->recoveryEnabledForUser();
// Make sure that a share key is generated for the owner too
list($owner, $ownerPath) = $this->getUidAndFilename($filePath);
diff --git a/apps/files_encryption/settings-admin.php b/apps/files_encryption/settings-admin.php
new file mode 100644
index 00000000000..b09515f0c33
--- /dev/null
+++ b/apps/files_encryption/settings-admin.php
@@ -0,0 +1,28 @@
+
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+\OC_Util::checkAdminUser();
+
+$tmpl = new OCP\Template( 'files_encryption', 'settings-admin' );
+
+$blackList = explode( ',', \OCP\Config::getAppValue( 'files_encryption', 'type_blacklist', '' ) );
+
+// Check if an adminRecovery account is enabled for recovering files after lost pwd
+$view = new OC_FilesystemView( '' );
+
+$recoveryAdminEnabled = OC_Appconfig::getValue( 'files_encryption', 'recoveryAdminEnabled' );
+$recoveryAdminUid = OC_Appconfig::getValue( 'files_encryption', 'recoveryAdminUid' );
+
+$tmpl->assign( 'blacklist', $blackList );
+$tmpl->assign( 'encryption_mode', \OC_Appconfig::getValue( 'files_encryption', 'mode', 'none' ) );
+$tmpl->assign( 'recoveryEnabled', $recoveryAdminEnabled );
+
+\OCP\Util::addscript( 'files_encryption', 'settings-admin' );
+\OCP\Util::addscript( 'core', 'multiselect' );
+
+return $tmpl->fetchPage();
diff --git a/apps/files_encryption/settings-personal.php b/apps/files_encryption/settings-personal.php
index c001bb0d725..f7ebc425120 100644
--- a/apps/files_encryption/settings-personal.php
+++ b/apps/files_encryption/settings-personal.php
@@ -10,6 +10,26 @@ $tmpl = new OCP\Template( 'files_encryption', 'settings-personal');
$blackList = explode( ',', \OCP\Config::getAppValue( 'files_encryption', 'type_blacklist', '' ) );
+// Add human readable message in case nothing is blacklisted
+if (
+ 1 == count( $blackList )
+ && $blackList[0] == ''
+) {
+
+ // FIXME: Make this string translatable
+ $blackList[0] = "(None - all filetypes will be encrypted)";
+
+}
+
+$user = \OCP\USER::getUser();
+$view = new \OC_FilesystemView( '/' );
+$util = new \OCA\Encryption\Util( $view, $user );
+
+$recoveryEnabledForUser = $util->recoveryEnabledForUser();
+
+\OCP\Util::addscript( 'files_encryption', 'settings-personal' );
+
+$tmpl->assign( 'recoveryEnabled', $recoveryEnabledForUser );
$tmpl->assign( 'blacklist', $blackList );
return $tmpl->fetchPage();
diff --git a/apps/files_encryption/settings.php b/apps/files_encryption/settings.php
deleted file mode 100644
index 71d47f061af..00000000000
--- a/apps/files_encryption/settings.php
+++ /dev/null
@@ -1,27 +0,0 @@
-
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-\OC_Util::checkAdminUser();
-
-$tmpl = new OCP\Template( 'files_encryption', 'settings' );
-
-$blackList = explode( ',', \OCP\Config::getAppValue( 'files_encryption', 'type_blacklist', '' ) );
-
-// Check if an adminRecovery account is enabled for recovering files after lost pwd
-$view = new OC_FilesystemView( '' );
-$util = new \OCA\Encryption\Util( $view, \OCP\USER::getUser() );
-$recoveryEnabled = $util->recoveryEnabled();
-
-$tmpl->assign( 'blacklist', $blackList );
-$tmpl->assign( 'encryption_mode', \OC_Appconfig::getValue( 'files_encryption', 'mode', 'none' ) );
-$tmpl->assign( 'recoveryEnabled', $recoveryEnabled );
-
-\OCP\Util::addscript( 'files_encryption', 'settings' );
-\OCP\Util::addscript( 'core', 'multiselect' );
-
-return $tmpl->fetchPage();
diff --git a/apps/files_encryption/templates/settings-admin.php b/apps/files_encryption/templates/settings-admin.php
new file mode 100644
index 00000000000..6499d0c8e80
--- /dev/null
+++ b/apps/files_encryption/templates/settings-admin.php
@@ -0,0 +1,39 @@
+
diff --git a/apps/files_encryption/templates/settings-personal.php b/apps/files_encryption/templates/settings-personal.php
index 5f0accaed5f..0cefde36b61 100644
--- a/apps/files_encryption/templates/settings-personal.php
+++ b/apps/files_encryption/templates/settings-personal.php
@@ -3,6 +3,7 @@
+
t( 'File encryption is enabled.' )); ?>
@@ -10,6 +11,7 @@
t( 'The following file types will not be encrypted:' )); ?>
+
+
+
+ t( "Enable password recovery by sharing all files with administrator:" )); ?>
+
+ />
+ t( "Enabled" )); ?>
+
+
+ />
+ t( "Disabled" )); ?>
+
+
diff --git a/apps/files_encryption/templates/settings.php b/apps/files_encryption/templates/settings.php
deleted file mode 100644
index 6499d0c8e80..00000000000
--- a/apps/files_encryption/templates/settings.php
+++ /dev/null
@@ -1,39 +0,0 @@
-
diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php
index e3ec0860fa5..d0a988f96b9 100755
--- a/apps/files_encryption/tests/util.php
+++ b/apps/files_encryption/tests/util.php
@@ -179,23 +179,23 @@ class Test_Enc_Util extends \PHPUnit_Framework_TestCase {
}
- function testRecoveryEnabled() {
+ function testRecoveryEnabledForUser() {
$util = new Encryption\Util( $this->view, $this->userId );
// Record the value so we can return it to it's original state later
- $enabled = $util->recoveryEnabled();
+ $enabled = $util->recoveryEnabledForUser();
- $this->assertTrue( $util->setRecovery( 1 ) );
+ $this->assertTrue( $util->setRecoveryForUser( 1 ) );
- $this->assertEquals( 1, $util->recoveryEnabled() );
+ $this->assertEquals( 1, $util->recoveryEnabledForUser() );
- $this->assertTrue( $util->setRecovery( 0 ) );
+ $this->assertTrue( $util->setRecoveryForUser( 0 ) );
- $this->assertEquals( 0, $util->recoveryEnabled() );
+ $this->assertEquals( 0, $util->recoveryEnabledForUser() );
// Return the setting to it's previous state
- $this->assertTrue( $util->setRecovery( $enabled ) );
+ $this->assertTrue( $util->setRecoveryForUser( $enabled ) );
}
--
cgit v1.2.3
From 4b53f72d0d749cceec7a9fa7be5d8bc6bab722c6 Mon Sep 17 00:00:00 2001
From: Sam Tuke
Date: Tue, 7 May 2013 16:17:38 +0200
Subject: Added facility to manually encrypt all files from personal settings
Added success/fail feedback to personal settings functions Improved
look/layout of personal settings page Fixed misplaced plain text in ajax
scripts
---
apps/files_encryption/ajax/adminrecovery.php | 5 ++-
apps/files_encryption/ajax/encryptall.php | 40 ++++++++++++++++++++++
apps/files_encryption/ajax/userrecovery.php | 22 +++++-------
apps/files_encryption/css/settings-personal.css | 10 ++++++
apps/files_encryption/js/settings-personal.js | 39 ++++++++++++++++++++-
apps/files_encryption/settings-personal.php | 3 ++
.../templates/settings-personal.php | 32 +++++++++++++----
7 files changed, 127 insertions(+), 24 deletions(-)
create mode 100644 apps/files_encryption/ajax/encryptall.php
create mode 100644 apps/files_encryption/css/settings-personal.css
(limited to 'apps/files_encryption/ajax/userrecovery.php')
diff --git a/apps/files_encryption/ajax/adminrecovery.php b/apps/files_encryption/ajax/adminrecovery.php
index eeeaf4c6ed7..c3c19943c0d 100644
--- a/apps/files_encryption/ajax/adminrecovery.php
+++ b/apps/files_encryption/ajax/adminrecovery.php
@@ -1,5 +1,3 @@
-setValue( $app, $key, $value )
-
@@ -91,4 +89,5 @@ if (
}
-($return) ? OC_JSON::success() : OC_JSON::error();
\ No newline at end of file
+// Return success or failure
+( $return ) ? \OCP\JSON::success() : \OCP\JSON::error();
\ No newline at end of file
diff --git a/apps/files_encryption/ajax/encryptall.php b/apps/files_encryption/ajax/encryptall.php
new file mode 100644
index 00000000000..ce613ca4435
--- /dev/null
+++ b/apps/files_encryption/ajax/encryptall.php
@@ -0,0 +1,40 @@
+
+ * This file is licensed under the Affero General Public License version 3 or later.
+ * See the COPYING-README file.
+ *
+ * @brief Script to handle manual trigger of \OCA\Encryption\Util{}->encryptAll()
+ */
+
+use OCA\Encryption;
+
+\OCP\JSON::checkAppEnabled( 'files_encryption' );
+\OCP\JSON::callCheck();
+
+$return = false;
+
+if (
+ isset( $_POST['encryptAll'] )
+ && ! empty( $_POST['userPassword'] )
+) {
+
+ $view = new \OC_FilesystemView( '' );
+ $userId = \OCP\User::getUser();
+ $util = new \OCA\Encryption\Util( $view, $userId );
+ $session = new \OCA\Encryption\Session( $view );
+ $publicKey = \OCA\Encryption\Keymanager::getPublicKey( $view, $userId );
+ $path = '/' . $userId . '/' . 'files';
+
+ $util->encryptAll( $publicKey, $path, $session->getLegacyKey(), $_POST['userPassword'] );
+
+ $return = true;
+
+} else {
+
+ $return = false;
+
+}
+
+// Return success or failure
+( $return ) ? \OCP\JSON::success() : \OCP\JSON::error();
\ No newline at end of file
diff --git a/apps/files_encryption/ajax/userrecovery.php b/apps/files_encryption/ajax/userrecovery.php
index f72be3181ef..85a799011d7 100644
--- a/apps/files_encryption/ajax/userrecovery.php
+++ b/apps/files_encryption/ajax/userrecovery.php
@@ -1,5 +1,3 @@
-setValue( $app, $key, $value )
-
@@ -13,6 +11,7 @@ use OCA\Encryption;
\OCP\JSON::checkLoggedIn();
\OCP\JSON::checkAppEnabled( 'files_encryption' );
+\OCP\JSON::callCheck();
if (
isset( $_POST['userEnableRecovery'] )
@@ -24,16 +23,13 @@ if (
$util = new \OCA\Encryption\Util( $view, $userId );
// Save recovery preference to DB
- $result = $util->setRecoveryForUser( $_POST['userEnableRecovery'] );
-
- if ( $result ) {
-
- \OCP\JSON::success();
-
- } else {
+ $return = $util->setRecoveryForUser( $_POST['userEnableRecovery'] );
- \OCP\JSON::error();
-
- }
+} else {
+
+ $return = false;
-}
\ No newline at end of file
+}
+
+// Return success or failure
+( $return ) ? \OCP\JSON::success() : \OCP\JSON::error();
\ No newline at end of file
diff --git a/apps/files_encryption/css/settings-personal.css b/apps/files_encryption/css/settings-personal.css
new file mode 100644
index 00000000000..4ee0acc9768
--- /dev/null
+++ b/apps/files_encryption/css/settings-personal.css
@@ -0,0 +1,10 @@
+/* Copyright (c) 2013, Sam Tuke,
+ This file is licensed under the Affero General Public License version 3 or later.
+ See the COPYING-README file. */
+
+#encryptAllError
+, #encryptAllSuccess
+, #recoveryEnabledError
+, #recoveryEnabledSuccess {
+ display: none;
+}
\ No newline at end of file
diff --git a/apps/files_encryption/js/settings-personal.js b/apps/files_encryption/js/settings-personal.js
index e4a1b7448f4..3b9b00dc797 100644
--- a/apps/files_encryption/js/settings-personal.js
+++ b/apps/files_encryption/js/settings-personal.js
@@ -9,15 +9,52 @@ $(document).ready(function(){
$( 'input:radio[name="userEnableRecovery"]' ).change(
function() {
+ // Hide feedback messages in case they're already visible
+ $('#recoveryEnabledSuccess').hide();
+ $('#recoveryEnabledError').hide();
+
var recoveryStatus = $( this ).val();
$.post(
OC.filePath( 'files_encryption', 'ajax', 'userrecovery.php' )
, { userEnableRecovery: recoveryStatus }
, function( data ) {
- alert( data );
+ if ( data.status == "success" ) {
+ $('#recoveryEnabledSuccess').show();
+ } else {
+ $('#recoveryEnabledError').show();
+ }
+ }
+ );
+ // Ensure page is not reloaded on form submit
+ return false;
+ }
+ );
+
+ $("#encryptAll").click(
+ function(){
+
+ // Hide feedback messages in case they're already visible
+ $('#encryptAllSuccess').hide();
+ $('#encryptAllError').hide();
+
+ var userPassword = $( '#userPassword' ).val();
+ var encryptAll = $( '#encryptAll' ).val();
+
+ $.post(
+ OC.filePath( 'files_encryption', 'ajax', 'encryptall.php' )
+ , { encryptAll: encryptAll, userPassword: userPassword }
+ , function( data ) {
+ if ( data.status == "success" ) {
+ $('#encryptAllSuccess').show();
+ } else {
+ $('#encryptAllError').show();
+ }
}
);
+ // Ensure page is not reloaded on form submit
+ return false;
}
+
);
})
\ No newline at end of file
diff --git a/apps/files_encryption/settings-personal.php b/apps/files_encryption/settings-personal.php
index c6d9d80f0b9..46efb61b029 100644
--- a/apps/files_encryption/settings-personal.php
+++ b/apps/files_encryption/settings-personal.php
@@ -6,6 +6,9 @@
* See the COPYING-README file.
*/
+// Add CSS stylesheet
+\OC_Util::addStyle( 'files_encryption', 'settings-personal' );
+
$tmpl = new OCP\Template( 'files_encryption', 'settings-personal');
$blackList = explode( ',', \OCP\Config::getAppValue( 'files_encryption', 'type_blacklist', '' ) );
diff --git a/apps/files_encryption/templates/settings-personal.php b/apps/files_encryption/templates/settings-personal.php
index c81f361ced9..00f567ecb26 100644
--- a/apps/files_encryption/templates/settings-personal.php
+++ b/apps/files_encryption/templates/settings-personal.php
@@ -1,15 +1,17 @@
+
+
+
+
+ t( "Use this if you suspect that you still have files which are unencrypted, or encrypted using ownCloud 4 or older." ) ); ?>
+
+
+
+
+
t( 'Scan complete' ) );?>
+ t( 'Unable to scan and encrypt files' ) );?>
+
--
cgit v1.2.3
From 57c0a7ed693fec6ef487b71a514202b24dd70df2 Mon Sep 17 00:00:00 2001
From: Björn Schießle
Date: Wed, 15 May 2013 17:56:45 +0200
Subject: add recovery key to all files if the user enabled the feature and
removes them again on disable
---
apps/files_encryption/ajax/userrecovery.php | 6 ++++
apps/files_encryption/lib/util.php | 34 ++++++++++++++++++++++
.../templates/settings-personal.php | 3 +-
3 files changed, 42 insertions(+), 1 deletion(-)
(limited to 'apps/files_encryption/ajax/userrecovery.php')
diff --git a/apps/files_encryption/ajax/userrecovery.php b/apps/files_encryption/ajax/userrecovery.php
index 85a799011d7..1f42b376e42 100644
--- a/apps/files_encryption/ajax/userrecovery.php
+++ b/apps/files_encryption/ajax/userrecovery.php
@@ -24,6 +24,12 @@ if (
// Save recovery preference to DB
$return = $util->setRecoveryForUser( $_POST['userEnableRecovery'] );
+
+ if ($_POST['userEnableRecovery'] == "1") {
+ $util->addRecoveryKeys();
+ } else {
+ $util->removeRecoveryKeys();
+ }
} else {
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index 6cb4ccb8085..6eee1ada8a8 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -1310,4 +1310,38 @@ class Util {
return $this->recoveryKeyId;
}
+ /**
+ * @brief add recovery key to all encrypted files
+ */
+ public function addRecoveryKeys($path = '/') {
+ $dirContent = $this->view->getDirectoryContent($this->keyfilesPath.$path);
+ foreach ($dirContent as $item) {
+ $filePath = substr($item['path'], 25);
+ if ($item['type'] == 'dir') {
+ $this->addRecoveryKey($filePath.'/');
+ } else {
+ $session = new Session(new \OC_FilesystemView('/'));
+ $sharingEnabled = \OCP\Share::isEnabled();
+ $file = substr($filePath, 0, -4);
+ $usersSharing = $this->getSharingUsersArray($sharingEnabled, $file);
+ $this->setSharedFileKeyfiles( $session, $usersSharing, $file );
+ }
+ }
+ }
+
+ /**
+ * @brief remove recovery key to all encrypted files
+ */
+ public function removeRecoveryKeys($path = '/') {
+ $dirContent = $this->view->getDirectoryContent($this->keyfilesPath.$path);
+ foreach ($dirContent as $item) {
+ $filePath = substr($item['path'], 25);
+ if ($item['type'] == 'dir') {
+ $this->removeRecoveryKeys($filePath.'/');
+ } else {
+ $file = substr($filePath, 0, -4);
+ $this->view->unlink($this->shareKeysPath.'/'.$file.'.'.$this->recoveryKeyId.'.shareKey');
+ }
+ }
+ }
}
diff --git a/apps/files_encryption/templates/settings-personal.php b/apps/files_encryption/templates/settings-personal.php
index 00f567ecb26..33989416d33 100644
--- a/apps/files_encryption/templates/settings-personal.php
+++ b/apps/files_encryption/templates/settings-personal.php
@@ -48,6 +48,7 @@
+
--
cgit v1.2.3