xray.html 100 KB

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