[squid-users] Receiving blank input in External ACL

Eliezer Croitoru eliezer at ngtech.co.il
Wed Feb 11 18:25:15 UTC 2015


Hey Alberto,

PHP as a squid helper turned to be a bad choice.
I know that Ruby,Python,Perl,Golang and many others do work fine with squid.

All The Bests,
Eliezer

On 11/02/2015 17:43, Alberto Perez wrote:
> # Set up the normal session helper.
> external_acl_type session_active_def concurrency=1 children-max=15
> children-startup=12  ipv4 ttl=3 negative_ttl=1 %SRC
> /etc/squid3/captive/sessionHelper.php
>
> And here the code
>
> #!/usr/bin/php
> <?php
> error_reporting(0);
> $meminstance = new Memcache();
> $meminstance->pconnect('127.0.0.1', 11211);
> ini_set("memory_limit",($memoryLimit=512)."M");
> while (!@feof(STDIN)) {
> try{
>
> 	$line = trim(fgets(STDIN));
> 	if (!$line) { shell_exec("echo \"SESSION - No client ip error: \"
> ".$line." - "." - $(date) >> /var/log/squid3/session.log");
> fwrite(STDOUT, "ERR\n"); continue;}
>
> 	$line = explode(" ", $line);
>
> 	$clientip = count($line > 1)?$line[1]:false; //1738
>
> 	if (!$clientip) { shell_exec("echo \"SESSION - No client ip error: \"
> ".$line." - "." - $(date) >> /var/log/squid3/session.log");
> fwrite(STDOUT, "ERR\n"); continue;}
>
> 	 $username = $meminstance->get($clientip);
> 	$hasInternet = $username?$meminstance->get("has_internet_$username"):false;
> 	if ($username && $hasInternet){
> 			// extend session
>   			$meminstance->set($clientip, $username, 0,3600); // extend 10 min
> 			$meminstance->set("ip_".$username, $clientip, 0, 3600); // 10 min
> 			$meminstance->set("has_internet_".$username, true, 0, 3600); // 10 min
> 	                fwrite(STDOUT, "OK user=$username\n");
> 	}else{
>          	fwrite(STDOUT, "ERR\n");
> 	}
> }catch(Exception $e){
>          	fwrite(STDOUT, "BH\n");
> }
> }
> exit;
> ?>
>
>
>
> Thanks to all




More information about the squid-users mailing list