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;
21 public static void main(String[] s) throws Exception {
23 File f = new File(Mailbox.STORAGE_ROOT + "/restart");
24 if (f.exists()) f.delete();
25 } catch (Exception e) { Log.error(Main.class, e); }
29 public void main() throws Exception {
30 if (System.getProperty("javax.net.ssl.keyStore")==null)
31 System.setProperty("javax.net.ssl.keyStore", Mailbox.STORAGE_ROOT+"/conf/ssl/ssl.keystore");
32 if (System.getProperty("javax.net.ssl.keyStorePassword")==null)
33 System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
34 SSLServerSocketFactory sslserversocketfactory =
35 (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
36 ServerSocket sslserversocket = (ServerSocket) sslserversocketfactory.createServerSocket(9999);
37 ServerSocket sock8025 = new ServerSocket(8025);
38 ServerSocket sock143 = new ServerSocket(143);
39 ServerSocket sock119 = new ServerSocket(119);
40 ServerSocket sock25 = new ServerSocket(25);
41 ServerSocket sock465 = (ServerSocket) sslserversocketfactory.createServerSocket(465);
42 ServerSocket sock993 = (ServerSocket) sslserversocketfactory.createServerSocket(993);
43 ServerSocket sock563 = (ServerSocket) sslserversocketfactory.createServerSocket(563);
44 //ServerSocket sock995 = new ServerSocket(995);
45 //ServerSocket sock113 = new ServerSocket(113);
49 try { Thread.sleep(500); } catch (Exception e) { }
51 File f = new File(Mailbox.STORAGE_ROOT + "/restart");
53 Log.error("RESTART", "restarting...");
56 } catch (Exception e) { Log.error(this, e); }
60 new Acceptor(sock143).start();
61 new Acceptor(sock119).start();
62 new Acceptor(sock25).start();
63 new Acceptor(sock465).start();
64 new Acceptor(sock8025).start();
65 new Acceptor(sock993).start();
66 new Acceptor(sock563).start();
67 //new Acceptor(sock995).start();
68 //new Acceptor(sock113).start();
71 private class Acceptor extends Thread {
72 private ServerSocket ss;
73 public Acceptor(ServerSocket ss) { this.ss = ss; }
76 ss.setReuseAddress(true);
79 final Socket s = ss.accept();
84 accept(new Connection(s, "megacz.com"));
85 } catch (Exception e) { Log.error(Main.class, e); }
88 } catch (Exception e) { Log.error(Main.class, e); }
90 } catch (Exception e) { Log.error(Main.class, e); }
94 public void accept(Connection conn) {
96 if (conn.getLocalPort() == 143) new IMAP.Listener(auth).handleRequest(conn);
97 else if (conn.getLocalPort() == 993) new IMAP.Listener(auth).handleRequest(conn);
98 else if (conn.getLocalPort() == 119) new NNTP.Listener(auth).handleRequest(conn);
99 else if (conn.getLocalPort() == 563) new NNTP.Listener(auth).handleRequest(conn);
100 else if (conn.getLocalPort() == 25) new SMTP.Server().handleRequest(conn);
101 else if (conn.getLocalPort() == 465) new SMTP.Server().handleRequest(conn);
102 else if (conn.getLocalPort() == 465) new SMTP.Server().handleRequest(conn);
103 else if (conn.getLocalPort() == 8025) SMTP.whitelist.handleRequest(conn);
104 //else if (conn.getLocalPort() == 110) new POP3.Listener(auth).handleRequest(conn);
105 //else if (conn.getLocalPort() == 995) new POP3.Listener(auth).handleRequest(conn);
106 //else if (conn.getLocalPort() == 8099) GMail.handleRequest(conn);
107 } catch (Stream.Closed c) {
108 Log.error(this, "connection abruptly closed by client");
109 } catch (IOException e) {
116 static final Auth auth = new Auth();
117 static class Auth implements Login {
118 private KerberosAuth ka = new KerberosAuth("MEGACZ.COM", "godel.megacz.com");
119 public Account anonymous() {
122 FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT + "/list", false);
123 if (root==null) return null;
124 return new Account("anonymous", null, root){
125 public Mailbox getMailbox(Class protocol) {
126 return super.getMailbox(protocol);
129 } catch (Exception e) { throw new RuntimeException(e); }
131 public Object login(String user, String pass, Class protocol) { return login(user, pass); }
132 public Account login(String user, String pass) {
133 //if (!EtcPasswd.verify(user, pass)) return null;
134 if (!ka.auth(user, pass)) return null;
136 FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT + "/user", true);
137 return new Account(user, null, root.slash(user, true)){
138 public Mailbox getMailbox(Class protocol) {
139 return super.getMailbox(protocol);