badoo /
liveprof-ui
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 declare(strict_types=1); |
||
| 2 | |||
| 3 | ini_set('display_errors', '0'); |
||
| 4 | |||
| 5 | $vendor_path = __DIR__ . '/../../vendor/autoload.php'; |
||
| 6 | $use_as_library_vendor_path = __DIR__ . '/../../../../../vendor/autoload.php'; |
||
| 7 | if (file_exists($vendor_path)) { |
||
| 8 | require_once $vendor_path; |
||
| 9 | } elseif (file_exists($use_as_library_vendor_path)) { |
||
| 10 | require_once $use_as_library_vendor_path; |
||
| 11 | } |
||
| 12 | |||
| 13 | $App = new \Badoo\LiveProfilerUI\LiveProfilerUI(); |
||
| 14 | $Logger = $App->getLogger(); |
||
| 15 | |||
| 16 | switch (getCurrentUri()) { |
||
| 17 | case '/profiler/list-view.phtml': |
||
| 18 | $data = [ |
||
| 19 | 'app' => isset($_GET['app']) ? trim($_GET['app']) : '', |
||
| 20 | 'label' => isset($_GET['label']) ? trim($_GET['label']) : '', |
||
| 21 | 'snapshot_id' => isset($_GET['snapshot_id']) ? (int)$_GET['snapshot_id'] : '', |
||
| 22 | 'all' => isset($_GET['all']) ? trim($_GET['all']) : '', |
||
| 23 | ]; |
||
| 24 | $Page = $App->getPage('profile_method_list_page'); |
||
| 25 | echo $Page->setData($data)->render(); |
||
| 26 | break; |
||
| 27 | |||
| 28 | case '/profiler/tree-view.phtml': |
||
| 29 | $data = [ |
||
| 30 | 'app' => isset($_GET['app']) ? trim($_GET['app']) : '', |
||
| 31 | 'label' => isset($_GET['label']) ? trim($_GET['label']) : '', |
||
| 32 | 'snapshot_id' => isset($_GET['snapshot_id']) ? (int)$_GET['snapshot_id'] : '', |
||
| 33 | 'method_id' => isset($_GET['method_id']) ? (int)$_GET['method_id'] : 0, |
||
| 34 | 'method_name' => isset($_GET['method_name']) ? trim($_GET['method_name']) : '', |
||
| 35 | 'stat_interval' => isset($_GET['stat_interval']) ? (int)$_GET['stat_interval'] : '', |
||
| 36 | 'date1' => isset($_GET['date1']) ? trim($_GET['date1']) : '', |
||
| 37 | 'date2' => isset($_GET['date2']) ? trim($_GET['date2']) : '', |
||
| 38 | ]; |
||
| 39 | $Page = $App->getPage('profile_method_tree_page'); |
||
| 40 | echo $Page->setData($data)->render(); |
||
| 41 | break; |
||
| 42 | |||
| 43 | case '/profiler/result-flamegraph.phtml': |
||
| 44 | $data = [ |
||
| 45 | 'app' => isset($_GET['app']) ? trim($_GET['app']) : '', |
||
| 46 | 'label' => isset($_GET['label']) ? trim($_GET['label']) : '', |
||
| 47 | 'snapshot_id' => isset($_GET['snapshot_id']) ? (int)$_GET['snapshot_id'] : '', |
||
| 48 | 'param' => isset($_GET['param']) ? trim($_GET['param']) : '', |
||
| 49 | 'diff' => isset($_GET['diff']) ? trim($_GET['diff']) : '', |
||
| 50 | 'date' => isset($_GET['date']) ? trim($_GET['date']) : '', |
||
| 51 | 'date1' => isset($_GET['date1']) ? trim($_GET['date1']) : '', |
||
| 52 | 'date2' => isset($_GET['date2']) ? trim($_GET['date2']) : '', |
||
| 53 | ]; |
||
| 54 | $Page = $App->getPage('flame_graph_page'); |
||
| 55 | echo $Page->setData($data)->render(); |
||
| 56 | break; |
||
| 57 | |||
| 58 | case '/profiler/result-diff.phtml': |
||
| 59 | $data = [ |
||
| 60 | 'app' => isset($_GET['app']) ? trim($_GET['app']) : '', |
||
| 61 | 'label' => isset($_GET['label']) ? trim($_GET['label']) : '', |
||
| 62 | 'date1' => isset($_GET['date1']) ? trim($_GET['date1']) : '', |
||
| 63 | 'date2' => isset($_GET['date2']) ? trim($_GET['date2']) : '', |
||
| 64 | 'param' => isset($_GET['param']) ? trim($_GET['param']) : '', |
||
| 65 | ]; |
||
| 66 | $Page = $App->getPage('snapshots_diff_page'); |
||
| 67 | echo $Page->setData($data)->render(); |
||
| 68 | break; |
||
| 69 | |||
| 70 | case '/profiler/method-usage.phtml': |
||
| 71 | $data = [ |
||
| 72 | 'method' => isset($_GET['method']) ? trim($_GET['method']) : '' |
||
| 73 | ]; |
||
| 74 | $Page = $App->getPage('method_usage_page'); |
||
| 75 | echo $Page->setData($data)->render(); |
||
| 76 | break; |
||
| 77 | |||
| 78 | case '/profiler/top-diff.phtml': |
||
| 79 | $data = [ |
||
| 80 | 'date1' => isset($_GET['date1']) ? trim($_GET['date1']) : date('Y-m-d', strtotime('-3 months')), |
||
| 81 | 'date2' => isset($_GET['date2']) ? trim($_GET['date2']) : date('Y-m-d', strtotime('-1 day')), |
||
| 82 | 'param' => isset($_GET['param']) ? trim($_GET['param']) : '', |
||
| 83 | 'mode' => isset($_GET['mode']) ? trim($_GET['mode']) : 'snapshots', |
||
| 84 | ]; |
||
| 85 | $Page = $App->getPage('top_diff_page'); |
||
| 86 | echo $Page->setData($data)->render(); |
||
| 87 | break; |
||
| 88 | |||
| 89 | case '/profiler/rebuild-snapshot.json': |
||
| 90 | $app = isset($_POST['app']) ? trim($_POST['app']) : ''; |
||
| 91 | $label = isset($_POST['label']) ? trim($_POST['label']) : ''; |
||
| 92 | $date = isset($_POST['date']) ? trim($_POST['date']) : date('Y-m-d'); |
||
| 93 | header('Content-Type: application/json;charset=UTF-8'); |
||
| 94 | |||
| 95 | /** @var \Badoo\LiveProfilerUI\Pages\AjaxPages $Page */ |
||
| 96 | $Page = $App->getPage('ajax_pages'); |
||
| 97 | echo json_encode($Page->rebuildSnapshot($app, $label, $date)); |
||
| 98 | break; |
||
| 99 | |||
| 100 | case '/profiler/check-snapshot.json': |
||
| 101 | $app = isset($_POST['app']) ? trim($_POST['app']) : ''; |
||
| 102 | $label = isset($_POST['label']) ? trim($_POST['label']) : ''; |
||
| 103 | $date = isset($_POST['date']) ? trim($_POST['date']) : date('Y-m-d'); |
||
| 104 | header('Content-Type: application/json;charset=UTF-8'); |
||
| 105 | |||
| 106 | /** @var \Badoo\LiveProfilerUI\Pages\AjaxPages $Page */ |
||
| 107 | $Page = $App->getPage('ajax_pages'); |
||
| 108 | echo json_encode($Page->checkSnapshot($app, $label, $date)); |
||
| 109 | break; |
||
| 110 | |||
| 111 | case '/profiler/search-method.json': |
||
| 112 | $term = isset($_POST['term']) ? trim($_POST['term']) : ''; |
||
| 113 | header('Content-Type: application/json;charset=UTF-8'); |
||
| 114 | |||
| 115 | /** @var \Badoo\LiveProfilerUI\Pages\AjaxPages $Page */ |
||
| 116 | $Page = $App->getPage('ajax_pages'); |
||
| 117 | $methods = $Page->searchMethods($term); |
||
| 118 | |||
| 119 | $result = []; |
||
| 120 | foreach ($methods as $method_id => $method) { |
||
| 121 | $result[] = [ |
||
| 122 | 'label' => $method['name'] . ' - ' . $method['date'], |
||
| 123 | 'value' => $method['name'], |
||
| 124 | ]; |
||
| 125 | } |
||
| 126 | |||
| 127 | echo json_encode($result); |
||
| 128 | break; |
||
| 129 | |||
| 130 | case '/profiler/method-used-apps.json': |
||
| 131 | $method = isset($_GET['method']) ? trim($_GET['method']) : ''; |
||
| 132 | header('Content-Type: application/json;charset=UTF-8'); |
||
| 133 | |||
| 134 | /** @var \Badoo\LiveProfilerUI\Pages\AjaxPages $Page */ |
||
| 135 | $Page = $App->getPage('ajax_pages'); |
||
| 136 | $method_data = $Page->getMethodUsedApps($method); |
||
| 137 | |||
| 138 | $result = []; |
||
| 139 | if ($method_data) { |
||
|
0 ignored issues
–
show
|
|||
| 140 | foreach ($method_data as $item) { |
||
| 141 | if (empty($item['fields']) || empty($item['fields']['calls_count'])) { |
||
| 142 | continue; |
||
| 143 | } |
||
| 144 | |||
| 145 | $item['cpu'] = $item['fields']['cpu'] / 1000; |
||
| 146 | $item['ct'] = $item['fields']['ct']; |
||
| 147 | $item['calls_count'] = (int)$item['fields']['calls_count']; |
||
| 148 | unset($item['fields']); |
||
| 149 | // Keep 1 app with maximum cpu |
||
| 150 | if (isset($result[$item['app']]) && $result[$item['app']]['cpu'] > $item['cpu']) { |
||
| 151 | continue; |
||
| 152 | } |
||
| 153 | $result[$item['app']] = $item; |
||
| 154 | } |
||
| 155 | |||
| 156 | uasort( |
||
| 157 | $result, |
||
| 158 | static function ($a, $b) { |
||
| 159 | return $b['cpu'] <=> $a['cpu']; |
||
| 160 | } |
||
| 161 | ); |
||
| 162 | |||
| 163 | $result = array_values($result); |
||
| 164 | } |
||
| 165 | |||
| 166 | echo json_encode($result); |
||
| 167 | break; |
||
| 168 | |||
| 169 | case '/profiler/all-methods.json': |
||
| 170 | header('Content-Type: application/json;charset=UTF-8'); |
||
| 171 | |||
| 172 | /** @var \Badoo\LiveProfilerUI\Pages\AjaxPages $Page */ |
||
| 173 | $Page = $App->getPage('ajax_pages'); |
||
| 174 | |||
| 175 | echo json_encode($Page->allMethods()); |
||
| 176 | break; |
||
| 177 | |||
| 178 | case '/profiler/get-source-app-list.json': |
||
| 179 | header('Content-Type: application/json;charset=UTF-8'); |
||
| 180 | |||
| 181 | /** @var \Badoo\LiveProfilerUI\Pages\AjaxPages $Page */ |
||
| 182 | $Page = $App->getPage('ajax_pages'); |
||
| 183 | echo json_encode($Page->getSourceAppList()); |
||
| 184 | break; |
||
| 185 | |||
| 186 | case '/profiler/get-source-label-list.json': |
||
| 187 | header('Content-Type: application/json;charset=UTF-8'); |
||
| 188 | |||
| 189 | /** @var \Badoo\LiveProfilerUI\Pages\AjaxPages $Page */ |
||
| 190 | $Page = $App->getPage('ajax_pages'); |
||
| 191 | echo json_encode($Page->getSourceLabelList()); |
||
| 192 | break; |
||
| 193 | |||
| 194 | case '/profiler/result-list.phtml': |
||
| 195 | default: |
||
| 196 | $data = [ |
||
| 197 | 'app' => isset($_GET['app']) ? trim($_GET['app']) : '', |
||
| 198 | 'label' => isset($_GET['label']) ? trim($_GET['label']) : '', |
||
| 199 | 'date' => isset($_GET['date']) ? trim($_GET['date']) : '', |
||
| 200 | ]; |
||
| 201 | $Page = $App->getPage('profile_list_page'); |
||
| 202 | echo $Page->setData($data)->render(); |
||
| 203 | } |
||
| 204 | |||
| 205 | function getCurrentUri() : string |
||
| 206 | { |
||
| 207 | return parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); |
||
| 208 | } |
||
| 209 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.