xray.html 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756
  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 @click="editOutbound(index)">
  404. <a-icon type="edit"></a-icon>
  405. {{ i18n "edit" }}
  406. </a-menu-item>
  407. <a-menu-item @click="resetOutboundTraffic(index)">
  408. <span>
  409. <a-icon type="retweet"></a-icon> {{ i18n "pages.inbounds.resetTraffic"}}
  410. </span>
  411. </a-menu-item>
  412. <a-menu-item @click="deleteOutbound(index)">
  413. <span style="color: #FF4D4F">
  414. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  415. </span>
  416. </a-menu-item>
  417. </a-menu>
  418. </a-dropdown>
  419. </template>
  420. <template slot="address" slot-scope="text, outbound, index">
  421. <p style="margin: 0 5px;" v-for="addr in findOutboundAddress(outbound)">[[ addr ]]</p>
  422. </template>
  423. <template slot="protocol" slot-scope="text, outbound, index">
  424. <a-tag style="margin:0;" color="purple">[[ outbound.protocol ]]</a-tag>
  425. <template v-if="[Protocols.VMess, Protocols.VLESS, Protocols.Trojan, Protocols.Shadowsocks].includes(outbound.protocol)">
  426. <a-tag style="margin:0;" color="blue">[[ outbound.streamSettings.network ]]</a-tag>
  427. <a-tag style="margin:0;" v-if="outbound.streamSettings.security=='tls'" color="green">tls</a-tag>
  428. <a-tag style="margin:0;" v-if="outbound.streamSettings.security=='reality'" color="green">reality</a-tag>
  429. </template>
  430. </template>
  431. <template slot="traffic" slot-scope="text, outbound, index">
  432. <a-tag color="green">[[ findOutboundTraffic(outbound) ]]</a-tag>
  433. </template>
  434. </a-table>
  435. </a-tab-pane>
  436. <a-tab-pane key="tpl-4" tab='{{ i18n "pages.xray.outbound.reverse"}}' style="padding-top: 20px;" force-render="true">
  437. <a-button type="primary" icon="plus" @click="addReverse()" style="margin-bottom: 10px;">{{ i18n "pages.xray.outbound.addReverse" }}</a-button>
  438. <a-table :columns="reverseColumns" bordered
  439. :row-key="r => r.key"
  440. :data-source="reverseData"
  441. :scroll="isMobile ? {} : { x: 200 }"
  442. :pagination="false"
  443. :indent-size="0"
  444. :style="isMobile ? 'padding: 5px 0' : 'margin-left: 1px;'">
  445. <template slot="action" slot-scope="text, reverse, index">
  446. [[ index+1 ]]
  447. <a-dropdown :trigger="['click']">
  448. <a-icon @click="e => e.preventDefault()" type="more" style="font-size: 16px; text-decoration: bold;"></a-icon>
  449. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  450. <a-menu-item @click="editReverse(index)">
  451. <a-icon type="edit"></a-icon>
  452. {{ i18n "edit" }}
  453. </a-menu-item>
  454. <a-menu-item @click="deleteReverse(index)">
  455. <span style="color: #FF4D4F">
  456. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  457. </span>
  458. </a-menu-item>
  459. </a-menu>
  460. </a-dropdown>
  461. </template>
  462. </a-table>
  463. </a-tab-pane>
  464. <a-tab-pane key="tpl-balancers" tab='{{ i18n "pages.xray.Balancers"}}' style="padding-top: 20px;" force-render="true">
  465. <a-button type="primary" icon="plus" @click="addBalancer()" style="margin-bottom: 10px;">{{ i18n "pages.xray.balancer.addBalancer"}}</a-button>
  466. <a-table :columns="balancerColumns" bordered
  467. :row-key="r => r.key"
  468. :data-source="balancersData"
  469. :scroll="isMobile ? {} : { x: 200 }"
  470. :pagination="false"
  471. :indent-size="0"
  472. :style="isMobile ? 'padding: 5px 0' : 'margin-left: 1px;'">
  473. <template slot="action" slot-scope="text, balancer, index">
  474. [[ index+1 ]]
  475. <a-dropdown :trigger="['click']">
  476. <a-icon @click="e => e.preventDefault()" type="more" style="font-size: 16px; text-decoration: bold;"></a-icon>
  477. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  478. <a-menu-item @click="editBalancer(index)">
  479. <a-icon type="edit"></a-icon>
  480. {{ i18n "edit" }}
  481. </a-menu-item>
  482. <a-menu-item @click="deleteBalancer(index)">
  483. <span style="color: #FF4D4F">
  484. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  485. </span>
  486. </a-menu-item>
  487. </a-menu>
  488. </a-dropdown>
  489. </template>
  490. <template slot="strategy" slot-scope="text, balancer, index">
  491. <a-tag style="margin:0;" v-if="balancer.strategy=='random'" color="purple">Random</a-tag>
  492. <a-tag style="margin:0;" v-if="balancer.strategy=='roundRobin'" color="green">Round Robin</a-tag>
  493. </template>
  494. <template slot="selector" slot-scope="text, balancer, index">
  495. <a-tag class="info-large-tag" style="margin:1;" v-for="sel in balancer.selector">[[ sel ]]</a-tag>
  496. </template>
  497. </a-table>
  498. </a-tab-pane>
  499. <a-tab-pane key="tpl-advanced" tab='{{ i18n "pages.xray.advancedTemplate"}}' style="padding-top: 20px;" force-render="true">
  500. <a-list-item-meta title='{{ i18n "pages.xray.Template"}}' description='{{ i18n "pages.xray.TemplateDesc"}}'></a-list-item-meta>
  501. <a-radio-group v-model="advSettings" @change="changeCode" button-style="solid" style="margin: 10px 0;" :size="isMobile ? 'small' : ''">
  502. <a-radio-button value="xraySetting">{{ i18n "pages.xray.completeTemplate"}}</a-radio-button>
  503. <a-radio-button value="inboundSettings">{{ i18n "pages.xray.Inbounds" }}</a-radio-button>
  504. <a-radio-button value="outboundSettings">{{ i18n "pages.xray.Outbounds" }}</a-radio-button>
  505. <a-radio-button value="routingRuleSettings">{{ i18n "pages.xray.Routings" }}</a-radio-button>
  506. </a-radio-group>
  507. <textarea style="position:absolute; left: -800px;" id="xraySetting"></textarea>
  508. </a-tab-pane>
  509. </a-tabs>
  510. </a-space>
  511. </a-spin>
  512. </a-layout-content>
  513. </a-layout>
  514. </a-layout>
  515. {{template "js" .}}
  516. {{template "component/themeSwitcher" .}}
  517. {{template "component/setting"}}
  518. {{template "ruleModal"}}
  519. {{template "outModal"}}
  520. {{template "reverseModal"}}
  521. {{template "balancerModal"}}
  522. {{template "warpModal"}}
  523. <script>
  524. const rulesColumns = [
  525. { title: "#", align: 'center', width: 15, scopedSlots: { customRender: 'action' } },
  526. { title: '{{ i18n "pages.xray.rules.source"}}', children: [
  527. { title: 'IP', dataIndex: "source", align: 'center', width: 20, ellipsis: true },
  528. { title: 'Port', dataIndex: 'sourcePort', align: 'center', width: 10, ellipsis: true } ]},
  529. { title: '{{ i18n "pages.inbounds.network"}}', children: [
  530. { title: 'L4', dataIndex: 'network', align: 'center', width: 10 },
  531. { title: 'Protocol', dataIndex: 'protocol', align: 'center', width: 10, ellipsis: true },
  532. { title: 'Attrs', dataIndex: 'attrs', align: 'center', width: 20, ellipsis: true } ]},
  533. { title: '{{ i18n "pages.xray.rules.dest"}}', children: [
  534. { title: 'IP', dataIndex: 'ip', align: 'center', width: 20, ellipsis: true },
  535. { title: 'Domain', dataIndex: 'domain', align: 'center', width: 20, ellipsis: true },
  536. { title: 'Port', dataIndex: 'port', align: 'center', width: 10, ellipsis: true }]},
  537. { title: '{{ i18n "pages.xray.rules.inbound"}}', children: [
  538. { title: 'Inbound Tag', dataIndex: 'inboundTag', align: 'center', width: 15, ellipsis: true },
  539. { title: 'Client Email', dataIndex: 'user', align: 'center', width: 20, ellipsis: true }]},
  540. { title: '{{ i18n "pages.xray.rules.outbound"}}', dataIndex: 'outboundTag', align: 'center', width: 15 },
  541. { title: '{{ i18n "pages.xray.rules.balancer"}}', dataIndex: 'balancerTag', align: 'center', width: 15 },
  542. ];
  543. const rulesMobileColumns = [
  544. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  545. { title: '{{ i18n "pages.xray.rules.inbound"}}', align: 'center', width: 50, ellipsis: true, scopedSlots: { customRender: 'inbound' } },
  546. { title: '{{ i18n "pages.xray.rules.outbound"}}', align: 'center', width: 50, ellipsis: true, scopedSlots: { customRender: 'outbound' } },
  547. { title: '{{ i18n "pages.xray.rules.info"}}', align: 'center', width: 50, ellipsis: true, scopedSlots: { customRender: 'info' } },
  548. ];
  549. const outboundColumns = [
  550. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  551. { title: '{{ i18n "pages.xray.outbound.tag"}}', dataIndex: 'tag', align: 'center', width: 50 },
  552. { title: '{{ i18n "protocol"}}', align: 'center', width: 50, scopedSlots: { customRender: 'protocol' } },
  553. { title: '{{ i18n "pages.xray.outbound.address"}}', align: 'center', width: 50, scopedSlots: { customRender: 'address' } },
  554. { title: '{{ i18n "pages.inbounds.traffic" }}', align: 'center', width: 50, scopedSlots: { customRender: 'traffic' } },
  555. ];
  556. const reverseColumns = [
  557. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  558. { title: '{{ i18n "pages.xray.outbound.type"}}', dataIndex: 'type', align: 'center', width: 50 },
  559. { title: '{{ i18n "pages.xray.outbound.tag"}}', dataIndex: 'tag', align: 'center', width: 50 },
  560. { title: '{{ i18n "pages.xray.outbound.domain"}}', dataIndex: 'domain', align: 'center', width: 50 },
  561. ];
  562. const balancerColumns = [
  563. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  564. { title: '{{ i18n "pages.xray.balancer.tag"}}', dataIndex: 'tag', align: 'center', width: 50 },
  565. { title: '{{ i18n "pages.xray.balancer.balancerStrategy"}}', align: 'center', width: 50, scopedSlots: { customRender: 'strategy' }},
  566. { title: '{{ i18n "pages.xray.balancer.balancerSelectors"}}', align: 'center', width: 100, scopedSlots: { customRender: 'selector' }},
  567. ];
  568. const app = new Vue({
  569. delimiters: ['[[', ']]'],
  570. el: '#app',
  571. data: {
  572. siderDrawer,
  573. themeSwitcher,
  574. isDarkTheme: themeSwitcher.isDarkTheme,
  575. spinning: false,
  576. oldXraySetting: '',
  577. xraySetting: '',
  578. inboundTags: [],
  579. outboundsTraffic: [],
  580. saveBtnDisable: true,
  581. refreshing: false,
  582. restartResult: '',
  583. isMobile: window.innerWidth <= 768,
  584. advSettings: 'xraySetting',
  585. cm: null,
  586. cmOptions: {
  587. lineNumbers: true,
  588. mode: "application/json",
  589. lint: true,
  590. styleActiveLine: true,
  591. matchBrackets: true,
  592. theme: "xq",
  593. autoCloseTags: true,
  594. lineWrapping: true,
  595. indentUnit: 2,
  596. indentWithTabs: true,
  597. smartIndent: true,
  598. tabSize: 2,
  599. lineWiseCopyCut: false,
  600. foldGutter: true,
  601. gutters: [
  602. "CodeMirror-lint-markers",
  603. "CodeMirror-linenumbers",
  604. "CodeMirror-foldgutter",
  605. ],
  606. },
  607. ipv4Settings: {
  608. tag: "IPv4",
  609. protocol: "freedom",
  610. settings: {
  611. domainStrategy: "UseIPv4"
  612. }
  613. },
  614. directSettings: {
  615. tag: "direct",
  616. protocol: "freedom"
  617. },
  618. routingDomainStrategies: ["AsIs", "IPIfNonMatch", "IPOnDemand"],
  619. logLevel: ["none" , "debug" , "info" , "warning", "error"],
  620. access: ["none" , "./access.log" ],
  621. settingsData: {
  622. protocols: {
  623. bittorrent: ["bittorrent"],
  624. },
  625. ips: {
  626. local: ["geoip:private"],
  627. cn: ["geoip:cn"],
  628. ir: ["ext:geoip_IR.dat:ir"],
  629. ru: ["geoip:ru"],
  630. vn: ["ext:geoip_VN.dat:vn"],
  631. },
  632. domains: {
  633. ads: [
  634. "geosite:category-ads-all",
  635. "ext:geosite_IR.dat:category-ads-all"
  636. ],
  637. security: [
  638. "ext:geosite_IR.dat:malware",
  639. "ext:geosite_IR.dat:phishing",
  640. "ext:geosite_IR.dat:cryptominers"
  641. ],
  642. speedtest: ["geosite:speedtest"],
  643. openai: ["geosite:openai"],
  644. google: ["geosite:google"],
  645. spotify: ["geosite:spotify"],
  646. netflix: ["geosite:netflix"],
  647. cn: [
  648. "geosite:cn",
  649. "regexp:.*\\.cn$"
  650. ],
  651. ru: [
  652. "geosite:category-gov-ru",
  653. "regexp:.*\\.ru$"
  654. ],
  655. ir: [
  656. "regexp:.*\\.ir$",
  657. "regexp:.*\\.xn--mgba3a4f16a$", // .ایران
  658. "ext:geosite_IR.dat:ir"
  659. ],
  660. vn: [
  661. "regexp:.*\\.vn$",
  662. "ext:geosite_VN.dat:vn",
  663. "ext:geosite_VN.dat:ads"
  664. ]
  665. },
  666. familyProtectDNS: {
  667. "servers": [
  668. "1.1.1.3", // https://developers.cloudflare.com/1.1.1.1/setup/
  669. "1.0.0.3",
  670. "2606:4700:4700::1113",
  671. "2606:4700:4700::1003"
  672. ],
  673. "queryStrategy": "UseIP"
  674. },
  675. }
  676. },
  677. methods: {
  678. loading(spinning = true) {
  679. this.spinning = spinning;
  680. },
  681. async getOutboundsTraffic() {
  682. const msg = await HttpUtil.get("/panel/xray/getOutboundsTraffic");
  683. if (msg.success) {
  684. this.outboundsTraffic = msg.obj;
  685. }
  686. },
  687. async getXraySetting() {
  688. this.loading(true);
  689. const msg = await HttpUtil.post("/panel/xray/");
  690. this.loading(false);
  691. if (msg.success) {
  692. result = JSON.parse(msg.obj);
  693. xs = JSON.stringify(result.xraySetting, null, 2);
  694. this.oldXraySetting = xs;
  695. this.xraySetting = xs;
  696. this.inboundTags = result.inboundTags;
  697. this.saveBtnDisable = true;
  698. }
  699. },
  700. async updateXraySetting() {
  701. this.loading(true);
  702. const msg = await HttpUtil.post("/panel/xray/update", {xraySetting : this.xraySetting});
  703. this.loading(false);
  704. if (msg.success) {
  705. await this.getXraySetting();
  706. }
  707. },
  708. async restartXray() {
  709. this.loading(true);
  710. const msg = await HttpUtil.post("server/restartXrayService");
  711. this.loading(false);
  712. if (msg.success) {
  713. await PromiseUtil.sleep(500);
  714. await this.getXrayResult();
  715. }
  716. this.loading(false);
  717. },
  718. async getXrayResult() {
  719. const msg = await HttpUtil.get("/panel/xray/getXrayResult");
  720. if(msg.success){
  721. this.restartResult=msg.obj;
  722. if(msg.obj.length > 1) Vue.prototype.$message.error(msg.obj);
  723. }
  724. },
  725. async fetchUserSecret() {
  726. this.loading(true);
  727. const userMessage = await HttpUtil.post("/panel/setting/getUserSecret", this.user);
  728. if (userMessage.success) {
  729. this.user = userMessage.obj;
  730. }
  731. this.loading(false);
  732. },
  733. async updateSecret() {
  734. this.loading(true);
  735. const msg = await HttpUtil.post("/panel/setting/updateUserSecret", this.user);
  736. if (msg.success) {
  737. this.user = msg.obj;
  738. window.location.replace(basePath + "logout");
  739. }
  740. this.loading(false);
  741. await this.updateXraySetting();
  742. },
  743. generateRandomString(length) {
  744. var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  745. let randomString = "";
  746. for (let i = 0; i < length; i++) {
  747. randomString += chars[Math.floor(Math.random() * chars.length)];
  748. }
  749. return randomString;
  750. },
  751. async getNewSecret() {
  752. this.loading(true);
  753. await PromiseUtil.sleep(600);
  754. const newSecret = this.generateRandomString(64);
  755. this.user.loginSecret = newSecret;
  756. document.getElementById("token").textContent = newSecret;
  757. this.loading(false);
  758. },
  759. async toggleToken(value) {
  760. if (value) {
  761. await this.getNewSecret();
  762. } else {
  763. this.user.loginSecret = "";
  764. }
  765. },
  766. async resetXrayConfigToDefault() {
  767. this.loading(true);
  768. const msg = await HttpUtil.get("/panel/setting/getDefaultJsonConfig");
  769. this.loading(false);
  770. if (msg.success) {
  771. this.templateSettings = JSON.parse(JSON.stringify(msg.obj, null, 2));
  772. this.saveBtnDisable = true;
  773. }
  774. },
  775. syncRulesWithOutbound(tag, setting) {
  776. const newTemplateSettings = this.templateSettings;
  777. const haveRules = newTemplateSettings.routing.rules.some((r) => r?.outboundTag === tag);
  778. const outboundIndex = newTemplateSettings.outbounds.findIndex((o) => o.tag === tag);
  779. if (!haveRules && outboundIndex > 0) {
  780. newTemplateSettings.outbounds.splice(outboundIndex);
  781. }
  782. if (haveRules && outboundIndex < 0) {
  783. newTemplateSettings.outbounds.push(setting);
  784. }
  785. this.templateSettings = newTemplateSettings;
  786. },
  787. templateRuleGetter(routeSettings) {
  788. const { property, outboundTag } = routeSettings;
  789. let result = [];
  790. if (this.templateSettings != null) {
  791. this.templateSettings.routing.rules.forEach(
  792. (routingRule) => {
  793. if (
  794. routingRule.hasOwnProperty(property) &&
  795. routingRule.hasOwnProperty("outboundTag") &&
  796. routingRule.outboundTag === outboundTag
  797. ) {
  798. result.push(...routingRule[property]);
  799. }
  800. }
  801. );
  802. }
  803. return result;
  804. },
  805. templateRuleSetter(routeSettings) {
  806. const { data, property, outboundTag } = routeSettings;
  807. const oldTemplateSettings = this.templateSettings;
  808. const newTemplateSettings = oldTemplateSettings;
  809. currentProperty = this.templateRuleGetter({ outboundTag, property })
  810. if (currentProperty.length == 0) {
  811. const propertyRule = {
  812. type: "field",
  813. outboundTag,
  814. [property]: data
  815. };
  816. newTemplateSettings.routing.rules.push(propertyRule);
  817. }
  818. else {
  819. const newRules = [];
  820. insertedOnce = false;
  821. newTemplateSettings.routing.rules.forEach(
  822. (routingRule) => {
  823. if (
  824. routingRule.hasOwnProperty(property) &&
  825. routingRule.hasOwnProperty("outboundTag") &&
  826. routingRule.outboundTag === outboundTag
  827. ) {
  828. if (!insertedOnce && data.length > 0) {
  829. insertedOnce = true;
  830. routingRule[property] = data;
  831. newRules.push(routingRule);
  832. }
  833. }
  834. else {
  835. newRules.push(routingRule);
  836. }
  837. }
  838. );
  839. newTemplateSettings.routing.rules = newRules;
  840. }
  841. this.templateSettings = newTemplateSettings;
  842. },
  843. changeCode() {
  844. if(this.cm != null) {
  845. this.cm.toTextArea();
  846. }
  847. textAreaObj = document.getElementById('xraySetting');
  848. textAreaObj.value = this[this.advSettings];
  849. this.cm = CodeMirror.fromTextArea(textAreaObj, this.cmOptions);
  850. this.cm.on('change',editor => {
  851. value = editor.getValue();
  852. if(this.isJsonString(value)){
  853. this[this.advSettings] = value;
  854. }
  855. });
  856. },
  857. isJsonString(str) {
  858. try {
  859. JSON.parse(str);
  860. } catch (e) {
  861. return false;
  862. }
  863. return true;
  864. },
  865. findOutboundTraffic(o) {
  866. for (const otraffic of this.outboundsTraffic) {
  867. if (otraffic.tag == o.tag) {
  868. return sizeFormat(otraffic.up) + ' / ' + sizeFormat(otraffic.down);
  869. }
  870. }
  871. return sizeFormat(0) + ' / ' + sizeFormat(0);
  872. },
  873. findOutboundAddress(o) {
  874. serverObj = null;
  875. switch(o.protocol){
  876. case Protocols.VMess:
  877. case Protocols.VLESS:
  878. serverObj = o.settings.vnext;
  879. break;
  880. case Protocols.HTTP:
  881. case Protocols.Socks:
  882. case Protocols.Shadowsocks:
  883. case Protocols.Trojan:
  884. serverObj = o.settings.servers;
  885. break;
  886. case Protocols.DNS:
  887. return [o.settings.address + ':' + o.settings.port];
  888. case Protocols.Wireguard:
  889. return o.settings.peers.map(peer => peer.endpoint);
  890. default:
  891. return null;
  892. }
  893. return serverObj ? serverObj.map(obj => obj.address + ':' + obj.port) : null;
  894. },
  895. addOutbound(){
  896. outModal.show({
  897. title: '{{ i18n "pages.xray.outbound.addOutbound"}}',
  898. okText: '{{ i18n "pages.xray.outbound.addOutbound" }}',
  899. confirm: (outbound) => {
  900. outModal.loading();
  901. if(outbound.tag.length > 0){
  902. this.templateSettings.outbounds.push(outbound);
  903. this.outboundSettings = JSON.stringify(this.templateSettings.outbounds);
  904. }
  905. outModal.close();
  906. },
  907. isEdit: false,
  908. tags: this.templateSettings.outbounds.map(obj => obj.tag)
  909. });
  910. },
  911. editOutbound(index){
  912. outModal.show({
  913. title: '{{ i18n "pages.xray.outbound.editOutbound"}} ' + (index+1),
  914. outbound: app.templateSettings.outbounds[index],
  915. confirm: (outbound) => {
  916. outModal.loading();
  917. this.templateSettings.outbounds[index] = outbound;
  918. this.outboundSettings = JSON.stringify(this.templateSettings.outbounds);
  919. outModal.close();
  920. },
  921. isEdit: true,
  922. tags: this.outboundData.filter((o) => o.key != index ).map(obj => obj.tag)
  923. });
  924. },
  925. deleteOutbound(index){
  926. outbounds = this.templateSettings.outbounds;
  927. outbounds.splice(index,1);
  928. this.outboundSettings = JSON.stringify(outbounds);
  929. },
  930. async refreshOutboundTraffic() {
  931. if (!this.refreshing) {
  932. this.refreshing = true;
  933. await this.getOutboundsTraffic();
  934. data = []
  935. if (this.templateSettings != null) {
  936. this.templateSettings.outbounds.forEach((o, index) => {
  937. data.push({'key': index, ...o});
  938. });
  939. }
  940. this.outboundData = data;
  941. this.refreshing = false;
  942. }
  943. },
  944. async resetOutboundTraffic(index) {
  945. let tag = "-alltags-";
  946. if (index >= 0) {
  947. tag = this.outboundData[index].tag ? this.outboundData[index].tag : ""
  948. }
  949. const msg = await HttpUtil.post("/panel/xray/resetOutboundsTraffic", { tag: tag });
  950. if (msg.success) {
  951. await this.refreshOutboundTraffic();
  952. }
  953. },
  954. addBalancer() {
  955. balancerModal.show({
  956. title: '{{ i18n "pages.xray.balancer.addBalancer"}}',
  957. okText: '{{ i18n "pages.xray.balancer.addBalancer"}}',
  958. balancerTags: this.balancersData.filter((o) => !ObjectUtil.isEmpty(o.tag)).map(obj => obj.tag),
  959. balancer: {
  960. tag: '',
  961. strategy: 'random',
  962. selector: []
  963. },
  964. confirm: (balancer) => {
  965. balancerModal.loading();
  966. newTemplateSettings = this.templateSettings;
  967. if (newTemplateSettings.routing.balancers == undefined) {
  968. newTemplateSettings.routing.balancers = [];
  969. }
  970. let tmpBalancer = {
  971. 'tag': balancer.tag,
  972. 'selector': balancer.selector
  973. };
  974. if (balancer.strategy == 'roundRobin') {
  975. tmpBalancer.strategy = {
  976. 'type': balancer.strategy
  977. };
  978. }
  979. newTemplateSettings.routing.balancers.push(tmpBalancer);
  980. this.templateSettings = newTemplateSettings;
  981. balancerModal.close();
  982. },
  983. isEdit: false
  984. });
  985. },
  986. editBalancer(index) {
  987. const oldTag = this.balancersData[index].tag;
  988. balancerModal.show({
  989. title: '{{ i18n "pages.xray.balancer.editBalancer"}}',
  990. okText: '{{ i18n "sure" }}',
  991. balancerTags: this.balancersData.filter((o) => !ObjectUtil.isEmpty(o.tag)).map(obj => obj.tag),
  992. balancer: this.balancersData[index],
  993. confirm: (balancer) => {
  994. balancerModal.loading();
  995. newTemplateSettings = this.templateSettings;
  996. let tmpBalancer = {
  997. 'tag': balancer.tag,
  998. 'selector': balancer.selector
  999. };
  1000. if (balancer.strategy == 'roundRobin') {
  1001. tmpBalancer.strategy = {
  1002. 'type': balancer.strategy
  1003. };
  1004. }
  1005. newTemplateSettings.routing.balancers[index] = tmpBalancer;
  1006. // change edited tag if used in rule section
  1007. if (oldTag != balancer.tag) {
  1008. newTemplateSettings.routing.rules.forEach((rule) => {
  1009. if (rule.balancerTag && rule.balancerTag == oldTag) {
  1010. rule.balancerTag = balancer.tag;
  1011. }
  1012. });
  1013. }
  1014. this.templateSettings = newTemplateSettings;
  1015. balancerModal.close();
  1016. },
  1017. isEdit: true
  1018. });
  1019. },
  1020. deleteBalancer(index) {
  1021. newTemplateSettings = this.templateSettings;
  1022. //remove from balancers
  1023. const oldTag = this.balancersData[index].tag;
  1024. this.balancersData.splice(index, 1);
  1025. // remove from settings
  1026. let realIndex = newTemplateSettings.routing.balancers.findIndex((b) => b.tag == oldTag);
  1027. newTemplateSettings.routing.balancers.splice(realIndex, 1);
  1028. // remove related routing rules
  1029. let rules = [];
  1030. newTemplateSettings.routing.rules.forEach((r) => {
  1031. if (!r.balancerTag || r.balancerTag != oldTag) {
  1032. rules.push(r);
  1033. }
  1034. });
  1035. newTemplateSettings.routing.rules = rules;
  1036. this.templateSettings = newTemplateSettings;
  1037. },
  1038. addReverse(){
  1039. reverseModal.show({
  1040. title: '{{ i18n "pages.xray.outbound.addReverse"}}',
  1041. okText: '{{ i18n "pages.xray.outbound.addReverse" }}',
  1042. confirm: (reverse, rules) => {
  1043. reverseModal.loading();
  1044. if(reverse.tag.length > 0){
  1045. newTemplateSettings = this.templateSettings;
  1046. if(newTemplateSettings.reverse == undefined) newTemplateSettings.reverse = {};
  1047. if(newTemplateSettings.reverse[reverse.type+'s'] == undefined) newTemplateSettings.reverse[reverse.type+'s'] = [];
  1048. newTemplateSettings.reverse[reverse.type+'s'].push({ tag: reverse.tag, domain: reverse.domain });
  1049. this.templateSettings = newTemplateSettings;
  1050. // Add related rules
  1051. this.templateSettings.routing.rules.push(...rules);
  1052. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  1053. }
  1054. reverseModal.close();
  1055. },
  1056. isEdit: false
  1057. });
  1058. },
  1059. editReverse(index){
  1060. if(this.reverseData[index].type == "bridge") {
  1061. oldRules = this.templateSettings.routing.rules.filter(r => r.inboundTag && r.inboundTag[0] == this.reverseData[index].tag);
  1062. } else {
  1063. oldRules = this.templateSettings.routing.rules.filter(r => r.outboundTag && r.outboundTag == this.reverseData[index].tag);
  1064. }
  1065. reverseModal.show({
  1066. title: '{{ i18n "pages.xray.outbound.editReverse"}} ' + (index+1),
  1067. reverse: this.reverseData[index],
  1068. rules: oldRules,
  1069. confirm: (reverse, rules) => {
  1070. reverseModal.loading();
  1071. if(reverse.tag.length > 0){
  1072. oldData = this.reverseData[index];
  1073. newTemplateSettings = this.templateSettings;
  1074. oldReverseIndex = newTemplateSettings.reverse[oldData.type+'s'].findIndex(rs => rs.tag == oldData.tag);
  1075. oldRuleIndex0 = oldRules.length>0 ? newTemplateSettings.routing.rules.findIndex(r => JSON.stringify(r) == JSON.stringify(oldRules[0])) : -1;
  1076. oldRuleIndex1 = oldRules.length==2 ? newTemplateSettings.routing.rules.findIndex(r => JSON.stringify(r) == JSON.stringify(oldRules[1])) : -1;
  1077. if(oldData.type == reverse.type){
  1078. newTemplateSettings.reverse[oldData.type + 's'][oldReverseIndex] = { tag: reverse.tag, domain: reverse.domain };
  1079. } else {
  1080. newTemplateSettings.reverse[oldData.type+'s'].splice(oldReverseIndex,1);
  1081. // delete empty object
  1082. if(newTemplateSettings.reverse[oldData.type+'s'].length == 0) Reflect.deleteProperty(newTemplateSettings.reverse, oldData.type+'s');
  1083. // add other type of reverse if it is not exist
  1084. if(!newTemplateSettings.reverse[reverse.type+'s']) newTemplateSettings.reverse[reverse.type+'s'] = [];
  1085. newTemplateSettings.reverse[reverse.type+'s'].push({ tag: reverse.tag, domain: reverse.domain });
  1086. }
  1087. this.templateSettings = newTemplateSettings;
  1088. // Adjust Rules
  1089. newRules = this.templateSettings.routing.rules;
  1090. oldRuleIndex0 != -1 ? newRules[oldRuleIndex0] = rules[0] : newRules.push(rules[0]);
  1091. oldRuleIndex1 != -1 ? newRules[oldRuleIndex1] = rules[1] : newRules.push(rules[1]);
  1092. this.routingRuleSettings = JSON.stringify(newRules);
  1093. }
  1094. reverseModal.close();
  1095. },
  1096. isEdit: true
  1097. });
  1098. },
  1099. deleteReverse(index){
  1100. oldData = this.reverseData[index];
  1101. newTemplateSettings = this.templateSettings;
  1102. reverseTypeObj = newTemplateSettings.reverse[oldData.type+'s'];
  1103. realIndex = reverseTypeObj.findIndex(r => r.tag==oldData.tag && r.domain==oldData.domain);
  1104. newTemplateSettings.reverse[oldData.type+'s'].splice(realIndex,1);
  1105. // delete empty objects
  1106. if(reverseTypeObj.length == 0) Reflect.deleteProperty(newTemplateSettings.reverse, oldData.type+'s');
  1107. if(Object.keys(newTemplateSettings.reverse).length === 0) Reflect.deleteProperty(newTemplateSettings, 'reverse');
  1108. // delete related routing rules
  1109. newRules = newTemplateSettings.routing.rules;
  1110. if(oldData.type == "bridge"){
  1111. newRules = newTemplateSettings.routing.rules.filter(r => !( r.inboundTag && r.inboundTag.length == 1 && r.inboundTag[0] == oldData.tag));
  1112. } else if(oldData.type == "portal"){
  1113. newRules = newTemplateSettings.routing.rules.filter(r => r.outboundTag != oldData.tag);
  1114. }
  1115. newTemplateSettings.routing.rules = newRules;
  1116. this.templateSettings = newTemplateSettings;
  1117. },
  1118. addRule(){
  1119. ruleModal.show({
  1120. title: '{{ i18n "pages.xray.rules.add"}}',
  1121. okText: '{{ i18n "pages.xray.rules.add" }}',
  1122. confirm: (rule) => {
  1123. ruleModal.loading();
  1124. if(JSON.stringify(rule).length > 3){
  1125. this.templateSettings.routing.rules.push(rule);
  1126. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  1127. }
  1128. ruleModal.close();
  1129. },
  1130. isEdit: false
  1131. });
  1132. },
  1133. editRule(index){
  1134. ruleModal.show({
  1135. title: '{{ i18n "pages.xray.rules.edit"}} ' + (index+1),
  1136. rule: app.templateSettings.routing.rules[index],
  1137. confirm: (rule) => {
  1138. ruleModal.loading();
  1139. if(JSON.stringify(rule).length > 3){
  1140. this.templateSettings.routing.rules[index] = rule;
  1141. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  1142. }
  1143. ruleModal.close();
  1144. },
  1145. isEdit: true
  1146. });
  1147. },
  1148. replaceRule(old_index,new_index){
  1149. rules = this.templateSettings.routing.rules;
  1150. if (new_index >= rules.length) rules.push(undefined);
  1151. rules.splice(new_index, 0, rules.splice(old_index, 1)[0]);
  1152. this.routingRuleSettings = JSON.stringify(rules);
  1153. },
  1154. deleteRule(index){
  1155. rules = this.templateSettings.routing.rules;
  1156. rules.splice(index,1);
  1157. this.routingRuleSettings = JSON.stringify(rules);
  1158. },
  1159. showWarp(){
  1160. warpModal.show();
  1161. }
  1162. },
  1163. async mounted() {
  1164. await this.getXraySetting();
  1165. await this.getXrayResult();
  1166. await this.getOutboundsTraffic();
  1167. while (true) {
  1168. await PromiseUtil.sleep(800);
  1169. this.saveBtnDisable = this.oldXraySetting === this.xraySetting;
  1170. }
  1171. },
  1172. computed: {
  1173. templateSettings: {
  1174. get: function () { return this.xraySetting ? JSON.parse(this.xraySetting) : null; },
  1175. set: function (newValue) { this.xraySetting = JSON.stringify(newValue, null, 2); },
  1176. },
  1177. inboundSettings: {
  1178. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.inbounds, null, 2) : null; },
  1179. set: function (newValue) {
  1180. newTemplateSettings = this.templateSettings;
  1181. newTemplateSettings.inbounds = JSON.parse(newValue);
  1182. this.templateSettings = newTemplateSettings;
  1183. },
  1184. },
  1185. outboundSettings: {
  1186. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.outbounds, null, 2) : null; },
  1187. set: function (newValue) {
  1188. newTemplateSettings = this.templateSettings;
  1189. newTemplateSettings.outbounds = JSON.parse(newValue);
  1190. this.templateSettings = newTemplateSettings;
  1191. },
  1192. },
  1193. outboundData: {
  1194. get: function () {
  1195. data = []
  1196. if (this.templateSettings != null) {
  1197. this.templateSettings.outbounds.forEach((o, index) => {
  1198. data.push({'key': index, ...o});
  1199. });
  1200. }
  1201. return data;
  1202. },
  1203. },
  1204. reverseData: {
  1205. get: function () {
  1206. data = []
  1207. if (this.templateSettings != null && this.templateSettings.reverse != null) {
  1208. if(this.templateSettings.reverse.bridges) {
  1209. this.templateSettings.reverse.bridges.forEach((o, index) => {
  1210. data.push({'key': index, 'type':'bridge', ...o});
  1211. });
  1212. }
  1213. if(this.templateSettings.reverse.portals){
  1214. this.templateSettings.reverse.portals.forEach((o, index) => {
  1215. data.push({'key': index, 'type':'portal', ...o});
  1216. });
  1217. }
  1218. }
  1219. return data;
  1220. },
  1221. },
  1222. balancersData: {
  1223. get: function () {
  1224. data = []
  1225. if (this.templateSettings != null && this.templateSettings.routing != null && this.templateSettings.routing.balancers != null) {
  1226. this.templateSettings.routing.balancers.forEach((o, index) => {
  1227. let strategy = "random"
  1228. if (o.strategy && o.strategy.type == "roundRobin") {
  1229. strategy = o.strategy.type
  1230. }
  1231. data.push({
  1232. 'key': index,
  1233. 'tag': o.tag ? o.tag : "",
  1234. 'strategy': strategy,
  1235. 'selector': o.selector ? o.selector : []
  1236. });
  1237. });
  1238. }
  1239. return data;
  1240. }
  1241. },
  1242. routingRuleSettings: {
  1243. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.routing.rules, null, 2) : null; },
  1244. set: function (newValue) {
  1245. newTemplateSettings = this.templateSettings;
  1246. newTemplateSettings.routing.rules = JSON.parse(newValue);
  1247. this.templateSettings = newTemplateSettings;
  1248. },
  1249. },
  1250. routingRuleData: {
  1251. get: function () {
  1252. data = [];
  1253. if (this.templateSettings != null) {
  1254. this.templateSettings.routing.rules.forEach((r, index) => {
  1255. data.push({'key': index, ...r});
  1256. });
  1257. // Make rules readable
  1258. data.forEach(r => {
  1259. if(r.domain) r.domain = r.domain.join(',')
  1260. if(r.ip) r.ip = r.ip.join(',')
  1261. if(r.source) r.source = r.source.join(',');
  1262. if(r.user) r.user = r.user.join(',')
  1263. if(r.inboundTag) r.inboundTag = r.inboundTag.join(',')
  1264. if(r.protocol) r.protocol = r.protocol.join(',')
  1265. if(r.attrs) r.attrs = JSON.stringify(r.attrs, null, 2)
  1266. });
  1267. }
  1268. return data;
  1269. }
  1270. },
  1271. freedomStrategy: {
  1272. get: function () {
  1273. if (!this.templateSettings) return "AsIs";
  1274. freedomOutbound = this.templateSettings.outbounds.find((o) => o.protocol === "freedom" && o.tag == "direct");
  1275. if (!freedomOutbound) return "AsIs";
  1276. if (!freedomOutbound.settings || !freedomOutbound.settings.domainStrategy) return "AsIs";
  1277. return freedomOutbound.settings.domainStrategy;
  1278. },
  1279. set: function (newValue) {
  1280. newTemplateSettings = this.templateSettings;
  1281. freedomOutboundIndex = newTemplateSettings.outbounds.findIndex((o) => o.protocol === "freedom" && o.tag == "direct");
  1282. if(freedomOutboundIndex == -1){
  1283. newTemplateSettings.outbounds.push({protocol: "freedom", tag: "direct", settings: { "domainStrategy": newValue }});
  1284. } else if (!newTemplateSettings.outbounds[freedomOutboundIndex].settings) {
  1285. newTemplateSettings.outbounds[freedomOutboundIndex].settings = {"domainStrategy": newValue};
  1286. } else {
  1287. newTemplateSettings.outbounds[freedomOutboundIndex].settings.domainStrategy = newValue;
  1288. }
  1289. this.templateSettings = newTemplateSettings;
  1290. }
  1291. },
  1292. routingStrategy: {
  1293. get: function () {
  1294. if (!this.templateSettings || !this.templateSettings.routing || !this.templateSettings.routing.domainStrategy) return "AsIs";
  1295. return this.templateSettings.routing.domainStrategy;
  1296. },
  1297. set: function (newValue) {
  1298. newTemplateSettings = this.templateSettings;
  1299. newTemplateSettings.routing.domainStrategy = newValue;
  1300. this.templateSettings = newTemplateSettings;
  1301. }
  1302. },
  1303. setLogLevel: {
  1304. get: function () {
  1305. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.loglevel) return "warning";
  1306. return this.templateSettings.log.loglevel;
  1307. },
  1308. set: function (newValue) {
  1309. newTemplateSettings = this.templateSettings;
  1310. newTemplateSettings.log.loglevel = newValue;
  1311. this.templateSettings = newTemplateSettings;
  1312. }
  1313. },
  1314. setAccessLog: {
  1315. get: function () {
  1316. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.access) return "none";
  1317. return this.templateSettings.log.access;
  1318. },
  1319. set: function (newValue) {
  1320. newTemplateSettings = this.templateSettings;
  1321. newTemplateSettings.log.access = newValue;
  1322. this.templateSettings = newTemplateSettings;
  1323. }
  1324. },
  1325. blockedIPs: {
  1326. get: function () {
  1327. return this.templateRuleGetter({ outboundTag: "blocked", property: "ip" });
  1328. },
  1329. set: function (newValue) {
  1330. this.templateRuleSetter({ outboundTag: "blocked", property: "ip", data: newValue });
  1331. }
  1332. },
  1333. blockedDomains: {
  1334. get: function () {
  1335. return this.templateRuleGetter({ outboundTag: "blocked", property: "domain" });
  1336. },
  1337. set: function (newValue) {
  1338. this.templateRuleSetter({ outboundTag: "blocked", property: "domain", data: newValue });
  1339. }
  1340. },
  1341. blockedProtocols: {
  1342. get: function () {
  1343. return this.templateRuleGetter({ outboundTag: "blocked", property: "protocol" });
  1344. },
  1345. set: function (newValue) {
  1346. this.templateRuleSetter({ outboundTag: "blocked", property: "protocol", data: newValue });
  1347. }
  1348. },
  1349. directIPs: {
  1350. get: function () {
  1351. return this.templateRuleGetter({ outboundTag: "direct", property: "ip" });
  1352. },
  1353. set: function (newValue) {
  1354. this.templateRuleSetter({ outboundTag: "direct", property: "ip", data: newValue });
  1355. this.syncRulesWithOutbound("direct", this.directSettings);
  1356. }
  1357. },
  1358. directDomains: {
  1359. get: function () {
  1360. return this.templateRuleGetter({ outboundTag: "direct", property: "domain" });
  1361. },
  1362. set: function (newValue) {
  1363. this.templateRuleSetter({ outboundTag: "direct", property: "domain", data: newValue });
  1364. this.syncRulesWithOutbound("direct", this.directSettings);
  1365. }
  1366. },
  1367. ipv4Domains: {
  1368. get: function () {
  1369. return this.templateRuleGetter({ outboundTag: "IPv4", property: "domain" });
  1370. },
  1371. set: function (newValue) {
  1372. this.templateRuleSetter({ outboundTag: "IPv4", property: "domain", data: newValue });
  1373. this.syncRulesWithOutbound("IPv4", this.ipv4Settings);
  1374. }
  1375. },
  1376. warpDomains: {
  1377. get: function () {
  1378. return this.templateRuleGetter({ outboundTag: "warp", property: "domain" });
  1379. },
  1380. set: function (newValue) {
  1381. this.templateRuleSetter({ outboundTag: "warp", property: "domain", data: newValue });
  1382. }
  1383. },
  1384. torrentSettings: {
  1385. get: function () {
  1386. return doAllItemsExist(this.settingsData.protocols.bittorrent, this.blockedProtocols);
  1387. },
  1388. set: function (newValue) {
  1389. if (newValue) {
  1390. this.blockedProtocols = [...this.blockedProtocols, ...this.settingsData.protocols.bittorrent];
  1391. } else {
  1392. this.blockedProtocols = this.blockedProtocols.filter(data => !this.settingsData.protocols.bittorrent.includes(data));
  1393. }
  1394. },
  1395. },
  1396. privateIpSettings: {
  1397. get: function () {
  1398. return doAllItemsExist(this.settingsData.ips.local, this.blockedIPs);
  1399. },
  1400. set: function (newValue) {
  1401. if (newValue) {
  1402. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.local];
  1403. } else {
  1404. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.local.includes(data));
  1405. }
  1406. },
  1407. },
  1408. AdsSettings: {
  1409. get: function () {
  1410. return doAllItemsExist(this.settingsData.domains.ads, this.blockedDomains);
  1411. },
  1412. set: function (newValue) {
  1413. if (newValue) {
  1414. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.ads];
  1415. } else {
  1416. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.ads.includes(data));
  1417. }
  1418. },
  1419. },
  1420. SecuritySettings: {
  1421. get: function () {
  1422. return doAllItemsExist(this.settingsData.domains.security, this.blockedDomains);
  1423. },
  1424. set: function (newValue) {
  1425. if (newValue) {
  1426. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.security];
  1427. } else {
  1428. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.security.includes(data));
  1429. }
  1430. },
  1431. },
  1432. SpeedTestSettings: {
  1433. get: function () {
  1434. return doAllItemsExist(this.settingsData.domains.speedtest, this.blockedDomains);
  1435. },
  1436. set: function (newValue) {
  1437. if (newValue) {
  1438. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.speedtest];
  1439. } else {
  1440. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.speedtest.includes(data));
  1441. }
  1442. },
  1443. },
  1444. familyProtectSettings: {
  1445. get: function () {
  1446. if (!this.templateSettings || !this.templateSettings.dns || !this.templateSettings.dns.servers) return false;
  1447. return doAllItemsExist(this.templateSettings.dns.servers, this.settingsData.familyProtectDNS.servers);
  1448. },
  1449. set: function (newValue) {
  1450. newTemplateSettings = this.templateSettings;
  1451. if (newValue) {
  1452. newTemplateSettings.dns = this.settingsData.familyProtectDNS;
  1453. } else {
  1454. delete newTemplateSettings.dns;
  1455. }
  1456. this.templateSettings = newTemplateSettings;
  1457. },
  1458. },
  1459. GoogleIPv4Settings: {
  1460. get: function () {
  1461. return doAllItemsExist(this.settingsData.domains.google, this.ipv4Domains);
  1462. },
  1463. set: function (newValue) {
  1464. if (newValue) {
  1465. this.ipv4Domains = [...this.ipv4Domains, ...this.settingsData.domains.google];
  1466. } else {
  1467. this.ipv4Domains = this.ipv4Domains.filter(data => !this.settingsData.domains.google.includes(data));
  1468. }
  1469. },
  1470. },
  1471. NetflixIPv4Settings: {
  1472. get: function () {
  1473. return doAllItemsExist(this.settingsData.domains.netflix, this.ipv4Domains);
  1474. },
  1475. set: function (newValue) {
  1476. if (newValue) {
  1477. this.ipv4Domains = [...this.ipv4Domains, ...this.settingsData.domains.netflix];
  1478. } else {
  1479. this.ipv4Domains = this.ipv4Domains.filter(data => !this.settingsData.domains.netflix.includes(data));
  1480. }
  1481. },
  1482. },
  1483. IRIpSettings: {
  1484. get: function () {
  1485. return doAllItemsExist(this.settingsData.ips.ir, this.blockedIPs);
  1486. },
  1487. set: function (newValue) {
  1488. if (newValue) {
  1489. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.ir];
  1490. } else {
  1491. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.ir.includes(data));
  1492. }
  1493. }
  1494. },
  1495. IRDomainSettings: {
  1496. get: function () {
  1497. return doAllItemsExist(this.settingsData.domains.ir, this.blockedDomains);
  1498. },
  1499. set: function (newValue) {
  1500. if (newValue) {
  1501. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.ir];
  1502. } else {
  1503. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.ir.includes(data));
  1504. }
  1505. }
  1506. },
  1507. ChinaIpSettings: {
  1508. get: function () {
  1509. return doAllItemsExist(this.settingsData.ips.cn, this.blockedIPs);
  1510. },
  1511. set: function (newValue) {
  1512. if (newValue) {
  1513. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.cn];
  1514. } else {
  1515. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.cn.includes(data));
  1516. }
  1517. }
  1518. },
  1519. ChinaDomainSettings: {
  1520. get: function () {
  1521. return doAllItemsExist(this.settingsData.domains.cn, this.blockedDomains);
  1522. },
  1523. set: function (newValue) {
  1524. if (newValue) {
  1525. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.cn];
  1526. } else {
  1527. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.cn.includes(data));
  1528. }
  1529. }
  1530. },
  1531. RussiaIpSettings: {
  1532. get: function () {
  1533. return doAllItemsExist(this.settingsData.ips.ru, this.blockedIPs);
  1534. },
  1535. set: function (newValue) {
  1536. if (newValue) {
  1537. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.ru];
  1538. } else {
  1539. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.ru.includes(data));
  1540. }
  1541. }
  1542. },
  1543. RussiaDomainSettings: {
  1544. get: function () {
  1545. return doAllItemsExist(this.settingsData.domains.ru, this.blockedDomains);
  1546. },
  1547. set: function (newValue) {
  1548. if (newValue) {
  1549. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.ru];
  1550. } else {
  1551. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.ru.includes(data));
  1552. }
  1553. }
  1554. },
  1555. VNIpSettings: {
  1556. get: function () {
  1557. return doAllItemsExist(this.settingsData.ips.vn, this.blockedIPs);
  1558. },
  1559. set: function (newValue) {
  1560. if (newValue) {
  1561. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.vn];
  1562. } else {
  1563. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.vn.includes(data));
  1564. }
  1565. }
  1566. },
  1567. VNDomainSettings: {
  1568. get: function () {
  1569. return doAllItemsExist(this.settingsData.domains.vn, this.blockedDomains);
  1570. },
  1571. set: function (newValue) {
  1572. if (newValue) {
  1573. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.vn];
  1574. } else {
  1575. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.vn.includes(data));
  1576. }
  1577. }
  1578. },
  1579. IRIpDirectSettings: {
  1580. get: function () {
  1581. return doAllItemsExist(this.settingsData.ips.ir, this.directIPs);
  1582. },
  1583. set: function (newValue) {
  1584. if (newValue) {
  1585. this.directIPs = [...this.directIPs, ...this.settingsData.ips.ir];
  1586. } else {
  1587. this.directIPs = this.directIPs.filter(data => !this.settingsData.ips.ir.includes(data));
  1588. }
  1589. }
  1590. },
  1591. IRDomainDirectSettings: {
  1592. get: function () {
  1593. return doAllItemsExist(this.settingsData.domains.ir, this.directDomains);
  1594. },
  1595. set: function (newValue) {
  1596. if (newValue) {
  1597. this.directDomains = [...this.directDomains, ...this.settingsData.domains.ir];
  1598. } else {
  1599. this.directDomains = this.directDomains.filter(data => !this.settingsData.domains.ir.includes(data));
  1600. }
  1601. }
  1602. },
  1603. ChinaIpDirectSettings: {
  1604. get: function () {
  1605. return doAllItemsExist(this.settingsData.ips.cn, this.directIPs);
  1606. },
  1607. set: function (newValue) {
  1608. if (newValue) {
  1609. this.directIPs = [...this.directIPs, ...this.settingsData.ips.cn];
  1610. } else {
  1611. this.directIPs = this.directIPs.filter(data => !this.settingsData.ips.cn.includes(data));
  1612. }
  1613. }
  1614. },
  1615. ChinaDomainDirectSettings: {
  1616. get: function () {
  1617. return doAllItemsExist(this.settingsData.domains.cn, this.directDomains);
  1618. },
  1619. set: function (newValue) {
  1620. if (newValue) {
  1621. this.directDomains = [...this.directDomains, ...this.settingsData.domains.cn];
  1622. } else {
  1623. this.directDomains = this.directDomains.filter(data => !this.settingsData.domains.cn.includes(data));
  1624. }
  1625. }
  1626. },
  1627. RussiaIpDirectSettings: {
  1628. get: function () {
  1629. return doAllItemsExist(this.settingsData.ips.ru, this.directIPs);
  1630. },
  1631. set: function (newValue) {
  1632. if (newValue) {
  1633. this.directIPs = [...this.directIPs, ...this.settingsData.ips.ru];
  1634. } else {
  1635. this.directIPs = this.directIPs.filter(data => !this.settingsData.ips.ru.includes(data));
  1636. }
  1637. }
  1638. },
  1639. RussiaDomainDirectSettings: {
  1640. get: function () {
  1641. return doAllItemsExist(this.settingsData.domains.ru, this.directDomains);
  1642. },
  1643. set: function (newValue) {
  1644. if (newValue) {
  1645. this.directDomains = [...this.directDomains, ...this.settingsData.domains.ru];
  1646. } else {
  1647. this.directDomains = this.directDomains.filter(data => !this.settingsData.domains.ru.includes(data));
  1648. }
  1649. }
  1650. },
  1651. VNIpDirectSettings: {
  1652. get: function () {
  1653. return doAllItemsExist(this.settingsData.ips.vn, this.directIPs);
  1654. },
  1655. set: function (newValue) {
  1656. if (newValue) {
  1657. this.directIPs = [...this.directIPs, ...this.settingsData.ips.vn];
  1658. } else {
  1659. this.directIPs = this.directIPs.filter(data => !this.settingsData.ips.vn.includes(data));
  1660. }
  1661. }
  1662. },
  1663. VNDomainDirectSettings: {
  1664. get: function () {
  1665. return doAllItemsExist(this.settingsData.domains.vn, this.directDomains);
  1666. },
  1667. set: function (newValue) {
  1668. if (newValue) {
  1669. this.directDomains = [...this.directDomains, ...this.settingsData.domains.vn];
  1670. } else {
  1671. this.directDomains = this.directDomains.filter(data => !this.settingsData.domains.vn.includes(data));
  1672. }
  1673. }
  1674. },
  1675. WarpExist: {
  1676. get: function() {
  1677. return this.templateSettings ? this.templateSettings.outbounds.findIndex((o) => o.tag == "warp")>=0 : false;
  1678. },
  1679. },
  1680. GoogleWARPSettings: {
  1681. get: function () {
  1682. return doAllItemsExist(this.settingsData.domains.google, this.warpDomains);
  1683. },
  1684. set: function (newValue) {
  1685. if (newValue) {
  1686. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.google];
  1687. } else {
  1688. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.google.includes(data));
  1689. }
  1690. },
  1691. },
  1692. OpenAIWARPSettings: {
  1693. get: function () {
  1694. return doAllItemsExist(this.settingsData.domains.openai, this.warpDomains);
  1695. },
  1696. set: function (newValue) {
  1697. if (newValue) {
  1698. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.openai];
  1699. } else {
  1700. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.openai.includes(data));
  1701. }
  1702. },
  1703. },
  1704. NetflixWARPSettings: {
  1705. get: function () {
  1706. return doAllItemsExist(this.settingsData.domains.netflix, this.warpDomains);
  1707. },
  1708. set: function (newValue) {
  1709. if (newValue) {
  1710. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.netflix];
  1711. } else {
  1712. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.netflix.includes(data));
  1713. }
  1714. },
  1715. },
  1716. SpotifyWARPSettings: {
  1717. get: function () {
  1718. return doAllItemsExist(this.settingsData.domains.spotify, this.warpDomains);
  1719. },
  1720. set: function (newValue) {
  1721. if (newValue) {
  1722. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.spotify];
  1723. } else {
  1724. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.spotify.includes(data));
  1725. }
  1726. },
  1727. },
  1728. },
  1729. });
  1730. </script>
  1731. </body>
  1732. </html>