Skip to content

Commit b49af59

Browse files
author
Christian Putzke
committed
- bugfix: email and name can now be null
- ajax POST contents are now base64 encoded - username and password can now be empty - minor localization changes
1 parent 5e25501 commit b49af59

9 files changed

+172
-19
lines changed

CHANGELOG

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
changes from v0.2.4 to v0.2.5
2+
- bugfix: email and name can now be null
3+
- ajax POST contents are now base64 encoded
4+
- username and password can now be empty
5+
- minor localization changes
6+
17
changes from v0.2.3 to v0.2.4
28
- bugfix: last_modified date is now STRING instead of INT
39
- CardDAV-Backend class update to v0.4.2

SQL/mysql.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ CREATE TABLE IF NOT EXISTS `carddav_contacts` (
33
`carddav_server_id` int(10) unsigned NOT NULL,
44
`user_id` int(10) unsigned NOT NULL,
55
`etag` varchar(64) NOT NULL,
6-
`last_modified` VARCHAR(128) NOT NULL,
6+
`last_modified` varchar(128) NOT NULL,
77
`vcard_id` varchar(64) NOT NULL,
88
`vcard` longtext NOT NULL,
9-
`name` varchar(255) NOT NULL,
10-
`email` varchar(255) NOT NULL,
9+
`name` varchar(255) DEFAULT NULL,
10+
`email` varchar(255) DEFAULT NULL,
1111
PRIMARY KEY (`carddav_contact_id`),
1212
UNIQUE KEY `carddav_server_id` (`carddav_server_id`,`user_id`,`vcard_id`),
1313
KEY `user_id` (`user_id`)

SQL/mysql.update.sql

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
ALTER TABLE `carddav_contacts` ADD `last_modified` int(10) unsigned NOT NULL AFTER `etag` ;
33

44
// updates from version 0.2.4
5-
ALTER TABLE `carddav_contacts` CHANGE `last_modified` `last_modified` VARCHAR(128) NOT NULL ;
5+
ALTER TABLE `carddav_contacts` CHANGE `last_modified` `last_modified` VARCHAR(128) NOT NULL ;
6+
7+
// updates from version 0.2.5
8+
ALTER TABLE `carddav_contacts` CHANGE `name` `name` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
9+
CHANGE `email` `email` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL

carddav.php

+10-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @copyright Graviox Studios
1717
* @link http://www.graviox.de
1818
* @since 06.09.2011
19-
* @version 0.2.4
19+
* @version 0.2.5
2020
* @license http://gnu.org/copyleft/gpl.html GNU GPL v2 or later
2121
*
2222
*/
@@ -61,6 +61,7 @@ public function init()
6161
$this->register_action('plugin.carddav-server-save', array($this, 'carddav_server_save'));
6262
$this->register_action('plugin.carddav-server-delete', array($this, 'carddav_server_delete'));
6363
$this->include_script('carddav_settings.js');
64+
$this->include_script('jquery.base64.js');
6465
break;
6566

6667
case 'addressbook':
@@ -310,9 +311,9 @@ protected function carddav_server_available()
310311
public function carddav_server_check_connection()
311312
{
312313
$rcmail = rcmail::get_instance();
313-
$url = get_input_value('_server_url', RCUBE_INPUT_POST);
314-
$username = get_input_value('_username', RCUBE_INPUT_POST);
315-
$password = get_input_value('_password', RCUBE_INPUT_POST);
314+
$url = parse_input_value(base64_decode($_POST['_server_url']));
315+
$username = parse_input_value(base64_decode($_POST['_username']));
316+
$password = parse_input_value(base64_decode($_POST['_password']));
316317

317318
$carddav_backend = new carddav_backend($url);
318319
$carddav_backend->set_auth($username, $password);
@@ -395,10 +396,10 @@ public function carddav_server_save()
395396
if ($this->carddav_server_check_connection())
396397
{
397398
$user_id = $rcmail->user->data['user_id'];
398-
$url = get_input_value('_server_url', RCUBE_INPUT_POST);
399-
$username = get_input_value('_username', RCUBE_INPUT_POST);
400-
$password = get_input_value('_password', RCUBE_INPUT_POST);
401-
$label = get_input_value('_label', RCUBE_INPUT_POST);
399+
$url = parse_input_value(base64_decode($_POST['_server_url']));
400+
$username = parse_input_value(base64_decode($_POST['_username']));
401+
$password = parse_input_value(base64_decode($_POST['_password']));
402+
$label = parse_input_value(base64_decode($_POST['_label']));
402403

403404
$query = "
404405
INSERT INTO
@@ -443,7 +444,7 @@ public function carddav_server_delete()
443444
{
444445
$rcmail = rcmail::get_instance();
445446
$user_id = $rcmail->user->data['user_id'];
446-
$carddav_server_id = get_input_value('_carddav_server_id', RCUBE_INPUT_POST);
447+
$carddav_server_id = parse_input_value(base64_decode($_POST['_carddav_server_id']));
447448

448449
$query = "
449450
DELETE FROM

carddav_addressbook.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @copyright Graviox Studios
88
* @since 12.09.2011
99
* @link http://www.graviox.de
10-
* @version 0.2.4
10+
* @version 0.2.5
1111
* @license http://gnu.org/copyleft/gpl.html GNU GPL v2 or later
1212
*
1313
*/

carddav_settings.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ if (window.rcmail)
1717
var input_username = rcube_find_object('_username');
1818
var input_password = rcube_find_object('_password');
1919

20-
if (input_label.value == '' || input_url.value == '' || input_username.value == '' || input_password.value == '')
20+
if (input_label.value == '' || input_url.value == '')
2121
{
2222
rcmail.display_message(rcmail.gettext('settings_empty_values', 'carddav'), 'error');
2323
}
2424
else
2525
{
2626
rcmail.http_post(
2727
'plugin.carddav-server-save',
28-
'_label=' + input_label.value + '&_server_url=' + input_url.value + '&_username=' + input_username.value + '&_password=' + input_password.value,
28+
'_label=' + $.base64Encode(input_label.value) + '&_server_url=' + $.base64Encode(input_url.value) + '&_username=' + $.base64Encode(input_username.value) + '&_password=' + $.base64Encode(input_password.value),
2929
rcmail.display_message(rcmail.gettext('settings_init_server', 'carddav'), 'loading')
3030
);
3131
}
@@ -35,7 +35,7 @@ if (window.rcmail)
3535
{
3636
rcmail.http_post(
3737
'plugin.carddav-server-delete',
38-
'_carddav_server_id=' + carddav_server_id,
38+
'_carddav_server_id=' + $.base64Encode(carddav_server_id),
3939
rcmail.display_message(rcmail.gettext('settings_delete_loading', 'carddav'), 'loading')
4040
);
4141
}, true);

jquery.base64.js

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
2+
/**
3+
* jQuery BASE64 functions
4+
*
5+
* <code>
6+
* Encodes the given data with base64.
7+
* String $.base64Encode ( String str )
8+
* <br />
9+
* Decodes a base64 encoded data.
10+
* String $.base64Decode ( String str )
11+
* </code>
12+
*
13+
* Encodes and Decodes the given data in base64.
14+
* This encoding is designed to make binary data survive transport through transport layers that are not 8-bit clean, such as mail bodies.
15+
* Base64-encoded data takes about 33% more space than the original data.
16+
* This javascript code is used to encode / decode data using base64 (this encoding is designed to make binary data survive transport through transport layers that are not 8-bit clean). Script is fully compatible with UTF-8 encoding. You can use base64 encoded data as simple encryption mechanism.
17+
* If you plan using UTF-8 encoding in your project don't forget to set the page encoding to UTF-8 (Content-Type meta tag).
18+
* This function orginally get from the WebToolkit and rewrite for using as the jQuery plugin.
19+
*
20+
* Example
21+
* Code
22+
* <code>
23+
* $.base64Encode("I'm Persian.");
24+
* </code>
25+
* Result
26+
* <code>
27+
* "SSdtIFBlcnNpYW4u"
28+
* </code>
29+
* Code
30+
* <code>
31+
* $.base64Decode("SSdtIFBlcnNpYW4u");
32+
* </code>
33+
* Result
34+
* <code>
35+
* "I'm Persian."
36+
* </code>
37+
*
38+
* @alias Muhammad Hussein Fattahizadeh < muhammad [AT] semnanweb [DOT] com >
39+
* @link http://www.semnanweb.com/jquery-plugin/base64.html
40+
* @see http://www.webtoolkit.info/
41+
* @license http://www.gnu.org/licenses/gpl.html [GNU General Public License]
42+
* @param {jQuery} {base64Encode:function(input))
43+
* @param {jQuery} {base64Decode:function(input))
44+
* @return string
45+
*/
46+
47+
(function($){
48+
49+
var keyString = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
50+
51+
var uTF8Encode = function(string) {
52+
string = string.replace(/\x0d\x0a/g, "\x0a");
53+
var output = "";
54+
for (var n = 0; n < string.length; n++) {
55+
var c = string.charCodeAt(n);
56+
if (c < 128) {
57+
output += String.fromCharCode(c);
58+
} else if ((c > 127) && (c < 2048)) {
59+
output += String.fromCharCode((c >> 6) | 192);
60+
output += String.fromCharCode((c & 63) | 128);
61+
} else {
62+
output += String.fromCharCode((c >> 12) | 224);
63+
output += String.fromCharCode(((c >> 6) & 63) | 128);
64+
output += String.fromCharCode((c & 63) | 128);
65+
}
66+
}
67+
return output;
68+
};
69+
70+
var uTF8Decode = function(input) {
71+
var string = "";
72+
var i = 0;
73+
var c = c1 = c2 = 0;
74+
while ( i < input.length ) {
75+
c = input.charCodeAt(i);
76+
if (c < 128) {
77+
string += String.fromCharCode(c);
78+
i++;
79+
} else if ((c > 191) && (c < 224)) {
80+
c2 = input.charCodeAt(i+1);
81+
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
82+
i += 2;
83+
} else {
84+
c2 = input.charCodeAt(i+1);
85+
c3 = input.charCodeAt(i+2);
86+
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
87+
i += 3;
88+
}
89+
}
90+
return string;
91+
}
92+
93+
$.extend({
94+
base64Encode: function(input) {
95+
var output = "";
96+
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
97+
var i = 0;
98+
input = uTF8Encode(input);
99+
while (i < input.length) {
100+
chr1 = input.charCodeAt(i++);
101+
chr2 = input.charCodeAt(i++);
102+
chr3 = input.charCodeAt(i++);
103+
enc1 = chr1 >> 2;
104+
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
105+
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
106+
enc4 = chr3 & 63;
107+
if (isNaN(chr2)) {
108+
enc3 = enc4 = 64;
109+
} else if (isNaN(chr3)) {
110+
enc4 = 64;
111+
}
112+
output = output + keyString.charAt(enc1) + keyString.charAt(enc2) + keyString.charAt(enc3) + keyString.charAt(enc4);
113+
}
114+
return output;
115+
},
116+
base64Decode: function(input) {
117+
var output = "";
118+
var chr1, chr2, chr3;
119+
var enc1, enc2, enc3, enc4;
120+
var i = 0;
121+
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
122+
while (i < input.length) {
123+
enc1 = keyString.indexOf(input.charAt(i++));
124+
enc2 = keyString.indexOf(input.charAt(i++));
125+
enc3 = keyString.indexOf(input.charAt(i++));
126+
enc4 = keyString.indexOf(input.charAt(i++));
127+
chr1 = (enc1 << 2) | (enc2 >> 4);
128+
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
129+
chr3 = ((enc3 & 3) << 6) | enc4;
130+
output = output + String.fromCharCode(chr1);
131+
if (enc3 != 64) {
132+
output = output + String.fromCharCode(chr2);
133+
}
134+
if (enc4 != 64) {
135+
output = output + String.fromCharCode(chr3);
136+
}
137+
}
138+
output = uTF8Decode(output);
139+
return output;
140+
}
141+
});
142+
})(jQuery);

localization/de_DE.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ $labels['addressbook_contacts'] = 'CardDAV-Kontakte';
88
$labels['addressbook_sync'] = 'CardDAV-Adressbuch synchronisieren';
99

1010
$messages = array();
11-
$messages['settings_empty_values'] = 'Bitte f&uuml;lle alle Felder aus';
11+
$messages['settings_empty_values'] = 'Bitte gebe ein Label und die URL an';
1212
$messages['settings_saved'] = 'CardDAV-Server Einstellungen und vCards erfolgreich gespeichert';
1313
$messages['settings_save_failed'] = 'Beim Speichern der CardDAV-Server Einstellungen ist ein Fehler aufgetreten';
1414
$messages['settings_delete_loading'] = 'L&ouml;sche CardDAV-Server Einstellungen und dazugeh&ouml;rige lokale Kontakte';

localization/en_US.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ $labels['addressbook_contacts'] = 'CardDAV-Contacts';
88
$labels['addressbook_sync'] = 'Synchronize CardDAV-Addressbook';
99

1010
$messages = array();
11-
$messages['settings_empty_values'] = 'Please fill out all fields';
11+
$messages['settings_empty_values'] = 'Please fill out all Label and URL';
1212
$messages['settings_saved'] = 'CardDAV-Server settings and vCards saved';
1313
$messages['settings_save_failed'] = 'Failed to save CardDAV-Server settings';
1414
$messages['settings_delete_loading'] = 'Delete CardDAV-Server settings and related local contacts';

0 commit comments

Comments
 (0)