From: <gem...@li...> - 2012-03-28 12:15:45
|
Revision: 570 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=570&view=rev Author: matijsdejong Date: 2012-03-28 12:15:34 +0000 (Wed, 28 Mar 2012) Log Message: ----------- Extra function for Https.php and some extra documentation Modified Paths: -------------- trunk/library/classes/Gems/Util.php trunk/library/classes/MUtil/Https.php trunk/library/configs/db/tables/gems__user_logins.10.sql Modified: trunk/library/classes/Gems/Util.php =================================================================== --- trunk/library/classes/Gems/Util.php 2012-03-28 09:36:53 UTC (rev 569) +++ trunk/library/classes/Gems/Util.php 2012-03-28 12:15:34 UTC (rev 570) @@ -161,23 +161,20 @@ return $this->_loadClass('lockFile', true, array(GEMS_ROOT_DIR . '/var/settings/cron_lock.txt')); } + /** + * Returns the current 'base site' url, optionally with a subpath. + * + * @staticvar string $uri + * @param string $subpath Optional string + * @return string The Url + basePath plus the optional subpath + */ public function getCurrentURI($subpath = '') { static $uri; if (! $uri) { - if(isset($_SERVER['HTTPS'])) { - $secure = $_SERVER["HTTPS"]; + $uri = MUtil_Https::on() ? 'https' : 'http'; - if (strtolower($secure) == 'off') { - $secure = false; - } - } else { - $secure = $_SERVER['SERVER_PORT'] == '443'; - } - - $uri = $secure ? 'https' : 'http'; - $uri .= '://'; $uri .= $_SERVER['SERVER_NAME']; $uri .= $this->basepath->getBasePath(); Modified: trunk/library/classes/MUtil/Https.php =================================================================== --- trunk/library/classes/MUtil/Https.php 2012-03-28 09:36:53 UTC (rev 569) +++ trunk/library/classes/MUtil/Https.php 2012-03-28 12:15:34 UTC (rev 570) @@ -1,44 +1,80 @@ <?php - -/** - * Copyright (c) 2011, Erasmus MC - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Erasmus MC nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - + /** - * @package MUtil + * Copyright (c) 2011, Erasmus MC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * @package MUtil + * @subpackage Https + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $id: Html.php 362 2011-12-15 17:21:17Z matijsdejong $ */ +/** + * Static utility function for determining wether https is on. + * + * @package MUtil + * @subpackage Https + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.0 + */ class MUtil_Https { + /** + * True when the url is a HTTPS url, false when HTTP, null otherwise + * + * @return boolean True when HTTPS, false when HTTP, null otherwise + */ + public static function isHttps($url) + { + $url = strtolower(substr($url, 0, 8)); + + if ('https://' == $url) { + return true; + } + + if ('http://' == substr($url, 0, 7)) { + return false; + } + return null; + } + + /** + * True when https is used. + * + * @return boolean + */ public static function on() { if (empty($_SERVER['HTTPS'])) { return false; } - return (($_SERVER['HTTPS'] !== 'off') || ($_SERVER['SERVER_PORT'] == 443)); + return ((strtolower($_SERVER['HTTPS']) !== 'off') || ($_SERVER['SERVER_PORT'] == 443)); } } \ No newline at end of file Modified: trunk/library/configs/db/tables/gems__user_logins.10.sql =================================================================== --- trunk/library/configs/db/tables/gems__user_logins.10.sql 2012-03-28 09:36:53 UTC (rev 569) +++ trunk/library/configs/db/tables/gems__user_logins.10.sql 2012-03-28 12:15:34 UTC (rev 570) @@ -21,3 +21,21 @@ ENGINE=InnoDB AUTO_INCREMENT = 10001 CHARACTER SET 'utf8' COLLATE 'utf8_general_ci'; + +/* +-- Code to restore login codes after failed update. You just never know when we might need it again. + +UPDATE gems__user_logins + SET gul_user_class = + CASE + WHEN EXISTS(SELECT gsf_id_user FROM gems__staff WHERE gsf_login = gul_login AND gsf_id_organization = gul_id_organization) THEN + CASE + WHEN EXISTS(SELECT gup_id_user FROM gems__user_passwords WHERE gup_id_user = gul_id_user) THEN 'StaffUser' + ELSE 'OldStaffUser' + END + WHEN EXISTS(SELECT gr2o_id_user FROM gems__respondent2org WHERE gr2o_patient_nr = gul_login AND gr2o_id_organization = gul_id_organization) THEN 'RespondentUser' + ELSE 'NoLogin' + END + WHERE gul_user_class = 'StaffUser'; + +*/ \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |