From: www-data Date: Tue, 2 Dec 2014 10:41:03 +0000 (+0100) Subject: shuffling + libs imported X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=bd7a266f1a37cb373614b8fa3d0c1e832c4b82e3;p=logicplayer.git shuffling + libs imported --- diff --git a/server/com/company/DeleteFileExample.class b/server/com/company/DeleteFileExample.class new file mode 100644 index 0000000..25a7db8 Binary files /dev/null and b/server/com/company/DeleteFileExample.class differ diff --git a/server/com/company/DirectoryWatcher.class b/server/com/company/DirectoryWatcher.class new file mode 100644 index 0000000..fb7ef98 Binary files /dev/null and b/server/com/company/DirectoryWatcher.class differ diff --git a/server/com/company/DirectoryWhatcer.java b/server/com/company/DirectoryWhatcer.java new file mode 100644 index 0000000..8b376a1 --- /dev/null +++ b/server/com/company/DirectoryWhatcer.java @@ -0,0 +1,147 @@ +package com.company; + +import java.io.*; +import java.nio.file.Path; +import java.nio.file.StandardWatchEventKinds; +import java.nio.file.WatchEvent; +import java.nio.file.WatchEvent.Kind; +import java.nio.file.WatchKey; +import java.nio.file.WatchService; +import java.security.NoSuchAlgorithmException; +import java.sql.SQLException; +import java.util.ArrayList; + +// Simple class to watch directory events. +class DirectoryWatcher implements Runnable { + + private Path path; + + public DirectoryWatcher(Path path) { + this.path = path; + } + + //rimuove tutti gli elementi non validi + private void pulisciCartella() { + File dir = new File(global.locationEsercizi); + String[] lista=dir.list(); + for(String name : lista) + { + if (!EsNameParser.check(name)) + { + File file = new File(global.locationEsercizi+name); + if (file.delete()) + System.out.println("eliminato: "+name); + else + System.out.println("problema di eliminazione file"); + } + else + { + xmlOperation es=new xmlOperation(); + File car=new File(global.listaEsercizi); + if (car.exists()) { + dbConnect db=new dbConnect(); + try { + ArrayList esercizi=suString.stringToArrayList(db.dbQuery("4")); + boolean add=true; + for(String esercizio : esercizi) + { + if(esercizio.equals(name)) + add=false; + } + if(add) + es.add(name); + } catch (SQLException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + } + } + } + } + + // print the events and the affected file + private void printEvent(WatchEvent event) throws IOException { + Kind kind = event.kind(); + if (kind.equals(StandardWatchEventKinds.ENTRY_CREATE)) + { + Path pathCreated = (Path) event.context(); + System.out.println("Entry created:" + pathCreated); + boolean check = EsNameParser.check(pathCreated.getFileName().toString()); + if(!check) + { + File file = new File(global.locationEsercizi+pathCreated.getFileName().toString()); + if(file.delete()) + System.out.println("eliminato"); + else + System.out.println("problema di eliminazione file"); + } + else + { + xmlOperation es=new xmlOperation(); + File dir=new File(global.listaEsercizi); + if (dir.exists()) + es.add(pathCreated.getFileName().toString()); + } + } + else if (kind.equals(StandardWatchEventKinds.ENTRY_DELETE)) + { + Path pathDeleted = (Path) event.context(); + System.out.println("Entry deleted:" + pathDeleted); + xmlOperation es=new xmlOperation(); + File dir=new File(global.listaEsercizi); + if (dir.exists()) + es.remove(pathDeleted.getFileName().toString()); + } + else if (kind.equals(StandardWatchEventKinds.ENTRY_MODIFY)) + { + Path pathModified = (Path) event.context(); + System.out.println("Entry modified:" + pathModified); + } + } + + @Override + public void run() { + try { + pulisciCartella(); + WatchService watchService = path.getFileSystem().newWatchService(); + path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE, + StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE); + + // loop forever to watch directory + while (true) { + WatchKey watchKey; + watchKey = watchService.take(); // this call is blocking until events are present + + // poll for file system events on the WatchKey + for (final WatchEvent event : watchKey.pollEvents()) { + printEvent(event); + } + + // if the watched directed gets deleted, get out of run method + if (!watchKey.reset()) { + System.out.println("No longer valid"); + watchKey.cancel(); + watchService.close(); + break; + } + } + + } catch (InterruptedException ex) { + System.out.println("interrupted. Goodbye"); + return; + } catch (IOException ex) { + ex.printStackTrace(); // don't do this in production code. Use a loggin framework + return; + } + } + +} diff --git a/server/com/company/EmailSender.class b/server/com/company/EmailSender.class new file mode 100644 index 0000000..8c301a8 Binary files /dev/null and b/server/com/company/EmailSender.class differ diff --git a/server/com/company/EmailSender.java b/server/com/company/EmailSender.java new file mode 100644 index 0000000..1abf701 --- /dev/null +++ b/server/com/company/EmailSender.java @@ -0,0 +1,110 @@ +package com.company; + +import java.util.Date; +import java.util.Properties; +import javax.mail.Message; +import javax.mail.MessagingException; +import javax.mail.Multipart; +import javax.mail.NoSuchProviderException; +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.internet.AddressException; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeBodyPart; +import javax.mail.internet.MimeMessage; +import javax.mail.internet.MimeMultipart; + + + +public class EmailSender { + private String user; + private String password; + private String host; + private String mittente; + private String destinatario; + private String oggetto; + private String mess; + + + EmailSender(String user, String password, String host, + String mittente, String destinatario, + String oggetto, String mess){ + + this.user = user; + this.password = password; + this.host = host; + this.mittente = mittente; + this.destinatario = destinatario; + this.oggetto = oggetto; + this.mess=mess; + } + + + // Metodo che si occupa dell'invio effettivo della mail + public void inviaEmail() { + int port = 465; //porta 25 per non usare SSL + + Properties props = new Properties(); + props.put("mail.smtp.auth", "true"); + props.put("mail.smtp.user", mittente); + props.put("mail.smtp.host", host); + props.put("mail.smtp.port", port); + + // commentare la riga seguente per non usare SSL + props.put("mail.smtp.starttls.enable","true"); + props.put("mail.smtp.socketFactory.port", port); + + // commentare la riga seguente per non usare SSL + props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); + props.put("mail.smtp.socketFactory.fallback", "false"); + + Session session = Session.getInstance(props, null); + session.setDebug(true); + + // Creazione delle BodyParts del messaggio + MimeBodyPart messageBodyPart1 = new MimeBodyPart(); + + try{ + // COSTRUZIONE DEL MESSAGGIO + Multipart multipart = new MimeMultipart(); + MimeMessage msg = new MimeMessage(session); + + // header del messaggio + msg.setSubject(oggetto); + msg.setSentDate(new Date()); + msg.setFrom(new InternetAddress(mittente)); + + // destinatario + msg.addRecipient(Message.RecipientType.TO, + new InternetAddress(destinatario)); + + // corpo del messaggio + messageBodyPart1.setText(mess); + multipart.addBodyPart(messageBodyPart1); + + // allegato al messaggio + /*DataSource source = new FileDataSource(allegato); + messageBodyPart2.setDataHandler(new DataHandler(source)); + messageBodyPart2.setFileName(allegato); + multipart.addBodyPart(messageBodyPart2);*/ + + // inserimento delle parti nel messaggio + msg.setContent(multipart); + + Transport transport = session.getTransport("smtps"); //("smtp") per non usare SSL + transport.connect(host, user, password); + transport.sendMessage(msg, msg.getAllRecipients()); + transport.close(); + + System.out.println("Invio dell'email Terminato"); + + }catch(AddressException ae) { + ae.printStackTrace(); + }catch(NoSuchProviderException nspe){ + nspe.printStackTrace(); + }catch(MessagingException me){ + me.printStackTrace(); + } + + } +} diff --git a/server/com/company/EsNameParser.class b/server/com/company/EsNameParser.class new file mode 100644 index 0000000..d2cfbe3 Binary files /dev/null and b/server/com/company/EsNameParser.class differ diff --git a/server/com/company/EsNameParser.java b/server/com/company/EsNameParser.java new file mode 100644 index 0000000..f4f1105 --- /dev/null +++ b/server/com/company/EsNameParser.java @@ -0,0 +1,144 @@ +package com.company; + +import java.io.File; +import java.io.FileInputStream; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathFactory; + +import org.w3c.dom.Document; + +import java.lang.Integer; +import java.io.FileReader; +import java.io.BufferedReader; + +public class EsNameParser { + EsNameParser(){} + + static public String esName() + { + try { + FileInputStream file = new FileInputStream(new File(global.listaEsercizi)); + DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = builderFactory.newDocumentBuilder(); + Document xmlDocument = builder.parse(file); + XPath xPath = XPathFactory.newInstance().newXPath(); + int esNumber = Integer.parseInt(xPath.compile("count(/esercizi/esercizio)").evaluate(xmlDocument)); + String returnValue = null; + for (int i = 1; i <= esNumber; i++) { + String name = xPath.compile("/esercizi/esercizio[" + i + "]").evaluate(xmlDocument); + if (name == null || name.isEmpty()) + continue; + else { + if(returnValue==null) + returnValue=name; + else + returnValue = returnValue + "/" + name; + } + } + file.close(); + return returnValue; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public static boolean check(String esercizio) + { + boolean value=false; + try + { + String cartellaEs=global.locationEsercizi; + + BufferedReader br = new BufferedReader(new FileReader(cartellaEs+esercizio)); + if (br.readLine() == null) { + br.close(); + return false; + } + FileInputStream file = new FileInputStream(new File(cartellaEs+"/"+esercizio)); + DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = builderFactory.newDocumentBuilder(); + Document xmlDocument = builder.parse(file); + value=checkFormula(xmlDocument,"/esercizio/tesi/formula[1]"); + if(value) + value=checkIpotesi(xmlDocument); + file.close(); + } catch (Exception e) { + e.printStackTrace(); + } + return value; + } + + static public boolean checkFormula(Document xmlDocument, String position) { + try + { + XPath xPath = XPathFactory.newInstance().newXPath(); + if(Integer.parseInt(xPath.compile("count(" + position + ")").evaluate(xmlDocument))==1) { + String type = xPath.compile(position + "/@type").evaluate(xmlDocument); + int numbOfElements = 5; + if (type.contentEquals("and") || type.contentEquals("or") || type.contentEquals("impl")) + numbOfElements = 2; + else if (type.contentEquals("not")) + numbOfElements = 1; + else if (type.contentEquals("literal") || type.contentEquals("atomic")) + numbOfElements = 0; + int count = Integer.parseInt(xPath.compile("count(" + position + "/formula)").evaluate(xmlDocument)); + if (count == numbOfElements) { + if (numbOfElements == 2) { + boolean firstChild = checkFormula(xmlDocument, position + "/formula[1]"); + boolean secondChild = checkFormula(xmlDocument, position + "/formula[2]"); + if (!firstChild || !secondChild) + return false; + else + return true; + } + else if (numbOfElements == 1) + { + boolean child = checkFormula(xmlDocument, position + "/formula[1]"); + if (!child) + return false; + return true; + } + else if (numbOfElements == 0) + { + String child = xPath.compile(position).evaluate(xmlDocument); + if (child == null || child.isEmpty()) + return false; + else + return true; + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + static public boolean checkIpotesi(Document xmlDocument) + { + XPath xPath = XPathFactory.newInstance().newXPath(); + boolean returnValue=false; + try + { + int count = Integer.parseInt(xPath.compile("count(/esercizio/ipotesi)").evaluate(xmlDocument)); + int numberHp=Integer.parseInt(xPath.compile("count(/esercizio/ipotesi/formula)").evaluate(xmlDocument)); + if(count==1 && numberHp==0)//se non ci sono ipotesi + return true; + for(int i=1;i<=numberHp;i++) + { + boolean valore = checkFormula(xmlDocument, "/esercizio/ipotesi/formula["+i+"]"); + if(!valore) + return false; + else + returnValue=true; + } + }catch (Exception e) { + e.printStackTrace(); + } + return returnValue; + } +} diff --git a/server/com/company/MD5.class b/server/com/company/MD5.class new file mode 100644 index 0000000..79abbc1 Binary files /dev/null and b/server/com/company/MD5.class differ diff --git a/server/com/company/MD5.java b/server/com/company/MD5.java new file mode 100644 index 0000000..623f11f --- /dev/null +++ b/server/com/company/MD5.java @@ -0,0 +1,46 @@ +package com.company; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + + +public class MD5 { + + MD5(){} + public static String digest(String filePath) { + InputStream inputStream = null; + try { + inputStream = new FileInputStream(global.locationEsercizi+filePath); + byte[] buffer = new byte[1024]; + MessageDigest digest = MessageDigest.getInstance("MD5"); + int numRead = 0; + while (numRead != -1) { + numRead = inputStream.read(buffer); + if (numRead > 0) + digest.update(buffer, 0, numRead); + } + byte [] md5Bytes = digest.digest(); + System.out.println(convertHashToString(md5Bytes)); + return convertHashToString(md5Bytes); + } catch (Exception e) { + return null; + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (Exception e) { } + } + } + } + + private static String convertHashToString(byte[] md5Bytes) { + String returnVal = ""; + for (int i = 0; i < md5Bytes.length; i++) { + returnVal += Integer.toString(( md5Bytes[i] & 0xff ) + 0x100, 16).substring(1); + } + return returnVal; + } +} diff --git a/server/com/company/Makefile b/server/com/company/Makefile new file mode 100644 index 0000000..2cc75ec --- /dev/null +++ b/server/com/company/Makefile @@ -0,0 +1,2 @@ +all: + javac -cp "/tmp/ext/mysql-connector-java.jar:/tmp/ext/jdom-2.0.5.jar:/tmp/ext/mail-1.4.1.jar:." *.java diff --git a/server/com/company/dbConnect.class b/server/com/company/dbConnect.class new file mode 100644 index 0000000..03ff58b Binary files /dev/null and b/server/com/company/dbConnect.class differ diff --git a/server/com/company/dbConnect.java b/server/com/company/dbConnect.java new file mode 100644 index 0000000..28d851c --- /dev/null +++ b/server/com/company/dbConnect.java @@ -0,0 +1,355 @@ +package com.company; + +import java.sql.*; +import java.io.IOException; + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import java.util.Random; + +import java.sql.Timestamp; + +import java.util.ArrayList; + +import java.lang.Double; + +public class dbConnect +{ + private static Connection db; + private static Statement stmt; + dbConnect() + {} + + + public static Long time() + { + java.util.Date date= new java.util.Date(); + Timestamp now=new Timestamp(date.getTime()); + return now.getTime(); + } + + //pulisce confmail e connessi da tutte le richieste maggiori di 10 minuti + private static void deletetmp() throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException + { + PreparedStatement preparedStmt = db.prepareStatement("DELETE FROM confmail WHERE time<=?"); + preparedStmt.setLong (1,(time()-600000)); + preparedStmt.execute(); + preparedStmt = db.prepareStatement("DELETE FROM connessi WHERE time<=?"); + preparedStmt.setLong (1,(time()-600000)); + preparedStmt.execute(); + } + + //divide la stringa in user e password + private static String splitUsrPass(String userAndPass, int code) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException + { + String user=null; + String pass=null; + ArrayList userPass= suString.stringToArrayList(userAndPass); + if(userPass.size()>=1) + user=userPass.get(0); + if(userPass.size()>=2) + pass=userPass.get(1); + + assert user != null; + if(!user.contains("@studio.unibo.it") && user.length()<16) + return "mail-error"; + else { + assert pass != null; + if(code==0) + return registration(user, pass); + else if(code==1) + return login(user, pass); + else if(code==2) + return recupero(user); + else + return "error"; + } + } + + //routin di gestione recupero pass + private static String recupero(String user) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException + { + ResultSet returnQuery=stmt.executeQuery("SELECT * FROM utenti where user='"+user+"'"); + if(returnQuery!=null) + { + if(returnQuery.next()) + { + EmailSender email = new EmailSender(global.email, + global.emailPass, + "smtp.gmail.com", + global.email, + user, + "OGGETTO: recupero password", + "la tua password è "+returnQuery.getString("pass")); + email.inviaEmail(); + return "mail-pass-ok"; + } + else + return "user-error"; + } + else + return "user-error"; + } + + + //routin di gestione della registrazione + private static String registration(String user, String pass) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException + { + String ran; + ResultSet returnQuery=stmt.executeQuery("SELECT * FROM utenti where user='"+user+"'"); + if(returnQuery!=null) + { + if(returnQuery.next()) + { + if(returnQuery.getString("user").compareTo(user)==0 && returnQuery.getString("pass").compareTo(pass)==0) + return "già-registrato"; + } + } + returnQuery=stmt.executeQuery("SELECT * FROM confmail where user='"+user+"'"); + if(returnQuery!=null) + { + if(returnQuery.next()) + { + ran=returnQuery.getString("hash"); + if(returnQuery.getString("pass").compareTo(pass)!=0) + { + PreparedStatement preparedStmt = db.prepareStatement("UPDATE confmail SET pass =? where user=?"); + preparedStmt.setString (1,pass); + preparedStmt.setString (2,user); + preparedStmt.execute(); + } + } + else + { + Random random = new Random(); + ran=String.valueOf(random.nextInt(100000000)+10000000)+String.valueOf(random.nextInt(100000000)+10000000)+String.valueOf(random.nextInt(100000000)+10000000); + //returnQuery=stmt.executeQuery("INSERT INTO confmail VALUES('"+user+"','"+pass+"',"+hash+"')"); + PreparedStatement preparedStmt = db.prepareStatement("INSERT INTO confmail (user,pass,hash,time) VALUES(?,?,?,?)"); + preparedStmt.setString (1,user); + preparedStmt.setString (2,pass); + preparedStmt.setString (3,ran); + preparedStmt.setDouble (4,(double)time()); + preparedStmt.execute(); + } + } + else + { + Random random = new Random(); + ran=String.valueOf(random.nextInt(100000000)+10000000)+String.valueOf(random.nextInt(100000000)+10000000)+String.valueOf(random.nextInt(100000000)+10000000); + //returnQuery=stmt.executeQuery("INSERT INTO confmail VALUES('"+user+"','"+pass+"',"+hash+"')"); + PreparedStatement preparedStmt = db.prepareStatement("INSERT INTO confmail (user,pass,hash,time) VALUES(?,?,?,?)"); + preparedStmt.setString (1,user); + preparedStmt.setString (2,pass); + preparedStmt.setString (3,ran); + preparedStmt.setDouble (4,(double)time()); + preparedStmt.execute(); + } + EmailSender email = new EmailSender(global.email, + global.emailPass, + "smtp.gmail.com", + global.email, + user, + "OGGETTO: Registrazione App", + "per confermare la tua email clicka sul link: http://"+global.serverName+"/test?id="+ran); + email.inviaEmail(); + return "mail-reg-ok"; + } + + //routin conferma registrazione + private static String confirmRegistration(String hash) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException + { + ResultSet returnQuery=stmt.executeQuery("SELECT * FROM confmail where hash='"+hash+"'"); + if(returnQuery!=null) + { + if(returnQuery.next()) + { + PreparedStatement preparedStmt = db.prepareStatement("INSERT INTO utenti (user,pass) VALUES(?,?)"); + preparedStmt.setString (1,returnQuery.getString("user")); + preparedStmt.setString (2,returnQuery.getString("pass")); + preparedStmt.execute(); + preparedStmt = db.prepareStatement("DELETE FROM confmail WHERE hash=?"); + preparedStmt.setString (1,hash); + preparedStmt.execute(); + return "registrazione-ok"; + } + } + return "registrazione-error"; + } + + //routin di gestione login + private static String login(String user, String pass) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException + { + + ResultSet returnQuery=stmt.executeQuery("SELECT * FROM utenti where user='"+user+"' and pass='"+pass+"'"); + if(returnQuery!=null) + { + if(returnQuery.next()) + { + if(returnQuery.getString("user").compareTo(user)==0 && returnQuery.getString("pass").compareTo(pass)==0) + return putConnessi(user); + } + } + return "login-error"; + } + + + //informazioni sulla connessione dell'utente + private String infoConnessi(String message) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException + { + ArrayList split= suString.stringToArrayList(message); + if(split.size()>=1) + { + ResultSet returnQuery=stmt.executeQuery("SELECT * FROM connessi WHERE tempkey='"+split.get(1)+"'"); + if(returnQuery!=null) + { + if(returnQuery.next()) + { + return "loggato"; + } + } + } + return "request-login"; + } + + //inserisce l'utente in connessi + private static String putConnessi(String user) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException + { + Random random = new Random(); + String ran=String.valueOf(random.nextInt(100000000)+10000000)+String.valueOf(random.nextInt(100000000)+10000000); + PreparedStatement preparedStmt = db.prepareStatement("INSERT INTO connessi (user,tempkey,thread,time) VALUES(?,?,?,?)"); + preparedStmt.setString (1,user); + preparedStmt.setString (2,ran); + preparedStmt.setBoolean (3,false); + preparedStmt.setDouble (4,(double)time()); + preparedStmt.execute(); + return ran; + } + + //segnalare morte di un thread + private String threadDead(String key) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException + { + PreparedStatement preparedStmt = db.prepareStatement("DELETE FROM confmail WHERE tempkey=?"); + preparedStmt.setString (1,key); + preparedStmt.execute(); + return "kill-ok"; + } + + //remposta il rimer dell'utente nella tabella connessi + private String connessiTimer(String key) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException + { + PreparedStatement preparedStmt = db.prepareStatement("UPDATE connessi SET time =? where tempkey=?"); + preparedStmt.setDouble (1,(double)time()); + preparedStmt.setString (2,key); + preparedStmt.execute(); + return "timer-settato"; + } + + private String exerciseAccept(String request) throws SQLException, IOException, NoSuchAlgorithmException { + ArrayList input=suString.stringToArrayList(request); + ResultSet returnQuery=stmt.executeQuery("SELECT * FROM connessi where tempkey='"+input.get(0)+"'"); + String utente=null; + if(returnQuery!=null) + { + if(returnQuery.next()) + utente=returnQuery.getString("user"); + } + if(utente!=null) + { + String[] esercizi=suString.stringToVectorString(EsNameParser.esName()); + for(String esercizio : esercizi) + { + if(esercizio.contentEquals(input.get(1)))//se l'esercizio esiste + { + if(MD5.digest(esercizio).contentEquals(input.get(2)))//se il digest è uguale + { + PreparedStatement preparedStmt = db.prepareStatement("INSERT INTO esercizi (esercizio,utente,click,time) VALUES(?,?,?,?)"); + preparedStmt.setDouble(4, Double.parseDouble(input.get(3))); + preparedStmt.setInt (3,Integer.valueOf(input.get(4))); + preparedStmt.setString (2,utente); + preparedStmt.setString (1,input.get(1)); + preparedStmt.execute(); + return "es-ok"; + } + } + } + } + return "es-err"; + } + + private String userExercise(String request) throws SQLException { + ArrayList arrayResult=new ArrayList(); + ArrayList input=suString.stringToArrayList(request); + String result=null; + ResultSet returnQuery=stmt.executeQuery("SELECT * FROM connessi where tempkey='"+input.get(0)+"'"); + String utente=null; + if(returnQuery!=null) + { + if(returnQuery.next()) + utente=returnQuery.getString("user"); + } + if(utente!=null) + { + returnQuery=stmt.executeQuery("SELECT * FROM esercizi where utente='"+utente+"'"); + while(returnQuery.next()) + { + arrayResult.add(returnQuery.getString("esercizio")+"/"+MD5.digest(returnQuery.getString("esercizio"))+"/"+returnQuery.getDouble("time")+"/"+returnQuery.getInt("click")); + } + result=suString.multiToString(arrayResult); + } + return result; + } + + private String cambiaPass(String request) throws ClassNotFoundException, SQLException, InstantiationException, IOException, IllegalAccessException { + ArrayList input=suString.stringToArrayList(request); + if(input.size()>=3) { + String result = login(input.get(0), input.get(1)); + if(!result.contains("err")) + { + PreparedStatement preparedStmt = db.prepareStatement("UPDATE utenti SET pass =? where user=?"); + preparedStmt.setString (1,input.get(2)); + preparedStmt.setString (2,input.get(0)); + preparedStmt.execute(); + return "cambiata"; + } + } + return "error"; + } + + public String dbQuery(String input) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException, NoSuchAlgorithmException { + Class.forName("com.mysql.jdbc.Driver").newInstance(); + db = DriverManager.getConnection("jdbc:mysql://localhost/logintesi", "root", "csc@CerCo!"); + stmt = db.createStatement(); + deletetmp(); + if (input.charAt(0) == '0') + return splitUsrPass(input.substring(2), 0); + else if (input.charAt(0) == '1') + return splitUsrPass(input.substring(2), 1); + else if (input.charAt(0) == '2') + return recupero(input.substring(2)); + else if (input.charAt(0) == '3') + return confirmRegistration(input.substring(1)); + else if (input.charAt(0) == '4') + return EsNameParser.esName(); + else if (input.charAt(0) == '5') + return infoConnessi(input.substring(2)); + else if (input.charAt(0) == '6') + return connessiTimer(input.substring(2)); + /*else if (input.charAt(0) == '7') + return threadDead(input.substring(2));*/ + /*else if(input.charAt(0)=='8') + return aggToClient(input.substring(2)); + else if(input.charAt(0)=='9') + return aggForClient(input.substring(2)); + else if(input.charAt(0)=='a' && input.charAt(1)=='0') + return check(input.substring(3));*/ + else if (input.charAt(0) == '8') + return exerciseAccept(input.substring(2)); + else if (input.charAt(0) == '9') + return userExercise(input.substring(2)); + else if(input.charAt(0)=='a' && input.charAt(1)=='0') + return cambiaPass(input.substring(3)); + return "error"; + } +} diff --git a/server/com/company/esercizi.xml b/server/com/company/esercizi.xml new file mode 100644 index 0000000..c28cd97 --- /dev/null +++ b/server/com/company/esercizi.xml @@ -0,0 +1,10 @@ + + + aalbero.xml + tautologia.xml + demorgan.xml + triviale.xml + test.xml + risolvibile.xml + demorgan2.xml + diff --git a/server/com/company/esercizi.xml~ b/server/com/company/esercizi.xml~ new file mode 100644 index 0000000..47eb032 --- /dev/null +++ b/server/com/company/esercizi.xml~ @@ -0,0 +1,4 @@ + + + aalbero.xml + diff --git a/server/com/company/global.class b/server/com/company/global.class new file mode 100644 index 0000000..00f0bd3 Binary files /dev/null and b/server/com/company/global.class differ diff --git a/server/com/company/global.java b/server/com/company/global.java new file mode 100644 index 0000000..2bf06c4 --- /dev/null +++ b/server/com/company/global.java @@ -0,0 +1,16 @@ +package com.company; + + +public class global { + public static final String listaEsercizi="/projects/logicplayer/Server/server/tesi/src/com/company/esercizi.xml"; + public static final String locationEsercizi="/projects/logicplayer/public_html/esercizi/"; + public static String home="/projects/logicplayer/Server/server/tesi/src/com/company/"; + public static String keyStorePass="123456"; + public static String keyStoreName="keystore.jks"; + public static String serverName="130.136.129.1"; + public static String email="confermaiscrizioneserver@gmail.com"; + public static String emailPass="tes6phev8n"; + public static int portaServer=25000; + public static int portaHttpServer=8000; + +} diff --git a/server/com/company/guestServer.class b/server/com/company/guestServer.class new file mode 100644 index 0000000..59b4c18 Binary files /dev/null and b/server/com/company/guestServer.class differ diff --git a/server/com/company/guestServer.java b/server/com/company/guestServer.java new file mode 100644 index 0000000..1fb6ce9 --- /dev/null +++ b/server/com/company/guestServer.java @@ -0,0 +1,80 @@ +package com.company; + +import java.io.*; + +import javax.net.ssl.*; + +class guestServer implements Runnable +{ + private SSLSocket socket; + + guestServer(SSLSocket client) + { + socket=client; + } + + public void run() + { + try + { + + //Reading the message from the client + InputStream is = socket.getInputStream(); + InputStreamReader isr = new InputStreamReader(is); + BufferedReader br = new BufferedReader(isr); + String requestMessage = br.readLine(); + System.out.println("ho ricevuto: "+requestMessage); + /*System.out.println("Message received from client is "+returnMessage); + dbConnect request=new dbConnect(); + String returnQuery=request.dbQuery(returnMessage); + OutputStream os = socket.getOutputStream(); + OutputStreamWriter osw = new OutputStreamWriter(os); + BufferedWriter bw = new BufferedWriter(osw); + System.out.println(returnQuery); + bw.write(returnQuery+"\n"); + bw.flush();*/ + if(requestMessage!=null) + { + dbConnect request = new dbConnect(); + String returnQuery; + if ( requestMessage.charAt(0) == '0' || + requestMessage.charAt(0) == '1' || + requestMessage.charAt(0) == '2' || + (requestMessage.charAt(0) == 'a' && requestMessage.charAt(1) == '0')) { + returnQuery = request.dbQuery(requestMessage); + OutputStream os = socket.getOutputStream(); + OutputStreamWriter osw = new OutputStreamWriter(os); + BufferedWriter bw = new BufferedWriter(osw); + bw.write(returnQuery + "\n"); + bw.flush(); + System.out.println("ho inviato: " + returnQuery); + } + else + { + returnQuery = request.dbQuery("5/" + requestMessage); + if (returnQuery.contains("request-login") || returnQuery.contains("request-error")) + { + OutputStream os = socket.getOutputStream(); + OutputStreamWriter osw = new OutputStreamWriter(os); + BufferedWriter bw = new BufferedWriter(osw); + bw.write(returnQuery + "\n"); + bw.flush(); + System.out.println("ho inviato: " + returnQuery); + } + else if (returnQuery.contains("loggato")) + { + personalServer nuovaConnessione = new personalServer(socket, requestMessage); + Thread t = new Thread(nuovaConnessione); + t.start(); + } + } + } + + } + catch (Exception e) + { + e.printStackTrace(); + } + + } +} diff --git a/server/com/company/httpget$MyHandler.class b/server/com/company/httpget$MyHandler.class new file mode 100644 index 0000000..7862be8 Binary files /dev/null and b/server/com/company/httpget$MyHandler.class differ diff --git a/server/com/company/httpget.class b/server/com/company/httpget.class new file mode 100644 index 0000000..b710c11 Binary files /dev/null and b/server/com/company/httpget.class differ diff --git a/server/com/company/httpget.java b/server/com/company/httpget.java new file mode 100644 index 0000000..079cc01 --- /dev/null +++ b/server/com/company/httpget.java @@ -0,0 +1,79 @@ +package com.company; + +import java.io.*; +import java.net.*; +import java.security.NoSuchAlgorithmException; +import java.util.*; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpServer; +import java.sql.*; + +public class httpget implements Runnable { + + httpget(){} + + public static Map splitQuery(String query) throws UnsupportedEncodingException + { + Map query_pairs = new LinkedHashMap(); + String[] pairs = query.split("&"); + for (String pair : pairs) + { + int idx = pair.indexOf("="); + query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), URLDecoder.decode(pair.substring(idx + 1), "UTF-8")); + } + return query_pairs; + } + + @Override + public void run() { + try { + HttpServer server = HttpServer.create(new InetSocketAddress(global.portaHttpServer), 0); + server.createContext("/test", new MyHandler()); + server.setExecutor(null); // creates a default executor + server.start(); + }catch (Exception e) + { + e.printStackTrace(); + } + } + + static class MyHandler implements HttpHandler + { + public void handle(HttpExchange t) throws IOException + { + + /*String response = "This is the response"; + System.out.println("mannaggia santa"); + t.sendResponseHeaders(200, response.length()); + OutputStream os = t.getResponseBody(); + os.write(response.getBytes());*/ + URI req=t.getRequestURI(); + String query=req.getQuery(); + Map result=splitQuery(query); + String id=result.get("id"); + //System.out.println(id); + try + { + dbConnect request=new dbConnect(); + String returnQuery=request.dbQuery("3"+id); + t.sendResponseHeaders(200, returnQuery.length()); + OutputStream os = t.getResponseBody(); + os.write(returnQuery.getBytes()); + os.close(); + } + catch(SQLException e) + {} + catch(ClassNotFoundException c) + {} + catch(IllegalAccessException a) + {} + catch(InstantiationException i) + {} catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + } + } + +} diff --git a/server/com/company/keystore.bks b/server/com/company/keystore.bks new file mode 100644 index 0000000..ecec326 Binary files /dev/null and b/server/com/company/keystore.bks differ diff --git a/server/com/company/keystore.crt b/server/com/company/keystore.crt new file mode 100644 index 0000000..e60e9db Binary files /dev/null and b/server/com/company/keystore.crt differ diff --git a/server/com/company/keystore.jks b/server/com/company/keystore.jks new file mode 100644 index 0000000..4edd598 Binary files /dev/null and b/server/com/company/keystore.jks differ diff --git a/server/com/company/personalServer.class b/server/com/company/personalServer.class new file mode 100644 index 0000000..1d5b025 Binary files /dev/null and b/server/com/company/personalServer.class differ diff --git a/server/com/company/personalServer.java b/server/com/company/personalServer.java new file mode 100644 index 0000000..1d338eb --- /dev/null +++ b/server/com/company/personalServer.java @@ -0,0 +1,56 @@ +package com.company; + +import java.io.BufferedWriter; +import java.io.OutputStream; +import java.io.OutputStreamWriter; + +import javax.net.ssl.*; + + +import java.util.ArrayList; + +class personalServer implements Runnable +{ + private SSLSocket socket; + private String key; + private String requestMessage; + + personalServer(SSLSocket client, String message) + { + socket=client; + ArrayList split= suString.stringToArrayList(message); + key=split.get(1); + requestMessage=message; + } + + public void run() + { + try + { + dbConnect request=new dbConnect(); + String returnQuery=request.dbQuery(requestMessage); + OutputStream os = socket.getOutputStream(); + OutputStreamWriter osw = new OutputStreamWriter(os); + BufferedWriter bw = new BufferedWriter(osw); + bw.write(returnQuery+"\n"); + bw.flush(); + System.out.println("ho inviato: "+returnQuery); + request.dbQuery("6/"+key); + socket.close(); + } + catch (Exception e) + { + try + { + e.printStackTrace(); + dbConnect request=new dbConnect(); + request.dbQuery("7/"+key); + } + catch (Exception k) + { + //k.printStackTrace(); + System.out.println("PANIC!"); + } + } + } +} diff --git a/server/com/company/suString.class b/server/com/company/suString.class new file mode 100644 index 0000000..6d094cb Binary files /dev/null and b/server/com/company/suString.class differ diff --git a/server/com/company/suString.java b/server/com/company/suString.java new file mode 100644 index 0000000..666febe --- /dev/null +++ b/server/com/company/suString.java @@ -0,0 +1,96 @@ +package com.company; + +import java.util.ArrayList; +import java.util.Collections; + +public class suString +{ + suString() + {} + + + public static ArrayList stringToArrayList(String string) + { + ArrayList returnValue=new ArrayList(); + int j=0; + for(int i=0;i vectorStringToArrayList(String[] vectorString) + { + ArrayList returnValue=new ArrayList(); + Collections.addAll(returnValue, vectorString); + return returnValue; + } + + public static String arrayListToString (ArrayList arraylist) + { + String returnValue= ""; + for(int i=0;i arraylist) + { + String[] returnValue=new String[arraylist.size()]; + for(int i=0;i input) + { + String returnValue=null; + int size=input.size(); + for(int i=0;i stringToMultiArray(String input) + { + ArrayList result=new ArrayList(); + int j=0; + for(int i=0;i - - - - \ No newline at end of file diff --git a/server/tesi/.idea/copyright/profiles_settings.xml b/server/tesi/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/server/tesi/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/server/tesi/.idea/description.html b/server/tesi/.idea/description.html deleted file mode 100644 index db5f129..0000000 --- a/server/tesi/.idea/description.html +++ /dev/null @@ -1 +0,0 @@ -Simple Java application that includes a class with main() method \ No newline at end of file diff --git a/server/tesi/.idea/encodings.xml b/server/tesi/.idea/encodings.xml deleted file mode 100644 index d821048..0000000 --- a/server/tesi/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/server/tesi/.idea/misc.xml b/server/tesi/.idea/misc.xml deleted file mode 100644 index 728f444..0000000 --- a/server/tesi/.idea/misc.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/server/tesi/.idea/modules.xml b/server/tesi/.idea/modules.xml deleted file mode 100644 index d9c1a63..0000000 --- a/server/tesi/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/server/tesi/.idea/project-template.xml b/server/tesi/.idea/project-template.xml deleted file mode 100644 index 1f08b88..0000000 --- a/server/tesi/.idea/project-template.xml +++ /dev/null @@ -1,3 +0,0 @@ - \ No newline at end of file diff --git a/server/tesi/.idea/scopes/scope_settings.xml b/server/tesi/.idea/scopes/scope_settings.xml deleted file mode 100644 index 922003b..0000000 --- a/server/tesi/.idea/scopes/scope_settings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/server/tesi/.idea/uiDesigner.xml b/server/tesi/.idea/uiDesigner.xml deleted file mode 100644 index e96534f..0000000 --- a/server/tesi/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/server/tesi/.idea/vcs.xml b/server/tesi/.idea/vcs.xml deleted file mode 100644 index 6564d52..0000000 --- a/server/tesi/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/server/tesi/.idea/workspace.xml b/server/tesi/.idea/workspace.xml deleted file mode 100644 index 7ff99c0..0000000 --- a/server/tesi/.idea/workspace.xml +++ /dev/null @@ -1,1003 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Control flow issues - - - - - InfiniteLoopStatement - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1415700559063 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - No facets are configured - - - - - - - - - - - - - - - 1.8 - - - - - - - - tesi - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/server/tesi/out/production/tesi/com/company/DirectoryWatcher.class b/server/tesi/out/production/tesi/com/company/DirectoryWatcher.class deleted file mode 100644 index cfca534..0000000 Binary files a/server/tesi/out/production/tesi/com/company/DirectoryWatcher.class and /dev/null differ diff --git a/server/tesi/out/production/tesi/com/company/EmailSender.class b/server/tesi/out/production/tesi/com/company/EmailSender.class deleted file mode 100644 index f7d68c0..0000000 Binary files a/server/tesi/out/production/tesi/com/company/EmailSender.class and /dev/null differ diff --git a/server/tesi/out/production/tesi/com/company/EsNameParser.class b/server/tesi/out/production/tesi/com/company/EsNameParser.class deleted file mode 100644 index 6b5cef6..0000000 Binary files a/server/tesi/out/production/tesi/com/company/EsNameParser.class and /dev/null differ diff --git a/server/tesi/out/production/tesi/com/company/MD5.class b/server/tesi/out/production/tesi/com/company/MD5.class deleted file mode 100644 index e5246c0..0000000 Binary files a/server/tesi/out/production/tesi/com/company/MD5.class and /dev/null differ diff --git a/server/tesi/out/production/tesi/com/company/dbConnect.class b/server/tesi/out/production/tesi/com/company/dbConnect.class deleted file mode 100644 index 982753e..0000000 Binary files a/server/tesi/out/production/tesi/com/company/dbConnect.class and /dev/null differ diff --git a/server/tesi/out/production/tesi/com/company/esercizi.xml b/server/tesi/out/production/tesi/com/company/esercizi.xml deleted file mode 100644 index 50ba729..0000000 --- a/server/tesi/out/production/tesi/com/company/esercizi.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - aalbero.xml - tautologia.xml - diff --git a/server/tesi/out/production/tesi/com/company/global.class b/server/tesi/out/production/tesi/com/company/global.class deleted file mode 100644 index dc41980..0000000 Binary files a/server/tesi/out/production/tesi/com/company/global.class and /dev/null differ diff --git a/server/tesi/out/production/tesi/com/company/guestServer.class b/server/tesi/out/production/tesi/com/company/guestServer.class deleted file mode 100644 index dbbf2f7..0000000 Binary files a/server/tesi/out/production/tesi/com/company/guestServer.class and /dev/null differ diff --git a/server/tesi/out/production/tesi/com/company/httpget$MyHandler.class b/server/tesi/out/production/tesi/com/company/httpget$MyHandler.class deleted file mode 100644 index 0db2b2c..0000000 Binary files a/server/tesi/out/production/tesi/com/company/httpget$MyHandler.class and /dev/null differ diff --git a/server/tesi/out/production/tesi/com/company/httpget.class b/server/tesi/out/production/tesi/com/company/httpget.class deleted file mode 100644 index 9593347..0000000 Binary files a/server/tesi/out/production/tesi/com/company/httpget.class and /dev/null differ diff --git a/server/tesi/out/production/tesi/com/company/keystore.bks b/server/tesi/out/production/tesi/com/company/keystore.bks deleted file mode 100644 index ecec326..0000000 Binary files a/server/tesi/out/production/tesi/com/company/keystore.bks and /dev/null differ diff --git a/server/tesi/out/production/tesi/com/company/keystore.crt b/server/tesi/out/production/tesi/com/company/keystore.crt deleted file mode 100644 index e60e9db..0000000 Binary files a/server/tesi/out/production/tesi/com/company/keystore.crt and /dev/null differ diff --git a/server/tesi/out/production/tesi/com/company/keystore.jks b/server/tesi/out/production/tesi/com/company/keystore.jks deleted file mode 100644 index 4edd598..0000000 Binary files a/server/tesi/out/production/tesi/com/company/keystore.jks and /dev/null differ diff --git a/server/tesi/out/production/tesi/com/company/personalServer.class b/server/tesi/out/production/tesi/com/company/personalServer.class deleted file mode 100644 index 81fabd7..0000000 Binary files a/server/tesi/out/production/tesi/com/company/personalServer.class and /dev/null differ diff --git a/server/tesi/out/production/tesi/com/company/suString.class b/server/tesi/out/production/tesi/com/company/suString.class deleted file mode 100644 index d504a2d..0000000 Binary files a/server/tesi/out/production/tesi/com/company/suString.class and /dev/null differ diff --git a/server/tesi/out/production/tesi/com/company/superServer.class b/server/tesi/out/production/tesi/com/company/superServer.class deleted file mode 100644 index 74de9bc..0000000 Binary files a/server/tesi/out/production/tesi/com/company/superServer.class and /dev/null differ diff --git a/server/tesi/out/production/tesi/com/company/xmlOperation.class b/server/tesi/out/production/tesi/com/company/xmlOperation.class deleted file mode 100644 index 143c104..0000000 Binary files a/server/tesi/out/production/tesi/com/company/xmlOperation.class and /dev/null differ diff --git a/server/tesi/out/production/testi/com/company/DeleteFileExample.class b/server/tesi/out/production/testi/com/company/DeleteFileExample.class deleted file mode 100644 index 0e024f6..0000000 Binary files a/server/tesi/out/production/testi/com/company/DeleteFileExample.class and /dev/null differ diff --git a/server/tesi/out/production/testi/com/company/EmailSender.class b/server/tesi/out/production/testi/com/company/EmailSender.class deleted file mode 100644 index e4c00d6..0000000 Binary files a/server/tesi/out/production/testi/com/company/EmailSender.class and /dev/null differ diff --git a/server/tesi/out/production/testi/com/company/EsNameParser.class b/server/tesi/out/production/testi/com/company/EsNameParser.class deleted file mode 100644 index bc79739..0000000 Binary files a/server/tesi/out/production/testi/com/company/EsNameParser.class and /dev/null differ diff --git a/server/tesi/out/production/testi/com/company/dbConnect.class b/server/tesi/out/production/testi/com/company/dbConnect.class deleted file mode 100644 index c6a1217..0000000 Binary files a/server/tesi/out/production/testi/com/company/dbConnect.class and /dev/null differ diff --git a/server/tesi/out/production/testi/com/company/esercizi.xml b/server/tesi/out/production/testi/com/company/esercizi.xml deleted file mode 100644 index 2d06edb..0000000 --- a/server/tesi/out/production/testi/com/company/esercizi.xml +++ /dev/null @@ -1,3 +0,0 @@ - - albero.xml - \ No newline at end of file diff --git a/server/tesi/out/production/testi/com/company/guestServer.class b/server/tesi/out/production/testi/com/company/guestServer.class deleted file mode 100644 index cc9ff21..0000000 Binary files a/server/tesi/out/production/testi/com/company/guestServer.class and /dev/null differ diff --git a/server/tesi/out/production/testi/com/company/httpget$MyHandler.class b/server/tesi/out/production/testi/com/company/httpget$MyHandler.class deleted file mode 100644 index 2426f4a..0000000 Binary files a/server/tesi/out/production/testi/com/company/httpget$MyHandler.class and /dev/null differ diff --git a/server/tesi/out/production/testi/com/company/httpget.class b/server/tesi/out/production/testi/com/company/httpget.class deleted file mode 100644 index 740b705..0000000 Binary files a/server/tesi/out/production/testi/com/company/httpget.class and /dev/null differ diff --git a/server/tesi/out/production/testi/com/company/keystore.bks b/server/tesi/out/production/testi/com/company/keystore.bks deleted file mode 100644 index ecec326..0000000 Binary files a/server/tesi/out/production/testi/com/company/keystore.bks and /dev/null differ diff --git a/server/tesi/out/production/testi/com/company/keystore.crt b/server/tesi/out/production/testi/com/company/keystore.crt deleted file mode 100644 index e60e9db..0000000 Binary files a/server/tesi/out/production/testi/com/company/keystore.crt and /dev/null differ diff --git a/server/tesi/out/production/testi/com/company/keystore.jks b/server/tesi/out/production/testi/com/company/keystore.jks deleted file mode 100644 index 4edd598..0000000 Binary files a/server/tesi/out/production/testi/com/company/keystore.jks and /dev/null differ diff --git a/server/tesi/out/production/testi/com/company/personalServer.class b/server/tesi/out/production/testi/com/company/personalServer.class deleted file mode 100644 index 03678d6..0000000 Binary files a/server/tesi/out/production/testi/com/company/personalServer.class and /dev/null differ diff --git a/server/tesi/out/production/testi/com/company/suString.class b/server/tesi/out/production/testi/com/company/suString.class deleted file mode 100644 index d8301c9..0000000 Binary files a/server/tesi/out/production/testi/com/company/suString.class and /dev/null differ diff --git a/server/tesi/out/production/testi/com/company/superServer.class b/server/tesi/out/production/testi/com/company/superServer.class deleted file mode 100644 index 44b721f..0000000 Binary files a/server/tesi/out/production/testi/com/company/superServer.class and /dev/null differ diff --git a/server/tesi/src/com/company/DeleteFileExample.class b/server/tesi/src/com/company/DeleteFileExample.class deleted file mode 100644 index 25a7db8..0000000 Binary files a/server/tesi/src/com/company/DeleteFileExample.class and /dev/null differ diff --git a/server/tesi/src/com/company/DirectoryWatcher.class b/server/tesi/src/com/company/DirectoryWatcher.class deleted file mode 100644 index fb7ef98..0000000 Binary files a/server/tesi/src/com/company/DirectoryWatcher.class and /dev/null differ diff --git a/server/tesi/src/com/company/DirectoryWhatcer.java b/server/tesi/src/com/company/DirectoryWhatcer.java deleted file mode 100644 index 8b376a1..0000000 --- a/server/tesi/src/com/company/DirectoryWhatcer.java +++ /dev/null @@ -1,147 +0,0 @@ -package com.company; - -import java.io.*; -import java.nio.file.Path; -import java.nio.file.StandardWatchEventKinds; -import java.nio.file.WatchEvent; -import java.nio.file.WatchEvent.Kind; -import java.nio.file.WatchKey; -import java.nio.file.WatchService; -import java.security.NoSuchAlgorithmException; -import java.sql.SQLException; -import java.util.ArrayList; - -// Simple class to watch directory events. -class DirectoryWatcher implements Runnable { - - private Path path; - - public DirectoryWatcher(Path path) { - this.path = path; - } - - //rimuove tutti gli elementi non validi - private void pulisciCartella() { - File dir = new File(global.locationEsercizi); - String[] lista=dir.list(); - for(String name : lista) - { - if (!EsNameParser.check(name)) - { - File file = new File(global.locationEsercizi+name); - if (file.delete()) - System.out.println("eliminato: "+name); - else - System.out.println("problema di eliminazione file"); - } - else - { - xmlOperation es=new xmlOperation(); - File car=new File(global.listaEsercizi); - if (car.exists()) { - dbConnect db=new dbConnect(); - try { - ArrayList esercizi=suString.stringToArrayList(db.dbQuery("4")); - boolean add=true; - for(String esercizio : esercizi) - { - if(esercizio.equals(name)) - add=false; - } - if(add) - es.add(name); - } catch (SQLException e) { - e.printStackTrace(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InstantiationException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } - } - } - } - } - - // print the events and the affected file - private void printEvent(WatchEvent event) throws IOException { - Kind kind = event.kind(); - if (kind.equals(StandardWatchEventKinds.ENTRY_CREATE)) - { - Path pathCreated = (Path) event.context(); - System.out.println("Entry created:" + pathCreated); - boolean check = EsNameParser.check(pathCreated.getFileName().toString()); - if(!check) - { - File file = new File(global.locationEsercizi+pathCreated.getFileName().toString()); - if(file.delete()) - System.out.println("eliminato"); - else - System.out.println("problema di eliminazione file"); - } - else - { - xmlOperation es=new xmlOperation(); - File dir=new File(global.listaEsercizi); - if (dir.exists()) - es.add(pathCreated.getFileName().toString()); - } - } - else if (kind.equals(StandardWatchEventKinds.ENTRY_DELETE)) - { - Path pathDeleted = (Path) event.context(); - System.out.println("Entry deleted:" + pathDeleted); - xmlOperation es=new xmlOperation(); - File dir=new File(global.listaEsercizi); - if (dir.exists()) - es.remove(pathDeleted.getFileName().toString()); - } - else if (kind.equals(StandardWatchEventKinds.ENTRY_MODIFY)) - { - Path pathModified = (Path) event.context(); - System.out.println("Entry modified:" + pathModified); - } - } - - @Override - public void run() { - try { - pulisciCartella(); - WatchService watchService = path.getFileSystem().newWatchService(); - path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE, - StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE); - - // loop forever to watch directory - while (true) { - WatchKey watchKey; - watchKey = watchService.take(); // this call is blocking until events are present - - // poll for file system events on the WatchKey - for (final WatchEvent event : watchKey.pollEvents()) { - printEvent(event); - } - - // if the watched directed gets deleted, get out of run method - if (!watchKey.reset()) { - System.out.println("No longer valid"); - watchKey.cancel(); - watchService.close(); - break; - } - } - - } catch (InterruptedException ex) { - System.out.println("interrupted. Goodbye"); - return; - } catch (IOException ex) { - ex.printStackTrace(); // don't do this in production code. Use a loggin framework - return; - } - } - -} diff --git a/server/tesi/src/com/company/EmailSender.class b/server/tesi/src/com/company/EmailSender.class deleted file mode 100644 index 8c301a8..0000000 Binary files a/server/tesi/src/com/company/EmailSender.class and /dev/null differ diff --git a/server/tesi/src/com/company/EmailSender.java b/server/tesi/src/com/company/EmailSender.java deleted file mode 100644 index 1abf701..0000000 --- a/server/tesi/src/com/company/EmailSender.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.company; - -import java.util.Date; -import java.util.Properties; -import javax.mail.Message; -import javax.mail.MessagingException; -import javax.mail.Multipart; -import javax.mail.NoSuchProviderException; -import javax.mail.Session; -import javax.mail.Transport; -import javax.mail.internet.AddressException; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeBodyPart; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMultipart; - - - -public class EmailSender { - private String user; - private String password; - private String host; - private String mittente; - private String destinatario; - private String oggetto; - private String mess; - - - EmailSender(String user, String password, String host, - String mittente, String destinatario, - String oggetto, String mess){ - - this.user = user; - this.password = password; - this.host = host; - this.mittente = mittente; - this.destinatario = destinatario; - this.oggetto = oggetto; - this.mess=mess; - } - - - // Metodo che si occupa dell'invio effettivo della mail - public void inviaEmail() { - int port = 465; //porta 25 per non usare SSL - - Properties props = new Properties(); - props.put("mail.smtp.auth", "true"); - props.put("mail.smtp.user", mittente); - props.put("mail.smtp.host", host); - props.put("mail.smtp.port", port); - - // commentare la riga seguente per non usare SSL - props.put("mail.smtp.starttls.enable","true"); - props.put("mail.smtp.socketFactory.port", port); - - // commentare la riga seguente per non usare SSL - props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); - props.put("mail.smtp.socketFactory.fallback", "false"); - - Session session = Session.getInstance(props, null); - session.setDebug(true); - - // Creazione delle BodyParts del messaggio - MimeBodyPart messageBodyPart1 = new MimeBodyPart(); - - try{ - // COSTRUZIONE DEL MESSAGGIO - Multipart multipart = new MimeMultipart(); - MimeMessage msg = new MimeMessage(session); - - // header del messaggio - msg.setSubject(oggetto); - msg.setSentDate(new Date()); - msg.setFrom(new InternetAddress(mittente)); - - // destinatario - msg.addRecipient(Message.RecipientType.TO, - new InternetAddress(destinatario)); - - // corpo del messaggio - messageBodyPart1.setText(mess); - multipart.addBodyPart(messageBodyPart1); - - // allegato al messaggio - /*DataSource source = new FileDataSource(allegato); - messageBodyPart2.setDataHandler(new DataHandler(source)); - messageBodyPart2.setFileName(allegato); - multipart.addBodyPart(messageBodyPart2);*/ - - // inserimento delle parti nel messaggio - msg.setContent(multipart); - - Transport transport = session.getTransport("smtps"); //("smtp") per non usare SSL - transport.connect(host, user, password); - transport.sendMessage(msg, msg.getAllRecipients()); - transport.close(); - - System.out.println("Invio dell'email Terminato"); - - }catch(AddressException ae) { - ae.printStackTrace(); - }catch(NoSuchProviderException nspe){ - nspe.printStackTrace(); - }catch(MessagingException me){ - me.printStackTrace(); - } - - } -} diff --git a/server/tesi/src/com/company/EsNameParser.class b/server/tesi/src/com/company/EsNameParser.class deleted file mode 100644 index d2cfbe3..0000000 Binary files a/server/tesi/src/com/company/EsNameParser.class and /dev/null differ diff --git a/server/tesi/src/com/company/EsNameParser.java b/server/tesi/src/com/company/EsNameParser.java deleted file mode 100644 index f4f1105..0000000 --- a/server/tesi/src/com/company/EsNameParser.java +++ /dev/null @@ -1,144 +0,0 @@ -package com.company; - -import java.io.File; -import java.io.FileInputStream; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathFactory; - -import org.w3c.dom.Document; - -import java.lang.Integer; -import java.io.FileReader; -import java.io.BufferedReader; - -public class EsNameParser { - EsNameParser(){} - - static public String esName() - { - try { - FileInputStream file = new FileInputStream(new File(global.listaEsercizi)); - DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = builderFactory.newDocumentBuilder(); - Document xmlDocument = builder.parse(file); - XPath xPath = XPathFactory.newInstance().newXPath(); - int esNumber = Integer.parseInt(xPath.compile("count(/esercizi/esercizio)").evaluate(xmlDocument)); - String returnValue = null; - for (int i = 1; i <= esNumber; i++) { - String name = xPath.compile("/esercizi/esercizio[" + i + "]").evaluate(xmlDocument); - if (name == null || name.isEmpty()) - continue; - else { - if(returnValue==null) - returnValue=name; - else - returnValue = returnValue + "/" + name; - } - } - file.close(); - return returnValue; - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - public static boolean check(String esercizio) - { - boolean value=false; - try - { - String cartellaEs=global.locationEsercizi; - - BufferedReader br = new BufferedReader(new FileReader(cartellaEs+esercizio)); - if (br.readLine() == null) { - br.close(); - return false; - } - FileInputStream file = new FileInputStream(new File(cartellaEs+"/"+esercizio)); - DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = builderFactory.newDocumentBuilder(); - Document xmlDocument = builder.parse(file); - value=checkFormula(xmlDocument,"/esercizio/tesi/formula[1]"); - if(value) - value=checkIpotesi(xmlDocument); - file.close(); - } catch (Exception e) { - e.printStackTrace(); - } - return value; - } - - static public boolean checkFormula(Document xmlDocument, String position) { - try - { - XPath xPath = XPathFactory.newInstance().newXPath(); - if(Integer.parseInt(xPath.compile("count(" + position + ")").evaluate(xmlDocument))==1) { - String type = xPath.compile(position + "/@type").evaluate(xmlDocument); - int numbOfElements = 5; - if (type.contentEquals("and") || type.contentEquals("or") || type.contentEquals("impl")) - numbOfElements = 2; - else if (type.contentEquals("not")) - numbOfElements = 1; - else if (type.contentEquals("literal") || type.contentEquals("atomic")) - numbOfElements = 0; - int count = Integer.parseInt(xPath.compile("count(" + position + "/formula)").evaluate(xmlDocument)); - if (count == numbOfElements) { - if (numbOfElements == 2) { - boolean firstChild = checkFormula(xmlDocument, position + "/formula[1]"); - boolean secondChild = checkFormula(xmlDocument, position + "/formula[2]"); - if (!firstChild || !secondChild) - return false; - else - return true; - } - else if (numbOfElements == 1) - { - boolean child = checkFormula(xmlDocument, position + "/formula[1]"); - if (!child) - return false; - return true; - } - else if (numbOfElements == 0) - { - String child = xPath.compile(position).evaluate(xmlDocument); - if (child == null || child.isEmpty()) - return false; - else - return true; - } - } - } - } catch (Exception e) { - e.printStackTrace(); - } - return false; - } - - static public boolean checkIpotesi(Document xmlDocument) - { - XPath xPath = XPathFactory.newInstance().newXPath(); - boolean returnValue=false; - try - { - int count = Integer.parseInt(xPath.compile("count(/esercizio/ipotesi)").evaluate(xmlDocument)); - int numberHp=Integer.parseInt(xPath.compile("count(/esercizio/ipotesi/formula)").evaluate(xmlDocument)); - if(count==1 && numberHp==0)//se non ci sono ipotesi - return true; - for(int i=1;i<=numberHp;i++) - { - boolean valore = checkFormula(xmlDocument, "/esercizio/ipotesi/formula["+i+"]"); - if(!valore) - return false; - else - returnValue=true; - } - }catch (Exception e) { - e.printStackTrace(); - } - return returnValue; - } -} diff --git a/server/tesi/src/com/company/MD5.class b/server/tesi/src/com/company/MD5.class deleted file mode 100644 index 79abbc1..0000000 Binary files a/server/tesi/src/com/company/MD5.class and /dev/null differ diff --git a/server/tesi/src/com/company/MD5.java b/server/tesi/src/com/company/MD5.java deleted file mode 100644 index 623f11f..0000000 --- a/server/tesi/src/com/company/MD5.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.company; - -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - - -public class MD5 { - - MD5(){} - public static String digest(String filePath) { - InputStream inputStream = null; - try { - inputStream = new FileInputStream(global.locationEsercizi+filePath); - byte[] buffer = new byte[1024]; - MessageDigest digest = MessageDigest.getInstance("MD5"); - int numRead = 0; - while (numRead != -1) { - numRead = inputStream.read(buffer); - if (numRead > 0) - digest.update(buffer, 0, numRead); - } - byte [] md5Bytes = digest.digest(); - System.out.println(convertHashToString(md5Bytes)); - return convertHashToString(md5Bytes); - } catch (Exception e) { - return null; - } finally { - if (inputStream != null) { - try { - inputStream.close(); - } catch (Exception e) { } - } - } - } - - private static String convertHashToString(byte[] md5Bytes) { - String returnVal = ""; - for (int i = 0; i < md5Bytes.length; i++) { - returnVal += Integer.toString(( md5Bytes[i] & 0xff ) + 0x100, 16).substring(1); - } - return returnVal; - } -} diff --git a/server/tesi/src/com/company/Makefile b/server/tesi/src/com/company/Makefile deleted file mode 100644 index 2cc75ec..0000000 --- a/server/tesi/src/com/company/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -all: - javac -cp "/tmp/ext/mysql-connector-java.jar:/tmp/ext/jdom-2.0.5.jar:/tmp/ext/mail-1.4.1.jar:." *.java diff --git a/server/tesi/src/com/company/dbConnect.class b/server/tesi/src/com/company/dbConnect.class deleted file mode 100644 index 03ff58b..0000000 Binary files a/server/tesi/src/com/company/dbConnect.class and /dev/null differ diff --git a/server/tesi/src/com/company/dbConnect.java b/server/tesi/src/com/company/dbConnect.java deleted file mode 100644 index 28d851c..0000000 --- a/server/tesi/src/com/company/dbConnect.java +++ /dev/null @@ -1,355 +0,0 @@ -package com.company; - -import java.sql.*; -import java.io.IOException; - -import java.math.BigInteger; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -import java.util.Random; - -import java.sql.Timestamp; - -import java.util.ArrayList; - -import java.lang.Double; - -public class dbConnect -{ - private static Connection db; - private static Statement stmt; - dbConnect() - {} - - - public static Long time() - { - java.util.Date date= new java.util.Date(); - Timestamp now=new Timestamp(date.getTime()); - return now.getTime(); - } - - //pulisce confmail e connessi da tutte le richieste maggiori di 10 minuti - private static void deletetmp() throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException - { - PreparedStatement preparedStmt = db.prepareStatement("DELETE FROM confmail WHERE time<=?"); - preparedStmt.setLong (1,(time()-600000)); - preparedStmt.execute(); - preparedStmt = db.prepareStatement("DELETE FROM connessi WHERE time<=?"); - preparedStmt.setLong (1,(time()-600000)); - preparedStmt.execute(); - } - - //divide la stringa in user e password - private static String splitUsrPass(String userAndPass, int code) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException - { - String user=null; - String pass=null; - ArrayList userPass= suString.stringToArrayList(userAndPass); - if(userPass.size()>=1) - user=userPass.get(0); - if(userPass.size()>=2) - pass=userPass.get(1); - - assert user != null; - if(!user.contains("@studio.unibo.it") && user.length()<16) - return "mail-error"; - else { - assert pass != null; - if(code==0) - return registration(user, pass); - else if(code==1) - return login(user, pass); - else if(code==2) - return recupero(user); - else - return "error"; - } - } - - //routin di gestione recupero pass - private static String recupero(String user) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException - { - ResultSet returnQuery=stmt.executeQuery("SELECT * FROM utenti where user='"+user+"'"); - if(returnQuery!=null) - { - if(returnQuery.next()) - { - EmailSender email = new EmailSender(global.email, - global.emailPass, - "smtp.gmail.com", - global.email, - user, - "OGGETTO: recupero password", - "la tua password è "+returnQuery.getString("pass")); - email.inviaEmail(); - return "mail-pass-ok"; - } - else - return "user-error"; - } - else - return "user-error"; - } - - - //routin di gestione della registrazione - private static String registration(String user, String pass) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException - { - String ran; - ResultSet returnQuery=stmt.executeQuery("SELECT * FROM utenti where user='"+user+"'"); - if(returnQuery!=null) - { - if(returnQuery.next()) - { - if(returnQuery.getString("user").compareTo(user)==0 && returnQuery.getString("pass").compareTo(pass)==0) - return "già-registrato"; - } - } - returnQuery=stmt.executeQuery("SELECT * FROM confmail where user='"+user+"'"); - if(returnQuery!=null) - { - if(returnQuery.next()) - { - ran=returnQuery.getString("hash"); - if(returnQuery.getString("pass").compareTo(pass)!=0) - { - PreparedStatement preparedStmt = db.prepareStatement("UPDATE confmail SET pass =? where user=?"); - preparedStmt.setString (1,pass); - preparedStmt.setString (2,user); - preparedStmt.execute(); - } - } - else - { - Random random = new Random(); - ran=String.valueOf(random.nextInt(100000000)+10000000)+String.valueOf(random.nextInt(100000000)+10000000)+String.valueOf(random.nextInt(100000000)+10000000); - //returnQuery=stmt.executeQuery("INSERT INTO confmail VALUES('"+user+"','"+pass+"',"+hash+"')"); - PreparedStatement preparedStmt = db.prepareStatement("INSERT INTO confmail (user,pass,hash,time) VALUES(?,?,?,?)"); - preparedStmt.setString (1,user); - preparedStmt.setString (2,pass); - preparedStmt.setString (3,ran); - preparedStmt.setDouble (4,(double)time()); - preparedStmt.execute(); - } - } - else - { - Random random = new Random(); - ran=String.valueOf(random.nextInt(100000000)+10000000)+String.valueOf(random.nextInt(100000000)+10000000)+String.valueOf(random.nextInt(100000000)+10000000); - //returnQuery=stmt.executeQuery("INSERT INTO confmail VALUES('"+user+"','"+pass+"',"+hash+"')"); - PreparedStatement preparedStmt = db.prepareStatement("INSERT INTO confmail (user,pass,hash,time) VALUES(?,?,?,?)"); - preparedStmt.setString (1,user); - preparedStmt.setString (2,pass); - preparedStmt.setString (3,ran); - preparedStmt.setDouble (4,(double)time()); - preparedStmt.execute(); - } - EmailSender email = new EmailSender(global.email, - global.emailPass, - "smtp.gmail.com", - global.email, - user, - "OGGETTO: Registrazione App", - "per confermare la tua email clicka sul link: http://"+global.serverName+"/test?id="+ran); - email.inviaEmail(); - return "mail-reg-ok"; - } - - //routin conferma registrazione - private static String confirmRegistration(String hash) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException - { - ResultSet returnQuery=stmt.executeQuery("SELECT * FROM confmail where hash='"+hash+"'"); - if(returnQuery!=null) - { - if(returnQuery.next()) - { - PreparedStatement preparedStmt = db.prepareStatement("INSERT INTO utenti (user,pass) VALUES(?,?)"); - preparedStmt.setString (1,returnQuery.getString("user")); - preparedStmt.setString (2,returnQuery.getString("pass")); - preparedStmt.execute(); - preparedStmt = db.prepareStatement("DELETE FROM confmail WHERE hash=?"); - preparedStmt.setString (1,hash); - preparedStmt.execute(); - return "registrazione-ok"; - } - } - return "registrazione-error"; - } - - //routin di gestione login - private static String login(String user, String pass) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException - { - - ResultSet returnQuery=stmt.executeQuery("SELECT * FROM utenti where user='"+user+"' and pass='"+pass+"'"); - if(returnQuery!=null) - { - if(returnQuery.next()) - { - if(returnQuery.getString("user").compareTo(user)==0 && returnQuery.getString("pass").compareTo(pass)==0) - return putConnessi(user); - } - } - return "login-error"; - } - - - //informazioni sulla connessione dell'utente - private String infoConnessi(String message) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException - { - ArrayList split= suString.stringToArrayList(message); - if(split.size()>=1) - { - ResultSet returnQuery=stmt.executeQuery("SELECT * FROM connessi WHERE tempkey='"+split.get(1)+"'"); - if(returnQuery!=null) - { - if(returnQuery.next()) - { - return "loggato"; - } - } - } - return "request-login"; - } - - //inserisce l'utente in connessi - private static String putConnessi(String user) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException - { - Random random = new Random(); - String ran=String.valueOf(random.nextInt(100000000)+10000000)+String.valueOf(random.nextInt(100000000)+10000000); - PreparedStatement preparedStmt = db.prepareStatement("INSERT INTO connessi (user,tempkey,thread,time) VALUES(?,?,?,?)"); - preparedStmt.setString (1,user); - preparedStmt.setString (2,ran); - preparedStmt.setBoolean (3,false); - preparedStmt.setDouble (4,(double)time()); - preparedStmt.execute(); - return ran; - } - - //segnalare morte di un thread - private String threadDead(String key) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException - { - PreparedStatement preparedStmt = db.prepareStatement("DELETE FROM confmail WHERE tempkey=?"); - preparedStmt.setString (1,key); - preparedStmt.execute(); - return "kill-ok"; - } - - //remposta il rimer dell'utente nella tabella connessi - private String connessiTimer(String key) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException - { - PreparedStatement preparedStmt = db.prepareStatement("UPDATE connessi SET time =? where tempkey=?"); - preparedStmt.setDouble (1,(double)time()); - preparedStmt.setString (2,key); - preparedStmt.execute(); - return "timer-settato"; - } - - private String exerciseAccept(String request) throws SQLException, IOException, NoSuchAlgorithmException { - ArrayList input=suString.stringToArrayList(request); - ResultSet returnQuery=stmt.executeQuery("SELECT * FROM connessi where tempkey='"+input.get(0)+"'"); - String utente=null; - if(returnQuery!=null) - { - if(returnQuery.next()) - utente=returnQuery.getString("user"); - } - if(utente!=null) - { - String[] esercizi=suString.stringToVectorString(EsNameParser.esName()); - for(String esercizio : esercizi) - { - if(esercizio.contentEquals(input.get(1)))//se l'esercizio esiste - { - if(MD5.digest(esercizio).contentEquals(input.get(2)))//se il digest è uguale - { - PreparedStatement preparedStmt = db.prepareStatement("INSERT INTO esercizi (esercizio,utente,click,time) VALUES(?,?,?,?)"); - preparedStmt.setDouble(4, Double.parseDouble(input.get(3))); - preparedStmt.setInt (3,Integer.valueOf(input.get(4))); - preparedStmt.setString (2,utente); - preparedStmt.setString (1,input.get(1)); - preparedStmt.execute(); - return "es-ok"; - } - } - } - } - return "es-err"; - } - - private String userExercise(String request) throws SQLException { - ArrayList arrayResult=new ArrayList(); - ArrayList input=suString.stringToArrayList(request); - String result=null; - ResultSet returnQuery=stmt.executeQuery("SELECT * FROM connessi where tempkey='"+input.get(0)+"'"); - String utente=null; - if(returnQuery!=null) - { - if(returnQuery.next()) - utente=returnQuery.getString("user"); - } - if(utente!=null) - { - returnQuery=stmt.executeQuery("SELECT * FROM esercizi where utente='"+utente+"'"); - while(returnQuery.next()) - { - arrayResult.add(returnQuery.getString("esercizio")+"/"+MD5.digest(returnQuery.getString("esercizio"))+"/"+returnQuery.getDouble("time")+"/"+returnQuery.getInt("click")); - } - result=suString.multiToString(arrayResult); - } - return result; - } - - private String cambiaPass(String request) throws ClassNotFoundException, SQLException, InstantiationException, IOException, IllegalAccessException { - ArrayList input=suString.stringToArrayList(request); - if(input.size()>=3) { - String result = login(input.get(0), input.get(1)); - if(!result.contains("err")) - { - PreparedStatement preparedStmt = db.prepareStatement("UPDATE utenti SET pass =? where user=?"); - preparedStmt.setString (1,input.get(2)); - preparedStmt.setString (2,input.get(0)); - preparedStmt.execute(); - return "cambiata"; - } - } - return "error"; - } - - public String dbQuery(String input) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException, NoSuchAlgorithmException { - Class.forName("com.mysql.jdbc.Driver").newInstance(); - db = DriverManager.getConnection("jdbc:mysql://localhost/logintesi", "root", "csc@CerCo!"); - stmt = db.createStatement(); - deletetmp(); - if (input.charAt(0) == '0') - return splitUsrPass(input.substring(2), 0); - else if (input.charAt(0) == '1') - return splitUsrPass(input.substring(2), 1); - else if (input.charAt(0) == '2') - return recupero(input.substring(2)); - else if (input.charAt(0) == '3') - return confirmRegistration(input.substring(1)); - else if (input.charAt(0) == '4') - return EsNameParser.esName(); - else if (input.charAt(0) == '5') - return infoConnessi(input.substring(2)); - else if (input.charAt(0) == '6') - return connessiTimer(input.substring(2)); - /*else if (input.charAt(0) == '7') - return threadDead(input.substring(2));*/ - /*else if(input.charAt(0)=='8') - return aggToClient(input.substring(2)); - else if(input.charAt(0)=='9') - return aggForClient(input.substring(2)); - else if(input.charAt(0)=='a' && input.charAt(1)=='0') - return check(input.substring(3));*/ - else if (input.charAt(0) == '8') - return exerciseAccept(input.substring(2)); - else if (input.charAt(0) == '9') - return userExercise(input.substring(2)); - else if(input.charAt(0)=='a' && input.charAt(1)=='0') - return cambiaPass(input.substring(3)); - return "error"; - } -} diff --git a/server/tesi/src/com/company/esercizi.xml b/server/tesi/src/com/company/esercizi.xml deleted file mode 100644 index c28cd97..0000000 --- a/server/tesi/src/com/company/esercizi.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - aalbero.xml - tautologia.xml - demorgan.xml - triviale.xml - test.xml - risolvibile.xml - demorgan2.xml - diff --git a/server/tesi/src/com/company/esercizi.xml~ b/server/tesi/src/com/company/esercizi.xml~ deleted file mode 100644 index 47eb032..0000000 --- a/server/tesi/src/com/company/esercizi.xml~ +++ /dev/null @@ -1,4 +0,0 @@ - - - aalbero.xml - diff --git a/server/tesi/src/com/company/global.class b/server/tesi/src/com/company/global.class deleted file mode 100644 index 00f0bd3..0000000 Binary files a/server/tesi/src/com/company/global.class and /dev/null differ diff --git a/server/tesi/src/com/company/global.java b/server/tesi/src/com/company/global.java deleted file mode 100644 index 2bf06c4..0000000 --- a/server/tesi/src/com/company/global.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.company; - - -public class global { - public static final String listaEsercizi="/projects/logicplayer/Server/server/tesi/src/com/company/esercizi.xml"; - public static final String locationEsercizi="/projects/logicplayer/public_html/esercizi/"; - public static String home="/projects/logicplayer/Server/server/tesi/src/com/company/"; - public static String keyStorePass="123456"; - public static String keyStoreName="keystore.jks"; - public static String serverName="130.136.129.1"; - public static String email="confermaiscrizioneserver@gmail.com"; - public static String emailPass="tes6phev8n"; - public static int portaServer=25000; - public static int portaHttpServer=8000; - -} diff --git a/server/tesi/src/com/company/guestServer.class b/server/tesi/src/com/company/guestServer.class deleted file mode 100644 index 59b4c18..0000000 Binary files a/server/tesi/src/com/company/guestServer.class and /dev/null differ diff --git a/server/tesi/src/com/company/guestServer.java b/server/tesi/src/com/company/guestServer.java deleted file mode 100644 index 1fb6ce9..0000000 --- a/server/tesi/src/com/company/guestServer.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.company; - -import java.io.*; - -import javax.net.ssl.*; - -class guestServer implements Runnable -{ - private SSLSocket socket; - - guestServer(SSLSocket client) - { - socket=client; - } - - public void run() - { - try - { - - //Reading the message from the client - InputStream is = socket.getInputStream(); - InputStreamReader isr = new InputStreamReader(is); - BufferedReader br = new BufferedReader(isr); - String requestMessage = br.readLine(); - System.out.println("ho ricevuto: "+requestMessage); - /*System.out.println("Message received from client is "+returnMessage); - dbConnect request=new dbConnect(); - String returnQuery=request.dbQuery(returnMessage); - OutputStream os = socket.getOutputStream(); - OutputStreamWriter osw = new OutputStreamWriter(os); - BufferedWriter bw = new BufferedWriter(osw); - System.out.println(returnQuery); - bw.write(returnQuery+"\n"); - bw.flush();*/ - if(requestMessage!=null) - { - dbConnect request = new dbConnect(); - String returnQuery; - if ( requestMessage.charAt(0) == '0' || - requestMessage.charAt(0) == '1' || - requestMessage.charAt(0) == '2' || - (requestMessage.charAt(0) == 'a' && requestMessage.charAt(1) == '0')) { - returnQuery = request.dbQuery(requestMessage); - OutputStream os = socket.getOutputStream(); - OutputStreamWriter osw = new OutputStreamWriter(os); - BufferedWriter bw = new BufferedWriter(osw); - bw.write(returnQuery + "\n"); - bw.flush(); - System.out.println("ho inviato: " + returnQuery); - } - else - { - returnQuery = request.dbQuery("5/" + requestMessage); - if (returnQuery.contains("request-login") || returnQuery.contains("request-error")) - { - OutputStream os = socket.getOutputStream(); - OutputStreamWriter osw = new OutputStreamWriter(os); - BufferedWriter bw = new BufferedWriter(osw); - bw.write(returnQuery + "\n"); - bw.flush(); - System.out.println("ho inviato: " + returnQuery); - } - else if (returnQuery.contains("loggato")) - { - personalServer nuovaConnessione = new personalServer(socket, requestMessage); - Thread t = new Thread(nuovaConnessione); - t.start(); - } - } - } - - } - catch (Exception e) - { - e.printStackTrace(); - } - - } -} diff --git a/server/tesi/src/com/company/httpget$MyHandler.class b/server/tesi/src/com/company/httpget$MyHandler.class deleted file mode 100644 index 7862be8..0000000 Binary files a/server/tesi/src/com/company/httpget$MyHandler.class and /dev/null differ diff --git a/server/tesi/src/com/company/httpget.class b/server/tesi/src/com/company/httpget.class deleted file mode 100644 index b710c11..0000000 Binary files a/server/tesi/src/com/company/httpget.class and /dev/null differ diff --git a/server/tesi/src/com/company/httpget.java b/server/tesi/src/com/company/httpget.java deleted file mode 100644 index 079cc01..0000000 --- a/server/tesi/src/com/company/httpget.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.company; - -import java.io.*; -import java.net.*; -import java.security.NoSuchAlgorithmException; -import java.util.*; - -import com.sun.net.httpserver.HttpExchange; -import com.sun.net.httpserver.HttpHandler; -import com.sun.net.httpserver.HttpServer; -import java.sql.*; - -public class httpget implements Runnable { - - httpget(){} - - public static Map splitQuery(String query) throws UnsupportedEncodingException - { - Map query_pairs = new LinkedHashMap(); - String[] pairs = query.split("&"); - for (String pair : pairs) - { - int idx = pair.indexOf("="); - query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), URLDecoder.decode(pair.substring(idx + 1), "UTF-8")); - } - return query_pairs; - } - - @Override - public void run() { - try { - HttpServer server = HttpServer.create(new InetSocketAddress(global.portaHttpServer), 0); - server.createContext("/test", new MyHandler()); - server.setExecutor(null); // creates a default executor - server.start(); - }catch (Exception e) - { - e.printStackTrace(); - } - } - - static class MyHandler implements HttpHandler - { - public void handle(HttpExchange t) throws IOException - { - - /*String response = "This is the response"; - System.out.println("mannaggia santa"); - t.sendResponseHeaders(200, response.length()); - OutputStream os = t.getResponseBody(); - os.write(response.getBytes());*/ - URI req=t.getRequestURI(); - String query=req.getQuery(); - Map result=splitQuery(query); - String id=result.get("id"); - //System.out.println(id); - try - { - dbConnect request=new dbConnect(); - String returnQuery=request.dbQuery("3"+id); - t.sendResponseHeaders(200, returnQuery.length()); - OutputStream os = t.getResponseBody(); - os.write(returnQuery.getBytes()); - os.close(); - } - catch(SQLException e) - {} - catch(ClassNotFoundException c) - {} - catch(IllegalAccessException a) - {} - catch(InstantiationException i) - {} catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } - } - } - -} diff --git a/server/tesi/src/com/company/keystore.bks b/server/tesi/src/com/company/keystore.bks deleted file mode 100644 index ecec326..0000000 Binary files a/server/tesi/src/com/company/keystore.bks and /dev/null differ diff --git a/server/tesi/src/com/company/keystore.crt b/server/tesi/src/com/company/keystore.crt deleted file mode 100644 index e60e9db..0000000 Binary files a/server/tesi/src/com/company/keystore.crt and /dev/null differ diff --git a/server/tesi/src/com/company/keystore.jks b/server/tesi/src/com/company/keystore.jks deleted file mode 100644 index 4edd598..0000000 Binary files a/server/tesi/src/com/company/keystore.jks and /dev/null differ diff --git a/server/tesi/src/com/company/personalServer.class b/server/tesi/src/com/company/personalServer.class deleted file mode 100644 index 1d5b025..0000000 Binary files a/server/tesi/src/com/company/personalServer.class and /dev/null differ diff --git a/server/tesi/src/com/company/personalServer.java b/server/tesi/src/com/company/personalServer.java deleted file mode 100644 index 1d338eb..0000000 --- a/server/tesi/src/com/company/personalServer.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.company; - -import java.io.BufferedWriter; -import java.io.OutputStream; -import java.io.OutputStreamWriter; - -import javax.net.ssl.*; - - -import java.util.ArrayList; - -class personalServer implements Runnable -{ - private SSLSocket socket; - private String key; - private String requestMessage; - - personalServer(SSLSocket client, String message) - { - socket=client; - ArrayList split= suString.stringToArrayList(message); - key=split.get(1); - requestMessage=message; - } - - public void run() - { - try - { - dbConnect request=new dbConnect(); - String returnQuery=request.dbQuery(requestMessage); - OutputStream os = socket.getOutputStream(); - OutputStreamWriter osw = new OutputStreamWriter(os); - BufferedWriter bw = new BufferedWriter(osw); - bw.write(returnQuery+"\n"); - bw.flush(); - System.out.println("ho inviato: "+returnQuery); - request.dbQuery("6/"+key); - socket.close(); - } - catch (Exception e) - { - try - { - e.printStackTrace(); - dbConnect request=new dbConnect(); - request.dbQuery("7/"+key); - } - catch (Exception k) - { - //k.printStackTrace(); - System.out.println("PANIC!"); - } - } - } -} diff --git a/server/tesi/src/com/company/suString.class b/server/tesi/src/com/company/suString.class deleted file mode 100644 index 6d094cb..0000000 Binary files a/server/tesi/src/com/company/suString.class and /dev/null differ diff --git a/server/tesi/src/com/company/suString.java b/server/tesi/src/com/company/suString.java deleted file mode 100644 index 666febe..0000000 --- a/server/tesi/src/com/company/suString.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.company; - -import java.util.ArrayList; -import java.util.Collections; - -public class suString -{ - suString() - {} - - - public static ArrayList stringToArrayList(String string) - { - ArrayList returnValue=new ArrayList(); - int j=0; - for(int i=0;i vectorStringToArrayList(String[] vectorString) - { - ArrayList returnValue=new ArrayList(); - Collections.addAll(returnValue, vectorString); - return returnValue; - } - - public static String arrayListToString (ArrayList arraylist) - { - String returnValue= ""; - for(int i=0;i arraylist) - { - String[] returnValue=new String[arraylist.size()]; - for(int i=0;i input) - { - String returnValue=null; - int size=input.size(); - for(int i=0;i stringToMultiArray(String input) - { - ArrayList result=new ArrayList(); - int j=0; - for(int i=0;i - - - - - - - - - - \ No newline at end of file