use of org.zaproxy.zap.control.AddOn in project zaproxy by zaproxy.
the class AutoUpdateAPI method handleApiView.
@Override
public ApiResponse handleApiView(String name, JSONObject params) throws ApiException {
ApiResponse result;
if (VIEW_LATEST_VERSION_NUMBER.equals(name)) {
result = new ApiResponseElement(name, this.getLatestVersionNumber());
} else if (VIEW_IS_LATEST_VERSION.equals(name)) {
result = new ApiResponseElement(name, Boolean.toString(this.isLatestVersion()));
} else if (VIEW_INSTALLED_ADDONS.equals(name)) {
final ApiResponseList resultList = new ApiResponseList(name);
for (AddOn ao : extension.getInstalledAddOns()) {
resultList.addItem(addonToSet(ao));
}
result = resultList;
} else if (VIEW_NEW_ADDONS.equals(name)) {
final ApiResponseList resultList = new ApiResponseList(name);
for (AddOn ao : extension.getNewAddOns()) {
resultList.addItem(addonToSet(ao));
}
result = resultList;
} else if (VIEW_UPDATED_ADDONS.equals(name)) {
final ApiResponseList resultList = new ApiResponseList(name);
for (AddOn ao : extension.getUpdatedAddOns()) {
resultList.addItem(addonToSet(ao));
}
result = resultList;
} else if (VIEW_MARKETPLACE_ADDONS.equals(name)) {
final ApiResponseList resultList = new ApiResponseList(name);
for (AddOn ao : extension.getMarketplaceAddOns()) {
resultList.addItem(addonToSet(ao));
}
result = resultList;
} else {
throw new ApiException(ApiException.Type.BAD_VIEW);
}
return result;
}
use of org.zaproxy.zap.control.AddOn in project zaproxy by zaproxy.
the class AutoUpdateAPI method handleApiAction.
@Override
public ApiResponse handleApiAction(String name, JSONObject params) throws ApiException {
log.debug("handleApiAction " + name + " " + params.toString());
if (ACTION_DOWNLOAD_LATEST_RELEASE.equals(name)) {
if (this.downloadLatestRelease()) {
return ApiResponseElement.OK;
} else {
return ApiResponseElement.FAIL;
}
} else if (ACTION_INSTALL_ADDON.equals(name)) {
String id = params.getString(PARAM_ID);
AddOn ao = extension.getAddOn(id);
if (ao == null) {
throw new ApiException(Type.DOES_NOT_EXIST);
} else {
List<String> l = new ArrayList<String>();
l.add(id);
String errorMessages = extension.installAddOns(l);
if (errorMessages.length() == 0) {
return ApiResponseElement.OK;
} else {
throw new ApiException(ApiException.Type.INTERNAL_ERROR, errorMessages);
}
}
} else if (ACTION_UNINSTALL_ADDON.equals(name)) {
String id = params.getString(PARAM_ID);
AddOn ao = extension.getLocalVersionInfo().getAddOn(id);
if (ao == null) {
throw new ApiException(Type.DOES_NOT_EXIST);
} else {
List<String> l = new ArrayList<String>();
l.add(id);
String errorMessages = extension.uninstallAddOns(l);
if (errorMessages.length() == 0) {
return ApiResponseElement.OK;
} else {
throw new ApiException(ApiException.Type.INTERNAL_ERROR, errorMessages);
}
}
} else {
throw new ApiException(ApiException.Type.BAD_ACTION);
}
}
use of org.zaproxy.zap.control.AddOn in project zaproxy by zaproxy.
the class OptionsExtensionTableModel method isCellEditable.
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
if (columnIndex == 0) {
Extension selectedExtension = getExtension(rowIndex);
AddOn addOn = selectedExtension.getAddOn();
if (addOn != null && addOn.isMandatory()) {
return false;
}
// directly;)
if (selectedExtension.isCore() && getEnabledState(selectedExtension)) {
return false;
}
// Check dependencies
List<Class<? extends Extension>> deps = selectedExtension.getDependencies();
for (Class<? extends Extension> dep : deps) {
Extension ext = getExtension(dep);
if (ext == null || !getEnabledState(ext)) {
return false;
}
}
return true;
}
return false;
}
use of org.zaproxy.zap.control.AddOn in project zaproxy by zaproxy.
the class ExtensionHelp method loadAddOnHelpSet.
private static void loadAddOnHelpSet(AddOn addOn) {
addOn.getLoadedExtensions().forEach(ExtensionHelp::loadExtensionHelpSet);
AddOn.HelpSetData helpSetData = addOn.getHelpSetData();
if (helpSetData.isEmpty()) {
return;
}
ClassLoader classLoader = addOn.getClassLoader();
URL helpSetUrl = LocaleUtils.findResource(helpSetData.getBaseName(), HELP_SET_FILE_EXTENSION, helpSetData.getLocaleToken(), Constant.getLocale(), classLoader::getResource);
if (helpSetUrl == null) {
logger.error("Declared helpset not found for '" + addOn.getId() + "' add-on, with base name: " + helpSetData.getBaseName() + (helpSetData.getLocaleToken().isEmpty() ? "" : " and locale token: " + helpSetData.getLocaleToken()));
return;
}
try {
logger.debug("Loading help for '" + addOn.getId() + "' add-on and merging with core help.");
addHelpSet(addOn, new HelpSet(classLoader, helpSetUrl));
} catch (HelpSetException e) {
logger.error("An error occured while adding help for '" + addOn.getId() + "' add-on:", e);
}
}
use of org.zaproxy.zap.control.AddOn in project zaproxy by zaproxy.
the class ExtensionAutoUpdate method getExtensionsMessages.
private static String getExtensionsMessages(Collection<AddOn> addOns, Set<Extension> extensions, Function<Extension, List<String>> function) {
List<String> messages = new ArrayList<>();
for (AddOn addOn : addOns) {
addMessages(addOn.getLoadedExtensions(), function, messages);
}
addMessages(extensions, function, messages);
return wrapEntriesInLiTags(messages);
}
Aggregations