Commit 32d3cb8c authored by David Morley's avatar David Morley

all works, can do single update also. naw api work

parent 7bd78987
......@@ -6,38 +6,40 @@
die("Error in connection: " . pg_last_error());
}
//foreach pod check it and update db
$sql = "SELECT domain,pingdomurl FROM pods";
if ($_GET['domain']) {$domain=$_GET['domain'];$sql = "SELECT domain,pingdomurl FROM pods WHERE domain = '$domain'";}
else {$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)) {
echo "pod" . $row[0] . "<br />";
//curl the header of pod with and without https
while ($row = pg_fetch_all($result)) {
$numrows = pg_num_rows($result);
for ($i = 0; $i < $numrows; $i++) {
$domain = $row[$i]['domain'];
//curl the header of pod with and without https
$chss = curl_init();
curl_setopt($chss, CURLOPT_URL, "https://".$row[0]);
curl_setopt($chss, CURLOPT_URL, "https://".$domain);
curl_setopt($chss, CURLOPT_POST, 1);
curl_setopt($chss, CURLOPT_HEADER, 1);
curl_setopt($chss, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($chss, CURLOPT_NOBODY, 1);
$outputssl = curl_exec($chss);
curl_close($chss);
//echo $outputssl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://".$row[0]);
curl_setopt($ch, CURLOPT_URL, "http://".$domain);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
$output = curl_exec($ch);
curl_close($ch);
//echo $output;
if (stristr($outputssl, 'Set-Cookie: _diaspora_session=')) {
//this is a ssl pod
echo "ssl";$secure="true";$hidden="no";
//parse header data
$secure="true";$hidden="no";
preg_match('/X-Git-Update: (.*?)\n/',$outputssl,$xgitdate);
$gitdate = trim($xgitdate[1]);
preg_match('/X-Git-Revision: (.*?)\n/',$outputssl,$xgitrev);
......@@ -50,15 +52,31 @@ preg_match('/Content-Encoding: (.*?)\n/',$outputssl,$xencoding);
$encoding = trim($xencoding[1]);
} elseif (stristr($output, 'Set-Cookie: _diaspora_session=')) {
echo "not";$secure="false";$hidden="no";
"not";$secure="false";$hidden="no";
//parse header data
preg_match('/X-Git-Update: (.*?)\n/',$output,$xgitdate);
$gitdate = trim($xgitdate[1]);
preg_match('/X-Git-Revision: (.*?)\n/',$output,$xgitrev);
$gitrev = trim($xgitrev[1]);
preg_match('/X-Runtime: (.*?)\n/',$output,$xruntime);
$runtime = trim($xruntime[1]);
preg_match('/Server: (.*?)\n/',$output,$xserver);
$server = trim($xserver[1]);
preg_match('/Content-Encoding: (.*?)\n/',$output,$xencoding);
$encoding = trim($xencoding[1]);
} else {
echo "fail";$secure="false";$hidden="yes";
$secure="false";$hidden="yes";
//no diaspora cookie on either, lets set this one as hidden and notify someone its not really a pod
//could also be a ssl pod with a bad cert, I think its ok to call that a dead pod now
}
$ip = escapeshellcmd('dig +nocmd '.$row[0].' aaaa +noall +short');
$ip6 = escapeshellcmd('dig +nocmd '.$domain.' aaaa +noall +short');
$ip = escapeshellcmd('dig +nocmd '.$domain.' a +noall +short');
$ip6num = exec($ip6);
$ipnum = exec($ip);
$test = strpos($ipnum, ":");
$test = strpos($ip6num, ":");
if ($test === false) {
$ipv6="no";
} else {
......@@ -68,7 +86,7 @@ $ipv6="yes";
//curl the pingdom page
$ping = curl_init();
$thismonth = "/".date("Y")."/".date("m");
curl_setopt($ping, CURLOPT_URL, $row[1].$thismonth);
curl_setopt($ping, CURLOPT_URL, $row[$i]['pingdomurl'].$thismonth);
curl_setopt($ping, CURLOPT_POST, 0);
curl_setopt($ping, CURLOPT_HEADER, 1);
curl_setopt($ping, CURLOPT_RETURNTRANSFER, 1);
......@@ -77,7 +95,6 @@ $ipv6="yes";
curl_setopt($ping, CURLOPT_FOLLOWLOCATION, true);
$pingdom = curl_exec($ping);
curl_close($ping);
//echo $pingdom;
//response time
preg_match_all('/<h3>Avg. resp. time this month<\/h3>
......@@ -92,21 +109,24 @@ $months = count($matchdates[0]);
preg_match_all('/<h3>Uptime this month<\/h3>
<p class="large">(.*?)</',$pingdom,$matchper);
$uptime = preg_replace("/,/", ".", $matchper[1][0]);
echo $uptime;
//last check
preg_match_all('/<h3>Last checked<\/h3>
<p>(.*?)</',$pingdom,$matchdate);
$pingdom_timestamp = $matchdate[1][0];
if ($pingdom_timestamp) {
echo $pingdom_timestamp;$pingdomdate = $pingdom_timestamp;
//echo $pingdom_timestamp;
$pingdomdate = $pingdom_timestamp;
}
else {
$splitdate = explode(" ",$matchdate[1][0]);
$newtimestamp = $splitdate[0];
#$dateTime = DateTime::createFromFormat('d/m/Y H:i:s', $matchdate[1][0]);
#$newunpin = strtotime($dateTime->format('Y-m-d h:i:s a'));
echo $splitdate[0];$pingdomdate = $splitdate[0];
//echo $splitdate[0];
$pingdomdate = $splitdate[0];
}
//status
if (strpos($pingdom,"class=\"up\"")) { $live="up"; }
elseif (strpos($pingdom,"class=\"down\"")) { $live="down"; }
......@@ -116,18 +136,17 @@ else {$live="error";}
//sql it
$timenow = date('Y-m-d H:i:s');
$sql = "UPDATE pods SET Hgitdate='$gitdate', Hencoding='$encoding', secure='$secure', hidden='$hidden', Hruntime='$runtime', Hgitref='$gitrev', ip='$ipnum', ipv6='$ipv6', monthsmonitored='$months', uptimelast7='$uptime', status='$live', dateLaststats='$pingdomdate', dateUpdated='$timenow', responsetimelast7='$responsetime' WHERE domain='$row[0]'";
$sql = "UPDATE pods SET Hgitdate='$gitdate', Hencoding='$encoding', secure='$secure', hidden='$hidden', Hruntime='$runtime', Hgitref='$gitrev', ip='$ipnum', ipv6='$ipv6', monthsmonitored='$months', uptimelast7='$uptime', status='$live', dateLaststats='$pingdomdate', dateUpdated='$timenow', responsetimelast7='$responsetime' WHERE domain='$domain'";
$result = pg_query($dbh, $sql);
if (!$result) {
die("Error in SQL query: " . pg_last_error());
}
echo "Data successfully inserted!";
echo "1";
//if went ok set hidden=no else =yes
//end foreach
}
}
pg_free_result($result);
......
......@@ -13,7 +13,6 @@ od last updated from the main Diaspora code.">?</a></th>
</tr>
</thead>
<tbody>
<?php
include('config.php');
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
......@@ -26,14 +25,14 @@ od last updated from the main Diaspora code.">?</a></th>
die("Error in SQL query: " . pg_last_error());
}
while ($row = pg_fetch_array($result)) {
if ($row["secure"] == "true") {$method = "https://";} else {$method = "http://";}
echo "<tr><td class='tipsy' title='SSL Cert ".$row["sslvalid"]."'>" . $method . $row["domain"] . "</td>";
if ($row["secure"] == "true") {$method = "https://";$class="green";} else {$method = "http://";$class="red";}
echo "<tr><td class='tipsy' title='SSL Cert ".$row["sslvalid"]."'><a class='$class' target='new' href='". $method . $row["domain"] ."'>" . $method . $row["domain"] . "</a></td>";
echo "<td>" . $row["status"] . "</td>";
echo "<td class='tipsy' title='Git Revision ".$row["hgitref"]."'>" . $row["hgitdate"] . "</td>";
echo "<td>" . $row["uptimelast7"] . "</td>";
echo "<td class='tipsy' title='Last Check ".$row["dateupdated"]." '>" . $row["monthsmonitored"] . "</td>";
echo "<td class='tipsy' title='Last Check ".$row["dateupdated"]." '><a target='new' href='".$row["pingdomurl"]."'>" . $row["monthsmonitored"] . "</a></td>";
echo "<td>" . $row["responsetimelast7"] . "</td>";
echo "<td class='tipsy' title='IP Address ".$row["ip"]." '>" . $row["ipv6"] . "</td></tr>";
echo "<td class='tipsy' title='IP Address ".$row["ip"]." '>" . $row["ipv6"] . "</td></tr>\n";
}
pg_free_result($result);
pg_close($dbh);
......
......@@ -8,8 +8,10 @@ $(document).ready(function(){
$('#howto').show('slow'); $('#add').hide('slow');$('#content').hide('slow');
});
$("#myTable").tablesorter( {sortList: [[3,1], [4,1]]} );
$('#add').fadeIn(6800);
$('#others').fadeIn(2000);
$('#add').delay(8000).fadeIn(2000);
$('#others').delay(8000).fadeIn(2000);
$('#buttonsy').delay(5550).slideDown(3330);
$('#title').delay(5000).slideUp(2333);
$( ".utc-timestamp" ).each(function() {
$( this ).text( get_date( $( this ).text() ) );
});
......
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