Combined fixes for
- https://bugs.cacert.org/view.php?id=413 "Add a web page indicating the certificate request is still pending" - https://bugs.cacert.org/view.php?id=1138 "Implement to log the SE activity" - https://bugs.cacert.org/view.php?id=1221 "Inconsistency in Assurance Management"
This commit is contained in:
parent
14aafe2212
commit
42f16aab95
5 changed files with 60 additions and 58 deletions
|
@ -441,7 +441,7 @@ sub calculateDays($)
|
|||
{
|
||||
if($_[0])
|
||||
{
|
||||
my @sum = $dbh->selectrow_array("select sum(`points`) as `total` from `notary` where `to`='".$_[0]."' group by `to`");
|
||||
my @sum = $dbh->selectrow_array("select sum(`points`) as `total` from `notary` where `to`='".$_[0]."' and `deleted`=0 group by `to`");
|
||||
SysLog("Summe: $sum[0]\n") if($debug);
|
||||
|
||||
return ($sum[0]>=50)?730:180;
|
||||
|
|
|
@ -425,7 +425,7 @@ sub calculateDays($)
|
|||
{
|
||||
if($_[0])
|
||||
{
|
||||
my @sum = $dbh->selectrow_array("select sum(`points`) as `total` from `notary` where `to`='".$_[0]."' group by `to`");
|
||||
my @sum = $dbh->selectrow_array("select sum(`points`) as `total` from `notary` where `to`='".$_[0]."' and `deleted`=0 group by `to`");
|
||||
SysLog("Summe: $sum[0]\n") if($debug);
|
||||
|
||||
return ($sum[0]>=50)?730:180;
|
||||
|
|
|
@ -19,10 +19,10 @@
|
|||
|
||||
/**
|
||||
* Function to recalculate the cached Assurer status
|
||||
*
|
||||
*
|
||||
* @param int $userID
|
||||
* if the user ID is not given the flag will be recalculated for all users
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
* false if there was an error on fixing the flag. This does NOT return the
|
||||
* new value of the flag
|
||||
|
@ -30,7 +30,7 @@
|
|||
function fix_assurer_flag($userID = NULL)
|
||||
{
|
||||
// Update Assurer-Flag on users table if 100 points and CATS passed.
|
||||
//
|
||||
//
|
||||
// We may have some performance issues here if no userID is given
|
||||
// there are ~150k assurances and ~220k users currently
|
||||
// but the exists-clause on cats_passed should be a good filter
|
||||
|
@ -46,20 +46,21 @@ function fix_assurer_flag($userID = NULL)
|
|||
WHERE `cp`.`variant_id` = `cv`.`id`
|
||||
AND `cv`.`type_id` = 1
|
||||
AND `cp`.`user_id` = `u`.`id`
|
||||
)
|
||||
)
|
||||
AND (
|
||||
SELECT SUM(`points`) FROM `notary` AS `n`
|
||||
WHERE `n`.`to` = `u`.`id`
|
||||
AND (`n`.`expire` > now()
|
||||
OR `n`.`expire` IS NULL)
|
||||
OR `n`.`expire` IS NULL)
|
||||
AND `n`.`deleted` = 0
|
||||
) >= 100';
|
||||
|
||||
|
||||
$query = mysql_query($sql);
|
||||
if (!$query) {
|
||||
return false;
|
||||
}
|
||||
// Challenge has been passed and non-expired points >= 100
|
||||
|
||||
|
||||
// Reset flag if requirements are not met
|
||||
//
|
||||
// Also a bit performance critical but assurer flag is only set on
|
||||
|
@ -86,13 +87,14 @@ function fix_assurer_flag($userID = NULL)
|
|||
`n`.`expire` > now()
|
||||
OR `n`.`expire` IS NULL
|
||||
)
|
||||
AND `n`.`deleted` = 0
|
||||
) < 100
|
||||
)';
|
||||
|
||||
|
||||
$query = mysql_query($sql);
|
||||
if (!$query) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
|
||||
/**
|
||||
* Checks if the user may log in and retrieve the user id
|
||||
*
|
||||
*
|
||||
* Usually called with $_SERVER['SSL_CLIENT_M_SERIAL'] and
|
||||
* $_SERVER['SSL_CLIENT_I_DN_CN']
|
||||
*
|
||||
*
|
||||
* @param $serial string
|
||||
* usually $_SERVER['SSL_CLIENT_M_SERIAL']
|
||||
* @param $issuer_cn string
|
||||
|
@ -43,7 +43,7 @@ function get_user_id_from_cert($serial, $issuer_cn)
|
|||
$row = mysql_fetch_assoc($res);
|
||||
return intval($row['memid']);
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ function failWithId($errormessage) {
|
|||
|
||||
/**
|
||||
* Runs a command on the shell and return it's exit code and output
|
||||
*
|
||||
*
|
||||
* @param string $command
|
||||
* The command to run. Make sure that you escapeshellarg() any non-constant
|
||||
* parts as this is executed on a shell!
|
||||
|
@ -85,7 +85,7 @@ function failWithId($errormessage) {
|
|||
* @param string|bool $errors
|
||||
* The output the command wrote to STDERR (this is passed as reference),
|
||||
* if true (default) the output will be written to the real STDERR
|
||||
*
|
||||
*
|
||||
* @return int|bool
|
||||
* The exit code of the command, true if the execution of the command
|
||||
* failed (true because then
|
||||
|
@ -93,38 +93,38 @@ function failWithId($errormessage) {
|
|||
*/
|
||||
function runCommand($command, $input = "", &$output = null, &$errors = true) {
|
||||
$descriptorspec = array();
|
||||
|
||||
|
||||
if ($input !== true) {
|
||||
$descriptorspec[0] = array("pipe", "r"); // STDIN for child
|
||||
}
|
||||
|
||||
|
||||
if ($output !== true) {
|
||||
$descriptorspec[1] = array("pipe", "w"); // STDOUT for child
|
||||
}
|
||||
|
||||
|
||||
if ($errors !== true) {
|
||||
$descriptorspec[2] = array("pipe", "w"); // STDERR for child
|
||||
}
|
||||
|
||||
|
||||
$proc = proc_open($command, $descriptorspec, $pipes);
|
||||
|
||||
|
||||
if (is_resource($proc))
|
||||
{
|
||||
if ($input !== true) {
|
||||
fwrite($pipes[0], $input);
|
||||
fclose($pipes[0]);
|
||||
}
|
||||
|
||||
|
||||
if ($output !== true) {
|
||||
$output = stream_get_contents($pipes[1]);
|
||||
}
|
||||
|
||||
|
||||
if ($errors !== true) {
|
||||
$errors = stream_get_contents($pipes[2]);
|
||||
}
|
||||
|
||||
|
||||
return proc_close($proc);
|
||||
|
||||
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
@ -145,19 +145,18 @@ function runCommand($command, $input = "", &$output = null, &$errors = true) {
|
|||
{
|
||||
$Result |= 5;
|
||||
}
|
||||
|
||||
$query = mysql_query('SELECT SUM(`points`) AS `points` FROM `notary` AS `n` WHERE `n`.`to` = \''.(int)intval($userID).'\' AND `n`.`expire` < now()');
|
||||
|
||||
$query = mysql_query('SELECT SUM(`points`) AS `points` FROM `notary` AS `n` WHERE `n`.`to` = \''.(int)intval($userID).'\' AND `n`.`expire` < now() and `deleted` = 0');
|
||||
$row = mysql_fetch_assoc($query);
|
||||
if ($row['points'] < 100) {
|
||||
$Result |= 3;
|
||||
}
|
||||
|
||||
|
||||
$query = mysql_query('SELECT `assurer_blocked` FROM `users` WHERE `id` = \''.(int)intval($userID).'\'');
|
||||
$row = mysql_fetch_assoc($query);
|
||||
if ($row['assurer_blocked'] > 0) {
|
||||
$Result |= 9;
|
||||
}
|
||||
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ require_once(dirname(__FILE__).'/../../includes/mysql.php');
|
|||
/**
|
||||
* Wrapper around mysql_query() to provide some error handling. Prints an error
|
||||
* message and dies if query fails
|
||||
*
|
||||
*
|
||||
* @param string $sql
|
||||
* the SQL statement to execute
|
||||
* @return resource|boolean
|
||||
|
@ -35,7 +35,7 @@ function sql_query($sql) {
|
|||
fwrite(STDERR, "MySQL query failed:\n\"$sql\"\n".mysql_error());
|
||||
die(1);
|
||||
}
|
||||
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ function updateCache($stats) {
|
|||
$sql = "insert into `statscache` (`timestamp`, `cache`) values
|
||||
('$timestamp', '".mysql_real_escape_string(serialize($stats))."')";
|
||||
sql_query($sql);
|
||||
|
||||
|
||||
// Make sure the new statistic was inserted successfully
|
||||
$res = sql_query(
|
||||
"select 1 from `statscache` where `timestamp` = '$timestamp'");
|
||||
|
@ -62,7 +62,7 @@ function updateCache($stats) {
|
|||
fwrite(STDERR, "Error on inserting the new statistic");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
sql_query("delete from `statscache` where `timestamp` != '$timestamp'");
|
||||
return true;
|
||||
}
|
||||
|
@ -74,22 +74,22 @@ function updateCache($stats) {
|
|||
*/
|
||||
function getDataFromLive() {
|
||||
echo "Calculating current statistics\n";
|
||||
|
||||
|
||||
$stats = array();
|
||||
$stats['verified_users'] = number_format(tc(
|
||||
"select count(*) as `count` from `users`
|
||||
where `verified` = 1
|
||||
and `deleted` = 0
|
||||
and `locked` = 0"));
|
||||
|
||||
|
||||
$stats['verified_emails'] = number_format(tc(
|
||||
"select count(*) as `count` from `email`
|
||||
where `hash` = '' and `deleted` = 0"));
|
||||
|
||||
|
||||
$stats['verified_domains'] = number_format(tc(
|
||||
"select count(*) as `count` from `domains`
|
||||
where `hash` = '' and `deleted` = 0"));
|
||||
|
||||
|
||||
$certs = tc("select count(*) as `count` from `domaincerts`
|
||||
where `expire` != 0");
|
||||
$certs += tc("select count(*) as `count` from `emailcerts`
|
||||
|
@ -101,7 +101,7 @@ function getDataFromLive() {
|
|||
$certs += tc("select count(*) as `count` from `orgemailcerts`
|
||||
where `expire` != 0");
|
||||
$stats['verified_certificates'] = number_format($certs);
|
||||
|
||||
|
||||
$certs = tc("select count(*) as `count` from `domaincerts`
|
||||
where `revoked` = 0 and `expire` > NOW()");
|
||||
$certs += tc("select count(*) as `count` from `emailcerts`
|
||||
|
@ -113,11 +113,12 @@ function getDataFromLive() {
|
|||
$certs += tc("select count(*) as `count` from `orgemailcerts`
|
||||
where `revoked` = 0 and `expire` > NOW()");
|
||||
$stats['valid_certificates'] = number_format($certs);
|
||||
|
||||
|
||||
$stats['assurances_made'] = number_format(tc(
|
||||
"select count(*) as `count` from `notary`
|
||||
where `method` = '' or `method` = 'Face to Face Meeting'"));
|
||||
|
||||
where (`method` = '' or `method` = 'Face to Face Meeting')
|
||||
and `deleted` = 0"));
|
||||
|
||||
$stats['users_1to49'] = number_format(tc(
|
||||
"select count(*) as `count` from (
|
||||
select 1 from `notary`
|
||||
|
@ -125,7 +126,7 @@ function getDataFromLive() {
|
|||
group by `to`
|
||||
having sum(`points`) > 0 and sum(`points`) < 50
|
||||
) as `low_points`"));
|
||||
|
||||
|
||||
$stats['users_50to99'] = number_format(tc(
|
||||
"select count(*) as `count` from (
|
||||
select 1 from `notary`
|
||||
|
@ -133,7 +134,7 @@ function getDataFromLive() {
|
|||
group by `to`
|
||||
having sum(`points`) >= 50 and sum(`points`) < 100
|
||||
) as `high_points`"));
|
||||
|
||||
|
||||
$stats['assurer_candidates'] = number_format(tc(
|
||||
"select count(*) as `count` from `users`
|
||||
where (
|
||||
|
@ -148,7 +149,7 @@ function getDataFromLive() {
|
|||
and `cv`.`type_id`=1
|
||||
)"
|
||||
));
|
||||
|
||||
|
||||
$stats['aussurers_with_test'] = number_format(tc(
|
||||
"select count(*) as `count` from `users`
|
||||
where (
|
||||
|
@ -163,7 +164,7 @@ function getDataFromLive() {
|
|||
and `cv`.`type_id`=1
|
||||
)"
|
||||
));
|
||||
|
||||
|
||||
$stats['points_issued'] = number_format(tc(
|
||||
"select sum(greatest(`points`, `awarded`)) as `count` from `notary`
|
||||
where `deleted` = 0
|
||||
|
@ -177,16 +178,16 @@ function getDataFromLive() {
|
|||
$next_month_ts = mktime(0, 0, 0, date("m") - $i + 1, 1, date("Y"));
|
||||
$first = date("Y-m-d", $first_ts);
|
||||
$next_month = date("Y-m-d", $next_month_ts);
|
||||
|
||||
|
||||
echo "Calculating statistics for month $first\n";
|
||||
|
||||
|
||||
$totalusers += $users = tc(
|
||||
"select count(*) as `count` from `users`
|
||||
"select count(*) as `count` from `users`
|
||||
where `created` >= '$first' and `created` < '$next_month'
|
||||
and `verified` = 1
|
||||
and `deleted` = 0
|
||||
and `locked` = 0");
|
||||
|
||||
|
||||
$totassurers += $assurers = tc(
|
||||
"select count(*) as `count` from (
|
||||
select 1 from `notary`
|
||||
|
@ -195,7 +196,7 @@ function getDataFromLive() {
|
|||
and `deleted` = 0
|
||||
group by `to` having sum(`points`) >= 100
|
||||
) as `assurer_candidates`");
|
||||
|
||||
|
||||
$certs = tc(
|
||||
"select count(*) as `count` from `domaincerts`
|
||||
where `created` >= '$first' and `created` < '$next_month'
|
||||
|
@ -240,16 +241,16 @@ function getDataFromLive() {
|
|||
$next_year_ts = mktime(0, 0, 0, 1, 1, $i + 1);
|
||||
$first = date("Y-m-d", $first_ts);
|
||||
$next_year = date("Y-m-d", $next_year_ts);
|
||||
|
||||
|
||||
echo "Calculating statistics for year $i\n";
|
||||
|
||||
|
||||
$totalusers += $users = tc(
|
||||
"select count(*) as `count` from `users`
|
||||
"select count(*) as `count` from `users`
|
||||
where `created` >= '$first' and `created` < '$next_year'
|
||||
and `verified` = 1
|
||||
and `deleted` = 0
|
||||
and `locked` = 0");
|
||||
|
||||
|
||||
$totassurers += $assurers = tc(
|
||||
"select count(*) as `count` from (
|
||||
select 1 from `notary`
|
||||
|
@ -258,7 +259,7 @@ function getDataFromLive() {
|
|||
and `deleted` = 0
|
||||
group by `to` having sum(`points`) >= 100
|
||||
) as `assurer_candidates`");
|
||||
|
||||
|
||||
$certs = tc(
|
||||
"select count(*) as `count` from `domaincerts`
|
||||
where `created` >= '$first' and `created` < '$next_year'
|
||||
|
@ -286,7 +287,7 @@ function getDataFromLive() {
|
|||
$tmp_arr['new_users'] = number_format($users);
|
||||
$tmp_arr['new_assurers'] = number_format($assurers);
|
||||
$tmp_arr['new_certificates'] = number_format($certs);
|
||||
|
||||
|
||||
$stats['growth_last_years'][] = $tmp_arr;
|
||||
}
|
||||
$stats['growth_last_years_total'] = array(
|
||||
|
|
Loading…
Reference in a new issue