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

MatrixCrawler's avatar
MatrixCrawler committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
require_once 'config.inc.php';
require_once 'db.class.php';
require_once 'pull.class.php';

$valid = 0;
if (! $_POST ['url']) {
	echo "no url given";
	die ();
}
if (! $_POST ['email']) {
	echo "no email given";
	die ();
}
if (! $_POST ['domain']) {
	echo "no pod domain given";
	die ();
}
if (! $_POST ['url']) {
	echo "no API key for your stats";
	die ();
}
if (strlen ( $_POST ['url'] ) < 14) {
	echo "API key bad needs to be like m58978-80abdb799f6ccf15e3e3787ee";
	die ();
}
33

MatrixCrawler's avatar
MatrixCrawler committed
34 35 36 37 38
$dbConnection = DB::connectDB();
if (!$dbConnection) {
	die ( "Error in connection: " . $dbConnection->errorInfo()[2] );
}
$sql = "SELECT domain,pingdomurl FROM pods";
39

MatrixCrawler's avatar
MatrixCrawler committed
40 41 42
$result = $dbConnection->query($sql);
if (! $result) {
	die ( "Error in SQL query: " . $dbConnection->errorInfo()[2] );
43
}
David Morley's avatar
David Morley committed
44

MatrixCrawler's avatar
MatrixCrawler committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
foreach ($result->fetchAll() as $row) {
	if ($row ["domain"] == $_POST ['domain']) {
		echo "domain already exists";
		die ();
	}
	if ($row ["pingdomurl"] == $_POST ['url']) {
		echo "API key already exists";
		die ();
	}
}

// curl the header of pod with and without https
$outputssl = Pull::getCurlResult("https://" . $_POST ['domain'] . "/users/sign_in");
$output = Pull::getCurlResult("http://" . $_POST ['domain'] . "/users/sign_in");

if (stristr ( $outputssl, 'Set-Cookie: _diaspora_session=' )) {
	echo "Your pod has ssl and is valid<br>";
	$valid = 1;
}
if (stristr ( $output, 'Set-Cookie: _diaspora_session=' )) {
	echo "Your pod does not have ssl but is a valid pod<br>";
	$valid = 1;
}

if ($valid == "1") {
	$sql = "INSERT INTO pods (domain, pingdomurl, email) VALUES(".$dbConnection->quote($_POST['domain']).", ".$dbConnection->quote($_POST['url']).", ".$dbConnection->quote($_POST['email']).")";
	$result = $dbConnection->query($sql);
	if (! $result) {
		die ( "Error in SQL query: " . $dbConnection->errorInfo()[2]);
	}
	$subject = "New pod added to poduptime ";
	$message = "http://podupti.me\n\n Pingdom Url:" . $_POST ["url"] . "\n\n Pod:" . $_POST ["domain"] . "\n\n";
	$headers = "From: " . $_POST ["email"] . "\r\nReply-To: " . $_POST ["email"] . "\r\n";
	@mail ( ADMIN_EMAIL, $subject, $message, $headers );
	
	echo "Data successfully inserted! Your pod will be reviewed and live on the list soon! You will get a support ticket, no need to do anything if your pod is listed in the next few hours.";
	
} else {
	echo "Could not validate your pod on http or https, check your setup!";
}

86
?>