xray.html 99 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. {{template "head" .}}
  4. <link rel="stylesheet" href="{{ .base_path }}assets/codemirror/codemirror.css">
  5. <link rel="stylesheet" href="{{ .base_path }}assets/codemirror/fold/foldgutter.css">
  6. <link rel="stylesheet" href="{{ .base_path }}assets/codemirror/xq.css?{{ .cur_ver }}">
  7. <link rel="stylesheet" href="{{ .base_path }}assets/codemirror/lint/lint.css">
  8. <script src="{{ .base_path }}assets/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.js"></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. </style>
  54. <body>
  55. <a-layout id="app" v-cloak :class="themeSwitcher.currentTheme">
  56. {{ template "commonSider" . }}
  57. <a-layout id="content-layout">
  58. <a-layout-content>
  59. <a-spin :spinning="spinning" :delay="500" tip='{{ i18n "loading"}}'>
  60. <a-space direction="vertical">
  61. <a-card hoverable style="margin-bottom: .5rem;">
  62. <a-row>
  63. <a-col :xs="24" :sm="8" style="padding: 4px;">
  64. <a-space direction="horizontal">
  65. <a-button type="primary" :disabled="saveBtnDisable" @click="updateXraySetting">{{ i18n "pages.xray.save" }}</a-button>
  66. <a-button type="danger" :disabled="!saveBtnDisable" @click="restartXray">{{ i18n "pages.xray.restart" }}</a-button>
  67. <a-popover v-if="restartResult"
  68. :overlay-class-name="themeSwitcher.currentTheme">
  69. <span slot="title" style="font-size: 12pt">Error in running xray-core</span>
  70. <template slot="content">
  71. <p style="max-width: 400px" v-for="line in restartResult.split('\n')">[[ line ]]</p>
  72. </template>
  73. <a-icon type="question-circle"></a-icon>
  74. </a-popover>
  75. </a-space>
  76. </a-col>
  77. <a-col :xs="24" :sm="16">
  78. <template>
  79. <div>
  80. <a-back-top :target="() => document.getElementById('content-layout')" visibility-height="200">
  81. </a-back-top>
  82. <a-alert type="warning" style="float: right; width: fit-content"
  83. message='{{ i18n "pages.settings.infoDesc" }}'
  84. show-icon
  85. >
  86. </div>
  87. </template>
  88. </a-col>
  89. </a-row>
  90. </a-card>
  91. <a-tabs class="ant-card-dark-box-nohover" default-active-key="tpl-1"
  92. @change="(activeKey) => { if(activeKey == 'tpl-advanced') this.changeCode(); }"
  93. :class="themeSwitcher.currentTheme">
  94. <a-tab-pane key="tpl-1" tab='{{ i18n "pages.xray.basicTemplate"}}'>
  95. <a-space direction="horizontal" style="padding: 20px 20px">
  96. <a-button type="primary" @click="resetXrayConfigToDefault">{{ i18n "pages.settings.resetDefaultConfig" }}</a-button>
  97. </a-space>
  98. <a-collapse>
  99. <a-collapse-panel header='{{ i18n "pages.xray.generalConfigs"}}'>
  100. <a-row :xs="24" :sm="24" :lg="12">
  101. <a-alert type="warning" style="text-align: center;">
  102. <template slot="message">
  103. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  104. {{ i18n "pages.xray.generalConfigsDesc" }}
  105. </template>
  106. </a-alert>
  107. </a-row>
  108. <a-list-item>
  109. <a-row style="padding: 20px">
  110. <a-col :lg="24" :xl="12">
  111. <a-list-item-meta
  112. title='{{ i18n "pages.xray.FreedomStrategy" }}'
  113. description='{{ i18n "pages.xray.FreedomStrategyDesc" }}'/>
  114. </a-col>
  115. <a-col :lg="24" :xl="12">
  116. <template>
  117. <a-select
  118. v-model="freedomStrategy"
  119. :dropdown-class-name="themeSwitcher.currentTheme"
  120. 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-col>
  125. </a-row>
  126. </a-list-item>
  127. <a-row style="padding: 20px">
  128. <a-col :lg="24" :xl="12">
  129. <a-list-item-meta
  130. title='{{ i18n "pages.xray.RoutingStrategy" }}'
  131. description='{{ i18n "pages.xray.RoutingStrategyDesc" }}'/>
  132. </a-col>
  133. <a-col :lg="24" :xl="12">
  134. <template>
  135. <a-select
  136. v-model="routingStrategy"
  137. :dropdown-class-name="themeSwitcher.currentTheme"
  138. style="width: 100%">
  139. <a-select-option v-for="s in routingDomainStrategies" :value="s">[[ s ]]</a-select-option>
  140. </a-select>
  141. </template>
  142. </a-col>
  143. </a-row>
  144. <a-row style="padding: 20px">
  145. <a-col :lg="24" :xl="12">
  146. <a-list-item-meta
  147. title='{{ i18n "pages.xray.logLevel" }}'
  148. description='{{ i18n "pages.xray.logLevelDesc" }}'/>
  149. </a-col>
  150. <a-col :lg="24" :xl="12">
  151. <template>
  152. <a-select
  153. v-model="setLogLevel"
  154. :dropdown-class-name="themeSwitcher.currentTheme"
  155. style="width: 100%">
  156. <a-select-option v-for="s in logLevel" :value="s">[[ s ]]</a-select-option>
  157. </a-select>
  158. </template>
  159. </a-col>
  160. </a-row>
  161. <a-row style="padding: 20px">
  162. <a-col :lg="24" :xl="12">
  163. <a-list-item-meta
  164. title='{{ i18n "pages.xray.accessLog" }}'
  165. description='{{ i18n "pages.xray.accessLogDesc" }}'/>
  166. </a-col>
  167. <a-col :lg="24" :xl="12">
  168. <template>
  169. <a-select
  170. v-model="setAccessLog"
  171. :dropdown-class-name="themeSwitcher.currentTheme"
  172. style="width: 100%">
  173. <a-select-option v-for="s in access" :value="s">[[ s ]]</a-select-option>
  174. </a-select>
  175. </template>
  176. </a-col>
  177. </a-row>
  178. </a-list-item>
  179. </a-collapse-panel>
  180. <a-collapse-panel header='{{ i18n "pages.xray.blockConfigs"}}'>
  181. <a-row :xs="24" :sm="24" :lg="12">
  182. <a-alert type="warning" style="text-align: center;">
  183. <template slot="message">
  184. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  185. {{ i18n "pages.xray.blockConfigsDesc" }}
  186. </template>
  187. </a-alert>
  188. </a-row>
  189. <setting-list-item type="switch" title='{{ i18n "pages.xray.Torrent"}}' desc='{{ i18n "pages.xray.TorrentDesc"}}' v-model="torrentSettings"></setting-list-item>
  190. <setting-list-item type="switch" title='{{ i18n "pages.xray.PrivateIp"}}' desc='{{ i18n "pages.xray.PrivateIpDesc"}}' v-model="privateIpSettings"></setting-list-item>
  191. <setting-list-item type="switch" title='{{ i18n "pages.xray.Ads"}}' desc='{{ i18n "pages.xray.AdsDesc"}}' v-model="AdsSettings"></setting-list-item>
  192. <setting-list-item type="switch" title='{{ i18n "pages.xray.Family"}}' desc='{{ i18n "pages.xray.FamilyDesc"}}' v-model="familyProtectSettings"></setting-list-item>
  193. <setting-list-item type="switch" title='{{ i18n "pages.xray.Security"}}' desc='{{ i18n "pages.xray.SecurityDesc"}}' v-model="SecuritySettings"></setting-list-item>
  194. <setting-list-item type="switch" title='{{ i18n "pages.xray.Speedtest"}}' desc='{{ i18n "pages.xray.SpeedtestDesc"}}' v-model="SpeedTestSettings"></setting-list-item>
  195. </a-collapse-panel>
  196. <a-collapse-panel header='{{ i18n "pages.xray.blockCountryConfigs"}}'>
  197. <a-row :xs="24" :sm="24" :lg="12">
  198. <a-alert type="warning" style="text-align: center;">
  199. <template slot="message">
  200. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  201. {{ i18n "pages.xray.blockCountryConfigsDesc" }}
  202. </template>
  203. </a-alert>
  204. </a-row>
  205. <setting-list-item type="switch" title='{{ i18n "pages.xray.IRIp"}}' desc='{{ i18n "pages.xray.IRIpDesc"}}' v-model="IRIpSettings"></setting-list-item>
  206. <setting-list-item type="switch" title='{{ i18n "pages.xray.IRDomain"}}' desc='{{ i18n "pages.xray.IRDomainDesc"}}' v-model="IRDomainSettings"></setting-list-item>
  207. <setting-list-item type="switch" title='{{ i18n "pages.xray.ChinaIp"}}' desc='{{ i18n "pages.xray.ChinaIpDesc"}}' v-model="ChinaIpSettings"></setting-list-item>
  208. <setting-list-item type="switch" title='{{ i18n "pages.xray.ChinaDomain"}}' desc='{{ i18n "pages.xray.ChinaDomainDesc"}}' v-model="ChinaDomainSettings"></setting-list-item>
  209. <setting-list-item type="switch" title='{{ i18n "pages.xray.RussiaIp"}}' desc='{{ i18n "pages.xray.RussiaIpDesc"}}' v-model="RussiaIpSettings"></setting-list-item>
  210. <setting-list-item type="switch" title='{{ i18n "pages.xray.RussiaDomain"}}' desc='{{ i18n "pages.xray.RussiaDomainDesc"}}' v-model="RussiaDomainSettings"></setting-list-item>
  211. <setting-list-item type="switch" title='{{ i18n "pages.xray.VNIp"}}' desc='{{ i18n "pages.xray.VNIpDesc"}}' v-model="VNIpSettings"></setting-list-item>
  212. <setting-list-item type="switch" title='{{ i18n "pages.xray.VNDomain"}}' desc='{{ i18n "pages.xray.VNDomainDesc"}}' v-model="VNDomainSettings"></setting-list-item>
  213. </a-collapse-panel>
  214. <a-collapse-panel header='{{ i18n "pages.xray.directCountryConfigs"}}'>
  215. <a-row :xs="24" :sm="24" :lg="12">
  216. <a-alert type="warning" style="text-align: center;">
  217. <template slot="message">
  218. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  219. {{ i18n "pages.xray.directCountryConfigsDesc" }}
  220. </template>
  221. </a-alert>
  222. </a-row>
  223. <setting-list-item type="switch" title='{{ i18n "pages.xray.DirectIRIp"}}' desc='{{ i18n "pages.xray.DirectIRIpDesc"}}' v-model="IRIpDirectSettings"></setting-list-item>
  224. <setting-list-item type="switch" title='{{ i18n "pages.xray.DirectIRDomain"}}' desc='{{ i18n "pages.xray.DirectIRDomainDesc"}}' v-model="IRDomainDirectSettings"></setting-list-item>
  225. <setting-list-item type="switch" title='{{ i18n "pages.xray.DirectChinaIp"}}' desc='{{ i18n "pages.xray.DirectChinaIpDesc"}}' v-model="ChinaIpDirectSettings"></setting-list-item>
  226. <setting-list-item type="switch" title='{{ i18n "pages.xray.DirectChinaDomain"}}' desc='{{ i18n "pages.xray.DirectChinaDomainDesc"}}' v-model="ChinaDomainDirectSettings"></setting-list-item>
  227. <setting-list-item type="switch" title='{{ i18n "pages.xray.DirectRussiaIp"}}' desc='{{ i18n "pages.xray.DirectRussiaIpDesc"}}' v-model="RussiaIpDirectSettings"></setting-list-item>
  228. <setting-list-item type="switch" title='{{ i18n "pages.xray.DirectRussiaDomain"}}' desc='{{ i18n "pages.xray.DirectRussiaDomainDesc"}}' v-model="RussiaDomainDirectSettings"></setting-list-item>
  229. <setting-list-item type="switch" title='{{ i18n "pages.xray.DirectVNIp"}}' desc='{{ i18n "pages.xray.DirectVNIpDesc"}}' v-model="VNIpDirectSettings"></setting-list-item>
  230. <setting-list-item type="switch" title='{{ i18n "pages.xray.DirectVNDomain"}}' desc='{{ i18n "pages.xray.DirectVNDomainDesc"}}' v-model="VNDomainDirectSettings"></setting-list-item>
  231. </a-collapse-panel>
  232. <a-collapse-panel header='{{ i18n "pages.xray.ipv4Configs"}}'>
  233. <a-row :xs="24" :sm="24" :lg="12">
  234. <a-alert type="warning" style="text-align: center;">
  235. <template slot="message">
  236. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  237. {{ i18n "pages.xray.ipv4ConfigsDesc" }}
  238. </template>
  239. </a-alert>
  240. </a-row>
  241. <setting-list-item type="switch" title='{{ i18n "pages.xray.GoogleIPv4"}}' desc='{{ i18n "pages.xray.GoogleIPv4Desc"}}' v-model="GoogleIPv4Settings"></setting-list-item>
  242. <setting-list-item type="switch" title='{{ i18n "pages.xray.NetflixIPv4"}}' desc='{{ i18n "pages.xray.NetflixIPv4Desc"}}' v-model="NetflixIPv4Settings"></setting-list-item>
  243. </a-collapse-panel>
  244. <a-collapse-panel header='{{ i18n "pages.xray.warpConfigs"}}'>
  245. <a-row :xs="24" :sm="24" :lg="12">
  246. <a-alert type="warning" style="text-align: center;">
  247. <template slot="message">
  248. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  249. {{ i18n "pages.xray.warpConfigsDesc" }}
  250. </template>
  251. </a-alert>
  252. </a-row>
  253. <template v-if="WarpExist">
  254. <setting-list-item type="switch" title='{{ i18n "pages.xray.GoogleWARP"}}' desc='{{ i18n "pages.xray.GoogleWARPDesc"}}' v-model="GoogleWARPSettings"></setting-list-item>
  255. <setting-list-item type="switch" title='{{ i18n "pages.xray.OpenAIWARP"}}' desc='{{ i18n "pages.xray.OpenAIWARPDesc"}}' v-model="OpenAIWARPSettings"></setting-list-item>
  256. <setting-list-item type="switch" title='{{ i18n "pages.xray.NetflixWARP"}}' desc='{{ i18n "pages.xray.NetflixWARPDesc"}}' v-model="NetflixWARPSettings"></setting-list-item>
  257. <setting-list-item type="switch" title='{{ i18n "pages.xray.SpotifyWARP"}}' desc='{{ i18n "pages.xray.SpotifyWARPDesc"}}' v-model="SpotifyWARPSettings"></setting-list-item>
  258. </template>
  259. <a-button v-else style="margin: 10px 0;" @click="showWarp">WARP {{ i18n "pages.xray.rules.outbound" }}</a-button>
  260. </a-collapse-panel>
  261. </a-collapse>
  262. </a-tab-pane>
  263. <a-tab-pane key="tpl-2" tab='{{ i18n "pages.xray.Routings"}}' style="padding-top: 20px;">
  264. <a-alert type="warning" style="margin-bottom: 10px; width: fit-content"
  265. message='{{ i18n "pages.xray.RoutingsDesc"}}' show-icon></a-alert>
  266. <a-button type="primary" icon="plus" @click="addRule">{{ i18n "pages.xray.rules.add" }}</a-button>
  267. <a-table :columns="isMobile ? rulesMobileColumns : rulesColumns" bordered
  268. :row-key="r => r.key"
  269. :data-source="routingRuleData"
  270. :scroll="isMobile ? {} : { x: 1000 }"
  271. :pagination="false"
  272. :indent-size="0"
  273. :style="isMobile ? 'padding: 5px 0' : 'margin-top: 10px;'">
  274. <template slot="action" slot-scope="text, rule, index">
  275. [[ index+1 ]]
  276. <a-dropdown :trigger="['click']">
  277. <a-icon @click="e => e.preventDefault()" type="more" style="font-size: 16px; text-decoration: bold;"></a-icon>
  278. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  279. <a-menu-item v-if="index>0" @click="replaceRule(index,0)">
  280. <a-icon type="vertical-align-top"></a-icon>
  281. {{ i18n "pages.xray.rules.first"}}
  282. </a-menu-item>
  283. <a-menu-item v-if="index>0" @click="replaceRule(index,index-1)">
  284. <a-icon type="arrow-up"></a-icon>
  285. {{ i18n "pages.xray.rules.up"}}
  286. </a-menu-item>
  287. <a-menu-item v-if="index<routingRuleData.length-1" @click="replaceRule(index,index+1)">
  288. <a-icon type="arrow-down"></a-icon>
  289. {{ i18n "pages.xray.rules.down"}}
  290. </a-menu-item>
  291. <a-menu-item v-if="index<routingRuleData.length-1" @click="replaceRule(index,routingRuleData.length-1)">
  292. <a-icon type="vertical-align-bottom"></a-icon>
  293. {{ i18n "pages.xray.rules.last"}}
  294. </a-menu-item>
  295. <a-menu-item @click="editRule(index)">
  296. <a-icon type="edit"></a-icon>
  297. {{ i18n "edit" }}
  298. </a-menu-item>
  299. <a-menu-item @click="deleteRule(index)">
  300. <span style="color: #FF4D4F">
  301. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  302. </span>
  303. </a-menu-item>
  304. </a-menu>
  305. </a-dropdown>
  306. </template>
  307. <template slot="inbound" slot-scope="text, rule, index">
  308. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  309. <template slot="content">
  310. <p v-if="rule.inboundTag">Inbound Tag: [[ rule.inboundTag ]]</p>
  311. <p v-if="rule.user">User email: [[ rule.user ]]</p>
  312. </template>
  313. [[ [rule.inboundTag,rule.user].join('\n') ]]
  314. </a-popover>
  315. </template>
  316. <template slot="outbound" slot-scope="text, rule, index">
  317. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  318. <template slot="content">
  319. <p v-if="rule.outboundTag">Outbound Tag: [[ rule.outboundTag ]]</p>
  320. </template>
  321. [[ rule.outboundTag ]]
  322. </a-popover>
  323. </template>
  324. <template slot="balancer" slot-scope="text, rule, index">
  325. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  326. <template slot="content">
  327. <p v-if="rule.balancerTag">Balancer Tag: [[ rule.balancerTag ]]</p>
  328. </template>
  329. [[ rule.balancerTag ]]
  330. </a-popover>
  331. </template>
  332. <template slot="info" slot-scope="text, rule, index">
  333. <a-popover placement="bottomRight"
  334. v-if="(rule.source+rule.sourcePort+rule.network+rule.protocol+rule.attrs+rule.ip+rule.domain+rule.port).length>0"
  335. :overlay-class-name="themeSwitcher.currentTheme" trigger="click">
  336. <template slot="content">
  337. <table cellpadding="2" style="max-width: 300px;">
  338. <tr v-if="rule.source">
  339. <td>Source</td>
  340. <td><a-tag color="blue" v-for="r in rule.source.split(',')">[[ r ]]</a-tag></td>
  341. </tr>
  342. <tr v-if="rule.sourcePort">
  343. <td>Source Port</td>
  344. <td><a-tag color="green" v-for="r in rule.sourcePort.split(',')">[[ r ]]</a-tag></td>
  345. </tr>
  346. <tr v-if="rule.network">
  347. <td>Network</td>
  348. <td><a-tag color="blue" v-for="r in rule.network.split(',')">[[ r ]]</a-tag></td>
  349. </tr>
  350. <tr v-if="rule.protocol">
  351. <td>Protocol</td>
  352. <td><a-tag color="green" v-for="r in rule.protocol.split(',')">[[ r ]]</a-tag></td>
  353. </tr>
  354. <tr v-if="rule.attrs">
  355. <td>Attrs</td>
  356. <td><a-tag color="blue" v-for="r in rule.attrs.split(',')">[[ r ]]</a-tag></td>
  357. </tr>
  358. <tr v-if="rule.ip">
  359. <td>IP</td>
  360. <td><a-tag color="green" v-for="r in rule.ip.split(',')">[[ r ]]</a-tag></td>
  361. </tr>
  362. <tr v-if="rule.domain">
  363. <td>Domain</td>
  364. <td><a-tag color="blue" v-for="r in rule.domain.split(',')">[[ r ]]</a-tag></td>
  365. </tr>
  366. <tr v-if="rule.port">
  367. <td>Port</td>
  368. <td><a-tag color="green" v-for="r in rule.port.split(',')">[[ r ]]</a-tag></td>
  369. </tr>
  370. </table>
  371. </template>
  372. <a-button shape="round" size="small" style="font-size: 14px; padding: 0 10px;">
  373. <a-icon type="info"></a-icon>
  374. </a-button>
  375. </a-popover>
  376. </template>
  377. </a-table>
  378. </a-tab-pane>
  379. <a-tab-pane key="tpl-3" tab='{{ i18n "pages.xray.Outbounds"}}' style="padding-top: 20px;" force-render="true">
  380. <a-row>
  381. <a-col :xs="12" :sm="12" :lg="12">
  382. <a-button type="primary" icon="plus" @click="addOutbound()" style="margin-bottom: 10px;">{{ i18n
  383. "pages.xray.outbound.addOutbound" }}</a-button>
  384. <a-button type="primary" @click="showWarp()" style="margin-bottom: 10px;">WARP</a-button>
  385. </a-col>
  386. <a-col :xs="12" :sm="12" :lg="12" style="text-align: right;">
  387. <a-icon type="sync" :spin="refreshing" @click="refreshOutboundTraffic()" style="margin: 0 5px;"></a-icon>
  388. <a-icon type="retweet" @click="resetOutboundTraffic(-1)"></a-icon>
  389. </a-col>
  390. </a-row>
  391. <a-table :columns="outboundColumns" bordered
  392. :row-key="r => r.key"
  393. :data-source="outboundData"
  394. :scroll="isMobile ? {} : { x: 200 }"
  395. :pagination="false"
  396. :indent-size="0"
  397. :style="isMobile ? 'padding: 5px 5px' : 'margin-right: 1px;'">
  398. <template slot="action" slot-scope="text, outbound, index">
  399. [[ index+1 ]]
  400. <a-dropdown :trigger="['click']">
  401. <a-icon @click="e => e.preventDefault()" type="more" style="font-size: 16px; text-decoration: bold;"></a-icon>
  402. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  403. <a-menu-item v-if="index>0" @click="setFirstOutbound(index)">
  404. <a-icon type="vertical-align-top"></a-icon>
  405. {{ i18n "pages.xray.rules.first"}}
  406. </a-menu-item>
  407. <a-menu-item @click="editOutbound(index)">
  408. <a-icon type="edit"></a-icon>
  409. {{ i18n "edit" }}
  410. </a-menu-item>
  411. <a-menu-item @click="resetOutboundTraffic(index)">
  412. <span>
  413. <a-icon type="retweet"></a-icon> {{ i18n "pages.inbounds.resetTraffic"}}
  414. </span>
  415. </a-menu-item>
  416. <a-menu-item @click="deleteOutbound(index)">
  417. <span style="color: #FF4D4F">
  418. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  419. </span>
  420. </a-menu-item>
  421. </a-menu>
  422. </a-dropdown>
  423. </template>
  424. <template slot="address" slot-scope="text, outbound, index">
  425. <p style="margin: 0 5px;" v-for="addr in findOutboundAddress(outbound)">[[ addr ]]</p>
  426. </template>
  427. <template slot="protocol" slot-scope="text, outbound, index">
  428. <a-tag style="margin:0;" color="purple">[[ outbound.protocol ]]</a-tag>
  429. <template v-if="[Protocols.VMess, Protocols.VLESS, Protocols.Trojan, Protocols.Shadowsocks].includes(outbound.protocol)">
  430. <a-tag style="margin:0;" color="blue">[[ outbound.streamSettings.network ]]</a-tag>
  431. <a-tag style="margin:0;" v-if="outbound.streamSettings.security=='tls'" color="green">tls</a-tag>
  432. <a-tag style="margin:0;" v-if="outbound.streamSettings.security=='reality'" color="green">reality</a-tag>
  433. </template>
  434. </template>
  435. <template slot="traffic" slot-scope="text, outbound, index">
  436. <a-tag color="green">[[ findOutboundTraffic(outbound) ]]</a-tag>
  437. </template>
  438. </a-table>
  439. </a-tab-pane>
  440. <a-tab-pane key="tpl-4" tab='{{ i18n "pages.xray.outbound.reverse"}}' style="padding-top: 20px;" force-render="true">
  441. <a-button type="primary" icon="plus" @click="addReverse()" style="margin-bottom: 10px;">{{ i18n "pages.xray.outbound.addReverse" }}</a-button>
  442. <a-table :columns="reverseColumns" bordered
  443. :row-key="r => r.key"
  444. :data-source="reverseData"
  445. :scroll="isMobile ? {} : { x: 200 }"
  446. :pagination="false"
  447. :indent-size="0"
  448. :style="isMobile ? 'padding: 5px 0' : 'margin-left: 1px;'">
  449. <template slot="action" slot-scope="text, reverse, index">
  450. [[ index+1 ]]
  451. <a-dropdown :trigger="['click']">
  452. <a-icon @click="e => e.preventDefault()" type="more" style="font-size: 16px; text-decoration: bold;"></a-icon>
  453. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  454. <a-menu-item @click="editReverse(index)">
  455. <a-icon type="edit"></a-icon>
  456. {{ i18n "edit" }}
  457. </a-menu-item>
  458. <a-menu-item @click="deleteReverse(index)">
  459. <span style="color: #FF4D4F">
  460. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  461. </span>
  462. </a-menu-item>
  463. </a-menu>
  464. </a-dropdown>
  465. </template>
  466. </a-table>
  467. </a-tab-pane>
  468. <a-tab-pane key="tpl-balancers" tab='{{ i18n "pages.xray.Balancers"}}' style="padding-top: 20px;" force-render="true">
  469. <a-button type="primary" icon="plus" @click="addBalancer()" style="margin-bottom: 10px;">{{ i18n "pages.xray.balancer.addBalancer"}}</a-button>
  470. <a-table :columns="balancerColumns" bordered
  471. :row-key="r => r.key"
  472. :data-source="balancersData"
  473. :scroll="isMobile ? {} : { x: 200 }"
  474. :pagination="false"
  475. :indent-size="0"
  476. :style="isMobile ? 'padding: 5px 0' : 'margin-left: 1px;'">
  477. <template slot="action" slot-scope="text, balancer, index">
  478. [[ index+1 ]]
  479. <a-dropdown :trigger="['click']">
  480. <a-icon @click="e => e.preventDefault()" type="more" style="font-size: 16px; text-decoration: bold;"></a-icon>
  481. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  482. <a-menu-item @click="editBalancer(index)">
  483. <a-icon type="edit"></a-icon>
  484. {{ i18n "edit" }}
  485. </a-menu-item>
  486. <a-menu-item @click="deleteBalancer(index)">
  487. <span style="color: #FF4D4F">
  488. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  489. </span>
  490. </a-menu-item>
  491. </a-menu>
  492. </a-dropdown>
  493. </template>
  494. <template slot="strategy" slot-scope="text, balancer, index">
  495. <a-tag style="margin:0;" v-if="balancer.strategy=='random'" color="purple">Random</a-tag>
  496. <a-tag style="margin:0;" v-if="balancer.strategy=='roundRobin'" color="green">Round Robin</a-tag>
  497. </template>
  498. <template slot="selector" slot-scope="text, balancer, index">
  499. <a-tag class="info-large-tag" style="margin:1;" v-for="sel in balancer.selector">[[ sel ]]</a-tag>
  500. </template>
  501. </a-table>
  502. </a-tab-pane>
  503. <a-tab-pane key="tpl-advanced" tab='{{ i18n "pages.xray.advancedTemplate"}}' style="padding-top: 20px;" force-render="true">
  504. <a-list-item-meta title='{{ i18n "pages.xray.Template"}}' description='{{ i18n "pages.xray.TemplateDesc"}}'></a-list-item-meta>
  505. <a-radio-group v-model="advSettings" @change="changeCode" button-style="solid" style="margin: 10px 0;" :size="isMobile ? 'small' : ''">
  506. <a-radio-button value="xraySetting">{{ i18n "pages.xray.completeTemplate"}}</a-radio-button>
  507. <a-radio-button value="inboundSettings">{{ i18n "pages.xray.Inbounds" }}</a-radio-button>
  508. <a-radio-button value="outboundSettings">{{ i18n "pages.xray.Outbounds" }}</a-radio-button>
  509. <a-radio-button value="routingRuleSettings">{{ i18n "pages.xray.Routings" }}</a-radio-button>
  510. </a-radio-group>
  511. <textarea style="position:absolute; left: -800px;" id="xraySetting"></textarea>
  512. </a-tab-pane>
  513. </a-tabs>
  514. </a-space>
  515. </a-spin>
  516. </a-layout-content>
  517. </a-layout>
  518. </a-layout>
  519. {{template "js" .}}
  520. {{template "component/themeSwitcher" .}}
  521. {{template "component/setting"}}
  522. {{template "ruleModal"}}
  523. {{template "outModal"}}
  524. {{template "reverseModal"}}
  525. {{template "balancerModal"}}
  526. {{template "warpModal"}}
  527. <script>
  528. const rulesColumns = [
  529. { title: "#", align: 'center', width: 15, scopedSlots: { customRender: 'action' } },
  530. { title: '{{ i18n "pages.xray.rules.source"}}', children: [
  531. { title: 'IP', dataIndex: "source", align: 'center', width: 20, ellipsis: true },
  532. { title: 'Port', dataIndex: 'sourcePort', align: 'center', width: 10, ellipsis: true } ]},
  533. { title: '{{ i18n "pages.inbounds.network"}}', children: [
  534. { title: 'L4', dataIndex: 'network', align: 'center', width: 10 },
  535. { title: 'Protocol', dataIndex: 'protocol', align: 'center', width: 10, ellipsis: true },
  536. { title: 'Attrs', dataIndex: 'attrs', align: 'center', width: 20, ellipsis: true } ]},
  537. { title: '{{ i18n "pages.xray.rules.dest"}}', children: [
  538. { title: 'IP', dataIndex: 'ip', align: 'center', width: 20, ellipsis: true },
  539. { title: 'Domain', dataIndex: 'domain', align: 'center', width: 20, ellipsis: true },
  540. { title: 'Port', dataIndex: 'port', align: 'center', width: 10, ellipsis: true }]},
  541. { title: '{{ i18n "pages.xray.rules.inbound"}}', children: [
  542. { title: 'Inbound Tag', dataIndex: 'inboundTag', align: 'center', width: 15, ellipsis: true },
  543. { title: 'Client Email', dataIndex: 'user', align: 'center', width: 20, ellipsis: true }]},
  544. { title: '{{ i18n "pages.xray.rules.outbound"}}', dataIndex: 'outboundTag', align: 'center', width: 15 },
  545. { title: '{{ i18n "pages.xray.rules.balancer"}}', dataIndex: 'balancerTag', align: 'center', width: 15 },
  546. ];
  547. const rulesMobileColumns = [
  548. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  549. { title: '{{ i18n "pages.xray.rules.inbound"}}', align: 'center', width: 50, ellipsis: true, scopedSlots: { customRender: 'inbound' } },
  550. { title: '{{ i18n "pages.xray.rules.outbound"}}', align: 'center', width: 50, ellipsis: true, scopedSlots: { customRender: 'outbound' } },
  551. { title: '{{ i18n "pages.xray.rules.info"}}', align: 'center', width: 50, ellipsis: true, scopedSlots: { customRender: 'info' } },
  552. ];
  553. const outboundColumns = [
  554. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  555. { title: '{{ i18n "pages.xray.outbound.tag"}}', dataIndex: 'tag', align: 'center', width: 50 },
  556. { title: '{{ i18n "protocol"}}', align: 'center', width: 50, scopedSlots: { customRender: 'protocol' } },
  557. { title: '{{ i18n "pages.xray.outbound.address"}}', align: 'center', width: 50, scopedSlots: { customRender: 'address' } },
  558. { title: '{{ i18n "pages.inbounds.traffic" }}', align: 'center', width: 50, scopedSlots: { customRender: 'traffic' } },
  559. ];
  560. const reverseColumns = [
  561. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  562. { title: '{{ i18n "pages.xray.outbound.type"}}', dataIndex: 'type', align: 'center', width: 50 },
  563. { title: '{{ i18n "pages.xray.outbound.tag"}}', dataIndex: 'tag', align: 'center', width: 50 },
  564. { title: '{{ i18n "pages.xray.outbound.domain"}}', dataIndex: 'domain', align: 'center', width: 50 },
  565. ];
  566. const balancerColumns = [
  567. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  568. { title: '{{ i18n "pages.xray.balancer.tag"}}', dataIndex: 'tag', align: 'center', width: 50 },
  569. { title: '{{ i18n "pages.xray.balancer.balancerStrategy"}}', align: 'center', width: 50, scopedSlots: { customRender: 'strategy' }},
  570. { title: '{{ i18n "pages.xray.balancer.balancerSelectors"}}', align: 'center', width: 100, scopedSlots: { customRender: 'selector' }},
  571. ];
  572. const app = new Vue({
  573. delimiters: ['[[', ']]'],
  574. el: '#app',
  575. data: {
  576. siderDrawer,
  577. themeSwitcher,
  578. isDarkTheme: themeSwitcher.isDarkTheme,
  579. spinning: false,
  580. oldXraySetting: '',
  581. xraySetting: '',
  582. inboundTags: [],
  583. outboundsTraffic: [],
  584. saveBtnDisable: true,
  585. refreshing: false,
  586. restartResult: '',
  587. isMobile: window.innerWidth <= 768,
  588. advSettings: 'xraySetting',
  589. cm: null,
  590. cmOptions: {
  591. lineNumbers: true,
  592. mode: "application/json",
  593. lint: true,
  594. styleActiveLine: true,
  595. matchBrackets: true,
  596. theme: "xq",
  597. autoCloseTags: true,
  598. lineWrapping: true,
  599. indentUnit: 2,
  600. indentWithTabs: true,
  601. smartIndent: true,
  602. tabSize: 2,
  603. lineWiseCopyCut: false,
  604. foldGutter: true,
  605. gutters: [
  606. "CodeMirror-lint-markers",
  607. "CodeMirror-linenumbers",
  608. "CodeMirror-foldgutter",
  609. ],
  610. },
  611. ipv4Settings: {
  612. tag: "IPv4",
  613. protocol: "freedom",
  614. settings: {
  615. domainStrategy: "UseIPv4"
  616. }
  617. },
  618. directSettings: {
  619. tag: "direct",
  620. protocol: "freedom"
  621. },
  622. routingDomainStrategies: ["AsIs", "IPIfNonMatch", "IPOnDemand"],
  623. logLevel: ["none" , "debug" , "info" , "warning", "error"],
  624. access: ["none" , "./access.log" ],
  625. settingsData: {
  626. protocols: {
  627. bittorrent: ["bittorrent"],
  628. },
  629. ips: {
  630. local: ["geoip:private"],
  631. cn: ["geoip:cn"],
  632. ir: ["ext:geoip_IR.dat:ir"],
  633. ru: ["geoip:ru"],
  634. vn: ["ext:geoip_VN.dat:vn"],
  635. },
  636. domains: {
  637. ads: [
  638. "geosite:category-ads-all",
  639. "ext:geosite_IR.dat:category-ads-all"
  640. ],
  641. security: [
  642. "ext:geosite_IR.dat:malware",
  643. "ext:geosite_IR.dat:phishing",
  644. "ext:geosite_IR.dat:cryptominers"
  645. ],
  646. speedtest: ["geosite:speedtest"],
  647. openai: ["geosite:openai"],
  648. google: ["geosite:google"],
  649. spotify: ["geosite:spotify"],
  650. netflix: ["geosite:netflix"],
  651. cn: [
  652. "geosite:cn",
  653. "regexp:.*\\.cn$"
  654. ],
  655. ru: [
  656. "geosite:category-gov-ru",
  657. "regexp:.*\\.ru$"
  658. ],
  659. ir: [
  660. "regexp:.*\\.ir$",
  661. "regexp:.*\\.xn--mgba3a4f16a$", // .ایران
  662. "ext:geosite_IR.dat:ir"
  663. ],
  664. vn: [
  665. "regexp:.*\\.vn$",
  666. "ext:geosite_VN.dat:vn",
  667. "ext:geosite_VN.dat:ads"
  668. ]
  669. },
  670. familyProtectDNS: {
  671. "servers": [
  672. "1.1.1.3", // https://developers.cloudflare.com/1.1.1.1/setup/
  673. "1.0.0.3",
  674. "2606:4700:4700::1113",
  675. "2606:4700:4700::1003"
  676. ],
  677. "queryStrategy": "UseIP"
  678. },
  679. }
  680. },
  681. methods: {
  682. loading(spinning = true) {
  683. this.spinning = spinning;
  684. },
  685. async getOutboundsTraffic() {
  686. const msg = await HttpUtil.get("/panel/xray/getOutboundsTraffic");
  687. if (msg.success) {
  688. this.outboundsTraffic = msg.obj;
  689. }
  690. },
  691. async getXraySetting() {
  692. this.loading(true);
  693. const msg = await HttpUtil.post("/panel/xray/");
  694. this.loading(false);
  695. if (msg.success) {
  696. result = JSON.parse(msg.obj);
  697. xs = JSON.stringify(result.xraySetting, null, 2);
  698. this.oldXraySetting = xs;
  699. this.xraySetting = xs;
  700. this.inboundTags = result.inboundTags;
  701. this.saveBtnDisable = true;
  702. }
  703. },
  704. async updateXraySetting() {
  705. this.loading(true);
  706. const msg = await HttpUtil.post("/panel/xray/update", {xraySetting : this.xraySetting});
  707. this.loading(false);
  708. if (msg.success) {
  709. await this.getXraySetting();
  710. }
  711. },
  712. async restartXray() {
  713. this.loading(true);
  714. const msg = await HttpUtil.post("server/restartXrayService");
  715. this.loading(false);
  716. if (msg.success) {
  717. await PromiseUtil.sleep(500);
  718. await this.getXrayResult();
  719. }
  720. this.loading(false);
  721. },
  722. async getXrayResult() {
  723. const msg = await HttpUtil.get("/panel/xray/getXrayResult");
  724. if(msg.success){
  725. this.restartResult=msg.obj;
  726. if(msg.obj.length > 1) Vue.prototype.$message.error(msg.obj);
  727. }
  728. },
  729. async fetchUserSecret() {
  730. this.loading(true);
  731. const userMessage = await HttpUtil.post("/panel/setting/getUserSecret", this.user);
  732. if (userMessage.success) {
  733. this.user = userMessage.obj;
  734. }
  735. this.loading(false);
  736. },
  737. async updateSecret() {
  738. this.loading(true);
  739. const msg = await HttpUtil.post("/panel/setting/updateUserSecret", this.user);
  740. if (msg.success) {
  741. this.user = msg.obj;
  742. window.location.replace(basePath + "logout");
  743. }
  744. this.loading(false);
  745. await this.updateXraySetting();
  746. },
  747. generateRandomString(length) {
  748. var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  749. let randomString = "";
  750. for (let i = 0; i < length; i++) {
  751. randomString += chars[Math.floor(Math.random() * chars.length)];
  752. }
  753. return randomString;
  754. },
  755. async getNewSecret() {
  756. this.loading(true);
  757. await PromiseUtil.sleep(600);
  758. const newSecret = this.generateRandomString(64);
  759. this.user.loginSecret = newSecret;
  760. document.getElementById("token").textContent = newSecret;
  761. this.loading(false);
  762. },
  763. async toggleToken(value) {
  764. if (value) {
  765. await this.getNewSecret();
  766. } else {
  767. this.user.loginSecret = "";
  768. }
  769. },
  770. async resetXrayConfigToDefault() {
  771. this.loading(true);
  772. const msg = await HttpUtil.get("/panel/setting/getDefaultJsonConfig");
  773. this.loading(false);
  774. if (msg.success) {
  775. this.templateSettings = JSON.parse(JSON.stringify(msg.obj, null, 2));
  776. this.saveBtnDisable = true;
  777. }
  778. },
  779. syncRulesWithOutbound(tag, setting) {
  780. const newTemplateSettings = this.templateSettings;
  781. const haveRules = newTemplateSettings.routing.rules.some((r) => r?.outboundTag === tag);
  782. const outboundIndex = newTemplateSettings.outbounds.findIndex((o) => o.tag === tag);
  783. if (!haveRules && outboundIndex > 0) {
  784. newTemplateSettings.outbounds.splice(outboundIndex);
  785. }
  786. if (haveRules && outboundIndex < 0) {
  787. newTemplateSettings.outbounds.push(setting);
  788. }
  789. this.templateSettings = newTemplateSettings;
  790. },
  791. templateRuleGetter(routeSettings) {
  792. const { property, outboundTag } = routeSettings;
  793. let result = [];
  794. if (this.templateSettings != null) {
  795. this.templateSettings.routing.rules.forEach(
  796. (routingRule) => {
  797. if (
  798. routingRule.hasOwnProperty(property) &&
  799. routingRule.hasOwnProperty("outboundTag") &&
  800. routingRule.outboundTag === outboundTag
  801. ) {
  802. result.push(...routingRule[property]);
  803. }
  804. }
  805. );
  806. }
  807. return result;
  808. },
  809. templateRuleSetter(routeSettings) {
  810. const { data, property, outboundTag } = routeSettings;
  811. const oldTemplateSettings = this.templateSettings;
  812. const newTemplateSettings = oldTemplateSettings;
  813. currentProperty = this.templateRuleGetter({ outboundTag, property })
  814. if (currentProperty.length == 0) {
  815. const propertyRule = {
  816. type: "field",
  817. outboundTag,
  818. [property]: data
  819. };
  820. newTemplateSettings.routing.rules.push(propertyRule);
  821. }
  822. else {
  823. const newRules = [];
  824. insertedOnce = false;
  825. newTemplateSettings.routing.rules.forEach(
  826. (routingRule) => {
  827. if (
  828. routingRule.hasOwnProperty(property) &&
  829. routingRule.hasOwnProperty("outboundTag") &&
  830. routingRule.outboundTag === outboundTag
  831. ) {
  832. if (!insertedOnce && data.length > 0) {
  833. insertedOnce = true;
  834. routingRule[property] = data;
  835. newRules.push(routingRule);
  836. }
  837. }
  838. else {
  839. newRules.push(routingRule);
  840. }
  841. }
  842. );
  843. newTemplateSettings.routing.rules = newRules;
  844. }
  845. this.templateSettings = newTemplateSettings;
  846. },
  847. changeCode() {
  848. if(this.cm != null) {
  849. this.cm.toTextArea();
  850. }
  851. textAreaObj = document.getElementById('xraySetting');
  852. textAreaObj.value = this[this.advSettings];
  853. this.cm = CodeMirror.fromTextArea(textAreaObj, this.cmOptions);
  854. this.cm.on('change',editor => {
  855. value = editor.getValue();
  856. if(this.isJsonString(value)){
  857. this[this.advSettings] = value;
  858. }
  859. });
  860. },
  861. isJsonString(str) {
  862. try {
  863. JSON.parse(str);
  864. } catch (e) {
  865. return false;
  866. }
  867. return true;
  868. },
  869. findOutboundTraffic(o) {
  870. for (const otraffic of this.outboundsTraffic) {
  871. if (otraffic.tag == o.tag) {
  872. return sizeFormat(otraffic.up) + ' / ' + sizeFormat(otraffic.down);
  873. }
  874. }
  875. return sizeFormat(0) + ' / ' + sizeFormat(0);
  876. },
  877. findOutboundAddress(o) {
  878. serverObj = null;
  879. switch(o.protocol){
  880. case Protocols.VMess:
  881. case Protocols.VLESS:
  882. serverObj = o.settings.vnext;
  883. break;
  884. case Protocols.HTTP:
  885. case Protocols.Socks:
  886. case Protocols.Shadowsocks:
  887. case Protocols.Trojan:
  888. serverObj = o.settings.servers;
  889. break;
  890. case Protocols.DNS:
  891. return [o.settings.address + ':' + o.settings.port];
  892. case Protocols.Wireguard:
  893. return o.settings.peers.map(peer => peer.endpoint);
  894. default:
  895. return null;
  896. }
  897. return serverObj ? serverObj.map(obj => obj.address + ':' + obj.port) : null;
  898. },
  899. addOutbound(){
  900. outModal.show({
  901. title: '{{ i18n "pages.xray.outbound.addOutbound"}}',
  902. okText: '{{ i18n "pages.xray.outbound.addOutbound" }}',
  903. confirm: (outbound) => {
  904. outModal.loading();
  905. if(outbound.tag.length > 0){
  906. this.templateSettings.outbounds.push(outbound);
  907. this.outboundSettings = JSON.stringify(this.templateSettings.outbounds);
  908. }
  909. outModal.close();
  910. },
  911. isEdit: false,
  912. tags: this.templateSettings.outbounds.map(obj => obj.tag)
  913. });
  914. },
  915. editOutbound(index){
  916. outModal.show({
  917. title: '{{ i18n "pages.xray.outbound.editOutbound"}} ' + (index+1),
  918. outbound: app.templateSettings.outbounds[index],
  919. confirm: (outbound) => {
  920. outModal.loading();
  921. this.templateSettings.outbounds[index] = outbound;
  922. this.outboundSettings = JSON.stringify(this.templateSettings.outbounds);
  923. outModal.close();
  924. },
  925. isEdit: true,
  926. tags: this.outboundData.filter((o) => o.key != index ).map(obj => obj.tag)
  927. });
  928. },
  929. deleteOutbound(index){
  930. outbounds = this.templateSettings.outbounds;
  931. outbounds.splice(index,1);
  932. this.outboundSettings = JSON.stringify(outbounds);
  933. },
  934. setFirstOutbound(index){
  935. outbounds = this.templateSettings.outbounds;
  936. outbounds.splice(0, 0, outbounds.splice(index, 1)[0]);
  937. this.outboundSettings = JSON.stringify(outbounds);
  938. },
  939. async refreshOutboundTraffic() {
  940. if (!this.refreshing) {
  941. this.refreshing = true;
  942. await this.getOutboundsTraffic();
  943. data = []
  944. if (this.templateSettings != null) {
  945. this.templateSettings.outbounds.forEach((o, index) => {
  946. data.push({'key': index, ...o});
  947. });
  948. }
  949. this.outboundData = data;
  950. this.refreshing = false;
  951. }
  952. },
  953. async resetOutboundTraffic(index) {
  954. let tag = "-alltags-";
  955. if (index >= 0) {
  956. tag = this.outboundData[index].tag ? this.outboundData[index].tag : ""
  957. }
  958. const msg = await HttpUtil.post("/panel/xray/resetOutboundsTraffic", { tag: tag });
  959. if (msg.success) {
  960. await this.refreshOutboundTraffic();
  961. }
  962. },
  963. addBalancer() {
  964. balancerModal.show({
  965. title: '{{ i18n "pages.xray.balancer.addBalancer"}}',
  966. okText: '{{ i18n "pages.xray.balancer.addBalancer"}}',
  967. balancerTags: this.balancersData.filter((o) => !ObjectUtil.isEmpty(o.tag)).map(obj => obj.tag),
  968. balancer: {
  969. tag: '',
  970. strategy: 'random',
  971. selector: []
  972. },
  973. confirm: (balancer) => {
  974. balancerModal.loading();
  975. newTemplateSettings = this.templateSettings;
  976. if (newTemplateSettings.routing.balancers == undefined) {
  977. newTemplateSettings.routing.balancers = [];
  978. }
  979. let tmpBalancer = {
  980. 'tag': balancer.tag,
  981. 'selector': balancer.selector
  982. };
  983. if (balancer.strategy == 'roundRobin') {
  984. tmpBalancer.strategy = {
  985. 'type': balancer.strategy
  986. };
  987. }
  988. newTemplateSettings.routing.balancers.push(tmpBalancer);
  989. this.templateSettings = newTemplateSettings;
  990. balancerModal.close();
  991. },
  992. isEdit: false
  993. });
  994. },
  995. editBalancer(index) {
  996. const oldTag = this.balancersData[index].tag;
  997. balancerModal.show({
  998. title: '{{ i18n "pages.xray.balancer.editBalancer"}}',
  999. okText: '{{ i18n "sure" }}',
  1000. balancerTags: this.balancersData.filter((o) => !ObjectUtil.isEmpty(o.tag)).map(obj => obj.tag),
  1001. balancer: this.balancersData[index],
  1002. confirm: (balancer) => {
  1003. balancerModal.loading();
  1004. newTemplateSettings = this.templateSettings;
  1005. let tmpBalancer = {
  1006. 'tag': balancer.tag,
  1007. 'selector': balancer.selector
  1008. };
  1009. if (balancer.strategy == 'roundRobin') {
  1010. tmpBalancer.strategy = {
  1011. 'type': balancer.strategy
  1012. };
  1013. }
  1014. newTemplateSettings.routing.balancers[index] = tmpBalancer;
  1015. // change edited tag if used in rule section
  1016. if (oldTag != balancer.tag) {
  1017. newTemplateSettings.routing.rules.forEach((rule) => {
  1018. if (rule.balancerTag && rule.balancerTag == oldTag) {
  1019. rule.balancerTag = balancer.tag;
  1020. }
  1021. });
  1022. }
  1023. this.templateSettings = newTemplateSettings;
  1024. balancerModal.close();
  1025. },
  1026. isEdit: true
  1027. });
  1028. },
  1029. deleteBalancer(index) {
  1030. newTemplateSettings = this.templateSettings;
  1031. //remove from balancers
  1032. const oldTag = this.balancersData[index].tag;
  1033. this.balancersData.splice(index, 1);
  1034. // remove from settings
  1035. let realIndex = newTemplateSettings.routing.balancers.findIndex((b) => b.tag == oldTag);
  1036. newTemplateSettings.routing.balancers.splice(realIndex, 1);
  1037. // remove related routing rules
  1038. let rules = [];
  1039. newTemplateSettings.routing.rules.forEach((r) => {
  1040. if (!r.balancerTag || r.balancerTag != oldTag) {
  1041. rules.push(r);
  1042. }
  1043. });
  1044. newTemplateSettings.routing.rules = rules;
  1045. this.templateSettings = newTemplateSettings;
  1046. },
  1047. addReverse(){
  1048. reverseModal.show({
  1049. title: '{{ i18n "pages.xray.outbound.addReverse"}}',
  1050. okText: '{{ i18n "pages.xray.outbound.addReverse" }}',
  1051. confirm: (reverse, rules) => {
  1052. reverseModal.loading();
  1053. if(reverse.tag.length > 0){
  1054. newTemplateSettings = this.templateSettings;
  1055. if(newTemplateSettings.reverse == undefined) newTemplateSettings.reverse = {};
  1056. if(newTemplateSettings.reverse[reverse.type+'s'] == undefined) newTemplateSettings.reverse[reverse.type+'s'] = [];
  1057. newTemplateSettings.reverse[reverse.type+'s'].push({ tag: reverse.tag, domain: reverse.domain });
  1058. this.templateSettings = newTemplateSettings;
  1059. // Add related rules
  1060. this.templateSettings.routing.rules.push(...rules);
  1061. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  1062. }
  1063. reverseModal.close();
  1064. },
  1065. isEdit: false
  1066. });
  1067. },
  1068. editReverse(index){
  1069. if(this.reverseData[index].type == "bridge") {
  1070. oldRules = this.templateSettings.routing.rules.filter(r => r.inboundTag && r.inboundTag[0] == this.reverseData[index].tag);
  1071. } else {
  1072. oldRules = this.templateSettings.routing.rules.filter(r => r.outboundTag && r.outboundTag == this.reverseData[index].tag);
  1073. }
  1074. reverseModal.show({
  1075. title: '{{ i18n "pages.xray.outbound.editReverse"}} ' + (index+1),
  1076. reverse: this.reverseData[index],
  1077. rules: oldRules,
  1078. confirm: (reverse, rules) => {
  1079. reverseModal.loading();
  1080. if(reverse.tag.length > 0){
  1081. oldData = this.reverseData[index];
  1082. newTemplateSettings = this.templateSettings;
  1083. oldReverseIndex = newTemplateSettings.reverse[oldData.type+'s'].findIndex(rs => rs.tag == oldData.tag);
  1084. oldRuleIndex0 = oldRules.length>0 ? newTemplateSettings.routing.rules.findIndex(r => JSON.stringify(r) == JSON.stringify(oldRules[0])) : -1;
  1085. oldRuleIndex1 = oldRules.length==2 ? newTemplateSettings.routing.rules.findIndex(r => JSON.stringify(r) == JSON.stringify(oldRules[1])) : -1;
  1086. if(oldData.type == reverse.type){
  1087. newTemplateSettings.reverse[oldData.type + 's'][oldReverseIndex] = { tag: reverse.tag, domain: reverse.domain };
  1088. } else {
  1089. newTemplateSettings.reverse[oldData.type+'s'].splice(oldReverseIndex,1);
  1090. // delete empty object
  1091. if(newTemplateSettings.reverse[oldData.type+'s'].length == 0) Reflect.deleteProperty(newTemplateSettings.reverse, oldData.type+'s');
  1092. // add other type of reverse if it is not exist
  1093. if(!newTemplateSettings.reverse[reverse.type+'s']) newTemplateSettings.reverse[reverse.type+'s'] = [];
  1094. newTemplateSettings.reverse[reverse.type+'s'].push({ tag: reverse.tag, domain: reverse.domain });
  1095. }
  1096. this.templateSettings = newTemplateSettings;
  1097. // Adjust Rules
  1098. newRules = this.templateSettings.routing.rules;
  1099. oldRuleIndex0 != -1 ? newRules[oldRuleIndex0] = rules[0] : newRules.push(rules[0]);
  1100. oldRuleIndex1 != -1 ? newRules[oldRuleIndex1] = rules[1] : newRules.push(rules[1]);
  1101. this.routingRuleSettings = JSON.stringify(newRules);
  1102. }
  1103. reverseModal.close();
  1104. },
  1105. isEdit: true
  1106. });
  1107. },
  1108. deleteReverse(index){
  1109. oldData = this.reverseData[index];
  1110. newTemplateSettings = this.templateSettings;
  1111. reverseTypeObj = newTemplateSettings.reverse[oldData.type+'s'];
  1112. realIndex = reverseTypeObj.findIndex(r => r.tag==oldData.tag && r.domain==oldData.domain);
  1113. newTemplateSettings.reverse[oldData.type+'s'].splice(realIndex,1);
  1114. // delete empty objects
  1115. if(reverseTypeObj.length == 0) Reflect.deleteProperty(newTemplateSettings.reverse, oldData.type+'s');
  1116. if(Object.keys(newTemplateSettings.reverse).length === 0) Reflect.deleteProperty(newTemplateSettings, 'reverse');
  1117. // delete related routing rules
  1118. newRules = newTemplateSettings.routing.rules;
  1119. if(oldData.type == "bridge"){
  1120. newRules = newTemplateSettings.routing.rules.filter(r => !( r.inboundTag && r.inboundTag.length == 1 && r.inboundTag[0] == oldData.tag));
  1121. } else if(oldData.type == "portal"){
  1122. newRules = newTemplateSettings.routing.rules.filter(r => r.outboundTag != oldData.tag);
  1123. }
  1124. newTemplateSettings.routing.rules = newRules;
  1125. this.templateSettings = newTemplateSettings;
  1126. },
  1127. addRule(){
  1128. ruleModal.show({
  1129. title: '{{ i18n "pages.xray.rules.add"}}',
  1130. okText: '{{ i18n "pages.xray.rules.add" }}',
  1131. confirm: (rule) => {
  1132. ruleModal.loading();
  1133. if(JSON.stringify(rule).length > 3){
  1134. this.templateSettings.routing.rules.push(rule);
  1135. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  1136. }
  1137. ruleModal.close();
  1138. },
  1139. isEdit: false
  1140. });
  1141. },
  1142. editRule(index){
  1143. ruleModal.show({
  1144. title: '{{ i18n "pages.xray.rules.edit"}} ' + (index+1),
  1145. rule: app.templateSettings.routing.rules[index],
  1146. confirm: (rule) => {
  1147. ruleModal.loading();
  1148. if(JSON.stringify(rule).length > 3){
  1149. this.templateSettings.routing.rules[index] = rule;
  1150. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  1151. }
  1152. ruleModal.close();
  1153. },
  1154. isEdit: true
  1155. });
  1156. },
  1157. replaceRule(old_index,new_index){
  1158. rules = this.templateSettings.routing.rules;
  1159. if (new_index >= rules.length) rules.push(undefined);
  1160. rules.splice(new_index, 0, rules.splice(old_index, 1)[0]);
  1161. this.routingRuleSettings = JSON.stringify(rules);
  1162. },
  1163. deleteRule(index){
  1164. rules = this.templateSettings.routing.rules;
  1165. rules.splice(index,1);
  1166. this.routingRuleSettings = JSON.stringify(rules);
  1167. },
  1168. showWarp(){
  1169. warpModal.show();
  1170. }
  1171. },
  1172. async mounted() {
  1173. await this.getXraySetting();
  1174. await this.getXrayResult();
  1175. await this.getOutboundsTraffic();
  1176. while (true) {
  1177. await PromiseUtil.sleep(800);
  1178. this.saveBtnDisable = this.oldXraySetting === this.xraySetting;
  1179. }
  1180. },
  1181. computed: {
  1182. templateSettings: {
  1183. get: function () { return this.xraySetting ? JSON.parse(this.xraySetting) : null; },
  1184. set: function (newValue) { this.xraySetting = JSON.stringify(newValue, null, 2); },
  1185. },
  1186. inboundSettings: {
  1187. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.inbounds, null, 2) : null; },
  1188. set: function (newValue) {
  1189. newTemplateSettings = this.templateSettings;
  1190. newTemplateSettings.inbounds = JSON.parse(newValue);
  1191. this.templateSettings = newTemplateSettings;
  1192. },
  1193. },
  1194. outboundSettings: {
  1195. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.outbounds, null, 2) : null; },
  1196. set: function (newValue) {
  1197. newTemplateSettings = this.templateSettings;
  1198. newTemplateSettings.outbounds = JSON.parse(newValue);
  1199. this.templateSettings = newTemplateSettings;
  1200. },
  1201. },
  1202. outboundData: {
  1203. get: function () {
  1204. data = []
  1205. if (this.templateSettings != null) {
  1206. this.templateSettings.outbounds.forEach((o, index) => {
  1207. data.push({'key': index, ...o});
  1208. });
  1209. }
  1210. return data;
  1211. },
  1212. },
  1213. reverseData: {
  1214. get: function () {
  1215. data = []
  1216. if (this.templateSettings != null && this.templateSettings.reverse != null) {
  1217. if(this.templateSettings.reverse.bridges) {
  1218. this.templateSettings.reverse.bridges.forEach((o, index) => {
  1219. data.push({'key': index, 'type':'bridge', ...o});
  1220. });
  1221. }
  1222. if(this.templateSettings.reverse.portals){
  1223. this.templateSettings.reverse.portals.forEach((o, index) => {
  1224. data.push({'key': index, 'type':'portal', ...o});
  1225. });
  1226. }
  1227. }
  1228. return data;
  1229. },
  1230. },
  1231. balancersData: {
  1232. get: function () {
  1233. data = []
  1234. if (this.templateSettings != null && this.templateSettings.routing != null && this.templateSettings.routing.balancers != null) {
  1235. this.templateSettings.routing.balancers.forEach((o, index) => {
  1236. let strategy = "random"
  1237. if (o.strategy && o.strategy.type == "roundRobin") {
  1238. strategy = o.strategy.type
  1239. }
  1240. data.push({
  1241. 'key': index,
  1242. 'tag': o.tag ? o.tag : "",
  1243. 'strategy': strategy,
  1244. 'selector': o.selector ? o.selector : []
  1245. });
  1246. });
  1247. }
  1248. return data;
  1249. }
  1250. },
  1251. routingRuleSettings: {
  1252. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.routing.rules, null, 2) : null; },
  1253. set: function (newValue) {
  1254. newTemplateSettings = this.templateSettings;
  1255. newTemplateSettings.routing.rules = JSON.parse(newValue);
  1256. this.templateSettings = newTemplateSettings;
  1257. },
  1258. },
  1259. routingRuleData: {
  1260. get: function () {
  1261. data = [];
  1262. if (this.templateSettings != null) {
  1263. this.templateSettings.routing.rules.forEach((r, index) => {
  1264. data.push({'key': index, ...r});
  1265. });
  1266. // Make rules readable
  1267. data.forEach(r => {
  1268. if(r.domain) r.domain = r.domain.join(',')
  1269. if(r.ip) r.ip = r.ip.join(',')
  1270. if(r.source) r.source = r.source.join(',');
  1271. if(r.user) r.user = r.user.join(',')
  1272. if(r.inboundTag) r.inboundTag = r.inboundTag.join(',')
  1273. if(r.protocol) r.protocol = r.protocol.join(',')
  1274. if(r.attrs) r.attrs = JSON.stringify(r.attrs, null, 2)
  1275. });
  1276. }
  1277. return data;
  1278. }
  1279. },
  1280. freedomStrategy: {
  1281. get: function () {
  1282. if (!this.templateSettings) return "AsIs";
  1283. freedomOutbound = this.templateSettings.outbounds.find((o) => o.protocol === "freedom" && o.tag == "direct");
  1284. if (!freedomOutbound) return "AsIs";
  1285. if (!freedomOutbound.settings || !freedomOutbound.settings.domainStrategy) return "AsIs";
  1286. return freedomOutbound.settings.domainStrategy;
  1287. },
  1288. set: function (newValue) {
  1289. newTemplateSettings = this.templateSettings;
  1290. freedomOutboundIndex = newTemplateSettings.outbounds.findIndex((o) => o.protocol === "freedom" && o.tag == "direct");
  1291. if(freedomOutboundIndex == -1){
  1292. newTemplateSettings.outbounds.push({protocol: "freedom", tag: "direct", settings: { "domainStrategy": newValue }});
  1293. } else if (!newTemplateSettings.outbounds[freedomOutboundIndex].settings) {
  1294. newTemplateSettings.outbounds[freedomOutboundIndex].settings = {"domainStrategy": newValue};
  1295. } else {
  1296. newTemplateSettings.outbounds[freedomOutboundIndex].settings.domainStrategy = newValue;
  1297. }
  1298. this.templateSettings = newTemplateSettings;
  1299. }
  1300. },
  1301. routingStrategy: {
  1302. get: function () {
  1303. if (!this.templateSettings || !this.templateSettings.routing || !this.templateSettings.routing.domainStrategy) return "AsIs";
  1304. return this.templateSettings.routing.domainStrategy;
  1305. },
  1306. set: function (newValue) {
  1307. newTemplateSettings = this.templateSettings;
  1308. newTemplateSettings.routing.domainStrategy = newValue;
  1309. this.templateSettings = newTemplateSettings;
  1310. }
  1311. },
  1312. setLogLevel: {
  1313. get: function () {
  1314. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.loglevel) return "warning";
  1315. return this.templateSettings.log.loglevel;
  1316. },
  1317. set: function (newValue) {
  1318. newTemplateSettings = this.templateSettings;
  1319. newTemplateSettings.log.loglevel = newValue;
  1320. this.templateSettings = newTemplateSettings;
  1321. }
  1322. },
  1323. setAccessLog: {
  1324. get: function () {
  1325. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.access) return "none";
  1326. return this.templateSettings.log.access;
  1327. },
  1328. set: function (newValue) {
  1329. newTemplateSettings = this.templateSettings;
  1330. newTemplateSettings.log.access = newValue;
  1331. this.templateSettings = newTemplateSettings;
  1332. }
  1333. },
  1334. blockedIPs: {
  1335. get: function () {
  1336. return this.templateRuleGetter({ outboundTag: "blocked", property: "ip" });
  1337. },
  1338. set: function (newValue) {
  1339. this.templateRuleSetter({ outboundTag: "blocked", property: "ip", data: newValue });
  1340. }
  1341. },
  1342. blockedDomains: {
  1343. get: function () {
  1344. return this.templateRuleGetter({ outboundTag: "blocked", property: "domain" });
  1345. },
  1346. set: function (newValue) {
  1347. this.templateRuleSetter({ outboundTag: "blocked", property: "domain", data: newValue });
  1348. }
  1349. },
  1350. blockedProtocols: {
  1351. get: function () {
  1352. return this.templateRuleGetter({ outboundTag: "blocked", property: "protocol" });
  1353. },
  1354. set: function (newValue) {
  1355. this.templateRuleSetter({ outboundTag: "blocked", property: "protocol", data: newValue });
  1356. }
  1357. },
  1358. directIPs: {
  1359. get: function () {
  1360. return this.templateRuleGetter({ outboundTag: "direct", property: "ip" });
  1361. },
  1362. set: function (newValue) {
  1363. this.templateRuleSetter({ outboundTag: "direct", property: "ip", data: newValue });
  1364. this.syncRulesWithOutbound("direct", this.directSettings);
  1365. }
  1366. },
  1367. directDomains: {
  1368. get: function () {
  1369. return this.templateRuleGetter({ outboundTag: "direct", property: "domain" });
  1370. },
  1371. set: function (newValue) {
  1372. this.templateRuleSetter({ outboundTag: "direct", property: "domain", data: newValue });
  1373. this.syncRulesWithOutbound("direct", this.directSettings);
  1374. }
  1375. },
  1376. ipv4Domains: {
  1377. get: function () {
  1378. return this.templateRuleGetter({ outboundTag: "IPv4", property: "domain" });
  1379. },
  1380. set: function (newValue) {
  1381. this.templateRuleSetter({ outboundTag: "IPv4", property: "domain", data: newValue });
  1382. this.syncRulesWithOutbound("IPv4", this.ipv4Settings);
  1383. }
  1384. },
  1385. warpDomains: {
  1386. get: function () {
  1387. return this.templateRuleGetter({ outboundTag: "warp", property: "domain" });
  1388. },
  1389. set: function (newValue) {
  1390. this.templateRuleSetter({ outboundTag: "warp", property: "domain", data: newValue });
  1391. }
  1392. },
  1393. torrentSettings: {
  1394. get: function () {
  1395. return doAllItemsExist(this.settingsData.protocols.bittorrent, this.blockedProtocols);
  1396. },
  1397. set: function (newValue) {
  1398. if (newValue) {
  1399. this.blockedProtocols = [...this.blockedProtocols, ...this.settingsData.protocols.bittorrent];
  1400. } else {
  1401. this.blockedProtocols = this.blockedProtocols.filter(data => !this.settingsData.protocols.bittorrent.includes(data));
  1402. }
  1403. },
  1404. },
  1405. privateIpSettings: {
  1406. get: function () {
  1407. return doAllItemsExist(this.settingsData.ips.local, this.blockedIPs);
  1408. },
  1409. set: function (newValue) {
  1410. if (newValue) {
  1411. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.local];
  1412. } else {
  1413. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.local.includes(data));
  1414. }
  1415. },
  1416. },
  1417. AdsSettings: {
  1418. get: function () {
  1419. return doAllItemsExist(this.settingsData.domains.ads, this.blockedDomains);
  1420. },
  1421. set: function (newValue) {
  1422. if (newValue) {
  1423. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.ads];
  1424. } else {
  1425. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.ads.includes(data));
  1426. }
  1427. },
  1428. },
  1429. SecuritySettings: {
  1430. get: function () {
  1431. return doAllItemsExist(this.settingsData.domains.security, this.blockedDomains);
  1432. },
  1433. set: function (newValue) {
  1434. if (newValue) {
  1435. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.security];
  1436. } else {
  1437. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.security.includes(data));
  1438. }
  1439. },
  1440. },
  1441. SpeedTestSettings: {
  1442. get: function () {
  1443. return doAllItemsExist(this.settingsData.domains.speedtest, this.blockedDomains);
  1444. },
  1445. set: function (newValue) {
  1446. if (newValue) {
  1447. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.speedtest];
  1448. } else {
  1449. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.speedtest.includes(data));
  1450. }
  1451. },
  1452. },
  1453. familyProtectSettings: {
  1454. get: function () {
  1455. if (!this.templateSettings || !this.templateSettings.dns || !this.templateSettings.dns.servers) return false;
  1456. return doAllItemsExist(this.templateSettings.dns.servers, this.settingsData.familyProtectDNS.servers);
  1457. },
  1458. set: function (newValue) {
  1459. newTemplateSettings = this.templateSettings;
  1460. if (newValue) {
  1461. newTemplateSettings.dns = this.settingsData.familyProtectDNS;
  1462. } else {
  1463. delete newTemplateSettings.dns;
  1464. }
  1465. this.templateSettings = newTemplateSettings;
  1466. },
  1467. },
  1468. GoogleIPv4Settings: {
  1469. get: function () {
  1470. return doAllItemsExist(this.settingsData.domains.google, this.ipv4Domains);
  1471. },
  1472. set: function (newValue) {
  1473. if (newValue) {
  1474. this.ipv4Domains = [...this.ipv4Domains, ...this.settingsData.domains.google];
  1475. } else {
  1476. this.ipv4Domains = this.ipv4Domains.filter(data => !this.settingsData.domains.google.includes(data));
  1477. }
  1478. },
  1479. },
  1480. NetflixIPv4Settings: {
  1481. get: function () {
  1482. return doAllItemsExist(this.settingsData.domains.netflix, this.ipv4Domains);
  1483. },
  1484. set: function (newValue) {
  1485. if (newValue) {
  1486. this.ipv4Domains = [...this.ipv4Domains, ...this.settingsData.domains.netflix];
  1487. } else {
  1488. this.ipv4Domains = this.ipv4Domains.filter(data => !this.settingsData.domains.netflix.includes(data));
  1489. }
  1490. },
  1491. },
  1492. IRIpSettings: {
  1493. get: function () {
  1494. return doAllItemsExist(this.settingsData.ips.ir, this.blockedIPs);
  1495. },
  1496. set: function (newValue) {
  1497. if (newValue) {
  1498. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.ir];
  1499. } else {
  1500. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.ir.includes(data));
  1501. }
  1502. }
  1503. },
  1504. IRDomainSettings: {
  1505. get: function () {
  1506. return doAllItemsExist(this.settingsData.domains.ir, this.blockedDomains);
  1507. },
  1508. set: function (newValue) {
  1509. if (newValue) {
  1510. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.ir];
  1511. } else {
  1512. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.ir.includes(data));
  1513. }
  1514. }
  1515. },
  1516. ChinaIpSettings: {
  1517. get: function () {
  1518. return doAllItemsExist(this.settingsData.ips.cn, this.blockedIPs);
  1519. },
  1520. set: function (newValue) {
  1521. if (newValue) {
  1522. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.cn];
  1523. } else {
  1524. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.cn.includes(data));
  1525. }
  1526. }
  1527. },
  1528. ChinaDomainSettings: {
  1529. get: function () {
  1530. return doAllItemsExist(this.settingsData.domains.cn, this.blockedDomains);
  1531. },
  1532. set: function (newValue) {
  1533. if (newValue) {
  1534. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.cn];
  1535. } else {
  1536. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.cn.includes(data));
  1537. }
  1538. }
  1539. },
  1540. RussiaIpSettings: {
  1541. get: function () {
  1542. return doAllItemsExist(this.settingsData.ips.ru, this.blockedIPs);
  1543. },
  1544. set: function (newValue) {
  1545. if (newValue) {
  1546. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.ru];
  1547. } else {
  1548. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.ru.includes(data));
  1549. }
  1550. }
  1551. },
  1552. RussiaDomainSettings: {
  1553. get: function () {
  1554. return doAllItemsExist(this.settingsData.domains.ru, this.blockedDomains);
  1555. },
  1556. set: function (newValue) {
  1557. if (newValue) {
  1558. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.ru];
  1559. } else {
  1560. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.ru.includes(data));
  1561. }
  1562. }
  1563. },
  1564. VNIpSettings: {
  1565. get: function () {
  1566. return doAllItemsExist(this.settingsData.ips.vn, this.blockedIPs);
  1567. },
  1568. set: function (newValue) {
  1569. if (newValue) {
  1570. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.vn];
  1571. } else {
  1572. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.vn.includes(data));
  1573. }
  1574. }
  1575. },
  1576. VNDomainSettings: {
  1577. get: function () {
  1578. return doAllItemsExist(this.settingsData.domains.vn, this.blockedDomains);
  1579. },
  1580. set: function (newValue) {
  1581. if (newValue) {
  1582. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.vn];
  1583. } else {
  1584. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.vn.includes(data));
  1585. }
  1586. }
  1587. },
  1588. IRIpDirectSettings: {
  1589. get: function () {
  1590. return doAllItemsExist(this.settingsData.ips.ir, this.directIPs);
  1591. },
  1592. set: function (newValue) {
  1593. if (newValue) {
  1594. this.directIPs = [...this.directIPs, ...this.settingsData.ips.ir];
  1595. } else {
  1596. this.directIPs = this.directIPs.filter(data => !this.settingsData.ips.ir.includes(data));
  1597. }
  1598. }
  1599. },
  1600. IRDomainDirectSettings: {
  1601. get: function () {
  1602. return doAllItemsExist(this.settingsData.domains.ir, this.directDomains);
  1603. },
  1604. set: function (newValue) {
  1605. if (newValue) {
  1606. this.directDomains = [...this.directDomains, ...this.settingsData.domains.ir];
  1607. } else {
  1608. this.directDomains = this.directDomains.filter(data => !this.settingsData.domains.ir.includes(data));
  1609. }
  1610. }
  1611. },
  1612. ChinaIpDirectSettings: {
  1613. get: function () {
  1614. return doAllItemsExist(this.settingsData.ips.cn, this.directIPs);
  1615. },
  1616. set: function (newValue) {
  1617. if (newValue) {
  1618. this.directIPs = [...this.directIPs, ...this.settingsData.ips.cn];
  1619. } else {
  1620. this.directIPs = this.directIPs.filter(data => !this.settingsData.ips.cn.includes(data));
  1621. }
  1622. }
  1623. },
  1624. ChinaDomainDirectSettings: {
  1625. get: function () {
  1626. return doAllItemsExist(this.settingsData.domains.cn, this.directDomains);
  1627. },
  1628. set: function (newValue) {
  1629. if (newValue) {
  1630. this.directDomains = [...this.directDomains, ...this.settingsData.domains.cn];
  1631. } else {
  1632. this.directDomains = this.directDomains.filter(data => !this.settingsData.domains.cn.includes(data));
  1633. }
  1634. }
  1635. },
  1636. RussiaIpDirectSettings: {
  1637. get: function () {
  1638. return doAllItemsExist(this.settingsData.ips.ru, this.directIPs);
  1639. },
  1640. set: function (newValue) {
  1641. if (newValue) {
  1642. this.directIPs = [...this.directIPs, ...this.settingsData.ips.ru];
  1643. } else {
  1644. this.directIPs = this.directIPs.filter(data => !this.settingsData.ips.ru.includes(data));
  1645. }
  1646. }
  1647. },
  1648. RussiaDomainDirectSettings: {
  1649. get: function () {
  1650. return doAllItemsExist(this.settingsData.domains.ru, this.directDomains);
  1651. },
  1652. set: function (newValue) {
  1653. if (newValue) {
  1654. this.directDomains = [...this.directDomains, ...this.settingsData.domains.ru];
  1655. } else {
  1656. this.directDomains = this.directDomains.filter(data => !this.settingsData.domains.ru.includes(data));
  1657. }
  1658. }
  1659. },
  1660. VNIpDirectSettings: {
  1661. get: function () {
  1662. return doAllItemsExist(this.settingsData.ips.vn, this.directIPs);
  1663. },
  1664. set: function (newValue) {
  1665. if (newValue) {
  1666. this.directIPs = [...this.directIPs, ...this.settingsData.ips.vn];
  1667. } else {
  1668. this.directIPs = this.directIPs.filter(data => !this.settingsData.ips.vn.includes(data));
  1669. }
  1670. }
  1671. },
  1672. VNDomainDirectSettings: {
  1673. get: function () {
  1674. return doAllItemsExist(this.settingsData.domains.vn, this.directDomains);
  1675. },
  1676. set: function (newValue) {
  1677. if (newValue) {
  1678. this.directDomains = [...this.directDomains, ...this.settingsData.domains.vn];
  1679. } else {
  1680. this.directDomains = this.directDomains.filter(data => !this.settingsData.domains.vn.includes(data));
  1681. }
  1682. }
  1683. },
  1684. WarpExist: {
  1685. get: function() {
  1686. return this.templateSettings ? this.templateSettings.outbounds.findIndex((o) => o.tag == "warp")>=0 : false;
  1687. },
  1688. },
  1689. GoogleWARPSettings: {
  1690. get: function () {
  1691. return doAllItemsExist(this.settingsData.domains.google, this.warpDomains);
  1692. },
  1693. set: function (newValue) {
  1694. if (newValue) {
  1695. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.google];
  1696. } else {
  1697. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.google.includes(data));
  1698. }
  1699. },
  1700. },
  1701. OpenAIWARPSettings: {
  1702. get: function () {
  1703. return doAllItemsExist(this.settingsData.domains.openai, this.warpDomains);
  1704. },
  1705. set: function (newValue) {
  1706. if (newValue) {
  1707. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.openai];
  1708. } else {
  1709. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.openai.includes(data));
  1710. }
  1711. },
  1712. },
  1713. NetflixWARPSettings: {
  1714. get: function () {
  1715. return doAllItemsExist(this.settingsData.domains.netflix, this.warpDomains);
  1716. },
  1717. set: function (newValue) {
  1718. if (newValue) {
  1719. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.netflix];
  1720. } else {
  1721. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.netflix.includes(data));
  1722. }
  1723. },
  1724. },
  1725. SpotifyWARPSettings: {
  1726. get: function () {
  1727. return doAllItemsExist(this.settingsData.domains.spotify, this.warpDomains);
  1728. },
  1729. set: function (newValue) {
  1730. if (newValue) {
  1731. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.spotify];
  1732. } else {
  1733. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.spotify.includes(data));
  1734. }
  1735. },
  1736. },
  1737. },
  1738. });
  1739. </script>
  1740. </body>
  1741. </html>