Example #1
0
 public function Connect()
 {
     $connected = false;
     $attempts = 0;
     $hosts = $this->options->Controllers();
     $options = $this->options->AdLdapOptions();
     while (!$connected && $attempts < count($hosts)) {
         try {
             $host = $hosts[$attempts];
             Log::Debug('ActiveDirectory - Trying to connect to host %s', $host);
             $options['domain_controllers'] = array($host);
             $attempts++;
             $this->ldap = new adLdap($options);
             $connected = true;
             if ($connected) {
                 Log::Debug('ActiveDirectory - Connection succeeded to host %s', $host);
             } else {
                 Log::Debug('ActiveDirectory - Connection failed to host %s. Reason %s', $host, $this->ldap->getLastError());
             }
         } catch (adLDAPException $ex) {
             Log::Error($ex);
             throw $ex;
         }
     }
     return $connected;
 }
Example #2
0
 public static function Handle($exception)
 {
     Log::Error('Uncaught exception: %s', $exception);
     if (isset(self::$handler)) {
         self::$handler->HandleException($exception);
     }
 }
 private function TryPageLoad($currentUser)
 {
     $fileId = $this->page->GetFileId();
     $referenceNumber = $this->page->GetReferenceNumber();
     Log::Debug('Trying to load reservation attachment. FileId: %s, ReferenceNumber %s', $fileId, $referenceNumber);
     $attachment = $this->reservationRepository->LoadReservationAttachment($fileId);
     if ($attachment == null) {
         Log::Error('Error loading resource attachment, attachment not found');
         return false;
     }
     $reservation = $this->reservationRepository->LoadByReferenceNumber($referenceNumber);
     if ($reservation == null) {
         Log::Error('Error loading resource attachment, reservation not found');
         return false;
     }
     if ($reservation->SeriesId() != $attachment->SeriesId()) {
         Log::Error('Error loading resource attachment, attachment not associated with reservation');
         return false;
     }
     if (!$this->permissionService->CanAccessResource(new ReservationResource($reservation->ResourceId()), $currentUser)) {
         Log::Error('Error loading resource attachment, insufficient permissions');
         return false;
     }
     return $attachment;
 }
Example #4
0
 public function UpdateTheme()
 {
     $logoFile = $this->page->GetLogoFile();
     $cssFile = $this->page->GetCssFile();
     if ($logoFile != null) {
         Log::Debug('Replacing logo with ' . $logoFile->OriginalName());
         $targets = glob(ROOT_DIR . 'Web/img/custom-logo.*');
         foreach ($targets as $target) {
             $removed = unlink($target);
             if (!$removed) {
                 Log::Error('Could not remove existing logo. Ensure %s is writable.', $target);
             }
         }
         $target = ROOT_DIR . 'Web/img/custom-logo.' . $logoFile->Extension();
         $copied = copy($logoFile->TemporaryName(), $target);
         if (!$copied) {
             Log::Error('Could not replace logo with %s. Ensure %s is writable.', $logoFile->OriginalName(), $target);
         }
     }
     if ($cssFile != null) {
         Log::Debug('Replacing css file with ' . $cssFile->OriginalName());
         $target = ROOT_DIR . 'Web/css/custom-style.css';
         $copied = copy($cssFile->TemporaryName(), $target);
         if (!$copied) {
             Log::Error('Could not replace css with %s. Ensure %s is writable.', $cssFile->OriginalName(), $target);
         }
     }
 }
Example #5
0
 /**
  * @param $fullPath string
  * @return void
  */
 public function RemoveFile($fullPath)
 {
     Log::Debug('Deleting file: %s', $fullPath);
     if (unlink($fullPath) === false) {
         Log::Error('Could not delete file: %s', $fullPath);
     }
 }
Example #6
0
 public function ProcessAction()
 {
     try {
         parent::ProcessAction();
     } catch (Exception $ex) {
         Log::Error('Error getting report: %s', $ex);
         $this->page->DisplayError();
     }
 }
Example #7
0
 public static function EnsureCommandLine()
 {
     try {
         if (array_key_exists('REQUEST_METHOD', $_SERVER)) {
             die('This can only be accessed via the command line');
         }
     } catch (Exception $ex) {
         Log::Error('Error in JobCop->EnsureCommandLine: %s', $ex);
     }
 }
Example #8
0
 public function Validate($username, $password)
 {
     try {
         phpCAS::forceAuthentication();
     } catch (Exception $ex) {
         Log::Error('CAS exception: %s', $ex);
         return false;
     }
     return true;
 }
 public function ProcessPageLoad()
 {
     $this->Set('EnableCaptcha', Configuration::Instance()->GetKey(ConfigKeys::REGISTRATION_ENABLE_CAPTCHA, new BooleanConverter()));
     try {
         $this->_presenter->PageLoad();
         $this->Display('register.tpl');
     } catch (Exception $ex) {
         $this->Set('PageLoadException', true);
         Log::Error('Error loading registration page %s', $ex);
     }
 }
 /**
  * @param $reservationSeries ReservationSeries|ExistingReservationSeries
  * @return void
  */
 public function Notify($reservationSeries)
 {
     $referenceNumber = $reservationSeries->CurrentInstance()->ReferenceNumber();
     foreach ($this->notifications as $notification) {
         try {
             Log::Debug("Calling notify on %s for reservation %s", get_class($notification), $referenceNumber);
             $notification->Notify($reservationSeries);
         } catch (Exception $ex) {
             Log::Error("Error sending notification of type %s for reservation %s. Exception: %s", get_class($notification), $referenceNumber, $ex);
         }
     }
 }
Example #11
0
 public function __call($func, $args)
 {
     if ($this->redis_ && method_exists($this->redis_, $func)) {
         $r = new RunTimeUtil();
         $ret = call_user_func_array(array($this->redis_, $func), $args);
         $time = $r->spent();
         Log::Info('cache', "#method:{$func}#args:" . json_encode($args) . "#ret:" . json_encode($ret) . "#runtime:{$time}");
         return $ret;
     } else {
         Log::Error('cache', "#method{$func}#args" . json_encode($args) . "#message:no funcs or client is null");
         return null;
     }
 }
Example #12
0
 public final function __call($func, $args)
 {
     if ($this->_medoo && method_exists($this->_medoo, $func)) {
         $r = new RunTimeUtil();
         $ret = call_user_func_array(array($this->_medoo, $func), $args);
         $time = $r->spent();
         $logs = $this->_medoo->log();
         Log::Info('db', "#method:{$func}#sql:" . end($logs) . "#ret:" . json_encode($ret) . "#runtime:{$time}");
         return $ret;
     } else {
         Log::Error('db', "#method{$func}#args" . json_encode($args) . "#message:no funcs or client is null");
         return null;
     }
 }
 public function RemoveLogo()
 {
     try {
         $targets = glob(ROOT_DIR . 'Web/img/custom-logo.*');
         foreach ($targets as $target) {
             $removed = unlink($target);
             if (!$removed) {
                 Log::Error('Could not remove existing logo. Ensure %s is writable.', $target);
             }
         }
     } catch (Exception $ex) {
         Log::Error('Could not remove logos. %s', $ex);
     }
 }
 public function Validate($username, $password)
 {
     try {
         if ($_GET["doCAS"] == 1) {
             phpCAS::forceAuthentication();
         } else {
             return parent::Validate($username, $password);
         }
     } catch (Exception $ex) {
         Log::Error('CAS exception: %s', $ex);
         return false;
     }
     return true;
 }
Example #15
0
 public function Flush()
 {
     try {
         $dirName = $this->GetDirectory();
         $cacheDir = opendir($dirName);
         while (false !== ($file = readdir($cacheDir))) {
             if ($file != "." && $file != "..") {
                 unlink($dirName . $file);
             }
         }
         closedir($cacheDir);
     } catch (Exception $ex) {
         Log::Error('Could not flush template cache directory: %s', $ex);
     }
 }
 public function PageLoad()
 {
     try {
         $reservationAction = ReservationAction::Approve;
         $factory = new ReservationPersistenceFactory();
         $persistenceService = $factory->Create($reservationAction);
         $handler = ReservationHandler::Create($reservationAction, $persistenceService, ServiceLocator::GetServer()->GetUserSession());
         $auth = new ReservationAuthorization(PluginManager::Instance()->LoadAuthorization());
         $presenter = new ReservationApprovalPresenter($this, $persistenceService, $handler, $auth, ServiceLocator::GetServer()->GetUserSession());
         $presenter->PageLoad();
     } catch (Exception $ex) {
         Log::Error('ReservationApprovalPage - Critical error saving reservation: %s', $ex);
         $this->Display('Ajax/reservation/reservation_error.tpl');
     }
 }
Example #17
0
 public function PageLoad()
 {
     try {
         $reservation = $this->_presenter->BuildReservation();
         $this->_presenter->HandleReservation($reservation);
         if ($this->_reservationSavedSuccessfully) {
             $this->Display('Ajax/reservation/update_successful.tpl');
         } else {
             $this->Display('Ajax/reservation/save_failed.tpl');
         }
     } catch (Exception $ex) {
         Log::Error('ReservationUpdatePage - Critical error saving reservation: %s', $ex);
         $this->Display('Ajax/reservation/reservation_error.tpl');
     }
 }
Example #18
0
 public function PageLoad()
 {
     try {
         if ($this->TakingAction()) {
             $this->ProcessAction();
         } else {
             if ($this->RequestingData()) {
                 $this->ProcessDataRequest($this->GetDataRequest());
             } else {
                 $this->ProcessPageLoad();
             }
         }
     } catch (Exception $ex) {
         Log::Error('Error loading page. %s', $ex);
         throw $ex;
     }
 }
Example #19
0
 public function PageLoad()
 {
     try {
         $reservation = $this->_presenter->BuildReservation();
         $this->_presenter->HandleReservation($reservation);
         if ($this->_reservationSavedSuccessfully) {
             $this->Set('Resources', $reservation->AllResources());
             $this->Set('Instances', $reservation->Instances());
             $this->Set('Timezone', ServiceLocator::GetServer()->GetUserSession()->Timezone);
             $this->Display('Ajax/reservation/update_successful.tpl');
         } else {
             $this->Display('Ajax/reservation/save_failed.tpl');
         }
     } catch (Exception $ex) {
         Log::Error('ReservationUpdatePage - Critical error saving reservation: %s', $ex);
         $this->Display('Ajax/reservation/reservation_error.tpl');
     }
 }
Example #20
0
 public static function enforceMake($name, $cache = false)
 {
     $name = strtolower($name);
     if (!($service = Dependency::getService($name))) {
         Log::Error("The service \"{$name}\" dose not exist!");
         throw new \Exception("The service \"{$name}\" dose not exist!", 1);
     }
     if (!class_exists($service)) {
         Log::Error("Class \" {$service}\" dose not exist!");
         throw new \Exception("Class \" {$service}\" dose not exist!", 1);
     }
     $reflectClass = new \ReflectionClass($name);
     $instance = $reflectClass->newInstanceWithoutConstructor();
     if ($cache) {
         self::$wareHouse[$name] = $instance;
     }
     return $instance;
 }
Example #21
0
 public function GetLayout(Date $date, $resourceId)
 {
     try {
         $hideBlocked = Configuration::Instance()->GetSectionKey(ConfigSection::SCHEDULE, ConfigKeys::SCHEDULE_HIDE_BLOCKED_PERIODS, new BooleanConverter());
         $sw = new StopWatch();
         $sw->Start();
         $items = $this->_reservationListing->OnDateForResource($date, $resourceId);
         $sw->Record('listing');
         $list = new ScheduleReservationList($items, $this->_scheduleLayout, $date, $hideBlocked);
         $slots = $list->BuildSlots();
         $sw->Record('slots');
         $sw->Stop();
         Log::Debug('DailyLayout::GetLayout - For resourceId %s on date %s, took %s seconds to get reservation listing, %s to build the slots, %s total seconds for %s reservations. Memory consumed=%sMB', $resourceId, $date->ToString(), $sw->GetRecordSeconds('listing'), $sw->TimeBetween('slots', 'listing'), $sw->GetTotalSeconds(), count($items), round(memory_get_usage() / 1048576, 2));
         return $slots;
     } catch (Exception $ex) {
         Log::Error('Error getting layout on date %s for resourceId %s. Exception=%s', $date->ToString(), $resourceId, $ex);
         throw $ex;
     }
 }
Example #22
0
 public function ProcessAction()
 {
     /** @var $action string */
     $action = $this->actionPage->GetAction();
     if ($this->ActionIsKnown($action)) {
         $method = $this->actions[$action];
         try {
             $this->LoadValidators($action);
             if ($this->actionPage->IsValid()) {
                 Log::Debug("Processing page action. Action %s", $action);
                 $this->{$method}();
             }
         } catch (Exception $ex) {
             Log::Error("ProcessAction Error. Action %s, Error %s", $action, $ex);
         }
     } else {
         Log::Error("Unknown action %s", $action);
     }
 }
Example #23
0
 public function Send(IEmailMessage $emailMessage)
 {
     $this->phpMailer->ClearAllRecipients();
     $this->phpMailer->ClearReplyTos();
     $this->phpMailer->CharSet = $emailMessage->Charset();
     $this->phpMailer->Subject = $emailMessage->Subject();
     $this->phpMailer->Body = $emailMessage->Body();
     $from = $emailMessage->From();
     $defaultFrom = Configuration::Instance()->GetSectionKey(ConfigSection::EMAIL, ConfigKeys::DEFAULT_FROM_ADDRESS);
     $defaultName = Configuration::Instance()->GetSectionKey(ConfigSection::EMAIL, ConfigKeys::DEFAULT_FROM_NAME);
     $address = empty($defaultFrom) ? $from->Address() : $defaultFrom;
     $name = empty($defaultName) ? $from->Name() : $defaultName;
     $this->phpMailer->SetFrom($address, $name);
     $replyTo = $emailMessage->ReplyTo();
     $this->phpMailer->AddReplyTo($replyTo->Address(), $replyTo->Name());
     $to = $this->ensureArray($emailMessage->To());
     $toAddresses = new StringBuilder();
     foreach ($to as $address) {
         $toAddresses->Append($address->Address());
         $this->phpMailer->AddAddress($address->Address(), $address->Name());
     }
     $cc = $this->ensureArray($emailMessage->CC());
     foreach ($cc as $address) {
         $this->phpMailer->AddCC($address->Address(), $address->Name());
     }
     $bcc = $this->ensureArray($emailMessage->BCC());
     foreach ($bcc as $address) {
         $this->phpMailer->AddBCC($address->Address(), $address->Name());
     }
     if ($emailMessage->HasStringAttachment()) {
         Log::Debug('Adding email attachment %s', $emailMessage->AttachmentFileName());
         $this->phpMailer->AddStringAttachment($emailMessage->AttachmentContents(), $emailMessage->AttachmentFileName());
     }
     Log::Debug('Sending %s email to: %s from: %s', get_class($emailMessage), $toAddresses->ToString(), $from->Address());
     $success = false;
     try {
         $success = $this->phpMailer->Send();
     } catch (Exception $ex) {
         Log::Error('Failed sending email. Exception: %s', $ex);
     }
     Log::Debug('Email send success: %d. %s', $success, $this->phpMailer->ErrorInfo);
 }
Example #24
0
 /**
  * @return void
  */
 public function Validate()
 {
     try {
         $this->isValid = true;
         $days = array(null);
         if (!$this->validateSingle) {
             Log::Debug('Validating daily layout');
             Log::Debug(var_export($this->reservableSlots, true));
             if (count($this->reservableSlots) != DayOfWeek::NumberOfDays || count($this->blockedSlots) != DayOfWeek::NumberOfDays) {
                 $this->isValid = false;
                 return;
             }
             $layout = ScheduleLayout::ParseDaily('UTC', $this->reservableSlots, $this->blockedSlots);
             $days = DayOfWeek::Days();
         } else {
             Log::Debug('Validating single layout');
             $layout = ScheduleLayout::Parse('UTC', $this->reservableSlots, $this->blockedSlots);
         }
         foreach ($days as $day) {
             if (is_null($day)) {
                 $day = 0;
             }
             $slots = $layout->GetLayout(Date::Now()->AddDays($day)->ToUtc());
             /** @var $firstDate Date */
             $firstDate = $slots[0]->BeginDate();
             /** @var $lastDate Date */
             $lastDate = $slots[count($slots) - 1]->EndDate();
             if (!$firstDate->IsMidnight() || !$lastDate->IsMidnight()) {
                 Log::Debug('Dates are not midnight');
                 $this->isValid = false;
             }
             for ($i = 0; $i < count($slots) - 1; $i++) {
                 if (!$slots[$i]->EndDate()->Equals($slots[$i + 1]->BeginDate())) {
                     $this->isValid = false;
                 }
             }
         }
     } catch (Exception $ex) {
         Log::Error('Error during LayoutValidator', $ex);
         $this->isValid = false;
     }
 }
Example #25
0
 protected function AddItem(ReservationListItem $item)
 {
     $currentDate = $item->StartDate()->ToTimezone($this->timezone);
     $lastDate = $item->EndDate()->ToTimezone($this->timezone);
     if ($currentDate->GreaterThan($lastDate)) {
         Log::Error("Reservation dates corrupted. ReferenceNumber=%s, Start=%s, End=%s", $item->ReferenceNumber(), $item->StartDate(), $item->EndDate());
         return;
     }
     if ($currentDate->DateEquals($lastDate)) {
         $this->AddOnDate($item, $currentDate);
     } else {
         while ($currentDate->LessThan($lastDate) && !$currentDate->DateEquals($lastDate)) {
             $this->AddOnDate($item, $currentDate);
             $currentDate = $currentDate->AddDays(1);
         }
         if (!$lastDate->IsMidnight()) {
             $this->AddOnDate($item, $lastDate);
         }
     }
     $this->_reservations[] = $item;
     $this->_reservationByResource[$item->ResourceId()][] = $item;
 }
Example #26
0
 /**
  * Default Constructor
  *
  * Instantiate an instance of the SimpleSAML_Auth_Simple class
  * and call requireAuth() to validate a user
  *
  * @param array $options Array of options to pass to the constructor
  *
  */
 function __construct($options = array())
 {
     // Auto load  libraries and
     // obtain simple SAML SP configuration data
     $this->samlLib = $options["ssphp_lib"];
     $this->samlConfig = $options["ssphp_config"];
     require_once $this->samlLib . '/lib/_autoload.php';
     SimpleSAML_Configuration::init($this->samlConfig);
     // You can specifically overide any of the default configuration options setup above
     if (count($options) > 0) {
         if (array_key_exists("ssphp_sp", $options)) {
             $this->ssphpSP = $options["ssphp_sp"];
         } else {
             Log::Error("Could not connect to SAML service provider." . "  Please check your SAML configuration settings");
         }
     }
     $this->authSimple = new SimpleSAML_Auth_Simple($this->ssphpSP);
     // requireAuth() redirects user to SSO login page
     // where user needs to enter SSO username and password.
     // If user is not validated, then this function does not return
     $this->authSimple->requireAuth();
 }
Example #27
0
 public function Validate($username, $password)
 {
     Log::Debug('Attempting to authenticate user against WordPress. User=%s', $username);
     $user = wp_authenticate($username, $password);
     if (is_wp_error($user)) {
         Log::Error('WordPress authentication error: %s', $user->get_error_message());
         return false;
     }
     if ($user->exists()) {
         Log::Debug('WordPress authentication successful. User=%s', $username);
         $this->user = $user;
         $this->password = $password;
         return true;
     } else {
         Log::Debug('WordPress authentication failed. User=%s', $username);
         if ($this->options->RetryAgainstDatabase()) {
             Log::Debug('WordPress authentication retrying against database');
             return $this->authToDecorate->Validate($username, $password);
         }
     }
     return false;
 }
Example #28
0
 /**
  * @param string $configKey key to use
  * @param string $pluginSubDirectory subdirectory name under 'plugins'
  * @param mixed $baseImplementation the base implementation of the plugin.  allows decorating
  * @return mixed|null plugin implementation
  */
 private function LoadPlugin($configKey, $pluginSubDirectory, $baseImplementation)
 {
     if (!$this->Cached($configKey)) {
         $plugin = Configuration::Instance()->GetSectionKey(ConfigSection::PLUGINS, $configKey);
         $pluginFile = ROOT_DIR . "plugins/{$pluginSubDirectory}/{$plugin}/{$plugin}.php";
         if (!empty($plugin) && file_exists($pluginFile)) {
             try {
                 Log::Debug('Loading plugin. Type=%s, Plugin=%s', $configKey, $plugin);
                 require_once $pluginFile;
                 $this->Cache($configKey, new $plugin($baseImplementation));
             } catch (Exception $ex) {
                 Log::Error('Error loading plugin. Type=%s, Plugin=%s', $configKey, $plugin);
             }
         } else {
             $this->Cache($configKey, null);
         }
     }
     return $this->GetCached($configKey);
 }
Example #29
0
 /**
  * @param $username string
  * @param $configFilter string
  * @return void
  */
 private function PopulateUser($username, $configFilter)
 {
     $uidAttribute = $this->options->GetUserIdAttribute();
     Log::Debug('LDAP - uid attribute: %s', $uidAttribute);
     $RequiredGroup = $this->options->GetRequiredGroup();
     $filter = Net_LDAP2_Filter::create($uidAttribute, 'equals', $username);
     if ($configFilter) {
         $configFilter = Net_LDAP2_Filter::parse($configFilter);
         if (Net_LDAP2::isError($configFilter)) {
             $message = 'Could not parse search filter %s: ' . $configFilter->getMessage();
             Log::Error($message, $username);
         }
         $filter = Net_LDAP2_Filter::combine('and', array($filter, $configFilter));
     }
     $attributes = $this->options->Attributes();
     Log::Debug('LDAP - Loading user attributes: %s', implode(', ', $attributes));
     $options = array('attributes' => $attributes);
     Log::Debug('Searching ldap for user %s', $username);
     $searchResult = $this->ldap->search(null, $filter, $options);
     if (Net_LDAP2::isError($searchResult)) {
         $message = 'Could not search ldap for user %s: ' . $searchResult->getMessage();
         Log::Error($message, $username);
     }
     $currentResult = $searchResult->current();
     if ($searchResult->count() == 1 && $currentResult !== false) {
         Log::Debug('Found user %s', $username);
         if (!empty($RequiredGroup)) {
             Log::Debug('LDAP - Required Group: %s', $RequiredGroup);
             $group_filter = Net_LDAP2_Filter::create('uniquemember', 'equals', $currentResult->dn());
             $group_searchResult = $this->ldap->search($RequiredGroup, $group_filter, null);
             if (Net_LDAP2::isError($group_searchResult) && !empty($RequiredGroup)) {
                 $message = 'Could not match Required Group %s: ' . $group_searchResult->getMessage();
                 Log::Error($message, $username);
             }
             if ($group_searchResult->count() == 1 && $group_searchResult !== false) {
                 Log::Debug('Matched Required Group %s', $RequiredGroup);
                 /** @var Net_LDAP2_Entry $entry  */
                 $this->user = new LdapUser($currentResult, $this->options->AttributeMapping());
             }
         } else {
             /** @var Net_LDAP2_Entry $entry  */
             $this->user = new LdapUser($currentResult, $this->options->AttributeMapping());
         }
     } else {
         Log::Debug('Could not find user %s', $username);
     }
 }
Example #30
0
 public function Validate($username, $password)
 {
     $this->password = $password;
     $username = $this->CleanUsername($username);
     $connected = $this->ldap->Connect();
     if (!$connected) {
         throw new Exception('Could not connect to ActiveDirectory LDAP server. Please check your ActiveDirectory LDAP configuration settings');
     }
     $isValid = $this->ldap->Authenticate($username, $password);
     Log::Debug('Result of ActiveDirectory LDAP Authenticate for user %s: %d', $username, $isValid);
     if ($isValid) {
         $this->user = $this->ldap->GetLdapUser($username);
         $userLoaded = $this->LdapUserExists();
         if (!$userLoaded) {
             Log::Error('Could not load user details from ActiveDirectory LDAP. Check your basedn setting. User: %s', $username);
         }
         return $userLoaded;
     } else {
         if ($this->options->RetryAgainstDatabase()) {
             return $this->authToDecorate->Validate($username, $password);
         }
     }
     return false;
 }