Search in sources :

Example 1 with ZapRelease

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);
}
Also used : ZapRelease(org.zaproxy.zap.control.ZapRelease) ConfigurationException(org.apache.commons.configuration.ConfigurationException) File(java.io.File)

Example 2 with ZapRelease

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;
}
Also used : ZapRelease(org.zaproxy.zap.control.ZapRelease) File(java.io.File)

Example 3 with ZapRelease

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);
    }
}
Also used : AddOn(org.zaproxy.zap.control.AddOn) ZapRelease(org.zaproxy.zap.control.ZapRelease) File(java.io.File) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException)

Aggregations

File (java.io.File)3 ZapRelease (org.zaproxy.zap.control.ZapRelease)3 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1 AddOn (org.zaproxy.zap.control.AddOn)1