diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2012-08-02 10:39:30 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2012-08-02 10:40:32 +0200 |
commit | 6b058cd3594d80a27097b04507355b219f4726e4 (patch) | |
tree | 9ed88fd5c66e67ba253becbf555e29c4d315270e | |
parent | c4d1ad1b7d4507e387a5833622b4831044eb9e09 (diff) | |
download | nextcloud-server-6b058cd3594d80a27097b04507355b219f4726e4.tar.gz nextcloud-server-6b058cd3594d80a27097b04507355b219f4726e4.zip |
allow user to choose encryption mode
-rw-r--r-- | apps/files_encryption/ajax/changemode.php | 17 | ||||
-rw-r--r-- | apps/files_encryption/appinfo/app.php | 3 | ||||
-rw-r--r-- | apps/files_encryption/appinfo/database.xml | 24 | ||||
-rw-r--r-- | apps/files_encryption/appinfo/version | 2 | ||||
-rw-r--r-- | apps/files_encryption/js/settings-personal.js | 22 | ||||
-rw-r--r-- | apps/files_encryption/js/settings.js | 11 | ||||
-rw-r--r-- | apps/files_encryption/lib/crypt.php | 19 | ||||
-rw-r--r-- | apps/files_encryption/settings-personal.php | 25 | ||||
-rw-r--r-- | apps/files_encryption/settings.php | 1 | ||||
-rw-r--r-- | apps/files_encryption/templates/settings-personal.php | 14 | ||||
-rw-r--r-- | apps/files_encryption/templates/settings.php | 3 | ||||
-rw-r--r-- | apps/files_sharing/appinfo/database.xml | 2 |
12 files changed, 124 insertions, 19 deletions
diff --git a/apps/files_encryption/ajax/changemode.php b/apps/files_encryption/ajax/changemode.php new file mode 100644 index 00000000000..0e6678e4bba --- /dev/null +++ b/apps/files_encryption/ajax/changemode.php @@ -0,0 +1,17 @@ +<?php +
+OCP\JSON::checkAppEnabled('files_encryption');
+OCP\JSON::checkLoggedIn();
+OCP\JSON::callCheck();
+ +$mode = $_POST['mode']; + +$query = \OC_DB::prepare( "SELECT mode FROM *PREFIX*encryption WHERE uid = ?" );
+$result = $query->execute(array(\OCP\User::getUser()));
+ +if ($row = $result->fetchRow()){ + $query = OC_DB::prepare( 'UPDATE *PREFIX*encryption SET mode = ? WHERE uid = ?' ); +} else { + $query = OC_DB::prepare( 'INSERT INTO *PREFIX*encryption ( mode, uid ) VALUES( ?, ? )' ); +} +$query->execute(array($mode, \OCP\User::getUser()));
\ No newline at end of file diff --git a/apps/files_encryption/appinfo/app.php b/apps/files_encryption/appinfo/app.php index 2047bdbb1fb..1c2fafa8da6 100644 --- a/apps/files_encryption/appinfo/app.php +++ b/apps/files_encryption/appinfo/app.php @@ -28,4 +28,5 @@ and OCP\User::isLoggedIn() } -OCP\App::registerAdmin('files_encryption', 'settings');
\ No newline at end of file +OCP\App::registerAdmin('files_encryption', 'settings'); +OCP\App::registerPersonal('files_encryption','settings-personal');
\ No newline at end of file diff --git a/apps/files_encryption/appinfo/database.xml b/apps/files_encryption/appinfo/database.xml new file mode 100644 index 00000000000..d294c35d63d --- /dev/null +++ b/apps/files_encryption/appinfo/database.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="ISO-8859-1" ?> +<database> + <name>*dbname*</name> + <create>true</create> + <overwrite>false</overwrite> + <charset>utf8</charset> + <table> + <name>*dbprefix*encryption</name> + <declaration> + <field> + <name>uid</name> + <type>text</type> + <notnull>true</notnull> + <length>64</length> + </field> + <field> + <name>mode</name> + <type>text</type> + <notnull>true</notnull> + <length>64</length> + </field> + </declaration> + </table> +</database>
\ No newline at end of file diff --git a/apps/files_encryption/appinfo/version b/apps/files_encryption/appinfo/version index 2f4536184bc..7dff5b89211 100644 --- a/apps/files_encryption/appinfo/version +++ b/apps/files_encryption/appinfo/version @@ -1 +1 @@ -0.2
\ No newline at end of file +0.2.1
\ 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..76f9a37f69e --- /dev/null +++ b/apps/files_encryption/js/settings-personal.js @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2012, Bjoern Schiessle <schiessle@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or later. + * See the COPYING-README file. + */ + +$(document).ready(function(){ + console.log("loaded!"); + $('input[name=encryption_mode]').change(function(){ + console.log("HERE!!!!!!!!!!!"); + var client=$('input[value="client"]:checked').val() + ,server=$('input[value="server"]:checked').val() + ,user=$('input[value="user"]:checked').val() + ,none=$('input[value="none"]:checked').val() + if (client) + $.post(OC.filePath('files_encryption', 'ajax', 'changemode.php'), { mode: 'client' }); + else if (server) + $.post(OC.filePath('files_encryption', 'ajax', 'changemode.php'), { mode: 'server' }); + else + $.post(OC.filePath('files_encryption', 'ajax', 'changemode.php'), { mode: 'none' }); + }) +})
\ No newline at end of file diff --git a/apps/files_encryption/js/settings.js b/apps/files_encryption/js/settings.js index 49dcf2bfca3..d4dc470ced8 100644 --- a/apps/files_encryption/js/settings.js +++ b/apps/files_encryption/js/settings.js @@ -17,19 +17,18 @@ $(document).ready(function(){ OC.AppConfig.setValue('files_encryption','type_blacklist',blackList); } - $('#enable_encryption').change(function(){ - var checked=$('#enable_encryption').is(':checked'); - OC.AppConfig.setValue('files_encryption','enable_encryption',(checked)?'true':'false'); - }) $('input[name=encryption_mode]').change(function(){ var client=$('input[value="client"]:checked').val() ,server=$('input[value="server"]:checked').val() + ,user=$('input[value="user"]:checked').val() ,none=$('input[value="none"]:checked').val() if (client) OC.AppConfig.setValue('files_encryption','mode','client'); - if (server) + else if (server) OC.AppConfig.setValue('files_encryption','mode','server'); - if (none) + else if (user) + OC.AppConfig.setValue('files_encryption','mode','user'); + else OC.AppConfig.setValue('files_encryption','mode','none'); }) })
\ No newline at end of file diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php index 7e50c900fa1..90b24dc8ddb 100644 --- a/apps/files_encryption/lib/crypt.php +++ b/apps/files_encryption/lib/crypt.php @@ -37,14 +37,17 @@ class Crypt { */
public static function mode( $user = null ) {
- $mode = \OC_Appconfig::getValue( 'files_encryption', 'mode', 'unknown' );
-
- if ( $mode == 'unknown' ) {
-
- error_log('no encryption mode configured');
-
- return false;
-
+ $mode = \OC_Appconfig::getValue( 'files_encryption', 'mode', 'none' );
+ + if ( $mode == 'user') { + $mode = 'none'; + if ( $user ) { + $query = \OC_DB::prepare( "SELECT mode FROM *PREFIX*encryption WHERE uid = ?" );
+ $result = $query->execute(array($user));
+ if ($row = $result->fetchRow()){
+ $mode = $row['mode'];
+ } + } }
return $mode;
diff --git a/apps/files_encryption/settings-personal.php b/apps/files_encryption/settings-personal.php new file mode 100644 index 00000000000..d4071e75ff4 --- /dev/null +++ b/apps/files_encryption/settings-personal.php @@ -0,0 +1,25 @@ +<?php
+
+$sysEncMode = \OC_Appconfig::getValue('files_encryption', 'mode', 'none');
+
+if ($sysEncMode == 'user') {
+
+ $tmpl = new OCP\Template( 'files_encryption', 'settings-personal');
+
+ $query = \OC_DB::prepare( "SELECT mode FROM *PREFIX*encryption WHERE uid = ?" );
+ $result = $query->execute(array(\OCP\User::getUser()));
+
+ if ($row = $result->fetchRow()){
+ $mode = $row['mode'];
+ } else {
+ $mode = 'none';
+ }
+
+ OCP\Util::addscript('files_encryption','settings-personal');
+ $tmpl->assign('encryption_mode', $mode);
+ return $tmpl->fetchPage();
+}
+
+return null;
+
+?>
\ No newline at end of file diff --git a/apps/files_encryption/settings.php b/apps/files_encryption/settings.php index a4e91627dd9..963fdf826c1 100644 --- a/apps/files_encryption/settings.php +++ b/apps/files_encryption/settings.php @@ -8,7 +8,6 @@ $tmpl = new OCP\Template( 'files_encryption', 'settings'); $blackList=explode(',',OCP\Config::getAppValue('files_encryption','type_blacklist','jpg,png,jpeg,avi,mpg,mpeg,mkv,mp3,oga,ogv,ogg')); -$enabled=(OCP\Config::getAppValue('files_encryption','enable_encryption','true')=='true'); $tmpl->assign('blacklist',$blackList); $tmpl->assign('encryption_mode',\OC_Appconfig::getValue('files_encryption', 'mode', 'none')); diff --git a/apps/files_encryption/templates/settings-personal.php b/apps/files_encryption/templates/settings-personal.php new file mode 100644 index 00000000000..2b51ab8694d --- /dev/null +++ b/apps/files_encryption/templates/settings-personal.php @@ -0,0 +1,14 @@ +
+<form id="encryption">
+<fieldset class="personalblock">
+
+<strong>Choose encryption mode:</strong>
+
+<p>
+ <input type="radio" name="encryption_mode" value="client" style="width:20px;" <?php if ($_['encryption_mode'] == 'client') echo "checked='checked'"?>/> Client side encryption (most secure but makes it impossible to access your data from the web interface)<br />
+ <input type="radio" name="encryption_mode" value="server" style="width:20px;" <?php if ($_['encryption_mode'] == 'server') echo "checked='checked'"?> /> Server side encryption (allows you to access your files from the web interface and the desktop client)<br />
+ <input type="radio" name="encryption_mode" value="none" style="width:20px;" <?php if ($_['encryption_mode'] == 'none') echo "checked='checked'"?>/> None (no encryption at all)<br/>
+ </p>
+ </fieldset>
+</form>
+
diff --git a/apps/files_encryption/templates/settings.php b/apps/files_encryption/templates/settings.php index 38c89ecde34..2a3c1fd5bdf 100644 --- a/apps/files_encryption/templates/settings.php +++ b/apps/files_encryption/templates/settings.php @@ -1,4 +1,4 @@ -<form id="calendar"> +<form id="encryption"> <fieldset class="personalblock"> <strong>Choose encryption mode:</strong> @@ -6,6 +6,7 @@ <p> <input type="radio" name="encryption_mode" value="client" style="width:20px;" <?php if ($_['encryption_mode'] == 'client') echo "checked='checked'"?>/> Client side encryption (most secure but makes it impossible to access your data from the web interface)<br /> <input type="radio" name="encryption_mode" value="server" style="width:20px;" <?php if ($_['encryption_mode'] == 'server') echo "checked='checked'"?> /> Server side encryption (allows you to access your files from the web interface and the desktop client)<br /> + <input type="radio" name="encryption_mode" value="user" style="width:20px;" <?php if ($_['encryption_mode'] == 'user') echo "checked='checked'"?>/> User specific (let the user decide)<br/> <input type="radio" name="encryption_mode" value="none" style="width:20px;" <?php if ($_['encryption_mode'] == 'none') echo "checked='checked'"?>/> None (no encryption at all)<br/> </p> <p> diff --git a/apps/files_sharing/appinfo/database.xml b/apps/files_sharing/appinfo/database.xml index c5cb632d4fe..bb6275fbacf 100644 --- a/apps/files_sharing/appinfo/database.xml +++ b/apps/files_sharing/appinfo/database.xml @@ -39,4 +39,4 @@ </field> </declaration> </table> -</database> +</database>
\ No newline at end of file |