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 | /** |
||
4 | * AJAX: handling of Ajax configuration calls. |
||
5 | * |
||
6 | * This Source Code Form is subject to the terms of the Mozilla Public License, |
||
7 | * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
||
8 | * obtain one at http://mozilla.org/MPL/2.0/. |
||
9 | * |
||
10 | * @package phpMyFAQ |
||
11 | * @author Anatoliy Belsky <[email protected]> |
||
12 | * @author Thorsten Rinne <[email protected]> |
||
13 | * @copyright 2009-2019 phpMyFAQ Team |
||
14 | * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
||
15 | * @link https://www.phpmyfaq.de |
||
16 | * @since 2009-04-01 |
||
17 | */ |
||
18 | |||
19 | use phpMyFAQ\Db; |
||
20 | use phpMyFAQ\Filter; |
||
21 | use phpMyFAQ\Helper\HttpHelper; |
||
22 | use phpMyFAQ\Instance; |
||
23 | use phpMyFAQ\Instance\Client; |
||
24 | use phpMyFAQ\Instance\Setup; |
||
25 | use phpMyFAQ\Instance\Database\Stopwords; |
||
26 | use phpMyFAQ\Language; |
||
27 | use phpMyFAQ\Meta; |
||
28 | use phpMyFAQ\Entity\Meta as MetaEntity; |
||
29 | use phpMyFAQ\User; |
||
30 | |||
31 | if (!defined('IS_VALID_PHPMYFAQ') || !$user->perm->checkRight($user->getUserId(), 'editconfig')) { |
||
32 | header('Location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME'])); |
||
33 | exit(); |
||
34 | } |
||
35 | |||
36 | $ajaxAction = Filter::filterInput(INPUT_GET, 'ajaxaction', FILTER_SANITIZE_STRING); |
||
37 | $instanceId = Filter::filterInput(INPUT_GET, 'instanceId', FILTER_VALIDATE_INT); |
||
38 | $stopwordId = Filter::filterInput(INPUT_GET, 'stopword_id', FILTER_VALIDATE_INT); |
||
39 | $stopword = Filter::filterInput(INPUT_GET, 'stopword', FILTER_SANITIZE_STRING); |
||
40 | $stopwordsLang = Filter::filterInput(INPUT_GET, 'stopwords_lang', FILTER_SANITIZE_STRING); |
||
41 | $csrfToken = Filter::filterInput(INPUT_GET, 'csrf', FILTER_SANITIZE_STRING); |
||
42 | |||
43 | $http = new HttpHelper(); |
||
44 | $stopwords = new Stopwords($faqConfig); |
||
45 | |||
46 | switch ($ajaxAction) { |
||
47 | |||
48 | case 'add_instance': |
||
49 | |||
50 | View Code Duplication | if (!isset($_SESSION['phpmyfaq_csrf_token']) || $_SESSION['phpmyfaq_csrf_token'] !== $csrfToken) { |
|
51 | $http->sendJsonWithHeaders(['error' => $PMF_LANG['err_NotAuth']]); |
||
52 | exit(1); |
||
53 | } |
||
54 | |||
55 | $url = Filter::filterInput(INPUT_GET, 'url', FILTER_SANITIZE_STRING); |
||
56 | $instance = Filter::filterInput(INPUT_GET, 'instance', FILTER_SANITIZE_STRING); |
||
57 | $comment = Filter::filterInput(INPUT_GET, 'comment', FILTER_SANITIZE_STRING); |
||
58 | $email = Filter::filterInput(INPUT_GET, 'email', FILTER_VALIDATE_EMAIL); |
||
59 | $admin = Filter::filterInput(INPUT_GET, 'admin', FILTER_SANITIZE_STRING); |
||
60 | $password = Filter::filterInput(INPUT_GET, 'password', FILTER_SANITIZE_STRING); |
||
61 | |||
62 | $data = array( |
||
63 | 'url' => 'http://'.$url.'.'.$_SERVER['SERVER_NAME'], |
||
64 | 'instance' => $instance, |
||
65 | 'comment' => $comment, |
||
66 | ); |
||
67 | |||
68 | $faqInstance = new Instance($faqConfig); |
||
69 | $instanceId = $faqInstance->addInstance($data); |
||
70 | |||
71 | $faqInstanceClient = new Client($faqConfig); |
||
72 | $faqInstanceClient->createClient($faqInstance); |
||
73 | |||
74 | $urlParts = parse_url($data['url']); |
||
75 | $hostname = $urlParts['host']; |
||
76 | |||
77 | if ($faqInstanceClient->createClientFolder($hostname)) { |
||
78 | $clientDir = PMF_ROOT_DIR.'/multisite/'.$hostname; |
||
79 | $clientSetup = new Setup(); |
||
80 | $clientSetup->setRootDir($clientDir); |
||
81 | |||
82 | $faqInstanceClient->copyConstantsFile($clientDir.'/constants.php'); |
||
83 | |||
84 | $dbSetup = array( |
||
85 | 'dbServer' => $DB['server'], |
||
86 | 'dbUser' => $DB['user'], |
||
87 | 'dbPassword' => $DB['password'], |
||
88 | 'dbDatabaseName' => $DB['db'], |
||
89 | 'dbPrefix' => substr($hostname, 0, strpos($hostname, '.')), |
||
90 | 'dbType' => $DB['type'], |
||
91 | ); |
||
92 | $clientSetup->createDatabaseFile($dbSetup, ''); |
||
93 | |||
94 | $faqInstanceClient->setClientUrl('http://'.$hostname); |
||
95 | $faqInstanceClient->createClientTables($dbSetup['dbPrefix']); |
||
96 | |||
97 | Db::setTablePrefix($dbSetup['dbPrefix']); |
||
98 | |||
99 | // add admin account and rights |
||
100 | $instanceAdmin = new User($faqConfig); |
||
101 | $instanceAdmin->createUser($admin, $password, null, 1); |
||
102 | $instanceAdmin->setStatus('protected'); |
||
103 | $instanceAdminData = array( |
||
104 | 'display_name' => '', |
||
105 | 'email' => $email, |
||
106 | ); |
||
107 | $instanceAdmin->setUserData($instanceAdminData); |
||
108 | |||
109 | // Add anonymous user account |
||
110 | $clientSetup->createAnonymousUser($faqConfig); |
||
111 | |||
112 | Db::setTablePrefix($DB['prefix']); |
||
113 | } else { |
||
114 | $faqInstance->removeInstance($instanceId); |
||
115 | $payload = array('error' => 'Cannot create instance.'); |
||
116 | } |
||
117 | |||
118 | if (0 !== $instanceId) { |
||
119 | $payload = array('added' => $instanceId, 'url' => $data['url']); |
||
120 | } else { |
||
121 | $payload = array('error' => $instanceId); |
||
122 | } |
||
123 | $http->sendJsonWithHeaders($payload); |
||
124 | break; |
||
125 | |||
126 | case 'delete_instance': |
||
127 | |||
128 | View Code Duplication | if (!isset($_SESSION['phpmyfaq_csrf_token']) || $_SESSION['phpmyfaq_csrf_token'] !== $csrfToken) { |
|
129 | $http->sendJsonWithHeaders(['error' => $PMF_LANG['err_NotAuth']]); |
||
130 | exit(1); |
||
131 | } |
||
132 | |||
133 | View Code Duplication | if (null !== $instanceId) { |
|
134 | $faqInstance = new Instance($faqConfig); |
||
135 | if (1 !== $instanceId && $faqInstance->removeInstance($instanceId)) { |
||
136 | $payload = array('deleted' => $instanceId); |
||
137 | } else { |
||
138 | $payload = array('error' => $instanceId); |
||
139 | } |
||
140 | $http->sendJsonWithHeaders($payload); |
||
141 | } |
||
142 | break; |
||
143 | |||
144 | case 'edit_instance': |
||
145 | View Code Duplication | if (null !== $instanceId) { |
|
146 | $faqInstance = new Instance($faqConfig); |
||
147 | if ($faqInstance->removeInstance($instanceId)) { |
||
148 | $payload = array('deleted' => $instanceId); |
||
149 | } else { |
||
150 | $payload = array('error' => $instanceId); |
||
151 | } |
||
152 | $http->sendJsonWithHeaders($payload); |
||
153 | } |
||
154 | break; |
||
155 | |||
156 | case 'load_stop_words_by_lang': |
||
157 | if (Language::isASupportedLanguage($stopwordsLang)) { |
||
158 | $stopwordsList = $stopwords->getByLang($stopwordsLang); |
||
0 ignored issues
–
show
|
|||
159 | |||
160 | $payload = $stopwordsList; |
||
161 | $http->sendJsonWithHeaders($payload); |
||
162 | } |
||
163 | break; |
||
164 | |||
165 | case 'delete_stop_word': |
||
166 | if (null != $stopwordId && Language::isASupportedLanguage($stopwordsLang)) { |
||
167 | $stopwords->setLanguage($stopwordsLang); |
||
0 ignored issues
–
show
The method
setLanguage() does not seem to exist on object<phpMyFAQ\Instance\Database\Stopwords> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
168 | $stopwords->remove($stopwordId); |
||
0 ignored issues
–
show
The method
remove() does not seem to exist on object<phpMyFAQ\Instance\Database\Stopwords> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
169 | } |
||
170 | break; |
||
171 | |||
172 | case 'save_stop_word': |
||
173 | |||
174 | View Code Duplication | if (!isset($_SESSION['phpmyfaq_csrf_token']) || $_SESSION['phpmyfaq_csrf_token'] !== $csrfToken) { |
|
175 | $http->sendJsonWithHeaders(['error' => $PMF_LANG['err_NotAuth']]); |
||
176 | exit(1); |
||
177 | } |
||
178 | |||
179 | if (null != $stopword && Language::isASupportedLanguage($stopwordsLang)) { |
||
180 | $stopwords->setLanguage($stopwordsLang); |
||
0 ignored issues
–
show
The method
setLanguage() does not seem to exist on object<phpMyFAQ\Instance\Database\Stopwords> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
181 | if (null !== $stopwordId && -1 < $stopwordId) { |
||
182 | echo $stopwords->update($stopwordId, $stopword); |
||
0 ignored issues
–
show
The method
update() does not seem to exist on object<phpMyFAQ\Instance\Database\Stopwords> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
183 | } elseif (!$stopwords->match($stopword)) { |
||
0 ignored issues
–
show
The method
match() does not seem to exist on object<phpMyFAQ\Instance\Database\Stopwords> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
184 | echo $stopwords->add($stopword); |
||
0 ignored issues
–
show
The method
add() does not seem to exist on object<phpMyFAQ\Instance\Database\Stopwords> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
185 | } |
||
186 | } |
||
187 | break; |
||
188 | |||
189 | case 'add_meta': |
||
190 | |||
191 | View Code Duplication | if (!isset($_SESSION['phpmyfaq_csrf_token']) || $_SESSION['phpmyfaq_csrf_token'] !== $csrfToken) { |
|
192 | $http->sendJsonWithHeaders(['error' => $PMF_LANG['err_NotAuth']]); |
||
193 | exit(1); |
||
194 | } |
||
195 | |||
196 | $meta = new Meta($faqConfig); |
||
197 | $entity = new MetaEntity(); |
||
198 | |||
199 | $entity |
||
200 | ->setPageId(Filter::filterInput(INPUT_GET, 'page_id', FILTER_SANITIZE_STRING)) |
||
201 | ->setType(Filter::filterInput(INPUT_GET, 'type', FILTER_SANITIZE_STRING)) |
||
202 | ->setContent(Filter::filterInput(INPUT_GET, 'content', FILTER_SANITIZE_SPECIAL_CHARS)); |
||
203 | |||
204 | $metaId = $meta->add($entity); |
||
205 | |||
206 | if (0 !== $metaId) { |
||
207 | $payload = array('added' => $metaId); |
||
208 | } else { |
||
209 | $payload = array('error' => $metaId); |
||
210 | } |
||
211 | $http->sendJsonWithHeaders($payload); |
||
212 | break; |
||
213 | |||
214 | |||
215 | case 'delete_meta': |
||
216 | |||
217 | View Code Duplication | if (!isset($_SESSION['phpmyfaq_csrf_token']) || $_SESSION['phpmyfaq_csrf_token'] !== $csrfToken) { |
|
218 | $http->sendJsonWithHeaders(['error' => $PMF_LANG['err_NotAuth']]); |
||
219 | exit(1); |
||
220 | } |
||
221 | |||
222 | $meta = new Meta($faqConfig); |
||
223 | $metaId = Filter::filterInput(INPUT_GET, 'meta_id', FILTER_SANITIZE_STRING); |
||
224 | |||
225 | if ($meta->delete($metaId)) { |
||
226 | $payload = array('deleted' => $metaId); |
||
227 | } else { |
||
228 | $payload = array('error' => $metaId); |
||
229 | } |
||
230 | |||
231 | $http->sendJsonWithHeaders($payload); |
||
232 | break; |
||
233 | } |
||
234 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.