Skip to content

Commit

Permalink
version 2.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
EasyG0ing1 committed Apr 23, 2024
1 parent 45195ae commit 7a22a73
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 125 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,13 @@ build/
/graalBuild/**
/GB/
/GB/*
/config.xml
/HotConfig1.xml
/HotConfig2.xml
/KeaDisabled.xml
/KeaEnabled.xml
/HotConfigCID.xml
/testCID.sh
/HotConfigBadIP.xml
/HotConfigBadMac.xml
/testNative.sh
4 changes: 2 additions & 2 deletions .idea/deployment.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/webServers.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ Create an Issue or a Pull Request if you want to contribute to the project.

### Updates

* 2.1.4
* Modified handling of ISC DHCP mappings when no MAC address exists where a CID value is provided
* Updated the static mapping error messages so that they include relevant details from the static map, making it easier to locate the record for correction

* 2.1.3
* Minor changes to code structure

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.simtechdata</groupId>
<artifactId>Migration</artifactId>
<version>2.1.3</version>
<version>2.1.4</version>
<packaging>jar</packaging>

<name>Migration</name>
Expand Down
113 changes: 72 additions & 41 deletions src/main/java/com/simtechdata/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.lang.StringTemplate.STR;

public class App {

private static final String EXE_FOLDER = System.getProperty("user.dir");
private static final Path OUT_FILE = Paths.get(EXE_FOLDER, "new_config.xml");
private static final Path IN_FILE = Paths.get(EXE_FOLDER, "config.xml");
private static final String LF = System.getProperty("line.separator");
private static boolean isCheck = false;
private static boolean debug = false;
private static final Path OUT_FILE = Paths.get(EXE_FOLDER, "new_config.xml");
private static final Path IN_FILE = Paths.get(EXE_FOLDER, "config.xml");
private static final Path SKIPPED = Paths.get(EXE_FOLDER, "skippedMappings.txt");
private static final String NL = System.getProperty("line.separator");
private static boolean isCheck = false;
private static boolean debug = false;
private static final LinkedList<Staticmap> failedStaticmaps = new LinkedList<>();


public static void main(String[] args) {
Expand Down Expand Up @@ -152,13 +153,13 @@ public static void main(String[] args) {
* and the import process will be expecting to see a UUID for the record.
*/

if(debug){
if (debug) {
System.out.println("Old Statics");
}

List<Reservation> reservationList = new ArrayList<>();

if(staticMappings.isEmpty()) {
if (staticMappings.isEmpty()) {
System.out.println("Could not find any existing static mappings");
System.exit(1);
}
Expand All @@ -168,11 +169,12 @@ public static void main(String[] args) {
for (Staticmap m : staticMappings) {
Reservation rsv = new Reservation();
String mac = m.getMac();
String ipAddy = m.getIpaddr();
String description = m.getDescr();
String cid = m.getCid();
String ipAddy = m.getIpAddress();
String description = m.getDescription();
String hostname = m.getHostname();
String uuid = getUUID();
while(uuidSet.contains(uuid))
while (uuidSet.contains(uuid))
uuid = getUUID();
uuidSet.add(uuid);
rsv.setUuid(uuid);
Expand All @@ -182,7 +184,7 @@ public static void main(String[] args) {
rsv.setDescription(description);
rsv.setSubnet(getSubnet(ipAddy, subnet4List));
reservationList.add(rsv);
if(debug) {
if (debug) {
String dbs = STR."\{ipAddy}\n\{mac}\{hostname}\n\{description}\n";
System.out.println(dbs);
}
Expand Down Expand Up @@ -226,10 +228,26 @@ public static void main(String[] args) {
StreamResult result = new StreamResult(writer);
transformer.transform(source, result);
String pattern = "\\r?\\n\\s+\\r?\\n";
String prettyXML = writer.toString().replaceAll(pattern, LF);
String prettyXML = writer.toString().replaceAll(pattern, NL);
OUT_FILE.toFile().createNewFile();
Files.writeString(OUT_FILE, prettyXML, Charset.defaultCharset());
System.out.println(Message.SUCCESS);
if (!failedStaticmaps.isEmpty()) {
StringBuilder fsb = new StringBuilder(Message.HAS_CID_ONLY());
for (Staticmap staticmap : failedStaticmaps) {
String ipAddress = staticmap.getIpAddress();
String hostname = staticmap.getHostname();
String description = staticmap.getDescription();
fsb.append(Message.EXCLUDED_STATIC_MAPPING(ipAddress, hostname, description));
}
Files.writeString(SKIPPED, fsb.toString(), Charset.defaultCharset());
fsb.append(NL).append("This information has also been saved to this text file for your convenience:");
fsb.append(NL).append(STR."\{NL}\t\{SKIPPED.toFile().getAbsolutePath()}");
fsb.append(NL);
System.out.println(fsb);
}
else {
System.out.println(Message.SUCCESS);
}
System.exit(0);
}
else {
Expand Down Expand Up @@ -274,50 +292,63 @@ private static List<Staticmap> getStaticMappings(NodeList nodeList) {
NodeList macNodeList = element.getElementsByTagName("mac");
Node macNode = macNodeList.item(0);

if (macNodeList == null || macNode == null) {
System.out.println(Message.GENERIC_NODE_NOT_FOUND("<mac>", "mac"));
System.exit(1);
}
NodeList cidNodeList = element.getElementsByTagName("cid");
Node cidNode = cidNodeList.item(0);

NodeList ipNodeList = element.getElementsByTagName("ipaddr");
Node ipNode = ipNodeList.item(0);

if (ipNodeList == null || ipNode == null) {
System.out.println(Message.GENERIC_NODE_NOT_FOUND("<ipaddr>", "ip"));
System.exit(1);
}

String macAddress = macNode.getTextContent();
String ipAddress = ipNode.getTextContent();
NodeList hostnameNodeList = element.getElementsByTagName("hostname");
Node hostnameNode = hostnameNodeList.item(0);

if (!validMac(macAddress)) {
System.out.println(Message.INVALID_MAC_ADDRESS(macAddress));
NodeList descriptionNodeList = element.getElementsByTagName("descr");
Node descriptionNode = descriptionNodeList.item(0);

boolean hasMac = macNode != null;
boolean hasCid = cidNode != null;
boolean hasIP = ipNode != null;
boolean hostnameNotNull = hostnameNode != null;
boolean descriptionNotNull = descriptionNode != null;

String macAddress = hasMac ? macNode.getTextContent() : "";
String cidString = hasCid ? cidNode.getTextContent() : "";
String ipAddress = hasIP ? ipNode.getTextContent() : "";
String hostname = hostnameNotNull ? hostnameNode.getTextContent() : "";
String description = descriptionNotNull ? descriptionNode.getTextContent() : "";

if (!hasIP) {
System.out.println(Message.STATIC_MAP_IP_NOT_FOUND(macAddress, cidString, hostname, description));
System.exit(1);
}

if (!validIPAddress(ipAddress)) {
System.out.println(Message.INVALID_IP_ADDRESS(ipAddress));
if (hasMac && !validMac(macAddress)) {
System.out.println(Message.INVALID_MAC_ADDRESS(macAddress, cidString, hostname, description));
System.exit(1);
}

Staticmap staticmap = new Staticmap(ipAddress, macAddress);

if (staticmap == null) {
System.out.println(Message.NULL_STATIC_MAP);
if (hasIP && !validIPAddress(ipAddress)) {
System.out.println(Message.INVALID_IP_ADDRESS(ipAddress));
System.exit(1);
}

NodeList hostnameNodeList = element.getElementsByTagName("hostname");
if (hostnameNodeList.getLength() > 0) {
staticmap.setHostname(hostnameNodeList.item(0).getTextContent());
if (hasIP && hasMac) {
Staticmap staticmap = new Staticmap(macAddress, ipAddress, hostname, description);
staticmaps.addLast(staticmap);
}

NodeList descriptionNodeList = element.getElementsByTagName("descr");
if (descriptionNodeList.getLength() > 0) {
staticmap.setDescription(descriptionNodeList.item(0).getTextContent());
if (!hasMac) {
if (hasCid) {
Staticmap staticmap = new Staticmap(cidString, ipAddress);
staticmap.setHostname(hostname);
staticmap.setDescription(description);
failedStaticmaps.addLast(staticmap);
}
else {
System.out.println(Message.MAC_CID_NODE_NOT_FOUND(ipAddress, hostname, description));
System.exit(1);
}
}

staticmaps.add(staticmap);
}
else {
System.out.println(Message.NO_STATIC_MAP);
Expand Down Expand Up @@ -378,7 +409,7 @@ private static void processArgs(String[] args) {
isCheck = true;
}
case "v", "version", "--version", "-v", "-version" -> {
System.out.println("2.1.3");
System.out.println("2.1.4");
System.exit(0);
}
case "?", "--help", "-help", "help" -> help();
Expand Down
Loading

0 comments on commit 7a22a73

Please sign in to comment.