]> source.dussan.org Git - nextcloud-server.git/commitdiff
Added facility to manually encrypt all files from personal settings
authorSam Tuke <samtuke@owncloud.com>
Tue, 7 May 2013 14:17:38 +0000 (16:17 +0200)
committerSam Tuke <samtuke@owncloud.com>
Tue, 7 May 2013 14:17:38 +0000 (16:17 +0200)
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
apps/files_encryption/ajax/encryptall.php [new file with mode: 0644]
apps/files_encryption/ajax/userrecovery.php
apps/files_encryption/css/settings-personal.css [new file with mode: 0644]
apps/files_encryption/js/settings-personal.js
apps/files_encryption/settings-personal.php
apps/files_encryption/templates/settings-personal.php

index eeeaf4c6ed79b2aa0ccc71068ae7feec1b542c20..c3c19943c0d20e203f01b6d957365fabc3210bd2 100644 (file)
@@ -1,5 +1,3 @@
-setValue( $app, $key, $value )
-
 <?php
 /**
  * Copyright (c) 2013, Sam Tuke <samtuke@owncloud.com>
@@ -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 (file)
index 0000000..ce613ca
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Copyright (c) 2013, Sam Tuke <samtuke@owncloud.com>
+ * 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
index f72be3181efd62397ab940e8502b9491133496ef..85a799011d7d4733f9849e2989dd8c3ec46c4c9a 100644 (file)
@@ -1,5 +1,3 @@
-setValue( $app, $key, $value )
-
 <?php
 /**
  * Copyright (c) 2013, Sam Tuke <samtuke@owncloud.com>
@@ -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 (file)
index 0000000..4ee0acc
--- /dev/null
@@ -0,0 +1,10 @@
+/* Copyright (c) 2013, Sam Tuke, <samtuke@owncloud.com>
+ 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
index e4a1b7448f41369759471f8e9cf94105178d2c67..3b9b00dc797046a00a42728412cee83623719064 100644 (file)
@@ -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
index c6d9d80f0b9c27cff11221978114078ce02e11a1..46efb61b0298eb6a0d62d1bd4f0c9139d2256600 100644 (file)
@@ -6,6 +6,9 @@
  * See the COPYING-README file.\r
  */\r
 \r
+// Add CSS stylesheet\r
+\OC_Util::addStyle( 'files_encryption', 'settings-personal' );\r
\r
 $tmpl = new OCP\Template( 'files_encryption', 'settings-personal');\r
 \r
 $blackList = explode( ',', \OCP\Config::getAppValue( 'files_encryption', 'type_blacklist', '' ) );\r
index c81f361ced95959fd5cd7ee69617f55675fb42f9..00f567ecb2665c085453e2ebe5f520675b7691f4 100644 (file)
@@ -1,15 +1,17 @@
 <form id="encryption">\r
        <fieldset class="personalblock">\r
                <legend>\r
-                       <?php p($l->t( 'Encryption' )); ?>\r
+                       <?php p( $l->t( 'Encryption' ) ); ?>\r
                </legend>\r
                \r
                <p>\r
-                       <?php p($l->t( 'File encryption is enabled.' )); ?>\r
+<!--                   <?php p( $l->t( 'File encryption is enabled.' ) ); ?> -->\r
                </p>\r
                <?php if ( ! empty( $_["blacklist"] ) ): ?>\r
                <p>\r
-                       <?php p($l->t( 'The following file types will not be encrypted:' )); ?>\r
+                       <strong>File types</strong>\r
+                       <br />\r
+                       <?php p( $l->t( 'The following file types will not be encrypted:' ) ); ?>\r
                </p>\r
                \r
                <ul>\r
                        <?php endforeach; ?>\r
                </ul>\r
                <?php endif; ?>\r
-               \r
+               <br />\r
                <?php if ( $_["recoveryEnabled"] ): ?>\r
                        <p>\r
-                               <?php p($l->t( "Enable password recovery by sharing all files with administrator:" )); ?>\r
+                               <label for="userEnableRecovery"><?php p( $l->t( "Enable password recovery by sharing all files with administrator:" ) ); ?></label>\r
+                               <br />\r
+                               <em><?php p( $l->t( "Enabling this option will allow you to reobtain access to your encrypted files if your password is lost" ) ); ?></em>\r
                                <br />\r
                                <input \r
                                type='radio'\r
                                name='userEnableRecovery'\r
                                value='1'\r
                                <?php echo ( $_["recoveryEnabledForUser"] == 1 ? 'checked="checked"' : '' ); ?> />\r
-                               <?php p($l->t( "Enabled" )); ?>\r
+                               <?php p( $l->t( "Enabled" ) ); ?>\r
                                <br />\r
                                \r
                                <input \r
                                name='userEnableRecovery'\r
                                value='0'\r
                                <?php echo ( $_["recoveryEnabledForUser"] == 0 ? 'checked="checked"' : '' ); ?> />\r
-                               <?php p($l->t( "Disabled" )); ?>\r
+                               <?php p( $l->t( "Disabled" ) ); ?>\r
+                               <div id="recoveryEnabledSuccess"><?php p( $l->t( 'File recovery settings updated' ) ); ?></div>\r
+                               <div id="recoveryEnabledError"><?php p( $l->t( 'Could not update file recovery' ) ); ?></div>\r
                        </p>\r
                <?php endif; ?>\r
+               <br />\r
+               <p>\r
+                               <label for="encryptAll"><?php p( $l->t( "Scan for unencrypted files and encrypt them" ) ); ?></label>\r
+                               <br />\r
+                               <em><?php p( $l->t( "Use this if you suspect that you still have files which are unencrypted, or encrypted using ownCloud 4 or older." ) ); ?></em>\r
+                               <br />\r
+                               <input type="submit" id="encryptAll" name="encryptAll" value="<?php p( $l->t( 'Scan and encrypt files' ) ); ?>" />\r
+                               <input type="password" name="userPassword" id="userPassword" />\r
+                               <label for="encryptAll"><?php p( $l->t( "Account password" ) ); ?></label>\r
+                               <div id="encryptAllSuccess"><?php p( $l->t( 'Scan complete' ) );?></div>\r
+                               <div id="encryptAllError"><?php p( $l->t( 'Unable to scan and encrypt files' ) );?></div>\r
+               </p>\r
                \r
        </fieldset>\r
 </form>\r