1
0

xray.html 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619
  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: "10m",
  361. enableConcurrency: true
  362. },
  363. defaultBurstObservatory: {
  364. subjectSelector: [],
  365. pingConfig: {
  366. destination: "https://www.google.com/generate_204",
  367. interval: "30m",
  368. connectivity: "http://connectivitycheck.platform.hicloud.com/generate_204",
  369. timeout: "10s",
  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. this.templateSettings = newTemplateSettings;
  910. this.updateObservatorySelectors();
  911. this.obsSettings = '';
  912. this.changeObsCode()
  913. },
  914. openDNSPresets() {
  915. dnsPresetsModal.show({
  916. title: '{{ i18n "pages.xray.dns.dnsPresetTitle" }}',
  917. selected: (selectedPreset) => {
  918. this.dnsServers = selectedPreset;
  919. dnsPresetsModal.close();
  920. }
  921. });
  922. },
  923. addDNSServer() {
  924. dnsModal.show({
  925. title: '{{ i18n "pages.xray.dns.add" }}',
  926. confirm: (dnsServer) => {
  927. dnsServers = this.dnsServers;
  928. dnsServers.push(dnsServer);
  929. this.dnsServers = dnsServers;
  930. dnsModal.close();
  931. },
  932. isEdit: false
  933. });
  934. },
  935. editDNSServer(index) {
  936. dnsModal.show({
  937. title: '{{ i18n "pages.xray.dns.edit" }} #' + (index + 1),
  938. dnsServer: this.dnsServers[index],
  939. confirm: (dnsServer) => {
  940. dnsServers = this.dnsServers;
  941. dnsServers[index] = dnsServer;
  942. this.dnsServers = dnsServers;
  943. dnsModal.close();
  944. },
  945. isEdit: true
  946. });
  947. },
  948. deleteDNSServer(index) {
  949. newDnsServers = this.dnsServers;
  950. newDnsServers.splice(index, 1);
  951. this.dnsServers = newDnsServers;
  952. },
  953. addFakedns() {
  954. fakednsModal.show({
  955. title: '{{ i18n "pages.xray.fakedns.add" }}',
  956. confirm: (item) => {
  957. fakeDns = this.fakeDns ?? [];
  958. fakeDns.push(item);
  959. this.fakeDns = fakeDns;
  960. fakednsModal.close();
  961. },
  962. isEdit: false
  963. });
  964. },
  965. editFakedns(index) {
  966. fakednsModal.show({
  967. title: '{{ i18n "pages.xray.fakedns.edit" }} #' + (index + 1),
  968. fakeDns: this.fakeDns[index],
  969. confirm: (item) => {
  970. fakeDns = this.fakeDns;
  971. fakeDns[index] = item;
  972. this.fakeDns = fakeDns;
  973. fakednsModal.close();
  974. },
  975. isEdit: true
  976. });
  977. },
  978. deleteFakedns(index) {
  979. fakeDns = this.fakeDns;
  980. fakeDns.splice(index, 1);
  981. this.fakeDns = fakeDns;
  982. },
  983. addRule() {
  984. ruleModal.show({
  985. title: '{{ i18n "pages.xray.rules.add"}}',
  986. okText: '{{ i18n "pages.xray.rules.add" }}',
  987. confirm: (rule) => {
  988. ruleModal.loading();
  989. if (JSON.stringify(rule).length > 3) {
  990. this.templateSettings.routing.rules.push(rule);
  991. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  992. }
  993. ruleModal.close();
  994. },
  995. isEdit: false
  996. });
  997. },
  998. editRule(index) {
  999. ruleModal.show({
  1000. title: '{{ i18n "pages.xray.rules.edit"}} ' + (index + 1),
  1001. rule: app.templateSettings.routing.rules[index],
  1002. confirm: (rule) => {
  1003. ruleModal.loading();
  1004. if (JSON.stringify(rule).length > 3) {
  1005. this.templateSettings.routing.rules[index] = rule;
  1006. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  1007. }
  1008. ruleModal.close();
  1009. },
  1010. isEdit: true
  1011. });
  1012. },
  1013. replaceRule(old_index, new_index) {
  1014. rules = this.templateSettings.routing.rules;
  1015. if (new_index >= rules.length) rules.push(undefined);
  1016. rules.splice(new_index, 0, rules.splice(old_index, 1)[0]);
  1017. this.routingRuleSettings = JSON.stringify(rules);
  1018. },
  1019. deleteRule(index) {
  1020. rules = this.templateSettings.routing.rules;
  1021. rules.splice(index, 1);
  1022. this.routingRuleSettings = JSON.stringify(rules);
  1023. },
  1024. showWarp() {
  1025. warpModal.show();
  1026. },
  1027. showNord() {
  1028. nordModal.show();
  1029. },
  1030. async loadCustomGeoAliases() {
  1031. try {
  1032. const msg = await HttpUtil.get('/panel/api/custom-geo/aliases');
  1033. if (!msg.success) {
  1034. console.warn('Failed to load custom geo aliases:', msg.msg || 'request failed');
  1035. return;
  1036. }
  1037. if (!msg.obj) return;
  1038. const { geoip = [], geosite = [] } = msg.obj;
  1039. const geoSuffix = this.customGeoAliasLabelSuffix || '';
  1040. geoip.forEach((x) => {
  1041. this.settingsData.IPsOptions.push({
  1042. label: x.alias + geoSuffix,
  1043. value: x.extExample,
  1044. });
  1045. });
  1046. geosite.forEach((x) => {
  1047. const opt = { label: x.alias + geoSuffix, value: x.extExample };
  1048. this.settingsData.DomainsOptions.push(opt);
  1049. this.settingsData.BlockDomainsOptions.push(opt);
  1050. });
  1051. } catch (e) {
  1052. console.error('Failed to load custom geo aliases:', e);
  1053. }
  1054. }
  1055. },
  1056. async mounted() {
  1057. if (window.location.protocol !== "https:") {
  1058. this.showAlert = true;
  1059. }
  1060. await this.getXraySetting();
  1061. await this.loadCustomGeoAliases();
  1062. await this.getXrayResult();
  1063. await this.getOutboundsTraffic();
  1064. if (window.wsClient) {
  1065. window.wsClient.connect();
  1066. window.wsClient.on('outbounds', (payload) => {
  1067. if (payload) {
  1068. this.outboundsTraffic = payload;
  1069. this.$forceUpdate();
  1070. }
  1071. });
  1072. // Handle invalidate signals (sent when payload is too large for WebSocket,
  1073. // or when traffic job notifies about data changes)
  1074. window.wsClient.on('invalidate', (payload) => {
  1075. if (payload && payload.type === 'outbounds') {
  1076. this.refreshOutboundTraffic();
  1077. }
  1078. });
  1079. }
  1080. while (true) {
  1081. await PromiseUtil.sleep(800);
  1082. this.saveBtnDisable = this.oldXraySetting === this.xraySetting && this.oldOutboundTestUrl === this.outboundTestUrl;
  1083. }
  1084. },
  1085. computed: {
  1086. templateSettings: {
  1087. get: function () {
  1088. const parsedSettings = this.xraySetting ? JSON.parse(this.xraySetting) : null;
  1089. return parsedSettings;
  1090. },
  1091. set: function (newValue) {
  1092. if (newValue) {
  1093. this.xraySetting = JSON.stringify(newValue, null, 2);
  1094. }
  1095. },
  1096. },
  1097. inboundSettings: {
  1098. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.inbounds, null, 2) : null; },
  1099. set: function (newValue) {
  1100. newTemplateSettings = this.templateSettings;
  1101. newTemplateSettings.inbounds = JSON.parse(newValue);
  1102. this.templateSettings = newTemplateSettings;
  1103. },
  1104. },
  1105. outboundSettings: {
  1106. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.outbounds, null, 2) : null; },
  1107. set: function (newValue) {
  1108. newTemplateSettings = this.templateSettings;
  1109. newTemplateSettings.outbounds = JSON.parse(newValue);
  1110. this.templateSettings = newTemplateSettings;
  1111. },
  1112. },
  1113. outboundData: {
  1114. get: function () {
  1115. data = []
  1116. if (this.templateSettings != null) {
  1117. this.templateSettings.outbounds.forEach((o, index) => {
  1118. data.push({ 'key': index, ...o });
  1119. });
  1120. }
  1121. return data;
  1122. },
  1123. },
  1124. reverseData: {
  1125. get: function () {
  1126. data = []
  1127. if (this.templateSettings != null && this.templateSettings.reverse != null) {
  1128. if (this.templateSettings.reverse.bridges) {
  1129. this.templateSettings.reverse.bridges.forEach((o, index) => {
  1130. data.push({ 'key': index, 'type': 'bridge', ...o });
  1131. });
  1132. }
  1133. if (this.templateSettings.reverse.portals) {
  1134. this.templateSettings.reverse.portals.forEach((o, index) => {
  1135. data.push({ 'key': index, 'type': 'portal', ...o });
  1136. });
  1137. }
  1138. }
  1139. return data;
  1140. },
  1141. },
  1142. routingRuleSettings: {
  1143. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.routing.rules, null, 2) : null; },
  1144. set: function (newValue) {
  1145. newTemplateSettings = this.templateSettings;
  1146. newTemplateSettings.routing.rules = JSON.parse(newValue);
  1147. this.templateSettings = newTemplateSettings;
  1148. },
  1149. },
  1150. routingRuleData: {
  1151. get: function () {
  1152. data = [];
  1153. if (this.templateSettings != null) {
  1154. this.templateSettings.routing.rules.forEach((r, index) => {
  1155. data.push({ 'key': index, ...r });
  1156. });
  1157. // Make rules readable
  1158. data.forEach(r => {
  1159. if (r.domain) r.domain = r.domain.join(',')
  1160. if (r.ip) r.ip = r.ip.join(',')
  1161. if (r.source) r.source = r.source.join(',');
  1162. if (r.user) r.user = r.user.join(',')
  1163. if (r.inboundTag) r.inboundTag = r.inboundTag.join(',')
  1164. if (r.protocol) r.protocol = r.protocol.join(',')
  1165. if (r.attrs) r.attrs = JSON.stringify(r.attrs, null, 2)
  1166. });
  1167. }
  1168. return data;
  1169. }
  1170. },
  1171. balancersData: {
  1172. get: function () {
  1173. data = []
  1174. if (this.templateSettings != null && this.templateSettings.routing != null && this.templateSettings.routing.balancers != null) {
  1175. this.templateSettings.routing.balancers.forEach((o, index) => {
  1176. data.push({
  1177. 'key': index,
  1178. 'tag': o.tag ? o.tag : "",
  1179. 'strategy': o.strategy?.type ?? "random",
  1180. 'selector': o.selector ? o.selector : [],
  1181. 'fallbackTag': o.fallbackTag ?? '',
  1182. });
  1183. });
  1184. }
  1185. return data;
  1186. }
  1187. },
  1188. observatory: {
  1189. get: function () {
  1190. return this.templateSettings?.observatory ? JSON.stringify(this.templateSettings.observatory, null, 2) : null;
  1191. },
  1192. set: function (newValue) {
  1193. newTemplateSettings = this.templateSettings;
  1194. newTemplateSettings.observatory = JSON.parse(newValue);
  1195. this.templateSettings = newTemplateSettings;
  1196. },
  1197. },
  1198. burstObservatory: {
  1199. get: function () {
  1200. return this.templateSettings?.burstObservatory ? JSON.stringify(this.templateSettings.burstObservatory, null, 2) : null;
  1201. },
  1202. set: function (newValue) {
  1203. newTemplateSettings = this.templateSettings;
  1204. newTemplateSettings.burstObservatory = JSON.parse(newValue);
  1205. this.templateSettings = newTemplateSettings;
  1206. },
  1207. },
  1208. observatoryEnable: function () { return this.templateSettings != null && this.templateSettings.observatory != undefined },
  1209. burstObservatoryEnable: function () { return this.templateSettings != null && this.templateSettings.burstObservatory != undefined },
  1210. freedomStrategy: {
  1211. get: function () {
  1212. if (!this.templateSettings) return "AsIs";
  1213. freedomOutbound = this.templateSettings.outbounds.find((o) => o.protocol === "freedom" && o.tag == "direct");
  1214. if (!freedomOutbound) return "AsIs";
  1215. if (!freedomOutbound.settings || !freedomOutbound.settings.domainStrategy) return "AsIs";
  1216. return freedomOutbound.settings.domainStrategy;
  1217. },
  1218. set: function (newValue) {
  1219. newTemplateSettings = this.templateSettings;
  1220. freedomOutboundIndex = newTemplateSettings.outbounds.findIndex((o) => o.protocol === "freedom" && o.tag == "direct");
  1221. if (freedomOutboundIndex == -1) {
  1222. newTemplateSettings.outbounds.push({ protocol: "freedom", tag: "direct", settings: { "domainStrategy": newValue } });
  1223. } else if (!newTemplateSettings.outbounds[freedomOutboundIndex].settings) {
  1224. newTemplateSettings.outbounds[freedomOutboundIndex].settings = { "domainStrategy": newValue };
  1225. } else {
  1226. newTemplateSettings.outbounds[freedomOutboundIndex].settings.domainStrategy = newValue;
  1227. }
  1228. this.templateSettings = newTemplateSettings;
  1229. }
  1230. },
  1231. routingStrategy: {
  1232. get: function () {
  1233. if (!this.templateSettings || !this.templateSettings.routing || !this.templateSettings.routing.domainStrategy) return "AsIs";
  1234. return this.templateSettings.routing.domainStrategy;
  1235. },
  1236. set: function (newValue) {
  1237. newTemplateSettings = this.templateSettings;
  1238. newTemplateSettings.routing.domainStrategy = newValue;
  1239. this.templateSettings = newTemplateSettings;
  1240. }
  1241. },
  1242. logLevel: {
  1243. get: function () {
  1244. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.loglevel) return "warning";
  1245. return this.templateSettings.log.loglevel;
  1246. },
  1247. set: function (newValue) {
  1248. newTemplateSettings = this.templateSettings;
  1249. newTemplateSettings.log.loglevel = newValue;
  1250. this.templateSettings = newTemplateSettings;
  1251. }
  1252. },
  1253. accessLog: {
  1254. get: function () {
  1255. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.access) return "";
  1256. return this.templateSettings.log.access;
  1257. },
  1258. set: function (newValue) {
  1259. newTemplateSettings = this.templateSettings;
  1260. newTemplateSettings.log.access = newValue;
  1261. this.templateSettings = newTemplateSettings;
  1262. }
  1263. },
  1264. errorLog: {
  1265. get: function () {
  1266. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.error) return "";
  1267. return this.templateSettings.log.error;
  1268. },
  1269. set: function (newValue) {
  1270. newTemplateSettings = this.templateSettings;
  1271. newTemplateSettings.log.error = newValue;
  1272. this.templateSettings = newTemplateSettings;
  1273. }
  1274. },
  1275. dnslog: {
  1276. get: function () {
  1277. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.dnsLog) return false;
  1278. return this.templateSettings.log.dnsLog;
  1279. },
  1280. set: function (newValue) {
  1281. newTemplateSettings = this.templateSettings;
  1282. newTemplateSettings.log.dnsLog = newValue;
  1283. this.templateSettings = newTemplateSettings;
  1284. }
  1285. },
  1286. statsInboundUplink: {
  1287. get: function () {
  1288. if (!this.templateSettings || !this.templateSettings.policy.system || !this.templateSettings.policy.system.statsInboundUplink) return false;
  1289. return this.templateSettings.policy.system.statsInboundUplink;
  1290. },
  1291. set: function (newValue) {
  1292. newTemplateSettings = this.templateSettings;
  1293. newTemplateSettings.policy.system.statsInboundUplink = newValue;
  1294. this.templateSettings = newTemplateSettings;
  1295. }
  1296. },
  1297. statsInboundDownlink: {
  1298. get: function () {
  1299. if (!this.templateSettings || !this.templateSettings.policy.system || !this.templateSettings.policy.system.statsInboundDownlink) return false;
  1300. return this.templateSettings.policy.system.statsInboundDownlink;
  1301. },
  1302. set: function (newValue) {
  1303. newTemplateSettings = this.templateSettings;
  1304. newTemplateSettings.policy.system.statsInboundDownlink = newValue;
  1305. this.templateSettings = newTemplateSettings;
  1306. }
  1307. },
  1308. statsOutboundUplink: {
  1309. get: function () {
  1310. if (!this.templateSettings || !this.templateSettings.policy.system || !this.templateSettings.policy.system.statsOutboundUplink) return false;
  1311. return this.templateSettings.policy.system.statsOutboundUplink;
  1312. },
  1313. set: function (newValue) {
  1314. newTemplateSettings = this.templateSettings;
  1315. newTemplateSettings.policy.system.statsOutboundUplink = newValue;
  1316. this.templateSettings = newTemplateSettings;
  1317. }
  1318. },
  1319. statsOutboundDownlink: {
  1320. get: function () {
  1321. if (!this.templateSettings || !this.templateSettings.policy.system || !this.templateSettings.policy.system.statsOutboundDownlink) return false;
  1322. return this.templateSettings.policy.system.statsOutboundDownlink;
  1323. },
  1324. set: function (newValue) {
  1325. newTemplateSettings = this.templateSettings;
  1326. newTemplateSettings.policy.system.statsOutboundDownlink = newValue;
  1327. this.templateSettings = newTemplateSettings;
  1328. }
  1329. },
  1330. maskAddressLog: {
  1331. get: function () {
  1332. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.maskAddress) return "";
  1333. return this.templateSettings.log.maskAddress;
  1334. },
  1335. set: function (newValue) {
  1336. newTemplateSettings = this.templateSettings;
  1337. newTemplateSettings.log.maskAddress = newValue;
  1338. this.templateSettings = newTemplateSettings;
  1339. }
  1340. },
  1341. blockedIPs: {
  1342. get: function () {
  1343. return this.templateRuleGetter({ outboundTag: "blocked", property: "ip" });
  1344. },
  1345. set: function (newValue) {
  1346. this.templateRuleSetter({ outboundTag: "blocked", property: "ip", data: newValue });
  1347. }
  1348. },
  1349. blockedDomains: {
  1350. get: function () {
  1351. return this.templateRuleGetter({ outboundTag: "blocked", property: "domain" });
  1352. },
  1353. set: function (newValue) {
  1354. this.templateRuleSetter({ outboundTag: "blocked", property: "domain", data: newValue });
  1355. }
  1356. },
  1357. blockedProtocols: {
  1358. get: function () {
  1359. return this.templateRuleGetter({ outboundTag: "blocked", property: "protocol" });
  1360. },
  1361. set: function (newValue) {
  1362. this.templateRuleSetter({ outboundTag: "blocked", property: "protocol", data: newValue });
  1363. }
  1364. },
  1365. directIPs: {
  1366. get: function () {
  1367. return this.templateRuleGetter({ outboundTag: "direct", property: "ip" });
  1368. },
  1369. set: function (newValue) {
  1370. this.templateRuleSetter({ outboundTag: "direct", property: "ip", data: newValue });
  1371. this.syncRulesWithOutbound("direct", this.directSettings);
  1372. }
  1373. },
  1374. directDomains: {
  1375. get: function () {
  1376. return this.templateRuleGetter({ outboundTag: "direct", property: "domain" });
  1377. },
  1378. set: function (newValue) {
  1379. this.templateRuleSetter({ outboundTag: "direct", property: "domain", data: newValue });
  1380. this.syncRulesWithOutbound("direct", this.directSettings);
  1381. }
  1382. },
  1383. ipv4Domains: {
  1384. get: function () {
  1385. return this.templateRuleGetter({ outboundTag: "IPv4", property: "domain" });
  1386. },
  1387. set: function (newValue) {
  1388. this.templateRuleSetter({ outboundTag: "IPv4", property: "domain", data: newValue });
  1389. this.syncRulesWithOutbound("IPv4", this.ipv4Settings);
  1390. }
  1391. },
  1392. warpDomains: {
  1393. get: function () {
  1394. return this.templateRuleGetter({ outboundTag: "warp", property: "domain" });
  1395. },
  1396. set: function (newValue) {
  1397. this.templateRuleSetter({ outboundTag: "warp", property: "domain", data: newValue });
  1398. }
  1399. },
  1400. nordTag: {
  1401. get: function () {
  1402. return this.templateSettings ? (this.templateSettings.outbounds.find((o) => o.tag.startsWith("nord-")) || { tag: "nord" }).tag : "nord";
  1403. }
  1404. },
  1405. nordDomains: {
  1406. get: function () {
  1407. return this.templateRuleGetter({ outboundTag: this.nordTag, property: "domain" });
  1408. },
  1409. set: function (newValue) {
  1410. this.templateRuleSetter({ outboundTag: this.nordTag, property: "domain", data: newValue });
  1411. }
  1412. },
  1413. torrentSettings: {
  1414. get: function () {
  1415. return ArrayUtils.doAllItemsExist(this.settingsData.protocols.bittorrent, this.blockedProtocols);
  1416. },
  1417. set: function (newValue) {
  1418. if (newValue) {
  1419. this.blockedProtocols = [...this.blockedProtocols, ...this.settingsData.protocols.bittorrent];
  1420. } else {
  1421. this.blockedProtocols = this.blockedProtocols.filter(data => !this.settingsData.protocols.bittorrent.includes(data));
  1422. }
  1423. },
  1424. },
  1425. WarpExist: {
  1426. get: function () {
  1427. return this.templateSettings ? this.templateSettings.outbounds.findIndex((o) => o.tag == "warp") >= 0 : false;
  1428. },
  1429. },
  1430. NordExist: {
  1431. get: function () {
  1432. return this.templateSettings ? this.templateSettings.outbounds.findIndex((o) => o.tag.startsWith("nord-")) >= 0 : false;
  1433. },
  1434. },
  1435. enableDNS: {
  1436. get: function () {
  1437. return this.templateSettings ? this.templateSettings.dns != null : false;
  1438. },
  1439. set: function (newValue) {
  1440. newTemplateSettings = this.templateSettings;
  1441. if (newValue) {
  1442. newTemplateSettings.dns = {
  1443. servers: [],
  1444. queryStrategy: "UseIP",
  1445. tag: "dns_inbound",
  1446. enableParallelQuery: false
  1447. };
  1448. newTemplateSettings.fakedns = null;
  1449. } else {
  1450. delete newTemplateSettings.dns;
  1451. delete newTemplateSettings.fakedns;
  1452. }
  1453. this.templateSettings = newTemplateSettings;
  1454. }
  1455. },
  1456. dnsTag: {
  1457. get: function () {
  1458. return this.enableDNS ? this.templateSettings.dns.tag : "";
  1459. },
  1460. set: function (newValue) {
  1461. newTemplateSettings = this.templateSettings;
  1462. newTemplateSettings.dns.tag = newValue;
  1463. this.templateSettings = newTemplateSettings;
  1464. }
  1465. },
  1466. dnsClientIp: {
  1467. get: function () {
  1468. return this.enableDNS ? this.templateSettings.dns.clientIp : null;
  1469. },
  1470. set: function (newValue) {
  1471. newTemplateSettings = this.templateSettings;
  1472. if (newValue) {
  1473. newTemplateSettings.dns.clientIp = newValue;
  1474. } else {
  1475. delete newTemplateSettings.dns.clientIp;
  1476. }
  1477. this.templateSettings = newTemplateSettings;
  1478. }
  1479. },
  1480. dnsDisableCache: {
  1481. get: function () {
  1482. return this.enableDNS ? this.templateSettings.dns.disableCache : false;
  1483. },
  1484. set: function (newValue) {
  1485. newTemplateSettings = this.templateSettings;
  1486. if (newValue) {
  1487. newTemplateSettings.dns.disableCache = newValue;
  1488. } else {
  1489. delete newTemplateSettings.dns.disableCache
  1490. }
  1491. this.templateSettings = newTemplateSettings;
  1492. }
  1493. },
  1494. dnsDisableFallback: {
  1495. get: function () {
  1496. return this.enableDNS ? this.templateSettings.dns.disableFallback : false;
  1497. },
  1498. set: function (newValue) {
  1499. newTemplateSettings = this.templateSettings;
  1500. if (newValue) {
  1501. newTemplateSettings.dns.disableFallback = newValue;
  1502. } else {
  1503. delete newTemplateSettings.dns.disableFallback
  1504. }
  1505. this.templateSettings = newTemplateSettings;
  1506. }
  1507. },
  1508. dnsDisableFallbackIfMatch: {
  1509. get: function () {
  1510. return this.enableDNS ? this.templateSettings.dns.disableFallbackIfMatch : false;
  1511. },
  1512. set: function (newValue) {
  1513. newTemplateSettings = this.templateSettings;
  1514. if (newValue) {
  1515. newTemplateSettings.dns.disableFallbackIfMatch = newValue;
  1516. } else {
  1517. delete newTemplateSettings.dns.disableFallbackIfMatch
  1518. }
  1519. this.templateSettings = newTemplateSettings;
  1520. }
  1521. },
  1522. dnsEnableParallelQuery: {
  1523. get: function () {
  1524. return this.enableDNS ? (this.templateSettings.dns.enableParallelQuery || false) : false;
  1525. },
  1526. set: function (newValue) {
  1527. newTemplateSettings = this.templateSettings;
  1528. if (newValue) {
  1529. newTemplateSettings.dns.enableParallelQuery = newValue;
  1530. } else {
  1531. delete newTemplateSettings.dns.enableParallelQuery
  1532. }
  1533. this.templateSettings = newTemplateSettings;
  1534. }
  1535. },
  1536. dnsUseSystemHosts: {
  1537. get: function () {
  1538. return this.enableDNS ? this.templateSettings.dns.useSystemHosts : false;
  1539. },
  1540. set: function (newValue) {
  1541. newTemplateSettings = this.templateSettings;
  1542. if (newValue) {
  1543. newTemplateSettings.dns.useSystemHosts = newValue;
  1544. } else {
  1545. delete newTemplateSettings.dns.useSystemHosts
  1546. }
  1547. this.templateSettings = newTemplateSettings;
  1548. }
  1549. },
  1550. dnsStrategy: {
  1551. get: function () {
  1552. return this.enableDNS ? this.templateSettings.dns.queryStrategy : null;
  1553. },
  1554. set: function (newValue) {
  1555. newTemplateSettings = this.templateSettings;
  1556. newTemplateSettings.dns.queryStrategy = newValue;
  1557. this.templateSettings = newTemplateSettings;
  1558. }
  1559. },
  1560. dnsServers: {
  1561. get: function () { return this.enableDNS ? this.templateSettings.dns.servers : []; },
  1562. set: function (newValue) {
  1563. newTemplateSettings = this.templateSettings;
  1564. newTemplateSettings.dns.servers = newValue;
  1565. this.templateSettings = newTemplateSettings;
  1566. }
  1567. },
  1568. fakeDns: {
  1569. get: function () { return this.templateSettings && this.templateSettings.fakedns ? this.templateSettings.fakedns : []; },
  1570. set: function (newValue) {
  1571. newTemplateSettings = this.templateSettings;
  1572. if (this.enableDNS) {
  1573. newTemplateSettings.fakedns = newValue.length > 0 ? newValue : null;
  1574. } else {
  1575. delete newTemplateSettings.fakedns;
  1576. }
  1577. this.templateSettings = newTemplateSettings;
  1578. }
  1579. }
  1580. },
  1581. });
  1582. </script>
  1583. {{ template "page/body_end" .}}