Support IpCondition in omega-web. Fix #705.

This commit is contained in:
FelisCatus 2016-10-23 01:06:29 -04:00
parent 56d1e8c4d6
commit 8dcad1697e
23 changed files with 286 additions and 7 deletions

View File

@ -68,6 +68,20 @@ msgstr ""
"the host (domain name).<br>Example: <code>www.example.com</code> is with a " "the host (domain name).<br>Example: <code>www.example.com</code> is with a "
"host level of 3, while <code>internal</code> is of host level 1." "host level of 3, while <code>internal</code> is of host level 1."
msgid "condition_IpCondition"
msgstr "IP Literals"
msgid "condition_help_IpCondition"
msgstr ""
"Matches the request if and only if the host is a <b>literal</b> IP address and"
" in the subnet as specified by <a href='"
"https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation'>"
"CIDR notation</a>.<br>For example, given the rule <code>127.0.0.1/16</code>, "
"it matches all IP addresses like <code>127.0.*.*</code>.<br>"
"So <code>127.0.0.1</code> matches while <code>127.1.0.0</code> does not. "
"Host names like <code>localhost</code> will never match because they are "
"<b>not</b> IP literals."
msgid "condition_UrlWildcardCondition" msgid "condition_UrlWildcardCondition"
msgstr "URL wildcard" msgstr "URL wildcard"

View File

@ -69,6 +69,20 @@ msgstr ""
"název domény).<br>Příklad: <code>www.example.com</code> je na úrovni " "název domény).<br>Příklad: <code>www.example.com</code> je na úrovni "
"hostitele 3, zatímco <code>vnitřní</code> hostitele úrovně 1." "hostitele 3, zatímco <code>vnitřní</code> hostitele úrovně 1."
msgid "condition_IpCondition"
msgstr "IP Literals"
msgid "condition_help_IpCondition"
msgstr ""
"Matches the request if and only if the host is a <b>literal</b> IP address and"
" in the subnet as specified by <a href='"
"https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation'>"
"CIDR notation</a>.<br>For example, given the rule <code>127.0.0.1/16</code>, "
"it matches all IP addresses like <code>127.0.*.*</code>.<br>"
"So <code>127.0.0.1</code> matches while <code>127.1.0.0</code> does not. "
"Host names like <code>localhost</code> will never match because they are "
"<b>not</b> IP literals."
msgid "condition_UrlWildcardCondition" msgid "condition_UrlWildcardCondition"
msgstr "URL wildcard" msgstr "URL wildcard"

View File

@ -73,6 +73,20 @@ msgstr ""
"the host (domain name).<br>Example: <code>www.example.com</code> is with a " "the host (domain name).<br>Example: <code>www.example.com</code> is with a "
"host level of 3, while <code>internal</code> is of host level 1." "host level of 3, while <code>internal</code> is of host level 1."
msgid "condition_IpCondition"
msgstr "IP Literals"
msgid "condition_help_IpCondition"
msgstr ""
"Matches the request if and only if the host is a <b>literal</b> IP address and"
" in the subnet as specified by <a href='"
"https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation'>"
"CIDR notation</a>.<br>For example, given the rule <code>127.0.0.1/16</code>, "
"it matches all IP addresses like <code>127.0.*.*</code>.<br>"
"So <code>127.0.0.1</code> matches while <code>127.1.0.0</code> does not. "
"Host names like <code>localhost</code> will never match because they are "
"<b>not</b> IP literals."
msgid "condition_UrlWildcardCondition" msgid "condition_UrlWildcardCondition"
msgstr "URL wildcard" msgstr "URL wildcard"

View File

@ -69,6 +69,20 @@ msgstr ""
"the host (domain name).<br>Example: <code>www.example.com</code> is with a " "the host (domain name).<br>Example: <code>www.example.com</code> is with a "
"host level of 3, while <code>internal</code> is of host level 1." "host level of 3, while <code>internal</code> is of host level 1."
msgid "condition_IpCondition"
msgstr "IP Literals"
msgid "condition_help_IpCondition"
msgstr ""
"Matches the request if and only if the host is a <b>literal</b> IP address and"
" in the subnet as specified by <a href='"
"https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation'>"
"CIDR notation</a>.<br>For example, given the rule <code>127.0.0.1/16</code>, "
"it matches all IP addresses like <code>127.0.*.*</code>.<br>"
"So <code>127.0.0.1</code> matches while <code>127.1.0.0</code> does not. "
"Host names like <code>localhost</code> will never match because they are "
"<b>not</b> IP literals."
msgid "condition_UrlWildcardCondition" msgid "condition_UrlWildcardCondition"
msgstr "URL wildcard" msgstr "URL wildcard"

View File

@ -72,6 +72,20 @@ msgstr ""
"<code>www.ejemplo.com</code> tiene un nivel 3 de host, mientras que " "<code>www.ejemplo.com</code> tiene un nivel 3 de host, mientras que "
"<code>interno</code> es un host de nivel 1." "<code>interno</code> es un host de nivel 1."
msgid "condition_IpCondition"
msgstr "IP Literals"
msgid "condition_help_IpCondition"
msgstr ""
"Matches the request if and only if the host is a <b>literal</b> IP address and"
" in the subnet as specified by <a href='"
"https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation'>"
"CIDR notation</a>.<br>For example, given the rule <code>127.0.0.1/16</code>, "
"it matches all IP addresses like <code>127.0.*.*</code>.<br>"
"So <code>127.0.0.1</code> matches while <code>127.1.0.0</code> does not. "
"Host names like <code>localhost</code> will never match because they are "
"<b>not</b> IP literals."
msgid "condition_UrlWildcardCondition" msgid "condition_UrlWildcardCondition"
msgstr "Comodín de URL" msgstr "Comodín de URL"

View File

@ -72,6 +72,20 @@ msgstr ""
"دارای سطح میزابن سه میباشد ، در حالی که <code>داخل</code> سطح میزبان یک را " "دارای سطح میزابن سه میباشد ، در حالی که <code>داخل</code> سطح میزبان یک را "
"دارد." "دارد."
msgid "condition_IpCondition"
msgstr "IP Literals"
msgid "condition_help_IpCondition"
msgstr ""
"Matches the request if and only if the host is a <b>literal</b> IP address and"
" in the subnet as specified by <a href='"
"https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation'>"
"CIDR notation</a>.<br>For example, given the rule <code>127.0.0.1/16</code>, "
"it matches all IP addresses like <code>127.0.*.*</code>.<br>"
"So <code>127.0.0.1</code> matches while <code>127.1.0.0</code> does not. "
"Host names like <code>localhost</code> will never match because they are "
"<b>not</b> IP literals."
msgid "condition_UrlWildcardCondition" msgid "condition_UrlWildcardCondition"
msgstr "فرانویسه ادرس (URL)" msgstr "فرانویسه ادرس (URL)"

View File

@ -70,6 +70,20 @@ msgstr ""
"the host (domain name).<br>Example: <code>www.example.com</code> is with a " "the host (domain name).<br>Example: <code>www.example.com</code> is with a "
"host level of 3, while <code>internal</code> is of host level 1." "host level of 3, while <code>internal</code> is of host level 1."
msgid "condition_IpCondition"
msgstr "IP Literals"
msgid "condition_help_IpCondition"
msgstr ""
"Matches the request if and only if the host is a <b>literal</b> IP address and"
" in the subnet as specified by <a href='"
"https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation'>"
"CIDR notation</a>.<br>For example, given the rule <code>127.0.0.1/16</code>, "
"it matches all IP addresses like <code>127.0.*.*</code>.<br>"
"So <code>127.0.0.1</code> matches while <code>127.1.0.0</code> does not. "
"Host names like <code>localhost</code> will never match because they are "
"<b>not</b> IP literals."
msgid "condition_UrlWildcardCondition" msgid "condition_UrlWildcardCondition"
msgstr "URL wildcard" msgstr "URL wildcard"

View File

@ -53,6 +53,20 @@ msgstr ""
msgid "condition_help_HostLevelsCondition" msgid "condition_help_HostLevelsCondition"
msgstr "" msgstr ""
msgid "condition_IpCondition"
msgstr "IP Literals"
msgid "condition_help_IpCondition"
msgstr ""
"Matches the request if and only if the host is a <b>literal</b> IP address and"
" in the subnet as specified by <a href='"
"https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation'>"
"CIDR notation</a>.<br>For example, given the rule <code>127.0.0.1/16</code>, "
"it matches all IP addresses like <code>127.0.*.*</code>.<br>"
"So <code>127.0.0.1</code> matches while <code>127.1.0.0</code> does not. "
"Host names like <code>localhost</code> will never match because they are "
"<b>not</b> IP literals."
msgid "condition_UrlWildcardCondition" msgid "condition_UrlWildcardCondition"
msgstr "" msgstr ""

View File

@ -66,6 +66,20 @@ msgstr ""
"the host (domain name).<br>Example: <code>www.example.com</code> is with a " "the host (domain name).<br>Example: <code>www.example.com</code> is with a "
"host level of 3, while <code>internal</code> is of host level 1." "host level of 3, while <code>internal</code> is of host level 1."
msgid "condition_IpCondition"
msgstr "IP Literals"
msgid "condition_help_IpCondition"
msgstr ""
"Matches the request if and only if the host is a <b>literal</b> IP address and"
" in the subnet as specified by <a href='"
"https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation'>"
"CIDR notation</a>.<br>For example, given the rule <code>127.0.0.1/16</code>, "
"it matches all IP addresses like <code>127.0.*.*</code>.<br>"
"So <code>127.0.0.1</code> matches while <code>127.1.0.0</code> does not. "
"Host names like <code>localhost</code> will never match because they are "
"<b>not</b> IP literals."
msgid "condition_UrlWildcardCondition" msgid "condition_UrlWildcardCondition"
msgstr "URLワイルドカード" msgstr "URLワイルドカード"

View File

@ -54,6 +54,20 @@ msgstr ""
msgid "condition_help_HostLevelsCondition" msgid "condition_help_HostLevelsCondition"
msgstr "" msgstr ""
msgid "condition_IpCondition"
msgstr "IP Literals"
msgid "condition_help_IpCondition"
msgstr ""
"Matches the request if and only if the host is a <b>literal</b> IP address and"
" in the subnet as specified by <a href='"
"https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation'>"
"CIDR notation</a>.<br>For example, given the rule <code>127.0.0.1/16</code>, "
"it matches all IP addresses like <code>127.0.*.*</code>.<br>"
"So <code>127.0.0.1</code> matches while <code>127.1.0.0</code> does not. "
"Host names like <code>localhost</code> will never match because they are "
"<b>not</b> IP literals."
msgid "condition_UrlWildcardCondition" msgid "condition_UrlWildcardCondition"
msgstr "" msgstr ""

View File

@ -69,6 +69,20 @@ msgstr ""
"the host (domain name).<br>Example: <code>www.example.com</code> is with a " "the host (domain name).<br>Example: <code>www.example.com</code> is with a "
"host level of 3, while <code>internal</code> is of host level 1." "host level of 3, while <code>internal</code> is of host level 1."
msgid "condition_IpCondition"
msgstr "IP Literals"
msgid "condition_help_IpCondition"
msgstr ""
"Matches the request if and only if the host is a <b>literal</b> IP address and"
" in the subnet as specified by <a href='"
"https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation'>"
"CIDR notation</a>.<br>For example, given the rule <code>127.0.0.1/16</code>, "
"it matches all IP addresses like <code>127.0.*.*</code>.<br>"
"So <code>127.0.0.1</code> matches while <code>127.1.0.0</code> does not. "
"Host names like <code>localhost</code> will never match because they are "
"<b>not</b> IP literals."
msgid "condition_UrlWildcardCondition" msgid "condition_UrlWildcardCondition"
msgstr "URL wildcard" msgstr "URL wildcard"

View File

@ -73,6 +73,20 @@ msgstr ""
"the host (domain name).<br>Example: <code>www.example.com</code> is with a " "the host (domain name).<br>Example: <code>www.example.com</code> is with a "
"host level of 3, while <code>internal</code> is of host level 1." "host level of 3, while <code>internal</code> is of host level 1."
msgid "condition_IpCondition"
msgstr "IP Literals"
msgid "condition_help_IpCondition"
msgstr ""
"Matches the request if and only if the host is a <b>literal</b> IP address and"
" in the subnet as specified by <a href='"
"https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation'>"
"CIDR notation</a>.<br>For example, given the rule <code>127.0.0.1/16</code>, "
"it matches all IP addresses like <code>127.0.*.*</code>.<br>"
"So <code>127.0.0.1</code> matches while <code>127.1.0.0</code> does not. "
"Host names like <code>localhost</code> will never match because they are "
"<b>not</b> IP literals."
msgid "condition_UrlWildcardCondition" msgid "condition_UrlWildcardCondition"
msgstr "URL wildcard" msgstr "URL wildcard"

View File

@ -52,6 +52,20 @@ msgstr ""
msgid "condition_help_HostLevelsCondition" msgid "condition_help_HostLevelsCondition"
msgstr "" msgstr ""
msgid "condition_IpCondition"
msgstr "IP Literals"
msgid "condition_help_IpCondition"
msgstr ""
"Matches the request if and only if the host is a <b>literal</b> IP address and"
" in the subnet as specified by <a href='"
"https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation'>"
"CIDR notation</a>.<br>For example, given the rule <code>127.0.0.1/16</code>, "
"it matches all IP addresses like <code>127.0.*.*</code>.<br>"
"So <code>127.0.0.1</code> matches while <code>127.1.0.0</code> does not. "
"Host names like <code>localhost</code> will never match because they are "
"<b>not</b> IP literals."
msgid "condition_UrlWildcardCondition" msgid "condition_UrlWildcardCondition"
msgstr "" msgstr ""

View File

@ -54,6 +54,20 @@ msgstr ""
msgid "condition_help_HostLevelsCondition" msgid "condition_help_HostLevelsCondition"
msgstr "" msgstr ""
msgid "condition_IpCondition"
msgstr "IP Literals"
msgid "condition_help_IpCondition"
msgstr ""
"Matches the request if and only if the host is a <b>literal</b> IP address and"
" in the subnet as specified by <a href='"
"https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation'>"
"CIDR notation</a>.<br>For example, given the rule <code>127.0.0.1/16</code>, "
"it matches all IP addresses like <code>127.0.*.*</code>.<br>"
"So <code>127.0.0.1</code> matches while <code>127.1.0.0</code> does not. "
"Host names like <code>localhost</code> will never match because they are "
"<b>not</b> IP literals."
msgid "condition_UrlWildcardCondition" msgid "condition_UrlWildcardCondition"
msgstr "" msgstr ""

View File

@ -72,6 +72,20 @@ msgstr ""
"the host (domain name).<br>Example: <code>www.example.com</code> is with a " "the host (domain name).<br>Example: <code>www.example.com</code> is with a "
"host level of 3, while <code>internal</code> is of host level 1." "host level of 3, while <code>internal</code> is of host level 1."
msgid "condition_IpCondition"
msgstr "IP Literals"
msgid "condition_help_IpCondition"
msgstr ""
"Matches the request if and only if the host is a <b>literal</b> IP address and"
" in the subnet as specified by <a href='"
"https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation'>"
"CIDR notation</a>.<br>For example, given the rule <code>127.0.0.1/16</code>, "
"it matches all IP addresses like <code>127.0.*.*</code>.<br>"
"So <code>127.0.0.1</code> matches while <code>127.1.0.0</code> does not. "
"Host names like <code>localhost</code> will never match because they are "
"<b>not</b> IP literals."
msgid "condition_UrlWildcardCondition" msgid "condition_UrlWildcardCondition"
msgstr "URL wildcard" msgstr "URL wildcard"

View File

@ -62,6 +62,20 @@ msgstr ""
"如果域名层数在设定的范围内则匹配,否则不匹配。<br>域名层数是指 <b>域名共有几段(以点分隔)</b>.<br>例如: <code>www." "如果域名层数在设定的范围内则匹配,否则不匹配。<br>域名层数是指 <b>域名共有几段(以点分隔)</b>.<br>例如: <code>www."
"example.com</code> 的域名层数为 3而 <code>internal</code> 的域名层数为 1." "example.com</code> 的域名层数为 3而 <code>internal</code> 的域名层数为 1."
msgid "condition_IpCondition"
msgstr "IP 地址字面量"
msgid "condition_help_IpCondition"
msgstr ""
"当且仅当主机是<b>字面的</b> IP 地址,且地址处于某个子网内时匹配。"
"子网使用 <a href='"
"http://www.ibm.com/support/knowledgecenter/zh/SS2MBL_9.0.2/PCAAdmin/PCA/Cfg/CIDRFormat_47.html'"
">CIDR 格式</a>表示。<br>例如,规则 <code>127.0.0.1/16</code> 会匹配所有类似 "
"<code>127.0.*.*</code> 的地址。<br>"
"因此地址 <code>127.0.0.1</code> 匹配而地址 <code>127.1.0.0</code> 不匹配。"
"主机名称,例如 <code>localhost</code> 不会被此类规则匹配,因为它们<b>不是</b> "
"IP 地址字面量。"
msgid "condition_UrlWildcardCondition" msgid "condition_UrlWildcardCondition"
msgstr "网址通配符" msgstr "网址通配符"

View File

@ -62,6 +62,20 @@ msgstr ""
"如果域名層數在設定的範圍內則匹配,否則不匹配。<br>域名層數是指 <b>域名共有幾段(以點分隔)</b>.<br>例如: <code>www." "如果域名層數在設定的範圍內則匹配,否則不匹配。<br>域名層數是指 <b>域名共有幾段(以點分隔)</b>.<br>例如: <code>www."
"example.com</code> 的域名層數為 3而 <code>internal</code> 的域名層數為 1." "example.com</code> 的域名層數為 3而 <code>internal</code> 的域名層數為 1."
msgid "condition_IpCondition"
msgstr "IP 地址字面量"
msgid "condition_help_IpCondition"
msgstr ""
"當且僅當主機是<b>字面的</b> IP 地址,且地址處於某個子網內時匹配。"
"子網使用 <a href='"
"http://www.ibm.com/support/knowledgecenter/zh/SS2MBL_9.0.2/PCAAdmin/PCA/Cfg/CIDRFormat_47.html'"
">CIDR 格式</a>表示。<br>例如,規則 <code>127.0.0.1/16</code> 會匹配所有類似"
"<code>127.0.*.*</code> 的地址。<br>"
"因此地址 <code>127.0.0.1</code> 匹配而地址 <code>127.1.0.0</code> 不匹配。"
"主機名稱,例如 <code>localhost</code> 不會被此類規則匹配,因為它們<b>不是</b> "
"IP 地址字面量。"
msgid "condition_UrlWildcardCondition" msgid "condition_UrlWildcardCondition"
msgstr "網址通配符" msgstr "網址通配符"

View File

@ -28,6 +28,7 @@
"uglify-js-real": "./uglifyjs.js" "uglify-js-real": "./uglifyjs.js"
}, },
"scripts": { "scripts": {
"dev": "npm link" "dev": "npm link",
"test": "TZ=Europe/London grunt test"
} }
} }

View File

@ -549,12 +549,13 @@ module.exports = exports =
) )
str: (condition) -> condition.ip + '/' + condition.prefixLength str: (condition) -> condition.ip + '/' + condition.prefixLength
fromStr: (str, condition) -> fromStr: (str, condition) ->
[ip, prefixLength] = str.split('/') addr = @parseIp str
condition.ip = ip if addr?
addr = @parseIp ip condition.ip = addr.addressMinusSuffix
condition.ip = '0.0.0.0' unless addr? condition.prefixLength = addr.subnetMask
condition.prefixLength = parseInt(prefixLength, 10) else
condition.prefixLength = 0 unless condition.prefixLength >= 0 condition.ip = '0.0.0.0'
condition.prefixLength = 0
condition condition
'HostLevelsCondition': 'HostLevelsCondition':

View File

@ -582,6 +582,20 @@ describe 'Conditions', ->
ip: '0.0.0.0' ip: '0.0.0.0'
prefixLength: 0 prefixLength: 0
) )
it 'should assume full match for IpCondition without prefixLength', ->
cond = Conditions.fromStr('Ip: 127.0.0.1')
cond.should.eql(
conditionType: 'IpCondition'
ip: '127.0.0.1'
prefixLength: 32
)
cond = Conditions.fromStr('Ip: ::1')
cond.should.eql(
conditionType: 'IpCondition'
ip: '::1'
prefixLength: 128
)
it 'should provide sensible fallbacks for invalid IpCondition', -> it 'should provide sensible fallbacks for invalid IpCondition', ->
cond = Conditions.fromStr('Ip: 0.0.0.0/-233') cond = Conditions.fromStr('Ip: 0.0.0.0/-233')
cond.should.eql( cond.should.eql(

View File

@ -77,6 +77,7 @@ angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $rootScope,
'HostWildcardCondition' 'HostWildcardCondition'
'HostRegexCondition' 'HostRegexCondition'
'HostLevelsCondition' 'HostLevelsCondition'
'IpCondition'
] ]
} }
{ {
@ -193,6 +194,11 @@ angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $rootScope,
return pattern.indexOf(':') >= 0 || pattern.indexOf('/') >= 0 return pattern.indexOf(':') >= 0 || pattern.indexOf('/') >= 0
return false return false
$scope.validateIpCondition = (condition, input) ->
return false unless input
ip = OmegaPac.Conditions.parseIp(input)
return ip?
$scope.getWeekdayList = OmegaPac.Conditions.getWeekdayList $scope.getWeekdayList = OmegaPac.Conditions.getWeekdayList
$scope.updateDay = (condition, i, selected) -> $scope.updateDay = (condition, i, selected) ->
condition.days ||= '-------' condition.days ||= '-------'

View File

@ -46,3 +46,18 @@ angular.module('omega').directive 'omegaInt2str', ->
parseInt(value) parseInt(value)
ngModel.$formatters.push (value) -> ngModel.$formatters.push (value) ->
'' + value '' + value
angular.module('omega').directive 'omegaIp2str', ->
restrict: 'A'
priority: 2 # Run post-link after input directive (0) and ngModel (1).
require: 'ngModel'
link: (scope, element, attr, ngModel) ->
ngModel.$parsers.push (value) ->
if value
OmegaPac.Conditions.fromStr('Ip: ' + value)
else
({conditionType: 'IpCondition', ip: '0.0.0.0', prefixLength: 0})
ngModel.$formatters.push (value) ->
if value?.ip
OmegaPac.Conditions.str(value).split(' ', 2)[1]
else
''

View File

@ -67,6 +67,10 @@ div(ng-controller='SwitchProfileCtrl')
span {{'options_hostLevelsBetween' | tr}} span {{'options_hostLevelsBetween' | tr}}
= ' ' = ' '
input.form-control(type='number' max='99' min='1' ng-model='rule.condition.maxValue' required) input.form-control(type='number' max='99' min='1' ng-model='rule.condition.maxValue' required)
span(ng-switch-when='IpCondition')
input.form-control(type='text' ng-model='rule.condition' required
omega-ip2str placeholder='127.0.0.1/8'
ui-validate='{pattern: "validateIpCondition(rule.condition, $value)"}')
span.host-levels-details(ng-switch-when='TimeCondition') span.host-levels-details(ng-switch-when='TimeCondition')
input.form-control(type='number' min='0' max='23' ng-model='rule.condition.startHour' required) input.form-control(type='number' min='0' max='23' ng-model='rule.condition.startHour' required)
= ' ' = ' '