1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
6 import org.ibex.util.*;
7 import org.ibex.jetty.*;
13 import org.ibex.crypto.*;
14 import org.ibex.jetty.*;
15 import javax.net.ssl.SSLServerSocket;
16 import javax.net.ssl.SSLServerSocketFactory;
17 import javax.net.ssl.SSLSocket;
19 // restrict the maximum number of open connections from any given source IP (probably max 4)
22 public static void main(String[] s) throws Exception {
24 File f = new File(Mailbox.STORAGE_ROOT + "/restart");
25 if (f.exists()) f.delete();
26 } catch (Exception e) { Log.error(Main.class, e); }
30 public void main() throws Exception {
31 if (System.getProperty("javax.net.ssl.keyStore")==null)
32 System.setProperty("javax.net.ssl.keyStore", Mailbox.STORAGE_ROOT+"/conf/ssl/ssl.keystore");
33 if (System.getProperty("javax.net.ssl.keyStorePassword")==null)
34 System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
35 SSLServerSocketFactory sslserversocketfactory =
36 (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
37 ServerSocket sslserversocket = (ServerSocket) sslserversocketfactory.createServerSocket(9999);
38 ServerSocket sock8025 = new ServerSocket(8025);
39 ServerSocket sock143 = new ServerSocket(143);
40 ServerSocket sock119 = new ServerSocket(119);
41 ServerSocket sock25 = new ServerSocket(25);
42 ServerSocket sock465 = (ServerSocket) sslserversocketfactory.createServerSocket(465);
43 ServerSocket sock993 = (ServerSocket) sslserversocketfactory.createServerSocket(993);
44 ServerSocket sock563 = (ServerSocket) sslserversocketfactory.createServerSocket(563);
45 //ServerSocket sock995 = new ServerSocket(995);
46 //ServerSocket sock113 = new ServerSocket(113);
50 try { Thread.sleep(500); } catch (Exception e) { }
52 File f = new File(Mailbox.STORAGE_ROOT + "/restart");
54 Log.error("RESTART", "restarting...");
57 } catch (Exception e) { Log.error(this, e); }
61 new Acceptor(sock143).start();
62 new Acceptor(sock119).start();
63 new Acceptor(sock25).start();
64 new Acceptor(sock465).start();
65 new Acceptor(sock8025).start();
66 new Acceptor(sock993).start();
67 new Acceptor(sock563).start();
68 //new Acceptor(sock995).start();
69 //new Acceptor(sock113).start();
72 private class Acceptor extends Thread {
73 private ServerSocket ss;
74 public Acceptor(ServerSocket ss) { this.ss = ss; }
78 ss.setReuseAddress(true);
79 final Socket s = ss.accept();
83 accept(new Connection(s, "megacz.com"));
84 } catch (Throwable t) { Log.error(Main.class, t); }
87 } catch (Throwable t) {
88 Log.error(Main.class, t);
95 public void accept(Connection conn) {
97 if (conn.getLocalPort() == 143) new IMAP.Listener(auth).handleRequest(conn);
98 else if (conn.getLocalPort() == 993) new IMAP.Listener(auth).handleRequest(conn);
99 else if (conn.getLocalPort() == 119) new NNTP.Listener(auth).handleRequest(conn);
100 else if (conn.getLocalPort() == 563) new NNTP.Listener(auth).handleRequest(conn);
101 else if (conn.getLocalPort() == 25) new SMTP.Server().handleRequest(conn);
102 else if (conn.getLocalPort() == 465) new SMTP.Server().handleRequest(conn);
103 else if (conn.getLocalPort() == 465) new SMTP.Server().handleRequest(conn);
104 else if (conn.getLocalPort() == 8025) SMTP.whitelist.handleRequest(conn);
105 //else if (conn.getLocalPort() == 110) new POP3.Listener(auth).handleRequest(conn);
106 //else if (conn.getLocalPort() == 995) new POP3.Listener(auth).handleRequest(conn);
107 //else if (conn.getLocalPort() == 8099) GMail.handleRequest(conn);
108 } catch (Stream.Closed c) {
109 Log.error(this, "connection abruptly closed by client");
110 } catch (IOException e) {
117 static final Auth auth = new Auth();
118 static class Auth implements Login {
119 private KerberosAuth ka = new KerberosAuth("MEGACZ.COM", "chaitin.megacz.com");
120 public Account anonymous() {
123 FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT + "/list", false);
124 if (root==null) return null;
125 return new Account("anonymous", null, root){
126 public Mailbox getMailbox(Class protocol) {
127 return super.getMailbox(protocol);
130 } catch (Exception e) { throw new RuntimeException(e); }
132 public Object login(String user, String pass, Class protocol) { return login(user, pass); }
133 public Account login(String user, String pass) {
134 //if (!EtcPasswd.verify(user, pass)) return null;
135 //if (!CheckPassword.verify(user, pass)) return null;
136 if (!ka.auth(user, pass)) return null;
138 FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT + "/user", true);
139 return new Account(user, null, root.slash(user, true)){
140 public Mailbox getMailbox(Class protocol) {
141 return super.getMailbox(protocol);