Skip to content

Commit

Permalink
Scan automation for web server
Browse files Browse the repository at this point in the history
  • Loading branch information
opty authored and opty committed Mar 9, 2019
1 parent acb6222 commit 5f80e5e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
21 changes: 18 additions & 3 deletions JRomManager/src/jrm/server/ws/ProfileWS.java
Expand Up @@ -23,6 +23,7 @@
import jrm.profile.manager.Import;
import jrm.profile.manager.ProfileNFO;
import jrm.profile.scan.Scan;
import jrm.profile.scan.options.ScanAutomation;
import jrm.server.WebSession;

public class ProfileWS
Expand Down Expand Up @@ -134,7 +135,7 @@ void load(JsonObject jso)
})).start();
}

void scan(JsonObject jso)
void scan(JsonObject jso, boolean automate)
{
(ws.session.worker = new Worker(() -> {
WebSession session = ws.session;
Expand All @@ -149,7 +150,15 @@ void scan(JsonObject jso)
session.worker.progress.close();
session.worker.progress = null;
session.lastAction = new Date();
scanned(session.curr_scan);
ScanAutomation automation = ScanAutomation.valueOf(session.curr_profile.settings.getProperty("automation.scan", ScanAutomation.SCAN.toString()));
scanned(session.curr_scan, automation.hasReport());
if(automate)
{
if(session.curr_scan!=null && session.curr_scan.actions.stream().mapToInt(Collection::size).sum() > 0 && automation.hasFix())
{
fix(jso);
}
}
})).start();
}

Expand All @@ -169,6 +178,9 @@ void fix(JsonObject jso)
}
final Fix fix = new Fix(session.curr_profile, session.curr_scan, session.worker.progress);
fixed(fix);
ScanAutomation automation = ScanAutomation.valueOf(session.curr_profile.settings.getProperty("automation.scan", ScanAutomation.SCAN.toString()));
if(automation.hasScanAgain())
scan(jso, false);
}
finally
{
Expand Down Expand Up @@ -252,7 +264,7 @@ void loaded(final Profile profile)


@SuppressWarnings("serial")
void scanned(final Scan scan)
void scanned(final Scan scan, final boolean hasReport)
{
try
{
Expand All @@ -263,7 +275,10 @@ void scanned(final Scan scan)
add("params", new JsonObject() {{
add("success", scan!=null);
if(scan!=null)
{
add("actions", scan.actions.stream().mapToInt(Collection::size).sum());
add("report", hasReport);
}
}});
}}.toString());
}
Expand Down
2 changes: 1 addition & 1 deletion JRomManager/src/jrm/server/ws/WebSckt.java
Expand Up @@ -87,7 +87,7 @@ protected void onMessage(WebSocketFrame messageFrame)
}
case "Profile.scan":
{
new ProfileWS(this).scan(jso);
new ProfileWS(this).scan(jso, true);
break;
}
case "Profile.fix":
Expand Down

0 comments on commit 5f80e5e

Please sign in to comment.