[squid-users] Java external acl

From: edward_ryan <edwardo_rodriegez_at_hotmail.com>
Date: Wed, 13 Apr 2011 05:45:34 -0700 (PDT)

Hi Guys,

Just for a learning experience (I'm learning java at uni and we have a squid
proxy at work) I am trying to create an external acl using Java that will
check if the user has a list of websites that they can access (the name of
the list will just be their username) that other users cannot (there is a
blacklist of domains, but it's a blanket ban). Obviously I need to send the
person's username and the domain they are trying to get to. I know I can use
the %LOGIN for the user name but how do I pass it the domain?

Also not sure if I can ask this here but if anyone knows a bit of java. How
do I capture the information passed to the java external acl? Maybe a stupid
question.

This is what I have so far. I'm entering the domain and username manually
because I'm not sure how I go about using the information that will be
passed to it by squid.

import java.io.File;
import java.util.Scanner;
import java.io.FileNotFoundException;

public class user_list_checker {
    public static void main(String [] args){

        String domain = new String ("hotmail.com");
        String user = new String("ryane");
        File file = new File("C:\\Users\\IT Support\\Desktop\\Java Squid\\"
+ user + ".txt");
        int WhitelistFlag = 0;
        int blacklistFlag = 0;

        //calls a method to see if the domain is blacklisted
        blacklistFlag = blacklist_checker(domain);
        try {
            Scanner scan = new Scanner(file);
            //checks the user.txt to see if they have special permission to
access the domain.
            //while loop starts if the domain is blacklisted and continues
as long as it hasn't
            //found the domain in the user list and there are lines
remaining in the .txt file
            while (scan.hasNextLine() && WhitelistFlag == 0 && blacklistFlag
== 1){
                String line = scan.nextLine();
                if (line.equals(domain)){
                    WhitelistFlag = 1;
                }

            }
        }catch (FileNotFoundException e) {
            }

         if (WhitelistFlag == 0 | WhitelistFlag == 2){
             System.out.println ("ERR");
            }
         else {
             System.out.println ("OK");
            }

        }
    private static int blacklist_checker (String domain){
        File blacklist = new File ("C:\\Users\\IT Support\\Desktop\\Java
Squid\\blacklist.txt");
        int blacklistFlag = 0;
        System.out.println(domain);
        try{
            Scanner scan = new Scanner(blacklist);
            while (blacklistFlag == 0 && scan.hasNext()){
                String line = scan.nextLine();
                if (line.equals(domain)){
                    blacklistFlag = 1;
                }
            }
        }catch (FileNotFoundException e) {
        }
       return blacklistFlag;
     }
    }

Thanks, Edward.

--
View this message in context: http://squid-web-proxy-cache.1019090.n4.nabble.com/Java-external-acl-tp3447049p3447049.html
Sent from the Squid - Users mailing list archive at Nabble.com.
Received on Wed Apr 13 2011 - 12:45:37 MDT

This archive was generated by hypermail 2.2.0 : Wed Apr 13 2011 - 12:00:03 MDT