adds the app tools

This commit is contained in:
Timothy Prepscius 2013-07-17 18:47:42 -04:00
parent 00199a0635
commit 9aa9af7e51
18 changed files with 1027 additions and 0 deletions

18
java/app/tools/.classpath Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mailiverse.Core"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mailiverse.Ext.BouncyCastle"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mailiverse.Ext.JordanZimmerman"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mailiverse.Ext.Json"/>
<classpathentry kind="lib" path="lib/dropbox-java-sdk-1.3.jar"/>
<classpathentry kind="lib" path="lib/json_simple-1.1.jar"/>
<classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/>
<classpathentry kind="lib" path="lib/mysql-connector-java-3.1.14-bin.jar"/>
<classpathentry kind="lib" path="lib/slf4j-api-1.3.1.jar"/>
<classpathentry kind="lib" path="lib/slf4j-simple-1.3.1.jar"/>
<classpathentry kind="lib" path="lib/JavaPNS_2.2.jar"/>
<classpathentry kind="lib" path="lib/bcprov-jdk15on-148.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

17
java/app/tools/.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Mailiverse.App.Tools</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

1
java/app/tools/lib Symbolic link
View File

@ -0,0 +1 @@
../../lib

View File

@ -0,0 +1,47 @@
/**
* Author: Timothy Prepscius
* License: GPLv3 Affero + keep my name in the code!
*/
package app.tools;
import java.util.HashMap;
import java.util.Map;
public class Arguments
{
public static Map<String,String> map (String[] s, int offset)
{
Map<String,String> map = new HashMap<String,String>();
for (int i=offset; i<s.length; ++i)
{
String kv = s[i];
String k, v=null;
if (kv.matches(".*=.*"))
{
k = kv.replaceAll("(.*)=(.*)", "$1");
v = kv.replaceAll("(.*)=(.*)", "$2");
}
else
k = kv;
map.put(k.toLowerCase(),v);
}
return map;
}
public static boolean containsAll(Map<String,String> kv, String[] keys)
{
for (String k : keys)
{
if (!kv.containsKey(k))
return false;
}
return true;
}
}

View File

@ -0,0 +1,14 @@
/**
* Author: Timothy Prepscius
* License: GPLv3 Affero + keep my name in the code!
*/
package app.tools;
public class CheckUsersAndScheduleForDeletion
{
public static void main(String[] args)
{
}
}

View File

@ -0,0 +1,136 @@
/**
* Author: Timothy Prepscius
* License: GPLv3 Affero + keep my name in the code!
*/
package app.tools;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import key.auth.KeyServerAuthenticatorSync;
import mail.server.util.JavaMailToJSON;
import core.connector.FileInfo;
import core.connector.dropbox.ClientInfoDropbox;
import core.connector.dropbox.sync.DropboxConnector;
import core.connector.s3.ClientInfoS3;
import core.connector.s3.sync.S3Connector;
import core.connector.sync.EncryptedStoreConnector;
import core.connector.sync.StoreConnector;
import core.constants.ConstantsEnvironmentKeys;
import core.constants.ConstantsServer;
import core.constants.ConstantsStorage;
import core.crypt.CryptorRSAAES;
import core.crypt.CryptorRSAFactoryEnvironment;
import core.util.Environment;
public class ConvertAccountMailToJson
{
public static void convert (String name, String password, boolean overwrite) throws Exception
{
KeyServerAuthenticatorSync auth = new KeyServerAuthenticatorSync("YOUR_SERVER", ConstantsServer.KEY_AUTH_PORT);
Environment environment = auth.get(name, password, null);
Environment clientEnv = environment.childEnvironment(ConstantsEnvironmentKeys.CLIENT_ENVIRONMENT);
String handlerName = clientEnv.get(ConstantsEnvironmentKeys.HANDLER);
StoreConnector storeConnector = null;
if (handlerName.equals(ConstantsStorage.HANDLER_S3))
{
storeConnector =
new S3Connector(
new ClientInfoS3(clientEnv.childEnvironment(ConstantsStorage.HANDLER_S3)
)
);
}
else
{
storeConnector =
new DropboxConnector(
new ClientInfoDropbox(clientEnv.childEnvironment(ConstantsStorage.HANDLER_DROPBOX)
)
);
}
StoreConnector connector = new EncryptedStoreConnector(
new CryptorRSAAES(CryptorRSAFactoryEnvironment.create(clientEnv)),
storeConnector
);
connector.open();
connector.ensureDirectories(ConstantsStorage.NEW_IN_JSON, ConstantsStorage.NEW_OUT_JSON);
List<FileInfo> inList = connector.listDirectory(ConstantsStorage.NEW_IN);
List<FileInfo> outList = connector.listDirectory(ConstantsStorage.NEW_OUT);
List<FileInfo> inListJson = connector.listDirectory(ConstantsStorage.NEW_IN_JSON);
List<FileInfo> outListJson = connector.listDirectory(ConstantsStorage.NEW_OUT_JSON);
/*
for (FileInfo i : inList)
i.path = ConstantsStorage.NEW_IN + i.path;
for (FileInfo i : outList)
i.path = ConstantsStorage.NEW_OUT + i.path;
*/
ArrayList<FileInfo> all = new ArrayList<FileInfo>();
all.addAll(inList);
all.addAll(outList);
Collections.sort(all, new FileInfo.SortByDateAscending());
Set<String> jsons = new HashSet<String>();
for (FileInfo i : inListJson)
jsons.add(i.relativePath.substring(i.relativePath.indexOf("_")+1));
for (FileInfo i : outListJson)
jsons.add(i.relativePath.substring(i.relativePath.indexOf("_")+1));
JavaMailToJSON converter = new JavaMailToJSON();
for (FileInfo i : all)
{
System.out.print("handling " + i.path);
if (i.path.indexOf(ConstantsStorage.JSON)!=-1)
{
System.out.println(" is json, continuing.");
continue;
}
String jsonPath = i.relativePath.substring(i.relativePath.indexOf('_') + 1);
if (jsons.contains(jsonPath) && !overwrite)
{
System.out.println(" has json counterpart, specify overwrite to overwrite.");
continue;
}
System.out.print(" reading");
byte[] raw = connector.get(i.path);
System.out.print(", converting");
byte[] json = converter.convert(i.path, i.date, raw, new JavaMailToJSON.MailDescription());
System.out.print(", writing");
String datePath =
(i.relativePath.contains("_")) ?
i.relativePath :
i.date.getTime() + "_" + i.relativePath;
String jsonFileName = i.path.contains(ConstantsStorage.IN) ?
(ConstantsStorage.NEW_IN_JSON + "/" + datePath) :
(ConstantsStorage.NEW_OUT_JSON + "/" + datePath);
System.out.print(" to " + jsonFileName);
connector.put(jsonFileName, json);
System.out.println(" : finished");
}
System.out.println("closing");
connector.close();
}
}

View File

@ -0,0 +1,66 @@
/**
* Author: Timothy Prepscius
* License: GPLv3 Affero + keep my name in the code!
*/
package app.tools;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Date;
import key.auth.KeyServerAuthenticatorSync;
import mail.server.util.JavaMailToJSON;
import core.crypt.CryptorRSAAES;
import core.crypt.CryptorRSAFactoryEnvironment;
import core.util.Environment;
import core.util.Streams;
import core.util.Zip;
public class ConvertFileMailToJson
{
public static void main(String[] args) throws Exception
{
String name = args[0];
String password = args[1];
KeyServerAuthenticatorSync auth = new KeyServerAuthenticatorSync();
Environment e = auth.get(name, password, null);
CryptorRSAAES rsa = new CryptorRSAAES(CryptorRSAFactoryEnvironment.create(e.childEnvironment("client")));
JavaMailToJSON converter = new JavaMailToJSON();
for (int i=2; i<args.length; ++i)
{
String fileName = args[i];
String fileNameOut = fileName + ".json";
System.out.print(fileName + " ... ");
FileInputStream fis = new FileInputStream(fileName);
byte[] bytes_ = Streams.readFullyBytes(fis);
fis.close();
byte[] bytes = Zip.inflate(rsa.decrypt(bytes_));
try
{
byte[] json = converter.convertAttemptToShowException(fileName, new Date(), bytes, new JavaMailToJSON.MailDescription());
byte[] json_ = rsa.encrypt(Zip.deflate(json));
FileOutputStream fos = new FileOutputStream(fileNameOut);
fos.write(json_);
fos.close();
System.out.println("finished.");
}
catch (Exception exception)
{
exception.printStackTrace();
System.out.println("Full:\n" + new String(bytes));
}
}
}
}

View File

@ -0,0 +1,111 @@
package app.tools;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import core.connector.FileInfo;
import core.connector.dropbox.ClientInfoDropbox;
import core.connector.dropbox.sync.DropboxConnector;
import core.connector.s3.ClientInfoS3;
import core.connector.s3.sync.S3Connector;
import core.connector.sync.EncryptedStoreConnector;
import core.connector.sync.StoreConnector;
import core.constants.ConstantsEnvironmentKeys;
import core.constants.ConstantsStorage;
import core.crypt.CryptorRSAAES;
import core.crypt.CryptorRSAFactoryEnvironment;
import core.util.Environment;
import core.util.Pair;
import key.auth.KeyServerAuthenticatorSync;
public class DecryptMailToFileSystem
{
public static void main (String[] _args) throws Exception
{
_args = new String[] { "name=SOMENAME@mailiverse.com", "password=SOMEPASSWORD", "out=." };
Map<String,String> args = Arguments.map(_args, 0);
String name = args.get("name");
String password = args.get("password");
String out = args.get("out");
if (name == null || password == null || out == null)
throw new IllegalArgumentException();
KeyServerAuthenticatorSync key = new KeyServerAuthenticatorSync();
Environment environment = key.get(name, password, null);
Environment clientEnv = environment.childEnvironment(ConstantsEnvironmentKeys.CLIENT_ENVIRONMENT);
String handlerName = clientEnv.get(ConstantsEnvironmentKeys.HANDLER);
StoreConnector storeConnector = null;
if (handlerName.equals(ConstantsStorage.HANDLER_S3))
{
storeConnector =
new S3Connector(
new ClientInfoS3(clientEnv.childEnvironment(ConstantsStorage.HANDLER_S3)
)
);
}
else
{
storeConnector =
new DropboxConnector(
new ClientInfoDropbox(clientEnv.childEnvironment(ConstantsStorage.HANDLER_DROPBOX)
)
);
}
StoreConnector connector = new EncryptedStoreConnector(
new CryptorRSAAES(CryptorRSAFactoryEnvironment.create(clientEnv)),
storeConnector
);
connector.open();
String[] dirs = new String[] {
ConstantsStorage.NEW_IN, ConstantsStorage.NEW_OUT,
ConstantsStorage.NEW_IN_JSON, ConstantsStorage.NEW_OUT_JSON
};
List<FileInfo> all = new ArrayList<FileInfo>();
for (String dir : dirs)
{
List<FileInfo> list = connector.listDirectory(dir);
all.addAll(list);
}
Collections.sort(all, new FileInfo.SortByDateAscending());
for (FileInfo f : all)
{
if (f.relativePath.contains(".lock"))
continue;
System.out.print("reading " + f.path);
byte[] block = connector.get(f.path);
String directory = out + "/" + f.path;
directory = directory.substring(0, directory.lastIndexOf('/'));
System.out.print(" ["+directory+"]");
new File(directory).mkdirs();
String outPath= out + "/" + f.path;
System.out.print(" writing " + outPath);
FileOutputStream of = new FileOutputStream (outPath);
of.write(block);
of.close();
System.out.println(" done.");
}
}
}

View File

@ -0,0 +1,40 @@
/**
* Author: Timothy Prepscius
* License: GPLv3 Affero + keep my name in the code!
*/
package app.tools;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.security.KeyStore;
import java.security.PublicKey;
import java.util.Map;
import core.util.Base64;
public class ExportPem {
public static void main (String[] args) throws Exception
{
Map<String,String> a = Arguments.map(args, 1);
if (!Arguments.containsAll(a, new String[] { "file"}))
throw new IllegalArgumentException();
String fileNameIn = a.get("file");
FileInputStream in = new FileInputStream(fileNameIn);
KeyStore tks = KeyStore.getInstance("JKS");
tks.load(in, "password".toCharArray());
PublicKey publicKey = tks.getCertificate(tks.aliases().nextElement()).getPublicKey();
byte[] bytes = publicKey.getEncoded();
String fileNameOut = fileNameIn + ".pem.b64";
FileWriter out = new FileWriter (fileNameOut);
out.write(Base64.encode(bytes));
out.close();
}
}

View File

@ -0,0 +1,76 @@
/**
* Author: Timothy Prepscius
* License: GPLv3 Affero + keep my name in the code!
*/
package app.tools;
import java.util.Map;
import core.connector.s3.ClientInfoS3;
import core.constants.ConstantsEnvironmentKeys;
import core.constants.ConstantsStorage;
import core.util.Environment;
import core.util.LogOut;
import mail.server.db.MailUserDb;
import mail.server.storage.AWSStorageDelete;
public class ExpungeDeletedUsers
{
static LogOut log = new LogOut(ExpungeDeletedUsers.class);
public static void main (String[] _args) throws Exception
{
Map<String,String> args = Arguments.map(_args,0);
ExpungeDeletedUsers expunger = new ExpungeDeletedUsers();
String num = args.get("num");
if (num == null)
num = "-1";
expunger.expungeQueue(Integer.parseInt(num), args.containsKey("force"));
}
public void expungeQueue(int maxToExpunge, boolean force) throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
MailUserDb mailUserDb;
mailUserDb = new MailUserDb();
String user;
AWSStorageDelete deletion = new AWSStorageDelete();
while (maxToExpunge-- != 0 && (user = mailUserDb.getDeletedUser()) != null)
{
try
{
Environment e = mailUserDb.getDeletedUserEnvironment(user);
if (e.containsKey(ConstantsEnvironmentKeys.HANDLER) && e.get(ConstantsEnvironmentKeys.HANDLER).equals(ConstantsStorage.HANDLER_S3))
{
ClientInfoS3 clientInfo = new ClientInfoS3(e.childEnvironment(ConstantsStorage.HANDLER_S3));
deletion.delete(clientInfo.getBucketName());
}
}
catch (Exception e)
{
if (!force)
throw e;
log.exception(e);
}
try
{
mailUserDb.expungeUser(user);
}
catch (Exception e)
{
if (!force)
throw e;
log.exception(e);
}
}
}
}

View File

@ -0,0 +1,34 @@
/**
* Author: Timothy Prepscius
* License: GPLv3 Affero + keep my name in the code!
*/
package app.tools;
import java.util.Map;
import core.util.Passwords;
import mail.server.storage.AWSStorageDelete;
public class ExpungeS3User
{
public static void main(String[] _args) throws Exception
{
Map<String, String> args = Arguments.map(_args, 0);
String accessKey = args.get("accesskey");
String secretKey = args.get("secretkey");
String bucketName = args.get("bucketname");
if (bucketName == null)
throw new IllegalArgumentException();
AWSStorageDelete deleter = new AWSStorageDelete();
if (accessKey == null && secretKey == null)
deleter.delete(bucketName);
else
deleter.delete(bucketName, accessKey, secretKey);
}
}

View File

@ -0,0 +1,283 @@
/**
* Author: Timothy Prepscius
* License: GPLv3 Affero + keep my name in the code!
*/
package app.tools;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import mail.auth.MailServerAuthenticatorSync;
import com.dropbox.client2.session.AccessTokenPair;
import com.dropbox.client2.session.AppKeyPair;
import core.connector.dropbox.sync.DropboxSignup;
import core.constants.ConstantsClient;
import core.constants.ConstantsDropbox;
import core.constants.ConstantsEnvironmentKeys;
import core.constants.ConstantsServer;
import core.constants.ConstantsStorage;
import core.util.Environment;
import core.util.JSONSerializer;
import core.util.LogNull;
import core.util.LogOut;
import core.util.Streams;
import key.auth.KeyServerAuthenticatorSync;
public class Main
{
static LogNull log = new LogNull(Main.class);
public static void usage (Exception e) throws Exception
{
System.out.println(
"Usage: java -jar Tools.jar [action] [args]" + "\n" +
" --help this screen" + "\n" +
" --get-environment name=x password=Y file=Z" + "\n" +
" --put-environment name=x password=Y file=Z" + "\n" +
" --dropbox-authorize name=X password=Y" + "\n" +
" --change-password name=X password=Y new-password=Z" + "\n" +
" --delete name=X password=Y" + "\n" +
" --convert-account-mail-to-json name=X password=Y [overwrite]" + "\n" +
" --export-pem file=X" + "\n" +
" --expunge-deleted-users [force]" + "\n" +
" --expunge-s3-user accessKey=[] secretKey=[] bucketName=[]" + "\n" +
" --schedule-user-for-deletion user=name" + "\n" +
" --show-user-mail-block user=name" + "\n" +
" --show-user-key-block user=name password=password" + "\n" +
" --decryptMailToFileSystem name=name password=password out=outpath" + "\n" +
" --sendPushNotificationForDevice device=id" + "\n" +
" --sendPushNotificationForUser user=email" + "\n" +
""
);
if (e != null)
{
System.out.println(e);
throw e;
}
}
public static void main (String[] args) throws Exception
{
System.out.println(new Date());
try
{
if (args.length == 0)
{
usage(null);
return;
}
else
{
String c = args[0].toLowerCase();
if (c.equalsIgnoreCase("--help"))
usage(null);
else
if (c.equalsIgnoreCase("--dropbox-authorize"))
dropboxAuthorize(args);
else
if (c.equalsIgnoreCase("--get-environment"))
getEnvironment(args);
else
if (c.equalsIgnoreCase("--put-environment"))
putEnvironment(args);
else
if (c.equalsIgnoreCase("--change-password"))
changePassword(args);
else
if (c.equalsIgnoreCase("--delete"))
delete(args);
else
if (c.equalsIgnoreCase("--convert-account-mail-to-json"))
convertAccountMailToJson(args);
else
if (c.equalsIgnoreCase("--export-pem"))
ExportPem.main(args);
else
if (c.equalsIgnoreCase("--expunge-deleted-users"))
ExpungeDeletedUsers.main(args);
else
if (c.equalsIgnoreCase("--expunge-s3-user"))
ExpungeS3User.main(args);
else
if (c.equalsIgnoreCase("--schedule-user-for-deletion"))
ScheduleUserForDeletion.main(args);
else
if (c.equalsIgnoreCase("--show-user-mail-block"))
ShowUserMailBlock.main(args);
else
if (c.equalsIgnoreCase("--show-user-key-block"))
ShowUserKeyBlock.main(args);
else
if (c.equalsIgnoreCase("--decryptMailToFileSystem"))
DecryptMailToFileSystem.main(args);
else
if (c.equalsIgnoreCase("--sendPushNotificationForDevice"))
SendPushNotificationForDevice.main(args);
else
if (c.equalsIgnoreCase("--sendPushNotificationForUser"))
SendPushNotificationForUser.main(args);
else
throw new IllegalArgumentException("Unknown command " + c);
}
}
catch (IllegalArgumentException e)
{
usage(e);
}
catch (Exception e)
{
System.err.println("Caught " + e);
throw e;
}
System.out.println(new Date());
}
public static void convertAccountMailToJson(String[] args) throws Exception
{
Map<String,String> a = Arguments.map(args, 1);
if (!Arguments.containsAll(a, new String[] {"name", "password"}))
throw new IllegalArgumentException();
String name = a.get("name") + ConstantsClient.ATHOST;
String password = a.get("password");
boolean overwrite = a.containsKey("overwrite");
ConvertAccountMailToJson.convert(name, password, overwrite);
}
public static void dropboxAuthorize (String[] args) throws Exception
{
Map<String,String> a = Arguments.map(args, 1);
if (!Arguments.containsAll(a, new String[] {"name", "password"}))
throw new IllegalArgumentException();
PrintStream out = System.out;
String name = a.get("name") + ConstantsClient.ATHOST;
String password = a.get("password");
out.println("Getting existing environment");
KeyServerAuthenticatorSync keyServer = new KeyServerAuthenticatorSync();
MailServerAuthenticatorSync mailServer = new MailServerAuthenticatorSync();
Environment e = keyServer.get(name, password, null);
out.println("Requesting access token");
AppKeyPair appToken = new AppKeyPair(ConstantsClient.DROPBOX_APPKEY, ConstantsClient.DROPBOX_APPSECRET);
AccessTokenPair requestToken = DropboxSignup.getDropboxRequestToken(appToken);
out.println("Please open in a web browser: " +
ConstantsClient.DROPBOX_AUTH_URL.replace("REQUEST_TOKEN_KEY", requestToken.key)
);
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
out.print ("Enter the authorization code recieved: ");
String authCode = in.readLine();
if (!authCode.equals(requestToken.key))
throw new Exception("Invalid authentication code");
out.println("Requesting access token");
AccessTokenPair accessToken = DropboxSignup.getDropboxAccessToken(appToken, requestToken);
out.println("Setting new environment variables");
String handler = ConstantsStorage.HANDLER_DROPBOX;
String prefix = handler + "/";
String client = ConstantsEnvironmentKeys.CLIENT_ENVIRONMENT + "/";
e.put(client + prefix + ConstantsDropbox.DropboxUserPrefix, name);
e.put(client + prefix + ConstantsDropbox.DropboxAppKey, appToken.key);
e.put(client + prefix + ConstantsDropbox.DropboxAppSecret, appToken.secret);
e.put(client + prefix + ConstantsDropbox.DropboxTokenKey, accessToken.key);
e.put(client + prefix + ConstantsDropbox.DropboxTokenSecret, accessToken.secret);
String server = ConstantsEnvironmentKeys.SERVER_ENVIRONMENT + "/";
e.put(server + prefix + ConstantsDropbox.DropboxUserPrefix, name);
e.put(server + prefix + ConstantsDropbox.DropboxAppKey, appToken.key);
e.put(server + prefix + ConstantsDropbox.DropboxAppSecret, appToken.secret);
e.put(server + prefix + ConstantsDropbox.DropboxTokenKey, accessToken.key);
e.put(server + prefix + ConstantsDropbox.DropboxTokenSecret, accessToken.secret);
out.println("putting environment into keyserver");
keyServer.put(name, password, e, null);
out.println("putting server environment into mailserver");
mailServer.put(name, password, e.childEnvironment(ConstantsEnvironmentKeys.SERVER_ENVIRONMENT));
out.println("finished");
}
public static void getEnvironment (String args[]) throws Exception
{
PrintStream out = System.out;
out.println("Getting existing environment");
KeyServerAuthenticatorSync keyServer = new KeyServerAuthenticatorSync();
Map<String,String> a = Arguments.map(args, 1);
if (!Arguments.containsAll(a, new String[] {"name", "password", "file"}))
throw new IllegalArgumentException();
String name = a.get("name");
String password = a.get("password");
String fileName = a.get("file");
Environment e = keyServer.get(name, password, null);
FileWriter writer = new FileWriter(fileName);
writer.write(new String(JSONSerializer.serialize(e)));
writer.flush();
writer.close();
out.println("finished");
}
public static void putEnvironment (String args[]) throws Exception
{
PrintStream out = System.out;
out.println("Putting existing environment");
KeyServerAuthenticatorSync keyServer = new KeyServerAuthenticatorSync();
MailServerAuthenticatorSync mailServer = new MailServerAuthenticatorSync();
Map<String,String> a = Arguments.map(args, 1);
if (!Arguments.containsAll(a, new String[] {"name", "password", "file"}))
throw new IllegalArgumentException();
String name = a.get("name");
String password = a.get("password");
String fileName = a.get("file");
FileInputStream in = new FileInputStream (fileName);
Environment e = JSONSerializer.deserialize(Streams.readFullyBytes(in));
in.close();
out.println("putting keyserver");
keyServer.put(name, password, e, null);
out.println("putting mailserver");
mailServer.put(name, password, e.childEnvironment(ConstantsEnvironmentKeys.SERVER_ENVIRONMENT));
out.println("finished");
}
public static void changePassword (String[] args)
{
}
public static void delete(String[] args)
{
}
}

View File

@ -0,0 +1,11 @@
/**
* Author: Timothy Prepscius
* License: GPLv3 Affero + keep my name in the code!
*/
package app.tools;
public class RemoveErrantJamesUsers
{
}

View File

@ -0,0 +1,25 @@
/**
* Author: Timothy Prepscius
* License: GPLv3 Affero + keep my name in the code!
*/
package app.tools;
import java.io.IOException;
import java.sql.SQLException;
import core.exceptions.CryptoException;
import mail.server.db.MailUserDb;
import mail.streamserver.MailServerSessionDb;
public class ScheduleUserForDeletion
{
public static void main (String[] args) throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
String user = Arguments.map(args, 0).get("user");
MailServerSessionDb db = new MailServerSessionDb(new MailUserDb());
db.deleteUser(user);
}
}

View File

@ -0,0 +1,25 @@
package app.tools;
import java.util.Map;
import mail.server.push.ApplePushService;
public class SendPushNotificationForDevice
{
public static void main (String[] _args)
{
Map<String,String> args = Arguments.map(_args, 0);
String deviceType = "ios";
String deviceId = args.get("device");
if (deviceId == null)
throw new IllegalArgumentException();
System.out.println ("Sending push notification to: " + deviceId);
ApplePushService pusher = new ApplePushService();
pusher.notifyUserOfEmail(deviceId, "author", "subject", "body");
pusher.shutdown();
}
}

View File

@ -0,0 +1,35 @@
/**
* Author: Timothy Prepscius
* License: GPLv3 Affero + keep my name in the code!
*/
package app.tools;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Map;
import mail.server.push.ApplePushService;
import mail.server.push.PushDispatcher;
public class SendPushNotificationForUser
{
public static void main (String[] _args) throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
Map<String,String> args = Arguments.map(_args, 0);
String user = args.get("user");
if (user == null)
throw new IllegalArgumentException();
System.out.println ("Sending push notification to: " + user);
PushDispatcher pusher = new PushDispatcher();
pusher.notifyUserOfEmail(user, "author@somehow.com", "subject", "body");
pusher.shutdown();
}
}

View File

@ -0,0 +1,50 @@
/**
* Author: Timothy Prepscius
* License: GPLv3 Affero + keep my name in the code!
*/
package app.tools;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Map;
import java.util.Map.Entry;
import key.server.sql.KeyUserDb;
import core.crypt.KeyPairFromPassword;
import core.crypt.KeyPairFromPasswordCryptor;
import core.exceptions.CryptoException;
import core.util.Environment;
import core.util.JSONSerializer;
import core.util.Zip;
public class ShowUserKeyBlock
{
public static void main (String[] _args) throws CryptoException, IOException, SQLException, ClassNotFoundException
{
Class.forName("com.mysql.jdbc.Driver");
Map<String,String> args = Arguments.map(_args,0);
String user = args.get("user");
String password = args.get("password");
if (user == null || password == null)
throw new IllegalArgumentException();
KeyPairFromPassword keyPair = new KeyPairFromPassword(password);
keyPair.generate();
KeyPairFromPasswordCryptor cryptor = new KeyPairFromPasswordCryptor(keyPair);
KeyUserDb db = new KeyUserDb();
byte[] encryptedBlock = db.getBlock(user);
byte[] block = Zip.inflate(cryptor.decrypt(encryptedBlock));
Environment e = JSONSerializer.deserialize(block);
for (Entry<String, String> i : e.entrySet())
{
System.out.println(i.getKey() + ":" + i.getValue());
}
}
}

View File

@ -0,0 +1,38 @@
/**
* Author: Timothy Prepscius
* License: GPLv3 Affero + keep my name in the code!
*/
package app.tools;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Map;
import java.util.Map.Entry;
import core.exceptions.CryptoException;
import core.util.Environment;
import core.util.JSONSerializer;
import mail.server.db.MailUserDb;
public class ShowUserMailBlock
{
public static void main (String[] _args) throws CryptoException, IOException, SQLException, ClassNotFoundException
{
Class.forName("com.mysql.jdbc.Driver");
Map<String,String> args = Arguments.map(_args,0);
String user = args.get("user");
if (user == null)
throw new IllegalArgumentException();
MailUserDb db = new MailUserDb();
byte[] block = db.getBlock(user);
Environment e = JSONSerializer.deserialize(block);
for (Entry<String, String> i : e.entrySet())
{
System.out.println(i.getKey() + ":" + i.getValue());
}
}
}