diff --git a/.gitignore b/.gitignore index 4ee6300d..1d19216a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,19 +13,17 @@ npm-debug.log yarn-error.log # Ignore Live Helper Chat files -/var -/translations -/ezcomponents -/design -/cron.php -/index_legacy.php -/cache -/extension -/lib -/livehelperchat -/modules -/pos -/settings -/.idea -/.vscode +/public/cache +/public/cron.php +/public/design +/public/extension +/public/ezcomponents +/public/lib +/public/livehelperchat +/public/modules +/public/pos +/public/settings +/public/translations +/public/var + diff --git a/CHANGELOG.md b/CHANGELOG.md index eabd7a59..0c859aa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,18 @@ # Release Notes -## [Unreleased](https://github.com/laravel/laravel/compare/v8.6.9...8.x) +## [Unreleased](https://github.com/laravel/laravel/compare/v8.6.10...8.x) + + +## [v8.6.10 (2021-12-22)](https://github.com/laravel/laravel/compare/v8.6.9...v8.6.10) + +### Changed +- Bump Laravel to v8.75 ([#5750](https://github.com/laravel/laravel/pull/5750)) +- Simplify the maintenance file call ([#5752](https://github.com/laravel/laravel/pull/5752)) +- Add enum translation ([#5753](https://github.com/laravel/laravel/pull/5753)) +- Add mac_address validation message ([#5754](https://github.com/laravel/laravel/pull/5754)) + +### Removed +- Delete web.config ([#5744](https://github.com/laravel/laravel/pull/5744)) ## [v8.6.9 (2021-12-07)](https://github.com/laravel/laravel/compare/v8.6.8...v8.6.9) diff --git a/README.md b/README.md index bfb990d6..547ed9f2 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,33 @@ ## Live Helper Chat -Install instructions after cloning this repository. Here we just create a symlinks to original live helper chat files. There is also a video tutorial how to setup it https://youtu.be/SeYA7Vpy4KU +Version of integration **V2** + +* Sample URL's which are handled by Laravel, but are using LHC classes + * `https://example.com/site_admin/logged` - this routes requires `lhfront`,`default` permissions. Modify it for production to avoid printing user details + * `https://example.com/anonymous` - this route does not require any permission and does not set any cookie. + * `https://example.com/site_admin/login` - this route shows how to redirect to LHC internal URL even if URL route is registered in Laravel. + +Now you can use any LHC class within Laravel routes. Where this option was missing in first version. + +* `site_admin` routes should be defined in `routes/admin.php` you will find also sample how to require permissions for specific URL. +* Cookieless routes should be defined in `routes/anonymous.php` route file. + +Install instructions after cloning this repository. Here we just create a symlinks to original live helper chat files. + +* V2 - Video tutorial - pending +* V1 - There is also a video tutorial how to setup it https://youtu.be/SeYA7Vpy4KU + * The only different that root directly now follows Laravel practise and is located in public folder. Adjusted shell commands also This allows two apps to work independently and have independent commit history. +For the most common Live Helper Chat classes read + + * https://doc.livehelperchat.com/docs/development/orm to work with LHC database most common methods + * https://doc.livehelperchat.com/docs/development/common-classes the most commit LHC classes + ```shell script git clone https://github.com/LiveHelperChat/livehelperchat_laravel.git -cd livehelperchat_laravel +cd livehelperchat_laravel/public git clone https://github.com/LiveHelperChat/livehelperchat.git ln -s livehelperchat/lhc_web/ezcomponents ln -s livehelperchat/lhc_web/lib @@ -15,20 +36,26 @@ ln -s livehelperchat/lhc_web/pos ln -s livehelperchat/lhc_web/extension ln -s livehelperchat/lhc_web/design ln -s livehelperchat/lhc_web/translations -cp livehelperchat/lhc_web/index.php index_legacy.php -cp livehelperchat/lhc_web/cron.php cron.php ln -s livehelperchat/lhc_web/var ln -s livehelperchat/lhc_web/settings ln -s livehelperchat/lhc_web/cache +chown apache:apache -R cache/ +chown apache:apache -R var/ +chown apache:apache settings/ +chmod -R 755 cache/ ``` -Now you can point your browser to root folder if closed repository E.g `livehelperchat_laravel/index.php` +Folder structure at the end should look like + + + +Your have to setup virtual host on your server pointing to `livehelperchat_laravel/public` same as default laravel installation You now might need to follow standard Laravel install procedure. After install don't forget to edit `.env` file and put database logins. -Now in any extension or core file you should be able to use any Laravel class. +Now in any extension or core file you should be able to use any Laravel class and vica versa. ## Laravel diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 644d87eb..33040636 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -40,7 +40,10 @@ public function register() } public function render( $request, Throwable $e) { - if ($e instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) { + if ( + $e instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException || + $e instanceof \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException + ) { // pass to legacy framework \App::make("LiveHelperChat"); die(); // prevent Laravel sending a 404 response diff --git a/app/Helpers/AppHelper.php b/app/Helpers/AppHelper.php new file mode 100644 index 00000000..b45aea5c --- /dev/null +++ b/app/Helpers/AppHelper.php @@ -0,0 +1,32 @@ +route()->getAction(); + + if (isset($required['permission']['m']) && + isset($required['permission']['f']) + ) { + return $this->auth()->hasAccessTo($required['permission']['m'],$required['permission']['f']); + } + + return true; + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Admin/LoginController.php b/app/Http/Controllers/Admin/LoginController.php new file mode 100644 index 00000000..ef453a0f --- /dev/null +++ b/app/Http/Controllers/Admin/LoginController.php @@ -0,0 +1,32 @@ + \AppHelper::instance()->auth(), + 'items' => \erLhcoreClassModelChat::getList(['limit' => 1]) + ]); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/LegacyController.php b/app/Http/Controllers/LegacyController.php index f8d3ed38..873496dd 100644 --- a/app/Http/Controllers/LegacyController.php +++ b/app/Http/Controllers/LegacyController.php @@ -9,4 +9,9 @@ public function index() return view('welcome'); } + public function anonymous() + { + return view('samples/anonymous'); + } + } \ No newline at end of file diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index d3722c2d..2ae131a0 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -38,7 +38,9 @@ class Kernel extends HttpKernel \App\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, ], - + 'anonymous' => [ + \Illuminate\Routing\Middleware\SubstituteBindings::class, + ], 'api' => [ // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class, 'throttle:api', @@ -63,5 +65,6 @@ class Kernel extends HttpKernel 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, + 'lhc' => \App\Http\Middleware\LiveHelperChat::class, ]; } diff --git a/app/Http/Middleware/LiveHelperChat.php b/app/Http/Middleware/LiveHelperChat.php new file mode 100644 index 00000000..53c4b038 --- /dev/null +++ b/app/Http/Middleware/LiveHelperChat.php @@ -0,0 +1,30 @@ +auth()->isLogged()) { + return redirect()->route('lhc_admin.login'); + } + + if (\AppHelper::instance()->accessible($request) !== true) { + throw new AccessDeniedHttpException(); + } + + return $next($request); + } +} diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 3bd3c81e..5162bba8 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -43,9 +43,21 @@ public function boot() ->namespace($this->namespace) ->group(base_path('routes/api.php')); + // Logged without site_admin Route::middleware('web') ->namespace($this->namespace) ->group(base_path('routes/web.php')); + + // Logged with site_admin + Route::middleware('web') + ->namespace($this->namespace . '\Admin') + ->prefix('site_admin') + ->group(base_path('routes/admin.php')); + + // Anonymous + Route::middleware('anonymous') + ->namespace($this->namespace) + ->group(base_path('routes/anonymous.php')); }); } diff --git a/composer.json b/composer.json index 8fc7406e..2b0c1155 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "php": "^7.3|^8.0", "fruitcake/laravel-cors": "^2.0", "guzzlehttp/guzzle": "^7.0.1", - "laravel/framework": "^8.65", + "laravel/framework": "^8.75", "laravel/sanctum": "^2.11", "laravel/tinker": "^2.5" }, diff --git a/config/app.php b/config/app.php index ed9ae5a4..8ed60b32 100644 --- a/config/app.php +++ b/config/app.php @@ -234,7 +234,7 @@ 'URL' => Illuminate\Support\Facades\URL::class, 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, - + 'AppHelper' => App\Helpers\AppHelper::class ], ]; diff --git a/public/index.php b/public/index.php index 002ee24d..5dcecd5a 100644 --- a/public/index.php +++ b/public/index.php @@ -16,8 +16,8 @@ | */ -if (file_exists(__DIR__.'/../storage/framework/maintenance.php')) { - require __DIR__.'/../storage/framework/maintenance.php'; +if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) { + require $maintenance; } /* @@ -33,6 +33,33 @@ require __DIR__.'/../vendor/autoload.php'; +/* +|-------------------------------------------------------------------------- +| Live Helper Chat classes Auto Loader +|-------------------------------------------------------------------------- +| +| Composer provides a convenient, automatically generated class loader for +| this application. We just need to utilize it! We'll simply require it +| into the script here so we don't need to manually load our classes. +| +*/ + +// Legacy index_legacy.php checks for that constant +define('LHC_AUTOLOADED', true); + +require_once "ezcomponents/Base/src/base.php"; // dependent on installation method, see below + +ezcBase::addClassRepository( './','./lib/autoloads'); + +spl_autoload_register(array('ezcBase','autoload'), true, false); +spl_autoload_register(array('erLhcoreClassSystem','autoload'), true, false); + +// your code here +ezcBaseInit::setCallback( + 'ezcInitDatabaseInstance', + 'erLhcoreClassLazyDatabaseConfiguration' +); + /* |-------------------------------------------------------------------------- | Run The Application diff --git a/public/index_legacy.php b/public/index_legacy.php new file mode 100644 index 00000000..2e6c7795 --- /dev/null +++ b/public/index_legacy.php @@ -0,0 +1,94 @@ +set('Result',$Result); + if (isset($Result['pagelayout'])) + { + $tpl->setFile('pagelayouts/'.$Result['pagelayout'].'.php'); + } + + echo $tpl->fetch(); + +} catch (Exception $e) { + + if (erConfigClassLhConfig::getInstance()->getSetting( 'site', 'debug_output' ) == true) { + echo "
"; + print_r($e); + echo ""; + exit; + } + + error_log($e); + + header('HTTP/1.1 503 Service Temporarily Unavailable'); + header('Status: 503 Service Temporarily Unavailable'); + header('Retry-After: 300'); + + include_once('design/defaulttheme/tpl/lhkernel/fatal_error.tpl.php'); + + erLhcoreClassLog::write(print_r($e,true)); +} + + +flush(); +session_write_close(); + +if ( function_exists('fastcgi_finish_request') ) { + fastcgi_finish_request(); +}; + +erLhcoreClassChatEventDispatcher::getInstance()->executeFinishRequest(); \ No newline at end of file diff --git a/public/structure.png b/public/structure.png new file mode 100644 index 00000000..f3c26695 Binary files /dev/null and b/public/structure.png differ diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index ba42c8d9..87fb437c 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -45,6 +45,7 @@ 'distinct' => 'The :attribute field has a duplicate value.', 'email' => 'The :attribute must be a valid email address.', 'ends_with' => 'The :attribute must end with one of the following: :values.', + 'enum' => 'The selected :attribute is invalid.', 'exists' => 'The selected :attribute is invalid.', 'file' => 'The :attribute must be a file.', 'filled' => 'The :attribute field must have a value.', @@ -67,6 +68,7 @@ 'ip' => 'The :attribute must be a valid IP address.', 'ipv4' => 'The :attribute must be a valid IPv4 address.', 'ipv6' => 'The :attribute must be a valid IPv6 address.', + 'mac_address' => 'The :attribute must be a valid MAC address.', 'json' => 'The :attribute must be a valid JSON string.', 'lt' => [ 'numeric' => 'The :attribute must be less than :value.', diff --git a/resources/views/samples/anonymous.blade.php b/resources/views/samples/anonymous.blade.php new file mode 100644 index 00000000..8197690b --- /dev/null +++ b/resources/views/samples/anonymous.blade.php @@ -0,0 +1,29 @@ + + + + + + + +
{{print_r($user->getUserData(), true)}}+ +
{{print_r($items, true)}}\ No newline at end of file diff --git a/routes/admin.php b/routes/admin.php new file mode 100644 index 00000000..1fc6c8e2 --- /dev/null +++ b/routes/admin.php @@ -0,0 +1,28 @@ +name('lhc_admin.login'); + +Route::group(['middleware' => 'lhc'], function () { + Route::group(['permission' => [ + 'm' => 'lhfront', // Module + 'f' => 'default' // Function + ]], function () { + Route::any('/logged', [LoginController::class, 'logged'])->name( 'lhc.logged'); + }); +}); diff --git a/routes/anonymous.php b/routes/anonymous.php new file mode 100644 index 00000000..2c408c99 --- /dev/null +++ b/routes/anonymous.php @@ -0,0 +1,15 @@ +name( 'lhc.anonymous'); \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index e2c072b9..d321e063 100644 --- a/routes/web.php +++ b/routes/web.php @@ -12,9 +12,4 @@ | contains the "web" middleware group. Now create something great! | */ - -Route::any('/dummy', [LegacyController::class, 'index'])->name( 'lhc.start_me'); - -/*Route::get('/', function () { - return view('welcome'); -});*/ +Route::any('/dummy', [LegacyController::class, 'index'])->name( 'lhc.start_me'); \ No newline at end of file diff --git a/storage/app/.gitignore b/storage/app/.gitignore old mode 100644 new mode 100755 diff --git a/storage/app/public/.gitignore b/storage/app/public/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/.gitignore b/storage/framework/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/cache/.gitignore b/storage/framework/cache/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/cache/data/.gitignore b/storage/framework/cache/data/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/sessions/.gitignore b/storage/framework/sessions/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/testing/.gitignore b/storage/framework/testing/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/views/.gitignore b/storage/framework/views/.gitignore old mode 100644 new mode 100755 diff --git a/storage/logs/.gitignore b/storage/logs/.gitignore old mode 100644 new mode 100755