use of org.parosproxy.paros.extension.option.DatabaseParam in project zaproxy by zaproxy.
the class SqlTableHistory method reconnect.
@Override
protected void reconnect(Connection conn) throws DatabaseException {
try {
//ZAP: Allow the request and response body sizes to be user-specifiable as far as possible
//re-load the configuration data from file, to get the configured length of the request and response bodies
//this will later be compared to the actual lengths of these fields in the database (in updateTable(Connection c))
DatabaseParam dbparams = new DatabaseParam();
dbparams.load(Constant.getInstance().FILE_CONFIG);
this.configuredrequestbodysize = dbparams.getRequestBodySize();
this.configuredresponsebodysize = dbparams.getResponseBodySize();
bodiesAsBytes = true;
if (DbSQL.getDbType().equals(Database.DB_TYPE_HSQLDB)) {
updateTable(conn);
}
isExistStatusCode = DbUtils.hasColumn(conn, TABLE_NAME, STATUSCODE);
int currentIndex = 0;
PreparedStatement stmt = null;
try {
stmt = conn.prepareStatement(DbSQL.getSQL("history.ps.lastindex"));
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
currentIndex = rs.getInt(1);
}
}
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
if (log.isDebugEnabled()) {
log.debug(e.getMessage(), e);
}
}
}
}
lastInsertedIndex = currentIndex;
} catch (SQLException e) {
throw new DatabaseException(e);
}
}
use of org.parosproxy.paros.extension.option.DatabaseParam 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(View.getSingleton().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 = View.getSingleton().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);
ReportGenerator.stringToHtml(sb.toString(), Constant.getZapInstall() + File.separator + "xml" + File.separator + "reportCompare.xsl", outputFile.getAbsolutePath());
try {
DesktopUtils.openUrlInBrowser(outputFile.toURI());
} catch (Exception e) {
log.error(e.getMessage(), e);
View.getSingleton().showMessageDialog(MessageFormat.format(Constant.messages.getString("report.complete.warning"), new Object[] { outputFile.getAbsolutePath() }));
}
} catch (Exception e1) {
log.warn(e1.getMessage(), e1);
}
}
//waitMessageDialog.setVisible(true);
} catch (Exception e) {
log.warn(e.getMessage(), e);
}
}
}
use of org.parosproxy.paros.extension.option.DatabaseParam in project zaproxy by zaproxy.
the class ParosTableHistory method reconnect.
@Override
protected void reconnect(Connection conn) throws DatabaseException {
try {
//ZAP: Allow the request and response body sizes to be user-specifiable as far as possible
//re-load the configuration data from file, to get the configured length of the request and response bodies
//this will later be compared to the actual lengths of these fields in the database (in updateTable(Connection c))
DatabaseParam dbparams = new DatabaseParam();
dbparams.load(Constant.getInstance().FILE_CONFIG);
this.configuredrequestbodysize = dbparams.getRequestBodySize();
this.configuredresponsebodysize = dbparams.getResponseBodySize();
bodiesAsBytes = true;
updateTable(conn);
isExistStatusCode = DbUtils.hasColumn(conn, TABLE_NAME, STATUSCODE);
psRead = conn.prepareStatement("SELECT TOP 1 * FROM HISTORY WHERE " + HISTORYID + " = ?");
// updatable recordset does not work in hsqldb jdbc impelementation!
//psWrite = mConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
psDelete = conn.prepareStatement("DELETE FROM HISTORY WHERE " + HISTORYID + " = ?");
psDeleteTemp = conn.prepareStatement("DELETE FROM HISTORY WHERE " + HISTTYPE + " IN (?) LIMIT 1000");
psContainsURI = conn.prepareStatement("SELECT TOP 1 HISTORYID FROM HISTORY WHERE URI = ? AND METHOD = ? AND REQBODY = ? AND SESSIONID = ? AND HISTTYPE = ?");
// ZAP: Added support for the tag when creating a history record
if (isExistStatusCode) {
psInsert = conn.prepareStatement("INSERT INTO HISTORY (" + SESSIONID + "," + HISTTYPE + "," + TIMESENTMILLIS + "," + TIMEELAPSEDMILLIS + "," + METHOD + "," + URI + "," + REQHEADER + "," + REQBODY + "," + RESHEADER + "," + RESBODY + "," + TAG + ", " + STATUSCODE + "," + NOTE + ", " + RESPONSE_FROM_TARGET_HOST + ") VALUES (?, ? ,?, ?, ?, ?, ?, ? ,? , ?, ?, ?, ?, ?)");
} else {
psInsert = conn.prepareStatement("INSERT INTO HISTORY (" + SESSIONID + "," + HISTTYPE + "," + TIMESENTMILLIS + "," + TIMEELAPSEDMILLIS + "," + METHOD + "," + URI + "," + REQHEADER + "," + REQBODY + "," + RESHEADER + "," + RESBODY + "," + TAG + "," + NOTE + ", " + RESPONSE_FROM_TARGET_HOST + ") VALUES (?, ? ,?, ?, ?, ?, ?, ? ,? , ? , ?, ?, ?)");
}
psGetIdLastInsert = conn.prepareCall("CALL IDENTITY();");
// psUpdateTag = conn.prepareStatement("UPDATE HISTORY SET TAG = ? WHERE HISTORYID = ?");
psUpdateNote = conn.prepareStatement("UPDATE HISTORY SET NOTE = ? WHERE HISTORYID = ?");
int currentIndex = 0;
PreparedStatement stmt = null;
try {
stmt = conn.prepareStatement("SELECT TOP 1 HISTORYID FROM HISTORY ORDER BY HISTORYID DESC");
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
currentIndex = rs.getInt(1);
}
}
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
if (log.isDebugEnabled()) {
log.debug(e.getMessage(), e);
}
}
}
}
lastInsertedIndex = currentIndex;
} catch (SQLException e) {
throw new DatabaseException(e);
}
}
Aggregations