xray.html 97 KB

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