xray.html 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629
  1. {{ template "page/head_start" .}}
  2. <link rel="stylesheet"
  3. href="{{ .base_path }}assets/codemirror/codemirror.min.css?{{ .cur_ver }}">
  4. <link rel="stylesheet"
  5. href="{{ .base_path }}assets/codemirror/fold/foldgutter.css">
  6. <link rel="stylesheet"
  7. href="{{ .base_path }}assets/codemirror/xq.min.css?{{ .cur_ver }}">
  8. <link rel="stylesheet" href="{{ .base_path }}assets/codemirror/lint/lint.css">
  9. {{ template "page/head_end" .}}
  10. {{ template "page/body_start" .}}
  11. <a-layout id="app" v-cloak :class="themeSwitcher.currentTheme + ' xray-page'">
  12. <a-sidebar></a-sidebar>
  13. <a-layout id="content-layout">
  14. <a-layout-content>
  15. <a-spin :spinning="loadingStates.spinning" :delay="500"
  16. tip='{{ i18n "loading"}}' size="large">
  17. <transition name="list" appear>
  18. <a-alert type="error" v-if="showAlert && loadingStates.fetched"
  19. :style="{ marginBottom: '10px' }"
  20. message='{{ i18n "secAlertTitle" }}' color="red"
  21. description='{{ i18n "secAlertSsl" }}' show-icon closable>
  22. </a-alert>
  23. </transition>
  24. <transition name="list" appear>
  25. <a-row v-if="!loadingStates.fetched">
  26. <div :style="{ minHeight: 'calc(100vh - 120px)' }"></div>
  27. </a-row>
  28. <a-row :gutter="[isMobile ? 8 : 16, isMobile ? 0 : 12]" v-else>
  29. <a-col>
  30. <a-card hoverable>
  31. <a-row
  32. :style="{ display: 'flex', flexWrap: 'wrap', alignItems: 'center' }">
  33. <a-col :xs="24" :sm="10" :style="{ padding: '4px' }">
  34. <a-space direction="horizontal">
  35. <a-button type="primary" :disabled="saveBtnDisable"
  36. @click="updateXraySetting">
  37. {{ i18n "pages.xray.save" }}
  38. </a-button>
  39. <a-button type="danger" :disabled="!saveBtnDisable"
  40. @click="restartXray">
  41. {{ i18n "pages.xray.restart" }}
  42. </a-button>
  43. <a-popover v-if="restartResult"
  44. :overlay-class-name="themeSwitcher.currentTheme">
  45. <span slot="title">{{ i18n
  46. "pages.index.xrayErrorPopoverTitle" }}</span>
  47. <template slot="content">
  48. <span :style="{ maxWidth: '400px' }"
  49. v-for="line in restartResult.split('\n')">[[ line
  50. ]]</span>
  51. </template>
  52. <a-icon type="question-circle"></a-icon>
  53. </a-popover>
  54. </a-space>
  55. </a-col>
  56. <a-col :xs="24" :sm="14">
  57. <template>
  58. <div>
  59. <a-back-top
  60. :target="() => document.getElementById('content-layout')"
  61. visibility-height="200"></a-back-top>
  62. <a-alert type="warning"
  63. :style="{ float: 'right', width: 'fit-content' }"
  64. message='{{ i18n "pages.settings.infoDesc" }}'
  65. show-icon>
  66. </a-alert>
  67. </div>
  68. </template>
  69. </a-col>
  70. </a-row>
  71. </a-card>
  72. </a-col>
  73. <a-col>
  74. <a-tabs default-active-key="tpl-basic"
  75. @change="(activeKey) => { this.changePage(activeKey); }"
  76. :class="themeSwitcher.currentTheme">
  77. <a-tab-pane key="tpl-basic" :style="{ paddingTop: '20px' }">
  78. <template #tab>
  79. <a-icon type="setting"></a-icon>
  80. <span>{{ i18n "pages.xray.basicTemplate"}}</span>
  81. </template>
  82. {{ template "settings/xray/basics" . }}
  83. </a-tab-pane>
  84. <a-tab-pane key="tpl-routing" :style="{ paddingTop: '20px' }">
  85. <template #tab>
  86. <a-icon type="swap"></a-icon>
  87. <span>{{ i18n "pages.xray.Routings"}}</span>
  88. </template>
  89. {{ template "settings/xray/routing" . }}
  90. </a-tab-pane>
  91. <a-tab-pane key="tpl-outbound" force-render="true">
  92. <template #tab>
  93. <a-icon type="upload"></a-icon>
  94. <span>{{ i18n "pages.xray.Outbounds"}}</span>
  95. </template>
  96. {{ template "settings/xray/outbounds" . }}
  97. </a-tab-pane>
  98. <a-tab-pane key="tpl-reverse" :style="{ paddingTop: '20px' }"
  99. force-render="true">
  100. <template #tab>
  101. <a-icon type="import"></a-icon>
  102. <span>{{ i18n "pages.xray.outbound.reverse"}}</span>
  103. </template>
  104. {{ template "settings/xray/reverse" . }}
  105. </a-tab-pane>
  106. <a-tab-pane key="tpl-balancer" :style="{ paddingTop: '20px' }"
  107. force-render="true">
  108. <template #tab>
  109. <a-icon type="cluster"></a-icon>
  110. <span>{{ i18n "pages.xray.Balancers"}}</span>
  111. </template>
  112. {{ template "settings/xray/balancers" . }}
  113. </a-tab-pane>
  114. <a-tab-pane key="tpl-dns" :style="{ paddingTop: '20px' }"
  115. force-render="true">
  116. <template #tab>
  117. <a-icon type="database"></a-icon>
  118. <span>DNS</span>
  119. </template>
  120. {{ template "settings/xray/dns" . }}
  121. </a-tab-pane>
  122. <a-tab-pane key="tpl-advanced" force-render="true">
  123. <template #tab>
  124. <a-icon type="code"></a-icon>
  125. <span>{{ i18n "pages.xray.advancedTemplate"}}</span>
  126. </template>
  127. {{ template "settings/xray/advanced" . }}
  128. </a-tab-pane>
  129. </a-tabs>
  130. </a-col>
  131. </a-row>
  132. </transition>
  133. </a-spin>
  134. </a-layout-content>
  135. </a-layout>
  136. </a-layout>
  137. {{template "page/body_scripts" .}}
  138. <script
  139. src="{{ .base_path }}assets/js/model/outbound.js?{{ .cur_ver }}"></script>
  140. <script
  141. src="{{ .base_path }}assets/codemirror/codemirror.min.js?{{ .cur_ver }}"></script>
  142. <script src="{{ .base_path }}assets/codemirror/javascript.js"></script>
  143. <script src="{{ .base_path }}assets/codemirror/jshint.js"></script>
  144. <script src="{{ .base_path }}assets/codemirror/jsonlint.js"></script>
  145. <script src="{{ .base_path }}assets/codemirror/lint/lint.js"></script>
  146. <script
  147. src="{{ .base_path }}assets/codemirror/lint/javascript-lint.js"></script>
  148. <script
  149. src="{{ .base_path }}assets/codemirror/hint/javascript-hint.js"></script>
  150. <script src="{{ .base_path }}assets/codemirror/fold/foldcode.js"></script>
  151. <script src="{{ .base_path }}assets/codemirror/fold/foldgutter.js"></script>
  152. <script src="{{ .base_path }}assets/codemirror/fold/brace-fold.js"></script>
  153. {{template "component/aSidebar" .}}
  154. {{template "component/aThemeSwitch" .}}
  155. {{template "component/aTableSortable" .}}
  156. {{template "component/aSettingListItem" .}}
  157. {{template "modals/ruleModal"}}
  158. {{template "modals/outModal"}}
  159. {{template "modals/reverseModal"}}
  160. {{template "modals/balancerModal"}}
  161. {{template "modals/dnsModal"}}
  162. {{template "modals/dnsPresetsModal"}}
  163. {{template "modals/fakednsModal"}}
  164. {{template "modals/warpModal"}}
  165. {{template "modals/nordModal"}}
  166. <script>
  167. const rulesColumns = [
  168. { title: "#", align: 'center', width: 15, scopedSlots: { customRender: 'action' } },
  169. {
  170. title: '{{ i18n "pages.xray.rules.source"}}', children: [
  171. { title: 'IP', dataIndex: "sourceIP", align: 'center', width: 20, ellipsis: true },
  172. { title: '{{ i18n "pages.inbounds.port" }}', dataIndex: 'sourcePort', align: 'center', width: 10, ellipsis: true },
  173. { title: 'VLESS Route', dataIndex: 'vlessRoute', align: 'center', width: 15, ellipsis: true }]
  174. },
  175. {
  176. title: '{{ i18n "pages.inbounds.network"}}', children: [
  177. { title: 'L4', dataIndex: 'network', align: 'center', width: 10 },
  178. { title: '{{ i18n "protocol" }}', dataIndex: 'protocol', align: 'center', width: 15, ellipsis: true },
  179. { title: 'Attrs', dataIndex: 'attrs', align: 'center', width: 10, ellipsis: true }]
  180. },
  181. {
  182. title: '{{ i18n "pages.xray.rules.dest"}}', children: [
  183. { title: 'IP', dataIndex: 'ip', align: 'center', width: 20, ellipsis: true },
  184. { title: '{{ i18n "pages.xray.outbound.domain" }}', dataIndex: 'domain', align: 'center', width: 20, ellipsis: true },
  185. { title: '{{ i18n "pages.inbounds.port" }}', dataIndex: 'port', align: 'center', width: 10, ellipsis: true }]
  186. },
  187. {
  188. title: '{{ i18n "pages.xray.rules.inbound"}}', children: [
  189. { title: '{{ i18n "pages.xray.outbound.tag" }}', dataIndex: 'inboundTag', align: 'center', width: 15, ellipsis: true },
  190. { title: '{{ i18n "pages.inbounds.client" }}', dataIndex: 'user', align: 'center', width: 20, ellipsis: true }]
  191. },
  192. { title: '{{ i18n "pages.xray.rules.outbound"}}', dataIndex: 'outboundTag', align: 'center', width: 17 },
  193. { title: '{{ i18n "pages.xray.rules.balancer"}}', dataIndex: 'balancerTag', align: 'center', width: 15 },
  194. ];
  195. const rulesMobileColumns = [
  196. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  197. { title: '{{ i18n "pages.xray.rules.inbound"}}', align: 'center', width: 50, ellipsis: true, scopedSlots: { customRender: 'inbound' } },
  198. { title: '{{ i18n "pages.xray.rules.outbound"}}', align: 'center', width: 50, ellipsis: true, scopedSlots: { customRender: 'outbound' } },
  199. { title: '{{ i18n "pages.xray.rules.info"}}', align: 'center', width: 50, ellipsis: true, scopedSlots: { customRender: 'info' } },
  200. ];
  201. const outboundColumns = [
  202. { title: "#", align: 'center', width: 60, scopedSlots: { customRender: 'action' } },
  203. { title: '{{ i18n "pages.xray.outbound.tag"}}', dataIndex: 'tag', align: 'center', width: 50 },
  204. { title: '{{ i18n "protocol"}}', align: 'center', width: 50, scopedSlots: { customRender: 'protocol' } },
  205. { title: '{{ i18n "pages.xray.outbound.address"}}', align: 'center', width: 50, scopedSlots: { customRender: 'address' } },
  206. { title: '{{ i18n "pages.inbounds.traffic" }}', align: 'center', width: 50, scopedSlots: { customRender: 'traffic' } },
  207. { title: '{{ i18n "pages.xray.outbound.testResult" }}', align: 'center', width: 120, scopedSlots: { customRender: 'testResult' } },
  208. { title: '{{ i18n "pages.xray.outbound.test" }}', align: 'center', width: 60, scopedSlots: { customRender: 'test' } },
  209. ];
  210. const reverseColumns = [
  211. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  212. { title: '{{ i18n "pages.xray.outbound.type"}}', dataIndex: 'type', align: 'center', width: 50 },
  213. { title: '{{ i18n "pages.xray.outbound.tag"}}', dataIndex: 'tag', align: 'center', width: 50 },
  214. { title: '{{ i18n "pages.xray.outbound.domain"}}', dataIndex: 'domain', align: 'center', width: 50 },
  215. ];
  216. const balancerColumns = [
  217. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  218. { title: '{{ i18n "pages.xray.balancer.tag"}}', dataIndex: 'tag', align: 'center', width: 50 },
  219. { title: '{{ i18n "pages.xray.balancer.balancerStrategy"}}', align: 'center', width: 50, scopedSlots: { customRender: 'strategy' } },
  220. { title: '{{ i18n "pages.xray.balancer.balancerSelectors"}}', align: 'center', width: 100, scopedSlots: { customRender: 'selector' } },
  221. ];
  222. const dnsColumns = [
  223. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  224. { title: '{{ i18n "pages.xray.outbound.address"}}', align: 'center', width: 50, scopedSlots: { customRender: 'address' } },
  225. { title: '{{ i18n "pages.xray.dns.domains"}}', align: 'center', width: 50, scopedSlots: { customRender: 'domain' } },
  226. { title: '{{ i18n "pages.xray.dns.expectIPs"}}', align: 'center', width: 50, scopedSlots: { customRender: 'expectIPs' } },
  227. ];
  228. const fakednsColumns = [
  229. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  230. { title: '{{ i18n "pages.xray.fakedns.ipPool"}}', dataIndex: 'ipPool', align: 'center', width: 50 },
  231. { title: '{{ i18n "pages.xray.fakedns.poolSize"}}', dataIndex: 'poolSize', align: 'center', width: 50 },
  232. ];
  233. const app = new Vue({
  234. delimiters: ['[[', ']]'],
  235. mixins: [MediaQueryMixin],
  236. el: '#app',
  237. data: {
  238. themeSwitcher,
  239. isDarkTheme: themeSwitcher.isDarkTheme,
  240. loadingStates: {
  241. fetched: false,
  242. spinning: false
  243. },
  244. oldXraySetting: '',
  245. xraySetting: '',
  246. outboundTestUrl: 'https://www.google.com/generate_204',
  247. oldOutboundTestUrl: 'https://www.google.com/generate_204',
  248. inboundTags: [],
  249. outboundsTraffic: [],
  250. outboundTestStates: {}, // Track testing state and results for each outbound
  251. saveBtnDisable: true,
  252. refreshing: false,
  253. restartResult: '',
  254. showAlert: false,
  255. customGeoAliasLabelSuffix: '{{ i18n "pages.index.customGeoAliasLabelSuffix" }}',
  256. advSettings: 'xraySetting',
  257. obsSettings: '',
  258. cm: null,
  259. cmOptions: {
  260. lineNumbers: true,
  261. mode: "application/json",
  262. lint: true,
  263. styleActiveLine: true,
  264. matchBrackets: true,
  265. theme: "xq",
  266. autoCloseTags: true,
  267. lineWrapping: true,
  268. indentUnit: 2,
  269. indentWithTabs: true,
  270. smartIndent: true,
  271. tabSize: 2,
  272. lineWiseCopyCut: false,
  273. foldGutter: true,
  274. gutters: [
  275. "CodeMirror-lint-markers",
  276. "CodeMirror-linenumbers",
  277. "CodeMirror-foldgutter",
  278. ],
  279. },
  280. ipv4Settings: {
  281. tag: "IPv4",
  282. protocol: "freedom",
  283. settings: {
  284. domainStrategy: "UseIPv4"
  285. }
  286. },
  287. directSettings: {
  288. tag: "direct",
  289. protocol: "freedom"
  290. },
  291. routingDomainStrategies: ["AsIs", "IPIfNonMatch", "IPOnDemand"],
  292. log: {
  293. loglevel: ["none", "debug", "info", "warning", "error"],
  294. access: ["none", "./access.log"],
  295. error: ["none", "./error.log"],
  296. dnsLog: false,
  297. maskAddress: ["quarter", "half", "full"],
  298. },
  299. settingsData: {
  300. protocols: {
  301. bittorrent: ["bittorrent"],
  302. },
  303. IPsOptions: [
  304. { label: 'Private IPs', value: 'geoip:private' },
  305. { label: '🇮🇷 Iran', value: 'ext:geoip_IR.dat:ir' },
  306. { label: '🇨🇳 China', value: 'geoip:cn' },
  307. { label: '🇷🇺 Russia', value: 'ext:geoip_RU.dat:ru' },
  308. { label: '🇻🇳 Vietnam', value: 'geoip:vn' },
  309. { label: '🇪🇸 Spain', value: 'geoip:es' },
  310. { label: '🇮🇩 Indonesia', value: 'geoip:id' },
  311. { label: '🇺🇦 Ukraine', value: 'geoip:ua' },
  312. { label: '🇹🇷 Türkiye', value: 'geoip:tr' },
  313. { label: '🇧🇷 Brazil', value: 'geoip:br' },
  314. ],
  315. DomainsOptions: [
  316. { label: '🇮🇷 Iran', value: 'ext:geosite_IR.dat:ir' },
  317. { label: '🇮🇷 .ir', value: 'regexp:.*\\.ir$' },
  318. { label: '🇮🇷 .ایران', value: 'regexp:.*\\.xn--mgba3a4f16a$' },
  319. { label: '🇨🇳 China', value: 'geosite:cn' },
  320. { label: '🇨🇳 .cn', value: 'regexp:.*\\.cn$' },
  321. { label: '🇷🇺 Russia', value: 'ext:geosite_RU.dat:ru-available-only-inside' },
  322. { label: '🇷🇺 .ru', value: 'regexp:.*\\.ru$' },
  323. { label: '🇷🇺 .su', value: 'regexp:.*\\.su$' },
  324. { label: '🇷🇺 .рф', value: 'regexp:.*\\.xn--p1ai$' },
  325. { label: '🇻🇳 .vn', value: 'regexp:.*\\.vn$' },
  326. ],
  327. BlockDomainsOptions: [
  328. { label: 'Ads All', value: 'geosite:category-ads-all' },
  329. { label: 'Ads IR 🇮🇷', value: 'ext:geosite_IR.dat:category-ads-all' },
  330. { label: 'Ads RU 🇷🇺', value: 'ext:geosite_RU.dat:category-ads-all' },
  331. { label: 'Malware 🇮🇷', value: 'ext:geosite_IR.dat:malware' },
  332. { label: 'Phishing 🇮🇷', value: 'ext:geosite_IR.dat:phishing' },
  333. { label: 'Cryptominers 🇮🇷', value: 'ext:geosite_IR.dat:cryptominers' },
  334. { label: 'Adult +18', value: 'geosite:category-porn' },
  335. { label: '🇮🇷 Iran', value: 'ext:geosite_IR.dat:ir' },
  336. { label: '🇮🇷 .ir', value: 'regexp:.*\\.ir$' },
  337. { label: '🇮🇷 .ایران', value: 'regexp:.*\\.xn--mgba3a4f16a$' },
  338. { label: '🇨🇳 China', value: 'geosite:cn' },
  339. { label: '🇨🇳 .cn', value: 'regexp:.*\\.cn$' },
  340. { label: '🇷🇺 Russia', value: 'ext:geosite_RU.dat:ru-available-only-inside' },
  341. { label: '🇷🇺 .ru', value: 'regexp:.*\\.ru$' },
  342. { label: '🇷🇺 .su', value: 'regexp:.*\\.su$' },
  343. { label: '🇷🇺 .рф', value: 'regexp:.*\\.xn--p1ai$' },
  344. { label: '🇻🇳 .vn', value: 'regexp:.*\\.vn$' },
  345. ],
  346. ServicesOptions: [
  347. { label: 'Apple', value: 'geosite:apple' },
  348. { label: 'Meta', value: 'geosite:meta' },
  349. { label: 'Google', value: 'geosite:google' },
  350. { label: 'OpenAI', value: 'geosite:openai' },
  351. { label: 'Spotify', value: 'geosite:spotify' },
  352. { label: 'Netflix', value: 'geosite:netflix' },
  353. { label: 'Reddit', value: 'geosite:reddit' },
  354. { label: 'Speedtest', value: 'geosite:speedtest' },
  355. ]
  356. },
  357. defaultObservatory: {
  358. subjectSelector: [],
  359. probeURL: "https://www.google.com/generate_204",
  360. probeInterval: "1m",
  361. enableConcurrency: true
  362. },
  363. defaultBurstObservatory: {
  364. subjectSelector: [],
  365. pingConfig: {
  366. destination: "https://www.google.com/generate_204",
  367. interval: "1m",
  368. connectivity: "http://connectivitycheck.platform.hicloud.com/generate_204",
  369. timeout: "5s",
  370. sampling: 2
  371. }
  372. }
  373. },
  374. methods: {
  375. loading(spinning = true) {
  376. this.loadingStates.spinning = spinning;
  377. },
  378. async getOutboundsTraffic() {
  379. const msg = await HttpUtil.get("/panel/xray/getOutboundsTraffic");
  380. if (msg.success) {
  381. this.outboundsTraffic = msg.obj;
  382. }
  383. },
  384. async getXraySetting() {
  385. const msg = await HttpUtil.post("/panel/xray/");
  386. if (msg.success) {
  387. if (!this.loadingStates.fetched) {
  388. this.loadingStates.fetched = true
  389. }
  390. result = JSON.parse(msg.obj);
  391. xs = JSON.stringify(result.xraySetting, null, 2);
  392. this.oldXraySetting = xs;
  393. this.xraySetting = xs;
  394. this.inboundTags = result.inboundTags;
  395. this.outboundTestUrl = result.outboundTestUrl || 'https://www.google.com/generate_204';
  396. this.oldOutboundTestUrl = this.outboundTestUrl;
  397. this.saveBtnDisable = true;
  398. }
  399. },
  400. async updateXraySetting() {
  401. this.loading(true);
  402. const msg = await HttpUtil.post("/panel/xray/update", {
  403. xraySetting: this.xraySetting,
  404. outboundTestUrl: this.outboundTestUrl || 'https://www.google.com/generate_204'
  405. });
  406. this.loading(false);
  407. if (msg.success) {
  408. await this.getXraySetting();
  409. }
  410. },
  411. async restartXray() {
  412. this.loading(true);
  413. const msg = await HttpUtil.post("/panel/api/server/restartXrayService");
  414. this.loading(false);
  415. if (msg.success) {
  416. await PromiseUtil.sleep(500);
  417. await this.getXrayResult();
  418. }
  419. this.loading(false);
  420. },
  421. async getXrayResult() {
  422. const msg = await HttpUtil.get("/panel/xray/getXrayResult");
  423. if (msg.success) {
  424. this.restartResult = msg.obj;
  425. if (msg.obj.length > 1) Vue.prototype.$message.error(msg.obj);
  426. }
  427. },
  428. async resetXrayConfigToDefault() {
  429. this.loading(true);
  430. const msg = await HttpUtil.get("/panel/setting/getDefaultJsonConfig");
  431. this.loading(false);
  432. if (msg.success) {
  433. this.templateSettings = JSON.parse(JSON.stringify(msg.obj, null, 2));
  434. this.saveBtnDisable = true;
  435. }
  436. },
  437. changePage(pageKey) {
  438. if (pageKey == 'tpl-advanced') this.changeCode();
  439. if (pageKey == 'tpl-balancer') this.changeObsCode();
  440. },
  441. syncRulesWithOutbound(tag, setting) {
  442. const newTemplateSettings = this.templateSettings;
  443. const haveRules = newTemplateSettings.routing.rules.some((r) => r?.outboundTag === tag);
  444. const outboundIndex = newTemplateSettings.outbounds.findIndex((o) => o.tag === tag);
  445. if (!haveRules && outboundIndex > 0) {
  446. newTemplateSettings.outbounds.splice(outboundIndex);
  447. }
  448. if (haveRules && outboundIndex < 0) {
  449. newTemplateSettings.outbounds.push(setting);
  450. }
  451. this.templateSettings = newTemplateSettings;
  452. },
  453. templateRuleGetter(routeSettings) {
  454. const { property, outboundTag } = routeSettings;
  455. let result = [];
  456. if (this.templateSettings != null) {
  457. this.templateSettings.routing.rules.forEach(
  458. (routingRule) => {
  459. if (
  460. routingRule.hasOwnProperty(property) &&
  461. routingRule.hasOwnProperty("outboundTag") &&
  462. routingRule.outboundTag === outboundTag
  463. ) {
  464. result.push(...routingRule[property]);
  465. }
  466. }
  467. );
  468. }
  469. return result;
  470. },
  471. templateRuleSetter(routeSettings) {
  472. const { data, property, outboundTag } = routeSettings;
  473. const oldTemplateSettings = this.templateSettings;
  474. const newTemplateSettings = oldTemplateSettings;
  475. currentProperty = this.templateRuleGetter({ outboundTag, property })
  476. if (currentProperty.length == 0) {
  477. const propertyRule = {
  478. type: "field",
  479. outboundTag,
  480. [property]: data
  481. };
  482. newTemplateSettings.routing.rules.push(propertyRule);
  483. }
  484. else {
  485. const newRules = [];
  486. insertedOnce = false;
  487. newTemplateSettings.routing.rules.forEach(
  488. (routingRule) => {
  489. if (
  490. routingRule.hasOwnProperty(property) &&
  491. routingRule.hasOwnProperty("outboundTag") &&
  492. routingRule.outboundTag === outboundTag
  493. ) {
  494. if (!insertedOnce && data.length > 0) {
  495. insertedOnce = true;
  496. routingRule[property] = data;
  497. newRules.push(routingRule);
  498. }
  499. }
  500. else {
  501. newRules.push(routingRule);
  502. }
  503. }
  504. );
  505. newTemplateSettings.routing.rules = newRules;
  506. }
  507. this.templateSettings = newTemplateSettings;
  508. },
  509. changeCode() {
  510. if (this.cm != null) {
  511. this.cm.toTextArea();
  512. }
  513. textAreaObj = document.getElementById('xraySetting');
  514. textAreaObj.value = this[this.advSettings];
  515. this.cm = CodeMirror.fromTextArea(textAreaObj, this.cmOptions);
  516. this.cm.on('change', editor => {
  517. value = editor.getValue();
  518. if (this.isJsonString(value)) {
  519. this[this.advSettings] = value;
  520. }
  521. });
  522. },
  523. changeObsCode() {
  524. if (this.cm != null) {
  525. this.cm.toTextArea();
  526. }
  527. if (this.obsSettings == '') {
  528. this.cm = null;
  529. return
  530. }
  531. textAreaObj = document.getElementById('obsSetting');
  532. textAreaObj.value = this[this.obsSettings];
  533. this.cm = CodeMirror.fromTextArea(textAreaObj, this.cmOptions);
  534. this.cm.on('change', editor => {
  535. value = editor.getValue();
  536. if (this.isJsonString(value)) {
  537. this[this.obsSettings] = value;
  538. }
  539. });
  540. },
  541. isJsonString(str) {
  542. try {
  543. JSON.parse(str);
  544. } catch (e) {
  545. return false;
  546. }
  547. return true;
  548. },
  549. findOutboundTraffic(o) {
  550. for (const otraffic of this.outboundsTraffic) {
  551. if (otraffic.tag == o.tag) {
  552. return `↑ ${SizeFormatter.sizeFormat(otraffic.up)} / ${SizeFormatter.sizeFormat(otraffic.down)} ↓`
  553. }
  554. }
  555. return `${SizeFormatter.sizeFormat(0)} / ${SizeFormatter.sizeFormat(0)}`
  556. },
  557. findOutboundAddress(o) {
  558. serverObj = null;
  559. switch (o.protocol) {
  560. case Protocols.VMess:
  561. serverObj = o.settings.vnext;
  562. break;
  563. case Protocols.VLESS:
  564. return [o.settings?.address + ':' + o.settings?.port];
  565. case Protocols.HTTP:
  566. case Protocols.Socks:
  567. case Protocols.Shadowsocks:
  568. case Protocols.Trojan:
  569. serverObj = o.settings.servers;
  570. break;
  571. case Protocols.DNS:
  572. return [o.settings?.address + ':' + o.settings?.port];
  573. case Protocols.Wireguard:
  574. return o.settings.peers.map(peer => peer.endpoint);
  575. default:
  576. return null;
  577. }
  578. return serverObj ? serverObj.map(obj => obj.address + ':' + obj.port) : null;
  579. },
  580. addOutbound() {
  581. outModal.show({
  582. title: '{{ i18n "pages.xray.outbound.addOutbound"}}',
  583. okText: '{{ i18n "pages.xray.outbound.addOutbound" }}',
  584. confirm: (outbound) => {
  585. outModal.loading();
  586. if (outbound.tag.length > 0) {
  587. this.templateSettings.outbounds.push(outbound);
  588. this.outboundSettings = JSON.stringify(this.templateSettings.outbounds);
  589. }
  590. outModal.close();
  591. },
  592. isEdit: false,
  593. tags: this.templateSettings.outbounds.map(obj => obj.tag)
  594. });
  595. },
  596. editOutbound(index) {
  597. outModal.show({
  598. title: '{{ i18n "pages.xray.outbound.editOutbound"}} ' + (index + 1),
  599. outbound: app.templateSettings.outbounds[index],
  600. confirm: (outbound) => {
  601. outModal.loading();
  602. this.templateSettings.outbounds[index] = outbound;
  603. this.outboundSettings = JSON.stringify(this.templateSettings.outbounds);
  604. outModal.close();
  605. },
  606. isEdit: true,
  607. tags: this.outboundData.filter((o) => o.key != index).map(obj => obj.tag)
  608. });
  609. },
  610. deleteOutbound(index) {
  611. outbounds = this.templateSettings.outbounds;
  612. outbounds.splice(index, 1);
  613. this.outboundSettings = JSON.stringify(outbounds);
  614. },
  615. setFirstOutbound(index) {
  616. outbounds = this.templateSettings.outbounds;
  617. outbounds.splice(0, 0, outbounds.splice(index, 1)[0]);
  618. this.outboundSettings = JSON.stringify(outbounds);
  619. },
  620. async testOutbound(index) {
  621. const outbound = this.templateSettings.outbounds[index];
  622. if (!outbound) {
  623. Vue.prototype.$message.error('{{ i18n "pages.xray.outbound.testError" }}');
  624. return;
  625. }
  626. if (outbound.protocol === 'blackhole' || outbound.tag === 'blocked') {
  627. Vue.prototype.$message.warning('{{ i18n "pages.xray.outbound.testError" }}: blocked/blackhole outbound');
  628. return;
  629. }
  630. // Initialize test state for this outbound if not exists
  631. if (!this.outboundTestStates[index]) {
  632. this.$set(this.outboundTestStates, index, {
  633. testing: false,
  634. result: null
  635. });
  636. }
  637. // Set testing state
  638. this.$set(this.outboundTestStates[index], 'testing', true);
  639. this.$set(this.outboundTestStates[index], 'result', null);
  640. try {
  641. const outboundJSON = JSON.stringify(outbound);
  642. const allOutboundsJSON = JSON.stringify(this.templateSettings.outbounds || []);
  643. const msg = await HttpUtil.post("/panel/xray/testOutbound", {
  644. outbound: outboundJSON,
  645. allOutbounds: allOutboundsJSON
  646. });
  647. // Update test state
  648. this.$set(this.outboundTestStates[index], 'testing', false);
  649. if (msg.success && msg.obj) {
  650. const result = msg.obj;
  651. this.$set(this.outboundTestStates[index], 'result', result);
  652. if (result.success) {
  653. Vue.prototype.$message.success(
  654. `{{ i18n "pages.xray.outbound.testSuccess" }}: ${result.delay}ms (${result.statusCode})`
  655. );
  656. } else {
  657. Vue.prototype.$message.error(
  658. `{{ i18n "pages.xray.outbound.testFailed" }}: ${result.error || 'Unknown error'}`
  659. );
  660. }
  661. } else {
  662. this.$set(this.outboundTestStates[index], 'result', {
  663. success: false,
  664. error: msg.msg || '{{ i18n "pages.xray.outbound.testError" }}'
  665. });
  666. Vue.prototype.$message.error(msg.msg || '{{ i18n "pages.xray.outbound.testError" }}');
  667. }
  668. } catch (error) {
  669. this.$set(this.outboundTestStates[index], 'testing', false);
  670. this.$set(this.outboundTestStates[index], 'result', {
  671. success: false,
  672. error: error.message || '{{ i18n "pages.xray.outbound.testError" }}'
  673. });
  674. Vue.prototype.$message.error('{{ i18n "pages.xray.outbound.testError" }}: ' + error.message);
  675. }
  676. },
  677. addReverse() {
  678. reverseModal.show({
  679. title: '{{ i18n "pages.xray.outbound.addReverse"}}',
  680. okText: '{{ i18n "pages.xray.outbound.addReverse" }}',
  681. confirm: (reverse, rules) => {
  682. reverseModal.loading();
  683. if (reverse.tag.length > 0) {
  684. newTemplateSettings = this.templateSettings;
  685. if (newTemplateSettings.reverse == undefined) newTemplateSettings.reverse = {};
  686. if (newTemplateSettings.reverse[reverse.type + 's'] == undefined) newTemplateSettings.reverse[reverse.type + 's'] = [];
  687. newTemplateSettings.reverse[reverse.type + 's'].push({ tag: reverse.tag, domain: reverse.domain });
  688. this.templateSettings = newTemplateSettings;
  689. // Add related rules
  690. this.templateSettings.routing.rules.push(...rules);
  691. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  692. }
  693. reverseModal.close();
  694. },
  695. isEdit: false
  696. });
  697. },
  698. editReverse(index) {
  699. if (this.reverseData[index].type == "bridge") {
  700. oldRules = this.templateSettings.routing.rules.filter(r => r.inboundTag && r.inboundTag[0] == this.reverseData[index].tag);
  701. } else {
  702. oldRules = this.templateSettings.routing.rules.filter(r => r.outboundTag && r.outboundTag == this.reverseData[index].tag);
  703. }
  704. reverseModal.show({
  705. title: '{{ i18n "pages.xray.outbound.editReverse"}} ' + (index + 1),
  706. reverse: this.reverseData[index],
  707. rules: oldRules,
  708. confirm: (reverse, rules) => {
  709. reverseModal.loading();
  710. if (reverse.tag.length > 0) {
  711. oldData = this.reverseData[index];
  712. newTemplateSettings = this.templateSettings;
  713. oldReverseIndex = newTemplateSettings.reverse[oldData.type + 's'].findIndex(rs => rs.tag == oldData.tag);
  714. oldRuleIndex0 = oldRules.length > 0 ? newTemplateSettings.routing.rules.findIndex(r => JSON.stringify(r) == JSON.stringify(oldRules[0])) : -1;
  715. oldRuleIndex1 = oldRules.length == 2 ? newTemplateSettings.routing.rules.findIndex(r => JSON.stringify(r) == JSON.stringify(oldRules[1])) : -1;
  716. if (oldData.type == reverse.type) {
  717. newTemplateSettings.reverse[oldData.type + 's'][oldReverseIndex] = { tag: reverse.tag, domain: reverse.domain };
  718. } else {
  719. newTemplateSettings.reverse[oldData.type + 's'].splice(oldReverseIndex, 1);
  720. // delete empty object
  721. if (newTemplateSettings.reverse[oldData.type + 's'].length == 0) Reflect.deleteProperty(newTemplateSettings.reverse, oldData.type + 's');
  722. // add other type of reverse if it is not exist
  723. if (!newTemplateSettings.reverse[reverse.type + 's']) newTemplateSettings.reverse[reverse.type + 's'] = [];
  724. newTemplateSettings.reverse[reverse.type + 's'].push({ tag: reverse.tag, domain: reverse.domain });
  725. }
  726. this.templateSettings = newTemplateSettings;
  727. // Adjust Rules
  728. newRules = this.templateSettings.routing.rules;
  729. oldRuleIndex0 != -1 ? newRules[oldRuleIndex0] = rules[0] : newRules.push(rules[0]);
  730. oldRuleIndex1 != -1 ? newRules[oldRuleIndex1] = rules[1] : newRules.push(rules[1]);
  731. this.routingRuleSettings = JSON.stringify(newRules);
  732. }
  733. reverseModal.close();
  734. },
  735. isEdit: true
  736. });
  737. },
  738. deleteReverse(index) {
  739. oldData = this.reverseData[index];
  740. newTemplateSettings = this.templateSettings;
  741. reverseTypeObj = newTemplateSettings.reverse[oldData.type + 's'];
  742. realIndex = reverseTypeObj.findIndex(r => r.tag == oldData.tag && r.domain == oldData.domain);
  743. newTemplateSettings.reverse[oldData.type + 's'].splice(realIndex, 1);
  744. // delete empty objects
  745. if (reverseTypeObj.length == 0) Reflect.deleteProperty(newTemplateSettings.reverse, oldData.type + 's');
  746. if (Object.keys(newTemplateSettings.reverse).length === 0) Reflect.deleteProperty(newTemplateSettings, 'reverse');
  747. // delete related routing rules
  748. newRules = newTemplateSettings.routing.rules;
  749. if (oldData.type == "bridge") {
  750. newRules = newTemplateSettings.routing.rules.filter(r => !(r.inboundTag && r.inboundTag.length == 1 && r.inboundTag[0] == oldData.tag));
  751. } else if (oldData.type == "portal") {
  752. newRules = newTemplateSettings.routing.rules.filter(r => r.outboundTag != oldData.tag);
  753. }
  754. newTemplateSettings.routing.rules = newRules;
  755. this.templateSettings = newTemplateSettings;
  756. },
  757. async refreshOutboundTraffic() {
  758. if (!this.refreshing) {
  759. this.refreshing = true;
  760. await this.getOutboundsTraffic();
  761. data = []
  762. if (this.templateSettings != null) {
  763. this.templateSettings.outbounds.forEach((o, index) => {
  764. data.push({ 'key': index, ...o });
  765. });
  766. }
  767. this.outboundData = data;
  768. this.refreshing = false;
  769. }
  770. },
  771. async resetOutboundTraffic(index) {
  772. let tag = "-alltags-";
  773. if (index >= 0) {
  774. tag = this.outboundData[index].tag ? this.outboundData[index].tag : ""
  775. }
  776. const msg = await HttpUtil.post("/panel/xray/resetOutboundsTraffic", { tag: tag });
  777. if (msg.success) {
  778. await this.refreshOutboundTraffic();
  779. }
  780. },
  781. addBalancer() {
  782. balancerModal.show({
  783. title: '{{ i18n "pages.xray.balancer.addBalancer"}}',
  784. okText: '{{ i18n "pages.xray.balancer.addBalancer"}}',
  785. balancerTags: this.balancersData.filter((o) => !ObjectUtil.isEmpty(o.tag)).map(obj => obj.tag),
  786. balancer: {
  787. tag: '',
  788. strategy: 'random',
  789. selector: [],
  790. fallbackTag: ''
  791. },
  792. confirm: (balancer) => {
  793. balancerModal.loading();
  794. newTemplateSettings = this.templateSettings;
  795. if (newTemplateSettings.routing.balancers == undefined) {
  796. newTemplateSettings.routing.balancers = [];
  797. }
  798. let tmpBalancer = {
  799. 'tag': balancer.tag,
  800. 'selector': balancer.selector,
  801. 'fallbackTag': balancer.fallbackTag
  802. };
  803. if (balancer.strategy && balancer.strategy != 'random') {
  804. tmpBalancer.strategy = {
  805. 'type': balancer.strategy
  806. };
  807. }
  808. newTemplateSettings.routing.balancers.push(tmpBalancer);
  809. this.templateSettings = newTemplateSettings;
  810. this.updateObservatorySelectors();
  811. balancerModal.close();
  812. this.changeObsCode();
  813. },
  814. isEdit: false
  815. });
  816. },
  817. editBalancer(index) {
  818. const oldTag = this.balancersData[index].tag;
  819. balancerModal.show({
  820. title: '{{ i18n "pages.xray.balancer.editBalancer"}}',
  821. okText: '{{ i18n "sure" }}',
  822. balancerTags: this.balancersData.filter((o) => !ObjectUtil.isEmpty(o.tag)).map(obj => obj.tag),
  823. balancer: this.balancersData[index],
  824. confirm: (balancer) => {
  825. balancerModal.loading();
  826. newTemplateSettings = this.templateSettings;
  827. let tmpBalancer = {
  828. 'tag': balancer.tag,
  829. 'selector': balancer.selector,
  830. 'fallbackTag': balancer.fallbackTag
  831. };
  832. // Remove old tag
  833. if (newTemplateSettings.observatory) {
  834. newTemplateSettings.observatory.subjectSelector = newTemplateSettings.observatory.subjectSelector.filter(s => s != oldTag);
  835. }
  836. if (newTemplateSettings.burstObservatory) {
  837. newTemplateSettings.burstObservatory.subjectSelector = newTemplateSettings.burstObservatory.subjectSelector.filter(s => s != oldTag);
  838. }
  839. if (balancer.strategy && balancer.strategy != 'random') {
  840. tmpBalancer.strategy = {
  841. 'type': balancer.strategy
  842. };
  843. }
  844. newTemplateSettings.routing.balancers[index] = tmpBalancer;
  845. // change edited tag if used in rule section
  846. if (oldTag != balancer.tag) {
  847. newTemplateSettings.routing.rules.forEach((rule) => {
  848. if (rule.balancerTag && rule.balancerTag == oldTag) {
  849. rule.balancerTag = balancer.tag;
  850. }
  851. });
  852. }
  853. this.templateSettings = newTemplateSettings;
  854. this.updateObservatorySelectors();
  855. balancerModal.close();
  856. this.changeObsCode();
  857. },
  858. isEdit: true
  859. });
  860. },
  861. updateObservatorySelectors() {
  862. newTemplateSettings = this.templateSettings;
  863. const leastPings = this.balancersData.filter((b) => b.strategy == 'leastPing');
  864. const leastLoads = this.balancersData.filter((b) =>
  865. b.strategy === 'leastLoad' ||
  866. b.strategy === 'roundRobin' ||
  867. b.strategy === 'random'
  868. );
  869. if (leastPings.length > 0) {
  870. if (!newTemplateSettings.observatory)
  871. newTemplateSettings.observatory = this.defaultObservatory;
  872. newTemplateSettings.observatory.subjectSelector = [];
  873. leastPings.forEach((b) => {
  874. b.selector.forEach((s) => {
  875. if (!newTemplateSettings.observatory.subjectSelector.includes(s))
  876. newTemplateSettings.observatory.subjectSelector.push(s);
  877. });
  878. });
  879. } else {
  880. delete newTemplateSettings.observatory
  881. }
  882. if (leastLoads.length > 0) {
  883. if (!newTemplateSettings.burstObservatory)
  884. newTemplateSettings.burstObservatory = this.defaultBurstObservatory;
  885. newTemplateSettings.burstObservatory.subjectSelector = [];
  886. leastLoads.forEach((b) => {
  887. b.selector.forEach((s) => {
  888. if (!newTemplateSettings.burstObservatory.subjectSelector.includes(s))
  889. newTemplateSettings.burstObservatory.subjectSelector.push(s);
  890. });
  891. });
  892. } else {
  893. delete newTemplateSettings.burstObservatory
  894. }
  895. this.templateSettings = newTemplateSettings;
  896. this.changeObsCode();
  897. },
  898. deleteBalancer(index) {
  899. newTemplateSettings = this.templateSettings;
  900. // Remove from balancers
  901. const removedBalancer = this.balancersData.splice(index, 1)[0];
  902. // Remove from settings
  903. let realIndex = newTemplateSettings.routing.balancers.findIndex((b) => b.tag === removedBalancer.tag);
  904. newTemplateSettings.routing.balancers.splice(realIndex, 1);
  905. // Update balancers property to an empty array if there are no more balancers
  906. if (newTemplateSettings.routing.balancers.length === 0) {
  907. delete newTemplateSettings.routing.balancers;
  908. }
  909. // Remove orphaned balancer references from routing rules
  910. if (newTemplateSettings.routing.rules) {
  911. newTemplateSettings.routing.rules.forEach((rule) => {
  912. if (rule.balancerTag && rule.balancerTag === removedBalancer.tag) {
  913. delete rule.balancerTag;
  914. }
  915. });
  916. }
  917. this.templateSettings = newTemplateSettings;
  918. this.updateObservatorySelectors();
  919. this.obsSettings = '';
  920. this.changeObsCode()
  921. },
  922. openDNSPresets() {
  923. dnsPresetsModal.show({
  924. title: '{{ i18n "pages.xray.dns.dnsPresetTitle" }}',
  925. selected: (selectedPreset) => {
  926. this.dnsServers = selectedPreset;
  927. dnsPresetsModal.close();
  928. }
  929. });
  930. },
  931. addDNSServer() {
  932. dnsModal.show({
  933. title: '{{ i18n "pages.xray.dns.add" }}',
  934. confirm: (dnsServer) => {
  935. dnsServers = this.dnsServers;
  936. dnsServers.push(dnsServer);
  937. this.dnsServers = dnsServers;
  938. dnsModal.close();
  939. },
  940. isEdit: false
  941. });
  942. },
  943. editDNSServer(index) {
  944. dnsModal.show({
  945. title: '{{ i18n "pages.xray.dns.edit" }} #' + (index + 1),
  946. dnsServer: this.dnsServers[index],
  947. confirm: (dnsServer) => {
  948. dnsServers = this.dnsServers;
  949. dnsServers[index] = dnsServer;
  950. this.dnsServers = dnsServers;
  951. dnsModal.close();
  952. },
  953. isEdit: true
  954. });
  955. },
  956. deleteDNSServer(index) {
  957. newDnsServers = this.dnsServers;
  958. newDnsServers.splice(index, 1);
  959. this.dnsServers = newDnsServers;
  960. },
  961. addFakedns() {
  962. fakednsModal.show({
  963. title: '{{ i18n "pages.xray.fakedns.add" }}',
  964. confirm: (item) => {
  965. fakeDns = this.fakeDns ?? [];
  966. fakeDns.push(item);
  967. this.fakeDns = fakeDns;
  968. fakednsModal.close();
  969. },
  970. isEdit: false
  971. });
  972. },
  973. editFakedns(index) {
  974. fakednsModal.show({
  975. title: '{{ i18n "pages.xray.fakedns.edit" }} #' + (index + 1),
  976. fakeDns: this.fakeDns[index],
  977. confirm: (item) => {
  978. fakeDns = this.fakeDns;
  979. fakeDns[index] = item;
  980. this.fakeDns = fakeDns;
  981. fakednsModal.close();
  982. },
  983. isEdit: true
  984. });
  985. },
  986. deleteFakedns(index) {
  987. fakeDns = this.fakeDns;
  988. fakeDns.splice(index, 1);
  989. this.fakeDns = fakeDns;
  990. },
  991. addRule() {
  992. ruleModal.show({
  993. title: '{{ i18n "pages.xray.rules.add"}}',
  994. okText: '{{ i18n "pages.xray.rules.add" }}',
  995. confirm: (rule) => {
  996. ruleModal.loading();
  997. if (JSON.stringify(rule).length > 3) {
  998. this.templateSettings.routing.rules.push(rule);
  999. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  1000. }
  1001. ruleModal.close();
  1002. },
  1003. isEdit: false
  1004. });
  1005. },
  1006. editRule(index) {
  1007. ruleModal.show({
  1008. title: '{{ i18n "pages.xray.rules.edit"}} ' + (index + 1),
  1009. rule: app.templateSettings.routing.rules[index],
  1010. confirm: (rule) => {
  1011. ruleModal.loading();
  1012. if (JSON.stringify(rule).length > 3) {
  1013. this.templateSettings.routing.rules[index] = rule;
  1014. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  1015. }
  1016. ruleModal.close();
  1017. },
  1018. isEdit: true
  1019. });
  1020. },
  1021. replaceRule(old_index, new_index) {
  1022. rules = this.templateSettings.routing.rules;
  1023. if (new_index >= rules.length) rules.push(undefined);
  1024. rules.splice(new_index, 0, rules.splice(old_index, 1)[0]);
  1025. this.routingRuleSettings = JSON.stringify(rules);
  1026. },
  1027. deleteRule(index) {
  1028. rules = this.templateSettings.routing.rules;
  1029. rules.splice(index, 1);
  1030. this.routingRuleSettings = JSON.stringify(rules);
  1031. },
  1032. showWarp() {
  1033. warpModal.show();
  1034. },
  1035. showNord() {
  1036. nordModal.show();
  1037. },
  1038. async loadCustomGeoAliases() {
  1039. try {
  1040. const msg = await HttpUtil.get('/panel/api/custom-geo/aliases');
  1041. if (!msg.success) {
  1042. console.warn('Failed to load custom geo aliases:', msg.msg || 'request failed');
  1043. return;
  1044. }
  1045. if (!msg.obj) return;
  1046. const geoip = msg.obj.geoip ?? [];
  1047. const geosite = msg.obj.geosite ?? [];
  1048. const geoSuffix = this.customGeoAliasLabelSuffix || '';
  1049. geoip.forEach((x) => {
  1050. this.settingsData.IPsOptions.push({
  1051. label: x.alias + geoSuffix,
  1052. value: x.extExample,
  1053. });
  1054. });
  1055. geosite.forEach((x) => {
  1056. const opt = { label: x.alias + geoSuffix, value: x.extExample };
  1057. this.settingsData.DomainsOptions.push(opt);
  1058. this.settingsData.BlockDomainsOptions.push(opt);
  1059. });
  1060. } catch (e) {
  1061. console.error('Failed to load custom geo aliases:', e);
  1062. }
  1063. }
  1064. },
  1065. async mounted() {
  1066. if (window.location.protocol !== "https:") {
  1067. this.showAlert = true;
  1068. }
  1069. await this.getXraySetting();
  1070. await this.loadCustomGeoAliases();
  1071. await this.getXrayResult();
  1072. await this.getOutboundsTraffic();
  1073. if (window.wsClient) {
  1074. window.wsClient.connect();
  1075. window.wsClient.on('outbounds', (payload) => {
  1076. if (payload) {
  1077. this.outboundsTraffic = payload;
  1078. this.$forceUpdate();
  1079. }
  1080. });
  1081. // Handle invalidate signals (sent when payload is too large for WebSocket,
  1082. // or when traffic job notifies about data changes)
  1083. window.wsClient.on('invalidate', (payload) => {
  1084. if (payload && payload.type === 'outbounds') {
  1085. this.refreshOutboundTraffic();
  1086. }
  1087. });
  1088. }
  1089. while (true) {
  1090. await PromiseUtil.sleep(800);
  1091. this.saveBtnDisable = this.oldXraySetting === this.xraySetting && this.oldOutboundTestUrl === this.outboundTestUrl;
  1092. }
  1093. },
  1094. computed: {
  1095. templateSettings: {
  1096. get: function () {
  1097. const parsedSettings = this.xraySetting ? JSON.parse(this.xraySetting) : null;
  1098. return parsedSettings;
  1099. },
  1100. set: function (newValue) {
  1101. if (newValue) {
  1102. this.xraySetting = JSON.stringify(newValue, null, 2);
  1103. }
  1104. },
  1105. },
  1106. inboundSettings: {
  1107. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.inbounds, null, 2) : null; },
  1108. set: function (newValue) {
  1109. newTemplateSettings = this.templateSettings;
  1110. newTemplateSettings.inbounds = JSON.parse(newValue);
  1111. this.templateSettings = newTemplateSettings;
  1112. },
  1113. },
  1114. outboundSettings: {
  1115. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.outbounds, null, 2) : null; },
  1116. set: function (newValue) {
  1117. newTemplateSettings = this.templateSettings;
  1118. newTemplateSettings.outbounds = JSON.parse(newValue);
  1119. this.templateSettings = newTemplateSettings;
  1120. },
  1121. },
  1122. outboundData: {
  1123. get: function () {
  1124. data = []
  1125. if (this.templateSettings != null) {
  1126. this.templateSettings.outbounds.forEach((o, index) => {
  1127. data.push({ 'key': index, ...o });
  1128. });
  1129. }
  1130. return data;
  1131. },
  1132. },
  1133. reverseData: {
  1134. get: function () {
  1135. data = []
  1136. if (this.templateSettings != null && this.templateSettings.reverse != null) {
  1137. if (this.templateSettings.reverse.bridges) {
  1138. this.templateSettings.reverse.bridges.forEach((o, index) => {
  1139. data.push({ 'key': index, 'type': 'bridge', ...o });
  1140. });
  1141. }
  1142. if (this.templateSettings.reverse.portals) {
  1143. this.templateSettings.reverse.portals.forEach((o, index) => {
  1144. data.push({ 'key': index, 'type': 'portal', ...o });
  1145. });
  1146. }
  1147. }
  1148. return data;
  1149. },
  1150. },
  1151. routingRuleSettings: {
  1152. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.routing.rules, null, 2) : null; },
  1153. set: function (newValue) {
  1154. newTemplateSettings = this.templateSettings;
  1155. newTemplateSettings.routing.rules = JSON.parse(newValue);
  1156. this.templateSettings = newTemplateSettings;
  1157. },
  1158. },
  1159. routingRuleData: {
  1160. get: function () {
  1161. data = [];
  1162. if (this.templateSettings != null) {
  1163. this.templateSettings.routing.rules.forEach((r, index) => {
  1164. data.push({ 'key': index, ...r });
  1165. });
  1166. // Make rules readable
  1167. data.forEach(r => {
  1168. if (r.domain) r.domain = r.domain.join(',')
  1169. if (r.ip) r.ip = r.ip.join(',')
  1170. if (r.source) r.source = r.source.join(',');
  1171. if (r.user) r.user = r.user.join(',')
  1172. if (r.inboundTag) r.inboundTag = r.inboundTag.join(',')
  1173. if (r.protocol) r.protocol = r.protocol.join(',')
  1174. if (r.attrs) r.attrs = JSON.stringify(r.attrs, null, 2)
  1175. });
  1176. }
  1177. return data;
  1178. }
  1179. },
  1180. balancersData: {
  1181. get: function () {
  1182. data = []
  1183. if (this.templateSettings != null && this.templateSettings.routing != null && this.templateSettings.routing.balancers != null) {
  1184. this.templateSettings.routing.balancers.forEach((o, index) => {
  1185. data.push({
  1186. 'key': index,
  1187. 'tag': o.tag ? o.tag : "",
  1188. 'strategy': o.strategy?.type ?? "random",
  1189. 'selector': o.selector ? o.selector : [],
  1190. 'fallbackTag': o.fallbackTag ?? '',
  1191. });
  1192. });
  1193. }
  1194. return data;
  1195. }
  1196. },
  1197. observatory: {
  1198. get: function () {
  1199. return this.templateSettings?.observatory ? JSON.stringify(this.templateSettings.observatory, null, 2) : null;
  1200. },
  1201. set: function (newValue) {
  1202. newTemplateSettings = this.templateSettings;
  1203. newTemplateSettings.observatory = JSON.parse(newValue);
  1204. this.templateSettings = newTemplateSettings;
  1205. },
  1206. },
  1207. burstObservatory: {
  1208. get: function () {
  1209. return this.templateSettings?.burstObservatory ? JSON.stringify(this.templateSettings.burstObservatory, null, 2) : null;
  1210. },
  1211. set: function (newValue) {
  1212. newTemplateSettings = this.templateSettings;
  1213. newTemplateSettings.burstObservatory = JSON.parse(newValue);
  1214. this.templateSettings = newTemplateSettings;
  1215. },
  1216. },
  1217. observatoryEnable: function () { return this.templateSettings != null && this.templateSettings.observatory != undefined },
  1218. burstObservatoryEnable: function () { return this.templateSettings != null && this.templateSettings.burstObservatory != undefined },
  1219. freedomStrategy: {
  1220. get: function () {
  1221. if (!this.templateSettings) return "AsIs";
  1222. freedomOutbound = this.templateSettings.outbounds.find((o) => o.protocol === "freedom" && o.tag == "direct");
  1223. if (!freedomOutbound) return "AsIs";
  1224. if (!freedomOutbound.settings || !freedomOutbound.settings.domainStrategy) return "AsIs";
  1225. return freedomOutbound.settings.domainStrategy;
  1226. },
  1227. set: function (newValue) {
  1228. newTemplateSettings = this.templateSettings;
  1229. freedomOutboundIndex = newTemplateSettings.outbounds.findIndex((o) => o.protocol === "freedom" && o.tag == "direct");
  1230. if (freedomOutboundIndex == -1) {
  1231. newTemplateSettings.outbounds.push({ protocol: "freedom", tag: "direct", settings: { "domainStrategy": newValue } });
  1232. } else if (!newTemplateSettings.outbounds[freedomOutboundIndex].settings) {
  1233. newTemplateSettings.outbounds[freedomOutboundIndex].settings = { "domainStrategy": newValue };
  1234. } else {
  1235. newTemplateSettings.outbounds[freedomOutboundIndex].settings.domainStrategy = newValue;
  1236. }
  1237. this.templateSettings = newTemplateSettings;
  1238. }
  1239. },
  1240. routingStrategy: {
  1241. get: function () {
  1242. if (!this.templateSettings || !this.templateSettings.routing || !this.templateSettings.routing.domainStrategy) return "AsIs";
  1243. return this.templateSettings.routing.domainStrategy;
  1244. },
  1245. set: function (newValue) {
  1246. newTemplateSettings = this.templateSettings;
  1247. newTemplateSettings.routing.domainStrategy = newValue;
  1248. this.templateSettings = newTemplateSettings;
  1249. }
  1250. },
  1251. logLevel: {
  1252. get: function () {
  1253. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.loglevel) return "warning";
  1254. return this.templateSettings.log.loglevel;
  1255. },
  1256. set: function (newValue) {
  1257. newTemplateSettings = this.templateSettings;
  1258. newTemplateSettings.log.loglevel = newValue;
  1259. this.templateSettings = newTemplateSettings;
  1260. }
  1261. },
  1262. accessLog: {
  1263. get: function () {
  1264. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.access) return "";
  1265. return this.templateSettings.log.access;
  1266. },
  1267. set: function (newValue) {
  1268. newTemplateSettings = this.templateSettings;
  1269. newTemplateSettings.log.access = newValue;
  1270. this.templateSettings = newTemplateSettings;
  1271. }
  1272. },
  1273. errorLog: {
  1274. get: function () {
  1275. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.error) return "";
  1276. return this.templateSettings.log.error;
  1277. },
  1278. set: function (newValue) {
  1279. newTemplateSettings = this.templateSettings;
  1280. newTemplateSettings.log.error = newValue;
  1281. this.templateSettings = newTemplateSettings;
  1282. }
  1283. },
  1284. dnslog: {
  1285. get: function () {
  1286. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.dnsLog) return false;
  1287. return this.templateSettings.log.dnsLog;
  1288. },
  1289. set: function (newValue) {
  1290. newTemplateSettings = this.templateSettings;
  1291. newTemplateSettings.log.dnsLog = newValue;
  1292. this.templateSettings = newTemplateSettings;
  1293. }
  1294. },
  1295. statsInboundUplink: {
  1296. get: function () {
  1297. if (!this.templateSettings || !this.templateSettings.policy.system || !this.templateSettings.policy.system.statsInboundUplink) return false;
  1298. return this.templateSettings.policy.system.statsInboundUplink;
  1299. },
  1300. set: function (newValue) {
  1301. newTemplateSettings = this.templateSettings;
  1302. newTemplateSettings.policy.system.statsInboundUplink = newValue;
  1303. this.templateSettings = newTemplateSettings;
  1304. }
  1305. },
  1306. statsInboundDownlink: {
  1307. get: function () {
  1308. if (!this.templateSettings || !this.templateSettings.policy.system || !this.templateSettings.policy.system.statsInboundDownlink) return false;
  1309. return this.templateSettings.policy.system.statsInboundDownlink;
  1310. },
  1311. set: function (newValue) {
  1312. newTemplateSettings = this.templateSettings;
  1313. newTemplateSettings.policy.system.statsInboundDownlink = newValue;
  1314. this.templateSettings = newTemplateSettings;
  1315. }
  1316. },
  1317. statsOutboundUplink: {
  1318. get: function () {
  1319. if (!this.templateSettings || !this.templateSettings.policy.system || !this.templateSettings.policy.system.statsOutboundUplink) return false;
  1320. return this.templateSettings.policy.system.statsOutboundUplink;
  1321. },
  1322. set: function (newValue) {
  1323. newTemplateSettings = this.templateSettings;
  1324. newTemplateSettings.policy.system.statsOutboundUplink = newValue;
  1325. this.templateSettings = newTemplateSettings;
  1326. }
  1327. },
  1328. statsOutboundDownlink: {
  1329. get: function () {
  1330. if (!this.templateSettings || !this.templateSettings.policy.system || !this.templateSettings.policy.system.statsOutboundDownlink) return false;
  1331. return this.templateSettings.policy.system.statsOutboundDownlink;
  1332. },
  1333. set: function (newValue) {
  1334. newTemplateSettings = this.templateSettings;
  1335. newTemplateSettings.policy.system.statsOutboundDownlink = newValue;
  1336. this.templateSettings = newTemplateSettings;
  1337. }
  1338. },
  1339. maskAddressLog: {
  1340. get: function () {
  1341. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.maskAddress) return "";
  1342. return this.templateSettings.log.maskAddress;
  1343. },
  1344. set: function (newValue) {
  1345. newTemplateSettings = this.templateSettings;
  1346. newTemplateSettings.log.maskAddress = newValue;
  1347. this.templateSettings = newTemplateSettings;
  1348. }
  1349. },
  1350. blockedIPs: {
  1351. get: function () {
  1352. return this.templateRuleGetter({ outboundTag: "blocked", property: "ip" });
  1353. },
  1354. set: function (newValue) {
  1355. this.templateRuleSetter({ outboundTag: "blocked", property: "ip", data: newValue });
  1356. }
  1357. },
  1358. blockedDomains: {
  1359. get: function () {
  1360. return this.templateRuleGetter({ outboundTag: "blocked", property: "domain" });
  1361. },
  1362. set: function (newValue) {
  1363. this.templateRuleSetter({ outboundTag: "blocked", property: "domain", data: newValue });
  1364. }
  1365. },
  1366. blockedProtocols: {
  1367. get: function () {
  1368. return this.templateRuleGetter({ outboundTag: "blocked", property: "protocol" });
  1369. },
  1370. set: function (newValue) {
  1371. this.templateRuleSetter({ outboundTag: "blocked", property: "protocol", data: newValue });
  1372. }
  1373. },
  1374. directIPs: {
  1375. get: function () {
  1376. return this.templateRuleGetter({ outboundTag: "direct", property: "ip" });
  1377. },
  1378. set: function (newValue) {
  1379. this.templateRuleSetter({ outboundTag: "direct", property: "ip", data: newValue });
  1380. this.syncRulesWithOutbound("direct", this.directSettings);
  1381. }
  1382. },
  1383. directDomains: {
  1384. get: function () {
  1385. return this.templateRuleGetter({ outboundTag: "direct", property: "domain" });
  1386. },
  1387. set: function (newValue) {
  1388. this.templateRuleSetter({ outboundTag: "direct", property: "domain", data: newValue });
  1389. this.syncRulesWithOutbound("direct", this.directSettings);
  1390. }
  1391. },
  1392. ipv4Domains: {
  1393. get: function () {
  1394. return this.templateRuleGetter({ outboundTag: "IPv4", property: "domain" });
  1395. },
  1396. set: function (newValue) {
  1397. this.templateRuleSetter({ outboundTag: "IPv4", property: "domain", data: newValue });
  1398. this.syncRulesWithOutbound("IPv4", this.ipv4Settings);
  1399. }
  1400. },
  1401. warpDomains: {
  1402. get: function () {
  1403. return this.templateRuleGetter({ outboundTag: "warp", property: "domain" });
  1404. },
  1405. set: function (newValue) {
  1406. this.templateRuleSetter({ outboundTag: "warp", property: "domain", data: newValue });
  1407. }
  1408. },
  1409. nordTag: {
  1410. get: function () {
  1411. return this.templateSettings ? (this.templateSettings.outbounds.find((o) => o.tag.startsWith("nord-")) || { tag: "nord" }).tag : "nord";
  1412. }
  1413. },
  1414. nordDomains: {
  1415. get: function () {
  1416. return this.templateRuleGetter({ outboundTag: this.nordTag, property: "domain" });
  1417. },
  1418. set: function (newValue) {
  1419. this.templateRuleSetter({ outboundTag: this.nordTag, property: "domain", data: newValue });
  1420. }
  1421. },
  1422. torrentSettings: {
  1423. get: function () {
  1424. return ArrayUtils.doAllItemsExist(this.settingsData.protocols.bittorrent, this.blockedProtocols);
  1425. },
  1426. set: function (newValue) {
  1427. if (newValue) {
  1428. this.blockedProtocols = [...this.blockedProtocols, ...this.settingsData.protocols.bittorrent];
  1429. } else {
  1430. this.blockedProtocols = this.blockedProtocols.filter(data => !this.settingsData.protocols.bittorrent.includes(data));
  1431. }
  1432. },
  1433. },
  1434. WarpExist: {
  1435. get: function () {
  1436. return this.templateSettings ? this.templateSettings.outbounds.findIndex((o) => o.tag == "warp") >= 0 : false;
  1437. },
  1438. },
  1439. NordExist: {
  1440. get: function () {
  1441. return this.templateSettings ? this.templateSettings.outbounds.findIndex((o) => o.tag.startsWith("nord-")) >= 0 : false;
  1442. },
  1443. },
  1444. enableDNS: {
  1445. get: function () {
  1446. return this.templateSettings ? this.templateSettings.dns != null : false;
  1447. },
  1448. set: function (newValue) {
  1449. newTemplateSettings = this.templateSettings;
  1450. if (newValue) {
  1451. newTemplateSettings.dns = {
  1452. servers: [],
  1453. queryStrategy: "UseIP",
  1454. tag: "dns_inbound",
  1455. enableParallelQuery: false
  1456. };
  1457. newTemplateSettings.fakedns = null;
  1458. } else {
  1459. delete newTemplateSettings.dns;
  1460. delete newTemplateSettings.fakedns;
  1461. }
  1462. this.templateSettings = newTemplateSettings;
  1463. }
  1464. },
  1465. dnsTag: {
  1466. get: function () {
  1467. return this.enableDNS ? this.templateSettings.dns.tag : "";
  1468. },
  1469. set: function (newValue) {
  1470. newTemplateSettings = this.templateSettings;
  1471. newTemplateSettings.dns.tag = newValue;
  1472. this.templateSettings = newTemplateSettings;
  1473. }
  1474. },
  1475. dnsClientIp: {
  1476. get: function () {
  1477. return this.enableDNS ? this.templateSettings.dns.clientIp : null;
  1478. },
  1479. set: function (newValue) {
  1480. newTemplateSettings = this.templateSettings;
  1481. if (newValue) {
  1482. newTemplateSettings.dns.clientIp = newValue;
  1483. } else {
  1484. delete newTemplateSettings.dns.clientIp;
  1485. }
  1486. this.templateSettings = newTemplateSettings;
  1487. }
  1488. },
  1489. dnsDisableCache: {
  1490. get: function () {
  1491. return this.enableDNS ? this.templateSettings.dns.disableCache : false;
  1492. },
  1493. set: function (newValue) {
  1494. newTemplateSettings = this.templateSettings;
  1495. if (newValue) {
  1496. newTemplateSettings.dns.disableCache = newValue;
  1497. } else {
  1498. delete newTemplateSettings.dns.disableCache
  1499. }
  1500. this.templateSettings = newTemplateSettings;
  1501. }
  1502. },
  1503. dnsDisableFallback: {
  1504. get: function () {
  1505. return this.enableDNS ? this.templateSettings.dns.disableFallback : false;
  1506. },
  1507. set: function (newValue) {
  1508. newTemplateSettings = this.templateSettings;
  1509. if (newValue) {
  1510. newTemplateSettings.dns.disableFallback = newValue;
  1511. } else {
  1512. delete newTemplateSettings.dns.disableFallback
  1513. }
  1514. this.templateSettings = newTemplateSettings;
  1515. }
  1516. },
  1517. dnsDisableFallbackIfMatch: {
  1518. get: function () {
  1519. return this.enableDNS ? this.templateSettings.dns.disableFallbackIfMatch : false;
  1520. },
  1521. set: function (newValue) {
  1522. newTemplateSettings = this.templateSettings;
  1523. if (newValue) {
  1524. newTemplateSettings.dns.disableFallbackIfMatch = newValue;
  1525. } else {
  1526. delete newTemplateSettings.dns.disableFallbackIfMatch
  1527. }
  1528. this.templateSettings = newTemplateSettings;
  1529. }
  1530. },
  1531. dnsEnableParallelQuery: {
  1532. get: function () {
  1533. return this.enableDNS ? (this.templateSettings.dns.enableParallelQuery || false) : false;
  1534. },
  1535. set: function (newValue) {
  1536. newTemplateSettings = this.templateSettings;
  1537. if (newValue) {
  1538. newTemplateSettings.dns.enableParallelQuery = newValue;
  1539. } else {
  1540. delete newTemplateSettings.dns.enableParallelQuery
  1541. }
  1542. this.templateSettings = newTemplateSettings;
  1543. }
  1544. },
  1545. dnsUseSystemHosts: {
  1546. get: function () {
  1547. return this.enableDNS ? this.templateSettings.dns.useSystemHosts : false;
  1548. },
  1549. set: function (newValue) {
  1550. newTemplateSettings = this.templateSettings;
  1551. if (newValue) {
  1552. newTemplateSettings.dns.useSystemHosts = newValue;
  1553. } else {
  1554. delete newTemplateSettings.dns.useSystemHosts
  1555. }
  1556. this.templateSettings = newTemplateSettings;
  1557. }
  1558. },
  1559. dnsStrategy: {
  1560. get: function () {
  1561. return this.enableDNS ? this.templateSettings.dns.queryStrategy : null;
  1562. },
  1563. set: function (newValue) {
  1564. newTemplateSettings = this.templateSettings;
  1565. newTemplateSettings.dns.queryStrategy = newValue;
  1566. this.templateSettings = newTemplateSettings;
  1567. }
  1568. },
  1569. dnsServers: {
  1570. get: function () { return this.enableDNS ? this.templateSettings.dns.servers : []; },
  1571. set: function (newValue) {
  1572. newTemplateSettings = this.templateSettings;
  1573. newTemplateSettings.dns.servers = newValue;
  1574. this.templateSettings = newTemplateSettings;
  1575. }
  1576. },
  1577. fakeDns: {
  1578. get: function () { return this.templateSettings && this.templateSettings.fakedns ? this.templateSettings.fakedns : []; },
  1579. set: function (newValue) {
  1580. newTemplateSettings = this.templateSettings;
  1581. if (this.enableDNS) {
  1582. newTemplateSettings.fakedns = newValue.length > 0 ? newValue : null;
  1583. } else {
  1584. delete newTemplateSettings.fakedns;
  1585. }
  1586. this.templateSettings = newTemplateSettings;
  1587. }
  1588. }
  1589. },
  1590. });
  1591. </script>
  1592. {{ template "page/body_end" .}}