This repository was archived by the owner on Jul 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDHCP.java
More file actions
138 lines (105 loc) · 4.49 KB
/
Copy pathDHCP.java
File metadata and controls
138 lines (105 loc) · 4.49 KB
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
130
131
132
133
134
135
136
137
138
package profile;
import java.util.Map;
import java.util.Vector;
import core.data.InterfaceData;
import core.iface.IUnit;
import core.model.FirewallModel;
import core.model.NetworkModel;
import core.model.ServerModel;
import core.profile.AStructuredProfile;
import core.unit.SimpleUnit;
import core.unit.fs.CustomFileUnit;
import core.unit.pkg.InstalledUnit;
public class DHCP extends AStructuredProfile {
private Vector<String> classes;
private Vector<String> stanzas;
private Vector<String> listeningIfaces;
public DHCP(ServerModel me, NetworkModel networkModel) {
super("dhcp", me, networkModel);
this.classes = new Vector<String>();
this.stanzas = new Vector<String>();
this.listeningIfaces = new Vector<String>();
}
public void addStanza(String stanza) {
this.stanzas.add(stanza);
}
public void addClass(String stanza) {
this.classes.add(stanza);
}
public void addListeningIface(String iface) {
this.listeningIfaces.add(iface);
}
public Vector<IUnit> getPersistentConfig() {
Vector<IUnit> units = new Vector<IUnit>();
String ifaceAutoString = "lan0";
//Build listening interfaces
for (InterfaceData iface : me.getInterfaces()) {
//Skip over non-LAN interfaces, or we'll potentially offer DHCP to the whole internet!
if (!iface.getIface().contains("lan") || iface.getMac() == null) { continue; }
ifaceAutoString += " " + iface.getIface();
this.stanzas.add(iface.getDhcpStanza());
}
units.addElement(((ServerModel)me).getConfigsModel().addConfigFile("dhcp_defiface", "dhcp_installed", "INTERFACES=\\\"" + ifaceAutoString + "\\\"", "/etc/default/isc-dhcp-server"));
((ServerModel)me).getProcessModel().addProcess("/usr/sbin/dhcpd -4 -q -cf /etc/dhcp/dhcpd.conf " + ifaceAutoString + "$");
return units;
}
protected Vector<IUnit> getInstalled() {
Vector<IUnit> units = new Vector<IUnit>();
units.addElement(new InstalledUnit("dhcp", "isc-dhcp-server"));
return units;
}
public Vector<IUnit> getNetworking() {
Vector<IUnit> units = new Vector<IUnit>();
FirewallModel fm = ((ServerModel)me).getFirewallModel();
for (Map.Entry<String, String> lanIface : networkModel.getData().getLanIfaces(me.getLabel()).entrySet() ) {
fm.addFilterInput("dhcp_ipt_in", "-i " + lanIface.getKey() + " -p udp --dport 67 -j ACCEPT", "Allow server to get an address by DHCP (This is only used up until the first configuration)");
fm.addFilterOutput("dhcp_ipt_out", "-o " + lanIface.getKey() + " -p udp --sport 67 -j ACCEPT", "Allow server to get an address by DHCP (This is only used up until the first configuration)");
}
return units;
}
protected Vector<IUnit> getLiveConfig() {
Vector<IUnit> units = new Vector<IUnit>();
units.addElement(new CustomFileUnit("dhcp_custom_conf", "dhcp_installed", "/etc/dhcp/dhcpd.custom.conf"));
String dhcpconf = "";
dhcpconf += "include \\\"/etc/dhcp/dhcpd.custom.conf\\\";\n";
dhcpconf += "\n";
dhcpconf += "ddns-update-style none;\n";
dhcpconf += "option domain-name \\\"" + networkModel.getData().getDomain(me.getLabel()) + "\\\";\n";
dhcpconf += "option domain-name-servers 10.0.0.1;\n";
dhcpconf += "default-lease-time 600;\n";
dhcpconf += "max-lease-time 1800;\n";
dhcpconf += "authoritative;\n";
dhcpconf += "log-facility local7;\n";
dhcpconf += "\n";
dhcpconf += "shared-network " + networkModel.getLabel() + " {\n";
dhcpconf += "\n";
dhcpconf += "\tsubnet 10.0.0.0 netmask 255.0.0.0 {\n";
dhcpconf += "\t}\n";
if (networkModel.getData().getAutoGuest()) {
dhcpconf += "\n";
dhcpconf += "\t#This is our pool for guest connections\n";
dhcpconf += "\t#We put it first, because everyone is a guest until they aren't!\n";
dhcpconf += "\tsubnet 10.250.0.0 netmask 255.255.252.0 {\n";
dhcpconf += "\t\tpool {\n";
dhcpconf += "\t\t\trange 10.250.0.15 10.250.3.255;\n";
dhcpconf += "\t\t\toption routers 10.0.0.1;\n";
dhcpconf += "\t\t\toption domain-name-servers 1.1.1.1;\n";
dhcpconf += "\t\t\tdeny members of \"VPN\";\n";
dhcpconf += "\t\t}\n";
dhcpconf += "\t}";
}
for (int i = 0; i < this.classes.size(); ++i) {
dhcpconf += this.classes.elementAt(i);
}
dhcpconf += "\n";
for (String stanza : this.stanzas) {
dhcpconf += stanza;
}
dhcpconf += "\n}";
units.addElement(((ServerModel)me).getConfigsModel().addConfigFile("dhcp", "dhcp_installed", dhcpconf, "/etc/dhcp/dhcpd.conf"));
units.addElement(new SimpleUnit("dhcp_running", "dhcp_installed",
"",
"sudo service isc-dhcp-server restart", "", "pass"));
return units;
}
}