From 33804d1ad3a35de797f56ae3a16c663aca42d168 Mon Sep 17 00:00:00 2001 From: Devon Hess Date: Wed, 18 Nov 2020 18:25:13 -0500 Subject: [PATCH 1/4] [IKWYDBridge] New bridge --- bridges/IKWYDBridge.php | 121 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 bridges/IKWYDBridge.php diff --git a/bridges/IKWYDBridge.php b/bridges/IKWYDBridge.php new file mode 100644 index 00000000000..1e6845ff95b --- /dev/null +++ b/bridges/IKWYDBridge.php @@ -0,0 +1,121 @@ + array( + 'name' => 'IP Address', + 'required' => true + ), + 'update' => array( + 'name' => 'Update last seen', + 'type' => 'checkbox', + 'title' => 'Update timestamp every time ' . + '"last seen" changes' + ) + ) + ); + private $name; + private $uri; + + public function detectParameters($url) { + $params = array(); + + $regex = '/^(https?:\/\/)?iknowwhatyoudownload\.com\/' . + '(?:en|ru)\/peer\/\?ip=(\d+\.\d+\.\d+\.\d+)/'; + if(preg_match($regex, $url, $matches) > 0) { + $params['ip'] = urldecode($matches[2]); + return $params; + } + + $regex = '/^(https?:\/\/)?iknowwhatyoudownload\.com\/' . + '(?:(?:en|ru)\/peer\/)?/'; + if(preg_match($regex, $url, $matches) > 0) { + $params['ip'] = $_SERVER['REMOTE_ADDR']; + return $params; + } + + return null; + } + + public function getName() { + if($this->name) { + return $this->name; + } + else { + return self::NAME; + } + } + + public function getURI() { + if($this->uri) { + return $this->uri; + } + else { + return self::URI; + } + } + + public function collectData() { + $ip = $this->getInput('ip'); + $root = self::URI . 'en/peer/?ip=' . $ip; + $html = getSimpleHTMLDOM($root) + or returnServerError('Could not request ' . self::URI); + + $this->name = 'IKWYD: ' . $ip; + $this->uri = $root; + + foreach($html->find('.table > tbody > tr') as $download) { + $download = defaultLinkTo($download, self::URI); + $firstSeen = $download->find('.date-column', + 0)->innertext; + $lastSeen = $download->find('.date-column', + 1)->innertext; + $category = $download->find('.category-column', + 0)->innertext; + $torlink = $download->find('.name-column > div > a', + 0); + $tortitle = strip_tags($torlink); + $size = $download->find('td', 4)->innertext; + + $title = $tortitle; + $author = 'IKWYD'; + if($this->getInput('update')) { + $timestamp = strtotime($lastSeen); + } + else { + $timestamp = strtotime($firstSeen); + } + + $uri = $torlink->href; + $content = + 'IP address: ' . $ip . + '
' . + 'First seen: ' . $firstSeen . '
' . + ($this->getInput('update') ? + 'Last seen: ' . $lastSeen . '
' : '') . + ($category ? + 'Category: ' . $category . '
' : '') . + 'Title: ' . $torlink . + '
' . + 'Size: ' . $size; + + $item = array(); + $item['uri'] = $uri; + $item['title'] = $title; + $item['author'] = $author; + $item['timestamp'] = $timestamp; + $item['content'] = $content; + if($category) { + $item['categories'] = array($category); + } + $this->items[] = $item; + } + } +} + From ee44243068bdfa41a552049a1e52d7103f929ed9 Mon Sep 17 00:00:00 2001 From: Devon Hess Date: Tue, 24 Nov 2020 13:58:42 -0500 Subject: [PATCH 2/4] [IKWYDBridge] Cleanup code style --- bridges/IKWYDBridge.php | 46 ++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/bridges/IKWYDBridge.php b/bridges/IKWYDBridge.php index 1e6845ff95b..a9189bf5222 100644 --- a/bridges/IKWYDBridge.php +++ b/bridges/IKWYDBridge.php @@ -4,8 +4,7 @@ class IKWYDBridge extends BridgeAbstract { const NAME = 'I Know What You Download'; const URI = 'https://iknowwhatyoudownload.com/'; const CACHE_TIMEOUT = 3600; // 1h - const DESCRIPTION = 'Returns torrent downloads and distributions ' . - 'for an IP address'; + const DESCRIPTION = 'Returns torrent downloads and distributions for an IP address'; const PARAMETERS = array( array( 'ip' => array( @@ -15,8 +14,7 @@ class IKWYDBridge extends BridgeAbstract { 'update' => array( 'name' => 'Update last seen', 'type' => 'checkbox', - 'title' => 'Update timestamp every time ' . - '"last seen" changes' + 'title' => 'Update timestamp every time "last seen" changes' ) ) ); @@ -26,15 +24,15 @@ class IKWYDBridge extends BridgeAbstract { public function detectParameters($url) { $params = array(); - $regex = '/^(https?:\/\/)?iknowwhatyoudownload\.com\/' . - '(?:en|ru)\/peer\/\?ip=(\d+\.\d+\.\d+\.\d+)/'; + $regex = '/^(https?:\/\/)?iknowwhatyoudownload\.com\/'; + $regex .= '(?:en|ru)\/peer\/\?ip=(\d+\.\d+\.\d+\.\d+)/'; if(preg_match($regex, $url, $matches) > 0) { $params['ip'] = urldecode($matches[2]); return $params; } - $regex = '/^(https?:\/\/)?iknowwhatyoudownload\.com\/' . - '(?:(?:en|ru)\/peer\/)?/'; + $regex = '/^(https?:\/\/)?iknowwhatyoudownload\.com\/'; + $regex .= '(?:(?:en|ru)\/peer\/)?/'; if(preg_match($regex, $url, $matches) > 0) { $params['ip'] = $_SERVER['REMOTE_ADDR']; return $params; @@ -46,8 +44,7 @@ public function detectParameters($url) { public function getName() { if($this->name) { return $this->name; - } - else { + } else { return self::NAME; } } @@ -55,8 +52,7 @@ public function getName() { public function getURI() { if($this->uri) { return $this->uri; - } - else { + } else { return self::URI; } } @@ -82,28 +78,26 @@ public function collectData() { 0); $tortitle = strip_tags($torlink); $size = $download->find('td', 4)->innertext; - $title = $tortitle; $author = 'IKWYD'; + if($this->getInput('update')) { $timestamp = strtotime($lastSeen); - } - else { + } else { $timestamp = strtotime($firstSeen); } $uri = $torlink->href; - $content = - 'IP address: ' . $ip . - '
' . - 'First seen: ' . $firstSeen . '
' . - ($this->getInput('update') ? - 'Last seen: ' . $lastSeen . '
' : '') . - ($category ? - 'Category: ' . $category . '
' : '') . - 'Title: ' . $torlink . - '
' . - 'Size: ' . $size; + + $content = 'IP address: '; + $content .= $ip . '
'; + $content .= 'First seen: ' . $firstSeen . '
'; + $content .= ($this->getInput('update') ? + 'Last seen: ' . $lastSeen . '
' : ''); + $content .= ($category ? + 'Category: ' . $category . '
' : ''); + $content .= 'Title: ' . $torlink . '
'; + $content .= 'Size: ' . $size; $item = array(); $item['uri'] = $uri; From f925a5d6d414d7dc4ecda35ee6c2c74b7822eac9 Mon Sep 17 00:00:00 2001 From: Devon Hess Date: Tue, 24 Nov 2020 14:07:53 -0500 Subject: [PATCH 3/4] [IKWYDBridge] Use IP as author --- bridges/IKWYDBridge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridges/IKWYDBridge.php b/bridges/IKWYDBridge.php index a9189bf5222..4bc06554c95 100644 --- a/bridges/IKWYDBridge.php +++ b/bridges/IKWYDBridge.php @@ -79,7 +79,7 @@ public function collectData() { $tortitle = strip_tags($torlink); $size = $download->find('td', 4)->innertext; $title = $tortitle; - $author = 'IKWYD'; + $author = $ip; if($this->getInput('update')) { $timestamp = strtotime($lastSeen); From ded9a3095165e2f0a9a23888b6d2f54263bccb03 Mon Sep 17 00:00:00 2001 From: Devon Hess Date: Tue, 24 Nov 2020 14:21:18 -0500 Subject: [PATCH 4/4] [IKWYDBridge] Fix Travis CI errors --- bridges/IKWYDBridge.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/bridges/IKWYDBridge.php b/bridges/IKWYDBridge.php index 4bc06554c95..b24ac75cc4b 100644 --- a/bridges/IKWYDBridge.php +++ b/bridges/IKWYDBridge.php @@ -24,7 +24,7 @@ class IKWYDBridge extends BridgeAbstract { public function detectParameters($url) { $params = array(); - $regex = '/^(https?:\/\/)?iknowwhatyoudownload\.com\/'; + $regex = '/^(https?:\/\/)?iknowwhatyoudownload\.com\/'; $regex .= '(?:en|ru)\/peer\/\?ip=(\d+\.\d+\.\d+\.\d+)/'; if(preg_match($regex, $url, $matches) > 0) { $params['ip'] = urldecode($matches[2]); @@ -92,10 +92,10 @@ public function collectData() { $content = 'IP address: '; $content .= $ip . '
'; $content .= 'First seen: ' . $firstSeen . '
'; - $content .= ($this->getInput('update') ? - 'Last seen: ' . $lastSeen . '
' : ''); - $content .= ($category ? - 'Category: ' . $category . '
' : ''); + $content .= ($this->getInput('update') ? 'Last seen: ' . + $lastSeen . '
' : ''); + $content .= ($category ? 'Category: ' . + $category . '
' : ''); $content .= 'Title: ' . $torlink . '
'; $content .= 'Size: ' . $size; @@ -112,4 +112,3 @@ public function collectData() { } } } -