From f15ed48f59381f32329c3b22f315c6d66d046757 Mon Sep 17 00:00:00 2001 From: simonmicro Date: Fri, 9 Dec 2022 20:49:27 +0100 Subject: [PATCH] Switched sqlite parameter to point to file instead of dir --- docs/Getting Started.md | 2 +- docs/Usage.md | 1 - py-kms/pykms_Base.py | 4 +--- py-kms/pykms_Server.py | 19 ++++++++++--------- py-kms/pykms_Sql.py | 6 ++---- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/docs/Getting Started.md b/docs/Getting Started.md index 5ff48f7..a562527 100644 --- a/docs/Getting Started.md +++ b/docs/Getting Started.md @@ -64,7 +64,7 @@ docker run -it -d --name py3-kms \ -v /etc/localtime:/etc/localtime:ro \ --restart unless-stopped ghcr.io/py-kms-organization/py-kms:[TAG] ``` -You can omit the `-e SQLITE=...` and `-p 8080:8080` option if you plan to use the `minimal` or `latest` image, which does not include the respective module support. +You can omit the `-p 8080:8080` option if you plan to use the `minimal` or `latest` image, which does not include the `sqlite` module support. ### Systemd If you are running a Linux distro using `systemd`, create the file: `sudo nano /etc/systemd/system/py3-kms.service`, then add the following (change it where needed) and save: diff --git a/docs/Usage.md b/docs/Usage.md index 6902f26..16e5743 100644 --- a/docs/Usage.md +++ b/docs/Usage.md @@ -53,7 +53,6 @@ e.g. because it could not reach the server. The default is 120 minutes (2 hours) -s or --sqlite [] > Use this option to store request information from unique clients in an SQLite database. Deactivated by default. -If enabled the default database file is _pykms_database.db_. You can also provide a specific location. -t0 or --timeout-idle > Maximum inactivity time (in seconds) after which the connection with the client is closed. diff --git a/py-kms/pykms_Base.py b/py-kms/pykms_Base.py index 1f38ba9..e0e9a6b 100644 --- a/py-kms/pykms_Base.py +++ b/py-kms/pykms_Base.py @@ -4,13 +4,12 @@ import binascii import logging import time import uuid -import socket from pykms_Structure import Structure from pykms_DB2Dict import kmsDB2Dict from pykms_PidGenerator import epidGenerator from pykms_Filetimes import filetime_to_dt -from pykms_Sql import sql_initialize, sql_update, sql_update_epid +from pykms_Sql import sql_update, sql_update_epid from pykms_Format import justify, byterize, enco, deco, pretty_printer #-------------------------------------------------------------------------------------------------------------------------------------------------------- @@ -214,7 +213,6 @@ could be detected as not genuine !{end}" %currentClientCount) 'product' : infoDict["skuId"]}) # Create database. if self.srv_config['sqlite']: - sql_initialize(self.srv_config['sqlite']) sql_update(self.srv_config['sqlite'], infoDict) return self.createKmsResponse(kmsRequest, currentClientCount, appName) diff --git a/py-kms/pykms_Server.py b/py-kms/pykms_Server.py index 543fe79..f506455 100755 --- a/py-kms/pykms_Server.py +++ b/py-kms/pykms_Server.py @@ -9,21 +9,20 @@ import uuid import logging import os import threading -import pickle import socketserver import queue as Queue import selectors -from tempfile import gettempdir from time import monotonic as time import pykms_RpcBind, pykms_RpcRequest from pykms_RpcBase import rpcBase from pykms_Dcerpc import MSRPCHeader -from pykms_Misc import check_setup, check_lcid, check_dir, check_other +from pykms_Misc import check_setup, check_lcid, check_other from pykms_Misc import KmsParser, KmsParserException, KmsParserHelp from pykms_Misc import kms_parser_get, kms_parser_check_optionals, kms_parser_check_positionals, kms_parser_check_connect from pykms_Format import enco, deco, pretty_printer, justify from pykms_Connect import MultipleListener +from pykms_Sql import sql_initialize srv_version = "py-kms_2020-10-01" __license__ = "The Unlicense" @@ -190,8 +189,7 @@ for server OSes and Office >=5', 'def' : None, 'des' : "clientcount"}, 'def' : 120, 'des': "activation"}, 'renewal' : {'help' : 'Use this option to specify the renewal interval (in minutes). Default is \"10080\" minutes (7 days).', 'def' : 1440 * 7, 'des' : "renewal"}, - 'sql' : {'help' : 'Use this option to store request information from unique clients in an SQLite database. Deactivated by default. \ -If enabled the default .db file is \"pykms_database.db\". You can also provide a specific location.', 'def' : False, + 'sql' : {'help' : 'Use this option to store request information from unique clients in an SQLite database. Deactivated by default.', 'def' : False, 'file': os.path.join('.', 'pykms_database.db'), 'des' : "sqlite"}, 'hwid' : {'help' : 'Use this option to specify a HWID. The HWID must be an 16-character string of hex characters. \ The default is \"364F463A8863D35F\" or type \"RANDOM\" to auto generate the HWID.', @@ -364,16 +362,19 @@ def server_check(): # Check sqlite. if srv_config['sqlite']: - if isinstance(srv_config['sqlite'], str): - check_dir(srv_config['sqlite'], 'srv', log_obj = loggersrv.error, argument = '-s/--sqlite') - elif srv_config['sqlite'] is True: + if srv_config['sqlite'] is True: # Resolve bool to the default path srv_config['sqlite'] = srv_options['sql']['file'] + if os.path.isdir(srv_config['sqlite']): + pretty_printer(log_obj = loggersrv.warning, + put_text = "{reverse}{yellow}{bold}You specified a folder instead of a database file! This behavior is not officially supported anymore, please change your start parameters soon.{end}") + srv_config['sqlite'] = os.path.join(srv_config['sqlite'], 'pykms_database.db') try: import sqlite3 + sql_initialize(srv_config['sqlite']) except ImportError: pretty_printer(log_obj = loggersrv.warning, - put_text = "{reverse}{yellow}{bold}Module 'sqlite3' not installed, database support disabled.{end}") + put_text = "{reverse}{yellow}{bold}Module 'sqlite3' not installed, database support disabled.{end}") srv_config['sqlite'] = False # Check other specific server options. diff --git a/py-kms/pykms_Sql.py b/py-kms/pykms_Sql.py index 6afa889..270d76a 100644 --- a/py-kms/pykms_Sql.py +++ b/py-kms/pykms_Sql.py @@ -23,12 +23,10 @@ def sql_initialize(dbName): try: con = sqlite3.connect(dbName) cur = con.cursor() - cur.execute("CREATE TABLE clients(clientMachineId TEXT, machineName TEXT, applicationId TEXT, skuId TEXT, \ -licenseStatus TEXT, lastRequestTime INTEGER, kmsEpid TEXT, requestCount INTEGER)") + cur.execute("CREATE TABLE clients(clientMachineId TEXT, machineName TEXT, applicationId TEXT, skuId TEXT, licenseStatus TEXT, lastRequestTime INTEGER, kmsEpid TEXT, requestCount INTEGER)") except sqlite3.Error as e: - pretty_printer(log_obj = loggersrv.error, to_exit = True, - put_text = "{reverse}{red}{bold}Sqlite Error: %s. Exiting...{end}" %str(e)) + pretty_printer(log_obj = loggersrv.error, to_exit = True, put_text = "{reverse}{red}{bold}Sqlite Error: %s. Exiting...{end}" %str(e)) finally: if con: con.commit()