Merge branch 'master' into readthedocs

This commit is contained in:
Simonmicro 2020-08-07 00:12:43 +02:00 committed by GitHub
commit 1201aba3b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 9 deletions

View File

@ -28,10 +28,10 @@ _py-kms_ is a port of node-kms created by [cyrozap](http://forums.mydigitallife.
- Microsoft Office 2013 ( Volume License ) - Microsoft Office 2013 ( Volume License )
- Microsoft Office 2016 ( Volume License ) - Microsoft Office 2016 ( Volume License )
- Microsoft Office 2019 ( Volume License ) - Microsoft Office 2019 ( Volume License )
- It's written in Python (tested with Python 3.6.7) - It's written in Python (tested with Python 3.6.7)
- Supports execution by `Docker`, `systemd`, `Upstart` and many more... - Supports execution by `Docker`, `systemd`, `Upstart` and many more...
- Includes a GUI for simlpe managing - Includes a GUI for simlpe managing
- Uses `sqlite` for persistent data storage - Uses `sqlite` for persistent data storage
## Documentation ## Documentation
![Read the Docs](https://img.shields.io/readthedocs/py-kms-demo) ![Read the Docs](https://img.shields.io/readthedocs/py-kms-demo)
@ -43,7 +43,6 @@ and running using your favourite tools - all without clumping this readme up. Th
- To start the server manually, execute `python3 pykms_Server.py [IPADDRESS] [PORT]`, the default `IPADDRESS` is `::` ( all ipv6-interfaces ) and the default `PORT` is `1688`. Note that both the address and port are optional. - To start the server manually, execute `python3 pykms_Server.py [IPADDRESS] [PORT]`, the default `IPADDRESS` is `::` ( all ipv6-interfaces ) and the default `PORT` is `1688`. Note that both the address and port are optional.
Also note that it is recommended to use an IPv6 address - even if you are just plan to use IPv4 (the kernel maps the incoming IPv4 requests automatically to IPv6)! Also note that it is recommended to use an IPv6 address - even if you are just plan to use IPv4 (the kernel maps the incoming IPv4 requests automatically to IPv6)!
- To start the server automatically using Docker, execute `docker run -d --name py-kms --restart always -p 1688:1688 pykmsorg/py-kms`. - To start the server automatically using Docker, execute `docker run -d --name py-kms --restart always -p 1688:1688 pykmsorg/py-kms`.
- To run the client (only for testing purposes), use `python3 pykms_Client.py [IPADDRESS] [PORT]`, with the same defaults of `pykms_Server.py`.
- To show the help pages type: `python3 pykms_Server.py -h` and `python3 pykms_Client.py -h`. - To show the help pages type: `python3 pykms_Server.py -h` and `python3 pykms_Client.py -h`.
- For launching py-kms GUI make the file `pykms_Server.py` executable with `chmod +x /path/to/folder/py-kms/pykms_Server.py`, then simply run `pykms_Server.py` by double-clicking. - For launching py-kms GUI make the file `pykms_Server.py` executable with `chmod +x /path/to/folder/py-kms/pykms_Server.py`, then simply run `pykms_Server.py` by double-clicking.

View File

@ -14,6 +14,7 @@ import socketserver
import queue as Queue import queue as Queue
import selectors import selectors
from time import monotonic as time from time import monotonic as time
import ipaddress
import pykms_RpcBind, pykms_RpcRequest import pykms_RpcBind, pykms_RpcRequest
from pykms_RpcBase import rpcBase from pykms_RpcBase import rpcBase
@ -36,9 +37,8 @@ class KeyServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
daemon_threads = True daemon_threads = True
allow_reuse_address = True allow_reuse_address = True
def __init__(self, server_address, RequestHandlerClass): def __init__(self, server_address, RequestHandlerClass, bind_and_activate = True):
self.address_family = socket.AF_INET6 # This call make sure the server creates an IPv6 socket and NOT an IPv4 by default socketserver.BaseServer.__init__(self, server_address, RequestHandlerClass)
socketserver.TCPServer.__init__(self, server_address, RequestHandlerClass)
self.__shutdown_request = False self.__shutdown_request = False
self.r_service, self.w_service = socket.socketpair() self.r_service, self.w_service = socket.socketpair()
@ -47,6 +47,25 @@ class KeyServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
else: else:
self._ServerSelector = selectors.SelectSelector self._ServerSelector = selectors.SelectSelector
try:
ip_ver = ipaddress.ip_address(server_address[0])
except ValueError as e:
pretty_printer(log_obj = loggersrv.error, to_exit = True,
put_text = "{reverse}{red}{bold}%s. Exiting...{end}" %str(e))
if ip_ver.version == 4:
self.address_family = socket.AF_INET
elif ip_ver.version == 6:
self.address_family = socket.AF_INET6
self.socket = socket.socket(self.address_family, self.socket_type)
if bind_and_activate:
try:
self.server_bind()
self.server_activate()
except:
self.server_close()
raise
def pykms_serve(self): def pykms_serve(self):
""" Mixing of socketserver serve_forever() and handle_request() functions, """ Mixing of socketserver serve_forever() and handle_request() functions,
without elements blocking tkinter. without elements blocking tkinter.
@ -157,7 +176,7 @@ loggersrv = logging.getLogger('logsrv')
# 'help' string - 'default' value - 'dest' string. # 'help' string - 'default' value - 'dest' string.
srv_options = { srv_options = {
'ip' : {'help' : 'The IPv6 address to listen on. The default is \"::\" (all interfaces).', 'def' : "::", 'des' : "ip"}, 'ip' : {'help' : 'The IP address (IPv4 or IPv6) to listen on. The default is \"0.0.0.0\" (all interfaces).', 'def' : "0.0.0.0", 'des' : "ip"},
'port' : {'help' : 'The network port to listen on. The default is \"1688\".', 'def' : 1688, 'des' : "port"}, 'port' : {'help' : 'The network port to listen on. The default is \"1688\".', 'def' : 1688, 'des' : "port"},
'epid' : {'help' : 'Use this option to manually specify an ePID to use. If no ePID is specified, a random ePID will be auto generated.', 'epid' : {'help' : 'Use this option to manually specify an ePID to use. If no ePID is specified, a random ePID will be auto generated.',
'def' : None, 'des' : "epid"}, 'def' : None, 'des' : "epid"},