From f66eb18558dee1bc399bd86a050394afbf7ecbfa Mon Sep 17 00:00:00 2001 From: Timothy Prepscius Date: Fri, 9 Aug 2013 16:31:05 -0400 Subject: [PATCH] adds the build scripts, removes some remaining unremoved files which I thought I removed last time --- .gitignore | 2 +- build/clean-demos3 | 1 + build/compile-web | 7 + build/compile-web-html | 68 +++ build/compile-web-js | 20 + build/dev-compile-web | 7 + build/doWeb | 3 + build/export | 8 + build/exportScripts/Client.xml | 56 ++ build/exportScripts/KeyStreamServer.xml | 49 ++ build/exportScripts/MailStreamServer.xml | 49 ++ build/exportScripts/Service.xml | 47 ++ build/exportScripts/Setup.xml | 61 +++ build/exportScripts/Tools.xml | 59 +++ build/exportTools | 2 + build/replace_html.sed | 27 + build/replace_html_dev.sed | 1 + build/replace_html_prod.sed | 6 + build/replace_js_dev.sed | 6 + build/replace_js_prod.sed | 4 + .../org/timepedia/exporter/client/Export.java | 9 - .../timepedia/exporter/client/Exportable.java | 10 - .../timepedia/exporter/client/NoExport.java | 10 - java/core/src/core/server/db/UserDb.java | 479 ------------------ java/core/src/core/server/db/sql/Catalog.java | 51 -- .../core/src/core/server/db/sql/create_tables | 55 -- java/core/src/core/server/db/sql/create_user | 1 - .../src/core/server/db/sql/delete_user.sql | 24 - .../server/db/sql/expunge_deleted_user.sql | 9 - .../core/server/db/sql/get_deleted_user.sql | 7 - .../db/sql/get_deleted_user_mail_block.sql | 8 - .../src/core/server/db/sql/get_last_failure | 8 - java/core/src/core/server/db/sql/get_user | 6 - .../src/core/server/db/sql/get_user_key_block | 8 - .../core/server/db/sql/get_user_mail_block | 8 - java/core/src/core/server/db/sql/mark_failure | 8 - .../src/core/server/db/sql/room_for_new_user | 4 - .../src/core/server/db/sql/set_user_key_block | 1 - .../core/server/db/sql/set_user_mail_block | 1 - 39 files changed, 482 insertions(+), 708 deletions(-) create mode 100755 build/clean-demos3 create mode 100755 build/compile-web create mode 100755 build/compile-web-html create mode 100755 build/compile-web-js create mode 100755 build/dev-compile-web create mode 100755 build/doWeb create mode 100755 build/export create mode 100644 build/exportScripts/Client.xml create mode 100644 build/exportScripts/KeyStreamServer.xml create mode 100644 build/exportScripts/MailStreamServer.xml create mode 100644 build/exportScripts/Service.xml create mode 100644 build/exportScripts/Setup.xml create mode 100644 build/exportScripts/Tools.xml create mode 100755 build/exportTools create mode 100644 build/replace_html.sed create mode 100644 build/replace_html_dev.sed create mode 100644 build/replace_html_prod.sed create mode 100644 build/replace_js_dev.sed create mode 100644 build/replace_js_prod.sed delete mode 100644 java/core/src/core/org/timepedia/exporter/client/Export.java delete mode 100644 java/core/src/core/org/timepedia/exporter/client/Exportable.java delete mode 100644 java/core/src/core/org/timepedia/exporter/client/NoExport.java delete mode 100644 java/core/src/core/server/db/UserDb.java delete mode 100644 java/core/src/core/server/db/sql/Catalog.java delete mode 100644 java/core/src/core/server/db/sql/create_tables delete mode 100644 java/core/src/core/server/db/sql/create_user delete mode 100644 java/core/src/core/server/db/sql/delete_user.sql delete mode 100644 java/core/src/core/server/db/sql/expunge_deleted_user.sql delete mode 100644 java/core/src/core/server/db/sql/get_deleted_user.sql delete mode 100644 java/core/src/core/server/db/sql/get_deleted_user_mail_block.sql delete mode 100644 java/core/src/core/server/db/sql/get_last_failure delete mode 100644 java/core/src/core/server/db/sql/get_user delete mode 100644 java/core/src/core/server/db/sql/get_user_key_block delete mode 100644 java/core/src/core/server/db/sql/get_user_mail_block delete mode 100644 java/core/src/core/server/db/sql/mark_failure delete mode 100644 java/core/src/core/server/db/sql/room_for_new_user delete mode 100644 java/core/src/core/server/db/sql/set_user_key_block delete mode 100644 java/core/src/core/server/db/sql/set_user_mail_block diff --git a/.gitignore b/.gitignore index df8a012..7c87c1b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ lib/ +xcuserdata # Compiled source # ################### @@ -23,7 +24,6 @@ lib/ # git has its own built in compression methods *.7z *.dmg -*.gz *.iso *.rar *.tar diff --git a/build/clean-demos3 b/build/clean-demos3 new file mode 100755 index 0000000..adf5493 --- /dev/null +++ b/build/clean-demos3 @@ -0,0 +1 @@ +s3cmd del --recursive s3://USER.YOUR_ACCOUNT/Cache diff --git a/build/compile-web b/build/compile-web new file mode 100755 index 0000000..c30c5d7 --- /dev/null +++ b/build/compile-web @@ -0,0 +1,7 @@ +#!/bin/bash + +V=`date "+%Y%m%d_%H%M%S"` + +./compile-web-html $V prod +./compile-web-js $V prod + diff --git a/build/compile-web-html b/build/compile-web-html new file mode 100755 index 0000000..9132626 --- /dev/null +++ b/build/compile-web-html @@ -0,0 +1,68 @@ +#!/bin/bash + +V=$1 +M=$2 + +dst=../gwt/war +cmn_src=../web/common +client_src=../web/client +signup_src=../web/signup +refill_src=../web/refill +delete_src=../web/delete +mobile_large=../web/mobile_large +mobile_small=../web/mobile_small +learnmore=../web/learnmore + +function replaceStrings() { + echo $1 $M + sed -i '' -f replace_html.sed $1 + sed -i '' -f replace_html_$M.sed $1 + sed -i '' -e s/__VERSION__/$V/g $1 + sed -i '' -e s/__THIS_YEAR__/2013/g $1 +} + +echo Compiling CSS/JS +rm -rf $dst/rev +mkdir -p $dst/rev/$V + +cat $cmn_src/*.css $client_src/*.css > $dst/rev/$V/client.css +cat $cmn_src/*.js $client_src/*.js > $dst/rev/$V/client.js + +cat $cmn_src/*.css $signup_src/*.css > $dst/rev/$V/signup.css +cat $cmn_src/*.js $signup_src/*.js > $dst/rev/$V/signup.js + +cat $cmn_src/*.css $refill_src/*.css > $dst/rev/$V/refill.css +cat $cmn_src/*.js $refill_src/*.js > $dst/rev/$V/refill.js + +cat $cmn_src/*.css $delete_src/*.css > $dst/rev/$V/delete.css +cat $cmn_src/*.js $delete_src/*.js > $dst/rev/$V/delete.js + +cat $cmn_src/*.js $client_src/*.js $mobile_large/*.js > $dst/rev/$V/mobile_large.js +cat $cmn_src/*.css $client_src/*.css $mobile_large/*.css > $dst/rev/$V/mobile_large.css + +cat $cmn_src/*.js $client_src/*.js $mobile_small/*.js > $dst/rev/$V/mobile_small.js +cat $cmn_src/*.css $client_src/*.css $mobile_small/*.css > $dst/rev/$V/mobile_small.css + +cat $cmn_src/*.css $learnmore/*.css > $dst/rev/$V/learnmore.css + +echo Copying +cp $client_src/index.html $dst/index.html +cp $signup_src/signup.html $dst/signup.html +cp $refill_src/refill.html $dst/refill.html +cp $delete_src/delete.html $dst/delete.html +cp $mobile_large/mobile_large.html $dst/mobile_large.html +cp $mobile_small/mobile_small.html $dst/mobile_small.html +cp $learnmore/learnmore.html $dst/learnmore.html +cp $learnmore/technical.html $dst/technical.html +cp $signup_src/DropboxAuthorized.html $dst/DropboxAuthorized.html + +echo Replacing Strings +replaceStrings $dst/index.html +replaceStrings $dst/signup.html +replaceStrings $dst/refill.html +replaceStrings $dst/delete.html +replaceStrings $dst/mobile_large.html +replaceStrings $dst/mobile_small.html +replaceStrings $dst/learnmore.html +replaceStrings $dst/technical.html +replaceStrings $dst/DropboxAuthorized.html diff --git a/build/compile-web-js b/build/compile-web-js new file mode 100755 index 0000000..9dd0143 --- /dev/null +++ b/build/compile-web-js @@ -0,0 +1,20 @@ +#!/bin/bash + +V=$1 +M=$2 +dst=../gwt/war + +function replaceStrings() { + sed -i '' -f replace_js_$M.sed $1 + sed -i '' -e s/__VERSION__/$V/g $1 + sed -i '' -e s/__THIS_YEAR__/2013/g $1 +} + +echo Replacing Strings +replaceStrings $dst/rev/$V/client.js +replaceStrings $dst/rev/$V/signup.js +replaceStrings $dst/rev/$V/refill.js +replaceStrings $dst/rev/$V/delete.js +replaceStrings $dst/rev/$V/mobile_large.js +replaceStrings $dst/rev/$V/mobile_small.js + diff --git a/build/dev-compile-web b/build/dev-compile-web new file mode 100755 index 0000000..f1b967a --- /dev/null +++ b/build/dev-compile-web @@ -0,0 +1,7 @@ +#!/bin/bash + +V=`date "+%Y%m%d_%H%M%S"` + +./compile-web-html $V dev +./compile-web-js $V dev + diff --git a/build/doWeb b/build/doWeb new file mode 100755 index 0000000..12f6b37 --- /dev/null +++ b/build/doWeb @@ -0,0 +1,3 @@ +./dev-compile-web && open -a Google\ Chrome --args --disable-web-security http://white:8000/index.html + + diff --git a/build/export b/build/export new file mode 100755 index 0000000..b8a7335 --- /dev/null +++ b/build/export @@ -0,0 +1,8 @@ +rm exported/KeyStreamServer.jar +ant -buildfile exportScripts/KeyStreamServer.xml + +rm exported/MailStreamServer.jar +ant -buildfile exportScripts/MailStreamServer.xml + +rm exported/Tools.jar +ant -buildfile exportScripts/Tools.xml diff --git a/build/exportScripts/Client.xml b/build/exportScripts/Client.xml new file mode 100644 index 0000000..3c783b4 --- /dev/null +++ b/build/exportScripts/Client.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/exportScripts/KeyStreamServer.xml b/build/exportScripts/KeyStreamServer.xml new file mode 100644 index 0000000..e740ebf --- /dev/null +++ b/build/exportScripts/KeyStreamServer.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/exportScripts/MailStreamServer.xml b/build/exportScripts/MailStreamServer.xml new file mode 100644 index 0000000..9bfe175 --- /dev/null +++ b/build/exportScripts/MailStreamServer.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/exportScripts/Service.xml b/build/exportScripts/Service.xml new file mode 100644 index 0000000..bb4194e --- /dev/null +++ b/build/exportScripts/Service.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/exportScripts/Setup.xml b/build/exportScripts/Setup.xml new file mode 100644 index 0000000..aa7a637 --- /dev/null +++ b/build/exportScripts/Setup.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/exportScripts/Tools.xml b/build/exportScripts/Tools.xml new file mode 100644 index 0000000..e724faf --- /dev/null +++ b/build/exportScripts/Tools.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/exportTools b/build/exportTools new file mode 100755 index 0000000..e36c451 --- /dev/null +++ b/build/exportTools @@ -0,0 +1,2 @@ +rm exported/Tools.jar +ant -buildfile exportScripts/Tools.xml diff --git a/build/replace_html.sed b/build/replace_html.sed new file mode 100644 index 0000000..191d7bc --- /dev/null +++ b/build/replace_html.sed @@ -0,0 +1,27 @@ +// { + r ../web/common/Link.Scripts.html + d +} + +// { + r ../web/common/Link.Meta.html + d +} + +// { + r ../web/common/Link.GWT.html + d +} + +// { + r ../web/common/Link.Scripts.SaveAs.html + d +} + + +// { + r ../web/common/Link.TestBrowser.html + d +} + + diff --git a/build/replace_html_dev.sed b/build/replace_html_dev.sed new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/build/replace_html_dev.sed @@ -0,0 +1 @@ + diff --git a/build/replace_html_prod.sed b/build/replace_html_prod.sed new file mode 100644 index 0000000..26e0ccf --- /dev/null +++ b/build/replace_html_prod.sed @@ -0,0 +1,6 @@ + +// { + r ../web/common/Link.DisableDuringBeta.html + d +} + diff --git a/build/replace_js_dev.sed b/build/replace_js_dev.sed new file mode 100644 index 0000000..0ad91be --- /dev/null +++ b/build/replace_js_dev.sed @@ -0,0 +1,6 @@ + +// { + r ../web/common/Link.ConstantsDev.html + d +} + diff --git a/build/replace_js_prod.sed b/build/replace_js_prod.sed new file mode 100644 index 0000000..8770937 --- /dev/null +++ b/build/replace_js_prod.sed @@ -0,0 +1,4 @@ +// { + r ../web/common/Link.ConstantsProd.html + d +} diff --git a/java/core/src/core/org/timepedia/exporter/client/Export.java b/java/core/src/core/org/timepedia/exporter/client/Export.java deleted file mode 100644 index 54e27c2..0000000 --- a/java/core/src/core/org/timepedia/exporter/client/Export.java +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Author: Timothy Prepscius - * License: GPLv3 Affero + keep my name in the code! - */ -package org.timepedia.exporter.client; - -public @interface Export -{ -} diff --git a/java/core/src/core/org/timepedia/exporter/client/Exportable.java b/java/core/src/core/org/timepedia/exporter/client/Exportable.java deleted file mode 100644 index 656688d..0000000 --- a/java/core/src/core/org/timepedia/exporter/client/Exportable.java +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Author: Timothy Prepscius - * License: GPLv3 Affero + keep my name in the code! - */ -package org.timepedia.exporter.client; - -public interface Exportable -{ - -} diff --git a/java/core/src/core/org/timepedia/exporter/client/NoExport.java b/java/core/src/core/org/timepedia/exporter/client/NoExport.java deleted file mode 100644 index 935dd87..0000000 --- a/java/core/src/core/org/timepedia/exporter/client/NoExport.java +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Author: Timothy Prepscius - * License: GPLv3 Affero + keep my name in the code! - */ -package org.timepedia.exporter.client; - -public @interface NoExport -{ - -} diff --git a/java/core/src/core/server/db/UserDb.java b/java/core/src/core/server/db/UserDb.java deleted file mode 100644 index 97feee8..0000000 --- a/java/core/src/core/server/db/UserDb.java +++ /dev/null @@ -1,479 +0,0 @@ -/** - * Author: Timothy Prepscius - * License: GPLv3 Affero + keep my name in the code! - */ - -package core.server.srp.db; - -import java.io.IOException; -import java.math.BigInteger; -import java.security.SecureRandom; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.sql.Timestamp; -import java.util.Date; - -import core.exceptions.CryptoException; -import core.exceptions.PublicMessageException; -import core.exceptions.UserExistsException; -import core.server.srp.db.sql.Catalog; -import core.util.LogOut; -import core.util.Pair; -import core.util.Passwords; -import core.util.Strings; -import core.util.Triple; -import core.util.Base64; - -public abstract class UserDb -{ - static LogOut log = new LogOut(UserDb.class); - - SecureRandom random = new SecureRandom(); - Catalog catalog; - - protected UserDb (Catalog catalog) - { - this.catalog = catalog; - } - - public void testCreateUser (String version, String userName) throws Exception - { - checkRoomForNewUser(); - testIllegalUserName(userName); - - if (getUser(userName)!=null) - throw new UserExistsException(); - } - - public void checkRoomForNewUser () throws Exception - { - Connection connection = openConnection(); - - try - { - PreparedStatement statement = connection.prepareStatement (catalog.getSingle(catalog.ROOM_FOR_NEW_USER)); - ResultSet results = statement.executeQuery(); - if (results.next()) - { - boolean hasRoom = results.getBoolean("room"); - if (hasRoom) - return; - } - - throw new PublicMessageException("No room for new users"); - } - finally - { - closeConnection(connection); - } - - } - - public Integer getUserId (String userName) throws IOException, SQLException - { - return getUser(userName).first; - } - - public void createUser(String version, String userName, byte[] v, byte[] s) throws Exception - { - checkRoomForNewUser(); - testIllegalUserName(userName); - - if (getUser(userName)!=null) - throw new UserExistsException(); - - Connection connection = openConnection(); - - try - { - PreparedStatement statement = connection.prepareStatement (catalog.getSingle(catalog.CREATE_USER)); - statement.setString(1, version); - statement.setString(2, userName); - statement.setString(3, Base64.encode(v)); - statement.setString(4, Base64.encode(s)); - log(statement); - - statement.executeUpdate(); - } - finally - { - closeConnection(connection); - } - } - - - public Pair > getUser (String userName) throws IOException, SQLException - { - Connection connection = openConnection(); - - Pair> result = null; - - try - { - PreparedStatement statement = connection.prepareStatement (catalog.getSingle(catalog.GET_USER)); - statement.setString(1, userName); - log(statement); - - ResultSet results = statement.executeQuery(); - if (results.next()) - { - result = - new Pair >( - results.getInt("id"), - new Triple ( - results.getString("version"), - Base64.decode(results.getString("v")), - Base64.decode(results.getString("s")) - ) - ); - } - } - finally - { - closeConnection(connection); - } - - return result; - } - - public Triple getVVS (String userName) throws IOException, SQLException - { - Triple vvs = getUser(userName).second; - return - new Triple( - vvs.first, - new BigInteger (vvs.second), - new BigInteger (vvs.third) - ); - } - - protected byte[] setMailBlock (String userName, byte[] block) throws IOException, SQLException - { - Integer id = getUser(userName).first; - - Connection connection = openConnection(); - - byte[] result = null; - - try - { - PreparedStatement statement = connection.prepareStatement (catalog.getSingle(catalog.SET_USER_MAIL_BLOCK)); - statement.setInt(1, id); - statement.setString (2, Base64.encode(block)); - log(statement); - - statement.executeUpdate(); - } - finally - { - closeConnection(connection); - } - - return result; - } - - abstract public byte[] setBlock (String userName, byte[] block) throws IOException, SQLException, CryptoException; - abstract public byte[] getBlock (String userName) throws IOException, SQLException, CryptoException; - - protected byte[] setKeyBlock (String userName, byte[] block) throws IOException, SQLException - { - Integer id = getUser(userName).first; - - Connection connection = openConnection(); - - byte[] result = null; - - try - { - PreparedStatement statement = connection.prepareStatement (catalog.getSingle(catalog.SET_USER_KEY_BLOCK)); - statement.setInt(1, id); - statement.setString (2, Base64.encode(block)); - log(statement); - - statement.executeUpdate(); - } - finally - { - closeConnection(connection); - } - - return result; - } - - protected byte[] getMailBlock (String userName) throws IOException, SQLException - { - Connection connection = openConnection(); - - byte[] result = null; - - try - { - PreparedStatement statement = connection.prepareStatement (catalog.getSingle(catalog.GET_USER_MAIL_BLOCK)); - statement.setString(1, userName); - log(statement); - - ResultSet results = statement.executeQuery(); - if (results.next()) - result = Base64.decode(results.getString("block")); - } - finally - { - closeConnection(connection); - } - - return result; - } - - public byte[] getDeletedMailBlock(String userName) throws IOException, SQLException - { - Connection connection = openConnection(); - - byte[] result = null; - - try - { - PreparedStatement statement = connection.prepareStatement (catalog.getSingle(catalog.GET_DELETED_USER_MAIL_BLOCK)); - statement.setString(1, userName); - log(statement); - - ResultSet results = statement.executeQuery(); - if (results.next()) - result = Base64.decode(results.getString("block")); - } - finally - { - closeConnection(connection); - } - - return result; - } - - public String getDeletedUser() throws IOException, SQLException - { - Connection connection = openConnection(); - - String result = null; - - try - { - PreparedStatement statement = connection.prepareStatement (catalog.getSingle(catalog.GET_DELETED_USER)); - log(statement); - - ResultSet results = statement.executeQuery(); - if (results.next()) - result = results.getString("name"); - } - finally - { - closeConnection(connection); - } - - return result; - } - - protected byte[] getKeyBlock (String userName) throws IOException, SQLException - { - Connection connection = openConnection(); - - byte[] result = null; - - try - { - PreparedStatement statement = connection.prepareStatement (catalog.getSingle(catalog.GET_USER_KEY_BLOCK)); - statement.setString(1, userName); - log(statement); - - ResultSet results = statement.executeQuery(); - if (results.next()) - result = Base64.decode(results.getString("block")); - } - finally - { - closeConnection(connection); - } - - return result; - } - - public void ensureTables() throws SQLException, IOException - { - Connection connection = openConnection(); - try - { - for (String sql : catalog.getMulti(catalog.CREATE_TABLES)) - { - PreparedStatement statement = connection.prepareStatement (sql); - log(statement); - statement.executeUpdate(); - } - } - finally - { - closeConnection(connection); - } - } - - public void rateLimitFailure (String userName) throws SQLException, IOException - { - Connection connection = openConnection(); - try - { - PreparedStatement statement = connection.prepareStatement (catalog.getSingle(catalog.GET_LAST_FAILURE)); - statement.setString(1, userName); - log(statement); - - ResultSet rs = statement.executeQuery(); - if (rs.next()) - { - Timestamp timeStamp = rs.getTimestamp("mark"); - Date now = new Date(); - - if (now.getTime() - timeStamp.getTime() < catalog.FAILURE_TIMEOUT_SECONDS * 1000) - throw new PublicMessageException ("Too many failures, try again later."); - } - } - finally - { - closeConnection(connection); - } - } - - public void markFailure (String userName) throws SQLException, IOException - { - Connection connection = openConnection(); - try - { - PreparedStatement statement = connection.prepareStatement (catalog.getSingle(catalog.MARK_FAILURE)); - statement.setString(1, userName); - statement.executeUpdate(); - } - finally - { - closeConnection(connection); - } - - } - - public void deleteUser(String userName) throws IOException, SQLException - { - Connection connection = openConnection(); - try - { - String[] texts = catalog.getMulti(catalog.DELETE); - for (String text : texts) - { - PreparedStatement statement = connection.prepareStatement (text); - statement.setString(1, userName); - - log(statement); - statement.executeUpdate(); - } - } - finally - { - closeConnection(connection); - } - } - - public void expungeUser(String userName) throws IOException, SQLException - { - Connection connection = openConnection(); - try - { - String[] texts = catalog.getMulti(catalog.EXPUNGE); - for (String text : texts) - { - PreparedStatement statement = connection.prepareStatement (text); - statement.setString(1, userName); - statement.executeUpdate(); - } - } - finally - { - closeConnection(connection); - } - } - - public Connection openConnection () throws IOException, SQLException - { - log.debug("Connecting to", catalog.CONNECTION_STRING); - return DriverManager.getConnection(catalog.CONNECTION_STRING, catalog.USER, Passwords.getPasswordFor(catalog.USER)); - } - - public void closeConnection (Connection connection) - { - try - { - if (connection != null) - connection.close(); - } - catch (Exception e) - { - e.printStackTrace(); - } - - } - public void log (Statement sql) - { - System.out.println (sql); - } - - protected void testIllegalUserName(String userName) throws Exception - { - // http://www.ietf.org/rfc/rfc2142.txt - final String[] illegalStartsWith = { - "info", - "marketing", - "sales", - "support", - - "abuse", - "noc", - "security", - - "postmaster", - "hostmaster", - "usenet", - "news", - "webmaster", - "www", - "uucp", - "ftp", - - "admin", - "system", - "root", - "test", - "root", - "hostma", - "web", - "post", - "mail", - }; - - final String[] illegalParts = { - "postmaster", - "webmaster", - "root", - "admin", - "system", - }; - - String username = userName.toLowerCase(); - for (String illegal : illegalParts) - { - if (username.indexOf(illegal) != -1) - throw new Exception("Illegal username"); - } - - for (String illegal : illegalStartsWith) - { - if (username.startsWith(illegal)) - throw new Exception("Illegal username"); - } - } -} diff --git a/java/core/src/core/server/db/sql/Catalog.java b/java/core/src/core/server/db/sql/Catalog.java deleted file mode 100644 index 7e4a9cd..0000000 --- a/java/core/src/core/server/db/sql/Catalog.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Author: Timothy Prepscius - * License: GPLv3 Affero + keep my name in the code! - */ - -package core.server.srp.db.sql; - -import java.io.IOException; -import java.sql.SQLException; - -import core.constants.ConstantsServer; -import core.util.Passwords; -import core.util.SqlCatalog; -import core.util.Streams; - - -public final class Catalog extends SqlCatalog -{ - public String CONNECTION_STRING = ConstantsServer.DBCONNECTION_PREFIX + "mail"; - public String USER = "mail"; - - public int FAILURE_TIMEOUT_SECONDS = 60; - - public final String - CREATE_TABLES = "create_tables", - CREATE_USER = "create_user", - GET_USER = "get_user", - GET_USER_MAIL_BLOCK = "get_user_mail_block", - SET_USER_MAIL_BLOCK = "set_user_mail_block", - GET_USER_KEY_BLOCK = "get_user_key_block", - SET_USER_KEY_BLOCK = "set_user_key_block", - GET_LAST_FAILURE = "get_last_failure", - MARK_FAILURE = "mark_failure", - - DELETE = "delete_user.sql", - EXPUNGE = "expunge_deleted_user.sql", - GET_DELETED_USER = "get_deleted_user.sql", - GET_DELETED_USER_MAIL_BLOCK = "get_deleted_user_mail_block.sql", - - ROOM_FOR_NEW_USER = "room_for_new_user"; - - public Catalog () - { - - } - - public String getPassword () throws IOException - { - return Passwords.getPasswordFor(USER); - } -} diff --git a/java/core/src/core/server/db/sql/create_tables b/java/core/src/core/server/db/sql/create_tables deleted file mode 100644 index ecd8894..0000000 --- a/java/core/src/core/server/db/sql/create_tables +++ /dev/null @@ -1,55 +0,0 @@ -CREATE TABLE IF NOT EXISTS registry ( - k VARCHAR(50), - v VARCHAR(255), - mark TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (k) -); - -INSERT IGNORE INTO registry (k,v) VALUES ("max_users", "1000"); - -CREATE TABLE IF NOT EXISTS user ( - version VARCHAR(50), - id INTEGER AUTO_INCREMENT, - name VARCHAR(255) COLLATE utf8_general_ci NOT NULL DEFAULT '', - v TEXT, - s TEXT, - mark TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (name), - UNIQUE KEY (id) -); - -CREATE TABLE IF NOT EXISTS mail_block ( - user_id INTEGER, - block TEXT, - mark TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (user_id) -); - -CREATE TABLE IF NOT EXISTS key_block ( - user_id INTEGER, - block TEXT, - mark TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (user_id) -); - -CREATE TABLE IF NOT EXISTS failure ( - user_id INTEGER, - mark TIMESTAMP, - PRIMARY KEY (user_id) -); - -CREATE TABLE IF NOT EXISTS deleted_user ( - version VARCHAR(50), - id INTEGER AUTO_INCREMENT, - name VARCHAR(255) COLLATE utf8_general_ci NOT NULL DEFAULT '', - v TEXT, - s TEXT, - mark TIMESTAMP NULL DEFAULT NULL, - deleted TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (id) -); - -CREATE TABLE IF NOT EXISTS deleted_mail_block LIKE mail_block; -CREATE TABLE IF NOT EXISTS deleted_key_block LIKE key_block; -DROP TABLE IF EXISTS metadata; - \ No newline at end of file diff --git a/java/core/src/core/server/db/sql/create_user b/java/core/src/core/server/db/sql/create_user deleted file mode 100644 index 65db5c4..0000000 --- a/java/core/src/core/server/db/sql/create_user +++ /dev/null @@ -1 +0,0 @@ -INSERT INTO user (version, name, v, s) VALUES (?, ?, ?, ?) \ No newline at end of file diff --git a/java/core/src/core/server/db/sql/delete_user.sql b/java/core/src/core/server/db/sql/delete_user.sql deleted file mode 100644 index 6e4c106..0000000 --- a/java/core/src/core/server/db/sql/delete_user.sql +++ /dev/null @@ -1,24 +0,0 @@ -REPLACE INTO deleted_mail_block - SELECT mail_block.* - FROM mail_block, user - WHERE user.name=? AND mail_block.user_id = user.id; - -REPLACE INTO deleted_key_block - SELECT key_block.* - FROM key_block, user - WHERE user.name=? AND key_block.user_id = user.id; - -REPLACE INTO deleted_user(version, id, name, v, s, mark) - SELECT version, id, name, v, s, mark - FROM user - WHERE user.name=?; - -DELETE mail_block.* - FROM mail_block, user - WHERE user.name=? AND mail_block.user_id = user.id; - -DELETE key_block.* - FROM key_block, user - WHERE user.name=? AND key_block.user_id = user.id; - -DELETE FROM user WHERE user.name=? \ No newline at end of file diff --git a/java/core/src/core/server/db/sql/expunge_deleted_user.sql b/java/core/src/core/server/db/sql/expunge_deleted_user.sql deleted file mode 100644 index 9231dae..0000000 --- a/java/core/src/core/server/db/sql/expunge_deleted_user.sql +++ /dev/null @@ -1,9 +0,0 @@ -DELETE deleted_mail_block.* - FROM deleted_mail_block, deleted_user - WHERE deleted_user.name=? AND deleted_mail_block.user_id = deleted_user.id; - -DELETE deleted_key_block.* - FROM deleted_key_block, deleted_user - WHERE deleted_user.name=? AND deleted_key_block.user_id = deleted_user.id; - -DELETE FROM deleted_user WHERE deleted_user.name=? \ No newline at end of file diff --git a/java/core/src/core/server/db/sql/get_deleted_user.sql b/java/core/src/core/server/db/sql/get_deleted_user.sql deleted file mode 100644 index 3dac938..0000000 --- a/java/core/src/core/server/db/sql/get_deleted_user.sql +++ /dev/null @@ -1,7 +0,0 @@ -select - * -from - deleted_user -order by - deleted -limit 1 \ No newline at end of file diff --git a/java/core/src/core/server/db/sql/get_deleted_user_mail_block.sql b/java/core/src/core/server/db/sql/get_deleted_user_mail_block.sql deleted file mode 100644 index 222f5b7..0000000 --- a/java/core/src/core/server/db/sql/get_deleted_user_mail_block.sql +++ /dev/null @@ -1,8 +0,0 @@ -SELECT - deleted_mail_block.* -FROM - deleted_user, - deleted_mail_block -WHERE - deleted_mail_block.user_id = deleted_user.id AND - deleted_user.name = ? \ No newline at end of file diff --git a/java/core/src/core/server/db/sql/get_last_failure b/java/core/src/core/server/db/sql/get_last_failure deleted file mode 100644 index 34f1ae7..0000000 --- a/java/core/src/core/server/db/sql/get_last_failure +++ /dev/null @@ -1,8 +0,0 @@ -SELECT - failure.mark -FROM - user, - failure -WHERE - user.name = ? AND - failure.user_id = user.id \ No newline at end of file diff --git a/java/core/src/core/server/db/sql/get_user b/java/core/src/core/server/db/sql/get_user deleted file mode 100644 index 90c2ac7..0000000 --- a/java/core/src/core/server/db/sql/get_user +++ /dev/null @@ -1,6 +0,0 @@ -SELECT - * -FROM - user -WHERE - user.name = ? diff --git a/java/core/src/core/server/db/sql/get_user_key_block b/java/core/src/core/server/db/sql/get_user_key_block deleted file mode 100644 index 99494fc..0000000 --- a/java/core/src/core/server/db/sql/get_user_key_block +++ /dev/null @@ -1,8 +0,0 @@ -SELECT - key_block.* -FROM - user, - key_block -WHERE - key_block.user_id = user.id AND - user.name = ? \ No newline at end of file diff --git a/java/core/src/core/server/db/sql/get_user_mail_block b/java/core/src/core/server/db/sql/get_user_mail_block deleted file mode 100644 index a37c5bd..0000000 --- a/java/core/src/core/server/db/sql/get_user_mail_block +++ /dev/null @@ -1,8 +0,0 @@ -SELECT - mail_block.* -FROM - user, - mail_block -WHERE - mail_block.user_id = user.id AND - user.name = ? \ No newline at end of file diff --git a/java/core/src/core/server/db/sql/mark_failure b/java/core/src/core/server/db/sql/mark_failure deleted file mode 100644 index baebf51..0000000 --- a/java/core/src/core/server/db/sql/mark_failure +++ /dev/null @@ -1,8 +0,0 @@ -REPLACE INTO failure (user_id, mark) -SELECT - id as user_id, - now() as mark -FROM - user -WHERE - name = ? \ No newline at end of file diff --git a/java/core/src/core/server/db/sql/room_for_new_user b/java/core/src/core/server/db/sql/room_for_new_user deleted file mode 100644 index c72a6b4..0000000 --- a/java/core/src/core/server/db/sql/room_for_new_user +++ /dev/null @@ -1,4 +0,0 @@ -select - count(*) < (select convert(v, unsigned integer) from registry where k="max_users") as room -from - user \ No newline at end of file diff --git a/java/core/src/core/server/db/sql/set_user_key_block b/java/core/src/core/server/db/sql/set_user_key_block deleted file mode 100644 index 4f8e6e8..0000000 --- a/java/core/src/core/server/db/sql/set_user_key_block +++ /dev/null @@ -1 +0,0 @@ -REPLACE INTO key_block (user_id, block) VALUES (?, ?) \ No newline at end of file diff --git a/java/core/src/core/server/db/sql/set_user_mail_block b/java/core/src/core/server/db/sql/set_user_mail_block deleted file mode 100644 index 3bcd3ab..0000000 --- a/java/core/src/core/server/db/sql/set_user_mail_block +++ /dev/null @@ -1 +0,0 @@ -REPLACE INTO mail_block (user_id, block) VALUES (?, ?) \ No newline at end of file