├── .gitignore
├── LICENSE
├── README.md
├── composer.json
├── config
└── laravel-html-encrypt.php
├── phpunit.xml
├── src
├── LaravelHtmlEncryptServiceProvider.php
└── Middleware
│ └── HtmlEncrypt.php
└── tests
├── HtmlEncryptTest.php
└── TestCase.php
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### JetBrains template
3 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
4 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
5 |
6 | # User-specific stuff:
7 | .idea/**/workspace.xml
8 | .idea/**/tasks.xml
9 | .idea/dictionaries
10 |
11 | # Sensitive or high-churn files:
12 | .idea/**/dataSources/
13 | .idea/**/dataSources.ids
14 | .idea/**/dataSources.xml
15 | .idea/**/dataSources.local.xml
16 | .idea/**/sqlDataSources.xml
17 | .idea/**/dynamic.xml
18 | .idea/**/uiDesigner.xml
19 |
20 | # Gradle:
21 | .idea/**/gradle.xml
22 | .idea/**/libraries
23 |
24 | # CMake
25 | cmake-build-debug/
26 |
27 | # Mongo Explorer plugin:
28 | .idea/**/mongoSettings.xml
29 |
30 | ## File-based project format:
31 | *.iws
32 |
33 | ## Plugin-specific files:
34 |
35 | # IntelliJ
36 | out/
37 |
38 | # mpeltonen/sbt-idea plugin
39 | .idea_modules/
40 |
41 | # JIRA plugin
42 | atlassian-ide-plugin.xml
43 |
44 | # Cursive Clojure plugin
45 | .idea/replstate.xml
46 |
47 | # Crashlytics plugin (for Android Studio and IntelliJ)
48 | com_crashlytics_export_strings.xml
49 | crashlytics.properties
50 | crashlytics-build.properties
51 | fabric.properties
52 |
53 | .idea/
54 |
55 | /vendor/
56 | composer.lock
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Nyi Nyi Lwin
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Laravel Html Encrypt
2 |
3 | [](https://packagist.org/packages/php-junior/laravel-html-encrypt)
4 | [](https://packagist.org/packages/php-junior/laravel-html-encrypt)
5 |
6 | ## Installation
7 |
8 | You can install the package via composer:
9 | ``` bash
10 | composer require php-junior/laravel-html-encrypt
11 | ```
12 | Laravel 5.5 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
13 |
14 | If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php
15 |
16 | ```php
17 | PhpJunior\LaravelHtmlEncrypt\LaravelHtmlEncryptServiceProvider::class,
18 | ```
19 |
20 | And
21 | ```php
22 | php artisan vendor:publish --provider="PhpJunior\LaravelHtmlEncrypt\LaravelHtmlEncryptServiceProvider"
23 | ```
24 |
25 | This is the contents of the published config file:
26 |
27 | ```php
28 | return [
29 | 'encrypt' => env('HTML_ENCRYPT', true),
30 | 'disable_right_click' => true,
31 | 'disable_ctrl_and_F12_key' => true,
32 | ];
33 | ```
34 |
35 | ## HTML Encryption?
36 |
37 | One major reason for the success of the World Wide Web is undeniably the openness of HTML. HTML files are basically plain text documents, meaning software applications and human users can easily create, read, and update web pages. The open nature of HTML not only allows users to edit websites with nothing more than a simple text editor, it also enables search engines to spider the web and forms the basis for a wide range of web-related applications for any platform you can imagine.
38 |
39 | However, as a web designer or website owner you may encounter situations in which you feel a need for protecting your HTML, CSS or JavaScript code from being viewed and reused .
40 |
41 | ## How It Works
42 |
43 | HTML encryption/decryption techniques are based on JavaScript. The encrypted HTML code, which is saved inside the HTML document, is decrypted at runtime through JavaScript and written directly into the browser window using the document.write(…) function. This ensures that any JavaScript-enabled web browser can load and display the pages without additional components or plugins.
44 |
45 | ## License
46 |
47 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
48 |
49 | ## Support on Beerpay
50 | Hey dude! Help me out for a couple of :beers:!
51 |
52 | [](https://beerpay.io/PHPJunior/laravel-html-encrypt) [](https://beerpay.io/PHPJunior/laravel-html-encrypt?focus=wish)
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "php-junior/laravel-html-encrypt",
3 | "description": "Simple Html Encrypt for Laravel",
4 | "type": "library",
5 | "license": "MIT",
6 | "keywords": [
7 | "laravel",
8 | "html",
9 | "encrypt"
10 | ],
11 | "require": {
12 | "php": ">=5.6.4",
13 | "illuminate/support": "5.3.* || 5.4.* || 5.5.*",
14 | "illuminate/contracts": "^5.5"
15 | },
16 | "type": "library",
17 | "authors": [
18 | {
19 | "name": "Nyi Nyi Lwin",
20 | "email": "nyinyilwin1992@hotmail.com"
21 | }
22 | ],
23 | "autoload": {
24 | "psr-4": {
25 | "PhpJunior\\LaravelHtmlEncrypt\\": "src/"
26 | }
27 | },
28 | "autoload-dev": {
29 | "psr-4": {
30 | "PhpJunior\\LaravelHtmlEncrypt\\Tests\\": "tests/"
31 | }
32 | },
33 | "extra": {
34 | "laravel": {
35 | "providers": [
36 | "PhpJunior\\LaravelHtmlEncrypt\\LaravelHtmlEncryptServiceProvider"
37 | ]
38 | }
39 | },
40 | "require-dev": {
41 | "phpunit/phpunit": "^6.4",
42 | "graham-campbell/testbench": "^4.0"
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/config/laravel-html-encrypt.php:
--------------------------------------------------------------------------------
1 | env('HTML_ENCRYPT', true),
12 |
13 | 'disable_right_click' => true,
14 | 'disable_ctrl_and_F12_key' => true,
15 | ];
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
20 | ./tests
21 |
22 |
23 |
24 |
25 | ./src
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/LaravelHtmlEncryptServiceProvider.php:
--------------------------------------------------------------------------------
1 | publishes([
18 | $this->configPath() => config_path('laravel-html-encrypt.php'),
19 | ]);
20 |
21 | if (config('laravel-html-encrypt.encrypt')) {
22 | $kernel->prependMiddleware('PhpJunior\LaravelHtmlEncrypt\Middleware\HtmlEncrypt');
23 | }
24 | }
25 |
26 | public function register()
27 | {
28 | $this->mergeConfigFrom($this->configPath(), 'laravel-html-encrypt');
29 | }
30 |
31 | /**
32 | * @return string
33 | */
34 | protected function configPath()
35 | {
36 | return __DIR__ . '/../config/laravel-html-encrypt.php';
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Middleware/HtmlEncrypt.php:
--------------------------------------------------------------------------------
1 | hex = '';
17 | }
18 |
19 | /**
20 | * Handle an incoming request.
21 | *
22 | * @param \Illuminate\Http\Request $request
23 | * @param \Closure $next
24 | * @return mixed
25 | */
26 | public function handle($request, Closure $next)
27 | {
28 | /**
29 | * @var $response Response
30 | */
31 | $response = $next($request);
32 |
33 | if ($request->isMethod('get') && !$request->ajax()) {
34 | $contentType = $response->headers->get('Content-Type');
35 |
36 | if (strpos($contentType, 'text/html') !== false) {
37 | $response->setContent($this->encryptHtml($response->getContent()));
38 | }
39 | }
40 |
41 | return $response;
42 |
43 | }
44 |
45 | public function encryptHtml($content)
46 | {
47 | $text = str_split(bin2hex($content),2);
48 |
49 | array_walk($text , function (&$a) {
50 | $this->addHexValue('%'.$a);
51 | });
52 |
53 | $script = '';
54 |
55 | if (config('laravel-html-encrypt.disable_right_click')){
56 | $script .= '';
57 | }
58 |
59 | if (config('laravel-html-encrypt.disable_ctrl_and_F12_key')){
60 | $script .= '';
61 | }
62 |
63 | return $script;
64 | }
65 |
66 | public function addHexValue($hex)
67 | {
68 | $this->hex .= $hex;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/tests/HtmlEncryptTest.php:
--------------------------------------------------------------------------------
1 | handle($request, function () use ($response) {
27 | return $response;
28 | });
29 |
30 | $this->assertEquals($response->getStatusCode(), 200);
31 | }
32 | }
--------------------------------------------------------------------------------
/tests/TestCase.php:
--------------------------------------------------------------------------------
1 |