use of org.parosproxy.paros.db.paros.ParosDatabase in project zaproxy by zaproxy.
the class Model method init.
public void init(ControlOverrides overrides) throws SAXException, IOException, Exception {
getOptionsParam().load(Constant.getInstance().FILE_CONFIG, overrides);
if (overrides.isExperimentalDb()) {
logger.info("Using experimental database :/");
db = DbSQL.getSingleton().initDatabase();
} else {
ParosDatabase parosDb = new ParosDatabase();
parosDb.setDatabaseParam(getOptionsParam().getDatabaseParam());
db = parosDb;
}
createAndOpenUntitledDb();
HistoryReference.setTableHistory(getDb().getTableHistory());
HistoryReference.setTableTag(getDb().getTableTag());
HistoryReference.setTableAlert(getDb().getTableAlert());
}
use of org.parosproxy.paros.db.paros.ParosDatabase in project zaproxy by zaproxy.
the class ExtensionCompare method compareSessions.
private void compareSessions() {
JFileChooser chooser = new JFileChooser(Model.getSingleton().getOptionsParam().getUserDirectory());
File file = null;
chooser.setFileFilter(new FileFilter() {
@Override
public boolean accept(File file) {
if (file.isDirectory()) {
return true;
} else if (file.isFile() && file.getName().endsWith(".session")) {
return true;
}
return false;
}
@Override
public String getDescription() {
return Constant.messages.getString("file.format.zap.session");
}
});
int rc = chooser.showOpenDialog(getView().getMainFrame());
if (rc == JFileChooser.APPROVE_OPTION) {
try {
file = chooser.getSelectedFile();
if (file == null) {
return;
}
Model cmpModel = new Model();
Session session = cmpModel.getSession();
// log.info("opening session file " + file.getAbsolutePath());
// WaitMessageDialog waitMessageDialog =
// getView().getWaitMessageDialog("Loading session file. Please wait...");
cmpModel.openSession(file, this);
// TODO support other implementations in the future
ParosDatabase db = new ParosDatabase();
db.setDatabaseParam(new DatabaseParam());
db.open(file.getAbsolutePath());
Map<String, String> curMap = new HashMap<>();
Map<String, String> cmpMap = new HashMap<>();
// Load the 2 sessions into 2 maps
this.buildHistoryMap(Model.getSingleton().getDb().getTableHistory(), curMap);
this.buildHistoryMap(db.getTableHistory(), cmpMap);
File outputFile = this.getOutputFile();
if (outputFile != null) {
// Write the result to the specified file
try {
TreeSet<String> sset = new TreeSet<>();
// Combine the keys for both maps
sset.addAll(curMap.keySet());
sset.addAll(cmpMap.keySet());
StringBuilder sb = new StringBuilder(500);
sb.append("<?xml version=\"1.0\"?>");
sb.append(CRLF);
sb.append("<report>");
sb.append(CRLF);
sb.append("<session-names>");
sb.append(CRLF);
sb.append("<session1>");
sb.append(Model.getSingleton().getSession().getSessionName());
sb.append("</session1>");
sb.append(CRLF);
sb.append("<session2>");
sb.append(session.getSessionName());
sb.append("</session2>");
sb.append(CRLF);
sb.append("</session-names>");
sb.append(CRLF);
Iterator<String> iter = sset.iterator();
while (iter.hasNext()) {
sb.append("<urlrow>");
sb.append(CRLF);
String key = iter.next();
String method = key.substring(0, key.indexOf(" "));
String url = key.substring(key.indexOf(" ") + 1);
sb.append("<method>");
sb.append(method);
sb.append("</method>");
sb.append(CRLF);
sb.append("<url>");
sb.append(url);
sb.append("</url>");
sb.append(CRLF);
sb.append("<code1>");
if (curMap.containsKey(key)) {
sb.append(curMap.get(key));
} else {
sb.append("---");
}
sb.append("</code1>");
sb.append(CRLF);
sb.append("<code2>");
if (cmpMap.containsKey(key)) {
sb.append(cmpMap.get(key));
} else {
sb.append("---");
}
sb.append("</code2>");
sb.append(CRLF);
sb.append("</urlrow>");
sb.append(CRLF);
}
sb.append("</report>");
sb.append(CRLF);
String fileName = "reportCompare.xsl";
Path xslFile = Paths.get(Constant.getZapInstall(), "xml", fileName);
if (Files.exists(xslFile)) {
stringToHtml(sb.toString(), xslFile.toString(), outputFile.getAbsolutePath());
} else {
String path = "/org/zaproxy/zap/resources/xml/" + fileName;
try (InputStream is = ExtensionCompare.class.getResourceAsStream(path)) {
if (is == null) {
log.error("Bundled file not found: " + path);
return;
}
stringToHtml(sb.toString(), new StreamSource(is), outputFile.getAbsolutePath());
}
}
if (Files.notExists(outputFile.toPath())) {
log.info("Not opening report, does not exist: " + outputFile);
return;
}
try {
DesktopUtils.openUrlInBrowser(outputFile.toURI());
} catch (Exception e) {
log.error(e.getMessage(), e);
getView().showMessageDialog(Constant.messages.getString("report.complete.warning", outputFile.getAbsolutePath()));
}
} catch (Exception e1) {
log.warn(e1.getMessage(), e1);
}
}
} catch (Exception e) {
log.warn(e.getMessage(), e);
}
}
}
Aggregations