47 lines
1.1 KiB
PHP
47 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Bots;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class BashScript implements BotContract
|
|
{
|
|
protected array $config;
|
|
|
|
public function __construct(array $config = [])
|
|
{
|
|
$this->config = $config;
|
|
}
|
|
|
|
public function run(): void
|
|
{
|
|
if (!empty($this->config['script'])) {
|
|
// Execute the bash script
|
|
$script = $this->config['script'];
|
|
$output = [];
|
|
$returnVar = null;
|
|
exec($script, $output, $returnVar);
|
|
|
|
if ($returnVar !== 0) {
|
|
// Log error if the script failed
|
|
\Illuminate\Support\Facades\Log::error("Bash script execution failed: " . implode("\n", $output));
|
|
} else {
|
|
Log::info("Bash script executed successfully: " . implode("\n", $output));
|
|
}
|
|
}
|
|
}
|
|
|
|
public static function configSchema(): array
|
|
{
|
|
return [
|
|
'script' => [
|
|
'type' => 'textarea',
|
|
'label' => 'Bash Script',
|
|
'rules' => [
|
|
'required',
|
|
]
|
|
],
|
|
];
|
|
}
|
|
}
|