Files
UNIT3D-Community-Edition/app/Http/Middleware/HtmlEncrypt.php
HDVinnie 77a8c2140a (Update) NOTICE OF LICENSE
- Updated Author Names To Match GitHub Usernames For Clarity.
2017-12-15 22:45:37 -05:00

81 lines
2.0 KiB
PHP

<?php
/**
* NOTICE OF LICENSE
*
* UNIT3D is open-sourced software licensed under the GNU General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D
* @license https://choosealicense.com/licenses/gpl-3.0/ GNU General Public License v3.0
* @author HDVinnie
*/
namespace App\Http\Middleware;
use Closure;
class HtmlEncrypt
{
private $hex;
/**
* HtmlEncrypt constructor.
*/
public function __construct()
{
$this->hex = '';
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
/**
* @var $response Response
*/
$response = $next($request);
if ($request->isMethod('get') && !$request->ajax()) {
$contentType = $response->headers->get('Content-Type');
if (strpos($contentType, 'text/html') !== false) {
$response->setContent($this->encryptHtml($response->getContent()));
}
}
return $response;
}
public function encryptHtml($content)
{
$text = str_split(bin2hex($content), 2);
array_walk($text, function (&$a) {
$this->addHexValue('%' . $a);
});
$script = '<script type="text/javascript">document.writeln(unescape("' . $this->hex . '"));</script>';
if (config('html-encrypt.disable_right_click')) {
$script .= '<script>var body = document.getElementsByTagName("body")[0];var att = document.createAttribute("oncontextmenu");att.value = "return false";body.setAttributeNode(att);</script>';
}
if (config('html-encrypt.disable_ctrl_and_F12_key')) {
$script .= '<script>document.onkeydown=function(e){if(e.ctrlKey || e.keyCode == 123){return false}}</script>';
}
return $script;
}
public function addHexValue($hex)
{
$this->hex .= $hex;
}
}