From 8ca6cc32b2c789a3149861159ad258f2cb9491e3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:39:39 +0200 Subject: Adding upstream version 2.11.4. Signed-off-by: Daniel Baumann --- library/Icinga/Web/RememberMeUserDevicesList.php | 144 +++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 library/Icinga/Web/RememberMeUserDevicesList.php (limited to 'library/Icinga/Web/RememberMeUserDevicesList.php') diff --git a/library/Icinga/Web/RememberMeUserDevicesList.php b/library/Icinga/Web/RememberMeUserDevicesList.php new file mode 100644 index 0000000..66609de --- /dev/null +++ b/library/Icinga/Web/RememberMeUserDevicesList.php @@ -0,0 +1,144 @@ + 'common-table', + 'data-base-target' => '_self' + ]; + + /** + * @var array + */ + protected $devicesList; + + /** + * @var string + */ + protected $username; + + /** + * @var string + */ + protected $url; + + /** + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * @param string $url + * + * @return $this + */ + public function setUrl($url) + { + $this->url = $url; + + return $this; + } + + /** + * @return string + */ + public function getUsername() + { + return $this->username; + } + + /** + * @param string $username + * + * @return $this + */ + public function setUsername($username) + { + $this->username = $username; + + return $this; + } + + /** + * @return array List of devices. Each device contains user agent and fingerprint string + */ + public function getDevicesList() + { + return $this->devicesList; + } + + /** + * @param $devicesList + * + * @return $this + */ + public function setDevicesList($devicesList) + { + $this->devicesList = $devicesList; + + return $this; + } + + protected function assemble() + { + $thead = Html::tag('thead'); + $theadRow = Html::tag('tr') + ->add(Html::tag( + 'th', + sprintf(t('List of devices and browsers %s is currently logged in:'), $this->getUsername()) + )); + + $thead->add($theadRow); + + $head = Html::tag('tr') + ->add(Html::tag('th', t('OS'))) + ->add(Html::tag('th', t('Browser'))) + ->add(Html::tag('th', t('Fingerprint'))); + + $thead->add($head); + $tbody = Html::tag('tbody'); + + if (empty($this->getDevicesList())) { + $tbody->add(Html::tag('td', t('No device found'))); + } else { + foreach ($this->getDevicesList() as $device) { + $agent = new UserAgent($device); + $element = Html::tag('tr') + ->add(Html::tag('td', $agent->getOs())) + ->add(Html::tag('td', $agent->getBrowser())) + ->add(Html::tag('td', $device->random_iv)); + + $link = (new Link( + new Icon('trash'), + iplWebUrl::fromPath($this->getUrl()) + ->addParams( + [ + 'name' => $this->getUsername(), + 'fingerprint' => $device->random_iv, + ] + ) + )); + + $element->add(Html::tag('td', $link)); + $tbody->add($element); + } + } + + $this->add($thead); + $this->add($tbody); + } +} -- cgit v1.2.3