Skip to content

Commit

Permalink
Merge branch 'release-0.2'
Browse files Browse the repository at this point in the history
Updated master to shocase new functionality
  • Loading branch information
daniel-cues committed Jul 11, 2017
2 parents f3ba7d6 + 8269b19 commit 04c3037
Show file tree
Hide file tree
Showing 31 changed files with 1,665 additions and 286 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ build/
nbbuild/
dist/
nbdist/
.nb-gradle/
.nb-gradle/

### NMap outputs ###
nmap-scan_*.xml
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: java
jdk:
- oraclejdk8
after_success:
- bash <(curl -s https://codecov.io/bash)
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# NMapGUI
Advanced Graphical User Interface for NMap

[![Build Status](https://travis-ci.org/danicuestasuarez/NMapGUI.svg?branch=develop)](https://travis-ci.org/danicuestasuarez/NMapGUI)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/37479ced18a04d4e8f1c38753b22003c)](https://www.codacy.com/app/danicuestasuarez/NMapGUI?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=danicuestasuarez/NMapGUI&amp;utm_campaign=Badge_Grade)

On progress: Menu creation
Binary file removed data/elasticsearch/nodes/0/_state/global-142.st
Binary file not shown.
Empty file.
Binary file removed data/elasticsearch/nodes/1/_state/global-5.st
Binary file not shown.
Empty file.
3 changes: 0 additions & 3 deletions google.es

This file was deleted.

8 changes: 1 addition & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<packaging>jar</packaging>

<name>NMapGUI</name>
<description>GUI forn NMap</description>
<description>GUI for NMap</description>

<parent>
<groupId>org.springframework.boot</groupId>
Expand All @@ -35,12 +35,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>
spring-boot-starter-data-elasticsearch
</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
94 changes: 83 additions & 11 deletions src/main/java/com/uniovi/nmapgui/WebController.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,117 @@
package com.uniovi.nmapgui;


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.core.io.InputStreamResource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.uniovi.nmapgui.executor.CommandExecutor;
import com.uniovi.nmapgui.model.Command;
import com.uniovi.nmapgui.util.Filefinder;

@Controller
public class WebController {
private CommandExecutor executor = new CommandExecutor();
Command command = new Command();

private List<Command> commands;
private Command command;
@GetMapping("/nmap")
public String command(Model model) {
command = new Command();
executor = new CommandExecutor();
commands= new ArrayList<Command>();
model.addAttribute("command", command);
model.addAttribute("output",executor.out);
model.addAttribute("commands", commands);


return "index";
}

@GetMapping("/nmap-exe")
public String command(Model model, @RequestParam String code) {
command.setText(code);
executor.execute(command);
model.addAttribute("output",executor.out);
command = new Command(code);
commands.add(0,command);
new CommandExecutor().execute(command);
model.addAttribute("command", command);
return "index :: out-fragment";
model.addAttribute("commands", commands);

return "index :: output";
}


@GetMapping("/nmap/update")
public String updateOut(Model model) {
model.addAttribute("output",executor.out);

model.addAttribute("command", command);
model.addAttribute("commands", commands);
boolean notFinished=false;
for(Command cmd : commands)
if(notFinished=!cmd.isFinished())
break;
if(!notFinished)
commands=new ArrayList<>();


return "index :: out-fragment";
return "index :: output";
}

@GetMapping("/nmap/update-finished")
public @ResponseBody Boolean updateEnd() {
for(Command cmd : commands)
if(!cmd.isFinished())
return false;
return true;
}
@GetMapping("/nmap/download/{filename}")
public ResponseEntity<InputStreamResource> download(@PathVariable("filename") String filename) throws FileNotFoundException {

InputStream file= new Filefinder().find(filename);

InputStreamResource resource = new InputStreamResource(file);

return ResponseEntity.ok()
.contentType(MediaType.parseMediaType("application/octect-stream"))
.body(resource);
}

// @GetMapping("/nmap/update-finished-list")
// public @ResponseBody List<Integer> updateEndList() {
// List<Integer> ids = new ArrayList<Integer>();
// int index=0;
// for(Command cmd : commands)
// {
// if(!cmd.isFinished())
// ids.add(++index);
// else if(!cmd.isChkUpdateFlag()){
// cmd.setChkUpdateFlag(true);
// ids.add(++index);
// }
// }
// return ids;
// }
//
// @GetMapping("/nmap/updateid")
// public String updateOut(Model model, @RequestParam int id) {
// model.addAttribute("command", command);
// model.addAttribute("commands", commands);
//
//
// return "index :: out"+id;
// }
//
//

}
69 changes: 60 additions & 9 deletions src/main/java/com/uniovi/nmapgui/executor/CommandExecutor.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,69 @@
package com.uniovi.nmapgui.executor;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.ArrayUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import com.uniovi.nmapgui.model.*;
import com.uniovi.nmapgui.util.TransInfoHtml;

@Service
public class CommandExecutor {
public Output out=new Output();
private Command cmd;
private String tempPath;

public CommandExecutor() {
this.setTempPath(System.getProperty("user.dir")+"/src/main/resources/static/temp/");
}


@Async
public void execute(Command command){
out = new Output();
String[] commands = (String[])ArrayUtils.addAll(new String[]{"nmap"},command.getText().split(" "));
try {

Process p = Runtime.getRuntime().exec(commands);
cmd=command;
String filename= "nmap-scan_" + new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss")
.format(new Date())+ ".xml";
this.cmd.getOutput().setFilename(filename);
tempPath=tempPath + filename;
List<String> commandsList = new ArrayList<String>();
commandsList.add("nmap");
commandsList.addAll(Arrays.asList(command.getText().split(" ")));
commandsList.addAll(Arrays.asList(new String[]{"-oX" , tempPath}));
try {
Process p = Runtime.getRuntime().exec(commandsList.toArray(new String[]{}));
final InputStream stream = p.getInputStream();
final InputStream errors = p.getErrorStream();
new Thread(new Runnable() {
public void run() {
BufferedReader reader = null;
BufferedReader errorReader = null;

try {
reader = new BufferedReader(new InputStreamReader(stream));
String line = null;
while ((line = reader.readLine()) != null) {
out.setText(out.getText()+line+"<br/>");
cmd.getOutput().setText(cmd.getOutput().getText()+line+"<br/>");
}
errorReader = new BufferedReader(new InputStreamReader(errors));
while ((line = errorReader.readLine()) != null) {
cmd.getOutput().setText(cmd.getOutput().getText()+"<i>"+line+"</i><br/>");
}

} catch (Exception e) {
// TODO
} finally {
readXML();
cmd.setFinished(true);
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
// ignore
cmd.setFinished(true);
}
}
}
Expand All @@ -47,6 +74,30 @@ public void run() {
e.printStackTrace();
}
}


public String getTempPath() {
return tempPath;
}


public void setTempPath(String tempPath) {
this.tempPath = tempPath;
}

public void readXML() {
StringBuilder sb = new StringBuilder();
try (BufferedReader br = new BufferedReader(new FileReader(tempPath))){
String sCurrentLine;
while ((sCurrentLine = br.readLine()) != null) {
sb.append(sCurrentLine);
}
cmd.getOutput().setXml(TransInfoHtml.transformToHtml(sb.toString()));

} catch (Exception e) {
e.printStackTrace();
}
}


}
38 changes: 36 additions & 2 deletions src/main/java/com/uniovi/nmapgui/model/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,47 @@
public class Command {

private String text;

public String getText() {
private boolean finished = false;
private Output output = new Output();
private boolean chkUpdateFlag = false;

public Command() {}

public Command(String text) {
setText(text);
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}

public boolean isFinished() {
return finished;
}

public void setFinished(boolean finished) {
this.finished = finished;
}

public Output getOutput() {
return output;
}

public void setCommand(Output output) {
this.output = output;
}

public boolean isChkUpdateFlag() {
return chkUpdateFlag;
}

public void setChkUpdateFlag(boolean chkUpdateFlag) {
this.chkUpdateFlag = chkUpdateFlag;
}


}
21 changes: 20 additions & 1 deletion src/main/java/com/uniovi/nmapgui/model/Output.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

public class Output {
private String text="";

private String xml="";
private String filename;

public String getText() {
return text;
}
Expand All @@ -11,4 +13,21 @@ public void setText(String text) {
this.text = text;
}


public String getXml() {
return xml;
}

public void setXml(String xml) {
this.xml = xml;
}

public String getFilename() {
return filename;
}

public void setFilename(String filename) {
this.filename = filename;
}

}
15 changes: 15 additions & 0 deletions src/main/java/com/uniovi/nmapgui/util/Filefinder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.uniovi.nmapgui.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

public class Filefinder {

public InputStream find(String filename) throws FileNotFoundException {
File xml =new File(System.getProperty("user.dir")+"/src/main/resources/static/temp/"+filename+".xml");
return new FileInputStream(xml);
}

}
Loading

0 comments on commit 04c3037

Please sign in to comment.