Friday, September 17, 2021

Enabling brotli compression

httpd -v

apt-get install brotli

apt-get install build-essential

apt-get install apache2-dev

sudo apt-get install libtool m4 automake


git clone --depth=1 --recursive https://github.com/kjdev/apache-mod-brotli.git

cd apache-mod-brotli

./autogen.sh

 ./configure

 make

 install -D .libs/mod_brotli.so /usr/lib/apache2/modules/mod_brotli.so -m 644

 

//Now copy the built build to the module folder

cp mod_brotli.so /opt/lampstack-7.4.7-0/apache2/modules/mod_brotli.so

sudo chmod 755 apache2/modules/mod_brotli.so

 

Add the following line in httpd.conf

LoadFile modules/mod_brotli.so

LoadModule brotli_module modules/mod_brotli.so


Check whether the module is loaded

apachectl -M


Make sure that the specific file to use brotli compression inside the httpd.conf file

<Location/>

BrotliCompressionLevel 4

    AddOutputFilterByType BROTLI text/html text/plain text/xml text/x-js text/css text/javascript application/javascript font/ttf font/woff

</Location>


<IfModule brotli_module>

 BrotliCompressionLevel 4

 AddOutputFilterByType BROTLI text/html text/plain text/css text/xml

 AddOutputFilterByType BROTLI text/css

 AddOutputFilterByType BROTLI application/x-javascript application/javascript

 AddOutputFilterByType BROTLI application/rss+xml

 AddOutputFilterByType BROTLI application/xml

 AddOutputFilterByType BROTLI application/json

</IfModule>


//Restart the server

./ctlscript.sh restart


//Testing

curl -I -H 'Accept-Encoding: gzip,deflate,br' https://casino.9fun.live

HTTP/1.1 200 OK

Date: Sat, 18 Sep 2021 06:50:45 GMT

Content-Type: text/html; charset=UTF-8

Connection: keep-alive

x-frame-options: SAMEORIGIN

x-powered-by: PHP/7.4.7

cache-control: no-cache, private

set-cookie: XSRF-TOKEN=eyJpdiI6InRFQVFQOWJ6cnV3SS9hTUpKSnc3RUE9PSIsInZhbHVlIjoiSEF6VzZqYUxySlRRK1E5K0ZHdVd0MUFtOEV1akpSNURoTmVuMFJRaWREaDE3Rk5JL1h0TFBjc1k1c0Y2OExCb3VFSVl2enZhbGFXODJMUHluMEVNbFJSeXgvbXJoTFVSSFhjRCtmM04zSGlTZ2xjM0cxVEdXUWxOOGZOOU1iV2giLCJtYWMiOiIzZGUzYTk5NTMzNDcyYzM5NzM2YmE2ZTA1ZmUyZmM4MWU2MjVlYzZkNWY4NWY2ZWVlZmI1NzZhYTIwYzViODZiIn0%3D; expires=Sat, 18-Sep-2021 08:50:45 GMT; Max-Age=7200; path=/; samesite=lax

CF-Cache-Status: DYNAMIC

set-cookie: laravel_session=eyJpdiI6Iitua2J6YTBhYkRTVDNwbkluWDRmdHc9PSIsInZhbHVlIjoiNG9TOTdFOWc5b3BwTG1Pcmx0MnQrZForWjBJRE1TcW9XQ3FOUnhEWGJ4N1JjL2hDZ2FIblk4YTlWcUdSYytFbWRMWnpoaXpvczc5N1YxMWxGWEk4RVVXQ01KSFdMRVBLZk0xc2x6cjYyK1ZlOFpGbzRST1BzcWg5UWxRVVBLRE8iLCJtYWMiOiIyNjEyOWEzYzFjMDE3ZjgzNTdmOTg0MDM5ZjAxNTA1ZTc4ZDZkMTMxYzkzNDhmN2M1NDczYWY3YTlhNjZkNTdlIn0%3D; expires=Sat, 18-Sep-2021 08:50:45 GMT; Max-Age=7200; path=/; httponly; samesite=lax

Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"

Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=pQZwuzVHNQv7yypPcMlhM1ndMFypycv5HPeQMB53IjoK%2Bot2cl7aDywhOBnY%2F%2FAOA0rVz4BuLt0THWhP2syuv09Kd5by2mooF3ufiCWzK1cw57qqXGt2bsKBDNQr%2B9Vt8bgC"}],"group":"cf-nel","max_age":604800}

NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}

Server: cloudflare

CF-RAY: 6908a454ccf84a5f-SIN

Content-Encoding: br

alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400, h3-28=":443"; ma=86400, h3-27=":443"; ma=86400

Monday, June 7, 2021

Integrating socialite with laravel

Installing the plugin

 composer require laravel/socialite 

Setting up the files

Add the following routes to the route file.
//Social Logins
Route::get('/auth/facebook/login', [App\Http\Controllers\SocialAuthFacebookController::class, 'redirect']);
Route::get('/auth/facebook/callback', [App\Http\Controllers\SocialAuthFacebookController::class, 'callback']);

Route::get('/auth/google/login', [App\Http\Controllers\SocialAuthGoogleController::class, 'redirect']);
Route::get('/auth/google/callback', [App\Http\Controllers\SocialAuthGoogleController::class, 'callback']);

Create a new file "SocialFacebookAccount.php" with the following code.

<?php
namespace App;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent; //Use MongoDB as a model
class SocialFacebookAccount extends Eloquent
{
protected $fillable = ['user_id', 'provider_user_id', 'provider'];
public function user()
{
return $this->belongsTo(User::class);
}
}

Create a new file "SocialGoogleAccount.php" file with the following code.

<?php
namespace App;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent; //Use MongoDB as a model
class SocialGoogleAccount extends Eloquent
{
protected $fillable = ['user_id', 'provider_user_id', 'provider'];
public function user()
{
return $this->belongsTo(User::class);
}
}

Create a new file "SocialFacebookAccountService.php" file under the Services folder.

<?php
namespace App\Services;
use App\Application;
use App\Player;
use App\User;
use Laravel\Socialite\Contracts\User as ProviderUser;
use Log;

class SocialFacebookAccountService
{
public function createOrGetUser(ProviderUser $providerUser)
{

}
}  

Create a new file "SocialGoogleAccountService.php" file under the Services folder.

<?php
namespace App\Services;
use App\Application;
use App\Player;
use App\SocialGoogleAccount;
use App\User;
use Laravel\Socialite\Contracts\User as ProviderUser;
use Log;

class SocialGoogleAccountService
{
public function createOrGetUser(ProviderUser $providerUser)
{

}
}

Create a new file "SocialAuthFacebookController.php" file under the "app>Http>Controllers" folder.

<?php
namespace App\Http\Controllers;
use Socialite;
use App\Services\SocialFacebookAccountService;
use Illuminate\Http\Request;
use Log;
use Redirect;
use Cookie;

class SocialAuthFacebookController extends Controller
{
public function redirect()
{
return Socialite::driver('facebook')->redirect();
}

public function callback(SocialFacebookAccountService $service)
// public function callback()
{
// return 'Callback received';
// Log::info('Getting user info !');
// $user = Socialite::driver('facebook')->user();
$user = Socialite::driver('facebook')->stateless()->user();
$user = $service->createOrGetUser($user);
auth()->login($user);
return Redirect::intended();

}
}

Create a new file "SocialAuthFacebookController.php" file under the "app>Http>Controllers" folder.

<?php
namespace App\Http\Controllers;
use App\Services\SocialGoogleAccountService;
use Socialite;
use App\Services\SocialFacebookAccountService;
use Illuminate\Http\Request;
use Log;
use Redirect;
use Cookie;

class SocialAuthGoogleController extends Controller
{
public function redirect()
{
return Socialite::driver('google')->redirect();
}

public function callback(SocialGoogleAccountService $service )
{
$user = Socialite::driver('google')->stateless()->user();
$user = $service->createOrGetUser($user);
auth()->login($user);

return Redirect::intended();
}
}

Setting up environment file

FACEBOOK_APP_ID=facebook_app_id
FACEBOOK_APP_SECRET=facebook_app_secret
FACEBOOK_REDIRECT=http://www.website.com/auth/facebook/callback

GOOGLE_CLIENT_ID=google_client_id
GOOGLE_CLIENT_SECRET=google_client_secret
GOOGLE_REDIRECT=http://www.website.com/auth/google/callback

Inside the services.php file, add the following codes.

'facebook' => [
'client_id' => env('FACEBOOK_APP_ID'),
'client_secret' => env('FACEBOOK_APP_SECRET'),
'redirect' => env('FACEBOOK_REDIRECT'),
],

'google' => [
'client_id' => env('GOOGLE_CLIENT_ID'),
'client_secret' => env('GOOGLE_CLIENT_SECRET'),
'redirect' => env('GOOGLE_REDIRECT')
],

Configuring google client

Create a new project in the google console.
https://console.cloud.google.com/

OAuth consent screen

Select the created project > API & Services >  OAuth consent screen > External > Create

Fill in the form and add the domains for both production and localhost and click next

Add or Remove Scopes > email > Update > Save and Continue

Add Test Users and Continue

Verify the domain

Domain verification > Add Domain and add your domain

Create a new web application credential

Credentials > Create Credentials > OAuth Client ID > Web application

Add the URI callbacks 
http://www.website.com/auth/google/callback and create the credential.

Now you'll get client ID and secret to be used inside the laravel environment file and it's now ready to test the google login.

Configuring facebook Client

Create a new facebook app at https://developer.facebook.com

Once you've created, you will get the app_id and secret where you have to put them inside your environment file for your laravel project. Make sure that you provide privacy policy, terms of service and data deletion instruction URL to be able to submit for production usage.

Add Platform > Website and fill in your website url with https.

On the left side bar, Add Product > Facebook Login > Setup and follow the instruction. You only need to copy the SDK script inside the body tag since socialite will handle remaining integrations.

Go to Products > Facebook Login > Settings > Valid OAuth Redirect URIs, add the following url
https://<your_website>.com/auth/facebook/callback. 

Now you're ready to test your facebook login. 

Note : For localhost development, http://localhost is automatically redirected while in development mode. So make sure you turn on the development mode while testing it out in localhost.




















Wednesday, May 5, 2021

Composer memory limit error

PHP Fatal error:  Allowed memory size of 1610612736 bytes exhausted (tried to allocate 655360 bytes) in phar:///opt/lampstack-7.4.7-0/php/bin/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 49

 COMPOSER_MEMORY_LIMIT=-1 composer update

Sunday, September 6, 2020

Using bitbucket tools

 git remote add origin https://username@your.bitbucket.domain:7999/yourproject/repo.git

git add -a

git  commit -a -m "Reason"

git push -u origin master

Sunday, August 23, 2020

Securing web based video contents

 It's not so easy to secure video contents if it starts available in the web. But we need to make sure that it's hard to copy web video contents to prevent piracy losses.


1 - Hide video URLs

2 - Use one time signed URL for your video links

3 - Use use ID or something infront of the screen to prevent screen recordings

4 - Use encrypted HLS streamings

5 - Use DRM to securely deliver decryption key to access encrypted HLS contents (Widevine, FairPlay)

6 - Use Skara Player or other commercial player which support playing of encrypted HLS streams.


Saturday, August 22, 2020

Testing CORS localhost policy

 Something, chrome will restrict from displaying videos from third-party links because of the web security. 

Although you can remove restriction from your video hosting provider by adding your actual production domains, you still can't test these videos in your localhost. So How to fix it?


Step 01 - Add localhost as allowed domain inside the dashboard of your video hosting provider

Step 02 - Create a new chrome shortcut and rightClick > Properties section to change the shortcut properties

Step 03 - Add the following to the target field of the shortcut section

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --disable-gpu --user-data-dir=~/chromeTemp and click Apply



Note : Always run that created shortcut as administrator and now you will be able to bypass CORS restriction for testing.

Thursday, August 20, 2020

Setting up letsencrypt SSL on ubuntu

 Setting up the best free SSL certificate (letsencrypt) is pretty easy on Ubuntu with lampstack.

Step 01 - If you haven't installed lampstack for webhostings, do it first.

Step 02 - Go to lampstack directory cd /opt/lampstack[v]

Step 03 - Execute ./bncert-tool 

Step 04 - Now follow the instructions