xray.html 65 KB

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