예제 #1
0
 /**
  * Configure general and server settings
  * 
  * @param TBGRequest $request The request object
  */
 public function runSettings(TBGRequest $request)
 {
     if (TBGContext::getRequest()->isMethod(TBGRequest::POST)) {
         $this->forward403unless($this->access_level == TBGSettings::ACCESS_FULL);
         $settings = array(TBGSettings::SETTING_THEME_NAME, TBGSettings::SETTING_ALLOW_USER_THEMES, TBGSettings::SETTING_ONLINESTATE, TBGSettings::SETTING_ENABLE_GRAVATARS, TBGSettings::SETTING_OFFLINESTATE, TBGSettings::SETTING_AWAYSTATE, TBGSettings::SETTING_AWAYSTATE, TBGSettings::SETTING_IS_SINGLE_PROJECT_TRACKER, TBGSettings::SETTING_REQUIRE_LOGIN, TBGSettings::SETTING_ALLOW_REGISTRATION, TBGSettings::SETTING_USER_GROUP, TBGSettings::SETTING_RETURN_FROM_LOGIN, TBGSettings::SETTING_RETURN_FROM_LOGOUT, TBGSettings::SETTING_IS_PERMISSIVE_MODE, TBGSettings::SETTING_REGISTRATION_DOMAIN_WHITELIST, TBGSettings::SETTING_SHOW_PROJECTS_OVERVIEW, TBGSettings::SETTING_KEEP_COMMENT_TRAIL_CLEAN, TBGSettings::SETTING_TBG_NAME, TBGSettings::SETTING_TBG_TAGLINE, TBGSettings::SETTING_DEFAULT_CHARSET, TBGSettings::SETTING_DEFAULT_LANGUAGE, TBGSettings::SETTING_SERVER_TIMEZONE, TBGSettings::SETTING_SYNTAX_HIGHLIGHT_DEFAULT_LANGUAGE, TBGSettings::SETTING_SYNTAX_HIGHLIGHT_DEFAULT_INTERVAL, TBGSettings::SETTING_SYNTAX_HIGHLIGHT_DEFAULT_NUMBERING, TBGSettings::SETTING_HEADER_ICON_TYPE, TBGSettings::SETTING_FAVICON_TYPE, TBGSettings::SETTING_HEADER_ICON_URL, TBGSettings::SETTING_FAVICON_URL, TBGSettings::SETTING_PREVIEW_COMMENT_IMAGES, TBGSettings::SETTING_HEADER_LINK);
         foreach ($settings as $setting) {
             if (TBGContext::getRequest()->getParameter($setting) !== null) {
                 $value = TBGContext::getRequest()->getParameter($setting);
                 switch ($setting) {
                     case TBGSettings::SETTING_TBG_NAME:
                     case TBGSettings::SETTING_TBG_TAGLINE:
                         $value = TBGContext::getRequest()->getParameter($setting, null, false);
                         break;
                     case TBGSettings::SETTING_SYNTAX_HIGHLIGHT_DEFAULT_INTERVAL:
                         if (!is_numeric($value) || $value < 1) {
                             $this->getResponse()->setHttpStatus(400);
                             return $this->renderJSON(array('failed' => true, 'error' => TBGContext::getI18n()->__('Please provide a valid setting for highlighting interval')));
                         }
                         break;
                     case TBGSettings::SETTING_DEFAULT_CHARSET:
                         TBGContext::loadLibrary('common');
                         if ($value && !tbg_check_syntax($value, "CHARSET")) {
                             $this->getResponse()->setHttpStatus(400);
                             return $this->renderJSON(array('failed' => true, 'error' => TBGContext::getI18n()->__('Please provide a valid setting for charset')));
                         }
                         break;
                 }
                 TBGSettings::saveSetting($setting, $value);
             }
         }
         return $this->renderJSON(array('failed' => false, 'title' => TBGContext::getI18n()->__('All settings saved')));
     }
 }
예제 #2
0
 public function postConfigSettings(framework\Request $request)
 {
     framework\Context::loadLibrary('common');
     $settings = array('smtp_host', 'smtp_port', 'smtp_user', 'smtp_pwd', 'smtp_encryption', 'timeout', 'mail_type', 'enable_outgoing_notifications', 'cli_mailing_url', 'headcharset', 'from_name', 'from_addr', 'use_queue', 'activation_needed', 'sendmail_command');
     foreach ($settings as $setting) {
         if ($request->getParameter($setting) !== null || $setting == 'no_dash_f' || $setting == 'activation_needed') {
             $value = $request->getParameter($setting);
             switch ($setting) {
                 case 'smtp_host':
                     if ($request['mail_type'] == self::MAIL_TYPE_SMTP && !tbg_check_syntax($value, "MAILSERVER")) {
                         throw new \Exception(framework\Context::getI18n()->__('Please provide a valid setting for SMTP server address'));
                     }
                     break;
                 case 'from_addr':
                     if (!tbg_check_syntax($value, "EMAIL")) {
                         throw new \Exception(framework\Context::getI18n()->__('Please provide a valid setting for email "from"-address'));
                     }
                     break;
                 case 'timeout':
                     if ($request['mail_type'] == self::MAIL_TYPE_SMTP && !is_numeric($value) || $value < 0) {
                         throw new \Exception(framework\Context::getI18n()->__('Please provide a valid setting for SMTP server timeout'));
                     }
                     break;
                 case 'smtp_port':
                     if ($request['mail_type'] == self::MAIL_TYPE_SMTP && !is_numeric($value) || $value < 1) {
                         throw new \Exception(framework\Context::getI18n()->__('Please provide a valid setting for SMTP server port'));
                     }
                     break;
                 case 'headcharset':
                     // list of supported character sets based on PHP doc : http://www.php.net/manual/en/function.htmlentities.php
                     if (!tbg_check_syntax($value, "CHARSET")) {
                         throw new \Exception(framework\Context::getI18n()->__('Please provide a valid setting for email header charset'));
                     }
                     break;
                 case 'activation_needed':
                     $value = (int) $request->getParameter($setting, 0);
                     break;
                 case 'cli_mailing_url':
                     $value = $request->getParameter($setting);
                     if (substr($value, -1) == '/') {
                         $value = substr($value, 0, strlen($value) - 1);
                     }
                     break;
             }
             $this->saveSetting($setting, $value);
         }
     }
 }
예제 #3
0
 /**
  * Configure general and server settings
  *
  * @param framework\Request $request The request object
  */
 public function runSettings(framework\Request $request)
 {
     if (framework\Context::getRequest()->isPost()) {
         $this->forward403unless($this->access_level == framework\Settings::ACCESS_FULL);
         $settings = array(framework\Settings::SETTING_USER_DISPLAYNAME_FORMAT, framework\Settings::SETTING_ENABLE_GRAVATARS, framework\Settings::SETTING_IS_SINGLE_PROJECT_TRACKER, framework\Settings::SETTING_REQUIRE_LOGIN, framework\Settings::SETTING_ALLOW_REGISTRATION, framework\Settings::SETTING_ALLOW_OPENID, framework\Settings::SETTING_USER_GROUP, framework\Settings::SETTING_RETURN_FROM_LOGIN, framework\Settings::SETTING_RETURN_FROM_LOGOUT, framework\Settings::SETTING_IS_PERMISSIVE_MODE, framework\Settings::SETTING_ALLOW_PERSONA, framework\Settings::SETTING_REGISTRATION_DOMAIN_WHITELIST, framework\Settings::SETTING_SHOW_PROJECTS_OVERVIEW, framework\Settings::SETTING_KEEP_COMMENT_TRAIL_CLEAN, framework\Settings::SETTING_TBG_NAME, framework\Settings::SETTING_TBG_NAME_HTML, framework\Settings::SETTING_DEFAULT_CHARSET, framework\Settings::SETTING_DEFAULT_LANGUAGE, framework\Settings::SETTING_SERVER_TIMEZONE, framework\Settings::SETTING_SYNTAX_HIGHLIGHT_DEFAULT_LANGUAGE, framework\Settings::SETTING_SYNTAX_HIGHLIGHT_DEFAULT_INTERVAL, framework\Settings::SETTING_SYNTAX_HIGHLIGHT_DEFAULT_NUMBERING, framework\Settings::SETTING_PREVIEW_COMMENT_IMAGES, framework\Settings::SETTING_HEADER_LINK, framework\Settings::SETTING_MAINTENANCE_MESSAGE, framework\Settings::SETTING_MAINTENANCE_MODE, framework\Settings::SETTING_ELEVATED_LOGIN_DISABLED, framework\Settings::SETTING_NOTIFICATION_POLL_INTERVAL);
         foreach ($settings as $setting) {
             if (framework\Context::getRequest()->getParameter($setting) !== null) {
                 $value = framework\Context::getRequest()->getParameter($setting);
                 switch ($setting) {
                     case framework\Settings::SETTING_TBG_NAME:
                         $value = framework\Context::getRequest()->getParameter($setting, null, false);
                         break;
                     case framework\Settings::SETTING_SYNTAX_HIGHLIGHT_DEFAULT_INTERVAL:
                         if (!is_numeric($value) || $value < 1) {
                             $this->getResponse()->setHttpStatus(400);
                             return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Please provide a valid setting for highlighting interval')));
                         }
                         break;
                     case framework\Settings::SETTING_DEFAULT_CHARSET:
                         framework\Context::loadLibrary('common');
                         if ($value && !tbg_check_syntax($value, "CHARSET")) {
                             $this->getResponse()->setHttpStatus(400);
                             return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Please provide a valid setting for charset')));
                         }
                         break;
                     case framework\Settings::SETTING_NOTIFICATION_POLL_INTERVAL:
                         if (!ctype_digit($value)) {
                             $this->getResponse()->setHttpStatus(400);
                             return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Please provide a valid setting for notification poll interval')));
                         }
                 }
                 framework\Settings::saveSetting($setting, $value);
             }
         }
         return $this->renderJSON(array('title' => framework\Context::getI18n()->__('All settings saved')));
     }
 }
예제 #4
0
 /**
  * Registration logic
  *
  * @Route(name="register", url="/do/register")
  * @AnonymousRoute
  *
  * @param \thebuggenie\core\framework\Request $request
  */
 public function runRegister(framework\Request $request)
 {
     framework\Context::loadLibrary('common');
     $i18n = framework\Context::getI18n();
     $fields = array();
     try {
         $username = mb_strtolower(trim($request['fieldusername']));
         $buddyname = $request['buddyname'];
         $email = mb_strtolower(trim($request['email_address']));
         $confirmemail = mb_strtolower(trim($request['email_confirm']));
         $security = $request['verification_no'];
         $realname = $request['realname'];
         $available = tables\Users::getTable()->isUsernameAvailable($username);
         if (!$available) {
             throw new \Exception($i18n->__('This username is in use'));
         }
         if (!empty($buddyname) && !empty($email) && !empty($confirmemail) && !empty($security)) {
             if ($email != $confirmemail) {
                 array_push($fields, 'email_address', 'email_confirm');
                 throw new \Exception($i18n->__('The email address must be valid, and must be typed twice.'));
             }
             if ($security != $_SESSION['activation_number']) {
                 array_push($fields, 'verification_no');
                 throw new \Exception($i18n->__('To prevent automatic sign-ups, enter the verification number shown below.'));
             }
             $email_ok = false;
             if (tbg_check_syntax($email, "EMAIL")) {
                 $email_ok = true;
             }
             if ($email_ok && framework\Settings::get('limit_registration') != '') {
                 $allowed_domains = preg_replace('/[[:space:]]*,[[:space:]]*/', '|', framework\Settings::get('limit_registration'));
                 if (preg_match('/@(' . $allowed_domains . ')$/i', $email) == false) {
                     array_push($fields, 'email_address', 'email_confirm');
                     throw new \Exception($i18n->__('Email adresses from this domain can not be used.'));
                 }
             }
             if ($email_ok == false) {
                 array_push($fields, 'email_address', 'email_confirm');
                 throw new \Exception($i18n->__('The email address must be valid, and must be typed twice.'));
             }
             if ($security != $_SESSION['activation_number']) {
                 array_push($fields, 'verification_no');
                 throw new \Exception($i18n->__('To prevent automatic sign-ups, enter the verification number shown below.'));
             }
             $password = entities\User::createPassword();
             $user = new entities\User();
             $user->setUsername($username);
             $user->setRealname($realname);
             $user->setBuddyname($buddyname);
             $user->setGroup(framework\Settings::getDefaultGroup());
             $user->setEnabled();
             $user->setPassword($password);
             $user->setEmail($email);
             $user->setJoined();
             $user->save();
             $_SESSION['activation_number'] = tbg_printRandomNumber();
             if ($user->isActivated()) {
                 framework\Context::setMessage('auto_password', $password);
                 return $this->renderJSON(array('loginmessage' => $i18n->__('After pressing %continue, you need to set your password.', array('%continue' => $i18n->__('Continue'))), 'one_time_password' => $password, 'activated' => true));
             }
             return $this->renderJSON(array('loginmessage' => $i18n->__('The account has now been registered - check your email inbox for the activation email. Please be patient - this email can take up to two hours to arrive.'), 'activated' => false));
         } else {
             array_push($fields, 'email_address', 'email_confirm', 'buddyname', 'verification_no');
             throw new \Exception($i18n->__('You need to fill out all fields correctly.'));
         }
     } catch (\Exception $e) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('error' => $i18n->__($e->getMessage()), 'fields' => $fields));
     }
 }
예제 #5
0
 public function postConfigSettings(TBGRequest $request)
 {
     TBGContext::loadLibrary('common');
     $settings = array('smtp_host', 'smtp_port', 'smtp_user', 'timeout', 'mail_type', 'enable_outgoing_notifications', 'smtp_pwd', 'headcharset', 'from_name', 'from_addr', 'ehlo', 'use_queue', 'no_dash_f');
     foreach ($settings as $setting) {
         if ($request->getParameter($setting) !== null || ($setting = 'no_dash_f')) {
             $value = $request->getParameter($setting);
             $dns_regex = '(\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b|(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\]))';
             $mail_regex = '(?:[a-z0-9!#$%&\'*+\\/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&\'*+\\/=?^_`{|}~-]+)*|"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*")@';
             switch ($setting) {
                 case 'smtp_host':
                     if ($request->getParameter('mail_type') == TBGMailer::MAIL_TYPE_B2M && !tbg_check_syntax($value, "MAILSERVER")) {
                         throw new Exception(TBGContext::getI18n()->__('Please provide a valid setting for SMTP server address'));
                     }
                     break;
                 case 'from_addr':
                     if (!tbg_check_syntax($value, "EMAIL")) {
                         throw new Exception(TBGContext::getI18n()->__('Please provide a valid setting for email "from"-address'));
                     }
                     break;
                 case 'timeout':
                     if ($request->getParameter('mail_type') == TBGMailer::MAIL_TYPE_B2M && !is_numeric($value) || $value < 0) {
                         throw new Exception(TBGContext::getI18n()->__('Please provide a valid setting for SMTP server timeout'));
                     }
                     break;
                 case 'smtp_port':
                     if ($request->getParameter('mail_type') == TBGMailer::MAIL_TYPE_B2M && !is_numeric($value) || $value < 1) {
                         throw new Exception(TBGContext::getI18n()->__('Please provide a valid setting for SMTP server port'));
                     }
                     break;
                 case 'headcharset':
                     // list of supported character sets based on PHP doc : http://www.php.net/manual/en/function.htmlentities.php
                     if (!tbg_check_syntax($value, "CHARSET")) {
                         throw new Exception(TBGContext::getI18n()->__('Please provide a valid setting for email header charset'));
                     }
                     break;
                 case 'no_dash_f':
                     $value = (int) $request->getParameter($setting, 0);
                     break;
             }
             $this->saveSetting($setting, $value);
         }
     }
 }
예제 #6
0
 /**
  * Registration logic part 2 - add user data
  *  
  * @param TBGRequest $request
  */
 public function runRegister2(TBGRequest $request)
 {
     TBGContext::loadLibrary('common');
     $i18n = TBGContext::getI18n();
     try {
         $username = $request->getParameter('username');
         $buddyname = $request->getParameter('buddyname');
         $email = $request->getParameter('email_address');
         $confirmemail = $request->getParameter('email_confirm');
         $security = $request->getParameter('verification_no');
         $realname = $request->getParameter('realname');
         $fields = array();
         if (!empty($buddyname) && !empty($email) && !empty($confirmemail) && !empty($security)) {
             if ($email != $confirmemail) {
                 array_push($fields, 'email_address', 'email_confirm');
                 throw new Exception($i18n->__('The email address must be valid, and must be typed twice.'));
             }
             if ($security != $_SESSION['activation_number']) {
                 array_push($fields, 'verification_no');
                 throw new Exception($i18n->__('To prevent automatic sign-ups, enter the verification number shown below.'));
             }
             $email_ok = false;
             $valid_domain = false;
             if (tbg_check_syntax($email, "EMAIL")) {
                 $email_ok = true;
             }
             if ($email_ok && TBGSettings::get('limit_registration') != '') {
                 $allowed_domains = preg_replace('/[[:space:]]*,[[:space:]]*/', '|', TBGSettings::get('limit_registration'));
                 if (preg_match('/@(' . $allowed_domains . ')$/i', $email) == false) {
                     array_push($fields, 'email_address', 'email_confirm');
                     throw new Exception($i18n->__('Email adresses from this domain can not be used.'));
                 }
                 /*if (count($allowed_domains) > 0)
                 		{
                 			foreach ($allowed_domains as $allowed_domain)
                 			{
                 				$allowed_domain = '@' . trim($allowed_domain);
                 				if (strpos($email, $allowed_domain) !== false ) //strpos checks if $to
                 				{
                 					$valid_domain = true;
                 					break;
                 				}
                 			}
                 			
                 		}
                 		else
                 		{
                 			$valid_domain = true;
                 		}*/
             }
             /*if ($valid_domain == false)
             		{
             			array_push($fields, 'email_address', 'email_confirm');					
             			throw new Exception($i18n->__('Email adresses from this domain can not be used.'));
             		}*/
             if ($email_ok == false) {
                 array_push($fields, 'email_address', 'email_confirm');
                 throw new Exception($i18n->__('The email address must be valid, and must be typed twice.'));
             }
             if ($security != $_SESSION['activation_number']) {
                 array_push($fields, 'verification_no');
                 throw new Exception($i18n->__('To prevent automatic sign-ups, enter the verification number shown below.'));
             }
             $password = TBGUser::createPassword();
             $user = new TBGUser();
             $user->setUsername($username);
             $user->setRealname($realname);
             $user->setBuddyname($buddyname);
             $user->setGroup(TBGSettings::getDefaultGroup());
             $user->setEnabled();
             $user->setPassword($password);
             $user->setEmail($email);
             $user->setJoined();
             $user->save();
             if ($user->isActivated()) {
                 return $this->renderJSON(array('message' => $i18n->__('A password has been autogenerated for you. To log in, use the following password:'******' <b>' . $password . '</b>'));
             }
             return $this->renderJSON(array('message' => $i18n->__('The account has now been registered - check your email inbox for the activation email. Please be patient - this email can take up to two hours to arrive.')));
         } else {
             array_push($fields, 'email_address', 'email_confirm', 'buddyname', 'verification_no');
             throw new Exception($i18n->__('You need to fill out all fields correctly.'));
         }
     } catch (Exception $e) {
         return $this->renderJSON(array('failed' => true, 'error' => $i18n->__($e->getMessage()), 'fields' => $fields));
     }
 }