-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
613 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} | ||
} |
Oops, something went wrong.