** Function: checkUserWebAuth ** used by server->on functions to discern whether a user has the correct ** httpapitoken OR is authenticated by username and password **********************************************************************/
| 168 | ** httpapitoken OR is authenticated by username and password |
| 169 | **********************************************************************/ |
| 170 | bool checkUserWebAuth(AsyncWebServerRequest *request, bool onFailureReturnLoginPage = false) { |
| 171 | if (request->hasHeader("Cookie")) { |
| 172 | const AsyncWebHeader *cookie = request->getHeader("Cookie"); |
| 173 | String c = cookie->value(); |
| 174 | int idx = c.indexOf("BRUCESESSION="); |
| 175 | if (idx != -1) { |
| 176 | int start = idx + 13; |
| 177 | int end = c.indexOf(';', start); |
| 178 | if (end == -1) end = c.length(); |
| 179 | String token = c.substring(start, end); |
| 180 | if (bruceConfig.isValidWebUISession(token)) { return true; } |
| 181 | } |
| 182 | } |
| 183 | if (onFailureReturnLoginPage) { |
| 184 | serveWebUIFile(request, "login.html", "text/html", true, login_html, login_html_size); |
| 185 | } else { |
| 186 | request->send(401, "text/plain", "Unauthorized"); |
| 187 | } |
| 188 | return false; |
| 189 | } |
| 190 | |
| 191 | /********************************************************************** |
| 192 | ** Function: createDirRecursive |
no test coverage detected