1 /********************************************************************************
2 *InternetCafe is a software solution that helps the management of Cybercafes
3 * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4 * Copyright (C) 2006 Guido Angelo Ingenito
5
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *******************************************************************************/
20
21 package base.jdbs.ui.command;
22
23 import java.io.File;
24 import java.security.KeyStore;
25
26 import org.apache.log4j.Logger;
27
28 import ui.command.Command;
29 import base.InternetCafe;
30 import base.jdbs.BackupDescriptor;
31 import base.jdbs.ConfigurationManager;
32 import base.jdbs.cryptography.asymmetric.AsymmetricKeyRing;
33 import base.jdbs.cryptography.asymmetric.KeyPair;
34 import base.jdbs.cryptography.symmetric.SymmetricKey;
35
36 /***
37 * @author skunk
38 *
39 */
40 public class RestoreBackupArtifactCommand extends Command {
41
42 private static final transient Logger logger = Logger.getLogger(RestoreBackupArtifactCommand.class.getName());
43
44 private final String guId;
45 private File outputDirectory = null;
46
47 public RestoreBackupArtifactCommand(String guId){
48 this.guId = guId;
49 }
50
51
52
53
54
55 @Override
56 protected void prologo() {
57 InternetCafe.setStatusBarMessage("Restoring a backup from the JDBS repository...");
58 javax.swing.JFileChooser outputDirectoryChooser = new javax.swing.JFileChooser();
59 outputDirectoryChooser.setDialogTitle("Select the output directory where the backup must be restored...");
60 outputDirectoryChooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
61 outputDirectoryChooser.setApproveButtonText("Select");
62 outputDirectoryChooser.setMultiSelectionEnabled(true);
63
64 if (outputDirectoryChooser.showOpenDialog(null) == javax.swing.JFileChooser.APPROVE_OPTION){
65 this.outputDirectory = outputDirectoryChooser.getSelectedFile();
66 if(!outputDirectory.isDirectory())
67 {
68 logger.warn("Chosen output directory is not a directory!");
69 setStatus(ERROR_STATUS);
70 }
71 logger.debug("Output Directory: "+outputDirectory);
72
73 }else setStatus(ABORT_STATUS);
74
75 setStatus(EXECUTE_STATUS);
76 }
77
78
79
80
81
82
83 @Override
84 protected void execution() throws Exception {
85 switch (getStatus()) {
86 case ABORT_STATUS:
87 break;
88 case VETOED_STATUS:
89 break;
90 case EXECUTE_STATUS:
91 AsymmetricKeyRing asymmetricKeyRing = new AsymmetricKeyRing(ConfigurationManager.getInstance().getUser());
92 KeyStore keyStore = asymmetricKeyRing.retrieve(ConfigurationManager.getInstance().getKeyRingLocation(),"password");
93
94 KeyPair keyPair = asymmetricKeyRing.getAllKeyPair()[0];
95 SymmetricKey symmetricKey = new SymmetricKey("password");
96 BackupDescriptor backupDescriptor = ConfigurationManager.getInstance().getRepository().getBackupDescriptorByGuId(guId);
97 if(backupDescriptor != null){
98 base.jdbs.BackupArtifactDisassembler.disassemblyBackupArtifact(symmetricKey, keyPair, backupDescriptor, this.outputDirectory);
99 setStatus(SUCCESS_STATUS);
100 }
101 else setStatus(ERROR_STATUS);
102 break;
103 }
104 }
105
106
107
108
109
110
111 @Override
112 protected void epilogue() {
113 switch (getStatus()) {
114 case SUCCESS_STATUS:
115 InternetCafe.setStatusBarMessage("JDBS Successfully exited...");
116 break;
117 case ABORT_STATUS:
118 InternetCafe.setStatusBarMessage("Command aborted by user...");
119 break;
120 case ERROR_STATUS:
121 InternetCafe.setStatusBarMessage("Command error...");
122 break;
123 case VETOED_STATUS:
124 InternetCafe.setStatusBarMessage("Command vetoed...");
125 break;
126 }
127 }
128
129 }
130