new pisilinux web sites
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php namespace ZN\Security;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Security;
|
||||
|
||||
class CrossSiteRequestForgery
|
||||
{
|
||||
/**
|
||||
* Cross Site Request Forgery
|
||||
*
|
||||
* @param string $uri = NULL
|
||||
* @param string $type = 'post'
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function token(?string $uri = NULL, string $type = 'post')
|
||||
{
|
||||
Security::CSRFToken($uri, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get
|
||||
*
|
||||
* @param string $uri = NULL
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function get(?string $uri = NULL)
|
||||
{
|
||||
self::token($uri, 'get');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get string token
|
||||
*
|
||||
* @param string $name = 'token'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function key(string $name = 'token')
|
||||
{
|
||||
Security::createCSRFTokenKey($name);
|
||||
|
||||
return Security::getCSRFTokenKey($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Valid token
|
||||
*
|
||||
* @param string $name = 'token'
|
||||
* @param string $type = 'post'
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function validToken(string $name = 'token', string $type = 'post') : bool
|
||||
{
|
||||
return Security::validCSRFToken($name, $type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php namespace ZN\Security;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class CrossSiteScripting
|
||||
{
|
||||
/**
|
||||
* Script Bad Chars
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $scriptBadChars =
|
||||
[
|
||||
'document\.cookie' => 'document.cookie',
|
||||
'document\.write' => 'document.write',
|
||||
'\.parentNode' => '.parentNode',
|
||||
'\.innerHTML' => '.innerHTML',
|
||||
'\-moz\-binding' => '–moz–binding',
|
||||
'<' => '<',
|
||||
'>' => '>',
|
||||
];
|
||||
|
||||
/**
|
||||
* Encode Cross Site Scripting
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function encode(string $string) : string
|
||||
{
|
||||
$secBadChars = self::$scriptBadChars;
|
||||
|
||||
if( ! empty($secBadChars) )
|
||||
{
|
||||
foreach( $secBadChars as $badChar => $changeChar )
|
||||
{
|
||||
$badChar = trim($badChar, '/');
|
||||
|
||||
$string = preg_replace('/'.$badChar.'/xi', $changeChar, $string);
|
||||
}
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,442 @@
|
||||
<?php namespace ZN\Security;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class ForeignChar
|
||||
{
|
||||
/**
|
||||
* Encode Foreign Char
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function encode(string $str) : string
|
||||
{
|
||||
$chars = self::$numericalCodes;
|
||||
|
||||
return str_replace(array_keys($chars), array_values($chars), $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode Foreign Char
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function decode(string $str) : string
|
||||
{
|
||||
$chars = self::$numericalCodes;
|
||||
|
||||
return str_replace(array_values($chars), array_keys($chars), $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Numerical Codes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $numericalCodes =
|
||||
[
|
||||
'À' => 'À',
|
||||
'Ā' => 'Ā',
|
||||
'ā' => 'ā',
|
||||
'Ă' => 'Ă',
|
||||
'ă' => 'ă',
|
||||
'à' => 'à',
|
||||
'Á' => 'Á',
|
||||
'á' => 'á',
|
||||
'Â' => 'Â',
|
||||
'Ą' => 'Ą',
|
||||
'ą' => 'ą',
|
||||
'â' => 'â',
|
||||
'Ã' => 'Ã',
|
||||
'ã' => 'ã',
|
||||
'Ä' => 'Ä',
|
||||
'ä' => 'ä',
|
||||
'Å' => 'Å',
|
||||
'å' => 'å',
|
||||
'Ǎ' => 'Ǎ',
|
||||
'ǎ' => 'ǎ',
|
||||
'Ǻ' => 'Ǻ',
|
||||
'ǻ' => 'ǻ',
|
||||
'Ǽ' => 'Ǽ',
|
||||
'ǽ' => 'ǽ',
|
||||
'Ȁ' => 'Ȁ',
|
||||
'ȁ' => 'ȁ',
|
||||
'Ȃ' => 'Ȃ',
|
||||
'ȃ' => 'ȃ',
|
||||
'Ȧ' => 'Ȧ',
|
||||
'ȧ' => 'ȧ',
|
||||
'Ǟ' => 'Ǟ',
|
||||
'ǟ' => 'ǟ',
|
||||
'Ǡ' => 'Ǡ',
|
||||
'ǡ' => 'ǡ',
|
||||
'Ǣ' => 'Ǣ',
|
||||
'ǣ' => 'ǣ',
|
||||
'Ⱥ' => 'Ⱥ',
|
||||
|
||||
'ß' => 'ß',
|
||||
'ƀ' => 'ƀ',
|
||||
'Ɓ' => 'Ɓ',
|
||||
'Ƃ' => 'Ƃ',
|
||||
'ƃ' => 'ƃ',
|
||||
'Ƅ' => 'Ƅ',
|
||||
'ƅ' => 'ƅ',
|
||||
'Ƀ' => 'Ƀ',
|
||||
|
||||
'Ç' => 'Ç',
|
||||
'ç' => 'ç',
|
||||
'Ć' => 'Ć',
|
||||
'ć' => 'ć',
|
||||
'Ĉ' => 'Ĉ',
|
||||
'ĉ' => 'ĉ',
|
||||
'Ċ' => 'Ċ',
|
||||
'ċ' => 'ċ',
|
||||
'Č' => 'Č',
|
||||
'č' => 'č',
|
||||
'Ɔ' => 'Ɔ',
|
||||
'Ƈ' => 'Ƈ',
|
||||
'ƈ' => 'ƈ',
|
||||
'Ȼ' => 'Ȼ',
|
||||
'ȼ' => 'ȼ',
|
||||
|
||||
'Ð' => 'Ð',
|
||||
'ð' => 'ð',
|
||||
'Ď' => 'Ď',
|
||||
'ď' => 'ď',
|
||||
'Đ' => 'Đ',
|
||||
'đ' => 'đ',
|
||||
'Ɖ' => 'Ɖ',
|
||||
'Ɗ' => 'Ɗ',
|
||||
'Ƌ' => 'Ƌ',
|
||||
'ƌ' => 'ƌ',
|
||||
'ƍ' => 'ƍ',
|
||||
'ȡ' => 'ȡ',
|
||||
'ȸ' => 'ȸ',
|
||||
|
||||
'È' => 'È',
|
||||
'è' => 'è',
|
||||
'É' => 'É',
|
||||
'é' => 'é',
|
||||
'Ê' => 'Ê',
|
||||
'ê' => 'ê',
|
||||
'Ë' => 'Ë',
|
||||
'ë' => 'ë',
|
||||
'Ē' => 'Ē',
|
||||
'ē' => 'ē',
|
||||
'Ĕ' => 'Ĕ',
|
||||
'ĕ' => 'ĕ',
|
||||
'Ė' => 'Ė',
|
||||
'ė' => 'ė',
|
||||
'Ę' => 'Ę',
|
||||
'ę' => 'ę',
|
||||
'Ě' => 'Ě',
|
||||
'ě' => 'ě',
|
||||
'Ǝ' => 'Ǝ',
|
||||
'Ə' => 'Ə',
|
||||
'Ɛ' => 'Ɛ',
|
||||
'ǝ' => 'ǝ',
|
||||
'Ȅ' => 'Ȅ',
|
||||
'ȅ' => 'ȅ',
|
||||
'Ȇ' => 'Ȇ',
|
||||
'ȇ' => 'ȇ',
|
||||
'Ȩ' => 'Ȩ',
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',
|
||||
|
||||
'Ŕ' => 'Ŕ',
|
||||
'ŕ' => 'ŕ',
|
||||
'Ŗ' => 'Ŗ',
|
||||
'ŗ' => 'ŗ',
|
||||
'Ř' => 'Ř',
|
||||
'ř' => 'ř',
|
||||
'Ʀ' => 'Ʀ',
|
||||
'Ȑ' => 'Ȑ',
|
||||
'ȑ' => 'ȑ',
|
||||
'Ȓ' => 'Ȓ',
|
||||
'ȓ' => 'ȓ',
|
||||
'Ɍ' => 'Ɍ',
|
||||
'ɍ' => 'ɍ',
|
||||
|
||||
'Ś' => 'Ś',
|
||||
'ś' => 'ś',
|
||||
'Ŝ' => 'Ŝ',
|
||||
'ŝ' => 'ŝ',
|
||||
'Ş' => 'Ş',
|
||||
'ş' => 'ş',
|
||||
'Š' => 'Š',
|
||||
'š' => 'š',
|
||||
'Ƨ' => 'Ƨ',
|
||||
'ƨ' => 'ƨ',
|
||||
'Ș' => 'Ș',
|
||||
'ș' => 'ș',
|
||||
'ȿ' => 'ȿ',
|
||||
|
||||
'Ʃ' => 'Ʃ',
|
||||
'ƪ' => 'ƪ',
|
||||
|
||||
'Ţ' => 'Ţ',
|
||||
'ţ' => 'ţ',
|
||||
'Ť' => 'Ť',
|
||||
'ť' => 'ť',
|
||||
'Ŧ' => 'Ŧ',
|
||||
'ŧ' => 'ŧ',
|
||||
'ƫ' => 'ƫ',
|
||||
'Ƭ' => 'Ƭ',
|
||||
'ƭ' => 'ƭ',
|
||||
'Ʈ' => 'Ʈ',
|
||||
'Ț' => 'Ț',
|
||||
'ț' => 'ț',
|
||||
'ȶ' => 'ȶ',
|
||||
'Ⱦ' => 'Ⱦ',
|
||||
|
||||
'Ù' => 'Ù',
|
||||
'ù' => 'ù',
|
||||
'Ú' => 'Ú',
|
||||
'ú' => 'ú',
|
||||
'Û' => 'Û',
|
||||
'û' => 'û',
|
||||
'Ü' => 'Ü',
|
||||
'ü' => 'ü',
|
||||
'Ũ' => 'Ũ',
|
||||
'ũ' => 'ũ',
|
||||
'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'Ƶ' => 'Ƶ',
|
||||
'ƶ' => 'ƶ',
|
||||
'Ȥ' => 'Ȥ',
|
||||
'ȥ' => 'ȥ',
|
||||
'ɀ' => 'ɀ',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php namespace ZN\Security;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Controller\Factory;
|
||||
|
||||
class Guard extends Factory
|
||||
{
|
||||
const factory =
|
||||
[
|
||||
'methods' =>
|
||||
[
|
||||
'timeonstay' => 'TimeOnStay::create',
|
||||
'validtimeonstay' => 'TimeOnStay::valid',
|
||||
'ncencode' => 'NastyCode::encode',
|
||||
'injectionencode' => 'Injection::encode',
|
||||
'injectiondecode' => 'Injection::decode',
|
||||
'nailencode' => 'Injection::nailEncode',
|
||||
'naildecode' => 'Injection::nailDecode',
|
||||
'escapestringencode' => 'Injection::escapeStringEncode',
|
||||
'escapestringdecode' => 'Injection::escapeStringDecode',
|
||||
'xssencode' => 'CrossSiteScripting::encode',
|
||||
'csrftoken' => 'CrossSiteRequestForgery::token',
|
||||
'csrfpost' => 'CrossSiteRequestForgery::token',
|
||||
'csrfget' => 'CrossSiteRequestForgery::get',
|
||||
'csrftokenkey' => 'CrossSiteRequestForgery::key',
|
||||
'validcsrftokenkey' => 'CrossSiteRequestForgery::validToken',
|
||||
'htmlencode' => 'Html::encode',
|
||||
'htmldecode' => 'Html::decode',
|
||||
'htmltagclean' => 'Html::tagClean',
|
||||
'phptagencode' => 'PHP::encode',
|
||||
'phptagdecode' => 'PHP::decode',
|
||||
'phptagclean' => 'PHP::tagClean',
|
||||
'scripttagencode' => 'Script::encode',
|
||||
'scripttagdecode' => 'Script::decode',
|
||||
'foreigncharencode' => 'ForeignChar::encode',
|
||||
'foreignchardecode' => 'ForeignChar::decode'
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php namespace ZN\Security;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Helper;
|
||||
|
||||
class Html
|
||||
{
|
||||
/**
|
||||
* Encode HTML
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $type = 'quotes'
|
||||
* @param string $encoding = 'utf-8'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function encode(string $string, string $type = 'quotes', string $encoding = 'utf-8') : string
|
||||
{
|
||||
return str_replace('&', '&', htmlspecialchars(trim($string), Helper::toConstant($type, 'ENT_'), $encoding, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode HTML
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $type = 'quotes'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function decode(string $string, string $type = 'quotes') : string
|
||||
{
|
||||
return htmlspecialchars_decode(trim($string), Helper::toConstant($type, 'ENT_'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean HTML Tag
|
||||
*
|
||||
* @param string $string
|
||||
* @param mixed $allowable = ''
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function tagClean(string $string, $allowable = '') : string
|
||||
{
|
||||
return strip_tags(self::decode($string), $allowable);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php namespace ZN\Security;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Injection
|
||||
{
|
||||
/**
|
||||
* Nail Chars
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $nailChars =
|
||||
[
|
||||
"'" => "'",
|
||||
'"' => """
|
||||
];
|
||||
|
||||
/**
|
||||
* Encode Injection Chars
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function encode(string $string) : string
|
||||
{
|
||||
$secBadChars = Properties::$injectionBadChars;
|
||||
|
||||
if( ! empty($secBadChars) )
|
||||
{
|
||||
foreach( $secBadChars as $badChar => $changeChar )
|
||||
{
|
||||
$badChar = trim($badChar, '/');
|
||||
$string = preg_replace('/'.$badChar.'/xi', $changeChar, $string);
|
||||
}
|
||||
}
|
||||
|
||||
return addslashes(trim($string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode Injection Chars
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function decode(string $string) : string
|
||||
{
|
||||
return stripslashes(trim($string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode Nail Chars
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function nailEncode(string $str) : string
|
||||
{
|
||||
$str = str_replace(array_keys(self::$nailChars), array_values(self::$nailChars), $str);
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode Nail Chars
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function nailDecode(string $str) : string
|
||||
{
|
||||
$str = str_replace(array_values(self::$nailChars), array_keys(self::$nailChars), $str);
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode Escape String
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function escapeStringEncode(string $data) : string
|
||||
{
|
||||
return addslashes($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode Escape String
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function escapeStringDecode(string $data) : string
|
||||
{
|
||||
return stripslashes($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php namespace ZN\Security;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Singleton;
|
||||
|
||||
class NastyCode
|
||||
{
|
||||
/**
|
||||
* Encode Nasty Code
|
||||
*
|
||||
* @param string $string
|
||||
* @param mixed $badWords = NULL
|
||||
* @param mixed $changeChar = '[badchars]'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function encode(string $string, $badWords = NULL, $changeChar = '[badchars]') : string
|
||||
{
|
||||
if( empty($badWords) )
|
||||
{
|
||||
$secnc = Properties::$ncEncode;
|
||||
$badWords = $secnc['badChars'];
|
||||
$changeChar = $secnc['changeBadChars'];
|
||||
}
|
||||
|
||||
$regex = Singleton::class('ZN\Regex');
|
||||
|
||||
if( ! is_array($badWords) )
|
||||
{
|
||||
return $string = $regex->replace($badWords, $changeChar, $string, 'xi');
|
||||
}
|
||||
|
||||
$ch = '';
|
||||
$i = 0;
|
||||
|
||||
foreach( $badWords as $value )
|
||||
{
|
||||
if( ! is_array($changeChar) )
|
||||
{
|
||||
$ch = $changeChar;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( isset($changeChar[$i]) )
|
||||
{
|
||||
$ch = $changeChar[$i];
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
$string = $regex->replace($value, $ch, $string, 'xi');
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php namespace ZN\Security;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class PHP
|
||||
{
|
||||
/**
|
||||
* PHP Tag Chars
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $phpTagChars =
|
||||
[
|
||||
'<?' => '<?',
|
||||
'?>' => '?>'
|
||||
];
|
||||
|
||||
/**
|
||||
* Encode PHP Tag
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function encode(string $str) : string
|
||||
{
|
||||
return str_replace(array_keys(self::$phpTagChars), array_values(self::$phpTagChars), $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode PHP Tag
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function decode(string $str) : string
|
||||
{
|
||||
return str_replace(array_values(self::$phpTagChars), array_keys(self::$phpTagChars), $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean PHP Tag
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function tagClean(string $str) : string
|
||||
{
|
||||
return str_ireplace(['<?php', '<?', '?>'], '', $str);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php namespace ZN\Security;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Properties
|
||||
{
|
||||
/**
|
||||
* Encode Nasty Chars
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $ncEncode =
|
||||
[
|
||||
'badChars' => # string or array
|
||||
[
|
||||
'<!--',
|
||||
'-->',
|
||||
'<?',
|
||||
'?>',
|
||||
'<',
|
||||
'>'
|
||||
],
|
||||
|
||||
'changeBadChars' => '[badchars]' # string veya array
|
||||
];
|
||||
|
||||
/**
|
||||
* Indection Bad Chars
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $injectionBadChars =
|
||||
[
|
||||
'or.+\=' => '',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php namespace ZN\Security;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Script
|
||||
{
|
||||
/**
|
||||
* Script Tag Chars
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $scriptTagChars =
|
||||
[
|
||||
'/\<script(.*?)\>/i' => '<script$1>',
|
||||
'/\<\/script\>/i' => '</script>'
|
||||
];
|
||||
|
||||
/**
|
||||
* Script Tag Chars Decode
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $scriptTagCharsDecode =
|
||||
[
|
||||
'/\&\#60\;script(.*?)\&\#62\;/i' => '<script$1>',
|
||||
'/\&\#60\;\/script\&\#62\;/i' => '</script>'
|
||||
];
|
||||
|
||||
/**
|
||||
* Encode Script Tags
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function encode(string $str) : string
|
||||
{
|
||||
return preg_replace
|
||||
(
|
||||
array_keys(self::$scriptTagChars),
|
||||
array_values(self::$scriptTagChars),
|
||||
$str
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode Script Tags
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function decode(string $str) : string
|
||||
{
|
||||
return preg_replace
|
||||
(
|
||||
array_keys(self::$scriptTagCharsDecode),
|
||||
array_values(self::$scriptTagCharsDecode),
|
||||
$str
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php namespace ZN\Security;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Ability\Serialization;
|
||||
|
||||
#[\AllowDynamicProperties]
|
||||
|
||||
class Secure
|
||||
{
|
||||
use Serialization;
|
||||
|
||||
const serialization =
|
||||
[
|
||||
'class' => 'Guard',
|
||||
'start' => 'data',
|
||||
'end' => 'get'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php namespace ZN\Security;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class TimeOnStay
|
||||
{
|
||||
/**
|
||||
* Create time to stay on the page
|
||||
*
|
||||
* @param string $name = 'timeOnStay'
|
||||
*/
|
||||
public static function create(string $name = 'timeOnStay')
|
||||
{
|
||||
$_SESSION[$name] = time();
|
||||
}
|
||||
|
||||
/**
|
||||
* Valid time to stay on the page
|
||||
*
|
||||
* @param int $time = 5
|
||||
* @param string $name = 'timeOnStay'
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function valid(int $time = 5, string $name = 'timeOnStay') : bool
|
||||
{
|
||||
if( empty($_SESSION[$name]) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$pagetime = time() - $_SESSION[$name];
|
||||
|
||||
if( $pagetime >= $time )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user