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.
1 | <?php |
||
2 | |||
3 | namespace Slackbot001; |
||
4 | |||
5 | use Illuminate\Support\Facades\Log; |
||
6 | |||
7 | class CP_TDauth |
||
8 | { |
||
9 | protected $auth = ''; |
||
10 | protected $expires = ''; |
||
11 | protected $BEID = ''; |
||
12 | protected $WebServicesKey = ''; |
||
13 | protected $urlroot = ''; |
||
14 | protected $appsroot = ''; |
||
15 | protected $appid = ''; |
||
16 | protected $authstring = ''; |
||
17 | protected $authsig = ''; |
||
18 | protected $header = ''; |
||
19 | |||
20 | public function __construct() |
||
21 | { |
||
22 | $args = func_get_args(); |
||
23 | $argcount = func_num_args(); |
||
24 | if (method_exists($this, $func = '__construct'.$argcount)) { |
||
25 | call_user_func_array([$this, $func], $args); |
||
26 | } |
||
27 | } |
||
28 | |||
29 | public function __construct0() |
||
30 | { |
||
31 | Log::info('CP_TDauth: Constructing empty self.'); |
||
32 | } |
||
33 | |||
34 | public function __construct5($beid, $wskey, $urlroot, $appid, $env) |
||
35 | { |
||
36 | Log::info('CP_TDauth: Constructing self with new authorization.'); |
||
37 | $this->setEnv($env, $urlroot); |
||
38 | $this->authorize($beid, $wskey, $this->urlroot); |
||
39 | $this->BEID = $beid; |
||
40 | $this->WebServicesKey = $wskey; |
||
41 | $this->appid = $appid; |
||
42 | } |
||
43 | |||
44 | public function __construct6($beid, $wskey, $urlroot, $appid, $env, $auth) |
||
45 | { |
||
46 | Log::info('CP_TDauth: Constructing self with existing authorization.'); |
||
47 | $this->setEnv($env, $urlroot); |
||
48 | $this->BEID = $beid; |
||
49 | $this->WebServicesKey = $wskey; |
||
50 | $this->appid = $appid; |
||
51 | |||
52 | $parts = explode('.', $auth); |
||
53 | if (count($parts) == 3) { |
||
54 | list($JWTheader, $JWTpayload, $JWTsig) = $parts; |
||
55 | $this->auth = $auth; |
||
56 | $this->expires = json_decode(base64_decode($JWTpayload))->exp; |
||
57 | $this->authstring = 'Authorization: Bearer '.$this->auth; |
||
58 | $this->header = $JWTheader; |
||
59 | $this->authsig = $JWTsig; |
||
60 | |||
61 | return; |
||
62 | } |
||
63 | Log::info('CP_TDauth: Invalid token.'); |
||
64 | } |
||
65 | |||
66 | private function setEnv($env, $urlroot) |
||
67 | { |
||
68 | if ($env == 'prod') { |
||
69 | Log::info('CP_TDauth: Setup for production.'); |
||
70 | $this->urlroot = $urlroot.'TDWebApi/api/'; |
||
71 | $this->appsroot = $urlroot.'TDNext/Apps/'; |
||
72 | } elseif ($env == 'sandbox') { |
||
73 | Log::info('CP_TDauth: Setup for sandbox.'); |
||
74 | $this->urlroot = $urlroot.'SBTDWebApi/api/'; |
||
75 | $this->appsroot = $urlroot.'SBTDNext/Apps/'; |
||
76 | } |
||
77 | } |
||
78 | |||
79 | private function authorize($beid, $wskey, $urlroot) |
||
80 | { |
||
81 | Log::info('CP_TDauth: authorize method called.'); |
||
82 | Log::info('CP_TDauth: authorize requesting at ['.$urlroot.'auth/loginadmin].'); |
||
83 | $ch = curl_init($urlroot.'auth/loginadmin'); |
||
84 | $payload = json_encode(['BEID' => $beid, 'WebServicesKey' => $wskey]); |
||
85 | curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); |
||
86 | curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type:application/json']); |
||
87 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||
88 | $bearer = curl_exec($ch); |
||
89 | curl_close($ch); |
||
90 | if (!$bearer) { |
||
91 | Log::info('CP_TDauth: Authorization failed.'); |
||
92 | |||
93 | return; |
||
94 | } |
||
95 | Log::info('CP_TDauth: Authorization successful.'); |
||
96 | list($JWTheader, $JWTpayload, $JWTsig) = explode('.', $bearer); |
||
97 | $this->auth = $bearer; |
||
98 | $this->expires = json_decode(base64_decode($JWTpayload))->exp; |
||
99 | $this->authstring = 'Authorization: Bearer '.$this->auth; |
||
100 | $this->header = $JWTheader; |
||
101 | $this->authsig = $JWTsig; |
||
102 | } |
||
103 | |||
104 | public function checkToken() |
||
105 | { |
||
106 | Log::info('CP_TDauth: checkToken method called.'); |
||
107 | if ($this->authstring) { |
||
108 | if (($this->expires - time()) <= 10) { |
||
109 | $this->authorize($this->BEID, $this->WebServicesKey, $this->urlroot); |
||
110 | Log::info('CP_TDauth: Token was expired. Replaced with new token.'); |
||
111 | } else { |
||
112 | $remain = $this->expires - time(); |
||
113 | Log::info('CP_TDauth: Token ok, time remaining: '.$remain); |
||
114 | } |
||
115 | |||
116 | return true; |
||
117 | } else { |
||
118 | Log::info('CP_TDauth: No token.'); |
||
119 | |||
120 | return false; |
||
121 | } |
||
122 | } |
||
123 | |||
124 | public function __toString() |
||
125 | { |
||
126 | Log::info('CP_TDauth: __toString method called.'); |
||
127 | $this->checkToken(); |
||
128 | Log::info('CP_TDauth: returning JWT.'); |
||
129 | |||
130 | return $this->auth; |
||
131 | } |
||
132 | |||
133 | public function getVersion() |
||
134 | { |
||
135 | Log::info('CP_TDauth: getVersion method called.'); |
||
136 | |||
137 | return '0.1.9'; |
||
138 | } |
||
139 | } |
||
140 | |||
141 | class CP_TDinstance extends CP_TDauth |
||
142 | { |
||
143 | private function connect($type, $point, $data) |
||
144 | { |
||
145 | Log::info('CP_TDinstance: connect method called.'); |
||
146 | $this->checkToken(); |
||
147 | $ch = curl_init($this->urlroot.$point); |
||
148 | curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type:application/json', $this->authstring]); |
||
149 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||
150 | if ($type == 'post') { |
||
151 | Log::info('CP_TDinstance: connect method POST.'); |
||
152 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); |
||
153 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
||
154 | } else { |
||
155 | Log::info('CP_TDinstance: connect method GET.'); |
||
156 | } |
||
157 | $result = curl_exec($ch); |
||
158 | |||
159 | return json_decode($result, true); |
||
160 | } |
||
161 | |||
162 | private function flagCheck($search) |
||
163 | { |
||
164 | Log::info('CP_TDinstance: flagCheck method called.'); |
||
165 | $check = substr($search, -3); |
||
166 | if (substr($check, 1, 1) == '-') { |
||
167 | $flag = substr($check, 1, 2); |
||
168 | Log::info('CP_TDinstance: flagCheck given flag '.$flag); |
||
169 | |||
170 | return $flag; |
||
171 | } else { |
||
172 | return; |
||
173 | } |
||
174 | } |
||
175 | |||
176 | public function ticket($ticketno) |
||
177 | { |
||
178 | Log::info('CP_TDinstance: ticket method called.'); |
||
179 | $ticket = $this->connect('get', $this->appid.'/tickets/'.$ticketno, ''); |
||
180 | |||
181 | return $ticket; |
||
182 | } |
||
183 | |||
184 | public function searchTicketsName($search) |
||
185 | { |
||
186 | Log::info('CP_TDinstance: searchTicketsName method called.'); |
||
187 | $flag = $this->flagCheck($search); |
||
188 | |||
189 | if (!$flag) { |
||
0 ignored issues
–
show
|
|||
190 | $people = $this->searchPeople($search); |
||
191 | foreach ($people as $person) { |
||
192 | $uids[] = $person['UID']; |
||
193 | } |
||
194 | if (isset($uids)) { |
||
195 | $tickets = $this->searchResponsibility($uids); |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
196 | |||
197 | return $tickets; |
||
198 | } else { |
||
199 | return; |
||
200 | } |
||
201 | } else { |
||
202 | if ($flag == '-r') { |
||
203 | $data = ['RequestorNameSearch' => substr($search, 0, -3)]; |
||
204 | $data_string = json_encode($data); |
||
205 | $tickets = $this->connect('post', $this->appid.'/tickets/search', $data_string); |
||
206 | |||
207 | return $tickets; |
||
208 | } |
||
209 | } |
||
210 | } |
||
211 | |||
212 | View Code Duplication | public function searchPeople($search) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||
213 | { |
||
214 | Log::info('CP_TDinstance: searchPeople method called.'); |
||
215 | $data = ['SearchText' => $search]; |
||
216 | $data_string = json_encode($data); |
||
217 | $people = $this->connect('post', 'people/search', $data_string); |
||
218 | |||
219 | return $people; |
||
220 | } |
||
221 | |||
222 | View Code Duplication | public function searchAssets($search) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||
223 | { |
||
224 | Log::info('CP_TDinstance: searchAssets method called.'); |
||
225 | $ticketids = [(int) $search]; |
||
226 | $data = ['TicketIDs' => $ticketids]; |
||
227 | $data_string = json_encode($data); |
||
228 | $assets = $this->connect('post', 'assets/search', $data_string); |
||
229 | |||
230 | return $assets; |
||
231 | } |
||
232 | |||
233 | public function searchResponsibility($search) |
||
234 | { |
||
235 | Log::info('CP_TDinstance: searchResponsibility method called.'); |
||
236 | if (!is_array($search)) { |
||
237 | $search = [(string) $search]; |
||
238 | } |
||
239 | $ResponsibilityUids = $search; |
||
240 | $data = ['ResponsibilityUids' => $ResponsibilityUids]; |
||
241 | $data_string = json_encode($data); |
||
242 | $tickets = $this->connect('post', '/tickets/search', $data_string); |
||
243 | |||
244 | return $tickets; |
||
245 | } |
||
246 | |||
247 | public function rootAppsUrl() |
||
248 | { |
||
249 | Log::info('CP_TDinstance: rootAppsUrl method called.'); |
||
250 | |||
251 | return $this->appsroot.$this->appid.'/'; |
||
252 | } |
||
253 | } |
||
254 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: