diff --git a/FFdownload.php b/FFdownload.php new file mode 100644 index 0000000..a8bf66a --- /dev/null +++ b/FFdownload.php @@ -0,0 +1,236 @@ +enableDebug(); + + $auth_failure = false; + + // Try to make request using stored token + try { + $o->setToken( $access_token, $access_secret ); + if( $o->fetch( $url ) ) { + print "Got data from API:\n\n"; + print $o->getLastResponse() . "\n\n"; + + print "Successful!\n"; + exit; + } else { + print "Couldn'\t fetch\n"; + } + } catch( OAuthException $e ) { + print 'Error: ' . $e->getMessage() . "\n"; + print 'Error Code: ' . $e->getCode() . "\n"; + print 'Response: ' . $e->lastResponse . "\n"; + + if( $e->getCode() == 401 ) { + $auth_failure = true; + } + } + + + // 2. If we get an auth error, try to refresh the token using the session. + if( $auth_failure ) { + + try { + $response = $o->getAccessToken( 'https://api.login.yahoo.com/oauth2/request_auth', $access_session, $access_verifier ); + } catch( OAuthException $e ) { + print 'Error: ' . $e->getMessage() . "\n"; + print 'Response: ' . $e->lastResponse . "\n"; + + $response = NULL; + } + + print_r( $response ); + + if( $response ) { + $access_token = $response['oauth_token']; + $access_secret = $response['oauth_token_secret']; + $access_session = $response['oauth_session_handle']; + $store_access_token_data = true; + + print "Was able to refresh access token:\n"; + print " Token: ${access_token}\n"; + print " Secret: ${access_secret}\n"; + print " Session Handle: ${access_session}\n\n"; + + } else { + + $access_token = NULL; + $access_secret = NULL; + $access_session = NULL; + print "Unable to refresh access token, will need to request a new one.\n"; + } + } +} + +// 3. If none of that worked, send the user to get a new token +if( ! $access_token ) { + + print "Better try to get a new access token.\n"; + $o = new OAuth( $consumer_key, $consumer_secret, + OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI ); + $o->enableDebug(); + + $request_token = NULL; + + try { + $response = $o->getRequestToken( "https://api.login.yahoo.com/oauth2/request_auth", 'oob' ); + $request_token = $response['oauth_token']; + $request_secret = $response['oauth_token_secret']; + + print "Hey! Go to this URL and tell us the verifier you get at the end.\n"; + print ' ' . $response['xoauth_request_auth_url'] . "\n"; + + } catch( OAuthException $e ) { + print $e->getMessage() . "\n"; + } + + // Wait for input, then try to use it to get a new access token. + if( $request_token && $request_secret ) { + print "Type the verifier and hit enter...\n"; + $verifier = fgets( STDIN ); + $verifier = rtrim( $verifier ); + + print "Here's the verifier you gave us: ${verifier}\n"; + + try { + $o->setToken( $request_token, $request_secret ); + $response = $o->getAccessToken( 'https://api.login.yahoo.com/oauth2/request_auth', NULL, $verifier ); + + print "Got it!\n"; + $access_token = $response['oauth_token']; + $access_secret = $response['oauth_token_secret']; + $access_session = $response['oauth_session_handle']; + $store_access_token_data = true; + print " Token: ${access_token}\n"; + print " Secret: ${access_secret}\n"; + print " Session Handle: ${access_session}\n\n"; + + + } catch( OAuthException $e ) { + print 'Error: ' . $e->getMessage() . "\n"; + print 'Response: ' . $e->lastResponse . "\n"; + print "Shoot, couldn't get the access token. :(\n"; + } + } + +} + +if( $access_token ) { + + // Try to make request using stored token + try { + $o->setToken( $access_token, $access_secret ); + if( $o->fetch( $url ) ) { + print "Got data from API:\n\n"; + print $o->getLastResponse() . "\n\n"; + + print "Successful!\n"; + } else { + print "Couldn'\t fetch\n"; + } + } catch( OAuthException $e ) { + print 'Error: ' . $e->getMessage() . "\n"; + print 'Error Code: ' . $e->getCode() . "\n"; + print 'Response: ' . $e->lastResponse . "\n"; + } +} + +// 4. Rewrite token information if necessary +if( $store_access_token_data ) { + + print "Looks like we need to store access token data! Doing that now.\n"; + + $tok_fh = fopen( $token_file_name, 'w' ); + if( $tok_fh ) { + fwrite( $tok_fh, "${access_token}\n" ); + fwrite( $tok_fh, "${access_secret}\n" ); + fwrite( $tok_fh, "${access_session}\n" ); + + fclose( $tok_fh ); + } else { + print "Hm, couldn't open file to write back access token information.\n"; + } +} +?> \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..3d1c62e --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# FFDownload2019 diff --git a/go-pear.phar b/go-pear.phar new file mode 100644 index 0000000..6c137dc --- /dev/null +++ b/go-pear.phar @@ -0,0 +1,98913 @@ + + * @author Greg Beaver + * @link http://www.synapticmedia.net Synaptic Media + * @version Id$ + * @package PHP_Archive + * @category PHP + */ + +class PHP_Archive +{ + const GZ = 0x00001000; + const BZ2 = 0x00002000; + const SIG = 0x00010000; + const SHA1 = 0x0002; + const MD5 = 0x0001; + const SHA256 = 0x0003; + const SHA512 = 0x0004; + const OPENSSL = 0x0010; + /** + * Whether this archive is compressed with zlib + * + * @var bool + */ + private $_compressed; + /** + * @var string Real path to the .phar archive + */ + private $_archiveName = null; + /** + * Current file name in the phar + * @var string + */ + protected $currentFilename = null; + /** + * Length of current file in the phar + * @var string + */ + protected $internalFileLength = null; + /** + * true if the current file is an empty directory + * @var string + */ + protected $isDir = false; + /** + * Current file statistics (size, creation date, etc.) + * @var string + */ + protected $currentStat = null; + /** + * @var resource|null Pointer to open .phar + */ + protected $fp = null; + /** + * @var int Current Position of the pointer + */ + protected $position = 0; + + /** + * Map actual realpath of phars to meta-data about the phar + * + * Data is indexed by the alias that is used by internal files. In other + * words, if a file is included via: + * + * require_once 'phar://PEAR.phar/PEAR/Installer.php'; + * + * then the alias is "PEAR.phar" + * + * Information stored is a boolean indicating whether this .phar is compressed + * with zlib, another for bzip2, phar-specific meta-data, and + * the precise offset of internal files + * within the .phar, used with the {@link $_manifest} to load actual file contents + * @var array + */ + private static $_pharMapping = array(); + /** + * Map real file paths to alias used + * + * @var array + */ + private static $_pharFiles = array(); + /** + * File listing for the .phar + * + * The manifest is indexed per phar. + * + * Files within the .phar are indexed by their relative path within the + * .phar. Each file has this information in its internal array + * + * - 0 = uncompressed file size + * - 1 = timestamp of when file was added to phar + * - 2 = offset of file within phar relative to internal file's start + * - 3 = compressed file size (actual size in the phar) + * @var array + */ + private static $_manifest = array(); + /** + * Absolute offset of internal files within the .phar, indexed by absolute + * path to the .phar + * + * @var array + */ + private static $_fileStart = array(); + /** + * file name of the phar + * + * @var string + */ + private $_basename; + + + /** + * Default MIME types used for the web front controller + * + * @var array + */ + public static $defaultmimes = array( + 'aif' => 'audio/x-aiff', + 'aiff' => 'audio/x-aiff', + 'arc' => 'application/octet-stream', + 'arj' => 'application/octet-stream', + 'art' => 'image/x-jg', + 'asf' => 'video/x-ms-asf', + 'asx' => 'video/x-ms-asf', + 'avi' => 'video/avi', + 'bin' => 'application/octet-stream', + 'bm' => 'image/bmp', + 'bmp' => 'image/bmp', + 'bz2' => 'application/x-bzip2', + 'css' => 'text/css', + 'doc' => 'application/msword', + 'dot' => 'application/msword', + 'dv' => 'video/x-dv', + 'dvi' => 'application/x-dvi', + 'eps' => 'application/postscript', + 'exe' => 'application/octet-stream', + 'gif' => 'image/gif', + 'gz' => 'application/x-gzip', + 'gzip' => 'application/x-gzip', + 'htm' => 'text/html', + 'html' => 'text/html', + 'ico' => 'image/x-icon', + 'jpe' => 'image/jpeg', + 'jpg' => 'image/jpeg', + 'jpeg' => 'image/jpeg', + 'js' => 'application/x-javascript', + 'log' => 'text/plain', + 'mid' => 'audio/x-midi', + 'mov' => 'video/quicktime', + 'mp2' => 'audio/mpeg', + 'mp3' => 'audio/mpeg3', + 'mpg' => 'audio/mpeg', + 'pdf' => 'aplication/pdf', + 'png' => 'image/png', + 'rtf' => 'application/rtf', + 'tif' => 'image/tiff', + 'tiff' => 'image/tiff', + 'txt' => 'text/plain', + 'xml' => 'text/xml', + ); + + public static $defaultphp = array( + 'php' => true + ); + + public static $defaultphps = array( + 'phps' => true + ); + + public static $deny = array('/.+\.inc$/'); + + public static function viewSource($archive, $file) + { + // security, idea borrowed from PHK + if (!file_exists($archive . '.introspect')) { + header("HTTP/1.0 404 Not Found"); + return false; + } + if (self::_fileExists($archive, $_GET['viewsource'])) { + $source = highlight_file('phar://go-pear.phar/' . + $_GET['viewsource'], true); + header('Content-Type: text/html'); + header('Content-Length: ' . strlen($source)); + echo 'Source of ', + htmlspecialchars($_GET['viewsource']), ''; + echo '

Source of ', + htmlspecialchars($_GET['viewsource']), '

'; + if (isset($_GET['introspect'])) { + echo 'Return to ', htmlspecialchars($_GET['introspect']), '
'; + } + echo $source; + return false; + } else { + header("HTTP/1.0 404 Not Found"); + return false; + } + + } + + public static function introspect($archive, $dir) + { + // security, idea borrowed from PHK + if (!file_exists($archive . '.introspect')) { + header("HTTP/1.0 404 Not Found"); + return false; + } + if (!$dir) { + $dir = '/'; + } + $dir = self::processFile($dir); + if ($dir[0] != '/') { + $dir = '/' . $dir; + } + try { + $self = htmlspecialchars($_SERVER['PHP_SELF']); + $iterate = new DirectoryIterator('phar://go-pear.phar' . $dir); + echo 'Introspect ', htmlspecialchars($dir), + '

Introspect ', htmlspecialchars($dir), + '