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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user