xray.html 59 KB

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