mirror of
https://github.com/mivodev/mivo.git
synced 2026-01-26 13:31:56 +07:00
Initial Release v1.0.0: Full feature set with Docker automation, Nginx/Alpine stack
This commit is contained in:
47
app/Controllers/SystemController.php
Normal file
47
app/Controllers/SystemController.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Core\Controller;
|
||||
use App\Models\Config;
|
||||
use App\Libraries\RouterOSAPI;
|
||||
|
||||
class SystemController extends Controller
|
||||
{
|
||||
// Reboot Router
|
||||
public function reboot($session)
|
||||
{
|
||||
$this->executeCommand($session, '/system/reboot');
|
||||
}
|
||||
|
||||
// Shutdown Router
|
||||
public function shutdown($session)
|
||||
{
|
||||
$this->executeCommand($session, '/system/shutdown');
|
||||
}
|
||||
|
||||
private function executeCommand($session, $command)
|
||||
{
|
||||
$configModel = new Config();
|
||||
$config = $configModel->getSession($session);
|
||||
if (!$config) {
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['error' => 'Session not found']);
|
||||
return;
|
||||
}
|
||||
|
||||
$API = new RouterOSAPI();
|
||||
if ($API->connect($config['ip_address'], $config['username'], $config['password'])) {
|
||||
$API->write($command);
|
||||
// Wait for command to be processed before cutting connection
|
||||
sleep(2);
|
||||
$API->disconnect();
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['success' => true]);
|
||||
} else {
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['error' => 'Connection failed']);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user