xray.html 107 KB

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