LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-29-2010, 01:47 AM   #1
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Rep: Reputation: 30
CentOS SQL Proxy


Hello All,

Im trying to set up a Proxy server on my CentOS server and I have been looking at Squid, however I wondered if there is a proxy server that will support having authenticated users and passwords in a MySQL database?

I wanted to do this so I have good control over who is connected through my proxy.

Thanks in advance,
trscookie.
 
Old 11-29-2010, 02:05 AM   #2
kirukan
Senior Member
 
Registered: Jun 2008
Location: Eelam
Distribution: Redhat, Solaris, Suse
Posts: 1,278

Rep: Reputation: 148Reputation: 148
Refer the following
http://people.arxnet.hu/airween/mysql_auth/
 
Old 11-29-2010, 03:48 AM   #3
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Original Poster
Rep: Reputation: 30
Humm,

I've followed the guide however on CentOS squid doesnt come with mysql_auth. It does however come with the following:


Code:
[root@server squid]# pwd
/usr/lib64/squid
[root@server squid]# ls -ltr
total 348
-rwxr-xr-x 1 root root   2280 Mar 31  2010 smb_auth.sh
-rwxr-xr-x 1 root root   4010 Mar 31  2010 smb_auth.pl
-rwxr-xr-x 1 root root   2359 Mar 31  2010 wbinfo_group.pl
-rwxr-xr-x 1 root root  10992 Mar 31  2010 yp_auth
-rwxr-xr-x 1 root root   4928 Mar 31  2010 unlinkd
-rwxr-xr-x 1 root root  11776 Mar 31  2010 squid_unix_group
-rwxr-xr-x 1 root root  19376 Mar 31  2010 squid_ldap_group
-rwxr-xr-x 1 root root  18048 Mar 31  2010 squid_ldap_auth
-rwxr-xr-x 1 root root  24200 Mar 31  2010 squid_kerb_auth
-rwxr-xr-x 1 root root  11264 Mar 31  2010 smb_auth
-rwxr-xr-x 1 root root  10992 Mar 31  2010 sasl_auth
-rwsr-x--- 1 root squid 12384 Mar 31  2010 pam_auth
-rwxr-xr-x 1 root root  46504 Mar 31  2010 ntlm_auth
-rwsr-x--- 1 root squid 15672 Mar 31  2010 ncsa_auth
-rwxr-xr-x 1 root root  37488 Mar 31  2010 msnt_auth
-rwxr-xr-x 1 root root  11352 Mar 31  2010 ip_user_check
-rwxr-xr-x 1 root root   9688 Mar 31  2010 getpwname_auth
-rwxr-xr-x 1 root root  12480 Mar 31  2010 fakeauth_auth
-rwxr-xr-x 1 root root  13312 Mar 31  2010 diskd-daemon
-rwxr-xr-x 1 root root  15360 Mar 31  2010 digest_pw_auth
-rwxr-xr-x 1 root root  23960 Mar 31  2010 cachemgr.cgi
[root@server squid]#

Is it possible to write my own authentication script if so, how does it work? I cant find out how it passes in the user, password and all that.

Cheers again,
trscookie.
 
Old 11-29-2010, 06:07 AM   #4
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Original Poster
Rep: Reputation: 30
Ah I may have just found something that might help:

http://www.freesoftwaremagazine.com/...ion_with_squid
 
Old 11-29-2010, 11:18 AM   #5
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Original Poster
Rep: Reputation: 30
Ok, now I have a new error!!! I have tried to create my own auth script however I just get crap in the log files and I cant find anything useful on google:


/var/log/squid/cache.log:
Code:
1031 2010/11/29 18:18:18| helperHandleRead: unexpected read from basicauthenticator #4, 3 bytes 'ERR'
1032 2010/11/29 18:18:18| helperHandleRead: unexpected read from basicauthenticator #5, 3 bytes 'ERR'
1033 2010/11/29 18:19:18| helperHandleRead: unexpected read from basicauthenticator #3, 3 bytes 'ERR'
1034 2010/11/29 18:19:18| helperHandleRead: unexpected read from basicauthenticator #2, 3 bytes 'ERR'
1035 2010/11/29 18:19:18| helperHandleRead: unexpected read from basicauthenticator #4, 3 bytes 'ERR'
1036 2010/11/29 18:19:18| helperHandleRead: unexpected read from basicauthenticator #5, 3 bytes 'ERR'

squid.conf:
Code:
 10 auth_param basic program /usr/bin/php /usr/lib64/squid/sql_auth.php
 11 auth_param basic children 5
 12 auth_param basic realm Linux Class
 13 auth_param basic credentialsttl 2 hours
 14 auth_param basic casesensitive off
 15 
 16 acl class proxy_auth REQUIRED
 17 http_access allow class
 18

My auth script - /usr/lib64/squid/sql_auth.php:
Code:
<?php
DEFINE('DB_USER', 'squid');
DEFINE('DB_PASSWORD', 'password');
DEFINE('DB_HOST', 'localhost');
DEFINE('DB_NAME', 'squid');


while(!feof(STDIN))
        {
        $line = trim(fgets(STDIN));
        $fields = explode(' ', $line);

        if(isset($fields[0]))
                {
                $username = rawurldecode($fields[0]);
                }
        if(isset($fields[1]))
                {
                $password = rawurldecode($fields[1]);
                }

        if($username == 'quit')
                {
                exit();
                }

        if(strlen($username)>0 && strlen($password)>0)
                {
                $dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

                $q = "SELECT id FROM users WHERE user = '$username' AND password = SHA1('$password') AND enabled = 'Y' AND paid_dstamp > DATE_SUB(NOW(), I
NTERVAL 1 YEAR);";
                $r = @mysqli_query($dbc, $q);

                if(mysqli_num_rows($r)== 1)
                        {
                        fwrite(STDOUT, "OK\n");
                        }
                else
                        {
                        fwrite(STDOUT, "ERR\n");
                        }

                mysqli_close($dbc);
                }
        else
                {
                // failed miserably
                fwrite(STDOUT, "ERR\n");
                }
        }

I believe that this error is causing my authentication to fail, however the script returns OK or ERR in the command line when passing the values in, such as:

Code:
root@server squid]# php /usr/lib64/squid/sql_auth.php 
trscookie mypass
OK
trscookie crappass
ERR
quit
[root@server squid]#

Any ideas would be more than appreciated.

Many thanks,
trscookie

Last edited by trscookie; 11-29-2010 at 11:43 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Proxy issue in CentOS raghureddii Linux - Server 2 08-22-2010 10:05 AM
proxy server with SQL table user authentication venkateven Linux - Newbie 1 06-16-2010 12:43 AM
Centos behind proxy Centos_user Linux - Networking 4 03-02-2010 01:03 AM
Problem with connect to Remote Sql Server 2000 from centos 4.5 with PHP rufat Linux - Software 12 02-08-2010 06:54 AM
Centos 5 YUM/Proxy metallica1973 Red Hat 6 01-30-2009 11:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration