From f26bbb022a0a115e793ac97939e988efbf6fe929 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 11 Feb 2024 18:07:55 +0100 Subject: [PATCH] Fix delay --- dev/tools/apstats.php | 107 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 94 insertions(+), 13 deletions(-) diff --git a/dev/tools/apstats.php b/dev/tools/apstats.php index fa6ceb893ea..6ba0315e7b2 100755 --- a/dev/tools/apstats.php +++ b/dev/tools/apstats.php @@ -192,19 +192,46 @@ $resexecglpu = 0; // Retrieve the git information for security alerts -$nbofmonth = 6; +$nbofmonth = 2; $delay = (3600 * 24 * 30 * $nbofmonth); $arrayofalerts = array(); -$commandcheck = "git log --first-parent --shortstat --no-renames --no-merges --use-mailmap --pretty='format:%cI;%H;%aN;%aE;%ce;%s' --since='".dol_print_date(dol_now() - $delay, '%Y-%m-%d');"' | grep yogosha"; -print 'Execute git log to get commits of security: '.$commandcheck."\n"; +$commandcheck = "git log --shortstat --no-renames --no-merges --use-mailmap --pretty='format:%cI;%H;%aN;%aE;%ce;%s' --since='".dol_print_date(dol_now() - $delay, '%Y-%m-%d')."' | grep -E 'yogosha|CVE|Sec:'"; +print 'Execute git log to get commits related to security: '.$commandcheck."\n"; $output_arrglpu = array(); $resexecglpu = 0; exec($commandcheck, $output_arrglpu, $resexecglpu); foreach ($output_arrglpu as $val) { $tmpval = cleanVal2($val); - if (preg_match('/yogosha/i', $tmpval['title'])) { - $arrayofalerts[$tmpval['numbercommit']] = $tmpval; + if (preg_match('/yogosha|CVE|Sec:/i', $tmpval['title'])) { + $alreadyfound = ''; + $alreadyfoundcommitid = ''; + foreach ($arrayofalerts as $val) { + if ($val['issueidyogosha'] && $val['issueidyogosha'] == $tmpval['issueidyogosha']) { // Already in list + $alreadyfound = 'yogosha'; + $alreadyfoundcommitid = $val['commitid']; + break; + } + if ($val['issueid'] && $val['issueid'] == $tmpval['issueid']) { // Already in list + $alreadyfound = 'git'; + $alreadyfoundcommitid = $val['commitid']; + break; + } + if ($val['issueidcve'] && $val['issueidcve'] == $tmpval['issueidcve']) { // Already in list + $alreadyfound = 'cve'; + $alreadyfoundcommitid = $val['commitid']; + break; + } + } + //$alreadyfound=0; + if (!$alreadyfound) { + $arrayofalerts[$tmpval['commitid']] = $tmpval; + } else { + if (empty($arrayofalerts[$alreadyfoundcommitid]['commitidbis'])) { + $arrayofalerts[$alreadyfoundcommitid]['commitidbis'] = array(); + } + $arrayofalerts[$alreadyfoundcommitid]['commitidbis'][] = $tmpval['commitid']; + } } } @@ -337,6 +364,18 @@ th,td { .trgroup { border-bottom: 1px solid #aaa; } +.tdoverflowmax100 { + max-width: 100px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} +.tdoverflowmax300 { + max-width: 300px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} .seedetail { color: #000088; cursor: pointer; @@ -586,16 +625,46 @@ if (!empty($output_arrtd)) { // Last security errors $html .= '
'."\n"; -$html .= '

Last security alerts (last '.$nbofmonth.' month)

'."\n"; +$html .= '

Last security issues (last '.$nbofmonth.' month)

'."\n"; $html .= '
'."\n"; $html .= '
'."\n"; $html .= ''."\n"; -$html .= ''."\n"; +$html .= ''."\n"; foreach ($arrayofalerts as $alert) { - $html .= ''; - $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; $html .= ''; } $html .= '
IDTitleDate
Commit IDReported on
Yogosha
Reported on
GIT
Reported on
CVE
TitleDate
#'.$alert['number'].''.$alert['title'].''; - $html .= $alert['created_at'].'
'; + $html .= ''.$alert['commitid'].''; + if (!empty($alert['commitidbis'])) { + foreach ($alert['commitidbis'] as $tmpcommitidbis) { + $html .= '
+'.$tmpcommitidbis.''; + } + } + $html .= '
'; + if (!empty($alert['issueidyogosha'])) { + $html .= '#'.$alert['issueidyogosha'].''; + } else { + //$html .= 'public issue'; + } + $html .= ''; + if (!empty($alert['issueid'])) { + $html .= '#'.$alert['issueid'].''; + } else { + //$html .= 'private'; + } + $html .= ''; + if (!empty($alert['issueidcve'])) { + $cve = preg_replace('/\s+/', '-', trim($alert['issueidcve'])); + $html .= 'CVE-'.$cve.''; + } + $html .= ''.$alert['title'].''; + $html .= preg_replace('/T.*$/', '', $alert['created_at']); + $html .= '
'; @@ -689,16 +758,28 @@ function cleanVal($val) */ function cleanVal2($val) { - $tmp = explode(';', $val); $tmpval = array(); + $tmpval['commitid'] = $tmp[1]; $tmpval['url'] = ''; - $tmpval['number'] = '???'; - $tmpval['numbercommit'] = $tmp[1]; + $tmpval['issueid'] = ''; + $tmpval['issueidyogosha'] = ''; + $tmpval['issueidcve'] = ''; $tmpval['title'] = $tmp[5]; $tmpval['created_at'] = $tmp[0]; $tmpval['updated_at'] = ''; + $reg = array(); + if (preg_match('/#(\d+)/', $tmpval['title'], $reg)) { + $tmpval['issueid'] = $reg[1]; + } + if (preg_match('/CVE([0-9\-\s]+)/', $tmpval['title'], $reg)) { + $tmpval['issueidcve'] = preg_replace('/^\-/', '', trim($reg[1])); + } + if (preg_match('/#yogosha(\d+)/i', $tmpval['title'], $reg)) { + $tmpval['issueidyogosha'] = $reg[1]; + } + return $tmpval; }