settings.html 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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. @media (max-width: 768px) {
  11. .ant-tabs-nav .ant-tabs-tab {
  12. margin: 0;
  13. padding: 12px .5rem;
  14. }
  15. }
  16. .ant-tabs-bar {
  17. margin: 0;
  18. }
  19. .ant-list-item {
  20. display: block;
  21. }
  22. .alert-msg {
  23. color: rgb(194, 117, 18);
  24. font-weight: normal;
  25. font-size: 16px;
  26. padding: .5rem 1rem;
  27. text-align: center;
  28. background: rgb(255 145 0 / 15%);
  29. margin: 1.5rem 2.5rem 0rem 2.5rem;
  30. border-radius: .5rem;
  31. transition: all 0.5s;
  32. animation: signal 3s cubic-bezier(0.18, 0.89, 0.32, 1.28) infinite;
  33. }
  34. .alert-msg:hover {
  35. cursor: default;
  36. transition-duration: .3s;
  37. animation: signal 0.9s ease infinite;
  38. }
  39. @keyframes signal{
  40. 0%{
  41. box-shadow: 0 0 0 0 rgba(194, 118, 18, 0.5);
  42. }
  43. 50%{
  44. box-shadow: 0 0 0 6px rgba(0 ,0,0,0);
  45. }
  46. 100%{
  47. box-shadow: 0 0 0 6px rgba(0 ,0,0,0);
  48. }
  49. }
  50. .alert-msg > i {
  51. color: inherit;
  52. font-size: 24px;
  53. }
  54. .collapse-title {
  55. color: inherit;
  56. font-weight: bold;
  57. font-size: 18px;
  58. padding: 10px 20px;
  59. border-bottom: 2px solid;
  60. }
  61. .collapse-title > i {
  62. color: inherit;
  63. font-size: 24px;
  64. }
  65. </style>
  66. <body>
  67. <a-layout id="app" v-cloak :class="themeSwitcher.currentTheme">
  68. {{ template "commonSider" . }}
  69. <a-layout id="content-layout">
  70. <a-layout-content>
  71. <a-spin :spinning="spinning" :delay="500" tip='{{ i18n "loading"}}'>
  72. <transition name="list" appear>
  73. <a-alert type="error" v-if="confAlerts.length>0" style="margin: 10px 5px;"
  74. message='{{ i18n "secAlertTitle" }}'
  75. color="red"
  76. show-icon
  77. closable
  78. >
  79. <template slot="description">
  80. <b>{{ i18n "secAlertConf" }}</b>
  81. <ul><li v-for="a in confAlerts">[[ a ]]</li></ul>
  82. </template>
  83. </a-alert>
  84. </transition>
  85. <a-space direction="vertical">
  86. <a-card hoverable style="margin-bottom: .5rem; overflow-x: hidden;">
  87. <a-row style="display: flex; flex-wrap: wrap; align-items: center;">
  88. <a-col :xs="24" :sm="10" style="padding: 4px;">
  89. <a-space direction="horizontal">
  90. <a-button type="primary" :disabled="saveBtnDisable" @click="updateAllSetting">{{ i18n "pages.settings.save" }}</a-button>
  91. <a-button type="danger" :disabled="!saveBtnDisable" @click="restartPanel">{{ i18n "pages.settings.restartPanel" }}</a-button>
  92. </a-space>
  93. </a-col>
  94. <a-col :xs="24" :sm="14">
  95. <template>
  96. <div>
  97. <a-back-top :target="() => document.getElementById('content-layout')" visibility-height="200">
  98. </a-back-top>
  99. <a-alert type="warning" style="float: right; width: fit-content"
  100. message='{{ i18n "pages.settings.infoDesc" }}'
  101. show-icon
  102. >
  103. </div>
  104. </template>
  105. </a-col>
  106. </a-row>
  107. </a-card>
  108. <a-tabs default-active-key="1">
  109. <a-tab-pane key="1" tab='{{ i18n "pages.settings.panelSettings"}}'>
  110. <a-list item-layout="horizontal">
  111. <a-list-item>
  112. <a-row style="padding: 20px">
  113. <a-col :lg="24" :xl="12">
  114. <a-list-item-meta title='{{ i18n "pages.settings.remarkModel"}}'>
  115. <template slot="description">{{ i18n "pages.settings.sampleRemark"}}: <i>#[[ remarkSample ]]</i></template>
  116. </a-list-item-meta>
  117. </a-col>
  118. <a-col :lg="24" :xl="12">
  119. <a-input-group style="width: 100%;">
  120. <a-select style="padding-right: .5rem; min-width: 80%; width: auto;"
  121. mode="multiple"
  122. v-model="remarkModel"
  123. :dropdown-class-name="themeSwitcher.currentTheme">
  124. <a-select-option v-for="(value, key) in remarkModels" :value="key">[[ value ]]</a-select-option>
  125. </a-select>
  126. <a-select style="width: 20%;" v-model="remarkSeparator" :dropdown-class-name="themeSwitcher.currentTheme">
  127. <a-select-option v-for="key in remarkSeparators" :value="key">[[ key ]]</a-select-option>
  128. </a-select>
  129. </a-input-group>
  130. </a-col>
  131. </a-row>
  132. </a-list-item>
  133. <setting-list-item type="text" title='{{ i18n "pages.settings.panelListeningIP"}}' desc='{{ i18n "pages.settings.panelListeningIPDesc"}}' v-model="allSetting.webListen"></setting-list-item>
  134. <setting-list-item type="text" title='{{ i18n "pages.settings.panelListeningDomain"}}' desc='{{ i18n "pages.settings.panelListeningDomainDesc"}}' v-model="allSetting.webDomain"></setting-list-item>
  135. <setting-list-item type="number" title='{{ i18n "pages.settings.panelPort"}}' desc='{{ i18n "pages.settings.panelPortDesc"}}' v-model="allSetting.webPort" :min="1" :max="65531"></setting-list-item>
  136. <setting-list-item type="text" title='{{ i18n "pages.settings.publicKeyPath"}}' desc='{{ i18n "pages.settings.publicKeyPathDesc"}}' v-model="allSetting.webCertFile"></setting-list-item>
  137. <setting-list-item type="text" title='{{ i18n "pages.settings.privateKeyPath"}}' desc='{{ i18n "pages.settings.privateKeyPathDesc"}}' v-model="allSetting.webKeyFile"></setting-list-item>
  138. <setting-list-item type="text" title='{{ i18n "pages.settings.panelUrlPath"}}' desc='{{ i18n "pages.settings.panelUrlPathDesc"}}' v-model="allSetting.webBasePath"></setting-list-item>
  139. <setting-list-item type="number" title='{{ i18n "pages.settings.sessionMaxAge" }}' desc='{{ i18n "pages.settings.sessionMaxAgeDesc" }}' v-model="allSetting.sessionMaxAge" :min="0"></setting-list-item>
  140. <setting-list-item type="number" title='{{ i18n "pages.settings.pageSize" }}' desc='{{ i18n "pages.settings.pageSizeDesc" }}' v-model="allSetting.pageSize" :min="0" :step="5"></setting-list-item>
  141. <setting-list-item type="number" title='{{ i18n "pages.settings.expireTimeDiff" }}' desc='{{ i18n "pages.settings.expireTimeDiffDesc" }}' v-model="allSetting.expireDiff" :min="0"></setting-list-item>
  142. <setting-list-item type="number" title='{{ i18n "pages.settings.trafficDiff" }}' desc='{{ i18n "pages.settings.trafficDiffDesc" }}' v-model="allSetting.trafficDiff" :min="0"></setting-list-item>
  143. <setting-list-item type="text" title='{{ i18n "pages.settings.timeZone"}}' desc='{{ i18n "pages.settings.timeZoneDesc"}}' v-model="allSetting.timeLocation"></setting-list-item>
  144. <a-list-item>
  145. <a-row style="padding: 20px">
  146. <a-col :lg="24" :xl="12">
  147. <a-list-item-meta title='{{ i18n "pages.settings.datepicker"}}'>
  148. <template slot="description">{{ i18n "pages.settings.datepickerDescription"}}</template>
  149. </a-list-item-meta>
  150. </a-col>
  151. <a-col :lg="24" :xl="12">
  152. <template>
  153. <a-select style="width: 100%"
  154. :dropdown-class-name="themeSwitcher.currentTheme"
  155. v-model="datepicker">
  156. <a-select-option v-for="item in datepickerList" :value="item.value">
  157. <span v-text="item.name"></span>
  158. </a-select-option>
  159. </a-select>
  160. </template>
  161. </a-col>
  162. </a-row>
  163. </a-list-item>
  164. <a-list-item>
  165. <a-row style="padding: 20px">
  166. <a-col :lg="24" :xl="12">
  167. <a-list-item-meta title="Language" />
  168. </a-col>
  169. <a-col :lg="24" :xl="12">
  170. <template>
  171. <a-select
  172. ref="selectLang"
  173. v-model="lang"
  174. @change="setLang(lang)"
  175. :dropdown-class-name="themeSwitcher.currentTheme"
  176. style="width: 100%"
  177. >
  178. <a-select-option :value="l.value" :label="l.value" v-for="l in supportLangs">
  179. <span role="img" :aria-label="l.name" v-text="l.icon"></span>
  180. &nbsp;&nbsp;<span v-text="l.name"></span>
  181. </a-select-option>
  182. </a-select>
  183. </template>
  184. </a-col>
  185. </a-row>
  186. </a-list-item>
  187. </a-list>
  188. </a-tab-pane>
  189. <a-tab-pane key="2" tab='{{ i18n "pages.settings.securitySettings"}}' style="padding: 20px;">
  190. <a-divider>{{ i18n "pages.settings.security.admin"}}</a-divider>
  191. <a-form layout="horizontal" :colon="false" style="float: left; margin: 10px 0;" :label-col="{ md: {span:10} }" :wrapper-col="{ md: {span:14} }">
  192. <a-form-item label='{{ i18n "pages.settings.oldUsername"}}'>
  193. <a-input autocomplete="username" v-model="user.oldUsername"></a-input>
  194. </a-form-item>
  195. <a-form-item label='{{ i18n "pages.settings.currentPassword"}}'>
  196. <password-input autocomplete="current-password" v-model="user.oldPassword"></password-input>
  197. </a-form-item>
  198. <a-form-item label='{{ i18n "pages.settings.newUsername"}}'>
  199. <a-input v-model="user.newUsername"></a-input>
  200. </a-form-item>
  201. <a-form-item label='{{ i18n "pages.settings.newPassword"}}'>
  202. <password-input autocomplete="new-password" v-model="user.newPassword"></password-input>
  203. </a-form-item>
  204. <a-form-item label=" ">
  205. <a-button type="primary" @click="updateUser">{{ i18n "confirm" }}</a-button>
  206. </a-form-item>
  207. </a-form>
  208. <a-divider>{{ i18n "pages.settings.security.secret"}}</a-divider>
  209. <a-form style="padding: 20px;">
  210. <a-list-item>
  211. <a-row>
  212. <a-col :lg="24" :xl="12">
  213. <a-list-item-meta title='{{ i18n "pages.settings.security.loginSecurity" }}' description='{{ i18n "pages.settings.security.loginSecurityDesc" }}' />
  214. </a-col>
  215. <a-col :lg="24" :xl="12">
  216. <template>
  217. <a-switch @change="toggleToken(allSetting.secretEnable)" v-model="allSetting.secretEnable"></a-switch>
  218. <a-icon style="margin-left: 1rem;" v-if="allSetting.secretEnable" :spin="this.changeSecret" type="sync" @click="getNewSecret"></a-icon>
  219. </template>
  220. </a-col>
  221. </a-row>
  222. </a-list-item>
  223. <a-list-item>
  224. <a-row>
  225. <a-col :lg="24" :xl="12">
  226. <a-list-item-meta title='{{ i18n "pages.settings.security.secretToken" }}' description='{{ i18n "pages.settings.security.secretTokenDesc" }}' />
  227. </a-col>
  228. <a-col :lg="24" :xl="12">
  229. <template>
  230. <a-textarea type="text" :disabled="!allSetting.secretEnable" v-model="user.loginSecret"></a-textarea>
  231. </template>
  232. </a-col>
  233. </a-row>
  234. </a-list-item>
  235. <a-button type="primary" :loading="this.changeSecret" @click="updateSecret">{{ i18n "confirm" }}</a-button>
  236. </a-form>
  237. </a-tab-pane>
  238. <a-tab-pane key="3" tab='{{ i18n "pages.settings.TGBotSettings"}}'>
  239. <a-list item-layout="horizontal">
  240. <setting-list-item type="switch" title='{{ i18n "pages.settings.telegramBotEnable" }}' desc='{{ i18n "pages.settings.telegramBotEnableDesc" }}' v-model="allSetting.tgBotEnable"></setting-list-item>
  241. <setting-list-item type="text" title='{{ i18n "pages.settings.telegramToken"}}' desc='{{ i18n "pages.settings.telegramTokenDesc"}}' v-model="allSetting.tgBotToken"></setting-list-item>
  242. <setting-list-item type="text" title='{{ i18n "pages.settings.telegramChatId"}}' desc='{{ i18n "pages.settings.telegramChatIdDesc"}}' v-model="allSetting.tgBotChatId"></setting-list-item>
  243. <setting-list-item type="text" title='{{ i18n "pages.settings.telegramNotifyTime"}}' desc='{{ i18n "pages.settings.telegramNotifyTimeDesc"}}' v-model="allSetting.tgRunTime"></setting-list-item>
  244. <setting-list-item type="switch" title='{{ i18n "pages.settings.tgNotifyBackup" }}' desc='{{ i18n "pages.settings.tgNotifyBackupDesc" }}' v-model="allSetting.tgBotBackup"></setting-list-item>
  245. <setting-list-item type="switch" title='{{ i18n "pages.settings.tgNotifyLogin" }}' desc='{{ i18n "pages.settings.tgNotifyLoginDesc" }}' v-model="allSetting.tgBotLoginNotify"></setting-list-item>
  246. <setting-list-item type="number" title='{{ i18n "pages.settings.tgNotifyCpu" }}' desc='{{ i18n "pages.settings.tgNotifyCpuDesc" }}' v-model="allSetting.tgCpu" :min="0" :max="100"></setting-list-item>
  247. <setting-list-item type="text" title='{{ i18n "pages.settings.telegramProxy"}}' desc='{{ i18n "pages.settings.telegramProxyDesc"}}' v-model="allSetting.tgBotProxy" placeholder="socks5://user:pass@host:port"></setting-list-item>
  248. <a-list-item>
  249. <a-row style="padding: 20px">
  250. <a-col :lg="24" :xl="12">
  251. <a-list-item-meta title="Telegram Bot Language" />
  252. </a-col>
  253. <a-col :lg="24" :xl="12">
  254. <template>
  255. <a-select
  256. ref="selectBotLang"
  257. v-model="allSetting.tgLang"
  258. :dropdown-class-name="themeSwitcher.currentTheme"
  259. style="width: 100%">
  260. <a-select-option :value="l.value" :label="l.value" v-for="l in supportLangs">
  261. <span role="img" :aria-label="l.name" v-text="l.icon"></span>
  262. &nbsp;&nbsp;<span v-text="l.name"></span>
  263. </a-select-option>
  264. </a-select>
  265. </template>
  266. </a-col>
  267. </a-row>
  268. </a-list-item>
  269. </a-list>
  270. </a-tab-pane>
  271. <a-tab-pane key="4" tab='{{ i18n "pages.settings.subSettings" }}'>
  272. <a-list item-layout="horizontal">
  273. <setting-list-item type="switch" title='{{ i18n "pages.settings.subEnable"}}' desc='{{ i18n "pages.settings.subEnableDesc"}}' v-model="allSetting.subEnable"></setting-list-item>
  274. <setting-list-item type="switch" title='{{ i18n "pages.settings.subEncrypt"}}' desc='{{ i18n "pages.settings.subEncryptDesc"}}' v-model="allSetting.subEncrypt"></setting-list-item>
  275. <setting-list-item type="switch" title='{{ i18n "pages.settings.subShowInfo"}}' desc='{{ i18n "pages.settings.subShowInfoDesc"}}' v-model="allSetting.subShowInfo"></setting-list-item>
  276. <setting-list-item type="text" title='{{ i18n "pages.settings.subListen"}}' desc='{{ i18n "pages.settings.subListenDesc"}}' v-model="allSetting.subListen"></setting-list-item>
  277. <setting-list-item type="text" title='{{ i18n "pages.settings.subDomain"}}' desc='{{ i18n "pages.settings.subDomainDesc"}}' v-model="allSetting.subDomain"></setting-list-item>
  278. <setting-list-item type="number" title='{{ i18n "pages.settings.subPort"}}' desc='{{ i18n "pages.settings.subPortDesc"}}' v-model.number="allSetting.subPort" :min="1" :max="65531"></setting-list-item>
  279. <setting-list-item type="text" title='{{ i18n "pages.settings.subPath"}}' desc='{{ i18n "pages.settings.subPathDesc"}}' v-model="allSetting.subPath"></setting-list-item>
  280. <setting-list-item type="text" title='{{ i18n "pages.settings.subCertPath"}}' desc='{{ i18n "pages.settings.subCertPathDesc"}}' v-model="allSetting.subCertFile"></setting-list-item>
  281. <setting-list-item type="text" title='{{ i18n "pages.settings.subKeyPath"}}' desc='{{ i18n "pages.settings.subKeyPathDesc"}}' v-model="allSetting.subKeyFile"></setting-list-item>
  282. <setting-list-item type="text" title='{{ i18n "pages.settings.subURI"}}' desc='{{ i18n "pages.settings.subURIDesc"}}' v-model="allSetting.subURI" placeholder="(http|https)://domain[:port]/path/"></setting-list-item>
  283. <setting-list-item type="number" title='{{ i18n "pages.settings.subUpdates"}}' desc='{{ i18n "pages.settings.subUpdatesDesc"}}' v-model="allSetting.subUpdates" :min="1"></setting-list-item>
  284. </a-list>
  285. </a-tab-pane>
  286. <a-tab-pane key="5" tab='{{ i18n "pages.settings.subSettings" }} Json' v-if="allSetting.subEnable">
  287. <a-list item-layout="horizontal">
  288. <setting-list-item type="text" title='{{ i18n "pages.settings.subPath"}}' desc='{{ i18n "pages.settings.subPathDesc"}}' v-model="allSetting.subJsonPath"></setting-list-item>
  289. <setting-list-item type="text" title='{{ i18n "pages.settings.subURI"}}' desc='{{ i18n "pages.settings.subURIDesc"}}' v-model="allSetting.subJsonURI" placeholder="(http|https)://domain[:port]/path/"></setting-list-item>
  290. <setting-list-item type="switch" title='{{ i18n "pages.settings.fragment"}}' desc='{{ i18n "pages.settings.fragmentDesc"}}' v-model="fragment"></setting-list-item>
  291. </a-list>
  292. <a-collapse v-if="fragment">
  293. <a-collapse-panel header='{{ i18n "pages.settings.fragment"}}'>
  294. <a-list-item style="padding: 20px">
  295. <a-row>
  296. <a-col :lg="24" :xl="12">
  297. <a-list-item-meta title='Packets'/>
  298. </a-col>
  299. <a-col :lg="24" :xl="12">
  300. <a-select
  301. v-model="fragmentPackets"
  302. style="width: 100%"
  303. :dropdown-class-name="themeSwitcher.currentTheme">
  304. <a-select-option :value="p" :label="p" v-for="p in ['1-1', '1-3', 'tlshello']">
  305. [[ p ]]
  306. </a-select-option>
  307. </a-select>
  308. </a-col>
  309. </a-row>
  310. </a-list-item>
  311. <setting-list-item type="text" title='Length' v-model="fragmentLength" placeholder="100-200"></setting-list-item>
  312. <setting-list-item type="text" title='Interval' v-model="fragmentInterval" placeholder="10-20"></setting-list-item>
  313. </a-collapse-panel>
  314. </a-collapse>
  315. </a-tab-pane>
  316. </a-tabs>
  317. </a-space>
  318. </a-spin>
  319. </a-layout-content>
  320. </a-layout>
  321. </a-layout>
  322. {{template "js" .}}
  323. <script src="{{ .base_path }}assets/js/model/setting.js?{{ .cur_ver }}"></script>
  324. {{template "component/themeSwitcher" .}}
  325. {{template "component/password" .}}
  326. {{template "component/setting"}}
  327. <script>
  328. const app = new Vue({
  329. delimiters: ['[[', ']]'],
  330. el: '#app',
  331. data: {
  332. siderDrawer,
  333. themeSwitcher,
  334. spinning: false,
  335. changeSecret: false,
  336. oldAllSetting: new AllSetting(),
  337. allSetting: new AllSetting(),
  338. saveBtnDisable: true,
  339. user: {},
  340. lang: getLang(),
  341. remarkModels: {i:'Inbound',e:'Email',o:'Other'},
  342. remarkSeparators: [' ','-','_','@',':','~','|',',','.','/'],
  343. datepickerList: [{name:'Gregorian (Standard)', value: 'gregorian'}, {name:'Jalalian (شمسی)', value: 'jalalian'}],
  344. remarkSample: '',
  345. defaultFragment: {
  346. tag: "fragment",
  347. protocol: "freedom",
  348. settings: {
  349. domainStrategy: "AsIs",
  350. fragment: {
  351. packets: "tlshello",
  352. length: "100-200",
  353. interval: "10-20"
  354. }
  355. },
  356. streamSettings: {
  357. sockopt: {
  358. tcpKeepAliveIdle: 100,
  359. tcpNoDelay: true
  360. }
  361. }
  362. },
  363. get remarkModel() {
  364. rm = this.allSetting.remarkModel;
  365. return rm.length>1 ? rm.substring(1).split('') : [];
  366. },
  367. set remarkModel(value) {
  368. rs = this.allSetting.remarkModel[0];
  369. this.allSetting.remarkModel = rs + value.join('');
  370. this.changeRemarkSample();
  371. },
  372. get remarkSeparator() {
  373. return this.allSetting.remarkModel.length > 1 ? this.allSetting.remarkModel.charAt(0) : '-';
  374. },
  375. set remarkSeparator(value) {
  376. this.allSetting.remarkModel = value + this.allSetting.remarkModel.substring(1);
  377. this.changeRemarkSample();
  378. },
  379. get datepicker() {
  380. return this.allSetting.datepicker ? this.allSetting.datepicker : 'gregorian';
  381. },
  382. set datepicker(value) {
  383. this.allSetting.datepicker = value;
  384. },
  385. changeRemarkSample(){
  386. sample = []
  387. this.remarkModel.forEach(r => sample.push(this.remarkModels[r]));
  388. this.remarkSample = sample.length == 0 ? '' : sample.join(this.remarkSeparator);
  389. }
  390. },
  391. methods: {
  392. loading(spinning = true) {
  393. this.spinning = spinning;
  394. },
  395. async getAllSetting() {
  396. this.loading(true);
  397. const msg = await HttpUtil.post("/panel/setting/all");
  398. this.loading(false);
  399. if (msg.success) {
  400. this.oldAllSetting = new AllSetting(msg.obj);
  401. this.allSetting = new AllSetting(msg.obj);
  402. app.changeRemarkSample();
  403. this.saveBtnDisable = true;
  404. }
  405. await this.fetchUserSecret();
  406. },
  407. async updateAllSetting() {
  408. this.loading(true);
  409. const msg = await HttpUtil.post("/panel/setting/update", this.allSetting);
  410. this.loading(false);
  411. if (msg.success) {
  412. await this.getAllSetting();
  413. }
  414. },
  415. async updateUser() {
  416. this.loading(true);
  417. const msg = await HttpUtil.post("/panel/setting/updateUser", this.user);
  418. this.loading(false);
  419. if (msg.success) {
  420. this.user = {};
  421. }
  422. },
  423. async restartPanel() {
  424. await new Promise(resolve => {
  425. this.$confirm({
  426. title: '{{ i18n "pages.settings.restartPanel" }}',
  427. content: '{{ i18n "pages.settings.restartPanelDesc" }}',
  428. class: themeSwitcher.currentTheme,
  429. okText: '{{ i18n "sure" }}',
  430. cancelText: '{{ i18n "cancel" }}',
  431. onOk: () => resolve(),
  432. });
  433. });
  434. this.loading(true);
  435. const msg = await HttpUtil.post("/panel/setting/restartPanel");
  436. this.loading(false);
  437. if (msg.success) {
  438. this.loading(true);
  439. await PromiseUtil.sleep(5000);
  440. let { webCertFile, webKeyFile, webDomain: host, webPort: port, webBasePath: base } = this.allSetting;
  441. const isTLS = webCertFile !== "" || webKeyFile !== "";
  442. const url = buildURL({ host, port, isTLS, base, path: "panel/settings" });
  443. window.location.replace(url);
  444. }
  445. },
  446. async fetchUserSecret() {
  447. this.loading(true);
  448. const userMessage = await HttpUtil.post("/panel/setting/getUserSecret", this.user);
  449. if (userMessage.success) {
  450. this.user = userMessage.obj;
  451. }
  452. this.loading(false);
  453. },
  454. async updateSecret() {
  455. this.loading(true);
  456. const msg = await HttpUtil.post("/panel/setting/updateUserSecret", this.user);
  457. if (msg && msg.obj) {
  458. this.user = msg.obj;
  459. }
  460. this.loading(false);
  461. await this.updateAllSetting();
  462. },
  463. generateRandomString(length) {
  464. var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  465. let randomString = "";
  466. for (let i = 0; i < length; i++) {
  467. randomString += chars[Math.floor(Math.random() * chars.length)];
  468. }
  469. return randomString;
  470. },
  471. async getNewSecret() {
  472. if (!this.changeSecret) {
  473. this.changeSecret = true;
  474. this.user.loginSecret = '';
  475. const newSecret = this.generateRandomString(64);
  476. await PromiseUtil.sleep(1000);
  477. this.user.loginSecret = newSecret;
  478. this.changeSecret = false;
  479. }
  480. },
  481. async toggleToken(value) {
  482. if (value) {
  483. await this.getNewSecret();
  484. } else {
  485. this.user.loginSecret = "";
  486. }
  487. },
  488. },
  489. computed: {
  490. fragment: {
  491. get: function() { return this.allSetting?.subJsonFragment != ""; },
  492. set: function (v) {
  493. this.allSetting.subJsonFragment = v ? JSON.stringify(this.defaultFragment) : "";
  494. }
  495. },
  496. fragmentPackets: {
  497. get: function() { return this.fragment ? JSON.parse(this.allSetting.subJsonFragment).settings.fragment.packets : ""; },
  498. set: function(v) {
  499. if (v != ""){
  500. newFragment = JSON.parse(this.allSetting.subJsonFragment);
  501. newFragment.settings.fragment.packets = v;
  502. this.allSetting.subJsonFragment = JSON.stringify(newFragment);
  503. }
  504. }
  505. },
  506. fragmentLength: {
  507. get: function() { return this.fragment ? JSON.parse(this.allSetting.subJsonFragment).settings.fragment.length : ""; },
  508. set: function(v) {
  509. if (v != ""){
  510. newFragment = JSON.parse(this.allSetting.subJsonFragment);
  511. newFragment.settings.fragment.length = v;
  512. this.allSetting.subJsonFragment = JSON.stringify(newFragment);
  513. }
  514. }
  515. },
  516. fragmentInterval: {
  517. get: function() { return this.fragment ? JSON.parse(this.allSetting.subJsonFragment).settings.fragment.interval : ""; },
  518. set: function(v) {
  519. if (v != ""){
  520. newFragment = JSON.parse(this.allSetting.subJsonFragment);
  521. newFragment.settings.fragment.interval = v;
  522. this.allSetting.subJsonFragment = JSON.stringify(newFragment);
  523. }
  524. }
  525. },
  526. confAlerts: {
  527. get: function() {
  528. if (!this.allSetting) return [];
  529. var alerts = []
  530. if (window.location.protocol !== "https:") alerts.push('{{ i18n "secAlertSSL" }}');
  531. if (this.allSetting.webPort == 54321) alerts.push('{{ i18n "secAlertPanelPort" }}');
  532. panelPath = window.location.pathname.split('/').length<4
  533. if (panelPath && this.allSetting.webBasePath == '/') alerts.push('{{ i18n "secAlertPanelURI" }}');
  534. if (this.allSetting.subEnable) {
  535. subPath = this.allSetting.subURI.length >0 ? new URL(this.allSetting.subURI).pathname : this.allSetting.subPath;
  536. if (subPath == '/sub/') alerts.push('{{ i18n "secAlertSubURI" }}');
  537. subJsonPath = this.allSetting.subJsonURI.length >0 ? new URL(this.allSetting.subJsonURI).pathname : this.allSetting.subJsonPath;
  538. if (subJsonPath == '/json/') alerts.push('{{ i18n "secAlertSubJsonURI" }}');
  539. }
  540. return alerts
  541. }
  542. }
  543. },
  544. async mounted() {
  545. await this.getAllSetting();
  546. while (true) {
  547. await PromiseUtil.sleep(1000);
  548. this.saveBtnDisable = this.oldAllSetting.equals(this.allSetting);
  549. }
  550. }
  551. });
  552. </script>
  553. </body>
  554. </html>