PageRenderTime 48ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/Branch_4_6dev/gforge/www/scm/include/viewvc_utils.php

https://gitlab.com/oslc-cm-server/olbergers-ff5-oslc
PHP | 111 lines | 68 code | 15 blank | 28 comment | 14 complexity | 5743601a1fe8225b3ed064cf1b9861a8 MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * Utilitary class for the GForge ViewCVS wrapper.
  4. *
  5. * Portion of this file is inspired from the ViewCVS wrapper
  6. * contained in CodeX.
  7. * Copyright (c) Xerox Corporation, CodeX / CodeX Team, 2001,2002. All Rights Reserved.
  8. * http://codex.xerox.com
  9. *
  10. * @version $ID$
  11. */
  12. define ('SEPARATOR', "\n\t\r\0\x0B");
  13. /**
  14. * viewcvs_is_html() - Test if ViewCVS returns HTML.
  15. *
  16. * @return true if the content type of the ViewCVS is text/html.
  17. */
  18. function viewcvs_is_html() {
  19. $request_uri = getStringFromServer('REQUEST_URI');
  20. $query_string = getStringFromServer('QUERY_STRING');
  21. return (strpos($request_uri,"*checkout*") === false &&
  22. strpos($query_string,"view=graphimg") === false &&
  23. strpos($query_string,"view=patch") === false &&
  24. strpos($query_string,"view=tar") === false &&
  25. strpos($request_uri,"*docroot*") === false &&
  26. strpos($request_uri,"makepatch=1") === false);
  27. }
  28. /**
  29. * make_arg_cmd_safe() - Make strings safe for the command line.
  30. *
  31. * @param string The argument that needs to be cleaned.
  32. * @return string The argument with dangerous shell characters escaped.
  33. */
  34. function make_arg_cmd_safe($arg) {
  35. if (get_magic_quotes_gpc()) {
  36. $arg = stripslashes($arg);
  37. }
  38. return escapeshellcmd($arg);
  39. }
  40. /**
  41. * viewcvs_execute() - Call to viewcvs.cgi and returned the output.
  42. *
  43. * @return String the output of the ViewCVS command.
  44. */
  45. function viewcvs_execute($repos_name, $repos_type) {
  46. global $Language;
  47. $request_uri = getStringFromServer('REQUEST_URI');
  48. $query_string = getStringFromServer('QUERY_STRING');
  49. $viewcvs_path = $GLOBALS['sys_urlroot'].'/scm/viewvc';
  50. // this is very important ...
  51. if (getStringFromServer('PATH_INFO') == '') {
  52. $path = '/';
  53. } else {
  54. $path = getStringFromServer('PATH_INFO');
  55. // hack: path must always end with /
  56. if (strrpos($path,'/') != (strlen($path)-1)) {
  57. $path .= '/';
  58. }
  59. }
  60. if ($repos_type == "cvs") {
  61. $repos_root = $GLOBALS['cvsdir_prefix'].'/'.$repos_name;
  62. } else if ($repos_type == "svn") {
  63. $repos_root = $GLOBALS['svndir_prefix'].'/'.$repos_name;
  64. } else {
  65. die("Invalid repository type");
  66. }
  67. if (!is_dir($repos_root)) {
  68. $content = $Language->getText('scm_index', 'not_created');
  69. return $content;
  70. }
  71. $query_string = str_replace('\\&', '&', make_arg_cmd_safe($query_string));
  72. $query_string = str_replace('\\*', '*', $query_string);
  73. $path = str_replace('\\*', '*', make_arg_cmd_safe($path));
  74. $command = 'HTTP_COOKIE="'.make_arg_cmd_safe(getStringFromServer('HTTP_COOKIE')).'" '.
  75. 'REMOTE_ADDR="'.make_arg_cmd_safe(getStringFromServer('REMOTE_ADDR')).'" '.
  76. 'QUERY_STRING="'.$query_string.'" '.
  77. 'SERVER_SOFTWARE="'.make_arg_cmd_safe(getStringFromServer('SERVER_SOFTWARE')).'" '.
  78. 'SCRIPT_NAME="'.make_arg_cmd_safe(getStringFromServer('SCRIPT_NAME')).'" '.
  79. 'HTTP_USER_AGENT="'.make_arg_cmd_safe(getStringFromServer('HTTP_USER_AGENT')).'" '.
  80. 'HTTP_ACCEPT_ENCODING="'.make_arg_cmd_safe(getStringFromServer('HTTP_ACCEPT_ENCODING')).'" '.
  81. 'HTTP_ACCEPT_LANGUAGE="'.make_arg_cmd_safe(getStringFromServer('HTTP_ACCEPT_LANGUAGE')).'" '.
  82. 'PATH_INFO="'.$path.'" '.
  83. 'PATH="'.make_arg_cmd_safe(getStringFromServer('PATH')).'" '.
  84. 'REPOSITORY_ROOT="'.make_arg_cmd_safe($repos_root).'" '.
  85. 'REPOSITORY_TYPE="'.$repos_type.'" '.
  86. 'REPOSITORY_NAME="'.make_arg_cmd_safe($repos_name).'" '.
  87. 'HTTP_HOST="'.make_arg_cmd_safe(getStringFromServer('HTTP_HOST')).'" '.
  88. 'DOCROOT="/themes/'.$GLOBALS['sys_theme'].'/viewvc" '.
  89. $viewcvs_path.'/bin/cgi/viewvc.cgi 2>&1';
  90. ob_start();
  91. passthru($command);
  92. $content = ob_get_contents();
  93. ob_end_clean();
  94. return $content;
  95. }
  96. ?>