mirror of
https://github.com/zero-peak/ZeroOmega.git
synced 2025-01-22 15:08:12 -05:00
Implement rule list exporting. Fix #99.
This commit is contained in:
parent
ca71a9a7d9
commit
8e56c4f883
@ -268,6 +268,12 @@
|
|||||||
"options_deleteProfile": {
|
"options_deleteProfile": {
|
||||||
"message": "Delete"
|
"message": "Delete"
|
||||||
},
|
},
|
||||||
|
"options_profileExportRuleList": {
|
||||||
|
"message": "Publish rule list"
|
||||||
|
},
|
||||||
|
"options_profileExportRuleListHelp": {
|
||||||
|
"message": "Export Switch Rules as text format for publishing."
|
||||||
|
},
|
||||||
"options_profileExportPac": {
|
"options_profileExportPac": {
|
||||||
"message": "Export PAC"
|
"message": "Export PAC"
|
||||||
},
|
},
|
||||||
|
@ -268,6 +268,12 @@
|
|||||||
"options_deleteProfile": {
|
"options_deleteProfile": {
|
||||||
"message": "删除"
|
"message": "删除"
|
||||||
},
|
},
|
||||||
|
"options_profileExportRuleList": {
|
||||||
|
"message": "发布规则列表"
|
||||||
|
},
|
||||||
|
"options_profileExportRuleListHelp": {
|
||||||
|
"message": "将切换规则导出为文本格式以便发布。"
|
||||||
|
},
|
||||||
"options_profileExportPac": {
|
"options_profileExportPac": {
|
||||||
"message": "导出PAC"
|
"message": "导出PAC"
|
||||||
},
|
},
|
||||||
|
@ -268,6 +268,12 @@
|
|||||||
"options_deleteProfile": {
|
"options_deleteProfile": {
|
||||||
"message": "刪除"
|
"message": "刪除"
|
||||||
},
|
},
|
||||||
|
"options_profileExportRuleList": {
|
||||||
|
"message": "釋出規則列表"
|
||||||
|
},
|
||||||
|
"options_profileExportRuleListHelp": {
|
||||||
|
"message": "將切換規則匯出為文字格式以便釋出。"
|
||||||
|
},
|
||||||
"options_profileExportPac": {
|
"options_profileExportPac": {
|
||||||
"message": "導出PAC"
|
"message": "導出PAC"
|
||||||
},
|
},
|
||||||
|
@ -268,6 +268,12 @@
|
|||||||
"options_deleteProfile": {
|
"options_deleteProfile": {
|
||||||
"message": "刪除"
|
"message": "刪除"
|
||||||
},
|
},
|
||||||
|
"options_profileExportRuleList": {
|
||||||
|
"message": "釋出規則列表"
|
||||||
|
},
|
||||||
|
"options_profileExportRuleListHelp": {
|
||||||
|
"message": "將切換規則匯出為文字格式以便釋出。"
|
||||||
|
},
|
||||||
"options_profileExportPac": {
|
"options_profileExportPac": {
|
||||||
"message": "匯出PAC"
|
"message": "匯出PAC"
|
||||||
},
|
},
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
Buffer = require('buffer').Buffer
|
Buffer = require('buffer').Buffer
|
||||||
|
Conditions = require('./conditions')
|
||||||
|
|
||||||
strStartsWith = (str, prefix) ->
|
strStartsWith = (str, prefix) ->
|
||||||
str.substr(0, prefix.length) == prefix
|
str.substr(0, prefix.length) == prefix
|
||||||
@ -52,6 +53,23 @@ module.exports = exports =
|
|||||||
# Exclusive rules have higher priority, so they come first.
|
# Exclusive rules have higher priority, so they come first.
|
||||||
return exclusive_rules.concat normal_rules
|
return exclusive_rules.concat normal_rules
|
||||||
'Switchy':
|
'Switchy':
|
||||||
|
conditionFromLegacyWildcard: (pattern) ->
|
||||||
|
if pattern[0] == '@'
|
||||||
|
pattern = pattern.substring(1)
|
||||||
|
else
|
||||||
|
if pattern.indexOf('://') <= 0 and pattern[0] != '*'
|
||||||
|
pattern = '*' + pattern
|
||||||
|
if pattern[pattern.length - 1] != '*'
|
||||||
|
pattern += '*'
|
||||||
|
|
||||||
|
host = Conditions.urlWildcard2HostWildcard(pattern)
|
||||||
|
if host
|
||||||
|
conditionType: 'HostWildcardCondition'
|
||||||
|
pattern: host
|
||||||
|
else
|
||||||
|
conditionType: 'UrlWildcardCondition'
|
||||||
|
pattern: pattern
|
||||||
|
|
||||||
parse: (text, matchProfileName, defaultProfileName) ->
|
parse: (text, matchProfileName, defaultProfileName) ->
|
||||||
text = text.trim()
|
text = text.trim()
|
||||||
normal_rules = []
|
normal_rules = []
|
||||||
@ -79,8 +97,7 @@ module.exports = exports =
|
|||||||
line = line.substring(1)
|
line = line.substring(1)
|
||||||
cond = switch section
|
cond = switch section
|
||||||
when 'WILDCARD'
|
when 'WILDCARD'
|
||||||
conditionType: 'UrlWildcardCondition'
|
exports['Switchy'].conditionFromLegacyWildcard(line)
|
||||||
pattern: line
|
|
||||||
when 'REGEXP'
|
when 'REGEXP'
|
||||||
conditionType: 'UrlRegexCondition'
|
conditionType: 'UrlRegexCondition'
|
||||||
pattern: line
|
pattern: line
|
||||||
|
@ -158,21 +158,7 @@ module.exports = (oldOptions, i18n) ->
|
|||||||
switch rule['patternType']
|
switch rule['patternType']
|
||||||
when 'wildcard'
|
when 'wildcard'
|
||||||
pattern = rule['urlPattern']
|
pattern = rule['urlPattern']
|
||||||
if pattern[0] == '@'
|
OmegaPac.RuleList['Switchy'].conditionFromLegacyWildcard(pattern)
|
||||||
pattern = pattern.substring(1)
|
|
||||||
else
|
|
||||||
if pattern.indexOf('://') <= 0 and pattern[0] != '*'
|
|
||||||
pattern = '*' + pattern
|
|
||||||
if pattern[pattern.length - 1] != '*'
|
|
||||||
pattern += '*'
|
|
||||||
|
|
||||||
host = OmegaPac.Conditions.urlWildcard2HostWildcard(pattern)
|
|
||||||
if host
|
|
||||||
conditionType: 'HostWildcardCondition'
|
|
||||||
pattern: host
|
|
||||||
else
|
|
||||||
conditionType: 'UrlWildcardCondition'
|
|
||||||
pattern: pattern
|
|
||||||
else
|
else
|
||||||
conditionType: 'UrlRegexCondition'
|
conditionType: 'UrlRegexCondition'
|
||||||
pattern: rule['urlPattern']
|
pattern: rule['urlPattern']
|
||||||
|
@ -83,6 +83,10 @@ angular.module('omega').controller 'ProfileCtrl', ($scope, $stateParams,
|
|||||||
revisionChanged = true
|
revisionChanged = true
|
||||||
this.$watch expression, onChange, true
|
this.$watch expression, onChange, true
|
||||||
|
|
||||||
|
$scope.exportRuleList = null
|
||||||
|
$scope.setExportRuleListHandler = (exportRuleList) ->
|
||||||
|
$scope.exportRuleList = exportRuleList
|
||||||
|
|
||||||
unwatch = $scope.$watch (-> $scope.options?['+' + name]), (profile) ->
|
unwatch = $scope.$watch (-> $scope.options?['+' + name]), (profile) ->
|
||||||
if not profile
|
if not profile
|
||||||
if $scope.options
|
if $scope.options
|
||||||
|
@ -40,6 +40,38 @@ angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $location,
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
exportRuleList = ->
|
||||||
|
wildcardRules = ''
|
||||||
|
regexpRules = ''
|
||||||
|
for rule in $scope.profile.rules
|
||||||
|
i = ''
|
||||||
|
if rule.profileName == 'direct'
|
||||||
|
i = '!'
|
||||||
|
switch rule.condition.conditionType
|
||||||
|
when 'HostWildcardCondition'
|
||||||
|
wildcardRules += i + '@*://' + rule.condition.pattern + '/*' + '\r\n'
|
||||||
|
when 'UrlWildcardCondition'
|
||||||
|
wildcardRules += i + '@' + rule.condition.pattern + '\r\n'
|
||||||
|
when 'UrlRegexCondition'
|
||||||
|
regexpRules += i + rule.condition.pattern + '\r\n'
|
||||||
|
|
||||||
|
text = """
|
||||||
|
; Summary: Proxy Switchy! Exported Rule List
|
||||||
|
; Date: #{new Date().toLocaleDateString()}
|
||||||
|
; Website: http://bit.ly/proxyswitchy
|
||||||
|
|
||||||
|
#BEGIN
|
||||||
|
|
||||||
|
[wildcard]
|
||||||
|
#{wildcardRules}
|
||||||
|
[regexp]
|
||||||
|
#{regexpRules}
|
||||||
|
#END
|
||||||
|
"""
|
||||||
|
blob = new Blob [text], {type: "text/plain;charset=utf-8"}
|
||||||
|
fileName = $scope.profile.name.replace(/\W+/g, '_')
|
||||||
|
saveAs(blob, "SwitchyRules_#{fileName}.ssrl")
|
||||||
|
|
||||||
expandGroups = (groups) ->
|
expandGroups = (groups) ->
|
||||||
result = []
|
result = []
|
||||||
for group in groups
|
for group in groups
|
||||||
@ -82,8 +114,10 @@ angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $location,
|
|||||||
$scope.showConditionTypes = $scope.hasConditionTypes
|
$scope.showConditionTypes = $scope.hasConditionTypes
|
||||||
if $scope.showConditionTypes == 0
|
if $scope.showConditionTypes == 0
|
||||||
$scope.conditionTypes = basicConditionTypesExpanded
|
$scope.conditionTypes = basicConditionTypesExpanded
|
||||||
|
$scope.setExportRuleListHandler(exportRuleList)
|
||||||
else
|
else
|
||||||
$scope.conditionTypes = advancedConditionTypesExpanded
|
$scope.conditionTypes = advancedConditionTypesExpanded
|
||||||
|
$scope.setExportRuleListHandler(null)
|
||||||
if not $scope.options["-showConditionTypes"]?
|
if not $scope.options["-showConditionTypes"]?
|
||||||
$scope.options["-showConditionTypes"] = $scope.showConditionTypes
|
$scope.options["-showConditionTypes"] = $scope.showConditionTypes
|
||||||
unwatchRules?()
|
unwatchRules?()
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
.page-header
|
.page-header
|
||||||
.profile-actions
|
.profile-actions
|
||||||
|
button.btn.btn-default(ng-show='exportRuleList' ng-click='exportRuleList(profile.name)' title="{{'options_profileExportRuleListHelp' | tr}}")
|
||||||
|
span.glyphicon.glyphicon-list
|
||||||
|
= ' '
|
||||||
|
| {{'options_profileExportRuleList' | tr}}
|
||||||
|
= ' '
|
||||||
button.btn.btn-default(ng-show='scriptable' ng-click='exportScript(profile.name)' title="{{'options_exportPacFileHelp' | tr}}")
|
button.btn.btn-default(ng-show='scriptable' ng-click='exportScript(profile.name)' title="{{'options_exportPacFileHelp' | tr}}")
|
||||||
span.glyphicon.glyphicon-download
|
span.glyphicon.glyphicon-download
|
||||||
= ' '
|
= ' '
|
||||||
|
Loading…
Reference in New Issue
Block a user