Commit 8c1761c6 authored by mcramer's avatar mcramer
Browse files

Implemented: FS#1102 - Convert internationalized domains to punycode automatically

- need to have the pecl idn and intl modules installed
  or
- have the idna_convert class in the classes/idn/ path
parent ecce33ad
...@@ -32,7 +32,8 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -32,7 +32,8 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//* This class is loaded automatically by the ispconfig framework. //* This class is loaded automatically by the ispconfig framework.
class functions { class functions {
var $idn_converter = null;
var $idn_converter_name = '';
public function mail($to, $subject, $text, $from, $filepath = '', $filetype = 'application/pdf', $filename = '', $cc = '', $bcc = '', $from_name = '') { public function mail($to, $subject, $text, $from, $filepath = '', $filetype = 'application/pdf', $filename = '', $cc = '', $bcc = '', $from_name = '') {
global $app,$conf; global $app,$conf;
...@@ -310,6 +311,72 @@ class functions { ...@@ -310,6 +311,72 @@ class functions {
return intval($string); return intval($string);
} }
} }
/** IDN converter wrapper.
* all converter classes should be placed in ISPC_CLASS_PATH.'/idn/'
*/
public function idn_encode($domain) {
if($domain == '') return '';
if(preg_match('/^[0-9\.]+$/', $domain)) return $domain; // may be an ip address - anyway does not need to bee encoded
// get domain and user part if it is an email
$user_part = false;
if(strpos($domain, '@') !== false) {
$user_part = substr($domain, 0, strrpos($domain, '@'));
$domain = substr($domain, strrpos($domain, '@') + 1);
}
if(function_exists('idn_to_ascii')) {
$domain = idn_to_ascii($domain);
} elseif(file_exists(ISPC_CLASS_PATH.'/idn/idna_convert.class.php')) {
/* use idna class:
* @author Matthias Sommerfeld <mso@phlylabs.de>
* @copyright 2004-2011 phlyLabs Berlin, http://phlylabs.de
* @version 0.8.0 2011-03-11
*/
if(!is_object($this->idn_converter) || $this->idn_converter_name != 'idna_convert.class') {
include_once(ISPC_CLASS_PATH.'/idn/idna_convert.class.php');
$this->idn_converter = new idna_convert(array('idn_version' => 2008));
$this->idn_converter_name = 'idna_convert.class';
}
$domain = $this->idn_converter->encode($domain);
}
if($user_part !== false) return $user_part . '@' . $domain;
else return $domain;
}
public function idn_decode($domain) {
if($domain == '') return '';
if(preg_match('/^[0-9\.]+$/', $domain)) return $domain; // may be an ip address - anyway does not need to bee decoded
// get domain and user part if it is an email
$user_part = false;
if(strpos($domain, '@') !== false) {
$user_part = substr($domain, 0, strrpos($domain, '@'));
$domain = substr($domain, strrpos($domain, '@') + 1);
}
if(function_exists('idn_to_utf8')) {
$domain = idn_to_utf8($domain);
} elseif(file_exists(ISPC_CLASS_PATH.'/idn/idna_convert.class.php')) {
/* use idna class:
* @author Matthias Sommerfeld <mso@phlylabs.de>
* @copyright 2004-2011 phlyLabs Berlin, http://phlylabs.de
* @version 0.8.0 2011-03-11
*/
if(!is_object($this->idn_converter) || $this->idn_converter_name != 'idna_convert.class') {
include_once(ISPC_CLASS_PATH.'/idn/idna_convert.class.php');
$this->idn_converter = new idna_convert(array('idn_version' => 2008));
$this->idn_converter_name = 'idna_convert.class';
}
$domain = $this->idn_converter->decode($domain);
}
if($user_part !== false) return $user_part . '@' . $domain;
else return $domain;
}
} }
......
...@@ -291,6 +291,11 @@ class listform { ...@@ -291,6 +291,11 @@ class listform {
if(is_array($record) && count($record) > 0 && is_array($this->listDef['item'])) { if(is_array($record) && count($record) > 0 && is_array($this->listDef['item'])) {
foreach($this->listDef['item'] as $field){ foreach($this->listDef['item'] as $field){
$key = $field['field']; $key = $field['field'];
//* Apply filter to record value.
if(isset($field['filters']) && is_array($field['filters'])) {
$app->uses('tform');
$record[$key] = $app->tform->filterField($key, (isset($record[$key]))?$record[$key]:'', $field['filters'], 'SHOW');
}
if(isset($record[$key])) { if(isset($record[$key])) {
switch ($field['datatype']){ switch ($field['datatype']){
case 'VARCHAR': case 'VARCHAR':
......
...@@ -418,18 +418,10 @@ class remoting_lib { ...@@ -418,18 +418,10 @@ class remoting_lib {
$returnval = strtoupper($field_value); $returnval = strtoupper($field_value);
break; break;
case 'IDNTOASCII': case 'IDNTOASCII':
if(function_exists('idn_to_ascii')) { $returnval = $app->functions->idn_encode($field_value);
$returnval = idn_to_ascii($field_value);
} else {
$returnval = $field_value;
}
break; break;
case 'IDNTOUTF8': case 'IDNTOUTF8':
if(function_exists('idn_to_utf8')) { $returnval = $app->functions->idn_decode($field_value);
$returnval = idn_to_utf8($field_value);
} else {
$returnval = $field_value;
}
break; break;
default: default:
$this->errorMessage .= "Unknown Filter: ".$filter['type']; $this->errorMessage .= "Unknown Filter: ".$filter['type'];
......
...@@ -629,7 +629,6 @@ class tform { ...@@ -629,7 +629,6 @@ class tform {
if(isset($field['filters']) && is_array($field['filters'])) { if(isset($field['filters']) && is_array($field['filters'])) {
$record[$key] = $this->filterField($key, (isset($record[$key]))?$record[$key]:'', $field['filters'], 'SAVE'); $record[$key] = $this->filterField($key, (isset($record[$key]))?$record[$key]:'', $field['filters'], 'SAVE');
} }
//* Validate record value //* Validate record value
if(isset($field['validators']) && is_array($field['validators'])) { if(isset($field['validators']) && is_array($field['validators'])) {
$this->validateField($key, (isset($record[$key]))?$record[$key]:'', $field['validators']); $this->validateField($key, (isset($record[$key]))?$record[$key]:'', $field['validators']);
...@@ -738,24 +737,16 @@ class tform { ...@@ -738,24 +737,16 @@ class tform {
if($filter['event'] == $filter_event) { if($filter['event'] == $filter_event) {
switch ($filter['type']) { switch ($filter['type']) {
case 'TOLOWER': case 'TOLOWER':
$returnval = strtolower($field_value); $returnval = strtolower($returnval);
break; break;
case 'TOUPPER': case 'TOUPPER':
$returnval = strtoupper($field_value); $returnval = strtoupper($returnval);
break; break;
case 'IDNTOASCII': case 'IDNTOASCII':
if(function_exists('idn_to_ascii')) { $returnval = $app->functions->idn_encode($returnval);
$returnval = idn_to_ascii($field_value);
} else {
$returnval = $field_value;
}
break; break;
case 'IDNTOUTF8': case 'IDNTOUTF8':
if(function_exists('idn_to_utf8')) { $returnval = $app->functions->idn_decode($returnval);
$returnval = idn_to_utf8($field_value);
} else {
$returnval = $field_value;
}
break; break;
default: default:
$this->errorMessage .= "Unknown Filter: ".$filter['type']; $this->errorMessage .= "Unknown Filter: ".$filter['type'];
...@@ -763,8 +754,7 @@ class tform { ...@@ -763,8 +754,7 @@ class tform {
} }
} }
} }
return $returnval;
return $returnval;
} }
/** /**
......
...@@ -109,6 +109,13 @@ $form["tabs"]['server'] = array( ...@@ -109,6 +109,13 @@ $form["tabs"]['server'] = array(
'datatype' => 'VARCHAR', 'datatype' => 'VARCHAR',
'formtype' => 'TEXT', 'formtype' => 'TEXT',
'default' => 'server1.domain.tld', 'default' => 'server1.domain.tld',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'validators' => array(0 => array('type' => 'NOTEMPTY', 'validators' => array(0 => array('type' => 'NOTEMPTY',
'errmsg' => 'hostname_error_empty'), 'errmsg' => 'hostname_error_empty'),
), ),
......
...@@ -212,6 +212,13 @@ $form["tabs"]['mail'] = array ( ...@@ -212,6 +212,13 @@ $form["tabs"]['mail'] = array (
), ),
'admin_mail' => array ( 'admin_mail' => array (
'datatype' => 'VARCHAR', 'datatype' => 'VARCHAR',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'formtype' => 'TEXT', 'formtype' => 'TEXT',
'default' => '', 'default' => '',
'value' => '', 'value' => '',
...@@ -234,6 +241,13 @@ $form["tabs"]['mail'] = array ( ...@@ -234,6 +241,13 @@ $form["tabs"]['mail'] = array (
), ),
'smtp_host' => array ( 'smtp_host' => array (
'datatype' => 'VARCHAR', 'datatype' => 'VARCHAR',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'formtype' => 'TEXT', 'formtype' => 'TEXT',
'default' => '', 'default' => '',
'value' => '', 'value' => '',
......
...@@ -46,6 +46,9 @@ $liste['auth'] = 'yes'; ...@@ -46,6 +46,9 @@ $liste['auth'] = 'yes';
$liste['item'][] = array( 'field' => 'server_name', $liste['item'][] = array( 'field' => 'server_name',
'datatype' => 'VARCHAR', 'datatype' => 'VARCHAR',
'filters' => array( 0 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8')
),
'formtype' => 'TEXT', 'formtype' => 'TEXT',
'op' => 'like', 'op' => 'like',
'prefix' => '%', 'prefix' => '%',
......
...@@ -285,6 +285,13 @@ $form["tabs"]['address'] = array ( ...@@ -285,6 +285,13 @@ $form["tabs"]['address'] = array (
'email' => array ( 'email' => array (
'datatype' => 'VARCHAR', 'datatype' => 'VARCHAR',
'formtype' => 'TEXT', 'formtype' => 'TEXT',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'default' => '', 'default' => '',
'value' => '', 'value' => '',
'separator' => '', 'separator' => '',
......
...@@ -88,6 +88,13 @@ $form["tabs"]['domain'] = array ( ...@@ -88,6 +88,13 @@ $form["tabs"]['domain'] = array (
'domain' => array ( 'domain' => array (
'datatype' => 'VARCHAR', 'datatype' => 'VARCHAR',
'formtype' => 'TEXT', 'formtype' => 'TEXT',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
'errmsg'=> 'domain_error_empty'), 'errmsg'=> 'domain_error_empty'),
1 => array ( 'type' => 'UNIQUE', 1 => array ( 'type' => 'UNIQUE',
......
...@@ -286,6 +286,13 @@ $form["tabs"]['address'] = array ( ...@@ -286,6 +286,13 @@ $form["tabs"]['address'] = array (
'email' => array ( 'email' => array (
'datatype' => 'VARCHAR', 'datatype' => 'VARCHAR',
'formtype' => 'TEXT', 'formtype' => 'TEXT',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'default' => '', 'default' => '',
'value' => '', 'value' => '',
'separator' => '', 'separator' => '',
......
...@@ -75,6 +75,9 @@ $liste["auth"] = "yes"; ...@@ -75,6 +75,9 @@ $liste["auth"] = "yes";
*****************************************************/ *****************************************************/
$liste["item"][] = array( 'field' => "domain", $liste["item"][] = array( 'field' => "domain",
'datatype' => "VARCHAR", 'datatype' => "VARCHAR",
'filters' => array( 0 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8')
),
'formtype' => "TEXT", 'formtype' => "TEXT",
'op' => "LIKE", 'op' => "LIKE",
'prefix' => "%", 'prefix' => "%",
......
...@@ -78,6 +78,13 @@ $form["tabs"]['dns'] = array ( ...@@ -78,6 +78,13 @@ $form["tabs"]['dns'] = array (
'name' => array ( 'name' => array (
'datatype' => 'VARCHAR', 'datatype' => 'VARCHAR',
'formtype' => 'TEXT', 'formtype' => 'TEXT',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'validators' => array ( 0 => array ( 'type' => 'REGEX', 'validators' => array ( 0 => array ( 'type' => 'REGEX',
'regex' => '/^[\w\.\-\*]{0,64}$/', 'regex' => '/^[\w\.\-\*]{0,64}$/',
'errmsg'=> 'name_error_regex'), 'errmsg'=> 'name_error_regex'),
......
...@@ -78,6 +78,13 @@ $form["tabs"]['dns'] = array ( ...@@ -78,6 +78,13 @@ $form["tabs"]['dns'] = array (
'name' => array ( 'name' => array (
'datatype' => 'VARCHAR', 'datatype' => 'VARCHAR',
'formtype' => 'TEXT', 'formtype' => 'TEXT',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
'errmsg'=> 'name_error_empty'), 'errmsg'=> 'name_error_empty'),
1 => array ( 'type' => 'REGEX', 1 => array ( 'type' => 'REGEX',
...@@ -100,6 +107,13 @@ $form["tabs"]['dns'] = array ( ...@@ -100,6 +107,13 @@ $form["tabs"]['dns'] = array (
'data' => array ( 'data' => array (
'datatype' => 'VARCHAR', 'datatype' => 'VARCHAR',
'formtype' => 'TEXT', 'formtype' => 'TEXT',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
'errmsg'=> 'data_error_empty'), 'errmsg'=> 'data_error_empty'),
1 => array ( 'type' => 'REGEX', 1 => array ( 'type' => 'REGEX',
......
...@@ -78,6 +78,13 @@ $form["tabs"]['dns'] = array ( ...@@ -78,6 +78,13 @@ $form["tabs"]['dns'] = array (
'name' => array ( 'name' => array (
'datatype' => 'VARCHAR', 'datatype' => 'VARCHAR',
'formtype' => 'TEXT', 'formtype' => 'TEXT',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'validators' => array ( 0 => array ( 'type' => 'REGEX', 'validators' => array ( 0 => array ( 'type' => 'REGEX',
'regex' => '/^[\w\.\-\*]{0,255}$/', 'regex' => '/^[\w\.\-\*]{0,255}$/',
'errmsg'=> 'name_error_regex'), 'errmsg'=> 'name_error_regex'),
...@@ -98,6 +105,13 @@ $form["tabs"]['dns'] = array ( ...@@ -98,6 +105,13 @@ $form["tabs"]['dns'] = array (
'data' => array ( 'data' => array (
'datatype' => 'VARCHAR', 'datatype' => 'VARCHAR',
'formtype' => 'TEXT', 'formtype' => 'TEXT',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
'errmsg'=> 'data_error_empty'), 'errmsg'=> 'data_error_empty'),
1 => array ( 'type' => 'REGEX', 1 => array ( 'type' => 'REGEX',
......
...@@ -78,6 +78,13 @@ $form["tabs"]['dns'] = array ( ...@@ -78,6 +78,13 @@ $form["tabs"]['dns'] = array (
'name' => array ( 'name' => array (
'datatype' => 'VARCHAR', 'datatype' => 'VARCHAR',
'formtype' => 'TEXT', 'formtype' => 'TEXT',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
'errmsg'=> 'name_error_empty'), 'errmsg'=> 'name_error_empty'),
1 => array ( 'type' => 'REGEX', 1 => array ( 'type' => 'REGEX',
......
...@@ -79,6 +79,13 @@ $form["tabs"]['dns'] = array ( ...@@ -79,6 +79,13 @@ $form["tabs"]['dns'] = array (
'name' => array ( 'name' => array (
'datatype' => 'VARCHAR', 'datatype' => 'VARCHAR',
'formtype' => 'TEXT', 'formtype' => 'TEXT',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'validators' => array ( 0 => array ( 'type' => 'REGEX', 'validators' => array ( 0 => array ( 'type' => 'REGEX',
'regex' => '/^[\w\.\-\*]{0,255}$/', 'regex' => '/^[\w\.\-\*]{0,255}$/',
'errmsg'=> 'name_error_regex'), 'errmsg'=> 'name_error_regex'),
...@@ -99,6 +106,13 @@ $form["tabs"]['dns'] = array ( ...@@ -99,6 +106,13 @@ $form["tabs"]['dns'] = array (
'data' => array ( 'data' => array (
'datatype' => 'VARCHAR', 'datatype' => 'VARCHAR',
'formtype' => 'TEXT', 'formtype' => 'TEXT',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
'errmsg'=> 'data_error_empty'), 'errmsg'=> 'data_error_empty'),
1 => array ( 'type' => 'REGEX', 1 => array ( 'type' => 'REGEX',
......
...@@ -78,6 +78,13 @@ $form["tabs"]['dns'] = array ( ...@@ -78,6 +78,13 @@ $form["tabs"]['dns'] = array (
'name' => array ( 'name' => array (
'datatype' => 'VARCHAR', 'datatype' => 'VARCHAR',
'formtype' => 'TEXT', 'formtype' => 'TEXT',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'validators' => array ( 0 => array ( 'type' => 'REGEX', 'validators' => array ( 0 => array ( 'type' => 'REGEX',
'regex' => '/^[\w\.\-]{0,255}$/', 'regex' => '/^[\w\.\-]{0,255}$/',
'errmsg'=> 'name_error_regex'), 'errmsg'=> 'name_error_regex'),
...@@ -98,6 +105,13 @@ $form["tabs"]['dns'] = array ( ...@@ -98,6 +105,13 @@ $form["tabs"]['dns'] = array (
'data' => array ( 'data' => array (
'datatype' => 'VARCHAR', 'datatype' => 'VARCHAR',
'formtype' => 'TEXT', 'formtype' => 'TEXT',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
'errmsg'=> 'data_error_empty'), 'errmsg'=> 'data_error_empty'),
1 => array ( 'type' => 'REGEX', 1 => array ( 'type' => 'REGEX',
......
...@@ -78,6 +78,13 @@ $form["tabs"]['dns'] = array ( ...@@ -78,6 +78,13 @@ $form["tabs"]['dns'] = array (
'name' => array ( 'name' => array (
'datatype' => 'VARCHAR', 'datatype' => 'VARCHAR',
'formtype' => 'TEXT', 'formtype' => 'TEXT',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'validators' => array ( 0 => array ( 'type' => 'REGEX', 'validators' => array ( 0 => array ( 'type' => 'REGEX',