use of com.jsql.model.accessible.CallableHttpHead in project jsql-injection by ron190.
the class ManagerAdminPage method createAdminPages.
/**
* Check if every page in the list responds 200 Success.
* @param urlInjection
* @param pageNames List of admin pages to test
* @throws InterruptedException
*/
public void createAdminPages(String urlInjection, List<ItemList> pageNames) throws InterruptedException {
var matcher = Pattern.compile("^((https?://)?[^/]*)(.*)").matcher(urlInjection);
matcher.find();
String urlProtocol = matcher.group(1);
String urlWithoutProtocol = matcher.group(3);
List<String> folderSplits = new ArrayList<>();
// Hostname only
if (urlWithoutProtocol.isEmpty() || !Pattern.matches("^/.*", urlWithoutProtocol)) {
urlWithoutProtocol = "/dummy";
}
String[] splits = urlWithoutProtocol.split("/", -1);
String[] folderNames = Arrays.copyOf(splits, splits.length - 1);
for (String folderName : Arrays.asList(folderNames)) {
folderSplits.add(folderName + "/");
}
ExecutorService taskExecutor = Executors.newFixedThreadPool(10, new ThreadFactoryCallable("CallableGetAdminPage"));
CompletionService<CallableHttpHead> taskCompletionService = new ExecutorCompletionService<>(taskExecutor);
var urlPart = new StringBuilder();
for (String segment : folderSplits) {
urlPart.append(segment);
for (ItemList pageName : pageNames) {
taskCompletionService.submit(new CallableHttpHead(urlProtocol + urlPart.toString() + pageName.toString(), MediatorHelper.model(), "check:page"));
}
}
var resourceAccess = MediatorHelper.model().getResourceAccess();
var nbAdminPagesFound = 0;
int submittedTasks = folderSplits.size() * pageNames.size();
int tasksHandled;
for (tasksHandled = 0; tasksHandled < submittedTasks && !resourceAccess.isSearchAdminStopped(); tasksHandled++) {
nbAdminPagesFound = resourceAccess.callAdminPage(taskCompletionService, nbAdminPagesFound);
}
taskExecutor.shutdown();
taskExecutor.awaitTermination(5, TimeUnit.SECONDS);
resourceAccess.setSearchAdminStopped(false);
resourceAccess.logSearchAdminPage(nbAdminPagesFound, submittedTasks, tasksHandled);
var request = new Request();
request.setMessage(Interaction.END_ADMIN_SEARCH);
MediatorHelper.model().sendToViews(request);
}
Aggregations