Fix health page not working #27

Merged
MrPetovan merged 5 commits from issue/#24 into master 2017-08-04 03:38:20 +02:00
2 changed files with 136 additions and 135 deletions
Showing only changes of commit c6d60df8ac - Show all commits

View file

@ -73,8 +73,6 @@ if ($a->module_loaded) {
if ((!$a->error) && (function_exists($a->module . '_content'))) { if ((!$a->error) && (function_exists($a->module . '_content'))) {
$func = $a->module . '_content'; $func = $a->module . '_content';
$a->page['content'] = $func($a); $a->page['content'] = $func($a);
killme();
} }
} }

View file

@ -1,35 +1,32 @@
<?php <?php
require_once('include/site-health.php'); require_once 'include/site-health.php';
function health_content(&$a) { use Friendica\Directory\App;
function health_content(App $a)
{
if ($a->argc > 1) { if ($a->argc > 1) {
return health_details($a, $a->argv[1]); return health_details($a, $a->argv[1]);
} }
if($_GET['s']){ if (isset($_GET['s']) && $_GET['s']) {
return health_search($a, $_GET['s']); return health_search($a, $_GET['s']);
} }
return health_summary($a); return health_summary($a);
} }
function health_search(&$a, $search) function health_search(App $a, $search)
{ {
if (strlen($search) < 3) { if (strlen($search) < 3) {
$result = 'Please use at least 3 characters in your search'; $result = 'Please use at least 3 characters in your search';
} } else {
else {
$r = q("SELECT * FROM `site-health` WHERE `base_url` LIKE '%%%s%%' ORDER BY `health_score` DESC LIMIT 100", dbesc($search)); $r = q("SELECT * FROM `site-health` WHERE `base_url` LIKE '%%%s%%' ORDER BY `health_score` DESC LIMIT 100", dbesc($search));
if (count($r)) { if (count($r)) {
$result = ''; $result = '';
foreach($r as $site){
foreach ($r as $site) {
//Get user count. //Get user count.
$site['users'] = 0; $site['users'] = 0;
$r = q( $r = q(
@ -37,6 +34,7 @@ function health_search(&$a, $search)
WHERE `homepage` LIKE '%s%%'", WHERE `homepage` LIKE '%s%%'",
dbesc($site['base_url']) dbesc($site['base_url'])
); );
if (count($r)) { if (count($r)) {
$site['users'] = $r[0]['users']; $site['users'] = $r[0]['users'];
} }
@ -48,26 +46,21 @@ function health_search(&$a, $search)
($site['effective_base_url'] ? ' -&gt; <abbr title="Redirects to this domain.">' . $site['effective_base_url'] . '</abbr>' : '') . ($site['effective_base_url'] ? ' -&gt; <abbr title="Redirects to this domain.">' . $site['effective_base_url'] . '</abbr>' : '') .
"<br />\r\n"; "<br />\r\n";
} }
} else {
}
else {
$result = 'No results'; $result = 'No results';
} }
} }
$tpl .= file_get_contents('view/health_search.tpl'); $tpl .= file_get_contents('view/health_search.tpl');
return replace_macros($tpl, array( return replace_macros($tpl, array(
'$searched' => $search, '$searched' => $search,
'$result' => $result '$result' => $result
)); ));
} }
function health_summary(&$a){ function health_summary(App $a)
{
$sites = array(); $sites = array();
//Find the user count per site. //Find the user count per site.
@ -76,8 +69,9 @@ function health_summary(&$a){
foreach ($r as $rr) { foreach ($r as $rr) {
$site = parse_site_from_url($rr['homepage']); $site = parse_site_from_url($rr['homepage']);
if ($site) { if ($site) {
if(!isset($sites[$site])) if (!isset($sites[$site])) {
$sites[$site] = 0; $sites[$site] = 0;
}
$sites[$site] ++; $sites[$site] ++;
} }
} }
@ -90,24 +84,28 @@ function health_summary(&$a){
$r = q("SELECT * FROM `site-health` WHERE `reg_policy`='REGISTER_OPEN' AND `ssl_state` = 1"); $r = q("SELECT * FROM `site-health` WHERE `reg_policy`='REGISTER_OPEN' AND `ssl_state` = 1");
if (count($r)) { if (count($r)) {
foreach ($r as $rr) { foreach ($r as $rr) {
if (isset($sites[$rr['base_url']])) {
$sites_with_health[$rr['base_url']] = (($sites[$rr['base_url']] / 100) + 10) * intval($rr['health_score']); $sites_with_health[$rr['base_url']] = (($sites[$rr['base_url']] / 100) + 10) * intval($rr['health_score']);
$site_healths[$rr['base_url']] = $rr; $site_healths[$rr['base_url']] = $rr;
} }
} }
}
arsort($sites_with_health); arsort($sites_with_health);
$total = 0; $total = 0;
$public_sites = ''; $public_sites = '';
foreach($sites_with_health as $k => $v) foreach ($sites_with_health as $k => $v) {
{
//Stop at unhealthy sites. //Stop at unhealthy sites.
$site = $site_healths[$k]; $site = $site_healths[$k];
if($site['health_score'] <= 20) break; if ($site['health_score'] <= 20) {
break;
}
//Skip small sites. //Skip small sites.
$users = $sites[$k]; $users = $sites[$k];
if($users < 5) continue; if ($users < 5) {
continue;
}
$public_sites .= $public_sites .=
'<span class="health ' . health_score_to_name($site['health_score']) . '">&hearts;</span> ' . '<span class="health ' . health_score_to_name($site['health_score']) . '">&hearts;</span> ' .
@ -115,21 +113,18 @@ function health_summary(&$a){
'(' . $users . ')' . '(' . $users . ')' .
"<br />\r\n"; "<br />\r\n";
$total ++; $total ++;
} }
$public_sites .= "<br>Total: $total<br />\r\n"; $public_sites .= "<br>Total: $total<br />\r\n";
$tpl .= file_get_contents('view/health_summary.tpl'); $tpl = file_get_contents('view/health_summary.tpl');
return replace_macros($tpl, array( return replace_macros($tpl, array(
'$versions' => $versions,
'$public_sites' => $public_sites '$public_sites' => $public_sites
)); ));
} }
function health_details($a, $id) function health_details(App $a, $id)
{ {
//Max data age in MySQL date. //Max data age in MySQL date.
$maxDate = date('Y-m-d H:i:s', time() - ($a->config['stats']['maxDataAge'])); $maxDate = date('Y-m-d H:i:s', time() - ($a->config['stats']['maxDataAge']));
@ -182,7 +177,6 @@ function health_details($a, $id)
//Does it redirect to a known site? //Does it redirect to a known site?
$redirectStatement = ''; $redirectStatement = '';
if ($site['effective_base_url']) { if ($site['effective_base_url']) {
//The effective health status. //The effective health status.
$r = q( $r = q(
"SELECT * FROM `site-health` "SELECT * FROM `site-health`
annando commented 2017-08-02 20:07:51 +02:00 (Migrated from github.com)
Review

Why is "versions" vanished?

Why is "versions" vanished?
MrPetovan commented 2017-08-02 20:20:49 +02:00 (Migrated from github.com)
Review

I have no idea, the variable didn't exist in the controller nor in the template.

I have no idea, the variable didn't exist in the controller nor in the template.
annando commented 2017-08-02 20:29:00 +02:00 (Migrated from github.com)
Review

Okay. When you had checked that, then It's fine for me.

Okay. When you had checked that, then It's fine for me.
@ -192,7 +186,6 @@ function health_details($a, $id)
if (count($r)) { if (count($r)) {
$redirectStatement = '<a href="/health/' . $r[0]['id'] . '">Redirects to ' . $site['effective_base_url'] . '</a>'; $redirectStatement = '<a href="/health/' . $r[0]['id'] . '">Redirects to ' . $site['effective_base_url'] . '</a>';
} }
} }
//Figure out SSL state. //Figure out SSL state.
@ -201,9 +194,12 @@ function health_details($a, $id)
$ssl_state = 'No'; $ssl_state = 'No';
} else { } else {
switch ($site['ssl_state']) { switch ($site['ssl_state']) {
case null: $ssl_state = 'Yes, but not yet verified.'; break; case null: $ssl_state = 'Yes, but not yet verified.';
case '0': $ssl_state = 'Certificate error!'; break; break;
case '1': $ssl_state = '&radic; Yes, verified.'; break; case '0': $ssl_state = 'Certificate error!';
break;
case '1': $ssl_state = '&radic; Yes, verified.';
break;
} }
$ssl_state .= ' <a href="https://www.ssllabs.com/ssltest/analyze.html?d=' . $urlMeta['host'] . '" target="_blank">Detailed test</a>'; $ssl_state .= ' <a href="https://www.ssllabs.com/ssltest/analyze.html?d=' . $urlMeta['host'] . '" target="_blank">Detailed test</a>';
} }
@ -265,23 +261,27 @@ function health_details($a, $id)
$a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/js/raphael/raphael.js"></script>' . PHP_EOL; $a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/js/raphael/raphael.js"></script>' . PHP_EOL;
$a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/js/raphael/g_raphael.js"></script>' . PHP_EOL; $a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/js/raphael/g_raphael.js"></script>' . PHP_EOL;
$a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/js/raphael/g_line.js?v=0.51"></script>'; $a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/js/raphael/g_line.js?v=0.51"></script>';
$speeds = array(); $speeds = array();
$times = array(); $times = array();
$mintime = time(); $mintime = time();
foreach ($r as $row) { foreach ($r as $row) {
$speeds[] = $row['avg_time']; $speeds[] = $row['avg_time'];
$time = strtotime($row['date']); $time = strtotime($row['date']);
$times[] = $time; $times[] = $time;
if($mintime > $time) $mintime = $time; if ($mintime > $time)
$mintime = $time;
} }
for ($i = 0; $i < count($times); $i++) { for ($i = 0; $i < count($times); $i++) {
$times[$i] -= $mintime; $times[$i] -= $mintime;
$times[$i] = floor($times[$i] / (24 * 3600)); $times[$i] = floor($times[$i] / (24 * 3600));
} }
$a->page['htmlhead'] .= $a->page['htmlhead'] .=
'<script type="text/javascript"> '<script type="text/javascript">
(function(){ (function(){
var x = [' . implode(',', $times) . ']; var x = [' . implode(',', $times) . '];
var y = [' . implode(',', $speeds) . ']; var y = [' . implode(',', $speeds) . '];
var smoothY = Smoothing.exponentialMovingAverage(y, smoothingFactor, smoothingBracket); var smoothY = Smoothing.exponentialMovingAverage(y, smoothingFactor, smoothingBracket);
@ -298,9 +298,7 @@ function health_details($a, $id)
r.linechart(30, 15, 400, 295, x, values, {axis:"0 0 1 1", shade:true, width:0.8, axisxstep:6}) r.linechart(30, 15, 400, 295, x, values, {axis:"0 0 1 1", shade:true, width:0.8, axisxstep:6})
.hoverColumn(onHoverPoint(r), onUnHoverPoint(r)); .hoverColumn(onHoverPoint(r), onUnHoverPoint(r));
}); });
})(); })();
</script>'; </script>';
} }
@ -319,23 +317,27 @@ function health_details($a, $id)
$a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/js/raphael/raphael.js"></script>' . PHP_EOL; $a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/js/raphael/raphael.js"></script>' . PHP_EOL;
$a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/js/raphael/g_raphael.js"></script>' . PHP_EOL; $a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/js/raphael/g_raphael.js"></script>' . PHP_EOL;
$a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/js/raphael/g_line.js?v=0.51"></script>'; $a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/js/raphael/g_line.js?v=0.51"></script>';
$speeds = array(); $speeds = array();
$times = array(); $times = array();
$mintime = time(); $mintime = time();
foreach ($r as $row) { foreach ($r as $row) {
$speeds[] = $row['avg_time']; $speeds[] = $row['avg_time'];
$time = strtotime($row['date']); $time = strtotime($row['date']);
$times[] = $time; $times[] = $time;
if($mintime > $time) $mintime = $time; if ($mintime > $time)
$mintime = $time;
} }
for ($i = 0; $i < count($times); $i++) { for ($i = 0; $i < count($times); $i++) {
$times[$i] -= $mintime; $times[$i] -= $mintime;
$times[$i] = floor($times[$i] / (24 * 3600)); $times[$i] = floor($times[$i] / (24 * 3600));
} }
$a->page['htmlhead'] .= $a->page['htmlhead'] .=
'<script type="text/javascript"> '<script type="text/javascript">
(function(){ (function(){
var x = [' . implode(',', $times) . ']; var x = [' . implode(',', $times) . '];
var y = [' . implode(',', $speeds) . ']; var y = [' . implode(',', $speeds) . '];
var smoothY = Smoothing.exponentialMovingAverage(y, smoothingFactor, smoothingBracket); var smoothY = Smoothing.exponentialMovingAverage(y, smoothingFactor, smoothingBracket);
@ -354,7 +356,6 @@ function health_details($a, $id)
.hoverColumn(onHoverPoint(r), onUnHoverPoint(r)); .hoverColumn(onHoverPoint(r), onUnHoverPoint(r));
}); });
})(); })();
</script>'; </script>';
} }
@ -367,7 +368,8 @@ function health_details($a, $id)
default: $policy = $site['reg_policy']; break; default: $policy = $site['reg_policy']; break;
} }
$tpl .= file_get_contents('view/health_details.tpl'); $tpl = file_get_contents('view/health_details.tpl');
return replace_macros($tpl, array( return replace_macros($tpl, array(
'$name' => $site['name'], '$name' => $site['name'],
'$redirectStatement' => $redirectStatement, '$redirectStatement' => $redirectStatement,
@ -393,3 +395,4 @@ function health_details($a, $id)
'$avg_photo_time' => round($site['avg_photo_time']), '$avg_photo_time' => round($site['avg_photo_time']),
'$avg_submit_time' => round($site['avg_submit_time']) '$avg_submit_time' => round($site['avg_submit_time'])
)); ));
}