unprotected file scenario

This commit is contained in:
nedlir 2022-04-22 00:45:05 +02:00
parent 7ad223b981
commit a08ca53a0d
1 changed files with 27 additions and 15 deletions

View File

@ -43,13 +43,13 @@ public class Controller {
private Image powerpointImage; private Image powerpointImage;
private Image progressOnGoing; private Image progressOnGoing;
private Image progressFinished; private Image progressFinished;
@FXML @FXML
private Text fileText; private Text fileText;
@FXML @FXML
private Text invalidFileText; private Text invalidFileText;
@FXML @FXML
private ImageView progressBarBrowse; private ImageView progressBarBrowse;
@ -60,19 +60,19 @@ public class Controller {
public void initialize() { public void initialize() {
anchorPane.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY))); anchorPane.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
invalidFileText.setVisible(false); invalidFileText.setVisible(false);
progressBarBrowse.setVisible(false); progressBarBrowse.setVisible(false);
progressBarRemove.setVisible(false); progressBarRemove.setVisible(false);
try { try {
wordImage = new Image(getClass().getResourceAsStream("img/word.png")); wordImage = new Image(getClass().getResourceAsStream("img/word.png"));
powerpointImage = new Image(getClass().getResourceAsStream("img/powerpoint.png")); powerpointImage = new Image(getClass().getResourceAsStream("img/powerpoint.png"));
excelImage = new Image(getClass().getResourceAsStream("img/excel.png")); excelImage = new Image(getClass().getResourceAsStream("img/excel.png"));
progressOnGoing = new Image(getClass().getResourceAsStream("img/prog-bar-ongoing.gif")); progressOnGoing = new Image(getClass().getResourceAsStream("img/prog-bar-ongoing.gif"));
progressFinished = new Image(getClass().getResourceAsStream("img/prog-bar-complete.png")); progressFinished = new Image(getClass().getResourceAsStream("img/prog-bar-complete.png"));
} catch (Exception e) { } catch (Exception e) {
@ -84,14 +84,20 @@ public class Controller {
void browsePressed(ActionEvent event) { void browsePressed(ActionEvent event) {
invalidFileText.setVisible(false); invalidFileText.setVisible(false);
progressBarRemove.setVisible(false);
progressBarBrowse.setVisible(true); progressBarBrowse.setVisible(true);
progressBarBrowse.setImage(progressOnGoing); progressBarBrowse.setImage(progressOnGoing);
filePathText.setVisible(false);
try { try {
fileChooser = new FileChooser(); fileChooser = new FileChooser();
fileChooser.setTitle("Please Select a File"); fileChooser.setTitle("Please Select a File");
file = fileChooser.showOpenDialog(null); file = fileChooser.showOpenDialog(null);
filePath = file.toString(); filePath = file.toString();
fileName = file.getName(); fileName = file.getName();
filePathText.setVisible(true);
filePathText.setText(filePath); filePathText.setText(filePath);
fileType = getFileType(); fileType = getFileType();
@ -106,6 +112,7 @@ public class Controller {
@FXML @FXML
void removePasswordPressed(ActionEvent event) { void removePasswordPressed(ActionEvent event) {
if (file == null) { if (file == null) {
return; return;
} }
@ -118,14 +125,14 @@ public class Controller {
// show progress // show progress
progressBarRemove.setVisible(true); progressBarRemove.setVisible(true);
progressBarRemove.setImage(progressOnGoing); progressBarRemove.setImage(progressOnGoing);
FileManipulator manipulator = new FileManipulator(filePath, "./"); // create new object to manipulate the file FileManipulator manipulator = new FileManipulator(filePath, "./"); // create new object to manipulate the file
manipulator.extractFile(); // extract XML from file manipulator.extractFile(); // extract XML from file
XMLParser parser = new XMLParser(manipulator); // create new object to parse the XML XMLParser parser = new XMLParser(manipulator); // create new object to parse the XML
if (parser.isExistSecurityElement()) // if the file has a password if (parser.isExistSecurityElement()) // if the file has a password protection as a read-only file
{ {
parser.removeElementOfSecurity(); // remove hash node from XML file parser.removeElementOfSecurity(); // remove hash node from XML file
@ -133,17 +140,17 @@ public class Controller {
manipulator.insertFile(); // write back to file manipulator.insertFile(); // write back to file
manipulator.removeXMLFile(); // cleans the xml extracted from origin file
fileText.setText(fileFinishedMessage()); fileText.setText(fileFinishedMessage());
progressBarRemove.setImage(progressFinished); } else // if there is no security element in the xml file, there is no read-only protection on it
}
else // if there is no security element in the xml file, there is no read-only protection on it
{ {
manipulator.removeXMLFile(); // cleans the xml extracted from origin file fileText.setText(notReadOnlyMessage());
} }
manipulator.removeXMLFile(); // cleans the xml extracted from origin file
progressBarRemove.setImage(progressFinished);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -219,4 +226,9 @@ public class Controller {
return messageOnScreen; return messageOnScreen;
} }
private String notReadOnlyMessage() {
String messageOnScreen = "Officer Breaker couldn't find any \"read-only\" restriction on the file. \n \nTry another file?";
return messageOnScreen;
}
} }