diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 1e6edff..cf18c06 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1 +1 @@ -__version__ = "4.0.0.43" +__version__ = "4.0.0.44" diff --git a/cbpi/controller/system_controller.py b/cbpi/controller/system_controller.py index ad1f902..cdb9c99 100644 --- a/cbpi/controller/system_controller.py +++ b/cbpi/controller/system_controller.py @@ -85,6 +85,30 @@ class SystemController: else: self.cbpi.notify("Error", "Wrong content type. Upload failed", NotificationType.ERROR) + async def uploadSVG(self, data): + fileData = data['File'] + filename = fileData.filename + svg_file = fileData.file + content_type = fileData.content_type + + logging.info(content_type) + + if content_type == 'image/svg+xml': + try: + content = svg_file.read().decode('utf-8','replace') + if svg_file and self.allowed_file(filename, 'svg'): + self.path = os.path.join(".","config","dashboard","widgets", filename) + logging.info(self.path) + + f=open(self.path, "w") + f.write(content) + f.close() + except: + self.cbpi.notify("Error", "SVG upload failed", NotificationType.ERROR) + pass + else: + self.cbpi.notify("Error", "Wrong content type. Upload failed", NotificationType.ERROR) + async def systeminfo(self): logging.info("SYSTEMINFO") system = "" @@ -147,6 +171,23 @@ class SystemController: except: pass + if system == "Windows": + try: + ethernet = psutil.net_if_addrs() + for nic, addrs in ethernet.items(): + if nic == "Ethernet": + for addr in addrs: + if str(addr.family) == "AddressFamily.AF_INET": + if addr.address: + eth0IP = addr.address + if nic == "WLAN": + for addr in addrs: + if str(addr.family) == "AddressFamily.AF_INET": + if addr.address: + wlan0IP = addr.address + except: + pass + except: pass diff --git a/cbpi/http_endpoints/http_system.py b/cbpi/http_endpoints/http_system.py index 2a0bb5a..468d57a 100644 --- a/cbpi/http_endpoints/http_system.py +++ b/cbpi/http_endpoints/http_system.py @@ -176,3 +176,20 @@ class SystemHttpEndpoints: """ systeminfo = await self.controller.systeminfo() return web.json_response(data=systeminfo) + + @request_mapping("/uploadsvg", method="POST", name="UploadSVG", auth_required=False) + async def uploadSVG(self, request): + """ + --- + description: Upload SVG file to widgets folder + tags: + - System + responses: + "200": + description: successful operation + """ + logging.info("Upload SVG file") + data = await request.post() + logging.info("Data received") + await self.controller.uploadSVG(data) + return web.Response(status=200) \ No newline at end of file