mirror of
https://github.com/Py-KMS-Organization/py-kms.git
synced 2025-07-27 12:06:09 +02:00
Added groups to product page
Signed-off-by: simonmicro <simon@simonmicro.de>
This commit is contained in:
parent
0f58e9bb6f
commit
a639486121
2 changed files with 57 additions and 42 deletions
|
@ -15,33 +15,34 @@ def _get_serve_count():
|
||||||
return _serve_count
|
return _serve_count
|
||||||
|
|
||||||
_kms_items = None
|
_kms_items = None
|
||||||
_kms_items_ignored = None
|
_kms_items_noglvk = None
|
||||||
def _get_kms_items_cache():
|
def _get_kms_items_cache():
|
||||||
global _kms_items, _kms_items_ignored
|
global _kms_items, _kms_items_noglvk
|
||||||
if _kms_items is None:
|
if _kms_items is None:
|
||||||
_kms_items = {}
|
_kms_items = {} # {group: str -> {product: str -> gvlk: str}}
|
||||||
_kms_items_ignored = 0
|
_kms_items_noglvk = 0
|
||||||
queue = [kmsDB2Dict()]
|
for section in kmsDB2Dict():
|
||||||
while len(queue):
|
for element in section:
|
||||||
item = queue.pop(0)
|
if "KmsItems" in element:
|
||||||
if isinstance(item, list):
|
for product in element["KmsItems"]:
|
||||||
for i in item:
|
group_name = product["DisplayName"]
|
||||||
queue.append(i)
|
items = {}
|
||||||
elif isinstance(item, dict):
|
for item in product["SkuItems"]:
|
||||||
if 'KmsItems' in item:
|
items[item["DisplayName"]] = item["Gvlk"]
|
||||||
queue.append(item['KmsItems'])
|
if not item["Gvlk"]:
|
||||||
elif 'SkuItems' in item:
|
_kms_items_noglvk += 1
|
||||||
queue.append(item['SkuItems'])
|
if len(items) == 0:
|
||||||
elif 'Gvlk' in item:
|
continue
|
||||||
if len(item['Gvlk']):
|
if group_name not in _kms_items:
|
||||||
_kms_items[item['DisplayName']] = item['Gvlk']
|
_kms_items[group_name] = {}
|
||||||
else:
|
_kms_items[group_name].update(items)
|
||||||
_kms_items_ignored += 1
|
elif "DisplayName" in element and "BuildNumber" in element and "PlatformId" in element:
|
||||||
#else:
|
pass # these are WinBuilds
|
||||||
# print(item)
|
elif "DisplayName" in element and "Activate" in element:
|
||||||
else:
|
pass # these are CsvlkItems
|
||||||
raise NotImplementedError(f'Unknown type: {type(item)}')
|
else:
|
||||||
return _kms_items, _kms_items_ignored
|
raise NotImplementedError(f'Unknown element: {element}')
|
||||||
|
return _kms_items, _kms_items_noglvk
|
||||||
|
|
||||||
app = Flask('pykms_webui')
|
app = Flask('pykms_webui')
|
||||||
app.jinja_env.globals['start_time'] = datetime.datetime.now()
|
app.jinja_env.globals['start_time'] = datetime.datetime.now()
|
||||||
|
@ -90,7 +91,7 @@ def root():
|
||||||
count_clients=countClients,
|
count_clients=countClients,
|
||||||
count_clients_windows=countClientsWindows,
|
count_clients_windows=countClientsWindows,
|
||||||
count_clients_office=countClientsOffice,
|
count_clients_office=countClientsOffice,
|
||||||
count_projects=len(_get_kms_items_cache()[0])
|
count_projects=sum([len(entries) for entries in _get_kms_items_cache()[0].values()])
|
||||||
), 200 if error is None else 500
|
), 200 if error is None else 500
|
||||||
|
|
||||||
@app.route('/readyz')
|
@app.route('/readyz')
|
||||||
|
@ -125,15 +126,15 @@ def license():
|
||||||
@app.route('/products')
|
@app.route('/products')
|
||||||
def products():
|
def products():
|
||||||
_increase_serve_count()
|
_increase_serve_count()
|
||||||
items, ignored = _get_kms_items_cache()
|
items, noglvk = _get_kms_items_cache()
|
||||||
countProducts = len(items)
|
countProducts = sum([len(entries) for entries in items.values()])
|
||||||
countProductsWindows = len([i for i in items if 'windows' in i.lower()])
|
countProductsWindows = sum([len(entries) for (name, entries) in items.items() if 'windows' in name.lower()])
|
||||||
countProductsOffice = len([i for i in items if 'office' in i.lower()])
|
countProductsOffice = sum([len(entries) for (name, entries) in items.items() if 'office' in name.lower()])
|
||||||
return render_template(
|
return render_template(
|
||||||
'products.html',
|
'products.html',
|
||||||
path='/products/',
|
path='/products/',
|
||||||
products=items,
|
products=items,
|
||||||
filtered=ignored,
|
filtered=noglvk,
|
||||||
count_products=countProducts,
|
count_products=countProducts,
|
||||||
count_products_windows=countProductsWindows,
|
count_products_windows=countProductsWindows,
|
||||||
count_products_office=countProductsOffice
|
count_products_office=countProductsOffice
|
||||||
|
|
|
@ -32,22 +32,36 @@
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
td.glvk {
|
||||||
|
width: 24rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre.glvk {
|
||||||
|
width: min-content;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
{% for group_name, group_products in products | dictsort %}
|
||||||
|
<h1 class="title">{{ group_name }}</h1>
|
||||||
<table class="table is-bordered is-striped is-hoverable is-fullwidth">
|
<table class="table is-bordered is-striped is-hoverable is-fullwidth">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th><abbr title="Group Volume License Key">GVLK</abbr></th>
|
<th class="glvk"><abbr title="Group Volume License Key">GVLK</abbr></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for name, gvlk in products | dictsort %}
|
{% for name, gvlk in group_products | dictsort %}
|
||||||
{% if gvlk %}
|
<tr>
|
||||||
<tr>
|
<td>{{ name }}</td>
|
||||||
<td>{{ name }}</td>
|
<td class="glvk">
|
||||||
<td><pre>{{ gvlk }}</pre></td>
|
{% if gvlk %}
|
||||||
</tr>
|
<pre class="glvk">{{ gvlk }}</pre>{% endif %}
|
||||||
{% endif %}
|
</td>
|
||||||
{% endfor %}
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{% endblock %}
|
{% endfor %}
|
||||||
|
{% endblock %}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue