mirror of
https://github.com/Py-KMS-Organization/py-kms.git
synced 2025-06-07 02:01:21 -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
|
import os, uuid, datetime
|
||||||
from flask import Flask, render_template
|
from flask import Flask, render_template
|
||||||
from pykms_Sql import sql_get_all
|
from pykms_Sql import sql_get_all
|
||||||
|
from pykms_DB2Dict import kmsDB2Dict
|
||||||
|
|
||||||
serve_count = 0
|
serve_count = 0
|
||||||
|
|
||||||
def _random_uuid():
|
def _random_uuid():
|
||||||
return str(uuid.uuid4()).replace('-', '_')
|
return str(uuid.uuid4()).replace('-', '_')
|
||||||
|
|
||||||
|
def _increase_serve_count():
|
||||||
|
global serve_count
|
||||||
|
serve_count += 1
|
||||||
|
|
||||||
def _get_serve_count():
|
def _get_serve_count():
|
||||||
return 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 = Flask('pykms_webui')
|
||||||
app.jinja_env.globals['start_time'] = datetime.datetime.now()
|
app.jinja_env.globals['start_time'] = datetime.datetime.now()
|
||||||
app.jinja_env.globals['get_serve_count'] = _get_serve_count
|
app.jinja_env.globals['get_serve_count'] = _get_serve_count
|
||||||
|
@ -17,8 +51,7 @@ app.jinja_env.globals['random_uuid'] = _random_uuid
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def root():
|
def root():
|
||||||
global serve_count
|
_increase_serve_count()
|
||||||
serve_count += 1
|
|
||||||
error = None
|
error = None
|
||||||
# Get the db name / path
|
# Get the db name / path
|
||||||
dbPath = None
|
dbPath = None
|
||||||
|
@ -39,19 +72,39 @@ def root():
|
||||||
countClientsOffice = countClients - countClientsWindows
|
countClientsOffice = countClients - countClientsWindows
|
||||||
return render_template(
|
return render_template(
|
||||||
'clients.html',
|
'clients.html',
|
||||||
|
path='/',
|
||||||
error=error,
|
error=error,
|
||||||
clients=clients,
|
clients=clients,
|
||||||
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])
|
||||||
)
|
)
|
||||||
|
|
||||||
@app.route('/license')
|
@app.route('/license')
|
||||||
def license():
|
def license():
|
||||||
global serve_count
|
_increase_serve_count()
|
||||||
serve_count += 1
|
|
||||||
with open('../LICENSE', 'r') as f:
|
with open('../LICENSE', 'r') as f:
|
||||||
return render_template(
|
return render_template(
|
||||||
'license.html',
|
'license.html',
|
||||||
|
path='/license/',
|
||||||
license=f.read()
|
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>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>py-kms {% block title %}{% endblock %}</title>
|
<title>py-kms {% block title %}{% endblock %}</title>
|
||||||
|
<link rel="stylesheet" href="{{ url_for('static', filename= 'css/bulma.min.css') }}">
|
||||||
<style>
|
<style>
|
||||||
#content {
|
#content {
|
||||||
margin: 1em;
|
margin: 1em;
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
}
|
}
|
||||||
|
pre {
|
||||||
|
overflow-x: auto;
|
||||||
|
padding: 0.5em;
|
||||||
|
}
|
||||||
|
{% if path != '/' %}
|
||||||
|
div.backtohome {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
{% endif %}
|
||||||
{% block style %}{% endblock %}
|
{% block style %}{% endblock %}
|
||||||
</style>
|
</style>
|
||||||
<link rel="stylesheet" href="{{ url_for('static', filename= 'css/bulma.min.css') }}">
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="content">
|
<div id="content">
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
|
|
||||||
|
{% if path != '/' %}
|
||||||
|
<div class="block backtohome">
|
||||||
|
<a class="button is-normal is-responsive" href="/">
|
||||||
|
Back to home
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<footer class="footer">
|
<footer class="footer">
|
||||||
|
|
|
@ -3,13 +3,9 @@
|
||||||
{% block title %}clients{% endblock %}
|
{% block title %}clients{% endblock %}
|
||||||
|
|
||||||
{% block style %}
|
{% block style %}
|
||||||
pre.clientMachineId {
|
th {
|
||||||
overflow-x: auto;
|
white-space: nowrap;
|
||||||
padding: 0.5em;
|
}
|
||||||
}
|
|
||||||
th {
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
@ -43,6 +39,12 @@
|
||||||
<p class="title">{{ count_clients_office }}</p>
|
<p class="title">{{ count_clients_office }}</p>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
</nav>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
|
@ -2,10 +2,8 @@
|
||||||
|
|
||||||
{% block title %}license{% endblock %}
|
{% block title %}license{% endblock %}
|
||||||
|
|
||||||
{% block style %}
|
|
||||||
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<pre>{{ license }}</pre>
|
<div class="block">
|
||||||
|
<pre>{{ license }}</pre>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% 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…
Add table
Add a link
Reference in a new issue