diff --git a/fanctrl.py b/fanctrl.py index adbee8f..1618cf7 100644 --- a/fanctrl.py +++ b/fanctrl.py @@ -9,6 +9,7 @@ import subprocess import sys import threading +import traceback from time import sleep from abc import ABC, abstractmethod @@ -53,7 +54,7 @@ def __init__(self, name, parameters): class Configuration: path = None - data: None + data = None def __init__(self, path): self.path = path @@ -125,6 +126,32 @@ class WindowsSocketController(SocketController, ABC): LPVOID = ctypes.c_void_p DWORD = wintypes.DWORD + kernel32 = ctypes.WinDLL("kernel32", use_last_error=True) + advapi32 = ctypes.WinDLL("advapi32", use_last_error=True) + + ConvertStringSecurityDescriptorToSecurityDescriptorW = advapi32.ConvertStringSecurityDescriptorToSecurityDescriptorW + ConvertStringSecurityDescriptorToSecurityDescriptorW.argtypes = [wintypes.LPCWSTR, wintypes.DWORD, ctypes.POINTER(wintypes.LPVOID), ctypes.POINTER(wintypes.DWORD)] + ConvertStringSecurityDescriptorToSecurityDescriptorW.restype = wintypes.HANDLE + + sddl_string = "D:P(A;;GA;;;WD)" + + security_descriptor = wintypes.LPVOID() + ConvertStringSecurityDescriptorToSecurityDescriptorW(sddl_string, 1, ctypes.byref(security_descriptor), None) + + class SECURITY_ATTRIBUTES(ctypes.Structure): + from ctypes import wintypes + + _fields_ = [ + ("nLength", wintypes.DWORD), + ("lpSecurityDescriptor", wintypes.LPVOID), + ("nLength", wintypes.BOOL), + ] + + security_attributes = SECURITY_ATTRIBUTES() + security_attributes.nLength = ctypes.sizeof(SECURITY_ATTRIBUTES) + security_attributes.lpSecurityDescriptor = security_descriptor + security_attributes.bInheritHandle = False + server_socket = None def startServerSocket(self, commandCallback=None): @@ -138,7 +165,7 @@ def startServerSocket(self, commandCallback=None): 65536, # nOutBufferSize 65536, # nInBufferSize 0, # nDefaultTimeOut - None # lpSecurityAttributes + self.ctypes.byref(self.security_attributes) # lpSecurityAttributes ) try: while True: @@ -394,6 +421,7 @@ def run(self, debug=True): print(f"Missing strategy, exiting for safety reasons: {e.args[0]}") except Exception as e: print(f"Critical error, exiting for safety reasons: {e}") + traceback.print_exc() exit(1) diff --git a/install.bat b/install.bat index cc1156a..2a9e571 100644 --- a/install.bat +++ b/install.bat @@ -62,10 +62,12 @@ GOTO :EOF set /p "acknowledgement=> " if not defined acknowledgement ( echo goodbye. + pause exit /b 2 ) if not "%acknowledgement%" equ "%acknowledgementPhrase%" ( echo wrong acknowledgement phrase [%acknowledgement%] not equal to [%acknowledgementPhrase%], stopping here! + pause exit /b 2 ) echo: @@ -155,6 +157,7 @@ GOTO :EOF @echo off if %errorLevel% neq 0 ( echo failed to download 'crosec.zip' + pause exit /b 1 ) @@ -164,6 +167,7 @@ GOTO :EOF @echo off if %errorLevel% neq 0 ( echo failed to extract 'crosec.zip' + pause exit /b 2 ) @@ -176,6 +180,7 @@ GOTO :EOF if %errorLevel% neq 0 ( cd /d "%~dp0" echo failed to run the 'crosec' driver installation + pause exit /b 3 ) cd /d "%~dp0" @@ -189,6 +194,7 @@ GOTO :EOF for %%i in (".temp\test-result.txt") do @set count=%%~zi if "%count%" == "0" ( echo 'crosec' driver not installed correctly + pause exit /b 4 ) @@ -199,6 +205,7 @@ GOTO :EOF @echo off if %errorLevel% neq 0 ( echo unable to copy '.temp' to '%ProgramFiles%\ectool' + pause exit /b 5 ) @@ -215,6 +222,7 @@ GOTO :EOF @echo off if %errorLevel% neq 0 ( echo failed to download 'artifact.zip' + pause exit /b 1 ) @@ -224,6 +232,7 @@ GOTO :EOF @echo off if %errorLevel% neq 0 ( echo failed to extract 'artifact.zip' + pause exit /b 2 ) @@ -234,6 +243,7 @@ GOTO :EOF @echo off if %errorLevel% neq 0 ( echo unable to create directory '%ProgramFiles%\ectool' + pause exit /b 3 ) @@ -248,6 +258,7 @@ GOTO :EOF @echo off if %errorLevel% neq 0 ( echo unable to install 'ectool.exe' + pause exit /b 3 ) @@ -264,6 +275,7 @@ GOTO :EOF @echo off if %errorLevel% neq 0 ( echo failed to download 'nssm.zip' + pause exit /b 1 ) @@ -273,6 +285,7 @@ GOTO :EOF @echo off if %errorLevel% neq 0 ( echo failed to extract 'nssm.zip' + pause exit /b 2 ) @@ -287,6 +300,7 @@ GOTO :EOF @echo off if %errorLevel% neq 0 ( echo unable to install 'nssm.exe' + pause exit /b 3 ) @@ -302,6 +316,7 @@ GOTO :EOF @echo off if %errorLevel% neq 0 ( echo unable to create directory '%ProgramFiles%\fw-fanctrl' + pause exit /b 3 ) @@ -316,6 +331,7 @@ GOTO :EOF @echo off if %errorLevel% neq 0 ( echo unable to install 'fanctrl.py' + pause exit /b 3 ) @@ -325,6 +341,7 @@ GOTO :EOF @echo off if %errorLevel% neq 0 ( echo unable to install '.\services\windows\run-service.bat' + pause exit /b 4 ) @@ -334,6 +351,7 @@ GOTO :EOF @echo off if %errorLevel% neq 0 ( echo unable to install '.\services\windows\run-service.bat' + pause exit /b 4 ) @@ -345,6 +363,7 @@ GOTO :EOF @echo off if %errorLevel% neq 0 ( echo unable to install '.\services\windows\fw-fanctrl.bat' + pause exit /b 4 ) @@ -362,6 +381,7 @@ GOTO :EOF "%ProgramFiles%\nssm\nssm" set "fw-fanctrl" Start "SERVICE_DELAYED_AUTO_START" "%ProgramFiles%\nssm\nssm" set "fw-fanctrl" DisplayName "Framework Fanctrl" "%ProgramFiles%\nssm\nssm" set "fw-fanctrl" Description "A simple systemd service to better control Framework Laptop's fan(s)" + "%ProgramFiles%\nssm\nssm" set "fw-fanctrl" AppExit "%ProgramFiles%\ectool\ectool autofanctrl" "%ProgramFiles%\nssm\nssm" set "fw-fanctrl" AppStdout "%ProgramFiles%\fw-fanctrl\out.log" "%ProgramFiles%\nssm\nssm" set "fw-fanctrl" AppStderr "%ProgramFiles%\fw-fanctrl\out.log" @echo off @@ -410,6 +430,8 @@ GOTO :EOF echo removing directory '%ProgramFiles%\nssm' rmdir /s /q "%ProgramFiles%\nssm" 2> nul + GOTO :EOF + :uninstall-ectool echo removing 'ectool' @@ -438,6 +460,7 @@ GOTO :EOF bcdedit /set {default} testsigning off GOTO :EOF + GOTO :EOF