warp_modal.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. {{define "warpModal"}}
  2. <a-modal id="warp-modal" v-model="warpModal.visible" title="Cloudflare WARP"
  3. :confirm-loading="warpModal.confirmLoading" :closable="true" :mask-closable="true"
  4. :footer="null" :class="themeSwitcher.currentTheme">
  5. <template v-if="ObjectUtil.isEmpty(warpModal.warpData)">
  6. <a-button icon="api" @click="register" :loading="warpModal.confirmLoading">{{ i18n "pages.inbounds.create" }}</a-button>
  7. </template>
  8. <template v-else>
  9. <table style="margin: 5px 0; width: 100%;">
  10. <tr class="client-table-odd-row">
  11. <td>Access Token</td>
  12. <td>[[ warpModal.warpData.access_token ]]</td>
  13. </tr>
  14. <tr>
  15. <td>Device ID</td>
  16. <td>[[ warpModal.warpData.device_id ]]</td>
  17. </tr>
  18. <tr class="client-table-odd-row">
  19. <td>License Key</td>
  20. <td>[[ warpModal.warpData.license_key ]]</td>
  21. </tr>
  22. <tr>
  23. <td>Private Key</td>
  24. <td>[[ warpModal.warpData.private_key ]]</td>
  25. </tr>
  26. </table>
  27. <a-divider style="margin: 0;">{{ i18n "pages.xray.outbound.settings" }}</a-divider>
  28. <a-collapse style="margin: 10px 0;">
  29. <a-collapse-panel header='WARP/WARP+ License Key'>
  30. <a-form :colon="false" :label-col="{ md: {span:6} }" :wrapper-col="{ md: {span:14} }">
  31. <a-form-item label="Key">
  32. <a-input v-model="warpPlus"></a-input>
  33. <a-button @click="updateLicense(warpPlus)" :disabled="warpPlus.length<26" :loading="warpModal.confirmLoading">{{ i18n "pages.inbounds.update" }}</a-button>
  34. </a-form-item>
  35. </a-form>
  36. </a-collapse-panel>
  37. </a-collapse>
  38. <a-divider style="margin: 0;">{{ i18n "pages.xray.outbound.accountInfo" }}</a-divider>
  39. <a-button icon="sync" @click="getConfig" style="margin-top: 5px; margin-bottom: 10px;" :loading="warpModal.confirmLoading" type="primary">{{ i18n "info" }}</a-button>
  40. <template v-if="!ObjectUtil.isEmpty(warpModal.warpConfig)">
  41. <table style="width: 100%">
  42. <tr class="client-table-odd-row">
  43. <td>Device Name</td>
  44. <td>[[ warpModal.warpConfig.name ]]</td>
  45. </tr>
  46. <tr>
  47. <td>Device Model</td>
  48. <td>[[ warpModal.warpConfig.model ]]</td>
  49. </tr>
  50. <tr class="client-table-odd-row">
  51. <td>Device Enabled</td>
  52. <td>[[ warpModal.warpConfig.enabled ]]</td>
  53. </tr>
  54. <template v-if="!ObjectUtil.isEmpty(warpModal.warpConfig.account)">
  55. <tr>
  56. <td>Account Type</td>
  57. <td>[[ warpModal.warpConfig.account.account_type ]]</td>
  58. </tr>
  59. <tr class="client-table-odd-row">
  60. <td>Role</td>
  61. <td>[[ warpModal.warpConfig.account.role ]]</td>
  62. </tr>
  63. <tr>
  64. <td>WARP+ Data</td>
  65. <td>[[ sizeFormat(warpModal.warpConfig.account.premium_data) ]]</td>
  66. </tr>
  67. <tr class="client-table-odd-row">
  68. <td>Quota</td>
  69. <td>[[ sizeFormat(warpModal.warpConfig.account.quota) ]]</td>
  70. </tr>
  71. <tr v-if="!ObjectUtil.isEmpty(warpModal.warpConfig.account.usage)">
  72. <td>Usage</td>
  73. <td>[[ sizeFormat(warpModal.warpConfig.account.usage) ]]</td>
  74. </tr>
  75. </template>
  76. </table>
  77. <a-divider style="margin: 10px 0;">{{ i18n "pages.xray.outbound.outboundStatus" }}</a-divider>
  78. <a-form :label-col="{ md: {span:8} }" :wrapper-col="{ md: {span:14} }">
  79. <template v-if="warpOutboundIndex>=0">
  80. <a-tag color="green" style="line-height: 31px;">{{ i18n "enabled" }}</a-tag>
  81. <a-button @click="resetOutbound" :loading="warpModal.confirmLoading" type="danger">{{ i18n "reset" }}</a-button>
  82. </template>
  83. <template v-else>
  84. <a-tag color="orange" style="line-height: 31px;">{{ i18n "disabled" }}</a-tag>
  85. <a-button @click="addOutbound" :loading="warpModal.confirmLoading" type="primary">{{ i18n "pages.xray.outbound.addOutbound" }}</a-button>
  86. </template>
  87. </a-form-item>
  88. </a-form>
  89. </template>
  90. </template>
  91. </a-modal>
  92. <script>
  93. const warpModal = {
  94. visible: false,
  95. confirmLoading: false,
  96. warpData: null,
  97. warpConfig: null,
  98. warpOutbound: null,
  99. show() {
  100. this.visible = true;
  101. this.warpConfig = null;
  102. this.getData();
  103. },
  104. close() {
  105. this.visible = false;
  106. this.loading(false);
  107. },
  108. loading(loading=true) {
  109. this.confirmLoading = loading;
  110. },
  111. async getData(){
  112. this.loading(true);
  113. const msg = await HttpUtil.post('/panel/xray/warp/data');
  114. this.loading(false);
  115. if (msg.success) {
  116. this.warpData = msg.obj.length>0 ? JSON.parse(msg.obj): null;
  117. }
  118. },
  119. };
  120. new Vue({
  121. delimiters: ['[[', ']]'],
  122. el: '#warp-modal',
  123. data: {
  124. warpModal: warpModal,
  125. warpPlus: '',
  126. },
  127. methods: {
  128. collectConfig() {
  129. config = warpModal.warpConfig.config;
  130. peer = config.peers[0];
  131. if(config){
  132. warpModal.warpOutbound = Outbound.fromJson({
  133. tag: 'warp',
  134. protocol: Protocols.Wireguard,
  135. settings: {
  136. mtu: 1420,
  137. secretKey: warpModal.warpData.private_key,
  138. address: Object.values(config.interface.addresses),
  139. domainStrategy: 'ForceIP',
  140. peers: [{
  141. publicKey: peer.public_key,
  142. endpoint: peer.endpoint.host,
  143. }],
  144. kernelMode: false
  145. }
  146. });
  147. }
  148. },
  149. async register(){
  150. warpModal.loading(true);
  151. keys = Wireguard.generateKeypair();
  152. const msg = await HttpUtil.post('/panel/xray/warp/reg',keys);
  153. if (msg.success) {
  154. resp = JSON.parse(msg.obj);
  155. warpModal.warpData = resp.data;
  156. warpModal.warpConfig = resp.config;
  157. this.collectConfig();
  158. }
  159. warpModal.loading(false);
  160. },
  161. async updateLicense(l){
  162. warpModal.loading(true);
  163. const msg = await HttpUtil.post('/panel/xray/warp/license',{license: l});
  164. if (msg.success) {
  165. warpModal.warpData = JSON.parse(msg.obj);
  166. warpModal.warpConfig = null;
  167. this.warpPlus = '';
  168. }
  169. warpModal.loading(false);
  170. },
  171. async getConfig(){
  172. warpModal.loading(true);
  173. const msg = await HttpUtil.post('/panel/xray/warp/config');
  174. warpModal.loading(false);
  175. if (msg.success) {
  176. warpModal.warpConfig = JSON.parse(msg.obj);
  177. this.collectConfig();
  178. }
  179. },
  180. addOutbound(){
  181. app.templateSettings.outbounds.push(warpModal.warpOutbound.toJson());
  182. app.outboundSettings = JSON.stringify(app.templateSettings.outbounds);
  183. warpModal.close();
  184. },
  185. resetOutbound(){
  186. app.templateSettings.outbounds[this.warpOutboundIndex] = warpModal.warpOutbound.toJson();
  187. app.outboundSettings = JSON.stringify(app.templateSettings.outbounds);
  188. warpModal.close();
  189. }
  190. },
  191. computed: {
  192. warpOutboundIndex: {
  193. get: function() {
  194. return app.templateSettings ? app.templateSettings.outbounds.findIndex((o) => o.tag == 'warp') : -1;
  195. }
  196. }
  197. }
  198. });
  199. </script>
  200. {{end}}