Commit 82e905cb authored by Daniel Morlock's avatar Daniel Morlock

Add/fix support to edit ical/caldav calendars.

parent 1116a2dd
......@@ -1396,16 +1396,57 @@ class caldav_driver extends calendar_driver
}
}
private function _decrypt_pass($pass) {
$p = base64_decode($pass);
$e = new Encryption(MCRYPT_BlOWFISH, MCRYPT_MODE_CBC);
return $e->decrypt($p, $this->crypt_key);
}
/**
* Callback function to produce driver-specific calendar create/edit form
*
* @param string Request action 'form-edit|form-new'
* @param array Calendar properties (e.g. id, color)
* @param array Edit form fields
*
* @return string HTML content of the form
*/
public function calendar_form($action, $calendar, $formfields)
{
// Make sure we have current attributes
$calendar = $this->calendars[$calendar["id"]];
$input_caldav_url = new html_inputfield( array(
"name" => "caldav_url",
"id" => "caldav_url",
"size" => 20
));
$formfields["caldav_url"] = array(
"label" => $this->cal->gettext("caldavurl"),
"value" => $input_caldav_url->show($calendar["caldav_url"]),
"id" => "caldav_url",
);
private function _encrypt_pass($pass) {
$e = new Encryption(MCRYPT_BlOWFISH, MCRYPT_MODE_CBC);
$p = $e->encrypt($pass, $this->crypt_key);
return base64_encode($p);
$input_caldav_user = new html_inputfield( array(
"name" => "caldav_user",
"id" => "caldav_user",
"size" => 20
));
$formfields["caldav_user"] = array(
"label" => $this->cal->gettext("username"),
"value" => $input_caldav_user->show($calendar["caldav_user"]),
"id" => "caldav_user",
);
$input_caldav_pass = new html_passwordfield( array(
"name" => "caldav_pass",
"id" => "caldav_pass",
"size" => 20
));
$formfields["caldav_pass"] = array(
"label" => $this->cal->gettext("password"),
"value" => $input_caldav_pass->show(null), // Don't send plain text password to GUI
"id" => "caldav_pass",
);
return parent::calendar_form($action, $calendar, $formfields);
}
/**
......@@ -1701,4 +1742,16 @@ class caldav_driver extends calendar_driver
return "UNIX_TIMESTAMP($field)";
}
}
private function _decrypt_pass($pass) {
$p = base64_decode($pass);
$e = new Encryption(MCRYPT_BlOWFISH, MCRYPT_MODE_CBC);
return $e->decrypt($p, $this->crypt_key);
}
private function _encrypt_pass($pass) {
$e = new Encryption(MCRYPT_BlOWFISH, MCRYPT_MODE_CBC);
$p = $e->encrypt($pass, $this->crypt_key);
return base64_encode($p);
}
}
......@@ -64,9 +64,6 @@ CREATE TABLE IF NOT EXISTS `ical_events` (
`attendees` text DEFAULT NULL,
`notifyat` datetime DEFAULT NULL,
`ical_url` varchar(255) NOT NULL,
`ical_last_change` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY(`event_id`),
INDEX `ical_uid_idx` (`uid`),
INDEX `ical_recurrence_idx` (`recurrence_id`),
......@@ -90,21 +87,24 @@ CREATE TABLE IF NOT EXISTS `ical_attachments` (
/* Migrate Data */
INSERT INTO ical_calendars
SELECT calendar_id, user_id, `name`, color, showalarms,
url as ical_url, `user` as ical_user, pass as ical_pass,
last_change as ical_last_change
url as ical_url, NULL as ical_user, NULL as ical_pass, last_change as ical_last_change
FROM calendars cal, ical_props dav
WHERE dav.obj_id = cal.calendar_id
AND dav.obj_type = 'vcal';
AND dav.obj_type = 'ical';
INSERT INTO ical_events SELECT e.*, dav.url as ical_url, dav.last_change as ical_last_change
FROM `events` e, ical_props dav
WHERE dav.obj_id = e.event_id
AND dav.obj_type = 'vevent';
INSERT INTO ical_events SELECT e.* FROM `events` e
WHERE e.calendar_id IN (
SELECT obj_id FROM ical_props
WHERE obj_type = 'ical'
);
INSERT INTO ical_attachments SELECT * FROM attachments a
WHERE a.event_id IN (
SELECT obj_id FROM ical_props dav
WHERE dav.obj_type = 'vevent'
SELECT e.event_id FROM `events` e
WHERE e.calendar_id IN (
SELECT obj_id FROM ical_props
WHERE obj_type = 'ical'
)
);
/* Drop deprecated data */
......@@ -114,7 +114,7 @@ DELETE FROM `events` WHERE event_id IN (
);
DELETE FROM calendars WHERE calendar_id IN (
SELECT obj_id FROM ical_props dav
WHERE dav.obj_type = 'vcal'
WHERE dav.obj_type = 'ical'
);
DELETE FROM attachments WHERE event_id IN (
SELECT obj_id FROM ical_props dav
......
......@@ -22,10 +22,10 @@
*/
require_once(dirname(__FILE__) . '/ical_sync.php');
require_once (dirname(__FILE__).'/../../lib/encryption.php');
/**
* TODO
* - Database constraint: obj_id, obj_type must be unique.
* - Postgresql, Sqlite scripts.
*
*/
......@@ -57,11 +57,32 @@ class ical_driver extends calendar_driver
private $sync_clients = array();
// Min. time period to wait until sync check.
private $sync_period = 600; // seconds
private $sync_period = 10; // TODO: 600; // seconds
// Crypt key for CalDAV auth
private $crypt_key;
// Indicates debug mode for iCAL
static private $debug = null;
/**
* Helper method to log debug msg if debug mode is enabled.
*/
static public function debug_log($msg)
{
if(self::$debug === true)
rcmail::console(__CLASS__.': '.$msg);
}
/**
* Helper method to log (if debug mode is enabled) and raise an user error.
*/
private function _raise_error($msg)
{
self::debug_log($msg);
$this->rc->output->show_message($msg, 'error');
}
/**
* Default constructor
*/
......@@ -85,15 +106,6 @@ class ical_driver extends calendar_driver
$this->_read_calendars();
}
/**
* Helper method to log debug msg if debug mode is enabled.
*/
static public function debug_log($msg)
{
if (self::$debug === true)
rcmail::console(__CLASS__.': '.$msg);
}
/**
* Read available calendars for the current user and store them internally
*/
......@@ -149,7 +161,17 @@ class ical_driver extends calendar_driver
// 'personal' is unsupported in this driver
return $calendars;
return array_map(function($cal) {
// Make calendar readonly
$cal["readonly"] = true;
// But name should be editable!
$cal["editable_name"] = true;
return $cal;
}, $calendars);
}
/**
......@@ -204,20 +226,20 @@ class ical_driver extends calendar_driver
$prop['name'],
$prop['color'],
$prop['showalarms'] ? 1 : 0,
isset($cal["ical_tag"]) ? $cal["ical_tag"] : null,
isset($cal["ical_user"]) ? $cal["ical_user"] : null,
isset($prop["ical_url"]) ? $prop["ical_url"] : null,
isset($prop["ical_user"]) ? $prop["ical_user"] : null,
$prop['id'],
$this->rc->user->ID
);
// Change password if specified
if (isset($cal["ical_pass"])) {
if (isset($prop["ical_pass"])) {
$query = $this->rc->db->query("UPDATE " . $this->db_calendars . "
SET ical_pass=?
WHERE calendar_id=?
AND user_id=?",
$this->_encrypt_pass($cal['ical_pass']),
$cal['id'],
$this->_encrypt_pass($prop['ical_pass']),
$prop['id'],
$this->rc->user->ID
);
}
......@@ -1261,6 +1283,59 @@ class ical_driver extends calendar_driver
}
}
/**
* Callback function to produce driver-specific calendar create/edit form
*
* @param string Request action 'form-edit|form-new'
* @param array Calendar properties (e.g. id, color)
* @param array Edit form fields
*
* @return string HTML content of the form
*/
public function calendar_form($action, $calendar, $formfields)
{
// Make sure we have current attributes
$calendar = $this->calendars[$calendar["id"]];
$input_ical_url = new html_inputfield(array(
"name" => "ical_url",
"id" => "ical_url",
"size" => 20
));
$formfields["ical_url"] = array(
"label" => $this->cal->gettext("icalurl"),
"value" => $input_ical_url->show($calendar["ical_url"]),
"id" => "ical_url",
);
$input_ical_user = new html_inputfield( array(
"name" => "ical_user",
"id" => "ical_user",
"size" => 20
));
$formfields["ical_user"] = array(
"label" => $this->cal->gettext("username"),
"value" => $input_ical_user->show($calendar["ical_user"]),
"id" => "ical_user",
);
$input_ical_pass = new html_passwordfield( array(
"name" => "ical_pass",
"id" => "ical_pass",
"size" => 20
));
$formfields["ical_pass"] = array(
"label" => $this->cal->gettext("password"),
"value" => $input_ical_pass->show(null), // Don't send plain text password to GUI
"id" => "ical_pass",
);
return parent::calendar_form($action, $calendar, $formfields);
}
/**
* Determines whether the given calendar is in sync regarding the configured sync period.
*
......
......@@ -88,8 +88,8 @@ class ical_sync
$vcal = file_get_contents($this->url, false, $context);
$updates = array();
$synced = array();
if($vcal !== false)
{
if($vcal !== false) {
// Hash existing events by uid.
$events_hash = array();
foreach($events as $event) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment