Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
croghostrider committed Mar 20, 2022
0 parents commit d4374ff
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Package Application with Pyinstaller

on:
pull_request:
paths:
- 'src/**'

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Package Application
uses: JackMcKew/pyinstaller-action-windows@main
with:
path: src

- uses: actions/upload-artifact@v2
with:
name: Loxone-Recovery
path: src/dist/windows
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Create Release

on:
push:
tags:
- '*'

jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v2

- name: Package Application
uses: JackMcKew/pyinstaller-action-windows@main
with:
path: src

- uses: ncipollo/release-action@v1
with:
allowUpdates: true
artifactErrorsFailBuild: false
artifacts: "src/dist/windows/app.exe"
artifactContentType: "raw"
bodyFile: "CHANGELOG.md"
draft: false
generateReleaseNotes: true
prerelease: false
replacesArtifacts: true
token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Release
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 croghostrider

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Loxone-Recovery
With this tool, you can recover the previous versions of the Loxone SPS program saved on the mini server.

Big thanks to Markus Fritze and his reverse engineering of the mini server,
the tool is based on this [script](https://github.com/sarnau/Inside-The-Loxone-Miniserver/blob/master/Code/loadMiniserverConfigurationFile.py).

# How-to
Connect with the Loxone Config to the mini server and create a backup.

![image](https://user-images.githubusercontent.com/8603272/159163795-84b48568-51ec-4baa-82a9-58a2422ab9af.png)

Select the source and destination folder.
Normally you can find the backup under "\Documents\Loxone\Loxone Config\Backups".
Click on Start.

![image](https://user-images.githubusercontent.com/8603272/159164023-e15f9809-1bc1-4560-a3d4-bf1220ffdc63.png)
141 changes: 141 additions & 0 deletions src/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import tkinter as tk
from tkinter import ttk
from tkinter import filedialog
import struct
import zipfile
import zlib
import os

def select_sourcefolder():
path= filedialog.askdirectory(title="Select Source Folder", initialdir=os.environ["USERPROFILE"] + "\\Documents\\Loxone\\Loxone Config\\Backups")
source_entry.configure(state="NORMAL")
source_entry.delete(0, "end") #deletes the current value
source_entry.insert(0, path) #inserts new value assigned by 2nd parameter
source_entry.configure(state="readonly")
if len(destination_entry.get()) > 0 and len(source_entry.get()) > 0:
start_button.state(["NORMAL"])

def select_destinationfolder():
path= filedialog.askdirectory(title="Select Destination Folder", initialdir=os.environ["USERPROFILE"] + "\\Documents\\Loxone\\Loxone Config\\Backups")
destination_entry.configure(state="NORMAL")
destination_entry.delete(0, "end") #deletes the current value
destination_entry.insert(0, path) #inserts new value assigned by 2nd parameter
destination_entry.configure(state="readonly")
if len(destination_entry.get()) > 0 and len(source_entry.get()) > 0:
start_button.config(state="normal")

def lox_backup(filename):
#with open(filename, "wb") as f:
# f.write(download_file.read())

zf = zipfile.ZipFile(source_entry.get() + "/" + filename)
with zf.open("sps0.LoxCC") as f:
header, = struct.unpack("<L", f.read(4))
if header == 0xaabbccee: # magic word to detect a compressed file
compressedSize,uncompressedSize,checksum, = struct.unpack("<LLL", f.read(12))
data = f.read(compressedSize)
index = 0
resultStr = bytearray()
while index<len(data):
# the first byte contains the number of bytes to copy in the upper
# nibble. If this nibble is 15, then another byte follows with
# the remainder of bytes to copy. (Comment: it might be possible that
# it follows the same scheme as below, which means: if more than
# 255+15 bytes need to be copied, another 0xff byte follows and so on)
byte, = struct.unpack("<B", data[index:index+1])
index += 1
copyBytes = byte >> 4
byte &= 0xf
if copyBytes == 15:
while True:
addByte = data[index]
copyBytes += addByte
index += 1
if addByte != 0xff:
break
if copyBytes > 0:
resultStr += data[index:index+copyBytes]
index += copyBytes
if index >= len(data):
break
# Reference to data which already was copied into the result.
# bytesBack is the offset from the end of the string
bytesBack, = struct.unpack("<H", data[index:index+2])
index += 2
# the number of bytes to be transferred is at least 4 plus the lower
# nibble of the package header.
bytesBackCopied = 4 + byte
if byte == 15:
# if the header was 15, then more than 19 bytes need to be copied.
while True:
val, = struct.unpack("<B", data[index:index+1])
bytesBackCopied += val
index += 1
if val != 0xff:
break
# Duplicating the last byte in the buffer multiple times is possible,
# so we need to account for that.
while bytesBackCopied > 0:
if -bytesBack+1 == 0:
resultStr += resultStr[-bytesBack:]
else:
resultStr += resultStr[-bytesBack:-bytesBack+1]
bytesBackCopied -= 1
if checksum != zlib.crc32(resultStr):
print("Checksum is wrong")
exit(1)
if len(resultStr) != uncompressedSize:
print("Uncompressed filesize is wrong %d != %d" % (len(resultStr),uncompressedSize))
exit(1)
newfilename = filename[:13] + "-" + filename[13:][:2] + "-" +filename[15:][:2] + "-" +filename[17:][:6]
print(newfilename)
with open(destination_entry.get() + "/" + newfilename + ".Loxone", "wb") as f:
f.write(resultStr)

def list_files():
# files = [f for f in os.listdir(source_entry.get()) if os.path.isfile(f)]
start_button.state(["disabled"])
filelist = []
for filename in os.listdir(source_entry.get()):
if filename.startswith("sps_") and (filename.endswith(".zip")):
filelist.append(filename)
for filename in filelist:
print(filename)
lox_backup(filename)

# root window
root = tk.Tk()
root.title("Select the prog Folder from the Backup")
root.resizable(0, 0)

# configure the grid
root.columnconfigure(0, weight=5)
root.columnconfigure(1, weight=1)

# event

var=tk.StringVar(root)

# source
source_button = ttk.Button(root, text="Source", command=select_sourcefolder)
source_button.grid(column=1, row=0, sticky=tk.E, padx=5, pady=5)

source_entry = ttk.Entry(root, width=50, state="readonly")
source_entry.grid(column=0, row=0, sticky=tk.W, padx=5, pady=5)

# destination
destination_button = ttk.Button(root, text="Destination", command=select_destinationfolder)
destination_button.grid(column=1, row=1, sticky=tk.E, padx=5, pady=5)

destination_entry = ttk.Entry(root, width=50, state="readonly")
destination_entry.grid(column=0, row=1, sticky=tk.W, padx=5, pady=5)

# start button
start_button = ttk.Button(root, text="Start", command=list_files)
start_button.grid(column=1, row=3, sticky=tk.E, padx=5, pady=5)
start_button.state(["disabled"])

root.mainloop()
39 changes: 39 additions & 0 deletions src/app.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- mode: python ; coding: utf-8 -*-


block_cipher = None


a = Analysis(['..\\src\\app.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)

exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='app',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None )

0 comments on commit d4374ff

Please sign in to comment.