Skip to content

Commit bc58227

Browse files
committed
Code update
* Fix a bug where login attempts remaining was not reset * added garbage collector explicitly to avoid memory spiking for some reason after locking and unlocking console. * Added assert in script mode to check if a script is called by an already running script (and denies execution) * Activate script functionality * Fix logic for correct policy checking * Update build information * Fix strings to be uniform across various modules * Add feature to list all users during account modification and deletion in Login class * Add the feature to delete an account using the user hash * Remove win95/98 easter egg :( * Add banner to SycoraxKernel class * Add string builder to reduce memory footprint
1 parent fc81670 commit bc58227

File tree

11 files changed

+213
-150
lines changed

11 files changed

+213
-150
lines changed

Source/Cataphract/API/Build.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class Build
3939
""";
4040

4141
/** An array that holds the values for Kernel Name, version, build date, build ID and the kernel branch/build type. */
42-
public final static String[] _BuildInfo = {"Cataphract", "1.0.0", "27-April-2024", "20240427-182445_NION", "Development"};
42+
public final static String[] _BuildInfo = {"Cataphract", "1.3.0", "14-August-2024", "20240814-003624_NION", "Development"};
4343

4444
/**
4545
* Sole constructor. (For invocation by subclass constructors, typically implicit.)
@@ -58,7 +58,7 @@ public static void viewBuildInfo()
5858
//print the branding string.
5959
IOStreams.println(_Branding + "\n");
6060
//new Build().debug();
61-
IOStreams.printWarning("Features disabled until integration tests are complete.\n\nIntegration test ongoing.\nCore features are almost complete.\n");
61+
IOStreams.printDebug("Development Build. Use at your own risk!");
6262

6363
debug();
6464
}

Source/Cataphract/API/Dragon/AccountCreate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public final void accountCreateLogic()throws Exception
183183
}
184184
//If the policy for usermanagement system is not setup, incorrect or the policy file is corrupt, display the same
185185
else
186-
IOStreams.printError("Policy Configuration Error!");
186+
IOStreams.printError("Policy Management System - Permission Denied.");
187187
System.gc();
188188
}
189189

Source/Cataphract/API/Dragon/AccountDelete.java

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void deleteUserAccount() throws Exception
7979
userManagementConsoleDelete();
8080
}
8181
else
82-
IOStreams.printError("Policy Configuration Error!");
82+
IOStreams.printError("Policy Management System - Permission Denied.");
8383
}
8484

8585
/**
@@ -126,6 +126,10 @@ private void userManagementConsoleDelete()throws Exception
126126
}
127127
break;
128128

129+
case "list":
130+
new Login(_currentUsername).listAllUserAccounts();
131+
break;
132+
129133
default:
130134
// Display error for unknown command
131135
IOStreams.printError("Command Not Found: " + command[0]);
@@ -151,33 +155,39 @@ private boolean accountDeletionLogic(String username) throws Exception
151155

152156
// Check if the username is "Administrator"
153157
if (username.equals(Cryptography.stringToSHA3_256("Administrator")))
154-
IOStreams.printError("Deletion of Administrator Account is not allowed!");
155-
else if (! new Login(Cryptography.stringToSHA3_256(username)).checkUserExistence())
156-
IOStreams.printError("User does not exist! Please enter a valid username.");
157-
else
158+
IOStreams.printError("Deletion of Administrator Account is not allowed!");
159+
else
158160
{
159-
try
161+
if (! new Login(Cryptography.stringToSHA3_256(username)).checkUserExistence() || ! new Login(username).checkUserExistence())
162+
{
163+
IOStreams.println("User does not exist! Please enter the correct username (or the username hash) to continue");
164+
}
165+
else
160166
{
161-
// Prompt user for confirmation
162-
if (console.readLine("Are you sure you wish to delete user account \"" + new Login(username).getNameLogic() + "\"? [ YES | NO ]\n> ").equalsIgnoreCase("yes"))
167+
try
163168
{
164-
// Delete account from database and directories
165-
status = deleteFromDatabase() & deleteDirectories(new File("./Users/Cataphract/" + username));
166-
// Print success message and exit
167-
IOStreams.printAttention("Account Successfully Deleted.");
168-
if(! _isCurrentUserAdmin)
169+
// Prompt user for confirmation
170+
if (console.readLine("Are you sure you wish to delete user account \"" + new Login(username).getNameLogic() + "\"? [ YES | NO ]\n> ").equalsIgnoreCase("yes"))
169171
{
170-
//wait for 5 seconds and then restart
171-
Thread.sleep(5000);
172-
System.exit(211);
172+
// Delete account from database and directories
173+
status = deleteFromDatabase() & deleteDirectories(new File("./Users/Cataphract/" + username));
174+
// Print success message and exit
175+
IOStreams.printAttention("Account Successfully Deleted.");
176+
if(! _isCurrentUserAdmin)
177+
{
178+
//wait for 5 seconds and then restart
179+
Thread.sleep(5000);
180+
System.exit(211);
181+
}
173182
}
174183
}
184+
catch (Exception e)
185+
{
186+
// Print error message for any exceptions
187+
IOStreams.printError("System Error: Unable to delete account.");
188+
}
175189
}
176-
catch (Exception e)
177-
{
178-
// Print error message for any exceptions
179-
IOStreams.printError("System Error: Unable to delete account.");
180-
}
190+
181191
}
182192

183193
return status;

Source/Cataphract/API/Dragon/AccountModify.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public final void accountModifyLogic()throws Exception
9090
System.gc();
9191
}
9292
else
93-
IOStreams.printError("Policy Configuration Error!");
93+
IOStreams.printError("Policy Management System - Permission Denied.");
9494

9595
// Trigger garbage collection
9696
System.gc();
@@ -182,6 +182,7 @@ private void accountManagementMenu()throws Exception
182182
break;
183183

184184
case "list":
185+
new Login(_currentUsername).listAllUserAccounts();
185186
break;
186187

187188
case "clear":
@@ -289,7 +290,7 @@ private void accountPromoteDemoteLogic(String action, String targetUser)throws E
289290

290291
/**
291292
* Logic to view account information by users with Administrator privileges
292-
*
293+
*
293294
* @param targetUser The user account intended to be viewed
294295
* @throws Exception Throws any exceptions encountered during runtime.
295296
*/
@@ -320,11 +321,6 @@ private void viewUserInformation(String targetUser) throws Exception
320321
}
321322
}
322323

323-
private void listAllUserAccounts()
324-
{
325-
//reuse code from FileManagement.java? It'd be easier to do so.
326-
}
327-
328324
/**
329325
* Method to change account name
330326
*/

Source/Cataphract/API/Dragon/Login.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
package Cataphract.API.Dragon;
1717

1818
import java.io.Console;
19+
import java.io.File;
1920
import java.sql.Connection;
2021
import java.sql.DriverManager;
2122
import java.sql.PreparedStatement;
2223
import java.sql.ResultSet;
2324

25+
import Cataphract.API.IOStreams;
26+
2427
/**
2528
* A class to handle the user login and authentication.
2629
*
@@ -111,6 +114,39 @@ public final boolean checkUserExistence() throws Exception
111114
return checkForExistingAccount();
112115
}
113116

117+
protected void listAllUserAccounts()throws Exception
118+
{
119+
// Check if the current user is an Administrator
120+
if(checkPrivilegeLogic())
121+
{
122+
// Define the format for displaying the usernames
123+
String format = "%1$-64s| %2$-32s| %3$-5s\n";
124+
String c = "-";
125+
126+
// Print a newline for better formatting
127+
System.out.println();
128+
129+
// Format and print the header for the user directory listing
130+
String disp = String.format(format, "Username", "Account Name", "Privileges");
131+
System.out.println(disp + c.repeat(disp.length()) + "\n");
132+
133+
// List the files in the ./Users/Cataphract directory
134+
File[] fileList = new File("./Users/Cataphract/").listFiles();
135+
136+
// Iterate through the list of files
137+
for(File users: fileList)
138+
{
139+
String usernames = users.getName();
140+
// Format and print the name, username and privileges
141+
System.out.format(String.format(format, usernames, new Login(usernames).getNameLogic(), new Login(usernames).checkPrivilegeLogic()));
142+
}
143+
144+
System.out.println();
145+
}
146+
else
147+
IOStreams.printError("Insufficient Privileges.");
148+
}
149+
114150
/**
115151
* Method to retrieve data from the database.
116152
*

Source/Cataphract/API/Wraith/Archive/FileUnzip.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void unzip(String fileName, String unzipDestination)throws Exception
7070
if(new PolicyCheck().retrievePolicyValue("filemgmt").equals("on") || isUserAdmin)
7171
unzipLogic(fileName, unzipDestination);
7272
else
73-
IOStreams.printError("Policy Configuration Error!");
73+
IOStreams.printError("Policy Management System - Permission Denied.");
7474
}
7575

7676
/**
@@ -84,7 +84,7 @@ public void installUpdate()throws Exception
8484
if(new PolicyCheck().retrievePolicyValue("update").equals("on") || isUserAdmin)
8585
unzipLogic("./Update.zip", "./");
8686
else
87-
IOStreams.printError("Policy Configuration Error!");
87+
IOStreams.printError("Policy Management System - Permission Denied.");
8888
}
8989

9090
/**

Source/Cataphract/API/Wraith/Archive/FileZip.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void zipFile(String zipFileName, String directoryToCompress) throws Excep
7777
fos.close();
7878
}
7979
else
80-
IOStreams.printError("Policy Configuration Error!");
80+
IOStreams.printError("Policy Management System - Permission Denied.");
8181
}
8282

8383
/**

Source/Cataphract/API/Wraith/FileDownload.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ public final boolean downloadUpdate() throws Exception
9898
}
9999
else
100100
IOStreams.printError("Policy Management System - Permission Denied.");
101-
102101
return status;
103102
}
104103

@@ -145,9 +144,6 @@ private boolean downloadUsingNIO(String urlStr, String fileName) throws Exceptio
145144
e.printStackTrace();
146145
}
147146

148-
// Explicitly request garbage collection (optional).
149-
System.gc();
150-
151147
// Return the status of the download
152148
return status;
153149
}

Source/Cataphract/API/Wyvern/NionUpdate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void updater()throws Exception
6969
IOStreams.printAttention("It is recommended to restart Cataphract for the updates to be reflected.");
7070
}
7171
else
72-
IOStreams.printError("Policy Configuration Error!");
72+
IOStreams.printError("Policy Management System - Permission Denied.");
7373
}
7474

7575
/**

Source/Cataphract/Core/Loader.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ private void loaderLogic()throws Exception
165165
System.exit(100);
166166
else
167167
{
168-
IOStreams.printError("Setup Failed! Reverting changes...");
169-
170-
//TODO: Delete /System and /Users directories
168+
IOStreams.printError("Setup Failed!");
171169
}
172170
break;
173171

@@ -535,8 +533,8 @@ private void guestShell() throws Exception
535533
case "login":
536534
new SycoraxKernel().startSycoraxKernel();
537535

538-
// A Windows 95/98 Easter Egg?
539-
IOStreams.println(3, 0, "It is now safe to turn off your PC ;)");
536+
Build.viewBuildInfo();
537+
IOStreams.println(3, 0, "Logout Successful");
540538
break;
541539

542540
default:

0 commit comments

Comments
 (0)