pull.php 4.07 KB
Newer Older
MatrixCrawler's avatar
MatrixCrawler committed
1
<?php
MatrixCrawler's avatar
MatrixCrawler committed
2
 error_reporting(E_ALL);
MatrixCrawler's avatar
MatrixCrawler committed
3 4 5 6 7 8 9
/** 
 * Copyright (c) 2011, David Morley. 
 * This file is licensed under the Affero General Public License version 3 or later. 
 * See the COPYRIGHT file. 
 */


MatrixCrawler's avatar
MatrixCrawler committed
10
require_once 'config.inc.php';
11
require_once 'pull.class.php';
MatrixCrawler's avatar
MatrixCrawler committed
12 13 14 15

if (DEBUG) {
	echo "Starting script<br/>";
}
MatrixCrawler's avatar
MatrixCrawler committed
16
// Inititialize variables
MatrixCrawler's avatar
MatrixCrawler committed
17

MatrixCrawler's avatar
MatrixCrawler committed
18 19 20 21 22 23 24 25 26 27 28
$state 					= ""; // Seems to be always empty. Deprecated?
$pingdomdate 			= date('Y-m-d H:i:s'); // is always the current date
$timenow 				= date('Y-m-d H:i:s'); // is always the current date
$gitdate 				= "";
$encoding 				= "";
$secure 				= ""; 
$hidden 				= ""; 
$runtime 				= ""; 
$gitrev 				= ""; 
$ipnum 					= ""; 
$ipv6 					= ""; 
MatrixCrawler's avatar
MatrixCrawler committed
29
$months 				= 0; 
MatrixCrawler's avatar
MatrixCrawler committed
30
$uptime 				= 0; 
MatrixCrawler's avatar
MatrixCrawler committed
31
$live 					= "";  
MatrixCrawler's avatar
MatrixCrawler committed
32 33 34 35 36 37 38 39 40 41 42
$responsetime 			= ""; 
$score 					= ""; 
$adminRating 			= ""; 
$country 				= ""; 
$city 					= ""; 
$lat 					= ""; 
$long 					= ""; 
$diasporaVersion		= ""; 
$whois 					= ""; 
$userRating 			= ""; 
$xdver 					= ""; 
43 44 45 46 47
$registrationsOpen		= 0; 
$totalUsers 			= 0; 
$activeUsersHalfyear 	= 0;
$activeUsersMonthly 	= 0; 
$localPosts 			= 0; 
MatrixCrawler's avatar
MatrixCrawler committed
48
$podName 				= ""; 
MatrixCrawler's avatar
MatrixCrawler committed
49

MatrixCrawler's avatar
MatrixCrawler committed
50 51 52 53 54 55
$masterVersion = Pull::getMasterVersion();
$dbh = Pull::getDatabaseConnection();

// Check if the pullrequest is made for a specific pod domain
$domain = isset($_GET['domain']) ? $_GET['domain'] : null;
$result = Pull::getPodList($domain, $dbh);
David Morley's avatar
David Morley committed
56

MatrixCrawler's avatar
MatrixCrawler committed
57
// Iterate over each Pod in the resultset
MatrixCrawler's avatar
MatrixCrawler committed
58 59 60
foreach ($result->fetchAll() as $row) {

	$podSecure = "false";
MatrixCrawler's avatar
MatrixCrawler committed
61 62 63
	
	$domain = $row['domain'];
	$score = $row['score'];
MatrixCrawler's avatar
MatrixCrawler committed
64
	$datecreated = $row['datecreated'];
MatrixCrawler's avatar
MatrixCrawler committed
65 66 67 68 69 70 71 72 73
	$adminRating = $row['adminrating'];
	
	if (DEBUG) {
		echo("Pod: <b>".$domain."</b><br />");
	}
	// Get Ratings for Pod
	Pull::getRatings($adminRating, $userRating, $domain, $dbh);
	
	// Get Header from Pod
MatrixCrawler's avatar
MatrixCrawler committed
74
	$header = Pull::getHeaderFromPod($domain, $podSecure);
MatrixCrawler's avatar
MatrixCrawler committed
75 76
	
	if (DEBUG) {
MatrixCrawler's avatar
MatrixCrawler committed
77
		if ($podSecure == "true") {
MatrixCrawler's avatar
MatrixCrawler committed
78 79 80 81 82 83 84 85 86 87
			echo "Pod has SSL connection<br />";
		} else {
			echo "Pod has no SSL connection<br />";
		}
		echo "Pod Header: ".$header."<br />";
	}
	
	if ($header) {
		// Parse Header Data, if there is a header
		Pull::parseHeader($header, $gitdate, $gitrev, $xdver, $diasporaVersion, $runtime, $server, $encoding);
MatrixCrawler's avatar
MatrixCrawler committed
88
		Pull::parseJSON($header, $podName, $registrationsOpen, $totalUsers, $activeUsersHalfyear, $activeUsersMonthly, $localPosts, $diasporaVersion, $xdver);
MatrixCrawler's avatar
MatrixCrawler committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
		
		if (!$diasporaVersion) {
			// No Diaspora-Version identifier. might not be trustable?
			$score -= 2;
			if (DEBUG) {
				echo("No Diaspora Version-identifier. Reducing points.<br />");
			}	
		} else {
			$score++;
			if (DEBUG) {
				echo("Everything allright. Increasing points.<br />");
			}
		}
	} else {
		// No header, no connection
		$score--;
		if (DEBUG) {
			echo("No header. Reducing points.<br />");
		}
	}
	
	
MatrixCrawler's avatar
MatrixCrawler committed
111

MatrixCrawler's avatar
MatrixCrawler committed
112
	// Get IPv6 if present
MatrixCrawler's avatar
MatrixCrawler committed
113 114 115 116 117 118
	$ip6num = Pull::getIPv6($domain);
	if ($ip6num == '') {
		$podHasIPv6 = "no";
	} else {
		$podHasIPv6 = "yes";
	}
MatrixCrawler's avatar
MatrixCrawler committed
119

MatrixCrawler's avatar
MatrixCrawler committed
120
	//Get IPv4 if present
MatrixCrawler's avatar
MatrixCrawler committed
121
	$ipnum = Pull::getIPv4($domain);
MatrixCrawler's avatar
MatrixCrawler committed
122

MatrixCrawler's avatar
MatrixCrawler committed
123
	// Try to get the position of the Pod via GeoIP
MatrixCrawler's avatar
MatrixCrawler committed
124
	Pull::getGeoIPData($ipnum, $whois, $country, $city, $lat, $long);
MatrixCrawler's avatar
MatrixCrawler committed
125

MatrixCrawler's avatar
MatrixCrawler committed
126 127
	// Pull the uptimedata
	$robotData = Pull::getRobotData($row['pingdomurl'], $datecreated, $responsetime, $months, $uptime, $live, $score);
MatrixCrawler's avatar
MatrixCrawler committed
128

MatrixCrawler's avatar
MatrixCrawler committed
129 130 131 132
	if ($robotData) {
		// All data is present.
		// Cap the score
		Pull::capScore($score);
MatrixCrawler's avatar
MatrixCrawler committed
133

MatrixCrawler's avatar
MatrixCrawler committed
134 135 136 137 138 139
		// Check if the Pod should be hidden or not
		if ($score > 5) {
			$hidden = "no";
		} else {
			$hidden = "yes";
		}
MatrixCrawler's avatar
MatrixCrawler committed
140 141 142 143 144 145 146

        if (DEBUG) {
            echo "Hidden: ".$hidden."<br />";
        }

		// Update Database entry
		Pull::writeData($dbh, $gitdate, $encoding, $podSecure, $hidden, $runtime, $gitrev, $ipnum,
MatrixCrawler's avatar
MatrixCrawler committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
						$ip6num, $months, $uptime, $live, $pingdomdate, $timenow, $responsetime, 
						$score, $adminRating, $country, $city, $state, $lat, $long, 
						$diasporaVersion, $whois, $userRating, $xdver, $masterVersion, 
						$registrationsOpen, $totalUsers, $activeUsersHalfyear, $activeUsersMonthly, 
						$localPosts, $podName, $domain);
		if (DEBUG) {
			echo "<br />Score out of 20: ".$score."<br />";
			echo "Success <br /><hr><br />";
		}
	} else {
		
		if (DEBUG) {
			echo "Not succesfull.<br /><hr><br />";
		}
	}	
MatrixCrawler's avatar
MatrixCrawler committed
162 163 164
	
} // end while	
unset($dbh);
165
?>