xray.html 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453
  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 fetchUserSecret() {
  379. this.loading(true);
  380. const userMessage = await HttpUtil.post("/panel/setting/getUserSecret", this.user);
  381. if (userMessage.success) {
  382. this.user = userMessage.obj;
  383. }
  384. this.loading(false);
  385. },
  386. async updateSecret() {
  387. this.loading(true);
  388. const msg = await HttpUtil.post("/panel/setting/updateUserSecret", this.user);
  389. if (msg.success) {
  390. this.user = msg.obj;
  391. window.location.replace(basePath + "logout");
  392. }
  393. this.loading(false);
  394. await this.updateXraySetting();
  395. },
  396. generateRandomString(length) {
  397. var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  398. let randomString = "";
  399. for (let i = 0; i < length; i++) {
  400. randomString += chars[Math.floor(Math.random() * chars.length)];
  401. }
  402. return randomString;
  403. },
  404. async getNewSecret() {
  405. this.loading(true);
  406. await PromiseUtil.sleep(600);
  407. const newSecret = this.generateRandomString(64);
  408. this.user.loginSecret = newSecret;
  409. document.getElementById("token").textContent = newSecret;
  410. this.loading(false);
  411. },
  412. async toggleToken(value) {
  413. if (value) {
  414. await this.getNewSecret();
  415. } else {
  416. this.user.loginSecret = "";
  417. }
  418. },
  419. async resetXrayConfigToDefault() {
  420. this.loading(true);
  421. const msg = await HttpUtil.get("/panel/setting/getDefaultJsonConfig");
  422. this.loading(false);
  423. if (msg.success) {
  424. this.templateSettings = JSON.parse(JSON.stringify(msg.obj, null, 2));
  425. this.saveBtnDisable = true;
  426. }
  427. },
  428. changePage(pageKey) {
  429. if(pageKey == 'tpl-advanced') this.changeCode();
  430. if(pageKey == 'tpl-balancer') this.changeObsCode();
  431. },
  432. syncRulesWithOutbound(tag, setting) {
  433. const newTemplateSettings = this.templateSettings;
  434. const haveRules = newTemplateSettings.routing.rules.some((r) => r?.outboundTag === tag);
  435. const outboundIndex = newTemplateSettings.outbounds.findIndex((o) => o.tag === tag);
  436. if (!haveRules && outboundIndex > 0) {
  437. newTemplateSettings.outbounds.splice(outboundIndex);
  438. }
  439. if (haveRules && outboundIndex < 0) {
  440. newTemplateSettings.outbounds.push(setting);
  441. }
  442. this.templateSettings = newTemplateSettings;
  443. },
  444. templateRuleGetter(routeSettings) {
  445. const { property, outboundTag } = routeSettings;
  446. let result = [];
  447. if (this.templateSettings != null) {
  448. this.templateSettings.routing.rules.forEach(
  449. (routingRule) => {
  450. if (
  451. routingRule.hasOwnProperty(property) &&
  452. routingRule.hasOwnProperty("outboundTag") &&
  453. routingRule.outboundTag === outboundTag
  454. ) {
  455. result.push(...routingRule[property]);
  456. }
  457. }
  458. );
  459. }
  460. return result;
  461. },
  462. templateRuleSetter(routeSettings) {
  463. const { data, property, outboundTag } = routeSettings;
  464. const oldTemplateSettings = this.templateSettings;
  465. const newTemplateSettings = oldTemplateSettings;
  466. currentProperty = this.templateRuleGetter({ outboundTag, property })
  467. if (currentProperty.length == 0) {
  468. const propertyRule = {
  469. type: "field",
  470. outboundTag,
  471. [property]: data
  472. };
  473. newTemplateSettings.routing.rules.push(propertyRule);
  474. }
  475. else {
  476. const newRules = [];
  477. insertedOnce = false;
  478. newTemplateSettings.routing.rules.forEach(
  479. (routingRule) => {
  480. if (
  481. routingRule.hasOwnProperty(property) &&
  482. routingRule.hasOwnProperty("outboundTag") &&
  483. routingRule.outboundTag === outboundTag
  484. ) {
  485. if (!insertedOnce && data.length > 0) {
  486. insertedOnce = true;
  487. routingRule[property] = data;
  488. newRules.push(routingRule);
  489. }
  490. }
  491. else {
  492. newRules.push(routingRule);
  493. }
  494. }
  495. );
  496. newTemplateSettings.routing.rules = newRules;
  497. }
  498. this.templateSettings = newTemplateSettings;
  499. },
  500. changeCode() {
  501. if(this.cm != null) {
  502. this.cm.toTextArea();
  503. }
  504. textAreaObj = document.getElementById('xraySetting');
  505. textAreaObj.value = this[this.advSettings];
  506. this.cm = CodeMirror.fromTextArea(textAreaObj, this.cmOptions);
  507. this.cm.on('change',editor => {
  508. value = editor.getValue();
  509. if (this.isJsonString(value)) {
  510. this[this.advSettings] = value;
  511. }
  512. });
  513. },
  514. changeObsCode() {
  515. if(this.cm != null) {
  516. this.cm.toTextArea();
  517. }
  518. if (this.obsSettings == ''){
  519. this.cm = null;
  520. return
  521. }
  522. textAreaObj = document.getElementById('obsSetting');
  523. textAreaObj.value = this[this.obsSettings];
  524. this.cm = CodeMirror.fromTextArea(textAreaObj, this.cmOptions);
  525. this.cm.on('change',editor => {
  526. value = editor.getValue();
  527. if(this.isJsonString(value)){
  528. this[this.obsSettings] = value;
  529. }
  530. });
  531. },
  532. isJsonString(str) {
  533. try {
  534. JSON.parse(str);
  535. } catch (e) {
  536. return false;
  537. }
  538. return true;
  539. },
  540. findOutboundTraffic(o) {
  541. for (const otraffic of this.outboundsTraffic) {
  542. if (otraffic.tag == o.tag) {
  543. return SizeFormatter.sizeFormat(otraffic.up) + ' / ' + SizeFormatter.sizeFormat(otraffic.down);
  544. }
  545. }
  546. return SizeFormatter.sizeFormat(0) + ' / ' + SizeFormatter.sizeFormat(0);
  547. },
  548. findOutboundAddress(o) {
  549. serverObj = null;
  550. switch(o.protocol){
  551. case Protocols.VMess:
  552. case Protocols.VLESS:
  553. serverObj = o.settings.vnext;
  554. break;
  555. case Protocols.HTTP:
  556. case Protocols.Socks:
  557. case Protocols.Shadowsocks:
  558. case Protocols.Trojan:
  559. serverObj = o.settings.servers;
  560. break;
  561. case Protocols.DNS:
  562. return [o.settings?.address + ':' + o.settings?.port];
  563. case Protocols.Wireguard:
  564. return o.settings.peers.map(peer => peer.endpoint);
  565. default:
  566. return null;
  567. }
  568. return serverObj ? serverObj.map(obj => obj.address + ':' + obj.port) : null;
  569. },
  570. addOutbound(){
  571. outModal.show({
  572. title: '{{ i18n "pages.xray.outbound.addOutbound"}}',
  573. okText: '{{ i18n "pages.xray.outbound.addOutbound" }}',
  574. confirm: (outbound) => {
  575. outModal.loading();
  576. if(outbound.tag.length > 0){
  577. this.templateSettings.outbounds.push(outbound);
  578. this.outboundSettings = JSON.stringify(this.templateSettings.outbounds);
  579. }
  580. outModal.close();
  581. },
  582. isEdit: false,
  583. tags: this.templateSettings.outbounds.map(obj => obj.tag)
  584. });
  585. },
  586. editOutbound(index){
  587. outModal.show({
  588. title: '{{ i18n "pages.xray.outbound.editOutbound"}} ' + (index+1),
  589. outbound: app.templateSettings.outbounds[index],
  590. confirm: (outbound) => {
  591. outModal.loading();
  592. this.templateSettings.outbounds[index] = outbound;
  593. this.outboundSettings = JSON.stringify(this.templateSettings.outbounds);
  594. outModal.close();
  595. },
  596. isEdit: true,
  597. tags: this.outboundData.filter((o) => o.key != index ).map(obj => obj.tag)
  598. });
  599. },
  600. deleteOutbound(index){
  601. outbounds = this.templateSettings.outbounds;
  602. outbounds.splice(index,1);
  603. this.outboundSettings = JSON.stringify(outbounds);
  604. },
  605. setFirstOutbound(index){
  606. outbounds = this.templateSettings.outbounds;
  607. outbounds.splice(0, 0, outbounds.splice(index, 1)[0]);
  608. this.outboundSettings = JSON.stringify(outbounds);
  609. },
  610. addReverse(){
  611. reverseModal.show({
  612. title: '{{ i18n "pages.xray.outbound.addReverse"}}',
  613. okText: '{{ i18n "pages.xray.outbound.addReverse" }}',
  614. confirm: (reverse, rules) => {
  615. reverseModal.loading();
  616. if(reverse.tag.length > 0){
  617. newTemplateSettings = this.templateSettings;
  618. if(newTemplateSettings.reverse == undefined) newTemplateSettings.reverse = {};
  619. if(newTemplateSettings.reverse[reverse.type+'s'] == undefined) newTemplateSettings.reverse[reverse.type+'s'] = [];
  620. newTemplateSettings.reverse[reverse.type+'s'].push({ tag: reverse.tag, domain: reverse.domain });
  621. this.templateSettings = newTemplateSettings;
  622. // Add related rules
  623. this.templateSettings.routing.rules.push(...rules);
  624. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  625. }
  626. reverseModal.close();
  627. },
  628. isEdit: false
  629. });
  630. },
  631. editReverse(index){
  632. if(this.reverseData[index].type == "bridge") {
  633. oldRules = this.templateSettings.routing.rules.filter(r => r.inboundTag && r.inboundTag[0] == this.reverseData[index].tag);
  634. } else {
  635. oldRules = this.templateSettings.routing.rules.filter(r => r.outboundTag && r.outboundTag == this.reverseData[index].tag);
  636. }
  637. reverseModal.show({
  638. title: '{{ i18n "pages.xray.outbound.editReverse"}} ' + (index+1),
  639. reverse: this.reverseData[index],
  640. rules: oldRules,
  641. confirm: (reverse, rules) => {
  642. reverseModal.loading();
  643. if(reverse.tag.length > 0){
  644. oldData = this.reverseData[index];
  645. newTemplateSettings = this.templateSettings;
  646. oldReverseIndex = newTemplateSettings.reverse[oldData.type+'s'].findIndex(rs => rs.tag == oldData.tag);
  647. oldRuleIndex0 = oldRules.length>0 ? newTemplateSettings.routing.rules.findIndex(r => JSON.stringify(r) == JSON.stringify(oldRules[0])) : -1;
  648. oldRuleIndex1 = oldRules.length==2 ? newTemplateSettings.routing.rules.findIndex(r => JSON.stringify(r) == JSON.stringify(oldRules[1])) : -1;
  649. if(oldData.type == reverse.type){
  650. newTemplateSettings.reverse[oldData.type + 's'][oldReverseIndex] = { tag: reverse.tag, domain: reverse.domain };
  651. } else {
  652. newTemplateSettings.reverse[oldData.type+'s'].splice(oldReverseIndex,1);
  653. // delete empty object
  654. if(newTemplateSettings.reverse[oldData.type+'s'].length == 0) Reflect.deleteProperty(newTemplateSettings.reverse, oldData.type+'s');
  655. // add other type of reverse if it is not exist
  656. if(!newTemplateSettings.reverse[reverse.type+'s']) newTemplateSettings.reverse[reverse.type+'s'] = [];
  657. newTemplateSettings.reverse[reverse.type+'s'].push({ tag: reverse.tag, domain: reverse.domain });
  658. }
  659. this.templateSettings = newTemplateSettings;
  660. // Adjust Rules
  661. newRules = this.templateSettings.routing.rules;
  662. oldRuleIndex0 != -1 ? newRules[oldRuleIndex0] = rules[0] : newRules.push(rules[0]);
  663. oldRuleIndex1 != -1 ? newRules[oldRuleIndex1] = rules[1] : newRules.push(rules[1]);
  664. this.routingRuleSettings = JSON.stringify(newRules);
  665. }
  666. reverseModal.close();
  667. },
  668. isEdit: true
  669. });
  670. },
  671. deleteReverse(index){
  672. oldData = this.reverseData[index];
  673. newTemplateSettings = this.templateSettings;
  674. reverseTypeObj = newTemplateSettings.reverse[oldData.type+'s'];
  675. realIndex = reverseTypeObj.findIndex(r => r.tag==oldData.tag && r.domain==oldData.domain);
  676. newTemplateSettings.reverse[oldData.type+'s'].splice(realIndex,1);
  677. // delete empty objects
  678. if(reverseTypeObj.length == 0) Reflect.deleteProperty(newTemplateSettings.reverse, oldData.type+'s');
  679. if(Object.keys(newTemplateSettings.reverse).length === 0) Reflect.deleteProperty(newTemplateSettings, 'reverse');
  680. // delete related routing rules
  681. newRules = newTemplateSettings.routing.rules;
  682. if(oldData.type == "bridge"){
  683. newRules = newTemplateSettings.routing.rules.filter(r => !( r.inboundTag && r.inboundTag.length == 1 && r.inboundTag[0] == oldData.tag));
  684. } else if(oldData.type == "portal"){
  685. newRules = newTemplateSettings.routing.rules.filter(r => r.outboundTag != oldData.tag);
  686. }
  687. newTemplateSettings.routing.rules = newRules;
  688. this.templateSettings = newTemplateSettings;
  689. },
  690. async refreshOutboundTraffic() {
  691. if (!this.refreshing) {
  692. this.refreshing = true;
  693. await this.getOutboundsTraffic();
  694. data = []
  695. if (this.templateSettings != null) {
  696. this.templateSettings.outbounds.forEach((o, index) => {
  697. data.push({'key': index, ...o});
  698. });
  699. }
  700. this.outboundData = data;
  701. this.refreshing = false;
  702. }
  703. },
  704. async resetOutboundTraffic(index) {
  705. let tag = "-alltags-";
  706. if (index >= 0) {
  707. tag = this.outboundData[index].tag ? this.outboundData[index].tag : ""
  708. }
  709. const msg = await HttpUtil.post("/panel/xray/resetOutboundsTraffic", { tag: tag });
  710. if (msg.success) {
  711. await this.refreshOutboundTraffic();
  712. }
  713. },
  714. addBalancer() {
  715. balancerModal.show({
  716. title: '{{ i18n "pages.xray.balancer.addBalancer"}}',
  717. okText: '{{ i18n "pages.xray.balancer.addBalancer"}}',
  718. balancerTags: this.balancersData.filter((o) => !ObjectUtil.isEmpty(o.tag)).map(obj => obj.tag),
  719. balancer: {
  720. tag: '',
  721. strategy: 'random',
  722. selector: [],
  723. fallbackTag: ''
  724. },
  725. confirm: (balancer) => {
  726. balancerModal.loading();
  727. newTemplateSettings = this.templateSettings;
  728. if (newTemplateSettings.routing.balancers == undefined) {
  729. newTemplateSettings.routing.balancers = [];
  730. }
  731. let tmpBalancer = {
  732. 'tag': balancer.tag,
  733. 'selector': balancer.selector,
  734. 'fallbackTag': balancer.fallbackTag
  735. };
  736. if (balancer.strategy && balancer.strategy != 'random') {
  737. tmpBalancer.strategy = {
  738. 'type': balancer.strategy
  739. };
  740. }
  741. newTemplateSettings.routing.balancers.push(tmpBalancer);
  742. this.templateSettings = newTemplateSettings;
  743. this.updateObservatorySelectors();
  744. balancerModal.close();
  745. this.changeObsCode();
  746. },
  747. isEdit: false
  748. });
  749. },
  750. editBalancer(index) {
  751. const oldTag = this.balancersData[index].tag;
  752. balancerModal.show({
  753. title: '{{ i18n "pages.xray.balancer.editBalancer"}}',
  754. okText: '{{ i18n "sure" }}',
  755. balancerTags: this.balancersData.filter((o) => !ObjectUtil.isEmpty(o.tag)).map(obj => obj.tag),
  756. balancer: this.balancersData[index],
  757. confirm: (balancer) => {
  758. balancerModal.loading();
  759. newTemplateSettings = this.templateSettings;
  760. let tmpBalancer = {
  761. 'tag': balancer.tag,
  762. 'selector': balancer.selector,
  763. 'fallbackTag': balancer.fallbackTag
  764. };
  765. // Remove old tag
  766. if (newTemplateSettings.observatory){
  767. newTemplateSettings.observatory.subjectSelector = newTemplateSettings.observatory.subjectSelector.filter(s => s != oldTag);
  768. }
  769. if (newTemplateSettings.burstObservatory){
  770. newTemplateSettings.burstObservatory.subjectSelector = newTemplateSettings.burstObservatory.subjectSelector.filter(s => s != oldTag);
  771. }
  772. if (balancer.strategy && balancer.strategy != 'random') {
  773. tmpBalancer.strategy = {
  774. 'type': balancer.strategy
  775. };
  776. }
  777. newTemplateSettings.routing.balancers[index] = tmpBalancer;
  778. // change edited tag if used in rule section
  779. if (oldTag != balancer.tag) {
  780. newTemplateSettings.routing.rules.forEach((rule) => {
  781. if (rule.balancerTag && rule.balancerTag == oldTag) {
  782. rule.balancerTag = balancer.tag;
  783. }
  784. });
  785. }
  786. this.templateSettings = newTemplateSettings;
  787. this.updateObservatorySelectors();
  788. balancerModal.close();
  789. this.changeObsCode();
  790. },
  791. isEdit: true
  792. });
  793. },
  794. updateObservatorySelectors(){
  795. newTemplateSettings = this.templateSettings;
  796. const leastPings = this.balancersData.filter((b) => b.strategy == 'leastPing');
  797. const leastLoads = this.balancersData.filter((b) =>
  798. b.strategy === 'leastLoad' ||
  799. b.strategy === 'roundRobin' ||
  800. b.strategy === 'random'
  801. );
  802. if (leastPings.length>0){
  803. if (!newTemplateSettings.observatory)
  804. newTemplateSettings.observatory = this.defaultObservatory;
  805. newTemplateSettings.observatory.subjectSelector = [];
  806. leastPings.forEach((b) => {
  807. b.selector.forEach((s) => {
  808. if (!newTemplateSettings.observatory.subjectSelector.includes(s))
  809. newTemplateSettings.observatory.subjectSelector.push(s);
  810. });
  811. });
  812. } else {
  813. delete newTemplateSettings.observatory
  814. }
  815. if (leastLoads.length>0){
  816. if (!newTemplateSettings.burstObservatory)
  817. newTemplateSettings.burstObservatory = this.defaultBurstObservatory;
  818. newTemplateSettings.burstObservatory.subjectSelector = [];
  819. leastLoads.forEach((b) => {
  820. b.selector.forEach((s) => {
  821. if (!newTemplateSettings.burstObservatory.subjectSelector.includes(s))
  822. newTemplateSettings.burstObservatory.subjectSelector.push(s);
  823. });
  824. });
  825. } else {
  826. delete newTemplateSettings.burstObservatory
  827. }
  828. this.templateSettings = newTemplateSettings;
  829. this.changeObsCode();
  830. },
  831. deleteBalancer(index) {
  832. newTemplateSettings = this.templateSettings;
  833. // Remove from balancers
  834. const removedBalancer = this.balancersData.splice(index, 1)[0];
  835. // Remove from settings
  836. let realIndex = newTemplateSettings.routing.balancers.findIndex((b) => b.tag === removedBalancer.tag);
  837. newTemplateSettings.routing.balancers.splice(realIndex, 1);
  838. // Update balancers property to an empty array if there are no more balancers
  839. if (newTemplateSettings.routing.balancers.length === 0) {
  840. delete newTemplateSettings.routing.balancers;
  841. }
  842. this.templateSettings = newTemplateSettings;
  843. this.updateObservatorySelectors();
  844. this.obsSettings = '';
  845. this.changeObsCode()
  846. },
  847. addDNSServer(){
  848. dnsModal.show({
  849. title: '{{ i18n "pages.xray.dns.add" }}',
  850. confirm: (dnsServer) => {
  851. dnsServers = this.dnsServers;
  852. dnsServers.push(dnsServer);
  853. this.dnsServers = dnsServers;
  854. dnsModal.close();
  855. },
  856. isEdit: false
  857. });
  858. },
  859. editDNSServer(index){
  860. dnsModal.show({
  861. title: '{{ i18n "pages.xray.dns.edit" }} #' + (index+1),
  862. dnsServer: this.dnsServers[index],
  863. confirm: (dnsServer) => {
  864. dnsServers = this.dnsServers;
  865. dnsServers[index] = dnsServer;
  866. this.dnsServers = dnsServers;
  867. dnsModal.close();
  868. },
  869. isEdit: true
  870. });
  871. },
  872. deleteDNSServer(index){
  873. newDnsServers = this.dnsServers;
  874. newDnsServers.splice(index,1);
  875. this.dnsServers = newDnsServers;
  876. },
  877. addFakedns() {
  878. fakednsModal.show({
  879. title: '{{ i18n "pages.xray.fakedns.add" }}',
  880. confirm: (item) => {
  881. fakeDns = this.fakeDns?? [];
  882. fakeDns.push(item);
  883. this.fakeDns = fakeDns;
  884. fakednsModal.close();
  885. },
  886. isEdit: false
  887. });
  888. },
  889. editFakedns(index){
  890. fakednsModal.show({
  891. title: '{{ i18n "pages.xray.fakedns.edit" }} #' + (index+1),
  892. fakeDns: this.fakeDns[index],
  893. confirm: (item) => {
  894. fakeDns = this.fakeDns;
  895. fakeDns[index] = item;
  896. this.fakeDns = fakeDns;
  897. fakednsModal.close();
  898. },
  899. isEdit: true
  900. });
  901. },
  902. deleteFakedns(index){
  903. fakeDns = this.fakeDns;
  904. fakeDns.splice(index,1);
  905. this.fakeDns = fakeDns;
  906. },
  907. addRule(){
  908. ruleModal.show({
  909. title: '{{ i18n "pages.xray.rules.add"}}',
  910. okText: '{{ i18n "pages.xray.rules.add" }}',
  911. confirm: (rule) => {
  912. ruleModal.loading();
  913. if(JSON.stringify(rule).length > 3){
  914. this.templateSettings.routing.rules.push(rule);
  915. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  916. }
  917. ruleModal.close();
  918. },
  919. isEdit: false
  920. });
  921. },
  922. editRule(index){
  923. ruleModal.show({
  924. title: '{{ i18n "pages.xray.rules.edit"}} ' + (index+1),
  925. rule: app.templateSettings.routing.rules[index],
  926. confirm: (rule) => {
  927. ruleModal.loading();
  928. if(JSON.stringify(rule).length > 3){
  929. this.templateSettings.routing.rules[index] = rule;
  930. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  931. }
  932. ruleModal.close();
  933. },
  934. isEdit: true
  935. });
  936. },
  937. replaceRule(old_index,new_index){
  938. rules = this.templateSettings.routing.rules;
  939. if (new_index >= rules.length) rules.push(undefined);
  940. rules.splice(new_index, 0, rules.splice(old_index, 1)[0]);
  941. this.routingRuleSettings = JSON.stringify(rules);
  942. },
  943. deleteRule(index){
  944. rules = this.templateSettings.routing.rules;
  945. rules.splice(index,1);
  946. this.routingRuleSettings = JSON.stringify(rules);
  947. },
  948. showWarp(){
  949. warpModal.show();
  950. }
  951. },
  952. async mounted() {
  953. if (window.location.protocol !== "https:") {
  954. this.showAlert = true;
  955. }
  956. await this.getXraySetting();
  957. await this.getXrayResult();
  958. await this.getOutboundsTraffic();
  959. while (true) {
  960. await PromiseUtil.sleep(800);
  961. this.saveBtnDisable = this.oldXraySetting === this.xraySetting;
  962. }
  963. },
  964. computed: {
  965. templateSettings: {
  966. get: function () {
  967. const parsedSettings = this.xraySetting ? JSON.parse(this.xraySetting) : null;
  968. return parsedSettings;
  969. },
  970. set: function (newValue) {
  971. if (newValue) {
  972. this.xraySetting = JSON.stringify(newValue, null, 2);
  973. }
  974. },
  975. },
  976. inboundSettings: {
  977. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.inbounds, null, 2) : null; },
  978. set: function (newValue) {
  979. newTemplateSettings = this.templateSettings;
  980. newTemplateSettings.inbounds = JSON.parse(newValue);
  981. this.templateSettings = newTemplateSettings;
  982. },
  983. },
  984. outboundSettings: {
  985. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.outbounds, null, 2) : null; },
  986. set: function (newValue) {
  987. newTemplateSettings = this.templateSettings;
  988. newTemplateSettings.outbounds = JSON.parse(newValue);
  989. this.templateSettings = newTemplateSettings;
  990. },
  991. },
  992. outboundData: {
  993. get: function () {
  994. data = []
  995. if (this.templateSettings != null) {
  996. this.templateSettings.outbounds.forEach((o, index) => {
  997. data.push({'key': index, ...o});
  998. });
  999. }
  1000. return data;
  1001. },
  1002. },
  1003. reverseData: {
  1004. get: function () {
  1005. data = []
  1006. if (this.templateSettings != null && this.templateSettings.reverse != null) {
  1007. if(this.templateSettings.reverse.bridges) {
  1008. this.templateSettings.reverse.bridges.forEach((o, index) => {
  1009. data.push({'key': index, 'type':'bridge', ...o});
  1010. });
  1011. }
  1012. if(this.templateSettings.reverse.portals){
  1013. this.templateSettings.reverse.portals.forEach((o, index) => {
  1014. data.push({'key': index, 'type':'portal', ...o});
  1015. });
  1016. }
  1017. }
  1018. return data;
  1019. },
  1020. },
  1021. routingRuleSettings: {
  1022. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.routing.rules, null, 2) : null; },
  1023. set: function (newValue) {
  1024. newTemplateSettings = this.templateSettings;
  1025. newTemplateSettings.routing.rules = JSON.parse(newValue);
  1026. this.templateSettings = newTemplateSettings;
  1027. },
  1028. },
  1029. routingRuleData: {
  1030. get: function () {
  1031. data = [];
  1032. if (this.templateSettings != null) {
  1033. this.templateSettings.routing.rules.forEach((r, index) => {
  1034. data.push({'key': index, ...r});
  1035. });
  1036. // Make rules readable
  1037. data.forEach(r => {
  1038. if(r.domain) r.domain = r.domain.join(',')
  1039. if(r.ip) r.ip = r.ip.join(',')
  1040. if(r.source) r.source = r.source.join(',');
  1041. if(r.user) r.user = r.user.join(',')
  1042. if(r.inboundTag) r.inboundTag = r.inboundTag.join(',')
  1043. if(r.protocol) r.protocol = r.protocol.join(',')
  1044. if(r.attrs) r.attrs = JSON.stringify(r.attrs, null, 2)
  1045. });
  1046. }
  1047. return data;
  1048. }
  1049. },
  1050. balancersData: {
  1051. get: function () {
  1052. data = []
  1053. if (this.templateSettings != null && this.templateSettings.routing != null && this.templateSettings.routing.balancers != null) {
  1054. this.templateSettings.routing.balancers.forEach((o, index) => {
  1055. data.push({
  1056. 'key': index,
  1057. 'tag': o.tag ? o.tag : "",
  1058. 'strategy': o.strategy?.type ?? "random",
  1059. 'selector': o.selector ? o.selector : [],
  1060. 'fallbackTag': o.fallbackTag?? '',
  1061. });
  1062. });
  1063. }
  1064. return data;
  1065. }
  1066. },
  1067. observatory: {
  1068. get: function () {
  1069. return this.templateSettings?.observatory ? JSON.stringify(this.templateSettings.observatory, null, 2) : null;
  1070. },
  1071. set: function (newValue) {
  1072. newTemplateSettings = this.templateSettings;
  1073. newTemplateSettings.observatory = JSON.parse(newValue);
  1074. this.templateSettings = newTemplateSettings;
  1075. },
  1076. },
  1077. burstObservatory: {
  1078. get: function () {
  1079. return this.templateSettings?.burstObservatory ? JSON.stringify(this.templateSettings.burstObservatory, null, 2) : null;
  1080. },
  1081. set: function (newValue) {
  1082. newTemplateSettings = this.templateSettings;
  1083. newTemplateSettings.burstObservatory = JSON.parse(newValue);
  1084. this.templateSettings = newTemplateSettings;
  1085. },
  1086. },
  1087. observatoryEnable: function () { return this.templateSettings != null && this.templateSettings.observatory != undefined },
  1088. burstObservatoryEnable: function () { return this.templateSettings != null && this.templateSettings.burstObservatory != undefined },
  1089. freedomStrategy: {
  1090. get: function () {
  1091. if (!this.templateSettings) return "AsIs";
  1092. freedomOutbound = this.templateSettings.outbounds.find((o) => o.protocol === "freedom" && o.tag == "direct");
  1093. if (!freedomOutbound) return "AsIs";
  1094. if (!freedomOutbound.settings || !freedomOutbound.settings.domainStrategy) return "AsIs";
  1095. return freedomOutbound.settings.domainStrategy;
  1096. },
  1097. set: function (newValue) {
  1098. newTemplateSettings = this.templateSettings;
  1099. freedomOutboundIndex = newTemplateSettings.outbounds.findIndex((o) => o.protocol === "freedom" && o.tag == "direct");
  1100. if(freedomOutboundIndex == -1){
  1101. newTemplateSettings.outbounds.push({protocol: "freedom", tag: "direct", settings: { "domainStrategy": newValue }});
  1102. } else if (!newTemplateSettings.outbounds[freedomOutboundIndex].settings) {
  1103. newTemplateSettings.outbounds[freedomOutboundIndex].settings = {"domainStrategy": newValue};
  1104. } else {
  1105. newTemplateSettings.outbounds[freedomOutboundIndex].settings.domainStrategy = newValue;
  1106. }
  1107. this.templateSettings = newTemplateSettings;
  1108. }
  1109. },
  1110. routingStrategy: {
  1111. get: function () {
  1112. if (!this.templateSettings || !this.templateSettings.routing || !this.templateSettings.routing.domainStrategy) return "AsIs";
  1113. return this.templateSettings.routing.domainStrategy;
  1114. },
  1115. set: function (newValue) {
  1116. newTemplateSettings = this.templateSettings;
  1117. newTemplateSettings.routing.domainStrategy = newValue;
  1118. this.templateSettings = newTemplateSettings;
  1119. }
  1120. },
  1121. logLevel: {
  1122. get: function () {
  1123. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.loglevel) return "warning";
  1124. return this.templateSettings.log.loglevel;
  1125. },
  1126. set: function (newValue) {
  1127. newTemplateSettings = this.templateSettings;
  1128. newTemplateSettings.log.loglevel = newValue;
  1129. this.templateSettings = newTemplateSettings;
  1130. }
  1131. },
  1132. accessLog: {
  1133. get: function () {
  1134. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.access) return "";
  1135. return this.templateSettings.log.access;
  1136. },
  1137. set: function (newValue) {
  1138. newTemplateSettings = this.templateSettings;
  1139. newTemplateSettings.log.access = newValue;
  1140. this.templateSettings = newTemplateSettings;
  1141. }
  1142. },
  1143. errorLog: {
  1144. get: function () {
  1145. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.error) return "";
  1146. return this.templateSettings.log.error;
  1147. },
  1148. set: function (newValue) {
  1149. newTemplateSettings = this.templateSettings;
  1150. newTemplateSettings.log.error = newValue;
  1151. this.templateSettings = newTemplateSettings;
  1152. }
  1153. },
  1154. dnslog: {
  1155. get: function () {
  1156. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.dnsLog) return false;
  1157. return this.templateSettings.log.dnsLog;
  1158. },
  1159. set: function (newValue) {
  1160. newTemplateSettings = this.templateSettings;
  1161. newTemplateSettings.log.dnsLog = newValue;
  1162. this.templateSettings = newTemplateSettings;
  1163. }
  1164. },
  1165. statsInboundUplink: {
  1166. get: function () {
  1167. if (!this.templateSettings || !this.templateSettings.policy.system || !this.templateSettings.policy.system.statsInboundUplink) return false;
  1168. return this.templateSettings.policy.system.statsInboundUplink;
  1169. },
  1170. set: function (newValue) {
  1171. newTemplateSettings = this.templateSettings;
  1172. newTemplateSettings.policy.system.statsInboundUplink = newValue;
  1173. this.templateSettings = newTemplateSettings;
  1174. }
  1175. },
  1176. statsInboundDownlink: {
  1177. get: function () {
  1178. if (!this.templateSettings || !this.templateSettings.policy.system || !this.templateSettings.policy.system.statsInboundDownlink) return false;
  1179. return this.templateSettings.policy.system.statsInboundDownlink;
  1180. },
  1181. set: function (newValue) {
  1182. newTemplateSettings = this.templateSettings;
  1183. newTemplateSettings.policy.system.statsInboundDownlink = newValue;
  1184. this.templateSettings = newTemplateSettings;
  1185. }
  1186. },
  1187. statsOutboundUplink: {
  1188. get: function () {
  1189. if (!this.templateSettings || !this.templateSettings.policy.system || !this.templateSettings.policy.system.statsOutboundUplink) return false;
  1190. return this.templateSettings.policy.system.statsOutboundUplink;
  1191. },
  1192. set: function (newValue) {
  1193. newTemplateSettings = this.templateSettings;
  1194. newTemplateSettings.policy.system.statsOutboundUplink = newValue;
  1195. this.templateSettings = newTemplateSettings;
  1196. }
  1197. },
  1198. statsOutboundDownlink: {
  1199. get: function () {
  1200. if (!this.templateSettings || !this.templateSettings.policy.system || !this.templateSettings.policy.system.statsOutboundDownlink) return false;
  1201. return this.templateSettings.policy.system.statsOutboundDownlink;
  1202. },
  1203. set: function (newValue) {
  1204. newTemplateSettings = this.templateSettings;
  1205. newTemplateSettings.policy.system.statsOutboundDownlink = newValue;
  1206. this.templateSettings = newTemplateSettings;
  1207. }
  1208. },
  1209. maskAddressLog: {
  1210. get: function () {
  1211. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.maskAddress) return "";
  1212. return this.templateSettings.log.maskAddress;
  1213. },
  1214. set: function (newValue) {
  1215. newTemplateSettings = this.templateSettings;
  1216. newTemplateSettings.log.maskAddress = newValue;
  1217. this.templateSettings = newTemplateSettings;
  1218. }
  1219. },
  1220. blockedIPs: {
  1221. get: function () {
  1222. return this.templateRuleGetter({ outboundTag: "blocked", property: "ip" });
  1223. },
  1224. set: function (newValue) {
  1225. this.templateRuleSetter({ outboundTag: "blocked", property: "ip", data: newValue });
  1226. }
  1227. },
  1228. blockedDomains: {
  1229. get: function () {
  1230. return this.templateRuleGetter({ outboundTag: "blocked", property: "domain" });
  1231. },
  1232. set: function (newValue) {
  1233. this.templateRuleSetter({ outboundTag: "blocked", property: "domain", data: newValue });
  1234. }
  1235. },
  1236. blockedProtocols: {
  1237. get: function () {
  1238. return this.templateRuleGetter({ outboundTag: "blocked", property: "protocol" });
  1239. },
  1240. set: function (newValue) {
  1241. this.templateRuleSetter({ outboundTag: "blocked", property: "protocol", data: newValue });
  1242. }
  1243. },
  1244. directIPs: {
  1245. get: function () {
  1246. return this.templateRuleGetter({ outboundTag: "direct", property: "ip" });
  1247. },
  1248. set: function (newValue) {
  1249. this.templateRuleSetter({ outboundTag: "direct", property: "ip", data: newValue });
  1250. this.syncRulesWithOutbound("direct", this.directSettings);
  1251. }
  1252. },
  1253. directDomains: {
  1254. get: function () {
  1255. return this.templateRuleGetter({ outboundTag: "direct", property: "domain" });
  1256. },
  1257. set: function (newValue) {
  1258. this.templateRuleSetter({ outboundTag: "direct", property: "domain", data: newValue });
  1259. this.syncRulesWithOutbound("direct", this.directSettings);
  1260. }
  1261. },
  1262. ipv4Domains: {
  1263. get: function () {
  1264. return this.templateRuleGetter({ outboundTag: "IPv4", property: "domain" });
  1265. },
  1266. set: function (newValue) {
  1267. this.templateRuleSetter({ outboundTag: "IPv4", property: "domain", data: newValue });
  1268. this.syncRulesWithOutbound("IPv4", this.ipv4Settings);
  1269. }
  1270. },
  1271. warpDomains: {
  1272. get: function () {
  1273. return this.templateRuleGetter({ outboundTag: "warp", property: "domain" });
  1274. },
  1275. set: function (newValue) {
  1276. this.templateRuleSetter({ outboundTag: "warp", property: "domain", data: newValue });
  1277. }
  1278. },
  1279. torrentSettings: {
  1280. get: function () {
  1281. return ArrayUtils.doAllItemsExist(this.settingsData.protocols.bittorrent, this.blockedProtocols);
  1282. },
  1283. set: function (newValue) {
  1284. if (newValue) {
  1285. this.blockedProtocols = [...this.blockedProtocols, ...this.settingsData.protocols.bittorrent];
  1286. } else {
  1287. this.blockedProtocols = this.blockedProtocols.filter(data => !this.settingsData.protocols.bittorrent.includes(data));
  1288. }
  1289. },
  1290. },
  1291. familyProtectSettings: {
  1292. get: function () {
  1293. if (!this.templateSettings || !this.templateSettings.dns || !this.templateSettings.dns.servers) return false;
  1294. return ArrayUtils.doAllItemsExist(this.settingsData.familyProtectDNS.servers, this.templateSettings.dns.servers);
  1295. },
  1296. set: function (newValue) {
  1297. newTemplateSettings = this.templateSettings;
  1298. if (newValue) {
  1299. newTemplateSettings.dns = this.settingsData.familyProtectDNS;
  1300. } else {
  1301. newTemplateSettings.dns.servers = newTemplateSettings.dns?.servers?.filter(data => !this.settingsData.familyProtectDNS.servers.includes(data))
  1302. }
  1303. this.templateSettings = newTemplateSettings;
  1304. },
  1305. },
  1306. WarpExist: {
  1307. get: function() {
  1308. return this.templateSettings ? this.templateSettings.outbounds.findIndex((o) => o.tag == "warp")>=0 : false;
  1309. },
  1310. },
  1311. enableDNS: {
  1312. get: function () {
  1313. return this.templateSettings ? this.templateSettings.dns != null : false;
  1314. },
  1315. set: function (newValue) {
  1316. newTemplateSettings = this.templateSettings;
  1317. if (newValue) {
  1318. newTemplateSettings.dns = {
  1319. servers: [],
  1320. queryStrategy: "UseIP",
  1321. tag: "dns_inbound"
  1322. };
  1323. newTemplateSettings.fakedns = null;
  1324. } else {
  1325. delete newTemplateSettings.dns;
  1326. delete newTemplateSettings.fakedns;
  1327. }
  1328. this.templateSettings = newTemplateSettings;
  1329. }
  1330. },
  1331. dnsTag: {
  1332. get: function () {
  1333. return this.enableDNS ? this.templateSettings.dns.tag : "";
  1334. },
  1335. set: function (newValue) {
  1336. newTemplateSettings = this.templateSettings;
  1337. newTemplateSettings.dns.tag = newValue;
  1338. this.templateSettings = newTemplateSettings;
  1339. }
  1340. },
  1341. dnsClientIp: {
  1342. get: function () {
  1343. return this.enableDNS ? this.templateSettings.dns.clientIp : null;
  1344. },
  1345. set: function (newValue) {
  1346. newTemplateSettings = this.templateSettings;
  1347. if (newValue) {
  1348. newTemplateSettings.dns.clientIp = newValue;
  1349. } else {
  1350. delete newTemplateSettings.dns.clientIp;
  1351. }
  1352. this.templateSettings = newTemplateSettings;
  1353. }
  1354. },
  1355. dnsDisableCache: {
  1356. get: function () {
  1357. return this.enableDNS ? this.templateSettings.dns.disableCache : false;
  1358. },
  1359. set: function (newValue) {
  1360. newTemplateSettings = this.templateSettings;
  1361. if (newValue) {
  1362. newTemplateSettings.dns.disableCache = newValue;
  1363. } else {
  1364. delete newTemplateSettings.dns.disableCache
  1365. }
  1366. this.templateSettings = newTemplateSettings;
  1367. }
  1368. },
  1369. dnsDisableFallback: {
  1370. get: function () {
  1371. return this.enableDNS ? this.templateSettings.dns.disableFallback : false;
  1372. },
  1373. set: function (newValue) {
  1374. newTemplateSettings = this.templateSettings;
  1375. if (newValue) {
  1376. newTemplateSettings.dns.disableFallback = newValue;
  1377. } else {
  1378. delete newTemplateSettings.dns.disableFallback
  1379. }
  1380. this.templateSettings = newTemplateSettings;
  1381. }
  1382. },
  1383. dnsDisableFallbackIfMatch: {
  1384. get: function () {
  1385. return this.enableDNS ? this.templateSettings.dns.disableFallbackIfMatch : false;
  1386. },
  1387. set: function (newValue) {
  1388. newTemplateSettings = this.templateSettings;
  1389. if (newValue) {
  1390. newTemplateSettings.dns.disableFallbackIfMatch = newValue;
  1391. } else {
  1392. delete newTemplateSettings.dns.disableFallbackIfMatch
  1393. }
  1394. this.templateSettings = newTemplateSettings;
  1395. }
  1396. },
  1397. dnsStrategy: {
  1398. get: function () {
  1399. return this.enableDNS ? this.templateSettings.dns.queryStrategy : null;
  1400. },
  1401. set: function (newValue) {
  1402. newTemplateSettings = this.templateSettings;
  1403. newTemplateSettings.dns.queryStrategy = newValue;
  1404. this.templateSettings = newTemplateSettings;
  1405. }
  1406. },
  1407. dnsServers: {
  1408. get: function () { return this.enableDNS ? this.templateSettings.dns.servers : []; },
  1409. set: function (newValue) {
  1410. newTemplateSettings = this.templateSettings;
  1411. newTemplateSettings.dns.servers = newValue;
  1412. this.templateSettings = newTemplateSettings;
  1413. }
  1414. },
  1415. fakeDns: {
  1416. get: function () { return this.templateSettings && this.templateSettings.fakedns ? this.templateSettings.fakedns : []; },
  1417. set: function (newValue) {
  1418. newTemplateSettings = this.templateSettings;
  1419. if (this.enableDNS) {
  1420. newTemplateSettings.fakedns = newValue.length > 0 ? newValue : null;
  1421. } else {
  1422. delete newTemplateSettings.fakedns;
  1423. }
  1424. this.templateSettings = newTemplateSettings;
  1425. }
  1426. }
  1427. },
  1428. });
  1429. </script>
  1430. </body>
  1431. </html>