1
0

xray_rule_modal.html 9.2 KB

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