confutil
Class ConfClient

java.lang.Object
  extended byconfutil.ConfClient

class ConfClient
extends java.lang.Object

This class encapsulates the main configuration client functionality. It offers methods to connect to a Linksys box where a configuration server runs, authenticate a user, get, set and unset configuration variables that reside in the NVRAM of the box and control the function of the P2PWNC protocol modules that run on the Linksys WRT54GS wireless router. The configuration client and server programs communicate by exchanging simpe text messages over TCP.

Title: P2PWNC configuration utility

Description: Linksys WRT54GS P2PWNC configuration utility

Copyright: Copyright (c) 2005

Company:

Version:
1.0
Author:
pfrag

Field Summary
static int ACTION_ACK
          "ACK" message.
static int ACTION_AUTH
          "AUT" message.
static int ACTION_AUTH_ERR
          "AER" message.
static int ACTION_AUTH_OK
          "AOK" message.
static int ACTION_ERR
          "ERR" message.
static int ACTION_GET
          "GET" message.
static int ACTION_SET
          "SET" message.
static int ACTION_UNSET
          "UST" message.
static int CONF_SERVER_PORT
          Default port where a configuration server listens for client messages.
protected  java.net.InetAddress serverAddr
          Configuration server IP address.
 
Constructor Summary
(package private) ConfClient(java.net.InetAddress addr)
          Constructs a ConfClient object using addr as the configuration server address.
 
Method Summary
 boolean authenticateUser(java.lang.String passwd, java.net.Socket socket)
          Sends an "AUT" message to the server and gets the server response.
 java.net.Socket connectToServer()
          Connect to the configuration server.
static void main(java.lang.String[] args)
           
 java.lang.String makeMessage(int action, java.lang.String var, java.lang.String val)
          Constructs a text message to be sent to the server.
 java.lang.String parseMessage(java.lang.String text)
          Parses a text message received by the server.
 ConfMsg readMessage(java.net.Socket socket)
          Reads a text message from socket and returns the correspondent ConfMsg object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACTION_GET

public static final int ACTION_GET
"GET" message. Gets the value of a specified NVRAM variable.

See Also:
Constant Field Values

ACTION_SET

public static final int ACTION_SET
"SET" message. Gets the value of a specified NVRAM variable to a given value.

See Also:
Constant Field Values

ACTION_UNSET

public static final int ACTION_UNSET
"UST" message. Unsets an NVRAM variable.

See Also:
Constant Field Values

ACTION_ACK

public static final int ACTION_ACK
"ACK" message. The requested operation has been performed successfully.

See Also:
Constant Field Values

ACTION_ERR

public static final int ACTION_ERR
"ERR" message. An error occured while performing a requested operation.

See Also:
Constant Field Values

ACTION_AUTH

public static final int ACTION_AUTH
"AUT" message. Password based authentication to a Linksys router.

See Also:
Constant Field Values

ACTION_AUTH_OK

public static final int ACTION_AUTH_OK
"AOK" message. User successfully authenticated.

See Also:
Constant Field Values

ACTION_AUTH_ERR

public static final int ACTION_AUTH_ERR
"AER" message. Authentication failed.

See Also:
Constant Field Values

CONF_SERVER_PORT

public static final int CONF_SERVER_PORT
Default port where a configuration server listens for client messages.

See Also:
Constant Field Values

serverAddr

protected java.net.InetAddress serverAddr
Configuration server IP address.

Constructor Detail

ConfClient

ConfClient(java.net.InetAddress addr)
Constructs a ConfClient object using addr as the configuration server address.

Parameters:
addr - InetAddress Configuration server address. This is the IP address of the Linksys WRT54GS router where the server runs.
Method Detail

makeMessage

public java.lang.String makeMessage(int action,
                                    java.lang.String var,
                                    java.lang.String val)
Constructs a text message to be sent to the server. Action must be one of the valid actions specified. Valid messages to be sent are "GET", "SET", "UST", "AUT".

Parameters:
action - int The message type (ACTION_GET, ACTION_UNSET, ACTION_SET, ACTION_AUTH
var - String The "VAR" message field. In case of a "GET", "SET" or "UST" message it specifies the variable whose value is to be retrieved, set or unset. In case of an "AUT" message, var specifies the Linksys router's administrator password.
val - String The "VAL" message field. It is used only in "SET" messages, where it represents the value of the variable to be set.
Returns:
String The constructed text message.

parseMessage

public java.lang.String parseMessage(java.lang.String text)
Parses a text message received by the server. Expected messages are "ACK" and "ERR". Other messages that a client can receive are "AOK" and "AER", but these need not be parsed because the consist only of the message type identifier ("AOK", "AER").

Parameters:
text - String The text message to be parsed.
Returns:
String The value of the "VAR" field. It indicates which variable was requested to be set/unset.

readMessage

public ConfMsg readMessage(java.net.Socket socket)
Reads a text message from socket and returns the correspondent ConfMsg object. First, the message type is read (3 characters). If it is an "AOK" or "AER" message, then (normally) there are no more data to be read, so a ConfMsg object is returned with mtype set to ACTION_AOK or ACTION_AER and mtext set to "AOK" or "AER" respectively. In other case, the content-length field is read and the remaining data (whose length is specified by the content length) are read.

Parameters:
socket - Socket Socket where the data will be read from.
Returns:
ConfMsg

authenticateUser

public boolean authenticateUser(java.lang.String passwd,
                                java.net.Socket socket)
Sends an "AUT" message to the server and gets the server response. This message repsesents an authenrication request. The user sends her passwd, the server checks the NVRAM "passwd" variable, and, if they match, sends an "AOK" message. Otherwise, it sends an "AER" message.

Parameters:
passwd - String The Linksys WRT54GS router administrator password sent by the user.
socket - Socket The socket over which the message will be sent.
Returns:
boolean Returns true if authentication succeeded.

connectToServer

public java.net.Socket connectToServer()
Connect to the configuration server. If a connection can be established, the resulting socket is returned. The server address used is this.serverAddr and the port is this.CONF_SERVER_PORT.

Returns:
Socket

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Throws:
java.io.IOException