com web/master: Neat changes and additions; bells and whistles; still need to add RRN data.: network/status/.htaccess network/status/api.php
network/status/index.php
| From: | Daniel P. Brown | Date: | Tue, 26 Jun 2012 22:19:22 +0000 |
| Subject: | com web/master: Neat changes and additions; bells and whistles; still need to add RRN data.: network/status/.htaccess network/status/api.php network/status/index.php |
||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-13793@lists.php.net to get a copy of this message | ||
Commit: c063b4270b891cf7dc2aab4cfe190d4fe3a32c65
Author: Daniel P. Brown <danbrown@php.net> Tue, 26 Jun 2012 18:19:22 -0400
Parents: 826672055581dd19204d8c6c3e45a3cdfe3c43f0
Branches: master
Link: http://git.php.net/?p=web/master.git;a=commitdiff;h=c063b4270b891cf7dc2aab4cfe190d4fe3a32c65
Log:
Neat changes and additions; bells and whistles; still need to add RRN data.
Changed paths:
A network/status/.htaccess
A network/status/api.php
M network/status/index.php
diff --git a/network/status/.htaccess b/network/status/.htaccess new file mode 100644 index 0000000..8c51172 --- /dev/null +++ b/network/status/.htaccess @@ -0,0 +1,5 @@ +RewriteEngine On + +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^(.*)$ api.php?host=$1 [QSA,L] diff --git a/network/status/api.php b/network/status/api.php new file mode 100644 index 0000000..8a04dd7 --- /dev/null +++ b/network/status/api.php @@ -0,0 +1,111 @@ +<?php + +// We place this on the screen so that the user +// knows something should be getting ready to happen +if (!isset($_GET['host'])) die('Waiting....'); + +// If it's not a legitimate *.php.net address, make 'em buzz off +if (!preg_match('/^[a-z]+[0-9]?\.php\.net$/i',$_GET['host'])) + die('Uhhh, yeeeaaaahhh.... that\'s not gonna\' happen.'); + +// Go ahead and include the functions and configuration and such now +require_once dirname(dirname(dirname(__FILE__))).'/include/functions.inc'; + +/** + * In the interest of keeping this (free) key from + * being copied and reused, we'll store it in a file here: + * /etc/ipinfodb-api-key.txt + * If you're reading this source and are interested in + * getting your own free API key, I'd recommend going + * to http://www.ipinfodb.com/ and signing up. + */ +$ipinfodb_api_key = trim(file_get_contents('/etc/ipinfodb-api-key.txt')); + +// Database connection and query +db_connect(); +$res = db_query("SELECT * FROM mirrors LEFT JOIN country ON mirrors.cc = country.id WHERE mirrors.hostname='".mysql_real_escape_string($_GET['host'])."' LIMIT 0,1"); +$row = mysql_fetch_assoc($res); + +// Grab the real-time info from the mirror +$data = file_get_contents('http://'.$_GET['host'].'/mirror-info') or die('Unable to reach '.$_GET['host'].' via HTTP GET request.'); +$conf = explode('|',$data); + +// Last time the mirror was synchronized +$last_updated = date('\o\n l, \t\h\e jS \o\f F, Y, \a\t H:i:s',$conf[2]); + +// Available SQLites +$sqlites = implode(', ',decipher_available_sqlites($conf[3])); + +// Whether or not stats are available +$stats = $conf[4] == '1' ? 'does' : 'does not'; + +// The mirror's primary ISO language code +$lang_iso = $conf[5]; + +// Whether the mirror is active or inactive +$active = $conf[7] == '1' ? 'active' : 'inactive'; + +// The mirror's actual CNAME, IP info, and network stats +$cname = $row['cname']; +$ip_info = str_replace(PHP_EOL,'; ',trim(`host $cname | grep -i address`)); +$ping_stats = nl2br(trim(`ping -c1 -i1 -w1 $cname | grep -v PING | grep -v "ping statistics"`)); +$ip_addr = gethostbyname($_GET['host']); + +// Our hostname info for showing in the probe report +$my_host = trim(`hostname`); + +// The maintainer's name with email address stripped +$maintainer = preg_replace('/\s?\<.*\>/U','',$row['maintainer']); + +// The date the mirror became official +preg_match('/^([0-9]{4,}-[0-9]{2,}-[0-9]{2,})/',$row['created'],$cd); +$ctime = strtotime(preg_replace('/([0-4\-])\s.*/','',$cd[0])); +$created = strstr('0000-00-00',$row['created']) ? 'before Tuesday, the 17th of September, 2002' : date('l, \t\h\e jS \o\f F, Y',$ctime); + +// The mirror type (normal = 1, special = 2) +$mirrortype = $row['mirrortype'] == '1' ? 'official' : 'special official'; + +// Geographical information from IP using danbrown's API key +$geoip_info = explode(';',file_get_contents('http://api.ipinfodb.com/v3/ip-city/?key='.$ipinfodb_api_key.'&ip='.$ip_addr)); + +// If we have location information to offer, build that output here +if (is_array($geoip_info) && $geoip_info[0] == 'OK') { + $geoip_info['region'] = $geoip_info[5]; + $geoip_info['city'] = $geoip_info[6]; + $geoip_info['lat_lon'] = $geoip_info[8].','.$geoip_info[9]; + $geoip_info['maplink'] = 'https://maps.google.com/maps?q='.$geoip_info['lat_lon'].'&hl=en&t=h&z=11'; + + if ($geoip_info['city'] != '-') { + $geoip_info['html'] = 'The mirror seems to be physically located in or near <b>'.$geoip_info['city']; + $geoip_info['html'] .= !empty($geoip_info['region']) && $geoip_info['region'] != $geoip_info['city'] ? ', '.$geoip_info['region'] : ''; + $geoip_info['html'] .= '</b>, which can be <b><a href="'.$geoip_info['maplink'].'" target="_blank">seen right here</a></b>.'; + } else { + $geoip_info['html'] = 'The mirror may or may not be <b><a href="'.$geoip_info['maplink'].'" target="_blank">near this point on the map.</a></b>'; + } + $geoip_info['html'] .= '<br/>'.PHP_EOL.'<br/>'.PHP_EOL; +} else { + $geoip_info['html'] = ''; +} + +// Build our HTML block +$html =<<<HTML +The node named <b><a href="{$conf[0]}" target="_blank">{$_GET['host']}</a></b> is an <b>{$active}</b> +{$mirrortype} php.net mirror serving the community from <b>{$row['name']}</b>. It is sponsored by +<b><a href="http://{$row['providerurl']}/" target="_blank">{$row['providername']}</a></b> and +primarily maintained by <b>{$maintainer}</b>. Its hostname <b>{$ip_info}</b>. It was +last updated <b>{$last_updated}</b>. It is presently running <b>PHP {$conf[1]}</b> with +<b>{$sqlites} SQLite</b> available. The node <b>{$stats}</b> have statistics available, and +is configured to use the <b>ISO language code "{$lang_iso}"</b> as its primary language. This +mirror has been in service since <b>{$created}</b>.<br/> +<br/> + +{$geoip_info['html']} + +From here at <b>{$_SERVER['HTTP_HOST']} ({$my_host})</b>, a single probe to the node responds:<br/> +<br/> +{$ping_stats} + +HTML; + +// Output the HTML now +echo $html; diff --git a/network/status/index.php b/network/status/index.php index 9e532c8..c6327de 100644 --- a/network/status/index.php +++ b/network/status/index.php @@ -164,44 +164,43 @@ function page_mirror_list($moreinfo = false) } // Mirror status information - $summary .= "<tr class=\"mirrorstatus\">\n" . - "<td bgcolor=\"#ffffff\" align=\"right\">\n" . - "<img src=\"images/{$siteimage}.gif\" /></td>\n"; + $summary .= "<tr class=\"mirrorstatus\" onclick=\"$('#".str_replace('.','_',$row['hostname'])."_info').toggle();". + "$('#".str_replace('.','_',$row['hostname'])."_realtime').load('".$row['hostname']."');". + "$('#".str_replace('.','_',$row['hostname'])."_realtime').focus();\">". + "<td bgcolor=\"#ffffff\" align=\"right\">".PHP_EOL. + "<img src=\"images/{$siteimage}.gif\" /></td>".PHP_EOL; // Print out mirror site link - $summary .= '<td style="background-color:#ffdddd;"><a href="http://'.$row['hostname'].'/" target="_blank">' . - $row['hostname'] . '</a><br /></td>' . "\n"; + $summary .= '<td style="background-color:#ffdddd;"><a href="http://'.$row['hostname'].'/" target="_blank">'. + $row['hostname'].'</a><br /></td>'.PHP_EOL; // Print out mirror provider information - $summary .= '<td style="background-color:#ffdddd;"><a href="'.$row['providerurl'].'">' . - $row['providername'] . '</a><br /></td>' . "\n"; + $summary .= '<td style="background-color:#ffdddd;"><a href="'.$row['providerurl'].'">'. + $row['providername'].'</a><br /></td>'.PHP_EOL; // Print out the sync status of the mirror - $summary .= '<td align="center" style="background-color:#ddddff;width:80px;">'.$synchrony_icon.'</td>' . "\n"; + $summary .= '<td align="center" style="background-color:#ddddff;width:80px;">'.$synchrony_icon.'</td>'.PHP_EOL; - // Print out mirror search table cell - $summary .= '<td align="center" style="background-color:#ddddff;width:80px;">'.$sqlite_icon. '</td>' . "\n"; + // Print out SQLite compliance information + $summary .= '<td align="center" style="background-color:#ddddff;width:80px;">'.$sqlite_icon.'</td>'.PHP_EOL; - // Print out version information for this mirror - $summary .= '<td align="center" style="background-color:#ddddff;width:80px;">'.$php_icon.'</td>' . "\n"; + // Print out PHP version compliance information + $summary .= '<td align="center" style="background-color:#ddddff;width:80px;">'.$php_icon.'</td>'.PHP_EOL; - // Print out mirror stats table cell + // AS-YET UNUSED CELL $summary .= '<td align="right" style="background-color:#ddddff;"> </td>' . "\n"; - // Print out mirror edit link + // AS-YET UNUSED CELL $summary .= '<td align="right" style="background-color:#ddddff;"> </td>' . "\n"; // End of row $summary .= '</tr>'; - // If additional details are desired - if ($moreinfo) { - $summary .= '<tr class=\"mirrordetails\"><td bgcolor="#ffffff"> </td>' . - '<td colspan="7">' . - ' Last update: ' . date(DATE_RSS, $row['ulastupdated']) . - ' SQLites: ' . implode(' : ', decipher_available_sqlites($row['has_search'])) . - '</td></tr>'; - } + // To show real-time info, if the row is clicked + $summary .= '<tr style="display:none;" id="'.str_replace('.','_',$row['hostname']).'_info">'.PHP_EOL; + $summary .= '<td colspan="8" id="'.str_replace('.','_',$row['hostname']).'_realtime">Hang on a sec....</td>'.PHP_EOL; + $summary .= '</tr>'.PHP_EOL; + } $summary .= '</table></div>'; @@ -220,10 +219,6 @@ function page_mirror_list($moreinfo = false) } } - // Create version specific statistics - $stats['version5_percent'] = sprintf('%.1f%%', $stats['phpversion_counts'][5] / $stats['mirrors'] * 100); - $stats['has_stats_percent'] = sprintf('%.1f%%', $stats['has_stats'] / $stats['mirrors'] * 100); - $last_check_time = get_print_date($checktime); $current_time = get_print_date(time()); @@ -258,12 +253,19 @@ $('.selector').qtip({ <br/> <b>In each node's compliance entries, you can place your -mouse over the icon to get additional details.</b><br/> +mouse over the icon to get additional details. Or, for +more than you ever wanted to know about the mirror, click +anywhere in its respective row.</b><br/> <br/> <h2>Key:</h2> -<img src="images/green.gif"/> Node Active +<br/> + + <img src="images/green.gif"/> Node Active <img src="images/pulsing_red.gif"/> Node Inactive +<img src="images/special.gif"/> Special Node<br/> +<br/> + <img src="images/ok.gif"/> Node Is Fully Compliant <img src="images/warn.gif"/> Node Is Partially Compliant <img src="images/fail.gif"/> Node Is Non-Compliant<br/>
diff --git a/network/status/.htaccess b/network/status/.htaccess new file mode 100644 index 0000000..8c51172 --- /dev/null +++ b/network/status/.htaccess @@ -0,0 +1,5 @@ +RewriteEngine On + +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^(.*)$ api.php?host=$1 [QSA,L] diff --git a/network/status/api.php b/network/status/api.php new file mode 100644 index 0000000..8a04dd7 --- /dev/null +++ b/network/status/api.php @@ -0,0 +1,111 @@ +<?php + +// We place this on the screen so that the user +// knows something should be getting ready to happen +if (!isset($_GET['host'])) die('Waiting....'); + +// If it's not a legitimate *.php.net address, make 'em buzz off +if (!preg_match('/^[a-z]+[0-9]?\.php\.net$/i',$_GET['host'])) + die('Uhhh, yeeeaaaahhh.... that\'s not gonna\' happen.'); + +// Go ahead and include the functions and configuration and such now +require_once dirname(dirname(dirname(__FILE__))).'/include/functions.inc'; + +/** + * In the interest of keeping this (free) key from + * being copied and reused, we'll store it in a file here: + * /etc/ipinfodb-api-key.txt + * If you're reading this source and are interested in + * getting your own free API key, I'd recommend going + * to http://www.ipinfodb.com/ and signing up. + */ +$ipinfodb_api_key = trim(file_get_contents('/etc/ipinfodb-api-key.txt')); + +// Database connection and query +db_connect(); +$res = db_query("SELECT * FROM mirrors LEFT JOIN country ON mirrors.cc = country.id WHERE mirrors.hostname='".mysql_real_escape_string($_GET['host'])."' LIMIT 0,1"); +$row = mysql_fetch_assoc($res); + +// Grab the real-time info from the mirror +$data = file_get_contents('http://'.$_GET['host'].'/mirror-info') or die('Unable to reach '.$_GET['host'].' via HTTP GET request.'); +$conf = explode('|',$data); + +// Last time the mirror was synchronized +$last_updated = date('\o\n l, \t\h\e jS \o\f F, Y, \a\t H:i:s',$conf[2]); + +// Available SQLites +$sqlites = implode(', ',decipher_available_sqlites($conf[3])); + +// Whether or not stats are available +$stats = $conf[4] == '1' ? 'does' : 'does not'; + +// The mirror's primary ISO language code +$lang_iso = $conf[5]; + +// Whether the mirror is active or inactive +$active = $conf[7] == '1' ? 'active' : 'inactive'; + +// The mirror's actual CNAME, IP info, and network stats +$cname = $row['cname']; +$ip_info = str_replace(PHP_EOL,'; ',trim(`host $cname | grep -i address`)); +$ping_stats = nl2br(trim(`ping -c1 -i1 -w1 $cname | grep -v PING | grep -v "ping statistics"`)); +$ip_addr = gethostbyname($_GET['host']); + +// Our hostname info for showing in the probe report +$my_host = trim(`hostname`); + +// The maintainer's name with email address stripped +$maintainer = preg_replace('/\s?\<.*\>/U','',$row['maintainer']); + +// The date the mirror became official +preg_match('/^([0-9]{4,}-[0-9]{2,}-[0-9]{2,})/',$row['created'],$cd); +$ctime = strtotime(preg_replace('/([0-4\-])\s.*/','',$cd[0])); +$created = strstr('0000-00-00',$row['created']) ? 'before Tuesday, the 17th of September, 2002' : date('l, \t\h\e jS \o\f F, Y',$ctime); + +// The mirror type (normal = 1, special = 2) +$mirrortype = $row['mirrortype'] == '1' ? 'official' : 'special official'; + +// Geographical information from IP using danbrown's API key +$geoip_info = explode(';',file_get_contents('http://api.ipinfodb.com/v3/ip-city/?key='.$ipinfodb_api_key.'&ip='.$ip_addr)); + +// If we have location information to offer, build that output here +if (is_array($geoip_info) && $geoip_info[0] == 'OK') { + $geoip_info['region'] = $geoip_info[5]; + $geoip_info['city'] = $geoip_info[6]; + $geoip_info['lat_lon'] = $geoip_info[8].','.$geoip_info[9]; + $geoip_info['maplink'] = 'https://maps.google.com/maps?q='.$geoip_info['lat_lon'].'&hl=en&t=h&z=11'; + + if ($geoip_info['city'] != '-') { + $geoip_info['html'] = 'The mirror seems to be physically located in or near <b>'.$geoip_info['city']; + $geoip_info['html'] .= !empty($geoip_info['region']) && $geoip_info['region'] != $geoip_info['city'] ? ', '.$geoip_info['region'] : ''; + $geoip_info['html'] .= '</b>, which can be <b><a href="'.$geoip_info['maplink'].'" target="_blank">seen right here</a></b>.'; + } else { + $geoip_info['html'] = 'The mirror may or may not be <b><a href="'.$geoip_info['maplink'].'" target="_blank">near this point on the map.</a></b>'; + } + $geoip_info['html'] .= '<br/>'.PHP_EOL.'<br/>'.PHP_EOL; +} else { + $geoip_info['html'] = ''; +} + +// Build our HTML block +$html =<<<HTML +The node named <b><a href="{$conf[0]}" target="_blank">{$_GET['host']}</a></b> is an <b>{$active}</b> +{$mirrortype} php.net mirror serving the community from <b>{$row['name']}</b>. It is sponsored by +<b><a href="http://{$row['providerurl']}/" target="_blank">{$row['providername']}</a></b> and +primarily maintained by <b>{$maintainer}</b>. Its hostname <b>{$ip_info}</b>. It was +last updated <b>{$last_updated}</b>. It is presently running <b>PHP {$conf[1]}</b> with +<b>{$sqlites} SQLite</b> available. The node <b>{$stats}</b> have statistics available, and +is configured to use the <b>ISO language code "{$lang_iso}"</b> as its primary language. This +mirror has been in service since <b>{$created}</b>.<br/> +<br/> + +{$geoip_info['html']} + +From here at <b>{$_SERVER['HTTP_HOST']} ({$my_host})</b>, a single probe to the node responds:<br/> +<br/> +{$ping_stats} + +HTML; + +// Output the HTML now +echo $html; diff --git a/network/status/index.php b/network/status/index.php index 9e532c8..c6327de 100644 --- a/network/status/index.php +++ b/network/status/index.php @@ -164,44 +164,43 @@ function page_mirror_list($moreinfo = false) } // Mirror status information - $summary .= "<tr class=\"mirrorstatus\">\n" . - "<td bgcolor=\"#ffffff\" align=\"right\">\n" . - "<img src=\"images/{$siteimage}.gif\" /></td>\n"; + $summary .= "<tr class=\"mirrorstatus\" onclick=\"$('#".str_replace('.','_',$row['hostname'])."_info').toggle();". + "$('#".str_replace('.','_',$row['hostname'])."_realtime').load('".$row['hostname']."');". + "$('#".str_replace('.','_',$row['hostname'])."_realtime').focus();\">". + "<td bgcolor=\"#ffffff\" align=\"right\">".PHP_EOL. + "<img src=\"images/{$siteimage}.gif\" /></td>".PHP_EOL; // Print out mirror site link - $summary .= '<td style="background-color:#ffdddd;"><a href="http://'.$row['hostname'].'/" target="_blank">' . - $row['hostname'] . '</a><br /></td>' . "\n"; + $summary .= '<td style="background-color:#ffdddd;"><a href="http://'.$row['hostname'].'/" target="_blank">'. + $row['hostname'].'</a><br /></td>'.PHP_EOL; // Print out mirror provider information - $summary .= '<td style="background-color:#ffdddd;"><a href="'.$row['providerurl'].'">' . - $row['providername'] . '</a><br /></td>' . "\n"; + $summary .= '<td style="background-color:#ffdddd;"><a href="'.$row['providerurl'].'">'. + $row['providername'].'</a><br /></td>'.PHP_EOL; // Print out the sync status of the mirror - $summary .= '<td align="center" style="background-color:#ddddff;width:80px;">'.$synchrony_icon.'</td>' . "\n"; + $summary .= '<td align="center" style="background-color:#ddddff;width:80px;">'.$synchrony_icon.'</td>'.PHP_EOL; - // Print out mirror search table cell - $summary .= '<td align="center" style="background-color:#ddddff;width:80px;">'.$sqlite_icon. '</td>' . "\n"; + // Print out SQLite compliance information + $summary .= '<td align="center" style="background-color:#ddddff;width:80px;">'.$sqlite_icon.'</td>'.PHP_EOL; - // Print out version information for this mirror - $summary .= '<td align="center" style="background-color:#ddddff;width:80px;">'.$php_icon.'</td>' . "\n"; + // Print out PHP version compliance information + $summary .= '<td align="center" style="background-color:#ddddff;width:80px;">'.$php_icon.'</td>'.PHP_EOL; - // Print out mirror stats table cell + // AS-YET UNUSED CELL $summary .= '<td align="right" style="background-color:#ddddff;"> </td>' . "\n"; - // Print out mirror edit link + // AS-YET UNUSED CELL $summary .= '<td align="right" style="background-color:#ddddff;"> </td>' . "\n"; // End of row $summary .= '</tr>'; - // If additional details are desired - if ($moreinfo) { - $summary .= '<tr class=\"mirrordetails\"><td bgcolor="#ffffff"> </td>' . - '<td colspan="7">' . - ' Last update: ' . date(DATE_RSS, $row['ulastupdated']) . - ' SQLites: ' . implode(' : ', decipher_available_sqlites($row['has_search'])) . - '</td></tr>'; - } + // To show real-time info, if the row is clicked + $summary .= '<tr style="display:none;" id="'.str_replace('.','_',$row['hostname']).'_info">'.PHP_EOL; + $summary .= '<td colspan="8" id="'.str_replace('.','_',$row['hostname']).'_realtime">Hang on a sec....</td>'.PHP_EOL; + $summary .= '</tr>'.PHP_EOL; + } $summary .= '</table></div>'; @@ -220,10 +219,6 @@ function page_mirror_list($moreinfo = false) } } - // Create version specific statistics - $stats['version5_percent'] = sprintf('%.1f%%', $stats['phpversion_counts'][5] / $stats['mirrors'] * 100); - $stats['has_stats_percent'] = sprintf('%.1f%%', $stats['has_stats'] / $stats['mirrors'] * 100); - $last_check_time = get_print_date($checktime); $current_time = get_print_date(time()); @@ -258,12 +253,19 @@ $('.selector').qtip({ <br/> <b>In each node's compliance entries, you can place your -mouse over the icon to get additional details.</b><br/> +mouse over the icon to get additional details. Or, for +more than you ever wanted to know about the mirror, click +anywhere in its respective row.</b><br/> <br/> <h2>Key:</h2> -<img src="images/green.gif"/> Node Active +<br/> + + <img src="images/green.gif"/> Node Active <img src="images/pulsing_red.gif"/> Node Inactive +<img src="images/special.gif"/> Special Node<br/> +<br/> + <img src="images/ok.gif"/> Node Is Fully Compliant <img src="images/warn.gif"/> Node Is Partially Compliant <img src="images/fail.gif"/> Node Is Non-Compliant<br/>