Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
[FurAffinityUserBridge] Replate username/password with cookie login (R…
Browse files Browse the repository at this point in the history
  • Loading branch information
girlpunk authored and Kwbmm committed Jun 17, 2022
1 parent 4f35b28 commit 569eb28
Showing 1 changed file with 9 additions and 61 deletions.
70 changes: 9 additions & 61 deletions bridges/FurAffinityUserBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class FurAffinityUserBridge extends BridgeAbstract {
const NAME = 'FurAffinity User Gallery';
const URI = 'https://www.furaffinity.net';
const MAINTAINER = 'CyberJacob';
const DESCRIPTION = 'See https://rss-bridge.github.io/rss-bridge/Bridge_Specific/Furaffinityuser.html for explanation';
const PARAMETERS = array(
array(
'searchUsername' => array(
Expand All @@ -12,24 +13,26 @@ class FurAffinityUserBridge extends BridgeAbstract {
'title' => 'Username to fetch the gallery for',
'exampleValue' => 'armundy',
),
'loginUsername' => array(
'name' => 'Login Username',
'aCookie' => array(
'name' => 'Login cookie \'a\'',
'type' => 'text',
'required' => true
),
'loginPassword' => array(
'name' => 'Login Password',
'bCookie' => array(
'name' => 'Login cookie \'b\'',
'type' => 'text',
'required' => true
)
)
);

public function collectData() {
$cookies = self::login();
$opt = array(CURLOPT_COOKIE => 'b=' . $this->getInput('bCookie') . '; a=' . $this->getInput('aCookie'));

$url = self::URI . '/gallery/' . $this->getInput('searchUsername');

$html = getSimpleHTMLDOM($url, $cookies);
$html = getSimpleHTMLDOM($url, array(), $opt)
or returnServerError('Could not load the user\'s gallery page.');

$submissions = $html->find('section[id=gallery-gallery]', 0)->find('figure');
foreach($submissions as $submission) {
Expand All @@ -52,59 +55,4 @@ public function getName() {
public function getURI() {
return self::URI . '/user/' . $this->getInput('searchUsername');
}

private function login() {
$ch = curl_init(self::URI . '/login/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($ch, CURLOPT_USERAGENT, ini_get('user_agent'));
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);

$fields = implode('&', array(
'action=login',
'retard_protection=1',
'name=' . urlencode($this->getInput('loginUsername')),
'pass=' . urlencode($this->getInput('loginPassword')),
'login=Login to Faraffinity'
));

curl_setopt($ch, CURLOPT_POST, 5);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);

if(defined('PROXY_URL') && !defined('NOPROXY')) {
curl_setopt($ch, CURLOPT_PROXY, PROXY_URL);
}

curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);

$data = curl_exec($ch);

$errorCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

$curlError = curl_error($ch);
$curlErrno = curl_errno($ch);
$curlInfo = curl_getinfo($ch);

if($data === false)
fDebug::log("Cant't download {$url} cUrl error: {$curlError} ({$curlErrno})");

curl_close($ch);

if($errorCode != 200) {
returnServerError(error_get_last());
} else {
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $data, $matches);
$cookies = array();

foreach($matches[1] as $item) {
parse_str($item, $cookie);
$cookies = array_merge($cookies, $cookie);
}

return $cookies;
}
}
}

0 comments on commit 569eb28

Please sign in to comment.