This commit is contained in:
46
app/Bots/BashScript.php
Normal file
46
app/Bots/BashScript.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?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',
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user