public static function getConfigSections($i18n) { $config_sections = array('general' => array(), self::CONFIGURATION_SECTION_MODULES => array()); if (TBGContext::getScope()->getID() == 1) { $config_sections['general'][self::CONFIGURATION_SECTION_SCOPES] = array('route' => 'configure_scopes', 'description' => $i18n->__('Scopes'), 'icon' => 'scopes', 'details' => $i18n->__('Scopes are self-contained Bug Genie environments. Configure them here.')); } $config_sections['general'][self::CONFIGURATION_SECTION_SETTINGS] = array('route' => 'configure_settings', 'description' => $i18n->__('Settings'), 'icon' => 'general_small', 'details' => $i18n->__('Every setting in the bug genie can be adjusted in this section.')); // $config_sections['general'][self::CONFIGURATION_SECTION_PERMISSIONS] = array('route' => 'configure_permissions', 'description' => $i18n->__('Permissions'), 'icon' => 'permissions', 'details' => $i18n->__('Configure permissions in this section')); $config_sections['general'][self::CONFIGURATION_SECTION_ROLES] = array('route' => 'configure_roles', 'description' => $i18n->__('Roles'), 'icon' => 'roles', 'details' => $i18n->__('Configure roles (permission templates) in this section')); $config_sections['general'][self::CONFIGURATION_SECTION_AUTHENTICATION] = array('route' => 'configure_authentication', 'description' => $i18n->__('Authentication'), 'icon' => 'authentication', 'details' => $i18n->__('Configure the authentication method in this section')); if (TBGContext::getScope()->isUploadsEnabled()) { $config_sections['general'][self::CONFIGURATION_SECTION_UPLOADS] = array('route' => 'configure_files', 'description' => $i18n->__('Uploads & attachments'), 'icon' => 'files', 'details' => $i18n->__('All settings related to file uploads are controlled from this section.')); } $config_sections['general'][self::CONFIGURATION_SECTION_IMPORT] = array('route' => 'configure_import', 'description' => $i18n->__('Import data'), 'icon' => 'import_small', 'details' => $i18n->__('Import data from CSV files and other sources.')); $config_sections['general'][self::CONFIGURATION_SECTION_PROJECTS] = array('route' => 'configure_projects', 'description' => $i18n->__('Projects'), 'icon' => 'projects', 'details' => $i18n->__('Set up all projects in this configuration section.')); $config_sections['general'][self::CONFIGURATION_SECTION_ISSUETYPES] = array('route' => 'configure_issuetypes', 'icon' => 'issuetypes', 'description' => $i18n->__('Issue types'), 'details' => $i18n->__('Manage issue types and configure issue fields for each issue type here')); $config_sections['general'][self::CONFIGURATION_SECTION_ISSUEFIELDS] = array('route' => 'configure_issuefields', 'icon' => 'resolutiontypes', 'description' => $i18n->__('Issue fields'), 'details' => $i18n->__('Status types, resolution types, categories, custom fields, etc. are configurable from this section.')); $config_sections['general'][self::CONFIGURATION_SECTION_WORKFLOW] = array('route' => 'configure_workflow', 'icon' => 'workflow', 'description' => $i18n->__('Workflow'), 'details' => $i18n->__('Set up and edit workflow configuration from this section')); $config_sections['general'][self::CONFIGURATION_SECTION_USERS] = array('route' => 'configure_users', 'description' => $i18n->__('Users, teams & clients'), 'icon' => 'users', 'details' => $i18n->__('Manage users, user teams and clients from this section.')); $config_sections[self::CONFIGURATION_SECTION_MODULES][] = array('route' => 'configure_modules', 'description' => $i18n->__('Module settings'), 'icon' => 'modules', 'details' => $i18n->__('Manage Bug Genie extensions from this section. New modules are installed from here.'), 'module' => 'core'); foreach (TBGContext::getModules() as $module) { if ($module->hasConfigSettings() && $module->isEnabled()) { $config_sections[self::CONFIGURATION_SECTION_MODULES][] = array('route' => array('configure_module', array('config_module' => $module->getName())), 'description' => TBGContext::geti18n()->__($module->getConfigTitle()), 'icon' => $module->getName(), 'details' => TBGContext::geti18n()->__($module->getConfigDescription()), 'module' => $module->getName()); } } return $config_sections; }
/** * Import all valid users * * @param TBGRequest $request */ public function runImportUsers(TBGRequest $request) { $validgroups = TBGContext::getModule('auth_ldap')->getSetting('groups'); $base_dn = TBGContext::getModule('auth_ldap')->getSetting('b_dn'); $dn_attr = TBGContext::getModule('auth_ldap')->getSetting('dn_attr'); $username_attr = TBGContext::getModule('auth_ldap')->getSetting('u_attr'); $fullname_attr = TBGContext::getModule('auth_ldap')->getSetting('f_attr'); $buddyname_attr = TBGContext::getModule('auth_ldap')->getSetting('b_attr'); $email_attr = TBGContext::getModule('auth_ldap')->getSetting('e_attr'); $groups_members_attr = TBGContext::getModule('auth_ldap')->getSetting('g_attr'); $user_class = TBGContext::getModule('auth_ldap')->getSetting('u_type'); $group_class = TBGContext::getModule('auth_ldap')->getSetting('g_type'); $users = array(); $importcount = 0; $updatecount = 0; try { /* * Connect and bind to the control user */ $connection = TBGContext::getModule('auth_ldap')->connect(); TBGContext::getModule('auth_ldap')->bind($connection, TBGContext::getModule('auth_ldap')->getSetting('control_user'), TBGContext::getModule('auth_ldap')->getSetting('control_pass')); /* * Get a list of all users of a certain objectClass */ $fields = array($fullname_attr, $buddyname_attr, $username_attr, $email_attr, 'cn', $dn_attr); $filter = '(objectClass=' . TBGLDAPAuthentication::getModule()->escape($user_class) . ')'; $results = ldap_search($connection, $base_dn, $filter, $fields); if (!$results) { TBGLogging::log('failed to search for users: ' . ldap_error($connection), 'ldap', TBGLogging::LEVEL_FATAL); throw new Exception(TBGContext::geti18n()->__('Search failed: ') . ldap_error($connection)); } $data = ldap_get_entries($connection, $results); /* * For every user that exists, process it. */ for ($i = 0; $i != $data['count']; $i++) { $user_dn = $data[$i][strtolower($dn_attr)][0]; /* * If groups are specified, perform group restriction tests */ if ($validgroups != '') { /* * We will repeat this for every group, but groups are supplied as a comma-separated list */ if (strstr($validgroups, ',')) { $groups = explode(',', $validgroups); } else { $groups = array(); $groups[] = $validgroups; } // Assumed we are initially banned $allowed = false; foreach ($groups as $group) { // No need to carry on looking if we have access if ($allowed == true) { continue; } /* * Find the group we are looking for, we search the entire directory * We want to find 1 group, if we don't get 1, silently ignore this group. */ $fields2 = array($groups_members_attr); $filter2 = '(&(cn=' . TBGLDAPAuthentication::getModule()->escape($group) . ')(objectClass=' . TBGLDAPAuthentication::getModule()->escape($group_class) . '))'; $results2 = ldap_search($connection, $base_dn, $filter2, $fields2); if (!$results2) { TBGLogging::log('failed to search for user: '******'ldap', TBGLogging::LEVEL_FATAL); throw new Exception(TBGContext::geti18n()->__('Search failed: ') . ldap_error($connection)); } $data2 = ldap_get_entries($connection, $results2); if ($data2['count'] != 1) { continue; } /* * Look through the group's member list. If we are found, grant access. */ foreach ($data2[0][strtolower($groups_members_attr)] as $member) { $member = preg_replace('/(?<=,) +(?=[a-zA-Z])/', '', $member); $user_dn = preg_replace('/(?<=,) +(?=[a-zA-Z])/', '', $user_dn); if (!is_numeric($member) && strtolower($member) == strtolower($user_dn)) { $allowed = true; } } } if ($allowed == false) { continue; } } $users[$i] = array(); /* * Set user's properties. * Realname is obtained from directory, if not found we set it to the username * Email is obtained from directory, if not found we set it to blank */ if (!array_key_exists(strtolower($fullname_attr), $data[$i])) { $users[$i]['realname'] = $data[$i]['cn'][0]; } else { $users[$i]['realname'] = $data[$i][strtolower($fullname_attr)][0]; } if (!array_key_exists(strtolower($buddyname_attr), $data[$i])) { $users[$i]['buddyname'] = $data[$i]['cn'][0]; } else { $users[$i]['buddyname'] = $data[$i][strtolower($buddyname_attr)][0]; } if (!array_key_exists(strtolower($email_attr), $data[$i])) { $users[$i]['email'] = ''; } else { $users[$i]['email'] = $data[$i][strtolower($email_attr)][0]; } $users[$i]['username'] = $data[$i][strtolower($username_attr)][0]; } } catch (Exception $e) { TBGContext::setMessage('module_error', TBGContext::getI18n()->__('Import failed')); TBGContext::setMessage('module_error_details', $e->getMessage()); $this->forward(TBGContext::getRouting()->generate('configure_module', array('config_module' => 'auth_ldap'))); } /* * For every user that was found, either create a new user object, or update * the existing one. This will update the created and updated counts as appropriate. */ foreach ($users as $ldapuser) { $username = $ldapuser['username']; $email = $ldapuser['email']; $realname = $ldapuser['realname']; $buddyname = $ldapuser['buddyname']; try { $user = TBGUser::getByUsername($username); if ($user instanceof TBGUser) { $user->setRealname($realname); $user->setEmail($email); // update email address $user->save(); $updatecount++; } else { // create user $user = new TBGUser(); $user->setUsername($username); $user->setRealname($realname); $user->setBuddyname($buddyname); $user->setEmail($email); $user->setEnabled(); $user->setActivated(); $user->setPassword($user->getJoinedDate() . $username); $user->setJoined(); $user->save(); $importcount++; } } catch (Exception $e) { ldap_unbind($connection); TBGContext::setMessage('module_error', TBGContext::getI18n()->__('Import failed')); TBGContext::setMessage('module_error_details', $e->getMessage()); $this->forward(TBGContext::getRouting()->generate('configure_module', array('config_module' => 'auth_ldap'))); } } ldap_unbind($connection); TBGContext::setMessage('module_message', TBGContext::getI18n()->__('Import successful! %imp users imported, %upd users updated from LDAP', array('%imp' => $importcount, '%upd' => $updatecount))); $this->forward(TBGContext::getRouting()->generate('configure_module', array('config_module' => 'auth_ldap'))); }
public function runProjectWorkflowTable(TBGRequest $request) { $this->selected_project = TBGContext::factory()->TBGProject($request['project_id']); if ($request->isPost()) { try { $workflow_scheme = TBGContext::factory()->TBGWorkflowScheme($request['new_workflow']); return $this->renderJSON(array('content' => $this->getTemplateHtml('projectworkflow_table', array('project' => $this->selected_project, 'new_workflow' => $workflow_scheme)))); } catch (Exception $e) { $this->getResponse()->setHTTPStatus(400); return $this->renderJSON(array('error' => TBGContext::geti18n()->__('This workflow scheme is not valid'))); } } }
public function componentLogin() { $this->selected_tab = isset($this->section) ? $this->section : 'login'; $this->options = $this->getParameterHolder(); if (TBGContext::hasMessage('login_referer')) { $this->referer = htmlentities(TBGContext::getMessage('login_referer'), ENT_COMPAT, TBGContext::getI18n()->getCharset()); } elseif (array_key_exists('HTTP_REFERER', $_SERVER)) { $this->referer = htmlentities($_SERVER['HTTP_REFERER'], ENT_COMPAT, TBGContext::getI18n()->getCharset()); } else { $this->referer = TBGContext::getRouting()->generate('dashboard'); } try { $this->loginintro = null; $this->registrationintro = null; $this->loginintro = TBGArticlesTable::getTable()->getArticleByName('LoginIntro'); $this->registrationintro = TBGArticlesTable::getTable()->getArticleByName('RegistrationIntro'); } catch (Exception $e) { } if (TBGSettings::isLoginRequired()) { TBGContext::getResponse()->deleteCookie('tbg3_username'); TBGContext::getResponse()->deleteCookie('tbg3_password'); $this->error = TBGContext::geti18n()->__('You need to log in to access this site'); } elseif (!TBGContext::getUser()->isAuthenticated()) { $this->error = TBGContext::geti18n()->__('Please log in'); } else { //$this->error = TBGContext::geti18n()->__('Please log in'); } }
/** * Launches the MVC framework */ public static function go() { TBGLogging::log('Dispatching'); try { if (($route = self::getRouting()->getRouteFromUrl(self::getRequest()->getParameter('url', null, false))) || self::isInstallmode()) { if (self::isUpgrademode()) { $route = array('module' => 'installation', 'action' => 'upgrade'); } elseif (self::isInstallmode()) { $route = array('module' => 'installation', 'action' => 'installIntro'); } if (is_dir(THEBUGGENIE_MODULES_PATH . $route['module'])) { if (!file_exists(THEBUGGENIE_MODULES_PATH . $route['module'] . DS . 'classes' . DS . 'actions.class.php')) { throw new TBGActionNotFoundException('The ' . $route['module'] . ' module is missing the classes/actions.class.php file, containing all the module actions'); } if (!class_exists($route['module'] . 'Actions') && !class_exists($route['module'] . 'ActionComponents')) { self::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . $route['module'] . DS . 'classes' . DS); } } else { throw new Exception('Cannot load the ' . $route['module'] . ' module'); } // Set up the action object // Construct the action class and method name, including any pre- action(s) $actionClassName = $route['module'] . 'Actions'; $actionObject = new $actionClassName(); $moduleName = $route['module']; $moduleMethod = $route['action']; } else { // self::setupI18n(); require THEBUGGENIE_MODULES_PATH . 'main' . DS . 'classes' . DS . 'actions.class.php'; $actionObject = new mainActions(); $moduleName = 'main'; $moduleMethod = 'notFound'; // self::performAction($actionObject, 'main', 'notFound'); // if (self::isDebugMode()) self::generateDebugInfo(); } self::$_action = $actionObject; if (!self::isInstallmode()) { self::initializeUser(); } self::setupI18n(); if (self::$_redirect_login == 'login') { TBGLogging::log('An error occurred setting up the user object, redirecting to login', 'main', TBGLogging::LEVEL_NOTICE); if (self::getRouting()->getCurrentRouteName() != 'login') { TBGContext::setMessage('login_message_err', TBGContext::geti18n()->__('Please log in')); } self::getResponse()->headerRedirect(self::getRouting()->generate('login_page'), 403); } if (self::$_redirect_login == 'elevated_login') { TBGLogging::log('Elevated permissions required', 'main', TBGLogging::LEVEL_NOTICE); if (self::getRouting()->getCurrentRouteName() != 'elevated_login') { TBGContext::setMessage('elevated_login_message_err', TBGContext::geti18n()->__('Please re-enter your password to continue')); } if (!class_exists('mainActions')) { require THEBUGGENIE_MODULES_PATH . 'main' . DS . 'classes' . DS . 'actions.class.php'; } $actionObject = new mainActions(); $moduleName = 'main'; $moduleMethod = 'elevatedLogin'; } if (self::performAction($actionObject, $moduleName, $moduleMethod)) { if (self::isDebugMode()) { self::generateDebugInfo(); } if (\b2db\Core::isInitialized()) { \b2db\Core::closeDBLink(); } return true; } } catch (TBGTemplateNotFoundException $e) { \b2db\Core::closeDBLink(); //header("HTTP/1.0 404 Not Found", true, 404); throw $e; } catch (TBGActionNotFoundException $e) { \b2db\Core::closeDBLink(); header("HTTP/1.0 404 Not Found", true, 404); throw $e; } catch (TBGCSRFFailureException $e) { \b2db\Core::closeDBLink(); if (self::isDebugMode()) { self::generateDebugInfo(); } self::getResponse()->setHttpStatus(301); $message = $e->getMessage(); if (self::getRequest()->getRequestedFormat() == 'json') { self::getResponse()->setContentType('application/json'); $message = json_encode(array('message' => $message)); } self::getResponse()->renderHeaders(); echo $message; } catch (Exception $e) { \b2db\Core::closeDBLink(); //header("HTTP/1.0 404 Not Found", true, 404); throw $e; } }
public function doAutoLogin() { if ($this->getSetting('integrated_auth')) { if (isset($_SERVER[$this->getSetting('integrated_auth_header')])) { return $this->doLogin($_SERVER[$this->getSetting('integrated_auth_header')], 'a', 1); } else { throw new Exception(TBGContext::geti18n()->__('HTTP integrated authentication is enabled but the HTTP header has not been provided by the web server.')); } } else { return true; } }
public function getAccountSettingsName() { return TBGContext::geti18n()->__($this->_account_settings_name); }
/** * Class constructor * * @param B2DBRow $row */ public function _construct(B2DBRow $row, $foreign_key = null) { //$this->_populateCustomfields(); $this->_mergeChangedProperties(); if ($this->isDeleted()) { throw new Exception(TBGContext::geti18n()->__('This issue has been deleted')); } }