PageRenderTime 60ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/websvn-2.3.3/include/configclass.php

#
PHP | 1609 lines | 1205 code | 245 blank | 159 comment | 156 complexity | c15fc2d320ca70174fecc84657547445 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. // WebSVN - Subversion repository viewing via the web using PHP
  3. // Copyright (C) 2004-2006 Tim Armes
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. //
  19. // --
  20. //
  21. // configclass.php
  22. //
  23. // General class for handling configuration options
  24. require_once 'include/command.php';
  25. require_once 'include/auth.php';
  26. require_once 'include/version.php';
  27. // Auxillary functions used to sort repositories by name/group
  28. // {{{ cmpReps($a, $b)
  29. function cmpReps($a, $b) {
  30. // First, sort by group
  31. $g = strcasecmp($a->group, $b->group);
  32. if ($g) return $g;
  33. // Same group? Sort by name
  34. return strcasecmp($a->name, $b->name);
  35. }
  36. // }}}
  37. // {{{ cmpGroups($a, $b)
  38. function cmpGroups($a, $b) {
  39. $g = strcasecmp($a->group, $b->group);
  40. if ($g) return $g;
  41. return 0;
  42. }
  43. // }}}
  44. // {{{ mergesort(&$array, [$cmp_function])
  45. function mergesort(&$array, $cmp_function = 'strcmp') {
  46. // Arrays of size < 2 require no action
  47. if (count($array) < 2) return;
  48. // Split the array in half
  49. $halfway = count($array) / 2;
  50. $array1 = array_slice($array, 0, $halfway);
  51. $array2 = array_slice($array, $halfway);
  52. // Recurse to sort the two halves
  53. mergesort($array1, $cmp_function);
  54. mergesort($array2, $cmp_function);
  55. // If all of $array1 is <= all of $array2, just append them.
  56. if (call_user_func($cmp_function, end($array1), $array2[0]) < 1) {
  57. $array = array_merge($array1, $array2);
  58. return;
  59. }
  60. // Merge the two sorted arrays into a single sorted array
  61. $array = array();
  62. $array1count = count($array1);
  63. $array2count = count($array2);
  64. $ptr1 = 0;
  65. $ptr2 = 0;
  66. while ($ptr1 < $array1count && $ptr2 < $array2count) {
  67. if (call_user_func($cmp_function, $array1[$ptr1], $array2[$ptr2]) < 1) {
  68. $array[] = $array1[$ptr1++];
  69. } else {
  70. $array[] = $array2[$ptr2++];
  71. }
  72. }
  73. // Merge the remainder
  74. while ($ptr1 < $array1count) $array[] = $array1[$ptr1++];
  75. while ($ptr2 < $array2count) $array[] = $array2[$ptr2++];
  76. return;
  77. }
  78. // }}}
  79. // A Repository parent path configuration class
  80. class ParentPath {
  81. // {{{ Properties
  82. var $path;
  83. var $group;
  84. var $pattern;
  85. var $skipAlreadyAdded;
  86. var $clientRootURL;
  87. // }}}
  88. // {{{ __construct($path [, $group [, $pattern [, $skipAlreadyAdded [, $clientRootURL]]]])
  89. function ParentPath($path, $group = null, $pattern = false, $skipAlreadyAdded = true, $clientRootURL = '') {
  90. $this->path = $path;
  91. $this->group = $group;
  92. $this->pattern = $pattern;
  93. $this->skipAlreadyAdded = $skipAlreadyAdded;
  94. $this->clientRootURL = rtrim($clientRootURL, '/');
  95. }
  96. // }}}
  97. // {{{ findRepository($name)
  98. // look for a repository with $name
  99. function &findRepository($name) {
  100. global $config;
  101. if ($this->group != null) {
  102. $prefix = $this->group.'.';
  103. if (substr($name, 0, strlen($prefix)) == $prefix) {
  104. $name = substr($name, strlen($prefix));
  105. } else {
  106. $null = null;
  107. return $null;
  108. }
  109. }
  110. if ($handle = @opendir($this->path)) {
  111. // is there a directory named $name?
  112. $fullpath = $this->path.DIRECTORY_SEPARATOR.$name;
  113. if (is_dir($fullpath) && is_readable($fullpath)) {
  114. // And that contains a db directory (in an attempt to not include non svn repositories.
  115. $dbfullpath = $fullpath.DIRECTORY_SEPARATOR.'db';
  116. if (is_dir($dbfullpath) && is_readable($dbfullpath)) {
  117. // And matches the pattern if specified
  118. if ($this->pattern === false || preg_match($this->pattern, $name)) {
  119. $url = 'file:///'.$fullpath;
  120. $url = str_replace(DIRECTORY_SEPARATOR, '/', $url);
  121. if ($url{strlen($url) - 1} == '/') {
  122. $url = substr($url, 0, -1);
  123. }
  124. if (!in_array($url, $config->_excluded, true)) {
  125. $clientRootURL = ($this->clientRootURL) ? $this->clientRootURL.'/'.$name : '';
  126. $rep = new Repository($name, $name, $url, $this->group, null, null, null, $clientRootURL);
  127. return $rep;
  128. }
  129. }
  130. }
  131. }
  132. closedir($handle);
  133. }
  134. $null = null;
  135. return $null;
  136. }
  137. // }}}
  138. // {{{ getRepositories()
  139. // return all repositories in the parent path matching pattern
  140. function &getRepositories() {
  141. $repos = array();
  142. $handle = @opendir($this->path);
  143. if (!$handle) return $repos;
  144. // For each file...
  145. while (false !== ($name = readdir($handle))) {
  146. $fullpath = $this->path.DIRECTORY_SEPARATOR.$name;
  147. if ($name{0} != '.' && is_dir($fullpath) && is_readable($fullpath)) {
  148. // And that contains a db directory (in an attempt to not include non svn repositories.
  149. $dbfullpath = $fullpath.DIRECTORY_SEPARATOR.'db';
  150. if (is_dir($dbfullpath) && is_readable($dbfullpath)) {
  151. // And matches the pattern if specified
  152. if ($this->pattern === false || preg_match($this->pattern, $name)) {
  153. $url = 'file:///'.$fullpath;
  154. $url = str_replace(DIRECTORY_SEPARATOR, '/', $url);
  155. if ($url{strlen($url) - 1} == '/') {
  156. $url = substr($url, 0, -1);
  157. }
  158. $clientRootURL = ($this->clientRootURL) ? $this->clientRootURL.'/'.$name : '';
  159. $repos[] = new Repository($name, $name, $url, $this->group, null, null, null, $clientRootURL);
  160. }
  161. }
  162. }
  163. }
  164. closedir($handle);
  165. // Sort the repositories into alphabetical order
  166. if (!empty($repos)) {
  167. usort($repos, 'cmpReps');
  168. }
  169. return $repos;
  170. }
  171. // }}}
  172. // {{{ getSkipAlreadyAdded()
  173. // Return if we should skip already added repos for this parent path.
  174. function getSkipAlreadyAdded() {
  175. return $this->skipAlreadyAdded;
  176. }
  177. // }}}
  178. }
  179. // A Repository configuration class
  180. class Repository {
  181. // {{{ Properties
  182. var $name;
  183. var $svnName;
  184. var $path;
  185. var $subpath;
  186. var $group;
  187. var $username = null;
  188. var $password = null;
  189. var $clientRootURL;
  190. // Local configuration options must start off unset
  191. var $allowDownload;
  192. var $minDownloadLevel;
  193. var $allowedExceptions = array();
  194. var $disallowedExceptions = array();
  195. var $logsShowChanges;
  196. var $rss;
  197. var $rssCaching;
  198. var $rssMaxEntries;
  199. var $spaces;
  200. var $ignoreSvnMimeTypes;
  201. var $ignoreWebSVNContentTypes;
  202. var $bugtraq;
  203. var $bugtraqProperties;
  204. var $auth = null;
  205. var $authBasicRealm;
  206. var $templatePath = false;
  207. // }}}
  208. // {{{ __construct($name, $svnName, $serverRootURL [, $group [, $username [, $password [, $clientRootURL]]]])
  209. function Repository($name, $svnName, $serverRootURL, $group = null, $username = null, $password = null, $subpath = null, $clientRootURL = null) {
  210. $this->name = $name;
  211. $this->svnName = $svnName;
  212. $this->path = $serverRootURL;
  213. $this->subpath = $subpath;
  214. $this->group = $group;
  215. $this->username = $username;
  216. $this->password = $password;
  217. $this->clientRootURL = rtrim($clientRootURL, '/');
  218. }
  219. // }}}
  220. // {{{ getDisplayName()
  221. function getDisplayName() {
  222. if (!empty($this->group)) {
  223. return $this->group.'.'.$this->name;
  224. }
  225. return $this->name;
  226. }
  227. // }}}
  228. // {{{ svnCredentials
  229. function svnCredentials() {
  230. $params = '';
  231. if ($this->username !== null && $this->username !== '') {
  232. $params .= ' --username '.quote($this->username);
  233. }
  234. if ($this->password !== null) {
  235. $params .= ' --password '.quote($this->password);
  236. }
  237. return $params;
  238. }
  239. // }}}
  240. // Local configuration accessors
  241. function setLogsShowChanges($enabled = true) {
  242. $this->logsShowChanges = $enabled;
  243. }
  244. function logsShowChanges() {
  245. global $config;
  246. if (isset($this->logsShowChanges))
  247. return $this->logsShowChanges;
  248. else
  249. return $config->logsShowChanges();
  250. }
  251. // {{{ RSS Feed
  252. function setRssEnabled($enabled) {
  253. $this->rss = $enabled;
  254. }
  255. function isRssEnabled() {
  256. global $config;
  257. if (isset($this->rss))
  258. return $this->rss;
  259. else
  260. return $config->isRssEnabled();
  261. }
  262. function setRssCachingEnabled($enabled = true) {
  263. $this->rssCaching = $enabled;
  264. }
  265. function isRssCachingEnabled() {
  266. global $config;
  267. if (isset($this->rssCaching))
  268. return $this->rssCaching;
  269. else
  270. return $config->isRssCachingEnabled();
  271. }
  272. function setRssMaxEntries($max) {
  273. $this->rssMaxEntries = $max;
  274. }
  275. function getRssMaxEntries() {
  276. global $config;
  277. if (isset($this->rssMaxEntries))
  278. return $this->rssMaxEntries;
  279. else
  280. return $config->getRssMaxEntries();
  281. }
  282. // }}}
  283. // {{{ Download
  284. function allowDownload() {
  285. $this->allowDownload = true;
  286. }
  287. function disallowDownload() {
  288. $this->allowDownload = false;
  289. }
  290. function getAllowDownload() {
  291. global $config;
  292. if (isset($this->allowDownload)) {
  293. return $this->allowDownload;
  294. }
  295. return $config->getAllowDownload();
  296. }
  297. function setMinDownloadLevel($level) {
  298. $this->minDownloadLevel = $level;
  299. }
  300. function getMinDownloadLevel() {
  301. global $config;
  302. if (isset($this->minDownloadLevel)) {
  303. return $this->minDownloadLevel;
  304. }
  305. return $config->getMinDownloadLevel();
  306. }
  307. function addAllowedDownloadException($path) {
  308. if ($path{strlen($path) - 1} != '/') $path .= '/';
  309. $this->allowedExceptions[] = $path;
  310. }
  311. function addDisallowedDownloadException($path) {
  312. if ($path{strlen($path) - 1} != '/') $path .= '/';
  313. $this->disallowedExceptions[] = $path;
  314. }
  315. function isDownloadAllowed($path) {
  316. global $config;
  317. // Check global download option
  318. if (!$this->getAllowDownload()) {
  319. return false;
  320. }
  321. // Check with access module
  322. if (!$this->hasUnrestrictedReadAccess($path)) {
  323. return false;
  324. }
  325. $subs = explode('/', $path);
  326. $level = count($subs) - 2;
  327. if ($level >= $this->getMinDownloadLevel()) {
  328. // Level OK, search for disallowed exceptions
  329. if ($config->findException($path, $this->disallowedExceptions)) {
  330. return false;
  331. }
  332. if ($config->findException($path, $config->disallowedExceptions)) {
  333. return false;
  334. }
  335. return true;
  336. } else {
  337. // Level not OK, search for disallowed exceptions
  338. if ($config->findException($path, $this->allowedExceptions)) {
  339. return true;
  340. }
  341. if ($config->findException($path, $config->allowedExceptions)) {
  342. return true;
  343. }
  344. return false;
  345. }
  346. }
  347. // }}}
  348. // {{{ Templates
  349. function setTemplatePath($path) {
  350. $this->templatePath = $path;
  351. }
  352. function getTemplatePath() {
  353. global $config;
  354. if (!empty($this->templatePath)) {
  355. return $this->templatePath;
  356. }
  357. return $config->getTemplatePath();
  358. }
  359. // }}}
  360. // {{{ Tab expansion
  361. function expandTabsBy($sp) {
  362. $this->spaces = $sp;
  363. }
  364. function getExpandTabsBy() {
  365. global $config;
  366. if (isset($this->spaces)) {
  367. return $this->spaces;
  368. }
  369. return $config->getExpandTabsBy();
  370. }
  371. // }}}
  372. // {{{ MIME-Type Handing
  373. function ignoreSvnMimeTypes() {
  374. $this->ignoreSvnMimeTypes = true;
  375. }
  376. function useSvnMimeTypes() {
  377. $this->ignoreSvnMimeTypes = false;
  378. }
  379. function getIgnoreSvnMimeTypes() {
  380. global $config;
  381. if (isset($this->ignoreSvnMimeTypes)) {
  382. return $this->ignoreSvnMimeTypes;
  383. }
  384. return $config->getIgnoreSvnMimeTypes();
  385. }
  386. function ignoreWebSVNContentTypes() {
  387. $this->ignoreWebSVNContentTypes = true;
  388. }
  389. function useWebSVNContentTypes() {
  390. $this->ignoreWebSVNContentTypes = false;
  391. }
  392. function getIgnoreWebSVNContentTypes() {
  393. global $config;
  394. if (isset($this->ignoreWebSVNContentTypes)) {
  395. return $this->ignoreWebSVNContentTypes;
  396. }
  397. return $config->getIgnoreWebSVNContentTypes();
  398. }
  399. // }}}
  400. // {{{ Bugtraq issue tracking
  401. function setBugtraqEnabled($enabled) {
  402. $this->bugtraq = $enabled;
  403. }
  404. function isBugtraqEnabled() {
  405. global $config;
  406. if (isset($this->bugtraq))
  407. return $this->bugtraq;
  408. else
  409. return $config->isBugtraqEnabled();
  410. }
  411. function setBugtraqProperties($properties) {
  412. $this->bugtraqProperties = $properties;
  413. }
  414. function getBugtraqProperties() {
  415. global $config;
  416. if (isset($this->bugtraqProperties))
  417. return $this->bugtraqProperties;
  418. else
  419. return $config->getBugtraqProperties();
  420. }
  421. // }}}
  422. // {{{ Authentication
  423. function useAuthenticationFile($file, $basicRealm = false) {
  424. if (is_readable($file)) {
  425. if ($this->auth === null) {
  426. $this->auth = new Authentication($basicRealm);
  427. }
  428. $this->auth->addAccessFile($file);
  429. } else {
  430. die('Unable to read authentication file "'.$file.'"');
  431. }
  432. }
  433. function &getAuth() {
  434. global $config;
  435. $a = null;
  436. if ($this->auth !== null) {
  437. $a =& $this->auth;
  438. } else {
  439. $a =& $config->getAuth();
  440. }
  441. return $a;
  442. }
  443. function hasReadAccess($path, $checkSubFolders = false) {
  444. global $config;
  445. $a =& $this->getAuth();
  446. if (!empty($a)) {
  447. return $a->hasReadAccess($this->svnName, $path, $checkSubFolders);
  448. }
  449. // No auth file - free access...
  450. return true;
  451. }
  452. function hasUnrestrictedReadAccess($path) {
  453. global $config;
  454. $a =& $this->getAuth();
  455. if (!empty($a)) {
  456. return $a->hasUnrestrictedReadAccess($this->svnName, $path);
  457. }
  458. // No auth file - free access...
  459. return true;
  460. }
  461. // }}}
  462. }
  463. // The general configuration class
  464. class WebSvnConfig {
  465. // {{{ Properties
  466. // Tool path locations
  467. var $_svnCommandPrefix = '';
  468. var $_svnCommandPath = '';
  469. var $_svnConfigDir = '/tmp';
  470. var $_svnTrustServerCert = false;
  471. var $svn = 'svn --non-interactive --config-dir /tmp';
  472. var $diff = 'diff';
  473. var $enscript = 'enscript -q';
  474. var $sed = 'sed';
  475. var $gzip = 'gzip';
  476. var $tar = 'tar';
  477. var $zip = 'zip';
  478. // different modes for file and folder download
  479. var $defaultFileDlMode = 'plain';
  480. var $defaultFolderDlMode = 'gzip';
  481. var $validFileDlModes = array( 'gzip', 'zip', 'plain' );
  482. var $validFolderDlModes = array( 'gzip', 'zip' );
  483. // Other configuration items
  484. var $treeView = true;
  485. var $flatIndex = true;
  486. var $openTree = false;
  487. var $alphabetic = false;
  488. var $showLastModInIndex = true;
  489. var $showLastModInListing = true;
  490. var $showAgeInsteadOfDate = true;
  491. var $_showRepositorySelectionForm = true;
  492. var $_ignoreWhitespacesInDiff = false;
  493. var $serverIsWindows = false;
  494. var $multiViews = false;
  495. var $useEnscript = false;
  496. var $useEnscriptBefore_1_6_3 = false;
  497. var $useGeshi = false;
  498. var $inlineMimeTypes = array();
  499. var $allowDownload = false;
  500. var $tempDir = '';
  501. var $minDownloadLevel = 0;
  502. var $allowedExceptions = array();
  503. var $disallowedExceptions = array();
  504. var $logsShowChanges = false;
  505. var $rss = true;
  506. var $rssCaching = false;
  507. var $rssMaxEntries = 40;
  508. var $spaces = 8;
  509. var $bugtraq = false;
  510. var $bugtraqProperties = null;
  511. var $auth = null;
  512. var $blockRobots = false;
  513. var $templatePaths = array();
  514. var $userTemplate = false;
  515. var $ignoreSvnMimeTypes = false;
  516. var $ignoreWebSVNContentTypes = false;
  517. var $subversionVersion = '';
  518. var $subversionMajorVersion = '';
  519. var $subversionMinorVersion = '';
  520. var $defaultLanguage = 'en';
  521. var $ignoreAcceptedLanguages = false;
  522. var $quote = "'";
  523. var $pathSeparator = ':';
  524. var $_repositories = array();
  525. var $_parentPaths = array(); // parent paths to load
  526. var $_parentPathsLoaded = false;
  527. var $_excluded = array();
  528. // }}}
  529. // {{{ __construct()
  530. function WebSvnConfig() {
  531. }
  532. // }}}
  533. // {{{ Repository configuration
  534. function addRepository($name, $serverRootURL, $group = null, $username = null, $password = null, $clientRootURL = null) {
  535. $this->addRepositorySubpath($name, $serverRootURL, null, $group, $username, $password, $clientRootURL);
  536. }
  537. function addRepositorySubpath($name, $serverRootURL, $subpath, $group = null, $username = null, $password = null, $clientRootURL = null) {
  538. if (DIRECTORY_SEPARATOR != '/') {
  539. $serverRootURL = str_replace(DIRECTORY_SEPARATOR, '/', $serverRootURL);
  540. if ($subpath !== null) {
  541. $subpath = str_replace(DIRECTORY_SEPARATOR, '/', $subpath);
  542. }
  543. }
  544. $serverRootURL = trim($serverRootURL, '/');
  545. $svnName = substr($serverRootURL, strrpos($serverRootURL, '/') + 1);
  546. $this->_repositories[] = new Repository($name, $svnName, $serverRootURL, $group, $username, $password, $subpath, $clientRootURL);
  547. }
  548. // Automatically set up the repositories based on a parent path
  549. function parentPath($path, $group = null, $pattern = false, $skipAlreadyAdded = true, $clientRootURL = '') {
  550. $this->_parentPaths[] = new ParentPath($path, $group, $pattern, $skipAlreadyAdded, $clientRootURL);
  551. }
  552. function addExcludedPath($path) {
  553. $url = 'file:///'.$path;
  554. $url = str_replace(DIRECTORY_SEPARATOR, '/', $url);
  555. if ($url{strlen($url) - 1} == '/') {
  556. $url = substr($url, 0, -1);
  557. }
  558. $this->_excluded[] = $url;
  559. }
  560. function getRepositories() {
  561. // lazily load parent paths
  562. if ($this->_parentPathsLoaded) return $this->_repositories;
  563. $this->_parentPathsLoaded = true;
  564. foreach ($this->_parentPaths as $parentPath) {
  565. $parentRepos = $parentPath->getRepositories();
  566. foreach ($parentRepos as $repo) {
  567. if (!$parentPath->getSkipAlreadyAdded()) {
  568. $this->_repositories[] = $repo;
  569. } else {
  570. // we have to check if we already have a repo with the same svn name
  571. $duplicate = false;
  572. foreach ($this->_repositories as $knownRepos) {
  573. if ($knownRepos->path == $repo->path && $knownRepos->subpath == $repo->subpath) {
  574. $duplicate = true;
  575. break;
  576. }
  577. }
  578. if (!$duplicate && !in_array($repo->path, $this->_excluded, true)) {
  579. $this->_repositories[] = $repo;
  580. }
  581. }
  582. }
  583. }
  584. return $this->_repositories;
  585. }
  586. function &findRepository($name) {
  587. // first look in the "normal repositories"
  588. foreach ($this->_repositories as $index => $rep) {
  589. if (strcmp($rep->getDisplayName(), $name) == 0) {
  590. $repref =& $this->_repositories[$index];
  591. return $repref;
  592. }
  593. }
  594. // now if the parent repos have not already been loaded
  595. // check them
  596. if (!$this->_parentPathsLoaded) {
  597. foreach ($this->_parentPaths as $parentPath) {
  598. $repref =& $parentPath->findRepository($name);
  599. if ($repref != null) {
  600. $this->_repositories[] = $repref;
  601. return $repref;
  602. }
  603. }
  604. }
  605. // Hack to return a string by reference; value retrieved at setup.php:414
  606. $str = 'Unable to find repository "'.escape($name).'".';
  607. $error =& $str;
  608. return $error;
  609. }
  610. // }}}
  611. // {{{ setServerIsWindows
  612. //
  613. // The server is running on Windows
  614. function setServerIsWindows() {
  615. $this->serverIsWindows = true;
  616. // On Windows machines, use double quotes around command line parameters
  617. $this->quote = '"';
  618. // On Windows, semicolon separates path entries in a list rather than colon.
  619. $this->pathSeparator = ';';
  620. }
  621. // }}}
  622. // {{{ MultiViews
  623. // useMultiViews
  624. //
  625. // Use MultiViews to access the repository
  626. function useMultiViews() {
  627. $this->multiViews = true;
  628. }
  629. function getUseMultiViews() {
  630. return $this->multiViews;
  631. }
  632. // }}}
  633. // {{{ Enscript
  634. // useEnscript
  635. //
  636. // Use Enscript to colourise listings
  637. function useEnscript($before_1_6_3 = false) {
  638. $this->useEnscript = true;
  639. $this->useEnscriptBefore_1_6_3 = $before_1_6_3;
  640. }
  641. function getUseEnscript() {
  642. return $this->useEnscript;
  643. }
  644. function getUseEnscriptBefore_1_6_3() {
  645. return $this->useEnscriptBefore_1_6_3;
  646. }
  647. // }}}
  648. // {{{ GeSHi
  649. // useGeshi
  650. //
  651. // Use GeSHi to colourise listings
  652. function useGeshi() {
  653. $this->useGeshi = true;
  654. }
  655. function getUseGeshi() {
  656. return $this->useGeshi;
  657. }
  658. // }}}
  659. // {{{ Inline MIME Types
  660. // inlineMimeTypes
  661. //
  662. // Specify MIME types to display inline in WebSVN pages
  663. function addInlineMimeType($type) {
  664. if (!in_array($type, $this->inlineMimeTypes)) {
  665. $this->inlineMimeTypes[] = $type;
  666. }
  667. }
  668. // }}}
  669. // {{{ Show changed files by default on log.php
  670. function setLogsShowChanges($enabled = true, $myrep = 0) {
  671. if (empty($myrep)) {
  672. $this->logsShowChanges = $enabled;
  673. } else {
  674. $repo =& $this->findRepository($myrep);
  675. $repo->logsShowChanges = $enabled;
  676. }
  677. }
  678. function logsShowChanges() {
  679. return $this->logsShowChanges;
  680. }
  681. // }}}
  682. // {{{ RSS
  683. function setRssEnabled($enabled = true, $myrep = 0) {
  684. if (empty($myrep)) {
  685. $this->rss = $enabled;
  686. } else {
  687. $repo =& $this->findRepository($myrep);
  688. $repo->setRssEnabled($enabled);
  689. }
  690. }
  691. function isRssEnabled() {
  692. return $this->rss;
  693. }
  694. function setRssCachingEnabled($enabled = true, $myrep = 0) {
  695. if (empty($myrep)) {
  696. $this->rssCaching = true;
  697. } else {
  698. $repo =& $this->findRepository($myrep);
  699. $repo->setRssCachingEnabled($enabled);
  700. }
  701. }
  702. function isRssCachingEnabled() {
  703. return $this->rssCaching;
  704. }
  705. // Maximum number of entries in RSS feed
  706. function setRssMaxEntries($max, $myrep = 0) {
  707. if (empty($myrep)) {
  708. $this->rssMaxEntries = $max;
  709. } else {
  710. $repo =& $this->findRepository($myrep);
  711. $repo->setRssMaxEntries($max);
  712. }
  713. }
  714. function getRssMaxEntries() {
  715. return $this->rssMaxEntries;
  716. }
  717. function getHideRSS() {
  718. return $this->rss;
  719. }
  720. // cacheRSS
  721. //
  722. // Enable caching of RSS feeds
  723. function enableRSSCaching($myrep = 0) {
  724. if (empty($myrep)) {
  725. $this->rssCaching = true;
  726. } else {
  727. $repo =& $this->findRepository($myrep);
  728. $repo->enableRSSCaching();
  729. }
  730. }
  731. function getRSSCaching() {
  732. return $this->rssCaching;
  733. }
  734. // }}}
  735. // {{{ Downloads
  736. // allowDownload
  737. //
  738. // Allow download of tarballs
  739. function allowDownload($myrep = 0) {
  740. if (empty($myrep)) {
  741. $this->allowDownload = true;
  742. } else {
  743. $repo =& $this->findRepository($myrep);
  744. $repo->allowDownload();
  745. }
  746. }
  747. function disallowDownload($myrep = 0) {
  748. if (empty($myrep)) {
  749. $this->allowDownload = false;
  750. } else {
  751. $repo =& $this->findRepository($myrep);
  752. $repo->disallowDownload();
  753. }
  754. }
  755. function getAllowDownload() {
  756. return $this->allowDownload;
  757. }
  758. function setTempDir($tempDir) {
  759. $this->tempDir = $tempDir;
  760. }
  761. function getTempDir() {
  762. if (empty($this->tempDir)) {
  763. if (!function_exists('sys_get_temp_dir')) {
  764. function sys_get_temp_dir() {
  765. if (($tmp = getenv('TMPDIR')) ||
  766. ($tmp = getenv('TMP')) ||
  767. ($tmp = getenv('TEMP')) ||
  768. ($tmp = ini_get('upload_tmp_dir')))
  769. return $tmp;
  770. $tmp = tempnam(__FILE__, '');
  771. if (file_exists($tmp)) {
  772. unlink($tmp);
  773. return dirname($tmp);
  774. }
  775. return null;
  776. }
  777. }
  778. $this->tempDir = sys_get_temp_dir();
  779. }
  780. return $this->tempDir;
  781. }
  782. function setMinDownloadLevel($level, $myrep = 0) {
  783. if (empty($myrep)) {
  784. $this->minDownloadLevel = $level;
  785. } else {
  786. $repo =& $this->findRepository($myrep);
  787. $repo->setMinDownloadLevel($level);
  788. }
  789. }
  790. function getMinDownloadLevel() {
  791. return $this->minDownloadLevel;
  792. }
  793. function addAllowedDownloadException($path, $myrep = 0) {
  794. if ($path{strlen($path) - 1} != '/') {
  795. $path .= '/';
  796. }
  797. if (empty($myrep)) {
  798. $this->allowedExceptions[] = $path;
  799. } else {
  800. $repo =& $this->findRepository($myrep);
  801. $repo->addAllowedDownloadException($path);
  802. }
  803. }
  804. function addDisallowedDownloadException($path, $myrep = 0) {
  805. if ($path{strlen($path) - 1} != '/') {
  806. $path .= '/';
  807. }
  808. if (empty($myrep)) {
  809. $this->disallowedExceptions[] = $path;
  810. } else {
  811. $repo =& $this->findRepository($myrep);
  812. $repo->addDisallowedDownloadException($path);
  813. }
  814. }
  815. function findException($path, $exceptions) {
  816. foreach ($exceptions as $key => $exc) {
  817. if (strncmp($exc, $path, strlen($exc)) == 0) {
  818. return true;
  819. }
  820. }
  821. return false;
  822. }
  823. // }}}
  824. // {{{ getURL
  825. //
  826. // Get the URL to a path name based on the current config
  827. function getURL($rep, $path, $op) {
  828. list($base, $params) = $this->getUrlParts($rep, $path, $op);
  829. $url = $base.'?';
  830. foreach ($params as $k => $v) {
  831. $url .= $k.'='.urlencode($v).'&amp;';
  832. }
  833. return $url;
  834. }
  835. // }}}
  836. // {{{ getUrlParts
  837. //
  838. // Get the URL and parameters for a path name based on the current config
  839. function getUrlParts($rep, $path, $op) {
  840. $params = array();
  841. if ($this->multiViews) {
  842. $url = $_SERVER['SCRIPT_NAME'];
  843. if (preg_match('|\.php$|i', $url)) {
  844. // remove the .php extension
  845. $url = substr($url, 0, -4);
  846. }
  847. if ($path && $path{0} != '/') {
  848. $path = '/'.$path;
  849. }
  850. if (substr($url, -5) == 'index') {
  851. $url = substr($url, 0, -5).'wsvn';
  852. }
  853. if ($op == 'index') {
  854. $url .= '/';
  855. } else if (is_object($rep)) {
  856. $url .= '/'.$rep->getDisplayName().str_replace('%2F', '/', rawurlencode($path));
  857. if ($op && $op != 'dir' && $op != 'file') {
  858. $params['op'] = $op;
  859. }
  860. }
  861. } else {
  862. switch ($op) {
  863. case 'index':
  864. $url = '.';
  865. break;
  866. case 'dir':
  867. $url = 'listing.php';
  868. break;
  869. case 'revision':
  870. $url = 'revision.php';
  871. break;
  872. case 'file':
  873. $url = 'filedetails.php';
  874. break;
  875. case 'log':
  876. $url = 'log.php';
  877. break;
  878. case 'diff':
  879. $url = 'diff.php';
  880. break;
  881. case 'blame':
  882. $url = 'blame.php';
  883. break;
  884. case 'form':
  885. $url = 'form.php';
  886. break;
  887. case 'rss':
  888. $url = 'rss.php';
  889. break;
  890. case 'dl':
  891. $url = 'dl.php';
  892. break;
  893. case 'comp':
  894. $url = 'comp.php';
  895. break;
  896. }
  897. if (is_object($rep) && $op != 'index') {
  898. $params['repname'] = $rep->getDisplayName();
  899. }
  900. if (!empty($path)) {
  901. $params['path'] = $path;
  902. }
  903. }
  904. return array($url, $params);
  905. }
  906. // }}}
  907. // {{{ Paths and Commands
  908. // setPath
  909. //
  910. // Set the location of the given path
  911. function _setPath(&$var, $path, $name, $params = '') {
  912. if ($path == '') {
  913. // Search in system search path. No check for existence possible
  914. $var = $name;
  915. } else {
  916. $lastchar = substr($path, -1, 1);
  917. $isDir = ($lastchar == DIRECTORY_SEPARATOR || $lastchar == '/' || $lastchar == '\\');
  918. if (!$isDir) $path .= DIRECTORY_SEPARATOR;
  919. if (($this->serverIsWindows && !file_exists($path.$name.'.exe')) || (!$this->serverIsWindows && !file_exists($path.$name))) {
  920. echo 'Unable to find "'.$name.'" tool at location "'.$path.$name.'"';
  921. exit;
  922. }
  923. // On a windows machine we need to put quotes around the
  924. // entire command to allow for spaces in the path
  925. if ($this->serverIsWindows) {
  926. $var = '"'.$path.$name.'"';
  927. } else {
  928. $var = $path.$name;
  929. }
  930. }
  931. // Append parameters
  932. if ($params != '') $var .= ' '.$params;
  933. }
  934. // Define directory path to use for --config-dir parameter
  935. function setSvnConfigDir($path) {
  936. $this->_svnConfigDir = $path;
  937. $this->_updateSVNCommand();
  938. }
  939. // Define flag to use --trust-server-cert parameter
  940. function setTrustServerCert() {
  941. $this->_svnTrustServerCert = true;
  942. $this->_updateSVNCommand();
  943. }
  944. // Define the location of the svn command (e.g. '/usr/bin')
  945. function setSvnCommandPath($path) {
  946. $this->_svnCommandPath = $path;
  947. $this->_updateSVNCommand();
  948. }
  949. // Define a prefix to include before every SVN command (e.g. 'arch -i386')
  950. function setSvnCommandPrefix($prefix) {
  951. $this->_svnCommandPrefix = $prefix;
  952. $this->_updateSVNCommand();
  953. }
  954. function _updateSVNCommand() {
  955. $this->_setPath($this->svn, $this->_svnCommandPath, 'svn', '--non-interactive --config-dir '.$this->_svnConfigDir.($this->_svnTrustServerCert ? ' --trust-server-cert' : ''));
  956. $this->svn = $this->_svnCommandPrefix.' '.$this->svn;
  957. }
  958. function getSvnCommand() {
  959. return $this->svn;
  960. }
  961. // setDiffPath
  962. //
  963. // Define the location of the diff command
  964. function setDiffPath($path) {
  965. $this->_setPath($this->diff, $path, 'diff');
  966. }
  967. function getDiffCommand() {
  968. return $this->diff;
  969. }
  970. // setEnscriptPath
  971. //
  972. // Define the location of the enscript command
  973. function setEnscriptPath($path) {
  974. $this->_setPath($this->enscript, $path, 'enscript', '-q');
  975. }
  976. function getEnscriptCommand() {
  977. return $this->enscript;
  978. }
  979. // setSedPath
  980. //
  981. // Define the location of the sed command
  982. function setSedPath($path) {
  983. $this->_setPath($this->sed, $path, 'sed');
  984. }
  985. function getSedCommand() {
  986. return $this->sed;
  987. }
  988. // setTarPath
  989. //
  990. // Define the location of the tar command
  991. function setTarPath($path) {
  992. $this->_setPath($this->tar, $path, 'tar');
  993. }
  994. function getTarCommand() {
  995. return $this->tar;
  996. }
  997. // setGzipPath
  998. //
  999. // Define the location of the GZip command
  1000. function setGzipPath($path) {
  1001. $this->_setPath($this->gzip, $path, 'gzip');
  1002. }
  1003. function getGzipCommand() {
  1004. return $this->gzip;
  1005. }
  1006. // setZipPath
  1007. //
  1008. // Define the location of the zip command
  1009. function setZipPath($path) {
  1010. $this->_setPath($this->zip, $path, 'zip');
  1011. }
  1012. function getZipPath() {
  1013. return $this->zip;
  1014. }
  1015. // setDefaultFileDlMode
  1016. //
  1017. // Define the default file download mode - one of [gzip, zip, plain]
  1018. function setDefaultFileDlMode($dlmode) {
  1019. if (in_array($dlmode, $this->validFileDlModes)) {
  1020. $this->defaultFileDlMode = $dlmode;
  1021. } else {
  1022. echo 'Setting default file download mode to an invalid value "'.$dlmode.'"';
  1023. exit;
  1024. }
  1025. }
  1026. function getDefaultFileDlMode() {
  1027. return $this->defaultFileDlMode;
  1028. }
  1029. // setDefaultFolderDlMode
  1030. //
  1031. // Define the default folder download mode - one of [gzip, zip]
  1032. function setDefaultFolderDlMode($dlmode) {
  1033. if (in_array($dlmode, $this->validFolderDlModes)) {
  1034. $this->defaultFolderDlMode = $dlmode;
  1035. } else {
  1036. echo 'Setting default file download mode to an invalid value "'.$dlmode.'"';
  1037. exit;
  1038. }
  1039. }
  1040. function getDefaultFolderDlMode() {
  1041. return $this->defaultFolderDlMode;
  1042. }
  1043. // Templates
  1044. function addTemplatePath($path) {
  1045. $lastchar = substr($path, -1, 1);
  1046. if ($lastchar != '/' && $lastchar != '\\') {
  1047. $path .= DIRECTORY_SEPARATOR;
  1048. }
  1049. if (!in_array($path, $this->templatePaths)) {
  1050. $this->templatePaths[] = $path;
  1051. }
  1052. }
  1053. function setTemplatePath($path, $myrep = null) {
  1054. $lastchar = substr($path, -1, 1);
  1055. if ($lastchar != '/' && $lastchar != '\\') {
  1056. $path .= DIRECTORY_SEPARATOR;
  1057. }
  1058. if ($myrep !== null) {
  1059. // fixed template for specific repository
  1060. $repo =& $this->findRepository($myrep);
  1061. $repo->setTemplatePath($path);
  1062. } else {
  1063. // for backward compatibility
  1064. if (in_array($path, $this->templatePaths)) {
  1065. array_splice($this->templatePaths, array_search($path, $this->templatePaths), 1);
  1066. }
  1067. array_unshift($this->templatePaths, $path);
  1068. }
  1069. }
  1070. function getTemplatePath() {
  1071. if (count($this->templatePaths) == 0) {
  1072. echo 'No template path added in config file';
  1073. exit;
  1074. }
  1075. if ($this->userTemplate !== false)
  1076. return $this->userTemplate;
  1077. else
  1078. return $this->templatePaths[0];
  1079. }
  1080. // }}}
  1081. function setDefaultLanguage($language) {
  1082. $this->defaultLanguage = $language;
  1083. }
  1084. function getDefaultLanguage() {
  1085. return $this->defaultLanguage;
  1086. }
  1087. function ignoreUserAcceptedLanguages() {
  1088. $this->ignoreAcceptedLanguages = true;
  1089. }
  1090. function useAcceptedLanguages() {
  1091. return !$this->ignoreAcceptedLanguages;
  1092. }
  1093. // {{{ Tab expansion functions
  1094. function expandTabsBy($sp, $myrep = 0) {
  1095. if (empty($myrep)) {
  1096. $this->spaces = $sp;
  1097. } else {
  1098. $repo =& $this->findRepository($myrep);
  1099. $repo->expandTabsBy($sp);
  1100. }
  1101. }
  1102. function getExpandTabsBy() {
  1103. return $this->spaces;
  1104. }
  1105. // }}}
  1106. // {{{ Bugtraq issue tracking
  1107. function setBugtraqEnabled($enabled, $myrep = 0) {
  1108. if (empty($myrep)) {
  1109. $this->bugtraq = $enabled;
  1110. } else {
  1111. $repo =& $this->findRepository($myrep);
  1112. $repo->setBugtraqEnabled($enabled);
  1113. }
  1114. }
  1115. function isBugtraqEnabled() {
  1116. return $this->bugtraq;
  1117. }
  1118. function setBugtraqProperties($message, $logregex, $url, $append = true, $myrep = null) {
  1119. $properties = array();
  1120. $properties['bugtraq:message'] = $message;
  1121. $properties['bugtraq:logregex'] = $logregex;
  1122. $properties['bugtraq:url'] = $url;
  1123. $properties['bugtraq:append'] = (bool)$append;
  1124. if ($myrep === null) {
  1125. $this->bugtraqProperties = $properties;
  1126. } else {
  1127. $repo =& $this->findRepository($myrep);
  1128. $repo->setBugtraqProperties($properties);
  1129. }
  1130. }
  1131. function getBugtraqProperties() {
  1132. return $this->bugtraqProperties;
  1133. }
  1134. // }}}
  1135. // {{{ Misc settings
  1136. function ignoreSvnMimeTypes() {
  1137. $this->ignoreSvnMimeTypes = true;
  1138. }
  1139. function getIgnoreSvnMimeTypes() {
  1140. return $this->ignoreSvnMimeTypes;
  1141. }
  1142. function ignoreWebSVNContentTypes() {
  1143. $this->ignoreWebSVNContentTypes = true;
  1144. }
  1145. function getIgnoreWebSVNContentTypes() {
  1146. return $this->ignoreWebSVNContentTypes;
  1147. }
  1148. function useAuthenticationFile($file, $myrep = 0, $basicRealm = false) {
  1149. if (empty($myrep)) {
  1150. if (is_readable($file)) {
  1151. if ($this->auth === null) {
  1152. $this->auth = new Authentication($basicRealm);
  1153. }
  1154. $this->auth->addAccessFile($file);
  1155. } else {
  1156. echo 'Unable to read authentication file "'.$file.'"';
  1157. exit;
  1158. }
  1159. } else {
  1160. $repo =& $this->findRepository($myrep);
  1161. $repo->useAuthenticationFile($file);
  1162. }
  1163. }
  1164. function &getAuth() {
  1165. return $this->auth;
  1166. }
  1167. function areRobotsBlocked() {
  1168. return $this->blockRobots;
  1169. }
  1170. function setBlockRobots($value = true) {
  1171. $this->blockRobots = $value;
  1172. }
  1173. function useTreeView() {
  1174. $this->treeView = true;
  1175. }
  1176. function getUseTreeView() {
  1177. return $this->treeView;
  1178. }
  1179. function useFlatView() {
  1180. $this->treeView = false;
  1181. }
  1182. function useTreeIndex($open) {
  1183. $this->flatIndex = false;
  1184. $this->openTree = $open;
  1185. }
  1186. function getUseFlatIndex() {
  1187. return $this->flatIndex;
  1188. }
  1189. function getOpenTree() {
  1190. return $this->openTree;
  1191. }
  1192. function setAlphabeticOrder($flag) {
  1193. $this->alphabetic = $flag;
  1194. }
  1195. function isAlphabeticOrder() {
  1196. return $this->alphabetic;
  1197. }
  1198. function showLastModInIndex() {
  1199. return $this->showLastModInIndex;
  1200. }
  1201. function setShowLastModInIndex($show) {
  1202. $this->showLastModInIndex = $show;
  1203. }
  1204. function showLastModInListing() {
  1205. return $this->showLastModInListing;
  1206. }
  1207. function setShowLastModInListing($show) {
  1208. $this->showLastModInListing = $show;
  1209. }
  1210. function showAgeInsteadOfDate() {
  1211. return $this->showAgeInsteadOfDate;
  1212. }
  1213. function setShowAgeInsteadOfDate($show) {
  1214. $this->showAgeInsteadOfDate = $show;
  1215. }
  1216. function showRepositorySelectionForm() {
  1217. return $this->_showRepositorySelectionForm;
  1218. }
  1219. function setShowRepositorySelectionForm($show) {
  1220. $this->_showRepositorySelectionForm = $show;
  1221. }
  1222. function getIgnoreWhitespacesInDiff() {
  1223. return $this->_ignoreWhitespacesInDiff;
  1224. }
  1225. function setIgnoreWhitespacesInDiff($ignore) {
  1226. $this->_ignoreWhitespacesInDiff = $ignore;
  1227. }
  1228. // Methods for storing version information for the command-line svn tool
  1229. function setSubversionVersion($subversionVersion) {
  1230. $this->subversionVersion = $subversionVersion;
  1231. }
  1232. function getSubversionVersion() {
  1233. return $this->subversionVersion;
  1234. }
  1235. function setSubversionMajorVersion($subversionMajorVersion) {
  1236. $this->subversionMajorVersion = $subversionMajorVersion;
  1237. }
  1238. function getSubversionMajorVersion() {
  1239. return $this->subversionMajorVersion;
  1240. }
  1241. function setSubversionMinorVersion($subversionMinorVersion) {
  1242. $this->subversionMinorVersion = $subversionMinorVersion;
  1243. }
  1244. function getSubversionMinorVersion() {
  1245. return $this->subversionMinorVersion;
  1246. }
  1247. // }}}
  1248. // {{{ Sort the repostories
  1249. //
  1250. // This function sorts the repositories by group name. The contents of the
  1251. // group are left in there original order, which will either be sorted if the
  1252. // group was added using the parentPath function, or defined for the order in
  1253. // which the repositories were included in the user's config file.
  1254. //
  1255. // Note that as of PHP 4.0.6 the usort command no longer preserves the order
  1256. // of items that are considered equal (in our case, part of the same group).
  1257. // The mergesort function preserves this order.
  1258. function sortByGroup() {
  1259. if (!empty($this->_repositories)) {
  1260. mergesort($this->_repositories, 'cmpGroups');
  1261. }
  1262. }
  1263. // }}}
  1264. }