mirror of
https://github.com/Py-KMS-Organization/py-kms.git
synced 2024-09-19 15:28:52 -04:00
Added products sub-page
This commit is contained in:
parent
28e07ac7e1
commit
0cb3ee538f
5 changed files with 143 additions and 19 deletions
|
@ -1,15 +1,49 @@
|
|||
import os, uuid, datetime
|
||||
from flask import Flask, render_template
|
||||
from pykms_Sql import sql_get_all
|
||||
from pykms_DB2Dict import kmsDB2Dict
|
||||
|
||||
serve_count = 0
|
||||
|
||||
def _random_uuid():
|
||||
return str(uuid.uuid4()).replace('-', '_')
|
||||
|
||||
def _increase_serve_count():
|
||||
global serve_count
|
||||
serve_count += 1
|
||||
|
||||
def _get_serve_count():
|
||||
return serve_count
|
||||
|
||||
_kms_items = None
|
||||
_kms_items_ignored = None
|
||||
def _get_kms_items_cache():
|
||||
global _kms_items, _kms_items_ignored
|
||||
if _kms_items is None:
|
||||
_kms_items = {}
|
||||
_kms_items_ignored = 0
|
||||
queue = [kmsDB2Dict()]
|
||||
while len(queue):
|
||||
item = queue.pop(0)
|
||||
if isinstance(item, list):
|
||||
for i in item:
|
||||
queue.append(i)
|
||||
elif isinstance(item, dict):
|
||||
if 'KmsItems' in item:
|
||||
queue.append(item['KmsItems'])
|
||||
elif 'SkuItems' in item:
|
||||
queue.append(item['SkuItems'])
|
||||
elif 'Gvlk' in item:
|
||||
if len(item['Gvlk']):
|
||||
_kms_items[item['DisplayName']] = item['Gvlk']
|
||||
else:
|
||||
_kms_items_ignored += 1
|
||||
#else:
|
||||
# print(item)
|
||||
else:
|
||||
raise NotImplementedError(f'Unknown type: {type(item)}')
|
||||
return _kms_items, _kms_items_ignored
|
||||
|
||||
app = Flask('pykms_webui')
|
||||
app.jinja_env.globals['start_time'] = datetime.datetime.now()
|
||||
app.jinja_env.globals['get_serve_count'] = _get_serve_count
|
||||
|
@ -17,8 +51,7 @@ app.jinja_env.globals['random_uuid'] = _random_uuid
|
|||
|
||||
@app.route('/')
|
||||
def root():
|
||||
global serve_count
|
||||
serve_count += 1
|
||||
_increase_serve_count()
|
||||
error = None
|
||||
# Get the db name / path
|
||||
dbPath = None
|
||||
|
@ -39,19 +72,39 @@ def root():
|
|||
countClientsOffice = countClients - countClientsWindows
|
||||
return render_template(
|
||||
'clients.html',
|
||||
path='/',
|
||||
error=error,
|
||||
clients=clients,
|
||||
count_clients=countClients,
|
||||
count_clients_windows=countClientsWindows,
|
||||
count_clients_office=countClientsOffice
|
||||
count_clients_office=countClientsOffice,
|
||||
count_projects=len(_get_kms_items_cache()[0])
|
||||
)
|
||||
|
||||
@app.route('/license')
|
||||
def license():
|
||||
global serve_count
|
||||
serve_count += 1
|
||||
_increase_serve_count()
|
||||
with open('../LICENSE', 'r') as f:
|
||||
return render_template(
|
||||
'license.html',
|
||||
path='/license/',
|
||||
license=f.read()
|
||||
)
|
||||
|
||||
@app.route('/products')
|
||||
def products():
|
||||
_increase_serve_count()
|
||||
items, ignored = _get_kms_items_cache()
|
||||
countProducts = len(items)
|
||||
countProductsWindows = len([i for i in items if 'windows' in i.lower()])
|
||||
countProductsOffice = len([i for i in items if 'office' in i.lower()])
|
||||
return render_template(
|
||||
'products.html',
|
||||
path='/products/',
|
||||
products=items,
|
||||
filtered=ignored,
|
||||
count_products=countProducts,
|
||||
count_products_windows=countProductsWindows,
|
||||
count_products_office=countProductsOffice
|
||||
)
|
||||
|
|
@ -3,18 +3,36 @@
|
|||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>py-kms {% block title %}{% endblock %}</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename= 'css/bulma.min.css') }}">
|
||||
<style>
|
||||
#content {
|
||||
margin: 1em;
|
||||
overflow-x: auto;
|
||||
}
|
||||
pre {
|
||||
overflow-x: auto;
|
||||
padding: 0.5em;
|
||||
}
|
||||
{% if path != '/' %}
|
||||
div.backtohome {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
{% endif %}
|
||||
{% block style %}{% endblock %}
|
||||
</style>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename= 'css/bulma.min.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
<div id="content">
|
||||
{% block content %}{% endblock %}
|
||||
|
||||
{% if path != '/' %}
|
||||
<div class="block backtohome">
|
||||
<a class="button is-normal is-responsive" href="/">
|
||||
Back to home
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<footer class="footer">
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
{% block title %}clients{% endblock %}
|
||||
|
||||
{% block style %}
|
||||
pre.clientMachineId {
|
||||
overflow-x: auto;
|
||||
padding: 0.5em;
|
||||
}
|
||||
th {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
@ -43,6 +39,12 @@
|
|||
<p class="title">{{ count_clients_office }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="level-item has-text-centered">
|
||||
<div>
|
||||
<p class="heading">Products</p>
|
||||
<p class="title"><a href="/products">{{ count_projects }}</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<hr>
|
||||
|
|
|
@ -2,10 +2,8 @@
|
|||
|
||||
{% block title %}license{% endblock %}
|
||||
|
||||
{% block style %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="block">
|
||||
<pre>{{ license }}</pre>
|
||||
</div>
|
||||
{% endblock %}
|
53
py-kms/templates/products.html
Normal file
53
py-kms/templates/products.html
Normal file
|
@ -0,0 +1,53 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block title %}clients{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<nav class="level">
|
||||
<div class="level-item has-text-centered">
|
||||
<div>
|
||||
<p class="heading">Products</p>
|
||||
<p class="title">{{ count_products + filtered }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="level-item has-text-centered">
|
||||
<div>
|
||||
<p class="heading">Windows</p>
|
||||
<p class="title">{{ count_products_windows }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="level-item has-text-centered">
|
||||
<div>
|
||||
<p class="heading">Office</p>
|
||||
<p class="title">{{ count_products_office }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="level-item has-text-centered">
|
||||
<div>
|
||||
<p class="heading"><abbr title="Empty GLVK or not recognized">Other</abbr></p>
|
||||
<p class="title">{{ filtered }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<hr>
|
||||
|
||||
<table class="table is-bordered is-striped is-hoverable is-fullwidth">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th><abbr title="Group Volume License Key">GVLK</abbr></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for name, gvlk in products | dictsort %}
|
||||
{% if gvlk %}
|
||||
<tr>
|
||||
<td>{{ name }}</td>
|
||||
<td><pre>{{ gvlk }}</pre></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock %}
|
Loading…
Reference in a new issue