Source code: org/relayirc/chatengine/IdentServer.java
1
2 /*
3 * FILE: IdentServer.java
4 *
5 * The contents of this file are subject to the Mozilla Public License
6 * Version 1.0 (the "License"); you may not use this file except in
7 * compliance with the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS"
11 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
12 * License for the specific language governing rights and limitations
13 * under the License.
14 *
15 * The Original Code is Relay IRC chat client.
16 *
17 * The Initial Developer of the Original Code is David M. Johnson.
18 * Portions created by David M. Johnson are Copyright (C) 1998.
19 * All Rights Reserved.
20 *
21 * Contributor(s): No contributors to this file.''
22 */
23
24 package org.relayirc.chatengine;
25 import org.relayirc.util.*;
26
27 import java.net.*;
28 import java.io.*;
29
30 /**
31 * Implments a "one-shot" ident authentication server. This is needed
32 * for systems that do not have an ident authentication server.
33 * @author David M. Johnson.
34 */
35 public class IdentServer implements Runnable {
36 String _userName = null;
37
38 /**
39 * Construct identity server for specified chat server with specified
40 * chat options.
41 */
42 public IdentServer( IChatEngine ctl, String userName) {
43 _userName = userName;
44 Thread t = new Thread(this);
45 t.start();
46 }
47 //------------------------------------------------------------------
48 /**
49 * Start running and stop once one identity request has been serviced.
50 */
51 public void run() {
52
53 ServerSocket echoServer = null;
54 String line;
55 BufferedReader is;
56 DataOutputStream os;
57 Socket clientSocket = null;
58
59 try {
60 echoServer = new ServerSocket(113);
61 }
62 catch (IOException e) {
63 }
64
65 try {
66 clientSocket = echoServer.accept();
67 is = new BufferedReader(
68 new InputStreamReader(
69 new DataInputStream( clientSocket.getInputStream() )));
70 os = new DataOutputStream(clientSocket.getOutputStream());
71 while (true) {
72 line = is.readLine();
73 if (line != null) {
74 String resp = line+" : USERID : UNIX : "+_userName;
75 System.out.println("IdentServer: "+resp);
76 os.writeBytes(resp);
77 clientSocket.close();
78 echoServer.close();
79 return;
80 }
81 }
82 }
83 catch (Exception e) {
84 e.printStackTrace();
85 System.out.println("");
86 System.out.println("WARNING: Unable to start Relay IRC's built-in Ident Server.");
87 System.out.println(" ");
88 System.out.println(" If you are running Linux, then ignore this message but be");
89 System.out.println(" aware that most chat servers require that running an identity");
90 System.out.println(" such as in.identd");
91 System.out.println(" ");
92 System.out.println(" If you are running Windows, then this probably indicates");
93 System.out.println(" that you are not connected to the internet.");
94 System.out.println(" ");
95 }
96 }
97 }
98
99