Skip to content

Commit da0bbb8

Browse files
mggaskilllaf
andauthored
showconfig.inc.php changed svn_log() and svn_diff() to Process() (librenms#16483)
* showconfig.inc.php changed svn from using functions in unsupported pecl svn package to using Process, like git * Fixed formatting mistake in showconfig.inc.php Added spaces around a '.' * Resolved quotation marks showconfig.inc.php Corrected my double quotes to single quotes. * Added Config::locateBinary('svn') to showconfig.inc.php Updated to use the recommended approach of using the LibreNMS execution finder code to use the full binary path instead of relying on the binary being in the path. * Added is_executable($svn_binary) showconfig.inc.php Verified that the executable and path exist before trying to run Process() * Fixed my whitespace issues in showconfig.inc.php Fixed my whitespace issues --------- Co-authored-by: Neil Lathwood <[email protected]>
1 parent 58882a7 commit da0bbb8

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

includes/html/pages/device/showconfig.inc.php

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,42 @@
2020
echo generate_link('Latest', ['page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig']);
2121
}
2222

23-
if (Config::get('rancid_repo_type') == 'svn' && function_exists('svn_log')) {
24-
$sep = ' | ';
25-
$svnlogs = svn_log($rancid_file, SVN_REVISION_HEAD, null, 8);
26-
$revlist = [];
27-
28-
foreach ($svnlogs as $svnlog) {
29-
echo $sep;
30-
$revlist[] = $svnlog['rev'];
23+
if (Config::get('rancid_repo_type') == 'svn') {
24+
$svn_binary = Config::locateBinary('svn');
25+
if (is_executable($svn_binary)) {
26+
$sep = ' | ';
3127

32-
if ($vars['rev'] == $svnlog['rev']) {
33-
echo '<span class="pagemenu-selected">';
28+
$process = new Process([$svn_binary, 'log', '-l 8', '-q', '--xml', $rancid_file], $rancid_path);
29+
$process->run();
30+
$svnlogs_xmlstring = $process->getOutput();
31+
$svnlogs = [];
32+
33+
$svnlogs_xml = simplexml_load_string($svnlogs_xmlstring);
34+
foreach ($svnlogs_xml->logentry as $svnlogentry) {
35+
$rev = $svnlogentry['revision'];
36+
$ts = strtotime($svnlogentry->date);
37+
$svnlogs[] = ['rev' => $rev, 'date' => $ts];
3438
}
3539

36-
$linktext = 'r' . $svnlog['rev'] . ' <small>' . date(Config::get('dateformat.byminute'), strtotime($svnlog['date'])) . '</small>';
37-
echo generate_link($linktext, ['page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig', 'rev' => $svnlog['rev']]);
40+
$revlist = [];
3841

39-
if ($vars['rev'] == $svnlog['rev']) {
40-
echo '</span>';
41-
}
42+
foreach ($svnlogs as $svnlog) {
43+
echo $sep;
44+
$revlist[] = $svnlog['rev'];
4245

43-
$sep = ' | ';
46+
if ($vars['rev'] == $svnlog['rev']) {
47+
echo '<span class="pagemenu-selected">';
48+
}
49+
50+
$linktext = 'r' . $svnlog['rev'] . ' <small>' . date(Config::get('dateformat.byminute'), $svnlog['date']) . '</small>';
51+
echo generate_link($linktext, ['page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig', 'rev' => $svnlog['rev']]);
52+
53+
if ($vars['rev'] == $svnlog['rev']) {
54+
echo '</span>';
55+
}
56+
57+
$sep = ' | ';
58+
}
4459
}
4560
}//end if
4661
if (Config::get('rancid_repo_type') == 'git') {
@@ -80,18 +95,16 @@
8095
print_optionbar_end();
8196

8297
if (Config::get('rancid_repo_type') == 'svn') {
83-
if (function_exists('svn_log') && in_array($vars['rev'], $revlist)) {
84-
[$diff, $errors] = svn_diff($rancid_file, $vars['rev'] - 1, $rancid_file, $vars['rev']);
98+
$svn_binary = Config::locateBinary('svn');
99+
if (is_executable($svn_binary) && in_array($vars['rev'], $revlist)) {
100+
$process = new Process([$svn_binary, 'diff', '-c', 'r' . $vars['rev'], $rancid_file], $rancid_path);
101+
$process->run();
102+
$diff = $process->getOutput();
85103
if (! $diff) {
86104
$text = 'No Difference';
87105
} else {
88-
$text = '';
89-
while (! feof($diff)) {
90-
$text .= fread($diff, 8192);
91-
}
92-
93-
fclose($diff);
94-
fclose($errors);
106+
$text = $diff;
107+
$previous_config = $vars['rev'] . '^';
95108
}
96109
} else {
97110
$fh = fopen($rancid_file, 'r');

0 commit comments

Comments
 (0)