Currently we have some license issues. We are working on it.

Unverified Commit 73fa0b75 authored by dmorley's avatar dmorley
Browse files

make this more logical and work for pods

parent ca94de08
......@@ -11,7 +11,6 @@ require_once __DIR__ . '/../config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
$dbh || die('Error in connection: ' . pg_last_error());
//foreach pod check it and update db
if ($_domain) {
$sql = 'SELECT domain,score,date_created,adminrating,weight,hidden,podmin_notify,email FROM pods WHERE domain = $1';
$result = pg_query_params($dbh, $sql, [$_domain]);
......@@ -74,62 +73,62 @@ while ($row = pg_fetch_assoc($result)) {
$jsonssl = json_decode($outputssl);
if (!$jsonssl) {
_debug('Connection', 'Can not connect to pod');
$sql_errors = 'INSERT INTO checks (domain, online, error, ttl) VALUES ($1, $2, $3, $4)';
$result_errors = pg_query_params($dbh, $sql_errors, [$domain, 0, $outputsslerror, $ttl]);
$result_errors || die('Error in SQL query: ' . pg_last_error());
continue;
}
if ($jsonssl !== null) {
$xdver = $jsonssl->software->version ?? 0;
$dverr = explode('-', trim($xdver));
$shortversion = $dverr[0];
$signup = ($jsonssl->openRegistrations ?? false) === true;
$softwarename = $jsonssl->software->name ?? 'unknown';
$name = $jsonssl->metadata->nodeName ?? 'null';
$total_users = $jsonssl->usage->users->total ?? 0;
$active_users_halfyear = $jsonssl->usage->users->activeHalfyear ?? 0;
$active_users_monthly = $jsonssl->usage->users->activeMonth ?? 0;
$local_posts = $jsonssl->usage->localPosts ?? 0;
$comment_counts = $jsonssl->usage->localComments ?? 0;
$service_xmpp = ($jsonssl->metadata->xmppChat ?? false) === true;
$service_facebook = 'false';
$service_twitter = 'false';
$service_tumblr = 'false';
$service_wordpress = 'false';
if (json_last_error() === 0) {
(!$jsonssl->software->version) || $score += 1;
$xdver = $jsonssl->software->version ?? 0;
$dverr = explode('-', trim($xdver));
$shortversion = $dverr[0];
_debug('Version code', $shortversion);
$signup = ($jsonssl->openRegistrations === true);
$softwarename = $jsonssl->software->name ?? 'null';
$name = $jsonssl->metadata->nodeName ?? 'null';
$total_users = $jsonssl->usage->users->total ?? 0;
$active_users_halfyear = $jsonssl->usage->users->activeHalfyear ?? 0;
$active_users_monthly = $jsonssl->usage->users->activeMonth ?? 0;
$local_posts = $jsonssl->usage->localPosts ?? 0;
$comment_counts = $jsonssl->usage->localComments ?? 0;
$service_facebook = in_array('facebook', $jsonssl->services->outbound, true);
$service_twitter = in_array('twitter', $jsonssl->services->outbound, true);
$service_tumblr = in_array('tumblr', $jsonssl->services->outbound, true);
$service_wordpress = in_array('wordpress', $jsonssl->services->outbound, true);
$service_xmpp = ($jsonssl->metadata->xmppChat ?? false) === true;
$status = 'Up';
}
if ($jsonssl !== null) {
$status = 'Up';
$sql_checks = 'INSERT INTO checks (domain, online, ttl, total_users, local_posts, comment_counts, shortversion) VALUES ($1, $2, $3, $4, $5, $6, $7)';
$result_checks = pg_query_params($dbh, $sql_checks, [$domain, 1, $ttl, $total_users, $local_posts, $comment_counts, $shortversion]);
$result_checks || die('Error in SQL query: ' . pg_last_error());
} else {
$score -= 1;
$dver = '.connect error';
$shortversion = 0;
}
if (!$jsonssl) {
_debug('Connection', 'Can not connect to pod');
$sql_errors = 'INSERT INTO checks (domain, online, error, ttl) VALUES ($1, $2, $3, $4)';
$result_errors = pg_query_params($dbh, $sql_errors, [$domain, 0, $outputsslerror, $ttl]);
$result_errors || die('Error in SQL query: ' . pg_last_error());
$score -= 1;
$shortversion = '0.error';
$status = 'Down';
}
_debug('Version code', $shortversion);
_debug('Signup Open', $signup);
$iplookupv4 = [];
$ip = '';
$ip = '';
exec(escapeshellcmd('delv @' . $dnsserver . ' ' . $domain), $iplookupv4);
_debug('Iplookupv4', $iplookupv4, true);
$dnssec = in_array('; fully validated', $iplookupv4, true) ?? false;
$dnssec = in_array('; fully validated', $iplookupv4, true) ?? false;
$getaonly = array_values(preg_grep('/\s+IN\s+A\s+.*/', $iplookupv4));
if ($iplookupv4) {
if ($getaonly) {
preg_match('/A\s(.*)/', $getaonly[0], $aversion);
$ip = trim($aversion[1]) ?? '';
$ip = trim($aversion[1]) ?? '';
}
$iplookupv6 = [];
$ipv6 = null;
exec(escapeshellcmd('delv @' . $dnsserver . ' ' . $domain . ' AAAA '), $iplookupv6);
_debug('Iplookupv6', $iplookupv6, true);
$getaaaaonly = array_values(preg_grep('/\s+IN\s+AAAA\s+.*/', $iplookupv6));
if ($getaaaaonly) {
preg_match('/AAAA\s(.*)/', $getaaaaonly[0], $aaaaversion);
......@@ -138,21 +137,23 @@ while ($row = pg_fetch_assoc($result)) {
$ip || $score -= 2;
_debug('IPv4', $ip);
_debug('Iplookupv4', $iplookupv4, true);
_debug('IPv6', $ipv6);
_debug('Iplookupv6', $iplookupv6, true);
$location = geoip_record_by_name($ip);
_debug('Location', $location, true);
$country = !empty($location['country_code']) ? iconv('UTF-8', 'UTF-8//IGNORE', $location['country_code']) : null;
$city = !empty($location['city']) ? iconv('UTF-8', 'UTF-8//IGNORE', $location['city']) : null;
$state = !empty($location['region']) ? iconv('UTF-8', 'UTF-8//IGNORE', $location['region']) : null;
$lat = !empty($location['latitude']) ? $location['latitude'] : 0;
$long = !empty($location['longitude']) ? $location['longitude'] : 0;
$country = !empty($location['country_code']) ? iconv('UTF-8', 'UTF-8//IGNORE', $location['country_code']) : null;
$city = !empty($location['city']) ? iconv('UTF-8', 'UTF-8//IGNORE', $location['city']) : null;
$state = !empty($location['region']) ? iconv('UTF-8', 'UTF-8//IGNORE', $location['region']) : null;
$lat = !empty($location['latitude']) ? $location['latitude'] : 0;
$long = !empty($location['longitude']) ? $location['longitude'] : 0;
echo $newline;
$statslastdate = date('Y-m-d H:i:s');
$diff = (new DateTime())->diff(new DateTime($dateadded));
$months = $diff->m + ($diff->y * 12);
$diff = (new DateTime())->diff(new DateTime($dateadded));
$months = $diff->m + ($diff->y * 12);
$responsetime = 0;
$sqlttl = 'SELECT round(avg(ttl) * 1000) AS ttl FROM checks WHERE domain = $1';
......@@ -200,7 +201,7 @@ while ($row = pg_fetch_assoc($result)) {
_debug('Score out of 100', $score);
echo 'Success';
echo 'Success '.$domain;
echo $newline;
echo $newline;
......
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