xray.html 105 KB

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