xray.html 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366
  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. tags: this.templateSettings.outbounds.map(obj => obj.tag)
  743. });
  744. },
  745. editOutbound(index){
  746. outModal.show({
  747. title: '{{ i18n "pages.xray.outbound.editOutbound"}} ' + (index+1),
  748. outbound: app.templateSettings.outbounds[index],
  749. confirm: (outbound) => {
  750. outModal.loading();
  751. this.templateSettings.outbounds[index] = outbound;
  752. this.outboundSettings = JSON.stringify(this.templateSettings.outbounds);
  753. outModal.close();
  754. },
  755. isEdit: true,
  756. tags: this.outboundData.filter((o) => o.key != index ).map(obj => obj.tag)
  757. });
  758. },
  759. deleteOutbound(index){
  760. outbounds = this.templateSettings.outbounds;
  761. outbounds.splice(index,1);
  762. this.outboundSettings = JSON.stringify(outbounds);
  763. },
  764. addReverse(){
  765. reverseModal.show({
  766. title: '{{ i18n "pages.xray.outbound.addReverse"}}',
  767. okText: '{{ i18n "pages.xray.outbound.addReverse" }}',
  768. confirm: (reverse, rules) => {
  769. reverseModal.loading();
  770. if(reverse.tag.length > 0){
  771. newTemplateSettings = this.templateSettings;
  772. if(newTemplateSettings.reverse == undefined) newTemplateSettings.reverse = {};
  773. if(newTemplateSettings.reverse[reverse.type+'s'] == undefined) newTemplateSettings.reverse[reverse.type+'s'] = [];
  774. newTemplateSettings.reverse[reverse.type+'s'].push({ tag: reverse.tag, domain: reverse.domain });
  775. this.templateSettings = newTemplateSettings;
  776. // Add related rules
  777. this.templateSettings.routing.rules.push(...rules);
  778. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  779. }
  780. reverseModal.close();
  781. },
  782. isEdit: false
  783. });
  784. },
  785. editReverse(index){
  786. if(this.reverseData[index].type == "bridge") {
  787. oldRules = this.templateSettings.routing.rules.filter(r => r.inboundTag && r.inboundTag[0] == this.reverseData[index].tag);
  788. } else {
  789. oldRules = this.templateSettings.routing.rules.filter(r => r.outboundTag && r.outboundTag == this.reverseData[index].tag);
  790. }
  791. reverseModal.show({
  792. title: '{{ i18n "pages.xray.outbound.editReverse"}} ' + (index+1),
  793. reverse: this.reverseData[index],
  794. rules: oldRules,
  795. confirm: (reverse, rules) => {
  796. reverseModal.loading();
  797. if(reverse.tag.length > 0){
  798. oldtag = this.reverseData[index].tag;
  799. this.deleteReverse(index);
  800. newTemplateSettings = this.templateSettings;
  801. if(newTemplateSettings.reverse == undefined) newTemplateSettings.reverse = {};
  802. if(newTemplateSettings.reverse[reverse.type+'s'] == undefined) newTemplateSettings.reverse[reverse.type+'s'] = [];
  803. newTemplateSettings.reverse[reverse.type+'s'].push({ tag: reverse.tag, domain: reverse.domain });
  804. this.templateSettings = newTemplateSettings;
  805. // Adjust Rules
  806. newRules = this.templateSettings.routing.rules.filter(r => r.outboundTag != oldtag && (r.inboundTag && !r.inboundTag.includes(oldtag)));
  807. newRules.push(...rules)
  808. this.routingRuleSettings = JSON.stringify(newRules);
  809. }
  810. reverseModal.close();
  811. },
  812. isEdit: true
  813. });
  814. },
  815. deleteReverse(index){
  816. oldData = this.reverseData[index];
  817. newTemplateSettings = this.templateSettings;
  818. reverseTypeObj = newTemplateSettings.reverse[oldData.type+'s'];
  819. realIndex = reverseTypeObj.findIndex(r => r.tag==oldData.tag && r.domain==oldData.domain);
  820. newTemplateSettings.reverse[oldData.type+'s'].splice(realIndex,1);
  821. if(reverseTypeObj.length == 0) Reflect.deleteProperty(newTemplateSettings.reverse, oldData.type+'s');
  822. if(Object.keys(newTemplateSettings.reverse).length === 0) Reflect.deleteProperty(newTemplateSettings, 'reverse');
  823. newRules = newTemplateSettings.routing.rules.filter(r => r.outboundTag != oldData.tag && (r.inboundTag && !r.inboundTag.includes(oldData.tag)));
  824. newTemplateSettings.routing.rules = newRules;
  825. this.templateSettings = newTemplateSettings;
  826. },
  827. addRule(){
  828. ruleModal.show({
  829. title: '{{ i18n "pages.xray.rules.add"}}',
  830. okText: '{{ i18n "pages.xray.rules.add" }}',
  831. confirm: (rule) => {
  832. ruleModal.loading();
  833. if(JSON.stringify(rule).length > 3){
  834. this.templateSettings.routing.rules.push(rule);
  835. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  836. }
  837. ruleModal.close();
  838. },
  839. isEdit: false
  840. });
  841. },
  842. editRule(index){
  843. ruleModal.show({
  844. title: '{{ i18n "pages.xray.rules.edit"}} ' + (index+1),
  845. rule: app.templateSettings.routing.rules[index],
  846. confirm: (rule) => {
  847. ruleModal.loading();
  848. if(JSON.stringify(rule).length > 3){
  849. this.templateSettings.routing.rules[index] = rule;
  850. this.routingRuleSettings = JSON.stringify(this.templateSettings.routing.rules);
  851. }
  852. ruleModal.close();
  853. },
  854. isEdit: true
  855. });
  856. },
  857. replaceRule(old_index,new_index){
  858. rules = this.templateSettings.routing.rules;
  859. if (new_index >= rules.length) rules.push(undefined);
  860. rules.splice(new_index, 0, rules.splice(old_index, 1)[0]);
  861. this.routingRuleSettings = JSON.stringify(rules);
  862. },
  863. deleteRule(index){
  864. rules = this.templateSettings.routing.rules;
  865. rules.splice(index,1);
  866. this.routingRuleSettings = JSON.stringify(rules);
  867. }
  868. },
  869. async mounted() {
  870. await this.getXraySetting();
  871. while (true) {
  872. await PromiseUtil.sleep(600);
  873. this.saveBtnDisable = this.oldXraySetting === this.xraySetting;
  874. }
  875. },
  876. computed: {
  877. templateSettings: {
  878. get: function () { return this.xraySetting ? JSON.parse(this.xraySetting) : null; },
  879. set: function (newValue) { this.xraySetting = JSON.stringify(newValue, null, 2); },
  880. },
  881. inboundSettings: {
  882. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.inbounds, null, 2) : null; },
  883. set: function (newValue) {
  884. newTemplateSettings = this.templateSettings;
  885. newTemplateSettings.inbounds = JSON.parse(newValue);
  886. this.templateSettings = newTemplateSettings;
  887. },
  888. },
  889. outboundSettings: {
  890. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.outbounds, null, 2) : null; },
  891. set: function (newValue) {
  892. newTemplateSettings = this.templateSettings;
  893. newTemplateSettings.outbounds = JSON.parse(newValue);
  894. this.templateSettings = newTemplateSettings;
  895. },
  896. },
  897. outboundData: {
  898. get: function () {
  899. data = []
  900. if (this.templateSettings != null) {
  901. this.templateSettings.outbounds.forEach((o, index) => {
  902. data.push({'key': index, ...o});
  903. });
  904. }
  905. return data;
  906. },
  907. },
  908. reverseData: {
  909. get: function () {
  910. data = []
  911. if (this.templateSettings != null && this.templateSettings.reverse != null) {
  912. if(this.templateSettings.reverse.bridges) {
  913. this.templateSettings.reverse.bridges.forEach((o, index) => {
  914. data.push({'key': index, 'type':'bridge', ...o});
  915. });
  916. }
  917. if(this.templateSettings.reverse.portals){
  918. this.templateSettings.reverse.portals.forEach((o, index) => {
  919. data.push({'key': index, 'type':'portal', ...o});
  920. });
  921. }
  922. }
  923. return data;
  924. },
  925. },
  926. routingRuleSettings: {
  927. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.routing.rules, null, 2) : null; },
  928. set: function (newValue) {
  929. newTemplateSettings = this.templateSettings;
  930. newTemplateSettings.routing.rules = JSON.parse(newValue);
  931. this.templateSettings = newTemplateSettings;
  932. },
  933. },
  934. routingRuleData: {
  935. get: function () {
  936. data = [];
  937. if (this.templateSettings != null) {
  938. this.templateSettings.routing.rules.forEach((r, index) => {
  939. data.push({'key': index, ...r});
  940. });
  941. // Make rules readable
  942. data.forEach(r => {
  943. if(r.domain) r.domain = r.domain.join(',')
  944. if(r.ip) r.ip = r.ip.join(',')
  945. if(r.source) r.source = r.source.join(',');
  946. if(r.user) r.user = r.user.join(',')
  947. if(r.inboundTag) r.inboundTag = r.inboundTag.join(',')
  948. if(r.protocol) r.protocol = r.protocol.join(',')
  949. if(r.attrs) r.attrs = JSON.stringify(r.attrs, null, 2)
  950. });
  951. }
  952. return data;
  953. }
  954. },
  955. freedomStrategy: {
  956. get: function () {
  957. if (!this.templateSettings) return "AsIs";
  958. freedomOutbound = this.templateSettings.outbounds.find((o) => o.protocol === "freedom" && !o.tag);
  959. if (!freedomOutbound) return "AsIs";
  960. if (!freedomOutbound.settings || !freedomOutbound.settings.domainStrategy) return "AsIs";
  961. return freedomOutbound.settings.domainStrategy;
  962. },
  963. set: function (newValue) {
  964. newTemplateSettings = this.templateSettings;
  965. freedomOutboundIndex = newTemplateSettings.outbounds.findIndex((o) => o.protocol === "freedom" && !o.tag);
  966. if (!newTemplateSettings.outbounds[freedomOutboundIndex].settings) {
  967. newTemplateSettings.outbounds[freedomOutboundIndex].settings = {"domainStrategy": newValue};
  968. } else {
  969. newTemplateSettings.outbounds[freedomOutboundIndex].settings.domainStrategy = newValue;
  970. }
  971. this.templateSettings = newTemplateSettings;
  972. }
  973. },
  974. routingStrategy: {
  975. get: function () {
  976. if (!this.templateSettings || !this.templateSettings.routing || !this.templateSettings.routing.domainStrategy) return "AsIs";
  977. return this.templateSettings.routing.domainStrategy;
  978. },
  979. set: function (newValue) {
  980. newTemplateSettings = this.templateSettings;
  981. newTemplateSettings.routing.domainStrategy = newValue;
  982. this.templateSettings = newTemplateSettings;
  983. }
  984. },
  985. blockedIPs: {
  986. get: function () {
  987. return this.templateRuleGetter({ outboundTag: "blocked", property: "ip" });
  988. },
  989. set: function (newValue) {
  990. this.templateRuleSetter({ outboundTag: "blocked", property: "ip", data: newValue });
  991. }
  992. },
  993. blockedDomains: {
  994. get: function () {
  995. return this.templateRuleGetter({ outboundTag: "blocked", property: "domain" });
  996. },
  997. set: function (newValue) {
  998. this.templateRuleSetter({ outboundTag: "blocked", property: "domain", data: newValue });
  999. }
  1000. },
  1001. blockedProtocols: {
  1002. get: function () {
  1003. return this.templateRuleGetter({ outboundTag: "blocked", property: "protocol" });
  1004. },
  1005. set: function (newValue) {
  1006. this.templateRuleSetter({ outboundTag: "blocked", property: "protocol", data: newValue });
  1007. }
  1008. },
  1009. directIPs: {
  1010. get: function () {
  1011. return this.templateRuleGetter({ outboundTag: "direct", property: "ip" });
  1012. },
  1013. set: function (newValue) {
  1014. this.templateRuleSetter({ outboundTag: "direct", property: "ip", data: newValue });
  1015. this.syncRulesWithOutbound("direct", this.directSettings);
  1016. }
  1017. },
  1018. directDomains: {
  1019. get: function () {
  1020. return this.templateRuleGetter({ outboundTag: "direct", property: "domain" });
  1021. },
  1022. set: function (newValue) {
  1023. this.templateRuleSetter({ outboundTag: "direct", property: "domain", data: newValue });
  1024. this.syncRulesWithOutbound("direct", this.directSettings);
  1025. }
  1026. },
  1027. ipv4Domains: {
  1028. get: function () {
  1029. return this.templateRuleGetter({ outboundTag: "IPv4", property: "domain" });
  1030. },
  1031. set: function (newValue) {
  1032. this.templateRuleSetter({ outboundTag: "IPv4", property: "domain", data: newValue });
  1033. this.syncRulesWithOutbound("IPv4", this.ipv4Settings);
  1034. }
  1035. },
  1036. warpDomains: {
  1037. get: function () {
  1038. return this.templateRuleGetter({ outboundTag: "WARP", property: "domain" });
  1039. },
  1040. set: function (newValue) {
  1041. this.templateRuleSetter({ outboundTag: "WARP", property: "domain", data: newValue });
  1042. this.syncRulesWithOutbound("WARP", this.warpSettings);
  1043. }
  1044. },
  1045. manualBlockedIPs: {
  1046. get: function () { return JSON.stringify(this.blockedIPs, null, 2); },
  1047. set: debounce(function (value) { this.blockedIPs = JSON.parse(value); }, 1000)
  1048. },
  1049. manualBlockedDomains: {
  1050. get: function () { return JSON.stringify(this.blockedDomains, null, 2); },
  1051. set: debounce(function (value) { this.blockedDomains = JSON.parse(value); }, 1000)
  1052. },
  1053. manualDirectIPs: {
  1054. get: function () { return JSON.stringify(this.directIPs, null, 2); },
  1055. set: debounce(function (value) { this.directIPs = JSON.parse(value); }, 1000)
  1056. },
  1057. manualDirectDomains: {
  1058. get: function () { return JSON.stringify(this.directDomains, null, 2); },
  1059. set: debounce(function (value) { this.directDomains = JSON.parse(value); }, 1000)
  1060. },
  1061. manualIPv4Domains: {
  1062. get: function () { return JSON.stringify(this.ipv4Domains, null, 2); },
  1063. set: debounce(function (value) { this.ipv4Domains = JSON.parse(value); }, 1000)
  1064. },
  1065. manualWARPDomains: {
  1066. get: function () { return JSON.stringify(this.warpDomains, null, 2); },
  1067. set: debounce(function (value) { this.warpDomains = JSON.parse(value); }, 1000)
  1068. },
  1069. torrentSettings: {
  1070. get: function () {
  1071. return doAllItemsExist(this.settingsData.protocols.bittorrent, this.blockedProtocols);
  1072. },
  1073. set: function (newValue) {
  1074. if (newValue) {
  1075. this.blockedProtocols = [...this.blockedProtocols, ...this.settingsData.protocols.bittorrent];
  1076. } else {
  1077. this.blockedProtocols = this.blockedProtocols.filter(data => !this.settingsData.protocols.bittorrent.includes(data));
  1078. }
  1079. },
  1080. },
  1081. privateIpSettings: {
  1082. get: function () {
  1083. return doAllItemsExist(this.settingsData.ips.local, this.blockedIPs);
  1084. },
  1085. set: function (newValue) {
  1086. if (newValue) {
  1087. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.local];
  1088. } else {
  1089. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.local.includes(data));
  1090. }
  1091. },
  1092. },
  1093. AdsSettings: {
  1094. get: function () {
  1095. return doAllItemsExist(this.settingsData.domains.ads, this.blockedDomains);
  1096. },
  1097. set: function (newValue) {
  1098. if (newValue) {
  1099. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.ads];
  1100. } else {
  1101. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.ads.includes(data));
  1102. }
  1103. },
  1104. },
  1105. SpeedTestSettings: {
  1106. get: function () {
  1107. return doAllItemsExist(this.settingsData.domains.speedtest, this.blockedDomains);
  1108. },
  1109. set: function (newValue) {
  1110. if (newValue) {
  1111. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.speedtest];
  1112. } else {
  1113. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.speedtest.includes(data));
  1114. }
  1115. },
  1116. },
  1117. familyProtectSettings: {
  1118. get: function () {
  1119. if (!this.templateSettings || !this.templateSettings.dns || !this.templateSettings.dns.servers) return false;
  1120. return doAllItemsExist(this.templateSettings.dns.servers, this.settingsData.familyProtectDNS.servers);
  1121. },
  1122. set: function (newValue) {
  1123. newTemplateSettings = this.templateSettings;
  1124. if (newValue) {
  1125. newTemplateSettings.dns = this.settingsData.familyProtectDNS;
  1126. } else {
  1127. delete newTemplateSettings.dns;
  1128. }
  1129. this.templateSettings = newTemplateSettings;
  1130. },
  1131. },
  1132. GoogleIPv4Settings: {
  1133. get: function () {
  1134. return doAllItemsExist(this.settingsData.domains.google, this.ipv4Domains);
  1135. },
  1136. set: function (newValue) {
  1137. if (newValue) {
  1138. this.ipv4Domains = [...this.ipv4Domains, ...this.settingsData.domains.google];
  1139. } else {
  1140. this.ipv4Domains = this.ipv4Domains.filter(data => !this.settingsData.domains.google.includes(data));
  1141. }
  1142. },
  1143. },
  1144. NetflixIPv4Settings: {
  1145. get: function () {
  1146. return doAllItemsExist(this.settingsData.domains.netflix, this.ipv4Domains);
  1147. },
  1148. set: function (newValue) {
  1149. if (newValue) {
  1150. this.ipv4Domains = [...this.ipv4Domains, ...this.settingsData.domains.netflix];
  1151. } else {
  1152. this.ipv4Domains = this.ipv4Domains.filter(data => !this.settingsData.domains.netflix.includes(data));
  1153. }
  1154. },
  1155. },
  1156. IRIpSettings: {
  1157. get: function () {
  1158. return doAllItemsExist(this.settingsData.ips.ir, this.blockedIPs);
  1159. },
  1160. set: function (newValue) {
  1161. if (newValue) {
  1162. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.ir];
  1163. } else {
  1164. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.ir.includes(data));
  1165. }
  1166. }
  1167. },
  1168. IRDomainSettings: {
  1169. get: function () {
  1170. return doAllItemsExist(this.settingsData.domains.ir, this.blockedDomains);
  1171. },
  1172. set: function (newValue) {
  1173. if (newValue) {
  1174. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.ir];
  1175. } else {
  1176. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.ir.includes(data));
  1177. }
  1178. }
  1179. },
  1180. ChinaIpSettings: {
  1181. get: function () {
  1182. return doAllItemsExist(this.settingsData.ips.cn, this.blockedIPs);
  1183. },
  1184. set: function (newValue) {
  1185. if (newValue) {
  1186. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.cn];
  1187. } else {
  1188. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.cn.includes(data));
  1189. }
  1190. }
  1191. },
  1192. ChinaDomainSettings: {
  1193. get: function () {
  1194. return doAllItemsExist(this.settingsData.domains.cn, this.blockedDomains);
  1195. },
  1196. set: function (newValue) {
  1197. if (newValue) {
  1198. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.cn];
  1199. } else {
  1200. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.cn.includes(data));
  1201. }
  1202. }
  1203. },
  1204. RussiaIpSettings: {
  1205. get: function () {
  1206. return doAllItemsExist(this.settingsData.ips.ru, this.blockedIPs);
  1207. },
  1208. set: function (newValue) {
  1209. if (newValue) {
  1210. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.ru];
  1211. } else {
  1212. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.ru.includes(data));
  1213. }
  1214. }
  1215. },
  1216. RussiaDomainSettings: {
  1217. get: function () {
  1218. return doAllItemsExist(this.settingsData.domains.ru, this.blockedDomains);
  1219. },
  1220. set: function (newValue) {
  1221. if (newValue) {
  1222. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.ru];
  1223. } else {
  1224. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.ru.includes(data));
  1225. }
  1226. }
  1227. },
  1228. IRIpDirectSettings: {
  1229. get: function () {
  1230. return doAllItemsExist(this.settingsData.ips.ir, this.directIPs);
  1231. },
  1232. set: function (newValue) {
  1233. if (newValue) {
  1234. this.directIPs = [...this.directIPs, ...this.settingsData.ips.ir];
  1235. } else {
  1236. this.directIPs = this.directIPs.filter(data => !this.settingsData.ips.ir.includes(data));
  1237. }
  1238. }
  1239. },
  1240. IRDomainDirectSettings: {
  1241. get: function () {
  1242. return doAllItemsExist(this.settingsData.domains.ir, this.directDomains);
  1243. },
  1244. set: function (newValue) {
  1245. if (newValue) {
  1246. this.directDomains = [...this.directDomains, ...this.settingsData.domains.ir];
  1247. } else {
  1248. this.directDomains = this.directDomains.filter(data => !this.settingsData.domains.ir.includes(data));
  1249. }
  1250. }
  1251. },
  1252. ChinaIpDirectSettings: {
  1253. get: function () {
  1254. return doAllItemsExist(this.settingsData.ips.cn, this.directIPs);
  1255. },
  1256. set: function (newValue) {
  1257. if (newValue) {
  1258. this.directIPs = [...this.directIPs, ...this.settingsData.ips.cn];
  1259. } else {
  1260. this.directIPs = this.directIPs.filter(data => !this.settingsData.ips.cn.includes(data));
  1261. }
  1262. }
  1263. },
  1264. ChinaDomainDirectSettings: {
  1265. get: function () {
  1266. return doAllItemsExist(this.settingsData.domains.cn, this.directDomains);
  1267. },
  1268. set: function (newValue) {
  1269. if (newValue) {
  1270. this.directDomains = [...this.directDomains, ...this.settingsData.domains.cn];
  1271. } else {
  1272. this.directDomains = this.directDomains.filter(data => !this.settingsData.domains.cn.includes(data));
  1273. }
  1274. }
  1275. },
  1276. RussiaIpDirectSettings: {
  1277. get: function () {
  1278. return doAllItemsExist(this.settingsData.ips.ru, this.directIPs);
  1279. },
  1280. set: function (newValue) {
  1281. if (newValue) {
  1282. this.directIPs = [...this.directIPs, ...this.settingsData.ips.ru];
  1283. } else {
  1284. this.directIPs = this.directIPs.filter(data => !this.settingsData.ips.ru.includes(data));
  1285. }
  1286. }
  1287. },
  1288. RussiaDomainDirectSettings: {
  1289. get: function () {
  1290. return doAllItemsExist(this.settingsData.domains.ru, this.directDomains);
  1291. },
  1292. set: function (newValue) {
  1293. if (newValue) {
  1294. this.directDomains = [...this.directDomains, ...this.settingsData.domains.ru];
  1295. } else {
  1296. this.directDomains = this.directDomains.filter(data => !this.settingsData.domains.ru.includes(data));
  1297. }
  1298. }
  1299. },
  1300. GoogleWARPSettings: {
  1301. get: function () {
  1302. return doAllItemsExist(this.settingsData.domains.google, this.warpDomains);
  1303. },
  1304. set: function (newValue) {
  1305. if (newValue) {
  1306. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.google];
  1307. } else {
  1308. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.google.includes(data));
  1309. }
  1310. },
  1311. },
  1312. OpenAIWARPSettings: {
  1313. get: function () {
  1314. return doAllItemsExist(this.settingsData.domains.openai, this.warpDomains);
  1315. },
  1316. set: function (newValue) {
  1317. if (newValue) {
  1318. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.openai];
  1319. } else {
  1320. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.openai.includes(data));
  1321. }
  1322. },
  1323. },
  1324. NetflixWARPSettings: {
  1325. get: function () {
  1326. return doAllItemsExist(this.settingsData.domains.netflix, this.warpDomains);
  1327. },
  1328. set: function (newValue) {
  1329. if (newValue) {
  1330. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.netflix];
  1331. } else {
  1332. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.netflix.includes(data));
  1333. }
  1334. },
  1335. },
  1336. SpotifyWARPSettings: {
  1337. get: function () {
  1338. return doAllItemsExist(this.settingsData.domains.spotify, this.warpDomains);
  1339. },
  1340. set: function (newValue) {
  1341. if (newValue) {
  1342. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.spotify];
  1343. } else {
  1344. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.spotify.includes(data));
  1345. }
  1346. },
  1347. },
  1348. },
  1349. });
  1350. </script>
  1351. </body>
  1352. </html>