public function __destruct() { try { Session::getObject()->update(); } catch (QueryException $e) { Database::getObject()->getDebug()->add($e); throw $e; } parent::__destruct(); }
// +-------------------------------------------------------------------+ /** * @package WiFiDogAuthServer * @author Francois Proulx <*****@*****.**> * @copyright 2005-2006 Francois Proulx, Technologies Coeus inc. * @version Subversion $Id: hotspots.php 1337 2008-03-20 18:07:28Z benoitg $ * @link http://www.wifidog.org/ */ /** * Load required files */ require_once '../../include/common.php'; require_once 'classes/MainUI.php'; require_once 'classes/Content/PatternLanguage/PatternLanguage.php'; $smarty = SmartyWifidog::getObject(); $session = Session::getObject(); // This trick is done to allow displaying of Pattern Language right away if there is only one available. if (!empty($_REQUEST['content_id'])) { $content_id = $_REQUEST['content_id']; $pattern_language = PatternLanguage::getObject($content_id); } else { $content_id = ""; $pattern_languages = PatternLanguage::getAllContent(); if (count($pattern_languages) >= 1) { $pattern_language = $pattern_languages[0]; } else { exit; } } // The Pattern Language toolbar $tool_html = "<h1>{$pattern_language->getTitle()->__toString()}</h1>";
/** Initialise the system locale (gettext, setlocale, etc.) * @return boolean true on success, false on failure. */ public static function setCurrentLocale($locale) { $session = Session::getObject(); $AVAIL_LOCALE_ARRAY = LocaleList::getAvailableLanguageArray(); $retval = false; // Get new locale ID, assume default if null if ($locale != null) { $locale_id = $locale->getId(); $retval = true; $q = "parameter"; } else { $locale_id = DEFAULT_LANG; $retval = false; $q = "default"; } //pretty_print_r($locale); //echo sprintf("Debug in /classes/Locale.php setCurentLocale(): locale_id=%s", $locale_id)."<br/>"; if (GETTEXT_AVAILABLE) { $lang_only_locale_id = substr($locale_id, 0, 2); if (!isset($AVAIL_LOCALE_ARRAY[$locale_id]) && !isset($AVAIL_LOCALE_ARRAY[$lang_only_locale_id])) { echo sprintf("Warning in /classes/Locale.php setCurrentLocale: Neither %s or %s are available in AVAIL_LOCALE_ARRAY", $locale_id, $lang_only_locale_id) . "<br/>"; } // Try to set locale $candidate_locale_array[] = str_ireplace('.UTF8', '', $locale_id) . '.UTF-8'; $candidate_locale_array[] = str_ireplace('.UTF8', '', $locale_id); $candidate_locale_array[] = $lang_only_locale_id . '.UTF-8'; $candidate_locale_array[] = $lang_only_locale_id; $current_locale = setlocale(LC_ALL, $candidate_locale_array); //echo sprintf("Warning in /classes/Locale.php setCurentLocale: Unable to setlocale() to %s: %s. I tried %s, %s, %s, %s, and got return value: %s, current locale is: %s",$q, $locale_id, $candidate_locale_array[0], $candidate_locale_array[1], $candidate_locale_array[2], $candidate_locale_array[3], $current_locale, setlocale(LC_ALL, 0))."<br/>"; // Test it against current PHP locale if (substr($current_locale, 0, 2) != $lang_only_locale_id) { echo sprintf("Warning in /classes/Locale.php setCurrentLocale: Unable to setlocale() to %s: %s. I tried %s, %s, %s, %s, and got return value: %s, current locale is: %s", $q, $locale_id, $candidate_locale_array[0], $candidate_locale_array[1], $candidate_locale_array[2], $candidate_locale_array[3], $current_locale, setlocale(LC_ALL, 0)) . "<br/>"; $retval = false; } else { bindtextdomain('messages', WIFIDOG_ABS_FILE_PATH . 'locale'); bind_textdomain_codeset('messages', 'UTF-8'); textDomain('messages'); putenv("LC_ALL=" . $current_locale); putenv("LANGUAGE=" . $current_locale); $retval = true; } } return $retval; }
public function logout() { $this->breadcrumb->add('Abmelden'); $this->header(); if (!Me::get()->loggedIn()) { CmsPage::error('Sie sind bereits abgelemdet!'); } else { Session::getObject()->close(); CmsPage::ok('Sie haben sich erfolgreich abgemeldet!', URI::frontPage()); } $this->footer(); }
/** Set Smarty template values. Standardization routine. */ public static function assignSmartyValues($smarty, $user = null) { if (!$user) { $user = User::getCurrentUser(); } $session = Session::getObject(); $smarty->assign('userOriginallyRequestedURL', $session ? $session->get(SESS_ORIGINAL_URL_VAR) : ''); $smarty->assign('userId', $user ? $user->getId() : ''); $smarty->assign('userName', $user ? $user->getUsername() : ''); /** * Define user security levels for the template * * These values are used in the default template of WiFoDog but could be * used in a customized template to restrict certain links to specific * user access levels. Note however that they will all be deprecateb by the * new roles system. */ $smarty->assign('userIsValid', $user && !$user->isSplashOnlyUser() ? true : false); $smarty->assign('userDEPRECATEDisSuperAdmin', $user && $user->DEPRECATEDisSuperAdmin()); if (isset($_REQUEST['debug_request']) && ($user && $user->DEPRECATEDisSuperAdmin())) { // Tell Smarty everything it needs to know $smarty->assign('debugRequested', true); $smarty->assign('debugOutput', print_r($_REQUEST, true)); } }
/** Get the actual report. * Classes can (but don't have to) override this, but must call the parent's method with what * would otherwise be their return value and return that instead. * @param $statistics_object Mandatory to give the report it's context * @param $child_html The child method's return value * @return A html fragment */ public function getReportUI(Statistics $statistics_object, $child_html = null) { $session = Session::getObject(); $session->set('current_statistics_object', $statistics_object); self::$stats = $statistics_object; /* Update it in case someone whants to use it right now */ $html = ''; $html .= "<fieldset>"; $html .= "<legend>" . $this->getGraphName() . "</legend>"; $errormsg = ''; if ($this->isAvailable($errormsg)) { $html .= "<div><img src='stats_show_graph.php?graph_class=" . get_class($this) . "'></div>"; } else { $html .= $errormsg; } $html .= $child_html; $html .= "</fieldset>"; return $html; }
/** * Get the content to be displayed in the tool pane * * @return string HTML markup * * @access private */ private function getToolContent() { $session = Session::getObject(); $AVAIL_LOCALE_ARRAY = LocaleList::getAvailableLanguageArray(); // Init values $html = ""; $_gwId = null; $_gwAddress = null; $_gwPort = null; $_mac = null; $_selected = ""; $_languageChooser = array(); // Init ALL smarty SWITCH values $this->smarty->assign('sectionSTART', false); $this->smarty->assign('sectionLOGIN', false); // Set section of Smarty template $this->smarty->assign('sectionSTART', true); // Get information about user $_currentUser = User::getCurrentUser(); $_currentUser ? $this->smarty->assign('userListUI', $_currentUser->getListUI()) : $this->smarty->assign('userListUI', ""); $this->smarty->assign('logoutParameters', ""); $this->smarty->assign('loginParameters', ""); $this->smarty->assign('formAction', ""); $this->smarty->assign('toolContent', ""); $this->smarty->assign('accountInformation', ""); $this->smarty->assign('techSupportInformation', ""); $this->smarty->assign('shrinkLeftArea', $this->_shrinkLeftArea); /* * Provide Smarty information about the user's login/logout status */ if ($_currentUser != null) { // User is logged in // Detect gateway information $_gwId = $session->get(SESS_GW_ID_VAR); $_gwAddress = $session->get(SESS_GW_ADDRESS_VAR); $_gwPort = $session->get(SESS_GW_PORT_VAR); $_mac = $session->get(SESS_USER_MAC_VAR); // If gateway information could be detected tell them to Smarty if ($_gwId && $_gwAddress && $_gwPort) { $this->smarty->assign('logoutParameters', "&gw_id=" . $_gwId . "&gw_address=" . $_gwAddress . "&gw_port=" . $_gwPort . ($_mac ? "&mac=" . $_mac : "")); } } else { } /* * Provide Smarty information for the language chooser */ // Assign the action URL for the form $this->smarty->assign('formAction', htmlspecialchars($_SERVER['REQUEST_URI'])); foreach ($AVAIL_LOCALE_ARRAY as $_langIds => $_langNames) { if (Locale::getCurrentLocale()->getId() == $_langIds) { $_selected = ' selected="selected"'; } else { $_selected = ""; } $langName = "{$_langNames[0]}"; $_languageChooser[] = '<option value="' . $_langIds . '"' . $_selected . '>' . $langName . '</option>'; } // Provide Smarty all available languages $this->smarty->assign('languageChooser', $_languageChooser); // Compile HTML code $html = $this->smarty->fetch("templates/classes/MainUI_ToolContent.tpl"); return $html; }
public function write($onlyCreate = false, $tpl = null) { $id = Request::get(1, VAR_INT); $isSent = Request::get(2, VAR_URI) == 'send'; $data = new CustomData($this->position); if ($id > 0 && $onlyCreate && Session::getObject()->getSetting('last_added') != $id) { CmsPage::error('Die Bearbeitungszeit ist abgelaufen. Bitte wenden Sie sich an den Administrator.'); } else { if ($id > 0 && !$data->load($id)) { CmsPage::error('Der gewählte Datensatz wurde leider nicht gefunden.'); } else { if ($id == 0) { $data->setToDefault(); } $fields = $data->getFields(); if ($isSent) { $options = array(); foreach ($fields as $field) { if ($field->canWrite()) { if ($field->getField() instanceof CustomExternalFields) { $options = array_merge($options, $field->getValidation()); } else { $options[$field->getFieldName()] = $field->getValidation(); } } } $result = Validator::checkRequest($options); foreach ($fields as $field) { if ($field->canWrite()) { $name = $field->getFieldName(); if (isset($result['data'][$name])) { $field->setData($result['data'][$name]); } } } if (count($result['error']) > 0) { CmsPage::error($result['error']); } else { $success = false; if ($id > 0) { $success = $data->edit($id); } else { $id = $data->add(); if ($onlyCreate) { Session::getObject()->setSetting('last_added', $id); } if ($id > 0) { $success = true; } else { $id = 0; $success = false; } } if ($success) { CmsPage::ok("Der Datensatz wurde erfolgreich gespeichert."); } else { CmsPage::error("Der Datensatz konnt leider nicht gespeichert werden."); } } } $html = array(); foreach ($fields as $field) { if ($field->canWrite()) { $html[] = array('field' => Sanitize::saveHTML($field->getFieldName()), 'name' => Sanitize::saveHTML($field->getName()), 'description' => Sanitize::saveHTML($field->getDescription()), 'code' => $field->getInputCode(), 'label' => !$field->noLabel()); } } $tpl = Response::getObject()->appendTemplate($tpl ? $tpl : '/Cms/fields/data_categories_write'); $tpl->assign('data', $data, false); $tpl->assign('fields', $html, false); $tpl->assign('id', $id); $tpl->assign('baseUri', $this->baseUri); $tpl->output(); } } }
exit('<div style="color: #cc0000;">Error: The organization of the config.php could not be found in the database!</div>'); } // add the organization to the session $gPreferences = $gCurrentOrganization->getPreferences(); $gCurrentSession->addObject('gCurrentOrganization', $gCurrentOrganization); $gCurrentSession->setValue('ses_org_id', $gCurrentOrganization->getValue('org_id')); // create a language data object and assign it to the language object $gLanguageData = new LanguageData($gPreferences['system_language']); $gL10n->addLanguageData($gLanguageData); $gCurrentSession->addObject('gLanguageData', $gLanguageData); // delete old entries in session table $gCurrentSession->tableCleanup($gPreferences['logout_minutes']); } // now if auto login is done, read global user data if ($gCurrentSession->hasObject('gCurrentUser')) { $gProfileFields =& $gCurrentSession->getObject('gProfileFields'); $gCurrentUser =& $gCurrentSession->getObject('gCurrentUser'); $gCurrentUser->mProfileFieldsData->setDatabase($gDb); // checks if user in database session is the same as in php session if ($gCurrentUser->getValue('usr_id') !== $gCurrentSession->getValue('ses_usr_id')) { $gCurrentUser->clear(); $gCurrentSession->setValue('ses_usr_id', ''); } } else { // create object with current user field structure und user object $gProfileFields = new ProfileFields($gDb, $gCurrentOrganization->getValue('org_id')); $gCurrentUser = new User($gDb, $gProfileFields, $gCurrentSession->getValue('ses_usr_id')); // if session is created with auto login then update user login data // if user object is created and session has usr_id then this is an auto login // and we should update the login data and count logins if ($gCurrentSession->getValue('ses_usr_id') > 0) {
/** * Logs out the user * * @param string $conn_id The connection id for the connection to work on. * If it is not present, the behaviour depends if * the network supports multiple logins. If it does * not, all connections associated with the current * user will be destroyed. If it does, only the * connections tied to the current node will be * destroyed. * * @return void */ public function logout($conn_id = null) { $db = AbstractDb::getObject(); $session = Session::getObject(); $conn_id = $db->escapeString($conn_id); if (!empty($conn_id)) { $db->execSqlUniqueRes("SELECT CURRENT_TIMESTAMP, *, CASE WHEN ((CURRENT_TIMESTAMP - reg_date) > networks.validation_grace_time) THEN true ELSE false END AS validation_grace_time_expired FROM connections JOIN users ON (users.user_id=connections.user_id) JOIN networks ON (users.account_origin = networks.network_id) WHERE connections.conn_id='{$conn_id}'", $info, false); $user = User::getObject($info['user_id']); $network = $user->getNetwork(); $splash_user_id = $network->getSplashOnlyUser()->getId(); $this->acctStop($conn_id); } else { $user = User::getCurrentUser(); $network = $user->getNetwork(); $splash_user_id = $network->getSplashOnlyUser()->getId(); if ($splash_user_id != $user->getId() && ($node = Node::getCurrentNode())) { // Try to destroy all connections tied to the current node $sql = "SELECT conn_id FROM connections JOIN tokens USING (token_id) WHERE user_id = '{$user->getId()}' AND node_id='{$node->getId()}' AND token_status='" . TOKEN_INUSE . "';"; $conn_rows = null; $db->execSql($sql, $conn_rows, false); if ($conn_rows) { foreach ($conn_rows as $conn_row) { $this->acctStop($conn_row['conn_id']); } } } } if ($splash_user_id != $user->getId() && $network->getMultipleLoginAllowed() === false) { /* * The user isn't the splash_only user and the network config does * not allow multiple logins. Logging in with a new token implies * that all other active tokens should expire */ $sql = "SELECT conn_id FROM connections JOIN tokens USING (token_id) WHERE user_id = '{$user->getId()}' AND token_status='" . TOKEN_INUSE . "';"; $conn_rows = null; $db->execSql($sql, $conn_rows, false); if ($conn_rows) { foreach ($conn_rows as $conn_row) { $this->acctStop($conn_row['conn_id']); } } } // Try to destroy current session // TODO: This will not work if ultimately called from the gateway (ex: after abuse control was reached). This creates a UI problem (the portal still shows the user as connected) if (method_exists($session, "destroy")) { $session->destroy(); } }
public static function get() { return Session::getObject()->getMe(); }
/** * Retourne le language par défaut, selon les préférences de l'usager */ public static function GetDefault() { $session = Session::getObject(); if ($user = User::getCurrentUser()) { $locale = $user->getPreferedLocale(); } else { $locale = $session->get(SESS_LANGUAGE_VAR); if (empty($locale)) { $locale = DEFAULT_LANG; } } return $locale; }
/** * Packs email and sends it according to RFC822 * * @return bool True if email could be sent * * @access public */ public function send() { $dir = new DirectoryIterator('lib'); foreach ($dir as $fileinfo) { if ($fileinfo->isDir() && substr($fileinfo->getFilename(), 0, 9) == 'PHPMailer') { $phpmailerPath = 'lib/' . $fileinfo->getFilename() . '/'; } } require_once $phpmailerPath . 'class.phpmailer.php'; require_once $phpmailerPath . 'class.smtp.php'; require_once 'classes/Session.php'; $mail = new PHPMailer(); $session = Session::getObject(); $lang = substr($session->get(SESS_LANGUAGE_VAR), 0, 2); $mail->SetLanguage($lang, $phpmailerPath . 'language/'); $mail->CharSet = "utf-8"; # $mail->SMTPDebug=TRUE; $mail->Mailer = EMAIL_MAILER; if (EMAIL_MAILER == 'smtp') { $mail->IsSMTP(); $mail->Host = EMAIL_HOST; $mail->SMTPAuth = EMAIL_AUTH; if (EMAIL_AUTH) { $mail->Username = EMAIL_USERNAME; $mail->Password = EMAIL_PASSWORD; } } $mail->AddAddress($this->getRecipientEmail(), $this->getRecipientName()); $mail->From = $this->getSenderEmail(); $mail->FromName = $this->getSenderName(); $mail->Sender = $this->getSenderEmail(); // add Sender Name if ($this->getHighPriority()) { $mail->Priority = 1; } $mail->Subject = $this->getMessageSubject(); $mail->Body = $this->getMessageBody(); $result = $mail->Send(); if (!$result) { throw new exception(sprintf(_("PHPMailer couldn't sent mail. Error was: %s"), $mail->ErrorInfo)); } return $result; }
public function edit() { $id = Request::get(1, VAR_INT); $action = Request::get(2, VAR_URI); $this->breadcrumb->add('Bearbeiten'); $this->header(); $member = UserUtils::getById($id); if ($member === null) { CmsPage::error('Das angeforderte Mitglied wurde leider nicht gefunden.'); $this->members(); } else { $min_year = date('Y') - 110; $max_year = date('Y') - 8; $countries = CmsTools::getCountries(); $db = Database::getObject(); $db->query("SELECT id, title FROM <p>group WHERE registered = 1 ORDER BY admin ASC, editor ASC, title"); $groups = array(); while ($row = $db->fetchAssoc()) { $groups[$row['id']] = $row['title']; } $options = UserPages::getFieldValidation($countries, $min_year, $max_year); $options['pw1'][Validator::OPTIONAL] = true; $options['email'] = array(Validator::MULTIPLE => array(array(Validator::MESSAGE => 'Die E-Mail-Adresse ist nicht korrekt.', Validator::CALLBACK => Validator::CB_MAIL), array(Validator::MESSAGE => 'Diese E-Mail-Adresse ist bereits registriert.', Validator::CLOSURE => function ($mail) use($id) { $other = UserUtils::getByEmail($mail); return !($other !== null && $id != $other->getId()); }))); if (Me::get()->getId() != $id) { $options['group_id'] = array(Validator::MESSAGE => 'Die Gruppe ist nicht gültig.', Validator::LIST_CS => array_keys($groups)); $options['active'] = array(Validator::OPTIONAL => true, Validator::EQUALS => 1, Validator::VAR_TYPE => VAR_INT); } $error = array(); $data = array(); if ($action == 'send') { extract(Validator::checkRequest($options)); if (count($error) > 0) { CmsPage::error($error); } else { // Update data if (!empty($data['pw1']) && !empty($data['pw2'])) { $data['pw'] = Hash::generate($data['pw1']); } // prepare SQL update $sql = $data; unset($sql['pw1'], $sql['pw2'], $sql['birthday'], $sql['birthmonth'], $sql['birthyear']); if (Me::get()->getId() == $id) { unset($sql['group_id'], $sql['active']); // Don't allow to change own group or active state } $dt = new DT(); $dt->setDate($data['birthyear'], $data['birthmonth'], $data['birthday']); $sql['birth'] = $dt->dbDate(); $update = array(); foreach ($sql as $field => $value) { $update[] = "{$field} = <{$field}>"; } $update = implode(', ', $update); $sql['id'] = $id; $db->query("UPDATE <p>user SET {$update} WHERE id = <id:int>", $sql); // Update global data about me Session::getObject()->refreshMe(); CmsPage::ok("Ihre Angaben wurden erfolgreich gespeichert."); } } $user = $member->getArray(); $user = array_merge($user, $data); $tpl = Response::getObject()->appendTemplate("Cms/admin/members_edit"); $tpl->assign('user', $user); $tpl->assign('r_birthday', range(1, 31)); $tpl->assign('r_birthmonth', range(1, 12)); $tpl->assign('r_birthyear', range($min_year, $max_year)); $tpl->assign('countries', $countries); $tpl->assign('groups', $groups); $tpl->output(); } $this->footer(); }