forked from mirrors/amnezia-wg-easy
		
	feat: load configuration from file
* import json config file & update the config (restore) * export the config and save it to json file (backup)
This commit is contained in:
		
							parent
							
								
									94d87681c3
								
							
						
					
					
						commit
						03b7d8e537
					
				
					 6 changed files with 134 additions and 39 deletions
				
			
		| 
						 | 
				
			
			@ -265,6 +265,23 @@ module.exports = class Server {
 | 
			
		|||
      });
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    // import_export
 | 
			
		||||
    const router3 = createRouter();
 | 
			
		||||
    app.use(router3);
 | 
			
		||||
 | 
			
		||||
    router3
 | 
			
		||||
      .get('/api/wireguard/dl', defineEventHandler((event) => {
 | 
			
		||||
        const config = WireGuard.downloadConfiguration();
 | 
			
		||||
        setHeader(event, 'Content-Disposition', 'attachment; filename="wg0.json"');
 | 
			
		||||
        setHeader(event, 'Content-Type', 'text/json');
 | 
			
		||||
        return config;
 | 
			
		||||
      }))
 | 
			
		||||
      .put('/api/wireguard/upload', defineEventHandler(async (event) => {
 | 
			
		||||
        const { file } = await readBody(event);
 | 
			
		||||
        await WireGuard.uploadConfiguration(file);
 | 
			
		||||
        return { success: true }
 | 
			
		||||
      }));
 | 
			
		||||
 | 
			
		||||
    // Static assets
 | 
			
		||||
    const publicDir = '/app/www';
 | 
			
		||||
    app.use(
 | 
			
		||||
| 
						 | 
				
			
			@ -276,7 +293,7 @@ module.exports = class Server {
 | 
			
		|||
          getMeta: async (id) => {
 | 
			
		||||
            const filePath = safePathJoin(publicDir, id);
 | 
			
		||||
 | 
			
		||||
            const stats = await stat(filePath).catch(() => {});
 | 
			
		||||
            const stats = await stat(filePath).catch(() => { });
 | 
			
		||||
            if (!stats || !stats.isFile()) {
 | 
			
		||||
              return;
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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}`;
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -319,6 +319,17 @@ Endpoint = ${WG_HOST}:${WG_CONFIG_PORT}`;
 | 
			
		|||
    await this.saveConfig();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async uploadConfiguration(config) {
 | 
			
		||||
    const _config = JSON.parse(config);
 | 
			
		||||
    await this.__saveConfig(_config);
 | 
			
		||||
    await this.__syncConfig();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async downloadConfiguration() {
 | 
			
		||||
    const config = await this.getConfig();
 | 
			
		||||
    return JSON.stringify(config, null, 2);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Shutdown wireguard
 | 
			
		||||
  async Shutdown() {
 | 
			
		||||
    await Util.exec('wg-quick down wg0').catch(() => { });
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,7 @@
 | 
			
		|||
 | 
			
		||||
<head>
 | 
			
		||||
  <title>WireGuard</title>
 | 
			
		||||
  <meta charset="utf-8"/>
 | 
			
		||||
  <meta charset="utf-8" />
 | 
			
		||||
  <link href="./css/app.css" rel="stylesheet">
 | 
			
		||||
  <link rel="manifest" href="./manifest.json">
 | 
			
		||||
  <link rel="icon" type="image/png" href="./img/favicon.png">
 | 
			
		||||
| 
						 | 
				
			
			@ -23,45 +23,50 @@
 | 
			
		|||
      <div v-if="authenticated === true">
 | 
			
		||||
        <div class="flex flex-col-reverse xxs:flex-row flex-auto items-center items-end gap-3">
 | 
			
		||||
          <h1 class="text-4xl dark:text-neutral-200 font-medium flex-grow self-start mb-4">
 | 
			
		||||
            <img src="./img/logo.png" width="32" class="inline align-middle dark:bg mr-2" /><span class="align-middle">WireGuard</span>
 | 
			
		||||
            <img src="./img/logo.png" width="32" class="inline align-middle dark:bg mr-2" /><span
 | 
			
		||||
              class="align-middle">WireGuard</span>
 | 
			
		||||
          </h1>
 | 
			
		||||
          <div class="flex items-center grow-0 gap-3 items-end self-end xxs:self-center">
 | 
			
		||||
            <!-- Dark / light theme -->
 | 
			
		||||
            <button @click="toggleTheme"
 | 
			
		||||
              class="flex items-center justify-center w-8 h-8 rounded-full bg-gray-200 hover:bg-gray-300 dark:bg-neutral-700 dark:hover:bg-neutral-600 transition" :title="$t(`theme.${uiTheme}`)">
 | 
			
		||||
              <svg v-if="uiTheme === 'light'" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"
 | 
			
		||||
                class="w-5 h-5">
 | 
			
		||||
              class="flex items-center justify-center w-8 h-8 rounded-full bg-gray-200 hover:bg-gray-300 dark:bg-neutral-700 dark:hover:bg-neutral-600 transition"
 | 
			
		||||
              :title="$t(`theme.${uiTheme}`)">
 | 
			
		||||
              <svg v-if="uiTheme === 'light'" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
 | 
			
		||||
                stroke-width="1.5" stroke="currentColor" class="w-5 h-5">
 | 
			
		||||
                <path stroke-linecap="round" stroke-linejoin="round"
 | 
			
		||||
                  d="M12 3v2.25m6.364.386-1.591 1.591M21 12h-2.25m-.386 6.364-1.591-1.591M12 18.75V21m-4.773-4.227-1.591 1.591M5.25 12H3m4.227-4.773L5.636 5.636M15.75 12a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0Z" />
 | 
			
		||||
              </svg>
 | 
			
		||||
              <svg v-else-if="uiTheme === 'dark'" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"
 | 
			
		||||
                class="w-5 h-5 text-neutral-400">
 | 
			
		||||
              <svg v-else-if="uiTheme === 'dark'" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
 | 
			
		||||
                stroke-width="1.5" stroke="currentColor" class="w-5 h-5 text-neutral-400">
 | 
			
		||||
                <path stroke-linecap="round" stroke-linejoin="round"
 | 
			
		||||
                  d="M21.752 15.002A9.72 9.72 0 0 1 18 15.75c-5.385 0-9.75-4.365-9.75-9.75 0-1.33.266-2.597.748-3.752A9.753 9.753 0 0 0 3 11.25C3 16.635 7.365 21 12.75 21a9.753 9.753 0 0 0 9.002-5.998Z" />
 | 
			
		||||
              </svg>
 | 
			
		||||
              <svg v-else xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" 
 | 
			
		||||
              <svg v-else xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24"
 | 
			
		||||
                class="w-5 h-5 fill-gray-600 dark:fill-neutral-400">
 | 
			
		||||
                <path
 | 
			
		||||
                  d="M12,2.2c-5.4,0-9.8,4.4-9.8,9.8s4.4,9.8,9.8,9.8s9.8-4.4,9.8-9.8S17.4,2.2,12,2.2z M3.8,12c0-4.5,3.7-8.2,8.2-8.2v16.5C7.5,20.2,3.8,16.5,3.8,12z" />
 | 
			
		||||
              </svg>
 | 
			
		||||
                <path stroke-linecap="round" stroke-linejoin="round"
 | 
			
		||||
                  d="M9 17.25v1.007a3 3 0 0 1-.879 2.122L7.5 21h9l-.621-.621A3 3 0 0 1 15 18.257V17.25m6-12V15a2.25 2.25 0 0 1-2.25 2.25H5.25A2.25 2.25 0 0 1 3 15V5.25m18 0A2.25 2.25 0 0 0 18.75 3H5.25A2.25 2.25 0 0 0 3 5.25m18 0V12a2.25 2.25 0 0 1-2.25 2.25H5.25A2.25 2.25 0 0 1 3 12V5.25" />
 | 
			
		||||
              <path stroke-linecap="round" stroke-linejoin="round"
 | 
			
		||||
                d="M9 17.25v1.007a3 3 0 0 1-.879 2.122L7.5 21h9l-.621-.621A3 3 0 0 1 15 18.257V17.25m6-12V15a2.25 2.25 0 0 1-2.25 2.25H5.25A2.25 2.25 0 0 1 3 15V5.25m18 0A2.25 2.25 0 0 0 18.75 3H5.25A2.25 2.25 0 0 0 3 5.25m18 0V12a2.25 2.25 0 0 1-2.25 2.25H5.25A2.25 2.25 0 0 1 3 12V5.25" />
 | 
			
		||||
              </svg>
 | 
			
		||||
            </button>
 | 
			
		||||
            <!-- Show / hide charts -->
 | 
			
		||||
            <label v-if="uiChartType > 0" class="inline-flex items-center justify-center cursor-pointer w-8 h-8 rounded-full bg-gray-200 hover:bg-gray-300 dark:bg-neutral-700 dark:hover:bg-neutral-600 whitespace-nowrap transition group" :title="$t('toggleCharts')">
 | 
			
		||||
            <label v-if="uiChartType > 0"
 | 
			
		||||
              class="inline-flex items-center justify-center cursor-pointer w-8 h-8 rounded-full bg-gray-200 hover:bg-gray-300 dark:bg-neutral-700 dark:hover:bg-neutral-600 whitespace-nowrap transition group"
 | 
			
		||||
              :title="$t('toggleCharts')">
 | 
			
		||||
              <input type="checkbox" value="" class="sr-only peer" v-model="uiShowCharts" @change="toggleCharts">
 | 
			
		||||
              <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" fill="currentColor"
 | 
			
		||||
              <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
 | 
			
		||||
                fill="currentColor"
 | 
			
		||||
                class="w-5 h-5 peer fill-gray-400 peer-checked:fill-gray-600 dark:fill-neutral-600 peer-checked:dark:fill-neutral-400 group-hover:dark:fill-neutral-500 transition">
 | 
			
		||||
                  <path
 | 
			
		||||
                    d="M18.375 2.25c-1.035 0-1.875.84-1.875 1.875v15.75c0 1.035.84 1.875 1.875 1.875h.75c1.035 0 1.875-.84 1.875-1.875V4.125c0-1.036-.84-1.875-1.875-1.875h-.75ZM9.75 8.625c0-1.036.84-1.875 1.875-1.875h.75c1.036 0 1.875.84 1.875 1.875v11.25c0 1.035-.84 1.875-1.875 1.875h-.75a1.875 1.875 0 0 1-1.875-1.875V8.625ZM3 13.125c0-1.036.84-1.875 1.875-1.875h.75c1.036 0 1.875.84 1.875 1.875v6.75c0 1.035-.84 1.875-1.875 1.875h-.75A1.875 1.875 0 0 1 3 19.875v-6.75Z" />
 | 
			
		||||
                <path
 | 
			
		||||
                  d="M18.375 2.25c-1.035 0-1.875.84-1.875 1.875v15.75c0 1.035.84 1.875 1.875 1.875h.75c1.035 0 1.875-.84 1.875-1.875V4.125c0-1.036-.84-1.875-1.875-1.875h-.75ZM9.75 8.625c0-1.036.84-1.875 1.875-1.875h.75c1.036 0 1.875.84 1.875 1.875v11.25c0 1.035-.84 1.875-1.875 1.875h-.75a1.875 1.875 0 0 1-1.875-1.875V8.625ZM3 13.125c0-1.036.84-1.875 1.875-1.875h.75c1.036 0 1.875.84 1.875 1.875v6.75c0 1.035-.84 1.875-1.875 1.875h-.75A1.875 1.875 0 0 1 3 19.875v-6.75Z" />
 | 
			
		||||
              </svg>
 | 
			
		||||
            </label>
 | 
			
		||||
            <span v-if="requiresPassword"
 | 
			
		||||
              class="text-sm text-gray-400 dark:text-neutral-400 cursor-pointer hover:underline"
 | 
			
		||||
              @click="logout">
 | 
			
		||||
              class="text-sm text-gray-400 dark:text-neutral-400 cursor-pointer hover:underline" @click="logout">
 | 
			
		||||
              {{$t("logout")}}
 | 
			
		||||
              <svg class="h-3 inline" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
 | 
			
		||||
              <svg class="h-3 inline" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
 | 
			
		||||
                stroke="currentColor">
 | 
			
		||||
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
 | 
			
		||||
                  d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1" />
 | 
			
		||||
              </svg>
 | 
			
		||||
| 
						 | 
				
			
			@ -91,6 +96,31 @@
 | 
			
		|||
              <p class="text-2xl font-medium dark:text-neutral-200">{{$t("clients")}}</p>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="flex-shrink-0">
 | 
			
		||||
              <!-- Import configuration -->
 | 
			
		||||
              <label for="importConfig"
 | 
			
		||||
                class="hover:bg-red-800 hover:border-red-800 hover:text-white text-gray-700 dark:text-neutral-200 border-2 border-gray-100 dark:border-neutral-600 py-2 px-4 rounded inline-flex items-center transition">
 | 
			
		||||
                <svg inline class="w-4 mr-2" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 22 22"
 | 
			
		||||
                  stroke="currentColor">
 | 
			
		||||
                  <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
 | 
			
		||||
                    d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5" />
 | 
			
		||||
                  <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
 | 
			
		||||
                    d="M7.646 1.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 2.707V11.5a.5.5 0 0 1-1 0V2.707L5.354 4.854a.5.5 0 1 1-.708-.708z" />
 | 
			
		||||
                </svg>
 | 
			
		||||
                <span class="text-sm">{{$t("upload")}}</span>
 | 
			
		||||
                <input id="importConfig" type="file" name="configurationfile" accept="text/*,.json"
 | 
			
		||||
                  @change="importConfig" class="opacity-0 hidden -z-[1]" />
 | 
			
		||||
              </label>
 | 
			
		||||
              <!-- Export configuration -->
 | 
			
		||||
              <a href="./api/wireguard/dl" title="Download your configuration"
 | 
			
		||||
                class="hover:bg-red-800 hover:border-red-800 hover:text-white text-gray-700 dark:text-neutral-200 border-2 border-gray-100 dark:border-neutral-600 py-2 px-4 rounded inline-flex items-center transition">
 | 
			
		||||
                <svg inline class="w-4 mr-2" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
 | 
			
		||||
                  stroke="currentColor">
 | 
			
		||||
                  <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
 | 
			
		||||
                    d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"></path>
 | 
			
		||||
                </svg>
 | 
			
		||||
                <span class="text-sm">{{$t("download")}}</span>
 | 
			
		||||
              </a>
 | 
			
		||||
              <!-- New client -->
 | 
			
		||||
              <button @click="clientCreate = true; clientCreateName = '';"
 | 
			
		||||
                class="hover:bg-red-800 hover:border-red-800 hover:text-white text-gray-700 dark:text-neutral-200 border-2 border-gray-100 dark:border-neutral-600 py-2 px-4 rounded inline-flex items-center transition">
 | 
			
		||||
                <svg class="w-4 mr-2" inline xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
 | 
			
		||||
| 
						 | 
				
			
			@ -109,11 +139,11 @@
 | 
			
		|||
              class="relative overflow-hidden border-b last:border-b-0 border-gray-100 dark:border-neutral-600 border-solid">
 | 
			
		||||
 | 
			
		||||
              <!-- Chart -->
 | 
			
		||||
              <div v-if="uiChartType" class="absolute z-0 bottom-0 left-0 right-0 h-6" >
 | 
			
		||||
              <div v-if="uiChartType" class="absolute z-0 bottom-0 left-0 right-0 h-6">
 | 
			
		||||
                <apexchart width="100%" height="100%" :options="chartOptionsTX" :series="client.transferTxSeries">
 | 
			
		||||
                </apexchart>
 | 
			
		||||
              </div>
 | 
			
		||||
              <div v-if="uiChartType" class="absolute z-0 top-0 left-0 right-0 h-6" >
 | 
			
		||||
              <div v-if="uiChartType" class="absolute z-0 top-0 left-0 right-0 h-6">
 | 
			
		||||
                <apexchart width="100%" height="100%" :options="chartOptionsRX" :series="client.transferRxSeries"
 | 
			
		||||
                  style="transform: scaleY(-1);">
 | 
			
		||||
                </apexchart>
 | 
			
		||||
| 
						 | 
				
			
			@ -194,20 +224,24 @@
 | 
			
		|||
                          </span>
 | 
			
		||||
                        </span>
 | 
			
		||||
                        <!-- Inline Transfer TX -->
 | 
			
		||||
                        <span v-if="!uiTrafficStats && client.transferTx" class="whitespace-nowrap" :title="$t('totalDownload') + bytes(client.transferTx)">
 | 
			
		||||
                        <span v-if="!uiTrafficStats && client.transferTx" class="whitespace-nowrap"
 | 
			
		||||
                          :title="$t('totalDownload') + bytes(client.transferTx)">
 | 
			
		||||
                          ·
 | 
			
		||||
                          <svg class="align-middle h-3 inline" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
 | 
			
		||||
                          <svg class="align-middle h-3 inline" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"
 | 
			
		||||
                            fill="currentColor">
 | 
			
		||||
                            <path fill-rule="evenodd"
 | 
			
		||||
                              d="M16.707 10.293a1 1 0 010 1.414l-6 6a1 1 0 01-1.414 0l-6-6a1 1 0 111.414-1.414L9 14.586V3a1 1 0 012 0v11.586l4.293-4.293a1 1 0 011.414 0z"
 | 
			
		||||
                              clip-rule="evenodd" />
 | 
			
		||||
                          </svg>
 | 
			
		||||
                          {{client.transferTxCurrent | bytes}}/s
 | 
			
		||||
                        </span>
 | 
			
		||||
                        
 | 
			
		||||
 | 
			
		||||
                        <!-- Inline Transfer RX -->
 | 
			
		||||
                        <span v-if="!uiTrafficStats && client.transferRx" class="whitespace-nowrap" :title="$t('totalUpload') + bytes(client.transferRx)">
 | 
			
		||||
                        <span v-if="!uiTrafficStats && client.transferRx" class="whitespace-nowrap"
 | 
			
		||||
                          :title="$t('totalUpload') + bytes(client.transferRx)">
 | 
			
		||||
                          ·
 | 
			
		||||
                          <svg class="align-middle h-3 inline" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
 | 
			
		||||
                          <svg class="align-middle h-3 inline" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"
 | 
			
		||||
                            fill="currentColor">
 | 
			
		||||
                            <path fill-rule="evenodd"
 | 
			
		||||
                              d="M3.293 9.707a1 1 0 010-1.414l6-6a1 1 0 011.414 0l6 6a1 1 0 01-1.414 1.414L11 5.414V17a1 1 0 11-2 0V5.414L4.707 9.707a1 1 0 01-1.414 0z"
 | 
			
		||||
                              clip-rule="evenodd" />
 | 
			
		||||
| 
						 | 
				
			
			@ -215,7 +249,8 @@
 | 
			
		|||
                          {{client.transferRxCurrent | bytes}}/s
 | 
			
		||||
                        </span>
 | 
			
		||||
                        <!-- Last seen -->
 | 
			
		||||
                        <span class="text-gray-400 dark:text-neutral-500 whitespace-nowrap" v-if="client.latestHandshakeAt"
 | 
			
		||||
                        <span class="text-gray-400 dark:text-neutral-500 whitespace-nowrap"
 | 
			
		||||
                          v-if="client.latestHandshakeAt"
 | 
			
		||||
                          :title="$t('lastSeen') + dateTime(new Date(client.latestHandshakeAt))">
 | 
			
		||||
                          {{!uiTrafficStats ? " · " : ""}}{{new Date(client.latestHandshakeAt) | timeago}}
 | 
			
		||||
                        </span>
 | 
			
		||||
| 
						 | 
				
			
			@ -291,8 +326,7 @@
 | 
			
		|||
                      :class="{
 | 
			
		||||
                        'hover:bg-red-800 dark:hover:bg-red-800 hover:text-white dark:hover:text-white': client.downloadableConfig,
 | 
			
		||||
                        'is-disabled': !client.downloadableConfig
 | 
			
		||||
                      }"
 | 
			
		||||
                      :title="!client.downloadableConfig ? $t('noPrivKey') : $t('showQR')"
 | 
			
		||||
                      }" :title="!client.downloadableConfig ? $t('noPrivKey') : $t('showQR')"
 | 
			
		||||
                      @click="qrcode = `./api/wireguard/client/${client.id}/qrcode.svg`">
 | 
			
		||||
                      <svg class="w-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
 | 
			
		||||
                        stroke="currentColor">
 | 
			
		||||
| 
						 | 
				
			
			@ -309,8 +343,7 @@
 | 
			
		|||
                      :class="{
 | 
			
		||||
                        'hover:bg-red-800 dark:hover:bg-red-800 hover:text-white dark:hover:text-white': client.downloadableConfig,
 | 
			
		||||
                        'is-disabled': !client.downloadableConfig
 | 
			
		||||
                      }"
 | 
			
		||||
                      :title="!client.downloadableConfig ? $t('noPrivKey') : $t('downloadConfig')"
 | 
			
		||||
                      }" :title="!client.downloadableConfig ? $t('noPrivKey') : $t('downloadConfig')"
 | 
			
		||||
                      @click="if(!client.downloadableConfig) { $event.preventDefault(); }">
 | 
			
		||||
                      <svg class="w-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
 | 
			
		||||
                        stroke="currentColor">
 | 
			
		||||
| 
						 | 
				
			
			@ -414,8 +447,8 @@
 | 
			
		|||
                <div class="sm:flex sm:items-start">
 | 
			
		||||
                  <div
 | 
			
		||||
                    class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-red-800 sm:mx-0 sm:h-10 sm:w-10">
 | 
			
		||||
                    <svg class="h-6 w-6 text-white" inline xmlns="http://www.w3.org/2000/svg"
 | 
			
		||||
                      fill="none" viewBox="0 0 24 24" stroke="currentColor">
 | 
			
		||||
                    <svg class="h-6 w-6 text-white" inline xmlns="http://www.w3.org/2000/svg" fill="none"
 | 
			
		||||
                      viewBox="0 0 24 24" stroke="currentColor">
 | 
			
		||||
                      <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
 | 
			
		||||
                        d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
 | 
			
		||||
                    </svg>
 | 
			
		||||
| 
						 | 
				
			
			@ -532,8 +565,8 @@
 | 
			
		|||
          class="shadow rounded-md bg-white dark:bg-neutral-700 mx-auto w-64 p-5 overflow-hidden mt-10">
 | 
			
		||||
          <!-- Avatar -->
 | 
			
		||||
          <div class="h-20 w-20 mb-10 mt-5 mx-auto rounded-full bg-red-800 dark:bg-red-800 relative overflow-hidden">
 | 
			
		||||
            <svg class="w-10 h-10 m-5 text-white dark:text-white" xmlns="http://www.w3.org/2000/svg"
 | 
			
		||||
              viewBox="0 0 20 20" fill="currentColor">
 | 
			
		||||
            <svg class="w-10 h-10 m-5 text-white dark:text-white" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"
 | 
			
		||||
              fill="currentColor">
 | 
			
		||||
              <path fill-rule="evenodd" d="M10 9a3 3 0 100-6 3 3 0 000 6zm-7 9a7 7 0 1114 0H3z" clip-rule="evenodd" />
 | 
			
		||||
            </svg>
 | 
			
		||||
          </div>
 | 
			
		||||
| 
						 | 
				
			
			@ -574,9 +607,10 @@
 | 
			
		|||
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    <p v-cloak class="text-center m-10 text-gray-300 dark:text-neutral-600 text-xs"> <a class="hover:underline" target="_blank"
 | 
			
		||||
        href="https://github.com/wg-easy/wg-easy">WireGuard Easy</a> © 2021-2024 by <a class="hover:underline" target="_blank"
 | 
			
		||||
        href="https://emilenijssen.nl/?ref=wg-easy">Emile Nijssen</a> is licensed under <a class="hover:underline" target="_blank"
 | 
			
		||||
    <p v-cloak class="text-center m-10 text-gray-300 dark:text-neutral-600 text-xs"> <a class="hover:underline"
 | 
			
		||||
        target="_blank" href="https://github.com/wg-easy/wg-easy">WireGuard Easy</a> © 2021-2024 by <a
 | 
			
		||||
        class="hover:underline" target="_blank" href="https://emilenijssen.nl/?ref=wg-easy">Emile Nijssen</a> is
 | 
			
		||||
      licensed under <a class="hover:underline" target="_blank"
 | 
			
		||||
        href="http://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> · <a class="hover:underline"
 | 
			
		||||
        href="https://github.com/sponsors/WeeJeWel" target="_blank">{{$t("donate")}}</a></p>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -138,4 +138,19 @@ class API {
 | 
			
		|||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async uploadConfiguration(file) {
 | 
			
		||||
    return this.call({
 | 
			
		||||
      method: 'put',
 | 
			
		||||
      path: `/wireguard/upload`,
 | 
			
		||||
      body: { file }
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async downloadConfiguration() {
 | 
			
		||||
    return this.call({
 | 
			
		||||
      method: 'get',
 | 
			
		||||
      path: `/wireguard/dl`,
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -299,6 +299,22 @@ new Vue({
 | 
			
		|||
        .catch((err) => alert(err.message || err.toString()))
 | 
			
		||||
        .finally(() => this.refresh().catch(console.error));
 | 
			
		||||
    },
 | 
			
		||||
    importConfig(e) {
 | 
			
		||||
      e.preventDefault();
 | 
			
		||||
      const file = e.currentTarget.files.item(0);
 | 
			
		||||
      file.text()
 | 
			
		||||
        .then(content => {
 | 
			
		||||
          this.api.uploadConfiguration(content)
 | 
			
		||||
            .then((_result) => {
 | 
			
		||||
              alert("The configuration was updated.");
 | 
			
		||||
              document.location.reload();
 | 
			
		||||
            })
 | 
			
		||||
            .catch((err) => alert(err.message || err.toString()))
 | 
			
		||||
            .finally(() => this.refresh().catch(console.error));
 | 
			
		||||
        })
 | 
			
		||||
        .catch((err) => alert(err.message || err.toString()))
 | 
			
		||||
        .finally(() => this.refresh().catch(console.error));
 | 
			
		||||
    },
 | 
			
		||||
    toggleTheme() {
 | 
			
		||||
      const themes = ['light', 'dark', 'auto'];
 | 
			
		||||
      const currentIndex = themes.indexOf(this.uiTheme);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,6 +11,8 @@ const messages = { // eslint-disable-line no-unused-vars
 | 
			
		|||
    clients: 'Clients',
 | 
			
		||||
    new: 'New',
 | 
			
		||||
    deleteClient: 'Delete Client',
 | 
			
		||||
    upload: 'Upload',
 | 
			
		||||
    download: 'Download',
 | 
			
		||||
    deleteDialog1: 'Are you sure you want to delete',
 | 
			
		||||
    deleteDialog2: 'This action cannot be undone.',
 | 
			
		||||
    cancel: 'Cancel',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue