-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2f63408
Showing
14 changed files
with
468 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Irfaardy - Irfa Ardiansyah | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
|
||
# 🚀Simple Laravel Encrypt Upload File | ||
[![GitHub license](https://img.shields.io/github/license/irfaardy/encrypt-file-laravel?style=flat-square)](https://github.com/irfaardy/encrypt-file-laravel/blob/master/LICENSE) [![Support me](https://img.shields.io/badge/Support-Buy%20me%20a%20coffee-yellow.svg?style=flat-square)](https://www.buymeacoffee.com/OBaAofN) | ||
|
||
<p>The Simple Laravel Encrypt Upload File uses the default encryption of Laravel which is implemented in upload file.<p> | ||
<h3>🛠️ Installation with Composer </h3> | ||
|
||
composer require irfa/encrypt-file-laravel | ||
|
||
>You can get Composer [ here]( https://getcomposer.org/download/) | ||
*** | ||
|
||
|
||
<h2>🛠️ Laravel Setup </h2> | ||
|
||
<h3>Add to config/app.php</h3> | ||
|
||
'providers' => [ | ||
.... | ||
Irfa\FileSafe\FileSafeServiceProvider::class, | ||
]; | ||
|
||
|
||
|
||
<h3>Add to config/app.php</h3> | ||
|
||
'aliases' => [ | ||
.... | ||
'FileSafe' => Irfa\FileSafe\Facades\FileSafe::class, | ||
|
||
], | ||
|
||
<h2>Publish Vendor</h2> | ||
|
||
|
||
php artisan vendor:publish --tag=file-safe | ||
|
||
<h2>Config File</h2> | ||
|
||
config/irfa/filesafe.php | ||
|
||
<h2>Example store file</h2> | ||
|
||
|
||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Filesafe; | ||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
|
||
class FileController extends Controller | ||
{ | ||
public function upload_file(Request $request) | ||
{ | ||
$file = $request->file('file'); | ||
FileSafe::store($file); | ||
//This is to encrypt the file before it is uploaded to the server. | ||
|
||
} | ||
} | ||
|
||
<h2>Example download file</h2> | ||
|
||
|
||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use FileSafe; | ||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
|
||
class FileController extends Controller | ||
{ | ||
public function upload_file(Request $request) | ||
{ | ||
$file = 'encrypted_file.doc'; | ||
return FileSafe::download($file); | ||
//This is to decrypt files to be downloaded. | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "irfa/app-license-server", | ||
"description": "\"License/Serial for web apllication\"", | ||
"type": "package", | ||
"license": "MIT", | ||
"version": "v1.0", | ||
"keywords": ["laravel", "security", "serial", "decrypt", "secure","upload file"], | ||
"authors": [ | ||
{ | ||
"name": "Irfa A", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": "^7.2", | ||
"ext-json": "*", | ||
"laravel/framework": "^6.0|^7.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Irfa\\AppLicenseServer\\": "src/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
return [ | ||
|
||
'hashed' => false,//Hashed Serial number, | ||
|
||
'caching_license' => true,//Generate random alnum for upload filename, | ||
|
||
'license_route' => "/check/license", | ||
|
||
'route_name' => "check_license", | ||
|
||
'length' => 4, //length char per segment | ||
|
||
'segment' => 4, | ||
|
||
|
||
|
||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreateLicenseSerials extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('license_serials', function (Blueprint $table) { | ||
$table->bigIncrements('id'); | ||
$table->string('name',65); | ||
$table->string('domain',120); | ||
$table->string('phone_number',30)->nullable(); | ||
$table->text('address')->nullable(); | ||
$table->string('serial',120)->unique(); | ||
$table->string('expired',16); | ||
$table->boolean('status')->default(0); | ||
$table->timestamps(); | ||
}); | ||
} | ||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('license_serials'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
use Illuminate\Http\Request; | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| API Routes | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here is where you can register API routes for your application. These | ||
| routes are loaded by the RouteServiceProvider within a group which | ||
| is assigned the "api" middleware group. Enjoy building your API! | ||
| | ||
*/ | ||
|
||
Route::get('/check','Controller\AppLicenseController@check'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Web Routes | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here is where you can register web routes for your application. These | ||
| routes are loaded by the RouteServiceProvider within a group which | ||
| contains the "web" middleware group. Now create something great! | ||
| | ||
*/ | ||
Route::get('/check','Controller\AppLicenseController@check'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Irfa\AppLicenseServer; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class AppLicenseServerServiceProvider extends ServiceProvider | ||
{ | ||
protected $namespace='AppLicenseServer\Controllers'; | ||
/** | ||
* Register services. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* Bootstrap services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
\Route::middleware('api')->post(config('irfa.app_license_server.license_route'),'Irfa\AppLicenseServer\Controller\AppLicenseController@check')->name(config('irfa.app_license_server.route_name')); | ||
$this->publishes([ | ||
__DIR__.'/../config/irfa/' => config_path('irfa')],'app-license-server'); | ||
$this->publishes([ | ||
__DIR__.'/../migrations/' => database_path('migrations'), | ||
], 'app-license'); | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Irfa\AppLicenseServer\Controller; | ||
|
||
use Illuminate\Http\Request; | ||
use Irfa\AppLicenseServer\Func\License; | ||
use Irfa\AppLicenseServer\Core\Json; | ||
use App\Http\Controllers\Controller; | ||
|
||
class AppLicenseController extends Controller | ||
{ | ||
public function check(Request $request,License $license,Json $json) | ||
{ | ||
if(empty($request->serial)) | ||
{ | ||
$data['active'] = false; | ||
$data['message'] = "Serial number must be provided."; | ||
return $json->response(400,'data',$data,[]); | ||
} | ||
$res = $license->serial($request->serial)->check(); | ||
if($res->active) | ||
{ | ||
return $json->response(200,'data',$res,[]); | ||
} | ||
return $json->response(400,'data',$res,[$res->message]); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
/* | ||
Author: Irfa Ardiansyah <[email protected]> | ||
*/ | ||
namespace Irfa\AppLicenseServer\Core; | ||
|
||
class Json | ||
{ | ||
public function response($status, $key_data = 'data', $data=null, $errors=null) | ||
{ | ||
return response()->json([ | ||
'status' => $status, | ||
$key_data => $data, | ||
'errors' => $errors | ||
],$status); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
/* | ||
Author: Irfa Ardiansyah <[email protected]> | ||
*/ | ||
namespace Irfa\AppLicenseServer\Core; | ||
|
||
use Illuminate\Support\Str; | ||
use Irfa\AppLicenseServer\Models\LicenseSerial; | ||
|
||
class SerialManager | ||
{ | ||
private $generated_serial; | ||
private $name; | ||
private $domain; | ||
private $phone_number; | ||
private $address; | ||
private $serial; | ||
private $expired; | ||
private $status; | ||
|
||
private function generateSerial() | ||
{ | ||
$sn = null; | ||
for($i=1;$i<=config('irfa.app_license_server.segment');$i++) | ||
{ | ||
$sn .= Str::random(config('irfa.app_license_server.length'))."-"; | ||
} | ||
$sn = strtoupper($sn); | ||
return rtrim($sn, '-'); | ||
} | ||
|
||
protected function expired($sn) | ||
{ | ||
$exp = LicenseSerial::where('serial',$sn)->first(); | ||
if(empty($exp)) | ||
{ | ||
return true; | ||
} else{ | ||
if($exp->expired > strtotime(date('Y-m-d'))) | ||
{ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
protected function exists($sn) | ||
{ | ||
$exp = LicenseSerial::where('serial',$sn)->count(); | ||
if(empty($exp)) | ||
{ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
protected function createLicense($params, $expired) | ||
{ | ||
$sn = $this->generateSerial(); | ||
$expired = strtotime($expired); | ||
if($this->checkAvaibility($sn)) | ||
{ | ||
$this->name = $params['name']; | ||
$this->domain = $params['domain']; | ||
$this->phone_number = $params['phone_number']; | ||
$this->address = $params['address']; | ||
$this->serial =$sn; | ||
$this->expired = $expired; | ||
|
||
return $this->insertToTable(); | ||
} else{ | ||
return $this->createLicense($params); | ||
} | ||
} | ||
private function checkAvaibility($sn) | ||
{ | ||
if(LicenseSerial::where('serial',$sn)->count() == 0) | ||
{ | ||
return true; | ||
} | ||
return true; | ||
} | ||
private function insertToTable() | ||
{ | ||
return LicenseSerial::create(['name'=>$this->name,'domain'=>$this->domain,'phone_number'=>$this->phone_number,'address'=>$this->address,'serial'=>$this->serial,'expired'=>$this->expired]); | ||
} | ||
} |
Oops, something went wrong.