Unverified Commit d862e510 authored by David Morley's avatar David Morley Committed by GitHub

fix pull again (#191)

parent 011676c7
......@@ -21,6 +21,7 @@ use RedBeanPHP\R;
$debug = isset($_GET['debug']) || (isset($argv) && in_array('debug', $argv, true));
$sqldebug = isset($_GET['sqldebug']) || (isset($argv) && in_array('sqldebug', $argv, true));
$develop = isset($_GET['develop']) || (isset($argv) && in_array('develop', $argv, true));
$write = !(isset($_GET['nowrite']) || (isset($argv) && in_array('nowrite', $argv, true)));
$newline = PHP_SAPI === 'cli' ? "\n\n" : '<br><br>';
......@@ -36,11 +37,10 @@ define('PODUPTIME', microtime(true));
// Set up global DB connection.
R::setup("pgsql:host={$pghost};dbname={$pgdb}", $pguser, $pgpass, true);
$sqldebug && R::fancyDebug(true);
$sqldebug && R::debug(true);
R::testConnection() || die('Error in DB connection');
R::usePartialBeans(true);
try {
// Setup GeoIP Database
$reader = new Reader($geoip2db);
......@@ -51,6 +51,7 @@ try {
';
$pods = [];
if ($_domain) {
$sql .= ' WHERE domain = ?';
$pods = R::getAll($sql, [$_domain]);
......@@ -91,6 +92,7 @@ foreach ($pods as $pod) {
_debug('Domain', $domain);
$user_rating = 0;
if ($user_ratings = array_column($ratings, 'rating')) {
$user_rating = round(array_sum($user_ratings) / count($user_ratings), 2);
}
......@@ -167,6 +169,7 @@ foreach ($pods as $pod) {
$c['comment_counts'] = $comment_counts;
$c['shortversion'] = $shortversion;
$c['version'] = $version;
if ($write) {
R::store($c);
} else {
......@@ -193,7 +196,9 @@ foreach ($pods as $pod) {
$masterversion = ($masterdata['version'] ?? '0.0.0.0');
$devlastcommit = ($masterdata['devlastcommit'] ?? date('Y-m-d H:i:s'));
$releasedate = ($masterdata['releasedate'] ?? date('Y-m-d H:i:s'));
_debug('Masterversion', $masterversion);
$masterversioncheck = explode('.', $masterversion);
$shortversioncheck = (strpos($shortversion, '.') ? explode('.', $shortversion) : implode('.', ['0', preg_replace('/\D/', '', $shortversion), '0']));
//this is still off with a pod with v1 as total version. cant explode that, won't have a [0] or [1] later to use either
......@@ -217,45 +222,57 @@ foreach ($pods as $pod) {
$devlastdays = $devlastcommit ? date_diff(new DateTime($devlastcommit), new DateTime())->format('%a') : 30;//tmp//if no dev branch then what?
_debug('Dev last commit was ', $devlastdays);
$updategap = date_diff(new DateTime($lastdatechecked), new DateTime($devlastcommit))->format('%a');
if (strpos($version, 'dev') !== false || strpos($version, 'rc') !== false || $shortversioncheck > $masterversioncheck) {
//tmp//if pod is on the development branch - see when you last updated your pod and when the last commit was made to dev branch - if the repo is active and your not updating every 120 days why are you on dev branch?
if ($updategap + $devlastdays > 400) {
_debug('Outdated', 'Yes');
_debug('Outdated More than 400 days', 'Yes');
$score -= 2;
}
} elseif (($masterversioncheck[1] - $shortversioncheck[1]) > 1) {
///tmp/If pod is two versions off AND it's been more than 60 days since that release came out AND your on the master production branch
_debug('Outdated', 'Yes');
_debug('Outdated second decimal > 1', 'Yes');
$score -= 2;
$updategap = date_diff(new DateTime($lastdatechecked), new DateTime($releasedate))->format('%a');
} elseif ($updategap - date_diff(new DateTime($releasedate), new DateTime())->format('%a') > 90) {
_debug('Outdated', 'Yes');
} elseif ($updategap - date_diff(new DateTime($releasedate), new DateTime())->format('%a') > 400) {
_debug('Outdated more than 400 days since x ', 'Yes');
$score -= 2;
$updategap = date_diff(new DateTime($lastdatechecked), new DateTime($releasedate))->format('%a');
} else {
$updategap = date_diff(new DateTime($lastdatechecked), new DateTime($releasedate))->format('%a');
}
_debug('Pod code was updated after ', $updategap);
$d = new DOMDocument;
libxml_use_internal_errors(true);
$d->loadHTMLFile('https://' . $domain);
$body = $d->getElementsByTagName('body')->item(0);
if ($body->nodeValue) {
$ld = new Language;
$detectedlanguage = strtoupper(key($ld->detect($body->nodeValue)->bestResults()->close()));
_debug('Detected Language', $detectedlanguage);
} else {
$score -= 1;
}
_debug('Pod code was updated after ', $updategap);
$status = PodStatus::UP;
}
if (!$jsonssl && !$body) {
$d = new DOMDocument;
libxml_use_internal_errors(true);
$d->loadHTMLFile('https://' . $domain);
$body = $d->getElementsByTagName('html')->item(0);
if ($body) {
$ld = new Language;
$detectedlanguage = strtoupper(key($ld->detect($body->nodeValue)->bestResults()->close()));
} else {
$score -= 1;
$detectedlanguage = null;
}
_debug('Detected Language', $detectedlanguage);
if (!$jsonssl || !$body) {
_debug('Connection', 'Can not connect to pod');
try {
......@@ -287,6 +304,7 @@ foreach ($pods as $pod) {
$iplookupv4 = explode(PHP_EOL, trim($delv->execute([], null, 15)->stdout));
$dnssec = in_array('; fully validated', $iplookupv4, true) ?? false;
$getaonly = array_values(preg_grep('/\s+IN\s+A\s+.*/', $iplookupv4));
if ($getaonly) {
preg_match('/A\s(.*)/', $getaonly[0], $aversion);
$ip = trim($aversion[1]) ?? '';
......@@ -334,24 +352,24 @@ foreach ($pods as $pod) {
_debug('Uptime', $uptime);
if ($score < 70 && $notify && !(isset($argv) && in_array('develop', $argv, true))) {
if ($score < 70 && $notify && !$develop) {
$to = $email;
$headers = ['From: ' . $adminemail, 'Bcc: ' . $adminemail];
$subject = 'Monitoring notice from poduptime';
$message = 'Notice for ' . $domain . '. Your score fell to ' . $score . ' and your pod is now not showing on the site.';
@mail($to, $subject, $message, implode("\r\n", $headers));
_debug('Mail Notice', 'sent to ' . $email);
}
if ($score > 100) {
$score = 100;
} elseif ($score < 0) {
$score = 0;
if ($masterv !== $shortv) {
$status = PodStatus::SYSTEM_DELETED;
}
$status = PodStatus::SYSTEM_DELETED;
}
_debug('Score', $score);
$weightedscore = ($uptime + $score - (10 - $weight)) / 2;
_debug('Score', $score);
_debug('Weighted Score', $weightedscore);
try {
......
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