use of org.zaproxy.zap.control.ZapRelease in project zaproxy by zaproxy.
the class ExtensionAutoUpdate method alertIfNewVersions.
public void alertIfNewVersions() {
// Kicks off a thread and pops up a window if there are new versions.
// Depending on the options the user has chosen.
// Only expect this to be called on startup and in desktop mode
final OptionsParamCheckForUpdates options = getModel().getOptionsParam().getCheckForUpdatesParam();
if (View.isInitialised()) {
if (options.isCheckOnStartUnset()) {
// First time in
int result = getView().showConfirmDialog(Constant.messages.getString("cfu.confirm.startCheck"));
if (result == JOptionPane.OK_OPTION) {
options.setCheckOnStart(true);
options.setCheckAddonUpdates(true);
options.setDownloadNewRelease(true);
} else {
options.setCheckOnStart(false);
}
// Save
try {
this.getModel().getOptionsParam().getConfig().save();
} catch (ConfigurationException ce) {
logger.error(ce.getMessage(), ce);
getView().showWarningDialog(Constant.messages.getString("cfu.confirm.error"));
return;
}
}
if (!options.isCheckOnStart()) {
alertIfOutOfDate(false);
return;
}
}
if (!options.checkOnStart()) {
// Top level option not set, dont do anything, unless already downloaded last release
if (View.isInitialised() && this.getPreviousVersionInfo() != null) {
ZapRelease rel = this.getPreviousVersionInfo().getZapRelease();
if (rel != null && rel.isNewerThan(this.getCurrentVersion())) {
File f = new File(Constant.FOLDER_LOCAL_PLUGIN, rel.getFileName());
if (f.exists() && f.length() >= rel.getSize()) {
// Already downloaded, prompt to install and exit
this.promptToLaunchReleaseAndClose(rel.getVersion(), f);
}
}
}
return;
}
// Handle the response in a callback
this.getLatestVersionInfo(this);
}
use of org.zaproxy.zap.control.ZapRelease in project zaproxy by zaproxy.
the class ExtensionAutoUpdate method downloadLatestRelease.
protected boolean downloadLatestRelease() {
if (Constant.isKali()) {
if (View.isInitialised()) {
// Just tell the user to use one of the Kali options
View.getSingleton().showMessageDialog(this.getAddOnsDialog(), Constant.messages.getString("cfu.kali.options"));
}
return false;
}
if (this.getLatestVersionInfo() == null || this.getLatestVersionInfo().getZapRelease() == null) {
return false;
}
ZapRelease latestRelease = this.getLatestVersionInfo().getZapRelease();
if (latestRelease.isNewerThan(this.getCurrentVersion())) {
File f = new File(Constant.FOLDER_LOCAL_PLUGIN, latestRelease.getFileName());
downloadFile(latestRelease.getUrl(), f, latestRelease.getSize(), latestRelease.getHash());
return true;
}
return false;
}
use of org.zaproxy.zap.control.ZapRelease in project zaproxy by zaproxy.
the class ExtensionAutoUpdate method gotLatestData.
@Override
public void gotLatestData(AddOnCollection aoc) {
if (aoc == null) {
return;
}
if (getView() != null) {
// Initialise the dialogue so that it gets notifications of
// possible add-on changes and is also shown when needed
getAddOnsDialog();
}
try {
ZapRelease rel = aoc.getZapRelease();
OptionsParamCheckForUpdates options = getModel().getOptionsParam().getCheckForUpdatesParam();
if (rel.isNewerThan(getCurrentVersion())) {
logger.debug("There is a newer release: " + rel.getVersion());
// New ZAP release
if (Constant.isKali()) {
// Kali has its own package management system
if (View.isInitialised()) {
getAddOnsDialog().setVisible(true);
}
return;
}
File f = new File(Constant.FOLDER_LOCAL_PLUGIN, rel.getFileName());
if (f.exists() && f.length() >= rel.getSize()) {
// Already downloaded, prompt to install and exit
promptToLaunchReleaseAndClose(rel.getVersion(), f);
} else if (options.isDownloadNewRelease()) {
logger.debug("Auto-downloading release");
if (downloadLatestRelease() && addonsDialog != null) {
addonsDialog.setDownloadingZap();
}
} else if (addonsDialog != null) {
// Just show the dialog
addonsDialog.setVisible(true);
}
return;
}
boolean keepChecking = checkForAddOnUpdates(aoc, options);
if (keepChecking && addonsDialog != null) {
List<AddOn> newAddOns = getNewAddOns();
if (newAddOns.size() > 0) {
boolean report = false;
for (AddOn addon : newAddOns) {
switch(addon.getStatus()) {
case alpha:
if (options.isReportAlphaAddons()) {
report = true;
}
break;
case beta:
if (options.isReportBetaAddons()) {
report = true;
}
break;
case release:
if (options.isReportReleaseAddons()) {
report = true;
}
break;
default:
break;
}
}
if (report) {
getAddOnsDialog().setVisible(true);
getAddOnsDialog().selectMarketplaceTab();
}
}
}
} catch (Exception e) {
// Ignore (well, debug;), will be already logged
logger.debug(e.getMessage(), e);
}
}
Aggregations