Docstoc

CHAP5 (DOC)

Document Sample
CHAP5 (DOC) Powered By Docstoc
					Dynamic Web Agent                                                           Implementation


CHAPTER-5


                              IMPLEMENTETION


5.1. DETAILED EXPLANATION OF MODULES


The system after careful analysis has been identified to be presented with the following

modules:

The Modules involved are

       1. User Module
       2. Admin Module

USER MODULE

This module filters the page for each request from the end user and compares the old and
present value of digest .

      Pagefilter

  Page filter class identifies the request from the user and uploads the page to the Server.

      DWAVarifier

   This verifier returns a Boolean value depending upon the Comparison of the old and
  present of digest values.

ADMIN MODULE

This module calculates the hash code of the WebPages and stores it in the database,
verifies the administration authentication implementing the SHA-1 algorithm.




K.E.C/IT/2010-11                                                                         57
Dynamic Web Agent                                                           Implementation


  Digest generator

   Digest Generator class
           •   identifies the request from the user,
           •   calculates the digest, and
           •   updates the database and digest value with the URL requested.
           •   and the administrator identity that uploaded the page to the Server.

  DWAConnection

 DWAConnection will load the driver required based upon the Backend Specification
 used.

   DWA_SHA

  In DWA_SHA we get an instance of SHA and obtain the hash value of the Requested
 page.


5.2. MODULE LEVEL CODING WITH EXPLANATION


PageFilter.java

Page filter class identifies the request from the user and uploads the page to the Server.


package sig;
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
import java.net.*;
import javax.sql.*;
import java.sql.*;
public class PageFilter implements Filter{
private String encoding;

K.E.C/IT/2010-11                                                                             58
Dynamic Web Agent                                                      Implementation


public void init(FilterConfig config) throws ServletException {
encoding = "UTF-8";
String enc = config.getInitParameter("encoding");
if(enc !=null && enc.length() > 0){
encoding = enc;
  }
 }
 public void destroy() {}
 public void doFilter(ServletRequest request,
                ServletResponse response,
                FilterChain chain)
 throws IOException, ServletException {
request.setCharacterEncoding(encoding);
HttpServletRequest rq=(HttpServletRequest)request;
response.setContentType("text/html");
String str=rq.getRealPath("");
String surl=rq.getRequestURL().toString();
URL url=new URL(surl);
str=str.substring(0,str.lastIndexOf('\\'));
String filename=url.getFile();
filename=filename.replace('/','\\');
str=str.concat(filename);
System.out.println(str);
sig.DWAVarifier df=new sig.DWAVarifier();
if(!df.verifyIntigrity(str))
{PrintWriter pw=response.getWriter();
pw.println("<h3><center><br><br><br><br><br><hr><font color=red>The page you
requested cannot be displayed because the page has been modified. We Regret for the
inconvenience. Will be back soon with the actual content<hr></center></h3>");
try
{String DriverClass="sun.jdbc.odbc.JdbcOdbcDriver";

K.E.C/IT/2010-11                                                                      59
Dynamic Web Agent                                                  Implementation


String User="Admin";
String Pass="";
Class.forName(DriverClass);
Connection con;
con=DriverManager.getConnection("jdbc:odbc:DWA",User,Pass);
java.util.Date date=new java.util.Date();
PreparedStatement st=con.prepareStatement("insert into recorder
values('"+str+"','"+date.toString()+"')");
st.executeUpdate();System.out.println("errornot");
con.commit();
}
catch(Exception e){System.out.println(e);}
}
else{
    chain.doFilter(request, response);
}
}
}



DWAVarifier.java

This verifier returns a Boolean value depending upon the Comparison of the old and
present of digest values.


package sig;
import java.sql.*;
public class DWAVarifier
{
static Connection con;
static PreparedStatement st;
public DWAVarifier()

K.E.C/IT/2010-11                                                               60
Dynamic Web Agent                                                         Implementation


{
try{
Beans.DWAConnection dwa=new Beans.DWAConnection();
con=dwa.getConnection();
st=con.prepareStatement("select digest,adminid from dwadigest where page=?");
}catch(Exception ex){System.out.println(ex);}


}
public static boolean verifyIntigrity(String url)
{
boolean valid=false;
try{
st.setString(1,url);
ResultSet rs=st.executeQuery();
if(rs.next())
{
String odigest=rs.getString(1);
String adminid=rs.getString(2);
String pdigest=sig.DigestGen.getDigest(url);
        if(odigest.equals(pdigest))
        {
        valid=true;
System.out.println("Orig: Digest"+odigest+"---------------TRUE------------------Prest
Digest---"+pdigest);
        }
else
        {
System.out.println("Orig: Digest"+odigest+"---------------FALSE------------------Prest
Digest---"+pdigest);
}
}con.close();

K.E.C/IT/2010-11                                                                         61
Dynamic Web Agent                                                 Implementation


}catch(Exception ex){System.out.println(ex);}
return valid;
}
}


DWAConnection.java

DWAConnection will load the driver required based upon the Backend Specification
used.


package Beans;
import java.sql.*;
import java.util.*;
public class DWAConnection
{
Connection con;
public DWAConnection()throws Exception
{
String DriverClass="sun.jdbc.odbc.JdbcOdbcDriver";
String url="jdbc:odbc:DWA";
String User="Admin";
String Pass="";
Class.forName(DriverClass);
con=DriverManager.getConnection(url,User,Pass);
}
public Connection getConnection()throws Exception
{
return con;
}
}




K.E.C/IT/2010-11                                                             62
Dynamic Web Agent                                                          Implementation


Digestgen.java

Digest Generator class
           •   identifies the request from the user,
           •   calculates the digest, and
           •   updates the database and digest value with the URL requested.
           •   and the administrator identity that uploaded the page to the Server.


package sig;
import java.sql.*;
import java.io.*;
import java.security.*;
public class DigestGen
{
static Connection con;
static boolean valid=false;
public DigestGen()
{
try{
Beans.DWAConnection dwa=new Beans.DWAConnection();
con=dwa.getConnection();
}catch(Exception ex){System.out.println(ex);}
}
public static String getDigest(String url)
{
String digest="";
try{
FileInputStream fin=new FileInputStream(url);
byte b[]=new byte[fin.available()];
fin.read(b);
String str=new String(b);


K.E.C/IT/2010-11                                                                      63
Dynamic Web Agent                                                       Implementation


digest=DWA_SHA.getHashCode(str);
}catch(Exception ex){System.out.println(ex);}
return digest;
}
public static boolean makeDigest(String url)
{
return makeDigest(url,"NOadminid");
}
public static boolean makeDigest(String url,String adminid)
{
boolean done=false;
try{
String digest=getDigest(url);
PreparedStatement st=con.prepareStatement("insert into dwadigest values(?,?,?)");
st.setString(1,url);
st.setString(2,digest);
st.setString(3,adminid);
st.executeUpdate();
con.commit();
done=true;
}catch(Exception ex){System.out.println(ex);}
return done;
}
public static void callDigestEngine()
{
try{
        DigestGen d=new DigestGen();
        File f=new File("./");
        File files[]=f.listFiles();
        for(int i=0;i<files.length;i++)
        {

K.E.C/IT/2010-11                                                                    64
Dynamic Web Agent                                                    Implementation


            if(files[i].isDirectory()==false)
            {
                    if(files[i].getName().endsWith(".jsp"))
                    {
                    d.makeDigest(f.getAbsolutePath());
                    }
            }
            }
}catch(Exception ex){System.out.println(ex);}
}
}


DWA_SHA.java

    In DWA_SHA we get an instance of SHA and obtain the hash value of the Requested
    page.


package sig;
import java.io.*;
import java.security.*;
public class DWA_SHA
{
public static String getHashCode(String str)
{
String hex="";
try{
     MessageDigest md = MessageDigest.getInstance("SHA");


    md.update(str.getBytes());
    byte[] digest = md.digest();
    for (int i=0; i<digest.length; i++)
            {

K.E.C/IT/2010-11                                                                65
Dynamic Web Agent                                                  Implementation


    hex = Integer.toHexString(digest[i]);
    if (hex.length() == 1) hex = "0" + hex;
    hex=hex.substring(hex.length()-2);
       }
}catch(Exception ex){System.out.println(ex);}
return hex;
}
}


5.3. DETAILED EXPLANATION OF DATABASE


Admin table has the details of the administrator like adminid and password through
which the administrator is going to login.




                                Fig 5.1: Admin Database


K.E.C/IT/2010-11                                                               66
Dynamic Web Agent                                                    Implementation




DWAdigest table stores the page digests of the corresponding web page URL




                           Fig 5.2: DWAdigest Database




K.E.C/IT/2010-11                                                                67
Dynamic Web Agent                                                      Implementation




Recorder table contains the details of hacked pages and the date and time of hacking of
that particular page for future purpose of Administrator.




                               Fig 5.3: Recorder Database




K.E.C/IT/2010-11                                                                    68

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:7
posted:4/27/2012
language:English
pages:12