add.php 3.22 KB
Newer Older
1
<!-- /* Copyright (c) 2011, David Morley. This file is licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file. */ -->
David Morley's avatar
David Morley committed
2
<?php
3
$valid=0;
David Morley's avatar
David Morley committed
4
 include('config.php');
5 6 7 8 9 10 11 12 13 14 15 16
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;
}
David Morley's avatar
David Morley committed
17
if (!$_POST['url']){
18 19 20
  echo "no pingdom url for your stats";
 die;
}
David Morley's avatar
David Morley committed
21
if (substr_count($_POST['url'], '/') != 4){
22 23 24
  echo "pingdom url bad, needs to look like http://stats.pingdom.com/xxxxxxxxxxx/xxxxxx";
 die;
}
25

David Morley's avatar
David Morley committed
26 27 28 29
 $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
     if (!$dbh) {
         die("Error in connection: " . pg_last_error());
     }
30 31 32 33 34 35 36 37 38 39 40 41 42 43
 $sql = "SELECT domain,pingdomurl FROM pods";
 $result = pg_query($dbh, $sql);
 if (!$result) {
     die("Error in SQL query: " . pg_last_error());
 }
 while ($row = pg_fetch_array($result)) {
if ($row["domain"] == $_POST['domain']) {
echo "domain already exists";die;
}
if ($row["pingdomurl"] == $_POST['url']) {
echo "pingdom report already exists";die;
}
 }

44 45 46
     //curl the header of pod with and without https

        $chss = curl_init();
47
        curl_setopt($chss, CURLOPT_URL, "https://".$_POST['domain']."/users/sign_in");
48 49 50 51 52 53 54 55 56
        curl_setopt($chss, CURLOPT_POST, 1);
        curl_setopt($chss, CURLOPT_HEADER, 1);
        curl_setopt($chss, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($chss, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($chss, CURLOPT_NOBODY, 1);
        $outputssl = curl_exec($chss);
        curl_close($chss);

        $ch = curl_init();
57
        curl_setopt($ch, CURLOPT_URL, "http://".$_POST['domain']."/users/sign_in");
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_NOBODY, 1);
        $output = curl_exec($ch);
        curl_close($ch);

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") {    
76
     $pingdomurl = pg_escape_string($_POST['url']);
David Morley's avatar
David Morley committed
77 78 79
     $domain = pg_escape_string($_POST['domain']);
     $email = pg_escape_string($_POST['email']);
    
80
     $sql = "INSERT INTO pods (domain, pingdomurl, email) VALUES('$domain', '$pingdomurl', '$email')";
David Morley's avatar
David Morley committed
81 82 83 84
     $result = pg_query($dbh, $sql);
     if (!$result) {
         die("Error in SQL query: " . pg_last_error());
     }
85 86 87 88 89 90
     $to = $adminemail;
     $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( $to, $subject, $message, $headers );    

91
     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.";
David Morley's avatar
David Morley committed
92 93 94 95
    
     pg_free_result($result);
    
     pg_close($dbh);
96 97 98
} else {
echo "Could not validate your pod on http or https, check your setup!";
}
David Morley's avatar
David Morley committed
99 100

?>