// You may not use this file except in compliance with the License.
package org.ibex.mail;
-import org.ibex.mail.target.*;
-import org.ibex.mail.protocol.*;
import org.ibex.util.*;
import org.ibex.jetty.*;
import org.ibex.io.*;
+import org.ibex.net.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocket;
+// restrict the maximum number of open connections from any given source IP (probably max 4)
public class Main {
+ public static final ThreadPool threadPool = new ThreadPool(10);
+ public static final Cron cron = new Cron(threadPool);
+
public static void main(String[] s) throws Exception {
try {
File f = new File(Mailbox.STORAGE_ROOT + "/restart");
System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
SSLServerSocketFactory sslserversocketfactory =
(SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
- ServerSocket sslserversocket =
- (ServerSocket) sslserversocketfactory.createServerSocket(9999);
+ ServerSocket sslserversocket = (ServerSocket) sslserversocketfactory.createServerSocket(9999);
+ ServerSocket sock8025 = new ServerSocket(8025);
ServerSocket sock143 = new ServerSocket(143);
ServerSocket sock119 = new ServerSocket(119);
ServerSocket sock25 = new ServerSocket(25);
- ServerSocket sock8025 = new ServerSocket(8025);
- ServerSocket sock993 = new ServerSocket(993);
- ServerSocket sock563 = new ServerSocket(563);
+ ServerSocket sock465 = (ServerSocket) sslserversocketfactory.createServerSocket(465);
+ ServerSocket sock993 = (ServerSocket) sslserversocketfactory.createServerSocket(993);
+ ServerSocket sock563 = (ServerSocket) sslserversocketfactory.createServerSocket(563);
//ServerSocket sock995 = new ServerSocket(995);
//ServerSocket sock113 = new ServerSocket(113);
- new Thread() {
+
+ cron.executeLater(500, new Runnable() {
public void run() {
- while(true) {
- try { Thread.sleep(500); } catch (Exception e) { }
- try {
- File f = new File(Mailbox.STORAGE_ROOT + "/restart");
- if (f.exists()) {
- Log.error("RESTART", "restarting...");
- System.exit(0);
- }
- } catch (Exception e) { Log.error(this, e); }
- }
- }
- }.start();
+ try {
+ File f = new File(Mailbox.STORAGE_ROOT + "/restart");
+ if (f.exists()) {
+ Log.error("RESTART", "restarting...");
+ System.exit(0);
+ }
+ } catch (Exception e) { Log.error(this, e); }
+ cron.executeLater(500, this);
+ } });
+
new Acceptor(sock143).start();
new Acceptor(sock119).start();
new Acceptor(sock25).start();
+ new Acceptor(sock465).start();
new Acceptor(sock8025).start();
new Acceptor(sock993).start();
new Acceptor(sock563).start();
private ServerSocket ss;
public Acceptor(ServerSocket ss) { this.ss = ss; }
public void run() {
- try {
- while(true) {
+ while(true) {
+ try {
+ ss.setReuseAddress(true);
final Socket s = ss.accept();
- try {
- new Thread() {
- public void run() {
- try {
- accept(new Connection(s, "megacz.com"));
- } catch (Exception e) { Log.error(Main.class, e); }
- }
- }.start();
- } catch (Exception e) { Log.error(Main.class, e); }
+ threadPool.start(new Runnable() {
+ public void run() {
+ try {
+ accept(new Connection(s, "megacz.com"));
+ } catch (Throwable t) { Log.error(Main.class, t); }
+ }
+ });
+ } catch (Throwable t) {
+ Log.error(Main.class, t);
+ Misc.sleep(1000);
}
- } catch (Exception e) { Log.error(Main.class, e); }
+ }
}
}
else if (conn.getLocalPort() == 119) new NNTP.Listener(auth).handleRequest(conn);
else if (conn.getLocalPort() == 563) new NNTP.Listener(auth).handleRequest(conn);
else if (conn.getLocalPort() == 25) new SMTP.Server().handleRequest(conn);
+ else if (conn.getLocalPort() == 465) new SMTP.Server().handleRequest(conn);
+ else if (conn.getLocalPort() == 465) new SMTP.Server().handleRequest(conn);
else if (conn.getLocalPort() == 8025) SMTP.whitelist.handleRequest(conn);
//else if (conn.getLocalPort() == 110) new POP3.Listener(auth).handleRequest(conn);
//else if (conn.getLocalPort() == 995) new POP3.Listener(auth).handleRequest(conn);
}
}
- private static final Auth auth = new Auth();
- private static class Auth implements Login {
- private KerberosAuth ka = new KerberosAuth("MEGACZ.COM", "godel.megacz.com");
+ static final Auth auth = new Auth();
+ static class Auth implements Login {
+ private KerberosAuth ka = new KerberosAuth("MEGACZ.COM", "chaitin.megacz.com");
public Account anonymous() {
try {
- final Mailbox root =
+ final MailTree root =
FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT + "/list", false);
if (root==null) return null;
- return new Account("anonymous", null, root){
- public Mailbox getMailbox(Class protocol) {
+ return new Account("anonymous", null, root) {
+ public MailTree getMailbox(Class protocol) {
return super.getMailbox(protocol);
}
};
}
public Object login(String user, String pass, Class protocol) { return login(user, pass); }
public Account login(String user, String pass) {
- if (!EtcPasswd.verify(user, pass)) return null;
-
- // currently broken, but should be used
- //if (!ka.auth(user, pass)) return null;
-
- final Mailbox root =
+ //if (!EtcPasswd.verify(user, pass)) return null;
+ //if (!CheckPassword.verify(user, pass)) return null;
+ if (!ka.auth(user, pass)) return null;
+ final MailTree root =
FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT + "/user", true);
return new Account(user, null, root.slash(user, true)){
- public Mailbox getMailbox(Class protocol) {
+ public MailTree getMailbox(Class protocol) {
return super.getMailbox(protocol);
}
};