mirror of
https://github.com/Py-KMS-Organization/py-kms.git
synced 2025-05-23 11:37:09 -04:00
Merge pull request #66 from edgd1er/dev
client: add -D to discover KMS server #51
This commit is contained in:
commit
7bea3a2cb0
4 changed files with 35 additions and 5 deletions
|
@ -28,7 +28,7 @@ RUN apk add --no-cache --update \
|
||||||
shadow \
|
shadow \
|
||||||
netcat-openbsd \
|
netcat-openbsd \
|
||||||
build-base python3-dev \
|
build-base python3-dev \
|
||||||
&& pip3 install --no-cache peewee tzlocal pytz wheel \
|
&& pip3 install --no-cache-dir peewee tzlocal pytz wheel dnspython \
|
||||||
&& apk del git build-base python3-dev \
|
&& apk del git build-base python3-dev \
|
||||||
&& addgroup power_users \
|
&& addgroup power_users \
|
||||||
&& adduser -S py-kms -G users -s /bin/bash \
|
&& adduser -S py-kms -G users -s /bin/bash \
|
||||||
|
|
|
@ -17,7 +17,7 @@ ENV LOGSIZE ""
|
||||||
ENV TZ America/Chicago
|
ENV TZ America/Chicago
|
||||||
|
|
||||||
COPY py-kms /home/py-kms/
|
COPY py-kms /home/py-kms/
|
||||||
#hadolint ignore=DL3013,DL3018
|
|
||||||
RUN apk add --no-cache --update \
|
RUN apk add --no-cache --update \
|
||||||
bash \
|
bash \
|
||||||
git \
|
git \
|
||||||
|
@ -36,7 +36,7 @@ RUN apk add --no-cache --update \
|
||||||
&& git clone --branch master --depth 1 https://github.com/coleifer/sqlite-web.git /tmp/sqlite_web \
|
&& git clone --branch master --depth 1 https://github.com/coleifer/sqlite-web.git /tmp/sqlite_web \
|
||||||
&& mv /tmp/sqlite_web/sqlite_web /home/ \
|
&& mv /tmp/sqlite_web/sqlite_web /home/ \
|
||||||
&& rm -rf /tmp/sqlite_web \
|
&& rm -rf /tmp/sqlite_web \
|
||||||
&& pip3 install --no-cache-dir peewee tzlocal pytz pysqlite3 wheel \
|
&& pip3 install --no-cache-dir peewee tzlocal pytz pysqlite3 wheel dnspython \
|
||||||
&& apk del git build-base python3-dev \
|
&& apk del git build-base python3-dev \
|
||||||
&& mkdir /db/ \
|
&& mkdir /db/ \
|
||||||
&& addgroup power_users \
|
&& addgroup power_users \
|
||||||
|
@ -52,7 +52,7 @@ COPY docker/start.py /usr/bin/start.py
|
||||||
RUN chmod 755 /usr/bin/entrypoint.py
|
RUN chmod 755 /usr/bin/entrypoint.py
|
||||||
|
|
||||||
WORKDIR /home/py-kms
|
WORKDIR /home/py-kms
|
||||||
#USER py-kms
|
|
||||||
EXPOSE ${PORT}/tcp
|
EXPOSE ${PORT}/tcp
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
|
|
|
@ -143,6 +143,12 @@ user@host ~/path/to/folder/py-kms $ python3 pykms_Server.py -V DEBUG
|
||||||
user@host ~/path/to/folder/py-kms $ python3 pykms_Client.py -V DEBUG
|
user@host ~/path/to/folder/py-kms $ python3 pykms_Client.py -V DEBUG
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you wish to get KMS server from DNS server: (ie perform a DNS resolution on _vlmcs._tcp.domain.tld, if ever there are several answers, only the first one is selected.). Althought that mode is supposed to be specific to devices connect to an Active Directory domain, setting a fully qualified name and a workgroup may help to use that automatic KMS discovery feature.
|
||||||
|
```
|
||||||
|
user@host ~/path/to/folder/py-kms $ python3 pykms_Client.py -V DEBUG -F STDOUT -D contoso.com
|
||||||
|
user@host ~/path/to/folder/py-kms $ python3 pykms_Client.py -V DEBUG -F STDOUT -D contoso.com
|
||||||
|
```
|
||||||
|
|
||||||
Or if you want better specify:
|
Or if you want better specify:
|
||||||
```
|
```
|
||||||
user@host ~/path/to/folder/py-kms $ python3 pykms_Server.py <YOUR_IPADDRESS> 1688 -V DEBUG
|
user@host ~/path/to/folder/py-kms $ python3 pykms_Server.py <YOUR_IPADDRESS> 1688 -V DEBUG
|
||||||
|
|
|
@ -13,7 +13,13 @@ import logging
|
||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
import pykms_RpcBind, pykms_RpcRequest
|
import dns.message
|
||||||
|
import dns.rdataclass
|
||||||
|
import dns.rdatatype
|
||||||
|
import dns.query
|
||||||
|
import dns.resolver
|
||||||
|
|
||||||
|
import pykms_RpcBind, pykms_RpcRequest
|
||||||
from pykms_Filetimes import dt_to_filetime
|
from pykms_Filetimes import dt_to_filetime
|
||||||
from pykms_Dcerpc import MSRPCHeader, MSRPCBindNak, MSRPCRequestHeader, MSRPCRespHeader
|
from pykms_Dcerpc import MSRPCHeader, MSRPCBindNak, MSRPCRequestHeader, MSRPCRespHeader
|
||||||
from pykms_Base import kmsBase, UUID
|
from pykms_Base import kmsBase, UUID
|
||||||
|
@ -72,6 +78,7 @@ Type \"STDOUT\" to view log info on stdout. Type \"FILESTDOUT\" to combine previ
|
||||||
Use \"STDOUTOFF\" to disable stdout messages. Use \"FILEOFF\" if you not want to create logfile.',
|
Use \"STDOUTOFF\" to disable stdout messages. Use \"FILEOFF\" if you not want to create logfile.',
|
||||||
'def' : os.path.join('.', 'pykms_logclient.log'), 'des' : "logfile"},
|
'def' : os.path.join('.', 'pykms_logclient.log'), 'des' : "logfile"},
|
||||||
'lsize' : {'help' : 'Use this flag to set a maximum size (in MB) to the output log file. Deactivated by default.', 'def' : 0, 'des': "logsize"},
|
'lsize' : {'help' : 'Use this flag to set a maximum size (in MB) to the output log file. Deactivated by default.', 'def' : 0, 'des': "logsize"},
|
||||||
|
'discovery' : {'help': 'ask the client to perform a _vlmcs._tcp.domain.tld DNS request to set KMS server.', 'def': None , 'des': 'discovery' },
|
||||||
}
|
}
|
||||||
|
|
||||||
def client_options():
|
def client_options():
|
||||||
|
@ -99,6 +106,8 @@ def client_options():
|
||||||
default = clt_options['lfile']['def'], help = clt_options['lfile']['help'], type = str)
|
default = clt_options['lfile']['def'], help = clt_options['lfile']['help'], type = str)
|
||||||
client_parser.add_argument("-S", "--logsize", dest = clt_options['lsize']['des'], action = "store",
|
client_parser.add_argument("-S", "--logsize", dest = clt_options['lsize']['des'], action = "store",
|
||||||
default = clt_options['lsize']['def'], help = clt_options['lsize']['help'], type = float)
|
default = clt_options['lsize']['def'], help = clt_options['lsize']['help'], type = float)
|
||||||
|
client_parser.add_argument("-D", "--discovery", dest = clt_options['discovery']['des'], action = "store",
|
||||||
|
default = clt_options['discovery']['def'], help = clt_options['discovery']['help'], type = str)
|
||||||
|
|
||||||
client_parser.add_argument("-h", "--help", action = "help", help = "show this help message and exit")
|
client_parser.add_argument("-h", "--help", action = "help", help = "show this help message and exit")
|
||||||
|
|
||||||
|
@ -186,6 +195,21 @@ def client_update():
|
||||||
raise RuntimeError(f'Client failed to find machine configuration in kms database - make sure it contains an entry for "{clt_config["mode"]}"')
|
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():
|
def client_connect():
|
||||||
|
|
||||||
|
if clt_config['discovery'] is not None:
|
||||||
|
loggerclt.info(f'Using Domain: {clt_config["discovery"]}')
|
||||||
|
r= None
|
||||||
|
try:
|
||||||
|
r = dns.resolver.resolve('_vlmcs._tcp.' + clt_config['discovery'], dns.rdatatype.SRV)
|
||||||
|
for a in r:
|
||||||
|
loggerclt.debug(f'answer KMS server: {a.target} , port: {a.port}')
|
||||||
|
clt_config['ip'] = socket.gethostbyname(r[0].target.to_text())
|
||||||
|
clt_config['port'] = r[0].port
|
||||||
|
except (dns.exception.Timeout, dns.resolver.NXDOMAIN) as e:
|
||||||
|
pretty_printer(log_obj = loggerclt.warning,
|
||||||
|
put_text = "{reverse}{red}{bold}Cannot resolve '%s'. Error: '%s'...{end}" %(clt_config['discovery'],
|
||||||
|
str(e)))
|
||||||
|
|
||||||
loggerclt.info("Connecting to %s on port %d" % (clt_config['ip'], clt_config['port']))
|
loggerclt.info("Connecting to %s on port %d" % (clt_config['ip'], clt_config['port']))
|
||||||
try:
|
try:
|
||||||
clt_sock = socket.create_connection((clt_config['ip'], clt_config['port']), timeout = clt_config['timeoutidle'])
|
clt_sock = socket.create_connection((clt_config['ip'], clt_config['port']), timeout = clt_config['timeoutidle'])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue