xray.html 108 KB

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