免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5874 | 回复: 5
打印 上一主题 下一主题

[proxy] [squid 重定向器应用实例]我想通过SQUID R。A。P。E 用户的意向[问题已经解决] [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-01-19 10:08 |只看该作者 |倒序浏览
网关用OPENBSD+PF +SQUID 做了透明代理,所有用户访问外部80 都要通过SQUID,现在我想在代理上设置一下,让客户在我们公司上网时,第一次访打开任何网页,可以重定向到公司的主页,或直接用公司网站的内容来取代,让他们看看咱公司的主页,有没有办法?
--------------------------
解决方法:
在squid.conf 加入下面代码

  1. redirect_program /etc/pftable/red.pl
  2. redirect_children 10
  3. redirector_bypass on
复制代码


/etc/pftable/red.pl 内容如下

  1. #!/usr/bin/perl -wl
  2. #
  3. use strict;
  4. use DB_File;
  5. $|=1;
  6. use vars qw(%ip $uri);
  7. my $db=tie %ip,"DB_File","/tmp/ip.db",O_CREAT|O_RDWR,0666;
  8. while (<>){
  9.         my ($client,$ident,$method)=();
  10.         ($uri,$client,$ident,$method)=split;
  11.          if (exists $ip{$client}){
  12.                 next;
  13.         }else{
  14.                 $ip{$client}=1;
  15.                 $db->sync;
  16.                 $uri="301:[url]http://www.163.cn[/url]";
  17.         }
  18. }continue{
  19.         print "$uri";
  20. }
  21. untie %ip;
复制代码

[ 本帖最后由 fengyong 于 2008-1-22 15:34 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2008-01-21 11:41 |只看该作者
没人回复,自己顶一下。

论坛徽章:
2
2015年辞旧岁徽章
日期:2015-03-03 16:54:1515-16赛季CBA联赛之上海
日期:2016-05-05 09:45:14
3 [报告]
发表于 2008-01-21 13:31 |只看该作者
不过你的好像也有点复杂了!

论坛徽章:
0
4 [报告]
发表于 2008-01-22 15:36 |只看该作者
新版带缓存的程序

  1. # cat /etc/pftable/red.pl                                                                                                        
  2. #!/usr/bin/perl -w
  3. # author fengyong 2008-01-22
  4. use strict;
  5. use DB_File;
  6. use vars qw (%cache $uri $cachetime);
  7. $|=1;
  8. my $timeout=3600;#缓存超时时间

  9. while (<>){
  10.         my ($client,$ident,$method)=();
  11.         ($uri,$client,$ident,$method)=split;
  12.         if (check($client)){
  13.                 next;
  14.         }else{
  15.                 save($client);
  16.                 $uri="301:[url]http://www.xxxx.cn[/url]";
  17.         }
  18. }continue{
  19.         print $uri;
  20. }
  21. sub check {
  22.         my $client=shift;
  23.         # init cache time
  24.         my $time=time();
  25.         if (!$cachetime){
  26.                 $cachetime=$time+$timeout;
  27.         }
  28.         if ($time > $cachetime){
  29.                 %cache=();
  30.                 $cachetime=();
  31.         }
  32.         return 1 if $cache{$client};
  33.         
  34.         # reopen db
  35.         my %ip=();
  36.         tie %ip,"DB_File","/tmp/ip.db",O_CREAT|O_RDWR,0666;
  37.         %cache=%ip; #hard copy?
  38.         untie %ip;
  39.         $cache{$client} ? 1:0;
  40. }
  41. sub save {
  42.         my $client=shift;

  43.         my %ip=();
  44.         tie %ip,"DB_File","/tmp/ip.db",O_CREAT|O_RDWR,0666;
  45.         $ip{$client}=1;
  46.         untie %ip;
  47. }
复制代码

[ 本帖最后由 fengyong 于 2008-1-22 16:09 编辑 ]

论坛徽章:
0
5 [报告]
发表于 2008-01-22 15:41 |只看该作者
BZ加个精吧

论坛徽章:
0
6 [报告]
发表于 2011-01-10 12:18 |只看该作者
LZ你好,我是在windows下想实现跟你一样的效果
但是启动后好像squid不能执行perl程序

redirect_program /etc/pftable/red.pl
不知道windows下应该怎么调用外部程序
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP