Skip to content

Commit

Permalink
feat: 增加规则过滤关键词
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed Nov 17, 2019
1 parent 1978429 commit 128f648
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lib/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import nunjucks from 'nunjucks';
import { JsonObject } from 'type-fest';
import YAML from 'yaml';
import { toBase64 } from './utils';
import { CLASH_UNSUPPORTED_RULE, MELLOW_UNSUPPORTED_RULE, QUANTUMULT_X_UNSUPPORTED_RULE } from './utils/constant';

export default function getEngine(templateDir: string): nunjucks.Environment {
const engine = nunjucks.configure(templateDir, {
Expand All @@ -13,10 +14,10 @@ export default function getEngine(templateDir: string): nunjucks.Environment {

return array
.filter(item => {
return item && item.trim() !== '' &&
item.toUpperCase().indexOf('USER-AGENT') === -1 &&
item.toUpperCase().indexOf('PROCESS-NAME') === -1 &&
item.toUpperCase().indexOf('URL-REGEX') === -1;
const testString: string = (!!item && item.trim() !== '') ? item.toUpperCase() : '';

return testString !== '' &&
CLASH_UNSUPPORTED_RULE.every(s => !testString.includes(s));
})
.map((item: string) => {
if (item.startsWith('#')) {
Expand All @@ -35,9 +36,10 @@ export default function getEngine(templateDir: string): nunjucks.Environment {

return array
.filter(item => {
return item && item.trim() !== '' &&
item.toUpperCase().indexOf('URL-REGEX') === -1 &&
item.toUpperCase().indexOf('PROCESS-NAME') === -1;
const testString: string = (!!item && item.trim() !== '') ? item.toUpperCase() : '';

return testString !== '' &&
QUANTUMULT_X_UNSUPPORTED_RULE.every(s => !testString.includes(s));
})
.join('\n');
});
Expand All @@ -47,9 +49,10 @@ export default function getEngine(templateDir: string): nunjucks.Environment {

return array
.filter(item => {
return item && item.trim() !== '' &&
item.toUpperCase().indexOf('URL-REGEX') === -1 &&
item.toUpperCase().indexOf('USER-AGENT') === -1;
const testString: string = (!!item && item.trim() !== '') ? item.toUpperCase() : '';

return testString !== '' &&
MELLOW_UNSUPPORTED_RULE.every(s => !testString.includes(s));
})
.map((item: string) => {
if (item.startsWith('#')) {
Expand Down
14 changes: 14 additions & 0 deletions lib/utils/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,17 @@ export const OBFS_UA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_3_1 like Mac OS X)
export const PROXY_TEST_URL = 'http://www.qualcomm.cn/generate_204';

export const PROXY_TEST_INTERVAL = 1200;

export const CLASH_UNSUPPORTED_RULE: ReadonlyArray<string> = [
'USER-AGENT', 'PROCESS-NAME', 'URL-REGEX', 'DEST-PORT', 'IN-PORT', 'RULE-SET',
'SRC-IP'
];

export const QUANTUMULT_X_UNSUPPORTED_RULE: ReadonlyArray<string> = [
'URL-REGEX', 'PROCESS-NAME', 'IP-CIDR6', 'AND', 'OR', 'NOT',
'DEST-PORT', 'SRC-IP', 'IN-PORT', 'RULE-SET'
];

export const MELLOW_UNSUPPORTED_RULE: ReadonlyArray<string> = [
'URL-REGEX', 'USER-AGENT', 'AND', 'OR', 'NOT', 'DEST-PORT', 'IN-PORT', 'SRC-IP', 'RULE-SET'
];

0 comments on commit 128f648

Please sign in to comment.