diff options
| author | Jonathan Bauer | 2018-09-05 18:16:38 +0200 |
|---|---|---|
| committer | Jonathan Bauer | 2018-09-05 18:16:38 +0200 |
| commit | aabf1698fbbfa5f7e3c25336d11f2619939a34b0 (patch) | |
| tree | e2daf0d72e5ae59636587f56420b941fb026c6d8 | |
| parent | [client] fixes network shares visibility & perms (diff) | |
| parent | [client] Introduce visibility flag for runscript (diff) | |
| download | tutor-module-aabf1698fbbfa5f7e3c25336d11f2619939a34b0.tar.gz tutor-module-aabf1698fbbfa5f7e3c25336d11f2619939a34b0.tar.xz tutor-module-aabf1698fbbfa5f7e3c25336d11f2619939a34b0.zip | |
Merge branch 'master' of git.openslx.org:openslx-ng/tutor-module
7 files changed, 106 insertions, 53 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/RunscriptConfigurator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/RunscriptConfigurator.java index ead06c0c..5323a215 100644..100755 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/RunscriptConfigurator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/RunscriptConfigurator.java @@ -20,6 +20,7 @@ import javax.swing.JTextArea; import org.openslx.dozmod.gui.changemonitor.DialogChangeMonitor; import org.openslx.dozmod.gui.configurator.RunscriptConfigurator.RunscriptType; +import org.openslx.dozmod.gui.configurator.RunscriptConfigurator.RunscriptVisibility; import org.openslx.dozmod.gui.control.ComboBox; import org.openslx.dozmod.gui.control.ComboBox.ComboBoxRenderer; import org.openslx.dozmod.gui.control.QLabel; @@ -52,6 +53,23 @@ public class RunscriptConfigurator extends RunscriptConfiguratorLayout { } } + public static enum RunscriptVisibility { + NORMAL("Normal", 1), MINIMIZED("Minimiert", 2), HIDDEN("Versteckt", 0); + + private final String displayName; + private final int flag; + + private RunscriptVisibility(String name, int flag) { + this.displayName = name; + this.flag = flag; + } + + @Override + public String toString() { + return displayName; + } + } + public RunscriptConfigurator() { super(); @@ -83,8 +101,8 @@ public class RunscriptConfigurator extends RunscriptConfiguratorLayout { lblError.setText(msg); } /** - * Gets the runscript as String. The chosen interpreter will get encoded as - * the first line of the script. + * Gets the runscript as String. The chosen interpreter and visibility flag + * will get encoded in the first line of the script. * * @return runscript as String. If no text was entered, returns a empty * string. @@ -109,8 +127,16 @@ public class RunscriptConfigurator extends RunscriptConfiguratorLayout { setError("Fehlende Dateinamenerweiterung!"); return null; } + + RunscriptVisibility visibility = (RunscriptVisibility) cboRunscriptVisibility.getSelectedItem(); + if (visibility == null) { + // this should never happen, so return null to report this invalid state + setError("Fehlendes Sichtbarkeits-Flag!"); + return null; + } + setError(""); - return "ext=" + extension + "\n" + taInputText; + return "ext=" + extension + ";" + "visibility=" + visibility.flag + "\n" + taInputText; } /** @@ -127,34 +153,49 @@ public class RunscriptConfigurator extends RunscriptConfiguratorLayout { taRunScript.setText(""); return; } - String extensionHeader = null; + String header = null; try { BufferedReader reader = new BufferedReader(new StringReader(config)); - extensionHeader = reader.readLine(); + header = reader.readLine(); reader.close(); } catch (IOException e) { // swallow ... } - if (extensionHeader != null) { - // we should have following format: ext=<interpreter> - // e.g. ext=sh - extensionHeader = extensionHeader.replace("ext=", ""); - for (RunscriptType type : RunscriptType.values()) { - if (type.extension.equals(extensionHeader)) { - cboRunscriptType.setSelectedItem(type); - // mark that we found it by nulling the shebang... - extensionHeader = null; - continue; + if (header != null) { + // we should have following format: ext=<interpreter>;visibility=<flag> + // e.g. ext=sh;scriptVisibility=0 + String[] options = header.split(";"); + String extension = null; + for (String option : options) { + if(option.startsWith("ext=")) { + extension = option.replace("ext=", ""); + for (RunscriptType type : RunscriptType.values()) { + if (type.extension.equals(extension)) { + cboRunscriptType.setSelectedItem(type); + // mark that we found it by nulling the shebang... + extension = null; + break; + } + } + } else if (option.startsWith("visibility=")) { + option = option.replace("visibility=", ""); + for (RunscriptVisibility windowFlag : RunscriptVisibility.values()) { + if (windowFlag.flag == Integer.parseInt(option)) { + cboRunscriptVisibility.setSelectedItem(windowFlag); + break; + } + } } } - if (extensionHeader != null) { + + if (extension != null) { // user specific shebang, so just write the text to the cbo - cboRunscriptType.getEditor().setItem(extensionHeader); + cboRunscriptType.getEditor().setItem(extension); } } // finished with the interpreter, remove that line from the given config // before setting that text - taRunScript.setText(config.replaceFirst("^ext=.*\n", "")); + taRunScript.setText(config.replaceFirst(header + "\n", "")); } /** @@ -197,12 +238,13 @@ public class RunscriptConfigurator extends RunscriptConfiguratorLayout { } } } - + public void addToChangeMonitor(DialogChangeMonitor changeMonitor) { changeMonitor.add(taRunScript); changeMonitor.addEditableCombo(cboRunscriptType, null); + changeMonitor.addFixedCombo(cboRunscriptVisibility, null); } - + } /** @@ -217,6 +259,7 @@ class RunscriptConfiguratorLayout extends JPanel { protected final QLabel lblError; protected final JTextArea taRunScript; protected final ComboBox<RunscriptType> cboRunscriptType; + protected final ComboBox<RunscriptVisibility> cboRunscriptVisibility; public RunscriptConfiguratorLayout() { @@ -241,13 +284,26 @@ class RunscriptConfiguratorLayout extends JPanel { }); cboRunscriptType.setModel(new DefaultComboBoxModel<RunscriptType>( RunscriptType.values())); - ; cboRunscriptType.setEditable(true); grid.add(new QLabel("Dateinamenserweiterung: ")).fill(false, false) .expand(false, false); grid.add(cboRunscriptType).fill(true, false) .expand(true, false); grid.nextRow(); + cboRunscriptVisibility = new ComboBox<RunscriptVisibility>(new ComboBoxRenderer<RunscriptVisibility>() { + @Override + public String renderItem(RunscriptVisibility item) { + if (item == null) + return null; + return item.toString(); + } + }); + cboRunscriptVisibility.setModel(new DefaultComboBoxModel<RunscriptVisibility>(RunscriptVisibility.values())); + grid.add(new QLabel("Sichtbarkeit: ")).fill(false, false) + .expand(false, false); + grid.add(cboRunscriptVisibility).fill(true, false) + .expand(true, false); + grid.nextRow(); grid.add(scpRunScript, 2).fill(true, true).expand(true, true); grid.nextRow(); lblError = new QLabel(""); diff --git a/dozentenmodulserver/src/main/java/fi/iki/elonen/NanoHTTPD.java b/dozentenmodulserver/src/main/java/fi/iki/elonen/NanoHTTPD.java index ece1b4dd..5b865384 100644 --- a/dozentenmodulserver/src/main/java/fi/iki/elonen/NanoHTTPD.java +++ b/dozentenmodulserver/src/main/java/fi/iki/elonen/NanoHTTPD.java @@ -490,7 +490,7 @@ public abstract class NanoHTTPD implements Runnable { /** * Headers for the HTTP response. Use addHeader() to add lines. */ - private Map<String, String> header = new HashMap<String, String>(); + private final Map<String, String> header = new HashMap<String, String>(); /** * The request method that spawned this response. */ @@ -552,7 +552,7 @@ public abstract class NanoHTTPD implements Runnable { protected void send(OutputStream outputStream) throws IOException { String mime = mimeType; - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); if (status == null) { throw new Error("sendResponse(): Status can't be null."); } @@ -566,19 +566,17 @@ public abstract class NanoHTTPD implements Runnable { sb.append("\r\n"); } - if (header == null || header.get("Date") == null) { + if (header.get("Date") == null) { sb.append("Date: "); sb.append(headerDateFormatter.print(System.currentTimeMillis())); sb.append("\r\n"); } - if (header != null) { - for (Entry<String, String> item : header.entrySet()) { - sb.append(item.getKey()); - sb.append(": "); - sb.append(item.getValue()); - sb.append("\r\n"); - } + for (Entry<String, String> item : header.entrySet()) { + sb.append(item.getKey()); + sb.append(": "); + sb.append(item.getValue()); + sb.append("\r\n"); } sendConnectionHeaderIfNotAlreadyPresent(sb, header); diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java index e5a86d22..0a948249 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java @@ -342,7 +342,7 @@ public class DbImage { + (user == null || User.isSuperUser(user) ? " istemplate = :istemplate," : "") + " canlinkdefault = :canlink," + " candownloaddefault = :candownload, caneditdefault = :canedit," - + " updaterid = :updaterid, updatetime = UNIX_TIMESTAMP()," + + (user != null ? " updaterid = :updaterid, updatetime = UNIX_TIMESTAMP()," : "") + " canadmindefault = :canadmin" + " WHERE imagebaseid = :baseid"); stmt.setString("baseid", imageBaseId); stmt.setString("imagename", image.imageName); @@ -358,7 +358,9 @@ public class DbImage { stmt.setBoolean("candownload", image.defaultPermissions.download); stmt.setBoolean("canedit", image.defaultPermissions.edit); stmt.setBoolean("canadmin", image.defaultPermissions.admin); - stmt.setString("updaterid", user.userId); + if (user != null) { + stmt.setString("updaterid", user.userId); + } stmt.executeUpdate(); connection.commit(); } catch (SQLException e) { diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java index a12d149c..656a515b 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java @@ -213,16 +213,18 @@ public class FileServer implements IncomingEvent { LOGGER.warn("Rejecting download of VID " + localImageData.imageVersionId + ": Invalid local relative path"); errorMessage = "File has invalid path on server"; - } else if (!srcFile.canRead()) { - LOGGER.warn("Rejecting download of VID " + localImageData.imageVersionId + ": Missing " - + srcFile.getPath()); - errorMessage = "File missing on server"; - } - if (srcFile.length() != localImageData.fileSize) { - LOGGER.warn("Rejecting download of VID " + localImageData.imageVersionId + ": Size mismatch for " - + srcFile.getPath() + " (expected " + localImageData.fileSize + ", is " - + srcFile.length() + ")"); - errorMessage = "File corrupted on server"; + } else { + if (!srcFile.canRead()) { + LOGGER.warn("Rejecting download of VID " + localImageData.imageVersionId + ": Missing " + + srcFile.getPath()); + errorMessage = "File missing on server"; + } + if (srcFile.length() != localImageData.fileSize) { + LOGGER.warn("Rejecting download of VID " + localImageData.imageVersionId + + ": Size mismatch for " + srcFile.getPath() + " (expected " + + localImageData.fileSize + ", is " + srcFile.length() + ")"); + errorMessage = "File corrupted on server"; + } } if (errorMessage != null) { if (localImageData.isValid) { diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/IncomingDataTransfer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/IncomingDataTransfer.java index 15e9485b..d5dd5a14 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/IncomingDataTransfer.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/IncomingDataTransfer.java @@ -191,7 +191,7 @@ public class IncomingDataTransfer extends IncomingTransferBase { if (!user.userId.equals(owner.userId)) { return false; } - versionSettings = data; + versionSettings = new ImageVersionWrite(data); return true; } } diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/FileSystem.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/FileSystem.java index 95cbcfe5..dc0cec2d 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/FileSystem.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/FileSystem.java @@ -77,18 +77,13 @@ public class FileSystem { if (isStorageMounted()) return true; LOGGER.warn("VM storage gone, waiting for it to reappear..."); - int intrCount = 0; long lastComplain = System.currentTimeMillis(); do { try { Thread.sleep(10000); - intrCount = 0; } catch (InterruptedException e) { - intrCount++; - if (intrCount > 2) { - LOGGER.warn("Lost patience while waiting"); - return false; - } + LOGGER.warn("Interrupted while waiting", e); + return false; } if (System.currentTimeMillis() - lastComplain > 600000) { lastComplain = System.currentTimeMillis(); diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java index 2383158e..e87ffdc8 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java @@ -43,12 +43,12 @@ public class WebServer extends NanoHTTPD { * @return IP address, or empty string if unknown */ private String extractIp(Map<String, String> headers) { + if (headers == null || headers.isEmpty()) + return ""; String ip; ip = headers.get("remote-addr"); if (ip != null && !ip.equals("127.0.0.1")) return ip; - if (headers == null || headers.isEmpty()) - return ""; ip = headers.get("x-forwarded-for"); if (ip == null || ip.isEmpty()) return ""; |
