xray.html 69 KB

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