Re: [squid-users] trouble in writing my own external acl for Squid

From: Amos Jeffries <squid3_at_treenet.co.nz>
Date: Sun, 24 Aug 2008 23:10:02 +1200

Farzane wrote:
> Hi all,
> I need to write an acl for squid. this is writen in java. when I check my
> program with stdin & stdout , it works fine. I also has tried adding a
> simple test acl (getting IDENt and always print OK)to squid and it works
> fine, I mean I have no problem with external acl configuration for squid.
>
> But when I replace the simple test acl with the main one ,Squid does'nt
> works.It restarts successfully but when I try to connect to the server ,it
> says that the server is not working well.
>
> my acl should checks if the user has not used more than 1G in the last
> month. I have writen a daemon that reads access.log and stores data in a
> database (I use mysql) and the only thing the acl does , is connecting to
> database, finding username in a table and print OK or ERR base on a boolean
> col in table.
> I have the impression ,that maybe my program takes too long and makes squid
> to crash.
> I've put my acl code here too.
> Please help me ,wether fixing my own program or if you know of any other way
> that I could implement this restriction for squid users.
> Thanks,

Please state some details about yoru Squid:

  * version
  * error messages that make you think Squid is 'not working well'
  * lines from cache.log mentioning 'helper', with a few around them.

Amos

>
> ------------------------
> code:
>
>
> package IOAcl;
>
>
> import java.io.*;
>
> import java.io.BufferedReader;
>
> import java.sql.*;
>
>
> public class AclIO {
>
> static String configFilePath="/var/log/squid/aclConfig.txt";
>
> static String dbUser="root";
>
> static String dbPassword="123456";
>
> static String dbUrl="jdbc:mysql://localhost:3308/proxy";
>
> static String dbDriver="com.mysql.jdbc.Driver";
>
>
> public static void main(String[] args) throws IOException {
>
> InputStreamReader isr = new InputStreamReader(System.in);
>
>
>
>
>
> try{
>
> FileReader file = new FileReader(args[0]);
>
> BufferedReader fileInput = new BufferedReader(file);
>
> dbUser=fileInput.readLine();
>
> dbPassword=fileInput.readLine();
>
> dbUrl=fileInput.readLine();
>
> dbDriver=fileInput.readLine();
>
>
> Connection conn=null;
>
> Class.forName (dbDriver).newInstance ();
>
> conn = DriverManager.getConnection (dbUrl, dbUser,dbPassword);
>
>
> char newLine = '\n';
>
> int c;
>
> String temp=new String("");
>
> while( (c = isr.read()) != -1 ) {
>
> if((char)c == newLine) {
>
> PreparedStatement pst=conn.prepareStatement("SELECT valid
> FROM "+
>
> "users WHERE ident=?");
>
> pst.setString(1, temp);
>
> ResultSet rs=pst.executeQuery();
>
> if(rs==null || !rs.next()){
>
> System.out.println("OK");
>
> }else{
>
> boolean valid=rs.getBoolean(1);
>
> if(valid) System.out.println("OK");
>
> else System.out.println("ERR");
>
> }
>
> temp="";
>
> continue;
>
> }
>
> temp=temp+String.valueOf((char)c);
>
> }
>
> isr.close();
>
> }catch(Exception e){
>
>
> }
>
> }
>
>
> }
>

-- 
Please use Squid 2.7.STABLE4 or 3.0.STABLE8
Received on Sun Aug 24 2008 - 11:10:08 MDT

This archive was generated by hypermail 2.2.0 : Mon Aug 25 2008 - 12:00:06 MDT