xray.html 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. {{template "head" .}}
  4. <link rel="stylesheet" href="{{ .base_path }}assets/codemirror/codemirror.css">
  5. <link rel="stylesheet" href="{{ .base_path }}assets/codemirror/fold/foldgutter.css">
  6. <link rel="stylesheet" href="{{ .base_path }}assets/codemirror/xq.css?{{ .cur_ver }}">
  7. <link rel="stylesheet" href="{{ .base_path }}assets/codemirror/lint/lint.css">
  8. <script src="{{ .base_path }}assets/js/model/outbound.js"></script>
  9. <script src="{{ .base_path }}assets/codemirror/codemirror.js"></script>
  10. <script src="{{ .base_path }}assets/codemirror/javascript.js"></script>
  11. <script src="{{ .base_path }}assets/codemirror/jshint.js"></script>
  12. <script src="{{ .base_path }}assets/codemirror/jsonlint.js"></script>
  13. <script src="{{ .base_path }}assets/codemirror/lint/lint.js"></script>
  14. <script src="{{ .base_path }}assets/codemirror/lint/javascript-lint.js"></script>
  15. <script src="{{ .base_path }}assets/codemirror/hint/javascript-hint.js"></script>
  16. <script src="{{ .base_path }}assets/codemirror/fold/foldcode.js"></script>
  17. <script src="{{ .base_path }}assets/codemirror/fold/foldgutter.js"></script>
  18. <script src="{{ .base_path }}assets/codemirror/fold/brace-fold.js"></script>
  19. <style>
  20. @media (min-width: 769px) {
  21. .ant-layout-content {
  22. margin: 24px 16px;
  23. }
  24. }
  25. @media (max-width: 768px) {
  26. .ant-tabs-nav .ant-tabs-tab {
  27. margin: 0;
  28. padding: 12px .5rem;
  29. }
  30. .ant-table-thead > tr > th,
  31. .ant-table-tbody > tr > td {
  32. padding: 10px 0px;
  33. }
  34. }
  35. .ant-tabs-bar {
  36. margin: 0;
  37. }
  38. .ant-list-item {
  39. display: block;
  40. }
  41. .collapse-title {
  42. color: inherit;
  43. font-weight: bold;
  44. font-size: 18px;
  45. padding: 10px 20px;
  46. border-bottom: 2px solid;
  47. }
  48. .collapse-title > i {
  49. color: inherit;
  50. font-size: 24px;
  51. }
  52. </style>
  53. <body>
  54. <a-layout id="app" v-cloak :class="themeSwitcher.currentTheme">
  55. {{ template "commonSider" . }}
  56. <a-layout id="content-layout">
  57. <a-layout-content>
  58. <a-spin :spinning="spinning" :delay="500" tip='{{ i18n "loading"}}'>
  59. <a-space direction="vertical">
  60. <a-card hoverable style="margin-bottom: .5rem;">
  61. <a-row>
  62. <a-col :xs="24" :sm="8" style="padding: 4px;">
  63. <a-space direction="horizontal">
  64. <a-button type="primary" :disabled="saveBtnDisable" @click="updateXraySetting">{{ i18n "pages.xray.save" }}</a-button>
  65. <a-button type="danger" :disabled="!saveBtnDisable" @click="restartXray">{{ i18n "pages.xray.restart" }}</a-button>
  66. <a-popover v-if="restartResult"
  67. :overlay-class-name="themeSwitcher.currentTheme">
  68. <span slot="title" style="font-size: 12pt">Error in running xray-core</span>
  69. <template slot="content">
  70. <p style="max-width: 400px" v-for="line in restartResult.split('\n')">[[ line ]]</p>
  71. </template>
  72. <a-icon type="question-circle"></a-icon>
  73. </a-popover>
  74. </a-space>
  75. </a-col>
  76. <a-col :xs="24" :sm="16">
  77. <a-back-top :target="() => document.getElementById('content-layout')" visibility-height="200">
  78. </a-back-top>
  79. <a-alert type="warning" style="float: right; width: fit-content"
  80. message='{{ i18n "pages.settings.infoDesc" }}'
  81. show-icon
  82. >
  83. </a-col>
  84. </a-row>
  85. </a-card>
  86. <a-tabs class="ant-card-dark-box-nohover" default-active-key="tpl-1"
  87. @change="(activeKey) => { if(activeKey == 'tpl-4') this.changeCode(); }"
  88. :class="themeSwitcher.currentTheme">
  89. <a-tab-pane key="tpl-1" tab='{{ i18n "pages.xray.basicTemplate"}}'>
  90. <a-space direction="horizontal" style="padding: 20px 20px">
  91. <a-button type="primary" @click="resetXrayConfigToDefault">{{ i18n "pages.settings.resetDefaultConfig" }}</a-button>
  92. </a-space>
  93. <a-collapse>
  94. <a-collapse-panel header='{{ i18n "pages.xray.generalConfigs"}}'>
  95. <a-row :xs="24" :sm="24" :lg="12">
  96. <a-alert type="warning" style="text-align: center;">
  97. <template slot="message">
  98. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  99. {{ i18n "pages.xray.generalConfigsDesc" }}
  100. </template>
  101. </a-alert>
  102. </a-row>
  103. <a-list-item>
  104. <a-row style="padding: 20px">
  105. <a-col :lg="24" :xl="12">
  106. <a-list-item-meta
  107. title='{{ i18n "pages.xray.FreedomStrategy" }}'
  108. description='{{ i18n "pages.xray.FreedomStrategyDesc" }}'/>
  109. </a-col>
  110. <a-col :lg="24" :xl="12">
  111. <template>
  112. <a-select
  113. v-model="freedomStrategy"
  114. :dropdown-class-name="themeSwitcher.currentTheme"
  115. style="width: 100%">
  116. <a-select-option v-for="s in outboundDomainStrategies" :value="s">[[ s ]]</a-select-option>
  117. </a-select>
  118. </template>
  119. </a-col>
  120. </a-row>
  121. </a-list-item>
  122. <a-row style="padding: 20px">
  123. <a-col :lg="24" :xl="12">
  124. <a-list-item-meta
  125. title='{{ i18n "pages.xray.RoutingStrategy" }}'
  126. description='{{ i18n "pages.xray.RoutingStrategyDesc" }}'/>
  127. </a-col>
  128. <a-col :lg="24" :xl="12">
  129. <template>
  130. <a-select
  131. v-model="routingStrategy"
  132. :dropdown-class-name="themeSwitcher.currentTheme"
  133. style="width: 100%">
  134. <a-select-option v-for="s in routingDomainStrategies" :value="s">[[ s ]]</a-select-option>
  135. </a-select>
  136. </template>
  137. </a-col>
  138. </a-row>
  139. </a-list-item>
  140. </a-collapse-panel>
  141. <a-collapse-panel header='{{ i18n "pages.xray.blockConfigs"}}'>
  142. <a-row :xs="24" :sm="24" :lg="12">
  143. <a-alert type="warning" style="text-align: center;">
  144. <template slot="message">
  145. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  146. {{ i18n "pages.xray.blockConfigsDesc" }}
  147. </template>
  148. </a-alert>
  149. </a-row>
  150. <setting-list-item type="switch" title='{{ i18n "pages.xray.Torrent"}}' desc='{{ i18n "pages.xray.TorrentDesc"}}' v-model="torrentSettings"></setting-list-item>
  151. <setting-list-item type="switch" title='{{ i18n "pages.xray.PrivateIp"}}' desc='{{ i18n "pages.xray.PrivateIpDesc"}}' v-model="privateIpSettings"></setting-list-item>
  152. <setting-list-item type="switch" title='{{ i18n "pages.xray.Ads"}}' desc='{{ i18n "pages.xray.AdsDesc"}}' v-model="AdsSettings"></setting-list-item>
  153. <setting-list-item type="switch" title='{{ i18n "pages.xray.Family"}}' desc='{{ i18n "pages.xray.FamilyDesc"}}' v-model="familyProtectSettings"></setting-list-item>
  154. <setting-list-item type="switch" title='{{ i18n "pages.xray.Speedtest"}}' desc='{{ i18n "pages.xray.SpeedtestDesc"}}' v-model="SpeedTestSettings"></setting-list-item>
  155. </a-collapse-panel>
  156. <a-collapse-panel header='{{ i18n "pages.xray.blockCountryConfigs"}}'>
  157. <a-row :xs="24" :sm="24" :lg="12">
  158. <a-alert type="warning" style="text-align: center;">
  159. <template slot="message">
  160. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  161. {{ i18n "pages.xray.blockCountryConfigsDesc" }}
  162. </template>
  163. </a-alert>
  164. </a-row>
  165. <setting-list-item type="switch" title='{{ i18n "pages.xray.IRIp"}}' desc='{{ i18n "pages.xray.IRIpDesc"}}' v-model="IRIpSettings"></setting-list-item>
  166. <setting-list-item type="switch" title='{{ i18n "pages.xray.IRDomain"}}' desc='{{ i18n "pages.xray.IRDomainDesc"}}' v-model="IRDomainSettings"></setting-list-item>
  167. <setting-list-item type="switch" title='{{ i18n "pages.xray.ChinaIp"}}' desc='{{ i18n "pages.xray.ChinaIpDesc"}}' v-model="ChinaIpSettings"></setting-list-item>
  168. <setting-list-item type="switch" title='{{ i18n "pages.xray.ChinaDomain"}}' desc='{{ i18n "pages.xray.ChinaDomainDesc"}}' v-model="ChinaDomainSettings"></setting-list-item>
  169. <setting-list-item type="switch" title='{{ i18n "pages.xray.RussiaIp"}}' desc='{{ i18n "pages.xray.RussiaIpDesc"}}' v-model="RussiaIpSettings"></setting-list-item>
  170. <setting-list-item type="switch" title='{{ i18n "pages.xray.RussiaDomain"}}' desc='{{ i18n "pages.xray.RussiaDomainDesc"}}' v-model="RussiaDomainSettings"></setting-list-item>
  171. </a-collapse-panel>
  172. <a-collapse-panel header='{{ i18n "pages.xray.directCountryConfigs"}}'>
  173. <a-row :xs="24" :sm="24" :lg="12">
  174. <a-alert type="warning" style="text-align: center;">
  175. <template slot="message">
  176. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  177. {{ i18n "pages.xray.directCountryConfigsDesc" }}
  178. </template>
  179. </a-alert>
  180. </a-row>
  181. <setting-list-item type="switch" title='{{ i18n "pages.xray.DirectIRIp"}}' desc='{{ i18n "pages.xray.DirectIRIpDesc"}}' v-model="IRIpDirectSettings"></setting-list-item>
  182. <setting-list-item type="switch" title='{{ i18n "pages.xray.DirectIRDomain"}}' desc='{{ i18n "pages.xray.DirectIRDomainDesc"}}' v-model="IRDomainDirectSettings"></setting-list-item>
  183. <setting-list-item type="switch" title='{{ i18n "pages.xray.DirectChinaIp"}}' desc='{{ i18n "pages.xray.DirectChinaIpDesc"}}' v-model="ChinaIpDirectSettings"></setting-list-item>
  184. <setting-list-item type="switch" title='{{ i18n "pages.xray.DirectChinaDomain"}}' desc='{{ i18n "pages.xray.DirectChinaDomainDesc"}}' v-model="ChinaDomainDirectSettings"></setting-list-item>
  185. <setting-list-item type="switch" title='{{ i18n "pages.xray.DirectRussiaIp"}}' desc='{{ i18n "pages.xray.DirectRussiaIpDesc"}}' v-model="RussiaIpDirectSettings"></setting-list-item>
  186. <setting-list-item type="switch" title='{{ i18n "pages.xray.DirectRussiaDomain"}}' desc='{{ i18n "pages.xray.DirectRussiaDomainDesc"}}' v-model="RussiaDomainDirectSettings"></setting-list-item>
  187. </a-collapse-panel>
  188. <a-collapse-panel header='{{ i18n "pages.xray.ipv4Configs"}}'>
  189. <a-row :xs="24" :sm="24" :lg="12">
  190. <a-alert type="warning" style="text-align: center;">
  191. <template slot="message">
  192. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  193. {{ i18n "pages.xray.ipv4ConfigsDesc" }}
  194. </template>
  195. </a-alert>
  196. </a-row>
  197. <setting-list-item type="switch" title='{{ i18n "pages.xray.GoogleIPv4"}}' desc='{{ i18n "pages.xray.GoogleIPv4Desc"}}' v-model="GoogleIPv4Settings"></setting-list-item>
  198. <setting-list-item type="switch" title='{{ i18n "pages.xray.NetflixIPv4"}}' desc='{{ i18n "pages.xray.NetflixIPv4Desc"}}' v-model="NetflixIPv4Settings"></setting-list-item>
  199. </a-collapse-panel>
  200. <a-collapse-panel header='{{ i18n "pages.xray.warpConfigs"}}'>
  201. <a-row :xs="24" :sm="24" :lg="12">
  202. <a-alert type="warning" style="text-align: center;">
  203. <template slot="message">
  204. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  205. {{ i18n "pages.xray.warpConfigsDesc" }}
  206. </template>
  207. </a-alert>
  208. </a-row>
  209. <setting-list-item type="switch" title='{{ i18n "pages.xray.GoogleWARP"}}' desc='{{ i18n "pages.xray.GoogleWARPDesc"}}' v-model="GoogleWARPSettings"></setting-list-item>
  210. <setting-list-item type="switch" title='{{ i18n "pages.xray.OpenAIWARP"}}' desc='{{ i18n "pages.xray.OpenAIWARPDesc"}}' v-model="OpenAIWARPSettings"></setting-list-item>
  211. <setting-list-item type="switch" title='{{ i18n "pages.xray.NetflixWARP"}}' desc='{{ i18n "pages.xray.NetflixWARPDesc"}}' v-model="NetflixWARPSettings"></setting-list-item>
  212. <setting-list-item type="switch" title='{{ i18n "pages.xray.SpotifyWARP"}}' desc='{{ i18n "pages.xray.SpotifyWARPDesc"}}' v-model="SpotifyWARPSettings"></setting-list-item>
  213. </a-collapse-panel>
  214. </a-collapse>
  215. </a-tab-pane>
  216. <a-tab-pane key="tpl-2" tab='{{ i18n "pages.xray.Routings"}}' style="padding-top: 20px;">
  217. <a-alert type="warning" style="margin-bottom: 10px; width: fit-content"
  218. message='{{ i18n "pages.xray.RoutingsDesc"}}' show-icon></a-alert>
  219. <a-button type="primary" icon="plus" @click="addRule">{{ i18n "pages.xray.rules.add" }}</a-button>
  220. <a-table :columns="isMobile ? rulesMobileColumns : rulesColumns" bordered
  221. :row-key="r => r.key"
  222. :data-source="routingRuleData"
  223. :scroll="isMobile ? {} : { x: 1000 }"
  224. :pagination="false"
  225. :indent-size="0"
  226. :style="isMobile ? 'padding: 5px 0' : 'margin-top: 10px;'">
  227. <template slot="action" slot-scope="text, rule, index">
  228. [[ index+1 ]]
  229. <a-dropdown :trigger="['click']">
  230. <a-icon @click="e => e.preventDefault()" type="more" style="font-size: 16px; text-decoration: bold;"></a-icon>
  231. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  232. <a-menu-item v-if="index>0" @click="replaceRule(index,0)">
  233. <a-icon type="vertical-align-top"></a-icon>
  234. {{ i18n "pages.xray.rules.first"}}
  235. </a-menu-item>
  236. <a-menu-item v-if="index>0" @click="replaceRule(index,index-1)">
  237. <a-icon type="arrow-up"></a-icon>
  238. {{ i18n "pages.xray.rules.up"}}
  239. </a-menu-item>
  240. <a-menu-item v-if="index<routingRuleData.length-1" @click="replaceRule(index,index+1)">
  241. <a-icon type="arrow-down"></a-icon>
  242. {{ i18n "pages.xray.rules.down"}}
  243. </a-menu-item>
  244. <a-menu-item v-if="index<routingRuleData.length-1" @click="replaceRule(index,routingRuleData.length-1)">
  245. <a-icon type="vertical-align-bottom"></a-icon>
  246. {{ i18n "pages.xray.rules.last"}}
  247. </a-menu-item>
  248. <a-menu-item @click="editRule(index)">
  249. <a-icon type="edit"></a-icon>
  250. {{ i18n "edit" }}
  251. </a-menu-item>
  252. <a-menu-item @click="deleteRule(index)">
  253. <span style="color: #FF4D4F">
  254. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  255. </span>
  256. </a-menu-item>
  257. </a-menu>
  258. </a-dropdown>
  259. </template>
  260. <template slot="inbound" slot-scope="text, rule, index">
  261. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  262. <template slot="content">
  263. <p v-if="rule.inboundTag">Inbound Tag: [[ rule.inboundTag ]]</p>
  264. <p v-if="rule.user">User email: [[ rule.user ]]</p>
  265. </template>
  266. [[ [rule.inboundTag,rule.user].join('\n') ]]
  267. </a-popover>
  268. </template>
  269. <template slot="outbound" slot-scope="text, rule, index">
  270. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  271. <template slot="content">
  272. <p v-if="rule.outboundTag">Outbound Tag: [[ rule.outboundTag ]]</p>
  273. </template>
  274. [[ rule.outboundTag ]]
  275. </a-popover>
  276. </template>
  277. <template slot="info" slot-scope="text, rule, index">
  278. <a-popover placement="bottomRight"
  279. v-if="(rule.source+rule.sourcePort+rule.network+rule.protocol+rule.attrs+rule.ip+rule.domain+rule.port).length>0"
  280. :overlay-class-name="themeSwitcher.currentTheme" trigger="click">
  281. <template slot="content">
  282. <table cellpadding="2" style="max-width: 300px;">
  283. <tr v-if="rule.source">
  284. <td>Source</td>
  285. <td><a-tag color="blue" v-for="r in rule.source.split(',')">[[ r ]]</a-tag></td>
  286. </tr>
  287. <tr v-if="rule.sourcePort">
  288. <td>Source Port</td>
  289. <td><a-tag color="green" v-for="r in rule.sourcePort.split(',')">[[ r ]]</a-tag></td>
  290. </tr>
  291. <tr v-if="rule.network">
  292. <td>Network</td>
  293. <td><a-tag color="blue" v-for="r in rule.network.split(',')">[[ r ]]</a-tag></td>
  294. </tr>
  295. <tr v-if="rule.protocol">
  296. <td>Protocol</td>
  297. <td><a-tag color="green" v-for="r in rule.protocol.split(',')">[[ r ]]</a-tag></td>
  298. </tr>
  299. <tr v-if="rule.attrs">
  300. <td>Attrs</td>
  301. <td><a-tag color="blue" v-for="r in rule.attrs.split(',')">[[ r ]]</a-tag></td>
  302. </tr>
  303. <tr v-if="rule.ip">
  304. <td>IP</td>
  305. <td><a-tag color="green" v-for="r in rule.ip.split(',')">[[ r ]]</a-tag></td>
  306. </tr>
  307. <tr v-if="rule.domain">
  308. <td>Domain</td>
  309. <td><a-tag color="blue" v-for="r in rule.domain.split(',')">[[ r ]]</a-tag></td>
  310. </tr>
  311. <tr v-if="rule.port">
  312. <td>Port</td>
  313. <td><a-tag color="green" v-for="r in rule.port.split(',')">[[ r ]]</a-tag></td>
  314. </tr>
  315. </table>
  316. </template>
  317. <a-button shape="round" size="small" style="font-size: 14px; padding: 0 10px;">
  318. <a-icon type="info"></a-icon>
  319. </a-button>
  320. </a-popover>
  321. </template>
  322. </a-table>
  323. </a-tab-pane>
  324. <a-tab-pane key="tpl-3" tab='{{ i18n "pages.xray.Outbounds"}}' style="padding-top: 20px;" force-render="true">
  325. <a-button type="primary" icon="plus" @click="addOutbound()">{{ i18n "pages.xray.outbound.addOutbound" }}</a-button>
  326. <a-button type="primary" icon="plus" @click="addReverse()">{{ i18n "pages.xray.outbound.addReverse" }}</a-button>
  327. <a-row>
  328. <a-col :sm="24" :md="12">
  329. <p style="margin: 10px;">{{ i18n "pages.xray.Outbounds"}}</p>
  330. <a-table :columns="outboundColumns" bordered
  331. :row-key="r => r.key"
  332. :data-source="outboundData"
  333. :scroll="isMobile ? {} : { x: 200 }"
  334. :pagination="false"
  335. :indent-size="0"
  336. :style="isMobile ? 'padding: 5px 5px' : 'margin-right: 1px;'">
  337. <template slot="action" slot-scope="text, outbound, index">
  338. [[ index+1 ]]
  339. <a-dropdown :trigger="['click']">
  340. <a-icon @click="e => e.preventDefault()" type="more" style="font-size: 16px; text-decoration: bold;"></a-icon>
  341. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  342. <a-menu-item @click="editOutbound(index)">
  343. <a-icon type="edit"></a-icon>
  344. {{ i18n "edit" }}
  345. </a-menu-item>
  346. <a-menu-item @click="deleteOutbound(index)">
  347. <span style="color: #FF4D4F">
  348. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  349. </span>
  350. </a-menu-item>
  351. </a-menu>
  352. </a-dropdown>
  353. </template>
  354. <template slot="address" slot-scope="text, outbound, index">
  355. <p style="margin: 0 5px;" v-for="addr in findOutboundAddress(outbound)">[[ addr ]]</p>
  356. </template>
  357. <template slot="protocol" slot-scope="text, outbound, index">
  358. <a-tag style="margin:0;" color="purple">[[ outbound.protocol ]]</a-tag>
  359. <template v-if="[Protocols.VMess, Protocols.VLESS, Protocols.Trojan, Protocols.Shadowsocks].includes(outbound.protocol)">
  360. <a-tag style="margin:0;" color="blue">[[ outbound.streamSettings.network ]]</a-tag>
  361. <a-tag style="margin:0;" v-if="outbound.streamSettings.security=='tls'" color="green">tls</a-tag>
  362. <a-tag style="margin:0;" v-if="outbound.streamSettings.security=='reality'" color="green">reality</a-tag>
  363. </template>
  364. </template>
  365. </a-table>
  366. </a-col>
  367. <a-col :sm="24" :md="12" v-if="reverseData.length>0">
  368. <p style="margin: 10px;">{{ i18n "pages.xray.outbound.reverse"}}</p>
  369. <a-table :columns="reverseColumns" bordered
  370. :row-key="r => r.key"
  371. :data-source="reverseData"
  372. :scroll="isMobile ? {} : { x: 200 }"
  373. :pagination="false"
  374. :indent-size="0"
  375. :style="isMobile ? 'padding: 5px 0' : 'margin-left: 1px;'">
  376. <template slot="action" slot-scope="text, reverse, index">
  377. [[ index+1 ]]
  378. <a-dropdown :trigger="['click']">
  379. <a-icon @click="e => e.preventDefault()" type="more" style="font-size: 16px; text-decoration: bold;"></a-icon>
  380. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  381. <a-menu-item @click="editReverse(index)">
  382. <a-icon type="edit"></a-icon>
  383. {{ i18n "edit" }}
  384. </a-menu-item>
  385. <a-menu-item @click="deleteReverse(index)">
  386. <span style="color: #FF4D4F">
  387. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  388. </span>
  389. </a-menu-item>
  390. </a-menu>
  391. </a-dropdown>
  392. </template>
  393. </a-table>
  394. </a-col>
  395. </a-row>
  396. </a-tab-pane>
  397. <a-tab-pane key="tpl-4" tab='{{ i18n "pages.xray.advancedTemplate"}}' style="padding-top: 20px;" force-render="true">
  398. <a-list-item-meta title='{{ i18n "pages.xray.Template"}}' description='{{ i18n "pages.xray.TemplateDesc"}}'></a-list-item-meta>
  399. <a-radio-group v-model="advSettings" @change="changeCode" button-style="solid" style="margin: 10px 0;" :size="isMobile ? 'small' : ''">
  400. <a-radio-button value="xraySetting">{{ i18n "pages.xray.completeTemplate"}}</a-radio-button>
  401. <a-radio-button value="inboundSettings">{{ i18n "pages.xray.Inbounds" }}</a-radio-button>
  402. <a-radio-button value="outboundSettings">{{ i18n "pages.xray.Outbounds" }}</a-radio-button>
  403. <a-radio-button value="routingRuleSettings">{{ i18n "pages.xray.Routings" }}</a-radio-button>
  404. </a-radio-group>
  405. <textarea style="position:absolute; left: -800px;" id="xraySetting"></textarea>
  406. </a-tab-pane>
  407. </a-tabs>
  408. </a-space>
  409. </a-spin>
  410. </a-layout-content>
  411. </a-layout>
  412. </a-layout>
  413. {{template "js" .}}
  414. {{template "component/themeSwitcher" .}}
  415. {{template "component/setting"}}
  416. {{template "ruleModal"}}
  417. {{template "outModal"}}
  418. {{template "reverseModal"}}
  419. <script>
  420. const rulesColumns = [
  421. { title: "#", align: 'center', width: 15, scopedSlots: { customRender: 'action' } },
  422. { title: '{{ i18n "pages.xray.rules.source"}}', children: [
  423. { title: 'IP', dataIndex: "source", align: 'center', width: 20, ellipsis: true },
  424. { title: 'port', dataIndex: 'sourcePort', align: 'center', width: 10, ellipsis: true } ]},
  425. { title: '{{ i18n "pages.inbounds.network"}}', children: [
  426. { title: 'L4', dataIndex: 'network', align: 'center', width: 10 },
  427. { title: 'Protocol', dataIndex: 'protocol', align: 'center', width: 10, ellipsis: true },
  428. { title: 'Attrs', dataIndex: 'attrs', align: 'center', width: 20, ellipsis: true } ]},
  429. { title: '{{ i18n "pages.xray.rules.dest"}}', children: [
  430. { title: 'IP', dataIndex: 'ip', align: 'center', width: 20, ellipsis: true },
  431. { title: 'Domain', dataIndex: 'domain', align: 'center', width: 20, ellipsis: true },
  432. { title: 'Port', dataIndex: 'port', align: 'center', width: 10, ellipsis: true }]},
  433. { title: '{{ i18n "pages.xray.rules.inbound"}}', children: [
  434. { title: 'Inbound Tag', dataIndex: 'inboundTag', align: 'center', width: 20, ellipsis: true },
  435. { title: 'User email', dataIndex: 'user', align: 'center', width: 20, ellipsis: true }]},
  436. { title: '{{ i18n "pages.xray.rules.outbound"}}', dataIndex: 'outboundTag', align: 'center', width: 20 },
  437. ];
  438. const rulesMobileColumns = [
  439. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  440. { title: '{{ i18n "pages.xray.rules.inbound"}}', align: 'center', width: 50, ellipsis: true, scopedSlots: { customRender: 'inbound' } },
  441. { title: '{{ i18n "pages.xray.rules.outbound"}}', align: 'center', width: 50, ellipsis: true, scopedSlots: { customRender: 'outbound' } },
  442. { title: '{{ i18n "pages.xray.rules.info"}}', align: 'center', width: 50, ellipsis: true, scopedSlots: { customRender: 'info' } },
  443. ];
  444. const outboundColumns = [
  445. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  446. { title: '{{ i18n "pages.xray.outbound.tag"}}', dataIndex: 'tag', align: 'center', width: 50 },
  447. { title: '{{ i18n "protocol"}}', align: 'center', width: 50, scopedSlots: { customRender: 'protocol' } },
  448. { title: '{{ i18n "pages.xray.outbound.address"}}', align: 'center', width: 50, scopedSlots: { customRender: 'address' } },
  449. ];
  450. const reverseColumns = [
  451. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  452. { title: '{{ i18n "pages.xray.outbound.type"}}', dataIndex: 'type', align: 'center', width: 50 },
  453. { title: '{{ i18n "pages.xray.outbound.tag"}}', dataIndex: 'tag', align: 'center', width: 50 },
  454. { title: '{{ i18n "pages.xray.outbound.domain"}}', dataIndex: 'domain', align: 'center', width: 50 },
  455. ];
  456. const app = new Vue({
  457. delimiters: ['[[', ']]'],
  458. el: '#app',
  459. data: {
  460. siderDrawer,
  461. themeSwitcher,
  462. isDarkTheme: themeSwitcher.isDarkTheme,
  463. spinning: false,
  464. oldXraySetting: '',
  465. xraySetting: '',
  466. inboundTags: [],
  467. saveBtnDisable: true,
  468. restartResult: '',
  469. isMobile: window.innerWidth <= 768,
  470. advSettings: 'xraySetting',
  471. cm: null,
  472. cmOptions: {
  473. lineNumbers: true,
  474. mode: "application/json",
  475. lint: true,
  476. styleActiveLine: true,
  477. matchBrackets: true,
  478. theme: "xq",
  479. autoCloseTags: true,
  480. lineWrapping: true,
  481. indentUnit: 2,
  482. indentWithTabs: true,
  483. smartIndent: true,
  484. tabSize: 2,
  485. lineWiseCopyCut: false,
  486. foldGutter: true,
  487. gutters: [
  488. "CodeMirror-lint-markers",
  489. "CodeMirror-linenumbers",
  490. "CodeMirror-foldgutter",
  491. ],
  492. },
  493. ipv4Settings: {
  494. tag: "IPv4",
  495. protocol: "freedom",
  496. settings: {
  497. domainStrategy: "UseIPv4"
  498. }
  499. },
  500. warpSettings: {
  501. tag: "WARP",
  502. protocol: "socks",
  503. settings: {
  504. servers: [
  505. {
  506. address: "127.0.0.1",
  507. port: 40000
  508. }
  509. ]
  510. }
  511. },
  512. directSettings: {
  513. tag: "direct",
  514. protocol: "freedom"
  515. },
  516. outboundDomainStrategies: ["AsIs", "UseIP", "UseIPv4", "UseIPv6"],
  517. routingDomainStrategies: ["AsIs", "IPIfNonMatch", "IPOnDemand"],
  518. settingsData: {
  519. protocols: {
  520. bittorrent: ["bittorrent"],
  521. },
  522. ips: {
  523. local: ["geoip:private"],
  524. cn: ["geoip:cn"],
  525. ir: ["ext:geoip_IR.dat:ir"],
  526. ru: ["geoip:ru"],
  527. },
  528. domains: {
  529. ads: [
  530. "geosite:category-ads-all",
  531. "ext:geosite_IR.dat:category-ads-all"
  532. ],
  533. speedtest: ["geosite:speedtest"],
  534. openai: ["geosite:openai"],
  535. google: ["geosite:google"],
  536. spotify: ["geosite:spotify"],
  537. netflix: ["geosite:netflix"],
  538. cn: [
  539. "geosite:cn",
  540. "regexp:.*\\.cn$"
  541. ],
  542. ru: [
  543. "geosite:category-gov-ru",
  544. "regexp:.*\\.ru$"
  545. ],
  546. ir: [
  547. "regexp:.*\\.ir$",
  548. "regexp:.*\\.xn--mgba3a4f16a$", // .ایران
  549. "ext:geosite_IR.dat:ir" // have rules to bypass all .ir domains.
  550. ]
  551. },
  552. familyProtectDNS: {
  553. "servers": [
  554. "1.1.1.3", // https://developers.cloudflare.com/1.1.1.1/setup/
  555. "1.0.0.3",
  556. "94.140.14.15", // https://adguard-dns.io/kb/general/dns-providers/
  557. "94.140.15.16"
  558. ],
  559. "queryStrategy": "UseIPv4"
  560. },
  561. }
  562. },
  563. methods: {
  564. loading(spinning = true) {
  565. this.spinning = spinning;
  566. },
  567. async getXraySetting() {
  568. this.loading(true);
  569. const msg = await HttpUtil.post("/panel/xray/");
  570. this.loading(false);
  571. if (msg.success) {
  572. result = JSON.parse(msg.obj);
  573. xs = JSON.stringify(result.xraySetting, null, 2);
  574. this.oldXraySetting = xs;
  575. this.xraySetting = xs;
  576. this.inboundTags = result.inboundTags;
  577. this.saveBtnDisable = true;
  578. }
  579. },
  580. async updateXraySetting() {
  581. this.loading(true);
  582. const msg = await HttpUtil.post("/panel/xray/update", {xraySetting : this.xraySetting});
  583. this.loading(false);
  584. if (msg.success) {
  585. await this.getXraySetting();
  586. }
  587. },
  588. async restartXray() {
  589. this.loading(true);
  590. const msg = await HttpUtil.post("server/restartXrayService");
  591. this.loading(false);
  592. if (msg.success) {
  593. await PromiseUtil.sleep(500);
  594. await this.getXrayResult();
  595. }
  596. this.loading(false);
  597. },
  598. async getXrayResult() {
  599. const msg = await HttpUtil.get("/panel/xray/getXrayResult");
  600. if(msg.success){
  601. this.restartResult=msg.obj;
  602. if(msg.obj.length > 1) Vue.prototype.$message.error(msg.obj);
  603. }
  604. },
  605. async fetchUserSecret() {
  606. this.loading(true);
  607. const userMessage = await HttpUtil.post("/panel/setting/getUserSecret", this.user);
  608. if (userMessage.success) {
  609. this.user = userMessage.obj;
  610. }
  611. this.loading(false);
  612. },
  613. async updateSecret() {
  614. this.loading(true);
  615. const msg = await HttpUtil.post("/panel/setting/updateUserSecret", this.user);
  616. if (msg.success) {
  617. this.user = msg.obj;
  618. window.location.replace(basePath + "logout");
  619. }
  620. this.loading(false);
  621. await this.updateXraySetting();
  622. },
  623. generateRandomString(length) {
  624. var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  625. let randomString = "";
  626. for (let i = 0; i < length; i++) {
  627. randomString += chars[Math.floor(Math.random() * chars.length)];
  628. }
  629. return randomString;
  630. },
  631. async getNewSecret() {
  632. this.loading(true);
  633. await PromiseUtil.sleep(600);
  634. const newSecret = this.generateRandomString(64);
  635. this.user.loginSecret = newSecret;
  636. document.getElementById("token").textContent = newSecret;
  637. this.loading(false);
  638. },
  639. async toggleToken(value) {
  640. if (value) {
  641. await this.getNewSecret();
  642. } else {
  643. this.user.loginSecret = "";
  644. }
  645. },
  646. async resetXrayConfigToDefault() {
  647. this.loading(true);
  648. const msg = await HttpUtil.get("/panel/setting/getDefaultJsonConfig");
  649. this.loading(false);
  650. if (msg.success) {
  651. this.templateSettings = JSON.parse(JSON.stringify(msg.obj, null, 2));
  652. this.saveBtnDisable = true;
  653. }
  654. },
  655. syncRulesWithOutbound(tag, setting) {
  656. const newTemplateSettings = {...this.templateSettings};
  657. const haveRules = newTemplateSettings.routing.rules.some((r) => r?.outboundTag === tag);
  658. const outboundIndex = newTemplateSettings.outbounds.findIndex((o) => o.tag === tag);
  659. if (!haveRules && outboundIndex >= 0) {
  660. newTemplateSettings.outbounds.splice(outboundIndex, 1);
  661. }
  662. if (haveRules && outboundIndex === -1) {
  663. newTemplateSettings.outbounds.push(setting);
  664. }
  665. this.templateSettings = newTemplateSettings;
  666. },
  667. templateRuleGetter(routeSettings) {
  668. const { property, outboundTag } = routeSettings;
  669. let result = [];
  670. if (this.templateSettings != null) {
  671. this.templateSettings.routing.rules.forEach(
  672. (routingRule) => {
  673. if (
  674. routingRule.hasOwnProperty(property) &&
  675. routingRule.hasOwnProperty("outboundTag") &&
  676. routingRule.outboundTag === outboundTag
  677. ) {
  678. result.push(...routingRule[property]);
  679. }
  680. }
  681. );
  682. }
  683. return result;
  684. },
  685. templateRuleSetter(routeSettings) {
  686. const { data, property, outboundTag } = routeSettings;
  687. const oldTemplateSettings = this.templateSettings;
  688. const newTemplateSettings = oldTemplateSettings;
  689. currentProperty = this.templateRuleGetter({ outboundTag, property })
  690. if (currentProperty.length == 0) {
  691. const propertyRule = {
  692. type: "field",
  693. outboundTag,
  694. [property]: data
  695. };
  696. newTemplateSettings.routing.rules.push(propertyRule);
  697. }
  698. else {
  699. const newRules = [];
  700. insertedOnce = false;
  701. newTemplateSettings.routing.rules.forEach(
  702. (routingRule) => {
  703. if (
  704. routingRule.hasOwnProperty(property) &&
  705. routingRule.hasOwnProperty("outboundTag") &&
  706. routingRule.outboundTag === outboundTag
  707. ) {
  708. if (!insertedOnce && data.length > 0) {
  709. insertedOnce = true;
  710. routingRule[property] = data;
  711. newRules.push(routingRule);
  712. }
  713. }
  714. else {
  715. newRules.push(routingRule);
  716. }
  717. }
  718. );
  719. newTemplateSettings.routing.rules = newRules;
  720. }
  721. this.templateSettings = newTemplateSettings;
  722. },
  723. changeCode() {
  724. if(this.cm != null) {
  725. this.cm.toTextArea();
  726. }
  727. textAreaObj = document.getElementById('xraySetting');
  728. textAreaObj.value = this[this.advSettings];
  729. this.cm = CodeMirror.fromTextArea(textAreaObj, this.cmOptions);
  730. this.cm.on('change',editor => {
  731. value = editor.getValue();
  732. if(this.isJsonString(value)){
  733. this[this.advSettings] = value;
  734. }
  735. });
  736. },
  737. isJsonString(str) {
  738. try {
  739. JSON.parse(str);
  740. } catch (e) {
  741. return false;
  742. }
  743. return true;
  744. },
  745. findOutboundAddress(o) {
  746. serverObj = null;
  747. switch(o.protocol){
  748. case Protocols.VMess:
  749. case Protocols.VLESS:
  750. serverObj = o.settings.vnext;
  751. break;
  752. case Protocols.HTTP:
  753. case Protocols.Socks:
  754. case Protocols.Shadowsocks:
  755. case Protocols.Trojan:
  756. serverObj = o.settings.servers;
  757. break;
  758. case Protocols.DNS:
  759. return [o.settings.address + ':' + o.settings.port];
  760. default:
  761. return null;
  762. }
  763. return serverObj ? serverObj.map(obj => obj.address + ':' + obj.port) : null;
  764. },
  765. addOutbound(){
  766. outModal.show({
  767. title: '{{ i18n "pages.xray.outbound.addOutbound"}}',
  768. okText: '{{ i18n "pages.xray.outbound.addOutbound" }}',
  769. confirm: (outbound) => {
  770. outModal.loading();
  771. if(outbound.tag.length > 0){
  772. this.templateSettings.outbounds.push(outbound);
  773. this.outboundSettings = JSON.stringify(this.templateSettings.outbounds);
  774. }
  775. outModal.close();
  776. },
  777. isEdit: false,
  778. tags: this.templateSettings.outbounds.map(obj => obj.tag)
  779. });
  780. },
  781. editOutbound(index){
  782. outModal.show({
  783. title: '{{ i18n "pages.xray.outbound.editOutbound"}} ' + (index+1),
  784. outbound: app.templateSettings.outbounds[index],
  785. confirm: (outbound) => {
  786. outModal.loading();
  787. this.templateSettings.outbounds[index] = outbound;
  788. this.outboundSettings = JSON.stringify(this.templateSettings.outbounds);
  789. outModal.close();
  790. },
  791. isEdit: true,
  792. tags: this.outboundData.filter((o) => o.key != index ).map(obj => obj.tag)
  793. });
  794. },
  795. deleteOutbound(index){
  796. outbounds = this.templateSettings.outbounds;
  797. outbounds.splice(index,1);
  798. this.outboundSettings = JSON.stringify(outbounds);
  799. },
  800. addReverse(){
  801. reverseModal.show({
  802. title: '{{ i18n "pages.xray.outbound.addReverse"}}',
  803. okText: '{{ i18n "pages.xray.outbound.addReverse" }}',
  804. confirm: (reverse, rules) => {
  805. reverseModal.loading();
  806. if(reverse.tag.length > 0){
  807. newTemplateSettings = this.templateSettings;
  808. if(newTemplateSettings.reverse == undefined) newTemplateSettings.reverse = {};
  809. if(newTemplateSettings.reverse[reverse.type+'s'] == undefined) newTemplateSettings.reverse[reverse.type+'s'] = [];
  810. newTemplateSettings.reverse[reverse.type+'s'].push({ tag: reverse.tag, domain: reverse.domain });
  811. this.templateSettings = newTemplateSettings;
  812. // Add related rules
  813. this.templateSettings.routing.rules.push(...rules);
  814. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  815. }
  816. reverseModal.close();
  817. },
  818. isEdit: false
  819. });
  820. },
  821. editReverse(index){
  822. if(this.reverseData[index].type == "bridge") {
  823. oldRules = this.templateSettings.routing.rules.filter(r => r.inboundTag && r.inboundTag[0] == this.reverseData[index].tag);
  824. } else {
  825. oldRules = this.templateSettings.routing.rules.filter(r => r.outboundTag && r.outboundTag == this.reverseData[index].tag);
  826. }
  827. reverseModal.show({
  828. title: '{{ i18n "pages.xray.outbound.editReverse"}} ' + (index+1),
  829. reverse: this.reverseData[index],
  830. rules: oldRules,
  831. confirm: (reverse, rules) => {
  832. reverseModal.loading();
  833. if(reverse.tag.length > 0){
  834. oldtag = this.reverseData[index].tag;
  835. this.deleteReverse(index);
  836. newTemplateSettings = this.templateSettings;
  837. if(newTemplateSettings.reverse == undefined) newTemplateSettings.reverse = {};
  838. if(newTemplateSettings.reverse[reverse.type+'s'] == undefined) newTemplateSettings.reverse[reverse.type+'s'] = [];
  839. newTemplateSettings.reverse[reverse.type+'s'].push({ tag: reverse.tag, domain: reverse.domain });
  840. this.templateSettings = newTemplateSettings;
  841. // Adjust Rules
  842. newRules = this.templateSettings.routing.rules.filter(r => r.outboundTag != oldtag && (r.inboundTag && !r.inboundTag.includes(oldtag)));
  843. newRules.push(...rules)
  844. this.routingRuleSettings = JSON.stringify(newRules);
  845. }
  846. reverseModal.close();
  847. },
  848. isEdit: true
  849. });
  850. },
  851. deleteReverse(index){
  852. oldData = this.reverseData[index];
  853. newTemplateSettings = this.templateSettings;
  854. reverseTypeObj = newTemplateSettings.reverse[oldData.type+'s'];
  855. realIndex = reverseTypeObj.findIndex(r => r.tag==oldData.tag && r.domain==oldData.domain);
  856. newTemplateSettings.reverse[oldData.type+'s'].splice(realIndex,1);
  857. if(reverseTypeObj.length == 0) Reflect.deleteProperty(newTemplateSettings.reverse, oldData.type+'s');
  858. if(Object.keys(newTemplateSettings.reverse).length === 0) Reflect.deleteProperty(newTemplateSettings, 'reverse');
  859. newRules = newTemplateSettings.routing.rules.filter(r => r.outboundTag != oldData.tag && (r.inboundTag && !r.inboundTag.includes(oldData.tag)));
  860. newTemplateSettings.routing.rules = newRules;
  861. this.templateSettings = newTemplateSettings;
  862. },
  863. addRule(){
  864. ruleModal.show({
  865. title: '{{ i18n "pages.xray.rules.add"}}',
  866. okText: '{{ i18n "pages.xray.rules.add" }}',
  867. confirm: (rule) => {
  868. ruleModal.loading();
  869. if(JSON.stringify(rule).length > 3){
  870. this.templateSettings.routing.rules.push(rule);
  871. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  872. }
  873. ruleModal.close();
  874. },
  875. isEdit: false
  876. });
  877. },
  878. editRule(index){
  879. ruleModal.show({
  880. title: '{{ i18n "pages.xray.rules.edit"}} ' + (index+1),
  881. rule: app.templateSettings.routing.rules[index],
  882. confirm: (rule) => {
  883. ruleModal.loading();
  884. if(JSON.stringify(rule).length > 3){
  885. this.templateSettings.routing.rules[index] = rule;
  886. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  887. }
  888. ruleModal.close();
  889. },
  890. isEdit: true
  891. });
  892. },
  893. replaceRule(old_index,new_index){
  894. rules = this.templateSettings.routing.rules;
  895. if (new_index >= rules.length) rules.push(undefined);
  896. rules.splice(new_index, 0, rules.splice(old_index, 1)[0]);
  897. this.routingRuleSettings = JSON.stringify(rules);
  898. },
  899. deleteRule(index){
  900. rules = this.templateSettings.routing.rules;
  901. rules.splice(index,1);
  902. this.routingRuleSettings = JSON.stringify(rules);
  903. }
  904. },
  905. async mounted() {
  906. await this.getXraySetting();
  907. await this.getXrayResult();
  908. while (true) {
  909. await PromiseUtil.sleep(600);
  910. this.saveBtnDisable = this.oldXraySetting === this.xraySetting;
  911. }
  912. },
  913. computed: {
  914. templateSettings: {
  915. get: function () { return this.xraySetting ? JSON.parse(this.xraySetting) : null; },
  916. set: function (newValue) { this.xraySetting = JSON.stringify(newValue, null, 2); },
  917. },
  918. inboundSettings: {
  919. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.inbounds, null, 2) : null; },
  920. set: function (newValue) {
  921. newTemplateSettings = this.templateSettings;
  922. newTemplateSettings.inbounds = JSON.parse(newValue);
  923. this.templateSettings = newTemplateSettings;
  924. },
  925. },
  926. outboundSettings: {
  927. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.outbounds, null, 2) : null; },
  928. set: function (newValue) {
  929. newTemplateSettings = this.templateSettings;
  930. newTemplateSettings.outbounds = JSON.parse(newValue);
  931. this.templateSettings = newTemplateSettings;
  932. },
  933. },
  934. outboundData: {
  935. get: function () {
  936. data = []
  937. if (this.templateSettings != null) {
  938. this.templateSettings.outbounds.forEach((o, index) => {
  939. data.push({'key': index, ...o});
  940. });
  941. }
  942. return data;
  943. },
  944. },
  945. reverseData: {
  946. get: function () {
  947. data = []
  948. if (this.templateSettings != null && this.templateSettings.reverse != null) {
  949. if(this.templateSettings.reverse.bridges) {
  950. this.templateSettings.reverse.bridges.forEach((o, index) => {
  951. data.push({'key': index, 'type':'bridge', ...o});
  952. });
  953. }
  954. if(this.templateSettings.reverse.portals){
  955. this.templateSettings.reverse.portals.forEach((o, index) => {
  956. data.push({'key': index, 'type':'portal', ...o});
  957. });
  958. }
  959. }
  960. return data;
  961. },
  962. },
  963. routingRuleSettings: {
  964. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.routing.rules, null, 2) : null; },
  965. set: function (newValue) {
  966. newTemplateSettings = this.templateSettings;
  967. newTemplateSettings.routing.rules = JSON.parse(newValue);
  968. this.templateSettings = newTemplateSettings;
  969. },
  970. },
  971. routingRuleData: {
  972. get: function () {
  973. data = [];
  974. if (this.templateSettings != null) {
  975. this.templateSettings.routing.rules.forEach((r, index) => {
  976. data.push({'key': index, ...r});
  977. });
  978. // Make rules readable
  979. data.forEach(r => {
  980. if(r.domain) r.domain = r.domain.join(',')
  981. if(r.ip) r.ip = r.ip.join(',')
  982. if(r.source) r.source = r.source.join(',');
  983. if(r.user) r.user = r.user.join(',')
  984. if(r.inboundTag) r.inboundTag = r.inboundTag.join(',')
  985. if(r.protocol) r.protocol = r.protocol.join(',')
  986. if(r.attrs) r.attrs = JSON.stringify(r.attrs, null, 2)
  987. });
  988. }
  989. return data;
  990. }
  991. },
  992. freedomStrategy: {
  993. get: function () {
  994. if (!this.templateSettings) return "AsIs";
  995. freedomOutbound = this.templateSettings.outbounds.find((o) => o.protocol === "freedom" && o.tag == "direct");
  996. if (!freedomOutbound) return "AsIs";
  997. if (!freedomOutbound.settings || !freedomOutbound.settings.domainStrategy) return "AsIs";
  998. return freedomOutbound.settings.domainStrategy;
  999. },
  1000. set: function (newValue) {
  1001. newTemplateSettings = this.templateSettings;
  1002. freedomOutboundIndex = newTemplateSettings.outbounds.findIndex((o) => o.protocol === "freedom" && o.tag == "direct");
  1003. if(freedomOutboundIndex == -1){
  1004. newTemplateSettings.outbounds.push({protocol: "freedom", tag: "direct", settings: { "domainStrategy": newValue }});
  1005. } else if (!newTemplateSettings.outbounds[freedomOutboundIndex].settings) {
  1006. newTemplateSettings.outbounds[freedomOutboundIndex].settings = {"domainStrategy": newValue};
  1007. } else {
  1008. newTemplateSettings.outbounds[freedomOutboundIndex].settings.domainStrategy = newValue;
  1009. }
  1010. this.templateSettings = newTemplateSettings;
  1011. }
  1012. },
  1013. routingStrategy: {
  1014. get: function () {
  1015. if (!this.templateSettings || !this.templateSettings.routing || !this.templateSettings.routing.domainStrategy) return "AsIs";
  1016. return this.templateSettings.routing.domainStrategy;
  1017. },
  1018. set: function (newValue) {
  1019. newTemplateSettings = this.templateSettings;
  1020. newTemplateSettings.routing.domainStrategy = newValue;
  1021. this.templateSettings = newTemplateSettings;
  1022. }
  1023. },
  1024. blockedIPs: {
  1025. get: function () {
  1026. return this.templateRuleGetter({ outboundTag: "blocked", property: "ip" });
  1027. },
  1028. set: function (newValue) {
  1029. this.templateRuleSetter({ outboundTag: "blocked", property: "ip", data: newValue });
  1030. }
  1031. },
  1032. blockedDomains: {
  1033. get: function () {
  1034. return this.templateRuleGetter({ outboundTag: "blocked", property: "domain" });
  1035. },
  1036. set: function (newValue) {
  1037. this.templateRuleSetter({ outboundTag: "blocked", property: "domain", data: newValue });
  1038. }
  1039. },
  1040. blockedProtocols: {
  1041. get: function () {
  1042. return this.templateRuleGetter({ outboundTag: "blocked", property: "protocol" });
  1043. },
  1044. set: function (newValue) {
  1045. this.templateRuleSetter({ outboundTag: "blocked", property: "protocol", data: newValue });
  1046. }
  1047. },
  1048. directIPs: {
  1049. get: function () {
  1050. return this.templateRuleGetter({ outboundTag: "direct", property: "ip" });
  1051. },
  1052. set: function (newValue) {
  1053. this.templateRuleSetter({ outboundTag: "direct", property: "ip", data: newValue });
  1054. this.syncRulesWithOutbound("direct", this.directSettings);
  1055. }
  1056. },
  1057. directDomains: {
  1058. get: function () {
  1059. return this.templateRuleGetter({ outboundTag: "direct", property: "domain" });
  1060. },
  1061. set: function (newValue) {
  1062. this.templateRuleSetter({ outboundTag: "direct", property: "domain", data: newValue });
  1063. this.syncRulesWithOutbound("direct", this.directSettings);
  1064. }
  1065. },
  1066. ipv4Domains: {
  1067. get: function () {
  1068. return this.templateRuleGetter({ outboundTag: "IPv4", property: "domain" });
  1069. },
  1070. set: function (newValue) {
  1071. this.templateRuleSetter({ outboundTag: "IPv4", property: "domain", data: newValue });
  1072. this.syncRulesWithOutbound("IPv4", this.ipv4Settings);
  1073. }
  1074. },
  1075. warpDomains: {
  1076. get: function () {
  1077. return this.templateRuleGetter({ outboundTag: "WARP", property: "domain" });
  1078. },
  1079. set: function (newValue) {
  1080. this.templateRuleSetter({ outboundTag: "WARP", property: "domain", data: newValue });
  1081. this.syncRulesWithOutbound("WARP", this.warpSettings);
  1082. }
  1083. },
  1084. manualBlockedIPs: {
  1085. get: function () { return JSON.stringify(this.blockedIPs, null, 2); },
  1086. set: debounce(function (value) { this.blockedIPs = JSON.parse(value); }, 1000)
  1087. },
  1088. manualBlockedDomains: {
  1089. get: function () { return JSON.stringify(this.blockedDomains, null, 2); },
  1090. set: debounce(function (value) { this.blockedDomains = JSON.parse(value); }, 1000)
  1091. },
  1092. manualDirectIPs: {
  1093. get: function () { return JSON.stringify(this.directIPs, null, 2); },
  1094. set: debounce(function (value) { this.directIPs = JSON.parse(value); }, 1000)
  1095. },
  1096. manualDirectDomains: {
  1097. get: function () { return JSON.stringify(this.directDomains, null, 2); },
  1098. set: debounce(function (value) { this.directDomains = JSON.parse(value); }, 1000)
  1099. },
  1100. manualIPv4Domains: {
  1101. get: function () { return JSON.stringify(this.ipv4Domains, null, 2); },
  1102. set: debounce(function (value) { this.ipv4Domains = JSON.parse(value); }, 1000)
  1103. },
  1104. manualWARPDomains: {
  1105. get: function () { return JSON.stringify(this.warpDomains, null, 2); },
  1106. set: debounce(function (value) { this.warpDomains = JSON.parse(value); }, 1000)
  1107. },
  1108. torrentSettings: {
  1109. get: function () {
  1110. return doAllItemsExist(this.settingsData.protocols.bittorrent, this.blockedProtocols);
  1111. },
  1112. set: function (newValue) {
  1113. if (newValue) {
  1114. this.blockedProtocols = [...this.blockedProtocols, ...this.settingsData.protocols.bittorrent];
  1115. } else {
  1116. this.blockedProtocols = this.blockedProtocols.filter(data => !this.settingsData.protocols.bittorrent.includes(data));
  1117. }
  1118. },
  1119. },
  1120. privateIpSettings: {
  1121. get: function () {
  1122. return doAllItemsExist(this.settingsData.ips.local, this.blockedIPs);
  1123. },
  1124. set: function (newValue) {
  1125. if (newValue) {
  1126. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.local];
  1127. } else {
  1128. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.local.includes(data));
  1129. }
  1130. },
  1131. },
  1132. AdsSettings: {
  1133. get: function () {
  1134. return doAllItemsExist(this.settingsData.domains.ads, this.blockedDomains);
  1135. },
  1136. set: function (newValue) {
  1137. if (newValue) {
  1138. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.ads];
  1139. } else {
  1140. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.ads.includes(data));
  1141. }
  1142. },
  1143. },
  1144. SpeedTestSettings: {
  1145. get: function () {
  1146. return doAllItemsExist(this.settingsData.domains.speedtest, this.blockedDomains);
  1147. },
  1148. set: function (newValue) {
  1149. if (newValue) {
  1150. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.speedtest];
  1151. } else {
  1152. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.speedtest.includes(data));
  1153. }
  1154. },
  1155. },
  1156. familyProtectSettings: {
  1157. get: function () {
  1158. if (!this.templateSettings || !this.templateSettings.dns || !this.templateSettings.dns.servers) return false;
  1159. return doAllItemsExist(this.templateSettings.dns.servers, this.settingsData.familyProtectDNS.servers);
  1160. },
  1161. set: function (newValue) {
  1162. newTemplateSettings = this.templateSettings;
  1163. if (newValue) {
  1164. newTemplateSettings.dns = this.settingsData.familyProtectDNS;
  1165. } else {
  1166. delete newTemplateSettings.dns;
  1167. }
  1168. this.templateSettings = newTemplateSettings;
  1169. },
  1170. },
  1171. GoogleIPv4Settings: {
  1172. get: function () {
  1173. return doAllItemsExist(this.settingsData.domains.google, this.ipv4Domains);
  1174. },
  1175. set: function (newValue) {
  1176. if (newValue) {
  1177. this.ipv4Domains = [...this.ipv4Domains, ...this.settingsData.domains.google];
  1178. } else {
  1179. this.ipv4Domains = this.ipv4Domains.filter(data => !this.settingsData.domains.google.includes(data));
  1180. }
  1181. },
  1182. },
  1183. NetflixIPv4Settings: {
  1184. get: function () {
  1185. return doAllItemsExist(this.settingsData.domains.netflix, this.ipv4Domains);
  1186. },
  1187. set: function (newValue) {
  1188. if (newValue) {
  1189. this.ipv4Domains = [...this.ipv4Domains, ...this.settingsData.domains.netflix];
  1190. } else {
  1191. this.ipv4Domains = this.ipv4Domains.filter(data => !this.settingsData.domains.netflix.includes(data));
  1192. }
  1193. },
  1194. },
  1195. IRIpSettings: {
  1196. get: function () {
  1197. return doAllItemsExist(this.settingsData.ips.ir, this.blockedIPs);
  1198. },
  1199. set: function (newValue) {
  1200. if (newValue) {
  1201. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.ir];
  1202. } else {
  1203. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.ir.includes(data));
  1204. }
  1205. }
  1206. },
  1207. IRDomainSettings: {
  1208. get: function () {
  1209. return doAllItemsExist(this.settingsData.domains.ir, this.blockedDomains);
  1210. },
  1211. set: function (newValue) {
  1212. if (newValue) {
  1213. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.ir];
  1214. } else {
  1215. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.ir.includes(data));
  1216. }
  1217. }
  1218. },
  1219. ChinaIpSettings: {
  1220. get: function () {
  1221. return doAllItemsExist(this.settingsData.ips.cn, this.blockedIPs);
  1222. },
  1223. set: function (newValue) {
  1224. if (newValue) {
  1225. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.cn];
  1226. } else {
  1227. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.cn.includes(data));
  1228. }
  1229. }
  1230. },
  1231. ChinaDomainSettings: {
  1232. get: function () {
  1233. return doAllItemsExist(this.settingsData.domains.cn, this.blockedDomains);
  1234. },
  1235. set: function (newValue) {
  1236. if (newValue) {
  1237. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.cn];
  1238. } else {
  1239. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.cn.includes(data));
  1240. }
  1241. }
  1242. },
  1243. RussiaIpSettings: {
  1244. get: function () {
  1245. return doAllItemsExist(this.settingsData.ips.ru, this.blockedIPs);
  1246. },
  1247. set: function (newValue) {
  1248. if (newValue) {
  1249. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.ru];
  1250. } else {
  1251. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.ru.includes(data));
  1252. }
  1253. }
  1254. },
  1255. RussiaDomainSettings: {
  1256. get: function () {
  1257. return doAllItemsExist(this.settingsData.domains.ru, this.blockedDomains);
  1258. },
  1259. set: function (newValue) {
  1260. if (newValue) {
  1261. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.ru];
  1262. } else {
  1263. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.ru.includes(data));
  1264. }
  1265. }
  1266. },
  1267. IRIpDirectSettings: {
  1268. get: function () {
  1269. return doAllItemsExist(this.settingsData.ips.ir, this.directIPs);
  1270. },
  1271. set: function (newValue) {
  1272. if (newValue) {
  1273. this.directIPs = [...this.directIPs, ...this.settingsData.ips.ir];
  1274. } else {
  1275. this.directIPs = this.directIPs.filter(data => !this.settingsData.ips.ir.includes(data));
  1276. }
  1277. }
  1278. },
  1279. IRDomainDirectSettings: {
  1280. get: function () {
  1281. return doAllItemsExist(this.settingsData.domains.ir, this.directDomains);
  1282. },
  1283. set: function (newValue) {
  1284. if (newValue) {
  1285. this.directDomains = [...this.directDomains, ...this.settingsData.domains.ir];
  1286. } else {
  1287. this.directDomains = this.directDomains.filter(data => !this.settingsData.domains.ir.includes(data));
  1288. }
  1289. }
  1290. },
  1291. ChinaIpDirectSettings: {
  1292. get: function () {
  1293. return doAllItemsExist(this.settingsData.ips.cn, this.directIPs);
  1294. },
  1295. set: function (newValue) {
  1296. if (newValue) {
  1297. this.directIPs = [...this.directIPs, ...this.settingsData.ips.cn];
  1298. } else {
  1299. this.directIPs = this.directIPs.filter(data => !this.settingsData.ips.cn.includes(data));
  1300. }
  1301. }
  1302. },
  1303. ChinaDomainDirectSettings: {
  1304. get: function () {
  1305. return doAllItemsExist(this.settingsData.domains.cn, this.directDomains);
  1306. },
  1307. set: function (newValue) {
  1308. if (newValue) {
  1309. this.directDomains = [...this.directDomains, ...this.settingsData.domains.cn];
  1310. } else {
  1311. this.directDomains = this.directDomains.filter(data => !this.settingsData.domains.cn.includes(data));
  1312. }
  1313. }
  1314. },
  1315. RussiaIpDirectSettings: {
  1316. get: function () {
  1317. return doAllItemsExist(this.settingsData.ips.ru, this.directIPs);
  1318. },
  1319. set: function (newValue) {
  1320. if (newValue) {
  1321. this.directIPs = [...this.directIPs, ...this.settingsData.ips.ru];
  1322. } else {
  1323. this.directIPs = this.directIPs.filter(data => !this.settingsData.ips.ru.includes(data));
  1324. }
  1325. }
  1326. },
  1327. RussiaDomainDirectSettings: {
  1328. get: function () {
  1329. return doAllItemsExist(this.settingsData.domains.ru, this.directDomains);
  1330. },
  1331. set: function (newValue) {
  1332. if (newValue) {
  1333. this.directDomains = [...this.directDomains, ...this.settingsData.domains.ru];
  1334. } else {
  1335. this.directDomains = this.directDomains.filter(data => !this.settingsData.domains.ru.includes(data));
  1336. }
  1337. }
  1338. },
  1339. GoogleWARPSettings: {
  1340. get: function () {
  1341. return doAllItemsExist(this.settingsData.domains.google, this.warpDomains);
  1342. },
  1343. set: function (newValue) {
  1344. if (newValue) {
  1345. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.google];
  1346. } else {
  1347. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.google.includes(data));
  1348. }
  1349. },
  1350. },
  1351. OpenAIWARPSettings: {
  1352. get: function () {
  1353. return doAllItemsExist(this.settingsData.domains.openai, this.warpDomains);
  1354. },
  1355. set: function (newValue) {
  1356. if (newValue) {
  1357. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.openai];
  1358. } else {
  1359. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.openai.includes(data));
  1360. }
  1361. },
  1362. },
  1363. NetflixWARPSettings: {
  1364. get: function () {
  1365. return doAllItemsExist(this.settingsData.domains.netflix, this.warpDomains);
  1366. },
  1367. set: function (newValue) {
  1368. if (newValue) {
  1369. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.netflix];
  1370. } else {
  1371. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.netflix.includes(data));
  1372. }
  1373. },
  1374. },
  1375. SpotifyWARPSettings: {
  1376. get: function () {
  1377. return doAllItemsExist(this.settingsData.domains.spotify, this.warpDomains);
  1378. },
  1379. set: function (newValue) {
  1380. if (newValue) {
  1381. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.spotify];
  1382. } else {
  1383. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.spotify.includes(data));
  1384. }
  1385. },
  1386. },
  1387. },
  1388. });
  1389. </script>
  1390. </body>
  1391. </html>