array(__CLASS__, 'sanitize')) ); } /** * Sanitize the submitted settings. * * @param array $input Raw submitted values. * @return array */ public static function sanitize($input) { $input = is_array($input) ? $input : array(); $current = of_sso_get_settings(); $output = array(); $textKeys = array('platform', 'client_id', 'default_role'); foreach ($textKeys as $key) { $output[$key] = isset($input[$key]) ? sanitize_text_field($input[$key]) : ''; } $urlKeys = array('base_url', 'redirect_uri', 'redirect_after_login'); foreach ($urlKeys as $key) { $output[$key] = isset($input[$key]) ? esc_url_raw(trim($input[$key])) : ''; } // Paths are kept as-is apart from trimming: they point outside the web root on purpose. $pathKeys = array('cert_dir', 'auth_cert', 'auth_key', 'sign_cert', 'sign_key', 'ca_cert', 'server_sign_cert'); foreach ($pathKeys as $key) { $output[$key] = isset($input[$key]) ? trim(wp_strip_all_tags($input[$key])) : ''; } $boolKeys = array('send_x_ssl_cert', 'auto_create', 'show_login_button', 'debug'); foreach ($boolKeys as $key) { $output[$key] = empty($input[$key]) ? 0 : 1; } // An empty secret field means "keep the stored value", so a secret is never wiped by accident. foreach (array('client_secret', 'key_passphrase') as $key) { $submitted = isset($input[$key]) ? trim($input[$key]) : ''; $output[$key] = ($submitted === '') ? $current[$key] : $submitted; } if (empty($output['base_url'])) { $output['base_url'] = 'https://openflyers.com'; } return $output; } /** * Render the settings page. * * @return void */ public static function renderPage() { if (!current_user_can('manage_options')) { return; } $settings = of_sso_get_settings(); $verdict = self::handleConnectionTest(); ?>

Configuration de l\'API) :', 'openflyers-sso'); ?>

, ', array_map('esc_html', of_sso_cert_file_names())); ?>

'unknown', 'detail' => __('Jeton de securite invalide, merci de recharger la page.', 'openflyers-sso')); } $client = of_sso_get_client(); if (!$client) { return array('status' => 'unknown', 'detail' => __('Renseignez au moins le code plateforme et le client_id.', 'openflyers-sso')); } return $client->testConnection(of_sso_get_redirect_uri()); } /** * Render the connection test button and the verdict of the last run. * * @param array|null $verdict Verdict returned by handleConnectionTest(). * @return void */ private static function renderConnectionTest($verdict) { if (is_array($verdict)) { // Every status but 'ok' names the exact link in the chain that refused the call. $messages = array( 'ok' => array('success', __('Connexion a OpenFlyers reussie. Le certificat TLS, la signature et les identifiants du client sont acceptes : un membre peut se connecter.', 'openflyers-sso')), 'network' => array('error', __('Le serveur OpenFlyers n\'a pas pu etre contacte. Verifiez que l\'hebergeur autorise les connexions sortantes avec un certificat client, et que la cle privee est lisible par PHP.', 'openflyers-sso')), 'server_ca' => array('error', __('Le certificat du serveur OpenFlyers n\'a pas pu etre verifie avec le fichier ca.crt fourni. Ce fichier sert a valider le serveur, pas votre client : s\'il ne convient pas, retirez ca.crt du dossier des certificats pour utiliser le magasin d\'autorites du systeme.', 'openflyers-sso')), 'tls' => array('error', __('Le certificat TLS a ete refuse. Il ne correspond pas a celui enregistre dans OpenFlyers. Si les fichiers sont les bons, votre hebergeur termine sans doute le TLS sur un proxy : activez l\'option X-SSL-CERT.', 'openflyers-sso')), 'signature' => array('error', __('La signature HTTP a ete refusee. Verifiez la cle de signature, et surtout que l\'horloge du serveur est a l\'heure (NTP).', 'openflyers-sso')), 'client' => array('error', __('Le client_id ou la passphrase sont incorrects.', 'openflyers-sso')), 'grant_type' => array('error', __('Ce client n\'est pas declare avec le type d\'autorisation authorization_code dans OpenFlyers.', 'openflyers-sso')), 'unknown' => array('warning', __('Reponse inattendue d\'OpenFlyers.', 'openflyers-sso')), ); $status = isset($messages[$verdict['status']]) ? $verdict['status'] : 'unknown'; list($noticeType, $text) = $messages[$status]; printf( '

%s

%s
', esc_attr($noticeType), esc_html($text), empty($verdict['detail']) ? '' : '

' . esc_html($verdict['detail']) . '

' ); } ?>

__('Certificat TLS mutuel', 'openflyers-sso'), 'auth_key' => __('Cle privee TLS mutuel', 'openflyers-sso'), 'sign_cert' => __('Certificat de signature HTTP', 'openflyers-sso'), 'sign_key' => __('Cle privee de signature HTTP', 'openflyers-sso'), 'ca_cert' => __('Autorite de certification', 'openflyers-sso'), 'server_sign_cert' => __('Certificat de signature du serveur', 'openflyers-sso'), ); // The folder setting and the per-file overrides both land here. $paths = of_sso_resolve_cert_paths($settings); foreach ($files as $key => $label) { $path = $paths[$key]; $comment = ''; if (!empty($path) and is_readable($path) and substr($key, -4) === 'cert') { $parsed = openssl_x509_parse((string) file_get_contents($path)); if (!empty($parsed['validTo_time_t'])) { $comment = sprintf( /* translators: %s: certificate expiry date. */ __('Expire le %s', 'openflyers-sso'), date_i18n(get_option('date_format'), $parsed['validTo_time_t']) ); } } // ca.crt only overrides the bundle used to validate the OpenFlyers server; without it // the system store applies, which is what most hosts want. if ($key === 'ca_cert' and empty($path)) { $checks[] = array( $label, true, __('Absent : le magasin d\'autorites du systeme sera utilise.', 'openflyers-sso'), ); continue; } if (empty($path)) { $comment = __('Aucun chemin : renseignez le dossier des certificats.', 'openflyers-sso'); } elseif (!is_readable($path)) { $comment = sprintf( /* translators: %s: expected file path. */ __('Introuvable ou illisible : %s', 'openflyers-sso'), $path ); } $checks[] = array($label, !empty($path) && is_readable($path), $comment); } // A certificate paired with the wrong key fails at handshake time with an obscure error. $pairs = array( 'auth' => array('auth_cert', 'auth_key', __('Le certificat TLS et sa cle correspondent', 'openflyers-sso')), 'sign' => array('sign_cert', 'sign_key', __('Le certificat de signature et sa cle correspondent', 'openflyers-sso')), ); foreach ($pairs as $pair) { list($certKey, $keyKey, $label) = $pair; if (empty($paths[$certKey]) or empty($paths[$keyKey]) or !is_readable($paths[$certKey]) or !is_readable($paths[$keyKey]) ) { continue; } $privateKey = empty($settings['key_passphrase']) ? openssl_get_privatekey((string) file_get_contents($paths[$keyKey])) : openssl_get_privatekey((string) file_get_contents($paths[$keyKey]), $settings['key_passphrase']); $matches = $privateKey ? openssl_x509_check_private_key((string) file_get_contents($paths[$certKey]), $privateKey) : false; $checks[] = array( $label, $matches, $matches ? '' : __('La cle ne correspond pas au certificat, ou la passphrase est incorrecte.', 'openflyers-sso'), ); } // A private key readable by anyone on a shared host is the main risk of this setup. // Skipped on Windows, where fileperms() says nothing about the actual ACL. foreach (array('auth_key', 'sign_key') as $key) { if (DIRECTORY_SEPARATOR === '\\') { break; } if (!empty($paths[$key]) and is_readable($paths[$key])) { $perms = substr(sprintf('%o', fileperms($paths[$key])), -3); $checks[] = array( sprintf( /* translators: %s: setting label. */ __('Permissions de %s', 'openflyers-sso'), $key ), in_array($perms, array('600', '400'), true), sprintf( /* translators: %s: octal file permissions. */ __('Actuellement %s, attendu 600.', 'openflyers-sso'), $perms ), ); } } echo ''; foreach ($checks as $check) { list($label, $ok, $comment) = $check; printf( '', esc_html($label), $ok ? '✓' : '✗', esc_html($comment) ); } echo '
%s%s%s
'; } /** * Render a text input row. * * @param string $key Setting key. * @param string $label Field label. * @param string $value Current value. * @param string $placeholder Placeholder text. * @return void */ private static function textRow($key, $label, $value, $placeholder) { printf( '' . '', esc_attr($key), esc_html($label), esc_attr(OF_SSO_OPTION), esc_attr($value), esc_attr($placeholder) ); } /** * Render a full-width note under the previous field. * * @param string $text Help text. * @return void */ private static function descriptionRow($text) { printf('

%s

', esc_html($text)); } /** * Render a write-only secret row. * * @param string $key Setting key. * @param string $label Field label. * @param string $value Current value. * @return void */ private static function secretRow($key, $label, $value) { printf( '' . '' . '

%4$s

', esc_attr($key), esc_html($label), esc_attr(OF_SSO_OPTION), empty($value) ? esc_html__('Non renseigne.', 'openflyers-sso') : esc_html__('Deja enregistre. Laisser vide pour conserver la valeur actuelle.', 'openflyers-sso') ); } /** * Render a checkbox row. * * @param string $key Setting key. * @param string $label Field label. * @param int $value Current value. * @param string $description Help text. * @return void */ private static function checkboxRow($key, $label, $value, $description) { printf( '%2$s' . '

%5$s

', esc_attr($key), esc_html($label), esc_attr(OF_SSO_OPTION), checked(1, (int) $value, false), esc_html($description) ); } /** * Render the role selector. * * @param string $key Setting key. * @param string $label Field label. * @param string $value Current value. * @return void */ private static function roleRow($key, $label, $value) { printf( ''; } /** * Display the OpenFlyers identifier on the user profile screen. * * @param WP_User $user User being edited. * @return void */ public static function renderUserField($user) { if (!current_user_can('edit_users') and get_current_user_id() !== $user->ID) { return; } $value = get_user_meta($user->ID, OF_SSO_USER_META, true); $editable = current_user_can('edit_users'); ?>