forked from privacyint/thornsec-profiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWifi.java
129 lines (100 loc) · 3.75 KB
/
Wifi.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package profile;
import core.model.NetworkModel;
import core.model.ServerModel;
import core.profile.AStructuredProfile;
public class Wifi extends AStructuredProfile {
public Wifi(ServerModel me, NetworkModel networkModel) {
super("wifi", me, networkModel);
}
/*
protected Vector<IUnit> getInstalled(String server, NetworkModel model) {
Vector<IUnit> units = new Vector<IUnit>();
units.addElement(new InstalledUnit("hostapd", "proceed", "hostapd"));
return units;
}
protected Vector<IUnit> getPersistentConfig(String server, NetworkModel model) {
Vector<IUnit> units = new Vector<IUnit>();
String hostapdconf = "DAEMON_CONF=\"/etc/hostapd/hostapd.conf\"";
units.addElement(new FileUnit("wifi_set_config_location", "hostapd_installed", hostapdconf, "/etc/default/hostapd"));
JsonArray interfaces = (JsonArray) model.getData().getPropertyObjectArray(server, "wifi");
for (int i = 0; i < interfaces.size(); ++i) {
JsonObject row = interfaces.getJsonObject(i);
String iface = row.getString("iface", null);
//We're declaring a real iface
if (!iface.equals(null)) {
units.addElement(model.getServerModel(server).getInterfaceModel().addIface("wifi_router_iface_" + i,
"manual",
iface,
null,
null,
null,
null,
null));
for (String router : model.getRouters()) {
DHCP dhcp = model.getServerModel(router).getRouter().getDHCP();
dhcp.addListeningIface(iface);
}
}
}
//Hostapd only really acts as a switch, so let's add it to a bridge to keep config overheads down
units.addElement(model.getServerModel(server).getInterfaceModel().addIface("wifi_bridge",
"manual",
iface,
null,
null,
null,
null,
null));
for (String router : model.getRouters()) {
DHCP dhcp = model.getServerModel(router).getRouter().getDHCP();
dhcp.addListeningIface(iface);
}
return units;
}
protected Vector<IUnit> getLiveConfig(String server, NetworkModel model) {
Vector<IUnit> units = new Vector<IUnit>();
String hostapdconf = "";
JsonArray interfaces = (JsonArray) model.getData().getPropertyObjectArray(server, "wifi");
for (int i = 0; i < interfaces.size(); ++i) {
JsonObject row = interfaces.getJsonObject(i);
String iface = row.getString("iface", null);
String ssid = row.getString("ssid", model.getData().getDomain(server) + " WiFi " + i);
String channel = row.getString("channel", "1");
String mode = row.getString("mode", "g");
String passwd = row.getString("passphrase", null);
//This is a full wifi interface definition
if (!iface.equals(null)) {
hostapdconf += "interface=" + iface + "\n";
hostapdconf += "hw_mode=" + mode + "\n";
hostapdconf += "channel=" + channel + "\n";
hostapdconf += "ieee80211n=1\n";
hostapdconf += "ieee80211ac=1\n";
hostapdconf += "wmm_enabled=1\n";
hostapdconf += "\n";
hostapdconf += "ssid=" + ssid + "\n";
hostapdconf += "auth_algs=1\n";
hostapdconf += "wpa=2\n";
hostapdconf += "wpa_key_mgmt=WPA-PSK\n";
hostapdconf += "rsn_pairwise=CCMP\n";
hostapdconf += "wpa_passphrase=" + passwd;
}
else { //A virtual iface
hostapdconf += "\n";
hostapdconf += "bss=wlan" + i + "\n";
hostapdconf += "ssid=" + ssid + "\n";
hostapdconf += "auth_algs=1\n";
hostapdconf += "wpa=2\n";
hostapdconf += "wpa_key_mgmt=WPA-PSK\n";
hostapdconf += "rsn_pairwise=CCMP\n";
hostapdconf += "wpa_passphrase=" + passwd;
}
}
units.addElement(new FileUnit("wifi_set_config", "hostapd_installed", hostapdconf, "/etc/hostapd/hostapd.conf"));
return units;
}
protected Vector<IUnit> getPersistentFirewall(String server, NetworkModel model) {
Vector<IUnit> units = new Vector<IUnit>();
return units;
}
*/
}