xray.html 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364
  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">
  7. <link rel="stylesheet" href="{{ .base_path }}assets/codemirror/lint/lint.css">
  8. <script src="{{ .base_path }}assets/js/model/outbound.js"></script>
  9. <script src="{{ .base_path }}assets/codemirror/codemirror.js"></script>
  10. <script src="{{ .base_path }}assets/codemirror/javascript.js"></script>
  11. <script src="{{ .base_path }}assets/codemirror/jshint.js"></script>
  12. <script src="{{ .base_path }}assets/codemirror/jsonlint.js"></script>
  13. <script src="{{ .base_path }}assets/codemirror/lint/lint.js"></script>
  14. <script src="{{ .base_path }}assets/codemirror/lint/javascript-lint.js"></script>
  15. <script src="{{ .base_path }}assets/codemirror/hint/javascript-hint.js"></script>
  16. <script src="{{ .base_path }}assets/codemirror/fold/foldcode.js"></script>
  17. <script src="{{ .base_path }}assets/codemirror/fold/foldgutter.js"></script>
  18. <script src="{{ .base_path }}assets/codemirror/fold/brace-fold.js"></script>
  19. <style>
  20. @media (min-width: 769px) {
  21. .ant-layout-content {
  22. margin: 24px 16px;
  23. }
  24. }
  25. @media (max-width: 768px) {
  26. .ant-tabs-nav .ant-tabs-tab {
  27. margin: 0;
  28. padding: 12px .5rem;
  29. }
  30. }
  31. .ant-tabs-bar {
  32. margin: 0;
  33. }
  34. .ant-list-item {
  35. display: block;
  36. }
  37. .collapse-title {
  38. color: inherit;
  39. font-weight: bold;
  40. font-size: 18px;
  41. padding: 10px 20px;
  42. border-bottom: 2px solid;
  43. }
  44. .collapse-title > i {
  45. color: inherit;
  46. font-size: 24px;
  47. }
  48. </style>
  49. <body>
  50. <a-layout id="app" v-cloak :class="themeSwitcher.currentTheme">
  51. {{ template "commonSider" . }}
  52. <a-layout id="content-layout">
  53. <a-layout-content>
  54. <a-spin :spinning="spinning" :delay="500" tip='{{ i18n "loading"}}'>
  55. <a-space direction="vertical">
  56. <a-card hoverable style="margin-bottom: .5rem;">
  57. <a-row>
  58. <a-col :xs="24" :sm="8" style="padding: 4px;">
  59. <a-space direction="horizontal">
  60. <a-button type="primary" :disabled="saveBtnDisable" @click="updateXraySetting">{{ i18n "pages.xray.save" }}</a-button>
  61. <a-button type="danger" :disabled="!saveBtnDisable" @click="restartXray">{{ i18n "pages.xray.restart" }}</a-button>
  62. </a-space>
  63. </a-col>
  64. <a-col :xs="24" :sm="16">
  65. <a-alert type="warning" style="float: right; width: fit-content"
  66. message='{{ i18n "pages.settings.infoDesc" }}'
  67. show-icon
  68. >
  69. </a-col>
  70. </a-row>
  71. </a-card>
  72. <a-tabs class="ant-card-dark-box-nohover" default-active-key="tpl-1"
  73. @change="(activeKey) => { if(activeKey == 'tpl-4') this.changeCode(); }"
  74. :class="themeSwitcher.currentTheme">
  75. <a-tab-pane key="tpl-1" tab='{{ i18n "pages.xray.basicTemplate"}}'>
  76. <a-space direction="horizontal" style="padding: 20px 20px">
  77. <a-button type="primary" @click="resetXrayConfigToDefault">{{ i18n "pages.settings.resetDefaultConfig" }}</a-button>
  78. </a-space>
  79. <a-collapse>
  80. <a-collapse-panel header='{{ i18n "pages.xray.generalConfigs"}}'>
  81. <a-row :xs="24" :sm="24" :lg="12">
  82. <h2 class="collapse-title">
  83. <a-icon type="warning"></a-icon>
  84. {{ i18n "pages.xray.generalConfigsDesc" }}
  85. </h2>
  86. </a-row>
  87. <a-list-item>
  88. <a-row style="padding: 20px">
  89. <a-col :lg="24" :xl="12">
  90. <a-list-item-meta
  91. title='{{ i18n "pages.xray.xrayConfigFreedomStrategy" }}'
  92. description='{{ i18n "pages.xray.xrayConfigFreedomStrategyDesc" }}'/>
  93. </a-col>
  94. <a-col :lg="24" :xl="12">
  95. <template>
  96. <a-select
  97. v-model="freedomStrategy"
  98. :dropdown-class-name="themeSwitcher.currentTheme"
  99. style="width: 100%">
  100. <a-select-option v-for="s in outboundDomainStrategies" :value="s">[[ s ]]</a-select-option>
  101. </a-select>
  102. </template>
  103. </a-col>
  104. </a-row>
  105. </a-list-item>
  106. <a-row style="padding: 20px">
  107. <a-col :lg="24" :xl="12">
  108. <a-list-item-meta
  109. title='{{ i18n "pages.xray.xrayConfigRoutingStrategy" }}'
  110. description='{{ i18n "pages.xray.xrayConfigRoutingStrategyDesc" }}'/>
  111. </a-col>
  112. <a-col :lg="24" :xl="12">
  113. <template>
  114. <a-select
  115. v-model="routingStrategy"
  116. :dropdown-class-name="themeSwitcher.currentTheme"
  117. style="width: 100%">
  118. <a-select-option v-for="s in routingDomainStrategies" :value="s">[[ s ]]</a-select-option>
  119. </a-select>
  120. </template>
  121. </a-col>
  122. </a-row>
  123. </a-list-item>
  124. </a-collapse-panel>
  125. <a-collapse-panel header='{{ i18n "pages.xray.blockConfigs"}}'>
  126. <a-row :xs="24" :sm="24" :lg="12">
  127. <h2 class="collapse-title">
  128. <a-icon type="warning"></a-icon>
  129. {{ i18n "pages.xray.blockConfigsDesc" }}
  130. </h2>
  131. </a-row>
  132. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigTorrent"}}' desc='{{ i18n "pages.xray.xrayConfigTorrentDesc"}}' v-model="torrentSettings"></setting-list-item>
  133. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigPrivateIp"}}' desc='{{ i18n "pages.xray.xrayConfigPrivateIpDesc"}}' v-model="privateIpSettings"></setting-list-item>
  134. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigAds"}}' desc='{{ i18n "pages.xray.xrayConfigAdsDesc"}}' v-model="AdsSettings"></setting-list-item>
  135. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigFamily"}}' desc='{{ i18n "pages.xray.xrayConfigFamilyDesc"}}' v-model="familyProtectSettings"></setting-list-item>
  136. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigSpeedtest"}}' desc='{{ i18n "pages.xray.xrayConfigSpeedtestDesc"}}' v-model="SpeedTestSettings"></setting-list-item>
  137. </a-collapse-panel>
  138. <a-collapse-panel header='{{ i18n "pages.xray.blockCountryConfigs"}}'>
  139. <a-row :xs="24" :sm="24" :lg="12">
  140. <h2 class="collapse-title">
  141. <a-icon type="warning"></a-icon>
  142. {{ i18n "pages.xray.blockCountryConfigsDesc" }}
  143. </h2>
  144. </a-row>
  145. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigIRIp"}}' desc='{{ i18n "pages.xray.xrayConfigIRIpDesc"}}' v-model="IRIpSettings"></setting-list-item>
  146. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigIRDomain"}}' desc='{{ i18n "pages.xray.xrayConfigIRDomainDesc"}}' v-model="IRDomainSettings"></setting-list-item>
  147. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigChinaIp"}}' desc='{{ i18n "pages.xray.xrayConfigChinaIpDesc"}}' v-model="ChinaIpSettings"></setting-list-item>
  148. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigChinaDomain"}}' desc='{{ i18n "pages.xray.xrayConfigChinaDomainDesc"}}' v-model="ChinaDomainSettings"></setting-list-item>
  149. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigRussiaIp"}}' desc='{{ i18n "pages.xray.xrayConfigRussiaIpDesc"}}' v-model="RussiaIpSettings"></setting-list-item>
  150. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigRussiaDomain"}}' desc='{{ i18n "pages.xray.xrayConfigRussiaDomainDesc"}}' v-model="RussiaDomainSettings"></setting-list-item>
  151. </a-collapse-panel>
  152. <a-collapse-panel header='{{ i18n "pages.xray.directCountryConfigs"}}'>
  153. <a-row :xs="24" :sm="24" :lg="12">
  154. <h2 class="collapse-title">
  155. <a-icon type="warning"></a-icon>
  156. {{ i18n "pages.xray.directCountryConfigsDesc" }}
  157. </h2>
  158. </a-row>
  159. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigDirectIRIp"}}' desc='{{ i18n "pages.xray.xrayConfigDirectIRIpDesc"}}' v-model="IRIpDirectSettings"></setting-list-item>
  160. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigDirectIRDomain"}}' desc='{{ i18n "pages.xray.xrayConfigDirectIRDomainDesc"}}' v-model="IRDomainDirectSettings"></setting-list-item>
  161. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigDirectChinaIp"}}' desc='{{ i18n "pages.xray.xrayConfigDirectChinaIpDesc"}}' v-model="ChinaIpDirectSettings"></setting-list-item>
  162. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigDirectChinaDomain"}}' desc='{{ i18n "pages.xray.xrayConfigDirectChinaDomainDesc"}}' v-model="ChinaDomainDirectSettings"></setting-list-item>
  163. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigDirectRussiaIp"}}' desc='{{ i18n "pages.xray.xrayConfigDirectRussiaIpDesc"}}' v-model="RussiaIpDirectSettings"></setting-list-item>
  164. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigDirectRussiaDomain"}}' desc='{{ i18n "pages.xray.xrayConfigDirectRussiaDomainDesc"}}' v-model="RussiaDomainDirectSettings"></setting-list-item>
  165. </a-collapse-panel>
  166. <a-collapse-panel header='{{ i18n "pages.xray.ipv4Configs"}}'>
  167. <a-row :xs="24" :sm="24" :lg="12">
  168. <h2 class="collapse-title">
  169. <a-icon type="warning"></a-icon>
  170. {{ i18n "pages.xray.ipv4ConfigsDesc" }}
  171. </h2>
  172. </a-row>
  173. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigGoogleIPv4"}}' desc='{{ i18n "pages.xray.xrayConfigGoogleIPv4Desc"}}' v-model="GoogleIPv4Settings"></setting-list-item>
  174. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigNetflixIPv4"}}' desc='{{ i18n "pages.xray.xrayConfigNetflixIPv4Desc"}}' v-model="NetflixIPv4Settings"></setting-list-item>
  175. </a-collapse-panel>
  176. <a-collapse-panel header='{{ i18n "pages.xray.warpConfigs"}}'>
  177. <a-row :xs="24" :sm="24" :lg="12">
  178. <h2 class="collapse-title">
  179. <a-icon type="warning"></a-icon>
  180. {{ i18n "pages.xray.warpConfigsDesc" }}
  181. </h2>
  182. </a-row>
  183. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigGoogleWARP"}}' desc='{{ i18n "pages.xray.xrayConfigGoogleWARPDesc"}}' v-model="GoogleWARPSettings"></setting-list-item>
  184. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigOpenAIWARP"}}' desc='{{ i18n "pages.xray.xrayConfigOpenAIWARPDesc"}}' v-model="OpenAIWARPSettings"></setting-list-item>
  185. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigNetflixWARP"}}' desc='{{ i18n "pages.xray.xrayConfigNetflixWARPDesc"}}' v-model="NetflixWARPSettings"></setting-list-item>
  186. <setting-list-item type="switch" title='{{ i18n "pages.xray.xrayConfigSpotifyWARP"}}' desc='{{ i18n "pages.xray.xrayConfigSpotifyWARPDesc"}}' v-model="SpotifyWARPSettings"></setting-list-item>
  187. </a-collapse-panel>
  188. </a-collapse>
  189. </a-tab-pane>
  190. <a-tab-pane key="tpl-2" tab='{{ i18n "pages.xray.Routings"}}' style="padding-top: 20px;">
  191. <a-alert type="warning" style="margin-bottom: 10px; width: fit-content"
  192. message='{{ i18n "pages.xray.RoutingsDesc"}}' show-icon></a-alert>
  193. <a-button type="primary" icon="plus" @click="addRule">{{ i18n "pages.xray.rules.add" }}</a-button>
  194. <a-table :columns="isMobile ? rulesMobileColumns : rulesColumns" bordered
  195. :row-key="r => r.key"
  196. :data-source="routingRuleData"
  197. :scroll="isMobile ? {} : { x: 1000 }"
  198. :pagination="false"
  199. :indent-size="0"
  200. :style="isMobile ? 'padding: 5px 0' : 'margin-top: 10px;'">
  201. <template slot="action" slot-scope="text, rule, index">
  202. [[ index+1 ]]
  203. <a-dropdown :trigger="['click']">
  204. <a-icon @click="e => e.preventDefault()" type="more" style="font-size: 16px; text-decoration: bold;"></a-icon>
  205. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  206. <a-menu-item v-if="index>0" @click="replaceRule(index,0)">
  207. <a-icon type="vertical-align-top"></a-icon>
  208. {{ i18n "pages.xray.rules.first"}}
  209. </a-menu-item>
  210. <a-menu-item v-if="index>0" @click="replaceRule(index,index-1)">
  211. <a-icon type="arrow-up"></a-icon>
  212. {{ i18n "pages.xray.rules.up"}}
  213. </a-menu-item>
  214. <a-menu-item v-if="index<routingRuleData.length-1" @click="replaceRule(index,index+1)">
  215. <a-icon type="arrow-down"></a-icon>
  216. {{ i18n "pages.xray.rules.down"}}
  217. </a-menu-item>
  218. <a-menu-item v-if="index<routingRuleData.length-1" @click="replaceRule(index,routingRuleData.length-1)">
  219. <a-icon type="vertical-align-bottom"></a-icon>
  220. {{ i18n "pages.xray.rules.last"}}
  221. </a-menu-item>
  222. <a-menu-item @click="editRule(index)">
  223. <a-icon type="edit"></a-icon>
  224. {{ i18n "edit" }}
  225. </a-menu-item>
  226. <a-menu-item @click="deleteRule(index)">
  227. <span style="color: #FF4D4F">
  228. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  229. </span>
  230. </a-menu-item>
  231. </a-menu>
  232. </a-dropdown>
  233. </template>
  234. <template slot="inbound" slot-scope="text, rule, index">
  235. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  236. <template slot="content">
  237. <p v-if="rule.inboundTag">Inbound Tag: [[ rule.inboundTag ]]</p>
  238. <p v-if="rule.user">User email: [[ rule.user ]]</p>
  239. </template>
  240. [[ [rule.inboundTag,rule.user].join('\n') ]]
  241. </a-popover>
  242. </template>
  243. <template slot="outbound" slot-scope="text, rule, index">
  244. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  245. <template slot="content">
  246. <p v-if="rule.outboundTag">Outbound Tag: [[ rule.outboundTag ]]</p>
  247. </template>
  248. [[ rule.outboundTag ]]
  249. </a-popover>
  250. </template>
  251. <template slot="info" slot-scope="text, rule, index">
  252. <a-popover placement="bottomRight"
  253. v-if="(rule.source+rule.sourcePort+rule.network+rule.protocol+rule.attrs+rule.ip+rule.domain+rule.port).length>0"
  254. :overlay-class-name="themeSwitcher.currentTheme" trigger="click">
  255. <template slot="content">
  256. <table cellpadding="2" style="max-width: 300px;">
  257. <tr v-if="rule.source">
  258. <td>Source</td>
  259. <td><a-tag color="blue" v-for="r in rule.source.split(',')">[[ r ]]</a-tag></td>
  260. </tr>
  261. <tr v-if="rule.sourcePort">
  262. <td>Source Port</td>
  263. <td><a-tag color="green" v-for="r in rule.sourcePort.split(',')">[[ r ]]</a-tag></td>
  264. </tr>
  265. <tr v-if="rule.network">
  266. <td>Network</td>
  267. <td><a-tag color="blue" v-for="r in rule.network.split(',')">[[ r ]]</a-tag></td>
  268. </tr>
  269. <tr v-if="rule.protocol">
  270. <td>Protocol</td>
  271. <td><a-tag color="green" v-for="r in rule.protocol.split(',')">[[ r ]]</a-tag></td>
  272. </tr>
  273. <tr v-if="rule.attrs">
  274. <td>Attrs</td>
  275. <td><a-tag color="blue" v-for="r in rule.attrs.split(',')">[[ r ]]</a-tag></td>
  276. </tr>
  277. <tr v-if="rule.ip">
  278. <td>IP</td>
  279. <td><a-tag color="green" v-for="r in rule.ip.split(',')">[[ r ]]</a-tag></td>
  280. </tr>
  281. <tr v-if="rule.domain">
  282. <td>Domain</td>
  283. <td><a-tag color="blue" v-for="r in rule.domain.split(',')">[[ r ]]</a-tag></td>
  284. </tr>
  285. <tr v-if="rule.port">
  286. <td>Port</td>
  287. <td><a-tag color="green" v-for="r in rule.port.split(',')">[[ r ]]</a-tag></td>
  288. </tr>
  289. </table>
  290. </template>
  291. <a-button shape="round" size="small" style="font-size: 14px; padding: 0 10px;">
  292. <a-icon type="info"></a-icon>
  293. </a-button>
  294. </a-popover>
  295. </template>
  296. </a-table>
  297. </a-tab-pane>
  298. <a-tab-pane key="tpl-3" tab='{{ i18n "pages.xray.Outbounds"}}' style="padding-top: 20px;" force-render="true">
  299. <a-button type="primary" icon="plus" @click="addOutbound()">{{ i18n "pages.xray.outbound.addOutbound" }}</a-button>
  300. <a-button type="primary" icon="plus" @click="addReverse()">{{ i18n "pages.xray.outbound.addReverse" }}</a-button>
  301. <a-row>
  302. <a-col :sm="24" :md="12">
  303. <p style="margin: 10px;">{{ i18n "pages.xray.Outbounds"}}</p>
  304. <a-table :columns="outboundColumns" bordered
  305. :row-key="r => r.key"
  306. :data-source="outboundData"
  307. :scroll="isMobile ? {} : { x: 200 }"
  308. :pagination="false"
  309. :indent-size="0"
  310. :style="isMobile ? 'padding: 5px 5px' : 'margin-right: 1px;'">
  311. <template slot="action" slot-scope="text, outbound, index">
  312. [[ index+1 ]]
  313. <a-dropdown :trigger="['click']">
  314. <a-icon @click="e => e.preventDefault()" type="more" style="font-size: 16px; text-decoration: bold;"></a-icon>
  315. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  316. <a-menu-item @click="editOutbound(index)">
  317. <a-icon type="edit"></a-icon>
  318. {{ i18n "edit" }}
  319. </a-menu-item>
  320. <a-menu-item @click="deleteOutbound(index)">
  321. <span style="color: #FF4D4F">
  322. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  323. </span>
  324. </a-menu-item>
  325. </a-menu>
  326. </a-dropdown>
  327. </template>
  328. <template slot="address" slot-scope="text, outbound, index">
  329. <p style="margin: 0 5px;" v-for="addr in findOutboundAddress(outbound)">[[ addr ]]</p>
  330. </template>
  331. <template slot="protocol" slot-scope="text, outbound, index">
  332. <a-tag style="margin:0;" color="purple">[[ outbound.protocol ]]</a-tag>
  333. <template v-if="[Protocols.VMess, Protocols.VLESS, Protocols.Trojan, Protocols.Shadowsocks].includes(outbound.protocol)">
  334. <a-tag style="margin:0;" color="blue">[[ outbound.streamSettings.network ]]</a-tag>
  335. <a-tag style="margin:0;" v-if="outbound.streamSettings.security=='tls'" color="green">tls</a-tag>
  336. <a-tag style="margin:0;" v-if="outbound.streamSettings.security=='reality'" color="green">reality</a-tag>
  337. </template>
  338. </template>
  339. </a-table>
  340. </a-col>
  341. <a-col :sm="24" :md="12" v-if="reverseData.length>0">
  342. <p style="margin: 10px;">{{ i18n "pages.xray.outbound.reverse"}}</p>
  343. <a-table :columns="reverseColumns" bordered
  344. :row-key="r => r.key"
  345. :data-source="reverseData"
  346. :scroll="isMobile ? {} : { x: 200 }"
  347. :pagination="false"
  348. :indent-size="0"
  349. :style="isMobile ? 'padding: 5px 0' : 'margin-left: 1px;'">
  350. <template slot="action" slot-scope="text, reverse, index">
  351. [[ index+1 ]]
  352. <a-dropdown :trigger="['click']">
  353. <a-icon @click="e => e.preventDefault()" type="more" style="font-size: 16px; text-decoration: bold;"></a-icon>
  354. <a-menu slot="overlay" :theme="themeSwitcher.currentTheme">
  355. <a-menu-item @click="editReverse(index)">
  356. <a-icon type="edit"></a-icon>
  357. {{ i18n "edit" }}
  358. </a-menu-item>
  359. <a-menu-item @click="deleteReverse(index)">
  360. <span style="color: #FF4D4F">
  361. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  362. </span>
  363. </a-menu-item>
  364. </a-menu>
  365. </a-dropdown>
  366. </template>
  367. </a-table>
  368. </a-col>
  369. </a-row>
  370. </a-tab-pane>
  371. <a-tab-pane key="tpl-4" tab='{{ i18n "pages.xray.advancedTemplate"}}' style="padding-top: 20px;" force-render="true">
  372. <a-list-item-meta title='{{ i18n "pages.xray.Template"}}' description='{{ i18n "pages.xray.TemplateDesc"}}'></a-list-item-meta>
  373. <a-radio-group v-model="advSettings" @change="changeCode" button-style="solid" style="margin: 10px 0;" :size="isMobile ? 'small' : ''">
  374. <a-radio-button value="xraySetting">{{ i18n "pages.xray.completeTemplate"}}</a-radio-button>
  375. <a-radio-button value="inboundSettings">{{ i18n "pages.xray.Inbounds" }}</a-radio-button>
  376. <a-radio-button value="outboundSettings">{{ i18n "pages.xray.Outbounds" }}</a-radio-button>
  377. <a-radio-button value="routingRuleSettings">{{ i18n "pages.xray.Routings" }}</a-radio-button>
  378. </a-radio-group>
  379. <textarea style="position:absolute; left: -800px;" id="xraySetting"></textarea>
  380. </a-tab-pane>
  381. </a-tabs>
  382. </a-space>
  383. </a-spin>
  384. </a-layout-content>
  385. </a-layout>
  386. </a-layout>
  387. {{template "js" .}}
  388. {{template "component/themeSwitcher" .}}
  389. {{template "component/setting"}}
  390. {{template "ruleModal"}}
  391. {{template "outModal"}}
  392. {{template "reverseModal"}}
  393. <script>
  394. const rulesColumns = [
  395. { title: "#", align: 'center', width: 15, scopedSlots: { customRender: 'action' } },
  396. { title: '{{ i18n "pages.xray.rules.source"}}', children: [
  397. { title: 'IP', dataIndex: "source", align: 'center', width: 20, ellipsis: true },
  398. { title: 'port', dataIndex: 'sourcePort', align: 'center', width: 10, ellipsis: true } ]},
  399. { title: '{{ i18n "pages.inbounds.network"}}', children: [
  400. { title: 'L4', dataIndex: 'network', align: 'center', width: 10 },
  401. { title: 'Protocol', dataIndex: 'protocol', align: 'center', width: 10, ellipsis: true },
  402. { title: 'Attrs', dataIndex: 'attrs', align: 'center', width: 20, ellipsis: true } ]},
  403. { title: '{{ i18n "pages.xray.rules.dest"}}', children: [
  404. { title: 'IP', dataIndex: 'ip', align: 'center', width: 20, ellipsis: true },
  405. { title: 'Domain', dataIndex: 'domain', align: 'center', width: 20, ellipsis: true },
  406. { title: 'Port', dataIndex: 'port', align: 'center', width: 10, ellipsis: true }]},
  407. { title: '{{ i18n "pages.xray.rules.inbound"}}', children: [
  408. { title: 'Inbound Tag', dataIndex: 'inboundTag', align: 'center', width: 20, ellipsis: true },
  409. { title: 'User email', dataIndex: 'user', align: 'center', width: 20, ellipsis: true }]},
  410. { title: '{{ i18n "pages.xray.rules.outbound"}}', dataIndex: 'outboundTag', align: 'center', width: 20 },
  411. ];
  412. const rulesMobileColumns = [
  413. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  414. { title: '{{ i18n "pages.xray.rules.inbound"}}', align: 'center', width: 50, ellipsis: true, scopedSlots: { customRender: 'inbound' } },
  415. { title: '{{ i18n "pages.xray.rules.outbound"}}', align: 'center', width: 50, ellipsis: true, scopedSlots: { customRender: 'outbound' } },
  416. { title: '{{ i18n "pages.xray.rules.info"}}', align: 'center', width: 50, ellipsis: true, scopedSlots: { customRender: 'info' } },
  417. ];
  418. const outboundColumns = [
  419. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  420. { title: '{{ i18n "pages.xray.outbound.tag"}}', dataIndex: 'tag', align: 'center', width: 50 },
  421. { title: '{{ i18n "protocol"}}', align: 'center', width: 50, scopedSlots: { customRender: 'protocol' } },
  422. { title: '{{ i18n "pages.xray.outbound.address"}}', align: 'center', width: 50, scopedSlots: { customRender: 'address' } },
  423. ];
  424. const reverseColumns = [
  425. { title: "#", align: 'center', width: 20, scopedSlots: { customRender: 'action' } },
  426. { title: '{{ i18n "pages.xray.outbound.type"}}', dataIndex: 'type', align: 'center', width: 50 },
  427. { title: '{{ i18n "pages.xray.outbound.tag"}}', dataIndex: 'tag', align: 'center', width: 50 },
  428. { title: '{{ i18n "pages.xray.outbound.domain"}}', dataIndex: 'domain', align: 'center', width: 50 },
  429. ];
  430. const app = new Vue({
  431. delimiters: ['[[', ']]'],
  432. el: '#app',
  433. data: {
  434. siderDrawer,
  435. themeSwitcher,
  436. isDarkTheme: themeSwitcher.isDarkTheme,
  437. spinning: false,
  438. oldXraySetting: '',
  439. xraySetting: '',
  440. inboundTags: [],
  441. saveBtnDisable: true,
  442. isMobile: window.innerWidth <= 768,
  443. advSettings: 'xraySetting',
  444. cm: null,
  445. cmOptions: {
  446. lineNumbers: true,
  447. mode: "application/json",
  448. lint: true,
  449. styleActiveLine: true,
  450. matchBrackets: true,
  451. theme: "xq",
  452. autoCloseTags: true,
  453. lineWrapping: true,
  454. indentUnit: 2,
  455. indentWithTabs: true,
  456. smartIndent: true,
  457. tabSize: 2,
  458. lineWiseCopyCut: false,
  459. foldGutter: true,
  460. gutters: [
  461. "CodeMirror-lint-markers",
  462. "CodeMirror-linenumbers",
  463. "CodeMirror-foldgutter",
  464. ],
  465. },
  466. ipv4Settings: {
  467. tag: "IPv4",
  468. protocol: "freedom",
  469. settings: {
  470. domainStrategy: "UseIPv4"
  471. }
  472. },
  473. warpSettings: {
  474. tag: "WARP",
  475. protocol: "socks",
  476. settings: {
  477. servers: [
  478. {
  479. address: "127.0.0.1",
  480. port: 40000
  481. }
  482. ]
  483. }
  484. },
  485. directSettings: {
  486. tag: "direct",
  487. protocol: "freedom"
  488. },
  489. outboundDomainStrategies: ["AsIs", "UseIP", "UseIPv4", "UseIPv6"],
  490. routingDomainStrategies: ["AsIs", "IPIfNonMatch", "IPOnDemand"],
  491. settingsData: {
  492. protocols: {
  493. bittorrent: ["bittorrent"],
  494. },
  495. ips: {
  496. local: ["geoip:private"],
  497. cn: ["geoip:cn"],
  498. ir: ["ext:geoip_IR.dat:ir","ext:geoip_IR.dat:arvancloud","ext:geoip_IR.dat:derakcloud","ext:geoip_IR.dat:iranserver"],
  499. ru: ["geoip:ru"],
  500. },
  501. domains: {
  502. ads: [
  503. "geosite:category-ads-all",
  504. "ext:geosite_IR.dat:category-ads-all"
  505. ],
  506. speedtest: ["geosite:speedtest"],
  507. openai: ["geosite:openai"],
  508. google: ["geosite:google"],
  509. spotify: ["geosite:spotify"],
  510. netflix: ["geosite:netflix"],
  511. cn: [
  512. "geosite:cn",
  513. "regexp:.*\\.cn$"
  514. ],
  515. ru: [
  516. "geosite:category-gov-ru",
  517. "regexp:.*\\.ru$"
  518. ],
  519. ir: [
  520. "regexp:.*\\.ir$",
  521. "regexp:.*\\.xn--mgba3a4f16a$", // .ایران
  522. "ext:geosite_IR.dat:ir" // have rules to bypass all .ir domains.
  523. ]
  524. },
  525. familyProtectDNS: {
  526. "servers": [
  527. "1.1.1.3", // https://developers.cloudflare.com/1.1.1.1/setup/
  528. "1.0.0.3",
  529. "94.140.14.15", // https://adguard-dns.io/kb/general/dns-providers/
  530. "94.140.15.16"
  531. ],
  532. "queryStrategy": "UseIPv4"
  533. },
  534. }
  535. },
  536. methods: {
  537. loading(spinning = true) {
  538. this.spinning = spinning;
  539. },
  540. async getXraySetting() {
  541. this.loading(true);
  542. const msg = await HttpUtil.post("/panel/xray/");
  543. this.loading(false);
  544. if (msg.success) {
  545. result = JSON.parse(msg.obj);
  546. xs = JSON.stringify(result.xraySetting, null, 2);
  547. this.oldXraySetting = xs;
  548. this.xraySetting = xs;
  549. this.inboundTags = result.inboundTags;
  550. this.saveBtnDisable = true;
  551. }
  552. },
  553. async updateXraySetting() {
  554. this.loading(true);
  555. const msg = await HttpUtil.post("/panel/xray/update", {xraySetting : this.xraySetting});
  556. this.loading(false);
  557. if (msg.success) {
  558. await this.getXraySetting();
  559. }
  560. },
  561. async restartXray() {
  562. this.loading(true);
  563. const msg = await HttpUtil.post("server/restartXrayService");
  564. this.loading(false);
  565. if (msg.success) {
  566. this.loading(true);
  567. }
  568. },
  569. async fetchUserSecret() {
  570. this.loading(true);
  571. const userMessage = await HttpUtil.post("/panel/setting/getUserSecret", this.user);
  572. if (userMessage.success) {
  573. this.user = userMessage.obj;
  574. }
  575. this.loading(false);
  576. },
  577. async updateSecret() {
  578. this.loading(true);
  579. const msg = await HttpUtil.post("/panel/setting/updateUserSecret", this.user);
  580. if (msg.success) {
  581. this.user = msg.obj;
  582. window.location.replace(basePath + "logout");
  583. }
  584. this.loading(false);
  585. await this.updateXraySetting();
  586. },
  587. generateRandomString(length) {
  588. var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  589. let randomString = "";
  590. for (let i = 0; i < length; i++) {
  591. randomString += chars[Math.floor(Math.random() * chars.length)];
  592. }
  593. return randomString;
  594. },
  595. async getNewSecret() {
  596. this.loading(true);
  597. await PromiseUtil.sleep(600);
  598. const newSecret = this.generateRandomString(64);
  599. this.user.loginSecret = newSecret;
  600. document.getElementById("token").textContent = newSecret;
  601. this.loading(false);
  602. },
  603. async toggleToken(value) {
  604. if (value) {
  605. await this.getNewSecret();
  606. } else {
  607. this.user.loginSecret = "";
  608. }
  609. },
  610. async resetXrayConfigToDefault() {
  611. this.loading(true);
  612. const msg = await HttpUtil.get("/panel/setting/getDefaultJsonConfig");
  613. this.loading(false);
  614. if (msg.success) {
  615. this.templateSettings = JSON.parse(JSON.stringify(msg.obj, null, 2));
  616. this.saveBtnDisable = true;
  617. }
  618. },
  619. syncRulesWithOutbound(tag, setting) {
  620. const newTemplateSettings = {...this.templateSettings};
  621. const haveRules = newTemplateSettings.routing.rules.some((r) => r?.outboundTag === tag);
  622. const outboundIndex = newTemplateSettings.outbounds.findIndex((o) => o.tag === tag);
  623. if (!haveRules && outboundIndex >= 0) {
  624. newTemplateSettings.outbounds.splice(outboundIndex, 1);
  625. }
  626. if (haveRules && outboundIndex === -1) {
  627. newTemplateSettings.outbounds.push(setting);
  628. }
  629. this.templateSettings = newTemplateSettings;
  630. },
  631. templateRuleGetter(routeSettings) {
  632. const { property, outboundTag } = routeSettings;
  633. let result = [];
  634. if (this.templateSettings != null) {
  635. this.templateSettings.routing.rules.forEach(
  636. (routingRule) => {
  637. if (
  638. routingRule.hasOwnProperty(property) &&
  639. routingRule.hasOwnProperty("outboundTag") &&
  640. routingRule.outboundTag === outboundTag
  641. ) {
  642. result.push(...routingRule[property]);
  643. }
  644. }
  645. );
  646. }
  647. return result;
  648. },
  649. templateRuleSetter(routeSettings) {
  650. const { data, property, outboundTag } = routeSettings;
  651. const oldTemplateSettings = this.templateSettings;
  652. const newTemplateSettings = oldTemplateSettings;
  653. currentProperty = this.templateRuleGetter({ outboundTag, property })
  654. if (currentProperty.length == 0) {
  655. const propertyRule = {
  656. type: "field",
  657. outboundTag,
  658. [property]: data
  659. };
  660. newTemplateSettings.routing.rules.push(propertyRule);
  661. }
  662. else {
  663. const newRules = [];
  664. insertedOnce = false;
  665. newTemplateSettings.routing.rules.forEach(
  666. (routingRule) => {
  667. if (
  668. routingRule.hasOwnProperty(property) &&
  669. routingRule.hasOwnProperty("outboundTag") &&
  670. routingRule.outboundTag === outboundTag
  671. ) {
  672. if (!insertedOnce && data.length > 0) {
  673. insertedOnce = true;
  674. routingRule[property] = data;
  675. newRules.push(routingRule);
  676. }
  677. }
  678. else {
  679. newRules.push(routingRule);
  680. }
  681. }
  682. );
  683. newTemplateSettings.routing.rules = newRules;
  684. }
  685. this.templateSettings = newTemplateSettings;
  686. },
  687. changeCode() {
  688. if(this.cm != null) {
  689. this.cm.toTextArea();
  690. }
  691. textAreaObj = document.getElementById('xraySetting');
  692. textAreaObj.value = this[this.advSettings];
  693. this.cm = CodeMirror.fromTextArea(textAreaObj, this.cmOptions);
  694. this.cm.on('change',editor => {
  695. value = editor.getValue();
  696. if(this.isJsonString(value)){
  697. this[this.advSettings] = value;
  698. }
  699. });
  700. },
  701. isJsonString(str) {
  702. try {
  703. JSON.parse(str);
  704. } catch (e) {
  705. return false;
  706. }
  707. return true;
  708. },
  709. findOutboundAddress(o) {
  710. serverObj = null;
  711. switch(o.protocol){
  712. case Protocols.VMess:
  713. case Protocols.VLESS:
  714. serverObj = o.settings.vnext;
  715. break;
  716. case Protocols.HTTP:
  717. case Protocols.Socks:
  718. case Protocols.Shadowsocks:
  719. case Protocols.Trojan:
  720. serverObj = o.settings.servers;
  721. break;
  722. case Protocols.DNS:
  723. return [o.settings.address + ':' + o.settings.port];
  724. default:
  725. return null;
  726. }
  727. return serverObj ? serverObj.map(obj => obj.address + ':' + obj.port) : null;
  728. },
  729. addOutbound(){
  730. outModal.show({
  731. title: '{{ i18n "pages.xray.outbound.addOutbound"}}',
  732. okText: '{{ i18n "pages.xray.outbound.addOutbound" }}',
  733. confirm: (outbound) => {
  734. outModal.loading();
  735. if(outbound.tag.length > 0){
  736. this.templateSettings.outbounds.push(outbound);
  737. this.outboundSettings = JSON.stringify(this.templateSettings.outbounds);
  738. }
  739. outModal.close();
  740. },
  741. isEdit: false
  742. });
  743. },
  744. editOutbound(index){
  745. outModal.show({
  746. title: '{{ i18n "pages.xray.outbound.editOutbound"}} ' + (index+1),
  747. outbound: app.templateSettings.outbounds[index],
  748. confirm: (outbound) => {
  749. outModal.loading();
  750. this.templateSettings.outbounds[index] = outbound;
  751. this.outboundSettings = JSON.stringify(this.templateSettings.outbounds);
  752. outModal.close();
  753. },
  754. isEdit: true
  755. });
  756. },
  757. deleteOutbound(index){
  758. outbounds = this.templateSettings.outbounds;
  759. outbounds.splice(index,1);
  760. this.outboundSettings = JSON.stringify(outbounds);
  761. },
  762. addReverse(){
  763. reverseModal.show({
  764. title: '{{ i18n "pages.xray.outbound.addReverse"}}',
  765. okText: '{{ i18n "pages.xray.outbound.addReverse" }}',
  766. confirm: (reverse, rules) => {
  767. reverseModal.loading();
  768. if(reverse.tag.length > 0){
  769. newTemplateSettings = this.templateSettings;
  770. if(newTemplateSettings.reverse == undefined) newTemplateSettings.reverse = {};
  771. if(newTemplateSettings.reverse[reverse.type+'s'] == undefined) newTemplateSettings.reverse[reverse.type+'s'] = [];
  772. newTemplateSettings.reverse[reverse.type+'s'].push({ tag: reverse.tag, domain: reverse.domain });
  773. this.templateSettings = newTemplateSettings;
  774. // Add related rules
  775. this.templateSettings.routing.rules.push(...rules);
  776. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  777. }
  778. reverseModal.close();
  779. },
  780. isEdit: false
  781. });
  782. },
  783. editReverse(index){
  784. if(this.reverseData[index].type == "bridge") {
  785. oldRules = this.templateSettings.routing.rules.filter(r => r.inboundTag && r.inboundTag[0] == this.reverseData[index].tag);
  786. } else {
  787. oldRules = this.templateSettings.routing.rules.filter(r => r.outboundTag && r.outboundTag == this.reverseData[index].tag);
  788. }
  789. reverseModal.show({
  790. title: '{{ i18n "pages.xray.outbound.editReverse"}} ' + (index+1),
  791. reverse: this.reverseData[index],
  792. rules: oldRules,
  793. confirm: (reverse, rules) => {
  794. reverseModal.loading();
  795. if(reverse.tag.length > 0){
  796. oldtag = this.reverseData[index].tag;
  797. this.deleteReverse(index);
  798. newTemplateSettings = this.templateSettings;
  799. if(newTemplateSettings.reverse == undefined) newTemplateSettings.reverse = {};
  800. if(newTemplateSettings.reverse[reverse.type+'s'] == undefined) newTemplateSettings.reverse[reverse.type+'s'] = [];
  801. newTemplateSettings.reverse[reverse.type+'s'].push({ tag: reverse.tag, domain: reverse.domain });
  802. this.templateSettings = newTemplateSettings;
  803. // Adjust Rules
  804. newRules = this.templateSettings.routing.rules.filter(r => r.outboundTag != oldtag && (r.inboundTag && !r.inboundTag.includes(oldtag)));
  805. newRules.push(...rules)
  806. this.routingRuleSettings = JSON.stringify(newRules);
  807. }
  808. reverseModal.close();
  809. },
  810. isEdit: true
  811. });
  812. },
  813. deleteReverse(index){
  814. oldData = this.reverseData[index];
  815. newTemplateSettings = this.templateSettings;
  816. reverseTypeObj = newTemplateSettings.reverse[oldData.type+'s'];
  817. realIndex = reverseTypeObj.findIndex(r => r.tag==oldData.tag && r.domain==oldData.domain);
  818. newTemplateSettings.reverse[oldData.type+'s'].splice(realIndex,1);
  819. if(reverseTypeObj.length == 0) Reflect.deleteProperty(newTemplateSettings.reverse, oldData.type+'s');
  820. if(Object.keys(newTemplateSettings.reverse).length === 0) Reflect.deleteProperty(newTemplateSettings, 'reverse');
  821. newRules = newTemplateSettings.routing.rules.filter(r => r.outboundTag != oldData.tag && (r.inboundTag && !r.inboundTag.includes(oldData.tag)));
  822. newTemplateSettings.routing.rules = newRules;
  823. this.templateSettings = newTemplateSettings;
  824. },
  825. addRule(){
  826. ruleModal.show({
  827. title: '{{ i18n "pages.xray.rules.add"}}',
  828. okText: '{{ i18n "pages.xray.rules.add" }}',
  829. confirm: (rule) => {
  830. ruleModal.loading();
  831. if(JSON.stringify(rule).length > 3){
  832. this.templateSettings.routing.rules.push(rule);
  833. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  834. }
  835. ruleModal.close();
  836. },
  837. isEdit: false
  838. });
  839. },
  840. editRule(index){
  841. ruleModal.show({
  842. title: '{{ i18n "pages.xray.rules.edit"}} ' + (index+1),
  843. rule: app.templateSettings.routing.rules[index],
  844. confirm: (rule) => {
  845. ruleModal.loading();
  846. if(JSON.stringify(rule).length > 3){
  847. this.templateSettings.routing.rules[index] = rule;
  848. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  849. }
  850. ruleModal.close();
  851. },
  852. isEdit: true
  853. });
  854. },
  855. replaceRule(old_index,new_index){
  856. rules = this.templateSettings.routing.rules;
  857. if (new_index >= rules.length) rules.push(undefined);
  858. rules.splice(new_index, 0, rules.splice(old_index, 1)[0]);
  859. this.routingRuleSettings = JSON.stringify(rules);
  860. },
  861. deleteRule(index){
  862. rules = this.templateSettings.routing.rules;
  863. rules.splice(index,1);
  864. this.routingRuleSettings = JSON.stringify(rules);
  865. }
  866. },
  867. async mounted() {
  868. await this.getXraySetting();
  869. while (true) {
  870. await PromiseUtil.sleep(600);
  871. this.saveBtnDisable = this.oldXraySetting === this.xraySetting;
  872. }
  873. },
  874. computed: {
  875. templateSettings: {
  876. get: function () { return this.xraySetting ? JSON.parse(this.xraySetting) : null; },
  877. set: function (newValue) { this.xraySetting = JSON.stringify(newValue, null, 2); },
  878. },
  879. inboundSettings: {
  880. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.inbounds, null, 2) : null; },
  881. set: function (newValue) {
  882. newTemplateSettings = this.templateSettings;
  883. newTemplateSettings.inbounds = JSON.parse(newValue);
  884. this.templateSettings = newTemplateSettings;
  885. },
  886. },
  887. outboundSettings: {
  888. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.outbounds, null, 2) : null; },
  889. set: function (newValue) {
  890. newTemplateSettings = this.templateSettings;
  891. newTemplateSettings.outbounds = JSON.parse(newValue);
  892. this.templateSettings = newTemplateSettings;
  893. },
  894. },
  895. outboundData: {
  896. get: function () {
  897. data = []
  898. if (this.templateSettings != null) {
  899. this.templateSettings.outbounds.forEach((o, index) => {
  900. data.push({'key': index, ...o});
  901. });
  902. }
  903. return data;
  904. },
  905. },
  906. reverseData: {
  907. get: function () {
  908. data = []
  909. if (this.templateSettings != null && this.templateSettings.reverse != null) {
  910. if(this.templateSettings.reverse.bridges) {
  911. this.templateSettings.reverse.bridges.forEach((o, index) => {
  912. data.push({'key': index, 'type':'bridge', ...o});
  913. });
  914. }
  915. if(this.templateSettings.reverse.portals){
  916. this.templateSettings.reverse.portals.forEach((o, index) => {
  917. data.push({'key': index, 'type':'portal', ...o});
  918. });
  919. }
  920. }
  921. return data;
  922. },
  923. },
  924. routingRuleSettings: {
  925. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.routing.rules, null, 2) : null; },
  926. set: function (newValue) {
  927. newTemplateSettings = this.templateSettings;
  928. newTemplateSettings.routing.rules = JSON.parse(newValue);
  929. this.templateSettings = newTemplateSettings;
  930. },
  931. },
  932. routingRuleData: {
  933. get: function () {
  934. data = [];
  935. if (this.templateSettings != null) {
  936. this.templateSettings.routing.rules.forEach((r, index) => {
  937. data.push({'key': index, ...r});
  938. });
  939. // Make rules readable
  940. data.forEach(r => {
  941. if(r.domain) r.domain = r.domain.join(',')
  942. if(r.ip) r.ip = r.ip.join(',')
  943. if(r.source) r.source = r.source.join(',');
  944. if(r.user) r.user = r.user.join(',')
  945. if(r.inboundTag) r.inboundTag = r.inboundTag.join(',')
  946. if(r.protocol) r.protocol = r.protocol.join(',')
  947. if(r.attrs) r.attrs = JSON.stringify(r.attrs, null, 2)
  948. });
  949. }
  950. return data;
  951. }
  952. },
  953. freedomStrategy: {
  954. get: function () {
  955. if (!this.templateSettings) return "AsIs";
  956. freedomOutbound = this.templateSettings.outbounds.find((o) => o.protocol === "freedom" && !o.tag);
  957. if (!freedomOutbound) return "AsIs";
  958. if (!freedomOutbound.settings || !freedomOutbound.settings.domainStrategy) return "AsIs";
  959. return freedomOutbound.settings.domainStrategy;
  960. },
  961. set: function (newValue) {
  962. newTemplateSettings = this.templateSettings;
  963. freedomOutboundIndex = newTemplateSettings.outbounds.findIndex((o) => o.protocol === "freedom" && !o.tag);
  964. if (!newTemplateSettings.outbounds[freedomOutboundIndex].settings) {
  965. newTemplateSettings.outbounds[freedomOutboundIndex].settings = {"domainStrategy": newValue};
  966. } else {
  967. newTemplateSettings.outbounds[freedomOutboundIndex].settings.domainStrategy = newValue;
  968. }
  969. this.templateSettings = newTemplateSettings;
  970. }
  971. },
  972. routingStrategy: {
  973. get: function () {
  974. if (!this.templateSettings || !this.templateSettings.routing || !this.templateSettings.routing.domainStrategy) return "AsIs";
  975. return this.templateSettings.routing.domainStrategy;
  976. },
  977. set: function (newValue) {
  978. newTemplateSettings = this.templateSettings;
  979. newTemplateSettings.routing.domainStrategy = newValue;
  980. this.templateSettings = newTemplateSettings;
  981. }
  982. },
  983. blockedIPs: {
  984. get: function () {
  985. return this.templateRuleGetter({ outboundTag: "blocked", property: "ip" });
  986. },
  987. set: function (newValue) {
  988. this.templateRuleSetter({ outboundTag: "blocked", property: "ip", data: newValue });
  989. }
  990. },
  991. blockedDomains: {
  992. get: function () {
  993. return this.templateRuleGetter({ outboundTag: "blocked", property: "domain" });
  994. },
  995. set: function (newValue) {
  996. this.templateRuleSetter({ outboundTag: "blocked", property: "domain", data: newValue });
  997. }
  998. },
  999. blockedProtocols: {
  1000. get: function () {
  1001. return this.templateRuleGetter({ outboundTag: "blocked", property: "protocol" });
  1002. },
  1003. set: function (newValue) {
  1004. this.templateRuleSetter({ outboundTag: "blocked", property: "protocol", data: newValue });
  1005. }
  1006. },
  1007. directIPs: {
  1008. get: function () {
  1009. return this.templateRuleGetter({ outboundTag: "direct", property: "ip" });
  1010. },
  1011. set: function (newValue) {
  1012. this.templateRuleSetter({ outboundTag: "direct", property: "ip", data: newValue });
  1013. this.syncRulesWithOutbound("direct", this.directSettings);
  1014. }
  1015. },
  1016. directDomains: {
  1017. get: function () {
  1018. return this.templateRuleGetter({ outboundTag: "direct", property: "domain" });
  1019. },
  1020. set: function (newValue) {
  1021. this.templateRuleSetter({ outboundTag: "direct", property: "domain", data: newValue });
  1022. this.syncRulesWithOutbound("direct", this.directSettings);
  1023. }
  1024. },
  1025. ipv4Domains: {
  1026. get: function () {
  1027. return this.templateRuleGetter({ outboundTag: "IPv4", property: "domain" });
  1028. },
  1029. set: function (newValue) {
  1030. this.templateRuleSetter({ outboundTag: "IPv4", property: "domain", data: newValue });
  1031. this.syncRulesWithOutbound("IPv4", this.ipv4Settings);
  1032. }
  1033. },
  1034. warpDomains: {
  1035. get: function () {
  1036. return this.templateRuleGetter({ outboundTag: "WARP", property: "domain" });
  1037. },
  1038. set: function (newValue) {
  1039. this.templateRuleSetter({ outboundTag: "WARP", property: "domain", data: newValue });
  1040. this.syncRulesWithOutbound("WARP", this.warpSettings);
  1041. }
  1042. },
  1043. manualBlockedIPs: {
  1044. get: function () { return JSON.stringify(this.blockedIPs, null, 2); },
  1045. set: debounce(function (value) { this.blockedIPs = JSON.parse(value); }, 1000)
  1046. },
  1047. manualBlockedDomains: {
  1048. get: function () { return JSON.stringify(this.blockedDomains, null, 2); },
  1049. set: debounce(function (value) { this.blockedDomains = JSON.parse(value); }, 1000)
  1050. },
  1051. manualDirectIPs: {
  1052. get: function () { return JSON.stringify(this.directIPs, null, 2); },
  1053. set: debounce(function (value) { this.directIPs = JSON.parse(value); }, 1000)
  1054. },
  1055. manualDirectDomains: {
  1056. get: function () { return JSON.stringify(this.directDomains, null, 2); },
  1057. set: debounce(function (value) { this.directDomains = JSON.parse(value); }, 1000)
  1058. },
  1059. manualIPv4Domains: {
  1060. get: function () { return JSON.stringify(this.ipv4Domains, null, 2); },
  1061. set: debounce(function (value) { this.ipv4Domains = JSON.parse(value); }, 1000)
  1062. },
  1063. manualWARPDomains: {
  1064. get: function () { return JSON.stringify(this.warpDomains, null, 2); },
  1065. set: debounce(function (value) { this.warpDomains = JSON.parse(value); }, 1000)
  1066. },
  1067. torrentSettings: {
  1068. get: function () {
  1069. return doAllItemsExist(this.settingsData.protocols.bittorrent, this.blockedProtocols);
  1070. },
  1071. set: function (newValue) {
  1072. if (newValue) {
  1073. this.blockedProtocols = [...this.blockedProtocols, ...this.settingsData.protocols.bittorrent];
  1074. } else {
  1075. this.blockedProtocols = this.blockedProtocols.filter(data => !this.settingsData.protocols.bittorrent.includes(data));
  1076. }
  1077. },
  1078. },
  1079. privateIpSettings: {
  1080. get: function () {
  1081. return doAllItemsExist(this.settingsData.ips.local, this.blockedIPs);
  1082. },
  1083. set: function (newValue) {
  1084. if (newValue) {
  1085. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.local];
  1086. } else {
  1087. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.local.includes(data));
  1088. }
  1089. },
  1090. },
  1091. AdsSettings: {
  1092. get: function () {
  1093. return doAllItemsExist(this.settingsData.domains.ads, this.blockedDomains);
  1094. },
  1095. set: function (newValue) {
  1096. if (newValue) {
  1097. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.ads];
  1098. } else {
  1099. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.ads.includes(data));
  1100. }
  1101. },
  1102. },
  1103. SpeedTestSettings: {
  1104. get: function () {
  1105. return doAllItemsExist(this.settingsData.domains.speedtest, this.blockedDomains);
  1106. },
  1107. set: function (newValue) {
  1108. if (newValue) {
  1109. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.speedtest];
  1110. } else {
  1111. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.speedtest.includes(data));
  1112. }
  1113. },
  1114. },
  1115. familyProtectSettings: {
  1116. get: function () {
  1117. if (!this.templateSettings || !this.templateSettings.dns || !this.templateSettings.dns.servers) return false;
  1118. return doAllItemsExist(this.templateSettings.dns.servers, this.settingsData.familyProtectDNS.servers);
  1119. },
  1120. set: function (newValue) {
  1121. newTemplateSettings = this.templateSettings;
  1122. if (newValue) {
  1123. newTemplateSettings.dns = this.settingsData.familyProtectDNS;
  1124. } else {
  1125. delete newTemplateSettings.dns;
  1126. }
  1127. this.templateSettings = newTemplateSettings;
  1128. },
  1129. },
  1130. GoogleIPv4Settings: {
  1131. get: function () {
  1132. return doAllItemsExist(this.settingsData.domains.google, this.ipv4Domains);
  1133. },
  1134. set: function (newValue) {
  1135. if (newValue) {
  1136. this.ipv4Domains = [...this.ipv4Domains, ...this.settingsData.domains.google];
  1137. } else {
  1138. this.ipv4Domains = this.ipv4Domains.filter(data => !this.settingsData.domains.google.includes(data));
  1139. }
  1140. },
  1141. },
  1142. NetflixIPv4Settings: {
  1143. get: function () {
  1144. return doAllItemsExist(this.settingsData.domains.netflix, this.ipv4Domains);
  1145. },
  1146. set: function (newValue) {
  1147. if (newValue) {
  1148. this.ipv4Domains = [...this.ipv4Domains, ...this.settingsData.domains.netflix];
  1149. } else {
  1150. this.ipv4Domains = this.ipv4Domains.filter(data => !this.settingsData.domains.netflix.includes(data));
  1151. }
  1152. },
  1153. },
  1154. IRIpSettings: {
  1155. get: function () {
  1156. return doAllItemsExist(this.settingsData.ips.ir, this.blockedIPs);
  1157. },
  1158. set: function (newValue) {
  1159. if (newValue) {
  1160. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.ir];
  1161. } else {
  1162. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.ir.includes(data));
  1163. }
  1164. }
  1165. },
  1166. IRDomainSettings: {
  1167. get: function () {
  1168. return doAllItemsExist(this.settingsData.domains.ir, this.blockedDomains);
  1169. },
  1170. set: function (newValue) {
  1171. if (newValue) {
  1172. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.ir];
  1173. } else {
  1174. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.ir.includes(data));
  1175. }
  1176. }
  1177. },
  1178. ChinaIpSettings: {
  1179. get: function () {
  1180. return doAllItemsExist(this.settingsData.ips.cn, this.blockedIPs);
  1181. },
  1182. set: function (newValue) {
  1183. if (newValue) {
  1184. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.cn];
  1185. } else {
  1186. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.cn.includes(data));
  1187. }
  1188. }
  1189. },
  1190. ChinaDomainSettings: {
  1191. get: function () {
  1192. return doAllItemsExist(this.settingsData.domains.cn, this.blockedDomains);
  1193. },
  1194. set: function (newValue) {
  1195. if (newValue) {
  1196. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.cn];
  1197. } else {
  1198. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.cn.includes(data));
  1199. }
  1200. }
  1201. },
  1202. RussiaIpSettings: {
  1203. get: function () {
  1204. return doAllItemsExist(this.settingsData.ips.ru, this.blockedIPs);
  1205. },
  1206. set: function (newValue) {
  1207. if (newValue) {
  1208. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.ru];
  1209. } else {
  1210. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.ru.includes(data));
  1211. }
  1212. }
  1213. },
  1214. RussiaDomainSettings: {
  1215. get: function () {
  1216. return doAllItemsExist(this.settingsData.domains.ru, this.blockedDomains);
  1217. },
  1218. set: function (newValue) {
  1219. if (newValue) {
  1220. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.ru];
  1221. } else {
  1222. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.ru.includes(data));
  1223. }
  1224. }
  1225. },
  1226. IRIpDirectSettings: {
  1227. get: function () {
  1228. return doAllItemsExist(this.settingsData.ips.ir, this.directIPs);
  1229. },
  1230. set: function (newValue) {
  1231. if (newValue) {
  1232. this.directIPs = [...this.directIPs, ...this.settingsData.ips.ir];
  1233. } else {
  1234. this.directIPs = this.directIPs.filter(data => !this.settingsData.ips.ir.includes(data));
  1235. }
  1236. }
  1237. },
  1238. IRDomainDirectSettings: {
  1239. get: function () {
  1240. return doAllItemsExist(this.settingsData.domains.ir, this.directDomains);
  1241. },
  1242. set: function (newValue) {
  1243. if (newValue) {
  1244. this.directDomains = [...this.directDomains, ...this.settingsData.domains.ir];
  1245. } else {
  1246. this.directDomains = this.directDomains.filter(data => !this.settingsData.domains.ir.includes(data));
  1247. }
  1248. }
  1249. },
  1250. ChinaIpDirectSettings: {
  1251. get: function () {
  1252. return doAllItemsExist(this.settingsData.ips.cn, this.directIPs);
  1253. },
  1254. set: function (newValue) {
  1255. if (newValue) {
  1256. this.directIPs = [...this.directIPs, ...this.settingsData.ips.cn];
  1257. } else {
  1258. this.directIPs = this.directIPs.filter(data => !this.settingsData.ips.cn.includes(data));
  1259. }
  1260. }
  1261. },
  1262. ChinaDomainDirectSettings: {
  1263. get: function () {
  1264. return doAllItemsExist(this.settingsData.domains.cn, this.directDomains);
  1265. },
  1266. set: function (newValue) {
  1267. if (newValue) {
  1268. this.directDomains = [...this.directDomains, ...this.settingsData.domains.cn];
  1269. } else {
  1270. this.directDomains = this.directDomains.filter(data => !this.settingsData.domains.cn.includes(data));
  1271. }
  1272. }
  1273. },
  1274. RussiaIpDirectSettings: {
  1275. get: function () {
  1276. return doAllItemsExist(this.settingsData.ips.ru, this.directIPs);
  1277. },
  1278. set: function (newValue) {
  1279. if (newValue) {
  1280. this.directIPs = [...this.directIPs, ...this.settingsData.ips.ru];
  1281. } else {
  1282. this.directIPs = this.directIPs.filter(data => !this.settingsData.ips.ru.includes(data));
  1283. }
  1284. }
  1285. },
  1286. RussiaDomainDirectSettings: {
  1287. get: function () {
  1288. return doAllItemsExist(this.settingsData.domains.ru, this.directDomains);
  1289. },
  1290. set: function (newValue) {
  1291. if (newValue) {
  1292. this.directDomains = [...this.directDomains, ...this.settingsData.domains.ru];
  1293. } else {
  1294. this.directDomains = this.directDomains.filter(data => !this.settingsData.domains.ru.includes(data));
  1295. }
  1296. }
  1297. },
  1298. GoogleWARPSettings: {
  1299. get: function () {
  1300. return doAllItemsExist(this.settingsData.domains.google, this.warpDomains);
  1301. },
  1302. set: function (newValue) {
  1303. if (newValue) {
  1304. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.google];
  1305. } else {
  1306. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.google.includes(data));
  1307. }
  1308. },
  1309. },
  1310. OpenAIWARPSettings: {
  1311. get: function () {
  1312. return doAllItemsExist(this.settingsData.domains.openai, this.warpDomains);
  1313. },
  1314. set: function (newValue) {
  1315. if (newValue) {
  1316. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.openai];
  1317. } else {
  1318. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.openai.includes(data));
  1319. }
  1320. },
  1321. },
  1322. NetflixWARPSettings: {
  1323. get: function () {
  1324. return doAllItemsExist(this.settingsData.domains.netflix, this.warpDomains);
  1325. },
  1326. set: function (newValue) {
  1327. if (newValue) {
  1328. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.netflix];
  1329. } else {
  1330. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.netflix.includes(data));
  1331. }
  1332. },
  1333. },
  1334. SpotifyWARPSettings: {
  1335. get: function () {
  1336. return doAllItemsExist(this.settingsData.domains.spotify, this.warpDomains);
  1337. },
  1338. set: function (newValue) {
  1339. if (newValue) {
  1340. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.spotify];
  1341. } else {
  1342. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.spotify.includes(data));
  1343. }
  1344. },
  1345. },
  1346. },
  1347. });
  1348. </script>
  1349. </body>
  1350. </html>