Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sock;
- import java.io.*;
- import java.net.*;
- import java.util.*;
- import java.sql.*;
- public class Serv extends Thread
- { static StringBuffer st;
- static Socket s,s1;
- static ServerSocket ss;
- static DataInputStream ins,ins1;
- static DataOutputStream dos,dos1;
- static byte[] request = new byte[1024];
- static byte[] reply = new byte[4096];
- public static void main(String args[]) throws Exception
- {
- ss=new ServerSocket(8080);
- s=ss.accept();
- System.out.println("1");
- ins=new DataInputStream(s.getInputStream());
- dos=new DataOutputStream(s.getOutputStream());
- java.lang.String req;
- Integer flag1=0;
- Integer flag=0;
- while(true)
- {
- req=ins.readLine();
- flag1++;
- if(flag1==1)
- {
- StringTokenizer st=new StringTokenizer(req," ");
- st.nextToken();
- String filename=st.nextToken();
- Integer i1=filename.indexOf("/",7);
- String finalhost=filename.substring(7,i1);
- try
- {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- Connection con=DriverManager.getConnection("jdbc:odbc:locksites");
- Statement stat=con.createStatement();
- ResultSet rs=stat.executeQuery("select * from sites where name="+"'"+finalhost+"'");
- if(rs.next())
- { flag=1;
- }
- else
- { flag=0;
- }
- }
- catch(Exception e)
- {System.out.println(e);}
- if(flag==0)
- { System.out.println("User has right to access "+finalhost);
- s1=new Socket(finalhost,80);
- ins1=new DataInputStream(s1.getInputStream());
- dos1=new DataOutputStream(s1.getOutputStream());
- (new Serv()).start();
- }
- else if(flag==1)
- { System.out.println("Restricted access to "+finalhost);
- s.close();
- }
- }
- // req=(char)ins.read();
- System.out.println(req);
- dos1.writeBytes(req);
- dos1.writeBytes("\r\n");
- }
- //System.out.println("finished request");
- /* StringTokenizer st=new StringTokenizer(req," ");
- st.nextToken();
- String filename=st.nextToken();
- Integer i1=filename.indexOf("/",7);
- String finalhost=filename.substring(7,i1);
- InetAddress address = null;
- try {
- address = InetAddress.getByName(finalhost);
- } catch (UnknownHostException e) {
- System.out.println(e);
- }
- System.out.println(address.getHostName() + "="
- + address.getHostAddress());
- try
- {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- Connection con=DriverManager.getConnection("jdbc:odbclocksites");
- Statement stat=con.createStatement();
- ResultSet rs=stat.executeQuery("select * from sites where name="+"'"+finalhost+"'");
- if(rs.next())
- { flag=1;
- }
- else
- { flag=0;
- }
- }
- catch(Exception e)
- {System.out.println(e);}
- if(flag==0)
- { System.out.println("User has right to access "+finalhost);
- }
- else if(flag==1)
- { System.out.println("Restricted access to "+finalhost);
- }
- s.close(); */
- }
- public void run()
- { String res;
- System.out.println("response");
- int bytesread;
- try
- {
- while((bytesread=ins1.read(reply))!=-1)
- {
- //System.out.println("waiting for response");
- //System.out.println("got response");
- System.out.println(reply.toString());
- dos.write(reply,0,bytesread);
- dos.flush();
- }
- }
- catch(Exception e)
- { System.out.println(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement