Skip to content

Commit abb8e51

Browse files
committed
Code Update
* Removed the History tag in readme files * fixed and activated the filezip and fileunzip programs * Fixed a crash in file management when running ls (program was trying to hash a directory) * create a _userhomedirectory variable to store the default user home directory * Updated BuildSigner to be more verbose and output to be more readable
1 parent 156ad81 commit abb8e51

File tree

9 files changed

+252
-308
lines changed

9 files changed

+252
-308
lines changed

Source/Cataphract/API/Astaroth/Readme.txt

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,6 @@ Author: DAK404 (https://github.com/DAK404)
2323
This Package provides utilities to handle date/time efficiently. Can also print a calendar,
2424
helpful for users and scripting.
2525

26-
27-
-[ HISTORY ]-
28-
29-
While working on Truncheon (then called Lamashtu before being cancelled and reworked),
30-
date/time handling became essential since the program would write log files. Additionally,
31-
for scripting, end users could not print the date and time information. At that point of
32-
time, WraithEdit.java handled the logging and used the java.util.Date class.
33-
34-
This created a problem.
35-
36-
For example, let us consider 3 classes: A, B and C.
37-
38-
If class A uses java.util.Date, class B uses java.time.LocalDateTime and class C uses a 3rd
39-
party library or java.text.date to implement the same features, the memory usage would be
40-
very high due to the number of classes loaded into the memory for runtime.
41-
42-
Current implementation has solved this issue by providing a single class that shall return
43-
the date/time information.
44-
45-
4626
-[ DETAILS ]-
4727

4828
The following classes are implemented in Astaroth Package:

Source/Cataphract/API/Dragon/Readme.txt

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,45 +23,6 @@ Author: DAK404 (https://github.com/DAK404)
2323
This Package provides utilities to create, manage and delete user accounts. Also provides a
2424
class for authenticating user credentials.
2525

26-
27-
-[ HISTORY ]-
28-
29-
While working on Zen Quantum, it was essential to have a class that handled authentication.
30-
Therefore a new package called "Anima" was created. Anima was aimed to contain all user
31-
account management utilities. The following functions were implemented:
32-
33-
* AddUser.java
34-
* CreateDB.java
35-
* LoginAPI.java
36-
37-
AddUser.java -> Contained code to add a user to the database. The code was non-modular and
38-
did not effectively handle invalid credentials.
39-
40-
CreateDB.java -> Contained code to create a database file, a table to hold the user details.
41-
CreateDB was called by the setup program.
42-
43-
LoginAPI.java -> Contained code to handle credential authentication. It was inefficient
44-
since it required 3 variables to check the validity of the credentials.
45-
46-
In Mosaic, UpdateCredentials.java was introduced. It was aimed to update the user
47-
credentials. Again, the code was non-modular, which made it very difficult to work on,
48-
although it provided the required functionality of updating credentials.
49-
50-
In Truncheon, package was renamed to Dragon. The class was renamed to ModifyAccount.java.
51-
With the privilege system in place, it was now necessary to check for the privilege to
52-
promote or demote users. There was no dedicated method that would return the privilege of
53-
the user, therefore, it had to be manually queried and then stored in a variable. It is also
54-
notable that DeleteAccount.java was created which helped in deleting accounts. With the
55-
privilege system, an administrator could now delete other user accounts.
56-
57-
In Truncheon: Katana, the LoginAPI, now renamed to LoginAuth.java, had an option to query
58-
and return privileges therefore it was easier to implement features without rewriting the
59-
logic to query and acquire the privilege value from the database.
60-
61-
Currently, the class is named as Login.java for a better nomenclature. It is also modular,
62-
therefore the code is easier to read and develop upon.
63-
64-
6526
-[ DETAILS ]-
6627

6728
The classes currently implemented in this package are:

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

Lines changed: 51 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,11 @@
1-
/*
2-
* |
3-
* ||
4-
* |||||| ||||||||| |||||||| ||||||||| ||||||| ||| ||| ||||||| ||||||||| |||||| ||||||||
5-
* ||| || ||| || || ||| ||| || || ||| |||
6-
* ||| |||||||| ||| |||||||| |||||| |||||||| |||||| |||||||| ||| |||
7-
* ||| ||| ||| ||| ||| ||| ||| ||| ||| || || ||| ||| ||| |||
8-
* |||||| ||| ||| ||| ||| ||| ||| ||| ||| || || ||| ||| |||||| |||
9-
* ||
10-
* |
11-
*
12-
* A Cross Platform OS Shell
13-
* Powered By Truncheon Core
14-
*/
15-
161
package Cataphract.API.Wraith.Archive;
172

18-
import java.io.FileInputStream;
3+
import java.io.FileInputStream;
194
import java.io.FileNotFoundException;
205
import java.io.FileOutputStream;
21-
226
import java.nio.file.Files;
237
import java.nio.file.Path;
248
import java.nio.file.Paths;
25-
269
import java.util.zip.ZipEntry;
2710
import java.util.zip.ZipInputStream;
2811

@@ -32,67 +15,70 @@
3215
import Cataphract.API.Wraith.FileWrite;
3316

3417
/**
35-
* A utility class for unzipping files.
36-
*
37-
* @author DAK404 (https://github.com/DAK404)
38-
* @version 1.0.0 (11-October-2023, Cataphract)
39-
* @since 0.0.1 (Cataphract 0.0.1)
40-
*/
18+
* A utility class for unzipping files.
19+
*
20+
* @author DAK404 (https://github.com/DAK404)
21+
* @version 1.0.0 (11-October-2023, Cataphract)
22+
* @since 0.0.1 (Cataphract 0.0.1)
23+
*/
4124
public class FileUnzip
4225
{
4326
/** Store value of user privileges. */
44-
private boolean isUserAdmin = false;
27+
private boolean _isUserAdmin = false;
4528

46-
/** Store value of the update mode; True if program is updating, False if program is not*/
29+
/** Store value of the update mode; True if program is updating, False if program is not */
4730
private boolean updateMode = false;
4831

4932
/**
50-
* Constructor to check if the current user is an administrator or not.
51-
*
52-
* @param username The currently logged in username.
53-
* @throws Exception Throws any exceptions encountered during runtime.
54-
*/
55-
public FileUnzip(String username)throws Exception
33+
* Constructor to check if the current user is an administrator or not.
34+
*
35+
* @param username The currently logged in username.
36+
* @throws Exception Throws any exceptions encountered during runtime.
37+
*/
38+
public FileUnzip(String username) throws Exception
5639
{
57-
isUserAdmin = new Login(username).checkPrivilegeLogic();
40+
_isUserAdmin = new Login(username).checkPrivilegeLogic();
5841
}
5942

6043
/**
61-
* Unzips a user file in the specified destination directory
62-
*
63-
* @param fileName Name of the file to be unzipped.
64-
* @param unzipDestination Destination for the file to be unzipped in.
65-
* @throws Exception Throws any exceptions encountered during runtime.
66-
*/
67-
public void unzip(String fileName, String unzipDestination)throws Exception
44+
* Unzips a user file in the specified destination directory
45+
*
46+
* @param fileName Name of the file to be unzipped.
47+
* @param unzipDestination Destination for the file to be unzipped in.
48+
* @throws Exception Throws any exceptions encountered during runtime.
49+
*/
50+
public void unzip(String fileName, String unzipDestination) throws Exception
6851
{
52+
fileName = IOStreams.convertFileSeparator(fileName);
53+
unzipDestination = IOStreams.convertFileSeparator(unzipDestination);
6954
// Check the policy if file unzip is allowed in the policy file, can be bypassed by the accounts with administrator privileges
70-
if(new PolicyCheck().retrievePolicyValue("filemgmt").equals("on") || isUserAdmin)
71-
unzipLogic(fileName, unzipDestination);
55+
if (new PolicyCheck().retrievePolicyValue("filemgmt").equals("on") || _isUserAdmin)
56+
unzipLogic(fileName, unzipDestination);
7257
else
73-
IOStreams.printError("Policy Management System - Permission Denied.");
58+
IOStreams.printError("Policy Management System - Permission Denied.");
7459
}
7560

7661
/**
77-
* Installs an update by unzipping the "Update.zip" file.
78-
*
79-
* @throws Exception Throws any exceptions encountered during runtime.
80-
*/
81-
public void installUpdate()throws Exception
62+
* Installs an update by unzipping the "Update.zip" file.
63+
*
64+
* @throws Exception Throws any exceptions encountered during runtime.
65+
*/
66+
public void installUpdate() throws Exception
8267
{
8368
updateMode = true;
84-
if(new PolicyCheck().retrievePolicyValue("update").equals("on") || isUserAdmin)
85-
unzipLogic("./Update.zip", "./");
69+
if (new PolicyCheck().retrievePolicyValue("update").equals("on") || _isUserAdmin)
70+
unzipLogic(IOStreams.convertFileSeparator(".|Update.zip"), IOStreams.convertFileSeparator(".|"));
8671
else
87-
IOStreams.printError("Policy Management System - Permission Denied.");
72+
IOStreams.printError("Policy Management System - Permission Denied.");
73+
updateMode = false;
8874
}
8975

9076
/**
91-
* Unzips a given zip file into the specified output directory.
92-
*
93-
* @param zipFilePath Path to the zip file.
94-
* @param outputDirectory Directory where the unzipped files will be placed.
95-
*/
77+
* Unzips a given zip file into the specified output directory.
78+
*
79+
* @param zipFilePath Path to the zip file.
80+
* @param outputDirectory Directory where the unzipped files will be placed.
81+
*/
9682
private void unzipLogic(String zipFilePath, String outputDirectory)
9783
{
9884
try
@@ -121,8 +107,8 @@ private void unzipLogic(String zipFilePath, String outputDirectory)
121107
// Create directories for file entries and write the file content
122108
Files.createDirectories(entryPath.getParent());
123109
try
124-
{
125-
if(updateMode)
110+
{
111+
if (updateMode)
126112
{
127113
IOStreams.printInfo("Installing File: " + entryName);
128114
FileWrite.logger("Installing: " + entryName, "Update");
@@ -132,18 +118,20 @@ private void unzipLogic(String zipFilePath, String outputDirectory)
132118
int bytesRead;
133119

134120
while ((bytesRead = zipIn.read(buffer)) != -1)
135-
fos.write(buffer, 0, bytesRead);
121+
{
122+
fos.write(buffer, 0, bytesRead);
123+
}
124+
fos.close(); // Close the FileOutputStream here
136125
}
137-
catch(Exception e)
126+
catch (Exception e)
138127
{
139128
IOStreams.printError("File Error: " + entryName);
140129
}
141130
}
142131
}
143132
zipIn.closeEntry();
144-
fos.close();
145-
}
146-
catch(Exception e)
133+
}
134+
catch (Exception e)
147135
{
148136
IOStreams.println("Error: " + e);
149137
e.printStackTrace();

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737
public class FileZip
3838
{
3939
/** Store value of user privileges. */
40-
private boolean isUserAdmin = false;
40+
private boolean _isUserAdmin = false;
41+
42+
/** Store the username of the current user */
43+
private String _username = "";
4144

4245
/**
4346
* Constructor to check if the current user is an administrator or not.
@@ -47,7 +50,8 @@ public class FileZip
4750
*/
4851
public FileZip(String username)throws Exception
4952
{
50-
isUserAdmin = new Login(username).checkPrivilegeLogic();
53+
_username = username;
54+
_isUserAdmin = new Login(username).checkPrivilegeLogic();
5155
}
5256

5357
/**
@@ -59,11 +63,12 @@ public FileZip(String username)throws Exception
5963
*/
6064
public void zipFile(String zipFileName, String directoryToCompress) throws Exception
6165
{
66+
directoryToCompress = IOStreams.convertFileSeparator(directoryToCompress);
6267
// Check the policy if file zipping is allowed in the policy file, can be bypassed by the accounts with administrator privileges
63-
if(new PolicyCheck().retrievePolicyValue("filemgmt").equals("on") || isUserAdmin)
68+
if(new PolicyCheck().retrievePolicyValue("filemgmt").equals("on") || _isUserAdmin)
6469
{
6570
// Create a FileOutputStream for the zip file
66-
FileOutputStream fos = new FileOutputStream(zipFileName);
71+
FileOutputStream fos = new FileOutputStream(IOStreams.convertFileSeparator(".|Users|Cataphract|" + _username + "|") + zipFileName);
6772
// Create a ZipOutputStream using the FileOutputStream
6873
ZipOutputStream zipOut = new ZipOutputStream(fos);
6974

@@ -95,18 +100,18 @@ private void zipFileLogic(File fileToZip, String fileName, ZipOutputStream zipOu
95100
if (fileToZip.isDirectory())
96101
{
97102
// If it's a directory, create a zip entry for it
98-
if (fileName.endsWith("/"))
103+
if (fileName.endsWith(File.separator))
99104
zipOut.putNextEntry(new ZipEntry(fileName));
100105
else
101-
zipOut.putNextEntry(new ZipEntry(fileName + "/"));
106+
zipOut.putNextEntry(new ZipEntry(fileName + File.separator));
102107

103108
// Get the list of children files and recursively zip them
104109
File[] children = fileToZip.listFiles();
105110
if (children != null)
106111
{
107112
for (File childFile : children)
108113
{
109-
zipFileLogic(childFile, fileName + "/" + childFile.getName(), zipOut);
114+
zipFileLogic(childFile, fileName + File.separator + childFile.getName(), zipOut);
110115
}
111116
}
112117
}

Source/Cataphract/API/Wraith/FileManagement.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import Cataphract.API.Dragon.Login;
2929
import Cataphract.API.Minotaur.Cryptography;
3030
import Cataphract.API.Minotaur.PolicyCheck;
31+
import Cataphract.API.Wraith.Archive.FileZip;
32+
import Cataphract.API.Wraith.Archive.FileUnzip;
3133

3234
/**
3335
* A utility class for file management.
@@ -44,6 +46,8 @@ public class FileManagement
4446
private String _name = "";
4547
/** Store the present working directory during file management */
4648
private String _presentWorkingDirectory = "";
49+
/** Store the default user home directory */
50+
private String _userHomeDirectory = "";
4751

4852
/** Instantiate Console to get user inputs. */
4953
private Console console = System.console();
@@ -61,7 +65,8 @@ public FileManagement(String username)throws Exception
6165
// Set the name of the user to the global variable
6266
_name = new Login(username).getNameLogic();
6367
// Initialize the present working directory
64-
_presentWorkingDirectory = ".|Users|Cataphract|" + _username + "|";
68+
_userHomeDirectory = ".|Users|Cataphract|" + _username + "|";
69+
_presentWorkingDirectory = _userHomeDirectory;
6570
}
6671

6772
/*****************************************
@@ -220,7 +225,7 @@ private final void navPreviousDirectory()throws Exception
220225
*/
221226
private final void resetToHomeDirectory()
222227
{
223-
_presentWorkingDirectory = ".|Users|Cataphract|" + _username + '|' ;
228+
_presentWorkingDirectory = _userHomeDirectory;
224229
}
225230

226231
/**
@@ -231,7 +236,7 @@ private final void resetToHomeDirectory()
231236
*/
232237
private final void makeDirectory(String fileName) throws Exception
233238
{
234-
new File(_presentWorkingDirectory + fileName).mkdirs();
239+
new File(IOStreams.convertFileSeparator(_presentWorkingDirectory) + fileName).mkdirs();
235240
}
236241

237242
/**
@@ -340,7 +345,7 @@ private final void listEntities() throws Exception
340345
for (File file : dPath.listFiles())
341346
{
342347
// Format and print the file or directory information
343-
System.out.format(format, file.getName().replace(_username, _name), file.length() / 1024 + " KB", file.isDirectory() ? "Directory" : "File", Cryptography.fileToMD5(file));
348+
System.out.format(format, file.getName().replace(_username, _name), file.length() / 1024 + " KB", file.isDirectory() ? "Directory" : "File", file.isDirectory() ? "" : Cryptography.fileToMD5(file));
344349
}
345350
// Print a newline for better formatting
346351
System.out.println();
@@ -401,7 +406,6 @@ public void fileManagementLogic()throws Exception
401406
// Check if the user is logged in
402407
if (login())
403408
{
404-
System.out.println(IOStreams.convertToNionSeparator(IOStreams.convertFileSeparator(_presentWorkingDirectory)));
405409
String inputValue = "";
406410
// Loop to continuously read and execute commands until 'exit' is entered
407411
do
@@ -604,6 +608,22 @@ private void grinchInterpreter(String command)throws Exception
604608
// Exit the interpreter
605609
break;
606610

611+
case "zip":
612+
// Check if the command has the correct number of arguments
613+
if (commandArray.length < 3)
614+
IOStreams.printError("Invalid Syntax.");
615+
else
616+
new FileZip(_username).zipFile(commandArray[1], _presentWorkingDirectory + commandArray[2]);
617+
break;
618+
619+
case "unzip":
620+
// Check if the command has the correct number of arguments
621+
if (commandArray.length < 3)
622+
IOStreams.printError("Invalid Syntax.");
623+
else
624+
new FileUnzip(_username).unzip(_presentWorkingDirectory + commandArray[1], _presentWorkingDirectory + commandArray[2]);
625+
break;
626+
607627
default:
608628
// Pass the command to the Anvil interpreter for further processing
609629
Anvil.anvilInterpreter(commandArray);

0 commit comments

Comments
 (0)