xray.html 114 KB

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