1
0
mirror of https://github.com/fHDHR/fHDHR_NextPVR.git synced 2025-12-06 05:16:58 -05:00

Compare commits

...

4 Commits

Author SHA1 Message Date
Deathbybandaid
c444d3123c
Merge pull request #117 from deathbybandaid/dev
Add missing comma to m3u
2021-01-07 17:28:26 -05:00
deathbybandaid
e003d502c2 Add missing comma to m3u 2021-01-07 17:25:47 -05:00
Deathbybandaid
a1e9e28e64
Merge pull request #116 from deathbybandaid/dev
Implement access_levels and route_list
2021-01-07 15:00:32 -05:00
deathbybandaid
4093a8c135 Implement access_levels and route_list 2021-01-07 14:56:02 -05:00
20 changed files with 172 additions and 170 deletions

View File

@ -34,6 +34,8 @@ class fHDHR_HTTP_Server():
# Set Secret Key For Sessions
self.fhdhr.app.secret_key = self.fhdhr.config.dict["fhdhr"]["friendlyname"]
self.route_list = {}
self.fhdhr.logger.info("Loading HTTP Pages Endpoints.")
self.pages = fHDHR_Pages(fhdhr)
self.add_endpoints(self.pages, "pages")
@ -83,6 +85,7 @@ class fHDHR_HTTP_Server():
session["session_id"] = str(uuid.uuid4())
session["instance_id"] = self.instance_id
session["route_list"] = self.route_list
session["is_internal_api"] = self.detect_internal_api(request)
if session["is_internal_api"]:
@ -151,6 +154,10 @@ class fHDHR_HTTP_Server():
return False
def add_endpoints(self, index_list, index_name):
if index_name not in list(self.route_list.keys()):
self.route_list[index_name] = {}
item_list = [x for x in dir(index_list) if self.isapath(x)]
for item in item_list:
endpoints = eval("self." + str(index_name) + "." + str(item) + ".endpoints")
@ -158,11 +165,38 @@ class fHDHR_HTTP_Server():
endpoints = [endpoints]
handler = eval("self." + str(index_name) + "." + str(item))
endpoint_name = eval("self." + str(index_name) + "." + str(item) + ".endpoint_name")
try:
endpoint_methods = eval("self." + str(index_name) + "." + str(item) + ".endpoint_methods")
except AttributeError:
endpoint_methods = ['GET']
try:
endpoint_access_level = eval("self." + str(index_name) + "." + str(item) + ".endpoint_access_level")
except AttributeError:
endpoint_access_level = 0
try:
pretty_name = eval("self." + str(index_name) + "." + str(item) + ".pretty_name")
except AttributeError:
pretty_name = endpoint_name
try:
endpoint_default_parameters = eval("self." + str(index_name) + "." + str(item) + ".endpoint_default_parameters")
except AttributeError:
endpoint_default_parameters = {}
self.fhdhr.logger.debug("Adding endpoint %s available at %s with %s methods." % (endpoint_name, ",".join(endpoints), ",".join(endpoint_methods)))
if endpoint_name not in list(self.route_list[index_name].keys()):
self.route_list[index_name][endpoint_name] = {}
self.route_list[index_name][endpoint_name]["name"] = endpoint_name
self.route_list[index_name][endpoint_name]["endpoints"] = endpoints
self.route_list[index_name][endpoint_name]["endpoint_methods"] = endpoint_methods
self.route_list[index_name][endpoint_name]["endpoint_access_level"] = endpoint_access_level
self.route_list[index_name][endpoint_name]["endpoint_default_parameters"] = endpoint_default_parameters
self.route_list[index_name][endpoint_name]["pretty_name"] = pretty_name
for endpoint in endpoints:
self.add_endpoint(endpoint=endpoint,
endpoint_name=endpoint_name,

View File

@ -12,6 +12,8 @@ from .tuners import Tuners
from .debug import Debug_JSON
from .tools import API_Tools
from .route_list import Route_List
from .images import Images
@ -33,4 +35,6 @@ class fHDHR_API():
self.debug = Debug_JSON(fhdhr)
self.tools = API_Tools(fhdhr)
self.route_list = Route_List(fhdhr)
self.images = Images(fhdhr)

View File

@ -89,7 +89,7 @@ class M3U():
for chan_key in list(channel_item_dict.keys()):
if not chan_key.startswith(tuple(["group-title", "stream_url"])):
m3ustring += "%s=\"%s\" " % (chan_key, channel_item_dict[chan_key])
m3ustring += "group-title=\"%s\"%s\n" % (channel_item_dict["group-title"], channel_item_dict["group-titleb"])
m3ustring += "group-title=\"%s\",%s\n" % (channel_item_dict["group-title"], channel_item_dict["group-titleb"])
m3ustring += "%s\n" % channel_item_dict["stream_url"]
fakefile.write(m3ustring)

View File

@ -0,0 +1,37 @@
from flask import Response, request, redirect, session
import urllib.parse
import json
class Route_List():
endpoints = ["/api/routes"]
endpoint_name = "api_routes"
endpoint_methods = ["GET", "POST"]
def __init__(self, fhdhr):
self.fhdhr = fhdhr
def __call__(self, *args):
return self.get(*args)
def get(self, *args):
method = request.args.get('method', default="get", type=str)
redirect_url = request.args.get('redirect', default=None, type=str)
if method == "get":
return_json = json.dumps(session["route_list"], indent=4)
return Response(status=200,
response=return_json,
mimetype='application/json')
else:
return "%s Invalid Method" % method
if redirect_url:
return redirect(redirect_url + "?retmessage=" + urllib.parse.quote("%s Success" % method))
else:
return "%s Success" % method

View File

@ -6,6 +6,8 @@ from fHDHR.tools import channel_sort
class Channels_Editor_HTML():
endpoints = ["/channels_editor", "/channels_editor.html"]
endpoint_name = "page_channels_editor_html"
endpoint_access_level = 2
pretty_name = "Channels Editor"
def __init__(self, fhdhr):
self.fhdhr = fhdhr

View File

@ -6,6 +6,8 @@ from fHDHR.tools import channel_sort
class Channels_HTML():
endpoints = ["/channels", "/channels.html"]
endpoint_name = "page_channels_html"
endpoint_access_level = 0
pretty_name = "Channels"
def __init__(self, fhdhr):
self.fhdhr = fhdhr

View File

@ -5,6 +5,8 @@ import urllib.parse
class Cluster_HTML():
endpoints = ["/cluster", "/cluster.html"]
endpoint_name = "page_cluster_html"
endpoint_access_level = 1
pretty_name = "Cluster/SSDP"
def __init__(self, fhdhr):
self.fhdhr = fhdhr

View File

@ -4,6 +4,8 @@ from flask import request, render_template, session
class Diagnostics_HTML():
endpoints = ["/diagnostics", "/diagnostics.html"]
endpoint_name = "page_diagnostics_html"
endpoint_access_level = 2
pretty_name = "Diagnostics"
def __init__(self, fhdhr):
self.fhdhr = fhdhr
@ -15,111 +17,27 @@ class Diagnostics_HTML():
base_url = request.url_root[:-1]
button_list = []
button_dict = {}
button_list.append({
"label": "Debug Json",
"hdhr": None,
"rmg": None,
"other": "/api/debug",
for route_group in list(session["route_list"].keys()):
if route_group not in ["pages", "brython", "files"]:
button_dict[route_group] = []
for route_item in list(session["route_list"][route_group].keys()):
if not session["route_list"][route_group][route_item]["name"].startswith("page_"):
button_link = session["route_list"][route_group][route_item]["endpoints"][0]
parameter_index = 0
for parameter in list(session["route_list"][route_group][route_item]["endpoint_default_parameters"].keys()):
parameter_val = session["route_list"][route_group][route_item]["endpoint_default_parameters"][parameter]
if not parameter_index:
button_link += "?"
else:
button_link += "&"
button_link += "%s=%s" % (parameter, parameter_val)
button_link = button_link.replace("<devicekey>", self.fhdhr.config.dict["main"]["uuid"])
button_link = button_link.replace("<base_url>", base_url)
button_dict[route_group].append({
"label": session["route_list"][route_group][route_item]["pretty_name"],
"link": button_link,
})
button_list.append({
"label": "Cluster Json",
"hdhr": None,
"rmg": None,
"other": "/api/cluster?method=get",
})
button_list.append({
"label": "Lineup XML",
"hdhr": "/lineup.xml",
"rmg": None,
"other": None,
})
button_list.append({
"label": "Lineup JSON",
"hdhr": "/hdhr/lineup.json",
"rmg": None,
"other": None,
})
button_list.append({
"label": "Lineup Status",
"hdhr": "/hdhr/lineup_status.json",
"rmg": None,
"other": None,
})
button_list.append({
"label": "Discover Json",
"hdhr": "/hdhr/discover.json",
"rmg": None,
"other": None,
})
button_list.append({
"label": "Device XML",
"hdhr": "/hdhr/device.xml",
"rmg": "/rmg/device.xml",
"other": None,
})
button_list.append({
"label": "RMG Identification XML",
"hdhr": "",
"rmg": "/rmg",
"other": None,
})
button_list.append({
"label": "RMG Devices Discover",
"hdhr": "",
"rmg": "/rmg/devices/discover",
"other": None,
})
button_list.append({
"label": "RMG Devices Probe",
"hdhr": "",
"rmg": "/rmg/devices/probe?uri=%s" % base_url,
"other": None,
})
button_list.append({
"label": "RMG Devices by DeviceKey",
"hdhr": "",
"rmg": "/rmg/devices/%s" % self.fhdhr.config.dict["main"]["uuid"],
"other": None,
})
button_list.append({
"label": "RMG Channels by DeviceKey",
"hdhr": "",
"rmg": "/rmg/devices/%s/channels" % self.fhdhr.config.dict["main"]["uuid"],
"other": None,
})
button_list.append({
"label": "RMG Scanners by DeviceKey",
"hdhr": "",
"rmg": "/rmg/devices/%s/scanners" % self.fhdhr.config.dict["main"]["uuid"],
"other": None,
})
button_list.append({
"label": "RMG Networks by DeviceKey",
"hdhr": "",
"rmg": "/rmg/devices/%s/networks" % self.fhdhr.config.dict["main"]["uuid"],
"other": None,
})
button_list.append({
"label": "RMG Scan by DeviceKey",
"hdhr": "",
"rmg": "/rmg/devices/%s/scan" % self.fhdhr.config.dict["main"]["uuid"],
"other": None,
})
return render_template('diagnostics.html', session=session, request=request, fhdhr=self.fhdhr, button_list=button_list)
return render_template('diagnostics.html', session=session, request=request, fhdhr=self.fhdhr, button_dict=button_dict, list=list)

View File

@ -7,6 +7,8 @@ from fHDHR.tools import humanized_time, channel_sort
class Guide_HTML():
endpoints = ["/guide", "/guide.html"]
endpoint_name = "page_guide_html"
endpoint_access_level = 0
pretty_name = "Guide"
def __init__(self, fhdhr):
self.fhdhr = fhdhr

View File

@ -4,6 +4,8 @@ from flask import request, render_template, session
class Index_HTML():
endpoints = ["/index", "/index.html"]
endpoint_name = "page_index_html"
endpoint_access_level = 0
pretty_name = "Index"
def __init__(self, fhdhr):
self.fhdhr = fhdhr

View File

@ -4,6 +4,8 @@ from flask import request, render_template, session
class Settings_HTML():
endpoints = ["/settings", "/settings.html"]
endpoint_name = "page_settings_html"
endpoint_access_level = 1
pretty_name = "Settings"
def __init__(self, fhdhr):
self.fhdhr = fhdhr

View File

@ -4,6 +4,8 @@ from flask import request, render_template, session
class Tools_HTML():
endpoints = ["/tools", "/tools.html"]
endpoint_name = "tools_html"
endpoint_access_level = 2
pretty_name = "Tools"
def __init__(self, fhdhr):
self.fhdhr = fhdhr

View File

@ -6,6 +6,8 @@ from fHDHR.tools import humanized_filesize
class Tuners_HTML():
endpoints = ["/tuners", "/tuners.html"]
endpoint_name = "page_streams_html"
endpoint_access_level = 0
pretty_name = "Tuners"
def __init__(self, fhdhr):
self.fhdhr = fhdhr

View File

@ -4,6 +4,8 @@ from flask import request, render_template, session
class Version_HTML():
endpoints = ["/version", "/version.html"]
endpoint_name = "page_version_html"
endpoint_access_level = 1
pretty_name = "Version"
def __init__(self, fhdhr):
self.fhdhr = fhdhr

View File

@ -4,6 +4,8 @@ from flask import request, render_template, session
class xmlTV_HTML():
endpoints = ["/xmltv", "/xmltv.html"]
endpoint_name = "page_xmltv_html"
endpoint_access_level = 1
pretty_name = "xmltv"
def __init__(self, fhdhr):
self.fhdhr = fhdhr

View File

@ -9,6 +9,9 @@ class RMG_Devices_Probe():
endpoints = ["/devices/probe", "/rmg/devices/probe"]
endpoint_name = "rmg_devices_probe"
endpoint_methods = ["GET", "POST"]
endpoint_default_parameters = {
"uri": "<base_url>"
}
def __init__(self, fhdhr):
self.fhdhr = fhdhr

View File

@ -17,45 +17,36 @@
<p></p>
<div>
<button class="pull-left" onclick="OpenLink('/index')">fHDHR</a></button>
<button class="pull-left" onclick="OpenLink('/index')">fHDHR</button>
<button class="pull-left" onclick="OpenLink('/origin')">{{ fhdhr.config.dict["main"]["servicename"] }}</button>
<button class="pull-left" onclick="OpenLink('/origin')">{{ fhdhr.config.dict["main"]["servicename"] }}</a></button>
<button class="pull-left" onclick="OpenLink('/channels')">Channels</a></button>
<button class="pull-left" onclick="OpenLink('/guide')">Guide</a></button>
<button class="pull-left" onclick="OpenLink('/cluster')">Cluster/SSDP</a></button>
<button class="pull-left" onclick="OpenLink('/tuners')">Tuners</a></button>
<button class="pull-left" onclick="OpenLink('/xmltv')">xmltv</a></button>
{% if fhdhr.config.dict["web_ui"]["advanced"] %}
<button class="pull-left" onclick="OpenLink('/version')">Version</a></button>
{% for page_dict in session["route_list"]["pages"] %}
{% if session["route_list"]["pages"][page_dict]["name"] != "page_index_html" and fhdhr.config.dict["web_ui"]["access_level"] >= session["route_list"]["pages"][page_dict]["endpoint_access_level"] %}
<button class="pull-left" onclick="OpenLink('{{ session["route_list"]["pages"][page_dict]["endpoints"][0] }}')">{{ session["route_list"]["pages"][page_dict]["pretty_name"] }}</button>
{% endif %}
{% if fhdhr.config.dict["web_ui"]["advanced"] %}
<button class="pull-left" onclick="OpenLink('/diagnostics')">Diagnostics</a></button>
{% endif %}
<button class="pull-left" onclick="OpenLink('/settings')">Settings</a></button>
{% endfor %}
<a class="pull-right" style="padding: 5px;" href="/api/xmltv?method=get&source={{ fhdhr.device.epg.def_method }}">xmltv</a>
<a class="pull-right" style="padding: 5px;" href="/api/m3u?method=get&channel=all">m3u</a>
<form class="pull-right" style="padding: 5px;" method="post" action="/api/settings?method=update&redirect={{ request.path }}">
<input type="hidden" name="config_section" value="web_ui">
<input type="hidden" name="config_name" value="advanced">
{% if fhdhr.config.dict["web_ui"]["advanced"] %}
<input type="hidden" name="config_value" value=False>
<input type="hidden" name="config_name" value="access_level">
{% if fhdhr.config.dict["web_ui"]["access_level"] == 2 %}
<input type="hidden" name="config_value" value=0>
{% elif fhdhr.config.dict["web_ui"]["access_level"] == 1 %}
<input type="hidden" name="config_value" value=2>
{% else %}
<input type="hidden" name="config_value" value=True>
<input type="hidden" name="config_value" value=1>
{% endif %}
<input type="hidden" name="config_default" value=False>
{% if fhdhr.config.dict["web_ui"]["advanced"] %}
<a data-th="Reset"><input type="submit" value="Basic"></a>
<input type="hidden" name="config_default" value=0>
{% if fhdhr.config.dict["web_ui"]["access_level"] == 2 %}
<a><input type="submit" value="Extra Advanced"></a>
{% elif fhdhr.config.dict["web_ui"]["access_level"] == 1 %}
<a><input type="submit" value="Advanced"></a>
{% else %}
<a data-th="Reset"><input type="submit" value="Advanced"></a>
<a><input type="submit" value="Basic"></a>
{% endif %}
</form>

View File

@ -4,37 +4,30 @@
<h4 style="text-align: center;">fHDHR Diagnostic Links</h4>
{% for route_group in list(button_dict.keys()) %}
<h4 style="text-align: center;">{{ route_group }}</h4>
<div class="container">
<table class="table-medium center">
<tbody>
<table class="table-settings center action-col text-edit-cols">
<thead>
<tr>
<th>Item</th>
<th>HDHR</th>
<th>RMG</th>
<th>Non-Specific</th>
<th>Link</th>
</tr>
</thead>
<tbody>
{% for button_item in button_dict[route_group] %}
<tr>
<td><button onclick="OpenLink('{{ button_item["link"] }}')">{{ button_item["label"] }}</a></button></td>
</tr>
{% for button_item in button_list %}
<tr>
<td>{{ button_item["label"] }}</td>
{% if button_item["hdhr"] %}
<td><button onclick="OpenLink('{{ button_item["hdhr"] }}')">{{ button_item["label"] }}</a></button></td>
{% else %}
<td></td>
{% endif %}
{% if button_item["rmg"] %}
<td><button onclick="OpenLink('{{ button_item["rmg"] }}')">{{ button_item["label"] }}</a></button></td>
{% else %}
<td> </td>
{% endif %}
{% if button_item["other"] %}
<td><button onclick="OpenLink('{{ button_item["other"] }}')">{{ button_item["label"] }}</a></button></td>
{% else %}
<td></td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endfor %}
{% endblock %}

View File

@ -66,6 +66,8 @@
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endfor %}

View File

@ -5,8 +5,8 @@
"config_file": true,
"config_web": true
},
"advanced":{
"value": false,
"access_level":{
"value": 0,
"config_file": true,
"config_web": true
}