Esempio n. 1
0
 /**
  * Handle the AJAX request
  *
  * @todo This function is unused
  */
 public function _handle_ajax()
 {
     $update_succeeded = false;
     $errstr = null;
     $user = new midcom_db_person($this->_request_data['user']->id);
     if (array_key_exists('org_openpsa_calendar_filters_add', $_POST)) {
         try {
             $target = new midcom_db_person($_POST['org_openpsa_calendar_filters_add']);
             $update_succeeded = $user->parameter('org_openpsa_calendar_show', $_POST['org_openpsa_calendar_filters_add'], 1);
         } catch (midcom_error $e) {
             $e->log();
         }
     } else {
         if (array_key_exists('org_openpsa_calendar_filters_remove', $_POST)) {
             try {
                 $target = new midcom_db_person($_POST['org_openpsa_calendar_filters_remove']);
                 $update_succeeded = $user->parameter('org_openpsa_calendar_show', $_POST['org_openpsa_calendar_filters_remove'], '');
             } catch (midcom_error $e) {
                 $e->log();
             }
         }
     }
     $errstr = midcom_connection::get_error_string();
     $response = new midcom_response_xml();
     $response->result = $update_succeeded;
     $response->status = $errstr;
     $response->send();
     //This will exit.
 }
Esempio n. 2
0
 public static function create_user($login = false)
 {
     $person = new midcom_db_person();
     $person->_use_rcs = false;
     $person->_use_activitystream = false;
     $password = substr('p_' . time(), 0, 11);
     $username = __CLASS__ . ' user ' . microtime();
     midcom::get('auth')->request_sudo('midcom.core');
     if (!$person->create()) {
         throw new Exception('Person could not be created. Reason: ' . midcom_connection::get_error_string());
     }
     $account = midcom_core_account::get($person);
     $account->set_password($password);
     $account->set_username($username);
     $account->save();
     midcom::get('auth')->drop_sudo();
     if ($login) {
         if (!midcom::get('auth')->login($username, $password)) {
             throw new Exception('Login for user ' . $username . ' failed');
         }
         midcom::get('auth')->_sync_user_with_backend();
     }
     self::$_class_objects[$person->guid] = $person;
     return $person;
 }
Esempio n. 3
0
 public function testCRUD()
 {
     midcom::get('auth')->request_sudo('midcom.core');
     $person = new midcom_db_person();
     $stat = $person->create();
     $this->assertTrue($stat);
     $this->register_object($person);
     $person = new midcom_db_person($person->guid);
     $this->assertEquals('person #' . $person->id, $person->name);
     $this->assertEquals('person #' . $person->id, $person->rname);
     $person->firstname = ' Firstname ';
     $person->lastname = ' Lastname ';
     $stat = $person->update();
     $this->assertTrue($stat);
     $this->assertEquals('Firstname Lastname', $person->name);
     $this->assertEquals('Lastname, Firstname', $person->rname);
     $group = $this->create_object('midcom_db_group');
     $attributes = array('gid' => $group->id, 'uid' => $person->id);
     $member = $this->create_object('midcom_db_member', $attributes);
     $stat = $person->delete();
     $this->assertTrue($stat);
     $qb = midcom_db_member::new_query_builder();
     $qb->add_constraint('id', '=', $member->id);
     $this->assertEquals(0, $qb->count());
     midcom::get('auth')->drop_sudo();
 }
Esempio n. 4
0
 /**
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_delete($handler_id, array $args, array &$data)
 {
     // Check if we get the person
     $this->_person = new midcom_db_person($args[0]);
     $this->_person->require_do('midgard:update');
     if ($this->_person->id != midcom_connection::get_user()) {
         midcom::get('auth')->require_user_do('org.openpsa.user:manage', null, 'org_openpsa_user_interface');
     }
     $this->_account = new midcom_core_account($this->_person);
     if (!$this->_account->get_username()) {
         // Account needs to be created first, relocate
         return new midcom_response_relocate("view/" . $this->_person->guid . "/");
     }
     $data['controller'] = midcom_helper_datamanager2_handler::get_delete_controller();
     switch ($data['controller']->process_form()) {
         case 'delete':
             if (!$this->_account->delete()) {
                 throw new midcom_error("Failed to delete account for {$this->_person->guid}, last Midgard error was: " . midcom_connection::get_error_string());
             }
             //Fall-through
         //Fall-through
         case 'cancel':
             return new midcom_response_relocate('view/' . $this->_person->guid . "/");
     }
     $this->add_stylesheet(MIDCOM_STATIC_URL . "/midcom.helper.datamanager2/legacy.css");
     midcom::get('head')->enable_jquery();
     midcom::get('head')->set_pagetitle("{$this->_person->firstname} {$this->_person->lastname}");
     $this->_prepare_request_data();
     $this->_update_breadcrumb_line('delete account');
     // Add toolbar items
     org_openpsa_helpers::dm2_savecancel($this, 'delete');
 }
Esempio n. 5
0
 /**
  * Get fireeagle location for a user
  *
  * @param midcom_db_person $user Person to fetch Plazes data for
  * @param boolean $cache Whether to cache the position to a log object
  * @return Array
  */
 function get_fireeagle_location($user, $cache = true)
 {
     $fireeagle_access_key = $user->get_parameter('net.yahoo.fireeagle', 'access_key');
     $fireeagle_access_secret = $user->get_parameter('net.yahoo.fireeagle', 'access_secret');
     if ($fireeagle_access_key && $fireeagle_access_secret) {
         $position = $this->_fetch_fireeagle_positions($fireeagle_access_key, $fireeagle_access_secret);
         if (is_null($position) && !is_array($position)) {
             return null;
         }
         $this->import($position, $user->id);
         return $position;
     } else {
         $this->error = 'POSITIONING_FIREEAGLE_NO_ACCOUNT';
     }
     return null;
 }
Esempio n. 6
0
 public function _on_updated()
 {
     // Invalidate topic in cache to refresh all views
     // TODO: Do this only on status changes
     $topic = midcom_db_topic::get_cached($this->topic);
     if ($topic->guid) {
         $_MIDCOM->cache->invalidate($topic->guid);
     }
     if (isset($GLOBALS['disable_activitystream'])) {
         return true;
     }
     if ($_MIDCOM->auth->request_sudo('midcom')) {
         $actor = midcom_db_person::get_cached($_MIDGARD['user']);
         $activity = new midcom_helper_activitystream_activity_dba();
         $activity->target = $this->guid;
         $activity->application = 'fi.kilonkipinat.account';
         $activity->actor = $actor->id;
         $activity->verb = 'http://activitystrea.ms/schema/1.0/post';
         if ($this->id == $actor->id) {
             $activity->summary = sprintf('%s muokkasi omaa tunnustaan', $actor->name);
         } else {
             $tmp_name = $this->firstname . ' ' . $this->lastname;
             $activity->summary = sprintf('%s muokkasi %s:n tunnusta', $actor->name, $tmp_name);
         }
         $activity->create();
         $_MIDCOM->auth->drop_sudo();
     }
     return true;
 }
Esempio n. 7
0
 public function __set($name, $value)
 {
     if ($name == 'homepage' && !empty($value) && $value != $this->homepage) {
         $this->_url_changed = true;
     }
     parent::__set($name, $value);
 }
Esempio n. 8
0
 public function _on_updated()
 {
     // Invalidate topic in cache to refresh all views
     // TODO: Do this only on status changes
     if (isset($GLOBALS['disable_activitystream'])) {
         return true;
     }
     if ($_MIDCOM->auth->request_sudo('midcom')) {
         // This is here because creating an object calls create and update..... and we don't want duplicate entry's
         $qb = midcom_helper_activitystream_activity_dba::new_query_builder();
         $qb->set_limit(1);
         $qb->add_constraint('application', '=', 'fi.kilonkipinat.forms');
         $qb->add_constraint('target', '=', $this->guid);
         $groups = $qb->execute();
         if ($groups && is_array($groups) && count($groups) > 0) {
             $new_object = false;
         } else {
             $new_object = true;
         }
         $actor = midcom_db_person::get_cached($_MIDGARD['user']);
         $activity = new midcom_helper_activitystream_activity_dba();
         $activity->target = $this->guid;
         $activity->application = 'fi.kilonkipinat.forms';
         $activity->actor = $actor->id;
         $activity->verb = 'http://activitystrea.ms/schema/1.0/post';
         if ($new_object) {
             $activity->summary = sprintf('%s loi kulukorvauslomakkeen', $actor->name);
         } else {
             $activity->summary = sprintf('%s muokkasi kulukorvauslomaketta', $actor->name);
         }
         $activity->create();
         $_MIDCOM->auth->drop_sudo();
     }
     return true;
 }
Esempio n. 9
0
 /**
  * Get plazes location for a user
  *
  * @param midcom_db_person $user Person to fetch Plazes data for
  * @param boolean $cache Whether to cache the position to a log object
  * @return Array
  */
 function get_icbm_location($user, $cache = true)
 {
     $icbm_url = $user->parameter('org.routamc.positioning:html', 'icbm_url');
     if ($icbm_url) {
         $position = $this->_fetch_icbm_position($icbm_url);
         if (is_null($position)) {
             return null;
         }
         if ($cache) {
             $this->import($position, $user->id);
         }
         return $position;
     } else {
         $this->error = 'POSITIONING_ICBM_NO_URL';
     }
     return null;
 }
Esempio n. 10
0
 /**
  * DM2 creation callback.
  */
 function &dm2_create_callback(&$controller)
 {
     // Create a new person
     $this->_person = new midcom_db_person();
     if (!$this->_person->create()) {
         debug_print_r('We operated on this object:', $this->_person);
         throw new midcom_error('Failed to create a new person. Last Midgard error was: ' . midcom_connection::get_error_string());
     }
     return $this->_person;
 }
Esempio n. 11
0
 /**
  * Get instamapper location for a user
  *
  * @param midcom_db_person $user Person to fetch Plazes data for
  * @param boolean $cache Whether to cache the position to a log object
  * @return Array
  */
 function get_instamapper_location($user, $cache = true)
 {
     $instamapper_url = trim($user->parameter('org.routamc.positioning:instamapper', 'api_key'));
     if ($instamapper_url) {
         $positions = $this->_fetch_instamapper_positions($instamapper_url);
         if (is_null($positions) || empty($positions)) {
             return null;
         }
         if ($cache) {
             foreach ($positions as $position) {
                 $this->import($position, $user->id);
             }
         }
         return $positions[0];
     } else {
         $this->error = 'POSITIONING_INSTAMAPPER_NO_APIKEY';
     }
     return null;
 }
Esempio n. 12
0
 /**
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_edit($handler_id, array $args, array &$data)
 {
     $this->_person = new org_openpsa_contacts_person_dba($args[0]);
     if ($this->_person->id != midcom_connection::get_user()) {
         midcom::get('auth')->require_user_do('org.openpsa.user:manage', null, 'org_openpsa_user_interface');
     }
     $data['controller'] = $this->get_controller('simple', $this->_person);
     switch ($data['controller']->process_form()) {
         case 'save':
             midcom::get('uimessages')->add($this->_l10n->get('org.openpsa.user'), sprintf($this->_l10n->get('person %s saved'), $this->_person->name));
             // Fall-through
         // Fall-through
         case 'cancel':
             return new midcom_response_relocate('view/' . $this->_person->guid . '/');
     }
     $this->add_breadcrumb('', sprintf($this->_l10n_midcom->get('edit %s'), $this->_person->get_label()));
     org_openpsa_helpers::dm2_savecancel($this);
     $this->bind_view_to_object($this->_person);
 }
Esempio n. 13
0
 /**
  * Get qaiku location for a user
  *
  * @param midcom_db_person $user Person to fetch Qaiku data for
  * @param boolean $cache Whether to cache the position to a log object
  * @return Array
  */
 function get_qaiku_location($user, $cache = true)
 {
     $qaiku_apikey = $user->get_parameter('org.routamc.statusmessage:qaiku', 'apikey');
     if ($qaiku_apikey) {
         $positions = $this->_fetch_qaiku_positions(trim($qaiku_apikey));
         if (empty($positions)) {
             return null;
         }
         if ($cache) {
             foreach ($positions as $position) {
                 $this->import($position, $user->id);
             }
         }
         return $positions[0];
     } else {
         $this->error = 'POSITIONING_QAIKU_NO_APIKEY';
     }
     return null;
 }
Esempio n. 14
0
 /**
  * Get plazes location for a user
  *
  * @param midcom_db_person $user Person to fetch Plazes data for
  * @param boolean $cache Whether to cache the position to a log object
  * @return Array
  */
 function get_plazes_location($user, $cache = true)
 {
     $plazes_username = $user->get_parameter('org.routamc.positioning:plazes', 'username');
     $plazes_password = $user->get_parameter('org.routamc.positioning:plazes', 'password');
     if ($plazes_username && $plazes_password) {
         $positions = $this->_fetch_plazes_positions($plazes_username, $plazes_password);
         if (is_null($positions) && !is_array($positions)) {
             return null;
         }
         if ($cache) {
             foreach ($positions as $position) {
                 $this->import($position, $user->id);
             }
         }
         return $positions[0];
     } else {
         $this->error = 'POSITIONING_PLAZES_NO_ACCOUNT';
     }
     return null;
 }
Esempio n. 15
0
 /**
  * Helper function that lists options for the person filter
  */
 public function get_person_options()
 {
     $qb_persons = midcom_db_person::new_query_builder();
     midcom_core_account::add_username_constraint($qb_persons, '<>', '');
     $person_array = array();
     $persons = $qb_persons->execute();
     foreach ($persons as $person) {
         $person_array[$person->id] = $person->get_label();
     }
     return $person_array;
 }
Esempio n. 16
0
 /**
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_privileges($handler_id, array $args, array &$data)
 {
     midcom::get('auth')->require_valid_user();
     // Check if we get the person
     $this->_person = new midcom_db_person($args[0]);
     $this->_person->require_do('midgard:privileges');
     $this->_request_data['person'] =& $this->_person;
     $data['acl_dm'] = $this->get_controller('simple', $this->_person);
     switch ($data['acl_dm']->process_form()) {
         case 'save':
             // Fall-through
         // Fall-through
         case 'cancel':
             return new midcom_response_relocate(midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX) . "view/" . $this->_person->guid . "/");
     }
     midcom::get('head')->set_pagetitle("{$this->_person->name}");
     org_openpsa_helpers::dm2_savecancel($this);
     $this->add_breadcrumb("view/{$this->_person->guid}/", $this->_person->name);
     $this->add_breadcrumb('', $this->_l10n->get('permissions'));
 }
Esempio n. 17
0
 /**
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_delete($handler_id, array $args, array &$data)
 {
     $this->_person = new midcom_db_person($args[0]);
     if ($this->_person->id != midcom_connection::get_user()) {
         midcom::get('auth')->require_user_do('org.openpsa.user:manage', null, 'org_openpsa_user_interface');
     }
     if (array_key_exists('org_openpsa_user_deleteok', $_POST)) {
         $delete_succeeded = $this->_person->delete();
         if ($delete_succeeded) {
             // Update the index
             $indexer = midcom::get('indexer');
             $indexer->delete($this->_person->guid);
             return new midcom_response_relocate('');
         } else {
             // Failure, give a message
             midcom::get('uimessages')->add($this->_l10n->get('org.openpsa.user'), $this->_l10n->get("failed to delete person, reason") . ' ' . midcom_connection::get_error_string(), 'error');
             return new midcom_response_relocate('view/' . $this->_person->guid . '/');
         }
     }
     $data['view'] = midcom_helper_datamanager2_handler::get_view_controller($this, $this->_person);
     $data['person'] = $this->_person;
     $this->add_breadcrumb('', sprintf($this->_l10n_midcom->get('delete %s'), $this->_person->get_label()));
     $this->bind_view_to_object($this->_person);
 }
Esempio n. 18
0
 /**
  * AJAX backend for saving data on the fly
  *
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  * @return boolean Indicating success.
  */
 public function _handler_ajax($handler_id, array $args, array &$data)
 {
     $this->_person = new midcom_db_person(midcom_connection::get_user());
     // Check for the ACL's
     $this->_person->require_do('midgard:update');
     // Patch for Midgard ACL problem of setting person's own parameters
     midcom::get('auth')->request_sudo('midgard.admin.asgard');
     foreach ($_POST as $key => $value) {
         if (is_array($value)) {
             $value = serialize($value);
         }
         if (!$this->_person->set_parameter('midgard.admin.asgard:preferences', $key, $value)) {
             $this->_status = false;
             midcom::get('uimessages')->add(midcom::get('i18n')->get_string('midgard.admin.asgard', 'midgard.admin.asgard'), sprintf(midcom::get('i18n')->get_string('failed to save the preference for %s', 'midgard.admin.asgard'), midcom::get('i18n')->get_string($key, 'midgard.admin.asgard')));
         }
         debug_add("Added configuration key-value pair {$key} => {$value}");
     }
     midcom::get('auth')->drop_sudo();
 }
Esempio n. 19
0
 /**
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_view($handler_id, array $args, array &$data)
 {
     midcom::get('auth')->require_valid_user();
     $this->_person = new org_openpsa_contacts_person_dba($args[0]);
     $data['view'] = midcom_helper_datamanager2_handler::get_view_controller($this, $this->_person);
     $this->add_breadcrumb('', $this->_person->get_label());
     $auth = midcom::get('auth');
     if ($this->_person->id == midcom_connection::get_user() || $auth->can_user_do('org.openpsa.user:manage', null, 'org_openpsa_user_interface')) {
         $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "edit/{$this->_person->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get("edit"), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/edit.png', MIDCOM_TOOLBAR_ENABLED => $this->_person->can_do('midgard:update'), MIDCOM_TOOLBAR_ACCESSKEY => 'e'));
         $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "delete/{$this->_person->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get("delete"), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/trash.png', MIDCOM_TOOLBAR_ENABLED => $this->_person->can_do('midgard:delete')));
         if (midcom_connection::is_user($this->_person)) {
             $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "privileges/{$this->_person->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n->get("permissions"), MIDCOM_TOOLBAR_ICON => 'midgard.admin.asgard/permissions-16.png', MIDCOM_TOOLBAR_ENABLED => $this->_person->can_do('midgard:privileges')));
         }
         $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "person/notifications/{$this->_person->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n->get("notification settings"), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock-discussion.png', MIDCOM_TOOLBAR_ENABLED => $this->_person->can_do('midgard:update')));
     }
     $this->bind_view_to_object($this->_person);
 }
Esempio n. 20
0
 /**
  * Helper function to record failed login attempts and disable account is necessary
  *
  * @param string $component the component we take the config values from
  * @return boolean True if further login attempts are allowed, false otherwise
  */
 public function check_login_attempts($component = null)
 {
     $stat = true;
     if (is_null($component)) {
         $component = "org.openpsa.user";
     }
     //max-attempts allowed & timeframe
     $max_attempts = midcom_baseclasses_components_configuration::get($component, 'config')->get('max_password_attempts');
     $timeframe = midcom_baseclasses_components_configuration::get($component, 'config')->get('password_block_timeframe_min');
     if ($max_attempts == 0 || $timeframe == 0) {
         return $stat;
     }
     midcom::get('auth')->request_sudo('org.openpsa.user');
     $attempts = $this->_person->get_parameter("org_openpsa_user_password", "attempts");
     if (!empty($attempts)) {
         $attempts = unserialize($attempts);
         if (is_array($attempts)) {
             $attempts = array_slice($attempts, 0, $max_attempts - 1);
         }
     }
     if (!is_array($attempts)) {
         $attempts = array();
     }
     array_unshift($attempts, time());
     /*
      * If the maximum number of attemps is reached and the oldest attempt
      * on the stack is within our defined timeframe, we block the account
      */
     if (sizeof($attempts) >= $max_attempts && $attempts[$max_attempts - 1] >= time() - $timeframe * 60) {
         $this->disable_account();
         $stat = false;
     }
     $attempts = serialize($attempts);
     $this->_person->set_parameter("org_openpsa_user_password", "attempts", $attempts);
     midcom::get('auth')->drop_sudo();
     return $stat;
 }
Esempio n. 21
0
 /**
  * Get querybuilder for JSON group member list
  */
 public function get_qb($field = null, $direction = 'ASC')
 {
     $qb = midcom_db_person::new_collector('metadata.deleted', false);
     $member_ids = array_keys($this->_request_data['group']->get_members());
     if (count($member_ids)) {
         $qb->add_constraint('id', 'IN', $member_ids);
     } else {
         $qb->add_constraint('id', '=', 0);
     }
     if (!is_null($field)) {
         if ($field == 'username') {
             midcom_core_account::add_username_order($qb, $direction);
         } else {
             $qb->add_order($field, $direction);
         }
     }
     $qb->add_order('lastname');
     $qb->add_order('firstname');
     $qb->add_order('email');
     $qb->add_order('id');
     return $qb;
 }
Esempio n. 22
0
 /**
  * Internal helper for processing the batch change of passwords
  */
 private function _process_batch_change()
 {
     // Set the mail commo parts
     $mail = new org_openpsa_mail();
     $mail->from = $this->_config->get('message_sender');
     $mail->encoding = 'UTF-8';
     // Success switch
     $success = true;
     // Get the context prefix
     $prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX);
     // Change every user or continue to next on failure - failures will show UI messages
     foreach ($_POST['midcom_admin_user'] as $id) {
         try {
             $person = new midcom_db_person($id);
         } catch (midcom_error $e) {
             midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), sprintf($this->_l10n->get('failed to get the user with id %s'), $id), 'error');
             $success = false;
             continue;
         }
         // This shortcut is used in case of errors
         $person_edit_url = "<a href=\"{$prefix}__mfa/asgard_midcom.admin.user/edit/{$person->guid}\">{$person->name}</a>";
         // Cannot send the email if address is not specified
         if (!$person->email) {
             midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), sprintf($this->_l10n->get('no email address defined for %s'), $person_edit_url), 'error');
             continue;
         }
         // Recipient
         $mail->to = $person->email;
         // Store the old password
         $person->set_parameter('midcom.admin.user', 'old_password', $person->password);
         // Get a new password
         $password = midcom_admin_user_plugin::generate_password(8);
         $mail->body = $_POST['body'];
         $mail->subject = $_POST['subject'];
         $mail->parameters = array('PASSWORD' => $password, 'FROM' => $this->_config->get('message_sender'), 'LONGDATE' => strftime('%c'), 'SHORTDATE' => strftime('%x'), 'TIME' => strftime('%X'), 'PERSON' => $person);
         // Send the message
         if ($mail->send()) {
             // Set the password
             $person->password = "******";
             if (!$person->update()) {
                 midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), sprintf($this->_l10n->get('failed to update the password for %s'), $person_edit_url));
                 $success = false;
             }
         } else {
             throw new midcom_error("Failed to send the mail, SMTP returned error " . $mail->get_error_message());
         }
     }
     // Show UI message on success
     if ($success) {
         midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), $this->_l10n->get('passwords updated and mail sent'));
     }
 }
Esempio n. 23
0
 private function _find_email_person($email, $prefer_user = true)
 {
     // TODO: Use the new helpers for finding persons by email (a person might have multiple ones...)
     $qb = midcom_db_person::new_query_builder();
     $qb->add_constraint('email', '=', $email);
     $results = $qb->execute();
     if (empty($results)) {
         return false;
     }
     if (!$prefer_user) {
         return $results[0];
     }
     foreach ($results as $person) {
         if (!empty($person->username)) {
             return $person;
         }
     }
     return $person;
 }
Esempio n. 24
0
 function emailimport_find_person($email, $prefer_user = true)
 {
     $qb = midcom_db_person::new_query_builder();
     $qb->add_constraint('email', '=', $email);
     $results = $qb->execute();
     if (empty($results)) {
         return false;
     }
     if (!$prefer_user) {
         return $results[0];
     }
     foreach ($results as $person) {
         if (!empty($person->username)) {
             return $person;
         }
     }
     return $person;
 }
Esempio n. 25
0
 /**
  * Method for exporting event in vCalendar format
  *
  * @param org_openpsa_calendar_event_dba $event The event we're working on
  * @param array compatibility options to override
  * @return string vCalendar data
  */
 public function export_event(org_openpsa_calendar_event_dba $event, $compatibility = array())
 {
     $encoder = new org_openpsa_helpers_vxparser();
     $encoder->merge_compatibility($compatibility);
     // Simple key/value pairs, for multiple occurrences of same key use array as value
     $vcal_keys = array();
     // For extended key data, like charset
     $vcal_key_parameters = array();
     // TODO: handle UID smarter
     $vcal_keys['UID'] = "{$event->guid}-midgardGuid";
     $revised = $event->metadata->revised;
     $created = $event->metadata->created;
     $vcal_keys['LAST-MODIFIED'] = $encoder->vcal_stamp($revised, array('TZID' => 'UTC')) . 'Z';
     $vcal_keys['CREATED'] = $encoder->vcal_stamp($created, array('TZID' => 'UTC')) . 'Z';
     /**
      * The real meaning of the DTSTAMP is fuzzy at best
      * http://www.kanzaki.com/docs/ical/dtstamp.html is less than helpful
      * http://lists.osafoundation.org/pipermail/ietf-calsify/2007-July/001750.html
      * seems to suggest that using the revision would be best
      */
     $vcal_keys['DTSTAMP'] =& $vcal_keys['LAST-MODIFIED'];
     // Type handling
     switch ($event->orgOpenpsaAccesstype) {
         case org_openpsa_core_acl::ACCESS_PUBLIC:
             $vcal_keys['CLASS'] = 'PUBLIC';
             break;
         default:
         case org_openpsa_core_acl::ACCESS_PRIVATE:
             $vcal_keys['CLASS'] = 'PRIVATE';
             break;
     }
     // "busy" or "transparency" as vCalendar calls it
     if ($event->busy) {
         $vcal_keys['TRANSP'] = 'OPAQUE';
     } else {
         $vcal_keys['TRANSP'] = 'TRANSPARENT';
     }
     // tentative vs confirmed
     $vcal_keys['STATUS'] = 'CONFIRMED';
     // we don't categorize events, at least yet
     $vcal_keys['CATEGORIES'] = 'MEETING';
     // we don't handle priorities
     $vcal_keys['PRIORITY'] = 1;
     // Basic fields
     $vcal_keys['SUMMARY'] = $encoder->escape_separators($event->title);
     $vcal_keys['DESCRIPTION'] = $encoder->escape_separators($event->description);
     $vcal_keys['LOCATION'] = $encoder->escape_separators($event->location);
     // Start & End in UTC
     $vcal_keys['DTSTART'] = $encoder->vcal_stamp($event->start, array('TZID' => 'UTC')) . 'Z';
     $vcal_keys['DTEND'] = $encoder->vcal_stamp($event->end, array('TZID' => 'UTC')) . 'Z';
     // Participants
     $vcal_keys['ATTENDEE'] = array();
     $vcal_key_parameters['ATTENDEE'] = array();
     // Safety, otherwise the notice will make output invalid
     if (!is_array($event->participants)) {
         $event->participants = array();
     }
     foreach ($event->participants as $uid => $bool) {
         // Just a safety
         if (!$bool) {
             continue;
         }
         $person = midcom_db_person::get_cached($uid);
         if (empty($person->email)) {
             // Attendee must have email address of valid format, these must also be unique.
             $person->email = preg_replace('/[^0-9_\\x61-\\x7a]/i', '_', strtolower($person->name)) . '*****@*****.**';
         }
         $vcal_keys['ATTENDEE'][] = "mailto:{$person->email}";
         $vcal_key_parameters['ATTENDEE'][] = array('ROLE' => 'REQ-PARTICIPANT', 'CUTYPE' => 'INDIVIDUAL', 'PARTSTAT' => 'ACCEPTED', 'CN' => $encoder->escape_separators($person->rname, true));
     }
     $ret = "BEGIN:VEVENT{$this->_newline}";
     $ret .= $encoder->export_vx_variables_recursive($vcal_keys, $vcal_key_parameters, false, $this->_newline);
     $ret .= "END:VEVENT{$this->_newline}";
     return $ret;
 }
Esempio n. 26
0
<?php

midcom::get('auth')->require_admin_user();
midcom::get()->disable_limits();
//Note: You have to run this multiple times, offset does not take deletions into account
$chunk_size = 1000;
$offset = 0;
$valid_persons = array();
$valid_targets = array();
$invalid_targets = array();
$person_qb = midcom_db_person::new_query_builder();
$person_qb->include_deleted();
$persons = $person_qb->execute();
foreach ($persons as $person) {
    $valid_persons[] = $person->id;
    $valid_targets[] = $person->guid;
}
unset($persons);
while (@ob_end_flush()) {
}
echo "<pre>\n";
flush();
do {
    $qb = midcom_helper_activitystream_activity_dba::new_query_builder();
    $qb->add_constraint('actor', 'NOT IN', $valid_persons);
    $qb->add_constraint('actor', '<>', 0);
    $qb->set_limit($chunk_size);
    $results = $qb->execute();
    echo "Deleting " . sizeof($results) . " entries for purged persons\n";
    flush();
    foreach ($results as $result) {
Esempio n. 27
0
 private function _batch_process()
 {
     foreach ($_POST['midcom_admin_user'] as $person_id) {
         try {
             if (is_numeric($person_id)) {
                 $person = new midcom_db_person((int) $person_id);
             } else {
                 $person = new midcom_db_person($person_id);
             }
         } catch (midcom_error $e) {
             continue;
         }
         switch ($_POST['midcom_admin_user_action']) {
             case 'removeaccount':
                 if (!$this->_config->get('allow_manage_accounts')) {
                     break;
                 }
                 $person->parameter('midcom.admin.user', 'username', $person->username);
                 $person->username = '';
                 $person->password = '';
                 if ($person->update()) {
                     midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), sprintf($this->_l10n->get('user account revoked for %s'), $person->name));
                 }
                 break;
             case 'groupadd':
                 if (isset($_POST['midcom_admin_user_group'])) {
                     $member = new midcom_db_member();
                     $member->uid = $person->id;
                     $member->gid = (int) $_POST['midcom_admin_user_group'];
                     if ($member->create()) {
                         midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), sprintf($this->_l10n->get('user %s added to group'), $person->name));
                     }
                 }
                 break;
         }
     }
 }
Esempio n. 28
0
 /**
  * The handler for the index article.
  *
  * @param mixed $handler_id the array key from the request array
  * @param array $args the arguments given to the handler
  * @param Array &$data The local request data.
  * @return boolean Indicating success.
  */
 function _handler_approveReset($handler_id, $args, &$data)
 {
     $message = array();
     $reset_request = new fi_kilonkipinat_accountregistration_resetrequest_dba(trim($args[0]));
     if (isset($reset_request) && isset($reset_request->guid) && $reset_request->guid == trim($args[0]) && $reset_request->status == FI_KILONKIPINAT_ACCOUNTREGISTRATION_PASSWORDRESETREQUEST_STATUS_NEW) {
         $_MIDCOM->auth->request_sudo('fi.kilonkipinat.accountregistration');
         $person = new midcom_db_person($reset_request->person);
         if (isset($person) && isset($person->guid) && $person->guid != '' && $person->id == $reset_request->person) {
             $password = fi_kilonkipinat_accountregistration_viewer::generatePassword($this->_config->get('password_length'));
             // Enforce crypt mode
             $salt = chr(rand(64, 126)) . chr(rand(64, 126));
             $crypt_password = crypt($password, $salt);
             $person->password = $crypt_password;
             if ($person->update()) {
                 $reset_request->status = FI_KILONKIPINAT_ACCOUNTREGISTRATION_PASSWORDRESETREQUEST_STATUS_RESOLVED;
                 $reset_request->update();
                 $message['title'] = "Onnistui";
                 $message['content'] = "Tarkista sähköpostisi";
                 $subject = sprintf('Uusi salasananne', $_SERVER['SERVER_NAME']);
                 $body = sprintf('Hei %s', $person->firstname);
                 $body .= "\n\n";
                 $body .= sprintf('Uusi salasanne on %s', $password);
                 $mail = new org_openpsa_mail();
                 $mail->from = $this->_config->get('mail_sender_title') . ' <' . $this->_config->get('mail_sender_address') . '>';
                 $mail->to = $person->firstname . ' ' . $person->lastname . ' <' . $person->email . '>';
                 $mail->body = $body;
                 $mail->subject = $subject;
                 if ($mail->send('mail')) {
                     $message['title'] = "Onnistui";
                     $message['content'] = "Tarkista sähköpostisi.";
                 } else {
                     $message['title'] = "Virhe";
                     $message['content'] = "Oho, jotain meni pieleen";
                 }
             }
         }
         $_MIDCOM->auth->drop_sudo('fi.kilonkipinat.accountregistration');
     } else {
         $message['title'] = "Virhe";
         $message['content'] = "Ei löytynyt pyyn";
     }
     $this->_request_data['message'] = $message;
     return true;
 }
Esempio n. 29
0
 public function _on_deleted()
 {
     $this->_invalidate_person_cache();
     if (!midcom::get('auth')->request_sudo('midcom')) {
         return;
     }
     // Create an Activity Log entry for the membership addition
     try {
         $actor = midcom_db_person::get_cached($this->uid);
         $target = midcom_db_group::get_cached($this->gid);
     } catch (midcom_error $e) {
         $e->log();
         return;
     }
     $activity = new midcom_helper_activitystream_activity_dba();
     $activity->target = $target->guid;
     $activity->actor = $actor->id;
     $activity->verb = 'http://community-equity.org/schema/1.0/leave';
     if (midcom::get('auth')->is_valid_user() && $actor->guid == midcom::get('auth')->user->guid) {
         $activity->summary = sprintf(midcom::get('i18n')->get_string('%s left group %s', 'midcom'), $actor->name, $target->official);
     } else {
         $activity->summary = sprintf(midcom::get('i18n')->get_string('%s was removed from group %s', 'midcom'), $actor->name, $target->official);
     }
     $activity->create();
     midcom::get('auth')->drop_sudo();
 }
Esempio n. 30
0
 /**
  * Get a preference for the current user
  *
  * @param string $preference    Name of the preference
  */
 public static function get_preference($preference)
 {
     static $preferences = array();
     if (!midcom::get('auth')->user) {
         return;
     }
     if (!isset($preferences[$preference])) {
         $person = midcom_db_person::get_cached(midcom::get('auth')->user->guid);
         $preferences[$preference] = $person->get_parameter('midgard.admin.asgard:preferences', $preference);
     }
     return $preferences[$preference];
 }