xray.html 70 KB

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