summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2015-09-03 19:27:50 +0200
committerSimon Rettberg2015-09-03 19:27:50 +0200
commit2ba5d314618fb7668322fc6a543ad35f9f18fd75 (patch)
tree389d26a5b0913b23562ee2473b0b2115c4deb359
parent[client] Show usable images by default, show admin images when selecting "sho... (diff)
downloadtutor-module-2ba5d314618fb7668322fc6a543ad35f9f18fd75.tar.gz
tutor-module-2ba5d314618fb7668322fc6a543ad35f9f18fd75.tar.xz
tutor-module-2ba5d314618fb7668322fc6a543ad35f9f18fd75.zip
[server] Allow lecture with no image; start httprpc classes
-rw-r--r--dozentenmodulserver/setup/sat-01-schema.sql2
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java4
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java26
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/MailQueue.java2
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/SmtpMailer.java12
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java1
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebRpc.java67
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java32
8 files changed, 135 insertions, 11 deletions
diff --git a/dozentenmodulserver/setup/sat-01-schema.sql b/dozentenmodulserver/setup/sat-01-schema.sql
index d0585db2..b0966e73 100644
--- a/dozentenmodulserver/setup/sat-01-schema.sql
+++ b/dozentenmodulserver/setup/sat-01-schema.sql
@@ -99,7 +99,7 @@ CREATE TABLE IF NOT EXISTS `lecture` (
`lectureid` char(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
`displayname` varchar(100) NOT NULL,
`description` text NOT NULL,
- `imageversionid` char(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL COMMENT 'We reference a specific image version here, not the base image.\nOn update of an image, we update the lecture table for all matching lectures that used the current image version.\nThis way, a tutor can explicitly switch back to an older version of an image.',
+ `imageversionid` char(36) CHARACTER SET ascii COLLATE ascii_bin NULL COMMENT 'We reference a specific image version here, not the base image.\nOn update of an image, we update the lecture table for all matching lectures that used the current image version.\nThis way, a tutor can explicitly switch back to an older version of an image.',
`autoupdate` tinyint(1) UNSIGNED NOT NULL DEFAULT '1',
`isenabled` tinyint(1) UNSIGNED NOT NULL DEFAULT '1',
`isprivate` tinyint(1) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Only users from the lectureuser table can start this lecture',
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java
index 5f4bfaac..e5e7fe4f 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java
@@ -168,7 +168,7 @@ public class DbLecture {
+ " l.isexam, l.hasinternetaccess, l.caneditdefault, l.canadmindefault,"
+ " i.isvalid AS imgvalid, perm.canedit, perm.canadmin"
+ " FROM lecture l "
- + " INNER JOIN imageversion i USING (imageversionid)"
+ + " LEFT JOIN imageversion i USING (imageversionid)"
+ " LEFT JOIN lecturepermission perm ON (perm.lectureid = l.lectureid AND perm.userid = :userid)";
public static LectureSummary getLectureSummary(UserInfo user, String lectureId) throws SQLException,
@@ -242,7 +242,7 @@ public class DbLecture {
+ " l.updatetime, l.ownerid, l.updaterid, l.runscript, l.nics, l.netrules, l.isexam,"
+ " l.hasinternetaccess, l.caneditdefault, l.canadmindefault, p.canedit, p.canadmin"
+ " FROM lecture l "
- + " INNER JOIN imageversion i USING (imageversionid)"
+ + " LEFT JOIN imageversion i USING (imageversionid)"
+ " LEFT JOIN lecturepermission p ON (l.lectureid = p.lectureid AND p.userid = :userid)"
+ " WHERE l.lectureid = :lectureid LIMIT 1");
stmt.setString("userid", user.userId);
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 a08d4e15..e74852d0 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
@@ -222,4 +222,30 @@ public class FileServer implements IncomingEvent {
return transfer;
}
+ public Status getStatus() {
+ return new Status();
+ }
+
+ class Status {
+ public final int activeUploads;
+ public final int activeDownloads;
+
+ private Status() {
+ long now = System.currentTimeMillis();
+ int d = 0, u = 0;
+ for (OutgoingDataTransfer t : downloads.values()) {
+ if (!t.isComplete(now)) {
+ d += 1;
+ }
+ }
+ for (IncomingDataTransfer t : uploads.values()) {
+ if (!t.isComplete(now)) {
+ u += 1;
+ }
+ }
+ this.activeDownloads = d;
+ this.activeUploads = u;
+ }
+ }
+
}
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/MailQueue.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/MailQueue.java
index 6ed921ff..37871049 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/MailQueue.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/MailQueue.java
@@ -98,7 +98,7 @@ public class MailQueue {
SmtpMailer smtpc;
try {
smtpc = new SmtpMailer(conf.host, conf.port, conf.ssl, conf.senderAddress, conf.serverName,
- conf.replyTo, conf.username, conf.password);
+ conf.replyTo, conf.username, conf.password, null);
} catch (InvalidKeyException | LoginException | NoSuchAlgorithmException
| InvalidKeySpecException | IOException e) {
LOGGER.error("Could not initialize connection to SMTP server. Mails will not be sent", e);
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/SmtpMailer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/SmtpMailer.java
index 8d90f860..3166a5c6 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/SmtpMailer.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/SmtpMailer.java
@@ -1,6 +1,7 @@
package org.openslx.bwlp.sat.mail;
import java.io.IOException;
+import java.io.PrintStream;
import java.io.Writer;
import java.net.InetAddress;
import java.net.SocketException;
@@ -36,9 +37,9 @@ public class SmtpMailer {
private final AuthenticatingSMTPClient client;
public SmtpMailer(String host, int port, EncryptionMode ssl, String fromAddress, String fromName,
- String replyTo, String username, String password) throws UnknownHostException, SocketException,
- IOException, LoginException, InvalidKeyException, NoSuchAlgorithmException,
- InvalidKeySpecException {
+ String replyTo, String username, String password, PrintStream logStream)
+ throws UnknownHostException, SocketException, IOException, LoginException, InvalidKeyException,
+ NoSuchAlgorithmException, InvalidKeySpecException {
InetAddress[] ips = InetAddress.getAllByName(host);
if (ips == null || ips.length == 0)
throw new UnknownHostException(host);
@@ -50,8 +51,11 @@ public class SmtpMailer {
}
boolean cleanup = true;
try {
- client.addProtocolCommandListener(new PrintCommandListener(System.out));
+ if (logStream != null) {
+ client.addProtocolCommandListener(new PrintCommandListener(logStream));
+ }
client.setConnectTimeout(5000);
+ client.setSoTimeout(10000);
IOException conEx = null;
for (InetAddress ip : ips) {
try {
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java
index 94d95042..45334db3 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java
@@ -548,6 +548,7 @@ public class ServerHandler implements SatelliteServer.Iface {
@Override
public List<UserInfo> getUserList(String userToken, int page) throws TAuthorizationException,
TInvocationException {
+ UserInfo user = SessionManager.getOrFail(userToken);
try {
return DbUser.getAll(page);
} catch (SQLException e) {
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebRpc.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebRpc.java
new file mode 100644
index 00000000..6fdd57b6
--- /dev/null
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebRpc.java
@@ -0,0 +1,67 @@
+package org.openslx.bwlp.sat.web;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.spec.InvalidKeySpecException;
+import java.util.Map;
+
+import javax.security.auth.login.LoginException;
+
+import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.log4j.Logger;
+import org.openslx.bwlp.sat.mail.SmtpMailer;
+import org.openslx.bwlp.sat.mail.SmtpMailer.EncryptionMode;
+import org.openslx.util.Util;
+
+import fi.iki.elonen.NanoHTTPD.Response;
+
+public class WebRpc {
+
+ private static final Logger LOGGER = Logger.getLogger(WebRpc.class);
+
+ public static Response handle(String uri, Map<String, String> params) {
+ if (uri.equals("mailtest")) {
+ mailTest(params);
+ }
+ return WebServer.notFound();
+ }
+
+ private static Response mailTest(Map<String, String> params) {
+ SmtpMailer smtpc;
+ String recipient = params.get("recipient");
+ String host = params.get("host");
+ String senderAddress = params.get("senderAddress");
+ String serverName = params.get("serverName");
+ String replyTo = params.get("replyTo");
+ String username = params.get("username");
+ String password = params.get("password");
+ int port = Util.parseInt(params.get("port"), 0);
+ EncryptionMode ssl;
+ try {
+ ssl = EncryptionMode.valueOf(params.get("ssl"));
+ } catch (Exception e) {
+ return WebServer.badRequest("Invalid SSL mode");
+ }
+ // Validate
+ if (port < 1 || port > 65535)
+ return WebServer.badRequest("Invalid port");
+ if (recipient == null)
+ return WebServer.badRequest("Missing recipient");
+ if (host == null)
+ return WebServer.badRequest("Missing host");
+ if (senderAddress == null)
+ return WebServer.badRequest("Missing senderAddress");
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try {
+ smtpc = new SmtpMailer(host, port, ssl, senderAddress, serverName, replyTo, username, password,
+ new PrintStream(baos));
+ } catch (InvalidKeyException | LoginException | NoSuchAlgorithmException | InvalidKeySpecException
+ | IOException e) {
+ LOGGER.error("Could not initialize connection to SMTP server. Mails will not be sent", e);
+ }
+ return WebServer.internalServerError();
+ }
+
+}
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 be680799..99ecf4c4 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
@@ -5,6 +5,8 @@ import java.sql.SQLException;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.openslx.bwlp.sat.database.mappers.DbLecture;
+import org.openslx.bwlp.sat.fileserv.FileServer;
+import org.openslx.bwlp.sat.util.Json;
import org.openslx.bwlp.thrift.iface.TNotFoundException;
import org.openslx.util.GenericDataCache;
import org.openslx.util.vm.VmMetaData;
@@ -46,14 +48,27 @@ public class WebServer extends NanoHTTPD {
if (uri.startsWith("/vmchooser/lecture/")) {
return serveLectureStart(uri.substring(19));
}
+ if (uri.startsWith("/status/fileserver")) {
+ return serveStatus();
+ }
+ if (session.getMethod() == Method.POST && uri.startsWith("/do/")) {
+ return WebRpc.handle(uri.substring(4), session.getParms());
+ }
return notFound();
}
- private Response notFound() {
- return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, "text/plain", "Nicht gefunden!");
+ private Response serveStatus() {
+ return new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, "application/json; charset=utf-8",
+ Json.serialize(FileServer.instance().getStatus()));
}
+ /**
+ * Return meta data (eg. *.vmx) required to start the given lecture.
+ *
+ * @param lectureId
+ * @return
+ */
private Response serveLectureStart(String lectureId) {
VmMetaData meta;
try {
@@ -72,9 +87,20 @@ public class WebServer extends NanoHTTPD {
new ByteArrayInputStream(lectureListCache.get()));
}
- private Response internalServerError() {
+ public static Response internalServerError() {
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.INTERNAL_ERROR, "text/plain",
"Internal Server Error");
}
+ public static Response notFound() {
+ return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, "text/plain", "Nicht gefunden!");
+ }
+
+ public static Response badRequest(String message) {
+ if (message == null) {
+ message = "Schlechte Anfrage!";
+ }
+ return new NanoHTTPD.Response(NanoHTTPD.Response.Status.BAD_REQUEST, "text/plain", message);
+ }
+
}