l10n('Force HTTPS'), 'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/admin.php'), )); return $menu; } /** * plugin initialization * - check for upgrades * - unserialize configuration * - load language */ function piwigo_force_https_init() { global $conf, $pwg_loaded_plugins; // apply upgrade if needed if ( FORCE_HTTPS_VERSION == 'auto' or $pwg_loaded_plugins[FORCE_HTTPS_ID]['version'] == 'auto' or version_compare($pwg_loaded_plugins[FORCE_HTTPS_ID]['version'], FORCE_HTTPS_VERSION, '<') ) { // call install function include_once(FORCE_HTTPS_PATH . 'maintain.inc.php'); plugin_install(); // update plugin version in database if ( $pwg_loaded_plugins[FORCE_HTTPS_ID]['version'] != 'auto' and FORCE_HTTPS_VERSION != 'auto' ) { $query = ' UPDATE '. PLUGINS_TABLE .' SET version = "'. FORCE_HTTPS_VERSION .'" WHERE id = "'. FORCE_HTTPS_ID .'"'; pwg_query($query); $pwg_loaded_plugins[FORCE_HTTPS_ID]['version'] = FORCE_HTTPS_VERSION; if (defined('IN_ADMIN')) { $_SESSION['page_infos'][] = 'Force https updated to version '. FORCE_HTTPS_VERSION; } } } } /** * Http connections control * - function completes http header based on configuration settings */ function piwigo_force_https_header() { global $conf; // Force https connection $use_https = isset($conf['fhp_use_https']) ? piwigo_force_https_strbool($conf['fhp_use_https']) : 'false'; $use_sts = isset($conf['fhp_use_sts']) ? piwigo_force_https_strbool($conf['fhp_use_sts']) : 'false'; // Activates STS security if ($use_https == 'true') { if ($use_sts == 'true' && isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { header('Strict-Transport-Security: max-age=500'); } elseif (!isset($_SERVER['HTTPS'])) { header('Status-Code: 301'); header('Location: https://'.$_SERVER["HTTP_HOST"].$_SERVER['REQUEST_URI']); } } } function piwigo_force_https_strbool($value) { return $value ? 'true' : 'false'; } ?>