Skip to content

Commit

Permalink
1. add test for login without token
Browse files Browse the repository at this point in the history
2. add support to new version of modal lp
  • Loading branch information
shaiu committed Jan 11, 2023
1 parent 00e80fb commit fff559a
Show file tree
Hide file tree
Showing 8 changed files with 460 additions and 7 deletions.
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ toml==0.10.2
urllib3==1.26.13
Werkzeug==0.16.1
lxml==4.9.2

setuptools~=65.6.3
responses~=0.22.0
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pathlib

from setuptools import setup

# The directory containing this file
Expand All @@ -10,7 +11,7 @@
# This call to setup() does all the work
setup(
name="pytechnicolor",
version="1.1.6",
version="1.1.7",
description="Technicolor Gateway library",
long_description=README,
long_description_content_type="text/markdown",
Expand Down
17 changes: 12 additions & 5 deletions technicolorgateway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

_LOGGER = logging.getLogger(__name__)

__version__ = "1.1.6"
__version__ = "1.1.7"


class TechnicolorGateway:
Expand All @@ -26,8 +26,9 @@ def __init__(self, host, port, user, password) -> None:
def srp6authenticate(self):
try:
self._br.open(self._uri)
token = self._br.find(lambda tag: tag.has_attr('name')
and tag['name'] == 'CSRFtoken')['content']
token_tag = self._br.find(lambda tag: tag.has_attr('name')
and tag['name'] == 'CSRFtoken')
token = token_tag['content']
_LOGGER.debug('Got CSRF token: %s', token)

usr = srp.User(self._user, self._password, hash_alg=srp.SHA256, ng_type=srp.NG_2048)
Expand Down Expand Up @@ -63,8 +64,14 @@ def srp6authenticate(self):
traceback.print_exc()
raise

def get_device_modal(self):
req = self._br.session.get(f"{self._uri}/modals/device-modal.lp")
def device_modal(self):
data = self.get_device_modals(f"{self._uri}/modals/device-modal.lp")
if len(data) == 0:
data = self.get_device_modals(f"{self._uri}/modals/ipv6devices-modal.lp")
return data

def get_device_modals(self, device_modal):
req = self._br.session.get(device_modal)
self._br._update_state(req)
content = req.content.decode()
return get_device_modal(content)
Expand Down
2 changes: 1 addition & 1 deletion technicolorgateway/modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_device_modal(content):
data = []
soup = BeautifulSoup(content, features="lxml")
devices = soup.find_all("div", {"class": "popUp smallcard span4"})
rows = soup.fieldset.find_all('tr')
rows = soup.find_all('tr')
if len(devices) > 0:
get_data_from_devices(data, devices)

Expand Down
80 changes: 80 additions & 0 deletions tests/resources/ipv6devices-modal.lp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<html>
<head></head>
<body>
<div class="modal-header">
<div class="row-fluid">
<div class="span11"><h2 class="span4"> Devices</h2>
<span class="modal-action"><span class="modal-action-refresh" id="Refresh_id"><i class="icon-refresh"></i> refresh data</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 no-save">
<ul class="nav nav-tabs">
<li><a id="Global Information" href="#" data-remote="modals/device-modal.lp">Global Information</a></li>
<li class="active"><a id="Devices List" href="#" data-remote="modals/ipv6devices-modal.lp">Devices List</a></li>
</ul>
<form class="form-horizontal" method="post" action="modals/ipv6devices-modal.lp">
<div id="to_top" class="btn"><i class=""></i></div>

<legend>Devices</legend>
<div class="control-group">
<table id="ipv6Devices" class="table table-striped" data-stateid="">
<thead>
<tr>
<th>Status</th>
<th>Device Type</th>
<th>Hostname</th>
<th>IPv4</th>
<th>MAC Address</th>
<th>Interface</th>
<th>Connected Time</th>
<th>Expires In</th>
<th>IPv6</th>
<th>IPv6 Link Local Addr</th>
<th>Priority</th>
<th>Priority</th>
</tr>
</thead>
<tbody>
<tr>
<td data-title="Status"><span class="simple-desc"><div class="light green"></div></span></td>
<td data-title="Device Type"></td>
<td data-title="Hostname">DeviceHostName</td>
<td data-title="IPv4">192.168.1.111</td>
<td data-title="MAC Address">A4:83:e7:32:7e:11</td>
<td data-title="Interface">wireless - 5GHz</td>
<td data-title="Connected Time">1 hour 52 minutes 30 seconds</td>
<td data-title="Expires In">10 hours 7 minutes 33 seconds</td>
<td data-title="IPv6">2a0d:6fc0:bb1:6f00:cc22:8d9b:2bcb:1111</td>
<td data-title="IPv6 Link Local Addr">fe80::1857:b258:5690:1111</td>
<td data-title="Priority">0</td>
<td data-title="Priority">
<div class="switch switch disabled">
<div class="switcher" texton="ON" textoff="OFF" valon="1" valoff="0"></div>
<input value="0" type="hidden" name="priority" id="priority"></div>
</td>
</tr>
</tbody>
</table>
</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>

<script>
var featureFlag = nil;
</script>
<script src="/js/ipv6devices-modal.js"></script>
</body>
</html>
Loading

0 comments on commit fff559a

Please sign in to comment.