-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #249 from TripleSD/dev
New version 0.1.10 (build 032)
- Loading branch information
Showing
99 changed files
with
20,308 additions
and
13,695 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
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
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,72 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\BackupFtpList; | ||
use App\Models\BackupFtpLogs; | ||
use Carbon\Carbon; | ||
use Illuminate\Console\Command; | ||
|
||
class BackupFtpScraper extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'scraper:ftp {--interval=}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Command description'; | ||
|
||
public function handle() | ||
{ | ||
if ($this->option('interval') === '3') { | ||
$interval = 3; | ||
} elseif ($this->option('interval') === '6') { | ||
$interval = 6; | ||
} elseif ($this->option('interval') === '12') { | ||
$interval = 12; | ||
} elseif ($this->option('interval') === '24') { | ||
$interval = 24; | ||
} elseif ($this->option('interval') === '1') { | ||
$interval = 1; | ||
} else { | ||
$interval = 1; | ||
} | ||
|
||
$tasks = BackupFtpList::where('enabled', 1)->where('interval', $interval)->get(); | ||
|
||
foreach ($tasks as $task) { | ||
BackupFtpList::where('id', $task->id)->update(['updated_at' => Carbon::now()->format('Y-m-d H:i:s')]); | ||
|
||
$stream = ftp_connect($task->hostname); | ||
ftp_login($stream, $task->login, $task->password); | ||
ftp_pasv($stream, true); | ||
$files = ftp_mlsd($stream, "/$task->folder"); | ||
ftp_close($stream); | ||
|
||
$status = 0; | ||
$resolved = 0; | ||
|
||
foreach ($files as $file) { | ||
if ($file['name'] === $task->FullFilename) { | ||
$status = 1; | ||
$resolved = 1; | ||
} | ||
} | ||
|
||
$arr = [ | ||
'task_id' => $task->id, | ||
'status' => $status, | ||
'resolved' => $resolved, | ||
]; | ||
|
||
BackupFtpLogs::create($arr); | ||
} | ||
} | ||
} |
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,65 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\BackupYandexConnectors; | ||
use App\Models\BackupYandexConnectorsLogs; | ||
use Illuminate\Console\Command; | ||
|
||
class BackupYandexConnectorsKeeper extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'backup:yandex-connectors-keeper'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Updating information about Yandex Disk connectors'; | ||
|
||
public function handle() | ||
{ | ||
$connectors = BackupYandexConnectors::get(); | ||
|
||
foreach ($connectors as $connector) { | ||
$ch = curl_init('https://cloud-api.yandex.net/v1/disk/'); | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: OAuth ' . $connector->token]); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | ||
curl_setopt($ch, CURLOPT_HEADER, false); | ||
$res = curl_exec($ch); | ||
$httpcode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); | ||
curl_close($ch); | ||
|
||
$res = json_decode($res, true); | ||
|
||
if ($httpcode === 200) { | ||
BackupYandexConnectors::where('id', $connector->id)->update( | ||
[ | ||
'total_space' => $res['total_space'], | ||
'trash_size' => $res['trash_size'], | ||
'used_space' => $res['used_space'], | ||
'http_code' => $httpcode, | ||
'status' => 1, | ||
] | ||
); | ||
|
||
BackupYandexConnectorsLogs::create(['connector_id' => $connector->id, 'status' => 1, 'resolved' => 1]); | ||
} else { | ||
BackupYandexConnectors::where('id', $connector->id)->update( | ||
[ | ||
'http_code' => $httpcode, | ||
'status' => 0, | ||
] | ||
); | ||
|
||
BackupYandexConnectorsLogs::create(['connector_id' => $connector->id, 'status' => 0, 'resolved' => 0]); | ||
} | ||
} | ||
} | ||
} |
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
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
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,67 @@ | ||
<?php | ||
|
||
namespace App\Helpers; | ||
|
||
use App\Models\SystemLogs; | ||
|
||
/** | ||
* Class SystemLog. | ||
*/ | ||
class SystemLog | ||
{ | ||
/** | ||
* @param $functionName | ||
* @param $request | ||
* @return mixed | ||
*/ | ||
public static function createUserEvent($functionName, $request) | ||
{ | ||
if (isset(\Auth::user()->id)) { | ||
$userId = \Auth::user()->id; | ||
} else { | ||
$userId = 0; | ||
} | ||
|
||
$logArray = [ | ||
'service' => \Config::get('moring.service_system'), | ||
'debug_info' => $request->method(), | ||
'status' => $request->server('REDIRECT_STATUS'), | ||
'user_id' => $userId, | ||
'route' => \Route::getCurrentRoute()->getActionName() . PHP_EOL, | ||
'callable_function' => $functionName, | ||
]; | ||
|
||
return SystemLogs::create($logArray); | ||
} | ||
|
||
/** | ||
* @param $functionName | ||
* @param null $service | ||
* @param null $status | ||
* @param null $debugInfo | ||
* @return mixed | ||
*/ | ||
public static function createServiceEvent($functionName, $service = null, $status = null, $debugInfo = null) | ||
{ | ||
if (isset(\Auth::user()->id)) { | ||
$userId = \Auth::user()->id; | ||
} else { | ||
$userId = 0; | ||
} | ||
|
||
if ($service === 'mysql') { | ||
$service = \Config::get('moring.service_mysql'); | ||
} | ||
|
||
$logArray = [ | ||
'service' => $service, | ||
'debug_info' => $debugInfo, | ||
'status' => $status, | ||
'user_id' => $userId, | ||
'route' => \Route::getCurrentRoute()->getActionName() . PHP_EOL, | ||
'callable_function' => $functionName, | ||
]; | ||
|
||
return SystemLogs::create($logArray); | ||
} | ||
} |
Oops, something went wrong.