setting.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. {{template "head" .}}
  4. <style>
  5. @media (min-width: 769px) {
  6. .ant-layout-content {
  7. margin: 24px 16px;
  8. }
  9. }
  10. .ant-col-sm-24 {
  11. margin-top: 10px;
  12. }
  13. .ant-tabs-bar {
  14. margin: 0;
  15. }
  16. .ant-list-item {
  17. display: block;
  18. }
  19. :not(.ant-card-dark)>.ant-tabs-top-bar {
  20. background: white;
  21. }
  22. </style>
  23. <body>
  24. <a-layout id="app" v-cloak>
  25. {{ template "commonSider" . }}
  26. <a-layout id="content-layout" :style="siderDrawer.isDarkTheme ? bgDarkStyle : ''">
  27. <a-layout-content>
  28. <a-spin :spinning="spinning" :delay="500" tip="loading">
  29. <a-space direction="vertical">
  30. <a-space direction="horizontal">
  31. <a-button type="primary" :disabled="saveBtnDisable" @click="updateAllSetting">{{ i18n "pages.setting.save" }}</a-button>
  32. <a-button type="danger" :disabled="!saveBtnDisable" @click="restartPanel">{{ i18n "pages.setting.restartPanel" }}</a-button>
  33. </a-space>
  34. <a-tabs default-active-key="1" :class="siderDrawer.isDarkTheme ? darkClass : ''">
  35. <a-tab-pane key="1" tab='{{ i18n "pages.setting.panelConfig"}}'>
  36. <a-list item-layout="horizontal" :style="siderDrawer.isDarkTheme ? 'color: hsla(0,0%,100%,.65);': 'background: white;'">
  37. <setting-list-item type="text" title='{{ i18n "pages.setting.panelListeningIP"}}' desc='{{ i18n "pages.setting.panelListeningIPDesc"}}' v-model="allSetting.webListen"></setting-list-item>
  38. <setting-list-item type="text" title='{{ i18n "pages.setting.panelPort"}}' desc='{{ i18n "pages.setting.panelPortDesc"}}' v-model.number="allSetting.webPort"></setting-list-item>
  39. <setting-list-item type="text" title='{{ i18n "pages.setting.publicKeyPath"}}' desc='{{ i18n "pages.setting.publicKeyPathDesc"}}' v-model="allSetting.webCertFile"></setting-list-item>
  40. <setting-list-item type="text" title='{{ i18n "pages.setting.privateKeyPath"}}' desc='{{ i18n "pages.setting.privateKeyPathDesc"}}' v-model="allSetting.webKeyFile"></setting-list-item>
  41. <setting-list-item type="text" title='{{ i18n "pages.setting.panelUrlPath"}}' desc='{{ i18n "pages.setting.panelUrlPathDesc"}}' v-model="allSetting.webBasePath"></setting-list-item>
  42. <a-list-item>
  43. <a-row style="padding: 20px">
  44. <a-col :lg="24" :xl="12">
  45. <a-list-item-meta title="Language"/>
  46. </a-col>
  47. <a-col :lg="24" :xl="12">
  48. <temlate>
  49. <a-select
  50. ref="selectLang"
  51. v-model="lang"
  52. @change="setLang(lang)"
  53. :dropdown-class-name="siderDrawer.isDarkTheme ? 'ant-card-dark' : ''"
  54. style="width: 100%"
  55. >
  56. <a-select-option :value="l.value" :label="l.value" v-for="l in supportLangs">
  57. <span role="img" aria-label="l.name" v-text="l.icon"></span>
  58. &nbsp;&nbsp;<span v-text="l.name"></span>
  59. </a-select-option>
  60. </a-select>
  61. </temlate>
  62. </a-col>
  63. </a-row>
  64. </a-list-item>
  65. </a-list>
  66. </a-tab-pane>
  67. <a-tab-pane key="2" tab='{{ i18n "pages.setting.userSetting"}}'>
  68. <a-form :style="siderDrawer.isDarkTheme ? 'color: hsla(0,0%,100%,.65); padding: 20px;': 'background: white; padding: 20px;'">
  69. <a-form-item label='{{ i18n "pages.setting.oldUsername"}}'>
  70. <a-input v-model="user.oldUsername" style="max-width: 300px"></a-input>
  71. </a-form-item>
  72. <a-form-item label='{{ i18n "pages.setting.currentPassword"}}'>
  73. <a-input type="password" v-model="user.oldPassword"
  74. style="max-width: 300px"></a-input>
  75. </a-form-item>
  76. <a-form-item label='{{ i18n "pages.setting.newUsername"}}'>
  77. <a-input v-model="user.newUsername" style="max-width: 300px"></a-input>
  78. </a-form-item>
  79. <a-form-item label='{{ i18n "pages.setting.newPassword"}}'>
  80. <a-input type="password" v-model="user.newPassword"
  81. style="max-width: 300px"></a-input>
  82. </a-form-item>
  83. <a-form-item>
  84. <!-- <a-button type="primary" @click="updateUser">Revise</a-button>-->
  85. <a-button type="primary" @click="updateUser">{{ i18n "confirm" }}</a-button>
  86. </a-form-item>
  87. </a-form>
  88. </a-tab-pane>
  89. <a-tab-pane key="3" tab='{{ i18n "pages.setting.xrayConfiguration"}}'>
  90. <a-list item-layout="horizontal" :style="siderDrawer.isDarkTheme ? 'color: hsla(0,0%,100%,.65);': 'background: white;'">
  91. <setting-list-item type="switch" title='{{ i18n "pages.setting.xrayConfigTorrent"}}' desc='{{ i18n "pages.setting.xrayConfigTorrentDesc"}}' v-model="torrentSettings"></setting-list-item>
  92. <setting-list-item type="switch" title='{{ i18n "pages.setting.xrayConfigPrivateIp"}}' desc='{{ i18n "pages.setting.xrayConfigPrivateIpDesc"}}' v-model="privateIpSettings"></setting-list-item>
  93. <a-divider>{{ i18n "pages.setting.advancedTemplate"}}</a-divider>
  94. <a-collapse>
  95. <a-collapse-panel header="{{ i18n "pages.setting.xrayConfigInbounds"}}">
  96. <setting-list-item type="textarea" title='{{ i18n "pages.setting.xrayConfigInbounds"}}' desc='{{ i18n "pages.setting.xrayConfigInboundsDesc"}}' v-model ="inboundSettings"></setting-list-item>
  97. </a-collapse-panel>
  98. <a-collapse-panel header="{{ i18n "pages.setting.xrayConfigOutbounds"}}">
  99. <setting-list-item type="textarea" title='{{ i18n "pages.setting.xrayConfigOutbounds"}}' desc='{{ i18n "pages.setting.xrayConfigOutboundsDesc"}}' v-model ="outboundSettings"></setting-list-item>
  100. </a-collapse-panel>
  101. <a-collapse-panel header="{{ i18n "pages.setting.xrayConfigRoutings"}}">
  102. <setting-list-item type="textarea" title='{{ i18n "pages.setting.xrayConfigRoutings"}}' desc='{{ i18n "pages.setting.xrayConfigRoutingsDesc"}}' v-model ="routingRuleSettings"></setting-list-item>
  103. </a-collapse-panel>
  104. </a-collapse>
  105. <a-divider>{{ i18n "pages.setting.completeTemplate"}}</a-divider>
  106. <setting-list-item type="textarea" title='{{ i18n "pages.setting.xrayConfigTemplate"}}' desc='{{ i18n "pages.setting.xrayConfigTemplateDesc"}}' v-model="allSetting.xrayTemplateConfig"></setting-list-item>
  107. </a-list>
  108. </a-tab-pane>
  109. <a-tab-pane key="4" tab='{{ i18n "pages.setting.TGReminder"}}'>
  110. <a-list item-layout="horizontal" :style="siderDrawer.isDarkTheme ? 'color: hsla(0,0%,100%,.65);': 'background: white;'">
  111. <setting-list-item type="switch" title='{{ i18n "pages.setting.telegramBotEnable" }}' desc='{{ i18n "pages.setting.telegramBotEnableDesc" }}' v-model="allSetting.tgBotEnable"></setting-list-item>
  112. <setting-list-item type="text" title='{{ i18n "pages.setting.telegramToken"}}' desc='{{ i18n "pages.setting.telegramTokenDesc"}}' v-model="allSetting.tgBotToken"></setting-list-item>
  113. <setting-list-item type="number" title='{{ i18n "pages.setting.telegramChatId"}}' desc='{{ i18n "pages.setting.telegramChatIdDesc"}}' v-model="allSetting.tgBotChatId"></setting-list-item>
  114. <setting-list-item type="text" title='{{ i18n "pages.setting.telegramNotifyTime"}}' desc='{{ i18n "pages.setting.telegramNotifyTimeDesc"}}' v-model="allSetting.tgRunTime"></setting-list-item>
  115. <setting-list-item type="switch" title='{{ i18n "pages.setting.tgNotifyBackup" }}' desc='{{ i18n "pages.setting.tgNotifyBackupDesc" }}' v-model="allSetting.tgBotBackup"></setting-list-item>
  116. <setting-list-item type="number" title='{{ i18n "pages.setting.tgNotifyExpireTimeDiff" }}' desc='{{ i18n "pages.setting.tgNotifyExpireTimeDiffDesc" }}' v-model="allSetting.tgExpireDiff" :min="0"></setting-list-item>
  117. <setting-list-item type="number" title='{{ i18n "pages.setting.tgNotifyTrafficDiff" }}' desc='{{ i18n "pages.setting.tgNotifyTrafficDiffDesc" }}' v-model="allSetting.tgTrafficDiff" :min="0"></setting-list-item>
  118. <setting-list-item type="number" title='{{ i18n "pages.setting.tgNotifyCpu" }}' desc='{{ i18n "pages.setting.tgNotifyCpuDesc" }}' v-model="allSetting.tgCpu" :min="0" :max="100"></setting-list-item>
  119. </a-list>
  120. </a-tab-pane>
  121. <a-tab-pane key="5" tab='{{ i18n "pages.setting.otherSetting"}}'>
  122. <a-list item-layout="horizontal" :style="siderDrawer.isDarkTheme ? 'color: hsla(0,0%,100%,.65);': 'background: white;'">
  123. <setting-list-item type="text" title='{{ i18n "pages.setting.timeZonee"}}' desc='{{ i18n "pages.setting.timeZoneDesc"}}' v-model="allSetting.timeLocation"></setting-list-item>
  124. </a-list>
  125. </a-tab-pane>
  126. </a-tabs>
  127. </a-space>
  128. </a-spin>
  129. </a-layout-content>
  130. </a-layout>
  131. </a-layout>
  132. {{template "js" .}}
  133. {{template "component/setting"}}
  134. <script>
  135. const app = new Vue({
  136. delimiters: ['[[', ']]'],
  137. el: '#app',
  138. data: {
  139. siderDrawer,
  140. spinning: false,
  141. oldAllSetting: new AllSetting(),
  142. allSetting: new AllSetting(),
  143. saveBtnDisable: true,
  144. user: {},
  145. lang : getLang()
  146. },
  147. methods: {
  148. loading(spinning = true) {
  149. this.spinning = spinning;
  150. },
  151. async getAllSetting() {
  152. this.loading(true);
  153. const msg = await HttpUtil.post("/xui/setting/all");
  154. this.loading(false);
  155. if (msg.success) {
  156. this.oldAllSetting = new AllSetting(msg.obj);
  157. this.allSetting = new AllSetting(msg.obj);
  158. this.saveBtnDisable = true;
  159. }
  160. },
  161. async updateAllSetting() {
  162. this.loading(true);
  163. const msg = await HttpUtil.post("/xui/setting/update", this.allSetting);
  164. this.loading(false);
  165. if (msg.success) {
  166. await this.getAllSetting();
  167. }
  168. },
  169. async updateUser() {
  170. this.loading(true);
  171. const msg = await HttpUtil.post("/xui/setting/updateUser", this.user);
  172. this.loading(false);
  173. if (msg.success) {
  174. this.user = {};
  175. }
  176. },
  177. async restartPanel() {
  178. await new Promise(resolve => {
  179. this.$confirm({
  180. title: '{{ i18n "pages.setting.restartPanel" }}',
  181. content: '{{ i18n "pages.setting.restartPanelDesc" }}',
  182. okText: '{{ i18n "sure" }}',
  183. cancelText: '{{ i18n "cancel" }}',
  184. onOk: () => resolve(),
  185. });
  186. });
  187. this.loading(true);
  188. const msg = await HttpUtil.post("/xui/setting/restartPanel");
  189. this.loading(false);
  190. if (msg.success) {
  191. this.loading(true);
  192. await PromiseUtil.sleep(5000);
  193. location.reload();
  194. }
  195. }
  196. },
  197. async mounted() {
  198. await this.getAllSetting();
  199. while (true) {
  200. await PromiseUtil.sleep(1000);
  201. this.saveBtnDisable = this.oldAllSetting.equals(this.allSetting);
  202. }
  203. },
  204. computed: {
  205. templateSettings: {
  206. get: function () { return this.allSetting.xrayTemplateConfig ? JSON.parse(this.allSetting.xrayTemplateConfig) : null ; },
  207. set: function (newValue) { this.allSetting.xrayTemplateConfig = JSON.stringify(newValue, null, 2) },
  208. },
  209. inboundSettings: {
  210. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.inbounds, null, 2) : null; },
  211. set: function (newValue) {
  212. newTemplateSettings = this.templateSettings;
  213. newTemplateSettings.inbounds = JSON.parse(newValue)
  214. this.templateSettings = newTemplateSettings
  215. },
  216. },
  217. outboundSettings: {
  218. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.outbounds, null, 2) : null; },
  219. set: function (newValue) {
  220. newTemplateSettings = this.templateSettings;
  221. newTemplateSettings.outbounds = JSON.parse(newValue)
  222. this.templateSettings = newTemplateSettings
  223. },
  224. },
  225. routingRuleSettings: {
  226. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.routing.rules, null, 2) : null; },
  227. set: function (newValue) {
  228. newTemplateSettings = this.templateSettings;
  229. newTemplateSettings.routing.rules = JSON.parse(newValue)
  230. this.templateSettings = newTemplateSettings
  231. },
  232. },
  233. torrentSettings: {
  234. get: function () {
  235. torrentFilter = false
  236. if(this.templateSettings != null){
  237. this.templateSettings.routing.rules.forEach(routingRule => {
  238. if(routingRule.hasOwnProperty("protocol")){
  239. if (routingRule.protocol[0] === "bittorrent" && routingRule.outboundTag == "blocked"){
  240. torrentFilter = true
  241. }
  242. }
  243. });
  244. }
  245. return torrentFilter
  246. },
  247. set: function (newValue) {
  248. newTemplateSettings = JSON.parse(this.allSetting.xrayTemplateConfig);
  249. if (newValue){
  250. newTemplateSettings.routing.rules.push(JSON.parse("{\"outboundTag\": \"blocked\",\"protocol\": [\"bittorrent\"],\"type\": \"field\"}"))
  251. }
  252. else {
  253. newTemplateSettings.routing.rules = [];
  254. this.templateSettings.routing.rules.forEach(routingRule => {
  255. if (routingRule.hasOwnProperty('protocol')){
  256. if (routingRule.protocol[0] === "bittorrent" && routingRule.outboundTag == "blocked"){
  257. return;
  258. }
  259. }
  260. newTemplateSettings.routing.rules.push(routingRule);
  261. });
  262. }
  263. this.templateSettings = newTemplateSettings
  264. },
  265. },
  266. privateIpSettings: {
  267. get: function () {
  268. localIpFilter = false
  269. if(this.templateSettings != null){
  270. this.templateSettings.routing.rules.forEach(routingRule => {
  271. if(routingRule.hasOwnProperty("ip")){
  272. if (routingRule.ip[0] === "geoip:private" && routingRule.outboundTag == "blocked"){
  273. localIpFilter = true
  274. }
  275. }
  276. });
  277. }
  278. return localIpFilter
  279. },
  280. set: function (newValue) {
  281. newTemplateSettings = JSON.parse(this.allSetting.xrayTemplateConfig);
  282. if (newValue){
  283. newTemplateSettings.routing.rules.push(JSON.parse("{\"outboundTag\": \"blocked\",\"ip\": [\"geoip:private\"],\"type\": \"field\"}"))
  284. }
  285. else {
  286. newTemplateSettings.routing.rules = [];
  287. this.templateSettings.routing.rules.forEach(routingRule => {
  288. if (routingRule.hasOwnProperty('ip')){
  289. if (routingRule.ip[0] === "geoip:private" && routingRule.outboundTag == "blocked"){
  290. return;
  291. }
  292. }
  293. newTemplateSettings.routing.rules.push(routingRule);
  294. });
  295. }
  296. this.templateSettings = newTemplateSettings
  297. },
  298. },
  299. }
  300. });
  301. </script>
  302. </body>
  303. </html>