xray.html 106 KB

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