Initial Upload
This commit is contained in:
33
src/main/java/tech/nevets/tvpn/Main.java
Normal file
33
src/main/java/tech/nevets/tvpn/Main.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package tech.nevets.tvpn;
|
||||
|
||||
import com.formdev.flatlaf.FlatDarkLaf;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws IOException, InterruptedException {
|
||||
try {
|
||||
UIManager.setLookAndFeel(new FlatDarkLaf());
|
||||
} catch (UnsupportedLookAndFeelException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
System.out.println("No args");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
switch (args[0]) {
|
||||
case "load" -> WireGuardHandler.loadTunnel(Path.of("C:\\Users\\steven.v\\Desktop\\test.conf"));
|
||||
case "delete" -> WireGuardHandler.deleteTunnel("test");
|
||||
case "start" -> WireGuardHandler.startTunnel("test");
|
||||
case "stop" -> WireGuardHandler.stopTunnel("test");
|
||||
case "--help", "-h" -> {
|
||||
System.out.println("Options:\n - load\n - delete\n - start\n - stop");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
36
src/main/java/tech/nevets/tvpn/UI.java
Normal file
36
src/main/java/tech/nevets/tvpn/UI.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Created by JFormDesigner on Tue Oct 08 20:59:17 EDT 2024
|
||||
*/
|
||||
|
||||
package tech.nevets.tvpn;
|
||||
|
||||
import javax.swing.*;
|
||||
import net.miginfocom.swing.*;
|
||||
|
||||
/**
|
||||
* @author steven
|
||||
*/
|
||||
public class UI extends JPanel {
|
||||
public UI() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents @formatter:off
|
||||
|
||||
//======== this ========
|
||||
setLayout(new MigLayout(
|
||||
"hidemode 3",
|
||||
// columns
|
||||
"[fill]" +
|
||||
"[fill]",
|
||||
// rows
|
||||
"[]" +
|
||||
"[]" +
|
||||
"[]"));
|
||||
// JFormDesigner - End of component initialization //GEN-END:initComponents @formatter:on
|
||||
}
|
||||
|
||||
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables @formatter:off
|
||||
// JFormDesigner - End of variables declaration //GEN-END:variables @formatter:on
|
||||
}
|
||||
17
src/main/java/tech/nevets/tvpn/UI.jfd
Normal file
17
src/main/java/tech/nevets/tvpn/UI.jfd
Normal file
@@ -0,0 +1,17 @@
|
||||
JFDML JFormDesigner: "8.2.4.0.393" Java: "17.0.9" encoding: "UTF-8"
|
||||
|
||||
new FormModel {
|
||||
contentType: "form/swing"
|
||||
root: new FormRoot {
|
||||
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
||||
"$layoutConstraints": "hidemode 3"
|
||||
"$columnConstraints": "[fill][fill]"
|
||||
"$rowConstraints": "[][][]"
|
||||
} ) {
|
||||
name: "this"
|
||||
}, new FormLayoutConstraints( null ) {
|
||||
"location": new java.awt.Point( 0, 0 )
|
||||
"size": new java.awt.Dimension( 400, 300 )
|
||||
} )
|
||||
}
|
||||
}
|
||||
12
src/main/java/tech/nevets/tvpn/Utils.java
Normal file
12
src/main/java/tech/nevets/tvpn/Utils.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package tech.nevets.tvpn;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Utils {
|
||||
public static final File APP_DIR = new File("./tvpn/");
|
||||
public static final String WG_CONF_DIR = "C:\\Program Files\\WireGuard\\Data\\Configurations\\";
|
||||
|
||||
static {
|
||||
if (!APP_DIR.exists()) APP_DIR.mkdirs();
|
||||
}
|
||||
}
|
||||
39
src/main/java/tech/nevets/tvpn/WireGuardHandler.java
Normal file
39
src/main/java/tech/nevets/tvpn/WireGuardHandler.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package tech.nevets.tvpn;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static tech.nevets.tvpn.Utils.*;
|
||||
|
||||
public class WireGuardHandler {
|
||||
|
||||
public static void loadTunnel(Path tunnelConfig) throws IOException {
|
||||
Files.copy(tunnelConfig, Path.of(WG_CONF_DIR + tunnelConfig.getFileName().toString()));
|
||||
}
|
||||
|
||||
public static void deleteTunnel(String tunnelName) throws IOException {
|
||||
File f = new File(WG_CONF_DIR + tunnelName + ".conf.dpapi");
|
||||
f.delete();
|
||||
}
|
||||
|
||||
public static void startTunnel(String tunnelName) throws IOException, InterruptedException {
|
||||
Process proc = new ProcessBuilder()
|
||||
.directory(APP_DIR)
|
||||
.command("cmd", "/C", "wireguard.exe", "/installtunnelservice", WG_CONF_DIR + tunnelName + ".conf.dpapi")
|
||||
.inheritIO()
|
||||
.start();
|
||||
System.out.println("Start Tunnel: " + proc.waitFor());
|
||||
}
|
||||
|
||||
public static void stopTunnel(String tunnelName) throws IOException, InterruptedException {
|
||||
Process proc = new ProcessBuilder()
|
||||
.directory(APP_DIR)
|
||||
.command("cmd", "/C", "wireguard.exe", "/uninstalltunnelservice", tunnelName)
|
||||
.inheritIO()
|
||||
.start();
|
||||
System.out.println("Stop Tunnel: " + proc.waitFor());
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user