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:
Wytze van der Raay 2014-06-07 09:13:27 +00:00
parent 14aafe2212
commit 42f16aab95
5 changed files with 60 additions and 58 deletions

View file

@ -441,7 +441,7 @@ sub calculateDays($)
{ {
if($_[0]) 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); SysLog("Summe: $sum[0]\n") if($debug);
return ($sum[0]>=50)?730:180; return ($sum[0]>=50)?730:180;

View file

@ -425,7 +425,7 @@ sub calculateDays($)
{ {
if($_[0]) 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); SysLog("Summe: $sum[0]\n") if($debug);
return ($sum[0]>=50)?730:180; return ($sum[0]>=50)?730:180;

View file

@ -19,10 +19,10 @@
/** /**
* Function to recalculate the cached Assurer status * Function to recalculate the cached Assurer status
* *
* @param int $userID * @param int $userID
* if the user ID is not given the flag will be recalculated for all users * if the user ID is not given the flag will be recalculated for all users
* *
* @return bool * @return bool
* false if there was an error on fixing the flag. This does NOT return the * false if there was an error on fixing the flag. This does NOT return the
* new value of the flag * new value of the flag
@ -30,7 +30,7 @@
function fix_assurer_flag($userID = NULL) function fix_assurer_flag($userID = NULL)
{ {
// Update Assurer-Flag on users table if 100 points and CATS passed. // Update Assurer-Flag on users table if 100 points and CATS passed.
// //
// We may have some performance issues here if no userID is given // We may have some performance issues here if no userID is given
// there are ~150k assurances and ~220k users currently // there are ~150k assurances and ~220k users currently
// but the exists-clause on cats_passed should be a good filter // 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` WHERE `cp`.`variant_id` = `cv`.`id`
AND `cv`.`type_id` = 1 AND `cv`.`type_id` = 1
AND `cp`.`user_id` = `u`.`id` AND `cp`.`user_id` = `u`.`id`
) )
AND ( AND (
SELECT SUM(`points`) FROM `notary` AS `n` SELECT SUM(`points`) FROM `notary` AS `n`
WHERE `n`.`to` = `u`.`id` WHERE `n`.`to` = `u`.`id`
AND (`n`.`expire` > now() AND (`n`.`expire` > now()
OR `n`.`expire` IS NULL) OR `n`.`expire` IS NULL)
AND `n`.`deleted` = 0
) >= 100'; ) >= 100';
$query = mysql_query($sql); $query = mysql_query($sql);
if (!$query) { if (!$query) {
return false; return false;
} }
// Challenge has been passed and non-expired points >= 100 // Challenge has been passed and non-expired points >= 100
// Reset flag if requirements are not met // Reset flag if requirements are not met
// //
// Also a bit performance critical but assurer flag is only set on // 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() `n`.`expire` > now()
OR `n`.`expire` IS NULL OR `n`.`expire` IS NULL
) )
AND `n`.`deleted` = 0
) < 100 ) < 100
)'; )';
$query = mysql_query($sql); $query = mysql_query($sql);
if (!$query) { if (!$query) {
return false; return false;
} }
return true; return true;
} }

View file

@ -18,10 +18,10 @@
/** /**
* Checks if the user may log in and retrieve the user id * Checks if the user may log in and retrieve the user id
* *
* Usually called with $_SERVER['SSL_CLIENT_M_SERIAL'] and * Usually called with $_SERVER['SSL_CLIENT_M_SERIAL'] and
* $_SERVER['SSL_CLIENT_I_DN_CN'] * $_SERVER['SSL_CLIENT_I_DN_CN']
* *
* @param $serial string * @param $serial string
* usually $_SERVER['SSL_CLIENT_M_SERIAL'] * usually $_SERVER['SSL_CLIENT_M_SERIAL']
* @param $issuer_cn string * @param $issuer_cn string
@ -43,7 +43,7 @@ function get_user_id_from_cert($serial, $issuer_cn)
$row = mysql_fetch_assoc($res); $row = mysql_fetch_assoc($res);
return intval($row['memid']); return intval($row['memid']);
} }
return -1; return -1;
} }
@ -71,7 +71,7 @@ function failWithId($errormessage) {
/** /**
* Runs a command on the shell and return it's exit code and output * Runs a command on the shell and return it's exit code and output
* *
* @param string $command * @param string $command
* The command to run. Make sure that you escapeshellarg() any non-constant * The command to run. Make sure that you escapeshellarg() any non-constant
* parts as this is executed on a shell! * parts as this is executed on a shell!
@ -85,7 +85,7 @@ function failWithId($errormessage) {
* @param string|bool $errors * @param string|bool $errors
* The output the command wrote to STDERR (this is passed as reference), * The output the command wrote to STDERR (this is passed as reference),
* if true (default) the output will be written to the real STDERR * if true (default) the output will be written to the real STDERR
* *
* @return int|bool * @return int|bool
* The exit code of the command, true if the execution of the command * The exit code of the command, true if the execution of the command
* failed (true because then * failed (true because then
@ -93,38 +93,38 @@ function failWithId($errormessage) {
*/ */
function runCommand($command, $input = "", &$output = null, &$errors = true) { function runCommand($command, $input = "", &$output = null, &$errors = true) {
$descriptorspec = array(); $descriptorspec = array();
if ($input !== true) { if ($input !== true) {
$descriptorspec[0] = array("pipe", "r"); // STDIN for child $descriptorspec[0] = array("pipe", "r"); // STDIN for child
} }
if ($output !== true) { if ($output !== true) {
$descriptorspec[1] = array("pipe", "w"); // STDOUT for child $descriptorspec[1] = array("pipe", "w"); // STDOUT for child
} }
if ($errors !== true) { if ($errors !== true) {
$descriptorspec[2] = array("pipe", "w"); // STDERR for child $descriptorspec[2] = array("pipe", "w"); // STDERR for child
} }
$proc = proc_open($command, $descriptorspec, $pipes); $proc = proc_open($command, $descriptorspec, $pipes);
if (is_resource($proc)) if (is_resource($proc))
{ {
if ($input !== true) { if ($input !== true) {
fwrite($pipes[0], $input); fwrite($pipes[0], $input);
fclose($pipes[0]); fclose($pipes[0]);
} }
if ($output !== true) { if ($output !== true) {
$output = stream_get_contents($pipes[1]); $output = stream_get_contents($pipes[1]);
} }
if ($errors !== true) { if ($errors !== true) {
$errors = stream_get_contents($pipes[2]); $errors = stream_get_contents($pipes[2]);
} }
return proc_close($proc); return proc_close($proc);
} else { } else {
return true; return true;
} }
@ -145,19 +145,18 @@ function runCommand($command, $input = "", &$output = null, &$errors = true) {
{ {
$Result |= 5; $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); $row = mysql_fetch_assoc($query);
if ($row['points'] < 100) { if ($row['points'] < 100) {
$Result |= 3; $Result |= 3;
} }
$query = mysql_query('SELECT `assurer_blocked` FROM `users` WHERE `id` = \''.(int)intval($userID).'\''); $query = mysql_query('SELECT `assurer_blocked` FROM `users` WHERE `id` = \''.(int)intval($userID).'\'');
$row = mysql_fetch_assoc($query); $row = mysql_fetch_assoc($query);
if ($row['assurer_blocked'] > 0) { if ($row['assurer_blocked'] > 0) {
$Result |= 9; $Result |= 9;
} }
return $Result; return $Result;
} }

View file

@ -23,7 +23,7 @@ require_once(dirname(__FILE__).'/../../includes/mysql.php');
/** /**
* Wrapper around mysql_query() to provide some error handling. Prints an error * Wrapper around mysql_query() to provide some error handling. Prints an error
* message and dies if query fails * message and dies if query fails
* *
* @param string $sql * @param string $sql
* the SQL statement to execute * the SQL statement to execute
* @return resource|boolean * @return resource|boolean
@ -35,7 +35,7 @@ function sql_query($sql) {
fwrite(STDERR, "MySQL query failed:\n\"$sql\"\n".mysql_error()); fwrite(STDERR, "MySQL query failed:\n\"$sql\"\n".mysql_error());
die(1); die(1);
} }
return $res; return $res;
} }
@ -54,7 +54,7 @@ function updateCache($stats) {
$sql = "insert into `statscache` (`timestamp`, `cache`) values $sql = "insert into `statscache` (`timestamp`, `cache`) values
('$timestamp', '".mysql_real_escape_string(serialize($stats))."')"; ('$timestamp', '".mysql_real_escape_string(serialize($stats))."')";
sql_query($sql); sql_query($sql);
// Make sure the new statistic was inserted successfully // Make sure the new statistic was inserted successfully
$res = sql_query( $res = sql_query(
"select 1 from `statscache` where `timestamp` = '$timestamp'"); "select 1 from `statscache` where `timestamp` = '$timestamp'");
@ -62,7 +62,7 @@ function updateCache($stats) {
fwrite(STDERR, "Error on inserting the new statistic"); fwrite(STDERR, "Error on inserting the new statistic");
return false; return false;
} }
sql_query("delete from `statscache` where `timestamp` != '$timestamp'"); sql_query("delete from `statscache` where `timestamp` != '$timestamp'");
return true; return true;
} }
@ -74,22 +74,22 @@ function updateCache($stats) {
*/ */
function getDataFromLive() { function getDataFromLive() {
echo "Calculating current statistics\n"; echo "Calculating current statistics\n";
$stats = array(); $stats = array();
$stats['verified_users'] = number_format(tc( $stats['verified_users'] = number_format(tc(
"select count(*) as `count` from `users` "select count(*) as `count` from `users`
where `verified` = 1 where `verified` = 1
and `deleted` = 0 and `deleted` = 0
and `locked` = 0")); and `locked` = 0"));
$stats['verified_emails'] = number_format(tc( $stats['verified_emails'] = number_format(tc(
"select count(*) as `count` from `email` "select count(*) as `count` from `email`
where `hash` = '' and `deleted` = 0")); where `hash` = '' and `deleted` = 0"));
$stats['verified_domains'] = number_format(tc( $stats['verified_domains'] = number_format(tc(
"select count(*) as `count` from `domains` "select count(*) as `count` from `domains`
where `hash` = '' and `deleted` = 0")); where `hash` = '' and `deleted` = 0"));
$certs = tc("select count(*) as `count` from `domaincerts` $certs = tc("select count(*) as `count` from `domaincerts`
where `expire` != 0"); where `expire` != 0");
$certs += tc("select count(*) as `count` from `emailcerts` $certs += tc("select count(*) as `count` from `emailcerts`
@ -101,7 +101,7 @@ function getDataFromLive() {
$certs += tc("select count(*) as `count` from `orgemailcerts` $certs += tc("select count(*) as `count` from `orgemailcerts`
where `expire` != 0"); where `expire` != 0");
$stats['verified_certificates'] = number_format($certs); $stats['verified_certificates'] = number_format($certs);
$certs = tc("select count(*) as `count` from `domaincerts` $certs = tc("select count(*) as `count` from `domaincerts`
where `revoked` = 0 and `expire` > NOW()"); where `revoked` = 0 and `expire` > NOW()");
$certs += tc("select count(*) as `count` from `emailcerts` $certs += tc("select count(*) as `count` from `emailcerts`
@ -113,11 +113,12 @@ function getDataFromLive() {
$certs += tc("select count(*) as `count` from `orgemailcerts` $certs += tc("select count(*) as `count` from `orgemailcerts`
where `revoked` = 0 and `expire` > NOW()"); where `revoked` = 0 and `expire` > NOW()");
$stats['valid_certificates'] = number_format($certs); $stats['valid_certificates'] = number_format($certs);
$stats['assurances_made'] = number_format(tc( $stats['assurances_made'] = number_format(tc(
"select count(*) as `count` from `notary` "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( $stats['users_1to49'] = number_format(tc(
"select count(*) as `count` from ( "select count(*) as `count` from (
select 1 from `notary` select 1 from `notary`
@ -125,7 +126,7 @@ function getDataFromLive() {
group by `to` group by `to`
having sum(`points`) > 0 and sum(`points`) < 50 having sum(`points`) > 0 and sum(`points`) < 50
) as `low_points`")); ) as `low_points`"));
$stats['users_50to99'] = number_format(tc( $stats['users_50to99'] = number_format(tc(
"select count(*) as `count` from ( "select count(*) as `count` from (
select 1 from `notary` select 1 from `notary`
@ -133,7 +134,7 @@ function getDataFromLive() {
group by `to` group by `to`
having sum(`points`) >= 50 and sum(`points`) < 100 having sum(`points`) >= 50 and sum(`points`) < 100
) as `high_points`")); ) as `high_points`"));
$stats['assurer_candidates'] = number_format(tc( $stats['assurer_candidates'] = number_format(tc(
"select count(*) as `count` from `users` "select count(*) as `count` from `users`
where ( where (
@ -148,7 +149,7 @@ function getDataFromLive() {
and `cv`.`type_id`=1 and `cv`.`type_id`=1
)" )"
)); ));
$stats['aussurers_with_test'] = number_format(tc( $stats['aussurers_with_test'] = number_format(tc(
"select count(*) as `count` from `users` "select count(*) as `count` from `users`
where ( where (
@ -163,7 +164,7 @@ function getDataFromLive() {
and `cv`.`type_id`=1 and `cv`.`type_id`=1
)" )"
)); ));
$stats['points_issued'] = number_format(tc( $stats['points_issued'] = number_format(tc(
"select sum(greatest(`points`, `awarded`)) as `count` from `notary` "select sum(greatest(`points`, `awarded`)) as `count` from `notary`
where `deleted` = 0 where `deleted` = 0
@ -177,16 +178,16 @@ function getDataFromLive() {
$next_month_ts = mktime(0, 0, 0, date("m") - $i + 1, 1, date("Y")); $next_month_ts = mktime(0, 0, 0, date("m") - $i + 1, 1, date("Y"));
$first = date("Y-m-d", $first_ts); $first = date("Y-m-d", $first_ts);
$next_month = date("Y-m-d", $next_month_ts); $next_month = date("Y-m-d", $next_month_ts);
echo "Calculating statistics for month $first\n"; echo "Calculating statistics for month $first\n";
$totalusers += $users = tc( $totalusers += $users = tc(
"select count(*) as `count` from `users` "select count(*) as `count` from `users`
where `created` >= '$first' and `created` < '$next_month' where `created` >= '$first' and `created` < '$next_month'
and `verified` = 1 and `verified` = 1
and `deleted` = 0 and `deleted` = 0
and `locked` = 0"); and `locked` = 0");
$totassurers += $assurers = tc( $totassurers += $assurers = tc(
"select count(*) as `count` from ( "select count(*) as `count` from (
select 1 from `notary` select 1 from `notary`
@ -195,7 +196,7 @@ function getDataFromLive() {
and `deleted` = 0 and `deleted` = 0
group by `to` having sum(`points`) >= 100 group by `to` having sum(`points`) >= 100
) as `assurer_candidates`"); ) as `assurer_candidates`");
$certs = tc( $certs = tc(
"select count(*) as `count` from `domaincerts` "select count(*) as `count` from `domaincerts`
where `created` >= '$first' and `created` < '$next_month' where `created` >= '$first' and `created` < '$next_month'
@ -240,16 +241,16 @@ function getDataFromLive() {
$next_year_ts = mktime(0, 0, 0, 1, 1, $i + 1); $next_year_ts = mktime(0, 0, 0, 1, 1, $i + 1);
$first = date("Y-m-d", $first_ts); $first = date("Y-m-d", $first_ts);
$next_year = date("Y-m-d", $next_year_ts); $next_year = date("Y-m-d", $next_year_ts);
echo "Calculating statistics for year $i\n"; echo "Calculating statistics for year $i\n";
$totalusers += $users = tc( $totalusers += $users = tc(
"select count(*) as `count` from `users` "select count(*) as `count` from `users`
where `created` >= '$first' and `created` < '$next_year' where `created` >= '$first' and `created` < '$next_year'
and `verified` = 1 and `verified` = 1
and `deleted` = 0 and `deleted` = 0
and `locked` = 0"); and `locked` = 0");
$totassurers += $assurers = tc( $totassurers += $assurers = tc(
"select count(*) as `count` from ( "select count(*) as `count` from (
select 1 from `notary` select 1 from `notary`
@ -258,7 +259,7 @@ function getDataFromLive() {
and `deleted` = 0 and `deleted` = 0
group by `to` having sum(`points`) >= 100 group by `to` having sum(`points`) >= 100
) as `assurer_candidates`"); ) as `assurer_candidates`");
$certs = tc( $certs = tc(
"select count(*) as `count` from `domaincerts` "select count(*) as `count` from `domaincerts`
where `created` >= '$first' and `created` < '$next_year' where `created` >= '$first' and `created` < '$next_year'
@ -286,7 +287,7 @@ function getDataFromLive() {
$tmp_arr['new_users'] = number_format($users); $tmp_arr['new_users'] = number_format($users);
$tmp_arr['new_assurers'] = number_format($assurers); $tmp_arr['new_assurers'] = number_format($assurers);
$tmp_arr['new_certificates'] = number_format($certs); $tmp_arr['new_certificates'] = number_format($certs);
$stats['growth_last_years'][] = $tmp_arr; $stats['growth_last_years'][] = $tmp_arr;
} }
$stats['growth_last_years_total'] = array( $stats['growth_last_years_total'] = array(