xray.html 68 KB

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