This repository has been 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
/
Copy pathDedicated.java
83 lines (66 loc) · 2.7 KB
/
Dedicated.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
package profile;
import java.net.InetAddress;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
import javax.swing.JOptionPane;
import core.data.InterfaceData;
import core.iface.IUnit;
import core.model.InterfaceModel;
import core.model.NetworkModel;
import core.model.ServerModel;
import core.profile.AStructuredProfile;
import core.unit.fs.DirUnit;
public class Dedicated extends AStructuredProfile {
public Dedicated(ServerModel me, NetworkModel networkModel) {
super("dedicated", me, networkModel);
}
protected Vector<IUnit> getPersistentConfig() {
Vector<IUnit> units = new Vector<IUnit>();
//Create /media/metaldata
units.addElement(new DirUnit("metaldata_bindpoint", "proceed", "/media/metaldata"));
//Create /media/data bindfs point
units.addElement(new DirUnit("data_dir_exists", "proceed", "/media/data/"));
return units;
}
public Vector<IUnit> getNetworking() {
Vector<IUnit> units = new Vector<IUnit>();
HashMap<String, String> lanIfaces = networkModel.getData().getLanIfaces(me.getLabel());
if (lanIfaces.isEmpty()) {
JOptionPane.showMessageDialog(null, "You must declare at least one lan interface for \"" + me.getLabel() + ".\n\nFormat is:\n\"lan\":[{\"interfacename\":\"macaddress\"}]");
System.exit(1);
}
else {
me.setFirstOctet(10);
me.setSecondOctet(0);
me.setThirdOctet(networkModel.getDediServers().indexOf(me) + 1);
int i = 0;
for (Map.Entry<String, String> lanIface : lanIfaces.entrySet() ) {
InterfaceModel im = me.getInterfaceModel();
InetAddress subnet = networkModel.stringToIP(me.getFirstOctet() + "." + me.getSecondOctet() + "." + me.getThirdOctet() + "." + (i * 4));
InetAddress router = networkModel.stringToIP(me.getFirstOctet() + "." + me.getSecondOctet() + "." + me.getThirdOctet() + "." + ((i * 4) + 1));
InetAddress address = networkModel.stringToIP(me.getFirstOctet() + "." + me.getSecondOctet() + "." + me.getThirdOctet() + "." + ((i * 4) + 2));
InetAddress broadcast = networkModel.stringToIP(me.getFirstOctet() + "." + me.getSecondOctet() + "." + me.getThirdOctet() + "." + ((i * 4) + 3));
InetAddress netmask = networkModel.getData().getNetmask();
im.addIface(new InterfaceData(me.getLabel(),
lanIface.getKey(),
lanIface.getValue(),
"static",
null,
subnet,
address,
netmask,
broadcast,
router,
"comment goes here")
);
++i;
}
}
me.addRequiredEgress("cdn.debian.net");
me.addRequiredEgress("security-cdn.debian.org");
me.addRequiredEgress("prod.debian.map.fastly.net");
me.addRequiredEgress("download.virtualbox.org");
return units;
}
}