Beispiel #1
0
 /**
  * Pre-execute function for search functions
  *
  * @param TBGRequest $request
  */
 public function preExecute(TBGRequest $request, $action)
 {
     $this->forward403unless(TBGContext::getUser()->hasPageAccess('search') && TBGContext::getUser()->canSearchForIssues());
     if ($project_key = $request['project_key']) {
         $project = TBGProject::getByKey($project_key);
     } elseif (is_numeric($request['project_id']) && ($project_id = (int) $request['project_id'])) {
         $project = TBGProjectsTable::getTable()->selectById($project_id);
     } else {
         $project = false;
     }
     if ($project instanceof TBGProject) {
         $this->forward403unless(TBGContext::getUser()->hasProjectPageAccess('project_issues', $project));
         TBGContext::getResponse()->setPage('project_issues');
         TBGContext::setCurrentProject($project);
     }
     $this->search_object = TBGSavedSearch::getFromRequest($request);
     $this->issavedsearch = $this->search_object instanceof TBGSavedSearch && $this->search_object->getB2DBID();
     $this->show_results = $this->issavedsearch || $request->hasParameter('quicksearch') || $request->hasParameter('fs') || $request->getParameter('search', false) ? true : false;
     $this->searchterm = $this->search_object->getSearchterm();
     $this->searchtitle = $this->search_object->getTitle();
     if ($this->issavedsearch) {
         if (!($this->search_object instanceof TBGSavedSearch && TBGContext::getUser()->canAccessSavedSearch($this->search_object))) {
             TBGContext::setMessage('search_error', TBGContext::getI18n()->__("You don't have access to this saved search"));
         }
     }
 }
 /**
  * Pre-execute function for search functions
  *
  * @param TBGRequest $request
  */
 public function preExecute(TBGRequest $request, $action)
 {
     $this->forward403unless(TBGContext::getUser()->hasPageAccess('search') && TBGContext::getUser()->canSearchForIssues());
     if ($request->hasParameter('project_key')) {
         if (($project = TBGProject::getByKey($request->getParameter('project_key'))) instanceof TBGProject) {
             $this->forward403unless(TBGContext::getUser()->hasProjectPageAccess('project_issues', $project->getID()));
             TBGContext::getResponse()->setPage('project_issues');
             TBGContext::setCurrentProject($project);
         }
     }
     $filters = $request->getParameter('filters', array());
     $this->searchterm = null;
     if (array_key_exists('text', $filters) && array_key_exists('value', $filters['text'])) {
         $this->searchterm = $filters['text']['value'];
     }
 }
function tbg_get_breadcrumblinks($type, $project = null)
{
    return TBGContext::getResponse()->getPredefinedBreadcrumbLinks($type, $project);
}
Beispiel #4
0
 /**
  * Returns the logged in user, or default user if not logged in
  *
  * @param TBGRequest $request
  * @param TBGAction  $action
  *
  * @return TBGUser
  */
 public static function loginCheck(TBGRequest $request, TBGAction $action)
 {
     try {
         $authentication_method = $action->getAuthenticationMethodForAction(TBGContext::getRouting()->getCurrentRouteAction());
         $user = null;
         $external = false;
         switch ($authentication_method) {
             case TBGAction::AUTHENTICATION_METHOD_ELEVATED:
             case TBGAction::AUTHENTICATION_METHOD_CORE:
                 $username = $request['tbg3_username'];
                 $password = $request['tbg3_password'];
                 if ($authentication_method == TBGAction::AUTHENTICATION_METHOD_ELEVATED) {
                     $elevated_password = $request['tbg3_elevated_password'];
                 }
                 $raw = true;
                 // If no username and password specified, check if we have a session that exists already
                 if ($username === null && $password === null) {
                     if (TBGContext::getRequest()->hasCookie('tbg3_username') && TBGContext::getRequest()->hasCookie('tbg3_password')) {
                         $username = TBGContext::getRequest()->getCookie('tbg3_username');
                         $password = TBGContext::getRequest()->getCookie('tbg3_password');
                         $user = TBGUsersTable::getTable()->getByUsername($username);
                         if ($authentication_method == TBGAction::AUTHENTICATION_METHOD_ELEVATED) {
                             $elevated_password = TBGContext::getRequest()->getCookie('tbg3_elevated_password');
                             if ($user instanceof TBGUser && !$user->hasPasswordHash($password)) {
                                 $user = null;
                             } else {
                                 if ($user instanceof TBGUser && !$user->hasPasswordHash($elevated_password)) {
                                     TBGContext::setUser($user);
                                     TBGContext::getRouting()->setCurrentRouteName('elevated_login_page');
                                     throw new TBGElevatedLoginException('reenter');
                                 }
                             }
                         } else {
                             if ($user instanceof TBGUser && !$user->hasPasswordHash($password)) {
                                 $user = null;
                             }
                         }
                         $raw = false;
                         if (!$user instanceof TBGUser) {
                             TBGContext::logout();
                             throw new Exception('No such login');
                         }
                     }
                 }
                 // If we have authentication details, validate them
                 if (TBGSettings::isUsingExternalAuthenticationBackend() && $username !== null && $password !== null) {
                     $external = true;
                     TBGLogging::log('Authenticating with backend: ' . TBGSettings::getAuthenticationBackend(), 'auth', TBGLogging::LEVEL_INFO);
                     try {
                         $mod = TBGContext::getModule(TBGSettings::getAuthenticationBackend());
                         if ($mod->getType() !== TBGModule::MODULE_AUTH) {
                             TBGLogging::log('Auth module is not the right type', 'auth', TBGLogging::LEVEL_FATAL);
                         }
                         if (TBGContext::getRequest()->hasCookie('tbg3_username') && TBGContext::getRequest()->hasCookie('tbg3_password')) {
                             $user = $mod->verifyLogin($username, $password);
                         } else {
                             $user = $mod->doLogin($username, $password);
                         }
                         if (!$user instanceof TBGUser) {
                             // Invalid
                             TBGContext::logout();
                             throw new Exception('No such login');
                             //TBGContext::getResponse()->headerRedirect(TBGContext::getRouting()->generate('login'));
                         }
                     } catch (Exception $e) {
                         throw $e;
                     }
                 } elseif (TBGSettings::isUsingExternalAuthenticationBackend()) {
                     $external = true;
                     TBGLogging::log('Authenticating without credentials with backend: ' . TBGSettings::getAuthenticationBackend(), 'auth', TBGLogging::LEVEL_INFO);
                     try {
                         $mod = TBGContext::getModule(TBGSettings::getAuthenticationBackend());
                         if ($mod->getType() !== TBGModule::MODULE_AUTH) {
                             TBGLogging::log('Auth module is not the right type', 'auth', TBGLogging::LEVEL_FATAL);
                         }
                         $user = $mod->doAutoLogin();
                         if ($user == false) {
                             // Invalid
                             TBGContext::logout();
                             throw new Exception('No such login');
                             //TBGContext::getResponse()->headerRedirect(TBGContext::getRouting()->generate('login'));
                         }
                     } catch (Exception $e) {
                         throw $e;
                     }
                 } elseif ($username !== null && $password !== null && !$user instanceof TBGUser) {
                     $external = false;
                     TBGLogging::log('Using internal authentication', 'auth', TBGLogging::LEVEL_INFO);
                     $user = TBGUsersTable::getTable()->getByUsername($username);
                     if (!$user->hasPassword($password)) {
                         $user = null;
                     }
                     if (!$user instanceof TBGUser) {
                         TBGContext::logout();
                     }
                 }
                 break;
             case TBGAction::AUTHENTICATION_METHOD_DUMMY:
                 $user = TBGUsersTable::getTable()->getByUserID(TBGSettings::getDefaultUserID());
                 break;
             case TBGAction::AUTHENTICATION_METHOD_CLI:
                 $user = TBGUsersTable::getTable()->getByUsername(TBGContext::getCurrentCLIusername());
                 break;
             case TBGAction::AUTHENTICATION_METHOD_RSS_KEY:
                 $user = TBGUsersTable::getTable()->getByRssKey($request['rsskey']);
                 break;
             case TBGAction::AUTHENTICATION_METHOD_APPLICATION_PASSWORD:
                 $user = TBGUsersTable::getTable()->getByUsername($request['api_username']);
                 if (!$user->authenticateApplicationPassword($request['api_token'])) {
                     $user = null;
                 }
                 break;
             default:
                 if (!TBGSettings::isLoginRequired()) {
                     $user = TBGUsersTable::getTable()->getByUserID(TBGSettings::getDefaultUserID());
                 }
         }
         if ($user instanceof TBGUser) {
             if (!$user->isActivated()) {
                 throw new Exception('This account has not been activated yet');
             } elseif (!$user->isEnabled()) {
                 throw new Exception('This account has been suspended');
             } elseif (!$user->isConfirmedMemberOfScope(TBGContext::getScope())) {
                 if (!TBGSettings::isRegistrationAllowed()) {
                     throw new Exception('This account does not have access to this scope');
                 }
             }
             if ($external == false && $authentication_method == TBGAction::AUTHENTICATION_METHOD_CORE) {
                 $password = $user->getHashPassword();
                 if (!$request->hasCookie('tbg3_username')) {
                     if ($request->getParameter('tbg3_rememberme')) {
                         TBGContext::getResponse()->setCookie('tbg3_username', $user->getUsername());
                         TBGContext::getResponse()->setCookie('tbg3_password', $user->getPassword());
                     } else {
                         TBGContext::getResponse()->setSessionCookie('tbg3_username', $user->getUsername());
                         TBGContext::getResponse()->setSessionCookie('tbg3_password', $user->getPassword());
                     }
                 }
             }
         } elseif (TBGSettings::isLoginRequired()) {
             throw new Exception('Login required');
         } else {
             throw new Exception('No such login');
         }
     } catch (Exception $e) {
         throw $e;
     }
     return $user;
 }
 protected function _parse_variable($matches)
 {
     switch ($matches[2]) {
         case 'CURRENTMONTH':
             return date('m');
         case 'CURRENTMONTHNAMEGEN':
         case 'CURRENTMONTHNAME':
             return date('F');
         case 'CURRENTDAY':
             return date('d');
         case 'CURRENTDAYNAME':
             return date('l');
         case 'CURRENTYEAR':
             return date('Y');
         case 'CURRENTTIME':
             return date('H:i');
         case 'NUMBEROFARTICLES':
             return 0;
         case 'PAGENAME':
             return TBGContext::getResponse()->getPage();
         case 'NAMESPACE':
             return 'None';
         case 'TOC':
             return '{{TOC}}';
         case 'SITENAME':
             return TBGSettings::getTBGname();
         case 'SITETAGLINE':
             return TBGSettings::getTBGtagline();
         default:
             return '';
     }
 }
Beispiel #6
0
function tbg_get_stylesheets()
{
    $tbg_response = TBGContext::getResponse();
    $cssstrings = array();
    $sepcss = array();
    // Add stylesheets to minify and non-minify lists
    foreach ($tbg_response->getStylesheets() as $stylesheet => $minify) {
        if ($minify == true && file_exists(THEBUGGENIE_PATH . THEBUGGENIE_PUBLIC_FOLDER_NAME . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . TBGSettings::getThemeName() . DIRECTORY_SEPARATOR . $stylesheet)) {
            $cssstrings[] = 'themes/' . TBGSettings::getThemeName() . '/' . $stylesheet;
        } else {
            $sepcss[] = $stylesheet;
        }
    }
    $cssstrings = join(',', $cssstrings);
    return array($cssstrings, $sepcss);
}
Beispiel #7
0
 /**
  * Do login (AJAX call)
  *  
  * @param TBGRequest $request
  */
 public function runDoLogin(TBGRequest $request)
 {
     $i18n = TBGContext::getI18n();
     $options = $request->getParameters();
     $forward_url = TBGContext::getRouting()->generate('home');
     if ($request->hasParameter('persona') && $request['persona'] == 'true') {
         $url = 'https://verifier.login.persona.org/verify';
         $assert = filter_input(INPUT_POST, 'assertion', FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH);
         //Use the $_POST superglobal array for PHP < 5.2 and write your own filter
         $params = 'assertion=' . urlencode($assert) . '&audience=' . urlencode(TBGContext::getURLhost() . ':80');
         $ch = curl_init();
         $options = array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_POST => 2, CURLOPT_POSTFIELDS => $params);
         curl_setopt_array($ch, $options);
         $result = curl_exec($ch);
         curl_close($ch);
         $details = json_decode($result);
         $user = null;
         if ($details->status == 'okay') {
             $user = TBGUser::getByEmail($details->email);
             if ($user instanceof TBGUser) {
                 TBGContext::getResponse()->setCookie('tbg3_password', $user->getPassword());
                 TBGContext::getResponse()->setCookie('tbg3_username', $user->getUsername());
                 TBGContext::getResponse()->setCookie('tbg3_persona_session', true);
                 return $this->renderJSON(array('status' => 'login ok', 'redirect' => in_array($request['referrer_route'], array('home', 'login'))));
             }
         }
         if (!$user instanceof TBGUser) {
             $this->getResponse()->setHttpStatus(401);
             $this->renderJSON(array('message' => $this->getI18n()->__('Invalid login')));
         }
         return;
     }
     if (TBGSettings::isOpenIDavailable()) {
         $openid = new LightOpenID(TBGContext::getRouting()->generate('login_page', array(), false));
     }
     if (TBGSettings::isOpenIDavailable() && !$openid->mode && $request->isPost() && $request->hasParameter('openid_identifier')) {
         $openid->identity = $request->getRawParameter('openid_identifier');
         $openid->required = array('contact/email');
         $openid->optional = array('namePerson/first', 'namePerson/friendly');
         return $this->forward($openid->authUrl());
     } elseif (TBGSettings::isOpenIDavailable() && $openid->mode == 'cancel') {
         $this->error = TBGContext::getI18n()->__("OpenID authentication cancelled");
     } elseif (TBGSettings::isOpenIDavailable() && $openid->mode) {
         try {
             if ($openid->validate()) {
                 if ($this->getUser()->isAuthenticated() && !$this->getUser()->isGuest()) {
                     if (TBGOpenIdAccountsTable::getTable()->getUserIDfromIdentity($openid->identity)) {
                         TBGContext::setMessage('openid_used', true);
                         throw new Exception('OpenID already in use');
                     }
                     $user = $this->getUser();
                 } else {
                     $user = TBGUser::getByOpenID($openid->identity);
                 }
                 if ($user instanceof TBGUser) {
                     $attributes = $openid->getAttributes();
                     $email = array_key_exists('contact/email', $attributes) ? $attributes['contact/email'] : null;
                     if (!$user->getEmail()) {
                         if (array_key_exists('contact/email', $attributes)) {
                             $user->setEmail($attributes['contact/email']);
                         }
                         if (array_key_exists('namePerson/first', $attributes)) {
                             $user->setRealname($attributes['namePerson/first']);
                         }
                         if (array_key_exists('namePerson/friendly', $attributes)) {
                             $user->setBuddyname($attributes['namePerson/friendly']);
                         }
                         if (!$user->getNickname() || $user->isOpenIdLocked()) {
                             $user->setBuddyname($user->getEmail());
                         }
                         if (!$user->getRealname()) {
                             $user->setRealname($user->getBuddyname());
                         }
                         $user->save();
                     }
                     if (!$user->hasOpenIDIdentity($openid->identity)) {
                         TBGOpenIdAccountsTable::getTable()->addIdentity($openid->identity, $email, $user->getID());
                     }
                     TBGContext::getResponse()->setCookie('tbg3_password', $user->getPassword());
                     TBGContext::getResponse()->setCookie('tbg3_username', $user->getUsername());
                     if ($this->checkScopeMembership($user)) {
                         return true;
                     }
                     return $this->forward(TBGContext::getRouting()->generate(TBGSettings::get('returnfromlogin')));
                 } else {
                     $this->error = TBGContext::getI18n()->__("Didn't recognize this OpenID. Please log in using your username and password, associate it with your user account in your account settings and try again.");
                 }
             } else {
                 $this->error = TBGContext::getI18n()->__("Could not validate against the OpenID provider");
             }
         } catch (Exception $e) {
             $this->error = TBGContext::getI18n()->__("Could not validate against the OpenID provider: %message", array('%message' => htmlentities($e->getMessage(), ENT_COMPAT, TBGContext::getI18n()->getCharset())));
         }
     } elseif ($request->getMethod() == TBGRequest::POST) {
         try {
             if ($request->hasParameter('tbg3_username') && $request->hasParameter('tbg3_password') && $request['tbg3_username'] != '' && $request['tbg3_password'] != '') {
                 $user = TBGUser::loginCheck($request, $this);
                 TBGContext::setUser($user);
                 if ($this->checkScopeMembership($user)) {
                     return true;
                 }
                 if ($request->hasParameter('return_to')) {
                     $forward_url = $request['return_to'];
                 } else {
                     if (TBGSettings::get('returnfromlogin') == 'referer') {
                         $forward_url = $request->getParameter('tbg3_referer', TBGContext::getRouting()->generate('dashboard'));
                     } else {
                         $forward_url = TBGContext::getRouting()->generate(TBGSettings::get('returnfromlogin'));
                     }
                 }
                 $forward_url = htmlentities($forward_url, ENT_COMPAT, TBGContext::getI18n()->getCharset());
             } else {
                 throw new Exception('Please enter a username and password');
             }
         } catch (Exception $e) {
             if ($request->isAjaxCall()) {
                 $this->getResponse()->setHttpStatus(401);
                 TBGLogging::log($e->getMessage(), 'openid', TBGLogging::LEVEL_WARNING_RISK);
                 return $this->renderJSON(array("error" => $i18n->__("Invalid login details")));
             } else {
                 $this->forward403($e->getMessage());
             }
         }
     } else {
         if ($request->isAjaxCall()) {
             $this->getResponse()->setHttpStatus(401);
             return $this->renderJSON(array("error" => $i18n->__('Please enter a username and password')));
         } else {
             $this->forward403($i18n->__('Please enter a username and password'));
         }
     }
     if ($this->checkScopeMembership($user)) {
         return true;
     }
     if ($request->isAjaxCall()) {
         return $this->renderJSON(array('forward' => $forward_url));
     } else {
         $this->forward($this->getRouting()->generate('account'));
     }
 }
 protected function _parse_insert_template($matches)
 {
     switch ($matches[1]) {
         case 'CURRENTMONTH':
             return date('m');
         case 'CURRENTMONTHNAMEGEN':
         case 'CURRENTMONTHNAME':
             return date('F');
         case 'CURRENTDAY':
             return date('d');
         case 'CURRENTDAYNAME':
             return date('l');
         case 'CURRENTYEAR':
             return date('Y');
         case 'CURRENTTIME':
             return date('H:i');
         case 'NUMBEROFARTICLES':
             return 0;
         case 'PAGENAME':
             return TBGContext::getResponse()->getPage();
         case 'NAMESPACE':
             return 'None';
         case 'TOC':
             return isset($this->options['included']) ? '' : '{{TOC}}';
         case 'SITENAME':
         case 'SITETAGLINE':
             return TBGSettings::getTBGname();
         default:
             $details = explode('|', $matches[1]);
             $template_name = array_shift($details);
             if (substr($template_name, 0, 1) == ':') {
                 $template_name = substr($template_name, 1);
             }
             $template_name = TBGWikiArticle::doesArticleExist($template_name) ? $template_name : 'Template:' . $template_name;
             $template_article = TBGArticlesTable::getTable()->getArticleByName($template_name);
             $parameters = array();
             if (count($details)) {
                 foreach ($details as $parameter) {
                     $param = explode('=', $parameter);
                     if (count($param) == 2) {
                         $parameters[$param[0]] = $param[1];
                     } else {
                         $parameters[] = $parameter;
                     }
                 }
             }
             if ($template_article instanceof TBGWikiArticle) {
                 return tbg_parse_text($template_article->getContent(), false, null, array('included' => true, 'parameters' => $parameters));
             } else {
                 return $matches[0];
             }
     }
 }
 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');
     }
 }
Beispiel #10
0
<?php

/**
 * Configuration for theme
 */
TBGContext::getResponse()->addStylesheet('oxygen.css');
?>
<style>
	#tbg3_username, #fieldusername { background-image: url('<?php 
echo TBGContext::getTBGPath() . 'iconsets/' . TBGSettings::getIconsetName() . '/';
?>
user_mono.png'); }
	#fieldusername.invalid { background-image: url('<?php 
echo TBGContext::getTBGPath() . 'iconsets/' . TBGSettings::getIconsetName() . '/';
?>
icon_error.png'); background-color: rgba(255, 220, 220, 0.5); }
	#fieldusername.valid { background-image: url('<?php 
echo TBGContext::getTBGPath() . 'iconsets/' . TBGSettings::getIconsetName() . '/';
?>
icon_ok.png'); background-color: rgba(220, 255, 220, 0.5); }
	.login_popup input[type=password] { background-image: url('<?php 
echo TBGContext::getTBGPath() . 'iconsets/' . TBGSettings::getIconsetName() . '/';
?>
password_mono.png'); }
	#openid-signin-button.persona-button span:after{ background-image: url('<?php 
echo TBGContext::getTBGPath() . 'iconsets/' . TBGSettings::getIconsetName() . '/';
?>
openid_providers.small/openid.ico.png'); }
	#regular-signin-button.persona-button span:after{ background-image: url('<?php 
echo TBGContext::getTBGPath() . 'iconsets/' . TBGSettings::getIconsetName() . '/';
?>
Beispiel #11
0
 public function runAddCommitGitorious(TBGRequest $request)
 {
     TBGContext::getResponse()->setContentType('text/plain');
     TBGContext::getResponse()->renderHeaders();
     $passkey = TBGContext::getRequest()->getParameter('passkey');
     $project_id = urldecode(TBGContext::getRequest()->getParameter('project_id'));
     $project = TBGContext::factory()->TBGProject($project_id);
     // Validate access
     if (!$project) {
         echo 'Error: The project with the ID ' . $project_id . ' does not exist';
         exit;
     }
     if (TBGSettings::get('access_method_' . $project->getID(), 'vcs_integration') == TBGVCSIntegration::ACCESS_DIRECT) {
         echo 'Error: This project uses the CLI access method, and so access via HTTP has been disabled';
         exit;
     }
     if (TBGSettings::get('access_passkey_' . $project->getID(), 'vcs_integration') != $passkey) {
         echo 'Error: The passkey specified does not match the passkey specified for this project';
         exit;
     }
     // Validate data
     $data = html_entity_decode(TBGContext::getRequest()->getParameter('payload', null, false));
     if (empty($data) || $data == null) {
         die('Error: No payload was provided');
     }
     $entries = json_decode($data);
     if ($entries == null) {
         die('Error: The payload could not be decoded');
     }
     $entries = json_decode($data);
     $previous = $entries->before;
     // Branch is stored in the ref
     $ref = $entries->ref;
     $parts = explode('/', $ref);
     if (count($parts) == 3) {
         $branch = $parts[2];
     } else {
         $branch = null;
     }
     // Parse each commit individually
     foreach (array_reverse($entries->commits) as $commit) {
         $email = $commit->author->email;
         $author = $commit->author->name;
         $new_rev = $commit->id;
         $old_rev = $previous;
         $commit_msg = $commit->message;
         $time = strtotime($commit->timestamp);
         // Add commit
         echo TBGVCSIntegration::processCommit($project, $commit_msg, $old_rev, $previous, $time, "", $author, $branch);
         $previous = $new_rev;
         exit;
     }
 }
Beispiel #12
0
<?php

TBGContext::getResponse()->addHeader('Content-Disposition: attachment; filename="' . $searchtitle . '.csv"');
include_template('search/results_normal_csv', array('issues' => $issues));
 /**
  * Returns the logged in user, or default user if not logged in
  *
  * @param string $uname
  * @param string $upwd
  * 
  * @return TBGUser
  */
 public static function loginCheck($username = null, $password = null)
 {
     try {
         $row = null;
         // If no username and password specified, check if we have a session that exists already
         if ($username === null && $password === null) {
             if (TBGContext::getRequest()->hasCookie('tbg3_username') && TBGContext::getRequest()->hasCookie('tbg3_password')) {
                 $username = TBGContext::getRequest()->getCookie('tbg3_username');
                 $password = TBGContext::getRequest()->getCookie('tbg3_password');
                 $row = TBGUsersTable::getTable()->getByUsernameAndPassword($username, $password);
                 if (!$row) {
                     TBGContext::getResponse()->deleteCookie('tbg3_username');
                     TBGContext::getResponse()->deleteCookie('tbg3_password');
                     throw new Exception('No such login');
                     //TBGContext::getResponse()->headerRedirect(TBGContext::getRouting()->generate('login'));
                 }
             }
         }
         // If we have authentication details, validate them
         if (TBGSettings::getAuthenticationBackend() !== null && TBGSettings::getAuthenticationBackend() !== 'tbg' && $username !== null && $password !== null) {
             TBGLogging::log('Authenticating with backend: ' . TBGSettings::getAuthenticationBackend(), 'auth', TBGLogging::LEVEL_INFO);
             try {
                 $mod = TBGContext::getModule(TBGSettings::getAuthenticationBackend());
                 if ($mod->getType() !== TBGModule::MODULE_AUTH) {
                     TBGLogging::log('Auth module is not the right type', 'auth', TBGLogging::LEVEL_FATAL);
                     throw new Exception('Invalid module type');
                 }
                 if (TBGContext::getRequest()->hasCookie('tbg3_username') && TBGContext::getRequest()->hasCookie('tbg3_password')) {
                     $row = $mod->verifyLogin($username, $password);
                 } else {
                     $row = $mod->doLogin($username, $password);
                 }
                 if (!$row) {
                     // Invalid
                     TBGContext::getResponse()->deleteCookie('tbg3_username');
                     TBGContext::getResponse()->deleteCookie('tbg3_password');
                     throw new Exception('No such login');
                     //TBGContext::getResponse()->headerRedirect(TBGContext::getRouting()->generate('login'));
                 }
             } catch (Exception $e) {
                 throw $e;
             }
         } elseif ($username !== null && $password !== null) {
             TBGLogging::log('Using internal authentication', 'auth', TBGLogging::LEVEL_INFO);
             // First test a pre-encrypted password
             $row = TBGUsersTable::getTable()->getByUsernameAndPassword($username, $password);
             if (!$row) {
                 // Then test an unencrypted password
                 $row = TBGUsersTable::getTable()->getByUsernameAndPassword($username, self::hashPassword($password));
                 if (!$row) {
                     // This is a legacy account from a 2.1 upgrade - try md5
                     $row = TBGUsersTable::getTable()->getByUsernameAndPassword($username, md5($password));
                     if (!$row) {
                         // Invalid
                         TBGContext::getResponse()->deleteCookie('tbg3_username');
                         TBGContext::getResponse()->deleteCookie('tbg3_password');
                         throw new Exception('No such login');
                         //TBGContext::getResponse()->headerRedirect(TBGContext::getRouting()->generate('login'));
                     } else {
                         // convert md5 to new password type
                         $user = new TBGUser($row->get(TBGUsersTable::ID), $row);
                         $user->changePassword($password);
                         $user->save();
                         unset($user);
                     }
                 }
             }
         } elseif (TBGContext::isCLI()) {
             $row = TBGUsersTable::getTable()->getByUsername(TBGContext::getCurrentCLIusername());
         } elseif (!TBGSettings::isLoginRequired()) {
             $row = TBGUsersTable::getTable()->getByUserID(TBGSettings::getDefaultUserID());
         }
         if ($row) {
             if (!$row->get(TBGScopesTable::ENABLED)) {
                 throw new Exception('This account belongs to a scope that is not active');
             } elseif (!$row->get(TBGUsersTable::ACTIVATED)) {
                 throw new Exception('This account has not been activated yet');
             } elseif (!$row->get(TBGUsersTable::ENABLED)) {
                 throw new Exception('This account has been suspended');
             }
             $user = TBGContext::factory()->TBGUser($row->get(TBGUsersTable::ID), $row);
         } elseif (TBGSettings::isLoginRequired()) {
             throw new Exception('Login required');
         } else {
             throw new Exception('No such login');
         }
     } catch (Exception $e) {
         throw $e;
     }
     return $user;
 }
 public function doLogin($username, $password, $mode = 1)
 {
     $validgroups = $this->getSetting('groups');
     $base_dn = $this->getSetting('b_dn');
     $dn_attr = $this->escape($this->getSetting('dn_attr'));
     $username_attr = $this->escape($this->getSetting('u_attr'));
     $fullname_attr = $this->escape($this->getSetting('f_attr'));
     $buddyname_attr = $this->escape($this->getSetting('b_attr'));
     $email_attr = $this->escape($this->getSetting('e_attr'));
     $groups_members_attr = $this->escape($this->getSetting('g_attr'));
     $user_class = TBGContext::getModule('auth_ldap')->getSetting('u_type');
     $group_class = TBGContext::getModule('auth_ldap')->getSetting('g_type');
     $email = null;
     $integrated_auth = $this->getSetting('integrated_auth');
     /*
      * Do the LDAP check here.
      * 
      * If a connection error or something, throw an exception and log
      * 
      * If we can, set $mail and $realname to correct values from LDAP
      * otherwise don't touch those variables.
      * 
      * To log do:
      * TBGLogging::log('error goes here', 'ldap', TBGLogging::LEVEL_FATAL);
      */
     try {
         /*
          * First job is to connect to our control user (may be an anonymous bind)
          * so we can find the user we want to log in as/validate.
          */
         $connection = $this->connect();
         $control_user = $this->getSetting('control_user');
         $control_password = $this->getSetting('control_pass');
         $this->bind($connection, $control_user, $control_password);
         // Assume bind successful, otherwise we would have had an exception
         /*
          * Search for a user with the username specified. We search in the base_dn, so we can
          * find users in multiple parts of the directory, and only return users of a specific
          * class (default person).
          * 
          * We want exactly 1 user to be returned. We get the user's full name, email, cn
          * and dn.
          */
         $fields = array($fullname_attr, $buddyname_attr, $email_attr, 'cn', $dn_attr);
         $filter = '(&(objectClass=' . TBGLDAPAuthentication::getModule()->escape($user_class) . ')(' . $username_attr . '=' . $this->escape($username) . '))';
         $results = ldap_search($connection, $base_dn, $filter, $fields);
         if (!$results) {
             TBGLogging::log('failed to search for user: '******'ldap', TBGLogging::LEVEL_FATAL);
             throw new Exception(TBGContext::geti18n()->__('Search failed: ') . ldap_error($connection));
         }
         $data = ldap_get_entries($connection, $results);
         // User does not exist
         if ($data['count'] == 0) {
             TBGLogging::log('could not find user ' . $username . ', class ' . $user_class . ', attribute ' . $username_attr, 'ldap', TBGLogging::LEVEL_FATAL);
             throw new Exception(TBGContext::geti18n()->__('User does not exist in the directory'));
         }
         // If we have more than 1 user, something is seriously messed up...
         if ($data['count'] > 1) {
             TBGLogging::log('too many users for ' . $username . ', class ' . $user_class . ', attribute ' . $username_attr, 'ldap', TBGLogging::LEVEL_FATAL);
             throw new Exception(TBGContext::geti18n()->__('This user was found multiple times in the directory, please contact your admimistrator'));
         }
         /*
          * 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 as per users (See that stuff)
                  * We want to find 1 group, if we don't get 1, silently ignore this group.
                  */
                 $fields2 = array($groups_members_attr);
                 $filter2 = '(&(objectClass=' . TBGLDAPAuthentication::getModule()->escape($group_class) . ')(cn=' . $this->escape($group) . '))';
                 $results2 = ldap_search($connection, $base_dn, $filter2, $fields2);
                 if (!$results2) {
                     TBGLogging::log('failed to search for user after binding: ' . ldap_error($connection), '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])/', '', $data[0][strtolower($dn_attr)][0]);
                     if (!is_numeric($member) && strtolower($member) == strtolower($user_dn)) {
                         $allowed = true;
                     }
                 }
             }
             if ($allowed == false) {
                 throw new Exception(TBGContext::getI18n()->__('You are not a member of a group allowed to log in'));
             }
         }
         /*
          * 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[0])) {
             $realname = $username;
         } else {
             $realname = $data[0][strtolower($fullname_attr)][0];
         }
         if (!array_key_exists(strtolower($buddyname_attr), $data[0])) {
             $buddyname = $username;
         } else {
             $buddyname = $data[0][strtolower($buddyname_attr)][0];
         }
         if (!array_key_exists(strtolower($email_attr), $data[0])) {
             $email = '';
         } else {
             $email = $data[0][strtolower($email_attr)][0];
         }
         /*
          * If we are performing a non integrated authentication login, 
          * now bind to the user and see if the credentials
          * are valid. We bind using the full DN of the user, so no need for DOMAIN\ stuff
          * on Windows, and more importantly it fixes other servers.
          * 
          * If the bind fails (exception), we throw a nicer exception and don't continue.
          */
         if ($mode == 1 && !$integrated_auth) {
             try {
                 if (!is_array($data[0][strtolower($dn_attr)])) {
                     $dn = $data[0][strtolower($dn_attr)];
                 } else {
                     $dn = $data[0][strtolower($dn_attr)][0];
                 }
                 $bind = $this->bind($connection, $this->escape($dn), $password);
             } catch (Exception $e) {
                 throw new Exception(TBGContext::geti18n()->__('Your password was not accepted by the server'));
             }
         } elseif ($mode == 1) {
             if (!isset($_SERVER[$this->getSetting('integrated_auth_header')]) || $_SERVER[$this->getSetting('integrated_auth_header')] != $username) {
                 throw new Exception(TBGContext::geti18n()->__('HTTP authentication internal error.'));
             }
         }
     } catch (Exception $e) {
         ldap_unbind($connection);
         throw $e;
     }
     try {
         /*
          * Get the user object. If the user exists, update the user's
          * data from the directory.
          */
         $user = TBGUser::getByUsername($username);
         if ($user instanceof TBGUser) {
             $user->setBuddyname($buddyname);
             $user->setRealname($realname);
             $user->setPassword($user->getJoinedDate() . $username);
             // update password
             $user->setEmail($email);
             // update email address
             $user->save();
         } else {
             /*
              * If not, and we are performing an initial login, create the user object
              * if we are validating a log in, kick the user out as the session is invalid.
              */
             if ($mode == 1) {
                 // create user
                 $user = new TBGUser();
                 $user->setUsername($username);
                 $user->setRealname('temporary');
                 $user->setBuddyname($username);
                 $user->setEmail('temporary');
                 $user->setEnabled();
                 $user->setActivated();
                 $user->setJoined();
                 $user->setPassword($user->getJoinedDate() . $username);
                 $user->save();
             } else {
                 throw new Exception('User does not exist in TBG');
             }
         }
     } catch (Exception $e) {
         ldap_unbind($connection);
         throw $e;
     }
     ldap_unbind($connection);
     /*
      * Set cookies and return user row for general operations.
      */
     TBGContext::getResponse()->setCookie('tbg3_username', $username);
     TBGContext::getResponse()->setCookie('tbg3_password', TBGUser::hashPassword($user->getJoinedDate() . $username, $user->getSalt()));
     return TBGUsersTable::getTable()->getByUsername($username);
 }
Beispiel #15
0
<?php

/**
 * Configuration for theme
 */
TBGContext::getResponse()->addStylesheet('firehouse.css');
/**
 * Displays a nicely formatted exception message
 *  
 * @param string $title
 * @param Exception $exception
 */
function tbg_exception($title, $exception)
{
    if (TBGContext::getRequest() instanceof TBGRequest && TBGContext::getRequest()->isAjaxCall()) {
        TBGContext::getResponse()->ajaxResponseText(404, $title);
    }
    $ob_status = ob_get_status();
    if (!empty($ob_status) && $ob_status['status'] != PHP_OUTPUT_HANDLER_END) {
        ob_end_clean();
    }
    if (TBGContext::isCLI()) {
        $trace_elements = null;
        if ($exception instanceof Exception) {
            if ($exception instanceof TBGActionNotFoundException) {
                TBGCliCommand::cli_echo("Could not find the specified action\n", 'white', 'bold');
            } elseif ($exception instanceof TBGTemplateNotFoundException) {
                TBGCliCommand::cli_echo("Could not find the template file for the specified action\n", 'white', 'bold');
            } elseif ($exception instanceof B2DBException) {
                TBGCliCommand::cli_echo("An exception was thrown in the B2DB framework\n", 'white', 'bold');
            } else {
                TBGCliCommand::cli_echo("An unhandled exception occurred:\n", 'white', 'bold');
            }
            echo TBGCliCommand::cli_echo($exception->getMessage(), 'red', 'bold') . "\n";
            echo "\n";
            TBGCliCommand::cli_echo('Stack trace') . ":\n";
            $trace_elements = $exception->getTrace();
        } else {
            if ($exception['code'] == 8) {
                TBGCliCommand::cli_echo('The following notice has stopped further execution:', 'white', 'bold');
            } else {
                TBGCliCommand::cli_echo('The following error occured:', 'white', 'bold');
            }
            echo "\n";
            echo "\n";
            TBGCliCommand::cli_echo($title, 'red', 'bold');
            echo "\n";
            TBGCliCommand::cli_echo("occured in\n");
            TBGCliCommand::cli_echo($exception['file'] . ', line ' . $exception['line'], 'blue', 'bold');
            echo "\n";
            echo "\n";
            TBGCliCommand::cli_echo("Backtrace:\n", 'white', 'bold');
            $trace_elements = debug_backtrace();
        }
        foreach ($trace_elements as $trace_element) {
            if (array_key_exists('class', $trace_element)) {
                TBGCliCommand::cli_echo($trace_element['class'] . $trace_element['type'] . $trace_element['function'] . '()');
            } elseif (array_key_exists('function', $trace_element)) {
                if (in_array($trace_element['function'], array('tbg_error_handler', 'tbg_exception'))) {
                    continue;
                }
                TBGCliCommand::cli_echo($trace_element['function'] . '()');
            } else {
                TBGCliCommand::cli_echo('unknown function');
            }
            echo "\n";
            if (array_key_exists('file', $trace_element)) {
                TBGCliCommand::cli_echo($trace_element['file'] . ', line ' . $trace_element['line'], 'blue', 'bold');
            } else {
                TBGCliCommand::cli_echo('unknown file', 'red', 'bold');
            }
            echo "\n";
        }
        if (class_exists('B2DB')) {
            echo "\n";
            TBGCliCommand::cli_echo("SQL queries:\n", 'white', 'bold');
            try {
                $cc = 1;
                foreach (B2DB::getSQLHits() as $details) {
                    TBGCliCommand::cli_echo("(" . $cc++ . ") [");
                    $str = $details['time'] >= 1 ? round($details['time'], 2) . ' seconds' : round($details['time'] * 1000, 1) . 'ms';
                    TBGCliCommand::cli_echo($str);
                    TBGCliCommand::cli_echo("] from ");
                    TBGCliCommand::cli_echo($details['filename'], 'blue');
                    TBGCliCommand::cli_echo(", line ");
                    TBGCliCommand::cli_echo($details['line'], 'white', 'bold');
                    TBGCliCommand::cli_echo(":\n");
                    TBGCliCommand::cli_echo("{$details['sql']}\n");
                }
                echo "\n";
            } catch (Exception $e) {
                TBGCliCommand::cli_echo("Could not generate query list (there may be no database connection)", "red", "bold");
            }
        }
        echo "\n";
        die;
    }
    echo "\n\t\t<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n\t\t<html>\n\t\t<head>\n\t\t<style>\n\t\tbody { background-color: #DFDFDF; font-family: \"Droid Sans\", \"Trebuchet MS\", \"Liberation Sans\", \"Nimbus Sans L\", \"Luxi Sans\", Verdana, sans-serif; font-size: 13px; }\n\t\th1 { margin: 5px 0 0 0; font-size: 19px; }\n\t\th2 { margin: 0 0 15px 0; font-size: 16px; }\n\t\th3 { margin: 15px 0 0 0; font-size: 14px; }\n\t\tinput[type=\"text\"], input[type=\"password\"] { float: left; margin-right: 15px; }\n\t\tlabel { float: left; font-weight: bold; margin-right: 5px; display: block; width: 150px; }\n\t\tlabel span { font-weight: normal; color: #888; }\n\t\t.rounded_box {background: transparent; margin:0px;}\n\t\t.rounded_box h4 { margin-bottom: 0px; margin-top: 7px; font-size: 14px; }\n\t\t.xtop, .xbottom {display:block; background:transparent; font-size:1px;}\n\t\t.xb1, .xb2, .xb3, .xb4 {display:block; overflow:hidden;}\n\t\t.xb1, .xb2, .xb3 {height:1px;}\n\t\t.xb2, .xb3, .xb4 {background:#F9F9F9; border-left:1px solid #CCC; border-right:1px solid #CCC;}\n\t\t.xb1 {margin:0 5px; background:#CCC;}\n\t\t.xb2 {margin:0 3px; border-width:0 2px;}\n\t\t.xb3 {margin:0 2px;}\n\t\t.xb4 {height:2px; margin:0 1px;}\n\t\t.xboxcontent {display:block; background:#F9F9F9; border:0 solid #CCC; border-width:0 1px; padding: 0 5px 0 5px;}\n\t\t.xboxcontent table td.description { padding: 3px 3px 3px 0;}\n\t\t.white .xb2, .white .xb3, .white .xb4 { background: #FFF; border-color: #CCC; }\n\t\t.white .xb1 { background: #CCC; }\n\t\t.white .xboxcontent { background: #FFF; border-color: #CCC; }\n\t\tpre { overflow: scroll; padding: 5px; }\n\t\t</style>\n\t\t<!--[if IE]>\n\t\t<style>\n\t\tbody { background-color: #DFDFDF; font-family: sans-serif; font-size: 13px; }\n\t\t</style>\n\t\t<![endif]-->\n\t\t</head>\n\t\t<body>\n\t\t<div class=\"rounded_box white\" style=\"margin: 30px auto 0 auto; width: 700px;\">\n\t\t\t<b class=\"xtop\"><b class=\"xb1\"></b><b class=\"xb2\"></b><b class=\"xb3\"></b><b class=\"xb4\"></b></b>\n\t\t\t<div class=\"xboxcontent\" style=\"vertical-align: middle; padding: 10px 10px 10px 15px;\">\n\t\t\t<img style=\"float: left; margin-right: 10px;\" src=\"" . TBGContext::getTBGPath() . "header.png\"><h1>An error occured in The Bug Genie</h1>";
    echo "<h2>{$title}</h2>";
    $report_description = null;
    if ($exception instanceof Exception) {
        if ($exception instanceof TBGActionNotFoundException) {
            echo "<h3>Could not find the specified action</h3>";
            $report_description = "Could not find the specified action";
        } elseif ($exception instanceof TBGTemplateNotFoundException) {
            echo "<h3>Could not find the template file for the specified action</h3>";
            $report_description = "Could not find the template file for the specified action";
        } elseif ($exception instanceof B2DBException) {
            echo "<h3>An exception was thrown in the B2DB framework</h3>";
            $report_description = "An exception was thrown in the B2DB framework";
        } else {
            echo "<h3>An unhandled exception occurred:</h3>";
            $report_description = "An unhandled exception occurred";
        }
        $report_description .= "\n" . $exception->getMessage();
        echo "<i>" . $exception->getMessage() . "</i><br>";
        if (class_exists("TBGContext") && TBGContext::isDebugMode()) {
            echo "<h3>Stack trace:</h3>\n\t\t\t\t\t<ul>";
            //echo '<pre>';var_dump($exception->getTrace());die();
            foreach ($exception->getTrace() as $trace_element) {
                echo '<li>';
                if (array_key_exists('class', $trace_element)) {
                    echo '<strong>' . $trace_element['class'] . $trace_element['type'] . $trace_element['function'] . '()</strong><br>';
                } elseif (array_key_exists('function', $trace_element)) {
                    if (!in_array($trace_element['function'], array('tbg_error_handler', 'tbg_exception'))) {
                        echo '<strong>' . $trace_element['function'] . '()</strong><br>';
                    }
                } else {
                    echo '<strong>unknown function</strong><br>';
                }
                if (array_key_exists('file', $trace_element)) {
                    echo '<span style="color: #55F;">' . $trace_element['file'] . '</span>, line ' . $trace_element['line'];
                } else {
                    echo '<span style="color: #C95;">unknown file</span>';
                }
                echo '</li>';
            }
            echo "</ul>";
        }
    } else {
        echo '<h3>';
        if ($exception['code'] == 8) {
            echo 'The following notice has stopped further execution:';
            $report_description = 'The following notice has stopped further execution: ';
        } else {
            echo 'The following error occured:';
            $report_description = 'The following error occured: ';
        }
        echo '</h3>';
        $report_description .= $title;
        echo "{$title}</i><br>\n\t\t\t\t<h3>Error information:</h3>\n\t\t\t\t<ul>\n\t\t\t\t\t<li>";
        echo '<span style="color: #55F;">' . $exception['file'] . '</span>, line ' . $exception['line'];
        echo "</li>\n\t\t\t\t</ul>";
        if (class_exists("TBGContext") && TBGContext::isDebugMode()) {
            echo "<h3>Backtrace:</h3>\n\t\t\t\t\t<ol>";
            foreach (debug_backtrace() as $trace_element) {
                echo '<li>';
                if (array_key_exists('class', $trace_element)) {
                    echo '<strong>' . $trace_element['class'] . $trace_element['type'] . $trace_element['function'] . '()</strong><br>';
                } elseif (array_key_exists('function', $trace_element)) {
                    if (in_array($trace_element['function'], array('tbg_error_handler', 'tbg_exception'))) {
                        continue;
                    }
                    echo '<strong>' . $trace_element['function'] . '()</strong><br>';
                } else {
                    echo '<strong>unknown function</strong><br>';
                }
                if (array_key_exists('file', $trace_element)) {
                    echo '<span style="color: #55F;">' . $trace_element['file'] . '</span>, line ' . $trace_element['line'];
                } else {
                    echo '<span style="color: #C95;">unknown file</span>';
                }
                echo '</li>';
            }
            echo "</ol>";
        }
    }
    if (class_exists("TBGContext") && TBGContext::isDebugMode()) {
        echo "<h3>Log messages:</h3>";
        foreach (TBGLogging::getEntries() as $entry) {
            $color = TBGLogging::getCategoryColor($entry['category']);
            $lname = TBGLogging::getLevelName($entry['level']);
            echo "<div class=\"log_{$entry['category']}\"><strong>{$lname}</strong> <strong style=\"color: #{$color}\">[{$entry['category']}]</strong> <span style=\"color: #555; font-size: 10px; font-style: italic;\">{$entry['time']}</span>&nbsp;&nbsp;{$entry['message']}</div>";
        }
    }
    if (class_exists("B2DB") && TBGContext::isDebugMode()) {
        echo "<h3>SQL queries:</h3>";
        try {
            echo "<ol>";
            foreach (B2DB::getSQLHits() as $details) {
                echo "<li>\n\t\t\t\t\t\t\t<b>\n\t\t\t\t\t\t\t<span class=\"faded_out dark small\">[";
                echo $details['time'] >= 1 ? round($details['time'], 2) . ' seconds' : round($details['time'] * 1000, 1) . 'ms';
                echo "]</span> </b> from <b>{$details['filename']}, line {$details['line']}</b>:<br>\n\t\t\t\t\t\t\t<span style=\"font-size: 12px;\">{$details['sql']}</span>\n\t\t\t\t\t\t</li>";
            }
            echo "</ol>";
        } catch (Exception $e) {
            echo '<span style="color: red;">Could not generate query list (there may be no database connection)</span>';
        }
    }
    echo "</div>\n\t\t\t<b class=\"xbottom\"><b class=\"xb4\"></b><b class=\"xb3\"></b><b class=\"xb2\"></b><b class=\"xb1\"></b></b>\n\t\t</div>";
    if (class_exists("TBGContext") && !TBGContext::isDebugMode()) {
        echo "<div style=\"text-align: left; margin: 35px auto 0 auto; width: 700px; font-size: 13px;\">\n\t\t\t\t<div class=\"rounded_box white\" style=\"margin-bottom: 10px; text-align: right; color: #111;\">\n\t\t\t\t\t<b class=\"xtop\"><b class=\"xb1\"></b><b class=\"xb2\"></b><b class=\"xb3\"></b><b class=\"xb4\"></b></b>\n\t\t\t\t\t<div class=\"xboxcontent\">\n\t\t\t\t\t\t<div style=\"text-align: left;\">\n\t\t\t\t\t\t\t<h2 style=\"padding-top: 10px; margin-bottom: 5px;\">Reporting this issue</h2>\n\t\t\t\t\t\t\tPlease report this error in the bug tracker by pressing the button below. This will file an automatic bug report and open it in a new window.<br><br>\n\t\t\t\t\t\t\tNo login is required - but if you have a username and password entering it below will post the issue with your username, allowing you to follow its progress.\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<br>\n\t\t\t\t\t\t<form action=\"http://thebuggenie.com/thebuggenie/thebuggenie/issues/new/bugreport\" target=\"_new\" method=\"post\">\n\t\t\t\t\t\t\t<label for=\"username\">Username <span>(optional)</span></label>\n\t\t\t\t\t\t\t<input type=\"text\" name=\"tbg3_username\" id=\"username\">\n\t\t\t\t\t\t\t<br style=\"clear: both;\">\n\t\t\t\t\t\t\t<label for=\"password\">Password <span>(optional)</span></label>\n\t\t\t\t\t\t\t<input type=\"password\" name=\"tbg3_password\" id=\"password\">\n\t\t\t\t\t\t\t<br>\n\t\t\t\t\t\t\t<input type=\"hidden\" name=\"category_id\" value=\"34\">\n\t\t\t\t\t\t\t<input type=\"hidden\" name=\"title\" value=\"" . htmlentities($title) . "\">\n\t\t\t\t\t\t\t<input type=\"hidden\" name=\"description\" value=\"" . htmlentities($report_description) . "\n\n\">";
        echo "<input type=\"hidden\" name=\"reproduction_steps\" value=\"PHP_SAPI: " . PHP_SAPI . "<br>PHP_VERSION: " . PHP_VERSION . "\n\n'''Backtrace''':<br>";
        if ($exception instanceof TBGException) {
            foreach ($exception->getTrace() as $trace_element) {
                if (array_key_exists('class', $trace_element)) {
                    echo "'''{$trace_element['class']}{$trace_element['type']}{$trace_element['function']}()'''\n";
                } elseif (array_key_exists('function', $trace_element)) {
                    if (in_array($trace_element['function'], array('tbg_error_handler', 'tbg_exception'))) {
                        continue;
                    }
                    echo "'''{$trace_element['function']}()'''\n";
                } else {
                    echo "'''unknown function'''\n";
                }
                if (array_key_exists('file', $trace_element)) {
                    echo 'in ' . str_replace(THEBUGGENIE_PATH, '<installpath>/', $trace_element['file']) . ', line ' . $trace_element['line'];
                } else {
                    echo 'in an unknown file';
                }
                echo "<br>";
            }
        } else {
            foreach (debug_backtrace() as $trace_element) {
                if (array_key_exists('class', $trace_element)) {
                    echo "'''{$trace_element['class']}{$trace_element['type']}{$trace_element['function']}()'''\n";
                } elseif (array_key_exists('function', $trace_element)) {
                    if (in_array($trace_element['function'], array('tbg_error_handler', 'tbg_exception'))) {
                        continue;
                    }
                    echo "'''{$trace_element['function']}()'''\n";
                } else {
                    echo "'''unknown function'''\n";
                }
                if (array_key_exists('file', $trace_element)) {
                    echo 'in ' . str_replace(THEBUGGENIE_PATH, '<installpath>/', $trace_element['file']) . ', line ' . $trace_element['line'];
                } else {
                    echo 'in an unknown file';
                }
                echo "<br>";
            }
        }
        echo "\n\n\">";
        echo "\t\t\t\t\t\n\t\t\t\t\t\t\t\t<input type=\"submit\" value=\"Submit details for reporting\" style=\"font-size: 16px; font-weight: normal; padding: 5px; margin: 10px 0;\">\n\t\t\t\t\t\t\t\t<div style=\"font-size: 15px; font-weight: bold; padding: 0 5px 10px 0;\">Thank you for helping us improve The Bug Genie!</div>\n\t\t\t\t\t\t\t</form>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<b class=\"xbottom\"><b class=\"xb4\"></b><b class=\"xb3\"></b><b class=\"xb2\"></b><b class=\"xb1\"></b></b>\n\t\t\t\t\t</div>";
        if (TBGLogging::isEnabled()) {
            echo "<h3 style=\"margin-top: 50px;\">Log messages (may contain useful information, but will not be submitted):</h3>";
            foreach (TBGLogging::getEntries() as $entry) {
                $color = TBGLogging::getCategoryColor($entry['category']);
                $lname = TBGLogging::getLevelName($entry['level']);
                echo "<div class=\"log_{$entry['category']}\"><strong>{$lname}</strong> <strong style=\"color: #{$color}\">[{$entry['category']}]</strong> <span style=\"color: #555; font-size: 10px; font-style: italic;\">{$entry['time']}</span>&nbsp;&nbsp;{$entry['message']}</div>";
            }
        }
    }
    echo "\n\t\t\t</div>\n\t\t</body>\n\t\t</html>\n\t\t";
    die;
}
 /**
  * Return the response object
  * 
  * @return TBGResponse
  */
 protected function getResponse()
 {
     return TBGContext::getResponse();
 }
 public function listen_headerBegins(TBGEvent $event)
 {
     if ($this->isOutgoingNotificationsEnabled() && TBGContext::getUser()->isGuest()) {
         TBGContext::getResponse()->addJavascript('forgot.js');
     }
 }