1<?php 2 3use App\Repository\BugRepository; 4use App\Repository\ObsoletePatchRepository; 5use App\Repository\PatchRepository; 6use App\Utils\PatchTracker; 7use App\Utils\Diff; 8 9session_start(); 10 11// Obtain common includes 12require_once '../include/prepend.php'; 13 14$obsoletePatchRepository = $container->get(ObsoletePatchRepository::class); 15$patchRepository = $container->get(PatchRepository::class); 16$patchTracker = $container->get(PatchTracker::class); 17 18// Authenticate 19bugs_authenticate($user, $pw, $logged_in, $user_flags); 20 21if (!isset($_GET['bug_id']) && !isset($_GET['bug'])) { 22 response_header('Error :: no bug selected'); 23 display_bug_error('No patch selected to view'); 24 response_footer(); 25 exit; 26} 27 28$canpatch = ($logged_in == 'developer'); 29 30$revision = isset($_GET['revision']) ? $_GET['revision'] : null; 31$patch_name = isset($_GET['patch']) ? $_GET['patch'] : null; 32if ($patch_name) { 33 $patch_name_url = urlencode($patch_name); 34} 35 36$bug_id = !empty($_GET['bug']) ? (int) $_GET['bug'] : 0; 37if (empty($bug_id)) { 38 $bug_id = (int) $_GET['bug_id']; 39} 40 41$bugRepository = $container->get(BugRepository::class); 42 43if (!($buginfo = $bugRepository->findOneById($bug_id))) { 44 response_header('Error :: invalid bug selected'); 45 display_bug_error("Invalid bug #{$bug_id} selected"); 46 response_footer(); 47 exit; 48} 49 50if (!bugs_has_access($bug_id, $buginfo, $pw, $user_flags)) { 51 response_header('Error :: No access to bug selected'); 52 display_bug_error("You have no access to bug #{$bug_id}"); 53 response_footer(); 54 exit; 55} 56 57if (isset($patch_name) && isset($revision)) { 58 if ($revision == 'latest') { 59 $revisions = $patchRepository->findRevisions($buginfo['id'], $patch_name); 60 if (isset($revisions[0])) { 61 $revision = $revisions[0]['revision']; 62 } 63 } 64 65 $path = $patchTracker->getPatchFullpath($bug_id, $patch_name, $revision); 66 if (!file_exists($path)) { 67 response_header('Error :: no such patch/revision'); 68 display_bug_error('Invalid patch/revision specified'); 69 response_footer(); 70 exit; 71 } 72 73 if (isset($_GET['download'])) { 74 header('Last-modified: ' . gmdate('l, d-M-y H:i:s \G\M\T', filemtime($path))); 75 header('Content-type: application/octet-stream'); 76 header('Content-disposition: attachment; filename="' . $patch_name . '.patch.txt"'); 77 header('Content-length: '.filesize($path)); 78 readfile($path); 79 exit; 80 } 81 82 try { 83 $patchcontents = $patchRepository->getPatchContents($buginfo['id'], $patch_name, $revision); 84 } catch (\Exception $e) { 85 response_header('Error :: Cannot retrieve patch'); 86 display_bug_error('Internal error: Invalid patch/revision specified (is in database, but not in filesystem)'); 87 response_footer(); 88 exit; 89 } 90 91 $package_name = $buginfo['package_name']; 92 $handle = $patchRepository->findDeveloper($bug_id, $patch_name, $revision); 93 $obsoletedby = $obsoletePatchRepository->findObsoletingPatches($bug_id, $patch_name, $revision); 94 $obsoletes = $obsoletePatchRepository->findObsoletePatches($bug_id, $patch_name, $revision); 95 $patches = $patchRepository->findAllByBugId($bug_id); 96 $revisions = $patchRepository->findRevisions($bug_id, $patch_name); 97 98 response_header("Bug #{$bug_id} :: Patches"); 99 include "{$ROOT_DIR}/templates/listpatches.php"; 100 101 if (isset($_GET['diff']) && $_GET['diff'] && isset($_GET['old']) && is_numeric($_GET['old'])) { 102 $old = $patchTracker->getPatchFullpath($bug_id, $patch_name, $_GET['old']); 103 $new = $path; 104 if (!realpath($old) || !realpath($new)) { 105 response_header('Error :: Cannot retrieve patch'); 106 display_bug_error('Internal error: Invalid patch revision specified for diff'); 107 response_footer(); 108 exit; 109 } 110 111 assert_options(ASSERT_WARNING, 0); 112 113 $d = new \Horde_Text_Diff('auto', [file($old), file($new)]); 114 $diff = new Diff($d); 115 116 include "{$ROOT_DIR}/templates/patchdiff.php"; 117 118 response_footer(); 119 exit; 120 } 121 include "{$ROOT_DIR}/templates/patchdisplay.php"; 122 response_footer(); 123 exit; 124} 125 126$patches = $patchTracker->listPatches($bug_id); 127response_header("Bug #{$bug_id} :: Patches"); 128include "{$ROOT_DIR}/templates/listpatches.php"; 129response_footer(); 130