diff options
author | Jonathan Bauer | 2016-03-05 11:59:12 +0100 |
---|---|---|
committer | Jonathan Bauer | 2016-03-05 11:59:12 +0100 |
commit | fb40fbbebbac732143ba346fb3dd6f33e62a35aa (patch) | |
tree | cabb543747614acac0aa53dc10124ac3820441be /dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/AdvancedConfigurator.java | |
parent | [client] fix bugs with line splitting per System.lineSeparator() (diff) | |
download | tutor-module-fb40fbbebbac732143ba346fb3dd6f33e62a35aa.tar.gz tutor-module-fb40fbbebbac732143ba346fb3dd6f33e62a35aa.tar.xz tutor-module-fb40fbbebbac732143ba346fb3dd6f33e62a35aa.zip |
[client] simple hostname check: now check for domain levels separately (fail if length of lvl is > 63)
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/AdvancedConfigurator.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/AdvancedConfigurator.java | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/AdvancedConfigurator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/AdvancedConfigurator.java index 47a2aa3f..306c5a40 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/AdvancedConfigurator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/AdvancedConfigurator.java @@ -47,7 +47,7 @@ public class AdvancedConfigurator extends AdvancedConfiguratorLayout { } /** - * + * */ public AdvancedConfiguration getState() { // cleanup the TextPane for network rules if needed @@ -127,7 +127,7 @@ public class AdvancedConfigurator extends AdvancedConfiguratorLayout { LOGGER.debug("Invalid number of fields! Expected 3, got: " + fields.length); Gui.showMessageBox( - "Nicht genug Felder! Nutzen Sie: <host> <port> [in|out]", + "Ungültige Syntax: Nutzen Sie: <host> <port> [in|out|in/out]", MessageType.ERROR, LOGGER, null); break; } @@ -135,15 +135,16 @@ public class AdvancedConfigurator extends AdvancedConfiguratorLayout { // start to check fields one by one from the last to the first .... // check net direction: accept either 'in' or 'out' (case // insensitive) - if (!fields[2].matches("(?i)^(IN|OUT)+$")) { + String ruleDirection = fields[2].toLowerCase(); + if (!ruleDirection.matches("^(\\bin\\b|\\bout\\b)$")) { markText(ruleLine, Color.RED); - LOGGER.debug("Invalid net direction! Expected (case insensitive) 'IN' or OUT'. Got: " - + fields[2]); + LOGGER.debug("Invalid net direction! Expected 'in' or out'. Got: " + ruleDirection); Gui.showMessageBox( - "Ungültige Richtung: nur 'IN' oder 'OUT' erlaubt!", + "Ungültige Richtung: nur 'in', 'out', 'in/out' und 'out/in' erlaubt!", MessageType.ERROR, LOGGER, null); break; } + // TODO match also when both are given. // check port: accept if > -2 and < 65535 int port = -2; @@ -202,8 +203,7 @@ public class AdvancedConfigurator extends AdvancedConfiguratorLayout { markText(ruleLine, Color.GREEN); } // valid, put it in the list - rulesList.add(new NetRule(rulesList.size(), NetDirection - .valueOf(fields[2].toUpperCase()), fields[0], port)); + rulesList.add(new NetRule(NetDirection.valueOf(fields[2].toUpperCase()), fields[0], port)); } if (netRules.length == rulesList.size()) { return rulesList; @@ -213,20 +213,31 @@ public class AdvancedConfigurator extends AdvancedConfiguratorLayout { private boolean checkHostnameSimple(final String hostname) { if (hostname.length() > 254) { - LOGGER.debug("Hostname is too long!"); Gui.showMessageBox("Hostname ist zu lang!", MessageType.ERROR, LOGGER, null); return false; } - for (int i = 0; i < hostname.length(); i++) { - Character c = Character.valueOf(hostname.charAt(i)); - if (!(Character.isDigit(c) || Character.isLetter(c) - || c.equals('-') || c.equals('.') || c.equals('/'))) { - LOGGER.debug("Invalid character in hostname: '" + c + "'"); - Gui.showMessageBox("Ungültiges Zeichen '" + c - + "' in hostname!", MessageType.ERROR, LOGGER, null); + // split by '.' to get domain levels + String[] domainLevels = hostname.split("\\."); + for (String lvl : domainLevels) { + if (lvl.length() > 63) { + // fail since domain level should be max 63 chars + Gui.showMessageBox("Domain-Ebene '" + lvl + "' länger als 63 Zeichen!", MessageType.ERROR, + LOGGER, null); return false; } + // length is ok, check for invalid characters + for (int i = 0; i < lvl.length(); i++) { + Character c = Character.valueOf(lvl.charAt(i)); + // only accepts numbers, letters, hyphen + // forward slash as a special case to accept subnets... + if (!(Character.isDigit(c) || Character.isLetter(c) + || c.equals('-') || c.equals('/'))) { + Gui.showMessageBox("Ungültiges Zeichen '" + c + + "' in hostname!", MessageType.ERROR, LOGGER, null); + return false; + } + } } return true; } @@ -240,7 +251,6 @@ public class AdvancedConfigurator extends AdvancedConfiguratorLayout { StyleConstants.setBold(set, color == Color.red); StyledDocument doc = taNetworkRules.getStyledDocument(); try { - boolean found = false; for (int pos = 0; pos < doc.getLength() - txt.length() + 1; ++pos) { String current = doc.getText(pos, txt.length()); if (current.endsWith(System.lineSeparator())) { @@ -252,8 +262,6 @@ public class AdvancedConfigurator extends AdvancedConfiguratorLayout { break; } } - if (found) { - } } catch (BadLocationException e) { LOGGER.error( "Failed to set '" + txt + "' to color " + color.toString(), |