Not found

'; exit; }; try { switch ($route) { case 'home': $titleKey = 'nav_home'; require dirname(__DIR__) . '/views/home.php'; break; case 'frm-library': $frms = PersonRepository::frmWithNoms(); $docs = PersonRepository::publicDocuments(); $titleKey = 'frm_title'; require dirname(__DIR__) . '/views/frm_library.php'; break; case 'lookup': $error = null; /** @var string|null */ $lookupErrorDetail = null; /** @var array{passport:string,ticket_id:string,status:string,posicion:?int}|null */ $lookupPending = null; $result = null; $penasquitoApiOk = PenasquitoDc3Api::isConfigured(); $envTok = getenv('CERTIMINE_PENASQUITO_TOKEN'); if (!is_string($envTok) || trim($envTok) === '') { $envTok = getenv('CERTIMINE_DC3_TOKEN'); } $penasquitoApiTokenFromEnv = is_string($envTok) && trim($envTok) !== ''; $lookupUsingExample = !Config::loadedFromLocalFile(); $penasquitoApiBaseUrl = (string) (Config::get('penasquito_dc3', 'base_url') ?? ''); if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!Security::verifyCsrf($_POST['_csrf'] ?? null)) { $error = I18n::t('csrf_invalid'); } else { $type = (string) ($_POST['person_type'] ?? 'employee'); $code = trim((string) ($_POST['code'] ?? '')); if (!in_array($type, ['employee', 'contractor'], true)) { $type = 'employee'; } if ($code === '') { $error = I18n::t('no_results'); } else { $result = PersonRepository::findByEmployeeNumberAndType($code, $type); if ($result === null) { $result = PersonRepository::findByEmployeeNumber($code); } if ($result !== null) { PersonRepository::logAudit('lookup', (string) $result['person_type'], $code); $ptype = (string) $result['person_type']; $ecode = (string) ($result['employee_number'] ?? $result['mobiliseme_id']); $sig = Security::qrSignature($ptype, $ecode); header( 'Location: ' . Util::url('profile', [ 'id' => $result['mobiliseme_id'], 'sig' => $sig, ]) ); exit; } if (PenasquitoDc3Api::isConfigured()) { try { $apiRes = PenasquitoDc3Api::fetchResultForPassport($code); $isContractor = PenasquitoDc3Api::guessContractorFromCompanyPublic( (string) ($apiRes['company'] ?? '') ); $ptype = $type === 'contractor' || $isContractor ? 'contractor' : 'employee'; $pid = (string) ($apiRes['passport'] ?? $code); PenasquitoDc3Api::persistResult($pid, $apiRes, $ptype); PersonRepository::logAudit('lookup_penasquito_api', $ptype, $code); $ecode = (string) ($apiRes['passport'] ?? $code); $sig = Security::qrSignature($ptype, $ecode); header( 'Location: ' . Util::url('profile', [ 'id' => $pid, 'sig' => $sig, ]) ); exit; } catch (PenasquitoPendingException $pex) { $lookupPending = [ 'passport' => $pex->passport, 'ticket_id' => $pex->ticketId, 'status' => $pex->remoteStatus, 'posicion' => $pex->posicion, ]; } catch (Throwable $ex) { $error = I18n::t('penasquito_api_lookup_error'); if ($ex instanceof \RuntimeException) { $lookupErrorDetail = $ex->getMessage(); } elseif (Config::debugMode()) { $lookupErrorDetail = $ex->getMessage(); } } } else { $error = I18n::t('lookup_need_dc3'); } } } } $titleKey = 'lookup_title'; require dirname(__DIR__) . '/views/lookup.php'; break; case 'profile': $id = (string) ($_GET['id'] ?? ''); $sig = isset($_GET['sig']) ? (string) $_GET['sig'] : null; if ($id === '') { $e('missing id'); } $row = PersonRepository::findByMobilisemeId($id); if ($row === null) { $e('unknown'); } $code = (string) ($row['employee_number'] ?? $row['mobiliseme_id']); $ptype = (string) $row['person_type']; if (!Security::verifyQrSignature($ptype, $code, $sig)) { http_response_code(403); echo '

Invalid signature

'; exit; } $certs = PersonRepository::certificates($id); $auths = $ptype === 'contractor' ? PersonRepository::authorizations($id) : []; $green = (int) ($row['green_license_flag'] ?? 0) === 1; $qrUrl = Util::url('profile', ['id' => $id, 'sig' => Security::qrSignature($ptype, $code)]); $titleKey = $ptype === 'contractor' ? 'contractor_profile' : 'employee_profile'; require dirname(__DIR__) . '/views/profile_public.php'; break; case 'login': $err = null; if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!Security::verifyCsrf($_POST['_csrf'] ?? null)) { $err = I18n::t('csrf_invalid'); } else { $u = (string) ($_POST['username'] ?? ''); $p = (string) ($_POST['password'] ?? ''); try { $login = MobilisemeClient::login($u, $p); /** @var array|null $dr */ $dr = isset($login['dc3_result']) && is_array($login['dc3_result']) ? $login['dc3_result'] : null; Auth::login($login['profile'], $login['token'], $dr); header('Location: ' . Util::url('dashboard')); exit; } catch (Throwable) { $err = I18n::t('login_error'); } } } $titleKey = 'login_title'; require dirname(__DIR__) . '/views/login.php'; break; case 'logout': Auth::logout(); header('Location: ' . Util::url('home')); exit; case 'dashboard': $user = Auth::requireUser(); $mid = (string) $user['mobiliseme_id']; $certs = PersonRepository::certificates($mid); $nomIds = PersonRepository::validNomIdsForPerson($mid); $courses = PersonRepository::coursesForNoms($nomIds); $titleKey = 'nav_dashboard'; require dirname(__DIR__) . '/views/dashboard.php'; break; case 'api-docs': header('Content-Type: text/plain; charset=utf-8'); $doc = dirname(__DIR__) . '/docs/mobiliseme-api.md'; if (is_readable($doc)) { readfile($doc); } else { echo "Documentation not found.\n"; } exit; default: $e('route'); } } catch (Throwable $ex) { http_response_code(500); echo '

Server error

'; if (getenv('CERTIMINE_DEBUG') === '1') { echo '
' . Util::h($ex->getMessage()) . '
'; } }