Andrey Andreev | a381d17 | 2012-01-06 19:19:37 +0200 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | a381d17 | 2012-01-06 19:19:37 +0200 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | a381d17 | 2012-01-06 19:19:37 +0200 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | /** |
| 29 | * CodeIgniter Security Helpers |
| 30 | * |
| 31 | * @package CodeIgniter |
| 32 | * @subpackage Helpers |
| 33 | * @category Helpers |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 34 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 35 | * @link http://codeigniter.com/user_guide/helpers/security_helper.html |
| 36 | */ |
| 37 | |
| 38 | // ------------------------------------------------------------------------ |
| 39 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 40 | if ( ! function_exists('xss_clean')) |
| 41 | { |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 42 | /** |
| 43 | * XSS Filtering |
| 44 | * |
| 45 | * @param string |
| 46 | * @param bool whether or not the content is an image file |
| 47 | * @return string |
| 48 | */ |
Derek Jones | f0bcb3c | 2009-02-10 18:40:21 +0000 | [diff] [blame] | 49 | function xss_clean($str, $is_image = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 50 | { |
| 51 | $CI =& get_instance(); |
Derek Jones | 11b1e51 | 2010-03-05 10:22:44 -0600 | [diff] [blame] | 52 | return $CI->security->xss_clean($str, $is_image); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | |
Derek Allard | 4433f42 | 2010-07-23 08:47:34 -0400 | [diff] [blame] | 56 | // ------------------------------------------------------------------------ |
| 57 | |
Derek Allard | 4433f42 | 2010-07-23 08:47:34 -0400 | [diff] [blame] | 58 | if ( ! function_exists('sanitize_filename')) |
| 59 | { |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 60 | /** |
| 61 | * Sanitize Filename |
| 62 | * |
| 63 | * @param string |
| 64 | * @return string |
| 65 | */ |
Derek Allard | 4433f42 | 2010-07-23 08:47:34 -0400 | [diff] [blame] | 66 | function sanitize_filename($filename) |
| 67 | { |
| 68 | $CI =& get_instance(); |
| 69 | return $CI->security->sanitize_filename($filename); |
| 70 | } |
| 71 | } |
| 72 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 73 | // -------------------------------------------------------------------- |
| 74 | |
Derek Allard | 8719a5c | 2009-10-08 16:42:59 +0000 | [diff] [blame] | 75 | if ( ! function_exists('do_hash')) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 76 | { |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 77 | /** |
| 78 | * Hash encode a string |
| 79 | * |
Andrey Andreev | 0f0b769 | 2012-06-07 14:57:04 +0300 | [diff] [blame] | 80 | * This function is DEPRECATED and should be removed in |
| 81 | * CodeIgniter 3.1+. Use hash() instead. |
| 82 | * |
Andrey Andreev | d1cace7 | 2012-06-17 03:01:00 +0300 | [diff] [blame] | 83 | * @deprecated |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 84 | * @param string |
| 85 | * @param string |
| 86 | * @return string |
| 87 | */ |
Derek Allard | 8719a5c | 2009-10-08 16:42:59 +0000 | [diff] [blame] | 88 | function do_hash($str, $type = 'sha1') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 89 | { |
Andrey Andreev | 7eea306 | 2012-03-19 12:58:45 +0200 | [diff] [blame] | 90 | if ( ! in_array(strtolower($type), hash_algos())) |
Andrey Andreev | 50bff7c | 2012-03-19 12:16:38 +0200 | [diff] [blame] | 91 | { |
| 92 | $type = 'md5'; |
| 93 | } |
| 94 | |
freewil | 8840c96 | 2012-03-18 15:23:09 -0400 | [diff] [blame] | 95 | return hash($type, $str); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 96 | } |
| 97 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 98 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 99 | // ------------------------------------------------------------------------ |
| 100 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 101 | if ( ! function_exists('strip_image_tags')) |
| 102 | { |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 103 | /** |
| 104 | * Strip Image Tags |
| 105 | * |
| 106 | * @param string |
| 107 | * @return string |
| 108 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 109 | function strip_image_tags($str) |
| 110 | { |
Andrey Andreev | 1a24a9d | 2012-06-27 00:52:47 +0300 | [diff] [blame] | 111 | $CI =& get_instance(); |
| 112 | return $CI->security->strip_image_tags($str); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 113 | } |
| 114 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 115 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 116 | // ------------------------------------------------------------------------ |
| 117 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 118 | if ( ! function_exists('encode_php_tags')) |
| 119 | { |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 120 | /** |
| 121 | * Convert PHP tags to entities |
| 122 | * |
| 123 | * @param string |
| 124 | * @return string |
| 125 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 126 | function encode_php_tags($str) |
| 127 | { |
vkeranov | 3c298dc | 2012-07-12 11:04:02 +0300 | [diff] [blame^] | 128 | return str_replace(array('<?', '?>'), array('<?', '?>'), $str); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 132 | /* End of file security_helper.php */ |
Andrey Andreev | e92df33 | 2012-03-26 22:44:20 +0300 | [diff] [blame] | 133 | /* Location: ./system/helpers/security_helper.php */ |