xray_rule_modal.html 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. {{define "modals/ruleModal"}}
  2. <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">
  3. <a-form :colon="false" :label-col="{ md: {span:8} }" :wrapper-col="{ md: {span:14} }">
  4. <a-form-item>
  5. <template slot="label">
  6. <a-tooltip>
  7. <template slot="title">
  8. <span>{{ i18n "pages.xray.rules.useComma" }}</span>
  9. </template> Source IPs <a-icon type="question-circle"></a-icon>
  10. </a-tooltip>
  11. </template>
  12. <a-input v-model.trim="ruleModal.rule.sourceIP" placeholder="e.g. 0.0.0.0/8, fc00::/7, geoip:ir"></a-input>
  13. </a-form-item>
  14. <a-form-item>
  15. <template slot="label">
  16. <a-tooltip>
  17. <template slot="title">
  18. <span>{{ i18n "pages.xray.rules.useComma" }}</span>
  19. </template> Source Port <a-icon type="question-circle"></a-icon>
  20. </a-tooltip>
  21. </template>
  22. <a-input v-model.trim="ruleModal.rule.sourcePort" placeholder="e.g. 53,443,1000-2000"></a-input>
  23. </a-form-item>
  24. <a-form-item>
  25. <template slot="label">
  26. <a-tooltip>
  27. <template slot="title">
  28. <span>{{ i18n "pages.xray.rules.useComma" }}</span>
  29. </template> VLESS Route <a-icon type="question-circle"></a-icon>
  30. </a-tooltip>
  31. </template>
  32. <a-input v-model.trim="ruleModal.rule.vlessRoute" placeholder="e.g. 53,443,1000-2000"></a-input>
  33. </a-form-item>
  34. <a-form-item label='Network'>
  35. <a-select v-model="ruleModal.rule.network" :dropdown-class-name="themeSwitcher.currentTheme">
  36. <a-select-option v-for="x in ['','TCP','UDP','TCP,UDP']" :value="x">[[ x ]]</a-select-option>
  37. </a-select>
  38. </a-form-item>
  39. <a-form-item label='Protocol'>
  40. <a-select v-model="ruleModal.rule.protocol" mode="multiple" :dropdown-class-name="themeSwitcher.currentTheme">
  41. <a-select-option v-for="x in ['http','tls','bittorrent','quic']" :value="x">[[ x ]]</a-select-option>
  42. </a-select>
  43. </a-form-item>
  44. <a-form-item label='Attributes'>
  45. <a-button icon="plus" size="small" :style="{ marginLeft: '10px' }" @click="ruleModal.rule.attrs.push(['', ''])"></a-button>
  46. </a-form-item>
  47. <a-form-item :wrapper-col="{span: 24}">
  48. <a-input-group compact v-for="(attr,index) in ruleModal.rule.attrs">
  49. <a-input :style="{ width: '50%' }" v-model="attr[0]" placeholder='{{ i18n "pages.inbounds.stream.general.name" }}'>
  50. <template slot="addonBefore" :style="{ margin: '0' }">[[ index+1 ]]</template>
  51. </a-input>
  52. <a-input :style="{ width: '50%' }" v-model="attr[1]" placeholder='{{ i18n "pages.inbounds.stream.general.value" }}'>
  53. <a-button icon="minus" slot="addonAfter" size="small" @click="ruleModal.rule.attrs.splice(index,1)"></a-button>
  54. </a-input>
  55. </a-input-group>
  56. </a-form-item>
  57. <a-form-item>
  58. <template slot="label">
  59. <a-tooltip>
  60. <template slot="title">
  61. <span>{{ i18n "pages.xray.rules.useComma" }}</span>
  62. </template> IP <a-icon type="question-circle"></a-icon>
  63. </a-tooltip>
  64. </template>
  65. <a-input v-model.trim="ruleModal.rule.ip" placeholder="e.g. 0.0.0.0/8, fc00::/7, geoip:ir"></a-input>
  66. </a-form-item>
  67. <a-form-item>
  68. <template slot="label">
  69. <a-tooltip>
  70. <template slot="title">
  71. <span>{{ i18n "pages.xray.rules.useComma" }}</span>
  72. </template> Domain <a-icon type="question-circle"></a-icon>
  73. </a-tooltip>
  74. </template>
  75. <a-input v-model.trim="ruleModal.rule.domain" placeholder="e.g. google.com, geosite:cn"></a-input>
  76. </a-form-item>
  77. <a-form-item>
  78. <template slot="label">
  79. <a-tooltip>
  80. <template slot="title">
  81. <span>{{ i18n "pages.xray.rules.useComma" }}</span>
  82. </template> User <a-icon type="question-circle"></a-icon>
  83. </a-tooltip>
  84. </template>
  85. <a-input v-model.trim="ruleModal.rule.user" placeholder="e.g. email address"></a-input>
  86. </a-form-item>
  87. <a-form-item>
  88. <template slot="label">
  89. <a-tooltip>
  90. <template slot="title">
  91. <span>{{ i18n "pages.xray.rules.useComma" }}</span>
  92. </template> Port <a-icon type="question-circle"></a-icon>
  93. </a-tooltip>
  94. </template>
  95. <a-input v-model.trim="ruleModal.rule.port" placeholder="e.g. 53,443,1000-2000"></a-input>
  96. </a-form-item>
  97. <a-form-item label='Inbound Tags'>
  98. <a-select v-model="ruleModal.rule.inboundTag" mode="multiple" :dropdown-class-name="themeSwitcher.currentTheme">
  99. <a-select-option v-for="tag in ruleModal.inboundTags" :value="tag">[[ tag ]]</a-select-option>
  100. </a-select>
  101. </a-form-item>
  102. <a-form-item label='Outbound Tag'>
  103. <a-select v-model="ruleModal.rule.outboundTag" :dropdown-class-name="themeSwitcher.currentTheme">
  104. <a-select-option v-for="tag in ruleModal.outboundTags" :value="tag">[[ tag ]]</a-select-option>
  105. </a-select>
  106. </a-form-item>
  107. <a-form-item>
  108. <template slot="label">
  109. <a-tooltip>
  110. <template slot="title">
  111. <span>{{ i18n "pages.xray.balancer.balancerDesc" }}</span>
  112. </template> Balancer Tag <a-icon type="question-circle"></a-icon>
  113. </a-tooltip>
  114. </template>
  115. <a-select v-model="ruleModal.rule.balancerTag" :dropdown-class-name="themeSwitcher.currentTheme">
  116. <a-select-option v-for="tag in ruleModal.balancerTags" :value="tag">[[ tag ]]</a-select-option>
  117. </a-select>
  118. </a-form-item>
  119. </a-form>
  120. </a-modal>
  121. <script>
  122. const ruleModal = {
  123. title: '',
  124. visible: false,
  125. confirmLoading: false,
  126. okText: '{{ i18n "sure" }}',
  127. isEdit: false,
  128. confirm: null,
  129. rule: {
  130. type: "field",
  131. domain: "",
  132. ip: "",
  133. port: "",
  134. sourcePort: "",
  135. vlessRoute: "",
  136. network: "",
  137. sourceIP: "",
  138. user: "",
  139. inboundTag: [],
  140. protocol: [],
  141. attrs: [],
  142. outboundTag: "",
  143. balancerTag: "",
  144. },
  145. inboundTags: [],
  146. outboundTags: [],
  147. users: [],
  148. balancerTags: [],
  149. ok() {
  150. newRule = ruleModal.getResult();
  151. ObjectUtil.execute(ruleModal.confirm, newRule);
  152. },
  153. show({
  154. title = '',
  155. okText = '{{ i18n "sure" }}',
  156. rule,
  157. confirm = (rule) => {},
  158. isEdit = false
  159. }) {
  160. this.title = title;
  161. this.okText = okText;
  162. this.confirm = confirm;
  163. this.visible = true;
  164. if (isEdit) {
  165. this.rule.domain = rule.domain ? rule.domain.join(',') : [];
  166. this.rule.ip = rule.ip ? rule.ip.join(',') : [];
  167. this.rule.port = rule.port;
  168. this.rule.sourcePort = rule.sourcePort;
  169. this.rule.vlessRoute = rule.vlessRoute;
  170. this.rule.network = rule.network;
  171. this.rule.sourceIP = rule.sourceIP ? rule.sourceIP.join(',') : [];
  172. this.rule.user = rule.user ? rule.user.join(',') : [];
  173. this.rule.inboundTag = rule.inboundTag;
  174. this.rule.protocol = rule.protocol;
  175. this.rule.attrs = rule.attrs ? Object.entries(rule.attrs) : [];
  176. this.rule.outboundTag = rule.outboundTag;
  177. this.rule.balancerTag = rule.balancerTag ? rule.balancerTag : "";
  178. } else {
  179. this.rule = {
  180. domain: "",
  181. ip: "",
  182. port: "",
  183. sourcePort: "",
  184. vlessRoute: "",
  185. network: "",
  186. sourceIP: "",
  187. user: "",
  188. inboundTag: [],
  189. protocol: [],
  190. attrs: [],
  191. outboundTag: "",
  192. balancerTag: "",
  193. }
  194. }
  195. this.isEdit = isEdit;
  196. this.inboundTags = app.templateSettings.inbounds.filter((i) => !ObjectUtil.isEmpty(i.tag)).map(obj => obj.tag);
  197. this.inboundTags.push(...app.inboundTags);
  198. if (app.enableDNS && !ObjectUtil.isEmpty(app.dnsTag)) this.inboundTags.push(app.dnsTag)
  199. this.outboundTags = ["", ...app.templateSettings.outbounds.filter((o) => !ObjectUtil.isEmpty(o.tag)).map(obj => obj.tag)];
  200. if (app.templateSettings.reverse) {
  201. if (app.templateSettings.reverse.bridges) {
  202. this.inboundTags.push(...app.templateSettings.reverse.bridges.map(b => b.tag));
  203. }
  204. if (app.templateSettings.reverse.portals) this.outboundTags.push(...app.templateSettings.reverse.portals.map(b => b.tag));
  205. }
  206. if (app.templateSettings.routing && app.templateSettings.routing.balancers) {
  207. this.balancerTags = ["", ...app.templateSettings.routing.balancers.filter((o) => !ObjectUtil.isEmpty(o.tag)).map(obj => obj.tag)];
  208. }
  209. },
  210. close() {
  211. ruleModal.visible = false;
  212. ruleModal.loading(false);
  213. },
  214. loading(loading = true) {
  215. ruleModal.confirmLoading = loading;
  216. },
  217. getResult() {
  218. value = ruleModal.rule;
  219. rule = {};
  220. newRule = {};
  221. rule.type = "field";
  222. rule.domain = value.domain.length > 0 ? value.domain.split(',') : [];
  223. rule.ip = value.ip.length > 0 ? value.ip.split(',') : [];
  224. rule.port = value.port;
  225. rule.sourcePort = value.sourcePort;
  226. rule.vlessRoute = value.vlessRoute;
  227. rule.network = value.network;
  228. rule.sourceIP = value.sourceIP.length > 0 ? value.sourceIP.split(',') : [];
  229. rule.user = value.user.length > 0 ? value.user.split(',') : [];
  230. rule.inboundTag = value.inboundTag;
  231. rule.protocol = value.protocol;
  232. rule.attrs = Object.fromEntries(value.attrs);
  233. rule.outboundTag = value.outboundTag == "" ? undefined : value.outboundTag;
  234. rule.balancerTag = value.balancerTag == "" ? undefined : value.balancerTag;
  235. for (const [key, value] of Object.entries(rule)) {
  236. if (value !== null && value !== undefined && !(Array.isArray(value) && value.length === 0) && !(typeof value === 'object' && Object.keys(value).length === 0) && value !== '') {
  237. newRule[key] = value;
  238. }
  239. }
  240. return newRule;
  241. }
  242. };
  243. new Vue({
  244. delimiters: ['[[', ']]'],
  245. el: '#rule-modal',
  246. data: {
  247. ruleModal: ruleModal,
  248. }
  249. });
  250. </script>
  251. {{end}}