How to use run_scan method of end.end.end Package

Best Unobtainium_ruby code snippet using end.end.end.run_scan

CopyOfAnyPangHack.java

Source:CopyOfAnyPangHack.java Github

copy

Full Screen

...217 @Override218 public void onAddListener() {219 //스케220 try {221 scheduler.schedule("loop", run_scan, 1000,50);222 } catch (Exception e1) {223 e1.printStackTrace();224 }225 226 227 Button btn = (Button) getComponent(VIEWID.START_BTN.getValue());228 btn.addActionListener(new ActionListener() {229 public void actionPerformed(ActionEvent e) {230 // TODO Auto-generated method stub231 scan_start=!scan_start;232 }233 });234 235 btn = (Button) getComponent(VIEWID.MOUSE_BTN.getValue());236 btn.addActionListener(new ActionListener() {237 public void actionPerformed(ActionEvent e) {238 // TODO Auto-generated method stub239 mouse_start=!mouse_start;240 /* if(mouse_start){241 try {242 scheduler.schedule("mouse", mouse_action, 500,50);243 } catch (Exception e1) {244 e1.printStackTrace();245 }246 }else{247 try {248 scheduler.removeScheduleTask("mouse");249 } catch (Exception e1) {250 e1.printStackTrace();251 }252 253 }*/254 }255 });256 257 mouse_t = new Thread(mouse_action);258 mouse_t.start();259 }260 Thread mouse_t = null;261 Scheduler scheduler = new Scheduler();262 263 264 public boolean scan_start = false;265 public boolean mouse_start = false;266 Runnable mouse_action = new Runnable() {267 @Override268 public void run() {269 270 while(!Thread.currentThread().isInterrupted()){271 if(mouse_start==false&&panglist.length>0){272 try {273 Thread.sleep(1000);274 } catch (InterruptedException e) {275 break;276 }277 continue;278 }279 280 281 for (int y = 0; y < panglist.length; y++) {282 for (int x = 0; x < panglist[y].length; x++) {283 Pang pang = panglist[x][y];284 pang = (pang==null?new Pang(-1,0,0,null):pang);285 int type = pang.getType();286 // System.out.print(type+",");287 288 //네번옮긴다289 //8가지 체크한다290 //있음 수행한다.291 292 293 294 ArrayList<TPointToPoint> points = new ArrayList<TPointToPoint>();295 296 try{297 //오른쪽한번 이동해서 나란쭉298 if(pang.getType() == panglist[x+2][y].getType() && pang.getType() == panglist[x+3][y].getType()){299 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x+1][y].getX(),panglist[x+1][y].getY()))); 300 pang.setType(-1);301 }302 }catch (Exception e) {303 }304 305 try{306 //오른쪽한번 이동해서 위쪽으로나란307 if(pang.getType() == panglist[x+1][y-1].getType() && pang.getType() == panglist[x+1][y-2].getType()){308 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x+1][y].getX(),panglist[x+1][y].getY()))); 309 pang.setType(-1);310 }311 }catch (Exception e) {312 }313 314 try{315 //오른쪽한번 이동해서 아래쪽으로나란316 if(pang.getType() == panglist[x+1][y+1].getType() && pang.getType() == panglist[x+1][y+2].getType()){317 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x+1][y].getX(),panglist[x+1][y].getY()))); 318 pang.setType(-1);319 }320 }catch (Exception e) {321 }322 try{323 //오른쪽한번 이동해서 양위으로나란324 if(pang.getType() == panglist[x+1][y+1].getType() && pang.getType() == panglist[x+1][y-1].getType()){325 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x+1][y].getX(),panglist[x+1][y].getY()))); 326 pang.setType(-1);327 }328 }catch (Exception e) {329 }330 331 332 333 334 335 336 337 338 339 340 341 try{342 //왼쪽한번 이동해서 나란쭉343 if(pang.getType() == panglist[x-2][y].getType() && pang.getType() == panglist[x-3][y].getType()){344 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x-1][y].getX(),panglist[x-1][y].getY()))); 345 pang.setType(-1);346 }347 }catch (Exception e) {348 }349 350 try{351 //왼쪽한번 이동해서 위쪽으로나란352 if(pang.getType() == panglist[x-1][y-1].getType() && pang.getType() == panglist[x-1][y-2].getType()){353 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x-1][y].getX(),panglist[x-1][y].getY()))); 354 pang.setType(-1);355 }356 }catch (Exception e) {357 }358 359 try{360 //왼쪽한번 이동해서 아래으로나란361 if(pang.getType() == panglist[x-1][y+1].getType() && pang.getType() == panglist[x-1][y+2].getType()){362 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x-1][y].getX(),panglist[x-1][y].getY()))); 363 pang.setType(-1);364 }365 }catch (Exception e) {366 }367 368 try{369 //왼쪽한번 이동해서 양쪽으로나란370 if(pang.getType() == panglist[x-1][y+1].getType() && pang.getType() == panglist[x-1][y-1].getType()){371 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x-1][y].getX(),panglist[x-1][y].getY()))); 372 pang.setType(-1);373 }374 }catch (Exception e) {375 }376 377 378 379 380 381 382 383 try{ 384 //위쪽한번 이동해서 위쪽나란쭉385 if(pang.getType() == panglist[x][y-2].getType() && pang.getType() == panglist[x][y-3].getType()){386 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x][y-1].getX(),panglist[x][y-1].getY()))); 387 pang.setType(-1);388 }389 }catch (Exception e) {390 }391 392 try{393 //위쪽한번 이동해서 왼쪽으로나란394 if(pang.getType() == panglist[x-1][y-1].getType() && pang.getType() == panglist[x-2][y-1].getType()){395 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x][y-1].getX(),panglist[x][y-1].getY()))); 396 pang.setType(-1);397 }398 }catch (Exception e) {399 }400 401 try{402 //위쪽한번 이동해서 오른쪽으로나란403 if(pang.getType() == panglist[x+1][y-1].getType() && pang.getType() == panglist[x+2][y-1].getType()){404 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x][y-1].getX(),panglist[x][y-1].getY()))); 405 pang.setType(-1);406 }407 }catch (Exception e) {408 }409 410 try{411 //위쪽한번 이동해서 좌우 양쪽으로나란412 if(pang.getType() == panglist[x-1][y-1].getType() && pang.getType() == panglist[x+1][y-1].getType()){413 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x][y-1].getX(),panglist[x][y-1].getY()))); 414 pang.setType(-1);415 }416 }catch (Exception e) {417 }418 419 420 421 try{422 //아래한번 이동해서 나란쭉423 if(pang.getType() == panglist[x][y+2].getType() && pang.getType() == panglist[x][y+3].getType()){424 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x][y+1].getX(),panglist[x][y+1].getY()))); 425 pang.setType(-1);426 }427 }catch (Exception e) {428 }429 try{430 //아래한번 이동해서 왼쪽으로나란431 if(pang.getType() == panglist[x-1][y+1].getType() && pang.getType() == panglist[x-2][y+1].getType()){432 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x][y+1].getX(),panglist[x][y+1].getY()))); 433 pang.setType(-1);434 }435 }catch (Exception e) {436 }437 try{438 //아래한번 이동해서 오른쪽으로나란439 if(pang.getType() == panglist[x+1][y+1].getType() && pang.getType() == panglist[x+2][y+1].getType()){440 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x][y+1].getX(),panglist[x][y+1].getY()))); 441 pang.setType(-1);442 }443 }catch (Exception e) {444 }445 446 try{447 //아래한번 이동해서 좌우 양쪽으로나란448 if(pang.getType() == panglist[x-1][y+1].getType() && pang.getType() == panglist[x+1][y+1].getType()){449 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x][y+1].getX(),panglist[x][y+1].getY()))); 450 pang.setType(-1);451 }452 }catch (Exception e) {453 }454 455 456 try{457 //붐!458 if(pang.getType() == Pang.BOOMB){459 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(pang.getX()+1,pang.getY()+1))); 460 pang.setType(-1);461 }462 }catch (Exception e) {463 }464 465 466 467 468 //log.debug("points Size:"+points.size());469 if(points.size()>0){470 int selectIndex = Util.getRandomInt(points.size());471 TPointToPoint tpt = points.get(selectIndex);472 // log.debug("selectIndex :"+selectIndex+" StartDragX:"+tpt.getStart().getX()+" StartDragY:"+tpt.getStart().getY()+" EndDragX:"+tpt.getEnd().getX()+" EndDragX:"+tpt.getEnd().getX());473 474 try {475 Thread.sleep(10);476 MouseUtil.move(tpt.getStart());477 Thread.sleep(10);478 MouseUtil.press(InputEvent.BUTTON1_MASK);479 Thread.sleep(10);480 MouseUtil.move(tpt.getEnd());481 Thread.sleep(10);482 MouseUtil.release(InputEvent.BUTTON1_MASK);483 Thread.sleep(100);484 } catch (Exception e) {485 e.printStackTrace();486 }487 points.clear();488 489 }490 }491 }492 }493 494 }495 496 };497 498 public Pang[][] panglist=new Pang[7][7];499 500Runnable run_scan = new Runnable() {501 public void run() {502 try{503 504 ImageView imgview = (ImageView) getComponent(VIEWID.IMAGE_COMPONENT.getValue());505 BufferedImage bi = DisPlayUtil.getScreenCapture(0, 0, imgview.getWidth(), imgview.getHeight());506507 508 509 int w_w = 350;510 int w_h = 350;511 512 int s_wc = bi.getWidth()/2;513 int s_hc = bi.getHeight()/2;514 ...

Full Screen

Full Screen

AnyPangHack.java

Source:AnyPangHack.java Github

copy

Full Screen

...213 @Override214 public void onAddListener() {215 //스케216 try {217 scheduler.schedule("loop", run_scan, 1000,50);218 } catch (Exception e1) {219 e1.printStackTrace();220 }221 222 223 Button btn = (Button) getComponent(VIEWID.START_BTN.getValue());224 btn.addActionListener(new ActionListener() {225 public void actionPerformed(ActionEvent e) {226 // TODO Auto-generated method stub227 scan_start=!scan_start;228 }229 });230 231 btn = (Button) getComponent(VIEWID.MOUSE_BTN.getValue());232 btn.addActionListener(new ActionListener() {233 public void actionPerformed(ActionEvent e) {234 // TODO Auto-generated method stub235 mouse_start=!mouse_start;236 /* if(mouse_start){237 try {238 scheduler.schedule("mouse", mouse_action, 500,50);239 } catch (Exception e1) {240 e1.printStackTrace();241 }242 }else{243 try {244 scheduler.removeScheduleTask("mouse");245 } catch (Exception e1) {246 e1.printStackTrace();247 }248 249 }*/250 }251 });252 253 mouse_t = new Thread(mouse_action);254 mouse_t.start();255 }256 Thread mouse_t = null;257 Scheduler scheduler = new Scheduler();258 259 260 public boolean scan_start = false;261 public boolean mouse_start = false;262 Runnable mouse_action = new Runnable() {263 @Override264 public void run() {265 266 while(!Thread.currentThread().isInterrupted()){267 if(mouse_start==false&&panglist.length>0){268 try {269 Thread.sleep(1000);270 } catch (InterruptedException e) {271 break;272 }273 continue;274 }275 276 277 for (int y = 0; y < panglist.length; y++) {278 for (int x = 0; x < panglist[y].length; x++) {279 Pang pang = panglist[x][y];280 pang = (pang==null?new Pang(-1,0,0,null):pang);281 int type = pang.getType();282 // System.out.print(type+",");283 284 //네번옮긴다285 //8가지 체크한다286 //있음 수행한다.287 288 289 290 ArrayList<TPointToPoint> points = new ArrayList<TPointToPoint>();291 292 try{293 //오른쪽한번 이동해서 나란쭉294 if(pang.getType() == panglist[x+2][y].getType() && pang.getType() == panglist[x+3][y].getType()){295 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x+1][y].getX(),panglist[x+1][y].getY()))); 296 pang.setType(-1);297 }298 }catch (Exception e) {299 }300 301 try{302 //오른쪽한번 이동해서 위쪽으로나란303 if(pang.getType() == panglist[x+1][y-1].getType() && pang.getType() == panglist[x+1][y-2].getType()){304 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x+1][y].getX(),panglist[x+1][y].getY()))); 305 pang.setType(-1);306 }307 }catch (Exception e) {308 }309 310 try{311 //오른쪽한번 이동해서 아래쪽으로나란312 if(pang.getType() == panglist[x+1][y+1].getType() && pang.getType() == panglist[x+1][y+2].getType()){313 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x+1][y].getX(),panglist[x+1][y].getY()))); 314 pang.setType(-1);315 }316 }catch (Exception e) {317 }318 try{319 //오른쪽한번 이동해서 양위으로나란320 if(pang.getType() == panglist[x+1][y+1].getType() && pang.getType() == panglist[x+1][y-1].getType()){321 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x+1][y].getX(),panglist[x+1][y].getY()))); 322 pang.setType(-1);323 }324 }catch (Exception e) {325 }326 327 328 329 330 331 332 333 334 335 336 337 try{338 //왼쪽한번 이동해서 나란쭉339 if(pang.getType() == panglist[x-2][y].getType() && pang.getType() == panglist[x-3][y].getType()){340 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x-1][y].getX(),panglist[x-1][y].getY()))); 341 pang.setType(-1);342 }343 }catch (Exception e) {344 }345 346 try{347 //왼쪽한번 이동해서 위쪽으로나란348 if(pang.getType() == panglist[x-1][y-1].getType() && pang.getType() == panglist[x-1][y-2].getType()){349 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x-1][y].getX(),panglist[x-1][y].getY()))); 350 pang.setType(-1);351 }352 }catch (Exception e) {353 }354 355 try{356 //왼쪽한번 이동해서 아래으로나란357 if(pang.getType() == panglist[x-1][y+1].getType() && pang.getType() == panglist[x-1][y+2].getType()){358 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x-1][y].getX(),panglist[x-1][y].getY()))); 359 pang.setType(-1);360 }361 }catch (Exception e) {362 }363 364 try{365 //왼쪽한번 이동해서 양쪽으로나란366 if(pang.getType() == panglist[x-1][y+1].getType() && pang.getType() == panglist[x-1][y-1].getType()){367 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x-1][y].getX(),panglist[x-1][y].getY()))); 368 pang.setType(-1);369 }370 }catch (Exception e) {371 }372 373 374 375 376 377 378 379 try{ 380 //위쪽한번 이동해서 위쪽나란쭉381 if(pang.getType() == panglist[x][y-2].getType() && pang.getType() == panglist[x][y-3].getType()){382 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x][y-1].getX(),panglist[x][y-1].getY()))); 383 pang.setType(-1);384 }385 }catch (Exception e) {386 }387 388 try{389 //위쪽한번 이동해서 왼쪽으로나란390 if(pang.getType() == panglist[x-1][y-1].getType() && pang.getType() == panglist[x-2][y-1].getType()){391 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x][y-1].getX(),panglist[x][y-1].getY()))); 392 pang.setType(-1);393 }394 }catch (Exception e) {395 }396 397 try{398 //위쪽한번 이동해서 오른쪽으로나란399 if(pang.getType() == panglist[x+1][y-1].getType() && pang.getType() == panglist[x+2][y-1].getType()){400 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x][y-1].getX(),panglist[x][y-1].getY()))); 401 pang.setType(-1);402 }403 }catch (Exception e) {404 }405 406 try{407 //위쪽한번 이동해서 좌우 양쪽으로나란408 if(pang.getType() == panglist[x-1][y-1].getType() && pang.getType() == panglist[x+1][y-1].getType()){409 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x][y-1].getX(),panglist[x][y-1].getY()))); 410 pang.setType(-1);411 }412 }catch (Exception e) {413 }414 415 416 417 try{418 //아래한번 이동해서 나란쭉419 if(pang.getType() == panglist[x][y+2].getType() && pang.getType() == panglist[x][y+3].getType()){420 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x][y+1].getX(),panglist[x][y+1].getY()))); 421 pang.setType(-1);422 }423 }catch (Exception e) {424 }425 try{426 //아래한번 이동해서 왼쪽으로나란427 if(pang.getType() == panglist[x-1][y+1].getType() && pang.getType() == panglist[x-2][y+1].getType()){428 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x][y+1].getX(),panglist[x][y+1].getY()))); 429 pang.setType(-1);430 }431 }catch (Exception e) {432 }433 try{434 //아래한번 이동해서 오른쪽으로나란435 if(pang.getType() == panglist[x+1][y+1].getType() && pang.getType() == panglist[x+2][y+1].getType()){436 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x][y+1].getX(),panglist[x][y+1].getY()))); 437 pang.setType(-1);438 }439 }catch (Exception e) {440 }441 442 try{443 //아래한번 이동해서 좌우 양쪽으로나란444 if(pang.getType() == panglist[x-1][y+1].getType() && pang.getType() == panglist[x+1][y+1].getType()){445 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(panglist[x][y+1].getX(),panglist[x][y+1].getY()))); 446 pang.setType(-1);447 }448 }catch (Exception e) {449 }450 451 /*452 try{453 //붐!454 if(pang.getType() == Pang.BOOMB){455 points.add( new TPointToPoint( new TPoint(pang.getX(),pang.getY()),new TPoint(pang.getX()+1,pang.getY()+1))); 456 pang.setType(-1);457 }458 }catch (Exception e) {459 }460 461 */462 463 //log.debug("points Size:"+points.size());464 if(points.size()>0){465 int selectIndex = Util.getRandomInt(points.size());466 TPointToPoint tpt = points.get(selectIndex);467 // log.debug("selectIndex :"+selectIndex+" StartDragX:"+tpt.getStart().getX()+" StartDragY:"+tpt.getStart().getY()+" EndDragX:"+tpt.getEnd().getX()+" EndDragX:"+tpt.getEnd().getX());468 469 try {470 Thread.sleep(10);471 MouseUtil.move(tpt.getStart());472 Thread.sleep(10);473 MouseUtil.press(InputEvent.BUTTON1_MASK);474 Thread.sleep(10);475 MouseUtil.move(tpt.getEnd());476 Thread.sleep(10);477 MouseUtil.release(InputEvent.BUTTON1_MASK);478 Thread.sleep(50);479 } catch (Exception e) {480 e.printStackTrace();481 }482 points.clear();483 484 }485 }486 }487 }488 489 }490 491 };492 493 public Pang[][] panglist=new Pang[7][7];494 495Runnable run_scan = new Runnable() {496 public void run() {497 try{498 499 ImageView imgview = (ImageView) getComponent(VIEWID.IMAGE_COMPONENT.getValue());500 BufferedImage bi = DisPlayUtil.getScreenCapture(0, 0, imgview.getWidth(), imgview.getHeight());501502 503 504 int w_w = 350;505 int w_h = 350;506 507 int s_wc = bi.getWidth()/2;508 int s_hc = bi.getHeight()/2;509 ...

Full Screen

Full Screen

EnterpriseRestClient.java

Source:EnterpriseRestClient.java Github

copy

Full Screen

1/*2 * Copyright © 2003 - 2020 Rapid7, Inc. All rights reserved.3 */4package com.rapid7.appspider;5import com.rapid7.appspider.datatransferobjects.ClientIdNamePair;6import com.rapid7.appspider.datatransferobjects.ScanResult;7import com.rapid7.appspider.models.AuthenticationModel;8import freemarker.template.Template;9import freemarker.template.TemplateException;10import org.apache.http.entity.StringEntity;11import org.apache.http.message.BasicNameValuePair;12import org.json.JSONArray;13import org.json.JSONException;14import org.json.JSONObject;15import java.io.IOException;16import java.io.InputStream;17import java.io.UnsupportedEncodingException;18import java.net.URL;19import java.util.ArrayList;20import java.util.List;21import java.util.Map;22import java.util.Objects;23import java.util.Optional;24/**25 * Provides methods to communicating with AppSpider Enterprise while obsuring the implementation26 * details of that communication.27 */28public final class EnterpriseRestClient implements EnterpriseClient {29 private final String restEndPointUrl;30 private final HttpClientService clientService;31 private final LoggerFacade logger;32 private final ApiSerializer apiSerializer;33 private final ContentHelper contentHelper;34 /**35 * Instantiates a new instance of the EnterpriseClient class36 * @param clientService helper that works directly with lower level HttpClient methods37 * @param restEndPointUrl base endpoint including /rest/v1 or equilvalent path38 * @param apiSerializer Helper class providing handling of HttpResponse to JSONObject methods39 * @param contentHelper Helper class providing parsing and encoding methods to support api calls40 * @param logger logger used for diagnostic output41 * @throws IllegalArgumentException thrown if any of the arguments are null or if restEntPointUrl is empty42 */43 public EnterpriseRestClient(HttpClientService clientService, String restEndPointUrl, ApiSerializer apiSerializer, ContentHelper contentHelper, LoggerFacade logger) {44 if (Objects.isNull(restEndPointUrl) || restEndPointUrl.isEmpty())45 throw new IllegalArgumentException("restEndPointUrl cannot be null or empty");46 if (Objects.isNull(clientService))47 throw new IllegalArgumentException("clientHelper cannot be null or empty");48 if (Objects.isNull(apiSerializer))49 throw new IllegalArgumentException("apiSerializer cannot be null or empty");50 if (Objects.isNull(contentHelper))51 throw new IllegalArgumentException("jsonHelper cannot be null");52 if (Objects.isNull(logger))53 throw new IllegalArgumentException("logger cannot be null");54 this.restEndPointUrl = restEndPointUrl;55 this.clientService = clientService;56 this.apiSerializer = apiSerializer;57 this.contentHelper = contentHelper;58 this.logger = logger;59 }60 /**61 * {@inheritDoc}62 */63 @Override64 public String getUrl() {65 return restEndPointUrl;66 }67 private static final String AUTHENTICATION_LOGIN = "/Authentication/Login";68 /**69 * {@inheritDoc}70 */71 @Override72 public Optional<String> login(AuthenticationModel authModel) {73 final String endPoint = restEndPointUrl + AUTHENTICATION_LOGIN;74 if (authModel == null) {75 throw new IllegalArgumentException();76 }77 try {78 final StringEntity contentEntity = authModel.hasClientId()79 ? contentHelper.entityFrom(80 contentHelper.pairFrom("name", authModel.getUsername()), 81 contentHelper.pairFrom("password", authModel.getPassword()),82 contentHelper.pairFrom("clientId", authModel.getClientId()))83 : contentHelper.entityFrom(84 contentHelper.pairFrom("name", authModel.getUsername()), 85 contentHelper.pairFrom("password", authModel.getPassword()));86 return clientService87 .buildPostRequestUsingApplicationJson(endPoint, contentEntity)88 .flatMap(request -> clientService.executeJsonRequest(request)89 .flatMap(apiSerializer::getTokenOrEmpty));90 } catch (UnsupportedEncodingException | JSONException e) {91 logger.println(e.toString());92 return Optional.empty();93 }94 }95 /**96 * {@inheritDoc}97 */98 @Override99 public boolean testAuthentication(AuthenticationModel authModel) {100 return login(authModel).isPresent();101 }102 // <editor-fold desc="Engine Group APIs">103 /**104 * {@inheritDoc}105 */106 @Override107 public Optional<String[]> getEngineGroupNamesForClient(String authToken) {108 return getEngineGroupsForClient(authToken)109 .map(map -> new ArrayList<>(map.keySet()))110 .map(Utility::toStringArray);111 }112 /**113 * {@inheritDoc}114 */115 @Override116 public Optional<String> getEngineGroupIdFromName(String authToken, String engineGroupName) {117 return getAllEngineGroups(authToken).filter(map -> map.containsKey(engineGroupName)).flatMap(map -> Optional.of(map.get(engineGroupName)));118 }119 private static final String GET_ALL_ENGINE_GROUPS = "/EngineGroup/GetAllEngineGroups";120 private static final String GET_ENGINE_GROUPS_FOR_CLIENT = "/EngineGroup/GetEngineGroupsForClient";121 private Optional<Map<String, String>> getAllEngineGroups(String authToken) {122 return clientService123 .buildGetRequestUsingFormUrlEncoding(restEndPointUrl + GET_ALL_ENGINE_GROUPS, authToken)124 .flatMap(get -> contentHelper.asMapOfStringToString("Name", "Id", clientService.executeJsonRequest(get)));125 }126 private Optional<Map<String,String>> getEngineGroupsForClient(String authToken) {127 return clientService128 .buildGetRequestUsingFormUrlEncoding(restEndPointUrl + GET_ENGINE_GROUPS_FOR_CLIENT, authToken)129 .flatMap(get -> contentHelper.asMapOfStringToString("Name", "Id", clientService.executeJsonRequest(get)));130 }131 // </editor-fold>132 // <editor-fold desc="Scan APIs">133 /**134 * {@inheritDoc}135 */136 @Override137 public ScanResult runScanByConfigName(String authToken, String configName) {138 return getConfigByName(authToken, configName)139 .flatMap(apiSerializer::getScanConfigId)140 .map(configId -> runScanByConfigId(authToken, configId))141 .orElse(new ScanResult(false, ""));142 }143 private static final String GET_SCAN_STATUS = "/Scan/GetScanStatus";144 private static final String SCAN_ID = "scanId";145 /**146 * {@inheritDoc}147 */148 @Override149 public Optional<String> getScanStatus(String authToken, String scanId) {150 return clientService151 .buildGetRequestUsingFormUrlEncoding(restEndPointUrl + GET_SCAN_STATUS, authToken, contentHelper.pairFrom(SCAN_ID, scanId))152 .flatMap(clientService::executeJsonRequest)153 .flatMap(apiSerializer::getStatus);154 }155 private static final String IS_SCAN_FINISHED = "/Scan/IsScanFinished";156 /**157 * {@inheritDoc}158 */159 @Override160 public boolean isScanFinished(String authToken, String scanId) {161 return resultAndIsSuccessProvider(restEndPointUrl + IS_SCAN_FINISHED, authToken, scanId);162 }163 private static final String HAS_REPORT = "/Scan/HasReport";164 /**165 * {@inheritDoc}166 */167 @Override168 public boolean hasReport(String authToken, String scanId) {169 return resultAndIsSuccessProvider(restEndPointUrl + HAS_REPORT, authToken, scanId);170 }171 private static final String RUN_SCAN = "/Scan/RunScan";172 /**173 * starts a new scan using configuration matching configId174 * @param authToken authorization token required to execute request175 * @param configId id of the config to run176 * @return ScanResult containing details on the success of the request and if successful the177 * unique id of the scan178 */179 private ScanResult runScanByConfigId(String authToken, String configId) {180 return clientService181 .buildPostRequestUsingFormUrlEncoding(182 restEndPointUrl + RUN_SCAN,183 authToken,184 new BasicNameValuePair("configId", configId))185 .flatMap(clientService::executeJsonRequest)186 .map(apiSerializer::getScanResult)187 .orElse(new ScanResult(false, ""));188 }189 private boolean resultAndIsSuccessProvider(String endpoint, String authToken, String scanId) {190 return clientService191 .buildGetRequestUsingFormUrlEncoding(endpoint, authToken, contentHelper.pairFrom(SCAN_ID, scanId))192 .flatMap(clientService::executeJsonRequest)193 .map(apiSerializer::getResultIsSuccess)194 .orElse(false);195 }196 // </editor-fold>197 // <editor-fold desc="Config APIs">198 private static final String GET_CONFIGS = "/Config/GetConfigs";199 private static final String SAVE_CONFIG = "/Config/SaveConfig";200 /**201 * calls the /Configs/SaveConfig endpoint using the provided data to create or update a configuration202 * @param authToken authorization token required to execute request203 * @param name name of the scanconfig to save204 * @param url target URL for the scan205 * @param engineGroupId unique engine group id for the engine(s) to be used to execute the scan206 * @return true on success; otherwise, false207 */208 private Optional<JSONObject> getConfigByName(String authToken, String configName) {209 return getConfigs(authToken)210 .flatMap(configs -> apiSerializer.findByConfigName(configs, configName));211 }212 /**213 * calls the /Config/GetConfigs endpoint returning the resulting JSONArray of Configs on success214 * @param authToken authorization token required to execute request215 * @return Optional containing JSONArray on success; otherwise Optional.empty()216 */217 private Optional<JSONArray> getConfigs(String authToken) {218 return clientService219 .buildGetRequestUsingFormUrlEncoding(restEndPointUrl + GET_CONFIGS, authToken)220 .flatMap(clientService::executeJsonRequest)221 .flatMap(configsObject -> contentHelper.getArrayFrom(configsObject, "Configs"));222 }223 /**224 * {@inheritDoc}225 */226 @Override227 public Optional<String[]> getConfigNames(String authToken) {228 return getConfigs(authToken)229 .flatMap(apiSerializer::getConfigNames)230 .map(Utility::toStringArray);231 }232 /**233 * {@inheritDoc}234 */235 @Override236 public boolean saveConfig(String authToken, String name, URL url, String engineGroupId) {237 try {238 Template template = FreemarkerConfiguration239 .getInstance()240 .getTemplate("scanConfigTemplate.ftl");241 String scanConfigXml = apiSerializer.getScanConfigXml(template, name, url);242 return clientService243 .buildPostRequestUsingFormUrlEncoding(244 restEndPointUrl + SAVE_CONFIG,245 authToken,246 contentHelper.pairFrom("defendEnabled", "true"),247 contentHelper.pairFrom("monitoringDelay", "0"),248 contentHelper.pairFrom("monitoringTriggerScan", "true"),249 contentHelper.pairFrom("id", "null"),250 contentHelper.pairFrom("name",name),251 contentHelper.pairFrom("clientId", "null"),252 contentHelper.pairFrom("engineGroupId",engineGroupId),253 contentHelper.pairFrom("monitoring", "true"),254 contentHelper.pairFrom("isApproveRequired", "false"),255 contentHelper.pairFrom("scanconfigxml", scanConfigXml))256 .flatMap(clientService::executeJsonRequest)257 .map(apiSerializer::getIsSuccess)258 .orElse(false);259 } catch (IOException | TemplateException e) {260 logger.println(e.toString());261 return false;262 }263 }264 // </editor-fold>265 // <editor-fold desc="Report APIs">266 private static final String GET_VULNERABILITIES_SUMMARY = "/Report/GetVulnerabilitiesSummaryXml";267 private static final String GET_REPORT_ZIP = "/Report/GetReportZip";268 /**269 * {@inheritDoc}270 */271 @Override272 public Optional<String> getVulnerabilitiesSummaryXml(String authToken, String scanId) {273 return clientService274 .buildGetRequestUsingFormUrlEncoding(restEndPointUrl + GET_VULNERABILITIES_SUMMARY, authToken, contentHelper.pairFrom(SCAN_ID, scanId))275 .flatMap(clientService::executeEntityRequest)276 .flatMap(contentHelper::getTextHtmlOrXmlContent);277 }278 /**279 * {@inheritDoc}280 */281 @Override282 public Optional<InputStream> getReportZip(String authToken, String scanId) {283 return clientService284 .buildGetRequestUsingFormUrlEncoding(restEndPointUrl + GET_REPORT_ZIP, authToken, contentHelper.pairFrom(SCAN_ID, scanId))285 .flatMap(clientService::executeEntityRequest)286 .flatMap(contentHelper::getInputStream);287 }288 // </editor-fold>289 // <editor-fold desc="Config APIs">290 private static final String GET_CLIENTS = "/Client/GetClients";291 /**292 * {@inheritDoc}293 */294 public Optional<List<ClientIdNamePair>> getClientNameIdPairs(String authToken) {295 return clientService296 .buildGetRequestUsingFormUrlEncoding(restEndPointUrl + GET_CLIENTS, authToken)297 .flatMap(clientService::executeJsonRequest)298 .filter(apiSerializer::getIsSuccess)299 .flatMap(clientObjects -> contentHelper.getArrayFrom(clientObjects, "Clients"))300 .flatMap(apiSerializer::getClientIdNamePairs);301 }302 // </editor-fold>303}...

Full Screen

Full Screen

run_scan

Using AI Code Generation

copy

Full Screen

1puts "Do you want to scan recursively? (y/n)"2end_class.run_scan(path, ext, str, recursive)3puts "Do you want to scan recursively? (y/n)"4end_class.run_scan(path, ext, str, recursive)5puts "Do you want to scan recursively? (y/n)"6end_class.run_scan(path, ext, str, recursive)

Full Screen

Full Screen

run_scan

Using AI Code Generation

copy

Full Screen

1puts "Do you want to scan recursively? (y/n)"2end_class.run_scan(path, ext, str, recursive)3puts "Do you want to scan recursively? (y/n)"4end_class.run_scan(path, ext, str, recursive)5puts "Do you want to scan recursively? (y/n)"6end_class.run_scan(path, ext, str, recursive)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Unobtainium_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful