xray.html 69 KB

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