1 | 1 | simandl | <?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 | | | // setup.php |
22 | | | // |
23 | | | // Global setup |
24 | | | |
25 | | | // --- DON'T CHANGE THIS FILE --- |
26 | | | // |
27 | | | // User changes should be done in config.ini |
28 | | | |
29 | | | // Include the configuration class |
30 | | | require_once 'include/configclass.php'; |
31 | | | |
32 | | | // Create the config |
33 | | | $config = new WebSvnConfig(); |
34 | | | |
35 | | | // Set up the default character encodings |
36 | | | if (function_exists('iconv_get_encoding')) { |
37 | | | $config->setInputEncoding(iconv_get_encoding('input_encoding')); |
38 | | | } |
39 | | | |
40 | | | // Set up locwebsvnhttp |
41 | | | // Note: we will use nothing in MultiViews mode so that the URLs use the root |
42 | | | // directory by default. |
43 | | | if (empty($locwebsvnhttp)) { |
44 | | | $locwebsvnhttp = defined('WSVN_MULTIVIEWS') ? '' : '.'; |
45 | | | } |
46 | | | if (empty($locwebsvnreal)) { |
47 | | | $locwebsvnreal = '.'; |
48 | | | } |
49 | | | |
50 | | | $vars['locwebsvnhttp'] = $locwebsvnhttp; |
51 | | | |
52 | | | // {{{ Content-Type's |
53 | | | // Set up the default content-type extension handling |
54 | | | |
55 | | | $contentType = array ( |
56 | | | '.dwg' => 'application/acad', // AutoCAD Drawing files |
57 | | | '.arj' => 'application/arj', // |
58 | | | '.ccad' => 'application/clariscad', // ClarisCAD files |
59 | | | '.drw' => 'application/drafting', // MATRA Prelude drafting |
60 | | | '.dxf' => 'application/dxf', // DXF (AutoCAD) |
61 | | | '.xl' => 'application/excel', // Microsoft Excel |
62 | | | '.unv' => 'application/i-deas', //SDRC I-DEAS files |
63 | | | '.igs' => 'application/iges', // IGES graphics format |
64 | | | '.iges' => 'application/iges', // IGES graphics format |
65 | | | '.hqx' => 'application/mac-binhex40', // Macintosh BinHex format |
66 | | | '.word' => 'application/msword', // Microsoft Word |
67 | | | '.w6w' => 'application/msword', // Microsoft Word |
68 | | | '.doc' => 'application/msword', // Microsoft Word |
69 | | | '.wri' => 'application/mswrite', // Microsoft Write |
70 | | | '.bin' => 'application/octet-stream', // Uninterpreted binary |
71 | | | '.exe' => 'application/x-msdownload', // Windows EXE |
72 | | | '.oda' => 'application/oda', // |
73 | | | '.pdf' => 'application/pdf', // PDF (Adobe Acrobat) |
74 | | | '.ai' => 'application/postscript', // PostScript |
75 | | | '.ps' => 'application/postscript', // PostScript |
76 | | | '.eps' => 'application/postscript', // PostScript |
77 | | | '.prt' => 'application/pro_eng', // PTC Pro/ENGINEER |
78 | | | '.part' => 'application/pro_eng', // PTC Pro/ENGINEER |
79 | | | '.rtf' => 'application/rtf', // Rich Text Format |
80 | | | '.set' => 'application/set', // SET (French CAD standard) |
81 | | | '.stl' => 'application/sla', // Stereolithography |
82 | | | '.sol' => 'application/solids', // MATRA Prelude Solids |
83 | | | '.stp' => 'application/STEP', // ISO-10303 STEP data files |
84 | | | '.step' => 'application/STEP', // ISO-10303 STEP data files |
85 | | | '.vda' => 'application/vda', // VDA-FS Surface data |
86 | | | '.dir' => 'application/x-director', // Macromedia Director |
87 | | | '.dcr' => 'application/x-director', // Macromedia Director |
88 | | | '.dxr' => 'application/x-director', // Macromedia Director |
89 | | | '.mif' => 'application/x-mif', // FrameMaker MIF Format |
90 | | | '.csh' => 'application/x-csh', // C-shell script |
91 | | | '.dvi' => 'application/x-dvi', // TeX DVI |
92 | | | '.gz' => 'application/x-gzip', // GNU Zip |
93 | | | '.gzip' => 'application/x-gzip', // GNU Zip |
94 | | | '.hdf' => 'application/x-hdf', // ncSA HDF Data File |
95 | | | '.latex' => 'application/x-latex', // LaTeX source |
96 | | | '.nc' => 'application/x-netcdf', // Unidata netCDF |
97 | | | '.cdf' => 'application/x-netcdf', // Unidata netCDF |
98 | | | '.sit' => 'application/x-stuffit', // Stiffut Archive |
99 | | | '.tcl' => 'application/x-tcl', // TCL script |
100 | | | '.texinfo' => 'application/x-texinfo', // Texinfo (Emacs) |
101 | | | '.texi' => 'application/x-texinfo', // Texinfo (Emacs) |
102 | | | '.t' => 'application/x-troff', // Troff |
103 | | | '.tr' => 'application/x-troff', // Troff |
104 | | | '.roff' => 'application/x-troff', // Troff |
105 | | | '.man' => 'application/x-troff-man', // Troff with MAN macros |
106 | | | '.me' => 'application/x-troff-me', // Troff with ME macros |
107 | | | '.ms' => 'application/x-troff-ms', // Troff with MS macros |
108 | | | '.src' => 'application/x-wais-source', // WAIS source |
109 | | | '.bcpio' => 'application/x-bcpio', // Old binary CPIO |
110 | | | '.cpio' => 'application/x-cpio', // POSIX CPIO |
111 | | | '.gtar' => 'application/x-gtar', // GNU tar |
112 | | | '.shar' => 'application/x-shar', // Shell archive |
113 | | | '.sv4cpio' => 'application/x-sv4cpio', // SVR4 CPIO |
114 | | | '.sv4crc' => 'application/x-sv4crc', // SVR4 CPIO with CRC |
115 | | | '.tar' => 'application/x-tar', // 4.3BSD tar format |
116 | | | '.ustar' => 'application/x-ustar', // POSIX tar format |
117 | | | '.hlp' => 'application/x-winhelp', // Windows Help |
118 | | | '.zip' => 'application/zip', // ZIP archive |
119 | | | '.au' => 'audio/basic', // Basic audio (usually m-law) |
120 | | | '.snd' => 'audio/basic', // Basic audio (usually m-law) |
121 | | | '.aif' => 'audio/x-aiff', // AIFF audio |
122 | | | '.aiff' => 'audio/x-aiff', // AIFF audio |
123 | | | '.aifc' => 'audio/x-aiff', // AIFF audio |
124 | | | '.ra' => 'audio/x-pn-realaudio', // RealAudio |
125 | | | '.ram' => 'audio/x-pn-realaudio', // RealAudio |
126 | | | '.rpm' => 'audio/x-pn-realaudio-plugin', // RealAudio (plug-in) |
127 | | | '.wav' => 'audio/x-wav', // Windows WAVE audio |
128 | | | '.mp3' => 'audio/x-mp3', // MP3 files |
129 | | | '.gif' => 'image/gif', // gif image |
130 | | | '.ief' => 'image/ief', // Image Exchange Format |
131 | | | '.jpg' => 'image/jpeg', // JPEG image |
132 | | | '.jpe' => 'image/jpeg', // JPEG image |
133 | | | '.jpeg' => 'image/jpeg', // JPEG image |
134 | | | '.pict' => 'image/pict', // Macintosh PICT |
135 | | | '.tiff' => 'image/tiff', // TIFF image |
136 | | | '.tif' => 'image/tiff', // TIFF image |
137 | | | '.ras' => 'image/x-cmu-raster', // CMU raster |
138 | | | '.pnm' => 'image/x-portable-anymap', // PBM Anymap format |
139 | | | '.pbm' => 'image/x-portable-bitmap', // PBM Bitmap format |
140 | | | '.pgm' => 'image/x-portable-graymap', // PBM Graymap format |
141 | | | '.ppm' => 'image/x-portable-pixmap', // PBM Pixmap format |
142 | | | '.rgb' => 'image/x-rgb', // RGB Image |
143 | | | '.xbm' => 'image/x-xbitmap', // X Bitmap |
144 | | | '.xpm' => 'image/x-xpixmap', // X Pixmap |
145 | | | '.xwd' => 'image/x-xwindowdump', // X Windows dump (xwd) format |
146 | | | '.zip' => 'multipart/x-zip', // PKZIP Archive |
147 | | | '.gzip' => 'multipart/x-gzip', // GNU ZIP Archive |
148 | | | '.mpeg' => 'video/mpeg', // MPEG video |
149 | | | '.mpg' => 'video/mpeg', // MPEG video |
150 | | | '.mpe' => 'video/mpeg', // MPEG video |
151 | | | '.mpeg' => 'video/mpeg', // MPEG video |
152 | | | '.qt' => 'video/quicktime', // QuickTime Video |
153 | | | '.mov' => 'video/quicktime', // QuickTime Video |
154 | | | '.avi' => 'video/msvideo', // Microsoft Windows Video |
155 | | | '.movie' => 'video/x-sgi-movie', // SGI Movieplayer format |
156 | | | '.wrl' => 'x-world/x-vrml', // VRML Worlds |
157 | | | '.odt' => 'application/vnd.oasis.opendocument.text', // OpenDocument Text |
158 | | | '.ott' => 'application/vnd.oasis.opendocument.text-template', // OpenDocument Text Template |
159 | | | '.ods' => 'application/vnd.oasis.opendocument.spreadsheet', // OpenDocument Spreadsheet |
160 | | | '.ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', // OpenDocument Spreadsheet Template |
161 | | | '.odp' => 'application/vnd.oasis.opendocument.presentation', // OpenDocument Presentation |
162 | | | '.otp' => 'application/vnd.oasis.opendocument.presentation-template', // OpenDocument Presentation Template |
163 | | | '.odg' => 'application/vnd.oasis.opendocument.graphics', // OpenDocument Drawing |
164 | | | '.otg' => 'application/vnd.oasis.opendocument.graphics-template', // OpenDocument Drawing Template |
165 | | | '.odc' => 'application/vnd.oasis.opendocument.chart', // OpenDocument Chart |
166 | | | '.otc' => 'application/vnd.oasis.opendocument.chart-template', // OpenDocument Chart Template |
167 | | | '.odf' => 'application/vnd.oasis.opendocument.formula', // OpenDocument Formula |
168 | | | '.otf' => 'application/vnd.oasis.opendocument.formula-template', // OpenDocument Formula Template |
169 | | | '.odi' => 'application/vnd.oasis.opendocument.image', // OpenDocument Image |
170 | | | '.oti' => 'application/vnd.oasis.opendocument.image-template', // OpenDocument Image Template |
171 | | | '.odm' => 'application/vnd.oasis.opendocument.text-master', // OpenDocument Master Document |
172 | | | '.oth' => 'application/vnd.oasis.opendocument.text-web', // HTML Document Template |
173 | | | '.odb' => 'application/vnd.oasis.opendocument.database', // OpenDocument Database |
174 | | | ); |
175 | | | |
176 | | | // }}} |
177 | | | |
178 | | | // {{{ Enscript file extensions |
179 | | | |
180 | | | // List of extensions recognised by enscript. |
181 | | | |
182 | | | $extEnscript = array |
183 | | | ( |
184 | | | '.ada' => 'ada', |
185 | | | '.adb' => 'ada', |
186 | | | '.ads' => 'ada', |
187 | | | '.awk' => 'awk', |
188 | | | '.c' => 'c', |
189 | | | '.c++' => 'cpp', |
190 | | | '.cc' => 'cpp', |
191 | | | '.cpp' => 'cpp', |
192 | | | '.csh' => 'csh', |
193 | | | '.cxx' => 'cpp', |
194 | | | '.diff' => 'diffu', |
195 | | | '.dpr' => 'delphi', |
196 | | | '.e' => 'eiffel', |
197 | | | '.el' => 'elisp', |
198 | | | '.eps' => 'postscript', |
199 | | | '.f' => 'fortran', |
200 | | | '.for' => 'fortran', |
201 | | | '.gs' => 'haskell', |
202 | | | '.h' => 'c', |
203 | | | '.hpp' => 'cpp', |
204 | | | '.hs' => 'haskell', |
205 | | | '.htm' => 'html', |
206 | | | '.html' => 'html', |
207 | | | '.idl' => 'idl', |
208 | | | '.java' => 'java', |
209 | | | '.js' => 'javascript', |
210 | | | '.lgs' => 'haskell', |
211 | | | '.lhs' => 'haskell', |
212 | | | '.m' => 'objc', |
213 | | | '.m4' => 'm4', |
214 | | | '.man' => 'nroff', |
215 | | | '.nr' => 'nroff', |
216 | | | '.p' => 'pascal', |
217 | | | '.pas' => 'delphi', |
218 | | | '.patch' => 'diffu', |
219 | | | '.pkg' => 'sql', |
220 | | | '.pl' => 'perl', |
221 | | | '.pm' => 'perl', |
222 | | | '.pp' => 'pascal', |
223 | | | '.ps' => 'postscript', |
224 | | | '.s' => 'asm', |
225 | | | '.scheme' => 'scheme', |
226 | | | '.scm' => 'scheme', |
227 | | | '.scr' => 'synopsys', |
228 | | | '.sh' => 'sh', |
229 | | | '.shtml' => 'html', |
230 | | | '.sql' => 'sql', |
231 | | | '.st' => 'states', |
232 | | | '.syn' => 'synopsys', |
233 | | | '.synth' => 'synopsys', |
234 | | | '.tcl' => 'tcl', |
235 | | | '.tex' => 'tex', |
236 | | | '.texi' => 'tex', |
237 | | | '.texinfo' => 'tex', |
238 | | | '.v' => 'verilog', |
239 | | | '.vba' => 'vba', |
240 | | | '.vh' => 'verilog', |
241 | | | '.vhd' => 'vhdl', |
242 | | | '.vhdl' => 'vhdl', |
243 | | | '.py' => 'python', |
244 | | | |
245 | | | // The following are handled internally by WebSVN, since there's no |
246 | | | // support for them in Enscript |
247 | | | |
248 | | | '.php' => 'php', |
249 | | | '.phtml' => 'php', |
250 | | | '.php3' => 'php', |
251 | | | '.php' => 'php' |
252 | | | ); |
253 | | | |
254 | | | // }}} |
255 | | | |
256 | | | // Include a default language file (must go before config.php) |
257 | | | require 'languages/english.php'; |
258 | | | |
259 | | | // Get the user's personalised config (requires the locwebsvnhttp stuff above) |
260 | | | require_once 'config.php'; |
261 | | | |
262 | | | require_once 'include/svnlook.php'; |
263 | | | |
264 | | | // Make sure that the input locale is set up correctly |
265 | | | setlocale(LC_ALL, ''); |
266 | | | |
267 | | | // Default 'zipped' array |
268 | | | |
269 | | | $zipped = array(); |
270 | | | |
271 | | | // Set up the version info |
272 | | | |
273 | | | initSvnVersion($major,$minor); |
274 | | | |
275 | | | // Get the user choice if there is one, and memorise the setting |
276 | | | // as a cookie (since we don't have user accounts, we can't store the setting |
277 | | | // anywhere else). We try to memorise a permanent cookie and a per session cookie |
278 | | | // in case the user has disabled permanent ones. |
279 | | | |
280 | | | $userLang = false; |
281 | | | if (!empty($_REQUEST['langchoice'])) { |
282 | | | $userLang = $_REQUEST['langchoice']; |
283 | | | setcookie('storedlang', $_REQUEST['langchoice'], time()+(3600*24*356*10), '/'); |
284 | | | setcookie('storedsesslang', $_REQUEST['langchoice']); |
285 | | | } else { // Try to read an existing cookie if there is one |
286 | | | if (!empty($_COOKIE['storedlang'])) $userLang = $_COOKIE['storedlang']; |
287 | | | else if (!empty($_COOKIE['storedsesslang'])) $userLang = $_COOKIE['storedsesslang']; |
288 | | | } |
289 | | | |
290 | | | // Load available languages |
291 | | | require 'languages/languages.php'; |
292 | | | |
293 | | | // Get the default language as defined as the default by config.php |
294 | | | $defaultLang = $config->getDefaultLanguage(); |
295 | | | if (!isset($languages[$defaultLang])) $defaultLang = 'en'; |
296 | | | |
297 | | | // Negotiate language |
298 | | | $userLang = getUserLanguage($languages, $defaultLang, $userLang); |
299 | | | $file = $languages[$userLang][0]; |
300 | | | |
301 | | | // Define the language array |
302 | | | $lang = array(); |
303 | | | |
304 | | | // XXX: this shouldn't be necessary |
305 | | | // ^ i.e. just require english.php, then the desired language |
306 | | | // Reload english to get untranslated strings |
307 | | | require 'languages/english.php'; |
308 | | | |
309 | | | // Reload the default language |
310 | | | require 'languages/'.$file.'.php'; |
311 | | | |
312 | | | $vars['lang_code'] = $userLang; |
313 | | | |
314 | | | $url = '?'.buildQuery($_GET + $_POST); |
315 | | | $vars["lang_form"] = "<form action=\"$url\" method=\"post\" id=\"langform\">"; |
316 | | | $vars["lang_select"] = "<select name=\"langchoice\" onchange=\"javascript:this.form.submit();\">"; |
317 | | | |
318 | | | foreach ($languages as $code => $d) { |
319 | | | $sel = ($code == $userLang) ? ' selected="selected"' : ''; |
320 | | | $vars["lang_select"] .= '<option value="'.$code.'"'.$sel.'>'.$d[2].' - '.$d[1].'</option>'; |
321 | | | } |
322 | | | |
323 | | | $vars["lang_select"] .= "</select>"; |
324 | | | $vars["lang_submit"] = "<input type=\"submit\" value=\"${lang["GO"]}\" />"; |
325 | | | $vars["lang_endform"] = "</form>"; |
326 | | | |
327 | | | // Set up headers |
328 | | | |
329 | | | header('Content-Type: text/html; charset=UTF-8'); |
330 | | | header('Content-Language: '.$userLang); |
331 | | | |
332 | | | // Make sure that the user has set up a repository |
333 | | | |
334 | | | $reps = $config->getRepositories(); |
335 | | | if (empty($reps[0])) { |
336 | | | echo $lang["SUPPLYREP"]; |
337 | | | exit; |
338 | | | } |
339 | | | |
340 | | | // Override the rep parameter with the repository name if it's available |
341 | | | $repname = @$_REQUEST["repname"]; |
342 | | | if (isset($repname)) { |
343 | | | $repname = urldecode($repname); |
344 | | | $rep = $config->findRepository($repname); |
345 | | | } else { |
346 | | | $rep = $reps[0]; |
347 | | | } |
348 | | | |
349 | | | // Retrieve other standard parameters |
350 | | | |
351 | | | // due to possible XSS exploit, we need to clean up path first |
352 | | | $path = !empty($_REQUEST['path']) ? $_REQUEST['path'] : null; |
353 | | | $vars['safepath'] = htmlentities($path, ENT_QUOTES, 'UTF-8'); |
354 | | | $rev = (int)@$_REQUEST["rev"]; |
355 | | | |
356 | | | // Function to create the project selection HTML form |
357 | | | function createProjectSelectionForm() { |
358 | | | global $config, $vars, $rep, $lang; |
359 | | | |
360 | | | if (!$config->showRepositorySelectionForm()) { |
361 | | | $vars["projects_form"] = ''; |
362 | | | $vars["projects_select"] = ''; |
363 | | | $vars["projects_submit"] = ''; |
364 | | | $vars["projects_hidden"] = ''; |
365 | | | $vars["projects_endform"] = ''; |
366 | | | return; |
367 | | | } |
368 | | | |
369 | | | $url = $config->getURL(-1, "", "form"); |
370 | | | $vars["projects_form"] = "<form action=\"$url\" method=\"post\" id=\"projectform\">"; |
371 | | | |
372 | | | $reps = $config->getRepositories(); |
373 | | | $vars["projects_select"] = "<select name=\"repname\" onchange=\"javascript:this.form.submit();\">"; |
374 | | | |
375 | | | foreach ($reps as $trep) { |
376 | | | if ($trep->hasReadAccess("/", true)) { |
377 | | | if ($rep->getDisplayName() == $trep->getDisplayName()) { |
378 | | | $sel = ' selected="selected"'; |
379 | | | } else { |
380 | | | $sel = ""; |
381 | | | } |
382 | | | |
383 | | | $vars["projects_select"] .= "<option value=\"".$trep->getDisplayName()."\"$sel>".$trep->getDisplayName()."</option>"; |
384 | | | } |
385 | | | } |
386 | | | |
387 | | | $vars["projects_select"] .= "</select>"; |
388 | | | |
389 | | | $vars["projects_submit"] = "<input type=\"submit\" value=\"${lang["GO"]}\" />"; |
390 | | | $vars["projects_hidden"] = "<input type=\"hidden\" name=\"selectproj\" value=\"1\" /><input type=\"hidden\" name=\"op\" value=\"form\" />"; |
391 | | | $vars["projects_endform"] = "</form>"; |
392 | | | } |
393 | | | |
394 | | | // Function to create the revision selection HTML form |
395 | | | function createRevisionSelectionForm() { |
396 | | | global $config, $vars, $rep, $lang, $showchanged, $rev; |
397 | | | |
398 | | | if ($rev == 0) { |
399 | | | $thisrev = "HEAD"; |
400 | | | } else { |
401 | | | $thisrev = $rev; |
402 | | | } |
403 | | | |
404 | | | list($url, $params) = $config->getUrlParts($rep, '', 'revision'); |
405 | | | $vars["revision_form"] = "<form action=\"$url\" method=\"get\" id=\"revisionform\">"; |
406 | | | |
407 | | | $vars["revision_input"] = "<input type=\"text\" size=\"4\" name=\"rev\" value=\"$thisrev\" />"; |
408 | | | $hidden = ''; |
409 | | | foreach ($params as $k => $v) { |
410 | | | $hidden .= "<input type=\"hidden\" name=\"$k\" value=\"".htmlspecialchars($v)."\" />"; |
411 | | | } |
412 | | | $vars["revision_hidden"] = $hidden; |
413 | | | |
414 | | | $vars["revision_submit"] = "<input type=\"submit\" value=\"${lang["GO"]}\" />"; |
415 | | | $vars["revision_endform"] = "</form>"; |
416 | | | } |
417 | | | |
418 | | | // Create the form if we're not in MultiViews. Otherwise wsvn must create the form once the current project has |
419 | | | // been found |
420 | | | |
421 | | | if (!$config->multiViews) { |
422 | | | createProjectSelectionForm(); |
423 | | | createRevisionSelectionForm(); |
424 | | | } |
425 | | | |
426 | | | if ($rep) { |
427 | | | $vars["allowdownload"] = $rep->getAllowDownload(); |
428 | | | $vars["repname"] = htmlentities($rep->getDisplayName(), ENT_QUOTES, 'UTF-8'); |
429 | | | } |
430 | | | |
431 | | | // As of version 1.70 the output encoding is forced to be UTF-8, since this is the output |
432 | | | // encoding returned by svn log --xml. This is good, since we are no longer reliant on PHP's |
433 | | | // rudimentary conversions. |
434 | | | |
435 | | | $vars["charset"] = "UTF-8"; |