1
0

xray.html 59 KB

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