Merge branch 'Radius/add-router-management-v1' into 'master'
Add router management functionality with GenieACS integration See merge request fronk/thetool!1915
This commit is contained in:
@@ -283,4 +283,288 @@ HTML;
|
||||
self::sendError("E-Mail konnte nicht gesendet werden. Bitte kontaktieren Sie den Support.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get GenieACS instance
|
||||
* @return GenieACS
|
||||
*/
|
||||
private function getGenieACS() {
|
||||
$host = defined('GENIEACS_HOST') ? GENIEACS_HOST : 'http://acs.xinon.at:3000';
|
||||
$username = defined('GENIEACS_USERNAME') ? GENIEACS_USERNAME : 'admin';
|
||||
$password = defined('GENIEACS_PASSWORD') ? GENIEACS_PASSWORD : 'savemanfb545aw';
|
||||
|
||||
return new GenieACS($host, $username, $password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if GenieACS task response indicates success
|
||||
* @param mixed $result
|
||||
* @return bool
|
||||
*/
|
||||
private static function isGenieAcsTaskSuccess($result) {
|
||||
// Null or empty array can indicate success (204 No Content)
|
||||
if ($result === null || (is_array($result) && empty($result))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Has explicit success flag
|
||||
if (isset($result['success']) && $result['success']) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Array of tasks with _id (task created successfully)
|
||||
if (is_array($result)) {
|
||||
// Check if it's an array of task objects
|
||||
foreach ($result as $item) {
|
||||
if (is_array($item) && isset($item['_id'])) {
|
||||
return true; // Task was created
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get devices from GenieACS and match by IP
|
||||
*/
|
||||
protected function genieacsGetDeviceByIpAction() {
|
||||
try {
|
||||
$ip = $_GET['ip'] ?? null;
|
||||
if (!$ip) {
|
||||
self::sendError("IP address is required");
|
||||
}
|
||||
|
||||
$acs = $this->getGenieACS();
|
||||
$devices = $acs->getDevices();
|
||||
|
||||
if (!$devices || !is_array($devices)) {
|
||||
self::returnJson(['success' => false, 'message' => 'No devices found']);
|
||||
return;
|
||||
}
|
||||
|
||||
// Find device by matching external IP
|
||||
$matchedDevice = null;
|
||||
foreach ($devices as $device) {
|
||||
$externalIp = GenieACS::getExternalIP($device);
|
||||
if ($externalIp === $ip) {
|
||||
$matchedDevice = $device;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$matchedDevice) {
|
||||
self::returnJson(['success' => false, 'message' => 'No device found with this IP']);
|
||||
return;
|
||||
}
|
||||
|
||||
$deviceId = GenieACS::getDeviceId($matchedDevice);
|
||||
$deviceInfo = GenieACS::getDeviceInfo($matchedDevice);
|
||||
$managementIp = GenieACS::getManagementIP($matchedDevice);
|
||||
|
||||
self::returnJson([
|
||||
'success' => true,
|
||||
'deviceId' => $deviceId,
|
||||
'deviceInfo' => $deviceInfo,
|
||||
'ip' => $ip,
|
||||
'managementIp' => $managementIp
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
error_log("GenieACS getDeviceByIp error: " . $e->getMessage());
|
||||
self::sendError("Error fetching device: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reboot device via GenieACS
|
||||
*/
|
||||
protected function genieacsRebootDeviceAction() {
|
||||
try {
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
$deviceId = $input['deviceId'] ?? null;
|
||||
|
||||
if (!$deviceId) {
|
||||
self::sendError("Device ID is required");
|
||||
}
|
||||
|
||||
error_log("GenieACS reboot request for device: " . $deviceId);
|
||||
|
||||
$acs = $this->getGenieACS();
|
||||
$result = $acs->rebootDevice($deviceId);
|
||||
|
||||
error_log("GenieACS reboot result: " . json_encode($result));
|
||||
|
||||
if (self::isGenieAcsTaskSuccess($result)) {
|
||||
self::returnJson(['success' => true, 'message' => 'Reboot task created', 'result' => $result]);
|
||||
} else {
|
||||
self::returnJson(['success' => false, 'message' => 'Failed to create reboot task', 'result' => $result]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log("GenieACS rebootDevice error: " . $e->getMessage());
|
||||
self::sendError("Error rebooting device: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh device information
|
||||
*/
|
||||
protected function genieacsRefreshDeviceAction() {
|
||||
try {
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
$deviceId = $input['deviceId'] ?? null;
|
||||
|
||||
if (!$deviceId) {
|
||||
self::sendError("Device ID is required");
|
||||
}
|
||||
|
||||
$acs = $this->getGenieACS();
|
||||
$result = $acs->refreshDevice($deviceId);
|
||||
|
||||
if (self::isGenieAcsTaskSuccess($result)) {
|
||||
self::returnJson(['success' => true, 'message' => 'Refresh task created', 'result' => $result]);
|
||||
} else {
|
||||
self::returnJson(['success' => false, 'message' => 'Failed to create refresh task', 'result' => $result]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log("GenieACS refreshDevice error: " . $e->getMessage());
|
||||
self::sendError("Error refreshing device: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get device parameters
|
||||
*/
|
||||
protected function genieacsGetParametersAction() {
|
||||
try {
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
$deviceId = $input['deviceId'] ?? null;
|
||||
$parameters = $input['parameters'] ?? [];
|
||||
|
||||
if (!$deviceId || empty($parameters)) {
|
||||
self::sendError("Device ID and parameters are required");
|
||||
}
|
||||
|
||||
$acs = $this->getGenieACS();
|
||||
$result = $acs->getParameterValues($deviceId, $parameters);
|
||||
|
||||
// Check if result is a successful task response
|
||||
if (self::isGenieAcsTaskSuccess($result)) {
|
||||
self::returnJson(['success' => true, 'message' => 'Get parameters task created', 'result' => $result]);
|
||||
} else {
|
||||
self::returnJson(['success' => false, 'message' => 'Failed to create get parameters task', 'result' => $result]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log("GenieACS getParameters error: " . $e->getMessage());
|
||||
self::sendError("Error getting parameters: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set device parameters
|
||||
*/
|
||||
protected function genieacsSetParametersAction() {
|
||||
try {
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
$deviceId = $input['deviceId'] ?? null;
|
||||
$parameters = $input['parameters'] ?? [];
|
||||
|
||||
if (!$deviceId || empty($parameters)) {
|
||||
self::sendError("Device ID and parameters are required");
|
||||
}
|
||||
|
||||
$acs = $this->getGenieACS();
|
||||
$result = $acs->setParameterValues($deviceId, $parameters);
|
||||
|
||||
if (self::isGenieAcsTaskSuccess($result)) {
|
||||
self::returnJson(['success' => true, 'message' => 'Set parameters task created', 'result' => $result]);
|
||||
} else {
|
||||
self::returnJson(['success' => false, 'message' => 'Failed to create set parameters task', 'result' => $result]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log("GenieACS setParameters error: " . $e->getMessage());
|
||||
self::sendError("Error setting parameters: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get full device information
|
||||
*/
|
||||
protected function genieacsGetDeviceInfoAction() {
|
||||
try {
|
||||
$deviceId = $_GET['deviceId'] ?? null;
|
||||
|
||||
if (!$deviceId) {
|
||||
self::sendError("Device ID is required");
|
||||
}
|
||||
|
||||
$acs = $this->getGenieACS();
|
||||
$device = $acs->getDevice($deviceId);
|
||||
|
||||
if (!$device) {
|
||||
self::sendError("Device not found");
|
||||
}
|
||||
|
||||
$deviceInfo = GenieACS::getDeviceInfo($device);
|
||||
$externalIp = GenieACS::getExternalIP($device);
|
||||
$macAddress = GenieACS::getMacAddress($device);
|
||||
|
||||
self::returnJson([
|
||||
'success' => true,
|
||||
'deviceInfo' => $deviceInfo,
|
||||
'externalIp' => $externalIp,
|
||||
'macAddress' => $macAddress,
|
||||
'fullData' => $device
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
error_log("GenieACS getDeviceInfo error: " . $e->getMessage());
|
||||
self::sendError("Error getting device info: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ping an IP address via GenieACS
|
||||
*/
|
||||
protected function genieacsPingAction() {
|
||||
try {
|
||||
$ip = $_GET['ip'] ?? null;
|
||||
|
||||
if (!$ip) {
|
||||
self::sendError("IP address is required");
|
||||
}
|
||||
|
||||
$acs = $this->getGenieACS();
|
||||
$result = $acs->ping($ip);
|
||||
|
||||
self::returnJson(['success' => true, 'result' => $result]);
|
||||
} catch (Exception $e) {
|
||||
error_log("GenieACS ping error: " . $e->getMessage());
|
||||
self::sendError("Error pinging: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory reset device via GenieACS
|
||||
*/
|
||||
protected function genieacsFactoryResetAction() {
|
||||
try {
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
$deviceId = $input['deviceId'] ?? null;
|
||||
|
||||
if (!$deviceId) {
|
||||
self::sendError("Device ID is required");
|
||||
}
|
||||
|
||||
$acs = $this->getGenieACS();
|
||||
$result = $acs->factoryResetDevice($deviceId);
|
||||
|
||||
if (self::isGenieAcsTaskSuccess($result)) {
|
||||
self::returnJson(['success' => true, 'message' => 'Factory reset task created', 'result' => $result]);
|
||||
} else {
|
||||
self::returnJson(['success' => false, 'message' => 'Failed to create factory reset task', 'result' => $result]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log("GenieACS factoryReset error: " . $e->getMessage());
|
||||
self::sendError("Error factory resetting device: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user