summaryrefslogtreecommitdiffstats
path: root/Dozentenmodulserver/src
diff options
context:
space:
mode:
authortspitzer2013-11-28 14:04:30 +0100
committertspitzer2013-11-28 14:04:30 +0100
commit2e0a5b912180b44338612969cca7cced89f8d637 (patch)
tree889369abe71ec129637e0688a677a71d0779967a /Dozentenmodulserver/src
parent-Anpassen der Texte (diff)
downloadtutor-module-2e0a5b912180b44338612969cca7cced89f8d637.tar.gz
tutor-module-2e0a5b912180b44338612969cca7cced89f8d637.tar.xz
tutor-module-2e0a5b912180b44338612969cca7cced89f8d637.zip
Dozentenmodulserver initales check-in
Diffstat (limited to 'Dozentenmodulserver/src')
-rw-r--r--Dozentenmodulserver/src/Models/User.java22
-rw-r--r--Dozentenmodulserver/src/server/ServerInterface.java11
-rw-r--r--Dozentenmodulserver/src/server/ServerMethod.java57
-rw-r--r--Dozentenmodulserver/src/sql/SQL.java49
4 files changed, 139 insertions, 0 deletions
diff --git a/Dozentenmodulserver/src/Models/User.java b/Dozentenmodulserver/src/Models/User.java
new file mode 100644
index 00000000..c946cd70
--- /dev/null
+++ b/Dozentenmodulserver/src/Models/User.java
@@ -0,0 +1,22 @@
+package Models;
+
+import java.io.Serializable;
+
+@SuppressWarnings("serial")
+public class User implements Serializable {
+
+ private String username;
+ private String pass;
+ public String getUsername() {
+ return username;
+ }
+ public void setUsername(String username) {
+ this.username = username;
+ }
+ public String getPass() {
+ return pass;
+ }
+ public void setPass(String pass) {
+ this.pass = pass;
+ }
+}
diff --git a/Dozentenmodulserver/src/server/ServerInterface.java b/Dozentenmodulserver/src/server/ServerInterface.java
new file mode 100644
index 00000000..783321be
--- /dev/null
+++ b/Dozentenmodulserver/src/server/ServerInterface.java
@@ -0,0 +1,11 @@
+package server;
+import java.rmi.*;
+
+import Models.User;
+
+public interface ServerInterface extends Remote
+{
+ public User getFtpUser() throws RemoteException;
+
+
+}
diff --git a/Dozentenmodulserver/src/server/ServerMethod.java b/Dozentenmodulserver/src/server/ServerMethod.java
new file mode 100644
index 00000000..73ce26b3
--- /dev/null
+++ b/Dozentenmodulserver/src/server/ServerMethod.java
@@ -0,0 +1,57 @@
+package server;
+import java.rmi.*;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.server.UnicastRemoteObject;
+import java.sql.Connection;
+import java.util.UUID;
+import Models.*;
+import sql.SQL;
+
+@SuppressWarnings("serial")
+public class ServerMethod extends UnicastRemoteObject implements ServerInterface
+{
+ protected static String m_strName;
+
+ public ServerMethod() throws RemoteException
+ {
+ super(); // call base class constructor
+ }
+
+
+
+ public static void main(String argv[])
+ {
+ try
+ {
+ LocateRegistry.createRegistry(9999);
+
+ m_strName = "TheRMIExample";
+ System.out.println("Server: Registering RMIExampleImpl as \"" + m_strName +"\"");
+ //System.setSecurityManager(new RMISecurityManager());
+ ServerMethod Example = new ServerMethod();
+ Naming.rebind("rmi://141.79.128.121:9999/"+m_strName, Example);
+ System.out.println("Server: Ready...");
+ }
+ catch (Exception e)
+ {
+ System.out.println("Server: Failed to register RMIExampleImpl: " + e);
+ }
+ }
+
+
+
+ @Override
+ public User getFtpUser() throws RemoteException {
+ User user=new User();
+ user.setUsername(UUID.randomUUID().toString().substring(0, 8));
+ user.setPass(UUID.randomUUID().toString().substring(0, 8));
+ SQL sql=new SQL();
+ Connection con=sql.getConnection();
+ sql.writeFTPUser(con, user.getUsername(), user.getPass());
+ return user;
+ }
+
+
+
+
+} \ No newline at end of file
diff --git a/Dozentenmodulserver/src/sql/SQL.java b/Dozentenmodulserver/src/sql/SQL.java
new file mode 100644
index 00000000..c3582527
--- /dev/null
+++ b/Dozentenmodulserver/src/sql/SQL.java
@@ -0,0 +1,49 @@
+package sql;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+
+public class SQL {
+
+ public Connection getConnection()
+ {
+ try {
+ Class.forName("com.mysql.jdbc.Driver").newInstance();
+ } catch (InstantiationException | IllegalAccessException
+ | ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ try {
+ Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1/bwLehrpool?user=root&password=slx-ng-open");
+ con.setAutoCommit(false);
+ return con;
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public int writeFTPUser(Connection con,String user, String pass)
+ {
+ Statement stm;
+ try {
+ stm=con.createStatement();
+
+ int ret=stm.executeUpdate("INSERT INTO `bwLehrpool`.`FtpUsers`(`User`,`Password`,`Dir`)VALUES('"+user+"','"+pass+"','/');");
+ con.commit();
+ return ret;
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return -1;
+ }
+
+
+
+}