Gerätehersteller, Devices, API Erweiterungen
This commit is contained in:
@@ -42,7 +42,9 @@ class DeviceController extends mfBaseController
|
||||
}
|
||||
|
||||
$this->layout()->setTemplate("Device/Detail");
|
||||
$devicesconfig = DeviceModel::getconifg($id);
|
||||
$devices = DeviceModel::getOne($id);
|
||||
$this->layout()->set("devicesconfig", $devicesconfig);
|
||||
$this->layout()->set("devices", $devices);
|
||||
|
||||
}
|
||||
@@ -60,13 +62,13 @@ class DeviceController extends mfBaseController
|
||||
$id = $this->request->id;
|
||||
|
||||
if (!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Gerät nicht gefunden", "error");
|
||||
$this->layout()->setFlash("Device nicht gefunden", "error");
|
||||
$this->redirect("Device");
|
||||
}
|
||||
|
||||
$device = new Device($id);
|
||||
if ($device->id != $id) {
|
||||
$this->layout()->setFlash("Gerät nicht gefunden", "error");
|
||||
$this->layout()->setFlash("Device nicht gefunden", "error");
|
||||
$this->redirect("Device");
|
||||
}
|
||||
|
||||
@@ -93,7 +95,7 @@ class DeviceController extends mfBaseController
|
||||
$data = [];
|
||||
$data['name'] = trim($r->name);
|
||||
$data['devicetype_id'] = $r->devicetype_id;
|
||||
if (trim($r->pop_id)=="0") {
|
||||
if (trim($r->pop_id) == "0") {
|
||||
$data['pop_id'] = NULL;
|
||||
} else {
|
||||
$data['pop_id'] = $r->pop_id;
|
||||
@@ -101,6 +103,16 @@ class DeviceController extends mfBaseController
|
||||
$data['ip'] = $r->ip;
|
||||
$data['mac'] = $r->mac;
|
||||
$data['serial'] = $r->serial;
|
||||
if (empty(trim($r->price))) {
|
||||
$data['price'] = "0.00";
|
||||
} else {
|
||||
$data['price'] = $r->price;
|
||||
}
|
||||
if (empty(trim($r->power))) {
|
||||
$data['power'] = "0.0";
|
||||
} else {
|
||||
$data['power'] = $r->power;
|
||||
}
|
||||
$data['comment'] = $r->comment;
|
||||
$ipv4_validation_regex = "/^(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/";
|
||||
|
||||
@@ -133,11 +145,8 @@ class DeviceController extends mfBaseController
|
||||
// exit;
|
||||
$id = $device->save();
|
||||
|
||||
if (!$id) {
|
||||
$this->layout()->setFlash("Device konnte nicht angelegt werden", "error");
|
||||
$this->redirect("Device");
|
||||
}
|
||||
$returnUrl="Device";
|
||||
|
||||
$returnUrl = "Device";
|
||||
$returnAction = "Index";
|
||||
$returnVariables = array();
|
||||
$returnAnker = "";
|
||||
@@ -163,6 +172,15 @@ class DeviceController extends mfBaseController
|
||||
}
|
||||
}
|
||||
|
||||
if (!$id) {
|
||||
$returnVariables['id'] = $r->id;
|
||||
if ($mode == "edit") {
|
||||
$this->layout()->setFlash("Device konnte nicht gespeichert werden", "error");
|
||||
} else if ($mode = "add") {
|
||||
$this->layout()->setFlash("Device konnte nicht angelegt werden", "error");
|
||||
}
|
||||
$this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
|
||||
}
|
||||
|
||||
if ($mode == "edit") {
|
||||
$this->layout()->setFlash("Device erfolgreich geändert", "success");
|
||||
@@ -171,4 +189,63 @@ class DeviceController extends mfBaseController
|
||||
}
|
||||
$this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
|
||||
}
|
||||
|
||||
protected function apiAction()
|
||||
{
|
||||
if (!$this->me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
$do = $this->request->do;
|
||||
$format = $this->request->format;
|
||||
$filename = $this->request->filename;
|
||||
$id = $this->request->id;
|
||||
$ip = $this->request->ip;
|
||||
|
||||
$data = [];
|
||||
|
||||
switch ($do) {
|
||||
case "getconfig":
|
||||
$return = $this->getConfig($id, $format, $filename);
|
||||
break;
|
||||
case "createconfig":
|
||||
$return = $this->createConfig($ip);
|
||||
break;
|
||||
default:
|
||||
$return = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function getConfig($id, $format, $filename)
|
||||
{
|
||||
$configDownload = DeviceModel::getconifgdownload($id, $format);
|
||||
//
|
||||
|
||||
// header('Content-Type: application/octet-stream');
|
||||
header('Content-Type: text/plain');
|
||||
header('Content-disposition: attachment; filename="' . $filename . '"');
|
||||
echo $configDownload;
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
private function createConfig($ip)
|
||||
{
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
$createConfig = DeviceModel::configcreate($ip);
|
||||
if ($createConfig->success==="true")
|
||||
{
|
||||
$this->layout()->setFlash("Backup wurde erfolgreich erstellt", "success");
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->layout()->setFlash("Backup konnte nicht erstellt werden. <b>Fehler</b>: ".$createConfig->error, "error");
|
||||
}
|
||||
$returnUrl = "Device";
|
||||
$returnAction = "Detail";
|
||||
$returnVariables['id'] = $id;
|
||||
return $this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user