xray.html 78 KB

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