xray.html 110 KB

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