xray.html 60 KB

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