Skip to content

Commit

Permalink
[feat] Read System Info and Connection Diagnostics modals (#80)
Browse files Browse the repository at this point in the history
* Create pylint.yml

* [feat] parse and return system info

* [feat] extract connection diagnostics

* Fix missing imports
  • Loading branch information
havardgulldahl authored Aug 11, 2024
1 parent 0ea8aa6 commit 00ba6c8
Show file tree
Hide file tree
Showing 6 changed files with 396 additions and 2 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Pylint

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
43 changes: 42 additions & 1 deletion technicolorgateway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
from robobrowser import RoboBrowser

from technicolorgateway import mysrp as srp
from technicolorgateway.modal import get_device_modal, get_broadband_modal
from technicolorgateway.modal import (
get_device_modal,
get_broadband_modal,
get_system_info_modal,
get_diagnostics_connection_modal,
)

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -98,3 +103,39 @@ def get_broadband_modal(self):
self._br._update_state(req)
content = req.content.decode()
return get_broadband_modal(content)

def get_system_info_modal(self):
"""Open System info modal and return the properties as a dict. Depending
on your hardware model, this may include the following keys:
"Product Vendor",
"Product Name",
"Serial Number",
"Software Version",
"Uptime since last reboot",
"Firmware Version",
"Hardware Version",
"MAC Address",
"Memory Usage",
"CPU Usage",
"Reboot Cause",
"""
req = self._br.session.get(f"{self._uri}/modals/system-info-modal.lp")
self._br._update_state(req)
content = req.content.decode()
return get_system_info_modal(content)

def get_diagnostics_connection_modal(self):
"""Open Diagnostics Connection modal and return connection check as a
dict. Depending on your hardware model, this may include the following
keys:
'WAN Enable', 'WAN Available', 'IP Version 4 Address', 'IP Version 6
Address', 'Next Hop Ping', 'First DNS Server Ping', 'Second DNS
Server Ping'
"""

req = self._br.session.get(
f"{self._uri}/modals/diagnostics-connection-modal.lp"
)
self._br._update_state(req)
content = req.content.decode()
return get_diagnostics_connection_modal(content)
27 changes: 27 additions & 0 deletions technicolorgateway/modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,30 @@ def get_data_from_rows(data, rows):
cols = row.find_all('td')
cols = [ele.text.strip() for ele in cols]
data.append({'name': cols[name_index], 'ip': cols[ip_index], 'mac': cols[mac_index]})

def get_system_info_modal(content):
soup = BeautifulSoup(content, "html.parser")
# Extract product information
product_info = {}
for div in soup.select("div.control-group"):
label = div.select_one("label.control-label")
span = div.select_one("span.simple-desc")
if label and span:
key = label.text.strip()
value = span.text.strip()
product_info[key] = value
return product_info


def get_diagnostics_connection_modal(content):
soup = BeautifulSoup(content, "html.parser")
# Extract connection diagnostics
product_info = {}
for div in soup.select("div.control-group"):
label = div.select_one("label.control-label")
span = div.select_one("span.simple-desc")
if label and span:
key = label.text.strip()
value = span.text.strip()
product_info[key] = value
return product_info
122 changes: 122 additions & 0 deletions tests/resources/diagnostics-connection-modal.lp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@

<div class="modal-header" data-autorefresh='2'>
<div class="row-fluid">
<div class="span11">
<h2 class="span4"> Diagnostics Connection</h2>
</div>
<div class="span1">
<a href="#" class="button btn-primary btn-close" data-dismiss="modal">
<i class="icon-remove"></i>
</a>
</div>
</div>
</div>

<div class="modal-body update">
<ul class="nav nav-tabs">

<li class="active">
<a id="Connection" href="#" data-remote="/modals/diagnostics-connection-modal.lp">Connection</a>
</li>
<li class="">
<a id="Ping & Traceroute" href="#" data-remote="/modals/diagnostics-ping-modal.lp">Ping & Traceroute</a>
</li>
<li class="">
<a id="Network" href="#" data-remote="/modals/diagnostics-network-modal.lp">Network</a>
</li>
<li class="">
<a id="Igmpproxy" href="#" data-remote="/modals/diagnostics-igmpproxy-modal.lp">Igmpproxy</a>
</li>
</ul>

<form class="form-horizontal" method="post" action="modals/diagnostics-connection-modal.lp">
<fieldset id="diagnostics-connection-tab">
<legend>Connection Check</legend>

<div class="control-group">
<label class="control-label">Restart all Tests</label>
<div class="controls restart_all_tests">
<div id="Restart" class="btn" data-name="operation" data-value="RESTART">
<i class="icon-reply"></i>
Restart
</div>
</div>
</div>
<div class="control-group">
<label class="control-label">WAN Enable</label>
<div class="controls">
<span id="WAN Enable" class=" simple-desc span5">
<i class="icon-ok icon-large green"></i>
Interface Enabled
</span>
</div>
</div>
<div class="control-group">
<label class="control-label">WAN Available</label>
<div class="controls">
<span id="WAN Available" class=" simple-desc span5">
<i class="icon-ok icon-large green"></i>
Link Up
</span>
</div>
</div>
<div class="control-group">
<label class="control-label">IP Version 4 Address</label>
<div class="controls">
<span id="IP Version 4 Address" class=" simple-desc span5">
<i class="icon-ok icon-large green"></i>
82.133.131.13
</span>
</div>
</div>
<div class="control-group">
<label class="control-label">IP Version 6 Address</label>
<div class="controls">
<span id="IP Version 6 Address" class=" simple-desc span5">
<i class="icon-ban-circle icon-large red"></i>
No Address Assigned
</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Next Hop Ping</label>
<div class="controls">
<span id="Next Hop Ping" class=" simple-desc span5">
<i class="icon-ok icon-large green"></i>
Success
</span>
</div>
</div>
<div class="control-group">
<label class="control-label">First DNS Server Ping</label>
<div class="controls">
<span id="First DNS Server Ping" class=" simple-desc span5">
<i class="icon-ok icon-large green"></i>
Success
</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Second DNS Server Ping</label>
<div class="controls">
<span id="Second DNS Server Ping" class=" simple-desc span5">
<i class="icon-ok icon-large green"></i>
Success
</span>
</div>
</div>

</fieldset>
</form>
</div>

<div class="modal-footer">
<div id="modal-no-change">
<div id="close-config" class="btn btn-primary btn-large" data-dismiss="modal">Close</div>
</div>
<div id="modal-changes" class="hide">
<div id="cancel-config" class="btn btn-large" data-dismiss="modal">Cancel</div>
<div id="save-config" class="btn btn-primary btn-large">Save</div>
</div>
</div>

136 changes: 136 additions & 0 deletions tests/resources/system-info-modal.lp
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<div class="modal-header">
<div class="row-fluid">
<div class="span11">
<h2 class="span4"> System Information</h2>
<span class="modal-action">
<span class="modal-action-refresh" id="Refresh_id">
<i class="icon-refresh"></i>
refresh data
</span>
</span>
<span class="modal-action">
<span class="modal-action-advanced hide" id="Hide_Advanced_id">
<i class="icon-minus-sign"></i>
hide advanced
</span>
<span class="modal-action-advanced" id="Show_Advanced_id">
<i class="icon-plus-sign"></i>
show advanced
</span>
</span>
</div>
<div class="span1">
<a href="#" class="button btn-primary btn-close" data-dismiss="modal">
<i class="icon-remove"></i>
</a>
</div>
</div>
</div>

<div class="modal-body update">

<ul class="nav nav-tabs">
<li class="active">
<a id="systemInfoGlobal" href="#" data-remote="/modals/system-info-modal.lp">Global Information</a>
</li>
<li class="">
<a id="Time Management" href="#" data-remote="/modals/time-management-modal.lp">Time Management</a>
</li>
<li class="">
<a id="Configuration" href="#" data-remote="/modals/system-config-modal.lp">Configuration</a>
</li>
</ul>

<form class="form-horizontal" method="post" action="modals/system-info-modal.lp">
<fieldset>
<legend>Information</legend>
<div class="control-group">
<label class="control-label">Product Vendor</label>
<div class="controls">
<span id="Product Vendor" class=" simple-desc span5">Technicolor</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Product Name</label>
<div class="controls">
<span id="Product Name" class=" simple-desc span5">Telia F1</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Serial Number</label>
<div class="controls">
<span id="Serial Number" class=" simple-desc span5">CP2221ADU9K</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Software Version</label>
<div class="controls">
<span id="Software Version" class=" simple-desc span5">19.5</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Uptime since last reboot</label>
<div class="controls">
<span id="Uptime since last reboot" class=" simple-desc span5">19 days 6 hours 13 minutes 8 seconds</span>
</div>
</div>
<div class="control-group advanced hide">
<label class="control-label">Firmware Version</label>
<div class="controls">
<span id="Firmware Version" class=" simple-desc span5">19.5.1062-4581003</span>
</div>
</div>
<div class="control-group advanced hide">
<label class="control-label">Hardware Version</label>
<div class="controls">
<span id="Hardware Version" class=" simple-desc span5">GCNT-X</span>
</div>
</div>
<div class="control-group advanced hide">
<label class="control-label">MAC Address</label>
<div class="controls">
<span id="MAC Address" class=" simple-desc span5">AA:BB:CC:45:18:0E</span>
</div>
</div>
<div class="control-group">
<label class="control-label">PowerSaving Mode</label>
<div class="controls">
<div class="switch">
<div class="switcher" textON="ON" textOFF="OFF" valOn="1" valOff="0"></div>
<input value="0" type="hidden" name="powerSavingMode" id="powerSavingMode">
</div>
</div>
</div>
</fieldset>
<fieldset class="advanced hide">
<legend>System Health</legend>
<div class="control-group advanced hide">
<label class="control-label">Memory Usage</label>
<div class="controls">
<span id="Memory Usage" class=" simple-desc span5">86 %</span>
</div>
</div>
<div class="control-group advanced hide">
<label class="control-label">CPU Usage</label>
<div class="controls">
<span id="CPU Usage" class=" simple-desc span5">2 %</span>
</div>
</div>
<div class="control-group advanced hide">
<label class="control-label">Reboot Cause</label>
<div class="controls">
<span id="Reboot Cause" class=" simple-desc span5">Power</span>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<div id="modal-no-change">
<div id="close-config" class="btn btn-primary btn-large" data-dismiss="modal">Close</div>
</div>
<div id="modal-changes" class="hide">
<div id="cancel-config" class="btn btn-large" data-dismiss="modal">Cancel</div>
<div id="save-config" class="btn btn-primary btn-large">Save</div>
</div>
</div>

Loading

0 comments on commit 00ba6c8

Please sign in to comment.