Skip to content

Commit

Permalink
added option to override bugtraq data from svn properties in config (…
Browse files Browse the repository at this point in the history
…partially fixed #315)
  • Loading branch information
dirk-thomas committed Mar 5, 2011
1 parent e23210d commit 2a1799d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 15 deletions.
38 changes: 23 additions & 15 deletions include/bugtraq.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,30 @@ function Bugtraq($rep, $svnrep, $path) {
global $config;

if ($rep->isBugtraqEnabled()) {
$pos = strrpos($path, '/');
$parent = substr($path, 0, $pos + 1);
$this->append = true;

$enoughdata = false;
while (!$enoughdata && (strpos($parent, '/') !== false)) {
$properties = $svnrep->getProperties($parent);
if (empty($this->msgstring) && in_array('bugtraq:message', $properties)) $this->msgstring = $svnrep->getProperty($parent, 'bugtraq:message');
if (empty($this->logregex) && in_array('bugtraq:logregex', $properties)) $this->logregex = $svnrep->getProperty($parent, 'bugtraq:logregex');
if (empty($this->urlstring) && in_array('bugtraq:url', $properties)) $this->urlstring = $svnrep->getProperty($parent, 'bugtraq:url');
if (in_array('bugtraq:append', $properties) && $svnrep->getProperty($parent, 'bugtraq:append') == 'false') $this->append = false;

$parent = substr($parent, 0, -1); // Remove the trailing slash
$pos = strrpos($parent, '/'); // Find the last trailing slash
$parent = substr($parent, 0, $pos + 1); // Find the previous parent directory
$enoughdata = ((!empty($this->msgstring) || !empty($this->logregex)) && !empty($this->urlstring));
if (($properties = $rep->getBugtraqProperties()) !== null) {
$this->msgstring = $properties['bugtraq:message'];
$this->logregex = $properties['bugtraq:logregex'];
$this->urlstring = $properties['bugtraq:url'];
$this->append = $properties['bugtraq:append'];
$enoughdata = true;
} else {
$pos = strrpos($path, '/');
$parent = substr($path, 0, $pos + 1);
$this->append = true;

while (!$enoughdata && (strpos($parent, '/') !== false)) {
$properties = $svnrep->getProperties($parent);
if (empty($this->msgstring) && in_array('bugtraq:message', $properties)) $this->msgstring = $svnrep->getProperty($parent, 'bugtraq:message');
if (empty($this->logregex) && in_array('bugtraq:logregex', $properties)) $this->logregex = $svnrep->getProperty($parent, 'bugtraq:logregex');
if (empty($this->urlstring) && in_array('bugtraq:url', $properties)) $this->urlstring = $svnrep->getProperty($parent, 'bugtraq:url');
if (in_array('bugtraq:append', $properties) && $svnrep->getProperty($parent, 'bugtraq:append') == 'false') $this->append = false;

$parent = substr($parent, 0, -1); // Remove the trailing slash
$pos = strrpos($parent, '/'); // Find the last trailing slash
$parent = substr($parent, 0, $pos + 1); // Find the previous parent directory
$enoughdata = ((!empty($this->msgstring) || !empty($this->logregex)) && !empty($this->urlstring));
}
}

$this->msgstring = trim(@$this->msgstring);
Expand Down
33 changes: 33 additions & 0 deletions include/configclass.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ class Repository {
var $ignoreSvnMimeTypes;
var $ignoreWebSVNContentTypes;
var $bugtraq;
var $bugtraqProperties;
var $auth = null;
var $authBasicRealm;
var $templatePath = false;
Expand Down Expand Up @@ -525,6 +526,19 @@ function isBugtraqEnabled() {
return $config->isBugtraqEnabled();
}

function setBugtraqProperties($properties) {
$this->bugtraqProperties = $properties;
}

function getBugtraqProperties() {
global $config;

if (isset($this->bugtraqProperties))
return $this->bugtraqProperties;
else
return $config->getBugtraqProperties();
}

// }}}

// {{{ Authentication
Expand Down Expand Up @@ -636,6 +650,7 @@ class WebSvnConfig {
var $rssMaxEntries = 40;
var $spaces = 8;
var $bugtraq = false;
var $bugtraqProperties = null;
var $auth = null;
var $blockRobots = false;

Expand Down Expand Up @@ -1404,6 +1419,24 @@ function isBugtraqEnabled() {
return $this->bugtraq;
}

function setBugtraqProperties($message, $logregex, $url, $append = true, $myrep = null) {
$properties = array();
$properties['bugtraq:message'] = $message;
$properties['bugtraq:logregex'] = $logregex;
$properties['bugtraq:url'] = $url;
$properties['bugtraq:append'] = (bool)$append;
if ($myrep === null) {
$this->bugtraqProperties = $properties;
} else {
$repo =& $this->findRepository($myrep);
$repo->setBugtraqProperties($properties);
}
}

function getBugtraqProperties() {
return $this->bugtraqProperties;
}

// }}}

// {{{ Misc settings
Expand Down
9 changes: 9 additions & 0 deletions include/distconfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,15 @@
// $config->setBugtraqEnabled(true, 'myrep');
// $config->setBugtraqEnabled(false, 'myrep');

// Usually the information to extract the bugtraq information and generate links are
// stored in SVN properties starting with 'bugtraq:':
// namely 'bugtraq:message', 'bugtraq:logregex', 'bugtraq:url' and 'bugtraq:append'.
// To override the SVN properties globally or for individual repositories, uncomment
// the appropriate line below (replacing 'myrep' with the name of the repository).

// $config->setBugtraqProperties('bug #%BUGID%', 'issues? (\d+)([, ] *(\d+))*'."\n".'(\d+)', 'http://www.example.com/issues/show_bug.cgi?id=%BUGID%', false);
// $config->setBugtraqProperties('bug #%BUGID%', 'issues? (\d+)([, ] *(\d+))*'."\n".'(\d+)', 'http://www.example.com/issues/show_bug.cgi?id=%BUGID%', false, 'myrep');

// }}}

// {{{ MISCELLANEOUS ---
Expand Down

0 comments on commit 2a1799d

Please sign in to comment.