Skip to content

Commit 1d0da9a

Browse files
committed
Code Update
* Remove policy Auth * Activate policy features to FileDownload * Activate script feature into FileManagement * Activate policy features to FileRead and FileWrite
1 parent 5fbf6a2 commit 1d0da9a

File tree

5 files changed

+201
-92
lines changed

5 files changed

+201
-92
lines changed

Source/Cataphract/API/Minotaur/PolicyManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class PolicyManager
3939
private boolean _isUserAdmin = false;
4040

4141
/** Stores the default Cataphract values in an array.*/
42-
public final String [] resetValues = {"auth", "update", "download", "script", "filemgmt", "read", "edit", "policy", "account_create", "account_delete", "account_modify"};
42+
public final String [] resetValues = {"update", "download", "script", "filemgmt", "read", "edit", "policy", "account_create", "account_delete", "account_modify"};
4343

4444
/** Stores the path of the policy file.*/
4545
private final String policyFileName = "./System/Cataphract/Private/Policy.burn";

Source/Cataphract/API/Wraith/FileDownload.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,15 @@ public final boolean downloadFile(String URL, String fileName) throws Exception
6565

6666
// Attempt to download the file using NIO only if the policy is configured to "on"
6767
if (new PolicyCheck().retrievePolicyValue("download").equals("on") || _isUserAdmin)
68-
status = downloadUsingNIO(URL, fileName);
69-
70-
// Check for an invalid URL
71-
if (URL == null || fileName == null || URL.equalsIgnoreCase("") || fileName.equalsIgnoreCase(""))
72-
IOStreams.printError("Invalid File Name. Enter a valid file name.");
68+
{
69+
status = downloadUsingNIO(URL, fileName);
70+
71+
// Check for an invalid URL
72+
if (URL == null || fileName == null || URL.equalsIgnoreCase("") || fileName.equalsIgnoreCase(""))
73+
IOStreams.printError("Invalid File Name. Enter a valid file name.");
74+
}
75+
else
76+
IOStreams.printError("Policy Management System - Permission Denied.");
7377

7478
return status;
7579
}
@@ -93,7 +97,7 @@ public final boolean downloadUpdate() throws Exception
9397
status = downloadUsingNIO(updateFileURL, "Update.zip");
9498
}
9599
else
96-
IOStreams.println("Policy Restriction: Program Update Disallowed! Please contact the Administrator for more information.");
100+
IOStreams.printError("Policy Management System - Permission Denied.");
97101

98102
return status;
99103
}

Source/Cataphract/API/Wraith/FileManagement.java

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

18+
import java.io.BufferedReader;
319
import java.io.Console;
420
import java.io.File;
5-
21+
import java.io.FileReader;
622
import java.nio.file.Files;
723
import java.nio.file.StandardCopyOption;
824

925
import Cataphract.API.Anvil;
1026
import Cataphract.API.IOStreams;
27+
import Cataphract.API.Dragon.Login;
1128
import Cataphract.API.Minotaur.Cryptography;
12-
29+
import Cataphract.API.Minotaur.PolicyCheck;
30+
31+
/**
32+
* A utility class for file management.
33+
*
34+
* @author DAK404 (https://github.com/DAK404)
35+
* @version 1.3.0 (12-August-2024, Cataphract)
36+
* @since 0.0.1 (Zen Quantum 0.0.1)
37+
*/
1338
public class FileManagement
1439
{
1540
private String _username = "";
@@ -212,19 +237,68 @@ private final void changeDirectory(String destination)throws Exception
212237

213238
public void fileManagementLogic()throws Exception
214239
{
215-
// AUTHENTICATION LOGIC OMITTED FOR THE MOMENT.
216-
if(login())
240+
if (new PolicyCheck().retrievePolicyValue("filemgmt").equals("on") || new Login(_username).checkPrivilegeLogic())
241+
{
242+
if(login())
243+
{
244+
String inputValue = "";
245+
do
246+
{
247+
inputValue = console.readLine(_name + "@" + _presentWorkingDirectory.replace(_username, _name) + "> ");
248+
grinchInterpreter(inputValue);
249+
}
250+
while(!inputValue.equalsIgnoreCase("exit"));
251+
}
252+
else
253+
IOStreams.printError("Invalid Credentials.");
254+
}
255+
else
256+
IOStreams.printError("Policy Management System - Permission Denied.");
257+
}
258+
259+
public void fileManagementLogic(String scriptFileName)throws Exception
260+
{
261+
if ((new PolicyCheck().retrievePolicyValue("filemgmt").equals("on") && new PolicyCheck().retrievePolicyValue("script").equals("on")) || new Login(_username).checkPrivilegeLogic())
217262
{
218-
String inputValue = "";
219-
do
263+
if(scriptFileName == null || scriptFileName.equalsIgnoreCase("") || scriptFileName.startsWith(" ") || new File(scriptFileName).isDirectory() || ! (new File("./Users/Truncheon/" + _username + "/" + scriptFileName + ".fmx").exists()))
220264
{
221-
inputValue = console.readLine(_name + "@" + _presentWorkingDirectory.replace(_username, _name) + "> ");
222-
grinchInterpreter(inputValue);
265+
IOStreams.printError("Invalid Script File!");
266+
}
267+
else
268+
{
269+
if(login())
270+
{
271+
//Initialize a stream to read the given file.
272+
BufferedReader br = new BufferedReader(new FileReader(scriptFileName));
273+
//Initialize a string to hold the contents of the script file being executed.
274+
String scriptLine;
275+
276+
//Read the script file, line by line.
277+
while ((scriptLine = br.readLine()) != "<EndGrinch>")
278+
{
279+
//Check if the line is a comment or is blank in the script file and skip the line.
280+
if(scriptLine.startsWith("#") || scriptLine.equalsIgnoreCase(""))
281+
continue;
282+
283+
//Check if End Script command is encountered, which will stop the execution of the script.
284+
else if(scriptLine.equalsIgnoreCase("End Script"))
285+
break;
286+
287+
//Read the command in the script file, and pass it on to menuLogic(<command>) for it to be processed.
288+
grinchInterpreter(scriptLine);
289+
}
290+
291+
//Close the streams, run the garbage collector and clean.
292+
br.close();
293+
}
294+
else
295+
{
296+
IOStreams.printError("Invalid Credentials.");
297+
}
223298
}
224-
while(!inputValue.equalsIgnoreCase("exit"));
225299
}
226300
else
227-
IOStreams.printError("Invalid Credentials.");
301+
IOStreams.printError("Policy Management System - Permission Denied.");
228302
}
229303

230304
private void grinchInterpreter(String command)throws Exception
@@ -277,14 +351,14 @@ private void grinchInterpreter(String command)throws Exception
277351
if(commandArray.length < 2)
278352
IOStreams.printError("Invalid Syntax.");
279353
else
280-
FileWrite.editFile(commandArray[1], _presentWorkingDirectory);
354+
new FileWrite(_username).editFile(commandArray[1], _presentWorkingDirectory);
281355
break;
282356

283357
case "read":
284358
if(commandArray.length < 2)
285359
IOStreams.printError("Invalid Syntax.");
286360
else
287-
new FileRead().readUserFile(_presentWorkingDirectory + commandArray[1]);
361+
new FileRead(_username).readUserFile(_presentWorkingDirectory + commandArray[1]);
288362
break;
289363

290364
case "pwd":

Source/Cataphract/API/Wraith/FileRead.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.io.BufferedReader;
2121

2222
import Cataphract.API.IOStreams;
23+
import Cataphract.API.Dragon.Login;
24+
import Cataphract.API.Minotaur.PolicyCheck;
2325
import Cataphract.API.Build;
2426

2527
/**
@@ -31,6 +33,8 @@
3133
*/
3234
public class FileRead
3335
{
36+
/** Store the current username to check privileges */
37+
private String _username = "";
3438

3539
/** Flag to indicate whether help mode is enabled. */
3640
private boolean helpMode = false;
@@ -39,11 +43,21 @@ public class FileRead
3943
private static File fileName = null;
4044

4145
/**
42-
* Sole constructor. (For invocation by subclass constructors, typically implicit.)
46+
*
4347
*/
4448
public FileRead()
4549
{
4650
}
51+
52+
/**
53+
*
54+
*
55+
* @param username
56+
*/
57+
public FileRead(String username)
58+
{
59+
_username = username;
60+
}
4761

4862
/**
4963
* Checks the validity of the file name.
@@ -159,10 +173,15 @@ else if (fileContents.startsWith("#"))
159173
*/
160174
public void readUserFile(String userFileName) throws Exception
161175
{
162-
// Set the file name
163-
fileName = new File(userFileName);
164-
// Perform file reading logic
165-
readFileLogic();
176+
if (new PolicyCheck().retrievePolicyValue("update").equals("on") || new Login(_username).checkPrivilegeLogic())
177+
{
178+
// Set the file name
179+
fileName = new File(userFileName);
180+
// Perform file reading logic
181+
readFileLogic();
182+
}
183+
else
184+
IOStreams.printError("Policy Management System - Permission Denied.");
166185
}
167186

168187
/**

0 commit comments

Comments
 (0)