Commit 5c32fda5 authored by David Morley's avatar David Morley
Browse files

Merge branch 'noplanman-simple_code_cleanup'

parents 2acabfba 11dcb761
<?php <?php
//Copyright (c) 2011, David Morley. This file is licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file. //Copyright (c) 2011, David Morley. This file is licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file.
if ($_GET['key'] != "4r45tg") {die;} if ($_GET['key'] != '4r45tg') {die;}
require_once __DIR__ . '/config.php'; require_once __DIR__ . '/config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass"); $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
if (!$dbh) { if (!$dbh) {
die("Error in connection: " . pg_last_error()); die('Error in connection: ' . pg_last_error());
} }
if ($_GET['format'] == "georss") { if ($_GET['format'] == 'georss') {
echo <<<EOF echo <<<EOF
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" <feed xmlns="http://www.w3.org/2005/Atom"
xmlns:georss="http://www.georss.org/georss"> xmlns:georss="http://www.georss.org/georss">
<title>Diaspora Pods</title> <title>Diaspora Pods</title>
<subtitle>IP Locations of Diaspora pods on podupti.me</subtitle> <subtitle>IP Locations of Diaspora pods on podupti.me</subtitle>
<link href="http://podupti.me/"/> <link href="http://podupti.me/"/>
EOF; EOF;
$sql = "SELECT * FROM pods WHERE hidden <> 'yes'"; $sql = "SELECT * FROM pods WHERE hidden <> 'yes'";
$result = pg_query($dbh, $sql); $result = pg_query($dbh, $sql);
if (!$result) { if (!$result) {
die("Error in SQL query: " . pg_last_error()); die('Error in SQL query: ' . pg_last_error());
} }
$numrows = pg_num_rows($result); $numrows = pg_num_rows($result);
while ($row = pg_fetch_array($result)) { while ($row = pg_fetch_array($result)) {
$pod_name = htmlentities($row["name"], ENT_QUOTES); $pod_name = htmlentities($row['name'], ENT_QUOTES);
$tip=""; $tip = sprintf(
$tip.="\n This pod {$pod_name} has been watched for {$row["monthsmonitored"]} months and its average ping time is {$row["responsetimelast7"]} with uptime of {$row["uptimelast7"]}% this month and was last checked on {$row["dateupdated"]}. "; 'This pod %1$s has been watched for %2$s months and its average ping time is %3$s with uptime of %4$s%% this month and was last checked on %5$s. On a score of 100 this pod is a %6$s right now',
$tip.="On a score of 100 this pod is a {$row["score"]} right now"; $pod_name,
if ($row["secure"] == "true") {$method = "https://";} else {$method = "http://";} $row['monthsmonitored'],
$row['responsetimelast7'],
$row['uptimelast7'],
$row['dateupdated'],
$row['score']
);
if ($row['secure'] == 'true') {$method = 'https://';} else {$method = 'http://';}
echo <<<EOF echo <<<EOF
<entry> <entry>
<title>{$method}{$row['domain']}</title> <title>{$method}{$row['domain']}</title>
<link href="{$method}{$row['domain']}"/> <link href="{$method}{$row['domain']}"/>
<id>urn:{$row['domain']}</id> <id>urn:{$row['domain']}</id>
<summary>Pod Location is: {$row['country']} <summary>Pod Location is: {$row['country']}
&#xA;{$tip}</summary> &#xA;
<georss:point>{$row['lat']} {$row['long']}</georss:point> {$tip}</summary>
<georss:featureName>{$row['domain']}</georss:featureName> <georss:point>{$row['lat']} {$row['long']}</georss:point>
</entry> <georss:featureName>{$row['domain']}</georss:featureName>
</entry>
EOF; EOF;
} }
echo "</feed>"; echo '</feed>';
} }
elseif ($_GET['format'] == "json") { elseif ($_GET['format'] == 'json') {
$sql = "SELECT id,domain,status,secure,score,userrating,adminrating,city,state,country,lat,long,ip,ipv6,pingdomurl,monthsmonitored,uptimelast7,responsetimelast7,local_posts,comment_counts,dateCreated,dateUpdated,dateLaststats,hidden FROM pods"; $sql = 'SELECT id,domain,status,secure,score,userrating,adminrating,city,state,country,lat,long,ip,ipv6,pingdomurl,monthsmonitored,uptimelast7,responsetimelast7,local_posts,comment_counts,dateCreated,dateUpdated,dateLaststats,hidden FROM pods';
$result = pg_query($dbh, $sql); $result = pg_query($dbh, $sql);
if (!$result) { if (!$result) {
die("Error in SQL query: " . pg_last_error()); die('Error in SQL query: ' . pg_last_error());
} }
$numrows = pg_num_rows($result); $numrows = pg_num_rows($result);
//json output, thx Vipul A M for fixing this //json output, thx Vipul A M for fixing this
...@@ -57,7 +64,7 @@ elseif ($_GET['format'] == "json") { ...@@ -57,7 +64,7 @@ elseif ($_GET['format'] == "json") {
$rows=array_values(pg_fetch_all($result)); $rows=array_values(pg_fetch_all($result));
$obj->podcount = $numrows; $obj->podcount = $numrows;
$obj->pods = $rows; $obj->pods = $rows;
if ($_GET['method'] == "jsonp") { if ($_GET['method'] == 'jsonp') {
print $_GET['callback'] . '(' . json_encode($obj) . ')'; print $_GET['callback'] . '(' . json_encode($obj) . ')';
} else { } else {
print json_encode($obj); print json_encode($obj);
...@@ -68,15 +75,15 @@ elseif ($_GET['format'] == "json") { ...@@ -68,15 +75,15 @@ elseif ($_GET['format'] == "json") {
$sql = "SELECT * FROM pods WHERE hidden <> 'yes' ORDER BY uptimelast7 DESC"; $sql = "SELECT * FROM pods WHERE hidden <> 'yes' ORDER BY uptimelast7 DESC";
$result = pg_query($dbh, $sql); $result = pg_query($dbh, $sql);
if (!$result) { if (!$result) {
die("Error in SQL query: " . pg_last_error()); die('Error in SQL query: ' . pg_last_error());
} }
$numrows = pg_num_rows($result); $numrows = pg_num_rows($result);
while ($row = pg_fetch_array($result)) { while ($row = pg_fetch_array($result)) {
if ($row["status"] == "up"){$status="Online";} else {$status="Offline";} if ($row['status'] == 'up'){$status = 'Online';} else {$status = 'Offline';}
if ($row["secure"] == "true") {$method = "https://";$class="green";} else {$method = "http://";$class="red";} if ($row['secure'] == 'true') {$method = 'https://';$class = 'green';} else {$method = 'http://';$class = 'red';}
echo $row["domain"] ." Up ".$row["uptimelast7"]."% This Month - Located in: ".$row["country"]; echo $row['domain'] . ' Up ' . $row['uptimelast7'] . '% This Month - Located in: ' . $row['country'];
if ($i < ($numrows -1)) { if ($i < ($numrows -1)) {
echo ","; echo ',';
} }
$i++; $i++;
...@@ -85,4 +92,3 @@ elseif ($_GET['format'] == "json") { ...@@ -85,4 +92,3 @@ elseif ($_GET['format'] == "json") {
pg_free_result($result); pg_free_result($result);
pg_close($dbh); pg_close($dbh);
} }
?>
...@@ -4,20 +4,17 @@ require_once __DIR__ . '/config.php'; ...@@ -4,20 +4,17 @@ require_once __DIR__ . '/config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass"); $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
if (!$dbh) { if (!$dbh) {
die("Error in connection: " . pg_last_error()); die('Error in connection: ' . pg_last_error());
} }
$sql = "SELECT * FROM pods WHERE hidden <> 'no' AND score < 50 ORDER BY weightedscore"; $sql = "SELECT * FROM pods WHERE hidden <> 'no' AND score < 50 ORDER BY weightedscore";
$result = pg_query($dbh, $sql); $result = pg_query($dbh, $sql);
if (!$result) { if (!$result) {
die("Error in SQL query: " . pg_last_error()); die('Error in SQL query: ' . pg_last_error());
} }
$numrows = pg_num_rows($result); $numrows = pg_num_rows($result);
echo "<meta property='og:title' content='";
echo $numrows;
echo " #Diaspora Pods listed, Come see the privacy aware social network.' />";
echo $numrows;
?> ?>
pods that are open for signup now.
<meta property="og:title" content="<?php echo $numrows; ?> #Diaspora Pods listed, Come see the privacy aware social network." /><?php echo $numrows; ?> pods that are open for signup now.
<meta charset="utf-8"> <meta charset="utf-8">
<!-- /* Copyright (c) 2011, David Morley. This file is licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file. */ --> <!-- /* Copyright (c) 2011, David Morley. This file is licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file. */ -->
<table id="myTable" class="table table-striped table-sm tablesorter table-hover tfont"> <table id="myTable" class="table table-striped table-sm tablesorter table-hover tfont">
...@@ -25,7 +22,7 @@ echo $numrows; ...@@ -25,7 +22,7 @@ echo $numrows;
<tr> <tr>
<th>Pod<a class="tipsy" title="A pod is a site for you to set up your account.">?</a></th> <th>Pod<a class="tipsy" title="A pod is a site for you to set up your account.">?</a></th>
<th>Version<a class="tipsy" title="Version of Diaspora this pod runs">?</a></th> <th>Version<a class="tipsy" title="Version of Diaspora this pod runs">?</a></th>
<th>Uptime<a class="tipsy" title="Percent of the time the pod is online for <?php echo date("F") ?>.">?</a></th> <th>Uptime<a class="tipsy" title="Percent of the time the pod is online for <?php echo date('F') ?>.">?</a></th>
<th>ms</th> <th>ms</th>
<th>Signups</th> <th>Signups</th>
<th>Total<a class="tipsy" title="Number of total users on this pod.">?</a></th> <th>Total<a class="tipsy" title="Number of total users on this pod.">?</a></th>
...@@ -43,61 +40,68 @@ echo $numrows; ...@@ -43,61 +40,68 @@ echo $numrows;
<?php <?php
while ($row = pg_fetch_array($result)) { while ($row = pg_fetch_array($result)) {
$tt=$tt+1; $tt=$tt+1;
if ($row["secure"] == "true") { if ($row['secure'] == 'true') {
$method = "https://"; $method = 'https://';
$class="green"; $class= 'green';
$tip="This pod uses SSL encryption for traffic.";} $tip= 'This pod uses SSL encryption for traffic.';}
else { else {
$method = "http://"; $method = 'http://';
$class="red"; $class= 'red';
$tip="This pod does not offer SSL"; $tip= 'This pod does not offer SSL';
} }
$verdiff = str_replace(".", "", $row["masterversion"]) - str_replace('.', '', $row["shortversion"]); $verdiff = str_replace('.', '', $row['masterversion']) - str_replace('.', '', $row['shortversion']);
$pod_name = htmlentities($row["name"], ENT_QUOTES); $pod_name = htmlentities($row['name'], ENT_QUOTES);
$tip.="\n This pod {$pod_name} has been watched for {$row["monthsmonitored"]} months and its average ping time is {$row["responsetimelast7"]} with uptime of {$row["uptimelast7"]}% this month and was last checked on {$row["dateupdated"]}. "; $tip .= sprintf(
$tip.="On a score of -20 to +20 this pod is a {$row["score"]} right now"; "\n" . 'This pod %1$s has been watched for %2$s months and its average ping time is %3$s with uptime of %4$s%% this month and was last checked on %5$s. On a score of -20 to +20 this pod is a %6$s right now',
$pod_name,
$row['monthsmonitored'],
$row['responsetimelast7'],
$row['uptimelast7'],
$row['dateupdated'],
$row['score']
);
echo "<tr><td><a class='$class' target='new' href='". $method . $row["domain"] ."'>" . $row["domain"] . " <div title='$tip' class='tipsy' style='display: inline-block'>?</div></a></td>"; echo '<tr><td><a class="' . $class . '" target="_self" href="' . $method . $row['domain'] . '">' . $row['domain'] . '<div title="' . $tip . '" class="tipsy" style="display: inline-block">?</div></a></td>';
"</div></td>";
if (stristr($row["shortversion"],'head')) if (stristr($row['shortversion'],'head'))
{$version=".dev";$pre = "This pod runs pre release {$version = '.dev';$pre = 'This pod runs pre release
development code";} elseif (!$row["shortversion"]) development code';} elseif (!$row['shortversion'])
{$version="0";$pre = "This pod runs {$version = '0';$pre = 'This pod runs
unknown code";} unknown code';}
else else
{$version=$row["shortversion"];$pre="This pod runs production code";} {$version =$row['shortversion'];$pre = 'This pod runs production code';}
if ($row["shortversion"] == $row["masterversion"] && $row["shortversion"] != "") {$classver = "green";} elseif ($verdiff > 6) {$classver = "red";} else {$classver = "black";} if ($row['shortversion'] == $row['masterversion'] && $row['shortversion'] != '') {$classver = 'green';} elseif ($verdiff > 6) {$classver = 'red';} else {$classver = 'black';}
echo "<td class='$classver'><div title='{$pre} codename: {$row["longversion"]} master version is: {$row["masterversion"]}' class='tipsy'>{$version}</div></td>"; echo '<td class="' . $classver . '"><div title="' . $pre . ' codename: ' . $row['longversion'] . ' master version is: ' . $row['masterversion'] . '" class="tipsy">' . $version . '</div></td>';
echo "<td>" . $row["uptimelast7"] . "</td>"; echo '<td>' . $row['uptimelast7'] . '</td>';
echo "<td>" . $row["responsetimelast7"] . "</td>"; echo '<td>' . $row['responsetimelast7'] . '</td>';
if ($row["signup"] == 1) {$signup="Open";} else {$signup="Closed";} if ($row['signup'] == 1) {$signup = 'Open';} else {$signup = 'Closed';}
echo "<td>" . $signup . "</td>"; echo '<td>' . $signup . '</td>';
echo "<td>" . $row["total_users"] . "</td>"; echo '<td>' . $row['total_users'] . '</td>';
echo "<td>" . $row["active_users_halfyear"] . "</td>"; echo '<td>' . $row['active_users_halfyear'] . '</td>';
echo "<td>" . $row["active_users_monthly"] . "</td>"; echo '<td>' . $row['active_users_monthly'] . '</td>';
echo "<td>" . $row["local_posts"] . "</td>"; echo '<td>' . $row['local_posts'] . '</td>';
echo "<td>" . $row["comment_counts"] . "</td>"; echo '<td>' . $row['comment_counts'] . '</td>';
if (strpos($row["pingdomurl"], "pingdom.com")) {$moreurl = $row["pingdomurl"];} else {$moreurl = "http://api.uptimerobot.com/getMonitors?format=json&customUptimeRatio=7-30-60-90&apiKey=".$row["pingdomurl"];} if (strpos($row['pingdomurl'],
echo "<td><div title='Last Check ".$row["dateupdated"]."' class='tipsy'><a target='new' href='".$moreurl."'>" . $row["monthsmonitored"] . "</a></div></td>"; 'pingdom.com')) {$moreurl = $row['pingdomurl'];} else {$moreurl = 'http://api.uptimerobot.com/getMonitors?format=json&customUptimeRatio=7-30-60-90&apiKey=' . $row['pingdomurl'];}
echo "<td>" . $row["score"] . "</td>\n"; echo '<td><div title="Last Check ' . $row['dateupdated'] . '" class="tipsy"><a target="_self" href="' . $moreurl . '">' . $row['monthsmonitored'] . '</a></div></td>';
echo "<td><div class='tipsy' title='".$row["sslvalid"]."'>con info </td>\n"; echo '<td>' . $row['score'] . '</td>';
echo '<td><div class="tipsy" title="' . $row['sslvalid'] . '">con info </td>';
?> ?>
<td> <td>
<form method="post" action="db/kill.php" target="_blank"> <form method="post" action="db/kill.php" target="_blank">
<input name="comments" value="<?php echo $row["sslvalid"] ?>" size=10> <input name="comments" value="<?php echo $row['sslvalid']; ?>" size=10>
<input name="domain" value="<?php echo $row["domain"] ?>" type="hidden"> <input name="domain" value="<?php echo $row['domain']; ?>" type="hidden">
<input name="adminkey" value="<?php echo $_COOKIE["adminkey"] ?>" type="hidden"> <input name="adminkey" value="<?php echo $_COOKIE['adminkey']; ?>" type="hidden">
<input name="action" type="radio" value="warn">warn <input name="action" type="radio" value="warn">warn
<input name="action" type="radio" value="delete">delete <input name="action" type="radio" value="delete">delete
<input type="submit" value="Process"> <input type="submit" value="Process">
</form> </form>
</td> </td>
<?php <?php
echo "</td></tr>\n"; echo '</td></tr>';
} }
pg_free_result($result); pg_free_result($result);
pg_close($dbh); pg_close($dbh);
......
...@@ -4,51 +4,53 @@ $valid=0; ...@@ -4,51 +4,53 @@ $valid=0;
require_once __DIR__ . '/../logging.php'; require_once __DIR__ . '/../logging.php';
$log = new Logging(); $log = new Logging();
$log->lfile($log_dir."/add.php.log"); $log->lfile($log_dir . '/add.php.log');
if (!$_POST['url']){ if (!$_POST['url']){
echo "no url given";$log->lwrite('no url given '.$_POST['domain']); $log->lwrite('no url given '.$_POST['domain']);
die; die('no url given');
} }
if (!$_POST['email']){ if (!$_POST['email']){
echo "no email given";$log->lwrite('no email given '.$_POST['domain']); $log->lwrite('no email given '.$_POST['domain']);
die; die('no email given');
} }
if (!$_POST['domain']){ if (!$_POST['domain']){
echo "no pod domain given";$log->lwrite('no domain given '.$_POST['domain']); $log->lwrite('no domain given '.$_POST['domain']);
die; die('no pod domain given');
} }
if (!$_POST['url']){ if (!$_POST['url']){
echo "no API key for your stats";$log->lwrite('no api given '.$_POST['domain']); $log->lwrite('no api given '.$_POST['domain']);
die; die('no API key for your stats');
} }
if (strlen($_POST['url']) < 14){ if (strlen($_POST['url']) < 14){
echo "API key bad needs to be like m58978-80abdb799f6ccf15e3e3787ee";$log->lwrite('api key too short '.$_POST['domain']); $log->lwrite('api key too short '.$_POST['domain']);
die; die('API key bad needs to be like m58978-80abdb799f6ccf15e3e3787ee');
} }
require_once __DIR__ . '/../config.php'; require_once __DIR__ . '/../config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass"); $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
if (!$dbh) { if (!$dbh) {
die("Error in connection: " . pg_last_error()); die('Error in connection: ' . pg_last_error());
} }
$sql = "SELECT domain,pingdomurl FROM pods"; $sql = 'SELECT domain,pingdomurl FROM pods';
$result = pg_query($dbh, $sql); $result = pg_query($dbh, $sql);
if (!$result) { if (!$result) {
die("Error in SQL query: " . pg_last_error()); die('Error in SQL query: ' . pg_last_error());
} }
while ($row = pg_fetch_array($result)) { while ($row = pg_fetch_array($result)) {
if ($row["domain"] == $_POST['domain']) { if ($row['domain'] == $_POST['domain']) {
echo "domain already exists";$log->lwrite('domain already exists '.$_POST['domain']);die; $log->lwrite('domain already exists '.$_POST['domain']);
die('domain already exists');
} }
if ($row["pingdomurl"] == $_POST['url']) { if ($row['pingdomurl'] == $_POST['url']) {
echo "API key already exists";$log->lwrite('API key already exists '.$_POST['domain']);die; $log->lwrite('API key already exists '.$_POST['domain']);
die('API key already exists');
} }
} }
//curl the header of pod with and without https //curl the header of pod with and without https
$chss = curl_init(); $chss = curl_init();
curl_setopt($chss, CURLOPT_URL, "https://".$_POST['domain']."/nodeinfo/1.0"); curl_setopt($chss, CURLOPT_URL, 'https://' . $_POST['domain'] . '/nodeinfo/1.0');
curl_setopt($chss, CURLOPT_POST, 0); curl_setopt($chss, CURLOPT_POST, 0);
curl_setopt($chss, CURLOPT_HEADER, 0); curl_setopt($chss, CURLOPT_HEADER, 0);
curl_setopt($chss, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($chss, CURLOPT_CONNECTTIMEOUT, 5);
...@@ -58,7 +60,7 @@ $outputssl = curl_exec($chss); ...@@ -58,7 +60,7 @@ $outputssl = curl_exec($chss);
curl_close($chss); curl_close($chss);
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://".$_POST['domain']."/nodeinfo/1.0"); curl_setopt($ch, CURLOPT_URL, 'http://' . $_POST['domain'] . '/nodeinfo/1.0');
curl_setopt($ch, CURLOPT_POST, 0); curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
...@@ -68,34 +70,41 @@ $output = curl_exec($ch); ...@@ -68,34 +70,41 @@ $output = curl_exec($ch);
curl_close($ch); curl_close($ch);
if (stristr($outputssl, 'nodeName')) { if (stristr($outputssl, 'nodeName')) {
echo "Your pod has ssl and is valid<br>";$log->lwrite('Your pod has ssl and is valid '.$_POST['domain']); $log->lwrite('Your pod has ssl and is valid '.$_POST['domain']);
echo 'Your pod has ssl and is valid<br>';
$valid=1; $valid=1;
} }
if (stristr($output, 'nodeName')) { if (stristr($output, 'nodeName')) {
echo "Your pod does not have ssl but is a valid pod<br>";$log->lwrite('Your pod does not have ssl but is a valid pod '.$_POST['domain']); $log->lwrite('Your pod does not have ssl but is a valid pod '.$_POST['domain']);
echo 'Your pod does not have ssl but is a valid pod<br>';
$valid=1; $valid=1;
} }
if ($valid=="1") { if ($valid == '1') {
$sql = "INSERT INTO pods (domain, pingdomurl, email) VALUES($1, $2, $3)"; $sql = "INSERT INTO pods (domain, pingdomurl, email) VALUES($1, $2, $3)";
$result = pg_query_params($dbh, $sql, array($_POST['domain'], $_POST['url'], $_POST['email'])); $result = pg_query_params($dbh, $sql, array($_POST['domain'], $_POST['url'], $_POST['email']));
if (!$result) { if (!$result) {
die("Error in SQL query: " . pg_last_error()); die('Error in SQL query: ' . pg_last_error());
} }
$to = $adminemail; $to = $adminemail;
$cc = $_POST["email"]; $cc = $_POST['email'];
$subject = "New pod added to podupti.me "; $subject = 'New pod added to podupti.me ';
$message.= "https://podupti.me\n\n Stats Url: https://api.uptimerobot.com/getMonitors?format=json&customUptimeRatio=7-30-60-90&apiKey=" . $_POST["url"] . "\n\n Pod: https://podupti.me/db/pull.php?debug=1&domain=" . $_POST["domain"] . "\n\n"; $message.= sprintf(
$message.= "Your pod will not show right away, needs to pass a few checks, Give it a few hours!"; "%1$s\n\n Stats Url: %2$s\n\n Pod: %3$s\n\n",
$headers = "From: ".$_POST["email"]."\r\nReply-To: ".$_POST["email"]."\r\nCc: " . $_POST["email"] . "\r\n"; 'https://podupti.me',
'https://api.uptimerobot.com/getMonitors?format=json&customUptimeRatio=7-30-60-90&apiKey=' . $_POST['url'],
'https://podupti.me/db/pull.php?debug=1&domain=' . $_POST['domain']
);
$message.= 'Your pod will not show right away, needs to pass a few checks, Give it a few hours!';
$headers = 'From: ' . $_POST['email'] . "\r\nReply-To: " . $_POST['email'] . "\r\nCc: " . $_POST['email'] . "\r\n";
@mail( $to, $subject, $message, $headers ); @mail( $to, $subject, $message, $headers );
echo "Data successfully inserted! Your pod will be reviewed and live on the list in a few hours!"; echo 'Data successfully inserted! Your pod will be reviewed and live on the list in a few hours!';
pg_free_result($result); pg_free_result($result);
pg_close($dbh); pg_close($dbh);
} else { } else {
echo "Could not validate your pod on http or https, check your setup!<br>Take a look at <a href='https://".$_POST['domain']."/nodeinfo/1.0'>your /nodeinfo</a>";$log->lwrite('Could not validate your pod on http or https, check your setup! '.$_POST['domain']); $log->lwrite('Could not validate your pod on http or https, check your setup! ' . $_POST['domain']);
echo 'Could not validate your pod on http or https, check your setup!<br>Take a look at <a href="https://' . $_POST['domain'] . '/nodeinfo/1.0">your /nodeinfo</a>';
} }
$log->lclose(); $log->lclose();
?>
...@@ -5,28 +5,27 @@ require_once __DIR__ . '/../config.php'; ...@@ -5,28 +5,27 @@ require_once __DIR__ . '/../config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass"); $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
if (!$dbh) { if (!$dbh) {
die("Error in connection: " . pg_last_error()); die('Error in connection: ' . pg_last_error());
} }
$sql = "SELECT id,domain,status,secure,score,userrating,adminrating,city,state,country,lat,long,ip,ipv6,pingdomurl,monthsmonitored,uptimelast7,responsetimelast7,local_posts,comment_counts,dateCreated,dateUpdated,dateLaststats,hidden FROM pods WHERE domain = $1"; $sql = "SELECT id,domain,status,secure,score,userrating,adminrating,city,state,country,lat,long,ip,ipv6,pingdomurl,monthsmonitored,uptimelast7,responsetimelast7,local_posts,comment_counts,dateCreated,dateUpdated,dateLaststats,hidden FROM pods WHERE domain = $1";
$result = pg_query_params($dbh, $sql, array($_GET['url'])); $result = pg_query_params($dbh, $sql, array($_GET['url']));
if (!$result) { if (!$result) {
die("Error in SQL query: " . pg_last_error()); die('Error in SQL query: ' . pg_last_error());
} }
while ($row = pg_fetch_array($result)) { while ($row = pg_fetch_array($result)) {
if ($_GET['format'] == "json") { if ($_GET['format'] == 'json') {
echo json_encode($row); echo json_encode($row);
} else { } else {
echo "Status: " . $row["status"] . "<br>"; echo 'Status: ' . $row['status'] . '<br>';
echo "Last Git Pull: " . $row["hgitdate"] . "<br>"; echo 'Last Git Pull: ' . $row['hgitdate'] . '<br>';
echo "Uptime This Month " . $row["uptimelast7"] . "<br>"; echo 'Uptime This Month ' . $row['uptimelast7'] . '<br>';
echo "Months Monitored: " . $row["monthsmonitored"] . "<br>"; echo 'Months Monitored: ' . $row['monthsmonitored'] . '<br>';
echo "Response Time: " . $row["responsetimelast7"] . "<br>"; echo 'Response Time: ' . $row['responsetimelast7'] . '<br>';
echo "User Rating: ". $row["userrating"] . "<br>"; echo 'User Rating: ' . $row['userrating'] . '<br>';
echo "Server Location: ". $row["country"] . "<br>"; echo 'Server Location: ' . $row['country'] . '<br>';
echo "Latitude: ". $row["lat"] . "<br>"; echo 'Latitude: ' . $row['lat'] . '<br>';
echo "Longitude: ". $row["long"] . "<br>"; echo 'Longitude: ' . $row['long'] . '<br>';
} }
} }
pg_free_result($result); pg_free_result($result);
pg_close($dbh); pg_close($dbh);
?>
...@@ -2,18 +2,17 @@ ...@@ -2,18 +2,17 @@
require_once __DIR__ . '/../config.php'; require_once __DIR__ . '/../config.php';
$keep = (60 * 60 * 6) * 1; $keep = (60 * 60 * 6) * 1;
$dump_date = date("Ymd_Hs"); $dump_date = date('Ymd_Hs');
$file_name = $backup_dir . "/dump_" . $dump_date . ".sql"; $file_name = $backup_dir . '/dump_' . $dump_date . '.sql';
system("export PGPASSWORD=$pgpass && $pg_dump_dir/pg_dump --username=$pguser $pgdb >> $file_name"); system("export PGPASSWORD=$pgpass && $pg_dump_dir/pg_dump --username=$pguser $pgdb >> $file_name");
echo "pg backup of $pgdb made"; echo "pg backup of $pgdb made";
$dirh = dir($backup_dir); $dirh = dir($backup_dir);
while($entry = $dirh->read()) { while($entry = $dirh->read()) {
$old_file_time = (date("U") - $keep); $old_file_time = (date('U') - $keep);
$file_created = filectime("$backup_dir/$entry"); $file_created = filectime("$backup_dir/$entry");
if ($file_created < $old_file_time && !is_dir($entry)) { if ($file_created < $old_file_time && !is_dir($entry)) {
if(unlink("$backup_dir/$entry")) { if(unlink("$backup_dir/$entry")) {
echo "Cleaned up old backups"; echo 'Cleaned up old backups';
} }
} }
} }
?>
<?php <?php
if (!$_GET['domain']){ if (!$_GET['domain']){
echo "no pod domain given";