Commit aaa29209 authored by MatrixCrawler's avatar MatrixCrawler

--no commit message

--no commit message
parent 2c10a5af
......@@ -18,4 +18,14 @@ $adminkey = '';
$chimpkey = '';
//apikey for public api calls
$apikey= '';
// Database connection
define("DB_DRIVER","pgsql"); //requires pdo-pgsql
// define("DB_DRIVER","mysql"); // requires pdo-mysql
define("DB_NAME","dbname");
define("DB_HOST","localhost");
define("DB_USER","dbuser");
define("DB_PASSWORD","dbpassword");
?>
<?php
error_reporting(E_ALL);
/**
* Copyright (c) 2011, David Morley.
* This file is licensed under the Affero General Public License version 3 or later.
......@@ -7,23 +7,24 @@ error_reporting(E_ALL);
*/
require_once "Net/GeoIP.php";
require_once 'config.php';
// The options for the cUrl Requests
define("CURL_POST", 0);
define("CURL_HEADER", 1);
define("CURL_CONNECTTIMEOUT", 5);
define("CURL_RETURNTRANSFER", 1);
define("CURL_NOBODY", 0);
define("DB_DRIVER","pgsql"); //requires pdo-pgsql
// define("DB_DRIVER","mysql"); // requires pdo-mysql
define("DB_NAME","poduptime");
define("DB_HOST","localhost");
define("DB_USER","poduptime");
define("DB_PASSWORD","poduptimetest");
define("DEBUG", true);
define("VERBOSE_CURL", false);
/**
* Class collecting functions for pulling data from Pods
* @author J. Brunswicker
* @version 1.0
*
*/
class Pull {
/**
......@@ -82,6 +83,10 @@ class Pull {
*/
public static function getDatabaseConnection() {
$dsn = DB_DRIVER.":dbname=".DB_NAME.";host=".DB_HOST;
if (DB_DRIVER == 'mysql') {
$dsn .= ";charset=UTF8";
}
try {
$connection = new PDO($dsn, DB_USER, DB_PASSWORD);
......@@ -359,6 +364,16 @@ class Pull {
}
}
/**
* Gets data from pingdom.com
* @param string $pingdomUrl
* @param string $responsetime
* @param string $months
* @param string $uptime
* @param string $live
* @param string $score
* @deprecated
*/
private static function getPingdomData($pingdomUrl, &$responsetime, &$months, &$uptime, &$live, &$score) {
// Pod is monitored via pingdom
$thismonth = "/".date("Y")."/".date("m");
......@@ -377,8 +392,6 @@ class Pull {
preg_match_all('/<option(.*?)/s',$implodemonths,$matchdates);
$months = isset($matchdates[0])?count($matchdates[0]):0;
//echo $matchdates[0];
//uptime %
preg_match_all('/<h3>Uptime this month<\/h3>\s*<p class="large">(.*?)%</',$pingdom,$matchper);
$uptime = isset($matchper[1][0])?preg_replace("/,/", ".", $matchper[1][0]):0;
......@@ -409,6 +422,14 @@ class Pull {
}
/**
* Gets data from the uptimerobot
* @param string $pingdomUrl
* @param string $responsetime
* @param string $months
* @param string $uptime
* @param string $live
*/
private static function getUptimerobotData($pingdomUrl, &$responsetime, &$months, &$uptime, &$live) {
//do uptimerobot API instead
$uptimerobot = Pull::getCurlResult($pingdomUrl);
......@@ -452,7 +473,7 @@ class Pull {
if (strpos($pingdomUrl, "pingdom.com")) {
Pull::getPingdomData($pingdomUrl, $responsetime, $months, $uptime, $live, $score);
} else {
Pull::getUptimerobotData($pingdomUrl, $responsetime, $months, $uptime, $live);
Pull::getUptimerobotData("http://api.uptimerobot.com/getMonitors?format=json&customUptimeRatio=7-30-60-90&apiKey=".$pingdomUrl, $responsetime, $months, $uptime, $live);
}
} else {
echo "No PingdomURL provided<br />";
......@@ -464,11 +485,18 @@ class Pull {
$sql = "UPDATE pods SET Hgitdate=".$connection->quote($gitdate).", Hencoding=".$connection->quote($encoding).", secure=".$connection->quote($secure).", hidden=".$connection->quote($hidden).", Hruntime=".$connection->quote($runtime).", ";
$sql .= "Hgitref=".$connection->quote($gitrev).", ip=".$connection->quote($ipnum).", ipv6=".$connection->quote($ipv6).", monthsmonitored=".$months.", uptimelast7=".$connection->quote($uptime).", status=".$connection->quote($live).", ";
$sql .= "dateLaststats=".$connection->quote($pingdomdate).", dateUpdated=".$connection->quote($timenow).", responsetimelast7=".$connection->quote($responsetime).", score=".$connection->quote($score).", ";
$sql .= "adminrating=".$connection->quote($adminRating).", country=".$connection->quote($country).", city=".$connection->quote($city).", state=".$connection->quote($state).", lat=".$connection->quote($lat).", long=".$connection->quote($long).", ";
$sql .= "postalcode='', connection=".$connection->quote($diasporaVersion).", whois=".$connection->quote($whois).", userrating=".$connection->quote($userRating).", longversion=".$connection->quote($xdver).", ";
$sql .= "adminrating=".$connection->quote($adminRating).", country=".$connection->quote($country).", city=".$connection->quote($city).", state=".$connection->quote($state).", lat=".$connection->quote($lat).", ";
$sql .= "connection=".$connection->quote($diasporaVersion).", whois=".$connection->quote($whois).", userrating=".$connection->quote($userRating).", longversion=".$connection->quote($xdver).", ";
$sql .= "shortversion=".$connection->quote($diasporaVersion).", masterversion=".$connection->quote($masterVersion).", signup=".$connection->quote($registrationsOpen).", total_users=".$connection->quote($totalUsers).", ";
$sql .= "active_users_halfyear=".$connection->quote($activeUsersHalfyear).", active_users_monthly=".$connection->quote($activeUsersMonthly).", local_posts=".$connection->quote($localPosts).", ";
$sql .= "name=".$connection->quote($podName)." ";
$sql .= "name=".$connection->quote($podName).", ";
if (DB_NAME == 'mysql') {
$sql .= "`long`=".$connection->quote($long)." ";
} else {
$sql .= "long=".$connection->quote($long)." ";
}
$sql .= "WHERE ";
$sql .= "domain=".$connection->quote($domain);
......
CREATE TABLE pods (
id bigint UNIQUE PRIMARY KEY,
domain varchar(50) UNIQUE NOT NULL,
name varchar(50),
score int DEFAULT 10,
adminrating decimal DEFAULT 10,
userrating decimal DEFAULT 10,
whois varchar(50),
hidden varchar(10) DEFAULT 'yes',
ip varchar(50),
ptr varchar(50),
country varchar(50),
city varchar(50),
state varchar(50),
lat varchar(50),
`long` varchar(50),
connection varchar(50),
postalcode varchar(50),
email varchar(50),
ipv6 varchar(50),
secure varchar(50),
sslvalid varchar(50),
Hgitdate varchar(50),
Hgitref varchar(50),
Hruntime varchar(50),
Hencoding varchar(50),
pingdomurl varchar(50),
pingdomlast varchar(50),
monthsmonitored int,
signup int,
total_users int,
active_users_halfyear int,
active_users_monthly int,
local_posts int,
uptimelast7 numeric(5,2),
status varchar(50),
responsetimelast7 varchar(50),
dateUpdated datetime,
dateLaststats datetime,
dateCreated datetime
);
CREATE TABLE rating_comments (
id bigint UNIQUE PRIMARY KEY,
domain varchar(50) NOT NULL,
comment varchar(50),
admin varchar(50),
pod_id int,
rating int,
username varchar(50),
userurl varchar(50),
date datetime
);
CREATE TABLE users (
id bigint UNIQUE PRIMARY KEY,
admin int NOT NULL,
username varchar(50) UNIQUE NOT NULL,
password varchar(50) NOT NULL,
userurl varchar(50),
userpod varchar(50),
dateCreated datetime
);
CREATE TABLE IF NOT EXISTS `pods` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`domain` varchar(100) NOT NULL,
`name` varchar(100) DEFAULT NULL,
`score` tinyint(3) unsigned DEFAULT '10',
`adminrating` decimal(4,2) DEFAULT '10.00',
`userrating` decimal(4,2) DEFAULT '10.00',
`whois` varchar(50) DEFAULT NULL,
`hidden` varchar(3) DEFAULT 'yes',
`ip` varchar(50) DEFAULT NULL,
`country` varchar(50) DEFAULT NULL,
`city` varchar(50) DEFAULT NULL,
`state` varchar(50) DEFAULT NULL,
`lat` varchar(50) DEFAULT NULL,
`long` varchar(50) DEFAULT NULL,
`connection` varchar(50) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
`ipv6` varchar(50) DEFAULT NULL,
`secure` varchar(50) DEFAULT NULL,
`sslvalid` varchar(50) DEFAULT NULL,
`Hgitdate` datetime DEFAULT NULL,
`Hgitref` varchar(50) DEFAULT NULL,
`Hruntime` varchar(50) DEFAULT NULL,
`Hencoding` varchar(50) DEFAULT NULL,
`pingdomurl` varchar(50) DEFAULT NULL,
`pingdomlast` varchar(50) DEFAULT NULL,
`monthsmonitored` int(11) DEFAULT NULL,
`signup` tinyint(4) DEFAULT NULL,
`total_users` int(11) DEFAULT NULL,
`active_users_halfyear` int(11) DEFAULT NULL,
`active_users_monthly` int(11) DEFAULT NULL,
`local_posts` int(11) DEFAULT NULL,
`uptimelast7` decimal(5,2) DEFAULT NULL,
`status` varchar(50) DEFAULT NULL,
`responsetimelast7` varchar(50) DEFAULT NULL,
`dateUpdated` datetime DEFAULT NULL,
`dateLaststats` datetime DEFAULT NULL,
`dateCreated` datetime DEFAULT NULL,
`longversion` varchar(20) DEFAULT NULL,
`shortversion` varchar(20) DEFAULT NULL,
`masterversion` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`),
UNIQUE KEY `domain` (`domain`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
CREATE TABLE IF NOT EXISTS `rating_comments` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`domain` varchar(50) NOT NULL,
`comment` varchar(50) DEFAULT NULL,
`admin` tinyint(1) DEFAULT '0',
`pod_id` int(11) DEFAULT NULL,
`rating` tinyint(3) unsigned DEFAULT NULL,
`username` varchar(50) DEFAULT NULL,
`userurl` varchar(50) DEFAULT NULL,
`date` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `users` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`admin` int(11) NOT NULL,
`username` varchar(50) NOT NULL,
`password` varchar(50) NOT NULL,
`userurl` varchar(50) DEFAULT NULL,
`userpod` varchar(50) DEFAULT NULL,
`dateCreated` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment