]> andersk Git - moira.git/blame - clients/regapplet/regapplet/Worker.java
Add a "PIN" screen that's an alternative to the six words screen;
[moira.git] / clients / regapplet / regapplet / Worker.java
CommitLineData
1d3501d2 1package regapplet;
2
3import java.awt.*;
4import java.net.*;
5import java.io.*;
6import java.util.Properties;
7import mit.cipher.*;
8
9public class Worker implements Runnable {
10 public static final int SENDNAME = 0;
11 public static final int SENDWORDS = 1;
12 public static final int SENDLOGIN = 2;
13 public static final int SENDPASSWD = 3;
14 public static final int INIT = 4;
15 public static final int DIALOG = 5;
16 public static final int INIT1 = 6;
c05c41a2 17 public static final int SENDPIN = 7;
1d3501d2 18 int oldstate = INIT;
19 int state = INIT;
20 int nextstate = INIT;
21 Socket sock = null;
22 Sender send;
23 Parser parse;
24 public Regapplet applet;
25 public Worker(Regapplet tapplet) {
26 applet = tapplet;
27 }
28 public void run () {
29 try {
30 switch (state) {
31 case DIALOG:
32 state = nextstate;
33 switch (state) {
34 case SENDWORDS:
35 applet.showWordsDiag();
36 break;
c05c41a2 37 case SENDPIN:
38 applet.showPinDiag();
39 break;
40 case SENDNAME:
1d3501d2 41 applet.showNameDiag();
42 break;
43 case SENDLOGIN:
44 applet.showLoginDiag();
45 break;
46 case SENDPASSWD:
47 applet.showPassDiag();
48 break;
49 case INIT:
50 applet.worker.close();
51 applet.workthread = null;
52 applet.worker = null;
53 if (applet.isStandalone) {
54 System.exit(0);
55 }
56 applet.showInit();
57 break;
58 }
59 return;
60 case INIT:
61 if (Regapplet.doRules) {
62 state = INIT1;
63 applet.showRules();
64 // Hmm. the lines below caused problems on the Mac
65 // Thread z = new Thread(new Seeder()); // Generate numbers in thread
66 // z.start();
67 return;
68 }
69 // Fall through
70 case INIT1:
71 applet.showMessage("Connecting to Server...");
72 try {
73 String host;
74 if (applet.isStandalone) {
75 host = (System.getProperties()).getProperty("host", "");
76 if (host == null || host.equals("")) {
77 System.err.println("Cannot learn host name (application) using localhost");
78 host = "localhost";
79 }
80 } else {
81 URL cb = applet.getCodeBase();
82 String protocol = cb.getProtocol();
83 if (protocol.equals("file") || protocol.equals("FILE")) {
84 System.err.println("Applet: FILE protocol in use, connecting to localhost");
85 host = "localhost";
86 } else {
87 host = cb.getHost();
88 }
89 }
90 sock = new Socket(host, 9001);
91 } catch (Exception e) {
92 e.printStackTrace();
93 applet.showError1(true);
94 applet.show();
95 state = DIALOG;
96 nextstate = INIT;
97 return;
98 // try {
99 // Thread.sleep(5000);
100 // } catch (java.lang.InterruptedException ae) {
101 // // Ignore exception for now
102 // }
103 // applet.showInit();
104 // return;
105 }
106 send = new Sender(sock);
107 parse = new Parser(sock, this);
108 parse.encap = send.encap; // Mumble, they need to share
109 // this
110 break; // We now expect a GETN after connect
111 // applet.showNameDiag();
112 // state = SENDNAME;
113 // return;
114 case SENDNAME:
115 applet.showMessage("Please wait...");
116 send.SendNameData(applet.FirstName.getText(),
117 applet.MiddleName.getText(),
118 applet.LastName.getText(),
119 applet.MITID.getText());
120 break;
121 case SENDWORDS:
122 applet.showMessage("Please wait...");
123 send.SendWords(applet.Word1.getText(),
124 applet.Word2.getText(),
125 applet.Word3.getText(),
126 applet.Word4.getText(),
127 applet.Word5.getText(),
128 applet.Word6.getText());
129 break;
c05c41a2 130 case SENDPIN:
131 applet.showMessage("Please wait...");
132 send.SendPin(applet.Pin.getText());
133 break;
134
1d3501d2 135 case SENDLOGIN:
136 applet.showMessage("Please wait...");
137 send.SendLogin(applet.LoginName.getText());
138 break;
139 case SENDPASSWD:
140 if (!(applet.Password1.getText().equals(applet.Password2.getText()))) {
141 applet.Password1.setText("");
142 applet.Password2.setText("");
143 applet.showMessage("Entered Passwords do not match, try again");
144 try {
145 Thread.sleep(3000);
146 } catch (java.lang.InterruptedException e) {
147 }
148 applet.showPassDiag();
149 return;
150 }
151 applet.showMessage("Please wait...");
152 send.SendPassword(applet.Password1.getText());
153 break;
154 }
155 parse.read();
156 // Add code to parse results and switch on new state
157 } catch (IOException e) {
158 e.printStackTrace();
159 applet.showError(true);
160 state = DIALOG;
161 nextstate = INIT;
162 // Moby reset applet
163 } catch (MITCipherException e) {
ca587527 164 applet.showError(true);
165 state = DIALOG;
166 nextstate = INIT;
1d3501d2 167 e.printStackTrace();
168 // Moby reset applet here too.
169 } catch (RegAppletException a) {
170 a.printStackTrace();
171 applet.showError(true);
172 state = DIALOG;
173 nextstate = INIT;
174 }
175 }
176 public void setState(int i) {
177 state = i;
178 }
179 public void setState(int i, int j) {
180 state = i;
181 nextstate = j;
182 }
183 public void close() {
184 if (sock != null) {
185 try {
186 sock.close();
187 } catch (Exception e) {
188 }
189 sock = null;
190 }
191 }
192 public void finalize() {
193 if (sock != null) {
194 System.err.println("Worker Finalized with open socket! Closing it.");
195 close();
196 }
197 }
198}
This page took 0.081546 seconds and 5 git commands to generate.