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.
//* This class is loaded automatically by the ispconfig framework.
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 = '') {
global $app,$conf;
......@@ -310,6 +311,72 @@ class functions {
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 {
if(is_array($record) && count($record) > 0 && is_array($this->listDef['item'])) {
foreach($this->listDef['item'] as $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])) {
switch ($field['datatype']){
case 'VARCHAR':
......
......@@ -418,18 +418,10 @@ class remoting_lib {
$returnval = strtoupper($field_value);
break;
case 'IDNTOASCII':
if(function_exists('idn_to_ascii')) {
$returnval = idn_to_ascii($field_value);
} else {
$returnval = $field_value;
}
$returnval = $app->functions->idn_encode($field_value);
break;
case 'IDNTOUTF8':
if(function_exists('idn_to_utf8')) {
$returnval = idn_to_utf8($field_value);
} else {
$returnval = $field_value;
}
$returnval = $app->functions->idn_decode($field_value);
break;
default:
$this->errorMessage .= "Unknown Filter: ".$filter['type'];
......
......@@ -629,7 +629,6 @@ class tform {
if(isset($field['filters']) && is_array($field['filters'])) {
$record[$key] = $this->filterField($key, (isset($record[$key]))?$record[$key]:'', $field['filters'], 'SAVE');
}
//* Validate record value
if(isset($field['validators']) && is_array($field['validators'])) {
$this->validateField($key, (isset($record[$key]))?$record[$key]:'', $field['validators']);
......@@ -738,24 +737,16 @@ class tform {
if($filter['event'] == $filter_event) {
switch ($filter['type']) {
case 'TOLOWER':
$returnval = strtolower($field_value);
$returnval = strtolower($returnval);
break;
case 'TOUPPER':
$returnval = strtoupper($field_value);
$returnval = strtoupper($returnval);
break;
case 'IDNTOASCII':
if(function_exists('idn_to_ascii')) {
$returnval = idn_to_ascii($field_value);
} else {
$returnval = $field_value;
}
$returnval = $app->functions->idn_encode($returnval);
break;
case 'IDNTOUTF8':
if(function_exists('idn_to_utf8')) {
$returnval = idn_to_utf8($field_value);
} else {
$returnval = $field_value;
}
$returnval = $app->functions->idn_decode($returnval);
break;
default:
$this->errorMessage .= "Unknown Filter: ".$filter['type'];
......@@ -763,8 +754,7 @@ class tform {
}
}
}
return $returnval;
return $returnval;
}
/**
......
......@@ -109,6 +109,13 @@ $form["tabs"]['server'] = array(
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
'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',
'errmsg' => 'hostname_error_empty'),
),
......
......@@ -212,6 +212,13 @@ $form["tabs"]['mail'] = array (
),
'admin_mail' => array (
'datatype' => 'VARCHAR',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'formtype' => 'TEXT',
'default' => '',
'value' => '',
......@@ -234,6 +241,13 @@ $form["tabs"]['mail'] = array (
),
'smtp_host' => array (
'datatype' => 'VARCHAR',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'formtype' => 'TEXT',
'default' => '',
'value' => '',
......
......@@ -46,6 +46,9 @@ $liste['auth'] = 'yes';
$liste['item'][] = array( 'field' => 'server_name',
'datatype' => 'VARCHAR',
'filters' => array( 0 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8')
),
'formtype' => 'TEXT',
'op' => 'like',
'prefix' => '%',
......
......@@ -285,6 +285,13 @@ $form["tabs"]['address'] = array (
'email' => array (
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'default' => '',
'value' => '',
'separator' => '',
......
......@@ -88,6 +88,13 @@ $form["tabs"]['domain'] = array (
'domain' => array (
'datatype' => 'VARCHAR',
'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',
'errmsg'=> 'domain_error_empty'),
1 => array ( 'type' => 'UNIQUE',
......
......@@ -286,6 +286,13 @@ $form["tabs"]['address'] = array (
'email' => array (
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'default' => '',
'value' => '',
'separator' => '',
......
......@@ -75,6 +75,9 @@ $liste["auth"] = "yes";
*****************************************************/
$liste["item"][] = array( 'field' => "domain",
'datatype' => "VARCHAR",
'filters' => array( 0 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8')
),
'formtype' => "TEXT",
'op' => "LIKE",
'prefix' => "%",
......
......@@ -78,6 +78,13 @@ $form["tabs"]['dns'] = array (
'name' => array (
'datatype' => 'VARCHAR',
'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',
'regex' => '/^[\w\.\-\*]{0,64}$/',
'errmsg'=> 'name_error_regex'),
......
......@@ -78,6 +78,13 @@ $form["tabs"]['dns'] = array (
'name' => array (
'datatype' => 'VARCHAR',
'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',
'errmsg'=> 'name_error_empty'),
1 => array ( 'type' => 'REGEX',
......@@ -100,6 +107,13 @@ $form["tabs"]['dns'] = array (
'data' => array (
'datatype' => 'VARCHAR',
'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',
'errmsg'=> 'data_error_empty'),
1 => array ( 'type' => 'REGEX',
......
......@@ -78,6 +78,13 @@ $form["tabs"]['dns'] = array (
'name' => array (
'datatype' => 'VARCHAR',
'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',
'regex' => '/^[\w\.\-\*]{0,255}$/',
'errmsg'=> 'name_error_regex'),
......@@ -98,6 +105,13 @@ $form["tabs"]['dns'] = array (
'data' => array (
'datatype' => 'VARCHAR',
'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',
'errmsg'=> 'data_error_empty'),
1 => array ( 'type' => 'REGEX',
......
......@@ -78,6 +78,13 @@ $form["tabs"]['dns'] = array (
'name' => array (
'datatype' => 'VARCHAR',
'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',
'errmsg'=> 'name_error_empty'),
1 => array ( 'type' => 'REGEX',
......
......@@ -79,6 +79,13 @@ $form["tabs"]['dns'] = array (
'name' => array (
'datatype' => 'VARCHAR',
'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',
'regex' => '/^[\w\.\-\*]{0,255}$/',
'errmsg'=> 'name_error_regex'),
......@@ -99,6 +106,13 @@ $form["tabs"]['dns'] = array (
'data' => array (
'datatype' => 'VARCHAR',
'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',
'errmsg'=> 'data_error_empty'),
1 => array ( 'type' => 'REGEX',
......
......@@ -78,6 +78,13 @@ $form["tabs"]['dns'] = array (
'name' => array (
'datatype' => 'VARCHAR',
'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',
'regex' => '/^[\w\.\-]{0,255}$/',
'errmsg'=> 'name_error_regex'),
......@@ -98,6 +105,13 @@ $form["tabs"]['dns'] = array (
'data' => array (
'datatype' => 'VARCHAR',
'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',
'errmsg'=> 'data_error_empty'),
1 => array ( 'type' => 'REGEX',
......
......@@ -78,6 +78,13 @@ $form["tabs"]['dns'] = array (
'name' => array (
'datatype' => 'VARCHAR',
'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',
'regex' => '/^[\w\.\-]{1,256}$/',
'errmsg'=> 'name_error_regex'),
......@@ -98,6 +105,13 @@ $form["tabs"]['dns'] = array (
'data' => array (
'datatype' => 'VARCHAR',
'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',
'errmsg'=> 'data_error_empty'),
1 => array ( 'type' => 'REGEX',
......
......@@ -75,6 +75,13 @@ $form["tabs"]['dns'] = array (
'width' => '30',
'maxlength' => '255'
),
'filters' => array( 0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'name' => array (
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
......
......@@ -82,6 +82,13 @@ $form["tabs"]['dns_slave'] = array (
'origin' => array (
'datatype' => 'VARCHAR',
'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',
'errmsg'=> 'origin_error_empty'),
1 => array ( 'type' => 'UNIQUE',
......@@ -99,6 +106,13 @@ $form["tabs"]['dns_slave'] = array (
'ns' => array (
'datatype' => 'VARCHAR',
'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',
'regex' => '/^[\w\.\-]{1,255}$/',
'errmsg'=> 'ns_error_regex'),
......
......@@ -83,6 +83,13 @@ $form["tabs"]['dns_soa'] = array (
'origin' => array (
'datatype' => 'VARCHAR',
'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',
'errmsg'=> 'origin_error_empty'),
1 => array ( 'type' => 'UNIQUE',
......@@ -100,6 +107,13 @@ $form["tabs"]['dns_soa'] = array (
'ns' => array (
'datatype' => 'VARCHAR',
'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',
'regex' => '/^[\w\.\-]{1,255}$/',
'errmsg'=> 'ns_error_regex'),
......@@ -113,6 +127,13 @@ $form["tabs"]['dns_soa'] = array (
'mbox' => array (
'datatype' => 'VARCHAR',
'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',
'errmsg'=> 'mbox_error_empty'),
1 => array ( 'type' => 'REGEX',
......
......@@ -78,6 +78,13 @@ $form["tabs"]['dns'] = array (
'name' => array (
'datatype' => 'VARCHAR',
'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',
'regex' => '/^[\w\.\-]{0,255}$/',
'errmsg'=> 'name_error_regex'),
......
......@@ -78,6 +78,13 @@ $form["tabs"]['dns'] = array (
'name' => array (
'datatype' => 'VARCHAR',
'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',
'regex' => '/^[\w\.\-]{0,255}$/',
'errmsg'=> 'name_error_regex'),
......
......@@ -74,6 +74,9 @@ $liste["item"][] = array( 'field' => "server_id",