prupp
Class Proxy

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--prupp.Proxy

public class Proxy
extends java.lang.Thread

This is the central dispatcher for RabbIt, get a connection and create a HTTPHeaderHandler for the connection. Also keeps a lot of variables. Handles logging so it goes out nicely formatted.


Field Summary
static java.lang.String HELPFILE
          which file contains help?
protected static java.lang.String inifile
          the standard inifile
protected static int PORT
          the standard port
static java.lang.String VERSION
          current version
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Method Summary
static boolean allowed(java.net.Socket s, int type)
          test if the socket that connects is a ok one
static boolean checkBasicAccess(java.lang.String userid, java.lang.String pass)
          check if a user is authorised
static java.util.Vector getAccesses()
          Get the Vector of allowed access
static NCache getCache()
          return the cache we have.
static int getConnectPort(int port)
          Get the port to connect to.
static java.lang.String getConvert()
          get the path to convert
static java.util.Vector getCurrentConections()
          returns the current connections.
static java.util.Vector getFilters(java.lang.Object o)
          gimme the filters for the object o.
static HTTPHeader getHeader()
          Get a standard (200 OK, text/html) header for the proxy, useful for metapages etc...
static HTTPHeader getHeader(java.lang.String statusLine)
          Get a header for the proxy.
static java.net.InetAddress getHost()
          Get the local host.
static java.net.InetAddress getInetAddress(java.net.URL urltoget)
          get the inetAdress of an URL
static int getNoOfServedPages()
          return the number of pages that are fully served
static int getPort()
          Get the port this proxy is using.
static java.util.Properties getProperties()
          return the configuration of the proxy.
static java.lang.String getSmallLogo()
          Get the small logo string.
static java.util.Date getStartDate()
          return the time when the proxy was started.
static java.util.Hashtable getUsers()
          Get the Hashtable of users->password entries.
static boolean isMetaRestricted()
          simple test for now (until all pages are checked).
static boolean isProxyConnected()
          are we connected to another proxy?
protected static void kill()
          shutdown
static void logError(java.lang.String error)
          log errors and other important stuff.
static void logRequest(java.net.Socket socket, Responder responder)
          log accesses.
static void main(java.lang.String[] args)
          Start a proxy.
static void printHelp()
          print out the helptext to the user.
protected static void readAccess()
          reads in the accessfile and parses out the given ranges and types given.
static void readAccess(java.io.Reader r)
          reads in the accessess allowed from the given Reader
protected static void readFilterConfig()
          set up the filters to use.
protected static void readIniFile(java.lang.String filename)
          load the config for the Proxy.
static void readUsers()
          read in the users specified in basicusersfile
static void readUsers(java.io.Reader r)
          reads the users from a given Reader
static void removeConnection(HTTPHeaderHandler con)
          Remove a connection (it has received full treatment)
 void run()
          while we can, accept new sockets, creating a handler for each and also save connections for statistics.
static void saveAccess()
          save access configuration back to file
static void saveConfig()
          save the config back to file
static void saveFilterConfig()
          save filter configuration back to file
static void saveUsers()
          save (auth)user configuration back to file
static void setConvert(java.lang.String conv)
          set the path to convert, the program we use to convert images
static void setSmallLogo(java.lang.String s)
          Set the small logo used on meta-pages etc
protected static void setup(java.util.Properties config)
          handle the setup of this Proxy.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VERSION

public static final java.lang.String VERSION
current version

HELPFILE

public static final java.lang.String HELPFILE
which file contains help?

PORT

protected static final int PORT
the standard port

inifile

protected static java.lang.String inifile
the standard inifile
Method Detail

main

public static void main(java.lang.String[] args)
Start a proxy. Parse flags and read the config, then starts the proxy.
Parameters:
args - the command-line flags given.

run

public void run()
while we can, accept new sockets, creating a handler for each and also save connections for statistics.
Overrides:
run in class java.lang.Thread

allowed

public static boolean allowed(java.net.Socket s,
                              int type)
test if the socket that connects is a ok one
Parameters:
socket - the Socket that connects

removeConnection

public static void removeConnection(HTTPHeaderHandler con)
Remove a connection (it has received full treatment)
Parameters:
con - the connection that is closing down.

logRequest

public static void logRequest(java.net.Socket socket,
                              Responder responder)
log accesses.
Parameters:
socket - the Socket were talking to.
responder - the responsehandler that handled the request.

logError

public static void logError(java.lang.String error)
log errors and other important stuff.
Parameters:
error - the thing that happend.

getFilters

public static java.util.Vector getFilters(java.lang.Object o)
gimme the filters for the object o.
Parameters:
o - the object were filtering.
Returns:
a Vector of Filters

getInetAddress

public static java.net.InetAddress getInetAddress(java.net.URL urltoget)
                                           throws java.net.UnknownHostException
get the inetAdress of an URL
Parameters:
urltoget - the URL were intrested in.
Returns:
an inetadress of null on error.

getConnectPort

public static int getConnectPort(int port)
Get the port to connect to.
Parameters:
port - the port we want to connect to.
Returns:
the port to connect to.

isProxyConnected

public static boolean isProxyConnected()
are we connected to another proxy?
Returns:
true if the proxy is connected to another proxy.

printHelp

public static void printHelp()
print out the helptext to the user.

readIniFile

protected static void readIniFile(java.lang.String filename)
load the config for the Proxy.

setConvert

public static void setConvert(java.lang.String conv)
set the path to convert, the program we use to convert images
Parameters:
conv - the new path to convert

getConvert

public static java.lang.String getConvert()
get the path to convert
Returns:
the full path to convert

getSmallLogo

public static java.lang.String getSmallLogo()
Get the small logo string.
Returns:
the string containing the url to the small logo

setSmallLogo

public static void setSmallLogo(java.lang.String s)
Set the small logo used on meta-pages etc
Parameters:
s - the new string to the logo

setup

protected static void setup(java.util.Properties config)
handle the setup of this Proxy. Should be nice and cope with runtime setup. NOTE! the proxy will die if it is setup wrong right now, this needs a fix since runtimeconfig is available and then you only want an errormessage. NOTE2! The proxy needs to be restarted for some settings to take place this is not done!
Parameters:
config - the Property to use.

saveConfig

public static void saveConfig()
save the config back to file

saveFilterConfig

public static void saveFilterConfig()
save filter configuration back to file

saveAccess

public static void saveAccess()
save access configuration back to file

saveUsers

public static void saveUsers()
save (auth)user configuration back to file

getPort

public static int getPort()
Get the port this proxy is using.
Returns:
the port number the proxy is listening on.

getHost

public static java.net.InetAddress getHost()
Get the local host.
Returns:
the InetAddress of the host the proxy is running on.

getProperties

public static java.util.Properties getProperties()
return the configuration of the proxy.
Returns:
the current configuration

isMetaRestricted

public static boolean isMetaRestricted()
simple test for now (until all pages are checked).

getCurrentConections

public static java.util.Vector getCurrentConections()
returns the current connections.
Returns:
a Vector with the current connections.

getStartDate

public static java.util.Date getStartDate()
return the time when the proxy was started.
Returns:
a Date with the time the proxy was started.

getNoOfServedPages

public static int getNoOfServedPages()
return the number of pages that are fully served
Returns:
The number of requests the proxy has handled

getCache

public static NCache getCache()
return the cache we have.
Returns:
The Cache this proxy is using

readFilterConfig

protected static void readFilterConfig()
set up the filters to use. If a static setup is found in the class invoke it with the Properies for the section.

getAccesses

public static java.util.Vector getAccesses()
Get the Vector of allowed access
Returns:
the Vector of access that are allowed.

readAccess

protected static void readAccess()
reads in the accessfile and parses out the given ranges and types given.

readAccess

public static void readAccess(java.io.Reader r)
                       throws java.io.IOException
reads in the accessess allowed from the given Reader
Parameters:
r - the Reader were data is available

getUsers

public static java.util.Hashtable getUsers()
Get the Hashtable of users->password entries.
Returns:
the Hashtable with the names and passwords of registered users.

readUsers

public static void readUsers()
read in the users specified in basicusersfile

readUsers

public static void readUsers(java.io.Reader r)
                      throws java.io.IOException
reads the users from a given Reader
Parameters:
r - the Reader to read users from.

checkBasicAccess

public static boolean checkBasicAccess(java.lang.String userid,
                                       java.lang.String pass)
check if a user is authorised
Parameters:
userid - the userid we check.
pass - the password supplied.
Returns:
true if user is in userlist, and has supplied a valid password, false otherwise.

getHeader

public static HTTPHeader getHeader()
Get a standard (200 OK, text/html) header for the proxy, useful for metapages etc...
Returns:
a HTTPHeader from this proxy.

getHeader

public static HTTPHeader getHeader(java.lang.String statusLine)
Get a header for the proxy. useful for metapages.
Parameters:
statusLine - the Statusline of this header.
Returns:
a HTTPHeader from this proxy.

kill

protected static void kill()
shutdown