This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Copyright (c) Enalean, 2015. All Rights Reserved. |
||
4 | * |
||
5 | * Tuleap 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 | * Tuleap 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 Tuleap; if not, write to the Free Software |
||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
18 | */ |
||
19 | |||
20 | require_once 'constants.php'; |
||
21 | |||
22 | class phpwikiPlugin extends Plugin { |
||
23 | |||
24 | const SEARCH_PAGENAME_EN = 'FullTextSearch'; |
||
25 | const SEARCH_PAGENAME_FR = 'RechercheEnTexteIntégral'; |
||
26 | |||
27 | public function __construct($id) { |
||
28 | parent::__construct($id); |
||
29 | $this->setScope(self::SCOPE_PROJECT); |
||
30 | |||
31 | $this->name = 'phpwiki'; |
||
32 | $this->text = 'PHPWiki'; |
||
33 | |||
34 | $this->addHook(Event::LAYOUT_SEARCH_ENTRY); |
||
35 | $this->addHook(Event::SEARCH_TYPE); |
||
36 | $this->addHook(Event::SEARCH_TYPES_PRESENTERS); |
||
37 | |||
38 | $this->addHook('backend_system_purge_files', 'purgeFiles'); |
||
39 | |||
40 | $this->addHook(Event::SERVICE_ICON); |
||
41 | $this->addHook(Event::SERVICES_ALLOWED_FOR_PROJECT); |
||
42 | $this->addHook(Event::SERVICE_PUBLIC_AREAS); |
||
43 | |||
44 | $this->addHook(Event::GET_SYSTEM_EVENT_CLASS); |
||
45 | $this->addHook(Event::SYSTEM_EVENT_GET_TYPES_FOR_DEFAULT_QUEUE); |
||
46 | $this->addHook('site_admin_option_hook'); |
||
47 | |||
48 | if ($this->isDocmanPluginActivated()) { |
||
49 | $this->addHook(PLUGIN_DOCMAN_EVENT_GET_PHPWIKI_PAGE, 'getWikiPage'); |
||
50 | } |
||
51 | |||
52 | $this->addHook('phpwiki_redirection'); |
||
53 | |||
54 | $this->addHook(Event::SERVICES_TRUNCATED_EMAILS); |
||
55 | |||
56 | $this->addHook(Event::REST_PROJECT_GET_PHPWIKI); |
||
57 | $this->addHook(Event::REST_PROJECT_OPTIONS_PHPWIKI); |
||
58 | $this->addHook(EVENT::REST_RESOURCES); |
||
59 | $this->addHook(EVENT::REST_PROJECT_RESOURCES); |
||
60 | |||
61 | } |
||
62 | |||
63 | private function isDocmanPluginActivated() { |
||
64 | return defined('PLUGIN_DOCMAN_BASE_DIR'); |
||
65 | } |
||
66 | |||
67 | public function getPluginInfo() { |
||
68 | if (!is_a($this->pluginInfo, 'PHPWikiPluginInfo')) { |
||
69 | $this->pluginInfo = new PHPWikiPluginInfo($this); |
||
70 | } |
||
71 | return $this->pluginInfo; |
||
72 | } |
||
73 | |||
74 | public function getServiceShortname() { |
||
75 | return 'plugin_phpwiki'; |
||
76 | } |
||
77 | |||
78 | public function service_icon($params) { |
||
79 | $params['list_of_icon_unicodes'][$this->getServiceShortname()] = '\e803'; |
||
80 | } |
||
81 | |||
82 | public function service_public_areas($params) { |
||
83 | if ($params['project']->usesService($this->getServiceShortname())) { |
||
84 | $service = $params['project']->getService($this->getServiceShortname()); |
||
85 | $wiki = new PHPWiki($params['project']->getID()); |
||
86 | |||
87 | $presenter = new WidgetPublicAreaPresenter( |
||
88 | $service->getUrl(), |
||
89 | $GLOBALS['HTML']->getImagePath('ic/wiki.png'), |
||
90 | $this->text, |
||
91 | $wiki->getProjectPageCount() |
||
92 | ); |
||
93 | $renderer = TemplateRendererFactory::build()->getRenderer(PHPWIKI_TEMPLATE_DIR); |
||
94 | $params['areas'][] = $renderer->renderToString('widget_public_area', $presenter); |
||
95 | } |
||
96 | } |
||
97 | |||
98 | public function process(HTTPRequest $request) { |
||
99 | $wiki = new PHPWikiService($request->get('group_id')); |
||
100 | $wiki->process(); |
||
101 | } |
||
102 | |||
103 | public function processAdmin(HTTPRequest $request) { |
||
104 | $wiki = new PHPWikiServiceAdmin($request->get('group_id')); |
||
105 | $wiki->process(); |
||
106 | } |
||
107 | |||
108 | public function processUpload(HTTPRequest $request) { |
||
109 | $attch = new PHPWikiAttachment(); |
||
110 | $request_uri = preg_replace('/^\/wiki/', PHPWIKI_PLUGIN_BASE_URL, $request->getFromServer('REQUEST_URI')); |
||
111 | $attch->setUri($request_uri); |
||
0 ignored issues
–
show
|
|||
112 | if($attch->exist() && $attch->isActive()) { |
||
113 | if($attch->isAutorized(user_getid())) { |
||
114 | $attch->htmlDump(); |
||
115 | } |
||
116 | } |
||
117 | else { |
||
118 | exit_error($GLOBALS['Language']->getText('global','error'), |
||
119 | $GLOBALS['Language']->getText('plugin_phpwiki_attachment_upload', 'err_not_exist')); |
||
120 | } |
||
121 | } |
||
122 | |||
123 | public function layout_search_entry($params) { |
||
124 | $is_in_phpwiki = strpos($_SERVER['REQUEST_URI'], PHPWIKI_PLUGIN_BASE_URL . '/') !== false; |
||
125 | $params['search_entries'][] = array( |
||
126 | 'value' => $this->name, |
||
127 | 'label' => $this->text, |
||
128 | 'selected' => $is_in_phpwiki, |
||
129 | ); |
||
130 | } |
||
131 | |||
132 | public function search_type($params) { |
||
133 | $query = $params['query']; |
||
134 | $project = $query->getProject(); |
||
135 | if ($query->getTypeOfSearch() === $this->name) { |
||
136 | if (!$project->isError()) { |
||
137 | util_return_to($this->getPhpwikiSearchURI($project, $query->getWords())); |
||
138 | } |
||
139 | } |
||
140 | } |
||
141 | |||
142 | public function search_types_presenters($params) { |
||
143 | if ($this->isSearchEntryAvailable($params['project'])) { |
||
144 | $params['project_presenters'][] = new Search_SearchTypePresenter( |
||
145 | $this->name, |
||
146 | $this->text, |
||
147 | array(), |
||
148 | $this->getPhpwikiSearchURI($params['project'], $params['words']) |
||
149 | ); |
||
150 | } |
||
151 | } |
||
152 | |||
153 | private function isSearchEntryAvailable(Project $project = null) { |
||
154 | if ($project && !$project->isError()) { |
||
155 | return $project->usesService('plugin_phpwiki'); |
||
156 | } |
||
157 | return false; |
||
158 | } |
||
159 | |||
160 | private function getPhpwikiSearchURI(Project $project, $words) { |
||
161 | $project_id = $project->getID(); |
||
162 | $page_name = $this->getSearchPageName($project->getID()); |
||
163 | return $this->getPluginPath() . '/index.php?group_id=' . $project_id . '&pagename=' . urlencode($page_name) . '&s=' . urlencode($words); |
||
164 | } |
||
165 | |||
166 | private function getSearchPageName($project_id) { |
||
167 | $wiki_dao = new PHPWikiDao(); |
||
168 | $search_page = self::SEARCH_PAGENAME_EN; |
||
169 | if ($wiki_dao->searchLanguage($project_id) == 'fr_FR') { |
||
170 | $search_page = self::SEARCH_PAGENAME_FR; |
||
171 | } |
||
172 | |||
173 | return $search_page; |
||
174 | } |
||
175 | |||
176 | public function purgeFiles($params) { |
||
177 | $wiki_attachment = new PHPWikiAttachment(); |
||
178 | $wiki_attachment->purgeAttachments($params['time']); |
||
179 | } |
||
180 | |||
181 | public function getWikiPage($params) { |
||
182 | $project_manager = ProjectManager::instance(); |
||
183 | $project = $project_manager->getProject($params['project_id']); |
||
184 | if ($project->usesService($this->getServiceShortname())) { |
||
185 | $wiki_page = new PHPWikiPage($params['project_id'], $params['wiki_page_name']); |
||
186 | $params['phpwiki_page'] = $wiki_page; |
||
187 | } |
||
188 | } |
||
189 | |||
190 | public function phpwiki_redirection($params) { |
||
191 | $request = HTTPRequest::instance(); |
||
192 | $project = $request->getProject(); |
||
193 | if ($project && $project->usesService($this->getServiceShortname())) { |
||
194 | $requested_uri = $request->getFromServer('REQUEST_URI'); |
||
195 | $new_uri = preg_replace('/^\/wiki/', PHPWIKI_PLUGIN_BASE_URL, $requested_uri); |
||
196 | $GLOBALS['Response']->redirect($new_uri); |
||
197 | } |
||
198 | } |
||
199 | |||
200 | public function site_admin_option_hook() { |
||
201 | echo '<li><a href="' . $this->getPluginPath() . '/admin.php?action=index">' . $this->text . '</a></li>'; |
||
202 | } |
||
203 | |||
204 | public function system_event_get_types_for_default_queue(array &$params) { |
||
205 | $params['types'] = array_merge($params['types'], array(SystemEvent_PHPWIKI_SWITCH_TO_PLUGIN::NAME)); |
||
206 | } |
||
207 | |||
208 | public function get_system_event_class($params) { |
||
209 | switch($params['type']) { |
||
210 | case SystemEvent_PHPWIKI_SWITCH_TO_PLUGIN::NAME: |
||
211 | $params['class'] = 'SystemEvent_PHPWIKI_SWITCH_TO_PLUGIN'; |
||
212 | $params['dependencies'] = array( |
||
213 | $this->getPHPWikiMigratorDao() |
||
214 | ); |
||
215 | } |
||
216 | } |
||
217 | |||
218 | private function getPHPWikiMigratorDao() { |
||
219 | return new PHPWikiMigratorDao(); |
||
220 | } |
||
221 | |||
222 | public function services_truncated_emails($params) { |
||
223 | $project = $params['project']; |
||
224 | if ($project->usesService($this->getServiceShortname())) { |
||
225 | $params['services'][] = $GLOBALS['Language']->getText('plugin_phpwiki', 'service_lbl_key'); |
||
226 | } |
||
227 | } |
||
228 | |||
229 | public function rest_project_get_phpwiki($params) { |
||
230 | $user = $params['user']; |
||
231 | $project = $params['project']; |
||
232 | |||
233 | if (! $this->userCanAccessPhpWikiService($user, $project)) { |
||
234 | $class_exception = 'Luracast\Restler\RestException'; |
||
235 | throw new $class_exception(403, 'You are not allowed to access the PHPWiki plugin'); |
||
236 | } |
||
237 | |||
238 | if ($project->usesService($this->getServiceShortname())) { |
||
239 | $class = 'Tuleap\PhpWiki\REST\v1\ProjectResource'; |
||
240 | $project_resource = new $class($this->getPaginatedPHPWikiPagesFactory()); |
||
241 | $project = $params['project']; |
||
242 | |||
243 | $params['result'] = $project_resource->getPhpWikiPlugin( |
||
244 | $user, |
||
245 | $project->getID(), |
||
246 | $params['limit'], |
||
247 | $params['offset'], |
||
248 | $params['pagename'] |
||
249 | ); |
||
250 | } |
||
251 | } |
||
252 | |||
253 | public function rest_project_options_phpwiki($params) { |
||
254 | $params['activated'] = true; |
||
255 | } |
||
256 | |||
257 | /** |
||
258 | * @return bool |
||
259 | */ |
||
260 | private function userCanAccessPhpWikiService(PFUser $user, Project $project) { |
||
261 | $wiki = new PHPWiki($project->getID()); |
||
262 | return $wiki->isAutorized($user->getId()); |
||
263 | } |
||
264 | |||
265 | /** |
||
266 | * @return PaginatedPHPWikiPagesFactory |
||
267 | */ |
||
268 | private function getPaginatedPHPWikiPagesFactory() { |
||
269 | return new PaginatedPHPWikiPagesFactory(new PHPWikiDao()); |
||
270 | } |
||
271 | |||
272 | /** |
||
273 | * @see REST_RESOURCES |
||
274 | */ |
||
275 | public function rest_resources($params) { |
||
276 | $injector = new PHPWikiPlugin_REST_ResourcesInjector(); |
||
277 | $injector->populate($params['restler']); |
||
278 | } |
||
279 | |||
280 | /** |
||
281 | * @see Event::REST_PROJECT_RESOURCES |
||
282 | */ |
||
283 | public function rest_project_resources(array $params) { |
||
284 | $injector = new PHPWikiPlugin_REST_ResourcesInjector(); |
||
285 | $injector->declarePhpWikiPluginResource($params['resources'], $params['project']); |
||
286 | } |
||
287 | } |
||
288 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.