xray.html 111 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. {{template "head" .}}
  4. <link rel="stylesheet" href="{{ .base_path }}assets/codemirror/codemirror.min.css?{{ .cur_ver }}">
  5. <link rel="stylesheet" href="{{ .base_path }}assets/codemirror/fold/foldgutter.css">
  6. <link rel="stylesheet" href="{{ .base_path }}assets/codemirror/xq.min.css?{{ .cur_ver }}">
  7. <link rel="stylesheet" href="{{ .base_path }}assets/codemirror/lint/lint.css">
  8. <script src="{{ .base_path }}assets/base64/base64.min.js"></script>
  9. <script src="{{ .base_path }}assets/js/model/outbound.js?{{ .cur_ver }}"></script>
  10. <script src="{{ .base_path }}assets/codemirror/codemirror.min.js?{{ .cur_ver }}"></script>
  11. <script src="{{ .base_path }}assets/codemirror/javascript.js"></script>
  12. <script src="{{ .base_path }}assets/codemirror/jshint.js"></script>
  13. <script src="{{ .base_path }}assets/codemirror/jsonlint.js"></script>
  14. <script src="{{ .base_path }}assets/codemirror/lint/lint.js"></script>
  15. <script src="{{ .base_path }}assets/codemirror/lint/javascript-lint.js"></script>
  16. <script src="{{ .base_path }}assets/codemirror/hint/javascript-hint.js"></script>
  17. <script src="{{ .base_path }}assets/codemirror/fold/foldcode.js"></script>
  18. <script src="{{ .base_path }}assets/codemirror/fold/foldgutter.js"></script>
  19. <script src="{{ .base_path }}assets/codemirror/fold/brace-fold.js"></script>
  20. <style>
  21. @media (min-width: 769px) {
  22. .ant-layout-content {
  23. margin: 24px 16px;
  24. }
  25. }
  26. @media (max-width: 768px) {
  27. .ant-tabs-nav .ant-tabs-tab {
  28. margin: 0;
  29. padding: 12px .5rem;
  30. }
  31. .ant-table-thead>tr>th,
  32. .ant-table-tbody>tr>td {
  33. padding: 10px 0px;
  34. }
  35. }
  36. .ant-tabs-bar {
  37. margin: 0;
  38. }
  39. .ant-list-item {
  40. display: block;
  41. }
  42. .collapse-title {
  43. color: inherit;
  44. font-weight: bold;
  45. font-size: 18px;
  46. padding: 10px 20px;
  47. border-bottom: 2px solid;
  48. }
  49. .collapse-title>i {
  50. color: inherit;
  51. font-size: 24px;
  52. }
  53. .ant-collapse-content-box>li {
  54. padding: 12px 0 0 !important;
  55. }
  56. .ant-list-item>li {
  57. padding: 10px 20px !important;
  58. }
  59. </style>
  60. <body>
  61. <a-layout id="app" v-cloak :class="themeSwitcher.currentTheme">
  62. {{ template "commonSider" . }}
  63. <a-layout id="content-layout">
  64. <a-layout-content>
  65. <a-spin :spinning="spinning" :delay="500" tip='{{ i18n "loading"}}'>
  66. <transition name="list" appear>
  67. <a-alert type="error" v-if="showAlert" style="margin-bottom: 10px"
  68. message='{{ i18n "secAlertTitle" }}'
  69. color="red"
  70. description='{{ i18n "secAlertSsl" }}'
  71. show-icon closable>
  72. </a-alert>
  73. </transition>
  74. <a-space direction="vertical">
  75. <a-card hoverable style="margin-bottom: .5rem;">
  76. <a-row style="display: flex; flex-wrap: wrap; align-items: center;">
  77. <a-col :xs="24" :sm="10" style="padding: 4px;">
  78. <a-space direction="horizontal">
  79. <a-button type="primary" :disabled="saveBtnDisable" @click="updateXraySetting">{{ i18n "pages.xray.save" }}</a-button>
  80. <a-button type="danger" :disabled="!saveBtnDisable" @click="restartXray">{{ i18n "pages.xray.restart" }}</a-button>
  81. <a-popover v-if="restartResult"
  82. :overlay-class-name="themeSwitcher.currentTheme">
  83. <span slot="title" style="font-size: 12pt">Error in running xray-core</span>
  84. <template slot="content">
  85. <p style="max-width: 400px" v-for="line in restartResult.split('\n')">[[ line ]]</p>
  86. </template>
  87. <a-icon type="question-circle"></a-icon>
  88. </a-popover>
  89. </a-space>
  90. </a-col>
  91. <a-col :xs="24" :sm="14">
  92. <template>
  93. <div>
  94. <a-back-top :target="() => document.getElementById('content-layout')" visibility-height="200"></a-back-top>
  95. <a-alert type="warning" style="float: right; width: fit-content" message='{{ i18n "pages.settings.infoDesc" }}' show-icon>
  96. </a-alert>
  97. </div>
  98. </template>
  99. </a-col>
  100. </a-row>
  101. </a-card>
  102. <a-tabs class="ant-card-dark-box-nohover" default-active-key="1"
  103. @change="(activeKey) => { this.changePage(activeKey); }"
  104. :class="themeSwitcher.currentTheme">
  105. <a-tab-pane key="tpl-basic" tab='{{ i18n "pages.xray.basicTemplate"}}' style="padding-top: 20px;">
  106. <a-collapse>
  107. <a-collapse-panel header='{{ i18n "pages.xray.generalConfigs"}}'>
  108. <a-row :xs="24" :sm="24" :lg="12">
  109. <a-alert type="warning" style="text-align: center;">
  110. <template slot="message">
  111. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  112. {{ i18n "pages.xray.generalConfigsDesc" }}
  113. </template>
  114. </a-alert>
  115. </a-row>
  116. <a-list-item>
  117. <a-row style="padding: 10px 20px">
  118. <a-col :lg="24" :xl="12">
  119. <a-list-item-meta title='{{ i18n "pages.xray.FreedomStrategy" }}'
  120. description='{{ i18n "pages.xray.FreedomStrategyDesc" }}'>
  121. </a-list-item-meta>
  122. </a-col>
  123. <a-col :lg="24" :xl="12">
  124. <template>
  125. <a-select v-model="freedomStrategy" :dropdown-class-name="themeSwitcher.currentTheme"
  126. style="width: 100%">
  127. <a-select-option v-for="s in OutboundDomainStrategies" :value="s">[[ s ]]</a-select-option>
  128. </a-select>
  129. </template>
  130. </a-col>
  131. </a-row>
  132. <a-row style="padding: 10px 20px">
  133. <a-col :lg="24" :xl="12">
  134. <a-list-item-meta title='{{ i18n "pages.xray.RoutingStrategy" }}'
  135. description='{{ i18n "pages.xray.RoutingStrategyDesc" }}'>
  136. </a-list-item-meta>
  137. </a-col>
  138. <a-col :lg="24" :xl="12">
  139. <a-select v-model="routingStrategy" :dropdown-class-name="themeSwitcher.currentTheme"
  140. style="width: 100%">
  141. <a-select-option v-for="s in routingDomainStrategies" :value="s">[[ s ]]</a-select-option>
  142. </a-select>
  143. </a-col>
  144. </a-row>
  145. <setting-list-item type="switch" title='{{ i18n "pages.xray.outboundTraffic"}}' desc='{{ i18n "pages.xray.outboundTrafficDesc"}}' v-model="outboundTraffic"></setting-list-item>
  146. </a-list-item>
  147. </a-collapse-panel>
  148. <a-collapse-panel header='{{ i18n "pages.xray.logConfigs" }}'>
  149. <a-row :xs="24" :sm="24" :lg="12">
  150. <a-alert type="warning" style="text-align: center;">
  151. <template slot="message">
  152. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  153. {{ i18n "pages.xray.logConfigsDesc" }}
  154. </template>
  155. </a-alert>
  156. </a-row>
  157. <a-list-item>
  158. <a-row style="padding: 10px 20px">
  159. <a-col :lg="24" :xl="12">
  160. <a-list-item-meta title='{{ i18n "pages.xray.logLevel" }}'
  161. description='{{ i18n "pages.xray.logLevelDesc" }}'>
  162. </a-list-item-meta>
  163. </a-col>
  164. <a-col :lg="24" :xl="12">
  165. <template>
  166. <a-select v-model="logLevel" :dropdown-class-name="themeSwitcher.currentTheme" style="width: 100%">
  167. <a-select-option v-for="s in log.loglevel" :value="s">[[ s ]]</a-select-option>
  168. </a-select>
  169. </template>
  170. </a-col>
  171. </a-row>
  172. <a-row style="padding: 10px 20px">
  173. <a-col :lg="24" :xl="12">
  174. <a-list-item-meta title='{{ i18n "pages.xray.accessLog" }}'
  175. description='{{ i18n "pages.xray.accessLogDesc" }}'>
  176. </a-list-item-meta>
  177. </a-col>
  178. <a-col :lg="24" :xl="12">
  179. <template>
  180. <a-select v-model="accessLog" :dropdown-class-name="themeSwitcher.currentTheme" style="width: 100%">
  181. <a-select-option value=''>Empty</a-select-option>
  182. <a-select-option v-for="s in log.access" :value="s">[[ s ]]</a-select-option>
  183. </a-select>
  184. </template>
  185. </a-col>
  186. </a-row>
  187. <a-row style="padding: 10px 20px">
  188. <a-col :lg="24" :xl="12">
  189. <a-list-item-meta title='{{ i18n "pages.xray.errorLog" }}'
  190. description='{{ i18n "pages.xray.errorLogDesc" }}'>
  191. </a-list-item-meta>
  192. </a-col>
  193. <a-col :lg="24" :xl="12">
  194. <template>
  195. <a-select v-model="errorLog" :dropdown-class-name="themeSwitcher.currentTheme" style="width: 100%">
  196. <a-select-option value=''>Empty</a-select-option>
  197. <a-select-option v-for="s in log.error" :value="s">[[ s ]]</a-select-option>
  198. </a-select>
  199. </template>
  200. </a-col>
  201. </a-row>
  202. <a-row style="padding: 10px 20px">
  203. <a-col :lg="24" :xl="12">
  204. <a-list-item-meta title='{{ i18n "pages.xray.maskAddress" }}'
  205. description='{{ i18n "pages.xray.maskAddressDesc" }}'>
  206. </a-list-item-meta>
  207. </a-col>
  208. <a-col :lg="24" :xl="12">
  209. <template>
  210. <a-select v-model="maskAddressLog" :dropdown-class-name="themeSwitcher.currentTheme" style="width: 100%">
  211. <a-select-option value=''>Empty</a-select-option>
  212. <a-select-option v-for="s in log.maskAddress" :value="s">[[ s ]]</a-select-option>
  213. </a-select>
  214. </template>
  215. </a-col>
  216. </a-row>
  217. <setting-list-item type="switch" title='{{ i18n "pages.xray.dnsLog"}}' desc='{{ i18n "pages.xray.dnsLogDesc"}}' v-model="dnslog"></setting-list-item>
  218. </a-list-item>
  219. </a-collapse-panel>
  220. <a-collapse-panel header='{{ i18n "pages.xray.blockConfigs"}}'>
  221. <a-row :xs="24" :sm="24" :lg="12">
  222. <a-alert type="warning" style="text-align: center;">
  223. <template slot="message">
  224. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  225. {{ i18n "pages.xray.blockConfigsDesc" }}
  226. </template>
  227. </a-alert>
  228. </a-row>
  229. <a-list-item>
  230. <setting-list-item type="switch" title='{{ i18n "pages.xray.Torrent"}}' desc='{{ i18n "pages.xray.TorrentDesc"}}' v-model="torrentSettings"></setting-list-item>
  231. <setting-list-item type="switch" title='{{ i18n "pages.xray.Family"}}' desc='{{ i18n "pages.xray.FamilyDesc"}}' v-model="familyProtectSettings"></setting-list-item>
  232. </a-list-item>
  233. </a-collapse-panel>
  234. <a-collapse-panel header='{{ i18n "pages.xray.basicRouting"}}'>
  235. <a-row :xs="24" :sm="24" :lg="12">
  236. <a-alert type="warning" style="text-align: center;">
  237. <template slot="message">
  238. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  239. {{ i18n "pages.xray.blockConnectionsConfigsDesc" }}
  240. </template>
  241. </a-alert>
  242. </a-row>
  243. <a-list-item>
  244. <a-row style="padding: 0 20px">
  245. <a-col :lg="24" :xl="12">
  246. <a-list-item-meta
  247. title='{{ i18n "pages.xray.blockips" }}'/>
  248. </a-col>
  249. <a-col :lg="24" :xl="12">
  250. <template>
  251. <a-select mode="tags" v-model="blockedIPs" style="width: 100%"
  252. :dropdown-class-name="themeSwitcher.currentTheme">
  253. <a-select-option :value="p.value" :label="p.label"
  254. v-for="p in settingsData.IPsOptions"> [[ p.label ]]
  255. </a-select-option>
  256. </a-select>
  257. </template>
  258. </a-col>
  259. </a-row>
  260. </a-list-item>
  261. <a-list-item>
  262. <a-row style="padding: 0 20px">
  263. <a-col :lg="24" :xl="12">
  264. <a-list-item-meta
  265. title='{{ i18n "pages.xray.blockdomains" }}'/>
  266. </a-col>
  267. <a-col :lg="24" :xl="12">
  268. <template>
  269. <a-select mode="tags" style="width: 100%"
  270. v-model="blockedDomains"
  271. :dropdown-class-name="themeSwitcher.currentTheme">
  272. <a-select-option :value="p.value" :label="p.label"
  273. v-for="p in settingsData.BlockDomainsOptions"> [[ p.label ]]
  274. </a-select-option>
  275. </a-select>
  276. </template>
  277. </a-col>
  278. </a-row>
  279. </a-list-item>
  280. <a-row :xs="24" :sm="24" :lg="12">
  281. <a-alert type="warning" style="text-align: center; margin-top: 20px;">
  282. <template slot="message">
  283. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  284. {{ i18n "pages.xray.directConnectionsConfigsDesc" }}
  285. </template>
  286. </a-alert>
  287. </a-row>
  288. <a-list-item>
  289. <a-row style="padding: 0 20px">
  290. <a-col :lg="24" :xl="12">
  291. <a-list-item-meta
  292. title='{{ i18n "pages.xray.directips" }}'/>
  293. </a-col>
  294. <a-col :lg="24" :xl="12">
  295. <template>
  296. <a-select mode="tags" style="width: 100%"
  297. v-model="directIPs"
  298. :dropdown-class-name="themeSwitcher.currentTheme">
  299. <a-select-option :value="p.value" :label="p.label"
  300. v-for="p in settingsData.IPsOptions"> [[ p.label ]]
  301. </a-select-option>
  302. </a-select>
  303. </template>
  304. </a-col>
  305. </a-row>
  306. </a-list-item>
  307. <a-list-item>
  308. <a-row style="padding: 0 20px">
  309. <a-col :lg="24" :xl="12">
  310. <a-list-item-meta
  311. title='{{ i18n "pages.xray.directdomains" }}'/>
  312. </a-col>
  313. <a-col :lg="24" :xl="12">
  314. <template>
  315. <a-select mode="tags" style="width: 100%"
  316. v-model="directDomains"
  317. :dropdown-class-name="themeSwitcher.currentTheme">
  318. <a-select-option :value="p.value" :label="p.label"
  319. v-for="p in settingsData.DomainsOptions"> [[ p.label ]]
  320. </a-select-option>
  321. </a-select>
  322. </template>
  323. </a-col>
  324. </a-row>
  325. </a-list-item>
  326. <a-row :xs="24" :sm="24" :lg="12">
  327. <a-alert type="warning" style="text-align: center; margin-top: 20px;">
  328. <template slot="message">
  329. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  330. {{ i18n "pages.xray.ipv4RoutingDesc" }}
  331. </template>
  332. </a-alert>
  333. </a-row>
  334. <a-list-item>
  335. <a-row style="padding: 0 20px">
  336. <a-col :lg="24" :xl="12">
  337. <a-list-item-meta
  338. title='{{ i18n "pages.xray.ipv4Routing" }}'/>
  339. </a-col>
  340. <a-col :lg="24" :xl="12">
  341. <template>
  342. <a-select mode="tags" style="width: 100%"
  343. v-model="ipv4Domains"
  344. :dropdown-class-name="themeSwitcher.currentTheme">
  345. <a-select-option :value="p.value" :label="p.label"
  346. v-for="p in settingsData.ServicesOptions"> [[ p.label ]]
  347. </a-select-option>
  348. </a-select>
  349. </template>
  350. </a-col>
  351. </a-row>
  352. </a-list-item>
  353. <a-row :xs="24" :sm="24" :lg="12">
  354. <a-alert type="warning" style="text-align: center; margin-top: 20px;">
  355. <template slot="message">
  356. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  357. {{ i18n "pages.xray.warpRoutingDesc" }}
  358. </template>
  359. </a-alert>
  360. </a-row>
  361. <a-list-item>
  362. <template v-if="WarpExist">
  363. <a-list-item>
  364. <a-row style="padding: 0 20px">
  365. <a-col :lg="24" :xl="12">
  366. <a-list-item-meta
  367. title='{{ i18n "pages.xray.warpRouting" }}'/>
  368. </a-col>
  369. <a-col :lg="24" :xl="12">
  370. <template>
  371. <a-select mode="tags" style="width: 100%"
  372. v-model="warpDomains"
  373. :dropdown-class-name="themeSwitcher.currentTheme">
  374. <a-select-option :value="p.value" :label="p.label"
  375. v-for="p in settingsData.ServicesOptions"> [[ p.label ]]
  376. </a-select-option>
  377. </a-select>
  378. </template>
  379. </a-col>
  380. </a-row>
  381. </a-list-item>
  382. </template>
  383. <a-button style="margin-left: 20px;" v-else type="primary" icon="cloud" @click="showWarp()">WARP</a-button>
  384. </a-list-item>
  385. </a-collapse-panel>
  386. <a-collapse-panel header='{{ i18n "pages.settings.resetDefaultConfig"}}'>
  387. <a-space direction="horizontal" style="padding: 0 20px">
  388. <a-button type="danger" @click="resetXrayConfigToDefault">{{ i18n "pages.settings.resetDefaultConfig" }}</a-button>
  389. </a-space>
  390. </a-collapse-panel>
  391. </a-collapse>
  392. </a-tab-pane>
  393. <a-tab-pane key="tpl-routing" tab='{{ i18n "pages.xray.Routings"}}' style="padding-top: 20px;">
  394. <a-button type="primary" icon="plus" @click="addRule">{{ i18n "pages.xray.rules.add" }}</a-button>
  395. <a-table-sortable :columns="isMobile ? rulesMobileColumns : rulesColumns" bordered
  396. :row-key="r => r.key"
  397. :data-source="routingRuleData"
  398. :scroll="isMobile ? {} : { x: 1000 }"
  399. :pagination="false"
  400. :indent-size="0"
  401. :style="isMobile ? 'padding: 5px 0' : 'margin-top: 10px;'"
  402. v-on:onSort="replaceRule">
  403. <template slot="action" slot-scope="text, rule, index">
  404. <table-sort-trigger :item-index="index"></table-sort-trigger>
  405. <span class="ant-table-row-index"> [[ index+1 ]] </span>
  406. <a-dropdown :trigger="['click']">
  407. <a-icon @click="e => e.preventDefault()" type="more" style="font-size: 16px; text-decoration: bold;"></a-icon>
  408. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  409. <a-menu-item v-if="index>0" @click="replaceRule(index,0)">
  410. <a-icon type="vertical-align-top"></a-icon>
  411. {{ i18n "pages.xray.rules.first"}}
  412. </a-menu-item>
  413. <a-menu-item v-if="index>0" @click="replaceRule(index,index-1)">
  414. <a-icon type="arrow-up"></a-icon>
  415. {{ i18n "pages.xray.rules.up"}}
  416. </a-menu-item>
  417. <a-menu-item v-if="index<routingRuleData.length-1" @click="replaceRule(index,index+1)">
  418. <a-icon type="arrow-down"></a-icon>
  419. {{ i18n "pages.xray.rules.down"}}
  420. </a-menu-item>
  421. <a-menu-item v-if="index<routingRuleData.length-1" @click="replaceRule(index,routingRuleData.length-1)">
  422. <a-icon type="vertical-align-bottom"></a-icon>
  423. {{ i18n "pages.xray.rules.last"}}
  424. </a-menu-item>
  425. <a-menu-item @click="editRule(index)">
  426. <a-icon type="edit"></a-icon>
  427. {{ i18n "edit" }}
  428. </a-menu-item>
  429. <a-menu-item @click="deleteRule(index)">
  430. <span style="color: #FF4D4F">
  431. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  432. </span>
  433. </a-menu-item>
  434. </a-menu>
  435. </a-dropdown>
  436. </template>
  437. <template slot="inbound" slot-scope="text, rule, index">
  438. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  439. <template slot="content">
  440. <p v-if="rule.inboundTag">Inbound Tag: [[ rule.inboundTag ]]</p>
  441. <p v-if="rule.user">User email: [[ rule.user ]]</p>
  442. </template>
  443. [[ [rule.inboundTag,rule.user].join('\n') ]]
  444. </a-popover>
  445. </template>
  446. <template slot="outbound" slot-scope="text, rule, index">
  447. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  448. <template slot="content">
  449. <p v-if="rule.outboundTag">Outbound Tag: [[ rule.outboundTag ]]</p>
  450. </template>
  451. [[ rule.outboundTag ]]
  452. </a-popover>
  453. </template>
  454. <template slot="balancer" slot-scope="text, rule, index">
  455. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  456. <template slot="content">
  457. <p v-if="rule.balancerTag">Balancer Tag: [[ rule.balancerTag ]]</p>
  458. </template>
  459. [[ rule.balancerTag ]]
  460. </a-popover>
  461. </template>
  462. <template slot="info" slot-scope="text, rule, index">
  463. <a-popover placement="bottomRight"
  464. v-if="(rule.source+rule.sourcePort+rule.network+rule.protocol+rule.attrs+rule.ip+rule.domain+rule.port).length>0"
  465. :overlay-class-name="themeSwitcher.currentTheme" trigger="click">
  466. <template slot="content">
  467. <table cellpadding="2" style="max-width: 300px;">
  468. <tr v-if="rule.source">
  469. <td>Source</td>
  470. <td><a-tag color="blue" v-for="r in rule.source.split(',')">[[ r ]]</a-tag></td>
  471. </tr>
  472. <tr v-if="rule.sourcePort">
  473. <td>Source Port</td>
  474. <td><a-tag color="green" v-for="r in rule.sourcePort.split(',')">[[ r ]]</a-tag></td>
  475. </tr>
  476. <tr v-if="rule.network">
  477. <td>Network</td>
  478. <td><a-tag color="blue" v-for="r in rule.network.split(',')">[[ r ]]</a-tag></td>
  479. </tr>
  480. <tr v-if="rule.protocol">
  481. <td>Protocol</td>
  482. <td><a-tag color="green" v-for="r in rule.protocol.split(',')">[[ r ]]</a-tag></td>
  483. </tr>
  484. <tr v-if="rule.attrs">
  485. <td>Attrs</td>
  486. <td><a-tag color="blue" v-for="r in rule.attrs.split(',')">[[ r ]]</a-tag></td>
  487. </tr>
  488. <tr v-if="rule.ip">
  489. <td>IP</td>
  490. <td><a-tag color="green" v-for="r in rule.ip.split(',')">[[ r ]]</a-tag></td>
  491. </tr>
  492. <tr v-if="rule.domain">
  493. <td>Domain</td>
  494. <td><a-tag color="blue" v-for="r in rule.domain.split(',')">[[ r ]]</a-tag></td>
  495. </tr>
  496. <tr v-if="rule.port">
  497. <td>Port</td>
  498. <td><a-tag color="green" v-for="r in rule.port.split(',')">[[ r ]]</a-tag></td>
  499. </tr>
  500. <tr v-if="rule.balancerTag">
  501. <td>Balancer Tag</td>
  502. <td><a-tag color="blue">[[ rule.balancerTag ]]</a-tag></td>
  503. </tr>
  504. </table>
  505. </template>
  506. <a-button shape="round" size="small" style="font-size: 14px; padding: 0 10px;">
  507. <a-icon type="info"></a-icon>
  508. </a-button>
  509. </a-popover>
  510. </template>
  511. </a-table-sortable>
  512. </a-tab-pane>
  513. <a-tab-pane key="tpl-outbound" tab='{{ i18n "pages.xray.Outbounds"}}' style="padding-top: 20px;" force-render="true">
  514. <a-row>
  515. <a-col :xs="12" :sm="12" :lg="12">
  516. <a-button type="primary" icon="plus" @click="addOutbound()" style="margin-bottom: 10px;">
  517. {{ i18n "pages.xray.outbound.addOutbound" }}
  518. </a-button>
  519. <a-button type="primary" icon="cloud" @click="showWarp()" style="margin-bottom: 10px;">WARP</a-button>
  520. </a-col>
  521. <a-col :xs="12" :sm="12" :lg="12" style="text-align: right;">
  522. <a-icon type="sync" :spin="refreshing" @click="refreshOutboundTraffic()" style="margin: 0 5px;"></a-icon>
  523. <a-popconfirm placement="topRight" @confirm="resetOutboundTraffic(-1)"
  524. title='{{ i18n "pages.inbounds.resetTrafficContent"}}'
  525. :overlay-class-name="themeSwitcher.currentTheme"
  526. ok-text='{{ i18n "reset"}}'
  527. cancel-text='{{ i18n "cancel"}}'>
  528. <a-icon slot="icon" type="question-circle-o" :style="themeSwitcher.isDarkTheme ? 'color: #008771' : 'color: #008771'"></a-icon>
  529. <a-icon type="retweet" style="cursor: pointer;"></a-icon>
  530. </a-popconfirm>
  531. </a-col>
  532. </a-row>
  533. <a-table :columns="outboundColumns" bordered
  534. :row-key="r => r.key"
  535. :data-source="outboundData"
  536. :scroll="isMobile ? {} : { x: 800 }"
  537. :pagination="false"
  538. :indent-size="0"
  539. :style="isMobile ? 'padding: 5px 5px' : 'margin-right: 1px;'">
  540. <template slot="action" slot-scope="text, outbound, index">
  541. [[ index+1 ]]
  542. <a-dropdown :trigger="['click']">
  543. <a-icon @click="e => e.preventDefault()" type="more" style="font-size: 16px; text-decoration: bold;"></a-icon>
  544. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  545. <a-menu-item v-if="index>0" @click="setFirstOutbound(index)">
  546. <a-icon type="vertical-align-top"></a-icon>
  547. {{ i18n "pages.xray.rules.first"}}
  548. </a-menu-item>
  549. <a-menu-item @click="editOutbound(index)">
  550. <a-icon type="edit"></a-icon>
  551. {{ i18n "edit" }}
  552. </a-menu-item>
  553. <a-menu-item @click="resetOutboundTraffic(index)">
  554. <span>
  555. <a-icon type="retweet"></a-icon> {{ i18n "pages.inbounds.resetTraffic"}}
  556. </span>
  557. </a-menu-item>
  558. <a-menu-item @click="deleteOutbound(index)">
  559. <span style="color: #FF4D4F">
  560. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  561. </span>
  562. </a-menu-item>
  563. </a-menu>
  564. </a-dropdown>
  565. </template>
  566. <template slot="address" slot-scope="text, outbound, index">
  567. <p style="margin: 0 5px;" v-for="addr in findOutboundAddress(outbound)">[[ addr ]]</p>
  568. </template>
  569. <template slot="protocol" slot-scope="text, outbound, index">
  570. <a-tag style="margin:0;" color="purple">[[ outbound.protocol ]]</a-tag>
  571. <template v-if="[Protocols.VMess, Protocols.VLESS, Protocols.Trojan, Protocols.Shadowsocks].includes(outbound.protocol)">
  572. <a-tag style="margin:0;" color="blue">[[ outbound.streamSettings.network ]]</a-tag>
  573. <a-tag style="margin:0;" v-if="outbound.streamSettings.security=='tls'" color="green">tls</a-tag>
  574. <a-tag style="margin:0;" v-if="outbound.streamSettings.security=='reality'" color="green">reality</a-tag>
  575. </template>
  576. </template>
  577. <template slot="traffic" slot-scope="text, outbound, index">
  578. <a-tag color="green">[[ findOutboundTraffic(outbound) ]]</a-tag>
  579. </template>
  580. </a-table>
  581. </a-tab-pane>
  582. <a-tab-pane key="tpl-reverse" tab='{{ i18n "pages.xray.outbound.reverse"}}' style="padding-top: 20px;" force-render="true">
  583. <a-button type="primary" icon="plus" @click="addReverse()" style="margin-bottom: 10px;">
  584. {{ i18n "pages.xray.outbound.addReverse" }}
  585. </a-button>
  586. <a-table :columns="reverseColumns" bordered v-if="reverseData.length>0"
  587. :row-key="r => r.key"
  588. :data-source="reverseData"
  589. :scroll="isMobile ? {} : { x: 200 }"
  590. :pagination="false"
  591. :indent-size="0"
  592. :style="isMobile ? 'padding: 5px 0' : 'margin-left: 1px;'">
  593. <template slot="action" slot-scope="text, reverse, index">
  594. [[ index+1 ]]
  595. <a-dropdown :trigger="['click']">
  596. <a-icon @click="e => e.preventDefault()" type="more" style="font-size: 16px; text-decoration: bold;"></a-icon>
  597. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  598. <a-menu-item @click="editReverse(index)">
  599. <a-icon type="edit"></a-icon>
  600. {{ i18n "edit" }}
  601. </a-menu-item>
  602. <a-menu-item @click="deleteReverse(index)">
  603. <span style="color: #FF4D4F">
  604. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  605. </span>
  606. </a-menu-item>
  607. </a-menu>
  608. </a-dropdown>
  609. </template>
  610. </a-table>
  611. </a-tab-pane>
  612. <a-tab-pane key="tpl-balancer" tab='{{ i18n "pages.xray.Balancers"}}' style="padding-top: 20px;" force-render="true">
  613. <a-button type="primary" icon="plus" @click="addBalancer()" style="margin-bottom: 10px;">
  614. {{ i18n "pages.xray.balancer.addBalancer"}}
  615. </a-button>
  616. <a-table :columns="balancerColumns" bordered v-if="balancersData.length>0"
  617. :row-key="r => r.key"
  618. :data-source="balancersData"
  619. :scroll="isMobile ? {} : { x: 200 }"
  620. :pagination="false"
  621. :indent-size="0"
  622. :style="isMobile ? 'padding: 5px 0' : 'margin-left: 1px;'">
  623. <template slot="action" slot-scope="text, balancer, index">
  624. [[ index+1 ]]
  625. <a-dropdown :trigger="['click']">
  626. <a-icon @click="e => e.preventDefault()" type="more" style="font-size: 16px; text-decoration: bold;"></a-icon>
  627. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  628. <a-menu-item @click="editBalancer(index)">
  629. <a-icon type="edit"></a-icon>
  630. {{ i18n "edit" }}
  631. </a-menu-item>
  632. <a-menu-item @click="deleteBalancer(index)">
  633. <span style="color: #FF4D4F">
  634. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  635. </span>
  636. </a-menu-item>
  637. </a-menu>
  638. </a-dropdown>
  639. </template>
  640. <template slot="strategy" slot-scope="text, balancer, index">
  641. <a-tag style="margin:0;" v-if="balancer.strategy=='random'" color="purple">Random</a-tag>
  642. <a-tag style="margin:0;" v-if="balancer.strategy=='roundRobin'" color="green">Round Robin</a-tag>
  643. <a-tag style="margin:0;" v-if="balancer.strategy=='leastLoad'" color="green">Least Load</a-tag>
  644. <a-tag style="margin:0;" v-if="balancer.strategy=='leastPing'" color="green">Least Ping</a-tag>
  645. </template>
  646. <template slot="selector" slot-scope="text, balancer, index">
  647. <a-tag class="info-large-tag" style="margin:1;" v-for="sel in balancer.selector">[[ sel ]]</a-tag>
  648. </template>
  649. </a-table>
  650. <a-radio-group
  651. v-if="observatoryEnable || burstObservatoryEnable"
  652. v-model="obsSettings"
  653. @change="changeObsCode"
  654. button-style="solid"
  655. style="margin: 10px 0;"
  656. :size="isMobile ? 'small' : ''">
  657. <a-radio-button value="observatory" v-if="observatoryEnable">Observatory</a-radio-button>
  658. <a-radio-button value="burstObservatory" v-if="burstObservatoryEnable">Burst Observatory</a-radio-button>
  659. </a-radio-group>
  660. <textarea style="position:absolute; left: -800px;" id="obsSetting"></textarea>
  661. </a-tab-pane>
  662. <a-tab-pane key="tpl-dns" tab='DNS' style="padding-top: 20px;" force-render="true">
  663. <a-collapse>
  664. <a-collapse-panel header='{{ i18n "pages.xray.generalConfigs"}}'>
  665. <a-list-item>
  666. <a-row style="padding: 10px 20px; padding-top: 0;">
  667. <a-col :lg="24" :xl="12">
  668. <a-list-item-meta title='{{ i18n "pages.xray.dns.enable" }}'
  669. description='{{ i18n "pages.xray.dns.enableDesc" }}' />
  670. </a-col>
  671. <a-col :lg="24" :xl="12">
  672. <a-switch v-model="enableDNS"></a-switch>
  673. </a-col>
  674. </a-row>
  675. <template v-if="enableDNS">
  676. <a-row style="padding: 10px 20px;">
  677. <a-col :lg="24" :xl="12">
  678. <a-list-item-meta title='{{ i18n "pages.xray.dns.tag" }}'
  679. description='{{ i18n "pages.xray.dns.tagDesc" }}' />
  680. </a-col>
  681. <a-col :lg="24" :xl="12">
  682. <a-input type="text" v-model="dnsTag"></a-input>
  683. </a-col>
  684. </a-row>
  685. <a-row style="padding: 10px 20px;">
  686. <a-col :lg="24" :xl="12">
  687. <a-list-item-meta title='{{ i18n "pages.xray.dns.clientIp" }}'
  688. description='{{ i18n "pages.xray.dns.clientIpDesc" }}'/>
  689. </a-col>
  690. <a-col :lg="24" :xl="12">
  691. <a-input type="text" v-model="dnsClientIp"></a-input>
  692. </a-col>
  693. </a-row>
  694. <a-row style="padding: 10px 20px;">
  695. <a-col :lg="24" :xl="12">
  696. <a-list-item-meta title='{{ i18n "pages.xray.dns.strategy" }}'
  697. description='{{ i18n "pages.xray.dns.strategyDesc" }}' />
  698. </a-col>
  699. <a-col :lg="24" :xl="12">
  700. <a-select v-model="dnsStrategy" style="width: 100%"
  701. :dropdown-class-name="themeSwitcher.currentTheme">
  702. <a-select-option :value="l" :label="l" v-for="l in ['UseIP', 'UseIPv4', 'UseIPv6']">
  703. [[ l ]]
  704. </a-select-option>
  705. </a-select>
  706. </a-col>
  707. </a-row>
  708. <a-row style="padding: 10px 20px;">
  709. <a-col :lg="24" :xl="12">
  710. <a-list-item-meta title='{{ i18n "pages.xray.dns.disableCache" }}'
  711. description='{{ i18n "pages.xray.dns.disableCacheDesc" }}'/>
  712. </a-col>
  713. <a-col :lg="24" :xl="12">
  714. <a-switch v-model="dnsDisableCache"></a-switch>
  715. </a-col>
  716. </a-row>
  717. <a-row style="padding: 10px 20px;">
  718. <a-col :lg="24" :xl="12">
  719. <a-list-item-meta title='{{ i18n "pages.xray.dns.disableFallback" }}'
  720. description='{{ i18n "pages.xray.dns.disableFallbackDesc" }}'/>
  721. </a-col>
  722. <a-col :lg="24" :xl="12">
  723. <a-switch v-model="dnsDisableFallback"></a-switch>
  724. </a-col>
  725. </a-row>
  726. <a-row style="padding: 10px 20px;">
  727. <a-col :lg="24" :xl="12">
  728. <a-list-item-meta title='{{ i18n "pages.xray.dns.disableFallbackIfMatch" }}'
  729. description='{{ i18n "pages.xray.dns.disableFallbackIfMatchDesc" }}'/>
  730. </a-col>
  731. <a-col :lg="24" :xl="12">
  732. <a-switch v-model="dnsDisableFallbackIfMatch"></a-switch>
  733. </a-col>
  734. </a-row>
  735. </template>
  736. </a-list-item>
  737. </a-collapse-panel>
  738. <template v-if="enableDNS">
  739. <a-collapse-panel header='DNS'>
  740. <a-button type="primary" icon="plus" @click="addDNSServer()" style="margin: 10px;">{{ i18n
  741. "pages.xray.dns.add" }}</a-button>
  742. <a-table :columns="dnsColumns" bordered v-if="dnsServers.length>0" :row-key="r => r.key"
  743. :data-source="dnsServers" :scroll="isMobile ? {} : { x: 200 }" :pagination="false" :indent-size="0"
  744. style="margin: 10px; margin-top: 10px;">
  745. <template slot="action" slot-scope="text,dns,index">
  746. [[ index+1 ]]
  747. <a-dropdown :trigger="['click']">
  748. <a-icon @click="e => e.preventDefault()" type="more"
  749. style="font-size: 16px; text-decoration: bold;"></a-icon>
  750. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  751. <a-menu-item @click="editDNSServer(index)">
  752. <a-icon type="edit"></a-icon>
  753. {{ i18n "edit" }}
  754. </a-menu-item>
  755. <a-menu-item @click="deleteDNSServer(index)">
  756. <span style="color: #FF4D4F">
  757. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  758. </span>
  759. </a-menu-item>
  760. </a-menu>
  761. </a-dropdown>
  762. </template>
  763. <template slot="address" slot-scope="dns,index">
  764. <span v-if="typeof dns == 'object'">[[ dns.address ]]</span>
  765. <span v-else>[[ dns ]]</span>
  766. </template>
  767. <template slot="domain" slot-scope="dns,index">
  768. <span v-if="typeof dns == 'object'">[[ dns.domains.join(",") ]]</span>
  769. </template>
  770. <template slot="expectIPs" slot-scope="dns,index">
  771. <span v-if="typeof dns == 'object'">[[ dns.expectIPs.join(",") ]]</span>
  772. </template>
  773. </a-table>
  774. </a-collapse-panel>
  775. <a-collapse-panel header='FakeDNS'>
  776. <a-button type="primary" icon="plus" @click="addFakedns()" style="margin: 10px;">{{ i18n
  777. "pages.xray.fakedns.add" }}</a-button>
  778. <a-table :columns="fakednsColumns" bordered v-if="fakeDns && fakeDns.length>0" :row-key="r => r.key"
  779. :data-source="fakeDns" :scroll="isMobile ? {} : { x: 200 }" :pagination="false" :indent-size="0"
  780. style="margin: 10px; margin-top: 10px;">
  781. <template slot="action" slot-scope="text,fakedns,index">
  782. [[ index+1 ]]
  783. <a-dropdown :trigger="['click']">
  784. <a-icon @click="e => e.preventDefault()" type="more"
  785. style="font-size: 16px; text-decoration: bold;"></a-icon>
  786. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  787. <a-menu-item @click="editFakedns(index)">
  788. <a-icon type="edit"></a-icon>
  789. {{ i18n "edit" }}
  790. </a-menu-item>
  791. <a-menu-item @click="deleteFakedns(index)">
  792. <span style="color: #FF4D4F">
  793. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  794. </span>
  795. </a-menu-item>
  796. </a-menu>
  797. </a-dropdown>
  798. </template>
  799. </a-table>
  800. </a-collapse-panel>
  801. </template>
  802. </a-collapse>
  803. </a-tab-pane>
  804. <a-tab-pane key="tpl-advanced" tab='{{ i18n "pages.xray.advancedTemplate"}}' style="padding-top: 20px;" force-render="true">
  805. <a-list-item-meta title='{{ i18n "pages.xray.Template"}}' description='{{ i18n "pages.xray.TemplateDesc"}}'></a-list-item-meta>
  806. <a-radio-group v-model="advSettings" @change="changeCode" button-style="solid" style="margin: 10px 0;" :size="isMobile ? 'small' : ''">
  807. <a-radio-button value="xraySetting">{{ i18n "pages.xray.completeTemplate"}}</a-radio-button>
  808. <a-radio-button value="inboundSettings">{{ i18n "pages.xray.Inbounds" }}</a-radio-button>
  809. <a-radio-button value="outboundSettings">{{ i18n "pages.xray.Outbounds" }}</a-radio-button>
  810. <a-radio-button value="routingRuleSettings">{{ i18n "pages.xray.Routings" }}</a-radio-button>
  811. </a-radio-group>
  812. <textarea style="position:absolute; left: -800px;" id="xraySetting"></textarea>
  813. </a-tab-pane>
  814. </a-tabs>
  815. </a-space>
  816. </a-spin>
  817. </a-layout-content>
  818. </a-layout>
  819. </a-layout>
  820. {{template "js" .}}
  821. {{template "component/themeSwitcher" .}}
  822. {{template "component/sortableTable" .}}
  823. {{template "component/setting"}}
  824. {{template "ruleModal"}}
  825. {{template "outModal"}}
  826. {{template "reverseModal"}}
  827. {{template "balancerModal"}}
  828. {{template "dnsModal"}}
  829. {{template "fakednsModal"}}
  830. {{template "warpModal"}}
  831. <script>
  832. const rulesColumns = [
  833. { title: "#", align: 'center', width: 15, scopedSlots: { customRender: 'action' } },
  834. { title: '{{ i18n "pages.xray.rules.source"}}', children: [
  835. { title: 'IP', dataIndex: "source", align: 'center', width: 20, ellipsis: true },
  836. { title: 'Port', dataIndex: 'sourcePort', align: 'center', width: 10, ellipsis: true } ]},
  837. { title: '{{ i18n "pages.inbounds.network"}}', children: [
  838. { title: 'L4', dataIndex: 'network', align: 'center', width: 10 },
  839. { title: 'Protocol', dataIndex: 'protocol', align: 'center', width: 10, ellipsis: true },
  840. { title: 'Attrs', dataIndex: 'attrs', align: 'center', width: 20, ellipsis: true } ]},
  841. { title: '{{ i18n "pages.xray.rules.dest"}}', children: [
  842. { title: 'IP', dataIndex: 'ip', align: 'center', width: 20, ellipsis: true },
  843. { title: 'Domain', dataIndex: 'domain', align: 'center', width: 20, ellipsis: true },
  844. { title: 'Port', dataIndex: 'port', align: 'center', width: 10, ellipsis: true }]},
  845. { title: '{{ i18n "pages.xray.rules.inbound"}}', children: [
  846. { title: 'Inbound Tag', dataIndex: 'inboundTag', align: 'center', width: 15, ellipsis: true },
  847. { title: 'Client Email', dataIndex: 'user', align: 'center', width: 20, ellipsis: true }]},
  848. { title: '{{ i18n "pages.xray.rules.outbound"}}', dataIndex: 'outboundTag', align: 'center', width: 15 },
  849. { title: '{{ i18n "pages.xray.rules.balancer"}}', dataIndex: 'balancerTag', align: 'center', width: 15 },
  850. ];
  851. const rulesMobileColumns = [
  852. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  853. { title: '{{ i18n "pages.xray.rules.inbound"}}', align: 'center', width: 50, ellipsis: true, scopedSlots: { customRender: 'inbound' } },
  854. { title: '{{ i18n "pages.xray.rules.outbound"}}', align: 'center', width: 50, ellipsis: true, scopedSlots: { customRender: 'outbound' } },
  855. { title: '{{ i18n "pages.xray.rules.info"}}', align: 'center', width: 50, ellipsis: true, scopedSlots: { customRender: 'info' } },
  856. ];
  857. const outboundColumns = [
  858. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  859. { title: '{{ i18n "pages.xray.outbound.tag"}}', dataIndex: 'tag', align: 'center', width: 50 },
  860. { title: '{{ i18n "protocol"}}', align: 'center', width: 50, scopedSlots: { customRender: 'protocol' } },
  861. { title: '{{ i18n "pages.xray.outbound.address"}}', align: 'center', width: 50, scopedSlots: { customRender: 'address' } },
  862. { title: '{{ i18n "pages.inbounds.traffic" }}', align: 'center', width: 50, scopedSlots: { customRender: 'traffic' } },
  863. ];
  864. const reverseColumns = [
  865. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  866. { title: '{{ i18n "pages.xray.outbound.type"}}', dataIndex: 'type', align: 'center', width: 50 },
  867. { title: '{{ i18n "pages.xray.outbound.tag"}}', dataIndex: 'tag', align: 'center', width: 50 },
  868. { title: '{{ i18n "pages.xray.outbound.domain"}}', dataIndex: 'domain', align: 'center', width: 50 },
  869. ];
  870. const balancerColumns = [
  871. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  872. { title: '{{ i18n "pages.xray.balancer.tag"}}', dataIndex: 'tag', align: 'center', width: 50 },
  873. { title: '{{ i18n "pages.xray.balancer.balancerStrategy"}}', align: 'center', width: 50, scopedSlots: { customRender: 'strategy' }},
  874. { title: '{{ i18n "pages.xray.balancer.balancerSelectors"}}', align: 'center', width: 100, scopedSlots: { customRender: 'selector' }},
  875. ];
  876. const dnsColumns = [
  877. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  878. { title: '{{ i18n "pages.xray.outbound.address"}}', align: 'center', width: 50, scopedSlots: { customRender: 'address' } },
  879. { title: '{{ i18n "pages.xray.dns.domains"}}', align: 'center', width: 50, scopedSlots: { customRender: 'domain' } },
  880. { title: '{{ i18n "pages.xray.dns.expectIPs"}}', align: 'center', width: 50, scopedSlots: { customRender: 'expectIPs' } },
  881. ];
  882. const fakednsColumns = [
  883. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  884. { title: '{{ i18n "pages.xray.fakedns.ipPool"}}', dataIndex: 'ipPool', align: 'center', width: 50 },
  885. { title: '{{ i18n "pages.xray.fakedns.poolSize"}}', dataIndex: 'poolSize', align: 'center', width: 50 },
  886. ];
  887. const app = new Vue({
  888. delimiters: ['[[', ']]'],
  889. el: '#app',
  890. data: {
  891. siderDrawer,
  892. themeSwitcher,
  893. isDarkTheme: themeSwitcher.isDarkTheme,
  894. spinning: false,
  895. oldXraySetting: '',
  896. xraySetting: '',
  897. inboundTags: [],
  898. outboundsTraffic: [],
  899. saveBtnDisable: true,
  900. refreshing: false,
  901. restartResult: '',
  902. showAlert: false,
  903. isMobile: window.innerWidth <= 768,
  904. advSettings: 'xraySetting',
  905. obsSettings: '',
  906. cm: null,
  907. cmOptions: {
  908. lineNumbers: true,
  909. mode: "application/json",
  910. lint: true,
  911. styleActiveLine: true,
  912. matchBrackets: true,
  913. theme: "xq",
  914. autoCloseTags: true,
  915. lineWrapping: true,
  916. indentUnit: 2,
  917. indentWithTabs: true,
  918. smartIndent: true,
  919. tabSize: 2,
  920. lineWiseCopyCut: false,
  921. foldGutter: true,
  922. gutters: [
  923. "CodeMirror-lint-markers",
  924. "CodeMirror-linenumbers",
  925. "CodeMirror-foldgutter",
  926. ],
  927. },
  928. ipv4Settings: {
  929. tag: "IPv4",
  930. protocol: "freedom",
  931. settings: {
  932. domainStrategy: "UseIPv4"
  933. }
  934. },
  935. directSettings: {
  936. tag: "direct",
  937. protocol: "freedom"
  938. },
  939. routingDomainStrategies: ["AsIs", "IPIfNonMatch", "IPOnDemand"],
  940. log: {
  941. loglevel: ["none", "debug", "info", "warning", "error"],
  942. access: ["none", "./access.log"],
  943. error: ["none", "./error.log"],
  944. dnsLog: false,
  945. maskAddress: ["quarter", "half", "full"],
  946. },
  947. settingsData: {
  948. protocols: {
  949. bittorrent: ["bittorrent"],
  950. },
  951. IPsOptions: [
  952. { label: 'Private IPs', value: 'geoip:private' },
  953. { label: '🇮🇷 Iran', value: 'ext:geoip_IR.dat:ir' },
  954. { label: '🇨🇳 China', value: 'geoip:cn' },
  955. { label: '🇷🇺 Russia', value: 'ext:geoip_RU.dat:ru' },
  956. { label: '🇻🇳 Vietnam', value: 'geoip:vn' },
  957. { label: '🇪🇸 Spain', value: 'geoip:es' },
  958. { label: '🇮🇩 Indonesia', value: 'geoip:id' },
  959. { label: '🇺🇦 Ukraine', value: 'geoip:ua' },
  960. { label: '🇹🇷 Türkiye', value: 'geoip:tr' },
  961. { label: '🇧🇷 Brazil', value: 'geoip:br' },
  962. ],
  963. DomainsOptions: [
  964. { label: '🇮🇷 Iran', value: 'ext:geosite_IR.dat:ir' },
  965. { label: '🇮🇷 .ir', value: 'regexp:.*\\.ir$' },
  966. { label: '🇮🇷 .ایران', value: 'regexp:.*\\.xn--mgba3a4f16a$' },
  967. { label: '🇨🇳 China', value: 'geosite:cn' },
  968. { label: '🇨🇳 .cn', value: 'regexp:.*\\.cn$' },
  969. { label: '🇷🇺 Russia', value: 'ext:geosite_RU.dat:ru-available-only-inside' },
  970. { label: '🇷🇺 .ru', value: 'regexp:.*\\.ru$' },
  971. { label: '🇷🇺 .su', value: 'regexp:.*\\.su$' },
  972. { label: '🇷🇺 .рф', value: 'regexp:.*\\.xn--p1ai$' },
  973. { label: '🇻🇳 .vn', value: 'regexp:.*\\.vn$' },
  974. ],
  975. BlockDomainsOptions: [
  976. { label: 'Ads All', value: 'geosite:category-ads-all' },
  977. { label: 'Ads IR 🇮🇷', value: 'ext:geosite_IR.dat:category-ads-all' },
  978. { label: 'Ads RU 🇷🇺', value: 'ext:geosite_RU.dat:category-ads-all' },
  979. { label: 'Malware 🇮🇷', value: 'ext:geosite_IR.dat:malware' },
  980. { label: 'Phishing 🇮🇷', value: 'ext:geosite_IR.dat:phishing' },
  981. { label: 'Cryptominers 🇮🇷', value: 'ext:geosite_IR.dat:cryptominers' },
  982. { label: '🇮🇷 Iran', value: 'ext:geosite_IR.dat:ir' },
  983. { label: '🇮🇷 .ir', value: 'regexp:.*\\.ir$' },
  984. { label: '🇮🇷 .ایران', value: 'regexp:.*\\.xn--mgba3a4f16a$' },
  985. { label: '🇨🇳 China', value: 'geosite:cn' },
  986. { label: '🇨🇳 .cn', value: 'regexp:.*\\.cn$' },
  987. { label: '🇷🇺 Russia', value: 'ext:geosite_RU.dat:ru-available-only-inside' },
  988. { label: '🇷🇺 .ru', value: 'regexp:.*\\.ru' },
  989. { label: '🇷🇺 .su', value: 'regexp:.*\\.su$' },
  990. { label: '🇷🇺 .рф', value: 'regexp:.*\\.xn--p1ai$' },
  991. { label: '🇻🇳 .vn', value: 'regexp:.*\\.vn$' },
  992. ],
  993. ServicesOptions: [
  994. { label: 'Apple', value: 'geosite:apple' },
  995. { label: 'Meta', value: 'geosite:meta' },
  996. { label: 'Google', value: 'geosite:google' },
  997. { label: 'OpenAI', value: 'geosite:openai' },
  998. { label: 'Spotify', value: 'geosite:spotify' },
  999. { label: 'Netflix', value: 'geosite:netflix' },
  1000. { label: 'Reddit', value: 'geosite:reddit' },
  1001. { label: 'Speedtest', value: 'geosite:speedtest' },
  1002. ],
  1003. familyProtectDNS: {
  1004. "servers": [
  1005. "1.1.1.3", // https://developers.cloudflare.com/1.1.1.1/setup/
  1006. "1.0.0.3",
  1007. "2606:4700:4700::1113",
  1008. "2606:4700:4700::1003"
  1009. ],
  1010. "queryStrategy": "UseIP"
  1011. },
  1012. },
  1013. defaultObservatory: {
  1014. subjectSelector: [],
  1015. probeURL: "http://www.google.com/gen_204",
  1016. probeInterval: "10m",
  1017. enableConcurrency: true
  1018. },
  1019. defaultBurstObservatory: {
  1020. subjectSelector: [],
  1021. pingConfig: {
  1022. destination: "http://www.google.com/gen_204",
  1023. interval: "30m",
  1024. connectivity: "http://connectivitycheck.platform.hicloud.com/generate_204",
  1025. timeout: "10s",
  1026. sampling: 2
  1027. }
  1028. }
  1029. },
  1030. methods: {
  1031. loading(spinning = true) {
  1032. this.spinning = spinning;
  1033. },
  1034. async getOutboundsTraffic() {
  1035. const msg = await HttpUtil.get("/panel/xray/getOutboundsTraffic");
  1036. if (msg.success) {
  1037. this.outboundsTraffic = msg.obj;
  1038. }
  1039. },
  1040. async getXraySetting() {
  1041. this.loading(true);
  1042. const msg = await HttpUtil.post("/panel/xray/");
  1043. this.loading(false);
  1044. if (msg.success) {
  1045. result = JSON.parse(msg.obj);
  1046. xs = JSON.stringify(result.xraySetting, null, 2);
  1047. this.oldXraySetting = xs;
  1048. this.xraySetting = xs;
  1049. this.inboundTags = result.inboundTags;
  1050. this.saveBtnDisable = true;
  1051. }
  1052. },
  1053. async updateXraySetting() {
  1054. this.loading(true);
  1055. const msg = await HttpUtil.post("/panel/xray/update", {xraySetting : this.xraySetting});
  1056. this.loading(false);
  1057. if (msg.success) {
  1058. await this.getXraySetting();
  1059. }
  1060. },
  1061. async restartXray() {
  1062. this.loading(true);
  1063. const msg = await HttpUtil.post("server/restartXrayService");
  1064. this.loading(false);
  1065. if (msg.success) {
  1066. await PromiseUtil.sleep(500);
  1067. await this.getXrayResult();
  1068. }
  1069. this.loading(false);
  1070. },
  1071. async getXrayResult() {
  1072. const msg = await HttpUtil.get("/panel/xray/getXrayResult");
  1073. if (msg.success) {
  1074. this.restartResult=msg.obj;
  1075. if(msg.obj.length > 1) Vue.prototype.$message.error(msg.obj);
  1076. }
  1077. },
  1078. async fetchUserSecret() {
  1079. this.loading(true);
  1080. const userMessage = await HttpUtil.post("/panel/setting/getUserSecret", this.user);
  1081. if (userMessage.success) {
  1082. this.user = userMessage.obj;
  1083. }
  1084. this.loading(false);
  1085. },
  1086. async updateSecret() {
  1087. this.loading(true);
  1088. const msg = await HttpUtil.post("/panel/setting/updateUserSecret", this.user);
  1089. if (msg.success) {
  1090. this.user = msg.obj;
  1091. window.location.replace(basePath + "logout");
  1092. }
  1093. this.loading(false);
  1094. await this.updateXraySetting();
  1095. },
  1096. generateRandomString(length) {
  1097. var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  1098. let randomString = "";
  1099. for (let i = 0; i < length; i++) {
  1100. randomString += chars[Math.floor(Math.random() * chars.length)];
  1101. }
  1102. return randomString;
  1103. },
  1104. async getNewSecret() {
  1105. this.loading(true);
  1106. await PromiseUtil.sleep(600);
  1107. const newSecret = this.generateRandomString(64);
  1108. this.user.loginSecret = newSecret;
  1109. document.getElementById("token").textContent = newSecret;
  1110. this.loading(false);
  1111. },
  1112. async toggleToken(value) {
  1113. if (value) {
  1114. await this.getNewSecret();
  1115. } else {
  1116. this.user.loginSecret = "";
  1117. }
  1118. },
  1119. async resetXrayConfigToDefault() {
  1120. this.loading(true);
  1121. const msg = await HttpUtil.get("/panel/setting/getDefaultJsonConfig");
  1122. this.loading(false);
  1123. if (msg.success) {
  1124. this.templateSettings = JSON.parse(JSON.stringify(msg.obj, null, 2));
  1125. this.saveBtnDisable = true;
  1126. }
  1127. },
  1128. changePage(pageKey) {
  1129. if(pageKey == 'tpl-advanced') this.changeCode();
  1130. if(pageKey == 'tpl-balancer') this.changeObsCode();
  1131. },
  1132. syncRulesWithOutbound(tag, setting) {
  1133. const newTemplateSettings = this.templateSettings;
  1134. const haveRules = newTemplateSettings.routing.rules.some((r) => r?.outboundTag === tag);
  1135. const outboundIndex = newTemplateSettings.outbounds.findIndex((o) => o.tag === tag);
  1136. if (!haveRules && outboundIndex > 0) {
  1137. newTemplateSettings.outbounds.splice(outboundIndex);
  1138. }
  1139. if (haveRules && outboundIndex < 0) {
  1140. newTemplateSettings.outbounds.push(setting);
  1141. }
  1142. this.templateSettings = newTemplateSettings;
  1143. },
  1144. templateRuleGetter(routeSettings) {
  1145. const { property, outboundTag } = routeSettings;
  1146. let result = [];
  1147. if (this.templateSettings != null) {
  1148. this.templateSettings.routing.rules.forEach(
  1149. (routingRule) => {
  1150. if (
  1151. routingRule.hasOwnProperty(property) &&
  1152. routingRule.hasOwnProperty("outboundTag") &&
  1153. routingRule.outboundTag === outboundTag
  1154. ) {
  1155. result.push(...routingRule[property]);
  1156. }
  1157. }
  1158. );
  1159. }
  1160. return result;
  1161. },
  1162. templateRuleSetter(routeSettings) {
  1163. const { data, property, outboundTag } = routeSettings;
  1164. const oldTemplateSettings = this.templateSettings;
  1165. const newTemplateSettings = oldTemplateSettings;
  1166. currentProperty = this.templateRuleGetter({ outboundTag, property })
  1167. if (currentProperty.length == 0) {
  1168. const propertyRule = {
  1169. type: "field",
  1170. outboundTag,
  1171. [property]: data
  1172. };
  1173. newTemplateSettings.routing.rules.push(propertyRule);
  1174. }
  1175. else {
  1176. const newRules = [];
  1177. insertedOnce = false;
  1178. newTemplateSettings.routing.rules.forEach(
  1179. (routingRule) => {
  1180. if (
  1181. routingRule.hasOwnProperty(property) &&
  1182. routingRule.hasOwnProperty("outboundTag") &&
  1183. routingRule.outboundTag === outboundTag
  1184. ) {
  1185. if (!insertedOnce && data.length > 0) {
  1186. insertedOnce = true;
  1187. routingRule[property] = data;
  1188. newRules.push(routingRule);
  1189. }
  1190. }
  1191. else {
  1192. newRules.push(routingRule);
  1193. }
  1194. }
  1195. );
  1196. newTemplateSettings.routing.rules = newRules;
  1197. }
  1198. this.templateSettings = newTemplateSettings;
  1199. },
  1200. changeCode() {
  1201. if(this.cm != null) {
  1202. this.cm.toTextArea();
  1203. }
  1204. textAreaObj = document.getElementById('xraySetting');
  1205. textAreaObj.value = this[this.advSettings];
  1206. this.cm = CodeMirror.fromTextArea(textAreaObj, this.cmOptions);
  1207. this.cm.on('change',editor => {
  1208. value = editor.getValue();
  1209. if (this.isJsonString(value)) {
  1210. this[this.advSettings] = value;
  1211. }
  1212. });
  1213. },
  1214. changeObsCode() {
  1215. if(this.cm != null) {
  1216. this.cm.toTextArea();
  1217. }
  1218. if (this.obsSettings == ''){
  1219. this.cm = null;
  1220. return
  1221. }
  1222. textAreaObj = document.getElementById('obsSetting');
  1223. textAreaObj.value = this[this.obsSettings];
  1224. this.cm = CodeMirror.fromTextArea(textAreaObj, this.cmOptions);
  1225. this.cm.on('change',editor => {
  1226. value = editor.getValue();
  1227. if(this.isJsonString(value)){
  1228. this[this.obsSettings] = value;
  1229. }
  1230. });
  1231. },
  1232. isJsonString(str) {
  1233. try {
  1234. JSON.parse(str);
  1235. } catch (e) {
  1236. return false;
  1237. }
  1238. return true;
  1239. },
  1240. findOutboundTraffic(o) {
  1241. for (const otraffic of this.outboundsTraffic) {
  1242. if (otraffic.tag == o.tag) {
  1243. return sizeFormat(otraffic.up) + ' / ' + sizeFormat(otraffic.down);
  1244. }
  1245. }
  1246. return sizeFormat(0) + ' / ' + sizeFormat(0);
  1247. },
  1248. findOutboundAddress(o) {
  1249. serverObj = null;
  1250. switch(o.protocol){
  1251. case Protocols.VMess:
  1252. case Protocols.VLESS:
  1253. serverObj = o.settings.vnext;
  1254. break;
  1255. case Protocols.HTTP:
  1256. case Protocols.Socks:
  1257. case Protocols.Shadowsocks:
  1258. case Protocols.Trojan:
  1259. serverObj = o.settings.servers;
  1260. break;
  1261. case Protocols.DNS:
  1262. return [o.settings?.address + ':' + o.settings?.port];
  1263. case Protocols.Wireguard:
  1264. return o.settings.peers.map(peer => peer.endpoint);
  1265. default:
  1266. return null;
  1267. }
  1268. return serverObj ? serverObj.map(obj => obj.address + ':' + obj.port) : null;
  1269. },
  1270. addOutbound(){
  1271. outModal.show({
  1272. title: '{{ i18n "pages.xray.outbound.addOutbound"}}',
  1273. okText: '{{ i18n "pages.xray.outbound.addOutbound" }}',
  1274. confirm: (outbound) => {
  1275. outModal.loading();
  1276. if(outbound.tag.length > 0){
  1277. this.templateSettings.outbounds.push(outbound);
  1278. this.outboundSettings = JSON.stringify(this.templateSettings.outbounds);
  1279. }
  1280. outModal.close();
  1281. },
  1282. isEdit: false,
  1283. tags: this.templateSettings.outbounds.map(obj => obj.tag)
  1284. });
  1285. },
  1286. editOutbound(index){
  1287. outModal.show({
  1288. title: '{{ i18n "pages.xray.outbound.editOutbound"}} ' + (index+1),
  1289. outbound: app.templateSettings.outbounds[index],
  1290. confirm: (outbound) => {
  1291. outModal.loading();
  1292. this.templateSettings.outbounds[index] = outbound;
  1293. this.outboundSettings = JSON.stringify(this.templateSettings.outbounds);
  1294. outModal.close();
  1295. },
  1296. isEdit: true,
  1297. tags: this.outboundData.filter((o) => o.key != index ).map(obj => obj.tag)
  1298. });
  1299. },
  1300. deleteOutbound(index){
  1301. outbounds = this.templateSettings.outbounds;
  1302. outbounds.splice(index,1);
  1303. this.outboundSettings = JSON.stringify(outbounds);
  1304. },
  1305. setFirstOutbound(index){
  1306. outbounds = this.templateSettings.outbounds;
  1307. outbounds.splice(0, 0, outbounds.splice(index, 1)[0]);
  1308. this.outboundSettings = JSON.stringify(outbounds);
  1309. },
  1310. addReverse(){
  1311. reverseModal.show({
  1312. title: '{{ i18n "pages.xray.outbound.addReverse"}}',
  1313. okText: '{{ i18n "pages.xray.outbound.addReverse" }}',
  1314. confirm: (reverse, rules) => {
  1315. reverseModal.loading();
  1316. if(reverse.tag.length > 0){
  1317. newTemplateSettings = this.templateSettings;
  1318. if(newTemplateSettings.reverse == undefined) newTemplateSettings.reverse = {};
  1319. if(newTemplateSettings.reverse[reverse.type+'s'] == undefined) newTemplateSettings.reverse[reverse.type+'s'] = [];
  1320. newTemplateSettings.reverse[reverse.type+'s'].push({ tag: reverse.tag, domain: reverse.domain });
  1321. this.templateSettings = newTemplateSettings;
  1322. // Add related rules
  1323. this.templateSettings.routing.rules.push(...rules);
  1324. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  1325. }
  1326. reverseModal.close();
  1327. },
  1328. isEdit: false
  1329. });
  1330. },
  1331. editReverse(index){
  1332. if(this.reverseData[index].type == "bridge") {
  1333. oldRules = this.templateSettings.routing.rules.filter(r => r.inboundTag && r.inboundTag[0] == this.reverseData[index].tag);
  1334. } else {
  1335. oldRules = this.templateSettings.routing.rules.filter(r => r.outboundTag && r.outboundTag == this.reverseData[index].tag);
  1336. }
  1337. reverseModal.show({
  1338. title: '{{ i18n "pages.xray.outbound.editReverse"}} ' + (index+1),
  1339. reverse: this.reverseData[index],
  1340. rules: oldRules,
  1341. confirm: (reverse, rules) => {
  1342. reverseModal.loading();
  1343. if(reverse.tag.length > 0){
  1344. oldData = this.reverseData[index];
  1345. newTemplateSettings = this.templateSettings;
  1346. oldReverseIndex = newTemplateSettings.reverse[oldData.type+'s'].findIndex(rs => rs.tag == oldData.tag);
  1347. oldRuleIndex0 = oldRules.length>0 ? newTemplateSettings.routing.rules.findIndex(r => JSON.stringify(r) == JSON.stringify(oldRules[0])) : -1;
  1348. oldRuleIndex1 = oldRules.length==2 ? newTemplateSettings.routing.rules.findIndex(r => JSON.stringify(r) == JSON.stringify(oldRules[1])) : -1;
  1349. if(oldData.type == reverse.type){
  1350. newTemplateSettings.reverse[oldData.type + 's'][oldReverseIndex] = { tag: reverse.tag, domain: reverse.domain };
  1351. } else {
  1352. newTemplateSettings.reverse[oldData.type+'s'].splice(oldReverseIndex,1);
  1353. // delete empty object
  1354. if(newTemplateSettings.reverse[oldData.type+'s'].length == 0) Reflect.deleteProperty(newTemplateSettings.reverse, oldData.type+'s');
  1355. // add other type of reverse if it is not exist
  1356. if(!newTemplateSettings.reverse[reverse.type+'s']) newTemplateSettings.reverse[reverse.type+'s'] = [];
  1357. newTemplateSettings.reverse[reverse.type+'s'].push({ tag: reverse.tag, domain: reverse.domain });
  1358. }
  1359. this.templateSettings = newTemplateSettings;
  1360. // Adjust Rules
  1361. newRules = this.templateSettings.routing.rules;
  1362. oldRuleIndex0 != -1 ? newRules[oldRuleIndex0] = rules[0] : newRules.push(rules[0]);
  1363. oldRuleIndex1 != -1 ? newRules[oldRuleIndex1] = rules[1] : newRules.push(rules[1]);
  1364. this.routingRuleSettings = JSON.stringify(newRules);
  1365. }
  1366. reverseModal.close();
  1367. },
  1368. isEdit: true
  1369. });
  1370. },
  1371. deleteReverse(index){
  1372. oldData = this.reverseData[index];
  1373. newTemplateSettings = this.templateSettings;
  1374. reverseTypeObj = newTemplateSettings.reverse[oldData.type+'s'];
  1375. realIndex = reverseTypeObj.findIndex(r => r.tag==oldData.tag && r.domain==oldData.domain);
  1376. newTemplateSettings.reverse[oldData.type+'s'].splice(realIndex,1);
  1377. // delete empty objects
  1378. if(reverseTypeObj.length == 0) Reflect.deleteProperty(newTemplateSettings.reverse, oldData.type+'s');
  1379. if(Object.keys(newTemplateSettings.reverse).length === 0) Reflect.deleteProperty(newTemplateSettings, 'reverse');
  1380. // delete related routing rules
  1381. newRules = newTemplateSettings.routing.rules;
  1382. if(oldData.type == "bridge"){
  1383. newRules = newTemplateSettings.routing.rules.filter(r => !( r.inboundTag && r.inboundTag.length == 1 && r.inboundTag[0] == oldData.tag));
  1384. } else if(oldData.type == "portal"){
  1385. newRules = newTemplateSettings.routing.rules.filter(r => r.outboundTag != oldData.tag);
  1386. }
  1387. newTemplateSettings.routing.rules = newRules;
  1388. this.templateSettings = newTemplateSettings;
  1389. },
  1390. async refreshOutboundTraffic() {
  1391. if (!this.refreshing) {
  1392. this.refreshing = true;
  1393. await this.getOutboundsTraffic();
  1394. data = []
  1395. if (this.templateSettings != null) {
  1396. this.templateSettings.outbounds.forEach((o, index) => {
  1397. data.push({'key': index, ...o});
  1398. });
  1399. }
  1400. this.outboundData = data;
  1401. this.refreshing = false;
  1402. }
  1403. },
  1404. async resetOutboundTraffic(index) {
  1405. let tag = "-alltags-";
  1406. if (index >= 0) {
  1407. tag = this.outboundData[index].tag ? this.outboundData[index].tag : ""
  1408. }
  1409. const msg = await HttpUtil.post("/panel/xray/resetOutboundsTraffic", { tag: tag });
  1410. if (msg.success) {
  1411. await this.refreshOutboundTraffic();
  1412. }
  1413. },
  1414. addBalancer() {
  1415. balancerModal.show({
  1416. title: '{{ i18n "pages.xray.balancer.addBalancer"}}',
  1417. okText: '{{ i18n "pages.xray.balancer.addBalancer"}}',
  1418. balancerTags: this.balancersData.filter((o) => !ObjectUtil.isEmpty(o.tag)).map(obj => obj.tag),
  1419. balancer: {
  1420. tag: '',
  1421. strategy: 'random',
  1422. selector: [],
  1423. fallbackTag: ''
  1424. },
  1425. confirm: (balancer) => {
  1426. balancerModal.loading();
  1427. newTemplateSettings = this.templateSettings;
  1428. if (newTemplateSettings.routing.balancers == undefined) {
  1429. newTemplateSettings.routing.balancers = [];
  1430. }
  1431. let tmpBalancer = {
  1432. 'tag': balancer.tag,
  1433. 'selector': balancer.selector,
  1434. 'fallbackTag': balancer.fallbackTag
  1435. };
  1436. if (balancer.strategy && balancer.strategy != 'random') {
  1437. tmpBalancer.strategy = {
  1438. 'type': balancer.strategy
  1439. };
  1440. }
  1441. newTemplateSettings.routing.balancers.push(tmpBalancer);
  1442. this.templateSettings = newTemplateSettings;
  1443. if (balancer.strategy == 'leastPing' || balancer.strategy == 'leastLoad')
  1444. this.updateObservatorySelectors();
  1445. balancerModal.close();
  1446. this.changeObsCode();
  1447. },
  1448. isEdit: false
  1449. });
  1450. },
  1451. editBalancer(index) {
  1452. const oldTag = this.balancersData[index].tag;
  1453. balancerModal.show({
  1454. title: '{{ i18n "pages.xray.balancer.editBalancer"}}',
  1455. okText: '{{ i18n "sure" }}',
  1456. balancerTags: this.balancersData.filter((o) => !ObjectUtil.isEmpty(o.tag)).map(obj => obj.tag),
  1457. balancer: this.balancersData[index],
  1458. confirm: (balancer) => {
  1459. balancerModal.loading();
  1460. newTemplateSettings = this.templateSettings;
  1461. let tmpBalancer = {
  1462. 'tag': balancer.tag,
  1463. 'selector': balancer.selector,
  1464. 'fallbackTag': balancer.fallbackTag
  1465. };
  1466. // Remove old tag
  1467. if (newTemplateSettings.observatory){
  1468. newTemplateSettings.observatory.subjectSelector = newTemplateSettings.observatory.subjectSelector.filter(s => s != oldTag);
  1469. }
  1470. if (newTemplateSettings.burstObservatory){
  1471. newTemplateSettings.burstObservatory.subjectSelector = newTemplateSettings.burstObservatory.subjectSelector.filter(s => s != oldTag);
  1472. }
  1473. if (balancer.strategy && balancer.strategy != 'random') {
  1474. tmpBalancer.strategy = {
  1475. 'type': balancer.strategy
  1476. };
  1477. }
  1478. newTemplateSettings.routing.balancers[index] = tmpBalancer;
  1479. // change edited tag if used in rule section
  1480. if (oldTag != balancer.tag) {
  1481. newTemplateSettings.routing.rules.forEach((rule) => {
  1482. if (rule.balancerTag && rule.balancerTag == oldTag) {
  1483. rule.balancerTag = balancer.tag;
  1484. }
  1485. });
  1486. }
  1487. this.templateSettings = newTemplateSettings;
  1488. if (balancer.strategy == 'leastPing' || balancer.strategy == 'leastLoad')
  1489. this.updateObservatorySelectors();
  1490. balancerModal.close();
  1491. this.changeObsCode();
  1492. },
  1493. isEdit: true
  1494. });
  1495. },
  1496. updateObservatorySelectors(){
  1497. newTemplateSettings = this.templateSettings;
  1498. const leastPings = this.balancersData.filter((b) => b.strategy == 'leastPing');
  1499. const leastLoads = this.balancersData.filter((b) => b.strategy == 'leastLoad');
  1500. if (leastPings.length>0){
  1501. if (!newTemplateSettings.observatory)
  1502. newTemplateSettings.observatory = this.defaultObservatory;
  1503. newTemplateSettings.observatory.subjectSelector = [];
  1504. leastPings.forEach((b) => {
  1505. b.selector.forEach((s) => {
  1506. if (!newTemplateSettings.observatory.subjectSelector.includes(s))
  1507. newTemplateSettings.observatory.subjectSelector.push(s);
  1508. });
  1509. });
  1510. } else {
  1511. delete newTemplateSettings.observatory
  1512. }
  1513. if (leastLoads.length>0){
  1514. if (!newTemplateSettings.burstObservatory)
  1515. newTemplateSettings.burstObservatory = this.defaultBurstObservatory;
  1516. newTemplateSettings.burstObservatory.subjectSelector = [];
  1517. leastLoads.forEach((b) => {
  1518. b.selector.forEach((s) => {
  1519. if (!newTemplateSettings.burstObservatory.subjectSelector.includes(s))
  1520. newTemplateSettings.burstObservatory.subjectSelector.push(s);
  1521. });
  1522. });
  1523. } else {
  1524. delete newTemplateSettings.burstObservatory
  1525. }
  1526. this.templateSettings = newTemplateSettings;
  1527. this.changeObsCode();
  1528. },
  1529. deleteBalancer(index) {
  1530. newTemplateSettings = this.templateSettings;
  1531. // Remove from balancers
  1532. const removedBalancer = this.balancersData.splice(index, 1)[0];
  1533. // Remove from settings
  1534. let realIndex = newTemplateSettings.routing.balancers.findIndex((b) => b.tag === removedBalancer.tag);
  1535. newTemplateSettings.routing.balancers.splice(realIndex, 1);
  1536. // Update balancers property to an empty array if there are no more balancers
  1537. if (newTemplateSettings.routing.balancers.length === 0) {
  1538. delete newTemplateSettings.routing.balancers;
  1539. }
  1540. this.templateSettings = newTemplateSettings;
  1541. this.updateObservatorySelectors();
  1542. this.obsSettings = '';
  1543. this.changeObsCode()
  1544. },
  1545. addDNSServer(){
  1546. dnsModal.show({
  1547. title: '{{ i18n "pages.xray.dns.add" }}',
  1548. confirm: (dnsServer) => {
  1549. dnsServers = this.dnsServers;
  1550. dnsServers.push(dnsServer);
  1551. this.dnsServers = dnsServers;
  1552. dnsModal.close();
  1553. },
  1554. isEdit: false
  1555. });
  1556. },
  1557. editDNSServer(index){
  1558. dnsModal.show({
  1559. title: '{{ i18n "pages.xray.dns.edit" }} #' + (index+1),
  1560. dnsServer: this.dnsServers[index],
  1561. confirm: (dnsServer) => {
  1562. dnsServers = this.dnsServers;
  1563. dnsServers[index] = dnsServer;
  1564. this.dnsServers = dnsServers;
  1565. dnsModal.close();
  1566. },
  1567. isEdit: true
  1568. });
  1569. },
  1570. deleteDNSServer(index){
  1571. newDnsServers = this.dnsServers;
  1572. newDnsServers.splice(index,1);
  1573. this.dnsServers = newDnsServers;
  1574. },
  1575. addFakedns() {
  1576. fakednsModal.show({
  1577. title: '{{ i18n "pages.xray.fakedns.add" }}',
  1578. confirm: (item) => {
  1579. fakeDns = this.fakeDns?? [];
  1580. fakeDns.push(item);
  1581. this.fakeDns = fakeDns;
  1582. fakednsModal.close();
  1583. },
  1584. isEdit: false
  1585. });
  1586. },
  1587. editFakedns(index){
  1588. fakednsModal.show({
  1589. title: '{{ i18n "pages.xray.fakedns.edit" }} #' + (index+1),
  1590. fakeDns: this.fakeDns[index],
  1591. confirm: (item) => {
  1592. fakeDns = this.fakeDns;
  1593. fakeDns[index] = item;
  1594. this.fakeDns = fakeDns;
  1595. fakednsModal.close();
  1596. },
  1597. isEdit: true
  1598. });
  1599. },
  1600. deleteFakedns(index){
  1601. fakeDns = this.fakeDns;
  1602. fakeDns.splice(index,1);
  1603. this.fakeDns = fakeDns;
  1604. },
  1605. addRule(){
  1606. ruleModal.show({
  1607. title: '{{ i18n "pages.xray.rules.add"}}',
  1608. okText: '{{ i18n "pages.xray.rules.add" }}',
  1609. confirm: (rule) => {
  1610. ruleModal.loading();
  1611. if(JSON.stringify(rule).length > 3){
  1612. this.templateSettings.routing.rules.push(rule);
  1613. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  1614. }
  1615. ruleModal.close();
  1616. },
  1617. isEdit: false
  1618. });
  1619. },
  1620. editRule(index){
  1621. ruleModal.show({
  1622. title: '{{ i18n "pages.xray.rules.edit"}} ' + (index+1),
  1623. rule: app.templateSettings.routing.rules[index],
  1624. confirm: (rule) => {
  1625. ruleModal.loading();
  1626. if(JSON.stringify(rule).length > 3){
  1627. this.templateSettings.routing.rules[index] = rule;
  1628. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  1629. }
  1630. ruleModal.close();
  1631. },
  1632. isEdit: true
  1633. });
  1634. },
  1635. replaceRule(old_index,new_index){
  1636. rules = this.templateSettings.routing.rules;
  1637. if (new_index >= rules.length) rules.push(undefined);
  1638. rules.splice(new_index, 0, rules.splice(old_index, 1)[0]);
  1639. this.routingRuleSettings = JSON.stringify(rules);
  1640. },
  1641. deleteRule(index){
  1642. rules = this.templateSettings.routing.rules;
  1643. rules.splice(index,1);
  1644. this.routingRuleSettings = JSON.stringify(rules);
  1645. },
  1646. showWarp(){
  1647. warpModal.show();
  1648. }
  1649. },
  1650. async mounted() {
  1651. if (window.location.protocol !== "https:") {
  1652. this.showAlert = true;
  1653. }
  1654. await this.getXraySetting();
  1655. await this.getXrayResult();
  1656. await this.getOutboundsTraffic();
  1657. while (true) {
  1658. await PromiseUtil.sleep(800);
  1659. this.saveBtnDisable = this.oldXraySetting === this.xraySetting;
  1660. }
  1661. },
  1662. computed: {
  1663. templateSettings: {
  1664. get: function () {
  1665. const parsedSettings = this.xraySetting ? JSON.parse(this.xraySetting) : null;
  1666. return parsedSettings;
  1667. },
  1668. set: function (newValue) {
  1669. if (newValue) {
  1670. this.xraySetting = JSON.stringify(newValue, null, 2);
  1671. }
  1672. },
  1673. },
  1674. inboundSettings: {
  1675. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.inbounds, null, 2) : null; },
  1676. set: function (newValue) {
  1677. newTemplateSettings = this.templateSettings;
  1678. newTemplateSettings.inbounds = JSON.parse(newValue);
  1679. this.templateSettings = newTemplateSettings;
  1680. },
  1681. },
  1682. outboundSettings: {
  1683. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.outbounds, null, 2) : null; },
  1684. set: function (newValue) {
  1685. newTemplateSettings = this.templateSettings;
  1686. newTemplateSettings.outbounds = JSON.parse(newValue);
  1687. this.templateSettings = newTemplateSettings;
  1688. },
  1689. },
  1690. outboundData: {
  1691. get: function () {
  1692. data = []
  1693. if (this.templateSettings != null) {
  1694. this.templateSettings.outbounds.forEach((o, index) => {
  1695. data.push({'key': index, ...o});
  1696. });
  1697. }
  1698. return data;
  1699. },
  1700. },
  1701. reverseData: {
  1702. get: function () {
  1703. data = []
  1704. if (this.templateSettings != null && this.templateSettings.reverse != null) {
  1705. if(this.templateSettings.reverse.bridges) {
  1706. this.templateSettings.reverse.bridges.forEach((o, index) => {
  1707. data.push({'key': index, 'type':'bridge', ...o});
  1708. });
  1709. }
  1710. if(this.templateSettings.reverse.portals){
  1711. this.templateSettings.reverse.portals.forEach((o, index) => {
  1712. data.push({'key': index, 'type':'portal', ...o});
  1713. });
  1714. }
  1715. }
  1716. return data;
  1717. },
  1718. },
  1719. routingRuleSettings: {
  1720. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.routing.rules, null, 2) : null; },
  1721. set: function (newValue) {
  1722. newTemplateSettings = this.templateSettings;
  1723. newTemplateSettings.routing.rules = JSON.parse(newValue);
  1724. this.templateSettings = newTemplateSettings;
  1725. },
  1726. },
  1727. routingRuleData: {
  1728. get: function () {
  1729. data = [];
  1730. if (this.templateSettings != null) {
  1731. this.templateSettings.routing.rules.forEach((r, index) => {
  1732. data.push({'key': index, ...r});
  1733. });
  1734. // Make rules readable
  1735. data.forEach(r => {
  1736. if(r.domain) r.domain = r.domain.join(',')
  1737. if(r.ip) r.ip = r.ip.join(',')
  1738. if(r.source) r.source = r.source.join(',');
  1739. if(r.user) r.user = r.user.join(',')
  1740. if(r.inboundTag) r.inboundTag = r.inboundTag.join(',')
  1741. if(r.protocol) r.protocol = r.protocol.join(',')
  1742. if(r.attrs) r.attrs = JSON.stringify(r.attrs, null, 2)
  1743. });
  1744. }
  1745. return data;
  1746. }
  1747. },
  1748. balancersData: {
  1749. get: function () {
  1750. data = []
  1751. if (this.templateSettings != null && this.templateSettings.routing != null && this.templateSettings.routing.balancers != null) {
  1752. this.templateSettings.routing.balancers.forEach((o, index) => {
  1753. data.push({
  1754. 'key': index,
  1755. 'tag': o.tag ? o.tag : "",
  1756. 'strategy': o.strategy?.type ?? "random",
  1757. 'selector': o.selector ? o.selector : [],
  1758. 'fallbackTag': o.fallbackTag?? '',
  1759. });
  1760. });
  1761. }
  1762. return data;
  1763. }
  1764. },
  1765. observatory: {
  1766. get: function () {
  1767. return this.templateSettings?.observatory ? JSON.stringify(this.templateSettings.observatory, null, 2) : null;
  1768. },
  1769. set: function (newValue) {
  1770. newTemplateSettings = this.templateSettings;
  1771. newTemplateSettings.observatory = JSON.parse(newValue);
  1772. this.templateSettings = newTemplateSettings;
  1773. },
  1774. },
  1775. burstObservatory: {
  1776. get: function () {
  1777. return this.templateSettings?.burstObservatory ? JSON.stringify(this.templateSettings.burstObservatory, null, 2) : null;
  1778. },
  1779. set: function (newValue) {
  1780. newTemplateSettings = this.templateSettings;
  1781. newTemplateSettings.burstObservatory = JSON.parse(newValue);
  1782. this.templateSettings = newTemplateSettings;
  1783. },
  1784. },
  1785. observatoryEnable: function () { return this.templateSettings != null && this.templateSettings.observatory != undefined },
  1786. burstObservatoryEnable: function () { return this.templateSettings != null && this.templateSettings.burstObservatory != undefined },
  1787. freedomStrategy: {
  1788. get: function () {
  1789. if (!this.templateSettings) return "AsIs";
  1790. freedomOutbound = this.templateSettings.outbounds.find((o) => o.protocol === "freedom" && o.tag == "direct");
  1791. if (!freedomOutbound) return "AsIs";
  1792. if (!freedomOutbound.settings || !freedomOutbound.settings.domainStrategy) return "AsIs";
  1793. return freedomOutbound.settings.domainStrategy;
  1794. },
  1795. set: function (newValue) {
  1796. newTemplateSettings = this.templateSettings;
  1797. freedomOutboundIndex = newTemplateSettings.outbounds.findIndex((o) => o.protocol === "freedom" && o.tag == "direct");
  1798. if(freedomOutboundIndex == -1){
  1799. newTemplateSettings.outbounds.push({protocol: "freedom", tag: "direct", settings: { "domainStrategy": newValue }});
  1800. } else if (!newTemplateSettings.outbounds[freedomOutboundIndex].settings) {
  1801. newTemplateSettings.outbounds[freedomOutboundIndex].settings = {"domainStrategy": newValue};
  1802. } else {
  1803. newTemplateSettings.outbounds[freedomOutboundIndex].settings.domainStrategy = newValue;
  1804. }
  1805. this.templateSettings = newTemplateSettings;
  1806. }
  1807. },
  1808. routingStrategy: {
  1809. get: function () {
  1810. if (!this.templateSettings || !this.templateSettings.routing || !this.templateSettings.routing.domainStrategy) return "AsIs";
  1811. return this.templateSettings.routing.domainStrategy;
  1812. },
  1813. set: function (newValue) {
  1814. newTemplateSettings = this.templateSettings;
  1815. newTemplateSettings.routing.domainStrategy = newValue;
  1816. this.templateSettings = newTemplateSettings;
  1817. }
  1818. },
  1819. logLevel: {
  1820. get: function () {
  1821. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.loglevel) return "warning";
  1822. return this.templateSettings.log.loglevel;
  1823. },
  1824. set: function (newValue) {
  1825. newTemplateSettings = this.templateSettings;
  1826. newTemplateSettings.log.loglevel = newValue;
  1827. this.templateSettings = newTemplateSettings;
  1828. }
  1829. },
  1830. accessLog: {
  1831. get: function () {
  1832. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.access) return "";
  1833. return this.templateSettings.log.access;
  1834. },
  1835. set: function (newValue) {
  1836. newTemplateSettings = this.templateSettings;
  1837. newTemplateSettings.log.access = newValue;
  1838. this.templateSettings = newTemplateSettings;
  1839. }
  1840. },
  1841. errorLog: {
  1842. get: function () {
  1843. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.error) return "";
  1844. return this.templateSettings.log.error;
  1845. },
  1846. set: function (newValue) {
  1847. newTemplateSettings = this.templateSettings;
  1848. newTemplateSettings.log.error = newValue;
  1849. this.templateSettings = newTemplateSettings;
  1850. }
  1851. },
  1852. dnslog: {
  1853. get: function () {
  1854. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.dnsLog) return false;
  1855. return this.templateSettings.log.dnsLog;
  1856. },
  1857. set: function (newValue) {
  1858. newTemplateSettings = this.templateSettings;
  1859. newTemplateSettings.log.dnsLog = newValue;
  1860. this.templateSettings = newTemplateSettings;
  1861. }
  1862. },
  1863. outboundTraffic: {
  1864. get: function () {
  1865. if (!this.templateSettings || !this.templateSettings.policy.system || !this.templateSettings.policy.system.statsOutboundDownlink) return false;
  1866. return this.templateSettings.policy.system.statsOutboundDownlink;
  1867. },
  1868. set: function (newValue) {
  1869. newTemplateSettings = this.templateSettings;
  1870. newTemplateSettings.policy.system.statsOutboundDownlink = newValue;
  1871. newTemplateSettings.policy.system.statsOutboundUplink = newValue;
  1872. this.templateSettings = newTemplateSettings;
  1873. }
  1874. },
  1875. maskAddressLog: {
  1876. get: function () {
  1877. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.maskAddress) return "";
  1878. return this.templateSettings.log.maskAddress;
  1879. },
  1880. set: function (newValue) {
  1881. newTemplateSettings = this.templateSettings;
  1882. newTemplateSettings.log.maskAddress = newValue;
  1883. this.templateSettings = newTemplateSettings;
  1884. }
  1885. },
  1886. blockedIPs: {
  1887. get: function () {
  1888. return this.templateRuleGetter({ outboundTag: "blocked", property: "ip" });
  1889. },
  1890. set: function (newValue) {
  1891. this.templateRuleSetter({ outboundTag: "blocked", property: "ip", data: newValue });
  1892. }
  1893. },
  1894. blockedDomains: {
  1895. get: function () {
  1896. return this.templateRuleGetter({ outboundTag: "blocked", property: "domain" });
  1897. },
  1898. set: function (newValue) {
  1899. this.templateRuleSetter({ outboundTag: "blocked", property: "domain", data: newValue });
  1900. }
  1901. },
  1902. blockedProtocols: {
  1903. get: function () {
  1904. return this.templateRuleGetter({ outboundTag: "blocked", property: "protocol" });
  1905. },
  1906. set: function (newValue) {
  1907. this.templateRuleSetter({ outboundTag: "blocked", property: "protocol", data: newValue });
  1908. }
  1909. },
  1910. directIPs: {
  1911. get: function () {
  1912. return this.templateRuleGetter({ outboundTag: "direct", property: "ip" });
  1913. },
  1914. set: function (newValue) {
  1915. this.templateRuleSetter({ outboundTag: "direct", property: "ip", data: newValue });
  1916. this.syncRulesWithOutbound("direct", this.directSettings);
  1917. }
  1918. },
  1919. directDomains: {
  1920. get: function () {
  1921. return this.templateRuleGetter({ outboundTag: "direct", property: "domain" });
  1922. },
  1923. set: function (newValue) {
  1924. this.templateRuleSetter({ outboundTag: "direct", property: "domain", data: newValue });
  1925. this.syncRulesWithOutbound("direct", this.directSettings);
  1926. }
  1927. },
  1928. ipv4Domains: {
  1929. get: function () {
  1930. return this.templateRuleGetter({ outboundTag: "IPv4", property: "domain" });
  1931. },
  1932. set: function (newValue) {
  1933. this.templateRuleSetter({ outboundTag: "IPv4", property: "domain", data: newValue });
  1934. this.syncRulesWithOutbound("IPv4", this.ipv4Settings);
  1935. }
  1936. },
  1937. warpDomains: {
  1938. get: function () {
  1939. return this.templateRuleGetter({ outboundTag: "warp", property: "domain" });
  1940. },
  1941. set: function (newValue) {
  1942. this.templateRuleSetter({ outboundTag: "warp", property: "domain", data: newValue });
  1943. }
  1944. },
  1945. torrentSettings: {
  1946. get: function () {
  1947. return doAllItemsExist(this.settingsData.protocols.bittorrent, this.blockedProtocols);
  1948. },
  1949. set: function (newValue) {
  1950. if (newValue) {
  1951. this.blockedProtocols = [...this.blockedProtocols, ...this.settingsData.protocols.bittorrent];
  1952. } else {
  1953. this.blockedProtocols = this.blockedProtocols.filter(data => !this.settingsData.protocols.bittorrent.includes(data));
  1954. }
  1955. },
  1956. },
  1957. familyProtectSettings: {
  1958. get: function () {
  1959. if (!this.templateSettings || !this.templateSettings.dns || !this.templateSettings.dns.servers) return false;
  1960. return doAllItemsExist(this.settingsData.familyProtectDNS.servers, this.templateSettings.dns.servers);
  1961. },
  1962. set: function (newValue) {
  1963. newTemplateSettings = this.templateSettings;
  1964. if (newValue) {
  1965. newTemplateSettings.dns = this.settingsData.familyProtectDNS;
  1966. } else {
  1967. newTemplateSettings.dns.servers = newTemplateSettings.dns?.servers?.filter(data => !this.settingsData.familyProtectDNS.servers.includes(data))
  1968. }
  1969. this.templateSettings = newTemplateSettings;
  1970. },
  1971. },
  1972. WarpExist: {
  1973. get: function() {
  1974. return this.templateSettings ? this.templateSettings.outbounds.findIndex((o) => o.tag == "warp")>=0 : false;
  1975. },
  1976. },
  1977. enableDNS: {
  1978. get: function () {
  1979. return this.templateSettings ? this.templateSettings.dns != null : false;
  1980. },
  1981. set: function (newValue) {
  1982. newTemplateSettings = this.templateSettings;
  1983. if (newValue) {
  1984. newTemplateSettings.dns = {
  1985. servers: [],
  1986. queryStrategy: "UseIP",
  1987. tag: "dns_inbound"
  1988. };
  1989. newTemplateSettings.fakedns = null;
  1990. } else {
  1991. delete newTemplateSettings.dns;
  1992. delete newTemplateSettings.fakedns;
  1993. }
  1994. this.templateSettings = newTemplateSettings;
  1995. }
  1996. },
  1997. dnsTag: {
  1998. get: function () {
  1999. return this.enableDNS ? this.templateSettings.dns.tag : "";
  2000. },
  2001. set: function (newValue) {
  2002. newTemplateSettings = this.templateSettings;
  2003. newTemplateSettings.dns.tag = newValue;
  2004. this.templateSettings = newTemplateSettings;
  2005. }
  2006. },
  2007. dnsClientIp: {
  2008. get: function () {
  2009. return this.enableDNS ? this.templateSettings.dns.clientIp : null;
  2010. },
  2011. set: function (newValue) {
  2012. newTemplateSettings = this.templateSettings;
  2013. if (newValue) {
  2014. newTemplateSettings.dns.clientIp = newValue;
  2015. } else {
  2016. delete newTemplateSettings.dns.clientIp;
  2017. }
  2018. this.templateSettings = newTemplateSettings;
  2019. }
  2020. },
  2021. dnsDisableCache: {
  2022. get: function () {
  2023. return this.enableDNS ? this.templateSettings.dns.disableCache : false;
  2024. },
  2025. set: function (newValue) {
  2026. newTemplateSettings = this.templateSettings;
  2027. if (newValue) {
  2028. newTemplateSettings.dns.disableCache = newValue;
  2029. } else {
  2030. delete newTemplateSettings.dns.disableCache
  2031. }
  2032. this.templateSettings = newTemplateSettings;
  2033. }
  2034. },
  2035. dnsDisableFallback: {
  2036. get: function () {
  2037. return this.enableDNS ? this.templateSettings.dns.disableFallback : false;
  2038. },
  2039. set: function (newValue) {
  2040. newTemplateSettings = this.templateSettings;
  2041. if (newValue) {
  2042. newTemplateSettings.dns.disableFallback = newValue;
  2043. } else {
  2044. delete newTemplateSettings.dns.disableFallback
  2045. }
  2046. this.templateSettings = newTemplateSettings;
  2047. }
  2048. },
  2049. dnsDisableFallbackIfMatch: {
  2050. get: function () {
  2051. return this.enableDNS ? this.templateSettings.dns.disableFallbackIfMatch : false;
  2052. },
  2053. set: function (newValue) {
  2054. newTemplateSettings = this.templateSettings;
  2055. if (newValue) {
  2056. newTemplateSettings.dns.disableFallbackIfMatch = newValue;
  2057. } else {
  2058. delete newTemplateSettings.dns.disableFallbackIfMatch
  2059. }
  2060. this.templateSettings = newTemplateSettings;
  2061. }
  2062. },
  2063. dnsStrategy: {
  2064. get: function () {
  2065. return this.enableDNS ? this.templateSettings.dns.queryStrategy : null;
  2066. },
  2067. set: function (newValue) {
  2068. newTemplateSettings = this.templateSettings;
  2069. newTemplateSettings.dns.queryStrategy = newValue;
  2070. this.templateSettings = newTemplateSettings;
  2071. }
  2072. },
  2073. dnsServers: {
  2074. get: function () { return this.enableDNS ? this.templateSettings.dns.servers : []; },
  2075. set: function (newValue) {
  2076. newTemplateSettings = this.templateSettings;
  2077. newTemplateSettings.dns.servers = newValue;
  2078. this.templateSettings = newTemplateSettings;
  2079. }
  2080. },
  2081. fakeDns: {
  2082. get: function () { return this.templateSettings && this.templateSettings.fakedns ? this.templateSettings.fakedns : []; },
  2083. set: function (newValue) {
  2084. newTemplateSettings = this.templateSettings;
  2085. if (this.enableDNS) {
  2086. newTemplateSettings.fakedns = newValue.length > 0 ? newValue : null;
  2087. } else {
  2088. delete newTemplateSettings.fakedns;
  2089. }
  2090. this.templateSettings = newTemplateSettings;
  2091. }
  2092. }
  2093. },
  2094. });
  2095. </script>
  2096. </body>
  2097. </html>