-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from teebow1e/refactor
Refactor
- Loading branch information
Showing
9 changed files
with
158 additions
and
19 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 @@ | ||
teebow1e,password,admin |
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,55 @@ | ||
package loganalyzer; | ||
|
||
public class Log { | ||
public Log(String ipAddress, String timeStamp, String method, String protocol, String requestPath, int statusCode, int contentLength, String userAgent) { | ||
this.ipAddress = ipAddress; | ||
this.timeStamp = timeStamp; | ||
this.method = method; | ||
this.protocol = protocol; | ||
this.requestPath = requestPath; | ||
this.statusCode = statusCode; | ||
this.contentLength = contentLength; | ||
this.userAgent = userAgent; | ||
} | ||
|
||
public String getIpAddress() { | ||
return ipAddress; | ||
} | ||
|
||
public String getTimestamp() { | ||
return timeStamp; | ||
} | ||
|
||
public String getMethod() { | ||
return method; | ||
} | ||
|
||
public String getProtocol() { | ||
return protocol; | ||
} | ||
|
||
public String getRequestPath() { | ||
return requestPath; | ||
} | ||
|
||
public int getStatusCode() { | ||
return statusCode; | ||
} | ||
|
||
public int getContentLength() { | ||
return contentLength; | ||
} | ||
|
||
public String getUserAgent() { | ||
return userAgent; | ||
} | ||
|
||
private final String ipAddress; | ||
private final String timeStamp; | ||
private final String method; | ||
private final String protocol; | ||
private final String requestPath; | ||
private final int statusCode; | ||
private final int contentLength; | ||
private final String userAgent; | ||
} |
15 changes: 4 additions & 11 deletions
15
src/main/java/LogAnalyzer/LogCrawl.java → src/main/java/loganalyzer/LogParser.java
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 |
---|---|---|
@@ -1,40 +1,33 @@ | ||
package LogAnalyzer; | ||
package loganalyzer; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
|
||
public class LogCrawl { | ||
public class LogParser { | ||
public static void main(String[] args) { | ||
// Define the path to the log file | ||
String logFilePath = "logs/apache/access_log_100.log"; | ||
|
||
// Create a Path object for the log file | ||
Path logPath = Paths.get(logFilePath); | ||
|
||
try { | ||
// Check if the log file exists | ||
if (Files.exists(logPath)) { | ||
// Read the contents of the log file | ||
List<String> lines = Files.readAllLines(logPath); | ||
|
||
// Print the first 5 lines of the log file | ||
System.out.println("First 5 lines of " + logPath.getFileName() + ":"); | ||
int lineCount = 0; | ||
for (String line : lines) { | ||
System.out.println(line); | ||
lineCount++; | ||
if (lineCount >= 5) { | ||
break; // Exit the loop after reading 5 lines | ||
break; | ||
} | ||
} | ||
} else { | ||
System.out.println("Log file does not exist: " + logPath); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
System.out.println("Error reading log file: " + e.getMessage()); | ||
} | ||
} | ||
} |
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
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
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,25 @@ | ||
package usermanagement; | ||
|
||
public class User { | ||
private final String username; | ||
private final String password; | ||
private final String role; | ||
|
||
public User(String username, String password, String role) { | ||
this.username = username; | ||
this.password = password; | ||
this.role = role; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public String getRole() { | ||
return role; | ||
} | ||
} |
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,37 @@ | ||
package usermanagement; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class UserManagement { | ||
public static List<User> readUserFile(String fileName) { | ||
List<User> userList = new ArrayList<>(); | ||
try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) { | ||
String line; | ||
while ((line = reader.readLine()) != null) { | ||
String[] parts = line.split(","); | ||
if (parts.length == 3) { | ||
String username = parts[0]; | ||
String password = parts[1]; | ||
String role = parts[2]; | ||
userList.add(new User(username, password, role)); | ||
} | ||
} | ||
} catch (IOException e) { | ||
System.out.println("Error reading file: " + e.getMessage()); | ||
} | ||
return userList; | ||
} | ||
|
||
public static boolean authenticateUser(List<User> userList, String username, String password) { | ||
for (User user : userList) { | ||
if (user.getUsername().equals(username) && user.getPassword().equals(password)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
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
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