diff --git a/Layout/default/Device/Detail.php b/Layout/default/Device/Detail.php index 6a161376d..c8d9ca4c6 100644 --- a/Layout/default/Device/Detail.php +++ b/Layout/default/Device/Detail.php @@ -25,7 +25,8 @@ -

Device: data->name ?> +

Device: data->name ?> + $devices->id, 'returnto' => "device-detail"]) ?>"> @@ -36,11 +37,17 @@ price)) { +if ($devices->price != "0.00") { $price = $devices->price; } else { $price = $devices->devicetype->price; } +if ($devices->power != "0.0") { + $power = $devices->power; +} else { + $power = $devices->devicetype->power; +} + ?>
@@ -83,6 +90,10 @@ if (!empty($devices->price)) { Preis € + + Leistung + Watt + Bemerkung comment) ?> @@ -152,11 +163,21 @@ if (!empty($devices->price)) {
-
-

Config Backups

+
+

Config Backups

+ devicetype->devicemanufactor->config_backup > count()): ?> + + +
success == "true" && $devicesconfig->data > count()) { ?>
@@ -164,21 +185,35 @@ if (!empty($devices->price)) { + - - - - + data as $config) : + $configfileCleartext = $config->config_cleartext; + $configfileCompressed = $config->config_compressed; + $configid = $config->id; + ?> + + + + + + +
Datum/Uhrzeit
config_timestamp); ?> + + TXT / + XML
-
Keine Configs vorhanden
- +
+
Keine Configs vorhanden
+
@@ -191,10 +226,48 @@ if (!empty($devices->price)) {
+devicetype->devicemanufactor->config_backup > count()): + $year = date("Y", time()); + $month = date("n", time()); + $day = date("d", time()); + $config = $devices->devicetype->devicemanufactor->config_backup; + $config = str_replace("&&YEAR&&", $year, $config); + $config = str_replace("&&MONTH&&", $month, $config); + $config = str_replace("&&DAY&&", $day, $config); + + ?> + + + + diff --git a/Layout/default/Device/Form.php b/Layout/default/Device/Form.php index 3da64e550..3714e7b24 100644 --- a/Layout/default/Device/Form.php +++ b/Layout/default/Device/Form.php @@ -1,11 +1,25 @@ id]=$devicetype->devicemanufactor->name . " " . $devicetype->name; + $deviceTypes[$devicetype->id] = $devicetype->devicemanufactor->name . " " . $devicetype->name; } asort($deviceTypes); - +if ($device->price == "0.00") { + $price = ""; +} else { + $price = $device->price; +} +if ($device->power == "0.0") { + $power = ""; +} else { + $power = $device->power; +} +if (isset($_GET['returnto']) && $_GET['returnto'] == "device-detail") { + $cancelUrl = self::getUrl("Device", "Detail", ["id" => $device->id]); +} else { + $cancelUrl = self::getUrl("Device"); +} ?> @@ -34,7 +48,6 @@ asort($deviceTypes);

id) ? "Device bearbeiten" : "Neues Gerät" ?>

-
$_GET["returnto"]]) ?>">
@@ -93,6 +106,22 @@ asort($deviceTypes); value="serial ?>">
+
+ +
+ +
+
+
+ +
+ +
+
@@ -109,6 +138,10 @@ asort($deviceTypes);
+ + + +
diff --git a/Layout/default/Device/Index.php b/Layout/default/Device/Index.php index 04b81e309..b506d76e0 100644 --- a/Layout/default/Device/Index.php +++ b/Layout/default/Device/Index.php @@ -4,7 +4,7 @@ $pagination_baseurl_params = ["filter" => $filter]; $pagination_entity_name = "Device"; ?> - + @@ -74,11 +74,16 @@ $pagination_entity_name = "Device"; price)) { + if ($device->price != "0.00") { $price = $device->price; } else { $price = $device->devicetype->price; } + if ($device->power != "0.0") { + $power = $device->power; + } else { + $power = $device->devicetype->power; + } ?> @@ -94,7 +99,7 @@ $pagination_entity_name = "Device"; mac ?> serial ?> € - devicetype->power ?> Watt + Watt @@ -124,13 +129,13 @@ $pagination_entity_name = "Device"; - + \ No newline at end of file diff --git a/Layout/default/Devicemanufactor/Form.php b/Layout/default/Devicemanufactor/Form.php index a524cc9fc..0d2b6100e 100644 --- a/Layout/default/Devicemanufactor/Form.php +++ b/Layout/default/Devicemanufactor/Form.php @@ -42,6 +42,13 @@ value="name ?>">
+
+ +
+ +
+
diff --git a/application/Api/v1/DeviceApicontroller.php b/application/Api/v1/DeviceApicontroller.php new file mode 100644 index 000000000..2d2b760fb --- /dev/null +++ b/application/Api/v1/DeviceApicontroller.php @@ -0,0 +1,25 @@ +db(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME); + $this->addRoute("/device/getDevices", "getDevices", "GET"); + + } + + protected function getDevices() + { + $devices = DeviceModel::getAll(); + foreach ($devices as $key => $device) { + $deviceReturn[$key]['id'] = $device->id; + $deviceReturn[$key]['name'] = $device->name; + $deviceReturn[$key]['ip'] = $device->ip; + $deviceReturn[$key]['serial'] = $device->serial; + } + + return mfResponse::Ok($deviceReturn); + + } +} \ No newline at end of file diff --git a/application/Device/DeviceController.php b/application/Device/DeviceController.php index 328dae192..37c9b49c6 100644 --- a/application/Device/DeviceController.php +++ b/application/Device/DeviceController.php @@ -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. Fehler: ".$createConfig->error, "error"); + } + $returnUrl = "Device"; + $returnAction = "Detail"; + $returnVariables['id'] = $id; + return $this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker); + } + } \ No newline at end of file diff --git a/application/Device/DeviceModel.php b/application/Device/DeviceModel.php index cd7bfb807..b5df9bdcc 100644 --- a/application/Device/DeviceModel.php +++ b/application/Device/DeviceModel.php @@ -5,8 +5,8 @@ class DeviceModel public $name = null; public $ip = null; public $mac = null; - public $serial= null; - public $comment= null; + public $serial = null; + public $comment = null; public $devicetype_id = null; public $pop_id = null; @@ -16,16 +16,18 @@ class DeviceModel public $create = null; public $edit = null; - public static function find($data) { + public static function find($data) + { } - public static function create(Array $data) { + public static function create(array $data) + { $model = new Device(); - foreach($data as $field => $value) { - if(property_exists(get_called_class(), $field)) { - if(substr($field, 0, 5) == "vlan_" && !$value) { + foreach ($data as $field => $value) { + if (property_exists(get_called_class(), $field)) { + if (substr($field, 0, 5) == "vlan_" && !$value) { $model->$field = null; continue; } @@ -34,45 +36,47 @@ class DeviceModel } $me = mfValuecache::singleton()->get("me"); - if(!$me) { + if (!$me) { $me = new User(); $me->loadMe(); mfValuecache::singleton()->set("me", $me); } - if($model->create_by === null) { + if ($model->create_by === null) { $model->create_by = $me->id; } - if($model->edit_by === null) { + if ($model->edit_by === null) { $model->edit_by = $me->id; } return $model; } - public static function getOne($id) { - if(!is_numeric($id) || !$id) { + public static function getOne($id) + { + if (!is_numeric($id) || !$id) { throw new Exception("Invalid number", 400); } $item = []; $db = FronkDB::singleton(); $res = $db->select("Device", "*", "id=$id LIMIT 1"); - if($db->num_rows($res)) { + if ($db->num_rows($res)) { $data = $db->fetch_object($res); $item = new Device($data); } return $item; } - public static function getAll() { + public static function getAll() + { $items = []; $db = FronkDB::singleton(); $res = $db->select("Device", "*"); - if($db->num_rows($res)) { - while($data = $db->fetch_object($res)) { + if ($db->num_rows($res)) { + while ($data = $db->fetch_object($res)) { $items[] = new Device($data); } } @@ -80,15 +84,16 @@ class DeviceModel } - public static function getFirst() { + public static function getFirst() + { $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); $res = $db->select("Device", "*", "$where ORDER BY name, network_id"); - if($db->num_rows($res)) { + if ($db->num_rows($res)) { $data = $db->fetch_object($res); $item = new Device($data); - if($item->id) { + if ($item->id) { return $item; } else { return null; @@ -97,26 +102,28 @@ class DeviceModel return null; } - public static function search($filter) { + public static function search($filter) + { $items = []; $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); $res = $db->select("Device", "*", "$where ORDER BY name"); - if($db->num_rows($res)) { - while($data = $db->fetch_object($res)) { + if ($db->num_rows($res)) { + while ($data = $db->fetch_object($res)) { $items[] = new Device($data); } } return $items; } - private static function getSqlFilter($filter) { + private static function getSqlFilter($filter) + { $where = "1=1 "; //var_dump($filter);exit; - if(array_key_exists("pop_id", $filter)) { + if (array_key_exists("pop_id", $filter)) { $popid = $filter['pop_id']; - if(is_numeric($popid)) { + if (is_numeric($popid)) { $where .= " AND pop_id=$popid"; } } @@ -124,4 +131,78 @@ class DeviceModel //var_dump($filter, $where);exit; return $where; } + + public static function getconifg($id) + { + $curl = curl_init(); + + curl_setopt_array($curl, array( + CURLOPT_URL => 'https://172.16.5.56/api/deviceconfigs/' . $id, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_SSL_VERIFYHOST => false, + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_HTTPHEADER => array( + 'Authorization: Bearer 4|6l5ixx3CYBP7xClqEfVAC3zrBbQlxusAtu4zNwQp'), + )); + $response = curl_exec($curl); + curl_close($curl); + return json_decode($response); + } + + public static function getconifgdownload($id, $format) + { + $curl = curl_init(); + + curl_setopt_array($curl, array( + CURLOPT_URL => 'https://172.16.5.56/api/deviceconfigsdownload/' . $id . '/' . $format, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_SSL_VERIFYHOST => false, + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_HTTPHEADER => array( + 'Authorization: Bearer 5|3QyhSkLgzrHwdVt05wQFUp2sFciiFhhGzucJirnI'), + )); + + $response = curl_exec($curl); + + curl_close($curl); +// echo $response; +// var_dump($response); + return ($response); + } + + + public static function configcreate($ip) + { + $curl = curl_init(); + + curl_setopt_array($curl, array( + CURLOPT_URL => 'https://172.16.5.56/api/deviceconfigscreate/' . $ip , + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_SSL_VERIFYHOST => false, + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_HTTPHEADER => array( + 'Authorization: Bearer 5|3QyhSkLgzrHwdVt05wQFUp2sFciiFhhGzucJirnI'), + )); + $response = curl_exec($curl); + + return json_decode($response); + } } \ No newline at end of file diff --git a/application/Devicemanufactor/DevicemanufactorController.php b/application/Devicemanufactor/DevicemanufactorController.php index 2b57e377a..cc535e56d 100644 --- a/application/Devicemanufactor/DevicemanufactorController.php +++ b/application/Devicemanufactor/DevicemanufactorController.php @@ -68,6 +68,7 @@ class DevicemanufactorController extends mfBaseController $data = []; $data['name'] = trim($r->name); + $data['config_backup'] = trim($r->config_backup); if (!$data['name']) { diff --git a/public/assets/css/datatables-std.css b/public/assets/css/datatables-std.css index 64953aef9..b0e233eb8 100644 --- a/public/assets/css/datatables-std.css +++ b/public/assets/css/datatables-std.css @@ -32,6 +32,10 @@ width: 50px; } +.edit-width-large { + width: 100px; +} + .order-date-pill { margin: 2px; white-space: nowrap; @@ -40,3 +44,40 @@ .font-weight-500 { font-weight: 500; } + +.history-ico { + color: #007bff; + cursor: pointer; +} + +.history-ico:hover { + color: #006875; + +} + +.code-ico { + cursor: pointer; + font-size: 25px; + margin-top: 7px; + margin-left: 10px; +} + +.spinner-ico { + margin-left: 5px; +} + +.filestore-history { + background-color: #33ff0021 !important; +} + +.filestore-history-td { + padding: 0 0px 0 10px !important; + box-shadow: unset; +} +.filestore-history-td:hover { + box-shadow: unset !important; +} +.filestore-history-tr:hover{ + color: unset !important; + background-color: #fff !important; +} \ No newline at end of file