Merge pull request #52 from Py-KMS-Organization/fixes/bugs

Fixes/bugs
This commit is contained in:
simonmicro 2021-12-23 20:02:38 +01:00 committed by GitHub
commit 59d9c2a7e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 10 deletions

View file

@ -10,7 +10,7 @@ import subprocess
import sys
PYTHON3 = '/usr/bin/python3'
dbPath = os.path.join(os.sep, 'home', 'py-kms', 'db', 'pykms_database.db')
dbPath = os.path.join(os.sep, 'home', 'py-kms', 'db') # Do not include the database file name, as we must correct the folder permissions (the db file is recursively reachable)
log_level_bootstrap = log_level = os.getenv('LOGLEVEL', 'INFO')
if log_level_bootstrap == "MININFO":
log_level_bootstrap = "INFO"
@ -33,10 +33,24 @@ def change_uid_grp():
new_uid = int(os.getenv('UID', str(uid)))
os.chown("/home/py-kms", new_uid, new_gid)
os.chown("/usr/bin/start.py", new_uid, new_gid)
if os.path.isfile(dbPath):
if os.path.isdir(dbPath):
# Corret permissions recursively, as to access the database file, also its parent folder must be accessible
loggersrv.debug(f'Correcting owner permissions on {dbPath}.')
os.chown(dbPath, new_uid, new_gid)
loggersrv.debug("%s" %str(subprocess.check_output("ls -al " + dbPath, shell=True)))
for root, dirs, files in os.walk(dbPath):
for dName in dirs:
dPath = os.path.join(root, dName)
loggersrv.debug(f'Correcting owner permissions on {dPath}.')
os.chown(dPath, new_uid, new_gid)
for fName in files:
fPath = os.path.join(root, fName)
loggersrv.debug(f'Correcting owner permissions on {fPath}.')
os.chown(fPath, new_uid, new_gid)
loggersrv.debug(subprocess.check_output(['ls', '-la', dbPath]).decode())
if 'LOGFILE' in os.environ and os.path.exists(os.environ['LOGFILE']):
# Oh, the user also wants a custom log file -> make sure start.py can access it by setting the correct permissions (777)
os.chmod(os.environ['LOGFILE'], 777)
loggersrv.error(str(subprocess.check_output(['ls', '-la', os.environ['LOGFILE']])))
loggersrv.info("Setting gid to '%s'." % str(new_gid))
os.setgid(new_gid)

View file

@ -52,7 +52,6 @@ services:
- SQLITE=true
- HWID=RANDOM
- LOGLEVEL=INFO
- LOGFILE=/dev/stdout
restart: always
volumes:
- ./db:/home/py-kms/db

View file

@ -156,18 +156,25 @@ def client_check():
def client_update():
kmsdb = kmsDB2Dict()
loggerclt.debug(f'Searching in kms database for machine "{clt_config["mode"]}"...')
appitems = kmsdb[2]
for appitem in appitems:
kmsitems = appitem['KmsItems']
for kmsitem in kmsitems:
name = re.sub('\(.*\)', '', kmsitem['DisplayName']).replace('2015', '').replace(' ', '')
name = re.sub('\(.*\)', '', kmsitem['DisplayName']) # Remove bracets
name = name.replace('2015', '') # Remove specific years
name = name.replace(' ', '') # Ignore whitespaces
name = name.replace('/11', '', 1) # Cut out Windows 11, as it is basically Windows 10
if name == clt_config['mode']:
skuitems = kmsitem['SkuItems']
# Select 'Enterprise' for Windows or 'Professional Plus' for Office.
for skuitem in skuitems:
if skuitem['DisplayName'].replace(' ','') == name + 'Enterprise' or \
skuitem['DisplayName'].replace(' ','') == name[:6] + 'ProfessionalPlus' + name[6:]:
sName = skuitem['DisplayName']
sName = sName.replace(' ', '') # Ignore whitespaces
sName = sName.replace('/11', '', 1) # Cut out Windows 11, as it is basically Windows 10
if sName == name + 'Enterprise' or \
sName == name[:6] + 'ProfessionalPlus' + name[6:]:
clt_config['KMSClientSkuID'] = skuitem['Id']
clt_config['RequiredClientCount'] = int(kmsitem['NCountPolicy'])
clt_config['KMSProtocolMajorVersion'] = int(float(kmsitem['DefaultKmsProtocol']))
@ -175,7 +182,8 @@ def client_update():
clt_config['KMSClientLicenseStatus'] = 2
clt_config['KMSClientAppID'] = appitem['Id']
clt_config['KMSClientKMSCountedID'] = kmsitem['Id']
break
return
raise RuntimeError(f'Client failed to find machine configuration in kms database - make sure it contains an entry for "{clt_config["mode"]}"')
def client_connect():
loggerclt.info("Connecting to %s on port %d" % (clt_config['ip'], clt_config['port']))

View file

@ -18,6 +18,7 @@ loggersrv = logging.getLogger('logsrv')
def sql_initialize(dbName):
if not os.path.isfile(dbName):
# Initialize the database.
loggersrv.debug(f'Initializing database file "{dbName}"...')
con = None
try:
con = sqlite3.connect(dbName)