This commit is contained in:
Bozhidar Slaveykov 2023-11-27 22:57:30 +02:00
parent 9d80151b6e
commit 01e2d4fa7f
5 changed files with 44 additions and 17 deletions

View file

@ -2,6 +2,7 @@
namespace App\Models;
use App\ShellApi;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Sushi\Sushi;
@ -27,19 +28,25 @@ class CronJob extends Model
parent::boot();
static::creating(function ($model) {
$args = escapeshellarg($model->user) .' '. escapeshellarg($model->schedule) . ' ' . escapeshellarg($model->command);
$addCron = shell_exec('/usr/local/phyre/bin/cron-job-add.sh ' . $args);
$addCron = ShellApi::callBin('cron-job-add', [
$model->user,
$model->schedule,
$model->command,
]);
if (empty($addCron)) {
return false;
}
});
static::deleting(function ($model) {
$args = escapeshellarg($model->user) .' '. escapeshellarg($model->schedule) . ' ' . escapeshellarg($model->command);
$args = str_replace(PHP_EOL, '', $args);
$command = '/usr/local/phyre/bin/cron-job-delete.sh ' . $args;
$deleteCron = shell_exec($command);
$deleteCron = ShellApi::callBin('cron-job-delete', [
$model->user,
$model->schedule,
$model->command,
]);
if (empty($deleteCron)) {
return false;
}
@ -47,15 +54,18 @@ class CronJob extends Model
});
}
// protected function sushiShouldCache()
// {
// return true;
// }
protected function sushiShouldCache()
{
return true;
}
public function getRows()
{
$user = shell_exec('whoami');
$cronList = shell_exec('/usr/local/phyre/bin/cron-jobs-list.sh ' . $user);
$user = ShellApi::exec('whoami');
$cronList = ShellApi::callBin('cron-jobs-list', [
$user
]);
$rows = [];
if (!empty($cronList)) {

View file

@ -29,7 +29,7 @@ class Website extends Model
static::creating(function ($model) {
$createWebsite = ShellApi::exec('website-create', [
$createWebsite = ShellApi::callBin('website-create', [
$model->server_name,
'bobkata'
]);
@ -41,7 +41,7 @@ class Website extends Model
});
static::deleting(function ($model) {
$deleteWebsite = ShellApi::exec('website-delete', [
$deleteWebsite = ShellApi::callBin('website-delete', [
$model->server_name
]);
if (empty($deleteWebsite)) {
@ -57,7 +57,7 @@ class Website extends Model
public function getRows()
{
$websitesList = ShellApi::exec('websites-list');
$websitesList = ShellApi::callBin('websites-list');
$rows = [];
if (!empty($websitesList)) {

View file

@ -13,6 +13,22 @@ class ShellApi
}
}
$fullCommand = escapeshellarg($command) . $args;
$execOutput = shell_exec($fullCommand);
$execOutput = str_replace(PHP_EOL, '', $execOutput);
return $execOutput;
}
public static function callBin($command, $argsArray = [])
{
$args = '';
if (!empty($argsArray)) {
foreach ($argsArray as $arg) {
$args .= escapeshellarg($arg) . ' ';
}
}
$fullCommand = escapeshellarg('/usr/local/phyre/bin/' . $command . '.sh') . ' ' . $args;
$commandAsSudo = '/usr/bin/sudo ' . $fullCommand;

View file

@ -15,7 +15,8 @@
"laravel/framework": "^10.10",
"laravel/sanctum": "^3.3",
"laravel/tinker": "^2.8",
"mkocansey/bladewind": "^2.4"
"mkocansey/bladewind": "^2.4",
"symfony/process": "^6.3"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",

2
web/composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "4fbb7c7f0a39000819ceb94d722139fa",
"content-hash": "4156f41c529370e484d10e9e768c0279",
"packages": [
{
"name": "blade-ui-kit/blade-heroicons",