xray_rule_modal.html 10 KB

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