Welcome to mirror list, hosted at ThFree Co, Russian Federation.

xray_rule_modal.html « xui « html « web - github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8148d94a474d12143fcbdbad8436944dc32496f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
{{define "ruleModal"}}
<a-modal id="rule-modal" v-model="ruleModal.visible" :title="ruleModal.title" @ok="ruleModal.ok"
         :confirm-loading="ruleModal.confirmLoading" :closable="true" :mask-closable="false"
         :ok-text="ruleModal.okText" cancel-text='{{ i18n "close" }}' :class="themeSwitcher.currentTheme">
    <a-form :colon="false" :label-col="{ md: {span:6} }" :wrapper-col="{ md: {span:14} }">
        <a-form-item label='Domain Matcher'>
                    <a-select v-model="ruleModal.rule.domainMatcher" :dropdown-class-name="themeSwitcher.currentTheme">
                        <a-select-option v-for="dm in ['','hybrid','linear']" :value="dm">[[ dm ]]</a-select-option>
                    </a-select>
        </a-form-item>
        <a-form-item>
            <template slot="label">
                <a-tooltip>
                    <template slot="title">
                        <span>{{ i18n "pages.xray.rules.useComma" }}</span>
                    </template>
                    Source IPs <a-icon type="question-circle"></a-icon>
                </a-tooltip>
            </template>
            <a-input v-model.trim="ruleModal.rule.source"></a-input>
        </a-form-item>
        <a-form-item>
            <template slot="label">Source Port
                <a-tooltip>
                    <template slot="title">
                        <span>{{ i18n "pages.xray.rules.useComma" }}</span>
                    </template>
                    Source Port <a-icon type="question-circle"></a-icon>
                </a-tooltip>
            </template>
            <a-input v-model.trim="ruleModal.rule.sourcePort"></a-input>
        </a-form-item>
        <a-form-item label='Network'>
            <a-select v-model="ruleModal.rule.network" :dropdown-class-name="themeSwitcher.currentTheme">
                <a-select-option v-for="x in ['','TCP','UDP','TCP,UDP']" :value="x">[[ x ]]</a-select-option>
            </a-select>
        </a-form-item>
        <a-form-item label='Protocol'>
            <a-select v-model="ruleModal.rule.protocol" :dropdown-class-name="themeSwitcher.currentTheme">
                <a-select-option v-for="x in ['','http','tls','bittorrent']" :value="x">[[ x ]]</a-select-option>
            </a-select>
        </a-form-item>
        <a-form-item label='Attributes'>
            <a-button size="small" style="margin-left: 10px" @click="ruleModal.rule.attrs.push(['', ''])">+</a-button>
        </a-form-item>
        <a-form-item :wrapper-col="{span: 24}">
            <a-input-group compact v-for="(attr,index) in ruleModal.rule.attrs">
                <a-input style="width: 50%" v-model="attr[0]" placeholder='{{ i18n "pages.inbounds.stream.general.name" }}'>
                    <template slot="addonBefore" style="margin: 0;">[[ index+1 ]]</template>
                </a-input>
                <a-input style="width: 50%" v-model="attr[1]" placeholder='{{ i18n "pages.inbounds.stream.general.value" }}'>
                    <a-button slot="addonAfter" size="small" @click="ruleModal.rule.attrs.splice(index,1)">-</a-button>
                </a-input>
            </a-input-group>
        </a-form-item>
        <a-form-item>
            <template slot="label">
                <a-tooltip>
                    <template slot="title">
                        <span>{{ i18n "pages.xray.rules.useComma" }}</span>
                    </template>
                    IP <a-icon type="question-circle"></a-icon>
                </a-tooltip>
            </template>
            <a-input v-model.trim="ruleModal.rule.ip"></a-input>
        </a-form-item>
        <a-form-item>
            <template slot="label">
                <a-tooltip>
                    <template slot="title">
                        <span>{{ i18n "pages.xray.rules.useComma" }}</span>
                    </template>
                    Domain <a-icon type="question-circle"></a-icon>
                </a-tooltip>
            </template>
            <a-input v-model.trim="ruleModal.rule.domain"></a-input>
        </a-form-item>
        <a-form-item>
            <template slot="label">
                <a-tooltip>
                    <template slot="title">
                        <span>{{ i18n "pages.xray.rules.useComma" }}</span>
                    </template>
                    Port <a-icon type="question-circle"></a-icon>
                </a-tooltip>
            </template>
            <a-input v-model.trim="ruleModal.rule.port"></a-input>
        </a-form-item>
        <a-form-item label='Inbound Tags'>
            <a-select v-model="ruleModal.rule.inboundTag" mode="multiple" :dropdown-class-name="themeSwitcher.currentTheme">
                <a-select-option v-for="tag in ruleModal.inboundTags" :value="tag">[[ tag ]]</a-select-option>
            </a-select>
        </a-form-item>
        <a-form-item label='Outbound Tag'>
            <a-select v-model="ruleModal.rule.outboundTag" :dropdown-class-name="themeSwitcher.currentTheme">
                <a-select-option v-for="tag in ruleModal.outboundTags" :value="tag">[[ tag ]]</a-select-option>
            </a-select>
        </a-form-item>
    </table>
    </a-form>
</a-modal>
<script>

    const ruleModal = {
        title: '',
        visible: false,
        confirmLoading: false,
        okText: '{{ i18n "sure" }}',
        isEdit: false,
        confirm: null,
        rule: {
            type: "field",
            domainMatcher: "",
            domain: "",
            ip: "",
            port: "",
            sourcePort: "",
            network: "",
            source: "",
            user: "",
            inboundTag: [],
            protocol: [],
            attrs: [],
            outboundTag: "",
        },
        inboundTags: [],
        outboundTags: [],
        users: [],
        balancerTag: [],
        ok() {
            newRule = ruleModal.getResult();
            ObjectUtil.execute(ruleModal.confirm, newRule);
        },
        show({ title='', okText='{{ i18n "sure" }}', rule, confirm=(rule)=>{}, isEdit=false  }) {
            this.title = title;
            this.okText = okText;
            this.confirm = confirm;
            this.visible = true;
            if(isEdit) {
                this.rule.domainMatcher = rule.domainMatcher;
                this.rule.domain = rule.domain ? rule.domain.join(',') : [];
                this.rule.ip = rule.ip ? rule.ip.join(',') : [];
                this.rule.port = rule.port;
                this.rule.sourcePort = rule.sourcePort;
                this.rule.network = rule.network;
                this.rule.source = rule.source ? rule.source.join(',') : [];
                this.rule.user = rule.user ? rule.user.join(',') : [];
                this.rule.inboundTag = rule.inboundTag;
                this.rule.protocol = rule.protocol;
                this.rule.attrs = rule.attrs ? Object.entries(rule.attrs) : [];
                this.rule.outboundTag = rule.outboundTag;
            } else {
                this.rule = {
                    domainMatcher: "",
                    domain: "",
                    ip: "",
                    port: "",
                    sourcePort: "",
                    network: "",
                    source: "",
                    user: "",
                    inboundTag: [],
                    protocol: [],
                    attrs: [],
                    outboundTag: "",
                }
            }
            this.isEdit = isEdit;
            this.inboundTags = app.templateSettings.inbounds.filter((i) => !ObjectUtil.isEmpty(i.tag)).map(obj => obj.tag);
            this.inboundTags.push(...app.inboundTags);
            this.outboundTags = app.templateSettings.outbounds.filter((o) => !ObjectUtil.isEmpty(o.tag)).map(obj => obj.tag);
            if(app.templateSettings.reverse){
                if(app.templateSettings.reverse.bridges) {
                    this.inboundTags.push(...app.templateSettings.reverse.bridges.map(b => b.tag));
                }
                if(app.templateSettings.reverse.portals) this.outboundTags.push(...app.templateSettings.reverse.portals.map(b => b.tag));
            }
        },
        close() {
            ruleModal.visible = false;
            ruleModal.loading(false);
        },
        loading(loading) {
            ruleModal.confirmLoading = loading;
        },
        getResult() {
            value = ruleModal.rule;
            rule = {};
            newRule = {};
            rule.type = "field";
            rule.domainMatcher = value.domainMatcher;
            rule.domain = value.domain.length>0 ? value.domain.split(',') : [];
            rule.ip = value.ip.length>0 ? value.ip.split(',') : [];
            rule.port = value.port;
            rule.sourcePort = value.sourcePort;
            rule.network = value.network;
            rule.source = value.source.length>0 ? value.source.split(',') : [];
            rule.user = value.user.length>0 ? value.user.split(',') : [];
            rule.inboundTag = value.inboundTag;
            rule.protocol = value.protocol;
            rule.attrs = Object.fromEntries(value.attrs);
            rule.outboundTag = value.outboundTag;

            for (const [key, value] of Object.entries(rule)) {
                if (
                value !== null &&
                value !== undefined &&
                !(Array.isArray(value) && value.length === 0) &&
                !(typeof value === 'object' && Object.keys(value).length === 0) &&
                value !== ''
                ) {
                    newRule[key] = value;
                }
            }
            return newRule;
        }
    };

    new Vue({
        delimiters: ['[[', ']]'],
        el: '#rule-modal',
        data: {
            ruleModal: ruleModal,
        }
    });

</script>
{{end}}