diff --git a/Layout/default/Device/Detail.php b/Layout/default/Device/Detail.php index 25d83adb0..dd5e780c9 100644 --- a/Layout/default/Device/Detail.php +++ b/Layout/default/Device/Detail.php @@ -135,6 +135,17 @@ padding: 6px 0.85rem 6px 0.85rem !important; } + .fa-fileupload { + font-size: 28px; + color: #128a01; + margin-top: 4px; + cursor: pointer; + } + + .form-label-upload { + margin-top: 10px; + } + @@ -337,15 +348,20 @@ foreach ($devicesall as $deviceall) { + is('Admin')) : ?>

Config Backups

+ devicetype->devicemanufactor->config_backup > count()): ?> + + is('Admin')): ?>
@@ -354,8 +370,30 @@ foreach ($devicesall as $deviceall) {
+
+ success == "true" && $devicesconfig->data > count()) { ?> @@ -683,6 +721,64 @@ foreach ($devicesall as $deviceall) { diff --git a/application/Device/DeviceController.php b/application/Device/DeviceController.php index b55d259a0..ee235cd49 100644 --- a/application/Device/DeviceController.php +++ b/application/Device/DeviceController.php @@ -318,6 +318,9 @@ class DeviceController extends mfBaseController case "createconfig": $this->createConfig($ip); break; + case "uploadFile": + $this->uploadFile($id); + break; case "getoltinfo": $this->getoltInfo($ip, $portid, $adv); break; @@ -361,6 +364,15 @@ class DeviceController extends mfBaseController exit; } + private function uploadFile($id) + { + $r = $this->request; + $file = $_FILES; + $response = DeviceModel::uploadFile($id, $file); + echo $response; + die(); + + } private function createConfig($ip) { diff --git a/application/Device/DeviceModel.php b/application/Device/DeviceModel.php index 7ed65c35f..5ad359291 100644 --- a/application/Device/DeviceModel.php +++ b/application/Device/DeviceModel.php @@ -362,4 +362,65 @@ class DeviceModel endif; return json_decode($response); } + public static function uploadFile($id, $file) + { + $response = ""; + + if (TT_MBI_API_ENABLE) { + // Überprüfe, ob im $_FILES-Array ein 'files'-Eintrag vorhanden ist + // und ob mindestens eine Datei hochgeladen wurde. + if (!isset($_FILES['files']) || !isset($_FILES['files']['tmp_name'][0]) || empty($_FILES['files']['tmp_name'][0])) { + return json_encode(["error" => "Dateiupload fehlgeschlagen: Keine Datei unter 'files' gefunden."]); + } + + // Baue die URL zusammen + $url = TT_MBI_API_URL . TT_MBI_API_VERSION . '/deviceuploadfile/' . $id; + + // Erstelle ein CURLFile-Objekt aus dem ersten (und evtl. einzigen) Element + $curlFile = new CURLFile( + $_FILES['files']['tmp_name'][0], + $_FILES['files']['type'][0], + $_FILES['files']['name'][0] + ); + + // Bereite die POST-Daten vor: Der Schlüssel "file" entspricht + // eventuell den Erwartungen der API. + $postFields = ['file' => $curlFile]; + + // cURL-Handle initialisieren und Optionen setzen + $curl = curl_init(); + curl_setopt_array($curl, [ + CURLOPT_URL => $url, + CURLOPT_HEADER => true, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_SSL_VERIFYHOST => false, + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => $postFields, + CURLOPT_HTTPHEADER => [ + 'Authorization: Bearer ' . TT_MBI_API_KEY + ] + ]); + + // Führe die Anfrage aus + $response = curl_exec($curl); + + // Fehlerbehandlung: Bei einem cURL-Fehler gebe diesen als JSON zurück + if (curl_errno($curl)) { + $error_msg = curl_error($curl); + curl_close($curl); + return json_encode(["error" => $error_msg]); + } + + // Schließe den cURL-Handle + curl_close($curl); + } + + // Dekodiere die Antwort und gebe sie zurück + return json_decode($response); + } + } \ No newline at end of file