Linux-CentOS XAMPP Apache 防盗链模块mod_auth_token的安装配置

来源:互联网 发布:淘宝买港版note7怎么退 编辑:程序博客网 时间:2024/06/06 03:20

【1】下载

https://code.google.com/p/mod-auth-token/



【2】编译

[plain] view plain copy
 print?
  1. rm -f configure  
  2. autoreconf -fi  
  3. automake -f  
  4. ./configure  
  5. make  
【3】配置httpd.conf

是否添加

[plain] view plain copy
 print?
  1. LoadModule auth_token_module  modules/mod_auth_token.so  
【4】配置httpd-vhosts.conf

假名preview指向mnt。

[plain] view plain copy
 print?
  1. Alias /preview "/mnt"  
  2. <Location /preview/>   
  3.    AuthTokenSecret      "s3cr3tstr1ng"   
  4.    AuthTokenPrefix       /preview/  
  5.    AuthTokenTimeout     3600   
  6.    AuthTokenLimitByIp    on   
  7. </Location>  
【5】编码

传入系统文件的path,返回http协议的防盗链path

[php] view plain copy
 print?
  1. public  static function get_auth_token_URI($sRelPath)  
  2.     {  
  3.         $secret        = "s3cr3tstr1ng";     // Same as AuthTokenSecret  
  4.         $protectedPath = "/preview/";        // Same as AuthTokenPrefix  
  5.         $ipLimitation  = true;               // Same as AuthTokenLimitByIp  
  6.         $hexTime       = dechex(time());     // Time in Hexadecimal  
  7.    
  8.         //  /mnt/volume1/2015/12/2/18/3/24637b61-a010-49cc-8c2d-6a0005abf2e5    
  9.         $fileName      = substr($sRelPath, 4); // The file to access  
  10.    
  11.         // Let's generate the token depending if we set AuthTokenLimitByIp  
  12.         if ($ipLimitation)  
  13.         {  
  14.             $token = md5($secret . $fileName . $hexTime . $_SERVER['REMOTE_ADDR']);  
  15.         }  
  16.         else  
  17.         {  
  18.             $token = md5($secret . $fileName$hexTime);  
  19.         }  
  20.    
  21.         // We build the url  
  22.         $httpOrigin = null;  
  23.         if(isset($_SERVER['HTTP_ORIGIN'] ))  
  24.             $httpOrigin = $_SERVER['HTTP_ORIGIN'];  
  25.         else  
  26.             $httpOrigin = 'http://' . $_SERVER['HTTP_HOST'];  
  27.    
  28.         $url = $httpOrigin . $protectedPath . $token"/" . $hexTime . $fileName;  
  29.         return $url;  
  30.     }  

转自 http://blog.csdn.net/aoshilang2249/article/details/50301505

0 0
原创粉丝点击