xray.html 110 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082
  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/base64/base64.min.js"></script>
  9. <script src="{{ .base_path }}assets/js/model/outbound.js?{{ .cur_ver }}"></script>
  10. <script src="{{ .base_path }}assets/codemirror/codemirror.min.js?{{ .cur_ver }}"></script>
  11. <script src="{{ .base_path }}assets/codemirror/javascript.js"></script>
  12. <script src="{{ .base_path }}assets/codemirror/jshint.js"></script>
  13. <script src="{{ .base_path }}assets/codemirror/jsonlint.js"></script>
  14. <script src="{{ .base_path }}assets/codemirror/lint/lint.js"></script>
  15. <script src="{{ .base_path }}assets/codemirror/lint/javascript-lint.js"></script>
  16. <script src="{{ .base_path }}assets/codemirror/hint/javascript-hint.js"></script>
  17. <script src="{{ .base_path }}assets/codemirror/fold/foldcode.js"></script>
  18. <script src="{{ .base_path }}assets/codemirror/fold/foldgutter.js"></script>
  19. <script src="{{ .base_path }}assets/codemirror/fold/brace-fold.js"></script>
  20. <style>
  21. @media (min-width: 769px) {
  22. .ant-layout-content {
  23. margin: 24px 16px;
  24. }
  25. }
  26. @media (max-width: 768px) {
  27. .ant-tabs-nav .ant-tabs-tab {
  28. margin: 0;
  29. padding: 12px .5rem;
  30. }
  31. .ant-table-thead>tr>th,
  32. .ant-table-tbody>tr>td {
  33. padding: 10px 0px;
  34. }
  35. }
  36. .ant-tabs-bar {
  37. margin: 0;
  38. }
  39. .ant-list-item {
  40. display: block;
  41. }
  42. .collapse-title {
  43. color: inherit;
  44. font-weight: bold;
  45. font-size: 18px;
  46. padding: 10px 20px;
  47. border-bottom: 2px solid;
  48. }
  49. .collapse-title>i {
  50. color: inherit;
  51. font-size: 24px;
  52. }
  53. .ant-collapse-content-box>li {
  54. padding: 12px 0 0 !important;
  55. }
  56. .ant-list-item>li {
  57. padding: 10px 20px !important;
  58. }
  59. </style>
  60. <body>
  61. <a-layout id="app" v-cloak :class="themeSwitcher.currentTheme">
  62. {{ template "commonSider" . }}
  63. <a-layout id="content-layout">
  64. <a-layout-content>
  65. <a-spin :spinning="spinning" :delay="500" tip='{{ i18n "loading"}}'>
  66. <transition name="list" appear>
  67. <a-alert type="error" v-if="showAlert" style="margin-bottom: 10px"
  68. message='{{ i18n "secAlertTitle" }}'
  69. color="red"
  70. description='{{ i18n "secAlertSsl" }}'
  71. show-icon closable>
  72. </a-alert>
  73. </transition>
  74. <a-space direction="vertical">
  75. <a-card hoverable style="margin-bottom: .5rem;">
  76. <a-row style="display: flex; flex-wrap: wrap; align-items: center;">
  77. <a-col :xs="24" :sm="10" style="padding: 4px;">
  78. <a-space direction="horizontal">
  79. <a-button type="primary" :disabled="saveBtnDisable" @click="updateXraySetting">{{ i18n "pages.xray.save" }}</a-button>
  80. <a-button type="danger" :disabled="!saveBtnDisable" @click="restartXray">{{ i18n "pages.xray.restart" }}</a-button>
  81. <a-popover v-if="restartResult"
  82. :overlay-class-name="themeSwitcher.currentTheme">
  83. <span slot="title" style="font-size: 12pt">Error in running xray-core</span>
  84. <template slot="content">
  85. <p style="max-width: 400px" v-for="line in restartResult.split('\n')">[[ line ]]</p>
  86. </template>
  87. <a-icon type="question-circle"></a-icon>
  88. </a-popover>
  89. </a-space>
  90. </a-col>
  91. <a-col :xs="24" :sm="14">
  92. <template>
  93. <div>
  94. <a-back-top :target="() => document.getElementById('content-layout')" visibility-height="200"></a-back-top>
  95. <a-alert type="warning" style="float: right; width: fit-content" message='{{ i18n "pages.settings.infoDesc" }}' show-icon>
  96. </a-alert>
  97. </div>
  98. </template>
  99. </a-col>
  100. </a-row>
  101. </a-card>
  102. <a-tabs class="ant-card-dark-box-nohover" default-active-key="1"
  103. @change="(activeKey) => { this.changePage(activeKey); }"
  104. :class="themeSwitcher.currentTheme">
  105. <a-tab-pane key="tpl-basic" tab='{{ i18n "pages.xray.basicTemplate"}}' style="padding-top: 20px;">
  106. <a-collapse>
  107. <a-collapse-panel header='{{ i18n "pages.xray.generalConfigs"}}'>
  108. <a-row :xs="24" :sm="24" :lg="12">
  109. <a-alert type="warning" style="text-align: center;">
  110. <template slot="message">
  111. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  112. {{ i18n "pages.xray.generalConfigsDesc" }}
  113. </template>
  114. </a-alert>
  115. </a-row>
  116. <a-setting-list-item paddings="small">
  117. <template #title>{{ i18n "pages.xray.FreedomStrategy" }}</template>
  118. <template #description>{{ i18n "pages.xray.FreedomStrategyDesc" }}</template>
  119. <template #control>
  120. <a-select v-model="freedomStrategy" :dropdown-class-name="themeSwitcher.currentTheme" style="width: 100%">
  121. <a-select-option v-for="s in OutboundDomainStrategies" :value="s">[[ s ]]</a-select-option>
  122. </a-select>
  123. </template>
  124. </a-setting-list-item>
  125. <a-setting-list-item paddings="small">
  126. <template #title>{{ i18n "pages.xray.RoutingStrategy" }}</template>
  127. <template #description>{{ i18n "pages.xray.RoutingStrategyDesc" }}</template>
  128. <template #control>
  129. <a-select v-model="routingStrategy" :dropdown-class-name="themeSwitcher.currentTheme" style="width: 100%">
  130. <a-select-option v-for="s in routingDomainStrategies" :value="s">[[ s ]]</a-select-option>
  131. </a-select>
  132. </template>
  133. </a-setting-list-item>
  134. </a-collapse-panel>
  135. <a-collapse-panel header='{{ i18n "pages.xray.statistics" }}'>
  136. <a-setting-list-item paddings="small">
  137. <template #title>{{ i18n "pages.xray.statsInboundUplink" }}</template>
  138. <template #description>{{ i18n "pages.xray.statsInboundUplinkDesc" }}</template>
  139. <template #control>
  140. <a-switch v-model="statsInboundUplink"></a-switch>
  141. </template>
  142. </a-setting-list-item>
  143. <a-setting-list-item paddings="small">
  144. <template #title>{{ i18n "pages.xray.statsInboundDownlink" }}</template>
  145. <template #description>{{ i18n "pages.xray.statsInboundDownlinkDesc" }}</template>
  146. <template #control>
  147. <a-switch v-model="statsInboundDownlink"></a-switch>
  148. </template>
  149. </a-setting-list-item>
  150. <a-setting-list-item paddings="small">
  151. <template #title>{{ i18n "pages.xray.statsOutboundUplink" }}</template>
  152. <template #description>{{ i18n "pages.xray.statsOutboundUplinkDesc" }}</template>
  153. <template #control>
  154. <a-switch v-model="statsOutboundUplink"></a-switch>
  155. </template>
  156. </a-setting-list-item>
  157. <a-setting-list-item paddings="small">
  158. <template #title>{{ i18n "pages.xray.statsOutboundDownlink" }}</template>
  159. <template #description>{{ i18n "pages.xray.statsOutboundDownlinkDesc" }}</template>
  160. <template #control>
  161. <a-switch v-model="statsOutboundDownlink"></a-switch>
  162. </template>
  163. </a-setting-list-item>
  164. </a-collapse-panel>
  165. <a-collapse-panel header='{{ i18n "pages.xray.logConfigs" }}'>
  166. <a-row :xs="24" :sm="24" :lg="12">
  167. <a-alert type="warning" style="text-align: center;">
  168. <template slot="message">
  169. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  170. {{ i18n "pages.xray.logConfigsDesc" }}
  171. </template>
  172. </a-alert>
  173. </a-row>
  174. <a-setting-list-item paddings="small">
  175. <template #title>{{ i18n "pages.xray.logLevel" }}</template>
  176. <template #description>{{ i18n "pages.xray.logLevelDesc" }}</template>
  177. <template #control>
  178. <a-select v-model="logLevel" :dropdown-class-name="themeSwitcher.currentTheme" style="width: 100%">
  179. <a-select-option v-for="s in log.loglevel" :value="s">[[ s ]]</a-select-option>
  180. </a-select>
  181. </template>
  182. </a-setting-list-item>
  183. <a-setting-list-item paddings="small">
  184. <template #title>{{ i18n "pages.xray.accessLog" }}</template>
  185. <template #description>{{ i18n "pages.xray.accessLogDesc" }}</template>
  186. <template #control>
  187. <a-select v-model="accessLog" :dropdown-class-name="themeSwitcher.currentTheme" style="width: 100%">
  188. <a-select-option value=''>Empty</a-select-option>
  189. <a-select-option v-for="s in log.access" :value="s">[[ s ]]</a-select-option>
  190. </a-select>
  191. </template>
  192. </a-setting-list-item>
  193. <a-setting-list-item paddings="small">
  194. <template #title>{{ i18n "pages.xray.errorLog" }}</template>
  195. <template #description>{{ i18n "pages.xray.errorLogDesc" }}</template>
  196. <template #control>
  197. <a-select v-model="errorLog" :dropdown-class-name="themeSwitcher.currentTheme" style="width: 100%">
  198. <a-select-option value=''>Empty</a-select-option>
  199. <a-select-option v-for="s in log.error" :value="s">[[ s ]]</a-select-option>
  200. </a-select>
  201. </template>
  202. </a-setting-list-item>
  203. <a-setting-list-item paddings="small">
  204. <template #title>{{ i18n "pages.xray.maskAddress" }}</template>
  205. <template #description>{{ i18n "pages.xray.maskAddressDesc" }}</template>
  206. <template #control>
  207. <a-select v-model="maskAddressLog" :dropdown-class-name="themeSwitcher.currentTheme" style="width: 100%">
  208. <a-select-option value=''>Empty</a-select-option>
  209. <a-select-option v-for="s in log.maskAddress" :value="s">[[ s ]]</a-select-option>
  210. </a-select>
  211. </template>
  212. </a-setting-list-item>
  213. <a-setting-list-item paddings="small">
  214. <template #title>{{ i18n "pages.xray.dnsLog"}}</template>
  215. <template #description>{{ i18n "pages.xray.dnsLogDesc"}}</template>
  216. <template #control>
  217. <a-switch v-model="dnslog"></a-switch>
  218. </template>
  219. </a-setting-list-item>
  220. </a-collapse-panel>
  221. <a-collapse-panel header='{{ i18n "pages.xray.blockConfigs"}}'>
  222. <a-row :xs="24" :sm="24" :lg="12">
  223. <a-alert type="warning" style="text-align: center;">
  224. <template slot="message">
  225. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  226. {{ i18n "pages.xray.blockConfigsDesc" }}
  227. </template>
  228. </a-alert>
  229. </a-row>
  230. <a-setting-list-item paddings="small">
  231. <template #title>{{ i18n "pages.xray.Torrent"}}</template>
  232. <template #description>{{ i18n "pages.xray.TorrentDesc"}}</template>
  233. <template #control>
  234. <a-switch v-model="torrentSettings"></a-switch>
  235. </template>
  236. </a-setting-list-item>
  237. <a-setting-list-item paddings="small">
  238. <template #title>{{ i18n "pages.xray.Family"}}</template>
  239. <template #description>{{ i18n "pages.xray.FamilyDesc"}}</template>
  240. <template #control>
  241. <a-switch v-model="familyProtectSettings"></a-switch>
  242. </template>
  243. </a-setting-list-item>
  244. </a-collapse-panel>
  245. <a-collapse-panel header='{{ i18n "pages.xray.basicRouting"}}'>
  246. <a-row :xs="24" :sm="24" :lg="12">
  247. <a-alert type="warning" style="text-align: center;">
  248. <template slot="message">
  249. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  250. {{ i18n "pages.xray.blockConnectionsConfigsDesc" }}
  251. </template>
  252. </a-alert>
  253. </a-row>
  254. <a-setting-list-item paddings="small">
  255. <template #title>{{ i18n "pages.xray.blockips" }}</template>
  256. <template #control>
  257. <a-select mode="tags" v-model="blockedIPs" style="width: 100%" :dropdown-class-name="themeSwitcher.currentTheme">
  258. <a-select-option :value="p.value" :label="p.label" v-for="p in settingsData.IPsOptions">[[ p.label ]]</a-select-option>
  259. </a-select>
  260. </template>
  261. </a-setting-list-item>
  262. <a-setting-list-item paddings="small">
  263. <template #title>{{ i18n "pages.xray.blockdomains" }}</template>
  264. <template #control>
  265. <a-select mode="tags" v-model="blockedDomains" style="width: 100%" :dropdown-class-name="themeSwitcher.currentTheme">
  266. <a-select-option :value="p.value" :label="p.label" v-for="p in settingsData.BlockDomainsOptions">[[ p.label ]]</a-select-option>
  267. </a-select>
  268. </template>
  269. </a-setting-list-item>
  270. <a-row :xs="24" :sm="24" :lg="12">
  271. <a-alert type="warning" style="text-align: center; margin-top: 20px;">
  272. <template slot="message">
  273. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  274. {{ i18n "pages.xray.directConnectionsConfigsDesc" }}
  275. </template>
  276. </a-alert>
  277. </a-row>
  278. <a-setting-list-item paddings="small">
  279. <template #title>{{ i18n "pages.xray.directips" }}</template>
  280. <template #control>
  281. <a-select mode="tags" style="width: 100%" v-model="directIPs" :dropdown-class-name="themeSwitcher.currentTheme">
  282. <a-select-option :value="p.value" :label="p.label" v-for="p in settingsData.IPsOptions">[[ p.label ]]</a-select-option>
  283. </a-select>
  284. </template>
  285. </a-setting-list-item>
  286. <a-setting-list-item paddings="small">
  287. <template #title>{{ i18n "pages.xray.directdomains" }}</template>
  288. <template #control>
  289. <a-select mode="tags" style="width: 100%" v-model="directDomains" :dropdown-class-name="themeSwitcher.currentTheme">
  290. <a-select-option :value="p.value" :label="p.label" v-for="p in settingsData.DomainsOptions">[[ p.label ]]</a-select-option>
  291. </a-select>
  292. </template>
  293. </a-setting-list-item>
  294. <a-row :xs="24" :sm="24" :lg="12">
  295. <a-alert type="warning" style="text-align: center; margin-top: 20px;">
  296. <template slot="message">
  297. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  298. {{ i18n "pages.xray.ipv4RoutingDesc" }}
  299. </template>
  300. </a-alert>
  301. </a-row>
  302. <a-setting-list-item paddings="small">
  303. <template #title>{{ i18n "pages.xray.ipv4Routing" }}</template>
  304. <template #control>
  305. <a-select mode="tags" style="width: 100%" v-model="ipv4Domains" :dropdown-class-name="themeSwitcher.currentTheme">
  306. <a-select-option :value="p.value" :label="p.label" v-for="p in settingsData.ServicesOptions">[[ p.label ]]</a-select-option>
  307. </a-select>
  308. </template>
  309. </a-setting-list-item>
  310. <a-row :xs="24" :sm="24" :lg="12">
  311. <a-alert type="warning" style="text-align: center; margin-top: 20px;">
  312. <template slot="message">
  313. <a-icon type="exclamation-circle" theme="filled" style="color: #FFA031"></a-icon>
  314. {{ i18n "pages.xray.warpRoutingDesc" }}
  315. </template>
  316. </a-alert>
  317. </a-row>
  318. <a-setting-list-item paddings="small">
  319. <template #title>{{ i18n "pages.xray.warpRouting" }}</template>
  320. <template #control>
  321. <template v-if="WarpExist">
  322. <a-select mode="tags" style="width: 100%" v-model="warpDomains" :dropdown-class-name="themeSwitcher.currentTheme">
  323. <a-select-option :value="p.value" :label="p.label" v-for="p in settingsData.ServicesOptions">[[ p.label ]]</a-select-option>
  324. </a-select>
  325. </template>
  326. <template v-else>
  327. <a-button type="primary" icon="cloud" @click="showWarp()">WARP</a-button>
  328. </template>
  329. </template>
  330. </a-setting-list-item>
  331. </a-collapse-panel>
  332. <a-collapse-panel header='{{ i18n "pages.settings.resetDefaultConfig"}}'>
  333. <a-space direction="horizontal" style="padding: 0 20px">
  334. <a-button type="danger" @click="resetXrayConfigToDefault">{{ i18n "pages.settings.resetDefaultConfig" }}</a-button>
  335. </a-space>
  336. </a-collapse-panel>
  337. </a-collapse>
  338. </a-tab-pane>
  339. <a-tab-pane key="tpl-routing" tab='{{ i18n "pages.xray.Routings"}}' style="padding-top: 20px;">
  340. <a-button type="primary" icon="plus" @click="addRule">{{ i18n "pages.xray.rules.add" }}</a-button>
  341. <a-table-sortable :columns="isMobile ? rulesMobileColumns : rulesColumns" bordered
  342. :row-key="r => r.key"
  343. :data-source="routingRuleData"
  344. :scroll="isMobile ? {} : { x: 1000 }"
  345. :pagination="false"
  346. :indent-size="0"
  347. :style="isMobile ? 'padding: 5px 0' : 'margin-top: 10px;'"
  348. v-on:onSort="replaceRule">
  349. <template slot="action" slot-scope="text, rule, index">
  350. <table-sort-trigger :item-index="index"></table-sort-trigger>
  351. <span class="ant-table-row-index"> [[ index+1 ]] </span>
  352. <a-dropdown :trigger="['click']">
  353. <a-icon @click="e => e.preventDefault()" type="more" style="font-size: 16px; text-decoration: bold;"></a-icon>
  354. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  355. <a-menu-item v-if="index>0" @click="replaceRule(index,0)">
  356. <a-icon type="vertical-align-top"></a-icon>
  357. {{ i18n "pages.xray.rules.first"}}
  358. </a-menu-item>
  359. <a-menu-item v-if="index>0" @click="replaceRule(index,index-1)">
  360. <a-icon type="arrow-up"></a-icon>
  361. {{ i18n "pages.xray.rules.up"}}
  362. </a-menu-item>
  363. <a-menu-item v-if="index<routingRuleData.length-1" @click="replaceRule(index,index+1)">
  364. <a-icon type="arrow-down"></a-icon>
  365. {{ i18n "pages.xray.rules.down"}}
  366. </a-menu-item>
  367. <a-menu-item v-if="index<routingRuleData.length-1" @click="replaceRule(index,routingRuleData.length-1)">
  368. <a-icon type="vertical-align-bottom"></a-icon>
  369. {{ i18n "pages.xray.rules.last"}}
  370. </a-menu-item>
  371. <a-menu-item @click="editRule(index)">
  372. <a-icon type="edit"></a-icon>
  373. {{ i18n "edit" }}
  374. </a-menu-item>
  375. <a-menu-item @click="deleteRule(index)">
  376. <span style="color: #FF4D4F">
  377. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  378. </span>
  379. </a-menu-item>
  380. </a-menu>
  381. </a-dropdown>
  382. </template>
  383. <template slot="inbound" slot-scope="text, rule, index">
  384. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  385. <template slot="content">
  386. <p v-if="rule.inboundTag">Inbound Tag: [[ rule.inboundTag ]]</p>
  387. <p v-if="rule.user">User email: [[ rule.user ]]</p>
  388. </template>
  389. [[ [rule.inboundTag,rule.user].join('\n') ]]
  390. </a-popover>
  391. </template>
  392. <template slot="outbound" slot-scope="text, rule, index">
  393. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  394. <template slot="content">
  395. <p v-if="rule.outboundTag">Outbound Tag: [[ rule.outboundTag ]]</p>
  396. </template>
  397. [[ rule.outboundTag ]]
  398. </a-popover>
  399. </template>
  400. <template slot="balancer" slot-scope="text, rule, index">
  401. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  402. <template slot="content">
  403. <p v-if="rule.balancerTag">Balancer Tag: [[ rule.balancerTag ]]</p>
  404. </template>
  405. [[ rule.balancerTag ]]
  406. </a-popover>
  407. </template>
  408. <template slot="info" slot-scope="text, rule, index">
  409. <a-popover placement="bottomRight"
  410. v-if="(rule.source+rule.sourcePort+rule.network+rule.protocol+rule.attrs+rule.ip+rule.domain+rule.port).length>0"
  411. :overlay-class-name="themeSwitcher.currentTheme" trigger="click">
  412. <template slot="content">
  413. <table cellpadding="2" style="max-width: 300px;">
  414. <tr v-if="rule.source">
  415. <td>Source</td>
  416. <td><a-tag color="blue" v-for="r in rule.source.split(',')">[[ r ]]</a-tag></td>
  417. </tr>
  418. <tr v-if="rule.sourcePort">
  419. <td>Source Port</td>
  420. <td><a-tag color="green" v-for="r in rule.sourcePort.split(',')">[[ r ]]</a-tag></td>
  421. </tr>
  422. <tr v-if="rule.network">
  423. <td>Network</td>
  424. <td><a-tag color="blue" v-for="r in rule.network.split(',')">[[ r ]]</a-tag></td>
  425. </tr>
  426. <tr v-if="rule.protocol">
  427. <td>Protocol</td>
  428. <td><a-tag color="green" v-for="r in rule.protocol.split(',')">[[ r ]]</a-tag></td>
  429. </tr>
  430. <tr v-if="rule.attrs">
  431. <td>Attrs</td>
  432. <td><a-tag color="blue" v-for="r in rule.attrs.split(',')">[[ r ]]</a-tag></td>
  433. </tr>
  434. <tr v-if="rule.ip">
  435. <td>IP</td>
  436. <td><a-tag color="green" v-for="r in rule.ip.split(',')">[[ r ]]</a-tag></td>
  437. </tr>
  438. <tr v-if="rule.domain">
  439. <td>Domain</td>
  440. <td><a-tag color="blue" v-for="r in rule.domain.split(',')">[[ r ]]</a-tag></td>
  441. </tr>
  442. <tr v-if="rule.port">
  443. <td>Port</td>
  444. <td><a-tag color="green" v-for="r in rule.port.split(',')">[[ r ]]</a-tag></td>
  445. </tr>
  446. <tr v-if="rule.balancerTag">
  447. <td>Balancer Tag</td>
  448. <td><a-tag color="blue">[[ rule.balancerTag ]]</a-tag></td>
  449. </tr>
  450. </table>
  451. </template>
  452. <a-button shape="round" size="small" style="font-size: 14px; padding: 0 10px;">
  453. <a-icon type="info"></a-icon>
  454. </a-button>
  455. </a-popover>
  456. </template>
  457. </a-table-sortable>
  458. </a-tab-pane>
  459. <a-tab-pane key="tpl-outbound" tab='{{ i18n "pages.xray.Outbounds"}}' style="padding-top: 20px;" force-render="true">
  460. <a-row>
  461. <a-col :xs="12" :sm="12" :lg="12">
  462. <a-button type="primary" icon="plus" @click="addOutbound()" style="margin-bottom: 10px;">
  463. {{ i18n "pages.xray.outbound.addOutbound" }}
  464. </a-button>
  465. <a-button type="primary" icon="cloud" @click="showWarp()" style="margin-bottom: 10px;">WARP</a-button>
  466. </a-col>
  467. <a-col :xs="12" :sm="12" :lg="12" style="text-align: right;">
  468. <a-icon type="sync" :spin="refreshing" @click="refreshOutboundTraffic()" style="margin: 0 5px;"></a-icon>
  469. <a-popconfirm placement="topRight" @confirm="resetOutboundTraffic(-1)"
  470. title='{{ i18n "pages.inbounds.resetTrafficContent"}}'
  471. :overlay-class-name="themeSwitcher.currentTheme"
  472. ok-text='{{ i18n "reset"}}'
  473. cancel-text='{{ i18n "cancel"}}'>
  474. <a-icon slot="icon" type="question-circle-o" :style="themeSwitcher.isDarkTheme ? 'color: #008771' : 'color: #008771'"></a-icon>
  475. <a-icon type="retweet" style="cursor: pointer;"></a-icon>
  476. </a-popconfirm>
  477. </a-col>
  478. </a-row>
  479. <a-table :columns="outboundColumns" bordered
  480. :row-key="r => r.key"
  481. :data-source="outboundData"
  482. :scroll="isMobile ? {} : { x: 800 }"
  483. :pagination="false"
  484. :indent-size="0"
  485. :style="isMobile ? 'padding: 5px 5px' : 'margin-right: 1px;'">
  486. <template slot="action" slot-scope="text, outbound, index">
  487. [[ index+1 ]]
  488. <a-dropdown :trigger="['click']">
  489. <a-icon @click="e => e.preventDefault()" type="more" style="font-size: 16px; text-decoration: bold;"></a-icon>
  490. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  491. <a-menu-item v-if="index>0" @click="setFirstOutbound(index)">
  492. <a-icon type="vertical-align-top"></a-icon>
  493. {{ i18n "pages.xray.rules.first"}}
  494. </a-menu-item>
  495. <a-menu-item @click="editOutbound(index)">
  496. <a-icon type="edit"></a-icon>
  497. {{ i18n "edit" }}
  498. </a-menu-item>
  499. <a-menu-item @click="resetOutboundTraffic(index)">
  500. <span>
  501. <a-icon type="retweet"></a-icon> {{ i18n "pages.inbounds.resetTraffic"}}
  502. </span>
  503. </a-menu-item>
  504. <a-menu-item @click="deleteOutbound(index)">
  505. <span style="color: #FF4D4F">
  506. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  507. </span>
  508. </a-menu-item>
  509. </a-menu>
  510. </a-dropdown>
  511. </template>
  512. <template slot="address" slot-scope="text, outbound, index">
  513. <p style="margin: 0 5px;" v-for="addr in findOutboundAddress(outbound)">[[ addr ]]</p>
  514. </template>
  515. <template slot="protocol" slot-scope="text, outbound, index">
  516. <a-tag style="margin:0;" color="purple">[[ outbound.protocol ]]</a-tag>
  517. <template v-if="[Protocols.VMess, Protocols.VLESS, Protocols.Trojan, Protocols.Shadowsocks].includes(outbound.protocol)">
  518. <a-tag style="margin:0;" color="blue">[[ outbound.streamSettings.network ]]</a-tag>
  519. <a-tag style="margin:0;" v-if="outbound.streamSettings.security=='tls'" color="green">tls</a-tag>
  520. <a-tag style="margin:0;" v-if="outbound.streamSettings.security=='reality'" color="green">reality</a-tag>
  521. </template>
  522. </template>
  523. <template slot="traffic" slot-scope="text, outbound, index">
  524. <a-tag color="green">[[ findOutboundTraffic(outbound) ]]</a-tag>
  525. </template>
  526. </a-table>
  527. </a-tab-pane>
  528. <a-tab-pane key="tpl-reverse" tab='{{ i18n "pages.xray.outbound.reverse"}}' style="padding-top: 20px;" force-render="true">
  529. <a-button type="primary" icon="plus" @click="addReverse()" style="margin-bottom: 10px;">
  530. {{ i18n "pages.xray.outbound.addReverse" }}
  531. </a-button>
  532. <a-table :columns="reverseColumns" bordered v-if="reverseData.length>0"
  533. :row-key="r => r.key"
  534. :data-source="reverseData"
  535. :scroll="isMobile ? {} : { x: 200 }"
  536. :pagination="false"
  537. :indent-size="0"
  538. :style="isMobile ? 'padding: 5px 0' : 'margin-left: 1px;'">
  539. <template slot="action" slot-scope="text, reverse, index">
  540. [[ index+1 ]]
  541. <a-dropdown :trigger="['click']">
  542. <a-icon @click="e => e.preventDefault()" type="more" style="font-size: 16px; text-decoration: bold;"></a-icon>
  543. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  544. <a-menu-item @click="editReverse(index)">
  545. <a-icon type="edit"></a-icon>
  546. {{ i18n "edit" }}
  547. </a-menu-item>
  548. <a-menu-item @click="deleteReverse(index)">
  549. <span style="color: #FF4D4F">
  550. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  551. </span>
  552. </a-menu-item>
  553. </a-menu>
  554. </a-dropdown>
  555. </template>
  556. </a-table>
  557. </a-tab-pane>
  558. <a-tab-pane key="tpl-balancer" tab='{{ i18n "pages.xray.Balancers"}}' style="padding-top: 20px;" force-render="true">
  559. <a-button type="primary" icon="plus" @click="addBalancer()" style="margin-bottom: 10px;">
  560. {{ i18n "pages.xray.balancer.addBalancer"}}
  561. </a-button>
  562. <a-table :columns="balancerColumns" bordered v-if="balancersData.length>0"
  563. :row-key="r => r.key"
  564. :data-source="balancersData"
  565. :scroll="isMobile ? {} : { x: 200 }"
  566. :pagination="false"
  567. :indent-size="0"
  568. :style="isMobile ? 'padding: 5px 0' : 'margin-left: 1px;'">
  569. <template slot="action" slot-scope="text, balancer, index">
  570. [[ index+1 ]]
  571. <a-dropdown :trigger="['click']">
  572. <a-icon @click="e => e.preventDefault()" type="more" style="font-size: 16px; text-decoration: bold;"></a-icon>
  573. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  574. <a-menu-item @click="editBalancer(index)">
  575. <a-icon type="edit"></a-icon>
  576. {{ i18n "edit" }}
  577. </a-menu-item>
  578. <a-menu-item @click="deleteBalancer(index)">
  579. <span style="color: #FF4D4F">
  580. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  581. </span>
  582. </a-menu-item>
  583. </a-menu>
  584. </a-dropdown>
  585. </template>
  586. <template slot="strategy" slot-scope="text, balancer, index">
  587. <a-tag style="margin:0;" v-if="balancer.strategy=='random'" color="purple">Random</a-tag>
  588. <a-tag style="margin:0;" v-if="balancer.strategy=='roundRobin'" color="green">Round Robin</a-tag>
  589. <a-tag style="margin:0;" v-if="balancer.strategy=='leastLoad'" color="green">Least Load</a-tag>
  590. <a-tag style="margin:0;" v-if="balancer.strategy=='leastPing'" color="green">Least Ping</a-tag>
  591. </template>
  592. <template slot="selector" slot-scope="text, balancer, index">
  593. <a-tag class="info-large-tag" style="margin:1;" v-for="sel in balancer.selector">[[ sel ]]</a-tag>
  594. </template>
  595. </a-table>
  596. <a-radio-group
  597. v-if="observatoryEnable || burstObservatoryEnable"
  598. v-model="obsSettings"
  599. @change="changeObsCode"
  600. button-style="solid"
  601. style="margin: 10px 0;"
  602. :size="isMobile ? 'small' : ''">
  603. <a-radio-button value="observatory" v-if="observatoryEnable">Observatory</a-radio-button>
  604. <a-radio-button value="burstObservatory" v-if="burstObservatoryEnable">Burst Observatory</a-radio-button>
  605. </a-radio-group>
  606. <textarea style="position:absolute; left: -800px;" id="obsSetting"></textarea>
  607. </a-tab-pane>
  608. <a-tab-pane key="tpl-dns" tab='DNS' style="padding-top: 20px;" force-render="true">
  609. <a-collapse>
  610. <a-collapse-panel header='{{ i18n "pages.xray.generalConfigs"}}'>
  611. <a-setting-list-item paddings="small">
  612. <template #title>{{ i18n "pages.xray.dns.enable" }}</template>
  613. <template #description>{{ i18n "pages.xray.dns.enableDesc" }}</template>
  614. <template #control>
  615. <a-switch v-model="enableDNS"></a-switch>
  616. </template>
  617. </a-setting-list-item>
  618. <template v-if="enableDNS">
  619. <a-setting-list-item paddings="small">
  620. <template #title>{{ i18n "pages.xray.dns.tag" }}</template>
  621. <template #description>{{ i18n "pages.xray.dns.tagDesc" }}</template>
  622. <template #control>
  623. <a-input type="text" v-model="dnsTag"></a-input>
  624. </template>
  625. </a-setting-list-item>
  626. <a-setting-list-item paddings="small">
  627. <template #title>{{ i18n "pages.xray.dns.clientIp" }}</template>
  628. <template #description>{{ i18n "pages.xray.dns.clientIpDesc" }}</template>
  629. <template #control>
  630. <a-input type="text" v-model="dnsClientIp"></a-input>
  631. </template>
  632. </a-setting-list-item>
  633. <a-setting-list-item paddings="small">
  634. <template #title>{{ i18n "pages.xray.dns.strategy" }}</template>
  635. <template #description>{{ i18n "pages.xray.dns.strategyDesc" }}</template>
  636. <template #control>
  637. <a-select v-model="dnsStrategy" style="width: 100%" :dropdown-class-name="themeSwitcher.currentTheme">
  638. <a-select-option :value="l" :label="l" v-for="l in ['UseIP', 'UseIPv4', 'UseIPv6']">
  639. [[ l ]]
  640. </a-select-option>
  641. </a-select>
  642. </template>
  643. </a-setting-list-item>
  644. <a-setting-list-item paddings="small">
  645. <template #title>{{ i18n "pages.xray.dns.disableCache" }}</template>
  646. <template #description>{{ i18n "pages.xray.dns.disableCacheDesc" }}</template>
  647. <template #control>
  648. <a-switch v-model="dnsDisableCache"></a-switch>
  649. </template>
  650. </a-setting-list-item>
  651. <a-setting-list-item paddings="small">
  652. <template #title>{{ i18n "pages.xray.dns.disableFallback" }}</template>
  653. <template #description>{{ i18n "pages.xray.dns.disableFallbackDesc" }}</template>
  654. <template #control>
  655. <a-switch v-model="dnsDisableFallback"></a-switch>
  656. </template>
  657. </a-setting-list-item>
  658. <a-setting-list-item paddings="small">
  659. <template #title>{{ i18n "pages.xray.dns.disableFallbackIfMatch" }}</template>
  660. <template #description>{{ i18n "pages.xray.dns.disableFallbackIfMatchDesc" }}</template>
  661. <template #control>
  662. <a-switch v-model="dnsDisableFallbackIfMatch"></a-switch>
  663. </template>
  664. </a-setting-list-item>
  665. </template>
  666. </a-collapse-panel>
  667. <template v-if="enableDNS">
  668. <a-collapse-panel header='DNS'>
  669. <a-button type="primary" icon="plus" @click="addDNSServer()" style="margin: 10px;">{{ i18n
  670. "pages.xray.dns.add" }}</a-button>
  671. <a-table :columns="dnsColumns" bordered v-if="dnsServers.length>0" :row-key="r => r.key"
  672. :data-source="dnsServers" :scroll="isMobile ? {} : { x: 200 }" :pagination="false" :indent-size="0"
  673. style="margin: 10px; margin-top: 10px;">
  674. <template slot="action" slot-scope="text,dns,index">
  675. [[ index+1 ]]
  676. <a-dropdown :trigger="['click']">
  677. <a-icon @click="e => e.preventDefault()" type="more"
  678. style="font-size: 16px; text-decoration: bold;"></a-icon>
  679. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  680. <a-menu-item @click="editDNSServer(index)">
  681. <a-icon type="edit"></a-icon>
  682. {{ i18n "edit" }}
  683. </a-menu-item>
  684. <a-menu-item @click="deleteDNSServer(index)">
  685. <span style="color: #FF4D4F">
  686. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  687. </span>
  688. </a-menu-item>
  689. </a-menu>
  690. </a-dropdown>
  691. </template>
  692. <template slot="address" slot-scope="dns,index">
  693. <span v-if="typeof dns == 'object'">[[ dns.address ]]</span>
  694. <span v-else>[[ dns ]]</span>
  695. </template>
  696. <template slot="domain" slot-scope="dns,index">
  697. <span v-if="typeof dns == 'object'">[[ dns.domains.join(",") ]]</span>
  698. </template>
  699. <template slot="expectIPs" slot-scope="dns,index">
  700. <span v-if="typeof dns == 'object'">[[ dns.expectIPs.join(",") ]]</span>
  701. </template>
  702. </a-table>
  703. </a-collapse-panel>
  704. <a-collapse-panel header='FakeDNS'>
  705. <a-button type="primary" icon="plus" @click="addFakedns()" style="margin: 10px;">{{ i18n
  706. "pages.xray.fakedns.add" }}</a-button>
  707. <a-table :columns="fakednsColumns" bordered v-if="fakeDns && fakeDns.length>0" :row-key="r => r.key"
  708. :data-source="fakeDns" :scroll="isMobile ? {} : { x: 200 }" :pagination="false" :indent-size="0"
  709. style="margin: 10px; margin-top: 10px;">
  710. <template slot="action" slot-scope="text,fakedns,index">
  711. [[ index+1 ]]
  712. <a-dropdown :trigger="['click']">
  713. <a-icon @click="e => e.preventDefault()" type="more"
  714. style="font-size: 16px; text-decoration: bold;"></a-icon>
  715. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  716. <a-menu-item @click="editFakedns(index)">
  717. <a-icon type="edit"></a-icon>
  718. {{ i18n "edit" }}
  719. </a-menu-item>
  720. <a-menu-item @click="deleteFakedns(index)">
  721. <span style="color: #FF4D4F">
  722. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  723. </span>
  724. </a-menu-item>
  725. </a-menu>
  726. </a-dropdown>
  727. </template>
  728. </a-table>
  729. </a-collapse-panel>
  730. </template>
  731. </a-collapse>
  732. </a-tab-pane>
  733. <a-tab-pane key="tpl-advanced" tab='{{ i18n "pages.xray.advancedTemplate"}}' style="padding-top: 20px;" force-render="true">
  734. <a-list-item-meta title='{{ i18n "pages.xray.Template"}}' description='{{ i18n "pages.xray.TemplateDesc"}}'></a-list-item-meta>
  735. <a-radio-group v-model="advSettings" @change="changeCode" button-style="solid" style="margin: 10px 0;" :size="isMobile ? 'small' : ''">
  736. <a-radio-button value="xraySetting">{{ i18n "pages.xray.completeTemplate"}}</a-radio-button>
  737. <a-radio-button value="inboundSettings">{{ i18n "pages.xray.Inbounds" }}</a-radio-button>
  738. <a-radio-button value="outboundSettings">{{ i18n "pages.xray.Outbounds" }}</a-radio-button>
  739. <a-radio-button value="routingRuleSettings">{{ i18n "pages.xray.Routings" }}</a-radio-button>
  740. </a-radio-group>
  741. <textarea style="position:absolute; left: -800px;" id="xraySetting"></textarea>
  742. </a-tab-pane>
  743. </a-tabs>
  744. </a-space>
  745. </a-spin>
  746. </a-layout-content>
  747. </a-layout>
  748. </a-layout>
  749. {{template "js" .}}
  750. {{template "component/themeSwitcher" .}}
  751. {{template "component/sortableTable" .}}
  752. {{template "component/setting"}}
  753. {{template "ruleModal"}}
  754. {{template "outModal"}}
  755. {{template "reverseModal"}}
  756. {{template "balancerModal"}}
  757. {{template "dnsModal"}}
  758. {{template "fakednsModal"}}
  759. {{template "warpModal"}}
  760. <script>
  761. const rulesColumns = [
  762. { title: "#", align: 'center', width: 15, scopedSlots: { customRender: 'action' } },
  763. { title: '{{ i18n "pages.xray.rules.source"}}', children: [
  764. { title: 'IP', dataIndex: "source", align: 'center', width: 20, ellipsis: true },
  765. { title: 'Port', dataIndex: 'sourcePort', align: 'center', width: 10, ellipsis: true } ]},
  766. { title: '{{ i18n "pages.inbounds.network"}}', children: [
  767. { title: 'L4', dataIndex: 'network', align: 'center', width: 10 },
  768. { title: 'Protocol', dataIndex: 'protocol', align: 'center', width: 10, ellipsis: true },
  769. { title: 'Attrs', dataIndex: 'attrs', align: 'center', width: 20, ellipsis: true } ]},
  770. { title: '{{ i18n "pages.xray.rules.dest"}}', children: [
  771. { title: 'IP', dataIndex: 'ip', align: 'center', width: 20, ellipsis: true },
  772. { title: 'Domain', dataIndex: 'domain', align: 'center', width: 20, ellipsis: true },
  773. { title: 'Port', dataIndex: 'port', align: 'center', width: 10, ellipsis: true }]},
  774. { title: '{{ i18n "pages.xray.rules.inbound"}}', children: [
  775. { title: 'Inbound Tag', dataIndex: 'inboundTag', align: 'center', width: 15, ellipsis: true },
  776. { title: 'Client Email', dataIndex: 'user', align: 'center', width: 20, ellipsis: true }]},
  777. { title: '{{ i18n "pages.xray.rules.outbound"}}', dataIndex: 'outboundTag', align: 'center', width: 15 },
  778. { title: '{{ i18n "pages.xray.rules.balancer"}}', dataIndex: 'balancerTag', align: 'center', width: 15 },
  779. ];
  780. const rulesMobileColumns = [
  781. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  782. { title: '{{ i18n "pages.xray.rules.inbound"}}', align: 'center', width: 50, ellipsis: true, scopedSlots: { customRender: 'inbound' } },
  783. { title: '{{ i18n "pages.xray.rules.outbound"}}', align: 'center', width: 50, ellipsis: true, scopedSlots: { customRender: 'outbound' } },
  784. { title: '{{ i18n "pages.xray.rules.info"}}', align: 'center', width: 50, ellipsis: true, scopedSlots: { customRender: 'info' } },
  785. ];
  786. const outboundColumns = [
  787. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  788. { title: '{{ i18n "pages.xray.outbound.tag"}}', dataIndex: 'tag', align: 'center', width: 50 },
  789. { title: '{{ i18n "protocol"}}', align: 'center', width: 50, scopedSlots: { customRender: 'protocol' } },
  790. { title: '{{ i18n "pages.xray.outbound.address"}}', align: 'center', width: 50, scopedSlots: { customRender: 'address' } },
  791. { title: '{{ i18n "pages.inbounds.traffic" }}', align: 'center', width: 50, scopedSlots: { customRender: 'traffic' } },
  792. ];
  793. const reverseColumns = [
  794. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  795. { title: '{{ i18n "pages.xray.outbound.type"}}', dataIndex: 'type', align: 'center', width: 50 },
  796. { title: '{{ i18n "pages.xray.outbound.tag"}}', dataIndex: 'tag', align: 'center', width: 50 },
  797. { title: '{{ i18n "pages.xray.outbound.domain"}}', dataIndex: 'domain', align: 'center', width: 50 },
  798. ];
  799. const balancerColumns = [
  800. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  801. { title: '{{ i18n "pages.xray.balancer.tag"}}', dataIndex: 'tag', align: 'center', width: 50 },
  802. { title: '{{ i18n "pages.xray.balancer.balancerStrategy"}}', align: 'center', width: 50, scopedSlots: { customRender: 'strategy' }},
  803. { title: '{{ i18n "pages.xray.balancer.balancerSelectors"}}', align: 'center', width: 100, scopedSlots: { customRender: 'selector' }},
  804. ];
  805. const dnsColumns = [
  806. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  807. { title: '{{ i18n "pages.xray.outbound.address"}}', align: 'center', width: 50, scopedSlots: { customRender: 'address' } },
  808. { title: '{{ i18n "pages.xray.dns.domains"}}', align: 'center', width: 50, scopedSlots: { customRender: 'domain' } },
  809. { title: '{{ i18n "pages.xray.dns.expectIPs"}}', align: 'center', width: 50, scopedSlots: { customRender: 'expectIPs' } },
  810. ];
  811. const fakednsColumns = [
  812. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  813. { title: '{{ i18n "pages.xray.fakedns.ipPool"}}', dataIndex: 'ipPool', align: 'center', width: 50 },
  814. { title: '{{ i18n "pages.xray.fakedns.poolSize"}}', dataIndex: 'poolSize', align: 'center', width: 50 },
  815. ];
  816. const app = new Vue({
  817. delimiters: ['[[', ']]'],
  818. el: '#app',
  819. data: {
  820. siderDrawer,
  821. themeSwitcher,
  822. isDarkTheme: themeSwitcher.isDarkTheme,
  823. spinning: false,
  824. oldXraySetting: '',
  825. xraySetting: '',
  826. inboundTags: [],
  827. outboundsTraffic: [],
  828. saveBtnDisable: true,
  829. refreshing: false,
  830. restartResult: '',
  831. showAlert: false,
  832. isMobile: window.innerWidth <= 768,
  833. advSettings: 'xraySetting',
  834. obsSettings: '',
  835. cm: null,
  836. cmOptions: {
  837. lineNumbers: true,
  838. mode: "application/json",
  839. lint: true,
  840. styleActiveLine: true,
  841. matchBrackets: true,
  842. theme: "xq",
  843. autoCloseTags: true,
  844. lineWrapping: true,
  845. indentUnit: 2,
  846. indentWithTabs: true,
  847. smartIndent: true,
  848. tabSize: 2,
  849. lineWiseCopyCut: false,
  850. foldGutter: true,
  851. gutters: [
  852. "CodeMirror-lint-markers",
  853. "CodeMirror-linenumbers",
  854. "CodeMirror-foldgutter",
  855. ],
  856. },
  857. ipv4Settings: {
  858. tag: "IPv4",
  859. protocol: "freedom",
  860. settings: {
  861. domainStrategy: "UseIPv4"
  862. }
  863. },
  864. directSettings: {
  865. tag: "direct",
  866. protocol: "freedom"
  867. },
  868. routingDomainStrategies: ["AsIs", "IPIfNonMatch", "IPOnDemand"],
  869. log: {
  870. loglevel: ["none", "debug", "info", "warning", "error"],
  871. access: ["none", "./access.log"],
  872. error: ["none", "./error.log"],
  873. dnsLog: false,
  874. maskAddress: ["quarter", "half", "full"],
  875. },
  876. settingsData: {
  877. protocols: {
  878. bittorrent: ["bittorrent"],
  879. },
  880. IPsOptions: [
  881. { label: 'Private IPs', value: 'geoip:private' },
  882. { label: '🇮🇷 Iran', value: 'ext:geoip_IR.dat:ir' },
  883. { label: '🇨🇳 China', value: 'geoip:cn' },
  884. { label: '🇷🇺 Russia', value: 'ext:geoip_RU.dat:ru' },
  885. { label: '🇻🇳 Vietnam', value: 'geoip:vn' },
  886. { label: '🇪🇸 Spain', value: 'geoip:es' },
  887. { label: '🇮🇩 Indonesia', value: 'geoip:id' },
  888. { label: '🇺🇦 Ukraine', value: 'geoip:ua' },
  889. { label: '🇹🇷 Türkiye', value: 'geoip:tr' },
  890. { label: '🇧🇷 Brazil', value: 'geoip:br' },
  891. ],
  892. DomainsOptions: [
  893. { label: '🇮🇷 Iran', value: 'ext:geosite_IR.dat:ir' },
  894. { label: '🇮🇷 .ir', value: 'regexp:.*\\.ir$' },
  895. { label: '🇮🇷 .ایران', value: 'regexp:.*\\.xn--mgba3a4f16a$' },
  896. { label: '🇨🇳 China', value: 'geosite:cn' },
  897. { label: '🇨🇳 .cn', value: 'regexp:.*\\.cn$' },
  898. { label: '🇷🇺 Russia', value: 'ext:geosite_RU.dat:ru-available-only-inside' },
  899. { label: '🇷🇺 .ru', value: 'regexp:.*\\.ru$' },
  900. { label: '🇷🇺 .su', value: 'regexp:.*\\.su$' },
  901. { label: '🇷🇺 .рф', value: 'regexp:.*\\.xn--p1ai$' },
  902. { label: '🇻🇳 .vn', value: 'regexp:.*\\.vn$' },
  903. ],
  904. BlockDomainsOptions: [
  905. { label: 'Ads All', value: 'geosite:category-ads-all' },
  906. { label: 'Ads IR 🇮🇷', value: 'ext:geosite_IR.dat:category-ads-all' },
  907. { label: 'Ads RU 🇷🇺', value: 'ext:geosite_RU.dat:category-ads-all' },
  908. { label: 'Malware 🇮🇷', value: 'ext:geosite_IR.dat:malware' },
  909. { label: 'Phishing 🇮🇷', value: 'ext:geosite_IR.dat:phishing' },
  910. { label: 'Cryptominers 🇮🇷', value: 'ext:geosite_IR.dat:cryptominers' },
  911. { label: '🇮🇷 Iran', value: 'ext:geosite_IR.dat:ir' },
  912. { label: '🇮🇷 .ir', value: 'regexp:.*\\.ir$' },
  913. { label: '🇮🇷 .ایران', value: 'regexp:.*\\.xn--mgba3a4f16a$' },
  914. { label: '🇨🇳 China', value: 'geosite:cn' },
  915. { label: '🇨🇳 .cn', value: 'regexp:.*\\.cn$' },
  916. { label: '🇷🇺 Russia', value: 'ext:geosite_RU.dat:ru-available-only-inside' },
  917. { label: '🇷🇺 .ru', value: 'regexp:.*\\.ru' },
  918. { label: '🇷🇺 .su', value: 'regexp:.*\\.su$' },
  919. { label: '🇷🇺 .рф', value: 'regexp:.*\\.xn--p1ai$' },
  920. { label: '🇻🇳 .vn', value: 'regexp:.*\\.vn$' },
  921. ],
  922. ServicesOptions: [
  923. { label: 'Apple', value: 'geosite:apple' },
  924. { label: 'Meta', value: 'geosite:meta' },
  925. { label: 'Google', value: 'geosite:google' },
  926. { label: 'OpenAI', value: 'geosite:openai' },
  927. { label: 'Spotify', value: 'geosite:spotify' },
  928. { label: 'Netflix', value: 'geosite:netflix' },
  929. { label: 'Reddit', value: 'geosite:reddit' },
  930. { label: 'Speedtest', value: 'geosite:speedtest' },
  931. ],
  932. familyProtectDNS: {
  933. "servers": [
  934. "1.1.1.3", // https://developers.cloudflare.com/1.1.1.1/setup/
  935. "1.0.0.3",
  936. "2606:4700:4700::1113",
  937. "2606:4700:4700::1003"
  938. ],
  939. "queryStrategy": "UseIP"
  940. },
  941. },
  942. defaultObservatory: {
  943. subjectSelector: [],
  944. probeURL: "http://www.google.com/gen_204",
  945. probeInterval: "10m",
  946. enableConcurrency: true
  947. },
  948. defaultBurstObservatory: {
  949. subjectSelector: [],
  950. pingConfig: {
  951. destination: "http://www.google.com/gen_204",
  952. interval: "30m",
  953. connectivity: "http://connectivitycheck.platform.hicloud.com/generate_204",
  954. timeout: "10s",
  955. sampling: 2
  956. }
  957. }
  958. },
  959. methods: {
  960. loading(spinning = true) {
  961. this.spinning = spinning;
  962. },
  963. async getOutboundsTraffic() {
  964. const msg = await HttpUtil.get("/panel/xray/getOutboundsTraffic");
  965. if (msg.success) {
  966. this.outboundsTraffic = msg.obj;
  967. }
  968. },
  969. async getXraySetting() {
  970. this.loading(true);
  971. const msg = await HttpUtil.post("/panel/xray/");
  972. this.loading(false);
  973. if (msg.success) {
  974. result = JSON.parse(msg.obj);
  975. xs = JSON.stringify(result.xraySetting, null, 2);
  976. this.oldXraySetting = xs;
  977. this.xraySetting = xs;
  978. this.inboundTags = result.inboundTags;
  979. this.saveBtnDisable = true;
  980. }
  981. },
  982. async updateXraySetting() {
  983. this.loading(true);
  984. const msg = await HttpUtil.post("/panel/xray/update", {xraySetting : this.xraySetting});
  985. this.loading(false);
  986. if (msg.success) {
  987. await this.getXraySetting();
  988. }
  989. },
  990. async restartXray() {
  991. this.loading(true);
  992. const msg = await HttpUtil.post("server/restartXrayService");
  993. this.loading(false);
  994. if (msg.success) {
  995. await PromiseUtil.sleep(500);
  996. await this.getXrayResult();
  997. }
  998. this.loading(false);
  999. },
  1000. async getXrayResult() {
  1001. const msg = await HttpUtil.get("/panel/xray/getXrayResult");
  1002. if (msg.success) {
  1003. this.restartResult=msg.obj;
  1004. if(msg.obj.length > 1) Vue.prototype.$message.error(msg.obj);
  1005. }
  1006. },
  1007. async fetchUserSecret() {
  1008. this.loading(true);
  1009. const userMessage = await HttpUtil.post("/panel/setting/getUserSecret", this.user);
  1010. if (userMessage.success) {
  1011. this.user = userMessage.obj;
  1012. }
  1013. this.loading(false);
  1014. },
  1015. async updateSecret() {
  1016. this.loading(true);
  1017. const msg = await HttpUtil.post("/panel/setting/updateUserSecret", this.user);
  1018. if (msg.success) {
  1019. this.user = msg.obj;
  1020. window.location.replace(basePath + "logout");
  1021. }
  1022. this.loading(false);
  1023. await this.updateXraySetting();
  1024. },
  1025. generateRandomString(length) {
  1026. var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  1027. let randomString = "";
  1028. for (let i = 0; i < length; i++) {
  1029. randomString += chars[Math.floor(Math.random() * chars.length)];
  1030. }
  1031. return randomString;
  1032. },
  1033. async getNewSecret() {
  1034. this.loading(true);
  1035. await PromiseUtil.sleep(600);
  1036. const newSecret = this.generateRandomString(64);
  1037. this.user.loginSecret = newSecret;
  1038. document.getElementById("token").textContent = newSecret;
  1039. this.loading(false);
  1040. },
  1041. async toggleToken(value) {
  1042. if (value) {
  1043. await this.getNewSecret();
  1044. } else {
  1045. this.user.loginSecret = "";
  1046. }
  1047. },
  1048. async resetXrayConfigToDefault() {
  1049. this.loading(true);
  1050. const msg = await HttpUtil.get("/panel/setting/getDefaultJsonConfig");
  1051. this.loading(false);
  1052. if (msg.success) {
  1053. this.templateSettings = JSON.parse(JSON.stringify(msg.obj, null, 2));
  1054. this.saveBtnDisable = true;
  1055. }
  1056. },
  1057. changePage(pageKey) {
  1058. if(pageKey == 'tpl-advanced') this.changeCode();
  1059. if(pageKey == 'tpl-balancer') this.changeObsCode();
  1060. },
  1061. syncRulesWithOutbound(tag, setting) {
  1062. const newTemplateSettings = this.templateSettings;
  1063. const haveRules = newTemplateSettings.routing.rules.some((r) => r?.outboundTag === tag);
  1064. const outboundIndex = newTemplateSettings.outbounds.findIndex((o) => o.tag === tag);
  1065. if (!haveRules && outboundIndex > 0) {
  1066. newTemplateSettings.outbounds.splice(outboundIndex);
  1067. }
  1068. if (haveRules && outboundIndex < 0) {
  1069. newTemplateSettings.outbounds.push(setting);
  1070. }
  1071. this.templateSettings = newTemplateSettings;
  1072. },
  1073. templateRuleGetter(routeSettings) {
  1074. const { property, outboundTag } = routeSettings;
  1075. let result = [];
  1076. if (this.templateSettings != null) {
  1077. this.templateSettings.routing.rules.forEach(
  1078. (routingRule) => {
  1079. if (
  1080. routingRule.hasOwnProperty(property) &&
  1081. routingRule.hasOwnProperty("outboundTag") &&
  1082. routingRule.outboundTag === outboundTag
  1083. ) {
  1084. result.push(...routingRule[property]);
  1085. }
  1086. }
  1087. );
  1088. }
  1089. return result;
  1090. },
  1091. templateRuleSetter(routeSettings) {
  1092. const { data, property, outboundTag } = routeSettings;
  1093. const oldTemplateSettings = this.templateSettings;
  1094. const newTemplateSettings = oldTemplateSettings;
  1095. currentProperty = this.templateRuleGetter({ outboundTag, property })
  1096. if (currentProperty.length == 0) {
  1097. const propertyRule = {
  1098. type: "field",
  1099. outboundTag,
  1100. [property]: data
  1101. };
  1102. newTemplateSettings.routing.rules.push(propertyRule);
  1103. }
  1104. else {
  1105. const newRules = [];
  1106. insertedOnce = false;
  1107. newTemplateSettings.routing.rules.forEach(
  1108. (routingRule) => {
  1109. if (
  1110. routingRule.hasOwnProperty(property) &&
  1111. routingRule.hasOwnProperty("outboundTag") &&
  1112. routingRule.outboundTag === outboundTag
  1113. ) {
  1114. if (!insertedOnce && data.length > 0) {
  1115. insertedOnce = true;
  1116. routingRule[property] = data;
  1117. newRules.push(routingRule);
  1118. }
  1119. }
  1120. else {
  1121. newRules.push(routingRule);
  1122. }
  1123. }
  1124. );
  1125. newTemplateSettings.routing.rules = newRules;
  1126. }
  1127. this.templateSettings = newTemplateSettings;
  1128. },
  1129. changeCode() {
  1130. if(this.cm != null) {
  1131. this.cm.toTextArea();
  1132. }
  1133. textAreaObj = document.getElementById('xraySetting');
  1134. textAreaObj.value = this[this.advSettings];
  1135. this.cm = CodeMirror.fromTextArea(textAreaObj, this.cmOptions);
  1136. this.cm.on('change',editor => {
  1137. value = editor.getValue();
  1138. if (this.isJsonString(value)) {
  1139. this[this.advSettings] = value;
  1140. }
  1141. });
  1142. },
  1143. changeObsCode() {
  1144. if(this.cm != null) {
  1145. this.cm.toTextArea();
  1146. }
  1147. if (this.obsSettings == ''){
  1148. this.cm = null;
  1149. return
  1150. }
  1151. textAreaObj = document.getElementById('obsSetting');
  1152. textAreaObj.value = this[this.obsSettings];
  1153. this.cm = CodeMirror.fromTextArea(textAreaObj, this.cmOptions);
  1154. this.cm.on('change',editor => {
  1155. value = editor.getValue();
  1156. if(this.isJsonString(value)){
  1157. this[this.obsSettings] = value;
  1158. }
  1159. });
  1160. },
  1161. isJsonString(str) {
  1162. try {
  1163. JSON.parse(str);
  1164. } catch (e) {
  1165. return false;
  1166. }
  1167. return true;
  1168. },
  1169. findOutboundTraffic(o) {
  1170. for (const otraffic of this.outboundsTraffic) {
  1171. if (otraffic.tag == o.tag) {
  1172. return sizeFormat(otraffic.up) + ' / ' + sizeFormat(otraffic.down);
  1173. }
  1174. }
  1175. return sizeFormat(0) + ' / ' + sizeFormat(0);
  1176. },
  1177. findOutboundAddress(o) {
  1178. serverObj = null;
  1179. switch(o.protocol){
  1180. case Protocols.VMess:
  1181. case Protocols.VLESS:
  1182. serverObj = o.settings.vnext;
  1183. break;
  1184. case Protocols.HTTP:
  1185. case Protocols.Socks:
  1186. case Protocols.Shadowsocks:
  1187. case Protocols.Trojan:
  1188. serverObj = o.settings.servers;
  1189. break;
  1190. case Protocols.DNS:
  1191. return [o.settings?.address + ':' + o.settings?.port];
  1192. case Protocols.Wireguard:
  1193. return o.settings.peers.map(peer => peer.endpoint);
  1194. default:
  1195. return null;
  1196. }
  1197. return serverObj ? serverObj.map(obj => obj.address + ':' + obj.port) : null;
  1198. },
  1199. addOutbound(){
  1200. outModal.show({
  1201. title: '{{ i18n "pages.xray.outbound.addOutbound"}}',
  1202. okText: '{{ i18n "pages.xray.outbound.addOutbound" }}',
  1203. confirm: (outbound) => {
  1204. outModal.loading();
  1205. if(outbound.tag.length > 0){
  1206. this.templateSettings.outbounds.push(outbound);
  1207. this.outboundSettings = JSON.stringify(this.templateSettings.outbounds);
  1208. }
  1209. outModal.close();
  1210. },
  1211. isEdit: false,
  1212. tags: this.templateSettings.outbounds.map(obj => obj.tag)
  1213. });
  1214. },
  1215. editOutbound(index){
  1216. outModal.show({
  1217. title: '{{ i18n "pages.xray.outbound.editOutbound"}} ' + (index+1),
  1218. outbound: app.templateSettings.outbounds[index],
  1219. confirm: (outbound) => {
  1220. outModal.loading();
  1221. this.templateSettings.outbounds[index] = outbound;
  1222. this.outboundSettings = JSON.stringify(this.templateSettings.outbounds);
  1223. outModal.close();
  1224. },
  1225. isEdit: true,
  1226. tags: this.outboundData.filter((o) => o.key != index ).map(obj => obj.tag)
  1227. });
  1228. },
  1229. deleteOutbound(index){
  1230. outbounds = this.templateSettings.outbounds;
  1231. outbounds.splice(index,1);
  1232. this.outboundSettings = JSON.stringify(outbounds);
  1233. },
  1234. setFirstOutbound(index){
  1235. outbounds = this.templateSettings.outbounds;
  1236. outbounds.splice(0, 0, outbounds.splice(index, 1)[0]);
  1237. this.outboundSettings = JSON.stringify(outbounds);
  1238. },
  1239. addReverse(){
  1240. reverseModal.show({
  1241. title: '{{ i18n "pages.xray.outbound.addReverse"}}',
  1242. okText: '{{ i18n "pages.xray.outbound.addReverse" }}',
  1243. confirm: (reverse, rules) => {
  1244. reverseModal.loading();
  1245. if(reverse.tag.length > 0){
  1246. newTemplateSettings = this.templateSettings;
  1247. if(newTemplateSettings.reverse == undefined) newTemplateSettings.reverse = {};
  1248. if(newTemplateSettings.reverse[reverse.type+'s'] == undefined) newTemplateSettings.reverse[reverse.type+'s'] = [];
  1249. newTemplateSettings.reverse[reverse.type+'s'].push({ tag: reverse.tag, domain: reverse.domain });
  1250. this.templateSettings = newTemplateSettings;
  1251. // Add related rules
  1252. this.templateSettings.routing.rules.push(...rules);
  1253. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  1254. }
  1255. reverseModal.close();
  1256. },
  1257. isEdit: false
  1258. });
  1259. },
  1260. editReverse(index){
  1261. if(this.reverseData[index].type == "bridge") {
  1262. oldRules = this.templateSettings.routing.rules.filter(r => r.inboundTag && r.inboundTag[0] == this.reverseData[index].tag);
  1263. } else {
  1264. oldRules = this.templateSettings.routing.rules.filter(r => r.outboundTag && r.outboundTag == this.reverseData[index].tag);
  1265. }
  1266. reverseModal.show({
  1267. title: '{{ i18n "pages.xray.outbound.editReverse"}} ' + (index+1),
  1268. reverse: this.reverseData[index],
  1269. rules: oldRules,
  1270. confirm: (reverse, rules) => {
  1271. reverseModal.loading();
  1272. if(reverse.tag.length > 0){
  1273. oldData = this.reverseData[index];
  1274. newTemplateSettings = this.templateSettings;
  1275. oldReverseIndex = newTemplateSettings.reverse[oldData.type+'s'].findIndex(rs => rs.tag == oldData.tag);
  1276. oldRuleIndex0 = oldRules.length>0 ? newTemplateSettings.routing.rules.findIndex(r => JSON.stringify(r) == JSON.stringify(oldRules[0])) : -1;
  1277. oldRuleIndex1 = oldRules.length==2 ? newTemplateSettings.routing.rules.findIndex(r => JSON.stringify(r) == JSON.stringify(oldRules[1])) : -1;
  1278. if(oldData.type == reverse.type){
  1279. newTemplateSettings.reverse[oldData.type + 's'][oldReverseIndex] = { tag: reverse.tag, domain: reverse.domain };
  1280. } else {
  1281. newTemplateSettings.reverse[oldData.type+'s'].splice(oldReverseIndex,1);
  1282. // delete empty object
  1283. if(newTemplateSettings.reverse[oldData.type+'s'].length == 0) Reflect.deleteProperty(newTemplateSettings.reverse, oldData.type+'s');
  1284. // add other type of reverse if it is not exist
  1285. if(!newTemplateSettings.reverse[reverse.type+'s']) newTemplateSettings.reverse[reverse.type+'s'] = [];
  1286. newTemplateSettings.reverse[reverse.type+'s'].push({ tag: reverse.tag, domain: reverse.domain });
  1287. }
  1288. this.templateSettings = newTemplateSettings;
  1289. // Adjust Rules
  1290. newRules = this.templateSettings.routing.rules;
  1291. oldRuleIndex0 != -1 ? newRules[oldRuleIndex0] = rules[0] : newRules.push(rules[0]);
  1292. oldRuleIndex1 != -1 ? newRules[oldRuleIndex1] = rules[1] : newRules.push(rules[1]);
  1293. this.routingRuleSettings = JSON.stringify(newRules);
  1294. }
  1295. reverseModal.close();
  1296. },
  1297. isEdit: true
  1298. });
  1299. },
  1300. deleteReverse(index){
  1301. oldData = this.reverseData[index];
  1302. newTemplateSettings = this.templateSettings;
  1303. reverseTypeObj = newTemplateSettings.reverse[oldData.type+'s'];
  1304. realIndex = reverseTypeObj.findIndex(r => r.tag==oldData.tag && r.domain==oldData.domain);
  1305. newTemplateSettings.reverse[oldData.type+'s'].splice(realIndex,1);
  1306. // delete empty objects
  1307. if(reverseTypeObj.length == 0) Reflect.deleteProperty(newTemplateSettings.reverse, oldData.type+'s');
  1308. if(Object.keys(newTemplateSettings.reverse).length === 0) Reflect.deleteProperty(newTemplateSettings, 'reverse');
  1309. // delete related routing rules
  1310. newRules = newTemplateSettings.routing.rules;
  1311. if(oldData.type == "bridge"){
  1312. newRules = newTemplateSettings.routing.rules.filter(r => !( r.inboundTag && r.inboundTag.length == 1 && r.inboundTag[0] == oldData.tag));
  1313. } else if(oldData.type == "portal"){
  1314. newRules = newTemplateSettings.routing.rules.filter(r => r.outboundTag != oldData.tag);
  1315. }
  1316. newTemplateSettings.routing.rules = newRules;
  1317. this.templateSettings = newTemplateSettings;
  1318. },
  1319. async refreshOutboundTraffic() {
  1320. if (!this.refreshing) {
  1321. this.refreshing = true;
  1322. await this.getOutboundsTraffic();
  1323. data = []
  1324. if (this.templateSettings != null) {
  1325. this.templateSettings.outbounds.forEach((o, index) => {
  1326. data.push({'key': index, ...o});
  1327. });
  1328. }
  1329. this.outboundData = data;
  1330. this.refreshing = false;
  1331. }
  1332. },
  1333. async resetOutboundTraffic(index) {
  1334. let tag = "-alltags-";
  1335. if (index >= 0) {
  1336. tag = this.outboundData[index].tag ? this.outboundData[index].tag : ""
  1337. }
  1338. const msg = await HttpUtil.post("/panel/xray/resetOutboundsTraffic", { tag: tag });
  1339. if (msg.success) {
  1340. await this.refreshOutboundTraffic();
  1341. }
  1342. },
  1343. addBalancer() {
  1344. balancerModal.show({
  1345. title: '{{ i18n "pages.xray.balancer.addBalancer"}}',
  1346. okText: '{{ i18n "pages.xray.balancer.addBalancer"}}',
  1347. balancerTags: this.balancersData.filter((o) => !ObjectUtil.isEmpty(o.tag)).map(obj => obj.tag),
  1348. balancer: {
  1349. tag: '',
  1350. strategy: 'random',
  1351. selector: [],
  1352. fallbackTag: ''
  1353. },
  1354. confirm: (balancer) => {
  1355. balancerModal.loading();
  1356. newTemplateSettings = this.templateSettings;
  1357. if (newTemplateSettings.routing.balancers == undefined) {
  1358. newTemplateSettings.routing.balancers = [];
  1359. }
  1360. let tmpBalancer = {
  1361. 'tag': balancer.tag,
  1362. 'selector': balancer.selector,
  1363. 'fallbackTag': balancer.fallbackTag
  1364. };
  1365. if (balancer.strategy && balancer.strategy != 'random') {
  1366. tmpBalancer.strategy = {
  1367. 'type': balancer.strategy
  1368. };
  1369. }
  1370. newTemplateSettings.routing.balancers.push(tmpBalancer);
  1371. this.templateSettings = newTemplateSettings;
  1372. this.updateObservatorySelectors();
  1373. balancerModal.close();
  1374. this.changeObsCode();
  1375. },
  1376. isEdit: false
  1377. });
  1378. },
  1379. editBalancer(index) {
  1380. const oldTag = this.balancersData[index].tag;
  1381. balancerModal.show({
  1382. title: '{{ i18n "pages.xray.balancer.editBalancer"}}',
  1383. okText: '{{ i18n "sure" }}',
  1384. balancerTags: this.balancersData.filter((o) => !ObjectUtil.isEmpty(o.tag)).map(obj => obj.tag),
  1385. balancer: this.balancersData[index],
  1386. confirm: (balancer) => {
  1387. balancerModal.loading();
  1388. newTemplateSettings = this.templateSettings;
  1389. let tmpBalancer = {
  1390. 'tag': balancer.tag,
  1391. 'selector': balancer.selector,
  1392. 'fallbackTag': balancer.fallbackTag
  1393. };
  1394. // Remove old tag
  1395. if (newTemplateSettings.observatory){
  1396. newTemplateSettings.observatory.subjectSelector = newTemplateSettings.observatory.subjectSelector.filter(s => s != oldTag);
  1397. }
  1398. if (newTemplateSettings.burstObservatory){
  1399. newTemplateSettings.burstObservatory.subjectSelector = newTemplateSettings.burstObservatory.subjectSelector.filter(s => s != oldTag);
  1400. }
  1401. if (balancer.strategy && balancer.strategy != 'random') {
  1402. tmpBalancer.strategy = {
  1403. 'type': balancer.strategy
  1404. };
  1405. }
  1406. newTemplateSettings.routing.balancers[index] = tmpBalancer;
  1407. // change edited tag if used in rule section
  1408. if (oldTag != balancer.tag) {
  1409. newTemplateSettings.routing.rules.forEach((rule) => {
  1410. if (rule.balancerTag && rule.balancerTag == oldTag) {
  1411. rule.balancerTag = balancer.tag;
  1412. }
  1413. });
  1414. }
  1415. this.templateSettings = newTemplateSettings;
  1416. this.updateObservatorySelectors();
  1417. balancerModal.close();
  1418. this.changeObsCode();
  1419. },
  1420. isEdit: true
  1421. });
  1422. },
  1423. updateObservatorySelectors(){
  1424. newTemplateSettings = this.templateSettings;
  1425. const leastPings = this.balancersData.filter((b) => b.strategy == 'leastPing');
  1426. const leastLoads = this.balancersData.filter((b) =>
  1427. b.strategy === 'leastLoad' ||
  1428. b.strategy === 'roundRobin' ||
  1429. b.strategy === 'random'
  1430. );
  1431. if (leastPings.length>0){
  1432. if (!newTemplateSettings.observatory)
  1433. newTemplateSettings.observatory = this.defaultObservatory;
  1434. newTemplateSettings.observatory.subjectSelector = [];
  1435. leastPings.forEach((b) => {
  1436. b.selector.forEach((s) => {
  1437. if (!newTemplateSettings.observatory.subjectSelector.includes(s))
  1438. newTemplateSettings.observatory.subjectSelector.push(s);
  1439. });
  1440. });
  1441. } else {
  1442. delete newTemplateSettings.observatory
  1443. }
  1444. if (leastLoads.length>0){
  1445. if (!newTemplateSettings.burstObservatory)
  1446. newTemplateSettings.burstObservatory = this.defaultBurstObservatory;
  1447. newTemplateSettings.burstObservatory.subjectSelector = [];
  1448. leastLoads.forEach((b) => {
  1449. b.selector.forEach((s) => {
  1450. if (!newTemplateSettings.burstObservatory.subjectSelector.includes(s))
  1451. newTemplateSettings.burstObservatory.subjectSelector.push(s);
  1452. });
  1453. });
  1454. } else {
  1455. delete newTemplateSettings.burstObservatory
  1456. }
  1457. this.templateSettings = newTemplateSettings;
  1458. this.changeObsCode();
  1459. },
  1460. deleteBalancer(index) {
  1461. newTemplateSettings = this.templateSettings;
  1462. // Remove from balancers
  1463. const removedBalancer = this.balancersData.splice(index, 1)[0];
  1464. // Remove from settings
  1465. let realIndex = newTemplateSettings.routing.balancers.findIndex((b) => b.tag === removedBalancer.tag);
  1466. newTemplateSettings.routing.balancers.splice(realIndex, 1);
  1467. // Update balancers property to an empty array if there are no more balancers
  1468. if (newTemplateSettings.routing.balancers.length === 0) {
  1469. delete newTemplateSettings.routing.balancers;
  1470. }
  1471. this.templateSettings = newTemplateSettings;
  1472. this.updateObservatorySelectors();
  1473. this.obsSettings = '';
  1474. this.changeObsCode()
  1475. },
  1476. addDNSServer(){
  1477. dnsModal.show({
  1478. title: '{{ i18n "pages.xray.dns.add" }}',
  1479. confirm: (dnsServer) => {
  1480. dnsServers = this.dnsServers;
  1481. dnsServers.push(dnsServer);
  1482. this.dnsServers = dnsServers;
  1483. dnsModal.close();
  1484. },
  1485. isEdit: false
  1486. });
  1487. },
  1488. editDNSServer(index){
  1489. dnsModal.show({
  1490. title: '{{ i18n "pages.xray.dns.edit" }} #' + (index+1),
  1491. dnsServer: this.dnsServers[index],
  1492. confirm: (dnsServer) => {
  1493. dnsServers = this.dnsServers;
  1494. dnsServers[index] = dnsServer;
  1495. this.dnsServers = dnsServers;
  1496. dnsModal.close();
  1497. },
  1498. isEdit: true
  1499. });
  1500. },
  1501. deleteDNSServer(index){
  1502. newDnsServers = this.dnsServers;
  1503. newDnsServers.splice(index,1);
  1504. this.dnsServers = newDnsServers;
  1505. },
  1506. addFakedns() {
  1507. fakednsModal.show({
  1508. title: '{{ i18n "pages.xray.fakedns.add" }}',
  1509. confirm: (item) => {
  1510. fakeDns = this.fakeDns?? [];
  1511. fakeDns.push(item);
  1512. this.fakeDns = fakeDns;
  1513. fakednsModal.close();
  1514. },
  1515. isEdit: false
  1516. });
  1517. },
  1518. editFakedns(index){
  1519. fakednsModal.show({
  1520. title: '{{ i18n "pages.xray.fakedns.edit" }} #' + (index+1),
  1521. fakeDns: this.fakeDns[index],
  1522. confirm: (item) => {
  1523. fakeDns = this.fakeDns;
  1524. fakeDns[index] = item;
  1525. this.fakeDns = fakeDns;
  1526. fakednsModal.close();
  1527. },
  1528. isEdit: true
  1529. });
  1530. },
  1531. deleteFakedns(index){
  1532. fakeDns = this.fakeDns;
  1533. fakeDns.splice(index,1);
  1534. this.fakeDns = fakeDns;
  1535. },
  1536. addRule(){
  1537. ruleModal.show({
  1538. title: '{{ i18n "pages.xray.rules.add"}}',
  1539. okText: '{{ i18n "pages.xray.rules.add" }}',
  1540. confirm: (rule) => {
  1541. ruleModal.loading();
  1542. if(JSON.stringify(rule).length > 3){
  1543. this.templateSettings.routing.rules.push(rule);
  1544. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  1545. }
  1546. ruleModal.close();
  1547. },
  1548. isEdit: false
  1549. });
  1550. },
  1551. editRule(index){
  1552. ruleModal.show({
  1553. title: '{{ i18n "pages.xray.rules.edit"}} ' + (index+1),
  1554. rule: app.templateSettings.routing.rules[index],
  1555. confirm: (rule) => {
  1556. ruleModal.loading();
  1557. if(JSON.stringify(rule).length > 3){
  1558. this.templateSettings.routing.rules[index] = rule;
  1559. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  1560. }
  1561. ruleModal.close();
  1562. },
  1563. isEdit: true
  1564. });
  1565. },
  1566. replaceRule(old_index,new_index){
  1567. rules = this.templateSettings.routing.rules;
  1568. if (new_index >= rules.length) rules.push(undefined);
  1569. rules.splice(new_index, 0, rules.splice(old_index, 1)[0]);
  1570. this.routingRuleSettings = JSON.stringify(rules);
  1571. },
  1572. deleteRule(index){
  1573. rules = this.templateSettings.routing.rules;
  1574. rules.splice(index,1);
  1575. this.routingRuleSettings = JSON.stringify(rules);
  1576. },
  1577. showWarp(){
  1578. warpModal.show();
  1579. }
  1580. },
  1581. async mounted() {
  1582. if (window.location.protocol !== "https:") {
  1583. this.showAlert = true;
  1584. }
  1585. await this.getXraySetting();
  1586. await this.getXrayResult();
  1587. await this.getOutboundsTraffic();
  1588. while (true) {
  1589. await PromiseUtil.sleep(800);
  1590. this.saveBtnDisable = this.oldXraySetting === this.xraySetting;
  1591. }
  1592. },
  1593. computed: {
  1594. templateSettings: {
  1595. get: function () {
  1596. const parsedSettings = this.xraySetting ? JSON.parse(this.xraySetting) : null;
  1597. return parsedSettings;
  1598. },
  1599. set: function (newValue) {
  1600. if (newValue) {
  1601. this.xraySetting = JSON.stringify(newValue, null, 2);
  1602. }
  1603. },
  1604. },
  1605. inboundSettings: {
  1606. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.inbounds, null, 2) : null; },
  1607. set: function (newValue) {
  1608. newTemplateSettings = this.templateSettings;
  1609. newTemplateSettings.inbounds = JSON.parse(newValue);
  1610. this.templateSettings = newTemplateSettings;
  1611. },
  1612. },
  1613. outboundSettings: {
  1614. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.outbounds, null, 2) : null; },
  1615. set: function (newValue) {
  1616. newTemplateSettings = this.templateSettings;
  1617. newTemplateSettings.outbounds = JSON.parse(newValue);
  1618. this.templateSettings = newTemplateSettings;
  1619. },
  1620. },
  1621. outboundData: {
  1622. get: function () {
  1623. data = []
  1624. if (this.templateSettings != null) {
  1625. this.templateSettings.outbounds.forEach((o, index) => {
  1626. data.push({'key': index, ...o});
  1627. });
  1628. }
  1629. return data;
  1630. },
  1631. },
  1632. reverseData: {
  1633. get: function () {
  1634. data = []
  1635. if (this.templateSettings != null && this.templateSettings.reverse != null) {
  1636. if(this.templateSettings.reverse.bridges) {
  1637. this.templateSettings.reverse.bridges.forEach((o, index) => {
  1638. data.push({'key': index, 'type':'bridge', ...o});
  1639. });
  1640. }
  1641. if(this.templateSettings.reverse.portals){
  1642. this.templateSettings.reverse.portals.forEach((o, index) => {
  1643. data.push({'key': index, 'type':'portal', ...o});
  1644. });
  1645. }
  1646. }
  1647. return data;
  1648. },
  1649. },
  1650. routingRuleSettings: {
  1651. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.routing.rules, null, 2) : null; },
  1652. set: function (newValue) {
  1653. newTemplateSettings = this.templateSettings;
  1654. newTemplateSettings.routing.rules = JSON.parse(newValue);
  1655. this.templateSettings = newTemplateSettings;
  1656. },
  1657. },
  1658. routingRuleData: {
  1659. get: function () {
  1660. data = [];
  1661. if (this.templateSettings != null) {
  1662. this.templateSettings.routing.rules.forEach((r, index) => {
  1663. data.push({'key': index, ...r});
  1664. });
  1665. // Make rules readable
  1666. data.forEach(r => {
  1667. if(r.domain) r.domain = r.domain.join(',')
  1668. if(r.ip) r.ip = r.ip.join(',')
  1669. if(r.source) r.source = r.source.join(',');
  1670. if(r.user) r.user = r.user.join(',')
  1671. if(r.inboundTag) r.inboundTag = r.inboundTag.join(',')
  1672. if(r.protocol) r.protocol = r.protocol.join(',')
  1673. if(r.attrs) r.attrs = JSON.stringify(r.attrs, null, 2)
  1674. });
  1675. }
  1676. return data;
  1677. }
  1678. },
  1679. balancersData: {
  1680. get: function () {
  1681. data = []
  1682. if (this.templateSettings != null && this.templateSettings.routing != null && this.templateSettings.routing.balancers != null) {
  1683. this.templateSettings.routing.balancers.forEach((o, index) => {
  1684. data.push({
  1685. 'key': index,
  1686. 'tag': o.tag ? o.tag : "",
  1687. 'strategy': o.strategy?.type ?? "random",
  1688. 'selector': o.selector ? o.selector : [],
  1689. 'fallbackTag': o.fallbackTag?? '',
  1690. });
  1691. });
  1692. }
  1693. return data;
  1694. }
  1695. },
  1696. observatory: {
  1697. get: function () {
  1698. return this.templateSettings?.observatory ? JSON.stringify(this.templateSettings.observatory, null, 2) : null;
  1699. },
  1700. set: function (newValue) {
  1701. newTemplateSettings = this.templateSettings;
  1702. newTemplateSettings.observatory = JSON.parse(newValue);
  1703. this.templateSettings = newTemplateSettings;
  1704. },
  1705. },
  1706. burstObservatory: {
  1707. get: function () {
  1708. return this.templateSettings?.burstObservatory ? JSON.stringify(this.templateSettings.burstObservatory, null, 2) : null;
  1709. },
  1710. set: function (newValue) {
  1711. newTemplateSettings = this.templateSettings;
  1712. newTemplateSettings.burstObservatory = JSON.parse(newValue);
  1713. this.templateSettings = newTemplateSettings;
  1714. },
  1715. },
  1716. observatoryEnable: function () { return this.templateSettings != null && this.templateSettings.observatory != undefined },
  1717. burstObservatoryEnable: function () { return this.templateSettings != null && this.templateSettings.burstObservatory != undefined },
  1718. freedomStrategy: {
  1719. get: function () {
  1720. if (!this.templateSettings) return "AsIs";
  1721. freedomOutbound = this.templateSettings.outbounds.find((o) => o.protocol === "freedom" && o.tag == "direct");
  1722. if (!freedomOutbound) return "AsIs";
  1723. if (!freedomOutbound.settings || !freedomOutbound.settings.domainStrategy) return "AsIs";
  1724. return freedomOutbound.settings.domainStrategy;
  1725. },
  1726. set: function (newValue) {
  1727. newTemplateSettings = this.templateSettings;
  1728. freedomOutboundIndex = newTemplateSettings.outbounds.findIndex((o) => o.protocol === "freedom" && o.tag == "direct");
  1729. if(freedomOutboundIndex == -1){
  1730. newTemplateSettings.outbounds.push({protocol: "freedom", tag: "direct", settings: { "domainStrategy": newValue }});
  1731. } else if (!newTemplateSettings.outbounds[freedomOutboundIndex].settings) {
  1732. newTemplateSettings.outbounds[freedomOutboundIndex].settings = {"domainStrategy": newValue};
  1733. } else {
  1734. newTemplateSettings.outbounds[freedomOutboundIndex].settings.domainStrategy = newValue;
  1735. }
  1736. this.templateSettings = newTemplateSettings;
  1737. }
  1738. },
  1739. routingStrategy: {
  1740. get: function () {
  1741. if (!this.templateSettings || !this.templateSettings.routing || !this.templateSettings.routing.domainStrategy) return "AsIs";
  1742. return this.templateSettings.routing.domainStrategy;
  1743. },
  1744. set: function (newValue) {
  1745. newTemplateSettings = this.templateSettings;
  1746. newTemplateSettings.routing.domainStrategy = newValue;
  1747. this.templateSettings = newTemplateSettings;
  1748. }
  1749. },
  1750. logLevel: {
  1751. get: function () {
  1752. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.loglevel) return "warning";
  1753. return this.templateSettings.log.loglevel;
  1754. },
  1755. set: function (newValue) {
  1756. newTemplateSettings = this.templateSettings;
  1757. newTemplateSettings.log.loglevel = newValue;
  1758. this.templateSettings = newTemplateSettings;
  1759. }
  1760. },
  1761. accessLog: {
  1762. get: function () {
  1763. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.access) return "";
  1764. return this.templateSettings.log.access;
  1765. },
  1766. set: function (newValue) {
  1767. newTemplateSettings = this.templateSettings;
  1768. newTemplateSettings.log.access = newValue;
  1769. this.templateSettings = newTemplateSettings;
  1770. }
  1771. },
  1772. errorLog: {
  1773. get: function () {
  1774. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.error) return "";
  1775. return this.templateSettings.log.error;
  1776. },
  1777. set: function (newValue) {
  1778. newTemplateSettings = this.templateSettings;
  1779. newTemplateSettings.log.error = newValue;
  1780. this.templateSettings = newTemplateSettings;
  1781. }
  1782. },
  1783. dnslog: {
  1784. get: function () {
  1785. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.dnsLog) return false;
  1786. return this.templateSettings.log.dnsLog;
  1787. },
  1788. set: function (newValue) {
  1789. newTemplateSettings = this.templateSettings;
  1790. newTemplateSettings.log.dnsLog = newValue;
  1791. this.templateSettings = newTemplateSettings;
  1792. }
  1793. },
  1794. statsInboundUplink: {
  1795. get: function () {
  1796. if (!this.templateSettings || !this.templateSettings.policy.system || !this.templateSettings.policy.system.statsInboundUplink) return false;
  1797. return this.templateSettings.policy.system.statsInboundUplink;
  1798. },
  1799. set: function (newValue) {
  1800. newTemplateSettings = this.templateSettings;
  1801. newTemplateSettings.policy.system.statsInboundUplink = newValue;
  1802. this.templateSettings = newTemplateSettings;
  1803. }
  1804. },
  1805. statsInboundDownlink: {
  1806. get: function () {
  1807. if (!this.templateSettings || !this.templateSettings.policy.system || !this.templateSettings.policy.system.statsInboundDownlink) return false;
  1808. return this.templateSettings.policy.system.statsInboundDownlink;
  1809. },
  1810. set: function (newValue) {
  1811. newTemplateSettings = this.templateSettings;
  1812. newTemplateSettings.policy.system.statsInboundDownlink = newValue;
  1813. this.templateSettings = newTemplateSettings;
  1814. }
  1815. },
  1816. statsOutboundUplink: {
  1817. get: function () {
  1818. if (!this.templateSettings || !this.templateSettings.policy.system || !this.templateSettings.policy.system.statsOutboundUplink) return false;
  1819. return this.templateSettings.policy.system.statsOutboundUplink;
  1820. },
  1821. set: function (newValue) {
  1822. newTemplateSettings = this.templateSettings;
  1823. newTemplateSettings.policy.system.statsOutboundUplink = newValue;
  1824. this.templateSettings = newTemplateSettings;
  1825. }
  1826. },
  1827. statsOutboundDownlink: {
  1828. get: function () {
  1829. if (!this.templateSettings || !this.templateSettings.policy.system || !this.templateSettings.policy.system.statsOutboundDownlink) return false;
  1830. return this.templateSettings.policy.system.statsOutboundDownlink;
  1831. },
  1832. set: function (newValue) {
  1833. newTemplateSettings = this.templateSettings;
  1834. newTemplateSettings.policy.system.statsOutboundDownlink = newValue;
  1835. this.templateSettings = newTemplateSettings;
  1836. }
  1837. },
  1838. maskAddressLog: {
  1839. get: function () {
  1840. if (!this.templateSettings || !this.templateSettings.log || !this.templateSettings.log.maskAddress) return "";
  1841. return this.templateSettings.log.maskAddress;
  1842. },
  1843. set: function (newValue) {
  1844. newTemplateSettings = this.templateSettings;
  1845. newTemplateSettings.log.maskAddress = newValue;
  1846. this.templateSettings = newTemplateSettings;
  1847. }
  1848. },
  1849. blockedIPs: {
  1850. get: function () {
  1851. return this.templateRuleGetter({ outboundTag: "blocked", property: "ip" });
  1852. },
  1853. set: function (newValue) {
  1854. this.templateRuleSetter({ outboundTag: "blocked", property: "ip", data: newValue });
  1855. }
  1856. },
  1857. blockedDomains: {
  1858. get: function () {
  1859. return this.templateRuleGetter({ outboundTag: "blocked", property: "domain" });
  1860. },
  1861. set: function (newValue) {
  1862. this.templateRuleSetter({ outboundTag: "blocked", property: "domain", data: newValue });
  1863. }
  1864. },
  1865. blockedProtocols: {
  1866. get: function () {
  1867. return this.templateRuleGetter({ outboundTag: "blocked", property: "protocol" });
  1868. },
  1869. set: function (newValue) {
  1870. this.templateRuleSetter({ outboundTag: "blocked", property: "protocol", data: newValue });
  1871. }
  1872. },
  1873. directIPs: {
  1874. get: function () {
  1875. return this.templateRuleGetter({ outboundTag: "direct", property: "ip" });
  1876. },
  1877. set: function (newValue) {
  1878. this.templateRuleSetter({ outboundTag: "direct", property: "ip", data: newValue });
  1879. this.syncRulesWithOutbound("direct", this.directSettings);
  1880. }
  1881. },
  1882. directDomains: {
  1883. get: function () {
  1884. return this.templateRuleGetter({ outboundTag: "direct", property: "domain" });
  1885. },
  1886. set: function (newValue) {
  1887. this.templateRuleSetter({ outboundTag: "direct", property: "domain", data: newValue });
  1888. this.syncRulesWithOutbound("direct", this.directSettings);
  1889. }
  1890. },
  1891. ipv4Domains: {
  1892. get: function () {
  1893. return this.templateRuleGetter({ outboundTag: "IPv4", property: "domain" });
  1894. },
  1895. set: function (newValue) {
  1896. this.templateRuleSetter({ outboundTag: "IPv4", property: "domain", data: newValue });
  1897. this.syncRulesWithOutbound("IPv4", this.ipv4Settings);
  1898. }
  1899. },
  1900. warpDomains: {
  1901. get: function () {
  1902. return this.templateRuleGetter({ outboundTag: "warp", property: "domain" });
  1903. },
  1904. set: function (newValue) {
  1905. this.templateRuleSetter({ outboundTag: "warp", property: "domain", data: newValue });
  1906. }
  1907. },
  1908. torrentSettings: {
  1909. get: function () {
  1910. return doAllItemsExist(this.settingsData.protocols.bittorrent, this.blockedProtocols);
  1911. },
  1912. set: function (newValue) {
  1913. if (newValue) {
  1914. this.blockedProtocols = [...this.blockedProtocols, ...this.settingsData.protocols.bittorrent];
  1915. } else {
  1916. this.blockedProtocols = this.blockedProtocols.filter(data => !this.settingsData.protocols.bittorrent.includes(data));
  1917. }
  1918. },
  1919. },
  1920. familyProtectSettings: {
  1921. get: function () {
  1922. if (!this.templateSettings || !this.templateSettings.dns || !this.templateSettings.dns.servers) return false;
  1923. return doAllItemsExist(this.settingsData.familyProtectDNS.servers, this.templateSettings.dns.servers);
  1924. },
  1925. set: function (newValue) {
  1926. newTemplateSettings = this.templateSettings;
  1927. if (newValue) {
  1928. newTemplateSettings.dns = this.settingsData.familyProtectDNS;
  1929. } else {
  1930. newTemplateSettings.dns.servers = newTemplateSettings.dns?.servers?.filter(data => !this.settingsData.familyProtectDNS.servers.includes(data))
  1931. }
  1932. this.templateSettings = newTemplateSettings;
  1933. },
  1934. },
  1935. WarpExist: {
  1936. get: function() {
  1937. return this.templateSettings ? this.templateSettings.outbounds.findIndex((o) => o.tag == "warp")>=0 : false;
  1938. },
  1939. },
  1940. enableDNS: {
  1941. get: function () {
  1942. return this.templateSettings ? this.templateSettings.dns != null : false;
  1943. },
  1944. set: function (newValue) {
  1945. newTemplateSettings = this.templateSettings;
  1946. if (newValue) {
  1947. newTemplateSettings.dns = {
  1948. servers: [],
  1949. queryStrategy: "UseIP",
  1950. tag: "dns_inbound"
  1951. };
  1952. newTemplateSettings.fakedns = null;
  1953. } else {
  1954. delete newTemplateSettings.dns;
  1955. delete newTemplateSettings.fakedns;
  1956. }
  1957. this.templateSettings = newTemplateSettings;
  1958. }
  1959. },
  1960. dnsTag: {
  1961. get: function () {
  1962. return this.enableDNS ? this.templateSettings.dns.tag : "";
  1963. },
  1964. set: function (newValue) {
  1965. newTemplateSettings = this.templateSettings;
  1966. newTemplateSettings.dns.tag = newValue;
  1967. this.templateSettings = newTemplateSettings;
  1968. }
  1969. },
  1970. dnsClientIp: {
  1971. get: function () {
  1972. return this.enableDNS ? this.templateSettings.dns.clientIp : null;
  1973. },
  1974. set: function (newValue) {
  1975. newTemplateSettings = this.templateSettings;
  1976. if (newValue) {
  1977. newTemplateSettings.dns.clientIp = newValue;
  1978. } else {
  1979. delete newTemplateSettings.dns.clientIp;
  1980. }
  1981. this.templateSettings = newTemplateSettings;
  1982. }
  1983. },
  1984. dnsDisableCache: {
  1985. get: function () {
  1986. return this.enableDNS ? this.templateSettings.dns.disableCache : false;
  1987. },
  1988. set: function (newValue) {
  1989. newTemplateSettings = this.templateSettings;
  1990. if (newValue) {
  1991. newTemplateSettings.dns.disableCache = newValue;
  1992. } else {
  1993. delete newTemplateSettings.dns.disableCache
  1994. }
  1995. this.templateSettings = newTemplateSettings;
  1996. }
  1997. },
  1998. dnsDisableFallback: {
  1999. get: function () {
  2000. return this.enableDNS ? this.templateSettings.dns.disableFallback : false;
  2001. },
  2002. set: function (newValue) {
  2003. newTemplateSettings = this.templateSettings;
  2004. if (newValue) {
  2005. newTemplateSettings.dns.disableFallback = newValue;
  2006. } else {
  2007. delete newTemplateSettings.dns.disableFallback
  2008. }
  2009. this.templateSettings = newTemplateSettings;
  2010. }
  2011. },
  2012. dnsDisableFallbackIfMatch: {
  2013. get: function () {
  2014. return this.enableDNS ? this.templateSettings.dns.disableFallbackIfMatch : false;
  2015. },
  2016. set: function (newValue) {
  2017. newTemplateSettings = this.templateSettings;
  2018. if (newValue) {
  2019. newTemplateSettings.dns.disableFallbackIfMatch = newValue;
  2020. } else {
  2021. delete newTemplateSettings.dns.disableFallbackIfMatch
  2022. }
  2023. this.templateSettings = newTemplateSettings;
  2024. }
  2025. },
  2026. dnsStrategy: {
  2027. get: function () {
  2028. return this.enableDNS ? this.templateSettings.dns.queryStrategy : null;
  2029. },
  2030. set: function (newValue) {
  2031. newTemplateSettings = this.templateSettings;
  2032. newTemplateSettings.dns.queryStrategy = newValue;
  2033. this.templateSettings = newTemplateSettings;
  2034. }
  2035. },
  2036. dnsServers: {
  2037. get: function () { return this.enableDNS ? this.templateSettings.dns.servers : []; },
  2038. set: function (newValue) {
  2039. newTemplateSettings = this.templateSettings;
  2040. newTemplateSettings.dns.servers = newValue;
  2041. this.templateSettings = newTemplateSettings;
  2042. }
  2043. },
  2044. fakeDns: {
  2045. get: function () { return this.templateSettings && this.templateSettings.fakedns ? this.templateSettings.fakedns : []; },
  2046. set: function (newValue) {
  2047. newTemplateSettings = this.templateSettings;
  2048. if (this.enableDNS) {
  2049. newTemplateSettings.fakedns = newValue.length > 0 ? newValue : null;
  2050. } else {
  2051. delete newTemplateSettings.fakedns;
  2052. }
  2053. this.templateSettings = newTemplateSettings;
  2054. }
  2055. }
  2056. },
  2057. });
  2058. </script>
  2059. </body>
  2060. </html>