Initial Commit
This commit is contained in:
57
app/Console/Commands/ChangePassword.php
Normal file
57
app/Console/Commands/ChangePassword.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Http\Controllers\AuthController;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class ChangePassword extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'user:password:change {username}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Change a password';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
App::setLocale("en");
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$username = $this->argument('username');
|
||||
$oAuthController = new AuthController();
|
||||
$current_password = $this->secret("Please enter the current password");
|
||||
$new_password = $this->secret("Please enter the new password");
|
||||
|
||||
$aReturn = $oAuthController->changePassword($username, $current_password, $new_password);
|
||||
|
||||
if ($aReturn["status"] == "error") {
|
||||
$this->error($aReturn["message"]);
|
||||
} else {
|
||||
$this->info($aReturn["message"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
56
app/Console/Commands/CreateUser.php
Normal file
56
app/Console/Commands/CreateUser.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Http\Controllers\AuthController;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class CreateUser extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'user:create {username}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new backend user';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
App::setLocale("en");
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$username = $this->argument('username');
|
||||
$password = $this->secret('What is the password?');
|
||||
$oAuthController = new AuthController();
|
||||
|
||||
$aReturn = $oAuthController->createUser($username, $password);
|
||||
|
||||
if ($aReturn["status"] == "error") {
|
||||
$this->error($aReturn["message"]);
|
||||
} else {
|
||||
$this->info($aReturn["message"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
57
app/Console/Commands/DeleteUser.php
Normal file
57
app/Console/Commands/DeleteUser.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Http\Controllers\AuthController;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class DeleteUser extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'user:delete {username}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Delete a backend user';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
App::setLocale("en");
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$username = $this->argument('username');
|
||||
$oAuthController = new AuthController();
|
||||
|
||||
if ($this->confirm("Are you sure that you want to delete the user '{$username}'?")) {
|
||||
$aReturn = $oAuthController->deleteUser($username);
|
||||
|
||||
if ($aReturn["status"] == "error") {
|
||||
$this->error($aReturn["message"]);
|
||||
} else {
|
||||
$this->info($aReturn["message"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
81
app/Console/Commands/FetchRecords.php
Normal file
81
app/Console/Commands/FetchRecords.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Http\Controllers\RecordController;
|
||||
use App\Models\Domains;
|
||||
use App\Models\Records;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class FetchRecords extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'dns-records:fetch';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Fetches the current DNS Records';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$oDomains = Domains::all();
|
||||
|
||||
if ($oDomains->isEmpty()) {
|
||||
$this->warn('No Domains, exiting!');
|
||||
exit();
|
||||
}
|
||||
|
||||
try {
|
||||
DB::table('records')->truncate();
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Error while truncating the records table: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
$oRecordController = new RecordController();
|
||||
|
||||
foreach ($oDomains as $oDomain) {
|
||||
$oAPIRecords = $oRecordController->fetchRecords($oDomain->name);
|
||||
$iRecords = $oAPIRecords->count();
|
||||
|
||||
foreach ($oAPIRecords as $oAPIRecord) {
|
||||
$oRecord = new Records();
|
||||
$oRecord->name = $oAPIRecord["name"];
|
||||
$oRecord->ttl = $oAPIRecord["ttl"];
|
||||
$oRecord->type = $oAPIRecord["type"];
|
||||
$oRecord->content = $oAPIRecord["content"];
|
||||
$oRecord->domains_id = $oDomain->id;
|
||||
|
||||
try {
|
||||
$oRecord->save();
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$this->info("Success! Saved {$iRecords} records for Domain {$oDomain->name} to the database!");
|
||||
}
|
||||
}
|
||||
}
|
||||
42
app/Console/Kernel.php
Normal file
42
app/Console/Kernel.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* The Artisan commands provided by your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
// $schedule->command('inspire')->hourly();
|
||||
$schedule->command('dns-records:fetch')->daily();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function commands()
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
41
app/Exceptions/Handler.php
Normal file
41
app/Exceptions/Handler.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* A list of the exception types that are not reported.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dontReport = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* A list of the inputs that are never flashed for validation exceptions.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dontFlash = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register the exception handling callbacks for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->reportable(function (Throwable $e) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
156
app/Http/Controllers/AuthController.php
Normal file
156
app/Http/Controllers/AuthController.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
public function getLogin()
|
||||
{
|
||||
return view('auth.login', [
|
||||
'title' => 'Login',
|
||||
]);
|
||||
}
|
||||
|
||||
public function postLogin(Request $request)
|
||||
{
|
||||
$aData = $this->validate($request, [
|
||||
'username' => 'required|exists:users,username',
|
||||
'password' => 'required',
|
||||
'remember' => '',
|
||||
]);
|
||||
|
||||
$blRememberMe = false;
|
||||
|
||||
if (isset($aData["remember"])) {
|
||||
$blRememberMe = true;
|
||||
}
|
||||
|
||||
if (Auth::attempt([
|
||||
'username' => $aData["username"],
|
||||
'password' => $aData["password"]
|
||||
], $blRememberMe)) {
|
||||
return ReturnController::returnWithSuccess(__("messages.suc_login"), "/");
|
||||
} else {
|
||||
return ReturnController::returnWithError(__("messages.err_login"), "", true);
|
||||
}
|
||||
}
|
||||
|
||||
public function getChangePassword()
|
||||
{
|
||||
return view('auth.change-password', [
|
||||
'title' => __("views.change_password")
|
||||
]);
|
||||
}
|
||||
|
||||
public function postChangePassword(Request $request)
|
||||
{
|
||||
$aData = $this->validate($request, [
|
||||
'old_password' => 'required',
|
||||
'new_password' => 'required'
|
||||
]);
|
||||
|
||||
$aReturn = $this->changePassword(Auth::user()->username, $aData["old_password"], $aData["new_password"]);
|
||||
|
||||
if ($aReturn["status"] == "error") {
|
||||
return ReturnController::returnWithError($aReturn["message"]);
|
||||
} else {
|
||||
return ReturnController::returnWithSuccess($aReturn["message"]);
|
||||
}
|
||||
}
|
||||
|
||||
public function changePassword(string $username, string $current_password, string $new_password): array
|
||||
{
|
||||
$oUser = User::where('username', $username)->first();
|
||||
|
||||
if (!Hash::check($current_password, $oUser->password)) {
|
||||
return [
|
||||
"status" => "error",
|
||||
"message" => __("messages.old_password_incorrect"),
|
||||
];
|
||||
}
|
||||
|
||||
$oUser->password = Hash::make($new_password);
|
||||
|
||||
try {
|
||||
$oUser->save();
|
||||
} catch (\Exception $e) {
|
||||
return [
|
||||
"status" => "error",
|
||||
"message" => __("messages.error_changing_password", ["error" => $e->getMessage()]),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
"status" => "ok",
|
||||
"message" => __("messages.suc_changing_password"),
|
||||
];
|
||||
}
|
||||
|
||||
public function createUser(string $username, string $password): array
|
||||
{
|
||||
if (!User::where('username', $username)->get()->isEmpty()) {
|
||||
return [
|
||||
"status" => "error",
|
||||
"message" => __("messages.err_user_existing"),
|
||||
];
|
||||
}
|
||||
|
||||
$oUser = new User();
|
||||
$oUser->username = $username;
|
||||
$oUser->password = Hash::make($password);
|
||||
|
||||
try {
|
||||
$oUser->save();
|
||||
} catch (\Exception $e) {
|
||||
return [
|
||||
"status" => "error",
|
||||
"message" => __("messages.error_creating_user", ["error" => $e->getMessage()]),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
"status" => "ok",
|
||||
"message" => __("messages.suc_creating_user", ["username" => $username]),
|
||||
];
|
||||
}
|
||||
|
||||
public function deleteUser(string $username)
|
||||
{
|
||||
$oUser = User::where('username', $username);
|
||||
|
||||
if ($oUser->get()->isEmpty()) {
|
||||
return [
|
||||
"status" => "error",
|
||||
"message" => __("messages.error_no_user", ["username" => $username]),
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
$oUser->delete();
|
||||
} catch (\Exception $e) {
|
||||
return [
|
||||
"status" => "error",
|
||||
"message" => __("messages.error_deleting_user", ["username" => $username, "error" => $e->getMessage()]),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
"status" => "ok",
|
||||
"message" => __("messages.suc_deleting_user", ["username" => $username]),
|
||||
];
|
||||
}
|
||||
|
||||
public function getLogout()
|
||||
{
|
||||
Auth::logout();
|
||||
|
||||
return ReturnController::returnWithSuccess(__("messages.suc_logout"), "/", false);
|
||||
}
|
||||
}
|
||||
13
app/Http/Controllers/Controller.php
Normal file
13
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
}
|
||||
53
app/Http/Controllers/DomainController.php
Normal file
53
app/Http/Controllers/DomainController.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
|
||||
use App\Models\Domains;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DomainController extends Controller
|
||||
{
|
||||
public function getManageDomains()
|
||||
{
|
||||
return view('domain_overview', [
|
||||
'title' => __("views.domains"),
|
||||
'domains' => Domains::orderBy('name', 'asc')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function postAddDomain(Request $request)
|
||||
{
|
||||
$aData = $this->validate($request, [
|
||||
'name' => 'required|unique:domains,name'
|
||||
]);
|
||||
|
||||
$oDomain = new Domains();
|
||||
$oDomain->name = $aData["name"];
|
||||
|
||||
try {
|
||||
$oDomain->save();
|
||||
} catch (\Exception $e) {
|
||||
return ReturnController::returnWithError(__("messages.error_saving_domain", ["error" => $e->getMessage()]));
|
||||
}
|
||||
|
||||
return ReturnController::returnWithSuccess(__("messages.suc_saving_domain"));
|
||||
}
|
||||
|
||||
public function postDeleteDomain(Request $request)
|
||||
{
|
||||
$aData = $this->validate($request, [
|
||||
'domain_name' => 'required|exists:domains,name',
|
||||
'domain_id' => 'required|exists:domains,id',
|
||||
]);
|
||||
|
||||
try {
|
||||
Domains::find($aData["domain_id"])->delete();
|
||||
} catch (\Exception $e) {
|
||||
return ReturnController::returnWithError(__("messages.error_deleting_domain", ["error" => $e->getMessage()]));
|
||||
}
|
||||
|
||||
return ReturnController::returnWithSuccess(__("messages.suc_deleting_domain", ["domain" => $aData["domain_name"]]));
|
||||
}
|
||||
}
|
||||
50
app/Http/Controllers/HomeController.php
Normal file
50
app/Http/Controllers/HomeController.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Domains;
|
||||
use App\Models\Records;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
public function homeView()
|
||||
{
|
||||
$oRecords = Records::orderBy("name", "asc")->get();
|
||||
$oDomains = Domains::orderBy("name", "asc")->get();
|
||||
$aUpdated = [];
|
||||
$aRecordCountByDomain = [];
|
||||
|
||||
foreach ($oRecords as $oRecord) {
|
||||
if (empty($aRecordCountByDomain[$oRecord->domains_id])) {
|
||||
$aRecordCountByDomain[$oRecord->domains_id] = 0;
|
||||
}
|
||||
|
||||
$aRecordCountByDomain[$oRecord->domains_id]++;
|
||||
|
||||
$last_update = $oRecord->created_at;
|
||||
$since_update = $last_update->diff(now());
|
||||
|
||||
if ($since_update->h != 0) {
|
||||
$since_update_text = trans_choice("views.last_update_text_hours", $since_update->h, ["hours" => $since_update->h, "date" => $last_update]);
|
||||
#$since_update_text = $since_update->h . " Stunde" . ($since_update->h > 1 ? "n ":" ") . $since_update->i . " Minuten";
|
||||
} else {
|
||||
$since_update_text = trans_choice("views.last_update_text_minutes", $since_update->i, ["minutes" => $since_update->i, "date" => $last_update]);
|
||||
#$since_update_text = $since_update->i . " Minuten";
|
||||
}
|
||||
|
||||
$aUpdated[$oRecord->domains_id] = [
|
||||
'diff' => $since_update,
|
||||
'text' => $since_update_text,
|
||||
'timestamp' => $last_update,
|
||||
];
|
||||
}
|
||||
|
||||
return view('home', [
|
||||
'title' => 'Home',
|
||||
'records' => $oRecords,
|
||||
'update' => $aUpdated,
|
||||
'domains' => $oDomains,
|
||||
'recordCount' => $aRecordCountByDomain,
|
||||
]);
|
||||
}
|
||||
}
|
||||
39
app/Http/Controllers/LanguageController.php
Normal file
39
app/Http/Controllers/LanguageController.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class LanguageController extends Controller
|
||||
{
|
||||
public function setLanguage($sLangCode)
|
||||
{
|
||||
if ($this->validateLangCode($sLangCode)) {
|
||||
session(["lang" => $sLangCode]);
|
||||
|
||||
return ReturnController::returnWithSuccess(__("messages.suc_lang_set"));
|
||||
}
|
||||
|
||||
return ReturnController::returnWithError(__("messages.err_lang_code_not_found", ["code" => $sLangCode]));
|
||||
}
|
||||
|
||||
public static function getActiveLanguage()
|
||||
{
|
||||
if (session()->has("lang")) {
|
||||
return session()->get("lang");
|
||||
}
|
||||
|
||||
return env("APP_LOCALE");
|
||||
}
|
||||
|
||||
public function validateLangCode($sLangCode): bool
|
||||
{
|
||||
$codes = [
|
||||
"ab", "aa", "af", "ak", "sq", "am", "ar", "an", "hy", "as", "av", "ae", "ay", "az", "bm", "ba", "eu", "be", "bn", "bh", "bi", "bs", "br", "bg", "my", "ca", "km", "ch", "ce", "ny", "zh", "cu", "cv", "kw", "co", "cr", "hr", "cs", "da", "dv", "nl", "dz", "en", "eo", "et", "ee", "fo", "fj", "fi", "fr", "ff", "gd", "gl", "lg", "ka", "de", "ki", "el", "kl", "gn", "gu", "ht", "ha", "he", "hz", "hi", "ho", "hu", "is", "io", "ig", "id", "ia", "ie", "iu", "ik", "ga", "it", "ja", "jv", "kn", "kr", "ks", "kk", "rw", "kv", "kg", "ko", "kj", "ku", "ky", "lo", "la", "lv", "lb", "li", "ln", "lt", "lu", "mk", "mg", "ms", "ml", "mt", "gv", "mi", "mr", "mh", "ro", "mn", "na", "nv", "nd", "ng", "ne", "se", "no", "nb", "nn", "ii", "oc", "oj", "or", "om", "os", "pi", "pa", "ps", "fa", "pl", "pt", "qu", "rm", "rn", "ru", "sm", "sg", "sa", "sc", "sr", "sn", "sd", "si", "sk", "sl", "so", "st", "nr", "es", "su", "sw", "ss", "sv", "tl", "ty", "tg", "ta", "tt", "te", "th", "bo", "ti", "to", "ts", "tn", "tr", "tk", "tw", "ug", "uk", "ur", "uz", "ve", "vi", "vo", "wa", "cy", "fy", "wo", "xh", "yi", "yo", "za", "zu",
|
||||
];
|
||||
|
||||
return in_array($sLangCode, $codes);
|
||||
}
|
||||
}
|
||||
224
app/Http/Controllers/RecordController.php
Normal file
224
app/Http/Controllers/RecordController.php
Normal file
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Domains;
|
||||
use App\Models\Records;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class RecordController extends Controller
|
||||
{
|
||||
public function fetchRecords($domain): \Illuminate\Support\Collection
|
||||
{
|
||||
$response = Http::withHeaders([
|
||||
'X-Auth-Username' => env('SERVERCOW_API_USER'),
|
||||
'X-Auth-Password' => env('SERVERCOW_API_PASS'),
|
||||
'Content-Type' => 'application/json',
|
||||
])->get(env('SERVERCOW_API_URL') . $domain);
|
||||
|
||||
return $response->collect();
|
||||
}
|
||||
|
||||
public function getRecordJSON($iRecordId)
|
||||
{
|
||||
$oRecord = Records::find($iRecordId);
|
||||
$oDomain = $oRecord->domain;
|
||||
$oRecord = collect($oRecord);
|
||||
$oRecord->put("domain", $oDomain->name);
|
||||
|
||||
return response()->json($oRecord);
|
||||
}
|
||||
|
||||
public function getAddRecords()
|
||||
{
|
||||
return view('record_add', [
|
||||
'title' => __("views.add_record"),
|
||||
'domains' => Domains::orderBy('name', 'asc')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function postAddRecord(Request $request)
|
||||
{
|
||||
$aData = $this->validate($request, [
|
||||
"type" => "required",
|
||||
"name" => "",
|
||||
"content" => "required",
|
||||
"ttl" => "required|integer",
|
||||
"domain" => "required|exists:domains,id",
|
||||
]);
|
||||
|
||||
if ($aData["name"] === null) {
|
||||
$aData["name"] = "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Records with the types specified in the array can exist multiple times with the same name, therefore the content needs to be an array so that the existing records does not get lost
|
||||
*/
|
||||
$aRecords = [];
|
||||
$blRecordArray = false;
|
||||
|
||||
if (in_array($aData["type"], ["mx", "txt", "caa", "tlsa"])) {
|
||||
$blRecordArray = true;
|
||||
|
||||
$oRecords = Records::where([
|
||||
['name', $aData["name"]],
|
||||
['type', $aData["type"]],
|
||||
['domains_id', $aData["domain"]],
|
||||
])->get();
|
||||
|
||||
foreach ($oRecords as $oRecord) {
|
||||
array_push($aRecords, $oRecord->content);
|
||||
}
|
||||
|
||||
array_push($aRecords, $aData["content"]);
|
||||
}
|
||||
//--
|
||||
|
||||
if ($aData["type"] == "mx" && !$this->startsWithNumber($aData["content"])) {
|
||||
$aData["content"] = "10 " . $aData["content"];
|
||||
}
|
||||
|
||||
$sDomainName = Domains::find($aData["domain"])->name;
|
||||
|
||||
try {
|
||||
$request = Http::withHeaders([
|
||||
'X-Auth-Username' => env('SERVERCOW_API_USER'),
|
||||
'X-Auth-Password' => env('SERVERCOW_API_PASS'),
|
||||
'Content-Type' => 'application/json',
|
||||
])->post(env('SERVERCOW_API_URL') . $sDomainName, [
|
||||
"type" => $aData["type"],
|
||||
"name" => $aData["name"],
|
||||
"content" => $blRecordArray ? json_encode($aRecords) : $aData["content"],
|
||||
"ttl" => $aData["ttl"]
|
||||
]);
|
||||
|
||||
$aReturn = $request->json();
|
||||
|
||||
dd($aReturn);
|
||||
|
||||
if (array_key_exists("error", $aReturn)) {
|
||||
return ReturnController::returnWithError(__("messages.error_saving_record", ["error" => $aReturn["error"]]));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return ReturnController::returnWithError(__("messages.error_saving_record", ["error" => $e->getMessage()]));
|
||||
}
|
||||
|
||||
$this->getNewRecordsForDomain($sDomainName, $aData["domain"]);
|
||||
|
||||
return ReturnController::returnWithSuccess(__("messages.suc_saving_record"));
|
||||
}
|
||||
|
||||
public function postDeleteRecord(Request $request)
|
||||
{
|
||||
$aData = $this->validate($request, [
|
||||
'type' => 'required',
|
||||
'name' => '',
|
||||
'domain_name' => 'required|exists:domains,name',
|
||||
'domain_id' => 'required|integer|exists:domains,id'
|
||||
]);
|
||||
|
||||
if ($aData["name"] === null) {
|
||||
$aData["name"] = "";
|
||||
}
|
||||
|
||||
try {
|
||||
$request = Http::withHeaders([
|
||||
'X-Auth-Username' => env('SERVERCOW_API_USER'),
|
||||
'X-Auth-Password' => env('SERVERCOW_API_PASS'),
|
||||
'Content-Type' => 'application/json',
|
||||
])->delete(env('SERVERCOW_API_URL') . $aData["domain_name"], $aData);
|
||||
|
||||
$aReturn = $request->json();
|
||||
|
||||
if (array_key_exists("error", $aReturn)) {
|
||||
return ReturnController::returnWithError(__("messages.error_deleting_record", ["error" => $aReturn["error"]]));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return ReturnController::returnWithError(__("messages.error_deleting_record", ["error" => $e->getMessage()]));
|
||||
}
|
||||
|
||||
$this->getNewRecordsForDomain($aData["domain_name"], $aData["domain_id"]);
|
||||
|
||||
return ReturnController::returnWithSuccess(__("messages.suc_deleting_record", ["record" => $aData["name"]]));
|
||||
}
|
||||
|
||||
public function postEditRecord(Request $request)
|
||||
{
|
||||
$aData = $this->validate($request, [
|
||||
'record_id' => 'required|exists:records,id',
|
||||
'content' => 'required',
|
||||
'ttl' => 'required|integer'
|
||||
]);
|
||||
|
||||
$oRecord = Records::find($aData["record_id"]);
|
||||
|
||||
try {
|
||||
$request = Http::withHeaders([
|
||||
'X-Auth-Username' => env('SERVERCOW_API_USER'),
|
||||
'X-Auth-Password' => env('SERVERCOW_API_PASS'),
|
||||
'Content-Type' => 'application/json',
|
||||
])->post(env('SERVERCOW_API_URL') . $oRecord->domain->name, [
|
||||
"type" => $oRecord->type,
|
||||
"name" => $oRecord->name,
|
||||
"content" => $aData["content"],
|
||||
"ttl" => $aData["ttl"]
|
||||
]);
|
||||
|
||||
$aReturn = $request->json();
|
||||
|
||||
if (array_key_exists("error", $aReturn)) {
|
||||
return ReturnController::returnWithError(__("messages.error_editing_record", ["error" => $aReturn["error"]]));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return ReturnController::returnWithError(__("messages.error_editing_record", ["error" => $e->getMessage()]));
|
||||
}
|
||||
|
||||
$this->getNewRecordsForDomain($oRecord->domain->name, $oRecord->domain->id);
|
||||
|
||||
return ReturnController::returnWithSuccess(__("messages.suc_editing_record"));
|
||||
}
|
||||
|
||||
public function getNewRecords($sDomainName, $iDomainId)
|
||||
{
|
||||
try {
|
||||
$this->getNewRecordsForDomain($sDomainName, $iDomainId);
|
||||
} catch (\Exception $e) {
|
||||
return ReturnController::returnWithError(__("messages.error_fetching_records", ["error" => $e->getMessage()]));
|
||||
}
|
||||
|
||||
return ReturnController::returnWithSuccess(__("messages.suc_fetching_records", ["domain" => $sDomainName]));
|
||||
}
|
||||
|
||||
public function getNewRecordsForDomain($sDomainName, $iDomainId)
|
||||
{
|
||||
try {
|
||||
DB::table('records')->where('domains_id', $iDomainId)->delete();
|
||||
} catch (\Exception $e) {
|
||||
dd($e->getMessage());
|
||||
}
|
||||
|
||||
$oAPIRecords = $this->fetchRecords($sDomainName);
|
||||
|
||||
foreach ($oAPIRecords as $oAPIRecord) {
|
||||
$oRecord = new Records();
|
||||
$oRecord->name = $oAPIRecord["name"];
|
||||
$oRecord->ttl = $oAPIRecord["ttl"];
|
||||
$oRecord->type = $oAPIRecord["type"];
|
||||
$oRecord->content = $oAPIRecord["content"];
|
||||
$oRecord->domains_id = $iDomainId;
|
||||
|
||||
try {
|
||||
$oRecord->save();
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function startsWithNumber($string) {
|
||||
return strlen($string) > 0 && ctype_digit(substr($string, 0, 1));
|
||||
}
|
||||
}
|
||||
51
app/Http/Controllers/ReturnController.php
Normal file
51
app/Http/Controllers/ReturnController.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class ReturnController extends Controller
|
||||
{
|
||||
public static function returnWithSuccess($message, $target = "", $to_route = false)
|
||||
{
|
||||
Session::flash('Success_Message', $message);
|
||||
|
||||
if (!empty($_POST["hash"])) {
|
||||
return redirect("/" . $_POST["hash"]);
|
||||
}
|
||||
|
||||
if ($target == "") {
|
||||
return redirect()->back();
|
||||
} else {
|
||||
switch ($to_route) {
|
||||
case false:
|
||||
return redirect($target);
|
||||
break;
|
||||
case true:
|
||||
return redirect()->route($target);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function returnWithError($error, $target = "", $with_input = false)
|
||||
{
|
||||
Session::flash('Error_Message', $error);
|
||||
|
||||
if (!empty($_POST["hash"])) {
|
||||
return redirect("/" . $_POST["hash"]);
|
||||
}
|
||||
|
||||
if ($target == "") {
|
||||
switch ($with_input) {
|
||||
case false:
|
||||
return redirect()->back();
|
||||
break;
|
||||
case true:
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
} else {
|
||||
return redirect($target);
|
||||
}
|
||||
}
|
||||
}
|
||||
68
app/Http/Kernel.php
Normal file
68
app/Http/Kernel.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use App\Http\Middleware\SetLocale;
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
/**
|
||||
* The application's global HTTP middleware stack.
|
||||
*
|
||||
* These middleware are run during every request to your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [
|
||||
// \App\Http\Middleware\TrustHosts::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\Fruitcake\Cors\HandleCors::class,
|
||||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware groups.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
// \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
'throttle:api',
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware.
|
||||
*
|
||||
* These middleware may be assigned to groups or used individually.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $routeMiddleware = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
'locale' => SetLocale::class,
|
||||
];
|
||||
}
|
||||
21
app/Http/Middleware/Authenticate.php
Normal file
21
app/Http/Middleware/Authenticate.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return string|null
|
||||
*/
|
||||
protected function redirectTo($request)
|
||||
{
|
||||
if (! $request->expectsJson()) {
|
||||
return route('auth-login.get');
|
||||
}
|
||||
}
|
||||
}
|
||||
17
app/Http/Middleware/EncryptCookies.php
Normal file
17
app/Http/Middleware/EncryptCookies.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||
|
||||
class EncryptCookies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
17
app/Http/Middleware/PreventRequestsDuringMaintenance.php
Normal file
17
app/Http/Middleware/PreventRequestsDuringMaintenance.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
|
||||
|
||||
class PreventRequestsDuringMaintenance extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be reachable while maintenance mode is enabled.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
32
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
32
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null ...$guards
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, ...$guards)
|
||||
{
|
||||
$guards = empty($guards) ? [null] : $guards;
|
||||
|
||||
foreach ($guards as $guard) {
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
25
app/Http/Middleware/SetLocale.php
Normal file
25
app/Http/Middleware/SetLocale.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Http\Controllers\LanguageController;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class SetLocale
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
App::setLocale(LanguageController::getActiveLanguage());
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
19
app/Http/Middleware/TrimStrings.php
Normal file
19
app/Http/Middleware/TrimStrings.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||
|
||||
class TrimStrings extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the attributes that should not be trimmed.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
||||
20
app/Http/Middleware/TrustHosts.php
Normal file
20
app/Http/Middleware/TrustHosts.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustHosts as Middleware;
|
||||
|
||||
class TrustHosts extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the host patterns that should be trusted.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hosts()
|
||||
{
|
||||
return [
|
||||
$this->allSubdomainsOfApplicationUrl(),
|
||||
];
|
||||
}
|
||||
}
|
||||
23
app/Http/Middleware/TrustProxies.php
Normal file
23
app/Http/Middleware/TrustProxies.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Fideloper\Proxy\TrustProxies as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The trusted proxies for this application.
|
||||
*
|
||||
* @var array|string|null
|
||||
*/
|
||||
protected $proxies;
|
||||
|
||||
/**
|
||||
* The headers that should be used to detect proxies.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $headers = Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO | Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||
}
|
||||
17
app/Http/Middleware/VerifyCsrfToken.php
Normal file
17
app/Http/Middleware/VerifyCsrfToken.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
|
||||
class VerifyCsrfToken extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
25
app/Models/Domains.php
Normal file
25
app/Models/Domains.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Domains extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public function records(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Records::class);
|
||||
}
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::deleting(function ($domain) {
|
||||
$domain->records()->delete();
|
||||
});
|
||||
}
|
||||
}
|
||||
16
app/Models/Records.php
Normal file
16
app/Models/Records.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Records extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public function domain(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Domains::class, 'domains_id');
|
||||
}
|
||||
}
|
||||
24
app/Models/User.php
Normal file
24
app/Models/User.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
];
|
||||
}
|
||||
28
app/Providers/AppServiceProvider.php
Normal file
28
app/Providers/AppServiceProvider.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
30
app/Providers/AuthServiceProvider.php
Normal file
30
app/Providers/AuthServiceProvider.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The policy mappings for the application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $policies = [
|
||||
// 'App\Models\Model' => 'App\Policies\ModelPolicy',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any authentication / authorization services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->registerPolicies();
|
||||
|
||||
//
|
||||
}
|
||||
}
|
||||
21
app/Providers/BroadcastServiceProvider.php
Normal file
21
app/Providers/BroadcastServiceProvider.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Broadcast;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class BroadcastServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Broadcast::routes();
|
||||
|
||||
require base_path('routes/channels.php');
|
||||
}
|
||||
}
|
||||
32
app/Providers/EventServiceProvider.php
Normal file
32
app/Providers/EventServiceProvider.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event listener mappings for the application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $listen = [
|
||||
Registered::class => [
|
||||
SendEmailVerificationNotification::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
63
app/Providers/RouteServiceProvider.php
Normal file
63
app/Providers/RouteServiceProvider.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The path to the "home" route for your application.
|
||||
*
|
||||
* This is used by Laravel authentication to redirect users after login.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public const HOME = '/home';
|
||||
|
||||
/**
|
||||
* The controller namespace for the application.
|
||||
*
|
||||
* When present, controller route declarations will automatically be prefixed with this namespace.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
// protected $namespace = 'App\\Http\\Controllers';
|
||||
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, etc.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->configureRateLimiting();
|
||||
|
||||
$this->routes(function () {
|
||||
Route::prefix('api')
|
||||
->middleware('api')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/api.php'));
|
||||
|
||||
Route::middleware('web')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/web.php'));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the rate limiters for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function configureRateLimiting()
|
||||
{
|
||||
RateLimiter::for('api', function (Request $request) {
|
||||
return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user