1
0

xray.html 103 KB

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