xray.html 114 KB

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