Browse files

Initial commit. Quick 'n' dirty PHP script for proxying FetLife pages.

  • Loading branch information...
0 parents commit 06f8966751b93684f1c88dbd36dfbc686227b5cb @meitar committed Aug 10, 2012
Showing with 2,321 additions and 0 deletions.
  1. +3 −0 .gitmodules
  2. +1 −0 lib
  3. +55 −0 proxy.php
  4. +2,262 −0 vendor/stylesheets/base_packaged.css
3 .gitmodules
@@ -0,0 +1,3 @@
+[submodule "lib"]
+ path = lib
+ url = git://github.com/meitar/libFetLife.git
1 lib
@@ -0,0 +1 @@
+Subproject commit 920a9cb896e0400999dda95ff652019a05f757bc
55 proxy.php
@@ -0,0 +1,55 @@
+<?php
+/**
+ * A quick-and-dirty proxy to make FetLife.com pages accessible to everyone.
+ */
+
+// Library.
+require_once(dirname(__FILE__) . '/lib/FetLife.php');
+
+// Grab the BugMeNot.com account credential listing for FetLife.com.
+$ch = curl_init('http://www.bugmenot.com/view/fetlife.com');
+curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+$html = curl_exec($ch);
+curl_close($ch);
+
+// Create HTML DOM from the BugMeNot.com account page.
+$bugmenot = new DOMDocument();
+$bugmenot->loadHTML($html);
+$divs = $bugmenot->getElementsByTagName('div');
+
+$accts = array();
+$i = 0;
+foreach ($divs as $div) {
+ if ('account' === $div->getAttribute('class')) {
+ $accts[$i]['nickname'] = $div->getElementsByTagName('td')->item(0)->nodeValue;
+ $accts[$i]['password'] = $div->getElementsByTagName('td')->item(1)->nodeValue;
+ $accts[$i]['hit_rate'] = $div->getElementsByTagName('td')->item(3)->nodeValue;
+ $i++;
+ }
+}
+// BugMeNot.com already sorts accounts based on reported success rate. Just use those.
+
+// Find a working login and use it.
+for ($i = 0; $i < count($accts); $i++) {
+ $FL = new FetLifeUser($accts[$i]['nickname'], $accts[$i]['password']);
+ if ($FL->logIn()) {
+ break; // exit loop, we've got a functional login to FetLife!
+ }
+}
+
+$conn = new FetLifeConnection($FL);
+
+if (isset($_GET['page'])) {
+ $response = $conn->doHttpGet(urldecode($_GET['page']));
+} else {
+ $response = $conn->doHttpGet('/home');
+}
+
+$html_out = preg_replace('/href="\//', 'href="' . $_SERVER['PHP_SELF'] . '?page=/', $response['body']);
+$html_out = preg_replace('/href="https:\/\/fetlife.com/', 'href="' . $_SERVER['PHP_SELF'] . '?page=', $html_out);
+
+// Replace CSS with our own.
+$html_out = preg_replace('/<link href="https:\/\/flassets.a.ssl.fastly.net\/stylesheets\/(std2\/std|base_packaged).css/', '<link href="' . dirname($_SERVER['PHP_SELF']) . '/vendor/stylesheets/base_packaged.css', $html_out);
+$html_out = preg_replace('/<link href="https:\/\/flassets.a.ssl.fastly.net\/stylesheets\/(std2\/scratch|print_packaged).css/', '<link href="' . dirname($_SERVER['PHP_SELF']) . '/vendor/stylesheets/base_packaged.css', $html_out);
+
+print $html_out;
2,262 vendor/stylesheets/base_packaged.css
2,262 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.

0 comments on commit 06f8966

Please sign in to comment.