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 | * User: tanchik |
||
4 | * Date: 15.07.14 18:18 |
||
5 | */ |
||
6 | |||
7 | use Yandex\Metrica\Management\ManagementClient; |
||
8 | |||
9 | $operations = array(); |
||
10 | $errorMessage = false; |
||
11 | $counterId = null; |
||
12 | |||
13 | //Is auth |
||
14 | View Code Duplication | if (isset($_COOKIE['yaAccessToken']) && isset($_COOKIE['yaClientId'])) { |
|
0 ignored issues
–
show
|
|||
15 | $settings = require_once '../../settings.php'; |
||
16 | |||
17 | try { |
||
18 | $managementClient = new ManagementClient($_COOKIE['yaAccessToken']); |
||
19 | |||
20 | if (isset($_GET['counter-id']) && $_GET['counter-id']) { |
||
21 | $counterId = $_GET['counter-id']; |
||
22 | //GET /management/v1/counter/{counterId}/operations; |
||
23 | /** |
||
24 | * @see http://api.yandex.ru/metrika/doc/beta/management/operations/operations.xml |
||
25 | */ |
||
26 | $operations = $managementClient->operations()->getOperations($counterId); |
||
27 | } |
||
28 | } catch (\Exception $ex) { |
||
29 | $errorMessage = $ex->getMessage(); |
||
30 | if ($errorMessage === 'PlatformNotAllowed') { |
||
31 | $errorMessage .= '<p>Возможно, у приложения нет прав на доступ к ресурсу. Попробуйте ' |
||
32 | . '<a href="' . rtrim(str_replace($_SERVER['DOCUMENT_ROOT'], '', __DIR__), "/") . '/../OAuth/' . '">авторизироваться</a> и повторить.</p>'; |
||
33 | } |
||
34 | } |
||
35 | } |
||
36 | ?> |
||
37 | <!doctype html> |
||
38 | <html lang="en-US"> |
||
39 | <head> |
||
40 | <meta charset="UTF-8"> |
||
41 | <title>Yandex.SDK: Metrica Demo</title> |
||
42 | |||
43 | <link rel="stylesheet" href="//yandex.st/bootstrap/3.0.3/css/bootstrap.min.css"> |
||
44 | <link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet"> |
||
45 | <link rel="stylesheet" href="/examples/Disk/css/style.css"> |
||
46 | |||
47 | </head> |
||
48 | <body> |
||
49 | |||
50 | <div class="container"> |
||
51 | <div class="jumbotron"> |
||
52 | <h2><a href="/examples/Metrica"><span class="glyphicon glyphicon-tasks"></span></a> Пример работы с Яндекс Метрикой</h2> |
||
53 | </div> |
||
54 | <ol class="breadcrumb"> |
||
55 | <li><a href="/examples">Examples</a></li> |
||
56 | <li><a href="/examples/Metrica">Metrica</a></li> |
||
57 | <li><a href="/examples/Metrica/Management/counters.php">Счетчики</a></li> |
||
58 | <li class="active">Операции</li> |
||
59 | </ol> |
||
60 | <?php |
||
61 | if (!isset($_COOKIE['yaAccessToken']) || !isset($_COOKIE['yaClientId'])) { |
||
62 | ?> |
||
63 | <div class="alert alert-info"> |
||
64 | Для просмотра этой страницы вам необходимо авторизироваться. |
||
65 | <a id="goToAuth" href="/examples/OAuth" class="alert-link">Перейти на страницу авторизации</a>. |
||
66 | </div> |
||
67 | <?php |
||
68 | } else { |
||
69 | if ($errorMessage) { |
||
0 ignored issues
–
show
The expression
$errorMessage of type string|false is loosely compared to true ; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
![]() |
|||
70 | ?> |
||
71 | <div class="alert alert-danger"><?= $errorMessage ?></div> |
||
72 | <?php |
||
73 | } else { |
||
74 | ?> |
||
75 | <div> |
||
76 | <h3>Операции:</h3> |
||
77 | <table id="operationsTable" class="table table-striped table-bordered table-hover"> |
||
78 | <thead> |
||
79 | <tr> |
||
80 | <td>ID</td> |
||
81 | <td>Тип</td> |
||
82 | <td>Поле для фильтрации</td> |
||
83 | <td>Значение для замены</td> |
||
84 | <td>Статус</td> |
||
85 | </tr> |
||
86 | </thead> |
||
87 | <tbody> |
||
88 | <?php |
||
89 | if ($operations instanceof Traversable) { |
||
90 | foreach ($operations as $operation) { |
||
91 | ?> |
||
92 | <tr data-operation-id="<?= $operation->getId() ?>"> |
||
93 | <td><?= $operation->getId() ?></td> |
||
94 | <td><?= $operation->getAction() ?></td> |
||
95 | <td><?= $operation->getAttr() ?></td> |
||
96 | <td><?= $operation->getValue() ?></td> |
||
97 | <td><?= $operation->getStatus() ?></td> |
||
98 | <td style="text-align: center"> |
||
99 | |||
100 | <button type="button" |
||
101 | class="btn btn-info showOperation"> |
||
102 | <span title="Открыть" class="glyphicon glyphicon-eye-open"></span> |
||
103 | </button> |
||
104 | |||
105 | <button type="button" |
||
106 | class="btn btn-warning updateOperation"> |
||
107 | <span title="Изменить" |
||
108 | class="glyphicon glyphicon-edit"></span> |
||
109 | </button> |
||
110 | <button type="button" class="btn btn-danger deleteOperation"> |
||
111 | <span title="Удалить" |
||
112 | class="glyphicon glyphicon-trash"></span> |
||
113 | </button> |
||
114 | </td> |
||
115 | </tr> |
||
116 | <?php |
||
117 | } |
||
118 | } |
||
119 | ?> |
||
120 | </tbody> |
||
121 | </table> |
||
122 | <button id="openAddOperationModal" type="button" class="btn btn-success"> |
||
123 | <span title="Создать счетчик" |
||
124 | class="glyphicon glyphicon-plus"> Создать операцию</span> |
||
125 | </button> |
||
126 | </div> |
||
127 | <?php |
||
128 | } |
||
129 | } |
||
130 | ?> |
||
131 | </div> |
||
132 | |||
133 | <!-- Modal --> |
||
134 | <div class="modal fade" id="errorModal" tabindex="-1" role="dialog" aria-hidden="true"> |
||
135 | <div class="modal-dialog"> |
||
136 | <div class="modal-content"> |
||
137 | <div class="modal-header"> |
||
138 | <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> |
||
139 | <h4 class="modal-title">Ошибка</h4> |
||
140 | </div> |
||
141 | <div class="modal-body"> |
||
142 | <div id="errorMessage"></div> |
||
143 | </div> |
||
144 | <div class="modal-footer"> |
||
145 | <button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button> |
||
146 | </div> |
||
147 | </div> |
||
148 | </div> |
||
149 | </div> |
||
150 | |||
151 | <!-- Modal --> |
||
152 | <div class="modal fade" id="showOperationModal" tabindex="-1" role="dialog" aria-hidden="true"> |
||
153 | <div class="modal-dialog"> |
||
154 | <div class="modal-content"> |
||
155 | <div class="modal-header"> |
||
156 | <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> |
||
157 | <h4 class="modal-title">Информация об операции</h4> |
||
158 | </div> |
||
159 | <div class="modal-body"> |
||
160 | <p><label>ID:</label> <span id="showOperationId"></span></p> |
||
161 | |||
162 | <p><label>Тип:</label> <span id="showOperationAction"></span></p> |
||
163 | |||
164 | <p><label>Поле для фильтрации:</label> <span id="showOperationAttr"></span></p> |
||
165 | |||
166 | <p><label>Значение для замены:</label> <span id="showOperationValue"></span></p> |
||
167 | |||
168 | <p><label>Статус:</label> <span id="showOperationStatus"></span></p> |
||
169 | |||
170 | </div> |
||
171 | <div class="modal-footer"> |
||
172 | <button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button> |
||
173 | </div> |
||
174 | </div> |
||
175 | </div> |
||
176 | </div> |
||
177 | |||
178 | |||
179 | <!-- Modal --> |
||
180 | <div class="modal fade" id="addOperationModal" tabindex="-1" role="dialog" aria-hidden="true"> |
||
181 | <div class="modal-dialog"> |
||
182 | <div class="modal-content"> |
||
183 | <div class="modal-header"> |
||
184 | <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> |
||
185 | <h4 class="modal-title">Создание операции</h4> |
||
186 | </div> |
||
187 | <div class="modal-body"> |
||
188 | <form class="form-horizontal" role="form"> |
||
189 | <div class="form-group"> |
||
190 | <label for="addOperationAction" class="col-sm-2 control-label">Тип</label> |
||
191 | |||
192 | <div class="col-sm-10"> |
||
193 | <input type="text" class="form-control" id="addOperationAction" placeholder="Тип"> |
||
194 | </div> |
||
195 | </div> |
||
196 | <div class="form-group"> |
||
197 | <label for="addOperationAttr" class="col-sm-2 control-label">Поле для фильтрации</label> |
||
198 | |||
199 | <div class="col-sm-10"> |
||
200 | <input type="text" class="form-control" id="addOperationAttr" placeholder="Поле для фильтрации"> |
||
201 | </div> |
||
202 | </div> |
||
203 | <div class="form-group"> |
||
204 | <label for="addOperationValue" class="col-sm-2 control-label">Значение для замены</label> |
||
205 | |||
206 | <div class="col-sm-10"> |
||
207 | <input type="text" class="form-control" id="addOperationValue" placeholder="Значение для замены"> |
||
208 | </div> |
||
209 | </div> |
||
210 | <div class="form-group"> |
||
211 | <label for="addOperationStatus" class="col-sm-2 control-label">Статус</label> |
||
212 | |||
213 | <div class="col-sm-10"> |
||
214 | <input type="text" class="form-control" id="addOperationStatus" placeholder="Статус"> |
||
215 | </div> |
||
216 | </div> |
||
217 | </form> |
||
218 | </div> |
||
219 | <div class="modal-footer"> |
||
220 | <button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button> |
||
221 | <button type="button" id="createOperation" class="btn btn-primary">Создать</button> |
||
222 | </div> |
||
223 | </div> |
||
224 | </div> |
||
225 | </div> |
||
226 | |||
227 | |||
228 | <!-- Modal --> |
||
229 | <div class="modal fade" id="updateOperationModal" tabindex="-1" role="dialog" aria-hidden="true"> |
||
230 | <div class="modal-dialog"> |
||
231 | <div class="modal-content"> |
||
232 | <div class="modal-header"> |
||
233 | <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> |
||
234 | <h4 class="modal-title">Изменение операции</h4> |
||
235 | </div> |
||
236 | <div class="modal-body"> |
||
237 | <form class="form-horizontal" role="form"> |
||
238 | <input type="hidden" id="updateOperationId"> |
||
239 | |||
240 | <div class="form-group"> |
||
241 | <label for="updateOperationAction" class="col-sm-2 control-label">Тип</label> |
||
242 | |||
243 | <div class="col-sm-10"> |
||
244 | <input type="text" class="form-control" id="updateOperationAction" placeholder="Тип"> |
||
245 | </div> |
||
246 | </div> |
||
247 | <div class="form-group"> |
||
248 | <label for="updateOperationAttr" class="col-sm-2 control-label">Поле для фильтрации</label> |
||
249 | |||
250 | <div class="col-sm-10"> |
||
251 | <input type="text" class="form-control" id="updateOperationAttr" placeholder="Поле для фильтрации"> |
||
252 | </div> |
||
253 | </div> |
||
254 | <div class="form-group"> |
||
255 | <label for="updateOperationValue" class="col-sm-2 control-label">Значение для замены</label> |
||
256 | |||
257 | <div class="col-sm-10"> |
||
258 | <input type="text" class="form-control" id="updateOperationValue" placeholder="Значение для замены"> |
||
259 | </div> |
||
260 | </div> |
||
261 | <div class="form-group"> |
||
262 | <label for="updateOperationStatus" class="col-sm-2 control-label">Статус</label> |
||
263 | |||
264 | <div class="col-sm-10"> |
||
265 | <input type="text" class="form-control" id="updateOperationStatus" placeholder="Статус"> |
||
266 | </div> |
||
267 | </div> |
||
268 | </form> |
||
269 | </div> |
||
270 | <div class="modal-footer"> |
||
271 | <button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button> |
||
272 | <button type="button" id="saveOperation" class="btn btn-primary">Сохранить</button> |
||
273 | </div> |
||
274 | </div> |
||
275 | </div> |
||
276 | </div> |
||
277 | |||
278 | |||
279 | <!-- Modal --> |
||
280 | <div class="modal fade" id="deleteOperationModal" tabindex="-1" role="dialog" aria-hidden="true"> |
||
281 | <div class="modal-dialog"> |
||
282 | <div class="modal-content"> |
||
283 | <div class="modal-header"> |
||
284 | <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> |
||
285 | <h4 class="modal-title">Удалить операцию?</h4> |
||
286 | </div> |
||
287 | <div class="modal-body"> |
||
288 | <input type="hidden" id="deleteOperationId"> |
||
289 | </div> |
||
290 | <div class="modal-footer"> |
||
291 | <button type="button" class="btn btn-default" data-dismiss="modal">Отмена</button> |
||
292 | <button type="button" id="deleteOperation" class="btn btn-danger">Удалить!</button> |
||
293 | </div> |
||
294 | </div> |
||
295 | </div> |
||
296 | </div> |
||
297 | |||
298 | <script src="http://yandex.st/jquery/2.0.3/jquery.min.js"></script> |
||
299 | <script src="http://yandex.st/jquery/cookie/1.0/jquery.cookie.min.js"></script> |
||
300 | <script src="http://yandex.st/bootstrap/3.0.3/js/bootstrap.min.js"></script> |
||
301 | |||
302 | <script> |
||
303 | $(function () { |
||
304 | |||
305 | $('#goToAuth').click(function (e) { |
||
306 | $.cookie('back', location.href, { expires: 256, path: '/' }); |
||
307 | }); |
||
308 | |||
309 | var $operationsTable = $("#operationsTable"); |
||
310 | |||
311 | $operationsTable.on('click', '.showOperation', function () { |
||
312 | var $el = $(this); |
||
313 | var operationId = $el.parents('tr').data('operation-id'); |
||
314 | |||
315 | $.get( |
||
316 | "/examples/Metrica/api.php", |
||
317 | { |
||
318 | method: 'getOperation', |
||
319 | counterId: <?= $counterId ?>, |
||
320 | operationId: operationId |
||
321 | }, |
||
322 | function (data) { |
||
323 | var response = JSON.parse(data); |
||
324 | if (response.status === 'ok' && response.result !== null) { |
||
325 | |||
326 | $('#showOperationId').text(response.result.id); |
||
327 | $('#showOperationAction').text(response.result.action); |
||
328 | $('#showOperationAttr').text(response.result.attr); |
||
329 | $('#showOperationValue').text(response.result.value); |
||
330 | $('#showOperationStatus').text(response.result.status); |
||
331 | |||
332 | $('#showOperationModal').modal('show'); |
||
333 | } else { |
||
334 | displayError(response.message); |
||
335 | } |
||
336 | } |
||
337 | ); |
||
338 | }); |
||
339 | |||
340 | |||
341 | $('#openAddOperationModal').click(function () { |
||
342 | $('#addOperationModal').modal('show'); |
||
343 | }); |
||
344 | |||
345 | $operationsTable.on('click', '.updateOperation', function () { |
||
346 | var $el = $(this); |
||
347 | var operationId = $el.parents('tr').data('operation-id'); |
||
348 | |||
349 | $.get( |
||
350 | "/examples/Metrica/api.php", |
||
351 | { |
||
352 | method: 'getOperation', |
||
353 | counterId: <?= $counterId ?>, |
||
354 | operationId: operationId, |
||
355 | action: $('#updateOperationAction').val(), |
||
356 | attr: $('#updateOperationAttr').val(), |
||
357 | value: $('#updateOperationValue').val(), |
||
358 | status: $('#updateOperationStatus').val() |
||
359 | }, |
||
360 | function (data) { |
||
361 | var response = JSON.parse(data); |
||
362 | if (response.status === 'ok' && response.result !== null) { |
||
363 | $('#updateOperationId').val(response.result.id); |
||
364 | $('#updateOperationAction').val(response.result.action); |
||
365 | $('#updateOperationAttr').val(response.result.attr); |
||
366 | $('#updateOperationValue').val(response.result.value); |
||
367 | $('#updateOperationStatus').val(response.result.status); |
||
368 | |||
369 | $('#updateOperationModal').modal('show'); |
||
370 | } else { |
||
371 | displayError(response.message); |
||
372 | } |
||
373 | } |
||
374 | ); |
||
375 | }); |
||
376 | |||
377 | |||
378 | $operationsTable.on('click', '.deleteOperation', function () { |
||
379 | var operationId = $el.parents('tr').data('operation-id'); |
||
380 | $('#deleteOperationId').val(operationId); |
||
381 | $('#deleteOperationModal').modal('show'); |
||
382 | }); |
||
383 | |||
384 | |||
385 | $('#createOperation').click(function () { |
||
386 | $.post( |
||
387 | "/examples/Metrica/api.php", |
||
388 | { |
||
389 | method: 'addOperation', |
||
390 | counterId: <?= $counterId ?>, |
||
391 | action: $('#addOperationAction').val(), |
||
392 | attr: $('#addOperationAttr').val(), |
||
393 | value: $('#addOperationValue').val(), |
||
394 | status: $('#addOperationStatus').val() |
||
395 | }, |
||
396 | function (data) { |
||
397 | $('#addOperationModal').modal('hide'); |
||
398 | |||
399 | var response = JSON.parse(data); |
||
400 | if (response.status === 'ok' && response.result !== null) { |
||
401 | |||
402 | var html = '\ |
||
403 | <tr data-operation-id="' + response.result.id + '">\ |
||
404 | <td>' + response.result.id + '</td>\ |
||
405 | <td>' + response.result.action + '</td>\ |
||
406 | <td>' + response.result.attr + '</td>\ |
||
407 | <td>' + response.result.value + '</td>\ |
||
408 | <td>' + response.result.status + '</td>\ |
||
409 | <td style="text-align: center">\ |
||
410 | <button type="button" class="btn btn-info showOperation">\ |
||
411 | <span title="Открыть" class="glyphicon glyphicon-eye-open"></span>\ |
||
412 | </button>\ |
||
413 | <button type="button" class="btn btn-warning updateOperation">\ |
||
414 | <span title="Изменить" class="glyphicon glyphicon-edit"></span>\ |
||
415 | </button>\ |
||
416 | <button type="button" class="btn btn-danger deleteOperation">\ |
||
417 | <span title="Удалить" class="glyphicon glyphicon-trash "></span>\ |
||
418 | </button>\ |
||
419 | </td>\ |
||
420 | </tr>'; |
||
421 | |||
422 | $operationsTable.find('tbody').append(html); |
||
423 | |||
424 | |||
425 | } else { |
||
426 | displayError(response.message); |
||
427 | } |
||
428 | } |
||
429 | ); |
||
430 | }); |
||
431 | |||
432 | |||
433 | $('#saveOperation').click(function () { |
||
434 | $.post( |
||
435 | "/examples/Metrica/api.php", |
||
436 | { |
||
437 | method: 'updateOperation', |
||
438 | counterId: <?= $counterId ?>, |
||
439 | operationId: operationId |
||
440 | }, |
||
441 | function (data) { |
||
442 | |||
443 | $('#updateOperationModal').modal('hide'); |
||
444 | |||
445 | var response = JSON.parse(data); |
||
446 | if (response.status === 'ok' && response.result !== null) { |
||
447 | |||
448 | var html = '\ |
||
449 | <tr data-operation-id="' + response.result.id + '">\ |
||
450 | <td>' + response.result.id + '</td>\ |
||
451 | <td>' + response.result.action + '</td>\ |
||
452 | <td>' + response.result.attr + '</td>\ |
||
453 | <td>' + response.result.value + '</td>\ |
||
454 | <td>' + response.result.status + '</td>\ |
||
455 | <td style="text-align: center">\ |
||
456 | <button type="button" class="btn btn-info showOperation">\ |
||
457 | <span title="Открыть" class="glyphicon glyphicon-eye-open"></span>\ |
||
458 | </button>\ |
||
459 | <button type="button" class="btn btn-warning updateOperation">\ |
||
460 | <span title="Изменить" class="glyphicon glyphicon-edit"></span>\ |
||
461 | </button>\ |
||
462 | <button type="button" class="btn btn-danger deleteOperation">\ |
||
463 | <span title="Удалить" class="glyphicon glyphicon-trash"></span>\ |
||
464 | </button>\ |
||
465 | </td>\ |
||
466 | </tr>'; |
||
467 | |||
468 | $operationsTable.find('tbody>tr').each(function () { |
||
469 | if ($(this).data('counter-id') == response.result.id) { |
||
470 | $(this).replaceWith(html); |
||
471 | } |
||
472 | }); |
||
473 | |||
474 | } else { |
||
475 | displayError(response.message); |
||
476 | } |
||
477 | } |
||
478 | ); |
||
479 | }); |
||
480 | |||
481 | |||
482 | $('#deleteOperation').click(function () { |
||
483 | |||
484 | var operationId = $.trim($('#deleteOperationId').val()); |
||
485 | $.post( |
||
486 | "/examples/Metrica/api.php", |
||
487 | { |
||
488 | method: 'deleteOperation', |
||
489 | counterId: <?= $counterId ?>, |
||
490 | operationId: operationId |
||
491 | }, |
||
492 | function (data) { |
||
493 | |||
494 | $('#deleteOperationModal').modal('hide'); |
||
495 | |||
496 | var response = JSON.parse(data); |
||
497 | if (response.status === 'ok' && response.result !== null) { |
||
498 | |||
499 | $operationsTable.find('tbody>tr').each(function () { |
||
500 | if ($(this).data('operation-id') == response.result.id) { |
||
501 | $(this).replaceWith(''); |
||
502 | } |
||
503 | }); |
||
504 | |||
505 | } else { |
||
506 | displayError(response.message); |
||
507 | } |
||
508 | } |
||
509 | ); |
||
510 | }); |
||
511 | |||
512 | }); |
||
513 | |||
514 | |||
515 | /** |
||
516 | * @param message string |
||
517 | */ |
||
518 | function displayError(message) { |
||
519 | $('#errorMessage').text(message); |
||
520 | $('#errorModal').modal('show'); |
||
521 | } |
||
522 | |||
523 | </script> |
||
524 | </body> |
||
525 | </html> |
||
526 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.