当前位置: 首页>>代码示例>>PHP>>正文


PHP AIOWPSecurity_Utility_Htaccess::get_server_type方法代码示例

本文整理汇总了PHP中AIOWPSecurity_Utility_Htaccess::get_server_type方法的典型用法代码示例。如果您正苦于以下问题:PHP AIOWPSecurity_Utility_Htaccess::get_server_type方法的具体用法?PHP AIOWPSecurity_Utility_Htaccess::get_server_type怎么用?PHP AIOWPSecurity_Utility_Htaccess::get_server_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AIOWPSecurity_Utility_Htaccess的用法示例。


在下文中一共展示了AIOWPSecurity_Utility_Htaccess::get_server_type方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getrules_blacklist

 static function getrules_blacklist()
 {
     global $aio_wp_security;
     $aiowps_server = AIOWPSecurity_Utility_Htaccess::get_server_type();
     $rules = '';
     if ($aio_wp_security->configs->get_value('aiowps_enable_blacklisting') == '1') {
         //Let's do the list of blacklisted IPs first
         $hosts = explode(PHP_EOL, $aio_wp_security->configs->get_value('aiowps_banned_ip_addresses'));
         if (!empty($hosts) && !(sizeof($hosts) == 1 && trim($hosts[0]) == '')) {
             if ($aiowps_server == 'apache' || $aiowps_server == 'litespeed') {
                 $rules .= AIOWPSecurity_Utility_Htaccess::$ip_blacklist_marker_start . PHP_EOL;
                 //Add feature marker start
                 $rules .= "Order allow,deny" . PHP_EOL . "Allow from all" . PHP_EOL;
             }
             $phosts = array();
             foreach ($hosts as $host) {
                 $host = trim($host);
                 if (!in_array($host, $phosts)) {
                     if (strstr($host, '*')) {
                         $parts = array_reverse(explode('.', $host));
                         $netmask = 32;
                         foreach ($parts as $part) {
                             if (strstr(trim($part), '*')) {
                                 $netmask = $netmask - 8;
                             }
                         }
                         $dhost = trim(str_replace('*', '0', implode('.', array_reverse($parts))) . '/' . $netmask);
                         if (strlen($dhost) > 4) {
                             if ($aiowps_server == 'apache' || $aiowps_server == 'litespeed') {
                                 $trule = "Deny from " . $dhost . PHP_EOL;
                                 if (trim($trule) != 'Deny From') {
                                     $rules .= $trule;
                                 }
                             } else {
                                 $rules .= "\tdeny " . $dhost . ';' . PHP_EOL;
                             }
                         }
                     } else {
                         $dhost = trim($host);
                         if (strlen($dhost) > 4) {
                             if ($aiowps_server == 'apache' || $aiowps_server == 'litespeed') {
                                 $rules .= "Deny from " . $dhost . PHP_EOL;
                             } else {
                                 $rules .= "\tdeny " . $dhost . ";" . PHP_EOL;
                             }
                         }
                     }
                 }
                 $phosts[] = $host;
             }
             $rules .= AIOWPSecurity_Utility_Htaccess::$ip_blacklist_marker_end . PHP_EOL;
             //Add feature marker end
         }
         //Now let's do the user agent list
         $user_agents = explode(PHP_EOL, $aio_wp_security->configs->get_value('aiowps_banned_user_agents'));
         if (!empty($user_agents) && !(sizeof($user_agents) == 1 && trim($user_agents[0]) == '')) {
             if ($aiowps_server == 'apache' || $aiowps_server == 'litespeed') {
                 $rules .= AIOWPSecurity_Utility_Htaccess::$user_agent_blacklist_marker_start . PHP_EOL;
                 //Add feature marker start
                 //Start mod_rewrite rules
                 $rules .= "<IfModule mod_rewrite.c>" . PHP_EOL . "RewriteEngine On" . PHP_EOL . PHP_EOL;
                 $count = 1;
                 foreach ($user_agents as $agent) {
                     $agent_escaped = quotemeta($agent);
                     $pattern = '/\\s/';
                     //Find spaces in the string
                     $replacement = '\\s';
                     //Replace spaces with \s so apache can understand
                     $agent_sanitized = preg_replace($pattern, $replacement, $agent_escaped);
                     $rules .= "RewriteCond %{HTTP_USER_AGENT} ^" . trim($agent_sanitized);
                     if ($count < sizeof($user_agents)) {
                         $rules .= " [NC,OR]" . PHP_EOL;
                         $count++;
                     } else {
                         $rules .= " [NC]" . PHP_EOL;
                     }
                 }
                 $rules .= "RewriteRule ^(.*)\$ - [F,L]" . PHP_EOL . PHP_EOL;
             } else {
                 $count = 1;
                 $alist = '';
                 foreach ($user_agents as $agent) {
                     $alist .= trim($agent);
                     if ($count < sizeof($user_agents)) {
                         $alist .= '|';
                         $count++;
                     }
                 }
                 $rules .= "\tif (\$http_user_agent ~* " . $alist . ") { return 403; }" . PHP_EOL;
             }
         }
         //close mod_rewrite
         if (strlen($aio_wp_security->configs->get_value('aiowps_banned_user_agents')) > 0) {
             if ($aiowps_server == 'apache' || $aiowps_server == 'litespeed') {
                 $rules .= "</IfModule>" . PHP_EOL;
                 $rules .= AIOWPSecurity_Utility_Htaccess::$user_agent_blacklist_marker_end . PHP_EOL;
                 //Add feature marker end
             }
         }
     }
//.........这里部分代码省略.........
开发者ID:CarterNelms,项目名称:www.engineeredcomfort.net,代码行数:101,代码来源:wp-security-utility-htaccess.php


注:本文中的AIOWPSecurity_Utility_Htaccess::get_server_type方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。