Philipp Dunkel 15 years ago
parent 3182cfa3c7
commit e13773e1f1

@ -1,177 +1,268 @@
<? /* <? /*
LibreSSL - CAcert web application LibreSSL - CAcert web application
Copyright (C) 2004-2008 CAcert Inc. Copyright (C) 2004-2008 CAcert Inc.
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
loadem("index"); define('MAX_CACHE_TTL', 36000);
showheader(_("Welcome to CAcert.org"));
loadem("index");
function tc($sql) showheader(_("Welcome to CAcert.org"));
{
$row = mysql_fetch_assoc($sql); function tc($sql)
return($row['count']); {
} $row = mysql_fetch_assoc($sql);
?> return($row['count']);
<h1>CAcert.org <?=_("Statistics")?></h1> }
<table align="center" valign="middle" border="0" cellspacing="0" cellpadding="0" class="wrapper"> /**
<tr> * writes new data to cache, create cache or update existing cache, set current
<td colspan="2" class="title">CAcert.org <?=_("Statistics")?></td> * time stamp
</tr> * @return boolean
<tr> */
<td class="DataTD"><?=_("Verified Users")?>:</td> function updateCache($stats) {
<td class="DataTD"><?=number_format(tc(mysql_query("select count(`id`) as `count` from `users` where `verified`=1")))?></td> $sql = 'insert into statscache (timestamp, cache) values ("' . time() . '", ' .
</tr> '"' . mysql_real_escape_string(serialize($stats)) . '")';
<tr> mysql_query($sql);
<td class="DataTD"><?=_("Verified Emails")?>:</td> }
<td class="DataTD"><?=number_format(tc(mysql_query("select count(`id`) as `count` from `email` where `hash`='' and `deleted`=0")))?></td>
</tr> /**
<tr> * get statistics data from current cache, return result of getDataFromLive if no cache file exists
<td class="DataTD"><?=_("Verified Domains")?>:</td> * @return array
<td class="DataTD"><?=number_format(tc(mysql_query("select count(`id`) as `count` from `domains` where `hash`='' and `deleted`=0")))?></td> */
</tr> function getData() {
<? $sql = 'select * from statscache order by timestamp desc limit 1';
$certs = tc(mysql_query("select count(`id`) as `count` from `domaincerts`")); $res = mysql_query($sql);
$certs += tc(mysql_query("select count(`id`) as `count` from `emailcerts`")); if ($res && mysql_numrows($res) > 0) {
$certs += tc(mysql_query("select count(`id`) as `count` from `gpg`")); $ar = mysql_fetch_assoc($res);
$certs += tc(mysql_query("select count(`id`) as `count` from `orgdomaincerts`")); $stats = unserialize($ar['cache']);
$certs += tc(mysql_query("select count(`id`) as `count` from `orgemailcerts`")); $stats['timestamp'] = $ar['timestamp'];
?> if ($ar['timestamp'] + MAX_CACHE_TTL < time())
<tr> {
<td class="DataTD"><?=_("Certificates Issued")?>:</td> $stats=getDataFromLive();
<td class="DataTD"><?=number_format($certs)?></td> updateCache($stats);
</tr> }
<? return $stats;
$certs = tc(mysql_query("select count(`id`) as `count` from `domaincerts` where `revoked`=0 and `expire`>NOW()")); }
$certs += tc(mysql_query("select count(`id`) as `count` from `emailcerts` where `revoked`=0 and `expire`>NOW()")); $stats=getDataFromLive();
$certs += tc(mysql_query("select count(`id`) as `count` from `gpg` where `expire`<=NOW()")); updateCache($stats);
$certs += tc(mysql_query("select count(`id`) as `count` from `orgdomaincerts` where `revoked`=0 and `expire`>NOW()")); return $stats;
$certs += tc(mysql_query("select count(`id`) as `count` from `orgemailcerts` where `revoked`=0 and `expire`>NOW()")); }
$assurercandidates = tc(mysql_query("select count(*) as `count` from `users` where ".
"not exists(select 1 from `cats_passed` as `cp`, `cats_variant` as `cv` where `cp`.`user_id`=`users`.`id` and `cp`.`variant_id`=`cv`.`id` and `cv`.`type_id`=1) and ". /**
"(select sum(`points`) from `notary` where `to`=`users`.`id`) >= 100")); * get statistics data from live tables, takes a long time so please try to use the
$realassurers = tc(mysql_query("select count(*) as `count` from `users` where ". * cache
"exists(select 1 from `cats_passed` as `cp`, `cats_variant` as `cv` where `cp`.`user_id`=`users`.`id` and `cp`.`variant_id`=`cv`.`id` and `cv`.`type_id`=1) and ". * @return array
"(select sum(`points`) from `notary` where `to`=`users`.`id`) >= 100")); */
?> function getDataFromLive() {
<tr> $stats = array();
<td class="DataTD"><?=_("Valid Certificates")?>:</td> $stats['verified_users'] = number_format(tc(mysql_query("select count(`id`) as `count` from `users` where `verified`=1")));
<td class="DataTD"><?=number_format($certs)?></td> $stats['verified_emails'] = number_format(tc(mysql_query("select count(`id`) as `count` from `email` where `hash`='' and `deleted`=0")));
</tr> $stats['verified_domains'] = number_format(tc(mysql_query("select count(`id`) as `count` from `domains` where `hash`='' and `deleted`=0")));
<tr> $certs = tc(mysql_query("select count(`id`) as `count` from `domaincerts`"));
<td class="DataTD"><?=_("Assurances Made")?>:</td> $certs += tc(mysql_query("select count(`id`) as `count` from `emailcerts`"));
<td class="DataTD"><?=number_format(tc(mysql_query("select count(`id`) as `count` from `notary`")))?></td> $certs += tc(mysql_query("select count(`id`) as `count` from `gpg`"));
</tr> $certs += tc(mysql_query("select count(`id`) as `count` from `orgdomaincerts`"));
<tr> $certs += tc(mysql_query("select count(`id`) as `count` from `orgemailcerts`"));
<td class="DataTD"><?=_("Users with 1-49 Points")?>:</td> $stats['verified_certificates'] = number_format($certs);
<td class="DataTD"><?=number_format(mysql_num_rows(mysql_query("select `to` from `notary` group by `to` having sum(`points`) > 0 and sum(`points`) < 50")))?></td> $certs = tc(mysql_query("select count(`id`) as `count` from `domaincerts` where `revoked`=0 and `expire`>NOW()"));
</tr> $certs += tc(mysql_query("select count(`id`) as `count` from `emailcerts` where `revoked`=0 and `expire`>NOW()"));
<tr> $certs += tc(mysql_query("select count(`id`) as `count` from `gpg` where `expire`<=NOW()"));
<td class="DataTD"><?=_("Users with 50-99 Points")?>:</td> $certs += tc(mysql_query("select count(`id`) as `count` from `orgdomaincerts` where `revoked`=0 and `expire`>NOW()"));
<td class="DataTD"><?=number_format(mysql_num_rows(mysql_query("select `to` from `notary` group by `to` having sum(`points`) >= 50 and sum(`points`) < 100")))?></td> $certs += tc(mysql_query("select count(`id`) as `count` from `orgemailcerts` where `revoked`=0 and `expire`>NOW()"));
</tr> $stats['valid_certificates'] = number_format($certs);
<tr> $stats['assurances_made'] = number_format(tc(mysql_query("select count(`id`) as `count` from `notary`")));
<td class="DataTD"><?=_("Assurer Candidates")?>:</td> $stats['users_1to49'] = number_format(mysql_num_rows(mysql_query("select `to` from `notary` group by `to` having sum(`points`) > 0 and sum(`points`) < 50")));
<td class="DataTD"><?=number_format($assurercandidates)?></td> $stats['users_50to99'] = number_format(mysql_num_rows(mysql_query("select `to` from `notary` group by `to` having sum(`points`) >= 50 and sum(`points`) < 100")));
</tr> $stats['assurer_candidates'] = number_format(tc(mysql_query("select count(*) as `count` from `users` where ".
<tr> "not exists(select 1 from `cats_passed` as `cp`, `cats_variant` as `cv` where `cp`.`user_id`=`users`.`id` and `cp`.`variant_id`=`cv`.`id` and `cv`.`type_id`=1) and ".
<td class="DataTD"><?=_("Assurers with test")?>:</td> "(select sum(`points`) from `notary` where `to`=`users`.`id`) >= 100")));
<td class="DataTD"><?=number_format($realassurers)?></td> $stats['aussurers_with_test'] = number_format(tc(mysql_query("select count(*) as `count` from `users` where ".
</tr> "exists(select 1 from `cats_passed` as `cp`, `cats_variant` as `cv` where `cp`.`user_id`=`users`.`id` and `cp`.`variant_id`=`cv`.`id` and `cv`.`type_id`=1) and ".
<tr><? $drow = mysql_fetch_assoc(mysql_query("select sum(`points`) as `points` from `notary`")); ?> "(select sum(`points`) from `notary` where `to`=`users`.`id`) >= 100")));
<td class="DataTD"><?=_("Points Issued")?>:</td> $stats['points_issued'] = number_format(tc(mysql_query("select sum(`points`) as `count` from `notary`")));
<td class="DataTD"><?=number_format($drow['points'])?></td>
</tr> $totalusers=0;
</table> $totassurers=0;
<br> $totalcerts=0;
<table align="center" valign="middle" border="0" cellspacing="0" cellpadding="0" class="wrapper"> for($i = 0; $i < 12; $i++) {
<tr> $tmp_arr = array();
<td colspan="4" class="title">CAcert.org <?=_("Growth in the last 12 months")?></td> $tmp_arr['date'] = date("Y-m", mktime(0,0,0,date("m") - $i,1,date("Y")));
</tr> $date = date("Y-m", mktime(0,0,0,date("m") - $i,1,date("Y")));
<tr> $totalusers += $users = tc(mysql_query("select count(`id`) as `count` from `users` where `created` like '$date%' and `verified`=1"));
<td class="DataTD"><b><?=_("Date")?></b> $totassurers += $assurers = mysql_num_rows(mysql_query("select `to` from `notary` where `when` like '$date%' and `method`!='Administrative Increase' group by `to` having sum(`points`) >= 100"));
<td class="DataTD"><b><?=_("New Users")?></b> $certs = tc(mysql_query("select count(`id`) as `count` from `domaincerts` where `created` like '$date%'"));
<td class="DataTD"><b><?=_("New Assurers")?></b> $certs += tc(mysql_query("select count(`id`) as `count` from `emailcerts` where `created` like '$date%'"));
<td class="DataTD"><b><?=_("New Certificates")?></b> $certs += tc(mysql_query("select count(`id`) as `count` from `gpg` where `issued` like '$date%'"));
</tr> $certs += tc(mysql_query("select count(`id`) as `count` from `orgdomaincerts` where `created` like '$date%'"));
<? $certs += tc(mysql_query("select count(`id`) as `count` from `orgemailcerts` where `created` like '$date%'"));
$totalusers=0; $totalcerts += $certs;
$totassurers=0;
$totalcerts=0; $tmp_arr['new_users'] = number_format($users);
for($i = 0; $i < 12; $i++) { $tmp_arr['new_assurers'] = number_format($assurers);
$date = date("Y-m", mktime(0,0,0,date("m") - $i,1,date("Y"))); $tmp_arr['new_certificates'] = number_format($certs);
$totalusers += $users = tc(mysql_query("select count(`id`) as `count` from `users` where `created` like '$date%' and `verified`=1"));
$totassurers += $assurers = mysql_num_rows(mysql_query("select `to` from `notary` where `when` like '$date%' and `method`!='Administrative Increase' group by `to` having sum(`points`) >= 100")); $stats['growth_last_12m'][] = $tmp_arr;
$certs = tc(mysql_query("select count(`id`) as `count` from `domaincerts` where `created` like '$date%'")); }
$certs += tc(mysql_query("select count(`id`) as `count` from `emailcerts` where `created` like '$date%'")); $stats['growth_last_12m_total'] = array('new_users' => number_format($totalusers),
$certs += tc(mysql_query("select count(`id`) as `count` from `gpg` where `issued` like '$date%'")); 'new_assurers' => number_format($totassurers),
$certs += tc(mysql_query("select count(`id`) as `count` from `orgdomaincerts` where `created` like '$date%'")); 'new_certificates' => number_format($totalcerts));
$certs += tc(mysql_query("select count(`id`) as `count` from `orgemailcerts` where `created` like '$date%'"));
$totalcerts += $certs; $totalcerts = 0;
?> $totalusers = 0;
<tr> $totassurers = 0;
<td class="DataTD"><?=$date?></td> for($i = date("Y"); $i >= 2002; $i--) {
<td class="DataTD"><?=number_format($users)?></td> $tmp_arr = array();
<td class="DataTD"><?=number_format($assurers)?></td> $tmp_arr['date'] = $i;
<td class="DataTD"><?=number_format($certs)?></td> $totalusers += $users = tc(mysql_query("select count(`id`) as `count` from `users` where `created` like '$i%' and `verified`=1"));
</tr> $totassurers += $assurers = mysql_num_rows(mysql_query("select `to` from `notary` where `when` like '$i%' and `method`!='Administrative Increase' group by `to` having sum(`points`) >= 100"));
<? } ?> $certs = tc(mysql_query("select count(`id`) as `count` from `domaincerts` where `created` like '$i%'"));
<tr> $certs += tc(mysql_query("select count(`id`) as `count` from `emailcerts` where `created` like '$i%'"));
<td class="DataTD">N/A</td> $certs += tc(mysql_query("select count(`id`) as `count` from `gpg` where `issued` like '$i%'"));
<td class="DataTD"><?=number_format($totalusers)?></td> $certs += tc(mysql_query("select count(`id`) as `count` from `orgdomaincerts` where `created` like '$i%'"));
<td class="DataTD"><?=number_format($totassurers)?></td> $certs += tc(mysql_query("select count(`id`) as `count` from `orgemailcerts` where `created` like '$i%'"));
<td class="DataTD"><?=number_format($totalcerts)?></td> $totalcerts += $certs;
</tr>
</table> $tmp_arr['new_users'] = number_format($users);
<br> $tmp_arr['new_assurers'] = number_format($assurers);
<table align="center" valign="middle" border="0" cellspacing="0" cellpadding="0" class="wrapper"> $tmp_arr['new_certificates'] = number_format($certs);
<tr>
<td colspan="4" class="title">CAcert.org <?=_("Growth by year")?></td> $stats['growth_last_years'][] = $tmp_arr;
</tr> }
<tr> $stats['growth_last_years_total'] = array('new_users' => number_format($totalusers),
<td class="DataTD"><b><?=_("Date")?></b> 'new_assurers' => number_format($totassurers),
<td class="DataTD"><b><?=_("New Users")?></b> 'new_certificates' => number_format($totalcerts));
<td class="DataTD"><b><?=_("New Assurers")?></b>
<td class="DataTD"><b><?=_("New Certificates")?></b> return $stats;
</tr> }
<?
$totalcerts = $totalusers = $totassurers = 0; $stats = getData();
for($i = date("Y"); $i >= 2002; $i--) { ?>
$totalusers += $users = tc(mysql_query("select count(`id`) as `count` from `users` where `created` like '$i%' and `verified`=1")); <h1>CAcert.org <?=_("Statistics")?></h1>
$totassurers += $assurers = mysql_num_rows(mysql_query("select `to` from `notary` where `when` like '$i%' and `method`!='Administrative Increase' group by `to` having sum(`points`) >= 100"));
$certs = tc(mysql_query("select count(`id`) as `count` from `domaincerts` where `created` like '$i%'")); <table align="center" border="0" cellspacing="0" cellpadding="0" class="wrapper">
$certs += tc(mysql_query("select count(`id`) as `count` from `emailcerts` where `created` like '$i%'")); <tr>
$certs += tc(mysql_query("select count(`id`) as `count` from `gpg` where `issued` like '$i%'")); <td colspan="2" class="title">CAcert.org <?=_("Statistics")?></td>
$certs += tc(mysql_query("select count(`id`) as `count` from `orgdomaincerts` where `created` like '$i%'")); </tr>
$certs += tc(mysql_query("select count(`id`) as `count` from `orgemailcerts` where `created` like '$i%'")); <tr>
$totalcerts += $certs; <td class="DataTD"><?=_("Verified Users")?>:</td>
?> <td class="DataTD"><?=$stats['verified_users'];?></td>
<tr> </tr>
<td class="DataTD"><?=$i?></td> <tr>
<td class="DataTD"><?=number_format($users)?></td> <td class="DataTD"><?=_("Verified Emails")?>:</td>
<td class="DataTD"><?=number_format($assurers)?></td> <td class="DataTD"><?=$stats['verified_emails'];?></td>
<td class="DataTD"><?=number_format($certs)?></td> </tr>
</tr> <tr>
<? } ?> <td class="DataTD"><?=_("Verified Domains")?>:</td>
<tr> <td class="DataTD"><?=$stats['verified_domains'];?></td>
<td class="DataTD">N/A</td> </tr>
<td class="DataTD"><?=number_format($totalusers)?></td> <tr>
<td class="DataTD"><?=number_format($totassurers)?></td> <td class="DataTD"><?=_("Certificates Issued")?>:</td>
<td class="DataTD"><?=number_format($totalcerts)?></td> <td class="DataTD"><?=$stats['verified_certificates'];?></td>
</tr> </tr>
</table> <tr>
<br> <td class="DataTD"><?=_("Valid Certificates")?>:</td>
<? showfooter(); ?> <td class="DataTD"><?=$stats['valid_certificates'];?></td>
</tr>
<tr>
<td class="DataTD"><?=_("Assurances Made")?>:</td>
<td class="DataTD"><?=$stats['assurances_made'];?></td>
</tr>
<tr>
<td class="DataTD"><?=_("Users with 1-49 Points")?>:</td>
<td class="DataTD"><?=$stats['users_1to49'];?></td>
</tr>
<tr>
<td class="DataTD"><?=_("Users with 50-99 Points")?>:</td>
<td class="DataTD"><?=$stats['users_50to99'];?></td>
</tr>
<tr>
<td class="DataTD"><?=_("Assurer Candidates")?>:</td>
<td class="DataTD"><?=$stats['assurer_candidates'];?></td>
</tr>
<tr>
<td class="DataTD"><?=_("Assurers with test")?>:</td>
<td class="DataTD"><?=$stats['aussurers_with_test'];?></td>
</tr>
<tr>
<td class="DataTD"><?=_("Points Issued")?>:</td>
<td class="DataTD"><?=$stats['points_issued'];?></td>
</tr>
</table>
<br>
<table align="center" border="0" cellspacing="0" cellpadding="0" class="wrapper">
<tr>
<td colspan="4" class="title">CAcert.org <?=_("Growth in the last 12 months")?></td>
</tr>
<tr>
<td class="DataTD"><b><?=_("Date")?></b>
<td class="DataTD"><b><?=_("New Users")?></b>
<td class="DataTD"><b><?=_("New Assurers")?></b>
<td class="DataTD"><b><?=_("New Certificates")?></b>
</tr>
<?
for($i = 0; $i < 12; $i++) {
?>
<tr>
<td class="DataTD"><?=$stats['growth_last_12m'][$i]['date'];?></td>
<td class="DataTD"><?=$stats['growth_last_12m'][$i]['new_users'];?></td>
<td class="DataTD"><?=$stats['growth_last_12m'][$i]['new_assurers'];?></td>
<td class="DataTD"><?=$stats['growth_last_12m'][$i]['new_certificates'];?></td>
</tr>
<? } ?>
<tr>
<td class="DataTD">N/A</td>
<td class="DataTD"><?=$stats['growth_last_12m_total']['new_users'];?></td>
<td class="DataTD"><?=$stats['growth_last_12m_total']['new_assurers'];?></td>
<td class="DataTD"><?=$stats['growth_last_12m_total']['new_certificates'];?></td>
</tr>
</table>
<br>
<table align="center" border="0" cellspacing="0" cellpadding="0" class="wrapper">
<tr>
<td colspan="4" class="title">CAcert.org <?=_("Growth by year")?></td>
</tr>
<tr>
<td class="DataTD"><b><?=_("Date")?></b>
<td class="DataTD"><b><?=_("New Users")?></b>
<td class="DataTD"><b><?=_("New Assurers")?></b>
<td class="DataTD"><b><?=_("New Certificates")?></b>
</tr>
<?
for($i = 0; $i < count($stats['growth_last_years']); $i++) {
?>
<tr>
<td class="DataTD"><?=$stats['growth_last_years'][$i]['date'];?></td>
<td class="DataTD"><?=$stats['growth_last_years'][$i]['new_users'];?></td>
<td class="DataTD"><?=$stats['growth_last_years'][$i]['new_assurers'];?></td>
<td class="DataTD"><?=$stats['growth_last_years'][$i]['new_certificates'];?></td>
</tr>
<? } ?>
<tr>
<td class="DataTD">N/A</td>
<td class="DataTD"><?=$stats['growth_last_years_total']['new_users'];?></td>
<td class="DataTD"><?=$stats['growth_last_years_total']['new_assurers'];?></td>
<td class="DataTD"><?=$stats['growth_last_years_total']['new_certificates'];?></td>
</tr>
</table>
<br>
<?php
if (isset($stats['timestamp'])) {
?>
<div style="text-align: center;font-size: small;"><?=_("Statistical data from cache, created at ") . date('Y-m-d H:i:s', $stats['timestamp']);?></div>
<?php
}
?>
<? showfooter(); ?>

Loading…
Cancel
Save