Ejemplo n.º 1
0
		{$tables['listmessage']}.listid = {$tables['listuser']}.listid";

  $query .= " $user_attribute_query";

  $userids = Sql_query("$query");
  if (Sql_Has_Error($database_connection)) {  ProcessError(Sql_Error($database_connection)); }

  # now we have all our users to send the message to
  $num = Sql_affected_rows();
  output( "Found them: $num to process");
  if ($safemode) {
  	# send in batches of $num_per_batch users
    $safemode_total = $num;
  	$query .= sprintf(' limit %d,%d',$reload * $num_per_batch,$num_per_batch);
    $userids = Sql_query("$query");
    if (Sql_Has_Error($database_connection)) {  ProcessError(Sql_Error($database_connection)); }
  }
  while ($userdata = Sql_fetch_row($userids)) {
	  $some = 1;
    #set_time_limit(60);
    # check if we have been "killed"
    $alive = checkLock($send_process_id);
    if ($alive)
      keepLock($send_process_id);
    else
      ProcessError("Process Killed by other process");

    # check if the message we are working on is still there
    $res = Sql_query("select id from {$tables['message']} where id = $messageid");
    if (!Sql_Affected_Rows())
      ProcessError("Message I was working on has disappeared");
 }
 # now we have all our users to send the message to
 $num_users = Sql_affected_rows();
 if ($skipped >= 10000) {
     $num_users -= $skipped;
 }
 output($GLOBALS['I18N']->get('Found them') . ': ' . $num_users . ' ' . $GLOBALS['I18N']->get('to process'));
 setMessageData($messageid, 'to process', $num_users);
 if ($num_per_batch) {
     # send in batches of $num_per_batch users
     $batch_total = $num_users;
     if ($num_per_batch > 0) {
         #$query .= sprintf(' limit 0,%d',$num_per_batch);
         $userids = Sql_query("{$query}");
         if (Sql_Has_Error($database_connection)) {
             ProcessError(Sql_Error($database_connection));
         }
     } else {
         output($GLOBALS['I18N']->get('No users to process for this batch'));
         $userids = Sql_Query(sprintf('select * from %s where id = 0', $tables["user"]));
     }
 }
 $affrows = Sql_Affected_Rows();
 while ($userdata = Sql_fetch_row($userids)) {
     if ($num_per_batch && $sent >= $num_per_batch) {
         output($GLOBALS['I18N']->get('batch limit reached') . ": {$sent} ({$num_per_batch})");
         $GLOBALS["wait"] = $batch_period;
         return;
     }
     $userid = $userdata[0];
     # id of the user
 public function login()
 {
     global $tables;
     if (!class_exists('Net_LDAP2')) {
         require getConfig('casldap_netldap2_path');
     }
     self::init_cas_client();
     // force CAS authentication
     phpCAS::forceAuthentication();
     $cas_login = phpCAS::getUser();
     if (!$cas_login) {
         return;
     }
     $ldap_config = array('host' => getConfig('ldap_host'), 'port' => getConfig('ldap_port'), 'basedn' => getConfig('ldap_basedn'));
     $ldap_version = getConfig('ldap_version');
     if (is_int($ldap_version)) {
         $ldap_config['version'] = $ldap_version;
     }
     if (getConfig('ldap_starttls')) {
         $ldap_config['starttls'] = true;
     }
     $ldap_binddn = getConfig('ldap_binddn');
     $ldap_bindpw = getConfig('ldap_bindpw');
     if ($ldap_binddn && $ldap_bindpw) {
         $ldap_config['binddn'] = $ldap_binddn;
         $ldap_config['bindpw'] = $ldap_bindpw;
     }
     $ldap = Net_LDAP2::connect($ldap_config);
     if (Net_LDAP2::isError($ldap)) {
         die(Fatal_Error(s("Could not connect to LDAP-server: %s", $ldap->getMessage())));
     }
     $user_filter = str_replace('%login', $cas_login, getConfig('ldap_search_user_filter'));
     $user_basedn = getConfig('ldap_search_user_basedn');
     if (!$user_basedn) {
         $user_basedn = NULL;
     }
     $user_scope = getConfig('ldap_search_user_scope');
     if (!in_array($user_scope, array('one', 'base', 'sub'))) {
         $user_scope = 'sub';
     }
     $user_login_attr = getConfig('ldap_search_user_login_attr');
     $user_mail_attr = getConfig('ldap_search_user_mail_attr');
     $options = array('scope' => $user_scope, 'attributes' => array($user_mail_attr));
     if ($user_login_attr) {
         $options['attributes'][] = $user_login_attr;
     }
     $search = $ldap->search($user_basedn, $user_filter, $options);
     if (Net_LDAP2::isError($search)) {
         die(Fatal_Error(s("A problem occured during user search in LDAP : %s", $search->getMessage())));
     }
     if ($search->count() == 0) {
         die(Error(s("You are not authorized to access to this page")));
     } elseif ($search->count() != 1) {
         die(Fatal_Error(s("Found %d users in LDAP corresponding to CAS login %s.", $search->count(), $cas_login)));
     }
     $user_entry = $search->shiftEntry();
     if ($user_login_attr) {
         $login = $user_entry->getValue($user_login_attr, 'single');
         if (!is_string($login)) {
             die(Fatal_Error(s("Fail to retreive user login from LDAP data")));
         }
     } else {
         $login = $cas_login;
     }
     $mail = $user_entry->getValue($user_mail_attr, 'single');
     if (!is_string($mail)) {
         die(Fatal_Error(s("Fail to retreive user mail from LDAP data")));
     }
     $superuser = 0;
     $superuser_filter = getConfig('ldap_search_superuser_filter');
     if ($superuser_filter) {
         $superuser_filter = str_replace('%login', $login, $superuser_filter);
         $superuser_basedn = getConfig('ldap_search_superuser_basedn');
         if (!$superuser_basedn) {
             $superuser_basedn = NULL;
         }
         $superuser_scope = getConfig('ldap_search_superuser_scope');
         if (!in_array($superuser_scope, array('one', 'base', 'sub'))) {
             $superuser_scope = 'sub';
         }
         $search = $ldap->search($superuser_basedn, $superuser_filter, array('scope' => $superuser_scope, 'attrsonly' => true));
         if (Net_LDAP2::isError($search)) {
             die(Fatal_Error(s("A problem occured during the search in LDAP to known if user is a superuser : %s", $search->getMessage())));
         }
         if ($search->count() > 0) {
             $superuser = 1;
         }
     } elseif (getConfig('casldap_all_user_superadmin')) {
         $superuser = 1;
     }
     $row = Sql_Fetch_Row_Query(sprintf("SELECT id, privileges\n\t\t\tFROM {$tables['admin']}\n\t\t\tWHERE loginname = '%s'", sql_escape($login)));
     if ($row) {
         list($id, $privileges) = $row;
         $update = Sql_Query(sprintf("UPDATE {$tables['admin']} SET\n\t\t\t\temail = '%s',\n\t\t\t\tsuperuser = %s,\n\t\t\t\tdisabled = 0\n\t\t\t\tWHERE id=%s", sql_escape($mail), $superuser, $id));
         if (!$update) {
             die(Fatal_Error(s("Fail to update user informations in database : %s", Sql_Error())));
         }
     } else {
         $insert = Sql_Query(sprintf("INSERT INTO {$tables['admin']}\n\t\t\t\t(loginname,email,superuser,disabled)\n\t\t\t\tVALUES\n\t\t\t\t('%s','%s',%s,0)", sql_escape($login), sql_escape($mail), $superuser));
         if (!$insert) {
             die(Fatal_Error(s("Fail to create user in database : %s", Sql_Error())));
         }
         $id = Sql_Insert_Id();
     }
     $_SESSION['adminloggedin'] = $_SERVER["REMOTE_ADDR"];
     $_SESSION['logindetails'] = array('adminname' => $login, 'id' => $id, 'superuser' => $superuser);
     if ($privileges) {
         $_SESSION['privileges'] = unserialize($privileges);
     }
     if (isset($_GET['ticket'])) {
         header('Location: ' . $_SERVER['REQUEST_URI']);
         exit;
     }
     return true;
 }