Skip to content

Commit fe75dcd

Browse files
committed
Merge branch 'release-0.3'
2 parents 04c3037 + 16053b9 commit fe75dcd

24 files changed

Lines changed: 1035 additions & 221 deletions

.travis.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
language: java
2+
sudo: false
23
jdk:
3-
- oraclejdk8
4+
- oraclejdk8
5+
6+
addons:
7+
apt:
8+
packages:
9+
- nmap
10+
11+
before_install:
12+
- pip install --user codecov
13+
414
after_success:
5-
- bash <(curl -s https://codecov.io/bash)
15+
- codecov
16+

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ Advanced Graphical User Interface for NMap
33

44
[![Build Status](https://travis-ci.org/danicuestasuarez/NMapGUI.svg?branch=develop)](https://travis-ci.org/danicuestasuarez/NMapGUI)
55
[![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)
6+
[![codecov](https://codecov.io/gh/danicuestasuarez/NMapGUI/branch/develop/graph/badge.svg)](https://codecov.io/gh/danicuestasuarez/NMapGUI)
67

7-
On progress: Menu creation
8+
On progress: Menu creation

pom.xml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.uniovi.nmapgui</groupId>
77
<artifactId>nmapGUI</artifactId>
8-
<version>0.0.1-SNAPSHOT</version>
8+
<version>0.3-SNAPSHOT</version>
99
<packaging>jar</packaging>
1010

1111
<name>NMapGUI</name>
@@ -39,10 +39,40 @@
3939

4040
<build>
4141
<plugins>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-jar-plugin</artifactId>
45+
<configuration>
46+
<archive>
47+
<manifest>
48+
<mainClass>com.uniovi.nmapgui.NMapGuiLoader</mainClass>
49+
</manifest>
50+
</archive>
51+
</configuration>
52+
</plugin>
4253
<plugin>
4354
<groupId>org.springframework.boot</groupId>
4455
<artifactId>spring-boot-maven-plugin</artifactId>
4556
</plugin>
57+
<plugin>
58+
<groupId>org.jacoco</groupId>
59+
<artifactId>jacoco-maven-plugin</artifactId>
60+
<version>0.7.9</version>
61+
<executions>
62+
<execution>
63+
<goals>
64+
<goal>prepare-agent</goal>
65+
</goals>
66+
</execution>
67+
<execution>
68+
<id>report</id>
69+
<phase>test</phase>
70+
<goals>
71+
<goal>report</goal>
72+
</goals>
73+
</execution>
74+
</executions>
75+
</plugin>
4676
</plugins>
4777
</build>
4878

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
11
package com.uniovi.nmapgui;
22

3-
import java.util.concurrent.Executor;
4-
53
import org.springframework.boot.SpringApplication;
64
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.context.ConfigurableApplicationContext;
76
import org.springframework.scheduling.annotation.AsyncConfigurerSupport;
87
import org.springframework.scheduling.annotation.EnableAsync;
9-
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
108

119
@SpringBootApplication
1210
@EnableAsync
1311
public class NMapGuiApplication extends AsyncConfigurerSupport {
1412

15-
public static void main(String[] args) {
16-
SpringApplication.run(NMapGuiApplication.class, args);
13+
public static ConfigurableApplicationContext mainExec(String[] args) {
14+
return SpringApplication.run(NMapGuiApplication.class, args);
1715
}
1816

19-
@Override
20-
public Executor getAsyncExecutor() {
21-
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
22-
executor.setCorePoolSize(2);
23-
executor.setMaxPoolSize(2);
24-
executor.setQueueCapacity(500);
25-
executor.setThreadNamePrefix("NMap-Thread-");
26-
executor.initialize();
27-
return executor;
28-
}
17+
public static void main(String[] args) {
18+
mainExec(args);
19+
}
2920
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.uniovi.nmapgui;
2+
3+
import javax.swing.JFrame;
4+
5+
public class NMapGuiLoader {
6+
7+
public static void main(String[] args) {
8+
JFrame f = new NMapLoaderWindow();
9+
f.setResizable(false);
10+
f.setLocationRelativeTo(null);
11+
f.setVisible(true);
12+
}
13+
14+
}
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
package com.uniovi.nmapgui;
2+
3+
import java.awt.BorderLayout;
4+
import java.awt.Container;
5+
import java.awt.Desktop;
6+
import java.awt.FlowLayout;
7+
import java.awt.GridLayout;
8+
import java.awt.event.ActionEvent;
9+
import java.awt.event.ActionListener;
10+
import java.awt.image.BufferedImage;
11+
import java.io.IOException;
12+
import java.net.MalformedURLException;
13+
import java.net.URI;
14+
import java.net.URISyntaxException;
15+
import java.net.URL;
16+
17+
import javax.imageio.ImageIO;
18+
import javax.swing.BorderFactory;
19+
import javax.swing.ImageIcon;
20+
import javax.swing.JButton;
21+
import javax.swing.JFrame;
22+
import javax.swing.JLabel;
23+
import javax.swing.JPanel;
24+
25+
import org.springframework.context.ConfigurableApplicationContext;
26+
27+
import com.uniovi.nmapgui.executor.CommandExecutor;
28+
import com.uniovi.nmapgui.model.Command;
29+
30+
31+
public class NMapLoaderWindow extends JFrame {
32+
33+
34+
private static final long serialVersionUID = 3028171478038465651L;
35+
36+
37+
private static final String IMG_PATH = "static/img/header.jpg";
38+
39+
40+
private JLabel image;
41+
private JButton start;
42+
private JButton stop;
43+
private ConfigurableApplicationContext springContext;
44+
private JButton go;
45+
private CommandExecutor executor = new CommandExecutor(new Command("-V"));
46+
private boolean nmapInstalled;
47+
48+
49+
public NMapLoaderWindow(){
50+
super("NMapGUI");
51+
try {
52+
executor.execute();
53+
executor.getCommandThread().join();
54+
55+
} catch (InterruptedException e) {
56+
e.printStackTrace();
57+
}
58+
nmapInstalled=executor.getCmd().getOutput().getText().contains("Nmap version");
59+
60+
setSize(400, 300);
61+
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
62+
Container cp = getContentPane();
63+
BorderLayout layout = new BorderLayout();
64+
cp.setLayout(layout);
65+
cp.add(image(), BorderLayout.CENTER);
66+
cp.add(buttons(), BorderLayout.SOUTH);
67+
68+
}
69+
70+
private JPanel image() {
71+
JPanel panel = new JPanel();
72+
panel.setLayout(new BorderLayout());
73+
BufferedImage img = null;
74+
75+
try {
76+
img = ImageIO.read(NMapLoaderWindow.class.getClassLoader().getResource(IMG_PATH));
77+
} catch (IOException e) {
78+
e.printStackTrace();
79+
}
80+
ImageIcon icon = new ImageIcon(img);
81+
image = new JLabel(icon);
82+
image.setLayout(new FlowLayout(FlowLayout.RIGHT));
83+
84+
85+
go= new JButton("Go!");
86+
go.setEnabled(false);
87+
88+
go.addActionListener(new ActionListener() {
89+
@Override
90+
public void actionPerformed(ActionEvent e) {
91+
try {
92+
openWebpage(new URL("http://localhost:8080/nmap"));
93+
} catch (MalformedURLException e1) {
94+
e1.printStackTrace();
95+
}
96+
}
97+
});
98+
image.add(go);
99+
panel.add(image);
100+
101+
return panel;
102+
}
103+
104+
private JPanel buttons() {
105+
JPanel buttons = new JPanel();
106+
buttons.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
107+
GridLayout gl = new GridLayout(2,1);
108+
gl.setHgap(10);
109+
gl.setVgap(5);
110+
buttons.setLayout(gl);
111+
start = new JButton("Start NMapGUI");
112+
if(!nmapInstalled){
113+
start.setEnabled(false);
114+
start.setText("NMap is not installed");
115+
116+
}
117+
start.addActionListener(new ActionListener() {
118+
@Override
119+
public void actionPerformed(ActionEvent e) {
120+
start.setEnabled(false);
121+
String[] args = {};
122+
springContext = NMapGuiApplication.mainExec(args);
123+
start.setText("NMapGUI running");
124+
go.setEnabled(true);
125+
stop.setText("Stop NMapGUI");
126+
stop.setEnabled(true);
127+
}
128+
});
129+
buttons.add(start);
130+
131+
stop = new JButton("Nmap not running");
132+
stop.addActionListener(new ActionListener() {
133+
@Override
134+
public void actionPerformed(ActionEvent e) {
135+
stop.setEnabled(false);
136+
go.setEnabled(false);
137+
springContext.close();
138+
stop.setText("NMapGUI not running");
139+
start.setText("Start NMapGUI");
140+
start.setEnabled(true);
141+
}
142+
});
143+
stop.setEnabled(false);
144+
buttons.add(stop);
145+
146+
147+
148+
return buttons;
149+
}
150+
151+
152+
153+
154+
public static void openWebpage(URI uri) {
155+
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
156+
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
157+
try {
158+
desktop.browse(uri);
159+
} catch (Exception e) {
160+
e.printStackTrace();
161+
}
162+
}
163+
}
164+
165+
public static void openWebpage(URL url) {
166+
try {
167+
openWebpage(url.toURI());
168+
} catch (URISyntaxException e) {
169+
e.printStackTrace();
170+
}
171+
}
172+
}

src/main/java/com/uniovi/nmapgui/WebController.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package com.uniovi.nmapgui;
22

33

4-
import java.io.File;
5-
import java.io.FileInputStream;
4+
65
import java.io.FileNotFoundException;
76
import java.io.InputStream;
87
import java.util.ArrayList;
98
import java.util.List;
109

11-
import javax.annotation.Resource;
12-
1310
import org.springframework.core.io.InputStreamResource;
1411
import org.springframework.http.MediaType;
1512
import org.springframework.http.ResponseEntity;
@@ -29,6 +26,7 @@ public class WebController {
2926
private List<Command> commands;
3027
private Command command;
3128

29+
3230
@GetMapping("/nmap")
3331
public String command(Model model) {
3432
command = new Command();
@@ -44,28 +42,28 @@ public String command(Model model) {
4442
public String command(Model model, @RequestParam String code) {
4543
command = new Command(code);
4644
commands.add(0,command);
47-
new CommandExecutor().execute(command);
45+
new CommandExecutor(command).execute();
4846
model.addAttribute("command", command);
4947
model.addAttribute("commands", commands);
5048

51-
return "index :: output";
49+
return "fragments/contents :: output";
5250
}
5351

5452

5553
@GetMapping("/nmap/update")
56-
public String updateOut(Model model) {
54+
public String updateOut(Model model, @RequestParam boolean allowDel) {
5755

5856
model.addAttribute("command", command);
5957
model.addAttribute("commands", commands);
6058
boolean notFinished=false;
6159
for(Command cmd : commands)
6260
if(notFinished=!cmd.isFinished())
6361
break;
64-
if(!notFinished)
62+
if(!notFinished && allowDel)
6563
commands=new ArrayList<>();
6664

6765

68-
return "index :: output";
66+
return "fragments/contents :: output";
6967
}
7068

7169
@GetMapping("/nmap/update-finished")
@@ -76,15 +74,21 @@ public String updateOut(Model model) {
7674
return true;
7775
}
7876
@GetMapping("/nmap/download/{filename}")
79-
public ResponseEntity<InputStreamResource> download(@PathVariable("filename") String filename) throws FileNotFoundException {
77+
public ResponseEntity<InputStreamResource> download(@PathVariable("filename") String filename) {
8078

81-
InputStream file= new Filefinder().find(filename);
82-
83-
InputStreamResource resource = new InputStreamResource(file);
79+
InputStream file;
80+
try {
81+
file = new Filefinder().find(filename);
82+
InputStreamResource resource = new InputStreamResource(file);
8483

85-
return ResponseEntity.ok()
86-
.contentType(MediaType.parseMediaType("application/octect-stream"))
87-
.body(resource);
84+
return ResponseEntity.ok()
85+
.contentType(MediaType.parseMediaType("application/octect-stream"))
86+
.body(resource);
87+
} catch (FileNotFoundException e) {
88+
return ResponseEntity.notFound().build();
89+
}
90+
91+
8892
}
8993

9094
// @GetMapping("/nmap/update-finished-list")

0 commit comments

Comments
 (0)