1
0

xray.html 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368
  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 == "direct");
  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 == "direct");
  966. if(freedomOutboundIndex == -1){
  967. newTemplateSettings.outbounds.push({protocol: "freedom", tag: "direct", settings: { "domainStrategy": newValue }});
  968. } else if (!newTemplateSettings.outbounds[freedomOutboundIndex].settings) {
  969. newTemplateSettings.outbounds[freedomOutboundIndex].settings = {"domainStrategy": newValue};
  970. } else {
  971. newTemplateSettings.outbounds[freedomOutboundIndex].settings.domainStrategy = newValue;
  972. }
  973. this.templateSettings = newTemplateSettings;
  974. }
  975. },
  976. routingStrategy: {
  977. get: function () {
  978. if (!this.templateSettings || !this.templateSettings.routing || !this.templateSettings.routing.domainStrategy) return "AsIs";
  979. return this.templateSettings.routing.domainStrategy;
  980. },
  981. set: function (newValue) {
  982. newTemplateSettings = this.templateSettings;
  983. newTemplateSettings.routing.domainStrategy = newValue;
  984. this.templateSettings = newTemplateSettings;
  985. }
  986. },
  987. blockedIPs: {
  988. get: function () {
  989. return this.templateRuleGetter({ outboundTag: "blocked", property: "ip" });
  990. },
  991. set: function (newValue) {
  992. this.templateRuleSetter({ outboundTag: "blocked", property: "ip", data: newValue });
  993. }
  994. },
  995. blockedDomains: {
  996. get: function () {
  997. return this.templateRuleGetter({ outboundTag: "blocked", property: "domain" });
  998. },
  999. set: function (newValue) {
  1000. this.templateRuleSetter({ outboundTag: "blocked", property: "domain", data: newValue });
  1001. }
  1002. },
  1003. blockedProtocols: {
  1004. get: function () {
  1005. return this.templateRuleGetter({ outboundTag: "blocked", property: "protocol" });
  1006. },
  1007. set: function (newValue) {
  1008. this.templateRuleSetter({ outboundTag: "blocked", property: "protocol", data: newValue });
  1009. }
  1010. },
  1011. directIPs: {
  1012. get: function () {
  1013. return this.templateRuleGetter({ outboundTag: "direct", property: "ip" });
  1014. },
  1015. set: function (newValue) {
  1016. this.templateRuleSetter({ outboundTag: "direct", property: "ip", data: newValue });
  1017. this.syncRulesWithOutbound("direct", this.directSettings);
  1018. }
  1019. },
  1020. directDomains: {
  1021. get: function () {
  1022. return this.templateRuleGetter({ outboundTag: "direct", property: "domain" });
  1023. },
  1024. set: function (newValue) {
  1025. this.templateRuleSetter({ outboundTag: "direct", property: "domain", data: newValue });
  1026. this.syncRulesWithOutbound("direct", this.directSettings);
  1027. }
  1028. },
  1029. ipv4Domains: {
  1030. get: function () {
  1031. return this.templateRuleGetter({ outboundTag: "IPv4", property: "domain" });
  1032. },
  1033. set: function (newValue) {
  1034. this.templateRuleSetter({ outboundTag: "IPv4", property: "domain", data: newValue });
  1035. this.syncRulesWithOutbound("IPv4", this.ipv4Settings);
  1036. }
  1037. },
  1038. warpDomains: {
  1039. get: function () {
  1040. return this.templateRuleGetter({ outboundTag: "WARP", property: "domain" });
  1041. },
  1042. set: function (newValue) {
  1043. this.templateRuleSetter({ outboundTag: "WARP", property: "domain", data: newValue });
  1044. this.syncRulesWithOutbound("WARP", this.warpSettings);
  1045. }
  1046. },
  1047. manualBlockedIPs: {
  1048. get: function () { return JSON.stringify(this.blockedIPs, null, 2); },
  1049. set: debounce(function (value) { this.blockedIPs = JSON.parse(value); }, 1000)
  1050. },
  1051. manualBlockedDomains: {
  1052. get: function () { return JSON.stringify(this.blockedDomains, null, 2); },
  1053. set: debounce(function (value) { this.blockedDomains = JSON.parse(value); }, 1000)
  1054. },
  1055. manualDirectIPs: {
  1056. get: function () { return JSON.stringify(this.directIPs, null, 2); },
  1057. set: debounce(function (value) { this.directIPs = JSON.parse(value); }, 1000)
  1058. },
  1059. manualDirectDomains: {
  1060. get: function () { return JSON.stringify(this.directDomains, null, 2); },
  1061. set: debounce(function (value) { this.directDomains = JSON.parse(value); }, 1000)
  1062. },
  1063. manualIPv4Domains: {
  1064. get: function () { return JSON.stringify(this.ipv4Domains, null, 2); },
  1065. set: debounce(function (value) { this.ipv4Domains = JSON.parse(value); }, 1000)
  1066. },
  1067. manualWARPDomains: {
  1068. get: function () { return JSON.stringify(this.warpDomains, null, 2); },
  1069. set: debounce(function (value) { this.warpDomains = JSON.parse(value); }, 1000)
  1070. },
  1071. torrentSettings: {
  1072. get: function () {
  1073. return doAllItemsExist(this.settingsData.protocols.bittorrent, this.blockedProtocols);
  1074. },
  1075. set: function (newValue) {
  1076. if (newValue) {
  1077. this.blockedProtocols = [...this.blockedProtocols, ...this.settingsData.protocols.bittorrent];
  1078. } else {
  1079. this.blockedProtocols = this.blockedProtocols.filter(data => !this.settingsData.protocols.bittorrent.includes(data));
  1080. }
  1081. },
  1082. },
  1083. privateIpSettings: {
  1084. get: function () {
  1085. return doAllItemsExist(this.settingsData.ips.local, this.blockedIPs);
  1086. },
  1087. set: function (newValue) {
  1088. if (newValue) {
  1089. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.local];
  1090. } else {
  1091. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.local.includes(data));
  1092. }
  1093. },
  1094. },
  1095. AdsSettings: {
  1096. get: function () {
  1097. return doAllItemsExist(this.settingsData.domains.ads, this.blockedDomains);
  1098. },
  1099. set: function (newValue) {
  1100. if (newValue) {
  1101. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.ads];
  1102. } else {
  1103. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.ads.includes(data));
  1104. }
  1105. },
  1106. },
  1107. SpeedTestSettings: {
  1108. get: function () {
  1109. return doAllItemsExist(this.settingsData.domains.speedtest, this.blockedDomains);
  1110. },
  1111. set: function (newValue) {
  1112. if (newValue) {
  1113. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.speedtest];
  1114. } else {
  1115. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.speedtest.includes(data));
  1116. }
  1117. },
  1118. },
  1119. familyProtectSettings: {
  1120. get: function () {
  1121. if (!this.templateSettings || !this.templateSettings.dns || !this.templateSettings.dns.servers) return false;
  1122. return doAllItemsExist(this.templateSettings.dns.servers, this.settingsData.familyProtectDNS.servers);
  1123. },
  1124. set: function (newValue) {
  1125. newTemplateSettings = this.templateSettings;
  1126. if (newValue) {
  1127. newTemplateSettings.dns = this.settingsData.familyProtectDNS;
  1128. } else {
  1129. delete newTemplateSettings.dns;
  1130. }
  1131. this.templateSettings = newTemplateSettings;
  1132. },
  1133. },
  1134. GoogleIPv4Settings: {
  1135. get: function () {
  1136. return doAllItemsExist(this.settingsData.domains.google, this.ipv4Domains);
  1137. },
  1138. set: function (newValue) {
  1139. if (newValue) {
  1140. this.ipv4Domains = [...this.ipv4Domains, ...this.settingsData.domains.google];
  1141. } else {
  1142. this.ipv4Domains = this.ipv4Domains.filter(data => !this.settingsData.domains.google.includes(data));
  1143. }
  1144. },
  1145. },
  1146. NetflixIPv4Settings: {
  1147. get: function () {
  1148. return doAllItemsExist(this.settingsData.domains.netflix, this.ipv4Domains);
  1149. },
  1150. set: function (newValue) {
  1151. if (newValue) {
  1152. this.ipv4Domains = [...this.ipv4Domains, ...this.settingsData.domains.netflix];
  1153. } else {
  1154. this.ipv4Domains = this.ipv4Domains.filter(data => !this.settingsData.domains.netflix.includes(data));
  1155. }
  1156. },
  1157. },
  1158. IRIpSettings: {
  1159. get: function () {
  1160. return doAllItemsExist(this.settingsData.ips.ir, this.blockedIPs);
  1161. },
  1162. set: function (newValue) {
  1163. if (newValue) {
  1164. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.ir];
  1165. } else {
  1166. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.ir.includes(data));
  1167. }
  1168. }
  1169. },
  1170. IRDomainSettings: {
  1171. get: function () {
  1172. return doAllItemsExist(this.settingsData.domains.ir, this.blockedDomains);
  1173. },
  1174. set: function (newValue) {
  1175. if (newValue) {
  1176. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.ir];
  1177. } else {
  1178. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.ir.includes(data));
  1179. }
  1180. }
  1181. },
  1182. ChinaIpSettings: {
  1183. get: function () {
  1184. return doAllItemsExist(this.settingsData.ips.cn, this.blockedIPs);
  1185. },
  1186. set: function (newValue) {
  1187. if (newValue) {
  1188. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.cn];
  1189. } else {
  1190. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.cn.includes(data));
  1191. }
  1192. }
  1193. },
  1194. ChinaDomainSettings: {
  1195. get: function () {
  1196. return doAllItemsExist(this.settingsData.domains.cn, this.blockedDomains);
  1197. },
  1198. set: function (newValue) {
  1199. if (newValue) {
  1200. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.cn];
  1201. } else {
  1202. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.cn.includes(data));
  1203. }
  1204. }
  1205. },
  1206. RussiaIpSettings: {
  1207. get: function () {
  1208. return doAllItemsExist(this.settingsData.ips.ru, this.blockedIPs);
  1209. },
  1210. set: function (newValue) {
  1211. if (newValue) {
  1212. this.blockedIPs = [...this.blockedIPs, ...this.settingsData.ips.ru];
  1213. } else {
  1214. this.blockedIPs = this.blockedIPs.filter(data => !this.settingsData.ips.ru.includes(data));
  1215. }
  1216. }
  1217. },
  1218. RussiaDomainSettings: {
  1219. get: function () {
  1220. return doAllItemsExist(this.settingsData.domains.ru, this.blockedDomains);
  1221. },
  1222. set: function (newValue) {
  1223. if (newValue) {
  1224. this.blockedDomains = [...this.blockedDomains, ...this.settingsData.domains.ru];
  1225. } else {
  1226. this.blockedDomains = this.blockedDomains.filter(data => !this.settingsData.domains.ru.includes(data));
  1227. }
  1228. }
  1229. },
  1230. IRIpDirectSettings: {
  1231. get: function () {
  1232. return doAllItemsExist(this.settingsData.ips.ir, this.directIPs);
  1233. },
  1234. set: function (newValue) {
  1235. if (newValue) {
  1236. this.directIPs = [...this.directIPs, ...this.settingsData.ips.ir];
  1237. } else {
  1238. this.directIPs = this.directIPs.filter(data => !this.settingsData.ips.ir.includes(data));
  1239. }
  1240. }
  1241. },
  1242. IRDomainDirectSettings: {
  1243. get: function () {
  1244. return doAllItemsExist(this.settingsData.domains.ir, this.directDomains);
  1245. },
  1246. set: function (newValue) {
  1247. if (newValue) {
  1248. this.directDomains = [...this.directDomains, ...this.settingsData.domains.ir];
  1249. } else {
  1250. this.directDomains = this.directDomains.filter(data => !this.settingsData.domains.ir.includes(data));
  1251. }
  1252. }
  1253. },
  1254. ChinaIpDirectSettings: {
  1255. get: function () {
  1256. return doAllItemsExist(this.settingsData.ips.cn, this.directIPs);
  1257. },
  1258. set: function (newValue) {
  1259. if (newValue) {
  1260. this.directIPs = [...this.directIPs, ...this.settingsData.ips.cn];
  1261. } else {
  1262. this.directIPs = this.directIPs.filter(data => !this.settingsData.ips.cn.includes(data));
  1263. }
  1264. }
  1265. },
  1266. ChinaDomainDirectSettings: {
  1267. get: function () {
  1268. return doAllItemsExist(this.settingsData.domains.cn, this.directDomains);
  1269. },
  1270. set: function (newValue) {
  1271. if (newValue) {
  1272. this.directDomains = [...this.directDomains, ...this.settingsData.domains.cn];
  1273. } else {
  1274. this.directDomains = this.directDomains.filter(data => !this.settingsData.domains.cn.includes(data));
  1275. }
  1276. }
  1277. },
  1278. RussiaIpDirectSettings: {
  1279. get: function () {
  1280. return doAllItemsExist(this.settingsData.ips.ru, this.directIPs);
  1281. },
  1282. set: function (newValue) {
  1283. if (newValue) {
  1284. this.directIPs = [...this.directIPs, ...this.settingsData.ips.ru];
  1285. } else {
  1286. this.directIPs = this.directIPs.filter(data => !this.settingsData.ips.ru.includes(data));
  1287. }
  1288. }
  1289. },
  1290. RussiaDomainDirectSettings: {
  1291. get: function () {
  1292. return doAllItemsExist(this.settingsData.domains.ru, this.directDomains);
  1293. },
  1294. set: function (newValue) {
  1295. if (newValue) {
  1296. this.directDomains = [...this.directDomains, ...this.settingsData.domains.ru];
  1297. } else {
  1298. this.directDomains = this.directDomains.filter(data => !this.settingsData.domains.ru.includes(data));
  1299. }
  1300. }
  1301. },
  1302. GoogleWARPSettings: {
  1303. get: function () {
  1304. return doAllItemsExist(this.settingsData.domains.google, this.warpDomains);
  1305. },
  1306. set: function (newValue) {
  1307. if (newValue) {
  1308. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.google];
  1309. } else {
  1310. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.google.includes(data));
  1311. }
  1312. },
  1313. },
  1314. OpenAIWARPSettings: {
  1315. get: function () {
  1316. return doAllItemsExist(this.settingsData.domains.openai, this.warpDomains);
  1317. },
  1318. set: function (newValue) {
  1319. if (newValue) {
  1320. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.openai];
  1321. } else {
  1322. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.openai.includes(data));
  1323. }
  1324. },
  1325. },
  1326. NetflixWARPSettings: {
  1327. get: function () {
  1328. return doAllItemsExist(this.settingsData.domains.netflix, this.warpDomains);
  1329. },
  1330. set: function (newValue) {
  1331. if (newValue) {
  1332. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.netflix];
  1333. } else {
  1334. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.netflix.includes(data));
  1335. }
  1336. },
  1337. },
  1338. SpotifyWARPSettings: {
  1339. get: function () {
  1340. return doAllItemsExist(this.settingsData.domains.spotify, this.warpDomains);
  1341. },
  1342. set: function (newValue) {
  1343. if (newValue) {
  1344. this.warpDomains = [...this.warpDomains, ...this.settingsData.domains.spotify];
  1345. } else {
  1346. this.warpDomains = this.warpDomains.filter(data => !this.settingsData.domains.spotify.includes(data));
  1347. }
  1348. },
  1349. },
  1350. },
  1351. });
  1352. </script>
  1353. </body>
  1354. </html>