Skip to content

Commit baab54d

Browse files
Alexander Shurshafichtner
Alexander Shursha
authored andcommitted
Add support UTF-8 domain names in black, white and exclude lists. (opnsense#1892)
1 parent 739835b commit baab54d

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ CORE_DEPENDS?= ${CORE_DEPENDS_${CORE_ARCH}} \
106106
php${CORE_PHP}-filter \
107107
php${CORE_PHP}-gettext \
108108
php${CORE_PHP}-hash \
109+
php${CORE_PHP}-intl \
109110
php${CORE_PHP}-json \
110111
php${CORE_PHP}-ldap \
111112
php${CORE_PHP}-mcrypt \

src/opnsense/mvc/app/controllers/OPNsense/Proxy/Api/SettingsController.php

+69
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,73 @@ public function fetchRBCronAction()
240240

241241
return $result;
242242
}
243+
244+
/**
245+
* get action
246+
* @return array
247+
*/
248+
public function getAction()
249+
{
250+
$result = parent::getAction();
251+
if (isset($result['proxy']['forward']['acl']['whiteList'])) {
252+
$result['proxy']['forward']['acl']['whiteList'] = self::decode($result['proxy']['forward']['acl']['whiteList']);
253+
}
254+
if (isset($result['proxy']['forward']['acl']['blackList'])) {
255+
$result['proxy']['forward']['acl']['blackList'] = self::decode($result['proxy']['forward']['acl']['blackList']);
256+
}
257+
if (isset($result['proxy']['forward']['icap']['exclude'])) {
258+
$result['proxy']['forward']['icap']['exclude'] = self::decode($result['proxy']['forward']['icap']['exclude']);
259+
}
260+
return $result;
261+
}
262+
263+
/**
264+
* set action
265+
* @return array status
266+
*/
267+
public function setAction()
268+
{
269+
$result = parent::setAction();
270+
$mdlProxy = $this->getModel();
271+
if (isset($mdlProxy->forward->acl->whiteList)) {
272+
$mdlProxy->forward->acl->whiteList = self::decode($mdlProxy->forward->acl->whiteList);
273+
}
274+
if (isset($mdlProxy->forward->acl->blackList)) {
275+
$mdlProxy->forward->acl->blackList = self::decode($mdlProxy->forward->acl->blackList);
276+
}
277+
if (isset($mdlProxy->forward->icap->exclude)) {
278+
$mdlProxy->forward->icap->exclude = self::decode($mdlProxy->forward->icap->exclude);
279+
}
280+
return $result;
281+
}
282+
283+
/**
284+
* Encode a given UTF-8 domain name
285+
* @param string Domain name (UTF-8 or UCS-4)
286+
* @return string Encoded Domain name (ACE string)
287+
*/
288+
public static function encode($domains)
289+
{
290+
$result = array();
291+
foreach (explode(",", $domains) as $domain) {
292+
if ($domain != "") {
293+
$result[] = ($domain[0] == "." ? "." : "") . idn_to_ascii($domain);
294+
}
295+
}
296+
return implode(",", $result);
297+
}
298+
299+
/**
300+
* Decode a given ACE domain name
301+
* @param string Domain name (ACE string)
302+
* @return string Decoded Domain name (UTF-8 or UCS-4)
303+
*/
304+
public static function decode($domains)
305+
{
306+
$result = array();
307+
foreach ($domains as $domain => $element) {
308+
$result[idn_to_utf8($domain)] = array('value' => idn_to_utf8($element['value']), 'selected' => $element['selected']);
309+
}
310+
return $result;
311+
}
243312
}

0 commit comments

Comments
 (0)