forked from mirrors/amnezia-wg-easy
		
	fix: reload configuration
* run linter * screenshot update
This commit is contained in:
		
							parent
							
								
									72ba79b5f2
								
							
						
					
					
						commit
						4deca34faf
					
				
					 5 changed files with 13 additions and 14 deletions
				
			
		
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 105 KiB After Width: | Height: | Size: 86 KiB  | 
| 
						 | 
				
			
			@ -270,8 +270,8 @@ module.exports = class Server {
 | 
			
		|||
    app.use(router3);
 | 
			
		||||
 | 
			
		||||
    router3
 | 
			
		||||
      .get('/api/wireguard/dl', defineEventHandler((event) => {
 | 
			
		||||
        const config = WireGuard.downloadConfiguration();
 | 
			
		||||
      .get('/api/wireguard/dl', defineEventHandler(async (event) => {
 | 
			
		||||
        const config = await WireGuard.downloadConfiguration();
 | 
			
		||||
        setHeader(event, 'Content-Disposition', 'attachment; filename="wg0.json"');
 | 
			
		||||
        setHeader(event, 'Content-Type', 'text/json');
 | 
			
		||||
        return config;
 | 
			
		||||
| 
						 | 
				
			
			@ -279,7 +279,7 @@ module.exports = class Server {
 | 
			
		|||
      .put('/api/wireguard/upload', defineEventHandler(async (event) => {
 | 
			
		||||
        const { file } = await readBody(event);
 | 
			
		||||
        await WireGuard.uploadConfiguration(file);
 | 
			
		||||
        return { success: true }
 | 
			
		||||
        return { success: true };
 | 
			
		||||
      }));
 | 
			
		||||
 | 
			
		||||
    // Static assets
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -111,7 +111,7 @@ PostDown = ${WG_POST_DOWN}
 | 
			
		|||
[Peer]
 | 
			
		||||
PublicKey = ${client.publicKey}
 | 
			
		||||
${client.preSharedKey ? `PresharedKey = ${client.preSharedKey}\n` : ''
 | 
			
		||||
        }AllowedIPs = ${client.address}/32`;
 | 
			
		||||
}AllowedIPs = ${client.address}/32`;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    debug('Config saving...');
 | 
			
		||||
| 
						 | 
				
			
			@ -206,7 +206,7 @@ ${WG_MTU ? `MTU = ${WG_MTU}\n` : ''}\
 | 
			
		|||
[Peer]
 | 
			
		||||
PublicKey = ${config.server.publicKey}
 | 
			
		||||
${client.preSharedKey ? `PresharedKey = ${client.preSharedKey}\n` : ''
 | 
			
		||||
      }AllowedIPs = ${WG_ALLOWED_IPS}
 | 
			
		||||
}AllowedIPs = ${WG_ALLOWED_IPS}
 | 
			
		||||
PersistentKeepalive = ${WG_PERSISTENT_KEEPALIVE}
 | 
			
		||||
Endpoint = ${WG_HOST}:${WG_CONFIG_PORT}`;
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -322,7 +322,9 @@ Endpoint = ${WG_HOST}:${WG_CONFIG_PORT}`;
 | 
			
		|||
  async uploadConfiguration(config) {
 | 
			
		||||
    const _config = JSON.parse(config);
 | 
			
		||||
    await this.__saveConfig(_config);
 | 
			
		||||
    await this.__syncConfig();
 | 
			
		||||
    // force restart
 | 
			
		||||
    this.__configPromise = null;
 | 
			
		||||
    await this.saveConfig();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async downloadConfiguration() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -141,15 +141,15 @@ class API {
 | 
			
		|||
  async uploadConfiguration(file) {
 | 
			
		||||
    return this.call({
 | 
			
		||||
      method: 'put',
 | 
			
		||||
      path: `/wireguard/upload`,
 | 
			
		||||
      body: { file }
 | 
			
		||||
      path: '/wireguard/upload',
 | 
			
		||||
      body: { file },
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async downloadConfiguration() {
 | 
			
		||||
    return this.call({
 | 
			
		||||
      method: 'get',
 | 
			
		||||
      path: `/wireguard/dl`,
 | 
			
		||||
      path: '/wireguard/dl',
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -303,12 +303,9 @@ new Vue({
 | 
			
		|||
      e.preventDefault();
 | 
			
		||||
      const file = e.currentTarget.files.item(0);
 | 
			
		||||
      file.text()
 | 
			
		||||
        .then(content => {
 | 
			
		||||
        .then((content) => {
 | 
			
		||||
          this.api.uploadConfiguration(content)
 | 
			
		||||
            .then((_result) => {
 | 
			
		||||
              alert("The configuration was updated.");
 | 
			
		||||
              document.location.reload();
 | 
			
		||||
            })
 | 
			
		||||
            .then((_result) => alert('The configuration was updated.'))
 | 
			
		||||
            .catch((err) => alert(err.message || err.toString()))
 | 
			
		||||
            .finally(() => this.refresh().catch(console.error));
 | 
			
		||||
        })
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue