7 Commits
0.7 ... 0.8

Author SHA1 Message Date
Boris Gulay
d667518d1f Fixed vary dangerous error when while editing settings ALL records ware
updated instead of only one.
2016-05-28 00:29:35 +03:00
Boris Gulay
5ad75ce989 Field validation code refactored. 2016-05-28 00:22:57 +03:00
Boris Gulay
dbadde3333 Fixed validation error when editing identity with Enabled not checked. 2016-05-28 00:22:57 +03:00
Boris Gulay
b499688318 Fixed #2 validation error when saving default identity (thanx Wouter de
Geus).
2016-05-28 00:22:49 +03:00
Boris Gulay
6cfbeab7f0 Added RUS messages for validation errors. 2016-05-27 23:42:46 +03:00
Boris Gulay
b10f3625c2 Added string in ENG for all validation erros. 2016-05-27 23:25:26 +03:00
Boris Gulay
f28fb5bb58 Added initial script for MySQL (thanx Wouter de Geus). Closes #1. 2016-05-27 22:46:58 +03:00
4 changed files with 183 additions and 81 deletions

38
SQL/mysql.initial.sql Normal file
View File

@@ -0,0 +1,38 @@
CREATE TABLE IF NOT EXISTS ident_switch
(
id
int(10) UNSIGNED
NOT NULL
AUTO_INCREMENT,
user_id
int(10) UNSIGNED
NOT NULL,
iid
int(10) UNSIGNED
NOT NULL,
username
varchar(64)
NOT NULL,
password
varchar(64),
host
varchar(64),
port
int
CHECK(port > 0 AND port <= 65535),
delimiter
char(1),
label
varchar(32),
flags
int
NOT NULL
DEFAULT 0,
UNIQUE KEY user_id_label (user_id, label),
CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT fk_identity_id FOREIGN KEY (iid) REFERENCES identities(identity_id) ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY(id),
INDEX IX_ident_switch_user_id (user_id),
INDEX IX_ident_switch_iid (iid)
);

View File

@@ -135,7 +135,7 @@ class ident_switch extends rcube_plugin
{ {
$rc = rcmail::get_instance(); $rc = rcmail::get_instance();
// Do now show options for default identity // Do not show options for default identity
if (strcasecmp($args['record']['email'], $rc->user->data['username']) === 0) if (strcasecmp($args['record']['email'], $rc->user->data['username']) === 0)
return $args; return $args;
@@ -182,71 +182,9 @@ class ident_switch extends rcube_plugin
{ {
$rc = rcmail::get_instance(); $rc = rcmail::get_instance();
// Check field values // Do not do anything for default identity
$noErrors = false; if (strcasecmp($args['record']['email'], $rc->user->data['username']) === 0)
$fLabel = self::ntrim(get_input_value('_ident_switch_form_label', RCUBE_INPUT_POST));
if (strlen($fLabel) > 32)
$rc->output->show_message('err.label.long', 'error');
else
{
$fHost = self::ntrim(get_input_value('_ident_switch_form_host', RCUBE_INPUT_POST));
if (strlen($fHost) > 64)
$rc->output->show_message('err.host.long', 'error');
else
{
$fPort = self::ntrim(get_input_value('_ident_switch_form_port', RCUBE_INPUT_POST));
if ($fPort && !ctype_digit($fPort))
$rc->output->show_message('err.port.num', 'error');
else
{
if ($fPort && ($fPort <= 0 || $fPort > 65535))
$rc->output->show_message('err.port.num', 'error');
else
{
$fUser = self::ntrim(get_input_value('_ident_switch_form_username', RCUBE_INPUT_POST));
if (strlen($fUser) > 64)
$rc->output->show_message('err.user.long', 'error');
else
{
if (!$fUser)
$rc->output->show_message('err.user.empty', 'error');
else
{
$fDelim = self::ntrim(get_input_value('_ident_switch_form_delimiter', RCUBE_INPUT_POST));
if (strlen($fDelim) > 1)
$rc->output->show_message('err.delim.long', 'error');
else
$noErrors = true;
}
}
}
}
}
}
if (!$noErrors)
{
//$rc->output->send();
$args['abort'] = true;
return $args; return $args;
}
$sql = 'SELECT password FROM ' . $rc->db->table_name($this->table) . ' WHERE iid = ? AND user_id = ?';
$q = $rc->db->query($sql, $args['id'], $rc->user->ID);
$r = $rc->db->fetch_assoc($q);
if ($r)
{ // Record already exists, will update it
$sql = 'UPDATE ' .
$rc->db->table_name($this->table) .
' SET flags = ?, label = ?, host = ?, port = ?, username = ?, password = ?, delimiter = ?, user_id = ?, iid = ?';
}
else
{ // No record exists, create new one
$sql = 'INSERT INTO ' .
$rc->db->table_name($this->table) .
'(flags, label, host, port, username, password, delimiter, user_id, iid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)';
}
// Process boolean fields // Process boolean fields
$flags = 0; $flags = 0;
@@ -255,6 +193,80 @@ class ident_switch extends rcube_plugin
if (get_input_value('_ident_switch_form_secure', RCUBE_INPUT_POST)) if (get_input_value('_ident_switch_form_secure', RCUBE_INPUT_POST))
$flags |= $this->db_secure; $flags |= $this->db_secure;
if (!($flags & $this->db_enabled))
{
$this->sw_imap_off($args['iid']);
return $args;
}
// Check field values
$errMsg = '';
$fLabel = self::ntrim(get_input_value('_ident_switch_form_label', RCUBE_INPUT_POST));
if (strlen($fLabel) > 32)
$errMsg = 'label.long';
else
{
$fHost = self::ntrim(get_input_value('_ident_switch_form_host', RCUBE_INPUT_POST));
if (strlen($fHost) > 64)
$errMsg = 'host.long';
else
{
$fPort = self::ntrim(get_input_value('_ident_switch_form_port', RCUBE_INPUT_POST));
if ($fPort && !ctype_digit($fPort))
$errMsg = 'port.num';
else
{
if ($fPort && ($fPort <= 0 || $fPort > 65535))
$errMsg = 'port.range';
else
{
$fUser = self::ntrim(get_input_value('_ident_switch_form_username', RCUBE_INPUT_POST));
if (strlen($fUser) > 64)
$errMsg = 'user.long';
else
{
if (!$fUser)
$errMsg = 'user.empty';
else
{
$fDelim = self::ntrim(get_input_value('_ident_switch_form_delimiter', RCUBE_INPUT_POST));
if (strlen($fDelim) > 1)
$errMsg = 'delim.long';
}
}
}
}
}
}
if ($errMsg)
{
$this->add_texts('localization');
$rc->output->show_message('ident_switch.err.' . $errMsg, 'error');
$args['abort'] = true;
return $args;
}
$sql = 'SELECT id, password FROM ' . $rc->db->table_name($this->table) . ' WHERE iid = ? AND user_id = ?';
$q = $rc->db->query($sql, $args['id'], $rc->user->ID);
$r = $rc->db->fetch_assoc($q);
if ($r)
{ // Record already exists, will update it
$sql = 'UPDATE ' .
$rc->db->table_name($this->table) .
' SET flags = ?, label = ?, host = ?, port = ?, username = ?, password = ?, delimiter = ?, user_id = ?, iid = ?' .
' WHERE id = ?';
}
else if ($flags & $this->db_enabled)
{ // No record exists, create new one
$sql = 'INSERT INTO ' .
$rc->db->table_name($this->table) .
'(flags, label, host, port, username, password, delimiter, user_id, iid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)';
}
if ($sql)
{
// Do we need to update pwd? // Do we need to update pwd?
$fPass = get_input_value('_ident_switch_form_password', RCUBE_INPUT_POST); $fPass = get_input_value('_ident_switch_form_password', RCUBE_INPUT_POST);
if ($fPass != $r['password']) if ($fPass != $r['password'])
@@ -270,8 +282,10 @@ class ident_switch extends rcube_plugin
$fPass, $fPass,
$fDelim, $fDelim,
$rc->user->ID, $rc->user->ID,
$args['id'] $args['id'],
$r['id']
); );
}
return $args; return $args;
} }
@@ -390,6 +404,14 @@ class ident_switch extends rcube_plugin
); );
} }
protected function sw_imap_off($iid)
{
$rc = rcmail::get_instance();
$sql = 'UPDATE ' . $rc->db->table_name($this->table) . ' SET flags = flags & ? WHERE iid = ? AND user_id = ?';
$rc->db->query($sql, ~$this->db_enabled, $iid, $rc->user->ID);
}
protected static function ntrim($str) protected static function ntrim($str)
{ {
if (is_null($str)) if (is_null($str))

View File

@@ -30,3 +30,24 @@ $labels['form.password'] = 'Password';
// Folder hierarchy delimiter // Folder hierarchy delimiter
$labels['form.delimiter'] = 'Folder hierarchy delimiter'; $labels['form.delimiter'] = 'Folder hierarchy delimiter';
// \'Username\' field in IMAP section cannot be empty.
$labels['err.user.empty'] = '\'Username\' field in IMAP section cannot be empty.';
// Value in \'Label\' field of IMAP section is too long (32 chars max).
$labels['err.label.long'] = 'Value in \'Label\' field of IMAP section is too long (32 chars max).';
// Value in \'Server host name\' field of IMAP section is too long (64 chars max).
$labels['err.host.long'] = 'Value in \'Server host name\' field of IMAP section is too long (64 chars max).';
// Value in \'Username\' field of IMAP section is too long (64 chars max).
$labels['err.user.long'] = 'Value in \'Username\' field of IMAP section is too long (64 chars max).';
// Value in \'Folder hierarchy delimiter\' field of IMAP section is too long (1 char max).
$labels['err.delim.long'] = 'Value in \'Folder hierarchy delimiter\' field of IMAP section is too long (1 char max).';
// Value in \'Port\' field of IMAP section must be a number.
$labels['err.port.num'] = 'Value in \'Port\' field of IMAP section must be a number.';
// Value in \'Port\' field of IMAP section must be between 1 and 65535.
$labels['err.port.rtange'] = 'Value in \'Port\' field of IMAP section must be between 1 and 65535.';

View File

@@ -30,3 +30,24 @@ $labels['form.password'] = 'Пароль';
// Folder hierarchy delimiter // Folder hierarchy delimiter
$labels['form.delimiter'] = 'Разделитель в иерархии папок'; $labels['form.delimiter'] = 'Разделитель в иерархии папок';
// \'Username\' field in IMAP section cannot be empty.
$labels['err.user.empty'] = '\'Имя пользователя\' в разделе IMAP не может быть пустым.';
// Value in \'Label\' field of IMAP section is too long (32 chars max).
$labels['err.label.long'] = '\'Название\' в разделе IMAP должно быть не длинее 32 символов.';
// Value in \'Server host name\' field of IMAP section is too long (64 chars max).
$labels['err.host.long'] = '\'Адрес сервера\' в разделе IMAP должен быть не длинее 64 символов.';
// Value in \'Username\' field of IMAP section is too long (64 chars max).
$labels['err.user.long'] = '\'Имя пользователя\' в секции IMAP должно быть не длинее 64 символов.';
// Value in \'Folder hierarchy delimiter\' field of IMAP section is too long (1 char max).
$labels['err.delim.long'] = '\'Разделитель в иерархии папок\' в секции IMAP должен быть не длинее 1 символа.';
// Value in \'Port\' field of IMAP section must be a number.
$labels['err.port.num'] = '\'Порт\' в секции IMAP должен быть числом.';
// Value in \'Port\' field of IMAP section must be between 1 and 65535.
$labels['err.port.rtange'] = '\'Порт\' в секции IMAP должен быть в диапазоне от 1 до 65535.';