public static function authenticate($username, $password) { if (!empty($username) && ($authSource = AuthUserTable::getAuthSource($username))) { Console::debug("Found authentication source {$authSource} for {$username}"); $driverList = array(AuthDriverManager::getDriver($authSource)); } else { // avoid issues with session collision when many users connect from // the same computer at the same time with the same browser session ! if (AuthUserTable::userExists($username)) { self::setFailureMessage(get_lang("There is already an account with this username.")); return false; } $authSource = null; $driverList = AuthDriverManager::getRegisteredDrivers(); } foreach ($driverList as $driver) { $driver->setAuthenticationParams($username, $password); if ($driver->authenticate()) { $uid = AuthUserTable::registered($username, $driver->getAuthSource()); if ($uid) { if ($driver->userUpdateAllowed()) { $userAttrList = $driver->getFilteredUserData(); if (isset($userAttrList['loginName'])) { $newUserName = $userAttrList['loginName']; if (!get_conf('claro_authUsernameCaseSensitive', true)) { $newUsername = strtolower($newUserName); $username = strtolower($username); } // avoid session collisions ! if ($username != $newUserName) { Console::error("EXTAUTH ERROR : try to overwrite an existing user {$username} with another one" . var_export($userAttrList, true)); } else { AuthUserTable::updateUser($uid, $userAttrList); Console::info("EXTAUTH INFO : update user {$uid} {$username} with " . var_export($userAttrList, true)); } } else { Console::error("EXTAUTH ERROR : no loginName given for user {$username} by authSource " . $driver->getAuthSource()); } } return Claro_CurrentUser::getInstance($uid, true); } elseif ($driver->userRegistrationAllowed()) { // duplicate code here to avoid issue with multiple requests on a busy server ! if (AuthUserTable::userExists($username)) { self::setFailureMessage(get_lang("There is already an account with this username.")); return false; } $uid = AuthUserTable::createUser($driver->getUserData()); return Claro_CurrentUser::getInstance($uid, true); } } elseif ($authSource) { self::setFailureMessage($driver->getFailureMessage()); } } // authentication failed return false; }
private function getTopicName($topicId, $courseId) { $tbl = get_module_course_tbl(array('bb_topics'), $courseId); $sql = "SELECT `topic_title`\n" . "FROM `{$tbl['bb_topics']}`\n" . "WHERE `topic_id`=" . Claroline::getDatabase()->escape($topicId); $res = Claroline::getDatabase()->query($sql); $res->setFetchMode(Database_ResultSet::FETCH_VALUE); $title = $res->fetch(); if ($title) { $title = trim($title); if (empty($title)) { $title = get_lang('Untitled'); } return $title; } else { Console::debug("Cannot load topic " . var_export($topicId, true) . " in " . __CLASS__ . " : query returned " . var_export($title, true)); return null; } }
/** * Run the garbage collector */ public function run() { if (is_dir($this->path)) { // control that path is not in a system folder if (strpos($this->path, get_path('coursesRepositorySys')) !== false) { Console::warning("GC directory {$this->path} located in platform course folder : ABORT!"); return; } if (strpos($this->path, get_path('clarolineRepositorySys')) !== false) { Console::warning("GC directory {$this->path} located in platform main folder : ABORT!"); return; } if (strpos($this->path, get_path('rootSys') . '/web') !== false) { Console::warning("GC directory {$this->path} located in platform web folder : ABORT!"); return; } if (strpos($this->path, get_path('rootSys') . '/module') !== false) { Console::warning("GC directory {$this->path} located in platform modules dir : ABORT!"); return; } Console::debug('GC Called in ' . $this->path); // Delete archive files older than one hour $directoryIterator = new RecursiveDirectoryIterator($this->path); //$directoryIterator->setFlags(FilesystemIterator::SKIP_DOTS); $tempDirectoryFiles = new RecursiveIteratorIterator($directoryIterator); foreach ($tempDirectoryFiles as $tempDirectoryFile) { if ($tempDirectoryFile->isReadable() && $tempDirectoryFile->isWritable()) { if ($tempDirectoryFile->getMTime() < $this->expire) { if (!$tempDirectoryFile->isDir()) { Console::debug('Unlink ' . $tempDirectoryFile->getPathName() . " mtime: " . $tempDirectoryFile->getMTime() . "; expire: " . $this->expire); @unlink($tempDirectoryFile->getPathName()); } elseif ($tempDirectoryFile->isDir() && $this->isEmpty($tempDirectoryFile->getPathName())) { Console::debug('Rmdir ' . $tempDirectoryFile->getPathName() . " mtime: " . $tempDirectoryFile->getMTime() . "; expire: " . $this->expire); @rmdir($tempDirectoryFile->getPathName()); } } } } } else { Console::warning("GC directory {$this->path} is not a folder folder : ABORT!"); } }
public function getResourceName(ResourceLocator $locator) { if (!$locator->hasResourceId()) { return false; } $tbl = get_module_course_tbl(array('calendar_event'), $locator->getCourseId()); $sql = "SELECT `titre`,`day`\n" . "FROM `{$tbl['calendar_event']}`\n" . "WHERE `id`=" . Claroline::getDatabase()->escape($locator->getResourceId()); $res = Claroline::getDatabase()->query($sql); $res->setFetchMode(Database_ResultSet::FETCH_OBJECT); $event = $res->fetch(); if ($event) { $titre = trim($event->titre); if (empty($titre)) { $titre = $event->day; } return $titre; } else { Console::debug("Cannot load ressource " . var_export($locator, true) . " in " . __CLASS__ . " : query returned " . var_export($event, true)); return null; } }
public function getResourceName(ResourceLocator $locator) { if (!$locator->hasResourceId()) { return false; } $tbl = get_module_course_tbl(array('announcement'), $locator->getCourseId()); $sql = "SELECT `title`\n" . "FROM `{$tbl['announcement']}`\n" . "WHERE `id`=" . Claroline::getDatabase()->escape($locator->getResourceId()); $res = Claroline::getDatabase()->query($sql); $res->setFetchMode(Database_ResultSet::FETCH_VALUE); $title = $res->fetch(); if ($title) { $title = trim($title); if (empty($title)) { $title = get_lang('Untitled'); } return $title; } else { Console::debug("Cannot load ressource " . var_export($locator, true) . " in " . __CLASS__ . " : query returned " . var_export($title, true)); return null; } }
private static function getValidSteps() { $holder = sfContext::getInstance()->getUser()->getAttributeHolder(); $path = $holder->get('path', null, self::$SESSION_NS); if ($path === null) { throw new afValidationException("No wizard was started yet!"); } $module = sfContext::getInstance()->getModuleName(); $action = sfContext::getInstance()->getActionName(); $updateAction = "{$module}/{$action}"; $steps = $holder->get('steps', array(), self::$SESSION_NS); if (count($steps) >= count($path)) { Console::debug('extra updateAction:', $updateAction, 'steps:', $steps, 'path:', $path); throw new afValidationException('The wizard is already finished!'); } $steps = self::getStepsTo($steps, $updateAction); for ($i = 0, $len = count($steps); $i < $len; $i++) { if ($steps[$i] !== $path[$i]) { Console::debug('wrong steps:', $steps, 'path:', $path); throw new afValidationException('It is not possible to skip a wizard step.'); } } return $steps; }
/** * @brief Static signal handler * * @param type $signal */ public function signal($signal) { echo "\n"; Console::debug("Caught signal %d", $signal); if ($signal === SIGINT || $signal === SIGTERM) { exit; } }
/** * starts the thread, all the parameters are * passed to the callback function * * @return void */ public function start() { $pid = @pcntl_fork(); if ($pid == -1) { throw new Exception($this->getError(Thread::COULD_NOT_FORK), Thread::COULD_NOT_FORK); } if ($pid) { // parent $this->pid = $pid; Console::debug("Thread forked with pid %d", $pid); return $pid; } else { // child $this->runnable->pid = posix_getpid(); pcntl_signal(SIGTERM, array(&$this, 'signalHandler')); exit(call_user_func(array(&$this->runnable, 'threadmain'))); } }
public function release() { if (!function_exists('shm_has_var')) { throw new BaseException("No mutex support on this platform"); } $this->enterCriticalSection(); Console::debug("Destroying mutex %s", $this->_lockname); $ls = shm_get_var(Mutex::$resource, Mutex::SHM_LOCKS); unset($ls[$this->_lockname]); shm_put_var(Mutex::$resource, Mutex::SHM_LOCKS, $ls); $this->_lockstate = false; $this->exitCriticalSection(); }
/** * @deprecated called automatically by kernel * @return string */ public function render() { Console::debug(__CLASS__ . '::' . __FUNCTION__ . " is deprecated"); return ''; }
function getThumbnail($imgPath, $newHeight, $newWidth) { $thumbName = md5($imgPath) . '_' . $newWidth . 'x' . $newHeight . '.jpg'; $thumbPath = $this->thumbnailDirectory . '/' . $thumbName; if (file_exists($thumbPath) && filectime($this->documentRootDir . '/' . $imgPath) < filectime($thumbPath) && filemtime($this->documentRootDir . '/' . $imgPath) < filemtime($thumbPath)) { return $thumbPath; } else { if (claro_debug_mode()) { Console::debug("Regenerating thumbnail for {$imgPath}"); } return $this->createThumbnail($imgPath, $newHeight, $newWidth); } }
function __destruct() { Console::debug("Deleting window with handle %xd", $this->_wh); ncurses_delwin($this->_wh); }
public function render() { $claro_buffer = new ClaroBuffer(); $claro_buffer->append("\n" . '<!-- ' . $this->name . ' -->' . "\n"); foreach ($this->appletList as $applet) { set_current_module_label($applet['label']); pushClaroMessage('Current module label set to : ' . get_current_module_label(), 'debug'); // install course applet if (claro_is_in_a_course()) { install_module_in_course($applet['label'], claro_get_current_course_id()); } if ($applet['activation'] == 'activated' && file_exists($applet['path'])) { load_module_config(); Language::load_module_translation(); if ($this->useList() && count($this->appletList) > 0) { $claro_buffer->append("<li\n id=\"dock-" . $this->name . "-applet-" . $applet['label'] . "\"\n class=\"applet dock-" . $this->name . " applet-" . $applet['label'] . "\"><span>\n"); } else { $claro_buffer->append("<span\n id=\"dock-" . $this->name . "-applet-" . $applet['label'] . "\"\n class=\"applet dock-" . $this->name . " applet-" . $applet['label'] . "\">\n"); } include_once $applet['path']; if ($this->useList() && count($this->appletList) > 0) { $claro_buffer->append("\n</span></li>\n"); } else { $claro_buffer->append("\n</span>\n"); } } else { Console::debug("Applet not found or not activated : " . $applet['label']); } clear_current_module_label(); pushClaroMessage('Current module label set to : ' . get_current_module_label(), 'debug'); } $claro_buffer->append("\n" . '<!-- End of ' . $this->name . ' -->' . "\n"); return $claro_buffer->getContent(); }
/** * notify occurence of an event to the event manager. Usage : * - EventManager::notify( $event ); * - EventManager::notify( $eventType, $args ); * @access public * @param string event type of occured event, or event object * @param array args optional event arguments (only if event type given * as first argument) * @static */ public static function notify($event, $args = null) { if (claro_debug_mode()) { Console::debug(__CLASS__ . "::notify " . $event->getEventType()); } if (is_string($event)) { // $event is an event type $event = new Event($event, $args); } $mngr = EventManager::getInstance(); return $mngr->eventOccurs($event); }
<?php require_once '_cmd.php'; define('GALLERY_NAME', 'test'); $gallery = ORM::factory('gallery')->where('name', GALLERY_NAME)->find(); if ($gallery->id == 0) { Console::debug('No gallery named ' . GALLERY_NAME . ' found'); exit; } Console::debug('Clearing Gallery: ' . $gallery->name); foreach ($gallery->images() as $image) { Console::debug('Deleting Image: ' . $image->name); $image->delete(); }