Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
nxvvvv authored Nov 10, 2023
1 parent 84dd0ed commit 4b6adb1
Show file tree
Hide file tree
Showing 18 changed files with 613 additions and 0 deletions.
15 changes: 15 additions & 0 deletions VPN-GUI.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="sqlite-jdbc" level="project" />
<orderEntry type="library" name="slf4j-api-2.0.9" level="project" />
<orderEntry type="library" name="logback-classic-1.4.9" level="project" />
<orderEntry type="library" name="logback-core-1.4.9" level="project" />
</component>
</module>
57 changes: 57 additions & 0 deletions VPNServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Cipher;
import javax.crypto.CipherOutputStream;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import java.util.Base64;

public class VPNServer {
private static final int SERVER_PORT = 8888;
private static final String GIF_FILE_PATH = "happi.gif"; // Change this to the actual path of your GIF file

public VPNServer() {
}

public static void main(String[] args) {
try {
ServerSocket serverSocket = new ServerSocket(8888);
System.out.println("VPN Server started on port 8888");

while(true) {
Socket socket = serverSocket.accept();
System.out.println("Client connected: " + socket.getInetAddress().getHostAddress());
ObjectInputStream inputStream = new ObjectInputStream(socket.getInputStream());
SecretKey secretKey = (SecretKey)inputStream.readObject();

byte[] gifBytes = Files.readAllBytes(Paths.get(GIF_FILE_PATH));
encryptAndSendData(gifBytes, secretKey, socket);
}
} catch (IOException | ClassNotFoundException var) {
var.printStackTrace();
}
}

private static void encryptAndSendData(byte[] data, SecretKey secretKey, Socket socket) {
try {
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
byte[] encryptedBytes = cipher.doFinal(data);

OutputStream outputStream = socket.getOutputStream();
CipherOutputStream cipherOutputStream = new CipherOutputStream(outputStream, cipher);
cipherOutputStream.write(encryptedBytes);
cipherOutputStream.close();
} catch (Exception e) {
throw new RuntimeException("Error encrypting and sending data", e);
}
}
}
Binary file added client_logs.db
Binary file not shown.
Binary file added happi.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added out/production/VPN-GUI/LogReaderGUI.class
Binary file not shown.
Binary file added out/production/VPN-GUI/VPNClientGUI.class
Binary file not shown.
Binary file not shown.
Binary file added out/production/VPN-GUI/VPNServer.class
Binary file not shown.
Binary file added out/production/VPN-GUI/client_logs.db
Binary file not shown.
11 changes: 11 additions & 0 deletions out/production/VPN-GUI/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<root level="debug">
<appender-ref ref="CONSOLE" />
</root>
</configuration>
Binary file added out/production/VPN-GUI/server_logs.db
Binary file not shown.
Binary file added server_logs.db
Binary file not shown.
112 changes: 112 additions & 0 deletions src/LogReaderGUI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class LogReaderGUI extends JFrame {

private JTextArea logArea;
private JButton clientLogsButton;
private JButton serverLogsButton;

public LogReaderGUI() {
super("Log Reader");

// Layout
setLayout(new BorderLayout());

// Log Area
logArea = new JTextArea();
logArea.setEditable(false);
logArea.setFont(new Font("Monospaced", Font.PLAIN, 12));

JScrollPane scrollPane = new JScrollPane(logArea);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

add(scrollPane, BorderLayout.CENTER);

// Buttons
clientLogsButton = new JButton("Client Logs");
serverLogsButton = new JButton("Server Logs");

clientLogsButton.addActionListener(e -> fetchClientLogsAndDisplay());
serverLogsButton.addActionListener(e -> fetchServerLogsAndDisplay());

JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
buttonPanel.add(clientLogsButton);
buttonPanel.add(serverLogsButton);

add(buttonPanel, BorderLayout.SOUTH);

// Frame Settings
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500, 400);
setLocationRelativeTo(null);
setVisible(true);

// Initially fetch client logs
fetchClientLogsAndDisplay();
}

private void fetchClientLogsAndDisplay() {
fetchLogsAndDisplay("client_logs.db", "client_logs");
}

private void fetchServerLogsAndDisplay() {
fetchLogsAndDisplay("server_logs.db", "server_logs");
}

private void fetchLogsAndDisplay(String fileName, String tableName) {
logArea.setText(""); // Clear existing logs

try {
// Load SQLite JDBC driver
Class.forName("org.sqlite.JDBC");

// Construct the absolute path to the database file
String dbUrl = "jdbc:sqlite:" + fileName;

// Connect to the SQLite database
Connection connection = DriverManager.getConnection(dbUrl);

// Query to retrieve logs
String query = "SELECT * FROM " + tableName;

// Prepare the statement
PreparedStatement preparedStatement = connection.prepareStatement(query);

// Execute the query
ResultSet resultSet = preparedStatement.executeQuery();

// Display logs in the GUI
while (resultSet.next()) {
String logMessage = resultSet.getString("log_message");
String timestamp = resultSet.getString("timestamp");
logArea.append("[" + timestamp + "] " + logMessage + "\n");
}

// Close the resources
resultSet.close();
preparedStatement.close();
connection.close();

} catch (Exception e) {
e.printStackTrace();
}
}






public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
new LogReaderGUI();
});
}
}
Loading

0 comments on commit 4b6adb1

Please sign in to comment.